/* Copyright (C) 2021 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("doc", "")); { TestLogger logger; TS_ASSERT(!v.Validate("doc", "")); TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "Validation error: doc:1: Expecting element test, got bogus"); } { TestLogger logger; TS_ASSERT(!v.Validate("doc", "bogus")); TS_ASSERT_STR_CONTAINS(logger.GetOutput(), "RelaxNGValidator: Failed to parse document"); } TS_ASSERT(v.Validate("doc", "")); } 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("doc", "2.0")); TestLogger logger; TS_ASSERT(!v.Validate("doc", "x")); TS_ASSERT(!v.Validate("doc", "1.0")); RelaxNGValidator w; TS_ASSERT(w.LoadGrammar("")); TS_ASSERT(w.Validate("doc", "2")); TS_ASSERT(!w.Validate("doc", "x")); TS_ASSERT(!w.Validate("doc", "2.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("doc", "")); } };