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
19using Poco::CppParser::Attributes;
20using Poco::CppParser::AttributesParser;
21
22
23AttributesParserTest::AttributesParserTest(const std::string& name): CppUnit::TestCase(name)
24{
25}
26
27
28AttributesParserTest::~AttributesParserTest()
29{
30}
31
32
33void 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
43void 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
53void 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
64void 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
76void 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
88void 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
100void 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
113void AttributesParserTest::setUp()
114{
115}
116
117
118void AttributesParserTest::tearDown()
119{
120}
121
122
123CppUnit::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