FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_ununpack-disk.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 /* locals */
23 static int Result = 0;
24 
32 {
33  deleteTmpFiles("./test-result/");
34  exists = file_dir_exists("./test-result/");
35  FO_ASSERT_EQUAL(exists, 0); // not existing
36  Filename = "../testdata/ext2file.fs";
37  MkDirs("./test-result/ext2file.fs.dir");
38  Result = ExtractDisk(Filename, "ext", "./test-result/ext2file.fs.dir");
39  exists = file_dir_exists("./test-result/ext2file.fs.dir/testtwo.zip");
40  FO_ASSERT_EQUAL(Result, 0);
41  FO_ASSERT_EQUAL(exists, 1);
42 }
43 
51 {
52  deleteTmpFiles("./test-result/");
53  exists = file_dir_exists("./test-result/");
54  FO_ASSERT_EQUAL(exists, 0); // not existing
55  Filename = "../testdata/ext3file.fs";
56  MkDirs("./test-result/ext3file.fs");
57  Result = ExtractDisk(Filename, "ext", "./test-result/ext3file.fs.dir");
58  exists = file_dir_exists("./test-result/ext3file.fs.dir/testtwo.zip");
59  FO_ASSERT_EQUAL(Result, 0);
60  FO_ASSERT_EQUAL(exists, 1);
61 }
62 
71 {
72  deleteTmpFiles("./test-result/");
73  exists = file_dir_exists("./test-result/");
74  FO_ASSERT_EQUAL(exists, 0); // not existing
75  Filename = "../testdata/ext2file.fs";
76  MkDirs("./test-result/ext2file.fs.dir");
77  Result = ExtractDisk(Filename, "", "./test-result/ext2file.fs.dir");
78  exists = file_dir_exists("./test-result/ext2file.fs.dir/testtwo.zip");
79  FO_ASSERT_EQUAL(Result, 1);
80  FO_ASSERT_EQUAL(exists, 0);
81 }
82 
90 {
91  deleteTmpFiles("./test-result/");
92  exists = file_dir_exists("./test-result/");
93  FO_ASSERT_EQUAL(exists, 0); // not existing
94  Filename = "../testdata/fatfile.fs";
95  MkDirs("./test-result/fatfile.fs.dir");
96  Result = ExtractDisk(Filename, "fat", "./test-result/fatfile.fs.dir");
97  exists = file_dir_exists("./test-result/fatfile.fs.dir/testtwo.zip");
98  FO_ASSERT_EQUAL(Result, 0);
99  FO_ASSERT_EQUAL(exists, 1);
100 }
101 
109 {
110  deleteTmpFiles("./test-result/");
111  exists = file_dir_exists("./test-result/");
112  FO_ASSERT_EQUAL(exists, 0); // not existing
113  Filename = "../testdata/ntfsfile.fs";
114  MkDirs("./test-result/ntfsfile.fs.dir");
115  Result = ExtractDisk(Filename, "ntfs", "./test-result/ntfsfile.fs.dir");
116  exists = file_dir_exists("./test-result/ntfsfile.fs.dir/testtwo.zip");
117  FO_ASSERT_EQUAL(Result, 0);
118  FO_ASSERT_EQUAL(exists, 1);
119 }
120 
121 
122 /* locals */
123 static char *Name = NULL;
124 
125 
130 {
131  Name = (char *)malloc(100);
132  return 0;
133 }
134 
139 {
140  free(Name);
141  return 0;
142 }
143 
151 {
152  strcpy(Name, "Fossology\0");
153  FatDiskName(Name);
154  FO_ASSERT_EQUAL(strcmp(Name, "fossology"), 0);
155 }
156 
166 {
167  strcpy(Name, "Fosso\0");
168  FatDiskName(Name);
169  FO_ASSERT_EQUAL(strcmp(Name, "fosso"), 0);
170 
171  strcpy(Name, "FOSSOLOGY HELLO\0");
172  FatDiskName(Name);
173  FO_ASSERT_EQUAL(strcmp(Name, "fossology hello"), 0);
174 }
175 
183 {
184  strcpy(Name, "Fosso (hello)");
185  FatDiskName(Name);
186  FO_ASSERT_EQUAL(strcmp(Name, "fosso"), 0);
187 }
188 
196 {
197  strcpy(Name, "");
198  FatDiskName(Name);
199  FO_ASSERT_EQUAL(strcmp(Name, ""), 0);
200 }
201 
202 
203 /* ************************************************************************** */
204 /* **** cunit test cases **************************************************** */
205 /* ************************************************************************** */
206 
207 CU_TestInfo ununpack_disk_testcases[] =
208 {
209  {"ExtractDisk: ext2 image:", testExtractDisk4Ext2},
210  {"ExtractDisk: ext3 image:", testExtractDisk4Ext3},
211  {"ExtractDisk: ext2 image, fs type is unknowed:", testExtractDisk4Ext2FstypeUnknow},
212  {"ExtractDisk: fat image:", testExtractDisk4Fat},
213  {"ExtractDisk: nfts image:", testExtractDisk4Ntfs},
214  {"FatDiskName: 1:", testFatDiskName1},
215  {"FatDiskName: 2:", testFatDiskName2},
216  {"FatDiskName: 3:", testFatDiskName3},
217  {"FatDiskName: empty parameter", testFatDiskNameNameEmpty},
218  CU_TEST_INFO_NULL
219 };
static int Result
Result of calls.
Definition: test_CopyFile.c:28
int file_dir_exists(char *path_name)
test if a file or directory exists
Definition: run_tests.c:136
int FatDiskNameInit()
initialize
CU_TestInfo ununpack_disk_testcases[]
Disk image test cases.
void FatDiskName(char *Name)
Special handling for FAT names.
Definition: ununpack-disk.c:48
int ExtractDisk(char *Source, char *FStype, char *Destination)
Given a disk image, type of system, and a directory, extract all files!
void testExtractDisk4Fat()
unpack disk image, fat
void testFatDiskNameNameEmpty()
Convert to lowercase.
void testFatDiskName1()
Convert to lowercase.
void testFatDiskName3()
Convert to lowercase.
void testExtractDisk4Ext2()
unpack disk image, ext2
void testExtractDisk4Ext2FstypeUnknow()
unpack disk image, ext2, FStype is unknown
void testExtractDisk4Ext3()
unpack disk image, ext3
int FatDiskNameClean()
clean env and others
void testExtractDisk4Ntfs()
unpack disk image, ntfs
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 testFatDiskName2()
Convert to lowercase.