• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Weave Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef LIBWEAVE_INCLUDE_WEAVE_TEST_UNITTEST_UTILS_H_
6 #define LIBWEAVE_INCLUDE_WEAVE_TEST_UNITTEST_UTILS_H_
7 
8 #include <memory>
9 #include <string>
10 
11 #include <base/values.h>
12 #include <gtest/gtest.h>
13 
14 namespace weave {
15 namespace test {
16 
17 // Helper method to create base::Value from a string as a smart pointer.
18 // For ease of definition in C++ code, double-quotes in the source definition
19 // are replaced with apostrophes.
20 std::unique_ptr<base::Value> CreateValue(const std::string& json);
21 
22 std::string ValueToString(const base::Value& value);
23 
24 // Helper method to create a JSON dictionary object from a string.
25 std::unique_ptr<base::DictionaryValue> CreateDictionaryValue(
26     const std::string& json);
27 
IsEqualValue(const base::Value & val1,const base::Value & val2)28 inline bool IsEqualValue(const base::Value& val1, const base::Value& val2) {
29   return val1.Equals(&val2);
30 }
31 
32 }  // namespace test
33 }  // namespace weave
34 
35 #define EXPECT_JSON_EQ(expected, actual)                                       \
36   EXPECT_PRED2(weave::test::IsEqualValue, *weave::test::CreateValue(expected), \
37                actual)
38 
39 #endif  // LIBWEAVE_INCLUDE_WEAVE_TEST_UNITTEST_UTILS_H_
40