TuttleOFX
1
|
00001 //#define BOOST_TEST_MODULE properties_tests 00002 #include <tuttle/test/unit_test.hpp> 00003 00004 #include <tuttle/common/utils/global.hpp> 00005 #include <tuttle/host/Core.hpp> 00006 00007 #include <boost/archive/xml_oarchive.hpp> 00008 #include <boost/archive/binary_oarchive.hpp> 00009 #include <boost/archive/text_oarchive.hpp> 00010 #include <boost/archive/xml_iarchive.hpp> 00011 #include <boost/archive/binary_iarchive.hpp> 00012 #include <boost/archive/text_iarchive.hpp> 00013 #include <boost/serialization/serialization.hpp> 00014 #include <boost/serialization/export.hpp> 00015 #include <boost/serialization/extended_type_info.hpp> 00016 00017 #include <fstream> 00018 #include <iostream> 00019 00020 using namespace boost::unit_test; 00021 00022 BOOST_AUTO_TEST_SUITE( properties_tests_suite02 ) 00023 00024 BOOST_AUTO_TEST_CASE( properties_serialization ) 00025 { 00026 using namespace std; 00027 using namespace tuttle::host; 00028 00029 #define testString_1_ro "testString_1_ro" 00030 #define testString_2_rw "testString_2_rw" 00031 #define testPointer_1_rw "testPointer_1_rw" 00032 #define testDouble_2_ro "testDouble_2_ro" 00033 #define testDouble_1_rw "testDouble_1_rw" 00034 #define testInt_1_rw "testInt_1_rw" 00035 #define testInt_2_rw "testInt_2_rw" 00036 #define testInt_4_ro "testInt_4_ro" 00037 00038 static const ofx::property::OfxhPropSpec testStuff[] = { 00039 /* name type dim. r/o default value */ 00040 { testString_1_ro, ofx::property::ePropTypeString, 1, true, "default_value" }, 00041 { testString_2_rw, ofx::property::ePropTypeString, 2, false, "default_value" }, 00042 { testPointer_1_rw, ofx::property::ePropTypePointer, 1, false, NULL }, 00043 { testDouble_2_ro, ofx::property::ePropTypeDouble, 2, true, "0" }, 00044 { testDouble_1_rw, ofx::property::ePropTypeDouble, 1, false, "0" }, 00045 { testInt_1_rw, ofx::property::ePropTypeInt, 1, false, "0" }, 00046 { testInt_2_rw, ofx::property::ePropTypeInt, 2, false, "8" }, 00047 { testInt_4_ro, ofx::property::ePropTypeInt, 4, true, "0" }, 00048 { 0 } 00049 }; 00050 00051 // init values 00052 ofx::property::OfxhSet testSet( testStuff ); 00053 testSet.setStringProperty( testString_1_ro, "testcontext" ); 00054 testSet.setIntProperty( testInt_1_rw, true ); 00055 int tab4Int[4] = { 11, 22, 33, 44 }; 00056 testSet.setIntProperty( testInt_4_ro, tab4Int[0], 0 ); 00057 testSet.setIntProperty( testInt_4_ro, tab4Int[1], 1 ); 00058 testSet.setIntProperty( testInt_4_ro, tab4Int[2], 2 ); 00059 testSet.setIntProperty( testInt_4_ro, tab4Int[3], 3 ); 00060 double tab2Double[2] = { 11, 22 }; 00061 testSet.setDoublePropertyN( testDouble_2_ro, tab2Double, 2 ); 00062 00063 // typedef boost::archive::binary_oarchive OArchive; 00064 // typedef boost::archive::binary_iarchive IArchive; 00065 // typedef boost::archive::text_oarchive OArchive; 00066 // typedef boost::archive::text_iarchive IArchive; 00067 typedef boost::archive::xml_oarchive OArchive; 00068 typedef boost::archive::xml_iarchive IArchive; 00069 00070 std::string testfile( "test_properties_serialization.xml" ); 00071 BOOST_REQUIRE( testfile.size() ); 00072 00073 std::ofstream ofsb( testfile.c_str() ); 00074 OArchive oArchive( ofsb ); 00075 oArchive << BOOST_SERIALIZATION_NVP( testSet ); 00076 ofsb.close(); 00077 00078 // new datas 00079 ofx::property::OfxhSet testSet2; 00080 00081 std::ifstream ifsb( testfile.c_str() ); 00082 IArchive iArchive( ifsb ); 00083 iArchive >> BOOST_SERIALIZATION_NVP( testSet2 ); 00084 ifsb.close(); 00085 00086 BOOST_CHECK( testSet == testSet2 ); 00087 00088 BOOST_CHECK_EQUAL( 0, std::remove( testfile.c_str() ) ); 00089 } 00090 00091 BOOST_AUTO_TEST_SUITE_END() 00092