]> granicus.if.org Git - neomutt/commitdiff
test: move address tests
authorRichard Russon <rich@flatcap.org>
Wed, 1 May 2019 15:01:24 +0000 (16:01 +0100)
committerRichard Russon <rich@flatcap.org>
Wed, 1 May 2019 22:39:00 +0000 (23:39 +0100)
test/Makefile.autosetup
test/address.c [deleted file]
test/address/common.h [new file with mode: 0644]
test/address/mutt_addr_for_display.c
test/address/mutt_addr_mbox_to_udomain.c
test/address/mutt_addr_write_single.c
test/main.c

index 510af3b2d2cb22be09de3a07fbd1492e08d216bd..3d03db1382b3a7b49f5b5fdba86b418c2ed4513e 100644 (file)
@@ -1,6 +1,5 @@
 TEST_OBJS   = test/main.o \
-             test/buffer.o \
-             test/address.o
+             test/buffer.o
 
 ADDRESS_OBJS   = test/address/main.o \
                  test/address/mutt_addr_append.o \
diff --git a/test/address.c b/test/address.c
deleted file mode 100644 (file)
index c0acfa1..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * @file
- * Test code for the Address object
- *
- * @authors
- * Copyright (C) 2018 Simon Symeonidis <lethaljellybean@gmail.com>
- *
- * @copyright
- * 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/>.
- */
-
-#define TEST_NO_MAIN
-#include "acutest.h"
-#include "address/lib.h"
-#include "mutt/memory.h"
-#include <string.h>
-
-#define TEST_CHECK_STR_EQ(expected, actual)                                    \
-  do                                                                           \
-  {                                                                            \
-    if (!TEST_CHECK(strcmp(expected, actual) == 0))                            \
-    {                                                                          \
-      TEST_MSG("Expected: %s", expected);                                      \
-      TEST_MSG("Actual  : %s", actual);                                        \
-    }                                                                          \
-  } while (false)
-
-void test_addr_mbox_to_udomain(void)
-{
-  { /* edge cases */
-    char *user = NULL;
-    char *domain = NULL;
-
-    if (!TEST_CHECK(mutt_addr_mbox_to_udomain("bobnodomain@", &user, &domain) == -1) ||
-        !TEST_CHECK(mutt_addr_mbox_to_udomain("bobnodomain", &user, &domain) == -1) ||
-        !TEST_CHECK(mutt_addr_mbox_to_udomain("@nobobohnoez", &user, &domain) == -1) ||
-        !TEST_CHECK(mutt_addr_mbox_to_udomain("", &user, &domain) == -1))
-    {
-      TEST_MSG("bad return");
-    }
-  }
-
-  { /* common */
-    int ret = 0;
-    const char *str = "bob@bobsdomain";
-
-    char *user = NULL;
-    char *domain = NULL;
-    ret = mutt_addr_mbox_to_udomain(str, &user, &domain);
-
-    if (!TEST_CHECK(ret == 0))
-    {
-      TEST_MSG("bad return");
-      TEST_MSG("Expected: %d", 0);
-      TEST_MSG("Actual  : %d", ret);
-    }
-
-    TEST_CHECK_STR_EQ("bob", user);
-    TEST_CHECK_STR_EQ("bobsdomain", domain);
-
-    FREE(&user);
-    FREE(&domain);
-  }
-
-  { /* integration */
-    char buf[256] = { 0 };
-    char per[64] = "bobby bob";
-    char mbx[64] = "bob@bobsdomain";
-
-    struct Address addr = {
-      .personal = per,
-      .mailbox = mbx,
-      .group = 0,
-      .next = NULL,
-      .is_intl = 0,
-      .intl_checked = 0,
-    };
-
-    mutt_addr_write_single(buf, sizeof(buf), &addr, false);
-
-    const char *expected = "bobby bob <bob@bobsdomain>";
-
-    TEST_CHECK_STR_EQ(expected, buf);
-  }
-
-  { /* integration */
-    char per[64] = "bobby bob";
-    char mbx[64] = "bob@bobsdomain";
-
-    struct Address addr = {
-      .personal = per,
-      .mailbox = mbx,
-      .group = 0,
-      .next = NULL,
-      .is_intl = 0,
-      .intl_checked = 0,
-    };
-
-    const char *expected = "bob@bobsdomain";
-    const char *actual = mutt_addr_for_display(&addr);
-
-    TEST_CHECK_STR_EQ(expected, actual);
-  }
-}
diff --git a/test/address/common.h b/test/address/common.h
new file mode 100644 (file)
index 0000000..1c01e1d
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * @file
+ * Test code for the Address object
+ *
+ * @authors
+ * Copyright (C) 2018 Simon Symeonidis <lethaljellybean@gmail.com>
+ *
+ * @copyright
+ * 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/>.
+ */
+
+#define TEST_NO_MAIN
+#include "acutest.h"
+#include <string.h>
+#include "mutt/memory.h"
+#include "address/lib.h"
+
+#define TEST_CHECK_STR_EQ(expected, actual)                                    \
+  do                                                                           \
+  {                                                                            \
+    if (!TEST_CHECK(strcmp(expected, actual) == 0))                            \
+    {                                                                          \
+      TEST_MSG("Expected: %s", expected);                                      \
+      TEST_MSG("Actual  : %s", actual);                                        \
+    }                                                                          \
+  } while (false)
index 71004d66653bceef8d3bc32b73c62dde688df3f3..2f8cc7fb60a8894393d3a659849460f7003aab80 100644 (file)
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "mutt/mutt.h"
 #include "address/lib.h"
