From 7ec8417e54d62fd3dba844b3932e2b67107aea0f Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Fri, 19 Aug 2022 00:55:00 +0100 Subject: [PATCH] Client tests: --version dummy, and float printing for sub. --- test/client/02-subscribe-argv-errors-without-tls.py | 3 ++- test/client/02-subscribe-format.py | 5 +++-- test/client/03-publish-argv-errors-without-tls.py | 5 +++-- test/client/04-rr-argv-errors-without-tls.py | 3 ++- test/mosq_test.py | 3 ++- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/test/client/02-subscribe-argv-errors-without-tls.py b/test/client/02-subscribe-argv-errors-without-tls.py index 20458e2c..06853a4b 100755 --- a/test/client/02-subscribe-argv-errors-without-tls.py +++ b/test/client/02-subscribe-argv-errors-without-tls.py @@ -29,8 +29,9 @@ def do_test(args, stderr_expected, rc_expected): if __name__ == '__main__': helps = "\nUse 'mosquitto_sub --help' to see usage.\n" - # Usage, ignore actual text though. + # Usage and version, ignore actual text though. do_test(['--help'], None, 1) + do_test(['--version'], None, 1) # Missing args do_test(['-A'], "Error: -A argument given but no address specified.\n\n" + helps, 1) diff --git a/test/client/02-subscribe-format.py b/test/client/02-subscribe-format.py index 4ddf6ea5..7a997eec 100755 --- a/test/client/02-subscribe-format.py +++ b/test/client/02-subscribe-format.py @@ -4,7 +4,7 @@ from mosq_test_helper import * -def do_test(format_str, expected_output, proto_ver=4): +def do_test(format_str, expected_output, proto_ver=4, payload="message"): rc = 1 port = mosq_test.get_port() @@ -32,7 +32,6 @@ def do_test(format_str, expected_output, proto_ver=4): if proto_ver == 5: cmd += ['-D', 'subscribe', 'subscription-identifier', '56'] - payload = "message" props = mqtt5_props.gen_byte_prop(mqtt5_props.PROP_PAYLOAD_FORMAT_INDICATOR, 1) props += mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_MESSAGE_EXPIRY_INTERVAL, 3600) props += mqtt5_props.gen_string_prop(mqtt5_props.PROP_CONTENT_TYPE, "plain/text") @@ -126,3 +125,5 @@ do_test('\\t', '\t\n') do_test('\\v', '\v\n') do_test('@@', '@\n') do_test('text', 'text\n') +do_test('%.3d', '2.718\n', payload=struct.pack('BBBBBBBB', 0x58, 0x39, 0xB4, 0xC8, 0x76, 0xBE, 0x05, 0x40)) +do_test('%.3f', '0.707\n', payload=struct.pack('BBBB', 0xF4, 0xFD, 0x34, 0x3F)) diff --git a/test/client/03-publish-argv-errors-without-tls.py b/test/client/03-publish-argv-errors-without-tls.py index 7c48bd14..611f128b 100755 --- a/test/client/03-publish-argv-errors-without-tls.py +++ b/test/client/03-publish-argv-errors-without-tls.py @@ -29,9 +29,10 @@ def do_test(args, stderr_expected, rc_expected): if __name__ == '__main__': helps = "\nUse 'mosquitto_pub --help' to see usage.\n" - # Usage, ignore actual text though. + # Usage, version, ignore actual text though. do_test(['--help'], None, 1) - + do_test(['--version'], None, 1) + # Missing args do_test(['-A'], "Error: -A argument given but no address specified.\n\n" + helps, 1) do_test(['-f'], "Error: -f argument given but no file specified.\n\n" + helps, 1) diff --git a/test/client/04-rr-argv-errors-without-tls.py b/test/client/04-rr-argv-errors-without-tls.py index 49d9ef30..997c2c1a 100755 --- a/test/client/04-rr-argv-errors-without-tls.py +++ b/test/client/04-rr-argv-errors-without-tls.py @@ -27,8 +27,9 @@ def do_test(args, stderr_expected, rc_expected): if __name__ == '__main__': helps = "\nUse 'mosquitto_rr --help' to see usage.\n" - # Usage, ignore actual text though. + # Usage, version, ignore actual text though. do_test(['--help'], None, 1) + do_test(['--version'], None, 1) # Missing args do_test(['-A'], "Error: -A argument given but no address specified.\n\n" + helps, 1) diff --git a/test/mosq_test.py b/test/mosq_test.py index 71ea4836..053873fb 100644 --- a/test/mosq_test.py +++ b/test/mosq_test.py @@ -626,7 +626,8 @@ def gen_publish(topic, qos, payload=None, retain=False, dup=False, mid=0, proto_ pack_format = pack_format + "%ds"%(len(properties)) if payload != None: - payload = payload.encode("utf-8") + if isinstance(payload, bytes) == False: + payload = payload.encode("utf-8") rl = rl + len(payload) pack_format = pack_format + str(len(payload))+"s" else: