Back to index

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

Go to the source code of this file.

Functions

int ReadHttpSubject (ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf)
wcsessionCreateSession (int Lockable, wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex)
void groupdav_main (void)
void SetUpContext (void)
int SetUpConnection (void)
void SetHttpURL (ParsedHttpHdrs *Hdr, const char *Title, long tlen, StrBuf *Buf)
void DestroyHttpHeaderHandler (void *V)
void SetUpRequest (const char *UrlPath)
void TearDownRequest (void)
void TearDownContext (void)
void test_worker_entry (StrBuf *UrlPath)
void SetGroupdavHeaders (int DavDepth)
void FlushHeaders (void)
void test_groupdav_directorycommands (void)
void httplang_to_locale (StrBuf *LocaleString, wcsession *sess)
static void test_gettext (const char *str, long len)
void test_gettext_headerevaluation_Opera (void)
void test_gettext_headerevaluation_firefox1 (void)
void test_gettext_headerevaluation_firefox2 (void)
void test_gettext_headerevaluation_firefox3 (void)
void test_gettext_headerevaluation_ie7 (void)
static void AddTests (void)
void run_tests (void)

Variables

wcsessionTestSessionList = NULL
ParsedHttpHdrs Hdr
wcsessionTheSession
StrBuf * Username
StrBuf * Passvoid

Function Documentation

static void AddTests ( void  ) [static]

Definition at line 284 of file test_tools.c.

{
       CU_pSuite pGroup = NULL;
       CU_pTest pTest = NULL;
/*
       pGroup = CU_add_suite("TestLocaleEvaluator", NULL, NULL);
       pTest = CU_add_test(pGroup, "Test ie7", test_gettext_headerevaluation_ie7);
       pTest = CU_add_test(pGroup, "Test Opera", test_gettext_headerevaluation_Opera);
       pTest = CU_add_test(pGroup, "Test firefox1", test_gettext_headerevaluation_firefox1);
       pTest = CU_add_test(pGroup, "Test firefox2", test_gettext_headerevaluation_firefox2);
       pTest = CU_add_test(pGroup, "Test firefox3", test_gettext_headerevaluation_firefox3);
*/
       pGroup = CU_add_suite("TestUrlPatterns", NULL, NULL);
       pTest = CU_add_test(pGroup, "Test", test_groupdav_directorycommands);


}

Here is the call graph for this function:

Here is the caller graph for this function:

wcsession* CreateSession ( int  Lockable,
wcsession **  wclist,
ParsedHttpHdrs Hdr,
pthread_mutex_t *  ListMutex 
)
void DestroyHttpHeaderHandler ( void *  V)

Definition at line 40 of file context_loop.c.

{
       OneHttpHeader *pHdr;
       pHdr = (OneHttpHeader*) V;
       FreeStrBuf(&pHdr->Val);
       free(pHdr);
}

Here is the caller graph for this function:

void FlushHeaders ( void  )

Definition at line 129 of file test_tools.c.

{

}

Here is the caller graph for this function:

void groupdav_main ( void  )

Here is the caller graph for this function:

void httplang_to_locale ( StrBuf *  LocaleString,
wcsession sess 
)

Here is the caller graph for this function:

int ReadHttpSubject ( ParsedHttpHdrs Hdr,
StrBuf *  Line,
StrBuf *  Buf 
)

Definition at line 258 of file context_loop.c.

