Statistics
| Branch: | Revision:

peerstreamer-src / Test / pstreamer_manager_test.c @ c81c126e

History | View | Annotate | Download (3.25 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, NULL);
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, NULL, NULL);
35
        assert(ps == NULL);
36

    
37
        psm = pstreamer_manager_new(6000, NULL);
38

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

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

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

    
48
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
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, NULL);
66
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
67

    
68
        json = pstreamer_to_json(ps);
69
        fprintf(stderr, "[DEBUG] %s\n", json);
70
        assert(strcmp(json, "{\"id\":\"42\",\"source_ip\":\"10.0.0.1\",\"source_port\":\"6000\",\"janus_streaming_id\":\"0\"}") == 0);
71
        free(json);
72

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

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

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

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

    
90
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
91
        ps = pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "24", "127.0.0.1", NULL);
92

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

    
96
        pstreamer_manager_destroy(&psm);
97

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

    
101
void pstreamer_manager_set_streamer_options_test()
102
{
103
        struct pstreamer_manager * psm = NULL;
104
        int8_t res;
105

    
106
        res = pstreamer_manager_set_streamer_options(psm, NULL);
107
        assert(res == -1);
108

    
109
        psm = pstreamer_manager_new(6000, NULL);
110

    
111
        res = pstreamer_manager_set_streamer_options(psm, NULL);
112
        assert(res == -1);
113

    
114
        res = pstreamer_manager_set_streamer_options(psm, "iface=lo");
115
        assert(res == 0);
116

    
117
        pstreamer_manager_create_streamer(psm, "10.0.0.1", "6000", "42", "127.0.0.1", NULL);
118
        pstreamer_manager_destroy(&psm);
119
        fprintf(stderr,"%s successfully passed!\n",__func__);
120
}
121

    
122
int main(int argv, char ** argc)
123
{
124
        pstreamer_manager_destroy_test();
125
        pstreamer_manager_create_streamer_test();
126
        pstreamer_to_json_test();
127
        pstreamer_manager_destroy_streamer_test();
128
        pstreamer_manager_set_streamer_options_test();
129
        return 0;
130
}