FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
tReadInFile.php
1 <?php
2 
3 
4 /***********************************************************
5  Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License
9  version 2 as published by the Free Software Foundation.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  ***********************************************************/
20 
31 // The require below needs to be fixed up once we know where the class
32 // file should go.
33 require_once ('../../../tests/fossologyUnitTestCase.php');
34 require_once ('../Classes/ReadInputFile.php');
35 
36 class TestReadinFile extends fossologyUnitTestCase
37 {
38  /* need a set up here, need to have a file to read in the correct
39  * format.
40  *
41  * Dang, just hardcode for now...
42  */
43 
44  /*
45  * Test case, no file, should not get a file resource
46  */
47 
48  function TestNoInputFile()
49  {
50  $RF = new ReadInputFile(" ");
51  $this->assert_Notresource($RF->file_resource);
52  }
53 
54  /* Test Case
55  * Use a test input file., Should get a file resouce back.
56  */
57  function TestResource()
58  {
59  $Rif = new ReadInputFile('/home/markd/workspace/fossology/utils/freshmeat/tests/tfile_small');
60 
61  /* make sure we have a resource */
62  $this->assert_resource($Rif->file_resource);
63  }
64 
65  /* Test Case
66  * Get all lines of data, check for comments or blank lines, Fail if we
67  * find any....
68  */
69  function TestForCommentBlankLine()
70  {
71  $Rif = new ReadInputFile('/home/markd/workspace/fossology/utils/freshmeat/tests/tfile_comment');
72  //print "DB: T4CBL: Before While loop, file res is: ";
73  //$this->dump($Rif->file_resource);
74  $line = $Rif->getline($Rif->file_resource);
75  while ($line = $Rif->getline($Rif->file_resource))
76  {
77  // print "DB: T4BCL line is:$line\n";
78  $this->assert_NoPattern('/^#/', $line);
79  $this->assert_NoPattern('//', $line);
80  $line = $Rif->getline($Rif->file_resource);
81  }
82  $this->pass("TestForCommentBlankLine Passed\n");
83  }
84  /* Test Case
85  * Read the complete file, make sure eof is dealt with correctly.
86  */
87 
88  function TestEof()
89  {
90  $Rif = new ReadInputFile('/home/markd/workspace/fossology/utils/freshmeat/tests/tfile_medium');
91  while ($line = $Rif->getline($Rif->file_resource))
92  {
93  continue;
94  }
95  if (empty ($line))
96  {
97  $this->pass("TestEof Passed\n");
98  }
99  }
100 }
101 ?>