From 7e53fc108db68bb9bc946b50bb828f57aad5e85d Mon Sep 17 00:00:00 2001 From: konn Date: Wed, 16 Jul 2008 13:56:15 +0000 Subject: [PATCH] * Added input tag with CSS for CHTML4.0 converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2965 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_chtml40.c | 161 ++++++++++------ test/chxj_chtml40/test_chxj_chtml40.c | 348 ++++++++++++++++++++++++++++++++++ 2 files changed, 452 insertions(+), 57 deletions(-) diff --git a/src/chxj_chtml40.c b/src/chxj_chtml40.c index 97d37a65..c5d69c80 100644 --- a/src/chxj_chtml40.c +++ b/src/chxj_chtml40.c @@ -1610,96 +1610,143 @@ s_chtml40_start_input_tag(void *pdoc, Node *node) chtml40_t *chtml40; Doc *doc; request_rec *r; - char *max_length = NULL; - char *type = NULL; - char *name = NULL; - char *value = NULL; - char *istyle = NULL; - char *size = NULL; - char *checked = NULL; - char *accesskey = NULL; - - chtml40 = GET_CHTML40(pdoc); - doc = chtml40->doc; - r = doc->r; - W_L("doc; + r = doc->r; + /*--------------------------------------------------------------------------*/ /* Get Attributes */ /*--------------------------------------------------------------------------*/ - type = qs_get_type_attr(doc, node, doc->buf.pool); - name = qs_get_name_attr(doc, node, doc->buf.pool); - value = qs_get_value_attr(doc,node, doc->buf.pool); - istyle = qs_get_istyle_attr(doc,node,doc->buf.pool); - max_length = qs_get_maxlength_attr(doc,node,doc->buf.pool); - checked = qs_get_checked_attr(doc,node,doc->buf.pool); - accesskey = qs_get_accesskey_attr(doc, node, doc->buf.pool); - size = qs_get_size_attr(doc, node, doc->buf.pool); - - if (type) { - type = qs_trim_string(doc->buf.pool, type); - if (type && (STRCASEEQ('t','T',"text", type) || - STRCASEEQ('p','P',"password",type) || - STRCASEEQ('c','C',"checkbox",type) || - STRCASEEQ('r','R',"radio", type) || - STRCASEEQ('h','H',"hidden", type) || - STRCASEEQ('s','S',"submit", type) || - STRCASEEQ('r','R',"reset", type))) { - W_L(" type=\""); - W_V(type); - W_L("\""); + 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); + if (STRCASEEQ('t','T',"type",name) && value && *value) { + char *tmp_type = qs_trim_string(doc->buf.pool, value); + if (tmp_type && (STRCASEEQ('t','T',"text", tmp_type) || + STRCASEEQ('p','P',"password",tmp_type) || + STRCASEEQ('c','C',"checkbox",tmp_type) || + STRCASEEQ('r','R',"radio", tmp_type) || + STRCASEEQ('h','H',"hidden", tmp_type) || + STRCASEEQ('s','S',"submit", tmp_type) || + STRCASEEQ('r','R',"reset", tmp_type))) { + attr_type = tmp_type; + } + } + else if (STRCASEEQ('n','N',"name",name) && value && *value) { + attr_name = value; + } + else if (STRCASEEQ('v','V',"value",name) && value && *value) { + attr_value = value; + } + else if (STRCASEEQ('i','I',"istyle",name) && value && *value) { + attr_istyle = value; + } + else if (STRCASEEQ('m','M',"maxlength",name) && value && *value) { + attr_max_length = value; + } + else if (STRCASEEQ('c','C',"checked", name)) { + attr_checked = value; + } + else if (STRCASEEQ('a','A',"accesskey", name) && value && *value) { + attr_accesskey = value; + } + else if (STRCASEEQ('s','S',"size", name) && value && *value) { + attr_size = value; + } + else if (STRCASEEQ('s','S',"style", name) && value && *value) { + attr_style = value; } } - if (size && *size) { + + if (IS_CSS_ON(chtml40->entryp)) { + css_prop_list_t *style = s_chtml40_nopush_and_get_now_style(pdoc, node, attr_style); + if (style) { + css_property_t *wap_input_format = chxj_css_get_property_value(doc, style, "-wap-input-format"); + css_property_t *cur; + for (cur = wap_input_format->next; cur != wap_input_format; cur = cur->next) { + if (strcasestr(cur->value, "")) { + attr_istyle = "4"; + } + else if (strcasestr(cur->value, "")) { + attr_istyle = "3"; + } + else if (strcasestr(cur->value, "")) { + attr_istyle = "2"; + } + else if (strcasestr(cur->value, "")) { + attr_istyle = "1"; + } + } + } + } + + W_L("pool, value)); + W_V(chxj_add_slash_to_doublequote(doc->pool, attr_value)); W_L("\""); } - if (accesskey && *accesskey) { + if (attr_accesskey) { W_L(" accesskey=\""); - W_V(accesskey); + W_V(attr_accesskey); W_L("\""); } - if (istyle) { - /*------------------------------------------------------------------------*/ - /* CHTML 2.0 */ - /*------------------------------------------------------------------------*/ - if (*istyle == '1' || *istyle == '2' || *istyle == '3' || *istyle == '4') { + if (attr_istyle) { + if (*attr_istyle == '1' || *attr_istyle == '2' || *attr_istyle == '3' || *attr_istyle == '4') { W_L(" istyle=\""); - W_V(istyle); + W_V(attr_istyle); W_L("\""); } } - /*--------------------------------------------------------------------------*/ /* The figure is default for the password. */ /*--------------------------------------------------------------------------*/ - if (max_length && *max_length) { - if (chxj_chk_numeric(max_length) != 0) { - max_length = apr_psprintf(r->pool, "0"); + if (attr_max_length) { + if (chxj_chk_numeric(attr_max_length) != 0) { + attr_max_length = apr_psprintf(doc->buf.pool, "0"); } - if (istyle != NULL && *istyle == '1') { - char *vv = apr_psprintf(doc->buf.pool, " maxlength=\"%d\"", chxj_atoi(max_length) * 2); + if (attr_istyle && *attr_istyle == '1') { + char *vv = apr_psprintf(doc->buf.pool, " maxlength=\"%d\"", chxj_atoi(attr_max_length) * 2); W_V(vv); } - else { - char *vv = apr_psprintf(doc->buf.pool, " maxlength=\"%d\"", chxj_atoi(max_length)); + else { + char *vv = apr_psprintf(doc->buf.pool, " maxlength=\"%d\"", chxj_atoi(attr_max_length)); W_V(vv); } } - if (checked) { + if (attr_checked) { W_L(" checked"); } W_L(">"); + return chtml40->out; } diff --git a/test/chxj_chtml40/test_chxj_chtml40.c b/test/chxj_chtml40/test_chxj_chtml40.c index f3d7fcf5..409a039c 100644 --- a/test/chxj_chtml40/test_chxj_chtml40.c +++ b/test/chxj_chtml40/test_chxj_chtml40.c @@ -615,6 +615,15 @@ void test_chtml40_form_tag_with_css_005(); void test_chtml40_form_tag_with_css_006(); void test_chtml40_form_tag_with_css_007(); void test_chtml40_form_tag_with_css_008(); + +void test_chtml40_input_tag_with_css_001(); +void test_chtml40_input_tag_with_css_002(); +void test_chtml40_input_tag_with_css_003(); +void test_chtml40_input_tag_with_css_004(); +void test_chtml40_input_tag_with_css_005(); +void test_chtml40_input_tag_with_css_006(); +void test_chtml40_input_tag_with_css_007(); +void test_chtml40_input_tag_with_css_008(); /* pend */ int @@ -1192,6 +1201,15 @@ main() CU_add_test(chtml40_suite, "test form with css 006", test_chtml40_form_tag_with_css_006); CU_add_test(chtml40_suite, "test form with css 007", test_chtml40_form_tag_with_css_007); CU_add_test(chtml40_suite, "test form with css 008", test_chtml40_form_tag_with_css_008); + + CU_add_test(chtml40_suite, "test input with css 001", test_chtml40_input_tag_with_css_001); + CU_add_test(chtml40_suite, "test input with css 002", test_chtml40_input_tag_with_css_002); + CU_add_test(chtml40_suite, "test input with css 003", test_chtml40_input_tag_with_css_003); + CU_add_test(chtml40_suite, "test input with css 004", test_chtml40_input_tag_with_css_004); + CU_add_test(chtml40_suite, "test input with css 005", test_chtml40_input_tag_with_css_005); + CU_add_test(chtml40_suite, "test input with css 006", test_chtml40_input_tag_with_css_006); + CU_add_test(chtml40_suite, "test input with css 007", test_chtml40_input_tag_with_css_007); + CU_add_test(chtml40_suite, "test input with css 008", test_chtml40_input_tag_with_css_008); /* aend */ CU_basic_run_tests(); @@ -17320,6 +17338,336 @@ void test_chtml40_form_tag_with_css_008() #undef TEST_STRING #undef RESULT_STRING } + + + +/*===========================================================================*/ +/* input tag with CSS */ +/*===========================================================================*/ +char *test_chxj_serf_get080(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" + "input { -wap-input-format: "*<ja:h>" }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml40_input_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_get080; + 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_chtml40(&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_chtml40_input_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_get080; + 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_chtml40(&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_get081(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" + "input { -wap-input-format: "*<ja:hk>" }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml40_input_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_get081; + 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_chtml40(&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_chtml40_input_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_get081; + 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_chtml40(&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_get082(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" + "input { -wap-input-format: "*<ja:en>" }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml40_input_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_get082; + 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_chtml40(&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_chtml40_input_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_get082; + 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_chtml40(&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_get083(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" + "input { -wap-input-format: "*<ja:n>"; }\n"; + *len = strlen(css); + call_check = 1; + return css; +} +void test_chtml40_input_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_get083; + 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_chtml40(&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_chtml40_input_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_get083; + 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_chtml40(&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