summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2022-10-24 20:31:30 +0200
committerNiels De Graef <ndegraef@redhat.com>2022-10-24 20:32:22 +0200
commitc9bf51147e95c60c9b68e01b4f180f3fe92d0090 (patch)
tree4e76c2e7a0240f14631645e2f446ab50c9323970 /tests
parent5c011486d6beac60981dafe5741f8acae197ce5d (diff)
downloadgnome-contacts-c9bf51147e95c60c9b68e01b4f180f3fe92d0090.tar.gz
Add tests for several Chunks
They're quite simple at this point, but the idea is to extend them as we put some of the serialization code in there, as well as more advanced logic.
Diffstat (limited to 'tests')
-rw-r--r--tests/core/meson.build8
-rw-r--r--tests/core/test-addresses-chunk.vala64
-rw-r--r--tests/core/test-birthday-chunk.vala46
-rw-r--r--tests/core/test-email-addresses-chunk.vala53
-rw-r--r--tests/core/test-full-name-chunk.vala46
-rw-r--r--tests/core/test-nickname-chunk.vala46
-rw-r--r--tests/core/test-notes-chunk.vala54
-rw-r--r--tests/core/test-phones-chunk.vala53
-rw-r--r--tests/core/test-roles-chunk.vala53
-rw-r--r--tests/core/test-urls-chunk.vala25
10 files changed, 446 insertions, 2 deletions
diff --git a/tests/core/meson.build b/tests/core/meson.build
index ecb8879..4e38475 100644
--- a/tests/core/meson.build
+++ b/tests/core/meson.build
@@ -1,4 +1,12 @@
test_names = [
+ 'test-addresses-chunk',
+ 'test-birthday-chunk',
+ 'test-email-addresses-chunk',
+ 'test-full-name-chunk',
+ 'test-nickname-chunk',
+ 'test-notes-chunk',
+ 'test-phones-chunk',
+ 'test-roles-chunk',
'test-urls-chunk',
]
diff --git a/tests/core/test-addresses-chunk.vala b/tests/core/test-addresses-chunk.vala
new file mode 100644
index 0000000..83ebb61
--- /dev/null
+++ b/tests/core/test-addresses-chunk.vala
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void main (string[] args) {
+ Test.init (ref args);
+ Test.add_func ("/core/addresses-chunk/property-name-chunk", test_property_name);
+ Test.add_func ("/core/addresses-chunk/get-is-empty", test_is_empty);
+ Test.add_func ("/core/addresses-chunk/to-maps-uri", test_to_maps_uri);
+ Test.run ();
+}
+
+// Make sure that "postal-addresses" maps to a UrlsChunk
+private void test_property_name () {
+ var contact = new Contacts.Contact.empty ();
+
+ var chunk = contact.create_chunk ("postal-addresses", null);
+ assert_nonnull (chunk);
+ assert_true (chunk is Contacts.AddressesChunk);
+ assert_true (chunk.property_name == "postal-addresses");
+}
+
+private void test_is_empty () {
+ var contact = new Contacts.Contact.empty ();
+ var chunk = (Contacts.AddressesChunk) contact.create_chunk ("postal-addresses", null);
+ assert_nonnull (chunk);
+ var address = (Contacts.Address) chunk.get_item (0);
+
+ // Even though there is an element, it's empty, so the urls chunk should
+ // count as empty too
+ assert_true (address.is_empty);
+ assert_true (chunk.is_empty);
+
+ address.address.street = "Yellow brick road";
+ assert_false (address.is_empty);
+ assert_false (chunk.is_empty);
+
+ address.address.street = "";
+ assert_true (address.is_empty);
+ assert_true (chunk.is_empty);
+}
+
+private void test_to_maps_uri () {
+ var contact = new Contacts.Contact.empty ();
+ var chunk = (Contacts.AddressesChunk) contact.create_chunk ("postal-addresses", null);
+ assert_nonnull (chunk);
+ var address = (Contacts.Address) chunk.get_item (0);
+
+ address.address.street = "Yellow brick road";
+ assert_true (address.to_maps_uri() == "maps:q=Yellow%20brick%20road");
+}
diff --git a/tests/core/test-birthday-chunk.vala b/tests/core/test-birthday-chunk.vala
new file mode 100644
index 0000000..826cb6d
--- /dev/null
+++ b/tests/core/test-birthday-chunk.vala
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void main (string[] args) {
+ Test.init (ref args);
+ Test.add_func ("/core/birthday-chunk/property_name_chunk", test_property_name);
+ Test.add_func ("/core/birthday-chunk/is-empty", test_is_empty);
+ Test.run ();
+}
+
+// Make sure that "birthday" maps to a BirthdayChunk
+private void test_property_name () {
+ var contact = new Contacts.Contact.empty ();
+
+ var chunk = contact.create_chunk ("birthday", null);
+ assert_nonnull (chunk);
+ assert_true (chunk is Contacts.BirthdayChunk);
+ assert_true (chunk.property_name == "birthday");
+}
+
+private void test_is_empty () {
+ var contact = new Contacts.Contact.empty ();
+ var chunk = (Contacts.BirthdayChunk) contact.create_chunk ("birthday", null);
+ assert_nonnull (chunk);
+ assert_true (chunk.is_empty);
+
+ chunk.birthday = new DateTime.now_utc ();
+ assert_false (chunk.is_empty);
+
+ chunk.birthday = null;
+ assert_true (chunk.is_empty);
+}
diff --git a/tests/core/test-email-addresses-chunk.vala b/tests/core/test-email-addresses-chunk.vala
new file mode 100644
index 0000000..d2d10c7
--- /dev/null
+++ b/tests/core/test-email-addresses-chunk.vala
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void main (string[] args) {
+ Test.init (ref args);
+ Test.add_func ("/core/addresses-chunk/property-name-chunk", test_property_name);
+ Test.add_func ("/core/addresses-chunk/get-is-empty", test_is_empty);
+ Test.run ();
+}
+
+// Make sure that "email-addresses" maps to a UrlsChunk
+private void test_property_name () {
+ var contact = new Contacts.Contact.empty ();
+
+ var chunk = contact.create_chunk ("email-addresses", null);
+ assert_nonnull (chunk);
+ assert_true (chunk is Contacts.EmailAddressesChunk);
+ assert_true (chunk.property_name == "email-addresses");
+}
+
+private void test_is_empty () {
+ var contact = new Contacts.Contact.empty ();
+ var chunk = (Contacts.EmailAddressesChunk) contact.create_chunk ("email-addresses", null);
+ assert_nonnull (chunk);
+ var address = (Contacts.EmailAddress) chunk.get_item (0);
+
+ // Even though there is an element, it's empty, so the urls chunk should
+ // count as empty too
+ assert_true (address.is_empty);
+ assert_true (chunk.is_empty);
+
+ address.raw_address = "neo@matrix.com";
+ assert_false (address.is_empty);
+ assert_false (chunk.is_empty);
+
+ address.raw_address = "";
+ assert_true (address.is_empty);
+ assert_true (chunk.is_empty);
+}
diff --git a/tests/core/test-full-name-chunk.vala b/tests/core/test-full-name-chunk.vala
new file mode 100644
index 0000000..4648b0c
--- /dev/null
+++ b/tests/core/test-full-name-chunk.vala
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void main (string[] args) {
+ Test.init (ref args);
+ Test.add_func ("/core/full-name-chunk/property_name_chunk", test_property_name);
+ Test.add_func ("/core/full-name-chunk/is-empty", test_is_empty);
+ Test.run ();
+}
+
+// Make sure that "full-name" maps to a FullNameChunk
+private void test_property_name () {
+ var contact = new Contacts.Contact.empty ();
+
+ var chunk = contact.create_chunk ("full-name", null);
+ assert_nonnull (chunk);
+ assert_true (chunk is Contacts.FullNameChunk);
+ assert_true (chunk.property_name == "full-name");
+}
+
+private void test_is_empty () {
+ var contact = new Contacts.Contact.empty ();
+ var chunk = (Contacts.FullNameChunk) contact.create_chunk ("full-name", null);
+ assert_nonnull (chunk);
+ assert_true (chunk.is_empty);
+
+ chunk.full_name = "Niels De Graef";
+ assert_false (chunk.is_empty);
+
+ chunk.full_name = "";
+ assert_true (chunk.is_empty);
+}
diff --git a/tests/core/test-nickname-chunk.vala b/tests/core/test-nickname-chunk.vala
new file mode 100644
index 0000000..e32ae52
--- /dev/null
+++ b/tests/core/test-nickname-chunk.vala
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void main (string[] args) {
+ Test.init (ref args);
+ Test.add_func ("/core/nickname-chunk/property_name_chunk", test_property_name);
+ Test.add_func ("/core/nickname-chunk/is-empty", test_is_empty);
+ Test.run ();
+}
+
+// Make sure that "nickname" maps to a NicknameChunk
+private void test_property_name () {
+ var contact = new Contacts.Contact.empty ();
+
+ var chunk = contact.create_chunk ("nickname", null);
+ assert_nonnull (chunk);
+ assert_true (chunk is Contacts.NicknameChunk);
+ assert_true (chunk.property_name == "nickname");
+}
+
+private void test_is_empty () {
+ var contact = new Contacts.Contact.empty ();
+ var chunk = (Contacts.NicknameChunk) contact.create_chunk ("nickname", null);
+ assert_nonnull (chunk);
+ assert_true (chunk.is_empty);
+
+ chunk.nickname = "Niels";
+ assert_false (chunk.is_empty);
+
+ chunk.nickname = "";
+ assert_true (chunk.is_empty);
+}
diff --git a/tests/core/test-notes-chunk.vala b/tests/core/test-notes-chunk.vala
new file mode 100644
index 0000000..52ac9f2
--- /dev/null
+++ b/tests/core/test-notes-chunk.vala
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void main (string[] args) {
+ Test.init (ref args);
+ Test.add_func ("/core/notes-chunk/property-name-chunk", test_property_name);
+ Test.add_func ("/core/notes-chunk/get-is-empty", test_is_empty);
+ Test.run ();
+}
+
+// Make sure that "notes" maps to a NotesChunk
+private void test_property_name () {
+ var contact = new Contacts.Contact.empty ();
+
+ var chunk = contact.create_chunk ("notes", null);
+ assert_nonnull (chunk);
+ assert_true (chunk is Contacts.NotesChunk);
+ assert_true (chunk.property_name == "notes");
+}
+
+private void test_is_empty () {
+ var contact = new Contacts.Contact.empty ();
+ var chunk = (Contacts.NotesChunk) contact.create_chunk ("notes", null);
+ assert_nonnull (chunk);
+ var note = (Contacts.Note) chunk.get_item (0);
+
+ // Even though there is an element, it's empty, so the notes chunk should
+ // count as empty too
+ assert_true (note.is_empty);
+ assert_true (chunk.is_empty);
+
+ note.text = "This is a note";
+ assert_false (note.is_empty);
+ assert_false (chunk.is_empty);
+
+ // Only whitespace should still count as empty
+ note.text = " ";
+ assert_true (note.is_empty);
+ assert_true (chunk.is_empty);
+}
diff --git a/tests/core/test-phones-chunk.vala b/tests/core/test-phones-chunk.vala
new file mode 100644
index 0000000..9fb6c65
--- /dev/null
+++ b/tests/core/test-phones-chunk.vala
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void main (string[] args) {
+ Test.init (ref args);
+ Test.add_func ("/core/phones-chunk/property-name-chunk", test_property_name);
+ Test.add_func ("/core/phones-chunk/get-is-empty", test_is_empty);
+ Test.run ();
+}
+
+// Make sure that "phones" maps to a PhonesChunk
+private void test_property_name () {
+ var contact = new Contacts.Contact.empty ();
+
+ var chunk = contact.create_chunk ("phone-numbers", null);
+ assert_nonnull (chunk);
+ assert_true (chunk is Contacts.PhonesChunk);
+ assert_true (chunk.property_name == "phone-numbers");
+}
+
+private void test_is_empty () {
+ var contact = new Contacts.Contact.empty ();
+ var chunk = (Contacts.PhonesChunk) contact.create_chunk ("phone-numbers", null);
+ assert_nonnull (chunk);
+ var phone = (Contacts.Phone) chunk.get_item (0);
+
+ // Even though there is an element, it's empty, so the phones chunk should
+ // count as empty too
+ assert_true (phone.is_empty);
+ assert_true (chunk.is_empty);
+
+ phone.raw_number = "+321245678";
+ assert_false (phone.is_empty);
+ assert_false (chunk.is_empty);
+
+ phone.raw_number = "";
+ assert_true (phone.is_empty);
+ assert_true (chunk.is_empty);
+}
diff --git a/tests/core/test-roles-chunk.vala b/tests/core/test-roles-chunk.vala
new file mode 100644
index 0000000..f3a59d8
--- /dev/null
+++ b/tests/core/test-roles-chunk.vala
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2022 Niels De Graef <nielsdegraef@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void main (string[] args) {
+ Test.init (ref args);
+ Test.add_func ("/core/roles-chunk/property-name-chunk", test_property_name);
+ Test.add_func ("/core/roles-chunk/get-is-empty", test_is_empty);
+ Test.run ();
+}
+
+// Make sure that "roles" maps to a RolesChunk
+private void test_property_name () {
+ var contact = new Contacts.Contact.empty ();
+
+ var chunk = contact.create_chunk ("roles", null);
+ assert_nonnull (chunk);
+ assert_true (chunk is Contacts.RolesChunk);
+ assert_true (chunk.property_name == "roles");
+}
+
+private void test_is_empty () {
+ var contact = new Contacts.Contact.empty ();
+ var chunk = (Contacts.RolesChunk) contact.create_chunk ("roles", null);
+ assert_nonnull (chunk);
+ var orgrole = (Contacts.OrgRole) chunk.get_item (0);
+
+ // Even though there is an element, it's empty, so the roles chunk should
+ // count as empty too
+ assert_true (orgrole.is_empty);
+ assert_true (chunk.is_empty);
+
+ orgrole.role.organisation_name = "GNOME";
+ assert_false (orgrole.is_empty);
+ assert_false (chunk.is_empty);
+
+ orgrole.role.organisation_name = "";
+ assert_true (orgrole.is_empty);
+ assert_true (chunk.is_empty);
+}
diff --git a/tests/core/test-urls-chunk.vala b/tests/core/test-urls-chunk.vala
index 29e5cbf..183db5c 100644
--- a/tests/core/test-urls-chunk.vala
+++ b/tests/core/test-urls-chunk.vala
@@ -17,8 +17,9 @@
void main (string[] args) {
Test.init (ref args);
- Test.add_func ("/core/urls-chunk/property_name_chunk", test_property_name);
- Test.add_func ("/core/urls-chunk/get_absolute_url", test_get_absolute_url);
+ Test.add_func ("/core/urls-chunk/property-name-chunk", test_property_name);
+ Test.add_func ("/core/urls-chunk/get-absolute-url", test_get_absolute_url);
+ Test.add_func ("/core/urls-chunk/get-is-empty", test_is_empty);
Test.run ();
}
@@ -53,3 +54,23 @@ private void test_get_absolute_url () {
assert_true (url.raw_url == "gnome.org");
assert_true (url.get_absolute_url () == "https://gnome.org");
}
+
+private void test_is_empty () {
+ var contact = new Contacts.Contact.empty ();
+ var chunk = (Contacts.UrlsChunk) contact.create_chunk ("urls", null);
+ assert_nonnull (chunk);
+ var url = (Contacts.Url) chunk.get_item (0);
+
+ // Even though there is an element, it's empty, so the urls chunk should
+ // count as empty too
+ assert_true (url.is_empty);
+ assert_true (chunk.is_empty);
+
+ url.raw_url = "https://gnome.org";
+ assert_false (url.is_empty);
+ assert_false (chunk.is_empty);
+
+ url.raw_url = "";
+ assert_true (url.is_empty);
+ assert_true (chunk.is_empty);
+}