OSDN Git Service

* Added test code of relative size specification for CHTML5.0 converter.
authorkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Tue, 29 Apr 2008 18:58:37 +0000 (18:58 +0000)
committerkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Tue, 29 Apr 2008 18:58:37 +0000 (18:58 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/RELEASE_0_12_0@2573 1a406e8e-add9-4483-a2c8-d8cac5b7c224

include/chxj_chtml50.h
src/chxj_chtml50.c
test/chxj_chtml50/test_chxj_chtml50.c

index bd64f0b..313bbc4 100644 (file)
@@ -33,6 +33,7 @@ struct chtml50_t {
     int                 out_len;
     int                 pre_flag;
     int                 textarea_flag;
+    int                 font_flag;
 
     device_table        *spec;
     mod_chxj_config     *conf;
index 41d3057..01a161d 100644 (file)
@@ -1236,35 +1236,77 @@ s_chtml50_start_font_tag(void *pdoc, Node *node)
   chtml50_t     *chtml50;
   Doc           *doc;
   request_rec   *r;
+  char          *color = NULL;
+  char          *size = NULL;
 
   chtml50 = GET_CHTML50(pdoc);
   doc     = chtml50->doc;
   r       = doc->r;
 
-  W_L("<font");
   /*--------------------------------------------------------------------------*/
   /* Get Attributes                                                           */
   /*--------------------------------------------------------------------------*/
   for (attr = qs_get_attr(doc,node);
-       attr; 
+       attr && (color == NULL || size == NULL)
        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('c','C',"color", name) && value && *value) {
-      W_L(" color=\"");
-      W_V(value);
-      W_L("\"");
+      color = apr_pstrdup(doc->buf.pool, value);
     }
     else if (STRCASEEQ('s','S',"size", name) && value && *value) {
       /*----------------------------------------------------------------------*/
       /* CHTML 5.0                                                            */
       /*----------------------------------------------------------------------*/
+      size = apr_pstrdup(doc->buf.pool, value);
+      switch (*size) {
+      case '1':
+      case '2':
+      case '3':
+      case '4':
+      case '5':
+      case '6':
+      case '7':
+        if (*(size + 1) == 0) {
+          break;
+        }
+        size = NULL;
+        break;
+
+      case '+':
+      case '-':
+        {
+          char ch = *(size + 1);
+          if (ch == '1' || ch == '2' || ch == '3') {
+            if (*(size + 2) == 0) {
+              break;
+            }
+          }
+        }
+        size = NULL;
+        break;
+
+      default:
+        size = NULL;
+      }
+    }
+    if (color && size) break;
+  }
+  if (color || size) {
+    W_L("<font");
+    if (color) {
+      W_L(" color=\"");
+      W_V(color);
+      W_L("\"");
+    }
+    if (size) {
       W_L(" size=\"");
-      W_V(value);
+      W_V(size);
       W_L("\"");
     }
+    W_L(">");
+    chtml50->font_flag++;
   }
-  W_L(">");
   return chtml50->out;
 }
 
@@ -1288,8 +1330,11 @@ s_chtml50_end_font_tag(void *pdoc, Node *UNUSED(child))
   doc     = chtml50->doc;
   r       = doc->r;
 
-  W_L("</font>");
-  W_NLCODE();
+  if (chtml50->font_flag) {
+    W_L("</font>");
+    W_NLCODE();
+    chtml50->font_flag--;
+  }
 
   return chtml50->out;
 }
