OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [tests/] [canvText.test] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# This file is a Tcl script to test out the procedures in tkCanvText.c,
2
# which implement canvas "text" items.  It is organized in the standard
3
# fashion for Tcl tests.
4
#
5
# Copyright (c) 1996-1997 Sun Microsystems, Inc.
6
#
7
# See the file "license.terms" for information on usage and redistribution
8
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9
#
10
# RCS: @(#) $Id: canvText.test,v 1.1.1.1 2002-01-16 10:25:58 markom Exp $
11
 
12
if {"[info procs test]" != "test"} {
13
    source defs
14
}
15
 
16
foreach i [winfo children .] {
17
    destroy $i
18
}
19
wm geometry . {}
20
raise .
21
 
22
canvas .c -width 400 -height 300 -bd 2 -relief sunken
23
pack .c
24
update
25
 
26
set i 1
27
.c create text 20 20 -tag test
28
 
29
set font "-adobe-times-medium-r-normal--*-200-*-*-*-*-*-*"
30
set ay [font metrics $font -linespace]
31
set ax [font measure $font 0]
32
 
33
 
34
foreach test {
35
    {-anchor nw nw xyz {bad anchor position "xyz": must be n, ne, e, se, s, sw, w, nw, or center}}
36
    {-fill #ff0000 #ff0000 xyz {unknown color name "xyz"}}
37
    {-fill {} {} {} {}}
38
    {-font {Times 40} {Times 40} {} {font "" doesn't exist}}
39
    {-justify left left xyz {bad justification "xyz": must be left, right, or center}}
40
    {-stipple gray50 gray50 xyz {bitmap "xyz" not defined}}
41
    {-tags {test a b c} {test a b c} {} {}}
42
    {-text xyz xyz {} {}}
43
    {-width 6 6 xyz {bad screen distance "xyz"}}
44
} {
45
    set name [lindex $test 0]
46
    test canvText-1.$i {configuration options} {
47
        .c itemconfigure test $name [lindex $test 1]
48
        list [lindex [.c itemconfigure test $name] 4] [.c itemcget test $name]
49
    } [list [lindex $test 2] [lindex $test 2]]
50
    incr i
51
    if {[lindex $test 3] != ""} {
52
        test canvText-1.$i {configuration options} {
53
            list [catch {.c itemconfigure test $name [lindex $test 3]} msg] $msg
54
        } [list 1 [lindex $test 4]]
55
    }
56
    incr i
57
}
58
test canvText-1.$i {configuration options} {
59
    .c itemconfigure test -tags {test xyz}
60
    .c itemcget xyz -tags
61
} {test xyz}
62
 
63
.c delete test
64
.c create text 20 20 -tag test
65
 
66
test canvText-2.1 {CreateText procedure: args} {
67
    list [catch {.c create text} msg] $msg
68
} {1 {wrong # args: should be ".c create text x y ?options?"}}
69
test canvText-2.2 {CreateText procedure: args} {
70
    list [catch {.c create text xyz 0} msg] $msg
71
} {1 {bad screen distance "xyz"}}
72
test canvText-2.3 {CreateText procedure: args} {
73
    list [catch {.c create text 0 xyz} msg] $msg
74
} {1 {bad screen distance "xyz"}}
75
test canvText-2.4 {CreateText procedure: args} {
76
    list [catch {.c create text 0 0 -xyz xyz} msg] $msg
77
} {1 {unknown option "-xyz"}}
78
test canvText-2.5 {CreateText procedure} {
79
    .c create text 0 0 -tags x
80
    set x [.c coords x]
81
    .c delete x
82
    set x
83
} {0.0 0.0}
84
 
85
focus -force .c
86
.c focus test
87
.c coords test 0 0
88
update
89
 
90
test canvText-3.1 {TextCoords procedure} {
91
    .c coords test
92
} {0.0 0.0}
93
test canvText-3.2 {TextCoords procedure} {
94
    list [catch {.c coords test xyz 0} msg] $msg
95
} {1 {bad screen distance "xyz"}}
96
test canvText-3.3 {TextCoords procedure} {
97
    list [catch {.c coords test 0 xyz} msg] $msg
98
} {1 {bad screen distance "xyz"}}
99
test canvText-3.4 {TextCoords procedure} {
100
    .c coords test 10 10
101
    set result {}
102
    foreach element [.c coords test] {
103
        lappend result [format %.1f $element]
104
    }
105
    set result
106
} {10.0 10.0}
107
test canvText-3.5 {TextCoords procedure} {
108
    list [catch {.c coords test 10} msg] $msg
109
} {1 {wrong # coordinates: expected 0 or 2, got 1}}
110
test canvText-3.6 {TextCoords procedure} {
111
    list [catch {.c coords test 10 10 10} msg] $msg
112
} {1 {wrong # coordinates: expected 0 or 2, got 3}}
113
 
114
test canvText-4.1 {ConfigureText procedure} {
115
    list [catch {.c itemconfig test -fill xyz} msg] $msg
116
} {1 {unknown color name "xyz"}}
117
test canvText-4.2 {ConfigureText procedure} {
118
    .c itemconfig test -fill blue
119
    .c itemcget test -fill
120
} {blue}
121
test canvText-4.3 {ConfigureText procedure: construct font gcs} {
122
    .c itemconfig test -font "times 20" -fill black -stipple gray50
123
    list [.c itemcget test -font] [.c itemcget test -fill] [.c itemcget test -stipple]
124
} {{times 20} black gray50}
125
test canvText-4.4 {ConfigureText procedure: construct cursor gc} {
126
    .c itemconfig test -text "abcdefg"
127
    .c select from test 2
128
    .c select to test 4
129
    .c icursor test 3
130
 
131
    # Both black -> cursor becomes white.
132
    .c config -insertbackground black
133
    .c config -selectbackground black
134
    .c itemconfig test -just left
135
    update
136
 
137
    # Both same color (and not black) -> cursor becomes black.
138
    .c config -insertbackground red
139
    .c config -selectbackground red
140
    .c itemconfig test -just left
141
    update
142
} {}
143
test canvText-4.5 {ConfigureText procedure: adjust selection} {
144
    set x {}
145
    .c itemconfig test -text "abcdefghi"
146
    .c select from test 2
147
    .c select to test 6
148
    lappend x [selection get]
149
    .c dchars test 1 end
150
    lappend x [catch {selection get}]
151
    .c insert test end "bcdefghi"
152
    .c select from test 2
153
    .c select to test 6
154
    lappend x [selection get]
155
    .c dchars test 4 end
156
    lappend x [selection get]
157
    .c insert test end "efghi"
158
    .c select from test 6
159
    .c select to test 2
160
    lappend x [selection get]
161
    .c dchars test 4 end
162
    lappend x [selection get]
163
} {cdefg 1 cdefg cd cdef cd}
164
test canvText-4.6 {ConfigureText procedure: adjust cursor} {
165
    .c itemconfig test -text "abcdefghi"
166
    set x {}
167
    .c icursor test 6
168
    .c dchars test 4 end
169
    .c index test insert
170
} {4}
171
 
172
test canvText-5.1 {ConfigureText procedure: adjust cursor} {
173
    .c create text 10 10 -tag x -fill blue -font "times 40" -stipple gray50 -text "xyz"
174
    .c delete x
175
} {}
176
 
177
test canvText-6.1 {ComputeTextBbox procedure} {fonts} {
178
    .c itemconfig test -font $font -text 0
179
    .c coords test 0 0
180
    set x {}
181
    lappend x [.c itemconfig test -anchor n; .c bbox test]
182
    lappend x [.c itemconfig test -anchor nw; .c bbox test]
183
    lappend x [.c itemconfig test -anchor w; .c bbox test]
184
    lappend x [.c itemconfig test -anchor sw; .c bbox test]
185
    lappend x [.c itemconfig test -anchor s; .c bbox test]
186
    lappend x [.c itemconfig test -anchor se; .c bbox test]
187
    lappend x [.c itemconfig test -anchor e; .c bbox test]
188
    lappend x [.c itemconfig test -anchor ne; .c bbox test]
189
    lappend x [.c itemconfig test -anchor center; .c bbox test]
190
} "{[expr -$ax/2-1] 0 [expr $ax/2+1] $ay}\
191
{-1 0 [expr $ax+1] $ay}\
192
{-1 [expr -$ay/2] [expr $ax+1] [expr $ay/2]}\
193
{-1 -$ay [expr $ax+1] 0}\
194
{[expr -$ax/2-1] -$ay [expr $ax/2+1] 0}\
195
{[expr -$ax-1] -$ay 1 0}\
196
{[expr -$ax-1] [expr -$ay/2] 1 [expr $ay/2]}\
197
{[expr -$ax-1] 0 1 $ay}\
198
{[expr -$ax/2-1] [expr -$ay/2] [expr $ax/2+1] [expr $ay/2]}"
199
 
200
focus .c
201
.c focus test
202
.c itemconfig test -text "abcd\nefghi\njklmnopq"
203
test canvText-7.1 {DisplayText procedure: stippling} {
204
    .c itemconfig test -stipple gray50
205
    update
206
    .c itemconfig test -stipple {}
207
    update
208
} {}
209
test canvText-7.2 {DisplayText procedure: draw selection} {
210
    .c select from test 0
211
    .c select to test end
212
    update
213
    selection get
214
} "abcd\nefghi\njklmnopq"
215
test canvText-7.3 {DisplayText procedure: selection} {
216
    .c select from test 0
217
    .c select to test end
218
    update
219
    selection get
220
} "abcd\nefghi\njklmnopq"
221
test canvText-7.4 {DisplayText procedure: one line selection} {
222
    .c select from test 2
223
    .c select to test 3
224
    update
225
} {}
226
test canvText-7.5 {DisplayText procedure: multi-line selection} {
227
    .c select from test 2
228
    .c select to test 12
229
    update
230
} {}
231
test canvText-7.6 {DisplayText procedure: draw cursor} {
232
    .c icursor test 3
233
    update
234
} {}
235
test canvText-7.7 {DisplayText procedure: selected text different color} {
236
    .c config -selectforeground blue
237
    .c itemconfig test -anchor n
238
    update
239
} {}
240
test canvText-7.8 {DisplayText procedure: not selected} {
241
    .c select clear
242
    update
243
} {}
244
 
245
test canvText-8.1 {TextInsert procedure: 0 length insert} {
246
    .c insert test end {}
247
} {}
248
test canvText-8.2 {TextInsert procedure: before beginning/after end} {
249
    # Can't test this because GetTextIndex filters out those numbers.
250
} {}
251
test canvText-8.3 {TextInsert procedure: inserting in a selected item} {
252
    .c itemconfig test -text "abcdefg"
253
    .c select from test 2
254
    .c select to test 4
255
    .c insert test 1 "xyz"
256
    .c itemcget test -text
257
} {axyzbcdefg}
258
test canvText-8.4 {TextInsert procedure: inserting before selection} {
259
    .c itemconfig test -text "abcdefg"
260
    .c select from test 2
261
    .c select to test 4
262
    .c insert test 1 "xyz"
263
    list [.c index test sel.first] [.c index test sel.last]
264
} {5 7}
265
test canvText-8.5 {TextInsert procedure: inserting in selection} {
266
    .c itemconfig test -text "abcdefg"
267
    .c select from test 2
268
    .c select to test 4
269
    .c insert test 3 "xyz"
270
    list [.c index test sel.first] [.c index test sel.last]
271
} {2 7}
272
test canvText-8.6 {TextInsert procedure: inserting after selection} {
273
    .c itemconfig test -text "abcdefg"
274
    .c select from test 2
275
    .c select to test 4
276
    .c insert test 5 "xyz"
277
    list [.c index test sel.first] [.c index test sel.last]
278
} {2 4}
279
test canvText-8.7 {TextInsert procedure: inserting in unselected item} {
280
    .c itemconfig test -text "abcdefg"
281
    .c select clear
282
    .c insert test 5 "xyz"
283
    .c itemcget test -text
284
} {abcdexyzfg}
285
test canvText-8.8 {TextInsert procedure: inserting before cursor} {
286
    .c itemconfig test -text "abcdefg"
287
    .c icursor test 3
288
    .c insert test 2 "xyz"
289
    .c index test insert
290
} {6}
291
test canvText-8.9 {TextInsert procedure: inserting after cursor} {
292
    .c itemconfig test -text "abcdefg"
293
    .c icursor test 3
294
    .c insert test 4 "xyz"
295
    .c index test insert
296
} {3}
297
 
298
test canvText-9.1 {TextInsert procedure: before beginning/after end} {
299
    # Can't test this because GetTextIndex filters out those numbers.
300
} {}
301
test canvText-9.2 {TextInsert procedure: start > end} {
302
    .c itemconfig test -text "abcdefg"
303
    .c dchars test 4 2
304
    .c itemcget test -text
305
} {abcdefg}
306
test canvText-9.3 {TextInsert procedure: deleting from a selected item} {
307
    .c itemconfig test -text "abcdefg"
308
    .c select from test 2
309
    .c select to test 4
310
    .c dchars test 3 5
311
    .c itemcget test -text
312
} {abcg}
313
test canvText-9.4 {TextInsert procedure: deleting before start} {
314
    .c itemconfig test -text "abcdefghijk"
315
    .c select from test 4
316
    .c select to test 8
317
    .c dchars test 1 1
318
    list [.c index test sel.first] [.c index test sel.last]
319
} {3 7}
320
test canvText-9.5 {TextInsert procedure: keep start > first char deleted} {
321
    .c itemconfig test -text "abcdefghijk"
322
    .c select from test 4
323
    .c select to test 8
324
    .c dchars test 2 6
325
    list [.c index test sel.first] [.c index test sel.last]
326
} {2 3}
327
test canvText-9.6 {TextInsert procedure: deleting inside selection} {
328
    .c itemconfig test -text "abcdefghijk"
329
    .c select from test 4
330
    .c select to test 8
331
    .c dchars test 6 6
332
    list [.c index test sel.first] [.c index test sel.last]
333
} {4 7}
334
test canvText-9.7 {TextInsert procedure: keep end > first char deleted} {
335
    .c itemconfig test -text "abcdefghijk"
336
    .c select from test 4
337
    .c select to test 8
338
    .c dchars test 6 10
339
    list [.c index test sel.first] [.c index test sel.last]
340
} {4 5}
341
test canvText-9.8 {TextInsert procedure: selectFirst > selectLast: deselect} {
342
    .c itemconfig test -text "abcdefghijk"
343
    .c select from test 4
344
    .c select to test 8
345
    .c dchars test 3 10
346
    list [catch {.c index test sel.first} msg] $msg
347
} {1 {selection isn't in item}}
348
test canvText-9.9 {TextInsert procedure: selectFirst <= selectLast} {
349
    .c itemconfig test -text "abcdefghijk"
350
    .c select from test 4
351
    .c select to test 8
352
    .c dchars test 4 7
353
    list [.c index test sel.first] [.c index test sel.last]
354
} {4 4}
355
test canvText-9.10 {TextInsert procedure: move anchor} {
356
    .c itemconfig test -text "abcdefghijk"
357
    .c select from test 6
358
    .c select to test 8
359
    .c dchars test 2 4
360
    .c select to test 1
361
    list [.c index test sel.first] [.c index test sel.last]
362
} {1 2}
363
test canvText-9.11 {TextInsert procedure: keep anchor >= first} {
364
    .c itemconfig test -text "abcdefghijk"
365
    .c select from test 6
366
    .c select to test 8
367
    .c dchars test 5 7
368
    .c select to test 1
369
    list [.c index test sel.first] [.c index test sel.last]
370
} {1 4}
371
test canvText-9.12 {TextInsert procedure: anchor doesn't move} {
372
    .c itemconfig test -text "abcdefghijk"
373
    .c select from test 2
374
    .c select to test 5
375
    .c dchars test 6 8
376
    .c select to test 8
377
    list [.c index test sel.first] [.c index test sel.last]
378
} {2 8}
379
test canvText-9.13 {TextInsert procedure: move cursor} {
380
    .c itemconfig test -text "abcdefghijk"
381
    .c icursor test 6
382
    .c dchars test 2 4
383
    .c index test insert
384
} {3}
385
test canvText-9.14 {TextInsert procedure: keep cursor >= first} {
386
    .c itemconfig test -text "abcdefghijk"
387
    .c icursor test 6
388
    .c dchars test 2 10
389
    .c index test insert
390
} {2}
391
test canvText-9.15 {TextInsert procedure: cursor doesn't move} {
392
    .c itemconfig test -text "abcdefghijk"
393
    .c icursor test 5
394
    .c dchars test 7 9
395
    .c index test insert
396
} {5}
397
 
398
test canvText-10.1 {TextToPoint procedure} {
399
    .c coords test 0 0
400
    .c itemconfig test -text 0 -anchor center
401
    .c index test @0,0
402
} {0}
403
 
404
test canvText-11.1 {TextToArea procedure} {
405
    .c coords test 0 0
406
    .c itemconfig test -text 0 -anchor center
407
    .c find overlapping 0 0 1 1
408
} [.c find withtag test]
409
test canvText-11.2 {TextToArea procedure} {
410
    .c coords test 0 0
411
    .c itemconfig test -text 0 -anchor center
412
    .c find overlapping 1000 1000 1001 1001
413
} {}
414
 
415
test canvText-12.1 {ScaleText procedure} {
416
    .c coords test 100 100
417
    .c scale all 50 50 2 2
418
    .c coords test
419
} {150.0 150.0}
420
 
421
test canvText-13.1 {TranslateText procedure} {
422
    .c coords test 100 100
423
    .c move all 10 10
424
    .c coords test
425
} {110.0 110.0}
426
 
427
.c itemconfig test -text "abcdefghijklmno" -anchor nw
428
.c select from test 5
429
.c select to test 8
430
.c icursor test 12
431
.c coords test 0 0
432
test canvText-14.1 {GetTextIndex procedure} {
433
    list [.c index test end] [.c index test insert] \
434
        [.c index test sel.first] [.c index test sel.last] \
435
        [.c index test @0,0] \
436
        [.c index test -1] [.c index test 10] [.c index test 100]
437
} {15 12 5 8 0 0 10 15}
438
test canvText-14.2 {GetTextIndex procedure: select error} {
439
    .c select clear
440
    list [catch {.c index test sel.first} msg] $msg
441
} {1 {selection isn't in item}}
442
test canvText-14.3 {GetTextIndex procedure: select error} {
443
    .c select clear
444
    list [catch {.c index test sel.last} msg] $msg
445
} {1 {selection isn't in item}}
446
test canvText-14.4 {GetTextIndex procedure: select error} {
447
    .c select clear
448
    list [catch {.c index test sel.} msg] $msg
449
} {1 {bad index "sel."}}
450
test canvText-14.5 {GetTextIndex procedure: bad int or unknown index} {
451
    list [catch {.c index test xyz} msg] $msg
452
} {1 {bad index "xyz"}}
453
 
454
test canvText-15.1 {SetTextCursor procedure} {
455
    .c itemconfig -text "abcdefg"
456
    .c icursor test 3
457
    .c index test insert
458
} {3}
459
 
460
test canvText-16.1 {GetSelText procedure} {
461
    .c itemconfig test -text "abcdefghijklmno" -anchor nw
462
    .c select from test 5
463
    .c select to test 8
464
    selection get
465
} {fghi}
466
 
467
set font {Courier 12 italic}
468
set ax [font measure $font 0]
469
set ay [font metrics $font -linespace]
470
 
471
test canvText-17.1 {TextToPostscript procedure} {
472
    .c delete all
473
    .c config -height 300 -highlightthickness 0 -bd 0
474
    update
475
    .c create text 100 100 -tags test
476
    .c itemconfig test -font $font -text "00000000" -width [expr 3*$ax]
477
    .c itemconfig test -anchor n -fill black
478
    set x [.c postscript]
479
    set x [string range $x [string first "/Courier-Oblique" $x] end]
480
} "/Courier-Oblique findfont [font actual $font -size] scalefont ISOEncode setfont
481
0.000 0.000 0.000 setrgbcolor AdjustColor
482
100 200 \[
483
(000)
484
(000)
485
(00)
486
] $ay -0.5 0 0 false DrawText
487
grestore
488
restore showpage
489
 
490
%%Trailer
491
end
492
%%EOF
493
"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.