Back to index

webcit  8.12-dfsg
Functions | Variables
test_main.c File Reference
#include "../webcit.h"
#include "../webserver.h"
#include "../modules_init.h"
#include <CUnit/CUnit.h>
#include <CUnit/Basic.h>
#include <CUnit/TestDB.h>

Go to the source code of this file.

Functions

CU_EXPORT void CU_automated_run_tests (void)
CU_EXPORT CU_ErrorCode CU_list_tests_to_file (void)
CU_EXPORT void CU_set_output_filename (const char *szFilenameRoot)
void run_tests (void)
int ig_tcp_server (char *ip_addr, int port_number, int queue_len)
int ig_uds_server (char *sockpath, int queue_len)
void webcit_calc_dirs_n_files (int relh, const char *basedir, int home, char *webcitdir, char *relhome)
void InitTemplateCache (void)
int main (int argc, char **argv)

Variables

int msock
int verbosity
char static_icon_dir [PATH_MAX]
int is_https = 0
int follow_xff = 0
int home_specified = 0
int DisableGzip = 0
pthread_mutex_t SessionListMutex
pthread_key_t MyConKey
char socket_dir [PATH_MAX]
char * server_cookie = NULL
int http_port = PORT_NUM
char * ctdlhost = DEFAULT_HOST
char * ctdlport = DEFAULT_PORT
int running_as_daemon = 0
char wizard_filename [PATH_MAX]
StrBuf * Username = NULL
StrBuf * Passvoid = NULL
int dbg_analyze_msg
int dbg_bactrace_template_errors
int DumpTemplateI18NStrings
StrBuf * I18nDump
int LoadTemplates

Function Documentation

CU_EXPORT void CU_automated_run_tests ( void  )
CU_EXPORT CU_ErrorCode CU_list_tests_to_file ( void  )
CU_EXPORT void CU_set_output_filename ( const char *  szFilenameRoot)

Here is the caller graph for this function:

int ig_tcp_server ( char *  ip_addr,
int  port_number,
int  queue_len 
)
int ig_uds_server ( char *  sockpath,
int  queue_len 
)
void InitTemplateCache ( void  )

Definition at line 1489 of file subst.c.

{
       int i;
       StrBuf *Key;
       StrBuf *Dir;
       HashList *Templates[2];

       Dir = NewStrBuf();
       Key = NewStrBuf();

       /* Primary Template set... */
       StrBufPrintf(Dir, "%s/t", static_dirs[0]);
       LoadTemplateDir(Dir,
                     TemplateCache, 
                     Key);

       /* User local Template set */
       StrBufPrintf(Dir, "%s/t", static_dirs[1]);
       LoadTemplateDir(Dir,
                     LocalTemplateCache, 
                     Key);
       
       /* Debug Templates, just to be loaded while debugging. */
       
       StrBufPrintf(Dir, "%s/dbg", static_dirs[0]);
       LoadTemplateDir(Dir,
                     TemplateCache, 
                     Key);
       Templates[0] = TemplateCache;
       Templates[1] = LocalTemplateCache;


       if (LoadTemplates == 0) 
              for (i=0; i < 2; i++) {
                     const char *Key;
                     long KLen;
                     HashPos *At;
                     void *vTemplate;

                     At = GetNewHashPos(Templates[i], 0);
                     while (GetNextHashPos(Templates[i], 
                                         At, 
                                         &KLen,
                                         &Key, 
                                         &vTemplate) && 
                            (vTemplate != NULL))
                     {
                            load_template(NULL, (WCTemplate *)vTemplate);
                     }
                     DeleteHashPos(&At);
              }


       FreeStrBuf(&Dir);
       FreeStrBuf(&Key);
}
int main ( int  argc,
char **  argv 
)

Definition at line 66 of file test_main.c.

