2 * BongoDB, an embedded document-based engine
3 * Copyright (C) 2015 by Javier Sancho Fernandez <jsf at jsancho dot org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 bongo_client_t *bongo_client;
30 bongo_database_t *database;
31 bongo_collection_t *collection;
32 const char *document = "{\"name\": \"Jack\", \"age\": 27, \"list\": [1, 2, 3]}";
35 bongo_client = bongo_client_new ();
36 printf ("Databases: %d\n", bongo_client->n_databases);
37 database = bongo_client_get_database (bongo_client, "db_test");
38 printf ("Databases: %d\n", bongo_client->n_databases);
40 printf ("Collections: %d\n", database->database_node->n_collections);
41 collection = bongo_client_get_collection (bongo_client, "db_test", "col_test");
42 printf ("Collections: %d\n", database->database_node->n_collections);
44 if (!bongo_collection_insert (collection, BONGO_INSERT_NONE, document, NULL, &error)) {
45 fprintf (stderr, "%s\n", error.message);
48 bongo_collection_destroy (collection);
49 bongo_database_destroy (database);
50 bongo_client_destroy (bongo_client);
52 printf ("test_bongodb: PASSED\n");
62 const char *js = "{\"name\": \"Jack\", \"age\": 27, \"list\": [1, 2, 3]}";
65 n_tokens = jsmn_parse (&parser, js, strlen (js), NULL, 1);
66 tokens = malloc (sizeof (jsmntok_t) * n_tokens);
68 n_tokens = jsmn_parse (&parser, js, strlen (js), tokens, n_tokens);
69 printf ("Tokens: %d\n", n_tokens);
71 for (int i = 0; i < n_tokens; i++)
73 printf (" %d, %d, %d, %d: %.*s\n", tokens[i].type, tokens[i].start, tokens[i].end, tokens[i].size, tokens[i].end - tokens[i].start, js + tokens[i].start);
78 printf ("test_jsmn: PASSED\n");