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