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