1 | // |
2 | // AttributesParserTest.cpp |
3 | // |
4 | // Copyright (c) 2006, Applied Informatics Software Engineering GmbH. |
5 | // and Contributors. |
6 | // |
7 | // SPDX-License-Identifier: BSL-1.0 |
8 | // |
9 | |
10 | |
11 | #include "AttributesParserTest.h" |
12 | #include "Poco/CppUnit/TestCaller.h" |
13 | #include "Poco/CppUnit/TestSuite.h" |
14 | #include "Poco/CppParser/Attributes.h" |
15 | #include "Poco/CppParser/AttributesParser.h" |
16 | #include <sstream> |
17 | |
18 | |
19 | using Poco::CppParser::Attributes; |
20 | using Poco::CppParser::AttributesParser; |
21 | |
22 | |
23 | AttributesParserTest::AttributesParserTest(const std::string& name): CppUnit::TestCase(name) |
24 | { |
25 | } |
26 | |
27 | |
28 | AttributesParserTest::~AttributesParserTest() |
29 | { |
30 | } |
31 | |
32 | |
33 | void AttributesParserTest::testParser1() |
34 | { |
35 | Attributes attrs; |
36 | std::istringstream istr("" ); |
37 | AttributesParser parser(attrs, istr); |
38 | parser.parse(); |
39 | assertTrue (attrs.begin() == attrs.end()); |
40 | } |
41 | |
42 | |
43 | void AttributesParserTest::testParser2() |
44 | { |
45 | Attributes attrs; |
46 | std::istringstream istr("name=value" ); |
47 | AttributesParser parser(attrs, istr); |
48 | parser.parse(); |
49 | assertTrue (attrs.getString("name" ) == "value" ); |
50 | } |
51 | |
52 | |
53 | void AttributesParserTest::testParser3() |
54 | { |
55 | Attributes attrs; |
56 | std::istringstream istr("name=value, name2=100" ); |
57 | AttributesParser parser(attrs, istr); |
58 | parser.parse(); |
59 | assertTrue (attrs.getString("name" ) == "value" ); |
60 | assertTrue (attrs.getInt("name2" ) == 100); |
61 | } |
62 | |
63 | |
64 | void AttributesParserTest::testParser4() |
65 | { |
66 | Attributes attrs; |
67 | std::istringstream istr("name=value, name2=100, name3" ); |
68 | AttributesParser parser(attrs, istr); |
69 | parser.parse(); |
70 | assertTrue (attrs.getString("name" ) == "value" ); |
71 | assertTrue (attrs.getInt("name2" ) == 100); |
72 | assertTrue (attrs.getBool("name3" )); |
73 | } |
74 | |
75 | |
76 | void AttributesParserTest::testParser5() |
77 | { |
78 | Attributes attrs; |
79 | std::istringstream istr("name.a=value, name.b=100, name.c" ); |
80 | AttributesParser parser(attrs, istr); |
81 | parser.parse(); |
82 | assertTrue (attrs.getString("name.a" ) == "value" ); |
83 | assertTrue (attrs.getInt("name.b" ) == 100); |
84 | assertTrue (attrs.getBool("name.c" )); |
85 | } |
86 | |
87 | |
88 | void AttributesParserTest::testParser6() |
89 | { |
90 | Attributes attrs; |
91 | std::istringstream istr("name = {a=value, b=100, c}" ); |
92 | AttributesParser parser(attrs, istr); |
93 | parser.parse(); |
94 | assertTrue (attrs.getString("name.a" ) == "value" ); |
95 | assertTrue (attrs.getInt("name.b" ) == 100); |
96 | assertTrue (attrs.getBool("name.c" )); |
97 | } |
98 | |
99 | |
100 | void AttributesParserTest::testParser7() |
101 | { |
102 | Attributes attrs; |
103 | std::istringstream istr("name = {a=value, b=100, c}, name2=\"foo\"" ); |
104 | AttributesParser parser(attrs, istr); |
105 | parser.parse(); |
106 | assertTrue (attrs.getString("name.a" ) == "value" ); |
107 | assertTrue (attrs.getInt("name.b" ) == 100); |
108 | assertTrue (attrs.getBool("name.c" )); |
109 | assertTrue (attrs.getString("name2" ) == "foo" ); |
110 | } |
111 | |
112 | |
113 | void AttributesParserTest::setUp() |
114 | { |
115 | } |
116 | |
117 | |
118 | void AttributesParserTest::tearDown() |
119 | { |
120 | } |
121 | |
122 | |
123 | CppUnit::Test* AttributesParserTest::suite() |
124 | { |
125 | CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AttributesParserTest" ); |
126 | |
127 | CppUnit_addTest(pSuite, AttributesParserTest, testParser1); |
128 | CppUnit_addTest(pSuite, AttributesParserTest, testParser2); |
129 | CppUnit_addTest(pSuite, AttributesParserTest, testParser3); |
130 | CppUnit_addTest(pSuite, AttributesParserTest, testParser4); |
131 | CppUnit_addTest(pSuite, AttributesParserTest, testParser5); |
132 | CppUnit_addTest(pSuite, AttributesParserTest, testParser6); |
133 | CppUnit_addTest(pSuite, AttributesParserTest, testParser7); |
134 | |
135 | return pSuite; |
136 | } |
137 | |