{
       const char *Args;
       void *vLine, *vHandler;
       const char *Pos = NULL;

       Hdr->HR.ReqLine = Line;
       /* The requesttype... GET, POST... */
       StrBufExtract_token(Buf, Hdr->HR.ReqLine, 0, ' ');
       if (GetHash(HttpReqTypes, SKEY(Buf), &vLine) &&
           (vLine != NULL))
       {
              Hdr->HR.eReqType = *(long*)vLine;
       }
       else {
              Hdr->HR.eReqType = eGET;
              return 1;
       }
       StrBufCutLeft(Hdr->HR.ReqLine, StrLength(Buf) + 1);

       /* the HTTP Version... */
       StrBufExtract_token(Buf, Hdr->HR.ReqLine, 1, ' ');
       StrBufCutRight(Hdr->HR.ReqLine, StrLength(Buf) + 1);
       
       if (StrLength(Buf) == 0) {
              Hdr->HR.eReqType = eGET;
              return 1;
       }

       StrBufAppendBuf(Hdr->this_page, Hdr->HR.ReqLine, 0);

       /* chop Filename / query arguments */
       Args = strchr(ChrPtr(Hdr->HR.ReqLine), '?');
       if (Args == NULL) /* whe're not that picky about params... TODO: this will spoil '&' in filenames.*/
              Args = strchr(ChrPtr(Hdr->HR.ReqLine), '&');
       if (Args != NULL) {
              Args ++; /* skip the ? */
              StrBufPlain(Hdr->PlainArgs, 
                         Args, 
                         StrLength(Hdr->HR.ReqLine) -
                         (Args - ChrPtr(Hdr->HR.ReqLine)));
              StrBufCutAt(Hdr->HR.ReqLine, 0, Args - 1);
       } /* don't parse them yet, maybe we don't even care... */
       
       /* now lookup what we are going to do with this... */
       /* skip first slash */
       StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/');
       do {
              StrBufExtract_NextToken(Buf, Hdr->HR.ReqLine, &Pos, '/');

              GetHash(HandlerHash, SKEY(Buf), &vHandler),
              Hdr->HR.Handler = (WebcitHandler*) vHandler;
              if (Hdr->HR.Handler == NULL)
                     break;
              /*
               * If the request is prefixed by "/webcit" then chop that off.  This
               * allows a front end web server to forward all /webcit requests to us
               * while still using the same web server port for other things.
               */
              if ((Hdr->HR.Handler->Flags & URLNAMESPACE) != 0)
                     continue;
              break;
       } while (1);
       /* remove the handlername from the URL */
       if ((Pos != NULL) && (Pos != StrBufNOTNULL)){
              StrBufCutLeft(Hdr->HR.ReqLine, 
                           Pos - ChrPtr(Hdr->HR.ReqLine));
       }

       if (Hdr->HR.Handler != NULL) {
              if ((Hdr->HR.Handler->Flags & BOGUS) != 0) {
                     return 1;
              }
              Hdr->HR.DontNeedAuth = (
                     ((Hdr->HR.Handler->Flags & ISSTATIC) != 0) ||
                     ((Hdr->HR.Handler->Flags & ANONYMOUS) != 0)
              );
       }
       else {
              /* If this is a "flat" request for the root, display the configured landing page. */
              int return_value;
              StrBuf *NewLine = NewStrBuf();
              Hdr->HR.DontNeedAuth = 1;
              StrBufAppendPrintf(NewLine, "GET /landing?go=%s HTTP/1.0", ChrPtr(Buf));
              syslog(LOG_DEBUG, "Replacing with: %s", ChrPtr(NewLine));
              return_value = ReadHttpSubject(Hdr, NewLine, Buf);
              FreeStrBuf(&NewLine);
              return return_value;
       }

       return 0;
}

Here is the call graph for this function:

Here is the caller 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 SetGroupdavHeaders ( int  DavDepth)

Definition at line 124 of file test_tools.c.

{
       Hdr.HR.dav_depth = DavDepth;
}

Here is the caller graph for this function:

void SetHttpURL ( ParsedHttpHdrs Hdr,
const char *  Title,
long  tlen,
StrBuf *  Buf 
)

Definition at line 62 of file test_tools.c.

{
       StrBuf *Line = NewStrBufPlain (Title, tlen);
       FreeStrBuf(&Line);
}
int SetUpConnection ( void  )

Definition at line 46 of file test_tools.c.

