00001 #include <boost/test/auto_unit_test.hpp> 00002 #include <boost/test/floating_point_comparison.hpp> 00003 00004 #include <lang/csupport/standard_types.hh> 00005 00006 #include <test/testsuite.hh> 00007 #include <utilmm/configfile/configset.hh> 00008 #include <typelib/pluginmanager.hh> 00009 #include <typelib/typemodel.hh> 00010 #include <typelib/registry.hh> 00011 #include <typelib/csvoutput.hh> 00012 using namespace Typelib; 00013 using namespace std; 00014 00015 #include "test_cimport.1" 00016 00017 00018 BOOST_AUTO_TEST_CASE(test_csv) 00019 { 00020 { 00021 Registry registry; 00022 Typelib::CXX::addStandardTypes(registry); 00023 00024 float f32 = 0.52; 00025 Type const& type = *registry.get("float"); 00026 00027 ostringstream stream; 00028 stream << csv_header(type, "base"); 00029 BOOST_CHECK_EQUAL("base", stream.str()); 00030 00031 stream.str(""); 00032 stream << csv(type, &f32); 00033 BOOST_CHECK_CLOSE(0.52f, boost::lexical_cast<float>(stream.str()), 0.00001); 00034 } 00035 00036 { 00037 // Get the test file into repository 00038 utilmm::config_set config; 00039 auto_ptr<Registry> registry(PluginManager::self()->load("tlb", TEST_DATA_PATH("test_cimport.tlb"), config)); 00040 00041 { 00042 ostringstream stream; 00043 00044 DisplayTest test; 00045 test.fields[0] = 0; 00046 test.fields[1] = 1; 00047 test.fields[2] = 2; 00048 test.fields[3] = 3; 00049 test.f = 1.1; 00050 test.d = 2.2; 00051 test.a.a = 10; 00052 test.a.b = 20; 00053 test.a.c = 'b'; 00054 test.a.d = 42; 00055 test.mode = OUTPUT; 00056 00057 Type const& display_type = *registry->get("/DisplayTest"); 00058 stream << csv_header(display_type, "t"); 00059 BOOST_CHECK_EQUAL("t.fields[0] t.fields[1] t.fields[2] t.fields[3] t.f t.d t.a.a t.a.b t.a.c t.a.d t.mode", stream.str()); 00060 } 00061 } 00062 } 00063