+#include "common.h"
 
 void test_mutt_addr_for_display(void)
 {
@@ -33,4 +34,23 @@ void test_mutt_addr_for_display(void)
   {
     TEST_CHECK(!mutt_addr_for_display(NULL));
   }
+
+  { /* integration */
+    char per[64] = "bobby bob";
+    char mbx[64] = "bob@bobsdomain";
+
+    struct Address addr = {
+      .personal = per,
+      .mailbox = mbx,
+      .group = 0,
+      .next = NULL,
+      .is_intl = 0,
+      .intl_checked = 0,
+    };
+
+    const char *expected = "bob@bobsdomain";
+    const char *actual = mutt_addr_for_display(&addr);
+
+    TEST_CHECK_STR_EQ(expected, actual);
+  }
 }
index eac5b7c7d85377ea96f91f3e750e3209bcd12a2b..d8e1df32846a86040bedfc52f788edb04bfbf862 100644 (file)
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "mutt/mutt.h"
 #include "address/lib.h"
+#include "common.h"
 
 void test_mutt_addr_mbox_to_udomain(void)
 {
@@ -45,4 +46,39 @@ void test_mutt_addr_mbox_to_udomain(void)
     char *user = NULL;
     TEST_CHECK(mutt_addr_mbox_to_udomain("apple", &user, NULL) == -1);
   }
+
+  { /* edge cases */
+    char *user = NULL;
+    char *domain = NULL;
+
+    if (!TEST_CHECK(mutt_addr_mbox_to_udomain("bobnodomain@", &user, &domain) == -1) ||
+        !TEST_CHECK(mutt_addr_mbox_to_udomain("bobnodomain", &user, &domain) == -1) ||
+        !TEST_CHECK(mutt_addr_mbox_to_udomain("@nobobohnoez", &user, &domain) == -1) ||
+        !TEST_CHECK(mutt_addr_mbox_to_udomain("", &user, &domain) == -1))
+    {
+      TEST_MSG("bad return");
+    }
+  }
+
+  { /* common */
+    int ret = 0;
+    const char *str = "bob@bobsdomain";
+
+    char *user = NULL;
+    char *domain = NULL;
+    ret = mutt_addr_mbox_to_udomain(str, &user, &domain);
+
+    if (!TEST_CHECK(ret == 0))
+    {
+      TEST_MSG("bad return");
+      TEST_MSG("Expected: %d", 0);
+      TEST_MSG("Actual  : %d", ret);
+    }
+
+    TEST_CHECK_STR_EQ("bob", user);
+    TEST_CHECK_STR_EQ("bobsdomain", domain);
+
+    FREE(&user);
+    FREE(&domain);
+  }
 }
index 09cc0a0f705de2d632db93c5a728638d90e6ccb0..af90391ca0d75db65321aa9d909220c8c877ccdf 100644 (file)
@@ -25,6 +25,7 @@
 #include "config.h"
 #include "mutt/mutt.h"
 #include "address/lib.h"
+#include "common.h"
 
 void test_mutt_addr_write_single(void)
 {
@@ -41,4 +42,25 @@ void test_mutt_addr_write_single(void)
     mutt_addr_write_single(buf, sizeof(buf), NULL, false);
     TEST_CHECK_(1, "mutt_addr_write_single(buf, sizeof(buf), NULL, false)");
   }
+
+  { /* integration */
+    char buf[256] = { 0 };
+    char per[64] = "bobby bob";
+    char mbx[64] = "bob@bobsdomain";
+
+    struct Address addr = {
+      .personal = per,
+      .mailbox = mbx,
+      .group = 0,
+      .next = NULL,
+      .is_intl = 0,
+      .intl_checked = 0,
+    };
+
+    mutt_addr_write_single(buf, sizeof(buf), &addr, false);
+
+    const char *expected = "bobby bob <bob@bobsdomain>";
+
+    TEST_CHECK_STR_EQ(expected, buf);
+  }
 }
index 43209aaa6699e86bea8b774ea0c9a45014243a77..d5ba2eec70a8a467bde64bd0cd16a1f6b65d4451 100644 (file)
@@ -26,7 +26,6 @@
  * Add your test cases to this list.
  *****************************************************************************/
 #define NEOMUTT_TEST_LIST                                                      \
-  NEOMUTT_TEST_ITEM(test_addr_mbox_to_udomain)                                 \
   NEOMUTT_TEST_ITEM(test_mutt_buffer_concat_path)                              \
 
 /******************************************************************************