rework of suite and unit

master
Chris Punches 2017-06-20 02:06:33 -04:00
parent c8b0872993
commit 64efd0898a
4 changed files with 74 additions and 21 deletions

View File

@ -10,13 +10,15 @@ 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. // 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 ); this->load_json_file( filename, verbose );
Json::Value jbuff;
// refill the json_root buffer with a json object in the // refill the json_root buffer with a json object in the
if ( this->get_serialized( Json::Value jbuf, "units", verbose ) != 0) if ( this->get_serialized( jbuff, "units", verbose ) != 0)
{ {
this->json_root = jbuf; this->json_root = jbuff;
} }
// assemble the units
} }

View File

@ -17,10 +17,10 @@ class Suite: public JSON_Loader
Suite(); Suite();
// load a unit definitions file and add valid unit definitions to this->units // load a unit definitions file and add valid unit definitions to this->units
void load_units_file( std::string filename ); void load_units_file( std::string filename, bool verbose );
// returns the unit identified by name // returns the unit identified by name
void get_unit(Unit & result, std::string provided_name); // void get_unit(Unit & result, std::string provided_name);
}; };
#endif //FTESTS_UNITS_H #endif //FTESTS_UNITS_H

View File

@ -1,14 +1,9 @@
#include "Unit.h" #include "Unit.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
Unit::Unit() {} Unit::Unit() {}
Unit::Unit( Json::Value loader_root )
/*
* Constructor for Unit type. Receives a UnitHolder loader_root.
*/
{
this->load_root( loader_root );
}
int Unit::load_root(Json::Value loader_root) int Unit::load_root(Json::Value loader_root)
{ {
@ -22,9 +17,41 @@ int Unit::load_root(Json::Value loader_root)
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
/*
* getters for Unit type. // TODO CHANGE HOW THIS WORKS
*/ int Unit::load_string(std::string json_val)
{
// reads from a string into a Json::Value type.
Json::Reader json_reader;
// the deserialized json type to contain what's read by the reader
Json::Value serialized;
// create the ifstream file handle for the parser method to consume
std::ifstream json_file_ifstream( json_val.c_str(), std::ifstream::binary );
// use the reader to parse the ifstream to the local property
bool parsingSuccessful = json_reader.parse( json_file_ifstream, serialized );
if (! parsingSuccessful )
{
std::cerr << "Failed to parse adhoc JSON value." << std::endl << json_val << std::endl << std::endl << json_reader.getFormattedErrorMessages();
throw JSON_Loader_InvalidJSON();
} else {
// if in verbose mode, give the user an "it worked" message
if ( verbose )
{
std::cout << "Successfully parsed JSON string with " << this->json_root.size() << " elements. Value:" << std::endl;
std::cout << json_val << std::endl << std::endl;
}
}
// exit successfully
this->populated = true;
}
// getters for Unit type.
std::string Unit::get_name() std::string Unit::get_name()
{ {
return this->name; return this->name;

View File

@ -1,29 +1,53 @@
// /* Unit.h
// Created by phanes on 4/29/17. * Unit is a type that represents a safely deserialized JSON object which defines what actions are taken as Examplar
// * iterates through it's Tasks in it's given Plan. They only define the behaviour on execution, while the tasks define
* which Units are executed and in what order (and which Units a given Task depends on.
*/
#ifndef FTESTS_UNIT_H #ifndef FTESTS_UNIT_H
#define FTESTS_UNIT_H #define FTESTS_UNIT_H
#include <string> #include <string>
#include "../json/json.h" #include "../json/json.h"
#include "JSON_Loader.h"
class Unit class Unit: JSON_Loader
{ {
private: private:
// the name of the test
std::string name; std::string name;
// the path of the executable this test executes when run
std::string target; std::string target;
// the desired output
// poll: would an empty value be good to indicate to rely solely on zero/non-zero exit code?
std::string output; std::string output;
// the path of the executable this test runs when the target executable fails to produce output or a 0 exit code.
std::string rectifier; std::string rectifier;
// an indicator of whether the test is active or not
// this is used as a way to give definers a way to force executors to edit arbitrary fields or prevent
// execution of potentially dangerous or intrusive tests
std::string active; std::string active;
// an indicator of whether or not this test is required to pass.
// intended to be used as a flag to halt execution of further tests on failure
std::string required; std::string required;
// indicator of whether the rectifier executable should be run on test failures.
// if rectifier exits on non-zero return code, it should be trigger the behaviour indicated by required
std::string rectify; std::string rectify;
public: public:
Unit(); Unit();
Unit( Json::Value loader_root );
// loads a serialized jason::value object as a unit
int load_root( Json::Value loader_root ); int load_root( Json::Value loader_root );
// loads a string as a json string and deserializes that.
int load_string( std::string json_val );
// getters
std::string get_name(); std::string get_name();
std::string get_target(); std::string get_target();
std::string get_output(); std::string get_output();