summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.gdbtk/console.test
blob: 41e79465cd29e572e1d21e9082a372c3e4f4103b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
#   Copyright (C) 1998, 1999, 2002 Red Hat, Inc.
#
# 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.

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

# This file was written by Keith Seitz (keiths@cygnus.com)

# Read in the standard defs file

if {![gdbtk_read_defs]} {
  break
}

global objdir test_ran
global console text
set console [ManagedWin::open Console]
set text [$console test set _twin]

#####                            #####
#                                    #
#  Helper functions for this module  #
#                                    #
#####                            #####

# console_command --
#      Invoke STRING as a command in the console window and
#      return the result
proc console_command {string} { 
  global console text

  # Save current position
  set line [lindex [split [$text index cmdmark] .] 0]
  incr line 1

  # Insert and invoke command
  $text insert end $string
  $console invoke
  update

  # Get the result
  set end [lindex [split [$text index cmdmark] .] 0]
  incr end -1
  return [$text get $line.0 [list $end.0 lineend]]
} 

# get_cmd_line --
#     Return the command line
proc get_cmd_line {} {
  global text

  update
  set index [$text index cmdmark]
  return [$text get [list $index linestart] [list $index lineend]]
}

# clear_command_line --
#     Clear the command line
proc clear_command_line {} {
  global text
  $text delete {cmdmark + 1 char} insert
}

#####         #####
#                 #
#  CONSOLE TESTS  #
#                 #
#####         #####

#
# Miscellaneous tests
#

# Test:  console-misc-1
# Desc:  Change console prompt
gdbtk_test console-misc-1 {change console prompt} {
  # Insert the "set prompt" command into the text widget
  console_command {set prompt (test) }

  $text get {cmdmark linestart} {cmdmark lineend}
} {(test) }
if {$test_ran} {
  console_command {set prompt (gdb) }
}

#
# Paste tests
#

# Test:  console-paste-1
# Desc:  Paste the X selection into console window
gdbtk_test console-paste-1 {paste X text} {
  # This is cheesy, but it works... Create a text widget
  # which holds the current selection...
  text .test_text
  .test_text insert end "this is some pasted text"
  .test_text tag add sel 1.0 {1.0 lineend}
  event generate .test_text <<Copy>>
  event generate $text <<Paste>>
  get_cmd_line
} {(gdb) this is some pasted text}
if {$test_ran} {
  destroy .test_text
  clear_command_line
}

#
# Test for errors
#

