Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: base/test/values_test_util.cc

Issue 11567027: Add a base::ParseJson() function to help tests construct Values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move ParseJson into base::test Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/test/values_test_util.cc
diff --git a/base/test/values_test_util.cc b/base/test/values_test_util.cc
index a5667f14b81e9700ef6e248fb1a34efb183302fd..c36e7b299280b71203983747e1c644917d63ded4 100644
--- a/base/test/values_test_util.cc
+++ b/base/test/values_test_util.cc
@@ -2,9 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/test/values_test_util.h"
+
+#include "base/json/json_reader.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_number_conversions.h"
-#include "base/test/values_test_util.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -58,4 +60,19 @@ void ExpectStringValue(const std::string& expected_str,
EXPECT_EQ(expected_str, actual_str);
}
+namespace test {
+
+scoped_ptr<Value> ParseJson(base::StringPiece json) {
+ std::string error_msg;
+ scoped_ptr<Value> result(base::JSONReader::ReadAndReturnError(
+ json, base::JSON_ALLOW_TRAILING_COMMAS,
+ NULL, &error_msg));
+ if (!result) {
+ ADD_FAILURE() << "Failed to parse \"" << json << "\": " << error_msg;
+ result.reset(Value::CreateNullValue());
+ }
+ return result.Pass();
+}
+
+} // namespace test
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698