From 9d0b7b6b259fa4ff1464d922aeea61c3d81966f8 Mon Sep 17 00:00:00 2001 From: konn Date: Thu, 17 Jul 2008 12:45:25 +0000 Subject: [PATCH] * Added center tag with CSS for au XHTML converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2989 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_jxhtml.c | 54 --- src/chxj_xhtml_mobile_1_0.c | 159 +++++++++ .../test_chxj_xhtml_mobile_1_0.c | 394 ++++++++++++++++++++- 3 files changed, 545 insertions(+), 62 deletions(-) diff --git a/src/chxj_jxhtml.c b/src/chxj_jxhtml.c index 6dd8d56b..032c3340 100644 --- a/src/chxj_jxhtml.c +++ b/src/chxj_jxhtml.c @@ -2746,61 +2746,7 @@ s_jxhtml_start_hr_tag(void *pdoc, Node *node) W_L("\""); } W_L(" />"); - return jxhtml->out; -#if 0 - jxhtml_t *jxhtml = GET_JXHTML(pdoc); - Doc *doc = jxhtml->doc; - Attr *attr; - W_L(""); -#endif return jxhtml->out; } diff --git a/src/chxj_xhtml_mobile_1_0.c b/src/chxj_xhtml_mobile_1_0.c index 9c4f1c6d..9e6c3f7f 100644 --- a/src/chxj_xhtml_mobile_1_0.c +++ b/src/chxj_xhtml_mobile_1_0.c @@ -2013,6 +2013,164 @@ s_xhtml_1_0_end_center_tag(void *pdoc, Node *UNUSED(node)) static char * s_xhtml_1_0_start_hr_tag(void *pdoc, Node *node) { + Attr *attr; + xhtml_t *xhtml; + Doc *doc; + request_rec *r; + char *attr_align = NULL; + char *attr_size = NULL; + char *attr_width = NULL; + char *attr_noshade = NULL; + char *attr_style = NULL; + char *attr_color = NULL; + + xhtml = GET_XHTML(pdoc); + doc = xhtml->doc; + r = doc->r; + + for (attr = qs_get_attr(doc,node); + attr; + attr = qs_get_next_attr(doc,attr)) { + char *name = qs_get_attr_name (doc,attr); + char *value = qs_get_attr_value(doc,attr); + switch(*name) { + case 'a': + case 'A': + if (strcasecmp(name, "align") == 0) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + if (value && (STRCASEEQ('l','L',"left",value) || STRCASEEQ('r','R',"right",value) || STRCASEEQ('c','C',"center",value))) { + attr_align = value; + } + } + break; + + case 's': + case 'S': + if (strcasecmp(name, "size") == 0) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + if (value && *value) { + attr_size = value; + } + } + else if (strcasecmp(name, "style") == 0) { + if (value && *value) { + attr_style = value; + } + } + break; + + case 'w': + case 'W': + if (strcasecmp(name, "width") == 0) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + if (value && *value) { + attr_width = value; + } + } + break; + + case 'n': + case 'N': + if (strcasecmp(name, "noshade") == 0) { + /*--------------------------------------------------------------------*/ + /* CHTML 1.0 */ + /*--------------------------------------------------------------------*/ + attr_noshade = apr_pstrdup(doc->pool, "noshade"); + } + break; + + case 'c': + case 'C': + if (strcasecmp(name, "color") == 0 && value && *value) { + /*--------------------------------------------------------------------*/ + /* CHTML 4.0 */ + /*--------------------------------------------------------------------*/ + attr_color = value; + } + break; + + default: + break; + } + } + if (IS_CSS_ON(xhtml->entryp)) { + css_prop_list_t *style = s_xhtml_1_0_nopush_and_get_now_style(pdoc, node, attr_style); + if (style) { + css_property_t *border_style_prop = chxj_css_get_property_value(doc, style, "border-style"); + css_property_t *height_prop = chxj_css_get_property_value(doc, style, "height"); + css_property_t *width_prop = chxj_css_get_property_value(doc, style, "width"); + css_property_t *cur; + for (cur = border_style_prop->next; cur != border_style_prop; cur = cur->next) { + if (STRCASEEQ('s','S',"solid",cur->value)) { + attr_noshade = "noshade"; + } + } + for (cur = height_prop->next; cur != height_prop; cur = cur->next) { + char *tmp = apr_pstrdup(doc->pool, cur->value); + char *tmpp = strstr(tmp, "px"); + if (tmpp) { + attr_size = apr_pstrdup(doc->pool, tmp); + } + } + for (cur = width_prop->next; cur != width_prop; cur = cur->next) { + char *tmp = apr_pstrdup(doc->pool, cur->value); + char *tmpp = strstr(tmp, "px"); + if (tmpp) { + attr_width = apr_pstrdup(doc->pool, tmp); + } + else { + tmpp = strstr(tmp, "%"); + if (tmpp) { + attr_width = apr_pstrdup(doc->pool, tmp); + } + } + } + } + } + W_L(""); + + return xhtml->out; +#if 0 xhtml_t *xhtml = GET_XHTML(pdoc); Doc *doc = xhtml->doc; Attr *attr; @@ -2070,6 +2228,7 @@ s_xhtml_1_0_start_hr_tag(void *pdoc, Node *node) } } W_L(" />"); +#endif return xhtml->out; } diff --git a/test/chxj_xhtml_mobile_1_0/test_chxj_xhtml_mobile_1_0.c b/test/chxj_xhtml_mobile_1_0/test_chxj_xhtml_mobile_1_0.c index 563ab377..aa90a3a0 100644 --- a/test/chxj_xhtml_mobile_1_0/test_chxj_xhtml_mobile_1_0.c +++ b/test/chxj_xhtml_mobile_1_0/test_chxj_xhtml_mobile_1_0.c @@ -680,6 +680,15 @@ void test_xhtml_center_tag_with_css_013(); void test_xhtml_center_tag_with_css_014(); void test_xhtml_center_tag_with_css_015(); void test_xhtml_center_tag_with_css_016(); + +void test_xhtml_hr_tag_with_css_001(); +void test_xhtml_hr_tag_with_css_002(); +void test_xhtml_hr_tag_with_css_003(); +void test_xhtml_hr_tag_with_css_004(); +void test_xhtml_hr_tag_with_css_005(); +void test_xhtml_hr_tag_with_css_006(); +void test_xhtml_hr_tag_with_css_007(); +void test_xhtml_hr_tag_with_css_008(); /* pend */ int @@ -1396,6 +1405,15 @@ main() CU_add_test(xhtml_suite, "test center with css 014", test_xhtml_center_tag_with_css_014); CU_add_test(xhtml_suite, "test center with css 015", test_xhtml_center_tag_with_css_015); CU_add_test(xhtml_suite, "test center with css 016", test_xhtml_center_tag_with_css_016); + + CU_add_test(xhtml_suite, "test hr with css 001", test_xhtml_hr_tag_with_css_001); + CU_add_test(xhtml_suite, "test hr with css 002", test_xhtml_hr_tag_with_css_002); + CU_add_test(xhtml_suite, "test hr with css 003", test_xhtml_hr_tag_with_css_003); + CU_add_test(xhtml_suite, "test hr with css 004", test_xhtml_hr_tag_with_css_004); + CU_add_test(xhtml_suite, "test hr with css 005", test_xhtml_hr_tag_with_css_005); + CU_add_test(xhtml_suite, "test hr with css 006", test_xhtml_hr_tag_with_css_006); + CU_add_test(xhtml_suite, "test hr with css 007", test_xhtml_hr_tag_with_css_007); + CU_add_test(xhtml_suite, "test hr with css 008", test_xhtml_hr_tag_with_css_008); /* aend */ CU_basic_run_tests(); @@ -5819,7 +5837,7 @@ void test_xhtml_hr_tag_010() void test_xhtml_hr_tag_011() { #define TEST_STRING "
" -#define RESULT_STRING "
" +#define RESULT_STRING "
" char *ret; char *tmp; device_table spec; @@ -5848,7 +5866,7 @@ void test_xhtml_hr_tag_011() void test_xhtml_hr_tag_012() { #define TEST_STRING "
" -#define RESULT_STRING "
" +#define RESULT_STRING "
" char *ret; char *tmp; device_table spec; @@ -5935,7 +5953,7 @@ void test_xhtml_hr_tag_014() void test_xhtml_hr_tag_015() { #define TEST_STRING "
" -#define RESULT_STRING "
" +#define RESULT_STRING "
" char *ret; char *tmp; device_table spec; @@ -5964,7 +5982,7 @@ void test_xhtml_hr_tag_015() void test_xhtml_hr_tag_016() { #define TEST_STRING "
" -#define RESULT_STRING "
" +#define RESULT_STRING "
" char *ret; char *tmp; device_table spec; @@ -5993,7 +6011,7 @@ void test_xhtml_hr_tag_016() void test_xhtml_hr_tag_017() { #define TEST_STRING "
" -#define RESULT_STRING "
" +#define RESULT_STRING "
" char *ret; char *tmp; device_table spec; @@ -6022,7 +6040,7 @@ void test_xhtml_hr_tag_017() void test_xhtml_hr_tag_018() { #define TEST_STRING "
" -#define RESULT_STRING "
" +#define RESULT_STRING "
" char *ret; char *tmp; device_table spec; @@ -6051,7 +6069,7 @@ void test_xhtml_hr_tag_018() void test_xhtml_hr_tag_018_1() { #define TEST_STRING "
" -#define RESULT_STRING "
" +#define RESULT_STRING "
" char *ret; char *tmp; device_table spec; @@ -6080,7 +6098,7 @@ void test_xhtml_hr_tag_018_1() void test_xhtml_hr_tag_018_2() { #define TEST_STRING "
" -#define RESULT_STRING "
" +#define RESULT_STRING "
" char *ret; char *tmp; device_table spec; @@ -20331,6 +20349,366 @@ void test_xhtml_center_tag_with_css_016() #undef TEST_STRING #undef RESULT_STRING } + + + +/*===========================================================================*/ +/* hr tag with CSS */ +/*===========================================================================*/ +char *test_chxj_serf_get100(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:visited { display:none }\n" + "hr { border-style:solid }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_xhtml_hr_tag_with_css_001() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "" \ + "" \ + "" \ + "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get100; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_xhtml_mobile_1_0(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + fprintf(stderr, "actual:[%s]\n", ret); + fprintf(stderr, "expect:[%s]\n", RESULT_STRING); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_xhtml_hr_tag_with_css_002() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "" \ + "" \ + "" \ + "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get100; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_xhtml_mobile_1_0(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + fprintf(stderr, "actual:[%s]\n", ret); + fprintf(stderr, "expect:[%s]\n", RESULT_STRING); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} + + +char *test_chxj_serf_get101(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:visited { display:none }\n" + "hr { height:10px }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_xhtml_hr_tag_with_css_003() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "" \ + "" \ + "" \ + "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get101; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_xhtml_mobile_1_0(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + fprintf(stderr, "actual:[%s]\n", ret); + fprintf(stderr, "expect:[%s]\n", RESULT_STRING); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_xhtml_hr_tag_with_css_004() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "" \ + "" \ + "" \ + "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get101; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_xhtml_mobile_1_0(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + fprintf(stderr, "actual:[%s]\n", ret); + fprintf(stderr, "expect:[%s]\n", RESULT_STRING); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} + +char *test_chxj_serf_get102(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:visited { display:none }\n" + "hr { width:10px }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_xhtml_hr_tag_with_css_005() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "" \ + "" \ + "" \ + "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get102; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_xhtml_mobile_1_0(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + fprintf(stderr, "actual:[%s]\n", ret); + fprintf(stderr, "expect:[%s]\n", RESULT_STRING); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_xhtml_hr_tag_with_css_006() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "" \ + "" \ + "" \ + "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get102; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_xhtml_mobile_1_0(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} + +char *test_chxj_serf_get103(request_rec *r, apr_pool_t *ppool, const char *uri_path, int ss, apr_size_t *len) +{ + static char *css = "a:focus { display: none }\n" + "a:link { display: none }\n" + "a { display: none }\n" + "hr { display: none }\n" + "a:visited { display:none }\n" + "hr { width:80% }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_xhtml_hr_tag_with_css_007() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "" \ + "" \ + "" \ + "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get103; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_xhtml_mobile_1_0(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + fprintf(stderr, "actual:[%s]\n", ret); + fprintf(stderr, "expect:[%s]\n", RESULT_STRING); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 1); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} +void test_xhtml_hr_tag_with_css_008() +{ +#define TEST_STRING "" \ + "
あいう" +#define RESULT_STRING "" \ + "" \ + "" \ + "
あいう" + char *ret; + char *tmp; + device_table spec; + chxjconvrule_entry entry; + cookie_t cookie; + apr_size_t destlen; + APR_INIT; + chxj_serf_get = test_chxj_serf_get103; + call_check = 0; + + COOKIE_INIT(cookie); + + SPEC_INIT(spec); + destlen = sizeof(TEST_STRING)-1; + entry.action |= CONVRULE_CSS_ON_BIT; + + tmp = chxj_encoding(&r, TEST_STRING, &destlen); + ret = chxj_convert_xhtml_mobile_1_0(&r, &spec, tmp, destlen, &destlen, &entry, &cookie); + ret = chxj_rencoding(&r, ret, &destlen); + fprintf(stderr, "actual:[%s]\n", ret); + fprintf(stderr, "expect:[%s]\n", RESULT_STRING); + CU_ASSERT(ret != NULL); + CU_ASSERT(strcmp(RESULT_STRING, ret) == 0); + CU_ASSERT(destlen == sizeof(RESULT_STRING)-1); + CU_ASSERT(call_check == 0); + + APR_TERM; +#undef TEST_STRING +#undef RESULT_STRING +} /* * vim:ts=2 et */ -- 2.11.0