2009-05-06 14:29:12 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <malloc.h>
|
2009-05-24 14:09:46 +00:00
|
|
|
#include <assert.h>
|
2009-05-06 14:29:12 +00:00
|
|
|
#include "xml.h"
|
|
|
|
|
|
|
|
#define ROOTNODE "/Configuration/output/menu"
|
|
|
|
#define LEAFNODE "name"
|
|
|
|
#define PATH ROOTNODE"/"LEAFNODE
|
|
|
|
#define BUFLEN 4096
|
2009-05-24 14:09:46 +00:00
|
|
|
|
|
|
|
#define PRINT_ERROR_AND_EXIT(id) \
|
|
|
|
if (xmlErrorGetNo(id, 0) != XML_NO_ERROR) { \
|
|
|
|
const char *errstr = xmlErrorGetString(id, 0); \
|
|
|
|
size_t column = xmlErrorGetColumnNo(id, 0); \
|
|
|
|
size_t lineno = xmlErrorGetLineNo(id, 1); \
|
|
|
|
printf("Error at line %i, column %i: %s\n", lineno, column, errstr); \
|
|
|
|
exit(-1); \
|
|
|
|
}
|
|
|
|
|
2009-05-06 14:29:12 +00:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
void *root_id;
|
|
|
|
|
|
|
|
root_id = xmlOpen("sample.xml");
|
|
|
|
if (root_id)
|
|
|
|
{
|
|
|
|
void *path_id, *node_id;
|
2009-05-08 09:10:56 +00:00
|
|
|
char *s;
|
2009-05-06 14:29:12 +00:00
|
|
|
|
2009-05-24 14:09:46 +00:00
|
|
|
printf("\nTesting xmlNodeGetString for /*/*/test:\t\t\t\t\t");
|
|
|
|
s = xmlNodeGetString(root_id , "/*/*/test");
|
2009-05-08 09:10:56 +00:00
|
|
|
if (s)
|
2009-05-06 14:29:12 +00:00
|
|
|
{
|
2009-05-08 09:10:56 +00:00
|
|
|
printf("failed.\n\t'%s' should be empty\n", s);
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("succes.\n");
|
2009-05-06 14:29:12 +00:00
|
|
|
|
2009-05-24 14:09:46 +00:00
|
|
|
printf("Testing xmlGetString for /Configuration/output/test:\t\t\t");
|
|
|
|
path_id = xmlNodeGet(root_id, "/Configuration/output/test");
|
2009-05-08 09:10:56 +00:00
|
|
|
if (path_id)
|
|
|
|
{
|
|
|
|
s = xmlGetString(path_id);
|
2009-05-06 14:29:12 +00:00
|
|
|
if (s)
|
|
|
|
{
|
2009-05-08 09:10:56 +00:00
|
|
|
printf("failed.\n\t'%s' should be empty\n", s);
|
2009-05-06 14:29:12 +00:00
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("succes.\n");
|
2009-05-08 09:10:56 +00:00
|
|
|
}
|
2009-05-24 14:09:46 +00:00
|
|
|
else
|
|
|
|
PRINT_ERROR_AND_EXIT(root_id);
|
2009-05-08 09:10:56 +00:00
|
|
|
|
|
|
|
path_id = xmlNodeGet(root_id, PATH);
|
|
|
|
node_id = xmlNodeGet(root_id, ROOTNODE);
|
|
|
|
|
|
|
|
if (path_id && node_id)
|
|
|
|
{
|
|
|
|
char buf[BUFLEN];
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
xmlCopyString(path_id, buf, BUFLEN);
|
2009-05-06 14:29:12 +00:00
|
|
|
printf("Testing xmlNodeCopyString against xmlGetString:\t\t\t\t");
|
|
|
|
if ((s = xmlGetString(path_id)) != 0)
|
|
|
|
{
|
|
|
|
if (strcmp(s, buf)) /* not the same */
|
|
|
|
printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
|
|
|
|
else
|
|
|
|
printf("succes.\n");
|
|
|
|
|
|
|
|
printf("Testing xmlCopyString against xmlGetString:\t\t\t\t");
|
|
|
|
xmlCopyString(path_id, buf, BUFLEN);
|
|
|
|
if (strcmp(s, buf)) /* not the same */
|
2009-05-24 14:09:46 +00:00
|
|
|
printf("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
|
2009-05-06 14:29:12 +00:00
|
|
|
else
|
|
|
|
printf("succes.\n");
|
|
|
|
}
|
|
|
|
else
|
2009-05-24 14:09:46 +00:00
|
|
|
PRINT_ERROR_AND_EXIT(path_id);
|
2009-05-06 14:29:12 +00:00
|
|
|
|
|
|
|
printf("Testing xmlCopyString against xmlCompareString:\t\t\t\t");
|
|
|
|
if (xmlCompareString(path_id, buf)) /* not the same */
|
2009-05-24 14:09:46 +00:00
|
|
|
printf ("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
|
2009-05-06 14:29:12 +00:00
|
|
|
else
|
|
|
|
printf("succes.\n");
|
|
|
|
|
|
|
|
printf("Testing xmlCopyString against xmlNodeCompareString:\t\t\t");
|
|
|
|
if (xmlNodeCompareString(node_id, LEAFNODE, buf)) /* not the same */
|
2009-05-24 14:09:46 +00:00
|
|
|
printf("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
|
2009-05-06 14:29:12 +00:00
|
|
|
else
|
|
|
|
printf("succes.\n");
|
2009-05-24 14:09:46 +00:00
|
|
|
|
|
|
|
if (s) free(s);
|
2009-05-06 14:29:12 +00:00
|
|
|
|
|
|
|
printf("Testing xmlCopyString against xmlNodeGetString:\t\t\t\t");
|
|
|
|
if ((s = xmlNodeGetString(node_id, LEAFNODE)) != 0)
|
|
|
|
{
|
|
|
|
if (strcmp(s, buf)) /* not the same */
|
2009-05-24 14:09:46 +00:00
|
|
|
printf("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
|
2009-05-06 14:29:12 +00:00
|
|
|
else
|
|
|
|
printf("succes.\n");
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
2009-05-24 14:09:46 +00:00
|
|
|
PRINT_ERROR_AND_EXIT(node_id);
|
2009-05-06 14:29:12 +00:00
|
|
|
|
|
|
|
free(path_id);
|
|
|
|
path_id = xmlNodeGet(root_id, "/Configuration/backend/name");
|
|
|
|
if (path_id)
|
|
|
|
{
|
|
|
|
printf("Testing xmlAttributeCopyString against xmlAttributeCompareString:\t");
|
2009-05-24 14:09:46 +00:00
|
|
|
xmlAttributeCopyString(path_id, "type", buf, BUFLEN);
|
2009-05-06 14:29:12 +00:00
|
|
|
if (xmlAttributeCompareString(path_id, "type", buf)) /* no match */
|
|
|
|
printf("failed.\n\t'%s' differs\n", buf);
|
|
|
|
else
|
|
|
|
printf("succes.\n");
|
|
|
|
|
|
|
|
printf("Testing xmlAttributeCopyString against xmlAttributeGetString:\t\t");
|
|
|
|
if ((s = xmlAttributeGetString(path_id, "type")) != 0)
|
|
|
|
{
|
|
|
|
if (strcmp(s, buf)) /* not the same */
|
|
|
|
printf("failed.\n\t'%s' differs from '%s'\n", s, buf);
|
|
|
|
else
|
|
|
|
printf("succes.\n");
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
else
|
2009-05-24 14:09:46 +00:00
|
|
|
PRINT_ERROR_AND_EXIT(path_id);
|
2009-05-06 14:29:12 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
2009-05-24 14:09:46 +00:00
|
|
|
PRINT_ERROR_AND_EXIT(root_id);
|
2009-05-06 14:29:12 +00:00
|
|
|
|
|
|
|
free(node_id);
|
|
|
|
free(path_id);
|
2009-05-07 12:23:30 +00:00
|
|
|
|
|
|
|
path_id = xmlNodeGet(root_id, "Configuration/output/sample/test");
|
|
|
|
if (path_id)
|
|
|
|
{
|
|
|
|
xmlNodeCopyString(root_id ,"Configuration/output/menu/name", buf, BUFLEN);
|
|
|
|
printf("Testing xmlCompareString against a fixed string: \t\t\t");
|
|
|
|
if (xmlCompareString(path_id, buf)) /* no match */
|
|
|
|
printf("failed.\n\t'%s' differs\n", buf);
|
|
|
|
else
|
|
|
|
printf("succes.\n");
|
|
|
|
|
|
|
|
s = xmlGetString(path_id);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
printf("Testing xmlGetString against a fixed string: \t\t\t\t");
|
|
|
|
if (strcmp(s, buf)) /* mismatch */
|
|
|
|
printf("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
|
|
|
|
else
|
|
|
|
printf("succes.\n");
|
|
|
|
|
|
|
|
printf("Testing xmlCopyString gainst a fixed string: \t\t\t\t");
|
|
|
|
xmlCopyString(path_id, buf, BUFLEN);
|
|
|
|
if (strcmp(s, buf)) /* mismatch */
|
|
|
|
printf("failed.\n\t'%s' differs from\n\t'%s'\n", s, buf);
|
|
|
|
else
|
|
|
|
printf("succes.\n");
|
|
|
|
|
|
|
|
free(s);
|
|
|
|
}
|
2009-05-24 14:09:46 +00:00
|
|
|
else
|
|
|
|
PRINT_ERROR_AND_EXIT(path_id);
|
2009-05-07 12:23:30 +00:00
|
|
|
|
|
|
|
free(path_id);
|
|
|
|
}
|
2009-05-06 14:29:12 +00:00
|
|
|
}
|
2009-05-24 14:09:46 +00:00
|
|
|
|
|
|
|
if (xmlErrorGetNo(root_id, 0) != XML_NO_ERROR)
|
2009-05-06 14:29:12 +00:00
|
|
|
{
|
2009-05-24 14:09:46 +00:00
|
|
|
const char *errstr = xmlErrorGetString(root_id, 0);
|
|
|
|
size_t column = xmlErrorGetColumnNo(root_id, 0);
|
|
|
|
size_t lineno = xmlErrorGetLineNo(root_id, 1);
|
|
|
|
|
|
|
|
printf("Error at line %i, column %i: %s\n", lineno, column, errstr);
|
2009-05-06 14:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xmlClose(root_id);
|
|
|
|
}
|
2009-05-08 09:10:56 +00:00
|
|
|
printf("\n");
|
2009-05-06 14:29:12 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|