From daa3c30f4c38ae5bb833449da35160c06e3845ad Mon Sep 17 00:00:00 2001 From: mutouyun Date: Tue, 1 Mar 2022 11:03:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0countof=20ut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_utility.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test_utility.cpp b/test/test_utility.cpp index d2c3dae..6f4d47c 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -1,6 +1,7 @@ #include // std::aligned_storage_t #include +#include #include "gtest/gtest.h" @@ -86,3 +87,14 @@ TEST(utility, pimpl_inherit) { EXPECT_EQ(ipc::pimpl::get(pbar)->pj_, &j); pbar->clear(); } + +TEST(utility, countof) { + struct { + constexpr int Size() const noexcept { return 3; } + } sv; + std::vector vec {1, 2, 3, 4, 5}; + int arr[] {7, 6, 5, 4, 3, 2, 1}; + EXPECT_EQ(ipc::countof(sv) , sv.Size()); + EXPECT_EQ(ipc::countof(vec), vec.size()); + EXPECT_EQ(ipc::countof(arr), sizeof(arr) / sizeof(arr[0])); +}