FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
testGetURL.c
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright (C) 2011-2012 Hewlett-Packard Development Company, L.P.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 *********************************************************************/
17 
18 /* cunit includes */
19 #include <CUnit/CUnit.h>
20 #include "wget_agent.h"
21 #include "utility.h"
22 #include "libfodbreposysconf.h"
23 
39 static char TempFile[MAX_LENGTH];
40 static char URL[MAX_LENGTH];
41 static char TempFileDir[MAX_LENGTH];
42 
47 {
48  return 0;
49 }
54 {
55  if (file_dir_existed(TempFileDir))
56  {
57  RemoveDir(TempFileDir);
58  }
59 
60  return 0;
61 }
62 
63 /* test functions */
64 
77 {
78  strcpy(URL, "https://mirrors.kernel.org/fossology/releases/3.0.0/ubuntu/14.04/fossology.sources.list");
79  strcpy(TempFileDir, "./test_result");
80  GetURL(TempFile, URL, TempFileDir); /* download the file mkpackages into ./test_result/ */
81  int existed = file_dir_existed("./test_result/mirrors.kernel.org/fossology/releases/3.0.0/ubuntu/14.04/fossology.sources.list");
82  CU_ASSERT_EQUAL(existed, 1); /* the file downloaded? */
83 }
84 
98 {
99  strcpy(GlobalParam, "-l 1 -A *.list -R *.deb");
100  strcpy(URL, "https://mirrors.kernel.org/fossology/releases/3.0.0/ubuntu/14.04/");
101  strcpy(TempFileDir, "./test_result/");
102  strcpy(TempFile, "./test_result/fossology.sources.list");
103  GetURL(TempFile, URL, TempFileDir);
104  int existed = file_dir_existed("./test_result/fossology.sources.list");
105  CU_ASSERT_EQUAL(existed, 1); /* the file downloaded? */
106 }
107 
111 CU_TestInfo testcases_GetURL[] =
112 {
113 #if 0
114 #endif
115  {"GetURL:File", testGetURLNormal_URLIsOneFile},
116  {"GetURL:Dir", testGetURLAbnormal_URLIsOneDir},
117  CU_TEST_INFO_NULL
118 };
119 
int GetURLClean()
clean the env
Definition: testGetURL.c:53
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
Definition: utils.c:1651
char GlobalParam[STRMAX]
Additional parameters.
Definition: wget_agent.c:39
int GetURL(char *TempFile, char *URL, char *TempFileDir)
Do the wget.
Definition: wget_agent.c:340
int GetURLInit()
initialize
Definition: testGetURL.c:46
void testGetURLAbnormal_URLIsOneDir()
the URL is one dir
Definition: testGetURL.c:97
CU_TestInfo testcases_GetURL[]
testcases for function GetURL
Definition: testGetURL.c:111
void testGetURLNormal_URLIsOneFile()
The URL is one file.
Definition: testGetURL.c:76