| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "headless/public/util/error_reporter.h" | 5 #include "headless/public/util/error_reporter.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 namespace headless { | 8 namespace headless { |
| 9 | 9 |
| 10 TEST(ErrorReporterTest, NoErrors) { | 10 TEST(ErrorReporterTest, NoErrors) { |
| 11 ErrorReporter reporter; | 11 ErrorReporter reporter; |
| 12 #if DCHECK_IS_ON() |
| 12 EXPECT_FALSE(reporter.HasErrors()); | 13 EXPECT_FALSE(reporter.HasErrors()); |
| 13 EXPECT_TRUE(reporter.errors().empty()); | 14 EXPECT_TRUE(reporter.errors().empty()); |
| 15 #endif // DCHECK_IS_ON() |
| 14 } | 16 } |
| 15 | 17 |
| 16 TEST(ErrorReporterTest, TopLevelErrors) { | 18 TEST(ErrorReporterTest, TopLevelErrors) { |
| 17 ErrorReporter reporter; | 19 ErrorReporter reporter; |
| 18 reporter.AddError("instructions unclear"); | 20 reporter.AddError("instructions unclear"); |
| 19 reporter.AddError("head stuck in std::unordered_map"); | 21 reporter.AddError("head stuck in std::unordered_map"); |
| 22 #if DCHECK_IS_ON() |
| 20 EXPECT_TRUE(reporter.HasErrors()); | 23 EXPECT_TRUE(reporter.HasErrors()); |
| 21 EXPECT_EQ(2u, reporter.errors().size()); | 24 EXPECT_EQ(2u, reporter.errors().size()); |
| 22 EXPECT_EQ("instructions unclear", reporter.errors()[0]); | 25 EXPECT_EQ("instructions unclear", reporter.errors()[0]); |
| 23 EXPECT_EQ("head stuck in std::unordered_map", reporter.errors()[1]); | 26 EXPECT_EQ("head stuck in std::unordered_map", reporter.errors()[1]); |
| 27 #endif // DCHECK_IS_ON() |
| 24 } | 28 } |
| 25 | 29 |
| 26 TEST(ErrorReporterTest, UnnamedContext) { | 30 TEST(ErrorReporterTest, UnnamedContext) { |
| 27 ErrorReporter reporter; | 31 ErrorReporter reporter; |
| 28 reporter.Push(); | 32 reporter.Push(); |
| 29 reporter.AddError("lp0 is on fire"); | 33 reporter.AddError("lp0 is on fire"); |
| 30 reporter.Pop(); | 34 reporter.Pop(); |
| 35 #if DCHECK_IS_ON() |
| 31 EXPECT_TRUE(reporter.HasErrors()); | 36 EXPECT_TRUE(reporter.HasErrors()); |
| 32 EXPECT_EQ(1u, reporter.errors().size()); | 37 EXPECT_EQ(1u, reporter.errors().size()); |
| 33 EXPECT_EQ("lp0 is on fire", reporter.errors()[0]); | 38 EXPECT_EQ("lp0 is on fire", reporter.errors()[0]); |
| 39 #endif // DCHECK_IS_ON() |
| 34 } | 40 } |
| 35 | 41 |
| 36 TEST(ErrorReporterTest, NestedContexts) { | 42 TEST(ErrorReporterTest, NestedContexts) { |
| 37 ErrorReporter reporter; | 43 ErrorReporter reporter; |
| 38 reporter.Push(); | 44 reporter.Push(); |
| 39 reporter.SetName("ship"); | 45 reporter.SetName("ship"); |
| 40 reporter.Push(); | 46 reporter.Push(); |
| 41 reporter.SetName("front"); | 47 reporter.SetName("front"); |
| 42 reporter.AddError("fell off"); | 48 reporter.AddError("fell off"); |
| 43 reporter.Pop(); | 49 reporter.Pop(); |
| 44 reporter.AddError("uh oh"); | 50 reporter.AddError("uh oh"); |
| 45 reporter.Pop(); | 51 reporter.Pop(); |
| 52 #if DCHECK_IS_ON() |
| 46 EXPECT_TRUE(reporter.HasErrors()); | 53 EXPECT_TRUE(reporter.HasErrors()); |
| 47 EXPECT_EQ(2u, reporter.errors().size()); | 54 EXPECT_EQ(2u, reporter.errors().size()); |
| 48 EXPECT_EQ("ship.front: fell off", reporter.errors()[0]); | 55 EXPECT_EQ("ship.front: fell off", reporter.errors()[0]); |
| 49 EXPECT_EQ("ship: uh oh", reporter.errors()[1]); | 56 EXPECT_EQ("ship: uh oh", reporter.errors()[1]); |
| 57 #endif // DCHECK_IS_ON() |
| 50 } | 58 } |
| 51 | 59 |
| 52 } // namespace headless | 60 } // namespace headless |
| OLD | NEW |