| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chromecast/base/scoped_temp_file.h" | 9 #include "chromecast/base/scoped_temp_file.h" |
| 10 #include "chromecast/base/serializers.h" | 10 #include "chromecast/base/serializers.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 EXPECT_NE(nullptr, value.get()); | 48 EXPECT_NE(nullptr, value.get()); |
| 49 } | 49 } |
| 50 | 50 |
| 51 TEST(DeserializeFromJson, PoorlyFormedJsonObject) { | 51 TEST(DeserializeFromJson, PoorlyFormedJsonObject) { |
| 52 std::string str = kPoorlyFormedJsonString; | 52 std::string str = kPoorlyFormedJsonString; |
| 53 std::unique_ptr<base::Value> value = DeserializeFromJson(str); | 53 std::unique_ptr<base::Value> value = DeserializeFromJson(str); |
| 54 EXPECT_EQ(nullptr, value.get()); | 54 EXPECT_EQ(nullptr, value.get()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 TEST(SerializeToJson, BadValue) { | 57 TEST(SerializeToJson, BadValue) { |
| 58 base::BinaryValue value(std::vector<char>(12)); | 58 base::Value value(std::vector<char>(12)); |
| 59 std::unique_ptr<std::string> str = SerializeToJson(value); | 59 std::unique_ptr<std::string> str = SerializeToJson(value); |
| 60 EXPECT_EQ(nullptr, str.get()); | 60 EXPECT_EQ(nullptr, str.get()); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST(SerializeToJson, EmptyValue) { | 63 TEST(SerializeToJson, EmptyValue) { |
| 64 base::DictionaryValue value; | 64 base::DictionaryValue value; |
| 65 std::unique_ptr<std::string> str = SerializeToJson(value); | 65 std::unique_ptr<std::string> str = SerializeToJson(value); |
| 66 ASSERT_NE(nullptr, str.get()); | 66 ASSERT_NE(nullptr, str.get()); |
| 67 EXPECT_EQ(kEmptyJsonString, *str); | 67 EXPECT_EQ(kEmptyJsonString, *str); |
| 68 } | 68 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 ScopedTempFile temp; | 111 ScopedTempFile temp; |
| 112 EXPECT_EQ(static_cast<int>(strlen(kPoorlyFormedJsonString)), | 112 EXPECT_EQ(static_cast<int>(strlen(kPoorlyFormedJsonString)), |
| 113 temp.Write(kPoorlyFormedJsonString)); | 113 temp.Write(kPoorlyFormedJsonString)); |
| 114 std::unique_ptr<base::Value> value = DeserializeJsonFromFile(temp.path()); | 114 std::unique_ptr<base::Value> value = DeserializeJsonFromFile(temp.path()); |
| 115 EXPECT_EQ(nullptr, value.get()); | 115 EXPECT_EQ(nullptr, value.get()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 TEST(SerializeJsonToFile, BadValue) { | 118 TEST(SerializeJsonToFile, BadValue) { |
| 119 ScopedTempFile temp; | 119 ScopedTempFile temp; |
| 120 | 120 |
| 121 base::BinaryValue value(std::vector<char>(12)); | 121 base::Value value(std::vector<char>(12)); |
| 122 ASSERT_FALSE(SerializeJsonToFile(temp.path(), value)); | 122 ASSERT_FALSE(SerializeJsonToFile(temp.path(), value)); |
| 123 std::string str(temp.Read()); | 123 std::string str(temp.Read()); |
| 124 EXPECT_TRUE(str.empty()); | 124 EXPECT_TRUE(str.empty()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 TEST(SerializeJsonToFile, EmptyValue) { | 127 TEST(SerializeJsonToFile, EmptyValue) { |
| 128 ScopedTempFile temp; | 128 ScopedTempFile temp; |
| 129 | 129 |
| 130 base::DictionaryValue value; | 130 base::DictionaryValue value; |
| 131 ASSERT_TRUE(SerializeJsonToFile(temp.path(), value)); | 131 ASSERT_TRUE(SerializeJsonToFile(temp.path(), value)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 142 ASSERT_TRUE(SerializeJsonToFile(temp.path(), orig_value)); | 142 ASSERT_TRUE(SerializeJsonToFile(temp.path(), orig_value)); |
| 143 std::string str(temp.Read()); | 143 std::string str(temp.Read()); |
| 144 ASSERT_FALSE(str.empty()); | 144 ASSERT_FALSE(str.empty()); |
| 145 | 145 |
| 146 std::unique_ptr<base::Value> new_value = DeserializeJsonFromFile(temp.path()); | 146 std::unique_ptr<base::Value> new_value = DeserializeJsonFromFile(temp.path()); |
| 147 ASSERT_NE(nullptr, new_value.get()); | 147 ASSERT_NE(nullptr, new_value.get()); |
| 148 EXPECT_TRUE(new_value->Equals(&orig_value)); | 148 EXPECT_TRUE(new_value->Equals(&orig_value)); |
| 149 } | 149 } |
| 150 | 150 |
| 151 } // namespace chromecast | 151 } // namespace chromecast |
| OLD | NEW |