"""
Test C++ virtual function and virtual inheritance.
"""
import os, time
import re
import lldb
from lldbtest import *
def Msg(expr, val):
return "'expression %s' matches the output (from compiled code): %s" % (expr, val)
class CppVirtualMadness(TestBase):
mydir = os.path.join("lang", "cpp", "virtual")
pattern = re.compile("^([^=]*) = '([^=]*)'$")
PRINTF_OUTPUT_GROKKED = "The printf output from compiled code is parsed correctly"
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
def test_virtual_madness_dsym(self):
"""Test that expression works correctly with virtual inheritance as well as virtual function."""
self.buildDsym()
self.virtual_madness_test()
def test_virtual_madness_dwarf(self):
"""Test that expression works correctly with virtual inheritance as well as virtual function."""
self.buildDwarf()
self.virtual_madness_test()
def setUp(self):
TestBase.setUp(self)
self.line = line_number('main.cpp', '// Set first breakpoint here.')
def virtual_madness_test(self):
"""Test that variable expressions with basic types are evaluated correctly."""
go = system("./a.out", sender=self)[0]
gl = []
for line in go.split(os.linesep):
match = self.pattern.search(line)
if match:
my_expr, val = match.group(1), match.group(2)
gl.append((my_expr, val))
self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
self.runCmd("breakpoint set -f main.cpp -l %d" % self.line)
self.runCmd("run", RUN_SUCCEEDED)
for my_expr, val in gl:
if "LLDB_TYPES_EXPR_TIME_WAIT" in os.environ:
time.sleep(float(os.environ["LLDB_TYPES_EXPR_TIME_WAIT"]))
self.runCmd("expression %s" % my_expr)
output = self.res.GetOutput()
self.expect(output, Msg(my_expr, val), exe=False,
substrs = [val])