1 #include "test.h"
2 #include "../src/alloc.h"
3 #include "../src/cntr.h"
4
do_test_extract_client_pid_bno(char * buf,const char * expected_cname,int expected_pid,int expected_bno)5 static void do_test_extract_client_pid_bno(char *buf,
6 const char *expected_cname, int expected_pid, int expected_bno)
7 {
8 int bno=0;
9 int pid=-1;
10 char b[32]="";
11 char *cname=NULL;
12 snprintf(b, sizeof(b), "%s", buf);
13 fail_unless(!extract_client_pid_bno(b, &cname, &pid, &bno));
14 fail_unless(!strcmp(cname, expected_cname));
15 fail_unless(pid==expected_pid);
16 fail_unless(pid==expected_bno);
17 free_w(&cname);
18 alloc_check();
19 }
20
START_TEST(test_extract_client_pid_bno)21 START_TEST(test_extract_client_pid_bno)
22 {
23 do_test_extract_client_pid_bno("", "", -1, 0);
24 do_test_extract_client_pid_bno("cliX.12345", "cliX", 12345, 0);
25 do_test_extract_client_pid_bno("cliX.12345\tblah", "cliX", 12345, 0);
26 do_test_extract_client_pid_bno("cliX", "cliX", -1, 0);
27 do_test_extract_client_pid_bno("cliX.12345.11", "cliX", 12345, 11);
28 do_test_extract_client_pid_bno("cliX.12345.11\t", "cliX", 12345, 11);
29 }
30 END_TEST
31
suite_cntr(void)32 Suite *suite_cntr(void)
33 {
34 Suite *s;
35 TCase *tc_core;
36
37 s=suite_create("cntr");
38
39 tc_core=tcase_create("Core");
40
41 tcase_add_test(tc_core, test_extract_client_pid_bno);
42
43 suite_add_tcase(s, tc_core);
44
45 return s;
46 }
47