Changeset 65 for php


Ignore:
Timestamp:
Aug 7, 2011, 5:22:38 PM (14 years ago)
Author:
cla
Message:

rdfint

  • added execution of positive parser tests
  • added exception list
Location:
php/trunk/unittest/rdftestcases
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • php/trunk/unittest/rdftestcases/help.txt

    r64 r65  
    55
    66   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
    810
    911   all                    - execute RDF Test Casesof all categories
  • php/trunk/unittest/rdftestcases/makefile

    r64 r65  
    5353listverbose:
    5454        @php action.php listverbose
     55       
     56listexceptions:
     57        @echo Testcase exceptions
     58        @echo -------------------
     59        @type exception.lst
    5560
    5661PositiveParserTest:
  • php/trunk/unittest/rdftestcases/rdftestcases.php

    r64 r65  
    2525
    2626  private $rdfDataManifest;
     27  private $exceptions;
    2728
    2829  // --------------------------------------------------------
     
    3132
    3233    $remoteManifest = 'http://www.w3.org/2000/10/rdf-tests/rdfcore/Manifest.rdf';
    33     $localManifest  = 'Manifest.rdf';
     34    $localManifest  = getenv('tmp').'/RDFTestcases_Manifest.rdf';
    3435
    3536    $aNamespace = array( 'rdf'      => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
     
    4950    }
    5051    $result = $this->rdfDataManifest->parse( $localManifest);
     52
     53    // load exception list
     54    $this->exceptions = explode( "\r\n", file_get_contents( 'exception.lst'));
    5155
    5256  } // public function __construct
     
    7781
    7882    // create name attribute from URI
     83    // unshring URI values
    7984    foreach ($testcases as $testcase) {
    8085      $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);
    8189    }
    8290
     
    98106    $testcases = array();
    99107    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
    100114      if ($this->rdfDataManifest->_getFirstValue( $uriTestcase, 'test:status') == 'APPROVED')
    101115        $testcases[] = $uriTestcase;
     
    104118    return $testcases;
    105119
    106   } // private function _searchApprovedTestcases
     120  } // private function _getApprovedTestcaseSubjects
    107121
    108122
    109123  private function _countApprovedTestcases( $category) {
    110124
    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));
    119126
    120127  } // private function _countApprovedTestcases
     
    166173        }
    167174      echo "$count cases for: $category\n\n";
    168 
    169175      } else {
    170176        $count = $this->_countApprovedTestcases( $category);
    171177        echo "   $category     $count cases\n";
    172178      }
    173 
    174 
    175179    }
    176180
  • php/trunk/unittest/rdftestcases/unittest.php

    r64 r65  
    3232  // rune once initializer
    3333  public static function setUpBeforeClass() {
     34
     35    // create manifest data object
    3436    self::$manifest = new RDFTestCasesManifest;
     37
    3538  }
    3639
     
    5760  // helper: write input and output data to new output
    5861  // 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);
    7374  }
    7475
     
    8586  } // private function _getSerializedData
    8687
     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
    87119
    88120  // --------------------------------------------------------
     
    90122  public function test() {
    91123
    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();
    95127    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);
    103135      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)
    106143      }
    107144    }
     
    156193      echo 'Input: ' . $testcase->input . "\n";
    157194      echo 'Output: ' . $testcase->output . "\n";
    158       echo 'Concluision: ' . $testcase->conclusion . "\n";
     195      echo 'Conclusion: ' . $testcase->conclusion . "\n";
    159196    }
    160197  }
Note: See TracChangeset for help on using the changeset viewer.