00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "smbios/compat.h"
00021
00022 #include <iomanip>
00023 #include <fstream>
00024
00025 #include "testStandalone.h"
00026 #include "smbios/SmbiosDefs.h"
00027
00028
00029
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
00039
00040
00041
00042
00043
00044
00045
00046
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 string xmlFile = programDirname + getXmlFile();
00076
00077
00078
00079 string memdumpOrigFile = programDirname + getTestDirectory() + "/memdump.dat";
00080 if(!fileExists(memdumpOrigFile))
00081 memdumpOrigFile = getTestDirectory() + "/memdump.dat";
00082 string memdumpCopyFile = writeDirectory + "/memdump-copy.dat";
00083 copyFile( memdumpCopyFile, memdumpOrigFile );
00084
00085
00086
00087 string cmosOrigFile = programDirname + getTestDirectory() + "/cmos.dat";
00088 if(!fileExists(cmosOrigFile))
00089 cmosOrigFile = getTestDirectory() + "/cmos.dat";
00090 string cmosCopyFile = writeDirectory + "/cmos-copy.dat";
00091 copyFile( cmosCopyFile, cmosOrigFile );
00092
00093
00094 string smiOutput = writeDirectory + "/smi-output.dat";
00095
00096
00097 smbios::SmbiosXmlFactory::getFactory();
00098
00099
00100
00101
00102
00103
00104 smbios::SmbiosFactory::getFactory()->setParameter("memFile", memdumpCopyFile);
00105 smbios::SmbiosFactory::getFactory()->setParameter("offset", 0);
00106 smbios::SmbiosFactory::getFactory()->setMode(smbios::SmbiosFactory::UnitTestMode);
00107
00108 cmos:: CmosRWFactory::getFactory()->setParameter("cmosMapFile", cmosCopyFile);
00109 cmos:: CmosRWFactory::getFactory()->setMode( factory::IFactory::UnitTestMode );
00110
00111 memory::MemoryFactory::getFactory()->setParameter("memFile", memdumpCopyFile);
00112 memory::MemoryFactory::getFactory()->setMode( memory::MemoryFactory::UnitTestMode );
00113
00114 smi::SmiFactory::getFactory()->setParameter("smiFile", smiOutput);
00115 smi::SmiFactory::getFactory()->setMode( smi::SmiFactory::UnitTestMode );
00116
00117
00118 smbios::SmbiosFactory::getFactory()->setParameter("xmlFile", xmlFile);
00119 }
00120
00121 void testStandalone::resetFactoryToBuiltinXml()
00122 {
00123 smbios::SmbiosFactory::getFactory()->setParameter("xmlFile", "");
00124 }
00125
00126 void testStandalone::tearDown()
00127 {
00128
00129
00130
00131
00132 smbios::TokenTableFactory::getFactory()->reset();
00133
00134 smbios::SmbiosFactory::getFactory()->reset();
00135
00136 memory::MemoryFactory::getFactory()->reset();
00137
00138 cmos::CmosRWFactory::getFactory()->reset();
00139
00140 smi::SmiFactory::getFactory()->reset();
00141 }
00142
00143
00144
00145
00146
00147
00148
00149 void testStandalone::testTable_Subscript()
00150 {
00151 STD_TEST_START(getTestName().c_str() << " " );
00152
00153
00154
00155
00156
00157
00158
00159 smbios::ISmbiosTable *table =
00160 smbios::SmbiosFactory::getFactory()->getSingleton();
00161
00162 smbios::ISmbiosTable::iterator item1;
00163 smbios::ISmbiosTable::iterator item2;
00164
00165 item1 = (*table)["BIOS Information"];
00166 item2 = (*table)[smbios::BIOS_Information];
00167
00168
00169
00170 CPPUNIT_ASSERT_EQUAL( item1->getHandle(), item2->getHandle() );
00171 CPPUNIT_ASSERT_EQUAL( getItemHandle(*item1), item2->getHandle() );
00172 CPPUNIT_ASSERT_EQUAL( item1->getLength(), item2->getLength() );
00173 CPPUNIT_ASSERT_EQUAL( getItemLength(*item1), item2->getLength() );
00174 CPPUNIT_ASSERT_EQUAL( item1->getType() , item2->getType() );
00175 CPPUNIT_ASSERT_EQUAL( getItemType(*item1) , item2->getType() );
00176
00177 CPPUNIT_ASSERT_EQUAL( (*table)[smbios::BIOS_Information]->getType(), item1->getType() );
00178 CPPUNIT_ASSERT_EQUAL( (*table)["BIOS Information"]->getType(), item1->getType() );
00179
00180 item1 = (*table)["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 CPPUNIT_ASSERT_EQUAL( (*table)["System Information"]->getType(), item1->getType() );
00192
00193
00194 STD_TEST_END("");
00195 }
00196
00197 void testStandalone::testTable_Subscript_builtinXml()
00198 {
00199 resetFactoryToBuiltinXml();
00200 testTable_Subscript();
00201 }
00202
00203 void
00204 testStandalone::testEntryCount ()
00205 {
00206 STD_TEST_START(getTestName().c_str() << " " );
00207
00208
00209 smbios::ISmbiosTable *table =
00210 smbios::SmbiosFactory::getFactory()->getSingleton();
00211
00212
00213 ostringstream ost;
00214 int tableEntriesCounted = 0;
00215 smbios::ISmbiosTable::iterator item = table->begin();
00216 while( item != table->end() )
00217 {
00218 tableEntriesCounted++;
00219 ost << *item << endl;
00220 ++item;
00221 }
00222
00223 CPPUNIT_ASSERT_EQUAL( tableEntriesCounted, table->getNumberOfEntries() );
00224 STD_TEST_END("");
00225 }
00226
00227 void testStandalone::testEntryCount_builtinXml ()
00228 {
00229 resetFactoryToBuiltinXml();
00230 testEntryCount();
00231 }
00232
00233 void
00234 testStandalone::testConstIterator ()
00235 {
00236 STD_TEST_START(getTestName().c_str() << " " );
00237
00238
00239 smbios::ISmbiosTable *table =
00240 smbios::SmbiosFactory::getFactory()->getSingleton();
00241
00242 const smbios::ISmbiosTable *constTable = &*table;
00243
00244 int tableEntriesCounted = 0;
00245 smbios::ISmbiosTable::const_iterator item = constTable->begin();
00246 while( item != constTable->end() )
00247 {
00248 tableEntriesCounted++;
00249 (void) *item;
00250
00251 ++item;
00252 }
00253 CPPUNIT_ASSERT_EQUAL( tableEntriesCounted, constTable->getNumberOfEntries() );
00254 STD_TEST_END("");
00255 }
00256
00257 void testStandalone::testConstIterator_builtinXml ()
00258 {
00259 resetFactoryToBuiltinXml();
00260 testConstIterator();
00261 }
00262
00263 void
00264 testStandalone::testSubscriptOperator1 ()
00265 {
00266 STD_TEST_START(getTestName().c_str() << " " );
00267
00268
00269 smbios::ISmbiosTable *table =
00270 smbios::SmbiosFactory::getFactory()->getSingleton();
00271
00272 int tableEntriesCounted = 0;
00273
00274
00275 for( smbios::ISmbiosTable::iterator item = (*table)[-1] ; item != table->end(); ++item)
00276 {
00277 tableEntriesCounted++;
00278 (void) *item;
00279 }
00280 CPPUNIT_ASSERT_EQUAL( table->getNumberOfEntries(), tableEntriesCounted );
00281 STD_TEST_END("");
00282 }
00283
00284 void testStandalone::testSubscriptOperator1_builtinXml ()
00285 {
00286 resetFactoryToBuiltinXml();
00287 testSubscriptOperator1();
00288 }
00289
00290 void
00291 testStandalone::testSubscriptOperator2 ()
00292 {
00293 STD_TEST_START(getTestName().c_str() << " " );
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 STD_TEST_END("");
00313 }
00314
00315 void testStandalone::testSubscriptOperator2_builtinXml ()
00316 {
00317 resetFactoryToBuiltinXml();
00318 testSubscriptOperator2();
00319 }
00320
00321 void
00322 testStandalone::testSubscriptOperator3 ()
00323 {
00324 STD_TEST_START(getTestName().c_str() << " " );
00325
00326
00327 smbios::ISmbiosTable *table =
00328 smbios::SmbiosFactory::getFactory()->getSingleton();
00329
00330
00331
00332
00333
00334
00335
00336
00337 int tableEntriesCounted = 0;
00338 for( smbios::ISmbiosTable::iterator item = (*table)[8] ; item != table->end(); ++item)
00339 {
00340 (void) *item;
00341 tableEntriesCounted++;
00342 }
00343 CPPUNIT_ASSERT( 1 < tableEntriesCounted );
00344 STD_TEST_END("");
00345 }
00346
00347 void testStandalone::testSubscriptOperator3_builtinXml ()
00348 {
00349 resetFactoryToBuiltinXml();
00350 testSubscriptOperator3();
00351 }
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361 void testStandalone::testStreamify()
00362 {
00363 STD_TEST_START(getTestName().c_str() << " " );
00364
00365
00366
00367
00368 smbios::ISmbiosTable *table =
00369 smbios::SmbiosFactory::getFactory()->getSingleton();
00370
00371 ostringstream ost;
00372 ost << *table << endl;
00373
00374
00375 for( smbios::ISmbiosTable::iterator item = (*table)[8] ; item != table->end(); ++item)
00376 {
00377 ost << *item << endl;
00378 }
00379
00380
00381 STD_TEST_END("");
00382 }
00383
00384 void
00385 testStandalone::testItemIdentity ()
00386 {
00387 STD_TEST_START(getTestName().c_str() << " " );
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397 smbios::ISmbiosTable *table =
00398 smbios::SmbiosFactory::getFactory()->getSingleton();
00399
00400
00401 smbios::ISmbiosTable::iterator position1 = (*table)[smbios::BIOS_Information];
00402 smbios::ISmbiosItem &item1 = *position1;
00403
00404
00405 smbios::ISmbiosTable::iterator position2 = (*table)[smbios::BIOS_Information];
00406 smbios::ISmbiosItem &item2 = *position2;
00407
00408
00409
00410 CPPUNIT_ASSERT_EQUAL( &item1, &item2 );
00411 CPPUNIT_ASSERT_EQUAL( &(*position1), &item2 );
00412 CPPUNIT_ASSERT_EQUAL( &item1 , &(*position2) );
00413 CPPUNIT_ASSERT_EQUAL( &(*position1), &(*position2) );
00414
00415
00416 smbios::ISmbiosTable::iterator position3 = (*table)[smbios::System_Information];
00417 smbios::ISmbiosItem &item3 = *position3;
00418
00419
00420 CPPUNIT_ASSERT( &item1 != &item3 );
00421 CPPUNIT_ASSERT( &item2 != &item3 );
00422
00423 CPPUNIT_ASSERT_EQUAL( item1.getType(), static_cast<u8>(smbios::BIOS_Information) );
00424 CPPUNIT_ASSERT_EQUAL( item2.getType(), static_cast<u8>(smbios::BIOS_Information) );
00425 CPPUNIT_ASSERT_EQUAL( item3.getType(), static_cast<u8>(smbios::System_Information) );
00426
00427 STD_TEST_END("");
00428 }
00429
00430 void testStandalone::testItemIdentity_builtinXml ()
00431 {
00432 resetFactoryToBuiltinXml();
00433 testItemIdentity();
00434 }
00435
00436 void
00437 testStandalone::testEachItemAccessors ()
00438 {
00439 STD_TEST_START(getTestName().c_str() << " " );
00440
00441
00442
00443
00444
00445
00446
00447 smbios::ISmbiosTable *table =
00448 smbios::SmbiosFactory::getFactory()->getSingleton();
00449
00450 smbios::ISmbiosTable::iterator item = table->begin();
00451 while( item != table->end() )
00452 {
00453 u8 type1 = item->getType();
00454 u8 type2 = getU8_FromItem(*item, 0);
00455 CPPUNIT_ASSERT_EQUAL( type1, type2 );
00456
00457 u8 len1 = item->getLength();
00458 u8 len2 = getU8_FromItem(*item, 1);
00459 CPPUNIT_ASSERT_EQUAL( len1, len2 );
00460
00461 u16 handle1 = item->getHandle();
00462 u16 handle2 = getU16_FromItem(*item, 2);
00463 CPPUNIT_ASSERT_EQUAL( handle1, handle2 );
00464
00465 ++item;
00466 }
00467
00468 STD_TEST_END("");
00469 }
00470
00471 void testStandalone::testEachItemAccessors_builtinXml ()
00472 {
00473 resetFactoryToBuiltinXml();
00474 testStandalone::testEachItemAccessors();
00475 }
00476
00477 void testStandalone::testItem_GetBiosInfo()
00478 {
00479 STD_TEST_START(getTestName().c_str() << " " );
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491 smbios::ISmbiosTable *table =
00492 smbios::SmbiosFactory::getFactory()->getSingleton();
00493
00494 smbios::ISmbiosTable::iterator item1 = (*table)["BIOS Information"];
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510 u64 ull1, ull2;
00511 u16 v1, v2, v3;
00512 u8 u1, u2, u3;
00513 int int1, int2;
00514 string str1, str2;
00515
00516
00517
00518
00519
00520
00521
00522
00523 u3=0;
00524 u1 = getU8_FromItem(*item1, "Type");
00525 u2 = item1->getType();
00526 getData(*item1, 0, u3);
00527 CPPUNIT_ASSERT_EQUAL (u1, u2);
00528 CPPUNIT_ASSERT_EQUAL (u1, u3);
00529
00530 u3=0;
00531 u1 = getU8_FromItem(*item1, "Length");
00532 u2 = item1->getLength();
00533 getData(*item1, 1, u3);
00534 CPPUNIT_ASSERT_EQUAL (u1, u2);
00535 CPPUNIT_ASSERT_EQUAL (u1, u3);
00536
00537 v3=0;
00538 v1 = getU16_FromItem(*item1, "Handle");
00539 v2 = item1->getHandle();
00540 getData(*item1, 2, v3);
00541 CPPUNIT_ASSERT_EQUAL (v1, v2);
00542 CPPUNIT_ASSERT_EQUAL (v1, v3);
00543
00544 str1 = getString_FromItem(*item1, "Vendor") ;
00545 str2 = getString_FromItem(*item1, 0x4 ) ;
00546 CPPUNIT_ASSERT_EQUAL (str1, str2);
00547
00548 str1 = getString_FromItem(*item1, "BIOS Version") ;
00549 str2 = getString_FromItem(*item1, 0x5 ) ;
00550 CPPUNIT_ASSERT_EQUAL (str1, str2);
00551
00552 v3=0;
00553 v1 = getU16_FromItem(*item1, "BIOS Starting Address Segment");
00554 v2 = getU16_FromItem(*item1, 0x6 );
00555 getData(*item1, 0x6, v3);
00556 CPPUNIT_ASSERT_EQUAL (v1, v2);
00557 CPPUNIT_ASSERT_EQUAL (v1, v3);
00558
00559 str1 = getString_FromItem(*item1, "BIOS Release Date");
00560 str2 = getString_FromItem(*item1, 0x8 );
00561 CPPUNIT_ASSERT_EQUAL (str1, str2);
00562
00563 int1 = getU8_FromItem(*item1, "BIOS ROM Size");
00564 int2 = getU8_FromItem(*item1, 0x9);
00565 CPPUNIT_ASSERT_EQUAL (int1, int2);
00566
00567 ull1 = getU64_FromItem(*item1, "BIOS Characteristics");
00568 ull2 = getU64_FromItem(*item1, 0xA);
00569
00570
00571
00572
00573 u32 bitfield = 0;
00574 getBits_FromItem(*item1, 0xA, &bitfield, 0, 15);
00575 CPPUNIT_ASSERT_EQUAL (static_cast<u32>(ull2 & 0x000000000000FFFFL), bitfield);
00576
00577
00578 ASSERT_THROWS( getBits_FromItem(*item1, 0xA, &bitfield, 48, 96 ), smbios::DataOutOfBounds );
00579
00580
00581
00582 u32 tempval=0;
00583 bitfield = 0;
00584
00585 getBits_FromItem(*item1, "BIOS Characteristics", "Reserved0", &tempval);
00586 bitfield = tempval;
00587
00588 getBits_FromItem(*item1, "BIOS Characteristics", "Reserved1", &tempval);
00589 bitfield |= (tempval << 1);
00590
00591 getBits_FromItem(*item1, "BIOS Characteristics", "Unknown", &tempval);
00592 bitfield |= (tempval << 2);
00593
00594 getBits_FromItem(*item1, "BIOS Characteristics", "BIOS Characteristics Not Supported", &tempval);
00595 bitfield |= (tempval << 3);
00596
00597 getBits_FromItem(*item1, "BIOS Characteristics", "ISA is supported", &tempval);
00598 bitfield |= (tempval << 4);
00599
00600 getBits_FromItem(*item1, "BIOS Characteristics", "MCA is supported", &tempval);
00601 bitfield |= (tempval << 5);
00602
00603 getBits_FromItem(*item1, "BIOS Characteristics", "EISA is supported", &tempval);
00604 bitfield |= (tempval << 6);
00605
00606 getBits_FromItem(*item1, "BIOS Characteristics", "PCI is supported", &tempval);
00607 bitfield |= (tempval << 7);
00608
00609 getBits_FromItem(*item1, "BIOS Characteristics", "PC Card (PCMCIA) is supported", &tempval);
00610 bitfield |= (tempval << 8);
00611
00612 getBits_FromItem(*item1, "BIOS Characteristics", "Plug and Play is supported", &tempval);
00613 bitfield |= (tempval << 9);
00614
00615 getBits_FromItem(*item1, "BIOS Characteristics", "APM is supported", &tempval);
00616 bitfield |= (tempval << 10);
00617
00618 getBits_FromItem(*item1, "BIOS Characteristics", "BIOS is Upgradeable (Flash)", &tempval);
00619 bitfield |= (tempval << 11);
00620
00621 getBits_FromItem(*item1, "BIOS Characteristics", "BIOS shadowing is allowed", &tempval);
00622 bitfield |= (tempval << 12);
00623
00624 getBits_FromItem(*item1, "BIOS Characteristics", "VL-VESA is supported", &tempval);
00625 bitfield |= (tempval << 13);
00626
00627 getBits_FromItem(*item1, "BIOS Characteristics", "ESCD support is available", &tempval);
00628 bitfield |= (tempval << 14);
00629
00630 getBits_FromItem(*item1, "BIOS Characteristics", "Boot from CD is supported", &tempval);
00631 bitfield |= (tempval << 15);
00632
00633
00634
00635 CPPUNIT_ASSERT_EQUAL (static_cast<u32>(ull2 & 0x000000000000FFFFL), bitfield);
00636
00637 STD_TEST_END("");
00638 }
00639
00640 void testStandalone::testItem_GetBiosInfo_builtinXml ()
00641 {
00642 resetFactoryToBuiltinXml();
00643 testItem_GetBiosInfo();
00644 }
00645
00646 void testStandalone::testNonXml()
00647 {
00648 STD_TEST_START(getTestName().c_str() << " " );
00649
00650 smbios::SmbiosFactory *factory = smbios::SmbiosFactory::getFactory();
00651 factory->reset();
00652
00653
00654
00655
00656
00657
00658 tearDown();
00659 factory = smbios::SmbiosFactory::getFactory();
00660 setUp();
00661
00662
00663
00664 auto_ptr<smbios::ISmbiosTable>p(factory->makeNew());
00665 auto_ptr<const smbios::ISmbiosTable>q(factory->makeNew());
00666 ASSERT_THROWS( (*p)["BIOS Information"], smbios::NotImplemented );
00667 ASSERT_THROWS( (*q)["BIOS Information"], smbios::NotImplemented );
00668
00669 smbios::ISmbiosTable::iterator item1 = (*p)[smbios::BIOS_Information];
00670 smbios::ISmbiosTable::const_iterator item2 = (*q)[smbios::BIOS_Information];
00671
00672
00673 ostringstream ost;
00674 ost << *item1 << endl;
00675
00676 CPPUNIT_ASSERT_EQUAL( item1->getHandle(), item2->getHandle() );
00677 CPPUNIT_ASSERT_EQUAL( item1->getHandle(), getU16_FromItem(*item2, 2) );
00678 CPPUNIT_ASSERT_EQUAL( item1->getLength(), item2->getLength() );
00679 CPPUNIT_ASSERT_EQUAL( item1->getLength(), getU8_FromItem(*item2, 1) );
00680 CPPUNIT_ASSERT_EQUAL( item1->getType() , item2->getType() );
00681 CPPUNIT_ASSERT_EQUAL( item1->getType() , getU8_FromItem(*item2, 0) );
00682
00683 ASSERT_THROWS( getU8_FromItem(*item1, "BIOS Version"), smbios::NotImplemented);
00684 ASSERT_THROWS( getU8_FromItem(*item1, "BIOS Version"), smbios::NotImplemented);
00685 ASSERT_THROWS( getU8_FromItem(*item1, "BIOS Version"), smbios::NotImplemented);
00686 ASSERT_THROWS( getU8_FromItem(*item1, "BIOS Version"), smbios::NotImplemented);
00687 ASSERT_THROWS( getString_FromItem(*item1, "BIOS Version"), smbios::NotImplemented);
00688
00689 STD_TEST_END("");
00690 }
00691
00692 void testStandalone::testItem_GetSystemInfo()
00693 {
00694 STD_TEST_START(getTestName().c_str() << " " );
00695
00696
00697
00698
00699 smbios::ISmbiosTable *table =
00700 smbios::SmbiosFactory::getFactory()->getSingleton();
00701
00702 smbios::ISmbiosTable::iterator item1 = ( *table )["System Information"];
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718 string str1, str2;
00719 int int1, int2;
00720
00721 int1 = getU8_FromItem(*item1, "Type");
00722 int2 = item1->getType();
00723 CPPUNIT_ASSERT_EQUAL (int1, int2);
00724
00725 int1 = getU8_FromItem(*item1, "Length");
00726 int2 = item1->getLength();
00727 CPPUNIT_ASSERT_EQUAL (int1, int2);
00728
00729 int1 = getU16_FromItem(*item1, "Handle");
00730 int2 = item1->getHandle();
00731 CPPUNIT_ASSERT_EQUAL (int1, int2);
00732
00733 str1 = getString_FromItem(*item1, "Manufacturer") ;
00734 str2 = getString_FromItem(*item1, 0x4 ) ;
00735 CPPUNIT_ASSERT_EQUAL (str1, str2);
00736
00737 str1 = getString_FromItem(*item1, "Product Name") ;
00738 str2 = getString_FromItem(*item1, 0x5 ) ;
00739 CPPUNIT_ASSERT_EQUAL (str1, str2);
00740
00741 #if 0
00742
00743
00744
00745
00746
00747
00748 str1 = getString_FromItem(*item1, "Version") ;
00749 str2 = getString_FromItem(*item1, 0x6 ) ;
00750 CPPUNIT_ASSERT_EQUAL( str1, str2 );
00751 #endif
00752
00753 try
00754 {
00755 str1 = getString_FromItem(*item1, "Serial Number") ;
00756 str2 = getString_FromItem(*item1, 0x7 ) ;
00757 CPPUNIT_ASSERT_EQUAL (str1, str2);
00758 }
00759 catch( const exception & )
00760 {
00761
00762 }
00763
00764 #if 0
00765
00766
00767
00768
00769 u8 val1, val2;
00770 val1 = item1->getU8("UUID") ;
00771 val2 = item1->getU8( 0x8 ) ;
00772 CPPUNIT_ASSERT_EQUAL( val1, val2 );
00773
00774 val1 = item1->getU8("Wake-up Type") ;
00775 val2 = item1->getU8( 0x9 ) ;
00776 CPPUNIT_ASSERT_EQUAL( val1, val2 );
00777 #endif
00778
00779 STD_TEST_END("");
00780 }
00781
00782 void testStandalone::testItem_GetSystemInfo_builtinXml ()
00783 {
00784 resetFactoryToBuiltinXml();
00785 testItem_GetSystemInfo();
00786 }
00787
00788
00789 extern const string getStringForType(const XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *doc, const int searchForType );
00790 #include "SmbiosXmlImpl.h"
00791
00792 void testStandalone::testSmbiosXml()
00793 {
00794 STD_TEST_START(getTestName().c_str() << " " );
00795
00796 smbios::ISmbiosTable *table =
00797 smbios::SmbiosFactory::getFactory()->getSingleton();
00798
00799
00800 string bios = dynamic_cast<smbios::SmbiosTableXml *>(table)->getStringForType(0);
00801 string expected = "BIOS Information";
00802 CPPUNIT_ASSERT_EQUAL ( bios, expected );
00803
00804
00805 smbios::ISmbiosTable::iterator item = (*table)["BIOS Information"];
00806 CPPUNIT_ASSERT_EQUAL( isBitSet( &(*item), 0xA, 0x7 ), true );
00807
00808 STD_TEST_END("");
00809 }
00810
00811 void testStandalone::testTypeMismatch()
00812 {
00813 STD_TEST_START(getTestName().c_str() << " " );
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823 smbios::ISmbiosTable *table =
00824 smbios::SmbiosFactory::getFactory()->getSingleton();
00825
00826 smbios::ISmbiosTable::iterator item1 = (*table)["BIOS Information"];
00827
00828
00829
00830
00831
00832
00833 ASSERT_THROWS( getU8_FromItem (*item1, "Handle"), smbios::ParseException );
00834 ASSERT_THROWS( getU16_FromItem(*item1, "Type"), smbios::ParseException );
00835 ASSERT_THROWS( getU32_FromItem(*item1, "Type"), smbios::ParseException );
00836 ASSERT_THROWS( getU64_FromItem(*item1, "Type"), smbios::ParseException );
00837 ASSERT_THROWS( getString_FromItem(*item1, "Type"), smbios::ParseException );
00838 ASSERT_THROWS( getBits_FromItem(*item1, "Type", "foo", NULL), smbios::ParseException );
00839
00840 STD_TEST_END("");
00841 }
00842
00843 void testStandalone::testTypeMismatch_builtinXml ()
00844 {
00845 resetFactoryToBuiltinXml();
00846 testStandalone::testTypeMismatch();
00847 }
00848
00849
00850 void
00851 testStandalone::testGetBoundaries()
00852 {
00853 STD_TEST_START(getTestName().c_str() << " " );
00854
00855
00856 smbios::ISmbiosTable *table =
00857 smbios::SmbiosFactory::getFactory()->getSingleton();
00858
00859 for( smbios::ISmbiosTable::iterator item = (*table)[-1] ; item != table->end(); ++item)
00860 {
00861 int len = item->getLength();
00862
00863
00864 (void) getU8_FromItem (*item, len - 1);
00865 (void) getU16_FromItem(*item, len - 2);
00866 (void) getU32_FromItem(*item, len - 4);
00867
00868
00869 if( len >= 8 )
00870 (void) getU64_FromItem(*item, len - 8);
00871
00872 ASSERT_THROWS( getU8_FromItem (*item, len - 0), smbios::DataOutOfBounds);
00873 ASSERT_THROWS( getU16_FromItem(*item, len - 1), smbios::DataOutOfBounds);
00874 ASSERT_THROWS( getU32_FromItem(*item, len - 3), smbios::DataOutOfBounds);
00875 ASSERT_THROWS( getU64_FromItem(*item, len - 7), smbios::DataOutOfBounds);
00876 }
00877
00878 STD_TEST_END("");
00879 }
00880
00881 void testStandalone::testGetBoundaries_builtinXml ()
00882 {
00883 resetFactoryToBuiltinXml();
00884 testStandalone::testGetBoundaries();
00885 }
00886
00887
00888
00889
00890
00891 void
00892 testStandalone::testMemoryBadFiles ()
00893 {
00894 STD_TEST_START(getTestName().c_str() << " " );
00895
00896 memory::MemoryFactory *memFact = memory::MemoryFactory::getFactory();
00897
00898 memFact->setParameter("memFile", "");
00899 ASSERT_THROWS( memFact->makeNew() , memory::AccessError);
00900
00901 memFact->setParameter("memFile", "nonexistentfile");
00902 ASSERT_THROWS( memFact->makeNew() , memory::AccessError);
00903
00904 memory::MemoryFactory::getFactory()->setMode( 2 );
00905 ASSERT_THROWS( memFact->makeNew(), smbios::NotImplemented);
00906
00907 memory::MemoryFactory::getFactory()->setMode( memory::MemoryFactory::UnitTestMode );
00908
00909 STD_TEST_END("");
00910 }
00911
00912 void
00913 testStandalone::testMemoryFuncs ()
00914 {
00915 STD_TEST_START(getTestName().c_str() << " " );
00916
00917 memory::MemoryFactory *memFact = memory::MemoryFactory::getFactory();
00918
00919 memory::IMemory *mem = memFact->getSingleton();
00920
00921 mem->getByte( 0 );
00922
00923 ASSERT_THROWS( mem->getByte( 0x10000000UL ), memory::AccessError);
00924
00925 mem->putByte( 0, 254 );
00926 int b = mem->getByte( 0 );
00927
00928 CPPUNIT_ASSERT_EQUAL ( b, 254 );
00929 STD_TEST_END("");
00930 }
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940 void
00941 testStandalone::testCmosConstructor ()
00942 {
00943 STD_TEST_START(getTestName().c_str() << " " );
00944
00945 smbios::TokenTableFactory *ttFactory;
00946 ttFactory = smbios::TokenTableFactory::getFactory() ;
00947 smbios::ITokenTable *tokenTable = ttFactory->getSingleton();
00948
00949 ostringstream ost;
00950
00951 smbios::ITokenTable::iterator token = tokenTable->begin();
00952 while( token != tokenTable->end() )
00953 {
00954 ost << *token << endl;
00955 ++token;
00956 }
00957
00958 STD_TEST_END("");
00959 }
00960
00961
00962
00963
00964
00965
00966 void
00967 testStandalone::testSmi_callingInterface()
00968 {
00969 STD_TEST_START(getTestName().c_str() << " " );
00970
00971 std::auto_ptr<smi::ISmi> smi = smi::SmiFactory::getFactory()->makeNew(smi::SmiFactory::DELL_CALLING_INTERFACE_SMI_RAW);
00972 smi->setCommandIOMagic( 0x1234, 0x56 );
00973
00974 smi::IDellCallingInterfaceSmi *ci = dynamic_cast<smi::IDellCallingInterfaceSmi *>(&*smi);
00975 ci->setClass( 0xAABB );
00976 ci->setSelect( 0xCCDD );
00977 ci->setArg( 0, 0xA1A2A3A4 );
00978 ci->setArg( 1, 0xB1B2B3B4 );
00979 ci->setArg( 2, 0xC1C2C3C4 );
00980 ci->setArg( 3, 0xD1D2D3D4 );
00981 try
00982 {
00983 ci->execute();
00984 }
00985 catch( const smi::UnhandledSmi & ) {}
00986
00987 STD_TEST_END("");
00988 }
00989
00990 void
00991 testStandalone::testSmi_callingInterface_physaddr ()
00992 {
00993 STD_TEST_START(getTestName().c_str() << " " );
00994
00995 std::auto_ptr<smi::ISmi> smi = smi::SmiFactory::getFactory()->makeNew(smi::SmiFactory::DELL_CALLING_INTERFACE_SMI_RAW);
00996 smi->setCommandIOMagic( 0x1234, 0x56 );
00997
00998 smi::IDellCallingInterfaceSmi *ci = dynamic_cast<smi::IDellCallingInterfaceSmi *>(&*smi);
00999 ci->setClass( 0xAABB );
01000 ci->setSelect( 0xCCDD );
01001 ci->setArgAsPhysicalAddress(0, 0);
01002 ci->setArgAsPhysicalAddress(1, 1);
01003 ci->setArgAsPhysicalAddress(2, 2);
01004 ci->setArgAsPhysicalAddress(3, 3);
01005 try
01006 {
01007 ci->execute();
01008 }
01009 catch( const smi::UnhandledSmi & ) {}
01010
01011 STD_TEST_END("");
01012 }
01013
01014
01015
01016 string safeConvertToString( const char *str )
01017 {
01018 string fromSystem = "";
01019 if( 0 != str )
01020 {
01021 fromSystem = str;
01022 }
01023 SMBIOSFreeMemory(str);
01024 return fromSystem;
01025 }
01026
01027 void
01028 testStandalone::testLibraryVersion()
01029 {
01030 STD_TEST_START(getTestName().c_str() << " " );
01031
01032 string fromSystem = SMBIOSGetLibraryVersionString();
01033 string testInput = LIBSMBIOS_RELEASE_VERSION;
01034
01035 CPPUNIT_ASSERT_EQUAL ( testInput, fromSystem );
01036 STD_TEST_END("");
01037 }
01038
01039 void
01040 testStandalone::testException()
01041 {
01042 STD_TEST_START(getTestName().c_str() << " " );
01043 std::string actual = "";
01044 smbios::Exception<smbios::IException> foo;
01045 string source = "";
01046 string expected = "";
01047 foo.setParameter("foo", "happy");
01048 foo.setParameter("bar", 42);
01049 foo.setParameter("recursive", "%(foo)s");
01050 foo.setParameter("recursiverecursive", "%(recursive)s");
01051
01052 source = "The %% cat is %(foo)s. The best number is %(bar)i. %";
01053 expected = "The % cat is happy. The best number is 42. %";
01054 foo.setMessageString( source );
01055 actual = foo.what();
01056 CPPUNIT_ASSERT_EQUAL( expected, actual );
01057
01058
01059 smbios::Exception<smbios::IException> bar = foo;
01060 actual = bar.what();
01061 CPPUNIT_ASSERT_EQUAL( expected, actual );
01062
01063 source = "The %% cat is %(recursive)s. The best number is %(bar)i. %";
01064 foo.setMessageString( source );
01065 actual = foo.what();
01066 CPPUNIT_ASSERT_EQUAL( expected, actual );
01067
01068 source = "The %% cat is %(recursiverecursive)s. The best number is %(bar)i. %";
01069 foo.setMessageString( source );
01070 actual = foo.what();
01071 CPPUNIT_ASSERT_EQUAL( expected, actual );
01072
01073 source = "The %% cat %is %(recursiverecursive)s. The best number is %(bar)i. %";
01074 expected = "The % cat %is happy. The best number is 42. %";
01075 foo.setMessageString( source );
01076 actual = foo.what();
01077 CPPUNIT_ASSERT_EQUAL( expected, actual );
01078
01079 source = " %(a_really_long_variable_longer_than_32_characters)s";
01080 expected = " %(a_really_long_variable_longer_than_32_characters)s";
01081 foo.setMessageString( source );
01082 actual = foo.what();
01083 CPPUNIT_ASSERT_EQUAL( expected, actual );
01084
01085 source = " %(no_closing_paren";
01086 expected = " %(no_closing_paren";
01087 foo.setMessageString( source );
01088 actual = foo.what();
01089 CPPUNIT_ASSERT_EQUAL( expected, actual );
01090
01091 source = " %(a_var_with_no_type)";
01092 expected = " %(a_var_with_no_type)";
01093 foo.setMessageString( source );
01094 actual = foo.what();
01095 CPPUNIT_ASSERT_EQUAL( expected, actual );
01096
01097 source = " %(a_var_with_no_type) ";
01098 expected = " %(a_var_with_no_type) ";
01099 foo.setMessageString( source );
01100 actual = foo.what();
01101 CPPUNIT_ASSERT_EQUAL( expected, actual );
01102
01103 source = " %";
01104 expected = " %";
01105 foo.setMessageString( source );
01106 actual = foo.what();
01107 CPPUNIT_ASSERT_EQUAL( expected, actual );
01108
01109 STD_TEST_END("");
01110 }
01111