| OLD | NEW |
| 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 const base::StringPiece& value) { | 37 const base::StringPiece& value) { |
| 38 (*key_values_)[key.as_string()] = value.as_string(); | 38 (*key_values_)[key.as_string()] = value.as_string(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 static void ClearKeyValue(const base::StringPiece& key) { | 41 static void ClearKeyValue(const base::StringPiece& key) { |
| 42 key_values_->erase(key.as_string()); | 42 key_values_->erase(key.as_string()); |
| 43 } | 43 } |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 TEST_F(CrashLoggingTest, SetClearSingle) { | 46 TEST_F(CrashLoggingTest, SetClearSingle) { |
| 47 const char* kTestKey = "test-key"; | 47 const char kTestKey[] = "test-key"; |
| 48 base::debug::CrashKey keys[] = { { kTestKey, 255 } }; | 48 base::debug::CrashKey keys[] = { { kTestKey, 255 } }; |
| 49 base::debug::InitCrashKeys(keys, arraysize(keys), 255); | 49 base::debug::InitCrashKeys(keys, arraysize(keys), 255); |
| 50 | 50 |
| 51 base::debug::SetCrashKeyValue(kTestKey, "value"); | 51 base::debug::SetCrashKeyValue(kTestKey, "value"); |
| 52 EXPECT_EQ("value", (*key_values_)[kTestKey]); | 52 EXPECT_EQ("value", (*key_values_)[kTestKey]); |
| 53 | 53 |
| 54 base::debug::ClearCrashKey(kTestKey); | 54 base::debug::ClearCrashKey(kTestKey); |
| 55 EXPECT_TRUE(key_values_->end() == key_values_->find(kTestKey)); | 55 EXPECT_TRUE(key_values_->end() == key_values_->find(kTestKey)); |
| 56 } | 56 } |
| 57 | 57 |
| 58 TEST_F(CrashLoggingTest, SetChunked) { | 58 TEST_F(CrashLoggingTest, SetChunked) { |
| 59 const char* kTestKey = "chunky"; | 59 const char kTestKey[] = "chunky"; |
| 60 const char* kChunk1 = "chunky-1"; | 60 const char kChunk1[] = "chunky-1"; |
| 61 const char* kChunk2 = "chunky-2"; | 61 const char kChunk2[] = "chunky-2"; |
| 62 const char* kChunk3 = "chunky-3"; | 62 const char kChunk3[] = "chunky-3"; |
| 63 base::debug::CrashKey keys[] = { { kTestKey, 15 } }; | 63 base::debug::CrashKey keys[] = { { kTestKey, 15 } }; |
| 64 base::debug::InitCrashKeys(keys, arraysize(keys), 5); | 64 base::debug::InitCrashKeys(keys, arraysize(keys), 5); |
| 65 | 65 |
| 66 std::map<std::string, std::string>& values = *key_values_; | 66 std::map<std::string, std::string>& values = *key_values_; |
| 67 | 67 |
| 68 // Fill only the first chunk. | 68 // Fill only the first chunk. |
| 69 base::debug::SetCrashKeyValue(kTestKey, "foo"); | 69 base::debug::SetCrashKeyValue(kTestKey, "foo"); |
| 70 EXPECT_EQ(1u, values.size()); | 70 EXPECT_EQ(1u, values.size()); |
| 71 EXPECT_EQ("foo", values[kChunk1]); | 71 EXPECT_EQ("foo", values[kChunk1]); |
| 72 EXPECT_TRUE(values.end() == values.find(kChunk2)); | 72 EXPECT_TRUE(values.end() == values.find(kChunk2)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 97 | 97 |
| 98 // Clear everything. | 98 // Clear everything. |
| 99 base::debug::ClearCrashKey(kTestKey); | 99 base::debug::ClearCrashKey(kTestKey); |
| 100 EXPECT_EQ(0u, values.size()); | 100 EXPECT_EQ(0u, values.size()); |
| 101 EXPECT_TRUE(values.end() == values.find(kChunk1)); | 101 EXPECT_TRUE(values.end() == values.find(kChunk1)); |
| 102 EXPECT_TRUE(values.end() == values.find(kChunk2)); | 102 EXPECT_TRUE(values.end() == values.find(kChunk2)); |
| 103 EXPECT_TRUE(values.end() == values.find(kChunk3)); | 103 EXPECT_TRUE(values.end() == values.find(kChunk3)); |
| 104 } | 104 } |
| 105 | 105 |
| 106 TEST_F(CrashLoggingTest, ScopedCrashKey) { | 106 TEST_F(CrashLoggingTest, ScopedCrashKey) { |
| 107 const char* kTestKey = "test-key"; | 107 const char kTestKey[] = "test-key"; |
| 108 base::debug::CrashKey keys[] = { { kTestKey, 255 } }; | 108 base::debug::CrashKey keys[] = { { kTestKey, 255 } }; |
| 109 base::debug::InitCrashKeys(keys, arraysize(keys), 255); | 109 base::debug::InitCrashKeys(keys, arraysize(keys), 255); |
| 110 | 110 |
| 111 EXPECT_EQ(0u, key_values_->size()); | 111 EXPECT_EQ(0u, key_values_->size()); |
| 112 EXPECT_TRUE(key_values_->end() == key_values_->find(kTestKey)); | 112 EXPECT_TRUE(key_values_->end() == key_values_->find(kTestKey)); |
| 113 { | 113 { |
| 114 base::debug::ScopedCrashKey scoped_crash_key(kTestKey, "value"); | 114 base::debug::ScopedCrashKey scoped_crash_key(kTestKey, "value"); |
| 115 EXPECT_EQ("value", (*key_values_)[kTestKey]); | 115 EXPECT_EQ("value", (*key_values_)[kTestKey]); |
| 116 EXPECT_EQ(1u, key_values_->size()); | 116 EXPECT_EQ(1u, key_values_->size()); |
| 117 } | 117 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 EXPECT_EQ("wor", results[2]); | 173 EXPECT_EQ("wor", results[2]); |
| 174 EXPECT_EQ("ld", results[3]); | 174 EXPECT_EQ("ld", results[3]); |
| 175 } | 175 } |
| 176 | 176 |
| 177 TEST_F(CrashLoggingTest, ChunkRounding) { | 177 TEST_F(CrashLoggingTest, ChunkRounding) { |
| 178 // 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, |
| 179 // not 2. | 179 // not 2. |
| 180 base::debug::CrashKey key = { "round", 12 }; | 180 base::debug::CrashKey key = { "round", 12 }; |
| 181 EXPECT_EQ(3u, base::debug::InitCrashKeys(&key, 1, 5)); | 181 EXPECT_EQ(3u, base::debug::InitCrashKeys(&key, 1, 5)); |
| 182 } | 182 } |
| OLD | NEW |