FOSSology  4.6.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  const char *expectedBinary = "fossology, fossology-common, fossology-web, "
28  "fossology-web-single, fossology-scheduler, "
29  "fossology-scheduler-single, fossology-db, fossology-agents, "
30  "fossology-agents-single, fossology-dev";
31  struct debpkginfo *pi;
32  //char *DBConfFile = NULL; /* use default Db.conf */
33  char *ErrorBuf;
34 
35  pi = (struct debpkginfo *)malloc(sizeof(struct debpkginfo));
36  memset(pi, 0, sizeof(struct debpkginfo));
37  int predictValue = 0;
38  db_conn = fo_dbconnect(DBConfFile, &ErrorBuf);
39  strcpy(pi->version, "");
40  int Result = GetMetadataDebSource(repFile, pi);
41  //printf("GetMetadataDebSource Result is:%d\n", Result);
42 
43  //printf("GetMetadataDebSource Result is:%s\n", pi->version);
44  CU_ASSERT_STRING_EQUAL(pi->pkgName, expectedBinary);
45  CU_ASSERT_STRING_EQUAL(pi->source, "fossology");
46  CU_ASSERT_STRING_EQUAL(pi->pkgArch, "any");
47  CU_ASSERT_STRING_EQUAL(pi->version, "1.4.1");
48  CU_ASSERT_STRING_EQUAL(pi->maintainer, "Matt Taggart <taggart@debian.org>");
49  CU_ASSERT_STRING_EQUAL(pi->homepage, "http://fossology.org");
50  CU_ASSERT_EQUAL(pi->dep_size, 13);
51 
52  PQfinish(db_conn);
53  int i;
54  for(i=0; i< pi->dep_size;i++)
55  free(pi->depends[i]);
56  free(pi->depends);
57  memset(pi, 0, sizeof(struct debpkginfo));
58  free(pi);
59  CU_ASSERT_EQUAL(Result, predictValue);
60 }
61 
71 {
72  char *repFile = "./testdata/fossology-1.2.0-1.el5.i386.rpm";
73  struct debpkginfo *pi;
74  char *ErrorBuf;
75 
76  pi = (struct debpkginfo *)malloc(sizeof(struct debpkginfo));
77  memset(pi, 0, sizeof(struct debpkginfo));
78  int predictValue = 0; /* FIXED: seems pkgagent have bug here. */
79  db_conn = fo_dbconnect(DBConfFile, &ErrorBuf);
80  int Result = GetMetadataDebSource(repFile, pi);
81  //printf("GetMetadataDebSource Result is:%d\n", Result);
82 
83  PQfinish(db_conn);
84  int i;
85  for(i=0; i< pi->dep_size;i++)
86  free(pi->depends[i]);
87  free(pi->depends);
88  memset(pi, 0, sizeof(struct debpkginfo));
89  free(pi);
90  CU_ASSERT_EQUAL(Result, predictValue);
91 }
92 
97  {"Testing the function GetMetadataDebSource", test_GetMetadataDebSource},
98  {"Testing the function GetMetadataDebSource with wrong testfile", test_GetMetadataDebSource_wrong_testfile},
99  CU_TEST_INFO_NULL
100 };
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:949
PGconn * db_conn
The connection to Database.
Definition: pkgagent.c:22
pkgagent header
Holds meta info of Debian packages.
Definition: pkgagent.h:68
char ** depends
Package dependency list.
Definition: pkgagent.h:82
char version[MAXCMD]
Package version.
Definition: pkgagent.h:71
char maintainer[MAXCMD]
Package maintainer.
Definition: pkgagent.h:76
char pkgArch[MAXCMD]
Package architecture.
Definition: pkgagent.h:74
int dep_size
Package dependency list size.
Definition: pkgagent.h:83
char source[MAXCMD]
Package source.
Definition: pkgagent.h:70
char pkgName[MAXCMD]
Package name.
Definition: pkgagent.h:69
char homepage[MAXCMD]
Package link.
Definition: pkgagent.h:77
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