summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-04-26 10:56:54 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2022-04-27 00:16:26 +0200
commitaa0a53fc19be10b8b1d191415bda82af259a8b23 (patch)
tree1fd2a8587a056427368ce183578a2f667cbe8bd3 /tests/auto/corelib/io
parentc164b75c175394000b17486c853be95e9e6d5752 (diff)
Don't declare type 'id' in the global namespace in a public header
It's not necessary, and it breaks the qttools build (where we have a global variable named 'id'), and thus will most certainly build a lot of existing user code. Amends e47c22480fe84c100019cd92d0296f0dd2a7f3f1. Change-Id: I97a91c2cb23fdae65143cf14c81570cf88d529d5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r--tests/auto/corelib/io/qdebug/CMakeLists.txt4
-rw-r--r--tests/auto/corelib/io/qdebug/tst_qdebug.cpp73
2 files changed, 77 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qdebug/CMakeLists.txt b/tests/auto/corelib/io/qdebug/CMakeLists.txt
index 39b92b9d2f..067e3be04b 100644
--- a/tests/auto/corelib/io/qdebug/CMakeLists.txt
+++ b/tests/auto/corelib/io/qdebug/CMakeLists.txt
@@ -10,3 +10,7 @@ qt_internal_add_test(tst_qdebug
PUBLIC_LIBRARIES
Qt::Concurrent
)
+
+if (APPLE)
+ target_compile_options(tst_qdebug PRIVATE -x objective-c++)
+endif()
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
index 9b9696d7c1..a85d8328e0 100644
--- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
+++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
@@ -52,6 +52,10 @@ struct ConvertsToQVariant {
};
static_assert(!QTypeTraits::has_ostream_operator_v<QDebug, ConvertsToQVariant>);
+#if defined(Q_OS_DARWIN)
+#include <objc/runtime.h>
+#include <Foundation/Foundation.h>
+#endif
class tst_QDebug: public QObject
{
@@ -88,6 +92,12 @@ private slots:
void threadSafety() const;
void toString() const;
void noQVariantEndlessRecursion() const;
+#if defined(Q_OS_DARWIN)
+ void objcInCppMode_data() const;
+ void objcInCppMode() const;
+ void objcInObjcMode_data() const;
+ void objcInObjcMode() const;
+#endif
};
void tst_QDebug::assignment() const
@@ -873,6 +883,69 @@ void tst_QDebug::noQVariantEndlessRecursion() const
qDebug() << var;
}
+#if defined(Q_OS_DARWIN)
+
+@interface MyObjcClass : NSObject
+@end
+
+@implementation MyObjcClass : NSObject
+- (NSString *)description
+{
+ return @"MyObjcClass is the best";
+}
+@end
+
+void tst_QDebug::objcInCppMode_data() const
+{
+ QTest::addColumn<objc_object *>("object");
+ QTest::addColumn<QString>("message");
+
+ QTest::newRow("nil") << static_cast<objc_object*>(nullptr) << QString::fromLatin1("(null)");
+
+ // Not an NSObject subclass
+ auto *nsproxy = reinterpret_cast<objc_object *>(class_createInstance(objc_getClass("NSProxy"), 0));
+ QTest::newRow("NSProxy") << nsproxy << QString::fromLatin1("<NSProxy: 0x%1>").arg(uintptr_t(nsproxy), 1, 16);
+
+ // Plain NSObject
+ auto *nsobject = reinterpret_cast<objc_object *>(class_createInstance(objc_getClass("NSObject"), 0));
+ QTest::newRow("NSObject") << nsobject << QString::fromLatin1("<NSObject: 0x%1>").arg(uintptr_t(nsobject), 1, 16);
+
+ auto str = QString::fromLatin1("foo");
+ QTest::newRow("NSString") << reinterpret_cast<objc_object*>(str.toNSString()) << str;
+
+ // Custom debug description
+ QTest::newRow("MyObjcClass") << reinterpret_cast<objc_object*>([[MyObjcClass alloc] init])
+ << QString::fromLatin1("MyObjcClass is the best");
+}
+
+void tst_QDebug::objcInCppMode() const
+{
+ QFETCH(objc_object *, object);
+ QFETCH(QString, message);
+
+ MessageHandlerSetter mhs(myMessageHandler);
+ { qDebug() << object; }
+
+ QCOMPARE(s_msg, message);
+}
+
+void tst_QDebug::objcInObjcMode_data() const
+{
+ objcInCppMode_data();
+}
+
+void tst_QDebug::objcInObjcMode() const
+{
+ QFETCH(objc_object *, object);
+ QFETCH(QString, message);
+
+ MessageHandlerSetter mhs(myMessageHandler);
+ { qDebug() << static_cast<id>(object); }
+
+ QCOMPARE(s_msg, message);
+}
+#endif
+
// Should compile: instentiation of unrelated operator<< should not cause cause compilation
// error in QDebug operators (QTBUG-47375)
class TestClassA {};