From: Roger Light Date: Sat, 22 Jun 2013 20:57:40 +0000 (+0100) Subject: Add more topic matching tests. X-Git-Tag: v0.9~68 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=21b9bc4c181d31dda0a306c932d004ab0052d882;p=packages%2Fp%2Fpaho-mqtt.git Add more topic matching tests. --- diff --git a/test/lib/python/09-util-topic-matching.test b/test/lib/python/09-util-topic-matching.test index c546e20..6ce4234 100755 --- a/test/lib/python/09-util-topic-matching.test +++ b/test/lib/python/09-util-topic-matching.test @@ -3,33 +3,24 @@ import paho.mqtt.client as mqtt import sys -if mqtt.topic_matches_sub("foo/bar", "foo/bar") == False: - print("ERROR: foo/bar : foo/bar") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+", "foo/bar") == False: - print("ERROR: foo/+ : foo/bar") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+/baz", "foo/bar/baz") == False: - print("ERROR: foo/+/baz : foo/bar/baz") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+/#", "foo/bar/baz") == False: - print("ERROR: foo/+/# : foo/bar/baz") - sys.exit(1) -if mqtt.topic_matches_sub("#", "foo/bar/baz") == False: - print("ERROR: # : foo/bar/baz") - sys.exit(1) +def do_check(sub, topic, bad_res): + if mqtt.topic_matches_sub(sub, topic) == bad_res: + print("ERROR: "+sub+" "+topic) + sys.exit(1) -if mqtt.topic_matches_sub("foo/bar", "foo") == True: - print("ERROR: foo/bar : foo") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+", "foo/bar/baz") == True: - print("ERROR: foo/+ : foo/bar/baz") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+/baz", "foo/bar/bar") == True: - print("ERROR: foo/+/baz : foo/bar/bar") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+/#", "fo2/bar/baz") == True: - print("ERROR: foo/+/# : foo/bar/baz") - sys.exit(1) +do_check("foo/bar", "foo/bar", False) +do_check("foo/+", "foo/bar", False) +do_check("foo/+/baz", "foo/bar/baz", False) +do_check("foo/+/#", "foo/bar/baz", False) +do_check("#", "foo/bar/baz", False) + +do_check("foo/bar", "foo", True) +do_check("foo/+", "foo/bar/baz", True) +do_check("foo/+/baz", "foo/bar/bar", True) +do_check("foo/+/#", "fo2/bar/baz", True) + +do_check("#", "/foo/bar", False) +do_check("/#", "/foo/bar", False) +do_check("/#", "foo/bar", True) sys.exit(0) diff --git a/test/lib/python3/08-ssl-bad-cacert.test b/test/lib/python3/08-ssl-bad-cacert.test index 404030a..a3cdc13 100755 --- a/test/lib/python3/08-ssl-bad-cacert.test +++ b/test/lib/python3/08-ssl-bad-cacert.test @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import os import subprocess diff --git a/test/lib/python3/09-util-topic-matching.test b/test/lib/python3/09-util-topic-matching.test index c546e20..a3cc8d9 100755 --- a/test/lib/python3/09-util-topic-matching.test +++ b/test/lib/python3/09-util-topic-matching.test @@ -1,35 +1,26 @@ -#!/usr/bin/python +#!/usr/bin/python3 import paho.mqtt.client as mqtt import sys -if mqtt.topic_matches_sub("foo/bar", "foo/bar") == False: - print("ERROR: foo/bar : foo/bar") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+", "foo/bar") == False: - print("ERROR: foo/+ : foo/bar") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+/baz", "foo/bar/baz") == False: - print("ERROR: foo/+/baz : foo/bar/baz") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+/#", "foo/bar/baz") == False: - print("ERROR: foo/+/# : foo/bar/baz") - sys.exit(1) -if mqtt.topic_matches_sub("#", "foo/bar/baz") == False: - print("ERROR: # : foo/bar/baz") - sys.exit(1) +def do_check(sub, topic, bad_res): + if mqtt.topic_matches_sub(sub, topic) == bad_res: + print("ERROR: "+sub+" "+topic) + sys.exit(1) -if mqtt.topic_matches_sub("foo/bar", "foo") == True: - print("ERROR: foo/bar : foo") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+", "foo/bar/baz") == True: - print("ERROR: foo/+ : foo/bar/baz") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+/baz", "foo/bar/bar") == True: - print("ERROR: foo/+/baz : foo/bar/bar") - sys.exit(1) -if mqtt.topic_matches_sub("foo/+/#", "fo2/bar/baz") == True: - print("ERROR: foo/+/# : foo/bar/baz") - sys.exit(1) +do_check("foo/bar", "foo/bar", False) +do_check("foo/+", "foo/bar", False) +do_check("foo/+/baz", "foo/bar/baz", False) +do_check("foo/+/#", "foo/bar/baz", False) +do_check("#", "foo/bar/baz", False) + +do_check("foo/bar", "foo", True) +do_check("foo/+", "foo/bar/baz", True) +do_check("foo/+/baz", "foo/bar/bar", True) +do_check("foo/+/#", "fo2/bar/baz", True) + +do_check("#", "/foo/bar", False) +do_check("/#", "/foo/bar", False) +do_check("/#", "foo/bar", True) sys.exit(0)