| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/services/catalog/builder.h" | |
| 6 | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/json/json_file_value_serializer.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/path_service.h" | |
| 11 #include "base/values.h" | |
| 12 #include "mojo/shell/public/cpp/capabilities.h" | |
| 13 #include "mojo/shell/public/cpp/names.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 namespace catalog { | |
| 17 | |
| 18 class BuilderTest : public testing::Test { | |
| 19 public: | |
| 20 BuilderTest() {} | |
| 21 ~BuilderTest() override {} | |
| 22 | |
| 23 protected: | |
| 24 scoped_ptr<base::Value> ReadEntry(const std::string& manifest, Entry* entry) { | |
| 25 DCHECK(entry); | |
| 26 scoped_ptr<base::Value> value = ReadManifest(manifest); | |
| 27 base::DictionaryValue* dictionary = nullptr; | |
| 28 CHECK(value->GetAsDictionary(&dictionary)); | |
| 29 *entry = BuildEntry(*dictionary); | |
| 30 return value; | |
| 31 } | |
| 32 | |
| 33 scoped_ptr<base::Value> ReadManifest(const std::string& manifest) { | |
| 34 base::FilePath manifest_path; | |
| 35 PathService::Get(base::DIR_SOURCE_ROOT, &manifest_path); | |
| 36 manifest_path = manifest_path.AppendASCII( | |
| 37 "mojo/services/catalog/data/" + manifest); | |
| 38 | |
| 39 JSONFileValueDeserializer deserializer(manifest_path); | |
| 40 int error = 0; | |
| 41 std::string message; | |
| 42 // TODO(beng): probably want to do more detailed error checking. This should | |
| 43 // be done when figuring out if to unblock connection | |
| 44 // completion. | |
| 45 return deserializer.Deserialize(&error, &message); | |
| 46 } | |
| 47 | |
| 48 private: | |
| 49 void SetUp() override {} | |
| 50 void TearDown() override {} | |
| 51 | |
| 52 DISALLOW_COPY_AND_ASSIGN(BuilderTest); | |
| 53 }; | |
| 54 | |
| 55 TEST_F(BuilderTest, Simple) { | |
| 56 Entry entry; | |
| 57 ReadEntry("simple", &entry); | |
| 58 | |
| 59 EXPECT_EQ("mojo:foo", entry.name); | |
| 60 EXPECT_EQ(mojo::GetNamePath(entry.name), entry.qualifier); | |
| 61 EXPECT_EQ("Foo", entry.display_name); | |
| 62 } | |
| 63 | |
| 64 TEST_F(BuilderTest, Instance) { | |
| 65 Entry entry; | |
| 66 ReadEntry("instance", &entry); | |
| 67 | |
| 68 EXPECT_EQ("mojo:foo", entry.name); | |
| 69 EXPECT_EQ("bar", entry.qualifier); | |
| 70 EXPECT_EQ("Foo", entry.display_name); | |
| 71 } | |
| 72 | |
| 73 TEST_F(BuilderTest, Capabilities) { | |
| 74 Entry entry; | |
| 75 ReadEntry("capabilities", &entry); | |
| 76 | |
| 77 EXPECT_EQ("mojo:foo", entry.name); | |
| 78 EXPECT_EQ("bar", entry.qualifier); | |
| 79 EXPECT_EQ("Foo", entry.display_name); | |
| 80 mojo::CapabilitySpec spec; | |
| 81 mojo::CapabilityRequest request; | |
| 82 request.interfaces.insert("mojo::Bar"); | |
| 83 spec.required["mojo:bar"] = request; | |
| 84 EXPECT_EQ(spec, entry.capabilities); | |
| 85 } | |
| 86 | |
| 87 TEST_F(BuilderTest, Serialization) { | |
| 88 Entry entry; | |
| 89 scoped_ptr<base::Value> value = ReadEntry("serialization", &entry); | |
| 90 | |
| 91 scoped_ptr<base::DictionaryValue> serialized(SerializeEntry(entry)); | |
| 92 | |
| 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 | |
| 95 // fail. | |
| 96 Entry reconstituted = BuildEntry(*serialized.get()); | |
| 97 EXPECT_EQ(entry, reconstituted); | |
| 98 } | |
| 99 | |
| 100 TEST_F(BuilderTest, Malformed) { | |
| 101 scoped_ptr<base::Value> value = ReadManifest("malformed"); | |
| 102 EXPECT_FALSE(value.get()); | |
| 103 } | |
| 104 | |
| 105 | |
| 106 } // namespace catalog | |
| OLD | NEW |