⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testtcl.tcl

📁 Software Testing Automation Framework (STAF)的开发代码
💻 TCL
📖 第 1 页 / 共 3 页
字号:
############################################################################## Software Testing Automation Framework (STAF)                              ## (C) Copyright IBM Corp. 2001                                              ##                                                                           ## This software is licensed under the Common Public License (CPL) V1.0.     ############################################################################### This file contains tests for the STAF Tcl supportpackage require STAFpackage require STAFMonpackage require STAFLogif {[STAF::Register "Tcl Test"] != 0} {    puts "Error registering with STAF, RC: $STAF::RC"    exit $STAF::RC}puts "Using handle $STAF::Handle"######################################## First test some basic functionality ########################################puts "Testing basic functionality"STAF::Submit local ping pingif {$STAF::Result != "PONG"} {    puts "Wrong output for ping request"    exit 1}if {[STAF::Submit local var "resolve string {STAF/Config/MachineNickname}"] != 0} {    puts "Error resolving machine nickname, RC: $STAF::RC, Result: $STAF::Result"    exit $STAF::RC}set self $STAF::Result################################################ Next, lets test the monitor service wrapper ################################################puts "Testing Monitor service functions"# Log the messageset monitorMessage "Hello World"if {[STAF::Monitor::Log $monitorMessage] != $STAF::kOk} {    puts "Error on STAF::Monitor::Log, RC: $STAF::RC, Result: $STAF::Result"    exit $STAF::RC} # Try to retrieve itset request "query machine $self handle $STAF::Handle"if {[STAF::Submit local monitor $request] != $STAF::kOk} {    puts "Error querying monitor info, RC: $STAF::RC, Result: $STAF::Result"    exit $STAF::RC} # Make sure we got back the correct messageif {[string first $monitorMessage $STAF::Result] == -1} {    puts "Wrong output for monitor query request"    puts "Expected to find '<Timestamp> $monitorMessage'"    puts "Found '$STAF::Result'"    exit 1}########################################### Now, lets test the log service wrapper ###########################################puts "Testing Log service functions"# Setup loggingSTAF::Log::Init TclTest handle "Fatal Error Warning Info"# Log the messageset logMessage "A log message"if {[STAF::Log::Log info $logMessage] != $STAF::kOk} {    puts "Error on STAF::Log::Log, RC: $STAF::RC, Result: $STAF::Result"    exit $STAF::RC} # Try to retrieve itset request "query machine $self handle $STAF::Handle logname TclTest"if {[STAF::Submit local log $request] != $STAF::kOk} {    puts "Error on STAF::Log::Log, RC: $STAF::RC, Result: $STAF::Result"    exit $STAF::RC} # Make sure we got back the correct messageif {[string first $logMessage $STAF::Result] == -1} {    puts "Wrong output for log query request"    puts "Expected to find '<Timestamp> $logMessage'"    puts "Found '$STAF::Result'"    exit 1}# Try to retrieve it from monitorset request "query machine $self handle $STAF::Handle"if {[STAF::Submit local Monitor $request] != $STAF::kOk} {    puts "Error on querying monitor info, RC: $STAF::RC, Result: $STAF::Result"    exit $STAF::RC} # Make sure we got back the correct message from monitorif {[string first INFO:$logMessage $STAF::Result] == -1} {    puts "Wrong output for monitor query request"    puts "Expected to find '<Timestamp> INFO:$logMessage'"    puts "Found '$STAF::Result'"    exit 1}# Delete the log fileset request "delete machine $self handle $STAF::Handle logname TclTest confirm" if {[STAF::Submit local log $request] != 0} {    puts "Error deleting log file, RC: $STAF::RC, Result: $STAF::Result"    exit 1}# Log the message so that Monitor shouldn't get itif {[STAF::Log::Log status $logMessage] != $STAF::kOk} {    puts "Error on STAF::Log::Log, RC: $STAF::RC, Result: $STAF::Result"    exit $STAF::RC} # Try to retrieve itset request "query machine $self handle $STAF::Handle logname TclTest"if {[STAF::Submit local log $request] != $STAF::kOk} {    puts "Error on STAF::Log::Log, RC: $STAF::RC, Result: $STAF::Result"    exit $STAF::RC} # Make sure we got back the correct messageif {[string first $logMessage $STAF::Result] == -1} {    puts "Wrong output for log query request"    puts "Expected to find '<Timestamp> $logMessage'"    puts "Found '$STAF::Result'"    exit 1}# Try to retrieve it from monitorset request "query machine $self handle $STAF::Handle"if {[STAF::Submit local Monitor $request] != $STAF::kOk} {    puts "Error on querying monitor info, RC: $STAF::RC, Result: $STAF::Result"    exit $STAF::RC} # Make sure we got back the correct (old) message from monitorif {[string first INFO:$logMessage $STAF::Result] == -1} {    puts "Wrong output for monitor query request"    puts "Expected to find '<Timestamp> INFO:$logMessage'"    puts "Found '$STAF::Result'"    exit 1}########################### Test privacy functions ###########################puts "Testing privacy functions"set data "secret"set dataWithPD [STAF::AddPrivacyDelimiters $data]set expectedResult "!!@secret@!!"if {[STAF::AddPrivacyDelimiters $data] != $expectedResult} {    puts "Error: \[STAF::AddPrivacyDelimiters $data\] : [STAF::AddPrivacyDelimiters $data]"    puts "       Should return the following instead: $expectedResult"    exit 1}set expectedResult "^!!@secret^@!!"if {[STAF::EscapePrivacyDelimiters $dataWithPD] != $expectedResult} {    puts "Error: \[STAF::EscapePrivacyDelimiters $dataWithPD\] = [STAF::EscapePrivacyDelimiters $dataWithPD]"    puts "       Should return the following instead: $expectedResult"    exit 1}set expectedResult "************"if {[STAF::MaskPrivateData $dataWithPD] != $expectedResult} {    puts "Error: \[STAF::MaskPrivateData $dataWithPD\] = [STAF::MaskPrivateData $dataWithPD]"    puts "       Should return the following instead: $expectedResult"    exit 1}set expectedResult "secret"if {[STAF::RemovePrivacyDelimiters $dataWithPD] != $expectedResult} {    puts "Error: \[STAF::RemovePrivacyDelimiters $dataWithPD\] = [STAF::RemovePrivacyDelimiters $dataWithPD]"    puts "       Should return the following instead: $expectedResult"    exit 1}set data "!!@Msg: ^!!@Pw is ^^!!@secret^^@!!.^@!!@!!"set expectedResult "Msg: Pw is secret."if {[STAF::RemovePrivacyDelimiters $data] != $expectedResult} {    puts "Error: \[STAF::RemovePrivacyDelimiters $data\] = [STAF::RemovePrivacyDelimiters $data]"    puts "       Should return the following instead: $expectedResult"    exit 1}set expectedResult "Msg: Pw is secret."if {[STAF::RemovePrivacyDelimiters $data 0] != $expectedResult} {    puts "Error: \[STAF::RemovePrivacyDelimiters $data 0\] = [STAF::RemovePrivacyDelimiters $data 0]"    puts "       Should return the following instead: $expectedResult"    exit 1}set expectedResult "Msg: !!@Pw is ^!!@secret^@!!.@!!"if {[STAF::RemovePrivacyDelimiters $data 1] != $expectedResult} {    puts "Error: \[STAF::RemovePrivacyDelimiters $data 1\] = [STAF::RemovePrivacyDelimiters $data 1]"    puts "       Should return the following instead: $expectedResult"    exit 1}set expectedResult "Msg: Pw is !!@secret@!!."if {[STAF::RemovePrivacyDelimiters $data 2] != $expectedResult} {    puts "Error: \[STAF::RemovePrivacyDelimiters $data 2\] = [STAF::RemovePrivacyDelimiters $data 2]"    puts "       Should return the following instead: $expectedResult"    exit 1}# Test private methods passing in an empty stringset data ""set expectedResult ""if {[STAF::AddPrivacyDelimiters $data] != $expectedResult} {    puts "Error: \[STAF::AddPrivacyDelimiters $data\] : [STAF::AddPrivacyDelimiters $data]"    puts "       Should return the following instead: $expectedResult"    exit 1}if {[STAF::EscapePrivacyDelimiters $data] != $expectedResult} {    puts "Error: \[STAF::EscapePrivacyDelimiters $data\] : [STAF::EscapePrivacyDelimiters $data]"    puts "       Should return the following instead: $expectedResult"    exit 1}if {[STAF::MaskPrivateData $data] != $expectedResult} {    puts "Error: \[STAF::MaskPrivateData $data\] : [STAF::MaskPrivateData $data]"    puts "       Should return the following instead: $expectedResult"    exit 1}if {[STAF::RemovePrivacyDelimiters $data] != $expectedResult} {    puts "Error: \[STAF::RemovePrivacyDelimiters $data\] : [STAF::RemovePrivacyDelimiters $data]"    puts "       Should return the following instead: $expectedResult"    exit 1}################################### Now, let's test STAF::datatype ###################################puts "\nTesting data type functions:\n"# For each type (None is handled a little differently),#   create (without value)#   validate type#   get value#   set value#   get value#   create (with value)#   get value#   set value#   get value## For list and map, also do the following#   append to STAF::datatype value#   get value# Testing data type Noneputs "Testing data type: None"set dtNone [STAF::datatype createNone]if {[STAF::datatype getType $dtNone] != $STAF::NoneType} {    puts "Wrong type for a None data type"    puts "Expected: $STAF::NoneType"    puts "Found: [STAF::datatype getType $dtNone]"    exit 1}if {[STAF::datatype getValue $dtNone] != "None"} {    puts "Wrong value for a None data type"    puts "Expected: None"    puts "Found: [STAF::datatype getValue $dtNone]"    exit 1}if {[catch {STAF::datatype setValue dtNone "Ok"}] == 0} {    puts "Error: Successfully set the type of a None data type"    exit 1}set dtNone2 [STAF::datatype createNone "NoneValue"]if {[STAF::datatype getValue $dtNone2] != "None"} {    puts "Wrong value for a None data type"    puts "Expected: None"    puts "Found: [STAF::datatype getValue $dtNone]"    exit 1}# Testing data type Contextputs "Testing data type: Context"set dtContext [STAF::datatype createContext]if {[STAF::datatype getType $dtContext] != $STAF::ContextType} {    puts "Wrong type for a Context data type"    puts "Expected: $STAF::ContextType"    puts "Found: [STAF::datatype getType $dtContext]"    exit 1}# Testing data type Scalarputs "Testing data type: Scalar"set dtScalar [STAF::datatype createScalar]if {[STAF::datatype getType $dtScalar] != "$STAF::ScalarType"} {    puts "Wrong type for a Scalar data type"    puts "Expected: $STAF::ScalarType"    puts "Found: [STAF::datatype getType $dtScalar]"    exit 1}if {[STAF::datatype getValue $dtScalar] != ""} {    puts "Wrong value for data type"    puts "Expected: <Empty string>"    puts "Found: [STAF::datatype getValue $dtScalar]"    exit 1}set scalarTestValue  "Scalar Test Value"STAF::datatype setValue dtScalar $scalarTestValueif {[STAF::datatype getValue $dtScalar] != $scalarTestValue} {    puts "Wrong value for data type"    puts "Expected: $scalarTestValue"    puts "Found: [STAF::datatype getValue $dtScalar]"    exit 1}set scalarInitValue "Scalar Init Value"set dtScalar [STAF::datatype createScalar $scalarInitValue]if {[STAF::datatype getValue $dtScalar] != $scalarInitValue} {    puts "Wrong value for data type"    puts "Expected: $scalarInitValue"    puts "Found: [STAF::datatype getValue $dtScalar]"    exit 1}STAF::datatype setValue dtScalar $scalarTestValueif {[STAF::datatype getValue $dtScalar] != $scalarTestValue} {    puts "Wrong value for data type"    puts "Expected: $scalarTestValue"    puts "Found: [STAF::datatype getValue $dtScalar]"    exit 1}# Testing data type Listputs "Testing data type: List"set dtList [STAF::datatype createList]if {[STAF::datatype getType $dtList] != "$STAF::ListType"} {    puts "Wrong type for a List data type"    puts "Expected: $STAF::ListType"    puts "Found: [STAF::datatype getType $dtList]"    exit 1}if {[STAF::datatype getValue $dtList] != ""} {    puts "Wrong value for data type"    puts "Expected: <Empty string>"    puts "Found: [STAF::datatype getValue $dtList]"    exit 1}set listTestValue [list "List" "Test" "Value"]STAF::datatype setValue dtList $listTestValueif {[STAF::datatype getValue $dtList] != $listTestValue} {    puts "Wrong value for data type"    puts "Expected: $listTestValue"    puts "Found: [STAF::datatype getValue $dtList]"    exit 1}set listInitValue [list "List" "Init" "Value"]set dtList [STAF::datatype createList $listInitValue]if {[STAF::datatype getValue $dtList] != $listInitValue} {    puts "Wrong value for data type"    puts "Expected: $listInitValue"    puts "Found: [STAF::datatype getValue $dtList]"    exit 1}STAF::datatype setValue dtList $listTestValueif {[STAF::datatype getValue $dtList] != $listTestValue} {    puts "Wrong value for data type"    puts "Expected: $listTestValue"    puts "Found: [STAF::datatype getValue $dtList]"    exit 1}lappend listTestValue "And"lappend listTestValue "More"lappend dtList "And"lappend dtList "More"if {[STAF::datatype getValue $dtList] != $listTestValue} {    puts "Wrong value for data type"    puts "Expected: $listTestValue"    puts "Found: [STAF::datatype getValue $dtList]"    exit 1}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -