#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License // If the library is compiled as a DLL, this ensures symbols are exported #define NUCLEX_PIXELS_SOURCE 1 #include "../../Source/PixelFormats/BitMask.h" #include "Nuclex/Pixels/UInt128.h" #include namespace { // ------------------------------------------------------------------------------------------- // /// Returns the upper 64 bits of a 128 bit integer /// 128 bit integer of which the upper 64 bits are returned /// The upper 64 bits of the specified 128 bit integer std::uint64_t upper64(Nuclex::Pixels::uint128_t integer) { return static_cast(integer >> 64); } // ------------------------------------------------------------------------------------------- // /// Returns the lower 64 bits of a 128 bit integer /// 128 bit integer of which the lower 64 bits are returned /// The lower 64 bits of the specified 128 bit integer std::uint64_t lower64(Nuclex::Pixels::uint128_t integer) { return static_cast(integer); } // ------------------------------------------------------------------------------------------- // } // anonymous namespace namespace Nuclex { namespace Pixels { namespace PixelFormats { // ------------------------------------------------------------------------------------------- // TEST(BitMaskTest, BitMaskCanBeSingleBit) { EXPECT_EQ((BitMask), 1U); EXPECT_EQ((BitMask), 2U); EXPECT_EQ((BitMask), 4U); EXPECT_EQ((BitMask), 8U); EXPECT_EQ((BitMask), 16U); EXPECT_EQ((BitMask), 32U); EXPECT_EQ((BitMask), 64U); EXPECT_EQ((BitMask), 128U); EXPECT_EQ((BitMask), 256U); EXPECT_EQ((BitMask), 512U); EXPECT_EQ((BitMask), 1024U); } // ------------------------------------------------------------------------------------------- // TEST(BitMaskTest, BitMaskCanBeAllBits) { std::size_t maximumSizeT = std::numeric_limits::max(); EXPECT_EQ((BitMask), maximumSizeT); } // ------------------------------------------------------------------------------------------- // TEST(BitMaskTest, BitMaskCanBeNoBits) { EXPECT_EQ((BitMask), 0U); EXPECT_EQ((BitMask), 0U); EXPECT_EQ((BitMask), 0U); } // ------------------------------------------------------------------------------------------- // TEST(BitMaskTest, EachBitCanBeSet) { EXPECT_EQ((BitMask), (1U << 0)); EXPECT_EQ((BitMask), (1U << 1)); EXPECT_EQ((BitMask), (1U << 2)); EXPECT_EQ((BitMask), (1U << 3)); EXPECT_EQ((BitMask), (1U << 4)); EXPECT_EQ((BitMask), (1U << 5)); EXPECT_EQ((BitMask), (1U << 6)); EXPECT_EQ((BitMask), (1U << 7)); } // ------------------------------------------------------------------------------------------- // TEST(BitMaskTest, RealWorldBitMasksAreCorrect) { EXPECT_EQ((BitMask), 0x001FU); EXPECT_EQ((BitMask), 0x07E0U); EXPECT_EQ((BitMask), 0xF800U); EXPECT_EQ((BitMask), 0x000000FFU); EXPECT_EQ((BitMask), 0x0000FF00U); EXPECT_EQ((BitMask), 0x00FF0000U); EXPECT_EQ((BitMask), 0xFF000000U); EXPECT_EQ((BitMask), 0x000003FFU); EXPECT_EQ((BitMask), 0x000FFC00U); EXPECT_EQ((BitMask), 0x3FF00000U); EXPECT_EQ((BitMask), 0xC0000000U); } // ------------------------------------------------------------------------------------------- // TEST(BitMaskTest, WorksWith128BitInteger) { uint128_t middleBits = BitMask; EXPECT_EQ(upper64(middleBits), 0x00000000FFFFFFFFU); EXPECT_EQ(lower64(middleBits), 0xFFFFFFFF00000000U); uint128_t lowerBits = BitMask; EXPECT_EQ(upper64(lowerBits), 0x0000000000000000U); EXPECT_EQ(lower64(lowerBits), 0x00000000FFFFFFFFU); uint128_t upperBits = BitMask; EXPECT_EQ(upper64(upperBits), 0xFFFFFFFF00000000U); EXPECT_EQ(lower64(upperBits), 0x0000000000000000U); } // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Pixels::PixelFormats