1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-09 21:50:45 +01:00

Test_serialiation update for JSON

This commit is contained in:
Antonin Portelli 2017-06-19 14:38:39 +01:00
parent 284ee194b1
commit b672717096

View File

@ -151,6 +151,11 @@ int main(int argc,char **argv)
ioTest<TextWriter, TextReader>("iotest.dat", obj, "text (object) "); ioTest<TextWriter, TextReader>("iotest.dat", obj, "text (object) ");
ioTest<TextWriter, TextReader>("iotest.dat", vec, "text (vector of objects)"); ioTest<TextWriter, TextReader>("iotest.dat", vec, "text (vector of objects)");
ioTest<TextWriter, TextReader>("iotest.dat", pair, "text (pair of objects)"); ioTest<TextWriter, TextReader>("iotest.dat", pair, "text (pair of objects)");
//// text
ioTest<JSONWriter, JSONReader>("iotest.json", obj, "JSON (object) ");
ioTest<JSONWriter, JSONReader>("iotest.json", vec, "JSON (vector of objects)");
ioTest<JSONWriter, JSONReader>("iotest.json", pair, "JSON (pair of objects)");
//// HDF5 //// HDF5
#undef HAVE_HDF5 #undef HAVE_HDF5
#ifdef HAVE_HDF5 #ifdef HAVE_HDF5
@ -194,50 +199,50 @@ int main(int argc,char **argv)
std::cout << std::endl; std::cout << std::endl;
std::cout << ".:::::: Testing JSON classes "<< std::endl; // std::cout << ".:::::: Testing JSON classes "<< std::endl;
//
//
{ // {
JSONWriter JW("bother.json"); // JSONWriter JW("bother.json");
//
// test basic type writing // // test basic type writing
push(JW,"BasicTypes"); // push(JW,"BasicTypes");
write(JW,std::string("i16"),i16); // write(JW,std::string("i16"),i16);
write(JW,"u16",u16); // write(JW,"u16",u16);
write(JW,"i32",i32); // write(JW,"i32",i32);
write(JW,"u32",u32); // write(JW,"u32",u32);
write(JW,"i64",i64); // write(JW,"i64",i64);
write(JW,"u64",u64); // write(JW,"u64",u64);
write(JW,"f",f); // write(JW,"f",f);
write(JW,"d",d); // write(JW,"d",d);
write(JW,"b",b); // write(JW,"b",b);
pop(JW); // pop(JW);
//
// test serializable class writing // // test serializable class writing
myclass obj(1234); // non-trivial constructor // myclass obj(1234); // non-trivial constructor
std::cout << "-- serialisable class writing to 'bother.json'..." << std::endl; // std::cout << "-- serialisable class writing to 'bother.json'..." << std::endl;
write(JW,"obj",obj); // write(JW,"obj",obj);
JW.write("obj2", obj); // JW.write("obj2", obj);
//
std::cout << obj << std::endl; // std::cout << obj << std::endl;
//
std::vector<myclass> vec; // std::vector<myclass> vec;
vec.push_back(myclass(1234)); // vec.push_back(myclass(1234));
vec.push_back(myclass(5678)); // vec.push_back(myclass(5678));
vec.push_back(myclass(3838)); // vec.push_back(myclass(3838));
write(JW, "objvec", vec); // write(JW, "objvec", vec);
//
} // }
//
{ // {
JSONReader RD("bother.json"); // JSONReader RD("bother.json");
myclass jcopy1; // myclass jcopy1;
std::vector<myclass> jveccopy1; // std::vector<myclass> jveccopy1;
read(RD,"obj",jcopy1); // read(RD,"obj",jcopy1);
read(RD,"objvec", jveccopy1); // read(RD,"objvec", jveccopy1);
std::cout << "Loaded (JSON) -----------------" << std::endl; // std::cout << "Loaded (JSON) -----------------" << std::endl;
std::cout << jcopy1 << std::endl << jveccopy1 << std::endl; // std::cout << jcopy1 << std::endl << jveccopy1 << std::endl;
} // }
/* /*
// This is still work in progress // This is still work in progress