added tests for XSLT attribute value tests

This commit is contained in:
jez_higgins 2006-01-12 14:35:59 +00:00
parent 374a31a45a
commit 09fe28158f
3 changed files with 86 additions and 1 deletions

View file

@ -0,0 +1,81 @@
#ifndef XPATHIC_ATTRIBUTE_VALUE_TEST_HPP
#define XPATHIC_ATTRIBUTE_VALUE_TEST_HPP
#include "../CppUnit/framework/TestCase.h"
#include "../CppUnit/framework/TestSuite.h"
#include "../CppUnit/framework/TestCaller.h"
#include <XPath/XPath.hpp>
template<class string_type, class string_adaptor>
class AttributeValueTest : public TestCase
{
Arabica::XPath::XPath<string_type> parser;
typedef string_adaptor SA;
public:
AttributeValueTest(std::string name) : TestCase(name)
{
} // AttributeValueTest
void setUp()
{
} // setUp
void testParse()
{
DOM::Node<string_type> dummy;
assertTrue(SA::construct_from_utf8("hello") == compileThis("hello")->evaluateAsString(dummy));
assertTrue(SA::construct_from_utf8("") == compileThis("{hello}")->evaluateAsString(dummy));
assertTrue(SA::construct_from_utf8("{hello}") == compileThis("{{hello}}")->evaluateAsString(dummy));
assertTrue(SA::construct_from_utf8("{hello}") == compileThis("{{{'hello'}}}")->evaluateAsString(dummy));
assertTrue(SA::construct_from_utf8("{}") == compileThis("{{{hello}}}")->evaluateAsString(dummy));
assertTrue(SA::construct_from_utf8("{") == compileThis("{{")->evaluateAsString(dummy));
assertTrue(SA::construct_from_utf8("}") == compileThis("}}")->evaluateAsString(dummy));
assertTrue(SA::construct_from_utf8("hello") == compileThis("hello{@there}")->evaluateAsString(dummy));
assertTrue(SA::construct_from_utf8("helloMOTHER{}") == compileThis("hello{@there}MOTHER{{}}")->evaluateAsString(dummy));
assertTrue(SA::construct_from_utf8("hello there everyone look a }") == compileThis("hello {string('there')} everyone {string('look a }')}")->evaluateAsString(dummy));
} // testParse
void testParseFail()
{
assertTrue(dontCompileThis(""));
assertTrue(dontCompileThis("{"));
assertTrue(dontCompileThis("}"));
assertTrue(dontCompileThis("{}}"));
assertTrue(dontCompileThis("{{}"));
assertTrue(dontCompileThis("{{{{{{{}"));
assertTrue(dontCompileThis("{}"));
} // testParseFail
bool dontCompileThis(const char* path)
{
try {
compileThis(path);
return false;
}
catch(const Arabica::XPath::SyntaxException&) {
}
return true;
} // dontCompileThis
Arabica::XPath::XPathExpressionPtr<string_type, string_adaptor> compileThis(const char* match)
{
//std::cout << "----\n" << match << std::endl;
return parser.compile_attribute_value_template(SA::construct_from_utf8(match));
} // compileMatch
}; // class AttributeValueTest
template<class string_type, class string_adaptor>
TestSuite* AttributeValueTest_suite()
{
TestSuite *suiteOfTests = new TestSuite;
suiteOfTests->addTest(new TestCaller<AttributeValueTest<string_type, string_adaptor> >("testParse", &AttributeValueTest<string_type, string_adaptor>::testParse));
suiteOfTests->addTest(new TestCaller<AttributeValueTest<string_type, string_adaptor> >("testParseFail", &AttributeValueTest<string_type, string_adaptor>::testParseFail));
return suiteOfTests;
} // AttributeValueTest_suite
#endif

View file

@ -16,7 +16,7 @@
#include "execute_test.hpp"
#include "expression_test.hpp"
#include "match_test.hpp"
#include "attr_value_test.hpp"
template<class string_type, class string_adaptor>
void XPath_test_suite(int argc, const char** argv)
@ -34,6 +34,7 @@ void XPath_test_suite(int argc, const char** argv)
runner.addTest("ExecuteTest", ExecuteTest_suite<string_type, string_adaptor>());
runner.addTest("ExpressionTest", ExpressionTest_suite<string_type, string_adaptor>());
runner.addTest("MatchTest", MatchTest_suite<string_type, string_adaptor>());
runner.addTest("AttributeValueTest", AttributeValueTest_suite<string_type, string_adaptor>());
runner.run(argc, argv);
} // XPath_test_suite

View file

@ -136,6 +136,9 @@
<File
RelativePath=".\arithmetic_test.hpp">
</File>
<File
RelativePath=".\attr_value_test.hpp">
</File>
<File
RelativePath=".\axis_enumerator_test.hpp">
</File>