]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-parameter.exp
* configure.ac: Move comment to remove extra space in last argument
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-parameter.exp
1 # Copyright (C) 2010 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # This file is part of the GDB testsuite.
17 # It tests gdb.parameter and gdb.Parameter.
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23 load_lib gdb-python.exp
24
25 # Start with a fresh gdb.
26 gdb_exit
27 gdb_start
28 gdb_reinitialize_dir $srcdir/$subdir
29
30 # Skip all tests if Python scripting is not enabled.
31 if { [skip_python_tests] } { continue }
32
33 # We use "." here instead of ":" so that this works on win32 too.
34 gdb_test "python print gdb.parameter ('directories')" "$srcdir/$subdir.\\\$cdir.\\\$cwd"
35
36 # Test a simple boolean parameter.
37 gdb_py_test_multiple "Simple gdb booleanparameter" \
38 "python" "" \
39 "class TestParam (gdb.Parameter):" "" \
40 " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \
41 " show_doc = \"Show whether the state of the Test Parameter does something useful\"" ""\
42 " set_doc = \"Set whether the state of the Test Parameter does something useful\"" "" \
43 " def __init__ (self, name):" "" \
44 " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
45 " self.value = True" "" \
46 "test_param = TestParam ('print test-param')" ""\
47 "end"
48
49 gdb_test "python print test_param.value" "True" "Test parameter value"
50 gdb_test "show print test-param" "Whether the state of the Test Parameter does something useful is on.*" "Show parameter on"
51 gdb_py_test_silent_cmd "set print test-param off" "Turn off parameter" 1
52 gdb_test "show print test-param" "Whether the state of the Test Parameter does something useful is off.*" "Show parameter off"
53 gdb_test "python print test_param.value" "False" "Test parameter value"
54 gdb_test "help show print test-param" "Show whether the state of the Test Parameter does something useful.*" "Test show help"
55 gdb_test "help set print test-param" "Set whether the state of the Test Parameter does something useful.*" "Test set help"
56 gdb_test "help set print" "set print test-param -- Set whether the state of the Test Parameter.*" "Test general help"
57
58 # Test an enum parameter.
59 gdb_py_test_multiple "enum gdb parameter" \
60 "python" "" \
61 "class TestEnumParam (gdb.Parameter):" "" \
62 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
63 " show_doc = \"Show the state of the enum\"" ""\
64 " set_doc = \"Set the state of the enum\"" "" \
65 " def __init__ (self, name):" "" \
66 " super (TestEnumParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_ENUM, \[\"one\", \"two\"\])" "" \
67 " self.value = \"one\"" "" \
68 "test_enum_param = TestEnumParam ('print test-enum-param')" ""\
69 "end"
70
71 gdb_test "python print test_enum_param.value" "one" "Test enum parameter value"
72 gdb_test "show print test-enum-param" "The state of the enum is \"one\".*" "Show parameter is initial value"
73 gdb_py_test_silent_cmd "set print test-enum-param two" "Set parameter to enum value" 1
74 gdb_test "show print test-enum-param" "The state of the enum is \"two\".*" "Show parameter is new value"
75 gdb_test "python print test_enum_param.value" "two" "Test enum parameter value"
76 gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "Set invalid enum parameter"
77
78 # Test a file parameter.
79 gdb_py_test_multiple "file gdb parameter" \
80 "python" "" \
81 "class TestFileParam (gdb.Parameter):" "" \
82 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
83 " show_doc = \"Show the name of the file\"" ""\
84 " set_doc = \"Set the name of the file\"" "" \
85 " def __init__ (self, name):" "" \
86 " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \
87 " self.value = \"foo.txt\"" "" \
88 "test_file_param = TestFileParam ('test-file-param')" ""\
89 "end"
90
91 gdb_test "python print test_file_param.value" "foo.txt" "Test file parameter value"
92 gdb_test "show test-file-param" "The name of the file is \"foo.txt\".*" "Show initial file value"
93 gdb_py_test_silent_cmd "set test-file-param bar.txt" "Set new file parameter" 1
94 gdb_test "show test-file-param" "The name of the file is \"bar.txt\".*" "Show new file value"
95 gdb_test "python print test_file_param.value" "bar.txt" "Test new file parameter value"
96 gdb_test "set test-file-param" "Argument required.*"
97
98 # Test a file parameter.
99 gdb_py_test_multiple "file gdb parameter" \
100 "python" "" \
101 "class TestFileParam (gdb.Parameter):" "" \
102 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
103 " show_doc = \"Show the name of the file\"" ""\
104 " set_doc = \"Set the name of the file\"" "" \
105 " def __init__ (self, name):" "" \
106 " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \
107 " self.value = \"foo.txt\"" "" \
108 "test_file_param = TestFileParam ('test-file-param')" ""\
109 "end"
110
111 gdb_test "python print test_file_param.value" "foo.txt" "Test parameter value"
112 gdb_test "show test-file-param" "The name of the file is \"foo.txt\".*" "Show parameter on"
113 gdb_py_test_silent_cmd "set test-file-param bar.txt" "Turn off parameter" 1
114 gdb_test "show test-file-param" "The name of the file is \"bar.txt\".*" "Show parameter on"
115 gdb_test "python print test_file_param.value" "bar.txt" "Test parameter value"
116 gdb_test "set test-file-param" "Argument required.*"