Commit ebc69862 authored by Mark Whitaker's avatar Mark Whitaker

Commit of whole code base to git

parents
ACLOCAL_AMFLAGS = -I m4
#SUBDIRS = libeasmail/src . libeasmail/tests
SUBDIRS = eas-daemon/libeas eas-daemon/src eas-daemon/tests . libeasmail/src . check_tests
EXTRA_DIST = autogen.sh
#!/bin/sh
autoreconf --force --install -I config
#!/bin/bash
# Before you try to build the eas-daemon you need to Install the following packages :
# autoconf
# libtool
# libedataserver
# libedataserver1.2-dev
# libdbus-glib-1-dev
# check
# libexpat1-dev
# libsoup2.4-dev
# cmake
# libwbxml (Not from Package Manager - use \\boudica\projects\INT07\Reference\Linux\libwbxml-0.11.beta4.tar.gz)
export GLIB_GENMARSHAL=glib-genmarshal
clear
make clean
./autogen.sh
aclocal
autoconf
autoheader
touch NEWS README AUTHORS ChangeLog
automake --add-missing
./configure
make all
./eas-daemon/src/activesyncd &
make check
killall lt-activesyncd
## Process this file with automake to produce Makefile.in
INCLUDES = -I/usr/include/dbus-1.0 \
-I/usr/lib/dbus-1.0/include \
-I/usr/include/glib-2.0 \
-I/usr/lib/glib-2.0/include
LIBS = -L/usr/lib \
-ldbus-1 \
-lpthread \
-lrt \
-lglib-2.0 \
-ldbus-glib-1 \
-lgobject-2.0 \
-lgthread-2.0
TESTS = check_eas
check_PROGRAMS = check_eas
check_eas_SOURCES = eas_daemon_tests.c \
eas_libeasmail_tests.c \
eas_main_tests.c \
$(top_builddir)/libeasmail/src/libeasmail.h
check_eas_CFLAGS = @CHECK_CFLAGS@
check_eas_LDADD = $(top_builddir)/libeasmail/src/libeasmail.la \
@CHECK_LIBS@
#eas_daemon_tests.c eas_daemon_tests.h
#include <check.h>
#include <glib.h>
#include <dbus/dbus-glib.h>
#include <stdlib.h>
#include <string.h>
#include "../eas-daemon/src/activesyncd-common-defs.h"
#include "../eas-daemon/tests/activesyncd-mail-client-stub.h"
GMainLoop* mainloop = NULL;
static void start_sync_completed(DBusGProxy* proxy, DBusGProxyCall* call, gpointer userData) {
GError* error = NULL;
gboolean rtn = TRUE;
// check to see if any errors have been reported
rtn = dbus_g_proxy_end_call(proxy,
call,
&error,
G_TYPE_INVALID);
mark_point();
if(error){
fail_if(rtn == FALSE, "%s",&(*error->message));
}
mark_point();
g_main_loop_quit (mainloop);
}
START_TEST (test_daemon_connection)
{
DBusGConnection* bus = NULL;
DBusGProxy* remoteEasMail = NULL;
GError* error = NULL;
// initise G type library to allow use of G type objects which provide
// a higher level of programming syntax including the psuedo object
// oriented approach supported by G types
g_type_init();
// initialisation of event loop within the program as required by any
// program using G types
mainloop = g_main_loop_new(NULL, FALSE);
fail_if(mainloop == NULL,
"Error: Failed to create the mainloop");
mark_point();
// get an interface to the standard DBus messaging daemon
bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
mark_point();
fail_if(bus == NULL,&(error->message));
mark_point();
// create object to the EasMail object that will be exposed over the DBus
// interface and return a pointer to this object on the activesyncd
remoteEasMail = dbus_g_proxy_new_for_name(bus,
EAS_SERVICE_NAME,
EAS_SERVICE_MAIL_OBJECT_PATH /*EAS_SERVICE_OBJECT_PATH*/,
EAS_SERVICE_MAIL_INTERFACE /*EAS_SERVICE_INTERFACE*/);
fail_if(mainloop == NULL,
"Error: Couldn't create the proxy object");
mark_point();
// give any value here. in this case -99 is the "known value" for this test
// this value is not checked as part of the test, it is simply required that
// something is passed from the client to the daemon
gint testValue = -99;
// generic dbus call to the "start_sync" method exposed by the EasMail object
// exposed by the daemon via DBus
dbus_g_proxy_begin_call(remoteEasMail, // name of interface object
"start_sync", // name of method on interface object
start_sync_completed, // name of callback function that will be called when "start_sync" completes
NULL, // ?
NULL, // ?
G_TYPE_INT, // type of test value
testValue, // value passed to the start_sync method
G_TYPE_INVALID); // ?
mark_point();
// start the mainloop
g_main_loop_run(mainloop);
}
END_TEST
Suite* eas_daemon_suite(void)
{
Suite* s = suite_create ("eas-daemon");
/* daemon test case */
TCase *tc_deamon = tcase_create ("core");
suite_add_tcase (s, tc_deamon);
tcase_add_test (tc_deamon, test_daemon_connection);
return s;
}
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <check.h>
#include "../libeasmail/src/libeasmail.h"
#include "../libeasmail/src/eas-folder.h"
#include "../libeasmail/src/eas-email-info.h"
#include "../libeasmail/src/eas-attachment.h"
static void testGetMailHandler(EasEmailHandler **email_handler, guint64 accountuid){
// get a handle to the DBus interface and associate the account ID with
// this object
*email_handler = eas_mail_handler_new(accountuid);
// confirm that the handle object has been correctly setup
fail_if(*email_handler == NULL,
"eas_mail_handler_new returns NULL when given a valid ID");
fail_if((*email_handler)->priv == NULL,
"eas_mail_handler_new account ID object (EasEmailHandler *) member priv (EasEmailHandlerPrivate *) NULL");
}
static void testGetFolderHierarchy(EasEmailHandler *email_handler,
gchar *sync_key,
GSList **created,
GSList **updated,
GSList **deleted,
GError **error){
gboolean ret = FALSE;
mark_point();
ret = eas_mail_handler_sync_folder_hierarchy(email_handler, sync_key,
&(*created),
&(*updated),
&(*deleted),
&(*error));
mark_point();
// if the call to the daemon returned an error, report and drop out of the test
if((*error) != NULL){
fail_if(ret == FALSE,"%s",(*error)->message);
}
// the exchange server should increment the sync key and send back to the
// client so that the client can track where it is with regard to sync.
// therefore the key must not be zero as this is the seed value for this test
fail_if(sync_key == 0,
"Sync Key not updated by call the exchange server");
}
static void testGetFolderInfo(EasEmailHandler *email_handler,
gchar *folder_sync_key,
const gchar *folder_id,
GSList **emails_created,
GSList **emails_updated,
GSList **emails_deleted,
gboolean *more_available,
GError **error){
gboolean ret = FALSE;
ret = eas_mail_handler_sync_folder_email_info(email_handler,
folder_sync_key,
folder_id,
&(*emails_created),
&(*emails_updated),
&(*emails_deleted),
more_available,
&(*error));
// if the call to the daemon returned an error, report and drop out of the test
if((*error) != NULL){
fail_if(ret == FALSE,"%s",&(*error)->message);
fail_if(folder_sync_key == 0,
"Folder Sync Key not updated by call the exchange server");
}
}
START_TEST (test_get_mail_handler)
{
guint64 accountuid = 123456789;
EasEmailHandler *email_handler = NULL;
testGetMailHandler(&email_handler, accountuid);
// email_handler = eas_mail_handler_new(accountuid);
fail_if(email_handler == NULL,
"eas_mail_handler_new returns NULL when given a valid ID");
fail_if(email_handler->priv == NULL,
"eas_mail_handler_new account ID object (EasEmailHandler *) member priv (EasEmailHandlerPrivate *) NULL");
}
END_TEST
START_TEST (test_get_init_eas_mail_sync_folder_hierarchy)
{
// This value needs to make sense in the daemon. in the first instance
// it should be hard coded to the value used by the daemon but later
// there should be a mechanism for getting the value from the same place
// that the daemon uses
guint64 accountuid = 123456789;
EasEmailHandler *email_handler = NULL;
// get a handle to the DBus interface and associate the account ID with
// this object
testGetMailHandler(&email_handler, accountuid);
// declare lists to hold the folder information returned by active sync
GSList *created = NULL; //receives a list of EasFolders
GSList *updated = NULL;
GSList *deleted = NULL;
// Sync Key set to Zero. This means that this is the first time the sync is being done,
// there is no persisted sync key from previous sync's, the returned information will be
// the complete folder hierarchy rather than a delta of any changes
gchar *sync_key = "0";
GError *error = NULL;
mark_point();
// call into the daemon to get the folder hierarchy from the exchange server
// testGetFolderHierarchy(email_handler,sync_key,&created,&updated,&deleted,&error);
gboolean ret = FALSE;
mark_point();
ret = eas_mail_handler_sync_folder_hierarchy(email_handler, sync_key,
&created,
&updated,
&deleted,
&error);
mark_point();
// if the call to the daemon returned an error, report and drop out of the test
if(error != NULL){
fail_if(ret == FALSE,
"%s",error->message);
}
// the exchange server should increment the sync key and send back to the
// client so that the client can track where it is with regard to sync.
// therefore the key must not be zero as this is the seed value for this test
fail_if(sync_key == 0,
"Sync Key not updated by call the exchange server");
// free everything!
g_slist_foreach(created, (GFunc)g_object_unref, NULL);
g_slist_foreach(deleted, (GFunc)g_object_unref, NULL);
g_slist_foreach(updated, (GFunc)g_object_unref, NULL);
g_slist_free(created);
g_slist_free(deleted);
g_slist_free(updated);
}
END_TEST
START_TEST (test_get_eas_mail_info_in_folder)
{
guint64 accountuid = 123456789;
EasEmailHandler *email_handler = NULL;
// get a handle to the DBus interface and associate the account ID with
// this object
testGetMailHandler(&email_handler, accountuid);
// declare lists to hold the folder information returned by active sync
GSList *created = NULL; //receives a list of EasFolders
GSList *updated = NULL;
GSList *deleted = NULL;
// Sync Key set to Zero. This means that this is the first time the sync is being done,
// there is no persisted sync key from previous sync's, the returned information will be
// the complete folder hierarchy rather than a delta of any changes
gchar *folder_hierarchy_sync_key = "0";
GError *error = NULL;
// call into the daemon to get the folder hierarchy from the exchange server
testGetFolderHierarchy(email_handler, folder_hierarchy_sync_key,&created,&updated,&deleted,&error);
// fail the test if there is no folder information
fail_unless(created, "No folder information returned from exchange server");
gchar *folder_sync_key = "0";
GSList *emails_created = NULL; //receives a list of EasMails
GSList *emails_updated = NULL;
GSList *emails_deleted = NULL;
EasFolder *folder = NULL;
gboolean more_available = FALSE;
// get the object for the first folder returned in the hierarchy
folder = g_slist_nth_data(created, 0);
// get the folder info for the first folder returned in the hierarchy
testGetFolderInfo(email_handler,folder_sync_key,folder->folder_id,&emails_created,&emails_updated,&emails_deleted,&more_available,&error);
// free email objects in lists of email objects
g_slist_foreach(emails_deleted, (GFunc)g_object_unref, NULL);
g_slist_foreach(emails_updated, (GFunc)g_object_unref, NULL);
g_slist_foreach(emails_created, (GFunc)g_object_unref, NULL);
// free folder objects in lists of folder objects
g_slist_foreach(created, (GFunc)g_object_unref, NULL);
g_slist_foreach(deleted, (GFunc)g_object_unref, NULL);
g_slist_foreach(updated, (GFunc)g_object_unref, NULL);
g_slist_free(created);
g_slist_free(deleted);
g_slist_free(updated);
}
END_TEST
START_TEST (test_eas_mail_handler_fetch_email_body)
{
guint64 accountuid = 123456789;
EasEmailHandler *email_handler = NULL;
// get a handle to the DBus interface and associate the account ID with
// this object
testGetMailHandler(&email_handler, accountuid);
// declare lists to hold the folder information returned by active sync
GSList *created = NULL; //receives a list of EasFolders
GSList *updated = NULL;
GSList *deleted = NULL;
// Sync Key set to Zero. This means that this is the first time the sync is being done,
// there is no persisted sync key from previous sync's, the returned information will be
// the complete folder hierarchy rather than a delta of any changes
gchar *folder_hierarchy_sync_key = "0";
GError *error = NULL;
// call into the daemon to get the folder hierarchy from the exchange server
testGetFolderHierarchy(email_handler, folder_hierarchy_sync_key,&created,&updated,&deleted,&error);
// fail the test if there is no folder information
// fail_unless(created, "No folder information returned from exchange server");
gchar *folder_sync_key = "0";
GSList *emails_created = NULL; //receives a list of EasMails
GSList *emails_updated = NULL;
GSList *emails_deleted = NULL;
gboolean more_available = FALSE;
EasFolder *folder = NULL;
gboolean testMailFound = FALSE;
guint folderIndex;
// loop through the folders in the hierarchy to find a folder with an email in it
for(folderIndex = 0;g_slist_length(created);folderIndex++){
// get the folder info for the current folderIndex
// since the sync id is zero only the created list will contain folders
folder = g_slist_nth(created, folderIndex);
testGetFolderInfo(email_handler,folder_sync_key,folder->folder_id,&emails_created,&emails_updated,&emails_deleted,&more_available,&error);
// if the emails_created list contains email
// get body for first email in the folder and drop out of the loop
if(emails_created){
EasEmailInfo *email = NULL;
gboolean rtn = FALSE;
// get body for first email in the folder
email = g_slist_nth(emails_created, 0);
// destination directory for the mime file
gchar *mime_directory = "/eastests/";
gchar mime_file[256];
strcpy(mime_file,mime_directory);
strcat(mime_file,email->server_id);
// check if the email body file exists
FILE *hBody = NULL;
hBody = fopen(mime_file,"r");
if(hBody){
// if the email body file exists delete it
fclose(hBody);
hBody = NULL;
remove(mime_file);
hBody = fopen(mime_file,"r");
if(hBody){
fclose(hBody);
fail_if(1,"unable to clear existing body file");
}
}
// call method to get body
rtn = eas_mail_handler_fetch_email_body(email_handler,folder->folder_id,email->server_id,mime_directory,&error);
if(rtn == TRUE){
// if reported success check if body file exists
hBody = fopen(mime_file,"r");
fail_if(hBody == NULL,"email body file not created in specified directory");
fclose(hBody);
}
else{
fail_if(1,"%s",error->message);
}
// after getting the body for the first mail, drop out of the loop
testMailFound = TRUE;
break;
}
// else, go round the loop again
}
// fail the test if there is no email in the folder hierarchy as this means the
// test has not exercised the code to get the email body as required by this test case
fail_if(testMailFound == FALSE,"no mail found in the folder hierarchy");
// free email objects in lists of email objects
g_slist_foreach(emails_deleted, (GFunc)g_object_unref, NULL);
g_slist_foreach(emails_updated, (GFunc)g_object_unref, NULL);
g_slist_foreach(emails_created, (GFunc)g_object_unref, NULL);
// free folder objects in lists of folder objects
g_slist_foreach(created, (GFunc)g_object_unref, NULL);
g_slist_foreach(deleted, (GFunc)g_object_unref, NULL);
g_slist_foreach(updated, (GFunc)g_object_unref, NULL);
g_slist_free(created);
g_slist_free(deleted);
g_slist_free(updated);
}
END_TEST
START_TEST (test_eas_mail_handler_fetch_email_attachments)
{
guint64 accountuid = 123456789;
EasEmailHandler *email_handler = NULL;
// get a handle to the DBus interface and associate the account ID with
// this object
testGetMailHandler(&email_handler, accountuid);
// declare lists to hold the folder information returned by active sync
GSList *created = NULL; //receives a list of EasFolders
GSList *updated = NULL;
GSList *deleted = NULL;
// Sync Key set to Zero. This means that this is the first time the sync is being done,
// there is no persisted sync key from previous sync's, the returned information will be
// the complete folder hierarchy rather than a delta of any changes
gchar *folder_hierarchy_sync_key = "0";
GError *error = NULL;
// call into the daemon to get the folder hierarchy from the exchange server
testGetFolderHierarchy(email_handler, folder_hierarchy_sync_key,&created,&updated,&deleted,&error);
// fail the test if there is no folder information
// fail_unless(created, "No folder information returned from exchange server");
gchar *folder_sync_key = "0";
GSList *emails_created = NULL; //receives a list of EasMails
GSList *emails_updated = NULL;
GSList *emails_deleted = NULL;
gboolean more_available = FALSE;
EasFolder *folder = NULL;
guint folderIndex;
gboolean attachmentFound = FALSE;
// loop through the folders in the hierarchy to find a folder with an email in it
for(folderIndex = 0;folderIndex < g_slist_length(created);folderIndex++){
// get the folder info for the current folderIndex
// since the sync id is zero only the created list will contain folders
folder = g_slist_nth(created, folderIndex);
testGetFolderInfo(email_handler,folder_sync_key,folder->folder_id,&emails_created,&emails_updated,&emails_deleted,&more_available,&error);
// if the emails_created list contains email
// loop through the emails in the folder untill we find a mail with attachment
if(emails_created){
EasEmailInfo *email = NULL;
gboolean rtn = FALSE;
guint mailIndex;
for(mailIndex = 0;mailIndex <g_slist_length(emails_created);mailIndex++){
// get header info for next email in the folder
email = g_slist_nth(emails_created, mailIndex);
if(email->attachments){
EasAttachment *attachment = NULL;
attachment = g_slist_nth(email->attachments, 0);
// destination directory for the attachment file
gchar *mime_directory = "/eastests/";
gchar attachment_file[256];
strcpy(attachment_file,mime_directory);
strcat(attachment_file,attachment->file_reference);
// check if the attachment file exists
FILE *hAtt = NULL;
hAtt = fopen(attachment_file,"r");
if(hAtt){
// if the attachment file exists delete it
fclose(hAtt);
hAtt = NULL;
remove(attachment_file);
hAtt = fopen(attachment_file,"r");
if(hAtt){
fclose(hAtt);
fail_if(1,"unable to clear existing attachment file");
}
}
// call method to get attachment
rtn = eas_mail_handler_fetch_email_attachment(email_handler,attachment->file_reference,mime_directory,&error);
if(rtn == TRUE){
// if reported success check if attachment exists
hAtt = fopen(attachment_file,"r");
fail_if(hAtt == NULL,"attachment file not created in specified directory");
fclose(hAtt);
}
else{
fail_if(1,"%s",error->message);
}
// after getting the body for the first mail, drop out of the loop
attachmentFound = TRUE;
break;
}
if(attachmentFound)
break;
}
}
// else, go round the loop again
}
// fail the test if there attachments in the folder hierarchy as this means the
// test has not exercised the code to get an attachment as required by this test case
fail_if(attachmentFound == FALSE,"no mail found in the folder hierarchy");
// free email objects in lists of email objects
g_slist_foreach(emails_deleted, (GFunc)g_object_unref, NULL);
g_slist_foreach(emails_updated, (GFunc)g_object_unref, NULL);
g_slist_foreach(emails_created, (GFunc)g_object_unref, NULL);
// free folder objects in lists of folder objects
g_slist_foreach(created, (GFunc)g_object_unref, NULL);
g_slist_foreach(deleted, (GFunc)g_object_unref, NULL);
g_slist_foreach(updated, (GFunc)g_object_unref, NULL);
g_slist_free(created);
g_slist_free(deleted);
g_slist_free(updated);
}
END_TEST
Suite* eas_libeasmail_suite (void)
{
Suite* s = suite_create ("libeasmail");
/* libeasmail test case */
TCase *tc_libeasmail = tcase_create ("core");
suite_add_tcase (s, tc_libeasmail);
// tcase_add_test (tc_libeasmail, test_get_mail_handler);
// tcase_add_test (tc_libeasmail, test_get_init_eas_mail_sync_folder_hierarchy);
// tcase_add_test (tc_libeasmail, test_get_eas_mail_info_in_folder);
// tcase_add_test (tc_libeasmail, test_eas_mail_handler_fetch_email_body);
tcase_add_test (tc_libeasmail, test_eas_mail_handler_fetch_email_attachments);
return s;
}
#include <stdlib.h>
#include <check.h>
int main (void)
{
int number_failed;
SRunner* sr = srunner_create (eas_daemon_suite());
srunner_add_suite(sr, eas_libeasmail_suite());
srunner_set_xml(sr, "eas-daemon_test.xml");
srunner_set_log (sr, "eas-daemon_test.log");
srunner_run_all (sr, CK_NORMAL);
number_failed = srunner_ntests_failed (sr);
srunner_free (sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
AC_INIT(eas-daemon, 1.0)
AC_PREREQ([2.59])
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([1.10 no-define])
# Checks for libraries.
# This macro is defined in check.m4 and tests if check.h and
# libcheck.a are installed in your system. It sets CHECK_CFLAGS and
# CHECK_LIBS accordingly.
# AM_PATH_CHECK([MINIMUM-VERSION,
# [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
AM_PATH_CHECK()
AC_CONFIG_HEADERS([config.h])
AC_PROG_CXX
AM_PROG_CC_C_O
#AC_CONFIG_SRCDIR(src/libeasmail.c)
AC_SUBST(NO_UNDEFINED)
AM_GLIB_GNU_GETTEXT
AM_DISABLE_STATIC
AC_PROG_LIBTOOL
AC_CONFIG_FILES([Makefile eas-daemon/data/Makefile eas-daemon/libeas/Makefile eas-daemon/src/Makefile eas-daemon/tests/Makefile libeasmail/src/Makefile check_tests/Makefile])
#AC_CONFIG_FILES([Makefile eas-daemon/src/Makefile eas-daemon/tests/Makefile libeasmail/src/Makefile libeasmail/tests/Makefile])
AC_OUTPUT
This diff is collapsed.
Installation Instructions
*************************
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
2006, 2007, 2008, 2009 Free Software Foundation, Inc.
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without warranty of any kind.
Basic Installation
==================
Briefly, the shell commands `./configure; make; make install' should
configure, build, and install this package. The following
more-detailed instructions are generic; see the `README' file for
instructions specific to this package. Some packages provide this