OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/cloud_devices/common/printer_description.h" | 5 #include "components/cloud_devices/common/printer_description.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace cloud_devices { | 13 namespace cloud_devices { |
14 | 14 |
15 namespace printer { | 15 namespace printer { |
16 | 16 |
17 // Replaces ' with " to allow readable json constants in tests. | 17 // Replaces ' with " to allow readable json constants in tests. |
18 // Makes sure that same json value represented by same strings to simplify | 18 // Makes sure that same json value represented by same strings to simplify |
19 // comparison. | 19 // comparison. |
20 std::string NormalizeJson(const std::string& json) { | 20 std::string NormalizeJson(const std::string& json) { |
21 std::string result = json; | 21 std::string result = json; |
22 base::ReplaceChars(result, "'", "\"", &result); | 22 base::ReplaceChars(result, "'", "\"", &result); |
23 scoped_ptr<base::Value> value(base::JSONReader::Read(result)); | 23 scoped_ptr<base::Value> value(base::JSONReader::Read(result)); |
24 DCHECK(value); | 24 DCHECK(value); |
25 base::JSONWriter::Write(value.get(), &result); | 25 base::JSONWriter::Write(*value, &result); |
26 return result; | 26 return result; |
27 } | 27 } |
28 | 28 |
29 const char kCdd[] = | 29 const char kCdd[] = |
30 "{" | 30 "{" |
31 " 'version': '1.0'," | 31 " 'version': '1.0'," |
32 " 'printer': {" | 32 " 'printer': {" |
33 " 'supported_content_type': [ {" | 33 " 'supported_content_type': [ {" |
34 " 'content_type': 'image/pwg-raster'" | 34 " 'content_type': 'image/pwg-raster'" |
35 " }, {" | 35 " }, {" |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 EXPECT_EQ(media.value(), Media(ISO_C7C6, 4261, 334)); | 610 EXPECT_EQ(media.value(), Media(ISO_C7C6, 4261, 334)); |
611 EXPECT_FALSE(collate.value()); | 611 EXPECT_FALSE(collate.value()); |
612 EXPECT_TRUE(reverse.value()); | 612 EXPECT_TRUE(reverse.value()); |
613 | 613 |
614 EXPECT_EQ(NormalizeJson(kCjt), NormalizeJson(description.ToString())); | 614 EXPECT_EQ(NormalizeJson(kCjt), NormalizeJson(description.ToString())); |
615 } | 615 } |
616 | 616 |
617 } // namespace printer | 617 } // namespace printer |
618 | 618 |
619 } // namespace cloud_devices | 619 } // namespace cloud_devices |
OLD | NEW |