9 #include "CUnit/CUnit.h"
31 memset(
SQL,
'\0',MAXSQL);
32 snprintf(
SQL,MAXSQL,
"BEGIN;");
36 printf(
"Perpare pfile information ERROR!\n");
43 memset(
SQL,
'\0',MAXSQL);
44 snprintf(
SQL,MAXSQL,
"INSERT INTO mimetype (mimetype_name) VALUES ('application/x-rpm');");
48 printf(
"Perpare mimetype information ERROR!\n");
53 memset(
SQL,
'\0',MAXSQL);
54 snprintf(
SQL,MAXSQL,
"INSERT INTO mimetype (mimetype_name) VALUES ('application/x-debian-package');");
58 printf(
"Perpare mimetype information ERROR!\n");
63 memset(
SQL,
'\0',MAXSQL);
64 snprintf(
SQL,MAXSQL,
"INSERT INTO mimetype (mimetype_name) VALUES ('application/x-debian-source');");
68 printf(
"Perpare mimetype information ERROR!\n");
75 memset(
SQL,
'\0',MAXSQL);
76 snprintf(
SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_size) VALUES ('%.40s','%.32s','%s');",
77 "AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC",
"2239AA7DAC291B6F8D0A56396B1B8530",
"4560");
81 printf(
"Perpare pfile information ERROR!\n");
87 memset(
SQL,
'\0',MAXSQL);
88 snprintf(
SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_size) VALUES ('%.40s','%.32s','%s');",
89 "F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810",
"87972FC55E2CDD2609ED85051BE50BAF",
"722");
93 printf(
"Perpare pfile information ERROR!\n");
100 memset(
SQL,
'\0',MAXSQL);
101 snprintf(
SQL,MAXSQL,
"SELECT pfile_pk FROM pfile WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
102 "AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC",
"2239AA7DAC291B6F8D0A56396B1B8530",
"4560");
106 printf(
"Get pfile information ERROR!\n");
110 pi->
pFileFk = atoi(PQgetvalue(result, 0, 0));
114 memset(
SQL,
'\0',MAXSQL);
115 snprintf(
SQL,MAXSQL,
"SELECT pfile_pk FROM pfile WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
116 "F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810",
"87972FC55E2CDD2609ED85051BE50BAF",
"722");
120 printf(
"Get pfile information ERROR!\n");
124 control_pfilepk = atoi(PQgetvalue(result, 0, 0));
128 memset(
SQL,
'\0',MAXSQL);
129 snprintf(
SQL,MAXSQL,
"INSERT INTO upload (upload_filename,upload_mode,upload_ts,pfile_fk) VALUES ('%s',40,now(),%ld);",
130 "fossology-web_1.4.1_all.deb", pi->
pFileFk);
134 printf(
"Perpare pfile information ERROR!\n");
139 memset(
SQL,
'\0',MAXSQL);
140 snprintf(
SQL,MAXSQL,
"SELECT upload_pk FROM upload WHERE pfile_fk = '%ld';",
145 printf(
"Get pfile information ERROR!\n");
149 upload_pk = atoi(PQgetvalue(result, 0, 0));
153 memset(
SQL,
'\0',MAXSQL);
154 snprintf(
SQL,MAXSQL,
"INSERT INTO uploadtree_a (upload_fk,pfile_fk,lft,rgt,ufile_name) VALUES (%ld,%ld,1,48,'fossology-web_1.4.1_all.deb');",
159 printf(
"Perpare pfile information ERROR!\n");
165 memset(
SQL,
'\0',MAXSQL);
166 snprintf(
SQL,MAXSQL,
"INSERT INTO uploadtree_a (upload_fk,pfile_fk,lft,rgt,ufile_name) VALUES (%ld,%ld,9,10,'control');",
171 printf(
"Perpare pfile information ERROR!\n");
177 memset(
SQL,
'\0',MAXSQL);
178 snprintf(
SQL,MAXSQL,
"COMMIT;");
182 printf(
"Perpare pfile information ERROR!\n");
197 char *Source =
"./testdata/control";
198 char *
Pfile =
"F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810.87972FC55E2CDD2609ED85051BE50BAF.722";
203 printf(
"Failed to import %s\n", Source);
222 memset(
SQL,
'\0',MAXSQL);
223 snprintf(
SQL,MAXSQL,
"BEGIN;");
227 printf(
"Remove pfile database information ERROR!\n");
233 memset(
SQL,
'\0',MAXSQL);
234 snprintf(
SQL,MAXSQL,
"DELETE FROM mimetype;");
238 printf(
"Remove mimetype information ERROR!\n");
244 memset(
SQL,
'\0',MAXSQL);
245 snprintf(
SQL,MAXSQL,
"DELETE FROM uploadtree_a WHERE upload_fk = %ld;",
upload_pk);
249 printf(
"Remove pfile database information ERROR!\n");
255 memset(
SQL,
'\0',MAXSQL);
256 snprintf(
SQL,MAXSQL,
"DELETE FROM upload WHERE upload_pk = %ld;",
upload_pk);
260 printf(
"Remove pfile database information ERROR!\n");
266 memset(
SQL,
'\0',MAXSQL);
267 snprintf(
SQL,MAXSQL,
"DELETE FROM pfile WHERE pfile_pk = %ld;", pi->
pFileFk);
271 printf(
"Remove pfile database information ERROR!\n");
277 memset(
SQL,
'\0',MAXSQL);
278 snprintf(
SQL,MAXSQL,
"DELETE FROM pfile WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
"F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810",
"87972FC55E2CDD2609ED85051BE50BAF",
"722");
282 printf(
"Remove pfile database 'control' ERROR!\n");
288 memset(
SQL,
'\0',MAXSQL);
289 snprintf(
SQL,MAXSQL,
"COMMIT;");
293 printf(
"Perpare pfile information ERROR!\n");
308 char *
Pfile =
"F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810.87972FC55E2CDD2609ED85051BE50BAF.722";
313 printf(
"Failed to remove %s\n",
Pfile);
337 int predictValue = 0;
344 CU_FAIL_FATAL(
"Prepare database data ERROR!");
349 CU_FAIL_FATAL(
"Prepare repository data ERROR!");
357 CU_ASSERT_STRING_EQUAL(pi->
pkgName,
"fossology-web");
358 CU_ASSERT_STRING_EQUAL(pi->
pkgArch,
"all");
359 CU_ASSERT_STRING_EQUAL(pi->
version,
"1.4.1");
360 CU_ASSERT_STRING_EQUAL(pi->
section,
"utils");
361 CU_ASSERT_STRING_EQUAL(pi->
priority,
"extra");
362 CU_ASSERT_STRING_EQUAL(pi->
maintainer,
"Matt Taggart <taggart@debian.org>");
363 CU_ASSERT_STRING_EQUAL(pi->
homepage,
"http://fossology.org");
366 CU_ASSERT_EQUAL(
Result, predictValue);
370 CU_FAIL_FATAL(
"Remove database data ERROR!");
372 CU_FAIL_FATAL(
"Remove repository data ERROR!");
398 int predictValue = -1;
405 CU_ASSERT_EQUAL(
Result, predictValue);
432 int predictValue = 0;
441 CU_FAIL_FATAL(
"Prepare database data ERROR!");
446 CU_FAIL_FATAL(
"Prepare repository data ERROR!");
451 printf(
"ProcessUpload Result is:%d\n",
Result);
453 CU_ASSERT_EQUAL(
Result, predictValue);
457 CU_FAIL_FATAL(
"Remove database data ERROR!");
459 CU_FAIL_FATAL(
"Remove repository data ERROR!");
char SQL[256]
SQL query to execute.
FUNCTION int ProcessUpload(int upload_pk, int agent_fk)
Process a single upload - read the first 32 bytes in each file.
char * Pfile
Pfile name (SHA1.MD5.Size)
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...
int fo_RepImport(char *Source, char *Type, char *Filename, int Link)
Import a file into the repository.
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.
int fo_RepRemove(char *Type, char *Filename)
Delete a repository file.
PGconn * db_conn
The connection to Database.
int GetMetadataDebBinary(long upload_pk, struct debpkginfo *pi)
Get debian binary package info.
Holds meta info of Debian packages.
char section[MAXCMD]
Package section.
char priority[MAXCMD]
Package priority.
long pFileFk
Package pfile in FOSSology.
char ** depends
Package dependency list.
char version[MAXCMD]
Package version.
char maintainer[MAXCMD]
Package maintainer.
char pkgArch[MAXCMD]
Package architecture.
int dep_size
Package dependency list size.
char pkgName[MAXCMD]
Package name.
char homepage[MAXCMD]
Package link.
static int Result
Result of calls.