byte_order_test.cc (1191B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #include "lib/jxl/base/byte_order.h" 7 8 #include "lib/jxl/testing.h" 9 10 namespace jxl { 11 namespace { 12 13 TEST(ByteOrderTest, TestRoundTripBE16) { 14 const uint32_t in = 0x1234; 15 uint8_t buf[2]; 16 StoreBE16(in, buf); 17 EXPECT_EQ(in, LoadBE16(buf)); 18 EXPECT_NE(in, LoadLE16(buf)); 19 } 20 21 TEST(ByteOrderTest, TestRoundTripLE16) { 22 const uint32_t in = 0x1234; 23 uint8_t buf[2]; 24 StoreLE16(in, buf); 25 EXPECT_EQ(in, LoadLE16(buf)); 26 EXPECT_NE(in, LoadBE16(buf)); 27 } 28 29 TEST(ByteOrderTest, TestRoundTripBE32) { 30 const uint32_t in = 0xFEDCBA98u; 31 uint8_t buf[4]; 32 StoreBE32(in, buf); 33 EXPECT_EQ(in, LoadBE32(buf)); 34 EXPECT_NE(in, LoadLE32(buf)); 35 } 36 37 TEST(ByteOrderTest, TestRoundTripLE32) { 38 const uint32_t in = 0xFEDCBA98u; 39 uint8_t buf[4]; 40 StoreLE32(in, buf); 41 EXPECT_EQ(in, LoadLE32(buf)); 42 EXPECT_NE(in, LoadBE32(buf)); 43 } 44 45 TEST(ByteOrderTest, TestRoundTripLE64) { 46 const uint64_t in = 0xFEDCBA9876543210ull; 47 uint8_t buf[8]; 48 StoreLE64(in, buf); 49 EXPECT_EQ(in, LoadLE64(buf)); 50 } 51 52 } // namespace 53 } // namespace jxl