index 5c3f0a1..b41bb7d 100644 (file)
@@ -12516,7 +12516,7 @@ void test_chtml50_param_tag_001()
 void test_chtml50_font_tag_001() 
 {
 #define  TEST_STRING "<font>aaa</font>"
-#define  RESULT_STRING "<font>aaa</font>"
+#define  RESULT_STRING "aaa"
   char  *ret;
   char  *tmp;
   device_table spec;
@@ -12572,7 +12572,7 @@ void test_chtml50_font_tag_002()
 void test_chtml50_font_tag_003() 
 {
 #define  TEST_STRING "<font color=\"\">aaa</font>"
-#define  RESULT_STRING "<font>aaa</font>"
+#define  RESULT_STRING "aaa"
   char  *ret;
   char  *tmp;
   device_table spec;
@@ -12600,7 +12600,7 @@ void test_chtml50_font_tag_003()
 void test_chtml50_font_tag_004() 
 {
 #define  TEST_STRING "<font color>aaa</font>"
-#define  RESULT_STRING "<font>aaa</font>"
+#define  RESULT_STRING "aaa"
   char  *ret;
   char  *tmp;
   device_table spec;
@@ -12880,7 +12880,7 @@ void test_chtml50_font_tag_005_9()
 void test_chtml50_font_tag_006() 
 {
 #define  TEST_STRING "<font size=\"\">aaa</font>"
-#define  RESULT_STRING "<font>aaa</font>"
+#define  RESULT_STRING "aaa"
   char  *ret;
   char  *tmp;
   device_table spec;
@@ -12908,7 +12908,203 @@ void test_chtml50_font_tag_006()
 void test_chtml50_font_tag_007() 
 {
 #define  TEST_STRING "<font size>aaa</font>"
-#define  RESULT_STRING "<font>aaa</font>"
+#define  RESULT_STRING "aaa"
+  char  *ret;
+  char  *tmp;
+  device_table spec;
+  chxjconvrule_entry entry;
+  cookie_t cookie;
+  apr_size_t destlen;
+  APR_INIT;
+
+  COOKIE_INIT(cookie);
+
+  SPEC_INIT(spec);
+  destlen = sizeof(TEST_STRING)-1;
+
+  tmp = chxj_encoding(&r, TEST_STRING, &destlen);
+  ret = chxj_convert_chtml50(&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);
+
+  APR_TERM;
+#undef TEST_STRING
+#undef RESULT_STRING
+}
+void test_chtml50_font_tag_008() 
+{
+#define  TEST_STRING "<font size=\"-1\">aaa</font>"
+#define  RESULT_STRING "<font size=\"-1\">aaa</font>"
+  char  *ret;
+  char  *tmp;
+  device_table spec;
+  chxjconvrule_entry entry;
+  cookie_t cookie;
+  apr_size_t destlen;
+  APR_INIT;
+
+  COOKIE_INIT(cookie);
+
+  SPEC_INIT(spec);
+  destlen = sizeof(TEST_STRING)-1;
+
+  tmp = chxj_encoding(&r, TEST_STRING, &destlen);
+  ret = chxj_convert_chtml50(&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);
+
+  APR_TERM;
+#undef TEST_STRING
+#undef RESULT_STRING
+}
+void test_chtml50_font_tag_009() 
+{
+#define  TEST_STRING "<font size=\"-2\">aaa</font>"
+#define  RESULT_STRING "<font size=\"-2\">aaa</font>"
+  char  *ret;
+  char  *tmp;
+  device_table spec;
+  chxjconvrule_entry entry;
+  cookie_t cookie;
+  apr_size_t destlen;
+  APR_INIT;
+
+  COOKIE_INIT(cookie);
+
+  SPEC_INIT(spec);
+  destlen = sizeof(TEST_STRING)-1;
+
+  tmp = chxj_encoding(&r, TEST_STRING, &destlen);
+  ret = chxj_convert_chtml50(&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);
+
+  APR_TERM;
+#undef TEST_STRING
+#undef RESULT_STRING
+}
+void test_chtml50_font_tag_010() 
+{
+#define  TEST_STRING "<font size=\"-3\">aaa</font>"
+#define  RESULT_STRING "<font size=\"-3\">aaa</font>"
+  char  *ret;
+  char  *tmp;
+  device_table spec;
+  chxjconvrule_entry entry;
+  cookie_t cookie;
+  apr_size_t destlen;
+  APR_INIT;
+
+  COOKIE_INIT(cookie);
+
+  SPEC_INIT(spec);
+  destlen = sizeof(TEST_STRING)-1;
+
+  tmp = chxj_encoding(&r, TEST_STRING, &destlen);
+  ret = chxj_convert_chtml50(&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);
+
+  APR_TERM;
+#undef TEST_STRING
+#undef RESULT_STRING
+}
+void test_chtml50_font_tag_011() 
+{
+#define  TEST_STRING "<font size=\"+1\">aaa</font>"
+#define  RESULT_STRING "<font size=\"+1\">aaa</font>"
+  char  *ret;
+  char  *tmp;
+  device_table spec;
+  chxjconvrule_entry entry;
+  cookie_t cookie;
+  apr_size_t destlen;
+  APR_INIT;
+
+  COOKIE_INIT(cookie);
+
+  SPEC_INIT(spec);
+  destlen = sizeof(TEST_STRING)-1;
+
+  tmp = chxj_encoding(&r, TEST_STRING, &destlen);
+  ret = chxj_convert_chtml50(&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);
+
+  APR_TERM;
+#undef TEST_STRING
+#undef RESULT_STRING
+}
+void test_chtml50_font_tag_012() 
+{
+#define  TEST_STRING "<font size=\"+2\">aaa</font>"
+#define  RESULT_STRING "<font size=\"+2\">aaa</font>"
+  char  *ret;
+  char  *tmp;
+  device_table spec;
+  chxjconvrule_entry entry;
+  cookie_t cookie;
+  apr_size_t destlen;
+  APR_INIT;
+
+  COOKIE_INIT(cookie);
+
+  SPEC_INIT(spec);
+  destlen = sizeof(TEST_STRING)-1;
+
+  tmp = chxj_encoding(&r, TEST_STRING, &destlen);
+  ret = chxj_convert_chtml50(&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);
+
+  APR_TERM;
+#undef TEST_STRING
+#undef RESULT_STRING
+}
+void test_chtml50_font_tag_013() 
+{
+#define  TEST_STRING "<font size=\"+3\">aaa</font>"
+#define  RESULT_STRING "<font size=\"+3\">aaa</font>"
+  char  *ret;
+  char  *tmp;
+  device_table spec;
+  chxjconvrule_entry entry;
+  cookie_t cookie;
+  apr_size_t destlen;
+  APR_INIT;
+
+  COOKIE_INIT(cookie);
+
+  SPEC_INIT(spec);
+  destlen = sizeof(TEST_STRING)-1;
+
+  tmp = chxj_encoding(&r, TEST_STRING, &destlen);
+  ret = chxj_convert_chtml50(&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);
+
+  APR_TERM;
+#undef TEST_STRING
+#undef RESULT_STRING
+}
+void test_chtml50_font_tag_014() 
+{
+#define  TEST_STRING "<font size=\"8\">aaa</font>"
+#define  RESULT_STRING "aaa"
   char  *ret;
   char  *tmp;
   device_table spec;