Skip to content

Commit

Permalink
Rewrote the JSON tests using GTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Urbanke committed Apr 21, 2024
1 parent 2af650f commit df04739
Show file tree
Hide file tree
Showing 185 changed files with 164 additions and 1,121 deletions.
15 changes: 13 additions & 2 deletions tests/json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ project(reflect-cpp-json-tests)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp")

add_executable(reflect-cpp-json-tests ${SOURCES})
add_executable(
reflect-cpp-json-tests
${SOURCES}
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/src/gtest_main.cc"
)

target_link_libraries(reflect-cpp-json-tests PRIVATE reflectcpp)
target_include_directories(reflect-cpp-json-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")

target_link_libraries(
reflect-cpp-json-tests
PRIVATE
reflectcpp
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libgtest.a"
)
6 changes: 1 addition & 5 deletions tests/json/test_all_of.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_all_of.hpp"

#include <iostream>
#include <rfl/json.hpp>
#include <source_location>
Expand All @@ -22,9 +20,7 @@ struct Person {
Age age;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_all_of) {
const auto homer =
Person{.first_name = "Homer", .last_name = "Simpson", .age = 45};

Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_all_of.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/json/test_alphanumeric_map.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_alphanumeric_map.hpp"

#include <iostream>
#include <map>
#include <memory>
Expand All @@ -12,9 +10,7 @@

namespace test_alphanumeric_map {

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_alphanumeric_map) {
std::map<rfl::AlphaNumeric, std::unique_ptr<std::string>> homer;
homer.insert(
std::make_pair("firstName", std::make_unique<std::string>("Homer")));
Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_alphanumeric_map.hpp

This file was deleted.

7 changes: 1 addition & 6 deletions tests/json/test_alphanumeric_unordered_map.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_alphanumeric_unordered_map.hpp"

#include <iostream>
#include <memory>
#include <rfl.hpp>
Expand All @@ -11,9 +9,7 @@
#include "write_and_read.hpp"

namespace test_alphanumeric_unordered_map {
void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_alphanumeric_unordered_map) {
using Map =
std::unordered_map<rfl::AlphaNumeric, std::unique_ptr<std::string>>;
Map homer;
Expand All @@ -26,6 +22,5 @@ void test() {
// compiles.
const auto json_string = rfl::json::write(homer);
const auto homer2 = rfl::json::read<Map>(json_string);
std::cout << "OK" << std::endl << std::endl;
}
} // namespace test_alphanumeric_unordered_map
4 changes: 0 additions & 4 deletions tests/json/test_alphanumeric_unordered_map.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/json/test_and_then.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <cassert>
#include <iostream>
#include <rfl.hpp>
#include <rfl/json.hpp>
Expand All @@ -7,7 +6,6 @@
#include <type_traits>
#include <vector>

#include "test_replace.hpp"
#include "write_and_read.hpp"

namespace test_and_then {
Expand All @@ -18,9 +16,7 @@ struct Person {
int age;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_and_then) {
const auto lisa =
Person{.first_name = "Lisa", .last_name = "Simpson", .age = 8};

Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_and_then.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/json/test_anonymous_fields.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_anonymous_fields.hpp"

#include <iostream>
#include <rfl.hpp>
#include <rfl/json.hpp>
Expand All @@ -23,9 +21,7 @@ struct Person {
std::vector<Person> children;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_anonymous_fields) {
const auto bart = Person{.first_name = "Bart",
.last_name = "Simpson",
.birthday = "1987-04-19",
Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_anonymous_fields.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/json/test_any_of.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_any_of.hpp"

#include <iostream>
#include <rfl.hpp>
#include <rfl/json.hpp>
Expand All @@ -22,9 +20,7 @@ struct Person {
Age age;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_any_of) {
const auto homer =
Person{.first_name = "Homer", .last_name = "Simpson", .age = 45};

Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_any_of.hpp

This file was deleted.

5 changes: 1 addition & 4 deletions tests/json/test_apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <type_traits>
#include <vector>

#include "test_replace.hpp"
#include "write_and_read.hpp"

namespace test_apply {
Expand All @@ -18,9 +17,7 @@ struct Person {
int age;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_apply) {
auto lisa = Person{.first_name = "Lisa", .last_name = "Simpson", .age = 8};

const auto view = rfl::to_view(lisa);
Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_apply.hpp

This file was deleted.

5 changes: 1 addition & 4 deletions tests/json/test_array.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include "test_array.hpp"

#include <array>
#include <iostream>
Expand All @@ -18,9 +17,7 @@ struct Person {
std::unique_ptr<std::array<Person, 3>> children = nullptr;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_array) {
auto bart = Person{.first_name = "Bart"};

auto lisa = Person{.first_name = "Lisa"};
Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_array.hpp

This file was deleted.

5 changes: 1 addition & 4 deletions tests/json/test_as.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_as.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -28,8 +26,7 @@ struct C {
rfl::Field<"f4", rfl::Box<std::string>> f4;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;
TEST(json, test_as) {

auto a = A{.f1 = "Hello", .f2 = rfl::make_box<std::string>("World")};

Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_as.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/json/test_as2.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_as2.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -28,9 +26,7 @@ struct C {
rfl::Box<std::string> f4;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_as2) {
auto a = A{.f1 = "Hello", .f2 = rfl::make_box<std::string>("World")};

auto b = B{.f3 = "Hello", .f4 = rfl::make_box<std::string>("World")};
Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_as2.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/json/test_as_flatten.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_as_flatten.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -28,9 +26,7 @@ struct C {
int f5;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_as_flatten) {
auto a = A{.f1 = "Hello", .f2 = rfl::make_box<std::string>("World")};

auto b = B{.f3 = "Hello", .f4 = rfl::make_box<std::string>("World")};
Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_as_flatten.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/json/test_box.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_box.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -30,9 +28,7 @@ struct DecisionTree {
rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_box) {
auto leaf1 = DecisionTree::Leaf{.value = 3.0};

auto leaf2 = DecisionTree::Leaf{.value = 5.0};
Expand Down
4 changes: 0 additions & 4 deletions tests/json/test_box.hpp

This file was deleted.

15 changes: 4 additions & 11 deletions tests/json/test_box2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@
#include <string>
#include <vector>

#include "test_box.hpp"
#include <gtest/gtest.h>

namespace test_box2 {

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_box2) {
auto ptr = std::make_unique<std::string>("Hello World!");
const rfl::Result<rfl::Box<std::string>> box =
rfl::make_box<std::string>(std::move(ptr));

if (box) {
std::cout << "OK" << std::endl << std::endl;
} else {
std::cout << "Expected the result to be successful." << std::endl
<< std::endl;
}
}
ASSERT_TRUE(box && true);
}
} // namespace test_box2
4 changes: 0 additions & 4 deletions tests/json/test_box2.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/json/test_c_array_class1.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_c_array_class1.hpp"

#include <iostream>
#include <source_location>
#include <string>
Expand All @@ -14,9 +12,7 @@ struct Test1 {
std::vector<std::string> classes[3];
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_c_array_class1) {
Test1 test1 = {.classes = {{"Little A", "Little B", "Little C"},
{"BIG A", "BIG B", "BIG C"},
{"??", "$%", "#@"}}};
Expand Down
5 changes: 0 additions & 5 deletions tests/json/test_c_array_class1.hpp

This file was deleted.

11 changes: 4 additions & 7 deletions tests/json/test_c_array_class2.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_c_array_class2.hpp"

#include <iostream>
#include <source_location>
#include <string>
Expand All @@ -15,12 +13,11 @@ struct Test2 {
std::string s;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(json, test_c_array_class2) {
Test2 test2;
for (int i = 0; i < 1 << 4; i++) {
test2.multi_dimension_arr[i >> 3 & 1][i >> 2 & 1][i >> 1 & 1][i >> 0 & 1] = i;
test2.multi_dimension_arr[i >> 3 & 1][i >> 2 & 1][i >> 1 & 1][i >> 0 & 1] =
i;
}
test2.s = "Hello, world!";

Expand All @@ -29,4 +26,4 @@ void test() {
R"({"multi_dimension_arr":[[[[0,1],[2,3]],[[4,5],[6,7]]],[[[8,9],[10,11]],[[12,13],[14,15]]]],"s":"Hello, world!"})");
}

} // namespace test_c_array
} // namespace test_c_array_class2
5 changes: 0 additions & 5 deletions tests/json/test_c_array_class2.hpp

This file was deleted.

0 comments on commit df04739

Please sign in to comment.