17 #include "run_tests.h" 18 #include "../agent/externs.h" 24 static PGresult *result = NULL;
26 static long pfile_pk = -1;
35 char *upload_filename =
"test_1.orig.tar.gz";
36 int upload_mode = 104;
37 char *upload_origin =
"test_1.orig.tar.gz";
43 LOG_FATAL(
"Unable to connect to database");
48 memset(
SQL,
'\0',MAXSQL);
49 snprintf(
SQL,MAXSQL,
"INSERT INTO upload (upload_filename,upload_mode,upload_origin) VALUES ('%s', %d, '%s');",
50 upload_filename, upload_mode, upload_origin);
54 printf(
"Insert upload information ERROR!\n");
60 memset(
SQL,
'\0',MAXSQL);
61 snprintf(
SQL,MAXSQL,
"SELECT upload_pk FROM upload WHERE upload_filename = '%s';",
66 tmp = PQgetvalue(result,0,0);
81 memset(
SQL,
'\0',MAXSQL);
82 snprintf(
SQL,MAXSQL,
"BEGIN;");
86 printf(
"Remove pfile database information ERROR!\n");
92 memset(
SQL,
'\0',MAXSQL);
93 snprintf(
SQL,MAXSQL,
"DELETE FROM uploadtree WHERE upload_fk = %ld;",
upload_pk);
97 printf(
"Remove pfile database information ERROR!\n");
103 memset(
SQL,
'\0',MAXSQL);
104 snprintf(
SQL,MAXSQL,
"DELETE FROM upload WHERE upload_pk = %ld;",
upload_pk);
108 printf(
"Remove pfile database information ERROR!\n");
114 memset(
SQL,
'\0',MAXSQL);
115 snprintf(
SQL,MAXSQL,
"DELETE FROM pfile WHERE pfile_pk = %ld;", pfile_pk);
119 printf(
"Remove pfile database information ERROR!\n");
125 memset(
SQL,
'\0',MAXSQL);
126 snprintf(
SQL,MAXSQL,
"COMMIT;");
130 printf(
"Perpare pfile information ERROR!\n");
148 struct stat Stat = {0};
149 ParentInfo PI = {0, 1287725739, 1287725739, 0, 0};
150 ContainerInfo CITest = {
"../testdata/test_1.orig.tar.gz",
"./test-result/",
151 "test_1.orig.tar.gz",
"test_1.orig.tar.gz.dir", 1, 1, 0, 0, Stat, PI, 0, 0, 0, 0, 0, 0};
153 char *Fuid =
"383A1791BA72A77F80698A90F22C1B7B04C59BEF.720B5CECCC4700FC90D628FCB45490E3.1aa248f65785e15aa9da4fa3701741d85653584544ab4003ef45e232a761a2f1.1312";
155 CU_ASSERT_EQUAL(result, 1);
167 struct stat Stat = {0};
168 ParentInfo PI = {0, 1287725739, 1287725739, 0, 0};
169 ContainerInfo CITest = {
"../testdata/test_1.orig.tar.gz",
"./test-result/",
170 "test_1.orig.tar.gz",
"test_1.orig.tar.gz.dir", 1, 1, 0, 0, Stat, PI, 0, 0, 0, 0, 0, 0};
173 CU_ASSERT_EQUAL(result, 0);
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
Structure for storing information about a particular file.
PGconn * pgConn
Database connection.
CU_TestInfo DBInsertUploadTree_testcases[]
DB insertion test cases (uploadtree)
int DBInsertClean()
clean the database
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.
char * DBConfFile
DB conf file location.
void testDBInsertUploadTree()
test DBInsertUploadTree function
char * Upload_Pk
Upload pk in DB.
CU_TestInfo DBInsertPfile_testcases[]
DB insertion test cases (pfile)
int DBInsertInit()
initialize
void testDBInsertPfile()
test DBInsertPfile function
int DBInsertUploadTree(ContainerInfo *CI, int Mask)
Insert an UploadTree record.
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
int DBInsertPfile(ContainerInfo *CI, char *Fuid)
Insert a Pfile record. Sets the pfile_pk in CI.