summaryrefslogtreecommitdiffstats
path: root/base/string_escape_unittest.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-23 20:00:20 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-23 20:00:20 +0000
commit93d49d70b89b22ec46d0b00b7950297f64865d56 (patch)
tree3243e0209c738df0c18c2ba615667f757fcaec94 /base/string_escape_unittest.cc
parenta9f607e33a91604bc63bd8c846aefbda9bf0dfa9 (diff)
downloadchromium_src-93d49d70b89b22ec46d0b00b7950297f64865d56.zip
chromium_src-93d49d70b89b22ec46d0b00b7950297f64865d56.tar.gz
chromium_src-93d49d70b89b22ec46d0b00b7950297f64865d56.tar.bz2
Move the json-related files into a separate json directory. This hopefully also
makes the naming of string_escape more clear (it's actually JSON-specific). Move the files into the base namespace. TEST=none BUG=none Review URL: http://codereview.chromium.org/316016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29934 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_escape_unittest.cc')
-rw-r--r--base/string_escape_unittest.cc95
1 files changed, 0 insertions, 95 deletions
diff --git a/base/string_escape_unittest.cc b/base/string_escape_unittest.cc
deleted file mode 100644
index d731dc1..0000000
--- a/base/string_escape_unittest.cc
+++ /dev/null
@@ -1,95 +0,0 @@
-// Copyright (c) 2006-2008 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 "testing/gtest/include/gtest/gtest.h"
-#include "base/string_escape.h"
-#include "base/string_util.h"
-
-namespace {
-
-const struct json_narrow_test_data {
- const char* to_escape;
- const char* escaped;
-} json_narrow_cases[] = {
- {"\b\001aZ\"\\wee", "\\b\\u0001aZ\\\"\\\\wee"},
- {"a\b\f\n\r\t\v\1\\.\"z",
- "a\\b\\f\\n\\r\\t\\u000B\\u0001\\\\.\\\"z"},
- {"b\x0f\x7f\xf0\xff!", "b\\u000F\\u007F\\u00F0\\u00FF!"},
-};
-
-}
-
-TEST(StringEscapeTest, JsonDoubleQuoteNarrow) {
- for (size_t i = 0; i < arraysize(json_narrow_cases); ++i) {
- std::string in = json_narrow_cases[i].to_escape;
- std::string out;
- string_escape::JsonDoubleQuote(in, false, &out);
- EXPECT_EQ(std::string(json_narrow_cases[i].escaped), out);
- }
-
- std::string in = json_narrow_cases[0].to_escape;
- std::string out;
- string_escape::JsonDoubleQuote(in, false, &out);
-
- // test quoting
- std::string out_quoted;
- string_escape::JsonDoubleQuote(in, true, &out_quoted);
- EXPECT_EQ(out.length() + 2, out_quoted.length());
- EXPECT_EQ(out_quoted.find(out), 1U);
-
- // now try with a NULL in the string
- std::string null_prepend = "test";
- null_prepend.push_back(0);
- in = null_prepend + in;
- std::string expected = "test\\u0000";
- expected += json_narrow_cases[0].escaped;
- out.clear();
- string_escape::JsonDoubleQuote(in, false, &out);
- EXPECT_EQ(expected, out);
-}
-
-namespace {
-
-const struct json_wide_test_data {
- const wchar_t* to_escape;
- const char* escaped;
-} json_wide_cases[] = {
- {L"b\uffb1\u00ff", "b\\uFFB1\\u00FF"},
- {L"\b\001aZ\"\\wee", "\\b\\u0001aZ\\\"\\\\wee"},
- {L"a\b\f\n\r\t\v\1\\.\"z",
- "a\\b\\f\\n\\r\\t\\u000B\\u0001\\\\.\\\"z"},
- {L"b\x0f\x7f\xf0\xff!", "b\\u000F\\u007F\\u00F0\\u00FF!"},
-};
-
-}
-
-TEST(StringEscapeTest, JsonDoubleQuoteWide) {
-
- for (size_t i = 0; i < arraysize(json_wide_cases); ++i) {
- std::string out;
- string16 in = WideToUTF16(json_wide_cases[i].to_escape);
- string_escape::JsonDoubleQuote(in, false, &out);
- EXPECT_EQ(std::string(json_wide_cases[i].escaped), out);
- }
-
- string16 in = WideToUTF16(json_wide_cases[0].to_escape);
- std::string out;
- string_escape::JsonDoubleQuote(in, false, &out);
-
- // test quoting
- std::string out_quoted;
- string_escape::JsonDoubleQuote(in, true, &out_quoted);
- EXPECT_EQ(out.length() + 2, out_quoted.length());
- EXPECT_EQ(out_quoted.find(out), 1U);
-
- // now try with a NULL in the string
- string16 null_prepend = WideToUTF16(L"test");
- null_prepend.push_back(0);
- in = null_prepend + in;
- std::string expected = "test\\u0000";
- expected += json_wide_cases[0].escaped;
- out.clear();
- string_escape::JsonDoubleQuote(in, false, &out);
- EXPECT_EQ(expected, out);
-}