1 // Copyright 2022 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "partition_alloc/reverse_bytes.h" 6 7 #include <cstdint> 8 9 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 12 namespace partition_alloc::internal { 13 namespace { 14 TEST(ReverseBytes,DeadBeefScramble)15TEST(ReverseBytes, DeadBeefScramble) { 16 if (sizeof(uintptr_t) == 4) { 17 EXPECT_EQ(ReverseBytes(uintptr_t{0xefbeadde}), 0xdeadbeef); 18 } else { 19 // Hacky kludge to escape the compiler from immediately noticing that 20 // this won't fit into a uintptr_t when it's four bytes. 21 EXPECT_EQ(ReverseBytes(uint64_t{0xffeeddccefbeadde}), 0xdeadbeefccddeeff); 22 } 23 } 24 25 } // namespace 26 } // namespace partition_alloc::internal 27