xref: /aosp_15_r20/external/zstd/contrib/pzstd/utils/test/ScopeGuardTest.cpp (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin Cui /*
2*01826a49SYabin Cui  * Copyright (c) Meta Platforms, Inc. and affiliates.
3*01826a49SYabin Cui  * All rights reserved.
4*01826a49SYabin Cui  *
5*01826a49SYabin Cui  * This source code is licensed under both the BSD-style license (found in the
6*01826a49SYabin Cui  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7*01826a49SYabin Cui  * in the COPYING file in the root directory of this source tree).
8*01826a49SYabin Cui  */
9*01826a49SYabin Cui #include "utils/ScopeGuard.h"
10*01826a49SYabin Cui 
11*01826a49SYabin Cui #include <gtest/gtest.h>
12*01826a49SYabin Cui 
13*01826a49SYabin Cui using namespace pzstd;
14*01826a49SYabin Cui 
TEST(ScopeGuard,Dismiss)15*01826a49SYabin Cui TEST(ScopeGuard, Dismiss) {
16*01826a49SYabin Cui   {
17*01826a49SYabin Cui     auto guard = makeScopeGuard([&] { EXPECT_TRUE(false); });
18*01826a49SYabin Cui     guard.dismiss();
19*01826a49SYabin Cui   }
20*01826a49SYabin Cui }
21*01826a49SYabin Cui 
TEST(ScopeGuard,Executes)22*01826a49SYabin Cui TEST(ScopeGuard, Executes) {
23*01826a49SYabin Cui   bool executed = false;
24*01826a49SYabin Cui   {
25*01826a49SYabin Cui     auto guard = makeScopeGuard([&] { executed = true; });
26*01826a49SYabin Cui   }
27*01826a49SYabin Cui   EXPECT_TRUE(executed);
28*01826a49SYabin Cui }
29