summaryrefslogtreecommitdiffstats
path: root/toolkit/components/xulstore/tests/gtest
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/xulstore/tests/gtest')
-rw-r--r--toolkit/components/xulstore/tests/gtest/Cargo.toml7
-rw-r--r--toolkit/components/xulstore/tests/gtest/TestXULStore.cpp141
-rw-r--r--toolkit/components/xulstore/tests/gtest/moz.build11
3 files changed, 159 insertions, 0 deletions
diff --git a/toolkit/components/xulstore/tests/gtest/Cargo.toml b/toolkit/components/xulstore/tests/gtest/Cargo.toml
new file mode 100644
index 0000000000..53c75a2100
--- /dev/null
+++ b/toolkit/components/xulstore/tests/gtest/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "xulstore-gtest"
+version = "0.1.0"
+authors = ["The Mozilla Project Developers"]
+
+[lib]
+path = "test.rs"
diff --git a/toolkit/components/xulstore/tests/gtest/TestXULStore.cpp b/toolkit/components/xulstore/tests/gtest/TestXULStore.cpp
new file mode 100644
index 0000000000..50d7f54b80
--- /dev/null
+++ b/toolkit/components/xulstore/tests/gtest/TestXULStore.cpp
@@ -0,0 +1,141 @@
+#include <stdint.h>
+#include "gtest/gtest.h"
+#include "mozilla/XULStore.h"
+#include "nsCOMPtr.h"
+#include "nsString.h"
+
+using mozilla::XULStoreIterator;
+using mozilla::XULStore::GetAttrs;
+using mozilla::XULStore::GetIDs;
+using mozilla::XULStore::GetValue;
+using mozilla::XULStore::HasValue;
+using mozilla::XULStore::RemoveValue;
+using mozilla::XULStore::SetValue;
+
+TEST(XULStore, SetGetValue)
+{
+ nsAutoString doc(u"SetGetValue"_ns);
+ nsAutoString id(u"foo"_ns);
+ nsAutoString attr(u"bar"_ns);
+ nsAutoString value;
+
+ EXPECT_EQ(GetValue(doc, id, attr, value), NS_OK);
+ EXPECT_TRUE(value.EqualsASCII(""));
+
+ {
+ nsAutoString value(u"baz"_ns);
+ EXPECT_EQ(SetValue(doc, id, attr, value), NS_OK);
+ }
+
+ EXPECT_EQ(GetValue(doc, id, attr, value), NS_OK);
+ EXPECT_TRUE(value.EqualsASCII("baz"));
+}
+
+TEST(XULStore, HasValue)
+{
+ nsAutoString doc(u"HasValue"_ns);
+ nsAutoString id(u"foo"_ns);
+ nsAutoString attr(u"bar"_ns);
+ bool hasValue = true;
+ EXPECT_EQ(HasValue(doc, id, attr, hasValue), NS_OK);
+ EXPECT_FALSE(hasValue);
+ nsAutoString value(u"baz"_ns);
+ EXPECT_EQ(SetValue(doc, id, attr, value), NS_OK);
+ EXPECT_EQ(HasValue(doc, id, attr, hasValue), NS_OK);
+ EXPECT_TRUE(hasValue);
+}
+
+TEST(XULStore, RemoveValue)
+{
+ nsAutoString doc(u"RemoveValue"_ns);
+ nsAutoString id(u"foo"_ns);
+ nsAutoString attr(u"bar"_ns);
+ nsAutoString value(u"baz"_ns);
+ EXPECT_EQ(SetValue(doc, id, attr, value), NS_OK);
+ EXPECT_EQ(GetValue(doc, id, attr, value), NS_OK);
+ EXPECT_TRUE(value.EqualsASCII("baz"));
+ EXPECT_EQ(RemoveValue(doc, id, attr), NS_OK);
+ EXPECT_EQ(GetValue(doc, id, attr, value), NS_OK);
+ EXPECT_TRUE(value.EqualsASCII(""));
+}
+
+TEST(XULStore, GetIDsIterator)
+{
+ nsAutoString doc(u"idIterDoc"_ns);
+ nsAutoString id1(u"id1"_ns);
+ nsAutoString id2(u"id2"_ns);
+ nsAutoString id3(u"id3"_ns);
+ nsAutoString attr(u"attr"_ns);
+ nsAutoString value(u"value"_ns);
+ nsAutoString id;
+
+ // Confirm that the store doesn't have any IDs yet.
+ mozilla::UniquePtr<XULStoreIterator> iter;
+ EXPECT_EQ(GetIDs(doc, iter), NS_OK);
+ EXPECT_FALSE(iter->HasMore());
+ // EXPECT_EQ(iter->GetNext(&id), NS_ERROR_FAILURE);
+
+ // Insert with IDs in non-alphanumeric order to confirm
+ // that store will order them when iterating them.
+ EXPECT_EQ(SetValue(doc, id3, attr, value), NS_OK);
+ EXPECT_EQ(SetValue(doc, id1, attr, value), NS_OK);
+ EXPECT_EQ(SetValue(doc, id2, attr, value), NS_OK);
+
+ // Insert different ID for another doc to confirm that store
+ // won't return it when iterating IDs for our doc.
+ nsAutoString otherDoc(u"otherDoc"_ns);
+ nsAutoString otherID(u"otherID"_ns);
+ EXPECT_EQ(SetValue(otherDoc, otherID, attr, value), NS_OK);
+
+ EXPECT_EQ(GetIDs(doc, iter), NS_OK);
+ EXPECT_TRUE(iter->HasMore());
+ EXPECT_EQ(iter->GetNext(&id), NS_OK);
+ EXPECT_TRUE(id.EqualsASCII("id1"));
+ EXPECT_TRUE(iter->HasMore());
+ EXPECT_EQ(iter->GetNext(&id), NS_OK);
+ EXPECT_TRUE(id.EqualsASCII("id2"));
+ EXPECT_TRUE(iter->HasMore());
+ EXPECT_EQ(iter->GetNext(&id), NS_OK);
+ EXPECT_TRUE(id.EqualsASCII("id3"));
+ EXPECT_FALSE(iter->HasMore());
+}
+
+TEST(XULStore, GetAttributeIterator)
+{
+ nsAutoString doc(u"attrIterDoc"_ns);
+ nsAutoString id(u"id"_ns);
+ nsAutoString attr1(u"attr1"_ns);
+ nsAutoString attr2(u"attr2"_ns);
+ nsAutoString attr3(u"attr3"_ns);
+ nsAutoString value(u"value"_ns);
+ nsAutoString attr;
+
+ mozilla::UniquePtr<XULStoreIterator> iter;
+ EXPECT_EQ(GetAttrs(doc, id, iter), NS_OK);
+ EXPECT_FALSE(iter->HasMore());
+ // EXPECT_EQ(iter->GetNext(&attr), NS_ERROR_FAILURE);
+
+ // Insert with attributes in non-alphanumeric order to confirm
+ // that store will order them when iterating them.
+ EXPECT_EQ(SetValue(doc, id, attr3, value), NS_OK);
+ EXPECT_EQ(SetValue(doc, id, attr1, value), NS_OK);
+ EXPECT_EQ(SetValue(doc, id, attr2, value), NS_OK);
+
+ // Insert different attribute for another ID to confirm that store
+ // won't return it when iterating attributes for our ID.
+ nsAutoString otherID(u"otherID"_ns);
+ nsAutoString otherAttr(u"otherAttr"_ns);
+ EXPECT_EQ(SetValue(doc, otherID, otherAttr, value), NS_OK);
+
+ EXPECT_EQ(GetAttrs(doc, id, iter), NS_OK);
+ EXPECT_TRUE(iter->HasMore());
+ EXPECT_EQ(iter->GetNext(&attr), NS_OK);
+ EXPECT_TRUE(attr.EqualsASCII("attr1"));
+ EXPECT_TRUE(iter->HasMore());
+ EXPECT_EQ(iter->GetNext(&attr), NS_OK);
+ EXPECT_TRUE(attr.EqualsASCII("attr2"));
+ EXPECT_TRUE(iter->HasMore());
+ EXPECT_EQ(iter->GetNext(&attr), NS_OK);
+ EXPECT_TRUE(attr.EqualsASCII("attr3"));
+ EXPECT_FALSE(iter->HasMore());
+}
diff --git a/toolkit/components/xulstore/tests/gtest/moz.build b/toolkit/components/xulstore/tests/gtest/moz.build
new file mode 100644
index 0000000000..81fd27a7e7
--- /dev/null
+++ b/toolkit/components/xulstore/tests/gtest/moz.build
@@ -0,0 +1,11 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+UNIFIED_SOURCES += [
+ "TestXULStore.cpp",
+]
+
+FINAL_LIBRARY = "xul-gtest"