Added some tests for the IMAP4 code
This commit is contained in:
parent
436820da05
commit
54fcc0b0a7
1
Makefile
1
Makefile
|
@ -110,6 +110,7 @@ dist:
|
|||
$(PACKAGE)-$(VERSION)/src/plugins/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/tests/date.c \
|
||||
$(PACKAGE)-$(VERSION)/tests/email.c \
|
||||
$(PACKAGE)-$(VERSION)/tests/imap4.c \
|
||||
$(PACKAGE)-$(VERSION)/tests/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/tests/tests.sh \
|
||||
$(PACKAGE)-$(VERSION)/tests/project.conf \
|
||||
|
|
|
@ -787,30 +787,48 @@ static int _context_status(IMAP4 * imap4, char const * answer)
|
|||
if(*p == ' ') /* skip spaces */
|
||||
for(p++; *p != '\0' && *p == ' '; p++);
|
||||
if(*p == '(')
|
||||
/* parse the data items */
|
||||
for(p++; *p != '\0' && *p != ')'; p++)
|
||||
{
|
||||
if(strncmp(p, messages, sizeof(messages) - 1) == 0
|
||||
&& p[sizeof(messages) - 1] == ' ')
|
||||
{
|
||||
/* number of messages in the mailbox */
|
||||
p += sizeof(messages);
|
||||
sscanf(p, "%u", &u);
|
||||
/* FIXME really implement */
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s() %u messages\n",
|
||||
__func__, u);
|
||||
#endif
|
||||
}
|
||||
if(strncmp(p, recent, sizeof(recent) - 1) == 0
|
||||
else if(strncmp(p, recent, sizeof(recent) - 1) == 0
|
||||
&& p[sizeof(recent) - 1] == ' ')
|
||||
{
|
||||
/* number of recent messages in the mailbox */
|
||||
p += sizeof(recent);
|
||||
sscanf(p, "%u", &u);
|
||||
/* FIXME really implement */
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s() %u recent\n",
|
||||
__func__, u);
|
||||
#endif
|
||||
}
|
||||
if(strncmp(p, unseen, sizeof(unseen) - 1) == 0
|
||||
else if(strncmp(p, unseen, sizeof(unseen) - 1) == 0
|
||||
&& p[sizeof(unseen) - 1] == ' ')
|
||||
{
|
||||
/* number of unseen messages in the mailbox */
|
||||
p += sizeof(unseen);
|
||||
sscanf(p, "%u", &u);
|
||||
/* FIXME really implement */
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s() %u unseen\n",
|
||||
__func__, u);
|
||||
#endif
|
||||
}
|
||||
/* FIXME implement more */
|
||||
else
|
||||
/* skip until the next space */
|
||||
for(; *p != '\0' && *p != ' '; p++);
|
||||
/* skip until the next space */
|
||||
for(; *p != '\0' && *p != ' '; p++);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
TARGETS = date email tests.log
|
||||
TARGETS = date email imap4 tests.log
|
||||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
BINDIR = $(PREFIX)/bin
|
||||
SBINDIR = $(PREFIX)/sbin
|
||||
CC ?= cc
|
||||
CPPFLAGSF= -I ../include
|
||||
CPPFLAGS?=
|
||||
CFLAGSF = -W
|
||||
CFLAGS = -Wall -g -O2 -ffreestanding
|
||||
LDFLAGSF= -L ../src -Wl,-rpath,../src -lMailer
|
||||
LDFLAGS =
|
||||
RM ?= rm -f
|
||||
LN ?= ln -f
|
||||
|
@ -19,19 +19,26 @@ all: $(TARGETS)
|
|||
|
||||
date_OBJS = date.o
|
||||
date_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
date_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
date_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -L ../src -Wl,-rpath,../src -lMailer
|
||||
|
||||
date: $(date_OBJS)
|
||||
$(CC) -o date $(date_OBJS) $(date_LDFLAGS)
|
||||
|
||||
email_OBJS = email.o
|
||||
email_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
email_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
email_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -L ../src -Wl,-rpath,../src -lMailer
|
||||
|
||||
email: $(email_OBJS)
|
||||
$(CC) -o email $(email_OBJS) $(email_LDFLAGS)
|
||||
|
||||
tests.log: email
|
||||
imap4_OBJS = imap4.o
|
||||
imap4_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) `pkg-config --cflags glib-2.0 libSystem` `pkg-config --cflags openssl`
|
||||
imap4_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) `pkg-config --libs glib-2.0 libSystem` `pkg-config --libs openssl` -lssl
|
||||
|
||||
imap4: $(imap4_OBJS)
|
||||
$(CC) -o imap4 $(imap4_OBJS) $(imap4_LDFLAGS)
|
||||
|
||||
tests.log: date email imap4
|
||||
./tests.sh -P "$(PREFIX)" -- "tests.log"
|
||||
|
||||
date.o: date.c ../src/libMailer.a
|
||||
|
@ -40,8 +47,11 @@ date.o: date.c ../src/libMailer.a
|
|||
email.o: email.c ../src/libMailer.a
|
||||
$(CC) $(email_CFLAGS) -c email.c
|
||||
|
||||
imap4.o: imap4.c ../src/account/imap4.c
|
||||
$(CC) $(imap4_CFLAGS) -c imap4.c
|
||||
|
||||
clean:
|
||||
$(RM) -- $(date_OBJS) $(email_OBJS) $(tests.log_OBJS)
|
||||
$(RM) -- $(date_OBJS) $(email_OBJS) $(imap4_OBJS) $(tests.log_OBJS)
|
||||
|
||||
distclean: clean
|
||||
$(RM) -- $(TARGETS)
|
||||
|
|
45
tests/imap4.c
Normal file
45
tests/imap4.c
Normal file
|
@ -0,0 +1,45 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Mailer */
|
||||
/* 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, version 3 of the License.
|
||||
*
|
||||
* 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 <string.h>
|
||||
#include "../src/account/imap4.c"
|
||||
|
||||
|
||||
/* imap4 */
|
||||
static int _imap4_status(char const * progname, char const * title,
|
||||
IMAP4 * imap4, char const * status)
|
||||
{
|
||||
printf("%s: Testing %s\n", progname, title);
|
||||
return _context_status(imap4, status);
|
||||
}
|
||||
|
||||
|
||||
/* main */
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
int ret = 0;
|
||||
IMAP4 imap4;
|
||||
char const status[] = "STATUS \"folder\""
|
||||
" (MESSAGES 3 RECENT 2 UNSEEN 1)";
|
||||
|
||||
memset(&imap4, 0, sizeof(imap4));
|
||||
ret |= _imap4_status(argv[0], "STATUS (1/4)", &imap4, status);
|
||||
ret |= _imap4_status(argv[0], "STATUS (2/4)", &imap4, "()");
|
||||
ret |= _imap4_status(argv[0], "STATUS (3/4)", &imap4, "( )");
|
||||
ret |= _imap4_status(argv[0], "STATUS (4/4)", &imap4, "");
|
||||
return (ret == 0) ? 0 : 2;
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
targets=date,email,tests.log
|
||||
targets=date,email,imap4,tests.log
|
||||
cppflags_force=-I ../include
|
||||
cflags_force=-W
|
||||
cflags=-Wall -g -O2 -ffreestanding
|
||||
ldflags_force=-L ../src -Wl,-rpath,../src -lMailer
|
||||
ldflags=
|
||||
dist=Makefile,tests.sh
|
||||
|
||||
[date]
|
||||
type=binary
|
||||
sources=date.c
|
||||
ldflags=-L ../src -Wl,-rpath,../src -lMailer
|
||||
|
||||
[date.c]
|
||||
depends=../src/libMailer.a
|
||||
|
@ -16,11 +16,21 @@ depends=../src/libMailer.a
|
|||
[email]
|
||||
type=binary
|
||||
sources=email.c
|
||||
ldflags=-L ../src -Wl,-rpath,../src -lMailer
|
||||
|
||||
[email.c]
|
||||
depends=../src/libMailer.a
|
||||
|
||||
[imap4]
|
||||
type=binary
|
||||
sources=imap4.c
|
||||
cflags=`pkg-config --cflags glib-2.0 libSystem` `pkg-config --cflags openssl`
|
||||
ldflags=`pkg-config --libs glib-2.0 libSystem` `pkg-config --libs openssl` -lssl
|
||||
|
||||
[imap4.c]
|
||||
depends=../src/account/imap4.c
|
||||
|
||||
[tests.log]
|
||||
type=script
|
||||
script=./tests.sh
|
||||
depends=email
|
||||
depends=date,email,imap4
|
||||
|
|
|
@ -47,6 +47,7 @@ target="$1"
|
|||
FAILED=
|
||||
./date >> "$target" || FAILED="$FAILED date(error $?)"
|
||||
./email >> "$target" || FAILED="$FAILED email(error $?)"
|
||||
./imap4 >> "$target" || FAILED="$FAILED imap4(error $?)"
|
||||
[ -z "$FAILED" ] && exit 0
|
||||
echo "Failed tests:$FAILED" 1>&2
|
||||
#XXX ignore errors for now
|
||||
|
|
Loading…
Reference in New Issue
Block a user