#!/usr/local/bin/python
#
# File:		stringtest
# Copyright:	(c) 2001 The Regents of the University of California
# Release:	$Name: release-0-8-8 $
# Revision:	$Revision: 1.2 $
# Date:		$Date: 2002/07/25 16:03:25 $
# Description:	Excercise strings in hopes of finding bugs
#

import Strings.Cstring

class TestCounter:
  partno = 0
  numpass = 0
  numfail = 0
  numxfail = 0
  numxpass = 0

  def __init__(self, numparts = -1):
    self.numparts = numparts
    print "NPARTS", numparts

  def describeTest(self, description):
    self.partno = self.partno + 1
    print "PART", self.partno
    print "COMMENT:", description

  def evalTest(self, result, expected=1):
    if (result):
      if (expected):
        self.numpass = self.numpass + 1
        print "RESULT", self.partno, "PASS"
      else:
        self.numxpass = self.numxpass + 1
        print "RESULT", self.partno, "XPASS"
    else:
      if (expected):
        self.numfail = self.numfail + 1
        print "RESULT", self.partno, "FAIL"
      else:
        self.numxfail = self.numxfail + 1
        print "RESULT", self.partno, "XFAIL"
        
  def finish(self):
    if (self.numparts < 0):
      self.numparts = self.partno
    if (self.numpass == self.numparts):
      print "TEST_RESULT PASS"
    else:
      if (self.numpass + self.numxfail == self.numparts):
        print "TEST_RESULT XFAIL"
      else:
        print "TEST_RESULT FAIL"
      
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
