SymbolStringPoolTest.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===----- SymbolStringPoolTest.cpp - Unit tests for SymbolStringPool -----===//
  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. #include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
  9. #include "gtest/gtest.h"
  10. using namespace llvm;
  11. using namespace llvm::orc;
  12. namespace {
  13. TEST(SymbolStringPool, UniquingAndComparisons) {
  14. SymbolStringPool SP;
  15. auto P1 = SP.intern("hello");
  16. std::string S("hel");
  17. S += "lo";
  18. auto P2 = SP.intern(S);
  19. auto P3 = SP.intern("goodbye");
  20. EXPECT_EQ(P1, P2) << "Failed to unique entries";
  21. EXPECT_NE(P1, P3) << "Inequal pooled symbol strings comparing equal";
  22. // We want to test that less-than comparison of SymbolStringPtrs compiles,
  23. // however we can't test the actual result as this is a pointer comparison and
  24. // SymbolStringPtr doesn't expose the underlying address of the string.
  25. (void)(P1 < P3);
  26. }
  27. TEST(SymbolStringPool, Dereference) {
  28. SymbolStringPool SP;
  29. auto Foo = SP.intern("foo");
  30. EXPECT_EQ(*Foo, "foo") << "Equality on dereferenced string failed";
  31. }
  32. TEST(SymbolStringPool, ClearDeadEntries) {
  33. SymbolStringPool SP;
  34. {
  35. auto P1 = SP.intern("s1");
  36. SP.clearDeadEntries();
  37. EXPECT_FALSE(SP.empty()) << "\"s1\" entry in pool should still be retained";
  38. }
  39. SP.clearDeadEntries();
  40. EXPECT_TRUE(SP.empty()) << "pool should be empty";
  41. }
  42. }