-
Notifications
You must be signed in to change notification settings - Fork 2
/
QueryEvaluationTest.php
219 lines (195 loc) · 7.61 KB
/
QueryEvaluationTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
class QueryEvaluationTest {
function countAllTests(){
global $modeDebug,$modeVerbose,$ENDPOINT,$GRAPHTESTS ;
$ENDPOINT->ResetErrors();
$q = Test::PREFIX.'
SELECT (COUNT(?s) AS ?count) WHERE {
GRAPH <'.$GRAPHTESTS.'> { ?s a mf:QueryEvaluationTest ;
dawgt:approval dawgt:Approved.}} ';
$res = $ENDPOINT->query($q, 'row');
$err = $ENDPOINT->getErrors();
if ($err) {
return -1;
}
return $res["count"];
}
function countSkipTests(){
global $modeDebug,$modeVerbose,$ENDPOINT,$GRAPHTESTS;
$ENDPOINT->ResetErrors();
$q = Test::PREFIX.'
SELECT (COUNT(?s) AS ?count) WHERE {
GRAPH <'.$GRAPHTESTS .'> { ?s a mf:QueryEvaluationTest ;
dawgt:approval dawgt:NotClassified .}} ';
$res = $ENDPOINT->query($q, 'row');
$err = $ENDPOINT->getErrors();
if ($err) {
return -1;
}
return $res["count"];
}
static function countApprovedTests(){
global $modeDebug,$modeVerbose,$ENDPOINT,$GRAPHTESTS;
$ENDPOINT->ResetErrors();
$q = Test::PREFIX.'
SELECT (COUNT(DISTINCT ?s) AS ?count) WHERE {
GRAPH <'.$GRAPHTESTS .'> { ?s a mf:QueryEvaluationTest ;
dawgt:approval dawgt:Approved .}} ';
$res = $ENDPOINT->query($q, 'row');
$err = $ENDPOINT->getErrors();
if ($err) {
return -1;
}
return $res["count"];
}
static function doAllTests(){
global $modeDebug,$modeVerbose,$ENDPOINT,$CURL,$GRAPHTESTS,$GRAPH_RESULTS_EARL,$TAGTESTS;
//////////////////////////////////////////////////////////////////////
echo "
--------------------------------------------------------------------
TESTS : QueryEvaluationTest";// ( ".QueryEvaluationTest::countApprovedTests()." Approved, ".QueryEvaluationTest::countSkipTests()." Skipped, ".QueryEvaluationTest::countAllTests()." Total\n";
$Report = new TestsReport("QueryEvaluationTest",$TAGTESTS.'-QueryEvaluationTest-junit.xml');
$q = Test::PREFIX.'
SELECT DISTINCT ?testiri ?name ?queryTest
?dataInput ?dataOutput
?dataInputExist ?graphDataInputExist ?serviceDataInputExist
?testSkipped
WHERE {
GRAPH <'.$GRAPHTESTS .'> {
#VALUES ?testiri {<http://www.w3.org/2009/sparql/docs/tests/data-sparql11/csv-tsv-res/manifest#tsv02>}
?manifest a mf:Manifest ;
mf:entries ?collection .
?collection rdf:rest*/rdf:first ?testiri .
?testiri a mf:QueryEvaluationTest ;
mf:name ?name ;
dawgt:approval dawgt:Approved ;
mf:action [
qt:query ?queryTest
] ;
mf:result ?dataOutput .
OPTIONAL {
?testiri mf:action [ qt:data ?dataInput ]
}
OPTIONAL {
?testiri mf:action [ qt:graphData ?graphDataInput ]
}
OPTIONAL {
?testiri mf:action [ qt:serviceData ?serviceDataInput ]
}
BIND(BOUND(?dataInput) AS ?dataInputExist)
BIND(BOUND(?graphDataInput) AS ?graphDataInputExist)
BIND(BOUND(?serviceDataInput) AS ?serviceDataInputExist)
#DISABLE TFT not supports tests with Entailment regime
OPTIONAL {
?testiri mf:action [ sd:EntailmentProfile ?EntailmentProfile ] ;
}
OPTIONAL {
?testiri mf:action [ sd:entailmentRegime ?entailmentRegime ] ;
}
OPTIONAL {
?testiri mf:action [ sd:supportedEntailmentProfile ?supportedEntailmentProfile ] ;
}
BIND((BOUND(?EntailmentProfile) || BOUND(?entailmentRegime) || BOUND(?supportedEntailmentProfile)) AS ?testSkipped)
}
}
ORDER BY ?testiri
';
//echo $q;
$ENDPOINT->ResetErrors();
$rows = $ENDPOINT->query($q, 'rows');
$err = $ENDPOINT->getErrors();
$iriTest = $GRAPH_RESULTS_EARL."/QueryEvaluationTest/select";
$iriAssert = $GRAPH_RESULTS_EARL."/QueryEvaluationTest/selectAssert";
$labelAssert = "Select the QueryEvaluationTest";
if ($err) {
echo "F => Cannot ".$labelAssert;
$Report->addTestCaseFailure($iriTest,$iriAssert,$labelAssert,print_r($err,true));
return;
}else{
echo ".";
$Report->addTestCasePassed($iriTest,$iriAssert,$labelAssert);
}
//Check the nb of tests
//print_r($rows);
$nbTest = count($rows["result"]["rows"]);
echo "Nb tests : ".$nbTest."\n";
//exit();
$nbApprovedTests = QueryEvaluationTest::countApprovedTests();
$iriTest = $GRAPH_RESULTS_EARL."/QueryEvaluationTest/CountTests";
$iriAssert = $GRAPH_RESULTS_EARL."/QueryEvaluationTest/CountTestsAssert";
$labelAssert = "Compare the nb of valid tests with the nb of tests in the dataset.";
if($nbTest != $nbApprovedTests ){
// echo "F";
echo "NB of tests (".$nbTest."/".$nbApprovedTests ." in theory) is incorrect.\n";
// $Report->addTestCaseFailure($iriTest,$iriAssert,$labelAssert,
// "NB of tests (".$nbTest."/".$nbApprovedTests ." in theory) is incorrect.\n TODO//220 but there are tests with several names..."
// );
}else{
// echo ".";
// $Report->addTestCasePassed($iriTest,$iriAssert,$labelAssert);
}
foreach ($rows["result"]["rows"] as $row){
$iriTest = trim($row["testiri"]);
/*
echo $iriTest;
//exit();
if(! preg_match("/exists03/i", $iriTest))
continue;
if(! preg_match("/service/i", $iriTest))
continue;
*/
$iriAssertProtocol =$row["testiri"]."/"."Protocol";
$labelAssertProtocol = trim($row["name"])." : Test the protocol.";
$iriAssertResponse =$row["testiri"]."/"."Response";
$labelAssertResponse = trim($row["name"])." : Test the response.";
if($modeVerbose){
echo "\n".$iriTest.":".trim($row["name"]).":" ;
}
$test = new Test(trim($row["queryTest"]),$iriTest);
if ($row["testSkipped"]){
echo "S";
$messageSkipped = "TFT not supports tests with Entailment regime.";
$Report->addTestCaseSkipped($iriTest,$iriAssertProtocol,$labelAssertProtocol,$messageSkipped);
echo "S";
$Report->addTestCaseSkipped($iriTest,$iriAssertResponse,$labelAssertResponse,$messageSkipped);
continue;
}
$graphName = "DEFAULT";
$test->addGraphOutput(trim($row["dataOutput"]),$graphName,$graphName);
if($row["dataInputExist"]){
$test->addGraphInput(trim($row["dataInput"]),$graphName,$graphName);
}
if($row["graphDataInputExist"]){
$test->readAndAddMultigraphInput($GRAPHTESTS,$iriTest); //todo check error http://www.w3.org/2009/sparql/docs/tests/data-sparql11/exists/exists03.rq
}
if($row["serviceDataInputExist"]){
$test->readAndAddService($GRAPHTESTS,$iriTest);
}
$test->doQuery(true,"DEFAULT");
$err = $test->GetErrors();
$fail = $test->GetFails();
if (count($err) != 0) {
echo "E";//echo "\n".$nameTestQueryPassed." ERROR";
$Report->addTestCaseError($iriTest,$iriAssertProtocol,$labelAssertProtocol,
print_r($err,true));
echo "S";//echo "\n".$nameTestQueryDataPassed." SKIP";
$Report->addTestCaseSkipped($iriTest,$iriAssertResponse,$labelAssertResponse,
"Cannot read result because test:" . $iriAssertProtocol . " is failed."
);
}else{
echo ".";//echo "\n".$nameTestQueryPassed." PASSED";
$Report->addTestCasePassed($iriTest,$iriAssertProtocol,$labelAssertProtocol);
if(count($fail) != 0){
echo "F";
$Report->addTestCaseFailure($iriTest,$iriAssertResponse,$labelAssertResponse,
print_r($fail,true));
}else{
echo ".";
$Report->addTestCasePassed($iriTest,$iriAssertResponse,$labelAssertResponse,
$test->GetTime());
}
}
}
echo "\n";
}
}