FOSSology  4.4.0
Open Source License Compliance by Open Source Software
testGetURL.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2011-2012 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 /* cunit includes */
8 #include <CUnit/CUnit.h>
9 #include "wget_agent.h"
10 #include "utility.h"
11 #include "libfodbreposysconf.h"
12 
28 static char TempFile[MAX_LENGTH];
29 static char URL[MAX_LENGTH];
30 static char TempFileDir[MAX_LENGTH];
31 
36 {
37  return 0;
38 }
43 {
44  if (file_dir_existed(TempFileDir))
45  {
46  RemoveDir(TempFileDir);
47  }
48 
49  return 0;
50 }
51 
52 /* test functions */
53 
66 {
67  strcpy(URL, "https://mirrors.kernel.org/fossology/releases/3.0.0/ubuntu/14.04/fossology.sources.list");
68  strcpy(TempFileDir, "./test_result");
69  GetURL(TempFile, URL, TempFileDir); /* download the file mkpackages into ./test_result/ */
70  int existed = file_dir_existed("./test_result/mirrors.kernel.org/fossology/releases/3.0.0/ubuntu/14.04/fossology.sources.list");
71  CU_ASSERT_EQUAL(existed, 1); /* the file downloaded? */
72 }
73 
87 {
88  strcpy(GlobalParam, "-l 1 -A *.list -R *.deb");
89  strcpy(URL, "https://mirrors.kernel.org/fossology/releases/3.0.0/ubuntu/14.04/");
90  strcpy(TempFileDir, "./test_result/");
91  strcpy(TempFile, "./test_result/fossology.sources.list");
92  GetURL(TempFile, URL, TempFileDir);
93  int existed = file_dir_existed("./test_result/fossology.sources.list");
94  CU_ASSERT_EQUAL(existed, 1); /* the file downloaded? */
95 }
96 
100 CU_TestInfo testcases_GetURL[] =
101 {
102 #if 0
103 #endif
104  {"GetURL:File", testGetURLNormal_URLIsOneFile},
105  {"GetURL:Dir", testGetURLAbnormal_URLIsOneDir},
106  CU_TEST_INFO_NULL
107 };
108 
CU_TestInfo testcases_GetURL[]
testcases for function GetURL
Definition: testGetURL.c:100
void testGetURLNormal_URLIsOneFile()
The URL is one file.
Definition: testGetURL.c:65
int GetURLClean()
clean the env
Definition: testGetURL.c:42
int GetURLInit()
initialize
Definition: testGetURL.c:35
void testGetURLAbnormal_URLIsOneDir()
the URL is one dir
Definition: testGetURL.c:86
int RemoveDir(char *dirpath)
Remove all files under dirpath (rm -rf)
Definition: utils.c:1641
char GlobalParam[STRMAX]
Additional parameters.
Definition: wget_agent.c:27
int GetURL(char *TempFile, char *URL, char *TempFileDir)
Do the wget.
Definition: wget_agent.c:328