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