xref: /aosp_15_r20/external/abseil-cpp/absl/strings/has_ostream_operator_test.cc (revision 9356374a3709195abf420251b3e825997ff56c0f)
1 // Copyright 2023 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/has_ostream_operator.h"
16 
17 #include <ostream>
18 #include <string>
19 
20 #include "gtest/gtest.h"
21 #include "absl/types/optional.h"
22 
23 namespace {
24 
25 struct TypeWithoutOstreamOp {};
26 
27 struct TypeWithOstreamOp {
operator <<(std::ostream & os,const TypeWithOstreamOp &)28   friend std::ostream& operator<<(std::ostream& os, const TypeWithOstreamOp&) {
29     return os;
30   }
31 };
32 
TEST(HasOstreamOperatorTest,Works)33 TEST(HasOstreamOperatorTest, Works) {
34   EXPECT_TRUE(absl::HasOstreamOperator<int>::value);
35   EXPECT_TRUE(absl::HasOstreamOperator<std::string>::value);
36   EXPECT_FALSE(absl::HasOstreamOperator<absl::optional<int>>::value);
37   EXPECT_FALSE(absl::HasOstreamOperator<TypeWithoutOstreamOp>::value);
38   EXPECT_TRUE(absl::HasOstreamOperator<TypeWithOstreamOp>::value);
39 }
40 
41 }  // namespace
42