grpc
third_party
abseil-cpp
absl
strings
internal
abseil-cpp/absl/strings/internal/string_constant_test.cc
Go to the documentation of this file.
1
// Copyright 2020 The Abseil Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include "absl/strings/internal/string_constant.h"
16
17
#include "absl/meta/type_traits.h"
18
#include "gmock/gmock.h"
19
#include "gtest/gtest.h"
20
21
namespace
{
22
23
using
absl::strings_internal::MakeStringConstant
;
24
25
struct
Callable {
26
constexpr
absl::string_view
operator()()
const
{
27
return
absl::string_view
(
"Callable"
, 8);
28
}
29
};
30
31
TEST
(StringConstant, Traits) {
32
constexpr
auto
str
=
MakeStringConstant
(Callable{});
33
using
T
= decltype(
str
);
34
35
EXPECT_TRUE
(
std::is_empty<T>::value
);
36
EXPECT_TRUE
(
std::is_trivial<T>::value
);
37
EXPECT_TRUE
(
absl::is_trivially_default_constructible<T>::value
);
38
EXPECT_TRUE
(
absl::is_trivially_copy_constructible<T>::value
);
39
EXPECT_TRUE
(
absl::is_trivially_move_constructible<T>::value
);
40
EXPECT_TRUE
(
absl::is_trivially_destructible<T>::value
);
41
}
42
43
TEST
(StringConstant, MakeFromCallable) {
44
constexpr
auto
str
=
MakeStringConstant
(Callable{});
45
using
T
= decltype(
str
);
46
EXPECT_EQ
(Callable{}(),
T::value
);
47
EXPECT_EQ
(Callable{}(),
str
());
48
}
49
50
TEST
(StringConstant, MakeFromStringConstant) {
51
// We want to make sure the StringConstant itself is a valid input to the
52
// factory function.
53
constexpr
auto
str
=
MakeStringConstant
(Callable{});
54
constexpr
auto
str2 =
MakeStringConstant
(
str
);
55
using
T
= decltype(str2);
56
EXPECT_EQ
(Callable{}(),
T::value
);
57
EXPECT_EQ
(Callable{}(), str2());
58
}
59
60
}
// namespace
xds_interop_client.str
str
Definition:
xds_interop_client.py:487
absl::is_trivially_default_constructible
Definition:
abseil-cpp/absl/meta/type_traits.h:349
absl::string_view
Definition:
abseil-cpp/absl/strings/string_view.h:167
T
#define T(upbtypeconst, upbtype, ctype, default_value)
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition:
iomgr/time_averaged_stats_test.cc:27
absl::is_trivially_move_constructible
Definition:
abseil-cpp/absl/meta/type_traits.h:383
TEST
#define TEST(name, init_size,...)
Definition:
arena_test.cc:75
absl::strings_internal::MakeStringConstant
constexpr StringConstant< T > MakeStringConstant(T)
Definition:
abseil-cpp/absl/strings/internal/string_constant.h:64
value
const char * value
Definition:
hpack_parser_table.cc:165
string_view
absl::string_view string_view
Definition:
attr.cc:22
absl::is_trivially_copy_constructible
Definition:
abseil-cpp/absl/meta/type_traits.h:418
EXPECT_TRUE
#define EXPECT_TRUE(condition)
Definition:
bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1967
absl::is_trivially_destructible
Definition:
abseil-cpp/absl/meta/type_traits.h:63
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:21