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