Merge "[lib-fix] Fixed return value of kdbus_write_msg Change-Id: Ia3a45a6a79b4078929...
[platform/upstream/dbus.git] / dbus / dbus-marshal-recursive-util.c
index e1b00e5..6d62983 100644 (file)
@@ -1,4 +1,4 @@
-/* -*- mode: C; c-file-style: "gnu" -*- */
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /* dbus-marshal-recursive-util.c  Would be in dbus-marshal-recursive.c, but only used in bus/tests
  *
  * Copyright (C) 2004, 2005 Red Hat, Inc.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
 
 #include <config.h>
 
-#ifdef DBUS_BUILD_TESTS
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
 
 #include "dbus-marshal-recursive.h"
 #include "dbus-marshal-basic.h"
@@ -38,8 +38,8 @@ basic_value_zero (DBusBasicValue *value)
 #ifdef DBUS_HAVE_INT64
   value->u64 = 0;
 #else
-  value->u64.first32 = 0;
-  value->u64.second32 = 0;
+  value->eight.first32 = 0;
+  value->eight.second32 = 0;
 #endif
 }
 
@@ -59,8 +59,8 @@ basic_value_equal (int             type,
 #ifdef DBUS_HAVE_INT64
       return lhs->u64 == rhs->u64;
 #else
-      return lhs->u64.first32 == rhs->u64.first32 &&
-        lhs->u64.second32 == rhs->u64.second32;
+      return lhs->eight.first32 == rhs->eight.first32 &&
+        lhs->eight.second32 == rhs->eight.second32;
 #endif
     }
 }
@@ -124,6 +124,9 @@ _dbus_type_reader_equal_values (const DBusTypeReader *lhs,
 }
 
 /* TESTS */
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+
 #include "dbus-test.h"
 #include "dbus-list.h"
 #include <stdio.h>
@@ -945,7 +948,7 @@ node_new (const TestTypeNodeClass *klass)
       if (!(* klass->construct) (node))
         {
           dbus_free (node);
-          return FALSE;
+          return NULL;
         }
     }
 
@@ -983,23 +986,11 @@ node_read_value (TestTypeNode   *node,
                  DBusTypeReader *reader,
                  int             seed)
 {
-  DBusTypeMark mark;
-  DBusTypeReader restored;
-
-  _dbus_type_reader_save_mark (reader, &mark);
+  /* DBusTypeReader restored; */
 
   if (!(* node->klass->read_value) (node, reader, seed))
     return FALSE;
 
-  _dbus_type_reader_init_from_mark (&restored,
-                                    reader->byte_order,
-                                    reader->type_str,
-                                    reader->value_str,
-                                    &mark);
-
-  if (!(* node->klass->read_value) (node, &restored, seed))
-    return FALSE;
-
   return TRUE;
 }
 
@@ -1099,7 +1090,7 @@ run_test_copy (NodeIterationData *nid)
   DBusTypeReader reader;
   DBusTypeWriter writer;
 
-  _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
+  _dbus_verbose ("\n");
 
   src = nid->block;
 
@@ -1162,7 +1153,7 @@ run_test_values_only_write (NodeIterationData *nid)
   dbus_bool_t retval;
   int sig_len;
 
-  _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
+  _dbus_verbose ("\n");
 
   retval = FALSE;
 
@@ -1230,7 +1221,7 @@ run_test_set_values (NodeIterationData *nid)
   dbus_bool_t retval;
   int i;
 
-  _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
+  _dbus_verbose ("\n");
 
   retval = FALSE;
 
@@ -1287,7 +1278,7 @@ run_test_delete_values (NodeIterationData *nid)
   dbus_bool_t retval;
   int t;
 
-  _dbus_verbose ("%s\n", _DBUS_FUNCTION_NAME);
+  _dbus_verbose ("\n");
 
   retval = FALSE;
 
@@ -1933,6 +1924,14 @@ make_and_run_test_nodes (void)
     node_destroy (node);
   }
 
+  if (_dbus_getenv ("DBUS_TEST_SLOW") == NULL ||
+      atoi (_dbus_getenv ("DBUS_TEST_SLOW")) < 1)
+    {
+      fprintf (stderr, "skipping remaining marshal-recursive tests, "
+          "run with DBUS_TEST_SLOW=1 (or more) to enable\n");
+      goto out;
+    }
+
   start_next_test ("Each container of each container of each value %d iterations\n",
                    N_CONTAINERS * N_CONTAINERS * N_VALUES);
   for (i = 0; i < N_CONTAINERS; i++)
