Statistics
| Branch: | Revision:

peerstreamer-src / Test / janus_instance_test.c @ c81c126e

History | View | Annotate | Download (2.7 KB)

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

    
7
#include<assert.h>
8
#include<janus_instance.h>
9
#include<mongoose.h>
10
#include<task_manager.h>
11
#include<unistd.h>
12
#include<libgen.h>
13

    
14
char janus_conf[6969];
15

    
16
void janus_instance_create_test()
17
{
18
        struct janus_instance * janus;
19
        struct task_manager * tm = NULL;
20
        struct mg_mgr * srv = NULL;
21

    
22
        janus = janus_instance_create(srv, tm, NULL);
23
        assert(janus == NULL);
24
        janus_instance_destroy(&janus);
25

    
26
        tm = task_manager_new();
27
        srv = (struct mg_mgr*) malloc(sizeof(struct mg_mgr));
28
        mg_mgr_init(srv, NULL);
29
        janus = janus_instance_create(srv, tm, NULL);
30
        assert(janus != NULL);
31

    
32
        janus_instance_destroy(&janus);
33
        task_manager_destroy(&tm);
34
        mg_mgr_free(srv);
35
        free(srv);
36

    
37
        fprintf(stderr,"%s successfully passed!\n",__func__);
38
}
39

    
40
void janus_instance_launch_test()
41
{
42
        struct janus_instance * janus = NULL;
43
        struct task_manager * tm = NULL;
44
        struct mg_mgr * srv = NULL;
45
        int8_t res;
46

    
47
        // invalid input
48
        res = janus_instance_launch(janus);
49
        assert(res);
50

    
51
        // wrong file
52
        tm = task_manager_new();
53
        srv = (struct mg_mgr*) malloc(sizeof(struct mg_mgr));
54
        mg_mgr_init(srv, NULL);
55
        janus = janus_instance_create(srv, tm, "janus_executable=/tmp/97897243xxx");
56
        assert(janus != NULL);
57
        res = janus_instance_launch(janus);
58
        assert(res);
59
        janus_instance_destroy(&janus);
60

    
61
        // common case
62
        janus = janus_instance_create(srv, tm, janus_conf);
63
        assert(janus != NULL);
64
        res = janus_instance_launch(janus);
65
        assert(res == 0);
66

    
67
        sleep(1);
68
        janus_instance_destroy(&janus);
69
        task_manager_destroy(&tm);
70
        mg_mgr_free(srv);
71
        free(srv);
72

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

    
76
void janus_instance_create_streaming_point_test()
77
{
78
        struct janus_instance * janus = NULL;
79
        struct task_manager * tm = NULL;
80
        struct mg_mgr * srv = NULL;
81
        int8_t res;
82

    
83
        // invalid input
84
        res = janus_instance_launch(janus);
85
        assert(res);
86

    
87
        // wrong file
88
        tm = task_manager_new();
89
        srv = (struct mg_mgr*) malloc(sizeof(struct mg_mgr));
90
        mg_mgr_init(srv, NULL);
91
        janus = janus_instance_create(srv, tm, janus_conf);
92
        res = janus_instance_launch(janus);
93
        assert(res == 0);
94
        sleep(1);
95

    
96
        res = janus_instance_create_streaming_point(NULL, NULL, 0, 0, NULL);
97
        assert(res);
98
        //res = janus_instance_create_streaming_point(janus, &mountpoint, 6000, 6002, NULL);
99
        // HARD to test without running mongoose..
100
        //assert(res == 0);
101
        //sleep(1);
102
        //assert(mountpoint);
103

    
104
        janus_instance_destroy(&janus);
105
        task_manager_destroy(&tm);
106
        mg_mgr_free(srv);
107
        free(srv);
108
        fprintf(stderr,"%s successfully passed!\n",__func__);
109
}
110

    
111
int main(int argv, char ** argc)
112
{
113
        sprintf(janus_conf, "janus_executable=%s/../Tools/janus/bin/janus", dirname(argc[0]));
114

    
115
        janus_instance_create_test();
116
        janus_instance_launch_test();
117
        janus_instance_create_streaming_point_test();
118
        return 0;
119
}