mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-03 15:55:27 +08:00
qt 6.5.1 original
This commit is contained in:
61
tests/manual/permissions/CMakeLists.txt
Normal file
61
tests/manual/permissions/CMakeLists.txt
Normal file
@ -0,0 +1,61 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
qt_internal_add_test(tst_manual_qpermissions
|
||||
SOURCES
|
||||
tst_qpermissions.cpp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
)
|
||||
|
||||
if(ANDROID)
|
||||
set_property(TARGET tst_manual_qpermissions
|
||||
PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
|
||||
elseif(APPLE)
|
||||
# Test an app bundle, but without any usage descriptions
|
||||
|
||||
qt_internal_add_test(tst_qpermissions_app
|
||||
SOURCES
|
||||
tst_qpermissions.cpp
|
||||
DEFINES
|
||||
tst_QPermissions=tst_QPermissionsApp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
)
|
||||
|
||||
set_property(TARGET tst_qpermissions_app
|
||||
PROPERTY MACOSX_BUNDLE TRUE)
|
||||
set_property(TARGET tst_qpermissions_app
|
||||
PROPERTY MACOSX_BUNDLE_GUI_IDENTIFIER "io.qt.dev.tst_permissions_app")
|
||||
|
||||
# Test an app bundle with all the required usage descriptions
|
||||
|
||||
qt_internal_add_test(tst_qpermissions_app_with_usage_descriptions
|
||||
SOURCES
|
||||
tst_qpermissions.cpp
|
||||
DEFINES
|
||||
tst_QPermissions=tst_QPermissionsAppWithUsageDescriptions
|
||||
HAVE_USAGE_DESCRIPTION=1
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
)
|
||||
|
||||
set_property(TARGET tst_qpermissions_app_with_usage_descriptions
|
||||
PROPERTY MACOSX_BUNDLE TRUE)
|
||||
set_property(TARGET tst_qpermissions_app_with_usage_descriptions
|
||||
PROPERTY MACOSX_BUNDLE_GUI_IDENTIFIER "io.qt.dev.tst_qpermissions_app_with_usage_descriptions")
|
||||
set_property(TARGET tst_qpermissions_app_with_usage_descriptions
|
||||
PROPERTY MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist")
|
||||
|
||||
foreach(permission_plugin IN LISTS QT_ALL_PLUGINS_FOUND_BY_FIND_PACKAGE_permissions)
|
||||
set(permission_plugin "${QT_CMAKE_EXPORT_NAMESPACE}::${permission_plugin}")
|
||||
qt6_import_plugins(tst_qpermissions_app INCLUDE ${permission_plugin})
|
||||
qt6_import_plugins(tst_qpermissions_app_with_usage_descriptions INCLUDE ${permission_plugin})
|
||||
endforeach()
|
||||
|
||||
if(NOT CMAKE_GENERATOR STREQUAL "Xcode")
|
||||
add_custom_command(TARGET tst_qpermissions_app_with_usage_descriptions
|
||||
POST_BUILD COMMAND codesign -s - tst_qpermissions_app_with_usage_descriptions.app)
|
||||
endif()
|
||||
endif()
|
59
tests/manual/permissions/Info.plist
Normal file
59
tests/manual/permissions/Info.plist
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
|
||||
<key>CFBundleName</key>
|
||||
<string>${MACOSX_BUNDLE_BUNDLE_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${MACOSX_BUNDLE_EXECUTABLE_NAME}</string>
|
||||
|
||||
<key>CFBundleVersion</key>
|
||||
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
|
||||
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string>
|
||||
|
||||
<key>NSHumanReadableCopyright</key>
|
||||
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
|
||||
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>${MACOSX_BUNDLE_ICON_FILE}</string>
|
||||
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
|
||||
<key>NSSupportsAutomaticGraphicsSwitching</key>
|
||||
<true/>
|
||||
|
||||
<key>NSBluetoothAlwaysUsageDescription</key>
|
||||
<string>Testing BluetoothAlways</string>
|
||||
<key>NSCalendarsUsageDescription</key>
|
||||
<string>Testing Calendars</string>
|
||||
<key>NSCameraUsageDescription</key>
|
||||
<string>Testing Camera</string>
|
||||
<key>NSContactsUsageDescription</key>
|
||||
<string>Testing Contacts</string>
|
||||
<key>NSHealthShareUsageDescription</key>
|
||||
<string>Testing HealthShare</string>
|
||||
<key>NSHealthUpdateUsageDescription</key>
|
||||
<string>Testing HealthUpdate</string>
|
||||
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
|
||||
<string>Testing LocationAlwaysAndWhenInUse</string>
|
||||
<key>NSLocationAlwaysUsageDescription</key>
|
||||
<string>Testing LocationAlways</string>
|
||||
<key>NSLocationWhenInUseUsageDescription</key>
|
||||
<string>Testing LocationWhenInUse</string>
|
||||
<key>NSMicrophoneUsageDescription</key>
|
||||
<string>Testing Microphone</string>
|
||||
|
||||
</dict>
|
||||
</plist>
|
53
tests/manual/permissions/android/AndroidManifest.xml
Normal file
53
tests/manual/permissions/android/AndroidManifest.xml
Normal file
@ -0,0 +1,53 @@
|
||||
<?xml version="1.0"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.qtproject.example"
|
||||
android:installLocation="auto"
|
||||
android:versionCode="-- %%INSERT_VERSION_CODE%% --"
|
||||
android:versionName="-- %%INSERT_VERSION_NAME%% --">
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.READ_CALENDAR" />
|
||||
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
|
||||
<!-- %%INSERT_PERMISSIONS -->
|
||||
<!-- %%INSERT_FEATURES -->
|
||||
<supports-screens
|
||||
android:anyDensity="true"
|
||||
android:largeScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:smallScreens="true" />
|
||||
<application
|
||||
android:name="org.qtproject.qt.android.bindings.QtApplication"
|
||||
android:hardwareAccelerated="true"
|
||||
android:label="-- %%INSERT_APP_NAME%% --"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:allowNativeHeapPointerTagging="false"
|
||||
android:allowBackup="true"
|
||||
android:fullBackupOnly="false">
|
||||
<activity
|
||||
android:name="org.qtproject.qt.android.bindings.QtActivity"
|
||||
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
|
||||
android:label="-- %%INSERT_APP_NAME%% --"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="unspecified"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.lib_name"
|
||||
android:value="-- %%INSERT_APP_LIB_NAME%% --" />
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.extract_android_style"
|
||||
android:value="minimal" />
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
116
tests/manual/permissions/tst_qpermissions.cpp
Normal file
116
tests/manual/permissions/tst_qpermissions.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QTest>
|
||||
|
||||
#include <QtCore/qpermissions.h>
|
||||
#include <QtCore/qthread.h>
|
||||
#include <QtCore/qmutex.h>
|
||||
#include <QtCore/qwaitcondition.h>
|
||||
#include <QtCore/qtimer.h>
|
||||
|
||||
#if defined(Q_OS_MACOS) && defined(QT_BUILD_INTERNAL)
|
||||
#include <private/qcore_mac_p.h>
|
||||
Q_CONSTRUCTOR_FUNCTION(qt_mac_ensureResponsible);
|
||||
#endif
|
||||
|
||||
class tst_QPermissions : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase_data();
|
||||
|
||||
void checkPermission();
|
||||
void checkPermissionInNonMainThread();
|
||||
|
||||
void requestPermission();
|
||||
void requestPermissionInNonMainThread();
|
||||
};
|
||||
|
||||
void tst_QPermissions::initTestCase_data()
|
||||
{
|
||||
QTest::addColumn<QPermission>("permission");
|
||||
|
||||
QTest::newRow("Camera") << QPermission(QCameraPermission{});
|
||||
QTest::newRow("Microphone") << QPermission(QMicrophonePermission{});
|
||||
QTest::newRow("Bluetooth") << QPermission(QBluetoothPermission{});
|
||||
QTest::newRow("Contacts") << QPermission(QContactsPermission{});
|
||||
QTest::newRow("Calendar") << QPermission(QCalendarPermission{});
|
||||
QTest::newRow("Location") << QPermission(QLocationPermission{});
|
||||
}
|
||||
|
||||
void tst_QPermissions::checkPermission()
|
||||
{
|
||||
QFETCH_GLOBAL(QPermission, permission);
|
||||
qApp->checkPermission(permission);
|
||||
}
|
||||
|
||||
class Thread : public QThread
|
||||
{
|
||||
public:
|
||||
QMutex mutex;
|
||||
QWaitCondition cond;
|
||||
std::function<void()> function;
|
||||
|
||||
void run() override
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
function();
|
||||
cond.wakeOne();
|
||||
}
|
||||
};
|
||||
|
||||
void tst_QPermissions::checkPermissionInNonMainThread()
|
||||
{
|
||||
QFETCH_GLOBAL(QPermission, permission);
|
||||
|
||||
Thread thread;
|
||||
thread.function = [=]{
|
||||
qApp->checkPermission(permission);
|
||||
};
|
||||
|
||||
QVERIFY(!thread.isFinished());
|
||||
QMutexLocker locker(&thread.mutex);
|
||||
thread.start();
|
||||
QVERIFY(!thread.isFinished());
|
||||
thread.cond.wait(locker.mutex());
|
||||
QVERIFY(thread.wait(1000));
|
||||
QVERIFY(thread.isFinished());
|
||||
}
|
||||
|
||||
void tst_QPermissions::requestPermission()
|
||||
{
|
||||
QFETCH_GLOBAL(QPermission, permission);
|
||||
QTimer::singleShot(0, this, [=] {
|
||||
qApp->requestPermission(permission, [=](auto result) {
|
||||
qDebug() << result;
|
||||
Q_ASSERT(QThread::currentThread() == thread());
|
||||
qApp->exit();
|
||||
});
|
||||
});
|
||||
qApp->exec();
|
||||
}
|
||||
|
||||
void tst_QPermissions::requestPermissionInNonMainThread()
|
||||
{
|
||||
QFETCH_GLOBAL(QPermission, permission);
|
||||
|
||||
QTest::ignoreMessage(QtWarningMsg, "Permissions can only be requested from the GUI (main) thread");
|
||||
|
||||
Thread thread;
|
||||
thread.function = [&]{
|
||||
qApp->requestPermission(permission, [&]() {});
|
||||
};
|
||||
|
||||
QVERIFY(!thread.isFinished());
|
||||
QMutexLocker locker(&thread.mutex);
|
||||
thread.start();
|
||||
QVERIFY(!thread.isFinished());
|
||||
thread.cond.wait(locker.mutex());
|
||||
QVERIFY(thread.wait(1000));
|
||||
QVERIFY(thread.isFinished());
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QPermissions)
|
||||
#include "tst_qpermissions.moc"
|
Reference in New Issue
Block a user