|
Boost : |
From: Loïc Joly (loic.actarus.joly_at_[hidden])
Date: 2005-05-22 15:59:36
Hello everybody,
I think I have some idea that might improve the ease for the end user to
test if he properly set-up his class for serialization.
Sorry if this idea has already been discussed (or even is already
implemented), but I tried to search a little, without finding anything
about this.
The main idea is that if an user has a serializable class, he will
probably want to test wether he forgot to put some usefull member data
in his |serialize function. Thus, he will have to write some test with
always the same pattern. My suggestion is to put test_tools.hpp inside
the serialization library, along with some template :|
||
|template<class T> void check_serialization(T const &t) // t should not
be initialized to default values|
|{|
| const char * testfile = boost::archive::tmpnam(NULL);|
| BOOST_REQUIRE(NULL != testfile);|
| {|
|| std::ofstream ofs(testFile);
| boost::archive::text_oarchive oa(ofs);|
| oa|| << t;|
| }|
| {
||| T t1;
|| std::ifstream ifs(testFile, std::ios::binary);
| boost::archive::text_iarchive ia(ifs);
| ia >> t1
||| }|
| BOOST_CHECK_EQUAL(t, t1);|
| std::remove(testfile);|
|||}|
||||
Do you think it would make a worthy addition ?
-- Loïc | |
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk