tizen 2.3.1 release
[framework/appfw/alarm-manager.git] / test / test_get_info.c
1 /*
2  *  alarm-manager
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
7  * Sewook Park <sewook7.park@samsung.com>, 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
23 #include<stdio.h>
24 #include<stdlib.h>
25 #include<glib.h>
26
27 #include "alarm.h"
28
29 int callback(alarm_id_t alarm_id)
30 {
31     time_t current_time;
32     time(&current_time);
33
34     printf("Alarm[%d] has expired at %s\n", alarm_id, ctime(&current_time));
35
36     return 0;
37
38 }
39
40
41
42 void create_test()
43 {
44     time_t current_time;
45     struct tm current_tm;
46     alarm_info_t alarm_info;
47
48     alarm_id_t alarm_id_1;
49     alarm_id_t alarm_id_2;
50
51     int error_code;
52         bool result = false;
53
54
55     time(&current_time);
56
57     printf("current time: %s\n", ctime(&current_time));
58     localtime_r(&current_time, &current_tm);
59
60     alarm_info.start.year = 0;
61     alarm_info.start.month = 0;
62     alarm_info.start.day = 0;
63
64     alarm_info.end.year = 2008;
65     alarm_info.end.month = 12;
66     alarm_info.end.day = 31;
67
68     alarm_info.start.hour = current_tm.tm_hour;
69     alarm_info.start.min = current_tm.tm_min+1;
70
71     alarm_info.mode.day_of_week = 0;
72     alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
73
74     alarm_info.activation = true;
75     alarm_info.auto_powerup = false;
76
77     result = alarm_create(&alarm_info, &alarm_id_1, &error_code);
78         if (!result)
79         {
80                 printf("test 1 failed: %d\n", error_code);
81         }
82
83
84     alarm_info.start.min = current_tm.tm_min+2;
85
86     result = alarm_create(&alarm_info, &alarm_id_2, &error_code);
87     if (!result)
88     {
89         printf("test 2 failed: %d\n", error_code);
90     }
91
92     alarm_info.start.min = current_tm.tm_min+2;
93
94     int num_of_ids = 0;
95     result = alarm_get_number_of_ids(&num_of_ids, &error_code);
96
97     if (!result)
98     {
99         printf("test 3 failed: %d\n", error_code);
100     }
101
102     printf("number of alarm is %d\n", num_of_ids);
103
104         int max = num_of_ids;
105         alarm_id_t ids[100];
106
107         result = alarm_get_list_of_ids(max, ids, &num_of_ids, &error_code);
108     if (!result)
109     {
110         printf("test 4 failed: %d\n", error_code);
111     }
112
113         printf("number of alarm in list is %d\n", num_of_ids);
114
115         int i = 0;
116         for( i = 0; i < num_of_ids; i++)
117         {
118                 printf("alarm id %d\n", ids[i]);
119         }
120
121         result = alarm_get_info(ids[0], &alarm_info, &error_code);
122
123         if (!result)
124     {
125         printf("test 4 failed: %d\n", error_code);
126     }
127
128         printf("start_year(%d), start_month(%d), start_day(%d)\n", alarm_info.start.year, alarm_info.start.month, alarm_info.start.day);
129
130         
131
132 }
133
134
135
136 int main(int argc, char** argv)
137 {
138     int error_code;
139     GMainLoop *mainloop;
140     mainloop = g_main_loop_new(NULL, FALSE);
141
142     alarm_init(&error_code);
143     alarm_set_cb(callback, &error_code);
144
145     create_test();
146
147     g_main_loop_run(mainloop);
148
149     alarm_fini(&error_code);
150 }