Statistics
| Branch: | Revision:

peerstreamer-src / Test / pstreamer_manager_test.c @ c039490c

History | View | Annotate | Download (2.42 KB)

1
/*
2
 *
3
 *  copyright (c) 2017 luca baldesi
4
 *
5
 */
6

    
7
#include<assert.h>
8
#include<stdlib.h>
9
#include<stdio.h>
10
#include<string.h>
11

    
12
#include"pstreamer.h"
13

    
14

    
15
void pstreamer_manager_destroy_test()
16
{
17
        struct pstreamer_manager * psm = NULL;
18

    
19
        pstreamer_manager_destroy(NULL);
20
        pstreamer_manager_destroy(&psm);
21

    
22
        psm = pstreamer_manager_new(6000);
23

    
24
        pstreamer_manager_destroy(&psm);
25

    
26
        fprintf(stderr,"%s successfully passed!\n",__func__);
27
}
28

    
29
void pstreamer_manager_create_streamer_test()
30
{
31
        struct pstreamer_manager * psm = NULL;
32
        const struct pstreamer * ps = NULL;
33

    
34
        ps = pstreamer_manager_create_streamer(NULL, NULL, NULL, NULL);
35
        assert(ps == NULL);
36

    
37
        psm = pstreamer_manager_new(6000);
38

    
39
        ps = pstreamer_manager_create_streamer(psm, NULL, NULL, NULL);
40
        assert(ps == NULL);
41

    
42
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42");
43
        assert(ps);
44

    
45
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "24");
46
        assert(ps);
47

    
48
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42");
49
        assert(ps == NULL);
50

    
51
        pstreamer_manager_destroy(&psm);
52

    
53
        fprintf(stderr,"%s successfully passed!\n",__func__);
54
}
55

    
56
void pstreamer_to_json_test()
57
{
58
        struct pstreamer_manager * psm = NULL;
59
        const struct pstreamer * ps = NULL;
60
        char * json = NULL;
61

    
62
        json = pstreamer_to_json(NULL);
63
        assert(json == NULL);
64

    
65
        psm = pstreamer_manager_new(6000);
66
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42");
67

    
68
        json = pstreamer_to_json(ps);
69
        assert(strcmp(json, "{\"id\":\"42\",\"source_ip\":\"10.0.0.1\",\"source_port\":\"6000\"}") == 0);
70
        free(json);
71

    
72
        pstreamer_manager_destroy(&psm);
73
        fprintf(stderr,"%s successfully passed!\n",__func__);
74
}
75

    
76
void pstreamer_manager_destroy_streamer_test()
77
{
78
        struct pstreamer_manager * psm = NULL;
79
        const struct pstreamer * ps = NULL;
80
        uint8_t res;
81

    
82
        res = pstreamer_manager_destroy_streamer(NULL, NULL);
83
        assert(res);
84

    
85
        psm = pstreamer_manager_new(6000);
86
        res = pstreamer_manager_destroy_streamer(psm, NULL);
87
        assert(res);
88

    
89
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42");
90
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "24");
91

    
92
        res = pstreamer_manager_destroy_streamer(psm, ps);
93
        assert(res == 0);
94

    
95
        pstreamer_manager_destroy(&psm);
96

    
97
        fprintf(stderr,"%s successfully passed!\n",__func__);
98
}
99

    
100
int main(int argv, char ** argc)
101
{
102
        pstreamer_manager_destroy_test();
103
        pstreamer_manager_create_streamer_test();
104
        pstreamer_to_json_test();
105
        pstreamer_manager_destroy_streamer_test();
106
        return 0;
107
}