From 9b8b2c28b3906c3d48b20afcc8d4c15017fca498 Mon Sep 17 00:00:00 2001 From: Lucien Schreiber Date: Sun, 7 Jul 2024 17:11:01 +0200 Subject: [PATCH] Adding test for TextParser --- test/src/test_textparser.cpp | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/src/test_textparser.cpp diff --git a/test/src/test_textparser.cpp b/test/src/test_textparser.cpp new file mode 100644 index 00000000..ec2999fb --- /dev/null +++ b/test/src/test_textparser.cpp @@ -0,0 +1,50 @@ +#include "gtest/gtest.h" +#include "test_param.h" +#include "../../src/core/textparser.h" + + + +// Test case for TextParserTxtFileTab +TEST(TextParserTxtFileTabTest, Constructor) { + TextParserTxtFileTab tabParser("test.txt"); + EXPECT_EQ(tabParser.GetParserType(), TEXTPARSER_NAME[TXTFILE_TAB]); +} + +// Test case for TextParserTxtFileComma +TEST(TextParserTxtFileCommaTest, Constructor) { + TextParserTxtFileComma commaParser("test.txt"); + EXPECT_EQ(commaParser.GetParserType(), TEXTPARSER_NAME[TXTFILE_COMMA]); +} + +// Test case for TextParserTxtFileTab open method +TEST(TextParserTxtFileTest, TabOpen) { + TextParserTxtFileTab txtParser("test.txt"); + EXPECT_FALSE(txtParser.OpenParseFile()); +} + +// Test case for TextParserTxtFileTab open method (create the file) +TEST(TextParserTxtFileTest, TabOpenCreate) { + wxFileName myFileName(g_TestPathEXPORT, "test_parser_create.txt"); + TextParserTxtFileTab txtParser(myFileName.GetFullPath()); + if (myFileName.Exists()) { + wxRemoveFile(myFileName.GetFullPath()); + } + EXPECT_FALSE(myFileName.Exists()); + EXPECT_TRUE(txtParser.OpenParseFile(true)); + + wxArrayString myValues; + myValues.Add(_T("test1")); + myValues.Add(_T("test2")); + myValues.Add(_T("test3")); + EXPECT_TRUE(txtParser.WriteNextLine(myValues)); + + EXPECT_TRUE(txtParser.CloseParseFile()); + EXPECT_TRUE(myFileName.Exists()); +} + +// Test case for TextParserTxtFileComma open method +TEST(TextParserTxtFileTest, CommaOpen) { + TextParserTxtFileComma txtParser("test.txt"); + EXPECT_FALSE(txtParser.OpenParseFile()); +} +