Add PPI header recognition tests
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "assets/image_format.h"
|
||||
#include "assets/ppi_header.h"
|
||||
#include "document/document.h"
|
||||
#include "foundation/parse.h"
|
||||
#include "foundation/result.h"
|
||||
@@ -28,6 +29,10 @@ struct ParseLayoutArgs {
|
||||
std::string path;
|
||||
};
|
||||
|
||||
struct InspectProjectArgs {
|
||||
std::string path;
|
||||
};
|
||||
|
||||
void print_error(std::string_view command, std::string_view message)
|
||||
{
|
||||
std::cout << "{\"ok\":false,\"command\":\"" << command
|
||||
@@ -40,6 +45,7 @@ void print_help()
|
||||
<< "pano_cli commands:\n"
|
||||
<< " create-document --width N --height N [--layers N]\n"
|
||||
<< " inspect-image --path FILE\n"
|
||||
<< " inspect-project --path FILE\n"
|
||||
<< " parse-layout --path FILE\n"
|
||||
<< " --help\n";
|
||||
}
|
||||
@@ -166,6 +172,68 @@ int inspect_image(int argc, char** argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_inspect_project_args(int argc, char** argv, InspectProjectArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
const std::string_view key(argv[i]);
|
||||
if (key == "--path") {
|
||||
if (i + 1 >= argc) {
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
|
||||
args.path = argv[++i];
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
}
|
||||
}
|
||||
|
||||
if (args.path.empty()) {
|
||||
return pp::foundation::Status::invalid_argument("path must not be empty");
|
||||
}
|
||||
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
int inspect_project(int argc, char** argv)
|
||||
{
|
||||
InspectProjectArgs args;
|
||||
const auto status = parse_inspect_project_args(argc, argv, args);
|
||||
if (!status.ok()) {
|
||||
print_error("inspect-project", status.message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::ifstream stream(args.path, std::ios::binary);
|
||||
if (!stream) {
|
||||
print_error("inspect-project", "project file could not be opened");
|
||||
return 2;
|
||||
}
|
||||
|
||||
const std::vector<char> chars {
|
||||
std::istreambuf_iterator<char>(stream),
|
||||
std::istreambuf_iterator<char>()
|
||||
};
|
||||
const auto* data = reinterpret_cast<const std::byte*>(chars.data());
|
||||
const auto header = pp::assets::parse_ppi_header(std::span<const std::byte>(data, chars.size()));
|
||||
if (!header) {
|
||||
print_error("inspect-project", header.status().message);
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::cout << "{\"ok\":true,\"command\":\"inspect-project\""
|
||||
<< ",\"documentVersion\":\"" << header.value().document_version.major
|
||||
<< "." << header.value().document_version.minor << "\""
|
||||
<< ",\"softwareVersion\":\"" << header.value().software_version.major
|
||||
<< "." << header.value().software_version.minor
|
||||
<< "." << header.value().software_version.fix
|
||||
<< "." << header.value().software_version.build << "\""
|
||||
<< ",\"thumbnail\":{\"width\":" << header.value().thumbnail.width
|
||||
<< ",\"height\":" << header.value().thumbnail.height
|
||||
<< ",\"components\":" << header.value().thumbnail.components
|
||||
<< "}}\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
pp::foundation::Status parse_layout_args(int argc, char** argv, ParseLayoutArgs& args)
|
||||
{
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
@@ -243,6 +311,10 @@ int main(int argc, char** argv)
|
||||
return inspect_image(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "inspect-project") {
|
||||
return inspect_project(argc, argv);
|
||||
}
|
||||
|
||||
if (command == "parse-layout") {
|
||||
return parse_layout(argc, argv);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user