diff --git a/conf/config.json b/conf/config.json index 0efa20c..1b4f139 100644 --- a/conf/config.json +++ b/conf/config.json @@ -1,4 +1,4 @@ { - "units_path": "/home/phanes/Development/internal/ftests/conf/units/all_test.units", - "plan_path": "/home/phanes/Development/internal/ftests/conf/plans/test.plan" + "units_path": "/home/phanes/Development/internal/Examplar/conf/units/all_test.units", + "plan_path": "/home/phanes/Development/internal/Examplar/conf/plans/test.plan" } diff --git a/conf/units/all_test.units b/conf/units/all_test.units index 50636f8..126a978 100644 --- a/conf/units/all_test.units +++ b/conf/units/all_test.units @@ -2,9 +2,9 @@ "units": [ { "name": "independent test", - "target": "/home/phanes/tests/test-script-pass.sh", + "target": "/bin/pwd", "output": "pass", - "rectifier": "/home/phanes/tests/test-script-rectifier.sh", + "rectifier": "/bin/pwd", "active": true, "required": true, "rectify": true diff --git a/examplar.cpp b/examplar.cpp index 4ced1fe..a0371b6 100644 --- a/examplar.cpp +++ b/examplar.cpp @@ -6,16 +6,14 @@ int main( ) { // A Plan is made up of Tasks, and a Suite is made up of Units. // A Plan declares what units are executed and a Suite declares the definitions of those units. - Conf configuration = Conf("/home/phanes/Development/internal/ftests/conf/config.json"); + Conf configuration = Conf("/home/phanes/Development/internal/Examplar/conf/config.json"); // load the configuration file which contains filepaths to definitions of a plan and definitions of units. std::string definitions_file = configuration.get_units_path(); - std::string plan_file = configuration.get_plan_path(); + // std::cout << definitions_file << std::endl << plan_file << std::endl; - - std::cout << definitions_file << std::endl << plan_file << std::endl; - + Suite available_definitions; // Suite * unit_definitions = new Suite(); diff --git a/src/json/jsoncpp.cpp b/src/json/jsoncpp.cpp index 180d674..2ea7b0a 100644 --- a/src/json/jsoncpp.cpp +++ b/src/json/jsoncpp.cpp @@ -318,8 +318,7 @@ namespace Json { lastValue_(), commentsBefore_(), features_(features), collectComments_() { } - bool - Reader::parse(const std::string& document, Value& root, bool collectComments) { + bool Reader::parse(const std::string& document, Value& root, bool collectComments) { JSONCPP_STRING documentCopy(document.data(), document.data() + document.capacity()); std::swap(documentCopy, document_); const char* begin = document_.c_str(); diff --git a/src/loaders/Conf.cpp b/src/loaders/Conf.cpp index 9f7542d..2f4456d 100644 --- a/src/loaders/Conf.cpp +++ b/src/loaders/Conf.cpp @@ -19,10 +19,10 @@ Conf::Conf( std::string filename ): JSON_Loader() this->load_json_file( filename, true ); // find the path to the plan file - if ( this->get_key( this->plan_path, "plan_path", true) != 0 ) { throw CONF_PLANPATH_INVALID(); } + if (this->get_serialized(this->plan_path, "plan_path", true) != 0 ) { throw CONF_PLANPATH_INVALID(); } // find the path to the unit definitions file - if ( this->get_key( this->units_path, "units_path", true) != 0 ) { throw CONF_UNITSPATH_INVALID(); } + if (this->get_serialized(this->units_path, "units_path", true) != 0 ) { throw CONF_UNITSPATH_INVALID(); } }; std::string Conf::get_plan_path() diff --git a/src/loaders/JSON_Loader.cpp b/src/loaders/JSON_Loader.cpp index 86183a4..65aebe1 100644 --- a/src/loaders/JSON_Loader.cpp +++ b/src/loaders/JSON_Loader.cpp @@ -70,7 +70,7 @@ void JSON_Loader::load_json_string( std::string input, bool verbose ) Json::Reader json_reader; // the deserialized json type to contain what's read by the reader - Json::Value json_root; + // Json::Value json_root; // create the ifstream file handle std::ifstream json_file_ifstream( input.c_str(), std::ifstream::binary ); @@ -112,11 +112,11 @@ std::string JSON_Loader::as_string() return this->json_root.asString(); } -// returns the string representation of the value of a key +// returns the serialized representation of the value of a key // the Jason::Value object to assign the fetched value to // verbosity flag // exit or not on failure -int JSON_Loader::get_key( Json::Value &input, std::string key, bool verbose) +int JSON_Loader::get_serialized(Json::Value &input, std::string key, bool verbose) { // throw if the class is not ready to be used. if ( ! this->populated ) { throw JSON_Loader_NotReady(); } @@ -129,7 +129,6 @@ int JSON_Loader::get_key( Json::Value &input, std::string key, bool verbose) } // key was not found - // shouldn't the be handled further up? if ( verbose ) { // verbose mode tells the user what key we were looking for. diff --git a/src/loaders/JSON_Loader.h b/src/loaders/JSON_Loader.h index 4ce2a66..880725c 100644 --- a/src/loaders/JSON_Loader.h +++ b/src/loaders/JSON_Loader.h @@ -27,10 +27,11 @@ class JSON_Loader void load_json_string( std::string input, bool verbose ); // return as a JSONCPP serialized object - Json::Value as_serialized(); - std::string as_string(); + // deprecated -- these aren't really used. + // Json::Value as_serialized(); + // std::string as_string(); - // safely handle key retrieval (if we want it to be safe) - int get_key( Json::Value &input, std::string key, bool verbose); + // safely handle deserialized type retrieval (if we want it to be safe) + int get_serialized(Json::Value &input, std::string key, bool verbose); }; #endif //FTESTS_JLOADER_H diff --git a/src/loaders/Suite.cpp b/src/loaders/Suite.cpp index 7433dfd..bef541e 100644 --- a/src/loaders/Suite.cpp +++ b/src/loaders/Suite.cpp @@ -1,16 +1,28 @@ #include "Suite.h" -/* -Suite::Suite( std::string filename ): JSON_Loader() -/* Suite loads a file and deserializes the Unit JSON object to Unit types as a vector member - * Suite { vector } +Suite::Suite(): JSON_Loader() { - load_file( filename ); + // empty }; +void Suite::load_units_file( std::string filename, bool verbose ) +{ + // will use json_root staging buffer on each run to append to this->units vector as valid units are found. + this->load_json_file( filename, verbose ); + + + // refill the json_root buffer with a json object in the + if ( this->get_serialized( Json::Value jbuf, "units", verbose ) != 0) + { + this->json_root = jbuf; + } + + +} + int Suite::load_file(std::string filename): JSON_Loader( filename ) { - Json::Value raw_units = this->get_root()["units"]; + Json::Value raw_units = this->get_serialized("") for ( int index = 0; index < raw_units.size(); index++ ) { this->units.push_back( Unit( raw_units[ index ] ) ); @@ -20,7 +32,7 @@ int Suite::load_file(std::string filename): JSON_Loader( filename ) return EXIT_SUCCESS; } -Unit Suite::get_unit(std::string provided_name) +/* Unit Suite::get_unit(std::string provided_name) * returns a unit from a unitholder object by name * this will need reworked. maybe should return int, populate a pointer. @@ -47,4 +59,8 @@ Unit Suite::get_unit(std::string provided_name) } return * returnable; } -*/ \ No newline at end of file +*/ + + + +ca \ No newline at end of file diff --git a/src/loaders/Suite.h b/src/loaders/Suite.h index 046c0df..ef0b412 100644 --- a/src/loaders/Suite.h +++ b/src/loaders/Suite.h @@ -9,15 +9,18 @@ class Suite: public JSON_Loader { private: + // storage for the definitions we are amassing from the unit definition files std::vector units; public: - // constructor - Suite( std::string filename ); + // constructor, empty + Suite(); - int load_file( std::string filename ); - // returns the unit type identified by name or null - Unit get_unit(std::string provided_name); + // load a unit definitions file and add valid unit definitions to this->units + void load_units_file( std::string filename ); + + // returns the unit identified by name + void get_unit(Unit & result, std::string provided_name); }; #endif //FTESTS_UNITS_H diff --git a/src/loaders/loaders.h b/src/loaders/loaders.h index 9f4f0e0..86085b4 100644 --- a/src/loaders/loaders.h +++ b/src/loaders/loaders.h @@ -5,7 +5,7 @@ #define FTESTS_LOADERS_H #include "JSON_Loader.h" -//#include "Suite.h" +#include "Suite.h" //#include "Plan.h" #include "Conf.h"