Commit | Line | Data |
---|---|---|
7b6bb8da | 1 | # Copyright (C) 2010, 2011 Free Software Foundation, Inc. |
0e3509db 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 | ||
16 | # This file is part of the GDB testsuite. | |
17 | # It tests the types.py module. | |
18 | ||
19 | if $tracelevel then { | |
20 | strace $tracelevel | |
21 | } | |
22 | ||
23 | load_lib gdb-python.exp | |
24 | ||
25 | set testfile "lib-types" | |
26 | set srcfile ${testfile}.cc | |
27 | set binfile ${objdir}/${subdir}/${testfile} | |
28 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { | |
29 | untested "Couldn't compile ${srcfile}" | |
30 | return -1 | |
31 | } | |
32 | ||
33 | # Start with a fresh gdb. | |
34 | gdb_exit | |
35 | gdb_start | |
36 | gdb_reinitialize_dir $srcdir/$subdir | |
37 | gdb_load ${binfile} | |
38 | ||
39 | # Skip all tests if Python scripting is not enabled. | |
40 | if { [skip_python_tests] } { continue } | |
41 | ||
42 | if ![runto_main] then { | |
43 | fail "Can't run to main" | |
44 | return 0 | |
45 | } | |
46 | ||
0e3509db DE |
47 | gdb_test_no_output "python import gdb.types" |
48 | ||
49 | # test get_basic_type const stripping | |
50 | gdb_test_no_output "python const_class1_obj = gdb.parse_and_eval ('const_class1_obj')" | |
51 | gdb_test_no_output "python basic_type_const_class1_obj = gdb.types.get_basic_type (const_class1_obj.type)" | |
52 | gdb_test "python print str (const_class1_obj.type)" "const class1" | |
53 | set test "const stripping" | |
54 | gdb_test_multiple "python print str (basic_type_const_class1_obj)" $test { | |
55 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
56 | pass $test | |
57 | } | |
58 | } | |
59 | ||
60 | # test get_basic_type volatile stripping | |
61 | gdb_test_no_output "python volatile_class1_obj = gdb.parse_and_eval ('volatile_class1_obj')" | |
62 | gdb_test_no_output "python basic_type_volatile_class1_obj = gdb.types.get_basic_type (volatile_class1_obj.type)" | |
63 | gdb_test "python print str (volatile_class1_obj.type)" "volatile class1" | |
64 | set test "volatile stripping" | |
65 | gdb_test_multiple "python print str (basic_type_volatile_class1_obj)" $test { | |
66 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
67 | pass $test | |
68 | } | |
69 | } | |
70 | ||
71 | # test get_basic_type volatile+const stripping | |
72 | gdb_test_no_output "python const_volatile_class1_obj = gdb.parse_and_eval ('const_volatile_class1_obj')" | |
73 | gdb_test_no_output "python basic_type_const_volatile_class1_obj = gdb.types.get_basic_type (const_volatile_class1_obj.type)" | |
74 | gdb_test "python print str (const_volatile_class1_obj.type)" "const volatile class1" | |
75 | set test "volatile+const stripping" | |
76 | gdb_test_multiple "python print str (basic_type_const_volatile_class1_obj)" $test { | |
77 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
78 | pass $test | |
79 | } | |
80 | } | |
81 | ||
82 | # test get_basic_type typedef stripping | |
83 | gdb_test_no_output "python typedef_class1_obj = gdb.parse_and_eval ('typedef_class1_obj')" | |
84 | gdb_test_no_output "python basic_type_typedef_class1_obj = gdb.types.get_basic_type (typedef_class1_obj.type)" | |
85 | gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1" | |
86 | set test "typedef stripping" | |
87 | gdb_test_multiple "python print str (basic_type_typedef_class1_obj)" $test { | |
88 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
89 | pass $test | |
90 | } | |
91 | } | |
92 | ||
93 | # test get_basic_type reference stripping | |
94 | gdb_test_no_output "python class1_ref_obj = gdb.parse_and_eval ('class1_ref_obj')" | |
95 | gdb_test_no_output "python basic_type_class1_ref_obj = gdb.types.get_basic_type (class1_ref_obj.type)" | |
96 | gdb_test "python print str (class1_ref_obj.type)" "class1 &" | |
97 | set test "reference stripping" | |
98 | gdb_test_multiple "python print str (basic_type_class1_ref_obj)" $test { | |
99 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
100 | pass $test | |
101 | } | |
102 | } | |
103 | ||
104 | # test nested typedef stripping | |
105 | gdb_test_no_output "python typedef_const_typedef_class1_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_obj')" | |
106 | gdb_test_no_output "python basic_type_typedef_const_typedef_class1_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_obj.type)" | |
107 | gdb_test "python print str (typedef_class1_obj.type)" "typedef_class1" | |
108 | set test "nested typedef stripping" | |
109 | gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_obj)" $test { | |
110 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
111 | pass $test | |
112 | } | |
113 | } | |
114 | ||
115 | # test nested typedef/reference stripping | |
116 | gdb_test_no_output "python typedef_const_typedef_class1_ref_obj = gdb.parse_and_eval ('typedef_const_typedef_class1_ref_obj')" | |
117 | gdb_test_no_output "python basic_type_typedef_const_typedef_class1_ref_obj = gdb.types.get_basic_type (typedef_const_typedef_class1_ref_obj.type)" | |
118 | gdb_test "python print str (typedef_const_typedef_class1_ref_obj.type)" "const typedef_const_typedef_class1_ref" | |
119 | set test "nested typedef/ref stripping" | |
120 | gdb_test_multiple "python print str (basic_type_typedef_const_typedef_class1_ref_obj)" $test { | |
121 | -re "\[\r\n\]+class1\[\r\n\]+$gdb_prompt $" { | |
122 | pass $test | |
123 | } | |
124 | } | |
125 | ||
126 | # test has_field on simple class | |
127 | gdb_test_no_output "python class1_obj = gdb.parse_and_eval ('class1_obj')" | |
128 | gdb_test "python print gdb.types.has_field (class1_obj.type, 'x')" "True" | |
129 | gdb_test "python print gdb.types.has_field (class1_obj.type, 'nope')" "False" | |
130 | ||
131 | # test has_field in base class | |
132 | gdb_test_no_output "python subclass1_obj = gdb.parse_and_eval ('subclass1_obj')" | |
133 | gdb_test "python print gdb.types.has_field (subclass1_obj.type, 'x')" "True" | |
134 | ||
135 | # test make_enum_dict | |
136 | gdb_test_no_output "python enum1_obj = gdb.parse_and_eval ('enum1_obj')" | |
137 | gdb_test_no_output "python enum1_dict = gdb.types.make_enum_dict (enum1_obj.type)" | |
138 | gdb_test_no_output "python enum1_list = enum1_dict.items ()" | |
139 | gdb_test_no_output "python enum1_list.sort ()" | |
140 | gdb_test "python print enum1_list" {\[\('A', 0L\), \('B', 1L\), \('C', 2L\)\]} |