2021-10-10 20:26:30 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "test_t.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
test_t::action test_t::to_action(std::string value) {
|
|
|
|
if (value == "read")
|
|
|
|
return action::read;
|
|
|
|
if (value == "write")
|
|
|
|
return action::write;
|
|
|
|
throw new std::out_of_range("Unknown action");
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string test_t::to_string(action value) {
|
|
|
|
if (value == action::read)
|
|
|
|
return "read";
|
|
|
|
if (value == action::write)
|
|
|
|
return "write";
|
|
|
|
throw new std::out_of_range("Unknown action");
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:59:23 +00:00
|
|
|
#ifdef USE_BOOST_JSON
|
|
|
|
|
|
|
|
test_t::test_t(const boost::json::object& serialised) {
|
|
|
|
initialise(serialised);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_t::test_t(const boost::json::value& serialised) {
|
|
|
|
assert(serialised.is_object());
|
|
|
|
initialise(serialised.get_object());
|
|
|
|
}
|
|
|
|
|
2021-10-10 20:26:30 +00:00
|
|
|
void test_t::initialise(const boost::json::object& serialised) {
|
|
|
|
|
|
|
|
m_name = get_string(serialised, "name");
|
|
|
|
m_initial_state = state_t(get_value(serialised, "initial"));
|
|
|
|
m_final_state = state_t(get_value(serialised, "final"));
|
|
|
|
|
|
|
|
const auto& cycles_array = get_array(serialised, "cycles");
|
|
|
|
m_cycles.reserve(cycles_array.size());
|
|
|
|
|
|
|
|
for (const auto& cycles_entry : cycles_array) {
|
|
|
|
const auto& cycle_array = get_array(cycles_entry);
|
|
|
|
assert(cycle_array.size() == 3);
|
|
|
|
const auto address = get_uint16(cycle_array[0]);
|
|
|
|
const auto contents = get_uint8(cycle_array[1]);
|
|
|
|
const auto action = to_action((std::string)get_string(cycle_array[2]));
|
2021-10-11 13:59:23 +00:00
|
|
|
m_cycles.push_back({ address, contents, action });
|
2021-10-10 20:26:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:59:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_NLOHMANN_JSON
|
|
|
|
|
|
|
|
test_t::test_t(const nlohmann::json& serialised) {
|
|
|
|
assert(serialised.is_object());
|
2021-10-10 20:26:30 +00:00
|
|
|
initialise(serialised);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:59:23 +00:00
|
|
|
void test_t::initialise(const nlohmann::json& serialised) {
|
|
|
|
|
|
|
|
m_name = serialised["name"].get<std::string>();
|
|
|
|
m_initial_state = state_t(serialised["initial"]);
|
|
|
|
m_final_state = state_t(serialised["final"]);
|
|
|
|
|
|
|
|
const auto& cycles_array = serialised["cycles"];
|
|
|
|
m_cycles.reserve(cycles_array.size());
|
|
|
|
|
|
|
|
for (const auto& cycles_entry : cycles_array) {
|
|
|
|
assert(cycles_entry.size() == 3);
|
|
|
|
const auto address = cycles_entry[0].get<uint16_t>();
|
|
|
|
const auto contents = cycles_entry[1].get<uint8_t>();
|
|
|
|
const auto action = to_action(cycles_entry[2].get<std::string>());
|
|
|
|
m_cycles.push_back({ address, contents, action });
|
|
|
|
}
|
2021-10-10 20:26:30 +00:00
|
|
|
}
|
2021-10-11 13:59:23 +00:00
|
|
|
|
|
|
|
#endif
|