Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
HEPnOS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sds
HEP
HEPnOS
Commits
7bc4b87c
Commit
7bc4b87c
authored
May 03, 2018
by
Matthieu Dorier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added loadstore test
parent
407030cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
278 additions
and
0 deletions
+278
-0
test/LoadStoreTest.cpp
test/LoadStoreTest.cpp
+195
-0
test/LoadStoreTest.hpp
test/LoadStoreTest.hpp
+83
-0
No files found.
test/LoadStoreTest.cpp
0 → 100644
View file @
7bc4b87c
#include "LoadStoreTest.hpp"
#include "CppUnitAdditionalMacros.hpp"
CPPUNIT_TEST_SUITE_REGISTRATION
(
LoadStoreTest
);
using
namespace
hepnos
;
void
LoadStoreTest
::
setUp
()
{}
void
LoadStoreTest
::
tearDown
()
{}
void
LoadStoreTest
::
testFillDataStore
()
{
auto
mds
=
datastore
->
createDataSet
(
"matthieu"
);
CPPUNIT_ASSERT
(
mds
.
valid
());
Run
r1
=
mds
.
createRun
(
42
);
CPPUNIT_ASSERT
(
r1
.
valid
());
SubRun
sr1
=
r1
.
createSubRun
(
3
);
CPPUNIT_ASSERT
(
sr1
.
valid
());
Event
ev1
=
sr1
.
createEvent
(
22
);
CPPUNIT_ASSERT
(
ev1
.
valid
());
}
void
LoadStoreTest
::
testLoadStoreDataSet
()
{
auto
mds
=
(
*
datastore
)[
"matthieu"
];
auto
run
=
mds
[
42
];
auto
subrun
=
run
[
3
];
auto
event
=
subrun
[
22
];
CPPUNIT_ASSERT
(
mds
.
valid
());
CPPUNIT_ASSERT
(
run
.
valid
());
CPPUNIT_ASSERT
(
subrun
.
valid
());
CPPUNIT_ASSERT
(
event
.
valid
());
TestObjectA
out_obj_a
;
out_obj_a
.
x
()
=
44
;
out_obj_a
.
y
()
=
1.2
;
TestObjectB
out_obj_b
;
out_obj_b
.
a
()
=
33
;
out_obj_b
.
b
()
=
"you"
;
std
::
string
key1
=
"mykey"
;
// we can store obj_a
CPPUNIT_ASSERT
(
mds
.
store
(
key1
,
out_obj_a
));
// we cannot store at that key again something of the same type
TestObjectA
tmpa
;
CPPUNIT_ASSERT
(
!
mds
.
store
(
key1
,
tmpa
));
// we can store obj_b at the same key because it's not the same type
CPPUNIT_ASSERT
(
mds
.
store
(
key1
,
out_obj_b
));
TestObjectA
in_obj_a
;
TestObjectB
in_obj_b
;
std
::
string
key2
=
"otherkey"
;
// we can't load something at a key that does not exist
CPPUNIT_ASSERT
(
!
mds
.
load
(
key2
,
in_obj_a
));
// we can reload obj_a from key1
CPPUNIT_ASSERT
(
mds
.
load
(
key1
,
in_obj_a
));
// and they are the same
CPPUNIT_ASSERT
(
in_obj_a
==
out_obj_a
);
// we can reload obj_b from key1
CPPUNIT_ASSERT
(
mds
.
load
(
key1
,
in_obj_b
));
// and they are the same
CPPUNIT_ASSERT
(
in_obj_b
==
out_obj_b
);
}
void
LoadStoreTest
::
testLoadStoreRun
()
{
auto
mds
=
(
*
datastore
)[
"matthieu"
];
auto
run
=
mds
[
42
];
auto
subrun
=
run
[
3
];
auto
event
=
subrun
[
22
];
CPPUNIT_ASSERT
(
mds
.
valid
());
CPPUNIT_ASSERT
(
run
.
valid
());
CPPUNIT_ASSERT
(
subrun
.
valid
());
CPPUNIT_ASSERT
(
event
.
valid
());
TestObjectA
out_obj_a
;
out_obj_a
.
x
()
=
44
;
out_obj_a
.
y
()
=
1.2
;
TestObjectB
out_obj_b
;
out_obj_b
.
a
()
=
33
;
out_obj_b
.
b
()
=
"you"
;
std
::
string
key1
=
"mykey"
;
// we can store obj_a
CPPUNIT_ASSERT
(
run
.
store
(
key1
,
out_obj_a
));
// we cannot store at that key again something of the same type
TestObjectA
tmpa
;
CPPUNIT_ASSERT
(
!
run
.
store
(
key1
,
tmpa
));
// we can store obj_b at the same key because it's not the same type
CPPUNIT_ASSERT
(
run
.
store
(
key1
,
out_obj_b
));
TestObjectA
in_obj_a
;
TestObjectB
in_obj_b
;
std
::
string
key2
=
"otherkey"
;
// we can't load something at a key that does not exist
CPPUNIT_ASSERT
(
!
run
.
load
(
key2
,
in_obj_a
));
// we can reload obj_a from key1
CPPUNIT_ASSERT
(
run
.
load
(
key1
,
in_obj_a
));
// and they are the same
CPPUNIT_ASSERT
(
in_obj_a
==
out_obj_a
);
// we can reload obj_b from key1
CPPUNIT_ASSERT
(
run
.
load
(
key1
,
in_obj_b
));
// and they are the same
CPPUNIT_ASSERT
(
in_obj_b
==
out_obj_b
);
}
void
LoadStoreTest
::
testLoadStoreSubRun
()
{
auto
mds
=
(
*
datastore
)[
"matthieu"
];
auto
run
=
mds
[
42
];
auto
subrun
=
run
[
3
];
auto
event
=
subrun
[
22
];
CPPUNIT_ASSERT
(
mds
.
valid
());
CPPUNIT_ASSERT
(
run
.
valid
());
CPPUNIT_ASSERT
(
subrun
.
valid
());
CPPUNIT_ASSERT
(
event
.
valid
());
TestObjectA
out_obj_a
;
out_obj_a
.
x
()
=
44
;
out_obj_a
.
y
()
=
1.2
;
TestObjectB
out_obj_b
;
out_obj_b
.
a
()
=
33
;
out_obj_b
.
b
()
=
"you"
;
std
::
string
key1
=
"mykey"
;
// we can store obj_a
CPPUNIT_ASSERT
(
subrun
.
store
(
key1
,
out_obj_a
));
// we cannot store at that key again something of the same type
TestObjectA
tmpa
;
CPPUNIT_ASSERT
(
!
subrun
.
store
(
key1
,
tmpa
));
// we can store obj_b at the same key because it's not the same type
CPPUNIT_ASSERT
(
subrun
.
store
(
key1
,
out_obj_b
));
TestObjectA
in_obj_a
;
TestObjectB
in_obj_b
;
std
::
string
key2
=
"otherkey"
;
// we can't load something at a key that does not exist
CPPUNIT_ASSERT
(
!
subrun
.
load
(
key2
,
in_obj_a
));
// we can reload obj_a from key1
CPPUNIT_ASSERT
(
subrun
.
load
(
key1
,
in_obj_a
));
// and they are the same
CPPUNIT_ASSERT
(
in_obj_a
==
out_obj_a
);
// we can reload obj_b from key1
CPPUNIT_ASSERT
(
subrun
.
load
(
key1
,
in_obj_b
));
// and they are the same
CPPUNIT_ASSERT
(
in_obj_b
==
out_obj_b
);
}
void
LoadStoreTest
::
testLoadStoreEvent
()
{
auto
mds
=
(
*
datastore
)[
"matthieu"
];
auto
run
=
mds
[
42
];
auto
subrun
=
run
[
3
];
auto
event
=
subrun
[
22
];
CPPUNIT_ASSERT
(
mds
.
valid
());
CPPUNIT_ASSERT
(
run
.
valid
());
CPPUNIT_ASSERT
(
subrun
.
valid
());
CPPUNIT_ASSERT
(
event
.
valid
());
TestObjectA
out_obj_a
;
out_obj_a
.
x
()
=
44
;
out_obj_a
.
y
()
=
1.2
;
TestObjectB
out_obj_b
;
out_obj_b
.
a
()
=
33
;
out_obj_b
.
b
()
=
"you"
;
std
::
string
key1
=
"mykey"
;
// we can store obj_a
CPPUNIT_ASSERT
(
event
.
store
(
key1
,
out_obj_a
));
// we cannot store at that key again something of the same type
TestObjectA
tmpa
;
CPPUNIT_ASSERT
(
!
event
.
store
(
key1
,
tmpa
));
// we can store obj_b at the same key because it's not the same type
CPPUNIT_ASSERT
(
event
.
store
(
key1
,
out_obj_b
));
TestObjectA
in_obj_a
;
TestObjectB
in_obj_b
;
std
::
string
key2
=
"otherkey"
;
// we can't load something at a key that does not exist
CPPUNIT_ASSERT
(
!
event
.
load
(
key2
,
in_obj_a
));
// we can reload obj_a from key1
CPPUNIT_ASSERT
(
event
.
load
(
key1
,
in_obj_a
));
// and they are the same
CPPUNIT_ASSERT
(
in_obj_a
==
out_obj_a
);
// we can reload obj_b from key1
CPPUNIT_ASSERT
(
event
.
load
(
key1
,
in_obj_b
));
// and they are the same
CPPUNIT_ASSERT
(
in_obj_b
==
out_obj_b
);
}
test/LoadStoreTest.hpp
0 → 100644
View file @
7bc4b87c
#ifndef __HEPNOS_TEST_LOADSTORE_H
#define __HEPNOS_TEST_LOADSTORE_H
#include <boost/serialization/access.hpp>
#include <boost/serialization/string.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <hepnos.hpp>
class
TestObjectA
{
friend
class
boost
::
serialization
::
access
;
public:
int
&
x
()
{
return
_x
;
}
double
&
y
()
{
return
_y
;
}
bool
operator
==
(
const
TestObjectA
&
other
)
const
{
return
_x
==
other
.
_x
&&
_y
==
other
.
_y
;
}
private:
int
_x
;
double
_y
;
template
<
typename
Archive
>
void
serialize
(
Archive
&
ar
,
const
unsigned
int
version
)
{
ar
&
_x
;
ar
&
_y
;
}
};
class
TestObjectB
{
friend
class
boost
::
serialization
::
access
;
public:
int
&
a
()
{
return
_a
;
}
std
::
string
&
b
()
{
return
_b
;
}
bool
operator
==
(
const
TestObjectB
&
other
)
const
{
return
_a
==
other
.
_a
&&
_b
==
other
.
_b
;
}
private:
int
_a
;
std
::
string
_b
;
template
<
typename
Archive
>
void
serialize
(
Archive
&
ar
,
const
unsigned
int
version
)
{
ar
&
_a
;
ar
&
_b
;
}
};
extern
hepnos
::
DataStore
*
datastore
;
class
LoadStoreTest
:
public
CppUnit
::
TestFixture
{
CPPUNIT_TEST_SUITE
(
LoadStoreTest
);
CPPUNIT_TEST
(
testFillDataStore
);
CPPUNIT_TEST
(
testLoadStoreDataSet
);
CPPUNIT_TEST
(
testLoadStoreRun
);
CPPUNIT_TEST
(
testLoadStoreSubRun
);
CPPUNIT_TEST
(
testLoadStoreEvent
);
CPPUNIT_TEST_SUITE_END
();
public:
void
setUp
();
void
tearDown
();
void
testFillDataStore
();
void
testLoadStoreDataSet
();
void
testLoadStoreRun
();
void
testLoadStoreSubRun
();
void
testLoadStoreEvent
();
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment