summaryrefslogtreecommitdiff
path: root/tests/func/bson/huge_doc.c
blob: d5daafe83e62c39fdffa5e6c410eeda4e86de464 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "bson.h"
#include "tap.h"
#include "test.h"

#ifndef HUGE_DOC_SIZE
#define HUGE_DOC_SIZE (1024 * 1024)
#endif

#include <string.h>

static void
test_bson_huge_doc (void)
{
  bson *b, *s;
  bson_cursor *c;
  gchar *buffer;
  gint32 ds1;

  buffer = (gchar *)g_malloc (HUGE_DOC_SIZE);
  memset (buffer, 'a', HUGE_DOC_SIZE);
  buffer[HUGE_DOC_SIZE - 1] = '\0';

  b = bson_new ();
  bson_append_int32 (b, "preamble", 1);
  bson_append_string (b, "huge", buffer, -1);
  bson_append_int32 (b, "post", 1234);
  bson_finish (b);
  ds1 = bson_size (b);

  g_free (buffer);

  s = bson_new ();
  bson_append_document (s, "hugedoc", b);
  bson_finish (s);
  bson_free (b);

  cmp_ok (bson_size (s), ">", ds1,
          "Document embedding another huge one, has bigger size");

  c = bson_find (s, "hugedoc");
  bson_cursor_get_document (c, &b);

  cmp_ok (bson_size (b), "==", ds1,
          "The embedded document has the correct, huge size");

  bson_cursor_free (c);
  bson_free (s);
  bson_free (b);
}

RUN_TEST (2, bson_huge_doc);