FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
testGetMetadata.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;
35 {
36  char *pkg = "../testdata/fossology-1.2.0-1.el5.i386.rpm";
37  struct rpmpkginfo *pi;
38  //char *DBConfFile = NULL; /* use default Db.conf */
39  char *ErrorBuf;
40 
41  pi = (struct rpmpkginfo *)malloc(sizeof(struct rpmpkginfo));
42  memset(pi, 0, sizeof(struct rpmpkginfo));
43  int predictValue = 0;
44  rpmReadConfigFiles(NULL, NULL);
45  db_conn = fo_dbconnect(DBConfFile, &ErrorBuf);
46  int Result = GetMetadata(pkg, pi);
47  //printf("test_GetMetadata Result is:%d\n", Result);
48  //printf("test_GetMetadata Result is temp:%s\n", pi->pkgArch);
49  CU_ASSERT_STRING_EQUAL(pi->pkgName, "fossology");
50  CU_ASSERT_STRING_EQUAL(pi->pkgArch, "i386");
51  CU_ASSERT_STRING_EQUAL(pi->version, "1.2.0");
52  CU_ASSERT_STRING_EQUAL(pi->license, "GPLv2");
53  CU_ASSERT_STRING_EQUAL(pi->group, "Applications/Engineering");
54  CU_ASSERT_STRING_EQUAL(pi->release, "1.el5");
55  CU_ASSERT_STRING_EQUAL(pi->buildDate, "Mon Jul 12 03:30:32 2010");
56  CU_ASSERT_STRING_EQUAL(pi->url, "http://www.fossology.org");
57  CU_ASSERT_STRING_EQUAL(pi->sourceRPM, "fossology-1.2.0-1.el5.src.rpm");
58  CU_ASSERT_EQUAL(pi->req_size, 44);
59  PQfinish(db_conn);
60  rpmFreeCrypto();
61  /* free memroy */
62  int i;
63  for(i=0; i< pi->req_size;i++)
64  free(pi->requires[i]);
65  rpmFreeMacros(NULL);
66  free(pi->requires);
67  free(pi);
68  CU_ASSERT_EQUAL(Result, predictValue);
69 }
70 
78 {
79  char *pkg = "../testdata/fossology_1.4.1.dsc";
80  struct rpmpkginfo *pi;
81  pi = (struct rpmpkginfo *)malloc(sizeof(struct rpmpkginfo));
82  memset(pi, 0, sizeof(struct rpmpkginfo));
83  int predictValue = -1;
84  //char *DBConfFile = NULL; /* use default Db.conf */
85  char *ErrorBuf;
86 
87  rpmReadConfigFiles(NULL, NULL);
88  db_conn = fo_dbconnect(DBConfFile, &ErrorBuf);
89  int Result = GetMetadata(pkg, pi);
90  //printf("test_GetMetadata Result is:%d\n", Result);
91  PQfinish(db_conn);
92  rpmFreeCrypto();
93  rpmFreeMacros(NULL);
94  memset(pi, 0, sizeof(struct rpmpkginfo));
95  free(pi);
96  CU_ASSERT_EQUAL(Result, predictValue);
97 }
98 
106 {
107  char *pkg = NULL;
108  struct rpmpkginfo *pi;
109  //char *DBConfFile = NULL; /* use default Db.conf */
110  char *ErrorBuf;
111 
112  pi = (struct rpmpkginfo *)malloc(sizeof(struct rpmpkginfo));
113  memset(pi, 0, sizeof(struct rpmpkginfo));
114  int predictValue = -1;
115  rpmReadConfigFiles(NULL, NULL);
116  db_conn = fo_dbconnect(DBConfFile, &ErrorBuf);
117  int Result = GetMetadata(pkg, pi);
118  //printf("test_GetMetadata Result is:%d\n", Result);
119  PQfinish(db_conn);
120  rpmFreeCrypto();
121  /* free memroy */
122  int i;
123  for(i=0; i< pi->req_size;i++)
124  free(pi->requires[i]);
125  rpmFreeMacros(NULL);
126  free(pi->requires);
127  free(pi);
128  CU_ASSERT_EQUAL(Result, predictValue);
129 }
130 
134 CU_TestInfo testcases_GetMetadata[] = {
135  {"Testing the function GetMetadata, paramters are normal", test_GetMetadata_normal},
136  {"Testing the function GetMetadata, test file is not rpm file", test_GetMetadata_wrong_testfile},
137  {"Testing the function GetMetadata, test file doesn't exist", test_GetMetadata_no_testfile},
138  CU_TEST_INFO_NULL
139 };
140 
static int Result
Result of calls.
Definition: test_CopyFile.c:28
int GetMetadata(char *pkg, struct rpmpkginfo *pi)
Get RPM package info.
Definition: pkgagent.c:517
char license[512]
RPM licenses.
Definition: pkgagent.h:56
char buildDate[128]
Package build date.
Definition: pkgagent.h:60
char sourceRPM[256]
Package source.
Definition: pkgagent.h:63
char pkgName[256]
RPM package name.
Definition: pkgagent.h:51
Holds meta info of rpm packages.
Definition: pkgagent.h:49
char version[64]
Package version.
Definition: pkgagent.h:54
void test_GetMetadata_no_testfile()
Test pkgagent.c Function GetMetadata() with No test file.
char ** requires
Package dependency list.
Definition: pkgagent.h:68
pkgagent header
char pkgArch[64]
Package architecture.
Definition: pkgagent.h:53
PGconn * db_conn
The connection to Database.
Definition: pkgagent.c:34
CU_TestInfo testcases_GetMetadata[]
testcases for function GetMetadata
void test_GetMetadata_normal()
Test pkgagent.c Function GetMetadata() Normal parameter.
char group[128]
Package group.
Definition: pkgagent.h:57
char * DBConfFile
DB conf file location.
Definition: testRun.c:33
char release[64]
Package release.
Definition: pkgagent.h:59
char url[256]
Package link.
Definition: pkgagent.h:62
int req_size
Package dependency list size.
Definition: pkgagent.h:69
PGconn * fo_dbconnect(char *DBConfFile, char **ErrorBuf)
Connect to a database. The default is Db.conf.
Definition: libfossdb.c:40
void test_GetMetadata_wrong_testfile()
Test pkgagent.c Function GetMetadata() Wrong test file.