MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / test_object_info_enumeration

Function test_object_info_enumeration

src/utest/object_tc.c:193–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193static void test_object_info_enumeration(void)
194{
195 struct rt_object static_objs[3];
196 rt_object_t dyn_objs[2] = {RT_NULL, RT_NULL};
197 char names[5][TEST_RT_NAME_MAX];
198
199 /* Generate unique names */
200 for (int i = 0; i < 5; i++)
201 {
202 uassert_true(generate_unique_name(names[i], TEST_RT_NAME_MAX, "enum") == RT_EOK);
203 }
204
205 /* Create test objects */
206 for (int i = 0; i < 3; i++)
207 {
208 rt_object_init(&static_objs[i], RT_Object_Class_Thread, names[i]);
209 }
210 for (int i = 0; i < 2; i++)
211 {
212 dyn_objs[i] = rt_object_allocate(RT_Object_Class_Thread, names[i + 3]);
213 uassert_not_null(dyn_objs[i]);
214 }
215
216 /* Test 1: Get object information */
217 struct rt_object_information *info = rt_object_get_information(RT_Object_Class_Thread);
218 uassert_not_null(info);
219 uassert_int_equal(info->type, RT_Object_Class_Thread);
220
221 /* Test 2: Get object count */
222 int count = rt_object_get_length(RT_Object_Class_Thread);
223 uassert_true(count >= 5);
224
225 /* Test 3: Get object pointers with sufficient buffer */
226 rt_object_t *objects = (rt_object_t *)rt_malloc((count + 2) * sizeof(rt_object_t));
227 uassert_not_null(objects);
228 int ret = rt_object_get_pointers(RT_Object_Class_Thread, objects, count + 2);
229 uassert_int_equal(ret, count);
230 int found_count = 0;
231 for (int i = 0; i < ret; i++)
232 {
233 for (int j = 0; j < 3; j++)
234 if (objects[i] == &static_objs[j]) found_count++;
235 for (int j = 0; j < 2; j++)
236 if (objects[i] == dyn_objs[j]) found_count++;
237 }
238 uassert_int_equal(found_count, 5);
239 rt_free(objects);
240
241 /* Test 4: Get object pointers with small buffer */
242 rt_object_t one_object[1];
243 ret = rt_object_get_pointers(RT_Object_Class_Thread, one_object, 1);
244 uassert_true(ret <= 1);
245
246 /* Test 5: Empty container (Semaphore) */
247#ifdef RT_USING_SEMAPHORE
248 int empty_count = rt_object_get_length(RT_Object_Class_Semaphore);
249 uassert_true(empty_count >= 0);
250#endif

Callers

nothing calls this directly

Calls 10

generate_unique_nameFunction · 0.85
rt_object_initFunction · 0.85
rt_object_allocateFunction · 0.85
rt_object_get_lengthFunction · 0.85
rt_mallocFunction · 0.85
rt_object_get_pointersFunction · 0.85
rt_freeFunction · 0.85
rt_object_detachFunction · 0.85
rt_object_deleteFunction · 0.85

Tested by

no test coverage detected