summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMikolaj Boc <mikolaj.boc@qt.io>2022-12-30 13:41:40 +0100
committerMikolaj Boc <mikolaj.boc@qt.io>2023-01-13 21:07:14 +0100
commit2e97ccc8d0e3c1fa0fe34e01d1d3e6f8cd7465ba (patch)
tree4a5094bb2cc1b700c2884e2b1a32226110b7ba45 /tests
parent4dbb07f614c914e78437aacf7a1716f632da5e8a (diff)
Add QString<->emscripten::val conversion functions
Following the QRect, add functions converting the QString to native emscripten::val and back: fromJsString, toJsString Change-Id: I2d0625ede3bbf7249e2e91b8de298b5b91df8ba2 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/text/qstring/CMakeLists.txt3
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring.cpp11
-rw-r--r--tests/auto/corelib/text/qstring/tst_qstring_wasm.cpp28
3 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/corelib/text/qstring/CMakeLists.txt b/tests/auto/corelib/text/qstring/CMakeLists.txt
index c3f8bbb717..d3db36e813 100644
--- a/tests/auto/corelib/text/qstring/CMakeLists.txt
+++ b/tests/auto/corelib/text/qstring/CMakeLists.txt
@@ -9,6 +9,9 @@ if(APPLE)
list(APPEND tst_qstring_extra_libraries ${FWFoundation})
list(APPEND tst_qstring_extra_sources tst_qstring_mac.mm)
endif()
+if(WASM)
+ list(APPEND tst_qstring_extra_sources tst_qstring_wasm.cpp)
+endif()
foreach(test tst_qstring tst_qstring_restricted_ascii)
qt_internal_add_test(${test}
diff --git a/tests/auto/corelib/text/qstring/tst_qstring.cpp b/tests/auto/corelib/text/qstring/tst_qstring.cpp
index aec2d2897a..2e733fc49b 100644
--- a/tests/auto/corelib/text/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/text/qstring/tst_qstring.cpp
@@ -541,6 +541,7 @@ private slots:
#endif
void STL();
void macTypes();
+ void wasmTypes();
void isEmpty();
void isNull();
void nullness();
@@ -1344,6 +1345,16 @@ void tst_QString::macTypes()
#endif
}
+void tst_QString::wasmTypes()
+{
+#ifndef Q_OS_WASM
+ QSKIP("This is a WASM-only test");
+#else
+ extern void tst_QString_wasmTypes(); // in qcore_wasm.cpp
+ tst_QString_wasmTypes();
+#endif
+}
+
void tst_QString::truncate()
{
QString nullStr;
diff --git a/tests/auto/corelib/text/qstring/tst_qstring_wasm.cpp b/tests/auto/corelib/text/qstring/tst_qstring_wasm.cpp
new file mode 100644
index 0000000000..df5ebddc96
--- /dev/null
+++ b/tests/auto/corelib/text/qstring/tst_qstring_wasm.cpp
@@ -0,0 +1,28 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include <QtCore/QString>
+#include <QTest>
+
+#include <emscripten/val.h>
+
+void tst_QString_wasmTypes()
+{
+ // QString <-> emscripten::val
+ {
+ QString qtString("test string");
+ const emscripten::val jsString = qtString.toJsString();
+ QString qtStringCopy(qtString);
+ qtString = qtString.toUpper(); // modify
+ QCOMPARE(QString::fromJsString(jsString), qtStringCopy);
+ }
+ {
+ QString longString;
+ for (uint64_t i = 0; i < 1000; ++i)
+ longString += "Lorem ipsum FTW";
+ const emscripten::val jsString = longString.toJsString();
+ QString qtStringCopy(longString);
+ longString = longString.toUpper(); // modify
+ QCOMPARE(QString::fromJsString(jsString), qtStringCopy);
+ }
+}