Skip to content

Commit

Permalink
added support for testing user-defined types for equality.
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyethridge committed Jul 20, 2019
1 parent 264bcca commit 022881b
Show file tree
Hide file tree
Showing 19 changed files with 340 additions and 210 deletions.
Binary file modified Binaries/Compiled/SimplyVBUnit.Component.ocx
Binary file not shown.
Binary file modified Binaries/Compiled/SimplyVBUnit.Component.pdb
Binary file not shown.
Binary file modified Binaries/Compiled/SimplyVBUnit.Framework.dll
Binary file not shown.
Binary file modified Binaries/Compiled/SimplyVBUnit.Framework.pdb
Binary file not shown.
6 changes: 3 additions & 3 deletions Install/InstallScript.iss
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{249D663E-A119-4D35-A0F4-15821B9416E5}
AppName=SimplyVBUnit 5.0.2
AppVerName=SimplyVBUnit 5.0.2
AppName=SimplyVBUnit 5.0.3
AppVerName=SimplyVBUnit 5.0.3
AppPublisher=Kelly Ethridge
AppPublisherURL=https://sourceforge.net/projects/simplyvbunit/
AppSupportURL=https://sourceforge.net/projects/simplyvbunit/
Expand All @@ -16,7 +16,7 @@ DefaultDirName={pf}\SimplyVBUnit 5.0
DefaultGroupName=SimplyVBUnit 5.0
AllowNoIcons=yes
OutputDir=.
OutputBaseFilename=SimplyVBUnitSetup-5.0.2
OutputBaseFilename=SimplyVBUnitSetup-5.0.3
Compression=lzma
SolidCompression=yes

Expand Down
3 changes: 3 additions & 0 deletions Install/readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
** SimplyVBUnit **

version 5.0.3
* Added equality support for userdefined types.

version 5.0.1
* Asserting against a compiled object that is private is incorrectly handled.
* Added "Errors" panel to status bar in UI.
Expand Down
24 changes: 24 additions & 0 deletions Source/Fakes/FakeTypes.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "FakeTypes"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Public Type FakeStructure
Value1 As Long
Value2 As String
End Type

Public Function NewFakeStructure(ByVal Value1 As Long, ByVal Value2 As String) As FakeStructure
NewFakeStructure.Value1 = Value1
NewFakeStructure.Value2 = Value2
End Function
62 changes: 54 additions & 8 deletions Source/Framework/EqualityComparer.cls
Original file line number Diff line number Diff line change
Expand Up @@ -208,28 +208,24 @@ Private Function EqualValues(ByRef X As Variant, ByRef Y As Variant) As Boolean
Select Case VarType(X)
Case vbString
Result = EqualStrings(X, Y)

Case vbLong, vbInteger, vbByte, vbDouble, vbSingle, vbCurrency, vbDecimal
Result = EqualNumbers(X, Y)

Case vbObject, vbDataObject
Result = EqualObjects(X, Y)

Case vbBoolean
Result = EqualBooleans(X, Y)

Case vbDate
Result = EqualDates(X, Y)

Case vbUserDefinedType
If VarType(Y) = vbUserDefinedType Then
Result = EqualUdt(X, Y)
End If
Case vbEmpty
Result = IsEmpty(Y)

Case vbNull
Result = IsNull(Y)

Case vbError
Result = (IsMissing(X) And IsMissing(Y))

End Select
End If

Expand Down Expand Up @@ -308,6 +304,56 @@ Private Function EqualDates(ByRef X As Variant, ByRef Y As Variant) As Boolean
End If
End Function

Private Function EqualUdt(ByRef ObjA As Variant, ByRef ObjB As Variant) As Boolean
Const VARIANTRECORD_OFFSET As Long = 12
Const VARIANTDATA_OFFSET As Long = 8
Dim ObjARecord As IRecordInfo
Dim ObjBRecord As IRecordInfo

ObjectPtr(ObjARecord) = MemLong(VarPtr(ObjA) + VARIANTRECORD_OFFSET)
ObjectPtr(ObjBRecord) = MemLong(VarPtr(ObjB) + VARIANTRECORD_OFFSET)

On Error GoTo Catch

