|
| 1 | + |
| 2 | +// Copyright 2023 Henrik Steffen Gaßmann |
| 3 | +// |
| 4 | +// Distributed under the Boost Software License, Version 1.0. |
| 5 | +// (See accompanying file LICENSE or copy at |
| 6 | +// https://www.boost.org/LICENSE_1_0.txt) |
| 7 | + |
| 8 | +#include "dplx/dp/codecs/uuid.hpp" |
| 9 | + |
| 10 | +#include <catch2/catch_test_macros.hpp> |
| 11 | +#include <catch2/generators/catch_generators.hpp> |
| 12 | + |
| 13 | +#include <dplx/dp/api.hpp> |
| 14 | + |
| 15 | +#include "blob_matcher.hpp" |
| 16 | +#include "item_sample_ct.hpp" |
| 17 | +#include "range_generator.hpp" |
| 18 | +#include "test_input_stream.hpp" |
| 19 | +#include "test_output_stream.hpp" |
| 20 | +#include "test_utils.hpp" |
| 21 | + |
| 22 | +namespace dp_tests |
| 23 | +{ |
| 24 | + |
| 25 | +namespace |
| 26 | +{ |
| 27 | + |
| 28 | +using namespace cncr::uuid_literals; |
| 29 | + |
| 30 | +constexpr item_sample_ct<cncr::uuid, 20U> uuid_samples[] = { |
| 31 | + {"00000000-0000-0000-0000-000000000000"_uuid, |
| 32 | + 17, {0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 33 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, |
| 34 | + {"00000000-0000-4000-bfff-ffffffffffff"_uuid, |
| 35 | + 17, {0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0xbf, 0xff, |
| 36 | + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}, |
| 37 | + {"ffffffff-ffff-ffff-ffff-ffffffffffff"_uuid, |
| 38 | + 17, {0x50, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 39 | + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}, |
| 40 | +}; |
| 41 | + |
| 42 | +} // namespace |
| 43 | + |
| 44 | +TEST_CASE("cncr::uuid has a codec") |
| 45 | +{ |
| 46 | + auto const sample = GENERATE(borrowed_range(uuid_samples)); |
| 47 | + INFO(sample); |
| 48 | + |
| 49 | + SECTION("with encode") |
| 50 | + { |
| 51 | + simple_test_output_stream outputStream(sample.encoded_length); |
| 52 | + |
| 53 | + REQUIRE(dp::encode(outputStream, sample.value)); |
| 54 | + |
| 55 | + CHECK_BLOB_EQ(outputStream.written(), sample.encoded_bytes()); |
| 56 | + } |
| 57 | + SECTION("with size_of") |
| 58 | + { |
| 59 | + CHECK(dp::encoded_size_of(sample.value) == sample.encoded_length); |
| 60 | + } |
| 61 | + SECTION("with decode") |
| 62 | + { |
| 63 | + simple_test_input_stream inputStream(sample.encoded_bytes()); |
| 64 | + |
| 65 | + cncr::uuid value{}; |
| 66 | + REQUIRE(dp::decode(inputStream, value)); |
| 67 | + |
| 68 | + CHECK(value == sample.value); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +} // namespace dp_tests |
0 commit comments