buffet: extract common unittest helper functions into separate file
CreateValue, CreateDictionaryValue and ValueToString() functions
were duplicated in two unit test files in buffet. These functions
will be needed for even more unit tests in the future, so extract
them into their own unittest_utils.cc/.h so they can be reused
in other unit tests.
BUG=None
TEST=USE=buffet P2_TEST_FILTER="buffet::*" FEATURES=test emerge-link platform2
Change-Id: I76ec6d13ed71e78dc02230167041cddc7de653ca
Reviewed-on: https://chromium-review.googlesource.com/208463
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/object_schema_unittest.cc b/buffet/commands/object_schema_unittest.cc
index 64f4600..6921b56 100644
--- a/buffet/commands/object_schema_unittest.cc
+++ b/buffet/commands/object_schema_unittest.cc
@@ -14,38 +14,11 @@
#include "buffet/commands/object_schema.h"
#include "buffet/commands/prop_types.h"
+#include "buffet/commands/unittest_utils.h"
-namespace {
-// Helper method to create base::Value from a string as a smart pointer.
-// For ease of definition in C++ code, double-quotes in the source definition
-// are replaced with apostrophes.
-std::unique_ptr<base::Value> CreateValue(const char* json) {
- std::string json2(json);
- // Convert apostrophes to double-quotes so JSONReader can parse the string.
- std::replace(json2.begin(), json2.end(), '\'', '"');
- return std::unique_ptr<base::Value>(base::JSONReader::Read(json2));
-}
-
-// Helper method to create a JSON dictionary object from a string.
-std::unique_ptr<base::DictionaryValue> CreateDictionaryValue(const char* json) {
- std::string json2(json);
- std::replace(json2.begin(), json2.end(), '\'', '"');
- base::Value* value = base::JSONReader::Read(json2);
- base::DictionaryValue* dict;
- value->GetAsDictionary(&dict);
- return std::unique_ptr<base::DictionaryValue>(dict);
-}
-
-// Converts a JSON value to a string. It also converts double-quotes to
-// apostrophes for easy comparisons in C++ source code.
-std::string ValueToString(const base::Value* value) {
- std::string json;
- base::JSONWriter::Write(value, &json);
- std::replace(json.begin(), json.end(), '"', '\'');
- return json;
-}
-
-} // namespace
+using buffet::unittests::CreateValue;
+using buffet::unittests::CreateDictionaryValue;
+using buffet::unittests::ValueToString;
TEST(CommandSchema, IntPropType_Empty) {
buffet::IntPropType prop;