/* * Copyright (C) 2017-2020 The Project X-Ray Authors. * * Use of this source code is governed by a ISC-style * license that can be found in the LICENSE file or at * https://opensource.org/licenses/ISC * * SPDX-License-Identifier: ISC */ #include #include #include #include TEST(BigEndianSpanTest, Read32WithEmptySpan) { std::vector bytes; auto words = prjxray::make_big_endian_span(bytes); EXPECT_EQ(words.size(), static_cast(0)); } TEST(BigEndianSpanTest, Read32WithTooFewBytes) { std::vector bytes{0x0, 0x1, 0x2}; auto words = prjxray::make_big_endian_span(bytes); EXPECT_EQ(words.size(), static_cast(0)); } TEST(BigEndianSpanTest, Read32WithExactBytes) { std::vector bytes{0x0, 0x1, 0x2, 0x3}; auto words = prjxray::make_big_endian_span(bytes); ASSERT_EQ(words.size(), static_cast(1)); EXPECT_EQ(words[0], static_cast(0x00010203)); } TEST(BigEndianSpanTest, Read32WithMultipleWords) { std::vector bytes{0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7}; auto words = prjxray::make_big_endian_span(bytes); ASSERT_EQ(words.size(), static_cast(2)); EXPECT_EQ(words[0], static_cast(0x00010203)); EXPECT_EQ(words[1], static_cast(0x04050607)); } TEST(BigEndianSpanTest, Write32) { std::vector bytes{0x0, 0x1, 0x2, 0x3}; auto words = prjxray::make_big_endian_span(bytes); words[0] = 0x04050607; std::vector expected{0x4, 0x5, 0x6, 0x7}; EXPECT_EQ(bytes, expected); }