1878 |
27 Mar 09 |
peter |
// $Id$ |
1878 |
27 Mar 09 |
peter |
2 |
|
1878 |
27 Mar 09 |
peter |
3 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2012 Peter Johansson |
1878 |
27 Mar 09 |
peter |
5 |
|
1878 |
27 Mar 09 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
1878 |
27 Mar 09 |
peter |
7 |
|
1878 |
27 Mar 09 |
peter |
The yat library is free software; you can redistribute it and/or |
1878 |
27 Mar 09 |
peter |
modify it under the terms of the GNU General Public License as |
1878 |
27 Mar 09 |
peter |
published by the Free Software Foundation; either version 3 of the |
1878 |
27 Mar 09 |
peter |
License, or (at your option) any later version. |
1878 |
27 Mar 09 |
peter |
12 |
|
1878 |
27 Mar 09 |
peter |
The yat library is distributed in the hope that it will be useful, |
1878 |
27 Mar 09 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1878 |
27 Mar 09 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1878 |
27 Mar 09 |
peter |
General Public License for more details. |
1878 |
27 Mar 09 |
peter |
17 |
|
1878 |
27 Mar 09 |
peter |
You should have received a copy of the GNU General Public License |
1878 |
27 Mar 09 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
1878 |
27 Mar 09 |
peter |
20 |
*/ |
1878 |
27 Mar 09 |
peter |
21 |
|
2881 |
18 Nov 12 |
peter |
22 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
23 |
|
1878 |
27 Mar 09 |
peter |
24 |
#include "Suite.h" |
1878 |
27 Mar 09 |
peter |
25 |
|
1878 |
27 Mar 09 |
peter |
26 |
#include "yat/utility/GetlineIterator.h" |
1878 |
27 Mar 09 |
peter |
27 |
|
1878 |
27 Mar 09 |
peter |
28 |
#include <algorithm> |
1878 |
27 Mar 09 |
peter |
29 |
#include <istream> |
1878 |
27 Mar 09 |
peter |
30 |
#include <sstream> |
1878 |
27 Mar 09 |
peter |
31 |
#include <string> |
1878 |
27 Mar 09 |
peter |
32 |
#include <vector> |
1878 |
27 Mar 09 |
peter |
33 |
|
1878 |
27 Mar 09 |
peter |
34 |
using namespace theplu::yat; |
1878 |
27 Mar 09 |
peter |
35 |
void test_default(test::Suite& suite); |
1880 |
28 Mar 09 |
peter |
36 |
void test_input_iterator(test::Suite& suite); |
1878 |
27 Mar 09 |
peter |
37 |
|
1878 |
27 Mar 09 |
peter |
38 |
int main( int argc, char* argv[]) |
4200 |
19 Aug 22 |
peter |
39 |
{ |
1878 |
27 Mar 09 |
peter |
40 |
test::Suite suite(argc, argv); |
1878 |
27 Mar 09 |
peter |
41 |
suite.err() << "testing ReadlineIterator" << std::endl; |
1878 |
27 Mar 09 |
peter |
42 |
test_default(suite); |
1880 |
28 Mar 09 |
peter |
43 |
test_input_iterator(suite); |
1878 |
27 Mar 09 |
peter |
44 |
|
1878 |
27 Mar 09 |
peter |
45 |
return suite.return_value(); |
1878 |
27 Mar 09 |
peter |
46 |
} |
1878 |
27 Mar 09 |
peter |
47 |
|
1878 |
27 Mar 09 |
peter |
48 |
void test_default(test::Suite& suite) |
1878 |
27 Mar 09 |
peter |
49 |
{ |
1878 |
27 Mar 09 |
peter |
50 |
std::istringstream is("Hello World!\nThis is a test."); |
1878 |
27 Mar 09 |
peter |
51 |
utility::GetlineIterator ri(is); |
1878 |
27 Mar 09 |
peter |
52 |
utility::GetlineIterator end; |
1878 |
27 Mar 09 |
peter |
53 |
std::vector<std::string> result; |
1878 |
27 Mar 09 |
peter |
54 |
std::copy(ri, end, std::back_inserter(result)); |
1878 |
27 Mar 09 |
peter |
55 |
if (result.size()==2) { |
1878 |
27 Mar 09 |
peter |
56 |
if (!suite.add(result[0]=="Hello World!")) |
1878 |
27 Mar 09 |
peter |
57 |
suite.err() << "result[0] is:" << result[0] << " expected Hello World!\n"; |
1878 |
27 Mar 09 |
peter |
58 |
if (!suite.add(result[1]=="This is a test.")) |
4200 |
19 Aug 22 |
peter |
59 |
suite.err() << "result[1] is:" << result[0] |
1878 |
27 Mar 09 |
peter |
60 |
<< " expected This is a test.\n"; |
1878 |
27 Mar 09 |
peter |
61 |
} |
1878 |
27 Mar 09 |
peter |
62 |
else { |
1878 |
27 Mar 09 |
peter |
63 |
suite.add(false); |
1878 |
27 Mar 09 |
peter |
64 |
suite.err() << "Error: result has " << result.size() << " expected 2.\n"; |
1878 |
27 Mar 09 |
peter |
65 |
} |
1878 |
27 Mar 09 |
peter |
66 |
} |
1878 |
27 Mar 09 |
peter |
67 |
|
1880 |
28 Mar 09 |
peter |
68 |
void test_input_iterator(test::Suite& suite) |
1880 |
28 Mar 09 |
peter |
69 |
{ |
1880 |
28 Mar 09 |
peter |
70 |
std::istringstream is("Hello World!\nThis is a test."); |
1880 |
28 Mar 09 |
peter |
71 |
utility::GetlineIterator ri(is, '\n'); |
1880 |
28 Mar 09 |
peter |
72 |
suite.test_input_iterator(ri); |
1880 |
28 Mar 09 |
peter |
73 |
} |