FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
testDeleteFolders.c
Go to the documentation of this file.
1 /*********************************************************************
2 Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 version 2 as published by the Free Software Foundation.
7 
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along
14 with this program; if not, write to the Free Software Foundation, Inc.,
15 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 *********************************************************************/
17 
18 /* cunit includes */
19 #include <CUnit/CUnit.h>
20 #include "delagent.h"
21 #include <string.h>
22 
23 extern char *DBConfFile;
24 static PGresult *result = NULL;
25 
38 {
39  long FolderId = 3;
40  //char *DBConfFile = NULL; /* use default Db.conf */
41  char *ErrorBuf;
42  int rc;
43 
44  pgConn = fo_dbconnect(DBConfFile, &ErrorBuf);
46  rc = deleteFolder(3, FolderId, 3, 10);
47 
48  PQfinish(pgConn);
49  CU_ASSERT_EQUAL(rc, 0);
50  CU_PASS("DeleteFolders PASS!");
51 }
52 
61 {
62  long UploadId = 2;
63  //char *DBConfFile = NULL; /* use default Db.conf */
64  char *ErrorBuf;
65  char sql[1024];
66  int rc;
67 
68  pgConn = fo_dbconnect(DBConfFile, &ErrorBuf);
70  rc = deleteUpload(UploadId, 3, 10);
71  CU_ASSERT_EQUAL(rc, 0);
72 
73  /* check if uploadtree records deleted */
74  memset(sql, '\0', 1024);
75  snprintf(sql, 1024, "SELECT * FROM uploadtree WHERE upload_fk = %ld;", UploadId);
76  result = PQexec(pgConn, sql);
77  if (fo_checkPQresult(pgConn, result, sql, __FILE__, __LINE__))
78  {
79  CU_FAIL("DeleteUploads FAIL!");
80  }
81  else
82  {
83  CU_ASSERT_EQUAL(PQntuples(result),0);
84  }
85  PQclear(result);
86 
87  /* check if copyright records deleted */
88  memset(sql, '\0', 1024);
89  snprintf(sql, 1024, "SELECT * FROM copyright C INNER JOIN uploadtree U ON C.pfile_fk = U.pfile_fk AND U.upload_fk = %ld;", UploadId);
90  result = PQexec(pgConn, sql);
91  if (fo_checkPQresult(pgConn, result, sql, __FILE__, __LINE__))
92  {
93  CU_FAIL("DeleteUploads FAIL!");
94  }
95  else
96  {
97  CU_ASSERT_EQUAL(PQntuples(result),0);
98  }
99  PQclear(result);
100 
102  UploadId = 4;
103  rc = deleteUpload(UploadId, 2, 10);
104  CU_ASSERT_NOT_EQUAL(rc, 0);
105 
106  PQfinish(pgConn);
107  CU_PASS("DeleteUploads PASS!");
108 }
109 
113 CU_TestInfo testcases_DeleteFolders[] =
114 {
115 #if 0
116 #endif
117 {"Testing the function DeleteFolders:", testDeleteFolders},
118 {"Testing the function DeleteUploads:", testDeleteUploads},
119  CU_TEST_INFO_NULL
120 };
121 
char * DBConfFile
DB conf file location.
Definition: testRun.c:33
int fo_checkPQresult(PGconn *pgConn, PGresult *result, char *sql, char *FileID, int LineNumb)
Check the result status of a postgres SELECT.
Definition: libfossdb.c:181
int deleteFolder(long cFolder, long pFolder, int userId, int userPerm)
recursively delete a folder
Definition: util.c:940
void testDeleteFolders()
for function DeleteFolders
PGconn * pgConn
Database connection.
Definition: adj2nest.c:98
int deleteUpload(long uploadId, int userId, int userPerm)
Given an upload ID, delete it.
Definition: util.c:289
void testDeleteUploads()
for function DeleteUploads
CU_TestInfo testcases_DeleteFolders[]
testcases for function Delete
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
Definition: libfossdb.c:40