summaryrefslogtreecommitdiff
path: root/testing/hstox/methods.h
blob: 1a7f30594532663fe6901861099f38c3325602cb (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
#pragma once

#include "util.h"

#include <msgpack.h>

#define CHECK(COND)                                                                                \
  do {                                                                                             \
    if (!(COND))                                                                                   \
      return #COND;                                                                                \
  } while (0)

#define CHECK_SIZE(ARG, SIZE)                                                                      \
  do {                                                                                             \
    if ((ARG).size != (SIZE))                                                                      \
      return ssprintf("%s:%d: Size of `" #ARG "' expected to be %zu, but was %zu", __FILE__,       \
                      __LINE__, SIZE, (ARG).size);                                                 \
  } while (0)

#define CHECK_TYPE(ARG, TYPE)                                                                      \
  do {                                                                                             \
    if ((ARG).type != (TYPE))                                                                      \
      return ssprintf("%s:%d: Type of `" #ARG "' expected to be %s, but was %s", __FILE__,         \
                      __LINE__, type_name(TYPE), type_name((ARG).type));                           \
  } while (0)

#define SUCCESS                                                                                    \
  msgpack_pack_array(res, 0);                                                                      \
  if (true)

#define METHOD(TYPE, SERVICE, NAME)                                                                \
  char const *SERVICE##_##NAME(msgpack_object_##TYPE args, msgpack_packer *res)

// These are not defined by msgpack.h, but we need them for uniformity in the
// METHOD macro.
typedef int64_t  msgpack_object_i64;
typedef uint64_t msgpack_object_u64;

METHOD(array, Binary, decode);
METHOD(array, Binary, encode);

char const *call_method(msgpack_object_str name, msgpack_object_array args, msgpack_packer *res);
int method_cmp(char const *ptr, char const *expected, size_t max_size);

extern char const *const failure;
extern char const *const pending;
extern char const *const unimplemented;