1 | #include "common.h" |
2 | |
3 | #define CTEST_MAIN |
4 | #include "ctest.h" |
5 | |
6 | #include "message.h" |
7 | #include "mpack-reader.h" |
8 | #include "mpack-writer.h" |
9 | |
10 | CTEST(test_message, mpack_serialization) |
11 | { |
12 | vrtql_msg* send = vrtql_msg_new(); |
13 | vrtql_msg* receive = vrtql_msg_new(); |
14 | |
15 | vrtql_msg_set_routing(send, "key" , "value" ); |
16 | vrtql_msg_set_header(send, "key" , "value" ); |
17 | vrtql_msg_set_content(send, "content" ); |
18 | |
19 | vws_buffer* binary = vrtql_msg_serialize(send); |
20 | bool rc = vrtql_msg_deserialize(receive, binary->data, binary->size); |
21 | |
22 | if (rc == false) |
23 | { |
24 | ASSERT_FAIL(); |
25 | } |
26 | |
27 | vws_buffer_free(binary); |
28 | |
29 | char* key; char* val; |
30 | |
31 | for (size_t i = 0; i < receive->routing->used; i++) |
32 | { |
33 | key = receive->routing->array[i].key; |
34 | val = receive->routing->array[i].value.data; |
35 | |
36 | ASSERT_STR(key, "key" ); |
37 | ASSERT_STR(val, "value" ); |
38 | } |
39 | |
40 | for (size_t i = 0; i < receive->headers->used; i++) |
41 | { |
42 | key = receive->headers->array[i].key; |
43 | val = receive->headers->array[i].value.data; |
44 | |
45 | ASSERT_STR(key, "key" ); |
46 | ASSERT_STR(val, "value" ); |
47 | } |
48 | |
49 | ASSERT_STR((cstr)receive->content->data, "content" ); |
50 | |
51 | vrtql_msg_free(send); |
52 | vrtql_msg_free(receive); |
53 | } |
54 | |
55 | CTEST(test_message, json_serialization) |
56 | { |
57 | vrtql_msg* send = vrtql_msg_new(); |
58 | vrtql_msg* receive = vrtql_msg_new(); |
59 | |
60 | vrtql_msg_set_routing(send, "key" , "value" ); |
61 | vrtql_msg_set_header(send, "key" , "value" ); |
62 | vrtql_msg_set_content(send, "content" ); |
63 | |
64 | send->format = VM_MPACK_FORMAT; |
65 | vws_buffer* binary = vrtql_msg_serialize(send); |
66 | bool rc = vrtql_msg_deserialize(receive, binary->data, binary->size); |
67 | |
68 | if (rc == false) |
69 | { |
70 | ASSERT_FAIL(); |
71 | } |
72 | |
73 | vws_buffer_free(binary); |
74 | |
75 | char* key; char* val; |
76 | |
77 | for (size_t i = 0; i < receive->routing->used; i++) |
78 | { |
79 | key = receive->routing->array[i].key; |
80 | val = receive->routing->array[i].value.data; |
81 | |
82 | ASSERT_STR(key, "key" ); |
83 | ASSERT_STR(val, "value" ); |
84 | } |
85 | |
86 | for (size_t i = 0; i < receive->headers->used; i++) |
87 | { |
88 | key = receive->headers->array[i].key; |
89 | val = receive->headers->array[i].value.data; |
90 | |
91 | ASSERT_STR(key, "key" ); |
92 | ASSERT_STR(val, "value" ); |
93 | } |
94 | |
95 | ASSERT_STR((cstr)receive->content->data, "content" ); |
96 | |
97 | vrtql_msg_free(send); |
98 | vrtql_msg_free(receive); |
99 | } |
100 | |
101 | int main(int argc, const char* argv[]) |
102 | { |
103 | return ctest_main(argc, argv); |
104 | } |
105 | |