1 /*
2 Copyright (c) 2014, Randolph Voorhies, Shane Grant
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of cereal nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES AND SHANE GRANT BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 #ifndef CEREAL_TEST_BASIC_STRING_H_
28 #define CEREAL_TEST_BASIC_STRING_H_
29 #include "common.hpp"
30
31 template <class IArchive, class OArchive> inline
test_string_basic()32 void test_string_basic()
33 {
34 std::random_device rd;
35 std::mt19937 gen(rd());
36
37 for(size_t i=0; i<100; ++i)
38 {
39 std::basic_string<char> o_string = random_basic_string<char>(gen);
40 std::basic_string<char> o_string2 = "";
41 std::basic_string<char> o_string3;
42
43 std::ostringstream os;
44 {
45 OArchive oar(os);
46 oar(o_string);
47 oar(o_string2);
48 oar(o_string3);
49 }
50
51 std::basic_string<char> i_string;
52 std::basic_string<char> i_string2;
53 std::basic_string<char> i_string3;
54
55 std::istringstream is(os.str());
56 {
57 IArchive iar(is);
58
59 iar(i_string);
60 iar(i_string2);
61 iar(i_string3);
62 }
63
64 CHECK_EQ(i_string, o_string);
65 CHECK_EQ(i_string2, o_string2);
66 CHECK_EQ(i_string3, o_string3);
67 }
68 }
69
70 template <class IArchive, class OArchive> inline
test_string_all()71 void test_string_all()
72 {
73 std::random_device rd;
74 std::mt19937 gen(rd());
75
76 for(size_t i=0; i<100; ++i)
77 {
78 std::basic_string<char> o_string = random_basic_string<char>(gen);
79 std::basic_string<wchar_t> o_wstring = random_basic_string<wchar_t>(gen);
80 std::basic_string<char16_t> o_u16string = random_basic_string<char16_t>(gen);
81 std::basic_string<char32_t> o_u32string = random_basic_string<char32_t>(gen);
82
83 std::ostringstream os;
84 {
85 OArchive oar(os);
86 oar(o_string);
87 oar(o_wstring);
88 oar(o_u16string);
89 oar(o_u32string);
90 }
91
92 std::basic_string<char> i_string;
93 std::basic_string<wchar_t> i_wstring;
94 std::basic_string<char16_t> i_u16string;
95 std::basic_string<char32_t> i_u32string;
96
97 std::istringstream is(os.str());
98 {
99 IArchive iar(is);
100
101 iar(i_string);
102 iar(i_wstring);
103 iar(i_u16string);
104 iar(i_u32string);
105 }
106
107 CHECK_EQ(i_string, o_string);
108 check_collection( i_wstring, o_wstring );
109 check_collection( i_u16string, o_u16string );
110 check_collection( i_u32string, o_u32string );
111 }
112 }
113
114 #endif // CEREAL_TEST_BASIC_STRING_H_
115