Debian Codegraph @

src/tests/yajl_test.c

raw symbols SCIP
1 #define SDL_MAIN_HANDLED
2 #include <cbehave/cbehave.h>
3
4 #include <yajl_utils.h>
5
6 FEATURE(string_pair, "String pair")
7 SCENARIO("String pair")
8 GIVEN("a string key/value pair")
9 const char *key = "key";
10 const char *value = "value";
11
12 WHEN("I add the pair")
13 yajl_gen g = yajl_gen_alloc(NULL);
14 yajl_gen_map_open(g);
15 YAJLAddStringPair(g, key, value);
16 yajl_gen_map_close(g);
17 const unsigned char *buf;
18 size_t len;
19 yajl_gen_get_buf(g, &buf, &len);
20 AND("I load the document back")
21 yajl_val node = yajl_tree_parse((const char *)buf, NULL, 0);
22
23 THEN("the loaded value should be the same")
24 char *loadedValue = YAJLGetStr(node, key);
25 SHOULD_STR_EQUAL(loadedValue, value);
26 CFREE(loadedValue);
27 yajl_tree_free(node);
28 yajl_gen_clear(g);
29 yajl_gen_free(g);
30 SCENARIO_END
31 FEATURE_END
32
33 CBEHAVE_RUN("YAJL features are:", TEST_FEATURE(string_pair))