{
       size_t basesize = 2;            /* how big should strbufs be on creation? */
       pthread_attr_t attr;        /* Thread attributes */
       int a;               /* General-purpose variables */
       char tracefile[PATH_MAX];
       char ip_addr[256]="0.0.0.0";
       int relh=0;
       int home=0;
       int home_specified=0;
       char relhome[PATH_MAX]="";
       char webcitdir[PATH_MAX] = DATADIR;
       char *hdir;
       const char *basedir = NULL;
       char uds_listen_path[PATH_MAX];    /* listen on a unix domain socket? */
       FILE *rvfp = NULL;
       
       WildFireInitBacktrace(argv[0], 2);

       start_modules ();

       /* Ensure that we are linked to the correct version of libcitadel */
       if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
              fprintf(stderr, " You are running libcitadel version %d.%02d\n",
                     (libcitadel_version_number() / 100), (libcitadel_version_number() % 100));
              fprintf(stderr, "WebCit was compiled against version %d.%02d\n",
                     (LIBCITADEL_VERSION_NUMBER / 100), (LIBCITADEL_VERSION_NUMBER % 100));
              return(1);
       }

       strcpy(uds_listen_path, "");

       /* Parse command line */
       while ((a = getopt(argc, argv, "h:i:p:t:T:B:x:U:P:cf:Z")) != EOF)
              switch (a) {
              case 'U':
                     Username = NewStrBufPlain(optarg, -1);
                     break;
              case 'P':
                     Passvoid = NewStrBufPlain(optarg, -1);
                     break;
              case 'h':
                     hdir = strdup(optarg);
                     relh=hdir[0]!='/';
                     if (!relh) {
                            safestrncpy(webcitdir, hdir, sizeof webcitdir);
                     }
                     else {
                            safestrncpy(relhome, relhome, sizeof relhome);
                     }
                     /* free(hdir); TODO: SHOULD WE DO THIS? */
                     home_specified = 1;
                     home=1;
                     break;
              case 'B': /* Basesize */
                     basesize = atoi(optarg);
                     if (basesize > 2)
                            StartLibCitadel(basesize);
                     break;
              case 'i':
                     safestrncpy(ip_addr, optarg, sizeof ip_addr);
                     break;
              case 'p':
                     http_port = atoi(optarg);
                     if (http_port == 0) {
                            safestrncpy(uds_listen_path, optarg, sizeof uds_listen_path);
                     }
                     break;
              case 't':
                     safestrncpy(tracefile, optarg, sizeof tracefile);
                     rvfp = freopen(tracefile, "w", stdout);
                     rvfp = freopen(tracefile, "w", stderr);
                     rvfp = freopen(tracefile, "r", stdin);
                     break;
              case 'T':
                     LoadTemplates = atoi(optarg);
                     dbg_analyze_msg = (LoadTemplates && (1<<1)) != 0;
                     dbg_bactrace_template_errors = (LoadTemplates && (1<<2)) != 0;
                     break;
              case 'Z':
                     DisableGzip = 1;
                     break;
              case 'x':
                     verbosity = atoi(optarg);
                     break;
              case 'f':
                     follow_xff = 1;
                     break;
              case 'c':
                     server_cookie = malloc(256);
                     if (server_cookie != NULL) {
                            safestrncpy(server_cookie,
                                   "Set-cookie: wcserver=",
                                   256);
                            if (gethostname
                                (&server_cookie[strlen(server_cookie)],
                                 200) != 0) {
                                   syslog(2, "gethostname: %s\n",
                                          strerror(errno));
                                   free(server_cookie);
                            }
                     }
                     break;
              default:
                     fprintf(stderr, "usage: webcit "
                            "[-i ip_addr] [-p http_port] "
                            "[-t tracefile] [-c] [-f] "
                            "[-T Templatedebuglevel] "
                            "[-Z] [-G i18ndumpfile] "
#ifdef HAVE_OPENSSL
                            "[-s] [-S cipher_suites]"
#endif
                            "[-U Username -P Password]"
                            ""
                            "[remotehost [remoteport]]\n");
                     return 1;
              }

       if (optind < argc) {
              ctdlhost = argv[optind];
              if (++optind < argc)
                     ctdlport = argv[optind];
       }

       webcit_calc_dirs_n_files(relh, basedir, home, webcitdir, relhome);
       LoadIconDir(static_icon_dir);

       /* Tell 'em who's in da house */
       syslog(1, PACKAGE_STRING "\n");
       syslog(1, "Copyright (C) 1996-2009 by the Citadel development team.\n"
              "This software is distributed under the terms of the "
              "GNU General Public License.\n\n"
       );


       /* initialize the International Bright Young Thing */

       initialise_modules();
       initialize_viewdefs();
       initialize_axdefs();

       InitTemplateCache();

       /* Use our own prefix on tzid's generated from system tzdata */
       icaltimezone_set_tzid_prefix("/citadel.org/");

       /*
        * Set up a place to put thread-specific data.
        * We only need a single pointer per thread - it points to the
        * wcsession struct to which the thread is currently bound.
        */
       if (pthread_key_create(&MyConKey, NULL) != 0) {
              syslog(1, "Can't create TSD key: %s\n", strerror(errno));
       }
       InitialiseSemaphores ();


       /*
        * Start up the housekeeping thread
        */
       pthread_attr_init(&attr);
       pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

       run_tests();

       ShutDownWebcit();
       FreeStrBuf(&Username);
       FreeStrBuf(&Passvoid);

       return 0;
}