@@ -2005,8 +2004,15 @@ make_and_run_test_nodes (void)
       node_destroy (outer_container);
     }
 
-#if 0
-  /* This one takes a really long time, so comment it out for now */
+  /* This one takes a really long time (10 minutes on a Core2), so only enable
+   * it if you're really sure */
+  if (atoi (_dbus_getenv ("DBUS_TEST_SLOW")) < 2)
+    {
+      fprintf (stderr, "skipping really slow marshal-recursive test, "
+          "run with DBUS_TEST_SLOW=2 (or more) to enable\n");
+      goto out;
+    }
+
   start_next_test ("Each value,value,value triplet combination as toplevel, in all orders %d iterations\n",
                    N_VALUES * N_VALUES * N_VALUES);
   {
@@ -2030,8 +2036,8 @@ make_and_run_test_nodes (void)
         node_destroy (nodes[0]);
       }
   }
-#endif /* #if 0 expensive test */
 
+out:
   fprintf (stderr, "%d total iterations of recursive marshaling tests\n",
            n_iterations_completed_total);
   fprintf (stderr, "each iteration ran at initial offsets 0 through %d in both big and little endian\n",
@@ -2458,9 +2464,10 @@ string_write_value (TestTypeNode   *node,
                     DBusTypeWriter *writer,
                     int             seed)
 {
-  char buf[MAX_SAMPLE_STRING_LEN];
+  char buf[MAX_SAMPLE_STRING_LEN + 1]="";
   const char *v_string = buf;
 
+
   string_from_seed (buf, node->klass->subclass_detail,
                     seed);
 
@@ -2475,7 +2482,8 @@ string_read_value (TestTypeNode   *node,
                    int             seed)
 {
   const char *v;
-  char buf[MAX_SAMPLE_STRING_LEN];
+  char buf[MAX_SAMPLE_STRING_LEN + 1];
+  v = buf;
 
   check_expected_type (reader, node->klass->typecode);
 
@@ -2501,7 +2509,7 @@ string_set_value (TestTypeNode   *node,
                   DBusTypeReader *realign_root,
                   int             seed)
 {
-  char buf[MAX_SAMPLE_STRING_LEN];
+  char buf[MAX_SAMPLE_STRING_LEN + 1];
   const char *v_string = buf;
 
   string_from_seed (buf, node->klass->subclass_detail,
@@ -2658,8 +2666,8 @@ double_read_value (TestTypeNode   *node,
 
   if (!_DBUS_DOUBLES_BITWISE_EQUAL (v, expected))
     {
-#ifdef DBUS_HAVE_INT64
-      _dbus_warn ("Expected double %g got %g\n bits = 0x%llx vs.\n bits = 0x%llx)\n",
+#ifdef DBUS_INT64_PRINTF_MODIFIER
+      _dbus_warn ("Expected double %g got %g\n bits = 0x%" DBUS_INT64_PRINTF_MODIFIER "x vs.\n bits = 0x%" DBUS_INT64_PRINTF_MODIFIER "x)\n",
                   expected, v,
                   *(dbus_uint64_t*)(char*)&expected,
                   *(dbus_uint64_t*)(char*)&v);
@@ -2730,7 +2738,7 @@ object_path_write_value (TestTypeNode   *node,
                          DBusTypeWriter *writer,
                          int             seed)
 {
-  char buf[MAX_SAMPLE_OBJECT_PATH_LEN];
+  char buf[MAX_SAMPLE_OBJECT_PATH_LEN + 1];
   const char *v_string = buf;
 
   object_path_from_seed (buf, seed);
@@ -2746,7 +2754,7 @@ object_path_read_value (TestTypeNode   *node,
                         int             seed)
 {
   const char *v;
-  char buf[MAX_SAMPLE_OBJECT_PATH_LEN];
+  char buf[MAX_SAMPLE_OBJECT_PATH_LEN + 1];
 
   check_expected_type (reader, node->klass->typecode);
 
@@ -2771,7 +2779,7 @@ object_path_set_value (TestTypeNode   *node,
                        DBusTypeReader *realign_root,
                        int             seed)
 {
-  char buf[MAX_SAMPLE_OBJECT_PATH_LEN];
+  char buf[MAX_SAMPLE_OBJECT_PATH_LEN + 1];
   const char *v_string = buf;
 
   object_path_from_seed (buf, seed);
@@ -2786,8 +2794,6 @@ static void
 signature_from_seed (char *buf,
                      int   seed)
 {
-  int i;
-  const char *s;
   /* try to avoid ascending, descending, or alternating length to help find bugs */
   const char *sample_signatures[] = {
     "asax"
@@ -2798,13 +2804,7 @@ signature_from_seed (char *buf,
     "a(ii)"
   };
 
-  s = sample_signatures[seed % _DBUS_N_ELEMENTS(sample_signatures)];
-
-  for (i = 0; s[i]; i++)
-    {
-      buf[i] = s[i];
-    }
-  buf[i] = '\0';
+  strcpy (buf, sample_signatures[seed % _DBUS_N_ELEMENTS(sample_signatures)]);
 }
 
 static dbus_bool_t
@@ -2813,7 +2813,7 @@ signature_write_value (TestTypeNode   *node,
                        DBusTypeWriter *writer,
                        int             seed)
 {
-  char buf[MAX_SAMPLE_SIGNATURE_LEN];
+  char buf[MAX_SAMPLE_SIGNATURE_LEN + 1];
   const char *v_string = buf;
 
   signature_from_seed (buf, seed);
@@ -2829,7 +2829,7 @@ signature_read_value (TestTypeNode   *node,
                       int             seed)
 {
   const char *v;
-  char buf[MAX_SAMPLE_SIGNATURE_LEN];
+  char buf[MAX_SAMPLE_SIGNATURE_LEN + 1];
 
   check_expected_type (reader, node->klass->typecode);
 
@@ -2855,7 +2855,7 @@ signature_set_value (TestTypeNode   *node,
                      DBusTypeReader *realign_root,
                      int             seed)
 {
-  char buf[MAX_SAMPLE_SIGNATURE_LEN];
+  char buf[MAX_SAMPLE_SIGNATURE_LEN + 1];
   const char *v_string = buf;
 
   signature_from_seed (buf, seed);
@@ -3074,7 +3074,7 @@ array_write_value (TestTypeNode   *node,
     goto oom;
 
   if (arrays_write_fixed_in_blocks &&
-      _dbus_type_is_fixed (element_type) &&
+      dbus_type_is_fixed (element_type) &&
       child->klass->write_multi)
     {
       if (!node_write_multi (child, block, &sub, seed, n_copies))
@@ -3138,7 +3138,7 @@ array_read_or_set_value (TestTypeNode   *node,
       _dbus_type_reader_recurse (reader, &sub);
 
       if (realign_root == NULL && arrays_write_fixed_in_blocks &&
-          _dbus_type_is_fixed (_dbus_type_reader_get_element_type (reader)) &&
+          dbus_type_is_fixed (_dbus_type_reader_get_element_type (reader)) &&
           child->klass->read_multi)
         {
           if (!node_read_multi (child, &sub, seed, n_copies))
@@ -3341,7 +3341,6 @@ dict_write_value (TestTypeNode   *node,
   DBusString dict_entry_signature;
   int i;
   int n_entries;
-  int entry_value_type;
   TestTypeNode *child;
 
   n_entries = node->klass->subclass_detail;
@@ -3378,9 +3377,7 @@ dict_write_value (TestTypeNode   *node,
   if (!_dbus_string_append_byte (&dict_entry_signature,
                                  DBUS_DICT_ENTRY_END_CHAR))
     goto oom;
-  
-  entry_value_type = _dbus_first_type_in_signature (&entry_value_signature, 0);
-  
+
   if (!_dbus_type_writer_recurse (writer, DBUS_TYPE_ARRAY,
                                   &dict_entry_signature, 0,
                                   &sub))
@@ -3575,4 +3572,6 @@ container_destroy (TestTypeNode *node)
     }
 }
 
-#endif /* DBUS_BUILD_TESTS */
+#endif /* !DOXYGEN_SHOULD_SKIP_THIS */
+
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */