#include "ConfigTest.h" #include #include // for cout #include // for setprecision( int p ) #include // For auto_ptr #include #include // For system independent path support namespace bf = boost::filesystem; #include "FilePairLineIterator.h" using namespace std; CPPUNIT_TEST_SUITE_REGISTRATION( ConfigTest ); ConfigTest::ConfigTest() : config(NULL) { } /** */ void ConfigTest::setUp() { } /** */ void ConfigTest::tearDown() { if( config ) delete config; } void ConfigTest::testDataFile() { config = new CERT::Config( "testConfig.xml" ); CPPUNIT_ASSERT( NULL != config ); std::vector items = config->getItems(); CPPUNIT_ASSERT( 1 == items.size() ); CERT::ConfigItem *item = items[0]; CPPUNIT_ASSERT( NULL != item ); CPPUNIT_ASSERT( "edu.ucsd.mplab.cert.LabWeights" == item->getPluginID() ); CPPUNIT_ASSERT( "Lab Weights" == item->getName() ); CPPUNIT_ASSERT( "LabWeights" == item->getInternalName() ); CPPUNIT_ASSERT( "MPT_PluginStep_SVM" == item->getPluginType() ); CPPUNIT_ASSERT( item->getEnabled() ); std::vector dirVec = item->getValueForKey( "dir" ); CPPUNIT_ASSERT( 1 == dirVec.size() ); CPPUNIT_ASSERT( "./SVMWeights" == dirVec[0] ); std::vector labels = item->getValueForKey( "labels" ); CPPUNIT_ASSERT( 5 == labels.size() ); CPPUNIT_ASSERT( "AU 6" == labels[0] ); CPPUNIT_ASSERT( "AU 7" == labels[1] ); CPPUNIT_ASSERT( "AU 16" == labels[2] ); CPPUNIT_ASSERT( "AU 18" == labels[3] ); CPPUNIT_ASSERT( "AU 28" == labels[4] ); } void ConfigTest::testXMLExport() { config = new CERT::Config( "testConfig.xml" ); CPPUNIT_ASSERT( NULL != config ); // write it to a string stream. // read in the original as a string. // compare. std::stringstream output; output << *config; #ifdef DEBUG_ASALAMON { std::ofstream of( "/tmp/testXMLExport.xml" ); of << *config; } #endif std::ifstream origFile( "testConfig.xml" ); std::string orig; std::string line; while( std::getline( origFile, line ) ) { orig += line; orig += "\n"; } // origFile >> orig; CPPUNIT_ASSERT( orig == output.str() ); } void ConfigTest::testBadXML() { CPPUNIT_ASSERT_THROW( (new CERT::Config( "badConfig.xml" )), CERT::Config::exception ); }