FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_ununpack-disk.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 /* locals */
12 static int Result = 0;
13 
21 {
22  deleteTmpFiles("./test-result/");
23  exists = file_dir_exists("./test-result/");
24  FO_ASSERT_EQUAL(exists, 0); // not existing
25  Filename = "../testdata/ext2file.fs";
26  MkDirs("./test-result/ext2file.fs.dir");
27  Result = ExtractDisk(Filename, "ext", "./test-result/ext2file.fs.dir");
28  exists = file_dir_exists("./test-result/ext2file.fs.dir/testtwo.zip");
29  FO_ASSERT_EQUAL(Result, 0);
30  FO_ASSERT_EQUAL(exists, 1);
31 }
32 
40 {
41  deleteTmpFiles("./test-result/");
42  exists = file_dir_exists("./test-result/");
43  FO_ASSERT_EQUAL(exists, 0); // not existing
44  Filename = "../testdata/ext3file.fs";
45  MkDirs("./test-result/ext3file.fs");
46  Result = ExtractDisk(Filename, "ext", "./test-result/ext3file.fs.dir");
47  exists = file_dir_exists("./test-result/ext3file.fs.dir/testtwo.zip");
48  FO_ASSERT_EQUAL(Result, 0);
49  FO_ASSERT_EQUAL(exists, 1);
50 }
51 
60 {
61  deleteTmpFiles("./test-result/");
62  exists = file_dir_exists("./test-result/");
63  FO_ASSERT_EQUAL(exists, 0); // not existing
64  Filename = "../testdata/ext2file.fs";
65  MkDirs("./test-result/ext2file.fs.dir");
66  Result = ExtractDisk(Filename, "", "./test-result/ext2file.fs.dir");
67  exists = file_dir_exists("./test-result/ext2file.fs.dir/testtwo.zip");
68  FO_ASSERT_EQUAL(Result, 1);
69  FO_ASSERT_EQUAL(exists, 0);
70 }
71 
79 {
80  deleteTmpFiles("./test-result/");
81  exists = file_dir_exists("./test-result/");
82  FO_ASSERT_EQUAL(exists, 0); // not existing
83  Filename = "../testdata/fatfile.fs";
84  MkDirs("./test-result/fatfile.fs.dir");
85  Result = ExtractDisk(Filename, "fat", "./test-result/fatfile.fs.dir");
86  exists = file_dir_exists("./test-result/fatfile.fs.dir/testtwo.zip");
87  FO_ASSERT_EQUAL(Result, 0);
88  FO_ASSERT_EQUAL(exists, 1);
89 }
90 
98 {
99  deleteTmpFiles("./test-result/");
100  exists = file_dir_exists("./test-result/");
101  FO_ASSERT_EQUAL(exists, 0); // not existing
102  Filename = "../testdata/ntfsfile.fs";
103  MkDirs("./test-result/ntfsfile.fs.dir");
104  Result = ExtractDisk(Filename, "ntfs", "./test-result/ntfsfile.fs.dir");
105  exists = file_dir_exists("./test-result/ntfsfile.fs.dir/testtwo.zip");
106  FO_ASSERT_EQUAL(Result, 0);
107  FO_ASSERT_EQUAL(exists, 1);
108 }
109 
110 
111 /* locals */
112 static char *Name = NULL;
113 
114 
119 {
120  Name = (char *)malloc(100);
121  return 0;
122 }
123 
128 {
129  free(Name);
130  return 0;
131 }
132 
140 {
141  strcpy(Name, "Fossology\0");
142  FatDiskName(Name);
143  FO_ASSERT_EQUAL(strcmp(Name, "fossology"), 0);
144 }
145 
155 {
156  strcpy(Name, "Fosso\0");
157  FatDiskName(Name);
158  FO_ASSERT_EQUAL(strcmp(Name, "fosso"), 0);
159 
160  strcpy(Name, "FOSSOLOGY HELLO\0");
161  FatDiskName(Name);
162  FO_ASSERT_EQUAL(strcmp(Name, "fossology hello"), 0);
163 }
164 
172 {
173  strcpy(Name, "Fosso (hello)");
174  FatDiskName(Name);
175  FO_ASSERT_EQUAL(strcmp(Name, "fosso"), 0);
176 }
177 
185 {
186  strcpy(Name, "");
187  FatDiskName(Name);
188  FO_ASSERT_EQUAL(strcmp(Name, ""), 0);
189 }
190 
191 
192 /* ************************************************************************** */
193 /* **** cunit test cases **************************************************** */
194 /* ************************************************************************** */
195 
196 CU_TestInfo ununpack_disk_testcases[] =
197 {
198  {"ExtractDisk: ext2 image:", testExtractDisk4Ext2},
199  {"ExtractDisk: ext3 image:", testExtractDisk4Ext3},
200  {"ExtractDisk: ext2 image, fs type is unknowed:", testExtractDisk4Ext2FstypeUnknow},
201  {"ExtractDisk: fat image:", testExtractDisk4Fat},
202  {"ExtractDisk: nfts image:", testExtractDisk4Ntfs},
203  {"FatDiskName: 1:", testFatDiskName1},
204  {"FatDiskName: 2:", testFatDiskName2},
205  {"FatDiskName: 3:", testFatDiskName3},
206  {"FatDiskName: empty parameter", testFatDiskNameNameEmpty},
207  CU_TEST_INFO_NULL
208 };
static int Result
Result of calls.
Definition: test_CopyFile.c:17
int FatDiskNameInit()
initialize
void testFatDiskName3()
Convert to lowercase.
void testExtractDisk4Ext2FstypeUnknow()
unpack disk image, ext2, FStype is unknown
CU_TestInfo ununpack_disk_testcases[]
Disk image test cases.
int FatDiskNameClean()
clean env and others
void testExtractDisk4Ext2()
unpack disk image, ext2
void testExtractDisk4Ntfs()
unpack disk image, ntfs
void testFatDiskName1()
Convert to lowercase.
void testFatDiskNameNameEmpty()
Convert to lowercase.
void testFatDiskName2()
Convert to lowercase.
void testExtractDisk4Fat()
unpack disk image, fat
void testExtractDisk4Ext3()
unpack disk image, ext3
void FatDiskName(char *Name)
Special handling for FAT names.
Definition: ununpack-disk.c:37
int ExtractDisk(char *Source, char *FStype, char *Destination)
Given a disk image, type of system, and a directory, extract all files!
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
char * Filename
Filename.
Definition: run_tests.c:17