1 /* 2 $Id: PropertyFindMatchTest.cpp 851 2002-08-22 03:15:35Z jrand $ 3 4 This file implements the FindMatch test for the Haiku BPropertyInfo 5 code. This class tests the following usecases: 6 - Find Match 7 8 */ 9 10 11 #include "PropertyFindMatchTest.h" 12 13 #include <assert.h> 14 15 #include <Message.h> 16 17 18 /* 19 * Method: PropertyFindMatchTest::PropertyFindMatchTest() 20 * Descr: This is the constructor for this class. 21 */ 22 23 24 PropertyFindMatchTest::PropertyFindMatchTest(std::string name) : 25 PropertyTestcase(name) 26 { 27 } 28 29 30 /* 31 * Method: PropertyFindMatchTest::~PropertyFindMatchTest() 32 * Descr: This is the destructor for this class. 33 */ 34 35 36 PropertyFindMatchTest::~PropertyFindMatchTest() 37 { 38 } 39 40 41 /* 42 * Method: PropertyFindMatchTest::TestProperty() 43 * Descr: This member function performs this test. 44 */ 45 46 47 void PropertyFindMatchTest::TestProperty( 48 BPropertyInfo *propTest, 49 const property_info *prop_list, 50 const value_info *value_list, 51 int32 prop_count, 52 int32 value_count, 53 ssize_t flat_size, 54 const char *lflat_data, 55 const char *bflat_data) 56 { 57 const uint32 *commands; 58 const uint32 *specifiers; 59 const property_info *theProps = propTest->Properties(); 60 int i, j, k; 61 bool wildcardCommand, wildcardSpec; 62 63 ExecFindMatch(propTest, uniquePropName, uniqueCommand, uniqueSpecifier, false, -1); 64 ExecFindMatch(propTest, commonPropName, uniqueCommand, uniqueSpecifier, false, -1); 65 ExecFindMatch(propTest, uniquePropName, commonCommand, uniqueSpecifier, false, -1); 66 ExecFindMatch(propTest, uniquePropName, uniqueCommand, commonSpecifier, false, -1); 67 68 for (i=0; i < prop_count; i++) { 69 wildcardCommand = (theProps[i].commands[0] == 0); 70 wildcardSpec = (theProps[i].specifiers[0] == 0); 71 if (wildcardCommand) { 72 commands = wildcardCommandTests; 73 } else { 74 commands = theProps[i].commands; 75 } 76 if (wildcardSpec) { 77 specifiers = wildcardSpecifierTests; 78 } else { 79 specifiers = theProps[i].specifiers; 80 } 81 for(j=0; j<10; j++) { 82 if (commands[j] == 0) { 83 break; 84 } 85 if (!wildcardSpec) { 86 ExecFindMatch(propTest, theProps[i].name, commands[j], uniqueSpecifier, 87 wildcardCommand, -1); 88 } 89 for(k=0; k<10; k++) { 90 if (specifiers[k] == 0) { 91 break; 92 } 93 if (!wildcardCommand) { 94 ExecFindMatch(propTest, theProps[i].name, uniqueCommand, specifiers[k], 95 wildcardCommand, -1); 96 } 97 ExecFindMatch(propTest, theProps[i].name, commands[j], specifiers[k], 98 wildcardCommand, i); 99 } 100 } 101 } 102 } 103 104 105 /* 106 * Method: PropertyFindMatchTest::ExecFindMatch() 107 * Descr: This member function executes the FindMatch() member on the 108 * BPropertyInfo instance and ensures that the result is what is 109 * expected. It calls FindMatch() normally with a zero index 110 * (meaning to match wildcard and non-wildcard command instances) 111 * and with a non-NULL specifier message. The extra_data member 112 * is checked to make sure it is what is expected if a match is 113 * returned. 114 * 115 * The Be implementation takes a pointer to a BMessage specifier 116 * but it doesn't seem to need it. So, the FindMatch() is called 117 * again with a NULL BMessage specifier and we expect the same 118 * result. 119 * 120 * Finally, the result is checked with a non-zero index. If index 121 * is non-zero, a match will only be found if the property uses 122 * a wildcard for the command. Depending on whether we are testing 123 * a wildcard command (from the wildcardCommand flag), we check the 124 * result with and without a BMessage specifier. 125 */ 126 127 128 void PropertyFindMatchTest::ExecFindMatch( 129 BPropertyInfo *propTest, 130 const char *prop, 131 uint32 comm, 132 uint32 spec, 133 bool wildcardCommand, 134 int32 result 135 ) 136 { 137 BMessage msg(comm); 138 BMessage specMsg(spec); 139 specMsg.AddString("property", prop); 140 msg.AddSpecifier(&specMsg); 141 uint32 extra_data; 142 143 assert(propTest->FindMatch(&msg, 0, &specMsg, spec, prop, &extra_data) == result); 144 if (result >= 0) { 145 assert((propTest->Properties())[result].extra_data == extra_data); 146 } 147 assert(propTest->FindMatch(&msg, 0, NULL, spec, prop, &extra_data) == result); 148 if (wildcardCommand) { 149 assert(propTest->FindMatch(&msg, 1, &specMsg, spec, prop, &extra_data) == result); 150 assert(propTest->FindMatch(&msg, 1, NULL, spec, prop, &extra_data) == result); 151 } else { 152 assert(propTest->FindMatch(&msg, 1, &specMsg, spec, prop, &extra_data) == -1); 153 assert(propTest->FindMatch(&msg, 1, NULL, spec, prop, &extra_data) == -1); 154 } 155 } 156 157 158 /* 159 * Method: PropertyFindMatchTest::suite() 160 * Descr: This static member function returns a test caller for performing 161 * all combinations of "PropertyFindMatchTest". The test 162 * is created as a ThreadedTestCase (typedef'd as 163 * PropertyFindMatchTestCaller) with only one thread. 164 */ 165 166 Test *PropertyFindMatchTest::suite(void) 167 { 168 typedef CppUnit::TestCaller<PropertyFindMatchTest> 169 PropertyFindMatchTestCaller; 170 171 return(new PropertyFindMatchTestCaller("BPropertyInfo::FindMatch Test", &PropertyFindMatchTest::PerformTest)); 172 } 173 174 175