HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
test_client_msg.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 
6 #include <hipc/client.h>
7 
8 static void test_hipcGenmsgBye(void)
9 {
10  hipc_msg msg;
11 
12  hipcGenmsgBye(msg);
14  assert(0 == msg[HIPC_MSGHDR_BYTE_OFFSET]);
15  assert(HIPC_UNSTRU == msg[HIPC_MSGHDR_BYTE_STRUNO]);
16  assert(0 == msg[HIPC_MSGHDR_BYTE_BDYSZ]);
17 
18  return;
19 }
20 
22  (unsigned char *) "id", 2, 5, 2, NULL
23 };
24 
25 unsigned char HIPCUD_tclmsg_structsizes[] = {
26  4,
27  8,
28 };
30  { '\0', HIPCUD_tclmsg_structsizes, NULL };
31 unsigned char HIPCUD_tclmsg_simg_buf0[4];
32 unsigned char HIPCUD_tclmsg_simg_buf1[8];
33 unsigned char *HIPCUD_tclmsg_simg[] = {
36 };
37 
38 const struct HIPC_client cl_msg = {
39  0,
41  NULL,
44 };
45 
46 static void test_hipcClientCheckStrutpl(void)
47 {
48  struct HIPC_client cl = cl_msg;
49 
50  /* STRUNO */
52  hipcClientCheckStrutpl(&cl, 2, 0, 0));
53  assert(HIPC_SUCCESS == hipcClientCheckStrutpl(&cl, 1, 0, 0));
54  assert(HIPC_SUCCESS == hipcClientCheckStrutpl(&cl, 0, 0, 0));
55 
56  /* INV_OFFSET */
58  hipcClientCheckStrutpl(&cl, 1, 8, 0));
59  assert(HIPC_SUCCESS == hipcClientCheckStrutpl(&cl, 1, 7, 0));
61  hipcClientCheckStrutpl(&cl, 0, 4, 0));
62  assert(HIPC_SUCCESS == hipcClientCheckStrutpl(&cl, 0, 3, 0));
63 
64  /* INV_SIZE */
66  hipcClientCheckStrutpl(&cl, 1, 0, 9));
67  assert(HIPC_SUCCESS == hipcClientCheckStrutpl(&cl, 1, 0, 8));
69  hipcClientCheckStrutpl(&cl, 0, 0, 5));
70  assert(HIPC_SUCCESS == hipcClientCheckStrutpl(&cl, 0, 0, 4));
71 
72  /* OFFSET_SIZE */
74  hipcClientCheckStrutpl(&cl, 1, 2, 7));
75  assert(HIPC_SUCCESS == hipcClientCheckStrutpl(&cl, 1, 2, 6));
77  hipcClientCheckStrutpl(&cl, 0, 1, 4));
78  assert(HIPC_SUCCESS == hipcClientCheckStrutpl(&cl, 0, 1, 3));
79 
80  return;
81 }
82 
83 static void test_hipcGenmsgGet(void)
84 {
85  struct HIPC_client cl = cl_msg;
86  hipc_msg msg;
87 
89  hipcGenmsgGet(msg, &cl, 2, 0, 0));
90 
91  assert(HIPC_SUCCESS == hipcGenmsgGet(msg, &cl, 0, 1, 2));
93  assert(0 == msg[HIPC_MSGHDR_BYTE_STRUNO]);
94  assert(1 == msg[HIPC_MSGHDR_BYTE_OFFSET]);
95  assert(2 == msg[HIPC_MSGHDR_BYTE_BDYSZ]);
96 
97  return;
98 }
99 
100 static void test_hipcGenmsgPut(void)
101 {
102  struct HIPC_client cl = cl_msg;
103  hipc_msg msg;
104 
106  hipcGenmsgPut(msg, &cl, 2, 0, 0));
107 
108  assert(HIPC_SUCCESS == hipcGenmsgPut(msg, &cl, 0, 1, 2));
110  assert(0 == msg[HIPC_MSGHDR_BYTE_STRUNO]);
111  assert(1 == msg[HIPC_MSGHDR_BYTE_OFFSET]);
112  assert(2 == msg[HIPC_MSGHDR_BYTE_BDYSZ]);
113 
114  return;
115 }
116 
117 static void test_hipcGenmsgHello(void)
118 {
119  struct HIPC_client cl = cl_msg;
120  hipc_msg msg;
121 
122  hipcGenmsgHello(msg, &cl);
124  assert(HIPC_UNSTRU == msg[HIPC_MSGHDR_BYTE_STRUNO]);
125  assert(0 == msg[HIPC_MSGHDR_BYTE_OFFSET]);
126  assert(2 == msg[HIPC_MSGHDR_BYTE_BDYSZ]);
127  assert(0 == memcmp(&msg[HIPC_MSGHDR_SIZE], "id", 2));
128 
129  return;
130 }
131 
132 int main(int argc, char *argv[])
133 {
134  if (2 != argc) {
135  fprintf(stderr, "Usage: %s test_id\n", argv[0]);
136  exit(EXIT_FAILURE);
137  }
138 
139  switch (argv[1][0]) {
140  case 'a':
142  break;
143  case 'b':
145  break;
146  case 'c':
148  break;
149  case 'd':
151  break;
152  case 'e':
154  break;
155  default:
156  fprintf(stderr, "Invalid test_id: %s \n", argv[1]);
157  exit(EXIT_FAILURE);
158  }
159 
160  return 0;
161 }
unsigned char hipc_msg[HIPC_MSG_ALLOCSIZE]
Definition: msg.h:8
Machine-independent information of a client.
Definition: client.h:44
int main(int argc, char *argv[])
static void test_hipcGenmsgBye(void)
unsigned char HIPCUD_tclmsg_simg_buf0[4]
void hipcGenmsgBye(hipc_msg msg)
Initializes a HIPC message as a BYE message.
Definition: client.c:1279
void hipcGenmsgHello(hipc_msg msg, const struct HIPC_client *const cl_p)
Generates HELLO message.
Definition: client.c:1201
const struct HIPC_client cl_msg
static void test_hipcGenmsgPut(void)
unsigned char HIPCUD_tclmsg_structsizes[]
unsigned char * HIPCUD_tclmsg_simg[]
const struct HIPC_cl_indp HIPCUD_tclmsg_indp
static void test_hipcClientCheckStrutpl(void)
unsigned char HIPCUD_tclmsg_simg_buf1[8]
Machine-dependent information of a client.
Definition: client.h:63
enum HIPC_errno hipcGenmsgPut(hipc_msg msg, struct HIPC_client *const cl_p, const unsigned char struno, const size_t offset, const size_t size)
Generates PUT message.
Definition: client.c:1253
#define HIPC_UNSTRU
Definition: hipc.h:44
static void test_hipcGenmsgHello(void)
enum HIPC_errno hipcClientCheckStrutpl(struct HIPC_client *const cl_p, const unsigned char struno, const size_t offset, const size_t rngsize)
Checks a combination of a structure number, an offset, and a size for a HIPC message.
Definition: client.c:509
struct HIPC_cl_dp HIPCUD_tclmsg_smdp
static void test_hipcGenmsgGet(void)
enum HIPC_errno hipcGenmsgGet(hipc_msg msg, struct HIPC_client *const cl_p, const unsigned char struno, const size_t offset, const size_t size)
Generates GET message.
Definition: client.c:1223