|
| 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 | + Variables vars; |
| 19 | +}; |
| 20 | + |
| 21 | +TEST_F(VariablesTest, GetNewVariableReference_UniqueAndRanges) { |
| 22 | + const int64_t temp1 = vars.GetNewVariableReference(false); |
| 23 | + const int64_t temp2 = vars.GetNewVariableReference(false); |
| 24 | + const int64_t perm1 = vars.GetNewVariableReference(true); |
| 25 | + const int64_t perm2 = vars.GetNewVariableReference(true); |
| 26 | + |
| 27 | + EXPECT_NE(temp1, temp2); |
| 28 | + EXPECT_NE(perm1, perm2); |
| 29 | + EXPECT_LT(temp1, perm1); |
| 30 | + EXPECT_LT(temp2, perm1); |
| 31 | +} |
| 32 | + |
| 33 | +TEST_F(VariablesTest, InsertAndGetVariable_Temporary) { |
| 34 | + lldb::SBValue dummy; |
| 35 | + const int64_t ref = vars.InsertVariable(dummy, false); |
| 36 | + lldb::SBValue out = vars.GetVariable(ref); |
| 37 | + |
| 38 | + EXPECT_TRUE(out.IsValid() == dummy.IsValid()); |
| 39 | +} |
| 40 | + |
| 41 | +TEST_F(VariablesTest, InsertAndGetVariable_Permanent) { |
| 42 | + lldb::SBValue dummy; |
| 43 | + const int64_t ref = vars.InsertVariable(dummy, true); |
| 44 | + lldb::SBValue out = vars.GetVariable(ref); |
| 45 | + |
| 46 | + EXPECT_TRUE(out.IsValid() == dummy.IsValid()); |
| 47 | +} |
| 48 | + |
| 49 | +TEST_F(VariablesTest, IsPermanentVariableReference) { |
| 50 | + const int64_t perm = vars.GetNewVariableReference(true); |
| 51 | + const int64_t temp = vars.GetNewVariableReference(false); |
| 52 | + |
| 53 | + EXPECT_TRUE(Variables::IsPermanentVariableReference(perm)); |
| 54 | + EXPECT_FALSE(Variables::IsPermanentVariableReference(temp)); |
| 55 | +} |
| 56 | + |
| 57 | +TEST_F(VariablesTest, Clear_RemovesTemporaryKeepsPermanent) { |
| 58 | + lldb::SBValue dummy; |
| 59 | + const int64_t temp = vars.InsertVariable(dummy, false); |
| 60 | + const int64_t perm = vars.InsertVariable(dummy, true); |
| 61 | + vars.Clear(); |
| 62 | + |
| 63 | + EXPECT_FALSE(vars.GetVariable(temp).IsValid()); |
| 64 | + EXPECT_TRUE(vars.GetVariable(perm).IsValid() == dummy.IsValid()); |
| 65 | +} |
| 66 | + |
| 67 | +TEST_F(VariablesTest, GetTopLevelScope_ReturnsCorrectScope) { |
| 68 | + vars.locals.Append(lldb::SBValue()); |
| 69 | + vars.globals.Append(lldb::SBValue()); |
| 70 | + vars.registers.Append(lldb::SBValue()); |
| 71 | + |
| 72 | + EXPECT_EQ(vars.GetTopLevelScope(VARREF_LOCALS), &vars.locals); |
| 73 | + EXPECT_EQ(vars.GetTopLevelScope(VARREF_GLOBALS), &vars.globals); |
| 74 | + EXPECT_EQ(vars.GetTopLevelScope(VARREF_REGS), &vars.registers); |
| 75 | + EXPECT_EQ(vars.GetTopLevelScope(9999), nullptr); |
| 76 | +} |
| 77 | + |
| 78 | +TEST_F(VariablesTest, FindVariable_LocalsByName) { |
| 79 | + lldb::SBValue dummy; |
| 80 | + vars.locals.Append(dummy); |
| 81 | + lldb::SBValue found = vars.FindVariable(VARREF_LOCALS, ""); |
| 82 | + |
| 83 | + EXPECT_TRUE(found.IsValid() == dummy.IsValid()); |
| 84 | +} |
0 commit comments