Skip to content

Commit

Permalink
Using GTest for testing msgpack
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Apr 22, 2024
1 parent 5a40b9f commit 7aa7b0f
Show file tree
Hide file tree
Showing 69 changed files with 59 additions and 396 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ if (REFLECTCPP_BUILD_TESTS)
add_subdirectory(tests)
endif ()


include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

Expand Down
16 changes: 13 additions & 3 deletions tests/msgpack/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
project(reflect-cpp-msgpack-tests)

file(GLOB_RECURSE SOURCES "*.cpp")
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp")

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

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

target_link_libraries(
reflect-cpp-msgpack-tests
PRIVATE
reflectcpp
"${REFLECT_CPP_GTEST_LIB}"
)
6 changes: 1 addition & 5 deletions tests/msgpack/test_array.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_array.hpp"

#include <array>
#include <iostream>
#include <memory>
Expand All @@ -21,9 +19,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(msgpack, test_array) {
auto bart = Person{.first_name = "Bart"};

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

This file was deleted.

6 changes: 1 addition & 5 deletions tests/msgpack/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 @@ -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(msgpack, 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/msgpack/test_box.hpp

This file was deleted.

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

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -31,9 +29,7 @@ struct Person {
PersonImpl impl;
};

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

TEST(msgpack, test_custom_class1) {
const auto bart = Person("Bart");

write_and_read(bart);
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_custom_class1.hpp

This file was deleted.

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

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -56,9 +54,7 @@ struct Parser<ReaderType, WriterType, test_custom_class3::Person>

namespace test_custom_class3 {

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

TEST(msgpack, test_custom_class3) {
const auto bart = Person("Bart", "Simpson", 10);

write_and_read(bart);
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_custom_class3.hpp

This file was deleted.

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

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -57,9 +55,7 @@ struct Parser<ReaderType, WriterType, test_custom_class4::Person>

namespace test_custom_class4 {

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

TEST(msgpack, test_custom_class4) {
const auto bart = test_custom_class4::Person(
"Bart", rfl::make_box<std::string>("Simpson"), 10);

Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_custom_class4.hpp

This file was deleted.

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

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand All @@ -17,9 +15,7 @@ struct Person {
std::vector<Person> children;
};

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

TEST(msgpack, test_default_values) {
const auto bart = Person{.first_name = "Bart"};
const auto lisa = Person{.first_name = "Lisa"};
const auto maggie = Person{.first_name = "Maggie"};
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_default_values.hpp

This file was deleted.

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

#include <iostream>
#include <rfl.hpp>
#include <source_location>
Expand All @@ -16,9 +14,7 @@ struct Person {
std::unique_ptr<std::deque<Person>> children;
};

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

TEST(msgpack, test_default_values) {
auto children = std::make_unique<std::deque<Person>>();
children->emplace_back(Person{.first_name = "Bart"});
children->emplace_back(Person{.first_name = "Lisa"});
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_deque.hpp

This file was deleted.

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

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand All @@ -18,9 +16,7 @@ struct Circle {
Color color;
};

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

TEST(msgpack, test_enum) {
const auto circle = Circle{.radius = 2.0, .color = Color::green};

write_and_read(circle);
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_enum.hpp

This file was deleted.

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

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -28,9 +26,7 @@ using Shapes = rfl::Variant<rfl::Field<"circle", Circle>,
rfl::Field<"rectangle", Rectangle>,
rfl::Field<"square", rfl::Box<Square>>>;

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

TEST(msgpack, test_field_variant) {
const Shapes r =
rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5});

Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_field_variant.hpp

This file was deleted.

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

#include "test_enum.hpp"
#include "write_and_read.hpp"

namespace test_flag_enum {
Expand All @@ -27,9 +26,7 @@ struct Circle {
Color color;
};

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

TEST(msgpack, test_flag_enum) {
const auto circle =
Circle{.radius = 2.0, .color = Color::blue | Color::orange};

Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_flag_enum.hpp

This file was deleted.

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

#include "test_enum.hpp"
#include "write_and_read.hpp"

namespace test_flag_enum_with_int {
Expand All @@ -27,9 +26,7 @@ struct Circle {
Color color;
};

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

TEST(msgpack, test_flag_enum_with_int) {
const auto circle = Circle{.radius = 2.0, .color = static_cast<Color>(10000)};

write_and_read(circle);
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_flag_enum_with_int.hpp

This file was deleted.

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

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand All @@ -23,9 +21,7 @@ struct Employee {
rfl::Field<"salary", float> salary;
};

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

TEST(msgpack, test_flatten) {
const auto employee = Employee{
.person = Person{.first_name = "Homer",
.last_name = rfl::make_box<std::string>("Simpson"),
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_flatten.hpp

This file was deleted.

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

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand All @@ -23,9 +21,7 @@ struct Employee {
float salary;
};

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

TEST(msgpack, test_flatten_anonymous) {
const auto employee = Employee{
.person = Person{.first_name = "Homer",
.last_name = rfl::make_box<std::string>("Simpson"),
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_flatten_anonymous.hpp

This file was deleted.

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

#include <iostream>
#include <rfl.hpp>
#include <source_location>
Expand All @@ -16,9 +14,7 @@ struct Person {
std::unique_ptr<std::forward_list<Person>> children;
};

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

TEST(msgpack, test_forward_list) {
auto children = std::make_unique<std::forward_list<Person>>();
children->emplace_front(Person{.first_name = "Maggie"});
children->emplace_front(Person{.first_name = "Lisa"});
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_forward_list.hpp

This file was deleted.

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

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand All @@ -20,9 +18,7 @@ struct Person {
std::vector<Person> children;
};

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

TEST(msgpack, test_literal) {
const auto bart = Person{.first_name = FirstName::make<"Bart">()};

write_and_read(bart);
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_literal.hpp

This file was deleted.

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

#include <iostream>
#include <map>
#include <memory>
Expand All @@ -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(msgpack, test_literal_map) {
std::map<FieldName, std::unique_ptr<std::string>> homer;
homer.insert(std::make_pair(FieldName::make<"firstName">(),
std::make_unique<std::string>("Homer")));
Expand Down
4 changes: 0 additions & 4 deletions tests/msgpack/test_literal_map.hpp

This file was deleted.

Loading

0 comments on commit 7aa7b0f

Please sign in to comment.