1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
# TestIndirectEnumVariables.py
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ------------------------------------------------------------------------------
"""
Tests that indirect Enum variables display correctly
"""
import lldb
from lldbsuite.test.lldbtest import *
from lldbsuite.test.decorators import *
import lldbsuite.test.lldbutil as lldbutil
import os
import unittest2
class TestIndirectEnumVariables(TestBase):
@swiftTest
def test_indirect_cases_variables(self):
"""Tests that indirect Enum variables display correctly when cases are indirect"""
self.build()
self.do_test("indirect case break here")
@swiftTest
def test_indirect_enum_variables(self):
"""Tests that indirect Enum variables display correctly when enum is indirect"""
self.build()
self.do_test("indirect enum break here")
def setUp(self):
TestBase.setUp(self)
def get_variable(self, name):
x = self.frame().FindVariable(name)
x.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
x.SetPreferSyntheticValue(True)
return x
def check_enum(
self,
enum,
value=None,
summary=None,
child_path=None,
child_value=None,
child_summary=None):
if value:
self.assertEqual(
enum.GetValue(), value,
"%s.GetValue() == %s" % (enum.GetName(), value),
)
if summary:
self.assertEqual(
enum.GetSummary(), summary,
"%s.GetSummary() == %s" % (enum.GetName(), summary),
)
if child_path:
child = enum
for child_index in child_path:
child = child.GetChildAtIndex(child_index)
child.SetPreferDynamicValue(lldb.eDynamicCanRunTarget)
child.SetPreferSyntheticValue(True)
self.assertTrue(
child.IsValid(),
"child at path %s valid" %
(child_path))
if child_value:
self.assertEqual(
child.GetValue(), child_value,
"%s.GetValue() == %s" % (child.GetName(), child_value),
)
if child_summary:
self.assertEqual(
child.GetSummary(), child_summary,
"%s.GetSummary() == %s" % (child.GetName(), child_summary),
)
def do_test(self, break_pattern):
"""Tests that indirect Enum variables display correctly"""
target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
self,
break_pattern,
lldb.SBFileSpec("main.swift"),
)
GP_StructType = self.get_variable("GP_StructType")
GP_TupleType = self.get_variable("GP_TupleType")
GP_ClassType = self.get_variable("GP_ClassType")
GP_ProtocolType_Struct = self.get_variable("GP_ProtocolType_Struct")
GP_ProtocolType_Class = self.get_variable("GP_ProtocolType_Class")
GP_CEnumType = self.get_variable("GP_CEnumType")
GP_ADTEnumType = self.get_variable("GP_ADTEnumType")
GP_Recursive = self.get_variable("GP_Recursive")
self.check_enum(
GP_StructType,
value='StructType',
child_path=[0],
child_value='12')
self.check_enum(
GP_TupleType,
value='TupleType',
child_path=[
0,
0],
child_value='12')
self.check_enum(
GP_TupleType, value='TupleType', child_path=[
0, 1], child_summary='"Hello World"')
self.check_enum(
GP_ClassType, value='ClassType', child_path=[
0, 0, 0], child_summary='"Hello World"')
self.check_enum(
GP_ClassType,
value='ClassType',
child_path=[
0,
1],
child_value='12')
self.check_enum(
GP_ProtocolType_Struct,
value='ProtocolType',
child_path=[0],
child_value='12')
self.check_enum(
GP_ProtocolType_Class,
value='ProtocolType',
child_path=[
0,
0,
0],
child_summary='"Hello World"')
self.check_enum(
GP_ProtocolType_Class,
value='ProtocolType',
child_path=[
0,
1],
child_value='12')
self.check_enum(
GP_CEnumType,
value='CEnumType',
child_path=[0],
child_value='B')
self.check_enum(
GP_ADTEnumType,
value='ADTEnumType',
child_path=[
0,
0],
child_value='12')
self.check_enum(
GP_Recursive,
value='Recursive',
child_path=[
0,
0],
child_value='12')
|