summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-03-18 10:34:01 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-03-22 17:37:19 +0100
commite640503b65c4d786edc9f005a1c3f6f66e87793d (patch)
tree67f5b30ece14b17ba237a2a02f03203ddda4ec0e /tests
parent4e1e7938763b5b8323c5e437286ccccd31d95156 (diff)
Fix handling of out-parameters that are of VARIANT-type
Qt knows about QVariant as a built-in meta type, QMetaType::QVariant. It is no longer mapped to user type. COM objects expect that untyped out- parameters, which are mapped to QVariant& by ActiveQt, are passed in as VT_VARIANT|VT_BYREF. Update our variant-conversion logic accordingly. If the typeName, which comes from the generated function signature, is "QVariant", then QMetaType::fromName(typeName) will always be QMetaType::QVariant, and had to be passed as VT_VARIANT. Fix the logic for deciding whether we have to write back the out- parameters so that it works when QAxScript::call is used. We need to write back no matter whether it's a property or a getter, so check whether any bit is set, not if both are set. Add some test for this. Not cherry-picking this further back, the auto-test coverage of ActiveQt is not good enough to make sure that we don't break any subtle usecases in e.g. QAxServer, and the usage of QAxScript does not seem to be very wide. Fixes: QTBUG-111718 Pick-to: 6.5 Change-Id: I239f71c3637ea9f32dff5123a8ada96e0a894371 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qaxscript/tst_qaxscript.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/auto/qaxscript/tst_qaxscript.cpp b/tests/auto/qaxscript/tst_qaxscript.cpp
index 227e853..454b347 100644
--- a/tests/auto/qaxscript/tst_qaxscript.cpp
+++ b/tests/auto/qaxscript/tst_qaxscript.cpp
@@ -14,6 +14,7 @@ class tst_QAxScript : public QObject
private slots:
void scriptReturnValue();
+ void scriptOutParameters();
};
void tst_QAxScript::scriptReturnValue()
@@ -30,5 +31,40 @@ void tst_QAxScript::scriptReturnValue()
QCOMPARE(result, QVariant(u"test"_s));
}
+void tst_QAxScript::scriptOutParameters()
+{
+ QAxScriptManager scriptManager;
+ const auto scriptCode = uR"VB(
+ Function GetProductName(ByRef manufacturer, ByRef name, ByRef version)
+ manufacturer = "The Qt Company"
+ name = "ActiveQt"
+ version = 650
+ On Error Resume Next
+ GetProductName = 42
+ End Function
+ )VB"_s;
+
+ QAxScript *script = scriptManager.load(scriptCode, u"Test"_s, u"VBScript"_s);
+ QVERIFY2(script, "Unable to load script (CoInitializeEx() called?)");
+
+ QVariant returnValue;
+ QList<QVariant> results = {{}, {}, {}};
+
+ returnValue = script->scriptEngine()->dynamicCall("GetProductName(QVariant&,QVariant&,QVariant&)", results);
+ QCOMPARE(returnValue, 42);
+ QCOMPARE(results.size(), 3);
+ QCOMPARE(results.at(0), "The Qt Company");
+ QCOMPARE(results.at(1), "ActiveQt");
+ QCOMPARE(results.at(2), 650);
+
+ results = {{}, {}, {}};
+ returnValue = script->call("GetProductName(QVariant&,QVariant&,QVariant&)", results);
+ QCOMPARE(returnValue, 42);
+ QCOMPARE(results.size(), 3);
+ QCOMPARE(results.at(0), "The Qt Company");
+ QCOMPARE(results.at(1), "ActiveQt");
+ QCOMPARE(results.at(2), 650);
+}
+
QTEST_MAIN(tst_QAxScript)
#include "tst_qaxscript.moc"