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