[Libreoffice-commits] core.git: 5 commits - basic/qa

Noel Power noel.power at suse.com
Thu Mar 7 02:57:58 PST 2013


 basic/qa/cppunit/basic_coverage.cxx     |   40 +-----
 basic/qa/cppunit/basictest.hxx          |  120 +++++++++++++++++++-
 basic/qa/cppunit/test_append.cxx        |   40 ++----
 basic/qa/cppunit/test_nested_struct.cxx |  192 +++++++++-----------------------
 4 files changed, 192 insertions(+), 200 deletions(-)

New commits:
commit fea9b3a99a24366b4dea22ed1b79f34046f7f521
Author: Noel Power <noel.power at suse.com>
Date:   Thu Mar 7 10:53:42 2013 +0000

    finally remove no long needed BasicTestBase
    
    Change-Id: Ic1522b0c3a292af061f5777e06e796dd82884fbf

diff --git a/basic/qa/cppunit/basictest.hxx b/basic/qa/cppunit/basictest.hxx
index 7e74a2a..c828f25 100644
--- a/basic/qa/cppunit/basictest.hxx
+++ b/basic/qa/cppunit/basictest.hxx
@@ -22,35 +22,6 @@
 #include "basic/sbuno.hxx"
 #include <osl/file.hxx>
 
