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

Unified Diff: mojo/services/catalog/builder_unittest.cc

Issue 1779683002: Add catalog unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@43catalog
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/services/catalog/builder.cc ('k') | mojo/services/catalog/catalog.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/catalog/builder_unittest.cc
diff --git a/mojo/services/catalog/builder_unittest.cc b/mojo/services/catalog/builder_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4290a2f0c8ef94fef76cd27eed17681e429bc643
--- /dev/null
+++ b/mojo/services/catalog/builder_unittest.cc
@@ -0,0 +1,89 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/catalog/builder.h"
+
+#include "base/files/file_path.h"
+#include "base/json/json_file_value_serializer.h"
+#include "base/macros.h"
+#include "base/path_service.h"
+#include "base/values.h"
+#include "mojo/shell/public/cpp/names.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class BuilderTest : public testing::Test {
+ public:
+ BuilderTest() {}
+ ~BuilderTest() override {}
+
+ protected:
+ scoped_ptr<base::Value> ReadManifest(const std::string& manifest) {
+ base::FilePath manifest_path;
+ PathService::Get(base::DIR_SOURCE_ROOT, &manifest_path);
+ manifest_path = manifest_path.AppendASCII(
+ "mojo/services/catalog/data/" + manifest);
+
+ JSONFileValueDeserializer deserializer(manifest_path);
+ int error = 0;
+ std::string message;
+ // TODO(beng): probably want to do more detailed error checking. This should
+ // be done when figuring out if to unblock connection
+ // completion.
+ return deserializer.Deserialize(&error, &message);
+ }
+
+ private:
+ void SetUp() override {}
+ void TearDown() override {}
+
+ DISALLOW_COPY_AND_ASSIGN(BuilderTest);
+};
+
+namespace catalog {
+
+TEST_F(BuilderTest, Simple) {
+ scoped_ptr<base::Value> value = ReadManifest("simple");
+ base::DictionaryValue* dictionary = nullptr;
+ CHECK(value->GetAsDictionary(&dictionary));
+ Entry entry = BuildEntry(*dictionary);
+
+ EXPECT_EQ("mojo:foo", entry.name);
+ EXPECT_EQ(mojo::GetNamePath(entry.name), entry.qualifier);
+ EXPECT_EQ("Foo", entry.display_name);
+}
+
+TEST_F(BuilderTest, Instance) {
+ scoped_ptr<base::Value> value = ReadManifest("instance");
+ base::DictionaryValue* dictionary = nullptr;
+ CHECK(value->GetAsDictionary(&dictionary));
+ Entry entry = BuildEntry(*dictionary);
+
+ EXPECT_EQ("mojo:foo", entry.name);
+ EXPECT_EQ("bar", entry.qualifier);
+ EXPECT_EQ("Foo", entry.display_name);
+}
+
+TEST_F(BuilderTest, Capabilities) {
+ scoped_ptr<base::Value> value = ReadManifest("capabilities");
+ base::DictionaryValue* dictionary = nullptr;
+ CHECK(value->GetAsDictionary(&dictionary));
+ Entry entry = BuildEntry(*dictionary);
+
+ EXPECT_EQ("mojo:foo", entry.name);
+ EXPECT_EQ("bar", entry.qualifier);
+ EXPECT_EQ("Foo", entry.display_name);
+ CapabilityFilter filter;
+ AllowedInterfaces interfaces;
+ interfaces.insert("mojo::Bar");
+ filter["mojo:bar"] = interfaces;
+ EXPECT_EQ(filter, entry.capabilities);
+}
+
+TEST_F(BuilderTest, Malformed) {
+ scoped_ptr<base::Value> value = ReadManifest("malformed");
+ EXPECT_FALSE(value.get());
+}
+
+
+} // namespace catalog
« no previous file with comments | « mojo/services/catalog/builder.cc ('k') | mojo/services/catalog/catalog.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698