iotivity 0.9.0
[platform/upstream/iotivity.git] / service / protocol-plugin / lib / cpluff / test / collections.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
27 void nocollections(void) {
28         cp_context_t *ctx;
29         cp_plugin_info_t **plugins;
30         cp_status_t status;
31         int errors;
32         int i;
33         
34         ctx = init_context(CP_LOG_ERROR, &errors);
35         check(cp_scan_plugins(ctx, 0) == CP_OK);
36         check((plugins = cp_get_plugins_info(ctx, &status, &i)) != NULL && status == CP_OK && i == 0);
37         cp_release_info(ctx, plugins);
38         cp_destroy();
39         check(errors == 0);
40 }
41
42 void onecollection(void) {
43         cp_context_t *ctx;
44         int errors;
45         
46         ctx = init_context(CP_LOG_ERROR, &errors);
47         check(cp_register_pcollection(ctx, pcollectiondir("collection1")) == CP_OK);
48         check(cp_scan_plugins(ctx, 0) == CP_OK);
49         check(cp_get_plugin_state(ctx, "plugin1") == CP_PLUGIN_INSTALLED);
50         cp_destroy();
51         check(errors == 0);
52 }
53
54 void twocollections(void) {
55         cp_context_t *ctx;
56         int errors;
57         
58         ctx = init_context(CP_LOG_ERROR, &errors);
59         check(cp_register_pcollection(ctx, pcollectiondir("collection1")) == CP_OK);
60         check(cp_register_pcollection(ctx, pcollectiondir("collection2")) == CP_OK);
61         check(cp_scan_plugins(ctx, 0) == CP_OK);
62         check(cp_get_plugin_state(ctx, "plugin1") == CP_PLUGIN_INSTALLED);
63         check(cp_get_plugin_state(ctx, "plugin2a") == CP_PLUGIN_INSTALLED);
64         check(cp_get_plugin_state(ctx, "plugin2b") == CP_PLUGIN_INSTALLED);
65         cp_destroy();
66         check(errors == 0);
67 }
68
69 void unregcollection(void) {
70         cp_context_t *ctx;
71         int errors;
72         
73         ctx = init_context(CP_LOG_ERROR, &errors);
74         check(cp_register_pcollection(ctx, pcollectiondir("collection1")) == CP_OK);
75         check(cp_register_pcollection(ctx, pcollectiondir("collection2")) == CP_OK);
76         cp_unregister_pcollection(ctx, pcollectiondir("collection2"));
77         check(cp_scan_plugins(ctx, 0) == CP_OK);
78         check(cp_get_plugin_state(ctx, "plugin1") == CP_PLUGIN_INSTALLED);
79         check(cp_get_plugin_state(ctx, "plugin2a") == CP_PLUGIN_UNINSTALLED);
80         check(cp_get_plugin_state(ctx, "plugin2b") == CP_PLUGIN_UNINSTALLED);
81         cp_destroy();
82         check(errors == 0);
83 }
84
85 void unregcollections(void) {
86         cp_context_t *ctx;
87         int errors;
88         
89         ctx = init_context(CP_LOG_ERROR, &errors);
90         check(cp_register_pcollection(ctx, pcollectiondir("collection1")) == CP_OK);
91         check(cp_register_pcollection(ctx, pcollectiondir("collection2")) == CP_OK);
92         cp_unregister_pcollections(ctx);
93         check(cp_scan_plugins(ctx, 0) == CP_OK);
94         check(cp_get_plugin_state(ctx, "plugin1") == CP_PLUGIN_UNINSTALLED);
95         check(cp_get_plugin_state(ctx, "plugin2a") == CP_PLUGIN_UNINSTALLED);
96         check(cp_get_plugin_state(ctx, "plugin2b") == CP_PLUGIN_UNINSTALLED);
97         cp_destroy();
98         check(errors == 0);
99 }