Back to index

webcit  8.12-dfsg
test_tools.c
Go to the documentation of this file.
00001 #include "webcit_test.h"
00002 #include <CUnit/CUnit.h>
00003 #include <CUnit/Basic.h>
00004 #include <CUnit/TestDB.h>
00005 
00006 
00007 #include "webcit.h"
00008 #include "webserver.h"
00009 #include "modules_init.h"
00010 #include <stdio.h>
00011 
00012 
00013 wcsession *TestSessionList = NULL;
00014 
00015 
00016 ParsedHttpHdrs Hdr;
00017 wcsession *TheSession;
00018 
00019 extern StrBuf *Username;
00020 extern StrBuf *Passvoid;
00021 
00022 
00023 extern int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf);
00024 extern wcsession *CreateSession(int Lockable, wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex);
00025 extern void groupdav_main(void);
00026 
00027 
00028 
00029 void SetUpContext(void)
00030 {
00031         memset(&Hdr, 0, sizeof(ParsedHttpHdrs));
00032         Hdr.HR.eReqType = eGET;
00033         http_new_modules(&Hdr); 
00034 
00035 
00036        Hdr.http_sock = 1; /* STDOUT */
00037 /* Context loop */
00038        Hdr.HR.dav_depth = 32767; /* TODO: find a general way to have non-0 defaults */
00039        TheSession = CreateSession(1, &TestSessionList, &Hdr, NULL);
00040        TheSession->lastreq = time(NULL);                /* log */
00041        TheSession->Hdr = &Hdr;
00042        Hdr.HTTPHeaders = NewHash(1, NULL);
00043        session_attach_modules(TheSession);
00044 }
00045 
00046 int SetUpConnection(void)
00047 {
00048        StrBuf *Response;
00049        if (!GetConnected ())
00050        {
00051               Response = NewStrBuf();
00052               become_logged_in(Username, Passvoid, Response);
00053               return 1;
00054               
00055        }
00056        else {
00057               CU_FAIL("Establishing session failed!");
00058               return 0;
00059        }
00060 }
00061 
00062 void SetHttpURL(ParsedHttpHdrs *Hdr, const char *Title, long tlen, StrBuf *Buf)
00063 {
00064        StrBuf *Line = NewStrBufPlain (Title, tlen);
00065        FreeStrBuf(&Line);
00066 }
00067 
00068 /* from context_loop.c: */
00069 extern void DestroyHttpHeaderHandler(void *V);
00070 extern int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf);
00071 void SetUpRequest(const char *UrlPath)
00072 {
00073        OneHttpHeader *pHdr;
00074        wcsession *WCC = WC;
00075        StrBuf *Buf;
00076        StrBuf *Line, *HeaderName;
00077 
00078        HeaderName = NewStrBuf();
00079        Buf = NewStrBuf();
00080        Line = NewStrBuf();
00081        StrBufPrintf(Line, "GET %s HTTP/1.0\r\n", UrlPath);
00082 
00083        WCC->Hdr->HTTPHeaders = NewHash(1, NULL);
00084        pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
00085        memset(pHdr, 0, sizeof(OneHttpHeader));
00086        pHdr->Val = Line;
00087        Put(Hdr.HTTPHeaders, HKEY("GET /"), pHdr, DestroyHttpHeaderHandler);
00088        syslog(9, "%s\n", ChrPtr(Line));
00089 
00090        if (ReadHttpSubject(&Hdr, Line, HeaderName))
00091               CU_FAIL("Failed to parse Request line / me is bogus!");
00092 
00093        FreeStrBuf(&Buf);
00094 }
00095 
00096 
00097 
00098 void TearDownRequest(void)
00099 {
00100 /* End Context loop */
00101        http_detach_modules(&Hdr);
00102 }
00103 
00104 void TearDownContext(void)
00105 {
00106        http_destroy_modules(&Hdr);
00107 /* End Session Loop */
00108        session_detach_modules(TheSession);
00109        session_destroy_modules(&TheSession);
00110 
00111 /* End Session loop */
00112 /* now shut it down clean. */
00113 //     shutdown_sessions();
00114        do_housekeeping();
00115 }
00116 
00117 void test_worker_entry(StrBuf *UrlPath)
00118 {
00119 
00120 
00121 }
00122 
00123 
00124 void SetGroupdavHeaders(int DavDepth)
00125 {
00126        Hdr.HR.dav_depth = DavDepth;
00127 }
00128 
00129 void FlushHeaders(void)
00130 {
00131 
00132 }
00133 
00134 void test_groupdav_directorycommands(void)
00135 {
00136        SetUpContext();
00137        if (SetUpConnection())
00138        {
00139               SetUpRequest("/");
00140               SetGroupdavHeaders(0);
00141               groupdav_main();
00142               FlushHeaders();
00143               TearDownRequest();
00144 
00145               SetUpRequest("/");
00146               SetGroupdavHeaders(1);
00147               groupdav_main();
00148               FlushHeaders();
00149               TearDownRequest();
00150 
00151 
00152               SetUpRequest("/groupdav");
00153               SetGroupdavHeaders(0);
00154               groupdav_main();
00155               FlushHeaders();
00156               TearDownRequest();
00157 
00158               SetUpRequest("/groupdav");
00159               SetGroupdavHeaders(1);
00160               groupdav_main();
00161               FlushHeaders();
00162               TearDownRequest();
00163 
00164               SetUpRequest("/groupdav/");
00165               SetGroupdavHeaders(0);
00166               groupdav_main();
00167               FlushHeaders();
00168               TearDownRequest();
00169 
00170               SetUpRequest("/groupdav/");
00171               SetGroupdavHeaders(1);
00172               groupdav_main();
00173               FlushHeaders();
00174               TearDownRequest();
00175 
00176 
00177               SetUpRequest("/groupdav/My%20Folders");
00178               SetGroupdavHeaders(0);
00179               groupdav_main();
00180               FlushHeaders();
00181               TearDownRequest();
00182 
00183               SetUpRequest("/groupdav/My%20Folders");
00184               SetGroupdavHeaders(1);
00185               groupdav_main();
00186               FlushHeaders();
00187               TearDownRequest();
00188 
00189               SetUpRequest("/groupdav/My%20Folders/");
00190               SetGroupdavHeaders(0);
00191               groupdav_main();
00192               FlushHeaders();
00193               TearDownRequest();
00194 
00195               SetUpRequest("/groupdav/My%20Folders/");
00196               SetGroupdavHeaders(1);
00197               groupdav_main();
00198               FlushHeaders();
00199               TearDownRequest();
00200 
00201               SetUpRequest("/groupdav/My%20Folders/Calendar");
00202               SetGroupdavHeaders(0);
00203               groupdav_main();
00204               FlushHeaders();
00205               TearDownRequest();
00206 
00207               SetUpRequest("/groupdav/My%20Folders/Calendar");
00208               SetGroupdavHeaders(1);
00209               groupdav_main();
00210               FlushHeaders();
00211               TearDownRequest();
00212 
00213               SetUpRequest("/groupdav/My%20Folders/Calendar/");
00214               SetGroupdavHeaders(0);
00215               groupdav_main();
00216               FlushHeaders();
00217               TearDownRequest();
00218 
00219               SetUpRequest("/groupdav/My%20Folders/Calendar/");
00220               SetGroupdavHeaders(1);
00221               groupdav_main();
00222               FlushHeaders();
00223               TearDownRequest();
00224 
00225 
00226               SetUpRequest("/");
00227               SetGroupdavHeaders(0);
00228               groupdav_main();
00229               FlushHeaders();
00230               TearDownRequest();
00231 
00232               SetUpRequest("/");
00233               SetGroupdavHeaders(1);
00234               groupdav_main();
00235               FlushHeaders();
00236               TearDownRequest();
00237        }
00238 
00239 
00240        TearDownContext();
00241 }
00242 
00243 extern void httplang_to_locale(StrBuf *LocaleString, wcsession *sess);
00244 
00245 static void test_gettext(const char *str, long len)
00246 {
00247        StrBuf *Test = NewStrBufPlain(str, len);
00248 
00249        SetUpContext();
00250        httplang_to_locale(Test, TheSession);
00251        TearDownContext();
00252 
00253        FreeStrBuf(&Test);
00254 }
00255 
00256 void test_gettext_headerevaluation_Opera(void)
00257 {
00258        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"));
00259 }
00260 
00261 void test_gettext_headerevaluation_firefox1(void)
00262 {
00263        test_gettext(HKEY("de-de,en-us;q=0.7,en;q=0.3"));
00264 }
00265 
00266 void test_gettext_headerevaluation_firefox2(void)
00267 {
00268        test_gettext(HKEY("de,en-ph;q=0.8,en-us;q=0.5,de-at;q=0.3"));
00269 }
00270 
00271 void test_gettext_headerevaluation_firefox3(void)
00272 {
00273        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"));
00274 }
00275 
00276 void test_gettext_headerevaluation_ie7(void)
00277 {
00278 // ie7????
00279 // 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)
00280 
00281        test_gettext(HKEY("en-us,x-ns1MvoLpRxbNhu,x-ns2F0f0NnyPOPN"));
00282 }
00283 
00284 static void AddTests(void)
00285 {
00286        CU_pSuite pGroup = NULL;
00287        CU_pTest pTest = NULL;
00288 /*
00289        pGroup = CU_add_suite("TestLocaleEvaluator", NULL, NULL);
00290        pTest = CU_add_test(pGroup, "Test ie7", test_gettext_headerevaluation_ie7);
00291        pTest = CU_add_test(pGroup, "Test Opera", test_gettext_headerevaluation_Opera);
00292        pTest = CU_add_test(pGroup, "Test firefox1", test_gettext_headerevaluation_firefox1);
00293        pTest = CU_add_test(pGroup, "Test firefox2", test_gettext_headerevaluation_firefox2);
00294        pTest = CU_add_test(pGroup, "Test firefox3", test_gettext_headerevaluation_firefox3);
00295 */
00296        pGroup = CU_add_suite("TestUrlPatterns", NULL, NULL);
00297        pTest = CU_add_test(pGroup, "Test", test_groupdav_directorycommands);
00298 
00299 
00300 }
00301 
00302 
00303 
00304 
00305 
00306 
00307 
00308 void run_tests(void)
00309 {
00310        setvbuf(stdout, NULL, _IONBF, 0);
00311 
00312        CU_set_output_filename("TestAutomated");
00313        if (CU_initialize_registry()) {
00314               printf("\nInitialize of test Registry failed.");
00315        }
00316 
00317        AddTests();
00318 
00319        printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
00320        CU_cleanup_registry();
00321 
00322 }