Concept-Blocks/src/s_DataAccess.cls

156 lines
5.6 KiB
OpenEdge ABL
Raw Normal View History

2024-06-07 20:02:35 +03:00
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "s_DataAccess"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private page_ As Visio.Page
Public Function Setup()
' Mandatory setup function
Set page_ = ThisDocument.Application.ActivePage
End Function
Public Function Teardown()
' Mandatory teardown function
Call ClearAll
End Function
Public Function t_Enumerator()
On Error GoTo PROPAGATE_ERROR
Call Dev_NewCase("Empty string")
Call Dev_ExpectEQ("", TrimEnumerator(""))
Call Dev_ExpectEQ(0, ExtractEnumerator(""))
Call Dev_NewCase("Invalid enumerated")
Call Dev_ExpectEQ("1.1 Test", TrimEnumerator("1.1 Test"))
Call Dev_ExpectEQ(0, ExtractEnumerator("1.1 Test"))
Call Dev_ExpectEQ("1.1. Test", TrimEnumerator("1.1. Test"))
Call Dev_ExpectEQ(0, ExtractEnumerator("1.1. Test"))
Call Dev_NewCase("Valid enumerated")
Call Dev_ExpectEQ("Test1", TrimEnumerator("<22><>1 Test1"))
Call Dev_ExpectEQ(1, ExtractEnumerator("<22><>1 Test1"))
Call Dev_ExpectEQ("Test2", TrimEnumerator("!<21><>2 Test2"))
Call Dev_ExpectEQ(2, ExtractEnumerator("!<21><>2 Test2"))
Call Dev_ExpectEQ("Test3", TrimEnumerator("??? Test3"))
Call Dev_ExpectEQ(0, ExtractEnumerator("??? Test3"))
Call Dev_NewCase("Extract appended")
Dim sText$: sText = AppendEnumerator("Test", 1337)
Call Dev_ExpectEQ("Test", TrimEnumerator(sText))
Call Dev_ExpectEQ(1337, ExtractEnumerator(sText))
Exit Function
PROPAGATE_ERROR:
Call Dev_LogError(Err.Number, Err.Description)
End Function
Public Function t_ExtractGraphNodes()
On Error GoTo PROPAGATE_ERROR
Call Dev_ExpectEQ(0, ExtractGraphNodes(page_).Count, "Empty page")
Call Dev_NewCase("Invalid shapes")
Call page_.DrawLine(0, 0, 1, 1)
Call page_.DrawRectangle(2, 2, 3, 3)
Call page_.Drop(FindMaster(ThisDocument, MASTER_ELEMENT), 10, 10)
Call page_.Drop(FindMaster(ThisDocument, MASTER_IDENTIFICATION), 15, 15)
Call Dev_ExpectEQ(0, ExtractGraphNodes(page_).Count)
Call Dev_NewCase("Valid schemas")
Dim ks1 As Visio.Shape: Set ks1 = page_.Drop(FindMaster(ThisDocument, MASTER_SCHEMA), 20, 20)
ks1.Text = "Test1"
Dim ks2 As Visio.Shape: Set ks2 = page_.Drop(FindMaster(ThisDocument, MASTER_SCHEMA), 25, 25)
ks2.Text = "Test2"
Dim iOperation As Visio.Shape: Set iOperation = page_.Drop(FindMaster(ThisDocument, MASTER_OPERATION), 30, 30)
Dim iProxy As Visio.Shape: Set iProxy = page_.Drop(FindMaster(ThisDocument, MASTER_PROXY), 35, 35)
iProxy.Text = ks1.Text
Dim iBlock As Visio.Shape: Set iBlock = page_.Drop(FindMaster(ThisDocument, MASTER_BLOCK), 40, 40)
Dim iNodes As Collection: Set iNodes = CColl(ks1, ks2, iOperation, iProxy)
Call Dev_ExpectEQ(iNodes, ExtractGraphNodes(page_))
Call Dev_NewCase("Contained shapes")
Call iBlock.ContainerProperties.AddMember(ks2, visMemberAddExpandContainer)
Call Dev_ExpectEQ(iNodes, ExtractGraphNodes(page_))
Exit Function
PROPAGATE_ERROR:
Call Dev_LogError(Err.Number, Err.Description)
End Function
Public Function t_ExtractRepresentatives()
On Error GoTo PROPAGATE_ERROR
Call Dev_ExpectEQ(0, ExtractRepresentatives(page_).Count, "Empty page")
Call Dev_NewCase("Literal representatives")
Dim iSchema As Visio.Shape: Set iSchema = page_.Drop(FindMaster(ThisDocument, MASTER_SCHEMA), 20, 20)
iSchema.Text = "Test"
Dim iProxy As Visio.Shape: Set iProxy = page_.Drop(FindMaster(ThisDocument, MASTER_PROXY), 35, 35)
iProxy.Text = "Test"
Dim iReps As New Scripting.Dictionary
iReps(iProxy.ID) = iSchema.ID
Call Dev_ExpectEQ(iReps, ExtractRepresentatives(page_))
Call Dev_NewCase("Invalid enumerated representatives")
iSchema.Text = "<22><>2 Test"
iProxy.Text = "<22><>1 Test"
Call Dev_ExpectEQ(iReps, ExtractRepresentatives(page_))
Call Dev_NewCase("Unrelated proxy")
iSchema.Text = "<22><>1 Test"
iProxy.Text = "<22><>1 Test1337"
Call Dev_ExpectEQ(0, ExtractRepresentatives(page_).Count)
Call Dev_NewCase("Duplicate schema")
Dim iDuplicate As Visio.Shape: Set iDuplicate = page_.Drop(FindMaster(ThisDocument, MASTER_SCHEMA), 30, 30)
iDuplicate.Text = iSchema.Text
Call Dev_ExpectEQ(0, ExtractRepresentatives(page_).Count)
Exit Function
PROPAGATE_ERROR:
Call Dev_LogError(Err.Number, Err.Description)
End Function
Public Function t_ExtractPowerLevels()
On Error GoTo PROPAGATE_ERROR
Call Dev_ExpectEQ(0, ExtractPowerLevels(page_).Count, "Empty page")
Call Dev_NewCase("Unlinked nodes")
Dim ks1 As Visio.Shape: Set ks1 = page_.Drop(FindMaster(ThisDocument, MASTER_SCHEMA), 30, 30)
Dim ks2 As Visio.Shape: Set ks2 = page_.Drop(FindMaster(ThisDocument, MASTER_SCHEMA), 25, 25)
Dim ks3 As Visio.Shape: Set ks3 = page_.Drop(FindMaster(ThisDocument, MASTER_SCHEMA), 20, 20)
Dim ks4 As Visio.Shape: Set ks4 = page_.Drop(FindMaster(ThisDocument, MASTER_SCHEMA), 35, 35)
Dim iOperation As Visio.Shape: Set iOperation = page_.Drop(FindMaster(ThisDocument, MASTER_OPERATION), 15, 15)
Dim iLevels As New Scripting.Dictionary
iLevels(ks1.ID) = 1
iLevels(ks2.ID) = 1
iLevels(ks3.ID) = 1
iLevels(ks4.ID) = 1
iLevels(iOperation.ID) = 1
Call Dev_ExpectEQ(iLevels, ExtractPowerLevels(page_))
Call Dev_NewCase("Valid graph")
Call ks1.AutoConnect(iOperation, visAutoConnectDirNone)
Call ks2.AutoConnect(iOperation, visAutoConnectDirNone)
Call iOperation.AutoConnect(ks3, visAutoConnectDirNone)
Call ks3.AutoConnect(ks4, visAutoConnectDirNone)
Call ks1.AutoConnect(ks4, visAutoConnectDirNone)
iLevels(ks3.ID) = 2
iLevels(ks4.ID) = 3
iLevels(iOperation.ID) = 2
Call Dev_ExpectEQ(iLevels, ExtractPowerLevels(page_))
Exit Function
PROPAGATE_ERROR:
Call Dev_LogError(Err.Number, Err.Description)
End Function