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

Side by Side Diff: mojo/services/catalog/entry_unittest.cc

Issue 1818373003: Move serialize/deserialize logic onto Entry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "mojo/services/catalog/builder.h" 5 #include "mojo/services/catalog/entry.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/json/json_file_value_serializer.h" 8 #include "base/json/json_file_value_serializer.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "mojo/shell/public/cpp/capabilities.h" 12 #include "mojo/shell/public/cpp/capabilities.h"
13 #include "mojo/shell/public/cpp/names.h" 13 #include "mojo/shell/public/cpp/names.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace catalog { 16 namespace catalog {
17 17
18 class BuilderTest : public testing::Test { 18 class EntryTest : public testing::Test {
19 public: 19 public:
20 BuilderTest() {} 20 EntryTest() {}
21 ~BuilderTest() override {} 21 ~EntryTest() override {}
22 22
23 protected: 23 protected:
24 scoped_ptr<base::Value> ReadEntry(const std::string& manifest, Entry* entry) { 24 scoped_ptr<base::Value> ReadEntry(const std::string& manifest, Entry* entry) {
25 DCHECK(entry); 25 DCHECK(entry);
26 scoped_ptr<base::Value> value = ReadManifest(manifest); 26 scoped_ptr<base::Value> value = ReadManifest(manifest);
27 base::DictionaryValue* dictionary = nullptr; 27 base::DictionaryValue* dictionary = nullptr;
28 CHECK(value->GetAsDictionary(&dictionary)); 28 CHECK(value->GetAsDictionary(&dictionary));
29 *entry = BuildEntry(*dictionary); 29 Entry::Deserialize(*dictionary, entry);
30 return value; 30 return value;
31 } 31 }
32 32
33 scoped_ptr<base::Value> ReadManifest(const std::string& manifest) { 33 scoped_ptr<base::Value> ReadManifest(const std::string& manifest) {
34 base::FilePath manifest_path; 34 base::FilePath manifest_path;
35 PathService::Get(base::DIR_SOURCE_ROOT, &manifest_path); 35 PathService::Get(base::DIR_SOURCE_ROOT, &manifest_path);
36 manifest_path = manifest_path.AppendASCII( 36 manifest_path = manifest_path.AppendASCII(
37 "mojo/services/catalog/data/" + manifest); 37 "mojo/services/catalog/data/" + manifest);
38 38
39 JSONFileValueDeserializer deserializer(manifest_path); 39 JSONFileValueDeserializer deserializer(manifest_path);
40 int error = 0; 40 int error = 0;
41 std::string message; 41 std::string message;
42 // TODO(beng): probably want to do more detailed error checking. This should 42 // TODO(beng): probably want to do more detailed error checking. This should
43 // be done when figuring out if to unblock connection 43 // be done when figuring out if to unblock connection
44 // completion. 44 // completion.
45 return deserializer.Deserialize(&error, &message); 45 return deserializer.Deserialize(&error, &message);
46 } 46 }
47 47
48 private: 48 private:
49 void SetUp() override {} 49 void SetUp() override {}
50 void TearDown() override {} 50 void TearDown() override {}
51 51
52 DISALLOW_COPY_AND_ASSIGN(BuilderTest); 52 DISALLOW_COPY_AND_ASSIGN(EntryTest);
53 }; 53 };
54 54
55 TEST_F(BuilderTest, Simple) { 55 TEST_F(EntryTest, Simple) {
56 Entry entry; 56 Entry entry;
57 ReadEntry("simple", &entry); 57 ReadEntry("simple", &entry);
58 58
59 EXPECT_EQ("mojo:foo", entry.name); 59 EXPECT_EQ("mojo:foo", entry.name());
60 EXPECT_EQ(mojo::GetNamePath(entry.name), entry.qualifier); 60 EXPECT_EQ(mojo::GetNamePath(entry.name()), entry.qualifier());
61 EXPECT_EQ("Foo", entry.display_name); 61 EXPECT_EQ("Foo", entry.display_name());
62 } 62 }
63 63
64 TEST_F(BuilderTest, Instance) { 64 TEST_F(EntryTest, Instance) {
65 Entry entry; 65 Entry entry;
66 ReadEntry("instance", &entry); 66 ReadEntry("instance", &entry);
67 67
68 EXPECT_EQ("mojo:foo", entry.name); 68 EXPECT_EQ("mojo:foo", entry.name());
69 EXPECT_EQ("bar", entry.qualifier); 69 EXPECT_EQ("bar", entry.qualifier());
70 EXPECT_EQ("Foo", entry.display_name); 70 EXPECT_EQ("Foo", entry.display_name());
71 } 71 }
72 72
73 TEST_F(BuilderTest, Capabilities) { 73 TEST_F(EntryTest, Capabilities) {
74 Entry entry; 74 Entry entry;
75 ReadEntry("capabilities", &entry); 75 ReadEntry("capabilities", &entry);
76 76
77 EXPECT_EQ("mojo:foo", entry.name); 77 EXPECT_EQ("mojo:foo", entry.name());
78 EXPECT_EQ("bar", entry.qualifier); 78 EXPECT_EQ("bar", entry.qualifier());
79 EXPECT_EQ("Foo", entry.display_name); 79 EXPECT_EQ("Foo", entry.display_name());
80 mojo::CapabilitySpec spec; 80 mojo::CapabilitySpec spec;
81 mojo::CapabilityRequest request; 81 mojo::CapabilityRequest request;
82 request.interfaces.insert("mojo::Bar"); 82 request.interfaces.insert("mojo::Bar");
83 spec.required["mojo:bar"] = request; 83 spec.required["mojo:bar"] = request;
84 EXPECT_EQ(spec, entry.capabilities); 84 EXPECT_EQ(spec, entry.capabilities());
85 } 85 }
86 86
87 TEST_F(BuilderTest, Serialization) { 87 TEST_F(EntryTest, Serialization) {
88 Entry entry; 88 Entry entry;
89 scoped_ptr<base::Value> value = ReadEntry("serialization", &entry); 89 scoped_ptr<base::Value> value = ReadEntry("serialization", &entry);
90 90
91 scoped_ptr<base::DictionaryValue> serialized(SerializeEntry(entry)); 91 scoped_ptr<base::DictionaryValue> serialized(entry.Serialize());
92 92
93 // We can't just compare values, since during deserialization some of the 93 // We can't just compare values, since during deserialization some of the
94 // lists get converted to std::sets, which are sorted, so Value::Equals will 94 // lists get converted to std::sets, which are sorted, so Value::Equals will
95 // fail. 95 // fail.
96 Entry reconstituted = BuildEntry(*serialized.get()); 96 Entry reconstituted;
97 Entry::Deserialize(*serialized.get(), &reconstituted);
97 EXPECT_EQ(entry, reconstituted); 98 EXPECT_EQ(entry, reconstituted);
98 } 99 }
99 100
100 TEST_F(BuilderTest, Malformed) { 101 TEST_F(EntryTest, Malformed) {
101 scoped_ptr<base::Value> value = ReadManifest("malformed"); 102 scoped_ptr<base::Value> value = ReadManifest("malformed");
102 EXPECT_FALSE(value.get()); 103 EXPECT_FALSE(value.get());
103 } 104 }
104 105
105 106
106 } // namespace catalog 107 } // namespace catalog
OLDNEW
« mojo/services/catalog/entry.h ('K') | « mojo/services/catalog/entry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698