FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
test_RunCommand.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 static char *Cmd = "";
23 static char *CmdPre = "";
24 static char *File = "";
25 static char *CmdPost = "";
26 static char *Out = "";
27 static char *Where = "";
28 static int Result = 0;
29 
34 {
35  deleteTmpFiles("./test-result/");
36  Cmd = "zcat";
37  CmdPre = "-q -l";
38  File = "../testdata/test.tar.Z";
39  CmdPost = ">/dev/null 2>&1";
40  Out = 0x0;
41  Where = 0x0;
42  Result = RunCommand(Cmd, CmdPre, File, CmdPost, Out, Where);
43  exists = file_dir_exists("./test-result/");
44  FO_ASSERT_EQUAL(exists, 0); // ./test-result/ is not existing
45  FO_ASSERT_EQUAL(Result, 0); // command could run
46 }
47 
52 {
53  deleteTmpFiles("./test-result/");
54  Cmd = "zcat";
55  CmdPre = "";
56  File = "../testdata/test.tar.Z";
57  CmdPost = "> '%s' 2>/dev/null";
58  Out = "test.tar.Z.unpacked";
59  Where = "./test-result";
60  Result = RunCommand(Cmd, CmdPre, File, CmdPost, Out, Where);
61  exists = file_dir_exists("./test-result/test.tar.Z.unpacked");
62  FO_ASSERT_EQUAL(exists, 1); // the file is existing
63  FO_ASSERT_EQUAL(Result, 0); // command could run
64 }
65 
70 {
71  deleteTmpFiles("./test-result/");
72  Cmd = "pdftotext";
73  CmdPre = "-htmlmeta";
74  File = "../testdata/test.pdf";
75  CmdPost = "> '%s' 2>/dev/null";
76  Out = "test.pdf.text";
77  Where = "./test-result";
78  Result = RunCommand(Cmd, CmdPre, File, CmdPost, Out, Where);
79  exists = file_dir_exists("./test-result/test.pdf.text");
80  FO_ASSERT_EQUAL(exists, 1); // the file is existing
81  FO_ASSERT_EQUAL(Result, 0); // command could run
82 }
83 
88 {
89  deleteTmpFiles("./test-result/");
90  Cmd = "rpm2cpio";
91  CmdPre = "";
92  File = "../testdata/test.rpm";
93  CmdPost = "> '%s' 2> /dev/null";
94  Out = "test.rpm.unpacked";
95  Where = "./test-result";
96  Result = RunCommand(Cmd, CmdPre, File, CmdPost, Out, Where);
97  exists = file_dir_exists("./test-result/test.rpm.unpacked");
98  FO_ASSERT_EQUAL(exists, 1); // existing
99  FO_ASSERT_EQUAL(Result, 0); // command could run
100 }
101 
106 {
107  deleteTmpFiles("./test-result/");
109  Cmd = "cpio";
110  CmdPre = "--no-absolute-filenames -i -d <";
111  File = "./test-result/test.rpm.unpacked";
112  CmdPost = ">/dev/null 2>&1";
113  Out = "test.rpm.unpacked.dir";
114  Where = "./test-result/test.rpm.unpacked.dir";
115  Result = RunCommand(Cmd, CmdPre, File, CmdPost, Out, Where);
116  exists = file_dir_exists("./test-result/test.rpm.unpacked.dir/usr/share/fossology/bsam/VERSION");
117  FO_ASSERT_EQUAL(exists, 1); // existing
118  FO_ASSERT_EQUAL(Result, 0); // command could run
119 }
120 
121 
122 /* ************************************************************************** */
123 /* **** cunit test cases **************************************************** */
124 /* ************************************************************************** */
125 
126 CU_TestInfo RunCommand_testcases[] =
127 {
128  {"RunCommand: Zcat, test if the command can run:", testRunCommand4ZcatTesting},
129  {"RunCommand: Zcat:", testRunCommand4Zcat},
130  {"RunCommand: pdf:", testRunCommand4Pdf},
131  {"RunCommand: rpm file with rpm2cpio", testRunCommand4Rpm1},
132  {"RunCommand: rpm file with cpio", testRunCommand4Rpm2},
133  CU_TEST_INFO_NULL
134 };
void testRunCommand4Zcat()
test the command zcat, unpack via zcat
void testRunCommand4ZcatTesting()
test the command zcat, just testing if the commmand can run
CU_TestInfo RunCommand_testcases[]
Run test cases.
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
void testRunCommand4Pdf()
test the command pdftotext
Definition: monk.h:72
void testRunCommand4Rpm2()
test rpm file, the command is cpio
void testRunCommand4Rpm1()
test rpm file, the command is rmp2cpio
int RunCommand(char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where)
Try a command and return command code.
Definition: utils.c:631
int exists
Default not exists.
Definition: run_tests.c:31