• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expresso or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include "aemu/base/ArraySize.h"
15 
16 #include <gtest/gtest.h>
17 
18 #include <vector>
19 
20 namespace android {
21 namespace base {
22 
TEST(ArraySize,Sizes)23 TEST(ArraySize, Sizes) {
24     int array1[100];
25     EXPECT_EQ(100U, arraySize(array1));
26     EXPECT_EQ(100U, ARRAY_SIZE(array1));
27 
28     char array2[200];
29     EXPECT_EQ(200U, arraySize(array2));
30     EXPECT_EQ(200U, ARRAY_SIZE(array2));
31 
32     std::array<std::vector<bool>, 15> array3;
33     EXPECT_EQ(15U, arraySize(array3));
34     EXPECT_EQ(15U, ARRAY_SIZE(array3));
35 }
36 
TEST(ArraySize,CompileTime)37 TEST(ArraySize, CompileTime) {
38     static constexpr int arr[20] = {};
39     static_assert(ARRAY_SIZE(arr) == 20U,
40                   "Bad ARRAY_SIZE() result in compile time");
41     static_assert(arraySize(arr) == 20U,
42                   "Bad arraySize() result in compile time");
43 
44     static constexpr bool arr2[arraySize(arr)] = {};
45     static_assert(arraySize(arr2) == 20U,
46                   "Bad size of a new array declared with a result of "
47                   "arraySize() call");
48     static_assert(arraySize(arr) == ARRAY_SIZE(arr2),
49                   "Macro and function are compatible");
50 }
51 
52 }  // namespace base
53 }  // namespace android
54