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
|
#include "tap.h"
#include "test.h"
#include <errno.h>
#include <bson.h>
#include <string.h>
void
test_bson_validate_key (void)
{
gboolean valid;
valid = bson_validate_key (NULL, FALSE, FALSE);
ok (valid == FALSE && errno == EINVAL,
"bson_validate_key() sets errno when the key is NULL");
valid = bson_validate_key ("$foo.bar", FALSE, FALSE);
ok (valid == TRUE,
"bson_validate_key() returns success if both checks are off");
valid = bson_validate_key ("$foo.bar", FALSE, TRUE);
ok (valid == FALSE,
"bson_validate_key() returns failiure if the key starts with a $");
valid = bson_validate_key ("foo.bar$", FALSE, TRUE);
ok (valid == TRUE,
"bson_validate_key() returns success if the key does not start with a $");
valid = bson_validate_key ("foo.bar", TRUE, TRUE);
ok (valid == FALSE,
"bson_validate_key() returns failiure if the key contains a dot");
valid = bson_validate_key ("foobar", TRUE, TRUE);
ok (valid == TRUE,
"bson_validate_key() returns success if the key does not contain a dot");
}
RUN_TEST (6, bson_validate_key)
|