FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_TraverseChild.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2010-2014 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 #include "run_tests.h"
11 extern unpackqueue Queue[MAXCHILD+1]; /* manage children */
12 
13 int Index = 0;
14 struct stat Stat;
15 
20 {
21  InitCmd();
22  return 0;
23 }
24 
33 {
34  deleteTmpFiles("./test-result/");
35  exists = file_dir_exists("./test-result/");
36 
37  Filename = "../testdata/test.iso";
38  MkDirs("./test-result/test.iso.dir/");
39  lstat(Filename, &Stat);
40  ContainerInfo CITemp;
41  memset(&CITemp,0,sizeof(ContainerInfo));
42  strcpy(CITemp.Source, Filename);
43  strcpy(CITemp.Partdir, NewDir);
44  strcpy(CITemp.Partname, "test.iso");
45  strcpy(CITemp.PartnameNew, "test.iso.dir");
46  CITemp.Stat = Stat;
47  CITemp.PI.Cmd = 21;
48  CITemp.PI.StartTime = 1287725739;
49  CITemp.PI.EndTime = 1287725739;
50  CITemp.PI.ChildRecurseArtifact = 0;
51  CITemp.uploadtree_pk = 0;
52  CITemp.Artifact = 0;
53  CITemp.IsDir = 0;
54  CITemp.IsCompressed = 0;
55  CITemp.uploadtree_pk = 0;
56  CITemp.pfile_pk = 0;
57  CITemp.ufile_mode = 0;
58  strcpy(Queue[0].ChildRecurse, "./test-result/test.iso.dir");
59  /* test TraverseChild */
60  int Pid;
61  Pid = fork();
62  if (Pid == 0)
63  {
64  TraverseChild(Index, &CITemp, NewDir);
65  } else
66  {
67  ParentWait();
68  exists = file_dir_exists("./test-result/test.iso.dir/test1.zip.tar.dir/test1.zip");
69  FO_ASSERT_EQUAL(exists, 1); // existing
70  }
71 }
72 
81 {
82  deleteTmpFiles("./test-result/");
83  exists = file_dir_exists("./test-result/");
84 
85  Filename = "../testdata/test_1-1.dsc";
86  // MkDirs("./test-result/fcitx_3.6.2-1.dsc.dir/");
87  lstat(Filename, &Stat);
88  ContainerInfo CITemp;
89  memset(&CITemp,0,sizeof(ContainerInfo));
90  strcpy(CITemp.Source, Filename);
91  strcpy(CITemp.Partdir, NewDir);
92  strcpy(CITemp.Partname, "test_1-1.dsc");
93  strcpy(CITemp.PartnameNew, "test_1-1.dsc.dir");
94  ParentInfo PITemp = {28, 1287725739, 1287725739, 0};
95  CITemp.Stat = Stat;
96  CITemp.PI = PITemp;
97  CITemp.uploadtree_pk = 0;
98  CITemp.Artifact = 0;
99  CITemp.IsDir = 0;
100  CITemp.IsCompressed = 0;
101  CITemp.uploadtree_pk = 0;
102  CITemp.pfile_pk = 0;
103  CITemp.ufile_mode = 0;
104  /* test TraverseChild */
105 
106  int Pid;
107  Pid = fork();
108  if (Pid == 0)
109  {
110  TraverseChild(Index, &CITemp, NewDir);
111  } else
112  {
113  ParentWait();
114  exists = file_dir_exists("./test-result/test_1-1.dsc.dir/debian/README.Debian");
115  FO_ASSERT_EQUAL(exists, 1); // existing
116  }
117 }
118 
128 {
129  deleteTmpFiles("./test-result/");
130  exists = file_dir_exists("./test-result/");
131 
132  Filename = "../testdata/vmlinuz-2.6.26-2-686";
133  MkDirs("./test-result/vmlinuz-2.6.26-2-686.dir/");
134  strcpy(Queue[0].ChildRecurse, "./test-result/vmlinuz-2.6.26-2-686.dir/");
135  lstat(Filename, &Stat);
136  ContainerInfo CITemp;
137  memset(&CITemp,0,sizeof(ContainerInfo));
138  strcpy(CITemp.Source, Filename);
139  strcpy(CITemp.Partdir, NewDir);
140  strcpy(CITemp.Partname, "vmlinuz-2.6.26-2-686");
141  strcpy(CITemp.PartnameNew, "vmlinuz-2.6.26-2-686");
142  ParentInfo PITemp = {27, 1287725739, 1287725739, 0};
143  lstat(Filename, &Stat);
144  CITemp.Stat = Stat;
145  CITemp.PI = PITemp;
146  int Pid;
147  Pid = fork();
148  if (Pid == 0)
149  {
150  TraverseChild(Index, &CITemp, NewDir);
151  } else
152  {
153  ParentWait();
154  exists = file_dir_exists("./test-result/vmlinuz-2.6.26-2-686.dir/Partition_0000");
155  FO_ASSERT_EQUAL(exists, 1); // existing
156  }
157 }
158 
159 
160 /* ************************************************************************** */
161 /* **** cunit test cases **************************************************** */
162 /* ************************************************************************** */
163 
164 CU_TestInfo TraverseChild_testcases[] =
165 {
166  {"TraverseChild for iso file:", testTraverseChild4IsoFile},
167  {"TraverseChild for debian source file:", testTraverseChild4DebianSourceFile},
168  // {"TraverseChild for departition:", testTraverseChild4PartitionFile},
169  CU_TEST_INFO_NULL
170 };
Structure for storing information about a particular file.
Definition: ununpack.h:116
int IsCompressed
Definition: ununpack.h:129
long pfile_pk
Definition: ununpack.h:131
ParentInfo PI
Definition: ununpack.h:126
char Partname[FILENAME_MAX]
Definition: ununpack.h:119
long uploadtree_pk
Definition: ununpack.h:130
long ufile_mode
Definition: ununpack.h:132
struct stat Stat
Definition: ununpack.h:125
char PartnameNew[FILENAME_MAX]
Definition: ununpack.h:120
char Partdir[FILENAME_MAX]
Definition: ununpack.h:118
time_t StartTime
Definition: ununpack.h:78
int ChildRecurseArtifact
Definition: ununpack.h:80
time_t EndTime
Definition: ununpack.h:79
Queue for files to be unpacked.
Definition: ununpack.h:89
CU_TestInfo TraverseChild_testcases[]
TraverseChild() test cases.
unpackqueue Queue[MAXCHILD+1]
Manage children.
void testTraverseChild4PartitionFile()
test the partition file
void testTraverseChild4DebianSourceFile()
unpack debian source
void testTraverseChild4IsoFile()
ununpack iso file
int TraverseChildInit()
initialize
void TraverseChild(int Index, ContainerInfo *CI, char *NewDir)
Called by exec'd child to process.
Definition: traverse.c:96
int MkDirs(char *Fname)
Same as command-line "mkdir -p".
Definition: utils.c:248
int ParentWait()
Wait for a child. Sets child status.
Definition: utils.c:509
void InitCmd()
Initialize the metahandler CMD table.
Definition: utils.c:108
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
char * NewDir
Test result directory.
Definition: run_tests.c:18
char * Filename
Filename.
Definition: run_tests.c:17