]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/libopensrf/osrf_json_test.c
Patch from Scott McKellar:
[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         snprintf(buf, sizeof(buf), "key_%d", i);
36
37         array = jsonNewObject(NULL);
38         for(k = 0; k < count + i; k++) {
39             jsonObjectPush(array, jsonNewNumberObject(k));
40             jsonObjectPush(array, jsonNewObject(NULL));
41             jsonObjectPush(array, jsonNewObjectFmt("str %d-%d", i, k));
42         }
43         jsonObjectSetKey(hash, buf, array);
44
45         jsonString = jsonObjectToJSON(hash);
46         printf("%s\n\n", jsonString);
47         dupe = jsonParseString(jsonString);
48
49         jsonObjectFree(dupe);
50         free(jsonString);
51     }
52
53     jsonObjectFree(hash);
54 }
55