tizen 2.3 release
[framework/api/url-download.git] / TC / testcase / utc_download_get_downloaded_file_path_positive.c
1 /*\r
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the License);\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an AS IS BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 #include <tet_api.h>\r
18 #include <download.h>\r
19 #include <glib.h>\r
20 #include <glib-object.h>\r
21 \r
22 \r
23 static void startup(void);\r
24 static void cleanup(void);\r
25 \r
26 void (*tet_startup)(void) = startup;\r
27 void (*tet_cleanup)(void) = cleanup;\r
28 \r
29 static void utc_download_get_downloaded_file_path_positive1(void);\r
30 \r
31 struct tet_testlist tet_testlist[] = {\r
32         {utc_download_get_downloaded_file_path_positive1, 1},\r
33         {NULL, 0},\r
34 };\r
35 \r
36 static GMainLoop* gloop = NULL;\r
37 #define TEST_URL "http://static.campaign.naver.com/0/hangeul/2011/img/img_family.gif"\r
38 \r
39 static void state_cb (int download_id, download_state_e state, void *user_data)\r
40 {\r
41         const char *TC_NAME = __FUNCTION__;\r
42         int retcode = 0;\r
43         download_error_e err = DOWNLOAD_ERROR_NONE;\r
44         if (state == DOWNLOAD_STATE_COMPLETED)\r
45                 g_main_loop_quit(gloop);\r
46         \r
47         retcode = download_get_error(download_id, &err);\r
48         if (retcode != DOWNLOAD_ERROR_NONE) {\r
49                 dts_fail(TC_NAME, "Fail to get error");\r
50                 g_main_loop_quit(gloop);\r
51                 return;\r
52         }\r
53         dts_message(TC_NAME, "err[%d]", err);\r
54         if (err == DOWNLOAD_ERROR_INVALID_URL)\r
55                 dts_message(TC_NAME, "invaild url err");\r
56         else\r
57                 dts_message(TC_NAME, "another error[%d]", err);\r
58 }\r
59 \r
60 \r
61 static void startup(void)\r
62 {\r
63         g_type_init();\r
64         gloop = g_main_loop_new (NULL, 0);\r
65 }\r
66 \r
67 static void cleanup(void)\r
68 {\r
69         g_main_loop_unref(gloop);\r
70         gloop = NULL;\r
71 }\r
72 \r
73 \r
74 void utc_download_get_downloaded_file_path_positive1(void)\r
75 {\r
76         const char *TC_NAME = __FUNCTION__;\r
77         int retcode = 0;\r
78         char *output = NULL;\r
79         int id = 0;\r
80 \r
81         retcode = download_create(&id);\r
82         if (retcode != DOWNLOAD_ERROR_NONE)     {\r
83                 dts_fail(TC_NAME,"Fail to create download handle");\r
84                 return;\r
85         }\r
86         retcode = download_set_url(id, TEST_URL);\r
87         if ( retcode != DOWNLOAD_ERROR_NONE ) {\r
88                 dts_fail(TC_NAME,"Fail to set url");\r
89                 return;\r
90         }\r
91         retcode = download_set_state_changed_cb(id, state_cb, NULL);\r
92         if (retcode != DOWNLOAD_ERROR_NONE)\r
93                 dts_fail(TC_NAME, "Fail to set callback");\r
94 \r
95         retcode = download_start(id);\r
96         if (retcode == DOWNLOAD_ERROR_NONE)\r
97                 g_main_loop_run(gloop);\r
98 \r
99         retcode = download_get_downloaded_file_path(id, &output);\r
100         if ( retcode != DOWNLOAD_ERROR_NONE )\r
101                 dts_message(TC_NAME,"Fail to get content name");\r
102 \r
103         download_unset_state_changed_cb(id);\r
104         download_destroy(id);\r
105 \r
106         if (retcode == DOWNLOAD_ERROR_NONE)\r
107                 dts_pass(TC_NAME, "retcode has no error");\r
108         else\r
109                 dts_fail(TC_NAME, "retcode has error");\r
110 }\r
111 \r