mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-07 17:50:59 +08:00
qt 6.5.1 original
This commit is contained in:
11
tests/benchmarks/corelib/kernel/qproperty/CMakeLists.txt
Normal file
11
tests/benchmarks/corelib/kernel/qproperty/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
qt_internal_add_benchmark(tst_bench_qproperty
|
||||
SOURCES
|
||||
tst_bench_qproperty.cpp
|
||||
propertytester.h
|
||||
LIBRARIES
|
||||
Qt::Core
|
||||
Qt::Test
|
||||
)
|
58
tests/benchmarks/corelib/kernel/qproperty/propertytester.h
Normal file
58
tests/benchmarks/corelib/kernel/qproperty/propertytester.h
Normal file
@ -0,0 +1,58 @@
|
||||
// Copyright (C) 2021 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#ifndef PROPERTYTESTER_H
|
||||
#define PROPERTYTESTER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QProperty>
|
||||
|
||||
class PropertyTester : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void xOldChanged();
|
||||
void yOldChanged();
|
||||
void xNotifiedChanged();
|
||||
void yNotifiedChanged();
|
||||
|
||||
public:
|
||||
PropertyTester() = default;
|
||||
Q_PROPERTY(int xOld READ xOld WRITE setXOld NOTIFY xOldChanged)
|
||||
Q_PROPERTY(int yOld READ yOld WRITE setYOld NOTIFY yOldChanged)
|
||||
Q_PROPERTY(int x MEMBER x BINDABLE xBindable)
|
||||
Q_PROPERTY(int y MEMBER y BINDABLE yBindable)
|
||||
Q_PROPERTY(int xNotified MEMBER xNotified NOTIFY xNotifiedChanged BINDABLE xNotifiedBindable)
|
||||
Q_PROPERTY(int yNotified MEMBER yNotified NOTIFY yNotifiedChanged BINDABLE yNotifiedBindable)
|
||||
void setXOld(int i) {
|
||||
if (m_xOld != i) {
|
||||
m_xOld = i;
|
||||
emit xOldChanged();
|
||||
}
|
||||
}
|
||||
void setYOld(int i) {
|
||||
if (m_yOld != i) {
|
||||
m_yOld = i;
|
||||
emit yOldChanged();
|
||||
}
|
||||
}
|
||||
int xOld() { return m_xOld; }
|
||||
int yOld() { return m_yOld; }
|
||||
QProperty<int> x;
|
||||
QProperty<int> y;
|
||||
|
||||
QBindable<int> xBindable() { return QBindable<int>(&x); }
|
||||
QBindable<int> yBindable() { return QBindable<int>(&y); }
|
||||
|
||||
Q_OBJECT_BINDABLE_PROPERTY(PropertyTester, int, xNotified, &PropertyTester::xNotifiedChanged)
|
||||
Q_OBJECT_BINDABLE_PROPERTY(PropertyTester, int, yNotified, &PropertyTester::yNotifiedChanged)
|
||||
|
||||
QBindable<int> xNotifiedBindable() { return QBindable<int>(&xNotified); }
|
||||
QBindable<int> yNotifiedBindable() { return QBindable<int>(&yNotified); }
|
||||
|
||||
private:
|
||||
int m_xOld = 0;
|
||||
int m_yOld = 0;
|
||||
};
|
||||
|
||||
#endif // PROPERTYTESTER_H
|
@ -0,0 +1,207 @@
|
||||
// Copyright (C) 2021 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QScopedPointer>
|
||||
#include <QProperty>
|
||||
|
||||
#include <qtest.h>
|
||||
|
||||
#include "propertytester.h"
|
||||
|
||||
class tst_QProperty : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void cppOldBinding();
|
||||
void cppOldBindingReadOnce();
|
||||
void cppOldBindingDirect();
|
||||
void cppOldBindingDirectReadOnce();
|
||||
|
||||
void cppNewBinding();
|
||||
void cppNewBindingReadOnce();
|
||||
void cppNewBindingDirect();
|
||||
void cppNewBindingDirectReadOnce();
|
||||
|
||||
void cppNotifying();
|
||||
void cppNotifyingReadOnce();
|
||||
void cppNotifyingDirect();
|
||||
void cppNotifyingDirectReadOnce();
|
||||
};
|
||||
|
||||
void tst_QProperty::cppOldBinding()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
auto connection = connect(tester.data(), &PropertyTester::xOldChanged,
|
||||
tester.data(), [&]() { tester->setYOld(tester->xOld()); });
|
||||
|
||||
QCOMPARE(tester->property("yOld").toInt(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->setProperty("xOld", ++i);
|
||||
if (tester->property("yOld").toInt() != i)
|
||||
QFAIL("boo");
|
||||
}
|
||||
|
||||
QObject::disconnect(connection);
|
||||
}
|
||||
|
||||
void tst_QProperty::cppOldBindingDirect()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
auto connection = connect(tester.data(), &PropertyTester::xOldChanged,
|
||||
tester.data(), [&]() { tester->setYOld(tester->xOld()); });
|
||||
|
||||
QCOMPARE(tester->yOld(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->setXOld(++i);
|
||||
if (tester->yOld() != i)
|
||||
QFAIL("boo");
|
||||
}
|
||||
|
||||
QObject::disconnect(connection);
|
||||
}
|
||||
|
||||
void tst_QProperty::cppOldBindingReadOnce()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
auto connection = connect(tester.data(), &PropertyTester::xOldChanged,
|
||||
tester.data(), [&]() { tester->setYOld(tester->xOld()); });
|
||||
|
||||
QCOMPARE(tester->property("yOld").toInt(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->setProperty("xOld", ++i);
|
||||
}
|
||||
|
||||
QCOMPARE(tester->property("yOld").toInt(), i);
|
||||
QObject::disconnect(connection);
|
||||
}
|
||||
|
||||
void tst_QProperty::cppOldBindingDirectReadOnce()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
auto connection = connect(tester.data(), &PropertyTester::xOldChanged,
|
||||
tester.data(), [&]() { tester->setYOld(tester->xOld()); });
|
||||
|
||||
QCOMPARE(tester->yOld(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->setXOld(++i);
|
||||
}
|
||||
|
||||
QCOMPARE(tester->yOld(), i);
|
||||
QObject::disconnect(connection);
|
||||
}
|
||||
|
||||
void tst_QProperty::cppNewBinding()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
tester->y.setBinding([&](){return tester->x.value();});
|
||||
|
||||
QCOMPARE(tester->property("y").toInt(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->setProperty("x", ++i);
|
||||
if (tester->property("y").toInt() != i)
|
||||
QFAIL("boo");
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QProperty::cppNewBindingDirect()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
tester->y.setBinding([&](){return tester->x.value();});
|
||||
QCOMPARE(tester->y.value(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->x = ++i;
|
||||
if (tester->y.value() != i)
|
||||
QFAIL("boo");
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QProperty::cppNewBindingReadOnce()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
tester->y.setBinding([&](){return tester->x.value();});
|
||||
|
||||
QCOMPARE(tester->property("y").toInt(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->setProperty("x", ++i);
|
||||
}
|
||||
|
||||
QCOMPARE(tester->property("y").toInt(), i);
|
||||
}
|
||||
|
||||
void tst_QProperty::cppNewBindingDirectReadOnce()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
tester->y.setBinding([&](){return tester->x.value();});
|
||||
QCOMPARE(tester->y.value(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->x = ++i;
|
||||
}
|
||||
|
||||
QCOMPARE(tester->y.value(), i);
|
||||
}
|
||||
|
||||
void tst_QProperty::cppNotifying()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
tester->yNotified.setBinding([&](){return tester->xNotified.value();});
|
||||
|
||||
QCOMPARE(tester->property("yNotified").toInt(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->setProperty("xNotified", ++i);
|
||||
if (tester->property("yNotified").toInt() != i)
|
||||
QFAIL("boo");
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QProperty::cppNotifyingDirect()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
tester->yNotified.setBinding([&](){return tester->xNotified.value();});
|
||||
QCOMPARE(tester->yNotified.value(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->xNotified.setValue(++i);
|
||||
if (tester->yNotified.value() != i)
|
||||
QFAIL("boo");
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QProperty::cppNotifyingReadOnce()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
tester->yNotified.setBinding([&](){return tester->xNotified.value();});
|
||||
|
||||
QCOMPARE(tester->property("yNotified").toInt(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->setProperty("xNotified", ++i);
|
||||
}
|
||||
|
||||
QCOMPARE(tester->property("yNotified").toInt(), i);
|
||||
}
|
||||
|
||||
void tst_QProperty::cppNotifyingDirectReadOnce()
|
||||
{
|
||||
QScopedPointer<PropertyTester> tester {new PropertyTester};
|
||||
tester->yNotified.setBinding([&](){return tester->xNotified.value();});
|
||||
QCOMPARE(tester->yNotified.value(), 0);
|
||||
int i = 0;
|
||||
QBENCHMARK {
|
||||
tester->xNotified.setValue(++i);
|
||||
}
|
||||
|
||||
QCOMPARE(tester->yNotified.value(), i);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QProperty)
|
||||
|
||||
#include "tst_bench_qproperty.moc"
|
Reference in New Issue
Block a user