Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / test / t_unsubscribe.c @ master

History | View | Annotate | Download (2.46 KB)

1 9c515e64 Eric Allman
/* vim: set ai sw=4 sts=4 ts=4 : */
2
3
/*  To compile:
4
cc -I. t_unsubscribe.c -Lep -Lgdp -lgdp -lep -levent -levent_pthreads -pthread -lcrypto -lavahi-client -lavahi-common
5
*/
6
7
#include "t_common_support.h"
8
9
#include <getopt.h>
10
11
//static EP_DBG        Dbg = EP_DBG_INIT("t_unsubscribe", "Unsubscribe test");
12
13
14
int
15
main(int argc, char **argv)
16
{
17 eae1d3ec Eric Allman
        gdp_gin_t *gin;
18
        gdp_name_t gobname;
19 9c515e64 Eric Allman
        gdp_datum_t *d;
20
        EP_STAT estat;
21
        int opt;
22 eae1d3ec Eric Allman
        char *gobxname = "x00";
23 9c515e64 Eric Allman
        bool test_wildcard = false;
24 1b7c480e Eric Allman
        int pausesec = 1;
25 9c515e64 Eric Allman
26 1b7c480e Eric Allman
        while ((opt = getopt(argc, argv, "D:p:w")) > 0)
27 9c515e64 Eric Allman
        {
28
                switch (opt)
29
                {
30
                  case 'D':
31
                        ep_dbg_set(optarg);
32
                        break;
33
34 1b7c480e Eric Allman
                  case 'p':
35
                        pausesec = atoi(optarg);
36
                        break;
37
38 9c515e64 Eric Allman
                  case 'w':
39
                        test_wildcard = true;
40
                        break;
41
                }
42
        }
43
        argc -= optind;
44
        argv += optind;
45
46
        if (argc > 0)
47 eae1d3ec Eric Allman
                gobxname = argv[0];
48 9c515e64 Eric Allman
49
        estat = gdp_init(NULL);
50
        test_message(estat, "gdp_init");
51
52
        ep_time_nanosleep(100 MILLISECONDS);
53
54 eae1d3ec Eric Allman
        estat = gdp_parse_name(gobxname, gobname);
55 9c515e64 Eric Allman
        test_message(estat, "gdp_parse_name");
56
57 eae1d3ec Eric Allman
        estat = gdp_gin_open(gobname, GDP_MODE_RA, NULL, &gin);
58
        test_message(estat, "gdp_gin_open");
59 9c515e64 Eric Allman
60 eae1d3ec Eric Allman
        estat = gdp_gin_subscribe_by_recno(gin, 0, 0, NULL, print_event, (void *) 1);
61
        test_message(estat, "gdp_ubscribe");
62 9c515e64 Eric Allman
        ep_app_info("You should see subscription results");
63
64
        d = gdp_datum_new();
65
        gdp_buf_printf(gdp_datum_getbuf(d), "one");
66 eae1d3ec Eric Allman
        estat = gdp_gin_append(gin, d, NULL);
67
        test_message(estat, "gdp_gin_append1");
68 9c515e64 Eric Allman
        gdp_buf_reset(gdp_datum_getbuf(d));
69
        ep_app_info("sleeping1");
70 1b7c480e Eric Allman
        ep_time_nanosleep(pausesec SECONDS);
71
72 9c515e64 Eric Allman
73
        // use different cbarg: subscription should persist
74 eae1d3ec Eric Allman
        estat = gdp_gin_unsubscribe(gin, NULL, (void *) 2);
75
        test_message(estat, "gdp_gin_unsubscribe1");
76 9c515e64 Eric Allman
77
        gdp_buf_printf(gdp_datum_getbuf(d), "two");
78 eae1d3ec Eric Allman
        estat = gdp_gin_append(gin, d, NULL);
79
        test_message(estat, "gdp_gin_append2");
80 9c515e64 Eric Allman
        ep_app_info("sleeping2");
81 1b7c480e Eric Allman
        ep_time_nanosleep(pausesec SECONDS);
82 9c515e64 Eric Allman
83
        if (test_wildcard)
84
        {
85
                // use wildcard cbarg: subscription should go away
86 eae1d3ec Eric Allman
                estat = gdp_gin_unsubscribe(gin, NULL, NULL);
87
                test_message(estat, "gdp_gin_unsubscribe3");
88 9c515e64 Eric Allman
        }
89
        else
90
        {
91
                // use correct cbarg: subscription should go away
92 eae1d3ec Eric Allman
                estat = gdp_gin_unsubscribe(gin, NULL, (void *) 1);
93
                test_message(estat, "gdp_gin_unsubscribe2");
94 9c515e64 Eric Allman
        }
95
96
        ep_app_info("Subscription should be gone");
97
98
        gdp_buf_printf(gdp_datum_getbuf(d), "three");
99 eae1d3ec Eric Allman
        estat = gdp_gin_append(gin, d, NULL);
100
        test_message(estat, "gdp_gin_append3");
101 9c515e64 Eric Allman
        ep_app_info("sleeping3");
102 1b7c480e Eric Allman
        ep_time_nanosleep(pausesec SECONDS);
103 9c515e64 Eric Allman
104
        ep_app_info("closing");
105 eae1d3ec Eric Allman
        estat = gdp_gin_close(gin);
106
        test_message(estat, "gdp_gin_close");
107 9c515e64 Eric Allman
108
        return 0;
109
}