Remove the private -> public definition from protobuf internals test

Access the private member functions using the QObject::property
interface. In general this is the puprose of this test, to ensure
that QObject::property does the expected initializations.

Pick-to: 6.5 6.6 6.7
Fixes: QTBUG-125355
Change-Id: I2072b378c3c8de136b5ea8b9ddc31fcd53534e10
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Alexey Edelev 2024-05-15 14:10:36 +02:00
parent 0dbc5bbe05
commit ed9b23bffd
1 changed files with 7 additions and 9 deletions

View File

@ -1,11 +1,7 @@
// Copyright (C) 2020 Alexey Edelev <semlanik@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#define private public
#define protected public
#include "basicmessages.qpb.h"
#undef private
#undef protected
#include <QTest>
@ -30,19 +26,21 @@ void QtProtobufInternalsTest::nullPointerMessageTest()
msg.setTestFieldInt(0);
msg.setTestComplexField(stringMsg);
msg.setTestComplexField_p(nullptr);
msg.setProperty("testComplexField_p",
QVariant::fromValue(static_cast<SimpleStringMessage *>(nullptr)));
QVERIFY(msg.testComplexField().testFieldString().isEmpty());
QVERIFY(msg.testComplexField_p() != nullptr);
QVERIFY(msg.property("testComplexField_p").value<SimpleStringMessage *>() != nullptr);
}
void QtProtobufInternalsTest::nullPointerGetterMessageTest()
{
ComplexMessage msg;
QVERIFY(!msg.hasTestComplexField());
QVERIFY(msg.testComplexField_p() != nullptr);
msg.setTestComplexField_p(nullptr);
QVERIFY(msg.property("testComplexField_p").value<SimpleStringMessage *>() != nullptr);
msg.setProperty("testComplexField_p",
QVariant::fromValue(static_cast<SimpleStringMessage *>(nullptr)));
QVERIFY(msg.testComplexField().testFieldString().isEmpty());
QVERIFY(msg.testComplexField_p() != nullptr);
QVERIFY(msg.property("testComplexField_p").value<SimpleStringMessage *>() != nullptr);
}
QTEST_MAIN(QtProtobufInternalsTest)