Skip to content

Commit

Permalink
qmake/cmake disabled deprecated APIs for Qt <=6.7
Browse files Browse the repository at this point in the history
 - for Qt <6 disabled deprecated APIs for Qt <=6.0
 - added temporary workaround for
   QVERIFY_EXCEPTION_THROWN() vs QVERIFY_THROWS_EXCEPTION(), will be
   correctly refactored for Qt v6.8
  • Loading branch information
silverqx committed Jun 16, 2024
1 parent 55cc67c commit b6d1063
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 86 deletions.
1 change: 1 addition & 0 deletions NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ Common:
- overflow : add check code, eg when size_t to int conversion
- perf : performance
- production : check before deploy to production
- qt5 remove : code to remove after the Qt v5 support will dropped
- regex : mark regex-es, try to avoid them
- reliability : make things more robust and reliable
- repeat : tasks that should I make from time to time
Expand Down
17 changes: 10 additions & 7 deletions cmake/CommonModules/TinyCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ ${TINY_UNPARSED_ARGUMENTS}")
# Qt defines
# ---

# Disable deprecated APIs up to the given Qt version
# TODO qt5 remove silverqx
if(QT_VERSION_MAJOR GREATER_EQUAL 6)
# Disable all the APIs deprecated up to Qt 6.7.0
target_compile_definitions(${target} INTERFACE QT_DISABLE_DEPRECATED_UP_TO=0x060700)
else()
# Disable all the APIs deprecated up to Qt 6.0.0
target_compile_definitions(${target} INTERFACE QT_DISABLE_DEPRECATED_BEFORE=0x060000)
endif()

