summaryrefslogtreecommitdiff
path: root/sc/qa/extras
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2020-03-21 14:59:27 +0100
committerMike Kaganski <mike.kaganski@collabora.com>2020-03-24 09:30:38 +0100
commit16b0bbb671a8080655e27542e576478486810404 (patch)
treee52bdd72fbc33308ba9ced4dfdaf0a0258dacc35 /sc/qa/extras
parent2846686272931cd8bb0bcd452dd0e8b5b52064b1 (diff)
tdf#131296: get numeric value with its data type in StepLOADNC
In order to load numeric values, generate SbiOpcode::NUMBER_ opcodes including the numeric value and its data type instead of SbiOpcode::CONST_. The numeric value and its data type will be restored in SbiRuntime::StepLOADNC. When the new compiled code is stored in documents, e.g. password-protected libraries, leagcy LO versions will just read up to non-numeric characters, thus correctly obtaining number value and ignoring the type, so the change is backward-compatible. To interpret legacy compiled code, old treatment of SbiRuntime::StepLOADI is restored, reverting commit 0b4f8bf571baf2ccd5a8aafdc4deb41867420be3. This change reimplements the fix for tdf#129596. Change-Id: I46ebfc77f9bea69479968950c0fb7264e4a7ab27 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90858 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc/qa/extras')
-rw-r--r--sc/qa/extras/macros-test.cxx83
-rw-r--r--sc/qa/extras/testdocuments/tdf131296_legacy.odsbin0 -> 15932 bytes
-rw-r--r--sc/qa/extras/testdocuments/tdf131296_new.odsbin0 -> 16734 bytes
3 files changed, 83 insertions, 0 deletions
diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx
index f887a95f7223..3801a9998895 100644
--- a/sc/qa/extras/macros-test.cxx
+++ b/sc/qa/extras/macros-test.cxx
@@ -37,6 +37,8 @@ public:
void testPasswordProtectedStarBasic();
void testRowColumn();
void testPasswordProtectedUnicodeString();
+ void testTdf131296_legacy();
+ void testTdf131296_new();
CPPUNIT_TEST_SUITE(ScMacrosTest);
CPPUNIT_TEST(testStarBasic);
@@ -45,6 +47,8 @@ public:
CPPUNIT_TEST(testPasswordProtectedStarBasic);
CPPUNIT_TEST(testRowColumn);
CPPUNIT_TEST(testPasswordProtectedUnicodeString);
+ CPPUNIT_TEST(testTdf131296_legacy);
+ CPPUNIT_TEST(testTdf131296_new);
CPPUNIT_TEST_SUITE_END();
};
@@ -453,6 +457,85 @@ void ScMacrosTest::testPasswordProtectedUnicodeString()
xCloseable->close(true);
}
+void ScMacrosTest::testTdf131296_legacy()
+{
+ // For legacy password-protected library images, we must correctly get the constants' values,
+ // and also - for Integer - the type.
+ const std::vector<std::pair<OUString, OUString>> aTests({
+ { "TestIntConst", "Integer: 123" },
+ { "TestLongConst", "Double: 123" },
+ { "TestSingleConst", "Double: 123" },
+ { "TestDoubleConst", "Double: 123" },
+ });
+
+ OUString aFileName;
+ createFileURL("tdf131296_legacy.ods", aFileName);
+ auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument");
+ CPPUNIT_ASSERT(xComponent);
+
+ {
+ Any aRet;
+ Sequence<sal_Int16> aOutParamIndex;
+ Sequence<Any> aOutParam;
+ Sequence<uno::Any> aParams;
+
+ for (auto& [sTestName, sExpected] : aTests)
+ {
+ SfxObjectShell::CallXScript(xComponent,
+ "vnd.sun.Star.script:Protected.Module1." + sTestName
+ + "?language=Basic&location=document",
+ aParams, aRet, aOutParamIndex, aOutParam);
+
+ OUString aReturnValue;
+ aRet >>= aReturnValue;
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue);
+ }
+ }
+
+ css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW);
+ xCloseable->close(true);
+}
+
+void ScMacrosTest::testTdf131296_new()
+{
+ // For new password-protected library images, we must correctly get both the constants' values
+ // and their types.
+ const std::vector<std::pair<OUString, OUString>> aTests({
+ { "TestIntConst", "Integer: 123" },
+ { "TestLongConst", "Long: 123" },
+ { "TestSingleConst", "Single: 123" },
+ { "TestDoubleConst", "Double: 123" },
+ { "TestCurrencyConst", "Currency: 123.0000" },
+ });
+
+ OUString aFileName;
+ createFileURL("tdf131296_new.ods", aFileName);
+ auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument");
+ CPPUNIT_ASSERT(xComponent);
+
+ {
+ Any aRet;
+ Sequence<sal_Int16> aOutParamIndex;
+ Sequence<Any> aOutParam;
+ Sequence<uno::Any> aParams;
+
+ for (auto& [sTestName, sExpected] : aTests)
+ {
+ SfxObjectShell::CallXScript(xComponent,
+ "vnd.sun.Star.script:Protected.Module1." + sTestName
+ + "?language=Basic&location=document",
+ aParams, aRet, aOutParamIndex, aOutParam);
+
+ OUString aReturnValue;
+ aRet >>= aReturnValue;
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sTestName.toUtf8().getStr(), sExpected, aReturnValue);
+ }
+ }
+
+ css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW);
+ xCloseable->close(true);
+}
+
ScMacrosTest::ScMacrosTest()
: UnoApiTest("/sc/qa/extras/testdocuments")
{
diff --git a/sc/qa/extras/testdocuments/tdf131296_legacy.ods b/sc/qa/extras/testdocuments/tdf131296_legacy.ods
new file mode 100644
index 000000000000..43ebdeb24f67
--- /dev/null
+++ b/sc/qa/extras/testdocuments/tdf131296_legacy.ods
Binary files differ
diff --git a/sc/qa/extras/testdocuments/tdf131296_new.ods b/sc/qa/extras/testdocuments/tdf131296_new.ods
new file mode 100644
index 000000000000..9c0161c40ccd
--- /dev/null
+++ b/sc/qa/extras/testdocuments/tdf131296_new.ods
Binary files differ