Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / test / t_unsubscribe.c @ master

History | View | Annotate | Download (2.46 KB)

1
/* 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
        gdp_gin_t *gin;
18
        gdp_name_t gobname;
19
        gdp_datum_t *d;
20
        EP_STAT estat;
21
        int opt;
22
        char *gobxname = "x00";
23
        bool test_wildcard = false;
24
        int pausesec = 1;
25

    
26
        while ((opt = getopt(argc, argv, "D:p:w")) > 0)
27
        {
28
                switch (opt)
29
                {
30
                  case 'D':
31
                        ep_dbg_set(optarg);
32
                        break;
33

    
34
                  case 'p':
35
                        pausesec = atoi(optarg);
36
                        break;
37

    
38
                  case 'w':
39
                        test_wildcard = true;
40
                        break;
41
                }
42
        }
43
        argc -= optind;
44
        argv += optind;
45

    
46
        if (argc > 0)
47
                gobxname = argv[0];
48

    
49
        estat = gdp_init(NULL);
50
        test_message(estat, "gdp_init");
51

    
52
        ep_time_nanosleep(100 MILLISECONDS);
53

    
54
        estat = gdp_parse_name(gobxname, gobname);
55
        test_message(estat, "gdp_parse_name");
56

    
57
        estat = gdp_gin_open(gobname, GDP_MODE_RA, NULL, &gin);
58
        test_message(estat, "gdp_gin_open");
59

    
60
        estat = gdp_gin_subscribe_by_recno(gin, 0, 0, NULL, print_event, (void *) 1);
61
        test_message(estat, "gdp_ubscribe");
62
        ep_app_info("You should see subscription results");
63

    
64
        d = gdp_datum_new();
65
        gdp_buf_printf(gdp_datum_getbuf(d), "one");
66
        estat = gdp_gin_append(gin, d, NULL);
67
        test_message(estat, "gdp_gin_append1");
68
        gdp_buf_reset(gdp_datum_getbuf(d));
69
        ep_app_info("sleeping1");
70
        ep_time_nanosleep(pausesec SECONDS);
71

    
72

    
73
        // use different cbarg: subscription should persist
74
        estat = gdp_gin_unsubscribe(gin, NULL, (void *) 2);
75
        test_message(estat, "gdp_gin_unsubscribe1");
76

    
77
        gdp_buf_printf(gdp_datum_getbuf(d), "two");
78
        estat = gdp_gin_append(gin, d, NULL);
79
        test_message(estat, "gdp_gin_append2");
80
        ep_app_info("sleeping2");
81
        ep_time_nanosleep(pausesec SECONDS);
82

    
83
        if (test_wildcard)
84
        {
85
                // use wildcard cbarg: subscription should go away
86
                estat = gdp_gin_unsubscribe(gin, NULL, NULL);
87
                test_message(estat, "gdp_gin_unsubscribe3");
88
        }
89
        else
90
        {
91
                // use correct cbarg: subscription should go away
92
                estat = gdp_gin_unsubscribe(gin, NULL, (void *) 1);
93
                test_message(estat, "gdp_gin_unsubscribe2");
94
        }
95

    
96
        ep_app_info("Subscription should be gone");
97

    
98
        gdp_buf_printf(gdp_datum_getbuf(d), "three");
99
        estat = gdp_gin_append(gin, d, NULL);
100
        test_message(estat, "gdp_gin_append3");
101
        ep_app_info("sleeping3");
102
        ep_time_nanosleep(pausesec SECONDS);
103

    
104
        ep_app_info("closing");
105
        estat = gdp_gin_close(gin);
106
        test_message(estat, "gdp_gin_close");
107

    
108
        return 0;
109
}