1 | /** |
---|
2 | * @file |
---|
3 | * Odd Object Name/Id Error Cases |
---|
4 | */ |
---|
5 | |
---|
6 | /* |
---|
7 | * COPYRIGHT (c) 1989-2012. |
---|
8 | * On-Line Applications Research Corporation (OAR). |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <tmacros.h> |
---|
20 | |
---|
21 | #include <rtems/score/objectimpl.h> |
---|
22 | |
---|
23 | const char rtems_test_name[] = "PSXOBJ 1"; |
---|
24 | |
---|
25 | /* forward declarations to avoid warnings */ |
---|
26 | rtems_task Init(rtems_task_argument ignored); |
---|
27 | |
---|
28 | rtems_task Init( |
---|
29 | rtems_task_argument ignored |
---|
30 | ) |
---|
31 | { |
---|
32 | Objects_Get_by_name_error error; |
---|
33 | Objects_Information TestClass; |
---|
34 | Objects_Control *the_object; |
---|
35 | char name[64]; |
---|
36 | size_t name_len; |
---|
37 | bool bc; |
---|
38 | |
---|
39 | TEST_BEGIN(); |
---|
40 | |
---|
41 | /* very fake object class to test with */ |
---|
42 | _Objects_Initialize_information( |
---|
43 | &TestClass, |
---|
44 | 1, /* the_api */ |
---|
45 | 4, /* the_class */ |
---|
46 | 0, /* maximum */ |
---|
47 | 4, /* size */ |
---|
48 | true, /* is_string */ |
---|
49 | 10 /* maximum_name_length */ |
---|
50 | #if defined(RTEMS_MULTIPROCESSING) |
---|
51 | , |
---|
52 | false, /* supports_global */ |
---|
53 | NULL /* Objects_Thread_queue_Extract_callout extract */ |
---|
54 | #endif |
---|
55 | ); |
---|
56 | |
---|
57 | puts( "INIT - _Objects_Get_by_name - NULL name" ); |
---|
58 | the_object = _Objects_Get_by_name( &TestClass, NULL, NULL, &error ); |
---|
59 | rtems_test_assert( the_object == NULL ); |
---|
60 | rtems_test_assert( error == OBJECTS_GET_BY_NAME_INVALID_NAME ); |
---|
61 | |
---|
62 | puts( "INIT - _Objects_Get_by_name - name too long" ); |
---|
63 | strcpy( name, "TOOOOOOOOOOOOOOOOOO LONG" ); |
---|
64 | the_object = _Objects_Get_by_name( &TestClass, name, NULL, &error ); |
---|
65 | rtems_test_assert( the_object == NULL ); |
---|
66 | rtems_test_assert( error == OBJECTS_GET_BY_NAME_NAME_TOO_LONG ); |
---|
67 | |
---|
68 | puts( "INIT - _Objects_Get_by_name - name of non-existent object" ); |
---|
69 | strcpy( name, "NOT FOUND" ); |
---|
70 | name_len = 123; |
---|
71 | the_object = _Objects_Get_by_name( &TestClass, name, &name_len, &error ); |
---|
72 | rtems_test_assert( the_object == NULL ); |
---|
73 | rtems_test_assert( error == OBJECTS_GET_BY_NAME_NO_OBJECT ); |
---|
74 | rtems_test_assert( name_len == 9 ); |
---|
75 | |
---|
76 | /* out of memory error ONLY when POSIX is enabled */ |
---|
77 | puts( "INIT - _Objects_Set_name fails - out of memory" ); |
---|
78 | rtems_workspace_greedy_allocate( NULL, 0 ); |
---|
79 | |
---|
80 | bc = _Objects_Set_name( &TestClass, &_Thread_Get_executing()->Object, name ); |
---|
81 | rtems_test_assert( bc == false ); |
---|
82 | |
---|
83 | TEST_END(); |
---|
84 | rtems_test_exit(0); |
---|
85 | } |
---|
86 | |
---|
87 | /* configuration information */ |
---|
88 | |
---|
89 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
90 | #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER |
---|
91 | |
---|
92 | #define CONFIGURE_MAXIMUM_TASKS 1 |
---|
93 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
94 | |
---|
95 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
96 | |
---|
97 | #define CONFIGURE_INIT |
---|
98 | #include <rtems/confdefs.h> |
---|
99 | |
---|
100 | /* global variables */ |
---|