offapi/UnoApi_offapi.mk                           |    1 
 offapi/org/libreoffice/embindtest/XAttributes.idl |   20 ++++++++++++++
 offapi/org/libreoffice/embindtest/XTest.idl       |    1 
 unotest/source/embindtest/embindtest.cxx          |   12 ++++++++
 unotest/source/embindtest/embindtest.js           |   31 +++++++++++++++++++---
 5 files changed, 62 insertions(+), 3 deletions(-)

New commits:
commit e8e6a5f7951da0cf94171fd4b9457864e9528a08
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Tue Jul 16 10:00:50 2024 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Tue Jul 16 12:48:40 2024 +0200

    Add test code for UNO attributes implemented in JS
    
    Change-Id: I74f5ef53e7850ab783ae4cd94525a55c63512bd3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170544
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>

diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index 096a55e69d38..864346d584dc 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -4446,6 +4446,7 @@ $(eval $(call 
gb_UnoApi_add_idlfiles,offapi,org/libreoffice/embindtest, \
     Struct \
     StructLong \
     StructString \
+    XAttributes \
     XTest \
 ))
 $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,org/libreoffice/embindtest, \
diff --git a/offapi/org/libreoffice/embindtest/XAttributes.idl 
b/offapi/org/libreoffice/embindtest/XAttributes.idl
new file mode 100644
index 000000000000..f6f637c9c00a
--- /dev/null
+++ b/offapi/org/libreoffice/embindtest/XAttributes.idl
@@ -0,0 +1,20 @@
+/* -*- 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 {
+
+interface XAttributes {
+    [attribute] long LongAttribute;
+    [attribute] string StringAttribute;
+    [attribute, readonly] boolean ReadOnlyAttribute;
+};
+
+}; }; };
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/offapi/org/libreoffice/embindtest/XTest.idl 
b/offapi/org/libreoffice/embindtest/XTest.idl
index 1f09c388e30a..370363cf9a09 100644
--- a/offapi/org/libreoffice/embindtest/XTest.idl
+++ b/offapi/org/libreoffice/embindtest/XTest.idl
@@ -129,6 +129,7 @@ interface XTest {
     void passJob([in] com::sun::star::task::XJob object);
     void passJobExecutor([in] com::sun::star::task::XJobExecutor object);
     void passInterface([in] com::sun::star::uno::XInterface object);
+    boolean checkAttributes([in] org::libreoffice::embindtest::XAttributes 
object);
     [attribute] string StringAttribute;
 };
 
diff --git a/unotest/source/embindtest/embindtest.cxx 
b/unotest/source/embindtest/embindtest.cxx
index bea60633dd3e..01e18d0b42f4 100644
--- a/unotest/source/embindtest/embindtest.cxx
+++ b/unotest/source/embindtest/embindtest.cxx
@@ -604,6 +604,18 @@ class Test : public 
cppu::WeakImplHelper<org::libreoffice::embindtest::XTest>
             ->trigger(u"queried executor"_ustr);
     }
 
+    sal_Bool SAL_CALL checkAttributes(
+        css::uno::Reference<org::libreoffice::embindtest::XAttributes> const& 
object) override
+    {
+        auto const ok1 = object->getLongAttribute() == 789;
+        assert(ok1);
+        auto const ok2 = object->getStringAttribute() == u"foo"_ustr;
+        assert(ok2);
+        auto const ok3 = object->getReadOnlyAttribute();
+        assert(ok3);
+        return ok1 && ok2 && ok3;
+    }
+
     OUString SAL_CALL getStringAttribute() override { return stringAttribute_; 
}
 
     void SAL_CALL setStringAttribute(OUString const& value) override { 
stringAttribute_ = value; }
diff --git a/unotest/source/embindtest/embindtest.js 
b/unotest/source/embindtest/embindtest.js
index be8fc1581066..e923a4f85d0a 100644
--- a/unotest/source/embindtest/embindtest.js
+++ b/unotest/source/embindtest/embindtest.js
@@ -647,7 +647,8 @@ Module.addOnPostRun(function() {
         any.delete();
     }
     const obj = Module.unoObject(
-        ['com.sun.star.task.XJob', 'com.sun.star.task.XJobExecutor'],
+        ['com.sun.star.task.XJob', 'com.sun.star.task.XJobExecutor',
+         'org.libreoffice.embindtest.XAttributes'],
         {
             execute(args) {
                 if (args.size() !== 1 || args.get(0).Name !== 'name') {
@@ -658,14 +659,22 @@ Module.addOnPostRun(function() {
                 console.log('Hello ' + args.get(0).Value.get());
                 return new Module.uno_Any(Module.uno_Type.Void(), undefined);
             },
-            trigger(event) { console.log('Ola ' + event); }
+            trigger(event) { console.log('Ola ' + event); },
+            the_LongAttribute: -123456,
+            getLongAttribute() { return this.the_LongAttribute; },
+            setLongAttribute(value) { this.the_LongAttribute = value; },
+            the_StringAttribute: 'hä',
+            getStringAttribute() { return this.the_StringAttribute; },
+            setStringAttribute(value) { this.the_StringAttribute = value; },
+            getReadOnlyAttribute() { return true; }
         });
     {
         const s = css.lang.XTypeProvider.query(obj).getTypes();
-        console.assert(s.size() === 3);
+        console.assert(s.size() === 4);
         console.assert(s.get(0).toString() === 
'com.sun.star.lang.XTypeProvider');
         console.assert(s.get(1).toString() === 'com.sun.star.task.XJob');
         console.assert(s.get(2).toString() === 
'com.sun.star.task.XJobExecutor');
+        console.assert(s.get(3).toString() === 
'org.libreoffice.embindtest.XAttributes');
         s.delete();
     }
     {
@@ -677,6 +686,21 @@ Module.addOnPostRun(function() {
     test.passJobExecutor(css.task.XJobExecutor.query(obj));
     test.passInterface(obj);
     css.task.XJobExecutor.query(obj).trigger('from JS');
+    {
+        const attrs = 
Module.uno.org.libreoffice.embindtest.XAttributes.query(obj);
+        console.assert(attrs.getLongAttribute() === -123456);
+        attrs.setLongAttribute(789);
+        console.assert(attrs.getLongAttribute() === 789);
+        console.assert(attrs.getStringAttribute() === 'hä');
+        attrs.setStringAttribute('foo');
+        console.assert(attrs.getStringAttribute() === 'foo');
+        console.assert(attrs.getReadOnlyAttribute() === 1); //TODO: true
+        try {
+            attrs.setReadOnlyAttribute(false);
+            console.assert(false);
+        } catch (e) {}
+        console.assert(test.checkAttributes(attrs));
+    }
     console.assert(test.getStringAttribute() === 'hä');
     test.setStringAttribute('foo');
     console.assert(test.getStringAttribute() === 'foo');
commit d2550cf13123702207097c2a09220a0ec8c89eda
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Tue Jul 16 09:58:06 2024 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Tue Jul 16 12:48:29 2024 +0200

    Test calling directly from JS a UNO method implemented in JS
    
    Change-Id: I46855474d2c183db9204bfea68cac94112e7766a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170543
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>
    Tested-by: Jenkins

diff --git a/unotest/source/embindtest/embindtest.js 
b/unotest/source/embindtest/embindtest.js
index 9482643ce9ec..be8fc1581066 100644
--- a/unotest/source/embindtest/embindtest.js
+++ b/unotest/source/embindtest/embindtest.js
@@ -676,6 +676,7 @@ Module.addOnPostRun(function() {
     test.passJob(css.task.XJob.query(obj));
     test.passJobExecutor(css.task.XJobExecutor.query(obj));
     test.passInterface(obj);
+    css.task.XJobExecutor.query(obj).trigger('from JS');
     console.assert(test.getStringAttribute() === 'hä');
     test.setStringAttribute('foo');
     console.assert(test.getStringAttribute() === 'foo');

Reply via email to