• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/core/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 {
tmpnam(char * buffer)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 #if !defined(BOOST_EMBTC)
67     #define chdir _chdir
68 #endif
69 //#endif  // defined win32
70 
71 #if defined(NDEBUG) && defined(BOOST_BORLANDC)
72     #define STRCPY strcpy
73 #else
74     #define STRCPY std::strcpy
75 #endif
76 
77 namespace boost {
78 namespace archive {
test_filename(const char * dir=NULL,char * fname=NULL)79     const char * test_filename(const char * dir = NULL, char *fname = NULL){
80         static char ibuffer [512];
81         ibuffer[0] = '\0';
82         if(NULL == dir){
83             dir = boost::archive::tmpdir();
84         }
85         STRCPY(ibuffer, dir);
86         std::strcat(ibuffer, "/");
87         if(NULL == fname){
88             char old_dir[256];
89             _getcwd(old_dir, sizeof(old_dir) - 1);
90             chdir(dir);
91             // (C) Copyright 2010 Dean Michael Berris. <mikhailberis@gmail.com>
92             // Instead of using std::tmpnam, we use Boost.Filesystem's unique_path
93             boost::filesystem::path tmp_path =
94                 boost::filesystem::unique_path("%%%%%");
95             std::strcat(ibuffer, tmp_path.string().c_str());
96             chdir(old_dir);
97         }
98         else{
99             std::strcat(ibuffer, fname);
100         }
101         return ibuffer;
102     }
tmpnam(char * buffer)103     const char * tmpnam(char * buffer){
104         const char * name = test_filename(NULL, NULL);
105         if(NULL != buffer){
106             STRCPY(buffer, name);
107         }
108         return name;
109     }
110 } // archive
111 } // boost
112 
113 #else // defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
114 #if defined(__hpux)
115 // (C) Copyright 2006 Boris Gubenko.
116 // HP-UX has a restriction that for multi-thread applications, (i.e.
117 // the ones compiled -mt) if argument to tmpnam is a NULL pointer, then,
118 // citing the tmpnam(3S) manpage, "the operation is not performed and a
119 // NULL pointer is returned". tempnam does not have this restriction, so,
120 // let's use tempnam instead.
121 
122 #define tmpnam(X) tempnam(NULL,X)
123 
124 namespace boost {
125 namespace archive {
126     using ::tmpnam;
127 } // archive
128 } // boost
129 
130 #else // defined(__hpux)
131 
132 // (C) Copyright 2010 Dean Michael Berris.
133 // Instead of using the potentially dangrous tempnam function that's part
134 // of the C standard library, on Unix/Linux we use the more portable and
135 // "safe" unique_path function provided in the Boost.Filesystem library.
136 
137 #include <boost/archive/tmpdir.hpp>
138 
139 namespace boost {
140 namespace archive {
tmpnam(char * buffer)141     char const * tmpnam(char * buffer) {
142         static char name[512] = {0};
143         if (name[0] == 0) {
144             boost::filesystem::path tempdir(tmpdir());
145             boost::filesystem::path tempfilename =
146                 boost::filesystem::unique_path("serialization-%%%%");
147             boost::filesystem::path temp = tempdir / tempfilename;
148             std::strcat(name, temp.string().c_str());
149         }
150         if (buffer != 0) std::strcpy(buffer, name);
151         return name;
152     }
153 } // archive
154 } // boost
155 
156 #endif // defined(__hpux)
157 #endif // defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
158 
159 #include <boost/core/lightweight_test.hpp>
160 
161 #define BOOST_CHECK( P ) \
162     BOOST_TEST( (P) )
163 #define BOOST_REQUIRE( P )  \
164     BOOST_TEST( (P) )
165 #define BOOST_CHECK_MESSAGE( P, M )  \
166     ((P)? (void)0 : ::boost::detail::error_impl( (M) , __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
167 #define BOOST_REQUIRE_MESSAGE( P, M ) \
168     BOOST_CHECK_MESSAGE( (P), (M) )
169 #define BOOST_CHECK_EQUAL( A , B ) \
170     BOOST_TEST( (A) == (B) )
171 
172 namespace boost { namespace detail {
msg_impl(char const * msg,char const * file,int line,char const * function)173 inline void msg_impl(char const * msg, char const * file, int line, char const * function)
174 {
175     std::cerr << file << "(" << line << "): " << msg << " in function '" << function << "'" << std::endl;
176 }
177 } } // boost::detail
178 
179 #define BOOST_WARN_MESSAGE( P, M )  \
180     ((P)? (void)0 : ::boost::detail::msg_impl( (M) , __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
181 #define BOOST_MESSAGE( M ) \
182     BOOST_WARN_MESSAGE( true , (M) )
183 
184 #define BOOST_CHECKPOINT( M ) \
185     BOOST_WARN_MESSAGE( true , (M) )
186 
187 //#define BOOST_TEST_DONT_PRINT_LOG_VALUE( T )
188 
189 #define BOOST_FAIL( M ) BOOST_REQUIRE_MESSAGE( false, (M) )
190 #define EXIT_SUCCESS 0
191 
192 int test_main(int argc, char * argv[]);
193 
194 #include <boost/serialization/singleton.hpp>
195 
196 int
main(int argc,char * argv[])197 main(int argc, char * argv[]){
198     boost::serialization::get_singleton_module().lock();
199 
200     int retval = 1;
201     BOOST_TRY{
202         retval = test_main(argc, argv);
203     }
204     #ifndef BOOST_NO_EXCEPTION_STD_NAMESPACE
205         BOOST_CATCH(const std::exception & e){
206             BOOST_ERROR(e.what());
207         }
208     #endif
209     BOOST_CATCH(...){
210         BOOST_ERROR("failed with uncaught exception:");
211     }
212     BOOST_CATCH_END
213 
214     boost::serialization::get_singleton_module().unlock();
215 
216     int error_count = boost::report_errors();
217     if(error_count > 0)
218         retval = error_count;
219     return retval;
220 }
221 
222 // the following is to ensure that when one of the libraries changes
223 // BJAM rebuilds and relinks the test.
224 /*
225 #include "text_archive.hpp"
226 #include "text_warchive.hpp"
227 #include "binary_archive.hpp"
228 #include "xml_archive.hpp"
229 #include "xml_warchive.hpp"
230 
231 #include "polymorphic_text_archive.hpp"
232 #include "polymorphic_text_warchive.hpp"
233 #include "polymorphic_binary_archive.hpp"
234 #include "polymorphic_xml_archive.hpp"
235 #include "polymorphic_xml_warchive.hpp"
236 */
237 
238 /////////////////////////////////////////////
239 // invoke header for a custom archive test.
240 
241 /////////////////////////////////////////////
242 // invoke header for a custom archive test.
243 #if ! defined(BOOST_ARCHIVE_TEST)
244 #define BOOST_ARCHIVE_TEST text_archive.hpp
245 #endif
246 
247 #include <boost/preprocessor/stringize.hpp>
248 #include BOOST_PP_STRINGIZE(BOOST_ARCHIVE_TEST)
249 
250 #ifndef TEST_STREAM_FLAGS
251     #define TEST_STREAM_FLAGS (std::ios_base::openmode)0
252 #endif
253 
254 #ifndef TEST_ARCHIVE_FLAGS
255     #define TEST_ARCHIVE_FLAGS 0
256 #endif
257 
258 #ifndef TEST_DIRECTORY
259 #define TEST_DIRECTORY
260 #else
261 #define __x__ TEST_DIRECTORY
262 #undef TEST_DIRECTORY
263 #define TEST_DIRECTORY BOOST_PP_STRINGIZE(__x__)
264 #endif
265 
266 #endif // BOOST_SERIALIZATION_TEST_TOOLS_HPP
267