diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/core/BufferedCharReaderTest.cpp | 185 | ||||
-rw-r--r-- | test/core/CodeTokenizerTest.cpp | 26 | ||||
-rw-r--r-- | test/core/LoggerTest.cpp | 74 | ||||
-rw-r--r-- | test/core/RegistryTest.cpp | 2 | ||||
-rw-r--r-- | test/core/TokenizerTest.cpp | 14 | ||||
-rw-r--r-- | test/core/common/CharReaderTest.cpp (renamed from test/core/utils/CharReaderTest.cpp) | 73 | ||||
-rw-r--r-- | test/core/common/LoggerTest.cpp | 102 | ||||
-rw-r--r-- | test/core/common/UtilsTest.cpp (renamed from test/core/UtilsTest.cpp) | 2 | ||||
-rw-r--r-- | test/core/common/VariantReaderTest.cpp (renamed from test/core/variant/ReaderTest.cpp) | 155 | ||||
-rw-r--r-- | test/core/common/VariantTest.cpp (renamed from test/core/variant/VariantTest.cpp) | 2 | ||||
-rw-r--r-- | test/plugins/css/CSSParserTest.cpp | 16 | ||||
-rw-r--r-- | test/plugins/xml/XmlParserTest.cpp | 2 |
12 files changed, 258 insertions, 395 deletions
diff --git a/test/core/BufferedCharReaderTest.cpp b/test/core/BufferedCharReaderTest.cpp deleted file mode 100644 index b3498f7..0000000 --- a/test/core/BufferedCharReaderTest.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - 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 <string> -#include <iostream> - -#include "gtest/gtest.h" - -#include <core/BufferedCharReader.hpp> - -namespace ousia{ - -TEST(BufferedCharReaderTest, SimpleReadTest) -{ - std::string testStr{"this is a test"}; - char c; - - // Feed a test string into the reader - BufferedCharReader reader{testStr}; - - // Try to read the test string - std::string res; - while (!reader.atEnd()) { - ASSERT_TRUE(reader.read(&c)); - res.append(&c, 1); - } - - // The two strings must equal - ASSERT_STREQ(testStr.c_str(), res.c_str()) ; - - // We must now be at line 1, column 15 - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(testStr.size() + 1, reader.getColumn()); - - // If we call either read or peek, false is returned - ASSERT_FALSE(reader.read(&c)); - ASSERT_FALSE(reader.peek(&c)); -} - -TEST(BufferedCharReaderTest, SimplePeekTest) -{ - std::string testStr{"this is a test"}; - char c; - - // Feed a test string into the reader - BufferedCharReader reader{testStr}; - - // Try to read the test string - std::string res; - while (reader.peek(&c)) { - res.append(&c, 1); - } - - // Peeking does not trigger the "atEnd" flag - ASSERT_FALSE(reader.atEnd()); - - // The two strings must equal - ASSERT_STREQ(testStr.c_str(), res.c_str()); - - // We must now be at line 1, column 1 and NOT at the end of the stream - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(1, reader.getColumn()); - ASSERT_FALSE(reader.atEnd()); - - // If we consume the peek, we must be at line 1, column 15 and we should be - // at the end of the stream - reader.consumePeek(); - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(testStr.size() + 1, reader.getColumn()); - ASSERT_TRUE(reader.atEnd()); - - // If we call either read or peek, false is returned - ASSERT_FALSE(reader.read(&c)); - ASSERT_FALSE(reader.peek(&c)); -} - -TEST(BufferedCharReaderTest, SplittedPeakTest) -{ - std::string testStr{"this is a test"}; - char c; - - // Feed a test string into the reader - BufferedCharReader reader; - - // Try to peek the test string, feed char after char into the reader - std::string res; - for (unsigned int i = 0; i < testStr.length(); i++) { - reader.feed(std::string(&testStr[i], 1)); - while (reader.peek(&c)) { - res.append(&c, 1); - } - } - reader.close(); - - // Consume the peeked data - ASSERT_FALSE(reader.atEnd()); - reader.consumePeek(); - ASSERT_TRUE(reader.atEnd()); - - // The two strings must equal - ASSERT_STREQ(testStr.c_str(), res.c_str()) ; - - // We must now be at line 1, column 15 - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(testStr.size() + 1, reader.getColumn()); - - // If we call either read or peek, false is returned - ASSERT_FALSE(reader.read(&c)); - ASSERT_FALSE(reader.peek(&c)); -} - -TEST(BufferedCharReaderTest, RowColumnCounterTest) -{ - // Feed a test string into the reader - BufferedCharReader reader{"1\n\r2\n3\r\n\n4"}; - - // We should currently be in line 1, column 1 - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(1, reader.getColumn()); - - // Read two characters - char c; - for (int i = 0; i < 2; i++) reader.read(&c); - ASSERT_EQ(2, reader.getLine()); - ASSERT_EQ(1, reader.getColumn()); - - // Read two characters - for (int i = 0; i < 2; i++) reader.read(&c); - ASSERT_EQ(3, reader.getLine()); - ASSERT_EQ(1, reader.getColumn()); - - // Read three characters - for (int i = 0; i < 3; i++) reader.read(&c); - ASSERT_EQ(5, reader.getLine()); - ASSERT_EQ(1, reader.getColumn()); -} - -TEST(BufferedCharReaderTest, LinebreakSubstitutionTest) -{ - // Feed a test string into the reader - BufferedCharReader reader{"this\n\ris\n\rjust\na test\r\n\rtest\n\r"}; - - // Read all characters from the test string - std::string res; - char c; - while (reader.read(&c)) { - res.append(&c, 1); - } - - // Test for equality - ASSERT_STREQ("this\nis\njust\na test\n\ntest\n", res.c_str()); -} - -TEST(BufferedCharReaderTest, RowColumnCounterUTF8Test) -{ - // Feed a test string with some umlauts into the reader - BufferedCharReader reader{"\x61\xc3\x96\xc3\x84\xc3\x9c\xc3\x9f"}; - - // Read all bytes - char c; - while (reader.read(&c)); - - // The sequence above equals 5 UTF-8 characters (so after reading all the - // cursor is at position 6) - ASSERT_EQ(1, reader.getLine()); - ASSERT_EQ(6, reader.getColumn()); -} - -} - diff --git a/test/core/CodeTokenizerTest.cpp b/test/core/CodeTokenizerTest.cpp index 1432564..4d11622 100644 --- a/test/core/CodeTokenizerTest.cpp +++ b/test/core/CodeTokenizerTest.cpp @@ -32,15 +32,15 @@ static const int CURLY_CLOSE = 41; TEST(CodeTokenizer, testTokenizer) { - BufferedCharReader reader; - reader.feed("/**\n"); // 1 - reader.feed(" * Some Block Comment\n"); // 2 - reader.feed(" */\n"); // 3 - reader.feed("var my_string = 'My \\'String\\'';\n"); // 4 - reader.feed("// and a line comment\n"); // 5 - reader.feed("var my_obj = { a = 4;}"); // 6 - // 123456789012345678901234567890123456789 - // 0 1 2 3 + CharReader reader{ + "/**\n" // 1 + " * Some Block Comment\n" // 2 + " */\n" // 3 + "var my_string = 'My \\'String\\'';\n" // 4 + "// and a line comment\n" // 5 + "var my_obj = { a = 4;}"}; // 6 + // 123456789012345678901234567890123456789 + // 0 1 2 3 TokenTreeNode root{{{"/*", 1}, {"*/", 2}, {"//", 3}, @@ -68,10 +68,10 @@ TEST(CodeTokenizer, testTokenizer) {STRING, "My 'String'", 17, 4, 32, 4}, {TOKEN_TEXT, ";", 32, 4, 33, 4}, {LINEBREAK, "\n", 33, 4, 1, 5}, - //this is slightly counter-intuitive but makes sense if you think about - //it: As a line comment is ended by a line break the line break is - //technically still a part of the line comment and thus the ending - //is in the next line. + // this is slightly counter-intuitive but makes sense if you think about + // it: As a line comment is ended by a line break the line break is + // technically still a part of the line comment and thus the ending + // is in the next line. {LINE_COMMENT, " and a line comment", 1, 5, 1, 6}, {TOKEN_TEXT, "var", 1, 6, 4, 6}, {TOKEN_TEXT, "my_obj", 5, 6, 11, 6}, diff --git a/test/core/LoggerTest.cpp b/test/core/LoggerTest.cpp deleted file mode 100644 index abb76de..0000000 --- a/test/core/LoggerTest.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - 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 <iostream> - -#include <gtest/gtest.h> - -#include <core/Logger.hpp> - -namespace ousia { - -struct Pos { - int line, column; - Pos(int line, int column) : line(line), column(column){}; - int getLine() const { return line; } - int getColumn() const { return column; } -}; - -TEST(TerminalLogger, log) -{ - // Test for manual visual expection only -- no assertions - TerminalLogger logger{std::cerr, true}; - 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{"An exception"}; - } - catch (const LoggableException &ex) { - logger.log(ex); - } - - try { - throw LoggableException{"An exception at position", Pos(10, 20)}; - } - catch (const LoggableException &ex) { - logger.log(ex); - } - - logger.logAt(Severity::ERROR, "This is a positioned log message", - Pos(10, 20)); - logger.debugAt("This is a positioned debug message", Pos(10, 20)); - logger.noteAt("This is a positioned log error", Pos(10, 20)); -} -} - diff --git a/test/core/RegistryTest.cpp b/test/core/RegistryTest.cpp index 4450227..8280188 100644 --- a/test/core/RegistryTest.cpp +++ b/test/core/RegistryTest.cpp @@ -22,7 +22,7 @@ #include <sstream> -#include <core/Logger.hpp> +#include <core/common/Logger.hpp> namespace ousia { diff --git a/test/core/TokenizerTest.cpp b/test/core/TokenizerTest.cpp index da6b578..2b80662 100644 --- a/test/core/TokenizerTest.cpp +++ b/test/core/TokenizerTest.cpp @@ -18,7 +18,7 @@ #include <gtest/gtest.h> -#include <core/BufferedCharReader.hpp> +#include <core/common/CharReader.hpp> #include <core/Tokenizer.hpp> @@ -65,10 +65,9 @@ TEST(Tokenizer, testTokenization) { TokenTreeNode root{{{"/", 1}, {"/*", 2}, {"*/", 3}}}; - BufferedCharReader reader; - reader.feed("Test/Test /* Block Comment */"); - // 12345678901234567890123456789 - // 0 1 2 + CharReader reader{"Test/Test /* Block Comment */"}; + // 12345678901234567890123456789 + // 0 1 2 std::vector<Token> expected = { {TOKEN_TEXT, "Test", 1, 1, 5, 1}, @@ -97,10 +96,7 @@ TEST(Tokenizer, testIncompleteTokens) { TokenTreeNode root{{{"ab", 1}, {"c", 2}}}; - BufferedCharReader reader; - reader.feed("ac"); - // 1234567890 - // 0 1 + CharReader reader{"ac"}; std::vector<Token> expected = { {TOKEN_TEXT, "a", 1, 1, 2, 1}, diff --git a/test/core/utils/CharReaderTest.cpp b/test/core/common/CharReaderTest.cpp index d5c7aad..9c1026c 100644 --- a/test/core/utils/CharReaderTest.cpp +++ b/test/core/common/CharReaderTest.cpp @@ -22,10 +22,9 @@ #include "gtest/gtest.h" -#include <core/utils/CharReader.hpp> +#include <core/common/CharReader.hpp> namespace ousia { -namespace utils { /* Test data */ @@ -95,6 +94,8 @@ TEST(Buffer, simpleRead) // The two strings must equal ASSERT_EQ(testStr, res); + + buf.deleteCursor(cursor); } TEST(Buffer, cursorManagement) @@ -112,6 +113,10 @@ TEST(Buffer, cursorManagement) buf.deleteCursor(c2); Buffer::CursorId c4 = buf.createCursor(); ASSERT_EQ(1U, c4); + + buf.deleteCursor(c1); + buf.deleteCursor(c3); + buf.deleteCursor(c4); } TEST(Buffer, twoCursors) @@ -152,6 +157,9 @@ TEST(Buffer, twoCursors) // The two strings must equal ASSERT_EQ(testStr, res1); ASSERT_EQ(testStr, res2); + + buf.deleteCursor(cur1); + buf.deleteCursor(cur2); } TEST(Buffer, copyCursors) @@ -203,6 +211,10 @@ TEST(Buffer, copyCursors) ASSERT_EQ("test3", res3); ASSERT_TRUE(buf.atEnd(cur3)); + + buf.deleteCursor(cur1); + buf.deleteCursor(cur2); + buf.deleteCursor(cur3); } TEST(Buffer, moveCursor) @@ -260,6 +272,8 @@ TEST(Buffer, moveCursor) } ASSERT_EQ("test3", res); } + + buf.deleteCursor(cursor); } struct VectorReadState { @@ -302,6 +316,8 @@ TEST(Buffer, simpleStream) // The read data and the original data must be equal ASSERT_EQ(DATA, res); + + buf.deleteCursor(cursor); } TEST(Buffer, streamTwoCursors) @@ -337,6 +353,9 @@ TEST(Buffer, streamTwoCursors) // The read data and the original data must be equal ASSERT_EQ(DATA, res1); ASSERT_EQ(DATA, res2); + + buf.deleteCursor(cur1); + buf.deleteCursor(cur2); } TEST(Buffer, streamTwoCursorsMovingInterleaved) @@ -386,6 +405,9 @@ TEST(Buffer, streamTwoCursorsMovingInterleaved) // The read data and the original data must be equal ASSERT_EQ(DATA, res1); ASSERT_EQ(DATA, res2); + + buf.deleteCursor(cur1); + buf.deleteCursor(cur2); } TEST(Buffer, streamMoveForward) @@ -407,6 +429,8 @@ TEST(Buffer, streamMoveForward) res.push_back(c); } ASSERT_EQ(partialData, res); + + buf.deleteCursor(cursor); } /* CharReader Test */ @@ -636,8 +660,8 @@ TEST(CharReaderTest, context) // Retrieval at beginning of stream { CharReader reader{testStr}; - CharReader::Context ctx = reader.getContext(80); - ASSERT_EQ("first line", ctx.line); + TextCursor::Context ctx = reader.getContext(80); + ASSERT_EQ("first line", ctx.text); ASSERT_EQ(0U, ctx.relPos); ASSERT_FALSE(ctx.truncatedStart); ASSERT_FALSE(ctx.truncatedEnd); @@ -646,13 +670,13 @@ TEST(CharReaderTest, context) // Retrieval in middle of line { CharReader reader{testStr}; - CharReader::Context ctx = reader.getContext(80); + TextCursor::Context ctx = reader.getContext(80); char c; for (int i = 0; i < 5; i++) reader.read(c); - ASSERT_EQ("first line", ctx.line); + ASSERT_EQ("first line", ctx.text); ASSERT_EQ(0U, ctx.relPos); ASSERT_FALSE(ctx.truncatedStart); ASSERT_FALSE(ctx.truncatedEnd); @@ -666,8 +690,8 @@ TEST(CharReaderTest, context) for (int i = 0; i < 11; i++) reader.read(c); - CharReader::Context ctx = reader.getContext(80); - ASSERT_EQ("first line", ctx.line); + TextCursor::Context ctx = reader.getContext(80); + ASSERT_EQ("first line", ctx.text); ASSERT_EQ(10U, ctx.relPos); ASSERT_FALSE(ctx.truncatedStart); ASSERT_FALSE(ctx.truncatedEnd); @@ -681,8 +705,8 @@ TEST(CharReaderTest, context) for (int i = 0; i < 5; i++) reader.read(c); - CharReader::Context ctx = reader.getContext(3); - ASSERT_EQ("t l", ctx.line); + TextCursor::Context ctx = reader.getContext(3); + ASSERT_EQ("t l", ctx.text); ASSERT_EQ(1U, ctx.relPos); ASSERT_TRUE(ctx.truncatedStart); ASSERT_TRUE(ctx.truncatedEnd); @@ -696,8 +720,8 @@ TEST(CharReaderTest, context) for (int i = 0; i < 12; i++) reader.read(c); - CharReader::Context ctx = reader.getContext(80); - ASSERT_EQ("second line", ctx.line); + TextCursor::Context ctx = reader.getContext(80); + ASSERT_EQ("second line", ctx.text); ASSERT_EQ(0U, ctx.relPos); ASSERT_FALSE(ctx.truncatedStart); ASSERT_FALSE(ctx.truncatedEnd); @@ -711,8 +735,8 @@ TEST(CharReaderTest, context) for (int i = 0; i < 23; i++) reader.read(c); - CharReader::Context ctx = reader.getContext(80); - ASSERT_EQ("second line", ctx.line); + TextCursor::Context ctx = reader.getContext(80); + ASSERT_EQ("second line", ctx.text); ASSERT_EQ(11U, ctx.relPos); ASSERT_FALSE(ctx.truncatedStart); ASSERT_FALSE(ctx.truncatedEnd); @@ -726,8 +750,8 @@ TEST(CharReaderTest, context) for (int i = 0; i < 24; i++) reader.read(c); - CharReader::Context ctx = reader.getContext(80); - ASSERT_EQ("last line", ctx.line); + TextCursor::Context ctx = reader.getContext(80); + ASSERT_EQ("last line", ctx.text); ASSERT_EQ(0U, ctx.relPos); ASSERT_FALSE(ctx.truncatedStart); ASSERT_FALSE(ctx.truncatedEnd); @@ -741,8 +765,8 @@ TEST(CharReaderTest, context) for (int i = 0; i < 28; i++) reader.read(c); - CharReader::Context ctx = reader.getContext(80); - ASSERT_EQ("last line", ctx.line); + TextCursor::Context ctx = reader.getContext(80); + ASSERT_EQ("last line", ctx.text); ASSERT_EQ(4U, ctx.relPos); ASSERT_FALSE(ctx.truncatedStart); ASSERT_FALSE(ctx.truncatedEnd); @@ -756,8 +780,8 @@ TEST(CharReaderTest, context) for (int i = 0; i < 28; i++) reader.read(c); - CharReader::Context ctx = reader.getContext(3); - ASSERT_EQ("t l", ctx.line); + TextCursor::Context ctx = reader.getContext(3); + ASSERT_EQ("t l", ctx.text); ASSERT_EQ(1U, ctx.relPos); ASSERT_TRUE(ctx.truncatedStart); ASSERT_TRUE(ctx.truncatedEnd); @@ -771,8 +795,8 @@ TEST(CharReaderTest, context) for (int i = 0; i < 100; i++) reader.read(c); - CharReader::Context ctx = reader.getContext(80); - ASSERT_EQ("last line", ctx.line); + TextCursor::Context ctx = reader.getContext(80); + ASSERT_EQ("last line", ctx.text); ASSERT_EQ(9U, ctx.relPos); ASSERT_FALSE(ctx.truncatedStart); ASSERT_FALSE(ctx.truncatedEnd); @@ -786,13 +810,12 @@ TEST(CharReaderTest, context) for (int i = 0; i < 100; i++) reader.read(c); - CharReader::Context ctx = reader.getContext(4); - ASSERT_EQ("line", ctx.line); + TextCursor::Context ctx = reader.getContext(4); + ASSERT_EQ("line", ctx.text); ASSERT_EQ(4U, ctx.relPos); ASSERT_TRUE(ctx.truncatedStart); ASSERT_FALSE(ctx.truncatedEnd); } } } -} diff --git a/test/core/common/LoggerTest.cpp b/test/core/common/LoggerTest.cpp new file mode 100644 index 0000000..cc9f701 --- /dev/null +++ b/test/core/common/LoggerTest.cpp @@ -0,0 +1,102 @@ +/* + 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 <iostream> + +#include <gtest/gtest.h> + +#include <core/common/Logger.hpp> + +namespace ousia { + +struct Pos { + TextCursor::Position pos; + TextCursor::Context ctx; + + Pos(TextCursor::Position pos = TextCursor::Position{}, + TextCursor::Context ctx = TextCursor::Context{}) + : pos(pos), ctx(ctx){}; + + TextCursor::Position getPosition() { return pos; } + TextCursor::Context getContext() { return ctx; } +}; + +TEST(TerminalLogger, log) +{ + // Test for manual visual expection only -- no assertions + TerminalLogger logger{std::cerr, true}; + logger.pushFile("test.odp"); + + logger.debug("This is a test debug message", TextCursor::Position{10, 20}); + logger.debug("This is a test debug message with no column", + TextCursor::Position{10}); + logger.debug("This is a test debug message with no line"); + logger.note("This is a test note", TextCursor::Position{10, 20}); + logger.warning("This is a test warning", TextCursor::Position{10, 20}); + logger.error("This is a test error", TextCursor::Position{10, 20}); + logger.fatalError("This is a test fatal error!", + TextCursor::Position{10, 20}); + + logger.error("This is a test error with context", + TextCursor::Position{10, 20}, + TextCursor::Context{"int bla = blub;", 10, true, false}); + + Pos pos(TextCursor::Position{10, 20}); + + try { + throw LoggableException{"An exception"}; + } + catch (const LoggableException &ex) { + logger.log(ex); + } + + try { + throw LoggableException{"An exception at position", pos}; + } + catch (const LoggableException &ex) { + logger.log(ex); + } + + logger.logAt(Severity::ERROR, "This is a positioned log message", pos); +} + +TEST(TerminalLogger, fork) +{ + // Test for manual visual expection only -- no assertions + TerminalLogger logger{std::cerr, true}; + + LoggerFork fork = logger.fork(); + + fork.pushFile("test.odp"); + fork.error("This is a test error with context", + TextCursor::Position{10, 20}, + TextCursor::Context{"int bla = blub;", 10, true, false}); + fork.pushFile("test2.odp"); + fork.error("This is a test error without context"); + fork.popFile(); + fork.error("Another error"); + fork.popFile(); + fork.error("Another error"); + + // Print all error messages + fork.commit(); +} + + +} + diff --git a/test/core/UtilsTest.cpp b/test/core/common/UtilsTest.cpp index 0a7d2a3..2858038 100644 --- a/test/core/UtilsTest.cpp +++ b/test/core/common/UtilsTest.cpp @@ -18,7 +18,7 @@ #include <gtest/gtest.h> -#include <core/Utils.hpp> +#include <core/common/Utils.hpp> namespace ousia { diff --git a/test/core/variant/ReaderTest.cpp b/test/core/common/VariantReaderTest.cpp index 595bb57..d9bb74e 100644 --- a/test/core/variant/ReaderTest.cpp +++ b/test/core/common/VariantReaderTest.cpp @@ -19,7 +19,7 @@ #include <iostream> #include <gtest/gtest.h> -#include <core/variant/Reader.hpp> +#include <core/common/VariantReader.hpp> namespace ousia { namespace variant { @@ -31,32 +31,32 @@ TEST(Reader, readString) { // Simple, double quoted string { - BufferedCharReader reader("\"hello world\""); - auto res = Reader::parseString(reader, logger); + CharReader reader("\"hello world\""); + auto res = VariantReader::parseString(reader, logger); ASSERT_TRUE(res.first); ASSERT_EQ("hello world", res.second); } // Simple, double quoted string with whitespace { - BufferedCharReader reader(" \"hello world\" "); - auto res = Reader::parseString(reader, logger); + CharReader reader(" \"hello world\" "); + auto res = VariantReader::parseString(reader, logger); ASSERT_TRUE(res.first); ASSERT_EQ("hello world", res.second); } // Simple, single quoted string { - BufferedCharReader reader("'hello world'"); - auto res = Reader::parseString(reader, logger); + CharReader reader("'hello world'"); + auto res = VariantReader::parseString(reader, logger); ASSERT_TRUE(res.first); ASSERT_EQ("hello world", res.second); } // Escape characters { - BufferedCharReader reader("'\\'\\\"\\b\\f\\n\\r\\t\\v'"); - auto res = Reader::parseString(reader, logger); + CharReader reader("'\\'\\\"\\b\\f\\n\\r\\t\\v'"); + auto res = VariantReader::parseString(reader, logger); ASSERT_TRUE(res.first); ASSERT_EQ("'\"\b\f\n\r\t\v", res.second); } @@ -66,32 +66,32 @@ TEST(Reader, parseUnescapedString) { // Simple case { - BufferedCharReader reader("hello world;"); - auto res = Reader::parseUnescapedString(reader, logger, {';'}); + CharReader reader("hello world;"); + auto res = VariantReader::parseUnescapedString(reader, logger, {';'}); ASSERT_TRUE(res.first); ASSERT_EQ("hello world", res.second); } // Simple case with whitespace { - BufferedCharReader reader(" hello world ; "); - auto res = Reader::parseUnescapedString(reader, logger, {';'}); + CharReader reader(" hello world ; "); + auto res = VariantReader::parseUnescapedString(reader, logger, {';'}); ASSERT_TRUE(res.first); ASSERT_EQ("hello world", res.second); } // Linebreaks { - BufferedCharReader reader(" hello\nworld ; "); - auto res = Reader::parseUnescapedString(reader, logger, {';'}); + CharReader reader(" hello\nworld ; "); + auto res = VariantReader::parseUnescapedString(reader, logger, {';'}); ASSERT_TRUE(res.first); ASSERT_EQ("hello\nworld", res.second); } // End of stream { - BufferedCharReader reader(" hello world "); - auto res = Reader::parseUnescapedString(reader, logger, {';'}); + CharReader reader(" hello world "); + auto res = VariantReader::parseUnescapedString(reader, logger, {';'}); ASSERT_TRUE(res.first); ASSERT_EQ("hello world", res.second); } @@ -103,76 +103,76 @@ TEST(Reader, parseInteger) { // Valid integers { - BufferedCharReader reader("0 "); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader("0 "); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(0, res.second); } { - BufferedCharReader reader("42 "); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader("42 "); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(42, res.second); } { - BufferedCharReader reader("-42"); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader("-42"); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(-42, res.second); } { - BufferedCharReader reader(" -0x4A2 "); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader(" -0x4A2 "); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(-0x4A2, res.second); } { - BufferedCharReader reader(" 0Xaffe"); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader(" 0Xaffe"); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(0xAFFE, res.second); } { - BufferedCharReader reader("0x7FFFFFFFFFFFFFFF"); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader("0x7FFFFFFFFFFFFFFF"); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(0x7FFFFFFFFFFFFFFFL, res.second); } { - BufferedCharReader reader("-0x7FFFFFFFFFFFFFFF"); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader("-0x7FFFFFFFFFFFFFFF"); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(-0x7FFFFFFFFFFFFFFFL, res.second); } // Invalid integers { - BufferedCharReader reader("-"); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader("-"); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_FALSE(res.first); } { - BufferedCharReader reader("0a"); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader("0a"); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_FALSE(res.first); } { - BufferedCharReader reader("-0xag"); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader("-0xag"); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_FALSE(res.first); } { - BufferedCharReader reader("0x8000000000000000"); - auto res = Reader::parseInteger(reader, logger, noDelim); + CharReader reader("0x8000000000000000"); + auto res = VariantReader::parseInteger(reader, logger, noDelim); ASSERT_FALSE(res.first); } } @@ -181,64 +181,64 @@ TEST(Reader, parseDouble) { // Valid doubles { - BufferedCharReader reader("1.25"); - auto res = Reader::parseDouble(reader, logger, noDelim); + CharReader reader("1.25"); + auto res = VariantReader::parseDouble(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(1.25, res.second); } { - BufferedCharReader reader(".25"); - auto res = Reader::parseDouble(reader, logger, noDelim); + CharReader reader(".25"); + auto res = VariantReader::parseDouble(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(.25, res.second); } { - BufferedCharReader reader(".25e1"); - auto res = Reader::parseDouble(reader, logger, noDelim); + CharReader reader(".25e1"); + auto res = VariantReader::parseDouble(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(2.5, res.second); } { - BufferedCharReader reader("-2.5e-1"); - auto res = Reader::parseDouble(reader, logger, noDelim); + CharReader reader("-2.5e-1"); + auto res = VariantReader::parseDouble(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(-0.25, res.second); } { - BufferedCharReader reader("-50e-2"); - auto res = Reader::parseDouble(reader, logger, noDelim); + CharReader reader("-50e-2"); + auto res = VariantReader::parseDouble(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(-0.5, res.second); } { - BufferedCharReader reader("-1."); - auto res = Reader::parseDouble(reader, logger, noDelim); + CharReader reader("-1."); + auto res = VariantReader::parseDouble(reader, logger, noDelim); ASSERT_TRUE(res.first); ASSERT_EQ(-1., res.second); } { - BufferedCharReader reader("-50.e-2"); - auto res = Reader::parseDouble(reader, logger, {'.'}); + CharReader reader("-50.e-2"); + auto res = VariantReader::parseDouble(reader, logger, {'.'}); ASSERT_TRUE(res.first); ASSERT_EQ(-50, res.second); } // Invalid doubles { - BufferedCharReader reader(".e1"); - auto res = Reader::parseDouble(reader, logger, noDelim); + CharReader reader(".e1"); + auto res = VariantReader::parseDouble(reader, logger, noDelim); ASSERT_FALSE(res.first); } { - BufferedCharReader reader("0e100000"); - auto res = Reader::parseDouble(reader, logger, noDelim); + CharReader reader("0e100000"); + auto res = VariantReader::parseDouble(reader, logger, noDelim); ASSERT_FALSE(res.first); } } @@ -247,13 +247,13 @@ TEST(Reader, parseArray) { // Simple case (only primitive data types) { - BufferedCharReader reader("[\"Hello, World\", unescaped\n string ,\n" + CharReader reader("[\"Hello, World\", unescaped\n string ,\n" "1234, 0.56, true, false, null]"); - auto res = Reader::parseArray(reader, logger); + auto res = VariantReader::parseArray(reader, logger); ASSERT_TRUE(res.first); // Make sure array has the correct size - ASSERT_EQ(7, res.second.size()); + ASSERT_EQ(7U, res.second.size()); // Check the types ASSERT_TRUE(res.second[0].isString()); @@ -275,12 +275,12 @@ TEST(Reader, parseArray) // Ending with comma { - BufferedCharReader reader("[ 'test' ,]"); - auto res = Reader::parseArray(reader, logger); + CharReader reader("[ 'test' ,]"); + auto res = VariantReader::parseArray(reader, logger); ASSERT_TRUE(res.first); // Make sure the array has the correct size - ASSERT_EQ(1, res.second.size()); + ASSERT_EQ(1U, res.second.size()); // Check the types ASSERT_TRUE(res.second[0].isString()); @@ -290,22 +290,23 @@ TEST(Reader, parseArray) } // Recovery from invalid values - // TODO: Actually parseGeneric should fall back to returning a simple string - // if parsing of a special (non-string) type failed { - BufferedCharReader reader("[ 0invalidNumber, str, 1invalid]"); - auto res = Reader::parseArray(reader, logger); - ASSERT_FALSE(res.first); + CharReader reader("[ 0invalidNumber, str, 1invalid]"); + auto res = VariantReader::parseArray(reader, logger); + ASSERT_TRUE(res.first); // Make sure the array has the correct size - ASSERT_EQ(3, res.second.size()); + ASSERT_EQ(3U, res.second.size()); - // Check the types (only for the valid entries, the other types are - // undefined) + // Check the types (all must be strings since the numbers are invalid) + ASSERT_TRUE(res.second[0].isString()); ASSERT_TRUE(res.second[1].isString()); + ASSERT_TRUE(res.second[2].isString()); // Check the values + ASSERT_EQ("0invalidNumber", res.second[0].asString()); ASSERT_EQ("str", res.second[1].asString()); + ASSERT_EQ("1invalid", res.second[2].asString()); } } @@ -313,8 +314,8 @@ TEST(Reader, parseGeneric) { // Simple case, unescaped string { - BufferedCharReader reader("hello world"); - auto res = Reader::parseGeneric(reader, logger, {';'}); + CharReader reader("hello world"); + auto res = VariantReader::parseGeneric(reader, logger, {';'}); ASSERT_TRUE(res.first); ASSERT_TRUE(res.second.isString()); ASSERT_EQ("hello world", res.second.asString()); @@ -322,8 +323,8 @@ TEST(Reader, parseGeneric) // Simple case, double quoted string { - BufferedCharReader reader(" \"hello world\" "); - auto res = Reader::parseGeneric(reader, logger, {';'}); + CharReader reader(" \"hello world\" "); + auto res = VariantReader::parseGeneric(reader, logger, {';'}); ASSERT_TRUE(res.first); ASSERT_TRUE(res.second.isString()); ASSERT_EQ("hello world", res.second.asString()); @@ -331,8 +332,8 @@ TEST(Reader, parseGeneric) // Simple case, single quoted string { - BufferedCharReader reader(" 'hello world' "); - auto res = Reader::parseGeneric(reader, logger, {';'}); + CharReader reader(" 'hello world' "); + auto res = VariantReader::parseGeneric(reader, logger, {';'}); ASSERT_TRUE(res.first); ASSERT_TRUE(res.second.isString()); ASSERT_EQ("hello world", res.second.asString()); diff --git a/test/core/variant/VariantTest.cpp b/test/core/common/VariantTest.cpp index e51cf36..580846e 100644 --- a/test/core/variant/VariantTest.cpp +++ b/test/core/common/VariantTest.cpp @@ -20,7 +20,7 @@ #include <gtest/gtest.h> -#include <core/variant/Variant.hpp> +#include <core/common/Variant.hpp> namespace ousia { diff --git a/test/plugins/css/CSSParserTest.cpp b/test/plugins/css/CSSParserTest.cpp index 6499375..3ea3a19 100644 --- a/test/plugins/css/CSSParserTest.cpp +++ b/test/plugins/css/CSSParserTest.cpp @@ -186,11 +186,11 @@ TEST(CSSParser, testParseCSS) { Rooted<RuleSet> ruleSet = A->getRuleSet(); ASSERT_EQ(2, ruleSet->getRules().size()); - variant::Variant v = ruleSet->getRules()["ident1"]; - ASSERT_EQ(variant::Variant::Type::STRING, v.getType()); + Variant v = ruleSet->getRules()["ident1"]; + ASSERT_EQ(Variant::Type::STRING, v.getType()); ASSERT_EQ("val4", v.asString()); v = ruleSet->getRules()["ident2"]; - ASSERT_EQ(variant::Variant::Type::STRING, v.getType()); + ASSERT_EQ(Variant::Type::STRING, v.getType()); ASSERT_EQ("val2", v.asString()); } /* @@ -211,8 +211,8 @@ TEST(CSSParser, testParseCSS) { Rooted<RuleSet> ruleSet = Aselect->getRuleSet(); ASSERT_EQ(1, ruleSet->getRules().size()); - variant::Variant v = ruleSet->getRules()["ident3"]; - ASSERT_EQ(variant::Variant::Type::STRING, v.getType()); + Variant v = ruleSet->getRules()["ident3"]; + ASSERT_EQ(Variant::Type::STRING, v.getType()); ASSERT_EQ("val3", v.asString()); } /* @@ -250,11 +250,11 @@ TEST(CSSParser, testParseCSS) { Rooted<RuleSet> ruleSet = BA->getRuleSet(); ASSERT_EQ(2, ruleSet->getRules().size()); - variant::Variant v = ruleSet->getRules()["ident1"]; - ASSERT_EQ(variant::Variant::Type::STRING, v.getType()); + Variant v = ruleSet->getRules()["ident1"]; + ASSERT_EQ(Variant::Type::STRING, v.getType()); ASSERT_EQ("val1", v.asString()); v = ruleSet->getRules()["ident2"]; - ASSERT_EQ(variant::Variant::Type::STRING, v.getType()); + ASSERT_EQ(Variant::Type::STRING, v.getType()); ASSERT_EQ("val2", v.asString()); } } diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp index 7dc8c24..39b1a9d 100644 --- a/test/plugins/xml/XmlParserTest.cpp +++ b/test/plugins/xml/XmlParserTest.cpp @@ -36,7 +36,7 @@ TEST(XmlParser, mismatchedTagException) p.parse("<document>\n</document2>", ctx); } catch (ParserException ex) { - ASSERT_EQ(2, ex.line); + ASSERT_EQ(2U, ex.pos.line); hadException = true; } ASSERT_TRUE(hadException); |