translate-all: fix 'consisits' typo in comment
[qemu/ar7.git] / tests / test-qapi-util.c
blob4b5e4f8bd36be06003036cfac82ea49f8278a623
1 /*
2 * Unit tests for QAPI utility functions
4 * Copyright (C) 2017 Red Hat Inc.
6 * Authors:
7 * Markus Armbruster <armbru@redhat.com>,
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "test-qapi-types.h"
17 static void test_qapi_enum_parse(void)
19 Error *err = NULL;
20 int ret;
22 ret = qapi_enum_parse(&QType_lookup, NULL, QTYPE_NONE, &error_abort);
23 g_assert_cmpint(ret, ==, QTYPE_NONE);
25 ret = qapi_enum_parse(&QType_lookup, "junk", -1, NULL);
26 g_assert_cmpint(ret, ==, -1);
28 ret = qapi_enum_parse(&QType_lookup, "junk", -1, &err);
29 error_free_or_abort(&err);
31 ret = qapi_enum_parse(&QType_lookup, "none", -1, &error_abort);
32 g_assert_cmpint(ret, ==, QTYPE_NONE);
34 ret = qapi_enum_parse(&QType_lookup, QType_str(QTYPE__MAX - 1),
35 QTYPE__MAX - 1, &error_abort);
36 g_assert_cmpint(ret, ==, QTYPE__MAX - 1);
39 static void test_parse_qapi_name(void)
41 int ret;
43 /* Must start with a letter */
44 ret = parse_qapi_name("a", true);
45 g_assert(ret == 1);
46 ret = parse_qapi_name("a$", false);
47 g_assert(ret == 1);
48 ret = parse_qapi_name("", false);
49 g_assert(ret == -1);
50 ret = parse_qapi_name("1", false);
51 g_assert(ret == -1);
53 /* Only letters, digits, hyphen, underscore */
54 ret = parse_qapi_name("A-Za-z0-9_", true);
55 g_assert(ret == 10);
56 ret = parse_qapi_name("A-Za-z0-9_$", false);
57 g_assert(ret == 10);
58 ret = parse_qapi_name("A-Za-z0-9_$", true);
59 g_assert(ret == -1);
61 /* __RFQDN_ */
62 ret = parse_qapi_name("__com.redhat_supports", true);
63 g_assert(ret == 21);
64 ret = parse_qapi_name("_com.example_", false);
65 g_assert(ret == -1);
66 ret = parse_qapi_name("__com.example", false);
67 g_assert(ret == -1);
68 ret = parse_qapi_name("__com.example_", false);
69 g_assert(ret == -1);
72 int main(int argc, char *argv[])
74 g_test_init(&argc, &argv, NULL);
75 g_test_add_func("/qapi/util/qapi_enum_parse", test_qapi_enum_parse);
76 g_test_add_func("/qapi/util/parse_qapi_name", test_parse_qapi_name);
77 g_test_run();
78 return 0;