File: test_util.c

package info (click to toggle)
libvirt-dbus 1.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 888 kB
  • sloc: ansic: 8,558; xml: 1,588; python: 926; sh: 149; makefile: 19
file content (49 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download | duplicates (4)
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
#include "util.h"

#include <stdlib.h>

static gint
virtTestEncodeStr(const gchar *input,
                  const gchar *expected)
{
    g_autofree gchar *encoded = virtDBusUtilEncodeStr(input);

    if (!g_str_equal(encoded, expected)) {
        g_printerr("encode failed: expected '%s' actual '%s'\n",
                   expected, encoded);
        return -1;
    }

    return 0;
}

static gint
virtTestDecodeStr(const gchar *input,
                  const gchar *expected)
{
    g_autofree gchar *decoded = virtDBusUtilDecodeStr(input);

    if (!g_str_equal(decoded, expected)) {
        g_printerr("decode failed: expected '%s' actual '%s'\n",
                   expected, decoded);
        return -1;
    }

    return 0;
}

gint
main(void)
{
#define TEST_ENCODE_DECODE(input, output) \
    if (virtTestEncodeStr(input, output) < 0) \
        return EXIT_FAILURE; \
    if (virtTestDecodeStr(output, input) < 0) \
        return EXIT_FAILURE;

    TEST_ENCODE_DECODE("foobar", "foobar");
    TEST_ENCODE_DECODE("_", "_5f");
    TEST_ENCODE_DECODE("/path/to/some/file.img", "_2fpath_2fto_2fsome_2ffile_2eimg");

    return EXIT_SUCCESS;
}