From 30bb1ab6015b462b5f2c4b3ce1986dec96d1f716 Mon Sep 17 00:00:00 2001 From: "rsesek@chromium.org" Date: Thu, 18 Apr 2013 20:17:29 +0000 Subject: Move SimpleStringDictionary from common/mac/ to just common/. This also cleans up some things like the file name, trailing whitespace, and making the test use gtest instead of sentest, since there's nothing Mac specific about this. BUG=https://code.google.com/p/chromium/issues/detail?id=77656 Review URL: https://breakpad.appspot.com/561003 git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@1154 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/client/ios/Breakpad.mm | 4 +- src/client/ios/Breakpad.xcodeproj/project.pbxproj | 16 +- src/client/mac/Breakpad.xcodeproj/project.pbxproj | 32 +-- src/client/mac/Framework/Breakpad.mm | 2 +- src/client/mac/crash_generation/ConfigFile.h | 2 +- src/client/mac/crash_generation/ConfigFile.mm | 1 - src/client/mac/crash_generation/Inspector.h | 2 +- src/client/mac/crash_generation/Inspector.mm | 1 - src/client/mac/tests/SimpleStringDictionaryTest.h | 40 ---- src/client/mac/tests/SimpleStringDictionaryTest.mm | 243 --------------------- src/common/mac/SimpleStringDictionary.h | 195 ----------------- src/common/mac/SimpleStringDictionary.mm | 133 ----------- src/common/simple_string_dictionary.cc | 129 +++++++++++ src/common/simple_string_dictionary.h | 192 ++++++++++++++++ src/common/simple_string_dictionary_unittest.cc | 221 +++++++++++++++++++ 15 files changed, 571 insertions(+), 642 deletions(-) delete mode 100644 src/client/mac/tests/SimpleStringDictionaryTest.h delete mode 100644 src/client/mac/tests/SimpleStringDictionaryTest.mm delete mode 100644 src/common/mac/SimpleStringDictionary.h delete mode 100644 src/common/mac/SimpleStringDictionary.mm create mode 100644 src/common/simple_string_dictionary.cc create mode 100644 src/common/simple_string_dictionary.h create mode 100644 src/common/simple_string_dictionary_unittest.cc (limited to 'src') diff --git a/src/client/ios/Breakpad.mm b/src/client/ios/Breakpad.mm index c3758a9f..39f4dc07 100644 --- a/src/client/ios/Breakpad.mm +++ b/src/client/ios/Breakpad.mm @@ -45,13 +45,13 @@ #include #include +#import "client/ios/handler/ios_exception_minidump_generator.h" #import "client/mac/crash_generation/ConfigFile.h" #import "client/mac/handler/exception_handler.h" #import "client/mac/handler/minidump_generator.h" #import "client/mac/sender/uploader.h" -#import "common/mac/SimpleStringDictionary.h" -#import "client/ios/handler/ios_exception_minidump_generator.h" #import "client/mac/handler/protected_memory_allocator.h" +#import "common/simple_string_dictionary.h" #ifndef __EXCEPTIONS // This file uses C++ try/catch (but shouldn't). Duplicate the macros from diff --git a/src/client/ios/Breakpad.xcodeproj/project.pbxproj b/src/client/ios/Breakpad.xcodeproj/project.pbxproj index 96986f20..11d05eae 100644 --- a/src/client/ios/Breakpad.xcodeproj/project.pbxproj +++ b/src/client/ios/Breakpad.xcodeproj/project.pbxproj @@ -36,8 +36,6 @@ 16C7CE79147D4A4300776EAD /* GTMLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 16C7CC89147D4A4300776EAD /* GTMLogger.m */; }; 16C7CE7A147D4A4300776EAD /* HTTPMultipartUpload.h in Headers */ = {isa = PBXBuildFile; fileRef = 16C7CC8A147D4A4300776EAD /* HTTPMultipartUpload.h */; }; 16C7CE7B147D4A4300776EAD /* HTTPMultipartUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = 16C7CC8B147D4A4300776EAD /* HTTPMultipartUpload.m */; }; - 16C7CE7E147D4A4300776EAD /* SimpleStringDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 16C7CC8E147D4A4300776EAD /* SimpleStringDictionary.h */; }; - 16C7CE7F147D4A4300776EAD /* SimpleStringDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 16C7CC8F147D4A4300776EAD /* SimpleStringDictionary.mm */; }; 16C7CE83147D4A4300776EAD /* file_id.cc in Sources */ = {isa = PBXBuildFile; fileRef = 16C7CC93147D4A4300776EAD /* file_id.cc */; }; 16C7CE84147D4A4300776EAD /* file_id.h in Headers */ = {isa = PBXBuildFile; fileRef = 16C7CC94147D4A4300776EAD /* file_id.h */; }; 16C7CE85147D4A4300776EAD /* macho_id.cc in Sources */ = {isa = PBXBuildFile; fileRef = 16C7CC95147D4A4300776EAD /* macho_id.cc */; }; @@ -54,6 +52,8 @@ 16C7CEA8147D4A4300776EAD /* string_conversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 16C7CCBA147D4A4300776EAD /* string_conversion.h */; }; 16C92FAD150DF8330053D7BA /* BreakpadController.h in Headers */ = {isa = PBXBuildFile; fileRef = 16C92FAB150DF8330053D7BA /* BreakpadController.h */; }; 16C92FAE150DF8330053D7BA /* BreakpadController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 16C92FAC150DF8330053D7BA /* BreakpadController.mm */; }; + 1EEEB60F1720821900F7E689 /* simple_string_dictionary.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1EEEB60C1720821900F7E689 /* simple_string_dictionary.cc */; }; + 1EEEB6101720821900F7E689 /* simple_string_dictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 1EEEB60D1720821900F7E689 /* simple_string_dictionary.h */; }; AA747D9F0F9514B9006C5449 /* Breakpad_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = AA747D9E0F9514B9006C5449 /* Breakpad_Prefix.pch */; }; AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; }; /* End PBXBuildFile section */ @@ -88,8 +88,6 @@ 16C7CC89147D4A4300776EAD /* GTMLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMLogger.m; sourceTree = ""; }; 16C7CC8A147D4A4300776EAD /* HTTPMultipartUpload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTTPMultipartUpload.h; sourceTree = ""; }; 16C7CC8B147D4A4300776EAD /* HTTPMultipartUpload.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HTTPMultipartUpload.m; sourceTree = ""; }; - 16C7CC8E147D4A4300776EAD /* SimpleStringDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SimpleStringDictionary.h; sourceTree = ""; }; - 16C7CC8F147D4A4300776EAD /* SimpleStringDictionary.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SimpleStringDictionary.mm; sourceTree = ""; }; 16C7CC93147D4A4300776EAD /* file_id.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_id.cc; sourceTree = ""; }; 16C7CC94147D4A4300776EAD /* file_id.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = file_id.h; sourceTree = ""; }; 16C7CC95147D4A4300776EAD /* macho_id.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = macho_id.cc; sourceTree = ""; }; @@ -106,6 +104,8 @@ 16C7CCBA147D4A4300776EAD /* string_conversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = string_conversion.h; sourceTree = ""; }; 16C92FAB150DF8330053D7BA /* BreakpadController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BreakpadController.h; sourceTree = ""; }; 16C92FAC150DF8330053D7BA /* BreakpadController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BreakpadController.mm; sourceTree = ""; }; + 1EEEB60C1720821900F7E689 /* simple_string_dictionary.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = simple_string_dictionary.cc; sourceTree = ""; }; + 1EEEB60D1720821900F7E689 /* simple_string_dictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = simple_string_dictionary.h; sourceTree = ""; }; AA747D9E0F9514B9006C5449 /* Breakpad_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Breakpad_Prefix.pch; sourceTree = SOURCE_ROOT; }; AACBBE490F95108600F1A2B1 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; D2AAC07E0554694100DB518D /* libBreakpad.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libBreakpad.a; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -259,6 +259,8 @@ 16C7CC47147D4A4300776EAD /* common */ = { isa = PBXGroup; children = ( + 1EEEB60C1720821900F7E689 /* simple_string_dictionary.cc */, + 1EEEB60D1720821900F7E689 /* simple_string_dictionary.h */, 16C7CC4A147D4A4300776EAD /* convert_UTF.c */, 16C7CC4B147D4A4300776EAD /* convert_UTF.h */, 16C7CC82147D4A4300776EAD /* mac */, @@ -278,8 +280,6 @@ 16C7CC89147D4A4300776EAD /* GTMLogger.m */, 16C7CC8A147D4A4300776EAD /* HTTPMultipartUpload.h */, 16C7CC8B147D4A4300776EAD /* HTTPMultipartUpload.m */, - 16C7CC8E147D4A4300776EAD /* SimpleStringDictionary.h */, - 16C7CC8F147D4A4300776EAD /* SimpleStringDictionary.mm */, 16C7CC93147D4A4300776EAD /* file_id.cc */, 16C7CC94147D4A4300776EAD /* file_id.h */, 16C7CC95147D4A4300776EAD /* macho_id.cc */, @@ -324,7 +324,6 @@ 16C7CE41147D4A4300776EAD /* convert_UTF.h in Headers */, 16C7CE78147D4A4300776EAD /* GTMLogger.h in Headers */, 16C7CE7A147D4A4300776EAD /* HTTPMultipartUpload.h in Headers */, - 16C7CE7E147D4A4300776EAD /* SimpleStringDictionary.h in Headers */, 16C7CE84147D4A4300776EAD /* file_id.h in Headers */, 16C7CE86147D4A4300776EAD /* macho_id.h in Headers */, 16C7CE8B147D4A4300776EAD /* macho_utilities.h in Headers */, @@ -334,6 +333,7 @@ 16C7CEA8147D4A4300776EAD /* string_conversion.h in Headers */, 16BFA67014E195E9009704F8 /* ios_exception_minidump_generator.h in Headers */, 16C92FAD150DF8330053D7BA /* BreakpadController.h in Headers */, + 1EEEB6101720821900F7E689 /* simple_string_dictionary.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -411,7 +411,6 @@ 16C7CE40147D4A4300776EAD /* convert_UTF.c in Sources */, 16C7CE79147D4A4300776EAD /* GTMLogger.m in Sources */, 16C7CE7B147D4A4300776EAD /* HTTPMultipartUpload.m in Sources */, - 16C7CE7F147D4A4300776EAD /* SimpleStringDictionary.mm in Sources */, 16C7CE83147D4A4300776EAD /* file_id.cc in Sources */, 16C7CE85147D4A4300776EAD /* macho_id.cc in Sources */, 16C7CE8A147D4A4300776EAD /* macho_utilities.cc in Sources */, @@ -421,6 +420,7 @@ 16C7CEA7147D4A4300776EAD /* string_conversion.cc in Sources */, 16BFA67214E1965A009704F8 /* ios_exception_minidump_generator.mm in Sources */, 16C92FAE150DF8330053D7BA /* BreakpadController.mm in Sources */, + 1EEEB60F1720821900F7E689 /* simple_string_dictionary.cc in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/client/mac/Breakpad.xcodeproj/project.pbxproj b/src/client/mac/Breakpad.xcodeproj/project.pbxproj index 9864ed4a..2507710b 100644 --- a/src/client/mac/Breakpad.xcodeproj/project.pbxproj +++ b/src/client/mac/Breakpad.xcodeproj/project.pbxproj @@ -44,6 +44,11 @@ 163201E31443029300C4DBF5 /* ConfigFile.mm in Sources */ = {isa = PBXBuildFile; fileRef = 163201D51443019E00C4DBF5 /* ConfigFile.mm */; }; 16C7C918147D45AE00776EAD /* BreakpadDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 16C7C917147D45AE00776EAD /* BreakpadDefines.h */; settings = {ATTRIBUTES = (Public, ); }; }; 16E02DB8147410F0008C604D /* uploader.mm in Sources */ = {isa = PBXBuildFile; fileRef = 16E02DB4147410D4008C604D /* uploader.mm */; }; + 1EEEB6231720829E00F7E689 /* simple_string_dictionary.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1EEEB6211720829E00F7E689 /* simple_string_dictionary.cc */; }; + 1EEEB6241720829E00F7E689 /* simple_string_dictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 1EEEB6221720829E00F7E689 /* simple_string_dictionary.h */; }; + 1EEEB6271720831E00F7E689 /* BreakpadFramework_Test.mm in Sources */ = {isa = PBXBuildFile; fileRef = F91AF5CF0FD60393009D8BE2 /* BreakpadFramework_Test.mm */; }; + 1EEEB62A1720859200F7E689 /* simple_string_dictionary_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1EEEB6251720830600F7E689 /* simple_string_dictionary_unittest.cc */; }; + 1EEEB62B1720868C00F7E689 /* simple_string_dictionary.cc in Sources */ = {isa = PBXBuildFile; fileRef = 1EEEB6211720829E00F7E689 /* simple_string_dictionary.cc */; }; 3329D4ED0FA16D820007BBC5 /* Breakpad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3329D4EC0FA16D820007BBC5 /* Breakpad.xib */; }; 33880C800F9E097100817F82 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 33880C7E0F9E097100817F82 /* InfoPlist.strings */; }; 4084699D0F5D9CF900FDCA37 /* crash_report_sender.icns in Resources */ = {isa = PBXBuildFile; fileRef = 4084699C0F5D9CF900FDCA37 /* crash_report_sender.icns */; }; @@ -141,7 +146,6 @@ D2F9A53F121383A1002747C1 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D69BFE84028FC02AAC07 /* Foundation.framework */; }; D2F9A541121383A1002747C1 /* libgtest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D2F9A41512131EF0002747C1 /* libgtest.a */; }; D2F9A553121383DC002747C1 /* crash_generation_server_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = D2F9A4CE121336F7002747C1 /* crash_generation_server_test.cc */; }; - F91AF5D00FD60393009D8BE2 /* BreakpadFramework_Test.mm in Sources */ = {isa = PBXBuildFile; fileRef = F91AF5CF0FD60393009D8BE2 /* BreakpadFramework_Test.mm */; }; F91AF6210FD60784009D8BE2 /* Breakpad.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* Breakpad.framework */; }; F9286B3A0F7EB25800A4DCC8 /* InspectorMain.mm in Sources */ = {isa = PBXBuildFile; fileRef = F9286B390F7EB25800A4DCC8 /* InspectorMain.mm */; }; F92C53B80ECCE7B3009BE4BA /* Inspector.mm in Sources */ = {isa = PBXBuildFile; fileRef = F92C53B70ECCE7B3009BE4BA /* Inspector.mm */; }; @@ -159,7 +163,6 @@ F92C56450ECD10CA009BE4BA /* MachIPC.mm in Sources */ = {isa = PBXBuildFile; fileRef = F92C53790ECCE635009BE4BA /* MachIPC.mm */; }; F92C56460ECD10CA009BE4BA /* minidump_file_writer.cc in Sources */ = {isa = PBXBuildFile; fileRef = F92C538F0ECCE70A009BE4BA /* minidump_file_writer.cc */; }; F92C56470ECD10CA009BE4BA /* minidump_generator.cc in Sources */ = {isa = PBXBuildFile; fileRef = F92C536F0ECCE3FD009BE4BA /* minidump_generator.cc */; }; - F92C56480ECD10CA009BE4BA /* SimpleStringDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = F92C53810ECCE635009BE4BA /* SimpleStringDictionary.mm */; }; F92C56490ECD10CA009BE4BA /* string_utilities.cc in Sources */ = {isa = PBXBuildFile; fileRef = F92C53820ECCE635009BE4BA /* string_utilities.cc */; }; F92C564A0ECD10CA009BE4BA /* string_conversion.cc in Sources */ = {isa = PBXBuildFile; fileRef = F92C53850ECCE6AD009BE4BA /* string_conversion.cc */; }; F92C564C0ECD10DD009BE4BA /* breakpadUtilities.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = F92C563C0ECD10B3009BE4BA /* breakpadUtilities.dylib */; }; @@ -211,8 +214,6 @@ F9C44EA20EF09F93003AEBAA /* HTTPMultipartUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = F92C53770ECCE635009BE4BA /* HTTPMultipartUpload.m */; }; F9C44EE50EF0A006003AEBAA /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F9C44EE40EF0A006003AEBAA /* SystemConfiguration.framework */; }; F9C44EE90EF0A3C1003AEBAA /* GTMLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = F9C44EE80EF0A3C1003AEBAA /* GTMLogger.m */; }; - F9C77DE20F7DD7E30045F7DB /* SimpleStringDictionaryTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = F9C77DE10F7DD7E30045F7DB /* SimpleStringDictionaryTest.mm */; }; - F9C77DE40F7DD82F0045F7DB /* SimpleStringDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = F92C53810ECCE635009BE4BA /* SimpleStringDictionary.mm */; }; F9C77E130F7DDF810045F7DB /* GTMSenTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = F9C77E120F7DDF810045F7DB /* GTMSenTestCase.m */; }; /* End PBXBuildFile section */ @@ -566,6 +567,9 @@ 163202431443201300C4DBF5 /* uploader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = uploader.h; path = sender/uploader.h; sourceTree = ""; }; 16C7C917147D45AE00776EAD /* BreakpadDefines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BreakpadDefines.h; sourceTree = ""; }; 16E02DB4147410D4008C604D /* uploader.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = uploader.mm; path = sender/uploader.mm; sourceTree = ""; }; + 1EEEB6211720829E00F7E689 /* simple_string_dictionary.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = simple_string_dictionary.cc; path = ../../common/simple_string_dictionary.cc; sourceTree = ""; }; + 1EEEB6221720829E00F7E689 /* simple_string_dictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = simple_string_dictionary.h; path = ../../common/simple_string_dictionary.h; sourceTree = ""; }; + 1EEEB6251720830600F7E689 /* simple_string_dictionary_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = simple_string_dictionary_unittest.cc; path = ../../common/simple_string_dictionary_unittest.cc; sourceTree = ""; }; 32DBCF5E0370ADEE00C91783 /* Breakpad_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Breakpad_Prefix.pch; path = Framework/Breakpad_Prefix.pch; sourceTree = ""; }; 3329D4EC0FA16D820007BBC5 /* Breakpad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Breakpad.xib; path = sender/Breakpad.xib; sourceTree = ""; }; 33880C7F0F9E097100817F82 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = sender/English.lproj/InfoPlist.strings; sourceTree = ""; }; @@ -651,8 +655,6 @@ F92C537D0ECCE635009BE4BA /* macho_utilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = macho_utilities.h; path = ../../common/mac/macho_utilities.h; sourceTree = SOURCE_ROOT; }; F92C537E0ECCE635009BE4BA /* macho_walker.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = macho_walker.cc; path = ../../common/mac/macho_walker.cc; sourceTree = SOURCE_ROOT; }; F92C537F0ECCE635009BE4BA /* macho_walker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = macho_walker.h; path = ../../common/mac/macho_walker.h; sourceTree = SOURCE_ROOT; }; - F92C53800ECCE635009BE4BA /* SimpleStringDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SimpleStringDictionary.h; path = ../../common/mac/SimpleStringDictionary.h; sourceTree = SOURCE_ROOT; }; - F92C53810ECCE635009BE4BA /* SimpleStringDictionary.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SimpleStringDictionary.mm; path = ../../common/mac/SimpleStringDictionary.mm; sourceTree = SOURCE_ROOT; }; F92C53820ECCE635009BE4BA /* string_utilities.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = string_utilities.cc; path = ../../common/mac/string_utilities.cc; sourceTree = SOURCE_ROOT; }; F92C53830ECCE635009BE4BA /* string_utilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = string_utilities.h; path = ../../common/mac/string_utilities.h; sourceTree = SOURCE_ROOT; }; F92C53850ECCE6AD009BE4BA /* string_conversion.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = string_conversion.cc; path = ../../common/string_conversion.cc; sourceTree = SOURCE_ROOT; }; @@ -699,8 +701,6 @@ F9C44EE80EF0A3C1003AEBAA /* GTMLogger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GTMLogger.m; path = ../../common/mac/GTMLogger.m; sourceTree = SOURCE_ROOT; }; F9C77DDA0F7DD5CF0045F7DB /* UnitTests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; F9C77DDB0F7DD5CF0045F7DB /* UnitTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "UnitTests-Info.plist"; sourceTree = ""; }; - F9C77DE00F7DD7E30045F7DB /* SimpleStringDictionaryTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SimpleStringDictionaryTest.h; path = tests/SimpleStringDictionaryTest.h; sourceTree = ""; }; - F9C77DE10F7DD7E30045F7DB /* SimpleStringDictionaryTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SimpleStringDictionaryTest.mm; path = tests/SimpleStringDictionaryTest.mm; sourceTree = ""; }; F9C77E110F7DDF810045F7DB /* GTMSenTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GTMSenTestCase.h; path = ../../common/mac/testing/GTMSenTestCase.h; sourceTree = SOURCE_ROOT; }; F9C77E120F7DDF810045F7DB /* GTMSenTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GTMSenTestCase.m; path = ../../common/mac/testing/GTMSenTestCase.m; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ @@ -936,6 +936,8 @@ F92C53870ECCE6C0009BE4BA /* convert_UTF.c */, F92C53880ECCE6C0009BE4BA /* convert_UTF.h */, 4D72CA0D13DFAD5C006CABE3 /* md5.cc */, + 1EEEB6211720829E00F7E689 /* simple_string_dictionary.cc */, + 1EEEB6221720829E00F7E689 /* simple_string_dictionary.h */, F92C53850ECCE6AD009BE4BA /* string_conversion.cc */, F92C53860ECCE6AD009BE4BA /* string_conversion.h */, F92C53840ECCE68D009BE4BA /* mac */, @@ -967,8 +969,6 @@ F92C537D0ECCE635009BE4BA /* macho_utilities.h */, F92C537E0ECCE635009BE4BA /* macho_walker.cc */, F92C537F0ECCE635009BE4BA /* macho_walker.h */, - F92C53800ECCE635009BE4BA /* SimpleStringDictionary.h */, - F92C53810ECCE635009BE4BA /* SimpleStringDictionary.mm */, F92C53820ECCE635009BE4BA /* string_utilities.cc */, F92C53830ECCE635009BE4BA /* string_utilities.h */, ); @@ -1116,12 +1116,11 @@ F9C77DDF0F7DD7CF0045F7DB /* tests */ = { isa = PBXGroup; children = ( + 1EEEB6251720830600F7E689 /* simple_string_dictionary_unittest.cc */, D23F4B9A12A8688800686C8D /* minidump_generator_test_helper.cc */, D23F4B2C12A7E13200686C8D /* minidump_generator_test.cc */, D2F9A4CE121336F7002747C1 /* crash_generation_server_test.cc */, D2F9A3D41212F87C002747C1 /* exception_handler_test.cc */, - F9C77DE00F7DD7E30045F7DB /* SimpleStringDictionaryTest.h */, - F9C77DE10F7DD7E30045F7DB /* SimpleStringDictionaryTest.mm */, F91AF5CF0FD60393009D8BE2 /* BreakpadFramework_Test.mm */, ); name = tests; @@ -1151,6 +1150,7 @@ 163201D61443019E00C4DBF5 /* ConfigFile.h in Headers */, 16C7C918147D45AE00776EAD /* BreakpadDefines.h in Headers */, 162F64F3161C577500CD68D5 /* arch_utilities.h in Headers */, + 1EEEB6241720829E00F7E689 /* simple_string_dictionary.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1676,6 +1676,7 @@ D2F9A4CD121336C7002747C1 /* crash_generation_server.cc in Sources */, 163201D71443019E00C4DBF5 /* ConfigFile.mm in Sources */, 162F64F2161C577500CD68D5 /* arch_utilities.cc in Sources */, + 1EEEB6231720829E00F7E689 /* simple_string_dictionary.cc in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1770,7 +1771,6 @@ 4D72CA0E13DFAD5C006CABE3 /* md5.cc in Sources */, F92C56460ECD10CA009BE4BA /* minidump_file_writer.cc in Sources */, F92C56470ECD10CA009BE4BA /* minidump_generator.cc in Sources */, - F92C56480ECD10CA009BE4BA /* SimpleStringDictionary.mm in Sources */, F92C56490ECD10CA009BE4BA /* string_utilities.cc in Sources */, F92C564A0ECD10CA009BE4BA /* string_conversion.cc in Sources */, 4D61A25F14F43CFC002D5862 /* bootstrap_compat.cc in Sources */, @@ -1814,6 +1814,8 @@ D23F4B2E12A7E13200686C8D /* minidump_generator_test.cc in Sources */, 4D72CA2F13DFAE65006CABE3 /* md5.cc in Sources */, 4D61A26D14F43D43002D5862 /* bootstrap_compat.cc in Sources */, + 1EEEB62B1720868C00F7E689 /* simple_string_dictionary.cc in Sources */, + 1EEEB62A1720859200F7E689 /* simple_string_dictionary_unittest.cc in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1855,6 +1857,7 @@ D244540B12439BA0009BBCE0 /* memory_unittest.cc in Sources */, 4D72CA3813DFAE91006CABE3 /* md5.cc in Sources */, 4D61A26E14F43D45002D5862 /* bootstrap_compat.cc in Sources */, + 1EEEB6271720831E00F7E689 /* BreakpadFramework_Test.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1872,10 +1875,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - F9C77DE40F7DD82F0045F7DB /* SimpleStringDictionary.mm in Sources */, - F9C77DE20F7DD7E30045F7DB /* SimpleStringDictionaryTest.mm in Sources */, F9C77E130F7DDF810045F7DB /* GTMSenTestCase.m in Sources */, - F91AF5D00FD60393009D8BE2 /* BreakpadFramework_Test.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/client/mac/Framework/Breakpad.mm b/src/client/mac/Framework/Breakpad.mm index 4762516e..71555e8f 100644 --- a/src/client/mac/Framework/Breakpad.mm +++ b/src/client/mac/Framework/Breakpad.mm @@ -52,7 +52,7 @@ #import "client/mac/Framework/OnDemandServer.h" #import "client/mac/handler/protected_memory_allocator.h" #import "common/mac/MachIPC.h" -#import "common/mac/SimpleStringDictionary.h" +#import "common/simple_string_dictionary.h" #ifndef __EXCEPTIONS // This file uses C++ try/catch (but shouldn't). Duplicate the macros from diff --git a/src/client/mac/crash_generation/ConfigFile.h b/src/client/mac/crash_generation/ConfigFile.h index f0575339..5662e8b0 100644 --- a/src/client/mac/crash_generation/ConfigFile.h +++ b/src/client/mac/crash_generation/ConfigFile.h @@ -31,7 +31,7 @@ #import -#import "common/mac/SimpleStringDictionary.h" +#include "common/simple_string_dictionary.h" namespace google_breakpad { diff --git a/src/client/mac/crash_generation/ConfigFile.mm b/src/client/mac/crash_generation/ConfigFile.mm index ee2d9448..0b7f0e15 100644 --- a/src/client/mac/crash_generation/ConfigFile.mm +++ b/src/client/mac/crash_generation/ConfigFile.mm @@ -36,7 +36,6 @@ #include #import "client/apple/Framework/BreakpadDefines.h" -#import "common/mac/SimpleStringDictionary.h" #import "GTMDefines.h" #define VERBOSE 0 diff --git a/src/client/mac/crash_generation/Inspector.h b/src/client/mac/crash_generation/Inspector.h index 11a0dec6..890e2157 100644 --- a/src/client/mac/crash_generation/Inspector.h +++ b/src/client/mac/crash_generation/Inspector.h @@ -30,7 +30,7 @@ // Interface file between the Breakpad.framework and // the Inspector process. -#import "common/mac/SimpleStringDictionary.h" +#include "common/simple_string_dictionary.h" #import #include diff --git a/src/client/mac/crash_generation/Inspector.mm b/src/client/mac/crash_generation/Inspector.mm index ea5d19a6..c6259121 100644 --- a/src/client/mac/crash_generation/Inspector.mm +++ b/src/client/mac/crash_generation/Inspector.mm @@ -41,7 +41,6 @@ #import "client/mac/Framework/Breakpad.h" #import "client/mac/handler/minidump_generator.h" -#import "common/mac/SimpleStringDictionary.h" #import "common/mac/MachIPC.h" #include "common/mac/bootstrap_compat.h" diff --git a/src/client/mac/tests/SimpleStringDictionaryTest.h b/src/client/mac/tests/SimpleStringDictionaryTest.h deleted file mode 100644 index 53f6ae42..00000000 --- a/src/client/mac/tests/SimpleStringDictionaryTest.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#import "GTMSenTestCase.h" -#import "SimpleStringDictionary.h" - -@interface SimpleStringDictionaryTest : GTMTestCase { - -} - -- (void)testKeyValueEntry; -- (void)testSimpleStringDictionary; -- (void)testSimpleStringDictionaryIterator; -@end diff --git a/src/client/mac/tests/SimpleStringDictionaryTest.mm b/src/client/mac/tests/SimpleStringDictionaryTest.mm deleted file mode 100644 index 94179cd2..00000000 --- a/src/client/mac/tests/SimpleStringDictionaryTest.mm +++ /dev/null @@ -1,243 +0,0 @@ -// Copyright (c) 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#import "SimpleStringDictionaryTest.h" -#import "SimpleStringDictionary.h" - -using google_breakpad::KeyValueEntry; -using google_breakpad::SimpleStringDictionary; -using google_breakpad::SimpleStringDictionaryIterator; - -@implementation SimpleStringDictionaryTest - -//============================================================================== -- (void)testKeyValueEntry { - KeyValueEntry entry; - - // Verify that initial state is correct - STAssertFalse(entry.IsActive(), @"Initial key value entry is active!"); - STAssertEquals(strlen(entry.GetKey()), (size_t)0, @"Empty key value did not " - @"have length 0"); - STAssertEquals(strlen(entry.GetValue()), (size_t)0, @"Empty key value did not " - @"have length 0"); - - // Try setting a key/value and then verify - entry.SetKeyValue("key1", "value1"); - STAssertEqualCStrings(entry.GetKey(), "key1", @"key was not equal to key1"); - STAssertEqualCStrings(entry.GetValue(), "value1", @"value was not equal"); - - // Try setting a new value - entry.SetValue("value3"); - - // Make sure the new value took - STAssertEqualCStrings(entry.GetValue(), "value3", @"value was not equal"); - - // Make sure the key didn't change - STAssertEqualCStrings(entry.GetKey(), "key1", @"key changed after setting " - @"value!"); - - // Try setting a new key/value and then verify - entry.SetKeyValue("key2", "value2"); - STAssertEqualCStrings(entry.GetKey(), "key2", @"New key was not equal to " - @"key2"); - STAssertEqualCStrings(entry.GetValue(), "value2", @"New value was not equal " - @"to value2"); - - // Clear the entry and verify the key and value are empty strings - entry.Clear(); - STAssertFalse(entry.IsActive(), @"Key value clear did not clear object"); - STAssertEquals(strlen(entry.GetKey()), (size_t)0, @"Length of cleared key " - @"was not 0"); - STAssertEquals(strlen(entry.GetValue()), (size_t)0, @"Length of cleared " - @"value was not 0!"); -} - -- (void)testEmptyKeyValueCombos { - KeyValueEntry entry; - entry.SetKeyValue(NULL, NULL); - STAssertEqualCStrings(entry.GetKey(), "", @"Setting NULL key did not return " - @"empty key!"); - STAssertEqualCStrings(entry.GetValue(), "", @"Setting NULL value did not " - @"set empty string value!"); -} - - -//============================================================================== -- (void)testSimpleStringDictionary { - // Make a new dictionary - SimpleStringDictionary *dict = new SimpleStringDictionary(); - STAssertTrue(dict != NULL, nil); - - // try passing in NULL for key - //dict->SetKeyValue(NULL, "bad"); // causes assert() to fire - - // Set three distinct values on three keys - dict->SetKeyValue("key1", "value1"); - dict->SetKeyValue("key2", "value2"); - dict->SetKeyValue("key3", "value3"); - - STAssertTrue(!strcmp(dict->GetValueForKey("key1"), "value1"), nil); - STAssertTrue(!strcmp(dict->GetValueForKey("key2"), "value2"), nil); - STAssertTrue(!strcmp(dict->GetValueForKey("key3"), "value3"), nil); - STAssertEquals(dict->GetCount(), 3, @"GetCount did not return 3"); - // try an unknown key - STAssertTrue(dict->GetValueForKey("key4") == NULL, nil); - - // try a NULL key - //STAssertTrue(dict->GetValueForKey(NULL) == NULL, nil); // asserts - - // Remove a key - dict->RemoveKey("key3"); - - // Now make sure it's not there anymore - STAssertTrue(dict->GetValueForKey("key3") == NULL, nil); - - // Remove a NULL key - //dict->RemoveKey(NULL); // will cause assert() to fire - - // Remove by setting value to NULL - dict->SetKeyValue("key2", NULL); - - // Now make sure it's not there anymore - STAssertTrue(dict->GetValueForKey("key2") == NULL, nil); -} - -//============================================================================== -// The idea behind this test is to add a bunch of values to the dictionary, -// remove some in the middle, then add a few more in. We then create a -// SimpleStringDictionaryIterator and iterate through the dictionary, taking -// note of the key/value pairs we see. We then verify that it iterates -// through exactly the number of key/value pairs we expect, and that they -// match one-for-one with what we would expect. In all cases we're setting -// key value pairs of the form: -// -// key/value (like key0/value0, key17,value17, etc.) -// -- (void)testSimpleStringDictionaryIterator { - SimpleStringDictionary *dict = new SimpleStringDictionary(); - STAssertTrue(dict != NULL, nil); - - char key[KeyValueEntry::MAX_STRING_STORAGE_SIZE]; - char value[KeyValueEntry::MAX_STRING_STORAGE_SIZE]; - - const int kDictionaryCapacity = SimpleStringDictionary::MAX_NUM_ENTRIES; - const int kPartitionIndex = kDictionaryCapacity - 5; - - // We assume at least this size in the tests below - STAssertTrue(kDictionaryCapacity >= 64, nil); - - // We'll keep track of the number of key/value pairs we think should - // be in the dictionary - int expectedDictionarySize = 0; - - // Set a bunch of key/value pairs like key0/value0, key1/value1, ... - for (int i = 0; i < kPartitionIndex; ++i) { - sprintf(key, "key%d", i); - sprintf(value, "value%d", i); - dict->SetKeyValue(key, value); - } - expectedDictionarySize = kPartitionIndex; - - // set a couple of the keys twice (with the same value) - should be nop - dict->SetKeyValue("key2", "value2"); - dict->SetKeyValue("key4", "value4"); - dict->SetKeyValue("key15", "value15"); - - // Remove some random elements in the middle - dict->RemoveKey("key7"); - dict->RemoveKey("key18"); - dict->RemoveKey("key23"); - dict->RemoveKey("key31"); - expectedDictionarySize -= 4; // we just removed four key/value pairs - - // Set some more key/value pairs like key59/value59, key60/value60, ... - for (int i = kPartitionIndex; i < kDictionaryCapacity; ++i) { - sprintf(key, "key%d", i); - sprintf(value, "value%d", i); - dict->SetKeyValue(key, value); - } - expectedDictionarySize += kDictionaryCapacity - kPartitionIndex; - - // Now create an iterator on the dictionary - SimpleStringDictionaryIterator iter(*dict); - - // We then verify that it iterates through exactly the number of - // key/value pairs we expect, and that they match one-for-one with what we - // would expect. The ordering of the iteration does not matter... - - // used to keep track of number of occurrences found for key/value pairs - int count[kDictionaryCapacity]; - memset(count, 0, sizeof(count)); - - int totalCount = 0; - - const KeyValueEntry *entry; - - while ((entry = iter.Next())) { - totalCount++; - - // Extract keyNumber from a string of the form key - int keyNumber; - sscanf(entry->GetKey(), "key%d", &keyNumber); - - // Extract valueNumber from a string of the form value - int valueNumber; - sscanf(entry->GetValue(), "value%d", &valueNumber); - - // The value number should equal the key number since that's how we set them - STAssertTrue(keyNumber == valueNumber, nil); - - // Key and value numbers should be in proper range: - // 0 <= keyNumber < kDictionaryCapacity - bool isKeyInGoodRange = - (keyNumber >= 0 && keyNumber < kDictionaryCapacity); - bool isValueInGoodRange = - (valueNumber >= 0 && valueNumber < kDictionaryCapacity); - STAssertTrue(isKeyInGoodRange, nil); - STAssertTrue(isValueInGoodRange, nil); - - if (isKeyInGoodRange && isValueInGoodRange) { - ++count[keyNumber]; - } - } - - // Make sure each of the key/value pairs showed up exactly one time, except - // for the ones which we removed. - for (int i = 0; i < kDictionaryCapacity; ++i) { - // Skip over key7, key18, key23, and key31, since we removed them - if (!(i == 7 || i == 18 || i == 23 || i == 31)) { - STAssertTrue(count[i] == 1, nil); - } - } - - // Make sure the number of iterations matches the expected dictionary size. - STAssertTrue(totalCount == expectedDictionarySize, nil); -} - -@end diff --git a/src/common/mac/SimpleStringDictionary.h b/src/common/mac/SimpleStringDictionary.h deleted file mode 100644 index 814a6f7a..00000000 --- a/src/common/mac/SimpleStringDictionary.h +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (c) 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// SimpleStringDictionary.h -// - -#ifndef SimpleStringDictionary_H__ -#define SimpleStringDictionary_H__ - -#import -#import - -namespace google_breakpad { - -//============================================================================== -// SimpleStringDictionary (and associated class KeyValueEntry) implement a very -// basic dictionary container class. It has the property of not making any -// memory allocations when getting and setting values. But it is not very -// efficient, with calls to get and set values operating in linear time. -// It has the additional limitation of having a fairly small fixed capacity of -// SimpleStringDictionary::MAX_NUM_ENTRIES entries. An assert() will fire if -// the client attempts to set more than this number of key/value pairs. -// Ordinarilly a C++ programmer would use something like the std::map template -// class, or on the Macintosh would often choose CFDictionary or NSDictionary. -// But these dictionary classes may call malloc() during get and set operations. -// Google Breakpad requires that no memory allocations be made in code running -// in its exception handling thread, so it uses SimpleStringDictionary as the -// underlying implementation for the GoogleBreakpad.framework APIs: -// GoogleBreakpadSetKeyValue(), GoogleBreakpadKeyValue(), and -// GoogleBreakpadRemoveKeyValue() -// - -//============================================================================== -// KeyValueEntry -// -// A helper class used by SimpleStringDictionary representing a single -// storage cell for a key/value pair. Each key and value string are -// limited to MAX_STRING_STORAGE_SIZE-1 bytes (not glyphs). This class -// performs no memory allocations. It has methods for setting and getting -// key and value strings. -// -class KeyValueEntry { - public: - KeyValueEntry() { - Clear(); - } - - KeyValueEntry(const char *key, const char *value) { - SetKeyValue(key, value); - } - - void SetKeyValue(const char *key, const char *value) { - if (!key) { - key = ""; - } - if (!value) { - value = ""; - } - - strlcpy(key_, key, sizeof(key_)); - strlcpy(value_, value, sizeof(value_)); - } - - void SetValue(const char *value) { - if (!value) { - value = ""; - } - strlcpy(value_, value, sizeof(value_)); - }; - - // Removes the key/value - void Clear() { - memset(key_, 0, sizeof(key_)); - memset(value_, 0, sizeof(value_)); - } - - bool IsActive() const { return key_[0] != '\0'; } - const char *GetKey() const { return key_; } - const char *GetValue() const { return value_; } - - // Don't change this without considering the fixed size - // of MachMessage (in MachIPC.h) - // (see also struct KeyValueMessageData in Inspector.h) - enum {MAX_STRING_STORAGE_SIZE = 256}; - - private: - char key_[MAX_STRING_STORAGE_SIZE]; - char value_[MAX_STRING_STORAGE_SIZE]; -}; - -//============================================================================== -// This class is not an efficient dictionary, but for the purposes of breakpad -// will be just fine. We're just dealing with ten or so distinct -// key/value pairs. The idea is to avoid any malloc() or free() calls -// in certain important methods to be called when a process is in a -// crashed state. Each key and value string are limited to -// KeyValueEntry::MAX_STRING_STORAGE_SIZE-1 bytes (not glyphs). Strings passed -// in exceeding this length will be truncated. -// -class SimpleStringDictionary { - public: - SimpleStringDictionary() {}; // entries will all be cleared - - // Returns the number of active key/value pairs. The upper limit for this - // is MAX_NUM_ENTRIES. - int GetCount() const; - - // Given |key|, returns its corresponding |value|. - // If |key| is NULL, an assert will fire or NULL will be returned. If |key| - // is not found or is an empty string, NULL is returned. - const char *GetValueForKey(const char *key) const; - - // Stores a string |value| represented by |key|. If |key| is NULL or an empty - // string, this will assert (or do nothing). If |value| is NULL then - // the |key| will be removed. An empty string is OK for |value|. - void SetKeyValue(const char *key, const char *value); - - // Given |key|, removes any associated value. It will assert (or do nothing) - // if NULL is passed in. It will do nothing if |key| is not found. - void RemoveKey(const char *key); - - // This is the maximum number of key/value pairs which may be set in the - // dictionary. An assert may fire if more values than this are set. - // Don't change this without also changing comment in GoogleBreakpad.h - enum {MAX_NUM_ENTRIES = 64}; - - private: - friend class SimpleStringDictionaryIterator; - - const KeyValueEntry *GetEntry(int i) const; - - KeyValueEntry entries_[MAX_NUM_ENTRIES]; -}; - -//============================================================================== -class SimpleStringDictionaryIterator { - public: - SimpleStringDictionaryIterator(const SimpleStringDictionary &dict) - : dict_(dict), i_(0) { - } - - // Initializes iterator to the beginning (may later call Next() ) - void Start() { - i_ = 0; - } - - // like the nextObject method of NSEnumerator (in Cocoa) - // returns NULL when there are no more entries - // - const KeyValueEntry* Next() { - for (; i_ < SimpleStringDictionary::MAX_NUM_ENTRIES; ++i_) { - const KeyValueEntry *entry = dict_.GetEntry(i_); - if (entry->IsActive()) { - i_++; // move to next entry for next time - return entry; - } - } - - return NULL; // reached end of array - } - - private: - const SimpleStringDictionary& dict_; - int i_; -}; - -} // namespace google_breakpad - -#endif // SimpleStringDictionary_H__ diff --git a/src/common/mac/SimpleStringDictionary.mm b/src/common/mac/SimpleStringDictionary.mm deleted file mode 100644 index b97b760c..00000000 --- a/src/common/mac/SimpleStringDictionary.mm +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) 2007, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// SimpleStringDictionary.mm -// Simple string dictionary that does not allocate memory -// - -#include - -#import "SimpleStringDictionary.h" - -namespace google_breakpad { - -//============================================================================== -const KeyValueEntry *SimpleStringDictionary::GetEntry(int i) const { - return (i >= 0 && i < MAX_NUM_ENTRIES) ? &entries_[i] : NULL; -} - -//============================================================================== -int SimpleStringDictionary::GetCount() const { - int count = 0; - for (int i = 0; i < MAX_NUM_ENTRIES; ++i) { - if (entries_[i].IsActive() ) { - ++count; - } - } - - return count; -} - -//============================================================================== -const char *SimpleStringDictionary::GetValueForKey(const char *key) const { - assert(key); - if (!key) - return NULL; - - for (int i = 0; i < MAX_NUM_ENTRIES; ++i) { - const KeyValueEntry &entry = entries_[i]; - if (entry.IsActive() && !strcmp(entry.GetKey(), key)) { - return entry.GetValue(); - } - } - - return NULL; -} - -//============================================================================== -void SimpleStringDictionary::SetKeyValue(const char *key, - const char *value) { - if (!value) { - RemoveKey(key); - return; - } - - // key must not be NULL - assert(key); - if (!key) - return; - - // key must not be empty string - assert(key[0] != '\0'); - if (key[0] == '\0') - return; - - int free_index = -1; - - // check if key already exists - for (int i = 0; i < MAX_NUM_ENTRIES; ++i) { - KeyValueEntry &entry = entries_[i]; - - if (entry.IsActive()) { - if (!strcmp(entry.GetKey(), key)) { - entry.SetValue(value); - return; - } - } else { - // Make a note of an empty slot - if (free_index == -1) { - free_index = i; - } - } - } - - // check if we've run out of space - assert(free_index != -1); - - // Put new key into an empty slot (if found) - if (free_index != -1) { - entries_[free_index].SetKeyValue(key, value); - } -} - -//============================================================================== -void SimpleStringDictionary::RemoveKey(const char *key) { - assert(key); - if (!key) - return; - - for (int i = 0; i < MAX_NUM_ENTRIES; ++i) { - if (!strcmp(entries_[i].GetKey(), key)) { - entries_[i].Clear(); - return; - } - } -} - -} // namespace google_breakpad diff --git a/src/common/simple_string_dictionary.cc b/src/common/simple_string_dictionary.cc new file mode 100644 index 00000000..f28ee9ef --- /dev/null +++ b/src/common/simple_string_dictionary.cc @@ -0,0 +1,129 @@ +// Copyright (c) 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + +#include "common/simple_string_dictionary.h" + +namespace google_breakpad { + +//============================================================================== +const KeyValueEntry *SimpleStringDictionary::GetEntry(int i) const { + return (i >= 0 && i < MAX_NUM_ENTRIES) ? &entries_[i] : NULL; +} + +//============================================================================== +int SimpleStringDictionary::GetCount() const { + int count = 0; + for (int i = 0; i < MAX_NUM_ENTRIES; ++i) { + if (entries_[i].IsActive() ) { + ++count; + } + } + + return count; +} + +//============================================================================== +const char *SimpleStringDictionary::GetValueForKey(const char *key) const { + assert(key); + if (!key) + return NULL; + + for (int i = 0; i < MAX_NUM_ENTRIES; ++i) { + const KeyValueEntry &entry = entries_[i]; + if (entry.IsActive() && !strcmp(entry.GetKey(), key)) { + return entry.GetValue(); + } + } + + return NULL; +} + +//============================================================================== +void SimpleStringDictionary::SetKeyValue(const char *key, + const char *value) { + if (!value) { + RemoveKey(key); + return; + } + + // key must not be NULL + assert(key); + if (!key) + return; + + // key must not be empty string + assert(key[0] != '\0'); + if (key[0] == '\0') + return; + + int free_index = -1; + + // check if key already exists + for (int i = 0; i < MAX_NUM_ENTRIES; ++i) { + KeyValueEntry &entry = entries_[i]; + + if (entry.IsActive()) { + if (!strcmp(entry.GetKey(), key)) { + entry.SetValue(value); + return; + } + } else { + // Make a note of an empty slot + if (free_index == -1) { + free_index = i; + } + } + } + + // check if we've run out of space + assert(free_index != -1); + + // Put new key into an empty slot (if found) + if (free_index != -1) { + entries_[free_index].SetKeyValue(key, value); + } +} + +//============================================================================== +void SimpleStringDictionary::RemoveKey(const char *key) { + assert(key); + if (!key) + return; + + for (int i = 0; i < MAX_NUM_ENTRIES; ++i) { + if (!strcmp(entries_[i].GetKey(), key)) { + entries_[i].Clear(); + return; + } + } +} + +} // namespace google_breakpad diff --git a/src/common/simple_string_dictionary.h b/src/common/simple_string_dictionary.h new file mode 100644 index 00000000..dbeaabc0 --- /dev/null +++ b/src/common/simple_string_dictionary.h @@ -0,0 +1,192 @@ +// Copyright (c) 2007, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef COMMON_SIMPLE_STRING_DICTIONARY_H_ +#define COMMON_SIMPLE_STRING_DICTIONARY_H_ + +#import +#import + +namespace google_breakpad { + +//============================================================================== +// SimpleStringDictionary (and associated class KeyValueEntry) implement a very +// basic dictionary container class. It has the property of not making any +// memory allocations when getting and setting values. But it is not very +// efficient, with calls to get and set values operating in linear time. +// It has the additional limitation of having a fairly small fixed capacity of +// SimpleStringDictionary::MAX_NUM_ENTRIES entries. An assert() will fire if +// the client attempts to set more than this number of key/value pairs. +// Ordinarilly a C++ programmer would use something like the std::map template +// class, or on the Macintosh would often choose CFDictionary or NSDictionary. +// But these dictionary classes may call malloc() during get and set operations. +// Google Breakpad requires that no memory allocations be made in code running +// in its exception handling thread, so it uses SimpleStringDictionary as the +// underlying implementation for the GoogleBreakpad.framework APIs: +// GoogleBreakpadSetKeyValue(), GoogleBreakpadKeyValue(), and +// GoogleBreakpadRemoveKeyValue() +// + +//============================================================================== +// KeyValueEntry +// +// A helper class used by SimpleStringDictionary representing a single +// storage cell for a key/value pair. Each key and value string are +// limited to MAX_STRING_STORAGE_SIZE-1 bytes (not glyphs). This class +// performs no memory allocations. It has methods for setting and getting +// key and value strings. +// +class KeyValueEntry { + public: + KeyValueEntry() { + Clear(); + } + + KeyValueEntry(const char *key, const char *value) { + SetKeyValue(key, value); + } + + void SetKeyValue(const char *key, const char *value) { + if (!key) { + key = ""; + } + if (!value) { + value = ""; + } + + strlcpy(key_, key, sizeof(key_)); + strlcpy(value_, value, sizeof(value_)); + } + + void SetValue(const char *value) { + if (!value) { + value = ""; + } + strlcpy(value_, value, sizeof(value_)); + }; + + // Removes the key/value + void Clear() { + memset(key_, 0, sizeof(key_)); + memset(value_, 0, sizeof(value_)); + } + + bool IsActive() const { return key_[0] != '\0'; } + const char *GetKey() const { return key_; } + const char *GetValue() const { return value_; } + + // Don't change this without considering the fixed size + // of MachMessage (in MachIPC.h) + // (see also struct KeyValueMessageData in Inspector.h) + enum {MAX_STRING_STORAGE_SIZE = 256}; + + private: + char key_[MAX_STRING_STORAGE_SIZE]; + char value_[MAX_STRING_STORAGE_SIZE]; +}; + +//============================================================================== +// This class is not an efficient dictionary, but for the purposes of breakpad +// will be just fine. We're just dealing with ten or so distinct +// key/value pairs. The idea is to avoid any malloc() or free() calls +// in certain important methods to be called when a process is in a +// crashed state. Each key and value string are limited to +// KeyValueEntry::MAX_STRING_STORAGE_SIZE-1 bytes (not glyphs). Strings passed +// in exceeding this length will be truncated. +// +class SimpleStringDictionary { + public: + SimpleStringDictionary() {}; // entries will all be cleared + + // Returns the number of active key/value pairs. The upper limit for this + // is MAX_NUM_ENTRIES. + int GetCount() const; + + // Given |key|, returns its corresponding |value|. + // If |key| is NULL, an assert will fire or NULL will be returned. If |key| + // is not found or is an empty string, NULL is returned. + const char *GetValueForKey(const char *key) const; + + // Stores a string |value| represented by |key|. If |key| is NULL or an empty + // string, this will assert (or do nothing). If |value| is NULL then + // the |key| will be removed. An empty string is OK for |value|. + void SetKeyValue(const char *key, const char *value); + + // Given |key|, removes any associated value. It will assert (or do nothing) + // if NULL is passed in. It will do nothing if |key| is not found. + void RemoveKey(const char *key); + + // This is the maximum number of key/value pairs which may be set in the + // dictionary. An assert may fire if more values than this are set. + // Don't change this without also changing comment in GoogleBreakpad.h + enum {MAX_NUM_ENTRIES = 64}; + + private: + friend class SimpleStringDictionaryIterator; + + const KeyValueEntry *GetEntry(int i) const; + + KeyValueEntry entries_[MAX_NUM_ENTRIES]; +}; + +//============================================================================== +class SimpleStringDictionaryIterator { + public: + SimpleStringDictionaryIterator(const SimpleStringDictionary &dict) + : dict_(dict), i_(0) { + } + + // Initializes iterator to the beginning (may later call Next() ) + void Start() { + i_ = 0; + } + + // like the nextObject method of NSEnumerator (in Cocoa) + // returns NULL when there are no more entries + // + const KeyValueEntry* Next() { + for (; i_ < SimpleStringDictionary::MAX_NUM_ENTRIES; ++i_) { + const KeyValueEntry *entry = dict_.GetEntry(i_); + if (entry->IsActive()) { + i_++; // move to next entry for next time + return entry; + } + } + + return NULL; // reached end of array + } + + private: + const SimpleStringDictionary& dict_; + int i_; +}; + +} // namespace google_breakpad + +#endif // COMMON_SIMPLE_STRING_DICTIONARY_H_ diff --git a/src/common/simple_string_dictionary_unittest.cc b/src/common/simple_string_dictionary_unittest.cc new file mode 100644 index 00000000..ff02115e --- /dev/null +++ b/src/common/simple_string_dictionary_unittest.cc @@ -0,0 +1,221 @@ +// Copyright (c) 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "breakpad_googletest_includes.h" +#include "common/simple_string_dictionary.h" + +namespace google_breakpad { + +//============================================================================== +TEST(SimpleStringDictionaryTest, KeyValueEntry) { + KeyValueEntry entry; + + // Verify that initial state is correct + EXPECT_FALSE(entry.IsActive()); + EXPECT_EQ(strlen(entry.GetKey()), 0u); + EXPECT_EQ(strlen(entry.GetValue()), 0u); + + // Try setting a key/value and then verify + entry.SetKeyValue("key1", "value1"); + EXPECT_STREQ(entry.GetKey(), "key1"); + EXPECT_STREQ(entry.GetValue(), "value1"); + + // Try setting a new value + entry.SetValue("value3"); + + // Make sure the new value took + EXPECT_STREQ(entry.GetValue(), "value3"); + + // Make sure the key didn't change + EXPECT_STREQ(entry.GetKey(), "key1"); + + // Try setting a new key/value and then verify + entry.SetKeyValue("key2", "value2"); + EXPECT_STREQ(entry.GetKey(), "key2"); + EXPECT_STREQ(entry.GetValue(), "value2"); + + // Clear the entry and verify the key and value are empty strings + entry.Clear(); + EXPECT_FALSE(entry.IsActive()); + EXPECT_EQ(strlen(entry.GetKey()), 0u); + EXPECT_EQ(strlen(entry.GetValue()), 0u); +} + +TEST(SimpleStringDictionaryTest, EmptyKeyValueCombos) { + KeyValueEntry entry; + entry.SetKeyValue(NULL, NULL); + EXPECT_STREQ(entry.GetKey(), ""); + EXPECT_STREQ(entry.GetValue(), ""); +} + + +//============================================================================== +TEST(SimpleStringDictionaryTest, SimpleStringDictionary) { + // Make a new dictionary + SimpleStringDictionary *dict = new SimpleStringDictionary(); + ASSERT_TRUE(dict); + + // Set three distinct values on three keys + dict->SetKeyValue("key1", "value1"); + dict->SetKeyValue("key2", "value2"); + dict->SetKeyValue("key3", "value3"); + + EXPECT_NE(dict->GetValueForKey("key1"), "value1"); + EXPECT_NE(dict->GetValueForKey("key2"), "value2"); + EXPECT_NE(dict->GetValueForKey("key3"), "value3"); + EXPECT_EQ(dict->GetCount(), 3); + // try an unknown key + EXPECT_FALSE(dict->GetValueForKey("key4")); + + // Remove a key + dict->RemoveKey("key3"); + + // Now make sure it's not there anymore + EXPECT_FALSE(dict->GetValueForKey("key3")); + + // Remove by setting value to NULL + dict->SetKeyValue("key2", NULL); + + // Now make sure it's not there anymore + EXPECT_FALSE(dict->GetValueForKey("key2")); +} + +//============================================================================== +// The idea behind this test is to add a bunch of values to the dictionary, +// remove some in the middle, then add a few more in. We then create a +// SimpleStringDictionaryIterator and iterate through the dictionary, taking +// note of the key/value pairs we see. We then verify that it iterates +// through exactly the number of key/value pairs we expect, and that they +// match one-for-one with what we would expect. In all cases we're setting +// key value pairs of the form: +// +// key/value (like key0/value0, key17,value17, etc.) +// +TEST(SimpleStringDictionaryTest, SimpleStringDictionaryIterator) { + SimpleStringDictionary *dict = new SimpleStringDictionary(); + ASSERT_TRUE(dict); + + char key[KeyValueEntry::MAX_STRING_STORAGE_SIZE]; + char value[KeyValueEntry::MAX_STRING_STORAGE_SIZE]; + + const int kDictionaryCapacity = SimpleStringDictionary::MAX_NUM_ENTRIES; + const int kPartitionIndex = kDictionaryCapacity - 5; + + // We assume at least this size in the tests below + ASSERT_GE(kDictionaryCapacity, 64); + + // We'll keep track of the number of key/value pairs we think should + // be in the dictionary + int expectedDictionarySize = 0; + + // Set a bunch of key/value pairs like key0/value0, key1/value1, ... + for (int i = 0; i < kPartitionIndex; ++i) { + sprintf(key, "key%d", i); + sprintf(value, "value%d", i); + dict->SetKeyValue(key, value); + } + expectedDictionarySize = kPartitionIndex; + + // set a couple of the keys twice (with the same value) - should be nop + dict->SetKeyValue("key2", "value2"); + dict->SetKeyValue("key4", "value4"); + dict->SetKeyValue("key15", "value15"); + + // Remove some random elements in the middle + dict->RemoveKey("key7"); + dict->RemoveKey("key18"); + dict->RemoveKey("key23"); + dict->RemoveKey("key31"); + expectedDictionarySize -= 4; // we just removed four key/value pairs + + // Set some more key/value pairs like key59/value59, key60/value60, ... + for (int i = kPartitionIndex; i < kDictionaryCapacity; ++i) { + sprintf(key, "key%d", i); + sprintf(value, "value%d", i); + dict->SetKeyValue(key, value); + } + expectedDictionarySize += kDictionaryCapacity - kPartitionIndex; + + // Now create an iterator on the dictionary + SimpleStringDictionaryIterator iter(*dict); + + // We then verify that it iterates through exactly the number of + // key/value pairs we expect, and that they match one-for-one with what we + // would expect. The ordering of the iteration does not matter... + + // used to keep track of number of occurrences found for key/value pairs + int count[kDictionaryCapacity]; + memset(count, 0, sizeof(count)); + + int totalCount = 0; + + const KeyValueEntry *entry; + + while ((entry = iter.Next())) { + totalCount++; + + // Extract keyNumber from a string of the form key + int keyNumber; + sscanf(entry->GetKey(), "key%d", &keyNumber); + + // Extract valueNumber from a string of the form value + int valueNumber; + sscanf(entry->GetValue(), "value%d", &valueNumber); + + // The value number should equal the key number since that's how we set them + EXPECT_EQ(keyNumber, valueNumber); + + // Key and value numbers should be in proper range: + // 0 <= keyNumber < kDictionaryCapacity + bool isKeyInGoodRange = + (keyNumber >= 0 && keyNumber < kDictionaryCapacity); + bool isValueInGoodRange = + (valueNumber >= 0 && valueNumber < kDictionaryCapacity); + EXPECT_TRUE(isKeyInGoodRange); + EXPECT_TRUE(isValueInGoodRange); + + if (isKeyInGoodRange && isValueInGoodRange) { + ++count[keyNumber]; + } + } + + // Make sure each of the key/value pairs showed up exactly one time, except + // for the ones which we removed. + for (int i = 0; i < kDictionaryCapacity; ++i) { + // Skip over key7, key18, key23, and key31, since we removed them + if (!(i == 7 || i == 18 || i == 23 || i == 31)) { + EXPECT_EQ(count[i], 1); + } + } + + // Make sure the number of iterations matches the expected dictionary size. + EXPECT_EQ(totalCount, expectedDictionarySize); +} + +} // namespace google_breakpad -- cgit v1.2.1