Skip to content

Commit 47b7f72

Browse files
committed
Add CMake tests
1 parent acc30bc commit 47b7f72

5 files changed

Lines changed: 100 additions & 0 deletions

File tree

test/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2018-2020, 2026 Peter Dimov
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# https://www.boost.org/LICENSE_1_0.txt
4+
5+
include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
6+
7+
if(NOT HAVE_BOOST_TEST)
8+
return()
9+
endif()
10+
11+
set(BOOST_TEST_LINK_LIBRARIES Boost::serialization Boost::core)
12+
13+
boost_test(SOURCES quick.cpp)

test/Jamfile.v2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,6 @@ if ! $(BOOST_ARCHIVE_LIST) {
188188
[ compile test_const_pass.cpp ]
189189
;
190190
}
191+
192+
run quick.cpp
193+
: : : <library>/boost/serialization//boost_serialization ;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2018, 2019 Peter Dimov
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
4+
5+
cmake_minimum_required(VERSION 3.5...3.31)
6+
7+
project(cmake_install_test LANGUAGES CXX)
8+
9+
find_package(Boost REQUIRED COMPONENTS serialization core)
10+
11+
add_executable(quick ../quick.cpp)
12+
target_link_libraries(quick Boost::serialization Boost::core)
13+
14+
enable_testing()
15+
add_test(quick quick)
16+
17+
add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2018, 2019 Peter Dimov
2+
# Distributed under the Boost Software License, Version 1.0.
3+
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
4+
5+
cmake_minimum_required(VERSION 3.5...3.31)
6+
7+
project(cmake_subdir_test LANGUAGES CXX)
8+
9+
set(BOOST_INCLUDE_LIBRARIES serialization core)
10+
add_subdirectory(../../../.. boostorg/boost)
11+
12+
add_executable(quick ../quick.cpp)
13+
target_link_libraries(quick Boost::serialization Boost::core)
14+
15+
enable_testing()
16+
add_test(quick quick)
17+
18+
add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

test/quick.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2026 Peter Dimov
2+
// Distributed under the Boost Software License, Version 1.0.
3+
// https://www.boost.org/LICENSE_1_0.txt
4+
5+
struct A
6+
{
7+
int x, y;
8+
9+
template<class Ar> void serialize( Ar& ar, unsigned /*version*/ )
10+
{
11+
ar & x;
12+
ar & y;
13+
}
14+
};
15+
16+
#include <boost/archive/text_iarchive.hpp>
17+
#include <boost/archive/text_oarchive.hpp>
18+
#include <boost/core/lightweight_test.hpp>
19+
#include <sstream>
20+
21+
int main()
22+
{
23+
std::string tmp;
24+
25+
{
26+
A a = { 1, 2 };
27+
28+
std::ostringstream os;
29+
boost::archive::text_oarchive oa( os );
30+
31+
oa << a;
32+
33+
tmp = os.str();
34+
}
35+
36+
{
37+
A a = {};
38+
39+
std::istringstream is( tmp );
40+
boost::archive::text_iarchive ia( is );
41+
42+
ia >> a;
43+
44+
BOOST_TEST_EQ( a.x, 1 );
45+
BOOST_TEST_EQ( a.y, 2 );
46+
}
47+
48+
return boost::report_errors();
49+
}

0 commit comments

Comments
 (0)