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

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

Issue 1360943004: Revert of 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, 2 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"
11 #include "base/bind.h" 10 #include "base/bind.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
13 12
14 namespace { 13 namespace {
15 14
16 std::map<std::string, std::string>* key_values_ = nullptr; 15 std::map<std::string, std::string>* key_values_ = NULL;
17 16
18 } // namespace 17 } // namespace
19 18
20 class CrashLoggingTest : public testing::Test { 19 class CrashLoggingTest : public testing::Test {
21 public: 20 public:
22 void SetUp() override { 21 void SetUp() override {
23 key_values_ = new std::map<std::string, std::string>; 22 key_values_ = new std::map<std::string, std::string>;
24 base::debug::SetCrashKeyReportingFunctions( 23 base::debug::SetCrashKeyReportingFunctions(
25 &CrashLoggingTest::SetKeyValue, 24 &CrashLoggingTest::SetKeyValue,
26 &CrashLoggingTest::ClearKeyValue); 25 &CrashLoggingTest::ClearKeyValue);
27 } 26 }
28 27
29 void TearDown() override { 28 void TearDown() override {
29 base::debug::ResetCrashLoggingForTesting();
30
30 delete key_values_; 31 delete key_values_;
31 key_values_ = nullptr; 32 key_values_ = NULL;
32 } 33 }
33 34
34 private: 35 private:
35 static void SetKeyValue(const base::StringPiece& key, 36 static void SetKeyValue(const base::StringPiece& key,
36 const base::StringPiece& value) { 37 const base::StringPiece& value) {
37 (*key_values_)[key.as_string()] = value.as_string(); 38 (*key_values_)[key.as_string()] = value.as_string();
38 } 39 }
39 40
40 static void ClearKeyValue(const base::StringPiece& key) { 41 static void ClearKeyValue(const base::StringPiece& key) {
41 key_values_->erase(key.as_string()); 42 key_values_->erase(key.as_string());
42 } 43 }
43
44 // The ShadowingAtExitManager will destroy the singleton used to store crash
45 // key data upon destruction.
46 base::ShadowingAtExitManager at_exit_manager_;
47 }; 44 };
48 45
49 TEST_F(CrashLoggingTest, SetClearSingle) { 46 TEST_F(CrashLoggingTest, SetClearSingle) {
50 const char kTestKey[] = "test-key"; 47 const char kTestKey[] = "test-key";
51 base::debug::CrashKey keys[] = { { kTestKey, 255 } }; 48 base::debug::CrashKey keys[] = { { kTestKey, 255 } };
52 base::debug::InitCrashKeys(keys, arraysize(keys), 255); 49 base::debug::InitCrashKeys(keys, arraysize(keys), 255);
53 50
54 base::debug::SetCrashKeyValue(kTestKey, "value"); 51 base::debug::SetCrashKeyValue(kTestKey, "value");
55 EXPECT_EQ("value", (*key_values_)[kTestKey]); 52 EXPECT_EQ("value", (*key_values_)[kTestKey]);
56 53
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 EXPECT_EQ("wor", results[2]); 173 EXPECT_EQ("wor", results[2]);
177 EXPECT_EQ("ld", results[3]); 174 EXPECT_EQ("ld", results[3]);
178 } 175 }
179 176
180 TEST_F(CrashLoggingTest, ChunkRounding) { 177 TEST_F(CrashLoggingTest, ChunkRounding) {
181 // If max_length=12 and max_chunk_length=5, there should be 3 chunks, 178 // If max_length=12 and max_chunk_length=5, there should be 3 chunks,
182 // not 2. 179 // not 2.
183 base::debug::CrashKey key = { "round", 12 }; 180 base::debug::CrashKey key = { "round", 12 };
184 EXPECT_EQ(3u, base::debug::InitCrashKeys(&key, 1, 5)); 181 EXPECT_EQ(3u, base::debug::InitCrashKeys(&key, 1, 5));
185 } 182 }
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