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