Yusuke Sato | 0d6eb57 | 2021-04-06 23:48:46 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "components/arc/session/arc_instance_mode.h" |
| 6 | |
| 7 | #include <sstream> |
| 8 | |
Yusuke Sato | 0d6eb57 | 2021-04-06 23:48:46 | [diff] [blame] | 9 | #include "testing/gtest/include/gtest/gtest.h" |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame^] | 10 | #include "third_party/abseil-cpp/absl/types/optional.h" |
Yusuke Sato | 0d6eb57 | 2021-04-06 23:48:46 | [diff] [blame] | 11 | |
| 12 | namespace arc { |
| 13 | namespace { |
| 14 | |
| 15 | // Test that ArcInstanceMode can be logged. |
| 16 | TEST(ArcInstanceModeTest, TestLogging) { |
| 17 | std::ostringstream mini; |
| 18 | mini << ArcInstanceMode::MINI_INSTANCE; |
| 19 | EXPECT_FALSE(mini.str().empty()); |
| 20 | |
| 21 | std::ostringstream full; |
| 22 | full << ArcInstanceMode::FULL_INSTANCE; |
| 23 | EXPECT_FALSE(full.str().empty()); |
| 24 | EXPECT_NE(mini.str(), full.str()); |
| 25 | |
| 26 | std::ostringstream invalid; |
| 27 | invalid << static_cast<ArcInstanceMode>(-1); |
| 28 | EXPECT_TRUE(invalid.str().empty()) << invalid.str(); |
| 29 | } |
| 30 | |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame^] | 31 | // Test that absl::optional<ArcInstanceMode> can be logged too. |
Yusuke Sato | 0d6eb57 | 2021-04-06 23:48:46 | [diff] [blame] | 32 | TEST(ArcInstanceModeTest, TestLoggingWithOptional) { |
| 33 | std::ostringstream nullopt; |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame^] | 34 | nullopt << absl::optional<ArcInstanceMode>(); |
Yusuke Sato | 0d6eb57 | 2021-04-06 23:48:46 | [diff] [blame] | 35 | EXPECT_FALSE(nullopt.str().empty()); |
| 36 | |
| 37 | std::ostringstream non_nullopt; |
Anton Bikineev | 1156b5f | 2021-05-15 22:35:36 | [diff] [blame^] | 38 | non_nullopt << absl::optional<ArcInstanceMode>( |
Yusuke Sato | 0d6eb57 | 2021-04-06 23:48:46 | [diff] [blame] | 39 | ArcInstanceMode::MINI_INSTANCE); |
| 40 | EXPECT_FALSE(non_nullopt.str().empty()); |
| 41 | EXPECT_NE(nullopt.str(), non_nullopt.str()); |
| 42 | |
| 43 | std::ostringstream value; |
| 44 | value << ArcInstanceMode::MINI_INSTANCE; |
| 45 | EXPECT_FALSE(value.str().empty()); |
| 46 | EXPECT_EQ(non_nullopt.str(), value.str()); |
| 47 | } |
| 48 | |
| 49 | } // namespace |
| 50 | } // namespace arc |