Пример #1
0
static void qobject_is_equal_num_test(void)
{
    QNum *u0, *i0, *d0, *dnan, *um42, *im42, *dm42;

    u0 = qnum_from_uint(0u);
    i0 = qnum_from_int(0);
    d0 = qnum_from_double(0.0);
    dnan = qnum_from_double(NAN);
    um42 = qnum_from_uint((uint64_t)-42);
    im42 = qnum_from_int(-42);
    dm42 = qnum_from_double(-42.0);

    /* Integers representing a mathematically equal number should
     * compare equal */
    check_equal(u0, i0);
    /* Doubles, however, are always unequal to integers */
    check_unequal(u0, d0);
    check_unequal(i0, d0);

    /* Do not assume any object is equal to itself -- note however
     * that NaN cannot occur in a JSON object anyway. */
    g_assert(qobject_is_equal(QOBJECT(dnan), QOBJECT(dnan)) == false);

    /* No unsigned overflow */
    check_unequal(um42, im42);
    check_unequal(um42, dm42);
    check_unequal(im42, dm42);

    free_all(u0, i0, d0, dnan, um42, im42, dm42);
}
Пример #2
0
static void qobject_is_equal_conversion_test(void)
{
    QNum *u0, *i0, *d0;
    QString *s0, *s_empty;
    QBool *bfalse;

    u0 = qnum_from_uint(0u);
    i0 = qnum_from_int(0);
    d0 = qnum_from_double(0.0);
    s0 = qstring_from_str("0");
    s_empty = qstring_new();
    bfalse = qbool_from_bool(false);

    /* No automatic type conversion */
    check_unequal(u0, s0, s_empty, bfalse, qnull(), NULL);
    check_unequal(i0, s0, s_empty, bfalse, qnull(), NULL);
    check_unequal(d0, s0, s_empty, bfalse, qnull(), NULL);

    free_all(u0, i0, d0, s0, s_empty, bfalse);
}
Пример #3
0
static void qobject_is_equal_bool_test(void)
{
    QBool *btrue_0, *btrue_1, *bfalse_0, *bfalse_1;

    btrue_0 = qbool_from_bool(true);
    btrue_1 = qbool_from_bool(true);
    bfalse_0 = qbool_from_bool(false);
    bfalse_1 = qbool_from_bool(false);

    check_equal(btrue_0, btrue_1);
    check_equal(bfalse_0, bfalse_1);
    check_unequal(btrue_0, bfalse_0);

    free_all(btrue_0, btrue_1, bfalse_0, bfalse_1);
}
Пример #4
0
void test_converting_ctor()
{
    stl::string text = "test message";
    any value (text);

    check_false(value.empty(), "empty");
    check_equal(value.type(), typeid(stl::string), "type");
    check_null(any_cast<int>(&value), "any_cast<int>");
    check_non_null(any_cast<stl::string>(&value), "any_cast<stl::string>");
    check_equal(
        any_cast<stl::string>(value), text,
        "comparing cast copy against original text");
    check_unequal(
        any_cast<stl::string>(&value), &text,
        "comparing address in copy against original text");
}
Пример #5
0
void test_copy_ctor()
{
    stl::string text = "test message";
    any original (text), copy = original.clone ();

    check_false(copy.empty(), "empty");
    check_equal(original.type(), copy.type(), "type");
    check_equal(
        any_cast<stl::string>(original), any_cast<stl::string>(copy),
        "comparing cast copy against original");
    check_equal(
        text, any_cast<stl::string>(copy),
        "comparing cast copy against original text");
    check_unequal(
        any_cast<stl::string>(&original),
        any_cast<stl::string>(&copy),
        "comparing address in copy against original");
}
Пример #6
0
static void qobject_is_equal_list_test(void)
{
    QList *list_0, *list_1, *list_cloned;
    QList *list_reordered, *list_longer, *list_shorter;

    list_0 = qlist_new();
    list_1 = qlist_new();
    list_reordered = qlist_new();
    list_longer = qlist_new();
    list_shorter = qlist_new();

    qlist_append_int(list_0, 1);
    qlist_append_int(list_0, 2);
    qlist_append_int(list_0, 3);

    qlist_append_int(list_1, 1);
    qlist_append_int(list_1, 2);
    qlist_append_int(list_1, 3);

    qlist_append_int(list_reordered, 1);
    qlist_append_int(list_reordered, 3);
    qlist_append_int(list_reordered, 2);

    qlist_append_int(list_longer, 1);
    qlist_append_int(list_longer, 2);
    qlist_append_int(list_longer, 3);
    qlist_append_null(list_longer);

    qlist_append_int(list_shorter, 1);
    qlist_append_int(list_shorter, 2);

    list_cloned = qlist_copy(list_0);

    check_equal(list_0, list_1, list_cloned);
    check_unequal(list_0, list_reordered, list_longer, list_shorter);

    /* With a NaN in it, the list should no longer compare equal to
     * itself */
    qlist_append(list_0, qnum_from_double(NAN));
    g_assert(qobject_is_equal(QOBJECT(list_0), QOBJECT(list_0)) == false);

    free_all(list_0, list_1, list_cloned, list_reordered, list_longer,
             list_shorter);
}
Пример #7
0
void test_converting_assign()
{
    stl::string text = "test message";
    any value;
    any * assign_result = &(value = text);

    check_false(value.empty(), "type");
    check_equal(value.type(), typeid(stl::string), "type");
    check_null(any_cast<int>(&value), "any_cast<int>");
    check_non_null(any_cast<stl::string>(&value), "any_cast<stl::string>");
    check_equal(
        any_cast<stl::string>(value), text,
        "comparing cast copy against original text");
    check_unequal(
        any_cast<stl::string>(&value),
        &text,
        "comparing address in copy against original text");
    check_equal(assign_result, &value, "address of assignment result");
}
Пример #8
0
void test_copy_assign()
{
    stl::string text = "test message";
    any original (text), copy;
    any * assign_result = &(copy = original.clone ());

    check_false(copy.empty(), "empty");
    check_equal(original.type(), copy.type(), "type");
    check_equal(
        any_cast<stl::string>(original), any_cast<stl::string>(copy),
        "comparing cast copy against cast original");
    check_equal(
        text, any_cast<stl::string>(copy),
        "comparing cast copy against original text");
    check_unequal(
        any_cast<stl::string>(&original),
        any_cast<stl::string>(&copy),
        "comparing address in copy against original");
    check_equal(assign_result, &copy, "address of assignment result");
}
Пример #9
0
static void qobject_is_equal_string_test(void)
{
    QString *str_base, *str_whitespace_0, *str_whitespace_1, *str_whitespace_2;
    QString *str_whitespace_3, *str_case, *str_built;

    str_base = qstring_from_str("foo");
    str_whitespace_0 = qstring_from_str(" foo");
    str_whitespace_1 = qstring_from_str("foo ");
    str_whitespace_2 = qstring_from_str("foo\b");
    str_whitespace_3 = qstring_from_str("fooo\b");
    str_case = qstring_from_str("Foo");

    /* Should yield "foo" */
    str_built = qstring_from_substr("form", 0, 1);
    qstring_append_chr(str_built, 'o');

    check_unequal(str_base, str_whitespace_0, str_whitespace_1,
                  str_whitespace_2, str_whitespace_3, str_case);

    check_equal(str_base, str_built);

    free_all(str_base, str_whitespace_0, str_whitespace_1, str_whitespace_2,
             str_whitespace_3, str_case, str_built);
}
Пример #10
0
static void qobject_is_equal_null_test(void)
{
    check_unequal(qnull(), NULL);
}
Пример #11
0
static void qobject_is_equal_dict_test(void)
{
    Error *local_err = NULL;
    QDict *dict_0, *dict_1, *dict_cloned;
    QDict *dict_different_key, *dict_different_value, *dict_different_null_key;
    QDict *dict_longer, *dict_shorter, *dict_nested;
    QDict *dict_crumpled;

    dict_0 = qdict_new();
    dict_1 = qdict_new();
    dict_different_key = qdict_new();
    dict_different_value = qdict_new();
    dict_different_null_key = qdict_new();
    dict_longer = qdict_new();
    dict_shorter = qdict_new();
    dict_nested = qdict_new();

    qdict_put_int(dict_0, "f.o", 1);
    qdict_put_int(dict_0, "bar", 2);
    qdict_put_int(dict_0, "baz", 3);
    qdict_put_null(dict_0, "null");

    qdict_put_int(dict_1, "f.o", 1);
    qdict_put_int(dict_1, "bar", 2);
    qdict_put_int(dict_1, "baz", 3);
    qdict_put_null(dict_1, "null");

    qdict_put_int(dict_different_key, "F.o", 1);
    qdict_put_int(dict_different_key, "bar", 2);
    qdict_put_int(dict_different_key, "baz", 3);
    qdict_put_null(dict_different_key, "null");

    qdict_put_int(dict_different_value, "f.o", 42);
    qdict_put_int(dict_different_value, "bar", 2);
    qdict_put_int(dict_different_value, "baz", 3);
    qdict_put_null(dict_different_value, "null");

    qdict_put_int(dict_different_null_key, "f.o", 1);
    qdict_put_int(dict_different_null_key, "bar", 2);
    qdict_put_int(dict_different_null_key, "baz", 3);
    qdict_put_null(dict_different_null_key, "none");

    qdict_put_int(dict_longer, "f.o", 1);
    qdict_put_int(dict_longer, "bar", 2);
    qdict_put_int(dict_longer, "baz", 3);
    qdict_put_int(dict_longer, "xyz", 4);
    qdict_put_null(dict_longer, "null");

    qdict_put_int(dict_shorter, "f.o", 1);
    qdict_put_int(dict_shorter, "bar", 2);
    qdict_put_int(dict_shorter, "baz", 3);

    qdict_put(dict_nested, "f", qdict_new());
    qdict_put_int(qdict_get_qdict(dict_nested, "f"), "o", 1);
    qdict_put_int(dict_nested, "bar", 2);
    qdict_put_int(dict_nested, "baz", 3);
    qdict_put_null(dict_nested, "null");

    dict_cloned = qdict_clone_shallow(dict_0);

    check_equal(dict_0, dict_1, dict_cloned);
    check_unequal(dict_0, dict_different_key, dict_different_value,
                  dict_different_null_key, dict_longer, dict_shorter,
                  dict_nested);

    dict_crumpled = qobject_to(QDict, qdict_crumple(dict_1, &local_err));
    g_assert(!local_err);
    check_equal(dict_crumpled, dict_nested);

    qdict_flatten(dict_nested);
    check_equal(dict_0, dict_nested);

    /* Containing an NaN value will make this dict compare unequal to
     * itself */
    qdict_put(dict_0, "NaN", qnum_from_double(NAN));
    g_assert(qobject_is_equal(QOBJECT(dict_0), QOBJECT(dict_0)) == false);

    free_all(dict_0, dict_1, dict_cloned, dict_different_key,
             dict_different_value, dict_different_null_key, dict_longer,
             dict_shorter, dict_nested, dict_crumpled);
}