OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
erikwright (departed)
2013/06/13 01:26:24
2013
Scott Hess - ex-Googler
2013/06/13 03:23:27
Done.
| |
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 "sql/test/scoped_error_ignorer.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/logging.h" | |
erikwright (departed)
2013/06/13 01:26:24
not required.
Scott Hess - ex-Googler
2013/06/13 03:23:27
Done.
| |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 namespace sql { | |
12 | |
13 ScopedErrorIgnorer::ScopedErrorIgnorer() | |
14 : checked_(false) { | |
15 Connection::SetErrorIgnorer( | |
erikwright (departed)
2013/06/13 01:26:24
include connection.h in this .cc file
Scott Hess - ex-Googler
2013/06/13 03:23:27
Done.
| |
16 base::Bind(&sql::ScopedErrorIgnorer::ShouldIgnore, | |
erikwright (departed)
2013/06/13 01:26:24
no sql namespace required here.
Scott Hess - ex-Googler
2013/06/13 03:23:27
Done.
| |
17 base::Unretained(this))); | |
18 } | |
19 | |
20 ScopedErrorIgnorer::~ScopedErrorIgnorer() { | |
21 if (!checked_) | |
22 ADD_FAILURE() << " Test must call CheckIgnoredErrors()"; | |
erikwright (departed)
2013/06/13 01:26:24
This can also be EXPECT_FALSE(checked) << "...";
Scott Hess - ex-Googler
2013/06/13 03:23:27
Done.
| |
23 | |
24 Connection::ResetErrorIgnorer(); | |
25 } | |
26 | |
27 void ScopedErrorIgnorer::IgnoreError(int err) { | |
28 if (ignore_errors_.count(err)) | |
29 ADD_FAILURE() << " Error " << err << " is already ignored"; | |
erikwright (departed)
2013/06/13 01:26:24
same here.
Scott Hess - ex-Googler
2013/06/13 03:23:27
Done.
| |
30 ignore_errors_.insert(err); | |
31 } | |
32 | |
33 bool ScopedErrorIgnorer::CheckIgnoredErrors() { | |
34 checked_ = true; | |
35 return errors_ignored_ == ignore_errors_; | |
36 } | |
37 | |
38 bool ScopedErrorIgnorer::ShouldIgnore(int err) { | |
39 // Look for extended code. | |
40 if (ignore_errors_.count(err) > 0) { | |
41 // Record that the error was seen and ignore it. | |
42 errors_ignored_.insert(err); | |
43 return true; | |
44 } | |
45 | |
46 // Trim extended codes and check again. | |
47 int base_err = err & 0xff; | |
48 if (ignore_errors_.count(base_err) > 0) { | |
49 // Record that the error was seen and ignore it. | |
50 errors_ignored_.insert(base_err); | |
51 return true; | |
52 } | |
53 | |
54 // Unexpected error. | |
55 ADD_FAILURE() << " Unexpected SQLite error " << err; | |
erikwright (departed)
2013/06/13 01:26:24
Personally I wonder why we would DCHECK on unexpec
Scott Hess - ex-Googler
2013/06/13 03:23:27
I am wondering that myself. I can see the utility
| |
56 | |
57 // TODO(shess): If it never makes sense to pass through an error | |
58 // under the test harness, then perhaps the ignore callback | |
59 // signature should be changed. | |
60 return true; | |
61 } | |
62 | |
63 } // namespace sql | |
OLD | NEW |