/
new_mail_observer.c
64 lines (56 loc) · 1.87 KB
/
new_mail_observer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @file
* Test code for new_mail_observer()
*
* @authors
* Copyright (C) 2022 Michal Siedlaczek <michal@siedlaczek.me>
*
* @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/>.
*/
#include "mutt/notify.h"
#include "mutt/observer.h"
#include "mutt/string2.h"
#define TEST_NO_MAIN
#include "config.h"
#include "acutest.h"
#include "core/lib.h"
#include "newmail/lib.h"
static char *message = NULL;
int dummy_execute_cmd(const char *cmd)
{
message = mutt_str_dup(cmd);
return 0;
}
int dummy_new_mail_observer(struct NotifyCallback *nc)
{
return handle_new_mail_event("New messages", nc, dummy_execute_cmd);
}
void test_new_mail_observer(void)
{
struct Notify *notify = notify_new();
notify_observer_add(notify, NT_MAILBOX, dummy_new_mail_observer, NULL);
struct Mailbox *mailbox = mailbox_new();
mailbox->name = mutt_str_dup("Mailbox");
struct EventMailbox event = { mailbox, ARRAY_HEAD_INITIALIZER };
notify_send(notify, NT_MAILBOX, NT_MAILBOX_NEW_MAIL, NULL);
TEST_CHECK(message == NULL);
notify_send(notify, NT_MAILBOX, NT_MAILBOX_NEW_MAIL, &event);
TEST_CHECK(message != NULL);
TEST_CHECK(mutt_str_equal(message, "New messages"));
TEST_MSG("Check failed: \"%s\" != \"New messages\"", message);
notify_free(¬ify);
mailbox_free(&mailbox);
FREE(&message);
}