[Libreoffice-commits] .: 4 commits - basic/qa basic/source

August Sodora augsod at kemper.freedesktop.org
Sat Jan 14 15:40:17 PST 2012


 basic/qa/cppunit/test_scanner.cxx |   96 ++++++++++++++++++++++++++++++++++++++
 basic/source/comp/scanner.cxx     |   38 +++++++++------
 2 files changed, 119 insertions(+), 15 deletions(-)

New commits:
commit 244382e62e91f56c2f1461f6656a6e1f973ae1eb
Author: August Sodora <augsod at gmail.com>
Date:   Sat Jan 14 18:39:35 2012 -0500

    Add tests for hex/octal numbers for basic scanner

diff --git a/basic/qa/cppunit/test_scanner.cxx b/basic/qa/cppunit/test_scanner.cxx
index 3d34feb..785d23c 100644
--- a/basic/qa/cppunit/test_scanner.cxx
+++ b/basic/qa/cppunit/test_scanner.cxx
@@ -39,6 +39,7 @@ namespace
     void testExclamation();
     void testNumbers();
     void testDataType();
+    void testHexOctal();
 
     // Adds code needed to register the test suite
     CPPUNIT_TEST_SUITE(ScannerTest);
@@ -53,6 +54,7 @@ namespace
     CPPUNIT_TEST(testExclamation);
     CPPUNIT_TEST(testNumbers);
     CPPUNIT_TEST(testDataType);
+    CPPUNIT_TEST(testHexOctal);
 
     // End of test suite definition
     CPPUNIT_TEST_SUITE_END();
@@ -733,6 +735,100 @@ namespace
     CPPUNIT_ASSERT(symbols[1].text == cr);
   }
 
+  void ScannerTest::testHexOctal()
+  {
+    const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("&HA"));
+    const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("&HASDF"));
+    const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("&H10"));
+    const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("&&H&1H1&H1"));
+    const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("&O&O12"));
+    const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("&O10"));
+    const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("&HO"));
+    const rtl::OUString source8(RTL_CONSTASCII_USTRINGPARAM("&O123000000000000000000000"));
+    const rtl::OUString source9(RTL_CONSTASCII_USTRINGPARAM("&H1.23"));
+
+    std::vector<Symbol> symbols;
+
+    symbols = getSymbols(source1);
+    CPPUNIT_ASSERT(symbols.size() == 2);
+    CPPUNIT_ASSERT(symbols[0].number == 10);
+    CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
+    CPPUNIT_ASSERT(symbols[1].text == cr);
+
+    symbols = getSymbols(source2);
+    CPPUNIT_ASSERT(symbols.size() == 2);
+    CPPUNIT_ASSERT(symbols[0].number == 2783);
+    CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[0].type = SbxINTEGER);
+    CPPUNIT_ASSERT(symbols[1].text == cr);
+
+    symbols = getSymbols(source3);
+    CPPUNIT_ASSERT(symbols.size() == 2);
+    CPPUNIT_ASSERT(symbols[0].number == 16);
+    CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[0].type = SbxINTEGER);
+    CPPUNIT_ASSERT(symbols[1].text == cr);
+
+    symbols = getSymbols(source4);
+    CPPUNIT_ASSERT(symbols.size() == 6);
+    CPPUNIT_ASSERT(symbols[0].number == 0);
+    CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&")));
+    CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT);
+    CPPUNIT_ASSERT(symbols[1].number == 0);
+    CPPUNIT_ASSERT(symbols[1].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[1].type == SbxINTEGER);
+    CPPUNIT_ASSERT(symbols[2].number == 1);
+    CPPUNIT_ASSERT(symbols[2].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[2].type == SbxINTEGER);
+    CPPUNIT_ASSERT(symbols[3].number == 1);
+    CPPUNIT_ASSERT(symbols[3].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("H1")));
+    CPPUNIT_ASSERT(symbols[3].type == SbxLONG);
+    CPPUNIT_ASSERT(symbols[4].number == 1);
+    CPPUNIT_ASSERT(symbols[4].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("H1")));
+    CPPUNIT_ASSERT(symbols[4].type == SbxVARIANT);
+    CPPUNIT_ASSERT(symbols[5].text == cr);
+
+    symbols = getSymbols(source5);
+    CPPUNIT_ASSERT(symbols.size() == 3);
+    CPPUNIT_ASSERT(symbols[0].number == 0);
+    CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
+    CPPUNIT_ASSERT(symbols[1].number == 0);
+    CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("O12")));
+    CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT);
+    CPPUNIT_ASSERT(symbols[2].text == cr);
+
+    symbols = getSymbols(source6);
+    CPPUNIT_ASSERT(symbols.size() == 2);
+    CPPUNIT_ASSERT(symbols[0].number == 8);
+    CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
+    CPPUNIT_ASSERT(symbols[1].text == cr);
+
+    symbols = getSymbols(source7);
+    CPPUNIT_ASSERT(symbols.size() == 2);
+    CPPUNIT_ASSERT(symbols[0].number == 0);
+    CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[1].text == cr);
+
+    symbols = getSymbols(source8);
+    CPPUNIT_ASSERT(symbols.size() == 2);
+    CPPUNIT_ASSERT(symbols[0].number == -1744830464);
+    CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[1].text == cr);
+
+    symbols = getSymbols(source9);
+    CPPUNIT_ASSERT(symbols.size() == 3);
+    CPPUNIT_ASSERT(symbols[0].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[0].number == 1);
+    CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER);
+    CPPUNIT_ASSERT(symbols[1].number == .23);
+    CPPUNIT_ASSERT(symbols[1].text == rtl::OUString());
+    CPPUNIT_ASSERT(symbols[1].type == SbxDOUBLE);
+    CPPUNIT_ASSERT(symbols[2].text == cr);
+  }
+
   // Put the test suite in the registry
   CPPUNIT_TEST_SUITE_REGISTRATION(ScannerTest);
 } // namespace
