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
2524using namespace std ;
2625using namespace diffpy ::srreal;
@@ -71,6 +70,16 @@ class TestBVParametersTable : public CxxTest::TestSuite
7170 }
7271
7372
73+ void test_atomvalence ()
74+ {
75+ TS_ASSERT_EQUALS (0 , mbvtb->getAtomValence (" O" ));
76+ mbvtb->setAtomValence (" O" , -2 );
77+ TS_ASSERT_EQUALS (-2 , mbvtb->getAtomValence (" O" ));
78+ mbvtb->resetAtomValences ();
79+ TS_ASSERT_EQUALS (0 , mbvtb->getAtomValence (" O" ));
80+ }
81+
82+
7483 void test_lookup ()
7584 {
7685 BVParam bp = mbvtb->lookup (" Xx" , 0 , " Yy" , 3 );
@@ -91,6 +100,11 @@ class TestBVParametersTable : public CxxTest::TestSuite
91100 const BVParam& bnacl0 = mbvtb->lookup (" Na" , 1 , " Cl" , -1 );
92101 TS_ASSERT_EQUALS (&bnacl0, &mbvtb->lookup (" Na+" , " Cl-" ));
93102 TS_ASSERT_EQUALS (&bnacl0, &mbvtb->lookup (" Cl1-" , " Na1+" ));
103+ const BVParam& bpnone = BVParametersTable::none ();
104+ TS_ASSERT_EQUALS (&bpnone, &mbvtb->lookup (" Na" , " Cl" ));
105+ mbvtb->setAtomValence (" Na" , +1 );
106+ mbvtb->setAtomValence (" Cl" , -1 );
107+ TS_ASSERT_EQUALS (&bnacl0, &mbvtb->lookup (" Na" , " Cl" ));
94108 }
95109
96110
@@ -135,6 +149,25 @@ class TestBVParametersTable : public CxxTest::TestSuite
135149 }
136150
137151
152+ void test_getAllCustom ()
153+ {
154+ TS_ASSERT (mbvtb->getAllCustom ().empty ());
155+ BVParam mymgo (" Mg" , 2 , " O" , -2 );
156+ mbvtb->setCustom (mymgo);
157+ TS_ASSERT_EQUALS (1u , mbvtb->getAllCustom ().size ());
158+ const BVParam& bp = mbvtb->lookup (" O2-" , " Mg2+" );
159+ BVParametersTable::SetOfBVParam::const_iterator ii;
160+ ii = mbvtb->getAllCustom ().find (mymgo);
161+ TS_ASSERT_DIFFERS (ii, mbvtb->getAllCustom ().end ());
162+ TS_ASSERT_DIFFERS (&mymgo, &(*ii));
163+ TS_ASSERT_EQUALS (&bp, &(*ii));
164+ TS_ASSERT_EQUALS (mymgo, *ii);
165+ // erase the only custom parameter
166+ mbvtb->resetCustom (*ii);
167+ TS_ASSERT (mbvtb->getAllCustom ().empty ());
168+ }
169+
170+
138171 void test_getAll ()
139172 {
140173 BVParametersTable::SetOfBVParam allpars0, allpars1;
@@ -164,13 +197,8 @@ class TestBVParametersTable : public CxxTest::TestSuite
164197 BVParam mymgo (" O" , -2 , " Mg" , 2 , 3.456 , 0.55 , " pj2" );
165198 mbvtb->setCustom (mynacl);
166199 mbvtb->setCustom (mymgo);
167- stringstream storage (ios::in | ios::out | ios::binary);
168- diffpy::serialization::oarchive oa (storage, ios::binary);
169- oa << mbvtb;
170- diffpy::serialization::iarchive ia (storage, ios::binary);
171- BVParametersTablePtr bvtb1;
172- TS_ASSERT (!bvtb1.get ());
173- ia >> bvtb1;
200+ // check serialization of shared pointers
201+ BVParametersTablePtr bvtb1 = dumpandload (mbvtb);
174202 TS_ASSERT_DIFFERS (mbvtb.get (), bvtb1.get ());
175203 TS_ASSERT_EQUALS (2.345 ,
176204 bvtb1->lookup (" Cl" , -1 , " Na" , 1 ).mRo );
@@ -184,6 +212,17 @@ class TestBVParametersTable : public CxxTest::TestSuite
184212 bvtb1->lookup (" O" , -2 , " Mg" , 2 ).mB );
185213 TS_ASSERT_EQUALS (string (" pj2" ),
186214 bvtb1->lookup (" O" , -2 , " Mg" , 2 ).mref_id );
215+ // check serialization of instances
216+ BVParametersTable tb2 = dumpandload (*mbvtb);
217+ TS_ASSERT_EQUALS (2u , tb2.getAllCustom ().size ());
218+ TS_ASSERT_EQUALS (mynacl, tb2.lookup (" Cl-" , " Na+" ));
219+ // check serialization of customized valences
220+ tb2.setAtomValence (" Na" , 1 );
221+ tb2.setAtomValence (" Cl" , -1 );
222+ BVParametersTable tb3 = dumpandload (tb2);
223+ TS_ASSERT_EQUALS (mynacl, tb3.lookup (" Cl" , " Na" ));
224+ const BVParam& bpnone = BVParametersTable::none ();
225+ TS_ASSERT_EQUALS (bpnone, mbvtb->lookup (" Cl" , " Na" ));
187226 }
188227
189228}; // class TestBVParametersTable
0 commit comments