FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_TraverseChild.c
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright (C) 2010-2014 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 extern unpackqueue Queue[MAXCHILD+1]; /* manage children */
23 
24 int Index = 0;
25 struct stat Stat;
26 
31 {
32  InitCmd();
33  return 0;
34 }
35 
44 {
45  deleteTmpFiles("./test-result/");
46  exists = file_dir_exists("./test-result/");
47 
48  Filename = "../testdata/test.iso";
49  MkDirs("./test-result/test.iso.dir/");
50  lstat(Filename, &Stat);
51  ContainerInfo CITemp;
52  memset(&CITemp,0,sizeof(ContainerInfo));
53  strcpy(CITemp.Source, Filename);
54  strcpy(CITemp.Partdir, NewDir);
55  strcpy(CITemp.Partname, "test.iso");
56  strcpy(CITemp.PartnameNew, "test.iso.dir");
57  CITemp.Stat = Stat;
58  CITemp.PI.Cmd = 21;
59  CITemp.PI.StartTime = 1287725739;
60  CITemp.PI.EndTime = 1287725739;
61  CITemp.PI.ChildRecurseArtifact = 0;
62  CITemp.uploadtree_pk = 0;
63  CITemp.Artifact = 0;
64  CITemp.IsDir = 0;
65  CITemp.IsCompressed = 0;
66  CITemp.uploadtree_pk = 0;
67  CITemp.pfile_pk = 0;
68  CITemp.ufile_mode = 0;
69  strcpy(Queue[0].ChildRecurse, "./test-result/test.iso.dir");
70  /* test TraverseChild */
71  int Pid;
72  Pid = fork();
73  if (Pid == 0)
74  {
75  TraverseChild(Index, &CITemp, NewDir);
76  } else
77  {
78  ParentWait();
79  exists = file_dir_exists("./test-result/test.iso.dir/test1.zip.tar.dir/test1.zip");
80  FO_ASSERT_EQUAL(exists, 1); // existing
81  }
82 }
83 
92 {
93  deleteTmpFiles("./test-result/");
94  exists = file_dir_exists("./test-result/");
95 
96  Filename = "../testdata/test_1-1.dsc";
97  // MkDirs("./test-result/fcitx_3.6.2-1.dsc.dir/");
98  lstat(Filename, &Stat);
99  ContainerInfo CITemp;
100  memset(&CITemp,0,sizeof(ContainerInfo));
101  strcpy(CITemp.Source, Filename);
102  strcpy(CITemp.Partdir, NewDir);
103  strcpy(CITemp.Partname, "test_1-1.dsc");
104  strcpy(CITemp.PartnameNew, "test_1-1.dsc.dir");
105  ParentInfo PITemp = {28, 1287725739, 1287725739, 0};
106  CITemp.Stat = Stat;
107  CITemp.PI = PITemp;
108  CITemp.uploadtree_pk = 0;
109  CITemp.Artifact = 0;
110  CITemp.IsDir = 0;
111  CITemp.IsCompressed = 0;
112  CITemp.uploadtree_pk = 0;
113  CITemp.pfile_pk = 0;
114  CITemp.ufile_mode = 0;
115  /* test TraverseChild */
116 
117  int Pid;
118  Pid = fork();
119  if (Pid == 0)
120  {
121  TraverseChild(Index, &CITemp, NewDir);
122  } else
123  {
124  ParentWait();
125  exists = file_dir_exists("./test-result/test_1-1.dsc.dir/debian/README.Debian");
126  FO_ASSERT_EQUAL(exists, 1); // existing
127  }
128 }
129 
139 {
140  deleteTmpFiles("./test-result/");
141  exists = file_dir_exists("./test-result/");
142 
143  Filename = "../testdata/vmlinuz-2.6.26-2-686";
144  MkDirs("./test-result/vmlinuz-2.6.26-2-686.dir/");
145  strcpy(Queue[0].ChildRecurse, "./test-result/vmlinuz-2.6.26-2-686.dir/");
146  lstat(Filename, &Stat);
147  ContainerInfo CITemp;
148  memset(&CITemp,0,sizeof(ContainerInfo));
149  strcpy(CITemp.Source, Filename);
150  strcpy(CITemp.Partdir, NewDir);
151  strcpy(CITemp.Partname, "vmlinuz-2.6.26-2-686");
152  strcpy(CITemp.PartnameNew, "vmlinuz-2.6.26-2-686");
153  ParentInfo PITemp = {27, 1287725739, 1287725739, 0};
154  lstat(Filename, &Stat);
155  CITemp.Stat = Stat;
156  CITemp.PI = PITemp;
157  int Pid;
158  Pid = fork();
159  if (Pid == 0)
160  {
161  TraverseChild(Index, &CITemp, NewDir);
162  } else
163  {
164  ParentWait();
165  exists = file_dir_exists("./test-result/vmlinuz-2.6.26-2-686.dir/Partition_0000");
166  FO_ASSERT_EQUAL(exists, 1); // existing
167  }
168 }
169 
170 
171 /* ************************************************************************** */
172 /* **** cunit test cases **************************************************** */
173 /* ************************************************************************** */
174 
175 CU_TestInfo TraverseChild_testcases[] =
176 {
177  {"TraverseChild for iso file:", testTraverseChild4IsoFile},
178  {"TraverseChild for debian source file:", testTraverseChild4DebianSourceFile},
179  // {"TraverseChild for departition:", testTraverseChild4PartitionFile},
180  CU_TEST_INFO_NULL
181 };
void testTraverseChild4PartitionFile()
test the partition file
int file_dir_exists(char *path_name)
test if a file or directory exists
Definition: run_tests.c:136
int ParentWait()
Wait for a child. Sets child status.
Definition: utils.c:520
Queue for files to be unpacked.
Definition: ununpack.h:93
Structure for storing information about a particular file.
Definition: ununpack.h:120
CU_TestInfo TraverseChild_testcases[]
TraverseChild() test cases.
char Partname[FILENAME_MAX]
Definition: ununpack.h:124
ParentInfo PI
Definition: ununpack.h:131
long uploadtree_pk
Definition: ununpack.h:135
unpackqueue Queue[MAXCHILD+1]
Manage children.
void testTraverseChild4DebianSourceFile()
unpack debian source
int IsCompressed
Definition: ununpack.h:134
long ufile_mode
Definition: ununpack.h:137
time_t EndTime
Definition: ununpack.h:84
char Partdir[FILENAME_MAX]
Definition: ununpack.h:123
int ChildRecurseArtifact
Definition: ununpack.h:85
struct stat Stat
Definition: ununpack.h:130
char * NewDir
Test result directory.
Definition: run_tests.c:29
time_t StartTime
Definition: ununpack.h:83
void TraverseChild(int Index, ContainerInfo *CI, char *NewDir)
Called by exec'd child to process.
Definition: traverse.c:107
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
void InitCmd()
Initialize the metahandler CMD table.
Definition: utils.c:119
int TraverseChildInit()
initialize
long pfile_pk
Definition: ununpack.h:136
char PartnameNew[FILENAME_MAX]
Definition: ununpack.h:125
void testTraverseChild4IsoFile()
ununpack iso file