summaryrefslogtreecommitdiffstats
path: root/t/test-common.c
blob: 707a5c73480d3ee28194ae6f64cc342c9d92083a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#define _GNU_SOURCE 1

#include <json.h>
#include <assert.h>
#include <check.h>

void
verify_value (struct json_object *jo, const char *key,
              const char *expected_value)
{
  struct json_object *o;
  const char *value;

  o = json_object_object_get (jo, key);

  ck_assert (o != NULL);

  value = json_object_get_string (o);

  ck_assert_str_eq (value, expected_value);
}

void
verify_value_differs (struct json_object *jo, const char *key,
                      const char *unexpected_value)
{
  struct json_object *o;
  const char *value;

  o = json_object_object_get (jo, key);

  ck_assert (o != NULL);

  value = json_object_get_string (o);

  ck_assert_str_ne (value, unexpected_value);
}

void
verify_value_exists (struct json_object *jo, const char *key)
{
  struct json_object *o;

  o = json_object_object_get (jo, key);
  ck_assert_msg (o != NULL, "key '%s' does not exist", key);
}

void
verify_value_missing (struct json_object *jo, const char *key)
{
  struct json_object *o;

  o = json_object_object_get (jo, key);
  assert (o == NULL);
}

struct json_object *
parse_msg (const char *msg)
{
  struct json_object *jo;

  jo = json_tokener_parse (msg);
  assert (jo != NULL);

  return jo;
}