summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorAndreas Heinisch <andreas.heinisch@yahoo.de>2019-09-26 07:55:37 +0200
committerStephan Bergmann <sbergman@redhat.com>2019-09-27 18:22:26 +0200
commitd5b7627a0e738c0866b819910153b96b611813f8 (patch)
tree03f1cde7ed1286ee7bc3b4ac19d88d3163a47352 /basic
parent52f16d1f1d3d2712313fb50014474f43a1528c32 (diff)
tdf#62326 - Macros: Converting Hex strings of negative value
If the value of the hex string lies within the range of 0x8000 (SbxMAXINT + 1) and 0xFFFF (SbxMAXUINT) inclusive, cast the value to 16 bit in order to get signed integers, e.g., SbxMININT through SbxMAXINT. Moved unit test to test_scanner.cxx in order to test basic hex convertations. Removed old vba unit tests. Change-Id: I247b41c40197afc5328ef5685c758c1dd1cefae5 Reviewed-on: https://gerrit.libreoffice.org/79583 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'basic')
-rw-r--r--basic/qa/basic_coverage/test_hexliteral_negIntLimit-2.vb18
-rw-r--r--basic/qa/basic_coverage/test_hexliteral_negIntLimit.vb18
-rw-r--r--basic/qa/basic_coverage/test_hexliteral_posIntLimit.vb18
-rw-r--r--basic/qa/basic_coverage/test_hexliteral_zeroIntLimit.vb18
-rw-r--r--basic/qa/cppunit/test_scanner.cxx65
-rw-r--r--basic/source/comp/scanner.cxx5
6 files changed, 69 insertions, 73 deletions
diff --git a/basic/qa/basic_coverage/test_hexliteral_negIntLimit-2.vb b/basic/qa/basic_coverage/test_hexliteral_negIntLimit-2.vb
deleted file mode 100644
index c660486a5618..000000000000
--- a/basic/qa/basic_coverage/test_hexliteral_negIntLimit-2.vb
+++ /dev/null
@@ -1,18 +0,0 @@
-'
-' 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/.
-'
-
-
-Function doUnitTest as Integer
- Dim lngDecimal as Long
- lngDecimal = Clng(&H80000000)
- If lngDecimal = -2147483648 Then
- doUnitTest = 1
- Else
- doUnitTest = 0
- End If
-End Function
diff --git a/basic/qa/basic_coverage/test_hexliteral_negIntLimit.vb b/basic/qa/basic_coverage/test_hexliteral_negIntLimit.vb
deleted file mode 100644
index f33d74cf8dd9..000000000000
--- a/basic/qa/basic_coverage/test_hexliteral_negIntLimit.vb
+++ /dev/null
@@ -1,18 +0,0 @@
-'
-' 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/.
-'
-
-
-Function doUnitTest as Integer
- Dim lngDecimal as Long
- lngDecimal = Clng(&HFFFFFFFF)
- If lngDecimal = -1 Then
- doUnitTest = 1
- Else
- doUnitTest = 0
- End If
-End Function
diff --git a/basic/qa/basic_coverage/test_hexliteral_posIntLimit.vb b/basic/qa/basic_coverage/test_hexliteral_posIntLimit.vb
deleted file mode 100644
index a03dadc42095..000000000000
--- a/basic/qa/basic_coverage/test_hexliteral_posIntLimit.vb
+++ /dev/null
@@ -1,18 +0,0 @@
-'
-' 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/.
-'
-
-
-Function doUnitTest as Integer
- Dim lngDecimal as Long
- lngDecimal = Clng(&H7FFFFFFF)
- If lngDecimal = 2147483647 Then
- doUnitTest = 1
- Else
- doUnitTest = 0
- End If
-End Function
diff --git a/basic/qa/basic_coverage/test_hexliteral_zeroIntLimit.vb b/basic/qa/basic_coverage/test_hexliteral_zeroIntLimit.vb
deleted file mode 100644
index 1a02bdebfb6f..000000000000
--- a/basic/qa/basic_coverage/test_hexliteral_zeroIntLimit.vb
+++ /dev/null
@@ -1,18 +0,0 @@
-'
-' 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/.
-'
-
-
-Function doUnitTest as Integer
- Dim lngDecimal as Long
- lngDecimal = Clng(&H0)
- If lngDecimal = 0 Then
- doUnitTest = 1
- Else
- doUnitTest = 0
- End If
-End Function
diff --git a/basic/qa/cppunit/test_scanner.cxx b/basic/qa/cppunit/test_scanner.cxx
index e81af6106542..511be7b486e0 100644
--- a/basic/qa/cppunit/test_scanner.cxx
+++ b/basic/qa/cppunit/test_scanner.cxx
@@ -779,6 +779,15 @@ namespace
const OUString source8("&O123000000000000000000000");
const OUString source9("&H1.23");
+ // tdf#62323, tdf#62326 - conversion of Hex literals to basic signed Integers
+ const OUString source10("&H0");
+ const OUString source11("&H8000");
+ const OUString source12("&H80000000");
+ const OUString source13("&HFFFF");
+ const OUString source14("&HFFFFFFFF");
+ const OUString source15("&H7FFF");
+ const OUString source16("&H7FFFFFFF");
+
std::vector<Symbol> symbols;
symbols = getSymbols(source1);
@@ -860,6 +869,62 @@ namespace
CPPUNIT_ASSERT_EQUAL(OUString(), symbols[1].text);
CPPUNIT_ASSERT_EQUAL(SbxDOUBLE, symbols[1].type);
CPPUNIT_ASSERT_EQUAL(cr, symbols[2].text);
+
+ // &H0 = 0
+ symbols = getSymbols(source10);
+ CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, symbols[0].number, 1E-12);
+ CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
+ CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
+ CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
+
+ // &H8000 = -32768
+ symbols = getSymbols(source11);
+ CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(SbxMININT, symbols[0].number, 1E-12);
+ CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
+ CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
+ CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
+
+ // &H80000000 = -2147483648
+ symbols = getSymbols(source12);
+ CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(SbxMINLNG, symbols[0].number, 1E-12);
+ CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
+ CPPUNIT_ASSERT_EQUAL(SbxLONG, symbols[0].type);
+ CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
+
+ // &HFFFF = -1
+ symbols = getSymbols(source13);
+ CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, symbols[0].number, 1E-12);
+ CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
+ CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
+ CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
+
+ // &HFFFFFFFF = -1
+ symbols = getSymbols(source14);
+ CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, symbols[0].number, 1E-12);
+ CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
+ CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
+ CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
+
+ // &H7FFF = 32767
+ symbols = getSymbols(source15);
+ CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(SbxMAXINT, symbols[0].number, 1E-12);
+ CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
+ CPPUNIT_ASSERT_EQUAL(SbxINTEGER, symbols[0].type);
+ CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
+
+ // &H7FFFFFFF = 2147483647
+ symbols = getSymbols(source16);
+ CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size());
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(SbxMAXLNG, symbols[0].number, 1E-12);
+ CPPUNIT_ASSERT_EQUAL(OUString(), symbols[0].text);
+ CPPUNIT_ASSERT_EQUAL(SbxLONG, symbols[0].type);
+ CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text);
}
void ScannerTest::testTdf103104()
diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 77424d4a369f..f08c0178d38e 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -487,7 +487,10 @@ bool SbiScanner::NextSym()
++nLineIdx;
++nCol;
}
- sal_Int32 ls = static_cast<sal_Int32>(lu);
+ // tdf#62326 - If the value of the hex string lies within the range of 0x8000 (SbxMAXINT + 1)
+ // and 0xFFFF (SbxMAXUINT) inclusive, cast the value to 16 bit in order to get
+ // signed integers, e.g., SbxMININT through SbxMAXINT
+ sal_Int32 ls = (lu > SbxMAXINT && lu <= SbxMAXUINT) ? static_cast<sal_Int16>(lu) : static_cast<sal_Int32>(lu);
nVal = static_cast<double>(ls);
eScanType = ( ls >= SbxMININT && ls <= SbxMAXINT ) ? SbxINTEGER : SbxLONG;
if( bOverflow )