HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
test_client.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <assert.h>
5 #include <stdint.h>
6 
7 #include <hipc/client.h>
8 
10  {HIPC_MBR_SIMPLE, "tick"},
11  {HIPC_MBR_SIMPLE, "count"},
12  {HIPC_MBR_SIMPLE, "diff"},
13 };
14 
16  {HIPC_MBR_SIMPLE, "enable"},
17  {HIPC_MBR_SIMPLE, "diff"},
18 };
19 
21  {3, "test_log", HIPCUD_test_indp_member_log},
22  {2, "test_ctl", HIPCUD_test_indp_member_ctl},
23 };
24 
26  NULL, 0, 5, 2, HIPCUD_test_indp_struct
27 };
28 
29 
30 unsigned char HIPCUD_test_cmdp_log_offset[] = {
31  0, 4, 8,
32 };
33 
34 unsigned char HIPCUD_test_cmdp_log_size[] = {
35  2, 4, 4,
36 };
37 
38 unsigned char HIPCUD_test_cmdp_ctl_offset[] = {
39  0, 4,
40 };
41 
42 unsigned char HIPCUD_test_cmdp_ctl_size[] = {
43  1, 4,
44 };
45 
49 };
50 
51 unsigned char HIPCUD_test_structsizes[] = {
52  12, 8,
53 };
54 
56  0x6c /* 'l' */ , HIPCUD_test_structsizes, HIPCUD_test_cmdp_struct
57 };
58 
59 static void test_hipcClientInit(void)
60 {
61  struct HIPC_client cl;
62  struct HIPC_client clbase;
63  struct HIPC_cl_indp indp;
64  struct HIPC_cl_dp cmdp;
65  struct HIPC_cl_dp smdp;
66  unsigned char structsizes[] = { 8 };
67 
68  indp.n_struct = 1;
69  cmdp.endian = 0x6c; /* 'l' */
70  smdp.endian = 0x6c; /* 'l' */
71  smdp.struct_size_p = structsizes;
72 
73  assert(HIPC_ERR_INV_BASE_CLIENT == hipcClientInit(&cl, NULL));
74 
75  clbase.indp_p = NULL;
76  clbase.cmdp_p = NULL;
77  clbase.smdp_p = NULL;
78  assert(HIPC_ERR_INV_BASE_CLIENT == hipcClientInit(&cl, &clbase));
79  clbase.indp_p = &indp;
80  assert(HIPC_ERR_INV_BASE_CLIENT == hipcClientInit(&cl, &clbase));
81  clbase.cmdp_p = &cmdp;
82  assert(HIPC_SUCCESS == hipcClientInit(&cl, &clbase));
84  clbase.smdp_p = &smdp;
85  assert(HIPC_SUCCESS == hipcClientInit(&cl, &clbase));
87 
88  return;
89 }
90 
91 static void msgWithStr(hipc_msg msg, unsigned char type,
92  unsigned char const hipc_errno,
93  char const *const str)
94 {
95  size_t len;
96 
97  msg[HIPC_MSGHDR_BYTE_TYPE] = type;
98  msg[HIPC_MSGHDR_BYTE_OFFSET] = hipc_errno;
100  if (NULL == str) {
101  msg[HIPC_MSGHDR_BYTE_BDYSZ] = 0;
102  } else {
103  len = strlen(str);
104  if (255 > len) {
105  msg[HIPC_MSGHDR_BYTE_BDYSZ] = len + 1;
106  } else {
107  msg[HIPC_MSGHDR_BYTE_BDYSZ] = 255;
108  }
109  memcpy(&msg[HIPC_MSGHDR_SIZE], str, msg[HIPC_MSGHDR_BYTE_BDYSZ]);
110  }
111  return;
112 }
113 
114 static void test_hipcClientFeedSysmsg(void)
115 {
116  hipc_msg msg_ov; /* overview */
117  hipc_msg msg_os; /* offset */
118  hipc_msg msg_sz; /* size */
119  struct HIPC_client cl;
120  struct HIPC_client clbase;
121  struct HIPC_cl_dp cmdp;
122 
123  clbase.indp_p = &HIPCUD_test_indp;
124  clbase.cmdp_p = &cmdp;
125  clbase.smdp_p = NULL;
126 
127  assert(HIPC_SUCCESS == hipcClientInit(&cl, &clbase));
130  hipcClientFeedSysmsg(&cl, msg_ov));
132  hipcClientTerminate(&cl);
133 
134  assert(HIPC_SUCCESS == hipcClientInit(&cl, &clbase));
136  msg_ov[HIPC_MSGHDR_BYTE_OFFSET] = 0xFF;
138  hipcClientFeedSysmsg(&cl, msg_ov));
139  hipcClientTerminate(&cl);
140 
141  assert(HIPC_SUCCESS == hipcClientInit(&cl, &clbase));
143  msg_ov[HIPC_MSGHDR_BYTE_STRUNO] = 0x6f; /* 'o' */
144  msg_ov[HIPC_MSGHDR_BYTE_BDYSZ] = 0;
145  assert(HIPC_ERR_INV_ENDIAN == hipcClientFeedSysmsg(&cl, msg_ov));
146  hipcClientTerminate(&cl);
147 
148  assert(HIPC_SUCCESS == hipcClientInit(&cl, &clbase));
149  msg_ov[HIPC_MSGHDR_BYTE_STRUNO] = 0x6c; /* 'l' */
151  hipcClientFeedSysmsg(&cl, msg_ov));
152  hipcClientTerminate(&cl);
153 
154  assert(HIPC_SUCCESS == hipcClientInit(&cl, &clbase));
155  msg_ov[HIPC_MSGHDR_BYTE_BDYSZ] = 2;
156  msg_ov[HIPC_MSGHDR_SIZE] = 12;
157  msg_ov[HIPC_MSGHDR_SIZE + 1] = 8;
158  assert(HIPC_SUCCESS == hipcClientFeedSysmsg(&cl, msg_ov));
159  assert(12 == cl.smdp_p->struct_size_p[0]);
160  assert(8 == cl.smdp_p->struct_size_p[1]);
161  hipcClientTerminate(&cl);
162 
163  msg_ov[HIPC_MSGHDR_BYTE_STRUNO] = 0x42; /* 'B' */
164  assert(HIPC_SUCCESS == hipcClientInit(&cl, &clbase));
165  assert(HIPC_SUCCESS == hipcClientFeedSysmsg(&cl, msg_ov));
166  assert(12 == cl.smdp_p->struct_size_p[0]);
167  assert(8 == cl.smdp_p->struct_size_p[1]);
170  msg_os[HIPC_MSGHDR_BYTE_STRUNO] = 1;
171  msg_os[HIPC_MSGHDR_BYTE_BDYSZ] = 2;
172  msg_os[HIPC_MSGHDR_SIZE] = 0;
173  msg_os[HIPC_MSGHDR_SIZE + 1] = 4;
174  assert(HIPC_SUCCESS == hipcClientFeedSysmsg(&cl, msg_os));
175  assert(0 == cl.smdp_p->struct_p[1].offset_p[0]);
176  assert(4 == cl.smdp_p->struct_p[1].offset_p[1]);
179  msg_sz[HIPC_MSGHDR_BYTE_STRUNO] = 1;
180  msg_sz[HIPC_MSGHDR_BYTE_BDYSZ] = 2;
181  msg_sz[HIPC_MSGHDR_SIZE] = 1;
182  msg_sz[HIPC_MSGHDR_SIZE + 1] = 4;
183  assert(HIPC_SUCCESS == hipcClientFeedSysmsg(&cl, msg_sz));
184  assert(1 == cl.smdp_p->struct_p[1].size_p[0]);
185  assert(4 == cl.smdp_p->struct_p[1].size_p[1]);
187  hipcClientFeedSysmsg(&cl, msg_sz));
188  hipcClientTerminate(&cl);
189 
190  assert(HIPC_SUCCESS == hipcClientInit(&cl, &clbase));
193  msg_os[HIPC_MSGHDR_BYTE_STRUNO] = 99;
194  msg_os[HIPC_MSGHDR_BYTE_BDYSZ] = 2;
196  hipcClientFeedSysmsg(&cl, msg_os));
197  msg_os[HIPC_MSGHDR_BYTE_STRUNO] = 1;
198  msg_os[HIPC_MSGHDR_BYTE_BDYSZ] = 1;
200  hipcClientFeedSysmsg(&cl, msg_os));
201 
202  return;
203 }
204 
205 static enum HIPC_errno setupTestClient(struct HIPC_client *const cl_p)
206 {
207  struct HIPC_client clbase;
208 
209  clbase.indp_p = &HIPCUD_test_indp;
210  clbase.cmdp_p = &HIPCUD_test_cmdp;
211  clbase.smdp_p = clbase.cmdp_p;
212  assert(HIPC_SUCCESS == hipcClientInit(cl_p, &clbase));
213 
214  return HIPC_SUCCESS;
215 }
216 
217 static void test_hipcClientFeedStrumsg(void)
218 {
219  hipc_msg tmpmsg;
220  struct HIPC_client cl;
221 
222  assert(HIPC_SUCCESS == setupTestClient(&cl));
225  hipcClientFeedStrumsg(&cl, tmpmsg));
227  hipcClientTerminate(&cl);
228 
230  tmpmsg[HIPC_MSGHDR_BYTE_OFFSET] = 0;
231  tmpmsg[HIPC_MSGHDR_BYTE_STRUNO] = 1;
232  tmpmsg[HIPC_MSGHDR_BYTE_BDYSZ] = 1;
233  tmpmsg[HIPC_MSGHDR_SIZE] = 7;
234  assert(HIPC_SUCCESS == setupTestClient(&cl));
235  assert(HIPC_SUCCESS == hipcClientFeedStrumsg(&cl, tmpmsg));
236  assert(7 == cl.simg_pp[1][0]);
237  hipcClientTerminate(&cl);
238 
239  tmpmsg[HIPC_MSGHDR_BYTE_STRUNO] = 0xff;
240  assert(HIPC_SUCCESS == setupTestClient(&cl));
242  hipcClientFeedStrumsg(&cl, tmpmsg));
243  hipcClientTerminate(&cl);
244 
246  tmpmsg[HIPC_MSGHDR_BYTE_OFFSET] = 0;
247  tmpmsg[HIPC_MSGHDR_BYTE_STRUNO] = 0;
248  tmpmsg[HIPC_MSGHDR_BYTE_BDYSZ] = 1;
249  tmpmsg[HIPC_MSGHDR_SIZE] = 5;
250  assert(HIPC_SUCCESS == setupTestClient(&cl));
251  assert(HIPC_SUCCESS == hipcClientFeedStrumsg(&cl, tmpmsg));
252  assert(5 == cl.simg_pp[0][0]);
253  hipcClientTerminate(&cl);
254 
255  tmpmsg[HIPC_MSGHDR_BYTE_OFFSET] = 0xff;
256  assert(HIPC_SUCCESS == setupTestClient(&cl));
258  hipcClientFeedStrumsg(&cl, tmpmsg));
259  hipcClientTerminate(&cl);
260 
261  return;
262 }
263 
265 {
266  hipc_msg tmpmsg;
267  struct HIPC_client cl;
268 
269  assert(HIPC_SUCCESS == setupTestClient(&cl));
271  "abc");
272  assert(HIPC_ERR_S_INV_STRUNO ==
273  hipcClientFeedUnstrumsgAsError(&cl, tmpmsg));
274  assert(HIPC_ERR_S_INV_STRUNO == cl.hipc_errno);
275  assert(0 == memcmp("abc", cl.err_detail_str, 4));
276  hipcClientTerminate(&cl);
277 
278  assert(HIPC_SUCCESS == setupTestClient(&cl));
279  tmpmsg[HIPC_MSGHDR_BYTE_STRUNO] = 0;
281  hipcClientFeedUnstrumsgAsError(&cl, tmpmsg));
283  hipcClientTerminate(&cl);
284 
285  return;
286 }
287 
288 static void test_hipcClientGetNsysmsg(void)
289 {
290  struct HIPC_client cl;
291 
292  assert(HIPC_SUCCESS == setupTestClient(&cl));
293  assert(5 == hipcClientGetNsysmsg(&cl));
294 
295  return;
296 }
297 
298 int main(int argc, char *argv[])
299 {
300  if (2 != argc) {
301  fprintf(stderr, "Usage: %s test_id\n", argv[0]);
302  exit(EXIT_FAILURE);
303  }
304 
305  switch (argv[1][0]) {
306  case 'a':
308  break;
309  case 'b':
311  break;
312  case 'c':
314  break;
315  case 'd':
317  break;
318  case 'e':
320  break;
321  default:
322  fprintf(stderr, "Invalid test_id: %s \n", argv[1]);
323  exit(EXIT_FAILURE);
324  }
325 
326  return 0;
327 }
enum HIPC_errno hipcClientFeedStrumsg(struct HIPC_client *const cl_p, const hipc_msg msgR)
Feeds a message and incorporates it to the internal data of a client.
Definition: client.c:1174
Machine-dependent information of a structure used in a client.
Definition: client.h:55
unsigned char hipc_msg[HIPC_MSG_ALLOCSIZE]
Definition: msg.h:8
Machine-independent information of a member of a structure used in a client.
Definition: client.h:18
Machine-independent information of a client.
Definition: client.h:44
enum HIPC_errno hipcClientFeedUnstrumsgAsError(struct HIPC_client *const cl_p, const hipc_msg msgR)
Feeds a message and sets an error specified by the message.
Definition: client.c:1011
enum HIPC_errno hipcClientFeedSysmsg(struct HIPC_client *const cl_p, const hipc_msg msgR)
Feeds a system message and incorporates it to the internal data of the client.
Definition: client.c:1087
struct HIPC_cl_dp * cmdp_p
Client Machine DePendent data.
Definition: client.h:77
static void test_hipcClientFeedStrumsg(void)
Definition: test_client.c:217
char err_detail_str[HIPC_IMG_ALLOCSIZE]
Definition: client.h:86
static void msgWithStr(hipc_msg msg, unsigned char type, unsigned char const hipc_errno, char const *const str)
Definition: test_client.c:91
void hipcClientTerminate(struct HIPC_client *const cl_p)
Terminates a HIPC client with releasing the memory space that the client has.
Definition: client.c:438
int main(int argc, char *argv[])
Definition: test_client.c:298
unsigned char hipcClientGetNsysmsg(struct HIPC_client const *const cl_p)
Gets the number of system messages.
Definition: client.c:326
HIPC_errno
Definition: hipc.h:4
unsigned char HIPCUD_test_cmdp_log_size[]
Definition: test_client.c:34
Machine-independent information of a structure used in a client.
Definition: client.h:35
const struct HIPC_cl_indp_mbr HIPCUD_test_indp_member_log[]
Definition: test_client.c:9
const struct HIPC_cl_indp_stru HIPCUD_test_indp_struct[]
Definition: test_client.c:20
static enum HIPC_errno setupTestClient(struct HIPC_client *const cl_p)
Definition: test_client.c:205
unsigned char HIPCUD_test_structsizes[]
Definition: test_client.c:51
static void test_hipcClientFeedUnstrumsgAsError(void)
Definition: test_client.c:264
unsigned int n_struct
Definition: client.h:48
unsigned char const * struct_size_p
Definition: client.h:65
static void test_hipcClientFeedSysmsg(void)
Definition: test_client.c:114
unsigned char HIPCUD_test_cmdp_ctl_offset[]
Definition: test_client.c:38
unsigned char HIPCUD_test_cmdp_log_offset[]
Definition: test_client.c:30
enum HIPC_errno hipc_errno
Definition: client.h:85
const struct HIPC_cl_indp HIPCUD_test_indp
Definition: test_client.c:25
unsigned char endian
Definition: client.h:64
enum HIPC_errno hipcClientInit(struct HIPC_client *const cl_p, struct HIPC_client const *const clbase_p)
Initializes a HIPC client with allocating memory space if necessary.
Definition: client.c:339
const struct HIPC_cl_indp_mbr HIPCUD_test_indp_member_ctl[]
Definition: test_client.c:15
unsigned char ** simg_pp
Server-side images of structures.
Definition: client.h:79
struct HIPC_cl_indp const * indp_p
Definition: client.h:76
Machine-dependent information of a client.
Definition: client.h:63
static void test_hipcClientGetNsysmsg(void)
Definition: test_client.c:288
struct HIPC_cl_dp_stru * struct_p
Definition: client.h:66
struct HIPC_cl_dp * smdp_p
Server Machine DePendent data.
Definition: client.h:78
#define HIPC_UNSTRU
Definition: hipc.h:44
static void test_hipcClientInit(void)
Definition: test_client.c:59
unsigned char * size_p
Definition: client.h:57
unsigned char * offset_p
Definition: client.h:56
struct HIPC_cl_dp_stru HIPCUD_test_cmdp_struct[]
Definition: test_client.c:46
unsigned char HIPCUD_test_cmdp_ctl_size[]
Definition: test_client.c:42
struct HIPC_cl_dp HIPCUD_test_cmdp
Definition: test_client.c:55