1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
2 // test_dll_simple.cpp
3 
4 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
5 // Use, modification and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 
9 // should pass compilation and execution
10 
11 // invoke header for a custom archive test.
12 
13 #include <cstddef> // NULL
14 #include <fstream>
15 
16 #include <cstdio> // remove
17 #include <boost/config.hpp>
18 
19 #if defined(BOOST_NO_STDC_NAMESPACE)
20 namespace std{
21     using ::remove;
22 }
23 #endif
24 
25 // for now, only test with simple text and polymorphic archive
26 #include "test_tools.hpp"
27 #include "text_archive.hpp"
28 
29 #include <boost/archive/polymorphic_text_oarchive.hpp>
30 #include <boost/archive/polymorphic_text_iarchive.hpp>
31 
32 #define A_IMPORT
33 #include "A.hpp"
34 
35 // simple class with text archive compiled in dll
36 void
test1()37 test1(){
38     const char * testfile = boost::archive::tmpnam(NULL);
39     BOOST_REQUIRE(NULL != testfile);
40 
41     const A a;
42     A a1;
43     {
44         test_ostream os(testfile, TEST_STREAM_FLAGS);
45         boost::archive::text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
46         oa << boost::serialization::make_nvp("a", a);
47     }
48     {
49         test_istream is(testfile, TEST_STREAM_FLAGS);
50         boost::archive::text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
51         ia >> boost::serialization::make_nvp("a", a1);
52     }
53     BOOST_CHECK_EQUAL(a, a1);
54 
55     std::remove(testfile);
56 }
57 
58 // simple class with polymorphic archive compiled in dll
59 void
test2()60 test2(){
61     const char * testfile = boost::archive::tmpnam(NULL);
62     BOOST_REQUIRE(NULL != testfile);
63 
64     const A a;
65     A a1;
66     {
67         test_ostream os(testfile, TEST_STREAM_FLAGS);
68         boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
69         boost::archive::polymorphic_oarchive & poa(oa);
70         poa << boost::serialization::make_nvp("a", a);
71     }
72     {
73         test_istream is(testfile, TEST_STREAM_FLAGS);
74         boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
75         boost::archive::polymorphic_iarchive & pia(ia);
76         pia >> boost::serialization::make_nvp("a", a1);
77     }
78     BOOST_CHECK_EQUAL(a, a1);
79 
80     std::remove(testfile);
81 }
82 
83 // simple class pointer with text archive compiled in dll
84 void
test3()85 test3(){
86     const char * testfile = boost::archive::tmpnam(NULL);
87     BOOST_REQUIRE(NULL != testfile);
88 
89     const A *a = new A;
90     A *a1;
91     {
92         test_ostream os(testfile, TEST_STREAM_FLAGS);
93         boost::archive::text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
94         oa << boost::serialization::make_nvp("a", a);
95     }
96     {
97         test_istream is(testfile, TEST_STREAM_FLAGS);
98         boost::archive::text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
99         ia >> boost::serialization::make_nvp("a", a1);
100     }
101     BOOST_CHECK_EQUAL(*a, *a1);
102 
103     std::remove(testfile);
104     delete a;
105 }
106 
107 // simple class pointer with polymorphic archive compiled in dll
108 void
test4()109 test4(){
110     const char * testfile = boost::archive::tmpnam(NULL);
111     BOOST_REQUIRE(NULL != testfile);
112 
113     const A *a = new A;
114     A *a1;
115     {
116         test_ostream os(testfile, TEST_STREAM_FLAGS);
117         boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
118         boost::archive::polymorphic_oarchive & poa(oa);
119         poa << boost::serialization::make_nvp("a", a);
120     }
121     {
122         test_istream is(testfile, TEST_STREAM_FLAGS);
123         boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
124         boost::archive::polymorphic_iarchive & pia(ia);
125         pia >> boost::serialization::make_nvp("a", a1);
126     }
127     BOOST_CHECK_EQUAL(*a, *a1);
128 
129     std::remove(testfile);
130     delete a;
131 }
132 
133 #include "B.hpp"
134 
135 // derived class with base text archive compiled in dll
136 void
test5()137 test5(){
138     const char * testfile = boost::archive::tmpnam(NULL);
139     BOOST_REQUIRE(NULL != testfile);
140 
141     const B b;
142     B b1;
143     {
144         test_ostream os(testfile, TEST_STREAM_FLAGS);
145         boost::archive::text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
146         oa << boost::serialization::make_nvp("b", b);
147     }
148     {
149         test_istream is(testfile, TEST_STREAM_FLAGS);
150         boost::archive::text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
151         ia >> boost::serialization::make_nvp("b", b1);
152     }
153     BOOST_CHECK_EQUAL(b, b1);
154 
155     std::remove(testfile);
156 }
157 
158 // derived class with base base compiled with polymorphic archive in dll
159 void
test6()160 test6(){
161     const char * testfile = boost::archive::tmpnam(NULL);
162     BOOST_REQUIRE(NULL != testfile);
163 
164     const B b;
165     B b1;
166     {
167         test_ostream os(testfile, TEST_STREAM_FLAGS);
168         boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
169         boost::archive::polymorphic_oarchive & poa(oa);
170         poa << boost::serialization::make_nvp("b", b);
171     }
172     {
173         test_istream is(testfile, TEST_STREAM_FLAGS);
174         boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
175         boost::archive::polymorphic_iarchive & pia(ia);
176         pia >> boost::serialization::make_nvp("b", b1);
177     }
178     BOOST_CHECK_EQUAL(b, b1);
179 
180     std::remove(testfile);
181 }
182 
183 // derived class pointer with base text archive compiled in dll
184 void
test7()185 test7(){
186     const char * testfile = boost::archive::tmpnam(NULL);
187     BOOST_REQUIRE(NULL != testfile);
188 
189     const B *b = new B;
190     B *b1;
191     {
192         test_ostream os(testfile, TEST_STREAM_FLAGS);
193         boost::archive::text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
194         oa << boost::serialization::make_nvp("b", b);
195     }
196     {
197         test_istream is(testfile, TEST_STREAM_FLAGS);
198         boost::archive::text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
199         ia >> boost::serialization::make_nvp("b", b1);
200     }
201     BOOST_CHECK_EQUAL(*b, *b1);
202 
203     std::remove(testfile);
204     delete b;
205 }
206 
207 // derived class pointer with base polymorphic archive compiled in dll
208 void
test8()209 test8(){
210     const char * testfile = boost::archive::tmpnam(NULL);
211     BOOST_REQUIRE(NULL != testfile);
212 
213     const B *b = new B;
214     B *b1;
215     {
216         test_ostream os(testfile, TEST_STREAM_FLAGS);
217         boost::archive::polymorphic_text_oarchive oa(os, TEST_ARCHIVE_FLAGS);
218         boost::archive::polymorphic_oarchive & poa(oa);
219         poa << boost::serialization::make_nvp("b", b);
220     }
221     {
222         test_istream is(testfile, TEST_STREAM_FLAGS);
223         boost::archive::polymorphic_text_iarchive ia(is, TEST_ARCHIVE_FLAGS);
224         boost::archive::polymorphic_iarchive & pia(ia);
225         pia >> boost::serialization::make_nvp("b", b1);
226     }
227     BOOST_CHECK_EQUAL(*b, *b1);
228 
229     std::remove(testfile);
230     delete b;
231 }
232 
233 
234 int
test_main(int,char * [])235 test_main( int /* argc */, char* /* argv */[] )
236 {
237     test1();
238     test2();
239     test3();
240     test4();
241     test5();
242     test6();
243     test7();
244     test8();
245     return EXIT_SUCCESS;
246 }
247 
248