commit 944140ae44708074ed7f88d3728e06c5e92413f5
Author: August Sodora <augsod at gmail.com>
Date:   Sat Jan 14 18:39:17 2012 -0500

    Remove uses of pLine in scanner

diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 4e01679..51c7ed4 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -317,7 +317,7 @@ bool SbiScanner::NextSym()
         short ncdig = 0;
         eScanType = SbxDOUBLE;
         bool bBufOverflow = false;
-        while( strchr( "0123456789.DEde", *pLine ) && *pLine )
+        while(nCol < aLine.getLength() && strchr("0123456789.DEde", aLine[nCol]))
         {
             // from 4.1.1996: buffer full? -> go on scanning empty
             if( (p-buf) == (BUF_SIZE-1) )
@@ -327,31 +327,40 @@ bool SbiScanner::NextSym()
                 continue;
             }
             // point or exponent?
-            if( *pLine == '.' )
+            if(aLine[nCol] == '.')
             {
                 if( ++comma > 1 )
                 {
                     ++pLine; ++nCol; continue;
                 }
-                else *p++ = *pLine++, ++nCol;
+                else
+                {
+                    *p = '.';
+                    ++p, ++pLine, ++nCol;
+                }
             }
-            else if( strchr( "DdEe", *pLine ) )
+            else if(strchr("DdEe", aLine[nCol]))
             {
                 if (++exp > 1)
                 {
                     ++pLine; ++nCol; continue;
                 }
-                *p++ = 'E'; ++pLine; ++nCol;
 
-                if( *pLine == '+' )
+                *p = 'E';
+                ++p, ++pLine, ++nCol;
+
+                if(aLine[nCol] == '+')
                     ++pLine, ++nCol;
-                else
-                if( *pLine == '-' )
-                    *p++ = *pLine++, ++nCol;
+                else if(aLine[nCol] == '-')
+                {
+                    *p = '-';
+                    ++p, ++pLine, ++nCol;
+                }
             }
             else
             {
-                *p++ = *pLine++, ++nCol;
+                *p = aLine[nCol];
+                ++p, ++pLine, ++nCol;
                 if( comma && !exp ) ++ncdig;
             }
             if (!exp) ++ndig;
@@ -379,7 +388,7 @@ bool SbiScanner::NextSym()
             GenError( SbERR_MATH_OVERFLOW );
 
         // type recognition?
-        SbxDataType t = GetSuffixType( *pLine );
+        SbxDataType t(GetSuffixType(aLine[nCol]));
         if( t != SbxVARIANT )
         {
             eScanType = t;
commit e4d6dfae33102891cbea0d330a31bb21572d5959
Author: August Sodora <augsod at gmail.com>
Date:   Sat Jan 14 17:47:43 2012 -0500

    Remove use of pLine in scanner

diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index f3ba9bd..4e01679 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -308,8 +308,8 @@ bool SbiScanner::NextSym()
     }
 
     // read in and convert if number
-    else if( theBasicCharClass::get().isDigit( *pLine & 0xFF )
-             || ( *pLine == '.' && theBasicCharClass::get().isDigit( *(pLine+1) & 0xFF ) ) )
+    else if((nCol < aLine.getLength() && theBasicCharClass::get().isDigit(aLine[nCol] & 0xFF)) ||
+            (nCol + 1 < aLine.getLength() && aLine[nCol] == '.' && theBasicCharClass::get().isDigit(aLine[nCol + 1] & 0xFF)))
     {
         short exp = 0;
         short comma = 0;
commit 679a8e1cfd4845634e379d0678fa1c352f7b97fd
Author: August Sodora <augsod at gmail.com>
Date:   Sat Jan 14 15:18:39 2012 -0500

    Remove use of pLine in scanner

diff --git a/basic/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx
index 23599d4..f3ba9bd 100644
--- a/basic/source/comp/scanner.cxx
+++ b/basic/source/comp/scanner.cxx
@@ -26,7 +26,6 @@
  *
  ************************************************************************/
 
-
 #include "basiccharclass.hxx"
 #include "sbcomp.hxx"
 
@@ -297,7 +296,7 @@ bool SbiScanner::NextSym()
         {
             if(nCol < aLine.getLength())
             {
-                SbxDataType t = GetSuffixType( *pLine );
+                SbxDataType t(GetSuffixType(aLine[nCol]));
                 if( t != SbxVARIANT )
                 {
                     eScanType = t;


More information about the Libreoffice-commits mailing list