mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 10:32:56 +01:00
new trunk (base for 1.5)
windows build only
This commit is contained in:
158
CppParser/testsuite/src/AttributesParserTest.cpp
Normal file
158
CppParser/testsuite/src/AttributesParserTest.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
//
|
||||
// AttributesParserTest.cpp
|
||||
//
|
||||
// $Id: //poco/1.3/CppParser/testsuite/src/AttributesParserTest.cpp#1 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "AttributesParserTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/CppParser/Attributes.h"
|
||||
#include "Poco/CppParser/AttributesParser.h"
|
||||
#include <sstream>
|
||||
|
||||
|
||||
using Poco::CppParser::Attributes;
|
||||
using Poco::CppParser::AttributesParser;
|
||||
|
||||
|
||||
AttributesParserTest::AttributesParserTest(const std::string& name): CppUnit::TestCase(name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
AttributesParserTest::~AttributesParserTest()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AttributesParserTest::testParser1()
|
||||
{
|
||||
Attributes attrs;
|
||||
std::istringstream istr("");
|
||||
AttributesParser parser(attrs, istr);
|
||||
parser.parse();
|
||||
assert (attrs.begin() == attrs.end());
|
||||
}
|
||||
|
||||
|
||||
void AttributesParserTest::testParser2()
|
||||
{
|
||||
Attributes attrs;
|
||||
std::istringstream istr("name=value");
|
||||
AttributesParser parser(attrs, istr);
|
||||
parser.parse();
|
||||
assert (attrs.getString("name") == "value");
|
||||
}
|
||||
|
||||
|
||||
void AttributesParserTest::testParser3()
|
||||
{
|
||||
Attributes attrs;
|
||||
std::istringstream istr("name=value, name2=100");
|
||||
AttributesParser parser(attrs, istr);
|
||||
parser.parse();
|
||||
assert (attrs.getString("name") == "value");
|
||||
assert (attrs.getInt("name2") == 100);
|
||||
}
|
||||
|
||||
|
||||
void AttributesParserTest::testParser4()
|
||||
{
|
||||
Attributes attrs;
|
||||
std::istringstream istr("name=value, name2=100, name3");
|
||||
AttributesParser parser(attrs, istr);
|
||||
parser.parse();
|
||||
assert (attrs.getString("name") == "value");
|
||||
assert (attrs.getInt("name2") == 100);
|
||||
assert (attrs.getBool("name3"));
|
||||
}
|
||||
|
||||
|
||||
void AttributesParserTest::testParser5()
|
||||
{
|
||||
Attributes attrs;
|
||||
std::istringstream istr("name.a=value, name.b=100, name.c");
|
||||
AttributesParser parser(attrs, istr);
|
||||
parser.parse();
|
||||
assert (attrs.getString("name.a") == "value");
|
||||
assert (attrs.getInt("name.b") == 100);
|
||||
assert (attrs.getBool("name.c"));
|
||||
}
|
||||
|
||||
|
||||
void AttributesParserTest::testParser6()
|
||||
{
|
||||
Attributes attrs;
|
||||
std::istringstream istr("name = {a=value, b=100, c}");
|
||||
AttributesParser parser(attrs, istr);
|
||||
parser.parse();
|
||||
assert (attrs.getString("name.a") == "value");
|
||||
assert (attrs.getInt("name.b") == 100);
|
||||
assert (attrs.getBool("name.c"));
|
||||
}
|
||||
|
||||
|
||||
void AttributesParserTest::testParser7()
|
||||
{
|
||||
Attributes attrs;
|
||||
std::istringstream istr("name = {a=value, b=100, c}, name2=\"foo\"");
|
||||
AttributesParser parser(attrs, istr);
|
||||
parser.parse();
|
||||
assert (attrs.getString("name.a") == "value");
|
||||
assert (attrs.getInt("name.b") == 100);
|
||||
assert (attrs.getBool("name.c"));
|
||||
assert (attrs.getString("name2") == "foo");
|
||||
}
|
||||
|
||||
|
||||
void AttributesParserTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void AttributesParserTest::tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* AttributesParserTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AttributesParserTest");
|
||||
|
||||
CppUnit_addTest(pSuite, AttributesParserTest, testParser1);
|
||||
CppUnit_addTest(pSuite, AttributesParserTest, testParser2);
|
||||
CppUnit_addTest(pSuite, AttributesParserTest, testParser3);
|
||||
CppUnit_addTest(pSuite, AttributesParserTest, testParser4);
|
||||
CppUnit_addTest(pSuite, AttributesParserTest, testParser5);
|
||||
CppUnit_addTest(pSuite, AttributesParserTest, testParser6);
|
||||
CppUnit_addTest(pSuite, AttributesParserTest, testParser7);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
Reference in New Issue
Block a user