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)/src/plugins/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/tests/date.c \
|
$(PACKAGE)-$(VERSION)/tests/date.c \
|
||||||
$(PACKAGE)-$(VERSION)/tests/email.c \
|
$(PACKAGE)-$(VERSION)/tests/email.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/tests/imap4.c \
|
||||||
$(PACKAGE)-$(VERSION)/tests/Makefile \
|
$(PACKAGE)-$(VERSION)/tests/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/tests/tests.sh \
|
$(PACKAGE)-$(VERSION)/tests/tests.sh \
|
||||||
$(PACKAGE)-$(VERSION)/tests/project.conf \
|
$(PACKAGE)-$(VERSION)/tests/project.conf \
|
||||||
|
|
|
@ -787,30 +787,48 @@ static int _context_status(IMAP4 * imap4, char const * answer)
|
||||||
if(*p == ' ') /* skip spaces */
|
if(*p == ' ') /* skip spaces */
|
||||||
for(p++; *p != '\0' && *p == ' '; p++);
|
for(p++; *p != '\0' && *p == ' '; p++);
|
||||||
if(*p == '(')
|
if(*p == '(')
|
||||||
|
/* parse the data items */
|
||||||
for(p++; *p != '\0' && *p != ')'; p++)
|
for(p++; *p != '\0' && *p != ')'; p++)
|
||||||
{
|
{
|
||||||
if(strncmp(p, messages, sizeof(messages) - 1) == 0
|
if(strncmp(p, messages, sizeof(messages) - 1) == 0
|
||||||
&& p[sizeof(messages) - 1] == ' ')
|
&& p[sizeof(messages) - 1] == ' ')
|
||||||
{
|
{
|
||||||
|
/* number of messages in the mailbox */
|
||||||
p += sizeof(messages);
|
p += sizeof(messages);
|
||||||
sscanf(p, "%u", &u);
|
sscanf(p, "%u", &u);
|
||||||
/* FIXME really implement */
|
/* 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] == ' ')
|
&& p[sizeof(recent) - 1] == ' ')
|
||||||
{
|
{
|
||||||
|
/* number of recent messages in the mailbox */
|
||||||
p += sizeof(recent);
|
p += sizeof(recent);
|
||||||
sscanf(p, "%u", &u);
|
sscanf(p, "%u", &u);
|
||||||
/* FIXME really implement */
|
/* 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] == ' ')
|
&& p[sizeof(unseen) - 1] == ' ')
|
||||||
{
|
{
|
||||||
|
/* number of unseen messages in the mailbox */
|
||||||
p += sizeof(unseen);
|
p += sizeof(unseen);
|
||||||
sscanf(p, "%u", &u);
|
sscanf(p, "%u", &u);
|
||||||
/* FIXME really implement */
|
/* 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 */
|
/* skip until the next space */
|
||||||
for(; *p != '\0' && *p != ' '; p++);
|
for(; *p != '\0' && *p != ' '; p++);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
TARGETS = date email tests.log
|
TARGETS = date email imap4 tests.log
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
DESTDIR =
|
DESTDIR =
|
||||||
BINDIR = $(PREFIX)/bin
|
BINDIR = $(PREFIX)/bin
|
||||||
|
SBINDIR = $(PREFIX)/sbin
|
||||||
CC ?= cc
|
CC ?= cc
|
||||||
CPPFLAGSF= -I ../include
|
CPPFLAGSF= -I ../include
|
||||||
CPPFLAGS?=
|
CPPFLAGS?=
|
||||||
CFLAGSF = -W
|
CFLAGSF = -W
|
||||||
CFLAGS = -Wall -g -O2 -ffreestanding
|
CFLAGS = -Wall -g -O2 -ffreestanding
|
||||||
LDFLAGSF= -L ../src -Wl,-rpath,../src -lMailer
|
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
RM ?= rm -f
|
RM ?= rm -f
|
||||||
LN ?= ln -f
|
LN ?= ln -f
|
||||||
|
@ -19,19 +19,26 @@ all: $(TARGETS)
|
||||||
|
|
||||||
date_OBJS = date.o
|
date_OBJS = date.o
|
||||||
date_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
date_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
date_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
date_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -L ../src -Wl,-rpath,../src -lMailer
|
||||||
|
|
||||||
date: $(date_OBJS)
|
date: $(date_OBJS)
|
||||||
$(CC) -o date $(date_OBJS) $(date_LDFLAGS)
|
$(CC) -o date $(date_OBJS) $(date_LDFLAGS)
|
||||||
|
|
||||||
email_OBJS = email.o
|
email_OBJS = email.o
|
||||||
email_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
email_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
email_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
email_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) -L ../src -Wl,-rpath,../src -lMailer
|
||||||
|
|
||||||
email: $(email_OBJS)
|
email: $(email_OBJS)
|
||||||
$(CC) -o email $(email_OBJS) $(email_LDFLAGS)
|
$(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"
|
./tests.sh -P "$(PREFIX)" -- "tests.log"
|
||||||
|
|
||||||
date.o: date.c ../src/libMailer.a
|
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
|
email.o: email.c ../src/libMailer.a
|
||||||
$(CC) $(email_CFLAGS) -c email.c
|
$(CC) $(email_CFLAGS) -c email.c
|
||||||
|
|
||||||
|
imap4.o: imap4.c ../src/account/imap4.c
|
||||||
|
$(CC) $(imap4_CFLAGS) -c imap4.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) -- $(date_OBJS) $(email_OBJS) $(tests.log_OBJS)
|
$(RM) -- $(date_OBJS) $(email_OBJS) $(imap4_OBJS) $(tests.log_OBJS)
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean
|
||||||
$(RM) -- $(TARGETS)
|
$(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
|
cppflags_force=-I ../include
|
||||||
cflags_force=-W
|
cflags_force=-W
|
||||||
cflags=-Wall -g -O2 -ffreestanding
|
cflags=-Wall -g -O2 -ffreestanding
|
||||||
ldflags_force=-L ../src -Wl,-rpath,../src -lMailer
|
|
||||||
ldflags=
|
ldflags=
|
||||||
dist=Makefile,tests.sh
|
dist=Makefile,tests.sh
|
||||||
|
|
||||||
[date]
|
[date]
|
||||||
type=binary
|
type=binary
|
||||||
sources=date.c
|
sources=date.c
|
||||||
|
ldflags=-L ../src -Wl,-rpath,../src -lMailer
|
||||||
|
|
||||||
[date.c]
|
[date.c]
|
||||||
depends=../src/libMailer.a
|
depends=../src/libMailer.a
|
||||||
|
@ -16,11 +16,21 @@ depends=../src/libMailer.a
|
||||||
[email]
|
[email]
|
||||||
type=binary
|
type=binary
|
||||||
sources=email.c
|
sources=email.c
|
||||||
|
ldflags=-L ../src -Wl,-rpath,../src -lMailer
|
||||||
|
|
||||||
[email.c]
|
[email.c]
|
||||||
depends=../src/libMailer.a
|
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]
|
[tests.log]
|
||||||
type=script
|
type=script
|
||||||
script=./tests.sh
|
script=./tests.sh
|
||||||
depends=email
|
depends=date,email,imap4
|
||||||
|
|
|
@ -47,6 +47,7 @@ target="$1"
|
||||||
FAILED=
|
FAILED=
|
||||||
./date >> "$target" || FAILED="$FAILED date(error $?)"
|
./date >> "$target" || FAILED="$FAILED date(error $?)"
|
||||||
./email >> "$target" || FAILED="$FAILED email(error $?)"
|
./email >> "$target" || FAILED="$FAILED email(error $?)"
|
||||||
|
./imap4 >> "$target" || FAILED="$FAILED imap4(error $?)"
|
||||||
[ -z "$FAILED" ] && exit 0
|
[ -z "$FAILED" ] && exit 0
|
||||||
echo "Failed tests:$FAILED" 1>&2
|
echo "Failed tests:$FAILED" 1>&2
|
||||||
#XXX ignore errors for now
|
#XXX ignore errors for now
|
||||||
|
|
Loading…
Reference in New Issue
Block a user