FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
ft_cliPkgagentTest.php
Go to the documentation of this file.
1 <?php
2 /***************************************************************
3  Copyright (C) 2011 Hewlett-Packard Development Company, L.P.
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  version 2 as published by the Free Software Foundation.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 
18  ***************************************************************/
19 
29 require_once (__DIR__ . "/../../../testing/db/createEmptyTestEnvironment.php");
30 
35 class ft_cliPkgagentTest extends \PHPUnit\Framework\TestCase {
36 
37  public $agentDir;
38  public $pkgagent;
39  protected $testfile = '../testdata/fossology-1.2.0-1.el5.i386.rpm';
40  private $db_conf;
41 
46  function setUp() {
47 /*
48  $AGENTDIR = NULL;
49  // determine where the agents are installed
50  $upStream = '/usr/local/share/fossology/php/pathinclude.php';
51  $pkg = '/usr/share/fossology/php/pathinclude.php';
52 
53  if (file_exists($upStream)) {
54  require $upStream;
55  //print "agentdir is:$AGENTDIR\n";
56  $this->agentDir = $AGENTDIR;
57  $this->pkgagent = $this->agentDir . '/pkgagent';
58  } else
59  if (file_exists($pkg)) {
60  require $pkg;
61  //print "agentdir is:$AGENTDIR\n";
62  $this->agentDir = $AGENTDIR;
63  $this->pkgagent = $this->agentDir . '/pkgagent';
64  } else {
65  $this->assertFileExists($upStream, $message = 'FATAL: cannot find pathinclude.php file, stopping test\n');
66  }
67 */
68  //print "agent:$this->agentDir\npkgagent:$this->pkgagent\n";
69 
70  $cwd = getcwd();
71  list($test_name, $this->db_conf, $DB_NAME, $PG_CONN) = setupTestEnv($cwd, "pkgagent");
72 
73  $this->agentDir = '../../agent';
74  $this->pkgagent = $this->agentDir .'/pkgagent -c ' . $this->db_conf;
75  return;
76  } // setUP
77 
84  function testHelp() {
85  // pkgagent -h
86  $rtn = NULL;
87  $last = exec("$this->pkgagent -h 2>&1", $usageOut, $rtn);
88  //print "testHelp: last is:$last\nusageout is:\n";
89  //print_r($usageOut) . "\n";
90  // Check a couple of options for sanity
91  $usage = "Usage: $this->agentDir/pkgagent [options] [file [file [...]]";
92  $dashI = '-i :: initialize the database, then exit.';
93  $this->assertEquals($usage, $usageOut[0]);
94  $this->assertEquals($dashI, trim($usageOut[1]));
95  return;
96  }
97 
104  function testI() {
105  // pkgagent -i
106  $rtn = NULL;
107  $last = exec("$this->pkgagent -i 2>&1", $got, $rtn);
108 
109  if($rtn != 0){
110  $this->fail("pkgagent FAILED!, return value is:$rtn\n");
111  }else{
112  $this->assertTrue(true);
113  }
114  if(!empty($got)) {
115  $this->fail("pkgagent FAILED! output in -i test\n");
116  print_r($got) . "\n";
117  }
118  return;
119  }
120 
127  function testOneRPM()
128  {
129  // pkgagent rpmfile
130 
131  $expected = array('Name:fossology',
132  'Arch:i386',
133  'License:GPLv2',
134  'Summary:FOSSology is a licenses exploration tool',
135  'OK'
136  );
137  $rtn = NULL;
138  $last = exec("$this->pkgagent -C $this->testfile 2>&1", $got, $rtn);
139  //print "testOneRpm: last is:$last\ngot is:\n";
140  //print_r($got) . "\n";
141  //$this->assertEquals($expected[0],$got[0]);
142  if(empty($got)){
143  $this->fail("pkgagent FAILED!, no output for test, stopping test");
144  exit(1);
145  }
146  $size = count($got);
147  foreach($expected as $match) {
148  if(FALSE === in_array($match, $got)){
149  $this->fail("pkgagent FAILED! did not fine $match in output\n");
150  }
151  }
152  $this->assertEquals('OK',$got[$size-1]);
153  return;
154  }
155 
162  function testOneRPMV()
163  {
164  // pkgagent -v rpmfile
165  $rtn = NULL;
166  $last = exec("$this->pkgagent -C -vv $this->testfile 2>&1", $got, $rtn);
167  //print "testOneRpm: last is:$last\ngot is:\n";
168  //print_r($got) . "\n";
169  // check the output
170  if(empty($got)){
171  $this->fail("pkgagent FAILED!, no output for -vv test, stopping test");
172  exit(1);
173  }
174  // compare output to the standard
175  /*look in the output for items that should be in the header
176  * e.g.
177  * Name:fossology
178  * Arch:i386
179  * License:GPLv2
180  * Summary:FOSSology is a licenses exploration tool
181  * Size:44
182  * Name:fossology-1.2.0-1.el5.src.rpm
183  * OK
184  */
185  $expected = array('Name:fossology',
186  'Arch:i386',
187  'License:GPLv2',
188  'Summary:FOSSology is a licenses exploration tool',
189  'Size:44',
190  'Name:fossology-1.2.0-1.el5.src.rpm',
191  'OK'
192  );
193  $size = count($got);
194  foreach($expected as $match) {
195  if(FALSE === in_array($match, $got)){
196  $this->fail("pkgagent FAILED! did not fine $match in output\n");
197  }
198  }
199  $this->assertEquals('OK',$got[$size-1]);
200  return;
201  }
202 }
203 ?>
testI()
Test DB init flag.
testHelp()
Test help message.
testOneRPMV()
Test CLI in verbose with one RPM.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:321
Test cli parameter i and v and rpm file and no parameters.
testOneRPM()
Test CLI with single RPM.
setUp()
Set up test environment.
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695