src/server/test/rewrite.c

changeset 648
205d41b19a13
parent 646
f64ebb0c5fa9
child 651
ed74879c7041
equal deleted inserted replaced
647:ffbc5076b4bf 648:205d41b19a13
30 30
31 #include "../daemon/rewrite.h" 31 #include "../daemon/rewrite.h"
32 #include <cx/mempool.h> 32 #include <cx/mempool.h>
33 #include <string.h> 33 #include <string.h>
34 34
35 CX_TEST(test_rewrite_rule_create) {
36 CxMempool *mp = cxMempoolCreate(100, CX_MEMPOOL_TYPE_ADVANCED);
37 const CxAllocator *a = mp->allocator;
38
39 CX_TEST_DO {
40 RewriteRule *rule = rewrite_rule_create(a, cx_mutstr(NULL), cx_mutstr("/rewrite"));
41 CX_TEST_ASSERT(rule != NULL);
42 CX_TEST_ASSERT(!rule->has_regex);
43 CX_TEST_ASSERT(rule->url != NULL);
44
45 cxmutstr newuri = string_template_build_string(rule->url, a, NULL, NULL);
46 CX_TEST_ASSERT(!cx_strcmp(newuri, "/rewrite"));
47
48 RewriteRule *rule2 = rewrite_rule_create(a, cx_mutstr("/path/(.*)/files/"), cx_mutstr("/rewrite/$1/"));
49 CX_TEST_ASSERT(rule2 != NULL);
50 CX_TEST_ASSERT(rule2->has_regex);
51 CX_TEST_ASSERT(rule2->url != NULL);
52 }
53
54 cxMempoolFree(mp);
55 }
35 56
36 CX_TEST(test_rewrite_url_no_regex) { 57 CX_TEST(test_rewrite_url_no_regex) {
37 CxMempool *mp = cxMempoolCreate(100, CX_MEMPOOL_TYPE_ADVANCED); 58 CxMempool *mp = cxMempoolCreate(100, CX_MEMPOOL_TYPE_ADVANCED);
38 const CxAllocator *a = mp->allocator; 59 const CxAllocator *a = mp->allocator;
39 60

mercurial