1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2006-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/interprocess/containers/string.hpp>
12 #include <boost/interprocess/containers/vector.hpp>
13 #include <boost/interprocess/streams/vectorstream.hpp>
14 #include <boost/interprocess/streams/bufferstream.hpp>
19 #include <boost/date_time/posix_time/posix_time_types.hpp>
23 namespace interprocess
{
25 //Force instantiations to catch compile-time errors
26 typedef basic_string
<char> my_string
;
27 typedef basic_vectorstream
<my_string
> my_stringstream_t
;
28 typedef vector
<char> my_vector
;
29 typedef basic_vectorstream
<my_vector
> my_vectorstream_t
;
30 template class basic_vectorstream
<my_string
>;
31 template class basic_vectorstream
<std::vector
<char> >;
35 using namespace boost::interprocess
;
37 static int vectorstream_test()
39 { //Test high watermarking initialization
40 my_stringstream_t my_stringstream
;
42 if(my_stringstream
.tellg() != std::streampos(0)){
45 if(my_stringstream
.tellp() != std::streampos(0)){
50 my_stringstream
<< 11;
55 { //Test high watermarking initialization
56 my_vectorstream_t my_stringstream
;
58 my_stringstream
<< 13;
66 my_stringstream_t my_stringstream
;
67 std::stringstream std_stringstream
;
68 std::string str1
, str2
, str3("testline:");
71 my_stringstream
.reserve(10000);
72 for(int i
= 0; i
< 100; ++i
){
73 my_stringstream
<< "testline: " << i
<< std::endl
;
74 std_stringstream
<< "testline: " << i
<< std::endl
;
77 if(std::strcmp(my_stringstream
.vector().c_str(), std_stringstream
.str().c_str()) != 0){
81 for(int i
= 0; i
< 100; ++i
){
82 my_stringstream
>> str1
>> number1
;
83 std_stringstream
>> str2
>> number2
;
84 if((str1
!= str2
) || (str1
!= str3
)){
87 if((number1
!= number2
) || (number1
!= i
)){
94 basic_vectorstream
<std::vector
<char> > my_vectorstream
;
95 std::vector
<char> myvector
;
96 std::stringstream std_stringstream
;
97 std::string str1
, str2
, str3("testline:");
100 my_vectorstream
.reserve(10000);
101 for(int i
= 0; i
< 100; ++i
){
102 my_vectorstream
<< "testline: " << i
<< std::endl
;
103 std_stringstream
<< "testline: " << i
<< std::endl
;
105 //Add final null to form a c string
106 myvector
.push_back(0);
107 if(std::strcmp(&(my_vectorstream
.vector()[0]), std_stringstream
.str().c_str()) != 0){
111 for(int i
= 0; i
< 100; ++i
){
112 my_vectorstream
>> str1
>> number1
;
113 std_stringstream
>> str2
>> number2
;
114 if((str1
!= str2
) || (str1
!= str3
)){
117 if((number1
!= number2
) || (number1
!= i
)){
123 //No pre-reserved or pre-reserved string
125 my_stringstream_t my_stringstream
;
126 std::stringstream std_stringstream
;
127 std::string str1
, str2
, str3("testline:");
128 int number1
, number2
;
130 for(int i
= 0; i
< 100; ++i
){
131 my_stringstream
<< "testline: " << i
<< std::endl
;
132 std_stringstream
<< "testline: " << i
<< std::endl
;
134 if(std::strcmp(my_stringstream
.vector().c_str(), std_stringstream
.str().c_str()) != 0){
137 for(int i
= 0; i
< 100; ++i
){
138 my_stringstream
>> str1
>> number1
;
139 std_stringstream
>> str2
>> number2
;
140 if((str1
!= str2
) || (str1
!= str3
)){
143 if((number1
!= number2
) || (number1
!= i
)){
151 my_stringstream_t my_stringstream
;
152 my_stringstream
<< "ABCDEFGHIJKLM";
153 my_stringstream
.seekp(0);
154 my_stringstream
<< "PQRST";
155 string
s("PQRSTFGHIJKLM");
156 if(s
!= my_stringstream
.vector()){
159 my_stringstream
.seekp(0, std::ios_base::end
);
160 my_stringstream
<< "NOPQRST";
161 s
="PQRSTFGHIJKLMNOPQRST";
162 if(s
!= my_stringstream
.vector()){
165 int size
= static_cast<int>(my_stringstream
.vector().size());
166 my_stringstream
.seekp(-size
, std::ios_base::cur
);
167 my_stringstream
<< "ABCDE";
168 s
="ABCDEFGHIJKLMNOPQRST";
169 if(s
!= my_stringstream
.vector()){
178 if(vectorstream_test()){