summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2022-09-18 21:57:21 +0200
committerAndreas Heinisch <andreas.heinisch@yahoo.de>2022-09-25 11:39:33 +0200
commit6f3532f6aaafb6ad58a9e32dc0eff43a0d54862b (patch)
tree6fa3187cc97d7d2a125794d6830a9a439856b18d
parent2aed71fa9e8a36ff2dc9f48897092c26ab89ea9e (diff)
tdf#151012 - Initialize optional parameters with their default values
Change-Id: I3ed3eb904b50892e5946abe684e801819ba296e6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140128 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
-rw-r--r--basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas4
-rw-r--r--basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb4
-rw-r--r--basic/source/runtime/methods.cxx49
3 files changed, 32 insertions, 25 deletions
diff --git a/basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas b/basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas
index dabb23c0faf1..67378213e287 100644
--- a/basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas
+++ b/basic/qa/basic_coverage/test_tdf147529_optional_parameters_msgbox.bas
@@ -18,9 +18,7 @@ Sub verify_testOptionalParametersMsgBox
On Error GoTo errorHandler
' tdf#147529 - check for missing optional parameters
- TestUtil.AssertEqual(TestOptionalParametersMsgBox(), True, "TestOptionalParametersMsgBox()")
- TestUtil.AssertEqual(TestOptionalParametersMsgBox("test"), True, "TestOptionalParametersMsgBox(""test"")")
- TestUtil.AssertEqual(TestOptionalParametersMsgBox("test", 1), True, "TestOptionalParametersMsgBox(""test"", 1)")
+ TestUtil.AssertEqual(TestOptionalParametersMsgBox(), True, "TestOptionalParametersMsgBox()")
Exit Sub
errorHandler:
diff --git a/basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb b/basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb
index dabe552a821b..e599f46eedf1 100644
--- a/basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb
+++ b/basic/qa/vba_tests/tdf147529_optional_parameters_msgbox.vb
@@ -19,9 +19,7 @@ Sub verify_testOptionalParametersMsgBox
On Error GoTo errorHandler
' tdf#147529 - check for missing optional parameters
- TestUtil.AssertEqual(TestOptionalParametersMsgBox(), True, "TestOptionalParametersMsgBox()")
- TestUtil.AssertEqual(TestOptionalParametersMsgBox("test"), True, "TestOptionalParametersMsgBox(""test"")")
- TestUtil.AssertEqual(TestOptionalParametersMsgBox("test", 1), True, "TestOptionalParametersMsgBox(""test"", 1)")
+ TestUtil.AssertEqual(TestOptionalParametersMsgBox(), True, "TestOptionalParametersMsgBox()")
Exit Sub
errorHandler:
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 3b718d78a9af..9cc839a1e154 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -3285,6 +3285,28 @@ void SbRtl_Format(StarBASIC *, SbxArray & rPar, bool)
}
}
+static bool IsMissing(SbxArray& rPar, const sal_uInt32 i)
+{
+ const sal_uInt32 nArgCount = rPar.Count();
+ if (nArgCount <= i)
+ return true;
+
+ SbxVariable* aPar = rPar.Get(i);
+ return (aPar->GetType() == SbxERROR && SbiRuntime::IsMissing(aPar, 1));
+}
+
+static sal_Int16 GetOptionalIntegerParamOrDefault(SbxArray& rPar, const sal_uInt32 i,
+ const sal_Int16 defaultValue)
+{
+ return IsMissing(rPar, i) ? defaultValue : rPar.Get(i)->GetInteger();
+}
+
+static OUString GetOptionalOUStringParamOrDefault(SbxArray& rPar, const sal_uInt32 i,
+ const OUString& defaultValue)
+{
+ return IsMissing(rPar, i) ? defaultValue : rPar.Get(i)->GetOUString();
+}
+
static void lcl_FormatNumberPercent(SbxArray& rPar, bool isPercent)
{
const sal_uInt32 nArgCount = rPar.Count();
@@ -4328,19 +4350,15 @@ void SbRtl_MsgBox(StarBASIC *, SbxArray & rPar, bool)
return;
}
- // tdf#147529 - check for missing optional parameters
- for (sal_uInt32 i = 2; i < nArgCount; i++)
+ // tdf#147529 - check for missing parameters
+ if (IsMissing(rPar, 1))
{
- if (rPar.Get(i)->GetType() == SbxERROR && SbiRuntime::IsMissing(rPar.Get(i), 1))
- {
- StarBASIC::Error(ERRCODE_BASIC_NOT_OPTIONAL);
- return;
- }
+ StarBASIC::Error(ERRCODE_BASIC_NOT_OPTIONAL);
+ return;
}
- WinBits nType = 0; // MB_OK
- if( nArgCount >= 3 )
- nType = static_cast<WinBits>(rPar.Get(2)->GetInteger());
+ // tdf#151012 - initialize optional parameters with their default values (number of buttons)
+ WinBits nType = static_cast<WinBits>(GetOptionalIntegerParamOrDefault(rPar, 2, 0)); // MB_OK
WinBits nStyle = nType;
nStyle &= 15; // delete bits 4-16
if (nStyle > 5)
@@ -4358,15 +4376,8 @@ void SbRtl_MsgBox(StarBASIC *, SbxArray & rPar, bool)
};
OUString aMsg = rPar.Get(1)->GetOUString();
- OUString aTitle;
- if( nArgCount >= 4 )
- {
- aTitle = rPar.Get(3)->GetOUString();
- }
- else
- {
- aTitle = Application::GetDisplayName();
- }
+ // tdf#151012 - initialize optional parameters with their default values (title of dialog box)
+ OUString aTitle = GetOptionalOUStringParamOrDefault(rPar, 3, Application::GetDisplayName());
WinBits nDialogType = nType & (16+32+64);