7 #include <CUnit/CUnit.h>
18 extern char *
GetFieldValue (
char *Sin,
char *Field,
int FieldMax,
19 char *Value,
int ValueMax);
22 static PGresult *result = NULL;
24 static long pfile_pk = -1;
36 LOG_FATAL(
"Unable to connect to database");
39 memset(
SQL,
'\0',MAXCMD);
40 snprintf(
SQL,MAXCMD,
"BEGIN;");
44 printf(
"Perpare pfile information ERROR!\n");
49 memset(
SQL,
'\0',MAXCMD);
50 snprintf(
SQL,MAXCMD,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_size) VALUES ('%.40s','%.32s','%s');",
51 "F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810",
"87972FC55E2CDD2609ED85051BE50BAF",
"722");
55 printf(
"Perpare pfile information ERROR!\n");
61 memset(
SQL,
'\0',MAXCMD);
62 snprintf(
SQL,MAXCMD,
"SELECT pfile_pk FROM pfile WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
63 "F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810",
"87972FC55E2CDD2609ED85051BE50BAF",
"722");
67 printf(
"Get pfile information ERROR!\n");
70 pfile_pk = atoi(PQgetvalue(result, 0, 0));
74 memset(
SQL,
'\0',MAXCMD);
75 snprintf(
SQL,MAXCMD,
"INSERT INTO upload (upload_filename,upload_mode,upload_ts,pfile_fk) VALUES ('ununpack.c',40,now(),'%ld');", pfile_pk);
79 printf(
"Perpare pfile information ERROR!\n");
85 memset(
SQL,
'\0',MAXCMD);
86 snprintf(
SQL,MAXCMD,
"SELECT upload_pk FROM upload WHERE pfile_fk = '%ld';",
91 printf(
"Get pfile information ERROR!\n");
94 upload_pk = atoi(PQgetvalue(result, 0, 0));
98 memset(
SQL,
'\0', MAXCMD);
99 snprintf(
SQL,MAXCMD,
"INSERT INTO uploadtree (upload_fk,pfile_fk,lft,rgt,ufile_name) VALUES (%ld,%ld,1,48,'ununpack.c');",
upload_pk, pfile_pk);
108 memset(
SQL,
'\0',MAXCMD);
109 snprintf(
SQL,MAXCMD,
"COMMIT;");
113 printf(
"Perpare pfile information ERROR!\n");
117 MagicCookie = magic_open(MAGIC_PRESERVE_ATIME|MAGIC_MIME);
119 memset(
SQL,
'\0', MAXCMD);
120 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype;");
130 FMimetype = fopen(
"/etc/mime.types",
"rb");
133 LOG_WARNING(
"Unable to open /etc/mime.types\n");
143 memset(
SQL,
'\0',MAXCMD);
144 snprintf(
SQL,MAXCMD,
"BEGIN;");
148 printf(
"Remove pfile database information ERROR!\n");
154 memset(
SQL,
'\0',MAXCMD);
155 snprintf(
SQL,MAXCMD,
"DELETE FROM uploadtree WHERE upload_fk = %ld;",
upload_pk);
159 printf(
"Remove pfile database information ERROR!\n");
165 memset(
SQL,
'\0',MAXCMD);
166 snprintf(
SQL,MAXCMD,
"DELETE FROM upload WHERE upload_pk = %ld;",
upload_pk);
170 printf(
"Remove pfile database information ERROR!\n");
176 memset(
SQL,
'\0',MAXCMD);
177 snprintf(
SQL,MAXCMD,
"DELETE FROM pfile WHERE pfile_pk = %ld;", pfile_pk);
181 printf(
"Remove pfile database information ERROR!\n");
186 memset(
SQL,
'\0',MAXCMD);
187 snprintf(
SQL,MAXCMD,
"COMMIT;");
191 printf(
"Perpare pfile information ERROR!\n");
216 MagicCookie = magic_open(MAGIC_PRESERVE_ATIME|MAGIC_MIME);
219 memset(
SQL,
'\0', MAXCMD);
220 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'application/octet-stream';");
231 memset(
SQL,
'\0', MAXCMD);
232 snprintf(
SQL, MAXCMD,
"SELECT mimetype_pk from mimetype where mimetype_name = 'application/octet-stream';");
239 int mimetype_pk = atoi(PQgetvalue(result, 0, 0));
241 CU_ASSERT_EQUAL(ret, mimetype_pk);
243 memset(
SQL,
'\0', MAXCMD);
244 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'application/octet-stream';");
256 char Ext2[] =
"spec";
258 memset(
SQL,
'\0', MAXCMD);
259 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'application/x-rpm-spec';");
270 memset(
SQL,
'\0', MAXCMD);
271 snprintf(
SQL, MAXCMD,
"SELECT mimetype_pk from mimetype where mimetype_name = 'application/x-rpm-spec';");
278 mimetype_pk = atoi(PQgetvalue(result, 0, 0));
280 CU_ASSERT_EQUAL(ret, mimetype_pk);
282 memset(
SQL,
'\0', MAXCMD);
283 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'application/x-rpm-spec';");
302 memset(
SQL,
'\0', MAXCMD);
303 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'text/x-csrc';");
313 memset(
SQL,
'\0', MAXCMD);
314 snprintf(
SQL,
sizeof(
SQL)-1,
"SELECT mimetype_pk FROM mimetype where mimetype_name = 'text/x-csrc';" );
321 int mimetype_pk = atoi(PQgetvalue(result, 0, 0));
323 CU_ASSERT_EQUAL(mimetype_id, mimetype_pk);
325 memset(
SQL,
'\0', MAXCMD);
326 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'text/x-csrc';");
345 char Sin[] =
"akey='20' pfile_fk='37331'" ;
346 char Field[256] = {0};
347 char Value[1024] = {0};
349 CU_ASSERT_STRING_EQUAL(Field,
"akey");
350 CU_ASSERT_STRING_EQUAL(Value,
"20");
char SQL[256]
SQL query to execute.
PGconn * pgConn
Database connection.
FILE * FMimetype
for /etc/mime.types
magic_t MagicCookie
for Magic
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
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...
void testGetFieldValue()
for function GetFieldValue()
char * GetFieldValue(char *Sin, char *Field, int FieldMax, char *Value, int ValueMax)
Given a string that contains field='value' pairs, save the items.
int CheckMimeTypes(char *Ext)
Given an extension, see if extension exists in the /etc/mime.types.
int DBInit()
initialize DB
CU_TestInfo testcases_DBCheckFileExtention[]
testcases for function DBCheckFileExtention
CU_TestInfo testcases_Utilities[]
testcases for function GetFieldValue
char * DBConfFile
DB conf file location.
void testCheckMimeTypes()
for function CheckMimeTypes()
int DBClean()
clean the env
CU_TestInfo testcases_CheckMimeTypes[]
testcases for function CheckMimeTypes
int DBCheckFileExtention()
Given a pfile, identify any filenames and see if any of them have a known extension based on /etc/mim...
void testDBCheckFileExtention()
for function DBCheckFileExtention()