FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
testGetMetadataDebSource.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 #include "pkgagent.h"
18 
19 #include <stdio.h>
20 #include "CUnit/CUnit.h"
21 
22 extern char *DBConfFile;
36 {
37  char *repFile = "../testdata/fossology_1.4.1.dsc";
38  struct debpkginfo *pi;
39  //char *DBConfFile = NULL; /* use default Db.conf */
40  char *ErrorBuf;
41 
42  pi = (struct debpkginfo *)malloc(sizeof(struct debpkginfo));
43  memset(pi, 0, sizeof(struct debpkginfo));
44  int predictValue = 0;
45  db_conn = fo_dbconnect(DBConfFile, &ErrorBuf);
46  strcpy(pi->version, "");
47  int Result = GetMetadataDebSource(repFile, pi);
48  //printf("GetMetadataDebSource Result is:%d\n", Result);
49 
50  //printf("GetMetadataDebSource Result is:%s\n", pi->version);
51  CU_ASSERT_STRING_EQUAL(pi->pkgName, "fossology");
52  CU_ASSERT_STRING_EQUAL(pi->pkgArch, "any");
53  CU_ASSERT_STRING_EQUAL(pi->version, "1.4.1");
54  CU_ASSERT_STRING_EQUAL(pi->maintainer, "Matt Taggart <taggart@debian.org>");
55  CU_ASSERT_STRING_EQUAL(pi->homepage, "http://fossology.org");
56  CU_ASSERT_EQUAL(pi->dep_size, 13);
57 
58  PQfinish(db_conn);
59  int i;
60  for(i=0; i< pi->dep_size;i++)
61  free(pi->depends[i]);
62  free(pi->depends);
63  memset(pi, 0, sizeof(struct debpkginfo));
64  free(pi);
65  CU_ASSERT_EQUAL(Result, predictValue);
66 }
67 
77 {
78  char *repFile = "../testdata/fossology-1.2.0-1.el5.i386.rpm";
79  struct debpkginfo *pi;
80  char *ErrorBuf;
81 
82  pi = (struct debpkginfo *)malloc(sizeof(struct debpkginfo));
83  memset(pi, 0, sizeof(struct debpkginfo));
84  int predictValue = 0; /* FIXED: seems pkgagent have bug here. */
85  db_conn = fo_dbconnect(DBConfFile, &ErrorBuf);
86  int Result = GetMetadataDebSource(repFile, pi);
87  //printf("GetMetadataDebSource Result is:%d\n", Result);
88 
89  PQfinish(db_conn);
90  int i;
91  for(i=0; i< pi->dep_size;i++)
92  free(pi->depends[i]);
93  free(pi->depends);
94  memset(pi, 0, sizeof(struct debpkginfo));
95  free(pi);
96  CU_ASSERT_EQUAL(Result, predictValue);
97 }
98 
103  {"Testing the function GetMetadataDebSource", test_GetMetadataDebSource},
104  {"Testing the function GetMetadataDebSource with wrong testfile", test_GetMetadataDebSource_wrong_testfile},
105  CU_TEST_INFO_NULL
106 };
107 
char ** depends
Package dependency list.
Definition: pkgagent.h:91
char maintainer[MAXCMD]
Package maintainer.
Definition: pkgagent.h:85
static int Result
Result of calls.
Definition: test_CopyFile.c:28
void test_GetMetadataDebSource_wrong_testfile()
Test pkgagent.c Function GetMetadataDebSource() test get debian source info from wrong dsc file...
char version[MAXCMD]
Package version.
Definition: pkgagent.h:80
char homepage[MAXCMD]
Package link.
Definition: pkgagent.h:86
void test_GetMetadataDebSource()
Test pkgagent.c Function GetMetadataDebSource() get debian source package info from ...
int dep_size
Package dependency list size.
Definition: pkgagent.h:92
char pkgArch[MAXCMD]
Package architecture.
Definition: pkgagent.h:83
Holds meta info of Debian packages.
Definition: pkgagent.h:76
char pkgName[MAXCMD]
Package name.
Definition: pkgagent.h:78
int GetMetadataDebSource(char *repFile, struct debpkginfo *pi)
Get debian source package info from .dsc file.
Definition: pkgagent.c:904
char * DBConfFile
DB conf file location.
Definition: testRun.c:33
pkgagent header
PGconn * db_conn
The connection to Database.
Definition: pkgagent.c:34
CU_TestInfo testcases_GetMetadataDebSource[]
testcases for function GetMetadataDebSource
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
Definition: libfossdb.c:40