HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
test_client_hndlr.c
Go to the documentation of this file.
1 #include <assert.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 
5 #include <hipc/client.h>
6 
7 /* Start of settings for a mock HIPC client */
8 struct s0 {
9  char m0;
10 };
11 struct s1 {
12  int m0;
13 };
14 
15 enum {
18 };
19 
20 const struct HIPC_cl_indp_mbr
22  {HIPC_MBR_SIMPLE, "m0"},
23 };
24 
25 const struct HIPC_cl_indp_mbr
27  {HIPC_MBR_SIMPLE, "m0"},
28 };
29 
31  = {
32  {1, "s0", HIPCUD_mock_CCFG_indp_member_s0},
33  {1, "s1", HIPCUD_mock_CCFG_indp_member_s1},
34 };
35 
37  NULL, 0, 5, 2,
39 };
40 
42  offsetof(struct s0, m0),
43 };
44 unsigned char HIPCUD_mock_CCFG_cmdp_s0_size[] = {
45  sizeof(char),
46 };
47 
49  offsetof(struct s1, m0),
50 };
51 unsigned char HIPCUD_mock_CCFG_cmdp_s1_size[] = {
52  sizeof(int),
53 };
54 
57  {HIPCUD_mock_CCFG_cmdp_s1_offset, HIPCUD_mock_CCFG_cmdp_s1_size},
58 };
59 
60 unsigned char HIPCUD_mock_CCFG_structsizes[] = {
61  sizeof(struct s0),
62  sizeof(struct s1),
63 };
65  { '\0', HIPCUD_mock_CCFG_structsizes, HIPCUD_mock_CCFG_cmdp_struct };
66 
67 const struct HIPC_client HIPCUD_mock_CCFG = {
68  0,
71  NULL,
72  NULL
73 };
74 
75 /* End of settings for a mock HIPC client */
76 
77 static struct call_log {
78  enum HIPC_errno (*hndlr_p) (struct HIPC_client *,
79  const hipc_msg, void *, void *);
80  const void *msg_p;
81  void *cimg;
82  void *arg;
83 } cllg;
84 
85 static enum HIPC_errno hndlr0(struct HIPC_client *cl_p, const hipc_msg msg,
86  void *cimg, void *arg)
87 {
89  cllg.msg_p = msg;
90  cllg.cimg = cimg;
91  cllg.arg = arg;
92 
93  return 5;
94 }
95 
96 static enum HIPC_errno hndlr1(struct HIPC_client *cl_p, const hipc_msg msg,
97  void *cimg, void *arg)
98 {
100  cllg.msg_p = msg;
101  cllg.cimg = cimg;
102  cllg.arg = arg;
103 
104  return 7;
105 }
106 
107 static void test_handler(void)
108 {
109  struct HIPC_client cl;
110  hipc_msg msg;
111  int iarg;
112  struct s1 is1;
113 
114  assert(HIPC_SUCCESS == hipcClientInit(&cl, &HIPCUD_mock_CCFG));
115  cllg.hndlr_p = NULL;
116  cllg.msg_p = NULL;
117  cllg.cimg = NULL;
118  cllg.arg = NULL;
119 
120  assert(HIPC_SUCCESS == hipcClientCallHandler(&cl, HIPCUD_s0, NULL));
121  assert(NULL == cllg.hndlr_p);
122  assert(NULL == cllg.msg_p);
123  assert(NULL == cllg.cimg);
124  assert(NULL == cllg.arg);
125  assert(HIPC_SUCCESS == hipcClientCallHandler(&cl, HIPCUD_s1, NULL));
126  assert(NULL == cllg.hndlr_p);
127  assert(NULL == cllg.msg_p);
128  assert(NULL == cllg.cimg);
129  assert(NULL == cllg.arg);
130 
132  assert(5 == hipcClientCallHandler(&cl, HIPCUD_s0, NULL));
133  assert(hndlr0 == cllg.hndlr_p);
134  assert(NULL == cllg.msg_p);
135  assert(NULL == cllg.cimg);
136  assert(NULL == cllg.arg);
137  assert(HIPC_SUCCESS == hipcClientCallHandler(&cl, HIPCUD_s1, NULL));
138  assert(hndlr0 == cllg.hndlr_p);
139  assert(NULL == cllg.msg_p);
140  assert(NULL == cllg.cimg);
141  assert(NULL == cllg.arg);
142 
143  hipcClientSetHandler(&cl, HIPCUD_s1, hndlr1, &iarg);
144  assert(5 == hipcClientCallHandler(&cl, HIPCUD_s0, msg));
145  assert(hndlr0 == cllg.hndlr_p);
146  assert(msg == cllg.msg_p);
147  assert(NULL == cllg.cimg);
148  assert(NULL == cllg.arg);
149  assert(7 == hipcClientCallHandler(&cl, HIPCUD_s1, NULL));
150  assert(hndlr1 == cllg.hndlr_p);
151  assert(NULL == cllg.msg_p);
152  assert(NULL == cllg.cimg);
153  assert(&iarg == cllg.arg);
154 
155  hipcClientSetCimg(&cl, HIPCUD_s1, &is1);
156  assert(7 == hipcClientCallHandler(&cl, HIPCUD_s1, msg));
157  assert(hndlr1 == cllg.hndlr_p);
158  assert(msg == cllg.msg_p);
159  assert(&is1 == cllg.cimg);
160  assert(&iarg == cllg.arg);
161  assert(5 == hipcClientCallHandler(&cl, HIPCUD_s0, msg));
162  assert(hndlr0 == cllg.hndlr_p);
163  assert(msg == cllg.msg_p);
164  assert(NULL == cllg.cimg);
165  assert(NULL == cllg.arg);
166 
167  return;
168 }
169 
170 int main(int argc, char *argv[])
171 {
172  if (2 != argc) {
173  fprintf(stderr, "Usage: %s test_id\n", argv[0]);
174  exit(EXIT_FAILURE);
175  }
176 
177  switch (argv[1][0]) {
178  case 'a':
179  test_handler();
180  break;
181  default:
182  fprintf(stderr, "Invalid test_id: %s \n", argv[1]);
183  exit(EXIT_FAILURE);
184  }
185 
186  return 0;
187 }
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
static struct call_log cllg
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 hipcClientCallHandler(struct HIPC_client *const cl_p, const unsigned char struno, const hipc_msg msgR)
Calls a handler that corresponds to struno.
Definition: client.c:303
char m0
HIPC_errno
Definition: hipc.h:4
Machine-independent information of a structure used in a client.
Definition: client.h:35
static void test_handler(void)
unsigned char HIPCUD_mock_CCFG_structsizes[]
unsigned char HIPCUD_mock_CCFG_cmdp_s1_offset[]
enum HIPC_errno(* hndlr_p)(struct HIPC_client *, const hipc_msg, void *, void *)
int main(int argc, char *argv[])
const struct HIPC_cl_indp_stru HIPCUD_mock_CCFG_indp_struct[]
void hipcClientSetHandler(struct HIPC_client *const cl_p, const unsigned char struno, enum HIPC_errno(*hndlr_p)(struct HIPC_client *, const hipc_msg, void *, void *), void *const arg)
Sets an handler hndlr_p to a structure number struno.
Definition: client.c:279
static enum HIPC_errno hndlr0(struct HIPC_client *cl_p, const hipc_msg msg, void *cimg, void *arg)
struct HIPC_cl_dp HIPCUD_mock_CCFG_cmdp
const struct HIPC_client HIPCUD_mock_CCFG
const struct HIPC_cl_indp_mbr HIPCUD_mock_CCFG_indp_member_s0[]
void hipcClientSetCimg(struct HIPC_client *const cl_p, const unsigned char struno, void *cimg_p)
Sets a client-side image that is a structure instance of a structure.
Definition: client.c:260
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
unsigned char HIPCUD_mock_CCFG_cmdp_s0_offset[]
static enum HIPC_errno hndlr1(struct HIPC_client *cl_p, const hipc_msg msg, void *cimg, void *arg)
unsigned char HIPCUD_mock_CCFG_cmdp_s0_size[]
Machine-dependent information of a client.
Definition: client.h:63
struct HIPC_cl_dp_stru HIPCUD_mock_CCFG_cmdp_struct[]
const struct HIPC_cl_indp_mbr HIPCUD_mock_CCFG_indp_member_s1[]
const struct HIPC_cl_indp HIPCUD_mock_CCFG_indp
unsigned char HIPCUD_mock_CCFG_cmdp_s1_size[]
const void * msg_p