ModEasy, a c++ library, is an easy to add modding system that is functional out of the box, but also designed to be extendable for whatever you may need.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

109 lines
3.7 KiB

#include "TestBase.h"
#include "Configuration/ConfigLoaderINI.h"
#include "Configuration/FileOperations.h"
#include <string>
#include <vector>
void addFile(std::string path, std::string contents) {
writeToTextFile(path, contents, 't');
}
int main (int argc, char* argv[]) {
/*TEST_BEGIN( "test1" );
ASSERT_EQUAL( 0, 0 );
ASSERT_THROW( 0 == 0 );
EXPECT_EXCEPTION( fakeFileLoad("does_not_exist.txt"), FileNotFound );
TEST_END();*/
ConfigLoaderINI test_loader;
//TEST_BEGIN( "Testing Validate Function: Success case" );
//TODO need to implement validate function ASSERT_THROW(test_loader.validate("test2.ini") == true);
//TEST_END();
//TEST_BEGIN( "Testing Validate Function: Failure cases" );
//TODO need to implement validate function ASSERT_THROW(test_loader.validate("DoesNotExist.ini") == false);
//TODO need to implement validate function ASSERT_THROW(test_loader.validate("test0.txt") == false);
//TODO need to implement validate function ASSERT_THROW(test_loader.validate("test1.txt") == false);
//TEST_END();
//values used in the test files
std::string id_testval = "112F24R433";
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");
store = test_loader.parse("test0.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");
store = test_loader.parse("test1-1.ini");
ASSERT_THROW( store->isPopulated() == false );
store = test_loader.parse("test1-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");
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");
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");
ASSERT_THROW( store->isPopulated() == true );
ASSERT_THROW( store->getNested("intro")->getStr("id") == id_testval );
ASSERT_THROW( store->getNested("mod")->getStr("test") == test_testval );
TEST_END();
TEST_BEGIN( "Testing Serialize Function: Normal case" );
TEST_END();
TEST_BEGIN( "Testing Serialize Function: 3+levels Case" );
test_loader.parse("test4");
TEST_END();
return 0;
}