1 #include <CUnit/CUnit.h>
2 #include <CUnit/Basic.h>
3 #include <CUnit/TestDB.h>
8 #include "modules_init.h"
12 wcsession *TestSessionList = NULL;
16 wcsession *TheSession;
18 extern StrBuf *Username;
19 extern StrBuf *Passvoid;
22 extern int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf);
23 extern wcsession *CreateSession(int Lockable, wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t *ListMutex);
27 void SetUpContext(void)
29 memset(&Hdr, 0, sizeof(ParsedHttpHdrs));
30 Hdr.HR.eReqType = eGET;
31 http_new_modules(&Hdr);
34 Hdr.http_sock = 1; /* STDOUT */
36 Hdr.HR.dav_depth = 32767; /* TODO: find a general way to have non-0 defaults */
37 TheSession = CreateSession(1, &TestSessionList, &Hdr, NULL);
38 TheSession->lastreq = time(NULL); /* log */
39 TheSession->Hdr = &Hdr;
40 Hdr.HTTPHeaders = NewHash(1, NULL);
41 session_attach_modules(TheSession);
44 int SetUpConnection(void)
49 Response = NewStrBuf();
50 become_logged_in(Username, Passvoid, Response);
55 CU_FAIL("Establishing session failed!");
60 void SetHttpURL(ParsedHttpHdrs *Hdr, const char *Title, long tlen, StrBuf *Buf)
62 StrBuf *Line = NewStrBufPlain (Title, tlen);
66 /* from context_loop.c: */
67 extern void DestroyHttpHeaderHandler(void *V);
68 extern int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf);
69 void SetUpRequest(const char *UrlPath)
74 StrBuf *Line, *HeaderName;
76 HeaderName = NewStrBuf();
79 StrBufPrintf(Line, "GET %s HTTP/1.0\r\n", UrlPath);
81 WCC->Hdr->HTTPHeaders = NewHash(1, NULL);
82 pHdr = (OneHttpHeader*) malloc(sizeof(OneHttpHeader));
83 memset(pHdr, 0, sizeof(OneHttpHeader));
85 Put(Hdr.HTTPHeaders, HKEY("GET /"), pHdr, DestroyHttpHeaderHandler);
86 lprintf(9, "%s\n", ChrPtr(Line));
88 if (ReadHttpSubject(&Hdr, Line, HeaderName))
89 CU_FAIL("Failed to parse Request line / me is bogus!");
96 void TearDownRequest(void)
98 /* End Context loop */
99 http_detach_modules(&Hdr);
102 void TearDownContext(void)
104 http_destroy_modules(&Hdr);
105 /* End Session Loop */
106 session_detach_modules(TheSession);
107 session_destroy_modules(&TheSession);
109 /* End Session loop */
110 /* now shut it down clean. */
111 // shutdown_sessions();
115 void test_worker_entry(StrBuf *UrlPath)
122 void SetGroupdavHeaders(int DavDepth)
124 Hdr.HR.dav_depth = DavDepth;
127 void FlushHeaders(void)
132 void test_groupdav_directorycommands(void)
135 if (SetUpConnection())
138 SetGroupdavHeaders(0);
144 SetGroupdavHeaders(1);
150 SetUpRequest("/groupdav");
151 SetGroupdavHeaders(0);
156 SetUpRequest("/groupdav");
157 SetGroupdavHeaders(1);
162 SetUpRequest("/groupdav/");
163 SetGroupdavHeaders(0);
168 SetUpRequest("/groupdav/");
169 SetGroupdavHeaders(1);
175 SetUpRequest("/groupdav/My%20Folders");
176 SetGroupdavHeaders(0);
181 SetUpRequest("/groupdav/My%20Folders");
182 SetGroupdavHeaders(1);
187 SetUpRequest("/groupdav/My%20Folders/");
188 SetGroupdavHeaders(0);
193 SetUpRequest("/groupdav/My%20Folders/");
194 SetGroupdavHeaders(1);
199 SetUpRequest("/groupdav/My%20Folders/Calendar");
200 SetGroupdavHeaders(0);
205 SetUpRequest("/groupdav/My%20Folders/Calendar");
206 SetGroupdavHeaders(1);
211 SetUpRequest("/groupdav/My%20Folders/Calendar/");
212 SetGroupdavHeaders(0);
217 SetUpRequest("/groupdav/My%20Folders/Calendar/");
218 SetGroupdavHeaders(1);
225 SetGroupdavHeaders(0);
231 SetGroupdavHeaders(1);
241 extern void httplang_to_locale(StrBuf *LocaleString, wcsession *sess);
243 static void test_gettext(const char *str, long len)
245 StrBuf *Test = NewStrBufPlain(str, len);
248 httplang_to_locale(Test, TheSession);
254 void test_gettext_headerevaluation_Opera(void)
256 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"));
259 void test_gettext_headerevaluation_firefox1(void)
261 test_gettext(HKEY("de-de,en-us;q=0.7,en;q=0.3"));
264 void test_gettext_headerevaluation_firefox2(void)
266 test_gettext(HKEY("de,en-ph;q=0.8,en-us;q=0.5,de-at;q=0.3"));
269 void test_gettext_headerevaluation_firefox3(void)
271 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"));
274 void test_gettext_headerevaluation_ie7(void)
277 // 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)
279 test_gettext(HKEY("en-us,x-ns1MvoLpRxbNhu,x-ns2F0f0NnyPOPN"));
282 static void AddTests(void)
284 CU_pSuite pGroup = NULL;
285 CU_pTest pTest = NULL;
287 pGroup = CU_add_suite("TestLocaleEvaluator", NULL, NULL);
288 pTest = CU_add_test(pGroup, "Test ie7", test_gettext_headerevaluation_ie7);
289 pTest = CU_add_test(pGroup, "Test Opera", test_gettext_headerevaluation_Opera);
290 pTest = CU_add_test(pGroup, "Test firefox1", test_gettext_headerevaluation_firefox1);
291 pTest = CU_add_test(pGroup, "Test firefox2", test_gettext_headerevaluation_firefox2);
292 pTest = CU_add_test(pGroup, "Test firefox3", test_gettext_headerevaluation_firefox3);
294 pGroup = CU_add_suite("TestUrlPatterns", NULL, NULL);
295 pTest = CU_add_test(pGroup, "Test", test_groupdav_directorycommands);
308 setvbuf(stdout, NULL, _IONBF, 0);
310 CU_set_output_filename("TestAutomated");
311 if (CU_initialize_registry()) {
312 printf("\nInitialize of test Registry failed.");
317 printf("\nTests completed with return value %d.\n", CU_basic_run_tests());
318 CU_cleanup_registry();