]]>]]>]]>")) {
axl_error_report (error, -1, "Expected to find different value after dump operation..\n");
return axl_false;
}
axl_free (content);
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Extended encoding support.
*
* @param error The optional axlError to be used to report erros.
*
* @return axl_true tests are ok, otherwise axl_false is returned.
*/
axl_bool test_41 (axlError ** error)
{
axlDoc * doc;
axlNode * node;
int index;
/* configure babel translate functions */
printf ("Test 41: init babel..\n");
if (! axl_babel_init (error))
return axl_false;
/* check utf 8 */
printf ("Test 41: checking utf-8 engine..\n");
if (! axl_babel_check_utf8_content (test_41_iso_8859_15_value, strlen (test_41_iso_8859_15_value), &index)) {
printf ("ERROR: utf-8 content error found at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but it wasn't found", NULL, error);
return axl_false;
}
/*** UTF-8 support */
/* test utf-8 encoding */
printf ("Test 41: test utf-8 support..\n");
doc = axl_doc_parse_from_file ("test_41.utf-8.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "encodings")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
axl_doc_free (doc);
/* check unicode file without xml header */
printf ("Test 41: test utf-8 content without xml header..\n");
doc = axl_doc_parse_from_file ("test_41.utf-8.withoutheader.xml", error);
if (doc == NULL)
return axl_false;
if (! axl_cmp (axl_doc_get_encoding (doc), "utf-8")) {
axl_error_new (-1, "Expected to find utf-8 content declaration but it wasn't found", NULL, error);
return axl_false;
}
axl_doc_free (doc);
/* check unicode file without xml header */
printf ("Test 41: test wrong xml utf-8 content without xml header..\n");
doc = axl_doc_parse_from_file ("test_41.utf-8.wrongwithoutheader.xml", NULL);
if (doc != NULL)
return axl_false;
/* test utf-8 encoding (wrong test) */
printf ("Test 41: test wrong utf-8 content..\n");
doc = axl_doc_parse_from_file ("test_41.utf-8.wrong.xml", error);
if (doc != NULL)
return axl_false;
/* check unicode file without declaration */
printf ("Test 41: test utf-8 content without decleration..\n");
doc = axl_doc_parse_from_file ("test_41.utf-8.withoutencoding.xml", error);
if (doc == NULL)
return axl_false;
if (! axl_cmp (axl_doc_get_encoding (doc), "utf-8")) {
axl_error_new (-1, "Expected to find utf-8 content declaration but it wasn't found", NULL, error);
return axl_false;
}
axl_doc_free (doc);
/* check large unicode file without declearation */
printf ("Test 41: test large utf-8 content without decleration..\n");
doc = axl_doc_parse_from_file ("large.xml", error);
if (doc == NULL)
return axl_false;
if (! axl_cmp (axl_doc_get_encoding (doc), "utf-8")) {
axl_error_new (-1, "Expected to find utf-8 content declaration but it wasn't found", NULL, error);
return axl_false;
}
axl_doc_free (doc);
/*** ISO-8859-15 SUPPORT ***/
/* test iso-8859-15 encoding */
printf ("Test 41: test iso-8859-15..\n");
doc = axl_doc_parse_from_file ("test_41.iso-8859-15.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check node content */
if (! axl_cmp (test_41_iso_8859_15_value,
axl_node_get_content (node, NULL))) {
printf ("Found diferences at node content: (size: %d)'%s' != (size: %d) '%s'..\n",
(int) strlen (test_41_iso_8859_15_value), test_41_iso_8859_15_value,
(int) strlen (axl_node_get_content (node, NULL)), axl_node_get_content (node, NULL));
axl_error_new (-1, "Found diferences at node content..\n", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
/*** ISO-8859-15 LARGE FILE ***/
printf ("Test 41: test iso-8859-15 large..\n");
/* now parse a large document that would require
* prebuffering */
doc = axl_doc_parse_from_file ("test_41.iso-8859-15.2.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check utf-8 format */
if (! axl_babel_check_utf8_content (axl_node_get_content (node, NULL), -1, &index)) {
printf ("ERROR: found utf-8 content error at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but a failure was found", NULL, error);
return axl_false;
}
if (strlen (axl_node_get_content (node, NULL)) != 26642) {
printf ("ERROR: expected content lenght %d but found %d\n",
(int) strlen (axl_node_get_content (node, NULL)), 26642);
}
/* free document */
axl_doc_free (doc);
/*** ISO-8859-1 support ***/
printf ("Test 41: test iso-8859-1..\n");
/* now parse a large document that would require
* prebuffering */
doc = axl_doc_parse_from_file ("test_41.iso-8859-1.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check utf-8 format */
if (! axl_babel_check_utf8_content (axl_node_get_content (node, NULL), -1, &index)) {
printf ("ERROR: found utf-8 content error at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but a failure was found", NULL, error);
return axl_false;
}
if (! axl_cmp (test_41_iso_8859_1_value,
axl_node_get_content (node, NULL))) {
printf ("Found diferences at node content: (size: %d)'%s' != (size: %d) '%s'..\n",
(int) strlen (test_41_iso_8859_1_value), test_41_iso_8859_1_value,
(int) strlen (axl_node_get_content (node, NULL)), axl_node_get_content (node, NULL));
axl_error_new (-1, "Found diferences at node content..\n", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
/*** ISO-8859-2 support ***/
printf ("Test 41: test iso-8859-2..\n");
/* now parse a large document that would require
* prebuffering */
doc = axl_doc_parse_from_file ("test_41.iso-8859-2.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check utf-8 format */
if (! axl_babel_check_utf8_content (axl_node_get_content (node, NULL), -1, &index)) {
printf ("ERROR: found utf-8 content error at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but a failure was found", NULL, error);
return axl_false;
}
if (! axl_cmp (test_41_iso_8859_2_value,
axl_node_get_content (node, NULL))) {
printf ("Found diferences at node content: (size: %d)'%s' != (size: %d) '%s'..\n",
(int) strlen (test_41_iso_8859_2_value), test_41_iso_8859_2_value,
(int) strlen (axl_node_get_content (node, NULL)), axl_node_get_content (node, NULL));
axl_error_new (-1, "Found diferences at node content..\n", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
/*** ISO-8859-3 support ***/
printf ("Test 41: test iso-8859-3..\n");
/* now parse a large document that would require
* prebuffering */
doc = axl_doc_parse_from_file ("test_41.iso-8859-3.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check utf-8 format */
if (! axl_babel_check_utf8_content (axl_node_get_content (node, NULL), -1, &index)) {
printf ("ERROR: found utf-8 content error at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but a failure was found", NULL, error);
return axl_false;
}
if (! axl_cmp (test_41_iso_8859_3_value,
axl_node_get_content (node, NULL))) {
printf ("Found diferences at node content: (size: %d)'%s' != (size: %d) '%s'..\n",
(int) strlen (test_41_iso_8859_3_value), test_41_iso_8859_3_value,
(int) strlen (axl_node_get_content (node, NULL)), axl_node_get_content (node, NULL));
axl_error_new (-1, "Found diferences at node content..\n", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
/*** ISO-8859-4 support ***/
printf ("Test 41: test iso-8859-4..\n");
/* now parse a large document that would require
* prebuffering */
doc = axl_doc_parse_from_file ("test_41.iso-8859-4.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check utf-8 format */
if (! axl_babel_check_utf8_content (axl_node_get_content (node, NULL), -1, &index)) {
printf ("ERROR: found utf-8 content error at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but a failure was found", NULL, error);
return axl_false;
}
if (! axl_cmp (test_41_iso_8859_4_value,
axl_node_get_content (node, NULL))) {
printf ("Found diferences at node content: (size: %d)'%s' != (size: %d) '%s'..\n",
(int) strlen (test_41_iso_8859_4_value), test_41_iso_8859_4_value,
(int) strlen (axl_node_get_content (node, NULL)), axl_node_get_content (node, NULL));
axl_error_new (-1, "Found diferences at node content..\n", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
/*** ISO-8859-5 support ***/
printf ("Test 41: test iso-8859-5..\n");
/* now parse a large document that would require
* prebuffering */
doc = axl_doc_parse_from_file ("test_41.iso-8859-5.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check utf-8 format */
if (! axl_babel_check_utf8_content (axl_node_get_content (node, NULL), -1, &index)) {
printf ("ERROR: found utf-8 content error at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but a failure was found", NULL, error);
return axl_false;
}
if (! axl_cmp (test_41_iso_8859_5_value,
axl_node_get_content (node, NULL))) {
printf ("Found diferences at node content: (size: %d)'%s' != (size: %d) '%s'..\n",
(int) strlen (test_41_iso_8859_5_value), test_41_iso_8859_5_value,
(int) strlen (axl_node_get_content (node, NULL)), axl_node_get_content (node, NULL));
axl_error_new (-1, "Found diferences at node content..\n", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
/*** ISO-8859-6 support ***/
printf ("Test 41: test iso-8859-6..\n");
/* now parse a large document that would require
* prebuffering */
doc = axl_doc_parse_from_file ("test_41.iso-8859-6.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check utf-8 format */
if (! axl_babel_check_utf8_content (axl_node_get_content (node, NULL), -1, &index)) {
printf ("ERROR: found utf-8 content error at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but a failure was found", NULL, error);
return axl_false;
}
if (! axl_cmp (test_41_iso_8859_6_value,
axl_node_get_content (node, NULL))) {
printf ("Found diferences at node content: (size: %d)'%s' != (size: %d) '%s'..\n",
(int) strlen (test_41_iso_8859_6_value), test_41_iso_8859_6_value,
(int) strlen (axl_node_get_content (node, NULL)), axl_node_get_content (node, NULL));
axl_error_new (-1, "Found diferences at node content..\n", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
/*** ISO-8859-7 support ***/
printf ("Test 41: test iso-8859-7..\n");
/* now parse a large document that would require
* prebuffering */
doc = axl_doc_parse_from_file ("test_41.iso-8859-7.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check utf-8 format */
if (! axl_babel_check_utf8_content (axl_node_get_content (node, NULL), -1, &index)) {
printf ("ERROR: found utf-8 content error at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but a failure was found", NULL, error);
return axl_false;
}
if (! axl_cmp (test_41_iso_8859_7_value,
axl_node_get_content (node, NULL))) {
printf ("Found diferences at node content: (size: %d)'%s' != (size: %d) '%s'..\n",
(int) strlen (test_41_iso_8859_7_value), test_41_iso_8859_7_value,
(int) strlen (axl_node_get_content (node, NULL)), axl_node_get_content (node, NULL));
axl_error_new (-1, "Found diferences at node content..\n", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
/*** ISO-8859-8 support ***/
printf ("Test 41: test iso-8859-8..\n");
/* now parse a large document that would require
* prebuffering */
doc = axl_doc_parse_from_file ("test_41.iso-8859-8.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check utf-8 format */
if (! axl_babel_check_utf8_content (axl_node_get_content (node, NULL), -1, &index)) {
printf ("ERROR: found utf-8 content error at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but a failure was found", NULL, error);
return axl_false;
}
if (! axl_cmp (test_41_iso_8859_8_value,
axl_node_get_content (node, NULL))) {
printf ("Found diferences at node content: (size: %d)'%s' != (size: %d) '%s'..\n",
(int) strlen (test_41_iso_8859_8_value), test_41_iso_8859_8_value,
(int) strlen (axl_node_get_content (node, NULL)), axl_node_get_content (node, NULL));
axl_error_new (-1, "Found diferences at node content..\n", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
/*** ISO-8859-9 support ***/
printf ("Test 41: test iso-8859-9..\n");
/* now parse a large document that would require
* prebuffering */
doc = axl_doc_parse_from_file ("test_41.iso-8859-9.xml", error);
if (doc == NULL)
return axl_false;
/* find info node */
node = axl_doc_get_root (doc);
if (! NODE_CMP_NAME (node, "info")) {
axl_error_new (-1, "Expected to find root node called but it wasn't found", NULL, error);
return axl_false;
}
/* check utf-8 format */
if (! axl_babel_check_utf8_content (axl_node_get_content (node, NULL), -1, &index)) {
printf ("ERROR: found utf-8 content error at index=%d..\n", index);
axl_error_new (-1, "Expected to find proper utf-8 content but a failure was found", NULL, error);
return axl_false;
}
if (! axl_cmp (test_41_iso_8859_9_value,
axl_node_get_content (node, NULL))) {
printf ("Found diferences at node content: (size: %d)'%s' != (size: %d) '%s'..\n",
(int) strlen (test_41_iso_8859_9_value), test_41_iso_8859_9_value,
(int) strlen (axl_node_get_content (node, NULL)), axl_node_get_content (node, NULL));
axl_error_new (-1, "Found diferences at node content..\n", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
return axl_true;
/* test utf-16 encoding */
doc = axl_doc_parse_from_file ("test_41.utf-16.xml", error);
if (doc == NULL)
return axl_false;
/* check document content to ensure values */
/* free document */
axl_free (doc);
/* finish babel */
axl_babel_finish ();
return axl_true;
}
/**
* @brief Avoid including recursively white spaces content into dumped
* documents.
*
* @param error The optional axlError to be used to report erros.
*
* @return axl_true tests are ok, otherwise axl_false is returned.
*/
axl_bool test_40 (axlError ** error)
{
axlDoc * doc = axl_doc_parse_from_file ("test_40.xml", error);
axlDoc * doc2;
axlNode * node;
axlItem * item;
char * content;
char * content2;
if (doc == NULL)
return axl_false;
/* now dump the document */
if (! axl_doc_dump_pretty_to_file (doc, "test_40.xml.test", 8))
return axl_false;
/* now parse dumped document */
doc2 = axl_doc_parse_from_file ("test_40.xml.test", error);
if (doc2 == NULL)
return axl_false;
/* check comment content */
node = axl_doc_get_root (doc2);
item = axl_item_get_first_child (node);
content = axl_item_get_content (item, NULL);
if (content == NULL) {
axl_error_new (-1, "Expected to find content defined for first axl item found inside test_40.xml", NULL, error);
return axl_false;
}
node = axl_doc_get_root (doc);
item = axl_item_get_first_child (node);
content2 = axl_item_get_content (item, NULL);
if (content2 == NULL) {
axl_error_new (-1, "Expected to find content defined for first axl item found inside test_40.xml.test", NULL, error);
return axl_false;
}
/* check content */
if (! axl_cmp (content, content2)) {
printf ("Failed, expected equal content, but found differences: (%d)'%s' != (%d)'%s'\n",
(int) strlen (content), content, (int) strlen (content2), content2);
axl_error_new (-1, "Failed, expected equal content, but found differences", NULL, error);
return axl_false;
}
axl_doc_free (doc);
axl_doc_free (doc2);
return axl_true;
}
/* include inline dtd definition (test_39) */
#include
#include
#include
#include
/**
* @brief Check DTD validation error found.
*
* @param error The optional axlError to be used to report erros.
*
* @return axl_true if the validity test is passed, otherwise axl_false is
* returned.
*/
axl_bool test_39 (axlError ** error)
{
axlDtd * dtd;
axlDtd * dtd2;
/* check channel.dtd */
dtd = axl_dtd_parse (CHANNEL_DTD, -1, error);
if (dtd == NULL) {
return axl_false;
}
dtd2 = axl_dtd_parse_from_file ("channel.dtd", error);
if (dtd2 == NULL)
return axl_false;
/* check if both dtds are equal */
if (! axl_dtd_are_equal (dtd, dtd2)) {
axl_error_new (-1, "Expected to find equal dtd definitions, but axl_dtd_are_equal failed", NULL, error);
return axl_false;
}
/* free dtd and doc */
axl_dtd_free (dtd);
axl_dtd_free (dtd2);
/* check channel.dtd */
dtd = axl_dtd_parse (FACT_DTD, -1, error);
if (dtd == NULL) {
return axl_false;
}
dtd2 = axl_dtd_parse_from_file ("fact.dtd", error);
if (dtd2 == NULL)
return axl_false;
/* check if both dtds are equal */
if (! axl_dtd_are_equal (dtd, dtd2)) {
axl_error_new (-1, "Expected to find equal dtd definitions, but axl_dtd_are_equal failed", NULL, error);
return axl_false;
}
/* free dtd and doc */
axl_dtd_free (dtd);
axl_dtd_free (dtd2);
/* check channel.dtd */
dtd = axl_dtd_parse (XML_RPC_DTD, -1, error);
if (dtd == NULL) {
return axl_false;
}
dtd2 = axl_dtd_parse_from_file ("xml-rpc.dtd", error);
if (dtd2 == NULL)
return axl_false;
/* check if both dtds are equal */
if (! axl_dtd_are_equal (dtd, dtd2)) {
axl_error_new (-1, "Expected to find equal dtd definitions, but axl_dtd_are_equal failed", NULL, error);
return axl_false;
}
/* free dtd and doc */
axl_dtd_free (dtd);
axl_dtd_free (dtd2);
/* check channel.dtd */
dtd = axl_dtd_parse (TLS_DTD, -1, error);
if (dtd == NULL) {
return axl_false;
}
dtd2 = axl_dtd_parse_from_file ("tls.dtd", error);
if (dtd2 == NULL)
return axl_false;
/* check if both dtds are equal */
if (! axl_dtd_are_equal (dtd, dtd2)) {
axl_error_new (-1, "Expected to find equal dtd definitions, but axl_dtd_are_equal failed", NULL, error);
return axl_false;
}
/* free dtd and doc */
axl_dtd_free (dtd);
axl_dtd_free (dtd2);
return axl_true;
}
/**
* @brief Check DTD validation error found.
*
* @param error The optional axlError to be used to report erros.
*
* @return axl_true if the validity test is passed, otherwise axl_false is
* returned.
*/
axl_bool test_38 (axlError ** error)
{
axlDtd * dtd;
axlDoc * doc;
dtd = axl_dtd_parse_from_file ("test_38.dtd", error);
if (dtd == NULL)
return axl_false;
doc = axl_doc_parse_from_file ("test_38.xml", error);
if (doc == NULL)
return axl_false;
/* validate */
if (! axl_dtd_validate (doc, dtd, error)) {
axl_error_new (-1, "Expected to find proper a validation for the test (IDREF references)", NULL, error);
return axl_false;
}
/* free dtd and doc */
axl_dtd_free (dtd);
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Check if it is possible to dettach the root node.
*
* @param error The optional axlError to be used to report erros.
*
* @return axl_true if the validity test is passed, otherwise axl_false is
* returned.
*/
axl_bool test_37 (axlError ** error)
{
axlDoc * doc;
axlDoc * doc2;
axlNode * root;
/* parse file */
doc = axl_doc_parse (" This is content, more content ", -1, error);
if (doc == NULL)
return axl_false;
doc2 = axl_doc_parse ("", -1, error);
if (doc2 == NULL)
return axl_false;
/* clear content */
root = axl_doc_get_root (doc);
axl_node_set_is_empty (root, axl_true);
if (! axl_doc_are_equal (doc, doc2)) {
axl_error_new (-1, "Expected equal documents, not found", NULL, error);
return axl_false;
}
axl_doc_free (doc);
axl_doc_free (doc2);
return axl_true;
}
/**
* @brief Check if it is possible to dettach the root node.
*
* @param error The optional axlError to be used to report erros.
*
* @return axl_true if the validity test is passed, otherwise axl_false is
* returned.
*/
axl_bool test_36 (axlError ** error)
{
/* parse the document */
axlDoc * doc = axl_doc_parse_from_file ("test_35.xml", error);
axlNode * root;
/* check returned document */
if (doc == NULL)
return axl_false;
/* now get the root node and detach it */
root = axl_doc_get_root (doc);
axl_node_deattach (root);
/* free the node */
axl_node_free (root);
/* free the document */
axl_doc_free (doc);
root = axl_node_parse_strings (error,
"",
" ",
" True",
" <b>1. Seleccione el sistema:</b>",
" False",
" True",
" GTK_JUSTIFY_LEFT",
" False",
" False",
" 0",
" 0.5",
" 0",
" 0",
" PANGO_ELLIPSIZE_NONE",
" -1",
" False",
" 0",
" ",
" ",
" 0",
" False",
" False",
" ",
"",
NULL);
if (root == NULL) {
printf ("Error: unable to parse content..\n");
return axl_false;
}
axl_node_free (root);
/* create the node using the parse api */
root = axl_node_parse (error, "");
if (root == NULL) {
printf ("Error: unable to parse content..\n");
return axl_false;
}
axl_node_free (root);
return axl_true;
}
/**
* @brief Checks a bug while opening a document.
*
* @param error The optional axlError to be used to report erros.
*
* @return axl_true if the validity test is passed, otherwise axl_false is
* returned.
*/
axl_bool test_35 (axlError ** error)
{
/* parse the document */
axlDoc * doc = axl_doc_parse_from_file ("test_35.xml", error);
if (doc == NULL)
return axl_false;
/* free the document */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Checks a bug while triming strings.
*
* @param error The optional axlError to be used to report erros.
*
* @return axl_true if the validity test is passed, otherwise axl_false is
* returned.
*/
axl_bool test_34 (axlError ** error)
{
char * string = axl_strdup (" ");
axl_stream_trim (string);
if (strlen (string) != 0) {
axl_error_new (-1, "Expected to find empty string after trim operation, but not found", NULL, error);
return axl_false;
}
axl_free (string);
/* more length */
string = axl_strdup (" ");
axl_stream_trim (string);
if (strlen (string) != 0) {
axl_error_new (-1, "Expected to find empty string after trim operation, but not found", NULL, error);
return axl_false;
}
axl_free (string);
/* more length with one byte */
string = axl_strdup (" a ");
axl_stream_trim (string);
if (strlen (string) != 1) {
axl_error_new (-1, "Expected to find one byte length string after trim operation, but not found", NULL, error);
return axl_false;
}
axl_free (string);
return axl_true;
}
/**
* @brief Checks a recursive root node configuration.
*
* @param error The optional axlError to be used to report erros.
*
* @return axl_true if the validity test is passed, otherwise axl_false is
* returned.
*/
axl_bool test_33 (axlError ** error)
{
axlDoc * doc;
axlNode * node;
axlNode * temp;
int iterator;
/* create an empty document */
doc = axl_doc_create (NULL, NULL, axl_true);
/* set the root node */
node = axl_node_create ("test");
axl_doc_set_root (doc, node);
/* create a root node */
iterator = 0;
while (iterator < 2) {
/* get current root */
temp = axl_doc_get_root (doc);
/* create a new root */
node = axl_node_create ("test");
/* configure the new root */
axl_doc_set_root (doc, node);
/* configure the child */
axl_node_set_child (node, temp);
/* next iterator */
iterator++;
}
/* free */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Test DTD attribute declaration support using IDREF
* declarations.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_32 (axlError ** error) {
axlDtd * dtd;
axlDoc * doc;
dtd = axl_dtd_parse_from_file ("test_32.dtd", error);
if (dtd == NULL)
return axl_false;
doc = axl_doc_parse_from_file ("test_32.xml", error);
if (doc == NULL)
return axl_false;
/* validate */
if (! axl_dtd_validate (doc, dtd, error)) {
axl_error_new (-1, "Expected to find a validation error for the test (IDREF references)", NULL, error);
return axl_false;
}
/* free dtd and doc */
axl_dtd_free (dtd);
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Test DTD attribute declaration support using ID
* declarations.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_31 (axlError ** error) {
axlDtd * dtd;
axlDoc * doc;
dtd = axl_dtd_parse_from_file ("test_31.dtd", error);
if (dtd == NULL)
return axl_false;
doc = axl_doc_parse_from_file ("test_31.xml", error);
if (doc == NULL)
return axl_false;
/* validate */
if (! axl_dtd_validate (doc, dtd, error)) {
axl_error_new (-1, "Expected to find a validation error for the test (unique ID)", NULL, error);
return axl_false;
}
/* free dtd and doc */
axl_dtd_free (dtd);
axl_doc_free (doc);
dtd = axl_dtd_parse_from_file ("test_31a.dtd", error);
if (dtd != NULL) {
axl_error_new (-1, "Expected to find a error due to double declaration for an ID attribute, but DTD was loaded ok", NULL, error);
axl_dtd_free (dtd);
return axl_false;
}
axl_error_free (*error);
*error = NULL;
return axl_true;
}
/**
* @brief Test DTD attribute declaration support
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_30 (axlError ** error) {
axlDtd * dtd;
axlDtdAttribute * attr;
axlDoc * doc;
dtd = axl_dtd_parse_from_file ("test_30.dtd", error);
if (dtd == NULL)
return axl_false;
/* get the declarations found */
attr = axl_dtd_get_attr (dtd, "node");
if (attr == NULL) {
axl_error_new (-1, "expected to find attribute declaration, but not found", NULL, error);
return axl_false;
} /* end if */
/* get the declarations found */
attr = axl_dtd_get_attr (dtd, "node1");
if (attr != NULL) {
axl_error_new (-1, "expected to NOT find attribute declaration, but not found", NULL, error);
return axl_false;
} /* end if */
/* check the number of contraints */
if (axl_dtd_get_attr_contraints (dtd, "node") != 3) {
axl_error_new (-1, "expected to find 2 contraints for the , but not found", NULL, error);
return axl_false;
} /* end if */
doc = axl_doc_parse_from_file ("test_30.xml", error);
if (doc == NULL) {
axl_error_new (-1, "unable to parse file to check attribute validation", NULL, error);
return axl_false;
}
/* validate */
if (! axl_dtd_validate (doc, dtd, error))
return axl_false;
axl_doc_free (doc);
doc = axl_doc_parse_from_file ("test_30a.xml", error);
if (doc == NULL) {
axl_error_new (-1, "unable to parse file to check attribute validation", NULL, error);
return axl_false;
}
/* validate */
if (axl_dtd_validate (doc, dtd, error)) {
axl_error_new (-1, "Expected to find non-proper validation for enum value (2), inside attlist declaration", NULL, error);
return axl_false;
}
axl_error_free (*error);
axl_dtd_free (dtd);
dtd = axl_dtd_parse_from_file ("test_30b.dtd", error);
if (dtd == NULL)
return axl_false;
/* validate */
if (axl_dtd_validate (doc, dtd, error)) {
axl_error_new (-1, "Expected to find non-proper validation for required value, inside attlist declaration", NULL, error);
return axl_false;
}
axl_error_free (*error);
axl_doc_free (doc);
doc = axl_doc_parse_from_file ("test_30b.xml", error);
if (doc == NULL) {
axl_error_new (-1, "unable to parse file to check attribute validation", NULL, error);
return axl_false;
}
/* validate */
if (! axl_dtd_validate (doc, dtd, error)) {
axl_error_new (-1, "Expected to FIND proper validation for required value, inside attlist declaration", NULL, error);
return axl_false;
}
axl_doc_free (doc);
axl_dtd_free (dtd);
return axl_true;
}
#ifdef AXL_NS_SUPPORT
#define HTML_NS "http://www.w3.org/1999/xhtml"
#define BOOK_NS "urn:loc.gov:books"
#define ISBN_NS "urn:ISBN:0-395-36341-6"
/**
* @brief Test namespace defaulting support from axl ns library.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_29 (axlError ** error)
{
axlDoc * doc;
axlNode * node;
/* parse namespace file */
doc = axl_doc_parse_from_file ("test_29.xml", error);
if (doc == NULL)
return axl_false;
/* call to validate namespace */
if (! axl_ns_doc_validate (doc, error))
return axl_false;
/* get root document */
node = axl_doc_get_root (doc);
/* find number inside isbn namespace */
node = axl_ns_node_find_called (node, HTML_NS, "p");
if (node == NULL || ! axl_ns_node_cmp (node, HTML_NS, "p")) {
axl_error_new (-1, "Expected to find xhtml p node, but it wasn't found", NULL, error);
return axl_false;
} /* end if */
/* get root document */
node = axl_doc_get_root (doc);
/* find number inside isbn namespace */
node = axl_ns_node_get_child_called (node, ISBN_NS, "number");
if (node == NULL || ! axl_ns_node_cmp (node, ISBN_NS, "number")) {
axl_error_new (-1, "Expected to find isbn number node, but it wasn't found", NULL, error);
return axl_false;
} /* end if */
/* find number inside isbn namespace */
node = axl_ns_node_get_next_called (node, ISBN_NS, "test");
if (node == NULL || ! axl_ns_node_cmp (node, ISBN_NS, "test")) {
axl_error_new (-1, "Expected to find isbn test node, but it wasn't found", NULL, error);
return axl_false;
} /* end if */
/* free document */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Test namespace defaulting support from axl ns library.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_28 (axlError ** error)
{
axlDoc * doc;
axlNode * node;
/* parse namespace file */
doc = axl_doc_parse_from_file ("test_28.xml", error);
if (doc == NULL)
return axl_false;
/* call to validate namespace */
if (! axl_ns_doc_validate (doc, error))
return axl_false;
/* get root document */
node = axl_doc_get_root (doc);
/* get following node */
node = axl_node_get_first_child (node);
/* check default namespace */
if (! axl_ns_node_cmp (node, HTML_NS, "table")) {
axl_error_new (-1, "expected to find a valid ns-node-cmp, but it wasn't found", NULL, error);
return axl_false;
}
/* get the following */
node = axl_node_get_first_child (node);
/* check default namespace */
if (! axl_ns_node_cmp (node, HTML_NS, "th")) {
axl_error_new (-1, "expected to find a valid ns-node-cmp, but it wasn't found", NULL, error);
return axl_false;
}
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Test namespace support from axl ns library.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_27 (axlError ** error)
{
axlDoc * doc;
axlNode * node;
/* parse namespace file */
doc = axl_doc_parse_from_file ("test_27.xml", error);
if (doc == NULL)
return axl_false;
/* call to validate namespace */
if (! axl_ns_doc_validate (doc, error))
return axl_false;
/* get root document */
node = axl_doc_get_root (doc);
if (! axl_ns_node_cmp (node, BOOK_NS, "book")) {
axl_error_new (-1, "expected to find a valid ns-node-cmp, but it wasn't found", NULL, error);
return axl_false;
}
/* get first child */
node = axl_node_get_first_child (node);
if (! axl_ns_node_cmp (node, BOOK_NS, "title")) {
axl_error_new (-1, "expected to find a failure validating with ns-node-cmp, but it wasn't found", NULL, error);
return axl_false;
}
node = axl_node_get_next (node);
if (axl_ns_node_cmp (node, BOOK_NS, "number")) {
axl_error_new (-1, "expected to find a failure validating with ns-node-cmp, but it wasn't found", NULL, error);
return axl_false;
}
/* get next */
if (! axl_ns_node_cmp (node, ISBN_NS, "number")) {
axl_error_new (-1, "expected to find a valid ns-node-cmp, but it wasn't found", NULL, error);
return axl_false;
}
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Test namespace support from axl ns library.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_26 (axlError ** error)
{
axlDoc * doc;
/* parse namespace file */
doc = axl_doc_parse_from_file ("test_26.xml", error);
if (doc == NULL)
return axl_false;
/* call to validate namespace */
if (! axl_ns_doc_validate (doc, error))
return axl_false;
axl_doc_free (doc);
/* parse a namespace file that do not follow rules (node) */
doc = axl_doc_parse_from_file ("test_26b.xml", error);
if (doc == NULL)
return axl_false;
/* call to validate namespace */
if (axl_ns_doc_validate (doc, error)) {
axl_error_new (-1, "Expected to find ns validation error, but not found (test_26b)", NULL, error);
return axl_false;
}
axl_error_free (*error);
axl_doc_free (doc);
/* parse a namespace file that do not follow rules (attribute) */
doc = axl_doc_parse_from_file ("test_26c.xml", error);
if (doc == NULL)
return axl_false;
/* call to validate namespace */
if (axl_ns_doc_validate (doc, error)) {
axl_error_new (-1, "Expected to find ns validation error, but not found (test_26c)", NULL, error);
return axl_false;
}
axl_error_free (*error);
axl_doc_free (doc);
return axl_true;
}
#endif /* end #ifdef AXL_NS_SUPPORT */
/**
* @brief Test Axl Item API while performing lookups.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_25 (axlError ** error) {
axlDoc * doc;
axlNode * root;
axlNode * node;
/* load the document */
doc = axl_doc_parse_from_file ("test_23.xml", error);
if (doc == NULL)
return axl_false;
/* get root node */
root = axl_doc_get_root (doc);
/* lookup a node */
node = axl_node_find_called (root, "child3");
if (! NODE_CMP_NAME (node, "child3")) {
axl_error_new (-1, "Expected to find node but it wasn't found", NULL, error);
return axl_false;
}
/* lookup a node */
node = axl_node_find_called (root, "strong");
if (! NODE_CMP_NAME (node, "strong")) {
axl_error_new (-1, "Expected to find node but it wasn't found", NULL, error);
return axl_false;
}
if (! axl_cmp (axl_node_get_content (node, NULL), "this content goes\n bold")) {
axl_error_new (-1, "Expected to find node content, but it wasn't found", NULL, error);
return axl_false;
}
/* lookup a node */
node = axl_node_find_called (root, "strong1");
if (node != NULL) {
axl_error_new (-1, "Expected to not find node content, but it wasn't found", NULL, error);
return axl_false;
}
/* free the document */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Test Axl Item API while replacing nodes and adding content
* on a particular position.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_24 (axlError ** error) {
if (! axl_node_has_invalid_chars ("MEDIR PIEZAS S/MUESTREO EN MAQUINA DE VISION SIN CONTACTO\n\
\n\
LOTES<10 UDS. 100%PIEZAS\n\
10 UDS.20 UDS 12+10% (SOBRE 20 PIEZAS) \n\
\n\
¡ATENCION!!!!\n\
MANIPULAR PIEZAS CON GUANTES DE LATEX EVITANDO CONTAMINAR LAS PIEZAS", -1, NULL)) {
axl_error_new (-1, "Expected to find invalid characters, but it wasn't found", NULL, error);
return axl_false;
}
if (axl_node_has_invalid_chars ("MEDIR PIEZAS S/MUESTREO EN MAQUINA DE VISION SIN CONTACTO\n\
\n\
LOTES 10 UDS. 100%PIEZAS\n\
10 UDS. LOTES 20 UDS. 10+20% (SOBRE 10 PIEZAS)\n\
LOTES20 UDS 12+10% (SOBRE 20 PIEZAS) \n\
\n\
¡ATENCION!!!!\n\
MANIPULAR PIEZAS CON GUANTES DE LATEX EVITANDO CONTAMINAR LAS PIEZAS", -1, NULL)) {
axl_error_new (-1, "Expected to find valid characters, but it wasn't found", NULL, error);
return axl_false;
}
return axl_true;
}
/**
* @brief Test Axl Item API while replacing nodes and adding content
* on a particular position.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_23 (axlError ** error)
{
axlDoc * doc;
axlDoc * doc2;
axlNode * node;
axlItem * item;
/* load the document */
doc = axl_doc_parse_from_file ("test_23.xml", error);
if (doc == NULL)
return axl_false;
/* get the child1 node */
node = axl_doc_get (doc, "/document/childs/child3a");
if (node == NULL) {
axl_error_new (-1, "Unable to get child3a node under /document/child3a", NULL, error);
return axl_false;
}
if (! NODE_CMP_NAME (node, "child3a")) {
axl_error_new (-1, "Found node that wasn't expected", NULL, error);
return axl_false;
}
if (! axl_node_is_empty (node)) {
axl_error_new (-1, "Expected to find child3a node to be empty, but it wasn't found", NULL, error);
return axl_false;
}
/* get the child1 node */
node = axl_doc_get (doc, "/document/childs/child1");
if (node == NULL) {
axl_error_new (-1, "Unable to get child1 node under /document/childs", NULL, error);
return axl_false;
}
if (! NODE_CMP_NAME (node, "child1")) {
axl_error_new (-1, "Found node that wasn't expected", NULL, error);
return axl_false;
}
/* create content */
item = axl_item_new (ITEM_CONTENT, "This is a test");
/* replace the node */
axl_item_replace (axl_item_node_holder (node), item, axl_true);
/* now parse the reference xml document */
doc2 = axl_doc_parse_from_file ("test_23b.xml", error);
if (doc2 == NULL)
return axl_false;
/* check that both documents are equal */
if (! axl_doc_are_equal_trimmed (doc, doc2)) {
axl_error_new (-1, "Expected to find equal documents, but it wasn't found", NULL, error);
return axl_false;
}
/* free the document */
axl_doc_free (doc);
/* load the document */
doc = axl_doc_parse_from_file ("test_23.xml", error);
if (doc == NULL)
return axl_false;
/* check that both documents aren't equal using strict comparation */
if (axl_doc_are_equal (doc, doc2)) {
axl_error_new (-1, "Expected to find documents not equal, but it wasn't found", NULL, error);
return axl_false;
}
/* free the document */
axl_doc_free (doc);
axl_doc_free (doc2);
/* test ok */
return axl_true;
}
/**
* @brief Test xml attribute support.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_22 (axlError ** error)
{
axlDoc * doc;
axlNode * node;
const char * value;
axlAttrCursor * cursor;
/* create a document */
doc = axl_doc_create (NULL, NULL, axl_false);
node = axl_node_create ("root-node");
axl_doc_set_root (doc, node);
/* check for attributes */
if (axl_node_has_attribute (node, "attribute-not-found")) {
axl_error_new (-1, "Found an attribute requested, which doesn't exists", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute-not-found");
if (value != NULL) {
axl_error_new (-1, "Found an attribute requested, which doesn't exists", NULL, error);
return axl_false;
}
/* store an attriburte */
axl_node_set_attribute (node, "attribute1", "value1");
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute1")) {
axl_error_new (-1, "Not found an attribute requested, which should exists", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute1");
if (! axl_cmp (value, "value1")) {
axl_error_new (-1, "Not found an attribute requested, which should exists", NULL, error);
return axl_false;
}
/* store more attributes to check function with hashes */
axl_node_set_attribute (node, "attribute2", "value2");
axl_node_set_attribute (node, "attribute3", "value3");
axl_node_set_attribute (node, "attribute4", "value4");
axl_node_set_attribute (node, "attribute5", "value5");
axl_node_set_attribute (node, "attribute6", "value6");
/* check axl attribute iteration API */
cursor = axl_node_attr_cursor_new (node);
while (axl_node_attr_cursor_has_item (cursor)) {
if (axl_cmp ("attribute2", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value2", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute2' isn't 'value2'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute3", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value3", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute3' isn't 'value3'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute4", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value4", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute4' isn't 'value4'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute5", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value5", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute5' isn't 'value5'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute6", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value6", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute6' isn't 'value6'", NULL, error);
return axl_false;
} /* end if */
/* go next */
axl_node_attr_cursor_next (cursor);
} /* end if */
axl_node_attr_cursor_free (cursor);
axl_node_set_attribute (node, "attribute7", "value7");
axl_node_set_attribute (node, "attribute8", "value8");
axl_node_set_attribute (node, "attribute9", "value9");
axl_node_set_attribute (node, "attribute10", "value10");
axl_node_set_attribute (node, "attribute11", "value11");
/* check that an attribute doesn't exists */
if (axl_node_has_attribute (node, "attribute-not-found")) {
axl_error_new (-1, "Found an attribute requested, which doesn't exists", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute-not-found");
if (value != NULL) {
axl_error_new (-1, "Found an attribute requested, which doesn't exists", NULL, error);
return axl_false;
}
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute2")) {
axl_error_new (-1, "Not found an attribute requested, which should exists(2)", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute2");
if (! axl_cmp (value, "value2")) {
printf ("value2 != %s\n", value);
axl_error_new (-1, "Not found an attribute requested, which should exists(value2)", NULL, error);
return axl_false;
}
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute3")) {
axl_error_new (-1, "Not found an attribute requested, which should exists(3)", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute3");
if (! axl_cmp (value, "value3")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value3)", NULL, error);
return axl_false;
}
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute4")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value4)", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute4");
if (! axl_cmp (value, "value4")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value4)", NULL, error);
return axl_false;
}
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute5")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value5)", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute5");
if (! axl_cmp (value, "value5")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value5)", NULL, error);
return axl_false;
}
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute6")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value6)", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute6");
if (! axl_cmp (value, "value6")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value6)", NULL, error);
return axl_false;
}
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute7")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value7)", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute7");
if (! axl_cmp (value, "value7")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value7)", NULL, error);
return axl_false;
}
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute8")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value8)", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute8");
if (! axl_cmp (value, "value8")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value8)", NULL, error);
return axl_false;
}
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute9")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value9)", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute9");
if (! axl_cmp (value, "value9")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value9)", NULL, error);
return axl_false;
}
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute10")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value10)", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute10");
if (! axl_cmp (value, "value10")) {
axl_error_new (-1, "Not found an attribute value requested, which should exists (value10)", NULL, error);
return axl_false;
}
/* check for attributes */
if (! axl_node_has_attribute (node, "attribute11")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value11)", NULL, error);
return axl_false;
}
/* get attribute */
value = axl_node_get_attribute_value (node, "attribute11");
if (! axl_cmp (value, "value11")) {
axl_error_new (-1, "Not found an attribute requested, which should exists (value11)", NULL, error);
return axl_false;
}
/* check axl attribute iteration API */
cursor = axl_node_attr_cursor_new (node);
while (axl_node_attr_cursor_has_item (cursor)) {
if (axl_cmp ("attribute2", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value2", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute2' isn't 'value2'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute3", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value3", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute3' isn't 'value3'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute4", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value4", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute4' isn't 'value4'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute5", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value5", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute5' isn't 'value5'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute6", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value6", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute6' isn't 'value6'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute7", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value7", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute7' isn't 'value7'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute8", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value8", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute8' isn't 'value8'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute9", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value9", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute9' isn't 'value9'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute10", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value10", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute10' isn't 'value10'", NULL, error);
return axl_false;
} /* end if */
if (axl_cmp ("attribute11", axl_node_attr_cursor_get_key (cursor)) &&
! axl_cmp ("value11", axl_node_attr_cursor_get_value (cursor))) {
axl_error_new (-1, "Found that the value associated to 'attribute11' isn't 'value11'", NULL, error);
return axl_false;
} /* end if */
/* go next */
axl_node_attr_cursor_next (cursor);
} /* end if */
axl_node_attr_cursor_free (cursor);
/* remove attributes */
if (axl_node_num_attributes (node) != 11) {
axl_error_new (-1, "Expected to find 11 attributes", NULL, error);
return axl_false;
}
printf ("Test 22: removing attribute 1, current attributes are %d\n", axl_node_num_attributes (node));
axl_node_remove_attribute (node, "attribute1");
printf ("Test 22: after removing attribute 1, current attributes are %d\n", axl_node_num_attributes (node));
if (axl_node_num_attributes (node) != 10) {
axl_error_report (error, -1, "Expected to find 10 attributes, but found: %d", axl_node_num_attributes (node));
return axl_false;
}
if (axl_node_has_attribute (node, "attribute1")) {
axl_error_new (-1, "Found that attribute1 should not appear, but it was found", NULL, error);
return axl_false;
} /* end if */
node = axl_node_create ("test");
axl_node_set_attribute (node, "test", "test");
if (axl_node_num_attributes (node) != 1) {
axl_error_new (-1, "Expected to find 1 attributes", NULL, error);
return axl_false;
}
axl_node_remove_attribute (node, "test");
if (axl_node_num_attributes (node) != 0) {
axl_error_new (-1, "Expected to find 1 attributes", NULL, error);
return axl_false;
}
axl_node_set_attribute (node, "test1", "test");
axl_node_set_attribute (node, "test2", "test");
axl_node_set_attribute (node, "test3", "test");
if (axl_node_num_attributes (node) != 3) {
axl_error_new (-1, "Expected to find 3 attributes", NULL, error);
return axl_false;
}
axl_node_remove_attribute (node, "test1");
axl_node_remove_attribute (node, "test2");
axl_node_remove_attribute (node, "test3");
if (axl_node_num_attributes (node) != 0) {
axl_error_new (-1, "Expected to find 0 attributes", NULL, error);
return axl_false;
}
axl_node_free (node);
/* free document */
axl_doc_free (doc);
/* check to parse a document with */
doc = axl_doc_parse_from_file ("test_22.xml", NULL);
if (doc != NULL) {
axl_error_report (error, -1, "Expected to find a failure while reading an xml document with duplicated attributes");
return axl_false;
} /* end if */
/* check for empty attributes ( ='value') */
doc = axl_doc_parse_from_file ("test_22b.xml", NULL);
if (doc != NULL) {
axl_error_report (error, -1, "Expected to find a failure while loading a document with empty attributes");
return axl_false;
}
/* check for empty values associated to
* attributes ( value=' this value ' ) */
doc = axl_doc_parse_from_file ("test_22c.xml", NULL);
if (doc != NULL) {
axl_error_report (error, -1, "Expected to find a failure while loading a document with empty attributes values");
return axl_false;
} /* end if */
doc = axl_doc_create (NULL, NULL, axl_true);
node = axl_node_create ("test");
axl_doc_set_root (doc, node);
/* configure attributes */
axl_node_set_attribute (node, "", "a value");
/* configure attribute */
axl_node_set_attribute (node, "", "");
/* configure attribute */
axl_node_set_attribute (node, "", "another value");
if (! axl_doc_dump_pretty_to_file (doc, "test_22-test.xml", 4)) {
axl_error_report (error, -1, "Expected to find proper dump after wrong attribute configuration..");
return axl_false;
} /* end if */
axl_doc_free (doc);
/* check for empty values associated to
* attributes ( value=' this value ' ) */
doc = axl_doc_parse_from_file ("test_22-test.xml", NULL);
if (doc == NULL) {
axl_error_report (error, -1, "Expected to find proper document loading after wrong attribute configuration.");
return axl_false;
} /* end if */
/* free documnent */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Test mixed content documents support (TEST NOT FINISHED).
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_21 (axlError ** error)
{
axlDoc * doc;
axlNode * node;
axlItem * item;
char * content;
int content_size;
/* load the document */
doc = axl_doc_parse_from_file ("test_21.xml", error);
if (doc == NULL)
return axl_false;
/* get the root node */
node = axl_doc_get_root (doc);
/* check document content */
if (! NODE_CMP_NAME (node, "document")) {
axl_error_new (-1, "Expected to find root node= but it wasn't found", NULL, error);
return axl_false;
}
/* iterate root childs */
item = axl_item_get_first_child (node);
if (axl_item_get_type (item) != ITEM_CONTENT) {
axl_error_new (-1, "Expected to find content but it wasn't found", NULL, error);
return axl_false;
}
/* get the content */
content = axl_item_get_content (item, &content_size);
if (! axl_cmp (content, "\n Some content inside the document ")) {
axl_error_new (-1, "Expected to find content but it wasn't found", NULL, error);
return axl_false;
}
/* get tne the item */
item = axl_item_get_next (item);
if (axl_item_get_type (item) != ITEM_NODE) {
axl_error_new (-1, "Expected to find a node but it wasn't found", NULL, error);
return axl_false;
}
/* get the node */
node = axl_item_get_data (item);
/* check document content */
if (! NODE_CMP_NAME (node, "strong")) {
axl_error_new (-1, "Expected to find root node= but it wasn't found", NULL, error);
return axl_false;
}
/* get the first child of */
item = axl_item_get_first_child (node);
if (axl_item_get_type (item) != ITEM_CONTENT) {
axl_error_new (-1, "Expected to find content inside strong but it wasn't found", NULL, error);
return axl_false;
}
/* get the content */
content = axl_item_get_content (item, &content_size);
if (! axl_cmp (content, "this content goes\n bold")) {
axl_error_new (-1, "Expected to find content but it wasn't found", NULL, error);
return axl_false;
}
/* now get the next item following the node */
item = axl_item_node_next (node);
if (item == NULL) {
axl_error_new (-1, "Expected to find content following but a null item reference was found", NULL, error);
return axl_false;
}
/* check to be it a content */
if (axl_item_get_type (item) != ITEM_CONTENT) {
axl_error_new (-1, "Expected to find content following node but it wasn't found", NULL, error);
return axl_false;
}
/* get the content */
content = axl_item_get_content (item, &content_size);
if (! axl_cmp (content, " more data stored directly inside the document node.\n\n ")) {
axl_error_new (-1, "Expected to find content but it wasn't found", NULL, error);
return axl_false;
}
/* get the next item */
item = axl_item_get_next (item);
if (axl_item_get_type (item) != ITEM_NODE) {
axl_error_new (-1, "Expected to find a node but it wasn't found", NULL, error);
return axl_false;
}
/* get the node */
node = axl_item_get_data (item);
/* check document content */
if (! NODE_CMP_NAME (node, "childs")) {
axl_error_new (-1, "Expected to find root node= but it wasn't found", NULL, error);
return axl_false;
}
/* get the first item */
item = axl_item_get_first_child (node);
if (axl_item_get_type (item) != ITEM_COMMENT) {
axl_error_new (-1, "Expected to find content inside strong but it wasn't found", NULL, error);
return axl_false;
}
/* get the content */
content = axl_item_get_content (item, &content_size);
if (! axl_cmp (content, " here goes a comment before text block ")) {
axl_error_new (-1, "Expected to find a comment, child of , but it wasn't found", NULL, error);
return axl_false;
}
/* get next item */
item = axl_item_get_next (item);
/* check to be it a content */
if (axl_item_get_type (item) != ITEM_CONTENT) {
axl_error_new (-1, "Expected to find content following node comment but it wasn't found", NULL, error);
return axl_false;
}
/* get the content */
content = axl_item_get_content (item, &content_size);
if (! axl_cmp (content, "More text after child declaration.\n ")) {
axl_error_new (-1, "Expected to find a content inside node, but it wasn't found", NULL, error);
return axl_false;
}
/* get next item */
item = axl_item_get_next (item);
/* get the node */
node = axl_item_get_data (item);
/* check document content */
if (! NODE_CMP_NAME (node, "child1")) {
axl_error_new (-1, "Expected to find root node= but it wasn't found", NULL, error);
return axl_false;
}
/* free axl document */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Test entity support (basic entity support).
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_20b (axlError ** error)
{
axlNode * node;
axlNode * aux;
axlNode * aux2;
axlNode * child1;
axlNode * root;
axlDoc * doc;
axlDoc * doc2;
axlDoc * doc3;
int iterator = 0;
int sum = 0;
/* load the document */
doc = axl_doc_parse_from_file ("test_20.xml", error);
if (doc == NULL)
return axl_false;
/* load reference */
doc2 = axl_doc_parse_from_file ("test_20a.xml", error);
if (doc2 == NULL)
return axl_false;
while (iterator < 10) {
/* get document root */
root = axl_doc_get_root (doc);
/* copy and release */
node = axl_node_copy (root, axl_true, axl_true);
/* get the child1 reference */
child1 = axl_node_get_first_child (node);
/* get child2 refrence */
aux = axl_node_get_first_child (child1);
while (aux != NULL) {
sum = axl_node_get_child_num (child1);
/* get the next child before deattaching the
* node */
aux2 = axl_node_get_next (aux);
/* dettach the node from the parent
* and attach it to the document */
axl_node_deattach (aux);
if ((sum - 1) != (axl_node_get_child_num (child1))) {
/* after doing the deattach process,
* the copy node doesn't have the
* expected child number */
axl_error_new (-1, "After doing the deattach process, the copy node doesn't have the expected child number", NULL, error);
return axl_false;
}
/* set the node to the document root */
axl_node_set_child (node, aux);
if (! NODE_CMP_NAME (axl_node_get_parent (aux), "document")) {
axl_error_new (-1, "Expected to find a parent not found", NULL, error);
return axl_false;
}
/* get the next child */
aux = aux2;
} /* end while */
/* remove the child1 node */
aux = axl_node_get_first_child (node);
axl_node_remove (aux, axl_true);
/* create the document holding the result */
doc3 = axl_doc_create (NULL, NULL, axl_false);
axl_doc_set_root (doc3, node);
/* compare the document */
if (!axl_doc_are_equal (doc2, doc3)) {
axl_error_new (-1, "Expected to find equal documents but (modified doc2 != doc3), they wasn't found", NULL, error);
return axl_false;
}
/* free the document */
axl_doc_free (doc3);
/* update iterator */
iterator++;
} /* end while */
/* free the document 2 */
axl_doc_free (doc2);
/* free the document */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Test entity support (basic entity support).
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_20 (axlError ** error)
{
axlNode * node;
axlNode * root;
axlDoc * doc;
axlDoc * doc2;
char * data;
/* load the document */
doc = axl_doc_parse_from_file ("test_20.xml", error);
if (doc == NULL)
return axl_false;
/* get document root */
root = axl_doc_get_root (doc);
node = axl_node_copy (root, axl_true, axl_true);
/* check if both nodes are equal */
if (! axl_node_are_equal (root, node)) {
axl_error_new (-1, "Expected to find equal nodes but they weren't", NULL, error);
return axl_false;
}
/* create a new document */
doc2 = axl_doc_create (NULL, NULL, axl_false);
axl_doc_set_root (doc2, node);
if (! axl_doc_are_equal (doc, doc2)) {
axl_error_new (-1, "Expected to find equal documents but they weren't", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc2);
/* configure some anotation data */
axl_node_annotate_data (root, "key", "value");
/* get child1 */
node = axl_node_get_first_child (root);
/* get child2 */
node = axl_node_get_first_child (node);
/* anotate data */
axl_node_annotate_data (node, "key1", "value1");
/* perform searches */
data = axl_node_annotate_get (node, "key", axl_false);
if (data != NULL) {
axl_error_new (-1, "Expected to find nothing while looking for 'key'(1)", NULL, error);
return axl_false;
}
data = axl_node_annotate_get (node, "key", axl_true);
if (data == NULL || !axl_cmp (data, "value")) {
axl_error_new (-1, "Expected to find data while looking for 'key' at parents (2)", NULL, error);
return axl_false;
}
/* perform searches inside the node */
data = axl_node_annotate_get (node, "key1", axl_false);
if (data == NULL || !axl_cmp (data, "value1")) {
axl_error_new (-1, "Expected to find nothing while looking for 'key1'(3)", NULL, error);
return axl_false;
}
/* perform more anotation but with native data */
axl_node_annotate_int (root, "int-value", 14);
if (axl_node_annotate_get_int (root, "int-value", axl_false) != 14) {
axl_error_new (-1, "Expected to find an integer value (14), but it wasn't found", NULL, error);
return axl_false;
}
axl_node_annotate_double (root, "double-value", 58.20);
if (axl_node_annotate_get_double (root, "double-value", axl_false) != 58.20) {
axl_error_new (-1, "Expected to find an double value (58.20), but it wasn't found", NULL, error);
return axl_false;
}
axl_node_annotate_string (root, "string-value", "this is a test string");
if (! axl_cmp (axl_node_annotate_get_string (root, "string-value", axl_false), "this is a test string")) {
axl_error_new (-1, "Expected to find a string value (\"this is a test string\"), but it wasn't found", NULL, error);
return axl_false;
}
if (axl_node_annotate_get_string (root, "string-not-found", axl_false) != NULL) {
axl_error_new (-1, "Expected to find empty value for an anotated element which isn't installed", NULL, error);
return axl_false;
}
/* free document created */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Test entity support (basic entity support).
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_19 (axlError ** error)
{
axlDoc * doc;
axlDoc * reference;
axlNode * node;
axlNode * replace;
/* create replace node */
replace = axl_node_create ("replace");
axl_node_set_content (replace, "test", -1);
doc = axl_doc_parse_from_file ("test_19.xml", error);
if (doc == NULL)
return axl_false;
/* document */
node = axl_doc_get_root (doc);
/* child1 */
node = axl_node_get_first_child (node);
/* child2 */
node = axl_node_get_first_child (node);
/* replace */
axl_node_replace (node, replace, axl_false);
reference = axl_doc_parse_from_file ("test_19a.xml", error);
if (reference == NULL)
return axl_false;
/* check both documents to be equal */
if (! axl_doc_are_equal (doc, reference)) {
axl_error_new (-1, "Expected to find equal documents, but not found on first child replace", NULL, error);
return axl_false;
}
/* free reference */
axl_doc_free (reference);
/* restore */
axl_node_replace (replace, node, axl_false);
/* get child2 */
node = axl_node_get_next (node);
/* replace */
axl_node_replace (node, replace, axl_false);
reference = axl_doc_parse_from_file ("test_19b.xml", error);
if (reference == NULL)
return axl_false;
/* check both documents to be equal */
if (! axl_doc_are_equal (doc, reference)) {
axl_error_new (-1, "Expected to find equal documents, but not found on first child replace", NULL, error);
return axl_false;
}
/* free reference */
axl_doc_free (reference);
/* restore */
axl_node_replace (replace, node, axl_false);
/* get child2 */
node = axl_node_get_next (node);
/* get child2 */
node = axl_node_get_next (node);
/* replace */
axl_node_replace (node, replace, axl_true);
reference = axl_doc_parse_from_file ("test_19c.xml", error);
if (reference == NULL)
return axl_false;
/* check both documents to be equal */
if (! axl_doc_are_equal (doc, reference)) {
axl_error_new (-1, "Expected to find equal documents, but not found on first child replace", NULL, error);
return axl_false;
}
/* free reference */
axl_doc_free (reference);
node = axl_node_create ("child5");
axl_node_set_content (node, "test", -1);
/* replace */
axl_node_replace (replace, node, axl_true);
/* document */
node = axl_doc_get_root (doc);
/* child1 */
node = axl_node_get_first_child (node);
/* child2 */
node = axl_node_get_first_child (node);
/* remove child2 */
axl_node_remove (node, axl_true);
reference = axl_doc_parse_from_file ("test_19d.xml", error);
if (reference == NULL)
return axl_false;
/* check both documents to be equal */
if (! axl_doc_are_equal (doc, reference)) {
axl_error_new (-1, "Expected to find equal documents, but not found on first child remove", NULL, error);
return axl_false;
}
/* free reference */
axl_doc_free (reference);
/* document */
node = axl_doc_get_root (doc);
/* child1 */
node = axl_node_get_first_child (node);
/* child3 */
node = axl_node_get_first_child (node);
/* remove child3 */
axl_node_remove (node, axl_true);
reference = axl_doc_parse_from_file ("test_19e.xml", error);
if (reference == NULL)
return axl_false;
/* check both documents to be equal */
if (! axl_doc_are_equal (doc, reference)) {
axl_error_new (-1, "Expected to find equal documents, but not found on first child remove", NULL, error);
return axl_false;
}
/* free reference */
axl_doc_free (reference);
/* document */
node = axl_doc_get_root (doc);
/* child1 */
node = axl_node_get_first_child (node);
/* child4 */
node = axl_node_get_first_child (node);
/* remove child4 */
axl_node_remove (node, axl_true);
reference = axl_doc_parse_from_file ("test_19f.xml", error);
if (reference == NULL)
return axl_false;
/* check both documents to be equal */
if (! axl_doc_are_equal (doc, reference)) {
axl_error_new (-1, "Expected to find equal documents, but not found on first child remove", NULL, error);
return axl_false;
}
/* free reference */
axl_doc_free (reference);
/* document */
node = axl_doc_get_root (doc);
/* child1 */
node = axl_node_get_first_child (node);
/* child5 */
node = axl_node_get_first_child (node);
/* remove child5 */
axl_node_remove (node, axl_true);
reference = axl_doc_parse_from_file ("test_19g.xml", error);
if (reference == NULL)
return axl_false;
/* check both documents to be equal */
if (! axl_doc_are_equal (doc, reference)) {
axl_error_new (-1, "Expected to find equal documents, but not found on first child remove", NULL, error);
return axl_false;
}
/* free reference */
axl_doc_free (reference);
/* free document */
axl_doc_free (doc);
/* free reference */
return axl_true;
}
/**
* @brief Test entity support (basic entity support).
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_18 (axlError ** error)
{
axlDtd * dtd = NULL;
char * content;
/* parse af-arch DTD */
dtd = axl_dtd_parse_from_file ("channel.dtd", error);
if (dtd == NULL)
return axl_false;
/* lookup for entity definitions */
if (axl_dtd_entity_exists (dtd, "TEST", GENERAL_ENTITY)) {
axl_error_new (-1, "Expected to not find an entity value which was found (TEST)..", NULL, error);
return axl_false;
}
if (axl_dtd_entity_exists (dtd, "URI", GENERAL_ENTITY)) {
axl_error_new (-1, "Expected to not find an entity value which was found (URI)..", NULL, error);
return axl_false;
}
/* lookup for entity definitions that are expected to be found */
if (! axl_dtd_entity_exists (dtd, "URI", PARAMETER_ENTITY)) {
axl_error_new (-1, "Expected to find an entity value which wasn't found (% URI)..", NULL, error);
return axl_false;
}
if (! axl_dtd_entity_exists (dtd, "LOCS", PARAMETER_ENTITY)) {
axl_error_new (-1, "Expected to find an entity value which wasn' found (% LOCS)..", NULL, error);
return axl_false;
}
/* now get the content inside */
content = axl_dtd_entity_value (dtd, "CHAN", PARAMETER_ENTITY);
if (content == NULL) {
axl_error_new (-1, "Expected to find parameter entity content for (% CHAN) but it wasn't found", NULL, error);
return axl_false;
}
if (! axl_cmp (content, "CDATA")) {
axl_error_new (-1, "Expected to find parameter entity content for (% CHAN) it doesn't match", NULL, error);
return axl_false;
}
/* free the dtd */
axl_dtd_free (dtd);
return axl_true;
}
/**
* @brief A more complex DTD parsing example
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_17 (axlError ** error)
{
axlDoc * doc = NULL;
axlDtd * dtd = NULL;
/* parse common DTD file */
dtd = axl_dtd_parse_from_file ("xml-rpc.dtd", error);
if (dtd == NULL)
return axl_false;
/* parse a file that must not be valid */
doc = axl_doc_parse_from_file ("test17.xdl", error);
if (doc == NULL)
return axl_false;
/* the following validation must fail */
if (axl_dtd_validate (doc, dtd, error)) {
axl_error_new (-1, "A validation was produced when expected a failure", NULL, error);
return axl_false;
}
/* because a failure was expected, release memory allocated by
* axl_error_new */
axl_error_free (*error);
/* free the document */
axl_doc_free (doc);
/* release DTD reference */
axl_dtd_free (dtd);
return axl_true;
}
/**
* @brief A more complex DTD parsing example
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_16 (axlError ** error)
{
axlDoc * doc = NULL;
axlDtd * dtd = NULL;
/* parse common DTD file */
dtd = axl_dtd_parse_from_file ("xml-rpc.dtd", error);
if (dtd == NULL)
return axl_false;
/* parse a file that must not be valid */
doc = axl_doc_parse_from_file ("test03.xdl", error);
if (doc == NULL)
return axl_false;
/* the following validation must fail */
if (axl_dtd_validate (doc, dtd, error)) {
axl_error_new (-1, "A validation was produced when expected a failure", NULL, error);
return axl_false;
}
/* because a failure was expected, release memory allocated by
* axl_error_new */
axl_error_free (*error);
/* free the document */
axl_doc_free (doc);
/* parse the next file that must be valid */
doc = axl_doc_parse_from_file ("test04.xdl", error);
if (doc == NULL)
return axl_false;
/* the following validation should successed */
if (! axl_dtd_validate (doc, dtd, error))
return axl_false;
/* release the document */
axl_doc_free (doc);
/* release DTD reference */
axl_dtd_free (dtd);
return axl_true;
}
/**
* @brief A more complex DTD parsing example
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_15 (axlError ** error)
{
axlDoc * doc = NULL;
axlDtd * dtd = NULL;
/* parse common DTD file */
dtd = axl_dtd_parse_from_file ("xml-rpc.dtd", error);
if (dtd == NULL)
return axl_false;
/* parse a file that must not be valid */
doc = axl_doc_parse_from_file ("test01.xdl", error);
if (doc == NULL)
return axl_false;
/* the following validation must fail */
if (axl_dtd_validate (doc, dtd, error)) {
axl_error_new (-1, "A validation was produced when expected a failure", NULL, error);
return axl_false;
}
/* because a failure was expected, release memory allocated by
* axl_error_new */
axl_error_free (*error);
/* free the document */
axl_doc_free (doc);
/* parse the next file that must be valid */
doc = axl_doc_parse_from_file ("test02.xdl", error);
if (doc == NULL)
return axl_false;
/* the following validation should successed */
if (! axl_dtd_validate (doc, dtd, error))
return axl_false;
/* release the document */
axl_doc_free (doc);
/* release DTD reference */
axl_dtd_free (dtd);
return axl_true;
}
/**
* @brief A more complex DTD parsing example
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_14 (axlError ** error)
{
axlDoc * doc = NULL;
axlNode * node = NULL;
char * xml_document;
char * value;
int size = 0;
int document_size;
/* create an emtpy document */
doc = axl_doc_create ("1.0", NULL, axl_false);
/* create the root node */
node = axl_node_create ("test");
axl_node_set_content (node, "This is a test (') (\") (>) (<) (&), more data###", -1);
axl_doc_set_root (doc, node);
/* dump the document */
axl_doc_dump (doc, &xml_document, &document_size);
if (!axl_cmp ("This is a test (') (") (>) (<) (&), more data###",
xml_document)) {
axl_error_new (-1, "Found dump mismatch that shows entities are not handled properly", NULL, error);
return axl_false;
}
/* free memory dump */
axl_free (xml_document);
/* get the content translated */
value = axl_node_get_content_copy (node, &size);
if (size != 68) {
axl_error_new (-1, "Found a document size mismatch while dumping entity content", NULL, error);
return axl_false;
}
/* free the content received */
axl_free (value);
/* get the content translated */
value = axl_node_get_content_trans (node, &size);
if (size != 48) {
axl_error_new (-1, "Found a document size mismatch while dumping entity content (already translated)", NULL, error);
return axl_false;
}
/* check node content returned */
if (!axl_cmp (value, "This is a test (\') (\") (>) (<) (&), more data###")) {
axl_error_new (-1, "Found an string mismatch while checking a node content which was translated", NULL, error);
return axl_false;
}
/* free the content translated */
axl_free (value);
/* free document */
axl_doc_free (doc);
doc = axl_doc_parse ("", 37, error);
if (doc == NULL) {
printf ("Expected to parse a document but it fails, error was: %s\n", axl_error_get (*error));
return axl_false;
}
/* get the content */
node = axl_doc_get (doc, "/test");
if (node == NULL) {
axl_error_new (-1, "Expected to find a node reference not found (/test)\n", NULL, error);
return axl_false;
}
/* get the content */
size = 11;
value = (char*) axl_node_get_content (node, &size);
if (size != 0) {
axl_error_new (-1, "Expected to find a node content with 0 bytes but it 11 (/test)\n", NULL, error);
return axl_false;
}
/* get the content copy */
size = 13;
value = axl_node_get_content_copy (node, &size);
if (size != 0) {
axl_error_new (-1, "Expected to find a node content with 0 bytes but it 13 (/test)\n", NULL, error);
return axl_false;
}
axl_free (value);
/* get content copy trans */
size = 14;
value = axl_node_get_content_trans (node, &size);
if (size != 0) {
axl_error_new (-1, "Expected to find a node content with 0 bytes but it 14 (/test)\n", NULL, error);
return axl_false;
}
axl_free (value);
/* get content trimmed */
size = 15;
value = axl_node_get_content_trim (node, &size);
if (size != 0) {
axl_error_new (-1, "Expected to find a node content with 0 bytes but it 15 (/test)\n", NULL, error);
return axl_false;
}
/* free the document */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Memory dump operation checks.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_13 (axlError ** error)
{
axlDoc * doc = NULL;
axlDoc * doc2 = NULL;
axlDoc * doc3 = NULL;
axlNode * node = NULL;
char * content;
int size;
doc = axl_doc_parse_from_file ("test13.xml", error);
if (doc == NULL)
return axl_false;
/* dump xml document */
axl_doc_dump (doc, &content, &size);
doc2 = axl_doc_parse (content, size, error);
if (doc2 == NULL)
return axl_false;
/* check if both documents are equals */
if (! axl_doc_are_equal (doc, doc2)) {
axl_error_new (-1, "Expected to dump an equivalent xml document, but found an error", NULL, error);
return axl_false;
}
/* free dump */
axl_free (content);
/* free axl document */
axl_doc_free (doc);
/* free axl document */
axl_doc_free (doc2);
doc = axl_doc_parse_from_file ("test_13c.xml", error);
if (doc == NULL)
return axl_false;
if (! axl_doc_dump_pretty (doc, &content, &size, 4)) {
axl_error_new (-1, "Failed to dump pretty print, while expected a proper execution", NULL, error);
return axl_false;
}
doc2 = axl_doc_parse (content, size, error);
if (doc2 == NULL)
return axl_false;
/* free content */
axl_free (content);
if (! axl_doc_are_equal (doc, doc2)) {
axl_error_new (-1, "Expected to find documents to be equal.", NULL, error);
return axl_false;
}
/* free both document references */
axl_doc_free (doc);
axl_doc_free (doc2);
/* check pretty printing function */
doc = axl_doc_parse_from_file ("test_13b.xml", error);
if (doc == NULL)
return axl_false;
if (! axl_doc_dump_pretty (doc, &content, &size, 4)) {
axl_error_new (-1, "Failed to dump pretty print, while expected a proper execution", NULL, error);
return axl_false;
}
doc2 = axl_doc_parse (content, size, error);
if (doc2 == NULL)
return axl_false;
if (! axl_doc_are_equal (doc, doc2)) {
axl_error_new (-1, "Expected to find documents to be equal.", NULL, error);
return axl_false;
}
/* free content */
axl_free (content);
/* free both document references */
axl_doc_free (doc);
axl_doc_free (doc2);
/* reopen document to dump nodes */
doc = axl_doc_parse_from_file ("test_13c.xml", error);
if (doc == NULL)
return axl_false;
/* get a reference to the first root child node: */
node = axl_doc_get_root (doc);
node = axl_node_get_first_child (node);
if (! NODE_CMP_NAME (node, "test")) {
axl_error_new (-1, "Expected to find a child node called: ", NULL, error);
return axl_false;
} /* end if */
/* dump the content */
if (! axl_node_dump (node, &content, &size)) {
axl_error_new (-1, "Expected to find a proper dump operation", NULL, error);
return axl_false;
} /* end if */
/* parse the content dumped, to check it is really the result
* expected */
doc2 = axl_doc_parse (content, size, NULL);
if (doc2 == NULL) {
axl_error_new (-1, "Expected to parse properly dumped content from a node, but a failure was found", NULL, error);
return axl_false;
} /* end if */
doc3 = axl_doc_parse_from_file ("test_13d.xml", NULL);
if (doc3 == NULL) {
axl_error_new (-1, "Expected to parse properly a reference file but an error was found", NULL, error);
return axl_false;
} /* end if */
/* check result */
if (! axl_doc_are_equal (doc2, doc3)) {
axl_error_new (-1, "Expected to find equal document to reference, at node dump operations, but not found", NULL, error);
return axl_false;
} /* end if */
/* free the content */
axl_free (content);
/* free the document */
axl_doc_free (doc);
axl_doc_free (doc2);
axl_doc_free (doc3);
/* load test_13e.xml document */
doc = axl_doc_parse_from_file ("test_13e.xml", NULL);
if (doc == NULL) {
axl_error_new (-1, "Expected to find parseable document, but an error was found..", NULL, error);
return axl_false;
}
/* now dump the document */
if (!axl_doc_dump_pretty_to_file (doc, "test_13e.xml.test", 4)) {
axl_error_new (-1, "Expected to perform a proper dump operation but an error was found..", NULL, error);
return axl_false;
}
/* now open the content produced and check both results */
doc2 = axl_doc_parse_from_file ("test_13e.xml.test", NULL);
if (doc2 == NULL) {
axl_error_new (-1, "Failed to open document that was expected to be opened", NULL, error);
return axl_false;
} /* end if */
/* check both document */
if (! axl_doc_are_equal (doc, doc2)) {
axl_error_new (-1, "Expected to find equal documents before dump operation, but it wasn't found", NULL, error);
return axl_false;
}
/* free both documents */
axl_doc_free (doc2);
axl_doc_free (doc);
/* load test_13e.xml document */
doc = axl_doc_parse_from_file ("test_13f.xml", NULL);
if (doc == NULL) {
axl_error_new (-1, "Expected to find parseable document, but an error was found..", NULL, error);
return axl_false;
}
/* dump to memory */
if (! axl_doc_dump_pretty (doc, &content, &size, 4)) {
axl_error_new (-1, "Expected to find proper dump operation not found", NULL, error);
return axl_false;
} /* end if */
/* now check content dumped against the predefined value */
if (size != 1262 || ! axl_cmp (content, "\n\
\n\
\n\
\n\
Value1\n\
Value1\n\
Value1\n\
Value1\n\
Value1\n\
Value1\n\
Value1\n\
Value1\n\
\n\
\n\
\n\
Value1\n\
Value1\n\
Value1\n\
\n\
\n")) {
printf ("Content lenght found: %d and size=%d..\n", (int) strlen (content), size);
axl_error_new (-1, "Failed to check dump content, expected different values", NULL, error);
return axl_false;
} /* end if */
axl_free (content);
/* free document */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief A more complex DTD parsing example
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_12 (axlError ** error)
{
axlDoc * doc = NULL;
axlDtd * dtd = NULL;
/* parse gmovil file (an af-arch xml chunk) */
doc = axl_doc_parse_from_file ("channel.xml", error);
if (doc == NULL)
return axl_false;
/* parse af-arch DTD */
dtd = axl_dtd_parse_from_file ("channel.dtd", error);
if (dtd == NULL)
return axl_false;
/* perform DTD validation */
if (! axl_dtd_validate (doc, dtd, error)) {
return axl_false;
}
/* free doc reference */
axl_doc_free (doc);
/* parse gmovil file (an af-arch xml chunk) */
doc = axl_doc_parse_from_file ("channel2.xml", error);
if (doc == NULL)
return axl_false;
/* perform DTD validation */
if (! axl_dtd_validate (doc, dtd, error)) {
return axl_false;
}
/* free doc reference */
axl_doc_free (doc);
/* parse gmovil file (an af-arch xml chunk) */
doc = axl_doc_parse_from_file ("channel3.xml", error);
if (doc == NULL)
return axl_false;
/* perform DTD validation */
if (! axl_dtd_validate (doc, dtd, error)) {
return axl_false;
}
/* free doc reference */
axl_doc_free (doc);
/* parse gmovil file (an af-arch xml chunk) */
doc = axl_doc_parse_from_file ("channel4.xml", error);
if (doc == NULL)
return axl_false;
/* perform DTD validation */
if (! axl_dtd_validate (doc, dtd, error)) {
return axl_false;
}
/* free doc reference */
axl_doc_free (doc);
/* free dtd reference */
axl_dtd_free (dtd);
/* parse a BEEP greetins example */
doc = axl_doc_parse_from_file ("channel5.xml", error);
if (doc == NULL)
return axl_false;
/* parse the TLS dtd file */
dtd = axl_dtd_parse_from_file ("channel.dtd", error);
if (dtd == NULL)
return axl_false;
/* perform DTD validation */
if (! axl_dtd_validate (doc, dtd, error)) {
return axl_false;
}
/* free doc reference */
axl_doc_free (doc);
/* free dtd reference */
axl_dtd_free (dtd);
/* test end */
return axl_true;
}
/**
* @brief A more complex DTD parsing example
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_11 (axlError ** error)
{
axlDoc * doc = NULL;
axlDtd * dtd = NULL;
/* parse gmovil file (an af-arch xml chunk) */
doc = axl_doc_parse_from_file ("gmovil2.xml", error);
if (doc == NULL)
return axl_false;
/* parse af-arch DTD */
dtd = axl_dtd_parse_from_file ("fact.dtd", error);
if (dtd == NULL)
return axl_false;
/* perform DTD validation */
if (! axl_dtd_validate (doc, dtd, error)) {
return axl_false;
}
/* free doc reference */
axl_doc_free (doc);
/* free dtd reference */
axl_dtd_free (dtd);
/* test end */
return axl_true;
}
/**
* @brief A more complex DTD parsing example
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_10 (axlError ** error)
{
axlDoc * doc = NULL;
axlDtd * dtd = NULL;
axlDtdElement * element = NULL;
axlDtdElementList * itemList = NULL;
/* parse gmovil file (an af-arch xml chunk) */
doc = axl_doc_parse_from_file ("test5.xml", error);
if (doc == NULL)
return axl_false;
/* parse af-arch DTD */
dtd = axl_dtd_parse_from_file ("test5.dtd", error);
if (dtd == NULL)
return axl_false;
/* get the dtd element representation */
element = axl_dtd_get_element (dtd, "choices");
/* get the item list inside */
itemList = axl_dtd_get_item_list (element);
if (axl_dtd_item_list_count (itemList) != 4) {
axl_error_new (-1, "expected to receive an item list with 4 item nodes inside", NULL, error);
return axl_false;
}
if (axl_dtd_item_list_type (itemList) != CHOICE) {
axl_error_new (-1, "expected to receive a choice item list", NULL, error);
return axl_false;
}
if (axl_dtd_item_list_repeat (itemList) != ZERO_OR_MANY) {
axl_log ("test-01", AXL_LEVEL_DEBUG, "received a different repeat configuration: %d != %d",
ZERO_OR_MANY, axl_dtd_item_list_repeat (itemList));
axl_error_new (-1, "expected to receive an item list with (*) zero or many spec", NULL, error);
return axl_false;
}
/* perform DTD validation */
if (! axl_dtd_validate (doc, dtd, error)) {
return axl_false;
}
/* free dtd reference */
axl_dtd_free (dtd);
/* parse af-arch DTD */
dtd = axl_dtd_parse_from_file ("test5.1.dtd", error);
if (dtd == NULL)
return axl_false;
/* perform DTD validation */
if (axl_dtd_validate (doc, dtd, error)) {
axl_error_new (-1, "A validation failure was expected.", NULL, error);
return axl_false;
}
/* because a failure was expected, release memory allocated by
* axl_error_new */
axl_error_free (*error);
/* free doc reference */
axl_doc_free (doc);
/* free dtd reference */
axl_dtd_free (dtd);
/* test end */
return axl_true;
}
/**
* @brief A more complex DTD parsing example
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_09 (axlError ** error)
{
axlDoc * doc = NULL;
axlDtd * dtd = NULL;
axlDtdElement * element = NULL;
axlDtdElementList * itemList = NULL;
axlDtdElementListNode * itemNode = NULL;
/* parse gmovil file (an af-arch xml chunk) */
doc = axl_doc_parse_from_file ("test4.xml", error);
if (doc == NULL)
return axl_false;
/* parse af-arch DTD */
dtd = axl_dtd_parse_from_file ("test4.dtd", error);
if (dtd == NULL)
return axl_false;
/* get dtd element */
element = axl_dtd_get_element (dtd, "nodes");
if (element == NULL) {
axl_error_new (-1, "unable to find expected DTD element", NULL, error);
return axl_false;
}
/* get the item list */
itemList = axl_dtd_get_item_list (element);
if (axl_dtd_item_list_count (itemList) != 8) {
axl_log ("test-01", AXL_LEVEL_CRITICAL, "found item list size: %d != 8",
axl_dtd_item_list_count (itemList));
axl_error_new (-1, "expected to find an item list definition with 8 elements", NULL, error);
return axl_false;
}
/* check node spec */
itemNode = axl_dtd_item_list_get_node (itemList, 0);
if (axl_dtd_item_node_get_type (itemNode) != AXL_ELEMENT_NODE) {
axl_error_new (-1, "expected to find an item node definition, not found", NULL, error);
return axl_false;
}
if (! axl_cmp (axl_dtd_item_node_get_value (itemNode), "first")) {
axl_error_new (-1, "expected to find an item node name (first) definition, not found", NULL, error);
return axl_false;
}
if (axl_dtd_item_node_get_repeat (itemNode) != ONE_OR_MANY) {
axl_error_new (-1, "expected to find an item node definition with one or many repeat def (+), not found", NULL, error);
return axl_false;
}
/* check node spec */
itemNode = axl_dtd_item_list_get_node (itemList, 1);
if (axl_dtd_item_node_get_type (itemNode) != AXL_ELEMENT_NODE) {
axl_error_new (-1, "expected to find an item node definition, not found", NULL, error);
return axl_false;
}
if (! axl_cmp (axl_dtd_item_node_get_value (itemNode), "second")) {
axl_error_new (-1, "expected to find an item node name (second) definition, not found", NULL, error);
return axl_false;
}
if (axl_dtd_item_node_get_repeat (itemNode) != ONE_AND_ONLY_ONE) {
axl_error_new (-1, "expected to find an item node definition with one and only one repeat def (), not found", NULL, error);
return axl_false;
}
/* check node spec */
itemNode = axl_dtd_item_list_get_node (itemList, 2);
if (axl_dtd_item_node_get_type (itemNode) != AXL_ELEMENT_NODE) {
axl_error_new (-1, "expected to find an item node definition, not found", NULL, error);
return axl_false;
}
if (! axl_cmp (axl_dtd_item_node_get_value (itemNode), "third")) {
axl_error_new (-1, "expected to find an item node name (third) definition, not found", NULL, error);
return axl_false;
}
if (axl_dtd_item_node_get_repeat (itemNode) != ZERO_OR_ONE) {
axl_error_new (-1, "expected to find an item node definition with zero or one repeat def (?), not found", NULL, error);
return axl_false;
}
/* check node spec */
itemNode = axl_dtd_item_list_get_node (itemList, 3);
if (axl_dtd_item_node_get_type (itemNode) != AXL_ELEMENT_NODE) {
axl_error_new (-1, "expected to find an item node definition, not found", NULL, error);
return axl_false;
}
if (! axl_cmp (axl_dtd_item_node_get_value (itemNode), "fourth")) {
axl_error_new (-1, "expected to find an item node name (fourth) definition, not found", NULL, error);
return axl_false;
}
if (axl_dtd_item_node_get_repeat (itemNode) != ONE_AND_ONLY_ONE) {
axl_error_new (-1, "expected to find an item node definition with one and only one repeat def (), not found", NULL, error);
return axl_false;
}
/* check node spec */
itemNode = axl_dtd_item_list_get_node (itemList, 4);
if (axl_dtd_item_node_get_type (itemNode) != AXL_ELEMENT_NODE) {
axl_error_new (-1, "expected to find an item node definition, not found", NULL, error);
return axl_false;
}
if (! axl_cmp (axl_dtd_item_node_get_value (itemNode), "fifth")) {
axl_error_new (-1, "expected to find an item node name (fifth) definition, not found", NULL, error);
return axl_false;
}
if (axl_dtd_item_node_get_repeat (itemNode) != ZERO_OR_MANY) {
axl_error_new (-1, "expected to find an item node definition with zero to many repeat def (*), not found", NULL, error);
return axl_false;
}
/* check node spec */
itemNode = axl_dtd_item_list_get_node (itemList, 5);
if (axl_dtd_item_node_get_type (itemNode) != AXL_ELEMENT_NODE) {
axl_error_new (-1, "expected to find an item node definition, not found", NULL, error);
return axl_false;
}
if (! axl_cmp (axl_dtd_item_node_get_value (itemNode), "fourth")) {
axl_error_new (-1, "expected to find an item node name (fourth) definition, not found", NULL, error);
return axl_false;
}
if (axl_dtd_item_node_get_repeat (itemNode) != ZERO_OR_MANY) {
axl_error_new (-1, "expected to find an item node definition with zero to many repeat def (*), not found", NULL, error);
return axl_false;
}
/* check repetition pattern for node spec 6 */
itemNode = axl_dtd_item_list_get_node (itemList, 6);
if (axl_dtd_item_node_get_type (itemNode) != AXL_ELEMENT_LIST) {
axl_error_new (-1, "expected to find an item node definition, not found", NULL, error);
return axl_false;
}
if (axl_dtd_item_node_get_repeat (itemNode) != ZERO_OR_ONE) {
axl_log ("test-01", AXL_LEVEL_DEBUG, "repeat configuration was different: %d != %d",
axl_dtd_item_node_get_repeat (itemNode), ZERO_OR_ONE);
axl_error_new (-1, "expected to find an item node definition with zero or one repeat def (?), not found", NULL, error);
return axl_false;
}
/* check repetition pattern for node spec 7 */
itemNode = axl_dtd_item_list_get_node (itemList, 7);
if (axl_dtd_item_node_get_type (itemNode) != AXL_ELEMENT_LIST) {
axl_error_new (-1, "expected to find an item node definition, not found", NULL, error);
return axl_false;
}
if (axl_dtd_item_node_get_repeat (itemNode) != ZERO_OR_MANY) {
axl_log ("test-01", AXL_LEVEL_DEBUG, "repeat configuration was different: %d != %d",
axl_dtd_item_node_get_repeat (itemNode), ZERO_OR_MANY);
axl_error_new (-1, "expected to find an item node definition with zero or one repeat def (*), not found", NULL, error);
return axl_false;
}
/* perform DTD validation */
if (! axl_dtd_validate (doc, dtd, error)) {
return axl_false;
}
/* free doc reference */
axl_doc_free (doc);
/* free dtd reference */
axl_dtd_free (dtd);
/* test end */
return axl_true;
}
/**
* @brief Perform a loading for a large file.
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_08 (axlError ** error)
{
/* top level definitions */
axlDoc * doc = NULL;
/* get current doc reference */
doc = axl_doc_parse_from_file ("large.xml", error);
if (doc == NULL)
return axl_false;
/* release the document */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief A bit more complex DTD parsing checkings
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_07 (axlError ** error)
{
/* top level definitions */
axlDoc * doc = NULL;
axlDtd * dtd = NULL;
/* get current doc reference */
doc = axl_doc_parse_from_file ("test3.xml", error);
if (doc == NULL)
return axl_false;
/* load DTD */
dtd = axl_dtd_parse_from_file ("test3.dtd", error);
if (dtd == NULL)
return axl_false;
/* validate the xml document */
if (! axl_dtd_validate (doc, dtd, error)) {
return axl_false;
}
/* free document */
axl_doc_free (doc);
/* free dtd document */
axl_dtd_free (dtd);
return axl_true;
}
/**
* @brief A bit more complex DTD parsing checkings
*
* @param error The optional axlError to be used to report errors.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_06 (axlError ** error)
{
/* top level definitions */
axlDoc * doc = NULL;
axlDtd * dtd = NULL;
/* dtd iteration variables */
axlDtdElement * element;
axlDtdElementList * itemList;
axlDtdElementListNode * itemNode;
/* get current doc reference */
doc = axl_doc_parse_from_file ("test3.xml", error);
if (doc == NULL)
return axl_false;
/* load DTD */
dtd = axl_dtd_parse_from_file ("test3.dtd", error);
if (dtd == NULL)
return axl_false;
/* get the DTD element reference and check it */
element = axl_dtd_get_root (dtd);
if (element == NULL) {
axl_error_new (-1, "Expected to receive a root DTD node, not found", NULL, error);
return axl_false;
}
/* check expected DTD root content */
if (! axl_cmp (axl_dtd_get_element_name (element), "complex")) {
axl_error_new (-1, "Expected to receive a root DTD node name, not found", NULL, error);
return axl_false;
}
if (axl_dtd_get_element_type (element) != ELEMENT_TYPE_CHILDREN) {
axl_error_new (-1, "Expected to receive a root DTD node selection type (Children), not found", NULL, error);
return axl_false;
}
/* get content specification */
itemList = axl_dtd_get_item_list (element);
if (axl_dtd_item_list_count (itemList) != 1) {
axl_log ("test-01", AXL_LEVEL_DEBUG, "item count %d != %d item spected",
axl_dtd_item_list_count (itemList), 1);
axl_error_new (-1, "Expected to receive an item list specification with only one node, not found", NULL, error);
return axl_false;
}
/* get times configuration */
if (axl_dtd_item_list_repeat (itemList) != ONE_AND_ONLY_ONE) {
axl_error_new (-1, "Expected to receive a repetition configuration (one and only one) but not found", NULL, error);
return axl_false;
}
/* get the child node reference */
itemNode = axl_dtd_item_list_get_node (itemList, 0);
if (! axl_cmp (axl_dtd_item_node_get_value (itemNode), "data")) {
axl_log ("test-01", AXL_LEVEL_CRITICAL, "found item name: '%s' != data",
axl_dtd_item_node_get_value (itemNode));
axl_error_new (-1, "Expected to receive an item node but, not found", NULL, error);
return axl_false;
}
/* get the DTD element which represents the provided data */
element = axl_dtd_get_element (dtd, "data");
if ((element == NULL) || (!axl_cmp (axl_dtd_get_element_name (element), "data"))) {
axl_error_new (-1, "Expected to receive a DTD element definition but NULL was found or a different DTD name, not found", NULL, error);
return axl_false;
}
/* get content specification */
itemList = axl_dtd_get_item_list (element);
if (axl_dtd_item_list_count (itemList) != 3) {
axl_log ("test-01", AXL_LEVEL_DEBUG, "item count %d != %d item spected",
axl_dtd_item_list_count (itemList), 3);
axl_error_new (-1, "Expected to receive an item list specification with only one node, not found", NULL, error);
return axl_false;
}
/* get item list especification */
if (axl_dtd_item_list_type (itemList) != SEQUENCE) {
axl_log ("test-01", AXL_LEVEL_DEBUG, "item count %d != %d item spected",
axl_dtd_item_list_count (itemList), 3);
axl_error_new (-1, "Expected to receive an item list specification as a sequence type, not found", NULL, error);
return axl_false;
}
/* check item nodes found inside the item list */
itemNode = axl_dtd_item_list_get_node (itemList, 0);
if (! axl_cmp (axl_dtd_item_node_get_value (itemNode), "row")) {
axl_error_new (-1, "Expected to receive an item node (row) but, not found", NULL, error);
return axl_false;
}
/* get the child node reference */
itemNode = axl_dtd_item_list_get_node (itemList, 1);
if (! axl_cmp (axl_dtd_item_node_get_value (itemNode), "column")) {
axl_error_new (-1, "Expected to receive an item node (column) but, not found", NULL, error);
return axl_false;
}
/* get current configuration for repetition value for the
* provided content particule */
if (axl_dtd_item_node_get_repeat (itemNode) != ONE_AND_ONLY_ONE) {
axl_error_new (-1, "Expected to receive an item node repeat configuration but, not found", NULL, error);
return axl_false;
}
/* get the child node reference */
itemNode = axl_dtd_item_list_get_node (itemList, 2);
if (! axl_cmp (axl_dtd_item_node_get_value (itemNode), "value")) {
axl_error_new (-1, "Expected to receive an item node (value) but, not found", NULL, error);
return axl_false;
}
/* now work with the choice element */
element = axl_dtd_get_element (dtd, "column");
if ((element == NULL) || (!axl_cmp (axl_dtd_get_element_name (element), "column"))) {
axl_error_new (-1, "Expected to receive a DTD element definition but NULL was found or a different DTD name (column), not found", NULL, error);
return axl_false;
}
/* get content specification */
itemList = axl_dtd_get_item_list (element);
if (axl_dtd_item_list_count (itemList) != 4) {
axl_log ("test-01", AXL_LEVEL_DEBUG, "item count %d != %d item spected",
axl_dtd_item_list_count (itemList), 4);
axl_error_new (-1, "Expected to receive an item list specification with only one node, not found", NULL, error);
return axl_false;
}
/* get item list especification */
if (axl_dtd_item_list_type (itemList) != CHOICE) {
axl_error_new (-1, "Expected to receive an item list specification as a CHOICE type, not found", NULL, error);
return axl_false;
}
/* get the DTD element which represents the provided data */
element = axl_dtd_get_element (dtd, "data");
if ((element == NULL) || (!axl_cmp (axl_dtd_get_element_name (element), "data"))) {
axl_error_new (-1, "Expected to receive a DTD element definition but NULL was found or a different DTD name, not found", NULL, error);
return axl_false;
}
/* free document */
axl_doc_free (doc);
/* free dtd document */
axl_dtd_free (dtd);
return axl_true;
}
/**
* @brief DTD operations. Checks that DTD support works, reading
* simple DTD definitions, and ensuring elements are properly read.
*
* @param error The axlError reference to be filled if the function
* returns axl_false.
*
* @return axl_true if the validity test is passed, axl_false if not.
*/
axl_bool test_05 (axlError ** error)
{
axlDoc * doc;
axlNode * node;
axlDtd * dtd;
/* parse the document found */
doc = axl_doc_parse_from_file ("test.xml", error);
if (doc == NULL)
return axl_false;
node = axl_doc_get (doc, "/complex/data/row/td");
if (node == NULL) {
axl_error_new (-1, "Expected to receive a node, not found", NULL, error);
axl_doc_free (doc);
return axl_false;
}
if (! axl_cmp (axl_node_get_content (node, NULL), "10")) {
axl_error_new (-1, "Expected to receive a node content, not found", NULL, error);
axl_doc_free (doc);
return axl_false;
}
/* free previous document */
axl_doc_free (doc);
/* parse the document found */
doc = axl_doc_parse_from_file ("test2.xml", error);
if (doc == NULL)
return axl_false;
dtd = axl_dtd_parse_from_file ("test.dtd", error);
if (dtd == NULL)
return axl_false;
/* now validate the document */
if (! axl_dtd_validate (doc, dtd, error)) {
return axl_false;
}
/* release memory used by the parser */
axl_doc_free (doc);
/* release memory used by the DTD element */
axl_dtd_free (dtd);
return axl_true;
}
/**
* @brief Perform some additional checks for a more extended xml
* documents, that includes attributes inside node definitions.
*
* @param error The axlError where failures will be reported
*
* @return The \ref axl_true if test is passed, axl_false if not.
*/
axl_bool test_04 (axlError ** error)
{
axlDoc * doc;
axlNode * node;
/* parse the document */
doc = axl_doc_parse_strings (error,
"",
" ",
" ",
" ",
" ",
" ",
"
10
",
" ",
" \n \n \r \n \n",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" \n \r \n \t",
" <<<<<<>>>>>><<<>>>><<<<<<>>>]]>"
" \r \n \r \t",
" ",
" ",
" ",
" ",
NULL);
/* check the result returned */
if (doc == NULL)
return axl_false;
/* get the node
value */
node = axl_doc_get (doc, "/complex/data/row/td");
if (! axl_cmp (axl_node_get_content (node, NULL), "10")) {
axl_log ("test-04", AXL_LEVEL_DEBUG, "found a different content than the expected ('10' != '%s')",
axl_node_get_content (node, NULL));
axl_error_new (-1, "Expected to receive a 10 value, but not found", NULL, error);
return axl_false;
}
/* get a reference to the test2 node */
node = axl_doc_get (doc, "/complex/data/row/more/test3");
if (node == NULL) {
axl_error_new (-1, "Expected to find a test3 node at the given location", NULL, error);
return axl_false;
}
/* check the attribute */
if (! axl_node_has_attribute (node, "attr")) {
axl_error_new (-1, "Expected to find an attribute called 'attr' inside test3 node at the given location", NULL, error);
return axl_false;
}
/* check the attribute value */
if (! axl_cmp (axl_node_get_attribute_value (node, "attr"), "2.0")) {
axl_error_new (-1, "Expected to find an attribute value equal '2.0' inside test2 node at the given location", NULL, error);
return axl_false;
}
/* add here Pi instruction checking */
if (! axl_doc_has_pi_target (doc, "test")) {
axl_error_new (-1, "failed to get expected PI target 'test'", NULL, error);
return axl_false;
}
if (! axl_cmp (axl_doc_get_pi_target_content (doc, "test"), "\"my content\"")) {
axl_error_new (-1, "expected to receive a PI content not found", NULL, error);
return axl_false;
}
node = axl_doc_get (doc, "/complex/data/row");
if (node == NULL) {
axl_error_new (-1, "unable to get expected node to check node PI support", NULL, error);
return axl_false;
}
if (! axl_node_has_pi_target (node, "test")) {
axl_error_new (-1, "failed to get expected PI target 'test' for the node", NULL, error);
return axl_false;
}
node = axl_doc_get (doc, "/complex/data/non-xml-document");
if (node == NULL) {
axl_error_new (-1, "Expected to receive the CDATA node, not found", NULL, error);
return axl_false;
}
if (! axl_cmp (axl_node_get_content (node, NULL), "<<<<<<>>>>>><<<>>>><<<<<<>>>")) {
printf ("Content doesn't match: %s != %s\n",
axl_node_get_content (node, NULL), "<<<<<<>>>>>><<<>>>><<<<<<>>>");
axl_error_new (-1, "Expected to recevie CDATA content, not found or not match", NULL, error);
return axl_false;
}
/* free the memory */
axl_doc_free (doc);
return axl_true;
}
/**
* @brief Checks a more extended and complex xml documents
*
* @param error The axlError where failures will be reported.
*
* @return \ref axl_true if test is passed, axl_false if not.
*/
axl_bool test_03 (axlError ** error)
{
axlDoc * doc;
axlNode * node;
/* parse the xml document provided */
doc = axl_doc_parse ("\n\
\n\
\n\
10203040\n\
\n\
\n\