mirror of
https://github.com/fraillt/bitsery.git
synced 2026-06-08 08:13:56 +00:00
Additional improvements for v5.2.2 release
* migration to github actions * additionally build tests/examples on windows and macos
This commit is contained in:
@@ -20,8 +20,9 @@
|
||||
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
#SOFTWARE.
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(bitsery_tests CXX)
|
||||
cmake_minimum_required(VERSION 3.11)
|
||||
project(bitsery_tests
|
||||
LANGUAGES CXX)
|
||||
|
||||
find_package(GTest 1.10 REQUIRED)
|
||||
|
||||
@@ -62,31 +63,40 @@ if (ParentDir)
|
||||
# add headers so IDE correctly show them
|
||||
target_sources(bitsery.dummy_for_ide PRIVATE ${HeadersForIDE} serialization_test_utils.h)
|
||||
target_link_libraries(bitsery.dummy_for_ide PRIVATE GTest::Main Bitsery::bitsery)
|
||||
|
||||
# creates a "check_includes" target to verify if all headers has required includes
|
||||
# to simplify things a little bit, it only works with modern compiler (C++17)
|
||||
# as some bitsery extensions require C++17 compliant compiler.
|
||||
if("cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
|
||||
add_library(check_includes OBJECT)
|
||||
target_compile_features(check_includes PRIVATE cxx_std_17)
|
||||
file(WRITE ${CMAKE_BINARY_DIR}/check_includes.in "
|
||||
// generated by CMake to verify header includes.
|
||||
// we need exactly 201703L, because some compilers with experimental C++17 support
|
||||
// provides bigger number than 201402L (C++14) but doesn't actually has enough
|
||||
// functionality to build these files
|
||||
#if __cplusplus >= 201703L
|
||||
#include \"@HeaderFile@\"
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma message(\"/Zc:__cplusplus option is required to enable check_includes\")
|
||||
#else
|
||||
#define XSTR(x) STR(x)
|
||||
#define STR(x) #x
|
||||
#pragma message (\"`__cplusplus` macro value should be 201703L or greater, actual value is: \" XSTR(__cplusplus))
|
||||
#endif
|
||||
")
|
||||
|
||||
file(GLOB_RECURSE HeaderFiles "${ParentDir}/include/bitsery/*.h")
|
||||
foreach (HeaderFile ${HeaderFiles})
|
||||
SET(CHK_TARGET_NAME "chk_inc_${HeaderFile}")
|
||||
STRING(REPLACE "${ParentDir}/include/bitsery/" "" CHK_TARGET_NAME ${CHK_TARGET_NAME})
|
||||
STRING(REGEX REPLACE "/" "_" CHK_TARGET_NAME ${CHK_TARGET_NAME})
|
||||
STRING(REGEX REPLACE "\\\\" "_" CHK_TARGET_NAME ${CHK_TARGET_NAME})
|
||||
configure_file(${CMAKE_BINARY_DIR}/check_includes.in "${CHK_TARGET_NAME}.cpp")
|
||||
target_sources(check_includes PRIVATE "${CHK_TARGET_NAME}.cpp")
|
||||
endforeach ()
|
||||
else()
|
||||
message(WARNING "`check_includes` target will be disabled, as it require compiler with C++17 support.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Check missing includes for each header file in include/bitsery
|
||||
# We compile each header files individually to check if each header contains all required includes
|
||||
# Code adopted from `https://stackoverflow.com/questions/57885042`
|
||||
# Usage:
|
||||
# run from repo root directory
|
||||
# > mkdir -p build && cd build
|
||||
# > cmake -D BITSERY_BUILD_TESTS=1 ..
|
||||
# > make check_includes
|
||||
add_custom_target(check_includes)
|
||||
get_directory_property(ParentDir PARENT_DIRECTORY)
|
||||
if (ParentDir)
|
||||
message("add header include test, run test with 'make check_includes'")
|
||||
file(GLOB_RECURSE HeaderFiles "${ParentDir}/include/bitsery/*.h")
|
||||
FOREACH (HeaderFile ${HeaderFiles})
|
||||
SET(CHK_TARGET_NAME "${HeaderFile}.chk")
|
||||
STRING(REPLACE "${ParentDir}/include/bitsery/" "" CHK_TARGET_NAME ${CHK_TARGET_NAME})
|
||||
STRING(REGEX REPLACE "/" "_" CHK_TARGET_NAME ${CHK_TARGET_NAME})
|
||||
STRING(REGEX REPLACE "\\\\" "_" CHK_TARGET_NAME ${CHK_TARGET_NAME})
|
||||
add_custom_target(
|
||||
${CHK_TARGET_NAME}
|
||||
COMMAND ${CMAKE_CXX_COMPILER} -c ${HeaderFile}
|
||||
VERBATIM
|
||||
)
|
||||
add_dependencies(check_includes ${CHK_TARGET_NAME})
|
||||
ENDFOREACH ()
|
||||
endif()
|
||||
|
||||
@@ -39,12 +39,10 @@
|
||||
#if __cplusplus > 201402L
|
||||
#include <bitsery/brief_syntax/tuple.h>
|
||||
#include <bitsery/brief_syntax/variant.h>
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma message("C++17 and /Zc:__cplusplus option is required to enable std::tuple and std::variant brief syntax tests")
|
||||
#else
|
||||
/*#if defined(_MSC_VER)
|
||||
#pragma message("tuple and variant only works with c++17")
|
||||
#else
|
||||
#warning "tuple and variant only works with c++17"
|
||||
#endif*/
|
||||
#pragma message("C++17 is required to enable std::tuple and std::variant brief syntax tests")
|
||||
#endif
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
@@ -41,7 +41,7 @@ TEST(SerializationContext, WhenContextIsNotTupleThenReturnThisContext) {
|
||||
|
||||
TEST(SerializationContext, WhenContextIsTupleThenReturnsTupleElements) {
|
||||
|
||||
MultipleTypesContext ctx{5, 798.654, 'F'};
|
||||
MultipleTypesContext ctx{5, 798.654f, 'F'};
|
||||
BasicSerializationContext<MultipleTypesContext> c1;
|
||||
auto& ser1 = c1.createSerializer(ctx);
|
||||
|
||||
@@ -59,7 +59,7 @@ TEST(SerializationContext, WhenContextDoesntExistsThenContextOrNullReturnsNull)
|
||||
*ser.contextOrNull<int>() = 2;
|
||||
EXPECT_THAT(ctx1, Eq(2));
|
||||
|
||||
MultipleTypesContext ctx2{5, 798.654, 'F'};
|
||||
MultipleTypesContext ctx2{5, 798.654f, 'F'};
|
||||
BasicSerializationContext<MultipleTypesContext> c2;
|
||||
auto& des = c2.createDeserializer(ctx2);
|
||||
EXPECT_THAT(des.contextOrNull<double>(), ::testing::IsNull());
|
||||
@@ -105,4 +105,4 @@ TEST(SerializationContext, WhenMultipleConvertibleTypesExistsThenFirstMatchIsTak
|
||||
//Base will not be accessable in this case, because Derived is first valid match
|
||||
EXPECT_THAT(des.context<Base>().value, Eq(std::get<1>(ctx2).value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,10 +120,8 @@ TEST(SerializeExtensionStdOptional, NoAlignAfterStateWriteRead) {
|
||||
EXPECT_THAT(t1.value(), Eq(r1.value()));
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma message("C++17 and /Zc:__cplusplus option is required to enable std::optional tests")
|
||||
#else
|
||||
/*#if defined(_MSC_VER)
|
||||
#pragma message("Tests for StdOptional requires C++17")
|
||||
#else
|
||||
#warning "Tests for StdOptional requires C++17"
|
||||
#endif*/
|
||||
#pragma message("C++17 is required to enable std::optional tests")
|
||||
#endif
|
||||
|
||||
@@ -102,8 +102,8 @@ private:
|
||||
};
|
||||
|
||||
TEST(SerializeExtensionStdTuple, NonDefaultConstructable) {
|
||||
std::tuple<NonDefaultConstructable> t1{34};
|
||||
std::tuple<NonDefaultConstructable> r1{8};
|
||||
std::tuple<NonDefaultConstructable> t1{34.0f};
|
||||
std::tuple<NonDefaultConstructable> r1{8.0f};
|
||||
SerializationContext ctx;
|
||||
ctx.createSerializer().ext(t1, bitsery::ext::StdTuple{
|
||||
[](auto& s, NonDefaultConstructable& v) {
|
||||
@@ -118,10 +118,8 @@ TEST(SerializeExtensionStdTuple, NonDefaultConstructable) {
|
||||
EXPECT_THAT(t1, Eq(r1));
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma message("C++17 and /Zc:__cplusplus option is required to enable std::tuple tests")
|
||||
#else
|
||||
/*#if defined(_MSC_VER)
|
||||
#pragma message("Tests for StdTuple requires C++17")
|
||||
#else
|
||||
#warning "Tests for StdTuple requires C++17"
|
||||
#endif*/
|
||||
#endif
|
||||
#pragma message("C++17 is required to enable std::tuple tests")
|
||||
#endif
|
||||
|
||||
@@ -167,10 +167,8 @@ TEST(SerializeExtensionStdVariant, CorrectlyHandleMonoState) {
|
||||
|
||||
}
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma message("C++17 and /Zc:__cplusplus option is required to enable std::variant tests")
|
||||
#else
|
||||
/*#if defined(_MSC_VER)
|
||||
#pragma message("Tests for StdVariant requires C++17")
|
||||
#else
|
||||
#warning "Tests for StdVariant requires C++17"
|
||||
#endif*/
|
||||
#pragma message("C++17 is required to enable std::variant tests")
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user