[gtk+/gtk-style-context] More css parsing tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-style-context] More css parsing tests
- Date: Fri, 19 Nov 2010 00:19:10 +0000 (UTC)
commit 04957c970899907507f06ab84df1fd6ad1b92341
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Nov 18 19:18:09 2010 -0500
More css parsing tests
gtk/tests/Makefile.am | 6 +-
gtk/tests/stylecontext.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++
gtk/tests/test.png | Bin 0 -> 3569 bytes
3 files changed, 112 insertions(+), 3 deletions(-)
---
diff --git a/gtk/tests/Makefile.am b/gtk/tests/Makefile.am
index 8b326c6..dda9727 100644
--- a/gtk/tests/Makefile.am
+++ b/gtk/tests/Makefile.am
@@ -50,8 +50,8 @@ floating_SOURCES = floating.c
floating_LDADD = $(progs_ldadd)
#TEST_PROGS += object
-object_SOURCES = object.c pixbuf-init.c
-object_LDADD = $(progs_ldadd)
+#object_SOURCES = object.c pixbuf-init.c
+#object_LDADD = $(progs_ldadd)
# this doesn't work in make distcheck, since running
# on a naked X server creates slightly different event
@@ -103,7 +103,7 @@ gtk_example_application_LDADD = $(progs_ldadd)
TEST_PROGS += stylecontext
stylecontext_SOURCES = stylecontext.c
stylecontext_LDADD = $(progs_ldadd)
-EXTRA_DIST += test.css
+EXTRA_DIST += test.css test.png
EXTRA_DIST += \
diff --git a/gtk/tests/stylecontext.c b/gtk/tests/stylecontext.c
index c2c20f4..8a53821 100644
--- a/gtk/tests/stylecontext.c
+++ b/gtk/tests/stylecontext.c
@@ -31,6 +31,18 @@ test_parse_at (void)
"@import url(\"test.css\");",
"@import url('test.css');",
"@import\nurl (\t\"test.css\" ) ;",
+ "@define-color bg_color #f9a039;",
+ "@define-color color @bg_color;",
+ "@define-color color rgb(100, 99, 88);",
+ "@define-color color rgba(50%, 50%, 50%, 0.5);",
+ "@define-color color lighter(#f9a039);",
+ "@define-color color darker ( @blue ) ;",
+ "@define-color color shade(@blue, 1.3);",
+ "@define-color color alpha(@blue, 1.3);",
+ "@define-color color mix(@blue, @red, 0.2);",
+ "@define-color color red;",
+ "@define-color color mix(shade (#121212, 0.5), mix (rgb(10%,20%,100%), @blue,0.5), 0.2);",
+ "@define-color blue @blue;",
NULL
};
@@ -41,6 +53,20 @@ test_parse_at (void)
"@import url(');",
"@import url(\"abc');",
"@ import ;",
+ "@define_color blue red;",
+ "@define-color blue #12234;",
+ "@define-color blue #12g234;",
+ "@define-color blue @@;",
+ "@define-color blue 5!#%4 DG$##x;",
+ "@define-color color mix(@red, @blue, @green);",
+ "@define-color color mix(@blue, 0.2, @red);",
+ "@define-color color mix(0.2, @blue, @red);",
+ "@define-color color mix(@blue, @red);",
+ "@define-color color mix(@blue);",
+ "@define-color color mix();",
+ "@define-color color rgba(50%, 50%, 50%);",
+ "@define-color color rgb(50%, a);",
+ "@three-dee { some other crap };",
NULL
};
@@ -104,6 +130,8 @@ test_parse_selectors (void)
"E:active:prelight {}",
"* > .notebook tab:first-child .label:focused {}",
"E, F {}",
+ "E, F /* comment here */ {}",
+ "E,/* comment here */ F {}",
NULL
};
@@ -147,6 +175,86 @@ test_parse_selectors (void)
}
}
+static void
+test_parse_declarations (void)
+{
+ GtkCssProvider *provider;
+ GError *error;
+ gboolean res;
+ gint i;
+ const gchar *valid[] = {
+ "* {}",
+ "* { font: Sans 15 }",
+ "* { font: Sans 15; }",
+ "* { font: bold }",
+ "* { color: red }",
+ "* { /* just a comment */ }",
+ "* { /* multi\nline\ncomment */ }",
+ "* { font: /* comment here */ Sans 15 }",
+ "* { color: red; background-color: shade (@bg_color, 0.5) }",
+ "* { margin: 5 }",
+ "* { margin: 5 10 }",
+ "* { margin: 5 10 3 }",
+ "* { margin: 5 10 3 5 }",
+ "* { padding: 5 }",
+ "* { padding: 5 10 }",
+ "* { border-width: 5; border-radius: 10 }",
+ "* { border-color: #ff00ff }",
+ "* { engine: clearlooks }",
+ "* { background-image: -gtk-gradient (linear, \n"
+ " left top, right top, \n"
+ " from (#fff), to (#000)) }",
+ "* { background-image: -gtk-gradient (linear, \n"
+ " 0.0 0.5, 0.5 1.0, \n"
+ " from (#fff), \n"
+ " color-stop (0.5, #f00),\n"
+ " to (#000)) }",
+ "* { background-image: -gtk-gradient (radial, \n"
+ " center center, 0.2, \n"
+ " center center, 0.8, \n"
+ " color-stop (0.0,#fff),\n"
+ " color-stop (1.0,#000))}\n",
+ "* { border-image: url (\"test.png\") 3 4 3 4 stretch }",
+ "* { border-image: url (\"test.png\") 3 4 3 4 repeat stretch}",
+ "* { transition: 150ms ease-in-out }",
+ "* { transition: 1s linear loop }",
+ NULL
+ };
+
+ const gchar *invalid[] = {
+ "* { color }",
+ "* { color:green; color }",
+ "* { color:red; color; color:green }",
+ "* { color:green; color: }",
+ "* { color:red; color:; color:green }",
+ "* { color:green; color{;color:maroon} }",
+ "* { color:red; color{;color:maroon}; color:green }",
+ "* { content: 'Hello",
+ NULL
+ };
+
+ error = NULL;
+ for (i = 0; valid[i]; i++)
+ {
+ provider = gtk_css_provider_new ();
+ res = gtk_css_provider_load_from_data (provider, valid[i], -1, &error);
+ g_assert_no_error (error);
+ g_assert (res);
+
+ g_object_unref (provider);
+ }
+
+ for (i = 0; invalid[i]; i++)
+ {
+ provider = gtk_css_provider_new ();
+ res = gtk_css_provider_load_from_data (provider, invalid[i], -1, &error);
+ g_assert_error (error, GTK_CSS_PROVIDER_ERROR, GTK_CSS_PROVIDER_ERROR_FAILED);
+ g_assert (!res);
+ g_object_unref (provider);
+ g_clear_error (&error);
+ }
+}
+
int
main (int argc, char *argv[])
{
@@ -156,6 +264,7 @@ main (int argc, char *argv[])
g_test_add_func ("/style/parse/empty", test_parse_empty);
g_test_add_func ("/style/parse/at", test_parse_at);
g_test_add_func ("/style/parse/selectors", test_parse_selectors);
+ g_test_add_func ("/style/parse/declarations", test_parse_declarations);
return g_test_run ();
}
diff --git a/gtk/tests/test.png b/gtk/tests/test.png
new file mode 100644
index 0000000..8d0f458
Binary files /dev/null and b/gtk/tests/test.png differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]