FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_RunCommand.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 static char *Cmd = "";
12 static char *CmdPre = "";
13 static char *File = "";
14 static char *CmdPost = "";
15 static char *Out = "";
16 static char *Where = "";
17 static int Result = 0;
18 
23 {
24  deleteTmpFiles("./test-result/");
25  Cmd = "zcat";
26  CmdPre = "-q -l";
27  File = "../testdata/test.tar.Z";
28  CmdPost = ">/dev/null 2>&1";
29  Out = 0x0;
30  Where = 0x0;
31  Result = RunCommand(Cmd, CmdPre, File, CmdPost, Out, Where);
32  exists = file_dir_exists("./test-result/");
33  FO_ASSERT_EQUAL(exists, 0); // ./test-result/ is not existing
34  FO_ASSERT_EQUAL(Result, 0); // command could run
35 }
36 
41 {
42  deleteTmpFiles("./test-result/");
43  Cmd = "zcat";
44  CmdPre = "";
45  File = "../testdata/test.tar.Z";
46  CmdPost = "> '%s' 2>/dev/null";
47  Out = "test.tar.Z.unpacked";
48  Where = "./test-result";
49  Result = RunCommand(Cmd, CmdPre, File, CmdPost, Out, Where);
50  exists = file_dir_exists("./test-result/test.tar.Z.unpacked");
51  FO_ASSERT_EQUAL(exists, 1); // the file is existing
52  FO_ASSERT_EQUAL(Result, 0); // command could run
53 }
54 
59 {
60  deleteTmpFiles("./test-result/");
61  Cmd = "pdftotext";
62  CmdPre = "-htmlmeta";
63  File = "../testdata/test.pdf";
64  CmdPost = "> '%s' 2>/dev/null";
65  Out = "test.pdf.text";
66  Where = "./test-result";
67  Result = RunCommand(Cmd, CmdPre, File, CmdPost, Out, Where);
68  exists = file_dir_exists("./test-result/test.pdf.text");
69  FO_ASSERT_EQUAL(exists, 1); // the file is existing
70  FO_ASSERT_EQUAL(Result, 0); // command could run
71 }
72 
77 {
78  deleteTmpFiles("./test-result/");
79  Cmd = "rpm2cpio";
80  CmdPre = "";
81  File = "../testdata/test.rpm";
82  CmdPost = "> '%s' 2> /dev/null";
83  Out = "test.rpm.unpacked";
84  Where = "./test-result";
85  Result = RunCommand(Cmd, CmdPre, File, CmdPost, Out, Where);
86  exists = file_dir_exists("./test-result/test.rpm.unpacked");
87  FO_ASSERT_EQUAL(exists, 1); // existing
88  FO_ASSERT_EQUAL(Result, 0); // command could run
89 }
90 
95 {
96  deleteTmpFiles("./test-result/");
98  Cmd = "cpio";
99  CmdPre = "--no-absolute-filenames -i -d <";
100  File = "./test-result/test.rpm.unpacked";
101  CmdPost = ">/dev/null 2>&1";
102  Out = "test.rpm.unpacked.dir";
103  Where = "./test-result/test.rpm.unpacked.dir";
104  Result = RunCommand(Cmd, CmdPre, File, CmdPost, Out, Where);
105  exists = file_dir_exists("./test-result/test.rpm.unpacked.dir/usr/share/fossology/bsam/VERSION");
106  FO_ASSERT_EQUAL(exists, 1); // existing
107  FO_ASSERT_EQUAL(Result, 0); // command could run
108 }
109 
110 
111 /* ************************************************************************** */
112 /* **** cunit test cases **************************************************** */
113 /* ************************************************************************** */
114 
115 CU_TestInfo RunCommand_testcases[] =
116 {
117  {"RunCommand: Zcat, test if the command can run:", testRunCommand4ZcatTesting},
118  {"RunCommand: Zcat:", testRunCommand4Zcat},
119  {"RunCommand: pdf:", testRunCommand4Pdf},
120  {"RunCommand: rpm file with rpm2cpio", testRunCommand4Rpm1},
121  {"RunCommand: rpm file with cpio", testRunCommand4Rpm2},
122  CU_TEST_INFO_NULL
123 };
Definition: monk.h:61
static int Result
Result of calls.
Definition: test_CopyFile.c:17
void testRunCommand4Rpm1()
test rpm file, the command is rmp2cpio
void testRunCommand4Pdf()
test the command pdftotext
void testRunCommand4Zcat()
test the command zcat, unpack via zcat
void testRunCommand4ZcatTesting()
test the command zcat, just testing if the commmand can run
void testRunCommand4Rpm2()
test rpm file, the command is cpio
CU_TestInfo RunCommand_testcases[]
Run test cases.
int RunCommand(char *Cmd, char *CmdPre, char *File, char *CmdPost, char *Out, char *Where)
Try a command and return command code.
Definition: utils.c:621
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