FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_Traverse.c
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright (C) 2010-2011 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 #include "run_tests.h"
22 static char *Label = "called by main";
23 static char *Basename ="";
24 static ParentInfo *PI = NULL;
25 static int Result = 0;
26 
31 {
32  MagicCookie = magic_open(MAGIC_PRESERVE_ATIME|MAGIC_MIME);
33  if (MagicCookie == NULL)
34  {
35  fprintf(stderr,"FATAL: Failed to initialize magic cookie\n");
36  return -1;
37  }
38 
39  magic_load(MagicCookie,NULL);
40  return 0;
41 }
42 
47 {
48  magic_close(MagicCookie);
49  return 0;
50 }
51 
59 {
60  Filename = "../testdata/testthree.zip";
61  Basename = "testthree.zip";
62  deleteTmpFiles(NewDir);
63  ParentInfo PITest = {0, 1287725739, 1287725739, 0, 0};
64  PI = &PITest;
65  Result = Traverse(Filename,Basename,Label,NewDir,Recurse,PI);
66  exists = file_dir_exists("./test-result/testthree.zip.dir/testtwo.zip.dir/test.zip.dir/ununpack");
67  FO_ASSERT_EQUAL(exists, 1); // is existing
68  FO_ASSERT_EQUAL(Result, 1); // Filename is one containter
69 }
70 
78 {
79  Filename = "../testdata/test.ar";
80  Basename = "test.ar";
81  deleteTmpFiles(NewDir);
82  ParentInfo PITest = {0, 1287725739, 1287725739, 0, 0};
83  PI = &PITest;
84  Result = Traverse(Filename,Basename,Label,NewDir,Recurse,PI);
85  exists = file_dir_exists("./test-result/test.ar.dir/test.tar");
86  FO_ASSERT_EQUAL(exists, 1); // is existing
87  FO_ASSERT_EQUAL(Result, 1); // Filename is one containter
88 }
89 
97 {
98  int returnval;
99  Filename = "../testdata";
100  Basename = NULL;
101  deleteTmpFiles(NewDir);
102  MkDirs("./test-result/testdata");
103  char *cmdline = "/bin/cp -r ../testdata/* ./test-result/testdata/";
104  returnval = system(cmdline); // cp ../testdata to ./test-result/testdata/
105  if(returnval > -1)
106  {
107  ParentInfo PITest = {0, 1287725739, 1287725739, 0, 0};
108  PI = &PITest;
109  Label = "Called by dir/wait";
110  Result = Traverse(Filename,Basename,Label,NewDir,Recurse,PI);
111  exists = file_dir_exists("./test-result/testdata/test.jar.dir/ununpack");
112  FO_ASSERT_EQUAL(exists, 1); // is existing
113  FO_ASSERT_EQUAL(Result, 1); // Filename is one containter
114  }
115 }
116 
124 {
125  Filename = "../testdata/test.rpm";
126  Basename = "test.rpm";
127  deleteTmpFiles(NewDir);
128  ParentInfo PITest = {0, 1287725739, 1287725739, 0, 0};
129  PI = &PITest;
130  Result = Traverse(Filename,Basename,Label,NewDir,Recurse,PI);
131  exists = file_dir_exists("./test-result/test.rpm.unpacked.dir/usr/share/fossology/bsam/VERSION");
132  FO_ASSERT_EQUAL(exists, 1); // is existing
133  FO_ASSERT_EQUAL(Result, 1); // Filename is one containter
134 }
135 
144 {
145  Filename = "";
146  Basename = "";
147  deleteTmpFiles(NewDir);
148  ParentInfo PITest = {0, 1287725739, 1287725739, 0, 0};
149  PI = &PITest;
150  Result = Traverse(Filename,Basename,Label,NewDir,Recurse,PI);
151  exists = file_dir_exists("./test-result");
152  FO_ASSERT_EQUAL(exists, 0); // not existing
153  FO_ASSERT_EQUAL(Result, 0); // Filename is not one containter
154 }
155 
156 /* ************************************************************************** */
157 /* **** cunit test cases **************************************************** */
158 /* ************************************************************************** */
159 
160 CU_TestInfo Traverse_testcases[] =
161 {
162  {"Traverse normal package:", testTraverseNormal4Package},
163  {"Traverse normal package another:", testTraverseNormal4Package2},
164  {"Traverse normal directory:", testTraverseNormal4Dir},
165  {"Traverse normal rpm:", testTraverseNormal4Rpm},
166  {"Traverse null paramters:", testTraverseNullParams},
167  CU_TEST_INFO_NULL
168 };
static int Result
Result of calls.
Definition: test_CopyFile.c:28
void testTraverseNormal4Rpm()
normal test for rpm
int file_dir_exists(char *path_name)
test if a file or directory exists
Definition: run_tests.c:136
int TraverseInit()
initialize
Definition: test_Traverse.c:30
int Traverse(char *Filename, char *Basename, char *Label, char *NewDir, int Recurse, ParentInfo *PI)
Find all files, traverse all directories. This is a depth-first search, in inode order! ...
Definition: traverse.c:282
int TraverseClean()
clean env and others
Definition: test_Traverse.c:46
void testTraverseNormal4Package()
normal test for one package
Definition: test_Traverse.c:58
CU_TestInfo Traverse_testcases[]
Traverse() test cases.
void testTraverseNullParams()
abnormal test for null parameters
char * NewDir
Test result directory.
Definition: run_tests.c:29
void testTraverseNormal4Dir()
normal test for one directory
Definition: test_Traverse.c:96
void testTraverseNormal4Package2()
normal test for one package another case
Definition: test_Traverse.c:77
magic_t MagicCookie
for Magic
Definition: finder.c:34
char * Filename
Filename.
Definition: run_tests.c:28
int exists
Default not exists.
Definition: run_tests.c:31
int MkDirs(char *Fname)
Same as command-line "mkdir -p".
Definition: utils.c:259
int Recurse
Level of unpack recursion. Default to infinite.
Definition: run_tests.c:30