File: ut_dobjectmodelproxy.cpp

package info (click to toggle)
dtkdeclarative 5.7.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 29,848 kB
  • sloc: cpp: 20,566; ansic: 66; makefile: 29; sh: 25
file content (64 lines) | stat: -rw-r--r-- 1,563 bytes parent folder | download
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <gtest/gtest.h>

#include "test_helper.hpp"

#include <QTest>
#include <QQuickItem>
#include <QSignalSpy>

#include "dobjectmodelproxy_p.h"
DQUICK_USE_NAMESPACE

class ut_ObjectModelProxy : public ::testing::Test
{
public:
    virtual void SetUp()
    {
        ASSERT_TRUE(helper.load("qrc:/qml/ObjectModelProxy.qml"));
        root = helper.object;

        target = helper.object->property("model").value<ObjectModelProxy *>();
        ASSERT_TRUE(target);
    }

    ControlHelper<QQuickItem> helper;
    QQuickItem *root = nullptr;
    ObjectModelProxy *target = nullptr;
};

TEST_F(ut_ObjectModelProxy, properties)
{
    EXPECT_EQ(target->count(), 3);
}

TEST_F(ut_ObjectModelProxy, filterAcceptsItem)
{
    EXPECT_EQ(root->property("count").toInt(), 3);
    root->setProperty("filterText", "Page2");
    target->update();
    ASSERT_EQ(root->property("count").toInt(), 1);

    root->setProperty("filterText", "");
    target->update();
    EXPECT_EQ(root->property("count").toInt(), 3);
}

TEST_F(ut_ObjectModelProxy, mappingWithSource)
{
    root->setProperty("filterText", "Page2");
    target->update();
    ASSERT_EQ(root->property("count").toInt(), 1);

    auto object1 = target->get(0);
    ASSERT_TRUE(object1);
    ASSERT_EQ(object1->property("text"), "Page2");

    auto sourceIndex1 = target->mapToSource(0);
    ASSERT_EQ(sourceIndex1, 1);
    auto index1 = target->mapFromSource(1);
    ASSERT_EQ(index1, 0);
}