Debian Codegraph @

lldb/unittests/DAP/VariablesTest.cpp

raw
1 //===-- VariablesTest.cpp -------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "Variables.h"
10 #include "lldb/API/SBValue.h"
11 #include "lldb/API/SBValueList.h"
12 #include "gtest/gtest.h"
13
14 using namespace lldb_dap;
15
16 class VariablesTest : public ::testing::Test {
17 protected:
18 enum : bool { Permanent = true, Temporary = false };
19 Variables vars;
20 };
21
22 TEST_F(VariablesTest, GetNewVariableReference_UniqueAndRanges) {
23 const int64_t temp1 = vars.GetNewVariableReference(Temporary);
24 const int64_t temp2 = vars.GetNewVariableReference(Temporary);
25 const int64_t perm1 = vars.GetNewVariableReference(Permanent);
26 const int64_t perm2 = vars.GetNewVariableReference(Permanent);
27
28 EXPECT_NE(temp1, temp2);
29 EXPECT_NE(perm1, perm2);
30 EXPECT_LT(temp1, perm1);
31 EXPECT_LT(temp2, perm1);
32 }
33
34 TEST_F(VariablesTest, InsertAndGetVariable_Temporary) {
35 lldb::SBValue dummy;
36 const int64_t ref = vars.InsertVariable(dummy, Temporary);
37 lldb::SBValue out = vars.GetVariable(ref);
38
39 EXPECT_EQ(out.IsValid(), dummy.IsValid());
40 }
41
42 TEST_F(VariablesTest, InsertAndGetVariable_Permanent) {
43 lldb::SBValue dummy;
44 const int64_t ref = vars.InsertVariable(dummy, Permanent);
45 lldb::SBValue out = vars.GetVariable(ref);
46
47 EXPECT_EQ(out.IsValid(), dummy.IsValid());
48 }
49
50 TEST_F(VariablesTest, IsPermanentVariableReference) {
51 const int64_t perm = vars.GetNewVariableReference(Permanent);
52 const int64_t temp = vars.GetNewVariableReference(Temporary);
53
54 EXPECT_TRUE(Variables::IsPermanentVariableReference(perm));
55 EXPECT_FALSE(Variables::IsPermanentVariableReference(temp));
56 }
57
58 TEST_F(VariablesTest, Clear_RemovesTemporaryKeepsPermanent) {
59 lldb::SBValue dummy;
60 const int64_t temp = vars.InsertVariable(dummy, Temporary);
61 const int64_t perm = vars.InsertVariable(dummy, Permanent);
62 vars.Clear();
63
64 EXPECT_FALSE(vars.GetVariable(temp).IsValid());
65 EXPECT_EQ(vars.GetVariable(perm).IsValid(), dummy.IsValid());
66 }
67
68 TEST_F(VariablesTest, GetTopLevelScope_ReturnsCorrectScope) {
69 vars.locals.Append(lldb::SBValue());
70 vars.globals.Append(lldb::SBValue());
71 vars.registers.Append(lldb::SBValue());
72
73 EXPECT_EQ(vars.GetTopLevelScope(VARREF_LOCALS), &vars.locals);
74 EXPECT_EQ(vars.GetTopLevelScope(VARREF_GLOBALS), &vars.globals);
75 EXPECT_EQ(vars.GetTopLevelScope(VARREF_REGS), &vars.registers);
76 EXPECT_EQ(vars.GetTopLevelScope(9999), nullptr);
77 }
78
79 TEST_F(VariablesTest, FindVariable_LocalsByName) {
80 lldb::SBValue dummy;
81 vars.locals.Append(dummy);
82 lldb::SBValue found = vars.FindVariable(VARREF_LOCALS, "");
83
84 EXPECT_EQ(found.IsValid(), dummy.IsValid());
85 }