Tizen 2.1 base
[platform/core/appfw/heynoti.git] / TC / unit / utc_ApplicationFW_heynoti_detach_handler_func.c
1 /*
2  *  heynoti
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22 #include <tet_api.h>
23 #include <heynoti.h>
24
25 static void startup(void);
26 static void cleanup(void);
27
28 void (*tet_startup)(void) = startup;
29 void (*tet_cleanup)(void) = cleanup;
30
31 static void utc_ApplicationFW_heynoti_detach_handler_func_01(void);
32 static void utc_ApplicationFW_heynoti_detach_handler_func_02(void);
33
34 enum {
35         POSITIVE_TC_IDX = 0x01,
36         NEGATIVE_TC_IDX,
37 };
38
39 struct tet_testlist tet_testlist[] = {
40         { utc_ApplicationFW_heynoti_detach_handler_func_01, POSITIVE_TC_IDX },
41         { utc_ApplicationFW_heynoti_detach_handler_func_02, NEGATIVE_TC_IDX },
42         { NULL, 0},
43 };
44
45 int fd;
46
47 void callback(void *data)
48 {
49
50 }
51
52 static void startup(void)
53 {
54         char *err;
55         int r;
56
57         fd  = heynoti_init();
58
59         if (fd < 0) {
60                 err = "Error init heynoti";
61                 tet_infoline(err);
62                 tet_delete(POSITIVE_TC_IDX, err);
63                 tet_delete(NEGATIVE_TC_IDX, err);
64         }
65
66         r = heynoti_subscribe(fd, "test_testnoti", callback, NULL);
67         if (r) {
68                 err = "Error subscribe";
69                 tet_infoline(err);
70                 tet_delete(POSITIVE_TC_IDX, err);
71                 tet_delete(NEGATIVE_TC_IDX, err);
72         }
73
74         r = heynoti_attach_handler(fd);
75         if (r) {
76                 err = "Error attach handler";
77                 tet_infoline(err);
78                 tet_delete(POSITIVE_TC_IDX, err);
79                 tet_delete(NEGATIVE_TC_IDX, err);
80         }
81
82 }
83
84 static void cleanup(void)
85 {
86         heynoti_unsubscribe(fd, "test_testnoti", callback);
87         heynoti_close(fd);
88 }
89
90 /**
91  * @brief Positive test case of heynoti_detach_handler()
92  */
93 static void utc_ApplicationFW_heynoti_detach_handler_func_01(void)
94 {
95         int r = 0;
96
97         r = heynoti_detach_handler(fd);
98
99         if (r) {
100                 tet_infoline("heynoti_detach_handler() failed in positive test case");
101                 tet_result(TET_FAIL);
102                 return;
103         }
104         tet_result(TET_PASS);
105 }
106
107 /**
108  * @brief Negative test case of ug_init heynoti_detach_handler()
109  */
110 static void utc_ApplicationFW_heynoti_detach_handler_func_02(void)
111 {
112         int r = 0;
113
114         r = heynoti_detach_handler(-1);
115
116         if (!r) {
117                 tet_infoline("heynoti_detach_handler() failed in negative test case");
118                 tet_result(TET_FAIL);
119                 return;
120         }
121         tet_result(TET_PASS);
122 }