testSmbiosXml.cpp

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:textwidth=0:
00003  *
00004  * Copyright (C) 2005 Dell Inc.
00005  *  by Michael Brown <Michael_E_Brown@dell.com>
00006  * Licensed under the Open Software License version 2.1 
00007  * 
00008  * Alternatively, you can redistribute it and/or modify 
00009  * it under the terms of the GNU General Public License as published 
00010  * by the Free Software Foundation; either version 2 of the License, 
00011  * or (at your option) any later version.
00012 
00013  * This program is distributed in the hope that it will be useful, but 
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of 
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00016  * See the GNU General Public License for more details.
00017  */
00018 
00019 // for windows auto-lib selection.
00020 // tells compiler to include smbiosxml libs.
00021 // also does additional checks to ensure runtime lib in compiler config 
00022 // is compatible with xerces
00023 #define LIBSMBIOS_NEED_SMBIOSXML
00024 
00025 // compat header should always be first header if including system headers
00026 #include "smbios/compat.h"
00027 
00028 #include <iomanip>
00029 #include <fstream>
00030 
00031 #include "testSmbiosXml.h"
00032 #include "smbios/SmbiosDefs.h"
00033 
00034 // specific to unit tests. Users do not need to include this,
00035 // so it is not in testSmbiosXml.h
00036 #include "smbios/IMemory.h"
00037 #include "smbios/ISmi.h"
00038 #include "smbios/IObserver.h"
00039 
00040 #include "smbios/version.h"
00041 
00042 using namespace std;
00043 
00044 extern string global_programDirname;
00045 extern string global_writeDirectory;
00046 
00047 // Note:
00048 //      Except for , there are no "using namespace XXXX;" statements
00049 //      here... on purpose. We want to ensure that while reading this code that
00050 //      it is extremely obvious where each function is coming from.
00051 //
00052 //      This leads to verbose code in some instances, but that is fine for
00053 //      these purposes.
00054 
00055 // Register the test
00056 CPPUNIT_TEST_SUITE_REGISTRATION (testSmbiosXml);
00057 
00058 void copyFile( string dstFile, string srcFile )
00059 {
00060     ifstream src(srcFile.c_str(), ios_base::binary);
00061     ofstream dst(dstFile.c_str(), ios_base::out | ios_base::binary | ios_base::trunc);
00062 
00063     char ch;
00064     while( src.get(ch)) dst.put(ch);
00065 
00066     if( !src.eof() || !dst ) throw exception();
00067 }
00068 
00069 bool fileExists(string fileName)
00070 {
00071     FILE *fh=0;
00072     fh=fopen(fileName.c_str(), "rb");
00073     if(!fh)
00074         return false;
00075 
00076     fclose(fh);
00077     return true;
00078 }
00079 
00080 void testSmbiosXml::setUp()
00081 {
00082     string xmlFile = global_programDirname + getXmlFile();
00083     string testInput = global_programDirname + getTestDirectory() + "/testInput.xml";
00084     if(!fileExists(testInput))
00085         testInput = getTestDirectory() + "/testInput.xml"; 
00086 
00087     // copy the memdump.dat file. We do not write to it, but rw open will fail
00088     // if we do not copy it
00089     string memdumpOrigFile = global_programDirname + getTestDirectory() + "/memdump.dat";
00090     if(!fileExists(memdumpOrigFile))
00091         memdumpOrigFile = getTestDirectory() + "/memdump.dat";
00092     string memdumpCopyFile = global_writeDirectory + "/memdump-copy.dat";
00093     copyFile( memdumpCopyFile, memdumpOrigFile );
00094 
00095     // copy the CMOS file. We are going to write to it and do not wan to mess up
00096     // the pristine unit test version
00097     string cmosOrigFile = global_programDirname + getTestDirectory() + "/cmos.dat";
00098     if(!fileExists(cmosOrigFile))
00099         cmosOrigFile = getTestDirectory() + "/cmos.dat";
00100     string cmosCopyFile = global_writeDirectory + "/cmos-copy.dat";
00101     copyFile( cmosCopyFile, cmosOrigFile );
00102 
00103     // Smi output file.
00104     string smiOutput = global_writeDirectory + "/smi-output.dat";
00105 
00106     // set up XML factory. from here on, we can just say SmbiosFactory.
00107     smbios::SmbiosXmlFactory::getFactory();
00108 
00109     // normal users of the smbios classes need not
00110     // set the four parameters below. They should all be set inside the factory
00111     // properly by default. We override stuff here to have
00112     // the smbios, cmos, etc classes use file dumps instead of
00113     // real memory/cmos/etc.
00114     smbios::SmbiosFactory::getFactory()->setParameter("memFile", memdumpCopyFile);
00115     smbios::SmbiosFactory::getFactory()->setParameter("offset", 0);
00116     smbios::SmbiosFactory::getFactory()->setMode(smbios::SmbiosFactory::UnitTestMode);
00117 
00118     cmos::  CmosRWFactory::getFactory()->setParameter("cmosMapFile", cmosCopyFile);
00119     cmos::  CmosRWFactory::getFactory()->setMode( factory::IFactory::UnitTestMode );
00120 
00121     memory::MemoryFactory::getFactory()->setParameter("memFile", memdumpCopyFile);
00122     memory::MemoryFactory::getFactory()->setMode( memory::MemoryFactory::UnitTestMode );
00123 
00124     smi::SmiFactory::getFactory()->setParameter("smiFile", smiOutput);
00125     smi::SmiFactory::getFactory()->setMode( smi::SmiFactory::UnitTestMode );
00126 
00127     // The parameter below will normally need to be set by the client code.
00128     smbios::SmbiosFactory::getFactory()->setParameter("xmlFile", xmlFile);
00129 
00130     parser = 0;
00131     doc = 0;
00132     try
00133     {
00134         XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::Initialize();
00135         parser = xmlutils::getParser();
00136         doc = parser->parseURI( testInput.c_str() );
00137     }
00138     catch ( ... )
00139     {}
00140 
00141 }
00142 
00143 void testSmbiosXml::resetFactoryToBuiltinXml()
00144 {
00145     smbios::SmbiosFactory::getFactory()->setParameter("xmlFile", "");
00146 }
00147 
00148 void testSmbiosXml::tearDown()
00149 {
00150     // the factory is static. If we do not reset the factory, the next
00151     // unit test may accidentally get the wrong objects.
00152     // Lifetime rules: CmosTokenTable cannot live longer than the ISmbiosTable
00153     // object used in its construction.
00154     smbios::TokenTableFactory::getFactory()->reset();
00155 
00156     smbios::SmbiosFactory::getFactory()->reset();
00157 
00158     memory::MemoryFactory::getFactory()->reset();
00159 
00160     cmos::CmosRWFactory::getFactory()->reset();
00161 
00162     smi::SmiFactory::getFactory()->reset();
00163 
00164     parser->resetDocumentPool();
00165     parser->release();
00166     parser = 0;
00167     doc = 0;
00168     XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::Terminate();
00169 }
00170 
00171 // checkSkipTest for Skipping known BIOS Bugs.
00172 void 
00173 testSmbiosXml::checkSkipTest(string testName)
00174 {
00175     if(!doc)
00176         return;
00177 
00178     try
00179     {
00180         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *testsToSkip = xmlutils::findElement(doc->getDocumentElement(),"testsToSkip","","");
00181         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *test = xmlutils::findElement(testsToSkip,"test","name",testName);
00182 
00183         if(test)
00184             throw skip_test();
00185     }
00186     catch (const skip_test &)
00187     {
00188         throw;
00189     }
00190     catch (const exception &)
00191     {
00192         //Do Nothing
00193     }
00194 }
00195 
00196 
00197 //
00198 //
00199 // TABLE tests
00200 //
00201 //
00202 
00203 void testSmbiosXml::testTable_Subscript()
00204 {
00205     STD_TEST_START("%s  ", getTestName().c_str() );
00206     // PURPOSE:
00207     //      The purpose of this test is to test the subscript operator [].
00208     //      It tests these operators using string and int args and tests
00209     //      it outside of a loop.
00210 
00211     // table should not be deleted when we are finished. It is managed by the
00212     // factory. Factory will delete it for us when ->reset() is called.
00213     smbios::ISmbiosTable *table =
00214         smbios::SmbiosFactory::getFactory()->getSingleton();
00215 
00216     smbios::ISmbiosTable::iterator item1;
00217     smbios::ISmbiosTable::iterator item2;
00218 
00219     item1 = (*table)["BIOS Information"];
00220     item2 = (*table)[smbios::BIOS_Information];
00221 
00222     // Use CPPUNIT_ASSERT_EQUAL when testing equality.
00223     // It gives better diagnostics on failure.
00224     CPPUNIT_ASSERT_EQUAL( item1->getHandle(), item2->getHandle() );
00225     CPPUNIT_ASSERT_EQUAL( item1->getLength(), item2->getLength() );
00226     CPPUNIT_ASSERT_EQUAL( item1->getType()  , item2->getType()   );
00227 
00228     CPPUNIT_ASSERT_EQUAL( (*table)[smbios::BIOS_Information]->getType(), item1->getType() );
00229     CPPUNIT_ASSERT_EQUAL( (*table)["BIOS Information"]->getType(), item1->getType() );
00230 
00231     item1 = (*table)["System Information"];
00232     item2 = (*table)[smbios::System_Information];
00233 
00234     CPPUNIT_ASSERT_EQUAL( item1->getHandle(), item2->getHandle() );
00235     CPPUNIT_ASSERT_EQUAL( item1->getLength(), item2->getLength() );
00236     CPPUNIT_ASSERT_EQUAL( item1->getType()  , item2->getType()   );
00237 
00238     CPPUNIT_ASSERT_EQUAL( (*table)[smbios::System_Information]->getType(), item1->getType() );
00239     CPPUNIT_ASSERT_EQUAL( (*table)["System Information"]->getType(), item1->getType() );
00240 
00241 
00242     STD_TEST_END();
00243 }
00244 
00245 void testSmbiosXml::testTable_Subscript_builtinXml()
00246 {
00247     resetFactoryToBuiltinXml();
00248     testTable_Subscript();
00249 }
00250 
00251 void
00252 testSmbiosXml::testEntryCount ()
00253 {
00254     STD_TEST_START("%s  ", getTestName().c_str() );
00255 
00256     // do not delete. Factory manages lifetime.
00257     smbios::ISmbiosTable *table =
00258         smbios::SmbiosFactory::getFactory()->getSingleton();
00259 
00260     // test streamify() while we are at it.
00261     ostringstream ost;
00262     int tableEntriesCounted = 0;
00263     smbios::ISmbiosTable::iterator item = table->begin();
00264     while( item != table->end() )
00265     {
00266         tableEntriesCounted++;
00267         ost << *item << endl;
00268         ++item;
00269     }
00270 
00271     CPPUNIT_ASSERT_EQUAL( tableEntriesCounted, table->getNumberOfEntries() );
00272     STD_TEST_END();
00273 }
00274 
00275 void testSmbiosXml::testEntryCount_builtinXml ()
00276 {
00277     resetFactoryToBuiltinXml();
00278     testEntryCount();
00279 }
00280 
00281 void
00282 testSmbiosXml::testConstIterator ()
00283 {
00284     STD_TEST_START("%s  ", getTestName().c_str() );
00285 
00286     // do not delete. Factory manages lifetime.
00287     smbios::ISmbiosTable *table =
00288         smbios::SmbiosFactory::getFactory()->getSingleton();
00289 
00290     const smbios::ISmbiosTable *constTable = &*table;
00291 
00292     int tableEntriesCounted = 0;
00293     smbios::ISmbiosTable::const_iterator item = constTable->begin();
00294     while( item != constTable->end() )
00295     {
00296         tableEntriesCounted++;
00297         (void) *item;  // do this to sniff out possible errors with deref iterator.
00298 
00299         ++item;
00300     }
00301     CPPUNIT_ASSERT_EQUAL( tableEntriesCounted, constTable->getNumberOfEntries() );
00302     STD_TEST_END();
00303 }
00304 
00305 void testSmbiosXml::testConstIterator_builtinXml ()
00306 {
00307     resetFactoryToBuiltinXml();
00308     testConstIterator();
00309 }
00310 
00311 void
00312 testSmbiosXml::testSubscriptOperator1 ()
00313 {
00314     STD_TEST_START("%s  ", getTestName().c_str() );
00315 
00316     // do not delete. Factory manages lifetime.
00317     smbios::ISmbiosTable *table =
00318         smbios::SmbiosFactory::getFactory()->getSingleton();
00319 
00320     int tableEntriesCounted = 0;
00321     // table[-1] is special, it returns all objects.
00322     // This test should be identical to testConstIterator (both walk all entries)
00323     for( smbios::ISmbiosTable::iterator item = (*table)[-1] ; item != table->end(); ++item)
00324     {
00325         tableEntriesCounted++;
00326         (void) *item;  // do this to sniff out possible errors with deref iterator.
00327     }
00328     CPPUNIT_ASSERT_EQUAL( table->getNumberOfEntries(), tableEntriesCounted );
00329     STD_TEST_END();
00330 }
00331 
00332 void testSmbiosXml::testSubscriptOperator1_builtinXml ()
00333 {
00334     resetFactoryToBuiltinXml();
00335     testSubscriptOperator1();
00336 }
00337 
00338 void
00339 testSmbiosXml::testSubscriptOperator2 ()
00340 {
00341     STD_TEST_START("%s  ", getTestName().c_str() );
00342 
00343 // it turns out that 8450 has 3 BIOS Information blocks.
00344 
00345 //    // do not delete. Factory manages lifetime.
00346 //    smbios::ISmbiosTable *table =
00347 //        smbios::SmbiosFactory::getFactory()->getSingleton();
00348 //
00349 //    // There should probably be only one "BIOS Information" block. Check.
00350 //    //  update this test if it turns out that there are actual systems with >1 Bios Info block
00351 //    //
00352 //    int tableEntriesCounted = 0;
00353 //    for( smbios::ISmbiosTable::iterator item = (*table)[0] ; item != table->end(); ++item)
00354 //    {
00355 //        (void) *item;  // do this to sniff out possible errors with deref iterator.
00356 //        tableEntriesCounted++;
00357 //    }
00358 //    CPPUNIT_ASSERT_EQUAL( 1, tableEntriesCounted );
00359 
00360     STD_TEST_END();
00361 }
00362 
00363 void testSmbiosXml::testSubscriptOperator2_builtinXml ()
00364 {
00365     resetFactoryToBuiltinXml();
00366     testSubscriptOperator2();
00367 }
00368 
00369 void
00370 testSmbiosXml::testSubscriptOperator3 ()
00371 {
00372     STD_TEST_START("%s  ", getTestName().c_str() );
00373 
00374     // do not delete. Factory manages lifetime.
00375     smbios::ISmbiosTable *table =
00376         smbios::SmbiosFactory::getFactory()->getSingleton();
00377 
00378     // There should normally be more than one "Port Connector" block. Check.
00379     //                               "Port Connector" block is type == 8
00380     //   memdump-opti.txt     has 12
00381     //   memdump-PAweb110.txt has 17
00382     //   memdump-PAweb110.txt has 9  *unverified...
00383     //  update this test if it turns out that there are actual systems with <2 Port Connector blocks
00384     //
00385     int tableEntriesCounted = 0;
00386     for( smbios::ISmbiosTable::iterator item = (*table)[8] ; item != table->end(); ++item)
00387     {
00388         (void) *item;  // do this to sniff out possible errors with deref iterator.
00389         tableEntriesCounted++;
00390     }
00391     CPPUNIT_ASSERT( 1 < tableEntriesCounted );
00392     STD_TEST_END();
00393 }
00394 
00395 void testSmbiosXml::testSubscriptOperator3_builtinXml ()
00396 {
00397     resetFactoryToBuiltinXml();
00398     testSubscriptOperator3();
00399 }
00400 
00401 
00402 
00403 //
00404 //
00405 // ITEM tests
00406 //
00407 //
00408 
00409 void testSmbiosXml::testStreamify()
00410 {
00411     STD_TEST_START("%s  ", getTestName().c_str() );
00412 
00413     // BEGIN EXAMPLE iterator
00414     // table should not be deleted when we are finished. It is managed by the
00415     // factory. Factory will delete it for us when ->reset() is called.
00416     smbios::ISmbiosTable *table =
00417         smbios::SmbiosFactory::getFactory()->getSingleton();
00418 
00419     ostringstream ost;
00420     ost << *table << endl;
00421 
00422     // iterate over all PORT INFORMATION BLOCKS
00423     for( smbios::ISmbiosTable::iterator item = (*table)[8] ; item != table->end(); ++item)
00424     {
00425         ost << *item << endl;
00426     }
00427     // END EXAMPLE iterator
00428 
00429     STD_TEST_END();
00430 }
00431 
00432 void
00433 testSmbiosXml::testItemIdentity ()
00434 {
00435     STD_TEST_START("%s  ", getTestName().c_str() );
00436     // test that when we grab things out of the
00437     // table, we get copies of the same thing
00438     // when we ask for the same thing, rather than
00439     // separate items with the same data.
00440     //
00441     // we use references below to make the CPPUNIT_ASSERT
00442     // a bit easier to read.
00443 
00444     // do not delete. Factory manages lifetime.
00445     smbios::ISmbiosTable *table =
00446         smbios::SmbiosFactory::getFactory()->getSingleton();
00447 
00448     // grab the first bios block
00449     smbios::ISmbiosTable::iterator position1 = (*table)[smbios::BIOS_Information];
00450     smbios::ISmbiosItem &item1 = *position1; //reference
00451 
00452     // use another iterator and grab another
00453     smbios::ISmbiosTable::iterator position2 = (*table)[smbios::BIOS_Information];
00454     smbios::ISmbiosItem &item2 = *position2; //reference
00455 
00456     // Check that they both gave the same thing
00457     // The address of each should be equal
00458     CPPUNIT_ASSERT_EQUAL(  &item1, &item2 );  // easiest to read
00459     CPPUNIT_ASSERT_EQUAL(  &(*position1), &item2 ); // same test, written differently
00460     CPPUNIT_ASSERT_EQUAL(  &item1       , &(*position2) ); // same test, written differently
00461     CPPUNIT_ASSERT_EQUAL(  &(*position1), &(*position2) ); // same test, written differently
00462 
00463     // use another iterator and grab another _different_ pointer.
00464     smbios::ISmbiosTable::iterator position3 = (*table)[smbios::System_Information];
00465     smbios::ISmbiosItem &item3 = *position3; //reference
00466 
00467     // Check that these are different...
00468     CPPUNIT_ASSERT( &item1 != &item3 );
00469     CPPUNIT_ASSERT( &item2 != &item3 );
00470 
00471     CPPUNIT_ASSERT_EQUAL( item1.getType(), static_cast<u8>(smbios::BIOS_Information) );
00472     CPPUNIT_ASSERT_EQUAL( item2.getType(), static_cast<u8>(smbios::BIOS_Information) );
00473     CPPUNIT_ASSERT_EQUAL( item3.getType(), static_cast<u8>(smbios::System_Information) );
00474 
00475     STD_TEST_END();
00476 }
00477 
00478 void testSmbiosXml::testItemIdentity_builtinXml ()
00479 {
00480     resetFactoryToBuiltinXml();
00481     testItemIdentity();
00482 }
00483 
00484 void
00485 testSmbiosXml::testEachItemAccessors ()
00486 {
00487     STD_TEST_START("%s  ", getTestName().c_str() );
00488     // test ->getU8 and ->getU16 methods
00489     // no way to test in generic table the ->getU32
00490     // or ->getU64
00491     //
00492     // primarily to ensure that getUx() has the endianness correct
00493 
00494     // do not delete. Factory manages lifetime.
00495     smbios::ISmbiosTable *table =
00496         smbios::SmbiosFactory::getFactory()->getSingleton();
00497 
00498     smbios::ISmbiosTable::iterator item = table->begin();
00499     while( item != table->end() )
00500     {
00501         u8 type1 = item->getType();
00502         u8 type2 = item->getU8(0);
00503         CPPUNIT_ASSERT_EQUAL( type1, type2 );
00504 
00505         u8 len1 = item->getLength();
00506         u8 len2 = item->getU8(1);
00507         CPPUNIT_ASSERT_EQUAL( len1, len2 );
00508 
00509         u16 handle1 = item->getHandle();
00510         u16 handle2 = item->getU16(2);
00511         CPPUNIT_ASSERT_EQUAL( handle1, handle2 );
00512 
00513         ++item;
00514     }
00515 
00516     STD_TEST_END();
00517 }
00518 
00519 void testSmbiosXml::testEachItemAccessors_builtinXml ()
00520 {
00521     resetFactoryToBuiltinXml();
00522     testSmbiosXml::testEachItemAccessors();
00523 }
00524 
00525 void testSmbiosXml::testItem_GetBiosInfo()
00526 {
00527     STD_TEST_START("%s  ", getTestName().c_str() );
00528     // Purpose:
00529     //      The purpose of this test is to exercise all of the getXX()
00530     //      functions that are avalable using std SMBIOS tables that are
00531     //      available on all dumps. Do not rely on any specific value in any
00532     //      table in these tests as this test will be run against many
00533     //      tables.
00534     //
00535 
00536     // BEGIN EXAMPLE factory
00537     // table should not be deleted when we are finished. It is managed by the
00538     // factory. Factory will delete it for us when ->reset() is called.
00539     smbios::ISmbiosTable *table =
00540         smbios::SmbiosFactory::getFactory()->getSingleton();
00541 
00542     smbios::ISmbiosTable::iterator item1 = (*table)["BIOS Information"];
00543 
00544     //
00545     // here is an example XML for BIOS Information Block, which we test below.
00546     //
00547     //<FIELD offset="0h" name="Type" length="BYTE" usage="STRUCTURE_TYPE"/>
00548     //<FIELD offset="1h" name="Length" length="BYTE" usage="SIZE"/>
00549     //<FIELD offset="2h" name="Handle" length="WORD" usage="HANDLE"/>
00550     //<FIELD offset="4h" name="Vendor" length="BYTE" usage="STRING"/>
00551     //<FIELD offset="5h" name="BIOS Version" length="BYTE" usage="STRING"/>
00552     //<FIELD offset="6h" name="BIOS Starting Address Segment" length="WORD" usage="ADDRESS"/>
00553     //<FIELD offset="8h" name="BIOS Release Date" length="BYTE" usage="STRING"/>
00554     //<FIELD offset="9h" name="BIOS ROM Size" length="BYTE" usage="SIZE"/>
00555     //<FIELD offset="Ah" name="BIOS Characteristics" length="QWORD" usage="BITFIELD">
00556     //
00557 
00558     u64 ll1, ll2;
00559     int int1, int2;
00560     string str1, str2;
00561 
00562     // Test Philosophy:
00563     //      There are multiple ways to access any particular item in the table.
00564     //      If you have an XML smbios file, you can access by string name and
00565     //      the code will look the name up in the XML.
00566     //
00567     //      We play the different access modes off each other below to ensure
00568     //      that each access mode returns the exact same data.
00569     int1 = item1->getU8("Type");
00570     int2 = item1->getType();
00571     CPPUNIT_ASSERT_EQUAL (int1, int2);
00572 
00573     int1 = item1->getU8("Length");
00574     int2 = item1->getLength();
00575     CPPUNIT_ASSERT_EQUAL (int1, int2);
00576 
00577     int1 = item1->getU16("Handle");
00578     int2 = item1->getHandle();
00579     CPPUNIT_ASSERT_EQUAL (int1, int2);
00580 
00581     str1 = item1->getString("Vendor") ;
00582     str2 = item1->getString( 0x4 ) ;
00583     CPPUNIT_ASSERT_EQUAL (str1, str2);
00584 
00585     str1 = item1->getString("BIOS Version") ;
00586     str2 = item1->getString( 0x5 ) ;
00587     CPPUNIT_ASSERT_EQUAL (str1, str2);
00588 
00589     int1 = item1->getU16("BIOS Starting Address Segment");
00590     int2 = item1->getU16( 0x6 );
00591     CPPUNIT_ASSERT_EQUAL (int1, int2);
00592 
00593     str1 = item1->getString("BIOS Release Date");
00594     str2 = item1->getString( 0x8 );
00595     CPPUNIT_ASSERT_EQUAL (str1, str2);
00596 
00597     int1 = item1->getU8("BIOS ROM Size");
00598     int2 = item1->getU8(0x9);
00599     CPPUNIT_ASSERT_EQUAL (int1, int2);
00600 
00601     ll1 = item1->getU64("BIOS Characteristics");
00602     ll2 = item1->getU64(0xA);
00603     // will not compile on VC++
00604     //    CPPUNIT_ASSERT_EQUAL (ll1, ll2);
00605 
00606     //First get some bits from the BIOS Characteristics bitfield and compare to U64
00607     u32 bitfield = item1->getBitfield(0xA, smbios::ISmbiosItem::FIELD_LEN_QWORD, 0, 15);
00608     CPPUNIT_ASSERT_EQUAL (static_cast<u32>(ll2 & 0x000000000000FFFFL), bitfield);
00609 
00610     //Get some bits from the BIOS Characteristics bitfield using the other method
00611     //and compare it to the U64
00612     bitfield = 0;
00613     bitfield = item1->getBitfield("BIOS Characteristics", "Reserved0");
00614     bitfield |= item1->getBitfield("BIOS Characteristics", "Reserved1") << 1;
00615     bitfield |= item1->getBitfield("BIOS Characteristics", "Unknown") << 2;
00616     bitfield |= item1->getBitfield("BIOS Characteristics", "BIOS Characteristics Not Supported") << 3;
00617     bitfield |= item1->getBitfield("BIOS Characteristics", "ISA is supported") << 4;
00618     bitfield |= item1->getBitfield("BIOS Characteristics", "MCA is supported") << 5;
00619     bitfield |= item1->getBitfield("BIOS Characteristics", "EISA is supported") << 6;
00620     bitfield |= item1->getBitfield("BIOS Characteristics", "PCI is supported") << 7;
00621     bitfield |= item1->getBitfield("BIOS Characteristics", "PC Card (PCMCIA) is supported") << 8;
00622     bitfield |= item1->getBitfield("BIOS Characteristics", "Plug and Play is supported") << 9;
00623     bitfield |= item1->getBitfield("BIOS Characteristics", "APM is supported") << 0x0a;
00624     bitfield |= item1->getBitfield("BIOS Characteristics", "BIOS is Upgradeable (Flash)") << 0x0b;
00625     bitfield |= item1->getBitfield("BIOS Characteristics", "BIOS shadowing is allowed") << 0x0c;
00626     bitfield |= item1->getBitfield("BIOS Characteristics", "VL-VESA is supported") << 0x0d;
00627     bitfield |= item1->getBitfield("BIOS Characteristics", "ESCD support is available") << 0x0e;
00628     bitfield |= item1->getBitfield("BIOS Characteristics", "Boot from CD is supported") << 0x0f;
00629     //cout << "BIOS Characteristics Bitfield (0x" << hex << bitfield << ")" << dec << endl;
00630     //Compare the lower 15 bits with the bitfield we just retrieved
00631     CPPUNIT_ASSERT_EQUAL (static_cast<u32>(ll2 & 0x000000000000FFFFL), bitfield);
00632 
00633     STD_TEST_END();
00634 }
00635 
00636 void testSmbiosXml::testItem_GetBiosInfo_builtinXml ()
00637 {
00638     resetFactoryToBuiltinXml();
00639     testItem_GetBiosInfo();
00640 }
00641 
00642 void testSmbiosXml::testItem_GetSystemInfo()
00643 {
00644     STD_TEST_START("%s  ", getTestName().c_str() );
00645     // PURPOSE:
00646     //      Same purpose as testGet_BiosInfo()
00647 
00648     // do not delete. Factory manages lifetime.
00649     smbios::ISmbiosTable *table =
00650         smbios::SmbiosFactory::getFactory()->getSingleton();
00651 
00652     smbios::ISmbiosTable::iterator item1 = ( *table )["System Information"];
00653 
00654     //
00655     // here is an example XML for System Information Block, which we test below.
00656     //
00657     // <FIELD offset="0h" name="Type" length="BYTE" usage="STRUCTURE_TYPE"/>
00658     // <FIELD offset="1h" name="Length" length="BYTE" usage="SIZE"/>
00659     // <FIELD offset="2h" name="Handle" length="WORD" usage="HANDLE"/>
00660     // <FIELD offset="4h" name="Manufacturer" length="BYTE" usage="STRING"/>
00661     // <FIELD offset="5h" name="Product Name" length="BYTE" usage="STRING"/>
00662     // <FIELD offset="6h" name="Version" length="BYTE" usage="STRING"/>
00663     // <FIELD offset="7h" name="Serial Number" length="BYTE" usage="STRING"/>
00664     // <FIELD offset="8h" version="2.1" name="UUID" length="BYTE" count="16" usage="NUMBER"/>
00665     // <FIELD offset="18h" version="2.1" name="Wake-up Type" length="BYTE" usage="ENUM">
00666     //
00667     //
00668     string str1, str2;
00669     int int1, int2;
00670 
00671     int1 = item1->getU8("Type");
00672     int2 = item1->getType();
00673     CPPUNIT_ASSERT_EQUAL (int1, int2);
00674 
00675     int1 = item1->getU8("Length");
00676     int2 = item1->getLength();
00677     CPPUNIT_ASSERT_EQUAL (int1, int2);
00678 
00679     int1 = item1->getU16("Handle");
00680     int2 = item1->getHandle();
00681     CPPUNIT_ASSERT_EQUAL (int1, int2);
00682 
00683     str1 = item1->getString("Manufacturer") ;
00684     str2 = item1->getString( 0x4 ) ;
00685     CPPUNIT_ASSERT_EQUAL (str1, str2);
00686 
00687     str1 = item1->getString("Product Name") ;
00688     str2 = item1->getString( 0x5 ) ;
00689     CPPUNIT_ASSERT_EQUAL (str1, str2);
00690 
00691 #if 0
00692     //
00693     // This is not a good test case because several
00694     // of our BIOSs have a '\0' in the header for this
00695     // string, which means this string does not
00696     // exist. Lowlevel code will throw an exception.
00697     //
00698     str1 = item1->getString("Version") ;
00699     str2 = item1->getString( 0x6 ) ;
00700     CPPUNIT_ASSERT_EQUAL( str1, str2 );
00701 #endif
00702 
00703     try
00704     {
00705         str1 = item1->getString("Serial Number") ;
00706         str2 = item1->getString( 0x7 ) ;
00707         CPPUNIT_ASSERT_EQUAL (str1, str2);
00708     }
00709     catch( const exception & )
00710     {
00711         // 4G systems do not support Serial Number.
00712     }
00713 
00714 #if 0
00715     //
00716     // These are not good test cases because they are SMBIOS 2.3
00717     // additions and are not guaranteed to be present.
00718     //
00719     u8 val1, val2;
00720     val1 =  item1->getU8("UUID") ;
00721     val2 = item1->getU8( 0x8 ) ;
00722     CPPUNIT_ASSERT_EQUAL( val1, val2 );
00723 
00724     val1 = item1->getU8("Wake-up Type") ;
00725     val2 = item1->getU8( 0x9 ) ;
00726     CPPUNIT_ASSERT_EQUAL( val1, val2 );
00727 #endif
00728 
00729     STD_TEST_END();
00730 }
00731 
00732 void testSmbiosXml::testItem_GetSystemInfo_builtinXml ()
00733 {
00734     resetFactoryToBuiltinXml();
00735     testItem_GetSystemInfo();
00736 }
00737 
00738 
00739 void testSmbiosXml::testTypeMismatch()
00740 {
00741     STD_TEST_START("%s  ", getTestName().c_str() );
00742     // PURPOSE:
00743     //      The purpose of this test is to test all types of invalid item
00744     //      access. The getXX(string) methods all validate that the field
00745     //      passed to them is actually of type XX. If a mismatch is found, an
00746     //      exception is thrown.
00747     //
00748     //      Each test validates that an exception is thrown and the type.
00749 
00750     // do not delete. Factory manages lifetime.
00751     smbios::ISmbiosTable *table =
00752         smbios::SmbiosFactory::getFactory()->getSingleton();
00753 
00754     smbios::ISmbiosTable::iterator item1 = (*table)["BIOS Information"];
00755 
00756     //
00757     // refer to testGet_BiosInfo() for XML sample for BIOS INFORMATION BLOCK
00758     //
00759 
00760     // ASSERT_THROWS is not a CPPUNIT macro, it is our custom macro.
00761     ASSERT_THROWS( item1->getU8("Handle"), smbios::ParseException );
00762     ASSERT_THROWS( item1->getU16("Type"), smbios::ParseException );
00763     ASSERT_THROWS( item1->getU32("Type"), smbios::ParseException );
00764     ASSERT_THROWS( item1->getU64("Type"), smbios::ParseException );
00765     ASSERT_THROWS( item1->getString("Type"), smbios::ParseException );
00766     ASSERT_THROWS( item1->getBitfield("Type", "foo"), smbios::ParseException );
00767 
00768     STD_TEST_END();
00769 }
00770 
00771 void testSmbiosXml::testTypeMismatch_builtinXml ()
00772 {
00773     resetFactoryToBuiltinXml();
00774     testSmbiosXml::testTypeMismatch();
00775 }
00776 
00777 
00778 void
00779 testSmbiosXml::testGetBoundaries()
00780 {
00781     STD_TEST_START("%s  ", getTestName().c_str() );
00782 
00783     // do not delete. Factory manages lifetime.
00784     smbios::ISmbiosTable *table =
00785         smbios::SmbiosFactory::getFactory()->getSingleton();
00786 
00787     for( smbios::ISmbiosTable::iterator item = (*table)[-1] ; item != table->end(); ++item)
00788     {
00789         int len = item->getLength();
00790 
00791         // none of these should throw.
00792         (void) item->getU8(len - 1);
00793         (void) item->getU16(len - 2);
00794         (void) item->getU32(len - 4);
00795 
00796         // not all items are large enough. only attempt if item is at least 8 bytes
00797         if( len >= 8 )
00798             (void) item->getU64(len - 8);
00799 
00800         ASSERT_THROWS( item->getU8(len - 0), smbios::DataOutOfBounds);
00801         ASSERT_THROWS( item->getU16(len - 1), smbios::DataOutOfBounds);
00802         ASSERT_THROWS( item->getU32(len - 3), smbios::DataOutOfBounds);
00803         ASSERT_THROWS( item->getU64(len - 7), smbios::DataOutOfBounds);
00804     }
00805 
00806     STD_TEST_END();
00807 }
00808 
00809 void testSmbiosXml::testGetBoundaries_builtinXml ()
00810 {
00811     resetFactoryToBuiltinXml();
00812     testSmbiosXml::testGetBoundaries();
00813 }
00814 
00815 
00816 //
00817 // CMOS Token
00818 //
00819 
00820 
00821 void
00822 testSmbiosXml::testCmosConstructor ()
00823 {
00824     STD_TEST_START("%s  ", getTestName().c_str() );
00825 
00826     smbios::TokenTableFactory *ttFactory;
00827     ttFactory = smbios::TokenTableFactory::getFactory() ;
00828     smbios::ITokenTable *tokenTable = ttFactory->getSingleton();
00829 
00830     ostringstream ost;
00831 
00832     smbios::ITokenTable::iterator token = tokenTable->begin();
00833     while( token != tokenTable->end() )
00834     {
00835         ost << *token << endl;
00836         ++token;
00837     }
00838 
00839     STD_TEST_END();
00840 }
00841 
00842 void
00843 testSmbiosXml::testCmosChecksum ()
00844 {
00845     STD_TEST_START("%s  ", getTestName().c_str() );
00846 
00847     smbios::TokenTableFactory *ttFactory;
00848     ttFactory = smbios::TokenTableFactory::getFactory() ;
00849     smbios::ITokenTable *tokenTable = ttFactory->getSingleton();
00850 
00851     smbios::ITokenTable::iterator token = tokenTable->begin();
00852     while( token != tokenTable->end() )
00853     {
00854         (void) *token;
00855         ++token;
00856     }
00857 
00858     cmos::ICmosRW *cmos = cmos::CmosRWFactory::getFactory()->getSingleton();
00859     observer::IObservable *ob = dynamic_cast<observer::IObservable *>(cmos);
00860     bool doUpdate = false;
00861     if( ob )
00862         ob->notify(&doUpdate);
00863 
00864     STD_TEST_END();
00865 }
00866 
00867 void
00868 testSmbiosXml::testCmosWriting ()
00869 {
00870     STD_TEST_START("%s  ", getTestName().c_str() );
00871 
00872     smbios::TokenTableFactory *ttFactory;
00873     ttFactory = smbios::TokenTableFactory::getFactory() ;
00874     smbios::ITokenTable *tokenTable = ttFactory->getSingleton();
00875     const smbios::ITokenTable *tokenTableC = ttFactory->getSingleton();
00876 
00877     ASSERT_THROWS( (*tokenTable) ["la la la"], smbios::NotImplemented );
00878     ASSERT_THROWS( (*tokenTableC)["la la la"], smbios::NotImplemented );
00879 
00880     // test [] on const table.
00881     (void) tokenTableC[0xFE];
00882 
00883     ostringstream ost;
00884     ost << *tokenTable << endl;
00885     ost << *tokenTableC << endl;
00886 
00887     // test const iterator
00888     smbios::ITokenTable::const_iterator tokenC = tokenTableC->begin();
00889     while( tokenC != tokenTableC->end() )
00890     {
00891         (void) *tokenC;
00892         (void) tokenC->isString();
00893 
00894         tokenC++;
00895     }
00896 
00897     // refuse to write to cmos unless the checksum is correct
00898     cmos::ICmosRW *cmos = cmos::CmosRWFactory::getFactory()->getSingleton();
00899     observer::IObservable *ob = dynamic_cast<observer::IObservable *>(cmos);
00900     bool doUpdate = false;
00901     if( ob )
00902         ob->notify(&doUpdate);
00903 
00904     smbios::ITokenTable::iterator token = tokenTable->begin();
00905     while( token != tokenTable->end() )
00906     {
00907         //cout << *token << endl;
00908         if( token->isString() )
00909         {
00910             const char *testStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnop";
00911             const u8 *testStrU8 = reinterpret_cast<const u8*>(testStr);
00912             u8 *myStr=0;
00913             u8 *myStr1=0;
00914             try
00915             {
00916                 // not really a valid test anymore since SMI tokens can be
00917                 // accessed as bit or string.
00918                 //ASSERT_THROWS( token->activate(), smbios::InvalidAccessMode );
00919                 //ASSERT_THROWS( token->isActive(), smbios::InvalidAccessMode );
00920 
00921                 unsigned int size = token->getStringLength() + 1;
00922 
00923                 myStr1 = new u8[ size ];
00924                 memset( myStr1, 0, size );
00925 
00926                 try
00927                 {
00928                     token->getString( myStr1, size );
00929                 }
00930                 catch(const smi::UnhandledSmi &)
00931                 {   /* if token is a smi token, cannot unit test. */
00932                     delete [] myStr1;
00933                     goto next_token;
00934                 }
00935 
00936                 token->setString( testStrU8, strlen(testStr) + 1 );
00937 
00938                 CPPUNIT_ASSERT( size <= strlen(testStr)+1 );
00939 
00940                 myStr = new u8[ size ];
00941                 memset( myStr, 0, size );
00942                 token->getString( myStr, size );
00943 
00944                 // return might be smaller, only compare up to what was stored.
00945                 if( 0 != memcmp( testStr, reinterpret_cast<char*>(myStr), size - 1 ) )
00946                 {
00947                     // FAILED
00948                     ostringstream ost;
00949                     ost << "String set on token failed." << endl;
00950                     ost << (*token) << endl;
00951                     ost << "Size of string to compare is: " << size-1 << endl;
00952                     ost << "Original data: (" << myStr1  << ")" << endl;
00953                     ost << "Wrote        : (" << testStr << ")" << endl;
00954                     ost << "Read back    : (" << myStr   << ")" << endl;
00955                     CPPUNIT_FAIL( ost.str().c_str() );
00956                 }
00957             }
00958             catch(...)
00959             {
00960                 delete [] myStr1;
00961                 delete [] myStr;
00962                 myStr1 = 0;
00963                 myStr = 0;
00964                 throw;
00965             }
00966             delete [] myStr1;
00967             delete [] myStr;
00968             myStr1 = 0;
00969             myStr = 0;
00970         }
00971         else
00972         {
00973             try
00974             {
00975                 token->activate();
00976             }
00977             catch(const smi::UnhandledSmi &)
00978             {   /* if token is a smi token, cannot unit test. */
00979                 goto next_token;
00980             }
00981             if( ! token->isActive() )
00982             {
00983                 ostringstream ost;
00984                 ost << "Failed to SET bit token. Token data: " << endl;
00985                 ost << (*token);
00986                 CPPUNIT_FAIL( ost.str().c_str() );
00987             }
00988             // not really a valid test anymore since SMI tokens can be
00989             // accessed as bit or string.
00990             //ASSERT_THROWS( token->setString(0, 0), smbios::InvalidAccessMode );
00991             //ASSERT_THROWS( token->getStringLength(), smbios::InvalidAccessMode );
00992         }
00993 
00994 next_token:
00995         // test post-increment behaves properly
00996         smbios::ITokenTable::iterator before = token;
00997         smbios::ITokenTable::iterator after = token++;
00998         CPPUNIT_ASSERT( before == after );
00999     }
01000 
01001     // recheck the checksums.
01002     // ensure that we wrote correct checksums out
01003     if( ob )
01004         ob->notify(&doUpdate);
01005 
01006     STD_TEST_END();
01007 }
01008 
01009 
01010 //
01011 // SMI Tests
01012 //
01013 
01014 void
01015 testSmbiosXml::testSmi_callingInterface()
01016 {
01017     STD_TEST_START("%s  ", getTestName().c_str() );
01018 
01019     std::auto_ptr<smi::ISmi> smi = smi::SmiFactory::getFactory()->makeNew(smi::SmiFactory::DELL_CALLING_INTERFACE_SMI);
01020     smi->setCommandIOMagic( 0x1234, 0x56 );
01021 
01022     smi::IDellCallingInterfaceSmi *ci = dynamic_cast<smi::IDellCallingInterfaceSmi *>(&*smi);
01023     ci->setClass( 0xAABB );
01024     ci->setSelect( 0xCCDD );
01025     ci->setArg( 0, 0xA1A2A3A4 );
01026     ci->setArg( 1, 0xB1B2B3B4 );
01027     ci->setArg( 2, 0xC1C2C3C4 );
01028     ci->setArg( 3, 0xD1D2D3D4 );
01029     try
01030     {   /* This is expected to fail in unit test, no good way to simulate them*/
01031         ci->execute();
01032     }
01033     catch( const smi::UnhandledSmi & ) {}
01034 
01035     STD_TEST_END();
01036 }
01037 
01038 void
01039 testSmbiosXml::testSmi_callingInterface_physaddr ()
01040 {
01041     STD_TEST_START("%s  ", getTestName().c_str() );
01042 
01043     std::auto_ptr<smi::ISmi> smi = smi::SmiFactory::getFactory()->makeNew(smi::SmiFactory::DELL_CALLING_INTERFACE_SMI);
01044     smi->setCommandIOMagic( 0x1234, 0x56 );
01045 
01046     smi::IDellCallingInterfaceSmi *ci = dynamic_cast<smi::IDellCallingInterfaceSmi *>(&*smi);
01047     ci->setClass( 0xAABB );
01048     ci->setSelect( 0xCCDD );
01049     ci->setArgAsPhysicalAddress(0, 0);
01050     ci->setArgAsPhysicalAddress(1, 1);
01051     ci->setArgAsPhysicalAddress(2, 2);
01052     ci->setArgAsPhysicalAddress(3, 3);
01053     try
01054     {   /* This is expected to fail in unit test, no good way to simulate them*/
01055         ci->execute();
01056     }
01057     catch( const smi::UnhandledSmi & ) {}
01058 
01059     STD_TEST_END();
01060 }
01061 
01062 
01063 //
01064 // System Info
01065 //
01066 
01067 
01068 void
01069 testSmbiosXml::testSystemInfo()
01070 {
01071     STD_TEST_START("%s  ", getTestName().c_str() );
01072 
01073     int   systemId   = 0;
01074     const char *systemName = 0;
01075     const char *serviceTag = 0;
01076     const char *assetTag   = 0;
01077     const char *biosVersion   = 0;
01078     const char *vendorName    = 0;
01079 
01080     try
01081     {
01082         systemId   = SMBIOSGetDellSystemId();
01083         systemName = SMBIOSGetSystemName();
01084         serviceTag = SMBIOSGetServiceTag();
01085         assetTag   = SMBIOSGetAssetTag();
01086         biosVersion   = SMBIOSGetBiosVersion();
01087         vendorName    = SMBIOSGetVendorName();
01088 
01089         int   isDell        = SMBIOSIsDellSystem();
01090 
01091         (void) systemId; //avoid unused var warning
01092         (void) isDell; //avoid unused var warning
01093 
01094         //We should at least get an empty string from these
01095         //methods.  Never a null string.
01096         CPPUNIT_ASSERT(systemId != 0);
01097         CPPUNIT_ASSERT(systemName != 0);
01098         //CPPUNIT_ASSERT(serviceTag != 0); // svc tag can legitimately be 0
01099         //CPPUNIT_ASSERT(assetTag != 0); //This fails on latitude so we comment out for now.
01100         CPPUNIT_ASSERT(biosVersion != 0);
01101         CPPUNIT_ASSERT(vendorName != 0);
01102     }
01103     catch(...)
01104     {
01105         SMBIOSFreeMemory( systemName );
01106         SMBIOSFreeMemory( serviceTag );
01107         SMBIOSFreeMemory( assetTag );
01108         SMBIOSFreeMemory( biosVersion );
01109         SMBIOSFreeMemory( vendorName );
01110 
01111         throw;
01112     }
01113 
01114     SMBIOSFreeMemory( systemName );
01115     SMBIOSFreeMemory( serviceTag );
01116     SMBIOSFreeMemory( assetTag );
01117     SMBIOSFreeMemory( biosVersion );
01118     SMBIOSFreeMemory( vendorName );
01119 
01120     STD_TEST_END();
01121 }
01122 
01123 void testSmbiosXml::testSystemInfo_builtinXml ()
01124 {
01125     resetFactoryToBuiltinXml();
01126     testSmbiosXml::testSystemInfo();
01127 }
01128 
01129 
01130 // testInput.xml tests
01131 
01132 
01133 void
01134 testSmbiosXml::testIdByte()
01135 {
01136     STD_TEST_START("%s  ", getTestName().c_str() );
01137 
01138     int   systemId   = SMBIOSGetDellSystemId  ();
01139 
01140     if (!doc)
01141         throw skip_test();
01142 
01143     int id;
01144     try
01145     {
01146         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *systeminfo = xmlutils::findElement( doc->getDocumentElement(), "systemInfo", "", "" );
01147         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *idByte = xmlutils::findElement( systeminfo, "idByte", "", "" );
01148         string idStr = xmlutils::getNodeText( idByte );
01149         id = strtol( idStr.c_str(), 0, 0);
01150     }
01151     catch( const exception & )
01152     {
01153         throw skip_test();
01154     }
01155 
01156     CPPUNIT_ASSERT_EQUAL ( id, systemId );
01157 
01158     STD_TEST_END()
01159 }
01160 
01161 string testSmbiosXml::getTestInputString( string toFind )
01162 {
01163     if (!doc)
01164         throw skip_test();
01165 
01166     string foundString = "";
01167 
01168     try
01169     {
01170         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *systeminfo = xmlutils::findElement( doc->getDocumentElement(), "systemInfo", "", "" );
01171         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *sysName = xmlutils::findElement( systeminfo, toFind, "", "" );
01172         foundString = xmlutils::getNodeText( sysName );
01173     }
01174     catch( const exception & )
01175     {
01176         throw skip_test();
01177     }
01178 
01179     return foundString;
01180 }
01181 
01182 string safeConvertToString( const char *str )
01183 {
01184     string fromSystem = "";
01185     if( 0 != str )
01186     {
01187         fromSystem = str;
01188     }
01189     SMBIOSFreeMemory(str);
01190     return fromSystem;
01191 }
01192 
01193 void
01194 testSmbiosXml::testSystemName()
01195 {
01196     STD_TEST_START("%s  ", getTestName().c_str() );
01197 
01198     string fromSystem = safeConvertToString( SMBIOSGetSystemName() );
01199     string testInput  = getTestInputString( "systemName" );
01200 
01201     CPPUNIT_ASSERT_EQUAL ( testInput, fromSystem );
01202     STD_TEST_END()
01203 }
01204 
01205 void
01206 testSmbiosXml::testLibraryVersion()
01207 {
01208     STD_TEST_START("%s  ", getTestName().c_str() );
01209 
01210     string fromSystem = SMBIOSGetLibraryVersionString();
01211     string testInput  = LIBSMBIOS_RELEASE_VERSION;
01212 
01213     CPPUNIT_ASSERT_EQUAL ( testInput, fromSystem );
01214     STD_TEST_END()
01215 }
01216 
01217 void
01218 testSmbiosXml::testServiceTag()
01219 {
01220     STD_TEST_START("%s  ", getTestName().c_str() );
01221 
01222     string fromSystem = safeConvertToString( SMBIOSGetServiceTag() );
01223     string testInput  = getTestInputString( "serviceTag" );
01224 
01225     CPPUNIT_ASSERT_EQUAL ( testInput, fromSystem );
01226 
01227     STD_TEST_END()
01228 }
01229 
01230 //  not part of public API, so just wing it here so that we can do the unit test.
01231 extern char *getServiceTagFromCMOSToken();
01232 
01233 void
01234 testSmbiosXml::testServiceTagWriting()
01235 {
01236     STD_TEST_START("%s  ", getTestName().c_str() );
01237 
01238     string fromSystem = safeConvertToString( SMBIOSGetServiceTag() );
01239     string testInput  = getTestInputString( "serviceTag" );
01240 
01241     CPPUNIT_ASSERT_EQUAL ( testInput, fromSystem );
01242 
01243     string rawCMOSOrig("");
01244     try
01245     {
01246         rawCMOSOrig = safeConvertToString( getServiceTagFromCMOSToken() );
01247     }
01248     catch(const exception &)
01249     {
01250         // if service tag is not in SMBIOS, we cannot do the
01251         // tests below
01252         throw skip_test();
01253     }
01254 
01255     CPPUNIT_ASSERT_EQUAL ( testInput, rawCMOSOrig );
01256 
01257     string shouldBe, rawCMOSNew;
01258 
01259     // test std 5-char svc tag
01260     shouldBe = "NEWTG";
01261     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01262     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01263 
01264     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01265 
01266     // test std 7-char svc tag (alphabet 1/3)
01267     shouldBe = "BCDFGHJ";
01268     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01269     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01270 
01271     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01272 
01273     // test std 7-char svc tag (alphabet 2/3)
01274     shouldBe = "KLMNPQR";
01275     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01276     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01277 
01278     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01279 
01280     // test std 7-char svc tag (alphabet 3/3)
01281     shouldBe = "STVWXYZ";
01282     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01283     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01284 
01285     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01286 
01287     // odd size (1)
01288     shouldBe = "A";
01289     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01290     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01291 
01292     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01293 
01294     // odd size (2)
01295     shouldBe = "AB";
01296     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01297     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01298 
01299     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01300 
01301     // odd size (3)
01302     shouldBe = "ABC";
01303     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01304     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01305 
01306     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01307 
01308     // odd size (4)
01309     shouldBe = "ABCD";
01310     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01311     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01312 
01313     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01314 
01315     // odd size (6)
01316     shouldBe = "BCDFGH";
01317     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01318     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01319 
01320     shouldBe = "BCDFGH0";  // invalid/missing chars for 7-char svc tag 
01321                     // converted to '0'
01322     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01323 
01324     // odd size (7)
01325     shouldBe = "XGYZYYY";
01326     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01327     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01328 
01329     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01330 
01331     // odd size (8)
01332     shouldBe = "MNPQMNPQ";
01333     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01334     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01335 
01336     shouldBe = "MNPQMNP"; // extra chars ignored
01337     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01338 
01339     // invalid chars in 7-char tag
01340     shouldBe = "ABEIOUD";
01341     SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01342     rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01343 
01344     shouldBe = "AB0000D"; // invalid chars turned into '0';
01345     CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01346 
01347 
01348     STD_TEST_END()
01349 }
01350 
01351 void
01352 testSmbiosXml::testAssetTag()
01353 {
01354     STD_TEST_START("%s  ", getTestName().c_str() );
01355 
01356     string fromSystem = safeConvertToString( SMBIOSGetAssetTag() );
01357     string testInput  = getTestInputString( "assetTag" );
01358 
01359     CPPUNIT_ASSERT_EQUAL ( testInput, fromSystem );
01360 
01361     STD_TEST_END()
01362 }
01363 
01364 void
01365 testSmbiosXml::testBiosVersion()
01366 {
01367     STD_TEST_START("%s  ", getTestName().c_str() );
01368 
01369     string fromSystem = safeConvertToString( SMBIOSGetBiosVersion() );
01370     string testInput  = getTestInputString( "biosVersion" );
01371 
01372     CPPUNIT_ASSERT_EQUAL ( testInput, fromSystem );
01373 
01374     STD_TEST_END()
01375 }
01376 
01377 void
01378 testSmbiosXml::testIsDell()
01379 {
01380     STD_TEST_START("%s  ", getTestName().c_str() );
01381 
01382     int   isDell   = SMBIOSIsDellSystem  ();
01383 
01384     if (!doc)
01385         throw skip_test();
01386 
01387     int isDellExpected;
01388     try
01389     {
01390         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *systeminfo = xmlutils::findElement( doc->getDocumentElement(), "systemInfo", "", "" );
01391         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *val = xmlutils::findElement( systeminfo, "SMBIOSIsDellSystem", "", "" );
01392         string strval = xmlutils::getNodeText( val );
01393         isDellExpected = strtol( strval.c_str(), 0, 0);
01394     }
01395     catch( const exception & )
01396     {
01397         throw skip_test();
01398     }
01399 
01400     CPPUNIT_ASSERT_EQUAL ( isDell, isDellExpected );
01401 
01402     STD_TEST_END()
01403 }
01404 
01405 void testSmbiosXml::testVariousAccessors()
01406 {
01407     STD_TEST_START("%s  ", getTestName().c_str() );
01408 
01409     // table should not be deleted when we are finished. It is managed by the
01410     // factory. Factory will delete it for us when ->reset() is called.
01411     smbios::ISmbiosTable *table =
01412         smbios::SmbiosFactory::getFactory()->getSingleton();
01413 
01414     smbios::ISmbiosTable::iterator item = (*table)["BIOS Information"] ;
01415 
01416     string vendorStr="";
01417     string versionStr="";
01418     string releaseStr="";
01419 
01420     if (!doc)
01421         throw skip_test();
01422 
01423     // pull info out of xml
01424     try
01425     {
01426         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *smbios = xmlutils::findElement( doc->getDocumentElement(), "smbios", "", "" );
01427         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *biosInfo = xmlutils::findElement( smbios, "biosInformation", "", "" );
01428         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *vendor = xmlutils::findElement( biosInfo, "vendor", "", "" );
01429         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *version = xmlutils::findElement( biosInfo, "version", "", "" );
01430         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *release = xmlutils::findElement( biosInfo, "release", "", "" );
01431         vendorStr = xmlutils::getNodeText( vendor );
01432         versionStr = xmlutils::getNodeText( version );
01433         releaseStr = xmlutils::getNodeText( release );
01434     }
01435     catch( const exception & )
01436     {
01437         throw skip_test();
01438     }
01439 
01440     const string string1( item->getString(4) ); // BIOS VENDOR
01441     const string string2( item->getString(5) ); // BIOS VERSION
01442     const string string3( item->getString(8) ); // RELEASE DATE
01443 
01444     const string string4( item->getStringByStringNumber(1) ); //BIOS VENDOR
01445     const string string5( item->getStringByStringNumber(2) ); //BIOS VERSION
01446     const string string6( item->getStringByStringNumber(3) ); //RELEASE DATE
01447 
01448     CPPUNIT_ASSERT_EQUAL( vendorStr, string1 );
01449     CPPUNIT_ASSERT_EQUAL( versionStr, string2 );
01450     CPPUNIT_ASSERT_EQUAL( releaseStr, string3 );
01451 
01452     CPPUNIT_ASSERT_EQUAL( string1, string4 );
01453     CPPUNIT_ASSERT_EQUAL( string2, string5 );
01454     CPPUNIT_ASSERT_EQUAL( string3, string6 );
01455 
01456     STD_TEST_END();
01457 }
01458 
01459 void
01460 testSmbiosXml::testStateBytes()
01461 {
01462     STD_TEST_START("%s  ", getTestName().c_str() );
01463 
01464     if( ! SMBIOSHasNvramStateBytes() )
01465         throw skip_test();
01466 
01467     int testValue = 0;
01468     SMBIOSGetNvramStateBytes( 0x0000 );
01469 
01470     // test DSA mode
01471     testValue = 0x1234;
01472     SMBIOSSetNvramStateBytes( testValue, 0x0000 );
01473     CPPUNIT_ASSERT_EQUAL( testValue, SMBIOSGetNvramStateBytes( 0x0000 ) ); // DSA sees real value
01474     CPPUNIT_ASSERT_EQUAL( 0x0000,    SMBIOSGetNvramStateBytes( 0x8000 ) ); // toolkit should see 0
01475     CPPUNIT_ASSERT_EQUAL( 0x0000,    SMBIOSGetNvramStateBytes( 0xF100 ) ); // other should see 0
01476 
01477     // test DSA mode (proper mask off)
01478     testValue = 0x9234; // we should not be able to set topmost bit
01479     SMBIOSSetNvramStateBytes( testValue, 0x0000 );
01480     CPPUNIT_ASSERT_EQUAL( (testValue & ~0x8000), SMBIOSGetNvramStateBytes( 0x0000 ) ); // DSA sees real value
01481     CPPUNIT_ASSERT_EQUAL( 0x0000,                SMBIOSGetNvramStateBytes( 0x8000 ) ); // toolkit should see 0
01482     CPPUNIT_ASSERT_EQUAL( 0x0000,                SMBIOSGetNvramStateBytes( 0xF100 ) ); // other should see 0
01483 
01484     // test Toolkit mode
01485     testValue = 0x0234; // we should not be able to set topmost bit
01486     SMBIOSSetNvramStateBytes( testValue, 0x8000 );
01487     CPPUNIT_ASSERT_EQUAL( testValue, SMBIOSGetNvramStateBytes( 0x8000 ) ); //toolkit sees real value
01488     CPPUNIT_ASSERT_EQUAL( 0x0000,    SMBIOSGetNvramStateBytes( 0x0000 ) ); // DSA should see 0
01489     CPPUNIT_ASSERT_EQUAL( 0x0000,    SMBIOSGetNvramStateBytes( 0xF100 ) ); // other should see 0
01490 
01491     // test Toolkit mode (proper mask off)
01492     testValue = 0x7234; // we should not be able to set topmost nibble (4 bits)
01493     SMBIOSSetNvramStateBytes( testValue, 0x8000 );
01494     CPPUNIT_ASSERT_EQUAL( (testValue & ~0xF000), SMBIOSGetNvramStateBytes( 0x8000 ) ); //toolkit sees real value
01495     CPPUNIT_ASSERT_EQUAL( 0x0000,                SMBIOSGetNvramStateBytes( 0x0000 ) ); // DSA should see 0
01496     CPPUNIT_ASSERT_EQUAL( 0x0000,                SMBIOSGetNvramStateBytes( 0xF100 ) ); // other should see 0
01497 
01498     // test other mode
01499     testValue = 0x0034; // we should not be able to set topmost byte
01500     SMBIOSSetNvramStateBytes( testValue, 0xF100 );
01501     CPPUNIT_ASSERT_EQUAL( testValue, SMBIOSGetNvramStateBytes( 0xF100 ) ); // other sees real value
01502     CPPUNIT_ASSERT_EQUAL( 0x0000,    SMBIOSGetNvramStateBytes( 0x0000 ) ); // DSA should see 0
01503     CPPUNIT_ASSERT_EQUAL( 0x0000,    SMBIOSGetNvramStateBytes( 0x8000 ) ); // DSA should see 0
01504 
01505     // test other mode (proper mask off)
01506     testValue = 0x7234; // we should not be able to set topmost byte
01507     SMBIOSSetNvramStateBytes( testValue, 0xF100 );
01508     CPPUNIT_ASSERT_EQUAL( (testValue & ~0xFF00), SMBIOSGetNvramStateBytes( 0xF100 ) ); // other sees real value
01509     CPPUNIT_ASSERT_EQUAL( 0x0000,                SMBIOSGetNvramStateBytes( 0x0000 ) ); // DSA should see 0
01510     CPPUNIT_ASSERT_EQUAL( 0x0000,                SMBIOSGetNvramStateBytes( 0x8000 ) ); // DSA should see 0
01511 
01512     STD_TEST_END();
01513 }
01514 
01515 void
01516 testSmbiosXml::testUpBoot()
01517 {
01518     STD_TEST_START("%s  ", getTestName().c_str() );
01519 
01520     if( ! SMBIOSHasBootToUp() )
01521         throw skip_test();
01522 
01523     SMBIOSSetBootToUp(1);
01524     CPPUNIT_ASSERT_EQUAL( 1, SMBIOSGetBootToUp() );
01525 
01526     SMBIOSSetBootToUp(0);
01527     CPPUNIT_ASSERT_EQUAL( 0, SMBIOSGetBootToUp() );
01528 
01529     SMBIOSSetBootToUp(1);
01530     CPPUNIT_ASSERT_EQUAL( 1, SMBIOSGetBootToUp() );
01531 
01532     SMBIOSSetBootToUp(0);
01533     CPPUNIT_ASSERT_EQUAL( 0, SMBIOSGetBootToUp() );
01534 
01535     STD_TEST_END();
01536 }
01537 
01538 
01539 void
01540 testSmbiosXml::testOutOfBounds()
01541 {
01542     STD_TEST_START("%s  ", getTestName().c_str() );
01543 
01544     smbios::ISmbiosTable *table =
01545         smbios::SmbiosFactory::getFactory()->getSingleton();
01546 
01547     smbios::ISmbiosTable::iterator item = (*table)["BIOS Information"] ;
01548 
01549     // access string '0' should always throw. (string offset start at 1, per
01550     // spec)
01551     ASSERT_THROWS( item->getStringByStringNumber(0), smbios::StringUnavailable );
01552 
01553     if (!doc)
01554         throw skip_test();
01555 
01556     int numStrings = 0;
01557     // pull info out of xml
01558     try
01559     {
01560         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *smbios = xmlutils::findElement( doc->getDocumentElement(), "smbios", "", "" );
01561         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *biosInfo = xmlutils::findElement( smbios, "biosInformation", "", "" );
01562         numStrings = strtoul( xmlutils::safeGetAttribute( biosInfo, "numstrings" ).c_str(), 0, 0 );
01563     }
01564     catch( const exception & )
01565     {
01566         throw skip_test();
01567     }
01568 
01569     // Should not throw (cast to void to eliminate unused var warn)
01570     if( numStrings > 0 )
01571         (void) (item->getStringByStringNumber(numStrings));
01572 
01573     ASSERT_THROWS( item->getStringByStringNumber(numStrings + 1), smbios::StringUnavailable );
01574     ASSERT_THROWS( item->getStringByStringNumber(numStrings + 2), smbios::StringUnavailable );
01575 
01576     STD_TEST_END()
01577 }
01578 
01579 
01580 void
01581 testSmbiosXml::testConstructionOffset()
01582 {
01583     STD_TEST_START("%s  ", getTestName().c_str() );
01584 
01585     if (!doc)
01586         throw skip_test();
01587 
01588     u32 offset = 0;
01589     // pull info out of xml
01590     try
01591     {
01592         XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *smbios = xmlutils::findElement( doc->getDocumentElement(), "smbios", "", "" );
01593         offset = strtoul( xmlutils::safeGetAttribute( smbios, "offset" ).c_str(), 0, 0 );
01594         if( 0 == offset )
01595         {
01596             throw skip_test();
01597         }
01598     }
01599     catch( const exception & )
01600     {
01601         throw skip_test();
01602     }
01603 
01604     smbios::SmbiosFactory::getFactory()->setParameter("offset", offset);
01605     smbios::ISmbiosTable *table =
01606         smbios::SmbiosFactory::getFactory()->getSingleton();
01607 
01608     int tableEntriesCounted = 0;
01609     smbios::ISmbiosTable::iterator item = table->begin();
01610     while( item != table->end() )
01611     {
01612         tableEntriesCounted++;
01613         (void) *item;  // do this to sniff out possible errors with deref iterator.
01614         ++item;
01615     }
01616 
01617     CPPUNIT_ASSERT( tableEntriesCounted == table->getNumberOfEntries() );
01618 
01619     //
01620     // TEST BAD FILENAMES
01621     // construct our table with various invalid file names
01622     //
01623     smbios::SmbiosFactory *factory = smbios::SmbiosFactory::getFactory();
01624     //memory::MemoryFactory *memfactory = memory::MemoryFactory::getFactory();
01625 
01626     //memfactory->setParameter("memFile", "");
01627     //ASSERT_THROWS( auto_ptr<smbios::ISmbiosTable>p(factory->makeNew()), smbios::Exception );
01628 
01629     // Not portable to Windows.
01630     //factory->setParameter("memFile", "/dev/null");
01631     //ASSERT_THROWS( auto_ptr<smbios::ISmbiosTable>p(factory->makeNew()), smbios::ParseException );
01632 
01633     // Not portable to Windows.
01634     //factory->setParameter("memFile", "/dev/zero");
01635     //ASSERT_THROWS( auto_ptr<smbios::ISmbiosTable>p(factory->makeNew()), smbios::ParseException );
01636 
01637     factory->reset();
01638 
01639     //
01640     // TEST BAD OFFSETS
01641     //
01642     // This is now a NON-XML factory.
01643     // This call nails the _instance variable to a regular non-xml factory
01644     // instance. Subsequent setup calls in setUp ensure it is properly set
01645     // with the correct paths and whatnot.
01646     tearDown();
01647     factory = smbios::SmbiosFactory::getFactory();
01648     setUp();
01649 
01650     // Ok, none of these are related to construction offset, but it is good to
01651     // run these tests while we have a handy reference to a NON-XML factory.
01652     auto_ptr<smbios::ISmbiosTable>p(factory->makeNew());
01653     auto_ptr<const smbios::ISmbiosTable>q(factory->makeNew());
01654     ASSERT_THROWS( (*p)["BIOS Information"], smbios::NotImplemented );
01655     ASSERT_THROWS( (*q)["BIOS Information"], smbios::NotImplemented );
01656 
01657     smbios::ISmbiosTable::iterator item1 = (*p)[smbios::BIOS_Information];
01658     smbios::ISmbiosTable::const_iterator item2 = (*q)[smbios::BIOS_Information];
01659 
01660     // test streamify() for non-XML SmbiosItem class while we are here.
01661     ostringstream ost;
01662     ost << *item1 << endl;
01663 
01664     CPPUNIT_ASSERT_EQUAL( item1->getHandle(), item2->getHandle() );
01665     CPPUNIT_ASSERT_EQUAL( item1->getHandle(), item2->getU16(2) );
01666     CPPUNIT_ASSERT_EQUAL( item1->getLength(), item2->getLength() );
01667     CPPUNIT_ASSERT_EQUAL( item1->getLength(), item2->getU8(1) );
01668     CPPUNIT_ASSERT_EQUAL( item1->getType()  , item2->getType()   );
01669     CPPUNIT_ASSERT_EQUAL( item1->getType()  , item2->getU8(0)   );
01670 
01671     ASSERT_THROWS( item1->getU8("BIOS Version"), smbios::NotImplemented);
01672     ASSERT_THROWS( item1->getU16("BIOS Version"), smbios::NotImplemented);
01673     ASSERT_THROWS( item1->getU32("BIOS Version"), smbios::NotImplemented);
01674     ASSERT_THROWS( item1->getU64("BIOS Version"), smbios::NotImplemented);
01675     ASSERT_THROWS( item1->getString("BIOS Version"), smbios::NotImplemented);
01676     ASSERT_THROWS( item1->getBitfield("BIOS Version", "test bitfield"), smbios::NotImplemented);
01677     // End unrelated tests.
01678 
01679     // use auto_ptr so in case it does _not_ throw, we don't leak mem in the test.
01680     //  DO NOT USE ->getSingleton() here... we use ->makeNew() on purpose.
01681     //  This is an internal test and the parameters of this test mean we should _not_ use a singleton.
01682     factory->setParameter("offset", 1);
01683     ASSERT_THROWS( auto_ptr<smbios::ISmbiosTable>p(factory->makeNew()), smbios::IException );
01684 
01685     factory->setParameter("offset", 1000);
01686     ASSERT_THROWS( auto_ptr<smbios::ISmbiosTable>p(factory->makeNew()), smbios::IException );
01687 
01688     factory->setParameter("offset", 0xFFFFFUL ); // F_BLOCK_END (private definition)
01689     ASSERT_THROWS( auto_ptr<smbios::ISmbiosTable>p(factory->makeNew()), smbios::IException );
01690 
01691     factory->setParameter("offset", 0xFFFFFUL - 1); // F_BLOCK_END (private definition)
01692     ASSERT_THROWS( auto_ptr<smbios::ISmbiosTable>p(factory->makeNew()), smbios::IException );
01693 
01694     smbios::SmbiosFactory::getFactory()->setParameter("offset", offset + 1);
01695     ASSERT_THROWS( auto_ptr<smbios::ISmbiosTable> table( factory->makeNew() ), smbios::IException );
01696 
01697     smbios::SmbiosFactory::getFactory()->setParameter("offset", offset - 1);
01698     ASSERT_THROWS( auto_ptr<smbios::ISmbiosTable> table( factory->makeNew() ), smbios::IException );
01699 
01700     // should not be able to use no-argument constructor...
01701     // UNCOMMENT TO CHECK.
01702     // THIS TEST DOES NOT COMPILE. IT SHOULD NOT COMPILE
01703     // DUE TO THE DEFINITION OF SmbiosTable.
01704     //ASSERT_THROWS( smbios::SmbiosTableFileIo myTable1, smbios::PermissionException);
01705 
01706     STD_TEST_END()
01707 }
01708 
01709 
01710 void
01711 testSmbiosXml::testException()
01712 {
01713     STD_TEST_START("%s  ", getTestName().c_str() );
01714     std::string actual = "";
01715     smbios::Exception<smbios::IException> foo;
01716     string source = "";
01717     string expected = "";
01718     foo.setParameter("foo", "happy");
01719     foo.setParameter("bar", 42);
01720     foo.setParameter("recursive", "%(foo)s");
01721     foo.setParameter("recursiverecursive", "%(recursive)s");
01722 
01723     source = "The %% cat is %(foo)s. The best number is %(bar)i. %";
01724     expected = "The % cat is happy. The best number is 42. %";
01725     foo.setMessageString( source );
01726     actual = foo.what();
01727     CPPUNIT_ASSERT_EQUAL( expected, actual );
01728 
01729     // test copy constructor
01730     smbios::Exception<smbios::IException> bar = foo;
01731     actual = bar.what();
01732     CPPUNIT_ASSERT_EQUAL( expected, actual );
01733 
01734     source = "The %% cat is %(recursive)s. The best number is %(bar)i. %";
01735     foo.setMessageString( source );
01736     actual = foo.what();
01737     CPPUNIT_ASSERT_EQUAL( expected, actual );
01738 
01739     source = "The %% cat is %(recursiverecursive)s. The best number is %(bar)i. %";
01740     foo.setMessageString( source );
01741     actual = foo.what();
01742     CPPUNIT_ASSERT_EQUAL( expected, actual );
01743 
01744     source = "The %% cat %is %(recursiverecursive)s. The best number is %(bar)i. %";
01745     expected = "The % cat %is happy. The best number is 42. %";
01746     foo.setMessageString( source );
01747     actual = foo.what();
01748     CPPUNIT_ASSERT_EQUAL( expected, actual );
01749 
01750     source = " %(a_really_long_variable_longer_than_32_characters)s";
01751     expected = " %(a_really_long_variable_longer_than_32_characters)s";
01752     foo.setMessageString( source );
01753     actual = foo.what();
01754     CPPUNIT_ASSERT_EQUAL( expected, actual );
01755 
01756     source = " %(no_closing_paren";
01757     expected = " %(no_closing_paren";
01758     foo.setMessageString( source );
01759     actual = foo.what();
01760     CPPUNIT_ASSERT_EQUAL( expected, actual );
01761 
01762     source = " %(a_var_with_no_type)";
01763     expected = " %(a_var_with_no_type)";
01764     foo.setMessageString( source );
01765     actual = foo.what();
01766     CPPUNIT_ASSERT_EQUAL( expected, actual );
01767 
01768     source = " %(a_var_with_no_type)  ";
01769     expected = " %(a_var_with_no_type)  ";
01770     foo.setMessageString( source );
01771     actual = foo.what();
01772     CPPUNIT_ASSERT_EQUAL( expected, actual );
01773 
01774     source = " %";
01775     expected = " %";
01776     foo.setMessageString( source );
01777     actual = foo.what();
01778     CPPUNIT_ASSERT_EQUAL( expected, actual );
01779 
01780     STD_TEST_END()
01781 }
01782 

Generated on Tue Jul 11 20:46:46 2006 for SMBIOS Library by  doxygen 1.4.7