Bug 124184 - Fix QA test for StrConv VBA function ( see comment 5)
Summary: Fix QA test for StrConv VBA function ( see comment 5)
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Tushar Kumar Rai
URL:
Whiteboard: target:7.2.0
Keywords: difficultyInteresting, easyHack, skillCpp, topicDebug
Depends on:
Blocks: 124066 Macro-QA
  Show dependency treegraph
 
Reported: 2019-03-18 21:37 UTC by Olivier Hallot
Modified: 2021-05-22 12:09 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments
Basic runtime error while running test. (125.38 KB, image/png)
2021-03-02 09:17 UTC, Tushar Kumar Rai
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Hallot 2019-03-18 21:37:14 UTC
The StrConv() VBA/BASIC function is implemented in LibreOffice but the QA test does not cover all possibilities of the arguments and parameters.

The QA test is available at 

https://opengrok.libreoffice.org/xref/core/basic/qa/vba_tests/strconv.vb?r=b9d75dea

The fix is to create a test or fix the existing QA test so that the function can be published and documented.

Then bug#124066 can be fixed and closed.
Comment 1 Gerhard Weydt 2019-03-18 22:27:11 UTC
A description of what is wrong with the code of the QA test can be found in Comment 3 of bug#124066.
Comment 2 Xisco Faulí 2019-06-26 09:42:26 UTC
@Raal, I thought you might be interested in this issue...
Comment 3 Xisco Faulí 2019-09-26 10:28:50 UTC
@Libreofficiant, I thought you might be interested in this issue...
Comment 4 Xisco Faulí 2020-07-22 21:08:00 UTC
Hello Olivier, Gerhard,
First attempt to improve the coverage in https://gerrit.libreoffice.org/c/core/+/99260
I'm not familiar with VBA at all so comments are appreciated
Comment 5 Mike Kaganski 2020-07-23 06:59:58 UTC
StrConv in LO does not implement handling its third argument (LCID). Without that, there's no way to create useful unit tests (since everything is system-dependent, and so different on different systems).

If someone wants to implement that, the code is SbRtl_StrConv in basic/source/runtime/methods.cxx; LCIDs (MS thing [1]) is represented in LO by LanguageType (include/i18nlangtag/lang.h), so it's directly usable in the SbRtl_StrConv function, that also internally uses a LanguageType value hardcoded to LANGUAGE_SYSTEM.

[1] https://msdn.microsoft.com/en-us/goglobal/bb964664
Comment 6 Tushar Kumar Rai 2021-03-02 09:17:33 UTC
Created attachment 170170 [details]
Basic runtime error while running test.

While running test in basic/qa/vba_tests/strconv.vb in my LO macros i am getting BASIC runtime error "TestUtil".

What is the problem here ?
 
Is this specific to my system or happening with everyone ?
Comment 7 Mike Kaganski 2021-03-02 09:28:11 UTC
(In reply to Tushar Kumar Rai from comment #6)

This is not specific to your system. This is a consequence of https://gerrit.libreoffice.org/c/core/+/107860, where we added a special module pre-loaded for unit tests (to remove duplication), but that mean that the tests depend on that module present. So you need to import basic/qa/vba_tests/_test_asserts.vb as a module "TestUtil" in your LO to be able to test.
Comment 8 Tushar Kumar Rai 2021-03-06 09:07:42 UTC
So the idea is something like this -
In file basic/source/runtime/methods.cxx in function SbRtl_StrConv -

Initialise
OUString lcid = rPar.Get32(3)->GetOUString();(lcid will be the locale_id which is passed by the user)

Then some changes in setting up the TransliterationFlags need to be done -

For example in case of Hiragana to Katakana conversion -

if ( (nConversion & 0x10) == 16 ) // vbKatakana
    {
        if (nArgCount == 2 && LANGUAGE_SYSTEM == LANGUAGE_JAPANESE)
            nType |= TransliterationFlags::HIRAGANA_KATAKANA;
        else if(nArgCount ==3 && lcid == "0x0411")
            nType |= TransliterationFlags::HIRAGANA_KATAKANA;
        else
            StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
    }

Basically if locale_id is not provided by user(number of arguments=2) then we need to check if the system locale id is that of Japan(because in vba strconv vbKatakana and vbHiragana applies to Japan only and cause run-time errors when used in locales where they do not apply)

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/strconv-function

And if localeid is provided by user(number of arguments=3) it has to be locale_id of Japan(0x0411)

Else it should throw runtime error.


One thing also to note in basic/qa/vba_tests/strconv.vb is that -

At line-
' Converts Hiragana characters in string to Katakana characters
    Module1.AssertEqual(StrConv("¤Ï¤Ê¤Á¤ã¤ó", vbKatakana), "¥Ï¥Ê¥Á¥ã¥ó", "StrConv(""¤Ï¤Ê¤Á¤ã¤ó"", vbKatakana)")

According to this line the expected output is "¥Ï¥Ê¥Á¥ã¥ó".

But when i checked online convertor of Hiragana to Katakana 

https://en.calc-site.com/letters/convert_kana

The outpot got is "¤Ï¤Ê¤Á¤ã¤ó".
I have checked few other online convertors and the result is same.So I guess this needs to be changed is test file as well.

This means that StrConv is working properly and there needs to be change in expected outputs in basic/qa/vba_tests/strconv.vb file.

Please correct me if i am wrong at any point.
Comment 9 Tushar Kumar Rai 2021-03-07 05:41:23 UTC Comment hidden (obsolete)
Comment 10 Mike Kaganski 2021-03-07 06:10:48 UTC
(In reply to Tushar Kumar Rai from comment #8)

What you write looks reasonable. But please let's talk at a gerrit change with your proposed code. There we can discuss right at the specific lines, discussing the code in detail.
Comment 11 Commit Notification 2021-05-01 11:12:46 UTC
tushar committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/6fecdeac5d81a60a479195a62cdc174b919f763b

tdf#124184 Fixing StrConv VBA Function

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 12 Tushar Kumar Rai 2021-05-03 18:27:30 UTC
Can someone verify the fix ?
Comment 13 Andreas Heinisch 2021-05-19 11:31:00 UTC
I think you can mark it as fixed :)