1 /* 2 * Copyright 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 //#define LOG_NDEBUG 0 18 #define LOG_TAG "C2_test" 19 20 #include <gtest/gtest.h> 21 22 #include <C2.h> 23 24 namespace android { 25 26 /* ======================================= STATIC TESTS ======================================= */ 27 28 template<int N> 29 struct c2_const_checker 30 { 31 inline constexpr static int num() { return N; } 32 }; 33 34 constexpr auto min_i32_i32 = c2_min(int32_t(1), int32_t(2)); 35 static_assert(std::is_same<decltype(min_i32_i32), const int32_t>::value, "should be int32_t"); 36 constexpr auto min_i32_i64 = c2_min(int32_t(3), int64_t(2)); 37 static_assert(std::is_same<decltype(min_i32_i64), const int64_t>::value, "should be int64_t"); 38 constexpr auto min_i8_i32 = c2_min(int8_t(0xff), int32_t(0xffffffff)); 39 static_assert(std::is_same<decltype(min_i8_i32), const int32_t>::value, "should be int32_t"); 40 41 static_assert(c2_const_checker<min_i32_i32>::num() == 1, "should be 1"); 42 static_assert(c2_const_checker<min_i32_i64>::num() == 2, "should be 2"); 43 static_assert(c2_const_checker<min_i8_i32>::num() == 0xffffffff, "should be 0xffffffff"); 44 45 constexpr auto min_u32_u32 = c2_min(uint32_t(1), uint32_t(2)); 46 static_assert(std::is_same<decltype(min_u32_u32), const uint32_t>::value, "should be uint32_t"); 47 constexpr auto min_u32_u64 = c2_min(uint32_t(3), uint64_t(2)); 48 static_assert(std::is_same<decltype(min_u32_u64), const uint32_t>::value, "should be uint32_t"); 49 constexpr auto min_u32_u8 = c2_min(uint32_t(0xffffffff), uint8_t(0xff)); 50 static_assert(std::is_same<decltype(min_u32_u8), const uint8_t>::value, "should be uint8_t"); 51 52 static_assert(c2_const_checker<min_u32_u32>::num() == 1, "should be 1"); 53 static_assert(c2_const_checker<min_u32_u64>::num() == 2, "should be 2"); 54 static_assert(c2_const_checker<min_u32_u8>::num() == 0xff, "should be 0xff"); 55 56 constexpr auto max_i32_i32 = c2_max(int32_t(1), int32_t(2)); 57 static_assert(std::is_same<decltype(max_i32_i32), const int32_t>::value, "should be int32_t"); 58 constexpr auto max_i32_i64 = c2_max(int32_t(3), int64_t(2)); 59 static_assert(std::is_same<decltype(max_i32_i64), const int64_t>::value, "should be int64_t"); 60 constexpr auto max_i8_i32 = c2_max(int8_t(0xff), int32_t(0xffffffff)); 61 static_assert(std::is_same<decltype(max_i8_i32), const int32_t>::value, "should be int32_t"); 62 63 static_assert(c2_const_checker<max_i32_i32>::num() == 2, "should be 2"); 64 static_assert(c2_const_checker<max_i32_i64>::num() == 3, "should be 3"); 65 static_assert(c2_const_checker<max_i8_i32>::num() == 0xffffffff, "should be 0xffffffff"); 66 67 constexpr auto max_u32_u32 = c2_max(uint32_t(1), uint32_t(2)); 68 static_assert(std::is_same<decltype(max_u32_u32), const uint32_t>::value, "should be uint32_t"); 69 constexpr auto max_u32_u64 = c2_max(uint32_t(3), uint64_t(2)); 70 static_assert(std::is_same<decltype(max_u32_u64), const uint64_t>::value, "should be uint64_t"); 71 constexpr auto max_u32_u8 = c2_max(uint32_t(0x7fffffff), uint8_t(0xff)); 72 static_assert(std::is_same<decltype(max_u32_u8), const uint32_t>::value, "should be uint32_t"); 73 74 static_assert(c2_const_checker<max_u32_u32>::num() == 2, "should be 2"); 75 static_assert(c2_const_checker<max_u32_u64>::num() == 3, "should be 3"); 76 static_assert(c2_const_checker<max_u32_u8>::num() == 0x7fffffff, "should be 0x7fffffff"); 77 78 } // namespace android 79