Kaydet (Commit) 76c31848 authored tarafından Noel Power's avatar Noel Power

Add some stand alone vba specific tests ( mostly vba only functions )

Change-Id: I137e93a8af67b7eec4c51348caf3d0d03dbbce73
üst 40e0b5e4
#
# 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/.
#
$(eval $(call gb_CppunitTest_CppunitTest,basic_vba))
$(eval $(call gb_CppunitTest_use_external,basic_vba,boost_headers))
$(eval $(call gb_CppunitTest_add_exception_objects,basic_vba, \
basic/qa/cppunit/test_vba \
))
#$(eval $(call gb_CppunitTest_use_library_objects,basic_vba,sb))
# add a list of all needed libraries here
$(eval $(call gb_CppunitTest_use_libraries,basic_vba, \
comphelper \
cppu \
cppuhelper \
i18nisolang1 \
sal \
salhelper \
sb \
sot \
svl \
svt \
test \
tl \
unotest \
utl \
vcl \
xmlscript \
$(gb_UWINAPI) \
))
ifeq ($(OS),WNT)
$(eval $(call gb_CppunitTest_use_system_win32_libs,basic_vba, \
oleaut32 \
))
endif
$(eval $(call gb_CppunitTest_set_include,basic_vba,\
-I$(SRCDIR)/basic/source/inc \
-I$(SRCDIR)/basic/inc \
$$(INCLUDE) \
))
$(eval $(call gb_CppunitTest_use_api,basic_vba,\
offapi \
udkapi \
oovbaapi \
))
$(eval $(call gb_CppunitTest_use_ure,basic_vba))
$(eval $(call gb_CppunitTest_use_components,basic_vba,\
configmgr/source/configmgr \
i18npool/util/i18npool \
))
$(eval $(call gb_CppunitTest_use_configuration,basic_vba))
...@@ -20,6 +20,7 @@ $(eval $(call gb_Module_add_check_targets,basic,\ ...@@ -20,6 +20,7 @@ $(eval $(call gb_Module_add_check_targets,basic,\
CppunitTest_basic_enable \ CppunitTest_basic_enable \
CppunitTest_basic_nested_struct \ CppunitTest_basic_nested_struct \
CppunitTest_basic_coverage \ CppunitTest_basic_coverage \
CppunitTest_basic_vba \
)) ))
endif endif
......
/* -*- 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"
};
OUString sMacroPathURL = getURLFromSrc("/basic/qa/vba_tests/");
// Some test data expects the uk locale
AllSettings aSettings = Application::GetSettings();
aSettings.SetLanguageTag( LanguageTag( LANGUAGE_ENGLISH_UK ) );
Application::SetSettings( aSettings );
for ( sal_uInt32 i=0; i<SAL_N_ELEMENTS( macroSource ); ++i )
{
OUString sMacroURL( sMacroPathURL );
sMacroURL += 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", 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: */
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
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
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
This diff is collapsed.
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
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
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
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment