diff --git a/.gitignore b/.gitignore index 36fa4976..48757cde 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,7 @@ *.cbor *.json *.fb +*.flexbuf *.msgpack *.toml *.xml diff --git a/tests/bson/CMakeLists.txt b/tests/bson/CMakeLists.txt index 318ba7a0..40d4d467 100644 --- a/tests/bson/CMakeLists.txt +++ b/tests/bson/CMakeLists.txt @@ -1,8 +1,18 @@ project(reflect-cpp-bson-tests) -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp") -add_executable(reflect-cpp-bson-tests ${SOURCES}) +add_executable( + reflect-cpp-bson-tests + ${SOURCES} + "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/src/gtest_main.cc" +) target_include_directories(reflect-cpp-bson-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") -target_link_libraries(reflect-cpp-bson-tests PRIVATE reflectcpp) + +target_link_libraries( + reflect-cpp-bson-tests + PRIVATE + reflectcpp + "${REFLECT_CPP_GTEST_LIB}" +) diff --git a/tests/bson/test_array.cpp b/tests/bson/test_array.cpp index 970ffd11..c50694fc 100644 --- a/tests/bson/test_array.cpp +++ b/tests/bson/test_array.cpp @@ -1,5 +1,3 @@ -#include "test_array.hpp" - #include #include #include @@ -8,7 +6,7 @@ #include // Make sure things still compile when -// rfl.hpp is included after rfl/bson.hpp. +// rfl.hpp is included after rfl/cbor.hpp. #include #include "write_and_read.hpp" @@ -21,9 +19,7 @@ struct Person { std::unique_ptr> children = nullptr; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_array) { auto bart = Person{.first_name = "Bart"}; auto lisa = Person{.first_name = "Lisa"}; diff --git a/tests/bson/test_array.hpp b/tests/bson/test_array.hpp deleted file mode 100644 index 502c3388..00000000 --- a/tests/bson/test_array.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_array{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_box.cpp b/tests/bson/test_box.cpp index fdb3516a..c570a725 100644 --- a/tests/bson/test_box.cpp +++ b/tests/bson/test_box.cpp @@ -1,5 +1,3 @@ -#include "test_box.hpp" - #include #include #include @@ -29,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_box) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/bson/test_box.hpp b/tests/bson/test_box.hpp deleted file mode 100644 index a564b9e1..00000000 --- a/tests/bson/test_box.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_box{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_custom_class1.cpp b/tests/bson/test_custom_class1.cpp index fe8d0ea0..ddc9cc76 100644 --- a/tests/bson/test_custom_class1.cpp +++ b/tests/bson/test_custom_class1.cpp @@ -1,5 +1,3 @@ -#include "test_custom_class1.hpp" - #include #include #include @@ -31,9 +29,7 @@ struct Person { PersonImpl impl; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_custom_class1) { const auto bart = Person("Bart"); write_and_read(bart); diff --git a/tests/bson/test_custom_class1.hpp b/tests/bson/test_custom_class1.hpp deleted file mode 100644 index eafe6cd0..00000000 --- a/tests/bson/test_custom_class1.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class1{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_custom_class3.cpp b/tests/bson/test_custom_class3.cpp index 598364b1..75cd152e 100644 --- a/tests/bson/test_custom_class3.cpp +++ b/tests/bson/test_custom_class3.cpp @@ -1,5 +1,3 @@ -#include "test_custom_class3.hpp" - #include #include #include @@ -56,9 +54,7 @@ struct Parser namespace test_custom_class3 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_custom_class3) { const auto bart = Person("Bart", "Simpson", 10); write_and_read(bart); diff --git a/tests/bson/test_custom_class3.hpp b/tests/bson/test_custom_class3.hpp deleted file mode 100644 index 9a6fdab4..00000000 --- a/tests/bson/test_custom_class3.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class3{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_custom_class4.cpp b/tests/bson/test_custom_class4.cpp index 2b3b3bac..8a0edea4 100644 --- a/tests/bson/test_custom_class4.cpp +++ b/tests/bson/test_custom_class4.cpp @@ -1,5 +1,3 @@ -#include "test_custom_class4.hpp" - #include #include #include @@ -57,9 +55,7 @@ struct Parser namespace test_custom_class4 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_custom_class4) { const auto bart = test_custom_class4::Person( "Bart", rfl::make_box("Simpson"), 10); diff --git a/tests/bson/test_custom_class4.hpp b/tests/bson/test_custom_class4.hpp deleted file mode 100644 index 2d3b151a..00000000 --- a/tests/bson/test_custom_class4.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class4{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_default_values.cpp b/tests/bson/test_default_values.cpp index f6af2352..99c9de6c 100644 --- a/tests/bson/test_default_values.cpp +++ b/tests/bson/test_default_values.cpp @@ -1,5 +1,3 @@ -#include "test_default_values.hpp" - #include #include #include @@ -17,9 +15,7 @@ struct Person { std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_default_values) { const auto bart = Person{.first_name = "Bart"}; const auto lisa = Person{.first_name = "Lisa"}; const auto maggie = Person{.first_name = "Maggie"}; diff --git a/tests/bson/test_default_values.hpp b/tests/bson/test_default_values.hpp deleted file mode 100644 index c8f8360e..00000000 --- a/tests/bson/test_default_values.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_default_values{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_deque.cpp b/tests/bson/test_deque.cpp index 6dfa5803..6483cb8a 100644 --- a/tests/bson/test_deque.cpp +++ b/tests/bson/test_deque.cpp @@ -1,5 +1,3 @@ -#include "test_deque.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_default_values) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/bson/test_deque.hpp b/tests/bson/test_deque.hpp deleted file mode 100644 index 6781e880..00000000 --- a/tests/bson/test_deque.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_deque{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_enum.cpp b/tests/bson/test_enum.cpp index d4d56a8b..4390668c 100644 --- a/tests/bson/test_enum.cpp +++ b/tests/bson/test_enum.cpp @@ -1,5 +1,3 @@ -#include "test_enum.hpp" - #include #include #include @@ -18,9 +16,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::green}; write_and_read(circle); diff --git a/tests/bson/test_enum.hpp b/tests/bson/test_enum.hpp deleted file mode 100644 index 2e2e0b3d..00000000 --- a/tests/bson/test_enum.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_enum { -void test(); -} - diff --git a/tests/bson/test_field_variant.cpp b/tests/bson/test_field_variant.cpp index 8b17665f..ef4e20ab 100644 --- a/tests/bson/test_field_variant.cpp +++ b/tests/bson/test_field_variant.cpp @@ -1,5 +1,3 @@ -#include "test_field_variant.hpp" - #include #include #include @@ -28,9 +26,7 @@ using Shapes = rfl::Variant, rfl::Field<"rectangle", Rectangle>, rfl::Field<"square", rfl::Box>>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_field_variant) { const Shapes r = rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); diff --git a/tests/bson/test_field_variant.hpp b/tests/bson/test_field_variant.hpp deleted file mode 100644 index ba93e732..00000000 --- a/tests/bson/test_field_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_field_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_flag_enum.cpp b/tests/bson/test_flag_enum.cpp index 1d3f76af..1570d740 100644 --- a/tests/bson/test_flag_enum.cpp +++ b/tests/bson/test_flag_enum.cpp @@ -5,7 +5,6 @@ #include #include -#include "test_enum.hpp" #include "write_and_read.hpp" namespace test_flag_enum { @@ -27,9 +26,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_flag_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::blue | Color::orange}; diff --git a/tests/bson/test_flag_enum.hpp b/tests/bson/test_flag_enum.hpp deleted file mode 100644 index 2f4dc7a0..00000000 --- a/tests/bson/test_flag_enum.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flag_enum { -void test(); -} - diff --git a/tests/bson/test_flag_enum_with_int.cpp b/tests/bson/test_flag_enum_with_int.cpp index 4c7deefe..60b0ac02 100644 --- a/tests/bson/test_flag_enum_with_int.cpp +++ b/tests/bson/test_flag_enum_with_int.cpp @@ -5,7 +5,6 @@ #include #include -#include "test_enum.hpp" #include "write_and_read.hpp" namespace test_flag_enum_with_int { @@ -27,9 +26,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_flag_enum_with_int) { const auto circle = Circle{.radius = 2.0, .color = static_cast(10000)}; write_and_read(circle); diff --git a/tests/bson/test_flag_enum_with_int.hpp b/tests/bson/test_flag_enum_with_int.hpp deleted file mode 100644 index a7512b60..00000000 --- a/tests/bson/test_flag_enum_with_int.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flag_enum_with_int { -void test(); -} - diff --git a/tests/bson/test_flatten.cpp b/tests/bson/test_flatten.cpp index c7f1d9be..66388a31 100644 --- a/tests/bson/test_flatten.cpp +++ b/tests/bson/test_flatten.cpp @@ -1,5 +1,3 @@ -#include "test_flatten.hpp" - #include #include #include @@ -23,9 +21,7 @@ struct Employee { rfl::Field<"salary", float> salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_flatten) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), diff --git a/tests/bson/test_flatten.hpp b/tests/bson/test_flatten.hpp deleted file mode 100644 index 24d60e11..00000000 --- a/tests/bson/test_flatten.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_flatten_anonymous.cpp b/tests/bson/test_flatten_anonymous.cpp index 05e61464..15cd0cf2 100644 --- a/tests/bson/test_flatten_anonymous.cpp +++ b/tests/bson/test_flatten_anonymous.cpp @@ -1,5 +1,3 @@ -#include "test_flatten_anonymous.hpp" - #include #include #include @@ -23,9 +21,7 @@ struct Employee { float salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_flatten_anonymous) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), diff --git a/tests/bson/test_flatten_anonymous.hpp b/tests/bson/test_flatten_anonymous.hpp deleted file mode 100644 index 7ffa2785..00000000 --- a/tests/bson/test_flatten_anonymous.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten_anonymous{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_forward_list.cpp b/tests/bson/test_forward_list.cpp index dd8d9e56..81f0699e 100644 --- a/tests/bson/test_forward_list.cpp +++ b/tests/bson/test_forward_list.cpp @@ -1,5 +1,3 @@ -#include "test_forward_list.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_forward_list) { auto children = std::make_unique>(); children->emplace_front(Person{.first_name = "Maggie"}); children->emplace_front(Person{.first_name = "Lisa"}); diff --git a/tests/bson/test_forward_list.hpp b/tests/bson/test_forward_list.hpp deleted file mode 100644 index 9784a0c4..00000000 --- a/tests/bson/test_forward_list.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_forward_list{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_literal.cpp b/tests/bson/test_literal.cpp index 00578178..12cbad32 100644 --- a/tests/bson/test_literal.cpp +++ b/tests/bson/test_literal.cpp @@ -1,5 +1,3 @@ -#include "test_literal.hpp" - #include #include #include @@ -20,9 +18,7 @@ struct Person { std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_literal) { const auto bart = Person{.first_name = FirstName::make<"Bart">()}; write_and_read(bart); diff --git a/tests/bson/test_literal.hpp b/tests/bson/test_literal.hpp deleted file mode 100644 index ccd500ef..00000000 --- a/tests/bson/test_literal.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_literal_map.cpp b/tests/bson/test_literal_map.cpp index 9bbebafb..83710d55 100644 --- a/tests/bson/test_literal_map.cpp +++ b/tests/bson/test_literal_map.cpp @@ -1,5 +1,3 @@ -#include "test_literal_map.hpp" - #include #include #include @@ -14,9 +12,7 @@ namespace test_literal_map { using FieldName = rfl::Literal<"firstName", "lastName">; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_literal_map) { std::map> homer; homer.insert(std::make_pair(FieldName::make<"firstName">(), std::make_unique("Homer"))); diff --git a/tests/bson/test_literal_map.hpp b/tests/bson/test_literal_map.hpp deleted file mode 100644 index cc05d0c8..00000000 --- a/tests/bson/test_literal_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_map.cpp b/tests/bson/test_map.cpp index e37ce564..537e77f6 100644 --- a/tests/bson/test_map.cpp +++ b/tests/bson/test_map.cpp @@ -1,5 +1,3 @@ -#include "test_map.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::map children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_map) { auto children = std::map(); children.insert(std::make_pair("child1", Person{.first_name = "Bart"})); children.insert(std::make_pair("child2", Person{.first_name = "Lisa"})); diff --git a/tests/bson/test_map.hpp b/tests/bson/test_map.hpp deleted file mode 100644 index 9ae49728..00000000 --- a/tests/bson/test_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_map_with_key_validation.cpp b/tests/bson/test_map_with_key_validation.cpp index e758219d..991f3e50 100644 --- a/tests/bson/test_map_with_key_validation.cpp +++ b/tests/bson/test_map_with_key_validation.cpp @@ -1,5 +1,3 @@ -#include "test_map_with_key_validation.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_map_with_key_validation) { auto children = std::make_unique>(); children->insert(std::make_pair("Bart", Person{.first_name = "Bart"})); diff --git a/tests/bson/test_map_with_key_validation.hpp b/tests/bson/test_map_with_key_validation.hpp deleted file mode 100644 index 1372f926..00000000 --- a/tests/bson/test_map_with_key_validation.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map_with_key_validation{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_monster_example.cpp b/tests/bson/test_monster_example.cpp index 052d8390..49887c35 100644 --- a/tests/bson/test_monster_example.cpp +++ b/tests/bson/test_monster_example.cpp @@ -1,5 +1,3 @@ -#include "test_monster_example.hpp" - #include #include #include @@ -38,9 +36,7 @@ struct Monster { std::vector path; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_monster_example) { const auto sword = Weapon{.name = "Sword", .damage = 3}; const auto axe = Weapon{.name = "Axe", .damage = 5}; diff --git a/tests/bson/test_monster_example.hpp b/tests/bson/test_monster_example.hpp deleted file mode 100644 index f2d959fc..00000000 --- a/tests/bson/test_monster_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_monster_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_readme_example.cpp b/tests/bson/test_readme_example.cpp index 4e6f8ee0..e42d8817 100644 --- a/tests/bson/test_readme_example.cpp +++ b/tests/bson/test_readme_example.cpp @@ -1,5 +1,3 @@ -#include "test_readme_example.hpp" - #include #include #include @@ -22,9 +20,7 @@ struct Person { std::vector child; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_readme_example) { const auto bart = Person{.first_name = "Bart", .birthday = "1987-04-19", .age = 10, diff --git a/tests/bson/test_readme_example.hpp b/tests/bson/test_readme_example.hpp deleted file mode 100644 index 68c6cf81..00000000 --- a/tests/bson/test_readme_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_readme_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_readme_example2.cpp b/tests/bson/test_readme_example2.cpp index a2d212a4..f93de197 100644 --- a/tests/bson/test_readme_example2.cpp +++ b/tests/bson/test_readme_example2.cpp @@ -4,7 +4,6 @@ #include #include -#include "test_readme_example.hpp" #include "write_and_read.hpp" namespace test_readme_example2 { @@ -15,9 +14,7 @@ struct Person { int age; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_readme_example2) { const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; diff --git a/tests/bson/test_readme_example2.hpp b/tests/bson/test_readme_example2.hpp deleted file mode 100644 index 5c6b011c..00000000 --- a/tests/bson/test_readme_example2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_readme_example2 { -void test(); -} - diff --git a/tests/bson/test_ref.cpp b/tests/bson/test_ref.cpp index 32a32e6c..7b7ca3a3 100644 --- a/tests/bson/test_ref.cpp +++ b/tests/bson/test_ref.cpp @@ -1,5 +1,3 @@ -#include "test_ref.hpp" - #include #include #include @@ -29,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_ref) { const auto leaf1 = DecisionTree::Leaf{.value = 3.0}; const auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/bson/test_ref.hpp b/tests/bson/test_ref.hpp deleted file mode 100644 index d289ba09..00000000 --- a/tests/bson/test_ref.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_ref{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_save_load.cpp b/tests/bson/test_save_load.cpp index d51c34c8..a72dc2a9 100644 --- a/tests/bson/test_save_load.cpp +++ b/tests/bson/test_save_load.cpp @@ -1,5 +1,3 @@ -#include "test_save_load.hpp" - #include #include #include @@ -8,6 +6,8 @@ #include #include +#include + namespace test_save_load { using Age = rfl::Validator children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_save_load) { const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19", @@ -59,12 +57,6 @@ void test() { const auto string1 = rfl::bson::write(homer1); const auto string2 = rfl::bson::write(homer2); - if (string1 != string2) { - std::cout << "Test failed. Content was not identical." << std::endl - << std::endl; - return; - } - - std::cout << "OK" << std::endl << std::endl; + EXPECT_EQ(string1, string2); } } // namespace test_save_load diff --git a/tests/bson/test_save_load.hpp b/tests/bson/test_save_load.hpp deleted file mode 100644 index 7bf10359..00000000 --- a/tests/bson/test_save_load.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_save_load { -void test(); -} - diff --git a/tests/bson/test_set.cpp b/tests/bson/test_set.cpp index 9f2516ce..ec6f8030 100644 --- a/tests/bson/test_set.cpp +++ b/tests/bson/test_set.cpp @@ -1,5 +1,3 @@ -#include "test_set.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_set) { auto children = std::make_unique>( std::set({"Bart", "Lisa", "Maggie"})); diff --git a/tests/bson/test_set.hpp b/tests/bson/test_set.hpp deleted file mode 100644 index 142a663b..00000000 --- a/tests/bson/test_set.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_set{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_size.cpp b/tests/bson/test_size.cpp index c37b9bd8..0de9abf5 100644 --- a/tests/bson/test_size.cpp +++ b/tests/bson/test_size.cpp @@ -1,5 +1,3 @@ -#include "test_size.hpp" - #include #include #include @@ -19,9 +17,7 @@ struct Person { children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_size) { const auto bart = Person{ .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"}; diff --git a/tests/bson/test_size.hpp b/tests/bson/test_size.hpp deleted file mode 100644 index be330df0..00000000 --- a/tests/bson/test_size.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_size{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_string_map.cpp b/tests/bson/test_string_map.cpp index cb4fb903..b4aef817 100644 --- a/tests/bson/test_string_map.cpp +++ b/tests/bson/test_string_map.cpp @@ -1,5 +1,3 @@ -#include "test_string_map.hpp" - #include #include #include @@ -10,9 +8,7 @@ #include "write_and_read.hpp" namespace test_string_map { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_string_map) { std::map> homer; homer.insert( std::make_pair("firstName", std::make_unique("Homer"))); diff --git a/tests/bson/test_string_map.hpp b/tests/bson/test_string_map.hpp deleted file mode 100644 index 94cb975a..00000000 --- a/tests/bson/test_string_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_string_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_tagged_union.cpp b/tests/bson/test_tagged_union.cpp index a9dd1abc..630b65e6 100644 --- a/tests/bson/test_tagged_union.cpp +++ b/tests/bson/test_tagged_union.cpp @@ -1,5 +1,3 @@ -#include "test_tagged_union.hpp" - #include #include #include @@ -26,11 +24,8 @@ struct Square { using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_tagged_union) { const Shapes r = Rectangle{.height = 10, .width = 5}; - write_and_read(r); } } // namespace test_tagged_union diff --git a/tests/bson/test_tagged_union.hpp b/tests/bson/test_tagged_union.hpp deleted file mode 100644 index 5d522ff9..00000000 --- a/tests/bson/test_tagged_union.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_tagged_union{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_timestamp.cpp b/tests/bson/test_timestamp.cpp index 8af261d1..c57e06fc 100644 --- a/tests/bson/test_timestamp.cpp +++ b/tests/bson/test_timestamp.cpp @@ -1,5 +1,3 @@ -#include "test_timestamp.hpp" - #include #include #include @@ -19,9 +17,7 @@ struct Person { TS birthday; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_timestamp) { const auto result = TS::from_string("nonsense"); if (result) { diff --git a/tests/bson/test_timestamp.hpp b/tests/bson/test_timestamp.hpp deleted file mode 100644 index 891d89b9..00000000 --- a/tests/bson/test_timestamp.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_timestamp{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_unique_ptr.cpp b/tests/bson/test_unique_ptr.cpp index b1833533..4091de86 100644 --- a/tests/bson/test_unique_ptr.cpp +++ b/tests/bson/test_unique_ptr.cpp @@ -1,5 +1,3 @@ -#include "test_unique_ptr.hpp" - #include #include #include @@ -17,9 +15,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_unique_ptr) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/bson/test_unique_ptr.hpp b/tests/bson/test_unique_ptr.hpp deleted file mode 100644 index 428ea2a2..00000000 --- a/tests/bson/test_unique_ptr.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_unique_ptr2.cpp b/tests/bson/test_unique_ptr2.cpp index e3007267..a9ba69b6 100644 --- a/tests/bson/test_unique_ptr2.cpp +++ b/tests/bson/test_unique_ptr2.cpp @@ -1,5 +1,3 @@ -#include "test_unique_ptr2.hpp" - #include #include #include @@ -29,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_unique_ptr2) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/bson/test_unique_ptr2.hpp b/tests/bson/test_unique_ptr2.hpp deleted file mode 100644 index 74adc170..00000000 --- a/tests/bson/test_unique_ptr2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr2{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_variant.cpp b/tests/bson/test_variant.cpp index cc3d6cbe..cea0b0b4 100644 --- a/tests/bson/test_variant.cpp +++ b/tests/bson/test_variant.cpp @@ -1,5 +1,3 @@ -#include "test_variant.hpp" - #include #include #include @@ -26,9 +24,7 @@ struct Square { using Shapes = std::variant>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(bson, test_variant) { const Shapes r = Rectangle{.height = 10, .width = 5}; write_and_read(r); diff --git a/tests/bson/test_variant.hpp b/tests/bson/test_variant.hpp deleted file mode 100644 index 0e58ce71..00000000 --- a/tests/bson/test_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/bson/test_wstring.cpp b/tests/bson/test_wstring.cpp index ba6202c0..0eaaf93c 100644 --- a/tests/bson/test_wstring.cpp +++ b/tests/bson/test_wstring.cpp @@ -1,5 +1,3 @@ -#include "test_wstring.hpp" - #include #include #include @@ -9,17 +7,15 @@ #include "write_and_read.hpp" -struct Test { +struct TestStruct { std::string theNormalString; std::wstring theWiderString; }; namespace test_wstring { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const Test test = Test{.theNormalString = "The normal string", - .theWiderString = L"The wider string"}; +TEST(bson, test_wstring) { + const auto test = TestStruct{.theNormalString = "The normal string", + .theWiderString = L"The wider string"}; write_and_read(test); } diff --git a/tests/bson/test_wstring.hpp b/tests/bson/test_wstring.hpp deleted file mode 100644 index 0f93e784..00000000 --- a/tests/bson/test_wstring.hpp +++ /dev/null @@ -1,3 +0,0 @@ -namespace test_wstring { - void test(); -} diff --git a/tests/bson/tests.cpp b/tests/bson/tests.cpp deleted file mode 100644 index 8a9fe0fb..00000000 --- a/tests/bson/tests.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "test_array.hpp" -#include "test_box.hpp" -#include "test_custom_class1.hpp" -#include "test_custom_class3.hpp" -#include "test_custom_class4.hpp" -#include "test_default_values.hpp" -#include "test_deque.hpp" -#include "test_enum.hpp" -#include "test_field_variant.hpp" -#include "test_flag_enum.hpp" -#include "test_flag_enum_with_int.hpp" -#include "test_flatten.hpp" -#include "test_flatten_anonymous.hpp" -#include "test_forward_list.hpp" -#include "test_literal.hpp" -#include "test_literal_map.hpp" -#include "test_map.hpp" -#include "test_map_with_key_validation.hpp" -#include "test_monster_example.hpp" -#include "test_readme_example.hpp" -#include "test_readme_example2.hpp" -#include "test_ref.hpp" -#include "test_save_load.hpp" -#include "test_set.hpp" -#include "test_size.hpp" -#include "test_tagged_union.hpp" -#include "test_timestamp.hpp" -#include "test_unique_ptr.hpp" -#include "test_unique_ptr2.hpp" -#include "test_variant.hpp" -#include "test_wstring.hpp" - -int main() { - test_readme_example::test(); - test_readme_example2::test(); - test_flatten::test(); - test_flatten_anonymous::test(); - test_enum::test(); - test_flag_enum::test(); - test_flag_enum_with_int::test(); - test_map::test(); - test_map_with_key_validation::test(); - test_variant::test(); - test_field_variant::test(); - test_tagged_union::test(); - test_deque::test(); - test_forward_list::test(); - test_literal_map::test(); - test_literal::test(); - test_monster_example::test(); - test_ref::test(); - test_set::test(); - test_size::test(); - test_timestamp::test(); - test_unique_ptr::test(); - test_unique_ptr2::test(); - test_array::test(); - test_box::test(); - test_custom_class1::test(); - test_custom_class3::test(); - test_custom_class4::test(); - test_default_values::test(); - test_save_load::test(); - test_wstring::test(); - - return 0; -} diff --git a/tests/bson/write_and_read.hpp b/tests/bson/write_and_read.hpp index f009be61..15096a38 100644 --- a/tests/bson/write_and_read.hpp +++ b/tests/bson/write_and_read.hpp @@ -1,39 +1,20 @@ #ifndef WRITE_AND_READ_ #define WRITE_AND_READ_ +#include + #include #include #include template void write_and_read(const T& _struct) { - const auto bytes1 = rfl::bson::write(_struct); - - const auto res = rfl::bson::read(bytes1); - - if (!res) { - std::cout << "Test failed on read. Error: " << res.error().value().what() - << std::endl - << std::endl; - return; - } - - const auto bytes2 = rfl::bson::write(res.value()); - - if (bytes1.size() != bytes2.size()) { - std::cout << "Test failed on write. Number of bytes was different." - << std::endl - << std::endl; - return; - } - - if (bytes1 != bytes2) { - std::cout << "Test failed on write. Content was not identical." << std::endl - << std::endl; - return; - } - - std::cout << "OK" << std::endl << std::endl; + const auto serialized1 = rfl::bson::write(_struct); + const auto res = rfl::bson::read(serialized1); + EXPECT_TRUE(res && true) << "Test failed on read. Error: " + << res.error().value().what(); + const auto serialized2 = rfl::bson::write(res.value()); + EXPECT_EQ(serialized1, serialized2); } #endif diff --git a/tests/cbor/CMakeLists.txt b/tests/cbor/CMakeLists.txt index 7f457ee5..ba5a8e0f 100644 --- a/tests/cbor/CMakeLists.txt +++ b/tests/cbor/CMakeLists.txt @@ -1,8 +1,19 @@ project(reflect-cpp-cbor-tests) -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp") -add_executable(reflect-cpp-cbor-tests ${SOURCES}) +add_executable( + reflect-cpp-cbor-tests + ${SOURCES} + "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/src/gtest_main.cc" +) +target_include_directories(reflect-cpp-cbor-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") target_include_directories(reflect-cpp-cbor-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include/tinycbor") -target_link_libraries(reflect-cpp-cbor-tests PRIVATE reflectcpp) + +target_link_libraries( + reflect-cpp-cbor-tests + PRIVATE + reflectcpp + "${REFLECT_CPP_GTEST_LIB}" +) diff --git a/tests/cbor/test_array.cpp b/tests/cbor/test_array.cpp index 108f730e..55274d49 100644 --- a/tests/cbor/test_array.cpp +++ b/tests/cbor/test_array.cpp @@ -1,5 +1,3 @@ -#include "test_array.hpp" - #include #include #include @@ -21,9 +19,7 @@ struct Person { std::unique_ptr> children = nullptr; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_array) { auto bart = Person{.first_name = "Bart"}; auto lisa = Person{.first_name = "Lisa"}; diff --git a/tests/cbor/test_array.hpp b/tests/cbor/test_array.hpp deleted file mode 100644 index 502c3388..00000000 --- a/tests/cbor/test_array.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_array{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_box.cpp b/tests/cbor/test_box.cpp index fdb3516a..3fd68a69 100644 --- a/tests/cbor/test_box.cpp +++ b/tests/cbor/test_box.cpp @@ -1,5 +1,3 @@ -#include "test_box.hpp" - #include #include #include @@ -29,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_box) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/cbor/test_box.hpp b/tests/cbor/test_box.hpp deleted file mode 100644 index a564b9e1..00000000 --- a/tests/cbor/test_box.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_box{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_custom_class1.cpp b/tests/cbor/test_custom_class1.cpp index fe8d0ea0..448ac187 100644 --- a/tests/cbor/test_custom_class1.cpp +++ b/tests/cbor/test_custom_class1.cpp @@ -1,5 +1,3 @@ -#include "test_custom_class1.hpp" - #include #include #include @@ -31,9 +29,7 @@ struct Person { PersonImpl impl; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_custom_class1) { const auto bart = Person("Bart"); write_and_read(bart); diff --git a/tests/cbor/test_custom_class1.hpp b/tests/cbor/test_custom_class1.hpp deleted file mode 100644 index eafe6cd0..00000000 --- a/tests/cbor/test_custom_class1.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class1{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_custom_class3.cpp b/tests/cbor/test_custom_class3.cpp index 598364b1..991df513 100644 --- a/tests/cbor/test_custom_class3.cpp +++ b/tests/cbor/test_custom_class3.cpp @@ -1,5 +1,3 @@ -#include "test_custom_class3.hpp" - #include #include #include @@ -56,9 +54,7 @@ struct Parser namespace test_custom_class3 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_custom_class3) { const auto bart = Person("Bart", "Simpson", 10); write_and_read(bart); diff --git a/tests/cbor/test_custom_class3.hpp b/tests/cbor/test_custom_class3.hpp deleted file mode 100644 index 9a6fdab4..00000000 --- a/tests/cbor/test_custom_class3.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class3{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_custom_class4.cpp b/tests/cbor/test_custom_class4.cpp index 2b3b3bac..45b6d914 100644 --- a/tests/cbor/test_custom_class4.cpp +++ b/tests/cbor/test_custom_class4.cpp @@ -1,5 +1,3 @@ -#include "test_custom_class4.hpp" - #include #include #include @@ -57,9 +55,7 @@ struct Parser namespace test_custom_class4 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_custom_class4) { const auto bart = test_custom_class4::Person( "Bart", rfl::make_box("Simpson"), 10); diff --git a/tests/cbor/test_custom_class4.hpp b/tests/cbor/test_custom_class4.hpp deleted file mode 100644 index 2d3b151a..00000000 --- a/tests/cbor/test_custom_class4.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class4{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_default_values.cpp b/tests/cbor/test_default_values.cpp index f6af2352..d69109e2 100644 --- a/tests/cbor/test_default_values.cpp +++ b/tests/cbor/test_default_values.cpp @@ -1,5 +1,3 @@ -#include "test_default_values.hpp" - #include #include #include @@ -17,9 +15,7 @@ struct Person { std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_default_values) { const auto bart = Person{.first_name = "Bart"}; const auto lisa = Person{.first_name = "Lisa"}; const auto maggie = Person{.first_name = "Maggie"}; diff --git a/tests/cbor/test_default_values.hpp b/tests/cbor/test_default_values.hpp deleted file mode 100644 index c8f8360e..00000000 --- a/tests/cbor/test_default_values.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_default_values{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_deque.cpp b/tests/cbor/test_deque.cpp index 6dfa5803..d897da5d 100644 --- a/tests/cbor/test_deque.cpp +++ b/tests/cbor/test_deque.cpp @@ -1,5 +1,3 @@ -#include "test_deque.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_default_values) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/cbor/test_deque.hpp b/tests/cbor/test_deque.hpp deleted file mode 100644 index 6781e880..00000000 --- a/tests/cbor/test_deque.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_deque{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_enum.cpp b/tests/cbor/test_enum.cpp index d4d56a8b..4e485288 100644 --- a/tests/cbor/test_enum.cpp +++ b/tests/cbor/test_enum.cpp @@ -1,5 +1,3 @@ -#include "test_enum.hpp" - #include #include #include @@ -18,9 +16,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::green}; write_and_read(circle); diff --git a/tests/cbor/test_enum.hpp b/tests/cbor/test_enum.hpp deleted file mode 100644 index 2e2e0b3d..00000000 --- a/tests/cbor/test_enum.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_enum { -void test(); -} - diff --git a/tests/cbor/test_field_variant.cpp b/tests/cbor/test_field_variant.cpp index 8b17665f..1276609d 100644 --- a/tests/cbor/test_field_variant.cpp +++ b/tests/cbor/test_field_variant.cpp @@ -1,5 +1,3 @@ -#include "test_field_variant.hpp" - #include #include #include @@ -28,9 +26,7 @@ using Shapes = rfl::Variant, rfl::Field<"rectangle", Rectangle>, rfl::Field<"square", rfl::Box>>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_field_variant) { const Shapes r = rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); diff --git a/tests/cbor/test_field_variant.hpp b/tests/cbor/test_field_variant.hpp deleted file mode 100644 index ba93e732..00000000 --- a/tests/cbor/test_field_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_field_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_flag_enum.cpp b/tests/cbor/test_flag_enum.cpp index 1d3f76af..3473dc84 100644 --- a/tests/cbor/test_flag_enum.cpp +++ b/tests/cbor/test_flag_enum.cpp @@ -5,7 +5,6 @@ #include #include -#include "test_enum.hpp" #include "write_and_read.hpp" namespace test_flag_enum { @@ -27,9 +26,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_flag_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::blue | Color::orange}; diff --git a/tests/cbor/test_flag_enum.hpp b/tests/cbor/test_flag_enum.hpp deleted file mode 100644 index 2f4dc7a0..00000000 --- a/tests/cbor/test_flag_enum.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flag_enum { -void test(); -} - diff --git a/tests/cbor/test_flag_enum_with_int.cpp b/tests/cbor/test_flag_enum_with_int.cpp index 4c7deefe..78f558f8 100644 --- a/tests/cbor/test_flag_enum_with_int.cpp +++ b/tests/cbor/test_flag_enum_with_int.cpp @@ -5,7 +5,6 @@ #include #include -#include "test_enum.hpp" #include "write_and_read.hpp" namespace test_flag_enum_with_int { @@ -27,9 +26,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_flag_enum_with_int) { const auto circle = Circle{.radius = 2.0, .color = static_cast(10000)}; write_and_read(circle); diff --git a/tests/cbor/test_flag_enum_with_int.hpp b/tests/cbor/test_flag_enum_with_int.hpp deleted file mode 100644 index a7512b60..00000000 --- a/tests/cbor/test_flag_enum_with_int.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flag_enum_with_int { -void test(); -} - diff --git a/tests/cbor/test_flatten.cpp b/tests/cbor/test_flatten.cpp index c7f1d9be..3896a206 100644 --- a/tests/cbor/test_flatten.cpp +++ b/tests/cbor/test_flatten.cpp @@ -1,5 +1,3 @@ -#include "test_flatten.hpp" - #include #include #include @@ -23,9 +21,7 @@ struct Employee { rfl::Field<"salary", float> salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_flatten) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), diff --git a/tests/cbor/test_flatten.hpp b/tests/cbor/test_flatten.hpp deleted file mode 100644 index 24d60e11..00000000 --- a/tests/cbor/test_flatten.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_flatten_anonymous.cpp b/tests/cbor/test_flatten_anonymous.cpp index 05e61464..3a90ba02 100644 --- a/tests/cbor/test_flatten_anonymous.cpp +++ b/tests/cbor/test_flatten_anonymous.cpp @@ -1,5 +1,3 @@ -#include "test_flatten_anonymous.hpp" - #include #include #include @@ -23,9 +21,7 @@ struct Employee { float salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_flatten_anonymous) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), diff --git a/tests/cbor/test_flatten_anonymous.hpp b/tests/cbor/test_flatten_anonymous.hpp deleted file mode 100644 index 7ffa2785..00000000 --- a/tests/cbor/test_flatten_anonymous.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten_anonymous{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_forward_list.cpp b/tests/cbor/test_forward_list.cpp index dd8d9e56..444d581f 100644 --- a/tests/cbor/test_forward_list.cpp +++ b/tests/cbor/test_forward_list.cpp @@ -1,5 +1,3 @@ -#include "test_forward_list.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_forward_list) { auto children = std::make_unique>(); children->emplace_front(Person{.first_name = "Maggie"}); children->emplace_front(Person{.first_name = "Lisa"}); diff --git a/tests/cbor/test_forward_list.hpp b/tests/cbor/test_forward_list.hpp deleted file mode 100644 index 9784a0c4..00000000 --- a/tests/cbor/test_forward_list.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_forward_list{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_literal.cpp b/tests/cbor/test_literal.cpp index 00578178..d444ec33 100644 --- a/tests/cbor/test_literal.cpp +++ b/tests/cbor/test_literal.cpp @@ -1,5 +1,3 @@ -#include "test_literal.hpp" - #include #include #include @@ -20,9 +18,7 @@ struct Person { std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_literal) { const auto bart = Person{.first_name = FirstName::make<"Bart">()}; write_and_read(bart); diff --git a/tests/cbor/test_literal.hpp b/tests/cbor/test_literal.hpp deleted file mode 100644 index ccd500ef..00000000 --- a/tests/cbor/test_literal.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_literal_map.cpp b/tests/cbor/test_literal_map.cpp index 9bbebafb..3c2a096d 100644 --- a/tests/cbor/test_literal_map.cpp +++ b/tests/cbor/test_literal_map.cpp @@ -1,5 +1,3 @@ -#include "test_literal_map.hpp" - #include #include #include @@ -14,9 +12,7 @@ namespace test_literal_map { using FieldName = rfl::Literal<"firstName", "lastName">; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_literal_map) { std::map> homer; homer.insert(std::make_pair(FieldName::make<"firstName">(), std::make_unique("Homer"))); diff --git a/tests/cbor/test_literal_map.hpp b/tests/cbor/test_literal_map.hpp deleted file mode 100644 index cc05d0c8..00000000 --- a/tests/cbor/test_literal_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_map.cpp b/tests/cbor/test_map.cpp index e37ce564..4ac14474 100644 --- a/tests/cbor/test_map.cpp +++ b/tests/cbor/test_map.cpp @@ -1,5 +1,3 @@ -#include "test_map.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::map children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_map) { auto children = std::map(); children.insert(std::make_pair("child1", Person{.first_name = "Bart"})); children.insert(std::make_pair("child2", Person{.first_name = "Lisa"})); diff --git a/tests/cbor/test_map.hpp b/tests/cbor/test_map.hpp deleted file mode 100644 index 9ae49728..00000000 --- a/tests/cbor/test_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_map_with_key_validation.cpp b/tests/cbor/test_map_with_key_validation.cpp index e758219d..9286e2ad 100644 --- a/tests/cbor/test_map_with_key_validation.cpp +++ b/tests/cbor/test_map_with_key_validation.cpp @@ -1,5 +1,3 @@ -#include "test_map_with_key_validation.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_map_with_key_validation) { auto children = std::make_unique>(); children->insert(std::make_pair("Bart", Person{.first_name = "Bart"})); diff --git a/tests/cbor/test_map_with_key_validation.hpp b/tests/cbor/test_map_with_key_validation.hpp deleted file mode 100644 index 1372f926..00000000 --- a/tests/cbor/test_map_with_key_validation.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map_with_key_validation{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_monster_example.cpp b/tests/cbor/test_monster_example.cpp index 052d8390..3a27276d 100644 --- a/tests/cbor/test_monster_example.cpp +++ b/tests/cbor/test_monster_example.cpp @@ -1,5 +1,3 @@ -#include "test_monster_example.hpp" - #include #include #include @@ -38,9 +36,7 @@ struct Monster { std::vector path; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_monster_example) { const auto sword = Weapon{.name = "Sword", .damage = 3}; const auto axe = Weapon{.name = "Axe", .damage = 5}; diff --git a/tests/cbor/test_monster_example.hpp b/tests/cbor/test_monster_example.hpp deleted file mode 100644 index f2d959fc..00000000 --- a/tests/cbor/test_monster_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_monster_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_readme_example.cpp b/tests/cbor/test_readme_example.cpp index 4e6f8ee0..092608fd 100644 --- a/tests/cbor/test_readme_example.cpp +++ b/tests/cbor/test_readme_example.cpp @@ -1,5 +1,3 @@ -#include "test_readme_example.hpp" - #include #include #include @@ -22,9 +20,7 @@ struct Person { std::vector child; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_readme_example) { const auto bart = Person{.first_name = "Bart", .birthday = "1987-04-19", .age = 10, diff --git a/tests/cbor/test_readme_example.hpp b/tests/cbor/test_readme_example.hpp deleted file mode 100644 index 68c6cf81..00000000 --- a/tests/cbor/test_readme_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_readme_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_readme_example2.cpp b/tests/cbor/test_readme_example2.cpp index a2d212a4..b1b69c42 100644 --- a/tests/cbor/test_readme_example2.cpp +++ b/tests/cbor/test_readme_example2.cpp @@ -4,7 +4,6 @@ #include #include -#include "test_readme_example.hpp" #include "write_and_read.hpp" namespace test_readme_example2 { @@ -15,9 +14,7 @@ struct Person { int age; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_readme_example2) { const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; diff --git a/tests/cbor/test_readme_example2.hpp b/tests/cbor/test_readme_example2.hpp deleted file mode 100644 index 5c6b011c..00000000 --- a/tests/cbor/test_readme_example2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_readme_example2 { -void test(); -} - diff --git a/tests/cbor/test_ref.cpp b/tests/cbor/test_ref.cpp index 32a32e6c..653783fd 100644 --- a/tests/cbor/test_ref.cpp +++ b/tests/cbor/test_ref.cpp @@ -1,5 +1,3 @@ -#include "test_ref.hpp" - #include #include #include @@ -29,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_ref) { const auto leaf1 = DecisionTree::Leaf{.value = 3.0}; const auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/cbor/test_ref.hpp b/tests/cbor/test_ref.hpp deleted file mode 100644 index d289ba09..00000000 --- a/tests/cbor/test_ref.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_ref{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_save_load.cpp b/tests/cbor/test_save_load.cpp index c2b19a43..4f4dcbd1 100644 --- a/tests/cbor/test_save_load.cpp +++ b/tests/cbor/test_save_load.cpp @@ -1,5 +1,3 @@ -#include "test_save_load.hpp" - #include #include #include @@ -8,6 +6,8 @@ #include #include +#include + namespace test_save_load { using Age = rfl::Validator children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_save_load) { const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19", @@ -59,12 +57,6 @@ void test() { const auto string1 = rfl::cbor::write(homer1); const auto string2 = rfl::cbor::write(homer2); - if (string1 != string2) { - std::cout << "Test failed. Content was not identical." << std::endl - << std::endl; - return; - } - - std::cout << "OK" << std::endl << std::endl; + EXPECT_EQ(string1, string2); } } // namespace test_save_load diff --git a/tests/cbor/test_save_load.hpp b/tests/cbor/test_save_load.hpp deleted file mode 100644 index 7bf10359..00000000 --- a/tests/cbor/test_save_load.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_save_load { -void test(); -} - diff --git a/tests/cbor/test_set.cpp b/tests/cbor/test_set.cpp index 9f2516ce..66f6d2e1 100644 --- a/tests/cbor/test_set.cpp +++ b/tests/cbor/test_set.cpp @@ -1,5 +1,3 @@ -#include "test_set.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_set) { auto children = std::make_unique>( std::set({"Bart", "Lisa", "Maggie"})); diff --git a/tests/cbor/test_set.hpp b/tests/cbor/test_set.hpp deleted file mode 100644 index 142a663b..00000000 --- a/tests/cbor/test_set.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_set{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_size.cpp b/tests/cbor/test_size.cpp index c37b9bd8..984fa087 100644 --- a/tests/cbor/test_size.cpp +++ b/tests/cbor/test_size.cpp @@ -1,5 +1,3 @@ -#include "test_size.hpp" - #include #include #include @@ -19,9 +17,7 @@ struct Person { children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_size) { const auto bart = Person{ .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"}; diff --git a/tests/cbor/test_size.hpp b/tests/cbor/test_size.hpp deleted file mode 100644 index be330df0..00000000 --- a/tests/cbor/test_size.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_size{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_string_map.cpp b/tests/cbor/test_string_map.cpp index cb4fb903..70934445 100644 --- a/tests/cbor/test_string_map.cpp +++ b/tests/cbor/test_string_map.cpp @@ -1,5 +1,3 @@ -#include "test_string_map.hpp" - #include #include #include @@ -10,9 +8,7 @@ #include "write_and_read.hpp" namespace test_string_map { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_string_map) { std::map> homer; homer.insert( std::make_pair("firstName", std::make_unique("Homer"))); diff --git a/tests/cbor/test_string_map.hpp b/tests/cbor/test_string_map.hpp deleted file mode 100644 index 94cb975a..00000000 --- a/tests/cbor/test_string_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_string_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_tagged_union.cpp b/tests/cbor/test_tagged_union.cpp index a9dd1abc..adbf422c 100644 --- a/tests/cbor/test_tagged_union.cpp +++ b/tests/cbor/test_tagged_union.cpp @@ -1,5 +1,3 @@ -#include "test_tagged_union.hpp" - #include #include #include @@ -26,11 +24,8 @@ struct Square { using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_tagged_union) { const Shapes r = Rectangle{.height = 10, .width = 5}; - write_and_read(r); } } // namespace test_tagged_union diff --git a/tests/cbor/test_tagged_union.hpp b/tests/cbor/test_tagged_union.hpp deleted file mode 100644 index 5d522ff9..00000000 --- a/tests/cbor/test_tagged_union.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_tagged_union{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_timestamp.cpp b/tests/cbor/test_timestamp.cpp index 8af261d1..da86861c 100644 --- a/tests/cbor/test_timestamp.cpp +++ b/tests/cbor/test_timestamp.cpp @@ -1,5 +1,3 @@ -#include "test_timestamp.hpp" - #include #include #include @@ -19,9 +17,7 @@ struct Person { TS birthday; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_timestamp) { const auto result = TS::from_string("nonsense"); if (result) { diff --git a/tests/cbor/test_timestamp.hpp b/tests/cbor/test_timestamp.hpp deleted file mode 100644 index 891d89b9..00000000 --- a/tests/cbor/test_timestamp.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_timestamp{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_unique_ptr.cpp b/tests/cbor/test_unique_ptr.cpp index b1833533..fc667206 100644 --- a/tests/cbor/test_unique_ptr.cpp +++ b/tests/cbor/test_unique_ptr.cpp @@ -1,5 +1,3 @@ -#include "test_unique_ptr.hpp" - #include #include #include @@ -17,9 +15,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_unique_ptr) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/cbor/test_unique_ptr.hpp b/tests/cbor/test_unique_ptr.hpp deleted file mode 100644 index 428ea2a2..00000000 --- a/tests/cbor/test_unique_ptr.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_unique_ptr2.cpp b/tests/cbor/test_unique_ptr2.cpp index e3007267..b2f83eed 100644 --- a/tests/cbor/test_unique_ptr2.cpp +++ b/tests/cbor/test_unique_ptr2.cpp @@ -1,5 +1,3 @@ -#include "test_unique_ptr2.hpp" - #include #include #include @@ -29,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_unique_ptr2) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/cbor/test_unique_ptr2.hpp b/tests/cbor/test_unique_ptr2.hpp deleted file mode 100644 index 74adc170..00000000 --- a/tests/cbor/test_unique_ptr2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr2{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_variant.cpp b/tests/cbor/test_variant.cpp index cc3d6cbe..82f83604 100644 --- a/tests/cbor/test_variant.cpp +++ b/tests/cbor/test_variant.cpp @@ -1,5 +1,3 @@ -#include "test_variant.hpp" - #include #include #include @@ -26,9 +24,7 @@ struct Square { using Shapes = std::variant>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(cbor, test_variant) { const Shapes r = Rectangle{.height = 10, .width = 5}; write_and_read(r); diff --git a/tests/cbor/test_variant.hpp b/tests/cbor/test_variant.hpp deleted file mode 100644 index 0e58ce71..00000000 --- a/tests/cbor/test_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/cbor/test_wstring.cpp b/tests/cbor/test_wstring.cpp index ba6202c0..36759b16 100644 --- a/tests/cbor/test_wstring.cpp +++ b/tests/cbor/test_wstring.cpp @@ -1,5 +1,3 @@ -#include "test_wstring.hpp" - #include #include #include @@ -9,17 +7,15 @@ #include "write_and_read.hpp" -struct Test { +struct TestStruct { std::string theNormalString; std::wstring theWiderString; }; namespace test_wstring { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const Test test = Test{.theNormalString = "The normal string", - .theWiderString = L"The wider string"}; +TEST(cbor, test_wstring) { + const auto test = TestStruct{.theNormalString = "The normal string", + .theWiderString = L"The wider string"}; write_and_read(test); } diff --git a/tests/cbor/test_wstring.hpp b/tests/cbor/test_wstring.hpp deleted file mode 100644 index 0f93e784..00000000 --- a/tests/cbor/test_wstring.hpp +++ /dev/null @@ -1,3 +0,0 @@ -namespace test_wstring { - void test(); -} diff --git a/tests/cbor/tests.cpp b/tests/cbor/tests.cpp deleted file mode 100644 index 8a9fe0fb..00000000 --- a/tests/cbor/tests.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "test_array.hpp" -#include "test_box.hpp" -#include "test_custom_class1.hpp" -#include "test_custom_class3.hpp" -#include "test_custom_class4.hpp" -#include "test_default_values.hpp" -#include "test_deque.hpp" -#include "test_enum.hpp" -#include "test_field_variant.hpp" -#include "test_flag_enum.hpp" -#include "test_flag_enum_with_int.hpp" -#include "test_flatten.hpp" -#include "test_flatten_anonymous.hpp" -#include "test_forward_list.hpp" -#include "test_literal.hpp" -#include "test_literal_map.hpp" -#include "test_map.hpp" -#include "test_map_with_key_validation.hpp" -#include "test_monster_example.hpp" -#include "test_readme_example.hpp" -#include "test_readme_example2.hpp" -#include "test_ref.hpp" -#include "test_save_load.hpp" -#include "test_set.hpp" -#include "test_size.hpp" -#include "test_tagged_union.hpp" -#include "test_timestamp.hpp" -#include "test_unique_ptr.hpp" -#include "test_unique_ptr2.hpp" -#include "test_variant.hpp" -#include "test_wstring.hpp" - -int main() { - test_readme_example::test(); - test_readme_example2::test(); - test_flatten::test(); - test_flatten_anonymous::test(); - test_enum::test(); - test_flag_enum::test(); - test_flag_enum_with_int::test(); - test_map::test(); - test_map_with_key_validation::test(); - test_variant::test(); - test_field_variant::test(); - test_tagged_union::test(); - test_deque::test(); - test_forward_list::test(); - test_literal_map::test(); - test_literal::test(); - test_monster_example::test(); - test_ref::test(); - test_set::test(); - test_size::test(); - test_timestamp::test(); - test_unique_ptr::test(); - test_unique_ptr2::test(); - test_array::test(); - test_box::test(); - test_custom_class1::test(); - test_custom_class3::test(); - test_custom_class4::test(); - test_default_values::test(); - test_save_load::test(); - test_wstring::test(); - - return 0; -} diff --git a/tests/cbor/write_and_read.hpp b/tests/cbor/write_and_read.hpp index 0864ad53..f0078856 100644 --- a/tests/cbor/write_and_read.hpp +++ b/tests/cbor/write_and_read.hpp @@ -1,39 +1,20 @@ #ifndef WRITE_AND_READ_ #define WRITE_AND_READ_ +#include + #include #include #include template void write_and_read(const T& _struct) { - const auto bytes1 = rfl::cbor::write(_struct); - - const auto res = rfl::cbor::read(bytes1); - - if (!res) { - std::cout << "Test failed on read. Error: " << res.error().value().what() - << std::endl - << std::endl; - return; - } - - const auto bytes2 = rfl::cbor::write(res.value()); - - if (bytes1.size() != bytes2.size()) { - std::cout << "Test failed on write. Number of bytes was different." - << std::endl - << std::endl; - return; - } - - if (bytes1 != bytes2) { - std::cout << "Test failed on write. Content was not identical." << std::endl - << std::endl; - return; - } - - std::cout << "OK" << std::endl << std::endl; + const auto serialized1 = rfl::cbor::write(_struct); + const auto res = rfl::cbor::read(serialized1); + EXPECT_TRUE(res && true) << "Test failed on read. Error: " + << res.error().value().what(); + const auto serialized2 = rfl::cbor::write(res.value()); + EXPECT_EQ(serialized1, serialized2); } #endif diff --git a/tests/flexbuffers/CMakeLists.txt b/tests/flexbuffers/CMakeLists.txt index 19125e19..aaf8a05f 100644 --- a/tests/flexbuffers/CMakeLists.txt +++ b/tests/flexbuffers/CMakeLists.txt @@ -1,7 +1,18 @@ -project(reflect-cpp-flexbuffer-tests) +project(reflect-cpp-flexbuffers-tests) -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp") -add_executable(reflect-cpp-flexbuffers-tests ${SOURCES}) +add_executable( + reflect-cpp-flexbuffers-tests + ${SOURCES} + "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/src/gtest_main.cc" +) -target_link_libraries(reflect-cpp-flexbuffers-tests PRIVATE reflectcpp) +target_include_directories(reflect-cpp-flexbuffers-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") + +target_link_libraries( + reflect-cpp-flexbuffers-tests + PRIVATE + reflectcpp + "${REFLECT_CPP_GTEST_LIB}" +) diff --git a/tests/flexbuffers/README.md b/tests/flexbuffers/README.md deleted file mode 100644 index 9acf80e9..00000000 --- a/tests/flexbuffers/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Tests for flexbuffers - -This folder contains the tests for flexbuffers. A Docker-based build pipeline is provided for Linux users. - -Build the Docker container containing the build environment: - -``` -./build_docker.sh -``` - -Compile the tests: - -``` -./compile.sh -``` - -Run the tests: - -``` -./build/reflect-cpp-flatbuffers-tests -``` - -To run the scripts, you may have to run `chmod +x build_docker.sh` and `chmod +x compile.sh` first. diff --git a/tests/flexbuffers/test_all_of.cpp b/tests/flexbuffers/test_all_of.cpp deleted file mode 100644 index a75d37a8..00000000 --- a/tests/flexbuffers/test_all_of.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "test_all_of.hpp" - -#include -#include -#include -#include -#include - -// Make sure things still compile when -// rfl.hpp is included after rfl/flexbuf.hpp. -#include - -#include "write_and_read.hpp" - -namespace test_all_of { - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - using Age = rfl::Validator, rfl::Maximum<130>>>; - - struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name; - rfl::Field<"age", Age> age; - }; - - const auto homer = - Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; - - write_and_read(homer); -} -} // namespace test_all_of diff --git a/tests/flexbuffers/test_all_of.hpp b/tests/flexbuffers/test_all_of.hpp deleted file mode 100644 index 082d508a..00000000 --- a/tests/flexbuffers/test_all_of.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_all_of{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_anonymous_fields.cpp b/tests/flexbuffers/test_anonymous_fields.cpp deleted file mode 100644 index 8ff2a704..00000000 --- a/tests/flexbuffers/test_anonymous_fields.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "test_anonymous_fields.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_anonymous_fields { - -using Age = rfl::Validator, rfl::Maximum<130>>>; - -struct Person { - std::string first_name; - std::string last_name; - rfl::Timestamp<"%Y-%m-%d"> birthday; - Age age; - rfl::Email email; - std::vector children; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const auto bart = Person{.first_name = "Bart", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 10, - .email = "bart@simpson.com"}; - - const auto lisa = Person{.first_name = "Lisa", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 8, - .email = "lisa@simpson.com"}; - - const auto maggie = Person{.first_name = "Maggie", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 0, - .email = "maggie@simpson.com"}; - - const auto homer = - Person{.first_name = "Homer", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 45, - .email = "homer@simpson.com", - .children = std::vector({bart, lisa, maggie})}; - - write_and_read(homer); -} -} // namespace test_anonymous_fields diff --git a/tests/flexbuffers/test_anonymous_fields.hpp b/tests/flexbuffers/test_anonymous_fields.hpp deleted file mode 100644 index 16c47d36..00000000 --- a/tests/flexbuffers/test_anonymous_fields.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_anonymous_fields{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_array.cpp b/tests/flexbuffers/test_array.cpp new file mode 100644 index 00000000..a4bebf0a --- /dev/null +++ b/tests/flexbuffers/test_array.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include + +// Make sure things still compile when +// rfl.hpp is included after rfl/cbor.hpp. +#include + +#include "write_and_read.hpp" + +namespace test_array { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children = nullptr; +}; + +TEST(flexbuf, test_array) { + auto bart = Person{.first_name = "Bart"}; + + auto lisa = Person{.first_name = "Lisa"}; + + auto maggie = Person{.first_name = "Maggie"}; + + const auto homer = Person{ + .first_name = "Homer", + .children = std::make_unique>(std::array{ + std::move(bart), std::move(lisa), std::move(maggie)})}; + + write_and_read(homer); +} +} // namespace test_array diff --git a/tests/flexbuffers/test_box.cpp b/tests/flexbuffers/test_box.cpp index 00625393..3f45b087 100644 --- a/tests/flexbuffers/test_box.cpp +++ b/tests/flexbuffers/test_box.cpp @@ -1,9 +1,6 @@ -#include "test_box.hpp" - #include #include #include -#include #include #include #include @@ -14,13 +11,15 @@ namespace test_box { struct DecisionTree { struct Leaf { - rfl::Field<"value", double> value; + using Tag = rfl::Literal<"Leaf">; + double value; }; struct Node { - rfl::Field<"criticalValue", double> critical_value; - rfl::Field<"left", rfl::Box> lesser; - rfl::Field<"right", rfl::Box> greater; + using Tag = rfl::Literal<"Node">; + rfl::Rename<"criticalValue", double> critical_value; + rfl::Box lesser; + rfl::Box greater; }; using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; @@ -28,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_box) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; @@ -43,5 +40,6 @@ void test() { const DecisionTree tree{.leaf_or_node = std::move(node)}; write_and_read(tree); + } } // namespace test_box diff --git a/tests/flexbuffers/test_box.hpp b/tests/flexbuffers/test_box.hpp deleted file mode 100644 index a564b9e1..00000000 --- a/tests/flexbuffers/test_box.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_box{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_custom_class1.cpp b/tests/flexbuffers/test_custom_class1.cpp index c0685f84..899e899e 100644 --- a/tests/flexbuffers/test_custom_class1.cpp +++ b/tests/flexbuffers/test_custom_class1.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class1.hpp" - #include #include #include -#include #include #include #include @@ -14,9 +11,9 @@ namespace test_custom_class1 { struct Person { struct PersonImpl { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::vector> children = rfl::default_value; + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::vector children; }; using ReflectionType = PersonImpl; @@ -32,9 +29,7 @@ struct Person { PersonImpl impl; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_custom_class1) { const auto bart = Person("Bart"); write_and_read(bart); diff --git a/tests/flexbuffers/test_custom_class1.hpp b/tests/flexbuffers/test_custom_class1.hpp deleted file mode 100644 index eafe6cd0..00000000 --- a/tests/flexbuffers/test_custom_class1.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class1{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_custom_class2.cpp b/tests/flexbuffers/test_custom_class2.cpp deleted file mode 100644 index 6e8487c5..00000000 --- a/tests/flexbuffers/test_custom_class2.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "test_custom_class2.hpp" - -#include -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_custom_class2 { - -struct Person { - Person(const std::string& _first_name, const std::string& _last_name, - const int _age) - : first_name_(_first_name), last_name_(_last_name), age_(_age) {} - - const auto& first_name() const { return first_name_; } - - const auto& last_name() const { return last_name_; } - - auto age() const { return age_; } - - private: - std::string first_name_; - std::string last_name_; - int age_; -}; - -struct PersonImpl { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name; - rfl::Field<"age", int> age; - - static PersonImpl from_class(const Person& _p) noexcept { - return PersonImpl{.first_name = _p.first_name(), - .last_name = _p.last_name(), - .age = _p.age()}; - } - - Person to_class() const { return Person(first_name(), last_name(), age()); } -}; - -} // namespace test_custom_class2 - -namespace rfl { -namespace parsing { - -template -struct Parser - : public CustomParser {}; - -} // namespace parsing -} // namespace rfl - -namespace test_custom_class2 { - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const auto bart = test_custom_class2::Person("Bart", "Simpson", 10); - - write_and_read(bart); -} - -} // namespace test_custom_class2 diff --git a/tests/flexbuffers/test_custom_class2.hpp b/tests/flexbuffers/test_custom_class2.hpp deleted file mode 100644 index 21cfbd51..00000000 --- a/tests/flexbuffers/test_custom_class2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class2{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_custom_class3.cpp b/tests/flexbuffers/test_custom_class3.cpp index fdd799d4..edd41c42 100644 --- a/tests/flexbuffers/test_custom_class3.cpp +++ b/tests/flexbuffers/test_custom_class3.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class3.hpp" - #include #include #include -#include #include #include #include @@ -13,11 +10,9 @@ namespace test_custom_class3 { struct Person { - Person(const std::string& _first_name, - const rfl::Box& _last_name, int _age) - : first_name_(_first_name), - last_name_(rfl::make_box(*_last_name)), - age_(_age) {} + Person(const std::string& _first_name, const std::string& _last_name, + const int _age) + : first_name_(_first_name), last_name_(_last_name), age_(_age) {} const auto& first_name() const { return first_name_; } @@ -27,22 +22,23 @@ struct Person { private: std::string first_name_; - rfl::Box last_name_; + std::string last_name_; int age_; }; struct PersonImpl { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", rfl::Box> last_name; - rfl::Field<"age", int> age; + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name; + int age; static PersonImpl from_class(const Person& _p) noexcept { return PersonImpl{.first_name = _p.first_name(), - .last_name = rfl::make_box(*_p.last_name()), + .last_name = _p.last_name(), .age = _p.age()}; } -}; + Person to_class() const { return Person(first_name(), last_name(), age); } +}; } // namespace test_custom_class3 namespace rfl { @@ -58,11 +54,8 @@ struct Parser namespace test_custom_class3 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const auto bart = test_custom_class3::Person( - "Bart", rfl::make_box("Simpson"), 10); +TEST(flexbuf, test_custom_class3) { + const auto bart = Person("Bart", "Simpson", 10); write_and_read(bart); } diff --git a/tests/flexbuffers/test_custom_class3.hpp b/tests/flexbuffers/test_custom_class3.hpp deleted file mode 100644 index 9a6fdab4..00000000 --- a/tests/flexbuffers/test_custom_class3.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class3{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_custom_class4.cpp b/tests/flexbuffers/test_custom_class4.cpp new file mode 100644 index 00000000..1ba35f4a --- /dev/null +++ b/tests/flexbuffers/test_custom_class4.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_custom_class4 { + +struct Person { + Person(const std::string& _first_name, + const rfl::Box& _last_name, int _age) + : first_name_(_first_name), + last_name_(rfl::make_box(*_last_name)), + age_(_age) {} + + const auto& first_name() const { return first_name_; } + + const auto& last_name() const { return last_name_; } + + auto age() const { return age_; } + + private: + std::string first_name_; + rfl::Box last_name_; + int age_; +}; + +struct PersonImpl { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", rfl::Box> last_name; + rfl::Field<"age", int> age; + + static PersonImpl from_class(const Person& _p) noexcept { + return PersonImpl{.first_name = _p.first_name(), + .last_name = rfl::make_box(*_p.last_name()), + .age = _p.age()}; + } +}; + +} // namespace test_custom_class4 + +namespace rfl { +namespace parsing { + +template +struct Parser + : public CustomParser {}; + +} // namespace parsing +} // namespace rfl + +namespace test_custom_class4 { + +TEST(flexbuf, test_custom_class4) { + const auto bart = test_custom_class4::Person( + "Bart", rfl::make_box("Simpson"), 10); + + write_and_read(bart); +} +} // namespace test_custom_class4 diff --git a/tests/flexbuffers/test_custom_constructor.cpp b/tests/flexbuffers/test_custom_constructor.cpp deleted file mode 100644 index bad09e24..00000000 --- a/tests/flexbuffers/test_custom_constructor.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "test_custom_constructor.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_custom_constructor { - -struct Person { - static rfl::Result from_flexbuf( - typename rfl::flexbuf::Reader::InputVarType _obj) { - /// This only exists for the purpose of the test. - const auto change_first_name = [](auto&& _person) { - return rfl::replace(std::move(_person), - rfl::Field<"firstName", std::string>("Bart")); - }; - const auto from_nt = [](auto&& _nt) { - return rfl::from_named_tuple(std::move(_nt)); - }; - return rfl::flexbuf::read>(_obj) - .transform(from_nt) - .transform(change_first_name); - } - - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name; - rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const auto person1 = Person{ - .first_name = "Homer", .last_name = "Simpson", .birthday = "1987-04-19"}; - - const auto bytes = rfl::flexbuf::write(person1); - - const auto res = rfl::flexbuf::read(bytes); - - if (!res) { - std::cout << "Test failed on read. Error: " << res.error().value().what() - << std::endl; - return; - } - - if (res.value().first_name() != "Bart") { - std::cout << "Expected 'Bart', got '" << res.value().first_name() << "'" - << std::endl - << std::endl; - } else { - std::cout << "OK" << std::endl << std::endl; - } -} -} // namespace test_custom_constructor diff --git a/tests/flexbuffers/test_custom_constructor.hpp b/tests/flexbuffers/test_custom_constructor.hpp deleted file mode 100644 index 013721d0..00000000 --- a/tests/flexbuffers/test_custom_constructor.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_constructor{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_optional_fields.cpp b/tests/flexbuffers/test_default_values.cpp similarity index 51% rename from tests/flexbuffers/test_optional_fields.cpp rename to tests/flexbuffers/test_default_values.cpp index f15c35a8..31d68ebf 100644 --- a/tests/flexbuffers/test_optional_fields.cpp +++ b/tests/flexbuffers/test_default_values.cpp @@ -1,36 +1,28 @@ -#include "test_optional_fields.hpp" - +#include #include #include -#include #include #include #include #include "write_and_read.hpp" -namespace test_optional_fields { +namespace test_default_values { struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::optional>> children = - rfl::default_value; + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_default_values) { const auto bart = Person{.first_name = "Bart"}; - const auto lisa = Person{.first_name = "Lisa"}; - const auto maggie = Person{.first_name = "Maggie"}; - const auto homer = Person{.first_name = "Homer", .children = std::vector({bart, lisa, maggie})}; write_and_read(homer); } -} // namespace test_optional_fields +} // namespace test_default_values diff --git a/tests/flexbuffers/test_deque.cpp b/tests/flexbuffers/test_deque.cpp index 7e1d1139..aa120c37 100644 --- a/tests/flexbuffers/test_deque.cpp +++ b/tests/flexbuffers/test_deque.cpp @@ -1,8 +1,5 @@ -#include "test_deque.hpp" - #include #include -#include #include #include #include @@ -12,15 +9,12 @@ namespace test_deque { struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_default_values) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); @@ -30,5 +24,6 @@ void test() { Person{.first_name = "Homer", .children = std::move(children)}; write_and_read(homer); + } } // namespace test_deque diff --git a/tests/flexbuffers/test_deque.hpp b/tests/flexbuffers/test_deque.hpp deleted file mode 100644 index 6781e880..00000000 --- a/tests/flexbuffers/test_deque.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_deque{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_enum.cpp b/tests/flexbuffers/test_enum.cpp new file mode 100644 index 00000000..7802e8af --- /dev/null +++ b/tests/flexbuffers/test_enum.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_enum { + +enum class Color { red, green, blue, yellow }; + +struct Circle { + float radius; + Color color; +}; + +TEST(flexbuf, test_enum) { + const auto circle = Circle{.radius = 2.0, .color = Color::green}; + + write_and_read(circle); +} + +} // namespace test_enum diff --git a/tests/flexbuffers/test_field_variant.cpp b/tests/flexbuffers/test_field_variant.cpp index e87ce872..2c1a830f 100644 --- a/tests/flexbuffers/test_field_variant.cpp +++ b/tests/flexbuffers/test_field_variant.cpp @@ -1,9 +1,6 @@ -#include "test_field_variant.hpp" - #include #include #include -#include #include #include #include @@ -13,25 +10,23 @@ namespace test_field_variant { struct Circle { - rfl::Field<"radius", double> radius; + double radius; }; struct Rectangle { - rfl::Field<"height", double> height; - rfl::Field<"width", double> width; + double height; + double width; }; struct Square { - rfl::Field<"width", double> width; + double width; }; using Shapes = rfl::Variant, rfl::Field<"rectangle", Rectangle>, rfl::Field<"square", rfl::Box>>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_field_variant) { const Shapes r = rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); diff --git a/tests/flexbuffers/test_field_variant.hpp b/tests/flexbuffers/test_field_variant.hpp deleted file mode 100644 index ba93e732..00000000 --- a/tests/flexbuffers/test_field_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_field_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_flag_enum.cpp b/tests/flexbuffers/test_flag_enum.cpp new file mode 100644 index 00000000..ccba582b --- /dev/null +++ b/tests/flexbuffers/test_flag_enum.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_flag_enum { + +enum class Color { + red = 256, + green = 512, + blue = 1024, + yellow = 2048, + orange = (256 | 2048) // red + yellow = orange +}; + +inline Color operator|(Color c1, Color c2) { + return static_cast(static_cast(c1) | static_cast(c2)); +} + +struct Circle { + float radius; + Color color; +}; + +TEST(flexbuf, test_flag_enum) { + const auto circle = + Circle{.radius = 2.0, .color = Color::blue | Color::orange}; + + write_and_read(circle); +} + +} // namespace test_flag_enum diff --git a/tests/flexbuffers/test_flag_enum_with_int.cpp b/tests/flexbuffers/test_flag_enum_with_int.cpp new file mode 100644 index 00000000..1dc35155 --- /dev/null +++ b/tests/flexbuffers/test_flag_enum_with_int.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_flag_enum_with_int { + +enum class Color { + red = 256, + green = 512, + blue = 1024, + yellow = 2048, + orange = (256 | 2048) // red + yellow = orange +}; + +inline Color operator|(Color c1, Color c2) { + return static_cast(static_cast(c1) | static_cast(c2)); +} + +struct Circle { + float radius; + Color color; +}; + +TEST(flexbuf, test_flag_enum_with_int) { + const auto circle = Circle{.radius = 2.0, .color = static_cast(10000)}; + + write_and_read(circle); +} + +} // namespace test_flag_enum_with_int diff --git a/tests/flexbuffers/test_flatten.cpp b/tests/flexbuffers/test_flatten.cpp new file mode 100644 index 00000000..fa7d9431 --- /dev/null +++ b/tests/flexbuffers/test_flatten.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_flatten { + +struct Person { + rfl::Field<"firstName", std::string> first_name; + rfl::Field<"lastName", rfl::Box> last_name; + rfl::Field<"age", int> age; +}; + +struct Employee { + rfl::Flatten person; + rfl::Field<"employer", rfl::Box> employer; + rfl::Field<"salary", float> salary; +}; + +TEST(flexbuf, test_flatten) { + const auto employee = Employee{ + .person = Person{.first_name = "Homer", + .last_name = rfl::make_box("Simpson"), + .age = 45}, + .employer = rfl::make_box("Mr. Burns"), + .salary = 60000.0}; + + write_and_read(employee); +} +} // namespace test_flatten diff --git a/tests/flexbuffers/test_flatten_anonymous.cpp b/tests/flexbuffers/test_flatten_anonymous.cpp index 7db468dd..13ba28de 100644 --- a/tests/flexbuffers/test_flatten_anonymous.cpp +++ b/tests/flexbuffers/test_flatten_anonymous.cpp @@ -1,9 +1,6 @@ -#include "test_flatten_anonymous.hpp" - #include #include #include -#include #include #include #include @@ -24,9 +21,7 @@ struct Employee { float salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_flatten_anonymous) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), @@ -36,4 +31,5 @@ void test() { write_and_read(employee); } + } // namespace test_flatten_anonymous diff --git a/tests/flexbuffers/test_flatten_anonymous.hpp b/tests/flexbuffers/test_flatten_anonymous.hpp deleted file mode 100644 index 7ffa2785..00000000 --- a/tests/flexbuffers/test_flatten_anonymous.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten_anonymous{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_forward_list.cpp b/tests/flexbuffers/test_forward_list.cpp index 4743e019..c747a3f5 100644 --- a/tests/flexbuffers/test_forward_list.cpp +++ b/tests/flexbuffers/test_forward_list.cpp @@ -1,8 +1,5 @@ -#include "test_forward_list.hpp" - #include #include -#include #include #include #include @@ -12,15 +9,12 @@ namespace test_forward_list { struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_forward_list) { auto children = std::make_unique>(); children->emplace_front(Person{.first_name = "Maggie"}); children->emplace_front(Person{.first_name = "Lisa"}); @@ -30,5 +24,6 @@ void test() { Person{.first_name = "Homer", .children = std::move(children)}; write_and_read(homer); + } } // namespace test_forward_list diff --git a/tests/flexbuffers/test_forward_list.hpp b/tests/flexbuffers/test_forward_list.hpp deleted file mode 100644 index 9784a0c4..00000000 --- a/tests/flexbuffers/test_forward_list.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_forward_list{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_list.cpp b/tests/flexbuffers/test_list.cpp deleted file mode 100644 index 5190d244..00000000 --- a/tests/flexbuffers/test_list.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "test_list.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_list { - -struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - auto children = std::make_unique>(); - children->emplace_back(Person{.first_name = "Bart"}); - children->emplace_back(Person{.first_name = "Lisa"}); - children->emplace_back(Person{.first_name = "Maggie"}); - - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; - - write_and_read(homer); -} -} // namespace test_list diff --git a/tests/flexbuffers/test_list.hpp b/tests/flexbuffers/test_list.hpp deleted file mode 100644 index 956d36cc..00000000 --- a/tests/flexbuffers/test_list.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_list{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_literal.cpp b/tests/flexbuffers/test_literal.cpp index af92ef3e..9c5d8b8b 100644 --- a/tests/flexbuffers/test_literal.cpp +++ b/tests/flexbuffers/test_literal.cpp @@ -1,9 +1,6 @@ -#include "test_literal.hpp" - #include #include #include -#include #include #include #include @@ -16,14 +13,12 @@ using FirstName = rfl::Literal<"Homer", "Marge", "Bart", "Lisa", "Maggie">; using LastName = rfl::Literal<"Simpson">; struct Person { - rfl::Field<"firstName", FirstName> first_name; - rfl::Field<"lastName", LastName> last_name = rfl::default_value; - rfl::Field<"children", std::vector> children = rfl::default_value; + rfl::Rename<"firstName", FirstName> first_name; + rfl::Rename<"lastName", LastName> last_name; + std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_literal) { const auto bart = Person{.first_name = FirstName::make<"Bart">()}; write_and_read(bart); diff --git a/tests/flexbuffers/test_literal.hpp b/tests/flexbuffers/test_literal.hpp deleted file mode 100644 index ccd500ef..00000000 --- a/tests/flexbuffers/test_literal.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_literal_map.cpp b/tests/flexbuffers/test_literal_map.cpp new file mode 100644 index 00000000..46fa5d14 --- /dev/null +++ b/tests/flexbuffers/test_literal_map.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_literal_map { + +using FieldName = rfl::Literal<"firstName", "lastName">; + +TEST(flexbuf, test_literal_map) { + std::map> homer; + homer.insert(std::make_pair(FieldName::make<"firstName">(), + std::make_unique("Homer"))); + homer.insert(std::make_pair(FieldName::make<"lastName">(), + std::make_unique("Simpson"))); + + write_and_read(homer); +} +} // namespace test_literal_map diff --git a/tests/flexbuffers/test_map.cpp b/tests/flexbuffers/test_map.cpp index 97a8a74b..119290bb 100644 --- a/tests/flexbuffers/test_map.cpp +++ b/tests/flexbuffers/test_map.cpp @@ -1,9 +1,6 @@ -#include "test_map.hpp" - #include #include #include -#include #include #include @@ -12,19 +9,16 @@ namespace test_map { struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::map children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - auto children = std::make_unique>(); - children->insert(std::make_pair(1, Person{.first_name = "Bart"})); - children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); - children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); +TEST(flexbuf, test_map) { + auto children = std::map(); + children.insert(std::make_pair("child1", Person{.first_name = "Bart"})); + children.insert(std::make_pair("child2", Person{.first_name = "Lisa"})); + children.insert(std::make_pair("child3", Person{.first_name = "Maggie"})); const auto homer = Person{.first_name = "Homer", .children = std::move(children)}; diff --git a/tests/flexbuffers/test_map.hpp b/tests/flexbuffers/test_map.hpp deleted file mode 100644 index 9ae49728..00000000 --- a/tests/flexbuffers/test_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_map_with_key_validation.cpp b/tests/flexbuffers/test_map_with_key_validation.cpp new file mode 100644 index 00000000..3a978ead --- /dev/null +++ b/tests/flexbuffers/test_map_with_key_validation.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_map_with_key_validation { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children; +}; + +TEST(flexbuf, test_map_with_key_validation) { + auto children = std::make_unique>(); + + children->insert(std::make_pair("Bart", Person{.first_name = "Bart"})); + children->insert(std::make_pair("Lisa", Person{.first_name = "Lisa"})); + children->insert(std::make_pair("Maggie", Person{.first_name = "Maggie"})); + + const auto homer = + Person{.first_name = "Homer", .children = std::move(children)}; + + write_and_read(homer); +} +} // namespace test_map_with_key_validation diff --git a/tests/flexbuffers/test_monster_example1.cpp b/tests/flexbuffers/test_monster_example.cpp similarity index 69% rename from tests/flexbuffers/test_monster_example1.cpp rename to tests/flexbuffers/test_monster_example.cpp index b1db84b2..d6c65eb5 100644 --- a/tests/flexbuffers/test_monster_example1.cpp +++ b/tests/flexbuffers/test_monster_example.cpp @@ -1,17 +1,14 @@ -#include "test_monster_example1.hpp" - #include #include -#include #include #include #include #include "write_and_read.hpp" -namespace test_monster_example1 { +namespace test_monster_example { -enum class Color { Red, Green, Blue }; +using Color = rfl::Literal<"Red", "Green", "Blue">; struct Weapon { std::string name; @@ -32,16 +29,14 @@ struct Monster { short hp = 100; std::string name; bool friendly = false; - std::vector inventory; - Color color = Color::Blue; + std::vector inventory; + Color color = Color::make<"Blue">(); std::vector weapons; Equipment equipped; std::vector path; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_monster_example) { const auto sword = Weapon{.name = "Sword", .damage = 3}; const auto axe = Weapon{.name = "Axe", .damage = 5}; @@ -49,19 +44,17 @@ void test() { const auto position = Vec3{1.0f, 2.0f, 3.0f}; - const auto inventory = - std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + const auto inventory = std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); const auto orc = Monster{.pos = position, .mana = 150, .hp = 80, .name = "MyMonster", .inventory = inventory, - .color = Color::Red, + .color = Color::make<"Red">(), .weapons = weapons, .equipped = rfl::make_field<"weapon">(axe)}; write_and_read(orc); } - -} // namespace test_monster_example1 +} // namespace test_monster_example diff --git a/tests/flexbuffers/test_monster_example1.hpp b/tests/flexbuffers/test_monster_example1.hpp deleted file mode 100644 index 80cd680d..00000000 --- a/tests/flexbuffers/test_monster_example1.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_monster_example1{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_monster_example2.cpp b/tests/flexbuffers/test_monster_example2.cpp deleted file mode 100644 index 3cb2ab73..00000000 --- a/tests/flexbuffers/test_monster_example2.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "test_monster_example2.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_monster_example2 { - -using Color = rfl::Literal<"Red", "Green", "Blue">; - -struct Weapon { - rfl::Field<"name", std::string> name; - rfl::Field<"damage", short> damage; -}; - -using Equipment = rfl::Variant>; - -struct Vec3 { - rfl::Field<"x", float> x; - rfl::Field<"y", float> y; - rfl::Field<"z", float> z; -}; - -struct Monster { - rfl::Field<"pos", Vec3> pos; - rfl::Field<"mana", short> mana = 150; - rfl::Field<"hp", short> hp = 100; - rfl::Field<"name", std::string> name; - rfl::Field<"friendly", bool> friendly = false; - rfl::Field<"inventory", std::vector> inventory; - rfl::Field<"color", Color> color = Color::make<"Blue">(); - rfl::Field<"weapons", std::vector> weapons; - rfl::Field<"equipped", Equipment> equipped; - rfl::Field<"path", std::vector> path; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const auto sword = Weapon{.name = "Sword", .damage = 3}; - const auto axe = Weapon{.name = "Axe", .damage = 5}; - - const auto weapons = std::vector({sword, axe}); - - const auto position = Vec3{1.0f, 2.0f, 3.0f}; - - const auto inventory = - std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); - - const auto orc = Monster{.pos = position, - .mana = 150, - .hp = 80, - .name = "MyMonster", - .inventory = inventory, - .color = Color::make<"Red">(), - .weapons = weapons, - .equipped = rfl::make_field<"weapon">(axe), - .path = rfl::default_value}; - - write_and_read(orc); -} -} // namespace test_monster_example2 diff --git a/tests/flexbuffers/test_monster_example2.hpp b/tests/flexbuffers/test_monster_example2.hpp deleted file mode 100644 index 9d82a452..00000000 --- a/tests/flexbuffers/test_monster_example2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_monster_example2{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_multimap.cpp b/tests/flexbuffers/test_multimap.cpp deleted file mode 100644 index add150d1..00000000 --- a/tests/flexbuffers/test_multimap.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "test_multimap.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_multimap { - -struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - auto children = std::make_unique>(); - children->insert(std::make_pair(1, Person{.first_name = "Bart"})); - children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); - children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); - - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; - - write_and_read(homer); -} -} // namespace test_multimap diff --git a/tests/flexbuffers/test_multimap.hpp b/tests/flexbuffers/test_multimap.hpp deleted file mode 100644 index 81845572..00000000 --- a/tests/flexbuffers/test_multimap.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_multimap{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_multiset.cpp b/tests/flexbuffers/test_multiset.cpp deleted file mode 100644 index 6a5a31ec..00000000 --- a/tests/flexbuffers/test_multiset.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "test_multiset.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_multiset { - -struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - auto children = std::make_unique>( - std::multiset({"Bart", "Lisa", "Maggie"})); - - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; - - write_and_read(homer); -} -} // namespace test_multiset diff --git a/tests/flexbuffers/test_multiset.hpp b/tests/flexbuffers/test_multiset.hpp deleted file mode 100644 index adfcf186..00000000 --- a/tests/flexbuffers/test_multiset.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_multiset{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_optional_fields.hpp b/tests/flexbuffers/test_optional_fields.hpp deleted file mode 100644 index 640cab95..00000000 --- a/tests/flexbuffers/test_optional_fields.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_optional_fields{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_readme_example.cpp b/tests/flexbuffers/test_readme_example.cpp index 7bc77c80..4212bf18 100644 --- a/tests/flexbuffers/test_readme_example.cpp +++ b/tests/flexbuffers/test_readme_example.cpp @@ -1,8 +1,5 @@ -#include "test_readme_example.hpp" - #include #include -#include #include #include #include @@ -11,49 +8,39 @@ namespace test_readme_example { -using Age = rfl::Validator, rfl::Maximum<130>>>; +using Age = rfl::Validator, rfl::Maximum<130>>; struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name; - rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; - rfl::Field<"age", Age> age; - rfl::Field<"email", rfl::Email> email; - rfl::Field<"children", std::vector> children; + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::string town = "Springfield"; + rfl::Timestamp<"%Y-%m-%d"> birthday; + Age age; + rfl::Email email; + std::vector child; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_readme_example) { const auto bart = Person{.first_name = "Bart", - .last_name = "Simpson", .birthday = "1987-04-19", .age = 10, - .email = "bart@simpson.com", - .children = std::vector()}; - - const auto lisa = Person{ - .first_name = "Lisa", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 8, - .email = "lisa@simpson.com", - .children = rfl::default_value // same as std::vector() - }; - - const auto maggie = - rfl::replace(lisa, rfl::make_field<"firstName">(std::string("Maggie")), - rfl::make_field<"email">(std::string("maggie@simpson.com")), - rfl::make_field<"age">(0)); - - const auto homer = - Person{.first_name = "Homer", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 45, - .email = "homer@simpson.com", - .children = std::vector({bart, lisa, maggie})}; + .email = "bart@simpson.com"}; + + const auto lisa = Person{.first_name = "Lisa", + .birthday = "1987-04-19", + .age = 8, + .email = "lisa@simpson.com"}; + + const auto maggie = Person{.first_name = "Maggie", + .birthday = "1987-04-19", + .age = 0, + .email = "maggie@simpson.com"}; + + const auto homer = Person{.first_name = "Homer", + .birthday = "1987-04-19", + .age = 45, + .email = "homer@simpson.com", + .child = std::vector({bart, lisa, maggie})}; write_and_read(homer); } diff --git a/tests/flexbuffers/test_readme_example.hpp b/tests/flexbuffers/test_readme_example.hpp deleted file mode 100644 index 68c6cf81..00000000 --- a/tests/flexbuffers/test_readme_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_readme_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_readme_example2.cpp b/tests/flexbuffers/test_readme_example2.cpp new file mode 100644 index 00000000..02cabd76 --- /dev/null +++ b/tests/flexbuffers/test_readme_example2.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_readme_example2 { + +struct Person { + std::string first_name; + std::string last_name; + int age; +}; + +TEST(flexbuf, test_readme_example2) { + const auto homer = + Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; + + write_and_read(homer); +} +} // namespace test_readme_example2 diff --git a/tests/flexbuffers/test_ref.cpp b/tests/flexbuffers/test_ref.cpp index 41ceca1c..1e9e6733 100644 --- a/tests/flexbuffers/test_ref.cpp +++ b/tests/flexbuffers/test_ref.cpp @@ -1,9 +1,6 @@ -#include "test_ref.hpp" - #include #include #include -#include #include #include #include @@ -14,13 +11,15 @@ namespace test_ref { struct DecisionTree { struct Leaf { - rfl::Field<"value", double> value; + using Tag = rfl::Literal<"Leaf">; + double value; }; struct Node { - rfl::Field<"criticalValue", double> critical_value; - rfl::Field<"left", rfl::Ref> lesser; - rfl::Field<"right", rfl::Ref> greater; + using Tag = rfl::Literal<"Node">; + rfl::Rename<"criticalValue", double> critical_value; + rfl::Ref lesser; + rfl::Ref greater; }; using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; @@ -28,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_ref) { const auto leaf1 = DecisionTree::Leaf{.value = 3.0}; const auto leaf2 = DecisionTree::Leaf{.value = 5.0}; @@ -43,5 +40,6 @@ void test() { const DecisionTree tree{.leaf_or_node = std::move(node)}; write_and_read(tree); + } } // namespace test_ref diff --git a/tests/flexbuffers/test_ref.hpp b/tests/flexbuffers/test_ref.hpp deleted file mode 100644 index d289ba09..00000000 --- a/tests/flexbuffers/test_ref.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_ref{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_save_load.cpp b/tests/flexbuffers/test_save_load.cpp index 9d9d7d7e..5aaa4507 100644 --- a/tests/flexbuffers/test_save_load.cpp +++ b/tests/flexbuffers/test_save_load.cpp @@ -1,5 +1,3 @@ -#include "test_save_load.hpp" - #include #include #include @@ -8,7 +6,7 @@ #include #include -#include "write_and_read.hpp" +#include namespace test_save_load { @@ -16,17 +14,15 @@ using Age = rfl::Validator, rfl::Maximum<130>>>; struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name; - rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; - rfl::Field<"age", Age> age; - rfl::Field<"email", rfl::Email> email; - rfl::Field<"children", std::vector> children; + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name; + rfl::Timestamp<"%Y-%m-%d"> birthday; + Age age; + rfl::Email email; + std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_save_load) { const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19", @@ -34,19 +30,17 @@ void test() { .email = "bart@simpson.com", .children = std::vector()}; - const auto lisa = Person{ - .first_name = "Lisa", - .last_name = "Simpson", - .birthday = "1987-04-19", - .age = 8, - .email = "lisa@simpson.com", - .children = rfl::default_value // same as std::vector() - }; + const auto lisa = Person{.first_name = "Lisa", + .last_name = "Simpson", + .birthday = "1987-04-19", + .age = 8, + .email = "lisa@simpson.com"}; - const auto maggie = - rfl::replace(lisa, rfl::make_field<"firstName">(std::string("Maggie")), - rfl::make_field<"email">(std::string("maggie@simpson.com")), - rfl::make_field<"age">(0)); + const auto maggie = Person{.first_name = "Maggie", + .last_name = "Simpson", + .birthday = "1987-04-19", + .age = 0, + .email = "maggie@simpson.com"}; const auto homer1 = Person{.first_name = "Homer", @@ -56,19 +50,13 @@ void test() { .email = "homer@simpson.com", .children = std::vector({bart, lisa, maggie})}; - rfl::flexbuf::save("homer.fb", homer1); - - const auto homer2 = rfl::flexbuf::load("homer.fb").value(); + rfl::flexbuf::save("homer.flexbuf", homer1); - const auto bytes1 = rfl::flexbuf::write(homer1); - const auto bytes2 = rfl::flexbuf::write(homer2); + const auto homer2 = rfl::flexbuf::load("homer.flexbuf").value(); - if (bytes1 != bytes2) { - std::cout << "Test failed. Content was not identical." << std::endl - << std::endl; - return; - } + const auto string1 = rfl::flexbuf::write(homer1); + const auto string2 = rfl::flexbuf::write(homer2); - std::cout << "OK" << std::endl << std::endl; + EXPECT_EQ(string1, string2); } } // namespace test_save_load diff --git a/tests/flexbuffers/test_save_load.hpp b/tests/flexbuffers/test_save_load.hpp deleted file mode 100644 index a8829fd1..00000000 --- a/tests/flexbuffers/test_save_load.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_save_load{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_set.cpp b/tests/flexbuffers/test_set.cpp index 4da6eeff..5b7d1031 100644 --- a/tests/flexbuffers/test_set.cpp +++ b/tests/flexbuffers/test_set.cpp @@ -1,8 +1,5 @@ -#include "test_set.hpp" - #include #include -#include #include #include #include @@ -12,15 +9,12 @@ namespace test_set { struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_set) { auto children = std::make_unique>( std::set({"Bart", "Lisa", "Maggie"})); diff --git a/tests/flexbuffers/test_set.hpp b/tests/flexbuffers/test_set.hpp deleted file mode 100644 index 142a663b..00000000 --- a/tests/flexbuffers/test_set.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_set{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_size.cpp b/tests/flexbuffers/test_size.cpp new file mode 100644 index 00000000..b07f02d5 --- /dev/null +++ b/tests/flexbuffers/test_size.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_size { + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name; + rfl::Timestamp<"%Y-%m-%d"> birthday; + rfl::Validator, + rfl::Size, rfl::EqualTo<3>>>> + children; +}; + +TEST(flexbuf, test_size) { + const auto bart = Person{ + .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto lisa = Person{ + .first_name = "Lisa", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto maggie = Person{ + .first_name = "Maggie", .last_name = "Simpson", .birthday = "1987-04-19"}; + + const auto homer = + Person{.first_name = "Homer", + .last_name = "Simpson", + .birthday = "1987-04-19", + .children = std::vector({bart, lisa, maggie})}; + + write_and_read(homer); +} +} // namespace test_size diff --git a/tests/flexbuffers/test_string_map.cpp b/tests/flexbuffers/test_string_map.cpp index fc2157cb..1f45634e 100644 --- a/tests/flexbuffers/test_string_map.cpp +++ b/tests/flexbuffers/test_string_map.cpp @@ -1,19 +1,14 @@ -#include "test_string_map.hpp" - #include #include #include #include -#include #include #include #include "write_and_read.hpp" namespace test_string_map { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_string_map) { std::map> homer; homer.insert( std::make_pair("firstName", std::make_unique("Homer"))); diff --git a/tests/flexbuffers/test_string_map.hpp b/tests/flexbuffers/test_string_map.hpp deleted file mode 100644 index 94cb975a..00000000 --- a/tests/flexbuffers/test_string_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_string_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_string_unordered_map.cpp b/tests/flexbuffers/test_string_unordered_map.cpp deleted file mode 100644 index 07241877..00000000 --- a/tests/flexbuffers/test_string_unordered_map.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "test_string_unordered_map.hpp" - -#include -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_string_unordered_map { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - using Map = std::unordered_map>; - Map homer; - homer.insert( - std::make_pair("firstName", std::make_unique("Homer"))); - homer.insert( - std::make_pair("lastName", std::make_unique("Simpson"))); - - // Unordered maps are unpredictable. We therefore only make sure that this - // compiles. - const auto json_string = rfl::flexbuf::write(homer); - const auto homer2 = rfl::flexbuf::read(json_string); - std::cout << "OK" << std::endl << std::endl; -} -} // namespace test_string_unordered_map diff --git a/tests/flexbuffers/test_string_unordered_map.hpp b/tests/flexbuffers/test_string_unordered_map.hpp deleted file mode 100644 index 268057a3..00000000 --- a/tests/flexbuffers/test_string_unordered_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_string_unordered_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_tagged_union.cpp b/tests/flexbuffers/test_tagged_union.cpp index f09d141d..da123f2e 100644 --- a/tests/flexbuffers/test_tagged_union.cpp +++ b/tests/flexbuffers/test_tagged_union.cpp @@ -1,9 +1,6 @@ -#include "test_tagged_union.hpp" - #include #include #include -#include #include #include #include @@ -25,13 +22,10 @@ struct Square { double width; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; +using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; +TEST(flexbuf, test_tagged_union) { const Shapes r = Rectangle{.height = 10, .width = 5}; - write_and_read(r); } } // namespace test_tagged_union diff --git a/tests/flexbuffers/test_tagged_union.hpp b/tests/flexbuffers/test_tagged_union.hpp deleted file mode 100644 index 5d522ff9..00000000 --- a/tests/flexbuffers/test_tagged_union.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_tagged_union{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_timestamp.cpp b/tests/flexbuffers/test_timestamp.cpp new file mode 100644 index 00000000..1c1ce052 --- /dev/null +++ b/tests/flexbuffers/test_timestamp.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_timestamp { + +using TS = rfl::Timestamp<"%Y-%m-%d">; + +struct Person { + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + TS birthday; +}; + +TEST(flexbuf, test_timestamp) { + const auto result = TS::from_string("nonsense"); + + if (result) { + std::cout << "Failed: Expected an error, but got none." << std::endl; + return; + } + + const auto bart = Person{.first_name = "Bart", .birthday = "1987-04-19"}; + + write_and_read(bart); +} +} // namespace test_timestamp diff --git a/tests/flexbuffers/test_unique_ptr.cpp b/tests/flexbuffers/test_unique_ptr.cpp index c093a161..5adc14e9 100644 --- a/tests/flexbuffers/test_unique_ptr.cpp +++ b/tests/flexbuffers/test_unique_ptr.cpp @@ -1,9 +1,6 @@ -#include "test_unique_ptr.hpp" - #include #include #include -#include #include #include #include @@ -13,15 +10,12 @@ namespace test_unique_ptr { struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> children = - rfl::default_value; + rfl::Rename<"firstName", std::string> first_name; + rfl::Rename<"lastName", std::string> last_name = "Simpson"; + std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_unique_ptr) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/flexbuffers/test_unique_ptr.hpp b/tests/flexbuffers/test_unique_ptr.hpp deleted file mode 100644 index 428ea2a2..00000000 --- a/tests/flexbuffers/test_unique_ptr.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_unique_ptr2.cpp b/tests/flexbuffers/test_unique_ptr2.cpp index dd02f9b0..4a5b76f7 100644 --- a/tests/flexbuffers/test_unique_ptr2.cpp +++ b/tests/flexbuffers/test_unique_ptr2.cpp @@ -1,9 +1,6 @@ -#include "test_unique_ptr2.hpp" - #include #include #include -#include #include #include #include @@ -14,13 +11,15 @@ namespace test_unique_ptr2 { struct DecisionTree { struct Leaf { - rfl::Field<"value", double> value; + using Tag = rfl::Literal<"Leaf">; + double value; }; struct Node { - rfl::Field<"criticalValue", double> critical_value; - rfl::Field<"left", std::unique_ptr> lesser; - rfl::Field<"right", std::unique_ptr> greater; + using Tag = rfl::Literal<"Node">; + rfl::Rename<"criticalValue", double> critical_value; + std::unique_ptr lesser; + std::unique_ptr greater; }; using LeafOrNode = rfl::TaggedUnion<"type", Leaf, Node>; @@ -28,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(flexbuf, test_unique_ptr2) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/flexbuffers/test_unique_ptr2.hpp b/tests/flexbuffers/test_unique_ptr2.hpp deleted file mode 100644 index 74adc170..00000000 --- a/tests/flexbuffers/test_unique_ptr2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr2{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_unordered_map.cpp b/tests/flexbuffers/test_unordered_map.cpp deleted file mode 100644 index f063937a..00000000 --- a/tests/flexbuffers/test_unordered_map.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "test_unordered_map.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_unordered_map { - -struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - auto children = std::make_unique>(); - children->insert(std::make_pair(1, Person{.first_name = "Bart"})); - children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); - children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); - - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; - - // Unordered maps are unpredictable. We therefore only make sure that this - // compiles. - const auto json_string = rfl::flexbuf::write(homer); - const auto homer2 = rfl::flexbuf::read(json_string); - std::cout << "OK" << std::endl << std::endl; -} -} // namespace test_unordered_map diff --git a/tests/flexbuffers/test_unordered_map.hpp b/tests/flexbuffers/test_unordered_map.hpp deleted file mode 100644 index 9b059a96..00000000 --- a/tests/flexbuffers/test_unordered_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unordered_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_unordered_multimap.cpp b/tests/flexbuffers/test_unordered_multimap.cpp deleted file mode 100644 index d304b26e..00000000 --- a/tests/flexbuffers/test_unordered_multimap.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "test_unordered_multimap.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_unordered_multimap { - -struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - auto children = std::make_unique>(); - children->insert(std::make_pair(1, Person{.first_name = "Bart"})); - children->insert(std::make_pair(2, Person{.first_name = "Lisa"})); - children->insert(std::make_pair(3, Person{.first_name = "Maggie"})); - - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; - - // Unordered maps are unpredictable. We therefore only make sure that this - // compiles. - const auto json_string = rfl::flexbuf::write(homer); - const auto homer2 = rfl::flexbuf::read(json_string); - std::cout << "OK" << std::endl << std::endl; -} -} // namespace test_unordered_multimap diff --git a/tests/flexbuffers/test_unordered_multimap.hpp b/tests/flexbuffers/test_unordered_multimap.hpp deleted file mode 100644 index 0f36f705..00000000 --- a/tests/flexbuffers/test_unordered_multimap.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unordered_multimap{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_unordered_multiset.cpp b/tests/flexbuffers/test_unordered_multiset.cpp deleted file mode 100644 index c72e2bc5..00000000 --- a/tests/flexbuffers/test_unordered_multiset.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "test_unordered_multiset.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_unordered_multiset { - -struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - auto children = std::make_unique>( - std::unordered_multiset({"Bart", "Lisa", "Maggie"})); - - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; - - // Unordered multisets are unpredictable. We therefore only make sure that - // this compiles. - const auto json_string = rfl::flexbuf::write(homer); - const auto homer2 = rfl::flexbuf::read(json_string); - std::cout << "OK" << std::endl << std::endl; -} -} // namespace test_unordered_multiset diff --git a/tests/flexbuffers/test_unordered_multiset.hpp b/tests/flexbuffers/test_unordered_multiset.hpp deleted file mode 100644 index 491ff7ba..00000000 --- a/tests/flexbuffers/test_unordered_multiset.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unordered_multiset{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_unordered_set.cpp b/tests/flexbuffers/test_unordered_set.cpp deleted file mode 100644 index 1d9bbbf3..00000000 --- a/tests/flexbuffers/test_unordered_set.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "test_unordered_set.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_unordered_set { - -struct Person { - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name = "Simpson"; - rfl::Field<"children", std::unique_ptr>> - children = rfl::default_value; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - auto children = std::make_unique>( - std::unordered_set({"Bart", "Lisa", "Maggie"})); - - const auto homer = - Person{.first_name = "Homer", .children = std::move(children)}; - - // Unordered sets are unpredictable. We therefore only make sure that this - // compiles. - const auto json_string = rfl::flexbuf::write(homer); - const auto homer2 = rfl::flexbuf::read(json_string); - std::cout << "OK" << std::endl << std::endl; -} -} // namespace test_unordered_set diff --git a/tests/flexbuffers/test_unordered_set.hpp b/tests/flexbuffers/test_unordered_set.hpp deleted file mode 100644 index be2b257f..00000000 --- a/tests/flexbuffers/test_unordered_set.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unordered_set{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_variant.cpp b/tests/flexbuffers/test_variant.cpp index 2861a3ab..8adc8d80 100644 --- a/tests/flexbuffers/test_variant.cpp +++ b/tests/flexbuffers/test_variant.cpp @@ -1,9 +1,6 @@ -#include "test_variant.hpp" - #include #include #include -#include #include #include #include @@ -13,23 +10,21 @@ namespace test_variant { struct Circle { - rfl::Field<"radius", double> radius; + double radius; }; struct Rectangle { - rfl::Field<"height", double> height; - rfl::Field<"width", double> width; + double height; + double width; }; struct Square { - rfl::Field<"width", double> width; + double width; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - using Shapes = std::variant>; +using Shapes = std::variant>; +TEST(flexbuf, test_variant) { const Shapes r = Rectangle{.height = 10, .width = 5}; write_and_read(r); diff --git a/tests/flexbuffers/test_variant.hpp b/tests/flexbuffers/test_variant.hpp deleted file mode 100644 index 0e58ce71..00000000 --- a/tests/flexbuffers/test_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/flexbuffers/test_wstring.cpp b/tests/flexbuffers/test_wstring.cpp index ba6202c0..e0e1dc1f 100644 --- a/tests/flexbuffers/test_wstring.cpp +++ b/tests/flexbuffers/test_wstring.cpp @@ -1,5 +1,3 @@ -#include "test_wstring.hpp" - #include #include #include @@ -9,17 +7,15 @@ #include "write_and_read.hpp" -struct Test { +struct TestStruct { std::string theNormalString; std::wstring theWiderString; }; namespace test_wstring { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const Test test = Test{.theNormalString = "The normal string", - .theWiderString = L"The wider string"}; +TEST(flexbuf, test_wstring) { + const auto test = TestStruct{.theNormalString = "The normal string", + .theWiderString = L"The wider string"}; write_and_read(test); } diff --git a/tests/flexbuffers/test_wstring.hpp b/tests/flexbuffers/test_wstring.hpp deleted file mode 100644 index 0f93e784..00000000 --- a/tests/flexbuffers/test_wstring.hpp +++ /dev/null @@ -1,3 +0,0 @@ -namespace test_wstring { - void test(); -} diff --git a/tests/flexbuffers/tests.cpp b/tests/flexbuffers/tests.cpp deleted file mode 100644 index aab6d5a7..00000000 --- a/tests/flexbuffers/tests.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "test_all_of.hpp" -#include "test_anonymous_fields.hpp" -#include "test_box.hpp" -#include "test_custom_class1.hpp" -#include "test_custom_class2.hpp" -#include "test_custom_class3.hpp" -#include "test_custom_constructor.hpp" -#include "test_deque.hpp" -#include "test_field_variant.hpp" -#include "test_flatten_anonymous.hpp" -#include "test_forward_list.hpp" -#include "test_list.hpp" -#include "test_literal.hpp" -#include "test_map.hpp" -#include "test_monster_example1.hpp" -#include "test_monster_example2.hpp" -#include "test_multimap.hpp" -#include "test_multiset.hpp" -#include "test_optional_fields.hpp" -#include "test_readme_example.hpp" -#include "test_ref.hpp" -#include "test_save_load.hpp" -#include "test_set.hpp" -#include "test_string_map.hpp" -#include "test_string_unordered_map.hpp" -#include "test_tagged_union.hpp" -#include "test_unique_ptr.hpp" -#include "test_unique_ptr2.hpp" -#include "test_unordered_map.hpp" -#include "test_unordered_multimap.hpp" -#include "test_unordered_multiset.hpp" -#include "test_unordered_set.hpp" -#include "test_variant.hpp" -#include "test_wstring.hpp" - -int main() { - test_readme_example::test(); - test_monster_example1::test(); - test_monster_example2::test(); - test_anonymous_fields::test(); - test_flatten_anonymous::test(); - test_optional_fields::test(); - test_unique_ptr::test(); - test_unique_ptr2::test(); - test_literal::test(); - test_variant::test(); - test_field_variant::test(); - test_tagged_union::test(); - test_custom_class1::test(); - test_custom_class2::test(); - test_custom_class3::test(); - test_box::test(); - test_ref::test(); - - test_deque::test(); - test_forward_list::test(); - test_list::test(); - test_map::test(); - test_multimap::test(); - test_multiset::test(); - test_set::test(); - test_string_map::test(); - test_string_unordered_map::test(); - test_unordered_map::test(); - test_unordered_multimap::test(); - test_unordered_multiset::test(); - test_unordered_set::test(); - - test_custom_constructor::test(); - - test_all_of::test(); - - test_save_load::test(); - test_wstring::test(); - - return 0; -} diff --git a/tests/flexbuffers/write_and_read.hpp b/tests/flexbuffers/write_and_read.hpp index 8bf426f3..a7f6d9ac 100644 --- a/tests/flexbuffers/write_and_read.hpp +++ b/tests/flexbuffers/write_and_read.hpp @@ -1,39 +1,20 @@ #ifndef WRITE_AND_READ_ #define WRITE_AND_READ_ +#include + #include #include #include template void write_and_read(const T& _struct) { - const auto bytes1 = rfl::flexbuf::write(_struct); - - const auto res = rfl::flexbuf::read(bytes1); - - if (!res) { - std::cout << "Test failed on read. Error: " << res.error().value().what() - << std::endl - << std::endl; - return; - } - - const auto bytes2 = rfl::flexbuf::write(res.value()); - - if (bytes1.size() != bytes2.size()) { - std::cout << "Test failed on write. Number of bytes was different." - << std::endl - << std::endl; - return; - } - - if (bytes1 != bytes2) { - std::cout << "Test failed on write. Content was not identical." << std::endl - << std::endl; - return; - } - - std::cout << "OK" << std::endl << std::endl; + const auto serialized1 = rfl::flexbuf::write(_struct); + const auto res = rfl::flexbuf::read(serialized1); + EXPECT_TRUE(res && true) << "Test failed on read. Error: " + << res.error().value().what(); + const auto serialized2 = rfl::flexbuf::write(res.value()); + EXPECT_EQ(serialized1, serialized2); } #endif diff --git a/tests/toml/CMakeLists.txt b/tests/toml/CMakeLists.txt index c80c52fa..31763819 100644 --- a/tests/toml/CMakeLists.txt +++ b/tests/toml/CMakeLists.txt @@ -1,9 +1,18 @@ project(reflect-cpp-toml-tests) -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp") -add_executable(reflect-cpp-toml-tests ${SOURCES}) +add_executable( + reflect-cpp-toml-tests + ${SOURCES} + "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/src/gtest_main.cc" +) target_include_directories(reflect-cpp-toml-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") -target_link_libraries(reflect-cpp-toml-tests PRIVATE reflectcpp) +target_link_libraries( + reflect-cpp-toml-tests + PRIVATE + reflectcpp + "${REFLECT_CPP_GTEST_LIB}" +) diff --git a/tests/toml/test_array.cpp b/tests/toml/test_array.cpp index f3f10206..421f2004 100644 --- a/tests/toml/test_array.cpp +++ b/tests/toml/test_array.cpp @@ -1,5 +1,3 @@ -#include "test_array.hpp" - #include #include #include @@ -8,7 +6,7 @@ #include // Make sure things still compile when -// rfl.hpp is included after rfl/yaml.hpp. +// rfl.hpp is included after rfl/cbor.hpp. #include #include "write_and_read.hpp" @@ -21,9 +19,7 @@ struct Person { std::unique_ptr> children = nullptr; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_array) { auto bart = Person{.first_name = "Bart"}; auto lisa = Person{.first_name = "Lisa"}; diff --git a/tests/toml/test_array.hpp b/tests/toml/test_array.hpp deleted file mode 100644 index 502c3388..00000000 --- a/tests/toml/test_array.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_array{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_box.cpp b/tests/toml/test_box.cpp index 04d88641..b9a57c67 100644 --- a/tests/toml/test_box.cpp +++ b/tests/toml/test_box.cpp @@ -1,9 +1,6 @@ -#include "test_box.hpp" - #include #include #include -#include #include #include #include @@ -30,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_box) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/toml/test_box.hpp b/tests/toml/test_box.hpp deleted file mode 100644 index a564b9e1..00000000 --- a/tests/toml/test_box.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_box{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_custom_class1.cpp b/tests/toml/test_custom_class1.cpp index 35f4a1da..1a020c27 100644 --- a/tests/toml/test_custom_class1.cpp +++ b/tests/toml/test_custom_class1.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class1.hpp" - #include #include #include -#include #include #include #include @@ -32,9 +29,7 @@ struct Person { PersonImpl impl; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_custom_class1) { const auto bart = Person("Bart"); write_and_read(bart); diff --git a/tests/toml/test_custom_class1.hpp b/tests/toml/test_custom_class1.hpp deleted file mode 100644 index eafe6cd0..00000000 --- a/tests/toml/test_custom_class1.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class1{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_custom_class3.cpp b/tests/toml/test_custom_class3.cpp index 2ea105e4..c5f70a25 100644 --- a/tests/toml/test_custom_class3.cpp +++ b/tests/toml/test_custom_class3.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class3.hpp" - #include #include #include -#include #include #include #include @@ -57,9 +54,7 @@ struct Parser namespace test_custom_class3 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_custom_class3) { const auto bart = Person("Bart", "Simpson", 10); write_and_read(bart); diff --git a/tests/toml/test_custom_class3.hpp b/tests/toml/test_custom_class3.hpp deleted file mode 100644 index 9a6fdab4..00000000 --- a/tests/toml/test_custom_class3.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class3{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_custom_class4.cpp b/tests/toml/test_custom_class4.cpp index e2d79a94..fc3c009e 100644 --- a/tests/toml/test_custom_class4.cpp +++ b/tests/toml/test_custom_class4.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class4.hpp" - #include #include #include -#include #include #include #include @@ -58,9 +55,7 @@ struct Parser namespace test_custom_class4 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_custom_class4) { const auto bart = test_custom_class4::Person( "Bart", rfl::make_box("Simpson"), 10); diff --git a/tests/toml/test_custom_class4.hpp b/tests/toml/test_custom_class4.hpp deleted file mode 100644 index 2d3b151a..00000000 --- a/tests/toml/test_custom_class4.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class4{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_custom_constructor.cpp b/tests/toml/test_custom_constructor.cpp deleted file mode 100644 index 03123d2a..00000000 --- a/tests/toml/test_custom_constructor.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "test_custom_constructor.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_custom_constructor { - -struct Person { - static rfl::Result from_toml_obj( - typename rfl::toml::Reader::InputVarType _obj) { - /// This only exists for the purpose of the test. - const auto change_first_name = [](auto&& _person) { - return rfl::replace(std::move(_person), - rfl::Field<"firstName", std::string>("Bart")); - }; - const auto from_nt = [](auto&& _nt) { - return rfl::from_named_tuple(std::move(_nt)); - }; - return rfl::toml::read>(_obj) - .transform(from_nt) - .transform(change_first_name); - } - - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name; - rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const auto res = rfl::toml::read( - R"(firstName = 'Homer' -lastName = 'Simpson' -birthday = '1987-04-19')"); - - if (!res) { - std::cout << "Test failed on read. Error: " << res.error().value().what() - << std::endl; - return; - } - - if (res.value().first_name() != "Bart") { - std::cout << "Expected 'Bart', got '" << res.value().first_name() << "'" - << std::endl - << std::endl; - } else { - std::cout << "OK" << std::endl << std::endl; - } -} -} // namespace test_custom_constructor diff --git a/tests/toml/test_custom_constructor.hpp b/tests/toml/test_custom_constructor.hpp deleted file mode 100644 index d3b5b950..00000000 --- a/tests/toml/test_custom_constructor.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_constructor { -void test(); -} - diff --git a/tests/toml/test_default_values.cpp b/tests/toml/test_default_values.cpp index f6af2352..e5deb0af 100644 --- a/tests/toml/test_default_values.cpp +++ b/tests/toml/test_default_values.cpp @@ -1,5 +1,3 @@ -#include "test_default_values.hpp" - #include #include #include @@ -17,9 +15,7 @@ struct Person { std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_default_values) { const auto bart = Person{.first_name = "Bart"}; const auto lisa = Person{.first_name = "Lisa"}; const auto maggie = Person{.first_name = "Maggie"}; diff --git a/tests/toml/test_default_values.hpp b/tests/toml/test_default_values.hpp deleted file mode 100644 index c8f8360e..00000000 --- a/tests/toml/test_default_values.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_default_values{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_deque.cpp b/tests/toml/test_deque.cpp index 6dfa5803..d23c1e97 100644 --- a/tests/toml/test_deque.cpp +++ b/tests/toml/test_deque.cpp @@ -1,5 +1,3 @@ -#include "test_deque.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_default_values) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/toml/test_deque.hpp b/tests/toml/test_deque.hpp deleted file mode 100644 index 6781e880..00000000 --- a/tests/toml/test_deque.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_deque{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_enum.cpp b/tests/toml/test_enum.cpp index d4d56a8b..e13df83f 100644 --- a/tests/toml/test_enum.cpp +++ b/tests/toml/test_enum.cpp @@ -1,5 +1,3 @@ -#include "test_enum.hpp" - #include #include #include @@ -18,9 +16,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::green}; write_and_read(circle); diff --git a/tests/toml/test_enum.hpp b/tests/toml/test_enum.hpp deleted file mode 100644 index 2e2e0b3d..00000000 --- a/tests/toml/test_enum.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_enum { -void test(); -} - diff --git a/tests/toml/test_field_variant.cpp b/tests/toml/test_field_variant.cpp index 8b17665f..e96360bf 100644 --- a/tests/toml/test_field_variant.cpp +++ b/tests/toml/test_field_variant.cpp @@ -1,5 +1,3 @@ -#include "test_field_variant.hpp" - #include #include #include @@ -28,9 +26,7 @@ using Shapes = rfl::Variant, rfl::Field<"rectangle", Rectangle>, rfl::Field<"square", rfl::Box>>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_field_variant) { const Shapes r = rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); diff --git a/tests/toml/test_field_variant.hpp b/tests/toml/test_field_variant.hpp deleted file mode 100644 index ba93e732..00000000 --- a/tests/toml/test_field_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_field_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_flag_enum.cpp b/tests/toml/test_flag_enum.cpp index 1d3f76af..c0d5e8d2 100644 --- a/tests/toml/test_flag_enum.cpp +++ b/tests/toml/test_flag_enum.cpp @@ -5,7 +5,6 @@ #include #include -#include "test_enum.hpp" #include "write_and_read.hpp" namespace test_flag_enum { @@ -27,9 +26,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_flag_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::blue | Color::orange}; diff --git a/tests/toml/test_flag_enum.hpp b/tests/toml/test_flag_enum.hpp deleted file mode 100644 index 2f4dc7a0..00000000 --- a/tests/toml/test_flag_enum.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flag_enum { -void test(); -} - diff --git a/tests/toml/test_flag_enum_with_int.cpp b/tests/toml/test_flag_enum_with_int.cpp index 4c7deefe..8a4fad20 100644 --- a/tests/toml/test_flag_enum_with_int.cpp +++ b/tests/toml/test_flag_enum_with_int.cpp @@ -5,7 +5,6 @@ #include #include -#include "test_enum.hpp" #include "write_and_read.hpp" namespace test_flag_enum_with_int { @@ -27,9 +26,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_flag_enum_with_int) { const auto circle = Circle{.radius = 2.0, .color = static_cast(10000)}; write_and_read(circle); diff --git a/tests/toml/test_flag_enum_with_int.hpp b/tests/toml/test_flag_enum_with_int.hpp deleted file mode 100644 index a7512b60..00000000 --- a/tests/toml/test_flag_enum_with_int.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flag_enum_with_int { -void test(); -} - diff --git a/tests/toml/test_flatten.cpp b/tests/toml/test_flatten.cpp index c7f1d9be..29a2c1d5 100644 --- a/tests/toml/test_flatten.cpp +++ b/tests/toml/test_flatten.cpp @@ -1,5 +1,3 @@ -#include "test_flatten.hpp" - #include #include #include @@ -23,9 +21,7 @@ struct Employee { rfl::Field<"salary", float> salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_flatten) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), diff --git a/tests/toml/test_flatten.hpp b/tests/toml/test_flatten.hpp deleted file mode 100644 index 24d60e11..00000000 --- a/tests/toml/test_flatten.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_flatten_anonymous.cpp b/tests/toml/test_flatten_anonymous.cpp index 05e61464..4b698c78 100644 --- a/tests/toml/test_flatten_anonymous.cpp +++ b/tests/toml/test_flatten_anonymous.cpp @@ -1,5 +1,3 @@ -#include "test_flatten_anonymous.hpp" - #include #include #include @@ -23,9 +21,7 @@ struct Employee { float salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_flatten_anonymous) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), diff --git a/tests/toml/test_flatten_anonymous.hpp b/tests/toml/test_flatten_anonymous.hpp deleted file mode 100644 index 7ffa2785..00000000 --- a/tests/toml/test_flatten_anonymous.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten_anonymous{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_forward_list.cpp b/tests/toml/test_forward_list.cpp index dd8d9e56..da27ae84 100644 --- a/tests/toml/test_forward_list.cpp +++ b/tests/toml/test_forward_list.cpp @@ -1,5 +1,3 @@ -#include "test_forward_list.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_forward_list) { auto children = std::make_unique>(); children->emplace_front(Person{.first_name = "Maggie"}); children->emplace_front(Person{.first_name = "Lisa"}); diff --git a/tests/toml/test_forward_list.hpp b/tests/toml/test_forward_list.hpp deleted file mode 100644 index 9784a0c4..00000000 --- a/tests/toml/test_forward_list.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_forward_list{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_literal.cpp b/tests/toml/test_literal.cpp index 00578178..6d447c36 100644 --- a/tests/toml/test_literal.cpp +++ b/tests/toml/test_literal.cpp @@ -1,5 +1,3 @@ -#include "test_literal.hpp" - #include #include #include @@ -20,9 +18,7 @@ struct Person { std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_literal) { const auto bart = Person{.first_name = FirstName::make<"Bart">()}; write_and_read(bart); diff --git a/tests/toml/test_literal.hpp b/tests/toml/test_literal.hpp deleted file mode 100644 index ccd500ef..00000000 --- a/tests/toml/test_literal.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_literal_map.cpp b/tests/toml/test_literal_map.cpp index 9bbebafb..b07902f3 100644 --- a/tests/toml/test_literal_map.cpp +++ b/tests/toml/test_literal_map.cpp @@ -1,5 +1,3 @@ -#include "test_literal_map.hpp" - #include #include #include @@ -14,9 +12,7 @@ namespace test_literal_map { using FieldName = rfl::Literal<"firstName", "lastName">; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_literal_map) { std::map> homer; homer.insert(std::make_pair(FieldName::make<"firstName">(), std::make_unique("Homer"))); diff --git a/tests/toml/test_literal_map.hpp b/tests/toml/test_literal_map.hpp deleted file mode 100644 index cc05d0c8..00000000 --- a/tests/toml/test_literal_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_map.cpp b/tests/toml/test_map.cpp index e37ce564..774ccc61 100644 --- a/tests/toml/test_map.cpp +++ b/tests/toml/test_map.cpp @@ -1,5 +1,3 @@ -#include "test_map.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::map children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_map) { auto children = std::map(); children.insert(std::make_pair("child1", Person{.first_name = "Bart"})); children.insert(std::make_pair("child2", Person{.first_name = "Lisa"})); diff --git a/tests/toml/test_map.hpp b/tests/toml/test_map.hpp deleted file mode 100644 index 9ae49728..00000000 --- a/tests/toml/test_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_map_with_key_validation.cpp b/tests/toml/test_map_with_key_validation.cpp index e758219d..0c27f830 100644 --- a/tests/toml/test_map_with_key_validation.cpp +++ b/tests/toml/test_map_with_key_validation.cpp @@ -1,5 +1,3 @@ -#include "test_map_with_key_validation.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_map_with_key_validation) { auto children = std::make_unique>(); children->insert(std::make_pair("Bart", Person{.first_name = "Bart"})); diff --git a/tests/toml/test_map_with_key_validation.hpp b/tests/toml/test_map_with_key_validation.hpp deleted file mode 100644 index 1372f926..00000000 --- a/tests/toml/test_map_with_key_validation.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map_with_key_validation{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_monster_example.cpp b/tests/toml/test_monster_example.cpp index 052d8390..91446f7f 100644 --- a/tests/toml/test_monster_example.cpp +++ b/tests/toml/test_monster_example.cpp @@ -1,5 +1,3 @@ -#include "test_monster_example.hpp" - #include #include #include @@ -38,9 +36,7 @@ struct Monster { std::vector path; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_monster_example) { const auto sword = Weapon{.name = "Sword", .damage = 3}; const auto axe = Weapon{.name = "Axe", .damage = 5}; diff --git a/tests/toml/test_monster_example.hpp b/tests/toml/test_monster_example.hpp deleted file mode 100644 index f2d959fc..00000000 --- a/tests/toml/test_monster_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_monster_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_readme_example.cpp b/tests/toml/test_readme_example.cpp index 4e6f8ee0..970b8411 100644 --- a/tests/toml/test_readme_example.cpp +++ b/tests/toml/test_readme_example.cpp @@ -1,5 +1,3 @@ -#include "test_readme_example.hpp" - #include #include #include @@ -22,9 +20,7 @@ struct Person { std::vector child; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_readme_example) { const auto bart = Person{.first_name = "Bart", .birthday = "1987-04-19", .age = 10, diff --git a/tests/toml/test_readme_example.hpp b/tests/toml/test_readme_example.hpp deleted file mode 100644 index 68c6cf81..00000000 --- a/tests/toml/test_readme_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_readme_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_readme_example2.cpp b/tests/toml/test_readme_example2.cpp index a2d212a4..7ad06cad 100644 --- a/tests/toml/test_readme_example2.cpp +++ b/tests/toml/test_readme_example2.cpp @@ -4,7 +4,6 @@ #include #include -#include "test_readme_example.hpp" #include "write_and_read.hpp" namespace test_readme_example2 { @@ -15,9 +14,7 @@ struct Person { int age; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_readme_example2) { const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; diff --git a/tests/toml/test_readme_example2.hpp b/tests/toml/test_readme_example2.hpp deleted file mode 100644 index 5c6b011c..00000000 --- a/tests/toml/test_readme_example2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_readme_example2 { -void test(); -} - diff --git a/tests/toml/test_ref.cpp b/tests/toml/test_ref.cpp index 32a32e6c..ebb254d5 100644 --- a/tests/toml/test_ref.cpp +++ b/tests/toml/test_ref.cpp @@ -1,5 +1,3 @@ -#include "test_ref.hpp" - #include #include #include @@ -29,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_ref) { const auto leaf1 = DecisionTree::Leaf{.value = 3.0}; const auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/toml/test_ref.hpp b/tests/toml/test_ref.hpp deleted file mode 100644 index d289ba09..00000000 --- a/tests/toml/test_ref.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_ref{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_save_load.cpp b/tests/toml/test_save_load.cpp index fb14c76f..71faf284 100644 --- a/tests/toml/test_save_load.cpp +++ b/tests/toml/test_save_load.cpp @@ -1,5 +1,3 @@ -#include "test_save_load.hpp" - #include #include #include @@ -8,6 +6,8 @@ #include #include +#include + namespace test_save_load { using Age = rfl::Validator children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_save_load) { const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19", @@ -59,12 +57,6 @@ void test() { const auto string1 = rfl::toml::write(homer1); const auto string2 = rfl::toml::write(homer2); - if (string1 != string2) { - std::cout << "Test failed. Content was not identical." << std::endl - << std::endl; - return; - } - - std::cout << "OK" << std::endl << std::endl; + EXPECT_EQ(string1, string2); } } // namespace test_save_load diff --git a/tests/toml/test_save_load.hpp b/tests/toml/test_save_load.hpp deleted file mode 100644 index 7bf10359..00000000 --- a/tests/toml/test_save_load.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_save_load { -void test(); -} - diff --git a/tests/toml/test_set.cpp b/tests/toml/test_set.cpp index 9f2516ce..6a2f6ba3 100644 --- a/tests/toml/test_set.cpp +++ b/tests/toml/test_set.cpp @@ -1,5 +1,3 @@ -#include "test_set.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_set) { auto children = std::make_unique>( std::set({"Bart", "Lisa", "Maggie"})); diff --git a/tests/toml/test_set.hpp b/tests/toml/test_set.hpp deleted file mode 100644 index 142a663b..00000000 --- a/tests/toml/test_set.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_set{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_size.cpp b/tests/toml/test_size.cpp index c37b9bd8..19daf958 100644 --- a/tests/toml/test_size.cpp +++ b/tests/toml/test_size.cpp @@ -1,5 +1,3 @@ -#include "test_size.hpp" - #include #include #include @@ -19,9 +17,7 @@ struct Person { children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_size) { const auto bart = Person{ .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"}; diff --git a/tests/toml/test_size.hpp b/tests/toml/test_size.hpp deleted file mode 100644 index be330df0..00000000 --- a/tests/toml/test_size.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_size{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_string_map.cpp b/tests/toml/test_string_map.cpp index cb4fb903..cffd9293 100644 --- a/tests/toml/test_string_map.cpp +++ b/tests/toml/test_string_map.cpp @@ -1,5 +1,3 @@ -#include "test_string_map.hpp" - #include #include #include @@ -10,9 +8,7 @@ #include "write_and_read.hpp" namespace test_string_map { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_string_map) { std::map> homer; homer.insert( std::make_pair("firstName", std::make_unique("Homer"))); diff --git a/tests/toml/test_string_map.hpp b/tests/toml/test_string_map.hpp deleted file mode 100644 index 94cb975a..00000000 --- a/tests/toml/test_string_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_string_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_tagged_union.cpp b/tests/toml/test_tagged_union.cpp index a9dd1abc..944aeaae 100644 --- a/tests/toml/test_tagged_union.cpp +++ b/tests/toml/test_tagged_union.cpp @@ -1,5 +1,3 @@ -#include "test_tagged_union.hpp" - #include #include #include @@ -26,11 +24,8 @@ struct Square { using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_tagged_union) { const Shapes r = Rectangle{.height = 10, .width = 5}; - write_and_read(r); } } // namespace test_tagged_union diff --git a/tests/toml/test_tagged_union.hpp b/tests/toml/test_tagged_union.hpp deleted file mode 100644 index 5d522ff9..00000000 --- a/tests/toml/test_tagged_union.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_tagged_union{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_timestamp.cpp b/tests/toml/test_timestamp.cpp index 8af261d1..0eb12367 100644 --- a/tests/toml/test_timestamp.cpp +++ b/tests/toml/test_timestamp.cpp @@ -1,5 +1,3 @@ -#include "test_timestamp.hpp" - #include #include #include @@ -19,9 +17,7 @@ struct Person { TS birthday; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_timestamp) { const auto result = TS::from_string("nonsense"); if (result) { diff --git a/tests/toml/test_timestamp.hpp b/tests/toml/test_timestamp.hpp deleted file mode 100644 index 891d89b9..00000000 --- a/tests/toml/test_timestamp.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_timestamp{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_unique_ptr.cpp b/tests/toml/test_unique_ptr.cpp index b1833533..ae2990ed 100644 --- a/tests/toml/test_unique_ptr.cpp +++ b/tests/toml/test_unique_ptr.cpp @@ -1,5 +1,3 @@ -#include "test_unique_ptr.hpp" - #include #include #include @@ -17,9 +15,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_unique_ptr) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/toml/test_unique_ptr.hpp b/tests/toml/test_unique_ptr.hpp deleted file mode 100644 index 428ea2a2..00000000 --- a/tests/toml/test_unique_ptr.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_unique_ptr2.cpp b/tests/toml/test_unique_ptr2.cpp index e3007267..ac32675e 100644 --- a/tests/toml/test_unique_ptr2.cpp +++ b/tests/toml/test_unique_ptr2.cpp @@ -1,5 +1,3 @@ -#include "test_unique_ptr2.hpp" - #include #include #include @@ -29,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_unique_ptr2) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/toml/test_unique_ptr2.hpp b/tests/toml/test_unique_ptr2.hpp deleted file mode 100644 index 74adc170..00000000 --- a/tests/toml/test_unique_ptr2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr2{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_variant.cpp b/tests/toml/test_variant.cpp index cc3d6cbe..087880ae 100644 --- a/tests/toml/test_variant.cpp +++ b/tests/toml/test_variant.cpp @@ -1,5 +1,3 @@ -#include "test_variant.hpp" - #include #include #include @@ -26,9 +24,7 @@ struct Square { using Shapes = std::variant>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(toml, test_variant) { const Shapes r = Rectangle{.height = 10, .width = 5}; write_and_read(r); diff --git a/tests/toml/test_variant.hpp b/tests/toml/test_variant.hpp deleted file mode 100644 index 0e58ce71..00000000 --- a/tests/toml/test_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/toml/test_wstring.cpp b/tests/toml/test_wstring.cpp index ba6202c0..8c0c4f9a 100644 --- a/tests/toml/test_wstring.cpp +++ b/tests/toml/test_wstring.cpp @@ -1,5 +1,3 @@ -#include "test_wstring.hpp" - #include #include #include @@ -9,17 +7,15 @@ #include "write_and_read.hpp" -struct Test { +struct TestStruct { std::string theNormalString; std::wstring theWiderString; }; namespace test_wstring { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const Test test = Test{.theNormalString = "The normal string", - .theWiderString = L"The wider string"}; +TEST(toml, test_wstring) { + const auto test = TestStruct{.theNormalString = "The normal string", + .theWiderString = L"The wider string"}; write_and_read(test); } diff --git a/tests/toml/test_wstring.hpp b/tests/toml/test_wstring.hpp deleted file mode 100644 index 0f93e784..00000000 --- a/tests/toml/test_wstring.hpp +++ /dev/null @@ -1,3 +0,0 @@ -namespace test_wstring { - void test(); -} diff --git a/tests/toml/tests.cpp b/tests/toml/tests.cpp deleted file mode 100644 index 7a38771d..00000000 --- a/tests/toml/tests.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "test_array.hpp" -#include "test_box.hpp" -#include "test_custom_class1.hpp" -#include "test_custom_class3.hpp" -#include "test_custom_class4.hpp" -#include "test_custom_constructor.hpp" -#include "test_default_values.hpp" -#include "test_deque.hpp" -#include "test_enum.hpp" -#include "test_field_variant.hpp" -#include "test_flag_enum.hpp" -#include "test_flag_enum_with_int.hpp" -#include "test_flatten.hpp" -#include "test_flatten_anonymous.hpp" -#include "test_forward_list.hpp" -#include "test_literal.hpp" -#include "test_literal_map.hpp" -#include "test_map.hpp" -#include "test_map_with_key_validation.hpp" -#include "test_monster_example.hpp" -#include "test_readme_example.hpp" -#include "test_readme_example2.hpp" -#include "test_ref.hpp" -#include "test_save_load.hpp" -#include "test_set.hpp" -#include "test_size.hpp" -#include "test_tagged_union.hpp" -#include "test_timestamp.hpp" -#include "test_unique_ptr.hpp" -#include "test_unique_ptr2.hpp" -#include "test_variant.hpp" -#include "test_wstring.hpp" - -int main() { - test_readme_example::test(); - test_readme_example2::test(); - test_flatten::test(); - test_flatten_anonymous::test(); - test_enum::test(); - test_flag_enum::test(); - test_flag_enum_with_int::test(); - test_map::test(); - test_map_with_key_validation::test(); - test_variant::test(); - test_field_variant::test(); - test_tagged_union::test(); - test_deque::test(); - test_forward_list::test(); - test_literal_map::test(); - test_literal::test(); - test_monster_example::test(); - test_ref::test(); - test_set::test(); - test_size::test(); - test_timestamp::test(); - test_unique_ptr::test(); - test_unique_ptr2::test(); - test_array::test(); - test_box::test(); - test_custom_class1::test(); - test_custom_class3::test(); - test_custom_class4::test(); - test_default_values::test(); - test_custom_constructor::test(); - test_save_load::test(); - test_wstring::test(); - - return 0; -} diff --git a/tests/toml/write_and_read.hpp b/tests/toml/write_and_read.hpp index 8b0d7cac..4c45b5d5 100644 --- a/tests/toml/write_and_read.hpp +++ b/tests/toml/write_and_read.hpp @@ -1,32 +1,20 @@ #ifndef WRITE_AND_READ_ #define WRITE_AND_READ_ +#include + #include #include #include template void write_and_read(const T& _struct) { - const auto toml_string1 = rfl::toml::write(_struct); - const auto res = rfl::toml::read(toml_string1); - if (!res) { - std::cout << "Test failed on read. Error: " << res.error().value().what() - << std::endl - << "Original string: " << toml_string1 << std::endl - << std::endl; - return; - } - const auto toml_string2 = rfl::toml::write(res.value()); - if (toml_string2 != toml_string1) { - std::cout << "Test failed on read. Expected:" << std::endl - << toml_string1 << std::endl - << "Got: " << std::endl - << toml_string2 << std::endl - << std::endl; - return; - } - // std::cout << toml_string1 << std::endl; - std::cout << "OK" << std::endl << std::endl; + const auto serialized1 = rfl::toml::write(_struct); + const auto res = rfl::toml::read(serialized1); + EXPECT_TRUE(res && true) << "Test failed on read. Error: " + << res.error().value().what(); + const auto serialized2 = rfl::toml::write(res.value()); + EXPECT_EQ(serialized1, serialized2); } #endif diff --git a/tests/xml/CMakeLists.txt b/tests/xml/CMakeLists.txt index c22bc116..fca21858 100644 --- a/tests/xml/CMakeLists.txt +++ b/tests/xml/CMakeLists.txt @@ -1,8 +1,18 @@ project(reflect-cpp-xml-tests) -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp") -add_executable(reflect-cpp-xml-tests ${SOURCES}) +add_executable( + reflect-cpp-xml-tests + ${SOURCES} + "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/src/gtest_main.cc" +) -target_link_libraries(reflect-cpp-xml-tests PRIVATE reflectcpp) +target_include_directories(reflect-cpp-xml-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") +target_link_libraries( + reflect-cpp-xml-tests + PRIVATE + reflectcpp + "${REFLECT_CPP_GTEST_LIB}" +) diff --git a/tests/xml/test_array.cpp b/tests/xml/test_array.cpp index bcc21feb..60c0a58b 100644 --- a/tests/xml/test_array.cpp +++ b/tests/xml/test_array.cpp @@ -1,5 +1,3 @@ -#include "test_array.hpp" - #include #include #include @@ -8,7 +6,7 @@ #include // Make sure things still compile when -// rfl.hpp is included after rfl/xml.hpp. +// rfl.hpp is included after rfl/cbor.hpp. #include #include "write_and_read.hpp" @@ -21,9 +19,7 @@ struct Person { std::unique_ptr> children = nullptr; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_array) { auto bart = Person{.first_name = "Bart"}; auto lisa = Person{.first_name = "Lisa"}; diff --git a/tests/xml/test_array.hpp b/tests/xml/test_array.hpp deleted file mode 100644 index 502c3388..00000000 --- a/tests/xml/test_array.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_array{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_attributes.cpp b/tests/xml/test_attributes.cpp deleted file mode 100644 index 9e5e5931..00000000 --- a/tests/xml/test_attributes.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "test_attributes.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_attributes { - -using Age = rfl::Validator, rfl::Maximum<130>>; - -struct Person { - rfl::Rename<"firstName", rfl::Attribute> first_name; - rfl::Rename<"lastName", rfl::Attribute> last_name = "Simpson"; - rfl::Attribute town = "Springfield"; - rfl::Attribute> birthday; - rfl::Attribute age; - rfl::Attribute email; - std::vector child; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const auto bart = Person{.first_name = "Bart", - .birthday = "1987-04-19", - .age = 10, - .email = "bart@simpson.com"}; - - const auto lisa = Person{.first_name = "Lisa", - .birthday = "1987-04-19", - .age = 8, - .email = "lisa@simpson.com"}; - - const auto maggie = Person{.first_name = "Maggie", - .birthday = "1987-04-19", - .age = 0, - .email = "maggie@simpson.com"}; - - const auto homer = Person{.first_name = "Homer", - .birthday = "1987-04-19", - .age = 45, - .email = "homer@simpson.com", - .child = std::vector({bart, lisa, maggie})}; - - write_and_read(homer); -} -} // namespace test_attributes diff --git a/tests/xml/test_attributes.hpp b/tests/xml/test_attributes.hpp deleted file mode 100644 index e77be6af..00000000 --- a/tests/xml/test_attributes.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_attributes { -void test(); -} - diff --git a/tests/xml/test_box.cpp b/tests/xml/test_box.cpp index 04d88641..582c9004 100644 --- a/tests/xml/test_box.cpp +++ b/tests/xml/test_box.cpp @@ -1,9 +1,6 @@ -#include "test_box.hpp" - #include #include #include -#include #include #include #include @@ -30,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_box) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/xml/test_box.hpp b/tests/xml/test_box.hpp deleted file mode 100644 index a564b9e1..00000000 --- a/tests/xml/test_box.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_box{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_custom_class1.cpp b/tests/xml/test_custom_class1.cpp index 35f4a1da..eee793eb 100644 --- a/tests/xml/test_custom_class1.cpp +++ b/tests/xml/test_custom_class1.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class1.hpp" - #include #include #include -#include #include #include #include @@ -32,9 +29,7 @@ struct Person { PersonImpl impl; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_custom_class1) { const auto bart = Person("Bart"); write_and_read(bart); diff --git a/tests/xml/test_custom_class1.hpp b/tests/xml/test_custom_class1.hpp deleted file mode 100644 index eafe6cd0..00000000 --- a/tests/xml/test_custom_class1.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class1{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_custom_class3.cpp b/tests/xml/test_custom_class3.cpp index 2ea105e4..3cbc23f6 100644 --- a/tests/xml/test_custom_class3.cpp +++ b/tests/xml/test_custom_class3.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class3.hpp" - #include #include #include -#include #include #include #include @@ -57,9 +54,7 @@ struct Parser namespace test_custom_class3 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_custom_class3) { const auto bart = Person("Bart", "Simpson", 10); write_and_read(bart); diff --git a/tests/xml/test_custom_class3.hpp b/tests/xml/test_custom_class3.hpp deleted file mode 100644 index 9a6fdab4..00000000 --- a/tests/xml/test_custom_class3.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class3{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_custom_class4.cpp b/tests/xml/test_custom_class4.cpp index e2d79a94..55a5c693 100644 --- a/tests/xml/test_custom_class4.cpp +++ b/tests/xml/test_custom_class4.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class4.hpp" - #include #include #include -#include #include #include #include @@ -58,9 +55,7 @@ struct Parser namespace test_custom_class4 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_custom_class4) { const auto bart = test_custom_class4::Person( "Bart", rfl::make_box("Simpson"), 10); diff --git a/tests/xml/test_custom_class4.hpp b/tests/xml/test_custom_class4.hpp deleted file mode 100644 index 2d3b151a..00000000 --- a/tests/xml/test_custom_class4.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class4{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_default_values.cpp b/tests/xml/test_default_values.cpp index 7613a6e3..d1220cc9 100644 --- a/tests/xml/test_default_values.cpp +++ b/tests/xml/test_default_values.cpp @@ -1,9 +1,6 @@ -#include "test_default_values.hpp" - #include #include #include -#include #include #include #include @@ -18,9 +15,7 @@ struct Person { std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_default_values) { const auto bart = Person{.first_name = "Bart"}; const auto lisa = Person{.first_name = "Lisa"}; const auto maggie = Person{.first_name = "Maggie"}; diff --git a/tests/xml/test_default_values.hpp b/tests/xml/test_default_values.hpp deleted file mode 100644 index c8f8360e..00000000 --- a/tests/xml/test_default_values.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_default_values{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_deque.cpp b/tests/xml/test_deque.cpp index cdcceac0..ede6a93f 100644 --- a/tests/xml/test_deque.cpp +++ b/tests/xml/test_deque.cpp @@ -1,8 +1,5 @@ -#include "test_deque.hpp" - #include #include -#include #include #include #include @@ -17,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_default_values) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/xml/test_deque.hpp b/tests/xml/test_deque.hpp deleted file mode 100644 index 6781e880..00000000 --- a/tests/xml/test_deque.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_deque{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_enum.cpp b/tests/xml/test_enum.cpp index 0095ee19..0634b0eb 100644 --- a/tests/xml/test_enum.cpp +++ b/tests/xml/test_enum.cpp @@ -1,9 +1,6 @@ -#include "test_enum.hpp" - #include #include #include -#include #include #include #include @@ -19,9 +16,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::green}; write_and_read(circle); diff --git a/tests/xml/test_enum.hpp b/tests/xml/test_enum.hpp deleted file mode 100644 index 2e2e0b3d..00000000 --- a/tests/xml/test_enum.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_enum { -void test(); -} - diff --git a/tests/xml/test_field_variant.cpp b/tests/xml/test_field_variant.cpp index 114d000c..cd3adf8e 100644 --- a/tests/xml/test_field_variant.cpp +++ b/tests/xml/test_field_variant.cpp @@ -1,9 +1,6 @@ -#include "test_field_variant.hpp" - #include #include #include -#include #include #include #include @@ -29,12 +26,10 @@ using Shapes = rfl::Variant, rfl::Field<"rectangle", Rectangle>, rfl::Field<"square", rfl::Box>>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_field_variant) { const Shapes r = rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); - write_and_read<"shape">(r); + write_and_read<"root">(r); } } // namespace test_field_variant diff --git a/tests/xml/test_field_variant.hpp b/tests/xml/test_field_variant.hpp deleted file mode 100644 index ba93e732..00000000 --- a/tests/xml/test_field_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_field_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_flag_enum.cpp b/tests/xml/test_flag_enum.cpp index 3846c1fd..d537322d 100644 --- a/tests/xml/test_flag_enum.cpp +++ b/tests/xml/test_flag_enum.cpp @@ -1,12 +1,10 @@ #include #include #include -#include #include #include #include -#include "test_enum.hpp" #include "write_and_read.hpp" namespace test_flag_enum { @@ -28,9 +26,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_flag_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::blue | Color::orange}; diff --git a/tests/xml/test_flag_enum.hpp b/tests/xml/test_flag_enum.hpp deleted file mode 100644 index 2f4dc7a0..00000000 --- a/tests/xml/test_flag_enum.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flag_enum { -void test(); -} - diff --git a/tests/xml/test_flag_enum_with_int.cpp b/tests/xml/test_flag_enum_with_int.cpp index 4a0eb52d..7dcc7204 100644 --- a/tests/xml/test_flag_enum_with_int.cpp +++ b/tests/xml/test_flag_enum_with_int.cpp @@ -1,12 +1,10 @@ #include #include #include -#include #include #include #include -#include "test_enum.hpp" #include "write_and_read.hpp" namespace test_flag_enum_with_int { @@ -28,9 +26,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_flag_enum_with_int) { const auto circle = Circle{.radius = 2.0, .color = static_cast(10000)}; write_and_read(circle); diff --git a/tests/xml/test_flag_enum_with_int.hpp b/tests/xml/test_flag_enum_with_int.hpp deleted file mode 100644 index a7512b60..00000000 --- a/tests/xml/test_flag_enum_with_int.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flag_enum_with_int { -void test(); -} - diff --git a/tests/xml/test_flatten.cpp b/tests/xml/test_flatten.cpp index 468add92..2d691656 100644 --- a/tests/xml/test_flatten.cpp +++ b/tests/xml/test_flatten.cpp @@ -1,9 +1,6 @@ -#include "test_flatten.hpp" - #include #include #include -#include #include #include #include @@ -24,9 +21,7 @@ struct Employee { rfl::Field<"salary", float> salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_flatten) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), diff --git a/tests/xml/test_flatten.hpp b/tests/xml/test_flatten.hpp deleted file mode 100644 index 24d60e11..00000000 --- a/tests/xml/test_flatten.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_flatten_anonymous.cpp b/tests/xml/test_flatten_anonymous.cpp index c1bc0f07..6bfb6f00 100644 --- a/tests/xml/test_flatten_anonymous.cpp +++ b/tests/xml/test_flatten_anonymous.cpp @@ -1,9 +1,6 @@ -#include "test_flatten_anonymous.hpp" - #include #include #include -#include #include #include #include @@ -24,9 +21,7 @@ struct Employee { float salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_flatten_anonymous) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), diff --git a/tests/xml/test_flatten_anonymous.hpp b/tests/xml/test_flatten_anonymous.hpp deleted file mode 100644 index 7ffa2785..00000000 --- a/tests/xml/test_flatten_anonymous.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten_anonymous{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_forward_list.cpp b/tests/xml/test_forward_list.cpp index ed0d07b8..c8bf9a52 100644 --- a/tests/xml/test_forward_list.cpp +++ b/tests/xml/test_forward_list.cpp @@ -1,8 +1,5 @@ -#include "test_forward_list.hpp" - #include #include -#include #include #include #include @@ -17,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_forward_list) { auto children = std::make_unique>(); children->emplace_front(Person{.first_name = "Maggie"}); children->emplace_front(Person{.first_name = "Lisa"}); diff --git a/tests/xml/test_forward_list.hpp b/tests/xml/test_forward_list.hpp deleted file mode 100644 index 9784a0c4..00000000 --- a/tests/xml/test_forward_list.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_forward_list{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_literal.cpp b/tests/xml/test_literal.cpp index 9b940423..71c589e1 100644 --- a/tests/xml/test_literal.cpp +++ b/tests/xml/test_literal.cpp @@ -1,9 +1,6 @@ -#include "test_literal.hpp" - #include #include #include -#include #include #include #include @@ -21,9 +18,7 @@ struct Person { std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_literal) { const auto bart = Person{.first_name = FirstName::make<"Bart">()}; write_and_read(bart); diff --git a/tests/xml/test_literal.hpp b/tests/xml/test_literal.hpp deleted file mode 100644 index ccd500ef..00000000 --- a/tests/xml/test_literal.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_literal_map.cpp b/tests/xml/test_literal_map.cpp index b9a03851..6f531efd 100644 --- a/tests/xml/test_literal_map.cpp +++ b/tests/xml/test_literal_map.cpp @@ -1,10 +1,7 @@ -#include "test_literal_map.hpp" - #include #include #include #include -#include #include #include #include @@ -15,15 +12,13 @@ namespace test_literal_map { using FieldName = rfl::Literal<"firstName", "lastName">; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_literal_map) { std::map> homer; homer.insert(std::make_pair(FieldName::make<"firstName">(), std::make_unique("Homer"))); homer.insert(std::make_pair(FieldName::make<"lastName">(), std::make_unique("Simpson"))); - write_and_read<"person">(homer); + write_and_read<"root">(homer); } } // namespace test_literal_map diff --git a/tests/xml/test_literal_map.hpp b/tests/xml/test_literal_map.hpp deleted file mode 100644 index cc05d0c8..00000000 --- a/tests/xml/test_literal_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_map.cpp b/tests/xml/test_map.cpp index 3e897fe3..638a71e3 100644 --- a/tests/xml/test_map.cpp +++ b/tests/xml/test_map.cpp @@ -1,9 +1,6 @@ -#include "test_map.hpp" - #include #include #include -#include #include #include @@ -17,9 +14,7 @@ struct Person { std::map children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_map) { auto children = std::map(); children.insert(std::make_pair("child1", Person{.first_name = "Bart"})); children.insert(std::make_pair("child2", Person{.first_name = "Lisa"})); diff --git a/tests/xml/test_map.hpp b/tests/xml/test_map.hpp deleted file mode 100644 index 9ae49728..00000000 --- a/tests/xml/test_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_map_with_key_validation.cpp b/tests/xml/test_map_with_key_validation.cpp index 20f831af..490665ad 100644 --- a/tests/xml/test_map_with_key_validation.cpp +++ b/tests/xml/test_map_with_key_validation.cpp @@ -1,9 +1,6 @@ -#include "test_map_with_key_validation.hpp" - #include #include #include -#include #include #include @@ -17,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_map_with_key_validation) { auto children = std::make_unique>(); children->insert(std::make_pair("Bart", Person{.first_name = "Bart"})); diff --git a/tests/xml/test_map_with_key_validation.hpp b/tests/xml/test_map_with_key_validation.hpp deleted file mode 100644 index 1372f926..00000000 --- a/tests/xml/test_map_with_key_validation.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map_with_key_validation{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_monster_example.cpp b/tests/xml/test_monster_example.cpp index e9a443ad..b7003fc5 100644 --- a/tests/xml/test_monster_example.cpp +++ b/tests/xml/test_monster_example.cpp @@ -1,8 +1,5 @@ -#include "test_monster_example.hpp" - #include #include -#include #include #include #include @@ -32,16 +29,14 @@ struct Monster { short hp = 100; std::string name; bool friendly = false; - std::vector inventory; + std::vector inventory; Color color = Color::make<"Blue">(); std::vector weapons; Equipment equipped; std::vector path; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_monster_example) { const auto sword = Weapon{.name = "Sword", .damage = 3}; const auto axe = Weapon{.name = "Axe", .damage = 5}; @@ -49,8 +44,7 @@ void test() { const auto position = Vec3{1.0f, 2.0f, 3.0f}; - const auto inventory = - std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + const auto inventory = std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); const auto orc = Monster{.pos = position, .mana = 150, @@ -62,6 +56,5 @@ void test() { .equipped = rfl::make_field<"weapon">(axe)}; write_and_read(orc); - } } // namespace test_monster_example diff --git a/tests/xml/test_monster_example.hpp b/tests/xml/test_monster_example.hpp deleted file mode 100644 index f2d959fc..00000000 --- a/tests/xml/test_monster_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_monster_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_readme_example.cpp b/tests/xml/test_readme_example.cpp index f75b51ce..688d7182 100644 --- a/tests/xml/test_readme_example.cpp +++ b/tests/xml/test_readme_example.cpp @@ -1,8 +1,5 @@ -#include "test_readme_example.hpp" - #include #include -#include #include #include #include @@ -23,9 +20,7 @@ struct Person { std::vector child; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_readme_example) { const auto bart = Person{.first_name = "Bart", .birthday = "1987-04-19", .age = 10, diff --git a/tests/xml/test_readme_example.hpp b/tests/xml/test_readme_example.hpp deleted file mode 100644 index 68c6cf81..00000000 --- a/tests/xml/test_readme_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_readme_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_readme_example2.cpp b/tests/xml/test_readme_example2.cpp new file mode 100644 index 00000000..9468af5d --- /dev/null +++ b/tests/xml/test_readme_example2.cpp @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include + +#include "write_and_read.hpp" + +namespace test_readme_example2 { + +struct Person { + std::string first_name; + std::string last_name; + int age; +}; + +TEST(xml, test_readme_example2) { + const auto homer = + Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; + + write_and_read(homer); +} +} // namespace test_readme_example2 diff --git a/tests/xml/test_ref.cpp b/tests/xml/test_ref.cpp index 39a0c726..da6c8d5f 100644 --- a/tests/xml/test_ref.cpp +++ b/tests/xml/test_ref.cpp @@ -1,9 +1,6 @@ -#include "test_ref.hpp" - #include #include #include -#include #include #include #include @@ -30,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_ref) { const auto leaf1 = DecisionTree::Leaf{.value = 3.0}; const auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/xml/test_ref.hpp b/tests/xml/test_ref.hpp deleted file mode 100644 index d289ba09..00000000 --- a/tests/xml/test_ref.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_ref{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_save_load.cpp b/tests/xml/test_save_load.cpp index 71adfcb3..a2ee4ad2 100644 --- a/tests/xml/test_save_load.cpp +++ b/tests/xml/test_save_load.cpp @@ -1,5 +1,3 @@ -#include "test_save_load.hpp" - #include #include #include @@ -8,6 +6,8 @@ #include #include +#include + namespace test_save_load { using Age = rfl::Validator children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_save_load) { const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19", @@ -59,12 +57,6 @@ void test() { const auto string1 = rfl::xml::write(homer1); const auto string2 = rfl::xml::write(homer2); - if (string1 != string2) { - std::cout << "Test failed. Content was not identical." << std::endl - << std::endl; - return; - } - - std::cout << "OK" << std::endl << std::endl; + EXPECT_EQ(string1, string2); } } // namespace test_save_load diff --git a/tests/xml/test_save_load.hpp b/tests/xml/test_save_load.hpp deleted file mode 100644 index 7bf10359..00000000 --- a/tests/xml/test_save_load.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_save_load { -void test(); -} - diff --git a/tests/xml/test_set.cpp b/tests/xml/test_set.cpp index fa135b37..2cea6dea 100644 --- a/tests/xml/test_set.cpp +++ b/tests/xml/test_set.cpp @@ -1,8 +1,5 @@ -#include "test_set.hpp" - #include #include -#include #include #include #include @@ -17,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_set) { auto children = std::make_unique>( std::set({"Bart", "Lisa", "Maggie"})); diff --git a/tests/xml/test_set.hpp b/tests/xml/test_set.hpp deleted file mode 100644 index 142a663b..00000000 --- a/tests/xml/test_set.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_set{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_size.cpp b/tests/xml/test_size.cpp index d3f5d6cf..df0cbcfc 100644 --- a/tests/xml/test_size.cpp +++ b/tests/xml/test_size.cpp @@ -1,8 +1,5 @@ -#include "test_size.hpp" - #include #include -#include #include #include #include @@ -20,9 +17,7 @@ struct Person { children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_size) { const auto bart = Person{ .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"}; diff --git a/tests/xml/test_size.hpp b/tests/xml/test_size.hpp deleted file mode 100644 index be330df0..00000000 --- a/tests/xml/test_size.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_size{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_string_map.cpp b/tests/xml/test_string_map.cpp index b4cd9e42..10fcb3ee 100644 --- a/tests/xml/test_string_map.cpp +++ b/tests/xml/test_string_map.cpp @@ -1,25 +1,20 @@ -#include "test_string_map.hpp" - #include #include #include #include -#include #include #include #include "write_and_read.hpp" namespace test_string_map { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_string_map) { std::map> homer; homer.insert( std::make_pair("firstName", std::make_unique("Homer"))); homer.insert( std::make_pair("lastName", std::make_unique("Simpson"))); - write_and_read<"person">(homer); + write_and_read<"root">(homer); } } // namespace test_string_map diff --git a/tests/xml/test_string_map.hpp b/tests/xml/test_string_map.hpp deleted file mode 100644 index 94cb975a..00000000 --- a/tests/xml/test_string_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_string_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_tagged_union.cpp b/tests/xml/test_tagged_union.cpp index 21d0e20c..79ea0014 100644 --- a/tests/xml/test_tagged_union.cpp +++ b/tests/xml/test_tagged_union.cpp @@ -1,9 +1,6 @@ -#include "test_tagged_union.hpp" - #include #include #include -#include #include #include #include @@ -27,11 +24,8 @@ struct Square { using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_tagged_union) { const Shapes r = Rectangle{.height = 10, .width = 5}; - write_and_read<"root">(r); } } // namespace test_tagged_union diff --git a/tests/xml/test_tagged_union.hpp b/tests/xml/test_tagged_union.hpp deleted file mode 100644 index 5d522ff9..00000000 --- a/tests/xml/test_tagged_union.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_tagged_union{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_timestamp.cpp b/tests/xml/test_timestamp.cpp index da643b1e..1a0efaef 100644 --- a/tests/xml/test_timestamp.cpp +++ b/tests/xml/test_timestamp.cpp @@ -1,9 +1,6 @@ -#include "test_timestamp.hpp" - #include #include #include -#include #include #include #include @@ -20,9 +17,7 @@ struct Person { TS birthday; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_timestamp) { const auto result = TS::from_string("nonsense"); if (result) { diff --git a/tests/xml/test_timestamp.hpp b/tests/xml/test_timestamp.hpp deleted file mode 100644 index 891d89b9..00000000 --- a/tests/xml/test_timestamp.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_timestamp{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_unique_ptr.cpp b/tests/xml/test_unique_ptr.cpp index 52c676cb..01f099fe 100644 --- a/tests/xml/test_unique_ptr.cpp +++ b/tests/xml/test_unique_ptr.cpp @@ -1,9 +1,6 @@ -#include "test_unique_ptr.hpp" - #include #include #include -#include #include #include #include @@ -18,9 +15,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_unique_ptr) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/xml/test_unique_ptr.hpp b/tests/xml/test_unique_ptr.hpp deleted file mode 100644 index 428ea2a2..00000000 --- a/tests/xml/test_unique_ptr.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_unique_ptr2.cpp b/tests/xml/test_unique_ptr2.cpp index cd91ccb8..7efd891f 100644 --- a/tests/xml/test_unique_ptr2.cpp +++ b/tests/xml/test_unique_ptr2.cpp @@ -1,9 +1,6 @@ -#include "test_unique_ptr2.hpp" - #include #include #include -#include #include #include #include @@ -30,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_unique_ptr2) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/xml/test_unique_ptr2.hpp b/tests/xml/test_unique_ptr2.hpp deleted file mode 100644 index 74adc170..00000000 --- a/tests/xml/test_unique_ptr2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr2{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_variant.cpp b/tests/xml/test_variant.cpp index 49b9f041..bf64cdcb 100644 --- a/tests/xml/test_variant.cpp +++ b/tests/xml/test_variant.cpp @@ -1,9 +1,6 @@ -#include "test_variant.hpp" - #include #include #include -#include #include #include #include @@ -27,9 +24,7 @@ struct Square { using Shapes = std::variant>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_variant) { const Shapes r = Rectangle{.height = 10, .width = 5}; write_and_read<"root">(r); diff --git a/tests/xml/test_variant.hpp b/tests/xml/test_variant.hpp deleted file mode 100644 index 0e58ce71..00000000 --- a/tests/xml/test_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/xml/test_wstring.cpp b/tests/xml/test_wstring.cpp index 52499e4a..5cfbbe94 100644 --- a/tests/xml/test_wstring.cpp +++ b/tests/xml/test_wstring.cpp @@ -1,5 +1,3 @@ -#include "test_wstring.hpp" - #include #include #include @@ -9,18 +7,16 @@ #include "write_and_read.hpp" -struct Test { +struct TestStruct { std::string theNormalString; std::wstring theWiderString; }; namespace test_wstring { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const Test test = Test{.theNormalString = "The normal string", - .theWiderString = L"The wider string"}; +TEST(xml, test_wstring) { + const auto test = TestStruct{.theNormalString = "The normal string", + .theWiderString = L"The wider string"}; - write_and_read<"root">(test); + write_and_read(test); } } // namespace test_wstring diff --git a/tests/xml/test_wstring.hpp b/tests/xml/test_wstring.hpp deleted file mode 100644 index 0f93e784..00000000 --- a/tests/xml/test_wstring.hpp +++ /dev/null @@ -1,3 +0,0 @@ -namespace test_wstring { - void test(); -} diff --git a/tests/xml/test_xml_content.cpp b/tests/xml/test_xml_content.cpp index be011125..7e47c2bd 100644 --- a/tests/xml/test_xml_content.cpp +++ b/tests/xml/test_xml_content.cpp @@ -1,5 +1,3 @@ -#include "test_xml_content.hpp" - #include #include #include @@ -19,9 +17,7 @@ struct Person { std::vector child; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(xml, test_xml_content) { const auto bart = Person{.xml_content = "Bart Simpson", .birthday = "1987-04-19", .email = "bart@simpson.com"}; diff --git a/tests/xml/test_xml_content.hpp b/tests/xml/test_xml_content.hpp deleted file mode 100644 index 58b774fb..00000000 --- a/tests/xml/test_xml_content.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_xml_content { -void test(); -} - diff --git a/tests/xml/tests.cpp b/tests/xml/tests.cpp deleted file mode 100644 index f8671ee9..00000000 --- a/tests/xml/tests.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "test_array.hpp" -#include "test_attributes.hpp" -#include "test_box.hpp" -#include "test_custom_class1.hpp" -#include "test_custom_class3.hpp" -#include "test_custom_class4.hpp" -#include "test_default_values.hpp" -#include "test_deque.hpp" -#include "test_enum.hpp" -#include "test_field_variant.hpp" -#include "test_flag_enum.hpp" -#include "test_flag_enum_with_int.hpp" -#include "test_flatten.hpp" -#include "test_flatten_anonymous.hpp" -#include "test_forward_list.hpp" -#include "test_literal.hpp" -#include "test_literal_map.hpp" -#include "test_map.hpp" -#include "test_map_with_key_validation.hpp" -#include "test_monster_example.hpp" -#include "test_readme_example.hpp" -#include "test_ref.hpp" -#include "test_save_load.hpp" -#include "test_set.hpp" -#include "test_size.hpp" -#include "test_tagged_union.hpp" -#include "test_timestamp.hpp" -#include "test_unique_ptr.hpp" -#include "test_unique_ptr2.hpp" -#include "test_variant.hpp" -#include "test_xml_content.hpp" -#include "test_wstring.hpp" - -int main() { - test_readme_example::test(); - test_attributes::test(); - test_xml_content::test(); - test_flatten::test(); - test_flatten_anonymous::test(); - test_enum::test(); - test_flag_enum::test(); - test_flag_enum_with_int::test(); - test_map::test(); - test_map_with_key_validation::test(); - test_variant::test(); - test_field_variant::test(); - test_tagged_union::test(); - test_deque::test(); - test_forward_list::test(); - test_literal_map::test(); - test_literal::test(); - test_monster_example::test(); - test_ref::test(); - test_set::test(); - test_size::test(); - test_timestamp::test(); - test_unique_ptr::test(); - test_unique_ptr2::test(); - test_array::test(); - test_box::test(); - test_custom_class1::test(); - test_custom_class3::test(); - test_custom_class4::test(); - test_default_values::test(); - test_save_load::test(); - test_wstring::test(); - - return 0; -} diff --git a/tests/xml/write_and_read.hpp b/tests/xml/write_and_read.hpp index ceb85c8a..a3aa4719 100644 --- a/tests/xml/write_and_read.hpp +++ b/tests/xml/write_and_read.hpp @@ -1,36 +1,23 @@ #ifndef WRITE_AND_READ_ #define WRITE_AND_READ_ +#include + #include +#include #include #include -#include "rfl/internal/StringLiteral.hpp" - template < rfl::internal::StringLiteral _root_name = rfl::internal::StringLiteral(""), class T> void write_and_read(const T& _struct) { - const auto xml_string1 = rfl::xml::write<_root_name>(_struct); - const auto res = rfl::xml::read(xml_string1); - if (!res) { - std::cout << "Test failed on read. Error: " << res.error().value().what() - << std::endl - << "Original string: " << xml_string1 << std::endl - << std::endl; - return; - } - const auto xml_string2 = rfl::xml::write<_root_name>(res.value()); - if (xml_string2 != xml_string1) { - std::cout << "Test failed on read. Expected:" << std::endl - << xml_string1 << std::endl - << "Got: " << std::endl - << xml_string2 << std::endl - << std::endl; - return; - } - // std::cout << xml_string1 << std::endl; - std::cout << "OK" << std::endl << std::endl; + const auto serialized1 = rfl::xml::write<_root_name>(_struct); + const auto res = rfl::xml::read(serialized1); + EXPECT_TRUE(res && true) << "Test failed on read. Error: " + << res.error().value().what(); + const auto serialized2 = rfl::xml::write<_root_name>(res.value()); + EXPECT_EQ(serialized1, serialized2); } #endif diff --git a/tests/yaml/CMakeLists.txt b/tests/yaml/CMakeLists.txt index 238ef474..5445171a 100644 --- a/tests/yaml/CMakeLists.txt +++ b/tests/yaml/CMakeLists.txt @@ -1,8 +1,18 @@ project(reflect-cpp-yaml-tests) -file(GLOB_RECURSE SOURCES "*.cpp") +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp") -add_executable(reflect-cpp-yaml-tests ${SOURCES}) +add_executable( + reflect-cpp-yaml-tests + ${SOURCES} + "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/src/gtest_main.cc" +) -target_link_libraries(reflect-cpp-yaml-tests PRIVATE reflectcpp) +target_include_directories(reflect-cpp-yaml-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include") +target_link_libraries( + reflect-cpp-yaml-tests + PRIVATE + reflectcpp + "${REFLECT_CPP_GTEST_LIB}" +) diff --git a/tests/yaml/test_array.cpp b/tests/yaml/test_array.cpp index a4586d3b..713a52b0 100644 --- a/tests/yaml/test_array.cpp +++ b/tests/yaml/test_array.cpp @@ -1,5 +1,3 @@ -#include "test_array.hpp" - #include #include #include @@ -8,7 +6,7 @@ #include // Make sure things still compile when -// rfl.hpp is included after rfl/yaml.hpp. +// rfl.hpp is included after rfl/cbor.hpp. #include #include "write_and_read.hpp" @@ -21,9 +19,7 @@ struct Person { std::unique_ptr> children = nullptr; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_array) { auto bart = Person{.first_name = "Bart"}; auto lisa = Person{.first_name = "Lisa"}; diff --git a/tests/yaml/test_array.hpp b/tests/yaml/test_array.hpp deleted file mode 100644 index 502c3388..00000000 --- a/tests/yaml/test_array.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_array{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_box.cpp b/tests/yaml/test_box.cpp index 04d88641..ca6e0cfe 100644 --- a/tests/yaml/test_box.cpp +++ b/tests/yaml/test_box.cpp @@ -1,9 +1,6 @@ -#include "test_box.hpp" - #include #include #include -#include #include #include #include @@ -30,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_box) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/yaml/test_box.hpp b/tests/yaml/test_box.hpp deleted file mode 100644 index a564b9e1..00000000 --- a/tests/yaml/test_box.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_box{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_custom_class1.cpp b/tests/yaml/test_custom_class1.cpp index 35f4a1da..872d1ef7 100644 --- a/tests/yaml/test_custom_class1.cpp +++ b/tests/yaml/test_custom_class1.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class1.hpp" - #include #include #include -#include #include #include #include @@ -32,9 +29,7 @@ struct Person { PersonImpl impl; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_custom_class1) { const auto bart = Person("Bart"); write_and_read(bart); diff --git a/tests/yaml/test_custom_class1.hpp b/tests/yaml/test_custom_class1.hpp deleted file mode 100644 index eafe6cd0..00000000 --- a/tests/yaml/test_custom_class1.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class1{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_custom_class3.cpp b/tests/yaml/test_custom_class3.cpp index 2ea105e4..a59d5c22 100644 --- a/tests/yaml/test_custom_class3.cpp +++ b/tests/yaml/test_custom_class3.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class3.hpp" - #include #include #include -#include #include #include #include @@ -57,9 +54,7 @@ struct Parser namespace test_custom_class3 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_custom_class3) { const auto bart = Person("Bart", "Simpson", 10); write_and_read(bart); diff --git a/tests/yaml/test_custom_class3.hpp b/tests/yaml/test_custom_class3.hpp deleted file mode 100644 index 9a6fdab4..00000000 --- a/tests/yaml/test_custom_class3.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class3{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_custom_class4.cpp b/tests/yaml/test_custom_class4.cpp index e2d79a94..43bccf9f 100644 --- a/tests/yaml/test_custom_class4.cpp +++ b/tests/yaml/test_custom_class4.cpp @@ -1,9 +1,6 @@ -#include "test_custom_class4.hpp" - #include #include #include -#include #include #include #include @@ -58,9 +55,7 @@ struct Parser namespace test_custom_class4 { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_custom_class4) { const auto bart = test_custom_class4::Person( "Bart", rfl::make_box("Simpson"), 10); diff --git a/tests/yaml/test_custom_class4.hpp b/tests/yaml/test_custom_class4.hpp deleted file mode 100644 index 2d3b151a..00000000 --- a/tests/yaml/test_custom_class4.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_class4{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_custom_constructor.cpp b/tests/yaml/test_custom_constructor.cpp deleted file mode 100644 index 3bff855c..00000000 --- a/tests/yaml/test_custom_constructor.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include "test_custom_constructor.hpp" - -#include -#include -#include -#include -#include -#include - -#include "write_and_read.hpp" - -namespace test_custom_constructor { - -struct Person { - static rfl::Result from_yaml_obj( - typename rfl::yaml::Reader::InputVarType _obj) { - /// This only exists for the purpose of the test. - const auto change_first_name = [](auto&& _person) { - return rfl::replace(std::move(_person), - rfl::Field<"firstName", std::string>("Bart")); - }; - const auto from_nt = [](auto&& _nt) { - return rfl::from_named_tuple(std::move(_nt)); - }; - return rfl::yaml::read>(_obj) - .transform(from_nt) - .transform(change_first_name); - } - - rfl::Field<"firstName", std::string> first_name; - rfl::Field<"lastName", std::string> last_name; - rfl::Field<"birthday", rfl::Timestamp<"%Y-%m-%d">> birthday; -}; - -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const auto res = rfl::yaml::read( - R"(firstName: Homer -lastName: Simpson -birthday: 1987-04-19)"); - - if (!res) { - std::cout << "Test failed on read. Error: " << res.error().value().what() - << std::endl; - return; - } - - if (res.value().first_name() != "Bart") { - std::cout << "Expected 'Bart', got '" << res.value().first_name() << "'" - << std::endl - << std::endl; - } else { - std::cout << "OK" << std::endl << std::endl; - } -} -} // namespace test_custom_constructor diff --git a/tests/yaml/test_custom_constructor.hpp b/tests/yaml/test_custom_constructor.hpp deleted file mode 100644 index 013721d0..00000000 --- a/tests/yaml/test_custom_constructor.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_custom_constructor{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_default_values.cpp b/tests/yaml/test_default_values.cpp index f6af2352..d73fad6b 100644 --- a/tests/yaml/test_default_values.cpp +++ b/tests/yaml/test_default_values.cpp @@ -1,5 +1,3 @@ -#include "test_default_values.hpp" - #include #include #include @@ -17,9 +15,7 @@ struct Person { std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_default_values) { const auto bart = Person{.first_name = "Bart"}; const auto lisa = Person{.first_name = "Lisa"}; const auto maggie = Person{.first_name = "Maggie"}; diff --git a/tests/yaml/test_default_values.hpp b/tests/yaml/test_default_values.hpp deleted file mode 100644 index c8f8360e..00000000 --- a/tests/yaml/test_default_values.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_default_values{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_deque.cpp b/tests/yaml/test_deque.cpp index 6dfa5803..6e0404c2 100644 --- a/tests/yaml/test_deque.cpp +++ b/tests/yaml/test_deque.cpp @@ -1,5 +1,3 @@ -#include "test_deque.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_default_values) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/yaml/test_deque.hpp b/tests/yaml/test_deque.hpp deleted file mode 100644 index 6781e880..00000000 --- a/tests/yaml/test_deque.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_deque{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_enum.cpp b/tests/yaml/test_enum.cpp index d4d56a8b..9a37b856 100644 --- a/tests/yaml/test_enum.cpp +++ b/tests/yaml/test_enum.cpp @@ -1,5 +1,3 @@ -#include "test_enum.hpp" - #include #include #include @@ -18,9 +16,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::green}; write_and_read(circle); diff --git a/tests/yaml/test_enum.hpp b/tests/yaml/test_enum.hpp deleted file mode 100644 index 2e2e0b3d..00000000 --- a/tests/yaml/test_enum.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_enum { -void test(); -} - diff --git a/tests/yaml/test_field_variant.cpp b/tests/yaml/test_field_variant.cpp index 8b17665f..c75be2d1 100644 --- a/tests/yaml/test_field_variant.cpp +++ b/tests/yaml/test_field_variant.cpp @@ -1,5 +1,3 @@ -#include "test_field_variant.hpp" - #include #include #include @@ -28,9 +26,7 @@ using Shapes = rfl::Variant, rfl::Field<"rectangle", Rectangle>, rfl::Field<"square", rfl::Box>>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_field_variant) { const Shapes r = rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5}); diff --git a/tests/yaml/test_field_variant.hpp b/tests/yaml/test_field_variant.hpp deleted file mode 100644 index ba93e732..00000000 --- a/tests/yaml/test_field_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_field_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_flag_enum.cpp b/tests/yaml/test_flag_enum.cpp index 1d3f76af..6c14a1db 100644 --- a/tests/yaml/test_flag_enum.cpp +++ b/tests/yaml/test_flag_enum.cpp @@ -5,7 +5,6 @@ #include #include -#include "test_enum.hpp" #include "write_and_read.hpp" namespace test_flag_enum { @@ -27,9 +26,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_flag_enum) { const auto circle = Circle{.radius = 2.0, .color = Color::blue | Color::orange}; diff --git a/tests/yaml/test_flag_enum.hpp b/tests/yaml/test_flag_enum.hpp deleted file mode 100644 index 2f4dc7a0..00000000 --- a/tests/yaml/test_flag_enum.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flag_enum { -void test(); -} - diff --git a/tests/yaml/test_flag_enum_with_int.cpp b/tests/yaml/test_flag_enum_with_int.cpp index 4c7deefe..5f63353c 100644 --- a/tests/yaml/test_flag_enum_with_int.cpp +++ b/tests/yaml/test_flag_enum_with_int.cpp @@ -5,7 +5,6 @@ #include #include -#include "test_enum.hpp" #include "write_and_read.hpp" namespace test_flag_enum_with_int { @@ -27,9 +26,7 @@ struct Circle { Color color; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_flag_enum_with_int) { const auto circle = Circle{.radius = 2.0, .color = static_cast(10000)}; write_and_read(circle); diff --git a/tests/yaml/test_flag_enum_with_int.hpp b/tests/yaml/test_flag_enum_with_int.hpp deleted file mode 100644 index a7512b60..00000000 --- a/tests/yaml/test_flag_enum_with_int.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flag_enum_with_int { -void test(); -} - diff --git a/tests/yaml/test_flatten.cpp b/tests/yaml/test_flatten.cpp index c7f1d9be..40a7ed56 100644 --- a/tests/yaml/test_flatten.cpp +++ b/tests/yaml/test_flatten.cpp @@ -1,5 +1,3 @@ -#include "test_flatten.hpp" - #include #include #include @@ -23,9 +21,7 @@ struct Employee { rfl::Field<"salary", float> salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_flatten) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), diff --git a/tests/yaml/test_flatten.hpp b/tests/yaml/test_flatten.hpp deleted file mode 100644 index 24d60e11..00000000 --- a/tests/yaml/test_flatten.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_flatten_anonymous.cpp b/tests/yaml/test_flatten_anonymous.cpp index 05e61464..866c80ae 100644 --- a/tests/yaml/test_flatten_anonymous.cpp +++ b/tests/yaml/test_flatten_anonymous.cpp @@ -1,5 +1,3 @@ -#include "test_flatten_anonymous.hpp" - #include #include #include @@ -23,9 +21,7 @@ struct Employee { float salary; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_flatten_anonymous) { const auto employee = Employee{ .person = Person{.first_name = "Homer", .last_name = rfl::make_box("Simpson"), diff --git a/tests/yaml/test_flatten_anonymous.hpp b/tests/yaml/test_flatten_anonymous.hpp deleted file mode 100644 index 7ffa2785..00000000 --- a/tests/yaml/test_flatten_anonymous.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_flatten_anonymous{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_forward_list.cpp b/tests/yaml/test_forward_list.cpp index dd8d9e56..6b8b5eb8 100644 --- a/tests/yaml/test_forward_list.cpp +++ b/tests/yaml/test_forward_list.cpp @@ -1,5 +1,3 @@ -#include "test_forward_list.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_forward_list) { auto children = std::make_unique>(); children->emplace_front(Person{.first_name = "Maggie"}); children->emplace_front(Person{.first_name = "Lisa"}); diff --git a/tests/yaml/test_forward_list.hpp b/tests/yaml/test_forward_list.hpp deleted file mode 100644 index 9784a0c4..00000000 --- a/tests/yaml/test_forward_list.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_forward_list{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_literal.cpp b/tests/yaml/test_literal.cpp index 00578178..7c5f7e50 100644 --- a/tests/yaml/test_literal.cpp +++ b/tests/yaml/test_literal.cpp @@ -1,5 +1,3 @@ -#include "test_literal.hpp" - #include #include #include @@ -20,9 +18,7 @@ struct Person { std::vector children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_literal) { const auto bart = Person{.first_name = FirstName::make<"Bart">()}; write_and_read(bart); diff --git a/tests/yaml/test_literal.hpp b/tests/yaml/test_literal.hpp deleted file mode 100644 index ccd500ef..00000000 --- a/tests/yaml/test_literal.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_literal_map.cpp b/tests/yaml/test_literal_map.cpp index 9bbebafb..41b4dffc 100644 --- a/tests/yaml/test_literal_map.cpp +++ b/tests/yaml/test_literal_map.cpp @@ -1,5 +1,3 @@ -#include "test_literal_map.hpp" - #include #include #include @@ -14,9 +12,7 @@ namespace test_literal_map { using FieldName = rfl::Literal<"firstName", "lastName">; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_literal_map) { std::map> homer; homer.insert(std::make_pair(FieldName::make<"firstName">(), std::make_unique("Homer"))); diff --git a/tests/yaml/test_literal_map.hpp b/tests/yaml/test_literal_map.hpp deleted file mode 100644 index cc05d0c8..00000000 --- a/tests/yaml/test_literal_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_literal_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_map.cpp b/tests/yaml/test_map.cpp index e37ce564..68c63646 100644 --- a/tests/yaml/test_map.cpp +++ b/tests/yaml/test_map.cpp @@ -1,5 +1,3 @@ -#include "test_map.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::map children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_map) { auto children = std::map(); children.insert(std::make_pair("child1", Person{.first_name = "Bart"})); children.insert(std::make_pair("child2", Person{.first_name = "Lisa"})); diff --git a/tests/yaml/test_map.hpp b/tests/yaml/test_map.hpp deleted file mode 100644 index 9ae49728..00000000 --- a/tests/yaml/test_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_map_with_key_validation.cpp b/tests/yaml/test_map_with_key_validation.cpp index e758219d..6cde9a83 100644 --- a/tests/yaml/test_map_with_key_validation.cpp +++ b/tests/yaml/test_map_with_key_validation.cpp @@ -1,5 +1,3 @@ -#include "test_map_with_key_validation.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_map_with_key_validation) { auto children = std::make_unique>(); children->insert(std::make_pair("Bart", Person{.first_name = "Bart"})); diff --git a/tests/yaml/test_map_with_key_validation.hpp b/tests/yaml/test_map_with_key_validation.hpp deleted file mode 100644 index 1372f926..00000000 --- a/tests/yaml/test_map_with_key_validation.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_map_with_key_validation{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_monster_example.cpp b/tests/yaml/test_monster_example.cpp index 052d8390..9f6f81b2 100644 --- a/tests/yaml/test_monster_example.cpp +++ b/tests/yaml/test_monster_example.cpp @@ -1,5 +1,3 @@ -#include "test_monster_example.hpp" - #include #include #include @@ -38,9 +36,7 @@ struct Monster { std::vector path; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_monster_example) { const auto sword = Weapon{.name = "Sword", .damage = 3}; const auto axe = Weapon{.name = "Axe", .damage = 5}; diff --git a/tests/yaml/test_monster_example.hpp b/tests/yaml/test_monster_example.hpp deleted file mode 100644 index f2d959fc..00000000 --- a/tests/yaml/test_monster_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_monster_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_readme_example.cpp b/tests/yaml/test_readme_example.cpp index 4e6f8ee0..a877b3eb 100644 --- a/tests/yaml/test_readme_example.cpp +++ b/tests/yaml/test_readme_example.cpp @@ -1,5 +1,3 @@ -#include "test_readme_example.hpp" - #include #include #include @@ -22,9 +20,7 @@ struct Person { std::vector child; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_readme_example) { const auto bart = Person{.first_name = "Bart", .birthday = "1987-04-19", .age = 10, diff --git a/tests/yaml/test_readme_example.hpp b/tests/yaml/test_readme_example.hpp deleted file mode 100644 index 68c6cf81..00000000 --- a/tests/yaml/test_readme_example.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_readme_example{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_readme_example2.cpp b/tests/yaml/test_readme_example2.cpp index a2d212a4..e42ac269 100644 --- a/tests/yaml/test_readme_example2.cpp +++ b/tests/yaml/test_readme_example2.cpp @@ -4,7 +4,6 @@ #include #include -#include "test_readme_example.hpp" #include "write_and_read.hpp" namespace test_readme_example2 { @@ -15,9 +14,7 @@ struct Person { int age; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_readme_example2) { const auto homer = Person{.first_name = "Homer", .last_name = "Simpson", .age = 45}; diff --git a/tests/yaml/test_readme_example2.hpp b/tests/yaml/test_readme_example2.hpp deleted file mode 100644 index 5c6b011c..00000000 --- a/tests/yaml/test_readme_example2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_readme_example2 { -void test(); -} - diff --git a/tests/yaml/test_ref.cpp b/tests/yaml/test_ref.cpp index 32a32e6c..93d069d7 100644 --- a/tests/yaml/test_ref.cpp +++ b/tests/yaml/test_ref.cpp @@ -1,5 +1,3 @@ -#include "test_ref.hpp" - #include #include #include @@ -29,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_ref) { const auto leaf1 = DecisionTree::Leaf{.value = 3.0}; const auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/yaml/test_ref.hpp b/tests/yaml/test_ref.hpp deleted file mode 100644 index d289ba09..00000000 --- a/tests/yaml/test_ref.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_ref{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_save_load.cpp b/tests/yaml/test_save_load.cpp index c20fc181..ac656f0b 100644 --- a/tests/yaml/test_save_load.cpp +++ b/tests/yaml/test_save_load.cpp @@ -1,5 +1,3 @@ -#include "test_save_load.hpp" - #include #include #include @@ -8,6 +6,8 @@ #include #include +#include + namespace test_save_load { using Age = rfl::Validator children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_save_load) { const auto bart = Person{.first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19", @@ -59,12 +57,6 @@ void test() { const auto string1 = rfl::yaml::write(homer1); const auto string2 = rfl::yaml::write(homer2); - if (string1 != string2) { - std::cout << "Test failed. Content was not identical." << std::endl - << std::endl; - return; - } - - std::cout << "OK" << std::endl << std::endl; + EXPECT_EQ(string1, string2); } } // namespace test_save_load diff --git a/tests/yaml/test_save_load.hpp b/tests/yaml/test_save_load.hpp deleted file mode 100644 index 7bf10359..00000000 --- a/tests/yaml/test_save_load.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_save_load { -void test(); -} - diff --git a/tests/yaml/test_set.cpp b/tests/yaml/test_set.cpp index 9f2516ce..0f19fbcd 100644 --- a/tests/yaml/test_set.cpp +++ b/tests/yaml/test_set.cpp @@ -1,5 +1,3 @@ -#include "test_set.hpp" - #include #include #include @@ -16,9 +14,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_set) { auto children = std::make_unique>( std::set({"Bart", "Lisa", "Maggie"})); diff --git a/tests/yaml/test_set.hpp b/tests/yaml/test_set.hpp deleted file mode 100644 index 142a663b..00000000 --- a/tests/yaml/test_set.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_set{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_size.cpp b/tests/yaml/test_size.cpp index c37b9bd8..b3502ff4 100644 --- a/tests/yaml/test_size.cpp +++ b/tests/yaml/test_size.cpp @@ -1,5 +1,3 @@ -#include "test_size.hpp" - #include #include #include @@ -19,9 +17,7 @@ struct Person { children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_size) { const auto bart = Person{ .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"}; diff --git a/tests/yaml/test_size.hpp b/tests/yaml/test_size.hpp deleted file mode 100644 index be330df0..00000000 --- a/tests/yaml/test_size.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_size{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_string_map.cpp b/tests/yaml/test_string_map.cpp index cb4fb903..fe682d62 100644 --- a/tests/yaml/test_string_map.cpp +++ b/tests/yaml/test_string_map.cpp @@ -1,5 +1,3 @@ -#include "test_string_map.hpp" - #include #include #include @@ -10,9 +8,7 @@ #include "write_and_read.hpp" namespace test_string_map { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_string_map) { std::map> homer; homer.insert( std::make_pair("firstName", std::make_unique("Homer"))); diff --git a/tests/yaml/test_string_map.hpp b/tests/yaml/test_string_map.hpp deleted file mode 100644 index 94cb975a..00000000 --- a/tests/yaml/test_string_map.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_string_map{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_tagged_union.cpp b/tests/yaml/test_tagged_union.cpp index a9dd1abc..b226f2e6 100644 --- a/tests/yaml/test_tagged_union.cpp +++ b/tests/yaml/test_tagged_union.cpp @@ -1,5 +1,3 @@ -#include "test_tagged_union.hpp" - #include #include #include @@ -26,11 +24,8 @@ struct Square { using Shapes = rfl::TaggedUnion<"shape", Circle, Square, Rectangle>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_tagged_union) { const Shapes r = Rectangle{.height = 10, .width = 5}; - write_and_read(r); } } // namespace test_tagged_union diff --git a/tests/yaml/test_tagged_union.hpp b/tests/yaml/test_tagged_union.hpp deleted file mode 100644 index 5d522ff9..00000000 --- a/tests/yaml/test_tagged_union.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_tagged_union{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_timestamp.cpp b/tests/yaml/test_timestamp.cpp index 8af261d1..64e3bdce 100644 --- a/tests/yaml/test_timestamp.cpp +++ b/tests/yaml/test_timestamp.cpp @@ -1,5 +1,3 @@ -#include "test_timestamp.hpp" - #include #include #include @@ -19,9 +17,7 @@ struct Person { TS birthday; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_timestamp) { const auto result = TS::from_string("nonsense"); if (result) { diff --git a/tests/yaml/test_timestamp.hpp b/tests/yaml/test_timestamp.hpp deleted file mode 100644 index 891d89b9..00000000 --- a/tests/yaml/test_timestamp.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_timestamp{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_unique_ptr.cpp b/tests/yaml/test_unique_ptr.cpp index b1833533..35d74cc3 100644 --- a/tests/yaml/test_unique_ptr.cpp +++ b/tests/yaml/test_unique_ptr.cpp @@ -1,5 +1,3 @@ -#include "test_unique_ptr.hpp" - #include #include #include @@ -17,9 +15,7 @@ struct Person { std::unique_ptr> children; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_unique_ptr) { auto children = std::make_unique>(); children->emplace_back(Person{.first_name = "Bart"}); children->emplace_back(Person{.first_name = "Lisa"}); diff --git a/tests/yaml/test_unique_ptr.hpp b/tests/yaml/test_unique_ptr.hpp deleted file mode 100644 index 428ea2a2..00000000 --- a/tests/yaml/test_unique_ptr.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_unique_ptr2.cpp b/tests/yaml/test_unique_ptr2.cpp index e3007267..3a8ee94a 100644 --- a/tests/yaml/test_unique_ptr2.cpp +++ b/tests/yaml/test_unique_ptr2.cpp @@ -1,5 +1,3 @@ -#include "test_unique_ptr2.hpp" - #include #include #include @@ -29,9 +27,7 @@ struct DecisionTree { rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node; }; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_unique_ptr2) { auto leaf1 = DecisionTree::Leaf{.value = 3.0}; auto leaf2 = DecisionTree::Leaf{.value = 5.0}; diff --git a/tests/yaml/test_unique_ptr2.hpp b/tests/yaml/test_unique_ptr2.hpp deleted file mode 100644 index 74adc170..00000000 --- a/tests/yaml/test_unique_ptr2.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_unique_ptr2{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_variant.cpp b/tests/yaml/test_variant.cpp index cc3d6cbe..e9bc0c9a 100644 --- a/tests/yaml/test_variant.cpp +++ b/tests/yaml/test_variant.cpp @@ -1,5 +1,3 @@ -#include "test_variant.hpp" - #include #include #include @@ -26,9 +24,7 @@ struct Square { using Shapes = std::variant>; -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - +TEST(yaml, test_variant) { const Shapes r = Rectangle{.height = 10, .width = 5}; write_and_read(r); diff --git a/tests/yaml/test_variant.hpp b/tests/yaml/test_variant.hpp deleted file mode 100644 index 0e58ce71..00000000 --- a/tests/yaml/test_variant.hpp +++ /dev/null @@ -1,4 +0,0 @@ -namespace test_variant{ - void test(); -} - \ No newline at end of file diff --git a/tests/yaml/test_wstring.cpp b/tests/yaml/test_wstring.cpp index ba6202c0..5fadc26c 100644 --- a/tests/yaml/test_wstring.cpp +++ b/tests/yaml/test_wstring.cpp @@ -1,5 +1,3 @@ -#include "test_wstring.hpp" - #include #include #include @@ -9,17 +7,15 @@ #include "write_and_read.hpp" -struct Test { +struct TestStruct { std::string theNormalString; std::wstring theWiderString; }; namespace test_wstring { -void test() { - std::cout << std::source_location::current().function_name() << std::endl; - - const Test test = Test{.theNormalString = "The normal string", - .theWiderString = L"The wider string"}; +TEST(yaml, test_wstring) { + const auto test = TestStruct{.theNormalString = "The normal string", + .theWiderString = L"The wider string"}; write_and_read(test); } diff --git a/tests/yaml/test_wstring.hpp b/tests/yaml/test_wstring.hpp deleted file mode 100644 index 0f93e784..00000000 --- a/tests/yaml/test_wstring.hpp +++ /dev/null @@ -1,3 +0,0 @@ -namespace test_wstring { - void test(); -} diff --git a/tests/yaml/tests.cpp b/tests/yaml/tests.cpp deleted file mode 100644 index 7a38771d..00000000 --- a/tests/yaml/tests.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "test_array.hpp" -#include "test_box.hpp" -#include "test_custom_class1.hpp" -#include "test_custom_class3.hpp" -#include "test_custom_class4.hpp" -#include "test_custom_constructor.hpp" -#include "test_default_values.hpp" -#include "test_deque.hpp" -#include "test_enum.hpp" -#include "test_field_variant.hpp" -#include "test_flag_enum.hpp" -#include "test_flag_enum_with_int.hpp" -#include "test_flatten.hpp" -#include "test_flatten_anonymous.hpp" -#include "test_forward_list.hpp" -#include "test_literal.hpp" -#include "test_literal_map.hpp" -#include "test_map.hpp" -#include "test_map_with_key_validation.hpp" -#include "test_monster_example.hpp" -#include "test_readme_example.hpp" -#include "test_readme_example2.hpp" -#include "test_ref.hpp" -#include "test_save_load.hpp" -#include "test_set.hpp" -#include "test_size.hpp" -#include "test_tagged_union.hpp" -#include "test_timestamp.hpp" -#include "test_unique_ptr.hpp" -#include "test_unique_ptr2.hpp" -#include "test_variant.hpp" -#include "test_wstring.hpp" - -int main() { - test_readme_example::test(); - test_readme_example2::test(); - test_flatten::test(); - test_flatten_anonymous::test(); - test_enum::test(); - test_flag_enum::test(); - test_flag_enum_with_int::test(); - test_map::test(); - test_map_with_key_validation::test(); - test_variant::test(); - test_field_variant::test(); - test_tagged_union::test(); - test_deque::test(); - test_forward_list::test(); - test_literal_map::test(); - test_literal::test(); - test_monster_example::test(); - test_ref::test(); - test_set::test(); - test_size::test(); - test_timestamp::test(); - test_unique_ptr::test(); - test_unique_ptr2::test(); - test_array::test(); - test_box::test(); - test_custom_class1::test(); - test_custom_class3::test(); - test_custom_class4::test(); - test_default_values::test(); - test_custom_constructor::test(); - test_save_load::test(); - test_wstring::test(); - - return 0; -} diff --git a/tests/yaml/write_and_read.hpp b/tests/yaml/write_and_read.hpp index 6f6e2743..6e4d5922 100644 --- a/tests/yaml/write_and_read.hpp +++ b/tests/yaml/write_and_read.hpp @@ -1,32 +1,20 @@ #ifndef WRITE_AND_READ_ #define WRITE_AND_READ_ +#include + #include #include #include template void write_and_read(const T& _struct) { - const auto yaml_string1 = rfl::yaml::write(_struct); - const auto res = rfl::yaml::read(yaml_string1); - if (!res) { - std::cout << "Test failed on read. Error: " << res.error().value().what() - << std::endl - << "Original string: " << yaml_string1 << std::endl - << std::endl; - return; - } - const auto yaml_string2 = rfl::yaml::write(res.value()); - if (yaml_string2 != yaml_string1) { - std::cout << "Test failed on read. Expected:" << std::endl - << yaml_string1 << std::endl - << "Got: " << std::endl - << yaml_string2 << std::endl - << std::endl; - return; - } - // std::cout << yaml_string1 << std::endl; - std::cout << "OK" << std::endl << std::endl; + const auto serialized1 = rfl::yaml::write(_struct); + const auto res = rfl::yaml::read(serialized1); + EXPECT_TRUE(res && true) << "Test failed on read. Error: " + << res.error().value().what(); + const auto serialized2 = rfl::yaml::write(res.value()); + EXPECT_EQ(serialized1, serialized2); } #endif