diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-08 19:04:54 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-08 19:04:54 +0000 |
commit | a2494cb564bee20bd59457293537599364a2863d (patch) | |
tree | 87233d47cdb31747e036d9446f4332c6fe9ca6ee /base/sys_string_conversions_mac_unittest.mm | |
parent | 87258a289e1d0732af8716d0aa5e910fc8c955be (diff) | |
download | chromium_src-a2494cb564bee20bd59457293537599364a2863d.zip chromium_src-a2494cb564bee20bd59457293537599364a2863d.tar.gz chromium_src-a2494cb564bee20bd59457293537599364a2863d.tar.bz2 |
Fix NSString conversions to treat a null NSString as a string of length 0, instead of crashing. This allows Cocoa to use null objects as empties, as is its wont, and we only run a check when needed.
This CL also removes the now-superfluous checks for null NSStrings from BugReportWindowController. A cursory look through the code shows that there are many places where a check for null precedes a call to an NSString conversion; filed another bug against myself to go through and fix all of these (http://code.google.com/p/chromium/issues/detail?id=27055). Also filed a bug to expand unit tests for NSString conversion methods (http://code.google.com/p/chromium/issues/detail?id=27059).
Review URL: http://codereview.chromium.org/371057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31408 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/sys_string_conversions_mac_unittest.mm')
-rw-r--r-- | base/sys_string_conversions_mac_unittest.mm | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/base/sys_string_conversions_mac_unittest.mm b/base/sys_string_conversions_mac_unittest.mm new file mode 100644 index 0000000..628b515 --- /dev/null +++ b/base/sys_string_conversions_mac_unittest.mm @@ -0,0 +1,19 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import <Foundation/Foundation.h> + +#include "base/string16.h" +#include "base/sys_string_conversions.h" +#include "testing/gtest/include/gtest/gtest.h" + +TEST(SysStrings, ConversionsFromNSString) { + EXPECT_STREQ("Hello, world!", + base::SysNSStringToUTF8(@"Hello, world!").c_str()); + + // Conversions should be able to handle a NULL value without crashing. + EXPECT_STREQ("", base::SysNSStringToUTF8(nil).c_str()); + EXPECT_EQ(string16(), base::SysNSStringToUTF16(nil)); + EXPECT_STREQ(L"", base::SysNSStringToWide(nil).c_str()); +} |