Skip to content

Commit

Permalink
Adds an unit test for the setConfig helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
ventsyv committed Nov 17, 2023
1 parent 89fced4 commit 6bd75ba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
EXE_FILE:=patexp
SRC_FILES:= Expander.o
MAIN_FILE:= main.o Helpers.o
SRC_FILES:= Expander.o Helpers.o
MAIN_FILE:= main.o
TEST_FILES:= TestExpander.o

# Build directories - allows for separate release and debug executables
Expand Down
40 changes: 40 additions & 0 deletions test/TestExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <gtest/gtest.h>
#include "Expander.h"
#include "Helpers.h"

using namespace ::testing;
using namespace std;
Expand Down Expand Up @@ -902,6 +903,45 @@ TEST_F(TestExpander, testSaveConfig)

}

TEST_F(TestExpander, testSetConfig)
{
string configFileName = std::tmpnam(nullptr);

string args = R"(-e # -r > -b { -n } -q ^)";
stringstream ss(args);
vector<string> temp;
string item;
while (ss >> item)
temp.push_back(item);

char** argv = new char*[temp.size()];
for (size_t i = 0; i < temp.size(); i++)
{
argv[i] = new char[temp[i].length()];
strcpy(argv[i], temp[i].c_str());
}

setConfig(temp.size(), argv, configFileName);

//Load the alt config file. All settings will change
underTest.loadConfig(configFileName);

ASSERT_EQ(underTest.getEscChar(), L'#');
ASSERT_EQ(underTest.getGroupBegin(), L'{');
ASSERT_EQ(underTest.getGroupEnd(), L'}');
ASSERT_EQ(underTest.getRangeChar(), L'>');
ASSERT_EQ(underTest.getQuote(), L'^');


for (size_t i = 0; i < temp.size(); i++)
{
delete argv[i];
}
delete [] argv;


}



int main(int argc, char **argv)
Expand Down

0 comments on commit 6bd75ba

Please sign in to comment.