FOSSology  4.4.0
Open Source License Compliance by Open Source Software
run_tests.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2010 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
12 #include "run_tests.h"
13 #include "../agent/ununpack_globals.h"
14 
15 #define AGENT_DIR "../../"
16 /* globals that mostly shouldn't be globals */
17 char *Filename = "";
18 char *NewDir = "./test-result";
19 int Recurse = -1;
20 int exists = 0;
21 char *DBConfFile = NULL;
22 
23 /* ************************************************************************** */
24 /* **** test suite ********************************************************** */
25 /* ************************************************************************** */
26 extern CU_TestInfo ExtractAR_testcases[];
27 extern CU_TestInfo ExtractZstd_testcases[];
28 extern CU_TestInfo ununpack_iso_testcases[];
29 extern CU_TestInfo ununpack_disk_testcases[];
30 extern CU_TestInfo CopyFile_testcases[];
31 extern CU_TestInfo FindCmd_testcases[];
32 extern CU_TestInfo Prune_testcases[];
33 extern CU_TestInfo RunCommand_testcases[];
34 extern CU_TestInfo Traverse_testcases[];
35 extern CU_TestInfo TraverseChild_testcases[];
36 extern CU_TestInfo TraverseStart_testcases[];
37 extern CU_TestInfo TaintString_testcases[];
38 extern CU_TestInfo IsFunctions_testcases[];
39 extern CU_TestInfo ContainerInfo_testcases[];
40 extern CU_TestInfo Checksum_testcases[];
41 extern CU_TestInfo PathCheck_testcases[];
42 extern CU_TestInfo DBInsertPfile_testcases[];
43 extern CU_TestInfo DBInsertUploadTree_testcases[];
44 
45 CU_SuiteInfo suites[] =
46 {
47  // ununpack-ar.c
48  {"ExtractAR", NULL, NULL, NULL, NULL, ExtractAR_testcases},
49 
50  // ununpack-zstd.c
51  {"ExtractZstd", NULL, NULL, NULL, NULL, ExtractZstd_testcases},
52 
53  // ununpack-iso.c
54  {"ununpack-iso", NULL, NULL, NULL, NULL, ununpack_iso_testcases},
55 
56  // ununpack-disk.c
57  {"ununpack-disk", NULL, NULL, (CU_SetUpFunc)FatDiskNameInit, (CU_TearDownFunc)FatDiskNameClean, ununpack_disk_testcases},
58 
59  // utils.c
60  {"CopyFile", NULL, NULL, (CU_SetUpFunc)CopyFileInit, (CU_TearDownFunc)CopyFileClean, CopyFile_testcases},
62  {"Prune", NULL, NULL, (CU_SetUpFunc)PruneInit, (CU_TearDownFunc)PruneClean, Prune_testcases},
63  {"RunCommand", NULL, NULL, NULL, NULL, RunCommand_testcases},
64  {"TaintString", NULL, NULL, NULL, NULL, TaintString_testcases},
65  {"IsFunctions", NULL, NULL, NULL, NULL, IsFunctions_testcases},
66  {"ContainerInfo", NULL, NULL, NULL, NULL, ContainerInfo_testcases},
67  {"PathCheck", NULL, NULL, NULL, NULL, PathCheck_testcases},
68  //{"DBInsert", DBInsertInit, DBInsertClean, DBInsert_testcases},
69 
70  // traverse.c
71  {"Traverse", NULL, NULL, (CU_SetUpFunc)TraverseInit, (CU_TearDownFunc)TraverseClean, Traverse_testcases},
72  {"TraverseChild", NULL, NULL, (CU_SetUpFunc)TraverseChildInit, NULL, TraverseChild_testcases},
73  {"TraverseStart", NULL, NULL, (CU_SetUpFunc)TraverseStartInit, (CU_TearDownFunc)TraverseStartClean, TraverseStart_testcases},
74 
75  // checksum.c
76  {"checksum", NULL, NULL, NULL, NULL, Checksum_testcases},
77 
78  //utils.c
79  {"DBInsertPfile", NULL, NULL, (CU_SetUpFunc)DBInsertInit, (CU_TearDownFunc)DBInsertClean, DBInsertPfile_testcases},
80  {"DBInsertUploadTree", NULL, NULL, (CU_SetUpFunc)DBInsertInit, (CU_TearDownFunc)DBInsertClean, DBInsertUploadTree_testcases},
81 
82  CU_SUITE_INFO_NULL
83 };
84 
90 int file_dir_exists(char *path_name)
91 {
92  struct stat sts;
93  int exists = 1; // 0: not exists, 1: exists, default exists
94 
95  if ((stat (path_name, &sts)) == -1) exists = 0;
96  return exists;
97 }
98 
99 
100 /* ************************************************************************** */
101 /* **** main test functions ************************************************* */
102 /* ************************************************************************** */
103 
104 int main(int argc, char** argv)
105 {
106 
107  fo_dbManager* dbManager = createTestEnvironment(AGENT_DIR, "ununpack", 1);
108  if(!dbManager) {
109  printf("Unable to connect to test database\n");
110  return 1;
111  }
112 
114 
115  int rc = focunit_main(argc, argv, "ununpack_Tests", suites);
116  dropTestEnvironment(dbManager, AGENT_DIR, "ununpack");
117  return(rc);
118 }
char * get_dbconf()
get Db.conf path just created by create_db_repo_sysconf()
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16
CU_SuiteInfo suites[]
all test suites for delagent
Definition: run_tests.c:46
int CopyFileClean()
clean env and others
Definition: test_CopyFile.c:32
int CopyFileInit()
initialize
Definition: test_CopyFile.c:23
int DBInsertClean()
clean the database
Definition: test_DBInsert.c:68
int DBInsertInit()
initialize
Definition: test_DBInsert.c:21
int PruneInit()
initialize
Definition: test_Prune.c:21
int PruneClean()
clean env and others
Definition: test_Prune.c:30
int TraverseChildInit()
initialize
int TraverseStartInit()
initialize
int TraverseStartClean()
clean env and others
int TraverseClean()
clean env and others
Definition: test_Traverse.c:35
int TraverseInit()
initialize
Definition: test_Traverse.c:19
int FatDiskNameInit()
initialize
int FatDiskNameClean()
clean env and others
CU_TestInfo ContainerInfo_testcases[]
Container info test cases.
CU_TestInfo TraverseChild_testcases[]
TraverseChild() test cases.
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
CU_TestInfo PathCheck_testcases[]
Pacth check test cases.
CU_TestInfo ExtractAR_testcases[]
AR test cases.
CU_TestInfo Prune_testcases[]
Prune() test cases.
Definition: test_Prune.c:99
CU_TestInfo ExtractZstd_testcases[]
Zstd test cases.
CU_TestInfo Checksum_testcases[]
Checksum test cases.
Definition: test_Checksum.c:94
CU_TestInfo FindCmd_testcases[]
FindCmd() test cases.
Definition: test_FindCmd.c:319
int Recurse
Level of unpack recursion. Default to infinite.
Definition: run_tests.c:19
CU_TestInfo TaintString_testcases[]
TaintString() test cases.
CU_TestInfo Traverse_testcases[]
Traverse() test cases.
CU_TestInfo DBInsertUploadTree_testcases[]
DB insertion test cases (uploadtree)
CU_TestInfo ununpack_iso_testcases[]
ISO test cases.
char * DBConfFile
DB conf file location.
Definition: run_tests.c:21
CU_TestInfo CopyFile_testcases[]
Copy test cases.
CU_TestInfo DBInsertPfile_testcases[]
DB insertion test cases (pfile)
CU_TestInfo ununpack_disk_testcases[]
Disk image test cases.
char * NewDir
Test result directory.
Definition: run_tests.c:18
char * Filename
Filename.
Definition: run_tests.c:17
CU_TestInfo IsFunctions_testcases[]
Isxxx() test cases.
CU_TestInfo TraverseStart_testcases[]
TraverseStart() test cases.
CU_TestInfo RunCommand_testcases[]
Run test cases.