If ObjARecord.IsMatchingType(ObjBRecord) Then
Dim FieldNameCount As Long

ObjARecord.GetFieldNames FieldNameCount, ByVal vbNullPtr

If FieldNameCount > 0 Then
Dim FieldNames() As String
Dim ObjAPtr As Long
Dim ObjBPtr As Long

ReDim FieldNames(0 To FieldNameCount - 1)
ObjARecord.GetFieldNames FieldNameCount, FieldNames(0)
ObjAPtr = MemLong(VarPtr(ObjA) + VARIANTDATA_OFFSET)
ObjBPtr = MemLong(VarPtr(ObjB) + VARIANTDATA_OFFSET)

Dim i As Long
For i = 0 To FieldNameCount - 1
If Not Equals(ObjARecord.GetField(ObjAPtr, FieldNames(i)), ObjARecord.GetField(ObjBPtr, FieldNames(i))) Then
GoSub Finally
Exit Function
End If
Next
End If

EqualUdt = True
End If

GoSub Finally
Exit Function

Catch:
GoSub Finally
Err.Raise Err.Number, Err.Source, Err.Description
Finally:
ObjectPtr(ObjARecord) = vbNullPtr
ObjectPtr(ObjBRecord) = vbNullPtr
Return
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Class Events
Expand Down
2 changes: 1 addition & 1 deletion Source/SimplyVBUnit.Component.Tests.vbp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\Windows\SysWOW64\stdole2.tlb#OLE Automation
Reference=*\G{F5078F18-C551-11D3-89B9-0000F81FE221}#6.0#0#..\..\..\..\..\..\Windows\SysWOW64\msxml6.dll#Microsoft XML, v6.0
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; MSCOMCTL.OCX
Object={7983BD3B-752A-43EA-9BFF-444BBA1FC293}#5.0#0; SimplyVBUnit.Component.ocx
Module=modMain; ComponentTests\modMain.bas
Class=TestTreeViewController; ComponentTests\TestTreeViewController.cls
Form=ComponentTests\frmTreeView.frm
Expand All @@ -18,7 +19,6 @@ Class=FakeFixture; ComponentTests\FakeFixture.cls
Class=TreeNodePathConstraint; ComponentTests\TreeNodePathConstraint.cls
Class=DebugListener; ComponentTests\DebugListener.cls
Class=TestConfiguration; ComponentTests\TestConfiguration.cls
Object={7983BD3B-752A-43EA-9BFF-444BBA1FC293}#5.0#0; SimplyVBUnit.Component.ocx
Startup="frmSample"
HelpFile=""
Command32=""
Expand Down
6 changes: 3 additions & 3 deletions Source/SimplyVBUnit.Component.vbp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Type=Control
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\Windows\SysWOW64\stdole2.tlb#OLE Automation
Reference=*\G{3F4DACA7-160D-11D2-A8E9-00104B365C9F}#5.5#0#..\..\..\..\..\..\Windows\SysWOW64\vbscript.dll\3#Microsoft VBScript Regular Expressions 5.5
Reference=*\G{F5078F18-C551-11D3-89B9-0000F81FE221}#6.0#0#..\..\..\..\..\..\Windows\SysWOW64\msxml6.dll#Microsoft XML, v6.0
Reference=*\G{923925AC-1013-4D27-9FB1-4FF0B3B47BA2}#4.0#0#..\..\..\..\..\..\WINDOWS\SysWow64\SimplyVBUnitType.tlb#SimplyVBUnit Type Library 4.0
Reference=*\G{8B217740-717D-11CE-AB5B-D41203C10000}#1.0#0#..\..\..\..\..\..\Windows\SysWow64\TLBINF32.DLL#TypeLib Information
Reference=*\G{3E4F7CEC-C640-49F1-80D9-8DD42421CB1B}#5.0#0#..\TypeLibrary\SimplyVBUnitType.tlb#SimplyVBUnit 5.0 Type Library
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; MSCOMCTL.OCX
Class=Anchor; Component\Anchor.cls
Class=ClientInfo; Component\AppInfo.cls
Expand Down Expand Up @@ -169,13 +169,13 @@ Path32="..\Binaries\Compiled"
Command32=""
Name="SimplyVBComp"
HelpContextID="0"
Description="SimplyVBUnit Component 5.0.2"
Description="SimplyVBUnit Component 5.0.3"
CompatibleMode="2"
CompatibleEXE32="..\Binaries\Compatibility\SimplyVBUnit.Component.cmp"
VersionCompatible32="1"
MajorVer=5
MinorVer=0
RevisionVer=2
RevisionVer=3
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Home"
Expand Down
5 changes: 3 additions & 2 deletions Source/SimplyVBUnit.Fakes.vbp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type=OleDll
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\Windows\SysWOW64\stdole2.tlb#OLE Automation
Reference=*\G{923925AC-1013-4D27-9FB1-4FF0B3B47BA2}#4.0#0#..\..\..\..\..\..\WINDOWS\SysWow64\SimplyVBUnitType.tlb#SimplyVBUnit 4.0 Type Library
Reference=*\G{23B6C3E6-2268-4527-B37A-F79C7DE37DA4}#5.0#0#..\Binaries\Compiled\SimplyVBUnit.Framework.dll#SimplyVBUnit Framework 5.0.2
Reference=*\G{23B6C3E6-2268-4527-B37A-F79C7DE37DA4}#5.0#0#..\Binaries\Compiled\SimplyVBUnit.Framework.dll#SimplyVBUnit Framework 5.0.3
Reference=*\G{3E4F7CEC-C640-49F1-80D9-8DD42421CB1B}#5.0#0#..\TypeLibrary\SimplyVBUnitType.tlb#SimplyVBUnit 5.0 Type Library
Class=FakeEmpty; Fakes\FakeEmpty.cls
Class=Fake1Test; Fakes\Fake1Test.cls
Class=Mock1Test; Fakes\Mock1Test.cls
Expand Down Expand Up @@ -51,6 +51,7 @@ Class=MockITestFixture; Fakes\MockITestFixture.cls
Class=FakeCategorizedTests; Fakes\FakeCategorizedTests.cls
Class=ClassEventMonitor; Fakes\ClassEventMonitor.cls
Class=FakeWithNonDiplayableArgs; Fakes\FakeWithNonDiplayableArgs.cls
Class=FakeTypes; Fakes\FakeTypes.cls
Startup="(None)"
HelpFile=""
Command32=""
Expand Down
4 changes: 2 additions & 2 deletions Source/SimplyVBUnit.Framework.Tests.vbp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\Windows\SysWOW64\stdole2.tlb#OLE Automation
Reference=*\ASimplyVBUnit.Fakes.vbp
Reference=*\G{8B217740-717D-11CE-AB5B-D41203C10000}#1.0#0#..\..\..\..\..\..\Windows\SysWow64\TLBINF32.DLL#TypeLib Information
Reference=*\G{923925AC-1013-4D27-9FB1-4FF0B3B47BA2}#4.0#0#..\..\..\..\..\..\WINDOWS\SysWow64\SimplyVBUnitType.tlb#SimplyVBUnit 4.0 Type Library
Reference=*\G{23B6C3E6-2268-4527-B37A-F79C7DE37DA4}#5.0#0#..\Binaries\Compiled\SimplyVBUnit.Framework.dll#SimplyVBUnit Framework 5.0.2
Reference=*\G{23B6C3E6-2268-4527-B37A-F79C7DE37DA4}#5.0#0#..\Binaries\Compiled\SimplyVBUnit.Framework.dll#SimplyVBUnit Framework 5.0.3
Reference=*\G{3E4F7CEC-C640-49F1-80D9-8DD42421CB1B}#5.0#0#..\TypeLibrary\SimplyVBUnitType.tlb#SimplyVBUnit 5.0 Type Library
Module=modMain; Tests\modMain.bas
Class=BootstrapTestFixtureTests; Tests\BootstrapTestFixtureTests.cls
Class=BootstrapMockOneSubTestClassTests; Tests\BootstrapMockOneSubTestClassTests.cls
Expand Down
6 changes: 3 additions & 3 deletions Source/SimplyVBUnit.Framework.vbp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type=OleDll
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\..\..\Windows\SysWOW64\stdole2.tlb#OLE Automation
Reference=*\G{8B217740-717D-11CE-AB5B-D41203C10000}#1.0#0#..\..\..\..\..\..\Windows\SysWow64\TLBINF32.DLL#TypeLib Information
Reference=*\G{923925AC-1013-4D27-9FB1-4FF0B3B47BA2}#4.0#0#..\..\..\..\..\..\WINDOWS\SysWow64\SimplyVBUnitType.tlb#SimplyVBUnit 4.0 Type Library
Reference=*\G{3F4DACA7-160D-11D2-A8E9-00104B365C9F}#5.5#0#..\..\..\..\..\..\Windows\SysWOW64\vbscript.dll\3#Microsoft VBScript Regular Expressions 5.5
Reference=*\G{3E4F7CEC-C640-49F1-80D9-8DD42421CB1B}#5.0#0#..\TypeLibrary\SimplyVBUnitType.tlb#SimplyVBUnit 5.0 Type Library
Class=TestFixture; Framework\TestFixture.cls
Class=SimConstructors; Framework\SimConstructors.cls
Class=SimStatics; Framework\SimStatics.cls
Expand Down Expand Up @@ -145,13 +145,13 @@ Path32="..\Binaries\Compiled"
Command32=""
Name="SimplyVBUnit"
HelpContextID="0"
Description="SimplyVBUnit Framework 5.0.2"
Description="SimplyVBUnit Framework 5.0.3"
CompatibleMode="2"
CompatibleEXE32="..\Binaries\Compatibility\SimplyVBUnit.Framework.cmp"
VersionCompatible32="1"
MajorVer=5
MinorVer=0
RevisionVer=2
RevisionVer=3
AutoIncrementVer=0
ServerSupportFiles=0
DllBaseAddress=&H53000000
Expand Down
3 changes: 3 additions & 0 deletions Source/Tests/BootstrapEqualityComparerTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ Public Function Run() As Long
ReDim Long2(0 To 1, 0 To 1, 0 To 1)
RunTest Equals_WithDefaultSettings_ReturnsExpected(Long1, Long2, False)
RunTest Equals_WithDefaultSettings_ReturnsExpected(Long2, Long2, True)
RunTest Equals_WithDefaultSettings_ReturnsExpected(NewFakeStructure(1, "hi"), NewFakeStructure(2, "hi"), False)
RunTest Equals_WithDefaultSettings_ReturnsExpected(NewFakeStructure(1, "hi"), NewFakeStructure(1, "bye"), False)
RunTest Equals_WithDefaultSettings_ReturnsExpected(NewFakeStructure(1, "hi"), NewFakeStructure(1, "hi"), True)

