summaryrefslogtreecommitdiff
path: root/unotest
diff options
context:
space:
mode:
authorStephan Bergmann <stephan.bergmann@allotropia.de>2024-02-29 08:54:08 +0100
committerStephan Bergmann <stephan.bergmann@allotropia.de>2024-02-29 16:19:19 +0100
commit41feb036b44ffefca898f44ed95a2129d779da59 (patch)
tree54af13da6b7a2db122ae03d2d53a75c4124b4b70 /unotest
parent6588c30ed4477627b2623560ca867682b189bc80 (diff)
Some minimal Embind support for UNO type
...which should be rare enough in practical use that it should be sufficient to only have toString-functionality for instances mapped from C++ to JS, but no constructor for new instances on the JS side. (The natural choice for the latter would be a mapping of the C++ > inline Type( TypeClass eTypeClass, const ::rtl::OUString & rTypeName ); constructor, but which requires a mapping for the css::uno::TypeClass UNOIDL enum, which is only provided "later" through CustomTarget_static/unoembind, so would at least conceptually be a bit dirty.) This Embind mapping treats css::uno::Type as a smart pointer for the underlying typelib_TypeDescriptionReference, to benefit from the fallback garbage collection (in more recent Emscripten versions, at least) for smart pointers, obviating the need to call .delete() on each instance mapped to JS. Change-Id: Ic113967c264c28641dfd1fe159012c85519f4a9b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164140 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'unotest')
-rw-r--r--unotest/source/embindtest/embindtest.cxx24
-rw-r--r--unotest/source/embindtest/embindtest.js16
2 files changed, 40 insertions, 0 deletions
diff --git a/unotest/source/embindtest/embindtest.cxx b/unotest/source/embindtest/embindtest.cxx
index 2a9cdfc4de3a..8b131cd9f376 100644
--- a/unotest/source/embindtest/embindtest.cxx
+++ b/unotest/source/embindtest/embindtest.cxx
@@ -10,6 +10,8 @@
#include <sal/config.h>
#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/Type.hxx>
+#include <cppu/unotype.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/weak.hxx>
#include <org/libreoffice/embindtest/Struct.hpp>
@@ -76,6 +78,13 @@ public:
sal_Bool SAL_CALL isString(OUString const& value) override { return value == u"hä"; }
+ css::uno::Type SAL_CALL getType() override { return cppu::UnoType<sal_Int32>::get(); }
+
+ sal_Bool SAL_CALL isType(css::uno::Type const& value) override
+ {
+ return value == cppu::UnoType<sal_Int32>::get();
+ }
+
org::libreoffice::embindtest::Enum SAL_CALL getEnum() override
{
return org::libreoffice::embindtest::Enum_E_2;
@@ -213,6 +222,21 @@ public:
return value == css::uno::Sequence<OUString>{ u"foo"_ustr, u"barr"_ustr, u"bazzz"_ustr };
}
+ css::uno::Sequence<css::uno::Type> SAL_CALL getSequenceType() override
+ {
+ return { cppu::UnoType<sal_Int32>::get(), cppu::UnoType<void>::get(),
+ cppu::UnoType<css::uno::Sequence<org::libreoffice::embindtest::Enum>>::get() };
+ }
+
+ sal_Bool SAL_CALL isSequenceType(css::uno::Sequence<css::uno::Type> const& value) override
+ {
+ return value
+ == css::uno::Sequence<css::uno::Type>{
+ cppu::UnoType<sal_Int32>::get(), cppu::UnoType<void>::get(),
+ cppu::UnoType<css::uno::Sequence<org::libreoffice::embindtest::Enum>>::get()
+ };
+ }
+
css::uno::Sequence<css::uno::Sequence<OUString>> SAL_CALL getSequenceSequenceString() override
{
return { {}, { u"foo"_ustr, u"barr"_ustr }, { u"baz"_ustr } };
diff --git a/unotest/source/embindtest/embindtest.js b/unotest/source/embindtest/embindtest.js
index 1978c9cc4ec7..422c1c1a421f 100644
--- a/unotest/source/embindtest/embindtest.js
+++ b/unotest/source/embindtest/embindtest.js
@@ -85,6 +85,12 @@ Module.addOnPostRun(function() {
console.assert(test.isString(v));
}
{
+ let v = test.getType();
+ console.log(v);
+ console.assert(v.toString() === 'long');
+ console.assert(test.isType(v));
+ }
+ {
let v = test.getEnum();
console.log(v);
console.assert(v === uno.org.libreoffice.embindtest.Enum.E_2);
@@ -219,6 +225,16 @@ Module.addOnPostRun(function() {
v.delete();
}
{
+ let v = test.getSequenceType();
+ console.log(v);
+ console.assert(v.size() === 3);
+ console.assert(v.get(0).toString() === 'long');
+ console.assert(v.get(1).toString() === 'void');
+ console.assert(v.get(2).toString() === '[]org.libreoffice.embindtest.Enum');
+ console.assert(test.isSequenceType(v));
+ v.delete();
+ }
+ {
let v = test.getSequenceSequenceString();
console.log(v);
console.assert(v.size() === 3);