00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <getopt.h>
00029 #include <errno.h>
00030 #include <string.h>
00031
00032 #include <libxml/xmlreader.h>
00033 #include <libxml/xmlschemas.h>
00034
00035 #include "testrunnerlite.h"
00036 #include "testdefinitiondatatypes.h"
00037 #include "testdefinitionparser.h"
00038 #include "log.h"
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 LOCAL td_parser_callbacks *cbs;
00066 LOCAL xmlTextReaderPtr reader;
00067 LOCAL xmlSchemaParserCtxtPtr schema_context = NULL;
00068 LOCAL xmlSchemaPtr schema = NULL;
00069 LOCAL td_td *current_td;
00070 LOCAL td_suite *current_suite;
00071 LOCAL td_set *current_set;
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 LOCAL int td_parse_gen_attribs (td_gen_attribs *,td_gen_attribs *);
00085
00086 LOCAL int td_parse_td (void);
00087
00088 LOCAL int td_parse_suite (void);
00089
00090 LOCAL int td_parse_steps (xmlListPtr, const char *);
00091
00092 LOCAL td_step *td_parse_step (int manual_default);
00093
00094 LOCAL int td_parse_case (td_set *s);
00095
00096 LOCAL int td_parse_environments(xmlListPtr);
00097
00098 LOCAL int td_parse_gets(xmlListPtr);
00099
00100 LOCAL int td_parse_set ();
00101
00102 LOCAL int td_parse_hwiddetect ();
00103
00104
00105
00106
00107
00108
00109
00110 LOCAL int td_parse_gen_attribs (td_gen_attribs *attr,
00111 td_gen_attribs *defaults)
00112 {
00113 const xmlChar *name;
00114
00115 if (defaults) {
00116 attr->timeout = defaults->timeout;
00117 attr->manual = defaults->manual;
00118 attr->insignificant = defaults->insignificant;
00119 if (defaults->requirement)
00120 attr->requirement = xmlStrdup(defaults->requirement);
00121 if (defaults->level)
00122 attr->level = xmlStrdup(defaults->level);
00123 if (defaults->type)
00124 attr->type = xmlStrdup(defaults->type);
00125 if (defaults->hwid)
00126 attr->hwid = xmlStrdup(defaults->hwid);
00127 }
00128
00129 while (xmlTextReaderMoveToNextAttribute(reader)) {
00130 name = xmlTextReaderConstName(reader);
00131 if (!xmlStrcmp (name, BAD_CAST "name")) {
00132 attr->name = xmlTextReaderValue(reader);
00133 continue;
00134 }
00135 if (!xmlStrcmp (name, BAD_CAST "timeout")) {
00136 attr->timeout = strtoul((char *)
00137 xmlTextReaderConstValue(reader),
00138 NULL, 10);
00139 continue;
00140 }
00141 if (!xmlStrcmp (name, BAD_CAST "description")) {
00142 attr->description = xmlTextReaderValue(reader);
00143 continue;
00144 }
00145 if (!xmlStrcmp (name, BAD_CAST "requirement")) {
00146 if (attr->requirement) free (attr->requirement);
00147 attr->requirement = xmlTextReaderValue(reader);
00148 continue;
00149 }
00150 if (!xmlStrcmp (name, BAD_CAST "type")) {
00151 if (attr->type) free (attr->type);
00152 attr->type = xmlTextReaderValue(reader);
00153 continue;
00154 }
00155 if (!xmlStrcmp (name, BAD_CAST "level")) {
00156 if (attr->level) free (attr->level);
00157 attr->level = xmlTextReaderValue(reader);
00158 continue;
00159 }
00160 if (!xmlStrcmp (name, BAD_CAST "domain")) {
00161 if (attr->domain) free (attr->domain);
00162 attr->domain = xmlTextReaderValue(reader);
00163 continue;
00164 }
00165 if (!xmlStrcmp (name, BAD_CAST "feature")) {
00166 if (attr->feature) free (attr->feature);
00167 attr->feature = xmlTextReaderValue(reader);
00168 continue;
00169 }
00170 if (!xmlStrcmp (name, BAD_CAST "component")) {
00171 if (attr->component) free (attr->component);
00172 attr->component = xmlTextReaderValue(reader);
00173 continue;
00174 }
00175 if (!xmlStrcmp (name, BAD_CAST "manual")) {
00176 attr->manual = !xmlStrcmp (xmlTextReaderConstValue
00177 (reader), BAD_CAST "true");
00178 continue;
00179 }
00180 if (!xmlStrcmp (name, BAD_CAST "insignificant")) {
00181 attr->insignificant =
00182 !xmlStrcmp (xmlTextReaderConstValue (reader),
00183 BAD_CAST "true");
00184 continue;
00185 }
00186 if (!xmlStrcmp (name, BAD_CAST "hwid")) {
00187 if (attr->hwid)
00188 free (attr->hwid);
00189 attr->hwid = xmlTextReaderValue(reader);
00190 continue;
00191 }
00192 }
00193 return 0;
00194 }
00195
00199 LOCAL td_step *td_parse_step(int manual_default)
00200 {
00201 const xmlChar *name;
00202 td_step *step = NULL;
00203 xmlNodePtr node;
00204 int ret;
00205
00206 step = td_step_create();
00207 step->manual = manual_default;
00208
00209 while (xmlTextReaderMoveToNextAttribute(reader)) {
00210 name = xmlTextReaderConstName(reader);
00211 if (!xmlStrcmp (name, BAD_CAST "expected_result")) {
00212 step->expected_result =
00213 strtoul((char *)xmlTextReaderConstValue(reader),
00214 NULL, 10);
00215 step->has_expected_result = 1;
00216
00217 continue;
00218 }
00219 if (!xmlStrcmp (name, BAD_CAST "manual")) {
00220 step->manual = !xmlStrcmp (xmlTextReaderConstValue
00221 (reader), BAD_CAST "true");
00222 continue;
00223 }
00224 }
00225
00226 do {
00227 ret = xmlTextReaderRead(reader);
00228 if (!ret) {
00229 LOG_MSG (LOG_ERR, "%s:%s: ReaderRead() fail\n",
00230 PROGNAME, __FUNCTION__);
00231
00232 goto ERROUT;
00233 }
00234 name = xmlTextReaderConstName(reader);
00235 if (!name) {
00236 LOG_MSG (LOG_ERR, "%s: ReaderName() fail\n",
00237 PROGNAME);
00238 goto ERROUT;
00239 }
00240
00241 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) {
00242 if (step->step)
00243 step->step = xmlStrcat
00244 (step->step,
00245 xmlTextReaderReadString (reader));
00246 else
00247 step->step = xmlTextReaderReadString (reader);
00248 }
00249
00250 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_CDATA) {
00251 node = xmlTextReaderCurrentNode (reader);
00252 if (step->step)
00253 step->step = xmlStrcat
00254 (step->step,
00255 node->content);
00256 else
00257 step->step = xmlStrdup(node->content);
00258
00259 }
00260
00261 } while (!(xmlTextReaderNodeType(reader) ==
00262 XML_READER_TYPE_END_ELEMENT &&
00263 !xmlStrcmp (name, BAD_CAST "step")));
00264
00265 return step;
00266 ERROUT:
00267 LOG_MSG (LOG_ERR, "%s:%s: Exiting with error\n",
00268 PROGNAME, __FUNCTION__);
00269 free (step);
00270
00271 return NULL;
00272 }
00273
00279 LOCAL int td_parse_steps(xmlListPtr list, const char *tag)
00280 {
00281 const xmlChar *name;
00282 td_steps *steps = NULL;
00283 td_step *step = NULL;
00284 int ret;
00285
00286 steps = td_steps_create();
00287
00288 if (!steps) {
00289 goto ERROUT;
00290 }
00291
00292 if (xmlTextReaderMoveToAttribute (reader, BAD_CAST "timeout") == 1) {
00293 steps->timeout = strtoul((char *)
00294 xmlTextReaderConstValue(reader),
00295 NULL, 10);
00296 }
00297
00298 do {
00299 ret = xmlTextReaderRead(reader);
00300 if (!ret) {
00301 LOG_MSG (LOG_ERR, "%s: ReaderRead() fail\n",
00302 PROGNAME);
00303 goto ERROUT;
00304 }
00305
00306 name = xmlTextReaderConstName(reader);
00307 if (!name) {
00308 LOG_MSG (LOG_ERR, "%s: ReaderName() fail\n",
00309 PROGNAME);
00310 goto ERROUT;
00311 }
00312
00313 if (xmlTextReaderNodeType(reader) ==
00314 XML_READER_TYPE_ELEMENT &&
00315 !xmlStrcmp (name, BAD_CAST "step")) {
00316 step = td_parse_step (current_set->gen.manual);
00317 if (!step)
00318 goto ERROUT;
00319 if (xmlListAppend (steps->steps, step)) {
00320 LOG_MSG (LOG_ERR, "%s: list insert failed\n",
00321 PROGNAME);
00322 goto ERROUT;
00323 }
00324 }
00325 } while (!(xmlTextReaderNodeType(reader) ==
00326 XML_READER_TYPE_END_ELEMENT &&
00327 !xmlStrcmp (name, BAD_CAST tag)));
00328
00329 xmlListAppend (list, steps);
00330
00331 return 0;
00332 ERROUT:
00333 LOG_MSG (LOG_ERR, "%s:%s: Exiting with error\n",
00334 PROGNAME, __FUNCTION__);
00335 xmlListDelete (steps->steps);
00336 free(steps);
00337 return 1;
00338 }
00339
00344 LOCAL int td_parse_case(td_set *s)
00345 {
00346 const xmlChar *name;
00347 td_step *step = NULL;
00348 td_case *c = NULL;
00349 int ret;
00350
00351 c = td_case_create();
00352 if (!c)
00353 goto ERROUT;
00354
00355 if (td_parse_gen_attribs (&c->gen, &s->gen))
00356 goto ERROUT;
00357
00358 if (xmlTextReaderMoveToAttribute (reader,
00359 BAD_CAST "subfeature") == 1) {
00360 c->subfeature = xmlTextReaderValue(reader);
00361 }
00362
00363 do {
00364 ret = xmlTextReaderRead(reader);
00365 if (!ret) {
00366 LOG_MSG (LOG_ERR, "%s: ReaderRead() fail\n",
00367 PROGNAME);
00368
00369 goto ERROUT;
00370 }
00371 name = xmlTextReaderConstName(reader);
00372 if (!name) {
00373 LOG_MSG (LOG_ERR, "%s: ReaderName() fail\n",
00374 PROGNAME);
00375 goto ERROUT;
00376 }
00377 if (xmlTextReaderNodeType(reader) ==
00378 XML_READER_TYPE_ELEMENT &&
00379 !xmlStrcmp (name, BAD_CAST "step")) {
00380 step = td_parse_step (c->gen.manual);
00381 if (!step)
00382 goto ERROUT;
00383 if (xmlListAppend (c->steps, step)) {
00384 LOG_MSG (LOG_ERR, "%s: list insert failed\n",
00385 PROGNAME);
00386 goto ERROUT;
00387 }
00388 }
00389 if (xmlTextReaderNodeType(reader) ==
00390 XML_READER_TYPE_ELEMENT &&
00391 !xmlStrcmp (name, BAD_CAST "TC_Title")) {
00392 c->tc_title = xmlTextReaderReadString (reader);
00393
00394 }
00395 if (xmlTextReaderNodeType(reader) ==
00396 XML_READER_TYPE_ELEMENT &&
00397 !xmlStrcmp (name, BAD_CAST "state")) {
00398 c->state = xmlTextReaderReadString (reader);
00399
00400 }
00401 if (xmlTextReaderNodeType(reader) ==
00402 XML_READER_TYPE_ELEMENT &&
00403 !xmlStrcmp (name, BAD_CAST "description")) {
00404 if (c->gen.description) {
00405 c->gen.description = xmlStrcat
00406 (c->gen.description,
00407 BAD_CAST " - ");
00408 c->gen.description = xmlStrcat
00409 (c->gen.description,
00410 BAD_CAST
00411 xmlTextReaderReadString (reader));
00412 }
00413 else
00414 c->gen.description = xmlTextReaderReadString(reader);
00415 }
00416
00417
00418 } while (!(xmlTextReaderNodeType(reader) ==
00419 XML_READER_TYPE_END_ELEMENT &&
00420 !xmlStrcmp (name, BAD_CAST "case")));
00421
00422 xmlListAppend (s->cases, c);
00423
00424 return 0;
00425 ERROUT:
00426 LOG_MSG (LOG_ERR, "%s:%s: Exiting with error\n",
00427 PROGNAME, __FUNCTION__);
00428 xmlListDelete (c->steps);
00429 if (c->gen.name) free (c->gen.name);
00430 if (c->gen.description) free (c->gen.description);
00431 free (c);
00432 return 1;
00433 }
00434
00439 LOCAL int td_parse_environments(xmlListPtr list)
00440 {
00441 int ret;
00442 const xmlChar *name;
00443 xmlChar *value;
00444
00445 do {
00446 ret = xmlTextReaderRead(reader);
00447 if (!ret) {
00448 LOG_MSG (LOG_ERR, "%s:%s: ReaderRead() fail\n",
00449 PROGNAME, __FUNCTION__);
00450
00451 goto ERROUT;
00452 }
00453
00454 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT) {
00455 name = xmlTextReaderConstName(reader);
00456 if (!name) {
00457 LOG_MSG (LOG_ERR, "%s:%s: ReaderName() "
00458 "fail\n",
00459 PROGNAME, __FUNCTION__);
00460 goto ERROUT;
00461 }
00462 }
00463
00464 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) {
00465 value = xmlTextReaderReadString (reader);
00466 if (!xmlStrcmp (value, BAD_CAST "false")) {
00467 xmlListRemoveAll (list, (void *)name);
00468 }
00469 free (value);
00470 }
00471 } while (!(xmlTextReaderNodeType(reader) ==
00472 XML_READER_TYPE_END_ELEMENT &&
00473 !xmlStrcmp (xmlTextReaderConstName(reader),
00474 BAD_CAST "environments")));
00475
00476 return 0;
00477 ERROUT:
00478 LOG_MSG (LOG_ERR, "%s:%s: Exiting with error\n",
00479 PROGNAME, __FUNCTION__);
00480 return 1;
00481 }
00482
00487 LOCAL int td_parse_gets(xmlListPtr list)
00488 {
00489 int ret;
00490 int delete_after = 0;
00491 td_file *file;
00492
00493 do {
00494
00495 ret = xmlTextReaderRead(reader);
00496 if (!ret) {
00497 LOG_MSG (LOG_ERR, "%s:%s: ReaderRead() fail\n",
00498 PROGNAME, __FUNCTION__);
00499
00500 goto ERROUT;
00501 }
00502
00503 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT &&
00504 xmlTextReaderMoveToNextAttribute(reader) == 1) {
00505 delete_after = !xmlStrcmp (xmlTextReaderConstValue
00506 (reader),
00507 BAD_CAST "true");
00508 }
00509
00510
00511 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT) {
00512 file = (td_file *)malloc (sizeof (td_file));
00513 file->filename = xmlTextReaderReadString (reader);
00514 file->delete_after = delete_after;
00515 delete_after = 0;
00516 if (xmlListAppend (list, file)) {
00517 LOG_MSG (LOG_ERR,
00518 "%s:%s list insert failed\n",
00519 PROGNAME, __FUNCTION__);
00520 goto ERROUT;
00521 }
00522
00523 }
00524 } while (!(xmlTextReaderNodeType(reader) ==
00525 XML_READER_TYPE_END_ELEMENT &&
00526 !xmlStrcmp (xmlTextReaderConstName(reader),
00527 BAD_CAST "get")));
00528
00529 return 0;
00530 ERROUT:
00531 LOG_MSG (LOG_ERR, "%s:%s: Exiting with error\n",
00532 PROGNAME, __FUNCTION__);
00533 return 1;
00534 }
00535
00539 LOCAL int td_parse_suite ()
00540 {
00541 td_suite *s;
00542
00543 if (!cbs->test_suite)
00544 return 1;
00545
00546 s = td_suite_create();
00547 if (!s) return 1;
00548
00549 current_suite = s;
00550
00551 td_parse_gen_attribs (&s->gen, NULL);
00552 cbs->test_suite(s);
00553
00554 return 0;
00555 }
00556
00560 LOCAL int td_parse_set ()
00561 {
00562 int ret = 0;
00563 td_set *s;
00564 const xmlChar *name;
00565
00566 if (!cbs->test_set)
00567 return 1;
00568 s = td_set_create ();
00569 current_set = s;
00570
00571 if (td_parse_gen_attribs(&s->gen, ¤t_suite->gen))
00572 goto ERROUT;
00573
00574 do {
00575 ret = xmlTextReaderRead(reader);
00576 if (!ret) {
00577 LOG_MSG (LOG_ERR, "%s:%s: ReaderRead() fail\n",
00578 PROGNAME, __FUNCTION__);
00579
00580 goto ERROUT;
00581 }
00582 name = xmlTextReaderConstName(reader);
00583 if (!name) {
00584 LOG_MSG (LOG_ERR, "%s: ReaderName() fail\n",
00585 PROGNAME);
00586 goto ERROUT;
00587 }
00588 if (!xmlStrcmp (name, BAD_CAST "pre_steps"))
00589 ret = !td_parse_steps(s->pre_steps, "pre_steps");
00590 if (!xmlStrcmp (name, BAD_CAST "post_steps"))
00591 ret = !td_parse_steps(s->post_steps, "post_steps");
00592 if (!xmlStrcmp (name, BAD_CAST "case"))
00593 ret = !td_parse_case(s);
00594 if (!xmlStrcmp (name, BAD_CAST "environments"))
00595 ret = !td_parse_environments(s->environments);
00596 if (!xmlStrcmp (name, BAD_CAST "get"))
00597 ret = !td_parse_gets(s->gets);
00598
00599 if (!ret)
00600 goto ERROUT;
00601 } while (!(xmlTextReaderNodeType(reader) ==
00602 XML_READER_TYPE_END_ELEMENT &&
00603 !xmlStrcmp (name, BAD_CAST "set")));
00604 cbs->test_set(s);
00605
00606 return 0;
00607 ERROUT:
00608 LOG_MSG (LOG_ERR, "%s:%s: Exiting with error\n",
00609 PROGNAME, __FUNCTION__);
00610
00611 return 1;
00612 }
00613
00617 LOCAL int td_parse_td ()
00618 {
00619 td_td *td;
00620
00621 td = td_td_create();
00622 if (!td)
00623 return 1;
00624
00625 current_td = td;
00626 if (cbs->test_td)
00627 cbs->test_td(td);
00628
00629 return 0;
00630 }
00631
00635 LOCAL int td_parse_hwiddetect ()
00636 {
00637 int ret;
00638 const xmlChar *name;
00639
00640 do {
00641 if (xmlTextReaderHasValue(reader) > 0) {
00642 current_td->hw_detector = xmlTextReaderValue(reader);
00643 LOG_MSG (LOG_INFO, "HW ID dectector command: %s",
00644 current_td->hw_detector);
00645 }
00646 ret = xmlTextReaderRead(reader);
00647 name = xmlTextReaderConstName(reader);
00648 }
00649 while(xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT &&
00650 xmlStrcmp (name, BAD_CAST "hwiddetect"));
00651
00652
00653 if (cbs->test_hwiddetect) {
00654 cbs->test_hwiddetect();
00655 }
00656
00657 return 0;
00658 }
00659
00660
00661
00662
00667 int parse_test_definition (testrunner_lite_options *opts)
00668 {
00669 int ret = TESTRUNNER_LITE_XML_PARSE_FAIL;
00670 xmlDocPtr doc = NULL;
00671 xmlParserCtxtPtr ctxt = NULL;
00672 xmlSchemaPtr sch = NULL;
00673 xmlSchemaValidCtxtPtr valid_ctxt = NULL;
00674 xmlSchemaParserCtxtPtr schema_ctxt = NULL;
00675
00676 xmlSubstituteEntitiesDefault(1);
00677
00678
00679
00680
00681 ctxt = xmlNewParserCtxt();
00682 if (ctxt == NULL) {
00683 LOG_MSG (LOG_ERR, "%s: Failed to allocate parser context\n",
00684 PROGNAME);
00685 goto out;
00686 }
00687
00688 doc = xmlCtxtReadFile(ctxt, opts->input_filename, NULL, XML_PARSE_NOENT);
00689 if (doc == NULL) {
00690 LOG_MSG (LOG_ERR, "%s: Failed to parse %s\n", PROGNAME,
00691 opts->input_filename);
00692 goto out;
00693 } else if (!ctxt->valid) {
00694 LOG_MSG (LOG_ERR, "%s: Failed to validate %s\n", PROGNAME,
00695 opts->input_filename);
00696 xmlFreeDoc(doc);
00697 doc = NULL;
00698 goto out;
00699 }
00700
00701 if (opts->disable_schema) {
00702 ret = 0;
00703 goto out;
00704 }
00705
00706
00707
00708 if (opts->semantic_schema)
00709 schema_ctxt = xmlSchemaNewParserCtxt("/usr/share/test-definition/"
00710 "testdefinition-tm_terms.xsd");
00711 else
00712 schema_ctxt = xmlSchemaNewParserCtxt("/usr/share/test-definition/"
00713 "testdefinition-syntax.xsd");
00714
00715 if (schema_ctxt == NULL) {
00716 LOG_MSG (LOG_ERR, "%s: Failed to allocate schema context\n",
00717 PROGNAME);
00718 goto out;
00719 }
00720
00721 sch = xmlSchemaParse(schema_ctxt);
00722 if (sch == NULL) {
00723 LOG_MSG (LOG_ERR, "%s: Failed to parse schema\n",
00724 PROGNAME);
00725 goto out;
00726 }
00727
00728 valid_ctxt = xmlSchemaNewValidCtxt(sch);
00729 if (valid_ctxt == NULL) {
00730 LOG_MSG (LOG_ERR, "%s: Failed to create schema validation "
00731 "context\n", PROGNAME);
00732 goto out;
00733
00734 }
00735
00736 ret = xmlSchemaValidateDoc(valid_ctxt, doc);
00737 if (ret)
00738 ret = TESTRUNNER_LITE_XML_VALIDATION_FAIL;
00739 out:
00740
00741
00742
00743 if (doc) xmlFreeDoc(doc);
00744 if (ctxt) xmlFreeParserCtxt(ctxt);
00745 if (sch) xmlSchemaFree(sch);
00746 if (valid_ctxt) xmlSchemaFreeValidCtxt(valid_ctxt);
00747 if (schema_ctxt) xmlSchemaFreeParserCtxt(schema_ctxt);
00748
00749 return ret;
00750 }
00751
00756 int td_reader_init (testrunner_lite_options *opts)
00757 {
00758
00759 reader = xmlNewTextReaderFilename(opts->input_filename);
00760 if (!reader) {
00761 LOG_MSG (LOG_ERR, "%s: failed to create xml reader for %s\n",
00762 PROGNAME, opts->input_filename);
00763
00764 }
00765
00766 if (opts->disable_schema)
00767 return 0;
00768
00769 if (opts->semantic_schema)
00770 schema_context = xmlSchemaNewParserCtxt
00771 ("/usr/share/test-definition/"
00772 "testdefinition-tm_terms.xsd");
00773 else
00774 schema_context = xmlSchemaNewParserCtxt
00775 ("/usr/share/test-definition/"
00776 "testdefinition-syntax.xsd");
00777 if (schema_context == NULL) {
00778 LOG_MSG (LOG_ERR, "%s: Failed to allocate schema context\n",
00779 PROGNAME);
00780 goto err_out;
00781 }
00782
00783 schema = xmlSchemaParse(schema_context);
00784 if (schema == NULL) {
00785 LOG_MSG (LOG_ERR, "%s: Failed to parse schema\n",
00786 PROGNAME);
00787 goto err_out;
00788 }
00789
00790 if (xmlTextReaderSetSchema (reader, schema)) {
00791 LOG_MSG (LOG_ERR, "%s: Failed to set schema for xml reader\n",
00792 PROGNAME);
00793 goto err_out;
00794 }
00795
00796
00797 return 0;
00798 err_out:
00799 LOG_MSG (LOG_ERR, "%s:%s: Exiting with error\n",
00800 PROGNAME, __FUNCTION__);
00801 td_reader_close ();
00802 return 1;
00803
00804 }
00805
00808 void td_reader_close ()
00809 {
00810 if (reader) xmlFreeTextReader (reader);
00811 if (schema) xmlSchemaFree(schema);
00812 if (schema_context) xmlSchemaFreeParserCtxt(schema_context);
00813 }
00814
00818 int td_next_node (void) {
00819 int ret;
00820 const xmlChar *name;
00821 xmlReaderTypes type;
00822
00823 ret = xmlTextReaderRead(reader);
00824
00825 if (!ret)
00826 return !ret;
00827
00828 name = xmlTextReaderConstName(reader);
00829 type = xmlTextReaderNodeType(reader);
00830
00831 if (!name)
00832 return 1;
00833
00834 if (!xmlStrcmp (name, BAD_CAST "testdefinition")) {
00835 if (type == XML_READER_TYPE_ELEMENT)
00836 return td_parse_td();
00837 else if (type == XML_READER_TYPE_END_ELEMENT) {
00838 if (cbs->test_td_end)
00839 cbs->test_td_end();
00840 return 0;
00841 }
00842 }
00843
00844 if (!xmlStrcmp (name, BAD_CAST "hwiddetect")) {
00845 if (type == XML_READER_TYPE_ELEMENT) {
00846 return td_parse_hwiddetect();
00847 }
00848 }
00849
00850 if (!xmlStrcmp (name, BAD_CAST "suite")) {
00851 if (type == XML_READER_TYPE_ELEMENT)
00852 return td_parse_suite();
00853 else if (type == XML_READER_TYPE_END_ELEMENT) {
00854 if (cbs->test_suite_end) cbs->test_suite_end();
00855 return 0;
00856 }
00857 }
00858
00859 if (!xmlStrcmp (name, BAD_CAST "set") &&
00860 type == XML_READER_TYPE_ELEMENT)
00861 return td_parse_set();
00862
00863
00864
00865 return !ret;
00866 }
00867
00871 int td_register_callbacks(td_parser_callbacks *pcbs)
00872 {
00873 cbs = pcbs;
00874
00875 return 0;
00876 }
00877
00878
00879
00880
00881
00882
00883