summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPiotr Srebrny <piotr.srebrny@qt.io>2022-05-16 21:04:38 +0200
committerPiotr Srebrny <piotr.srebrny@qt.io>2022-05-24 12:05:53 +0200
commit8131af7dea6f0e4f55fb6af1457b64dde567c69a (patch)
treecf703732dcf2227a41570d6266550d3d9b58d961 /tests
parent98e9c47020183b79c64dd30b1481c92c2e5dc01c (diff)
Extend fraction computation algorithm to numbers above 1 and below 0
This patch extends the algorithm for finding a real number numerator and denominator to numbers below 0 and above 1. It also improves interface by returning a pair of number. Additionally, it adds some basic test cases. Change-Id: I70f23a06a1cd2451242a53ec7c5e2fb90b9586bb Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/unit/multimedia/CMakeLists.txt1
-rw-r--r--tests/auto/unit/multimedia/qmultimediautils/CMakeLists.txt6
-rw-r--r--tests/auto/unit/multimedia/qmultimediautils/tst_qmultimediautils.cpp100
3 files changed, 107 insertions, 0 deletions
diff --git a/tests/auto/unit/multimedia/CMakeLists.txt b/tests/auto/unit/multimedia/CMakeLists.txt
index d95cab75a..bf1169e58 100644
--- a/tests/auto/unit/multimedia/CMakeLists.txt
+++ b/tests/auto/unit/multimedia/CMakeLists.txt
@@ -12,6 +12,7 @@ add_subdirectory(qmediaplayer)
#add_subdirectory(qmediaplaylist)
add_subdirectory(qmediarecorder)
add_subdirectory(qmediatimerange)
+add_subdirectory(qmultimediautils)
add_subdirectory(qvideoframe)
add_subdirectory(qvideoframeformat)
add_subdirectory(qaudiobuffer)
diff --git a/tests/auto/unit/multimedia/qmultimediautils/CMakeLists.txt b/tests/auto/unit/multimedia/qmultimediautils/CMakeLists.txt
new file mode 100644
index 000000000..5c522a5c6
--- /dev/null
+++ b/tests/auto/unit/multimedia/qmultimediautils/CMakeLists.txt
@@ -0,0 +1,6 @@
+qt_internal_add_test(tst_qmultimediautils
+ SOURCES
+ tst_qmultimediautils.cpp
+ PUBLIC_LIBRARIES
+ Qt::MultimediaPrivate
+)
diff --git a/tests/auto/unit/multimedia/qmultimediautils/tst_qmultimediautils.cpp b/tests/auto/unit/multimedia/qmultimediautils/tst_qmultimediautils.cpp
new file mode 100644
index 000000000..37766843c
--- /dev/null
+++ b/tests/auto/unit/multimedia/qmultimediautils/tst_qmultimediautils.cpp
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** 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:GPL-EXCEPT$
+** 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.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QDebug>
+#include <private/qmultimediautils_p.h>
+
+class tst_QMultimediaUtils : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void fraction_of_0();
+ void fraction_of_negative_1_5();
+ void fraction_of_1_5();
+ void fraction_of_30();
+ void fraction_of_29_97();
+ void fraction_of_lower_boundary();
+ void fraction_of_upper_boundary();
+};
+
+void tst_QMultimediaUtils::fraction_of_0()
+{
+ auto [n, d] = qRealToFraction(0.);
+ QCOMPARE(n, 0);
+ QCOMPARE(d, 1);
+}
+
+void tst_QMultimediaUtils::fraction_of_negative_1_5()
+{
+ auto [n, d] = qRealToFraction(-1.5);
+ QCOMPARE(double(n) / double(d), -1.5);
+ QCOMPARE(n, -3);
+ QCOMPARE(d, 2);
+}
+
+void tst_QMultimediaUtils::fraction_of_1_5()
+{
+ auto [n, d] = qRealToFraction(1.5);
+ QCOMPARE(double(n) / double(d), 1.5);
+ QCOMPARE(n, 3);
+ QCOMPARE(d, 2);
+}
+
+void tst_QMultimediaUtils::fraction_of_30()
+{
+ auto [n, d] = qRealToFraction(30.);
+ QCOMPARE(double(n) / double(d), 30.);
+ QCOMPARE(d, 1);
+}
+
+void tst_QMultimediaUtils::fraction_of_29_97()
+{
+ auto [n, d] = qRealToFraction(29.97);
+ QCOMPARE(double(n) / double(d), 29.97);
+}
+
+void tst_QMultimediaUtils::fraction_of_lower_boundary()
+{
+ double f = 0.000001;
+ auto [n, d] = qRealToFraction(f);
+ QVERIFY(double(n) / double(d) < f);
+ QVERIFY(double(n) / double(d) >= 0.);
+}
+
+void tst_QMultimediaUtils::fraction_of_upper_boundary()
+{
+ double f = 0.999999;
+ auto [n, d] = qRealToFraction(f);
+ QVERIFY(double(n) / double(d) <= 1.);
+ QVERIFY(double(n) / double(d) > f);
+}
+
+QTEST_MAIN(tst_QMultimediaUtils)
+#include "tst_qmultimediautils.moc"