2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <glib-object.h>
22 static void startup(void);
23 static void cleanup(void);
25 void (*tet_startup)(void) = startup;
26 void (*tet_cleanup)(void) = cleanup;
28 static void utc_download_start_negative1(void);
30 struct tet_testlist tet_testlist[] = {
31 {utc_download_start_negative1, 1},
35 static GMainLoop *gloop = NULL;
36 static int is_download_failed = 0;
38 static void startup(void)
41 gloop = g_main_loop_new (NULL, 0);
42 is_download_failed = false;
45 static void cleanup(void)
48 is_download_failed = false;
49 g_main_loop_quit(gloop);
50 g_main_loop_unref(gloop);
53 static void state_cb (int download_id, download_state_e state, void *user_data)
55 const char *TC_NAME = __FUNCTION__;
57 download_error_e err = DOWNLOAD_ERROR_NONE;
58 if (state == DOWNLOAD_STATE_FAILED || state == DOWNLOAD_STATE_CANCELED) {
59 is_download_failed = true;
60 g_main_loop_quit(gloop);
63 is_download_failed = false;
64 retcode = download_get_error(download_id, &err);
65 if (retcode != DOWNLOAD_ERROR_NONE) {
66 dts_fail(TC_NAME, "Fail to get error");
67 g_main_loop_quit(gloop);
70 dts_message(TC_NAME, "err[%d]", err);
71 if (err == DOWNLOAD_ERROR_INVALID_URL)
72 dts_message(TC_NAME, "invaild url err");
74 dts_message(TC_NAME, "another error[%d]", err);
77 static void utc_download_start_negative1(void)
79 const char *TC_NAME = __FUNCTION__;
83 retcode = download_create(&id);
84 if (retcode != DOWNLOAD_ERROR_NONE)
85 dts_fail(TC_NAME, "Fail to create download id");
86 retcode = download_set_url(id, "abc.com");
87 if (retcode != DOWNLOAD_ERROR_NONE)
88 dts_fail(TC_NAME, "Fail to set url");
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");
93 retcode = download_start(id);
94 if (retcode == DOWNLOAD_ERROR_NONE)
95 g_main_loop_run(gloop);
97 retcode = download_unset_state_changed_cb(id);
98 if ( retcode != DOWNLOAD_ERROR_NONE )
99 dts_message(TC_NAME,"Fail to unset callback");
100 download_destroy(id);
102 if (is_download_failed)
103 dts_pass(TC_NAME, "retcode has invalid url");
105 dts_fail(TC_NAME, "retcode does not have invalid url");