3910 |
13 May 20 |
peter |
// $Id$ |
3910 |
13 May 20 |
peter |
2 |
|
3910 |
13 May 20 |
peter |
3 |
/* |
3910 |
13 May 20 |
peter |
Copyright (C) 2020 Peter Johansson |
3910 |
13 May 20 |
peter |
5 |
|
3910 |
13 May 20 |
peter |
This program is free software; you can redistribute it and/or modify |
3910 |
13 May 20 |
peter |
it under the terms of the GNU General Public License as published by |
3910 |
13 May 20 |
peter |
the Free Software Foundation; either version 3 of the License, or |
3910 |
13 May 20 |
peter |
(at your option) any later version. |
3910 |
13 May 20 |
peter |
10 |
|
3910 |
13 May 20 |
peter |
This program is distributed in the hope that it will be useful, but |
3910 |
13 May 20 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
3910 |
13 May 20 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3910 |
13 May 20 |
peter |
General Public License for more details. |
3910 |
13 May 20 |
peter |
15 |
|
3910 |
13 May 20 |
peter |
You should have received a copy of the GNU General Public License |
3910 |
13 May 20 |
peter |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
3910 |
13 May 20 |
peter |
18 |
*/ |
3910 |
13 May 20 |
peter |
19 |
|
3910 |
13 May 20 |
peter |
20 |
#include <config.h> |
3910 |
13 May 20 |
peter |
21 |
|
3910 |
13 May 20 |
peter |
22 |
#include "Suite.h" |
3910 |
13 May 20 |
peter |
23 |
|
3910 |
13 May 20 |
peter |
24 |
#include "yat/utility/BinaryIstreamIterator.h" |
3910 |
13 May 20 |
peter |
25 |
#include "yat/utility/BinaryOstreamIterator.h" |
3910 |
13 May 20 |
peter |
26 |
#include "yat/utility/utility.h" |
3910 |
13 May 20 |
peter |
27 |
|
3910 |
13 May 20 |
peter |
28 |
#include <sstream> |
3910 |
13 May 20 |
peter |
29 |
#include <string> |
3910 |
13 May 20 |
peter |
30 |
|
3910 |
13 May 20 |
peter |
31 |
using namespace theplu::yat; |
3910 |
13 May 20 |
peter |
32 |
|
3910 |
13 May 20 |
peter |
33 |
int main(int argc, char* argv[]) |
3910 |
13 May 20 |
peter |
34 |
{ |
3910 |
13 May 20 |
peter |
35 |
test::Suite suite(argc, argv); |
3910 |
13 May 20 |
peter |
36 |
std::vector<unsigned long int> x; |
3910 |
13 May 20 |
peter |
37 |
x.push_back(0); |
3910 |
13 May 20 |
peter |
38 |
x.push_back(1); |
3910 |
13 May 20 |
peter |
39 |
while (x.size() < 100) |
3910 |
13 May 20 |
peter |
40 |
x.push_back(x.rbegin()[0] + x.rbegin()[1]); |
3910 |
13 May 20 |
peter |
41 |
|
3910 |
13 May 20 |
peter |
42 |
std::stringstream ss; |
3910 |
13 May 20 |
peter |
43 |
for (size_t i=0; i<x.size(); ++i) |
3910 |
13 May 20 |
peter |
44 |
utility::binary_write(ss, x[i]); |
3910 |
13 May 20 |
peter |
45 |
|
3910 |
13 May 20 |
peter |
46 |
std::vector<unsigned long int> y(x.size()); |
3910 |
13 May 20 |
peter |
47 |
for (size_t i=0; i<y.size(); ++i) |
3910 |
13 May 20 |
peter |
48 |
utility::binary_read(ss, y[i]); |
3910 |
13 May 20 |
peter |
49 |
|
3910 |
13 May 20 |
peter |
50 |
if (y != x) { |
3910 |
13 May 20 |
peter |
51 |
suite.add(false); |
3910 |
13 May 20 |
peter |
52 |
suite.err() << "x != y\n"; |
3910 |
13 May 20 |
peter |
53 |
} |
3910 |
13 May 20 |
peter |
54 |
|
3910 |
13 May 20 |
peter |
55 |
double pi = 3.141592; |
3910 |
13 May 20 |
peter |
56 |
utility::binary_write(ss, pi); |
3910 |
13 May 20 |
peter |
57 |
double pi2 = 0; |
3910 |
13 May 20 |
peter |
58 |
utility::binary_read(ss, pi2); |
3910 |
13 May 20 |
peter |
59 |
if (!suite.equal(pi2, pi)) { |
3910 |
13 May 20 |
peter |
60 |
suite.add(false); |
3910 |
13 May 20 |
peter |
61 |
suite.err() << "pi != pi2\n"; |
3910 |
13 May 20 |
peter |
62 |
} |
3910 |
13 May 20 |
peter |
63 |
|
3910 |
13 May 20 |
peter |
64 |
std::stringstream ss2; |
3910 |
13 May 20 |
peter |
65 |
std::copy(x.begin(), x.end(), |
3910 |
13 May 20 |
peter |
66 |
utility::BinaryOstreamIterator<unsigned long int>(ss2)); |
3910 |
13 May 20 |
peter |
67 |
if (ss2.str().size() != sizeof(unsigned long int) * x.size()) { |
3910 |
13 May 20 |
peter |
68 |
suite.add(false); |
3910 |
13 May 20 |
peter |
69 |
suite.err() << "x size: " << x.size() << "\n"; |
3910 |
13 May 20 |
peter |
70 |
suite.err() << "stream size: " << ss2.str().size() << "\n"; |
3910 |
13 May 20 |
peter |
71 |
suite.err() << "unexpected size\n"; |
3910 |
13 May 20 |
peter |
72 |
} |
3910 |
13 May 20 |
peter |
73 |
|
3910 |
13 May 20 |
peter |
74 |
std::vector<unsigned long int> z; |
3910 |
13 May 20 |
peter |
75 |
std::copy(utility::BinaryIstreamIterator<unsigned long int>(ss2), |
3910 |
13 May 20 |
peter |
76 |
utility::BinaryIstreamIterator<unsigned long int>(), |
3910 |
13 May 20 |
peter |
77 |
std::back_inserter(z)); |
3910 |
13 May 20 |
peter |
78 |
|
3910 |
13 May 20 |
peter |
79 |
if (z != x) { |
3910 |
13 May 20 |
peter |
80 |
suite.add(false); |
3910 |
13 May 20 |
peter |
81 |
suite.err() << "binary stream iterators failed\n"; |
3910 |
13 May 20 |
peter |
82 |
} |
3910 |
13 May 20 |
peter |
83 |
|
3910 |
13 May 20 |
peter |
84 |
utility::BinaryIstreamIterator<unsigned long int> input(ss2); |
3910 |
13 May 20 |
peter |
85 |
utility::BinaryOstreamIterator<unsigned long int> output(ss2); |
3910 |
13 May 20 |
peter |
86 |
suite.test_input_iterator(input); |
3910 |
13 May 20 |
peter |
87 |
suite.test_output_iterator(input); |
3910 |
13 May 20 |
peter |
88 |
|
3910 |
13 May 20 |
peter |
89 |
test::test_single_pass_iterator(input); |
3910 |
13 May 20 |
peter |
90 |
test::test_readable_iterator(input); |
3910 |
13 May 20 |
peter |
91 |
test::test_lvalue_iterator(input); |
3910 |
13 May 20 |
peter |
92 |
test::test_const_iterator(input); |
3910 |
13 May 20 |
peter |
93 |
|
3910 |
13 May 20 |
peter |
94 |
test::test_incrementable_iterator(output); |
3910 |
13 May 20 |
peter |
95 |
|
3910 |
13 May 20 |
peter |
96 |
return suite.return_value(); |
3910 |
13 May 20 |
peter |
97 |
} |