1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#!/usr/local/bin/python
#
# File: stringtest
# Copyright: (c) 2001 The Regents of the University of California
# Revision: $Revision: 4434 $
# Date: $Date: 2005-03-17 09:05:29 -0800 (Thu, 17 Mar 2005) $
# Description: Excercise strings in hopes of finding bugs
#
import Strings.Cstring
from synch import RegOut
from synch.ResultType import *
class TestCounter:
def __init__(self, numparts = -1):
self.tracker = RegOut.RegOut();
self.partno = 0
self.tracker.setExpectations(numparts)
def describeTest(self, description):
self.partno = self.partno + 1
self.tracker.startPart(self.partno)
self.tracker.writeComment(description)
def evalTest(self, result, expected=1):
if (result):
if (expected):
self.tracker.endPart(self.partno, PASS)
else:
self.tracker.endPart(self.partno, XPASS)
else:
if (expected):
self.tracker.endPart(self.partno, FAIL)
else:
self.tracker.endPart(self.partno, XFAIL)
def finish(self):
self.tracker.close()
if __name__ == '__main__':
counter = TestCounter(12)
counter.describeTest("obj = Strings.Cstring.Cstring()")
obj = Strings.Cstring.Cstring()
counter.evalTest(obj != None)
counter.describeTest('obj.returnback(1) == "Three"')
counter.evalTest(obj.returnback(1) == "Three")
counter.describeTest('obj.returnback(0) == None || ""')
rbr = obj.returnback(0)
counter.evalTest((rbr == None) or (rbr == ""))
counter.describeTest('obj.passin("Three")')
counter.evalTest(obj.passin("Three"))
counter.describeTest('not obj.passin(None)')
counter.evalTest(not obj.passin(None))
counter.describeTest('(1, "Three") == obj.passout(1)')
counter.evalTest((1, "Three") == obj.passout(1))
counter.describeTest('obj.passout(0) == (0, None) || (0, "")')
rbr = obj.passout(0)
counter.evalTest((rbr == (0, None)) or (rbr == (0, "")))
counter.describeTest('(1, "threes") == obj.passinout("Three")')
counter.evalTest((1, "threes") == obj.passinout("Three"))
counter.describeTest('obj.passinout(None) == (0, None) || (0, "")')
rbr = obj.passinout(None)
counter.evalTest((rbr == (0, None)) or (rbr == 0, ""))
counter.describeTest('("Three", "Three", "Three") == obj.passeverywhere("Three", "threes")')
counter.evalTest(("Three", "Three", "Three") ==
obj.passeverywhere("Three", "threes"))
counter.describeTest('obj.mixedarguments("Test", "z", "Test", "z")')
counter.evalTest(obj.mixedarguments("Test", "z", "Test", "z"))
counter.describeTest('obj.mixedarguments("Not", "A", "Equal", "a")')
counter.evalTest(not obj.mixedarguments("Not", "A", "Equal", "a"))
counter.finish()
0
|