HIPC  0.5
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
test_msg.c
Go to the documentation of this file.
1 #include <assert.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 
5 #include <hipc/msg.h>
6 
7 static void test_msg_basics(void)
8 {
9  assert(HIPC_MSG_ALLOCSIZE == sizeof(hipc_msg));
10  return;
11 }
12 
13 static void test_msg_sizes(void)
14 {
15  hipc_msg msg;
16 
18  msg[HIPC_MSGHDR_BYTE_BDYSZ] = 0;
19  assert(0 == hipcMsgRngsize(msg));
20  assert(0 == hipcMsgBdySize(msg));
21  assert(HIPC_MSGHDR_SIZE == hipcMsgTotalSize(msg));
22 
24  msg[HIPC_MSGHDR_BYTE_BDYSZ] = 3;
25  assert(3 == hipcMsgRngsize(msg));
26  assert(0 == hipcMsgBdySize(msg));
27  assert(HIPC_MSGHDR_SIZE == hipcMsgTotalSize(msg));
28 
30  msg[HIPC_MSGHDR_BYTE_BDYSZ] = 255;
31  assert(255 == hipcMsgRngsize(msg));
32  assert(0 == hipcMsgBdySize(msg));
33  assert(HIPC_MSGHDR_SIZE == hipcMsgTotalSize(msg));
34 
36  msg[HIPC_MSGHDR_BYTE_BDYSZ] = 0;
37  assert(0 == hipcMsgRngsize(msg));
38  assert(0 == hipcMsgBdySize(msg));
39  assert(HIPC_MSGHDR_SIZE == hipcMsgTotalSize(msg));
40 
42  msg[HIPC_MSGHDR_BYTE_BDYSZ] = 3;
43  assert(3 == hipcMsgRngsize(msg));
44  assert(3 == hipcMsgBdySize(msg));
45  assert((3 + HIPC_MSGHDR_SIZE) == hipcMsgTotalSize(msg));
46 
48  msg[HIPC_MSGHDR_BYTE_BDYSZ] = 255;
49  assert(255 == hipcMsgRngsize(msg));
50  assert(255 == hipcMsgBdySize(msg));
51  assert((255 + HIPC_MSGHDR_SIZE) == hipcMsgTotalSize(msg));
52 
54  msg[HIPC_MSGHDR_BYTE_BDYSZ] = 5;
55  assert(5 == hipcMsgRngsize(msg));
56  assert(5 == hipcMsgBdySize(msg));
57  assert((5 + HIPC_MSGHDR_SIZE) == hipcMsgTotalSize(msg));
58 
59  msg[HIPC_MSGHDR_BYTE_TYPE] = 100;
60  msg[HIPC_MSGHDR_BYTE_BDYSZ] = 7;
61  assert(7 == hipcMsgRngsize(msg));
62  assert(7 == hipcMsgBdySize(msg));
63  assert((7 + HIPC_MSGHDR_SIZE) == hipcMsgTotalSize(msg));
64 
65  return;
66 }
67 
68 static void test_hipcMsgType(void)
69 {
70  hipc_msg msg;
71 
72  msg[HIPC_MSGHDR_BYTE_TYPE] = 11;
73  assert(11 == hipcMsgType(msg));
74 
75  return;
76 }
77 
78 static void test_hipcMsgStruno(void)
79 {
80  hipc_msg msg;
81 
82  msg[HIPC_MSGHDR_BYTE_STRUNO] = 127;
83  assert(127 == hipcMsgStruno(msg));
84 
85  return;
86 }
87 
88 static void test_hipcMsgOffset(void)
89 {
90  hipc_msg msg;
91 
92  msg[HIPC_MSGHDR_BYTE_OFFSET] = 8;
93  assert(8 == hipcMsgOffset(msg));
94 
95  return;
96 }
97 
98 static void test_hipcMsgBdyPtr(void)
99 {
100  hipc_msg msg;
101 
102  msg[HIPC_MSGHDR_SIZE] = 0;
103  assert(0 == *(unsigned char *) hipcMsgBdyPtr(msg));
104 
105  msg[HIPC_MSGHDR_SIZE] = 19;
106  assert(19 == *(unsigned char *) hipcMsgBdyPtr(msg));
107 
108  return;
109 }
110 
111 int main(int argc, char *argv[])
112 {
113  if (2 != argc) {
114  fprintf(stderr, "Usage: %s test_id\n", argv[0]);
115  exit(EXIT_FAILURE);
116  }
117 
118  switch (argv[1][0]) {
119  case 'a':
120  test_msg_basics();
121  break;
122  case 'b':
123  test_msg_sizes();
124  break;
125  case 'c':
127  break;
128  case 'd':
130  break;
131  case 'e':
133  break;
134  case 'f':
136  break;
137  default:
138  fprintf(stderr, "Invalid test_id: %s \n", argv[1]);
139  exit(EXIT_FAILURE);
140  }
141 
142  return 0;
143 }
int main(int argc, char *argv[])
Definition: test_msg.c:111
unsigned char hipc_msg[HIPC_MSG_ALLOCSIZE]
Definition: msg.h:8
static void test_msg_basics(void)
Definition: test_msg.c:7
size_t hipcMsgTotalSize(const hipc_msg msg)
Returns total size of a HIPC message, which is the header size plus the body size.
Definition: msg.c:9
static void test_hipcMsgOffset(void)
Definition: test_msg.c:88
static void test_hipcMsgStruno(void)
Definition: test_msg.c:78
unsigned char hipcMsgOffset(const hipc_msg msg)
Returns offset of a HIPC message.
Definition: msg.c:53
static void test_hipcMsgBdyPtr(void)
Definition: test_msg.c:98
unsigned char hipcMsgBdySize(const hipc_msg msg)
Returns body size of a HIPC message.
Definition: msg.c:20
static void test_msg_sizes(void)
Definition: test_msg.c:13
#define HIPC_MSG_ALLOCSIZE
Definition: hipc.h:47
static void test_hipcMsgType(void)
Definition: test_msg.c:68
unsigned char hipcMsgStruno(const hipc_msg msg)
Returns structure number of a HIPC message.
Definition: msg.c:64
unsigned char hipcMsgType(const hipc_msg msg)
Returns type of a HIPC message.
Definition: msg.c:42
unsigned char hipcMsgRngsize(const hipc_msg msg)
Returns range size of a HIPC message.
Definition: msg.c:75
const void * hipcMsgBdyPtr(const hipc_msg msg)
Returns a pointer to a body of a HIPC message.
Definition: msg.c:31