iotivity 0.9.0
[platform/upstream/iotivity.git] / service / protocol-plugin / lib / cpluff / test / pinstallation.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 install(void) {
28         cp_context_t *ctx;
29         cp_plugin_info_t *plugin;
30         cp_status_t status;
31         int errors;
32         
33         ctx = init_context(CP_LOG_ERROR, &errors);
34         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_UNINSTALLED);
35         check((plugin = cp_load_plugin_descriptor(ctx, plugindir("minimal"), &status)) != NULL && status == CP_OK);
36         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_UNINSTALLED);
37         check(cp_install_plugin(ctx, plugin) == CP_OK);
38         cp_release_info(ctx, plugin);
39         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_INSTALLED);      
40         cp_destroy();
41         check(errors == 0);
42 }
43
44 void installtwo(void) {
45         cp_context_t *ctx;
46         cp_plugin_info_t *plugin;
47         cp_status_t status;
48         int errors;
49         
50         ctx = init_context(CP_LOG_ERROR, &errors);
51         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_UNINSTALLED);
52         check((plugin = cp_load_plugin_descriptor(ctx, plugindir("minimal"), &status)) != NULL && status == CP_OK);
53         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_UNINSTALLED);
54         check(cp_install_plugin(ctx, plugin) == CP_OK);
55         cp_release_info(ctx, plugin);
56         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_INSTALLED);
57         check(cp_get_plugin_state(ctx, "maximal") == CP_PLUGIN_UNINSTALLED);
58         check((plugin = cp_load_plugin_descriptor(ctx, plugindir("maximal"), &status)) != NULL && status == CP_OK);
59         check(cp_get_plugin_state(ctx, "maximal") == CP_PLUGIN_UNINSTALLED);
60         check(cp_install_plugin(ctx, plugin) == CP_OK);
61         cp_release_info(ctx, plugin);           
62         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_INSTALLED);
63         check(cp_get_plugin_state(ctx, "maximal") == CP_PLUGIN_INSTALLED);
64         cp_destroy();
65         check(errors == 0);     
66 }
67
68 void installconflict(void) {
69         cp_context_t *ctx;
70         cp_plugin_info_t *plugin;
71         cp_status_t status;
72         
73         ctx = init_context(CP_LOG_ERROR + 1, NULL);
74         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_UNINSTALLED);
75         check((plugin = cp_load_plugin_descriptor(ctx, plugindir("minimal"), &status)) != NULL && status == CP_OK);
76         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_UNINSTALLED);
77         check(cp_install_plugin(ctx, plugin) == CP_OK);
78         cp_release_info(ctx, plugin);
79         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_INSTALLED);      
80         check((plugin = cp_load_plugin_descriptor(ctx, plugindir("minimal"), &status)) != NULL && status == CP_OK);
81         check(cp_install_plugin(ctx, plugin) == CP_ERR_CONFLICT);
82         cp_release_info(ctx, plugin);
83         cp_destroy();
84 }
85
86 void uninstall(void) {
87         cp_context_t *ctx;
88         cp_plugin_info_t *plugin;
89         cp_status_t status;
90         int errors;
91         
92         ctx = init_context(CP_LOG_ERROR, &errors);
93         check((plugin = cp_load_plugin_descriptor(ctx, plugindir("minimal"), &status)) != NULL && status == CP_OK);
94         check(cp_install_plugin(ctx, plugin) == CP_OK);
95         cp_release_info(ctx, plugin);
96         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_INSTALLED);
97         check(cp_uninstall_plugin(ctx, "minimal") == CP_OK);
98         check(cp_get_plugin_state(ctx, "minimal") == CP_PLUGIN_UNINSTALLED);    
99         cp_destroy();
100         check(errors == 0);     
101 }