mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Consider QObject could be null in CSlot
This commit is contained in:
@@ -62,13 +62,13 @@ namespace BlackMisc
|
||||
//! True if the slot can be called, false if it is empty.
|
||||
operator bool() const
|
||||
{
|
||||
return !this->isEmpty();
|
||||
return !this->isEmpty() && !this->hasNullObject();
|
||||
}
|
||||
|
||||
//! True if the slot is empty, false if it can be called.
|
||||
//! True if the slot is empty or object is null, false if it can be called.
|
||||
bool operator !() const
|
||||
{
|
||||
return this->isEmpty();
|
||||
return this->isEmpty() || this->hasNullObject();
|
||||
}
|
||||
|
||||
//! True if the slot is empty, false if it can be called.
|
||||
@@ -77,6 +77,12 @@ namespace BlackMisc
|
||||
return ! m_function;
|
||||
}
|
||||
|
||||
//! True if the object is null
|
||||
bool hasNullObject() const
|
||||
{
|
||||
return m_object.isNull();
|
||||
}
|
||||
|
||||
private:
|
||||
QPointer<QObject> m_object;
|
||||
std::function<R(Args...)> m_function;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "testlibrarypath.h"
|
||||
#include "testmath.h"
|
||||
#include "testphysicalquantities.h"
|
||||
#include "testslot.h"
|
||||
#include "testvaluecache.h"
|
||||
#include "testvariantandmap.h"
|
||||
#include "testweather.h"
|
||||
@@ -45,6 +46,7 @@ namespace BlackMiscTest
|
||||
CTestVariantAndMap variantAndMap;
|
||||
CTestInput inputTests;
|
||||
CTestIdentifier identifierTests;
|
||||
CTestSlot slotTests;
|
||||
CTestValueCache valueCacheTests;
|
||||
CTestWeather weatherTests;
|
||||
CTestMath mathTests;
|
||||
@@ -56,6 +58,7 @@ namespace BlackMiscTest
|
||||
status |= QTest::qExec(&containerTests, argc, argv);
|
||||
status |= QTest::qExec(&variantAndMap, argc, argv);
|
||||
status |= QTest::qExec(&inputTests, argc, argv);
|
||||
status |= QTest::qExec(&slotTests, argc, argv);
|
||||
status |= QTest::qExec(&valueCacheTests, argc, argv);
|
||||
status |= QTest::qExec(&weatherTests, argc, argv);
|
||||
status |= QTest::qExec(&mathTests, argc, argv);
|
||||
|
||||
42
tests/blackmisc/testslot.cpp
Normal file
42
tests/blackmisc/testslot.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \cond PRIVATE_TESTS
|
||||
|
||||
/*!
|
||||
* \file
|
||||
* \ingroup testblackmisc
|
||||
*/
|
||||
|
||||
#include "testslot.h"
|
||||
#include "blackmisc/slot.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
|
||||
void CTestSlot::slotBasics()
|
||||
{
|
||||
QObject *obj = new QObject(this);
|
||||
CSlot<void(const QString &)> slot1 = { obj, &QObject::setObjectName };
|
||||
QVERIFY2(slot1, "Slot has valid object and function - can be called.");
|
||||
|
||||
CSlot<void(const QString &)> slot2 = { static_cast<QObject*>(nullptr), &QObject::setObjectName };
|
||||
QVERIFY2(!slot2, "Slot has an invalid pointer - cannot be called.");
|
||||
|
||||
CSlot<void(const QString &)> slot3;
|
||||
QVERIFY2(!slot3, "Slot has an invalid pointer and invalid function - cannot be called.");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
//! \endcond
|
||||
43
tests/blackmisc/testslot.h
Normal file
43
tests/blackmisc/testslot.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project community / contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef BLACKMISCTEST_TESTSLOT_H
|
||||
#define BLACKMISCTEST_TESTSLOT_H
|
||||
|
||||
//! \cond PRIVATE_TESTS
|
||||
|
||||
/*!
|
||||
* \file
|
||||
* \ingroup testblackmisc
|
||||
*/
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
|
||||
//! CSlot tests
|
||||
class CTestSlot : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Standard test case constructor
|
||||
explicit CTestSlot(QObject *parent = nullptr) : QObject(parent) {}
|
||||
|
||||
private slots:
|
||||
//! Basic unit tests for CSlot
|
||||
void slotBasics();
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
//! \endcond
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user