$search
00001 #include <boost/test/auto_unit_test.hpp> 00002 00003 #include <lang/csupport/standard_types.hh> 00004 00005 #include <test/testsuite.hh> 00006 #include <utilmm/configfile/configset.hh> 00007 #include <typelib/pluginmanager.hh> 00008 #include <typelib/importer.hh> 00009 #include <typelib/typemodel.hh> 00010 #include <typelib/registry.hh> 00011 #include <typelib/registryiterator.hh> 00012 #include <typelib/typedisplay.hh> 00013 #include <iostream> 00014 #include <sstream> 00015 #include <fstream> 00016 using namespace Typelib; 00017 using namespace std; 00018 00019 #ifdef HAS_INTERNAL_CPARSER 00020 BOOST_AUTO_TEST_CASE( test_tlb_rejects_recursive_types ) 00021 { 00022 PluginManager::self manager; 00023 Registry registry; 00024 00025 static const char* test_file = TEST_DATA_PATH("test_cimport.1"); 00026 utilmm::config_set config; 00027 manager->load("c", test_file, config, registry); 00028 00029 BOOST_REQUIRE_THROW(manager->save("tlb", registry), ExportError); 00030 } 00031 #endif 00032 00033 BOOST_AUTO_TEST_CASE( test_tlb_idempotent ) 00034 { 00035 PluginManager::self manager; 00036 Registry registry; 00037 00038 static const char* test_file = TEST_DATA_PATH("test_cimport.tlb"); 00039 { 00040 utilmm::config_set config; 00041 manager->load("tlb", test_file, config, registry); 00042 } 00043 00044 string result; 00045 result = manager->save("tlb", registry); 00046 istringstream io(result); 00047 utilmm::config_set config; 00048 Registry* reloaded = NULL; 00049 reloaded = manager->load("tlb", io, config); 00050 00051 if (!registry.isSame(*reloaded)) 00052 { 00053 RegistryIterator it = registry.begin(), 00054 end = registry.end(); 00055 for (; it != end; ++it) 00056 { 00057 if (!reloaded->has(it->getName(), true)) 00058 std::cerr << "reloaded does not have " << it->getName() << std::endl; 00059 else if (!(*it).isSame(*reloaded->build(it->getName()))) 00060 { 00061 std::cerr << "versions of " << it->getName() << " differ" << std::endl; 00062 std::cerr << *it << std::endl << std::endl; 00063 std::cerr << *reloaded->get(it->getName()) << std::endl; 00064 } 00065 } 00066 } 00067 } 00068 00069 BOOST_AUTO_TEST_CASE( test_tlb_import ) 00070 { 00071 PluginManager::self manager; 00072 auto_ptr<Importer> importer(manager->importer("tlb")); 00073 utilmm::config_set config; 00074 00075 { 00076 string empty_tlb = "<?xml version=\"1.0\"?>\n<typelib>\n</typelib>"; 00077 istringstream stream(empty_tlb); 00078 Registry registry; 00079 importer->load(stream, config, registry); 00080 } 00081 00082 { 00083 string invalid_element_type = "<?xml version=\"1.0\"?>\n<typelib>\n<invalid_thing name=\"fake\"/></typelib>"; 00084 istringstream stream(invalid_element_type); 00085 Registry registry; 00086 BOOST_CHECK_THROW(importer->load(stream, config, registry), std::runtime_error); 00087 } 00088 { 00089 string missing_arg = "<?xml version=\"1.0\"?>\n<typelib>\n<invalid_thing /></typelib>"; 00090 istringstream stream(missing_arg); 00091 Registry registry; 00092 BOOST_CHECK_THROW(importer->load(stream, config, registry), std::runtime_error); 00093 } 00094 00095 00096 { 00097 ifstream file(TEST_DATA_PATH("rflex.tlb")); 00098 Registry registry; 00099 Typelib::CXX::addStandardTypes(registry); 00100 importer->load(file, config, registry); 00101 00102 BOOST_CHECK( registry.get("/custom_null") ); 00103 BOOST_CHECK( registry.get("/custom_null")->isNull() ); 00104 } 00105 } 00106