1 # Copyright (C) 2010, 2011 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the GDB testsuite.
17 # It tests gdb.parameter and gdb.Parameter.
23 load_lib gdb-python.exp
25 # Start with a fresh gdb.
28 gdb_reinitialize_dir $srcdir/$subdir
30 # Skip all tests if Python scripting is not enabled.
31 if { [skip_python_tests] } { continue }
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"
36 # Test a simple boolean parameter.
37 gdb_py_test_multiple "Simple gdb booleanparameter" \
39 "class TestParam (gdb.Parameter):" "" \
40 " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \
41 " show_doc = \"Show the state of the boolean test-param\"" ""\
42 " set_doc = \"Set the state of the boolean test-param\"" "" \
43 " def get_show_string (self, pvalue):" ""\
44 " return \"The state of the Test Parameter is \" + pvalue" ""\
45 " def get_set_string (self):" ""\
47 " if (self.value == False):" ""\
49 " return \"Test Parameter has been set to \" + val" ""\
50 " def __init__ (self, name):" "" \
51 " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
52 " self.value = True" "" \
53 "test_param = TestParam ('print test-param')" ""\
56 gdb_test "python print test_param.value" "True" "Test parameter value"
57 gdb_test "show print test-param" "The state of the Test Parameter is on.*" "Show parameter on"
58 gdb_test "set print test-param off" "Test Parameter has been set to off" "Turn off parameter"
59 gdb_test "show print test-param" "The state of the Test Parameter is off.*" "Show parameter off"
60 gdb_test "python print test_param.value" "False" "Test parameter value"
61 gdb_test "help show print test-param" "Show the state of the boolean test-param.*" "Test show help"
62 gdb_test "help set print test-param" "Set the state of the boolean test-param.*" "Test set help"
63 gdb_test "help set print" "set print test-param -- Set the state of the boolean test-param.*" "Test general help"
66 # Test an enum parameter.
67 gdb_py_test_multiple "enum gdb parameter" \
69 "class TestEnumParam (gdb.Parameter):" "" \
70 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
71 " show_doc = \"Show the state of the enum\"" ""\
72 " set_doc = \"Set the state of the enum\"" "" \
73 " def get_show_string (self, pvalue):" ""\
74 " return \"The state of the enum is \" + pvalue" ""\
75 " def get_set_string (self):" ""\
76 " return \"The state of the enum has been set to \" + self.value" ""\
77 " def __init__ (self, name):" "" \
78 " super (TestEnumParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_ENUM, \[\"one\", \"two\"\])" "" \
79 " self.value = \"one\"" "" \
80 "test_enum_param = TestEnumParam ('print test-enum-param')" ""\
83 gdb_test "python print test_enum_param.value" "one" "Test enum parameter value"
84 gdb_test "show print test-enum-param" "The state of the enum is one.*" "Show parameter is initial value"
85 gdb_test "set print test-enum-param two" "The state of the enum has been set to two" "Set enum to two"
86 gdb_test "show print test-enum-param" "The state of the enum is two.*" "Show parameter is new value"
87 gdb_test "python print test_enum_param.value" "two" "Test enum parameter value"
88 gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "Set invalid enum parameter"
90 # Test a file parameter.
91 gdb_py_test_multiple "file gdb parameter" \
93 "class TestFileParam (gdb.Parameter):" "" \
94 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
95 " show_doc = \"Show the name of the file\"" ""\
96 " set_doc = \"Set the name of the file\"" "" \
97 " def get_show_string (self, pvalue):" ""\
98 " return \"The name of the file is \" + pvalue" ""\
99 " def get_set_string (self):" ""\
100 " return \"The name of the file has been changed to \" + self.value" ""\
101 " def __init__ (self, name):" "" \
102 " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \
103 " self.value = \"foo.txt\"" "" \
104 "test_file_param = TestFileParam ('test-file-param')" ""\
107 gdb_test "python print test_file_param.value" "foo.txt" "Test file parameter value"
108 gdb_test "show test-file-param" "The name of the file is foo.txt.*" "Show initial file value"
109 gdb_test "set test-file-param bar.txt" "The name of the file has been changed to bar.txt" "Set new file parameter" 1
110 gdb_test "show test-file-param" "The name of the file is bar.txt.*" "Show new file value"
111 gdb_test "python print test_file_param.value" "bar.txt" "Test new file parameter value"
112 gdb_test "set test-file-param" "Argument required.*"
114 # Test a parameter that is not documented.
115 gdb_py_test_multiple "Simple gdb booleanparameter" \
117 "class TestUndocParam (gdb.Parameter):" "" \
118 " def get_show_string (self, pvalue):" ""\
119 " return \"The state of the Test Parameter is \" + pvalue" ""\
120 " def get_set_string (self):" ""\
122 " if (self.value == False):" ""\
124 " return \"Test Parameter has been set to \" + val" ""\
125 " def __init__ (self, name):" "" \
126 " super (TestUndocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
127 " self.value = True" "" \
128 "test_undoc_param = TestUndocParam ('print test-undoc-param')" ""\
131 gdb_test "show print test-undoc-param" "The state of the Test Parameter is on.*" "Show parameter on"
132 gdb_test "set print test-undoc-param off" "Test Parameter has been set to off" "Turn off parameter"
133 gdb_test "show print test-undoc-param" "The state of the Test Parameter is off.*" "Show parameter off"
134 gdb_test "python print test_undoc_param.value" "False" "Test parameter value"
135 gdb_test "help show print test-undoc-param" "This command is not documented.*" "Test show help"
136 gdb_test "help set print test-undoc-param" "This command is not documented.*" "Test set help"
137 gdb_test "help set print" "set print test-undoc-param -- This command is not documented.*" "Test general help"
139 # Test a parameter that is not documented in any way..
140 gdb_py_test_multiple "Simple gdb booleanparameter" \
142 "class TestNodocParam (gdb.Parameter):" "" \
143 " def __init__ (self, name):" "" \
144 " super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
145 " self.value = True" "" \
146 "test_nodoc_param = TestNodocParam ('print test-nodoc-param')" ""\
149 gdb_test "show print test-nodoc-param" "This command is not documented.*" "Show parameter on"
150 gdb_test "set print test-nodoc-param off" "This command is not documented.*" "Turn off parameter"
151 gdb_test "show print test-nodoc-param" "This command is not documented.*.*" "Show parameter off"
152 gdb_test "python print test_nodoc_param.value" "False" "Test parameter value"
153 gdb_test "help show print test-nodoc-param" "This command is not documented.*" "Test show help"
154 gdb_test "help set print test-nodoc-param" "This command is not documented.*" "Test set help"
155 gdb_test "help set print" "set print test-nodoc-param -- This command is not documented.*" "Test general help"
157 # Test deprecated API. Do not use in your own implementations.
158 gdb_py_test_multiple "Simple gdb booleanparameter" \
160 "class TestParam (gdb.Parameter):" "" \
161 " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \
162 " show_doc = \"State of the Test Parameter\"" ""\
163 " set_doc = \"Set the state of the Test Parameter\"" "" \
164 " def __init__ (self, name):" "" \
165 " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
166 " self.value = True" "" \
167 "test_param = TestParam ('print test-param')" ""\
170 gdb_test "python print test_param.value" "True" "Test parameter value"
171 gdb_test "show print test-param" "State of the Test Parameter on.*" "Show parameter on"
172 gdb_test "set print test-param off" "Set the state of the Test Parameter.*" "Turn off parameter"
173 gdb_test "show print test-param" "State of the Test Parameter off.*" "Show parameter off"
174 gdb_test "python print test_param.value" "False" "Test parameter value"
175 gdb_test "help show print test-param" "State of the Test Parameter.*" "Test show help"
176 gdb_test "help set print test-param" "Set the state of the Test Parameter.*" "Test set help"
177 gdb_test "help set print" "set print test-param -- Set the state of the Test Parameter.*" "Test general help"