| Calin Juravle | da030de | 2014-02-20 13:40:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 | |
| Elliott Hughes | 7f850e3 | 2025-04-21 08:42:00 -0700 | [diff] [blame^] | 17 | #include <stdint.h> |
| 18 | |
| Calin Juravle | da030de | 2014-02-20 13:40:36 +0000 | [diff] [blame] | 19 | #include <gtest/gtest.h> |
| 20 | |
| Elliott Hughes | 7f850e3 | 2025-04-21 08:42:00 -0700 | [diff] [blame^] | 21 | #include <limits> |
| Calin Juravle | da030de | 2014-02-20 13:40:36 +0000 | [diff] [blame] | 22 | |
| Elliott Hughes | 995eee6 | 2025-04-14 07:57:27 -0700 | [diff] [blame] | 23 | #if !defined(__WINT_UNSIGNED__) |
| 24 | #error wint_t is unsigned on Android |
| 25 | #endif |
| 26 | |
| Elliott Hughes | 7f850e3 | 2025-04-21 08:42:00 -0700 | [diff] [blame^] | 27 | TEST(stdint, wint_sign) { |
| 28 | EXPECT_FALSE(std::numeric_limits<wint_t>::is_signed); |
| 29 | } |
| 30 | |
| 31 | TEST(stdint, fast_type_sizes) { |
| 32 | EXPECT_EQ(1U, sizeof(int_fast8_t)); |
| 33 | EXPECT_EQ(8U, sizeof(int_fast64_t)); |
| 34 | EXPECT_EQ(1U, sizeof(uint_fast8_t)); |
| 35 | EXPECT_EQ(8U, sizeof(uint_fast64_t)); |
| Calin Juravle | da030de | 2014-02-20 13:40:36 +0000 | [diff] [blame] | 36 | #if defined(__LP64__) |
| Elliott Hughes | 7f850e3 | 2025-04-21 08:42:00 -0700 | [diff] [blame^] | 37 | EXPECT_EQ(8U, sizeof(int_fast16_t)); |
| 38 | EXPECT_EQ(8U, sizeof(int_fast32_t)); |
| 39 | EXPECT_EQ(8U, sizeof(uint_fast16_t)); |
| 40 | EXPECT_EQ(8U, sizeof(uint_fast32_t)); |
| Calin Juravle | da030de | 2014-02-20 13:40:36 +0000 | [diff] [blame] | 41 | #else |
| Elliott Hughes | 7f850e3 | 2025-04-21 08:42:00 -0700 | [diff] [blame^] | 42 | EXPECT_EQ(4U, sizeof(int_fast16_t)); |
| 43 | EXPECT_EQ(4U, sizeof(int_fast32_t)); |
| 44 | EXPECT_EQ(4U, sizeof(uint_fast16_t)); |
| 45 | EXPECT_EQ(4U, sizeof(uint_fast32_t)); |
| Calin Juravle | da030de | 2014-02-20 13:40:36 +0000 | [diff] [blame] | 46 | #endif |
| 47 | } |
| Elliott Hughes | 7f850e3 | 2025-04-21 08:42:00 -0700 | [diff] [blame^] | 48 | |
| 49 | TEST(stdint, least_type_sizes) { |
| 50 | EXPECT_EQ(1U, sizeof(int_least8_t)); |
| 51 | EXPECT_EQ(1U, sizeof(uint_least8_t)); |
| 52 | EXPECT_EQ(2U, sizeof(int_least16_t)); |
| 53 | EXPECT_EQ(2U, sizeof(uint_least16_t)); |
| 54 | EXPECT_EQ(4U, sizeof(int_least32_t)); |
| 55 | EXPECT_EQ(4U, sizeof(uint_least32_t)); |
| 56 | EXPECT_EQ(8U, sizeof(int_least64_t)); |
| 57 | EXPECT_EQ(8U, sizeof(uint_least64_t)); |
| 58 | } |