-class BasicTestBase : public test::BootstrapFixture
-{
-    private:
-    bool mbError;
-    public:
-    BasicTestBase() : BootstrapFixture(true, false), mbError(false) {};
-
-
-    DECL_LINK( BasicErrorHdl, StarBASIC * );
-    bool HasError() { return mbError; }
-    void ResetError()
-    {
-        StarBASIC::SetGlobalErrorHdl( Link() );
-        mbError = false;
-    }
-    BasicDLL& basicDLL()
-    {
-        static BasicDLL maDll; // we need a dll instance for resouce manager etc.
-        return maDll;
-    }
-};
-
-IMPL_LINK( BasicTestBase, BasicErrorHdl, StarBASIC *, /*pBasic*/)
-{
-    fprintf(stderr,"Got error: \n\t%s!!!\n", rtl::OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() );
-    mbError = true;
-    return 0;
-}
-
 class MacroSnippet
 {
     private:
commit 20f12a1d7ad5f9694f901a85e1fa22f46c3953a2
Author: Noel Power <noel.power at suse.com>
Date:   Thu Mar 7 10:52:51 2013 +0000

    Nested_Struct should really inherit from test::BootstrapFixture
    
    Change-Id: I06255940f41c32493187d1ec847f7238fef4e9f8

diff --git a/basic/qa/cppunit/test_nested_struct.cxx b/basic/qa/cppunit/test_nested_struct.cxx
index 266d11f..8c7fabc 100644
--- a/basic/qa/cppunit/test_nested_struct.cxx
+++ b/basic/qa/cppunit/test_nested_struct.cxx
@@ -19,10 +19,10 @@
 namespace
 {
     using namespace com::sun::star;
-    class Nested_Struct : public BasicTestBase
+    class Nested_Struct : public test::BootstrapFixture
     {
         public:
-        Nested_Struct() {};
+        Nested_Struct(): BootstrapFixture(true, false) {};
         void testAssign1();
         void testAssign1Alt(); // result is uno-ised and tested
         void testOldAssign();
commit 8534787f95dfbfff24167b2160cfe07a1b70bcc6
Author: Noel Power <noel.power at suse.com>
Date:   Thu Mar 7 10:49:28 2013 +0000

    adapt existing tests to use MacroSnipper helper class
    
    Change-Id: I50980d9510b82277a5da04cc4f6c1d3ec8e7c756

diff --git a/basic/qa/cppunit/basic_coverage.cxx b/basic/qa/cppunit/basic_coverage.cxx
index fefdd4e..b406122 100644
--- a/basic/qa/cppunit/basic_coverage.cxx
+++ b/basic/qa/cppunit/basic_coverage.cxx
@@ -16,7 +16,7 @@
 namespace
 {
 
-class Coverage : public BasicTestBase
+class Coverage : public test::BootstrapFixture
 {
 private:
     bool m_bError;
@@ -32,8 +32,6 @@ private:
     void test_success(void);
     void print_summary() {};
 
-    DECL_LINK( CoverageErrorHdl, StarBASIC * );
-
 public:
     Coverage();
     ~Coverage();
@@ -50,18 +48,9 @@ public:
     CPPUNIT_TEST_SUITE_END();
 };
 
-IMPL_LINK( Coverage, CoverageErrorHdl, StarBASIC *, /*pBasic*/)
-{
-    fprintf(stderr,"%s:(%d:%d)\n",
-            rtl::OUStringToOString( m_sCurrentTest, RTL_TEXTENCODING_UTF8 ).getStr(),
-            StarBASIC::GetLine(), StarBASIC::GetCol1());
-    fprintf(stderr,"Basic error: %s\n", rtl::OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() );
-    m_bError = true;
-    return 0;
-}
-
 Coverage::Coverage()
-    : m_bError(false)
+    : BootstrapFixture(true, false)
+    , m_bError(false)
     , m_nb_tests(0)
     , m_nb_tests_ok(0)
     , m_nb_tests_skipped(0)
@@ -94,25 +83,14 @@ void Coverage::test_success()
 void Coverage::run_test(OUString /*sFileName*/, OUString sCode)
 {
     bool result = false;
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, Coverage, CoverageErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sCode );
-    pMod->Compile();
-    if(!m_bError)
+    MacroSnippet testMacro( sCode );
+    testMacro.Compile();
+    if( !testMacro.HasError() )
     {
-        SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("doUnitTest"),  SbxCLASS_METHOD ));
-        if(pMeth)
+        SbxVariableRef pResult = testMacro.Run();
+        if( pResult && pResult->GetInteger() == 1 )
         {
-            SbxVariableRef refTemp = pMeth;
-            // forces a broadcast
-            SbxVariableRef pNew = new  SbxMethod( *((SbxMethod*)pMeth));
-            if(pNew->GetInteger() == 1 )
-            {
-                result = true;
-            }
+            result = true;
         }
     }
     if(result)
diff --git a/basic/qa/cppunit/test_append.cxx b/basic/qa/cppunit/test_append.cxx
index 7e7990f..e3d9f6b 100644
--- a/basic/qa/cppunit/test_append.cxx
+++ b/basic/qa/cppunit/test_append.cxx
@@ -15,10 +15,10 @@
 #include "basic/sbmeth.hxx"
 namespace
 {
-    class EnableTest : public BasicTestBase
+    class EnableTest : public test::BootstrapFixture
     {
         public:
-        EnableTest() {};
+        EnableTest() : BootstrapFixture(true, false) {};
         void testDimEnable();
         void testEnableRuntime();
         // Adds code needed to register the test suite
@@ -33,50 +33,34 @@ namespace
     };
 
 rtl::OUString sTestEnableRuntime(
-    "Function Test as Integer\n"
+    "Function doUnitTest as Integer\n"
     "Dim Enable as Integer\n"
     "Enable = 1\n"
     "Enable = Enable + 2\n"
-    "Test = Enable\n"
+    "doUnitTest = Enable\n"
     "End Function\n"
 );
 
 rtl::OUString sTestDimEnable(
-    "Sub Test\n"
+    "Sub doUnitTest\n"
     "Dim Enable as String\n"
     "End Sub\n"
 );
 
 void EnableTest::testEnableRuntime()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestEnableRuntime );
-    pMod->Compile();
-    CPPUNIT_ASSERT_MESSAGE("testEnableRuntime fails with compile error",!HasError() );
-    SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("Test"),  SbxCLASS_METHOD ));
-    CPPUNIT_ASSERT_MESSAGE("testEnableRuntime no method found", pMeth );
-    SbxVariableRef refTemp = pMeth;
-    // forces a broadcast
-    SbxVariableRef pNew = new  SbxMethod( *((SbxMethod*)pMeth));
+    MacroSnippet myMacro(sTestEnableRuntime);
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("testEnableRuntime fails with compile error",!myMacro.HasError() );
+    SbxVariableRef pNew = myMacro.Run();
     CPPUNIT_ASSERT(pNew->GetInteger() == 3 );
 }
 
 void EnableTest::testDimEnable()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) );
-
-    ResetError();
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestDimEnable );
-    pMod->Compile();
-
-    CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !HasError() );
+    MacroSnippet myMacro(sTestDimEnable);
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !myMacro.HasError() );
 }
 
   // Put the test suite in the registry
diff --git a/basic/qa/cppunit/test_nested_struct.cxx b/basic/qa/cppunit/test_nested_struct.cxx
index c55f4b3..266d11f 100644
--- a/basic/qa/cppunit/test_nested_struct.cxx
+++ b/basic/qa/cppunit/test_nested_struct.cxx
@@ -54,18 +54,18 @@ namespace
 // tests the new behaviour, we should be able to
 // directly modify the value of the nested 'HorizontalLine' struct
 rtl::OUString sTestSource1(
-    "Function simpleNestStructAccess() as Integer\n"
+    "Function doUnitTest() as Integer\n"
     "Dim b0 as new \"com.sun.star.table.TableBorder\"\n"
     "b0.HorizontalLine.OuterLineWidth = 9\n"
-    "simpleNestStructAccess = b0.HorizontalLine.OuterLineWidth\n"
+    "doUnitTest = b0.HorizontalLine.OuterLineWidth\n"
     "End Function\n"
 );
 
 rtl::OUString sTestSource1Alt(
-    "Function simpleNestStructAccess() as Object\n"
+    "Function doUnitTest() as Object\n"
     "Dim b0 as new \"com.sun.star.table.TableBorder\"\n"
     "b0.HorizontalLine.OuterLineWidth = 9\n"
-    "simpleNestStructAccess = b0\n"
+    "doUnitTest = b0\n"
     "End Function\n"
 );
 
@@ -76,22 +76,22 @@ rtl::OUString sTestSource1Alt(
 // c) modifying the new instance
 // d) setting b0.HorizontalLine with the value of the new instance
 rtl::OUString sTestSource2(
-    "Function simpleRegressionTestOld()\n"
+    "Function doUnitTest()\n"
     "Dim b0 as new \"com.sun.star.table.TableBorder\", l as new \"com.sun.star.table.BorderLine\"\n"
     "l = b0.HorizontalLine\n"
     "l.OuterLineWidth = 9\n"
     "b0.HorizontalLine = l\n"
-    "simpleRegressionTestOld = b0.HorizontalLine.OuterLineWidth\n"
+    "doUnitTest = b0.HorizontalLine.OuterLineWidth\n"
 "End Function\n"
 );
 
 rtl::OUString sTestSource2Alt(
-    "Function simpleRegressionTestOld()\n"
+    "Function doUnitTest()\n"
     "Dim b0 as new \"com.sun.star.table.TableBorder\", l as new \"com.sun.star.table.BorderLine\"\n"
     "l = b0.HorizontalLine\n"
     "l.OuterLineWidth = 9\n"
     "b0.HorizontalLine = l\n"
-    "simpleRegressionTestOld = b0\n"
+    "doUnitTest = b0\n"
 "End Function\n"
 );
 // it should be legal to assign a variant to a struct ( and copy by val )
@@ -100,18 +100,18 @@ rtl::OUString sTestSource2Alt(
 // OuterLineWidth of 4 & 9 respectively and we should be returning
 // 13 the sum of the two ( hopefully unique values if we haven't copied by reference )
 rtl::OUString sTestSource3(
-    "Function testUnfixedVarAssign()\n"
+    "Function doUnitTest()\n"
     "Dim b0 as new \"com.sun.star.table.TableBorder\"\n"
     "l = b0.HorizontalLine\n"
     "l.OuterLineWidth = 9\n"
     "b0.HorizontalLine = l\n"
     "l.OuterLineWidth = 4\n"
-    "testUnfixedVarAssign = b0.HorizontalLine.OuterLineWidth + l.OuterLineWidth\n"
+    "doUnitTest = b0.HorizontalLine.OuterLineWidth + l.OuterLineWidth\n"
 "End Function\n"
 );
 
 rtl::OUString sTestSource3Alt(
-    "Function testUnfixedVarAssign()\n"
+    "Function doUnitTest()\n"
     "Dim b0 as new \"com.sun.star.table.TableBorder\"\n"
     "l = b0.HorizontalLine\n"
     "l.OuterLineWidth = 9\n"
@@ -120,25 +120,25 @@ rtl::OUString sTestSource3Alt(
     "Dim result(1)\n"
     "result(0) = b0\n"
     "result(1) = l\n"
-    "testUnfixedVarAssign = result\n"
+    "doUnitTest = result\n"
 "End Function\n"
 );
 
 // nearly the same as above but this time for a fixed type
 // variable
 rtl::OUString sTestSource4(
-    "Function testFixedVarAssign()\n"
+    "Function doUnitTest()\n"
     "Dim b0 as new \"com.sun.star.table.TableBorder\", l as new \"com.sun.star.table.BorderLine\"\n"
     "l = b0.HorizontalLine\n"
     "l.OuterLineWidth = 9\n"
     "b0.HorizontalLine = l\n"
     "l.OuterLineWidth = 4\n"
-    "testFixedVarAssign = b0.HorizontalLine.OuterLineWidth + l.OuterLineWidth\n"
+    "doUnitTest = b0.HorizontalLine.OuterLineWidth + l.OuterLineWidth\n"
 "End Function\n"
 );
 
 rtl::OUString sTestSource4Alt(
-    "Function testFixedVarAssign()\n"
+    "Function doUnitTest()\n"
     "Dim b0 as new \"com.sun.star.table.TableBorder\", l as new \"com.sun.star.table.BorderLine\"\n"
     "l = b0.HorizontalLine\n"
     "l.OuterLineWidth = 9\n"
@@ -147,7 +147,7 @@ rtl::OUString sTestSource4Alt(
     "Dim result(1)\n"
     "result(0) = b0\n"
     "result(1) = l\n"
-    "testFixedVarAssign = result\n"
+    "doUnitTest = result\n"
 "End Function\n"
 );
 
@@ -157,49 +157,31 @@ rtl::OUString sTestSource4Alt(
 // We need to additionally check the actual uno struct to see if the
 // changes made are *really* reflected in the object
 rtl::OUString sTestSource5(
-    "Function testUnoAccess() as Object\n"
+    "Function doUnitTest() as Object\n"
     "Dim aWinDesc as new \"com.sun.star.awt.WindowDescriptor\"\n"
     "Dim aRect as new \"com.sun.star.awt.Rectangle\"\n"
     "aRect.X = 200\n"
     "aWinDesc.Bounds = aRect\n"
-    "testUnoAccess = aWinDesc\n"
+    "doUnitTest = aWinDesc\n"
 "End Function\n"
 );
 
 
 void Nested_Struct::testAssign1()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource1 );
-    pMod->Compile();
-    CPPUNIT_ASSERT_MESSAGE("testAssign1 fails with compile error",!HasError() );
-    SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("simpleNestStructAccess"),  SbxCLASS_METHOD ));
-    CPPUNIT_ASSERT_MESSAGE("testAssign1 no method found", pMeth );
-    SbxVariableRef refTemp = pMeth;
-    // forces a broadcast
-    SbxVariableRef pNew = new  SbxMethod( *((SbxMethod*)pMeth));
+    MacroSnippet myMacro( sTestSource1 );
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("testAssign1 fails with compile error",!myMacro.HasError() );
+    SbxVariableRef pNew = myMacro.Run();
     CPPUNIT_ASSERT(pNew->GetInteger() == 9 );
 }
 
 void Nested_Struct::testAssign1Alt()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource1Alt );
-    pMod->Compile();
-    CPPUNIT_ASSERT_MESSAGE("testAssign1Alt fails with compile error",!HasError() );
-    SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("simpleNestStructAccess"),  SbxCLASS_METHOD ));
-    CPPUNIT_ASSERT_MESSAGE("testAssign1Alt no method found", pMeth );
-    SbxVariableRef refTemp = pMeth;
-    // forces a broadcast
-    SbxVariableRef pNew = new  SbxMethod( *((SbxMethod*)pMeth));
+    MacroSnippet myMacro( sTestSource1Alt );
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("testAssign1Alt fails with compile error",!myMacro.HasError() );
+    SbxVariableRef pNew = myMacro.Run();
     uno::Any aRet = sbxToUnoValue( pNew );
     table::TableBorder aBorder;
     aRet >>= aBorder;
@@ -210,37 +192,19 @@ void Nested_Struct::testAssign1Alt()
 
 void Nested_Struct::testOldAssign()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource2 );
-    pMod->Compile();
-    CPPUNIT_ASSERT_MESSAGE("testOldAssign fails with compile error",!HasError() );
-    SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("simpleRegressionTestOld"),  SbxCLASS_METHOD ));
-    CPPUNIT_ASSERT_MESSAGE("testOldAssign no method found", pMeth );
-    SbxVariableRef refTemp = pMeth;
-    // forces a broadcast
-    SbxVariableRef pNew = new  SbxMethod( *((SbxMethod*)pMeth));
+    MacroSnippet myMacro( sTestSource2 );
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("testOldAssign fails with compile error",!myMacro.HasError() );
+    SbxVariableRef pNew = myMacro.Run();
     CPPUNIT_ASSERT(pNew->GetInteger() == 9 );
 }
 
 void Nested_Struct::testOldAssignAlt()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource2Alt );
-    pMod->Compile();
-    CPPUNIT_ASSERT_MESSAGE("testOldAssign fails with compile error",!HasError() );
-    SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("simpleRegressionTestOld"),  SbxCLASS_METHOD ));
-    CPPUNIT_ASSERT_MESSAGE("testOldAssign no method found", pMeth );
-    SbxVariableRef refTemp = pMeth;
-    // forces a broadcast
-    SbxVariableRef pNew = new  SbxMethod( *((SbxMethod*)pMeth));
+    MacroSnippet myMacro( sTestSource2Alt );
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("testOldAssign fails with compile error",!myMacro.HasError() );
+    SbxVariableRef pNew = myMacro.Run();
     uno::Any aRet = sbxToUnoValue( pNew );
     table::TableBorder aBorder;
     aRet >>= aBorder;
@@ -251,37 +215,20 @@ void Nested_Struct::testOldAssignAlt()
 
 void Nested_Struct::testUnfixedVarAssign()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource3 );
-    pMod->Compile();
-    CPPUNIT_ASSERT_MESSAGE("testUnfixedVarAssign fails with compile error",!HasError() );
-    SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("testUnfixedVarAssign"),  SbxCLASS_METHOD ));
-    CPPUNIT_ASSERT_MESSAGE("testUnfixedVarAssign no method found", pMeth );
-    SbxVariableRef refTemp = pMeth;
+    MacroSnippet myMacro( sTestSource3 );
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("testUnfixedVarAssign fails with compile error",!myMacro.HasError() );
     // forces a broadcast
-    SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
+    SbxVariableRef pNew = myMacro.Run();
     CPPUNIT_ASSERT(pNew->GetInteger() == 13 );
 }
 
 void Nested_Struct::testUnfixedVarAssignAlt()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource3Alt );
-    pMod->Compile();
-    CPPUNIT_ASSERT_MESSAGE("testUnfixedVarAssignAlt fails with compile error",!HasError() );
-    SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("testUnfixedVarAssign"),  SbxCLASS_METHOD ));
-    CPPUNIT_ASSERT_MESSAGE("testUnfixedVarAssignAlt no method found", pMeth );
-    SbxVariableRef refTemp = pMeth;
-    // forces a broadcast
-    SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
+    MacroSnippet myMacro( sTestSource3Alt );
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("testUnfixedVarAssignAlt fails with compile error",!myMacro.HasError() );
+    SbxVariableRef pNew = myMacro.Run();
     uno::Any aRet = sbxToUnoValue( pNew );
 
     uno::Sequence< uno::Any > aResult;
@@ -305,37 +252,19 @@ void Nested_Struct::testUnfixedVarAssignAlt()
 
 void Nested_Struct::testFixedVarAssign()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource4 );
-    pMod->Compile();
-    CPPUNIT_ASSERT_MESSAGE("testFixedVarAssign fails with compile error",!HasError() );
-    SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("testFixedVarAssign"),  SbxCLASS_METHOD ));
-    CPPUNIT_ASSERT_MESSAGE("testFixedVarAssign no method found", pMeth );
-    SbxVariableRef refTemp = pMeth;
-    // forces a broadcast
-    SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
+    MacroSnippet myMacro( sTestSource4 );
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("testFixedVarAssign fails with compile error",!myMacro.HasError() );
+    SbxVariableRef pNew = myMacro.Run();
     CPPUNIT_ASSERT(pNew->GetInteger() == 13 );
 }
 
 void Nested_Struct::testFixedVarAssignAlt()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource4Alt );
-    pMod->Compile();
-    CPPUNIT_ASSERT_MESSAGE("testFixedVarAssignAlt fails with compile error",!HasError() );
-    SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("testFixedVarAssign"),  SbxCLASS_METHOD ));
-    CPPUNIT_ASSERT_MESSAGE("testFixedVarAssignAlt no method found", pMeth );
-    SbxVariableRef refTemp = pMeth;
-    // forces a broadcast
-    SbxVariableRef pNew = new SbxMethod( *((SbxMethod*)pMeth));
+    MacroSnippet myMacro( sTestSource4Alt );
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("testFixedVarAssignAlt fails with compile error",!myMacro.HasError() );
+    SbxVariableRef pNew = myMacro.Run();
     uno::Any aRet = sbxToUnoValue( pNew );
 
     uno::Sequence< uno::Any > aResult;
@@ -359,19 +288,10 @@ void Nested_Struct::testFixedVarAssignAlt()
 
 void Nested_Struct::testUnoAccess()
 {
-    CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
-    StarBASICRef pBasic = new StarBASIC();
-    ResetError();
-    StarBASIC::SetGlobalErrorHdl( LINK( this, Nested_Struct, BasicErrorHdl ) );
-
-    SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sTestSource5 );
-    pMod->Compile();
-    CPPUNIT_ASSERT_MESSAGE("testUnoAccess fails with compile error",!HasError() );
-    SbMethod* pMeth = static_cast<SbMethod*>(pMod->Find( rtl::OUString("testUnoAccess"),  SbxCLASS_METHOD ));
-    CPPUNIT_ASSERT_MESSAGE("testUnoAccess no method found", pMeth );
-    SbxVariableRef refTemp = pMeth;
-    // forces a broadcast
-    SbxVariableRef pNew = new  SbxMethod( *((SbxMethod*)pMeth));
+    MacroSnippet myMacro( sTestSource5 );
+    myMacro.Compile();
+    CPPUNIT_ASSERT_MESSAGE("testUnoAccess fails with compile error",!myMacro.HasError() );
+    SbxVariableRef pNew = myMacro.Run();
     uno::Any aRet = sbxToUnoValue( pNew );
     awt::WindowDescriptor aWinDesc;
     aRet >>= aWinDesc;
commit 49417b0b68e8c9743bd6f664a5f8b4a0f3c19723
Author: Noel Power <noel.power at suse.com>
Date:   Thu Mar 7 10:48:50 2013 +0000

    use "doUnitTest" as the method to search for, tweak error reporting
    
    Change-Id: I0c0f4ce1304b561bf94af5444c83d8920062568b

diff --git a/basic/qa/cppunit/basictest.hxx b/basic/qa/cppunit/basictest.hxx
index d94abbf..7e74a2a 100644
--- a/basic/qa/cppunit/basictest.hxx
+++ b/basic/qa/cppunit/basictest.hxx
@@ -89,7 +89,7 @@ class MacroSnippet
     void LoadSourceFromFile( const OUString& sMacroFileURL )
     {
         OUString sSource;
-        printf("loadSource opening macro file %s\n", OUStringToOString( sMacroFileURL, RTL_TEXTENCODING_UTF8 ).getStr() );
+        fprintf(stderr,"loadSource opening macro file %s\n", OUStringToOString( sMacroFileURL, RTL_TEXTENCODING_UTF8 ).getStr() );
 
         osl::File aFile(sMacroFileURL);
         if(osl::FileBase::E_None == aFile.open(osl_File_OpenFlag_Read))
@@ -119,7 +119,7 @@ class MacroSnippet
         SbxVariableRef pReturn = NULL;
         if ( !Compile() )
             return pReturn;
-        SbMethod* pMeth = mpMod ? static_cast<SbMethod*>(mpMod->Find( OUString("test"),  SbxCLASS_METHOD )) : NULL;
+        SbMethod* pMeth = mpMod ? static_cast<SbMethod*>(mpMod->Find( OUString("doUnitTest"),  SbxCLASS_METHOD )) : NULL;
         if ( pMeth )
         {
             if ( rArgs.getLength() )
@@ -179,7 +179,9 @@ class MacroSnippet
 
 IMPL_LINK( MacroSnippet, BasicErrorHdl, StarBASIC *, /*pBasic*/)
 {
-    fprintf(stderr,"Got error: \n\t%s!!!\n", OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() );
+    fprintf(stderr,"(%d:%d)\n",
+            StarBASIC::GetLine(), StarBASIC::GetCol1());
+    fprintf(stderr,"Basic error: %s\n", rtl::OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() );
     mbError = true;
     return 0;
 }
commit a9fc6ee7dc640f016728bf524d684696a376e989
Author: Noel Power <noel.power at suse.com>
Date:   Wed Mar 6 21:14:08 2013 +0000

    Create new Macro helper class to help invoking macros for unittests
    
    Change-Id: Icc3cbfc3eae6ade037960497e7fe2addf1912897

diff --git a/basic/qa/cppunit/basictest.hxx b/basic/qa/cppunit/basictest.hxx
index bb26a23..d94abbf 100644
--- a/basic/qa/cppunit/basictest.hxx
+++ b/basic/qa/cppunit/basictest.hxx
@@ -16,6 +16,11 @@
 #include <test/bootstrapfixture.hxx>
 #include "basic/sbstar.hxx"
 #include "basic/basrdll.hxx"
+#include "basic/sbmod.hxx"
+#include "basic/sbmeth.hxx"
+#include "basic/basrdll.hxx"
+#include "basic/sbuno.hxx"
+#include <osl/file.hxx>
 
 class BasicTestBase : public test::BootstrapFixture
 {
@@ -46,6 +51,138 @@ IMPL_LINK( BasicTestBase, BasicErrorHdl, StarBASIC *, /*pBasic*/)
     return 0;
 }
 
+class MacroSnippet
+{
+    private:
+    bool mbError;
+    SbModuleRef mpMod;
+    StarBASICRef mpBasic;
+
+    void InitSnippet()
+    {
+        CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL );
+        mpBasic = new StarBASIC();
+        StarBASIC::SetGlobalErrorHdl( LINK( this, MacroSnippet, BasicErrorHdl ) );
+    }
+    void MakeModule( const OUString& sSource )
+    {
+        mpMod = mpBasic->MakeModule( OUString( "TestModule" ), sSource );
+    }
+    public:
+    struct ErrorDetail
+    {
+        OUString sErrorText;
+        int nLine;
+        int nCol;
+        ErrorDetail() : nLine(0), nCol(0) {}
+    };
+
+    MacroSnippet( const OUString& sSource ) : mbError(false)
+    {
+        InitSnippet();
+        MakeModule( sSource );
+    };
+    MacroSnippet() : mbError(false)
+    {
+        InitSnippet();
+    };
+    void LoadSourceFromFile( const OUString& sMacroFileURL )
+    {
+        OUString sSource;
+        printf("loadSource opening macro file %s\n", OUStringToOString( sMacroFileURL, RTL_TEXTENCODING_UTF8 ).getStr() );
+
+        osl::File aFile(sMacroFileURL);
+        if(osl::FileBase::E_None == aFile.open(osl_File_OpenFlag_Read))
+        {
+            sal_uInt64 size;
+            sal_uInt64 size_read;
+            if(osl::FileBase::E_None == aFile.getSize(size))
+            {
+                void* buffer = calloc(1, size+1);
+                CPPUNIT_ASSERT(buffer);
+                if(osl::FileBase::E_None == aFile.read( buffer, size, size_read))
+                {
+                    if(size == size_read)
+                    {
+                        OUString sCode((sal_Char*)buffer, size, RTL_TEXTENCODING_UTF8);
+                        sSource = sCode;
+                    }
+                }
+            }
+        }
+        CPPUNIT_ASSERT_MESSAGE( "Source is empty", ( sSource.getLength() > 0 ) );
+        MakeModule( sSource );
+    }
+
+    SbxVariableRef Run( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rArgs )
+    {
+        SbxVariableRef pReturn = NULL;
+        if ( !Compile() )
+            return pReturn;
+        SbMethod* pMeth = mpMod ? static_cast<SbMethod*>(mpMod->Find( OUString("test"),  SbxCLASS_METHOD )) : NULL;
+        if ( pMeth )
+        {
+            if ( rArgs.getLength() )
+            {
+                SbxArrayRef aArgs = new SbxArray;
+                for ( int i=0; i < rArgs.getLength(); ++i )
+                {
+                    SbxVariable* pVar = new SbxVariable();
+                    unoToSbxValue( pVar, rArgs[ i ] );
+                    aArgs->Put(  pVar, i + 1 );
+                }
+                pMeth->SetParameters( aArgs );
+            }
+            pReturn = new SbxMethod( *((SbxMethod*)pMeth));
+        }
+        return pReturn;
+    }
+
+    SbxVariableRef Run()
+    {
+        ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aArgs;
+        return Run( aArgs );
+    }
+
+    bool Compile()
+    {
+        CPPUNIT_ASSERT_MESSAGE("module is NULL", mpMod != NULL );
+        mpMod->Compile();
+        return !mbError;
+    }
+
+    DECL_LINK( BasicErrorHdl, StarBASIC * );
+
+    ErrorDetail GetError()
+    {
+        ErrorDetail aErr;
+        aErr.sErrorText = StarBASIC::GetErrorText();
+        aErr.nLine = StarBASIC::GetLine();
+        aErr.nCol = StarBASIC::GetCol1();
+        return aErr;
+    }
+
+    bool HasError() { return mbError; }
+
+    void ResetError()
+    {
+        StarBASIC::SetGlobalErrorHdl( Link() );
+        mbError = false;
+    }
+
+    BasicDLL& basicDLL()
+    {
+        static BasicDLL maDll; // we need a dll instance for resouce manager etc.
+        return maDll;
+    }
+};
+
+IMPL_LINK( MacroSnippet, BasicErrorHdl, StarBASIC *, /*pBasic*/)
+{
+    fprintf(stderr,"Got error: \n\t%s!!!\n", OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() );
+    mbError = true;
+    return 0;
+}
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list