diff options
author | Dodji Seketeli <dodji@gnome.org> | 2004-03-07 13:22:49 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2004-03-07 13:22:49 +0000 |
commit | 94f1a410a3d257124c3131b41ccaa883ccabb9c3 (patch) | |
tree | a5ba5d6805fb556194553df761754b640e600d2b /tests | |
parent | 9e1a6d35382841cbbaaca9779fe21c3123cc367f (diff) | |
download | libcroco-94f1a410a3d257124c3131b41ccaa883ccabb9c3.tar.gz |
re-indented the source files to make'em comply with gnome indentation
2004-03-07 Dodji Seketeli <dodji@gnome.org>
* src/*.c: re-indented the source files to make'em comply
with gnome indentation rules.
* libcroco-indent: added this indentation script.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cr-test-utils.c | 42 | ||||
-rw-r--r-- | tests/test0-main.c | 184 | ||||
-rw-r--r-- | tests/test1-main.c | 178 | ||||
-rw-r--r-- | tests/test2-main.c | 737 | ||||
-rw-r--r-- | tests/test3-main.c | 741 | ||||
-rw-r--r-- | tests/test4-main.c | 559 | ||||
-rw-r--r-- | tests/test5-main.c | 291 | ||||
-rw-r--r-- | tests/test6-main.c | 49 | ||||
-rw-r--r-- | tests/test7-main.c | 277 |
9 files changed, 1385 insertions, 1673 deletions
diff --git a/tests/cr-test-utils.c b/tests/cr-test-utils.c index e03955e..9435ef7 100644 --- a/tests/cr-test-utils.c +++ b/tests/cr-test-utils.c @@ -29,35 +29,31 @@ */ void cr_test_utils_parse_cmd_line (int a_argc, char **a_argv, - struct Options *a_options) + struct Options *a_options) { - int i= 0 ; - - g_return_if_fail (a_options) ; + int i = 0; - memset (a_options, 0, sizeof (struct Options)) ; + g_return_if_fail (a_options); - for (i = 1 ; i < a_argc ; i++) - { - if (a_argv[i][0] != '-') break ; + memset (a_options, 0, sizeof (struct Options)); - if (!strcmp (a_argv[i], "-h") || !strcmp (a_argv[i], "--help")) - { - a_options->display_help = TRUE ; + for (i = 1; i < a_argc; i++) { + if (a_argv[i][0] != '-') + break; + + if (!strcmp (a_argv[i], "-h") + || !strcmp (a_argv[i], "--help")) { + a_options->display_help = TRUE; } - if (!strcmp (a_argv[i], "--about")) - { - a_options->display_about = TRUE ; + if (!strcmp (a_argv[i], "--about")) { + a_options->display_about = TRUE; } - } + } - if (i >= a_argc) - { - /*No file parameter where given*/ - a_options->files_list = NULL ; + if (i >= a_argc) { + /*No file parameter where given */ + a_options->files_list = NULL; + } else { + a_options->files_list = &a_argv[i]; } - else - { - a_options->files_list = &a_argv[i] ; - } } diff --git a/tests/test0-main.c b/tests/test0-main.c index ac1a55e..a991abf 100644 --- a/tests/test0-main.c +++ b/tests/test0-main.c @@ -39,25 +39,23 @@ *during the parsing the command line by the *parse_command_line() function. */ -struct Options -{ - gboolean display_help ; - gboolean display_about ; - gchar ** files_list ; +struct Options { + gboolean display_help; + gboolean display_about; + gchar **files_list; }; -static void -display_help (char *prg_name) ; +static void + display_help (char *prg_name); -static void -display_about (char *prg_name) ; +static void + display_about (char *prg_name); static void -parse_command_line (int a_argc, char **a_argv, - struct Options *a_options) ; + parse_command_line (int a_argc, char **a_argv, struct Options *a_options); static enum CRStatus -test_cr_input_read_byte (guchar * a_file_uri) ; + test_cr_input_read_byte (guchar * a_file_uri); /** *Displays the usage of the test @@ -65,15 +63,15 @@ test_cr_input_read_byte (guchar * a_file_uri) ; *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - g_print ("\n\n") ; - g_print ("usage: %s <file-to-parse>\n", prg_name) ; - g_print ("\t <file-to-parse>: the file to parse\n") ; - g_print ("\n\n") ; - g_print ("This test just reads the file byte per byte\nand sends each byte to stdout\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("usage: %s <file-to-parse>\n", prg_name); + g_print ("\t <file-to-parse>: the file to parse\n"); + g_print ("\n\n"); + g_print ("This test just reads the file byte per byte\nand sends each byte to stdout\n"); + g_print ("\n\n"); } /** @@ -81,15 +79,15 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - g_print ("\n\n") ; - g_print ("%s is a libcroco CRInput class test program.\n", prg_name) ; - g_print ("It should run on GNU compliants systems.\n") ; - g_print ("\n\n") ; - g_print ("Initial author: Dodji Seketeli <dodji@seketeli.org>.\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("%s is a libcroco CRInput class test program.\n", prg_name); + g_print ("It should run on GNU compliants systems.\n"); + g_print ("\n\n"); + g_print ("Initial author: Dodji Seketeli <dodji@seketeli.org>.\n"); + g_print ("\n\n"); } /** @@ -99,41 +97,35 @@ display_about (char *prg_name) *@param a_options out parameter. The abstraction of the parsed the options. */ static void -parse_command_line (int a_argc, char **a_argv, - struct Options *a_options) +parse_command_line (int a_argc, char **a_argv, struct Options *a_options) { - int i= 0 ; - - g_return_if_fail (a_options) ; + int i = 0; + + g_return_if_fail (a_options); - memset (a_options, 0, sizeof (struct Options)) ; + memset (a_options, 0, sizeof (struct Options)); - for (i = 1 ; i < a_argc ; i++) - { - if (a_argv[i][0] != '-') break ; + for (i = 1; i < a_argc; i++) { + if (a_argv[i][0] != '-') + break; - if (!strcmp (a_argv[i], "-h") || !strcmp (a_argv[i], "--help")) - { - a_options->display_help = TRUE ; + if (!strcmp (a_argv[i], "-h") + || !strcmp (a_argv[i], "--help")) { + a_options->display_help = TRUE; } - if (!strcmp (a_argv[i], "--about")) - { - a_options->display_about = TRUE ; + if (!strcmp (a_argv[i], "--about")) { + a_options->display_about = TRUE; } - } + } - if (i >= a_argc) - { - /*No file parameter where given*/ - a_options->files_list = NULL ; + if (i >= a_argc) { + /*No file parameter where given */ + a_options->files_list = NULL; + } else { + a_options->files_list = &a_argv[i]; } - else - { - a_options->files_list = &a_argv[i] ; - } } - /** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the @@ -146,78 +138,66 @@ parse_command_line (int a_argc, char **a_argv, static enum CRStatus test_cr_input_read_byte (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CRInput * input = NULL ; - guchar byte = 0 ; - guint c = 0 ; - - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; - - input = - cr_input_new_from_uri (a_file_uri, CR_UTF_8) ; - - if (!input) - { - cr_utils_trace_debug ("Input Stream creation failed.") ; - return CR_ERROR ; - } + enum CRStatus status = CR_OK; + CRInput *input = NULL; + guchar byte = 0; + guint c = 0; + + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); - for (status = CR_OK; - status == CR_OK ;) - { - status = cr_input_read_byte (input, &byte) ; - - if (status == CR_OK) - { - c = byte ; - printf ("%d", c) ; - fflush (stdout) ; - } + input = cr_input_new_from_uri (a_file_uri, CR_UTF_8); + + if (!input) { + cr_utils_trace_debug ("Input Stream creation failed."); + return CR_ERROR; } - + for (status = CR_OK; status == CR_OK;) { + status = cr_input_read_byte (input, &byte); - if (status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; + if (status == CR_OK) { + c = byte; + printf ("%d", c); + fflush (stdout); + } } - cr_input_destroy (input) ; - input = NULL ; + if (status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; + } - return status ; -} + cr_input_destroy (input); + input = NULL; + return status; +} /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; + struct Options options; - parse_command_line (argc, argv, &options) ; + parse_command_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - test_cr_input_read_byte (options.files_list[0]) ; + test_cr_input_read_byte (options.files_list[0]); - return 0 ; + return 0; } diff --git a/tests/test1-main.c b/tests/test1-main.c index 893b5d5..019e6dc 100644 --- a/tests/test1-main.c +++ b/tests/test1-main.c @@ -39,27 +39,23 @@ *during the parsing the command line by the *parse_command_line() function. */ -struct Options -{ - gboolean display_help ; - gboolean display_about ; - gchar ** files_list ; +struct Options { + gboolean display_help; + gboolean display_about; + gchar **files_list; }; +static void + display_help (char *prg_name); -static void -display_help (char *prg_name) ; - -static void -display_about (char *prg_name) ; +static void + display_about (char *prg_name); static void -parse_command_line (int a_argc, char **a_argv, - struct Options *a_options) ; + parse_command_line (int a_argc, char **a_argv, struct Options *a_options); static enum CRStatus -test_cr_input_read_char (guchar * a_file_uri) ; - + test_cr_input_read_char (guchar * a_file_uri); /** *Displays the usage of the test @@ -67,15 +63,15 @@ test_cr_input_read_char (guchar * a_file_uri) ; *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - g_print ("\n\n") ; - g_print ("usage: %s <file-to-parse>\n", prg_name) ; - g_print ("\t <file-to-parse>: the file to parse\n") ; - g_print ("\n\n") ; - g_print ("This test just reads the file character per character\nand sends each character to stdout\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("usage: %s <file-to-parse>\n", prg_name); + g_print ("\t <file-to-parse>: the file to parse\n"); + g_print ("\n\n"); + g_print ("This test just reads the file character per character\nand sends each character to stdout\n"); + g_print ("\n\n"); } /** @@ -83,15 +79,15 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - g_print ("\n\n") ; - g_print ("%s is a libcroco CRInput class test program.\n", prg_name) ; - g_print ("It should run on GNU compliants systems.\n") ; - g_print ("\n\n") ; - g_print ("Initial author: Dodji Seketeli <dodji@seketeli.org>.\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("%s is a libcroco CRInput class test program.\n", prg_name); + g_print ("It should run on GNU compliants systems.\n"); + g_print ("\n\n"); + g_print ("Initial author: Dodji Seketeli <dodji@seketeli.org>.\n"); + g_print ("\n\n"); } /** @@ -101,41 +97,35 @@ display_about (char *prg_name) *@param a_options out parameter. The abstraction of the parsed the options. */ static void -parse_command_line (int a_argc, char **a_argv, - struct Options *a_options) +parse_command_line (int a_argc, char **a_argv, struct Options *a_options) { - int i= 0 ; - - g_return_if_fail (a_options) ; + int i = 0; + + g_return_if_fail (a_options); - memset (a_options, 0, sizeof (struct Options)) ; + memset (a_options, 0, sizeof (struct Options)); - for (i = 1 ; i < a_argc ; i++) - { - if (a_argv[i][0] != '-') break ; + for (i = 1; i < a_argc; i++) { + if (a_argv[i][0] != '-') + break; - if (!strcmp (a_argv[i], "-h") || !strcmp (a_argv[i], "--help")) - { - a_options->display_help = TRUE ; + if (!strcmp (a_argv[i], "-h") + || !strcmp (a_argv[i], "--help")) { + a_options->display_help = TRUE; } - if (!strcmp (a_argv[i], "--about")) - { - a_options->display_about = TRUE ; + if (!strcmp (a_argv[i], "--about")) { + a_options->display_about = TRUE; } - } + } - if (i >= a_argc) - { - /*No file parameter where given*/ - a_options->files_list = NULL ; + if (i >= a_argc) { + /*No file parameter where given */ + a_options->files_list = NULL; + } else { + a_options->files_list = &a_argv[i]; } - else - { - a_options->files_list = &a_argv[i] ; - } } - /** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the @@ -148,74 +138,64 @@ parse_command_line (int a_argc, char **a_argv, enum CRStatus test_cr_input_read_char (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CRInput * input = NULL ; - guint32 c = 0 ; - - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; - - input = - cr_input_new_from_uri (a_file_uri, CR_UTF_8) ; - - if (!input) - { - cr_utils_trace_debug ("Input Stream creation failed.") ; - return CR_ERROR ; + enum CRStatus status = CR_OK; + CRInput *input = NULL; + guint32 c = 0; + + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); + + input = cr_input_new_from_uri (a_file_uri, CR_UTF_8); + + if (!input) { + cr_utils_trace_debug ("Input Stream creation failed."); + return CR_ERROR; } - for (status = CR_OK; - status == CR_OK ;) - { - status = cr_input_read_char (input, &c) ; + for (status = CR_OK; status == CR_OK;) { + status = cr_input_read_char (input, &c); - if (status == CR_OK) - { - printf ("%c", c) ; - fflush (stdout) ; + if (status == CR_OK) { + printf ("%c", c); + fflush (stdout); } - } + } - if (status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; + if (status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; } - cr_input_destroy (input) ; - input = NULL ; + cr_input_destroy (input); + input = NULL; - return status ; + return status; } - /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; + struct Options options; - parse_command_line (argc, argv, &options) ; + parse_command_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - test_cr_input_read_char (options.files_list[0]) ; + test_cr_input_read_char (options.files_list[0]); - return 0 ; + return 0; } diff --git a/tests/test2-main.c b/tests/test2-main.c index b27967e..d64071c 100644 --- a/tests/test2-main.c +++ b/tests/test2-main.c @@ -31,22 +31,21 @@ #include "cr-test-utils.h" #include "cr-parser.h" - /** *@file *Some test facilities for the #CRParser class. */ -CRDocHandler * gv_test_handler = {0} ; +CRDocHandler *gv_test_handler = { 0 }; -static void -display_help (char *prg_name) ; +static void + display_help (char *prg_name); -static void -display_about (char *prg_name) ; +static void + display_about (char *prg_name); static enum CRStatus -test_cr_parser_parse (guchar * a_file_uri) ; + test_cr_parser_parse (guchar * a_file_uri); /** *Displays the usage of the test @@ -54,16 +53,16 @@ test_cr_parser_parse (guchar * a_file_uri) ; *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - fprintf (stdout,"\n\n") ; - fprintf (stdout,"usage: %s <file-to-parse>\n", prg_name) ; - fprintf (stdout,"\t <file-to-parse>: the file to parse\n") ; - fprintf (stdout,"\n\n") ; - fprintf (stdout,"Tests the cr_parser_parse () method.\n") ; - fprintf (stdout,"Returns OK if the status is CR_OK, KO otherwise\n") ; - fprintf (stdout,"\n\n") ; + fprintf (stdout, "\n\n"); + fprintf (stdout, "usage: %s <file-to-parse>\n", prg_name); + fprintf (stdout, "\t <file-to-parse>: the file to parse\n"); + fprintf (stdout, "\n\n"); + fprintf (stdout, "Tests the cr_parser_parse () method.\n"); + fprintf (stdout, "Returns OK if the status is CR_OK, KO otherwise\n"); + fprintf (stdout, "\n\n"); } /** @@ -71,492 +70,437 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - fprintf (stdout,"\n\n") ; - fprintf (stdout,"%s is a libcroco CRParser class test program.\n", prg_name) ; - fprintf (stdout,"It should run on GNU compliants systems.\n") ; - fprintf (stdout,"\n\n") ; - fprintf (stdout,"Initial author: Dodji Seketeli <dodji@seketeli.org>.\n") ; - fprintf (stdout,"\n\n") ; + fprintf (stdout, "\n\n"); + fprintf (stdout, "%s is a libcroco CRParser class test program.\n", + prg_name); + fprintf (stdout, "It should run on GNU compliants systems.\n"); + fprintf (stdout, "\n\n"); + fprintf (stdout, + "Initial author: Dodji Seketeli <dodji@seketeli.org>.\n"); + fprintf (stdout, "\n\n"); } - /*************************** *Some SAC document handlers *for TEST PURPOSES. ***************************/ static void -test_start_document (CRDocHandler *a_handler) +test_start_document (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_document\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_document\n"); + fprintf (stdout, "***************\n\n"); } static void -test_end_document (CRDocHandler *a_handler) +test_end_document (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_document\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_document\n"); + fprintf (stdout, "***************\n\n"); } static void -test_import_style (CRDocHandler *a_handler, - GList *a_media_list, GString *a_uri, - GString *a_uri_default_ns) +test_import_style (CRDocHandler * a_handler, + GList * a_media_list, GString * a_uri, + GString * a_uri_default_ns) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"****************\n") ; - fprintf (stdout,"import_style\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - - fprintf (stdout,"\nmedia list:\n") ; - fprintf (stdout,"-------------\n") ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data) - { - guchar *str = - g_strndup - (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; - - if (str) - { - fprintf (stdout,str) ; - fprintf (stdout,"\n") ; - g_free (str) ; - str = NULL ; - } - } - } - - fprintf (stdout,"\ndefault namespace:\n") ; - fprintf (stdout,"--------------------\n") ; - - if (a_uri_default_ns && a_uri_default_ns->str) - { - guchar * str = - g_strndup (a_uri_default_ns->str, - a_uri_default_ns->len) ; - if (str) - { - fprintf (stdout,str) ; - fprintf (stdout,"\n") ; - g_free (str) ; - str = NULL ; - } - } - } - - fprintf (stdout,"******************\n\n") ; - a_uri = NULL; /*keep compiler happy*/ -} + g_return_if_fail (a_handler); + + fprintf (stdout, "****************\n"); + fprintf (stdout, "import_style\n"); + + if (a_media_list) { + GList *cur = NULL; + + fprintf (stdout, "\nmedia list:\n"); + fprintf (stdout, "-------------\n"); + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data) { + guchar *str = + g_strndup + (((GString *) cur->data)->str, + ((GString *) cur->data)->len); + + if (str) { + fprintf (stdout, str); + fprintf (stdout, "\n"); + g_free (str); + str = NULL; + } + } + } + fprintf (stdout, "\ndefault namespace:\n"); + fprintf (stdout, "--------------------\n"); + + if (a_uri_default_ns && a_uri_default_ns->str) { + guchar *str = g_strndup (a_uri_default_ns->str, + a_uri_default_ns->len); + + if (str) { + fprintf (stdout, str); + fprintf (stdout, "\n"); + g_free (str); + str = NULL; + } + } + } + + fprintf (stdout, "******************\n\n"); + a_uri = NULL; /*keep compiler happy */ +} static void -test_namespace_declaration (CRDocHandler *a_handler, - GString *a_prefix, - GString *a_uri) +test_namespace_declaration (CRDocHandler * a_handler, + GString * a_prefix, GString * a_uri) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"namespace_declaration:\n") ; - - if (a_prefix && a_prefix->str) - { - guchar * prefix = NULL ; - - prefix = g_strndup (a_prefix->str, a_prefix->len) ; - - if (prefix) - { - fprintf (stdout,"prefix: %s\n", prefix) ; - g_free (prefix) ; - prefix = NULL ; - } - } - - if (a_uri && a_uri->str) - { - guchar *uri = NULL ; - - uri = g_strndup (a_uri->str, a_uri->len) ; - - if (uri) - { - fprintf (stdout,"uri: %s\n", uri) ; - g_free (uri) ; - uri = NULL ; - } - } - fprintf (stdout,"\n") ; - - fprintf (stdout,"***************\n\n") ; - - -} + g_return_if_fail (a_handler); + fprintf (stdout, "***************\n"); + fprintf (stdout, "namespace_declaration:\n"); + + if (a_prefix && a_prefix->str) { + guchar *prefix = NULL; + + prefix = g_strndup (a_prefix->str, a_prefix->len); + + if (prefix) { + fprintf (stdout, "prefix: %s\n", prefix); + g_free (prefix); + prefix = NULL; + } + } + + if (a_uri && a_uri->str) { + guchar *uri = NULL; + + uri = g_strndup (a_uri->str, a_uri->len); + + if (uri) { + fprintf (stdout, "uri: %s\n", uri); + g_free (uri); + uri = NULL; + } + } + fprintf (stdout, "\n"); + + fprintf (stdout, "***************\n\n"); + +} static void -test_comment (CRDocHandler *a_handler, - GString *a_comment) +test_comment (CRDocHandler * a_handler, GString * a_comment) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"comment:\n") ; - - if (a_comment && a_comment->str) - { - guchar *comment = NULL ; - - comment = g_strndup (a_comment->str, a_comment->len) ; - - if (comment) - { - fprintf (stdout,"\n/*----------------------\n") ; - fprintf (stdout,"%s\n", comment) ; - fprintf (stdout,"-------------------------*/\n") ; - - g_free (comment) ; - comment = NULL ; - } - } - - fprintf (stdout,"***************\n\n") ; -} + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "comment:\n"); + if (a_comment && a_comment->str) { + guchar *comment = NULL; + comment = g_strndup (a_comment->str, a_comment->len); + + if (comment) { + fprintf (stdout, "\n/*----------------------\n"); + fprintf (stdout, "%s\n", comment); + fprintf (stdout, "-------------------------*/\n"); + + g_free (comment); + comment = NULL; + } + } + + fprintf (stdout, "***************\n\n"); +} static void -test_start_selector (CRDocHandler *a_handler, - CRSelector *a_selector_list) +test_start_selector (CRDocHandler * a_handler, CRSelector * a_selector_list) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_selector\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_selector\n"); - if (a_selector_list) - { - cr_selector_dump (a_selector_list, stdout) ; - fprintf (stdout, "\n") ; + if (a_selector_list) { + cr_selector_dump (a_selector_list, stdout); + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_end_selector (CRDocHandler *a_handler, - CRSelector *a_selector_list) +test_end_selector (CRDocHandler * a_handler, CRSelector * a_selector_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_selector\n") ; - - if (a_selector_list) - { - cr_selector_dump (a_selector_list, stdout) ; - fprintf (stdout,"\n") ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_selector\n"); + + if (a_selector_list) { + cr_selector_dump (a_selector_list, stdout); + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_property (CRDocHandler *a_handler, GString *a_name, - CRTerm *a_expr, gboolean a_important) +test_property (CRDocHandler * a_handler, GString * a_name, + CRTerm * a_expr, gboolean a_important) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"property\n") ; - - if (a_name && a_name->str) - { - guchar *name = g_strndup (a_name->str, a_name->len) ; - - if (name) - { - fprintf (stdout,name) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "property\n"); + + if (a_name && a_name->str) { + guchar *name = g_strndup (a_name->str, a_name->len); + + if (name) { + fprintf (stdout, name); } - - if (a_expr) - { - fprintf (stdout,": ") ; - cr_term_dump (a_expr, stdout) ; + + if (a_expr) { + fprintf (stdout, ": "); + cr_term_dump (a_expr, stdout); } - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - - fprintf (stdout,"\n") ; + + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_start_font_face (CRDocHandler *a_handler) +test_start_font_face (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_font_face\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_font_face\n"); + fprintf (stdout, "***************\n\n"); } - static void -test_end_font_face (CRDocHandler *a_handler) +test_end_font_face (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_font_face\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_font_face\n"); + fprintf (stdout, "***************\n\n"); } static void -test_start_media (CRDocHandler *a_handler, - GList *a_media_list) +test_start_media (CRDocHandler * a_handler, GList * a_media_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_media\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - guchar *medium = NULL ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data == NULL) - continue ; - - medium = g_strndup (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_media\n"); + + if (a_media_list) { + GList *cur = NULL; + guchar *medium = NULL; + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data == NULL) + continue; + + medium = g_strndup (((GString *) cur->data)->str, + ((GString *) cur->data)->len); if (medium == NULL) - continue ; + continue; - fprintf (stdout,"medium: %s\n", medium) ; + fprintf (stdout, "medium: %s\n", medium); - if (medium) - { - g_free (medium) ; - medium = NULL ; + if (medium) { + g_free (medium); + medium = NULL; } } } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_end_media (CRDocHandler *a_handler, - GList *a_media_list) +test_end_media (CRDocHandler * a_handler, GList * a_media_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_media\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - guchar *medium = NULL ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data == NULL) - continue ; - - medium = g_strndup (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_media\n"); + + if (a_media_list) { + GList *cur = NULL; + guchar *medium = NULL; + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data == NULL) + continue; + + medium = g_strndup (((GString *) cur->data)->str, + ((GString *) cur->data)->len); if (medium == NULL) - continue ; + continue; - fprintf (stdout,"medium: %s\n", medium) ; + fprintf (stdout, "medium: %s\n", medium); - if (medium) - { - g_free (medium) ; - medium = NULL ; + if (medium) { + g_free (medium); + medium = NULL; } } } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } static void -test_start_page (CRDocHandler *a_handler, - GString *a_name, GString *a_pseudo_page) +test_start_page (CRDocHandler * a_handler, + GString * a_name, GString * a_pseudo_page) { - guchar *name = NULL, *pseudo_page = NULL ; + guchar *name = NULL, + *pseudo_page = NULL; + + g_return_if_fail (a_handler); - g_return_if_fail (a_handler) ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_page\n"); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_page\n") ; - - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (a_pseudo_page && a_pseudo_page->str) - { - pseudo_page = g_strndup (a_pseudo_page->str, - a_pseudo_page->len) ; + if (a_pseudo_page && a_pseudo_page->str) { + pseudo_page = g_strndup (a_pseudo_page->str, + a_pseudo_page->len); } - if (name) - { - fprintf (stdout,"%s", name) ; + if (name) { + fprintf (stdout, "%s", name); } - if (pseudo_page) - { - fprintf (stdout,": %s\n", pseudo_page) ; + if (pseudo_page) { + fprintf (stdout, ": %s\n", pseudo_page); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - if (pseudo_page) - { - g_free (pseudo_page) ; - pseudo_page = NULL ; + if (pseudo_page) { + g_free (pseudo_page); + pseudo_page = NULL; } } static void -test_end_page (CRDocHandler *a_handler, - GString *a_name, GString *a_pseudo_page) +test_end_page (CRDocHandler * a_handler, + GString * a_name, GString * a_pseudo_page) { - guchar *name = NULL, *pseudo_page = NULL ; + guchar *name = NULL, + *pseudo_page = NULL; - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_page\n") ; - - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_page\n"); + + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (a_pseudo_page && a_pseudo_page->str) - { - pseudo_page = g_strndup (a_pseudo_page->str, - a_pseudo_page->len) ; + if (a_pseudo_page && a_pseudo_page->str) { + pseudo_page = g_strndup (a_pseudo_page->str, + a_pseudo_page->len); } - if (name) - { - fprintf (stdout,"%s", name) ; + if (name) { + fprintf (stdout, "%s", name); } - if (pseudo_page) - { - fprintf (stdout,": %s\n", pseudo_page) ; - + if (pseudo_page) { + fprintf (stdout, ": %s\n", pseudo_page); + } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - if (pseudo_page) - { - g_free (pseudo_page) ; - pseudo_page = NULL ; + if (pseudo_page) { + g_free (pseudo_page); + pseudo_page = NULL; } } - static void -test_ignorable_at_rule (CRDocHandler *a_handler, - GString *a_name) +test_ignorable_at_rule (CRDocHandler * a_handler, GString * a_name) { - guchar *name = NULL ; + guchar *name = NULL; - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"*********************\n") ; - fprintf (stdout,"ignorable_at_rule\n") ; + fprintf (stdout, "*********************\n"); + fprintf (stdout, "ignorable_at_rule\n"); - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (name) - { - fprintf (stdout,"%s\n", name) ; + if (name) { + fprintf (stdout, "%s\n", name); } - fprintf (stdout,"*********************\n\n") ; + fprintf (stdout, "*********************\n\n"); } - static void -init_test_sac_handler (CRDocHandler *a_handler) - +init_test_sac_handler (CRDocHandler * a_handler) { - a_handler->start_document = test_start_document ; - a_handler->end_document = test_end_document ; - a_handler->import_style = test_import_style ; - a_handler->namespace_declaration = test_namespace_declaration ; - a_handler->comment = test_comment ; - a_handler->start_selector = test_start_selector ; - a_handler->end_selector = test_end_selector ; - a_handler->property = test_property ; - a_handler->start_font_face = test_start_font_face ; - a_handler->end_font_face = test_end_font_face ; - a_handler->start_media = test_start_media ; - a_handler->end_media = test_end_media ; - a_handler->start_page = test_start_page ; - a_handler->end_page = test_end_page ; - a_handler->ignorable_at_rule = test_ignorable_at_rule ; + a_handler->start_document = test_start_document; + a_handler->end_document = test_end_document; + a_handler->import_style = test_import_style; + a_handler->namespace_declaration = test_namespace_declaration; + a_handler->comment = test_comment; + a_handler->start_selector = test_start_selector; + a_handler->end_selector = test_end_selector; + a_handler->property = test_property; + a_handler->start_font_face = test_start_font_face; + a_handler->end_font_face = test_end_font_face; + a_handler->start_media = test_start_media; + a_handler->end_media = test_end_media; + a_handler->start_page = test_start_page; + a_handler->end_page = test_end_page; + a_handler->ignorable_at_rule = test_ignorable_at_rule; } /*************************** @@ -564,7 +508,6 @@ init_test_sac_handler (CRDocHandler *a_handler) *handlers. ***************************/ - /** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the @@ -577,69 +520,63 @@ init_test_sac_handler (CRDocHandler *a_handler) static enum CRStatus test_cr_parser_parse (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CRParser *parser = NULL ; + enum CRStatus status = CR_OK; + CRParser *parser = NULL; - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); - gv_test_handler = cr_doc_handler_new () ; - init_test_sac_handler (gv_test_handler) ; + gv_test_handler = cr_doc_handler_new (); + init_test_sac_handler (gv_test_handler); - parser = cr_parser_new (NULL) ; + parser = cr_parser_new (NULL); - status = cr_parser_set_sac_handler (parser, gv_test_handler) ; - - if (status != CR_OK) - { - cr_parser_destroy (parser) ; - g_return_val_if_fail (status == CR_OK, CR_ERROR) ; + status = cr_parser_set_sac_handler (parser, gv_test_handler); + + if (status != CR_OK) { + cr_parser_destroy (parser); + g_return_val_if_fail (status == CR_OK, CR_ERROR); } - status = cr_parser_parse_file (parser, a_file_uri, CR_ASCII) ; + status = cr_parser_parse_file (parser, a_file_uri, CR_ASCII); - cr_parser_destroy (parser) ; + cr_parser_destroy (parser); - gv_test_handler = NULL ; + gv_test_handler = NULL; - return status ; + return status; } - /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; - enum CRStatus status = CR_OK ; + struct Options options; + enum CRStatus status = CR_OK; - cr_test_utils_parse_cmd_line (argc, argv, &options) ; + cr_test_utils_parse_cmd_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - status = test_cr_parser_parse (options.files_list[0]) ; + status = test_cr_parser_parse (options.files_list[0]); - if (status != CR_OK) - { - fprintf (stdout,"KO\n") ; + if (status != CR_OK) { + fprintf (stdout, "KO\n"); } - return 0 ; + return 0; } diff --git a/tests/test3-main.c b/tests/test3-main.c index 3b7f1ac..e312b3b 100644 --- a/tests/test3-main.c +++ b/tests/test3-main.c @@ -29,22 +29,21 @@ #include "cr-test-utils.h" #include "cr-parser.h" - /** *@file *Some test facilities for the #CRParser class. */ -CRDocHandler * gv_test_handler = {0} ; +CRDocHandler *gv_test_handler = { 0 }; -static void -display_help (char *prg_name) ; +static void + display_help (char *prg_name); -static void -display_about (char *prg_name) ; +static void + display_about (char *prg_name); static enum CRStatus -test_cr_parser_parse (guchar * a_file_uri) ; + test_cr_parser_parse (guchar * a_file_uri); /** *Displays the usage of the test @@ -52,17 +51,17 @@ test_cr_parser_parse (guchar * a_file_uri) ; *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - fprintf (stdout,"\n\n") ; - fprintf (stdout,"usage: %s <file-to-parse>\n", prg_name) ; - fprintf (stdout,"\t <file-to-parse>: the file to parse\n") ; - fprintf (stdout,"\n\n") ; - fprintf (stdout,"Tests the cr_parser_parse () method.\n") ; - fprintf (stdout,"Tests the parsing following the css core syntax\n") ; - fprintf (stdout,"Returns OK if the status is CR_OK, KO otherwise\n") ; - fprintf (stdout,"\n\n") ; + fprintf (stdout, "\n\n"); + fprintf (stdout, "usage: %s <file-to-parse>\n", prg_name); + fprintf (stdout, "\t <file-to-parse>: the file to parse\n"); + fprintf (stdout, "\n\n"); + fprintf (stdout, "Tests the cr_parser_parse () method.\n"); + fprintf (stdout, "Tests the parsing following the css core syntax\n"); + fprintf (stdout, "Returns OK if the status is CR_OK, KO otherwise\n"); + fprintf (stdout, "\n\n"); } /** @@ -70,492 +69,437 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - fprintf (stdout,"\n\n") ; - fprintf (stdout,"%s is a libcroco CRParser class test program.\n", - prg_name) ; - fprintf (stdout,"It should run on GNU compliants systems.\n") ; - fprintf (stdout,"\n\n") ; - fprintf (stdout,"Initial author: Dodji Seketeli <dodji@seketeli.org>.\n") ; - fprintf (stdout,"\n\n") ; + fprintf (stdout, "\n\n"); + fprintf (stdout, "%s is a libcroco CRParser class test program.\n", + prg_name); + fprintf (stdout, "It should run on GNU compliants systems.\n"); + fprintf (stdout, "\n\n"); + fprintf (stdout, + "Initial author: Dodji Seketeli <dodji@seketeli.org>.\n"); + fprintf (stdout, "\n\n"); } - /*************************** *Some SAC document handlers *for TEST PURPOSES. ***************************/ static void -test_start_document (CRDocHandler *a_handler) +test_start_document (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_document\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_document\n"); + fprintf (stdout, "***************\n\n"); } static void -test_end_document (CRDocHandler *a_handler) +test_end_document (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_document\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_document\n"); + fprintf (stdout, "***************\n\n"); } static void -test_import_style (CRDocHandler *a_handler, - GList *a_media_list, GString *a_uri, - GString *a_uri_default_ns) +test_import_style (CRDocHandler * a_handler, + GList * a_media_list, GString * a_uri, + GString * a_uri_default_ns) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"****************\n") ; - fprintf (stdout,"import_style\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - - fprintf (stdout,"\nmedia list:\n") ; - fprintf (stdout,"-------------\n") ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data) - { - guchar *str = - g_strndup - (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; - - if (str) - { - fprintf (stdout,str) ; fprintf (stdout,"\n") ; - g_free (str) ; - str = NULL ; - } - } - } - - fprintf (stdout,"\ndefault namespace:\n") ; - fprintf (stdout,"--------------------\n") ; - - if (a_uri_default_ns && a_uri_default_ns->str) - { - guchar * str = - g_strndup (a_uri_default_ns->str, - a_uri_default_ns->len) ; - if (str) - { - fprintf (stdout,str) ; fprintf (stdout,"\n") ; - g_free (str) ; - str = NULL ; - } - } - } - - fprintf (stdout,"******************\n\n") ; - a_uri = NULL ; /*keep compiler happy*/ -} + g_return_if_fail (a_handler); + + fprintf (stdout, "****************\n"); + fprintf (stdout, "import_style\n"); + + if (a_media_list) { + GList *cur = NULL; + + fprintf (stdout, "\nmedia list:\n"); + fprintf (stdout, "-------------\n"); + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data) { + guchar *str = + g_strndup + (((GString *) cur->data)->str, + ((GString *) cur->data)->len); + + if (str) { + fprintf (stdout, str); + fprintf (stdout, "\n"); + g_free (str); + str = NULL; + } + } + } + fprintf (stdout, "\ndefault namespace:\n"); + fprintf (stdout, "--------------------\n"); + + if (a_uri_default_ns && a_uri_default_ns->str) { + guchar *str = g_strndup (a_uri_default_ns->str, + a_uri_default_ns->len); + + if (str) { + fprintf (stdout, str); + fprintf (stdout, "\n"); + g_free (str); + str = NULL; + } + } + } + + fprintf (stdout, "******************\n\n"); + a_uri = NULL; /*keep compiler happy */ +} static void -test_namespace_declaration (CRDocHandler *a_handler, - GString *a_prefix, - GString *a_uri) +test_namespace_declaration (CRDocHandler * a_handler, + GString * a_prefix, GString * a_uri) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"namespace_declaration:\n") ; - - if (a_prefix && a_prefix->str) - { - guchar * prefix = NULL ; - - prefix = g_strndup (a_prefix->str, a_prefix->len) ; - - if (prefix) - { - fprintf (stdout,"prefix: %s\n", prefix) ; - g_free (prefix) ; - prefix = NULL ; - } - } - - if (a_uri && a_uri->str) - { - guchar *uri = NULL ; - - uri = g_strndup (a_uri->str, a_uri->len) ; - - if (uri) - { - fprintf (stdout,"uri: %s\n", uri) ; - g_free (uri) ; - uri = NULL ; - } - } - fprintf (stdout,"\n") ; - - fprintf (stdout,"***************\n\n") ; - - -} + g_return_if_fail (a_handler); + fprintf (stdout, "***************\n"); + fprintf (stdout, "namespace_declaration:\n"); + + if (a_prefix && a_prefix->str) { + guchar *prefix = NULL; + + prefix = g_strndup (a_prefix->str, a_prefix->len); + + if (prefix) { + fprintf (stdout, "prefix: %s\n", prefix); + g_free (prefix); + prefix = NULL; + } + } + + if (a_uri && a_uri->str) { + guchar *uri = NULL; + + uri = g_strndup (a_uri->str, a_uri->len); + + if (uri) { + fprintf (stdout, "uri: %s\n", uri); + g_free (uri); + uri = NULL; + } + } + fprintf (stdout, "\n"); + + fprintf (stdout, "***************\n\n"); + +} static void -test_comment (CRDocHandler *a_handler, - GString *a_comment) +test_comment (CRDocHandler * a_handler, GString * a_comment) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"comment:\n") ; - - if (a_comment && a_comment->str) - { - guchar *comment = NULL ; - - comment = g_strndup (a_comment->str, a_comment->len) ; - - if (comment) - { - fprintf (stdout,"\n/*----------------------\n") ; - fprintf (stdout,"%s\n", comment) ; - fprintf (stdout,"-------------------------*/\n") ; - - g_free (comment) ; - comment = NULL ; - } - } - - fprintf (stdout,"***************\n\n") ; -} + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "comment:\n"); + if (a_comment && a_comment->str) { + guchar *comment = NULL; + comment = g_strndup (a_comment->str, a_comment->len); + if (comment) { + fprintf (stdout, "\n/*----------------------\n"); + fprintf (stdout, "%s\n", comment); + fprintf (stdout, "-------------------------*/\n"); + + g_free (comment); + comment = NULL; + } + } + + fprintf (stdout, "***************\n\n"); +} static void -test_start_selector (CRDocHandler *a_handler, - CRSelector *a_selector_list) +test_start_selector (CRDocHandler * a_handler, CRSelector * a_selector_list) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_selector\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_selector\n"); - if (a_selector_list) - { - cr_selector_dump (a_selector_list, stdout) ; - fprintf (stdout,"\n") ; + if (a_selector_list) { + cr_selector_dump (a_selector_list, stdout); + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_end_selector (CRDocHandler *a_handler, - CRSelector *a_selector_list) +test_end_selector (CRDocHandler * a_handler, CRSelector * a_selector_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_selector\n") ; - - if (a_selector_list) - { - cr_selector_dump (a_selector_list, stdout) ; - fprintf (stdout,"\n") ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_selector\n"); + + if (a_selector_list) { + cr_selector_dump (a_selector_list, stdout); + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_property (CRDocHandler *a_handler, GString *a_name, - CRTerm *a_expr, gboolean a_important) +test_property (CRDocHandler * a_handler, GString * a_name, + CRTerm * a_expr, gboolean a_important) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"property\n") ; - - if (a_name && a_name->str) - { - guchar *name = g_strndup (a_name->str, a_name->len) ; - - if (name) - { - fprintf (stdout,name) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "property\n"); + + if (a_name && a_name->str) { + guchar *name = g_strndup (a_name->str, a_name->len); + + if (name) { + fprintf (stdout, name); } - - if (a_expr) - { - fprintf (stdout,": ") ; - cr_term_dump (a_expr, stdout) ; + + if (a_expr) { + fprintf (stdout, ": "); + cr_term_dump (a_expr, stdout); } - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - - fprintf (stdout,"\n") ; + + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_start_font_face (CRDocHandler *a_handler) +test_start_font_face (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_font_face\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_font_face\n"); + fprintf (stdout, "***************\n\n"); } - static void -test_end_font_face (CRDocHandler *a_handler) +test_end_font_face (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_font_face\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_font_face\n"); + fprintf (stdout, "***************\n\n"); } static void -test_start_media (CRDocHandler *a_handler, - GList *a_media_list) +test_start_media (CRDocHandler * a_handler, GList * a_media_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_media\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - guchar *medium = NULL ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data == NULL) - continue ; - - medium = g_strndup (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_media\n"); + + if (a_media_list) { + GList *cur = NULL; + guchar *medium = NULL; + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data == NULL) + continue; + + medium = g_strndup (((GString *) cur->data)->str, + ((GString *) cur->data)->len); if (medium == NULL) - continue ; + continue; - fprintf (stdout,"medium: %s\n", medium) ; + fprintf (stdout, "medium: %s\n", medium); - if (medium) - { - g_free (medium) ; - medium = NULL ; + if (medium) { + g_free (medium); + medium = NULL; } } } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_end_media (CRDocHandler *a_handler, - GList *a_media_list) +test_end_media (CRDocHandler * a_handler, GList * a_media_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_media\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - guchar *medium = NULL ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data == NULL) - continue ; - - medium = g_strndup (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_media\n"); + + if (a_media_list) { + GList *cur = NULL; + guchar *medium = NULL; + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data == NULL) + continue; + + medium = g_strndup (((GString *) cur->data)->str, + ((GString *) cur->data)->len); if (medium == NULL) - continue ; + continue; - fprintf (stdout,"medium: %s\n", medium) ; + fprintf (stdout, "medium: %s\n", medium); - if (medium) - { - g_free (medium) ; - medium = NULL ; + if (medium) { + g_free (medium); + medium = NULL; } } } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } static void -test_start_page (CRDocHandler *a_handler, - GString *a_name, GString *a_pseudo_page) +test_start_page (CRDocHandler * a_handler, + GString * a_name, GString * a_pseudo_page) { - guchar *name = NULL, *pseudo_page = NULL ; + guchar *name = NULL, + *pseudo_page = NULL; - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_page\n") ; - - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_page\n"); + + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (a_pseudo_page && a_pseudo_page->str) - { - pseudo_page = g_strndup (a_pseudo_page->str, - a_pseudo_page->len) ; + if (a_pseudo_page && a_pseudo_page->str) { + pseudo_page = g_strndup (a_pseudo_page->str, + a_pseudo_page->len); } - if (name) - { - fprintf (stdout,"%s", name) ; + if (name) { + fprintf (stdout, "%s", name); } - if (pseudo_page) - { - fprintf (stdout,": %s\n", pseudo_page) ; + if (pseudo_page) { + fprintf (stdout, ": %s\n", pseudo_page); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - if (pseudo_page) - { - g_free (pseudo_page) ; - pseudo_page = NULL ; + if (pseudo_page) { + g_free (pseudo_page); + pseudo_page = NULL; } } static void -test_end_page (CRDocHandler *a_handler, - GString *a_name, GString *a_pseudo_page) +test_end_page (CRDocHandler * a_handler, + GString * a_name, GString * a_pseudo_page) { - guchar *name = NULL, *pseudo_page = NULL ; + guchar *name = NULL, + *pseudo_page = NULL; + + g_return_if_fail (a_handler); - g_return_if_fail (a_handler) ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_page\n"); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_page\n") ; - - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (a_pseudo_page && a_pseudo_page->str) - { - pseudo_page = g_strndup (a_pseudo_page->str, - a_pseudo_page->len) ; + if (a_pseudo_page && a_pseudo_page->str) { + pseudo_page = g_strndup (a_pseudo_page->str, + a_pseudo_page->len); } - if (name) - { - fprintf (stdout,"%s", name) ; + if (name) { + fprintf (stdout, "%s", name); } - if (pseudo_page) - { - fprintf (stdout,": %s\n", pseudo_page) ; - + if (pseudo_page) { + fprintf (stdout, ": %s\n", pseudo_page); + } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - if (pseudo_page) - { - g_free (pseudo_page) ; - pseudo_page = NULL ; + if (pseudo_page) { + g_free (pseudo_page); + pseudo_page = NULL; } } - static void -test_ignorable_at_rule (CRDocHandler *a_handler, - GString *a_name) +test_ignorable_at_rule (CRDocHandler * a_handler, GString * a_name) { - guchar *name = NULL ; + guchar *name = NULL; - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"*********************\n") ; - fprintf (stdout,"ignorable_at_rule\n") ; + fprintf (stdout, "*********************\n"); + fprintf (stdout, "ignorable_at_rule\n"); - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (name) - { - fprintf (stdout,"%s\n", name) ; + if (name) { + fprintf (stdout, "%s\n", name); } - fprintf (stdout,"*********************\n\n") ; + fprintf (stdout, "*********************\n\n"); } - static void -init_test_sac_handler (CRDocHandler *a_handler) - +init_test_sac_handler (CRDocHandler * a_handler) { - a_handler->start_document = test_start_document ; - a_handler->end_document = test_end_document ; - a_handler->import_style = test_import_style ; - a_handler->namespace_declaration = test_namespace_declaration ; - a_handler->comment = test_comment ; - a_handler->start_selector = test_start_selector ; - a_handler->end_selector = test_end_selector ; - a_handler->property = test_property ; - a_handler->start_font_face = test_start_font_face ; - a_handler->end_font_face = test_end_font_face ; - a_handler->start_media = test_start_media ; - a_handler->end_media = test_end_media ; - a_handler->start_page = test_start_page ; - a_handler->end_page = test_end_page ; - a_handler->ignorable_at_rule = test_ignorable_at_rule ; + a_handler->start_document = test_start_document; + a_handler->end_document = test_end_document; + a_handler->import_style = test_import_style; + a_handler->namespace_declaration = test_namespace_declaration; + a_handler->comment = test_comment; + a_handler->start_selector = test_start_selector; + a_handler->end_selector = test_end_selector; + a_handler->property = test_property; + a_handler->start_font_face = test_start_font_face; + a_handler->end_font_face = test_end_font_face; + a_handler->start_media = test_start_media; + a_handler->end_media = test_end_media; + a_handler->start_page = test_start_page; + a_handler->end_page = test_end_page; + a_handler->ignorable_at_rule = test_ignorable_at_rule; } /*************************** @@ -563,7 +507,6 @@ init_test_sac_handler (CRDocHandler *a_handler) *handlers. ***************************/ - /** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the @@ -576,70 +519,64 @@ init_test_sac_handler (CRDocHandler *a_handler) static enum CRStatus test_cr_parser_parse (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CRParser *parser = NULL ; + enum CRStatus status = CR_OK; + CRParser *parser = NULL; + + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; + gv_test_handler = cr_doc_handler_new (); + init_test_sac_handler (gv_test_handler); - gv_test_handler = cr_doc_handler_new () ; - init_test_sac_handler (gv_test_handler) ; + parser = cr_parser_new (NULL); - parser = cr_parser_new (NULL) ; + status = cr_parser_set_sac_handler (parser, gv_test_handler); - status = cr_parser_set_sac_handler (parser, gv_test_handler) ; - - if (status != CR_OK) - { - cr_parser_destroy (parser) ; - g_return_val_if_fail (status == CR_OK, CR_ERROR) ; - } + if (status != CR_OK) { + cr_parser_destroy (parser); + g_return_val_if_fail (status == CR_OK, CR_ERROR); + } - status = cr_parser_set_use_core_grammar (parser, TRUE) ; - status = cr_parser_parse_file (parser, a_file_uri, CR_ASCII) ; + status = cr_parser_set_use_core_grammar (parser, TRUE); + status = cr_parser_parse_file (parser, a_file_uri, CR_ASCII); - cr_parser_destroy (parser) ; + cr_parser_destroy (parser); - gv_test_handler = NULL ; + gv_test_handler = NULL; - return status ; + return status; } - /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; - enum CRStatus status = CR_OK ; + struct Options options; + enum CRStatus status = CR_OK; - cr_test_utils_parse_cmd_line (argc, argv, &options) ; + cr_test_utils_parse_cmd_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - status = test_cr_parser_parse (options.files_list[0]) ; + status = test_cr_parser_parse (options.files_list[0]); - if (status != CR_OK) - { - fprintf (stdout,"KO\n") ; + if (status != CR_OK) { + fprintf (stdout, "KO\n"); } - return 0 ; + return 0; } diff --git a/tests/test4-main.c b/tests/test4-main.c index 997e2ec..ea51d68 100644 --- a/tests/test4-main.c +++ b/tests/test4-main.c @@ -27,59 +27,43 @@ #include "cr-test-utils.h" #include "libcroco.h" - /** *@file *Some test facilities for the #CROMParser class. */ -CRDocHandler * gv_test_handler = {0} ; +CRDocHandler *gv_test_handler = { 0 }; -const guchar * gv_term_buf= "106" ; +const guchar *gv_term_buf = "106"; -const guchar * gv_decl_buf = -"toto: tutu, tata" ; +const guchar *gv_decl_buf = "toto: tutu, tata"; -const guchar * gv_decl_list_buf = -"toto: titi; prop1:val1 ; prop2:val2;" ; +const guchar *gv_decl_list_buf = "toto: titi; prop1:val1 ; prop2:val2;"; -const guchar *gv_ruleset_buf = -"s1 > s2 {toto: tutu, tata} " -; +const guchar *gv_ruleset_buf = "s1 > s2 {toto: tutu, tata} "; const guchar *gv_at_media_buf = -"@media print, toto {" -" BODY { font-size: 10pt }" -" }" -; + "@media print, toto {" " BODY { font-size: 10pt }" " }"; -const guchar *gv_at_page_buf = -"@page { size :8.5in 11in; margin: 2cm }" -; +const guchar *gv_at_page_buf = "@page { size :8.5in 11in; margin: 2cm }"; -const guchar *gv_at_charset_buf = -"@charset \"ISO-8859-1\" ; " -; +const guchar *gv_at_charset_buf = "@charset \"ISO-8859-1\" ; "; -const guchar *gv_at_font_face_buf= -"@font-face {" -" font-family: \"Robson Celtic\";" -" src: url(\"http://site/fonts/rob-celt\")" -"}" -; +const guchar *gv_at_font_face_buf = + "@font-face {" + " font-family: \"Robson Celtic\";" + " src: url(\"http://site/fonts/rob-celt\")" "}"; -const guchar *gv_at_import_buf= -"@import \"subs.css\";" -; +const guchar *gv_at_import_buf = "@import \"subs.css\";"; -static void -display_help (char *prg_name) ; +static void + display_help (char *prg_name); -static void -display_about (char *prg_name) ; +static void + display_about (char *prg_name); static enum CRStatus -test_cr_parser_parse (guchar * a_file_uri) ; + test_cr_parser_parse (guchar * a_file_uri); /** *Displays the usage of the test @@ -87,17 +71,17 @@ test_cr_parser_parse (guchar * a_file_uri) ; *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - g_print ("\n\n") ; - g_print ("usage: %s <file-to-parse>\n", prg_name) ; - g_print ("\t <file-to-parse>: the file to parse\n") ; - g_print ("\n\n") ; - g_print ("Tests the cr_parser_parse () method.\n") ; - g_print ("Tests the parsing following the css core syntax\n") ; - g_print ("Returns OK if the status is CR_OK, KO otherwise\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("usage: %s <file-to-parse>\n", prg_name); + g_print ("\t <file-to-parse>: the file to parse\n"); + g_print ("\n\n"); + g_print ("Tests the cr_parser_parse () method.\n"); + g_print ("Tests the parsing following the css core syntax\n"); + g_print ("Returns OK if the status is CR_OK, KO otherwise\n"); + g_print ("\n\n"); } /** @@ -105,21 +89,19 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - g_print ("\n\n") ; - g_print ("%s is a libcroco CROMParser class test program.\n", - prg_name) ; - g_print ("%s Parses a file and builds a CSS object model", - prg_name) ; - g_print ("It should run on GNU compliants systems.\n") ; - g_print ("\n\n") ; - g_print ("Initial author: Dodji Seketeli <dodji@seketeli.org>.\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("%s is a libcroco CROMParser class test program.\n", + prg_name); + g_print ("%s Parses a file and builds a CSS object model", prg_name); + g_print ("It should run on GNU compliants systems.\n"); + g_print ("\n\n"); + g_print ("Initial author: Dodji Seketeli <dodji@seketeli.org>.\n"); + g_print ("\n\n"); } - /** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the @@ -132,383 +114,332 @@ display_about (char *prg_name) static enum CRStatus test_cr_parser_parse (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CROMParser *parser = NULL ; - CRStyleSheet *stylesheet = NULL ; - - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; - - parser = cr_om_parser_new (NULL) ; - status = cr_om_parser_parse_file (parser, a_file_uri, CR_ASCII, - &stylesheet) ; - if (status == CR_OK && stylesheet) - { - cr_stylesheet_dump (stylesheet, stdout) ; - cr_stylesheet_destroy (stylesheet) ; - } - cr_om_parser_destroy (parser) ; - - return status ; -} + enum CRStatus status = CR_OK; + CROMParser *parser = NULL; + CRStyleSheet *stylesheet = NULL; + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); + + parser = cr_om_parser_new (NULL); + status = cr_om_parser_parse_file (parser, a_file_uri, CR_ASCII, + &stylesheet); + if (status == CR_OK && stylesheet) { + cr_stylesheet_dump (stylesheet, stdout); + cr_stylesheet_destroy (stylesheet); + } + cr_om_parser_destroy (parser); + + return status; +} static enum CRStatus test_cr_term_parse_expression_from_buf (void) { - guchar * tmp_str = NULL ; - CRTerm * term = NULL ; + guchar *tmp_str = NULL; + CRTerm *term = NULL; - term = cr_term_parse_expression_from_buf (gv_term_buf, - CR_UTF_8) ; + term = cr_term_parse_expression_from_buf (gv_term_buf, CR_UTF_8); if (!term) - return CR_ERROR ; - tmp_str = cr_term_to_string (term) ; - if (term) - { - cr_term_destroy (term) ; - term = NULL ; - } - if (tmp_str) - { - g_free (tmp_str) ; - tmp_str = NULL ; - } - return CR_OK ; + return CR_ERROR; + tmp_str = cr_term_to_string (term); + if (term) { + cr_term_destroy (term); + term = NULL; + } + if (tmp_str) { + g_free (tmp_str); + tmp_str = NULL; + } + return CR_OK; } static enum CRStatus test_cr_declaration_parse (void) { - guchar * tmp_str = NULL ; - CRDeclaration * decl = NULL ; + guchar *tmp_str = NULL; + CRDeclaration *decl = NULL; - decl = cr_declaration_parse_from_buf (NULL, gv_decl_buf, - CR_UTF_8) ; + decl = cr_declaration_parse_from_buf (NULL, gv_decl_buf, CR_UTF_8); if (!decl) - return CR_ERROR ; - tmp_str = cr_declaration_to_string (decl, 2) ; + return CR_ERROR; + tmp_str = cr_declaration_to_string (decl, 2); - if (decl) - { - cr_declaration_destroy (decl) ; + if (decl) { + cr_declaration_destroy (decl); } - if (tmp_str) - { - g_free (tmp_str) ; - tmp_str = NULL ; + if (tmp_str) { + g_free (tmp_str); + tmp_str = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_declaration_parse_list (void) { - GString *str = NULL ; - guchar *tmp_str = NULL ; - CRDeclaration *decl = NULL, *cur_decl = NULL ; + GString *str = NULL; + guchar *tmp_str = NULL; + CRDeclaration *decl = NULL, + *cur_decl = NULL; decl = cr_declaration_parse_list_from_buf (gv_decl_list_buf, - CR_UTF_8) ; + CR_UTF_8); if (!decl) - return CR_ERROR ; - str = g_string_new (NULL) ; - for (cur_decl = decl ; cur_decl ; cur_decl = cur_decl->next) - { - tmp_str = cr_declaration_to_string (cur_decl, 2) ; - if (tmp_str) - { - g_string_append_printf (str, "%s;", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + return CR_ERROR; + str = g_string_new (NULL); + for (cur_decl = decl; cur_decl; cur_decl = cur_decl->next) { + tmp_str = cr_declaration_to_string (cur_decl, 2); + if (tmp_str) { + g_string_append_printf (str, "%s;", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } - + } - if (decl) - { - cr_declaration_destroy (decl) ; + if (decl) { + cr_declaration_destroy (decl); } - if (str) - { - g_string_free (str, TRUE) ; - str = NULL ; + if (str) { + g_string_free (str, TRUE); + str = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_statement_ruleset_parse (void) { - CRStatement *stmt = NULL ; - - stmt = cr_statement_ruleset_parse_from_buf (gv_ruleset_buf, - CR_UTF_8) ; - g_return_val_if_fail (stmt, CR_ERROR) ; + CRStatement *stmt = NULL; + + stmt = cr_statement_ruleset_parse_from_buf (gv_ruleset_buf, CR_UTF_8); + g_return_val_if_fail (stmt, CR_ERROR); - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_statement_at_media_rule_parse (void) { - CRStatement *stmt = NULL ; + CRStatement *stmt = NULL; stmt = cr_statement_at_media_rule_parse_from_buf (gv_at_media_buf, - CR_UTF_8) ; - g_return_val_if_fail (stmt, CR_ERROR) ; - - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + CR_UTF_8); + g_return_val_if_fail (stmt, CR_ERROR); + + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_statement_at_page_rule_parse (void) { - CRStatement *stmt = NULL ; - + CRStatement *stmt = NULL; + stmt = cr_statement_at_page_rule_parse_from_buf (gv_at_page_buf, - CR_UTF_8) ; - - g_return_val_if_fail (stmt, CR_ERROR) ; - - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + CR_UTF_8); + + g_return_val_if_fail (stmt, CR_ERROR); + + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_statement_at_charset_rule_parse (void) { - CRStatement *stmt = NULL ; - + CRStatement *stmt = NULL; + stmt = cr_statement_at_charset_rule_parse_from_buf (gv_at_charset_buf, - CR_UTF_8) ; - g_return_val_if_fail (stmt, CR_ERROR) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + CR_UTF_8); + g_return_val_if_fail (stmt, CR_ERROR); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - return CR_OK ; + return CR_OK; } - static enum CRStatus test_cr_statement_font_face_rule_parse_from_buf (void) { - CRStatement *stmt = NULL ; - - stmt = cr_statement_font_face_rule_parse_from_buf (gv_at_font_face_buf, - CR_UTF_8) ; - g_return_val_if_fail (stmt, CR_ERROR) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - - return CR_OK ; + CRStatement *stmt = NULL; + + stmt = cr_statement_font_face_rule_parse_from_buf + (gv_at_font_face_buf, CR_UTF_8); + g_return_val_if_fail (stmt, CR_ERROR); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } + + return CR_OK; } static enum CRStatus test_cr_statement_at_import_rule_parse_from_buf (void) { - CRStatement *stmt = NULL ; + CRStatement *stmt = NULL; stmt = cr_statement_at_import_rule_parse_from_buf (gv_at_import_buf, - CR_UTF_8) ; - g_return_val_if_fail (stmt, CR_ERROR) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + CR_UTF_8); + g_return_val_if_fail (stmt, CR_ERROR); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_statement_parse_from_buf (void) { - CRStatement *stmt = NULL ; - - stmt = cr_statement_parse_from_buf (gv_ruleset_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - stmt = cr_statement_parse_from_buf (gv_at_media_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - stmt = cr_statement_parse_from_buf (gv_at_page_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - stmt = cr_statement_parse_from_buf (gv_at_charset_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - stmt = cr_statement_parse_from_buf (gv_at_font_face_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - stmt = cr_statement_parse_from_buf (gv_at_import_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - - return CR_OK ; + CRStatement *stmt = NULL; + + stmt = cr_statement_parse_from_buf (gv_ruleset_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + stmt = cr_statement_parse_from_buf (gv_at_media_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + stmt = cr_statement_parse_from_buf (gv_at_page_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + stmt = cr_statement_parse_from_buf (gv_at_charset_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + stmt = cr_statement_parse_from_buf (gv_at_font_face_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + stmt = cr_statement_parse_from_buf (gv_at_import_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + + return CR_OK; } /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; - enum CRStatus status = CR_OK ; + struct Options options; + enum CRStatus status = CR_OK; - status = test_cr_term_parse_expression_from_buf() ; - if (status != CR_OK) - { - g_print ("\ntest \"cr_term_parse_expression_from_buf failed\"") ; + status = test_cr_term_parse_expression_from_buf (); + if (status != CR_OK) { + g_print ("\ntest \"cr_term_parse_expression_from_buf failed\""); } - status = test_cr_declaration_parse () ; - if (status != CR_OK) - { - g_print ("\n test \"cr_declaration_parse() failed\"\n") ; + status = test_cr_declaration_parse (); + if (status != CR_OK) { + g_print ("\n test \"cr_declaration_parse() failed\"\n"); } - status = test_cr_declaration_parse_list () ; - if (status != CR_OK) - { - g_print ("\ntest cr_declaration_parse_list() failed\n") ; + status = test_cr_declaration_parse_list (); + if (status != CR_OK) { + g_print ("\ntest cr_declaration_parse_list() failed\n"); } - status = test_cr_statement_ruleset_parse () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_ruleset_parse() failed\n") ; + status = test_cr_statement_ruleset_parse (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_ruleset_parse() failed\n"); } - status = test_cr_statement_at_media_rule_parse () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_at_media_rule_parse() failed\n") ; + status = test_cr_statement_at_media_rule_parse (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_at_media_rule_parse() failed\n"); } - test_cr_statement_at_page_rule_parse () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_at_page_rule_parse() failed\n") ; - return 0 ; + test_cr_statement_at_page_rule_parse (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_at_page_rule_parse() failed\n"); + return 0; } - status = test_cr_statement_at_charset_rule_parse () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_at_charset_rule_parse() failed\n") ; + status = test_cr_statement_at_charset_rule_parse (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_at_charset_rule_parse() failed\n"); } - status = test_cr_statement_font_face_rule_parse_from_buf () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_font_face_rule_parse_from_buf() failed\n") ; + status = test_cr_statement_font_face_rule_parse_from_buf (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_font_face_rule_parse_from_buf() failed\n"); } - test_cr_statement_at_import_rule_parse_from_buf () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_at_import_rule() failed\n") ; + test_cr_statement_at_import_rule_parse_from_buf (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_at_import_rule() failed\n"); } - status = test_cr_statement_parse_from_buf () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_parse_from_buf() failed\n") ; + status = test_cr_statement_parse_from_buf (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_parse_from_buf() failed\n"); } - cr_test_utils_parse_cmd_line (argc, argv, &options) ; + cr_test_utils_parse_cmd_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - - status = test_cr_parser_parse (options.files_list[0]) ; - if (status != CR_OK) - { - g_print ("\nKO\n") ; + + status = test_cr_parser_parse (options.files_list[0]); + if (status != CR_OK) { + g_print ("\nKO\n"); } - - return 0 ; + + return 0; } diff --git a/tests/test5-main.c b/tests/test5-main.c index 4214746..59d81aa 100644 --- a/tests/test5-main.c +++ b/tests/test5-main.c @@ -28,38 +28,35 @@ #include "cr-test-utils.h" #include "libcroco.h" - /** *@file *Some test facilities for the #CRParser class. */ -CRDocHandler * gv_test_handler = {0} ; - -const guchar *xml_content= -"<document>" -"<E0>text0</E0> " -"<E1><E1-1>text1</E1-1></E1>" -"<E2 attr2=\"val2\">text2</E2>" -"<E3 attr3=\"val3_1 val3_2 val3_3\">text3</E3>" -"<E4 attr4=\"val4_1-val4_2-val4_3\">text4</E4>" -"<E5 class=\"class5\">text5</E5>" -"<E6 id=\"id6\">text6</E6>" -"<E7 lang=\"fr\">text7</E7>" -"</document>"; - -static void -display_help (char *prg_name) ; - -static void -display_about (char *prg_name) ; +CRDocHandler *gv_test_handler = { 0 }; + +const guchar *xml_content = + "<document>" + "<E0>text0</E0> " + "<E1><E1-1>text1</E1-1></E1>" + "<E2 attr2=\"val2\">text2</E2>" + "<E3 attr3=\"val3_1 val3_2 val3_3\">text3</E3>" + "<E4 attr4=\"val4_1-val4_2-val4_3\">text4</E4>" + "<E5 class=\"class5\">text5</E5>" + "<E6 id=\"id6\">text6</E6>" + "<E7 lang=\"fr\">text7</E7>" "</document>"; + +static void + display_help (char *prg_name); + +static void + display_about (char *prg_name); static enum CRStatus -test_sel_eng (guchar * a_file_uri) ; + test_sel_eng (guchar * a_file_uri); static void -walk_xml_tree_and_lookup_rules (CRSelEng *a_sel_eng, - CRStyleSheet *a_sheet, - xmlNode *a_node) ; + walk_xml_tree_and_lookup_rules (CRSelEng * a_sel_eng, + CRStyleSheet * a_sheet, xmlNode * a_node); /** *Displays the usage of the test @@ -67,16 +64,16 @@ walk_xml_tree_and_lookup_rules (CRSelEng *a_sel_eng, *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - g_print ("\n\n") ; - g_print ("usage: %s <file-to-parse>\n", prg_name) ; - g_print ("\t <file-to-parse>: the file to parse\n") ; - g_print ("\n\n") ; - g_print ("Test the selection engine") ; - g_print ("Returns OK if the status is CR_OK, KO otherwise\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("usage: %s <file-to-parse>\n", prg_name); + g_print ("\t <file-to-parse>: the file to parse\n"); + g_print ("\n\n"); + g_print ("Test the selection engine"); + g_print ("Returns OK if the status is CR_OK, KO otherwise\n"); + g_print ("\n\n"); } /** @@ -84,68 +81,56 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - g_print ("\n\n") ; - g_print ("%s is a libcroco CROMParser class test program.\n", - prg_name) ; - g_print ("%s Parses a file and builds a CSS object model", - prg_name) ; - g_print ("It should run on GNU compliants systems.\n") ; - g_print ("\n\n") ; - g_print ("Initial author: Dodji Seketeli <dodji@seketeli.org>.\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("%s is a libcroco CROMParser class test program.\n", + prg_name); + g_print ("%s Parses a file and builds a CSS object model", prg_name); + g_print ("It should run on GNU compliants systems.\n"); + g_print ("\n\n"); + g_print ("Initial author: Dodji Seketeli <dodji@seketeli.org>.\n"); + g_print ("\n\n"); } - static void -walk_xml_tree_and_lookup_rules (CRSelEng *a_sel_eng, - CRStyleSheet *a_sheet, - xmlNode *a_node) +walk_xml_tree_and_lookup_rules (CRSelEng * a_sel_eng, + CRStyleSheet * a_sheet, xmlNode * a_node) { CRStatement **stmts_tab = NULL; - gulong tab_len = 0, i= 0 ; - enum CRStatus status = CR_OK ; - - xmlNode *cur_node = a_node ; - - for (cur_node = a_node ;cur_node ; cur_node = cur_node->next) - { - status = cr_sel_eng_get_matched_rulesets - (a_sel_eng, a_sheet, - cur_node, &stmts_tab, &tab_len) ; - - if (status == CR_OK && tab_len) - { - g_print ("'''''''''''''''''''''''''\n") ; - g_print ("xml start element: %s\n", - cur_node->name); - - for (i = 0 ; i < tab_len; i++) - { - if (stmts_tab[i]) - { - g_print ("\n") ; + gulong tab_len = 0, + i = 0; + enum CRStatus status = CR_OK; + + xmlNode *cur_node = a_node; + + for (cur_node = a_node; cur_node; cur_node = cur_node->next) { + status = cr_sel_eng_get_matched_rulesets + (a_sel_eng, a_sheet, cur_node, &stmts_tab, &tab_len); + + if (status == CR_OK && tab_len) { + g_print ("'''''''''''''''''''''''''\n"); + g_print ("xml start element: %s\n", cur_node->name); + + for (i = 0; i < tab_len; i++) { + if (stmts_tab[i]) { + g_print ("\n"); cr_statement_dump (stmts_tab[i], - stdout, 2) ; + stdout, 2); } } - g_print ("\n\nxml end element: %s\n", - cur_node->name); - g_print ("'''''''''''''''''''''''''\n") ; + g_print ("\n\nxml end element: %s\n", cur_node->name); + g_print ("'''''''''''''''''''''''''\n"); } - if (stmts_tab) - { - g_free (stmts_tab) ; - stmts_tab= NULL ; + if (stmts_tab) { + g_free (stmts_tab); + stmts_tab = NULL; } - if (cur_node->children) - { - walk_xml_tree_and_lookup_rules - (a_sel_eng, a_sheet, - cur_node->children) ; + if (cur_node->children) { + walk_xml_tree_and_lookup_rules + (a_sel_eng, a_sheet, cur_node->children); } } } @@ -162,121 +147,107 @@ walk_xml_tree_and_lookup_rules (CRSelEng *a_sel_eng, static enum CRStatus test_sel_eng (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CROMParser *parser = NULL ; - CRStyleSheet *stylesheet = NULL ; - xmlDoc * xml_doc = NULL ; - xmlNode *cur_node = NULL ; - CRSelEng *selection_engine = NULL ; - - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; - - parser = cr_om_parser_new (NULL) ; - status = cr_om_parser_parse_file (parser, a_file_uri, CR_ASCII, - &stylesheet) ; - if (status != CR_OK || !stylesheet) - { - cr_utils_trace_info ("Could not parse xml content") ; - goto error ; - } - - xml_doc = xmlParseMemory (xml_content, strlen (xml_content)) ; - if (!xml_doc) - { - cr_utils_trace_info ("Could not parse xml content") ; - goto error ; - + enum CRStatus status = CR_OK; + CROMParser *parser = NULL; + CRStyleSheet *stylesheet = NULL; + xmlDoc *xml_doc = NULL; + xmlNode *cur_node = NULL; + CRSelEng *selection_engine = NULL; + + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); + + parser = cr_om_parser_new (NULL); + status = cr_om_parser_parse_file (parser, a_file_uri, CR_ASCII, + &stylesheet); + if (status != CR_OK || !stylesheet) { + cr_utils_trace_info ("Could not parse xml content"); + goto error; } - selection_engine = cr_sel_eng_new () ; + xml_doc = xmlParseMemory (xml_content, strlen (xml_content)); + if (!xml_doc) { + cr_utils_trace_info ("Could not parse xml content"); + goto error; - cur_node = xml_doc->children ; + } + + selection_engine = cr_sel_eng_new (); + + cur_node = xml_doc->children; walk_xml_tree_and_lookup_rules (selection_engine, - stylesheet, - cur_node) ; + stylesheet, cur_node); - if (parser) - { - cr_om_parser_destroy (parser) ; - parser = NULL ; + if (parser) { + cr_om_parser_destroy (parser); + parser = NULL; } - if (xml_doc) - { - xmlFreeDoc (xml_doc) ; - xml_doc = NULL ; + if (xml_doc) { + xmlFreeDoc (xml_doc); + xml_doc = NULL; } - if (stylesheet) - { - cr_stylesheet_destroy (stylesheet) ; - stylesheet = NULL ; + if (stylesheet) { + cr_stylesheet_destroy (stylesheet); + stylesheet = NULL; } - xmlCleanupParser () ; - return status ; + xmlCleanupParser (); + return status; - error: + error: - if (parser) - { - cr_om_parser_destroy (parser) ; - parser = NULL ; + if (parser) { + cr_om_parser_destroy (parser); + parser = NULL; } - if (xml_doc) - { - xmlFreeDoc (xml_doc) ; - xml_doc = NULL ; + if (xml_doc) { + xmlFreeDoc (xml_doc); + xml_doc = NULL; } - if (stylesheet) - { - cr_stylesheet_destroy (stylesheet) ; - stylesheet = NULL ; + if (stylesheet) { + cr_stylesheet_destroy (stylesheet); + stylesheet = NULL; } - xmlCleanupParser () ; - return CR_ERROR ; + xmlCleanupParser (); + return CR_ERROR; } - /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; - enum CRStatus status = CR_OK ; + struct Options options; + enum CRStatus status = CR_OK; - cr_test_utils_parse_cmd_line (argc, argv, &options) ; + cr_test_utils_parse_cmd_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - status = test_sel_eng (options.files_list[0]) ; + status = test_sel_eng (options.files_list[0]); - if (status != CR_OK) - { - g_print ("\nKO\n") ; + if (status != CR_OK) { + g_print ("\nKO\n"); } - return 0 ; + return 0; } diff --git a/tests/test6-main.c b/tests/test6-main.c index 4e534bf..f9dd1c3 100644 --- a/tests/test6-main.c +++ b/tests/test6-main.c @@ -30,13 +30,11 @@ #include "libcroco.h" #include "cr-test-utils.h" -const guchar * gv_cssbuf = -".str0 {stroke:#007844;stroke-width:44}" -".fil0 {fill:url(#id0)}" ; +const guchar *gv_cssbuf = + ".str0 {stroke:#007844;stroke-width:44}" ".fil0 {fill:url(#id0)}"; static enum CRStatus -test_cr_parser_parse (void) ; - + test_cr_parser_parse (void); /** *The test of the cr_input_read_byte() method. @@ -50,40 +48,37 @@ test_cr_parser_parse (void) ; static enum CRStatus test_cr_parser_parse (void) { - enum CRStatus status = CR_OK ; - CROMParser *parser = NULL ; - CRStyleSheet *stylesheet = NULL ; + enum CRStatus status = CR_OK; + CROMParser *parser = NULL; + CRStyleSheet *stylesheet = NULL; - parser = cr_om_parser_new (NULL) ; - status = cr_om_parser_parse_buf (parser, (guchar*)gv_cssbuf, - strlen (gv_cssbuf), - CR_ASCII, - &stylesheet) ; + parser = cr_om_parser_new (NULL); + status = cr_om_parser_parse_buf (parser, (guchar *) gv_cssbuf, + strlen (gv_cssbuf), + CR_ASCII, &stylesheet); - if (status == CR_OK && stylesheet) - { - cr_stylesheet_dump (stylesheet, stdout) ; - cr_stylesheet_destroy (stylesheet) ; - } - cr_om_parser_destroy (parser) ; + if (status == CR_OK && stylesheet) { + cr_stylesheet_dump (stylesheet, stdout); + cr_stylesheet_destroy (stylesheet); + } + cr_om_parser_destroy (parser); - return status ; + return status; } /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - status = test_cr_parser_parse () ; + status = test_cr_parser_parse (); - if (status != CR_OK) - { - g_print ("\nKO\n") ; + if (status != CR_OK) { + g_print ("\nKO\n"); } - return 0 ; + return 0; } diff --git a/tests/test7-main.c b/tests/test7-main.c index 4165a53..e55467a 100644 --- a/tests/test7-main.c +++ b/tests/test7-main.c @@ -30,179 +30,164 @@ #include "libcroco.h" #include "cr-test-utils.h" - const guchar *gv_xmlbuf = -"<?xml version=\"1.0\"?>" -"<rss version=\"0.91\">" -"<channel>" -"<title>scottandrew.com JavaScript and DHTML Channel</title>" -"<link>http://www.scottandrew.com</link>" -"<description>DHTML, DOM and JavaScript snippets from scottandrew.com</description>" -"<language>en-us</language>" -"<item>" -"<title>DHTML Animation Array Generator</title>" -"<description>Robert points us to the first third-party tool for the DomAPI: The Animation Array Generator, a visual tool for creating...</description>" -"<link>http://www.scottandrew.com/weblog/2002_06#a000395</link>" -"</item>" -"<item>" -"<title>DOM and Extended Entries</title>" -"<description>Aarondot: A Better Way To Display Extended Entries. Very cool, and uses the DOM and JavaScript to reveal the extended...</description>" -"<link>http://www.scottandrew.com/weblog/2002_06#a000373</link>" -"</item>" -"<item>" -"<title>cellspacing and the DOM</title>" -"<description>By the way, if you're using the DOM to generate TABLE elements, you have to use setAttribute() to set the...</description>" -"<link>http://www.scottandrew.com/weblog/2002_05#a000365</link>" -"</item>" -"<item>" -"<title>contenteditable for Mozilla</title>" -"<description>The folks art Q42, creator of Quek (cute little avatar/chat) and Xopus (browser-based WYSIWYG XML-editor) have released code that ,simulates...</description>" -"<link>http://www.scottandrew.com/weblog/2002_05#a000361</link>" -"</item>" -"</channel>" -"</rss>" -; - -const char * gv_cssbuf= -"rss " -"{ " -" display:block; " -" margin:10px; " -"} " -" " -"channel " -"{ " -" display:block; " -" /*height:300px;*/ " -" width:200px; " -" border:1px solid #000; " -" overflow:auto; " -" background-color:#eee; " -" /*font: 12px verdana;*/ " -" font-style: font-family ; " -" font-style: normal; " -"} " -" " -"item " -"{ " -" width: 100%; " -" display: block; " -" padding:10px; " -" margin-bottom:10px; " -" border:1px solid #ccc; " -" /*border-top:1px solid #ccc; " -" border-bottom:1px solid #ccc; " -" border-left:1px solid #ccc; " -" border-right:1px solid #ccc; " -" */ " -" background-color:#fff; " -"} " -" " -" " -"channel>title, channel>description " -"{ " -" display: block; " -" width: 100%; " -" /*margin-left:10px;*/ " -" /*margin-top:10px;*/ " -" background-color:#eee; " -" font-weight:bold; " -" font-size: 12px; " -"} " -" " -"channel>title " -"{ " -" font-size:16px; " -"} " -" " -"channel>description " -"{ " -" display: block ; " -" font-size:10px; " -" margin-bottom:10px; " -"} " -" " -"item>title " -"{ " -" font-weight:bold; " -"} " -" " -"item>link, channel>link, channel>language " -"{ " -" display: none; " -"} " -" " -; + "<?xml version=\"1.0\"?>" + "<rss version=\"0.91\">" + "<channel>" + "<title>scottandrew.com JavaScript and DHTML Channel</title>" + "<link>http://www.scottandrew.com</link>" + "<description>DHTML, DOM and JavaScript snippets from scottandrew.com</description>" + "<language>en-us</language>" + "<item>" + "<title>DHTML Animation Array Generator</title>" + "<description>Robert points us to the first third-party tool for the DomAPI: The Animation Array Generator, a visual tool for creating...</description>" + "<link>http://www.scottandrew.com/weblog/2002_06#a000395</link>" + "</item>" + "<item>" + "<title>DOM and Extended Entries</title>" + "<description>Aarondot: A Better Way To Display Extended Entries. Very cool, and uses the DOM and JavaScript to reveal the extended...</description>" + "<link>http://www.scottandrew.com/weblog/2002_06#a000373</link>" + "</item>" + "<item>" + "<title>cellspacing and the DOM</title>" + "<description>By the way, if you're using the DOM to generate TABLE elements, you have to use setAttribute() to set the...</description>" + "<link>http://www.scottandrew.com/weblog/2002_05#a000365</link>" + "</item>" + "<item>" + "<title>contenteditable for Mozilla</title>" + "<description>The folks art Q42, creator of Quek (cute little avatar/chat) and Xopus (browser-based WYSIWYG XML-editor) have released code that ,simulates...</description>" + "<link>http://www.scottandrew.com/weblog/2002_05#a000361</link>" + "</item>" "</channel>" "</rss>"; + +const char *gv_cssbuf = + "rss " + "{ " + " display:block; " + " margin:10px; " + "} " + " " + "channel " + "{ " + " display:block; " + " /*height:300px;*/ " + " width:200px; " + " border:1px solid #000; " + " overflow:auto; " + " background-color:#eee; " + " /*font: 12px verdana;*/ " + " font-style: font-family ; " + " font-style: normal; " + "} " + " " + "item " + "{ " + " width: 100%; " + " display: block; " + " padding:10px; " + " margin-bottom:10px; " + " border:1px solid #ccc; " + " /*border-top:1px solid #ccc; " + " border-bottom:1px solid #ccc; " + " border-left:1px solid #ccc; " + " border-right:1px solid #ccc; " + " */ " + " background-color:#fff; " + "} " + " " + " " + "channel>title, channel>description " + "{ " + " display: block; " + " width: 100%; " + " /*margin-left:10px;*/ " + " /*margin-top:10px;*/ " + " background-color:#eee; " + " font-weight:bold; " + " font-size: 12px; " + "} " + " " + "channel>title " + "{ " + " font-size:16px; " + "} " + " " + "channel>description " + "{ " + " display: block ; " + " font-size:10px; " + " margin-bottom:10px; " + "} " + " " + "item>title " + "{ " + " font-weight:bold; " + "} " + " " + "item>link, channel>link, channel>language " + "{ " + " display: none; " + "} " + " "; static enum CRStatus -test_layout_box (void) ; + test_layout_box (void); static gboolean -delete_event_cb (GtkWidget *a_widget, GdkEvent *a_event, - gpointer *a_user_data) ; - +delete_event_cb (GtkWidget * a_widget, GdkEvent * a_event, + gpointer * a_user_data); static gboolean -delete_event_cb (GtkWidget *a_widget, GdkEvent *a_event, - gpointer *a_user_data) +delete_event_cb (GtkWidget * a_widget, GdkEvent * a_event, + gpointer * a_user_data) { - gtk_main_quit () ; - return FALSE ; + gtk_main_quit (); + return FALSE; } static enum CRStatus test_layout_box (void) { - CRBoxView *box_view = NULL ; - GtkWidget *window = NULL, *scroll = NULL ; + CRBoxView *box_view = NULL; + GtkWidget *window = NULL, + *scroll = NULL; - box_view = cr_box_view_new_from_xml_css_bufs - (gv_xmlbuf, gv_cssbuf) ; - g_return_val_if_fail (box_view, CR_BAD_PARAM_ERROR) ; + box_view = cr_box_view_new_from_xml_css_bufs (gv_xmlbuf, gv_cssbuf); + g_return_val_if_fail (box_view, CR_BAD_PARAM_ERROR); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL) ; - g_return_val_if_fail (window, CR_BAD_PARAM_ERROR) ; + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_return_val_if_fail (window, CR_BAD_PARAM_ERROR); - gtk_window_set_title (GTK_WINDOW (window), - "Croco Renderer Test") ; - gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, TRUE) ; - gtk_widget_set_size_request (window, 800, 600) ; + gtk_window_set_title (GTK_WINDOW (window), "Croco Renderer Test"); + gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, TRUE); + gtk_widget_set_size_request (window, 800, 600); g_signal_connect (G_OBJECT (window), - "delete-event", - G_CALLBACK (delete_event_cb), - NULL) ; + "delete-event", G_CALLBACK (delete_event_cb), NULL); - scroll = gtk_scrolled_window_new (NULL, NULL) ; - g_return_val_if_fail (scroll, CR_BAD_PARAM_ERROR) ; + scroll = gtk_scrolled_window_new (NULL, NULL); + g_return_val_if_fail (scroll, CR_BAD_PARAM_ERROR); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_ALWAYS, - GTK_POLICY_ALWAYS) ; - gtk_container_add (GTK_CONTAINER (window), scroll) ; - gtk_container_add - (GTK_CONTAINER (scroll), - GTK_WIDGET (box_view)) ; - gtk_widget_show_all (window) ; - gtk_main () ; - - return CR_OK ; -} - + GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS); + gtk_container_add (GTK_CONTAINER (window), scroll); + gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (box_view)); + gtk_widget_show_all (window); + gtk_main (); + return CR_OK; +} int main (int argc, char **argv) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - cr_lay_eng_init (argc, argv) ; + cr_lay_eng_init (argc, argv); - status = test_layout_box () ; + status = test_layout_box (); - if (status != CR_OK) - { - g_print ("\nKO\n") ; - } - return 0 ; + if (status != CR_OK) { + g_print ("\nKO\n"); + } + return 0; } |