# Test:  console-error-1
# Desc:  Check if console window reports internal gdb errors
gdbtk_test console-error-1 {invoke unknown command} {
  console_command {this_command_doesn't_exist}
} {Error: Undefined command: "this".  Try "help".
}

#
# History tests
#

# Test:  console-history-1.1
# Desc:  Exercise the up-history functionality
gdbtk_test console-history-1.1 {up history once} {
  # Add some commands into the command buffer
  console_command {show annotate}
  console_command {show complaints}
  console_command {show confirm}
  console_command {show height}
  console_command {show language}
  console_command {show print demangle}
  console_command {show remotebaud}
  console_command {show remotebreak}
  console_command {show remotecache}
  console_command {show remotedebug}
  console_command {show remotedevice}
  console_command {show remotelogbase}
  console_command {help quit}
  console_command {help si}
  # this doesn't seem to work reliably: event generate $text <Up>
  $console test _previous
  get_cmd_line
} {(gdb) help si}
if {$test_ran} {
  clear_command_line
}

# Test:  console-history-1.2
# Desc:  Exercise the up-history functionality
gdbtk_test console-history-1.2 {up history twice} {
  # Add some commands into the command buffer
  console_command {show annotate}
  console_command {show complaints}
  console_command {show confirm}
  console_command {show height}
  console_command {show language}
  console_command {show print demangle}
  console_command {show remotebaud}
  console_command {show remotebreak}
  console_command {show remotecache}
  console_command {show remotedebug}
  console_command {show remotedevice}
  console_command {show remotelogbase}
  console_command {help quit}
  console_command {help si}
  # this doesn't seem to work reliably: event generate $text <Up>
  # this doesn't seem to work reliably: event generate $text <Up>
  $console test _previous
  $console test _previous
  get_cmd_line
} {(gdb) help quit}
if {$test_ran} {
  clear_command_line
}

# Test:  console-history-1.3
# Desc:  Exercise the up-history functionality
gdbtk_test console-history-1.3 {up history four times} {
  # Add some commands into the command buffer
  console_command {show annotate}
  console_command {show complaints}
  console_command {show confirm}
  console_command {show height}
  console_command {show language}
  console_command {show print demangle}
  console_command {show remotebaud}
  console_command {show remotebreak}
  console_command {show remotecache}
  console_command {show remotedebug}
  console_command {show remotedevice}
  console_command {show remotelogbase}
  console_command {help quit}
  console_command {help si}

  for {set i 0} {$i < 4} {incr i} {
    # this doesn't seem to work reliably: event generate $text <Up>
    $console test _previous
  }
  get_cmd_line
} {(gdb) show remotedevice}
if {$test_ran} {
  clear_command_line
}

# Test:  console-history-1.4
# Desc:  Exercise the up-history functionality
gdbtk_test console-history-1.4 {up fourteen times} {
  # Add some commands into the command buffer
  console_command {show annotate}
  console_command {show complaints}
  console_command {show confirm}
  console_command {show height}
  console_command {show language}
  console_command {show print demangle}
  console_command {show remotebaud}
  console_command {show remotebreak}
  console_command {show remotecache}
  console_command {show remotedebug}
  console_command {show remotedevice}
  console_command {show remotelogbase}
  console_command {help quit}
  console_command {help si}
  for {set i 0} {$i < 14} {incr i} {
    # this doesn't seem to work reliably: event generate $text <Up>
    $console test _previous
  }
  get_cmd_line
} {(gdb) show annotate}
if {$test_ran} {
  clear_command_line
}

# Test:  console-history-1.5
# Desc:  Exercise the up-history search functionality
gdbtk_test console-history-1.5 {up search} {
 # Add some commands into the command buffer
  console_command {show height}
  console_command {show annotate}
  console_command {show complaints}
  console_command {print main}
  console_command {show remotelogbase}
  console_command {help quit}
  console_command {help si}

  $text insert end "sh"
  # this doesn't seem to work reliably: event generate $text <Shift-Up>
  # this doesn't seem to work reliably: event generate $text <Shift-Up>
  # this doesn't seem to work reliably: event generate $text <Shift-Up>
  $console test _search_history
  $console test _search_history
  $console test _search_history
  get_cmd_line
} {(gdb) show annotate}


# Test:  console-history-1.6
# Desc:  Exercise the down-history search functionality
gdbtk_test console-history-1.6 {down search} {
  # this doesn't seem to work reliably: event generate $text <Shift-Down>
  # this doesn't seem to work reliably: event generate $text <Shift-Down>
  $console test _rsearch_history
  $console test _rsearch_history
  get_cmd_line
} {(gdb) show remotelogbase}

# Test:  console-history-1.7
# Desc:  Down-history search to bottom
# We go back down until the original partialcommand is displayed
gdbtk_test console-history-1.7 {down search to bottom} {
  # this doesn't seem to work reliably: event generate $text <Shift-Down>
  # this doesn't seem to work reliably: event generate $text <Shift-Down>
  $console test _rsearch_history
  $console test _rsearch_history
  get_cmd_line
} {(gdb) sh}

# Test:  console-history-1.8
# Desc:  Up-history search to top
# We go up until there are no matches
gdbtk_test console-history-1.8 {up search to top} {
  for {set i 0} {$i < 100} {incr i} {
    # this doesn't seem to work reliably: event generate $text <Shift-Up>
    $console test _search_history
  }
  get_cmd_line
} {(gdb) show annotate}

if {$test_ran} {
  clear_command_line
}

# Test:  console-history-2.1
# Desc:  Exercise the down-history functionality
gdbtk_test console-history-2.1 {down once} {
  # Add some commands into the command buffer
  console_command {show annotate}
  console_command {show complaints}
  console_command {show confirm}
  console_command {show height}
  console_command {show language}
  console_command {show print demangle}
  console_command {show remotebaud}
  console_command {show remotebreak}
  console_command {show remotecache}
  console_command {show remotedebug}
  console_command {show remotedevice}
  console_command {show remotelogbase}
  console_command {help quit}
  console_command {help si}

  for {set i 0} {$i < 14} {incr i} {
    # this doesn't seem to work reliably: event generate $text <Up>
    $console test _previous
  }
  # this doesn't seem to work reliably: event generate $text <Down>
  $console test _next
  get_cmd_line
} {(gdb) show complaints}
if {$test_ran} {
  clear_command_line
}

# Test:  console-history-2.2
# Desc:  Exercise the down-history functionality
gdbtk_test console-history-2.2 {down twice} {
  # Add some commands into the command buffer
  console_command {show annotate}
  console_command {show complaints}
  console_command {show confirm}
  console_command {show height}
  console_command {show language}
  console_command {show print demangle}
  console_command {show remotebaud}
  console_command {show remotebreak}
  console_command {show remotecache}
  console_command {show remotedebug}
  console_command {show remotedevice}
  console_command {show remotelogbase}
  console_command {help quit}
  console_command {help si}

  for {set i 0} {$i < 14} {incr i} {
    # this doesn't seem to work reliably: event generate $text <Up>
    $console test _previous
  }

  # this doesn't seem to work reliably: event generate $text <Down>
  # this doesn't seem to work reliably: event generate $text <Down>
  $console test _next
  $console test _next
  get_cmd_line
} {(gdb) show confirm}
if {$test_ran} {
  clear_command_line
}

# Test:  console-history-2.3
# Desc:  Exercise the down-history functionality
gdbtk_test console-history-2.3 {down four times} {
  # Add some commands into the command buffer
  console_command {show annotate}
  console_command {show complaints}
  console_command {show confirm}
  console_command {show height}
  console_command {show language}
  console_command {show print demangle}
  console_command {show remotebaud}
  console_command {show remotebreak}
  console_command {show remotecache}
  console_command {show remotedebug}
  console_command {show remotedevice}
  console_command {show remotelogbase}
  console_command {help quit}
  console_command {help si}

  for {set i 0} {$i < 14} {incr i} {
    # this doesn't seem to work reliably: event generate $text <Up>
    $console test _previous
  }

  for {set i 0} {$i < 4} {incr i} {
    # this doesn't seem to work reliably: event generate $text <Down>
    $console test _next
  }
  get_cmd_line
} {(gdb) show language}
if {$test_ran} {
  clear_command_line
}

# Test:  console-history-2.4
# Desc:  Exercise the down-history functionality
gdbtk_test console-history-2.4 {down infinitely} {
  # Add some commands into the command buffer
  console_command {show annotate}
  console_command {show complaints}
  console_command {show confirm}
  console_command {show height}
  console_command {show language}
  console_command {show print demangle}
  console_command {show remotebaud}
  console_command {show remotebreak}
  console_command {show remotecache}
  console_command {show remotedebug}
  console_command {show remotedevice}
  console_command {show remotelogbase}
  console_command {help quit}
  console_command {help si}
  for {set i 0} {$i < 14} {incr i} {
    # this doesn't seem to work reliably: event generate $text <Up>
    $console test _previous
  }

  for {set i 0} {$i < 20} {incr i} {
    # this doesn't seem to work reliably: event generate $text <Down>
    $console test _next
  }
  get_cmd_line
} {(gdb) }
if {$test_ran} {
  clear_command_line
}

#
# gdb - gdbtk Interface Tests
#

# Test:  console-interface-1.1
# Desc:  Verify that a "file" command in the console window causes
#        gdb to invoke the pre-/post-add-symbol hooks
set file_loaded 0
gdbtk_test console-interface-1.1 {file command goes through hooks} {
  global TEST1_RESULT TEST2_RESULT

  # This is really ugly, but its the only way to do this...
  rename gdbtk_tcl_pre_add_symbol pre_add
  rename gdbtk_tcl_post_add_symbol post_add

  proc gdbtk_tcl_pre_add_symbol {file} {
    global TEST1_RESULT

    set TEST1_RESULT $file
    pre_add $file
  }
  proc gdbtk_tcl_post_add_symbol {} {
    global TEST2_RESULT

    set TEST2_RESULT ok
    post_add
  }

  # load a file and make sure we went through the pre/post_add_symbol hooks
  set TEST1_RESULT {}
  set TEST2_RESULT {}
  set file [file join $objdir simple]
  console_command "file $file"
  if {$TEST1_RESULT != $file} {
    set result "did not go through gdbtk_tcl_pre_add_symbol ($TEST1_RESULT)"
  } elseif {$TEST2_RESULT != "ok"} {
    set result "did not go through gdbtk_tcl_post_add_symbol"
  } else {
    set result {}
    set file_loaded 1
  }

  set result
} {}
if {$test_ran} {
  rename gdbtk_tcl_pre_add_symbol {}
  rename gdbtk_tcl_post_add_symbol {}
  rename pre_add gdbtk_tcl_pre_add_symbol
  rename post_add gdbtk_tcl_post_add_symbol
}

#
#  Exit
#
gdbtk_test_done