--- gpl/axl/test/test_01.c 2011/06/08 07:09:12 1.1.1.1 +++ gpl/axl/test/test_01.c 2012/02/17 12:50:02 1.1.1.2 @@ -2105,10 +2105,13 @@ axl_bool test_22 (axlError ** error) 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_new (-1, "Expected to find 10 attributes", NULL, error); + axl_error_report (error, -1, "Expected to find 10 attributes, but found: %d", axl_node_num_attributes (node)); return axl_false; } @@ -5257,7 +5260,6 @@ axl_bool test_01e (axlError ** error) { axlDoc * doc; axlNode * node; - const char * content; int size; /* parse document */ @@ -5267,7 +5269,8 @@ axl_bool test_01e (axlError ** error) /* get root node */ node = axl_doc_get_root (doc); - content = axl_node_get_content (node, &size); + if (! axl_node_get_content (node, &size)) + return axl_false; /* free document */ axl_doc_free (doc); @@ -5348,10 +5351,10 @@ axl_bool test_01f (axlError ** error) * * @return axl_true if it works properly or axl_false if not. */ -axl_bool test_01_01 () +axl_bool test_01_01 (void) { axlList * list; - int value; + int value; axlPointer ptr1; axlPointer ptr2; @@ -5690,6 +5693,11 @@ axl_bool test_01_01 () /* get the integer value */ value = PTR_TO_INT (axl_list_get_first (list)); + + if (! (value > 0)) { + printf ("Expected to not find any item under 0..\n"); + return axl_false; + } /* remove */ axl_list_unlink_first (list); @@ -5912,7 +5920,7 @@ axl_bool test_01_02_foreach (axlPointer stack_data, * @return axl_true if the stack works properly, otherwise axl_false * is returned. */ -axl_bool test_01_02 () +axl_bool test_01_02 (void) { axlStack * stack; char * value; @@ -5999,6 +6007,29 @@ axl_bool test_01_03_vargs (const char * format, ...) return axl_true; } +axl_bool test_01_03_replace_check (const char * _source, const char * string, const char * replacement, int check_size, const char * result_string) +{ + char * source; + int res; + + printf ("Test 01-03: Checking %s (%s -> %s)\n", _source, string, replacement); + + source = axl_strdup (_source); + res = axl_stream_replace (&source, -1, string, -1, replacement, -1); + if (res != check_size) { + printf ("ERROR: expected to find %d bytes but found %d at the replacement\n", check_size, res); + return axl_false; + } + /* check replacement */ + if (! axl_cmp (source, result_string)) { + printf ("ERROR: expected to find '%s' but found '%s'\n", result_string, source); + return axl_false; + } + axl_free (source); + + return axl_true; +} + /** * * @brief Checks some internal functions that the library provides to @@ -6007,7 +6038,7 @@ axl_bool test_01_03_vargs (const char * format, ...) * @return The function must return axl_true if everything is * ok. Otherwise axl_false is returned. */ -axl_bool test_01_03 () +axl_bool test_01_03 (void) { char * string; char ** result; @@ -6334,7 +6365,7 @@ axl_bool test_01_03 () return axl_false; } - res = axl_stream_printf_len ("%lu", (unsigned long int) 182); + res = axl_stream_printf_len ("%lu", (unsigned long) 182); if ( res != 4) { printf ("failed, expected to find an string value of 4, but it was found (%d)\n", res); return axl_false; @@ -6725,13 +6756,36 @@ axl_bool test_01_03 () axl_free (string); + /* check replacement */ + if (! test_01_03_replace_check ("1) This is a test", "test", "prueba", 19, "1) This is a prueba")) + return axl_false; + + /* source, string, replace, check_size, result */ + if (! test_01_03_replace_check ("test", "test", "prueba", 6, "prueba")) + return axl_false; + + if (! test_01_03_replace_check ("3) We are going to replace o o this is a test", "o", "####", 57, "3) We are g####ing t#### replace #### #### this is a test")) + return axl_false; + + if (! test_01_03_replace_check ("4) We are g####ing t#### replace #### #### this is a test", "####", "o", 45, "4) We are going to replace o o this is a test")) + return axl_false; + + if (! test_01_03_replace_check ("oooo", "o", "i", 4, "iiii")) + return axl_false; + + if (! test_01_03_replace_check ("oooo", "o", "ii", 8, "iiiiiiii")) + return axl_false; + + if (! test_01_03_replace_check (" tes", "test", "asdfsdf", 4, " tes")) + return axl_false; + return axl_true; } /** * @brief Intensive axl list implementation. */ -axl_bool test_01_04 () { +axl_bool test_01_04 (void) { int iterator = 0; int value; axlList * list; @@ -6823,7 +6877,7 @@ axl_bool test_01_04 () { /** * @brief Check axl list remove at API. */ -axl_bool test_01_04_a () { +axl_bool test_01_04_a (void) { axlList * list; char * value; char * value2; @@ -6957,7 +7011,7 @@ axl_bool test_01_04_a () { * * @return \ref axl_true if ok, \ref axl_false on rainy days. */ -axl_bool test_01_05 () +axl_bool test_01_05 (void) { axlError * error = NULL; @@ -6999,7 +7053,7 @@ void test_02_02_check_key (axlHash * hash, char * key) * * @return axl_true if it works properly or axl_false if not. */ -axl_bool test_02_02 () +axl_bool test_02_02 (void) { axlHash * hash; int iterator; @@ -7997,7 +8051,7 @@ axlPointer test_02_01_copy_value (axlPointer key, axlD * * @return \ref axl_true if it was ok. */ -axl_bool test_02_01 () +axl_bool test_02_01 (void) { axlHash * hash; axlHash * hash2; @@ -8055,7 +8109,7 @@ axl_bool test_02_01 () * * @return axl_true if it works properly or axl_false if not. */ -axl_bool test_02_03 () +axl_bool test_02_03 (void) { axlHash * hash; @@ -8087,7 +8141,7 @@ axl_bool test_02_03 () return axl_true; } -axl_bool test_02_03a () +axl_bool test_02_03a (void) { axlHash * hash; @@ -8157,7 +8211,7 @@ void show_item_test_02_04 (axlPointer key, axlPointer __axl_log ("hash-test", AXL_LEVEL_DEBUG, " %s -> %s", (char *) key, (char *) data); } -axl_bool test_02_04 () +axl_bool test_02_04 (void) { axlHash * hash; @@ -8211,7 +8265,7 @@ axl_bool test_02_04 () } -axl_bool test_02_04_1 () +axl_bool test_02_04_1 (void) { axlHash * hash; int iterator; @@ -8427,7 +8481,7 @@ axl_bool test_02_04_1 () return axl_true; } -axl_bool test_02_05 () +axl_bool test_02_05 (void) { axlHash * hash; axlHashCursor * cursor; @@ -8638,7 +8692,7 @@ axl_bool test_02_05 () * * @return axl_true if tests are ok. */ -axl_bool test_02_06 () +axl_bool test_02_06 (void) { axl_bool value; axlBinaryStack * bstack; @@ -8772,7 +8826,7 @@ int main (int argc, char ** argv) printf ("** Report bugs to:\n**\n"); printf ("** Axl mailing list\n**\n"); - + /* initialize axl library */ if (! axl_init ()) { printf ("Unable to initialize Axl library\n");