1""" 2Test some expressions involving STL data types. 3""" 4 5 6 7import unittest2 8import lldb 9from lldbsuite.test.decorators import * 10from lldbsuite.test.lldbtest import * 11from lldbsuite.test import lldbutil 12 13 14class STLTestCase(TestBase): 15 16 mydir = TestBase.compute_mydir(__file__) 17 18 @skipIf 19 @expectedFailureAll(bugnumber="llvm.org/PR36713") 20 def test(self): 21 """Test some expressions involving STL data types.""" 22 self.build() 23 lldbutil.run_to_source_breakpoint(self, "// Set break point at this line", lldb.SBFileSpec("main.cpp")) 24 25 # Now try some expressions.... 26 27 self.runCmd( 28 'expr for (int i = 0; i < hello_world.length(); ++i) { (void)printf("%c\\n", hello_world[i]); }') 29 30 self.expect('expr associative_array.size()', 31 substrs=[' = 3']) 32 self.expect('expr associative_array.count(hello_world)', 33 substrs=[' = 1']) 34 self.expect('expr associative_array[hello_world]', 35 substrs=[' = 1']) 36 self.expect('expr associative_array["hello"]', 37 substrs=[' = 2']) 38 39 @expectedFailureAll( 40 compiler="icc", 41 bugnumber="ICC (13.1, 14-beta) do not emit DW_TAG_template_type_parameter.") 42 @add_test_categories(['pyapi']) 43 def test_SBType_template_aspects(self): 44 """Test APIs for getting template arguments from an SBType.""" 45 self.build() 46 (_, _, thread, _) = lldbutil.run_to_source_breakpoint(self, "// Set break point at this line", lldb.SBFileSpec("main.cpp")) 47 frame0 = thread.GetFrameAtIndex(0) 48 49 # Get the type for variable 'associative_array'. 50 associative_array = frame0.FindVariable('associative_array') 51 self.DebugSBValue(associative_array) 52 self.assertTrue(associative_array, VALID_VARIABLE) 53 map_type = associative_array.GetType() 54 self.DebugSBType(map_type) 55 self.assertTrue(map_type, VALID_TYPE) 56 num_template_args = map_type.GetNumberOfTemplateArguments() 57 self.assertTrue(num_template_args > 0) 58 59 # We expect the template arguments to contain at least 'string' and 60 # 'int'. 61 expected_types = {'string': False, 'int': False} 62 for i in range(num_template_args): 63 t = map_type.GetTemplateArgumentType(i) 64 self.DebugSBType(t) 65 self.assertTrue(t, VALID_TYPE) 66 name = t.GetName() 67 if 'string' in name: 68 expected_types['string'] = True 69 elif 'int' == name: 70 expected_types['int'] = True 71 72 # Check that both entries of the dictionary have 'True' as the value. 73 self.assertTrue(all(expected_types.values())) 74