Tizen 2.1 base
[platform/core/appfw/heynoti.git] / TC / unit / utc_ApplicationFW_heynoti_poll_event_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 #include <pthread.h>
25 #include <unistd.h>
26
27 static void startup(void);
28 static void cleanup(void);
29
30 void (*tet_startup)(void) = startup;
31 void (*tet_cleanup)(void) = cleanup;
32
33 static void utc_ApplicationFW_heynoti_poll_event_func_01(void);
34 static void utc_ApplicationFW_heynoti_poll_event_func_02(void);
35
36 enum {
37         POSITIVE_TC_IDX = 0x01,
38         NEGATIVE_TC_IDX,
39 };
40
41 struct tet_testlist tet_testlist[] = {
42         { utc_ApplicationFW_heynoti_poll_event_func_01, POSITIVE_TC_IDX },
43         { utc_ApplicationFW_heynoti_poll_event_func_02, NEGATIVE_TC_IDX },
44         { NULL, 0},
45 };
46
47 int fd;
48
49 void callback(void *data)
50 {
51
52 }
53
54
55 void * thread_event(void *data)
56 {
57         sleep(5);
58
59         heynoti_publish("test_testnoti");
60
61         return data;
62 }
63
64 static void startup(void)
65 {
66         char *err;
67         int r;
68
69         fd = heynoti_init();
70
71         if (fd < 0) {
72                 err = "Error init heynoti";
73                 tet_infoline(err);
74                 tet_delete(POSITIVE_TC_IDX, err);
75                 tet_delete(NEGATIVE_TC_IDX, err);
76         }
77
78         r = heynoti_subscribe(fd, "test_testnoti", callback, NULL);
79         if (r) {
80                 err = "Error init heynoti";
81                 tet_infoline(err);
82                 tet_delete(POSITIVE_TC_IDX, err);
83                 tet_delete(NEGATIVE_TC_IDX, err);
84         }
85 }
86
87 static void cleanup(void)
88 {
89         pthread_exit(0);
90         heynoti_unsubscribe(fd, "test_testnoti", callback);
91         heynoti_close(fd);
92 }
93
94 /**
95  * @brief Positive test case of heynoti_poll_event()
96  */
97 static void utc_ApplicationFW_heynoti_poll_event_func_01(void)
98 {
99         int r = 0;
100
101         pthread_t tid;
102         pthread_create(&tid, NULL, thread_event, NULL);
103
104         r = heynoti_poll_event(fd);
105
106         if (r == -1) {
107                 tet_infoline("heynoti_poll_event() failed in positive test case");
108                 tet_result(TET_FAIL);
109                 return;
110         }
111         tet_result(TET_PASS);
112 }
113
114 /**
115  * @brief Negative test case of ug_init heynoti_poll_event()
116  */
117 static void utc_ApplicationFW_heynoti_poll_event_func_02(void)
118 {
119         int r = 0;
120
121         r = heynoti_poll_event(-1);
122
123         if (!r) {
124                 tet_infoline("heynoti_poll_event() failed in negative test case");
125                 tet_result(TET_FAIL);
126                 return;
127         }
128         tet_result(TET_PASS);
129 }