FOSSology  4.4.0
Open Source License Compliance by Open Source Software
testRun.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
3  SPDX-FileCopyrightText: © 2018 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 #include "testRun.h"
9 #include "finder.h"
10 #include <unistd.h>
11 
21 char *DBConfFile = NULL;
23 
28 CU_SuiteInfo suites[] = {
29  // for finder.c
30  {"DBCheckMime", NULL, NULL, (CU_SetUpFunc)DBCheckMimeInit, (CU_TearDownFunc)DBCheckMimeClean, testcases_DBCheckMime},
31  {"DBLoadMime", NULL, NULL, (CU_SetUpFunc)DBLoadMimeInit, (CU_TearDownFunc)DBLoadMimeClean, testcases_DBLoadMime},
32  {"DBFindMime", NULL, NULL, (CU_SetUpFunc)DBFindMimeInit, (CU_TearDownFunc)DBFindMimeClean, testcases_DBFindMime},
33  {"CheckMimeType", NULL, NULL, (CU_SetUpFunc)DBInit, (CU_TearDownFunc)DBClean, testcases_CheckMimeTypes},
34  {"DBCheckFileExtention", NULL, NULL, (CU_SetUpFunc)DBInit, (CU_TearDownFunc)DBClean, testcases_DBCheckFileExtention},
35  {"Utilities", NULL, NULL, NULL, NULL, testcases_Utilities},
36  CU_SUITE_INFO_NULL
37 };
38 
39 /*
40  * \brief Create required tables
41  */
42 void createTables()
43 {
44  char *ErrorBuf;
45  char SQL[1024];
46  PGresult *result = NULL;
47 
48  pgConn = fo_dbconnect(DBConfFile, &ErrorBuf);
49 
50  memset(SQL,'\0',1024);
51  sprintf(SQL, "%s",
52  "CREATE TABLE uploadtree"
53  " (uploadtree_pk SERIAL, parent integer, realparent integer, upload_fk integer, pfile_fk integer, ufile_mode integer,"
54  " lft integer, rgt integer, ufile_name text);"
55  );
56  result = PQexec(pgConn, SQL);
57  if (fo_checkPQcommand(pgConn, result, SQL, __FILE__ ,__LINE__))
58  {
59  printf("Create uploadtree ERROR!\n");
60  return;
61  }
62  PQclear(result);
63 
64  memset(SQL,'\0',1024);
65  sprintf(SQL, "%s",
66  "CREATE TABLE upload"
67  " (upload_pk SERIAL, upload_desc text, upload_filename text, user_fk integer, upload_mode integer,"
68  " upload_ts timestamp with time zone DEFAULT now(), pfile_fk integer, upload_origin text,"
69  " uploadtree_tablename character varying(18) DEFAULT 'uploadtree_a'::character varying, expire_date date,"
70  " expire_action character(1), public_perm integer);"
71  );
72  result = PQexec(pgConn, SQL);
73  if (fo_checkPQcommand(pgConn, result, SQL, __FILE__ ,__LINE__))
74  {
75  printf("Create uploadtree ERROR!\n");
76  return;
77  }
78  PQclear(result);
79 
80  memset(SQL,'\0',1024);
81  sprintf(SQL, "%s",
82  "CREATE TABLE pfile"
83  " (pfile_pk SERIAL, pfile_md5 character(32), pfile_sha1 character(40), pfile_size bigint, pfile_mimetypefk integer);"
84  );
85  result = PQexec(pgConn, SQL);
86  if (fo_checkPQcommand(pgConn, result, SQL, __FILE__ ,__LINE__))
87  {
88  printf("Create pfile ERROR!\n");
89  return;
90  }
91  PQclear(result);
92 
93  memset(SQL,'\0',1024);
94  sprintf(SQL, "%s", "CREATE TABLE mimetype (mimetype_pk SERIAL, mimetype_name text);");
95  result = PQexec(pgConn, SQL);
96  if (fo_checkPQcommand(pgConn, result, SQL, __FILE__ ,__LINE__))
97  {
98  printf("Create mimetype ERROR!\n");
99  return;
100  }
101  PQclear(result);
102 
103  memset(SQL,'\0',1024);
104  sprintf(SQL, "%s",
105  "INSERT INTO public.mimetype (mimetype_pk, mimetype_name) VALUES"
106  " (2, 'application/gzip'), (3, 'application/x-gzip'), (4, 'application/x-compress'), (5, 'application/x-bzip'),"
107  " (6, 'application/x-bzip2'), (7, 'application/x-upx'), (8, 'application/pdf'), (9, 'application/x-pdf'),"
108  " (10, 'application/x-zip'), (11, 'application/zip'), (12, 'application/x-tar'), (13, 'application/x-gtar'),"
109  " (14, 'application/x-cpio'), (15, 'application/x-rar'), (16, 'application/x-cab'), (17, 'application/x-7z-compressed'),"
110  " (18, 'application/x-7z-w-compressed'), (19, 'application/x-rpm'), (20, 'application/x-archive'),"
111  " (21, 'application/x-debian-package'), (22, 'application/x-iso'), (23, 'application/x-iso9660-image'),"
112  " (24, 'application/x-fat'), (25, 'application/x-ntfs'), (26, 'application/x-ext2'), (27, 'application/x-ext3'),"
113  " (28, 'application/x-x86_boot'), (29, 'application/x-debian-source'), (30, 'application/x-xz'), (31, 'application/jar'),"
114  " (32, 'application/java-archive'), (33, 'application/x-dosexec'), (34, 'text/plain');"
115  );
116  result = PQexec(pgConn, SQL);
117  if (fo_checkPQcommand(pgConn, result, SQL, __FILE__ ,__LINE__))
118  {
119  printf("Insert mimetype ERROR!\n");
120  return;
121  }
122  PQclear(result);
123 }
124 
125 /*
126  * \brief Main test function
127  */
128 int main( int argc, char *argv[] )
129 {
130  // char cwd[2048];
131  // char* confDir = NULL;
132  // char CMD[2048];
133  // int rc;
134 
135  // if(getcwd(cwd, sizeof(cwd)) != NULL)
136  // {
137  // confDir = createTestConfDir(cwd, "mimetype");
138  // }
139 
140  // create_db_repo_sysconf(0, "mimetype", confDir);
141  // DBConfFile = get_dbconf();
142 
143  // createTables();
144  // sprintf(CMD,"rm -rf %s", confDir);
145  // rc = system(CMD);
146 
147  // rc = focunit_main(argc, argv, "mimetype_Tests", suites) ;
148  // drop_db_repo_sysconf(get_db_name());
149 
150  // return rc;
151 
152  dbManager = createTestEnvironment(AGENT_DIR, "mimetype", 0);
154  createTables();
155  const int returnValue = focunit_main(argc, argv, "mimetype_Tests", suites);
156  if (returnValue == 0) {
157  dropTestEnvironment(dbManager, AGENT_DIR, "mimetype");
158  } else {
159  printf("preserving test environment in '%s'\n", get_sysconfdir());
160  }
161  return returnValue;
162 }
163 
char SQL[256]
SQL query to execute.
Definition: adj2nest.c:78
PGconn * pgConn
Database connection.
Definition: adj2nest.c:86
int main(int argc, char *argv[])
main test function
Definition: testRun.c:134
CU_SuiteInfo suites[]
all test suites for delagent
Definition: testRun.h:36
char * get_dbconf()
get Db.conf path just created by create_db_repo_sysconf()
char * get_sysconfdir()
get sysconfig dir path just created by create_db_repo_sysconf()
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
Definition: libfossdb.c:29
int fo_checkPQcommand(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres commands (not select) If an error occured, write the error to s...
Definition: libfossdb.c:204
fo_dbManager * dbManager
fo_dbManager object
Definition: testRun.c:22
int DBCheckMimeClean()
Clean the env.
int DBCheckMimeInit()
Initialize DB.
CU_TestInfo testcases_DBCheckMime[]
testcases for function DBCheckMime
CU_TestInfo testcases_DBFindMime[]
testcases for function DBFindMime
int DBFindMimeInit()
initialize
int DBFindMimeClean()
clean the env
int DBLoadMimeClean()
clean the env
int DBLoadMimeInit()
initialize DB
CU_TestInfo testcases_DBLoadMime[]
testcases for function DBLoadGold
char * DBConfFile
DB conf file location.
Definition: testRun.c:21
int DBInit()
initialize DB
CU_TestInfo testcases_DBCheckFileExtention[]
testcases for function DBCheckFileExtention
CU_TestInfo testcases_Utilities[]
testcases for function GetFieldValue
int DBClean()
clean the env
CU_TestInfo testcases_CheckMimeTypes[]
testcases for function CheckMimeTypes