FOSSology  4.4.0
Open Source License Compliance by Open Source Software
testDeleteFolders.c
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2011 Hewlett-Packard Development Company, L.P.
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
6 
7 /* cunit includes */
8 #include <CUnit/CUnit.h>
9 #include "delagent.h"
10 #include <string.h>
11 
12 extern char *DBConfFile;
13 static PGresult *result = NULL;
14 
27 {
28  long FolderId = 3;
29  //char *DBConfFile = NULL; /* use default Db.conf */
30  char *ErrorBuf;
31  int rc;
32 
33  pgConn = fo_dbconnect(DBConfFile, &ErrorBuf);
35  rc = deleteFolder(3, FolderId, 3, 10);
36 
37  PQfinish(pgConn);
38  CU_ASSERT_EQUAL(rc, 0);
39  CU_PASS("DeleteFolders PASS!");
40 }
41 
50 {
51  long UploadId = 2;
52  //char *DBConfFile = NULL; /* use default Db.conf */
53  char *ErrorBuf;
54  char sql[1024];
55  int rc;
56 
57  pgConn = fo_dbconnect(DBConfFile, &ErrorBuf);
59  rc = deleteUpload(UploadId, 3, 10);
60  CU_ASSERT_EQUAL(rc, 0);
61 
62  /* check if uploadtree records deleted */
63  memset(sql, '\0', 1024);
64  snprintf(sql, 1024, "SELECT * FROM uploadtree WHERE upload_fk = %ld;", UploadId);
65  result = PQexec(pgConn, sql);
66  if (fo_checkPQresult(pgConn, result, sql, __FILE__, __LINE__))
67  {
68  CU_FAIL("DeleteUploads FAIL!");
69  }
70  else
71  {
72  CU_ASSERT_EQUAL(PQntuples(result),0);
73  }
74  PQclear(result);
75 
76  /* check if copyright records deleted */
77  memset(sql, '\0', 1024);
78  snprintf(sql, 1024, "SELECT * FROM copyright C INNER JOIN uploadtree U ON C.pfile_fk = U.pfile_fk AND U.upload_fk = %ld;", UploadId);
79  result = PQexec(pgConn, sql);
80  if (fo_checkPQresult(pgConn, result, sql, __FILE__, __LINE__))
81  {
82  CU_FAIL("DeleteUploads FAIL!");
83  }
84  else
85  {
86  CU_ASSERT_EQUAL(PQntuples(result),0);
87  }
88  PQclear(result);
89 
91  UploadId = 4;
92  rc = deleteUpload(UploadId, 2, 10);
93  CU_ASSERT_NOT_EQUAL(rc, 0);
94 
95  PQfinish(pgConn);
96  CU_PASS("DeleteUploads PASS!");
97 }
98 
102 CU_TestInfo testcases_DeleteFolders[] =
103 {
104 #if 0
105 #endif
106 {"Testing the function DeleteFolders:", testDeleteFolders},
107 {"Testing the function DeleteUploads:", testDeleteUploads},
108  CU_TEST_INFO_NULL
109 };
110 
PGconn * pgConn
Database connection.
Definition: adj2nest.c:86
int deleteUpload(long uploadId, int userId, int userPerm)
Given an upload ID, delete it.
Definition: util.c:318
int deleteFolder(long cFolder, long pFolder, int userId, int userPerm)
recursively delete a folder
Definition: util.c:1018
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
Definition: libfossdb.c:29
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
Definition: libfossdb.c:170
void testDeleteFolders()
for function DeleteFolders
char * DBConfFile
DB conf file location.
Definition: testRun.c:21
void testDeleteUploads()
for function DeleteUploads
CU_TestInfo testcases_DeleteFolders[]
testcases for function Delete