This is an automated email from the ASF dual-hosted git repository.

wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new d4695c90 Add UT of ScopeGuard (#2569)
d4695c90 is described below

commit d4695c90092c2574d27e9f6eaa9dc9a86137be40
Author: Bright Chen <chenguangmin...@foxmail.com>
AuthorDate: Mon Mar 18 10:51:02 2024 +0800

    Add UT of ScopeGuard (#2569)
---
 test/CMakeLists.txt          |  1 +
 test/Makefile                |  3 ++-
 test/scope_guard_unittest.cc | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index da59abeb..fe9bb424 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -173,6 +173,7 @@ SET(TEST_BUTIL_SOURCES
     ${PROJECT_SOURCE_DIR}/test/object_pool_unittest.cpp
     ${PROJECT_SOURCE_DIR}/test/test_switches.cc
     ${PROJECT_SOURCE_DIR}/test/scoped_locale.cc
+    ${PROJECT_SOURCE_DIR}/test/scope_guard_unittest.cc
     ${PROJECT_SOURCE_DIR}/test/butil_unittest_main.cpp
     ${PROJECT_SOURCE_DIR}/test/butil_unittest_main.cpp
        )
diff --git a/test/Makefile b/test/Makefile
index 82efc381..97bde8f5 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -145,7 +145,8 @@ TEST_BUTIL_SOURCES = \
     scoped_locale.cc \
     popen_unittest.cpp \
     bounded_queue_unittest.cc \
-    butil_unittest_main.cpp
+    butil_unittest_main.cpp \
+    scope_guard_unittest.cc
 
 ifeq ($(SYSTEM), Linux)
     TEST_BUTIL_SOURCES += test_file_util_linux.cc \
diff --git a/test/scope_guard_unittest.cc b/test/scope_guard_unittest.cc
new file mode 100644
index 00000000..085162fd
--- /dev/null
+++ b/test/scope_guard_unittest.cc
@@ -0,0 +1,39 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+
+#include <gtest/gtest.h>
+#include "butil/memory/scope_guard.h"
+
+TEST(ScopedGuardTest, sanity) {
+    bool flag = false;
+    {
+        auto guard = butil::MakeScopeGuard([&flag] {
+            flag = true;
+        });
+    }
+    ASSERT_TRUE(flag);
+
+    flag = false;
+    {
+        auto guard = butil::MakeScopeGuard([&flag] {
+            flag = true;
+        });
+        guard.dismiss();
+    }
+    ASSERT_FALSE(flag);
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to