xref: /3.0.3-GA/platform/tests/cjson_test.c (revision 21dc4478)
1/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2#include <stdlib.h>
3#include <string.h>
4#include <cJSON.h>
5#include <stdio.h>
6
7int main(void) {
8   const char *expected = "{\"foo\":\"bar\"}";
9   char *str;
10   int retcode = EXIT_SUCCESS;
11   cJSON *obj;
12
13   obj = cJSON_CreateObject();
14   cJSON_AddStringToObject(obj, "foo", "bar");
15   str = cJSON_PrintUnformatted(obj);
16   if (strcmp(str, expected) != 0) {
17      fprintf(stderr, "Expected %s got %s\n", expected, str);
18      retcode = EXIT_FAILURE;
19   }
20   cJSON_Delete(obj);
21   cJSON_Free(str);
22
23   return retcode;
24}
25