diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/core/RegistryTest.cpp | 2 | ||||
| -rw-r--r-- | test/core/model/DocumentTest.cpp | 2 | ||||
| -rw-r--r-- | test/core/model/DomainTest.cpp | 8 | ||||
| -rw-r--r-- | test/core/model/TestAdvanced.hpp | 2 | ||||
| -rw-r--r-- | test/core/model/TestDocument.hpp | 2 | ||||
| -rw-r--r-- | test/core/model/TestDocumentBuilder.hpp | 2 | ||||
| -rw-r--r-- | test/core/model/TestDomain.hpp | 3 | ||||
| -rw-r--r-- | test/core/model/TypesystemTest.cpp | 87 | ||||
| -rw-r--r-- | test/core/parser/StandaloneParserContext.hpp | 12 | ||||
| -rw-r--r-- | test/core/resource/ResourceRequestTest.cpp | 149 | ||||
| -rw-r--r-- | test/plugins/css/CSSParserTest.cpp | 4 | ||||
| -rw-r--r-- | test/plugins/html/DemoOutputTest.cpp | 44 | 
12 files changed, 223 insertions, 94 deletions
diff --git a/test/core/RegistryTest.cpp b/test/core/RegistryTest.cpp index 21195f2..1a23139 100644 --- a/test/core/RegistryTest.cpp +++ b/test/core/RegistryTest.cpp @@ -33,7 +33,7 @@ class TestParser : public Parser {  protected:  	Rooted<Node> doParse(CharReader &reader, ParserContext &ctx) override  	{ -		return new Node{ctx.manager}; +		return new Node{ctx.getManager()};  	}  };  } diff --git a/test/core/model/DocumentTest.cpp b/test/core/model/DocumentTest.cpp index 1d8457c..563f1b4 100644 --- a/test/core/model/DocumentTest.cpp +++ b/test/core/model/DocumentTest.cpp @@ -29,7 +29,6 @@  #include "TestDomain.hpp"  namespace ousia { -namespace model {  TEST(Document, construct)  { @@ -308,4 +307,3 @@ TEST(Document, validate)  	}  }  } -} diff --git a/test/core/model/DomainTest.cpp b/test/core/model/DomainTest.cpp index 54fd86a..8bf1a47 100644 --- a/test/core/model/DomainTest.cpp +++ b/test/core/model/DomainTest.cpp @@ -27,7 +27,6 @@  #include "TestDomain.hpp"  namespace ousia { -namespace model {  void assert_path(const ResolutionResult &res, const Rtti &expected_type,                   std::vector<std::string> expected_path) @@ -335,8 +334,7 @@ TEST(Domain, validate)  		ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());  		ASSERT_TRUE(domain->validate(logger));  		// add a subclass for our base class. -		Rooted<StructuredClass> sub{ -		    new StructuredClass(mgr, "sub", domain)}; +		Rooted<StructuredClass> sub{new StructuredClass(mgr, "sub", domain)};  		// this should be valid in itself.  		ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());  		ASSERT_TRUE(domain->validate(logger)); @@ -355,8 +353,7 @@ TEST(Domain, validate)  		ASSERT_TRUE(domain->validate(logger));  		ASSERT_EQ(base, sub->getSuperclass());  		// add a non-primitive field to the child class. -		Rooted<FieldDescriptor> sub_field{ -		    new FieldDescriptor(mgr, sub)}; +		Rooted<FieldDescriptor> sub_field{new FieldDescriptor(mgr, sub)};  		// this should be valid  		ASSERT_EQ(ValidationState::UNKNOWN, domain->getValidationState());  		ASSERT_TRUE(domain->validate(logger)); @@ -383,4 +380,3 @@ TEST(Domain, validate)  	}  }  } -} diff --git a/test/core/model/TestAdvanced.hpp b/test/core/model/TestAdvanced.hpp index 6f8ca33..035ee8e 100644 --- a/test/core/model/TestAdvanced.hpp +++ b/test/core/model/TestAdvanced.hpp @@ -26,7 +26,6 @@  #include "TestDocumentBuilder.hpp"  namespace ousia { -namespace model {  static Rooted<StructuredClass> resolveDescriptor(Handle<Domain> domain,                                                   const std::string &className) @@ -316,6 +315,5 @@ static Rooted<Document> constructAdvancedDocument(Manager &mgr, Logger &logger,  	return doc;  }  } -}  #endif /* _TEST_DOCUMENT_HPP_ */ diff --git a/test/core/model/TestDocument.hpp b/test/core/model/TestDocument.hpp index 2397fe6..243672b 100644 --- a/test/core/model/TestDocument.hpp +++ b/test/core/model/TestDocument.hpp @@ -26,7 +26,6 @@  #include "TestDocumentBuilder.hpp"  namespace ousia { -namespace model {  /**   * This constructs a fairly simple test document for the "book" domain. The @@ -88,7 +87,6 @@ static Rooted<Document> constructBookDocument(Manager &mgr, Logger &logger,  	return doc;  }  } -}  #endif /* _TEST_DOCUMENT_HPP_ */ diff --git a/test/core/model/TestDocumentBuilder.hpp b/test/core/model/TestDocumentBuilder.hpp index 63d60eb..149b88e 100644 --- a/test/core/model/TestDocumentBuilder.hpp +++ b/test/core/model/TestDocumentBuilder.hpp @@ -27,7 +27,6 @@  #include <core/model/Typesystem.hpp>  namespace ousia { -namespace model {  typedef std::vector<std::string> Path; @@ -215,5 +214,4 @@ Rooted<AnnotationEntity> buildAnnotationEntity(  	return anno;  }  } -}  #endif diff --git a/test/core/model/TestDomain.hpp b/test/core/model/TestDomain.hpp index ec63216..a36f593 100644 --- a/test/core/model/TestDomain.hpp +++ b/test/core/model/TestDomain.hpp @@ -23,8 +23,6 @@  #include <core/model/Typesystem.hpp>  namespace ousia { -namespace model { -  /**   * This constructs the "book" domain for test purposes. The structure of the   * domain is fairly simple and can be seen from the construction itself. @@ -91,6 +89,5 @@ static Rooted<Domain> constructBookDomain(Manager &mgr,  	return domain;  }  } -}  #endif /* _TEST_DOMAIN_HPP_ */ diff --git a/test/core/model/TypesystemTest.cpp b/test/core/model/TypesystemTest.cpp index 4d1d2c9..7d05f56 100644 --- a/test/core/model/TypesystemTest.cpp +++ b/test/core/model/TypesystemTest.cpp @@ -25,10 +25,9 @@  #include <core/model/Typesystem.hpp>  namespace ousia { -namespace model {  static TerminalLogger logger(std::cerr, true); -//static ConcreteLogger logger; +// static ConcreteLogger logger;  /* Class StringType */ @@ -519,28 +518,28 @@ TEST(StructType, creationWithParent)  	Manager mgr{1};  	Rooted<StructType> structType = createStructType(mgr, logger);  	{ -	Rooted<StructType> structWithParentType = -	    createStructTypeWithParent(structType, mgr, logger); +		Rooted<StructType> structWithParentType = +		    createStructTypeWithParent(structType, mgr, logger); -	Variant val = structWithParentType->create(); -	ASSERT_TRUE(val.isArray()); -	ASSERT_EQ(7U, val.asArray().size()); +		Variant val = structWithParentType->create(); +		ASSERT_TRUE(val.isArray()); +		ASSERT_EQ(7U, val.asArray().size()); -	const auto &arr = val.asArray(); -	ASSERT_TRUE(arr[0].isString()); -	ASSERT_TRUE(arr[1].isString()); -	ASSERT_TRUE(arr[2].isInt()); -	ASSERT_TRUE(arr[3].isInt()); -	ASSERT_TRUE(arr[4].isString()); -	ASSERT_TRUE(arr[5].isInt()); -	ASSERT_TRUE(arr[6].isArray()); +		const auto &arr = val.asArray(); +		ASSERT_TRUE(arr[0].isString()); +		ASSERT_TRUE(arr[1].isString()); +		ASSERT_TRUE(arr[2].isInt()); +		ASSERT_TRUE(arr[3].isInt()); +		ASSERT_TRUE(arr[4].isString()); +		ASSERT_TRUE(arr[5].isInt()); +		ASSERT_TRUE(arr[6].isArray()); -	ASSERT_EQ("attr1default", arr[0].asString()); -	ASSERT_EQ("", arr[1].asString()); -	ASSERT_EQ(3, arr[2].asInt()); -	ASSERT_EQ(0, arr[3].asInt()); -	ASSERT_EQ("value1", arr[4].asString()); -	ASSERT_EQ(42, arr[5].asInt()); +		ASSERT_EQ("attr1default", arr[0].asString()); +		ASSERT_EQ("", arr[1].asString()); +		ASSERT_EQ(3, arr[2].asInt()); +		ASSERT_EQ(0, arr[3].asInt()); +		ASSERT_EQ("value1", arr[4].asString()); +		ASSERT_EQ(42, arr[5].asInt());  	}  } @@ -566,13 +565,13 @@ TEST(StructType, createValidated)  	{  		logger.reset();  		Rooted<StructType> structType{StructType::createValidated( -			mgr, "struct", nullptr, nullptr, -			NodeVector<Attribute>{ -			    new Attribute{mgr, "d", stringType, "attr1default"}, -			    new Attribute{mgr, "b", stringType}, -			    new Attribute{mgr, "c", intType, 3}, -			    new Attribute{mgr, "a", intType}}, -			logger)}; +		    mgr, "struct", nullptr, nullptr, +		    NodeVector<Attribute>{ +		        new Attribute{mgr, "d", stringType, "attr1default"}, +		        new Attribute{mgr, "b", stringType}, +		        new Attribute{mgr, "c", intType, 3}, +		        new Attribute{mgr, "a", intType}}, +		    logger)};  		ASSERT_TRUE(structType->validate(logger));  		ASSERT_EQ(Severity::DEBUG, logger.getMaxEncounteredSeverity());  	} @@ -580,13 +579,13 @@ TEST(StructType, createValidated)  	{  		logger.reset();  		Rooted<StructType> structType{StructType::createValidated( -			mgr, "struct", nullptr, nullptr, -			NodeVector<Attribute>{ -				new Attribute{mgr, "d", stringType, "attr1default"}, -				new Attribute{mgr, "b", stringType}, -				new Attribute{mgr, "a", intType, 3}, -				new Attribute{mgr, "a", intType}}, -			logger)}; +		    mgr, "struct", nullptr, nullptr, +		    NodeVector<Attribute>{ +		        new Attribute{mgr, "d", stringType, "attr1default"}, +		        new Attribute{mgr, "b", stringType}, +		        new Attribute{mgr, "a", intType, 3}, +		        new Attribute{mgr, "a", intType}}, +		    logger)};  		ASSERT_FALSE(structType->validate(logger));  		ASSERT_EQ(Severity::ERROR, logger.getMaxEncounteredSeverity());  	} @@ -594,13 +593,13 @@ TEST(StructType, createValidated)  	{  		logger.reset();  		Rooted<StructType> structType{StructType::createValidated( -			mgr, "struct", nullptr, nullptr, -			NodeVector<Attribute>{ -			    new Attribute{mgr, "d", stringType, "attr1default"}, -			    new Attribute{mgr, "b", stringType}, -			    new Attribute{mgr, "a", intType, 3}, -			    new Attribute{mgr, "a a", intType}}, -			logger)}; +		    mgr, "struct", nullptr, nullptr, +		    NodeVector<Attribute>{ +		        new Attribute{mgr, "d", stringType, "attr1default"}, +		        new Attribute{mgr, "b", stringType}, +		        new Attribute{mgr, "a", intType, 3}, +		        new Attribute{mgr, "a a", intType}}, +		    logger)};  		ASSERT_FALSE(structType->validate(logger));  		ASSERT_EQ(Severity::ERROR, logger.getMaxEncounteredSeverity());  	} @@ -704,7 +703,6 @@ TEST(StructType, build)  		ASSERT_EQ(5, arr[3].asInt());  	} -  	// All mandatory attributes given as array  	{  		Variant var{{"v1", 2, 3, 4}}; @@ -923,7 +921,4 @@ TEST(SystemTypesystem, rtti)  	ASSERT_FALSE(typesystem->composedOf(RttiTypes::Typesystem));  	ASSERT_FALSE(typesystem->composedOf(RttiTypes::SystemTypesystem));  } - - -}  } diff --git a/test/core/parser/StandaloneParserContext.hpp b/test/core/parser/StandaloneParserContext.hpp index 51cd1e6..cae843f 100644 --- a/test/core/parser/StandaloneParserContext.hpp +++ b/test/core/parser/StandaloneParserContext.hpp @@ -34,19 +34,21 @@ public:  	Manager manager;  	Logger logger;  	Registry registry; +	Rooted<Project> project;  	ParserScope scope; -	Rooted<model::Project> project;  	ParserContext context;  	StandaloneParserContext() -	    : project(new model::Project(manager)), -	      context(scope, registry, logger, manager, project) +	    : project(new Project(manager, registry)), +	      context(project, scope, logger)  	{  	}  	StandaloneParserContext(Logger &externalLogger) -	    : project(new model::Project(manager)), -	      context(scope, registry, externalLogger, manager, project){}; +	    : project(new Project(manager, registry)), +	      context(project, scope, externalLogger) +	{ +	}  };  } diff --git a/test/core/resource/ResourceRequestTest.cpp b/test/core/resource/ResourceRequestTest.cpp new file mode 100644 index 0000000..0bb34be --- /dev/null +++ b/test/core/resource/ResourceRequestTest.cpp @@ -0,0 +1,149 @@ +/* +    Ousía +    Copyright (C) 2014, 2015  Benjamin Paaßen, Andreas Stöckel + +    This program 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 3 of the License, or +    (at your option) any later version. + +    This program 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 this program.  If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <gtest/gtest.h> + +#include <iostream> + +#include <core/common/Logger.hpp> +#include <core/common/Rtti.hpp> +#include <core/frontend/TerminalLogger.hpp> +#include <core/parser/Parser.hpp> +#include <core/resource/ResourceRequest.hpp> +#include <core/Registry.hpp> + +namespace ousia { + +namespace RttiTypes { +extern const Rtti Document; +extern const Rtti Domain; +extern const Rtti Typesystem; +} + +static TerminalLogger logger(std::cerr, true); +// static ConcreteLogger logger; + +namespace { +class ModuleParser : public Parser { +protected: +	Rooted<Node> doParse(CharReader &reader, ParserContext &ctx) override +	{ +		return nullptr;  // Stub +	} +}; + +class DocumentParser : public Parser { +protected: +	Rooted<Node> doParse(CharReader &reader, ParserContext &ctx) override +	{ +		return nullptr;  // Stub +	} +}; + +struct TestSetup { +	ModuleParser pModule; +	DocumentParser pDocument; +	Registry registry; + +	TestSetup() +	{ +		registry.registerExtension("domain", "application/domain"); +		registry.registerExtension("typesystem", "application/typesystem"); +		registry.registerExtension("document", "application/document"); +		registry.registerParser( +		    {"application/domain", "application/typesystem"}, +		    {&RttiTypes::Domain, &RttiTypes::Typesystem}, &pModule); +		registry.registerParser({"application/document"}, +		                        {&RttiTypes::Document}, &pDocument); +	} +}; +} + +TEST(ResourceRequest, deduction) +{ +	TestSetup t; + +	ResourceRequest req("test.domain", "", "", {&RttiTypes::Domain}); + +	ASSERT_TRUE(req.deduce(t.registry, logger)); + +	ASSERT_EQ("test.domain", req.getPath()); +	ASSERT_EQ("application/domain", req.getMimetype()); +	ASSERT_EQ(RttiSet({&RttiTypes::Domain}), req.getSupportedTypes()); +	ASSERT_EQ(ResourceType::DOMAIN_DESC, req.getResourceType()); +	ASSERT_EQ(&t.pModule, req.getParser()); +	ASSERT_EQ(RttiSet({&RttiTypes::Domain, &RttiTypes::Typesystem}), +	          req.getParserTypes()); +} + +TEST(ResourceRequest, deductionWithMimetype) +{ +	TestSetup t; + +	ResourceRequest req("test.domain", "application/typesystem", "", +	                    {&RttiTypes::Typesystem}); + +	ASSERT_TRUE(req.deduce(t.registry, logger)); + +	ASSERT_EQ("test.domain", req.getPath()); +	ASSERT_EQ("application/typesystem", req.getMimetype()); +	ASSERT_EQ(RttiSet({&RttiTypes::Typesystem}), req.getSupportedTypes()); +	ASSERT_EQ(ResourceType::TYPESYSTEM, req.getResourceType()); +	ASSERT_EQ(&t.pModule, req.getParser()); +	ASSERT_EQ(RttiSet({&RttiTypes::Domain, &RttiTypes::Typesystem}), +	          req.getParserTypes()); +} + +TEST(ResourceRequest, deductionWithUnknownResourceType) +{ +	TestSetup t; + +	ResourceRequest req("test.domain", "", "", +	                    {&RttiTypes::Domain, &RttiTypes::Typesystem}); + +	ASSERT_TRUE(req.deduce(t.registry, logger)); + +	ASSERT_EQ("test.domain", req.getPath()); +	ASSERT_EQ("application/domain", req.getMimetype()); +	ASSERT_EQ(RttiSet({&RttiTypes::Domain, &RttiTypes::Typesystem}), +	          req.getSupportedTypes()); +	ASSERT_EQ(ResourceType::UNKNOWN, req.getResourceType()); +	ASSERT_EQ(&t.pModule, req.getParser()); +	ASSERT_EQ(RttiSet({&RttiTypes::Domain, &RttiTypes::Typesystem}), +	          req.getParserTypes()); +} + +TEST(ResourceRequest, deductionWithRel) +{ +	TestSetup t; + +	ResourceRequest req("test.domain", "", "domain", +	                    {&RttiTypes::Domain, &RttiTypes::Typesystem}); + +	ASSERT_TRUE(req.deduce(t.registry, logger)); + +	ASSERT_EQ("test.domain", req.getPath()); +	ASSERT_EQ("application/domain", req.getMimetype()); +	ASSERT_EQ(RttiSet({&RttiTypes::Domain}), req.getSupportedTypes()); +	ASSERT_EQ(ResourceType::DOMAIN_DESC, req.getResourceType()); +	ASSERT_EQ(&t.pModule, req.getParser()); +	ASSERT_EQ(RttiSet({&RttiTypes::Domain, &RttiTypes::Typesystem}), +	          req.getParserTypes()); +} +} + diff --git a/test/plugins/css/CSSParserTest.cpp b/test/plugins/css/CSSParserTest.cpp index 5132e51..46b4ebb 100644 --- a/test/plugins/css/CSSParserTest.cpp +++ b/test/plugins/css/CSSParserTest.cpp @@ -266,9 +266,7 @@ void assertException(std::string css)  	CharReader reader(css);  	TerminalLogger logger(std::cerr, true);  	{ -		GuardedLogger sl(logger); -		StandaloneParserContext ctx(sl); - +		StandaloneParserContext ctx(logger);  		CSSParser instance;  		try {  			instance.parse(reader, ctx.context).cast<SelectorNode>(); diff --git a/test/plugins/html/DemoOutputTest.cpp b/test/plugins/html/DemoOutputTest.cpp index 11e5fa6..094b5fd 100644 --- a/test/plugins/html/DemoOutputTest.cpp +++ b/test/plugins/html/DemoOutputTest.cpp @@ -39,18 +39,18 @@ TEST(DemoHTMLTransformer, writeHTML)  	// Construct Manager  	TerminalLogger logger{std::cerr, true};  	Manager mgr{1}; -	Rooted<model::SystemTypesystem> sys{new model::SystemTypesystem(mgr)}; +	Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)};  	// Get the domains. -	Rooted<model::Domain> bookDom = -	    model::constructBookDomain(mgr, sys, logger); -	Rooted<model::Domain> headingDom = -	    model::constructHeadingDomain(mgr, sys, bookDom, logger); -	Rooted<model::Domain> listDom = -	    model::constructListDomain(mgr, sys, bookDom, logger); -	Rooted<model::Domain> emDom = -	    model::constructEmphasisDomain(mgr, sys, logger); +	Rooted<Domain> bookDom = +	    constructBookDomain(mgr, sys, logger); +	Rooted<Domain> headingDom = +	    constructHeadingDomain(mgr, sys, bookDom, logger); +	Rooted<Domain> listDom = +	    constructListDomain(mgr, sys, bookDom, logger); +	Rooted<Domain> emDom = +	    constructEmphasisDomain(mgr, sys, logger);  	// Construct the document. -	Rooted<model::Document> doc = model::constructAdvancedDocument( +	Rooted<Document> doc = constructAdvancedDocument(  	    mgr, logger, bookDom, headingDom, listDom, emDom);  	ASSERT_TRUE(doc != nullptr); @@ -77,29 +77,29 @@ TEST(DemoHTMLTransformer, AnnotationProcessing)  	// Construct Manager  	TerminalLogger logger{std::cerr, true};  	Manager mgr{1}; -	Rooted<model::SystemTypesystem> sys{new model::SystemTypesystem(mgr)}; +	Rooted<SystemTypesystem> sys{new SystemTypesystem(mgr)};  	// Get the domains. -	Rooted<model::Domain> bookDom = -	    model::constructBookDomain(mgr, sys, logger); -	Rooted<model::Domain> emDom = -	    model::constructEmphasisDomain(mgr, sys, logger); +	Rooted<Domain> bookDom = +	    constructBookDomain(mgr, sys, logger); +	Rooted<Domain> emDom = +	    constructEmphasisDomain(mgr, sys, logger);  	// Construct a document only containing overlapping annotations.  	// it has the form: <em>bla<strong>blub</em>bla</strong> -	Rooted<model::Document> doc{new model::Document(mgr, "annotations.oxd")}; +	Rooted<Document> doc{new Document(mgr, "annotations.oxd")};  	doc->addDomains({bookDom, emDom}); -	Rooted<model::StructuredEntity> book = +	Rooted<StructuredEntity> book =  	    buildRootStructuredEntity(doc, logger, {"book"});  	ASSERT_TRUE(book != nullptr); -	Rooted<model::StructuredEntity> p = +	Rooted<StructuredEntity> p =  	    buildStructuredEntity(doc, logger, book, {"paragraph"});  	ASSERT_TRUE(p != nullptr); -	Rooted<model::Anchor> em_start{new model::Anchor(mgr, "1", p)}; +	Rooted<Anchor> em_start{new Anchor(mgr, "1", p)};  	ASSERT_TRUE(addText(logger, doc, p, "bla")); -	Rooted<model::Anchor> strong_start{new model::Anchor(mgr, "2", p)}; +	Rooted<Anchor> strong_start{new Anchor(mgr, "2", p)};  	ASSERT_TRUE(addText(logger, doc, p, "blub")); -	Rooted<model::Anchor> em_end{new model::Anchor(mgr, "3", p)}; +	Rooted<Anchor> em_end{new Anchor(mgr, "3", p)};  	ASSERT_TRUE(addText(logger, doc, p, "bla")); -	Rooted<model::Anchor> strong_end{new model::Anchor(mgr, "4", p)}; +	Rooted<Anchor> strong_end{new Anchor(mgr, "4", p)};  	buildAnnotationEntity(doc, logger, {"emphasized"}, em_start, em_end);  	buildAnnotationEntity(doc, logger, {"strong"}, strong_start, strong_end);  | 
