#!/usr/local/bin/ruby
#
# Copyright 2005 Perforce Software. All rights reserved.
#
require "../../cur.triggers/P4Data.rb"
require "../../cur.triggers/P4Form.rb"
require "../../cur.triggers/P4Jobs.rb"
FORM = {
"Status" => "z",
"Product" => "a.b.c",
"AltOwner" => "alt",
}
`sed -e 's/USERNAME/five/g' useradd.txt | p4 user -i -f`
`sed -e 's/USERNAME/six/g' useradd.txt | p4 user -i -f`
`sed -e 's/USERNAME/seven/g' useradd.txt | p4 user -i -f`
`sed -e 's/USERNAME/eight/g' useradd.txt | p4 user -i -f`
`sed -e 's/USERNAME/alt/g' useradd.txt | p4 user -i -f`
failed = 0
P4TESTFLOW = [
{ "a.b.c:z" => "one", },
{ "a.b.c:*" => "two", },
{ "a.b:z" => "three", },
{ "a.b:*" => "four", },
{ "a:z" => "five", },
{ "a:*" => "six", },
{ "*:z" => "seven", },
{ "*:*" => "eight", },
]
printf("Test run 1:\n")
cnt = 0
expect = ["one", "two", "three", "four", "five", "six", "seven", "eight"]
P4TESTFLOW.each do |flow|
result = state_owner(flow, FORM, "Status", "Product")
if expect[cnt] == result then
printf("%d: pass with %s\n", cnt, result)
else
printf("%d: FAILED, %s instead of %s\n", cnt, result, expect[cnt])
failed += 1
end
cnt += 1
end
P4TESTFLOWREF = [
{ "a.b.c:z" => "$AltOwner", },
{ "a.b.c:*" => "$AltOwner", },
{ "a.b:z" => "$AltOwner", },
{ "a.b:*" => "$AltOwner", },
{ "a:z" => "$AltOwner", },
{ "a:*" => "$AltOwner", },
{ "*:z" => "$AltOwner", },
{ "*:*" => "$AltOwner", },
]
printf("\nTest run 2:\n")
cnt = 0
P4TESTFLOWREF.each do |flow|
result = state_owner(flow, FORM, "Status", "Product")
if result == "alt" then
printf("%d: pass with %s\n", cnt, result)
else
printf("%d: FAILED, %s instead of alt\n", cnt, result)
failed += 1
end
cnt += 1
end
P4TESTFLOW2 = [
{ "a.b.c:z" => "%y", "a.b.c:y" => "one", },
{ "a.b.c:*" => "%y", },
{ "a.b:z" => "%y", "a.b:y" => "three", },
{ "a.b:*" => "%y", },
{ "a:z" => "%y", "a:y" => "five", },
{ "a:*" => "%y", },
{ "*:z" => "%y", "*:y" => "seven", },
{ "*:*" => "%y", },
]
printf("\nTest run 3:\n")
cnt = 0
expect = ["one", "", "three", "", "five", "", "seven", ""]
P4TESTFLOW2.each do |flow|
result = state_owner(flow, FORM, "Status", "Product")
if expect[cnt] == result then
printf("%d: pass with %s\n", cnt, result)
else
printf("%d: FAILED, %s instead of %s\n", cnt, result, expect[cnt])
failed += 1
end
cnt += 1
end
P4TESTFLOW3 = {
"a.b.c:z" => "one",
"a.b.c:*" => "two",
"a.b:z" => "three",
"a.b:*" => "four",
"a:z" => "five",
"a:*" => "six",
"*:z" => "seven",
"*:*" => "eight",
}
PRODS = [ "a.b.c", "a.b", "a", "e" ]
STATES = [ "z", "y" ]
form2 = {
"Status" => "z",
"Product" => "a.b.c",
"AltOwner" => "alt",
}
printf("\nTest run 4:\n")
cnt = 0
expect = ["one", "two", "three", "four", "five", "six", "seven", "eight"]
PRODS.each do |prod|
STATES.each do |state|
form2["Product"] = prod
form2["Status"] = state
result = state_owner(P4TESTFLOW3, form2, "Status", "Product")
if expect[cnt] == result then
printf("%d: pass with %s:%s -> %s\n", cnt, prod, state, result)
else
printf("%d: FAILED, %s:%s -> %s instead of%s\n", cnt,
prod, state, result, expect[cnt])
failed += 1
end
cnt += 1
end
end
P4TESTFLOW4 = [
{ "a.b.c:z" => "%y", "a.b.c:y" => "one", },
{ "a.b.c:z" => "%y", "a.b.c:*" => "two", },
{ "a.b.c:z" => "%y", "a.b:y" => "three", },
{ "a.b.c:z" => "%y", "a.b:*" => "four", },
{ "a.b.c:z" => "%y", "a:y" => "five", },
{ "a.b.c:z" => "%y", "a:*" => "six", },
{ "a.b.c:z" => "%y", "*:y" => "seven", },
{ "a.b.c:z" => "%y", "*:*" => "eight", },
{ "a.b.c:*" => "%y", "a.b.c:y" => "one", },
{ "a.b.c:*" => "%y", "a.b:y" => "three", },
{ "a.b.c:*" => "%y", "a.b:*" => "four", },
{ "a.b.c:*" => "%y", "a:y" => "five", },
{ "a.b.c:*" => "%y", "a:*" => "six", },
{ "a.b.c:*" => "%y", "*:y" => "seven", },
{ "a.b.c:*" => "%y", "*:*" => "eight", },
{ "a.b:z" => "%y", "a.b.c:y" => "one", },
{ "a.b:z" => "%y", "a.b:y" => "three", },
{ "a.b:z" => "%y", "a.b:*" => "four", },
{ "a.b:z" => "%y", "a:y" => "five", },
{ "a.b:z" => "%y", "a:*" => "six", },
{ "a.b:z" => "%y", "*:y" => "seven", },
{ "a.b:z" => "%y", "*:*" => "eight", },
{ "a.b:*" => "%y", "a.b.c:y" => "one", },
{ "a.b:*" => "%y", "a.b:y" => "three", },
{ "a.b:*" => "%y", "a:y" => "five", },
{ "a.b:*" => "%y", "a:*" => "six", },
{ "a.b:*" => "%y", "*:y" => "seven", },
{ "a.b:*" => "%y", "*:*" => "eight", },
{ "a:z" => "%y", "a.b.c:y" => "one", },
{ "a:z" => "%y", "a.b:y" => "three", },
{ "a:z" => "%y", "a:y" => "five", },
{ "a:z" => "%y", "a:*" => "six", },
{ "a:z" => "%y", "*:y" => "seven", },
{ "a:z" => "%y", "*:*" => "eight", },
{ "a:*" => "%y", "a.b.c:y" => "one", },
{ "a:*" => "%y", "a.b:y" => "three", },
{ "a:*" => "%y", "a:y" => "five", },
{ "a:*" => "%y", "*:y" => "seven", },
{ "a:*" => "%y", "*:*" => "eight", },
{ "*:z" => "%y", "a.b.c:y" => "one", },
{ "*:z" => "%y", "a.b:y" => "three", },
{ "*:z" => "%y", "a:y" => "five", },
{ "*:z" => "%y", "*:y" => "seven", },
{ "*:z" => "%y", "*:*" => "eight", },
{ "*:*" => "%y", "a.b.c:y" => "one", },
{ "*:*" => "%y", "a.b:y" => "three", },
{ "*:*" => "%y", "a:y" => "five", },
{ "*:*" => "%y", "*:y" => "seven", },
]
printf("\nTest run 5:\n")
cnt = 0
expect = [
"one", "two", "three", "four", "five", "six", "seven", "eight",
"one", "three", "four", "five", "six", "seven", "eight",
"one", "three", "four", "five", "six", "seven", "eight",
"one", "three", "five", "six", "seven", "eight",
"one", "three", "five", "six", "seven", "eight",
"one", "three", "five", "seven", "eight",
"one", "three", "five", "seven", "eight",
"one", "three", "five", "seven",
"", "", "", "", "", "", ""
]
P4TESTFLOW4.each do |flow|
result = state_owner(flow, FORM, "Status", "Product")
if expect[cnt] == result then
printf("%d: pass with %s\n", cnt, result)
else
printf("%d: FAILED, %s instead of %s\n", cnt, result, expect[cnt])
failed += 1
end
cnt += 1
end
if failed > 0 then
printf("\n%d tests FAILED\n", failed)
else
printf("\nAll tests passed\n");
end