1#!@SH_PROG@
2# -*- shell-script -*-
3# Test breakpoint set, unset, enable, disable, clear
4test_breakpoint() {
5    # Some mock functions
6    _Dbg_errmsg() {
7	errmsgs+=("$@")
8    }
9    _Dbg_msg() {
10	msgs+=("$@")
11    }
12    _Dbg_adjust_filename() {
13	echo $*
14    }
15    _Dbg_expand_filename() {
16	echo $*
17    }
18
19    typeset -a msgs
20    msgs=()
21
22    # Test parameter count checking for _Dbg_set_brkpt
23    _Dbg_set_brkpt
24    assertNotEquals 'set breakpoint no parameters' '0' "$?"
25    _Dbg_set_brkpt 1 2 3 4 5
26    assertNotEquals 'set breakpoint too many parameter' '0' "$?"
27
28    # This should work
29    _Dbg_frame_last_lineno=5
30    _Dbg_set_brkpt test.sh 5 0
31    assertEquals 'simple set breakpoint' \
32	'Breakpoint 1 set in file test.sh, line 5.' "${msgs[0]}"
33    msgs=()
34
35    # Test parameter count checking for _Dbg_unset_brkpt
36    _Dbg_unset_brkpt
37    assertEquals 'unset_brkpt no params invalid' '0' "$?"
38    _Dbg_unset_brkpt 1 2 3
39    assertEquals '0' "$?"
40# FIXME
41#     # Shouldn't find this breakpoint
42#     _Dbg_unset_brkpt test.sh 6
43#     assertEquals '0' "$?"
44#     assertEquals 'No breakpoint found at test.sh:6' "${msgs[0]}"
45
46    msgs=()
47    # This should work and remove a breakpoint
48    _Dbg_unset_brkpt test.sh 5
49    assertEquals 'valid unset_brkpt' '1' "$?"
50    assertEquals '0' "${#msgs[@]}"
51
52# FIXME
53#     # This should not work since breakpoint has already been removed.
54#     _Dbg_unset_brkpt test.sh 5
55#     assertEquals '0' "$?"
56#     assertEquals 'No breakpoint found at test.sh:5' "${msgs[0]}"
57
58    msgs=(); errmsgs=()
59    # Enable/disable parameter checking
60    _Dbg_enable_disable_brkpt
61    assertEquals 'enable_disable_brkpt' '1' "$?"
62
63    # Enable a non-existent breakpoint
64    msgs=()
65    _Dbg_enable_disable_brkpt 1 'enabled' 1
66    assertEquals "enable_disable_brkpt enabled" \
67	"Breakpoint entry 1 doesn't exist, so nothing done." "${errmsgs[0]}"
68
69    msgs=(); errmsgs=()
70    # Add another breakpoint for testing
71    _Dbg_set_brkpt test.sh 6 1
72    assertEquals 'add 2nd breakpoint' \
73	'One-time breakpoint 2 set in file test.sh, line 6.' "${msgs[0]}"
74
75    msgs=(); errmsgs=()
76    _Dbg_enable_disable_brkpt 1 'enabled' 2
77    assertEquals 'redundant 2nd breakpoint enable' \
78	'Breakpoint entry 2 already enabled, so nothing done.' "${errmsgs[0]}"
79
80    msgs=(); errmsgs=()
81    _Dbg_enable_disable_brkpt 0 'enabled' 2
82    assertEquals 'Breakpoint entry 2 enabled.' "${msgs[0]}"
83
84    msgs=(); errmsgs=()
85    _Dbg_enable_disable_brkpt 1 'disabled' 2
86    assertEquals '0' "$?"
87    assertEquals 'Breakpoint entry 2 disabled.' "${msgs[0]}"
88
89    _Dbg_clear_all_brkpt
90}
91
92abs_top_srcdir=@abs_top_srcdir@
93# Make sure @abs_top_srcrdir@ has a trailing slash
94abs_top_srcdir=${abs_top_srcdir%%/}/
95. ${abs_top_srcdir}test/unit/helper.sh
96. $abs_top_srcdir/init/pre.sh
97. $abs_top_srcdir/lib/file.sh
98. $abs_top_srcdir/lib/fns.sh
99. $abs_top_srcdir/lib/journal.sh
100. $abs_top_srcdir/lib/break.sh
101. $abs_top_srcdir/lib/validate.sh
102set -- # reset $# so shunit2 doesn't get confused.
103[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
104