Commit | Line | Data |
---|---|---|
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 |
19 | load_lib gdb-python.exp |
20 | ||
21 | # Start with a fresh gdb. | |
22 | gdb_exit | |
23 | gdb_start | |
24 | gdb_reinitialize_dir $srcdir/$subdir | |
25 | ||
26 | # Skip all tests if Python scripting is not enabled. | |
27 | if { [skip_python_tests] } { continue } | |
28 | ||
29 | # We use "." here instead of ":" so that this works on win32 too. | |
30 | gdb_test "python print gdb.parameter ('directories')" "$srcdir/$subdir.\\\$cdir.\\\$cwd" | |
b521dba8 DE |
31 | |
32 | # Test a simple boolean parameter. | |
33 | gdb_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 | ||
52 | gdb_test "python print test_param.value" "True" "Test parameter value" | |
ecec24e6 PM |
53 | gdb_test "show print test-param" "The state of the Test Parameter is on.*" "Show parameter on" |
54 | gdb_test "set print test-param off" "Test Parameter has been set to off" "Turn off parameter" | |
55 | gdb_test "show print test-param" "The state of the Test Parameter is off.*" "Show parameter off" | |
b521dba8 | 56 | gdb_test "python print test_param.value" "False" "Test parameter value" |
ecec24e6 PM |
57 | gdb_test "help show print test-param" "Show the state of the boolean test-param.*" "Test show help" |
58 | gdb_test "help set print test-param" "Set the state of the boolean test-param.*" "Test set help" | |
59 | gdb_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. | |
63 | gdb_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 | ||
79 | gdb_test "python print test_enum_param.value" "one" "Test enum parameter value" | |
ecec24e6 PM |
80 | gdb_test "show print test-enum-param" "The state of the enum is one.*" "Show parameter is initial value" |
81 | gdb_test "set print test-enum-param two" "The state of the enum has been set to two" "Set enum to two" | |
82 | gdb_test "show print test-enum-param" "The state of the enum is two.*" "Show parameter is new value" | |
b521dba8 DE |
83 | gdb_test "python print test_enum_param.value" "two" "Test enum parameter value" |
84 | gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "Set invalid enum parameter" | |
85 | ||
86 | # Test a file parameter. | |
87 | gdb_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 | ||
103 | gdb_test "python print test_file_param.value" "foo.txt" "Test file parameter value" | |
ecec24e6 PM |
104 | gdb_test "show test-file-param" "The name of the file is foo.txt.*" "Show initial file value" |
105 | gdb_test "set test-file-param bar.txt" "The name of the file has been changed to bar.txt" "Set new file parameter" 1 | |
106 | gdb_test "show test-file-param" "The name of the file is bar.txt.*" "Show new file value" | |
b521dba8 DE |
107 | gdb_test "python print test_file_param.value" "bar.txt" "Test new file parameter value" |
108 | gdb_test "set test-file-param" "Argument required.*" | |
109 | ||
ecec24e6 PM |
110 | # Test a parameter that is not documented. |
111 | gdb_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 |
127 | gdb_test "show print test-undoc-param" "The state of the Test Parameter is on.*" "Show parameter on" |
128 | gdb_test "set print test-undoc-param off" "Test Parameter has been set to off" "Turn off parameter" | |
129 | gdb_test "show print test-undoc-param" "The state of the Test Parameter is off.*" "Show parameter off" | |
130 | gdb_test "python print test_undoc_param.value" "False" "Test parameter value" | |
131 | gdb_test "help show print test-undoc-param" "This command is not documented.*" "Test show help" | |
132 | gdb_test "help set print test-undoc-param" "This command is not documented.*" "Test set help" | |
133 | gdb_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.. | |
136 | gdb_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 | ||
145 | gdb_test "show print test-nodoc-param" "This command is not documented.*" "Show parameter on" | |
146 | gdb_test "set print test-nodoc-param off" "This command is not documented.*" "Turn off parameter" | |
147 | gdb_test "show print test-nodoc-param" "This command is not documented.*.*" "Show parameter off" | |
148 | gdb_test "python print test_nodoc_param.value" "False" "Test parameter value" | |
149 | gdb_test "help show print test-nodoc-param" "This command is not documented.*" "Test show help" | |
150 | gdb_test "help set print test-nodoc-param" "This command is not documented.*" "Test set help" | |
151 | gdb_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. | |
154 | gdb_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 | ||
166 | gdb_test "python print test_param.value" "True" "Test parameter value" | |
167 | gdb_test "show print test-param" "State of the Test Parameter on.*" "Show parameter on" | |
168 | gdb_test "set print test-param off" "Set the state of the Test Parameter.*" "Turn off parameter" | |
169 | gdb_test "show print test-param" "State of the Test Parameter off.*" "Show parameter off" | |
170 | gdb_test "python print test_param.value" "False" "Test parameter value" | |
171 | gdb_test "help show print test-param" "State of the Test Parameter.*" "Test show help" | |
172 | gdb_test "help set print test-param" "Set the state of the Test Parameter.*" "Test set help" | |
173 | gdb_test "help set print" "set print test-param -- Set the state of the Test Parameter.*" "Test general help" |