Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,18 @@ if (MSVC)
# mis-decoded, breaking the wstring/filepath round-trip tests. See PR #668.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++20 /utf-8")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall -Werror -ggdb -ftemplate-backtrace-limit=0")
# Leave optimization and debug-info flags to CMAKE_BUILD_TYPE / CMAKE_CXX_FLAGS_<CONFIG>.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -ftemplate-backtrace-limit=0")
endif()

if (CMAKE_UNITY_BUILD)
if (MSVC)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/bigobj>)
elseif (MINGW)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wa,-mbig-obj>)
endif ()
endif ()

if (REFLECTCPP_JSON)
add_subdirectory(generic)
add_subdirectory(json)
Expand Down
2 changes: 1 addition & 1 deletion tests/boost_serialization/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_executable(
reflect-cpp-boost-serialization-tests
${SOURCES}
)
target_precompile_headers(reflect-cpp-boost-serialization-tests PRIVATE [["rfl.hpp"]] <iostream> <string> <functional> <gtest/gtest.h>)
target_precompile_headers(reflect-cpp-boost-serialization-tests PRIVATE <gtest/gtest.h> <functional> <iostream> <optional> <string> <vector> [["rfl/boost_serialization.hpp"]])


target_link_libraries(reflect-cpp-boost-serialization-tests PRIVATE reflectcpp_tests_crt)
Expand Down
10 changes: 8 additions & 2 deletions tests/check_bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ template <std::size_t N, class Write, class Read, class NativeWrite,
void check_native(Write write, Read read, NativeWrite native_write,
NativeRead native_read) {
using Bits = std::bitset<N>;
std::vector<Bits> patterns{Bits{}, Bits{}.set()};
std::vector<Bits> patterns;
patterns.reserve(4 + N);
patterns.push_back(Bits{});
patterns.push_back(Bits{}.set());
for (std::size_t i = 0; i < N; ++i) patterns.push_back(Bits{}.set(i));
Bits alternating;
for (std::size_t i = 0; i < N; i += 2) alternating.set(i);
Expand Down Expand Up @@ -100,7 +103,10 @@ template <std::size_t N, class Write, class Read>
void check_size(Write write, Read read) {
SCOPED_TRACE(N);
using Bits = std::bitset<N>;
std::vector<Bits> patterns{Bits{}, Bits{}.set()};
std::vector<Bits> patterns;
patterns.reserve(4 + N);
patterns.push_back(Bits{});
patterns.push_back(Bits{}.set());
Bits alternating;
for (std::size_t i = 0; i < N; i += 2) alternating.set(i);
patterns.push_back(alternating);
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_executable(
reflect-cpp-cli-tests
${SOURCES}
)
target_precompile_headers(reflect-cpp-cli-tests PRIVATE [["rfl.hpp"]] <iostream> <string> <functional> <gtest/gtest.h>)
target_precompile_headers(reflect-cpp-cli-tests PRIVATE <gtest/gtest.h> <functional> <iostream> <optional> <string> <vector> [["rfl/cli.hpp"]])

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

Expand Down
2 changes: 1 addition & 1 deletion tests/env/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_executable(
reflect-cpp-env-tests
${SOURCES}
)
target_precompile_headers(reflect-cpp-env-tests PRIVATE [["rfl.hpp"]] <iostream> <string> <functional> <gtest/gtest.h>)
target_precompile_headers(reflect-cpp-env-tests PRIVATE <gtest/gtest.h> <functional> <iostream> <optional> <string> <vector> [["rfl/env.hpp"]] [["rfl/json.hpp"]])

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

Expand Down
13 changes: 13 additions & 0 deletions tests/generic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ add_executable(
${SOURCES}
)

# These files define RFL_ENUM_RANGE_MIN / RFL_ENUM_RANGE_MAX before #include <rfl.hpp>,
# so they must not receive a precompiled rfl.hpp or be merged into a unity batch.
set_source_files_properties(
"${CMAKE_CURRENT_SOURCE_DIR}/test_enum_range.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test_enum_range_min_max.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/test_enum_range_size.cpp"
PROPERTIES
SKIP_PRECOMPILE_HEADERS ON
SKIP_UNITY_BUILD_INCLUSION ON
)

target_precompile_headers(reflect-cpp-generic-tests PRIVATE <gtest/gtest.h> <functional> <iostream> <optional> <string> <vector> [["rfl/json.hpp"]])

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

target_link_libraries(reflect-cpp-generic-tests PRIVATE reflectcpp_tests_crt)
Expand Down
3 changes: 2 additions & 1 deletion tests/generic/test_wstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

#include "write_and_read.hpp"

namespace test_wstring {

struct TestStruct {
std::string theNormalString;
std::wstring theWiderString;
};

namespace test_wstring {
TEST(generic, test_wstring) {
const auto test = TestStruct{.theNormalString = "The normal string",
.theWiderString = L"The wider string"};
Expand Down
2 changes: 1 addition & 1 deletion tests/json/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_executable(
reflect-cpp-json-tests
${SOURCES}
)
target_precompile_headers(reflect-cpp-json-tests PRIVATE [["rfl.hpp"]] <iostream> <string> <functional> <gtest/gtest.h>)
target_precompile_headers(reflect-cpp-json-tests PRIVATE <gtest/gtest.h> <functional> <iostream> <optional> <string> <vector> [["rfl/json.hpp"]])

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

Expand Down
6 changes: 4 additions & 2 deletions tests/json/test_fail_fast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "../check_fail_fast.hpp"

namespace test_fail_fast_json {

TEST(json, test_fail_fast_round_trip) {
test_fail_fast::check_round_trip(
[](const auto& input) { return rfl::json::write(input); },
Expand All @@ -11,7 +13,6 @@ TEST(json, test_fail_fast_round_trip) {
});
}

namespace {
struct TwoFields {
int first;
int second;
Expand All @@ -36,7 +37,6 @@ struct OwningRecord {
int invalid;
Counted skipped;
};
} // namespace

TEST(json, test_fail_fast_first_error) {
const auto result = rfl::json::read<TwoFields, rfl::FailFast>(
Expand Down Expand Up @@ -142,3 +142,5 @@ TEST(json, test_fail_fast_named_tuple) {
EXPECT_EQ(result.error().what(),
"Failed to parse field 'first': Could not cast to int.");
}

} // namespace test_fail_fast_json
6 changes: 5 additions & 1 deletion tests/json/test_movable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "write_and_read.hpp"


namespace test_movable {

struct MoveableType {
int x;

Expand All @@ -23,4 +25,6 @@ TEST(json, test_moveable) {

write_and_read(
moveable, R"(2)");
}
}

} // namespace test_movable
12 changes: 8 additions & 4 deletions tests/json_c_arrays_and_inheritance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ add_executable(
reflect-cpp-json-c-arrays-and-inheritance-tests
${SOURCES}
)
target_precompile_headers(reflect-cpp-json-c-arrays-and-inheritance-tests PRIVATE [["rfl.hpp"]] <iostream> <string> <functional> <gtest/gtest.h>)


SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DREFLECT_CPP_C_ARRAYS_OR_INHERITANCE")
target_precompile_headers(reflect-cpp-json-c-arrays-and-inheritance-tests PRIVATE <gtest/gtest.h> <functional> <iostream> <optional> <string> <vector> [["rfl/json.hpp"]])

target_compile_definitions(reflect-cpp-json-c-arrays-and-inheritance-tests PRIVATE REFLECT_CPP_C_ARRAYS_OR_INHERITANCE)
if (NOT MSVC)
# C-array aggregate construction in move_from_tuple.hpp relies on brace elision,
# which triggers -Wmissing-braces under -Wall -Werror when PCH is disabled.
target_compile_options(reflect-cpp-json-c-arrays-and-inheritance-tests PRIVATE -Wno-missing-braces)
endif ()

target_include_directories(reflect-cpp-json-c-arrays-and-inheritance-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")

Expand Down
2 changes: 1 addition & 1 deletion tests/xml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ add_executable(
reflect-cpp-xml-tests
${SOURCES}
)
target_precompile_headers(reflect-cpp-xml-tests PRIVATE [["rfl.hpp"]] <iostream> <string> <functional> <gtest/gtest.h>)
target_precompile_headers(reflect-cpp-xml-tests PRIVATE <gtest/gtest.h> <functional> <iostream> <optional> <string> <vector> [["rfl/xml.hpp"]])

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

Expand Down
3 changes: 2 additions & 1 deletion tests/xml/test_wstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

#include "write_and_read.hpp"

namespace test_wstring {

struct TestStruct {
std::string theNormalString;
std::wstring theWiderString;
};

namespace test_wstring {
TEST(xml, test_wstring) {
const auto test = TestStruct{.theNormalString = "The normal string",
.theWiderString = L"The wider string"};
Expand Down
Loading