4
#include <glib/gstring.h>
5
#include <gtk/gtkmain.h>
6
#include <gtk/gtkscrolledwindow.h>
7
#include <gtk/gtkwindow.h>
10
#include "htmlclueflow.h"
11
#include "htmlcluev.h"
12
#include "htmlcursor.h"
13
#include "htmlgdkpainter.h"
14
#include "htmlengine.h"
15
#include "htmlengine-edit.h"
16
#include "htmlengine-edit-cut-and-paste.h"
17
#include "htmlengine-edit-movement.h"
18
#include "htmlengine-edit-text.h"
19
#include "htmlengine-save.h"
20
#include "htmlplainpainter.h"
21
#include "htmlselection.h"
22
#include "htmltable.h"
23
#include "htmltablecell.h"
28
int (*test_function) (GtkHTML *html);
31
static int test_level_1 (GtkHTML *html);
33
static Test tests[] = {
34
{ "cursor movement", NULL },
35
{ "level 1 - cut/copy/paste", test_level_1 },
39
static HTMLGdkPainter *gdk_painter = NULL;
40
static HTMLGdkPainter *plain_painter = NULL;
43
set_format (GtkHTML *html, gboolean format_html)
45
HTMLGdkPainter *p, *old_p;
47
gtk_widget_ensure_style (GTK_WIDGET (html));
50
gdk_painter = HTML_GDK_PAINTER (html->engine->painter);
51
plain_painter = HTML_GDK_PAINTER (html_plain_painter_new (GTK_WIDGET (html), TRUE));
53
g_object_ref (G_OBJECT (gdk_painter));
59
old_p = plain_painter;
65
if (html->engine->painter != (HTMLPainter *) p) {
66
html_gdk_painter_unrealize (old_p);
67
if (html->engine->window)
68
html_gdk_painter_realize (p, html->engine->window);
70
html_font_manager_set_default (&HTML_PAINTER (p)->font_manager,
71
HTML_PAINTER (old_p)->font_manager.variable.face,
72
HTML_PAINTER (old_p)->font_manager.fixed.face,
73
HTML_PAINTER (old_p)->font_manager.var_size,
74
HTML_PAINTER (old_p)->font_manager.var_points,
75
HTML_PAINTER (old_p)->font_manager.fix_size,
76
HTML_PAINTER (old_p)->font_manager.fix_points);
78
html_engine_set_painter (html->engine, HTML_PAINTER (p));
79
html_engine_schedule_redraw (html->engine);
84
static int test_level_1 (GtkHTML *html)
88
set_format (html, FALSE);
92
for (i = 0; i < 200; i ++) {
93
int j, len = 1 + (int) (10.0*rand()/(RAND_MAX+1.0));
96
for (j = 0; j < len; j ++)
97
word [j] = 'a' + (int) (26.0*rand()/(RAND_MAX+1.0));
100
total_len += len + 1;
102
html_engine_insert_text (html->engine, word, -1);
105
while (html_cursor_backward (html->engine->cursor, html->engine))
108
if (html->engine->cursor->position != 0 || html->engine->cursor->offset != 0)
111
for (i = 0; i < 1000; i ++) {
112
int j, new_pos, pos, len;
114
len = 1 + (int) (120.0*rand()/(RAND_MAX+1.0));
115
pos = MAX (0, (int) (((double) (total_len - len))*rand()/(RAND_MAX+1.0)));
117
printf ("step: %d pos: %d len: %d\n", i, pos, len);
119
switch ((int) (10.0*rand()/(RAND_MAX+1.0))) {
122
printf ("cut'n'paste\n");
123
html_cursor_jump_to_position (html->engine->cursor, html->engine, pos);
124
html_engine_set_mark (html->engine);
125
html_cursor_jump_to_position (html->engine->cursor, html->engine, pos + len);
126
html_engine_cut (html->engine);
128
new_pos = (int) (((double) (total_len - len))*rand()/(RAND_MAX+1.0));
130
html_cursor_jump_to_position (html->engine->cursor, html->engine, new_pos);
131
html_engine_paste (html->engine);
135
printf ("insert text\n");
136
html_cursor_jump_to_position (html->engine->cursor, html->engine, pos);
137
for (j = 0; j < len; j ++) {
138
int et = (int) (10.0*rand()/(RAND_MAX+1.0));
140
gtk_html_command (html, "insert-tab");
147
ch [0] = 'a' + (int) (26.0*rand()/(RAND_MAX+1.0));
149
html_engine_insert_text (html->engine, ch, 1);
156
printf ("delete text\n");
157
html_cursor_jump_to_position (html->engine->cursor, html->engine, pos + len);
158
for (j = 0; j < len; j++) {
159
gtk_html_command (html, "delete");
166
for (j = 0; j < len; j ++) {
167
html_engine_undo (html->engine);
173
for (j = 0; j < len; j ++) {
174
html_engine_redo (html->engine);
178
/* cut'n'quoted paste */
179
printf ("cut'n'quoted paste\n");
180
html_cursor_jump_to_position (html->engine->cursor, html->engine, pos);
181
html_engine_set_mark (html->engine);
182
html_cursor_jump_to_position (html->engine->cursor, html->engine, pos + len);
185
new_pos = (int) (((double) (total_len - len))*rand()/(RAND_MAX+1.0));
187
html_cursor_jump_to_position (html->engine->cursor, html->engine, new_pos);
188
gtk_html_paste (html, TRUE);
193
for (j = 0; j < 5*len; j ++) {
194
html_cursor_left (html->engine->cursor, html->engine);
200
for (j = 0; j < 5*len; j ++) {
201
html_cursor_right (html->engine->cursor, html->engine);
206
printf ("beginning of line\n");
207
html_cursor_beginning_of_line (html->engine->cursor, html->engine);
211
printf ("end of line\n");
212
html_cursor_end_of_line (html->engine->cursor, html->engine);
216
html_engine_thaw_idle_flush (html->engine);
218
while (html_cursor_backward (html->engine->cursor, html->engine))
220
if (html->engine->cursor->position != 0 || html->engine->cursor->offset != 0)
224
while (html_cursor_backward (html->engine->cursor, html->engine))
227
if (html->engine->cursor->position != 0 || html->engine->cursor->offset != 0)
233
int main (int argc, char *argv[])
235
GtkWidget *win, *html_widget, *sw;
237
int i = 0, n_all, n_successful;
242
gtk_init (&argc, &argv);
244
html_widget = gtk_html_new ();
245
html = GTK_HTML (html_widget);
246
gtk_html_load_empty (html);
247
gtk_html_set_editable (html, TRUE);
248
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
249
sw = gtk_scrolled_window_new (NULL, NULL);
250
gtk_widget_set_size_request (win, 600, 400);
251
gtk_container_add (GTK_CONTAINER (sw), html_widget);
252
gtk_container_add (GTK_CONTAINER (win), sw);
254
gtk_widget_show_all (win);
255
gtk_widget_show_now (win);
257
n_all = n_successful = 0;
259
fprintf (stderr, "\nGtkHTML test suite\n");
260
fprintf (stderr, "--------------------------------------------------------------------------------\n");
261
for (i = 0; tests [i].name; i ++) {
264
if (tests [i].test_function) {
265
fprintf (stderr, " %s ", tests [i].name);
266
for (j = strlen (tests [i].name); j < 69; j ++)
268
result = (*tests [i].test_function) (html);
269
fprintf (stderr, " %s\n", result ? "passed" : "failed");
275
fprintf (stderr, "* %s\n", tests [i].name);
279
fprintf (stderr, "--------------------------------------------------------------------------------\n");
280
fprintf (stderr, "%d tests failed %d tests passed (of %d tests)\n\n", n_all - n_successful, n_successful, n_all);
284
return n_all != n_successful;