diff options
author | Yuhang Zhao <2546789017@qq.com> | 2022-02-27 18:19:41 +0800 |
---|---|---|
committer | Yuhang Zhao <2546789017@qq.com> | 2022-04-20 14:13:16 +0800 |
commit | 39635d025444e61acc0417b088411199b6bea334 (patch) | |
tree | 8e6da8d051900496d2cc3818d4456e7da30b8585 /tests/auto/core | |
parent | e6d37999e72b56200751c1e0b5b96470dc742b37 (diff) |
QtQmlCore: Add SystemInformation singleton
[ChangeLog][QtQmlCore][New Feature] Add SystemInformation singleton.
Change-Id: If219cbc5a09fa965015cf73a402f62f539a9ef84
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/core')
-rw-r--r-- | tests/auto/core/CMakeLists.txt | 15 | ||||
-rw-r--r-- | tests/auto/core/data/tst_systeminformation.qml | 66 | ||||
-rw-r--r-- | tests/auto/core/tst_core.cpp | 42 |
3 files changed, 119 insertions, 4 deletions
diff --git a/tests/auto/core/CMakeLists.txt b/tests/auto/core/CMakeLists.txt index a57498db91..cfdb8d7ff0 100644 --- a/tests/auto/core/CMakeLists.txt +++ b/tests/auto/core/CMakeLists.txt @@ -10,11 +10,22 @@ qt_internal_add_test(tst_core SOURCES tst_core.cpp PUBLIC_LIBRARIES - Qt::Core - Qt::Qml + Qt::CorePrivate + Qt::QmlPrivate + Qt::QuickTestUtilsPrivate TESTDATA ${test_data} ) if(QT_BUILD_STANDALONE_TESTS) qt_import_qml_plugins(tst_core) endif() + +qt_internal_extend_target(tst_core CONDITION ANDROID OR IOS + DEFINES + QT_QMLTEST_DATADIR=\\\":/data\\\" +) + +qt_internal_extend_target(tst_core CONDITION NOT ANDROID AND NOT IOS + DEFINES + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" +) diff --git a/tests/auto/core/data/tst_systeminformation.qml b/tests/auto/core/data/tst_systeminformation.qml new file mode 100644 index 0000000000..2a6d9653f1 --- /dev/null +++ b/tests/auto/core/data/tst_systeminformation.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQml +import QtCore + +QtObject { + property string buildCpuArchitecture: SystemInformation.buildCpuArchitecture + property string currentCpuArchitecture: SystemInformation.currentCpuArchitecture + property string buildAbi: SystemInformation.buildAbi + property string kernelType: SystemInformation.kernelType + property string kernelVersion: SystemInformation.kernelVersion + property string productType: SystemInformation.productType + property string productVersion: SystemInformation.productVersion + property string prettyProductName: SystemInformation.prettyProductName + property string machineHostName: SystemInformation.machineHostName + property var machineUniqueId: SystemInformation.machineUniqueId + property var bootUniqueId: SystemInformation.bootUniqueId +} diff --git a/tests/auto/core/tst_core.cpp b/tests/auto/core/tst_core.cpp index 421775281c..c79eb8186e 100644 --- a/tests/auto/core/tst_core.cpp +++ b/tests/auto/core/tst_core.cpp @@ -26,5 +26,43 @@ ** ****************************************************************************/ -#include <QtQuickTest/quicktest.h> -QUICK_TEST_MAIN(tst_core) +#include <QQmlEngine> +#include <QQmlComponent> +#include <QtCore/qsysinfo.h> +#include <QtQuickTestUtils/private/qmlutils_p.h> + +class tst_core : public QQmlDataTest +{ + Q_OBJECT + +public: + explicit tst_core() : QQmlDataTest(QT_QMLTEST_DATADIR) {} + +private Q_SLOTS: + void systemInformation(); +}; + +void tst_core::systemInformation() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("tst_systeminformation.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + + QCOMPARE(object->property("buildCpuArchitecture").toString(), QSysInfo::buildCpuArchitecture()); + QCOMPARE(object->property("currentCpuArchitecture").toString(), QSysInfo::currentCpuArchitecture()); + QCOMPARE(object->property("buildAbi").toString(), QSysInfo::buildAbi()); + QCOMPARE(object->property("kernelType").toString(), QSysInfo::kernelType()); + QCOMPARE(object->property("kernelVersion").toString(), QSysInfo::kernelVersion()); + QCOMPARE(object->property("productType").toString(), QSysInfo::productType()); + QCOMPARE(object->property("productVersion").toString(), QSysInfo::productVersion()); + QCOMPARE(object->property("prettyProductName").toString(), QSysInfo::prettyProductName()); + QCOMPARE(object->property("machineHostName").toString(), QSysInfo::machineHostName()); + QCOMPARE(object->property("machineUniqueId").toByteArray(), QSysInfo::machineUniqueId()); + QCOMPARE(object->property("bootUniqueId").toByteArray(), QSysInfo::bootUniqueId()); +} + +QTEST_MAIN(tst_core) + +#include "tst_core.moc" |