summaryrefslogtreecommitdiffstats
path: root/contrib/libucl/tests/test_msgpack.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libucl/tests/test_msgpack.c')
-rw-r--r--contrib/libucl/tests/test_msgpack.c143
1 files changed, 135 insertions, 8 deletions
diff --git a/contrib/libucl/tests/test_msgpack.c b/contrib/libucl/tests/test_msgpack.c
index dd5860e..00f804a 100644
--- a/contrib/libucl/tests/test_msgpack.c
+++ b/contrib/libucl/tests/test_msgpack.c
@@ -26,9 +26,9 @@
#include "ucl_internal.h"
#include <ctype.h>
-static const int niter = 1000;
-static const int ntests = 100;
-static const int nelt = 10;
+static const int niter = 20;
+static const int ntests = 10;
+static const int nelt = 20;
static int recursion = 0;
@@ -39,6 +39,10 @@ static ucl_object_t* ucl_test_string (void);
static ucl_object_t* ucl_test_boolean (void);
static ucl_object_t* ucl_test_map (void);
static ucl_object_t* ucl_test_array (void);
+static ucl_object_t* ucl_test_large_map (void);
+static ucl_object_t* ucl_test_large_array (void);
+static ucl_object_t* ucl_test_large_string (void);
+static ucl_object_t* ucl_test_null (void);
ucl_msgpack_test tests[] = {
ucl_test_integer,
@@ -46,6 +50,7 @@ ucl_msgpack_test tests[] = {
ucl_test_boolean,
ucl_test_map,
ucl_test_array,
+ ucl_test_null
};
#define NTESTS (sizeof(tests) / sizeof(tests[0]))
@@ -144,6 +149,18 @@ main (int argc, char **argv)
ucl_object_insert_key (obj, elt, key, klen, true);
}
+ key = random_key (&klen);
+ elt = ucl_test_large_array ();
+ ucl_object_insert_key (obj, elt, key, klen, true);
+
+ key = random_key (&klen);
+ elt = ucl_test_large_map ();
+ ucl_object_insert_key (obj, elt, key, klen, true);
+
+ key = random_key (&klen);
+ elt = ucl_test_large_string ();
+ ucl_object_insert_key (obj, elt, key, klen, true);
+
emitted = ucl_object_emit_len (obj, UCL_EMIT_MSGPACK, &elen);
assert (emitted != NULL);
@@ -189,6 +206,7 @@ ucl_test_integer (void)
ucl_object_t *res;
int count, i;
uint64_t cur;
+ double curf;
res = ucl_object_typed_new (UCL_ARRAY);
count = pcg32_random () % nelt;
@@ -196,13 +214,32 @@ ucl_test_integer (void)
for (i = 0; i < count; i ++) {
cur = ((uint64_t)pcg32_random ()) << 32 | pcg32_random ();
ucl_array_append (res, ucl_object_fromint (cur % 128));
+ ucl_array_append (res, ucl_object_fromint (-(cur % 128)));
+ cur = ((uint64_t)pcg32_random ()) << 32 | pcg32_random ();
+ ucl_array_append (res, ucl_object_fromint (cur % UINT16_MAX));
+ ucl_array_append (res, ucl_object_fromint (-(cur % INT16_MAX)));
+ cur = ((uint64_t)pcg32_random ()) << 32 | pcg32_random ();
+ ucl_array_append (res, ucl_object_fromint (cur % UINT32_MAX));
+ ucl_array_append (res, ucl_object_fromint (-(cur % INT32_MAX)));
+ cur = ((uint64_t)pcg32_random ()) << 32 | pcg32_random ();
+ ucl_array_append (res, ucl_object_fromint (cur));
+ ucl_array_append (res, ucl_object_fromint (-cur));
+ /* Double version */
+ cur = ((uint64_t)pcg32_random ()) << 32 | pcg32_random ();
+ curf = (cur % 128) / 19 * 16;
+ ucl_array_append (res, ucl_object_fromdouble (curf));
cur = ((uint64_t)pcg32_random ()) << 32 | pcg32_random ();
- ucl_array_append (res, ucl_object_fromint (-cur % 128));
+ curf = -(cur % 128) / 19 * 16;
+ ucl_array_append (res, ucl_object_fromdouble (curf));
cur = ((uint64_t)pcg32_random ()) << 32 | pcg32_random ();
- ucl_array_append (res, ucl_object_fromint (cur % 65536));
+ curf = (cur % 65536) / 19 * 16;
+ ucl_array_append (res, ucl_object_fromdouble (curf));
+ ucl_array_append (res, ucl_object_fromdouble (-curf));
cur = ((uint64_t)pcg32_random ()) << 32 | pcg32_random ();
- ucl_array_append (res, ucl_object_fromint (cur % INT32_MAX));
+ curf = (cur % INT32_MAX) / 19 * 16;
+ ucl_array_append (res, ucl_object_fromdouble (curf));
cur = ((uint64_t)pcg32_random ()) << 32 | pcg32_random ();
+ memcpy (&curf, &cur, sizeof (curf));
ucl_array_append (res, ucl_object_fromint (cur));
}
@@ -251,6 +288,14 @@ ucl_test_string (void)
free (str);
}
+ /* One large string */
+ str = malloc (65537);
+ elt = ucl_object_fromstring_common (str, 65537,
+ UCL_STRING_RAW);
+ elt->flags |= UCL_OBJECT_BINARY;
+ ucl_array_append (res, elt);
+ free (str);
+
return res;
}
@@ -287,7 +332,13 @@ ucl_test_map (void)
for (i = 0; i < count; i ++) {
if (recursion > 10) {
- sel = pcg32_random () % (NTESTS - 2);
+ for (;;) {
+ sel = pcg32_random () % NTESTS;
+ if (tests[sel] != ucl_test_map &&
+ tests[sel] != ucl_test_array) {
+ break;
+ }
+ }
}
else {
sel = pcg32_random () % NTESTS;
@@ -311,6 +362,32 @@ ucl_test_map (void)
}
static ucl_object_t*
+ucl_test_large_map (void)
+{
+ ucl_object_t *res, *cur;
+ int count, i;
+ uint32_t cur_len;
+ size_t klen;
+ const char *key;
+
+ res = ucl_object_typed_new (UCL_OBJECT);
+ count = 65537;
+
+ recursion ++;
+
+ for (i = 0; i < count; i ++) {
+ key = random_key (&klen);
+ cur = ucl_test_boolean ();
+ assert (cur != NULL);
+ assert (klen != 0);
+
+ ucl_object_insert_key (res, cur, key, klen, true);
+ }
+
+ return res;
+}
+
+static ucl_object_t*
ucl_test_array (void)
{
ucl_object_t *res, *cur;
@@ -324,7 +401,13 @@ ucl_test_array (void)
for (i = 0; i < count; i ++) {
if (recursion > 10) {
- sel = pcg32_random () % (NTESTS - 2);
+ for (;;) {
+ sel = pcg32_random () % NTESTS;
+ if (tests[sel] != ucl_test_map &&
+ tests[sel] != ucl_test_array) {
+ break;
+ }
+ }
}
else {
sel = pcg32_random () % NTESTS;
@@ -338,3 +421,47 @@ ucl_test_array (void)
return res;
}
+
+static ucl_object_t*
+ucl_test_large_array (void)
+{
+ ucl_object_t *res, *cur;
+ int count, i;
+ uint32_t cur_len;
+
+ res = ucl_object_typed_new (UCL_ARRAY);
+ count = 65537;
+
+ recursion ++;
+
+ for (i = 0; i < count; i ++) {
+ cur = ucl_test_boolean ();
+ assert (cur != NULL);
+
+ ucl_array_append (res, cur);
+ }
+
+ return res;
+}
+
+static ucl_object_t*
+ucl_test_large_string (void)
+{
+ ucl_object_t *res;
+ char *str;
+ uint32_t cur_len;
+
+ while ((cur_len = pcg32_random ()) % 100000 == 0);
+ str = malloc (cur_len % 100000);
+ res = ucl_object_fromstring_common (str, cur_len % 100000,
+ UCL_STRING_RAW);
+ res->flags |= UCL_OBJECT_BINARY;
+
+ return res;
+}
+
+static ucl_object_t*
+ucl_test_null (void)
+{
+ return ucl_object_typed_new (UCL_NULL);
+}
OpenPOWER on IntegriCloud