19 #include <CUnit/CUnit.h> 30 extern char *
GetFieldValue (
char *Sin,
char *Field,
int FieldMax,
31 char *Value,
int ValueMax);
34 static PGresult *result = NULL;
36 static long pfile_pk = -1;
48 LOG_FATAL(
"Unable to connect to database");
51 memset(
SQL,
'\0',MAXCMD);
52 snprintf(
SQL,MAXCMD,
"BEGIN;");
56 printf(
"Perpare pfile information ERROR!\n");
61 memset(
SQL,
'\0',MAXCMD);
62 snprintf(
SQL,MAXCMD,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_size) VALUES ('%.40s','%.32s','%s');",
63 "F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810",
"87972FC55E2CDD2609ED85051BE50BAF",
"722");
67 printf(
"Perpare pfile information ERROR!\n");
73 memset(
SQL,
'\0',MAXCMD);
74 snprintf(
SQL,MAXCMD,
"SELECT pfile_pk FROM pfile WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
75 "F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810",
"87972FC55E2CDD2609ED85051BE50BAF",
"722");
79 printf(
"Get pfile information ERROR!\n");
82 pfile_pk = atoi(PQgetvalue(result, 0, 0));
86 memset(
SQL,
'\0',MAXCMD);
87 snprintf(
SQL,MAXCMD,
"INSERT INTO upload (upload_filename,upload_mode,upload_ts,pfile_fk) VALUES ('ununpack.c',40,now(),'%ld');", pfile_pk);
91 printf(
"Perpare pfile information ERROR!\n");
97 memset(
SQL,
'\0',MAXCMD);
98 snprintf(
SQL,MAXCMD,
"SELECT upload_pk FROM upload WHERE pfile_fk = '%ld';",
103 printf(
"Get pfile information ERROR!\n");
106 upload_pk = atoi(PQgetvalue(result, 0, 0));
110 memset(
SQL,
'\0', MAXCMD);
111 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);
120 memset(
SQL,
'\0',MAXCMD);
121 snprintf(
SQL,MAXCMD,
"COMMIT;");
125 printf(
"Perpare pfile information ERROR!\n");
129 MagicCookie = magic_open(MAGIC_PRESERVE_ATIME|MAGIC_MIME);
131 memset(
SQL,
'\0', MAXCMD);
132 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype;");
142 FMimetype = fopen(
"/etc/mime.types",
"rb");
145 LOG_WARNING(
"Unable to open /etc/mime.types\n");
155 memset(
SQL,
'\0',MAXCMD);
156 snprintf(
SQL,MAXCMD,
"BEGIN;");
160 printf(
"Remove pfile database information ERROR!\n");
166 memset(
SQL,
'\0',MAXCMD);
167 snprintf(
SQL,MAXCMD,
"DELETE FROM uploadtree WHERE upload_fk = %ld;",
upload_pk);
171 printf(
"Remove pfile database information ERROR!\n");
177 memset(
SQL,
'\0',MAXCMD);
178 snprintf(
SQL,MAXCMD,
"DELETE FROM upload WHERE upload_pk = %ld;",
upload_pk);
182 printf(
"Remove pfile database information ERROR!\n");
188 memset(
SQL,
'\0',MAXCMD);
189 snprintf(
SQL,MAXCMD,
"DELETE FROM pfile WHERE pfile_pk = %ld;", pfile_pk);
193 printf(
"Remove pfile database information ERROR!\n");
198 memset(
SQL,
'\0',MAXCMD);
199 snprintf(
SQL,MAXCMD,
"COMMIT;");
203 printf(
"Perpare pfile information ERROR!\n");
228 MagicCookie = magic_open(MAGIC_PRESERVE_ATIME|MAGIC_MIME);
231 memset(
SQL,
'\0', MAXCMD);
232 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'application/octet-stream';");
243 memset(
SQL,
'\0', MAXCMD);
244 snprintf(
SQL, MAXCMD,
"SELECT mimetype_pk from mimetype where mimetype_name = 'application/octet-stream';");
251 int mimetype_pk = atoi(PQgetvalue(result, 0, 0));
253 CU_ASSERT_EQUAL(ret, mimetype_pk);
255 memset(
SQL,
'\0', MAXCMD);
256 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'application/octet-stream';");
268 char Ext2[] =
"spec";
270 memset(
SQL,
'\0', MAXCMD);
271 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'application/x-rpm-spec';");
282 memset(
SQL,
'\0', MAXCMD);
283 snprintf(
SQL, MAXCMD,
"SELECT mimetype_pk from mimetype where mimetype_name = 'application/x-rpm-spec';");
290 mimetype_pk = atoi(PQgetvalue(result, 0, 0));
292 CU_ASSERT_EQUAL(ret, mimetype_pk);
294 memset(
SQL,
'\0', MAXCMD);
295 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'application/x-rpm-spec';");
314 memset(
SQL,
'\0', MAXCMD);
315 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'text/x-csrc';");
325 memset(
SQL,
'\0', MAXCMD);
326 snprintf(
SQL,
sizeof(
SQL)-1,
"SELECT mimetype_pk FROM mimetype where mimetype_name = 'text/x-csrc';" );
333 int mimetype_pk = atoi(PQgetvalue(result, 0, 0));
335 CU_ASSERT_EQUAL(mimetype_id, mimetype_pk);
337 memset(
SQL,
'\0', MAXCMD);
338 snprintf(
SQL, MAXCMD,
"DELETE FROM mimetype where mimetype_name = 'text/x-csrc';");
357 char Sin[] =
"akey='20' pfile_fk='37331'" ;
358 char Field[256] = {0};
359 char Value[1024] = {0};
361 CU_ASSERT_STRING_EQUAL(Field,
"akey");
362 CU_ASSERT_STRING_EQUAL(Value,
"20");
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
int DBCheckFileExtention()
Given a pfile, identify any filenames and see if any of them have a known extension based on /etc/mim...
PGconn * pgConn
Database connection.
int DBInit()
initialize DB
CU_TestInfo testcases_DBCheckFileExtention[]
testcases for function DBCheckFileExtention
void testCheckMimeTypes()
for function CheckMimeTypes()
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...
char SQL[256]
SQL query to execute.
CU_TestInfo testcases_Utilities[]
testcases for function GetFieldValue
int DBClean()
clean the env
CU_TestInfo testcases_CheckMimeTypes[]
testcases for function CheckMimeTypes
char * GetFieldValue(char *Sin, char *Field, int FieldMax, char *Value, int ValueMax)
Given a string that contains field='value' pairs, save the items.
void testDBCheckFileExtention()
for function DBCheckFileExtention()
void testGetFieldValue()
for function GetFieldValue()
FILE * FMimetype
for /etc/mime.types
magic_t MagicCookie
for Magic
int CheckMimeTypes(char *Ext)
Given an extension, see if extension exists in the /etc/mime.types.
char * DBConfFile
DB conf file location.
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.