diff options
author | Havoc Pennington <hp@pobox.com> | 2002-01-28 02:09:12 +0000 |
---|---|---|
committer | Havoc Pennington <hp@src.gnome.org> | 2002-01-28 02:09:12 +0000 |
commit | 8ddeb4f953148473978443f94e6cf14e2d078f1e (patch) | |
tree | 64ca1ae2994be237988171819e6f17bcc26c62a6 /src/theme-viewer.c | |
parent | 33dd196cba189d17ab67cdf6cb3aed702a82e60c (diff) | |
download | metacity-8ddeb4f953148473978443f94e6cf14e2d078f1e.tar.gz |
move in here so util.c doesn't require display.[hc]
2002-01-27 Havoc Pennington <hp@pobox.com>
* src/display.c (meta_set_syncing): move in here so util.c doesn't
require display.[hc]
* src/theme.h, src/theme.c: implement coordinate expression
parser, write MetaShapeSpec declaration
* src/util.c (meta_exit): move in here so we can link
to util.c with a different main()
* src/theme.h: rename the MetaWindow* enums to MetaFrame*
Diffstat (limited to 'src/theme-viewer.c')
-rw-r--r-- | src/theme-viewer.c | 247 |
1 files changed, 247 insertions, 0 deletions
diff --git a/src/theme-viewer.c b/src/theme-viewer.c new file mode 100644 index 00000000..59af1fdc --- /dev/null +++ b/src/theme-viewer.c @@ -0,0 +1,247 @@ +/* Metacity theme viewer and test app main() */ + +/* + * Copyright (C) 2002 Havoc Pennington + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#include <config.h> +#include "util.h" +#include "theme.h" +#include <gtk/gtk.h> + +static void run_position_expression_tests (void); + +int +main (int argc, char **argv) +{ + bindtextdomain (GETTEXT_PACKAGE, METACITY_LOCALEDIR); + + run_position_expression_tests (); + + return 0; +} + +typedef struct +{ + GdkRectangle rect; + const char *expr; + int expected_x; + int expected_y; + MetaPositionExprError expected_error; +} PositionExpressionTest; + +#define NO_ERROR -1 + +static const PositionExpressionTest position_expression_tests[] = { + /* Just numbers */ + { { 10, 20, 40, 50 }, + "10", 20, 30, NO_ERROR }, + { { 10, 20, 40, 50 }, + "14.37", 24, 34, NO_ERROR }, + /* Binary expressions with 2 ints */ + { { 10, 20, 40, 50 }, + "14 * 10", 150, 160, NO_ERROR }, + { { 10, 20, 40, 50 }, + "14 + 10", 34, 44, NO_ERROR }, + { { 10, 20, 40, 50 }, + "14 - 10", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "8 / 2", 14, 24, NO_ERROR }, + /* Binary expressions with floats and mixed float/ints */ + { { 10, 20, 40, 50 }, + "7.0 / 3.5", 12, 22, NO_ERROR }, + { { 10, 20, 40, 50 }, + "12.1 / 3", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "12 / 2.95", 14, 24, NO_ERROR }, + /* Binary expressions without whitespace after first number */ + { { 10, 20, 40, 50 }, + "14* 10", 150, 160, NO_ERROR }, + { { 10, 20, 40, 50 }, + "14+ 10", 34, 44, NO_ERROR }, + { { 10, 20, 40, 50 }, + "14- 10", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "8/ 2", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "7.0/ 3.5", 12, 22, NO_ERROR }, + { { 10, 20, 40, 50 }, + "12.1/ 3", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "12/ 2.95", 14, 24, NO_ERROR }, + /* Binary expressions without whitespace before second number */ + { { 10, 20, 40, 50 }, + "14 *10", 150, 160, NO_ERROR }, + { { 10, 20, 40, 50 }, + "14 +10", 34, 44, NO_ERROR }, + { { 10, 20, 40, 50 }, + "14 -10", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "8 /2", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "7.0 /3.5", 12, 22, NO_ERROR }, + { { 10, 20, 40, 50 }, + "12.1 /3", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "12 /2.95", 14, 24, NO_ERROR }, + /* Binary expressions without any whitespace */ + { { 10, 20, 40, 50 }, + "14*10", 150, 160, NO_ERROR }, + { { 10, 20, 40, 50 }, + "14+10", 34, 44, NO_ERROR }, + { { 10, 20, 40, 50 }, + "14-10", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "8/2", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "7.0/3.5", 12, 22, NO_ERROR }, + { { 10, 20, 40, 50 }, + "12.1/3", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "12/2.95", 14, 24, NO_ERROR }, + /* Binary expressions with parentheses */ + { { 10, 20, 40, 50 }, + "(14) * (10)", 150, 160, NO_ERROR }, + { { 10, 20, 40, 50 }, + "(14) + (10)", 34, 44, NO_ERROR }, + { { 10, 20, 40, 50 }, + "(14) - (10)", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "(8) / (2)", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "(7.0) / (3.5)", 12, 22, NO_ERROR }, + { { 10, 20, 40, 50 }, + "(12.1) / (3)", 14, 24, NO_ERROR }, + { { 10, 20, 40, 50 }, + "(12) / (2.95)", 14, 24, NO_ERROR }, + /* Lots of extra parentheses */ + { { 10, 20, 40, 50 }, + "(((14)) * ((10)))", 150, 160, NO_ERROR }, + { { 10, 20, 40, 50 }, + "((((14)))) + ((((((((10))))))))", 34, 44, NO_ERROR }, + { { 10, 20, 40, 50 }, + "((((((((((14 - 10))))))))))", 14, 24, NO_ERROR }, + /* Binary expressions with variables */ + { { 10, 20, 40, 50 }, + "2 * width", 90, 100, NO_ERROR }, + { { 10, 20, 40, 50 }, + "2 * height", 110, 120, NO_ERROR }, + { { 10, 20, 40, 50 }, + "width - 10", 40, 50, NO_ERROR }, + { { 10, 20, 40, 50 }, + "height / 2", 35, 45, NO_ERROR }, + /* More than two operands */ + { { 10, 20, 40, 50 }, + "8 / 2 + 5", 19, 29, NO_ERROR }, + { { 10, 20, 40, 50 }, + "8 * 2 + 5", 31, 41, NO_ERROR }, + { { 10, 20, 40, 50 }, + "8 + 2 * 5", 28, 38, NO_ERROR }, + { { 10, 20, 40, 50 }, + "8 + 8 / 2", 22, 32, NO_ERROR }, + { { 10, 20, 40, 50 }, + "14 / (2 + 5)", 12, 22, NO_ERROR }, + { { 10, 20, 40, 50 }, + "8 * (2 + 5)", 66, 76, NO_ERROR }, + { { 10, 20, 40, 50 }, + "(8 + 2) * 5", 60, 70, NO_ERROR }, + { { 10, 20, 40, 50 }, + "(8 + 8) / 2", 18, 28, NO_ERROR }, + /* Errors */ + { { 10, 20, 40, 50 }, + "2 * foo", 0, 0, META_POSITION_EXPR_ERROR_UNKNOWN_VARIABLE }, + { { 10, 20, 40, 50 }, + "2 *", 0, 0, META_POSITION_EXPR_ERROR_FAILED }, + { { 10, 20, 40, 50 }, + "- width", 0, 0, META_POSITION_EXPR_ERROR_FAILED }, + { { 10, 20, 40, 50 }, + "! * 2", 0, 0, META_POSITION_EXPR_ERROR_BAD_CHARACTER }, + { { 10, 20, 40, 50 }, + " ", 0, 0, META_POSITION_EXPR_ERROR_FAILED }, + { { 10, 20, 40, 50 }, + "() () (( ) ()) ((()))", 0, 0, META_POSITION_EXPR_ERROR_FAILED }, + { { 10, 20, 40, 50 }, + "(*) () ((/) ()) ((()))", 0, 0, META_POSITION_EXPR_ERROR_FAILED }, + { { 10, 20, 40, 50 }, + "2 * 5 /", 0, 0, META_POSITION_EXPR_ERROR_FAILED }, + { { 10, 20, 40, 50 }, + "+ 2 * 5", 0, 0, META_POSITION_EXPR_ERROR_FAILED }, + { { 10, 20, 40, 50 }, + "+ 2 * 5", 0, 0, META_POSITION_EXPR_ERROR_FAILED } +}; + +static void +run_position_expression_tests (void) +{ + int i; + + i = 0; + while (i < G_N_ELEMENTS (position_expression_tests)) + { + GError *err; + gboolean retval; + const PositionExpressionTest *test; + int x, y; + + test = &position_expression_tests[i]; + + if (g_getenv ("META_PRINT_TESTS") != NULL) + g_print ("Test expression: \"%s\" expecting x = %d y = %d", + test->expr, test->expected_x, test->expected_y); + + err = NULL; + + retval = meta_parse_position_expression (test->expr, + test->rect.x, + test->rect.y, + test->rect.width, + test->rect.height, + &x, &y, + &err); + + if (retval && err) + g_error ("position expression test returned TRUE but set error"); + if (!retval && err == NULL) + g_error ("position expression test returned FALSE but didn't set error"); + if (test->expected_error != NO_ERROR) + { + if (err == NULL) + g_error ("Error was expected but none given"); + if (err->code != test->expected_error) + g_error ("Error %d was expected but %d given", + test->expected_error, err->code); + } + else + { + if (err) + g_error ("Error not expected but one was returned: %s", + err->message); + + if (x != test->expected_x) + g_error ("x value was %d, %d was expected", x, test->expected_x); + + if (y != test->expected_y) + g_error ("y value was %d, %d was expected", y, test->expected_y); + } + + if (err) + g_error_free (err); + + ++i; + } +} |