Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / service / protocol-plugin / lib / cpluff / test / initdestroy.c
1 /*-------------------------------------------------------------------------
2  * C-Pluff, a plug-in framework for C
3  * Copyright 2007 Johannes Lehtinen
4  * 
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *-----------------------------------------------------------------------*/
23
24 #include <stdio.h>
25 #include "test.h"
26 #include <cpluff.h>
27
28 void initdestroy(void) {
29         int i;
30         
31         for (i = 0; i < 10; i++) {
32                 check(cp_init() == CP_OK);
33                 cp_destroy();
34         }
35 }
36
37 void initcreatedestroy(void) {
38         int i;
39         
40         for (i = 0; i < 3; i++) {
41                 int errors;
42                 
43                 init_context(CP_LOG_ERROR, &errors);
44                 cp_destroy();
45                 check(errors == 0);
46         }
47 }
48
49 void initloaddestroy(void) {
50         int i;
51         
52         for (i = 0; i < 3; i++) {
53                 cp_context_t *ctx;
54                 cp_plugin_info_t *pi;
55                 cp_status_t status;
56                 const char *pdir = plugindir("minimal");
57                 int errors;
58
59                 ctx = init_context(CP_LOG_ERROR, &errors);              
60                 check((pi = cp_load_plugin_descriptor(ctx, pdir, &status)) != NULL && status == CP_OK);
61                 cp_release_info(ctx, pi);
62                 cp_destroy();
63                 check(errors == 0);
64         }
65 }
66
67 void initinstalldestroy(void) {
68         int i;
69         
70         for (i = 0; i < 3; i++) {
71                 cp_context_t *ctx;
72                 cp_plugin_info_t *pi;
73                 cp_status_t status;
74                 const char *pdir = plugindir("minimal");
75                 int errors;
76
77                 ctx = init_context(CP_LOG_ERROR, &errors);              
78                 check((pi = cp_load_plugin_descriptor(ctx, pdir, &status)) != NULL && status == CP_OK);
79                 check(cp_install_plugin(ctx, pi) == CP_OK);
80                 cp_release_info(ctx, pi);
81                 cp_destroy();
82                 check(errors == 0);
83         }
84 }
85
86 void initstartdestroy(void) {
87         int i;
88         
89         for (i = 0; i < 3; i++) {
90                 cp_context_t *ctx;
91                 cp_plugin_info_t *pi;
92                 cp_status_t status;
93                 const char *pdir = plugindir("minimal");
94                 int errors;
95                 
96                 ctx = init_context(CP_LOG_ERROR, &errors);
97                 check((pi = cp_load_plugin_descriptor(ctx, pdir, &status)) != NULL && status == CP_OK);
98                 check(cp_install_plugin(ctx, pi) == CP_OK);
99                 cp_release_info(ctx, pi);
100                 check(cp_start_plugin(ctx, "minimal") == CP_OK);
101                 cp_destroy();
102                 check(errors == 0);
103         }
104 }
105
106 void initstartdestroyboth(void) {
107         int i;
108         
109         for (i = 0; i < 3; i++) {
110                 cp_context_t *ctx;
111                 cp_plugin_info_t *pi;
112                 cp_status_t status;
113                 const char *pdir = plugindir("minimal");
114                 int errors;
115                 
116                 ctx = init_context(CP_LOG_ERROR, &errors);
117                 check((pi = cp_load_plugin_descriptor(ctx, pdir, &status)) != NULL && status == CP_OK);
118                 check(cp_install_plugin(ctx, pi) == CP_OK);
119                 cp_release_info(ctx, pi);
120                 check(cp_start_plugin(ctx, "minimal") == CP_OK);
121                 cp_destroy_context(ctx);
122                 cp_destroy();
123                 check(errors == 0);
124         }
125 }