]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/test/test_tools.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / serialization / test / test_tools.hpp
1 #ifndef BOOST_SERIALIZATION_TEST_TOOLS_HPP
2 #define BOOST_SERIALIZATION_TEST_TOOLS_HPP
3
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER)
6 # pragma once
7 #endif
8
9 #define BOOST_FILESYSTEM_VERSION 3
10 #include <boost/filesystem/operations.hpp> // unique_path
11
12 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
13 // test_tools.hpp
14 //
15 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
16 // Use, modification and distribution is subject to the Boost Software
17 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
19
20 // See http://www.boost.org for updates, documentation, and revision history.
21
22 #include <boost/config.hpp>
23 #ifndef BOOST_NO_EXCEPTION_STD_NAMESPACE
24 #include <exception>
25 #endif
26 #include <boost/detail/no_exceptions_support.hpp>
27
28 #if defined(UNDER_CE)
29
30 // Windows CE does not supply the tmpnam function in its CRT.
31 // Substitute a primitive implementation here.
32 namespace boost {
33 namespace archive {
34 const char * tmpnam(char * buffer){
35 static char ibuffer [512];
36 if(NULL == buffer)
37 buffer = ibuffer;
38
39 static unsigned short index = 0;
40 std::sprintf(buffer, "\\tmpfile%05X.tmp", index++);
41 return buffer;
42 }
43 } // archive
44 } // boost
45
46 #elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
47 // win32 has a brain-dead tmpnam implementation.
48 // which leaves temp files in root directory
49 // regardless of environmental settings
50
51 #include <cstdlib>
52 #include <cstring>
53 #if defined(BOOST_NO_STDC_NAMESPACE)
54 namespace std{
55 using ::remove;
56 using ::strcpy;
57 using ::strcat;
58 using ::tmpnam;
59 }
60 #endif // defined(BOOST_NO_STDC_NAMESPACE)
61
62 #include <direct.h>
63 #include <boost/archive/tmpdir.hpp>
64
65 //#if defined(__COMO__)
66 #define chdir _chdir
67 //#endif // defined win32
68
69 #if defined(NDEBUG) && defined(__BORLANDC__)
70 #define STRCPY strcpy
71 #else
72 #define STRCPY std::strcpy
73 #endif
74
75 namespace boost {
76 namespace archive {
77 const char * test_filename(const char * dir = NULL, char *fname = NULL){
78 static char ibuffer [512];
79 ibuffer[0] = '\0';
80 if(NULL == dir){
81 dir = boost::archive::tmpdir();
82 }
83 STRCPY(ibuffer, dir);
84 std::strcat(ibuffer, "/");
85 if(NULL == fname){
86 char old_dir[256];
87 _getcwd(old_dir, sizeof(old_dir) - 1);
88 chdir(dir);
89 // (C) Copyright 2010 Dean Michael Berris. <mikhailberis@gmail.com>
90 // Instead of using std::tmpnam, we use Boost.Filesystem's unique_path
91 boost::filesystem::path tmp_path =
92 boost::filesystem::unique_path("%%%%%");
93 std::strcat(ibuffer, tmp_path.string().c_str());
94 chdir(old_dir);
95 }
96 else{
97 std::strcat(ibuffer, fname);
98 }
99 return ibuffer;
100 }
101 const char * tmpnam(char * buffer){
102 const char * name = test_filename(NULL, NULL);
103 if(NULL != buffer){
104 STRCPY(buffer, name);
105 }
106 return name;
107 }
108 } // archive
109 } // boost
110
111 #else // defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
112 #if defined(__hpux)
113 // (C) Copyright 2006 Boris Gubenko.
114 // HP-UX has a restriction that for multi-thread applications, (i.e.
115 // the ones compiled -mt) if argument to tmpnam is a NULL pointer, then,
116 // citing the tmpnam(3S) manpage, "the operation is not performed and a
117 // NULL pointer is returned". tempnam does not have this restriction, so,
118 // let's use tempnam instead.
119
120 #define tmpnam(X) tempnam(NULL,X)
121
122 namespace boost {
123 namespace archive {
124 using ::tmpnam;
125 } // archive
126 } // boost
127
128 #else // defined(__hpux)
129
130 // (C) Copyright 2010 Dean Michael Berris.
131 // Instead of using the potentially dangrous tempnam function that's part
132 // of the C standard library, on Unix/Linux we use the more portable and
133 // "safe" unique_path function provided in the Boost.Filesystem library.
134
135 #include <boost/archive/tmpdir.hpp>
136
137 namespace boost {
138 namespace archive {
139 char const * tmpnam(char * buffer) {
140 static char name[512] = {0};
141 if (name[0] == 0) {
142 boost::filesystem::path tempdir(tmpdir());
143 boost::filesystem::path tempfilename =
144 boost::filesystem::unique_path("serialization-%%%%");
145 boost::filesystem::path temp = tempdir / tempfilename;
146 std::strcat(name, temp.string().c_str());
147 }
148 if (buffer != 0) std::strcpy(buffer, name);
149 return name;
150 }
151 } // archive
152 } // boost
153
154 #endif // defined(__hpux)
155 #endif // defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
156
157 #include <boost/core/lightweight_test.hpp>
158
159 #define BOOST_CHECK( P ) \
160 BOOST_TEST( (P) )
161 #define BOOST_REQUIRE( P ) \
162 BOOST_TEST( (P) )
163 #define BOOST_CHECK_MESSAGE( P, M ) \
164 ((P)? (void)0 : ::boost::detail::error_impl( (M) , __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
165 #define BOOST_REQUIRE_MESSAGE( P, M ) \
166 BOOST_CHECK_MESSAGE( (P), (M) )
167 #define BOOST_CHECK_EQUAL( A , B ) \
168 BOOST_TEST( (A) == (B) )
169
170 namespace boost { namespace detail {
171 inline void msg_impl(char const * msg, char const * file, int line, char const * function)
172 {
173 std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl;
174 }
175 } } // boost::detail
176
177 #define BOOST_WARN_MESSAGE( P, M ) \
178 ((P)? (void)0 : ::boost::detail::msg_impl( (M) , __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
179 #define BOOST_MESSAGE( M ) \
180 BOOST_WARN_MESSAGE( true , (M) )
181
182 #define BOOST_CHECKPOINT( M ) \
183 BOOST_WARN_MESSAGE( true , (M) )
184
185 //#define BOOST_TEST_DONT_PRINT_LOG_VALUE( T )
186
187 #define BOOST_FAIL( M ) BOOST_REQUIRE_MESSAGE( false, (M) )
188 #define EXIT_SUCCESS 0
189
190 int test_main(int argc, char * argv[]);
191
192 #include <boost/serialization/singleton.hpp>
193
194 int
195 main(int argc, char * argv[]){
196 boost::serialization::singleton_module::lock();
197
198 int retval = 1;
199 BOOST_TRY{
200 retval = test_main(argc, argv);
201 }
202 #ifndef BOOST_NO_EXCEPTION_STD_NAMESPACE
203 BOOST_CATCH(const std::exception & e){
204 BOOST_ERROR(e.what());
205 }
206 #endif
207 BOOST_CATCH(...){
208 BOOST_ERROR("failed with uncaught exception:");
209 }
210 BOOST_CATCH_END
211
212 boost::serialization::singleton_module::unlock();
213
214 int error_count = boost::report_errors();
215 if(error_count > 0)
216 retval = error_count;
217 return retval;
218 }
219
220 // the following is to ensure that when one of the libraries changes
221 // BJAM rebuilds and relinks the test.
222 /*
223 #include "text_archive.hpp"
224 #include "text_warchive.hpp"
225 #include "binary_archive.hpp"
226 #include "xml_archive.hpp"
227 #include "xml_warchive.hpp"
228 */
229
230 /////////////////////////////////////////////
231 // invoke header for a custom archive test.
232
233 /////////////////////////////////////////////
234 // invoke header for a custom archive test.
235 #if ! defined(BOOST_ARCHIVE_TEST)
236 #define BOOST_ARCHIVE_TEST text_archive.hpp
237 #endif
238
239 #include <boost/preprocessor/stringize.hpp>
240 #include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
241
242 #ifndef TEST_STREAM_FLAGS
243 #define TEST_STREAM_FLAGS (std::ios_base::openmode)0
244 #endif
245
246 #ifndef TEST_ARCHIVE_FLAGS
247 #define TEST_ARCHIVE_FLAGS 0
248 #endif
249
250 #ifndef TEST_DIRECTORY
251 #define TEST_DIRECTORY
252 #else
253 #define __x__ TEST_DIRECTORY
254 #undef TEST_DIRECTORY
255 #define TEST_DIRECTORY BOOST_PP_STRINGIZE(__x__)
256 #endif
257
258 #endif // BOOST_SERIALIZATION_TEST_TOOLS_HPP