• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
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 express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "utils/bit_helpers.h"
17 
18 #include <cstdint>
19 #include <type_traits>
20 
21 #include <gtest/gtest.h>
22 
23 namespace panda::helpers::test {
24 
TEST(BitHelpers,UnsignedTypeHelper)25 TEST(BitHelpers, UnsignedTypeHelper)
26 {
27     EXPECT_TRUE((std::is_same_v<UnsignedTypeHelperT<0>, uint8_t>));
28     EXPECT_TRUE((std::is_same_v<UnsignedTypeHelperT<1>, uint8_t>));
29     EXPECT_TRUE((std::is_same_v<UnsignedTypeHelperT<8>, uint8_t>));
30 
31     EXPECT_TRUE((std::is_same_v<UnsignedTypeHelperT<9>, uint16_t>));
32     EXPECT_TRUE((std::is_same_v<UnsignedTypeHelperT<16>, uint16_t>));
33 
34     EXPECT_TRUE((std::is_same_v<UnsignedTypeHelperT<17>, uint32_t>));
35     EXPECT_TRUE((std::is_same_v<UnsignedTypeHelperT<32>, uint32_t>));
36 
37     EXPECT_TRUE((std::is_same_v<UnsignedTypeHelperT<33>, uint64_t>));
38     EXPECT_TRUE((std::is_same_v<UnsignedTypeHelperT<64>, uint64_t>));
39 
40     EXPECT_TRUE((std::is_same_v<UnsignedTypeHelperT<65>, void>));
41 }
42 
TEST(BitHelpers,TypeHelper)43 TEST(BitHelpers, TypeHelper)
44 {
45     EXPECT_TRUE((std::is_same_v<TypeHelperT<0, false>, uint8_t>));
46     EXPECT_TRUE((std::is_same_v<TypeHelperT<1, false>, uint8_t>));
47     EXPECT_TRUE((std::is_same_v<TypeHelperT<8, false>, uint8_t>));
48 
49     EXPECT_TRUE((std::is_same_v<TypeHelperT<0, true>, int8_t>));
50     EXPECT_TRUE((std::is_same_v<TypeHelperT<1, true>, int8_t>));
51     EXPECT_TRUE((std::is_same_v<TypeHelperT<8, true>, int8_t>));
52 
53     EXPECT_TRUE((std::is_same_v<TypeHelperT<9, false>, uint16_t>));
54     EXPECT_TRUE((std::is_same_v<TypeHelperT<16, false>, uint16_t>));
55 
56     EXPECT_TRUE((std::is_same_v<TypeHelperT<9, true>, int16_t>));
57     EXPECT_TRUE((std::is_same_v<TypeHelperT<16, true>, int16_t>));
58 
59     EXPECT_TRUE((std::is_same_v<TypeHelperT<17, false>, uint32_t>));
60     EXPECT_TRUE((std::is_same_v<TypeHelperT<32, false>, uint32_t>));
61 
62     EXPECT_TRUE((std::is_same_v<TypeHelperT<17, true>, int32_t>));
63     EXPECT_TRUE((std::is_same_v<TypeHelperT<32, true>, int32_t>));
64 
65     EXPECT_TRUE((std::is_same_v<TypeHelperT<33, false>, uint64_t>));
66     EXPECT_TRUE((std::is_same_v<TypeHelperT<64, false>, uint64_t>));
67 
68     EXPECT_TRUE((std::is_same_v<TypeHelperT<33, true>, int64_t>));
69     EXPECT_TRUE((std::is_same_v<TypeHelperT<64, true>, int64_t>));
70 }
71 
72 }  // namespace panda::helpers::test
73