File: hex_test.cc

package info (click to toggle)
opentelemetry-cpp 1.23.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,368 kB
  • sloc: cpp: 96,239; sh: 1,766; makefile: 38; python: 31
file content (43 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <gtest/gtest.h>
#include <stdint.h>
#include <string>

#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/trace/propagation/detail/hex.h"

using namespace opentelemetry;

TEST(HexTest, ConvertOddLength)
{
  const int kLength        = 16;
  std::string trace_id_hex = "78cfcfec62ae9e9";
  uint8_t trace_id[kLength];
  trace::propagation::detail::HexToBinary(trace_id_hex, trace_id, sizeof(trace_id));

  const uint8_t expected_trace_id[kLength] = {0x0, 0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,
                                              0x7, 0x8c, 0xfc, 0xfe, 0xc6, 0x2a, 0xe9, 0xe9};

  for (int i = 0; i < kLength; ++i)
  {
    EXPECT_EQ(trace_id[i], expected_trace_id[i]);
  }
}

TEST(HexTest, ConvertEvenLength)
{
  const int kLength        = 16;
  std::string trace_id_hex = "078cfcfec62ae9e9";
  uint8_t trace_id[kLength];
  trace::propagation::detail::HexToBinary(trace_id_hex, trace_id, sizeof(trace_id));

  const uint8_t expected_trace_id[kLength] = {0x0, 0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0x0,
                                              0x7, 0x8c, 0xfc, 0xfe, 0xc6, 0x2a, 0xe9, 0xe9};

  for (int i = 0; i < kLength; ++i)
  {
    EXPECT_EQ(trace_id[i], expected_trace_id[i]);
  }
}