diff options
author | shubham656 <shubham656jain@gmail.com> | 2021-01-26 21:33:53 +0530 |
---|---|---|
committer | Andreas Heinisch <andreas.heinisch@yahoo.de> | 2021-02-17 15:34:22 +0100 |
commit | 30ca77c43ba1c8f94d6f34eea763a3d3ca7e72f6 (patch) | |
tree | 6a40ca5219c8c7db235d0c1c93639f2e25d4416a /basic/qa/cppunit | |
parent | 0c8bff4622d9a0b725e035652d1aaf286c87cbd8 (diff) |
tdf#130677 Write new tests for literals
Change-Id: I22607fdcaab840ca1512abf534712d36d4b5ee9b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109964
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-by: Andreas Heinisch <andreas.heinisch@yahoo.de>
Tested-by: Jenkins
Diffstat (limited to 'basic/qa/cppunit')
-rw-r--r-- | basic/qa/cppunit/test_scanner.cxx | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/basic/qa/cppunit/test_scanner.cxx b/basic/qa/cppunit/test_scanner.cxx index ed340755deba..5663c44d027e 100644 --- a/basic/qa/cppunit/test_scanner.cxx +++ b/basic/qa/cppunit/test_scanner.cxx @@ -1034,6 +1034,83 @@ void ScannerTest::testHexOctal() CPPUNIT_ASSERT_EQUAL(cr, symbols[1].text); // ERRCODE_BASIC_MATH_OVERFLOW CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors)); + + // maximum for Hex & = SbxLONG + symbols = getSymbols("&H7FFFFFFF&"); + CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2147483647.0, 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); + + // minimum for Hex & = SbxLONG + symbols = getSymbols("&H80000000&"); + CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-2147483648.0, 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); + + // overflow for Hex & = SbxLONG + symbols = getSymbols("&H100000000&", errors); + CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0, 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); + // ERRCODE_BASIC_MATH_OVERFLOW + CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors)); + + // maximum for Octal & = SbxLONG + symbols = getSymbols("&O17777777777&"); + CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2147483647.0, 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); + + // minimum for Octal & = SbxLONG + symbols = getSymbols("&O20000000000&", errors); + CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(-2147483648.0, 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); + + // overflow for Octal & = SbxLONG + symbols = getSymbols("&O40000000000&", errors); + CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(0, 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); + // ERRCODE_BASIC_MATH_OVERFLOW + CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned int>(errors)); + + /* test for leading zeros */ + + // &H0000000FFFF = 65535 + symbols = getSymbols("&H0000000FFFF"); + 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); + + // &O00000123 = 83 + symbols = getSymbols("&O00000123"); + CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(83.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); + + symbols = getSymbols("&O7777777"); + CPPUNIT_ASSERT_EQUAL(size_t(2), symbols.size()); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2097151.0, 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() |