From 0b3132b3915f7c6f279b06d6d852a7a5a7e2c1eb Mon Sep 17 00:00:00 2001 From: konn Date: Wed, 16 Jul 2008 13:56:28 +0000 Subject: [PATCH] * Added input tag with CSS for au XHTML converter. git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/sandbox@2969 1a406e8e-add9-4483-a2c8-d8cac5b7c224 --- src/chxj_xhtml_mobile_1_0.c | 173 +++++++++- .../test_chxj_xhtml_mobile_1_0.c | 373 +++++++++++++++++++++ 2 files changed, 538 insertions(+), 8 deletions(-) diff --git a/src/chxj_xhtml_mobile_1_0.c b/src/chxj_xhtml_mobile_1_0.c index a2068e3a..a025c85f 100644 --- a/src/chxj_xhtml_mobile_1_0.c +++ b/src/chxj_xhtml_mobile_1_0.c @@ -1623,15 +1623,171 @@ s_xhtml_1_0_start_input_tag(void *pdoc, Node *node) xhtml_t *xhtml = GET_XHTML(pdoc); Doc *doc = xhtml->doc; request_rec *r = doc->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; + Attr *attr; + char *attr_max_length = NULL; + char *attr_type = NULL; + char *attr_name = NULL; + char *attr_value = NULL; + char *attr_istyle = NULL; + char *attr_size = NULL; + char *attr_checked = NULL; + char *attr_accesskey = NULL; + char *attr_style = NULL; + + /*--------------------------------------------------------------------------*/ + /* Get Attributes */ + /*--------------------------------------------------------------------------*/ + 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 (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 *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("buf.pool, attr_type); + if (attr_type && (STRCASEEQ('t','T',"text", attr_type) || + STRCASEEQ('p','P',"password",attr_type) || + STRCASEEQ('c','C',"checkbox",attr_type) || + STRCASEEQ('r','R',"radio", attr_type) || + STRCASEEQ('h','H',"hidden", attr_type) || + STRCASEEQ('s','S',"submit", attr_type) || + STRCASEEQ('r','R',"reset", attr_type))) { + W_L(" type=\""); + W_V(attr_type); + W_L("\""); + } + } + if (attr_size && *attr_size) { + W_L(" size=\""); + W_V(attr_size); + W_L("\""); + } + if (attr_name && *attr_name) { + W_L(" name=\""); + W_V(attr_name); + W_L("\""); + } + if (attr_value && *attr_value) { + W_L(" value=\""); + W_V(chxj_add_slash_to_doublequote(doc->pool, attr_value)); + W_L("\""); + } + if (attr_accesskey && *attr_accesskey) { + W_L(" accesskey=\""); + W_V(attr_accesskey); + W_L("\""); + } + if (attr_istyle && *attr_istyle && (*attr_istyle == '1' || *attr_istyle == '2' || *attr_istyle == '3' || *attr_istyle == '4')) { + char *fmt = qs_conv_istyle_to_format(r,attr_istyle); + if (attr_max_length && *attr_max_length) { + int ii; + for (ii=0; (unsigned int)ii '9') { + attr_max_length = apr_psprintf(r->pool, "0"); + break; + } + } + if (strcmp(attr_max_length, "0")) { + char *vv = apr_psprintf(r->pool, " FORMAT=\"%d%s\"", atoi(attr_max_length), fmt); + W_V(vv); + } + } + else { + W_L(" FORMAT=\""); + W_L("*"); + W_V(fmt); + W_L("\""); + } + } + else { + if (attr_max_length && *attr_max_length) { + if (chxj_chk_numeric(attr_max_length) != 0) { + attr_max_length = apr_psprintf(r->pool, "0"); + } + if (strcmp(attr_max_length, "0")) { + char *vv = apr_psprintf(r->pool, " FORMAT=\"%dm\"", atoi(attr_max_length)); + W_V(vv); + } + } + } + /*--------------------------------------------------------------------------*/ + /* The figure is default for the password. */ + /*--------------------------------------------------------------------------*/ + if (attr_type && (attr_istyle == NULL || *attr_istyle == 0) && STRCASEEQ('p','P',"password", attr_type) && ! xhtml->entryp->pc_flag) { + if (attr_max_length) { + W_L(" FORMAT=\""); + W_V(attr_max_length); + W_L("N\""); + } + else { + W_L(" FORMAT=\"*N\""); + } + } + if (attr_checked) { + W_L(" checked=\"checked\""); + } + W_L(" />"); +#if 0 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 45e97910..e2bade2f 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 @@ -654,6 +654,15 @@ void test_xhtml_form_tag_with_css_005(); void test_xhtml_form_tag_with_css_006(); void test_xhtml_form_tag_with_css_007(); void test_xhtml_form_tag_with_css_008(); + +void test_xhtml_input_tag_with_css_001(); +void test_xhtml_input_tag_with_css_002(); +void test_xhtml_input_tag_with_css_003(); +void test_xhtml_input_tag_with_css_004(); +void test_xhtml_input_tag_with_css_005(); +void test_xhtml_input_tag_with_css_006(); +void test_xhtml_input_tag_with_css_007(); +void test_xhtml_input_tag_with_css_008(); /* pend */ int @@ -1344,6 +1353,15 @@ main() CU_add_test(xhtml_suite, "test form with css 006", test_xhtml_form_tag_with_css_006); CU_add_test(xhtml_suite, "test form with css 007", test_xhtml_form_tag_with_css_007); CU_add_test(xhtml_suite, "test form with css 008", test_xhtml_form_tag_with_css_008); + + CU_add_test(xhtml_suite, "test input with css 001", test_xhtml_input_tag_with_css_001); + CU_add_test(xhtml_suite, "test input with css 002", test_xhtml_input_tag_with_css_002); + CU_add_test(xhtml_suite, "test input with css 003", test_xhtml_input_tag_with_css_003); + CU_add_test(xhtml_suite, "test input with css 004", test_xhtml_input_tag_with_css_004); + CU_add_test(xhtml_suite, "test input with css 005", test_xhtml_input_tag_with_css_005); + CU_add_test(xhtml_suite, "test input with css 006", test_xhtml_input_tag_with_css_006); + CU_add_test(xhtml_suite, "test input with css 007", test_xhtml_input_tag_with_css_007); + CU_add_test(xhtml_suite, "test input with css 008", test_xhtml_input_tag_with_css_008); /* aend */ CU_basic_run_tests(); @@ -19216,6 +19234,361 @@ void test_xhtml_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_xhtml_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_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_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_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_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_xhtml_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_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_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_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_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_xhtml_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_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_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_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_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_xhtml_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_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_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_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