[gprpp] Add more tests for NoDestruct (#30497)

pull/30500/head
Craig Tiller 3 years ago committed by GitHub
parent 0b1a8c984b
commit 4f9f26316d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      test/core/gprpp/no_destruct_test.cc

@ -14,6 +14,8 @@
#include "src/core/lib/gprpp/no_destruct.h"
#include <stdlib.h>
#include <memory>
#include <gtest/gtest.h>
@ -22,10 +24,23 @@ namespace grpc_core {
namespace testing {
namespace {
class CrashOnDestruction {
public:
void Exists() {}
private:
~CrashOnDestruction() { abort(); }
};
NoDestruct<std::unique_ptr<int>> g_test_int(new int(42));
NoDestruct<CrashOnDestruction> g_test_crash_on_destruction;
TEST(NoDestruct, Works) { EXPECT_EQ(42, **g_test_int); }
TEST(NoDestruct, CrashOnDestructionIsAccessible) {
g_test_crash_on_destruction->Exists();
}
} // namespace
} // namespace testing
} // namespace grpc_core

Loading…
Cancel
Save