1 /* 2 $Id: PropertyConstructionTest.cpp,v 1.3 2002/08/22 03:15:35 jrand Exp $ 3 4 This file implements the construction test for the OpenBeOS BPropertyInfo 5 code. This class tests the following usecases: 6 - Construction 1 to 4 7 - Destruction 8 - Properties 9 - Values 10 - Count Properties 11 - Count Values 12 - Unflatten 13 14 */ 15 16 17 #include "PropertyConstructionTest.h" 18 19 20 /* 21 * Method: PropertyConstructionTest::PropertyConstructionTest() 22 * Descr: This is the constructor for this class. 23 */ 24 25 26 PropertyConstructionTest::PropertyConstructionTest(std::string name) : 27 PropertyTestcase(name) 28 { 29 } 30 31 32 /* 33 * Method: PropertyConstructionTest::~PropertyConstructionTest() 34 * Descr: This is the destructor for this class. 35 */ 36 37 38 PropertyConstructionTest::~PropertyConstructionTest() 39 { 40 } 41 42 43 /* 44 * Method: PropertyConstructionTest::CompareProperties() 45 * Descr: This member function checks that the two property_info structures 46 * passed in match. 47 */ 48 49 50 void PropertyConstructionTest::CompareProperties( 51 const property_info *prop1, 52 const property_info *prop2, 53 int prop_count) 54 { 55 int i, j, k; 56 57 if ((prop_count != 0) && (prop1 != prop2)) { 58 assert(prop1 != NULL); 59 assert(prop2 != NULL); 60 for (i = 0; i < prop_count; i++) { 61 assert(prop1[i].name != 0); 62 assert(prop2[i].name != 0); 63 assert(strcmp(prop1[i].name, prop2[i].name) == 0); 64 65 for(j = 0; j < 10; j++) { 66 assert(prop1[i].commands[j] == prop2[i].commands[j]); 67 if (prop1[i].commands[j] == 0) { 68 break; 69 } 70 } 71 72 for(j = 0; j < 10; j++) { 73 assert(prop1[i].specifiers[j] == prop2[i].specifiers[j]); 74 if (prop1[i].specifiers[j] == 0) { 75 break; 76 } 77 } 78 79 if (prop1[i].usage != prop2[i].usage) { 80 if (prop1[i].usage == NULL) { 81 assert(prop2[i].usage == NULL); 82 } else { 83 assert(strcmp(prop1[i].usage, prop2[i].usage) == 0); 84 } 85 } 86 87 assert(prop1[i].extra_data == prop2[i].extra_data); 88 89 for(j = 0; j < 10; j++) { 90 assert(prop1[i].types[j] == prop2[i].types[j]); 91 if (prop1[i].types[j] == 0) { 92 break; 93 } 94 } 95 96 for(j = 0; j < 3; j++) { 97 for(k = 0; k < 5; k++) { 98 if (prop1[i].ctypes[j].pairs[k].name == 0) { 99 assert(prop2[i].ctypes[j].pairs[k].name == 0); 100 break; 101 } else { 102 assert(prop2[i].ctypes[j].pairs[k].name != 0); 103 assert(strcmp(prop1[i].ctypes[j].pairs[k].name, 104 prop2[i].ctypes[j].pairs[k].name) == 0); 105 assert(prop1[i].ctypes[j].pairs[k].type == 106 prop2[i].ctypes[j].pairs[k].type); 107 } 108 } 109 if (prop1[i].ctypes[j].pairs[0].name == 0) { 110 break; 111 } 112 } 113 } 114 } 115 } 116 117 118 /* 119 * Method: PropertyConstructionTest::CompareValues() 120 * Descr: This member function checks that the two value_info structures 121 * passed in match. 122 */ 123 124 125 void PropertyConstructionTest::CompareValues( 126 const value_info *value1, 127 const value_info *value2, 128 int value_count) 129 { 130 int i; 131 if ((value_count != 0) && (value1 != value2)) { 132 assert(value1 != NULL); 133 assert(value2 != NULL); 134 for (i = 0; i < value_count; i++) { 135 assert(value1[i].name != 0); 136 assert(value2[i].name != 0); 137 assert(strcmp(value1[i].name, value2[i].name) == 0); 138 139 assert(value1[i].value == value2[i].value); 140 141 assert(value1[i].kind == value2[i].kind); 142 143 if (value1[i].usage == 0) { 144 assert(value2[i].usage == 0); 145 } else { 146 assert(value2[i].usage != 0); 147 assert(strcmp(value1[i].usage, value2[i].usage) == 0); 148 } 149 150 assert(value1[i].extra_data == value2[i].extra_data); 151 } 152 } 153 } 154 155 156 /* 157 * Method: PropertyConstructionTest::TestProperty() 158 * Descr: This member function performs this test. 159 */ 160 161 162 void PropertyConstructionTest::TestProperty( 163 BPropertyInfo *propTest, 164 const property_info *prop_list, 165 const value_info *value_list, 166 int32 prop_count, 167 int32 value_count, 168 ssize_t flat_size, 169 const char *lflat_data, 170 const char *bflat_data) 171 { 172 assert(propTest->CountProperties() == prop_count); 173 assert(propTest->CountValues() == value_count); 174 CompareProperties(propTest->Properties(), prop_list, prop_count); 175 CompareValues(propTest->Values(), value_list, value_count); 176 } 177 178 179 /* 180 * Method: PropertyConstructionTest::suite() 181 * Descr: This static member function returns a test caller for performing 182 * all combinations of "PropertyConstructionTest". The test 183 * is created as a ThreadedTestCase (typedef'd as 184 * PropertyConstructionTestCaller) with only one thread. 185 */ 186 187 Test *PropertyConstructionTest::suite(void) 188 { 189 typedef CppUnit::TestCaller<PropertyConstructionTest> 190 PropertyConstructionTestCaller; 191 192 return(new PropertyConstructionTestCaller("BPropertyInfo::Construction Test", &PropertyConstructionTest::PerformTest)); 193 } 194 195 196