target_compile_definitions(${target}
INTERFACE
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version
# of Qt.
# Disables all the APIs deprecated before Qt 6.0.0
QT_DISABLE_DEPRECATED_BEFORE=0x060000

#QT_ASCII_CAST_WARNINGS
#QT_NO_CAST_FROM_ASCII
#QT_RESTRICTED_CAST_FROM_ASCII
Expand Down
14 changes: 9 additions & 5 deletions qmake/common/common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load(tiny_dotenv)
# Common Configuration ( also for tests )
# ---

# TODO qt5 remove silverqx
versionAtLeast(QT_VERSION, 6.2.4): \
CONFIG *= c++20
else: \
Expand All @@ -19,11 +20,14 @@ CONFIG -= c++11 app_bundle
# Qt defines
# ---

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
# Disables all the APIs deprecated before Qt 6.0.0
DEFINES *= QT_DISABLE_DEPRECATED_BEFORE=0x060000
# Disable deprecated APIs up to the given Qt version
# Disable all the APIs deprecated up to Qt 6.7.0
# TODO qt5 remove silverqx
versionAtLeast(QT_VERSION, 6): \
DEFINES *= QT_DISABLE_DEPRECATED_UP_TO=0x060700
# Disable all the APIs deprecated up to Qt 6.0.0
else: \
DEFINES *= QT_DISABLE_DEPRECATED_BEFORE=0x060000

#DEFINES *= QT_ASCII_CAST_WARNINGS
#DEFINES *= QT_NO_CAST_FROM_ASCII
Expand Down
12 changes: 12 additions & 0 deletions tests/TinyUtils/src/databases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
# define sl(str) QStringLiteral(str)
#endif

#ifndef TVERIFY_EXCEPTION_THROWN
# if QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
/*! Alias for QVERIFY_THROWS_EXCEPTION() (temporary workaround for Qt v6.8). */
# define TVERIFY_EXCEPTION_THROWN(expression, exceptiontype) \
QVERIFY_THROWS_EXCEPTION(exceptiontype, expression)
# else
/*! Alias for QVERIFY_EXCEPTION_THROWN(). */
# define TVERIFY_EXCEPTION_THROWN(expression, exceptiontype) \
QVERIFY_EXCEPTION_THROWN(expression, exceptiontype)
# endif
#endif

namespace Orm
{
class DatabaseManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ void tst_DatabaseManager::SQLite_CheckDatabaseExists_True() const
.toUtf8().constData(), );

// Verify
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
m_dm->connection(*connectionName)
.statement(sl("create table tbl1 (one varchar(10), two smallint)")),
SQLiteDatabaseDoesNotExistError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ void tst_QueryBuilder::upsert_EmptyUpdate() const
{
QFETCH_GLOBAL(QString, connection); // NOLINT(modernize-type-traits)

QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
createQuery(connection)->from("tag_properties")
.upsert({{{"tag_id", 1}, {"color", "pink"}, {"position", 0}},
{{"tag_id", 1}, {"color", "purple"}, {"position", 4}}},
Expand Down Expand Up @@ -1583,7 +1583,7 @@ void tst_QueryBuilder::sole_RecordsNotFoundError() const
{
QFETCH_GLOBAL(QString, connection); // NOLINT(modernize-type-traits)

QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
createQuery(connection)->from("torrents")
.whereEq(NAME, dummy_NONEXISTENT)
.sole(),
Expand All @@ -1594,7 +1594,7 @@ void tst_QueryBuilder::sole_MultipleRecordsFoundError() const
{
QFETCH_GLOBAL(QString, connection); // NOLINT(modernize-type-traits)

QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
createQuery(connection)->from("torrents").whereEq("user_id", 1).sole(),
MultipleRecordsFoundError);
}
Expand All @@ -1615,7 +1615,7 @@ void tst_QueryBuilder::soleValue_RecordsNotFoundError() const
{
QFETCH_GLOBAL(QString, connection); // NOLINT(modernize-type-traits)

QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
createQuery(connection)->from("torrents")
.whereEq(NAME, dummy_NONEXISTENT)
.soleValue(NAME),
Expand All @@ -1626,7 +1626,7 @@ void tst_QueryBuilder::soleValue_MultipleRecordsFoundError() const
{
QFETCH_GLOBAL(QString, connection); // NOLINT(modernize-type-traits)

QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
createQuery(connection)->from("torrents")
.whereEq("user_id", 1)
.soleValue(NAME),
Expand Down Expand Up @@ -1719,7 +1719,7 @@ void tst_QueryBuilder::chunk_EnforceOrderBy() const
{
QFETCH_GLOBAL(QString, connection); // NOLINT(modernize-type-traits)

QVERIFY_EXCEPTION_THROWN(createQuery(connection)->from("file_property_properties")
TVERIFY_EXCEPTION_THROWN(createQuery(connection)->from("file_property_properties")
.chunk(3, [](SqlQuery &/*unused*/, const qint64 /*unused*/)
{
return true;
Expand Down Expand Up @@ -1812,7 +1812,7 @@ void tst_QueryBuilder::each_EnforceOrderBy() const
{
QFETCH_GLOBAL(QString, connection); // NOLINT(modernize-type-traits)

QVERIFY_EXCEPTION_THROWN(createQuery(connection)->from("file_property_properties")
TVERIFY_EXCEPTION_THROWN(createQuery(connection)->from("file_property_properties")
.each([](SqlQuery &/*unused*/, const qint64 /*unused*/)
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void tst_PostgreSQL_SchemaBuilder_f::
.toUtf8().constData(), );

// Verify
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
Schema::on(*connectionName).hasTable(sl("users")),
SearchPathEmptyError);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ void tst_CastAttributes::cast_QByteArray_to_QDateTime_ThrowException() const

type.mergeCasts({{"binary", CastType::QDateTime}});

QVERIFY_EXCEPTION_THROWN(type.getAttribute("binary"),
TVERIFY_EXCEPTION_THROWN(type.getAttribute("binary"),
InvalidFormatError);
}

Expand All @@ -525,7 +525,7 @@ void tst_CastAttributes::cast_QDateTime_to_QByteArray_ThrowException() const

type.mergeCasts({{"datetime", CastType::QByteArray}});

QVERIFY_EXCEPTION_THROWN(type.getAttribute("datetime"),
TVERIFY_EXCEPTION_THROWN(type.getAttribute("datetime"),
InvalidArgumentError);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2666,7 +2666,7 @@ void tst_Collection_Models::load_lvalue_NonExistentRelation_Failed() const
// Verify before
verify();

QVERIFY_EXCEPTION_THROWN(albums.load("albumImages-NON_EXISTENT"),
TVERIFY_EXCEPTION_THROWN(albums.load("albumImages-NON_EXISTENT"),
RelationMappingNotFoundError);

// Verify after
Expand Down Expand Up @@ -2905,7 +2905,7 @@ void tst_Collection_Models::load_rvalue_NonExistentRelation_Failed() const
// Verify before
verify();

QVERIFY_EXCEPTION_THROWN(std::move(albums).load("albumImages-NON_EXISTENT"),
TVERIFY_EXCEPTION_THROWN(std::move(albums).load("albumImages-NON_EXISTENT"),
RelationMappingNotFoundError);

// Verify after
Expand Down Expand Up @@ -3132,7 +3132,7 @@ void tst_Collection_Models::where_InvalidComparisonOperator_ThrowException() con
QVERIFY(Common::verifyIds(images, {2, 3, 4, 5, 6}));

// Verify
QVERIFY_EXCEPTION_THROWN(images.where(ID, dummy_NONEXISTENT, 10),
TVERIFY_EXCEPTION_THROWN(images.where(ID, dummy_NONEXISTENT, 10),
InvalidArgumentError);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3116,7 +3116,7 @@ void tst_Collection_Relations::load_lvalue_NonExistentRelation_Failed() const
// Verify before
verify();

QVERIFY_EXCEPTION_THROWN(albumsInit.load("albumImages-NON_EXISTENT"),
TVERIFY_EXCEPTION_THROWN(albumsInit.load("albumImages-NON_EXISTENT"),
RelationMappingNotFoundError);

// Verify after
Expand Down Expand Up @@ -3377,7 +3377,7 @@ void tst_Collection_Relations::load_rvalue_NonExistentRelation_Failed() const
// Verify before
verify();

QVERIFY_EXCEPTION_THROWN(std::move(albumsInit).load("albumImages-NON_EXISTENT"),
TVERIFY_EXCEPTION_THROWN(std::move(albumsInit).load("albumImages-NON_EXISTENT"),
RelationMappingNotFoundError);

// Verify after
Expand Down Expand Up @@ -3652,7 +3652,7 @@ void tst_Collection_Relations::where_InvalidComparisonOperator_ThrowException()
QVERIFY(Common::verifyIds(images, {2, 3, 4, 5, 6}));

// Verify
QVERIFY_EXCEPTION_THROWN(images.where(ID, dummy_NONEXISTENT, 10),
TVERIFY_EXCEPTION_THROWN(images.where(ID, dummy_NONEXISTENT, 10),
InvalidArgumentError);
}

Expand Down
8 changes: 4 additions & 4 deletions tests/auto/functional/orm/tiny/model/tst_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ void tst_Model::save_Update_Failed() const

peer->setAttribute("total_seeds-NON_EXISTENT", 15);

QVERIFY_EXCEPTION_THROWN(peer->save(), QueryError);
TVERIFY_EXCEPTION_THROWN(peer->save(), QueryError);

QVERIFY(peer->exists);
}
Expand Down Expand Up @@ -832,9 +832,9 @@ void tst_Model::findOrFail_NotFoundFailed() const

ConnectionOverride::connection = connection;

QVERIFY_EXCEPTION_THROWN(Torrent::findOrFail(999999),
TVERIFY_EXCEPTION_THROWN(Torrent::findOrFail(999999),
ModelNotFoundError);
QVERIFY_EXCEPTION_THROWN(Torrent::findOrFail(999999, {ID, NAME}),
TVERIFY_EXCEPTION_THROWN(Torrent::findOrFail(999999, {ID, NAME}),
ModelNotFoundError);
}

Expand Down Expand Up @@ -1351,7 +1351,7 @@ void tst_Model::create_Failed() const
const auto addedOn = QDateTime({2021, 2, 1}, {20, 22, 10}, Qt::UTC);

Torrent torrent;
QVERIFY_EXCEPTION_THROWN((torrent = Torrent::create({
TVERIFY_EXCEPTION_THROWN((torrent = Torrent::create({
{"name-NON_EXISTENT", "test100"},
{SIZE_, 100},
{Progress, 333},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,14 @@ void tst_Model_Connection_Independent::
defaultAttributeValues_WithQDateTime_DefaultCtor() const
{
// Default ctor must throw because of the QDateTime
QVERIFY_EXCEPTION_THROWN(TorrentEager(), InvalidArgumentError);
TVERIFY_EXCEPTION_THROWN(TorrentEager(), InvalidArgumentError);
}

void tst_Model_Connection_Independent::
defaultAttributeValues_WithQDateTime_ConvertingAttributesCtor() const
{
// Attributes converting ctor must throw because of the QDateTime
QVERIFY_EXCEPTION_THROWN(TorrentEager({
TVERIFY_EXCEPTION_THROWN(TorrentEager({
{NAME, "test22"},
{NOTE, "Torrent::instance()"},
}),
Expand All @@ -227,7 +227,7 @@ defaultAttributeValues_WithQDateTime_ListInitializationCtor() const
{
/* List initialization using the std::initializer_list<AttributeItem> must throw
because of the QDateTime. */
QVERIFY_EXCEPTION_THROWN((TorrentEager {
TVERIFY_EXCEPTION_THROWN((TorrentEager {
{NAME, "test22"},
{NOTE, "Torrent::instance()"},
}),
Expand Down Expand Up @@ -963,7 +963,7 @@ tst_Model_Connection_Independent::massAssignment_TotallyGuarded_Exception() cons
Torrent_TotallyGuarded torrent;

QVERIFY(!torrent.exists);
QVERIFY_EXCEPTION_THROWN(torrent.fill({{NAME, "test150"}}),
TVERIFY_EXCEPTION_THROWN(torrent.fill({{NAME, "test150"}}),
MassAssignmentError);
}

Expand Down Expand Up @@ -2217,14 +2217,14 @@ void tst_Model_Connection_Independent::sole() const

void tst_Model_Connection_Independent::sole_RecordsNotFoundError() const
{
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
FilePropertyProperty::whereEq(NAME, dummy_NONEXISTENT)->sole(),
RecordsNotFoundError);
}

void tst_Model_Connection_Independent::sole_MultipleRecordsFoundError() const
{
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
FilePropertyProperty::whereEq("file_property_id", 5)->sole(),
MultipleRecordsFoundError);
}
Expand Down Expand Up @@ -2257,14 +2257,14 @@ void tst_Model_Connection_Independent::soleValue() const

void tst_Model_Connection_Independent::soleValue_RecordsNotFoundError() const
{
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
FilePropertyProperty::whereEq(NAME, dummy_NONEXISTENT)->soleValue(NAME),
RecordsNotFoundError);
}

void tst_Model_Connection_Independent::soleValue_MultipleRecordsFoundError() const
{
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
FilePropertyProperty::soleValue(NAME),
MultipleRecordsFoundError);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,23 +412,23 @@ void tst_Model_Relations::getRelation_EagerLoad_Failed() const
Torrent torrent;

// Many relation
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
(torrent.getRelation<TorrentPreviewableFile>("torrentFiles")),
RelationNotLoadedError);
// One relation, obtained as QVector, also possible
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
(torrent.getRelation<TorrentPeer>("torrentFiles")),
RelationNotLoadedError);
// Many relation
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
(torrent.getRelation<TorrentPeer, One>("torrentFiles")),
RelationNotLoadedError);
// BelongsTo relation
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
(TorrentPeer().getRelation<Torrent, One>("torrent")),
RelationNotLoadedError);
// BelongsToMany relation
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
(torrent.getRelation<Tag>("tags")),
RelationNotLoadedError);
}
Expand All @@ -439,7 +439,7 @@ void tst_Model_Relations::eagerLoad_Failed() const

ConnectionOverride::connection = connection;

QVERIFY_EXCEPTION_THROWN(TorrentEager_Failed::find(1),
TVERIFY_EXCEPTION_THROWN(TorrentEager_Failed::find(1),
RelationMappingNotFoundError);
}

Expand Down Expand Up @@ -928,7 +928,7 @@ void tst_Model_Relations::with_Vector_MoreRelations() const
QCOMPARE(typeid (file), typeid (TorrentPreviewableFile *));

// No TorrentPreviewableFileProperty loaded
QVERIFY_EXCEPTION_THROWN(
TVERIFY_EXCEPTION_THROWN(
(file->getRelation<TorrentPreviewableFileProperty, One>(
"fileProperty")),
RuntimeError);
Expand All @@ -941,7 +941,7 @@ void tst_Model_Relations::with_NonExistentRelation_Failed() const

ConnectionOverride::connection = connection;

QVERIFY_EXCEPTION_THROWN(Torrent::with("torrentFiles-NON_EXISTENT")->find(1),
TVERIFY_EXCEPTION_THROWN(Torrent::with("torrentFiles-NON_EXISTENT")->find(1),
RelationMappingNotFoundError);
}

Expand Down Expand Up @@ -1783,7 +1783,7 @@ void tst_Model_Relations::load_NonExistentRelation_Failed() const

QVERIFY(torrent->getRelations().empty());

QVERIFY_EXCEPTION_THROWN(torrent->load("torrentFiles-NON_EXISTENT"),
TVERIFY_EXCEPTION_THROWN(torrent->load("torrentFiles-NON_EXISTENT"),
RelationMappingNotFoundError);
QVERIFY(torrent->getRelations().empty());
}
Expand Down
Loading

0 comments on commit b6d1063

Please sign in to comment.