File: test-mongoc-set.c

package info (click to toggle)
syslog-ng 3.8.1-10
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 47,320 kB
  • ctags: 43,937
  • sloc: ansic: 159,432; yacc: 25,059; sh: 13,574; makefile: 4,669; python: 3,468; java: 3,218; xml: 2,309; perl: 318; lex: 316; awk: 184
file content (92 lines) | stat: -rw-r--r-- 1,704 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <mongoc.h>

#include "mongoc-set-private.h"

#include "TestSuite.h"

static void
test_set_dtor (void * item_, void * ctx_)
{
   int *destroyed = (int *)ctx_;

   (*destroyed)++;
}

static bool
test_set_visit_cb (void * item_, void * ctx_)
{
   int *visited = (int *)ctx_;

   (*visited)++;

   return true;
}

static bool
test_set_stop_after_cb (void * item_, void * ctx_)
{
   int *stop_after = (int *)ctx_;

   (*stop_after)--;

   return *stop_after > 0;
}

static void
test_set_new (void)
{
   void * items[10];
   int i;
   int destroyed = 0;
   int visited = 0;
   int stop_after = 3;

   mongoc_set_t * set = mongoc_set_new(2, &test_set_dtor, &destroyed);

   for (i = 0; i < 5; i++) {
      mongoc_set_add(set, i, items + i);
   }

   for (i = 0; i < 5; i++) {
      assert( mongoc_set_get(set, i) == items + i);
   }

   mongoc_set_rm(set, 0);

   assert (destroyed == 1);

   for (i = 5; i < 10; i++) {
      mongoc_set_add(set, i, items + i);
   }

   for (i = 5; i < 10; i++) {
      assert( mongoc_set_get(set, i) == items + i);
   }

   mongoc_set_rm(set, 9);
   assert (destroyed == 2);
   mongoc_set_rm(set, 5);
   assert (destroyed == 3);

   assert( mongoc_set_get(set, 1) == items + 1);
   assert( mongoc_set_get(set, 7) == items + 7);
   assert( ! mongoc_set_get(set, 5) );

   mongoc_set_add(set, 5, items + 5);
   assert( mongoc_set_get(set, 5) == items + 5);

   mongoc_set_for_each(set, test_set_visit_cb, &visited);
   assert( visited == 8 );

   mongoc_set_for_each(set, test_set_stop_after_cb, &stop_after);
   assert( stop_after == 0 );

   mongoc_set_destroy(set);
}


void
test_set_install (TestSuite *suite)
{
   TestSuite_Add (suite, "/Set/new", test_set_new);
}