diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-12-11 21:46:11 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-12-11 21:46:11 +0100 |
commit | 741463dd18efd8d126bcc70224025703858fdef7 (patch) | |
tree | 82f83172a3229f14957b6c3f90fd10180c6b2612 /test | |
parent | 3f62168ed0b088eec3cb2903f03966f7d501f564 (diff) |
refactored logger
Diffstat (limited to 'test')
-rw-r--r-- | test/core/common/CharReaderTest.cpp | 44 | ||||
-rw-r--r-- | test/core/common/LoggerTest.cpp | 48 | ||||
-rw-r--r-- | test/plugins/xml/XmlParserTest.cpp | 2 |
3 files changed, 49 insertions, 45 deletions
diff --git a/test/core/common/CharReaderTest.cpp b/test/core/common/CharReaderTest.cpp index 06b9d45..9c1026c 100644 --- a/test/core/common/CharReaderTest.cpp +++ b/test/core/common/CharReaderTest.cpp @@ -660,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); @@ -670,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); @@ -690,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); @@ -705,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); @@ -720,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); @@ -735,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); @@ -750,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); @@ -765,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); @@ -780,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); @@ -795,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); @@ -810,8 +810,8 @@ 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 index 54c67f9..bb31fa6 100644 --- a/test/core/common/LoggerTest.cpp +++ b/test/core/common/LoggerTest.cpp @@ -25,31 +25,38 @@ 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; } + 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.pushFilename("test.odp"); + logger.pushFile("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", 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.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); + 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"}; @@ -59,16 +66,13 @@ TEST(TerminalLogger, log) } try { - throw LoggableException{"An exception at position", Pos(10, 20)}; + 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(10, 20)); - logger.debugAt("This is a positioned debug message", Pos(10, 20)); - logger.noteAt("This is a positioned log error", Pos(10, 20)); + logger.logAt(Severity::ERROR, "This is a positioned log message", pos); } } 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); |