[geary] Add an initial/example unit test.
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary] Add an initial/example unit test.
- Date: Tue, 13 Dec 2016 00:32:47 +0000 (UTC)
commit 7683044d61cf066a3aaa635866cf63d62bd3a370
Author: Michael James Gratton <mike vee net>
Date: Mon Dec 12 23:39:46 2016 +1100
Add an initial/example unit test.
test/CMakeLists.txt | 5 ++
test/engine/rfc822-mailbox-address-test.vala | 31 ++++++++++
test/main.vala | 8 ++-
test/testcase.vala | 80 ++++++++++++++++++++++++++
4 files changed, 122 insertions(+), 2 deletions(-)
---
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 83e6023..40d227a 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -4,6 +4,9 @@
set(TEST_SRC
main.vala
+ testcase.vala # Taken as-is from libgee, courtesy Julien Peeters
+
+ engine/rfc822-mailbox-address-test.vala
)
# Vala
@@ -30,6 +33,8 @@ set(CFLAGS
-D_SOURCE_ROOT_DIR=\"${CMAKE_SOURCE_DIR}\"
)
+include_directories(${CMAKE_BINARY_DIR}/src)
+
set(LIB_PATHS ${DEPS_LIBRARY_DIRS})
link_directories(${LIB_PATHS})
add_definitions(${CFLAGS})
diff --git a/test/engine/rfc822-mailbox-address-test.vala b/test/engine/rfc822-mailbox-address-test.vala
new file mode 100644
index 0000000..938e31f
--- /dev/null
+++ b/test/engine/rfc822-mailbox-address-test.vala
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016 Michael Gratton <mike vee net>
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+class Geary.RFC822.MailboxAddressTest : Gee.TestCase {
+
+ public MailboxAddressTest() {
+ base("Geary.RFC822.MailboxAddressTest");
+ add_test("is_valid_address", is_valid_address);
+ }
+
+ public void is_valid_address() {
+ assert(Geary.RFC822.MailboxAddress.is_valid_address("john dep aol.museum") == true);
+ assert(Geary.RFC822.MailboxAddress.is_valid_address("test example com") == true);
+ // This is Bug 714299
+ //assert(Geary.RFC822.MailboxAddress.is_valid_address("test@example") == true);
+ assert(Geary.RFC822.MailboxAddress.is_valid_address("some context test example com text") == true);
+
+ assert(Geary.RFC822.MailboxAddress.is_valid_address("john aol com") == false);
+ assert(Geary.RFC822.MailboxAddress.is_valid_address("@example.com") == false);
+ assert(Geary.RFC822.MailboxAddress.is_valid_address("@example") == false);
+ assert(Geary.RFC822.MailboxAddress.is_valid_address("test") == false);
+ assert(Geary.RFC822.MailboxAddress.is_valid_address("test@") == false);
+ assert(Geary.RFC822.MailboxAddress.is_valid_address("@") == false);
+ assert(Geary.RFC822.MailboxAddress.is_valid_address("") == false);
+ }
+
+}
diff --git a/test/main.vala b/test/main.vala
index 3636691..62ebdf2 100644
--- a/test/main.vala
+++ b/test/main.vala
@@ -5,7 +5,11 @@
* (version 2.1 or later). See the COPYING file in this distribution.
*/
-void main(string[] args) {
+int main(string[] args) {
Test.init(ref args);
- print("OHHAI!");
+ TestSuite root = TestSuite.get_root();
+
+ root.add_suite(new Geary.RFC822.MailboxAddressTest().get_suite());
+
+ return Test.run();
}
diff --git a/test/testcase.vala b/test/testcase.vala
new file mode 100644
index 0000000..83a37ae
--- /dev/null
+++ b/test/testcase.vala
@@ -0,0 +1,80 @@
+/* testcase.vala
+ *
+ * Copyright (C) 2009 Julien Peeters
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library 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
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Julien Peeters <contact julienpeeters fr>
+ */
+
+public abstract class Gee.TestCase : Object {
+
+ private GLib.TestSuite suite;
+ private Adaptor[] adaptors = new Adaptor[0];
+
+ public delegate void TestMethod ();
+
+ public TestCase (string name) {
+ this.suite = new GLib.TestSuite (name);
+ }
+
+ public void add_test (string name, owned TestMethod test) {
+ var adaptor = new Adaptor (name, (owned)test, this);
+ this.adaptors += adaptor;
+
+ this.suite.add (new GLib.TestCase (adaptor.name,
+ adaptor.set_up,
+ adaptor.run,
+ adaptor.tear_down ));
+ }
+
+ public virtual void set_up () {
+ }
+
+ public virtual void tear_down () {
+ }
+
+ public GLib.TestSuite get_suite () {
+ return this.suite;
+ }
+
+ private class Adaptor {
+ [CCode (notify = false)]
+ public string name { get; private set; }
+ private TestMethod test;
+ private TestCase test_case;
+
+ public Adaptor (string name,
+ owned TestMethod test,
+ TestCase test_case) {
+ this.name = name;
+ this.test = (owned)test;
+ this.test_case = test_case;
+ }
+
+ public void set_up (void* fixture) {
+ this.test_case.set_up ();
+ }
+
+ public void run (void* fixture) {
+ this.test ();
+ }
+
+ public void tear_down (void* fixture) {
+ this.test_case.tear_down ();
+ }
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]