00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define LIBSMBIOS_NEED_SMBIOSXML
00024
00025
00026 #include "smbios/compat.h"
00027
00028 #include <iomanip>
00029 #include <fstream>
00030
00031 #include "testSmbiosXml.h"
00032 #include "smbios/SmbiosDefs.h"
00033
00034
00035
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
00048
00049
00050
00051
00052
00053
00054
00055
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
00088
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
00096
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
00104 string smiOutput = global_writeDirectory + "/smi-output.dat";
00105
00106
00107 smbios::SmbiosXmlFactory::getFactory();
00108
00109
00110
00111
00112
00113
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
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
00151
00152
00153
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
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
00193 }
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203 void testSmbiosXml::testTable_Subscript()
00204 {
00205 STD_TEST_START("%s ", getTestName().c_str() );
00206
00207
00208
00209
00210
00211
00212
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
00223
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
00257 smbios::ISmbiosTable *table =
00258 smbios::SmbiosFactory::getFactory()->getSingleton();
00259
00260
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
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;
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
00317 smbios::ISmbiosTable *table =
00318 smbios::SmbiosFactory::getFactory()->getSingleton();
00319
00320 int tableEntriesCounted = 0;
00321
00322
00323 for( smbios::ISmbiosTable::iterator item = (*table)[-1] ; item != table->end(); ++item)
00324 {
00325 tableEntriesCounted++;
00326 (void) *item;
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
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
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
00375 smbios::ISmbiosTable *table =
00376 smbios::SmbiosFactory::getFactory()->getSingleton();
00377
00378
00379
00380
00381
00382
00383
00384
00385 int tableEntriesCounted = 0;
00386 for( smbios::ISmbiosTable::iterator item = (*table)[8] ; item != table->end(); ++item)
00387 {
00388 (void) *item;
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
00406
00407
00408
00409 void testSmbiosXml::testStreamify()
00410 {
00411 STD_TEST_START("%s ", getTestName().c_str() );
00412
00413
00414
00415
00416 smbios::ISmbiosTable *table =
00417 smbios::SmbiosFactory::getFactory()->getSingleton();
00418
00419 ostringstream ost;
00420 ost << *table << endl;
00421
00422
00423 for( smbios::ISmbiosTable::iterator item = (*table)[8] ; item != table->end(); ++item)
00424 {
00425 ost << *item << endl;
00426 }
00427
00428
00429 STD_TEST_END();
00430 }
00431
00432 void
00433 testSmbiosXml::testItemIdentity ()
00434 {
00435 STD_TEST_START("%s ", getTestName().c_str() );
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445 smbios::ISmbiosTable *table =
00446 smbios::SmbiosFactory::getFactory()->getSingleton();
00447
00448
00449 smbios::ISmbiosTable::iterator position1 = (*table)[smbios::BIOS_Information];
00450 smbios::ISmbiosItem &item1 = *position1;
00451
00452
00453 smbios::ISmbiosTable::iterator position2 = (*table)[smbios::BIOS_Information];
00454 smbios::ISmbiosItem &item2 = *position2;
00455
00456
00457
00458 CPPUNIT_ASSERT_EQUAL( &item1, &item2 );
00459 CPPUNIT_ASSERT_EQUAL( &(*position1), &item2 );
00460 CPPUNIT_ASSERT_EQUAL( &item1 , &(*position2) );
00461 CPPUNIT_ASSERT_EQUAL( &(*position1), &(*position2) );
00462
00463
00464 smbios::ISmbiosTable::iterator position3 = (*table)[smbios::System_Information];
00465 smbios::ISmbiosItem &item3 = *position3;
00466
00467
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
00489
00490
00491
00492
00493
00494
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
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539 smbios::ISmbiosTable *table =
00540 smbios::SmbiosFactory::getFactory()->getSingleton();
00541
00542 smbios::ISmbiosTable::iterator item1 = (*table)["BIOS Information"];
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558 u64 ll1, ll2;
00559 int int1, int2;
00560 string str1, str2;
00561
00562
00563
00564
00565
00566
00567
00568
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
00604
00605
00606
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
00611
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
00630
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
00646
00647
00648
00649 smbios::ISmbiosTable *table =
00650 smbios::SmbiosFactory::getFactory()->getSingleton();
00651
00652 smbios::ISmbiosTable::iterator item1 = ( *table )["System Information"];
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
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
00694
00695
00696
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
00712 }
00713
00714 #if 0
00715
00716
00717
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
00743
00744
00745
00746
00747
00748
00749
00750
00751 smbios::ISmbiosTable *table =
00752 smbios::SmbiosFactory::getFactory()->getSingleton();
00753
00754 smbios::ISmbiosTable::iterator item1 = (*table)["BIOS Information"];
00755
00756
00757
00758
00759
00760
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
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
00792 (void) item->getU8(len - 1);
00793 (void) item->getU16(len - 2);
00794 (void) item->getU32(len - 4);
00795
00796
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
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
00881 (void) tokenTableC[0xFE];
00882
00883 ostringstream ost;
00884 ost << *tokenTable << endl;
00885 ost << *tokenTableC << endl;
00886
00887
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
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
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
00917
00918
00919
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 {
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
00945 if( 0 != memcmp( testStr, reinterpret_cast<char*>(myStr), size - 1 ) )
00946 {
00947
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 {
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
00989
00990
00991
00992 }
00993
00994 next_token:
00995
00996 smbios::ITokenTable::iterator before = token;
00997 smbios::ITokenTable::iterator after = token++;
00998 CPPUNIT_ASSERT( before == after );
00999 }
01000
01001
01002
01003 if( ob )
01004 ob->notify(&doUpdate);
01005
01006 STD_TEST_END();
01007 }
01008
01009
01010
01011
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 {
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 {
01055 ci->execute();
01056 }
01057 catch( const smi::UnhandledSmi & ) {}
01058
01059 STD_TEST_END();
01060 }
01061
01062
01063
01064
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;
01092 (void) isDell;
01093
01094
01095
01096 CPPUNIT_ASSERT(systemId != 0);
01097 CPPUNIT_ASSERT(systemName != 0);
01098
01099
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
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
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
01251
01252 throw skip_test();
01253 }
01254
01255 CPPUNIT_ASSERT_EQUAL ( testInput, rawCMOSOrig );
01256
01257 string shouldBe, rawCMOSNew;
01258
01259
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
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
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
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
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
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
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
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
01316 shouldBe = "BCDFGH";
01317 SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01318 rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01319
01320 shouldBe = "BCDFGH0";
01321
01322 CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01323
01324
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
01332 shouldBe = "MNPQMNPQ";
01333 SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01334 rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01335
01336 shouldBe = "MNPQMNP";
01337 CPPUNIT_ASSERT_EQUAL ( shouldBe, rawCMOSNew );
01338
01339
01340 shouldBe = "ABEIOUD";
01341 SMBIOSSetServiceTag("", shouldBe.c_str(), strlen(shouldBe.c_str()));
01342 rawCMOSNew = safeConvertToString( getServiceTagFromCMOSToken() );
01343
01344 shouldBe = "AB0000D";
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
01410
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
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) );
01441 const string string2( item->getString(5) );
01442 const string string3( item->getString(8) );
01443
01444 const string string4( item->getStringByStringNumber(1) );
01445 const string string5( item->getStringByStringNumber(2) );
01446 const string string6( item->getStringByStringNumber(3) );
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
01471 testValue = 0x1234;
01472 SMBIOSSetNvramStateBytes( testValue, 0x0000 );
01473 CPPUNIT_ASSERT_EQUAL( testValue, SMBIOSGetNvramStateBytes( 0x0000 ) );
01474 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0x8000 ) );
01475 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0xF100 ) );
01476
01477
01478 testValue = 0x9234;
01479 SMBIOSSetNvramStateBytes( testValue, 0x0000 );
01480 CPPUNIT_ASSERT_EQUAL( (testValue & ~0x8000), SMBIOSGetNvramStateBytes( 0x0000 ) );
01481 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0x8000 ) );
01482 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0xF100 ) );
01483
01484
01485 testValue = 0x0234;
01486 SMBIOSSetNvramStateBytes( testValue, 0x8000 );
01487 CPPUNIT_ASSERT_EQUAL( testValue, SMBIOSGetNvramStateBytes( 0x8000 ) );
01488 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0x0000 ) );
01489 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0xF100 ) );
01490
01491
01492 testValue = 0x7234;
01493 SMBIOSSetNvramStateBytes( testValue, 0x8000 );
01494 CPPUNIT_ASSERT_EQUAL( (testValue & ~0xF000), SMBIOSGetNvramStateBytes( 0x8000 ) );
01495 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0x0000 ) );
01496 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0xF100 ) );
01497
01498
01499 testValue = 0x0034;
01500 SMBIOSSetNvramStateBytes( testValue, 0xF100 );
01501 CPPUNIT_ASSERT_EQUAL( testValue, SMBIOSGetNvramStateBytes( 0xF100 ) );
01502 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0x0000 ) );
01503 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0x8000 ) );
01504
01505
01506 testValue = 0x7234;
01507 SMBIOSSetNvramStateBytes( testValue, 0xF100 );
01508 CPPUNIT_ASSERT_EQUAL( (testValue & ~0xFF00), SMBIOSGetNvramStateBytes( 0xF100 ) );
01509 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0x0000 ) );
01510 CPPUNIT_ASSERT_EQUAL( 0x0000, SMBIOSGetNvramStateBytes( 0x8000 ) );
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
01550
01551 ASSERT_THROWS( item->getStringByStringNumber(0), smbios::StringUnavailable );
01552
01553 if (!doc)
01554 throw skip_test();
01555
01556 int numStrings = 0;
01557
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
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
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;
01614 ++item;
01615 }
01616
01617 CPPUNIT_ASSERT( tableEntriesCounted == table->getNumberOfEntries() );
01618
01619
01620
01621
01622
01623 smbios::SmbiosFactory *factory = smbios::SmbiosFactory::getFactory();
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637 factory->reset();
01638
01639
01640
01641
01642
01643
01644
01645
01646 tearDown();
01647 factory = smbios::SmbiosFactory::getFactory();
01648 setUp();
01649
01650
01651
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
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
01678
01679
01680
01681
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 );
01689 ASSERT_THROWS( auto_ptr<smbios::ISmbiosTable>p(factory->makeNew()), smbios::IException );
01690
01691 factory->setParameter("offset", 0xFFFFFUL - 1);
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
01701
01702
01703
01704
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
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