static void test_bson_alloc (void) { static const bson_uint8_t empty_bson[] = { 5, 0, 0, 0, 0 }; bson_t *b; b = bson_new(); assert_cmpint(b->len, ==, 5); assert((b->flags & BSON_FLAG_INLINE)); assert(!(b->flags & BSON_FLAG_CHILD)); assert(!(b->flags & BSON_FLAG_STATIC)); assert(!(b->flags & BSON_FLAG_NO_FREE)); bson_destroy(b); /* * This checks that we fit in the inline buffer size. */ b = bson_sized_new(44); assert_cmpint(b->len, ==, 5); assert((b->flags & BSON_FLAG_INLINE)); bson_destroy(b); /* * Make sure we grow to next power of 2. */ b = bson_sized_new(121); assert_cmpint(b->len, ==, 5); assert(!(b->flags & BSON_FLAG_INLINE)); bson_destroy(b); /* * Make sure we grow to next power of 2. */ b = bson_sized_new(129); assert_cmpint(b->len, ==, 5); assert(!(b->flags & BSON_FLAG_INLINE)); bson_destroy(b); b = bson_new_from_data(empty_bson, sizeof empty_bson); assert_cmpint(b->len, ==, sizeof empty_bson); assert((b->flags & BSON_FLAG_INLINE)); assert(!memcmp(bson_get_data(b), empty_bson, sizeof empty_bson)); bson_destroy(b); }
static void test_bson_new (void) { bson_t *b; b = bson_new(); assert_cmpint(b->len, ==, 5); bson_destroy(b); b = bson_sized_new(32); assert_cmpint(b->len, ==, 5); bson_destroy(b); }
/** * _mongoc_gridfs_file_flush_page: * * Unconditionally flushes the file's current page to the database. * The page to flush is determined by page->n. * * Side Effects: * * On success, file->page is properly destroyed and set to NULL. * * Returns: * * True on success; false otherwise. */ static bool _mongoc_gridfs_file_flush_page (mongoc_gridfs_file_t *file) { bson_t *selector, *update; bool r; const uint8_t *buf; uint32_t len; ENTRY; BSON_ASSERT (file); BSON_ASSERT (file->page); buf = _mongoc_gridfs_file_page_get_data (file->page); len = _mongoc_gridfs_file_page_get_len (file->page); selector = bson_new (); bson_append_value (selector, "files_id", -1, &file->files_id); bson_append_int32 (selector, "n", -1, file->n); update = bson_sized_new (file->chunk_size + 100); bson_append_value (update, "files_id", -1, &file->files_id); bson_append_int32 (update, "n", -1, file->n); bson_append_binary (update, "data", -1, BSON_SUBTYPE_BINARY, buf, len); r = mongoc_collection_update (file->gridfs->chunks, MONGOC_UPDATE_UPSERT, selector, update, NULL, &file->error); bson_destroy (selector); bson_destroy (update); if (r) { _mongoc_gridfs_file_page_destroy (file->page); file->page = NULL; r = mongoc_gridfs_file_save (file); } RETURN (r); }