Skip to content

Commit 6d6c033

Browse files
committedJun 18, 2016
Improve serialization of BVParametersTable.
Make sure serialization methods are instantiated in the library. Test serialization of table instances and of shared pointers. Simplify serialization test by using dumpandload helper.
1 parent 5ac6995 commit 6d6c033

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed
 

‎src/diffpy/srreal/BVParametersTable.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,6 @@ BVParametersTable::getStandardSetOfBVParam() const
178178
// Serialization -------------------------------------------------------------
179179

180180
DIFFPY_INSTANTIATE_SERIALIZATION(diffpy::srreal::BVParametersTable)
181+
DIFFPY_INSTANTIATE_PTR_SERIALIZATION(diffpy::srreal::BVParametersTable)
181182

182183
// End of file

‎src/tests/TestBVParametersTable.hpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
*
1717
*****************************************************************************/
1818

19-
#include <stdexcept>
2019
#include <cxxtest/TestSuite.h>
2120

22-
#include <diffpy/serialization.hpp>
2321
#include <diffpy/srreal/BVParametersTable.hpp>
22+
#include "serialization_helpers.hpp"
2423

2524
using namespace std;
2625
using namespace diffpy::srreal;
@@ -183,13 +182,8 @@ class TestBVParametersTable : public CxxTest::TestSuite
183182
BVParam mymgo("O", -2, "Mg", 2, 3.456, 0.55, "pj2");
184183
mbvtb->setCustom(mynacl);
185184
mbvtb->setCustom(mymgo);
186-
stringstream storage(ios::in | ios::out | ios::binary);
187-
diffpy::serialization::oarchive oa(storage, ios::binary);
188-
oa << mbvtb;
189-
diffpy::serialization::iarchive ia(storage, ios::binary);
190-
BVParametersTablePtr bvtb1;
191-
TS_ASSERT(!bvtb1.get());
192-
ia >> bvtb1;
185+
// check serialization of shared pointers
186+
BVParametersTablePtr bvtb1 = dumpandload(mbvtb);
193187
TS_ASSERT_DIFFERS(mbvtb.get(), bvtb1.get());
194188
TS_ASSERT_EQUALS(2.345,
195189
bvtb1->lookup("Cl", -1, "Na", 1).mRo);
@@ -203,6 +197,10 @@ class TestBVParametersTable : public CxxTest::TestSuite
203197
bvtb1->lookup("O", -2, "Mg", 2).mB);
204198
TS_ASSERT_EQUALS(string("pj2"),
205199
bvtb1->lookup("O", -2, "Mg", 2).mref_id);
200+
// check serialization of instances
201+
BVParametersTable tb2 = dumpandload(*mbvtb);
202+
TS_ASSERT_EQUALS(2u, tb2.getAllCustom().size());
203+
TS_ASSERT_EQUALS(mynacl, tb2.lookup("Cl-", "Na+"));
206204
}
207205

208206
}; // class TestBVParametersTable

0 commit comments

Comments
 (0)
Please sign in to comment.