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