53 char buf[512] =
"\nWROTE:\n\n";
58 unsigned int one, two;
60 two = 0xff & should[i];
61 sprintf(buf + strlen(buf),
" %02x%c=%02x", one,
62 (one == two ?
'=' :
'!'), two);
63 if (one != two) found =1;
65 if (found) ck_abort_msg(buf);
69 char buf[512] =
"\nREAD\n\n";
74 unsigned int one, two;
76 two = 0xff & should[i];
77 sprintf(buf + strlen(buf),
" %02x%c=%02x", one,
78 (one == two ?
'=' :
'!'), two);
79 if (one != two) found =1;
81 if (found) ck_abort_msg(buf);
88 const static char scanfornodes_query[] = {0x07,0x00,0x00,0x13,0x01,0x00,0x00,0x00,0x01 };
93 const static char scanfornodes_answer[] = {
94 0x33, 0x00, 0x01, 0x13, 0x01, 0x00, 0x00, 0x00,
95 0x00, 0x01, 0x00, 0x55, 0xaa,
96 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
97 0x02, 0x01, 0x02, 0x03, 0x07,
98 0x02, 0xcd, 0xab, 0x00, 0x64, 0x8e,
99 0x0a, 0xf0, 0xf1, 0xf2, 0xf3, 0x4c, 0x69, 0x63,
100 0x68, 0x74, 0x20, 0x30, 0x31, 0x00, 0x00, 0x00,
101 0x00, 0x00, 0x00, 0x00, 0x00
105 const static char turnonlight_query_broadcast[] = {
106 0x0f, 0x00, 0x00, 0x32, 0x02, 0x00, 0x00, 0x00,
107 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
111 const static char turnonlight_answer_broadcast[] = {
112 0x12, 0x00, 0x01, 0x32, 0x02, 0x00, 0x00, 0x00,
114 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
118 const static char turnofflight_query_broadcast[] = {
119 0x0f, 0x00, 0x00, 0x32, 0x04, 0x00, 0x00, 0x00,
120 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
124 const static char turnofflight_answer_broadcast[] = {
125 0x12, 0x00, 0x01, 0x32, 0x04, 0x00, 0x00, 0x00,
127 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
131 const static char turnonlight2_query_broadcast[] = {
132 0x0f, 0x00, 0x00, 0x32, 0x05, 0x00, 0x00, 0x00,
133 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
137 const static char turnonlight2_answer_broadcast[] = {
138 0x12, 0x00, 0x01, 0x32, 0x05, 0x00, 0x00, 0x00,
140 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
145 const static char turnonlight_query_node[] = {
146 0x0f, 0x00, 0x00, 0x32, 0x03, 0x00, 0x00, 0x00,
147 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
151 const static char turnonlight_answer_node[] = {
152 0x12, 0x00, 0x01, 0x32, 0x03, 0x00, 0x00, 0x00,
154 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
159 const static char changecct_query_node[] = {
160 0x12, 0x00, 0x00, 0x33, 0x06, 0x00, 0x00, 0x00,
161 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
162 0x8C, 0x0A, 0x0a, 0x00
165 const static char changecct_answer_node[] = {
166 0x12, 0x00, 0x01, 0x33, 0x06, 0x00, 0x00, 0x00,
168 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
172 const static char setrgbw_query_node[] = {
173 0x14, 0x00, 0x00, 0x36, 0x07, 0x00, 0x00, 0x00,
174 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
175 0x01, 0x02, 0x03, 0x04, 0x0a, 0x00
178 const static char setrgbw_answer_node[] = {
179 0x12, 0x00, 0x01, 0x36, 0x07, 0x00, 0x00, 0x00,
181 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
185 const static char setbright_query_node[] = {
186 0x11, 0x00, 0x00, 0x31, 0x08, 0x00, 0x00, 0x00,
187 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
191 const static char setbright_answer_node[] = {
192 0x12, 0x00, 0x01, 0x31, 0x08, 0x00, 0x00, 0x00,
194 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
198 const static char requpdate_query_node[] = {
199 0x0e, 0x00, 0x00, 0x68, 0x09, 0x00, 0x00, 0x00,
200 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
203 const static char requpdate_answer_node[] = {
204 0x1d, 0x00, 0x00, 0x68, 0x09, 0x00, 0x00, 0x00,
206 0x78, 0x56, 0x34, 0x12, 0xef, 0xbe, 0xad, 0xde,
208 0x02, 0x01, 0x55, 0x8C, 0x0A, 0x10, 0x11, 0x12, 0x13
212 const static char req_getgroups[] = {
213 0x07, 0x00, 0x00, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x35
216 const static char req_getgroups_answer[] = {
217 0x3f, 0x00, 0x01, 0x1e, 0x01, 0x00, 0x00, 0x00,
219 0x01, 0x00, 0x47, 0x72, 0x75, 0x70, 0x70, 0x65,
220 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222 0x02, 0x00, 0x47, 0x72, 0x75, 0x70, 0x70, 0x65,
223 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225 0x03, 0x00, 0x47, 0x72, 0x75, 0x70, 0x70, 0x65,
226 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232 printf(
"setup done\n");
238 printf(
"teardown done\n");
243 static void helper_mfs_setup_answer(
struct fake_socket *mfs,
244 const char *our_answer,
size_t answer_len) {
248 memcpy(mfs->
buf_read, our_answer, answer_len);
261 printf(
"now testing context::userdata\n");
265 printf(
"now testing context::log\n");
270 printf(
"now testing context::socket\n");
275 printf(
"now testing context::context\n");
278 printf(
"now testing context::nodes\n");
281 printf(
"now testing context::groups\n");
296 printf(
"now testing context\n");
299 ck_assert_int_eq(
err, 0);
300 ck_assert_ptr_ne(ctx, 0);
309 s = suite_create(
"liblithify_ABI");
310 tc_context = tcase_create(
"testfixture basic tests");
311 tcase_add_test(tc_context, lightify_context_object);
312 suite_add_tcase(s, tc_context);
335 ck_assert((
err < 0));
340 ck_assert_int_eq(
err, 1);
346 s = suite_create(
"liblightify");
349 tc = tcase_create(
"API_misuse");
351 tcase_add_test(tc, lightify_context_base_NULL_checks);
352 suite_add_tcase(s, tc);
354 tc = tcase_create(
"context_API_check");
355 tcase_add_test(tc, lightify_context_userdata);
356 suite_add_tcase(s, tc);
358 tc = tcase_create(
"context_skt_API_check");
359 tcase_add_test(tc, lightify_context_skt);
360 suite_add_tcase(s, tc);
371 printf(
"my_write_from_socket: size=%d, msg=%p\n", size, msg);
395 printf(
"my_read_from_socket: size=%d, msg=%p\n", size, msg);
398 if (read_size > size)
402 memcpy(msg, fs->
buf_read, read_size);
418 helper_mfs_setup_answer(mfs, scanfornodes_answer,
419 sizeof(scanfornodes_answer));
423 ck_assert_int_eq(
err, 0);
426 ck_assert_int_eq(
err, 0);
429 ck_assert_int_eq(
err, 1);
431 ck_assert_int_eq(mfs->
size_write,
sizeof(scanfornodes_query));
433 ck_assert_int_eq(
err, 0);
439 ck_assert_ptr_ne(node, NULL);
442 ck_assert_ptr_eq(node2, NULL);
446 ck_assert_ptr_ne(
name, NULL);
447 ck_assert_int_eq(strcmp(
"Licht 01",
name), 0);
451 ck_assert_int_eq(
cct, 2702);
455 ck_assert(mac == 0xdeadbeef12345678);
459 ck_assert_ptr_eq(node,node2);
463 ck_assert_ptr_eq(node2,NULL);
467 ck_assert_uint_eq(zoneadr, 0xaa55);
471 ck_assert_uint_eq(grp, 0xabcd);
477 ck_assert_int_eq(color, 0xf0);
480 ck_assert_int_eq(color, 0xf1);
483 ck_assert_int_eq(color, 0xf2);
486 ck_assert_int_eq(color, 0xf3);
491 helper_mfs_setup_answer(mfs, scanfornodes_answer,
492 sizeof(scanfornodes_answer));
495 ck_assert_int_eq(
err, -EPROTO);
499 ck_assert_ptr_eq(node, NULL);
503 ck_assert_int_eq(
err, 0);
506 ck_assert_int_eq(
err, 0);
516 s = suite_create(
"liblightify_functional_nodes");
519 tc = tcase_create(
"lightify_tst_scan_nodes");
522 tcase_add_test(tc, lightify_tst_scan_nodes);
523 suite_add_tcase(s, tc);
537 helper_mfs_setup_answer(mfs, scanfornodes_answer,
538 sizeof(scanfornodes_answer));
543 ck_assert_int_ge(
err, 0);
547 helper_mfs_setup_answer(mfs, turnonlight_answer_broadcast,
548 sizeof(turnonlight_answer_broadcast));
552 ck_assert_int_eq(
err, 0);
553 err = memcmp(mfs->
buf_write, turnonlight_query_broadcast,
555 ck_assert_int_eq(
err, 0);
558 helper_mfs_setup_answer(mfs, turnonlight_answer_node,
559 sizeof(turnonlight_answer_node));
562 ck_assert_int_eq(
err, 0);
573 unsigned int one, two;
575 two = 0xff & turnonlight_query_node[i];
576 sprintf(buf + strlen(buf),
" %02x%c=%02x", one,
577 (one == two ?
'=' :
'!'), two);
581 ck_assert_int_eq(
err, 0);
587 ck_assert_int_eq(
err, 1);
591 helper_mfs_setup_answer(mfs, turnofflight_answer_broadcast,
592 sizeof(turnofflight_answer_broadcast));
602 ck_assert_int_eq(
err, 0);
606 helper_mfs_setup_answer(mfs, turnonlight2_answer_broadcast,
607 sizeof(turnonlight2_answer_broadcast));
616 ck_assert_int_eq(
err, 1);
622 helper_mfs_setup_answer(mfs, changecct_answer_node,
623 sizeof(changecct_answer_node));
630 ck_assert_int_eq(
err, 0);
634 ck_assert_int_eq(
err, 2700);
640 helper_mfs_setup_answer(mfs, setrgbw_answer_node,
641 sizeof(setrgbw_answer_node));
648 ck_assert_int_eq(
err, 0);
652 ck_assert_int_eq(
err, 1);
654 ck_assert_int_eq(
err, 2);
656 ck_assert_int_eq(
err, 3);
658 ck_assert_int_eq(
err, 4);
663 helper_mfs_setup_answer(mfs, setbright_answer_node,
664 sizeof(setbright_answer_node));
671 ck_assert_int_eq(
err, 0);
675 ck_assert_int_eq(
err, 0x12);
680 helper_mfs_setup_answer(mfs, requpdate_answer_node,
681 sizeof(requpdate_answer_node));
687 ck_assert_int_eq(
err, 0);
705 s = suite_create(
"liblightify_functional_manipulate_node");
708 tc = tcase_create(
"liblightify_functional_manipulate_node");
711 tcase_add_test(tc, lightify_tst_manipulate_nodes);
712 suite_add_tcase(s, tc);
728 helper_mfs_setup_answer(mfs, req_getgroups_answer,
729 sizeof(req_getgroups_answer));
739 ck_assert_int_eq(
err, 3);
779 s = suite_create(
"lightify_tst_groups_basic");
782 tc = tcase_create(
"lightify_tst_groups_basic");
785 tcase_add_test(tc, lightify_tst_groups_basic);
786 suite_add_tcase(s, tc);
803 srunner_set_tap(sr,
"-");
804 srunner_set_fork_status(sr, CK_NOFORK);
805 srunner_run_all(sr, CK_VERBOSE);
806 number_failed = srunner_ntests_failed(sr);
809 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;