diff options
Diffstat (limited to 'tests/unit/bson/bson_validate_key.c')
-rw-r--r-- | tests/unit/bson/bson_validate_key.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/unit/bson/bson_validate_key.c b/tests/unit/bson/bson_validate_key.c new file mode 100644 index 0000000..126b1fd --- /dev/null +++ b/tests/unit/bson/bson_validate_key.c @@ -0,0 +1,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) |