FOSSology  4.4.0
Open Source License Compliance by Open Source Software
tReadInFile.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
18 // The require below needs to be fixed up once we know where the class
19 // file should go.
20 require_once ('../../../tests/fossologyUnitTestCase.php');
21 require_once ('../Classes/ReadInputFile.php');
22 
23 class TestReadinFile extends fossologyUnitTestCase
24 {
25  /* need a set up here, need to have a file to read in the correct
26  * format.
27  *
28  * Dang, just hardcode for now...
29  */
30 
31  /*
32  * Test case, no file, should not get a file resource
33  */
34 
35  function TestNoInputFile()
36  {
37  $RF = new ReadInputFile(" ");
38  $this->assert_Notresource($RF->file_resource);
39  }
40 
41  /* Test Case
42  * Use a test input file., Should get a file resouce back.
43  */
44  function TestResource()
45  {
46  $Rif = new ReadInputFile('/home/markd/workspace/fossology/utils/freshmeat/tests/tfile_small');
47 
48  /* make sure we have a resource */
49  $this->assert_resource($Rif->file_resource);
50  }
51 
52  /* Test Case
53  * Get all lines of data, check for comments or blank lines, Fail if we
54  * find any....
55  */
56  function TestForCommentBlankLine()
57  {
58  $Rif = new ReadInputFile('/home/markd/workspace/fossology/utils/freshmeat/tests/tfile_comment');
59  //print "DB: T4CBL: Before While loop, file res is: ";
60  //$this->dump($Rif->file_resource);
61  $line = $Rif->getline($Rif->file_resource);
62  while ($line = $Rif->getline($Rif->file_resource))
63  {
64  // print "DB: T4BCL line is:$line\n";
65  $this->assert_NoPattern('/^#/', $line);
66  $this->assert_NoPattern('//', $line);
67  $line = $Rif->getline($Rif->file_resource);
68  }
69  $this->pass("TestForCommentBlankLine Passed\n");
70  }
71  /* Test Case
72  * Read the complete file, make sure eof is dealt with correctly.
73  */
74 
75  function TestEof()
76  {
77  $Rif = new ReadInputFile('/home/markd/workspace/fossology/utils/freshmeat/tests/tfile_medium');
78  while ($line = $Rif->getline($Rif->file_resource))
79  {
80  continue;
81  }
82  if (empty ($line))
83  {
84  $this->pass("TestEof Passed\n");
85  }
86  }
87 }