From 6c13a3172dd416a42952b1ad32c60f474b38bec5 Mon Sep 17 00:00:00 2001 Message-Id: <6c13a3172dd416a42952b1ad32c60f474b38bec5.1715134122.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 24 May 2008 13:53:39 +0100 Subject: [PATCH] More schedule code testing; fix C interface. Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/client.c | 16 +++++---- tests/schedule.py | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 6 deletions(-) diff --git a/lib/client.c b/lib/client.c index e7fba81..d357a8c 100644 --- a/lib/client.c +++ b/lib/client.c @@ -1289,12 +1289,16 @@ int disorder_schedule_add(disorder_client *c, snprintf(when_str, sizeof when_str, "%lld", (long long)when); va_start(ap, action); if(!strcmp(action, "play")) - rc = disorder_simple(c, 0, when_str, priority, - action, va_arg(ap, char *)); - else if(!strcmp(action, "set-global")) - rc = disorder_simple(c, 0, when_str, priority, - action, va_arg(ap, char *), va_arg(ap, char *)); - else + rc = disorder_simple(c, 0, "schedule-add", when_str, priority, + action, va_arg(ap, char *), + (char *)0); + else if(!strcmp(action, "set-global")) { + const char *key = va_arg(ap, char *); + const char *value = va_arg(ap, char *); + rc = disorder_simple(c, 0,"schedule-add", when_str, priority, + action, key, value, + (char *)0); + } else fatal(0, "unknown action '%s'", action); va_end(ap); return rc; diff --git a/tests/schedule.py b/tests/schedule.py index 40b1b07..ae6623c 100755 --- a/tests/schedule.py +++ b/tests/schedule.py @@ -50,6 +50,7 @@ def test(): assert waited < 10, "checking track played within a reasonable period" assert waited > 2, "checking track didn't play immediately" assert p["track"] == track, "checking right track played" + assert c.schedule_list() == [], "checking schedule is empty" print " waiting for nothing to be playing" while c.playing() is not None: time.sleep(1) @@ -70,6 +71,96 @@ def test(): p = c.playing() assert waited < 10, "checking a track played within a reasonable period" assert waited > 2, "checking a track didn't play immediately" + print " disabling random play" + c.random_disable() + print " waiting for nothing to be playing" + while c.playing() is not None: + time.sleep(1) + print " scheduling track to play later via command line" + now = int(time.time()) + dtest.command(["disorder", + "--config", disorder._configfile, + "--no-per-user-config", + "schedule-play", + str(now + 4), + "normal", + track]) + print " disorder schedule-list output:" + print string.join(dtest.command(["disorder", + "--config", disorder._configfile, + "--no-per-user-config", + "schedule-list"]), ""), + print " waiting for it to play" + waited = 0 + p = c.playing() + while p is None and waited < 10: + time.sleep(1) + waited += 1 + p = c.playing() + assert waited < 10, "checking track played within a reasonable period" + assert waited > 2, "checking track didn't play immediately" + assert p["track"] == track, "checking right track played" + assert c.schedule_list() == [], "checking schedule is empty" + print " waiting for nothing to be playing" + while c.playing() is not None: + time.sleep(1) + print " scheduling an enable-random for later via command line" + now = int(time.time()) + dtest.command(["disorder", + "--config", disorder._configfile, + "--no-per-user-config", + "schedule-set-global", + str(now + 4), + "normal", + "random-play", + "yes"]) + print " disorder schedule-list output:" + print string.join(dtest.command(["disorder", + "--config", disorder._configfile, + "--no-per-user-config", + "schedule-list"]), ""), + print " waiting for it to take effect" + waited = 0 + p = c.playing() + while p is None and waited < 10: + time.sleep(1) + waited += 1 + p = c.playing() + assert waited < 10, "checking a track played within a reasonable period" + assert waited > 2, "checking a track didn't play immediately" + print " disabling random play" + c.random_disable() + print " waiting for nothing to be playing" + while c.playing() is not None: + time.sleep(1) + print " scheduling a track for the future" + now = int(time.time()) + c.schedule_add(now + 4, "normal", "play", track) + print " schedule via python:" + s = c.schedule_list() + for event in s: + e = c.schedule_get(event) + print "item %s: %s" % (event, e) + print " deleting item %s" % s[0] + c.schedule_del(s[0]) + print " checking it's really gone" + s = c.schedule_list() + assert s == [], "checking schedule is empty" + waited = 0 + p = c.playing() + while p is None and waited < 10: + time.sleep(1) + waited += 1 + p = c.playing() + assert p is None, "checking deleted scheduled event did not run" + print " checking you can't schedule events for the past" + try: + now = int(time.time()) + c.schedule_add(now - 4, "normal", "play", track) + assert False, "checking schedule_add failed" + except disorder.operationError: + pass # good + if __name__ == '__main__': dtest.run() -- [mdw]