/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see .
*/
#include "lib/self_test.h"
#include "ps/CLogger.h"
#include "ps/XML/Xeromyces.h"
#include "ps/XML/RelaxNG.h"
class TestRelaxNG : public CxxTest::TestSuite
{
public:
void setUp()
{
CXeromyces::Startup();
}
void tearDown()
{
CXeromyces::Terminate();
}
void test_basic()
{
RelaxNGValidator v;
TS_ASSERT(v.LoadGrammar(""));
TS_ASSERT(v.Validate(L"doc", L""));
{
TestLogger logger;
TS_ASSERT(!v.Validate(L"doc", L""));
TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "Validation error: doc:1: Expecting element test, got bogus");
}
{
TestLogger logger;
TS_ASSERT(!v.Validate(L"doc", L"bogus"));
TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "RelaxNGValidator: Failed to parse document");
}
TS_ASSERT(v.Validate(L"doc", L""));
}
void test_interleave()
{
RelaxNGValidator v;
TS_ASSERT(v.LoadGrammar(""));
// This currently (libxml2-2.7.7) leaks memory and makes Valgrind complain - see https://bugzilla.gnome.org/show_bug.cgi?id=615767
}
void test_datatypes()
{
RelaxNGValidator v;
TS_ASSERT(v.LoadGrammar("1.5"));
TS_ASSERT(v.Validate(L"doc", L"2.0"));
TestLogger logger;
TS_ASSERT(!v.Validate(L"doc", L"x"));
TS_ASSERT(!v.Validate(L"doc", L"1.0"));
}
void test_broken_grammar()
{
RelaxNGValidator v;
TestLogger logger;
TS_ASSERT(!v.LoadGrammar("whoops"));
TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "RelaxNGValidator: Failed to compile schema");
TS_ASSERT(!v.Validate(L"doc", L""));
}
};