Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Commit

Permalink
CDRIVER-1003 utf-8 literals in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdavis committed Nov 17, 2015
1 parent d228ea8 commit d4feba4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions tests/test-bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,9 @@ test_bson_new_from_buffer (void)
static void
test_bson_utf8_key (void)
{
/* euro currency symbol */
#define EU "\xe2\x82\xac"
#define FIVE_EUROS EU EU EU EU EU
uint32_t length;
bson_iter_t iter;
const char *str;
Expand All @@ -1086,10 +1089,10 @@ test_bson_utf8_key (void)
assert(bson_validate(b, BSON_VALIDATE_NONE, &offset));
assert(bson_iter_init(&iter, b));
assert(bson_iter_next(&iter));
assert(!strcmp(bson_iter_key(&iter), "€€€€€"));
assert(!strcmp(bson_iter_key(&iter), FIVE_EUROS));
assert((str = bson_iter_utf8(&iter, &length)));
assert(length == 15); /* 5 3-byte sequences. */
assert(!strcmp(str, "€€€€€"));
assert(!strcmp(str, FIVE_EUROS));
bson_destroy(b);
}

Expand Down
7 changes: 5 additions & 2 deletions tests/test-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,17 @@ test_bson_as_json_double (void)
static void
test_bson_as_json_utf8 (void)
{
/* euro currency symbol */
#define EU "\xe2\x82\xac"
#define FIVE_EUROS EU EU EU EU EU
size_t len;
bson_t *b;
char *str;

b = bson_new();
assert(bson_append_utf8(b, "€€€€€", -1, "€€€€€", -1));
assert(bson_append_utf8(b, FIVE_EUROS, -1, FIVE_EUROS, -1));
str = bson_as_json(b, &len);
assert(!strcmp(str, "{ \"€€€€€\" : \"€€€€€\" }"));
assert(!strcmp(str, "{ \"" FIVE_EUROS "\" : \"" FIVE_EUROS "\" }"));
bson_free(str);
bson_destroy(b);
}
Expand Down

0 comments on commit d4feba4

Please sign in to comment.