FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_Traverse.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2010-2011 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 #include "run_tests.h"
11 static char *Label = "called by main";
12 static char *Basename ="";
13 static ParentInfo *PI = NULL;
14 static int Result = 0;
15 
20 {
21  MagicCookie = magic_open(MAGIC_PRESERVE_ATIME|MAGIC_MIME);
22  if (MagicCookie == NULL)
23  {
24  fprintf(stderr,"FATAL: Failed to initialize magic cookie\n");
25  return -1;
26  }
27 
28  magic_load(MagicCookie,NULL);
29  return 0;
30 }
31 
36 {
37  magic_close(MagicCookie);
38  return 0;
39 }
40 
48 {
49  Filename = "../testdata/testthree.zip";
50  Basename = "testthree.zip";
51  deleteTmpFiles(NewDir);
52  ParentInfo PITest = {0, 1287725739, 1287725739, 0, 0};
53  PI = &PITest;
54  Result = Traverse(Filename,Basename,Label,NewDir,Recurse,PI);
55  exists = file_dir_exists("./test-result/testthree.zip.dir/testtwo.zip.dir/test.zip.dir/ununpack");
56  FO_ASSERT_EQUAL(exists, 1); // is existing
57  FO_ASSERT_EQUAL(Result, 1); // Filename is one containter
58 }
59 
67 {
68  Filename = "../testdata/test.ar";
69  Basename = "test.ar";
70  deleteTmpFiles(NewDir);
71  ParentInfo PITest = {0, 1287725739, 1287725739, 0, 0};
72  PI = &PITest;
73  Result = Traverse(Filename,Basename,Label,NewDir,Recurse,PI);
74  exists = file_dir_exists("./test-result/test.ar.dir/test.tar");
75  FO_ASSERT_EQUAL(exists, 1); // is existing
76  FO_ASSERT_EQUAL(Result, 1); // Filename is one containter
77 }
78 
86 {
87  int returnval;
88  Filename = "../testdata";
89  Basename = NULL;
90  deleteTmpFiles(NewDir);
91  MkDirs("./test-result/testdata");
92  char *cmdline = "/bin/cp -r ../testdata/* ./test-result/testdata/";
93  returnval = system(cmdline); // cp ../testdata to ./test-result/testdata/
94  if(returnval > -1)
95  {
96  ParentInfo PITest = {0, 1287725739, 1287725739, 0, 0};
97  PI = &PITest;
98  Label = "Called by dir/wait";
99  Result = Traverse(Filename,Basename,Label,NewDir,Recurse,PI);
100  exists = file_dir_exists("./test-result/testdata/test.jar.dir/ununpack");
101  FO_ASSERT_EQUAL(exists, 1); // is existing
102  FO_ASSERT_EQUAL(Result, 1); // Filename is one containter
103  }
104 }
105 
113 {
114  Filename = "../testdata/test.rpm";
115  Basename = "test.rpm";
116  deleteTmpFiles(NewDir);
117  ParentInfo PITest = {0, 1287725739, 1287725739, 0, 0};
118  PI = &PITest;
119  Result = Traverse(Filename,Basename,Label,NewDir,Recurse,PI);
120  exists = file_dir_exists("./test-result/test.rpm.unpacked.dir/usr/share/fossology/bsam/VERSION");
121  FO_ASSERT_EQUAL(exists, 1); // is existing
122  FO_ASSERT_EQUAL(Result, 1); // Filename is one containter
123 }
124 
133 {
134  Filename = "";
135  Basename = "";
136  deleteTmpFiles(NewDir);
137  ParentInfo PITest = {0, 1287725739, 1287725739, 0, 0};
138  PI = &PITest;
139  Result = Traverse(Filename,Basename,Label,NewDir,Recurse,PI);
140  exists = file_dir_exists("./test-result");
141  FO_ASSERT_EQUAL(exists, 0); // not existing
142  FO_ASSERT_EQUAL(Result, 0); // Filename is not one containter
143 }
144 
145 /* ************************************************************************** */
146 /* **** cunit test cases **************************************************** */
147 /* ************************************************************************** */
148 
149 CU_TestInfo Traverse_testcases[] =
150 {
151  {"Traverse normal package:", testTraverseNormal4Package},
152  {"Traverse normal package another:", testTraverseNormal4Package2},
153  {"Traverse normal directory:", testTraverseNormal4Dir},
154  {"Traverse normal rpm:", testTraverseNormal4Rpm},
155  {"Traverse null paramters:", testTraverseNullParams},
156  CU_TEST_INFO_NULL
157 };
magic_t MagicCookie
for Magic
Definition: finder.c:23
static int Result
Result of calls.
Definition: test_CopyFile.c:17
void testTraverseNormal4Package()
normal test for one package
Definition: test_Traverse.c:47
void testTraverseNullParams()
abnormal test for null parameters
CU_TestInfo Traverse_testcases[]
Traverse() test cases.
void testTraverseNormal4Rpm()
normal test for rpm
int TraverseClean()
clean env and others
Definition: test_Traverse.c:35
int TraverseInit()
initialize
Definition: test_Traverse.c:19
void testTraverseNormal4Dir()
normal test for one directory
Definition: test_Traverse.c:85
void testTraverseNormal4Package2()
normal test for one package another case
Definition: test_Traverse.c:66
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:275
int MkDirs(char *Fname)
Same as command-line "mkdir -p".
Definition: utils.c:248
int file_dir_exists(char *path_name)
test if a file or directory exists
Definition: run_tests.c:90
int exists
Default not exists.
Definition: run_tests.c:20
int Recurse
Level of unpack recursion. Default to infinite.
Definition: run_tests.c:19
char * NewDir
Test result directory.
Definition: run_tests.c:18
char * Filename
Filename.
Definition: run_tests.c:17