aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.python
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r--gdb/testsuite/gdb.python/py-color.exp100
-rw-r--r--gdb/testsuite/gdb.python/py-parameter.exp53
2 files changed, 153 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-color.exp b/gdb/testsuite/gdb.python/py-color.exp
new file mode 100644
index 0000000..eb62d7f
--- /dev/null
+++ b/gdb/testsuite/gdb.python/py-color.exp
@@ -0,0 +1,100 @@
+# Copyright (C) 2010-2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This file is part of the GDB testsuite.
+# It tests gdb.parameter and gdb.Parameter.
+
+load_lib gdb-python.exp
+
+require allow_python_tests
+
+# Start with a fresh gdb.
+clean_restart
+
+gdb_test_no_output "python print_color_attrs = lambda c: print (c, c.colorspace, c.is_none, c.is_indexed, c.is_direct)" \
+ "print_color_attrs helper"
+
+gdb_test_no_output "python c = gdb.Color ()" \
+ "create color without params"
+gdb_test "python print_color_attrs (c)" "none 0 True False False" \
+ "print attrs of a color without params"
+
+gdb_test_no_output "python c = gdb.Color ('green')" \
+ "create color from basic name string"
+gdb_test "python print_color_attrs (c)" "green 1 False True False" \
+ "print attrs of a basic color name"
+gdb_test "python print (c.index)" "2" \
+ "print index of a basic color name"
+
+gdb_test_no_output "python c = gdb.Color (2)" \
+ "create color from basic index"
+gdb_test "python print_color_attrs (c)" "green 1 False True False" \
+ "print attrs of a basic color"
+gdb_test "python print (c.index)" "2" \
+ "print index of a basic color"
+
+gdb_test_no_output "python c = gdb.Color (14)" \
+ "create color from integer 14"
+gdb_test "python print_color_attrs (c)" "14 2 False True False" \
+ "print attrs of an color 14"
+gdb_test "python print (c.index)" "14" \
+ "print index of color 14"
+
+gdb_test_no_output "python c = gdb.Color (2, gdb.COLORSPACE_ANSI_8COLOR)" \
+ "create color from basic index and ansi colorspace"
+gdb_test "python print_color_attrs (c)" "green 1 False True False" \
+ "print attrs of a basic color with ansi colorspace"
+gdb_test "python print (c.index)" "2" \
+ "print index of a basic color with ansi colorspace"
+
+gdb_test_no_output "python c = gdb.Color (2, gdb.COLORSPACE_XTERM_256COLOR)" \
+ "create color from basic index and xterm256 colorspace"
+gdb_test "python print_color_attrs (c)" "2 3 False True False" \
+ "print attrs of a basic color with xterm256 colorspace"
+gdb_test "python print (c.index)" "2" \
+ "print index of a basic color with xterm256 colorspace"
+
+gdb_test_no_output "python c = gdb.Color ((171, 205, 239), gdb.COLORSPACE_RGB_24BIT)" \
+ "create color from rgb components"
+gdb_test "python print_color_attrs (c)" "#ABCDEF 4 False False True" \
+ "print attrs of an RGB color"
+gdb_test "python print (c.components)" "\\(171, 205, 239\\)" \
+ "print components of an RGB color"
+
+gdb_test_no_output "python c = gdb.Color ('none')" \
+ "create color from string none"
+gdb_test "python print_color_attrs (c)" "none 0 True False False" \
+ "print attrs of a color none"
+
+gdb_test_no_output "python c = gdb.Color ('254')" \
+ "create color from string 254"
+gdb_test "python print_color_attrs (c)" "254 3 False True False" \
+ "print attrs of an color 254"
+gdb_test "python print (c.index)" "254" \
+ "print index of color 254"
+
+gdb_test_no_output "python c_none = gdb.Color ('none')" \
+ "save default color"
+gdb_test_no_output "python c_red = gdb.Color ('red')" \
+ "save blue color"
+gdb_test_no_output "python c_green = gdb.Color ('green')" \
+ "save yellow color"
+gdb_test [concat "python print (c_red.escape_sequence (True) + " \
+ "c_green.escape_sequence (False) + 'red on green' + " \
+ "c_none.escape_sequence (False) + ' red on default' + " \
+ "c_none.escape_sequence (True))"] \
+ "\033\\\[31m\033\\\[42mred on green\033\\\[49m red on default\033\\\[39m" \
+ "escape sequences"
+
diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp
index de524f4..74e4178 100644
--- a/gdb/testsuite/gdb.python/py-parameter.exp
+++ b/gdb/testsuite/gdb.python/py-parameter.exp
@@ -185,6 +185,58 @@ proc_with_prefix test_enum_parameter { } {
"Undefined item: \"three\".*" "set invalid enum parameter"
}
+# Test an color parameter.
+proc_with_prefix test_color_parameter { } {
+ global env
+ with_ansi_styling_terminal {
+ # This enables 256 colors support and disables colors approximation.
+ setenv TERM xterm-256color
+ setenv COLORTERM truecolor
+
+ clean_restart
+
+ gdb_test_multiline "color gdb parameter" \
+ "python" "" \
+ "class TestColorParam (gdb.Parameter):" "" \
+ " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
+ " show_doc = \"Show the state of the color\"" ""\
+ " set_doc = \"Set the state of the color\"" "" \
+ " def get_show_string (self, pvalue):" ""\
+ " return \"The state of the color is \" + str(pvalue)" ""\
+ " def get_set_string (self):" ""\
+ " return \"The state of the color has been set to \" + str(self.value)" ""\
+ " def __init__ (self, name):" "" \
+ " super (TestColorParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_COLOR)" "" \
+ " self.value = gdb.Color(\"green\")" "" \
+ "test_color_param = TestColorParam ('print test-color-param')" ""\
+ "end"
+
+ gdb_test "python print (test_color_param.value)" "green" \
+ "test color parameter value is green"
+ gdb_test "show print test-color-param" \
+ "The state of the color is green.*" \
+ "show parameter is initial value"
+ gdb_test "set print test-color-param 255" \
+ "The state of the color has been set to 255" "set color to 255"
+ gdb_test "show print test-color-param" \
+ "The state of the color is 255.*" "show parameter is new value"
+ gdb_test "python print (test_color_param.value)" "255" \
+ "test color parameter value is 255"
+ gdb_test_no_output "python test_color_param.value = gdb.Color(254)" \
+ "assign test_color_param.value to 254"
+ gdb_test "python print (test_color_param.value)" "254" \
+ "test color parameter value is integer"
+ gdb_test_no_output "python test_color_param.value = gdb.Color('#FED210')" \
+ "assign test_color_param.value to #FED210"
+ gdb_test "python print (test_color_param.value.components)" "\\(254, 210, 16\\)" \
+ "test color parameter components from RGB hex tripple value"
+ gdb_test "set print test-color-param 256" \
+ "integer 256 out of range.*" "set invalid color parameter"
+ gdb_test "python test_color_param.value = gdb.Color(256)" \
+ ".*Error occurred in Python: Palette color index 256 is out of range.*" "set invalid color value"
+ }
+}
+
# Test a file parameter.
proc_with_prefix test_file_parameter { } {
clean_restart
@@ -623,6 +675,7 @@ test_directories
test_data_directory
test_boolean_parameter
test_enum_parameter
+test_color_parameter
test_file_parameter
test_undocumented_parameter
test_really_undocumented_parameter