Here is the call graph for this function:

void run_tests ( void  )

Definition at line 308 of file test_tools.c.

{
       setvbuf(stdout, NULL, _IONBF, 0);

       CU_set_output_filename("TestAutomated");
       if (CU_initialize_registry()) {
              printf("\nInitialize of test Registry failed.");
       }

       AddTests();

       printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
       CU_cleanup_registry();

}

Here is the call graph for this function:

Here is the caller graph for this function:

void webcit_calc_dirs_n_files ( int  relh,
const char *  basedir,
int  home,
char *  webcitdir,
char *  relhome 
)

Definition at line 452 of file sysdep.c.

{
       char dirbuffer[PATH_MAX]="";
       /* calculate all our path on a central place */
    /* where to keep our config */
       
#define COMPUTE_DIRECTORY(SUBDIR) memcpy(dirbuffer,SUBDIR, sizeof dirbuffer);\
       snprintf(SUBDIR,sizeof SUBDIR,  "%s%s%s%s%s%s%s", \
                      (home&!relh)?webcitdir:basedir, \
             ((basedir!=webcitdir)&(home&!relh))?basedir:"/", \
             ((basedir!=webcitdir)&(home&!relh))?"/":"", \
                      relhome, \
             (relhome[0]!='\0')?"/":"",\
                      dirbuffer,\
                      (dirbuffer[0]!='\0')?"/":"");
       basedir=RUNDIR;
       COMPUTE_DIRECTORY(socket_dir);
       basedir=WWWDIR "/static";
       COMPUTE_DIRECTORY(static_dir);
       basedir=WWWDIR "/static/icons";
       COMPUTE_DIRECTORY(static_icon_dir);
       basedir=WWWDIR "/static.local";
       COMPUTE_DIRECTORY(static_local_dir);
       StripSlashes(static_dir, 1);
       StripSlashes(static_icon_dir, 1);
       StripSlashes(static_local_dir, 1);

       snprintf(file_crpt_file_key,
               sizeof file_crpt_file_key, 
               "%s/citadel.key",
               ctdl_key_dir);
       snprintf(file_crpt_file_csr,
               sizeof file_crpt_file_csr, 
               "%s/citadel.csr",
               ctdl_key_dir);
       snprintf(file_crpt_file_cer,
               sizeof file_crpt_file_cer, 
               "%s/citadel.cer",
               ctdl_key_dir);

       /* we should go somewhere we can leave our coredump, if enabled... */
       syslog(9, "Changing directory to %s\n", socket_dir);
       if (chdir(webcitdir) != 0) {
              perror("chdir");
       }
}

Variable Documentation

Definition at line 45 of file test_main.c.

Definition at line 46 of file test_main.c.

Definition at line 24 of file messages.c.

int DisableGzip = 0

Definition at line 31 of file test_main.c.

Definition at line 30 of file subst.c.

int follow_xff = 0

Definition at line 29 of file test_main.c.

int home_specified = 0

Definition at line 30 of file test_main.c.

Definition at line 44 of file test_main.c.

StrBuf* I18nDump

Definition at line 34 of file subst.c.

int is_https = 0

Definition at line 28 of file test_main.c.

Definition at line 31 of file subst.c.

int msock

Definition at line 74 of file sysdep.c.

pthread_key_t MyConKey

Definition at line 27 of file context_loop.c.

StrBuf* Passvoid = NULL

Definition at line 51 of file test_main.c.

Definition at line 47 of file test_main.c.

char* server_cookie = NULL

Definition at line 43 of file test_main.c.

pthread_mutex_t SessionListMutex

Definition at line 23 of file context_loop.c.

char socket_dir[PATH_MAX]

Definition at line 41 of file test_main.c.

char static_icon_dir[PATH_MAX]

Definition at line 89 of file sysdep.c.

StrBuf* Username = NULL

Definition at line 50 of file test_main.c.

int verbosity
char wizard_filename[PATH_MAX]

Definition at line 48 of file test_main.c.