20 #include "CUnit/CUnit.h" 42 memset(SQL,
'\0',MAXSQL);
43 snprintf(SQL,MAXSQL,
"BEGIN;");
44 result = PQexec(db_conn, SQL);
47 printf(
"Perpare pfile information ERROR!\n");
54 memset(SQL,
'\0',MAXSQL);
55 snprintf(SQL,MAXSQL,
"INSERT INTO mimetype (mimetype_name) VALUES ('application/x-rpm');");
56 result = PQexec(db_conn, SQL);
59 printf(
"Perpare mimetype information ERROR!\n");
64 memset(SQL,
'\0',MAXSQL);
65 snprintf(SQL,MAXSQL,
"INSERT INTO mimetype (mimetype_name) VALUES ('application/x-debian-package');");
66 result = PQexec(db_conn, SQL);
69 printf(
"Perpare mimetype information ERROR!\n");
74 memset(SQL,
'\0',MAXSQL);
75 snprintf(SQL,MAXSQL,
"INSERT INTO mimetype (mimetype_name) VALUES ('application/x-debian-source');");
76 result = PQexec(db_conn, SQL);
79 printf(
"Perpare mimetype information ERROR!\n");
86 memset(SQL,
'\0',MAXSQL);
87 snprintf(SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_size) VALUES ('%.40s','%.32s','%s');",
88 "AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC",
"2239AA7DAC291B6F8D0A56396B1B8530",
"4560");
89 result = PQexec(db_conn, SQL);
92 printf(
"Perpare pfile information ERROR!\n");
98 memset(SQL,
'\0',MAXSQL);
99 snprintf(SQL,MAXSQL,
"INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_size) VALUES ('%.40s','%.32s','%s');",
100 "F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810",
"87972FC55E2CDD2609ED85051BE50BAF",
"722");
101 result = PQexec(db_conn, SQL);
104 printf(
"Perpare pfile information ERROR!\n");
111 memset(SQL,
'\0',MAXSQL);
112 snprintf(SQL,MAXSQL,
"SELECT pfile_pk FROM pfile WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
113 "AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC",
"2239AA7DAC291B6F8D0A56396B1B8530",
"4560");
114 result = PQexec(db_conn, SQL);
117 printf(
"Get pfile information ERROR!\n");
121 pi->
pFileFk = atoi(PQgetvalue(result, 0, 0));
125 memset(SQL,
'\0',MAXSQL);
126 snprintf(SQL,MAXSQL,
"SELECT pfile_pk FROM pfile WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
127 "F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810",
"87972FC55E2CDD2609ED85051BE50BAF",
"722");
128 result = PQexec(db_conn, SQL);
131 printf(
"Get pfile information ERROR!\n");
135 control_pfilepk = atoi(PQgetvalue(result, 0, 0));
139 memset(SQL,
'\0',MAXSQL);
140 snprintf(SQL,MAXSQL,
"INSERT INTO upload (upload_filename,upload_mode,upload_ts,pfile_fk) VALUES ('%s',40,now(),%ld);",
141 "fossology-web_1.4.1_all.deb", pi->
pFileFk);
142 result = PQexec(db_conn, SQL);
145 printf(
"Perpare pfile information ERROR!\n");
150 memset(SQL,
'\0',MAXSQL);
151 snprintf(SQL,MAXSQL,
"SELECT upload_pk FROM upload WHERE pfile_fk = '%ld';",
153 result = PQexec(db_conn, SQL);
156 printf(
"Get pfile information ERROR!\n");
160 upload_pk = atoi(PQgetvalue(result, 0, 0));
164 memset(SQL,
'\0',MAXSQL);
165 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');",
167 result = PQexec(db_conn, SQL);
170 printf(
"Perpare pfile information ERROR!\n");
176 memset(SQL,
'\0',MAXSQL);
177 snprintf(SQL,MAXSQL,
"INSERT INTO uploadtree_a (upload_fk,pfile_fk,lft,rgt,ufile_name) VALUES (%ld,%ld,9,10,'control');",
178 upload_pk, control_pfilepk);
179 result = PQexec(db_conn, SQL);
182 printf(
"Perpare pfile information ERROR!\n");
188 memset(SQL,
'\0',MAXSQL);
189 snprintf(SQL,MAXSQL,
"COMMIT;");
190 result = PQexec(db_conn, SQL);
193 printf(
"Perpare pfile information ERROR!\n");
208 char *Source =
"../testdata/control";
209 char *
Pfile =
"F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810.87972FC55E2CDD2609ED85051BE50BAF.722";
214 printf(
"Failed to import %s\n", Source);
233 memset(SQL,
'\0',MAXSQL);
234 snprintf(SQL,MAXSQL,
"BEGIN;");
235 result = PQexec(db_conn, SQL);
238 printf(
"Remove pfile database information ERROR!\n");
244 memset(SQL,
'\0',MAXSQL);
245 snprintf(SQL,MAXSQL,
"DELETE FROM mimetype;");
246 result = PQexec(db_conn, SQL);
249 printf(
"Remove mimetype information ERROR!\n");
255 memset(SQL,
'\0',MAXSQL);
256 snprintf(SQL,MAXSQL,
"DELETE FROM uploadtree_a WHERE upload_fk = %ld;", upload_pk);
257 result = PQexec(db_conn, SQL);
260 printf(
"Remove pfile database information ERROR!\n");
266 memset(SQL,
'\0',MAXSQL);
267 snprintf(SQL,MAXSQL,
"DELETE FROM upload WHERE upload_pk = %ld;", upload_pk);
268 result = PQexec(db_conn, SQL);
271 printf(
"Remove pfile database information ERROR!\n");
277 memset(SQL,
'\0',MAXSQL);
278 snprintf(SQL,MAXSQL,
"DELETE FROM pfile WHERE pfile_pk = %ld;", pi->
pFileFk);
279 result = PQexec(db_conn, SQL);
282 printf(
"Remove pfile database information ERROR!\n");
288 memset(SQL,
'\0',MAXSQL);
289 snprintf(SQL,MAXSQL,
"DELETE FROM pfile WHERE pfile_sha1 = '%.40s' AND pfile_md5 = '%.32s' AND pfile_size = '%s';",
"F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810",
"87972FC55E2CDD2609ED85051BE50BAF",
"722");
290 result = PQexec(db_conn, SQL);
293 printf(
"Remove pfile database 'control' ERROR!\n");
299 memset(SQL,
'\0',MAXSQL);
300 snprintf(SQL,MAXSQL,
"COMMIT;");
301 result = PQexec(db_conn, SQL);
304 printf(
"Perpare pfile information ERROR!\n");
319 char *
Pfile =
"F1D2319DF20ABC4CEB02CA5A3C2021BD87B26810.87972FC55E2CDD2609ED85051BE50BAF.722";
324 printf(
"Failed to remove %s\n", Pfile);
348 int predictValue = 0;
355 CU_FAIL_FATAL(
"Prepare database data ERROR!");
360 CU_FAIL_FATAL(
"Prepare repository data ERROR!");
368 CU_ASSERT_STRING_EQUAL(pi->
pkgName,
"fossology-web");
369 CU_ASSERT_STRING_EQUAL(pi->
pkgArch,
"all");
370 CU_ASSERT_STRING_EQUAL(pi->
version,
"1.4.1");
371 CU_ASSERT_STRING_EQUAL(pi->
section,
"utils");
372 CU_ASSERT_STRING_EQUAL(pi->
priority,
"extra");
373 CU_ASSERT_STRING_EQUAL(pi->
maintainer,
"Matt Taggart <taggart@debian.org>");
374 CU_ASSERT_STRING_EQUAL(pi->
homepage,
"http://fossology.org");
377 CU_ASSERT_EQUAL(Result, predictValue);
381 CU_FAIL_FATAL(
"Remove database data ERROR!");
383 CU_FAIL_FATAL(
"Remove repository data ERROR!");
409 int predictValue = -1;
416 CU_ASSERT_EQUAL(Result, predictValue);
443 int predictValue = 0;
452 CU_FAIL_FATAL(
"Prepare database data ERROR!");
457 CU_FAIL_FATAL(
"Prepare repository data ERROR!");
462 printf(
"ProcessUpload Result is:%d\n", Result);
464 CU_ASSERT_EQUAL(Result, predictValue);
468 CU_FAIL_FATAL(
"Remove database data ERROR!");
470 CU_FAIL_FATAL(
"Remove repository data ERROR!");
char ** depends
Package dependency list.
char maintainer[MAXCMD]
Package maintainer.
static int Result
Result of calls.
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
FUNCTION int ProcessUpload(int upload_pk, int agent_fk)
Process a single upload - read the first 32 bytes in each file.
char version[MAXCMD]
Package version.
char homepage[MAXCMD]
Package link.
long pFileFk
Package pfile in FOSSology.
char * Pfile
Pfile name (SHA1.MD5.Size)
int dep_size
Package dependency list size.
char pkgArch[MAXCMD]
Package architecture.
Holds meta info of Debian packages.
char pkgName[MAXCMD]
Package name.
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.
PGconn * db_conn
The connection to Database.
int GetMetadataDebBinary(long upload_pk, struct debpkginfo *pi)
Get debian binary package info.
char priority[MAXCMD]
Package priority.
char section[MAXCMD]
Package section.
int fo_RepImport(char *Source, char *Type, char *Filename, int Link)
Import a file into the repository.
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
int fo_RepRemove(char *Type, char *Filename)
Delete a repository file.
int fo_RepExist(char *Type, char *Filename)
Determine if a file exists.