Centralize legacy brush package export
This commit is contained in:
@@ -227,6 +227,7 @@ add_library(pp_app_core STATIC
|
||||
src/app_core/app_preferences.h
|
||||
src/app_core/app_status.h
|
||||
src/app_core/app_startup.h
|
||||
src/app_core/brush_package_export.h
|
||||
src/app_core/brush_ui.h
|
||||
src/app_core/canvas_hotkey.h
|
||||
src/app_core/canvas_tool_ui.h
|
||||
|
||||
@@ -86,6 +86,8 @@ set(PP_PANOPAINTER_APP_SOURCES
|
||||
src/legacy_app_preference_services.h
|
||||
src/legacy_app_startup_services.cpp
|
||||
src/legacy_app_startup_services.h
|
||||
src/legacy_brush_package_export_services.cpp
|
||||
src/legacy_brush_package_export_services.h
|
||||
src/legacy_cloud_services.cpp
|
||||
src/legacy_cloud_services.h
|
||||
src/legacy_document_export_services.cpp
|
||||
|
||||
@@ -639,6 +639,16 @@ Known local toolchain state:
|
||||
preserving desktop worker-thread timelapse behavior, mobile/Web save
|
||||
callbacks, `App::rec_export`, animation `Canvas::export_anim_mp4`, and
|
||||
success messages; retained video/export ownership is tracked by `DEBT-0044`.
|
||||
- `src/legacy_brush_package_export_services.*` is the current app-shell bridge
|
||||
between `pp_app_core` PPBR brush package export requests and live
|
||||
`NodePanelBrushPreset::export_ppbr` execution. It preserves dialog metadata,
|
||||
the retained legacy `Image` header object, desktop worker-thread export,
|
||||
mobile/Web save completion, dialog lifetime, and success messages while brush
|
||||
asset/storage/UI/platform ownership is tracked by `DEBT-0047`.
|
||||
- `pp_app_core_brush_package_export_tests` covers PPBR export request path
|
||||
validation, metadata preservation, legacy-flexible destination/export-data
|
||||
combinations, service dispatch, and malformed request rejection without
|
||||
requiring a window, brush preset panel, or filesystem write.
|
||||
- `src/legacy_history_services.*` is the current app-shell bridge between
|
||||
`pp_app_core` history plans and legacy `ActionManager`; toolbar and
|
||||
`NodeCanvas` hotkeys share it while document-history extraction remains
|
||||
|
||||
@@ -64,6 +64,7 @@ agent or engineer to remove them without reconstructing context from chat.
|
||||
| DEBT-0044 | Open | Modernization | Timelapse and animation MP4 export execution dispatch now consumes pure `pp_app_core` through `App::dialog_timelapse_export`, `App::dialog_export_mp4`, `pano_cli plan-export-menu`, `pano_cli plan-export-target --kind name`, `DocumentVideoExportServices`, and `src/legacy_document_export_services.*`, but the bridge still launches legacy desktop timelapse worker threads, calls `App::rec_export`, calls `Canvas::export_anim_mp4`, owns mobile/Web save callbacks, and emits success messages directly | Preserve current MP4/timelapse export behavior while video export moves toward app/document/renderer/video/platform/storage services | `pp_app_core_document_export_tests`; `pano_cli plan-export-menu --kind animation-mp4`; `pano_cli plan-export-menu --kind timelapse`; `pano_cli plan-export-target --kind name --doc-name demo --suffix -animation`; `pano_cli plan-export-target --kind name --doc-name demo --suffix -timelapse`; `ctest --preset desktop-fast --build-config Debug` | Timelapse and animation MP4 execution, desktop worker threading, frame readback/video encoding handoff, mobile/Web save callbacks, and success reporting are owned by injected app/document/renderer/video/platform/storage services with export dialogs acting only as UI adapters |
|
||||
| DEBT-0045 | Open | Modernization | Options-menu preference execution now consumes pure `pp_app_core` through UI scale, viewport scale, RTL direction, VR mode, VR-controller, auto-timelapse, and canvas cursor-mode callbacks plus `AppPreferenceServices` and `src/legacy_app_preference_services.*`, but the bridge still calls legacy `App::set_ui_scale`, `App::set_ui_rtl`, `App::vr_start`, `App::vr_stop`, `NodeCanvas::set_density`, `NodeCanvas::set_cursor_visibility`, `App::rec_start`, `App::rec_stop`, and `Settings::save` directly | Preserve current options-menu behavior while preferences move toward app/UI/platform/storage services | `pp_app_core_app_preferences_tests`; `pano_cli plan-app-preferences --ui-scale 1.5 --display-density 2 --current-scale 1.6 --scale-option 1 --scale-option 1.5 --rtl`; `ctest --preset desktop-fast --build-config Debug`; `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter` | Preference persistence, UI/layout direction, viewport density, cursor mode, VR mode start/stop/failure handling, VR-controller state, and auto-timelapse recording side effects are owned by injected app/UI/platform/storage services with options-menu callbacks acting only as UI adapters |
|
||||
| DEBT-0046 | Open | Modernization | Startup preference/runtime execution now consumes pure `pp_app_core` through `App::init`, `pano_cli plan-app-startup`, `AppStartupServices`, and `src/legacy_app_startup_services.*`, but the bridge still calls legacy `Settings::set`, `Settings::save`, `App::rec_start`, app VR-controller state mutation, and message-box license warning execution directly | Preserve current startup behavior while app startup moves toward app/preferences/storage/recording/UI services | `pp_app_core_app_startup_tests`; `pano_cli plan-app-startup --run-counter 7 --vr-controllers-disabled --license-invalid`; `pano_cli plan-app-startup --run-counter -1`; `ctest --preset desktop-fast --build-config Debug`; `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter` | Startup preference persistence, auto-timelapse startup, stored VR-controller state, license validation/warning, and startup UI/runtime side effects are owned by injected app/preferences/storage/recording/UI services with `App::init` acting only as orchestration |
|
||||
| DEBT-0047 | Open | Modernization | PPBR brush package export request validation and execution dispatch now consume pure `pp_app_core` through `App::dialog_ppbr_export`, `pano_cli plan-brush-package-export`, `BrushPackageExportServices`, and `src/legacy_brush_package_export_services.*`, but the bridge still reads `NodeDialogExportPPBR`, carries the legacy `Image` header object outside the pure request, converts to `NodePanelBrushPreset::PPBRInfo`, calls `NodePanelBrushPreset::export_ppbr`, owns desktop worker-thread dispatch, dialog destruction, mobile/Web completion, and success-message behavior directly | Preserve current PPBR export behavior while brush assets, PPBR serialization, picker completion, and UI lifetime move toward asset/storage/UI/platform services | `pp_app_core_brush_package_export_tests`; `pano_cli plan-brush-package-export --path D:/Paint/clouds.ppbr --author Artist --dest-path D:/Paint/BrushPreviews --export-data --header-image`; `pano_cli plan-brush-package-export`; `pano_cli plan-brush-package-export --path D:/Paint/clouds.ppbr --dest-path D:/Paint/BrushPreviews --no-export-data`; `ctest --preset desktop-fast --build-config Debug`; `cmake --build --preset windows-msvc-default --config Debug --target PanoPainter` | PPBR metadata collection, header-image ownership, serialization, picker-selected path execution, desktop threading, dialog lifetime, and success UI are owned by injected brush asset/storage/UI/platform services with `App::dialog_ppbr_export` acting only as a UI adapter |
|
||||
|
||||
## Closed Debt
|
||||
|
||||
|
||||
@@ -778,6 +778,12 @@ executor and `src/legacy_document_export_services.*`, preserving mobile/Web
|
||||
suggested-name save callbacks, desktop worker-thread timelapse export,
|
||||
`App::rec_export`, animation `Canvas::export_anim_mp4` dispatch, and existing
|
||||
success messages while retained execution remains tracked under `DEBT-0044`.
|
||||
`App::dialog_ppbr_export` now routes picker-selected PPBR brush package exports
|
||||
through the app-core brush package export executor and
|
||||
`src/legacy_brush_package_export_services.*`, preserving dialog metadata
|
||||
collection, legacy `Image` header ownership, desktop worker-thread export,
|
||||
mobile/Web save completion, `NodePanelBrushPreset::export_ppbr`, and existing
|
||||
success messages while retained execution remains tracked under `DEBT-0047`.
|
||||
|
||||
Implementation tasks:
|
||||
|
||||
@@ -1369,6 +1375,14 @@ Results:
|
||||
- Focused startup CTest coverage passed for `pp_app_core_app_startup_tests`,
|
||||
`pano_cli_plan_app_startup_smoke`, and
|
||||
`pano_cli_plan_app_startup_rejects_negative_counter`.
|
||||
- `PanoPainter`, `pp_app_core_brush_package_export_tests`, and `pano_cli` built
|
||||
after PPBR brush package export request validation and dispatch moved behind
|
||||
app-core brush package services.
|
||||
- Focused PPBR export CTest coverage passed for
|
||||
`pp_app_core_brush_package_export_tests`,
|
||||
`pano_cli_plan_brush_package_export_smoke`,
|
||||
`pano_cli_plan_brush_package_export_rejects_empty_path`, and
|
||||
`pano_cli_plan_brush_package_export_dest_without_data_smoke`.
|
||||
- `pp_app_core_document_recording_tests` passed, covering recording start/stop,
|
||||
clear, platform recorded-file cleanup, frame-count reset, export progress
|
||||
totals, and oversized progress-total clamping.
|
||||
|
||||
63
src/app_core/brush_package_export.h
Normal file
63
src/app_core/brush_package_export.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace pp::app {
|
||||
|
||||
struct BrushPackageExportRequest {
|
||||
std::string author;
|
||||
std::string email;
|
||||
std::string url;
|
||||
std::string description;
|
||||
std::string destination_path;
|
||||
bool export_data = false;
|
||||
bool has_header_image = false;
|
||||
};
|
||||
|
||||
class BrushPackageExportServices {
|
||||
public:
|
||||
virtual ~BrushPackageExportServices() = default;
|
||||
|
||||
virtual void export_brush_package(std::string_view path, const BrushPackageExportRequest& request) = 0;
|
||||
};
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status validate_brush_package_export_path(std::string_view path) noexcept
|
||||
{
|
||||
if (path.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("brush package export path must not be empty");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status validate_brush_package_export_request(
|
||||
std::string_view path,
|
||||
const BrushPackageExportRequest& request) noexcept
|
||||
{
|
||||
(void)request;
|
||||
const auto path_status = validate_brush_package_export_path(path);
|
||||
if (!path_status.ok()) {
|
||||
return path_status;
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
[[nodiscard]] inline pp::foundation::Status execute_brush_package_export(
|
||||
std::string_view path,
|
||||
const BrushPackageExportRequest& request,
|
||||
BrushPackageExportServices& services)
|
||||
{
|
||||
const auto status = validate_brush_package_export_request(path, request);
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
services.export_brush_package(path, request);
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
} // namespace pp::app
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "app_core/document_export.h"
|
||||
#include "app_core/document_session.h"
|
||||
#include "legacy_document_canvas_services.h"
|
||||
#include "legacy_brush_package_export_services.h"
|
||||
#include "legacy_document_export_services.h"
|
||||
#include "legacy_document_layer_services.h"
|
||||
#include "legacy_document_session_services.h"
|
||||
@@ -520,33 +521,34 @@ void App::dialog_ppbr_export()
|
||||
auto root = layout[main_id];
|
||||
auto dialog = root->add_child_ref<NodeDialogExportPPBR>();
|
||||
dialog->btn_ok->on_click = [this, dialog] (Node*) {
|
||||
NodePanelBrushPreset::PPBRInfo info;
|
||||
info.author = dialog->txt_author->m_text;
|
||||
info.url = dialog->txt_url->m_text;
|
||||
info.email = dialog->txt_email->m_text;
|
||||
info.descr = dialog->txt_descr->m_text;
|
||||
info.header_image = dialog->m_header_image;
|
||||
info.dest_path = dialog->m_dest_path;
|
||||
if (dialog->export_check)
|
||||
info.export_data = dialog->export_check->checked;
|
||||
const auto request = pp::panopainter::make_legacy_brush_package_export_request(*dialog);
|
||||
#if __IOS__ || __WEB__
|
||||
App::I->pick_file_save("ppbr", "exported-brushes",
|
||||
[this, dialog, info] (std::string path) {
|
||||
presets->export_ppbr(path, info);
|
||||
[this, dialog, request] (std::string path) {
|
||||
const auto status = pp::panopainter::execute_legacy_brush_package_export(
|
||||
*this,
|
||||
*dialog,
|
||||
request,
|
||||
path,
|
||||
pp::panopainter::LegacyBrushPackageExportMode::inline_export_only);
|
||||
if (!status.ok())
|
||||
LOG("PPBR export failed: %s", status.message);
|
||||
},
|
||||
[dialog] (const std::string& path, bool saved) {
|
||||
if (saved)
|
||||
dialog->destroy();
|
||||
(void)path;
|
||||
pp::panopainter::complete_legacy_brush_package_export(*dialog, saved);
|
||||
}
|
||||
);
|
||||
#else
|
||||
App::I->pick_file_save({ "ppbr" }, [this, dialog, info] (std::string path) {
|
||||
std::thread([this, path, dialog, info] {
|
||||
BT_SetTerminate();
|
||||
presets->export_ppbr(path, info);
|
||||
dialog->destroy();
|
||||
App::I->message_box("Export PPBR", "Brushes exported to:\n" + path);
|
||||
}).detach();
|
||||
App::I->pick_file_save({ "ppbr" }, [this, dialog, request] (std::string path) {
|
||||
const auto status = pp::panopainter::execute_legacy_brush_package_export(
|
||||
*this,
|
||||
*dialog,
|
||||
request,
|
||||
path,
|
||||
pp::panopainter::LegacyBrushPackageExportMode::desktop_async_close_and_message);
|
||||
if (!status.ok())
|
||||
LOG("PPBR export failed: %s", status.message);
|
||||
});
|
||||
#endif
|
||||
};
|
||||
|
||||
100
src/legacy_brush_package_export_services.cpp
Normal file
100
src/legacy_brush_package_export_services.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "legacy_brush_package_export_services.h"
|
||||
|
||||
#include "app.h"
|
||||
#include "node_dialog_export_ppbr.h"
|
||||
#include "node_panel_brush.h"
|
||||
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
namespace pp::panopainter {
|
||||
namespace {
|
||||
|
||||
NodePanelBrushPreset::PPBRInfo to_legacy_ppbr_info(
|
||||
const pp::app::BrushPackageExportRequest& request,
|
||||
const NodeDialogExportPPBR& dialog)
|
||||
{
|
||||
NodePanelBrushPreset::PPBRInfo info;
|
||||
info.author = request.author;
|
||||
info.email = request.email;
|
||||
info.url = request.url;
|
||||
info.descr = request.description;
|
||||
info.header_image = dialog.m_header_image;
|
||||
info.export_data = request.export_data;
|
||||
info.dest_path = request.destination_path;
|
||||
return info;
|
||||
}
|
||||
|
||||
class LegacyBrushPackageExportServices final : public pp::app::BrushPackageExportServices {
|
||||
public:
|
||||
LegacyBrushPackageExportServices(
|
||||
App& app,
|
||||
NodeDialogExportPPBR& dialog,
|
||||
LegacyBrushPackageExportMode mode) noexcept
|
||||
: app_(app)
|
||||
, dialog_(dialog)
|
||||
, mode_(mode)
|
||||
{
|
||||
}
|
||||
|
||||
void export_brush_package(std::string_view path, const pp::app::BrushPackageExportRequest& request) override
|
||||
{
|
||||
const auto path_string = std::string(path);
|
||||
const auto info = to_legacy_ppbr_info(request, dialog_);
|
||||
if (mode_ == LegacyBrushPackageExportMode::desktop_async_close_and_message) {
|
||||
auto* app = &app_;
|
||||
auto* dialog = &dialog_;
|
||||
std::thread([app, dialog, path_string, info] {
|
||||
BT_SetTerminate();
|
||||
app->presets->export_ppbr(path_string, info);
|
||||
dialog->destroy();
|
||||
app->message_box("Export PPBR", "Brushes exported to:\n" + path_string);
|
||||
}).detach();
|
||||
return;
|
||||
}
|
||||
|
||||
app_.presets->export_ppbr(path_string, info);
|
||||
}
|
||||
|
||||
private:
|
||||
App& app_;
|
||||
NodeDialogExportPPBR& dialog_;
|
||||
LegacyBrushPackageExportMode mode_ = LegacyBrushPackageExportMode::inline_export_only;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
pp::app::BrushPackageExportRequest make_legacy_brush_package_export_request(const NodeDialogExportPPBR& dialog)
|
||||
{
|
||||
pp::app::BrushPackageExportRequest request;
|
||||
request.author = dialog.txt_author ? dialog.txt_author->m_text : std::string();
|
||||
request.email = dialog.txt_email ? dialog.txt_email->m_text : std::string();
|
||||
request.url = dialog.txt_url ? dialog.txt_url->m_text : std::string();
|
||||
request.description = dialog.txt_descr ? dialog.txt_descr->m_text : std::string();
|
||||
request.destination_path = dialog.m_dest_path;
|
||||
request.export_data = dialog.export_check && dialog.export_check->checked;
|
||||
request.has_header_image = static_cast<bool>(dialog.m_header_image);
|
||||
return request;
|
||||
}
|
||||
|
||||
pp::foundation::Status execute_legacy_brush_package_export(
|
||||
App& app,
|
||||
NodeDialogExportPPBR& dialog,
|
||||
const pp::app::BrushPackageExportRequest& request,
|
||||
std::string_view path,
|
||||
LegacyBrushPackageExportMode mode)
|
||||
{
|
||||
LegacyBrushPackageExportServices services(app, dialog, mode);
|
||||
return pp::app::execute_brush_package_export(path, request, services);
|
||||
}
|
||||
|
||||
void complete_legacy_brush_package_export(NodeDialogExportPPBR& dialog, bool saved)
|
||||
{
|
||||
if (saved) {
|
||||
dialog.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace pp::panopainter
|
||||
30
src/legacy_brush_package_export_services.h
Normal file
30
src/legacy_brush_package_export_services.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "app_core/brush_package_export.h"
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
class App;
|
||||
class NodeDialogExportPPBR;
|
||||
|
||||
namespace pp::panopainter {
|
||||
|
||||
enum class LegacyBrushPackageExportMode {
|
||||
inline_export_only,
|
||||
desktop_async_close_and_message,
|
||||
};
|
||||
|
||||
[[nodiscard]] pp::app::BrushPackageExportRequest make_legacy_brush_package_export_request(
|
||||
const NodeDialogExportPPBR& dialog);
|
||||
|
||||
[[nodiscard]] pp::foundation::Status execute_legacy_brush_package_export(
|
||||
App& app,
|
||||
NodeDialogExportPPBR& dialog,
|
||||
const pp::app::BrushPackageExportRequest& request,
|
||||
std::string_view path,
|
||||
LegacyBrushPackageExportMode mode);
|
||||
|
||||
void complete_legacy_brush_package_export(NodeDialogExportPPBR& dialog, bool saved);
|
||||
|
||||
} // namespace pp::panopainter
|
||||
@@ -288,6 +288,16 @@ add_test(NAME pp_app_core_brush_ui_tests COMMAND pp_app_core_brush_ui_tests)
|
||||
set_tests_properties(pp_app_core_brush_ui_tests PROPERTIES
|
||||
LABELS "app;paint;desktop-fast;fuzz")
|
||||
|
||||
add_executable(pp_app_core_brush_package_export_tests
|
||||
app_core/brush_package_export_tests.cpp)
|
||||
target_link_libraries(pp_app_core_brush_package_export_tests PRIVATE
|
||||
pp_app_core
|
||||
pp_test_harness)
|
||||
|
||||
add_test(NAME pp_app_core_brush_package_export_tests COMMAND pp_app_core_brush_package_export_tests)
|
||||
set_tests_properties(pp_app_core_brush_package_export_tests PROPERTIES
|
||||
LABELS "app;paint;assets;desktop-fast;fuzz")
|
||||
|
||||
add_executable(pp_app_core_canvas_tool_ui_tests
|
||||
app_core/canvas_tool_ui_tests.cpp)
|
||||
target_link_libraries(pp_app_core_canvas_tool_ui_tests PRIVATE
|
||||
@@ -877,6 +887,37 @@ if(TARGET pano_cli)
|
||||
WILL_FAIL TRUE
|
||||
PASS_REGULAR_EXPRESSION "\"command\":\"plan-app-startup\".*\"message\":\"run counter must not be negative\"")
|
||||
|
||||
add_test(NAME pano_cli_plan_brush_package_export_smoke
|
||||
COMMAND pano_cli plan-brush-package-export
|
||||
--path D:/Paint/clouds.ppbr
|
||||
--author Artist
|
||||
--email artist@example.test
|
||||
--url https://example.test/brushes
|
||||
--description "Cloud brush set"
|
||||
--dest-path D:/Paint/BrushPreviews
|
||||
--export-data
|
||||
--header-image)
|
||||
set_tests_properties(pano_cli_plan_brush_package_export_smoke PROPERTIES
|
||||
LABELS "app;paint;assets;integration;desktop-fast"
|
||||
PASS_REGULAR_EXPRESSION "\"command\":\"plan-brush-package-export\".*\"path\":\"D:/Paint/clouds.ppbr\".*\"author\":\"Artist\".*\"destPath\":\"D:/Paint/BrushPreviews\".*\"exportData\":true.*\"hasHeaderImage\":true.*\"dispatches\":1")
|
||||
|
||||
add_test(NAME pano_cli_plan_brush_package_export_rejects_empty_path
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-DPANO_CLI=$<TARGET_FILE:pano_cli>
|
||||
"-DEXPECTED_OUTPUT=brush package export path must not be empty"
|
||||
-P "${CMAKE_CURRENT_SOURCE_DIR}/cmake/expect_pano_cli_plan_brush_package_export_failure.cmake")
|
||||
set_tests_properties(pano_cli_plan_brush_package_export_rejects_empty_path PROPERTIES
|
||||
LABELS "app;paint;assets;integration;desktop-fast;fuzz")
|
||||
|
||||
add_test(NAME pano_cli_plan_brush_package_export_dest_without_data_smoke
|
||||
COMMAND pano_cli plan-brush-package-export
|
||||
--path D:/Paint/clouds.ppbr
|
||||
--dest-path D:/Paint/BrushPreviews
|
||||
--no-export-data)
|
||||
set_tests_properties(pano_cli_plan_brush_package_export_dest_without_data_smoke PROPERTIES
|
||||
LABELS "app;paint;assets;integration;desktop-fast;fuzz"
|
||||
PASS_REGULAR_EXPRESSION "\"command\":\"plan-brush-package-export\".*\"destPath\":\"D:/Paint/BrushPreviews\".*\"exportData\":false.*\"dispatches\":1")
|
||||
|
||||
add_test(NAME pano_cli_plan_tools_menu_shortcuts_smoke
|
||||
COMMAND pano_cli plan-tools-menu --command shortcuts)
|
||||
set_tests_properties(pano_cli_plan_tools_menu_shortcuts_smoke PROPERTIES
|
||||
|
||||
94
tests/app_core/brush_package_export_tests.cpp
Normal file
94
tests/app_core/brush_package_export_tests.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "app_core/brush_package_export.h"
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace {
|
||||
|
||||
class FakeBrushPackageExportServices final : public pp::app::BrushPackageExportServices {
|
||||
public:
|
||||
void export_brush_package(std::string_view path, const pp::app::BrushPackageExportRequest& request) override
|
||||
{
|
||||
exports += 1;
|
||||
last_path = std::string(path);
|
||||
last_request = request;
|
||||
}
|
||||
|
||||
int exports = 0;
|
||||
std::string last_path;
|
||||
pp::app::BrushPackageExportRequest last_request;
|
||||
};
|
||||
|
||||
void validates_path_and_preserves_metadata_edges(pp::tests::Harness& harness)
|
||||
{
|
||||
pp::app::BrushPackageExportRequest request;
|
||||
request.author = "Pano Artist";
|
||||
request.email = "artist@example.test";
|
||||
request.url = "https://example.test/brushes";
|
||||
request.description = "Cloud brushes";
|
||||
request.export_data = true;
|
||||
request.destination_path = "D:/Paint/BrushPreviews";
|
||||
request.has_header_image = true;
|
||||
|
||||
PP_EXPECT(harness, pp::app::validate_brush_package_export_request("D:/Paint/clouds.ppbr", request).ok());
|
||||
PP_EXPECT(harness, !pp::app::validate_brush_package_export_request("", request).ok());
|
||||
|
||||
request.export_data = false;
|
||||
PP_EXPECT(harness, pp::app::validate_brush_package_export_request("D:/Paint/clouds.ppbr", request).ok());
|
||||
|
||||
request.destination_path.clear();
|
||||
PP_EXPECT(harness, pp::app::validate_brush_package_export_request("D:/Paint/clouds.ppbr", request).ok());
|
||||
}
|
||||
|
||||
void executor_dispatches_export_request(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeBrushPackageExportServices services;
|
||||
pp::app::BrushPackageExportRequest request;
|
||||
request.author = "Pano Artist";
|
||||
request.email = "artist@example.test";
|
||||
request.url = "https://example.test/brushes";
|
||||
request.description = "Cloud brushes";
|
||||
request.export_data = true;
|
||||
request.destination_path = "D:/Paint/BrushPreviews";
|
||||
request.has_header_image = true;
|
||||
|
||||
const auto status = pp::app::execute_brush_package_export("D:/Paint/clouds.ppbr", request, services);
|
||||
PP_EXPECT(harness, status.ok());
|
||||
PP_EXPECT(harness, services.exports == 1);
|
||||
PP_EXPECT(harness, services.last_path == "D:/Paint/clouds.ppbr");
|
||||
PP_EXPECT(harness, services.last_request.author == "Pano Artist");
|
||||
PP_EXPECT(harness, services.last_request.email == "artist@example.test");
|
||||
PP_EXPECT(harness, services.last_request.url == "https://example.test/brushes");
|
||||
PP_EXPECT(harness, services.last_request.description == "Cloud brushes");
|
||||
PP_EXPECT(harness, services.last_request.destination_path == "D:/Paint/BrushPreviews");
|
||||
PP_EXPECT(harness, services.last_request.export_data);
|
||||
PP_EXPECT(harness, services.last_request.has_header_image);
|
||||
}
|
||||
|
||||
void executor_rejects_malformed_requests_before_dispatch(pp::tests::Harness& harness)
|
||||
{
|
||||
FakeBrushPackageExportServices services;
|
||||
pp::app::BrushPackageExportRequest empty_path_request;
|
||||
PP_EXPECT(harness, !pp::app::execute_brush_package_export("", empty_path_request, services).ok());
|
||||
PP_EXPECT(harness, services.exports == 0);
|
||||
|
||||
pp::app::BrushPackageExportRequest legacy_flexible_request;
|
||||
legacy_flexible_request.destination_path = "D:/Paint/BrushPreviews";
|
||||
legacy_flexible_request.export_data = false;
|
||||
PP_EXPECT(
|
||||
harness,
|
||||
pp::app::execute_brush_package_export("D:/Paint/clouds.ppbr", legacy_flexible_request, services).ok());
|
||||
PP_EXPECT(harness, services.exports == 1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
pp::tests::Harness harness;
|
||||
harness.run("validates path and preserves metadata edges", validates_path_and_preserves_metadata_edges);
|
||||
harness.run("executor dispatches export request", executor_dispatches_export_request);
|
||||
harness.run("executor rejects malformed requests before dispatch", executor_rejects_malformed_requests_before_dispatch);
|
||||
return harness.finish();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
if(NOT DEFINED PANO_CLI)
|
||||
message(FATAL_ERROR "PANO_CLI must be set")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED EXPECTED_OUTPUT)
|
||||
message(FATAL_ERROR "EXPECTED_OUTPUT must be set")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${PANO_CLI}" plan-brush-package-export
|
||||
RESULT_VARIABLE result
|
||||
OUTPUT_VARIABLE output
|
||||
ERROR_VARIABLE error)
|
||||
|
||||
if(result EQUAL 0)
|
||||
message(FATAL_ERROR "Expected pano_cli plan-brush-package-export to fail, but it exited 0")
|
||||
endif()
|
||||
|
||||
set(combined_output "${output}${error}")
|
||||
string(FIND "${combined_output}" "${EXPECTED_OUTPUT}" expected_index)
|
||||
if(expected_index LESS 0)
|
||||
message(FATAL_ERROR
|
||||
"Expected output to contain '${EXPECTED_OUTPUT}', got: ${combined_output}")
|
||||
endif()
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "app_core/app_preferences.h"
|
||||
#include "app_core/app_status.h"
|
||||
#include "app_core/app_startup.h"
|
||||
#include "app_core/brush_package_export.h"
|
||||
#include "app_core/brush_ui.h"
|
||||
#include "app_core/canvas_hotkey.h"
|
||||
#include "app_core/canvas_tool_ui.h"
|
||||
@@ -235,6 +236,17 @@ struct PlanAppStartupArgs {
|
||||
bool license_valid = true;
|
||||
};
|
||||
|
||||
struct PlanBrushPackageExportArgs {
|
||||
std::string path;
|
||||
std::string author;
|
||||
std::string email;
|
||||
std::string url;
|
||||
std::string description;
|
||||
std::string destination_path;
|
||||
bool export_data = false;
|
||||
bool has_header_image = false;
|
||||
};
|
||||
|
||||
struct PlanAppStatusArgs {
|
||||
std::string document_name = "no-name";
|
||||
bool unsaved = false;
|
||||
@@ -1862,6 +1874,7 @@ void print_help()
|
||||
<< " plan-app-preferences [--ui-scale N] [--display-density N] [--current-scale N] [--scale-option N] [--viewport-scale N] [--rtl] [--timelapse-disabled] [--recording-running] [--vr-controllers-disabled] [--cursor-mode N]\n"
|
||||
<< " plan-app-startup [--run-counter N] [--auto-timelapse-disabled] [--vr-controllers-disabled] [--license-invalid]\n"
|
||||
<< " plan-app-status [--doc-name NAME] [--unsaved] [--resolution N] [--resolution-index N] [--zoom N] [--history-bytes N] [--recording-running] [--encoder-available] [--encoded-frames N] [--framebuffer-fetch] [--float32] [--float32-linear] [--float16]\n"
|
||||
<< " plan-brush-package-export --path FILE [--author NAME] [--email EMAIL] [--url URL] [--description TEXT] [--dest-path DIR] [--export-data|--no-export-data] [--header-image]\n"
|
||||
<< " plan-tools-menu --command panels|options|clear-grids|reset-camera|shortcuts|sonarpen [--sonarpen-available]\n"
|
||||
<< " plan-tools-panel --panel presets|color|color-advanced|layers|brush|grids|animation [--already-visible]\n"
|
||||
<< " plan-about-menu --command help|about|news|crash|performance [--version-major N] [--version-minor N] [--version-fix N] [--no-diagnostics] [--no-canvas]\n"
|
||||
@@ -3489,6 +3502,98 @@ int plan_app_startup(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_brush_package_export_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
PlanBrushPackageExportArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--path" || key == "--author" || key == "--email" || key == "--url"
|
||||
|| key == "--description" || key == "--dest-path") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
if (key == "--path") {
|
||||
args.path = argv[++i];
|
||||
} else if (key == "--author") {
|
||||
args.author = argv[++i];
|
||||
} else if (key == "--email") {
|
||||
args.email = argv[++i];
|
||||
} else if (key == "--url") {
|
||||
args.url = argv[++i];
|
||||
} else if (key == "--description") {
|
||||
args.description = argv[++i];
|
||||
} else {
|
||||
args.destination_path = argv[++i];
|
||||
}
|
||||
} else if (key == "--export-data") {
|
||||
args.export_data = true;
|
||||
} else if (key == "--no-export-data") {
|
||||
args.export_data = false;
|
||||
} else if (key == "--header-image") {
|
||||
args.has_header_image = true;
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
class CliBrushPackageExportServices final : public pp::app::BrushPackageExportServices {
|
||||
public:
|
||||
void export_brush_package(std::string_view path, const pp::app::BrushPackageExportRequest& request) override
|
||||
{
|
||||
exports += 1;
|
||||
last_path = std::string(path);
|
||||
last_request = request;
|
||||
}
|
||||
|
||||
int exports = 0;
|
||||
std::string last_path;
|
||||
pp::app::BrushPackageExportRequest last_request;
|
||||
};
|
||||
|
||||
int plan_brush_package_export(int argc, char** argv)
|
||||
{
|
||||
PlanBrushPackageExportArgs args;
|
||||
const auto status = parse_plan_brush_package_export_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("plan-brush-package-export", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
pp::app::BrushPackageExportRequest request;
|
||||
request.author = args.author;
|
||||
request.email = args.email;
|
||||
request.url = args.url;
|
||||
request.description = args.description;
|
||||
request.destination_path = args.destination_path;
|
||||
request.export_data = args.export_data;
|
||||
request.has_header_image = args.has_header_image;
|
||||
|
||||
CliBrushPackageExportServices services;
|
||||
const auto export_status = pp::app::execute_brush_package_export(args.path, request, services);
|
||||
if (!export_status.ok()) {
|
||||
print_error("plan-brush-package-export", export_status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::cout << "{\"ok\":true,\"command\":\"plan-brush-package-export\""
|
||||
<< ",\"request\":{\"path\":\"" << json_escape(services.last_path)
|
||||
<< "\",\"author\":\"" << json_escape(services.last_request.author)
|
||||
<< "\",\"email\":\"" << json_escape(services.last_request.email)
|
||||
<< "\",\"url\":\"" << json_escape(services.last_request.url)
|
||||
<< "\",\"description\":\"" << json_escape(services.last_request.description)
|
||||
<< "\",\"destPath\":\"" << json_escape(services.last_request.destination_path)
|
||||
<< "\",\"exportData\":" << json_bool(services.last_request.export_data)
|
||||
<< ",\"hasHeaderImage\":" << json_bool(services.last_request.has_header_image)
|
||||
<< "},\"dispatches\":" << services.exports
|
||||
<< "}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_plan_tools_menu_args(
|
||||
int argc,
|
||||
char** argv,
|
||||
@@ -8569,6 +8674,10 @@ int main(int argc, char** argv)
|
||||
return plan_app_startup(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-brush-package-export") {
|
||||
return plan_brush_package_export(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "plan-app-status") {
|
||||
return plan_app_status(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user