Custom Test Types Interfaces

Script Viewer Example

' The following is an example of the script viewer control
' that allows you to view the test.
' Using Microsoft Visual Basic, create a new ActiveX Control project.
' Choose Project > References, and select the OTA COM 8.0 Type Library reference.
' For this example, you must also select a reference to the
' Microsoft Scripting Runtime, though you may not need it for your production code.
' Add a text box to the user control. The script contents are displayed inside the box.
' Add a Command button named cmdSave. The button is used to save changes to the script.

Private td As New TDAPIOLELib.TDConnection
Private tfact As TDAPIOLELib.TestFactory
Private theTest As TDAPIOLELib.Test
Private LocalScriptPath As String
Private ExtStorage As TDAPIOLELib.ExtendedStorage

'
'*******************************************************************
Public Sub Init(mytd As Variant)
' Initialization method, Quality Center will call this
' method and pass an TDConnection class object.
Set td = mytd

End Sub

Public Sub ShowTest(TestKey As Long)
' ShowTest(TestKey As Long) always displays the most recent
' checked-in version of the test.
' From Quality Center version 10.0 and later, Quality Center
' calls ShowTestEx if it is implemented.

' This implementation of ShowTest gets the path for the specified test
' using its key, reads the script file (Batch.bat) from this location,
' and displays it in the text box.
'
Dim mydata As String
Const ForReading=1

On Error GoTo ShowTestErr

'Get the test
Set tfact = td.TestFactory
Set theTest = tfact.Item(TestKey)

'Get a local copy of the script
'In this example, the script is "batch.bat"
Set ExtStorage = theTest.ExtendedStorage
    LocalScriptPath = ExtStorage.Load("-r batch.bat", True)

'Add the file name to the path returned from Load
'so it directly refers to the file.
    LocalScriptPath = LocalScriptPath & "\batch.bat"

'Open the script
Set oFileSys = _
        CreateObject("Scripting.FileSystemObject")
Set ScriptFile = _
        oFileSys.OpenTextFile(LocalScriptPath, _
            ForReading, False)

'Get the contents of the file into a string variable
If Not ScriptFile.AtEndOfStream Then _
        mydata = ScriptFile.ReadLine
Do While ScriptFile.AtEndOfStream <> True
'List1.AddItem ScriptFile.ReadLine
         mydata = mydata & vbCrLf & ScriptFile.ReadLine
Loop
    ScriptFile.Close

' Load the script text into the text box.
' Note that the text box must have the Multi-line
' attribute enabled.
    Text1.Text = mydata
    Text1.Enabled = False

Exit Sub
ShowTestErr:
On Error Resume Next
Dim msg$
    msg = " on " & theTest.name
    msg = "ShowTest error" & msg & vbCrLf
    msg = msg & Err.Description
    MsgBox msg
End Sub

Public Sub ShowTestEx(theTest As TDAPIOLELib.Test)
' Quality Center will call the ShowTestEx method and pass
' a reference to the test object. The appropriate version
' of the test is displayed.

' This implementation of ShowTestEx gets the path for the specified test
' using its key,reads the script file (Batch.bat) from this location,
' and displays it in the text box.
'
Dim mydata As String

On Error GoTo ShowTestErr

'Get a local copy of the script
'In this example, the script is "batch.bat"
Set ExtStorage = theTest.ExtendedStorage
    LocalScriptPath = ExtStorage.Load("-r batch.bat", True)

'Add the file name to the path returned from Load
'so it directly refers to the file.
    LocalScriptPath = LocalScriptPath & "\batch.bat"

'Open the script
Set oFileSys = _
        CreateObject("Scripting.FileSystemObject")
Set ScriptFile = _
        oFileSys.OpenTextFile(LocalScriptPath, _
            ForReading, False)

'Get the contents of the file into a string variable
If Not ScriptFile.AtEndOfStream Then _
        mydata = ScriptFile.ReadLine
Do While ScriptFile.AtEndOfStream <> True
'List1.AddItem ScriptFile.ReadLine
         mydata = mydata & vbCrLf & ScriptFile.ReadLine
Loop
    ScriptFile.Close

' Load the script text into the text box.
' Note that the text box must have the Multi-line
' attribute enabled.
    Text1.Text = mydata
    Text1.Enabled = False

Exit Sub
ShowTestErr:
On Error Resume Next
Dim msg$
    msg = " on " & theTest.name
    msg = "ShowTest error" & msg & vbCrLf
    msg = msg & Err.Description
    MsgBox msg
End Sub


© 1992 - 2012 Hewlett-Packard Development Company, L.P.