summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-11-30 23:42:05 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-11-30 23:42:05 +0100
commit58ac684725b4c5c75c94516a2068d8d55e8c348c (patch)
treef455832ac77707947d655f4c4389b45b3b363f38
parent235b98e0d1a2e9e60c440076b5a11c8bf64ba071 (diff)
backup
-rw-r--r--CMakeLists.txt54
-rw-r--r--test/core/LoggerTest.cpp10
-rw-r--r--test/plugins/mozjs/MozJsScriptEngineTest.cpp2
-rw-r--r--test/plugins/xml/XmlParserTest.cpp47
4 files changed, 77 insertions, 36 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f638fd0..da6479b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,7 +21,7 @@
PROJECT(ousia)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
-# Option for enabling testing. Turn on with 'cmake -Dtest=ON'.
+# Option for enabling testing. Turn on with 'cmake -DTEST=ON'.
# TODO: Automatically activate tests if gtest is available
OPTION(TEST "Build all tests." OFF) # Makes boolean 'test' available.
@@ -106,28 +106,34 @@ ADD_LIBRARY(ousia_core
src/core/Logger
src/core/Managed
src/core/Node
- src/core/Parser
src/core/Tokenizer
# src/core/Typesystem
src/core/Utils
- src/core/parser/XmlParser
+ src/core/parser/Parser
src/core/script/Function
src/core/script/Object
src/core/script/ScriptEngine
src/core/script/Variant
)
-TARGET_LINK_LIBRARIES(ousia_core
+# ousia_xml library
+
+ADD_LIBRARY(ousia_xml
+ src/plugins/xml/XmlParser
+)
+
+TARGET_LINK_LIBRARIES(ousia_xml
+ ousia_core
${EXPAT_LIBRARIES}
)
-# ousia_plugin_mozjs library
+# ousia_mozjs library
-ADD_LIBRARY(ousia_plugin_mozjs
+ADD_LIBRARY(ousia_mozjs
src/plugins/mozjs/MozJsScriptEngine
)
-TARGET_LINK_LIBRARIES(ousia_plugin_mozjs
+TARGET_LINK_LIBRARIES(ousia_mozjs
ousia_core
${MOZJS_LIBRARIES}
)
@@ -135,18 +141,10 @@ TARGET_LINK_LIBRARIES(ousia_plugin_mozjs
# If testing is enabled, build the unit tests
IF(TEST)
- #
- # Core Test
- #
-
- # Include the gtest include files and the src directory
INCLUDE_DIRECTORIES(
${GTEST_INCLUDE_DIRS}
- ${EXPAT_INCLUDE_DIRS}
- src/
)
- # Add all unit test files
ADD_EXECUTABLE(ousia_test_core
test/core/BufferedCharReaderTest
test/core/CodeTokenizerTest
@@ -158,7 +156,6 @@ IF(TEST)
test/core/RangeSetTest
test/core/TokenizerTest
test/core/UtilsTest
- test/core/parser/XmlParserTest
test/core/script/FunctionTest
test/core/script/ObjectTest
test/core/script/VariantTest
@@ -169,30 +166,29 @@ IF(TEST)
ousia_core
)
- #
- # Plugin Tests
- #
+ ADD_EXECUTABLE(ousia_test_xml
+ test/plugins/xml/XmlParserTest
+ )
- # Include the gtest include files and the src directory
- INCLUDE_DIRECTORIES(
- ${MOZJS_INCLUDE_DIRS}
- ${GTEST_INCLUDE_DIRS}
- src/
+ TARGET_LINK_LIBRARIES(ousia_test_xml
+ ${GTEST_LIBRARIES}
+ ousia_core
+ ousia_xml
)
- # Add all unit test files
- ADD_EXECUTABLE(ousia_test_plugin_mozjs
+ ADD_EXECUTABLE(ousia_test_mozjs
test/plugins/mozjs/MozJsScriptEngineTest
)
- TARGET_LINK_LIBRARIES(ousia_test_plugin_mozjs
+ TARGET_LINK_LIBRARIES(ousia_test_mozjs
${GTEST_LIBRARIES}
ousia_core
- ousia_plugin_mozjs
+ ousia_mozjs
)
# Register the unit tests
ADD_TEST(ousia_test_core ousia_test_core)
- ADD_TEST(ousia_test_plugin_mozjs ousia_test_plugin_mozjs)
+ ADD_TEST(ousia_test_xml ousia_test_xml)
+ ADD_TEST(ousia_test_mozjs ousia_test_mozjs)
ENDIF()
diff --git a/test/core/LoggerTest.cpp b/test/core/LoggerTest.cpp
index 4badc28..7031dc7 100644
--- a/test/core/LoggerTest.cpp
+++ b/test/core/LoggerTest.cpp
@@ -26,17 +26,23 @@ namespace ousia {
TEST(TerminalLogger, log)
{
+ // Test for manual visual expection only -- no assertions
TerminalLogger logger{std::cerr, true};
- logger.pushFilename("/homes/mmuster/ousia/test.odp");
+ logger.pushFilename("test.odp");
logger.debug("This is a test debug message", 10, 20);
+ logger.debug("This is a test debug message with no column", 10);
+ logger.debug("This is a test debug message with no line");
+ logger.debug("This is a test debug message with no file", "");
+ logger.debug("This is a test debug message with no file but a line", "", 10);
+ logger.debug("This is a test debug message with no file but a line and a column", "", 10, 20);
logger.note("This is a test note", 10, 20);
logger.warning("This is a test warning", 10, 20);
logger.error("This is a test error", 10, 20);
logger.fatalError("This is a test fatal error!", 10, 20);
try {
- throw LoggableException{"A fatal exception", true};
+ throw LoggableException{"A fatal exception"};
} catch (const LoggableException &ex) {
logger.log(ex);
}
diff --git a/test/plugins/mozjs/MozJsScriptEngineTest.cpp b/test/plugins/mozjs/MozJsScriptEngineTest.cpp
index 96e6cf6..da88acb 100644
--- a/test/plugins/mozjs/MozJsScriptEngineTest.cpp
+++ b/test/plugins/mozjs/MozJsScriptEngineTest.cpp
@@ -25,6 +25,7 @@
namespace ousia {
namespace script {
+namespace mozjs {
/* Global engine object */
MozJsScriptEngine engine;
@@ -37,4 +38,5 @@ auto scope = std::unique_ptr<MozJsScriptEngineScope>{engine.createScope()};
}
}
+}
diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp
index d2c4410..98a5a34 100644
--- a/test/plugins/xml/XmlParserTest.cpp
+++ b/test/plugins/xml/XmlParserTest.cpp
@@ -20,18 +20,55 @@
#include <gtest/gtest.h>
-#include <core/parser/XmlParser.hpp>
+#include <plugins/xml/XmlParser.hpp>
namespace ousia {
+namespace parser {
+namespace xml {
-TEST(XmlParser, logging)
+struct TestParserContext : public ParserContext {
+
+private:
+ Logger log;
+ Registry r;
+ Scope s;
+
+public:
+ TestParserContext() : ParserContext(s, r, log), r(log), s(nullptr) {};
+
+};
+
+TEST(XmlParser, mismatchedTagException)
+{
+ TestParserContext ctx;
+ XmlParser p;
+
+ bool hadException = false;
+ try {
+ p.parse("<test foo=\"bar\">data<![CDATA[bla]]>\n</btest>", ctx);
+ }
+ catch (ParserException ex) {
+ ASSERT_EQ(2, ex.line);
+ ASSERT_FALSE(ex.fatal);
+ hadException = true;
+ }
+ ASSERT_TRUE(hadException);
+}
+
+const char* TEST_DATA = "<?xml version=\"1.0\" standalone=\"yes\"?>\n"
+ "<document a:bc=\"b\">\n"
+ " <bla:test xmlAttr=\"blub\" />\n"
+ "</document>\n";
+
+TEST(XmlParser, namespaces)
{
- TerminalLogger log(std::cerr, true);
+ TestParserContext ctx;
XmlParser p;
- log.pushFilename("test.xml");
- p.parse("<test></btest>", nullptr, log);
+ p.parse(TEST_DATA, ctx);
}
}
+}
+}