4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
33 #include "email-api-rule.h"
36 #include "testapp-utility.h"
37 #include "testapp-mailbox.h"
39 static gboolean testapp_test_add_rule()
41 email_rule_t* rule = NULL;
43 int target_mailbox_id = 0;
48 int result_from_scanf = 0;
50 rule = malloc(sizeof(email_rule_t));
51 testapp_print("> Enter account id: ");
52 result_from_scanf = scanf("%d", &account_id);
53 rule->account_id = account_id;
55 testapp_print("> Enter Type(FROM - 1 / SUBJECT - 2): ");
56 result_from_scanf = scanf("%d", &type);
59 memset(arg, 0x00, 500);
60 testapp_print("\n> Enter Filtering Value:");
61 result_from_scanf = scanf("%s",arg);
62 rule->value= strdup(arg);
64 testapp_print("> Enter Action(MOVE - 1, BLOCK - 2, DELETE - 3): ");
65 result_from_scanf = scanf("%d", &action);
66 rule->faction= action;
69 testapp_print("\n> Enter target mailbox id:");
70 result_from_scanf = scanf("%d", &target_mailbox_id);
71 rule->target_mailbox_id = target_mailbox_id;
74 testapp_print("> Enter Flag1 value: ");
75 result_from_scanf = scanf("%d", &flag);
78 testapp_print("> Enter Flag2 value: ");
79 result_from_scanf = scanf("%d", &flag);
82 if ( email_add_rule(rule) < 0)
83 testapp_print("\n email_add_rule failed");
86 email_free_rule(&rule, 1);
91 static gboolean testapp_test_delete_rule()
93 int result_from_scanf = 0;
96 testapp_print("> Enter filter id: ");
97 result_from_scanf = scanf("%d", &filter_id);
99 if(email_delete_rule(filter_id) < 0)
100 testapp_print("email_delete_rule failed..! ");
106 static gboolean testapp_test_update_rule()
108 int result_from_scanf = 0;
109 email_rule_t* rule = NULL;
111 int target_mailbox_id = 0;
118 rule = malloc(sizeof(email_rule_t));
119 memset(rule,0X00,sizeof(email_rule_t));
120 testapp_print("> Enter filter id: ");
121 result_from_scanf = scanf("%d", &filter_id);
123 testapp_print("> Enter account id: ");
124 result_from_scanf = scanf("%d", &account_id);
125 rule->account_id = account_id;
127 testapp_print("> Enter Type(FROM - 1 / SUBJECT - 2): ");
128 result_from_scanf = scanf("%d", &type);
131 memset(arg, 0x00, 500);
132 testapp_print("\n> Enter Filtering Value:");
133 result_from_scanf = scanf("%s",arg);
134 rule->value= strdup(arg);
136 testapp_print("> Enter Action(MOVE - 1, BLOCK - 2, DELETE - 3): ");
137 result_from_scanf = scanf("%d", &action);
138 rule->faction= action;
141 testapp_print("\n> Enter target mailbox id:");
142 result_from_scanf = scanf("%d", &target_mailbox_id);
143 rule->target_mailbox_id = target_mailbox_id;
146 testapp_print("> Enter Flag1 value: ");
147 result_from_scanf = scanf("%d", &flag);
150 testapp_print("> Enter Flag2 value: ");
151 result_from_scanf = scanf("%d", &flag);
154 if( !email_update_rule(filter_id, rule) < 0)
155 testapp_print("email_update_rule failed..! ");
157 email_free_rule(&rule, 1);
163 static gboolean testapp_test_get_rule(void)
165 email_rule_t* rule = NULL;
167 int result_from_scanf = 0;
169 testapp_print("> Enter filter id: ");
170 result_from_scanf = scanf("%d", &filter_id);
172 if(email_get_rule(filter_id, &rule) >= 0)
173 testapp_print("\n Got rule of account_id = %d and type = %d\n", rule->account_id, rule->type);
175 email_free_rule(&rule, 1);
181 static gboolean testapp_test_get_rule_list (void)
184 email_rule_t* rule_list=NULL;
186 if(email_get_rule_list(&rule_list, &count) < 0) {
187 testapp_print(" email_get_rule_list error\n");
191 for(i=0;i<count;i++){
192 testapp_print(" %2d) Fileter_Id: %d | Account_id: %d | Type: %d | Value %s \n", i+1,
193 rule_list[i].filter_id,
194 rule_list[i].account_id,
199 email_free_rule(&rule_list, count);
206 static gboolean testapp_test_interpret_command (int menu_number)
208 gboolean go_to_loop = TRUE;
210 switch (menu_number) {
212 testapp_test_add_rule();
215 testapp_test_delete_rule ();
218 testapp_test_update_rule();
221 testapp_test_get_rule ();
224 testapp_test_get_rule_list();
237 void email_test_rule_main()
239 gboolean go_to_loop = TRUE;
241 int result_from_scanf = 0;
244 testapp_show_menu (EMAIL_RULE_MENU);
245 testapp_show_prompt (EMAIL_RULE_MENU);
247 result_from_scanf = scanf("%d", &menu_number);
249 go_to_loop = testapp_test_interpret_command (menu_number);