~ubuntu-branches/ubuntu/wily/dovecot/wily-proposed

« back to all changes in this revision

Viewing changes to src/lib-mail/test-ostream-dot.c

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2015-09-14 13:58:42 UTC
  • mfrom: (4.1.54 sid)
  • Revision ID: package-import@ubuntu.com-20150914135842-jhpp689shskxt0hu
Tags: 1:2.2.18-2ubuntu1
* Merge with Debian (after 552 days); remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
* d/control: Drop dovecot-postfix package as its no longer required.
* Rename init.d script to work with the dh_installinit --name option, so
  that it comes back. (LP: #1323274)
* d/dovecot-core.config: Drop db_input for ssl-cert-exists; this message
  not actually an error, is documented in the README.Debian, and blocks
  automated upgrades (LP: #1278897).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2013-2015 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "lib.h"
 
4
#include "buffer.h"
 
5
#include "str.h"
 
6
#include "istream.h"
 
7
#include "ostream.h"
 
8
#include "ostream-dot.h"
 
9
#include "test-common.h"
 
10
 
 
11
struct dot_test {
 
12
        const char *input;
 
13
        const char *output;
 
14
};
 
15
 
 
16
static void test_ostream_dot_one(const struct dot_test *test)
 
17
{
 
18
        struct istream *test_input;
 
19
        struct ostream *output, *test_output;
 
20
        buffer_t *output_data;
 
21
        const unsigned char *data;
 
22
        size_t size;
 
23
        ssize_t ret;
 
24
 
 
25
        test_input = test_istream_create(test->input);
 
26
        output_data = buffer_create_dynamic(pool_datastack_create(), 1024);
 
27
        test_output = o_stream_create_buffer(output_data);
 
28
 
 
29
        output = o_stream_create_dot(test_output, FALSE);
 
30
 
 
31
        while ((ret = i_stream_read(test_input)) > 0 || ret == -2) {
 
32
                data = i_stream_get_data(test_input, &size);
 
33
                ret = o_stream_send(output, data, size);
 
34
                test_assert(ret >= 0);
 
35
                if (ret <= 0)
 
36
                        break;
 
37
                i_stream_skip(test_input, ret);
 
38
        }
 
39
 
 
40
        test_assert(test_input->eof);
 
41
 
 
42
        test_assert(o_stream_flush(output) > 0);
 
43
        o_stream_unref(&output);
 
44
        o_stream_unref(&test_output);
 
45
 
 
46
        test_assert(strcmp(str_c(output_data), test->output) == 0);
 
47
 
 
48
        i_stream_unref(&test_input);
 
49
}
 
50
 
 
51
static void test_ostream_dot(void)
 
52
{
 
53
        static struct dot_test tests[] = {
 
54
                { "foo\r\n.\r\n", "foo\r\n..\r\n.\r\n" },
 
55
                { "foo\n.\n", "foo\r\n..\r\n.\r\n" },
 
56
                { ".foo\r\n.\r\nfoo\r\n", "..foo\r\n..\r\nfoo\r\n.\r\n" },
 
57
                { ".foo\n.\nfoo\n", "..foo\r\n..\r\nfoo\r\n.\r\n" },
 
58
                { "\r\n", "\r\n.\r\n" },
 
59
                { "\n", "\r\n.\r\n" },
 
60
                { "", "\r\n.\r\n" },
 
61
        };
 
62
        unsigned int i;
 
63
 
 
64
        for (i = 0; i < N_ELEMENTS(tests); i++) {
 
65
                test_begin(t_strdup_printf("dot ostream[%d]:", i));
 
66
                test_ostream_dot_one(&tests[i]);
 
67
                test_end();
 
68
        }
 
69
}
 
70
 
 
71
int main(void)
 
72
{
 
73
        static void (*test_functions[])(void) = {
 
74
                test_ostream_dot,
 
75
                NULL
 
76
        };
 
77
        return test_run(test_functions);
 
78
}