testStandalone.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 // compat header should always be first header if including system headers
00020 #include "smbios/compat.h"
00021 
00022 #include <iomanip>
00023 #include <fstream>
00024 
00025 #include "testStandalone.h"
00026 #include "smbios/SmbiosDefs.h"
00027 
00028 // specific to unit tests. Users do not need to include this,
00029 // so it is not in testStandalone.h
00030 #include "smbios/IMemory.h"
00031 #include "smbios/ISmi.h"
00032 #include "smbios/IObserver.h"
00033 
00034 #include "smbios/version.h"
00035 
00036 using namespace std;
00037 
00038 // Note:
00039 //      Except for , there are no "using namespace XXXX;" statements
00040 //      here... on purpose. We want to ensure that while reading this code that
00041 //      it is extremely obvious where each function is coming from.
00042 //
00043 //      This leads to verbose code in some instances, but that is fine for
00044 //      these purposes.
00045 
00046 // Register the test
00047 CPPUNIT_TEST_SUITE_REGISTRATION (testStandalone);
00048 
00049 void copyFile( string dstFile, string srcFile )
00050 {
00051     ifstream src(srcFile.c_str(), ios_base::binary);
00052     ofstream dst(dstFile.c_str(), ios_base::out | ios_base::binary | ios_base::trunc);
00053 
00054     char ch;
00055     while( src.get(ch)) dst.put(ch);
00056 
00057     if( !src.eof() || !dst ) throw exception();
00058 }
00059 
00060 bool fileExists(string fileName)
00061 {
00062     FILE *fh=0;
00063     fh=fopen(fileName.c_str(), "rb");
00064     if(!fh)
00065         return false;
00066 
00067     fclose(fh);
00068     return true;
00069 }
00070 
00071 void testStandalone::setUp()
00072 {
00073     string programDirname = getCppunitTopDirectory();
00074     string writeDirectory = getWritableDirectory();
00075 
00076     // copy the memdump.dat file. We do not write to it, but rw open will fail
00077     // if we do not copy it
00078     string memdumpOrigFile = programDirname + getTestDirectory() + "/memdump.dat";
00079     if(!fileExists(memdumpOrigFile))
00080         memdumpOrigFile = getTestDirectory() + "/memdump.dat";
00081     string memdumpCopyFile = writeDirectory + "/memdump-copy.dat";
00082     copyFile( memdumpCopyFile, memdumpOrigFile );
00083 
00084     // copy the CMOS file. We are going to write to it and do not wan to mess up
00085     // the pristine unit test version
00086     string cmosOrigFile = programDirname + getTestDirectory() + "/cmos.dat";
00087     if(!fileExists(cmosOrigFile))
00088         cmosOrigFile = getTestDirectory() + "/cmos.dat";
00089     string cmosCopyFile = writeDirectory + "/cmos-copy.dat";
00090     copyFile( cmosCopyFile, cmosOrigFile );
00091 
00092     // Smi output file.
00093     string smiOutput = writeDirectory + "/smi-output.dat";
00094 
00095     // normal users of the smbios classes need not
00096     // set the four parameters below. They should all be set inside the factory
00097     // properly by default. We override stuff here to have
00098     // the smbios, cmos, etc classes use file dumps instead of
00099     // real memory/cmos/etc.
00100     smbios::SmbiosFactory::getFactory()->setParameter("memFile", memdumpCopyFile);
00101     smbios::SmbiosFactory::getFactory()->setParameter("offset", 0);
00102     smbios::SmbiosFactory::getFactory()->setMode(smbios::SmbiosFactory::UnitTestMode);
00103 
00104     cmos::  CmosRWFactory::getFactory()->setParameter("cmosMapFile", cmosCopyFile);
00105     cmos::  CmosRWFactory::getFactory()->setMode( factory::IFactory::UnitTestMode );
00106 
00107     memory::MemoryFactory::getFactory()->setParameter("memFile", memdumpCopyFile);
00108     memory::MemoryFactory::getFactory()->setMode( memory::MemoryFactory::UnitTestMode );
00109 
00110     smi::SmiFactory::getFactory()->setParameter("smiFile", smiOutput);
00111     smi::SmiFactory::getFactory()->setMode( smi::SmiFactory::UnitTestMode );
00112 }
00113 
00114 void testStandalone::tearDown()
00115 {
00116     // the factory is static. If we do not reset the factory, the next
00117     // unit test may accidentally get the wrong objects.
00118     // Lifetime rules: CmosTokenTable cannot live longer than the ISmbiosTable
00119     // object used in its construction.
00120     smbios::TokenTableFactory::getFactory()->reset();
00121 
00122     smbios::SmbiosFactory::getFactory()->reset();
00123 
00124     memory::MemoryFactory::getFactory()->reset();
00125 
00126     cmos::CmosRWFactory::getFactory()->reset();
00127 
00128     smi::SmiFactory::getFactory()->reset();
00129 }
00130 
00131 //
00132 //
00133 // TABLE tests
00134 //
00135 //
00136 
00137 void testStandalone::testSmbiosTableBase()
00138 {}
00139 
00140 void testStandalone::testSmbiosTableBase_iterNextItem()
00141 {}
00142 
00143 void testStandalone::testSmbiosTableBase_findItemByHandle()
00144 {}
00145 
00146 void testStandalone::testSmbiosTableBase_findItemByType()
00147 {}
00148 
00149 
00150 void testStandalone::testTable_Subscript()
00151 {
00152     STD_TEST_START(getTestName().c_str() << "  " );
00153     // PURPOSE:
00154     //      The purpose of this test is to test the subscript operator [].
00155     //      It tests these operators using string and int args and tests
00156     //      it outside of a loop.
00157 
00158     // table should not be deleted when we are finished. It is managed by the
00159     // factory. Factory will delete it for us when ->reset() is called.
00160     smbios::ISmbiosTable *table =
00161         smbios::SmbiosFactory::getFactory()->getSingleton();
00162 
00163     smbios::ISmbiosTable::iterator item1;
00164     smbios::ISmbiosTable::const_iterator item2;
00165 
00166     item1 = (*table)[smbios::BIOS_Information];
00167     item2 = (*table)[smbios::BIOS_Information];
00168 
00169     // Use CPPUNIT_ASSERT_EQUAL when testing equality.
00170     // It gives better diagnostics on failure.
00171     CPPUNIT_ASSERT_EQUAL( item1->getHandle(),    item2->getHandle() );
00172     CPPUNIT_ASSERT_EQUAL( getItemHandle(*item1), item2->getHandle() );
00173     CPPUNIT_ASSERT_EQUAL( item1->getLength(),    item2->getLength() );
00174     CPPUNIT_ASSERT_EQUAL( getItemLength(*item1), item2->getLength() );
00175     CPPUNIT_ASSERT_EQUAL( item1->getType()  ,    item2->getType()   );
00176     CPPUNIT_ASSERT_EQUAL( getItemType(*item1)  , item2->getType()   );
00177 
00178     CPPUNIT_ASSERT_EQUAL( (*table)[smbios::BIOS_Information]->getType(), item1->getType() );
00179 
00180     item1 = (*table)[smbios::System_Information];
00181     item2 = (*table)[smbios::System_Information];
00182 
00183     CPPUNIT_ASSERT_EQUAL( item1->getHandle(),    item2->getHandle() );
00184     CPPUNIT_ASSERT_EQUAL( getItemHandle(*item1), item2->getHandle() );
00185     CPPUNIT_ASSERT_EQUAL( item1->getLength(),    item2->getLength() );
00186     CPPUNIT_ASSERT_EQUAL( getItemLength(*item1), item2->getLength() );
00187     CPPUNIT_ASSERT_EQUAL( item1->getType(),      item2->getType()   );
00188     CPPUNIT_ASSERT_EQUAL( getItemType(*item1)  , item2->getType()   );
00189 
00190     CPPUNIT_ASSERT_EQUAL( (*table)[smbios::System_Information]->getType(), item1->getType() );
00191 
00192 
00193     STD_TEST_END("");
00194 }
00195 
00196 void
00197 testStandalone::testEntryCount ()
00198 {
00199     STD_TEST_START(getTestName().c_str() << "  " );
00200 
00201     // do not delete. Factory manages lifetime.
00202     smbios::ISmbiosTable *table =
00203         smbios::SmbiosFactory::getFactory()->getSingleton();
00204 
00205     // test streamify() while we are at it.
00206     ostringstream ost;
00207     int tableEntriesCounted = 0;
00208     smbios::ISmbiosTable::iterator item = table->begin();
00209     while( item != table->end() )
00210     {
00211         tableEntriesCounted++;
00212         ost << *item << endl;
00213         ++item;
00214     }
00215 
00216     CPPUNIT_ASSERT_EQUAL( tableEntriesCounted, table->getNumberOfEntries() );
00217     STD_TEST_END("");
00218 }
00219 
00220 void
00221 testStandalone::testConstIterator ()
00222 {
00223     STD_TEST_START(getTestName().c_str() << "  " );
00224 
00225     // do not delete. Factory manages lifetime.
00226     const smbios::ISmbiosTable *table =
00227         smbios::SmbiosFactory::getFactory()->getSingleton();
00228 
00229     const smbios::ISmbiosTable *constTable = &*table;
00230 
00231     int tableEntriesCounted = 0;
00232     smbios::ISmbiosTable::const_iterator item = constTable->begin();
00233     while( item != constTable->end() )
00234     {
00235         tableEntriesCounted++;
00236         (void) *item;  // do this to sniff out possible errors with deref iterator.
00237 
00238         ++item;
00239     }
00240     CPPUNIT_ASSERT_EQUAL( tableEntriesCounted, constTable->getNumberOfEntries() );
00241     STD_TEST_END("");
00242 }
00243 
00244 void
00245 testStandalone::testSubscriptOperator1 ()
00246 {
00247     STD_TEST_START(getTestName().c_str() << "  " );
00248 
00249     // do not delete. Factory manages lifetime.
00250     const smbios::ISmbiosTable *table =
00251         smbios::SmbiosFactory::getFactory()->getSingleton();
00252 
00253     int tableEntriesCounted = 0;
00254     // table[-1] is special, it returns all objects.
00255     // This test should be identical to testConstIterator (both walk all entries)
00256     for( smbios::ISmbiosTable::const_iterator item = (*table)[-1] ; item != table->end(); ++item)
00257     {
00258         tableEntriesCounted++;
00259         (void) *item;  // do this to sniff out possible errors with deref iterator.
00260     }
00261     CPPUNIT_ASSERT_EQUAL( table->getNumberOfEntries(), tableEntriesCounted );
00262     STD_TEST_END("");
00263 }
00264 
00265 void
00266 testStandalone::testSubscriptOperator2 ()
00267 {
00268     STD_TEST_START(getTestName().c_str() << "  " );
00269 
00270 // it turns out that 8450 has 3 BIOS Information blocks.
00271 
00272 //    // do not delete. Factory manages lifetime.
00273 //    smbios::ISmbiosTable *table =
00274 //        smbios::SmbiosFactory::getFactory()->getSingleton();
00275 //
00276 //    // There should probably be only one "BIOS Information" block. Check.
00277 //    //  update this test if it turns out that there are actual systems with >1 Bios Info block
00278 //    //
00279 //    int tableEntriesCounted = 0;
00280 //    for( smbios::ISmbiosTable::iterator item = (*table)[0] ; item != table->end(); ++item)
00281 //    {
00282 //        (void) *item;  // do this to sniff out possible errors with deref iterator.
00283 //        tableEntriesCounted++;
00284 //    }
00285 //    CPPUNIT_ASSERT_EQUAL( 1, tableEntriesCounted );
00286 
00287     STD_TEST_END("");
00288 }
00289 
00290 void
00291 testStandalone::testSubscriptOperator3 ()
00292 {
00293     STD_TEST_START(getTestName().c_str() << "  " );
00294 
00295     // do not delete. Factory manages lifetime.
00296     const smbios::ISmbiosTable *table =
00297         smbios::SmbiosFactory::getFactory()->getSingleton();
00298 
00299     // There should normally be more than one "Port Connector" block. Check.
00300     //                               "Port Connector" block is type == 8
00301     //   memdump-opti.txt     has 12
00302     //   memdump-PAweb110.txt has 17
00303     //   memdump-PAweb110.txt has 9  *unverified...
00304     //  update this test if it turns out that there are actual systems with <2 Port Connector blocks
00305     //
00306     int tableEntriesCounted = 0;
00307     for( smbios::ISmbiosTable::const_iterator item = (*table)[8] ; item != table->end(); ++item)
00308     {
00309         (void) *item;  // do this to sniff out possible errors with deref iterator.
00310         tableEntriesCounted++;
00311     }
00312     CPPUNIT_ASSERT( 1 < tableEntriesCounted );
00313     STD_TEST_END("");
00314 }
00315 
00316 
00317 
00318 //
00319 //
00320 // ITEM tests
00321 //
00322 //
00323 
00324 void testStandalone::testStreamify()
00325 {
00326     STD_TEST_START(getTestName().c_str() << "  " );
00327 
00328     // BEGIN EXAMPLE iterator
00329     // table should not be deleted when we are finished. It is managed by the
00330     // factory. Factory will delete it for us when ->reset() is called.
00331     smbios::ISmbiosTable *table =
00332         smbios::SmbiosFactory::getFactory()->getSingleton();
00333 
00334     ostringstream ost;
00335     ost << *table << endl;
00336 
00337     // iterate over all PORT INFORMATION BLOCKS
00338     for( smbios::ISmbiosTable::iterator item = (*table)[8] ; item != table->end(); ++item)
00339     {
00340         ost << *item << endl;
00341     }
00342     // END EXAMPLE iterator
00343 
00344     STD_TEST_END("");
00345 }
00346 
00347 void
00348 testStandalone::testItemIdentity ()
00349 {
00350     STD_TEST_START(getTestName().c_str() << "  " );
00351     // test that when we grab things out of the
00352     // table, we get copies of the same thing
00353     // when we ask for the same thing, rather than
00354     // separate items with the same data.
00355     //
00356     // we use references below to make the CPPUNIT_ASSERT
00357     // a bit easier to read.
00358 
00359     // do not delete. Factory manages lifetime.
00360     const smbios::ISmbiosTable *table =
00361         smbios::SmbiosFactory::getFactory()->getSingleton();
00362 
00363     // grab the first bios block
00364     smbios::ISmbiosTable::const_iterator position1 = (*table)[smbios::BIOS_Information];
00365     const smbios::ISmbiosItem &item1 = *position1; //reference
00366 
00367     // use another iterator and grab another
00368     smbios::ISmbiosTable::const_iterator position2 = (*table)[smbios::BIOS_Information];
00369     const smbios::ISmbiosItem &item2 = *position2; //reference
00370 
00371     // Check that they both gave the same thing
00372     // The address of each should be equal
00373     CPPUNIT_ASSERT_EQUAL(  &item1, &item2 );  // easiest to read
00374     CPPUNIT_ASSERT_EQUAL(  &(*position1), &item2 ); // same test, written differently
00375     CPPUNIT_ASSERT_EQUAL(  &item1       , &(*position2) ); // same test, written differently
00376     CPPUNIT_ASSERT_EQUAL(  &(*position1), &(*position2) ); // same test, written differently
00377 
00378     // use another iterator and grab another _different_ pointer.
00379     smbios::ISmbiosTable::const_iterator position3 = (*table)[smbios::System_Information];
00380     const smbios::ISmbiosItem &item3 = *position3; //reference
00381 
00382     // Check that these are different...
00383     CPPUNIT_ASSERT( &item1 != &item3 );
00384     CPPUNIT_ASSERT( &item2 != &item3 );
00385 
00386     CPPUNIT_ASSERT_EQUAL( item1.getType(), static_cast<u8>(smbios::BIOS_Information) );
00387     CPPUNIT_ASSERT_EQUAL( item2.getType(), static_cast<u8>(smbios::BIOS_Information) );
00388     CPPUNIT_ASSERT_EQUAL( item3.getType(), static_cast<u8>(smbios::System_Information) );
00389 
00390     STD_TEST_END("");
00391 }
00392 
00393 void
00394 testStandalone::testEachItemAccessors ()
00395 {
00396     STD_TEST_START(getTestName().c_str() << "  " );
00397     // test getU{8|16}_FromItem() functions
00398     // no way to test in generic table the getU32
00399     // or getU64
00400     //
00401     // primarily to ensure that getUx_FromItem() has the endianness correct
00402 
00403     // do not delete. Factory manages lifetime.
00404     const smbios::ISmbiosTable *table =
00405         smbios::SmbiosFactory::getFactory()->getSingleton();
00406 
00407     smbios::ISmbiosTable::const_iterator item = table->begin();
00408     while( item != table->end() )
00409     {
00410         u8 type1 = item->getType();
00411         u8 type2 = getU8_FromItem(*item, 0);
00412         CPPUNIT_ASSERT_EQUAL( type1, type2 );
00413 
00414         u8 len1 = item->getLength();
00415         u8 len2 = getU8_FromItem(*item, 1);
00416         CPPUNIT_ASSERT_EQUAL( len1, len2 );
00417 
00418         u16 handle1 = item->getHandle();
00419         u16 handle2 = getU16_FromItem(*item, 2);
00420         CPPUNIT_ASSERT_EQUAL( handle1, handle2 );
00421 
00422         ++item;
00423     }
00424 
00425     STD_TEST_END("");
00426 }
00427 
00428 void testStandalone::testNonXml()
00429 {
00430     STD_TEST_START(getTestName().c_str() << "  " );
00431 
00432     smbios::SmbiosFactory *factory = smbios::SmbiosFactory::getFactory();
00433     factory->reset();
00434 
00435     //
00436     // This is now a NON-XML factory.
00437     // This call nails the _instance variable to a regular non-xml factory
00438     // instance. Subsequent setup calls in setUp ensure it is properly set
00439     // with the correct paths and whatnot.
00440     tearDown();
00441     factory = smbios::SmbiosFactory::getFactory();
00442     setUp();
00443 
00444     // Ok, none of these are related to construction offset, but it is good to
00445     // run these tests while we have a handy reference to a NON-XML factory.
00446     auto_ptr<smbios::ISmbiosTable>p(factory->makeNew());
00447     auto_ptr<const smbios::ISmbiosTable>q(factory->makeNew());
00448 
00449     smbios::ISmbiosTable::iterator item1 = (*p)[smbios::BIOS_Information];
00450     smbios::ISmbiosTable::const_iterator item2 = (*q)[smbios::BIOS_Information];
00451 
00452     // test streamify() for non-XML SmbiosItem class while we are here.
00453     ostringstream ost;
00454     ost << *item1 << endl;
00455 
00456     CPPUNIT_ASSERT_EQUAL( item1->getHandle(), item2->getHandle() );
00457     CPPUNIT_ASSERT_EQUAL( item1->getHandle(), getU16_FromItem(*item2, 2) );
00458     CPPUNIT_ASSERT_EQUAL( item1->getLength(), item2->getLength() );
00459     CPPUNIT_ASSERT_EQUAL( item1->getLength(), getU8_FromItem(*item2, 1) );
00460     CPPUNIT_ASSERT_EQUAL( item1->getType()  , item2->getType()   );
00461     CPPUNIT_ASSERT_EQUAL( item1->getType()  , getU8_FromItem(*item2, 0)   );
00462 
00463     STD_TEST_END("");
00464 }
00465 
00466 void testStandalone::testSmbiosXml()
00467 {
00468     STD_TEST_START(getTestName().c_str() << "  " );
00469     // do not delete. Factory manages lifetime.
00470     const smbios::ISmbiosTable *table =
00471             smbios::SmbiosFactory::getFactory()->getSingleton();
00472     
00473     // test if "PCI Supported" bit is set, should always be set.
00474     smbios::ISmbiosTable::const_iterator item = (*table)[smbios::BIOS_Information];
00475     CPPUNIT_ASSERT_EQUAL( isBitSet( &(*item), 0xA,  0x7 ), true );
00476     
00477     STD_TEST_END("");
00478 }
00479 
00480 
00481 
00482 void
00483 testStandalone::testGetBoundaries()
00484 {
00485     STD_TEST_START(getTestName().c_str() << "  " );
00486 
00487     // do not delete. Factory manages lifetime.
00488     const smbios::ISmbiosTable *table =
00489         smbios::SmbiosFactory::getFactory()->getSingleton();
00490 
00491     for( smbios::ISmbiosTable::const_iterator item = (*table)[-1] ; item != table->end(); ++item)
00492     {
00493         int len = item->getLength();
00494 
00495         // none of these should throw.
00496         (void) getU8_FromItem (*item, len - 1);
00497         (void) getU16_FromItem(*item, len - 2);
00498         (void) getU32_FromItem(*item, len - 4);
00499 
00500         // not all items are large enough. only attempt if item is at least 8 bytes
00501         if( len >= 8 )
00502             (void) getU64_FromItem(*item, len - 8);
00503 
00504         ASSERT_THROWS( getU8_FromItem (*item, len - 0), smbios::DataOutOfBounds);
00505         ASSERT_THROWS( getU16_FromItem(*item, len - 1), smbios::DataOutOfBounds);
00506         ASSERT_THROWS( getU32_FromItem(*item, len - 3), smbios::DataOutOfBounds);
00507         ASSERT_THROWS( getU64_FromItem(*item, len - 7), smbios::DataOutOfBounds);
00508     }
00509 
00510     STD_TEST_END("");
00511 }
00512 
00513 
00514 
00515 //
00516 // Memory tests
00517 //
00518 void
00519 testStandalone::testMemoryBadFiles ()
00520 {
00521     STD_TEST_START(getTestName().c_str() << "  " );
00522 
00523     memory::MemoryFactory *memFact = memory::MemoryFactory::getFactory();
00524 
00525     memFact->setParameter("memFile", "");
00526     ASSERT_THROWS( memFact->makeNew() , memory::AccessError);
00527 
00528     memFact->setParameter("memFile", "nonexistentfile");
00529     ASSERT_THROWS( memFact->makeNew() , memory::AccessError);
00530 
00531     memory::MemoryFactory::getFactory()->setMode( 2 );
00532     ASSERT_THROWS( memFact->makeNew(), smbios::NotImplemented);
00533 
00534     memory::MemoryFactory::getFactory()->setMode( memory::MemoryFactory::UnitTestMode );
00535 
00536     STD_TEST_END("");
00537 }
00538 
00539 void
00540 testStandalone::testMemoryFuncs ()
00541 {
00542     STD_TEST_START(getTestName().c_str() << "  " );
00543 
00544     memory::MemoryFactory *memFact = memory::MemoryFactory::getFactory();
00545 
00546     memory::IMemory *mem =  memFact->getSingleton();
00547 
00548     mem->getByte( 0 );
00549 
00550     ASSERT_THROWS( mem->getByte( 0x10000000UL ), memory::AccessError);
00551 
00552     mem->putByte( 0, 254 );
00553     int b = mem->getByte( 0 );
00554 
00555     CPPUNIT_ASSERT_EQUAL ( b, 254 );
00556     STD_TEST_END("");
00557 }
00558 
00559 
00560 
00561 
00562 //
00563 // CMOS Token
00564 //
00565 
00566 
00567 void
00568 testStandalone::testCmosConstructor ()
00569 {
00570     STD_TEST_START(getTestName().c_str() << "  " );
00571 
00572     smbios::TokenTableFactory *ttFactory;
00573     ttFactory = smbios::TokenTableFactory::getFactory() ;
00574     smbios::ITokenTable *tokenTable = ttFactory->getSingleton();
00575 
00576     ostringstream ost;
00577 
00578     smbios::ITokenTable::iterator token = tokenTable->begin();
00579     while( token != tokenTable->end() )
00580     {
00581         ost << *token << endl;
00582         ++token;
00583     }
00584 
00585     STD_TEST_END("");
00586 }
00587 
00588 
00589 //
00590 // SMI Tests
00591 //
00592 
00593 void
00594 testStandalone::testSmi_callingInterface()
00595 {
00596     STD_TEST_START(getTestName().c_str() << "  " );
00597 
00598     std::auto_ptr<smi::IDellCallingInterfaceSmi> smi = smi::SmiFactory::getFactory()->makeNew(smi::SmiFactory::DELL_CALLING_INTERFACE_SMI);
00599 
00600     smi->setClass( 0xAABB );
00601     smi->setSelect( 0xCCDD );
00602     smi->setArg( 0, 0xA1A2A3A4 );
00603     smi->setArg( 1, 0xB1B2B3B4 );
00604     smi->setArg( 2, 0xC1C2C3C4 );
00605     smi->setArg( 3, 0xD1D2D3D4 );
00606     try
00607     {   /* This is expected to fail in unit test, no good way to simulate them*/
00608         smi->execute();
00609     }
00610     catch( const smi::UnhandledSmi & ) {}
00611 
00612     STD_TEST_END("");
00613 }
00614 
00615 void
00616 testStandalone::testSmi_callingInterface_physaddr ()
00617 {
00618     STD_TEST_START(getTestName().c_str() << "  " );
00619 
00620     std::auto_ptr<smi::IDellCallingInterfaceSmi> smi = smi::SmiFactory::getFactory()->makeNew(smi::SmiFactory::DELL_CALLING_INTERFACE_SMI);
00621     smi->setClass( 0xAABB );
00622     smi->setSelect( 0xCCDD );
00623     smi->setArgAsPhysicalAddress(0, 0);
00624     smi->setArgAsPhysicalAddress(1, 1);
00625     smi->setArgAsPhysicalAddress(2, 2);
00626     smi->setArgAsPhysicalAddress(3, 3);
00627     try
00628     {   /* This is expected to fail in unit test, no good way to simulate them*/
00629         smi->execute();
00630     }
00631     catch( const smi::UnhandledSmi & ) {}
00632 
00633     STD_TEST_END("");
00634 }
00635 
00636 
00637 
00638 string safeConvertToString( const char *str )
00639 {
00640     string fromSystem = "";
00641     if( 0 != str )
00642     {
00643         fromSystem = str;
00644     }
00645     SMBIOSFreeMemory(str);
00646     return fromSystem;
00647 }
00648 
00649 void
00650 testStandalone::testLibraryVersion()
00651 {
00652     STD_TEST_START(getTestName().c_str() << "  " );
00653 
00654     string fromSystem = SMBIOSGetLibraryVersionString();
00655     string testInput  = LIBSMBIOS_RELEASE_VERSION;
00656 
00657     CPPUNIT_ASSERT_EQUAL ( testInput, fromSystem );
00658     STD_TEST_END("");
00659 }
00660 
00661 void
00662 testStandalone::testException()
00663 {
00664     STD_TEST_START(getTestName().c_str() << "  " );
00665     std::string actual = "";
00666     smbios::Exception<smbios::IException> foo;
00667     string source = "";
00668     string expected = "";
00669     foo.setParameter("foo", "happy");
00670     foo.setParameter("bar", 42);
00671     foo.setParameter("recursive", "%(foo)s");
00672     foo.setParameter("recursiverecursive", "%(recursive)s");
00673 
00674     source = "The %% cat is %(foo)s. The best number is %(bar)i. %";
00675     expected = "The % cat is happy. The best number is 42. %";
00676     foo.setMessageString( source );
00677     actual = foo.what();
00678     CPPUNIT_ASSERT_EQUAL( expected, actual );
00679 
00680     // test copy constructor
00681     smbios::Exception<smbios::IException> bar = foo;
00682     actual = bar.what();
00683     CPPUNIT_ASSERT_EQUAL( expected, actual );
00684 
00685     source = "The %% cat is %(recursive)s. The best number is %(bar)i. %";
00686     foo.setMessageString( source );
00687     actual = foo.what();
00688     CPPUNIT_ASSERT_EQUAL( expected, actual );
00689 
00690     source = "The %% cat is %(recursiverecursive)s. The best number is %(bar)i. %";
00691     foo.setMessageString( source );
00692     actual = foo.what();
00693     CPPUNIT_ASSERT_EQUAL( expected, actual );
00694 
00695     source = "The %% cat %is %(recursiverecursive)s. The best number is %(bar)i. %";
00696     expected = "The % cat %is happy. The best number is 42. %";
00697     foo.setMessageString( source );
00698     actual = foo.what();
00699     CPPUNIT_ASSERT_EQUAL( expected, actual );
00700 
00701     source = " %(a_really_long_variable_longer_than_32_characters)s";
00702     expected = " %(a_really_long_variable_longer_than_32_characters)s";
00703     foo.setMessageString( source );
00704     actual = foo.what();
00705     CPPUNIT_ASSERT_EQUAL( expected, actual );
00706 
00707     source = " %(no_closing_paren";
00708     expected = " %(no_closing_paren";
00709     foo.setMessageString( source );
00710     actual = foo.what();
00711     CPPUNIT_ASSERT_EQUAL( expected, actual );
00712 
00713     source = " %(a_var_with_no_type)";
00714     expected = " %(a_var_with_no_type)";
00715     foo.setMessageString( source );
00716     actual = foo.what();
00717     CPPUNIT_ASSERT_EQUAL( expected, actual );
00718 
00719     source = " %(a_var_with_no_type)  ";
00720     expected = " %(a_var_with_no_type)  ";
00721     foo.setMessageString( source );
00722     actual = foo.what();
00723     CPPUNIT_ASSERT_EQUAL( expected, actual );
00724 
00725     source = " %";
00726     expected = " %";
00727     foo.setMessageString( source );
00728     actual = foo.what();
00729     CPPUNIT_ASSERT_EQUAL( expected, actual );
00730 
00731     STD_TEST_END("");
00732 }
00733 

Generated on Wed Apr 2 16:37:32 2008 for SMBIOS Library by  doxygen 1.5.1