udkapi/UnoApi_udkapi.mk                     |    1 +
 udkapi/org/libreoffice/embindtest/Enum.idl  |   21 +++++++++++++++++++++
 udkapi/org/libreoffice/embindtest/XTest.idl |    4 ++++
 unotest/source/embindtest/embindtest.cxx    |   26 ++++++++++++++++++++++++++
 unotest/source/embindtest/embindtest.js     |   16 ++++++++++++++++
 5 files changed, 68 insertions(+)

New commits:
commit 6cc09586f583e6509cf7bda052f365ddc3bca16e
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Wed Feb 28 15:50:35 2024 +0100
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Thu Feb 29 07:54:11 2024 +0100

    Test Embind'ing of UNO enums
    
    Change-Id: I87d55236ee09b80aadcc95e2c0f06f15b9e24a44
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164100
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>

diff --git a/udkapi/UnoApi_udkapi.mk b/udkapi/UnoApi_udkapi.mk
index 15164a798006..34117950d64e 100644
--- a/udkapi/UnoApi_udkapi.mk
+++ b/udkapi/UnoApi_udkapi.mk
@@ -523,6 +523,7 @@ $(eval $(call 
gb_UnoApi_add_idlfiles,udkapi,com/sun/star/util,\
 ifeq ($(OS)-$(ENABLE_DBGUTIL),EMSCRIPTEN-TRUE)
 $(eval $(call gb_UnoApi_add_idlfiles,udkapi,org/libreoffice/embindtest, \
     Constants \
+    Enum \
     Struct \
     XTest \
 ))
diff --git a/udkapi/org/libreoffice/embindtest/Enum.idl 
b/udkapi/org/libreoffice/embindtest/Enum.idl
new file mode 100644
index 000000000000..9056687aa0a6
--- /dev/null
+++ b/udkapi/org/libreoffice/embindtest/Enum.idl
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+module org { module libreoffice { module embindtest {
+
+enum Enum {
+    E_10 = -10,
+    E_2 = -2,
+    E1 = 1,
+    E3 = 3
+};
+
+}; }; };
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/udkapi/org/libreoffice/embindtest/XTest.idl 
b/udkapi/org/libreoffice/embindtest/XTest.idl
index 36aae5c7c394..f64a3857e863 100644
--- a/udkapi/org/libreoffice/embindtest/XTest.idl
+++ b/udkapi/org/libreoffice/embindtest/XTest.idl
@@ -34,6 +34,8 @@ interface XTest {
     boolean isChar([in] char value);
     string getString();
     boolean isString([in] string value);
+    Enum getEnum();
+    boolean isEnum([in] Enum value);
     Struct getStruct();
     boolean isStruct([in] Struct value);
     sequence<boolean> getSequenceBoolean();
@@ -62,6 +64,8 @@ interface XTest {
     boolean isSequenceString([in] sequence<string> value);
     sequence<sequence<string> > getSequenceSequenceString();
     boolean isSequenceSequenceString([in] sequence<sequence<string> > value);
+    sequence<Enum> getSequenceEnum();
+    boolean isSequenceEnum([in] sequence<Enum> value);
     sequence<Struct> getSequenceStruct();
     boolean isSequenceStruct([in] sequence<Struct> value);
 };
diff --git a/unotest/source/embindtest/embindtest.cxx 
b/unotest/source/embindtest/embindtest.cxx
index 152afe551e5b..2a9cdfc4de3a 100644
--- a/unotest/source/embindtest/embindtest.cxx
+++ b/unotest/source/embindtest/embindtest.cxx
@@ -76,6 +76,16 @@ public:
 
     sal_Bool SAL_CALL isString(OUString const& value) override { return value 
== u"hä"; }
 
+    org::libreoffice::embindtest::Enum SAL_CALL getEnum() override
+    {
+        return org::libreoffice::embindtest::Enum_E_2;
+    }
+
+    sal_Bool SAL_CALL isEnum(org::libreoffice::embindtest::Enum value) override
+    {
+        return value == org::libreoffice::embindtest::Enum_E_2;
+    }
+
     org::libreoffice::embindtest::Struct SAL_CALL getStruct() override
     {
         return { -123456, 100.5, u"hä"_ustr };
@@ -217,6 +227,22 @@ public:
                                                                     { 
u"baz"_ustr } };
     }
 
+    css::uno::Sequence<org::libreoffice::embindtest::Enum> SAL_CALL 
getSequenceEnum() override
+    {
+        return { org::libreoffice::embindtest::Enum_E_2, 
org::libreoffice::embindtest::Enum_E3,
+                 org::libreoffice::embindtest::Enum_E_10 };
+    }
+
+    sal_Bool SAL_CALL
+    isSequenceEnum(css::uno::Sequence<org::libreoffice::embindtest::Enum> 
const& value) override
+    {
+        return value
+               == css::uno::Sequence<org::libreoffice::embindtest::Enum>{
+                      org::libreoffice::embindtest::Enum_E_2, 
org::libreoffice::embindtest::Enum_E3,
+                      org::libreoffice::embindtest::Enum_E_10
+                  };
+    }
+
     css::uno::Sequence<org::libreoffice::embindtest::Struct> SAL_CALL 
getSequenceStruct() override
     {
         return { { -123456, -100.5, u"foo"_ustr },
diff --git a/unotest/source/embindtest/embindtest.js 
b/unotest/source/embindtest/embindtest.js
index 4eb9e60832e6..1978c9cc4ec7 100644
--- a/unotest/source/embindtest/embindtest.js
+++ b/unotest/source/embindtest/embindtest.js
@@ -84,6 +84,12 @@ Module.addOnPostRun(function() {
         console.assert(v === 'hä');
         console.assert(test.isString(v));
     }
+    {
+        let v = test.getEnum();
+        console.log(v);
+        console.assert(v === uno.org.libreoffice.embindtest.Enum.E_2);
+        console.assert(test.isEnum(v));
+    }
     {
         let v = test.getStruct();
         console.log(v.m1 + ', ' + v.m2 + ', ' + v.m3);
@@ -231,6 +237,16 @@ Module.addOnPostRun(function() {
         console.assert(test.isSequenceSequenceString(v));
         v.delete();
     }
+    {
+        let v = test.getSequenceEnum();
+        console.log(v);
+        console.assert(v.size() === 3);
+        console.assert(v.get(0) == uno.org.libreoffice.embindtest.Enum.E_2);
+        console.assert(v.get(1) == uno.org.libreoffice.embindtest.Enum.E3);
+        console.assert(v.get(2) == uno.org.libreoffice.embindtest.Enum.E_10);
+        console.assert(test.isSequenceEnum(v));
+        v.delete();
+    }
     {
         let v = test.getSequenceStruct();
         console.log(v);

Reply via email to