添加countof ut

This commit is contained in:
mutouyun 2022-03-01 11:03:29 +08:00
parent 1ff5900a6d
commit daa3c30f4c

View File

@ -1,6 +1,7 @@
#include <type_traits> // std::aligned_storage_t #include <type_traits> // std::aligned_storage_t
#include <cstdint> #include <cstdint>
#include <vector>
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -86,3 +87,14 @@ TEST(utility, pimpl_inherit) {
EXPECT_EQ(ipc::pimpl::get(pbar)->pj_, &j); EXPECT_EQ(ipc::pimpl::get(pbar)->pj_, &j);
pbar->clear(); pbar->clear();
} }
TEST(utility, countof) {
struct {
constexpr int Size() const noexcept { return 3; }
} sv;
std::vector<int> 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]));
}