Friday, April 01, 2005

Expat : I tried and ported the XML parser to T-Engine platform as following.
$ cd /usr/local
$ tar xvfz expat-1.95.8.tar.gz
$ export EXPATROOT=/usr/local/expat-1.95.8
$ vi Makefile
......
EXPATSRC = $(EXPATROOT)/lib/xmlparse.c $(EXPATROOT)/lib/xmlrole.c $(EXPATROOT)/lib/xmltok.c
# $(EXPATROOT)/lib/xmltok_ns.c
# $(EXPATROOT)/lib/xmltok_impl.c \ ......
......
SRC = ...... $(EXPATSRC)
......
CFLAGS += -DHAVE_MEMMOVE
......
Using the XML parser, I have created my XML functions with the following test case. The test case have been passed :-)
char *XML_TEST_CONTENT = "<?xml version=\"1.0\" ?><root xmlns=\"urn:schemas-upnp-org:device-1-0\"><specVersion><major>1</major><minor>0</minor></specVersion></root>";

void SampleTestCase::testXmlParser()
{
CgXmlNodeList *nodeList = cg_xml_nodelist_new();
CgXmlParser *parser = cg_xml_parser_new();
CPPUNIT_ASSERT(cg_xml_parse(parser, nodeList, XML_TEST_CONTENT, strlen(XML_TEST_CONTENT)) == TRUE);

CgXmlNode *node;
CgXmlNode *parentNode;
int nodeCnt;

/* root node */
nodeCnt = 0;
node = cg_xml_nodelist_gets(nodeList);
for (; node; node=cg_xml_node_next(node))
nodeCnt++;
CPPUNIT_ASSERT(nodeCnt == 1);
node = cg_xml_nodelist_gets(nodeList);
CPPUNIT_ASSERT(strcmp(cg_xml_node_getname(node), "root") == 0);

/* specVersion node */
parentNode = node;
nodeCnt = 0;
node = cg_xml_node_getchildnodes(parentNode);
for (; node; node=cg_xml_node_next(node))
nodeCnt++;
CPPUNIT_ASSERT(nodeCnt == 1);
node = cg_xml_node_getchildnodes(parentNode);
CPPUNIT_ASSERT(strcmp(cg_xml_node_getname(node), "specVersion") == 0);

/* major and minor node */
parentNode = node;
nodeCnt = 0;
node = cg_xml_node_getchildnodes(parentNode);
for (; node; node=cg_xml_node_next(node))
nodeCnt++;
CPPUNIT_ASSERT(nodeCnt == 2);
node = cg_xml_node_getchildnodes(parentNode);
CPPUNIT_ASSERT(strcmp(cg_xml_node_getname(node), "major") == 0);
CPPUNIT_ASSERT(strcmp(cg_xml_node_getvalue(node), "1") == 0);
node = cg_xml_node_next(node);
CPPUNIT_ASSERT(strcmp(cg_xml_node_getname(node), "minor") == 0);
CPPUNIT_ASSERT(strcmp(cg_xml_node_getvalue(node), "0") == 0);

cg_xml_parser_delete(parser);
}

This page is powered by Blogger. Isn't yours?