Files
panopainter/tests/app_core/app_status_tests.cpp

87 lines
3.2 KiB
C++

#include "app_core/app_status.h"
#include "test_harness.h"
namespace {
void resolution_maps_supported_indices_and_labels(pp::tests::Harness& harness)
{
const auto resolution = pp::app::display_resolution_from_index(3);
PP_EXPECT(harness, resolution);
if (resolution) {
PP_EXPECT(harness, resolution.value() == 2048);
}
const auto index = pp::app::document_resolution_to_index(4096);
PP_EXPECT(harness, index);
if (index) {
PP_EXPECT(harness, index.value() == 4U);
}
const auto label = pp::app::document_resolution_label(8192);
PP_EXPECT(harness, label);
if (label) {
PP_EXPECT(harness, label.value() == "32K");
}
}
void resolution_mapping_rejects_out_of_range_values(pp::tests::Harness& harness)
{
PP_EXPECT(harness, !pp::app::display_resolution_from_index(-1));
PP_EXPECT(harness, !pp::app::display_resolution_from_index(6));
PP_EXPECT(harness, !pp::app::document_resolution_to_index(1234));
PP_EXPECT(harness, !pp::app::document_resolution_label(1234));
}
void document_title_marks_unsaved_documents(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::make_document_title("demo", false, 2048) == "Panodoc: demo (8K)");
PP_EXPECT(
harness,
pp::app::make_document_title("demo", true, 2048) == "Panodoc: demo* (8K)");
}
void document_title_survives_unknown_resolution(pp::tests::Harness& harness)
{
PP_EXPECT(
harness,
pp::app::make_document_title("demo", true, 1234) == "Panodoc: demo* (unknown)");
}
void status_labels_match_legacy_text(pp::tests::Harness& harness)
{
PP_EXPECT(harness, pp::app::make_dpi_label(1.25F) == "1.2x-dpi");
PP_EXPECT(harness, pp::app::make_dpi_label(1.26F) == "1.3x-dpi");
PP_EXPECT(harness, pp::app::make_history_memory_label(1024U * 1024U * 3U / 2U) == "History memory: 1.50 Mb");
}
void recording_label_only_shows_when_recording_with_encoder(pp::tests::Harness& harness)
{
const auto inactive = pp::app::make_recording_frame_label(false, true, 12);
PP_EXPECT(harness, !inactive.visible);
PP_EXPECT(harness, inactive.text.empty());
const auto missing_encoder = pp::app::make_recording_frame_label(true, false, 12);
PP_EXPECT(harness, !missing_encoder.visible);
PP_EXPECT(harness, missing_encoder.text.empty());
const auto active = pp::app::make_recording_frame_label(true, true, 12);
PP_EXPECT(harness, active.visible);
PP_EXPECT(harness, active.text == "Recorded 12 frames");
}
}
int main()
{
pp::tests::Harness harness;
harness.run("resolution maps supported indices and labels", resolution_maps_supported_indices_and_labels);
harness.run("resolution mapping rejects out of range values", resolution_mapping_rejects_out_of_range_values);
harness.run("document title marks unsaved documents", document_title_marks_unsaved_documents);
harness.run("document title survives unknown resolution", document_title_survives_unknown_resolution);
harness.run("status labels match legacy text", status_labels_match_legacy_text);
harness.run("recording label only shows when recording with encoder", recording_label_only_shows_when_recording_with_encoder);
return harness.finish();
}