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

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: Address comments 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
« no previous file with comments | « base/debug/crash_logging.cc ('k') | chrome/common/crash_keys_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // The ShadowingAtExitManager will destroy the singleton used to store crash
45 // key data upon destruction.
46 base::ShadowingAtExitManager at_exit_manager_;
44 }; 47 };
45 48
46 TEST_F(CrashLoggingTest, SetClearSingle) { 49 TEST_F(CrashLoggingTest, SetClearSingle) {
47 const char kTestKey[] = "test-key"; 50 const char kTestKey[] = "test-key";
48 base::debug::CrashKey keys[] = { { kTestKey, 255 } }; 51 base::debug::CrashKey keys[] = { { kTestKey, 255 } };
49 base::debug::InitCrashKeys(keys, arraysize(keys), 255); 52 base::debug::InitCrashKeys(keys, arraysize(keys), 255);
50 53
51 base::debug::SetCrashKeyValue(kTestKey, "value"); 54 base::debug::SetCrashKeyValue(kTestKey, "value");
52 EXPECT_EQ("value", (*key_values_)[kTestKey]); 55 EXPECT_EQ("value", (*key_values_)[kTestKey]);
53 56
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 EXPECT_EQ("wor", results[2]); 176 EXPECT_EQ("wor", results[2]);
174 EXPECT_EQ("ld", results[3]); 177 EXPECT_EQ("ld", results[3]);
175 } 178 }
176 179
177 TEST_F(CrashLoggingTest, ChunkRounding) { 180 TEST_F(CrashLoggingTest, ChunkRounding) {
178 // If max_length=12 and max_chunk_length=5, there should be 3 chunks, 181 // If max_length=12 and max_chunk_length=5, there should be 3 chunks,
179 // not 2. 182 // not 2.
180 base::debug::CrashKey key = { "round", 12 }; 183 base::debug::CrashKey key = { "round", 12 };
181 EXPECT_EQ(3u, base::debug::InitCrashKeys(&key, 1, 5)); 184 EXPECT_EQ(3u, base::debug::InitCrashKeys(&key, 1, 5));
182 } 185 }
OLDNEW
« no previous file with comments | « base/debug/crash_logging.cc ('k') | chrome/common/crash_keys_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698