OSDN Git Service

* Added test code of the qs_get_value_attr() function.
authorkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Fri, 2 May 2008 18:42:01 +0000 (18:42 +0000)
committerkonn <konn@1a406e8e-add9-4483-a2c8-d8cac5b7c224>
Fri, 2 May 2008 18:42:01 +0000 (18:42 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/modchxj/mod_chxj/branches/RELEASE_0_12_0@2603 1a406e8e-add9-4483-a2c8-d8cac5b7c224

13 files changed:
include/chxj_tag_util.h
src/chxj_chtml10.c
src/chxj_chtml20.c
src/chxj_chtml30.c
src/chxj_chtml40.c
src/chxj_chtml50.c
src/chxj_hdml.c
src/chxj_jhtml.c
src/chxj_jxhtml.c
src/chxj_tag_util.c
src/chxj_xhtml_mobile_1_0.c
test/chxj_tag_util/Makefile [new file with mode: 0644]
test/chxj_tag_util/test_chxj_tag_util.c [new file with mode: 0644]

index 9055c26..3edcb61 100644 (file)
 /*----------------------------------------------------------------------------*/
 /* prototype declare                                                          */
 /*----------------------------------------------------------------------------*/
-extern charqs_get_value_attr(
-  Doc*                doc, 
-  Node*               tag, 
-  request_rec*        r);
-
-extern charqs_get_checked_attr(
-  Doc*                doc, 
-  Node*               tag, 
-  request_rec*        r);
+extern char *qs_get_value_attr(
+  Doc                 *doc, 
+  Node                *tag, 
+  apr_pool_t          *pool);
+
+extern char *qs_get_checked_attr(
+  Doc                 *doc, 
+  Node                *tag, 
+  request_rec         *r);
 
 extern char* qs_get_type_attr(
   Doc*                doc,
index 38c3816..491d129 100644 (file)
@@ -1948,7 +1948,7 @@ s_chtml10_start_input_tag(void *pdoc, Node *node)
 
   type       = qs_get_type_attr(doc, node, r);
   name       = qs_get_name_attr(doc, node, r);
-  value      = qs_get_value_attr(doc,node,r);
+  value      = qs_get_value_attr(doc,node,doc->buf.pool);
   istyle     = qs_get_istyle_attr(doc,node,r);
   max_length = qs_get_maxlength_attr(doc,node,r);
   checked    = qs_get_checked_attr(doc,node,r);
index 81569b0..741cdcc 100644 (file)
@@ -1560,7 +1560,7 @@ s_chtml20_start_input_tag(void *pdoc, Node *node)
   /*--------------------------------------------------------------------------*/
   type       = qs_get_type_attr(doc, node, r);
   name       = qs_get_name_attr(doc, node, r);
-  value      = qs_get_value_attr(doc,node,r);
+  value      = qs_get_value_attr(doc,node,doc->buf.pool);
   istyle     = qs_get_istyle_attr(doc,node,r);
   max_length = qs_get_maxlength_attr(doc,node,r);
   checked    = qs_get_checked_attr(doc,node,r);
index 1df81e4..790882e 100644 (file)
@@ -1411,7 +1411,7 @@ s_chtml30_start_input_tag(void *pdoc, Node *node)
   /*--------------------------------------------------------------------------*/
   type       = qs_get_type_attr(doc, node, r);
   name       = qs_get_name_attr(doc, node, r);
-  value      = qs_get_value_attr(doc,node,r);
+  value      = qs_get_value_attr(doc,node,doc->buf.pool);
   istyle     = qs_get_istyle_attr(doc,node,r);
   max_length = qs_get_maxlength_attr(doc,node,r);
   checked    = qs_get_checked_attr(doc,node,r);
index c62067d..ce26c79 100644 (file)
@@ -1418,7 +1418,7 @@ s_chtml40_start_input_tag(void *pdoc, Node *node)
   /*--------------------------------------------------------------------------*/
   type       = qs_get_type_attr(doc, node, r);
   name       = qs_get_name_attr(doc, node, r);
-  value      = qs_get_value_attr(doc,node,r);
+  value      = qs_get_value_attr(doc,node,doc->buf.pool);
   istyle     = qs_get_istyle_attr(doc,node,r);
   max_length = qs_get_maxlength_attr(doc,node,r);
   checked    = qs_get_checked_attr(doc,node,r);
index 01a161d..cf3dd09 100644 (file)
@@ -1457,7 +1457,7 @@ s_chtml50_start_input_tag(void *pdoc, Node *node)
   /*--------------------------------------------------------------------------*/
   type       = qs_get_type_attr(doc, node, r);
   name       = qs_get_name_attr(doc, node, r);
-  value      = qs_get_value_attr(doc,node,r);
+  value      = qs_get_value_attr(doc,node,doc->buf.pool);
   istyle     = qs_get_istyle_attr(doc,node,r);
   max_length = qs_get_maxlength_attr(doc,node,r);
   checked    = qs_get_checked_attr(doc,node,r);
index 15e8640..484de73 100644 (file)
@@ -1491,7 +1491,7 @@ s_hdml_do_input_text_tag(hdml_t *hdml, Node *tag)
 
   mlen = qs_get_maxlength_attr  (doc, tag, r);
   is   = qs_get_istyle_attr     (doc, tag, r);
-  val  = qs_get_value_attr      (doc, tag, r);
+  val  = qs_get_value_attr      (doc, tag, doc->buf.pool);
 
   fmt  = qs_conv_istyle_to_format(r, is);
   DBG(r,"qs_conv_istyle_to_format end");
@@ -1597,7 +1597,7 @@ s_hdml_do_input_password_tag(hdml_t *hdml, Node *tag)
                           hdml->var_cnt[hdml->pure_form_cnt]));
 
   mlen = qs_get_maxlength_attr  (doc, tag, r);
-  val  = qs_get_value_attr      (doc, tag, r);
+  val  = qs_get_value_attr      (doc, tag, doc->buf.pool);
   /*--------------------------------------------------------------------------*/
   /* Default is a figure input.                                               */
   /*--------------------------------------------------------------------------*/
@@ -1661,7 +1661,7 @@ s_hdml_do_input_submit_tag(hdml_t *hdml, Node *tag)
   /* get name and value attribute                                             */
   /*--------------------------------------------------------------------------*/
   nm  = qs_get_name_attr  (doc, tag, r);
-  val = qs_get_value_attr (doc, tag, r);
+  val = qs_get_value_attr (doc, tag, doc->buf.pool);
 
   if (nm && val) {
     s_output_to_hdml_out(hdml, 
@@ -1707,7 +1707,7 @@ s_hdml_do_input_reset_tag(hdml_t *hdml, Node *tag)
   /* get name and value attribute                                             */
   /*--------------------------------------------------------------------------*/
   nm  = qs_get_name_attr  (doc, tag, r);
-  val = qs_get_value_attr (doc, tag, r);
+  val = qs_get_value_attr (doc, tag, doc->buf.pool);
   if (val) {
     s_output_to_hdml_out(hdml, val);
   }
@@ -1734,7 +1734,7 @@ s_hdml_do_input_hidden_tag(hdml_t *hdml, Node *tag)
   /* get name and value attribute                                             */
   /*--------------------------------------------------------------------------*/
   nm  = qs_get_name_attr  (doc, tag, r);
-  val = qs_get_value_attr (doc, tag, r);
+  val = qs_get_value_attr (doc, tag, doc->buf.pool);
   if (nm && val) {
     s_output_to_postdata(hdml, 
                     apr_psprintf(r->pool, 
@@ -1769,7 +1769,7 @@ s_hdml_do_input_radio_tag(hdml_t *hdml, Node *tag)
   /* get name and value attribute                                             */
   /*--------------------------------------------------------------------------*/
   nm  = qs_get_name_attr  (doc, tag, r);
-  val = qs_get_value_attr (doc, tag, r);
+  val = qs_get_value_attr (doc, tag, doc->buf.pool);
   /*--------------------------------------------------------------------------*/
   /* The same name is searched out from the list made beforehand.             */
   /*--------------------------------------------------------------------------*/
@@ -1947,7 +1947,7 @@ s_hdml_do_input_checkbox_tag(hdml_t *hdml, Node *tag)
   /* The value of the name attribute and the value attribute is acquired      */
   /* respectively.                                                            */
   /*--------------------------------------------------------------------------*/
-  val = qs_get_value_attr(doc, tag, r);
+  val = qs_get_value_attr(doc, tag, doc->buf.pool);
   nm  = qs_get_name_attr(doc, tag, r);
 
   if (! val) {
@@ -2462,7 +2462,7 @@ s_hdml_start_option_tag(void *pdoc, Node *node)
   hdml->card_cnt++;
 
   hdml->option_flag = 1;
-  val = qs_get_value_attr(doc, node, r);
+  val = qs_get_value_attr(doc, node, doc->buf.pool);
 
   /*--------------------------------------------------------------------------*/
   /* The child node of the object tag node acquires the value in assumption   */
@@ -2696,7 +2696,7 @@ s_hdml_count_radio_tag(hdml_t *hdml, Node *node)
     DBG(r, "found type=radio");
 
     rname  = qs_get_name_attr (doc, child, r);
-    rvalue = qs_get_value_attr(doc, child, r);
+    rvalue = qs_get_value_attr(doc, child, doc->buf.pool);
 
     if (!rname) {
       /*----------------------------------------------------------------------*/
index 1f5634d..802bac8 100644 (file)
@@ -1481,7 +1481,7 @@ s_jhtml_start_input_tag(void *pdoc, Node *node)
   /*--------------------------------------------------------------------------*/
   type       = qs_get_type_attr(doc, node, r);
   name       = qs_get_name_attr(doc, node, r);
-  value      = qs_get_value_attr(doc,node,r);
+  value      = qs_get_value_attr(doc,node,doc->buf.pool);
   istyle     = qs_get_istyle_attr(doc,node,r);
   max_length = qs_get_maxlength_attr(doc,node,r);
   checked    = qs_get_checked_attr(doc,node,r);
index 5a5ae1d..def0153 100644 (file)
@@ -1539,7 +1539,7 @@ s_jxhtml_start_input_tag(void *pdoc, Node *node)
   /*--------------------------------------------------------------------------*/
   type       = qs_get_type_attr(doc, node, r);
   name       = qs_get_name_attr(doc, node, r);
-  value      = qs_get_value_attr(doc,node,r);
+  value      = qs_get_value_attr(doc,node, doc->buf.pool);
   istyle     = qs_get_istyle_attr(doc,node,r);
   max_length = qs_get_maxlength_attr(doc,node,r);
   checked    = qs_get_checked_attr(doc,node,r);
index 8dc5955..e241467 100644 (file)
@@ -28,7 +28,7 @@
  *         is returned. NULL is returned when not found.
  */
 char *
-qs_get_value_attr(Doc *doc, Node *node, request_rec *r)
+qs_get_value_attr(Doc *doc, Node *node, apr_pool_t *pool)
 {
   Attr *attr;
 
@@ -44,7 +44,7 @@ qs_get_value_attr(Doc *doc, Node *node, request_rec *r)
       /*----------------------------------------------------------------------*/
       /* The VALUE attribute was found.                                       */
       /*----------------------------------------------------------------------*/
-      return apr_pstrdup(r->pool, value);
+      return apr_pstrdup(pool, value);
     }
   }
   /*--------------------------------------------------------------------------*/
@@ -255,7 +255,7 @@ qs_get_selected_value(Doc *doc, Node *node, request_rec *r)
           /*------------------------------------------------------------------*/
           /* SELECTED Value Found                                             */
           /*------------------------------------------------------------------*/
-          return qs_get_value_attr(doc, child, r);
+          return qs_get_value_attr(doc, child, doc->buf.pool);
         }
       }
     }
index e2efb7f..49e146e 100644 (file)
@@ -1404,7 +1404,7 @@ s_xhtml_1_0_start_input_tag(void *pdoc, Node *node)
   /*--------------------------------------------------------------------------*/
   type       = qs_get_type_attr(doc, node, r);
   name       = qs_get_name_attr(doc, node, r);
-  value      = qs_get_value_attr(doc,node,r);
+  value      = qs_get_value_attr(doc,node,doc->buf.pool);
   istyle     = qs_get_istyle_attr(doc,node,r);
   max_length = qs_get_maxlength_attr(doc,node,r);
   checked    = qs_get_checked_attr(doc,node,r);
diff --git a/test/chxj_tag_util/Makefile b/test/chxj_tag_util/Makefile
new file mode 100644 (file)
index 0000000..b228af2
--- /dev/null
@@ -0,0 +1,25 @@
+.SUFFIXES:
+.SUFFIXES: .c.o
+
+TARGET= test_chxj_tag_util
+
+TOP_DIR=../..
+
+INC_DIR=-I$(TOP_DIR)/include \
+  -I/usr/include/apache2 \
+  -I/usr/include/apr-1.0 \
+  -I$(TOP_DIR)/src
+
+all:test
+
+
+
+test: $(TARGET)
+       ./$(TARGET)
+
+$(TARGET): $(TARGET).c
+       gcc -g -o $@ -Wall -lcunit $< $(INC_DIR) -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE  -lapr-1 -laprutil-1 
+
+
+clean:
+       rm -f ./$(TARGET)
diff --git a/test/chxj_tag_util/test_chxj_tag_util.c b/test/chxj_tag_util/test_chxj_tag_util.c
new file mode 100644 (file)
index 0000000..021ba1a
--- /dev/null
@@ -0,0 +1,160 @@
+#include <CUnit/CUnit.h>
+#include <CUnit/Console.h>
+#include <CUnit/Basic.h>
+#include <stdio.h>
+#define CHXJ_TEST
+#define IMG_NOT_CONVERT_FILENAME
+
+#include "apr.h"
+#include "apr_strings.h"
+#include "chxj_apache.h"
+#include "chxj_str_util.h"
+#include "chxj_str_util.c"
+#include "qs_ignore_sp.c"
+#include "qs_log.c"
+#include "qs_malloc.c"
+#include "qs_parse_string.c"
+#include "qs_parse_attr.c"
+#include "qs_parse_tag.c"
+#include "chxj_tag_util.c"
+#include <iconv.h>
+
+
+/*===========================================================================*/
+/* qs_new_tag();                                                             */
+/*===========================================================================*/
+void test_qs_get_value_attr_001();
+void test_qs_get_value_attr_002();
+void test_qs_get_value_attr_003();
+/* pend */
+
+void test_log_rerror(const char *file, int line, int level, apr_status_t status, const request_rec *r, const char *fmt, ...)
+{
+  va_list ap;
+  fprintf(stderr, "ERROR LOG %s:%d ", file,line);
+  va_start(ap, fmt);
+  vfprintf(stderr, fmt,ap);
+  va_end(ap);
+  fprintf(stderr, "\n");
+}
+void test_log_error(const char *file, int line, int level, apr_status_t status, const request_rec *r, const char *fmt, ...)
+{
+  va_list ap;
+  fprintf(stderr, "ERROR LOG %s:%d ", file,line);
+  va_start(ap, fmt);
+  vfprintf(stderr, fmt,ap);
+  va_end(ap);
+  fprintf(stderr, "\n");
+}
+
+int
+main()
+{
+  CU_pSuite str_util_suite;
+  CU_initialize_registry();
+  str_util_suite = CU_add_suite("test chxj_tag_util.c", NULL, NULL);
+  /*=========================================================================*/
+  /* qs_new_tag()                                                            */
+  /*=========================================================================*/
+  CU_add_test(str_util_suite, "qs_get_value_attr() 001",                               test_qs_get_value_attr_001);
+  CU_add_test(str_util_suite, "qs_get_value_attr() 002",                               test_qs_get_value_attr_002);
+  CU_add_test(str_util_suite, "qs_get_value_attr() 003",                               test_qs_get_value_attr_003);
+  /* aend */
+
+  CU_basic_run_tests();
+  CU_cleanup_registry();
+
+  return(0);
+}
+
+
+
+#define APR_INIT \
+  apr_pool_t *p; \
+  Doc doc;  \
+  do { \
+    apr_initialize(); \
+    apr_pool_create(&p, NULL); \
+    memset(&doc, 0, sizeof(Doc)); \
+    doc.pool = p; \
+  } \
+  while (0)
+
+#define APR_TERM \
+  do { \
+    apr_terminate(); \
+  } while (0)
+
+#define COOKIE_INIT(X) \
+  do { \
+    X.cookie_id = "test_cookie_id"; \
+  } while (0) \
+
+#define SPEC_INIT(X) \
+  do { \
+    X.html_spec_type = CHXJ_SPEC_Chtml_1_0; \
+  } while (0)
+
+
+
+
+/*===========================================================================*/
+/* qs_get_value_attr()                                                       */
+/*===========================================================================*/
+#if 0
+char *
+qs_get_value_attr(Doc *doc, Node *node, request_rec *r)
+#endif
+void test_qs_get_value_attr_001()
+{
+  Node *node;
+  char *ret;
+  APR_INIT;
+
+  node = qs_new_tag(&doc);
+  ret = qs_get_value_attr(&doc,node,p);
+  CU_ASSERT(ret == NULL);
+
+  APR_TERM;
+#undef TEST_STRING
+}
+void test_qs_get_value_attr_002()
+{
+  Node *node;
+  Attr *attr;
+  char *ret;
+  APR_INIT;
+
+  node = qs_new_tag(&doc);
+  attr = qs_new_attr(&doc);
+  attr->name = apr_pstrdup(p, "value");
+  attr->value = apr_pstrdup(p, "atai");
+  qs_add_attr(&doc,node,attr);
+  ret = qs_get_value_attr(&doc,node,p);
+  CU_ASSERT(ret != NULL);
+  CU_ASSERT(strcmp(ret, "atai") == 0);
+
+  APR_TERM;
+#undef TEST_STRING
+}
+void test_qs_get_value_attr_003()
+{
+  Node *node;
+  Attr *attr;
+  char *ret;
+  APR_INIT;
+
+  node = qs_new_tag(&doc);
+  attr = qs_new_attr(&doc);
+  attr->name = apr_pstrdup(p, "value1");
+  attr->value = apr_pstrdup(p, "atai");
+  qs_add_attr(&doc,node,attr);
+  ret = qs_get_value_attr(&doc,node,p);
+  CU_ASSERT(ret == NULL);
+
+  APR_TERM;
+#undef TEST_STRING
+}
+/*
+ * vim:ts=2 et
+ */