diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 20:03:11 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-01 20:03:11 +0000 |
commit | 1599077a645a03c31c09efe57befaefbe00c958a (patch) | |
tree | dcf0702d4e1a241ce69e4e6a9968992f42ed4b68 | |
parent | f27a0b59065835a9fe6f9a30681c36f14fe9edc3 (diff) | |
download | chromium_src-1599077a645a03c31c09efe57befaefbe00c958a.zip chromium_src-1599077a645a03c31c09efe57befaefbe00c958a.tar.gz chromium_src-1599077a645a03c31c09efe57befaefbe00c958a.tar.bz2 |
Clang: make DCHECK_EQ(string16, string16) work.
The problem is that string16 is a typedef for a std::basic_string with a custom base::char_traits, hence ADL looks for operator<< only in std and base, not in the global namespace. Since adding stuff to the global namespace isn't permitted, move the operator to namespace base instead.
Also give WebString an explicit operator<< because clang can't figure out that it can use WebString's |operator string16| to print WebStrings.
string16 is just wstring on windows, and gtest has special code to make printing wstrings to non-wide ostreams work already, so nothing is required on windows.
Fix a few other minor issues.
Based on a patch by hans@chromium.org
BUG=57294
TEST=still compiles with gcc, fewer build errors in tests with clang
Review URL: http://codereview.chromium.org/3515003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61218 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/string16.cc | 2 | ||||
-rw-r--r-- | base/string16.h | 2 | ||||
-rw-r--r-- | chrome/browser/idbbindingutilities_browsertest.cc | 1 | ||||
-rw-r--r-- | chrome/renderer/form_autocomplete_browsertest.cc | 1 | ||||
-rw-r--r-- | chrome/renderer/form_manager.cc | 1 | ||||
-rw-r--r-- | chrome/renderer/form_manager_browsertest.cc | 1 | ||||
-rw-r--r-- | chrome/renderer/render_view_browsertest.cc | 19 | ||||
-rw-r--r-- | webkit/glue/multipart_response_delegate_unittest.cc | 4 | ||||
-rw-r--r-- | webkit/glue/web_io_operators.cc | 19 | ||||
-rw-r--r-- | webkit/glue/web_io_operators.h | 19 | ||||
-rw-r--r-- | webkit/glue/webkit_glue.gypi | 2 | ||||
-rw-r--r-- | webkit/tools/test_shell/event_listener_unittest.cc | 1 |
12 files changed, 62 insertions, 10 deletions
diff --git a/base/string16.cc b/base/string16.cc index f7eaf7e..69d10e7 100644 --- a/base/string16.cc +++ b/base/string16.cc @@ -69,8 +69,10 @@ char16* c16memset(char16* s, char16 c, size_t n) { template class std::basic_string<char16, base::string16_char_traits>; +namespace base { std::ostream& operator<<(std::ostream& out, const string16& str) { return out << UTF16ToUTF8(str); } +} #endif // WCHAR_T_IS_UTF32 diff --git a/base/string16.h b/base/string16.h index 78734fd..25e980c 100644 --- a/base/string16.h +++ b/base/string16.h @@ -167,7 +167,9 @@ extern template class std::basic_string<char16, base::string16_char_traits>; typedef std::basic_string<char16, base::string16_char_traits> string16; +namespace base { extern std::ostream& operator<<(std::ostream& out, const string16& str); +} #endif // WCHAR_T_IS_UTF32 diff --git a/chrome/browser/idbbindingutilities_browsertest.cc b/chrome/browser/idbbindingutilities_browsertest.cc index a408379..c32a9ae 100644 --- a/chrome/browser/idbbindingutilities_browsertest.cc +++ b/chrome/browser/idbbindingutilities_browsertest.cc @@ -14,6 +14,7 @@ #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" #include "webkit/glue/idb_bindings.h" +#include "webkit/glue/web_io_operators.h" #include "third_party/WebKit/WebKit/chromium/public/WebSerializedScriptValue.h" using WebKit::WebSerializedScriptValue; diff --git a/chrome/renderer/form_autocomplete_browsertest.cc b/chrome/renderer/form_autocomplete_browsertest.cc index 55429bd..eddf0fb 100644 --- a/chrome/renderer/form_autocomplete_browsertest.cc +++ b/chrome/renderer/form_autocomplete_browsertest.cc @@ -10,6 +10,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" #include "webkit/glue/form_data.h" +#include "webkit/glue/web_io_operators.h" using webkit_glue::FormData; using WebKit::WebFrame; diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc index 820a086..2de7f0f 100644 --- a/chrome/renderer/form_manager.cc +++ b/chrome/renderer/form_manager.cc @@ -23,6 +23,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" #include "webkit/glue/form_data.h" #include "webkit/glue/form_field.h" +#include "webkit/glue/web_io_operators.h" using webkit_glue::FormData; using webkit_glue::FormField; diff --git a/chrome/renderer/form_manager_browsertest.cc b/chrome/renderer/form_manager_browsertest.cc index 0b89e1d..a82dbe6 100644 --- a/chrome/renderer/form_manager_browsertest.cc +++ b/chrome/renderer/form_manager_browsertest.cc @@ -16,6 +16,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" #include "webkit/glue/form_data.h" +#include "webkit/glue/web_io_operators.h" using WebKit::WebDocument; using WebKit::WebElement; diff --git a/chrome/renderer/render_view_browsertest.cc b/chrome/renderer/render_view_browsertest.cc index 4660931..2b14045 100644 --- a/chrome/renderer/render_view_browsertest.cc +++ b/chrome/renderer/render_view_browsertest.cc @@ -7,6 +7,7 @@ #include "app/keyboard_codes.h" #include "base/file_util.h" #include "base/shared_memory.h" +#include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/common/content_settings.h" #include "chrome/common/native_web_keyboard_event.h" @@ -26,6 +27,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebView.h" #include "webkit/glue/form_data.h" #include "webkit/glue/form_field.h" +#include "webkit/glue/web_io_operators.h" using WebKit::WebDocument; using WebKit::WebFrame; @@ -619,14 +621,15 @@ TEST_F(RenderViewTest, OnHandleKeyboardEvent) { // our JavaScript function. (See the above comment for the format.) static char expected_result[1024]; expected_result[0] = NULL; - sprintf(&expected_result[0], - "\n" // texts in the <input> element - "%d,%s\n" // texts in the first <div> element - "%d,%s\n" // texts in the second <div> element - "%d,%s", // texts in the third <div> element - key_code, kModifierData[j].expected_result, - char_code[0], kModifierData[j].expected_result, - key_code, kModifierData[j].expected_result); + base::snprintf(&expected_result[0], + sizeof(expected_result), + "\n" // texts in the <input> element + "%d,%s\n" // texts in the first <div> element + "%d,%s\n" // texts in the second <div> element + "%d,%s", // texts in the third <div> element + key_code, kModifierData[j].expected_result, + char_code[0], kModifierData[j].expected_result, + key_code, kModifierData[j].expected_result); // Retrieve the text in the test page and compare it with the expected // text created from a virtual-key code, a character code, and the diff --git a/webkit/glue/multipart_response_delegate_unittest.cc b/webkit/glue/multipart_response_delegate_unittest.cc index ffacfb3..fab798c 100644 --- a/webkit/glue/multipart_response_delegate_unittest.cc +++ b/webkit/glue/multipart_response_delegate_unittest.cc @@ -623,7 +623,7 @@ TEST(MultipartResponseTest, MultipartPayloadSet) { client.received_response_); EXPECT_EQ(string("response data"), client.data_); - EXPECT_EQ(false, client.response_.isMultipartPayload()); + EXPECT_FALSE(client.response_.isMultipartPayload()); string data2( "Content-type: text/plain\n\n" @@ -634,7 +634,7 @@ TEST(MultipartResponseTest, MultipartPayloadSet) { client.received_response_); EXPECT_EQ(string("response data2"), client.data_); - EXPECT_EQ(true, client.response_.isMultipartPayload()); + EXPECT_TRUE(client.response_.isMultipartPayload()); } } // namespace diff --git a/webkit/glue/web_io_operators.cc b/webkit/glue/web_io_operators.cc new file mode 100644 index 0000000..f381399 --- /dev/null +++ b/webkit/glue/web_io_operators.cc @@ -0,0 +1,19 @@ +// Copyright (c) 2010 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. + +#include "webkit/glue/web_io_operators.h" + +#if defined(WCHAR_T_IS_UTF32) +#include "base/string16.h" +#include "third_party/WebKit/WebKit/chromium/public/WebString.h" + +namespace WebKit { + +std::ostream& operator<<(std::ostream& out, const WebString& s) { + return out << static_cast<string16>(s); +} + +} // namespace WebKit + +#endif // defined(WCHAR_T_IS_UTF32) diff --git a/webkit/glue/web_io_operators.h b/webkit/glue/web_io_operators.h new file mode 100644 index 0000000..ba10ee0 --- /dev/null +++ b/webkit/glue/web_io_operators.h @@ -0,0 +1,19 @@ +// Copyright (c) 2010 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. + +#ifndef WEBKIT_GLUE_WEB_IO_OPERATORS_H_ +#define WEBKIT_GLUE_WEB_IO_OPERATORS_H_ + +#include <iosfwd> + +#include "build/build_config.h" + +#if defined(WCHAR_T_IS_UTF32) +namespace WebKit { +class WebString; +std::ostream& operator<<(std::ostream& out, const WebString& s); +} // namespace WebKit +#endif // defined(WCHAR_T_IS_UTF32) + +#endif // WEBKIT_GLUE_WEB_IO_OPERATORS_H_ diff --git a/webkit/glue/webkit_glue.gypi b/webkit/glue/webkit_glue.gypi index 80e53c8..05c689a2 100644 --- a/webkit/glue/webkit_glue.gypi +++ b/webkit/glue/webkit_glue.gypi @@ -346,6 +346,8 @@ 'webaccessibility.h', 'webclipboard_impl.cc', 'webclipboard_impl.h', + 'web_io_operators.cc', + 'web_io_operators.h', 'webcookie.cc', 'webcookie.h', 'webcursor.cc', diff --git a/webkit/tools/test_shell/event_listener_unittest.cc b/webkit/tools/test_shell/event_listener_unittest.cc index 77a7a73..7b859c5 100644 --- a/webkit/tools/test_shell/event_listener_unittest.cc +++ b/webkit/tools/test_shell/event_listener_unittest.cc @@ -16,6 +16,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/WebKit/chromium/public/WebScriptSource.h" #include "third_party/WebKit/WebKit/chromium/public/WebView.h" +#include "webkit/glue/web_io_operators.h" #include "webkit/tools/test_shell/test_shell.h" #include "webkit/tools/test_shell/test_shell_request_context.h" #include "webkit/tools/test_shell/test_shell_test.h" |