Browse Source

Added important test to the INI loader test code.

master
DomtronVox 1 year ago
parent
commit
50a0171bcc
1 changed files with 25 additions and 22 deletions
  1. +25
    -22
      tests/test_ConfigLoaderINI.cpp

+ 25
- 22
tests/test_ConfigLoaderINI.cpp View File

@ -36,59 +36,62 @@ int main (int argc, char* argv[]) {
std::string test_testval = "6";
std::string test2_testval = "1+1=2";
//invalid ext
std::shared_ptr<ConfigStore> store;
TEST_BEGIN( "Testing Parse Function Test 0: bad ext" );
addFile("test0.txt", "id=112F24R433\n[mod]\ntest=6");
//Missing file
TEST_BEGIN( "Testing Parse Function Test 0: missing file" );
store = test_loader.parse("test0.txt");
ASSERT_THROW( store->isPopulated() == false );
TEST_END();
//invalid ext
TEST_BEGIN( "Testing Parse Function Test 1: bad ext" );
addFile("test1.txt", "id=112F24R433\n[mod]\ntest=6");
store = test_loader.parse("test1.txt");
ASSERT_THROW( store->isPopulated() == false );
TEST_END();
//invalid format
TEST_BEGIN( "Testing Parse Function Test 1: bad format" );
addFile("test1-1.ini", "id112F24R433\n[mod\ntest6");
addFile("test1-2.ini", "id=id112F24R433\n[mod\ntest6");
TEST_BEGIN( "Testing Parse Function Test 2: bad format" );
addFile("test2-1.ini", "id112F24R433\n[mod\ntest6");
addFile("test2-2.ini", "id=id112F24R433\n[mod\ntest6");
store = test_loader.parse("test1-1.ini");
store = test_loader.parse("test2-1.ini");
ASSERT_THROW( store->isPopulated() == false );
store = test_loader.parse("test1-2.ini");
store = test_loader.parse("test2-2.ini");
ASSERT_THROW( store->isPopulated() == false );
TEST_END();
//valid format 1: keys, no sections, blank line, '=' in value
TEST_BEGIN( "Testing Parse Function Test 2: valid format 1; no sections, key/val pairs, '=' in val" );
addFile("test2.ini", "id=112F24R433\n \ntest=6\ntest2=1+1=2");
store = test_loader.parse("test2.ini");
TEST_BEGIN( "Testing Parse Function Test 3: valid format 1; no sections, key/val pairs, '=' in val" );
addFile("test3.ini", "id=112F24R433\n \ntest=6\ntest2=1+1=2");
store = test_loader.parse("test3.ini");
std::cout << store->isPopulated() << std::endl;
ASSERT_THROW( store->isPopulated() == true );
std::cout << store->getStr("id") << std::endl;
ASSERT_THROW( store->getStr("id") == id_testval );
std::cout << store->getStr("test") << std::endl;
ASSERT_THROW( store->getStr("test") == test_testval );
std::cout << store->getStr("test2") << std::endl;
ASSERT_THROW( store->getStr("test2") == test2_testval );
TEST_END();
//valid format 2: keys, section, comment
TEST_BEGIN( "Testing Parse Function Test 3: valid format, key/val, sections, comment" );
addFile("test3.ini", "id=112F24R433\n[mod]\n;a comment\ntest=6");
store = test_loader.parse("test3.ini");
TEST_BEGIN( "Testing Parse Function Test 4: valid format, key/val, sections, comment" );
addFile("test4.ini", "id=112F24R433\n[mod]\n;a comment\ntest=6");
store = test_loader.parse("test4.ini");
ASSERT_THROW( store->isPopulated() == true );
ASSERT_THROW( store->getStr("id") == id_testval );
ASSERT_THROW( store->getNested("mod")->getStr("test") == test_testval );
TEST_END();
TEST_BEGIN( "Testing Parse Function: Test 4" );
addFile("test4.ini", "[intro]\nid=112F24R433\n[mod]\ntest=6"); //valid format 3: everything belongs in sections
store = test_loader.parse("test4.ini");
TEST_BEGIN( "Testing Parse Function: Test 5" );
addFile("test5.ini", "[intro]\nid=112F24R433\n[mod]\ntest=6"); //valid format 3: everything belongs in sections
store = test_loader.parse("test5.ini");
ASSERT_THROW( store->isPopulated() == true );
ASSERT_THROW( store->getNested("intro")->getStr("id") == id_testval );


Loading…
Cancel
Save