{
       StrBuf *Response;
       if (!GetConnected ())
       {
              Response = NewStrBuf();
              become_logged_in(Username, Passvoid, Response);
              return 1;
              
       }
       else {
              CU_FAIL("Establishing session failed!");
              return 0;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SetUpContext ( void  )

Definition at line 29 of file test_tools.c.

{
        memset(&Hdr, 0, sizeof(ParsedHttpHdrs));
        Hdr.HR.eReqType = eGET;
        http_new_modules(&Hdr); 


       Hdr.http_sock = 1; /* STDOUT */
/* Context loop */
       Hdr.HR.dav_depth = 32767; /* TODO: find a general way to have non-0 defaults */
       TheSession = CreateSession(1, &TestSessionList, &Hdr, NULL);
       TheSession->lastreq = time(NULL);                /* log */
       TheSession->Hdr = &Hdr;
       Hdr.HTTPHeaders = NewHash(1, NULL);
       session_attach_modules(TheSession);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SetUpRequest ( const char *  UrlPath)

Definition at line 71 of file test_tools.c.

{
       OneHttpHeader *pHdr;
       wcsession *WCC = WC;
       StrBuf *Buf;
       StrBuf *Line, *HeaderName;

       HeaderName = NewStrBuf();
       Buf = NewStrBuf();
       Line = NewStrBuf();
       StrBufPrintf(Line, "GET %s HTTP/1.0\r\n", UrlPath);

       WCC->Hdr->HTTPHeaders = NewHash(1, NULL);
       pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
       memset(pHdr, 0, sizeof(OneHttpHeader));
       pHdr->Val = Line;
       Put(Hdr.HTTPHeaders, HKEY("GET /"), pHdr, DestroyHttpHeaderHandler);
       syslog(9, "%s\n", ChrPtr(Line));

       if (ReadHttpSubject(&Hdr, Line, HeaderName))
              CU_FAIL("Failed to parse Request line / me is bogus!");

       FreeStrBuf(&Buf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TearDownContext ( void  )

Definition at line 104 of file test_tools.c.

{
       http_destroy_modules(&Hdr);
/* End Session Loop */
       session_detach_modules(TheSession);
       session_destroy_modules(&TheSession);

/* End Session loop */
/* now shut it down clean. */
//     shutdown_sessions();
       do_housekeeping();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void TearDownRequest ( void  )

Definition at line 98 of file test_tools.c.

{
/* End Context loop */
       http_detach_modules(&Hdr);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void test_gettext ( const char *  str,
long  len 
) [static]

Definition at line 245 of file test_tools.c.

{
       StrBuf *Test = NewStrBufPlain(str, len);

       SetUpContext();
       httplang_to_locale(Test, TheSession);
       TearDownContext();

       FreeStrBuf(&Test);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 261 of file test_tools.c.

{
       test_gettext(HKEY("de-de,en-us;q=0.7,en;q=0.3"));
}

Here is the call graph for this function:

Definition at line 266 of file test_tools.c.

{
       test_gettext(HKEY("de,en-ph;q=0.8,en-us;q=0.5,de-at;q=0.3"));
}

Here is the call graph for this function:

Definition at line 271 of file test_tools.c.

{
       test_gettext(HKEY("de,en-us;q=0.9,it;q=0.9,de-de;q=0.8,en-ph;q=0.7,de-at;q=0.7,zh-cn;q=0.6,cy;q=0.5,ar-om;q=0.5,en-tt;q=0.4,xh;q=0.3,nl-be;q=0.3,cs;q=0.2,sv;q=0.1,tk;q=0.1"));
}

Here is the call graph for this function:

Definition at line 276 of file test_tools.c.

{
// ie7????
// User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; FunWebProducts; FBSMTWB; GTB6.3; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618; Seekmo 10.3.86.0)

       test_gettext(HKEY("en-us,x-ns1MvoLpRxbNhu,x-ns2F0f0NnyPOPN"));
}

Here is the call graph for this function:

Definition at line 256 of file test_tools.c.

{
       test_gettext(HKEY("sq;q=1.0,de;q=0.9,as;q=0.8,ar;q=0.7,bn;q=0.6,zh-cn;q=0.5,kn;q=0.4,ch;q=0.3,fo;q=0.2,gn;q=0.1,ce;q=0.1,ie;q=0.1"));
}

Here is the call graph for this function:

Definition at line 134 of file test_tools.c.

{
       SetUpContext();
       if (SetUpConnection())
       {
              SetUpRequest("/");
              SetGroupdavHeaders(0);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/");
              SetGroupdavHeaders(1);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();


              SetUpRequest("/groupdav");
              SetGroupdavHeaders(0);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/groupdav");
              SetGroupdavHeaders(1);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/groupdav/");
              SetGroupdavHeaders(0);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/groupdav/");
              SetGroupdavHeaders(1);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();


              SetUpRequest("/groupdav/My%20Folders");
              SetGroupdavHeaders(0);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/groupdav/My%20Folders");
              SetGroupdavHeaders(1);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/groupdav/My%20Folders/");
              SetGroupdavHeaders(0);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/groupdav/My%20Folders/");
              SetGroupdavHeaders(1);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/groupdav/My%20Folders/Calendar");
              SetGroupdavHeaders(0);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/groupdav/My%20Folders/Calendar");
              SetGroupdavHeaders(1);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/groupdav/My%20Folders/Calendar/");
              SetGroupdavHeaders(0);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/groupdav/My%20Folders/Calendar/");
              SetGroupdavHeaders(1);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();


              SetUpRequest("/");
              SetGroupdavHeaders(0);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();

              SetUpRequest("/");
              SetGroupdavHeaders(1);
              groupdav_main();
              FlushHeaders();
              TearDownRequest();
       }


       TearDownContext();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void test_worker_entry ( StrBuf *  UrlPath)

Definition at line 117 of file test_tools.c.

{


}

Variable Documentation

Definition at line 16 of file test_tools.c.

StrBuf* Passvoid

Definition at line 51 of file test_main.c.

Definition at line 13 of file test_tools.c.

Definition at line 17 of file test_tools.c.

StrBuf* Username

Definition at line 50 of file test_main.c.