Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 * Description: ?Description
24 #undef G_DISABLE_ASSERT
34 #include <glib/gstdio.h>
37 #include "mrt2_glib2_test.h"
40 #define C2P(c) ((gpointer) ((long) (c)))
41 #define GINT_TO_POINTER(i) ((gpointer) (i))
42 #define GPOINTER_TO_INT(p) ((gint) (p))
47 void hash_func(gpointer key,gpointer value,gpointer user_data)
52 void err_func(GScanner* scanner,gchar* message, gboolean error)
54 char s[] = "unexpected string constant \"efgh\", expected number (float) - error";
55 g_assert(!strcmp(s,message));
60 void tg_scanner_tests()
64 const gint TOKEN_OPEN = G_TOKEN_LEFT_BRACE;
65 const gint TOKEN_CLOSE = G_TOKEN_RIGHT_BRACE;
66 const gint TOKEN_INT = G_TOKEN_INT;
67 const gint TOKEN_CH = G_TOKEN_STRING;
72 gchar* g_scanner_cur_value_str;
74 char* g_scanner_peek_next_token_str;
75 gchar ip_text[]="(30)";
78 scanner = g_scanner_new(NULL);
79 fd = g_open ("c:\scanfile.txt", O_RDONLY, 0);
80 g_scanner_input_file (scanner, fd);
81 scanner->config->symbol_2_token = TRUE;
82 scanner->msg_handler = err_func;
84 g_scanner_scope_add_symbol(scanner,0,"leftbrace",GUINT_TO_POINTER (TOKEN_OPEN));
85 g_scanner_scope_add_symbol(scanner,0,"rightbrace",GUINT_TO_POINTER (TOKEN_CLOSE));
86 g_scanner_scope_add_symbol(scanner,0,"intval",GUINT_TO_POINTER (TOKEN_INT));
87 g_scanner_scope_add_symbol(scanner,0,"strval",GUINT_TO_POINTER (TOKEN_CH));
91 token = g_scanner_get_next_token (scanner);
92 cur_pos = g_scanner_cur_position (scanner);
97 g_assert(g_scanner_cur_line(scanner) == 2); //g_scanner_cur_line test
98 g_assert(g_scanner_cur_position(scanner) == 11); //g_scanner_cur_position test
99 g_assert(g_scanner_cur_token (scanner) == G_TOKEN_STRING); //g_scanner_cur_token test
100 val = g_scanner_cur_value (scanner); //g_scanner_cur_value test
101 g_scanner_cur_value_str = val.v_string;
102 g_assert(!strcmp(g_scanner_cur_value_str,"efgh"));
103 g_assert(g_scanner_peek_next_token(scanner) == G_TOKEN_LEFT_BRACE); //g_scanner_peek_next_token test
104 g_assert(g_scanner_scope_lookup_symbol(scanner,0,"intval") == GUINT_TO_POINTER (TOKEN_INT)); //g_scanner_scope_lookup_symbol test
105 g_assert(g_scanner_lookup_symbol(scanner,"intval") == GUINT_TO_POINTER (TOKEN_INT)); //g_scanner_lookup_symbol test
106 g_assert(g_scanner_set_scope(scanner,14) == 0); //g_scanner_set_scope..set to 14
108 g_scanner_scope_remove_symbol(scanner,14,"leftbrace");
109 g_assert(g_scanner_lookup_symbol(scanner,"leftbrace") == NULL); //g_scanner_scope_remove_symbol test
111 g_scanner_scope_foreach_symbol(scanner,14,hash_func,GUINT_TO_POINTER(G_TOKEN_LEFT_PAREN));
112 g_assert(g_scanner_lookup_symbol(scanner,"intval") == NULL); //g_scanner_scope_foreach_symbol test
115 g_scanner_unexp_token(scanner,G_TOKEN_FLOAT,NULL,NULL,"float","error",err);
117 //Test for g_scanner_input_text
118 g_scanner_set_scope(scanner,0);
119 g_scanner_input_text(scanner,ip_text,strlen(ip_text));
122 token = g_scanner_get_next_token (scanner);
124 g_assert(g_scanner_cur_token (scanner) == G_TOKEN_RIGHT_PAREN); //g_scanner_input_text test
127 g_scanner_destroy (scanner);
133 int main (int argc,char *argv[])
138 g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
143 testResultXml("tscanner");
144 #endif /* EMULATOR */