*/
#include "qemu/osdep.h"
-#include "qemu/cutils.h"
+#include "qemu/units.h"
#include "qemu/option.h"
#include "qemu/option_int.h"
#include "qapi/error.h"
{
Error *err = NULL;
QemuOpts *opts;
- char long_key[129];
- char *params;
/* Nothing */
opts = qemu_opts_parse(&opts_list_03, "", false, &error_abort);
g_assert_cmpuint(opts_count(opts), ==, 1);
g_assert_cmpstr(qemu_opt_get(opts, ""), ==, "val");
- /* Long key */
- memset(long_key, 'a', 127);
- long_key[127] = 'z';
- long_key[128] = 0;
- params = g_strdup_printf("%s=v", long_key);
- opts = qemu_opts_parse(&opts_list_03, params + 1, NULL, &error_abort);
- g_assert_cmpuint(opts_count(opts), ==, 1);
- g_assert_cmpstr(qemu_opt_get(opts, long_key + 1), ==, "v");
-
- /* Overlong key gets truncated */
- opts = qemu_opts_parse(&opts_list_03, params, NULL, &error_abort);
- g_assert(opts_count(opts) == 1);
- long_key[127] = 0;
- g_assert_cmpstr(qemu_opt_get(opts, long_key), ==, "v");
- g_free(params);
-
/* Multiple keys, last one wins */
opts = qemu_opts_parse(&opts_list_03, "a=1,b=2,,x,a=3",
false, &error_abort);
g_assert(!opts);
/* TODO Cover .merge_lists = true */
- /* Buggy ID recognition */
+ /* Buggy ID recognition (fixed) */
opts = qemu_opts_parse(&opts_list_03, "x=,,id=bar", false, &error_abort);
g_assert_cmpuint(opts_count(opts), ==, 1);
- g_assert_cmpstr(qemu_opts_id(opts), ==, "bar"); /* BUG */
+ g_assert(!qemu_opts_id(opts));
g_assert_cmpstr(qemu_opt_get(opts, "x"), ==, ",id=bar");
/* Anti-social ID */
g_assert_cmpuint(opts_count(opts), ==, 3);
g_assert_cmphex(qemu_opt_get_size(opts, "size1", 0), ==, 8);
g_assert_cmphex(qemu_opt_get_size(opts, "size2", 0), ==, 1536);
- g_assert_cmphex(qemu_opt_get_size(opts, "size3", 0), ==, 2 * M_BYTE);
+ g_assert_cmphex(qemu_opt_get_size(opts, "size3", 0), ==, 2 * MiB);
opts = qemu_opts_parse(&opts_list_02, "size1=0.1G,size2=16777215T",
false, &error_abort);
g_assert_cmpuint(opts_count(opts), ==, 2);
- g_assert_cmphex(qemu_opt_get_size(opts, "size1", 0), ==, G_BYTE / 10);
- g_assert_cmphex(qemu_opt_get_size(opts, "size2", 0),
- ==, 16777215 * T_BYTE);
+ g_assert_cmphex(qemu_opt_get_size(opts, "size1", 0), ==, GiB / 10);
+ g_assert_cmphex(qemu_opt_get_size(opts, "size2", 0), ==, 16777215ULL * TiB);
/* Beyond limit with suffix */
opts = qemu_opts_parse(&opts_list_02, "size1=16777216T",
qemu_opts_reset(&opts_list_02);
}
+static void test_has_help_option(void)
+{
+ static const struct {
+ const char *params;
+ /* expected value of qemu_opt_has_help_opt() with implied=false */
+ bool expect;
+ /* expected value of qemu_opt_has_help_opt() with implied=true */
+ bool expect_implied;
+ } test[] = {
+ { "help", true, false },
+ { "?", true, false },
+ { "helpme", false, false },
+ { "?me", false, false },
+ { "a,help", true, true },
+ { "a,?", true, true },
+ { "a=0,help,b", true, true },
+ { "a=0,?,b", true, true },
+ { "help,b=1", true, false },
+ { "?,b=1", true, false },
+ { "a,b,,help", true, true },
+ { "a,b,,?", true, true },
+ };
+ int i;
+ QemuOpts *opts;
+
+ for (i = 0; i < ARRAY_SIZE(test); i++) {
+ g_assert_cmpint(has_help_option(test[i].params),
+ ==, test[i].expect);
+ opts = qemu_opts_parse(&opts_list_03, test[i].params, false,
+ &error_abort);
+ g_assert_cmpint(qemu_opt_has_help_opt(opts),
+ ==, test[i].expect);
+ qemu_opts_del(opts);
+ opts = qemu_opts_parse(&opts_list_03, test[i].params, true,
+ &error_abort);
+ g_assert_cmpint(qemu_opt_has_help_opt(opts),
+ ==, test[i].expect_implied);
+ qemu_opts_del(opts);
+ }
+}
+
static void append_verify_list_01(QemuOptDesc *desc, bool with_overlapping)
{
int i = 0;
g_assert_cmpstr(qdict_get_str(dict, "number1"), ==, "42");
g_assert_false(qdict_haskey(dict, "number2"));
- QDECREF(dict);
+ qobject_unref(dict);
qemu_opts_del(opts);
}
g_assert_cmpstr(qdict_get_str(dict, "number1"), ==, "42");
g_assert_false(qdict_haskey(dict, "number2"));
g_assert_false(qdict_haskey(dict, "bool1"));
- QDECREF(dict);
+ qobject_unref(dict);
dict = qemu_opts_to_qdict_filtered(opts, NULL, &opts_list_02, false);
g_assert(dict != NULL);
g_assert_false(qdict_haskey(dict, "str3"));
g_assert_false(qdict_haskey(dict, "number1"));
g_assert_false(qdict_haskey(dict, "number2"));
- QDECREF(dict);
+ qobject_unref(dict);
/* Now delete converted options from opts */
dict = qemu_opts_to_qdict_filtered(opts, NULL, &opts_list_01, true);
g_assert_cmpstr(qdict_get_str(dict, "number1"), ==, "42");
g_assert_false(qdict_haskey(dict, "number2"));
g_assert_false(qdict_haskey(dict, "bool1"));
- QDECREF(dict);
+ qobject_unref(dict);
dict = qemu_opts_to_qdict_filtered(opts, NULL, &opts_list_02, true);
g_assert(dict != NULL);
g_assert_false(qdict_haskey(dict, "str3"));
g_assert_false(qdict_haskey(dict, "number1"));
g_assert_false(qdict_haskey(dict, "number2"));
- QDECREF(dict);
+ qobject_unref(dict);
g_assert_true(QTAILQ_EMPTY(&opts->head));
dict = qemu_opts_to_qdict(opts, NULL);
g_assert(dict != NULL);
g_assert_cmpstr(qdict_get_str(dict, "foo"), ==, "b");
- QDECREF(dict);
+ qobject_unref(dict);
/* The last one still wins if entries are deleted, and both are deleted */
dict = qemu_opts_to_qdict_filtered(opts, NULL, NULL, true);
g_assert(dict != NULL);
g_assert_cmpstr(qdict_get_str(dict, "foo"), ==, "b");
- QDECREF(dict);
+ qobject_unref(dict);
g_assert_true(QTAILQ_EMPTY(&opts->head));
g_test_add_func("/qemu-opts/opts_parse/bool", test_opts_parse_bool);
g_test_add_func("/qemu-opts/opts_parse/number", test_opts_parse_number);
g_test_add_func("/qemu-opts/opts_parse/size", test_opts_parse_size);
+ g_test_add_func("/qemu-opts/has_help_option", test_has_help_option);
g_test_add_func("/qemu-opts/append_to_null", test_opts_append_to_null);
g_test_add_func("/qemu-opts/append", test_opts_append);
g_test_add_func("/qemu-opts/to_qdict/basic", test_opts_to_qdict_basic);