]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/libopensrf/osrf_json_test.c
b3df61031f90a8d589c077db8c208873dace025b
[OpenSRF.git] / src / libopensrf / osrf_json_test.c
1 /*
2  * Basic JSON test module.  Needs more strenous tests....
3  *
4  */
5 #include <stdio.h>
6 #include <opensrf/osrf_json.h>
7
8 static void speedTest();
9
10
11 int main(int argc, char* argv[]) {
12     /* XXX add support for command line test type specification */
13     speedTest(); 
14     return 0; 
15 }
16
17
18
19 static void speedTest() {
20
21     /* creates a giant json object, generating JSON strings
22      * of subobjects as it goes. */
23
24     int i,k;
25     int count = 50;
26     char buf[16];
27     char* jsonString;
28
29     jsonObject* array;
30     jsonObject* dupe;
31     jsonObject* hash = jsonNewObject(NULL);
32
33     for(i = 0; i < count; i++) {
34         
35         memset(buf, 0, 16);
36         snprintf(buf, 16, "key_%d", i);
37
38         array = jsonNewObject(NULL);
39         for(k = 0; k < count + i; k++) {
40             jsonObjectPush(array, jsonNewNumberObject(k));
41             jsonObjectPush(array, jsonNewObject(NULL));
42             jsonObjectPush(array, jsonNewObjectFmt("str %d-%d", i, k));
43         }
44         jsonObjectSetKey(hash, buf, array);
45
46         jsonString = jsonObjectToJSON(hash);
47         printf("%s\n\n", jsonString);
48         dupe = jsonParseString(jsonString);
49
50         jsonObjectFree(dupe);
51         free(jsonString);
52     }
53
54     jsonObjectFree(hash);
55 }
56