summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@seketeli.org>2003-06-19 20:55:30 +0000
committerDodji Seketeli <dodji@src.gnome.org>2003-06-19 20:55:30 +0000
commit97f56f0bfd289fdd3bd586ea13ed93517f8a6d9e (patch)
tree8c95b3d8e86fa6f3861ba779ad4349e8063196d3
parent127628a4ae11a60cbf609ae1396345190f9d1129 (diff)
downloadlibcroco-97f56f0bfd289fdd3bd586ea13ed93517f8a6d9e.tar.gz
updated this to test cr_statement_parse_from_buf(). It seems to work now.
2003-06-19 Dodji Seketeli <dodji@seketeli.org> * tests/test4-main.[ch]: updated this to test cr_statement_parse_from_buf(). It seems to work now. Still some memleaks to fix. * src/parser/cr-statement.[ch]: some bug fixes in cr_statement_parse_from_buf() + added a new cr_statement_at_import_rule_parse_from_buf() method. Dodji.
-rw-r--r--ChangeLog10
-rw-r--r--TODO8
-rw-r--r--src/parser/cr-statement.c137
-rw-r--r--src/parser/cr-statement.h4
-rw-r--r--tests/test4-main.c104
5 files changed, 242 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index d536551..5f766e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2003-06-19 Dodji Seketeli <dodji@seketeli.org>
+
+ * tests/test4-main.[ch]: updated this to test
+ cr_statement_parse_from_buf(). It seems to work now.
+ Still some memleaks to fix.
+
+ * src/parser/cr-statement.[ch]:
+ some bug fixes in cr_statement_parse_from_buf() +
+ added a new cr_statement_at_import_rule_parse_from_buf() method.
+
2003-06-18 Dodji Seketeli <dodji@seketeli.org>
* src/parser/cr-statement.[ch]:
diff --git a/TODO b/TODO
index 7214f34..9b801de 100644
--- a/TODO
+++ b/TODO
@@ -1,10 +1,12 @@
*coding:)
-Code a cr_statement_at_import_rule_parse () function and
-include it support in cr_statement_parse_from_buf ().
+Well, in the cr_statement_xxx_parse_functions, memleaks
+occur (the parsing result set in the sac callback is not freed)
+when a parsing fails. This is because I haven't implemented
+the "error" SAC callbacks yet. I must do it !!!
-Code a test case for cr_statement_parse_from_buf ().
+More debug of the test case for cr_statement_parse_from_buf ().
Provide support for font selection. (hard, started, is well underway.)
First make sure to be able to gather all the font related property
diff --git a/src/parser/cr-statement.c b/src/parser/cr-statement.c
index ce1ea56..947ea4c 100644
--- a/src/parser/cr-statement.c
+++ b/src/parser/cr-statement.c
@@ -794,39 +794,64 @@ cr_statement_parse_from_buf (const guchar *a_buf,
if (!result)
{
result = cr_statement_at_charset_rule_parse_from_buf
- (a_buf, a_encoding) ;
- if (result)
- goto out ;
+ (a_buf, a_encoding) ;
}
+ else
+ {
+ goto out ;
+ }
+
if (!result)
{
result = cr_statement_at_media_rule_parse_from_buf
(a_buf, a_encoding) ;
- if (result)
- goto out ;
}
+ else
+ {
+ goto out ;
+ }
+
if (!result)
{
result = cr_statement_at_charset_rule_parse_from_buf
(a_buf, a_encoding) ;
- if (result)
- goto out ;
}
+ else
+ {
+ goto out ;
+ }
+
if (!result)
{
result = cr_statement_font_face_rule_parse_from_buf
(a_buf, a_encoding) ;
- if (result)
- goto out ;
+
}
+ else
+ {
+ goto out ;
+ }
+
if (!result)
{
result = cr_statement_at_page_rule_parse_from_buf
(a_buf, a_encoding) ;
- if (result)
- goto out ;
}
-
+ else
+ {
+ goto out ;
+ }
+
+ if (!result)
+ {
+ result = cr_statement_at_import_rule_parse_from_buf
+ (a_buf, a_encoding) ;
+ }
+ else
+ {
+ goto out ;
+ }
+
out:
return result ;
}
@@ -865,8 +890,12 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf,
cr_parser_set_sac_handler (parser, sac_handler) ;
cr_parser_try_to_skip_spaces_and_comments (parser) ;
- cr_parser_parse_ruleset (parser) ;
-
+ status = cr_parser_parse_ruleset (parser) ;
+ if (status != CR_OK)
+ {
+ goto cleanup ;
+ }
+
status = cr_doc_handler_get_result (sac_handler,
(gpointer*)&result) ;
if (! ((status == CR_OK) && result) )
@@ -878,7 +907,7 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf,
}
}
-/* cleanup:*/
+ cleanup:
if (parser)
{
cr_parser_destroy (parser) ;
@@ -1120,8 +1149,6 @@ cr_statement_new_at_import_rule (CRStyleSheet *a_container_sheet,
{
CRStatement *result = NULL ;
- g_return_val_if_fail (a_container_sheet, NULL) ;
-
result = g_try_malloc (sizeof (CRStatement)) ;
if (!result)
@@ -1147,12 +1174,86 @@ cr_statement_new_at_import_rule (CRStyleSheet *a_container_sheet,
result->kind.import_rule->url = a_url;
result->kind.import_rule->media_list = a_media_list ;
result->kind.import_rule->sheet = a_imported_sheet;
- cr_statement_set_parent_sheet (result, a_container_sheet) ;
+ if (a_container_sheet)
+ cr_statement_set_parent_sheet (result, a_container_sheet) ;
return result ;
}
/**
+ *Parses a buffer that contains an "@import" rule and
+ *instanciate a #CRStatement of type AT_IMPORT_RULE_STMT
+ *@param a_buf the buffer to parse.
+ *@param a_encoding the encoding of a_buf.
+ *@return the newly built instance of #CRStatement in case of
+ *a successfull parsing, NULL otherwise.
+ */
+CRStatement *
+cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf,
+ enum CREncoding a_encoding)
+{
+ enum CRStatus status = CR_OK ;
+ CRParser *parser = NULL ;
+ CRStatement *result = NULL ;
+ GList *media_list = NULL ;
+ GString *import_string = NULL ;
+
+ parser = cr_parser_new_from_buf (a_buf, strlen (a_buf),
+ a_encoding, FALSE) ;
+ if (!parser)
+ {
+ cr_utils_trace_info ("Instanciation of parser failed.") ;
+ goto cleanup ;
+ }
+
+ status = cr_parser_try_to_skip_spaces_and_comments (parser) ;
+ if (status != CR_OK)
+ goto cleanup ;
+
+ status = cr_parser_parse_import (parser, &media_list,
+ &import_string) ;
+ if (status != CR_OK || !import_string)
+ goto cleanup ;
+
+ result = cr_statement_new_at_import_rule (NULL, import_string,
+ media_list, NULL) ;
+ if (result)
+ {
+ import_string = NULL ;
+ media_list = NULL ;
+ }
+
+ cleanup:
+ if (parser)
+ {
+ cr_parser_destroy (parser) ;
+ parser = NULL ;
+ }
+ if (media_list)
+ {
+ GList *cur = NULL ;
+ for (cur = media_list; media_list;
+ media_list = g_list_next (media_list))
+ {
+ if (media_list->data)
+ {
+ g_string_free (media_list->data, TRUE);
+ media_list->data = NULL ;
+ }
+ }
+ g_list_free (media_list) ;
+ media_list = NULL;
+ }
+ if (import_string)
+ {
+ g_string_free (import_string, TRUE) ;
+ import_string = NULL;
+ }
+
+ return result ;
+}
+
+/**
*Creates a new instance of #CRStatement of type
*#CRAtPageRule.
*@param a_decl_list a list of instances of #CRDeclarations
diff --git a/src/parser/cr-statement.h b/src/parser/cr-statement.h
index e293235..eccb927 100644
--- a/src/parser/cr-statement.h
+++ b/src/parser/cr-statement.h
@@ -252,6 +252,10 @@ cr_statement_new_at_import_rule (CRStyleSheet *a_container_sheet,
CRStyleSheet *a_imported_sheet) ;
CRStatement *
+cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf,
+ enum CREncoding a_encoding) ;
+
+CRStatement *
cr_statement_new_at_media_rule (CRStyleSheet *a_sheet,
CRStatement *a_ruleset,
GList *a_media) ;
diff --git a/tests/test4-main.c b/tests/test4-main.c
index 414455a..4dc7ca4 100644
--- a/tests/test4-main.c
+++ b/tests/test4-main.c
@@ -63,6 +63,10 @@ const guchar *gv_at_font_face_buf=
"}"
;
+const guchar *gv_at_import_buf=
+"@import \"subs.css\";"
+;
+
static void
display_help (char *prg_name) ;
@@ -257,6 +261,92 @@ test_cr_statement_font_face_rule_parse_from_buf (void)
return CR_OK ;
}
+static enum CRStatus
+test_cr_statement_at_import_rule_parse_from_buf (void)
+{
+ 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 ;
+ }
+
+ 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 ;
+}
+
/**
*The entry point of the testing routine.
*/
@@ -308,6 +398,20 @@ main (int argc, char ** argv)
return 0 ;
}
+ test_cr_statement_at_import_rule_parse_from_buf () ;
+ if (status != CR_OK)
+ {
+ g_print ("\nKO\n") ;
+ return 0 ;
+ }
+
+ status = test_cr_statement_parse_from_buf () ;
+ if (status != CR_OK)
+ {
+ g_print ("\nKO\n") ;
+ return 0 ;
+ }
+
cr_test_utils_parse_cmd_line (argc, argv, &options) ;
if (options.display_help == TRUE)