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.
 

105 lines
3.4 KiB

#include "TestBase.h"
#include "Configuration/ConfigStore.h"
#include "Dependency/Dependency.h"
#include <iostream>
//helper function to create ConfigStores that mimic id and dependancy info
std::shared_ptr<ConfigStore> makeModConfig(std::string id, std::string depends = "", std::string optdepends = "") {
std::shared_ptr<ConfigStore> mod_config = std::make_shared<ConfigStore>();
mod_config->set("id", id);
mod_config->set("depends", depends);
mod_config->set("opt depends", optdepends);
return mod_config;
}
//create a string showing the mod order.
std::string makeOrderNameString( std::vector< std::shared_ptr<ConfigStore> > ordered_list) {
auto it = ordered_list.begin();
std::string return_str = (*it)->getStr("id");
it++;
for (; it < ordered_list.end(); it++){
return_str += ", " + (*it)->getStr("id");
}
return return_str;
}
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();
//build out test data
TEST_BEGIN( "Testing buildLoadOrder complex" );
std::vector< std::shared_ptr<ConfigStore> > mod_configs;
//no depends, no dependants, placed first
mod_configs.push_back(makeModConfig( "111" ));
//hard depend that is added later
mod_configs.push_back(makeModConfig( "44f", "15f" ));
mod_configs.push_back(makeModConfig( "15f" ));
//chain dependancy in order
mod_configs.push_back(makeModConfig( "1a" ));
mod_configs.push_back(makeModConfig( "1b", "1a" ));
mod_configs.push_back(makeModConfig( "1c", "1b" ));
//chain dependancy out of order
mod_configs.push_back(makeModConfig( "2c", "2b" ));
mod_configs.push_back(makeModConfig( "2b", "2a" ));
mod_configs.push_back(makeModConfig( "2a" ));
//no depends, no dependants, placed middleish
mod_configs.push_back(makeModConfig( "222" ));
//optional depend that is added later
mod_configs.push_back(makeModConfig( "hgw", "", "hhh" ));
mod_configs.push_back(makeModConfig( "hhh" ));
//optional depend added after
mod_configs.push_back(makeModConfig( "aaa" ));
mod_configs.push_back(makeModConfig( "bbb", "", "aaa" ));
//optional depend and required depend
mod_configs.push_back(makeModConfig( "ccc", "aaa", "bbb" ));
//missing optional depend
mod_configs.push_back(makeModConfig( "dup", "", "not_here" ));
//optional depend on something with a missing optional depend
mod_configs.push_back(makeModConfig( "lup", "", "dup" ));
//depend on mod with missing optional depend
mod_configs.push_back(makeModConfig( "rup", "dup" ));
//missing required depend
mod_configs.push_back(makeModConfig( "ohno", "not_here" ));
//optional depend on mod with missing depend
mod_configs.push_back(makeModConfig( "ohyes", "", "ohno" ));
//no depends, no dependants, added lastish
mod_configs.push_back(makeModConfig( "333" ));
//sort it
std::vector< std::shared_ptr<ConfigStore> > sorted_mods = sortForLoadOrder(mod_configs);
std::string modOrder = makeOrderNameString(sorted_mods);
//expected output order based on test data:
ASSERT_THROW( modOrder == "111, 15f, 44f, 1a, 1b, 1c, 2a, 2b, 2c, 222, hhh, hgw, aaa, bbb, ccc, dup, lup, rup, ohyes, 333" );
TEST_END();
return 0;
}