-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33d994b
commit a33afd1
Showing
3 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (C) 2023 Albin Johansson (GNU General Public License v3.0) | ||
|
||
#include "tactile/core/platform/bits.hpp" | ||
|
||
#include <bit> // bit_cast | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "tactile/core/container/array.hpp" | ||
|
||
using namespace tactile; | ||
|
||
TEST(BitUtilities, ReverseBytes) | ||
{ | ||
using ByteArray = Array<uint8, sizeof(uint32)>; | ||
|
||
const uint32 original = 0xDEADBEEF; | ||
const auto swapped = reverse_bytes(original); | ||
|
||
const auto original_bytes = std::bit_cast<ByteArray>(original); | ||
const auto swapped_bytes = std::bit_cast<ByteArray>(swapped); | ||
|
||
EXPECT_EQ(original_bytes.at(0), swapped_bytes.at(3)); | ||
EXPECT_EQ(original_bytes.at(1), swapped_bytes.at(2)); | ||
EXPECT_EQ(original_bytes.at(2), swapped_bytes.at(1)); | ||
EXPECT_EQ(original_bytes.at(3), swapped_bytes.at(0)); | ||
} |