RunTest Equals_WithStrictSettings_ReturnsExpected(0, 0, True)
RunTest Equals_WithStrictSettings_ReturnsExpected(0&, 0, False)
Expand Down
3 changes: 0 additions & 3 deletions Source/Tests/EqualConstraintTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ Public Sub Resolve_WhenCalled_ReturnsSelf()
Assert.IsTrue Actual Is c
End Sub




Private Function MakeMissing(Optional ByVal Value As Variant) As Variant
MakeMissing = Value
End Function
Expand Down
3 changes: 1 addition & 2 deletions Source/Tests/TestCaseTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,9 @@ Public Sub Run_WithUnknownErrorTest_ReturnsErrorTestResult2()

Dim Actual As String
Actual = Result.Message
Assert.IsTrue Actual = "unknown error", "Wrong error message."
Assert.IsTrue Actual = "1, unknown error", "Wrong error message. was '" & Actual & "'"
End Sub


Public Sub Run_WithSetupDefined_RunsSetup()
Dim TestClass As New Mock2TestsWithSetup
Dim Fixture As TestFixture
Expand Down
2 changes: 1 addition & 1 deletion TypeLibrary/BuildSimplyVBUnitType.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
echo off
mktyplib /tlb SimplyVBUnitType.tlb SimplyVBUnitType.odl
mktyplib /nocpp /tlb SimplyVBUnitType.tlb SimplyVBUnitType.odl
if not errorlevel 1 goto end
pause
:end
Expand Down
Loading

0 comments on commit 022881b

Please sign in to comment.