From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- mfbt/tests/TestEnumTypeTraits.cpp | 136 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 mfbt/tests/TestEnumTypeTraits.cpp (limited to 'mfbt/tests/TestEnumTypeTraits.cpp') diff --git a/mfbt/tests/TestEnumTypeTraits.cpp b/mfbt/tests/TestEnumTypeTraits.cpp new file mode 100644 index 000000000..879d40526 --- /dev/null +++ b/mfbt/tests/TestEnumTypeTraits.cpp @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "mozilla/IntegerTypeTraits.h" +#include "mozilla/EnumTypeTraits.h" + +using namespace mozilla; + +/* Feature check for EnumTypeFitsWithin. */ + +#define MAKE_FIXED_EMUM_FOR_TYPE(IntType) \ + enum FixedEnumFor_##IntType : IntType { \ + A_##IntType, \ + B_##IntType, \ + C_##IntType, \ + }; + +template +static void +TestShouldFit() +{ + static_assert(EnumTypeFitsWithin::value, + "Should fit within exact/promoted integral type"); +} + +template +static void +TestShouldNotFit() +{ + static_assert(!EnumTypeFitsWithin::value, + "Should not fit within"); +} + +int +main() +{ + // check for int8_t + MAKE_FIXED_EMUM_FOR_TYPE(int8_t); + TestShouldFit(); + TestShouldFit(); + TestShouldFit(); + TestShouldFit(); + + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + + // check for uint8_t + MAKE_FIXED_EMUM_FOR_TYPE(uint8_t); + TestShouldFit(); + TestShouldFit(); + TestShouldFit(); + TestShouldFit(); + + TestShouldNotFit(); + TestShouldFit(); + TestShouldFit(); + TestShouldFit(); + + // check for int16_t + MAKE_FIXED_EMUM_FOR_TYPE(int16_t); + TestShouldNotFit(); + TestShouldFit(); + TestShouldFit(); + TestShouldFit(); + + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + + // check for uint16_t + MAKE_FIXED_EMUM_FOR_TYPE(uint16_t); + TestShouldNotFit(); + TestShouldFit(); + TestShouldFit(); + TestShouldFit(); + + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldFit(); + TestShouldFit(); + + // check for int32_t + MAKE_FIXED_EMUM_FOR_TYPE(int32_t); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldFit(); + TestShouldFit(); + + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + + // check for uint32_t + MAKE_FIXED_EMUM_FOR_TYPE(uint32_t); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldFit(); + TestShouldFit(); + + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldFit(); + + // check for int64_t + MAKE_FIXED_EMUM_FOR_TYPE(int64_t); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldFit(); + + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + + // check for uint64_t + MAKE_FIXED_EMUM_FOR_TYPE(uint64_t); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldFit(); + + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + TestShouldNotFit(); + + return 0; +} -- cgit v1.2.3