LANG="VBScript" REM *** Global vars DIM ServerProgID DIM CountFail DIM CountWarning DIM CountTotal DIM xmlString DIM xmlDoc DIM root REM ************************************** REM ************************************** Sub Main DIM ServerID DIM GroupID DIM ItemID OPC.DisconnectAllServers OPC.Wait 2000 OPC.StopExecutionOnFail FALSE OPC.StopExecutionOnWarning FALSE OPC.EnableLogicalOnStartup FALSE ServerProgID = "OPCSample.OpcDaServer.1" ServerID = OPC.ConnectServer(ServerProgID, FALSE, "ALL", "") if ServerID=0 then Exit Sub OPC.SetupDATestCases ServerID OPC.DisableInterface ServerID, "IOPCSecurityNT" OPC.DisableInterface ServerID, "IOPCSecurityPrivate" GroupID = OPC.AddGroup(ServerID, "Group_PCPA1", TRUE, 1000, 2) ItemID = OPC.AddItem( GroupID, "Analog Types/Double", "") ItemID = OPC.AddItem( GroupID, "Analog Types/Int", "") ItemID = OPC.AddItem( GroupID, "Enumerated Types/Fellowship", "") ItemID = OPC.AddItem( GroupID, "Limited Access/Read Only 1", "") ItemID = OPC.AddItem( GroupID, "Limited Access/Write Only 1", "") ItemID = OPC.AddItem( GroupID, "Simple Types/Float", "") ItemID = OPC.AddItem( GroupID, "Simple Types/Int", "") GroupID = OPC.AddGroup(ServerID, "Group_PCPA2", TRUE, 1000, 2) ItemID = OPC.AddItem( GroupID, "Analog Types/Double", "") ItemID = OPC.AddItem( GroupID, "Analog Types/Int", "") ItemID = OPC.AddItem( GroupID, "Enumerated Types/Fellowship", "") ItemID = OPC.AddItem( GroupID, "Limited Access/Read Only 1", "") ItemID = OPC.AddItem( GroupID, "Limited Access/Write Only 1", "") ItemID = OPC.AddItem( GroupID, "Simple Types/Float", "") ItemID = OPC.AddItem( GroupID, "Simple Types/Int", "") GroupID = OPC.AddGroup(ServerID, "Group_PCPI", FALSE, 1000, 2) ItemID = OPC.AddItem( GroupID, "Analog Types/Double", "") ItemID = OPC.AddItem( GroupID, "Analog Types/Int", "") ItemID = OPC.AddItem( GroupID, "Enumerated Types/Fellowship", "") ItemID = OPC.AddItem( GroupID, "Limited Access/Read Only 1", "") ItemID = OPC.AddItem( GroupID, "Limited Access/Write Only 1", "") ItemID = OPC.AddItem( GroupID, "Simple Types/Float", "") ItemID = OPC.AddItem( GroupID, "Simple Types/Int", "") GroupID = OPC.AddGroup(ServerID, "Group_PNCA", TRUE, 1000, -1) ItemID = OPC.AddItem( GroupID, "Analog Types/Double", "") ItemID = OPC.AddItem( GroupID, "Analog Types/Int", "") ItemID = OPC.AddItem( GroupID, "Enumerated Types/Fellowship", "") ItemID = OPC.AddItem( GroupID, "Limited Access/Read Only 1", "") ItemID = OPC.AddItem( GroupID, "Limited Access/Write Only 1", "") ItemID = OPC.AddItem( GroupID, "Simple Types/Float", "") ItemID = OPC.AddItem( GroupID, "Simple Types/Int", "") GroupID = OPC.AddGroup(ServerID, "Group_PNCI", FALSE, 1000, -1) ItemID = OPC.AddItem( GroupID, "Analog Types/Double", "") ItemID = OPC.AddItem( GroupID, "Analog Types/Int", "") ItemID = OPC.AddItem( GroupID, "Enumerated Types/Fellowship", "") ItemID = OPC.AddItem( GroupID, "Limited Access/Read Only 1", "") ItemID = OPC.AddItem( GroupID, "Limited Access/Write Only 1", "") ItemID = OPC.AddItem( GroupID, "Simple Types/Float", "") ItemID = OPC.AddItem( GroupID, "Simple Types/Int", "") REM *** REM create xml object, header, and root call CreateXMLdoc() REM *** REM Init counting variables CountFail = 0 CountWarning = 0 CountTotal = 0 REM *** Testing IOPCCommon interface REM *** REM Test SetLocaleID TCN = "2.1.1.2" call ExecTestCase( ServerID, TCN ) TCN = "2.1.1.6" call ExecTestCase( ServerID, TCN ) TCN = "2.1.1.241" call ExecTestCase( ServerID, TCN ) REM *** REM Test GetLocaleID TCN = "2.1.2.3" call ExecTestCase( ServerID, TCN ) REM *** REM Test QueryAvailableLocaleIDs TCN = "2.1.3.1" call ExecTestCase( ServerID, TCN ) REM *** REM Test GetErrorString TCN = "2.1.4.1" call ExecTestCase( ServerID, TCN ) TCN = "2.1.4.4" call ExecTestCase( ServerID, TCN ) TCN = "2.1.4.47" call ExecTestCase( ServerID, TCN ) TCN = "2.1.4.111" call ExecTestCase( ServerID, TCN ) REM *** REM Test SetClientName TCN = "2.1.5.4" call ExecTestCase( ServerID, TCN ) TCN = "2.1.5.6" call ExecTestCase( ServerID, TCN ) REM TCN = "3.1.1.32" REM call ExecTestCase( ServerID, TCN ) REM *** REM Place stats in the xml document call StoreStats() REM *** REM xml file info and email address XMLFilename = "C:\MyTests\MyTestResults.xml" EmailAddress = "Developer@TheCompanyXYZ.com" REM *** REM save the xml document to an external file xmlDoc.save(XMLFilename) REM *** REM send email to the developer with test results REM call NotifyDeveloperByEmail(EmailAddress,XMLFilename) REM *** REM close XML object and release from memory Set root = Nothing Set xmlDoc = Nothing End Sub REM ************************************** REM ************************************** REM Exec Test Case given number, i.e. "3.1.1.1" and server handle REM Build XML document for FAIL/WARNING test cases Public Sub ExecTestCase(ServerID, TCN) REM just a flag to determine if test case passed or not TestCaseNotBad = TRUE CountTotal = CountTotal + 1 REM execute the given test case OPC.ExecuteTestCase ServerID, TCN REM get the test case status Status = OPC.GetTestCaseStatus(ServerID, TCN) REM check if it failed/warning or ok REM keep track of fail/warning total count If StrComp( Status, "FAIL", vbTextCompare ) = 0 Then CountFail = CountFail + 1 TestCaseNotBad = FALSE End If If StrComp( Status, "WARNING", vbTextCompare ) = 0 Then CountWarning = CountWarning + 1 TestCaseNotBad = FALSE End If If TestCaseNotBad = TRUE Then REM test case status is not FAIL or WARNING REM so there is nothing for us to place in the XML document IsDisabled = OPC.IsTestCaseDisabled(ServerID, TCN) If IsDisabled Then OPC.ScriptOutputEntry TCN & " test case is disabled" End If Exit Sub End If REM collect all the data for this FAIL/WARNING test case ServerName = OPC.GetTestCaseServerName(ServerID, TCN) FunctionName = OPC.GetTestCaseFunctionName(ServerID, TCN) FunctionHR = OPC.GetTestCaseFunctionHRESULT(ServerID, TCN) OPCVersions = OPC.GetTestCaseOPCVersions(ServerID, TCN) ParamIN = OPC.GetTestCaseParamIN(ServerID, TCN) ParamOUT = OPC.GetTestCaseParamOUT(ServerID, TCN) ParamOUTLOOP = OPC.GetTestCaseParamOUTLOOP(ServerID, TCN) ParamCALLBACK = OPC.GetTestCaseParamCALLBACK(ServerID, TCN) ExecTime = OPC.GetTestCaseExecTime(ServerID, TCN) ExecDuration = OPC.GetTestCaseExecDuration(ServerID, TCN) Comment = OPC.GetTestCaseComment(ServerID, TCN) REM create xml nodes and elements/attributes Set TCElem = xmlDoc.createElement("TEST-CASE") TCElem.setAttribute "id", TCN TCElem.setAttribute "status", Status Set ParamElem = xmlDoc.createElement("SERVER") ParamElem.text = ServerName TCElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("FUNCTION") ParamElem.text = FunctionName TCElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("HRESULT") ParamElem.text = FunctionHR TCElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("OPC-VERSIONS") ParamElem.text = OPCVersions TCElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("PARAM-IN") ParamElem.text = ParamIN TCElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("PARAM-OUT") ParamElem.text = ParamOUT TCElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("PARAM-OUTLOOP") ParamElem.text = ParamOUTLOOP TCElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("PARAM-CALLBACK") ParamElem.text = ParamCALLBACK TCElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("EXEC-TIME") ParamElem.text = ExecTime TCElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("EXEC-DURATION") ParamElem.text = ExecDuration ParamElem.setAttribute "unit", "milliseconds" TCElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("COMMENT") ParamElem.text = Comment TCElem.appendChild ParamElem Set ParamElem = Nothing root.appendChild TCElem End Sub REM ************************************** REM ************************************** REM create xml document, add comments Public Sub CreateXMLdoc REM *** ROOT Set xmlDoc = CreateObject("msxml2.DOMDocument.4.0") xmlString = "" xmlDoc.loadXML xmlString Set root = xmlDoc.documentElement REM *** COMMENTS Set comment = xmlDoc.createComment("Visual OPCTest Validator " & OPC.GetAppVersion()) root.appendChild comment Set comment = Nothing End Sub REM ************************************** REM ************************************** REM Add stats to the xml document Public Sub StoreStats Set StatElem = xmlDoc.createElement("STATS") Set ParamElem = xmlDoc.createElement("DATE") ParamElem.text = CStr(Now) StatElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("FAIL-COUNT") ParamElem.text = CStr(CountFail) StatElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("WARNING-COUNT") ParamElem.text = CStr(CountWarning) StatElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("TOTAL-COUNT") ParamElem.text = CStr(CountTotal) StatElem.appendChild ParamElem Set ParamElem = Nothing Set ParamElem = xmlDoc.createElement("SERVER-PROGID") ParamElem.text = ServerProgID StatElem.appendChild ParamElem Set ParamElem = Nothing root.appendChild StatElem End Sub REM ************************************** REM ************************************** REM Send notification to developer with xml report file REM Requires mail system on the client machine REM to be installed and configured Sub NotifyDeveloperByEmail(EmailAddress,XMLFilename) OPC.StatusPaneMsg "Generating email to " & EmailAddress Set golApp = CreateObject("Outlook.Application") Set objNewMail = golApp.CreateItem(olMailItem) objNewMail.Recipients.Add EmailAddress objNewMail.Attachments.Add XMLFilename objNewMail.Subject = "XML Test Results Notification" objNewMail.Body = "XML Test Results Attached. Please verify results." objNewMail.Send Set objNewMail = Nothing Set golApp = Nothing End Sub