Add Android headless preset and parser tests
This commit is contained in:
@@ -5,14 +5,25 @@ target_link_libraries(pp_test_harness INTERFACE
|
||||
pp_project_options
|
||||
pp_project_warnings)
|
||||
|
||||
add_executable(pp_foundation_tests
|
||||
foundation/binary_stream_tests.cpp)
|
||||
target_link_libraries(pp_foundation_tests PRIVATE
|
||||
add_executable(pp_foundation_binary_stream_tests
|
||||
foundation/binary_stream_tests.cpp
|
||||
)
|
||||
target_link_libraries(pp_foundation_binary_stream_tests PRIVATE
|
||||
pp_foundation
|
||||
pp_test_harness)
|
||||
|
||||
add_test(NAME pp_foundation_tests COMMAND pp_foundation_tests)
|
||||
set_tests_properties(pp_foundation_tests PROPERTIES
|
||||
add_test(NAME pp_foundation_binary_stream_tests COMMAND pp_foundation_binary_stream_tests)
|
||||
set_tests_properties(pp_foundation_binary_stream_tests PROPERTIES
|
||||
LABELS "foundation;desktop-fast")
|
||||
|
||||
add_executable(pp_foundation_parse_tests
|
||||
foundation/parse_tests.cpp)
|
||||
target_link_libraries(pp_foundation_parse_tests PRIVATE
|
||||
pp_foundation
|
||||
pp_test_harness)
|
||||
|
||||
add_test(NAME pp_foundation_parse_tests COMMAND pp_foundation_parse_tests)
|
||||
set_tests_properties(pp_foundation_parse_tests PROPERTIES
|
||||
LABELS "foundation;desktop-fast")
|
||||
|
||||
if(TARGET pano_cli)
|
||||
|
||||
66
tests/foundation/parse_tests.cpp
Normal file
66
tests/foundation/parse_tests.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "foundation/parse.h"
|
||||
#include "test_harness.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
using pp::foundation::parse_u32;
|
||||
using pp::foundation::StatusCode;
|
||||
|
||||
namespace {
|
||||
|
||||
void accepts_decimal_uint32_values(pp::tests::Harness& h)
|
||||
{
|
||||
const auto zero = parse_u32("0");
|
||||
const auto ordinary = parse_u32("12345");
|
||||
const auto max = parse_u32("4294967295");
|
||||
|
||||
PP_EXPECT(h, zero.ok());
|
||||
PP_EXPECT(h, zero.value() == 0U);
|
||||
PP_EXPECT(h, ordinary.ok());
|
||||
PP_EXPECT(h, ordinary.value() == 12345U);
|
||||
PP_EXPECT(h, max.ok());
|
||||
PP_EXPECT(h, max.value() == UINT32_MAX);
|
||||
}
|
||||
|
||||
void rejects_empty_signed_and_mixed_input(pp::tests::Harness& h)
|
||||
{
|
||||
const auto empty = parse_u32("");
|
||||
const auto negative = parse_u32("-1");
|
||||
const auto positive = parse_u32("+1");
|
||||
const auto trailing = parse_u32("12px");
|
||||
const auto spaced = parse_u32(" 12");
|
||||
|
||||
PP_EXPECT(h, !empty.ok());
|
||||
PP_EXPECT(h, empty.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !negative.ok());
|
||||
PP_EXPECT(h, negative.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !positive.ok());
|
||||
PP_EXPECT(h, positive.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !trailing.ok());
|
||||
PP_EXPECT(h, trailing.status().code == StatusCode::invalid_argument);
|
||||
PP_EXPECT(h, !spaced.ok());
|
||||
PP_EXPECT(h, spaced.status().code == StatusCode::invalid_argument);
|
||||
}
|
||||
|
||||
void rejects_overflow_without_wrapping(pp::tests::Harness& h)
|
||||
{
|
||||
const auto overflow = parse_u32("4294967296");
|
||||
const auto very_large = parse_u32("999999999999999999999999999999999999");
|
||||
|
||||
PP_EXPECT(h, !overflow.ok());
|
||||
PP_EXPECT(h, overflow.status().code == StatusCode::out_of_range);
|
||||
PP_EXPECT(h, !very_large.ok());
|
||||
PP_EXPECT(h, very_large.status().code == StatusCode::out_of_range);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
pp::tests::Harness harness;
|
||||
harness.run("accepts_decimal_uint32_values", accepts_decimal_uint32_values);
|
||||
harness.run("rejects_empty_signed_and_mixed_input", rejects_empty_signed_and_mixed_input);
|
||||
harness.run("rejects_overflow_without_wrapping", rejects_overflow_without_wrapping);
|
||||
return harness.finish();
|
||||
}
|
||||
Reference in New Issue
Block a user