Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Side by Side Diff: base/debug/crash_logging_unittest.cc

Issue 1368703002: Use a class instead of several separate globals in crash_logging.cc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/debug/crash_logging.h" 5 #include "base/debug/crash_logging.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/at_exit.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace { 14 namespace {
14 15
15 std::map<std::string, std::string>* key_values_ = NULL; 16 std::map<std::string, std::string>* key_values_ = nullptr;
16 17
17 } // namespace 18 } // namespace
18 19
19 class CrashLoggingTest : public testing::Test { 20 class CrashLoggingTest : public testing::Test {
20 public: 21 public:
21 void SetUp() override { 22 void SetUp() override {
22 key_values_ = new std::map<std::string, std::string>; 23 key_values_ = new std::map<std::string, std::string>;
23 base::debug::SetCrashKeyReportingFunctions( 24 base::debug::SetCrashKeyReportingFunctions(
24 &CrashLoggingTest::SetKeyValue, 25 &CrashLoggingTest::SetKeyValue,
25 &CrashLoggingTest::ClearKeyValue); 26 &CrashLoggingTest::ClearKeyValue);
26 } 27 }
27 28
28 void TearDown() override { 29 void TearDown() override {
29 base::debug::ResetCrashLoggingForTesting();
30
31 delete key_values_; 30 delete key_values_;
32 key_values_ = NULL; 31 key_values_ = nullptr;
33 } 32 }
34 33
35 private: 34 private:
36 static void SetKeyValue(const base::StringPiece& key, 35 static void SetKeyValue(const base::StringPiece& key,
37 const base::StringPiece& value) { 36 const base::StringPiece& value) {
38 (*key_values_)[key.as_string()] = value.as_string(); 37 (*key_values_)[key.as_string()] = value.as_string();
39 } 38 }
40 39
41 static void ClearKeyValue(const base::StringPiece& key) { 40 static void ClearKeyValue(const base::StringPiece& key) {
42 key_values_->erase(key.as_string()); 41 key_values_->erase(key.as_string());
43 } 42 }
43
44 base::ShadowingAtExitManager at_exit_manager_;
danakj 2015/09/24 21:08:36 Can you leave a comment explaining why this is her
Robert Sesek 2015/09/24 21:28:19 Done.
44 }; 45 };
45 46
46 TEST_F(CrashLoggingTest, SetClearSingle) { 47 TEST_F(CrashLoggingTest, SetClearSingle) {
47 const char kTestKey[] = "test-key"; 48 const char kTestKey[] = "test-key";
48 base::debug::CrashKey keys[] = { { kTestKey, 255 } }; 49 base::debug::CrashKey keys[] = { { kTestKey, 255 } };
49 base::debug::InitCrashKeys(keys, arraysize(keys), 255); 50 base::debug::InitCrashKeys(keys, arraysize(keys), 255);
50 51
51 base::debug::SetCrashKeyValue(kTestKey, "value"); 52 base::debug::SetCrashKeyValue(kTestKey, "value");
52 EXPECT_EQ("value", (*key_values_)[kTestKey]); 53 EXPECT_EQ("value", (*key_values_)[kTestKey]);
53 54
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 EXPECT_EQ("wor", results[2]); 174 EXPECT_EQ("wor", results[2]);
174 EXPECT_EQ("ld", results[3]); 175 EXPECT_EQ("ld", results[3]);
175 } 176 }
176 177
177 TEST_F(CrashLoggingTest, ChunkRounding) { 178 TEST_F(CrashLoggingTest, ChunkRounding) {
178 // If max_length=12 and max_chunk_length=5, there should be 3 chunks, 179 // If max_length=12 and max_chunk_length=5, there should be 3 chunks,
179 // not 2. 180 // not 2.
180 base::debug::CrashKey key = { "round", 12 }; 181 base::debug::CrashKey key = { "round", 12 };
181 EXPECT_EQ(3u, base::debug::InitCrashKeys(&key, 1, 5)); 182 EXPECT_EQ(3u, base::debug::InitCrashKeys(&key, 1, 5));
182 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698