本文整理汇总了C++中qdict_new函数的典型用法代码示例。如果您正苦于以下问题:C++ qdict_new函数的具体用法?C++ qdict_new怎么用?C++ qdict_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qdict_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qdict_haskey_test
static void qdict_haskey_test(void)
{
const char *key = "test";
QDict *tests_dict = qdict_new();
qdict_put(tests_dict, key, qint_from_int(0));
g_assert(qdict_haskey(tests_dict, key) == 1);
QDECREF(tests_dict);
}
示例2: qdict_array_entries_test
static void qdict_array_entries_test(void)
{
QDict *dict = qdict_new();
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0);
qdict_put_int(dict, "bar", 0);
qdict_put_int(dict, "baz.0", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0);
qdict_put_int(dict, "foo.1", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL);
qdict_put_int(dict, "foo.0", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 2);
qdict_put_int(dict, "foo.bar", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL);
qdict_del(dict, "foo.bar");
qdict_put_int(dict, "foo.2.a", 0);
qdict_put_int(dict, "foo.2.b", 0);
qdict_put_int(dict, "foo.2.c", 0);
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 3);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
qobject_unref(dict);
dict = qdict_new();
qdict_put_int(dict, "1", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
qdict_put_int(dict, "0", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, 2);
qdict_put_int(dict, "bar", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
qdict_del(dict, "bar");
qdict_put_int(dict, "2.a", 0);
qdict_put_int(dict, "2.b", 0);
qdict_put_int(dict, "2.c", 0);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, 3);
qobject_unref(dict);
}
示例3: test_event_d
/* Complex type */
static void test_event_d(TestEventData *data,
const void *unused)
{
UserDefOne struct1;
EventStructOne a;
QDict *d, *d_data, *d_a, *d_struct1;
struct1.integer = 2;
struct1.string = g_strdup("test1");
struct1.has_enum1 = true;
struct1.enum1 = ENUM_ONE_VALUE1;
a.struct1 = &struct1;
a.string = g_strdup("test2");
a.has_enum2 = true;
a.enum2 = ENUM_ONE_VALUE2;
d_struct1 = qdict_new();
qdict_put(d_struct1, "integer", qint_from_int(2));
qdict_put(d_struct1, "string", qstring_from_str("test1"));
qdict_put(d_struct1, "enum1", qstring_from_str("value1"));
d_a = qdict_new();
qdict_put(d_a, "struct1", d_struct1);
qdict_put(d_a, "string", qstring_from_str("test2"));
qdict_put(d_a, "enum2", qstring_from_str("value2"));
d_data = qdict_new();
qdict_put(d_data, "a", d_a);
qdict_put(d_data, "b", qstring_from_str("test3"));
qdict_put(d_data, "enum3", qstring_from_str("value3"));
d = data->expect;
qdict_put(d, "event", qstring_from_str("EVENT_D"));
qdict_put(d, "data", d_data);
qapi_event_send_event_d(&a, "test3", false, NULL, true, ENUM_ONE_VALUE3,
&error_abort);
g_free(struct1.string);
g_free(a.string);
}
示例4: qdict_array_entries_test
static void qdict_array_entries_test(void)
{
QDict *dict = qdict_new();
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0);
qdict_put(dict, "bar", qint_from_int(0));
qdict_put(dict, "baz.0", qint_from_int(0));
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 0);
qdict_put(dict, "foo.1", qint_from_int(0));
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL);
qdict_put(dict, "foo.0", qint_from_int(0));
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 2);
qdict_put(dict, "foo.bar", qint_from_int(0));
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, -EINVAL);
qdict_del(dict, "foo.bar");
qdict_put(dict, "foo.2.a", qint_from_int(0));
qdict_put(dict, "foo.2.b", qint_from_int(0));
qdict_put(dict, "foo.2.c", qint_from_int(0));
g_assert_cmpint(qdict_array_entries(dict, "foo."), ==, 3);
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
QDECREF(dict);
dict = qdict_new();
qdict_put(dict, "1", qint_from_int(0));
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
qdict_put(dict, "0", qint_from_int(0));
g_assert_cmpint(qdict_array_entries(dict, ""), ==, 2);
qdict_put(dict, "bar", qint_from_int(0));
g_assert_cmpint(qdict_array_entries(dict, ""), ==, -EINVAL);
qdict_del(dict, "bar");
qdict_put(dict, "2.a", qint_from_int(0));
qdict_put(dict, "2.b", qint_from_int(0));
qdict_put(dict, "2.c", qint_from_int(0));
g_assert_cmpint(qdict_array_entries(dict, ""), ==, 3);
QDECREF(dict);
}
示例5: qdict_defaults_test
static void qdict_defaults_test(void)
{
QDict *dict, *copy;
dict = qdict_new();
copy = qdict_new();
qdict_set_default_str(dict, "foo", "abc");
qdict_set_default_str(dict, "foo", "def");
g_assert_cmpstr(qdict_get_str(dict, "foo"), ==, "abc");
qdict_set_default_str(dict, "bar", "ghi");
qdict_copy_default(copy, dict, "foo");
g_assert_cmpstr(qdict_get_str(copy, "foo"), ==, "abc");
qdict_set_default_str(copy, "bar", "xyz");
qdict_copy_default(copy, dict, "bar");
g_assert_cmpstr(qdict_get_str(copy, "bar"), ==, "xyz");
QDECREF(copy);
QDECREF(dict);
}
示例6: qdict_crumple_test_bad_inputs
static void qdict_crumple_test_bad_inputs(void)
{
QDict *src;
Error *error = NULL;
src = qdict_new();
/* rule.0 can't be both a string and a dict */
qdict_put(src, "rule.0", qstring_from_str("fred"));
qdict_put(src, "rule.0.policy", qstring_from_str("allow"));
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
error_free(error);
error = NULL;
QDECREF(src);
src = qdict_new();
/* rule can't be both a list and a dict */
qdict_put(src, "rule.0", qstring_from_str("fred"));
qdict_put(src, "rule.a", qstring_from_str("allow"));
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
error_free(error);
error = NULL;
QDECREF(src);
src = qdict_new();
/* The input should be flat, ie no dicts or lists */
qdict_put(src, "rule.a", qdict_new());
qdict_put(src, "rule.b", qstring_from_str("allow"));
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
error_free(error);
error = NULL;
QDECREF(src);
src = qdict_new();
/* List indexes must not have gaps */
qdict_put(src, "rule.0", qstring_from_str("deny"));
qdict_put(src, "rule.3", qstring_from_str("allow"));
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
error_free(error);
error = NULL;
QDECREF(src);
src = qdict_new();
/* List indexes must be in %zu format */
qdict_put(src, "rule.0", qstring_from_str("deny"));
qdict_put(src, "rule.+1", qstring_from_str("allow"));
g_assert(qdict_crumple(src, &error) == NULL);
g_assert(error != NULL);
error_free(error);
error = NULL;
QDECREF(src);
}
示例7: ssh_create
static int ssh_create(const char *filename, QemuOpts *opts, Error **errp)
{
int r, ret;
int64_t total_size = 0;
QDict *uri_options = NULL;
BDRVSSHState s;
ssize_t r2;
char c[1] = { '\0' };
ssh_state_init(&s);
/* Get desired file size. */
total_size = ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0),
BDRV_SECTOR_SIZE);
DPRINTF("total_size=%" PRIi64, total_size);
uri_options = qdict_new();
r = parse_uri(filename, uri_options, errp);
if (r < 0) {
ret = r;
goto out;
}
r = connect_to_ssh(&s, uri_options,
LIBSSH2_FXF_READ|LIBSSH2_FXF_WRITE|
LIBSSH2_FXF_CREAT|LIBSSH2_FXF_TRUNC,
0644, errp);
if (r < 0) {
ret = r;
goto out;
}
if (total_size > 0) {
libssh2_sftp_seek64(s.sftp_handle, total_size-1);
r2 = libssh2_sftp_write(s.sftp_handle, c, 1);
if (r2 < 0) {
sftp_error_setg(errp, &s, "truncate failed");
ret = -EINVAL;
goto out;
}
s.attrs.filesize = total_size;
}
ret = 0;
out:
ssh_state_free(&s);
if (uri_options != NULL) {
QDECREF(uri_options);
}
return ret;
}
示例8: qdict_crumple_test_empty
static void qdict_crumple_test_empty(void)
{
QDict *src, *dst;
src = qdict_new();
dst = (QDict *)qdict_crumple(src, &error_abort);
g_assert_cmpint(qdict_size(dst), ==, 0);
QDECREF(src);
QDECREF(dst);
}
示例9: qdict_new_test
static void qdict_new_test(void)
{
QDict *qdict;
qdict = qdict_new();
g_assert(qdict != NULL);
g_assert(qdict_size(qdict) == 0);
g_assert(qdict->base.refcnt == 1);
g_assert(qobject_type(QOBJECT(qdict)) == QTYPE_QDICT);
// destroy doesn't exit yet
g_free(qdict);
}
示例10: qdict_crumple_test_empty
static void qdict_crumple_test_empty(void)
{
QDict *src, *dst;
src = qdict_new();
dst = qobject_to(QDict, qdict_crumple(src, &error_abort));
g_assert_cmpint(qdict_size(dst), ==, 0);
qobject_unref(src);
qobject_unref(dst);
}
示例11: test_dispatch_cmd
/* test commands with no input and no return value */
static void test_dispatch_cmd(void)
{
QDict *req = qdict_new();
QDict *resp;
qdict_put_str(req, "execute", "user_def_cmd");
resp = qmp_dispatch(&qmp_commands, QOBJECT(req), false);
assert(resp != NULL);
assert(!qdict_haskey(resp, "error"));
qobject_unref(resp);
qobject_unref(req);
}
示例12: test_dispatch_cmd
/* test commands with no input and no return value */
static void test_dispatch_cmd(void)
{
QDict *req = qdict_new();
QObject *resp;
qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd")));
resp = qmp_dispatch(&qmp_commands, QOBJECT(req));
assert(resp != NULL);
assert(!qdict_haskey(qobject_to_qdict(resp), "error"));
qobject_decref(resp);
QDECREF(req);
}
示例13: iscsi_create
static int iscsi_create(const char *filename, QEMUOptionParameter *options)
{
int ret = 0;
int64_t total_size = 0;
BlockDriverState bs;
IscsiLun *iscsilun = NULL;
QDict *bs_options;
memset(&bs, 0, sizeof(BlockDriverState));
/* Read out options */
while (options && options->name) {
if (!strcmp(options->name, "size")) {
total_size = options->value.n / BDRV_SECTOR_SIZE;
}
options++;
}
bs.opaque = g_malloc0(sizeof(struct IscsiLun));
iscsilun = bs.opaque;
bs_options = qdict_new();
qdict_put(bs_options, "filename", qstring_from_str(filename));
ret = iscsi_open(&bs, bs_options, 0);
QDECREF(bs_options);
if (ret != 0) {
goto out;
}
if (iscsilun->nop_timer) {
qemu_del_timer(iscsilun->nop_timer);
qemu_free_timer(iscsilun->nop_timer);
}
if (iscsilun->type != TYPE_DISK) {
ret = -ENODEV;
goto out;
}
if (bs.total_sectors < total_size) {
ret = -ENOSPC;
goto out;
}
ret = 0;
out:
if (iscsilun->iscsi != NULL) {
iscsi_destroy_context(iscsilun->iscsi);
}
g_free(bs.opaque);
return ret;
}
示例14: qdict_get_int_test
static void qdict_get_int_test(void)
{
int ret;
const int value = 100;
const char *key = "int";
QDict *tests_dict = qdict_new();
qdict_put(tests_dict, key, qint_from_int(value));
ret = qdict_get_int(tests_dict, key);
g_assert(ret == value);
QDECREF(tests_dict);
}
示例15: test_dispatch_cmd_error
/* test commands that return an error due to invalid parameters */
static void test_dispatch_cmd_error(void)
{
QDict *req = qdict_new();
QObject *resp;
qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2")));
resp = qmp_dispatch(QOBJECT(req));
assert(resp != NULL);
assert(qdict_haskey(qobject_to_qdict(resp), "error"));
g_print("\nresp: %s\n", qstring_get_str(qobject_to_json_pretty(resp)));
qobject_decref(resp);
QDECREF(req);
}