1 //------------------------------------------------------------------------------ 2 // BArchivableTester.cpp 3 // 4 /** 5 BArchivable tests 6 @note InvalidArchiveShallow() and InvalidArchiveDeep() are not tested 7 against the original implementation as it does not handle NULL 8 parameters gracefully. 9 */ 10 //------------------------------------------------------------------------------ 11 12 // Standard Includes ----------------------------------------------------------- 13 14 // System Includes ------------------------------------------------------------- 15 #include <Message.h> 16 17 // Project Includes ------------------------------------------------------------ 18 19 // Local Includes -------------------------------------------------------------- 20 #include "BArchivableTester.h" 21 22 // Local Defines --------------------------------------------------------------- 23 24 // Globals --------------------------------------------------------------------- 25 26 //------------------------------------------------------------------------------ 27 /** 28 BArchivable::Perform(perform_code d, void* arg) 29 @case Any 30 @param d Not used 31 @param arg Not used 32 @results Returns B_ERROR in all cases. 33 */ 34 void TBArchivableTestCase::TestPerform() 35 { 36 BArchivable Archive; 37 CPPUNIT_ASSERT(Archive.Perform(0, NULL) == B_ERROR); 38 } 39 //------------------------------------------------------------------------------ 40 /** 41 BArchivable::Archive(BMessage* into, bool deep) 42 @case Invalid archive, shallow archiving 43 @param into NULL 44 @param deep false 45 @results Returns B_BAD_VALUE. 46 */ 47 void TBArchivableTestCase::InvalidArchiveShallow() 48 { 49 BArchivable Archive; 50 CPPUNIT_ASSERT(Archive.Archive(NULL, false) == B_BAD_VALUE); 51 } 52 //------------------------------------------------------------------------------ 53 /** 54 BArchivable::Archive(BMessage* into, bool deep) 55 @case Valid archive, shallow archiving 56 @param into Valid BMessage pointer 57 @param deep false 58 @results Returns B_OK. 59 Resultant archive has a string field labeled "class". 60 Field "class" contains the string "BArchivable". 61 */ 62 void TBArchivableTestCase::ValidArchiveShallow() 63 { 64 BMessage Storage; 65 BArchivable Archive; 66 CPPUNIT_ASSERT(Archive.Archive(&Storage, false) == B_OK); 67 const char* name; 68 CPPUNIT_ASSERT(Storage.FindString("class", &name) == B_OK); 69 CPPUNIT_ASSERT(strcmp(name, "BArchivable") == 0); 70 } 71 //------------------------------------------------------------------------------ 72 /** 73 BArchivable::Archive(BMessage* into, bool deep) 74 @case Invalid archive, deep archiving 75 @param into NULL 76 @param deep true 77 @results Returns B_BAD_VALUE 78 */ 79 void TBArchivableTestCase::InvalidArchiveDeep() 80 { 81 BArchivable Archive; 82 CPPUNIT_ASSERT(Archive.Archive(NULL, true) == B_BAD_VALUE); 83 } 84 //------------------------------------------------------------------------------ 85 /** 86 BArchivable::Archive(BMessage* into, bool deep) 87 @case Valid archive, deep archiving 88 @param into Valid BMessage pointer 89 @param deep true 90 @results Returns B_OK. 91 Resultant archive has a string field labeled "class". 92 Field "class" contains the string "BArchivable". 93 */ 94 void TBArchivableTestCase::ValidArchiveDeep() 95 { 96 BMessage Storage; 97 BArchivable Archive; 98 CPPUNIT_ASSERT(Archive.Archive(&Storage, true) == B_OK); 99 const char* name; 100 CPPUNIT_ASSERT(Storage.FindString("class", &name) == B_OK); 101 CPPUNIT_ASSERT(strcmp(name, "BArchivable") == 0); 102 } 103 //------------------------------------------------------------------------------ 104 CppUnit::Test* TBArchivableTestCase::Suite() 105 { 106 CppUnit::TestSuite* SuiteOfTests = new CppUnit::TestSuite; 107 ADD_TEST(SuiteOfTests, TBArchivableTestCase, TestPerform); 108 #if !defined(TEST_R5) 109 ADD_TEST(SuiteOfTests, TBArchivableTestCase, InvalidArchiveShallow); 110 #endif 111 ADD_TEST(SuiteOfTests, TBArchivableTestCase, ValidArchiveShallow); 112 #if !defined(TEST_R5) 113 ADD_TEST(SuiteOfTests, TBArchivableTestCase, InvalidArchiveDeep); 114 #endif 115 ADD_TEST(SuiteOfTests, TBArchivableTestCase, ValidArchiveDeep); 116 117 return SuiteOfTests; 118 } 119 //------------------------------------------------------------------------------ 120 121 122 /* 123 * $Log $ 124 * 125 * $Id $ 126 * 127 */ 128 129 130 131