2012-12-10 Paul Koning <paul_koning@dell.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-parameter.exp
CommitLineData
c5a57081 1# Copyright (C) 2010-2012 Free Software Foundation, Inc.
99e7ae30
DE
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
b521dba8
DE
16# This file is part of the GDB testsuite.
17# It tests gdb.parameter and gdb.Parameter.
99e7ae30 18
99e7ae30
DE
19load_lib gdb-python.exp
20
21# Start with a fresh gdb.
22gdb_exit
23gdb_start
24gdb_reinitialize_dir $srcdir/$subdir
25
26# Skip all tests if Python scripting is not enabled.
27if { [skip_python_tests] } { continue }
28
29# We use "." here instead of ":" so that this works on win32 too.
9325cb04 30gdb_test "python print (gdb.parameter ('directories'))" "$srcdir/$subdir.\\\$cdir.\\\$cwd"
b521dba8
DE
31
32# Test a simple boolean parameter.
33gdb_py_test_multiple "Simple gdb booleanparameter" \
34 "python" "" \
35 "class TestParam (gdb.Parameter):" "" \
36 " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \
ecec24e6
PM
37 " show_doc = \"Show the state of the boolean test-param\"" ""\
38 " set_doc = \"Set the state of the boolean test-param\"" "" \
39 " def get_show_string (self, pvalue):" ""\
40 " return \"The state of the Test Parameter is \" + pvalue" ""\
41 " def get_set_string (self):" ""\
42 " val = \"on\"" ""\
43 " if (self.value == False):" ""\
44 " val = \"off\"" ""\
45 " return \"Test Parameter has been set to \" + val" ""\
b521dba8
DE
46 " def __init__ (self, name):" "" \
47 " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
48 " self.value = True" "" \
49 "test_param = TestParam ('print test-param')" ""\
50 "end"
51
9325cb04 52gdb_test "python print (test_param.value)" "True" "Test parameter value"
ecec24e6
PM
53gdb_test "show print test-param" "The state of the Test Parameter is on.*" "Show parameter on"
54gdb_test "set print test-param off" "Test Parameter has been set to off" "Turn off parameter"
55gdb_test "show print test-param" "The state of the Test Parameter is off.*" "Show parameter off"
9325cb04 56gdb_test "python print (test_param.value)" "False" "Test parameter value"
ecec24e6
PM
57gdb_test "help show print test-param" "Show the state of the boolean test-param.*" "Test show help"
58gdb_test "help set print test-param" "Set the state of the boolean test-param.*" "Test set help"
59gdb_test "help set print" "set print test-param -- Set the state of the boolean test-param.*" "Test general help"
60
b521dba8
DE
61
62# Test an enum parameter.
63gdb_py_test_multiple "enum gdb parameter" \
64 "python" "" \
65 "class TestEnumParam (gdb.Parameter):" "" \
66 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
67 " show_doc = \"Show the state of the enum\"" ""\
68 " set_doc = \"Set the state of the enum\"" "" \
ecec24e6
PM
69 " def get_show_string (self, pvalue):" ""\
70 " return \"The state of the enum is \" + pvalue" ""\
71 " def get_set_string (self):" ""\
72 " return \"The state of the enum has been set to \" + self.value" ""\
b521dba8
DE
73 " def __init__ (self, name):" "" \
74 " super (TestEnumParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_ENUM, \[\"one\", \"two\"\])" "" \
75 " self.value = \"one\"" "" \
76 "test_enum_param = TestEnumParam ('print test-enum-param')" ""\
77 "end"
78
9325cb04 79gdb_test "python print (test_enum_param.value)" "one" "Test enum parameter value"
ecec24e6
PM
80gdb_test "show print test-enum-param" "The state of the enum is one.*" "Show parameter is initial value"
81gdb_test "set print test-enum-param two" "The state of the enum has been set to two" "Set enum to two"
82gdb_test "show print test-enum-param" "The state of the enum is two.*" "Show parameter is new value"
9325cb04 83gdb_test "python print (test_enum_param.value)" "two" "Test enum parameter value"
b521dba8
DE
84gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "Set invalid enum parameter"
85
86# Test a file parameter.
87gdb_py_test_multiple "file gdb parameter" \
88 "python" "" \
89 "class TestFileParam (gdb.Parameter):" "" \
90 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
91 " show_doc = \"Show the name of the file\"" ""\
92 " set_doc = \"Set the name of the file\"" "" \
ecec24e6
PM
93 " def get_show_string (self, pvalue):" ""\
94 " return \"The name of the file is \" + pvalue" ""\
95 " def get_set_string (self):" ""\
96 " return \"The name of the file has been changed to \" + self.value" ""\
b521dba8
DE
97 " def __init__ (self, name):" "" \
98 " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \
99 " self.value = \"foo.txt\"" "" \
100 "test_file_param = TestFileParam ('test-file-param')" ""\
101 "end"
102
9325cb04 103gdb_test "python print (test_file_param.value)" "foo.txt" "Test file parameter value"
ecec24e6
PM
104gdb_test "show test-file-param" "The name of the file is foo.txt.*" "Show initial file value"
105gdb_test "set test-file-param bar.txt" "The name of the file has been changed to bar.txt" "Set new file parameter" 1
106gdb_test "show test-file-param" "The name of the file is bar.txt.*" "Show new file value"
9325cb04 107gdb_test "python print (test_file_param.value)" "bar.txt" "Test new file parameter value"
b521dba8
DE
108gdb_test "set test-file-param" "Argument required.*"
109
ecec24e6
PM
110# Test a parameter that is not documented.
111gdb_py_test_multiple "Simple gdb booleanparameter" \
b521dba8 112 "python" "" \
ecec24e6
PM
113 "class TestUndocParam (gdb.Parameter):" "" \
114 " def get_show_string (self, pvalue):" ""\
115 " return \"The state of the Test Parameter is \" + pvalue" ""\
116 " def get_set_string (self):" ""\
117 " val = \"on\"" ""\
118 " if (self.value == False):" ""\
119 " val = \"off\"" ""\
120 " return \"Test Parameter has been set to \" + val" ""\
b521dba8 121 " def __init__ (self, name):" "" \
ecec24e6
PM
122 " super (TestUndocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
123 " self.value = True" "" \
124 "test_undoc_param = TestUndocParam ('print test-undoc-param')" ""\
b521dba8
DE
125 "end"
126
ecec24e6
PM
127gdb_test "show print test-undoc-param" "The state of the Test Parameter is on.*" "Show parameter on"
128gdb_test "set print test-undoc-param off" "Test Parameter has been set to off" "Turn off parameter"
129gdb_test "show print test-undoc-param" "The state of the Test Parameter is off.*" "Show parameter off"
9325cb04 130gdb_test "python print (test_undoc_param.value)" "False" "Test parameter value"
ecec24e6
PM
131gdb_test "help show print test-undoc-param" "This command is not documented.*" "Test show help"
132gdb_test "help set print test-undoc-param" "This command is not documented.*" "Test set help"
133gdb_test "help set print" "set print test-undoc-param -- This command is not documented.*" "Test general help"
134
135# Test a parameter that is not documented in any way..
136gdb_py_test_multiple "Simple gdb booleanparameter" \
137 "python" "" \
138 "class TestNodocParam (gdb.Parameter):" "" \
139 " def __init__ (self, name):" "" \
140 " super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
141 " self.value = True" "" \
142 "test_nodoc_param = TestNodocParam ('print test-nodoc-param')" ""\
143 "end"
144
145gdb_test "show print test-nodoc-param" "This command is not documented.*" "Show parameter on"
146gdb_test "set print test-nodoc-param off" "This command is not documented.*" "Turn off parameter"
147gdb_test "show print test-nodoc-param" "This command is not documented.*.*" "Show parameter off"
9325cb04 148gdb_test "python print (test_nodoc_param.value)" "False" "Test parameter value"
ecec24e6
PM
149gdb_test "help show print test-nodoc-param" "This command is not documented.*" "Test show help"
150gdb_test "help set print test-nodoc-param" "This command is not documented.*" "Test set help"
151gdb_test "help set print" "set print test-nodoc-param -- This command is not documented.*" "Test general help"
152
153# Test deprecated API. Do not use in your own implementations.
154gdb_py_test_multiple "Simple gdb booleanparameter" \
155 "python" "" \
156 "class TestParam (gdb.Parameter):" "" \
157 " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \
158 " show_doc = \"State of the Test Parameter\"" ""\
159 " set_doc = \"Set the state of the Test Parameter\"" "" \
160 " def __init__ (self, name):" "" \
161 " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
162 " self.value = True" "" \
163 "test_param = TestParam ('print test-param')" ""\
164 "end"
165
9325cb04 166gdb_test "python print (test_param.value)" "True" "Test parameter value"
ecec24e6
PM
167gdb_test "show print test-param" "State of the Test Parameter on.*" "Show parameter on"
168gdb_test "set print test-param off" "Set the state of the Test Parameter.*" "Turn off parameter"
169gdb_test "show print test-param" "State of the Test Parameter off.*" "Show parameter off"
9325cb04 170gdb_test "python print (test_param.value)" "False" "Test parameter value"
ecec24e6
PM
171gdb_test "help show print test-param" "State of the Test Parameter.*" "Test show help"
172gdb_test "help set print test-param" "Set the state of the Test Parameter.*" "Test set help"
173gdb_test "help set print" "set print test-param -- Set the state of the Test Parameter.*" "Test general help"
This page took 0.267342 seconds and 4 git commands to generate.