1 // Copyright 2020 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://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, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #include "pw_bytes/units.h" 16 17 #include <cstddef> 18 19 namespace pw::bytes { 20 namespace { 21 22 using namespace pw::bytes::unit_literals; 23 24 // Byte Function tests 25 static_assert(B(1) == 1ull); 26 static_assert(B(42) == 42ull); 27 28 static_assert(KiB(1) == 1'024ull); 29 static_assert(KiB(42) == 43'008ull); 30 31 static_assert(MiB(1) == 1'048'576ull); 32 static_assert(MiB(42) == 44'040'192ull); 33 34 static_assert(GiB(1) == 1'073'741'824ull); 35 static_assert(GiB(42) == 45'097'156'608ull); 36 37 static_assert(TiB(1) == 1'099'511'627'776ull); 38 static_assert(TiB(42) == 46'179'488'366'592ull); 39 40 static_assert(PiB(1) == 1'125'899'906'842'624ull); 41 static_assert(PiB(42) == 47'287'796'087'390'208ull); 42 43 static_assert(EiB(1) == 1'152'921'504'606'846'976ull); 44 static_assert(EiB(4) == 4'611'686'018'427'387'904ull); 45 46 // User-defined literal tests 47 static_assert(1_B == 1ull); 48 static_assert(42_B == 42ull); 49 50 static_assert(1_KiB == 1'024ull); 51 static_assert(42_KiB == 43'008ull); 52 53 static_assert(1_MiB == 1'048'576ull); 54 static_assert(42_MiB == 44'040'192ull); 55 56 static_assert(1_GiB == 1'073'741'824ull); 57 static_assert(42_GiB == 45'097'156'608ull); 58 59 static_assert(1_TiB == 1'099'511'627'776ull); 60 static_assert(42_TiB == 46'179'488'366'592ull); 61 62 static_assert(1_PiB == 1'125'899'906'842'624ull); 63 static_assert(42_PiB == 47'287'796'087'390'208ull); 64 65 static_assert(1_EiB == 1'152'921'504'606'846'976ull); 66 static_assert(4_EiB == 4'611'686'018'427'387'904ull); 67 68 } // namespace 69 } // namespace pw::bytes 70