Skip to content
Snippets Groups Projects
Commit d5f380b4 authored by Evgeny Alexandrov's avatar Evgeny Alexandrov Committed by Tadej Novak
Browse files

improve Json2Cool_test

improve Json2Cool_test
parent 9b52a4db
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,7 @@
#include "CoolKernel/Record.h"
#include "CxxUtils/checker_macros.h"
#include "CxxUtils/base64.h"
#include <istream>
#include <string>
......@@ -65,12 +66,13 @@ BOOST_AUTO_TEST_SUITE(Json2CoolTest)
}
BOOST_AUTO_TEST_CASE(parsePayloadSpec){
const std::string testSpecString="crate: UChar, ROB: Int32, BCIDOffset: Int16, AName: String255";
const std::string testSpecString="crate: UChar, ROB: Int32, BCIDOffset: Int16, AName: String255, fTest: Float";
auto *referenceSpec = new cool::RecordSpecification();
referenceSpec->extend("crate", StorageType::UChar);
referenceSpec->extend("ROB", StorageType::Int32);
referenceSpec->extend("BCIDOffset", StorageType::Int16);
referenceSpec->extend("AName", StorageType::String255);
referenceSpec->extend("fTest", StorageType::Float);
auto *returnedSpec = Json2Cool::parsePayloadSpec(testSpecString);
BOOST_CHECK(*(returnedSpec) == *static_cast<const cool::IRecordSpecification*>(referenceSpec));
}
......@@ -78,30 +80,98 @@ BOOST_AUTO_TEST_SUITE(Json2CoolTest)
auto *referenceSpec = new cool::RecordSpecification();
referenceSpec->extend("crate", StorageType::UChar);
referenceSpec->extend("ROB", StorageType::Int32);
referenceSpec->extend("ROB1", StorageType::Int32);
referenceSpec->extend("BCIDOffset", StorageType::Int16);
referenceSpec->extend("AName", StorageType::String255);
const std::string jsonValues="[\"1\",\"2\",\"3\",\"purple\"]";
std::istringstream initializerStream(jsonValues);
nlohmann::json j;
initializerStream >>j;
auto record=Json2Cool::createAttributeList(referenceSpec, j);
referenceSpec->extend("fnTest1", StorageType::Float);
referenceSpec->extend("fnTest2", StorageType::Float);
referenceSpec->extend("fsTest1", StorageType::Float);
referenceSpec->extend("fsTest2", StorageType::Float);
referenceSpec->extend("dnTest1", StorageType::Double);
referenceSpec->extend("dnTest2", StorageType::Double);
referenceSpec->extend("dsTest1", StorageType::Double);
referenceSpec->extend("dsTest2", StorageType::Double);
referenceSpec->extend("blobTest", StorageType::Blob16M);
nlohmann::json j=nlohmann::json::array();
cool::Record reference(*referenceSpec);
BOOST_CHECK(record.size() == reference.size());
//
auto & att0 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[0]);
unsigned char set0(1);
att0.setValue<unsigned char>(set0);
j.push_back(set0);
//
auto & att1 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[1]);
att1.setValue<int>(2);
j.push_back(2);
//
auto & att2 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[2]);
auto & att1_ ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[2]);
att1_.setValue<int>(4);
std::ostringstream ss2;
ss2<<4;
j.push_back(ss2.str());
//
auto & att2 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[3]);
short set2(3);
att2.setValue<short>(set2);
j.push_back(set2);
//
auto & att3 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[3]);
auto & att3 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[4]);
att3.setValue<std::string>("purple");
j.push_back("purple");
//
auto & att4 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[5]);
float set4(1.01);
att4.setValue<float>(set4);
j.push_back(set4);
//
auto & att5 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[6]);
float set5(1);
att5.setValue<float>(set5);
j.push_back(set5);
//
auto & att6 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[7]);
float set6(1.02);
att6.setValue<float>(set6);
j.push_back(std::to_string(set6));
//
auto & att7 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[8]);
float set7(2);
att7.setValue<float>(set7);
j.push_back(std::to_string(set7));
//
auto & att8 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[9]);
double set8(1.01);
att8.setValue<double>(set8);
j.push_back(set8);
//
auto & att9 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[10]);
double set9(1);
att9.setValue<double>(set9);
j.push_back(set9);
//
auto & att10 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[11]);
double set10(1.02);
att10.setValue<double>(set10);
j.push_back(std::to_string(set10));
//
auto & att11 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[12]);
double set11(2);
att11.setValue<double>(set11);
j.push_back(std::to_string(set11));
//
auto & att12 ATLAS_THREAD_SAFE = const_cast<coral::Attribute&>(reference.attributeList()[13]);
std::stringstream p;
unsigned char myString [] = "This is my BLOB";
const coral::Blob bl(strlen((char*)myString));
att12.setValue<coral::Blob>(bl);
const auto address = static_cast<const unsigned char *>(bl.startingAddress());
const unsigned int nBytes = bl.size();
std::string str=CxxUtils::base64_encode(address, nBytes);
j.push_back(str);
auto record=Json2Cool::createAttributeList(referenceSpec, j);
BOOST_CHECK(record.size() == reference.size());
BOOST_CHECK(reference == record);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment