diff options
author | Noel Power <noel.power@suse.com> | 2013-03-08 15:16:16 +0000 |
---|---|---|
committer | Noel Power <noel.power@suse.com> | 2013-03-08 15:19:57 +0000 |
commit | 68f26e62002e0c7419ae57c64a78588ed2d01efa (patch) | |
tree | f90fa8ceb82a79764a6b5df7cdb3720c0cd50b75 /basic | |
parent | 25cfd690e84b52d854f79110db6e12f3f68b78b3 (diff) |
cherry-pick/backport bunch of vba unit test related patches
Change-Id: I7c7e5652bc1b44ce0085f9c593aa73077165c090
master:4596120336b575d94d305c4139054afd95d2f740
master:76c3184813c97224cfd1e114ec13796e1da040d5
master:fea9b3a99a24366b4dea22ed1b79f34046f7f521
master:8534787f95dfbfff24167b2160cfe07a1b70bcc6
master:49417b0b68e8c9743bd6f664a5f8b4a0f3c19723
master:a9fc6ee7dc640f016728bf524d684696a376e989
master:b68a0f659500c2db86aa99df78bac292e3e93d79
Diffstat (limited to 'basic')
-rw-r--r-- | basic/Module_basic.mk | 2 | ||||
-rw-r--r-- | basic/qa/basic_coverage/string_left_01.vb | 25 | ||||
-rw-r--r-- | basic/qa/basic_coverage/string_right_01.vb | 24 | ||||
-rw-r--r-- | basic/qa/basic_coverage/uno_struct_assign.vb | 15 | ||||
-rw-r--r-- | basic/qa/cppunit/basic_coverage.cxx | 169 | ||||
-rw-r--r-- | basic/qa/cppunit/basictest.hxx | 161 | ||||
-rw-r--r-- | basic/qa/cppunit/test_append.cxx | 88 | ||||
-rw-r--r-- | basic/qa/cppunit/test_nested_struct.cxx | 308 | ||||
-rw-r--r-- | basic/qa/cppunit/test_scanner.cxx | 259 | ||||
-rw-r--r-- | basic/qa/cppunit/test_structref.cxx | 71 | ||||
-rw-r--r-- | basic/qa/cppunit/test_vba.cxx | 81 | ||||
-rw-r--r-- | basic/qa/vba_tests/bytearraystring.vb | 68 | ||||
-rw-r--r-- | basic/qa/vba_tests/dateserial.vb | 65 | ||||
-rw-r--r-- | basic/qa/vba_tests/datevalue.vb | 65 | ||||
-rw-r--r-- | basic/qa/vba_tests/format.vb | 406 | ||||
-rw-r--r-- | basic/qa/vba_tests/partition.vb | 71 | ||||
-rw-r--r-- | basic/qa/vba_tests/replace.vb | 70 | ||||
-rw-r--r-- | basic/qa/vba_tests/strconv.vb | 90 | ||||
-rw-r--r-- | basic/qa/vba_tests/stringplusdouble.vb | 328 |
19 files changed, 2173 insertions, 193 deletions
diff --git a/basic/Module_basic.mk b/basic/Module_basic.mk index fe430ffac66c..fd5bd832ed11 100644 --- a/basic/Module_basic.mk +++ b/basic/Module_basic.mk @@ -37,6 +37,8 @@ $(eval $(call gb_Module_add_targets,basic,\ $(eval $(call gb_Module_add_check_targets,basic,\ CppunitTest_basic_scanner \ CppunitTest_basic_enable \ + CppunitTest_basic_coverage \ + CppunitTest_basic_vba \ )) endif diff --git a/basic/qa/basic_coverage/string_left_01.vb b/basic/qa/basic_coverage/string_left_01.vb new file mode 100644 index 000000000000..ef896bef1009 --- /dev/null +++ b/basic/qa/basic_coverage/string_left_01.vb @@ -0,0 +1,25 @@ +' +' 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 s1 As String +Dim s2 As String + + s1 = "abc" + + s2 = Left(s1, 2) + + If s2 = "ab" Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If + +End Function diff --git a/basic/qa/basic_coverage/string_right_01.vb b/basic/qa/basic_coverage/string_right_01.vb new file mode 100644 index 000000000000..65b16c6a8762 --- /dev/null +++ b/basic/qa/basic_coverage/string_right_01.vb @@ -0,0 +1,24 @@ +' +' 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 s1 As String +Dim s2 As String + + s1 = "abc" + + s2 = Right(s1, 2) + + If s2 = "bc" Then + doUnitTest = 1 + Else + doUnitTest = 0 + End If + +End Function diff --git a/basic/qa/basic_coverage/uno_struct_assign.vb b/basic/qa/basic_coverage/uno_struct_assign.vb new file mode 100644 index 000000000000..23812de2cd6a --- /dev/null +++ b/basic/qa/basic_coverage/uno_struct_assign.vb @@ -0,0 +1,15 @@ +' +' 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 oNamedValue as new com.sun.star.beans.NamedValue + Dim oCellAddress as new com.sun.star.table.CellAddress + oNamedValue.Value = oCellAddress ' fdo#60065 - this would throw an error + doUnitTest = 1 +End Function diff --git a/basic/qa/cppunit/basic_coverage.cxx b/basic/qa/cppunit/basic_coverage.cxx new file mode 100644 index 000000000000..1ae027cb7448 --- /dev/null +++ b/basic/qa/cppunit/basic_coverage.cxx @@ -0,0 +1,169 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + */ + +#include "basictest.hxx" +#include <osl/file.hxx> +#include "basic/sbmod.hxx" +#include "basic/sbmeth.hxx" + + +namespace +{ + +class Coverage : public test::BootstrapFixture +{ +private: + int m_nb_tests; + int m_nb_tests_ok; + int m_nb_tests_skipped; + rtl::OUString m_sCurrentTest; + void process_directory(rtl::OUString sDirName); + void process_file(rtl::OUString sFileName); + void run_test(rtl::OUString sFileName, rtl::OUString sCode); + void test_start(rtl::OUString /* sFileName */); + void test_failed(void); + void test_success(void); + void print_summary() {}; + +public: + Coverage(); + ~Coverage(); + + void Coverage_Iterator(); + + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE(Coverage); + + // Declares the method as a test to call + CPPUNIT_TEST(Coverage_Iterator); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); +}; + +Coverage::Coverage() + : BootstrapFixture(true, false) + , m_nb_tests(0) + , m_nb_tests_ok(0) + , m_nb_tests_skipped(0) +{ +} + +Coverage::~Coverage() +{ + fprintf(stderr,"basic coverage Summary : skipped:%d pass:%d\n", m_nb_tests_skipped, m_nb_tests_ok ); +} + +void Coverage::test_start(rtl::OUString sFileName) +{ + m_nb_tests += 1; + m_sCurrentTest = sFileName; +} + +void Coverage::test_failed() +{ + CPPUNIT_FAIL( + rtl::OUStringToOString(m_sCurrentTest, RTL_TEXTENCODING_UTF8).getStr()); +} + +void Coverage::test_success() +{ + m_nb_tests_ok += 1; + fprintf(stderr,"%s,PASS\n", rtl::OUStringToOString( m_sCurrentTest, RTL_TEXTENCODING_UTF8 ).getStr() ); +} + +void Coverage::run_test(rtl::OUString /*sFileName*/, rtl::OUString sCode) +{ + bool result = false; + MacroSnippet testMacro( sCode ); + testMacro.Compile(); + if( !testMacro.HasError() ) + { + SbxVariableRef pResult = testMacro.Run(); + if( pResult && pResult->GetInteger() == 1 ) + { + result = true; + } + } + if(result) + { + test_success(); + } + else + { + test_failed(); + } +} + +void Coverage::process_file(rtl::OUString sFileName) +{ + osl::File aFile(sFileName); + + test_start(sFileName); + 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) + { + rtl::OUString sCode((sal_Char*)buffer, size, RTL_TEXTENCODING_UTF8); + run_test(sFileName, sCode); + return; + } + } + } + } + test_failed(); +} + +void Coverage::process_directory(rtl::OUString sDirName) +{ + osl::Directory aDir(sDirName); + osl::DirectoryItem aItem; + osl::FileStatus aFileStatus(osl_FileStatus_Mask_FileURL|osl_FileStatus_Mask_Type); + + if(osl::FileBase::E_None == aDir.open()) + { + while (aDir.getNextItem(aItem) == osl::FileBase::E_None) + { + aItem.getFileStatus(aFileStatus); + if(aFileStatus.isRegular()) + { + process_file(aFileStatus.getFileURL()); + } + } + } + else + { + } + fprintf(stderr,"end process directory\n"); +} + +void Coverage::Coverage_Iterator(void) +{ + rtl::OUString sDirName = getURLFromSrc("/basic/qa/basic_coverage/"); + + CPPUNIT_ASSERT(!sDirName.isEmpty()); + process_directory(sDirName); +} + + CPPUNIT_TEST_SUITE_REGISTRATION(Coverage); + +} +CPPUNIT_PLUGIN_IMPLEMENT(); + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basic/qa/cppunit/basictest.hxx b/basic/qa/cppunit/basictest.hxx new file mode 100644 index 000000000000..1116c4be73b8 --- /dev/null +++ b/basic/qa/cppunit/basictest.hxx @@ -0,0 +1,161 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright 2012 LibreOffice contributors. + * + * 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/. + */ +#ifndef _BASICTEST_HXX +#define _BASICTEST_HXX + +#include <sal/types.h> +#include "cppunit/TestFixture.h" +#include "cppunit/extensions/HelperMacros.h" +#include "cppunit/plugin/TestPlugIn.h" +#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 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 rtl::OUString& sSource ) + { + mpMod = mpBasic->MakeModule( rtl::OUString( "TestModule" ), sSource ); + } + public: + struct ErrorDetail + { + rtl::OUString sErrorText; + int nLine; + int nCol; + ErrorDetail() : nLine(0), nCol(0) {} + }; + + MacroSnippet( const rtl::OUString& sSource ) : mbError(false) + { + InitSnippet(); + MakeModule( sSource ); + }; + MacroSnippet() : mbError(false) + { + InitSnippet(); + }; + void LoadSourceFromFile( const rtl::OUString& sMacroFileURL ) + { + rtl::OUString sSource; + fprintf(stderr,"loadSource opening macro file %s\n", rtl::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) + { + rtl::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( rtl::OUString("doUnitTest"), 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,"(%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; +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basic/qa/cppunit/test_append.cxx b/basic/qa/cppunit/test_append.cxx index 9a9401f31bc1..e3d9f6b6704f 100644 --- a/basic/qa/cppunit/test_append.cxx +++ b/basic/qa/cppunit/test_append.cxx @@ -1,36 +1,24 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - * Copyright 2012 LibreOffice contributors. + * 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/. */ -#include "sal/config.h" -#include "sal/precppunit.hxx" - -#include "cppunit/TestAssert.h" -#include "cppunit/TestFixture.h" -#include "cppunit/extensions/HelperMacros.h" -#include "cppunit/plugin/TestPlugIn.h" - -#include <test/bootstrapfixture.hxx> +#include "basictest.hxx" #include "osl/file.hxx" #include "osl/process.h" -#include "basic/sbstar.hxx" #include "basic/sbmod.hxx" #include "basic/sbmeth.hxx" -#include "basic/basrdll.hxx" namespace { class EnableTest : public test::BootstrapFixture { - private: - bool mbError; public: - EnableTest() : mbError(false) {}; + EnableTest() : BootstrapFixture(true, false) {}; void testDimEnable(); void testEnableRuntime(); // Adds code needed to register the test suite @@ -42,63 +30,37 @@ namespace // End of test suite definition CPPUNIT_TEST_SUITE_END(); - - DECL_LINK( BasicErrorHdl, StarBASIC * ); - bool HasError() { return mbError; } - BasicDLL& basicDLL() - { - static BasicDLL maDll; // we need a dll instance for resouce manager etc. - return maDll; - } }; -IMPL_LINK( EnableTest, BasicErrorHdl, StarBASIC *, /*pBasic*/) -{ - fprintf(stderr,"Got error: \n\t%s!!!\n", rtl::OUStringToOString( StarBASIC::GetErrorText(), RTL_TEXTENCODING_UTF8 ).getStr() ); - mbError = true; - return 0; -} +rtl::OUString sTestEnableRuntime( + "Function doUnitTest as Integer\n" + "Dim Enable as Integer\n" + "Enable = 1\n" + "Enable = Enable + 2\n" + "doUnitTest = Enable\n" + "End Function\n" +); + +rtl::OUString sTestDimEnable( + "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(); - StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) ); - - rtl::OUString sSource("Function Test as Integer\n"); - sSource += rtl::OUString("Dim Enable as Integer\n"); - sSource += rtl::OUString("Enable = 1\n"); - sSource += rtl::OUString("Enable = Enable + 2\n"); - sSource += rtl::OUString("Test = Enable\n"); - sSource += rtl::OUString("End Function\n"); - - SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sSource ); - pMod->Compile(); - CPPUNIT_ASSERT_MESSAGE("testEnableRuntime fails with compile error",!mbError ); - 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 ); - StarBASIC::SetGlobalErrorHdl( Link() ); - } + void EnableTest::testDimEnable() { - CPPUNIT_ASSERT_MESSAGE( "No resource manager", basicDLL().GetBasResMgr() != NULL ); - StarBASICRef pBasic = new StarBASIC(); - StarBASIC::SetGlobalErrorHdl( LINK( this, EnableTest, BasicErrorHdl ) ); - - rtl::OUString sSource("Sub Test\n"); - sSource += rtl::OUString("Dim Enable as String\n"); - sSource += rtl::OUString("End Sub\n"); - - SbModule* pMod = pBasic->MakeModule( rtl::OUString( "TestModule" ), sSource ); - pMod->Compile(); - - CPPUNIT_ASSERT_MESSAGE("Dim causes compile error", !mbError ); - StarBASIC::SetGlobalErrorHdl( Link() ); + 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 new file mode 100644 index 000000000000..8c7fabcdec85 --- /dev/null +++ b/basic/qa/cppunit/test_nested_struct.cxx @@ -0,0 +1,308 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright 2012 LibreOffice contributors. + * + * 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/. + */ +#include "basictest.hxx" +#include "osl/file.hxx" +#include "osl/process.h" + +#include "basic/sbmod.hxx" +#include "basic/sbmeth.hxx" +#include "com/sun/star/awt/WindowDescriptor.hpp" +#include "com/sun/star/table/TableBorder.hpp" +#include "basic/sbuno.hxx" + +namespace +{ + using namespace com::sun::star; + class Nested_Struct : public test::BootstrapFixture + { + public: + Nested_Struct(): BootstrapFixture(true, false) {}; + void testAssign1(); + void testAssign1Alt(); // result is uno-ised and tested + void testOldAssign(); + void testOldAssignAlt(); // result is uno-ised and tested + void testUnfixedVarAssign(); + void testUnfixedVarAssignAlt(); // result is uno-ised and tested + void testFixedVarAssign(); + void testFixedVarAssignAlt(); // result is uno-ised and tested + void testUnoAccess(); // fdo#60117 specific test + + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE(Nested_Struct); + + // Declares the method as a test to call + CPPUNIT_TEST(testAssign1); + CPPUNIT_TEST(testAssign1Alt); + CPPUNIT_TEST(testOldAssign); + CPPUNIT_TEST(testOldAssignAlt); + CPPUNIT_TEST(testUnfixedVarAssign); + CPPUNIT_TEST(testUnfixedVarAssignAlt); + CPPUNIT_TEST(testFixedVarAssign); + CPPUNIT_TEST(testFixedVarAssignAlt); + CPPUNIT_TEST(testUnoAccess); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); + }; + +// tests the new behaviour, we should be able to +// directly modify the value of the nested 'HorizontalLine' struct +rtl::OUString sTestSource1( + "Function doUnitTest() as Integer\n" + "Dim b0 as new \"com.sun.star.table.TableBorder\"\n" + "b0.HorizontalLine.OuterLineWidth = 9\n" + "doUnitTest = b0.HorizontalLine.OuterLineWidth\n" + "End Function\n" +); + +rtl::OUString sTestSource1Alt( + "Function doUnitTest() as Object\n" + "Dim b0 as new \"com.sun.star.table.TableBorder\"\n" + "b0.HorizontalLine.OuterLineWidth = 9\n" + "doUnitTest = b0\n" + "End Function\n" +); + +// tests the old behaviour, we should still be able +// to use the old workaround of +// a) creating a new instance BorderLine, +// b) cloning the new instance with the value of b0.HorizontalLine +// c) modifying the new instance +// d) setting b0.HorizontalLine with the value of the new instance +rtl::OUString sTestSource2( + "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" + "doUnitTest = b0.HorizontalLine.OuterLineWidth\n" +"End Function\n" +); + +rtl::OUString sTestSource2Alt( + "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" + "doUnitTest = b0\n" +"End Function\n" +); +// it should be legal to assign a variant to a struct ( and copy by val ) +// make sure we aren't copying by reference, we make sure that l is not +// a reference copy of b0.HorizontalLine, each one should have an +// 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 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" + "doUnitTest = b0.HorizontalLine.OuterLineWidth + l.OuterLineWidth\n" +"End Function\n" +); + +rtl::OUString sTestSource3Alt( + "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" + "Dim result(1)\n" + "result(0) = b0\n" + "result(1) = l\n" + "doUnitTest = result\n" +"End Function\n" +); + +// nearly the same as above but this time for a fixed type +// variable +rtl::OUString sTestSource4( + "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" + "doUnitTest = b0.HorizontalLine.OuterLineWidth + l.OuterLineWidth\n" +"End Function\n" +); + +rtl::OUString sTestSource4Alt( + "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" + "Dim result(1)\n" + "result(0) = b0\n" + "result(1) = l\n" + "doUnitTest = result\n" +"End Function\n" +); + +// Although basic might appear to correctly change nested struct elements +// fdo#60117 shows that basic can be fooled ( and even the watch(ed) variable +// in the debugger shows the expected values ) +// 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 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" + "doUnitTest = aWinDesc\n" +"End Function\n" +); + + +void Nested_Struct::testAssign1() +{ + 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() +{ + 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; + + int result = aBorder.HorizontalLine.OuterLineWidth; + CPPUNIT_ASSERT_EQUAL( 9, result ); +} + +void Nested_Struct::testOldAssign() +{ + 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() +{ + 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; + + int result = aBorder.HorizontalLine.OuterLineWidth; + CPPUNIT_ASSERT_EQUAL( 9, result ); +} + +void Nested_Struct::testUnfixedVarAssign() +{ + MacroSnippet myMacro( sTestSource3 ); + myMacro.Compile(); + CPPUNIT_ASSERT_MESSAGE("testUnfixedVarAssign fails with compile error",!myMacro.HasError() ); + // forces a broadcast + SbxVariableRef pNew = myMacro.Run(); + CPPUNIT_ASSERT(pNew->GetInteger() == 13 ); +} + +void Nested_Struct::testUnfixedVarAssignAlt() +{ + 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; + bool bRes = aRet >>= aResult; + CPPUNIT_ASSERT_EQUAL(true, bRes ); + + int result = aResult.getLength(); + // should have 2 elements in a sequence returned + CPPUNIT_ASSERT_EQUAL(2, result ); + + table::TableBorder aBorder; + aResult[0] >>= aBorder; + + table::BorderLine aBorderLine; + aResult[1] >>= aBorderLine; + result = aBorder.HorizontalLine.OuterLineWidth; + CPPUNIT_ASSERT_EQUAL(9, result ); + result = aBorderLine.OuterLineWidth; + CPPUNIT_ASSERT_EQUAL(4, result ); +} + +void Nested_Struct::testFixedVarAssign() +{ + 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() +{ + 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; + bool bRes = aRet >>= aResult; + CPPUNIT_ASSERT_EQUAL(true, bRes ); + + int result = aResult.getLength(); + // should have 2 elements in a sequence returned + CPPUNIT_ASSERT_EQUAL(2, result ); + + table::TableBorder aBorder; + aResult[0] >>= aBorder; + + table::BorderLine aBorderLine; + aResult[1] >>= aBorderLine; + result = aBorder.HorizontalLine.OuterLineWidth; + CPPUNIT_ASSERT_EQUAL(9, result ); + result = aBorderLine.OuterLineWidth; + CPPUNIT_ASSERT_EQUAL(4, result ); +} + +void Nested_Struct::testUnoAccess() +{ + 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; + + int result = aWinDesc.Bounds.X; + CPPUNIT_ASSERT_EQUAL(200, result ); +} + + // Put the test suite in the registry + CPPUNIT_TEST_SUITE_REGISTRATION(Nested_Struct); +} // namespace +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basic/qa/cppunit/test_scanner.cxx b/basic/qa/cppunit/test_scanner.cxx index 0935f66a6fba..bce45c448c4c 100644 --- a/basic/qa/cppunit/test_scanner.cxx +++ b/basic/qa/cppunit/test_scanner.cxx @@ -1,14 +1,13 @@ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* - * Copyright 2012 LibreOffice contributors. + * 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/. */ -#include "sal/config.h" -#include "sal/precppunit.hxx" +#include <sal/types.h> #include "cppunit/TestAssert.h" #include "cppunit/TestFixture.h" #include "cppunit/extensions/HelperMacros.h" @@ -26,7 +25,7 @@ namespace sal_uInt16 line; sal_uInt16 col1; sal_uInt16 col2; - rtl::OUString text; + OUString text; double number; SbxDataType type; }; @@ -67,14 +66,14 @@ namespace CPPUNIT_TEST_SUITE_END(); }; - const static rtl::OUString cr(RTL_CONSTASCII_USTRINGPARAM("\n")); - const static rtl::OUString rem(RTL_CONSTASCII_USTRINGPARAM("REM")); - const static rtl::OUString asdf(RTL_CONSTASCII_USTRINGPARAM("asdf")); - const static rtl::OUString dot(RTL_CONSTASCII_USTRINGPARAM(".")); - const static rtl::OUString goto_(RTL_CONSTASCII_USTRINGPARAM("goto")); - const static rtl::OUString excl(RTL_CONSTASCII_USTRINGPARAM("!")); + const static OUString cr("\n"); + const static OUString rem("REM"); + const static OUString asdf("asdf"); + const static OUString dot("."); + const static OUString goto_("goto"); + const static OUString excl("!"); - std::vector<Symbol> getSymbols(const rtl::OUString& source, sal_Int32& errors, bool bCompatible = false) + std::vector<Symbol> getSymbols(const OUString& source, sal_Int32& errors, bool bCompatible = false) { std::vector<Symbol> symbols; SbiScanner scanner(source); @@ -95,7 +94,7 @@ namespace return symbols; } - std::vector<Symbol> getSymbols(const rtl::OUString& source, bool bCompatible = false) + std::vector<Symbol> getSymbols(const OUString& source, bool bCompatible = false) { sal_Int32 i; return getSymbols(source, i, bCompatible); @@ -103,15 +102,15 @@ namespace void ScannerTest::testBlankLines() { - const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("")); - const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("\r\n")); - const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("\n")); - const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("\r")); - const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("\r\n\r\n")); - const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("\n\r")); - const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("\n\r\n")); - const rtl::OUString source8(RTL_CONSTASCII_USTRINGPARAM("\r\n\r")); - const rtl::OUString source9(RTL_CONSTASCII_USTRINGPARAM(" ")); + const OUString source1(""); + const OUString source2("\r\n"); + const OUString source3("\n"); + const OUString source4("\r"); + const OUString source5("\r\n\r\n"); + const OUString source6("\n\r"); + const OUString source7("\n\r\n"); + const OUString source8("\r\n\r"); + const OUString source9(" "); std::vector<Symbol> symbols; symbols = getSymbols(source1); @@ -168,14 +167,14 @@ namespace void ScannerTest::testOperators() { - const rtl::OUString sourceE(RTL_CONSTASCII_USTRINGPARAM("=")); - const rtl::OUString sourceLT(RTL_CONSTASCII_USTRINGPARAM("<")); - const rtl::OUString sourceGT(RTL_CONSTASCII_USTRINGPARAM(">")); - const rtl::OUString sourceLTE(RTL_CONSTASCII_USTRINGPARAM("<=")); - const rtl::OUString sourceGTE(RTL_CONSTASCII_USTRINGPARAM(">=")); - const rtl::OUString sourceEE(RTL_CONSTASCII_USTRINGPARAM("==")); - const rtl::OUString sourceNE(RTL_CONSTASCII_USTRINGPARAM("<>")); - const rtl::OUString sourceA(RTL_CONSTASCII_USTRINGPARAM(":=")); + const OUString sourceE("="); + const OUString sourceLT("<"); + const OUString sourceGT(">"); + const OUString sourceLTE("<="); + const OUString sourceGTE(">="); + const OUString sourceEE("=="); + const OUString sourceNE("<>"); + const OUString sourceA(":="); std::vector<Symbol> symbols; @@ -240,18 +239,18 @@ namespace void ScannerTest::testAlphanum() { - const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("asdfghefg")); - const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("1asfdasfd")); - const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("AdfsaAUdsl10987")); - const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("asdfa_mnvcnm")); - const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("_asdf1")); - const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("_6")); - const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("joxclk_")); - const rtl::OUString source8(RTL_CONSTASCII_USTRINGPARAM(" asdf ")); - const rtl::OUString source9(RTL_CONSTASCII_USTRINGPARAM(" 19395 asdfa ")); - const rtl::OUString source10(RTL_CONSTASCII_USTRINGPARAM("\n1\n2\na sdf")); - const rtl::OUString source11(RTL_CONSTASCII_USTRINGPARAM("asdf.asdf")); - const rtl::OUString source12(RTL_CONSTASCII_USTRINGPARAM("..")); + const OUString source1("asdfghefg"); + const OUString source2("1asfdasfd"); + const OUString source3("AdfsaAUdsl10987"); + const OUString source4("asdfa_mnvcnm"); + const OUString source5("_asdf1"); + const OUString source6("_6"); + const OUString source7("joxclk_"); + const OUString source8(" asdf "); + const OUString source9(" 19395 asdfa "); + const OUString source10("\n1\n2\na sdf"); + const OUString source11("asdf.asdf"); + const OUString source12(".."); std::vector<Symbol> symbols; @@ -267,7 +266,7 @@ namespace CPPUNIT_ASSERT(symbols[0].text.isEmpty()); // Can't start symbol with a digit CPPUNIT_ASSERT(symbols[0].number == 1); CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER); - CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("asfdasfd"))); + CPPUNIT_ASSERT(symbols[1].text == OUString("asfdasfd")); CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT); CPPUNIT_ASSERT(symbols[2].text == cr); CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT); @@ -302,15 +301,15 @@ namespace symbols = getSymbols(source7); CPPUNIT_ASSERT(symbols.size() == 2); - CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("joxclk_"))); + CPPUNIT_ASSERT(symbols[0].text == OUString("joxclk_")); CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT); - CPPUNIT_ASSERT(source7 == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("joxclk "))); // Change the trailing '_' to a ' ' + CPPUNIT_ASSERT(source7 == OUString("joxclk ")); // Change the trailing '_' to a ' ' CPPUNIT_ASSERT(symbols[1].text == cr); CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT); symbols = getSymbols(source8); CPPUNIT_ASSERT(symbols.size() == 2); - CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("asdf"))); + CPPUNIT_ASSERT(symbols[0].text == OUString("asdf")); CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT); CPPUNIT_ASSERT(symbols[1].text == cr); CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT); @@ -320,7 +319,7 @@ namespace CPPUNIT_ASSERT(symbols[0].text.isEmpty()); CPPUNIT_ASSERT(symbols[0].number = 19395); CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER); - CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("asdfa"))); + CPPUNIT_ASSERT(symbols[1].text == OUString("asdfa")); CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT); CPPUNIT_ASSERT(symbols[2].text == cr); CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT); @@ -342,7 +341,7 @@ namespace CPPUNIT_ASSERT(symbols[5].text.getLength() == 1); CPPUNIT_ASSERT(symbols[5].text[0] == 'a'); CPPUNIT_ASSERT(symbols[5].type == SbxVARIANT); - CPPUNIT_ASSERT(symbols[6].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdf"))); + CPPUNIT_ASSERT(symbols[6].text == OUString("sdf")); CPPUNIT_ASSERT(symbols[6].type == SbxVARIANT); CPPUNIT_ASSERT(symbols[7].text == cr); CPPUNIT_ASSERT(symbols[7].type == SbxVARIANT); @@ -370,13 +369,13 @@ namespace void ScannerTest::testComments() { - const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("REM asdf")); - const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("REMasdf")); - const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("'asdf")); - const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("asdf _\n'100")); - const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("'asdf _\n100")); - const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("'asdf _\n'100")); - const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("'asdf _\n 1234 _\n asdf'")); + const OUString source1("REM asdf"); + const OUString source2("REMasdf"); + const OUString source3("'asdf"); + const OUString source4("asdf _\n'100"); + const OUString source5("'asdf _\n100"); + const OUString source6("'asdf _\n'100"); + const OUString source7("'asdf _\n 1234 _\n asdf'"); std::vector<Symbol> symbols; @@ -387,7 +386,7 @@ namespace symbols = getSymbols(source2); CPPUNIT_ASSERT(symbols.size() == 2); - CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REMasdf"))); + CPPUNIT_ASSERT(symbols[0].text == OUString("REMasdf")); CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT); CPPUNIT_ASSERT(symbols[1].text == cr); CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT); @@ -436,9 +435,9 @@ namespace void ScannerTest::testGoto() { - const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("goto")); - const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("go to")); - const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("go\nto")); + const OUString source1("goto"); + const OUString source2("go to"); + const OUString source3("go\nto"); std::vector<Symbol> symbols; @@ -451,20 +450,20 @@ namespace symbols = getSymbols(source2); CPPUNIT_ASSERT(symbols.size() == 3); - CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("go"))); + CPPUNIT_ASSERT(symbols[0].text == OUString("go")); CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT); - CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("to"))); + CPPUNIT_ASSERT(symbols[1].text == OUString("to")); CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT); CPPUNIT_ASSERT(symbols[2].text == cr); CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT); symbols = getSymbols(source3); CPPUNIT_ASSERT(symbols.size() == 4); - CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("go"))); + CPPUNIT_ASSERT(symbols[0].text == OUString("go")); CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT); CPPUNIT_ASSERT(symbols[1].text == cr); CPPUNIT_ASSERT(symbols[1].type == SbxVARIANT); - CPPUNIT_ASSERT(symbols[2].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("to"))); + CPPUNIT_ASSERT(symbols[2].text == OUString("to")); CPPUNIT_ASSERT(symbols[2].type == SbxVARIANT); CPPUNIT_ASSERT(symbols[3].text == cr); CPPUNIT_ASSERT(symbols[3].type == SbxVARIANT); @@ -472,9 +471,9 @@ namespace void ScannerTest::testGotoCompatible() { - const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("goto")); - const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("go to")); - const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("go\nto")); + const OUString source1("goto"); + const OUString source2("go to"); + const OUString source3("go\nto"); std::vector<Symbol> symbols; @@ -485,25 +484,25 @@ namespace symbols = getSymbols(source2, true); CPPUNIT_ASSERT(symbols.size() == 2); - CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(goto_)); + CPPUNIT_ASSERT(symbols[0].text == OUString(goto_)); CPPUNIT_ASSERT(symbols[1].text == cr); symbols = getSymbols(source3, true); CPPUNIT_ASSERT(symbols.size() == 4); - CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("go"))); + CPPUNIT_ASSERT(symbols[0].text == OUString("go")); CPPUNIT_ASSERT(symbols[1].text == cr); - CPPUNIT_ASSERT(symbols[2].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("to"))); + CPPUNIT_ASSERT(symbols[2].text == OUString("to")); CPPUNIT_ASSERT(symbols[3].text == cr); } void ScannerTest::testExclamation() { - const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("asdf!asdf")); - const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("!1234")); - const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("!_3")); - const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("!$")); - const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("!%")); - const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("!\n")); + const OUString source1("asdf!asdf"); + const OUString source2("!1234"); + const OUString source3("!_3"); + const OUString source4("!$"); + const OUString source5("!%"); + const OUString source6("!\n"); std::vector<Symbol> symbols; @@ -524,19 +523,19 @@ namespace symbols = getSymbols(source3); CPPUNIT_ASSERT(symbols.size() == 3); CPPUNIT_ASSERT(symbols[0].text == excl); - CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_3"))); + CPPUNIT_ASSERT(symbols[1].text == OUString("_3")); CPPUNIT_ASSERT(symbols[2].text == cr); symbols = getSymbols(source4); CPPUNIT_ASSERT(symbols.size() == 3); CPPUNIT_ASSERT(symbols[0].text == excl); - CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("$"))); + CPPUNIT_ASSERT(symbols[1].text == OUString("$")); CPPUNIT_ASSERT(symbols[2].text == cr); symbols = getSymbols(source5); CPPUNIT_ASSERT(symbols.size() == 3); CPPUNIT_ASSERT(symbols[0].text == excl); - CPPUNIT_ASSERT(symbols[1].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%"))); + CPPUNIT_ASSERT(symbols[1].text == OUString("%")); CPPUNIT_ASSERT(symbols[2].text == cr); symbols = getSymbols(source6); @@ -547,22 +546,22 @@ namespace void ScannerTest::testNumbers() { - const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("12345")); - const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("1.2.3")); - const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("123.4")); - const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("0.5")); - const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("5.0")); - const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("0.0")); - const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("-3")); - const rtl::OUString source8(RTL_CONSTASCII_USTRINGPARAM("-0.0")); - const rtl::OUString source9(RTL_CONSTASCII_USTRINGPARAM("12dE3")); - const rtl::OUString source10(RTL_CONSTASCII_USTRINGPARAM("12e3")); - const rtl::OUString source11(RTL_CONSTASCII_USTRINGPARAM("12D+3")); - const rtl::OUString source12(RTL_CONSTASCII_USTRINGPARAM("12e++3")); - const rtl::OUString source13(RTL_CONSTASCII_USTRINGPARAM("12e-3")); - const rtl::OUString source14(RTL_CONSTASCII_USTRINGPARAM("12e-3+")); - const rtl::OUString source15(RTL_CONSTASCII_USTRINGPARAM("1,2,3")); - const rtl::OUString source16(RTL_CONSTASCII_USTRINGPARAM("1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + const OUString source1("12345"); + const OUString source2("1.2.3"); + const OUString source3("123.4"); + const OUString source4("0.5"); + const OUString source5("5.0"); + const OUString source6("0.0"); + const OUString source7("-3"); + const OUString source8("-0.0"); + const OUString source9("12dE3"); + const OUString source10("12e3"); + const OUString source11("12D+3"); + const OUString source12("12e++3"); + const OUString source13("12e-3"); + const OUString source14("12e-3+"); + const OUString source15("1,2,3"); + const OUString source16("1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); std::vector<Symbol> symbols; sal_Int32 errors; @@ -611,7 +610,7 @@ namespace symbols = getSymbols(source7, errors); CPPUNIT_ASSERT(symbols.size() == 3); - CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-"))); + CPPUNIT_ASSERT(symbols[0].text == OUString("-")); CPPUNIT_ASSERT(symbols[1].number == 3); CPPUNIT_ASSERT(symbols[1].type == SbxINTEGER); CPPUNIT_ASSERT(symbols[2].text == cr); @@ -619,7 +618,7 @@ namespace symbols = getSymbols(source8, errors); CPPUNIT_ASSERT(symbols.size() == 3); - CPPUNIT_ASSERT(symbols[0].text == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("-"))); + CPPUNIT_ASSERT(symbols[0].text == OUString("-")); CPPUNIT_ASSERT(symbols[1].number == 0); CPPUNIT_ASSERT(symbols[1].type == SbxDOUBLE); CPPUNIT_ASSERT(symbols[2].text == cr); @@ -650,7 +649,7 @@ namespace CPPUNIT_ASSERT(symbols.size() == 4); CPPUNIT_ASSERT(symbols[0].number == 12); CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE); - CPPUNIT_ASSERT(symbols[1].text == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("+"))); + CPPUNIT_ASSERT(symbols[1].text == OUString("+")); CPPUNIT_ASSERT(symbols[2].number == 3); CPPUNIT_ASSERT(symbols[2].type == SbxINTEGER); CPPUNIT_ASSERT(symbols[3].text == cr); @@ -667,7 +666,7 @@ namespace CPPUNIT_ASSERT(symbols.size() == 3); CPPUNIT_ASSERT(symbols[0].number == .012); CPPUNIT_ASSERT(symbols[0].type == SbxDOUBLE); - CPPUNIT_ASSERT(symbols[1].text == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("+"))); + CPPUNIT_ASSERT(symbols[1].text == OUString("+")); CPPUNIT_ASSERT(symbols[2].text == cr); CPPUNIT_ASSERT(errors == 0); @@ -675,10 +674,10 @@ namespace CPPUNIT_ASSERT(symbols.size() == 6); CPPUNIT_ASSERT(symbols[0].number == 1); CPPUNIT_ASSERT(symbols[0].type == SbxINTEGER); - CPPUNIT_ASSERT(symbols[1].text == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","))); + CPPUNIT_ASSERT(symbols[1].text == OUString(",")); CPPUNIT_ASSERT(symbols[2].number == 2); CPPUNIT_ASSERT(symbols[2].type == SbxINTEGER); - CPPUNIT_ASSERT(symbols[3].text == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(","))); + CPPUNIT_ASSERT(symbols[3].text == OUString(",")); CPPUNIT_ASSERT(symbols[4].number == 3); CPPUNIT_ASSERT(symbols[4].type == SbxINTEGER); CPPUNIT_ASSERT(symbols[5].text == cr); @@ -696,13 +695,13 @@ namespace void ScannerTest::testDataType() { - const rtl::OUString source1(RTL_CONSTASCII_USTRINGPARAM("asdf%")); - const rtl::OUString source2(RTL_CONSTASCII_USTRINGPARAM("asdf&")); - const rtl::OUString source3(RTL_CONSTASCII_USTRINGPARAM("asdf!")); - const rtl::OUString source4(RTL_CONSTASCII_USTRINGPARAM("asdf#")); - const rtl::OUString source5(RTL_CONSTASCII_USTRINGPARAM("asdf@")); - const rtl::OUString source6(RTL_CONSTASCII_USTRINGPARAM("asdf$")); - const rtl::OUString source7(RTL_CONSTASCII_USTRINGPARAM("asdf ")); + const OUString source1("asdf%"); + const OUString source2("asdf&"); + const OUString source3("asdf!"); + const OUString source4("asdf#"); + const OUString source5("asdf@"); + const OUString source6("asdf$"); + const OUString source7("asdf "); std::vector<Symbol> symbols; @@ -744,95 +743,95 @@ namespace 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")); + const OUString source1("&HA"); + const OUString source2("&HASDF"); + const OUString source3("&H10"); + const OUString source4("&&H&1H1&H1"); + const OUString source5("&O&O12"); + const OUString source6("&O10"); + const OUString source7("&HO"); + const OUString source8("&O123000000000000000000000"); + const OUString source9("&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].text == 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].text == 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].text == 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].text == OUString("&")); CPPUNIT_ASSERT(symbols[0].type == SbxVARIANT); CPPUNIT_ASSERT(symbols[1].number == 0); - CPPUNIT_ASSERT(symbols[1].text == rtl::OUString()); + CPPUNIT_ASSERT(symbols[1].text == OUString()); CPPUNIT_ASSERT(symbols[1].type == SbxINTEGER); CPPUNIT_ASSERT(symbols[2].number == 1); - CPPUNIT_ASSERT(symbols[2].text == rtl::OUString()); + CPPUNIT_ASSERT(symbols[2].text == 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].text == OUString("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].text == OUString("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].text == 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].text == OUString("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].text == 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[0].text == OUString()); CPPUNIT_ASSERT(symbols[1].text == cr); symbols = getSymbols(source8); CPPUNIT_ASSERT(symbols.size() == 2); // TODO: this line fails on 64 bit systems!!! // CPPUNIT_ASSERT(symbols[0].number == -1744830464); - CPPUNIT_ASSERT(symbols[0].text == rtl::OUString()); + CPPUNIT_ASSERT(symbols[0].text == 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].text == 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].text == OUString()); CPPUNIT_ASSERT(symbols[1].type == SbxDOUBLE); CPPUNIT_ASSERT(symbols[2].text == cr); } diff --git a/basic/qa/cppunit/test_structref.cxx b/basic/qa/cppunit/test_structref.cxx new file mode 100644 index 000000000000..17ffcf36b246 --- /dev/null +++ b/basic/qa/cppunit/test_structref.cxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright 2012 LibreOffice contributors. + * + * 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/. + */ +#include "basictest.hxx" +#include "osl/file.hxx" +#include "osl/process.h" + +#include "basic/sbmod.hxx" +#include "basic/sbmeth.hxx" +#include "sbunoobj.hxx" +#include <com/sun/star/awt/WindowDescriptor.hpp> +#include <comphelper/anytostring.hxx> + +using namespace com::sun::star; +namespace +{ + class Test_StructRef : public BasicTestBase + { + public: + Test_StructRef() {}; + void testSimple(); + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE(Test_StructRef); + + // Declares the method as a test to call + CPPUNIT_TEST(testSimple); + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); + }; + + +void Test_StructRef::testSimple() +{ + + uno::Any aWinDescAny; + awt::WindowDescriptor aDesc; + aWinDescAny <<= aDesc; + typelib_TypeDescription * pDeclTD = 0; + typelib_typedescription_getByName( &pDeclTD, aWinDescAny.getValueTypeName().pData ); + StructRefInfo aWinDesc( aWinDescAny, pDeclTD, 0 ); + SbUnoStructRefObject refObject( "aBasicWinDesc", aWinDesc ); + + +// StructRefInfo aInfo = refObject.getStructMember( "WindowServiceName" ); + StructRefInfo aBounds = refObject.getStructMember( "Bounds" ); + + SbUnoStructRefObject aBoundRef( "Bound", aBounds ); + StructRefInfo xInfo = aBoundRef.getStructMember( "X" ); + xInfo.setValue( uno::Any((sal_Int32)300) ); + + printf("\n\n\n"); + printf("aBasicWinDesc %s\n", OUStringToOString( comphelper::anyToString( aWinDescAny ), RTL_TEXTENCODING_UTF8 ).getStr() ); + + uno::Any aWinDescAnyCopy; + aWinDescAnyCopy = aWinDescAny; + + printf("aBasicWinDescCopy %s\n", OUStringToOString( comphelper::anyToString( aWinDescAnyCopy ), RTL_TEXTENCODING_UTF8 ).getStr() ); + + + CPPUNIT_ASSERT_EQUAL( true, false ); +} + // Put the test suite in the registry + CPPUNIT_TEST_SUITE_REGISTRATION(Test_StructRef); +} // namespace +CPPUNIT_PLUGIN_IMPLEMENT(); +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx new file mode 100644 index 000000000000..805267ab2fb8 --- /dev/null +++ b/basic/qa/cppunit/test_vba.cxx @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright 2012 LibreOffice contributors. + * + * 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/. + */ +#include "basictest.hxx" +#include <vcl/svapp.hxx> + +using namespace ::com::sun::star; + +namespace +{ + + + class VBATest : public test::BootstrapFixture + { + public: + VBATest() : BootstrapFixture(true, false) {} + ~VBATest(){} + void testMiscVBAFunctions(); + // Adds code needed to register the test suite + CPPUNIT_TEST_SUITE(VBATest); + + // Declares the method as a test to call + CPPUNIT_TEST(testMiscVBAFunctions); + //CPPUNIT_TEST(testOle); + + // End of test suite definition + CPPUNIT_TEST_SUITE_END(); + + }; + +void VBATest::testMiscVBAFunctions() +{ + const char* macroSource[] = { + "bytearraystring.vb", +#if 1// FIXED // datevalue test seems to depend on both locale and language + // settings, should try and rewrite the test to deal with that + "datevalue.vb", +#endif + "partition.vb", + "strconv.vb", + "dateserial.vb", + "format.vb", + "replace.vb", + "stringplusdouble.vb" + }; + rtl::OUString sMacroPathURL = getURLFromSrc("/basic/qa/vba_tests/"); + // Some test data expects the uk locale + AllSettings aSettings = Application::GetSettings(); + aSettings.SetLanguage( LANGUAGE_ENGLISH_UK ); + Application::SetSettings( aSettings ); + for ( sal_uInt32 i=0; i<SAL_N_ELEMENTS( macroSource ); ++i ) + { + rtl::OUString sMacroURL( sMacroPathURL ); + sMacroURL += rtl::OUString::createFromAscii( macroSource[ i ] ); + + MacroSnippet myMacro; + myMacro.LoadSourceFromFile( sMacroURL ); + SbxVariableRef pReturn = myMacro.Run(); + if ( pReturn ) + { + fprintf(stderr, "macro result for %s\n", macroSource[ i ] ); + fprintf(stderr, "macro returned:\n%s\n", rtl::OUStringToOString( pReturn->GetOUString(), RTL_TEXTENCODING_UTF8 ).getStr() ); + } + CPPUNIT_ASSERT_MESSAGE("No return variable huh?", pReturn != NULL ); + CPPUNIT_ASSERT_MESSAGE("Result not as expected", pReturn->GetOUString() == rtl::OUString("OK") ); + } +} + + // Put the test suite in the registry + + // Put the test suite in the registry + CPPUNIT_TEST_SUITE_REGISTRATION(VBATest); +} // namespace +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/basic/qa/vba_tests/bytearraystring.vb b/basic/qa/vba_tests/bytearraystring.vb new file mode 100644 index 000000000000..a4054d4a2ac4 --- /dev/null +++ b/basic/qa/vba_tests/bytearraystring.vb @@ -0,0 +1,68 @@ +Option VBASupport 1 +Option Explicit + +Dim passCount As Integer +Dim failCount As Integer +Dim displayMessage As Boolean +Dim thisTest As String + +Function doUnitTest() As String +Dim result As String +result = verify_ByteArrayString() +If failCount <> 0 Then + doUnitTest = result +Else + doUnitTest = "OK" +End If +End Function + +Sub Main() +MsgBox verify_ByteArrayString() +End Sub + +Function verify_ByteArrayString() As String + passCount = 0 + failCount = 0 + Dim result As String + + Dim testName As String + Dim MyString As String + Dim x() As Byte + Dim count As Integer + testName = "Test the conversion between bytearray and string" + + + On Error GoTo errorHandler + + MyString = "abc" + x = MyString ' string -> byte array + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + + count = UBound(x) ' 6 byte + + ' test bytes in string + result = result + updateResultString("test1 numbytes ", (count), 5) + + + MyString = x 'byte array -> string + result = result + updateResultString("test assign byte array to string", MyString, "abc") + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_ByteArrayString = result + Exit Function +errorHandler: + failCount = failCount + 1 + verify_ByteArrayString = "Error Handler hit" +End Function + +Function updateResultString(testDesc As String, actual As String, expected As String) As String +Dim result As String +If actual <> expected Then + result = result & Chr$(10) & testDesc & " Failed: expected " & expected & " got " & actual + failCount = failCount + 1 +Else + passCount = passCount + 1 +End If +updateResultString = result +End Function diff --git a/basic/qa/vba_tests/dateserial.vb b/basic/qa/vba_tests/dateserial.vb new file mode 100644 index 000000000000..9df5ae291cf3 --- /dev/null +++ b/basic/qa/vba_tests/dateserial.vb @@ -0,0 +1,65 @@ +Option VBASupport 1 +Option Explicit + +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String +result = verify_testDateSerial() +If failCount <> 0 And passCount > 0 Then + doUnitTest = result +Else + doUnitTest = "OK" +End If +End Function + +Function verify_testDateSerial() as String + Dim testName As String + Dim TestDateTime As Date + Dim TestStr As String + Dim date1, date2 As Date + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + + testName = "Test DateSerial function" + date2 = 36326 + + On Error GoTo errorHandler + + date1 = DateSerial(1999, 6, 15) '6/15/1999 + TestLog_ASSERT date1 = date2, "the return date is: " & date1 + date1 = DateSerial(2000, 1 - 7, 15) '6/15/1999 + TestLog_ASSERT date1 = date2, "the return date is: " & date1 + date1 = DateSerial(1999, 1, 166) '6/15/1999 + TestLog_ASSERT date1 = date2, "the return date is: " & date1 + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + + verify_testDateSerial = result + + Exit Function +errorHandler: + TestLog_ASSERT (False), testName & ": hit error handler" +End Function + +Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String) + + If assertion = True Then + passCount = passCount + 1 + Else + Dim testMsg As String + If Not IsMissing(testId) Then + testMsg = testMsg + " : " + testId + End If + If Not IsMissing(testComment) And Not (testComment = "") Then + testMsg = testMsg + " (" + testComment + ")" + End If + + result = result & Chr$(10) & " Failed: " & testMsg + failCount = failCount + 1 + End If + +End Sub + diff --git a/basic/qa/vba_tests/datevalue.vb b/basic/qa/vba_tests/datevalue.vb new file mode 100644 index 000000000000..20aac6416345 --- /dev/null +++ b/basic/qa/vba_tests/datevalue.vb @@ -0,0 +1,65 @@ +Option VBASupport 1 +Option Explicit +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String +result = verify_testDateValue() +If failCount <> 0 And passCount > 0 Then + doUnitTest = result +Else + doUnitTest = "OK" +End If +End Function + + + +Function verify_testDateValue() as String + + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + + Dim testName As String + Dim TestDateTime As Date + Dim TestStr As String + Dim date1, date2 As Date + testName = "Test DateValue function" + date2 = 25246 + + On Error GoTo errorHandler + + date1 = DateValue("February 12, 1969") '2/12/1969 + TestLog_ASSERT date1 = date2, "the return date is: " & date1 + + date2 = 39468 + date1 = DateValue("21/01/2008") '1/21/2008 + TestLog_ASSERT date1 = date2, "the return date is: " & date1 + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testDateValue = result + + Exit Function +errorHandler: + TestLog_ASSERT (False), testName & ": hit error handler" +End Sub + +Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String) + + If assertion = True Then + passCount = passCount + 1 + Else + Dim testMsg As String + If Not IsMissing(testId) Then + testMsg = testMsg + " : " + testId + End If + If Not IsMissing(testComment) And Not (testComment = "") Then + testMsg = testMsg + " (" + testComment + ")" + End If + + result = result & Chr$(10) & " Failed: " & testMsg + failCount = failCount + 1 + End If + +End Sub diff --git a/basic/qa/vba_tests/format.vb b/basic/qa/vba_tests/format.vb new file mode 100644 index 000000000000..b4f19281ba25 --- /dev/null +++ b/basic/qa/vba_tests/format.vb @@ -0,0 +1,406 @@ +Option VBASupport 1 +Option Explicit + +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String +result = verify_format() +If failCount <> 0 And passCount > 0 Then + doUnitTest = result +Else + doUnitTest = "OK" +End If +End Function + +Function verify_format() as String + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + + 'Predefined_Datetime_Format_Sample + Predefined_Number_Format_Sample + 'Custom_Datetime_Format_Sample + Custom_Number_Format_Sample + Custom_Text_Format_Sample + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_format = result + +End Sub + + +Sub Predefined_Datetime_Format_Sample() + Dim testName As String + Dim myDate, MyTime, TestStr As String + myDate = "01/06/98" + MyTime = "17:08:06" + testName = "Test Predefined_Datetime_Format_Sample function" + + On Error GoTo errorHandler + + ' The date/time format have a little different between ms office and OOo due to different locale and system... + TestStr = Format(myDate, "General Date") ' 1/6/98 + + TestLog_ASSERT IsDate(TestStr), "General Date: " & TestStr & " (Test only applies to en_US locale)" + 'TestLog_ASSERT TestStr = "1/6/98", "General Date: " & TestStr + + TestStr = Format(myDate, "Long Date") ' Tuesday, January 06, 1998 + TestLog_ASSERT TestStr = "Tuesday, January 06, 1998", "Long Date: " & TestStr & " (Test only applies to en_US locale)" + 'TestLog_ASSERT IsDate(TestStr), "Long Date: " & TestStr + + TestStr = Format(myDate, "Medium Date") ' 06-Jan-98 + 'TestLog_ASSERT TestStr = "06-Jan-98", "Medium Date: " & TestStr + TestLog_ASSERT IsDate(TestStr), "Medium Date: " & TestStr & " (Test only applies to en_US locale)" + + + TestStr = Format(myDate, "Short Date") ' 1/6/98 + 'TestLog_ASSERT TestStr = "1/6/98", "Short Date: " & TestStr + TestLog_ASSERT IsDate(TestStr), "Short Date: " & TestStr & " (Test only applies to en_US locale)" + + TestStr = Format(MyTime, "Long Time") ' 5:08:06 PM + 'TestLog_ASSERT TestStr = "5:08:06 PM", "Long Time: " & TestStr + TestLog_ASSERT IsDate(TestStr), "Long Time: " & TestStr & " (Test only applies to en_US locale)" + + + TestStr = Format(MyTime, "Medium Time") ' 05:08 PM + 'TestLog_ASSERT TestStr = "05:08 PM", "Medium Time: " & TestStr + TestLog_ASSERT IsDate(TestStr), "Medium Time: " & TestStr & " (Test only applies to en_US locale)" + + + TestStr = Format(MyTime, "Short Time") ' 17:08 + 'TestLog_ASSERT TestStr = "17:08", "Short Time: " & TestStr + TestLog_ASSERT IsDate(TestStr), "Short Time: " & TestStr & " (Test only applies to en_US locale)" + Exit Sub +errorHandler: + TestLog_ASSERT (false), testName & ": hit error handler" +End Sub + +Sub Predefined_Number_Format_Sample() + Dim myNumber, TestStr As String + Dim testName As String + testName = "Test Predefined_Number_Format_Sample function" + myNumber = 562486.2356 + + On Error GoTo errorHandler + + TestStr = Format(myNumber, "General Number") '562486.2356 + TestLog_ASSERT TestStr = "562486.2356", "General Number: " & TestStr + 'MsgBox TestStr + + TestStr = Format(0.2, "Fixed") '0.20 + TestLog_ASSERT TestStr = "0.20", "Fixed: " & TestStr + 'MsgBox TestStr + + TestStr = Format(myNumber, "Standard") '562,486.24 + TestLog_ASSERT TestStr = "562,486.24", "Standard: " & TestStr + 'MsgBox TestStr + + TestStr = Format(0.7521, "Percent") '75.21% + TestLog_ASSERT TestStr = "75.21%", "Percent: " & TestStr + 'MsgBox TestStr + + TestStr = Format(myNumber, "Scientific") '5.62E+05 + TestLog_ASSERT TestStr = "5.62E+05", "Scientific: " & TestStr + 'MsgBox TestStr + + TestStr = Format(-3456.789, "Scientific") '-3.46E+03 + TestLog_ASSERT TestStr = "-3.46E+03", "Scientific: " & TestStr + 'MsgBox TestStr + + TestStr = Format(0, "Yes/No") 'No + TestLog_ASSERT TestStr = "No", "Yes/No: " & TestStr + 'MsgBox TestStr + + TestStr = Format(23, "Yes/No") 'Yes + TestLog_ASSERT TestStr = "Yes", "Yes/No: " & TestStr + 'MsgBox TestStr + + TestStr = Format(0, "True/False") 'False + TestLog_ASSERT TestStr = "False", "True/False: " & TestStr + 'MsgBox TestStr + + TestStr = Format(23, "True/False") 'True + TestLog_ASSERT TestStr = "True", "True/False: " & TestStr + 'MsgBox TestStr + + TestStr = Format(0, "On/Off") 'Off + TestLog_ASSERT TestStr = "Off", "On/Off: " & TestStr + 'MsgBox TestStr + + TestStr = Format(23, "On/Off") 'On + TestLog_ASSERT TestStr = "On", "On/Off: " & TestStr + 'MsgBox TestStr + + Exit Sub +errorHandler: + TestLog_ASSERT (false), testName & ": hit error handler" + +End Sub + +Sub Custom_Datetime_Format_Sample() + Dim myDate, MyTime, TestStr As String + Dim testName As String + + myDate = "01/06/98" + MyTime = "05:08:06" + + testName = "Test Custom_Datetime_Format_Sample function" + On Error GoTo errorHandler + + TestStr = Format("01/06/98 17:08:06", "c") ' 1/6/98 5:08:06 PM + TestLog_ASSERT TestStr = "1/6/98 5:08:06 PM", "c: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "dddddd") ' (Long Date), Tuesday, January 06, 1998 + TestLog_ASSERT TestStr = "Tuesday, January 06, 1998", "dddddd: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "mm-dd-yyyy") ' 01-06-19s98 + TestLog_ASSERT TestStr = "01-06-1998", "mm-dd-yyyy: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "d") ' 6 + TestLog_ASSERT TestStr = "6", "d: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "dd") ' 06 + TestLog_ASSERT TestStr = "06", "dd: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "ddd") ' Tue + TestLog_ASSERT TestStr = "Tue", "ddd: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "dddd") ' Tuesday + TestLog_ASSERT TestStr = "Tuesday", "dddd: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(MyTime, "h") ' 5 + TestLog_ASSERT TestStr = "5", "h: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(MyTime, "hh") ' 05 + TestLog_ASSERT TestStr = "05", "hh: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(MyTime, "n") ' 8 + TestLog_ASSERT TestStr = "8", "n: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(MyTime, "nn") ' 08 + TestLog_ASSERT TestStr = "08", "nn: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "m") ' 1 + TestLog_ASSERT TestStr = "1", "m: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "mm") ' 01 + TestLog_ASSERT TestStr = "01", "mm: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "mmm") ' Jan + TestLog_ASSERT TestStr = "Jan", "mmm: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "mmmm") ' January + TestLog_ASSERT TestStr = "January", "mmmm: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(MyTime, "s") ' 6 + TestLog_ASSERT TestStr = "6", "s: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(MyTime, "ss") ' 06 + TestLog_ASSERT TestStr = "06", "ss: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + + MyTime = "17:08:06" + + TestStr = Format(MyTime, "hh:mm:ss AM/PM") ' 05:08:06 PM + TestLog_ASSERT TestStr = "05:08:06 PM", "hh:mm:ss AM/PM: " & TestStr & " (Test only applies to en_US locale)" + + + TestStr = Format(MyTime, "hh:mm:ss") ' 17:08:06 + TestLog_ASSERT TestStr = "17:08:06", "hh:mm:ss: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "ww") ' 2 + TestLog_ASSERT TestStr = "2", "ww: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "w") ' 3 + TestLog_ASSERT TestStr = "3", "w: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "y") ' 6 + TestLog_ASSERT TestStr = "6", "y: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "yy") ' 98 + TestLog_ASSERT TestStr = "98", "yy: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + TestStr = Format(myDate, "yyyy") ' 1998 + TestLog_ASSERT TestStr = "1998", "yyyy: " & TestStr & " (Test only applies to en_US locale)" + 'MsgBox TestStr + + Exit Sub +errorHandler: + TestLog_ASSERT (false), testName & ": hit error handler" +End Sub + +Sub Custom_Number_Format_Sample() + Dim TestStr As String + Dim testName As String + + testName = "Test Custom_Number_Format_Sample function" + On Error GoTo errorHandler + + TestStr = Format(23.675, "00.0000") ' 23.6750 + TestLog_ASSERT TestStr = "23.6750", "00.0000: " & TestStr + 'MsgBox TestStr + + TestStr = Format(23.675, "00.00") ' 23.68 + TestLog_ASSERT TestStr = "23.68", "00.00: " & TestStr + 'MsgBox TestStr + + TestStr = Format(2658, "00000") ' 02658 + TestLog_ASSERT TestStr = "02658", "00000: " & TestStr + 'MsgBox TestStr + + TestStr = Format(2658, "00.00") ' 2658.00 + TestLog_ASSERT TestStr = "2658.00", "00.00: " & TestStr + 'MsgBox TestStr + + TestStr = Format(23.675, "##.####") ' 23.675 + TestLog_ASSERT TestStr = "23.675", "##.####: " & TestStr + 'MsgBox TestStr + + TestStr = Format(23.675, "##.##") ' 23.68 + TestLog_ASSERT TestStr = "23.68", "##.##: " & TestStr + 'MsgBox TestStr + + TestStr = Format(12345.25, "#,###.##") '12,345.25 + TestLog_ASSERT TestStr = "12,345.25", "#,###.##: " & TestStr + 'MsgBox TestStr + + TestStr = Format(0.25, "##.00%") '25.00% + TestLog_ASSERT TestStr = "25.00%", "##.00%: " & TestStr + 'MsgBox TestStr + + TestStr = Format(1000000, "#,###") '1,000,000 + TestLog_ASSERT TestStr = "1,000,000", "#,###: " & TestStr + 'MsgBox TestStr + + TestStr = Format(1.09837555, "######E-###") '109838E-5 + TestLog_ASSERT TestStr = "109838E-5", "######E-###: " & TestStr + 'MsgBox TestStr + + TestStr = Format(2345.25, "$#,###.##") '$2.345.25 + TestLog_ASSERT TestStr = "$2,345.25", "$#,###.##: " & TestStr + 'MsgBox TestStr + + TestStr = Format(0.25, "##.###\%") '.25% + TestLog_ASSERT TestStr = ".25%", "##.###\%: " & TestStr + 'MsgBox TestStr + + Exit Sub +errorHandler: + TestLog_ASSERT (false), testName & ": hit error handler" +End Sub + +Sub Custom_Text_Format_Sample() + Dim myText, TestStr As String + myText = "VBA" + + Dim testName As String + + testName = "Test Custom_Text_Format_Sample function" + On Error GoTo errorHandler + + TestStr = Format(myText, "<") 'vba + TestLog_ASSERT TestStr = "vba", "<: " & TestStr + 'MsgBox TestStr + + TestStr = Format("vba", ">") 'VBA + TestLog_ASSERT TestStr = "VBA", ">: " & TestStr + 'MsgBox TestStr + + Exit Sub +errorHandler: + TestLog_ASSERT (false), testName & "hit error handler" +End Sub + + + +Sub testFormat() + Dim testName As String + Dim TestDateTime As Date + Dim TestStr As String + testName = "Test Format function" + + On Error GoTo errorHandler + + TestDateTime = "1/27/2001 5:04:23 PM" + + ' Returns the value of TestDateTime in user-defined date/time formats. + ' Returns "17:4:23". + TestStr = Format(TestDateTime, "h:m:s") + TestLog_ASSERT TestStr = "17:4:23", "the format of h:m:s: " & TestStr + + ' Returns "05:04:23 PM". + TestStr = Format(TestDateTime, "ttttt") + TestLog_ASSERT TestStr = "5:04:23 PM", "the format of ttttt: " & TestStr + + ' Returns "Saturday, Jan 27 2001". + TestStr = Format(TestDateTime, "dddd, MMM d yyyy") + TestLog_ASSERT TestStr = "Saturday, Jan 27 2001", "the format of dddd, MMM d yyyy: " & TestStr + + ' Returns "17:04:23". + TestStr = Format(TestDateTime, "HH:mm:ss") + TestLog_ASSERT TestStr = "17:04:23", "the format of HH:mm:ss: " & TestStr + + ' Returns "23". + TestStr = Format(23) + TestLog_ASSERT TestStr = "23", "no format:" & TestStr + + ' User-defined numeric formats. + ' Returns "5,459.40". + TestStr = Format(5459.4, "##,##0.00") + TestLog_ASSERT TestStr = "5,459.40", "the format of ##,##0.00: " & TestStr + + ' Returns "334.90". + TestStr = Format(334.9, "###0.00") + TestLog_ASSERT TestStr = "334.90", "the format of ###0.00: " & TestStr + + ' Returns "500.00%". + TestStr = Format(5, "0.00%") + TestLog_ASSERT TestStr = "500.00%", "the format of 0.00%: " & TestStr + Exit Sub +errorHandler: + TestLog_ASSERT (false), testName & ": hit error handler" +End Sub + +Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String) + + If assertion = True Then + passCount = passCount + 1 + Else + Dim testMsg As String + If Not IsMissing(testId) Then + testMsg = testMsg + " : " + testId + End If + If Not IsMissing(testComment) And Not (testComment = "") Then + testMsg = testMsg + " (" + testComment + ")" + End If + + result = result & Chr$(10) & " Failed: " & testMsg + failCount = failCount + 1 + End If + +End Sub + diff --git a/basic/qa/vba_tests/partition.vb b/basic/qa/vba_tests/partition.vb new file mode 100644 index 000000000000..821cdebb21d8 --- /dev/null +++ b/basic/qa/vba_tests/partition.vb @@ -0,0 +1,71 @@ +Option VBASupport 1 +Option Explicit +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String +result = verify_testPartition() +If failCount <> 0 And passCount > 0 Then + doUnitTest = result +Else + doUnitTest = "OK" +End If +End Function + +Function verify_testPartition() as String + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + + + Dim testName As String + Dim retStr As String + testName = "Test Partition function" + On Error GoTo errorHandler + + retStr = Partition(20, 0, 98, 5) + 'MsgBox retStr + TestLog_ASSERT retStr = "20:24", "the number 20 occurs in the range:" & retStr + + retStr = Partition(20, 0, 99, 1) + 'MsgBox retStr + TestLog_ASSERT retStr = " 20: 20", "the number 20 occurs in the range:" & retStr + + retStr = Partition(120, 0, 99, 5) + 'MsgBox retStr + TestLog_ASSERT retStr = "100: ", "the number 120 occurs in the range:" & retStr + + retStr = Partition(-5, 0, 99, 5) + 'MsgBox retStr + TestLog_ASSERT retStr = " : -1", "the number -5 occurs in the range:" & retStr + + retStr = Partition(2, 0, 5, 2) + 'MsgBox retStr + TestLog_ASSERT retStr = " 2: 3", "the number 2 occurs in the range:" & retStr + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testPartition = result + Exit Function +errorHandler: + TestLog_ASSERT (false), "vertify_testPartion failed, hit error handler" +End Function + +Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String) + + If assertion = True Then + passCount = passCount + 1 + Else + Dim testMsg As String + If Not IsMissing(testId) Then + testMsg = testMsg + " : " + testId + End If + If Not IsMissing(testComment) And Not (testComment = "") Then + testMsg = testMsg + " (" + testComment + ")" + End If + + result = result & Chr$(10) & " Failed: " & testMsg + failCount = failCount + 1 + End If + +End Sub diff --git a/basic/qa/vba_tests/replace.vb b/basic/qa/vba_tests/replace.vb new file mode 100644 index 000000000000..e04cde058eb2 --- /dev/null +++ b/basic/qa/vba_tests/replace.vb @@ -0,0 +1,70 @@ +Option VBASupport 1 +Option Explicit +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String +result = verify_testReplace() +If failCount <> 0 And passCount > 0 Then + doUnitTest = result +Else + doUnitTest = "OK" +End If +End Function + +Function verify_testReplace() as String + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + + Dim testName As String + Dim srcStr, destStr, repStr, start, count, retStr + testName = "Test Replace function" + On Error GoTo errorHandler + srcStr = "abcbcdBc" + destStr = "bc" + repStr = "ef" + retStr = Replace(srcStr, destStr, repStr) + TestLog_ASSERT retStr = "aefefdBc", "common string:" & retStr + retStr = Replace("abcbcdbc", destStr, repStr) + TestLog_ASSERT retStr = "aefefdef", "expression string:" & retStr + retStr = Replace(srcStr, destStr, repStr, 1, -1, vbBinaryCompare) + TestLog_ASSERT retStr = "aefefdBc", "binanary compare:" & retStr + retStr = Replace(srcStr, destStr, repStr, 1, -1, vbTextCompare) + TestLog_ASSERT retStr = "aefefdef", "text compare:" & retStr + retStr = Replace(srcStr, destStr, repStr, compare:=vbTextCompare) + TestLog_ASSERT retStr = "aefefdef", "text compare:" & retStr + retStr = Replace(srcStr, destStr, repStr, 3, -1, vbBinaryCompare) + TestLog_ASSERT retStr = "cefdBc", "start = 3:" & retStr + retStr = Replace(srcStr, destStr, repStr, 1, 2, vbBinaryCompare) + TestLog_ASSERT retStr = "aefefdBc", "count = 2: " & retStr + retStr = Replace(srcStr, destStr, repStr, 1, 0, vbBinaryCompare) + TestLog_ASSERT retStr = "abcbcdBc", "start = 1, count = 0, not support in Unix: " & retStr + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testReplace = result + + Exit Function +errorHandler: + TestLog_ASSERT (False), testName & ": hit error handler" +End Function + +Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String) + + If assertion = True Then + passCount = passCount + 1 + Else + Dim testMsg As String + If Not IsMissing(testId) Then + testMsg = testMsg + " : " + testId + End If + If Not IsMissing(testComment) And Not (testComment = "") Then + testMsg = testMsg + " (" + testComment + ")" + End If + + result = result & Chr$(10) & " Failed: " & testMsg + failCount = failCount + 1 + End If + +End Sub diff --git a/basic/qa/vba_tests/strconv.vb b/basic/qa/vba_tests/strconv.vb new file mode 100644 index 000000000000..a98fbaa5b092 --- /dev/null +++ b/basic/qa/vba_tests/strconv.vb @@ -0,0 +1,90 @@ +Option VBASupport 1 +Option Explicit +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String +result = verify_testStrConv() +If failCount <> 0 And passCount > 0 Then + doUnitTest = result +Else + doUnitTest = "OK" +End If +End Function + +Function verify_testStrConv() as String + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + + Dim testName As String + Dim srcStr, retStr As String + Dim x() As Byte + srcStr = "abc EFG hij" + testName = "Test StrConv function" + On Error GoTo errorHandler + + retStr = StrConv(srcStr, vbUpperCase) + 'MsgBox retStr + TestLog_ASSERT retStr = "ABC EFG HIJ", "Converts the string to uppercase characters:" & retStr + + retStr = StrConv(srcStr, vbLowerCase) + 'MsgBox retStr + TestLog_ASSERT retStr = "abc efg hij", "Converts the string to lowercase characters:" & retStr + + retStr = StrConv(srcStr, vbProperCase) + 'MsgBox retStr + TestLog_ASSERT retStr = "Abc Efg Hij", "Converts the first letter of every word in string to uppercase:" & retStr + + 'retStr = StrConv("ABCDEVB¥ì¥¹¥¥å©`", vbWide) + 'MsgBox retStr + 'TestLog_ASSERT retStr = "£Á£Â£Ã£Ä£ÅVB¥ì¥¹¥¥å©`", "Converts narrow (single-byte) characters in string to wide" + + 'retStr = StrConv("£Á£Â£Ã£Ä£ÅVB¥ì¥¹¥¥å©`", vbNarrow) + 'MsgBox retStr + 'TestLog_ASSERT retStr = "ABCDEVB¥ì¥¹¥¥å©`", "Converts wide (double-byte) characters in string to narrow (single-byte) characters." & retStr + + 'retStr = StrConv("¤Ï¤Ê¤Á¤ã¤ó", vbKatakana) + 'MsgBox retStr + 'TestLog_ASSERT retStr = "¥Ï¥Ê¥Á¥ã¥ó", "Converts Hiragana characters in string to Katakana characters.." & retStr + + ' retStr = StrConv("¥Ï¥Ê¥Á¥ã¥ó", vbHiragana) + 'MsgBox retStr + ' TestLog_ASSERT retStr = "¤Ï¤Ê¤Á¤ã¤ó", "Converts Katakana characters in string to Hiragana characters.." & retStr + + 'x = StrConv("ÉϺ£ÊÐABC", vbFromUnicode) + 'MsgBox retStr + 'TestLog_ASSERT UBound(x) = 8, "Converts the string from Unicode, the lenght is : " & UBound(x) + 1 + + ' retStr = StrConv(x, vbUnicode) + 'MsgBox retStr + ' TestLog_ASSERT retStr = "ÉϺ£ÊÐABC", "Converts the string to Unicode: " & retStr + + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_testStrConv = result + + Exit Function +errorHandler: + TestLog_ASSERT (False), testName & ": hit error handler" +End Function + +Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String) + + If assertion = True Then + passCount = passCount + 1 + Else + Dim testMsg As String + If Not IsMissing(testId) Then + testMsg = testMsg + " : " + testId + End If + If Not IsMissing(testComment) And Not (testComment = "") Then + testMsg = testMsg + " (" + testComment + ")" + End If + + result = result & Chr$(10) & " Failed: " & testMsg + failCount = failCount + 1 + End If + +End Sub diff --git a/basic/qa/vba_tests/stringplusdouble.vb b/basic/qa/vba_tests/stringplusdouble.vb new file mode 100644 index 000000000000..e75cfdb4e161 --- /dev/null +++ b/basic/qa/vba_tests/stringplusdouble.vb @@ -0,0 +1,328 @@ +Option VBASupport 1 +Option Explicit +Dim passCount As Integer +Dim failCount As Integer +Dim result As String + +Function doUnitTest() As String +result = verify_stringplusdouble() +If failCount <> 0 And passCount > 0 Then + doUnitTest = result +Else + doUnitTest = "OK" +End If +End Function + +Function verify_stringplusdouble() as String + passCount = 0 + failCount = 0 + + result = "Test Results" & Chr$(10) & "============" & Chr$(10) + + DSD + SSD + DSS + result = result & Chr$(10) & "Tests passed: " & passCount & Chr$(10) & "Tests failed: " & failCount & Chr$(10) + verify_stringplusdouble = result +End Function + +Sub DSD() + Dim testName As String + testName = "double = string + double" + Dim testCompute As String + + Dim s As String + Dim d As Double + Dim r As Double + + On Error GoTo ErrorHandler + + testCompute = "s = null, d = null, r = s + d" + r = s + d + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + testCompute = "s = null, d = null, r = s & d" + r = s & d + TestLog_ASSERT r = 0, testCompute & " .The result is: " & r + + testCompute = "s = null, d = 20, r = s + d" + d = 20 + r = s + d + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + testCompute = "s = null, d = 20, r = s & d" + d = 20 + r = s & d + TestLog_ASSERT r = 20, testCompute & " .The result is: " & r + + + '''''''''''''' + s = "10" + Dim d2 As Double + testCompute = "s = '10', d = null, r = s + d" + r = s + d2 + TestLog_ASSERT r = 10, testCompute & " .The result is: " & r + + testCompute = "s = '10', d = null, r = s & d" + r = s & d2 + TestLog_ASSERT r = 100, testCompute & " .The result is: " & r + + testCompute = "s = '10', d = 20, r = s + d" + d2 = 20 + r = s + d2 + TestLog_ASSERT r = 30, testCompute & " .The result is: " & r + + testCompute = "s = '10', d = 20, r = s & d" + d2 = 20 + r = s & d2 + TestLog_ASSERT r = 1020, testCompute & " .The result is: " & r + + '''''''''''''' + s = "abc" + Dim d3 As Double + testCompute = "s = 'abc', d = null, r = s + d" + r = s + d3 + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + testCompute = "s = 'abc', d = null, r = s & d" + r = s & d3 + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + testCompute = "s = 'abc', d = 20, r = s + d" + d3 = 20 + r = s + d3 + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + testCompute = "s = 'abc', d = 20, r = s & d" + d3 = 20 + r = s & d3 + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + Exit Sub + +ErrorHandler: + r = -1 +' TestLog_Comment "The next compute raises error: " & testCompute + Resume Next +End Sub + + +Sub SSD() + Dim testName As String + testName = "string = string + double" + Dim testCompute As String + + Dim s As String + Dim d As Double + Dim r As String + + On Error GoTo ErrorHandler + + testCompute = "s = null, d = null, r = s + d" + r = s + d + TestLog_ASSERT r = "-1", testCompute & " .The result is: " & r + + testCompute = "s = null, d = null, r = s & d" + r = s & d + TestLog_ASSERT r = "0", testCompute & " .The result is: " & r + + testCompute = "s = null, d = 20, r = s + d" + d = 20 + r = s + d + TestLog_ASSERT r = "-1", testCompute & " .The result is: " & r + + testCompute = "s = null, d = 20, r = s & d" + d = 20 + r = s & d + TestLog_ASSERT r = "20", testCompute & " .The result is: " & r + + + '''''''''''''' + s = "10" + Dim d2 As Double + testCompute = "s = '10', d = null, r = s + d" + r = s + d2 + TestLog_ASSERT r = "10", testCompute & " .The result is: " & r + + testCompute = "s = '10', d = null, r = s & d" + r = s & d2 + TestLog_ASSERT r = "100", testCompute & " .The result is: " & r + + testCompute = "s = '10', d = 20, r = s + d" + d2 = 20 + r = s + d2 + TestLog_ASSERT r = "30", testCompute & " .The result is: " & r + + testCompute = "s = '10', d = 20, r = s & d" + d2 = 20 + r = s & d2 + TestLog_ASSERT r = "1020", testCompute & " .The result is: " & r + + '''''''''''''' + s = "abc" + Dim d3 As Double + testCompute = "s = 'abc', d = null, r = s + d" + r = s + d3 + TestLog_ASSERT r = "-1", testCompute & " .The result is: " & r + + testCompute = "s = 'abc', d = null, r = s & d" + r = s & d3 + TestLog_ASSERT r = "abc0", testCompute & " .The result is: " & r + + testCompute = "s = 'abc', d = 20, r = s + d" + d3 = 20 + r = s + d3 + TestLog_ASSERT r = "-1", testCompute & " .The result is: " & r + + testCompute = "s = 'abc', d = 20, r = s & d" + d3 = 20 + r = s & d3 + TestLog_ASSERT r = "abc20", testCompute & " .The result is: " & r + Exit Sub + +ErrorHandler: + r = "-1" +' TestLog_Comment "The next compute raises error: " & testCompute + Resume Next +End Sub + +Sub DSS() + Dim testName As String + testName = "double = string + string" + Dim testCompute As String + + Dim s As String + Dim d As String + Dim r As Double + + On Error GoTo ErrorHandler + + testCompute = "s = null, d = null, r = s + d" + r = s + d + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + testCompute = "s = null, d = null, r = s & d" + r = s & d + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + testCompute = "s = null, d = 20, r = s + d" + d = "20" + r = s + d + TestLog_ASSERT r = 20, testCompute & " .The result is: " & r + + testCompute = "s = null, d = 20, r = s & d" + d = "20" + r = s & d + TestLog_ASSERT r = 20, testCompute & " .The result is: " & r + + + '''''''''''''' + s = "10" + Dim d2 As String + testCompute = "s = '10', d = null, r = s + d" + r = s + d2 + TestLog_ASSERT r = 10, testCompute & " .The result is: " & r + + testCompute = "s = '10', d = null, r = s & d" + r = s & d2 + TestLog_ASSERT r = 10, testCompute & " .The result is: " & r + + testCompute = "s = '10', d = 20, r = s + d" + d2 = "20" + r = s + d2 + TestLog_ASSERT r = 1020, testCompute & " .The result is: " & r + + testCompute = "s = '10', d = 20, r = s & d" + d2 = "20" + r = s & d2 + TestLog_ASSERT r = 1020, testCompute & " .The result is: " & r + + '''''''''''''' + s = "abc" + Dim d3 As String + testCompute = "s = 'abc', d = null, r = s + d" + r = s + d3 + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + testCompute = "s = 'abc', d = null, r = s & d" + r = s & d3 + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + testCompute = "s = 'abc', d = 20, r = s + d" + d3 = "20" + r = s + d3 + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + + testCompute = "s = 'abc', d = 20, r = s & d" + d3 = "20" + r = s & d3 + TestLog_ASSERT r = -1, testCompute & " .The result is: " & r + Exit Sub + +ErrorHandler: + r = -1 +' TestLog_Comment "The next compute raises error: " & testCompute + Resume Next +End Sub + + + +Sub test2() + Dim s As String + Dim d As Double + s = "" + d = s ' fail in MSO + MsgBox d +End Sub + +Sub testBolean() + Dim a As String + Dim b As Boolean + Dim c As Boolean + Dim d As String + + b = True + + a = "1" + c = a + b ' c = false + MsgBox c + + d = a + b 'd = 0 + MsgBox d +End Sub + +Sub testCurrency() + Dim a As String + Dim b As Currency + Dim c As Currency + Dim d As String + + a = "10" + b = 30.3 + + c = a + b ' c = 40.3 + MsgBox c + + d = a + b ' c =40.3 + MsgBox d + +End Sub + +Sub TestLog_ASSERT(assertion As Boolean, Optional testId As String, Optional testComment As String) + + If assertion = True Then + passCount = passCount + 1 + Else + Dim testMsg As String + If Not IsMissing(testId) Then + testMsg = testMsg + " : " + testId + End If + If Not IsMissing(testComment) And Not (testComment = "") Then + testMsg = testMsg + " (" + testComment + ")" + End If + + result = result & Chr$(10) & " Failed: " & testMsg + failCount = failCount + 1 + End If + +End Sub |