File: utility_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 (57 lines) | stat: -rw-r--r-- 1,519 bytes parent folder | download | duplicates (3)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include <gtest/gtest.h>
#include <initializer_list>
#include <string>
#include <tuple>
#include <type_traits>
#include <vector>

#include "opentelemetry/nostd/utility.h"

namespace nostd = opentelemetry::nostd;

template <class T>
auto IsDataCallable(const T &t) -> decltype(nostd::data(t), std::true_type{});

std::false_type IsDataCallable(...);

template <class T>
auto IsSizeCallable(const T &t) -> decltype(nostd::size(t), std::true_type{});

std::false_type IsSizeCallable(...);

TEST(UtilityTest, Data)
{
  std::vector<int> v = {1, 2, 3};
  int array[3]       = {1, 2, 3};
  std::initializer_list<int> list{1, 2, 3};
  int x       = 0;
  std::ignore = x;

  EXPECT_EQ(nostd::data(v), v.data());
  EXPECT_EQ(nostd::data(array), array);
  EXPECT_EQ(nostd::data(list), list.begin());
  EXPECT_FALSE(decltype(IsDataCallable(x)){});
}

TEST(UtilityTest, Size)
{
  std::vector<int> v = {1, 2, 3};
  int array[3]       = {1, 2, 3};
  int x              = 0;
  std::ignore        = x;

  EXPECT_EQ(nostd::size(v), v.size());
  EXPECT_EQ(nostd::size(array), 3);

  EXPECT_FALSE(decltype(IsSizeCallable(x)){});
}

TEST(UtilityTest, MakeIndexSequence)
{
  EXPECT_TRUE((std::is_same<nostd::make_index_sequence<0>, nostd::index_sequence<>>::value));
  EXPECT_TRUE((std::is_same<nostd::make_index_sequence<1>, nostd::index_sequence<0>>::value));
  EXPECT_TRUE((std::is_same<nostd::make_index_sequence<2>, nostd::index_sequence<0, 1>>::value));
}