Commit 2b9c9f2e authored by Per Cederqvist's avatar Per Cederqvist

Test simple create+add+delete.

parent ae5ef676
import string import string
# Set EXTENDED to 1 to emit tests for lots of misc-into combinations,
# which takes a very long time to test (approx. 5 minutes on a 600 MHz Athlon).
EXTENDED = 0
# Set DEBUG to 1 to emit extra "get-time" calls, which slows the test down
# approximately 5%, but makes it easier to spot errors.
DEBUG = 1
class factory: class factory:
def __init__(self, bcc_trigg, bcc_visible, other_trigg, other_visible, rd): def __init__(self, bcc_trigg, bcc_visible, other_trigg, other_visible, rd):
self.__bcc_trigg = bcc_trigg self.__bcc_trigg = bcc_trigg
...@@ -11,38 +19,59 @@ class factory: ...@@ -11,38 +19,59 @@ class factory:
self.__other_visible.append(n) self.__other_visible.append(n)
self.__readable = bcc_trigg + other_trigg + rd self.__readable = bcc_trigg + other_trigg + rd
def create(self, misc, conf, loc): def create(self, misc, conf, loc,
rec_time = None, sent_by = None, sent_at = None):
if misc == 15: if misc == 15:
trigg = self.__bcc_trigg trigg = self.__bcc_trigg
visib = self.__bcc_visible visib = self.__bcc_visible
else: else:
trigg = self.__other_trigg trigg = self.__other_trigg
visib = self.__other_visible visib = self.__other_visible
return misc_group(misc, conf, loc, trigg, visib, self.__readable) return misc_group(misc, conf, loc, trigg, visib, self.__readable,
rec_time, sent_by, sent_at)
def a_list_pattern(lst):
if len(lst) == 0:
return "0 \\\\\\*"
else:
return "%d { %s }" % (len(lst), string.join(lst, " "))
def a_list_rq(lst):
return "%d { %s }" % (len(lst), string.join(lst, " "))
class misc_group: class misc_group:
def __init__(self, misc, conf, loc, trigg, visib, readable): def __init__(self, misc, conf, loc, trigg, visib, readable,
rec_time, sent_by, sent_at):
self.__misc = misc self.__misc = misc
self.__conf = conf self.__conf = conf
self.__loc = loc self.__loc = loc
self.__trigg = trigg self.__trigg = trigg
self.__visib = visib self.__visib = visib
self.__readable = readable self.__readable = readable
self.__rec_time = rec_time
self.__sent_by = sent_by
self.__sent_at = sent_at
def miscs(self, viewer, rec_time = None, sent_by = None, sent_at = None): def miscs(self, viewer):
if viewer not in self.__visib: if viewer not in self.__visib:
return [] return []
res = ["%d %d" % (self.__misc, self.__conf), res = ["%d %d" % (self.__misc, self.__conf),
"6 %d" % self.__loc] "6 %d" % self.__loc]
if rec_time != None: if self.__rec_time != None:
res.append("7 $any_time") res.append("7 $any_time")
if sent_by != None: if self.__sent_by != None:
res.append("8 %d" % sent_by) res.append("8 %d" % self.__sent_by)
if sent_at != None: if self.__sent_at != None:
res.append("9 $any_time") res.append("9 $any_time")
return res return res
def async(self, viewer, txt):
if viewer not in self.__visib:
return None
return "%d %d %d" % (txt, self.__conf, self.__misc)
def trigger(self, viewer): def trigger(self, viewer):
return viewer in self.__trigg return viewer in self.__trigg
...@@ -90,7 +119,7 @@ obj = { ...@@ -90,7 +119,7 @@ obj = {
(9, 8): factory([8], [9], [], [6, 7], []), (9, 8): factory([8], [9], [], [6, 7], []),
(9, 9): factory([9], [], [], [6, 7, 8], []), (9, 9): factory([9], [], [], [6, 7, 8], []),
(9, 10): factory([7, 8], [6, 9], [], [], [6, 9]), (9, 10): factory([7, 8], [6, 9], [], [], [6, 9]),
(9, 11): factory([7, 8], [9], [], [], []), (9, 11): factory([7, 8], [9], [], [6], []),
(9, 12): factory([7, 8], [9], [], [], []), (9, 12): factory([7, 8], [9], [], [], []),
(9, 13): factory([7, 8], [6, 9], [], [], [6, 9]), (9, 13): factory([7, 8], [6, 9], [], [], [6, 9]),
(9, 14): factory([7, 8], [9], [], [6], [9]), (9, 14): factory([7, 8], [9], [], [6], [9]),
...@@ -138,11 +167,26 @@ def create(author, recipients): ...@@ -138,11 +167,26 @@ def create(author, recipients):
talk_to(author) talk_to(author)
cs = ref.next() cs = ref.next()
tx = tno.next() tx = tno.next()
print "send \"%d 86 [holl \"text %d\"] %d { %s } 0 { }\\n\"" % ( print "send \"%d 86 [holl \"text %d\"] %s 0 { }\\n\"" % (
cs, tx, len(crea), string.join(crea, " ")) cs, tx, a_list_rq(crea))
new_text(author, tx, misc) new_text(author, tx, misc)
talk_to(author) talk_to(author)
print "simple_expect \"=%d %d\"" % (cs, tx) print "simple_expect \"=%d %d\"" % (cs, tx)
verify_text_stat(tx, author, misc)
return (tx, misc)
def add_misc(author, txt, misc_type, rcpt, old_misc):
misc = obj[(author, rcpt)].create(misc_type, rcpt, locno.alloc(rcpt),
sent_at = 1)
talk_to(author)
cs = ref.next()
print "send \"%d 30 %d %d %d\\n\"" % (cs, txt, rcpt, misc_type)
new_recipient(author, txt, misc, old_misc)
talk_to(author)
print "simple_expect \"=%d\"" % cs
return misc
def verify_text_stat(tx, author, misc):
for p in PERSONS: for p in PERSONS:
talk_to(p) talk_to(p)
print "send \"%d 90 %d\\n\"" % (ref.next(), tx) print "send \"%d 90 %d\\n\"" % (ref.next(), tx)
...@@ -154,12 +198,11 @@ def create(author, recipients): ...@@ -154,12 +198,11 @@ def create(author, recipients):
visib = 1 visib = 1
if visib: if visib:
print "simple_expect \"=%d $any_time " \ print "simple_expect \"=%d $any_time " \
"%d 0 %d 0 %d { %s } 0 \\\\\\*\"" % ( "%d 0 %d 0 %s 0 \\\\\\*\"" % (
ref.curr, author, len("text %d" % tx), ref.curr, author, len("text %d" % tx),
len(pattern), string.join(pattern, " ")) a_list_pattern(pattern))
else: else:
print "simple_expect \"%%%d 14 %d\"" % (ref.curr, tx) print "simple_expect \"%%%d 14 %d\"" % (ref.curr, tx)
return (tx, misc)
PERSONS = range(6, 10) PERSONS = range(6, 10)
...@@ -174,10 +217,52 @@ def new_text(author, txt, misc): ...@@ -174,10 +217,52 @@ def new_text(author, txt, misc):
if sent: if sent:
talk_to(viewer) talk_to(viewer)
print "simple_expect \":18 15 %d $any_time " \ print "simple_expect \":18 15 %d $any_time " \
"%d 0 %d 0 %d { %s } 0 \\\\\\*\"" % ( "%d 0 %d 0 %s 0 \\\\\\*\"" % (
txt, author, len("text %d" % txt),
a_list_pattern(pattern))
elif author != viewer and DEBUG:
talk_to(viewer)
print "send \"%d 35\\n\"" % ref.next()
print "simple_expect \"=%d $any_time\"" % ref.curr
def new_recipient(author, tx, misc, old_misc):
for viewer in PERSONS:
sent = 0
for m in old_misc + [misc]:
if m.trigger(viewer):
sent = 1
async = misc.async(viewer, tx)
if sent and async != None:
talk_to(viewer)
print "simple_expect \":3 16 %s\"" % async
elif author != viewer and DEBUG:
talk_to(viewer)
print "send \"%d 35\\n\"" % ref.next()
print "simple_expect \"=%d $any_time\"" % ref.curr
def delete(author, txt, misc):
nr = ref.next()
talk_to(author)
print "send \"%d 29 %d\\n\"" % (nr, txt)
deleted_text(author, txt, misc)
talk_to(author)
print "simple_expect \"=%d\"" % nr
def deleted_text(author, txt, misc):
for viewer in PERSONS:
sent = 0
pattern = []
for m in misc:
if m.trigger(viewer):
sent = 1
pattern = pattern + m.miscs(viewer)
if sent:
talk_to(viewer)
print "simple_expect \":18 14 %d $any_time " \
"%d 0 %d 0 %s 0 \\\\\\*\"" % (
txt, author, len("text %d" % txt), txt, author, len("text %d" % txt),
len(pattern), string.join(pattern, " ")) a_list_pattern(pattern))
elif author != viewer: elif author != viewer and DEBUG:
talk_to(viewer) talk_to(viewer)
print "send \"%d 35\\n\"" % ref.next() print "send \"%d 35\\n\"" % ref.next()
print "simple_expect \"=%d $any_time\"" % ref.curr print "simple_expect \"=%d $any_time\"" % ref.curr
...@@ -242,10 +327,55 @@ def disco(): ...@@ -242,10 +327,55 @@ def disco():
print "lyskomd_death" print "lyskomd_death"
setup() setup()
print "send_user \"testing simple create+delete\\n\""
for author in [6, 7, 8, 9]: for author in [6, 7, 8, 9]:
for misc in [0, 1, 15]: for misc_type in [0, 1, 15]:
for rcpt in [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]: for rcpt in [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]:
if author in [6, 9] and rcpt in [12, 15]: if author in [6, 9] and rcpt in [12, 15]:
continue continue
create(author, [(misc, rcpt)]) (txt, misc) = create(author, [(misc_type, rcpt)])
delete(author, txt, misc)
if not EXTENDED:
continue
for second_misc_type in [0, 1, 15]:
for second_rcpt in [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]:
if rcpt == second_rcpt:
continue
if author in [6, 9] and second_rcpt in [12, 15]:
continue
(txt, misc) = create(author, [
(misc_type, rcpt),
(second_misc_type, second_rcpt)])
delete(author, txt, misc)
print "send_user \"testing simple create+add+delete\\n\""
for author in [6, 7, 8, 9]:
for misc_type in [0, 1, 15]:
for rcpt in [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]:
if author in [6, 9] and rcpt in [12, 15]:
continue
(txt, misc) = create(author, [])
misc.append(add_misc(author, txt, misc_type, rcpt, misc))
verify_text_stat(txt, author, misc)
delete(author, txt, misc)
if not EXTENDED:
continue
for second_misc_type in [0, 1, 15]:
for second_rcpt in [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]:
if rcpt == second_rcpt:
continue
if author in [6, 9] and second_rcpt in [12, 15]:
continue
(txt, misc) = create(author, [])
misc.append(add_misc(author, txt, misc_type, rcpt, misc))
verify_text_stat(txt, author, misc)
misc.append(add_misc(author, txt,
second_misc_type, second_rcpt, misc))
verify_text_stat(txt, author, misc)
delete(author, txt, misc)
disco() disco()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment