Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49612 - trunk/libs/date_time/test/posix_time
From: andrey.semashev_at_[hidden]
Date: 2008-11-06 11:03:44


Author: andysem
Date: 2008-11-06 11:03:44 EST (Thu, 06 Nov 2008)
New Revision: 49612
URL: http://svn.boost.org/trac/boost/changeset/49612

Log:
The test now operates on strings rather than files. This was made in order to reduce possible influence from the file system and improve diagnostics in case of failure.
Text files modified:
   trunk/libs/date_time/test/posix_time/testtime_serialize.cpp | 24 +++++++++---------------
   1 files changed, 9 insertions(+), 15 deletions(-)

Modified: trunk/libs/date_time/test/posix_time/testtime_serialize.cpp
==============================================================================
--- trunk/libs/date_time/test/posix_time/testtime_serialize.cpp (original)
+++ trunk/libs/date_time/test/posix_time/testtime_serialize.cpp 2008-11-06 11:03:44 EST (Thu, 06 Nov 2008)
@@ -12,7 +12,7 @@
 #include <boost/date_time/posix_time/posix_time.hpp>
 #include <boost/date_time/posix_time/time_serialize.hpp>
 #include <boost/date_time/testfrmwk.hpp>
-#include <fstream>
+#include <sstream>
 
 using namespace boost;
 using namespace posix_time;
@@ -47,16 +47,16 @@
   ptime sv_pt4(min_date_time);
   time_duration sv_td2(0,0,0);
   
- std::ofstream ofs("tmp_file");
+ std::ostringstream oss;
 
   // NOTE: DATE_TIME_XML_SERIALIZE is only used in testing and is
   // defined in the testing Jamfile
 #if defined(DATE_TIME_XML_SERIALIZE)
   std::cout << "Running xml archive tests" << std::endl;
- archive::xml_oarchive oa(ofs);
+ archive::xml_oarchive oa(oss);
 #else
   std::cout << "Running text archive tests" << std::endl;
- archive::text_oarchive oa(ofs);
+ archive::text_oarchive oa(oss);
 #endif // DATE_TIME_XML_SERIALIZE
 
   try{
@@ -77,18 +77,15 @@
 #endif // DATE_TIME_XML_SERIALIZE
   }catch(archive::archive_exception& ae){
     std::string s(ae.what());
- check("Error writing to archive: " + s, false);
- ofs.close();
+ check("Error writing to archive: " + s + "\nWritten data: \"" + oss.str() + "\"", false);
     return printTestStats();
   }
 
- ofs.close();
-
- std::ifstream ifs("tmp_file");
+ std::istringstream iss(oss.str());
 #if defined(DATE_TIME_XML_SERIALIZE)
- archive::xml_iarchive ia(ifs);
+ archive::xml_iarchive ia(iss);
 #else
- archive::text_iarchive ia(ifs);
+ archive::text_iarchive ia(iss);
 #endif // DATE_TIME_XML_SERIALIZE
 
   try{
@@ -109,13 +106,10 @@
 #endif // DATE_TIME_XML_SERIALIZE
   }catch(archive::archive_exception& ae){
     std::string s(ae.what());
- check("Error readng from archive: " + s, false);
- ifs.close();
+ check("Error readng from archive: " + s + "\nWritten data: \"" + oss.str() + "\"", false);
     return printTestStats();
   }
 
- ifs.close();
-
   check("ptime", pt == pt2);
   check("special_values ptime (nadt)", sv_pt1 == sv_pt3);
   check("special_values ptime (pos_infin)", sv_pt2 == sv_pt4);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk