Add Android headless preset and parser tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "foundation/parse.h"
|
||||
#include "foundation/result.h"
|
||||
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
@@ -13,14 +13,6 @@ struct DocumentArgs {
|
||||
std::uint32_t layers = 1;
|
||||
};
|
||||
|
||||
bool parse_u32(std::string_view text, std::uint32_t& value)
|
||||
{
|
||||
const auto* begin = text.data();
|
||||
const auto* end = text.data() + text.size();
|
||||
const auto [ptr, ec] = std::from_chars(begin, end, value);
|
||||
return ec == std::errc {} && ptr == end;
|
||||
}
|
||||
|
||||
void print_error(std::string_view command, std::string_view message)
|
||||
{
|
||||
std::cout << "{\"ok\":false,\"command\":\"" << command
|
||||
@@ -44,17 +36,17 @@ pp::foundation::Status parse_document_args(int argc, char** argv, DocumentArgs&
|
||||
return pp::foundation::Status::invalid_argument("missing value for option");
|
||||
}
|
||||
|
||||
std::uint32_t value = 0;
|
||||
if (!parse_u32(argv[++i], value)) {
|
||||
return pp::foundation::Status::invalid_argument("option value must be an unsigned integer");
|
||||
const auto value = pp::foundation::parse_u32(argv[++i]);
|
||||
if (!value) {
|
||||
return value.status();
|
||||
}
|
||||
|
||||
if (key == "--width") {
|
||||
args.width = value;
|
||||
args.width = value.value();
|
||||
} else if (key == "--height") {
|
||||
args.height = value;
|
||||
args.height = value.value();
|
||||
} else {
|
||||
args.layers = value;
|
||||
args.layers = value.value();
|
||||
}
|
||||
} else {
|
||||
return pp::foundation::Status::invalid_argument("unknown option");
|
||||
|
||||
Reference in New Issue
Block a user