| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "headless/public/util/error_reporter.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 |
| 8 namespace headless { |
| 9 |
| 10 TEST(ErrorReporterTest, NoErrors) { |
| 11 ErrorReporter reporter; |
| 12 EXPECT_FALSE(reporter.HasErrors()); |
| 13 EXPECT_TRUE(reporter.errors().empty()); |
| 14 } |
| 15 |
| 16 TEST(ErrorReporterTest, TopLevelErrors) { |
| 17 ErrorReporter reporter; |
| 18 reporter.AddError("instructions unclear"); |
| 19 reporter.AddError("head stuck in std::unordered_map"); |
| 20 EXPECT_TRUE(reporter.HasErrors()); |
| 21 EXPECT_EQ(2u, reporter.errors().size()); |
| 22 EXPECT_EQ("instructions unclear", reporter.errors()[0]); |
| 23 EXPECT_EQ("head stuck in std::unordered_map", reporter.errors()[1]); |
| 24 } |
| 25 |
| 26 TEST(ErrorReporterTest, UnnamedContext) { |
| 27 ErrorReporter reporter; |
| 28 reporter.Push(); |
| 29 reporter.AddError("lp0 is on fire"); |
| 30 reporter.Pop(); |
| 31 EXPECT_TRUE(reporter.HasErrors()); |
| 32 EXPECT_EQ(1u, reporter.errors().size()); |
| 33 EXPECT_EQ("lp0 is on fire", reporter.errors()[0]); |
| 34 } |
| 35 |
| 36 TEST(ErrorReporterTest, NestedContexts) { |
| 37 ErrorReporter reporter; |
| 38 reporter.Push(); |
| 39 reporter.SetName("ship"); |
| 40 reporter.Push(); |
| 41 reporter.SetName("front"); |
| 42 reporter.AddError("fell off"); |
| 43 reporter.Pop(); |
| 44 reporter.AddError("uh oh"); |
| 45 reporter.Pop(); |
| 46 EXPECT_TRUE(reporter.HasErrors()); |
| 47 EXPECT_EQ(2u, reporter.errors().size()); |
| 48 EXPECT_EQ("ship.front: fell off", reporter.errors()[0]); |
| 49 EXPECT_EQ("ship: uh oh", reporter.errors()[1]); |
| 50 } |
| 51 |
| 52 } // namespace headless |
| OLD | NEW |