- Timestamp:
- Aug 7, 2011, 5:22:38 PM (14 years ago)
- Location:
- php/trunk/unittest/rdftestcases
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
php/trunk/unittest/rdftestcases/help.txt
r64 r65 5 5 6 6 help - display this help 7 list - list names of testcase categories 7 list - list testcase categories 8 listverbose - list testcase categories and testcase names 9 listexceptions - list testcases not being executed 8 10 9 11 all - execute RDF Test Casesof all categories -
php/trunk/unittest/rdftestcases/makefile
r64 r65 53 53 listverbose: 54 54 @php action.php listverbose 55 56 listexceptions: 57 @echo Testcase exceptions 58 @echo ------------------- 59 @type exception.lst 55 60 56 61 PositiveParserTest: -
php/trunk/unittest/rdftestcases/rdftestcases.php
r64 r65 25 25 26 26 private $rdfDataManifest; 27 private $exceptions; 27 28 28 29 // -------------------------------------------------------- … … 31 32 32 33 $remoteManifest = 'http://www.w3.org/2000/10/rdf-tests/rdfcore/Manifest.rdf'; 33 $localManifest = 'Manifest.rdf';34 $localManifest = getenv('tmp').'/RDFTestcases_Manifest.rdf'; 34 35 35 36 $aNamespace = array( 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', … … 49 50 } 50 51 $result = $this->rdfDataManifest->parse( $localManifest); 52 53 // load exception list 54 $this->exceptions = explode( "\r\n", file_get_contents( 'exception.lst')); 51 55 52 56 } // public function __construct … … 77 81 78 82 // create name attribute from URI 83 // unshring URI values 79 84 foreach ($testcases as $testcase) { 80 85 $testcase->name = $this->_caseNameFromSubject( $testcase->getSubject()); 86 $testcase->input = $this->rdfDataManifest->_resolve( $testcase->input); 87 $testcase->output = $this->rdfDataManifest->_resolve( $testcase->output); 88 $testcase->conclusion = $this->rdfDataManifest->_resolve( $testcase->conclusion); 81 89 } 82 90 … … 98 106 $testcases = array(); 99 107 foreach ( $uriTestcases as $uriTestcase) { 108 109 // don't execute if in exception list 110 if (array_search( $this->_caseNameFromSubject( $uriTestcase), $this->exceptions) !== false) 111 continue; 112 113 100 114 if ($this->rdfDataManifest->_getFirstValue( $uriTestcase, 'test:status') == 'APPROVED') 101 115 $testcases[] = $uriTestcase; … … 104 118 return $testcases; 105 119 106 } // private function _ searchApprovedTestcases120 } // private function _getApprovedTestcaseSubjects 107 121 108 122 109 123 private function _countApprovedTestcases( $category) { 110 124 111 $uriTestcases = $this->rdfDataManifest->getSubjects( 'rdf:type', "test:$category"); 112 $count = 0; 113 foreach ( $uriTestcases as $uriTestcase) { 114 if ($this->rdfDataManifest->_getFirstValue( $uriTestcase, 'test:status') == 'APPROVED') 115 $count += 1; 116 } 117 118 return $count; 125 return count( $this->_getApprovedTestcaseSubjects( $category)); 119 126 120 127 } // private function _countApprovedTestcases … … 166 173 } 167 174 echo "$count cases for: $category\n\n"; 168 169 175 } else { 170 176 $count = $this->_countApprovedTestcases( $category); 171 177 echo " $category $count cases\n"; 172 178 } 173 174 175 179 } 176 180 -
php/trunk/unittest/rdftestcases/unittest.php
r64 r65 32 32 // rune once initializer 33 33 public static function setUpBeforeClass() { 34 35 // create manifest data object 34 36 self::$manifest = new RDFTestCasesManifest; 37 35 38 } 36 39 … … 57 60 // helper: write input and output data to new output 58 61 // directory for manual examination 59 private function _writeErrorData( $testcase, 60 $source, $sourceuri, 61 $result, $resulturi) { 62 if (!is_dir( $testcase)) 63 mkdir( $testcase, NULL, true); 64 65 $orgsource = file_get_contents( $sourceuri); 66 file_put_contents ( "$testcase/org_source.txt" , $orgsource); 67 68 $orgresult = file_get_contents( $resulturi); 69 file_put_contents ( "$testcase/org_result.txt" , $orgresult); 70 71 file_put_contents ( "$testcase/parsed_source.txt" , $source); 72 file_put_contents ( "$testcase/parsed_result.txt" , $result); 62 private function _writeErrorData( $testcase, $source, $result) { 63 if (!is_dir( $testcase->name)) 64 mkdir( $testcase->name, NULL, true); 65 66 $orgsource = file_get_contents( $testcase->input); 67 file_put_contents ( $testcase->name."/org_source.txt" , $orgsource); 68 69 $orgresult = file_get_contents( $testcase->output); 70 file_put_contents ( $testcase->name."/org_result.txt" , $orgresult); 71 72 file_put_contents ( $testcase->name."/parsed_source.txt" , $source); 73 file_put_contents ( $testcase->name."/parsed_result.txt" , $result); 73 74 } 74 75 … … 85 86 } // private function _getSerializedData 86 87 88 // -------------------------------------------------------- 89 90 public function _executePositiveParserTest( $testcase) { 91 92 // read source data 93 $source = $this->_getSerializedData( $testcase->input); 94 $this->assertEquals( ($source !== false), true); 95 96 // read target data 97 $result = $this->_getSerializedData( $testcase->output); 98 $this->assertEquals( ($result !== false), true); 99 100 // resolve problems with blnak node identifiers 101 // and different sorting of triples 102 $source = $this->_refineResult( $source); 103 $result = $this->_refineResult( $result); 104 105 // check if results are equal 106 $success = ($source == $result); 107 108 // in case of error, write serialized data to subdirectory 109 if (!$success) 110 $this->_writeErrorData( $testcase, 111 $source, 112 $result); 113 114 // compare source and target data 115 $this->assertEquals( $success, true); 116 117 } // public function test_parse_sparql() 118 87 119 88 120 // -------------------------------------------------------- … … 90 122 public function test() { 91 123 92 $ type= trim( getenv( 'CATEGORY'));93 if ($ type== '')94 $ types = self::$manifest->getCategories();124 $category = trim( getenv( 'CATEGORY')); 125 if ($category == '') 126 $categories = self::$manifest->getCategories(); 95 127 else 96 $ types = array( $type);97 98 foreach ($types as $type) {99 echo "\nExecuting RDF Test Cases of category: $type\n\n";100 101 $testcases = self::$manifest->getParserTests( $type);102 128 $categories = array( $type); 129 130 // run test 131 // NOTE: all assertions are made in the specific test routine 132 foreach ($categories as $category) { 133 echo "\nExecuting RDF Test Cases of category: $category\n\n"; 134 $testcases = self::$manifest->getParserTests( $category); 103 135 foreach ($testcases as $testcase) { 104 echo " Executing: " . $testcase->name . "\n"; 105 $this->assertEquals( 0, 0); 136 137 echo " Executing: " . $testcase->name . "\n"; 138 switch ($category) { 139 case 'PositiveParserTest': 140 $result = $this->_executePositiveParserTest( $testcase); 141 break; 142 } // switch ($category) 106 143 } 107 144 } … … 156 193 echo 'Input: ' . $testcase->input . "\n"; 157 194 echo 'Output: ' . $testcase->output . "\n"; 158 echo 'Conclu ision: ' . $testcase->conclusion . "\n";195 echo 'Conclusion: ' . $testcase->conclusion . "\n"; 159 196 } 160 197 }
Note:
See TracChangeset
for help on using the changeset viewer.