Add document layer metadata tests
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
#include "document/document.h"
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <string_view>
|
||||
|
||||
using pp::paint::BlendMode;
|
||||
using pp::document::CanvasDocument;
|
||||
using pp::document::DocumentHistory;
|
||||
using pp::document::DocumentConfig;
|
||||
@@ -10,6 +12,7 @@ using pp::document::max_document_history_entries;
|
||||
using pp::document::max_canvas_dimension;
|
||||
using pp::document::max_frame_count;
|
||||
using pp::document::max_layer_count;
|
||||
using pp::document::max_layer_name_length;
|
||||
using pp::foundation::StatusCode;
|
||||
|
||||
namespace {
|
||||
@@ -93,6 +96,64 @@ void moves_layers_and_preserves_active_layer_identity(pp::tests::Harness& h)
|
||||
PP_EXPECT(h, bad_move.code == StatusCode::out_of_range);
|
||||
}
|
||||
|
||||
void updates_layer_metadata(pp::tests::Harness& h)
|
||||
{
|
||||
auto document_result = CanvasDocument::create(
|
||||
DocumentConfig { .width = 64, .height = 64, .layer_count = 2 });
|
||||
PP_EXPECT(h, document_result.ok());
|
||||
auto document = document_result.value();
|
||||
|
||||
PP_EXPECT(h, document.rename_layer(1, "Ink").ok());
|
||||
PP_EXPECT(h, document.set_layer_visible(1, false).ok());
|
||||
PP_EXPECT(h, document.set_layer_opacity(1, 0.25F).ok());
|
||||
PP_EXPECT(h, document.set_layer_blend_mode(1, BlendMode::multiply).ok());
|
||||
|
||||
PP_EXPECT(h, document.layers()[1].name == std::string_view("Ink"));
|
||||
PP_EXPECT(h, !document.layers()[1].visible);
|
||||
PP_EXPECT(h, std::fabs(document.layers()[1].opacity - 0.25F) < 0.0001F);
|
||||
PP_EXPECT(h, document.layers()[1].blend_mode == BlendMode::multiply);
|
||||
}
|
||||
|
||||
void rejects_invalid_layer_metadata(pp::tests::Harness& h)
|
||||
{
|
||||
auto document_result = CanvasDocument::create(
|
||||
DocumentConfig { .width = 64, .height = 64, .layer_count = 1 });
|
||||
PP_EXPECT(h, document_result.ok());
|
||||
auto document = document_result.value();
|
||||
|
||||
const auto empty_name = document.rename_layer(0, "");
|
||||
const auto long_name = document.rename_layer(0, std::string(max_layer_name_length + 1U, 'x'));
|
||||
const auto missing_name = document.rename_layer(4, "Missing");
|
||||
const auto bad_opacity_low = document.set_layer_opacity(0, -0.1F);
|
||||
const auto bad_opacity_high = document.set_layer_opacity(0, 1.1F);
|
||||
const auto bad_opacity_nan = document.set_layer_opacity(0, std::nanf(""));
|
||||
const auto missing_visible = document.set_layer_visible(2, true);
|
||||
const auto missing_blend = document.set_layer_blend_mode(2, BlendMode::normal);
|
||||
const auto bad_blend = document.set_layer_blend_mode(0, static_cast<BlendMode>(255));
|
||||
const auto bad_add_layer = document.add_layer(std::string(max_layer_name_length + 1U, 'x'));
|
||||
|
||||
PP_EXPECT(h, !empty_name.ok());
|
||||
PP_EXPECT(h, empty_name.code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !long_name.ok());
|
||||
PP_EXPECT(h, long_name.code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !missing_name.ok());
|
||||
PP_EXPECT(h, missing_name.code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !bad_opacity_low.ok());
|
||||
PP_EXPECT(h, bad_opacity_low.code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !bad_opacity_high.ok());
|
||||
PP_EXPECT(h, bad_opacity_high.code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !bad_opacity_nan.ok());
|
||||
PP_EXPECT(h, bad_opacity_nan.code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !missing_visible.ok());
|
||||
PP_EXPECT(h, missing_visible.code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !missing_blend.ok());
|
||||
PP_EXPECT(h, missing_blend.code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !bad_blend.ok());
|
||||
PP_EXPECT(h, bad_blend.code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !bad_add_layer.ok());
|
||||
PP_EXPECT(h, bad_add_layer.status().code == StatusCode::out_of_range);
|
||||
}
|
||||
|
||||
void manages_animation_frames_and_duration(pp::tests::Harness& h)
|
||||
{
|
||||
auto document_result = CanvasDocument::create(
|
||||
@@ -267,6 +328,8 @@ int main()
|
||||
harness.run("rejects_invalid_document_configs", rejects_invalid_document_configs);
|
||||
harness.run("manages_layer_add_remove_and_active_index", manages_layer_add_remove_and_active_index);
|
||||
harness.run("moves_layers_and_preserves_active_layer_identity", moves_layers_and_preserves_active_layer_identity);
|
||||
harness.run("updates_layer_metadata", updates_layer_metadata);
|
||||
harness.run("rejects_invalid_layer_metadata", rejects_invalid_layer_metadata);
|
||||
harness.run("manages_animation_frames_and_duration", manages_animation_frames_and_duration);
|
||||
harness.run("rejects_invalid_animation_frame_operations", rejects_invalid_animation_frame_operations);
|
||||
harness.run("records_document_history_and_restores_snapshots", records_document_history_and_restores_snapshots);
|
||||
|
||||
Reference in New Issue
Block a user