Skip to content

Instantly share code, notes, and snippets.

@saga
Created April 9, 2013 15:56
Show Gist options
  • Save saga/5346904 to your computer and use it in GitHub Desktop.
Save saga/5346904 to your computer and use it in GitHub Desktop.
Get a test object with name and path
Public Function GetTest(ByVal TestName As String, _
ByVal SubjectPath As String, _
Optional delimChar As String = "\") _
As TDAPIOLELib.Test
'This function gets a test name and path and
'returns a test object.
Dim TestFact As TestFactory, testList As List
Dim TestFilter As TDFilter
On Error GoTo GetTestErr
'--------------------------------------
' Check arguments.
If (Len(SubjectPath) = 0) _
Or (Len(TestName) = 0) Then
Set GetTest = Nothing
Exit Function
End If
'--------------------------------------
' Trim the SubjectPath, stripping leading and trailing delimiters.
SubjectPath = Trim(SubjectPath)
Dim pos%, ln%
pos = InStr(1, SubjectPath, delimChar)
If pos = 1 Then
SubjectPath = Mid(SubjectPath, 2)
End If
ln = Len(SubjectPath)
pos = InStr(ln - 1, SubjectPath, delimChar)
If pos > 0 Then
SubjectPath = Mid(SubjectPath, 1, ln - 1)
End If
'--------------------------------------
' Path must start with "Subject."
pos = InStr(SubjectPath, "Subject")
If pos <> 1 Then
SubjectPath = "Subject\" & SubjectPath
End If
'--------------------------------------
' Get a TestFactory.Filter and define it.
'tdc is the global TDConnection object.
Set TestFact = tdc.TestFactory
Set TestFilter = TestFact.Filter
' The test name
TestFilter.Filter("TS_NAME") = Trim(TestName)
' The test subject node
TestFilter.Filter("TS_SUBJECT") = SubjectPath
' Debug.Print TestFilter.Text
'--------------------------------------
' Get the test object.
' The filter defines a unique test, so we
' expect only one test in the list.
Set TestFact = tdc.TestFactory
Set testList = TestFact.NewList(TestFilter.Text)
If testList.Count = 0 Then
Set GetTest = Nothing
Else
Set GetTest = testList.Item(1)
End If
Exit Function
GetTestErr:
On Error Resume Next
Set GetTest = Nothing
ErrHandler err, "GetTest", "Failed to get " & TestName
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment