Skip to content

[json] improve roottest/io/json testing #18483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion roottest/root/io/json/.rootrc

This file was deleted.

59 changes: 57 additions & 2 deletions roottest/root/io/json/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,58 @@

ROOTTEST_COMPILE_MACRO(test_classes.h FIXTURES_SETUP json-test-classes-build)
ROOTTEST_ADD_AUTOMACROS(FIXTURES_REQUIRED json-test-classes-build)
ROOTTEST_ADD_TEST(ArrayCompress
MACRO runArrayCompress.C
OUTREF ArrayCompress.ref)

ROOTTEST_ADD_TEST(PolyMarker
MACRO runPolyMarker.C
OUTREF PolyMarker.ref)

ROOTTEST_GENERATE_DICTIONARY(libJsonTestClasses
test_classes.h
LINKDEF LinkDef.h
NO_ROOTMAP NO_CXXMODULE)

ROOTTEST_ADD_TEST(BasicTypes
MACRO runBasicTypes.C
OUTREF BasicTypes.ref
DEPENDS ${GENERATE_DICTIONARY_TEST})

ROOTTEST_ADD_TEST(Objects
MACRO runObjects.C
OUTREF Objects.ref
DEPENDS ${GENERATE_DICTIONARY_TEST})

ROOTTEST_ADD_TEST(RootClasses
MACRO runRootClasses.C
OUTREF RootClasses.ref
DEPENDS ${GENERATE_DICTIONARY_TEST})

ROOTTEST_ADD_TEST(STL
MACRO runSTL.C
OUTREF STL.ref
DEPENDS ${GENERATE_DICTIONARY_TEST})

ROOTTEST_ADD_TEST(STL0
MACRO runSTL0.C
OUTREF STL0.ref
DEPENDS ${GENERATE_DICTIONARY_TEST})

ROOTTEST_ADD_TEST(STL1
MACRO runSTL1.C
OUTREF STL1.ref
DEPENDS ${GENERATE_DICTIONARY_TEST})

ROOTTEST_ADD_TEST(StreamerLoop
MACRO runStreamerLoop.C
OUTREF StreamerLoop.ref
DEPENDS ${GENERATE_DICTIONARY_TEST})

ROOTTEST_ADD_TEST(Map
MACRO runMap.C
OUTREF Map.ref
DEPENDS ${GENERATE_DICTIONARY_TEST})

ROOTTEST_ADD_TEST(String
MACRO runString.C
OUTREF String.ref
DEPENDS ${GENERATE_DICTIONARY_TEST})
24 changes: 24 additions & 0 deletions roottest/root/io/json/LinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifdef __CLING__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class std::map<std::string,int>+;

#pragma link C++ class TJsonEx1+;
#pragma link C++ class TJsonEx2+;
#pragma link C++ class TJsonEx3+;
#pragma link C++ class TJsonEx4+;
#pragma link C++ class TJsonEx5+;
#pragma link C++ class TJsonEx6+;
#pragma link C++ class TJsonEx7+;
#pragma link C++ class TJsonEx8+;
#pragma link C++ class TJsonEx9+;
#pragma link C++ class TJsonEx10+;
#pragma link C++ class TJsonEx11+;
#pragma link C++ class TJsonEx12+;
#pragma link C++ class TJsonEx13+;
#pragma link C++ class TJsonEx14+;

#endif
44 changes: 16 additions & 28 deletions roottest/root/io/json/runBasicTypes.C
Original file line number Diff line number Diff line change
@@ -1,45 +1,33 @@
{
// Fill out the code of the actual test
#ifndef SECOND_RUN
gROOT->ProcessLine(".L test_classes.h+");
#endif
#include "test_classes.h"

#if defined(ClingWorkAroundMissingDynamicScope) && !defined(SECOND_RUN)
#define SECOND_RUN
gROOT->ProcessLine(".x runBasicTypes.C");
#else
void runBasicTypes()
{
gSystem->Load("libJsonTestClasses");

TJsonEx1 ex1; ex1.Init();
TJsonEx2 ex2; ex2.Init();
TJsonEx3 ex3; ex3.Init();
TJsonEx11 ex11; ex11.Init();
TString json;

cout << " ====== basic data types TJsonEx1 ===== " << endl;
std::cout << " ====== basic data types TJsonEx1 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex1);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== inheritance from TJsonEx1, TJsonEx11 ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== inheritance from TJsonEx1, TJsonEx11 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex11);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== arrays of basic data types TJsonEx2 ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== arrays of basic data types TJsonEx2 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex2);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== dynamic arrays of basic data types TJsonEx3 ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== dynamic arrays of basic data types TJsonEx3 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex3);
testJsonReading(json);
cout << json << endl << endl;
cout << " ============ selected data members ======== " << endl;
cout << "ex2.fInt = " << TBufferJSON::ToJSON(&ex2, 0, "fInt") << endl;
cout << "ex3.fChar = " << TBufferJSON::ToJSON(&ex3, 0, "fChar") << endl;
cout << "ex3.fLong = " << TBufferJSON::ToJSON(&ex3, 0, "fLong") << endl;

#endif
#ifdef ClingWorkAroundBrokenUnnamedReturn
gApplication->Terminate(0);
#else
return 0;
#endif
std::cout << json << std::endl << std::endl;
std::cout << " ============ selected data members ======== " << std::endl;
std::cout << "ex2.fInt = " << TBufferJSON::ToJSON(&ex2, 0, "fInt") << std::endl;
std::cout << "ex3.fChar = " << TBufferJSON::ToJSON(&ex3, 0, "fChar") << std::endl;
std::cout << "ex3.fLong = " << TBufferJSON::ToJSON(&ex3, 0, "fLong") << std::endl;
}
3 changes: 3 additions & 0 deletions roottest/root/io/json/runMap.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ void testJson(std::map<std::string,int> &data, int compact, const char *name)

void runMap()
{
// for dictionary
gSystem->Load("libJsonTestClasses");

std::map<std::string,int> data;

for (int n=0;n<10;++n) {
Expand Down
42 changes: 15 additions & 27 deletions roottest/root/io/json/runObjects.C
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
{
// Fill out the code of the actual test
#ifndef SECOND_RUN
gROOT->ProcessLine(".L test_classes.h+");
#endif
#include "test_classes.h"

#if defined(ClingWorkAroundMissingDynamicScope) && !defined(SECOND_RUN)
#define SECOND_RUN
gROOT->ProcessLine(".x runObjects.C");
#else
void runObjects()
{
gSystem->Load("libJsonTestClasses");

TJsonEx5 ex5; ex5.Init();
TJsonEx6 ex6; ex6.Init();
TJsonEx10 ex10; ex10.Init();
TString json;

cout << " ====== objects as class members TJsonEx5 ===== " << endl;
std::cout << " ====== objects as class members TJsonEx5 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex5);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== arrays of objects as class members TJsonEx6 ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== arrays of objects as class members TJsonEx6 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex6);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== ROOT TObject/TNamed/TString as class members TJsonEx10 ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== ROOT TObject/TNamed/TString as class members TJsonEx10 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex10);
testJsonReading(json);
cout << json << endl << endl;
cout << " ============ selected data members ======== " << endl;
cout << "ex5.fObj1 = " << TBufferJSON::ToJSON(&ex5, 0, "fObj1") << endl;
cout << "ex5.fPtr1 = " << TBufferJSON::ToJSON(&ex5, 0, "fPtr1") << endl;
cout << "ex5.fSafePtr1 = " << TBufferJSON::ToJSON(&ex5, 0, "fSafePtr1") << endl;
cout << "ex6.fObj1 = " << TBufferJSON::ToJSON(&ex6, 0, "fObj1") << endl;

#endif
#ifdef ClingWorkAroundBrokenUnnamedReturn
gApplication->Terminate(0);
#else
return 0;
#endif
std::cout << json << std::endl << std::endl;
std::cout << " ============ selected data members ======== " << std::endl;
std::cout << "ex5.fObj1 = " << TBufferJSON::ToJSON(&ex5, 0, "fObj1") << std::endl;
std::cout << "ex5.fPtr1 = " << TBufferJSON::ToJSON(&ex5, 0, "fPtr1") << std::endl;
std::cout << "ex5.fSafePtr1 = " << TBufferJSON::ToJSON(&ex5, 0, "fSafePtr1") << std::endl;
std::cout << "ex6.fObj1 = " << TBufferJSON::ToJSON(&ex6, 0, "fObj1") << std::endl;
}
2 changes: 1 addition & 1 deletion roottest/root/io/json/runPolyMarker.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ void runPolyMarker()

TString json = TBufferJSON::ToJSON(&marker);

cout << json << endl;
std::cout << json << std::endl;
}
48 changes: 18 additions & 30 deletions roottest/root/io/json/runRootClasses.C
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#include "test_classes.h"

void runRootClasses()
{
// Fill out the code of the actual test
#ifndef SECOND_RUN
gROOT->ProcessLine(".L test_classes.h+");
#endif
gSystem->Load("libJsonTestClasses");

#if defined(ClingWorkAroundMissingDynamicScope) && !defined(SECOND_RUN)
#define SECOND_RUN
gROOT->ProcessLine(".x runRootClasses.C");
#else

TH1I *h1 = new TH1I("histo1","histo title", 100, -10., 10.);
for (Int_t bin=1;bin<=100;++bin)
Expand Down Expand Up @@ -39,34 +35,34 @@

TString json;

cout << " ====== TObject representation ===== " << endl;
std::cout << " ====== TObject representation ===== " << std::endl;
json = TBufferJSON::ToJSON(obj);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== TH1I representation ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== TH1I representation ===== " << std::endl;
json = TBufferJSON::ToJSON(h1);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== TBox representation ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== TBox representation ===== " << std::endl;
json = TBufferJSON::ToJSON(box);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== TList representation ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== TList representation ===== " << std::endl;
json = TBufferJSON::ToJSON(arr);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== TClonesArray representation ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== TClonesArray representation ===== " << std::endl;
json = TBufferJSON::ToJSON(clones);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== TMap representation ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== TMap representation ===== " << std::endl;
json = TBufferJSON::ToJSON(map);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== TJsonEx14 with different ROOT collections ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== TJsonEx14 with different ROOT collections ===== " << std::endl;
json = TBufferJSON::ToJSON(ex14);
testJsonReading(json);
cout << json << endl << endl;
std::cout << json << std::endl << std::endl;

delete obj;
delete h1;
Expand All @@ -75,12 +71,4 @@
delete clones;
delete map;
delete ex14;


#endif
#ifdef ClingWorkAroundBrokenUnnamedReturn
gApplication->Terminate(0);
#else
return 0;
#endif
}
36 changes: 12 additions & 24 deletions roottest/root/io/json/runSTL.C
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
{
// Fill out the code of the actual test
#ifndef SECOND_RUN
gROOT->ProcessLine(".L test_classes.h+");
#endif
#include "test_classes.h"

#if defined(ClingWorkAroundMissingDynamicScope) && !defined(SECOND_RUN)
#define SECOND_RUN
gROOT->ProcessLine(".x runSTL.C");
#else
void runSTL()
{
gSystem->Load("libJsonTestClasses");

TJsonEx7 ex7; ex7.Init();
TJsonEx8 ex8; ex8.Init();
TJsonEx12 ex12; ex12.Init();
TJsonEx13 ex13; ex13.Init();
TString json;

cout << " ====== different STL containers TJsonEx7 ===== " << endl;
std::cout << " ====== different STL containers TJsonEx7 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex7);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== STL as base class TJsonEx8 ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== STL as base class TJsonEx8 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex8);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== STL vector of complex classes TJsonEx12 ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== STL vector of complex classes TJsonEx12 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex12);
testJsonReading(json);
cout << json << endl << endl;
cout << " ====== More exotic STL containers as set or map with TRef inside TJsonEx13 ===== " << endl;
std::cout << json << std::endl << std::endl;
std::cout << " ====== More exotic STL containers as set or map with TRef inside TJsonEx13 ===== " << std::endl;
json = TBufferJSON::ToJSON(&ex13);
testJsonReading(json);
cout << json << endl << endl;

#endif
#ifdef ClingWorkAroundBrokenUnnamedReturn
gApplication->Terminate(0);
#else
return 0;
#endif
std::cout << json << std::endl << std::endl;
}
Loading
Loading