diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-06-12 16:50:26 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-06-12 16:50:26 +0300 |
commit | d894f5a48393adf94e685b4667a281f2795e3f2f (patch) | |
tree | 2e9a893a63a0cf5245a8a6f6e63262ab2f7c635b /libmu_scm | |
parent | 1f3e74f57c2d902ed5e070fc895513dc82f2ef05 (diff) | |
download | mailutils-d894f5a48393adf94e685b4667a281f2795e3f2f.tar.gz mailutils-d894f5a48393adf94e685b4667a281f2795e3f2f.tar.bz2 |
libmu_scm: add testcases for mu-mime functions (with bugfixes)
* libmu_scm/mu_message.c (mu_scm_message_add_owner): Fix owner
list construction.
* libmu_scm/mu_mime.c (mu-mime-create): Fix a bug: both arguments
are optional now.
* libmu_scm/tests/Makefile.am: Add new tests.
* libmu_scm/tests/testsuite.at: Likewise,
New testcases:
* libmu_scm/tests/mime-add-part.at
* libmu_scm/tests/mime-create.at
* libmu_scm/tests/mime-get-num-parts.at
* libmu_scm/tests/mime-get-part.at
* libmu_scm/tests/mime-multipart-p.at
* libmu_scm/tests/mime-p.at
Diffstat (limited to 'libmu_scm')
-rw-r--r-- | libmu_scm/mu_message.c | 14 | ||||
-rw-r--r-- | libmu_scm/mu_mime.c | 2 | ||||
-rw-r--r-- | libmu_scm/tests/Makefile.am | 8 | ||||
-rw-r--r-- | libmu_scm/tests/mime-add-part.at | 64 | ||||
-rw-r--r-- | libmu_scm/tests/mime-create.at | 16 | ||||
-rw-r--r-- | libmu_scm/tests/mime-get-num-parts.at | 14 | ||||
-rw-r--r-- | libmu_scm/tests/mime-get-part.at | 30 | ||||
-rw-r--r-- | libmu_scm/tests/mime-multipart-p.at | 15 | ||||
-rw-r--r-- | libmu_scm/tests/mime-p.at | 11 | ||||
-rw-r--r-- | libmu_scm/tests/testsuite.at | 8 |
10 files changed, 171 insertions, 11 deletions
diff --git a/libmu_scm/mu_message.c b/libmu_scm/mu_message.c index 08bda97bb..10d2e8416 100644 --- a/libmu_scm/mu_message.c +++ b/libmu_scm/mu_message.c @@ -150,17 +150,13 @@ mu_scm_message_add_owner (SCM MESG, SCM owner) struct mu_message *mum = (struct mu_message *) SCM_CDR (MESG); SCM cell; - if (scm_is_bool (mum->mbox)) + if (mum->mbox == NULL) + mum->mbox = scm_cons (owner, SCM_EOL); + else { - mum->mbox = owner; - return; + cell = scm_cons (owner, mum->mbox); + mum->mbox = cell; } - - if (scm_is_pair (mum->mbox)) - cell = scm_cons (owner, mum->mbox); - else - cell = scm_cons (owner, scm_cons (mum->mbox, SCM_EOL)); - mum->mbox = cell; } mu_message_t diff --git a/libmu_scm/mu_mime.c b/libmu_scm/mu_mime.c index da9e8e344..f5ecabbc0 100644 --- a/libmu_scm/mu_mime.c +++ b/libmu_scm/mu_mime.c @@ -101,7 +101,7 @@ SCM_DEFINE_PUBLIC (scm_mu_mime_create, "mu-mime-create", 0, 2, 0, int fl; int status; - if (scm_is_bool (flags)) + if (SCM_UNBNDP (flags) || scm_is_bool (flags)) { /*if (flags == SCM_BOOL_F)*/ fl = 0; diff --git a/libmu_scm/tests/Makefile.am b/libmu_scm/tests/Makefile.am index 9ae2e23ee..391d93adc 100644 --- a/libmu_scm/tests/Makefile.am +++ b/libmu_scm/tests/Makefile.am @@ -77,7 +77,13 @@ TESTSUITE_AT = \ mailbox-append-message.at\ message-delete.at\ message-get-flag.at\ - mailbox-expunge.at + mailbox-expunge.at\ + mime-create.at\ + mime-p.at\ + mime-multipart-p.at\ + mime-get-num-parts.at\ + mime-get-part.at\ + mime-add-part.at TESTSUITE = $(srcdir)/testsuite M4=m4 diff --git a/libmu_scm/tests/mime-add-part.at b/libmu_scm/tests/mime-add-part.at new file mode 100644 index 000000000..ea2c5d09d --- /dev/null +++ b/libmu_scm/tests/mime-add-part.at @@ -0,0 +1,64 @@ +# This file is part of GNU Mailutils -*- Autotest -*- +# Copyright (C) 2018 Free Software Foundation, Inc. +# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> +# This is free software: you are free to change and redistribute it. +# There is NO WARRANTY, to the extent permitted by law. + +AT_SETUP([mu-mime-add-part and mu-mime-get-message]) +AT_KEYWORDS([mime]) +WITH_MAILBOX([spool/mime.msg], + [MU_GUILE_CHECK([ +(use-modules ((ice-9 regex)) + ((ice-9 binary-ports))) + +(let ((mime (mu-mime-create))) + (mu-mime-add-part mime (test-message)) + (mu-mime-add-part mime (test-message)) + (let ((msg (mu-mime-get-message mime))) + (let* ((hdr (mu-message-get-header msg "Content-Type")) + (m (string-match "^multipart/mixed; boundary=\"(.*)\"" hdr)) + (bnd (match:substring m 1))) + (let ((s (with-output-to-string + (lambda () + (let ((port (mu-message-get-port msg "r" #t))) + (do ((c (get-u8 port) (get-u8 port))) + ((eof-object? c)) + (put-u8 (current-output-port) c)) + (close port)))))) + (regexp-substitute/global + (current-output-port) + (make-regexp (regexp-quote bnd)) + s + 'pre "BOUNDARY" 'post)))))], + 0, + [MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="BOUNDARY" + +--BOUNDARY +From: user@example.org +To: someone@example.com +Subject: De omnibus rebus et quibusdam aliis + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat +non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +--BOUNDARY +From: user@example.org +To: someone@example.com +Subject: De omnibus rebus et quibusdam aliis + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat +non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + +--BOUNDARY-- +])]) +AT_CLEANUP + diff --git a/libmu_scm/tests/mime-create.at b/libmu_scm/tests/mime-create.at new file mode 100644 index 000000000..c7ede6eb6 --- /dev/null +++ b/libmu_scm/tests/mime-create.at @@ -0,0 +1,16 @@ +# This file is part of GNU Mailutils -*- Autotest -*- +# Copyright (C) 2018 Free Software Foundation, Inc. +# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> +# This is free software: you are free to change and redistribute it. +# There is NO WARRANTY, to the extent permitted by law. + +AT_SETUP([mu-mime-create (from file)]) +AT_KEYWORDS([mime]) +WITH_MAILBOX([spool/mime.msg], + [MU_GUILE_CHECK([ +(let ((msg (file->message "mbox"))) + (let ((mime (mu-mime-create 0 msg))) + (display mime)))], + 0, + [#<mime 2>])]) +AT_CLEANUP diff --git a/libmu_scm/tests/mime-get-num-parts.at b/libmu_scm/tests/mime-get-num-parts.at new file mode 100644 index 000000000..7a86c06f1 --- /dev/null +++ b/libmu_scm/tests/mime-get-num-parts.at @@ -0,0 +1,14 @@ +# This file is part of GNU Mailutils -*- Autotest -*- +# Copyright (C) 2018 Free Software Foundation, Inc. +# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> +# This is free software: you are free to change and redistribute it. +# There is NO WARRANTY, to the extent permitted by law. + +AT_SETUP([mu-mime-get-num-parts]) +AT_KEYWORDS([mime]) +WITH_MAILBOX([spool/mime.msg], + [MU_GUILE_CHECK([ +(display (mu-mime-get-num-parts (mu-mime-create 0 (file->message "mbox"))))], + 0, + [2])]) +AT_CLEANUP diff --git a/libmu_scm/tests/mime-get-part.at b/libmu_scm/tests/mime-get-part.at new file mode 100644 index 000000000..8eabbcb41 --- /dev/null +++ b/libmu_scm/tests/mime-get-part.at @@ -0,0 +1,30 @@ +# This file is part of GNU Mailutils -*- Autotest -*- +# Copyright (C) 2018 Free Software Foundation, Inc. +# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> +# This is free software: you are free to change and redistribute it. +# There is NO WARRANTY, to the extent permitted by law. + +AT_SETUP([mu-mime-get-part]) +AT_KEYWORDS([mime]) +WITH_MAILBOX([spool/mime.msg], + [MU_GUILE_CHECK([ +(let ((msg (file->message "mbox"))) + (let* ((mime (mu-mime-create 0 msg)) + (part-1 (mu-mime-get-part mime 1)) + (part-2 (mu-mime-get-part mime 2))) + (message-format #t part-1) + (newline) + (display (mu-message-get-header part-1 "Content-ID")) + (newline) + (message-format #t part-2) + (newline) + (display (mu-message-get-header part-2 "Content-ID")) + (newline)))], + 0, + [#<message "X@Y" "Dow Mon Day HH:MM" 14 489> +<5122.1026510654.2@example.net> +#<message "X@Y" "Dow Mon Day HH:MM" 52 2343> +<5122.1026510654.3@example.net> +])]) +AT_CLEANUP + diff --git a/libmu_scm/tests/mime-multipart-p.at b/libmu_scm/tests/mime-multipart-p.at new file mode 100644 index 000000000..4ce9ca961 --- /dev/null +++ b/libmu_scm/tests/mime-multipart-p.at @@ -0,0 +1,15 @@ +# This file is part of GNU Mailutils -*- Autotest -*- +# Copyright (C) 2018 Free Software Foundation, Inc. +# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> +# This is free software: you are free to change and redistribute it. +# There is NO WARRANTY, to the extent permitted by law. + +AT_SETUP([mu-mime-multipart?]) +AT_KEYWORDS([mime]) +WITH_MAILBOX([spool/mime.msg], + [MU_GUILE_CHECK([ +(display (mu-mime-multipart? (mu-mime-create 0 (file->message "mbox")))) +(display (mu-mime-multipart? (mu-mime-create 0 (test-message))))], +0, +[#t#f])]) +AT_CLEANUP diff --git a/libmu_scm/tests/mime-p.at b/libmu_scm/tests/mime-p.at new file mode 100644 index 000000000..150e854e4 --- /dev/null +++ b/libmu_scm/tests/mime-p.at @@ -0,0 +1,11 @@ +# This file is part of GNU Mailutils -*- Autotest -*- +# Copyright (C) 2018 Free Software Foundation, Inc. +# License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> +# This is free software: you are free to change and redistribute it. +# There is NO WARRANTY, to the extent permitted by law. + +AT_SETUP([mu-mime?]) +AT_KEYWORDS([mime]) +WITH_MAILBOX([spool/mime.msg], + [MU_GUILE_CHECK([(exit (if (mu-mime? (mu-mime-create 0 (file->message "mbox"))) 0 1))])]) +AT_CLEANUP diff --git a/libmu_scm/tests/testsuite.at b/libmu_scm/tests/testsuite.at index 7da2503fb..4acef0b3d 100644 --- a/libmu_scm/tests/testsuite.at +++ b/libmu_scm/tests/testsuite.at @@ -78,5 +78,13 @@ m4_include([mailbox-append-message.at]) m4_include([mailbox-expunge.at]) m4_include([message-get-flag.at]) +AT_BANNER([mu-mime functions]) +m4_include([mime-create.at]) +m4_include([mime-p.at]) +m4_include([mime-multipart-p.at]) +m4_include([mime-get-num-parts.at]) +m4_include([mime-get-part.at]) +m4_include([mime-add-part.at]) + # m4_popdef([MU_TEST_MAILBOX]) |