diff --git a/CMakeLists.txt b/CMakeLists.txt index cbbb8e7..e0f9945 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 11) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror -Wno-unused-parameter") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-unused-parameter") include_directories(include) @@ -40,7 +40,9 @@ set(TEST_FILES tests/helpers.cpp tests/packet.cpp tests/string.cpp - tests/tests.cpp) + tests/tests.cpp + tests/generated.cpp + ) add_executable(tests ${TEST_FILES}) diff --git a/examples/async.c b/examples/async.c index fdf5899..7855462 100644 --- a/examples/async.c +++ b/examples/async.c @@ -15,7 +15,8 @@ lwmqtt_client_t client; pthread_mutex_t mutex; -static void message_arrived(lwmqtt_client_t *_client, void *ref, lwmqtt_string_t topic, lwmqtt_message_t msg) { +static void message_arrived(lwmqtt_client_t *_client, void *ref, lwmqtt_string_t topic, lwmqtt_message_t msg, + lwmqtt_serialized_properties_t props) { printf("message_arrived: %.*s => %.*s (%d)\n", (int)topic.len, topic.data, (int)msg.payload_len, (char *)msg.payload, (int)msg.payload_len); } @@ -102,7 +103,9 @@ int main() { printf("connected!\n"); // subscribe to topic - err = lwmqtt_subscribe_one(&client, lwmqtt_string("hello"), LWMQTT_QOS0, COMMAND_TIMEOUT); + lwmqtt_sub_options_t subopts = lwmqtt_default_sub_options; + lwmqtt_properties_t subprops = lwmqtt_empty_props; + err = lwmqtt_subscribe_one(&client, lwmqtt_string("hello"), subopts, subprops, COMMAND_TIMEOUT); if (err != LWMQTT_SUCCESS) { printf("failed lwmqtt_subscribe: %d\n", err); exit(1); @@ -135,7 +138,8 @@ int main() { pthread_mutex_lock(&mutex); // publish message - err = lwmqtt_publish(&client, lwmqtt_string("hello"), msg, COMMAND_TIMEOUT); + lwmqtt_properties_t props = lwmqtt_empty_props; + err = lwmqtt_publish(&client, lwmqtt_string("hello"), msg, props, COMMAND_TIMEOUT); if (err != LWMQTT_SUCCESS) { printf("failed lwmqtt_publish: %d\n", err); exit(1); diff --git a/examples/sync.c b/examples/sync.c index 16fdb36..740b2d9 100644 --- a/examples/sync.c +++ b/examples/sync.c @@ -13,9 +13,41 @@ lwmqtt_unix_timer_t timer1, timer2, timer3; lwmqtt_client_t client; -static void message_arrived(lwmqtt_client_t *_client, void *ref, lwmqtt_string_t topic, lwmqtt_message_t msg) { +static void prop_byte_printer(void *ref, lwmqtt_prop_t prop, uint8_t value) { + printf(" Property %x (byte): 0x%x\n", prop, value); +} + +static void prop_int16_printer(void *ref, lwmqtt_prop_t prop, int16_t value) { + printf(" Property %x (int): %d\n", prop, value); +} + +static void prop_int32_printer(void *ref, lwmqtt_prop_t prop, int32_t value) { + printf(" Property %x (int32): %d\n", prop, value); +} + +static void prop_str_printer(void *ref, lwmqtt_prop_t prop, lwmqtt_string_t value) { + printf(" Property %x (string): %.*s\n", prop, (int)value.len, value.data); +} + +static void prop_user_printer(void *ref, lwmqtt_string_t k, lwmqtt_string_t v) { + printf(" User property: k=%.*s, v=%.*s\n", (int)k.len, k.data, (int)v.len, v.data); +} + +static void message_arrived(lwmqtt_client_t *_client, void *ref, lwmqtt_string_t topic, lwmqtt_message_t msg, + lwmqtt_serialized_properties_t props) { printf("message_arrived: %.*s => %.*s (%d)\n", (int)topic.len, topic.data, (int)msg.payload_len, (char *)msg.payload, (int)msg.payload_len); + + lwmqtt_property_callbacks_t cb = { + .byte_prop = prop_byte_printer, + .int16_prop = prop_int16_printer, + .int32_prop = prop_int32_printer, + .str_prop = prop_str_printer, + .user_prop = prop_user_printer, + }; + if (lwmqtt_property_visitor(NULL, props, cb) != LWMQTT_SUCCESS) { + exit(1); + } } int main() { @@ -26,12 +58,13 @@ int main() { lwmqtt_set_network(&client, &network, lwmqtt_unix_network_read, lwmqtt_unix_network_write); lwmqtt_set_timers(&client, &timer1, &timer2, lwmqtt_unix_timer_set, lwmqtt_unix_timer_get); lwmqtt_set_callback(&client, NULL, message_arrived); + lwmqtt_set_protocol(&client, LWMQTT_MQTT5); // configure message time lwmqtt_unix_timer_set(&timer3, MESSAGE_TIMEOUT); // connect to broker - lwmqtt_err_t err = lwmqtt_unix_network_connect(&network, "public.cloud.shiftr.io", 1883); + lwmqtt_err_t err = lwmqtt_unix_network_connect(&network, "localhost", 1883); if (err != LWMQTT_SUCCESS) { printf("failed lwmqtt_unix_network_connect: %d\n", err); exit(1); @@ -56,7 +89,9 @@ int main() { printf("connected!\n"); // subscribe to topic - err = lwmqtt_subscribe_one(&client, lwmqtt_string("hello"), LWMQTT_QOS0, COMMAND_TIMEOUT); + lwmqtt_sub_options_t subopts = lwmqtt_default_sub_options; + lwmqtt_properties_t subprops = lwmqtt_empty_props; + err = lwmqtt_subscribe_one(&client, lwmqtt_string("hello"), subopts, subprops, COMMAND_TIMEOUT); if (err != LWMQTT_SUCCESS) { printf("failed lwmqtt_subscribe: %d\n", err); exit(1); @@ -91,10 +126,17 @@ int main() { // check if message is due if (lwmqtt_unix_timer_get(&timer3) <= 0) { // prepare message - lwmqtt_message_t msg = {.qos = LWMQTT_QOS0, .retained = false, .payload = (uint8_t *)("world"), .payload_len = 5}; + lwmqtt_message_t msg = {.qos = LWMQTT_QOS0, .retained = true, .payload = (uint8_t *)("world"), .payload_len = 5}; // publish message - err = lwmqtt_publish(&client, lwmqtt_string("hello"), msg, COMMAND_TIMEOUT); + lwmqtt_property_t proplist[] = { + {.prop = LWMQTT_PROP_MESSAGE_EXPIRY_INTERVAL, .value = {.int32 = 30}}, + {.prop = LWMQTT_PROP_USER_PROPERTY, + .value = {.pair = {.k = lwmqtt_string("hello from"), .v = lwmqtt_string("lwmqtt")}}}, + }; + + lwmqtt_properties_t props = {2, (lwmqtt_property_t *)&proplist}; + err = lwmqtt_publish(&client, lwmqtt_string("hello"), msg, props, COMMAND_TIMEOUT); if (err != LWMQTT_SUCCESS) { printf("failed lwmqtt_keep_alive: %d\n", err); exit(1); diff --git a/gentests/.gitignore b/gentests/.gitignore new file mode 100644 index 0000000..3483168 --- /dev/null +++ b/gentests/.gitignore @@ -0,0 +1,3 @@ +.stack-work/ +gentests.cabal +*~ \ No newline at end of file diff --git a/gentests/Setup.hs b/gentests/Setup.hs new file mode 100644 index 0000000..9a994af --- /dev/null +++ b/gentests/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/gentests/app/Main.hs b/gentests/app/Main.hs new file mode 100644 index 0000000..565f9aa --- /dev/null +++ b/gentests/app/Main.hs @@ -0,0 +1,554 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} +{-# LANGUAGE RecordWildCards #-} + +module Main where + +import Control.Monad (replicateM) +import qualified Data.ByteString.Char8 as BC +import qualified Data.ByteString.Lazy as BL +import Data.List (intercalate) +import Data.Maybe (isJust) +import Network.MQTT.Arbitrary +import Network.MQTT.Types as MT +import Numeric (showHex) +import Test.QuickCheck as QC +import Text.RawString.QQ + +hexa :: BL.ByteString -> String +hexa b + | BL.null b = "0" + | otherwise = (intercalate ", " . map (\x -> "0x" <> showHex x "") . BL.unpack) b + +bool :: Bool -> String +bool True = "true" +bool False = "false" + +qos :: QoS -> String +qos QoS0 = "LWMQTT_QOS0" +qos QoS1 = "LWMQTT_QOS1" +qos QoS2 = "LWMQTT_QOS2" + +protlvl :: ProtocolLevel -> String +protlvl Protocol311 = "LWMQTT_MQTT311" +protlvl Protocol50 = "LWMQTT_MQTT5" + +shortprot :: ProtocolLevel -> String +shortprot Protocol311 = "311" +shortprot Protocol50 = "5" + +v311PubReq :: PublishRequest -> PublishRequest +v311PubReq p50 = let (PublishPkt p) = v311mask (PublishPkt p50) in p + +data PubACKs = ACK PubACK | REC PubREC | REL PubREL | COMP PubCOMP deriving(Show, Eq) + +instance Arbitrary PubACKs where + arbitrary = oneof [ + ACK <$> arbitrary, + REC <$> arbitrary, + REL <$> arbitrary, + COMP <$> arbitrary + ] + +v311ACKs :: PubACKs -> PubACKs +v311ACKs (ACK p50) = let (PubACKPkt a) = v311mask (PubACKPkt p50) in ACK a +v311ACKs (REC p50) = let (PubRECPkt a) = v311mask (PubRECPkt p50) in REC a +v311ACKs (REL p50) = let (PubRELPkt a) = v311mask (PubRELPkt p50) in REL a +v311ACKs (COMP p50) = let (PubCOMPPkt a) = v311mask (PubCOMPPkt p50) in COMP a + +v311SubReq :: SubscribeRequest -> SubscribeRequest +v311SubReq p50 = let (SubscribePkt p) = v311mask (SubscribePkt p50) in p + +v311UnsubReq :: UnsubscribeRequest -> UnsubscribeRequest +v311UnsubReq p50 = let (UnsubscribePkt p) = v311mask (UnsubscribePkt p50) in p + +v311SubACK :: SubscribeResponse -> SubscribeResponse +v311SubACK p50 = let (SubACKPkt p) = v311mask (SubACKPkt p50) in p + +v311UnsubACK :: UnsubscribeResponse -> UnsubscribeResponse +v311UnsubACK p50 = let (UnsubACKPkt p) = v311mask (UnsubACKPkt p50) in p + +v311ConnReq :: ConnectRequest -> ConnectRequest +v311ConnReq p50 = let (ConnPkt p) = v311mask (ConnPkt p50) in p + +v311DiscoClean :: DisconnectRequest -> DisconnectRequest +v311DiscoClean p50 = let (DisconnectPkt p) = v311mask (DisconnectPkt p50) in p + +userFix :: ConnectRequest -> ConnectRequest +userFix = ufix . pfix + where + ufix p@ConnectRequest{..} + | _username == Just "" = p{_username=Nothing} + | otherwise = p + pfix p@ConnectRequest{..} + | _password == Just "" = p{_password=Nothing} + | otherwise = p + +data Prop = IProp Int String Int + | SProp Int String (Int,BL.ByteString) + | UProp Int (Int,BL.ByteString) (Int,BL.ByteString) + +captureProps :: [MT.Property] -> [Prop] +captureProps = map e + where + peW8 i x = IProp i "byte" (fromEnum x) + peW16 i x = IProp i "int16" (fromEnum x) + peW32 i x = IProp i "int32" (fromEnum x) + peUTF8 i x = SProp i "str" (0,x) + peBin i x = SProp i "str" (0,x) + peVarInt i = IProp i "int32" + pePair i k v = UProp i (0,k) (0,v) + + e (PropPayloadFormatIndicator x) = peW8 0x01 x + e (PropMessageExpiryInterval x) = peW32 0x02 x + e (PropContentType x) = peUTF8 0x03 x + e (PropResponseTopic x) = peUTF8 0x08 x + e (PropCorrelationData x) = peBin 0x09 x + e (PropSubscriptionIdentifier x) = peVarInt 0x0b x + e (PropSessionExpiryInterval x) = peW32 0x11 x + e (PropAssignedClientIdentifier x) = peUTF8 0x12 x + e (PropServerKeepAlive x) = peW16 0x13 x + e (PropAuthenticationMethod x) = peUTF8 0x15 x + e (PropAuthenticationData x) = peBin 0x16 x + e (PropRequestProblemInformation x) = peW8 0x17 x + e (PropWillDelayInterval x) = peW32 0x18 x + e (PropRequestResponseInformation x) = peW8 0x19 x + e (PropResponseInformation x) = peUTF8 0x1a x + e (PropServerReference x) = peUTF8 0x1c x + e (PropReasonString x) = peUTF8 0x1f x + e (PropReceiveMaximum x) = peW16 0x21 x + e (PropTopicAliasMaximum x) = peW16 0x22 x + e (PropTopicAlias x) = peW16 0x23 x + e (PropMaximumQoS x) = peW8 0x24 x + e (PropRetainAvailable x) = peW8 0x25 x + e (PropUserProperty k v) = pePair 0x26 k v + e (PropMaximumPacketSize x) = peW32 0x27 x + e (PropWildcardSubscriptionAvailable x) = peW8 0x28 x + e (PropSubscriptionIdentifierAvailable x) = peW8 0x29 x + e (PropSharedSubscriptionAvailable x) = peW8 0x2a x + +-- Emit the given list of properties as C code. +genProperties :: String -> [MT.Property] -> String +genProperties name props = mconcat [ + " ", encodePropList, "\n", + " lwmqtt_properties_t ", name, " = {" <> show (length props) <> ", (lwmqtt_property_t*)&", name, "list};\n" + ] + + where + encodePropList = let (hdr, cp) = (emitByteArrays . captureProps) props in + mconcat (map (<>"\n ") hdr) <> "\n" + <> " lwmqtt_property_t " <> name <> "list[] = {\n" + <> mconcat (map (indent.e) cp) + <> " };\n" + where + emitByteArrays :: [Prop] -> ([String], [Prop]) + emitByteArrays = go [] [] 0 + where + go :: [String] -> [Prop] -> Int -> [Prop] -> ([String], [Prop]) + go l p _ [] = (reverse l, reverse p) + go l p n (x@IProp{}:xs) = go l (x:p) n xs + go l p n (SProp i s (_,bs):xs) = go (newstr n bs:l) (SProp i s (n,bs):p) (n+1) xs + go l p n (UProp i (_,bs1) (_,bs2):xs) = go (newstr n bs1 : newstr (n+1) bs2 : l) (UProp i (n,bs1) (n+1,bs2):p) (n+2) xs + + newstr n s = "uint8_t bytes" <> name <> show n <> "[] = {" <> hexa s <> "};" + + e :: Prop -> String + e (IProp i n v) = prop i n (show v) + e (SProp i n (x,xv)) = prop i n (b x xv) + e (UProp i (k,kv) (v,vv)) = prop i "pair" ("{.k=" <> b k kv <> ", .v=" <> b v vv <> "}") + + prop i n v = "{.prop = (lwmqtt_prop_t)" <> show i <> ", .value = {." <> n <> " = " <> v <> "}},\n" + + indent = (" " <>) + + b x xv = "{" <> show (BL.length xv) <> ", (char*)&bytes" <> name <> show x <> "}" + +encodeString :: String -> BL.ByteString -> String +encodeString name bytes = mconcat [ + " uint8_t " <> name <> "_bytes[] = {" <> hexa bytes <> "};\n", + " lwmqtt_string_t " <> name <> " = {" <> show (BL.length bytes) <> ", (char*)&" <> name <> "_bytes};\n" + ] + +genTestFunc :: (Show a, ByteMe a) => String -> String -> ProtocolLevel -> Int -> a -> String -> String +genTestFunc tset tname prot i p body = let e = toByteString prot p in + mconcat [ + "// ", show p, "\n", + "TEST(", tset, shortprot prot, "QCTest, ", tname, show i <> ") {\n", + "uint8_t pkt[] = {" <> hexa e <> "};\n", + body, "\n", + "}\n\n" + ] + +genPublishTest :: ProtocolLevel -> Int -> PublishRequest -> String +genPublishTest prot i p@PublishRequest{..} = + mconcat [encTest, decTest] + + where + encTest = genTestFunc "Publish" "Encode" prot i p $ mconcat [ + encodeString "topic" _pubTopic, + "\n uint8_t buf[sizeof(pkt)+10] = { 0 };\n", + "lwmqtt_message_t msg = lwmqtt_default_message;\n", + "msg.qos = " <> qos _pubQoS <> ";\n", + "msg.retained = " <> bool _pubRetain <> ";\n", + "uint8_t msg_bytes[] = {" <> hexa _pubBody <> "};\n", + "msg.payload = (unsigned char*)&msg_bytes;\n", + "msg.payload_len = " <> show (BL.length _pubBody) <> ";\n\n", + genProperties "props" _pubProps, + "size_t len = 0;\n", + "lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, " <> protlvl prot <> ", ", + bool _pubDup, ", ", show _pubPktID, ", topic, msg, props);\n\n", + "EXPECT_EQ(err, LWMQTT_SUCCESS);\n", + "EXPECT_ARRAY_EQ(pkt, buf, len);" + ] + + decTest = genTestFunc "Publish" "Decode" prot i p $ mconcat [ + "bool dup;\n", + "uint16_t packet_id;\n", + "lwmqtt_string_t topic;\n", + "lwmqtt_message_t msg;\n", + "lwmqtt_serialized_properties_t props;\n", + "lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), ", protlvl prot, ", &dup, &packet_id, &topic, &msg, &props);\n", + "\n", + "EXPECT_EQ(err, LWMQTT_SUCCESS);\n", + encodeString "exp_topic" _pubTopic, + encodeString "exp_body" _pubBody, + "EXPECT_EQ(dup, ", bool _pubDup, ");\n", + "EXPECT_EQ(msg.qos, ", qos _pubQoS, ");\n", + "EXPECT_EQ(msg.retained, ", bool _pubRetain, ");\n", + "EXPECT_EQ(packet_id, ", show _pubPktID, ");\n", + "EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), ", show (BL.length _pubTopic), ");\n", + "EXPECT_EQ(msg.payload_len, ", show (BL.length _pubBody), ");\n", + "EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, ", show (BL.length _pubBody), ");\n", + "lwmqtt_string_t x = exp_topic;\nx = exp_body;\n" + ] + +genUnsubTest :: ProtocolLevel -> Int -> UnsubscribeRequest -> String +genUnsubTest prot i p@(UnsubscribeRequest pid subs props) = do + genTestFunc "Unsubscribe" "Encode" prot i p $ mconcat [ + "uint8_t buf[sizeof(pkt)+10] = { 0 };\n", + genProperties "props" props, + encodeFilters, + "size_t len;\n", + "lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, ", protlvl prot, ", ", show pid, ", ", + show (length subs), ", topic_filters, props);\n", + " EXPECT_EQ(err, LWMQTT_SUCCESS);\n", + " EXPECT_ARRAY_EQ(pkt, buf, len);\n" + ] + where + encodeFilters = "lwmqtt_string_t topic_filters[" <> show (length subs) <> "];\n" <> + concatMap aSub (zip [0..] subs) + where aSub :: (Int, BL.ByteString) -> String + aSub (i', t) = mconcat [ + encodeString ("topic_filter_s" <> show i') t, + "topic_filters[", show i', "] = topic_filter_s", show i', ";\n" + ] + +genSubTest :: ProtocolLevel -> Int -> SubscribeRequest -> String +genSubTest prot i p@(SubscribeRequest pid subs props) = do + genTestFunc "Subscribe" "Encode" prot i p $ mconcat [ + "uint8_t buf[sizeof(pkt)+10] = { 0 };\n", + encodeFilters, + encodeQos, + genProperties "props" props, + " size_t len = 0;\n", + " lwmqtt_err_t err = lwmqtt_encode_subscribe(buf, sizeof(buf), &len, ", protlvl prot, ", ", + show pid, ", ", show (length subs), ", topic_filters, sub_opts, props);\n\n", + " EXPECT_EQ(err, LWMQTT_SUCCESS);\n", + " EXPECT_ARRAY_EQ(pkt, buf, len);\n" + ] + + where + encodeFilters = "lwmqtt_string_t topic_filters[" <> show (length subs) <> "];\n" <> + concatMap aSub (zip [0..] subs) + where + aSub :: (Int, (BL.ByteString, SubOptions)) -> String + aSub (i', (s,_)) = mconcat [ + encodeString ("topic_filter_s" <> show i') s, + "topic_filters[", show i', "] = topic_filter_s", show i', ";\n" + ] + + encodeQos = "lwmqtt_sub_options_t sub_opts["<> show (length subs) <> "];\n" <> (concatMap subvals $ zip [0..] subs) + where + subvals :: (Int,(BL.ByteString, SubOptions)) -> String + subvals (subi,(_,SubOptions{..})) = mconcat [ + si, "qos = ", qos _subQoS, ";\n", + si, "retain_handling = ", rh _retainHandling, ";\n", + si, "retain_as_published = ", bool _retainAsPublished, ";\n", + si, "no_local = ", bool _noLocal, ";\n" + ] + where + si = "sub_opts[" <> show subi <> "]." + rh SendOnSubscribe = "LWMQTT_SUB_SEND_ON_SUB" + rh SendOnSubscribeNew = "LWMQTT_SUB_SEND_ON_SUB_NEW" + rh DoNotSendOnSubscribe = "LWMQTT_SUB_NO_SEND_ON_SUB" + +genConnectTest :: ProtocolLevel -> Int -> ConnectRequest -> String +genConnectTest prot i p@ConnectRequest{..} = do + genTestFunc "Connect" "Encode" prot i p $ mconcat [ + "uint8_t buf[sizeof(pkt)+10] = { 0 };\n", + + genProperties "props" _properties, + encodeWill _lastWill, + encodeOptions, + "size_t len = 0;\n", + "lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, " <> protlvl prot <> ", opts, ", + if isJust _lastWill then "&will" else "NULL", ");\n\n", + "EXPECT_EQ(err, LWMQTT_SUCCESS);\n", + "EXPECT_EQ(len, sizeof(pkt));\n", + "EXPECT_ARRAY_EQ(pkt, buf, len);\n" + ] + + where + encodeWill Nothing = "" + encodeWill (Just LastWill{..}) = mconcat [ + "lwmqtt_will_t will = lwmqtt_default_will;\n", + genProperties "willprops" _willProps, + encodeString "will_topic" _willTopic, + encodeString "will_payload" _willMsg, + "will.topic = will_topic;\n", + "will.payload = will_payload;\n", + "will.qos = " <> qos _willQoS <> ";\n", + "will.retained = " <> bool _willRetain <> ";\n", + "will.properties = willprops;\n" + ] + + encodeOptions = mconcat [ + "lwmqtt_options_t opts = lwmqtt_default_options;\n", + "opts.properties = props;\n", + "opts.clean_session = " <> bool _cleanSession <> ";\n", + "opts.keep_alive = " <> show _keepAlive <> ";\n", + encodeString "client_id" _connID, + "opts.client_id = client_id;\n", + maybeString "username" _username, + maybeString "password" _password + ] + + where maybeString _ Nothing = "" + maybeString n (Just b) = mconcat [ + encodeString n b, + "opts.", n, " = ", n, ";\n" + ] + +genSubACKTest :: ProtocolLevel -> Int -> SubscribeResponse -> String +genSubACKTest prot i p@(SubscribeResponse pid res _props) = do + let ll = show (length res) + genTestFunc "SubACK" "Decode" prot i p $ mconcat [ + "uint16_t packet_id;\n", + "int count;\n", + "lwmqtt_qos_t granted_qos_levels[", ll, "];\n", + "lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id,", + protlvl prot, ", ", ll, ", &count, granted_qos_levels);\n", + "EXPECT_EQ(err, LWMQTT_SUCCESS);\n", + "EXPECT_EQ(packet_id, ", show pid, ");\n", + "EXPECT_EQ(count, ", ll, ");\n", + concatMap checkQos (zip [0..] res) + ] + + where + checkQos :: (Int,Either SubErr QoS) -> String + checkQos (qi,q) = "EXPECT_EQ(granted_qos_levels[" <> show qi <> "], " <> qq prot q <> ");\n" + qq Protocol311 (Left _) = "0x80" + qq Protocol50 (Left x) = q5 x + qq _ (Right q) = qos q + + q5 SubErrUnspecifiedError = "0x80" + q5 SubErrImplementationSpecificError = "0x83" + q5 SubErrNotAuthorized = "0x87" + q5 SubErrTopicFilterInvalid = "0x8F" + q5 SubErrPacketIdentifierInUse = "0x91" + q5 SubErrQuotaExceeded = "0x97" + q5 SubErrSharedSubscriptionsNotSupported = "0x9E" + q5 SubErrSubscriptionIdentifiersNotSupported = "0xA1" + q5 SubErrWildcardSubscriptionsNotSupported = "0xA2" + +genUnsubACKTest :: ProtocolLevel -> Int -> UnsubscribeResponse -> String +genUnsubACKTest prot i p@(UnsubscribeResponse pid _props res) = do + let ll = show (length res) + genTestFunc "UnsubACK" "Decode" prot i p $ mconcat [ + "uint16_t packet_id;\n", + "int count;\n", + "lwmqtt_unsubscribe_status_t statuses[", ll, "];\n", + "lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id,", + protlvl prot, ", ", ll, ", &count, statuses);\n", + "EXPECT_EQ(err, LWMQTT_SUCCESS);\n", + "EXPECT_EQ(packet_id, ", show pid, ");\n", + "EXPECT_EQ(count, ", ll, ");\n", + concatMap checkStatus (zip [0..] res) + ] + + where + checkStatus :: (Int,UnsubStatus) -> String + checkStatus (qi,q) = "EXPECT_EQ(statuses[" <> show qi <> "], " <> b q <> ");\n" + + b UnsubSuccess = "LWMQTT_UNSUB_SUCCESS" + b UnsubNoSubscriptionExisted = "LWMQTT_UNSUB_NO_SUB_EXISTED" + b UnsubUnspecifiedError = "LWMQTT_UNSUB_UNSPECIFIED_ERROR" + b UnsubImplementationSpecificError = "LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR" + b UnsubNotAuthorized = "LWMQTT_UNSUB_NOT_AUTHORIZED" + b UnsubTopicFilterInvalid = "LWMQTT_UNSUB_TOPIC_FILTER_INVALID" + b UnsubPacketIdentifierInUse = "LWMQTT_UNSUB_PACKET_ID_IN_USE" + + +genDiscoTest :: ProtocolLevel -> Int -> DisconnectRequest -> String +genDiscoTest prot i p@(DisconnectRequest rsn props) = do + genTestFunc "Disco" "Encode" prot i p $ mconcat [ + "uint8_t buf[sizeof(pkt)+10] = { 0 };\n", + genProperties "props" props, + "size_t len = 0;\n", + "lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, ", protlvl prot, ", ", show (dr rsn), ", props);\n", + "EXPECT_EQ(err, LWMQTT_SUCCESS);\n", + "EXPECT_EQ(len, sizeof(pkt));\n", + "EXPECT_ARRAY_EQ(pkt, buf, len);\n" + ] + + where + dr DiscoNormalDisconnection = 0x00 + dr DiscoDisconnectWithWill = 0x04 + dr DiscoUnspecifiedError = 0x80 + dr DiscoMalformedPacket = 0x81 + dr DiscoProtocolError = 0x82 + dr DiscoImplementationSpecificError = 0x83 + dr DiscoNotAuthorized = 0x87 + dr DiscoServerBusy = 0x89 + dr DiscoServershuttingDown = 0x8B + dr DiscoKeepAliveTimeout = 0x8D + dr DiscoSessiontakenOver = 0x8e + dr DiscoTopicFilterInvalid = 0x8f + dr DiscoTopicNameInvalid = 0x90 + dr DiscoReceiveMaximumExceeded = 0x93 + dr DiscoTopicAliasInvalid = 0x94 + dr DiscoPacketTooLarge = 0x95 + dr DiscoMessageRateTooHigh = 0x96 + dr DiscoQuotaExceeded = 0x97 + dr DiscoAdministrativeAction = 0x98 + dr DiscoPayloadFormatInvalid = 0x99 + dr DiscoRetainNotSupported = 0x9a + dr DiscoQoSNotSupported = 0x9b + dr DiscoUseAnotherServer = 0x9c + dr DiscoServerMoved = 0x9d + dr DiscoSharedSubscriptionsNotSupported = 0x9e + dr DiscoConnectionRateExceeded = 0x9f + dr DiscoMaximumConnectTime = 0xa0 + dr DiscoSubscriptionIdentifiersNotSupported = 0xa1 + dr DiscoWildcardSubscriptionsNotSupported = 0xa2 + +genPubACKTest :: ProtocolLevel -> Int -> PubACKs -> String +genPubACKTest prot i pkt = enc <> dec + + where + enc = tf (name pkt) "Encode" $ mconcat [ + "uint8_t buf[sizeof(pkt)+10];\n", + genProperties "props" props, + "size_t len;\n", + "lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, ", protlvl prot, ", ", cname pkt, ", 0, ", show pid, ", ", show st, ", props);\n", + "EXPECT_EQ(err, LWMQTT_SUCCESS);\n", + "EXPECT_EQ(len, sizeof(pkt));\n", + "EXPECT_ARRAY_EQ(pkt, buf, len);\n" + ] + dec = tf (name pkt) "Decode" $ mconcat [ + "uint16_t packet_id;\n", + "uint8_t status;\n", + "lwmqtt_serialized_properties_t props;\n", + "bool dup;\n", + "lwmqtt_err_t err = lwmqtt_decode_ack(pkt, sizeof(pkt), ", protlvl prot, ", ", cname pkt, ", &dup, &packet_id, &status, &props);\n", + "EXPECT_EQ(err, ", exst st, ");\n", + "EXPECT_EQ(packet_id, ", show pid, ");\n", + "EXPECT_EQ(status, ", show st, ");\n" + ] + + name = ("PubACK" <>) . head . words . show + val (ACK x) = toByteString prot x + val (REC x) = toByteString prot x + val (REL x) = toByteString prot x + val (COMP x) = toByteString prot x + + pid = let (p,_,_) = parts pkt in p + st = let (_,s,_) = parts pkt in s + props = let (_,_,p) = parts pkt in p + + exst 0 = "LWMQTT_SUCCESS" + exst _ = "LWMQTT_PUBACK_NACKED" + + parts (ACK (PubACK a b p)) = (a,b,p) + parts (REC (PubREC a b p)) = (a,b,p) + parts (REL (PubREL a b p)) = (a,b,p) + parts (COMP (PubCOMP a b p)) = (a,b,p) + + cname (ACK _) = "LWMQTT_PUBACK_PACKET" + cname (REC _) = "LWMQTT_PUBREC_PACKET" + cname (REL _) = "LWMQTT_PUBREL_PACKET" + cname (COMP _) = "LWMQTT_PUBCOMP_PACKET" + + -- this is genTestFunc specialized to be more informative here. + tf test tname body = let e = val pkt in + mconcat [ + "// ", show pkt, "\n", + "TEST(", test, shortprot prot, "QCTest, ", tname, show i <> ") {\n", + "uint8_t pkt[] = {" <> hexa e <> "};\n", + body, "\n", + "}\n\n" + ] + + +main :: IO () +main = do + putStrLn [r|#include + +extern "C" { +#include +#include "../src/packet.h" +} + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#ifdef __clang__ +#pragma GCC diagnostic ignored "-Wc99-extensions" +#else +#pragma GCC diagnostic ignored "-Wpedantic" +#endif +#endif + +#define EXPECT_ARRAY_EQ(reference, actual, element_count) \ + { \ + for (size_t cmp_i = 0; cmp_i < element_count; cmp_i++) { \ + EXPECT_EQ(reference[cmp_i], actual[cmp_i]) << "At byte: " << cmp_i; \ + } \ + } +|] + let numTests = 30 + + pubs <- replicateM numTests $ generate arbitrary + f genPublishTest Protocol311 (v311PubReq <$> pubs) + f genPublishTest Protocol50 pubs + + pubax <- replicateM numTests $ generate arbitrary + f genPubACKTest Protocol311 (v311ACKs <$> pubax) + f genPubACKTest Protocol50 pubax + + conns <- replicateM numTests $ generate arbitrary + f genConnectTest Protocol311 (userFix . v311ConnReq <$> conns) + f genConnectTest Protocol50 (userFix <$> conns) + + subs <- replicateM numTests $ generate arbitrary + f genSubTest Protocol311 (v311SubReq <$> subs) + f genSubTest Protocol50 subs + + subax <- replicateM numTests $ generate arbitrary + f genSubACKTest Protocol311 (v311SubACK <$> subax) + f genSubACKTest Protocol50 subax + + unsubs <- replicateM numTests $ generate arbitrary + f genUnsubTest Protocol311 (v311UnsubReq <$> unsubs) + f genUnsubTest Protocol50 unsubs + + unsubax <- replicateM numTests $ generate arbitrary + f genUnsubACKTest Protocol311 (v311UnsubACK <$> unsubax) + f genUnsubACKTest Protocol50 unsubax + + discos <- replicateM numTests $ generate arbitrary + f genDiscoTest Protocol311 (take 2 $ v311DiscoClean <$> discos) -- these are all the same + f genDiscoTest Protocol50 discos + + where + f :: (ProtocolLevel -> Int -> a -> String) -> ProtocolLevel -> [a] -> IO () + f g pl l = mapM_ putStrLn $ map (uncurry $ g pl) $ zip [1..] l diff --git a/gentests/package.yaml b/gentests/package.yaml new file mode 100644 index 0000000..e5f00ba --- /dev/null +++ b/gentests/package.yaml @@ -0,0 +1,35 @@ +name: gentests +version: 0.1.0.0 +github: "dustin/gentests" +license: BSD3 +author: "Dustin Sallings" +maintainer: "dustin@spy.net" +copyright: "MIT" + +extra-source-files: [] + +# Metadata used when publishing your package +# synopsis: Short description of your package +# category: Web + +# To avoid duplicated efforts in documentation and dealing with the +# complications of embedding Haddock markup inside cabal files, it is +# common to point users to the README.md file. +description: Please see the README on GitHub at + +dependencies: +- base >= 4.7 && < 5 + +executables: + gentests: + main: Main.hs + source-dirs: app + ghc-options: + - -threaded + - -rtsopts + - -with-rtsopts=-N + dependencies: + - net-mqtt + - QuickCheck + - bytestring + - raw-strings-qq diff --git a/gentests/stack.yaml b/gentests/stack.yaml new file mode 100644 index 0000000..7ef783a --- /dev/null +++ b/gentests/stack.yaml @@ -0,0 +1,65 @@ +# This file was automatically generated by 'stack init' +# +# Some commonly used options have been documented as comments in this file. +# For advanced use and comprehensive documentation of the format, please see: +# https://docs.haskellstack.org/en/stable/yaml_configuration/ + +# Resolver to choose a 'specific' stackage snapshot or a compiler version. +# A snapshot resolver dictates the compiler version and the set of packages +# to be used for project dependencies. For example: +# +# resolver: lts-3.5 +# resolver: nightly-2015-09-21 +# resolver: ghc-7.10.2 +# +# The location of a snapshot can be provided as a file or url. Stack assumes +# a snapshot provided as a file might change, whereas a url resource does not. +# +# resolver: ./custom-snapshot.yaml +# resolver: https://example.com/snapshots/2018-01-01.yaml +resolver: lts-14.6 + +# User packages to be built. +# Various formats can be used as shown in the example below. +# +# packages: +# - some-directory +# - https://example.com/foo/bar/baz-0.0.2.tar.gz +# - location: +# git: https://github.com/commercialhaskell/stack.git +# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a +# subdirs: +# - auto-update +# - wai +packages: +- . +# Dependency packages to be pulled from upstream that are not in the resolver +# using the same syntax as the packages field. +# (e.g., acme-missiles-0.3) +extra-deps: +- net-mqtt-0.5.1.0 + +# Override default flag values for local packages and extra-deps +# flags: {} + +# Extra package databases containing global packages +# extra-package-dbs: [] + +# Control whether we use the GHC we find on the path +# system-ghc: true +# +# Require a specific version of stack, using version ranges +# require-stack-version: -any # Default +# require-stack-version: ">=1.9" +# +# Override the architecture used by stack, especially useful on Windows +# arch: i386 +# arch: x86_64 +# +# Extra directories used by stack for building +# extra-include-dirs: [/path/to/dir] +# extra-lib-dirs: [/path/to/dir] +# +# Allow a newer minor version of GHC than the snapshot specifies +# compiler-check: newer-minor diff --git a/include/lwmqtt.h b/include/lwmqtt.h index 4feee57..7bb2a00 100644 --- a/include/lwmqtt.h +++ b/include/lwmqtt.h @@ -5,6 +5,8 @@ #include #include +typedef enum { LWMQTT_MQTT311, LWMQTT_MQTT5 } lwmqtt_protocol_t; + /** * The error type used by all exposed APIs. * @@ -27,6 +29,8 @@ typedef enum { LWMQTT_FAILED_SUBSCRIPTION = -11, LWMQTT_SUBACK_ARRAY_OVERFLOW = -12, LWMQTT_PONG_TIMEOUT = -13, + LWMQTT_FAILED_UNSUBSCRIPTION = -14, + LWMQTT_PUBACK_NACKED = -15, } lwmqtt_err_t; /** @@ -63,7 +67,85 @@ int lwmqtt_strcmp(lwmqtt_string_t a, const char *b); /** * The available QOS levels. */ -typedef enum { LWMQTT_QOS0 = 0, LWMQTT_QOS1 = 1, LWMQTT_QOS2 = 2, LWMQTT_QOS_FAILURE = 128 } lwmqtt_qos_t; +typedef enum __attribute__((__packed__)) { + LWMQTT_QOS0 = 0, + LWMQTT_QOS1 = 1, + LWMQTT_QOS2 = 2, + LWMQTT_QOS_FAILURE = 128 +} lwmqtt_qos_t; + +typedef enum __attribute__((__packed__)) { + LWMQTT_SUB_SEND_ON_SUB = 0, + LWMQTT_SUB_SEND_ON_SUB_NEW = 1, + LWMQTT_SUB_NO_SEND_ON_SUB = 2 +} lwmqtt_retain_handling_t; + +typedef struct { + lwmqtt_qos_t qos : 3; + lwmqtt_retain_handling_t retain_handling : 3; + bool retain_as_published : 1; + bool no_local : 1; +} lwmqtt_sub_options_t; + +#define lwmqtt_default_sub_options \ + { LWMQTT_QOS0, LWMQTT_SUB_SEND_ON_SUB, false, false } + +typedef enum { + LWMQTT_PROP_PAYLOAD_FORMAT_INDICATOR = 0x01, + LWMQTT_PROP_MESSAGE_EXPIRY_INTERVAL = 0x02, + LWMQTT_PROP_CONTENT_TYPE = 0x03, + LWMQTT_PROP_RESPONSE_TOPIC = 0x08, + LWMQTT_PROP_CORRELATION_DATA = 0x09, + LWMQTT_PROP_SUBSCRIPTION_IDENTIFIER = 0x0B, + LWMQTT_PROP_SESSION_EXPIRY_INTERVAL = 0x11, + LWMQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER = 0x12, + LWMQTT_PROP_SERVER_KEEP_ALIVE = 0x13, + LWMQTT_PROP_AUTHENTICATION_METHOD = 0x15, + LWMQTT_PROP_AUTHENTICATION_DATA = 0x16, + LWMQTT_PROP_REQUEST_PROBLEM_INFORMATION = 0x17, + LWMQTT_PROP_WILL_DELAY_INTERVAL = 0x18, + LWMQTT_PROP_REQUEST_RESPONSE_INFORMATION = 0x19, + LWMQTT_PROP_RESPONSE_INFORMATION = 0x1A, + LWMQTT_PROP_SERVER_REFERENCE = 0x1C, + LWMQTT_PROP_REASON_STRING = 0x1F, + LWMQTT_PROP_RECEIVE_MAXIMUM = 0x21, + LWMQTT_PROP_TOPIC_ALIAS_MAXIMUM = 0x22, + LWMQTT_PROP_TOPIC_ALIAS = 0x23, + LWMQTT_PROP_MAXIMUM_QOS = 0x24, + LWMQTT_PROP_RETAIN_AVAILABLE = 0x25, + LWMQTT_PROP_USER_PROPERTY = 0x26, + LWMQTT_PROP_MAXIMUM_PACKET_SIZE = 0x27, + LWMQTT_PROP_WILDCARD_SUBSCRIPTION_AVAILABLE = 0x28, + LWMQTT_PROP_SUBSCRIPTION_IDENTIFIER_AVAILABLE = 0x29, + LWMQTT_PROP_SHARED_SUBSCRIPTION_AVAILABLE = 0x2A, +} lwmqtt_prop_t; + +typedef struct { + lwmqtt_prop_t prop; + union { + uint8_t byte; + uint32_t int32; + uint16_t int16; + lwmqtt_string_t str; + struct { + lwmqtt_string_t k; + lwmqtt_string_t v; + } pair; + } value; +} lwmqtt_property_t; + +typedef struct { + uint16_t len; + lwmqtt_property_t *props; +} lwmqtt_properties_t; + +#define lwmqtt_empty_props \ + { 0, NULL } + +typedef struct { + size_t size; + uint8_t *start; +} lwmqtt_serialized_properties_t; /** * The message object used to publish and receive messages. @@ -139,12 +221,15 @@ typedef int32_t (*lwmqtt_timer_get_t)(void *ref); * recommended to call any further lwmqtt methods in the callback as this might result in weird call stacks. The * callback should place the received messages in a queue and dispatch them after the caller has returned. */ -typedef void (*lwmqtt_callback_t)(lwmqtt_client_t *client, void *ref, lwmqtt_string_t str, lwmqtt_message_t msg); +typedef void (*lwmqtt_callback_t)(lwmqtt_client_t *client, void *ref, lwmqtt_string_t str, lwmqtt_message_t msg, + lwmqtt_serialized_properties_t props); /** * The client object. */ struct lwmqtt_client_t { + lwmqtt_protocol_t protocol; + uint16_t last_packet_id; uint32_t keep_alive_interval; bool pong_pending; @@ -180,6 +265,8 @@ struct lwmqtt_client_t { void lwmqtt_init(lwmqtt_client_t *client, uint8_t *write_buf, size_t write_buf_size, uint8_t *read_buf, size_t read_buf_size); +void lwmqtt_set_protocol(lwmqtt_client_t *client, lwmqtt_protocol_t prot); + /** * Will set the network reference and callbacks for this client object. * @@ -229,13 +316,14 @@ typedef struct { lwmqtt_qos_t qos; bool retained; lwmqtt_string_t payload; + lwmqtt_properties_t properties; } lwmqtt_will_t; /** * The default initializer for the will object. */ #define lwmqtt_default_will \ - { lwmqtt_default_string, LWMQTT_QOS0, false, lwmqtt_default_string } + { lwmqtt_default_string, LWMQTT_QOS0, false, lwmqtt_default_string, lwmqtt_empty_props } /** * The object containing the connection options for a client. @@ -246,13 +334,14 @@ typedef struct { bool clean_session; lwmqtt_string_t username; lwmqtt_string_t password; + lwmqtt_properties_t properties; } lwmqtt_options_t; /** * The default initializer for the options object. */ #define lwmqtt_default_options \ - { lwmqtt_default_string, 60, true, lwmqtt_default_string, lwmqtt_default_string } + { lwmqtt_default_string, 60, true, lwmqtt_default_string, lwmqtt_default_string, lwmqtt_empty_props } /** * The available return codes transported by the connack packet. @@ -295,7 +384,8 @@ lwmqtt_err_t lwmqtt_connect(lwmqtt_client_t *client, lwmqtt_options_t options, l * @param timeout - The command timeout. * @return An error value. */ -lwmqtt_err_t lwmqtt_publish(lwmqtt_client_t *client, lwmqtt_string_t topic, lwmqtt_message_t msg, uint32_t timeout); +lwmqtt_err_t lwmqtt_publish(lwmqtt_client_t *client, lwmqtt_string_t topic, lwmqtt_message_t msg, + lwmqtt_properties_t props, uint32_t timeout); /** * Will send a subscribe packet with multiple topic filters plus QOS levels and wait for the suback to complete. @@ -305,12 +395,12 @@ lwmqtt_err_t lwmqtt_publish(lwmqtt_client_t *client, lwmqtt_string_t topic, lwmq * @param client - The client object. * @param count - The number of topic filters and QOS levels. * @param topic_filter - The list of topic filters. - * @param qos - The list of QOS levels. + * @param opts - The list of subscription options. * @param timeout - The command timeout. * @return An error value. */ -lwmqtt_err_t lwmqtt_subscribe(lwmqtt_client_t *client, int count, lwmqtt_string_t *topic_filter, lwmqtt_qos_t *qos, - uint32_t timeout); +lwmqtt_err_t lwmqtt_subscribe(lwmqtt_client_t *client, int count, lwmqtt_string_t *topic_filter, + lwmqtt_sub_options_t *opts, lwmqtt_properties_t props, uint32_t timeout); /** * Will send a subscribe packet with a single topic filter plus QOS level and wait for the suback to complete. @@ -319,12 +409,22 @@ lwmqtt_err_t lwmqtt_subscribe(lwmqtt_client_t *client, int count, lwmqtt_string_ * * @param client - The client object. * @param topic_filter - The topic filter. - * @param qos - The QOS level. + * @param qos - The subscription options. * @param timeout - The command timeout. * @return An error value. */ -lwmqtt_err_t lwmqtt_subscribe_one(lwmqtt_client_t *client, lwmqtt_string_t topic_filter, lwmqtt_qos_t qos, - uint32_t timeout); +lwmqtt_err_t lwmqtt_subscribe_one(lwmqtt_client_t *client, lwmqtt_string_t topic_filter, lwmqtt_sub_options_t opts, + lwmqtt_properties_t props, uint32_t timeout); + +typedef enum { + LWMQTT_UNSUB_SUCCESS = 0, + LWMQTT_UNSUB_NO_SUB_EXISTED = 0x11, + LWMQTT_UNSUB_UNSPECIFIED_ERROR = 0x80, + LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR = 0x83, + LWMQTT_UNSUB_NOT_AUTHORIZED = 0x87, + LWMQTT_UNSUB_TOPIC_FILTER_INVALID = 0x8f, + LWMQTT_UNSUB_PACKET_ID_IN_USE = 0x91, +} lwmqtt_unsubscribe_status_t; /** * Will send an unsubscribe packet with multiple topic filters and wait for the unsuback to complete. @@ -337,7 +437,8 @@ lwmqtt_err_t lwmqtt_subscribe_one(lwmqtt_client_t *client, lwmqtt_string_t topic * @param timeout - The command timeout. * @return An error value. */ -lwmqtt_err_t lwmqtt_unsubscribe(lwmqtt_client_t *client, int count, lwmqtt_string_t *topic_filter, uint32_t timeout); +lwmqtt_err_t lwmqtt_unsubscribe(lwmqtt_client_t *client, int count, lwmqtt_string_t *topic_filter, + lwmqtt_properties_t props, uint32_t timeout); /** * Will send an unsubscribe packet with a single topic filter and wait for the unsuback to complete. @@ -349,7 +450,8 @@ lwmqtt_err_t lwmqtt_unsubscribe(lwmqtt_client_t *client, int count, lwmqtt_strin * @param timeout - The command timeout. * @return An error value. */ -lwmqtt_err_t lwmqtt_unsubscribe_one(lwmqtt_client_t *client, lwmqtt_string_t topic_filter, uint32_t timeout); +lwmqtt_err_t lwmqtt_unsubscribe_one(lwmqtt_client_t *client, lwmqtt_string_t topic_filter, lwmqtt_properties_t props, + uint32_t timeout); /** * Will send a disconnect packet and finish the client. @@ -358,7 +460,7 @@ lwmqtt_err_t lwmqtt_unsubscribe_one(lwmqtt_client_t *client, lwmqtt_string_t top * @param timeout - The command timeout. * @return An error value. */ -lwmqtt_err_t lwmqtt_disconnect(lwmqtt_client_t *client, uint32_t timeout); +lwmqtt_err_t lwmqtt_disconnect(lwmqtt_client_t *client, uint8_t reason, lwmqtt_properties_t props, uint32_t timeout); /** * Will yield control to the client and receive incoming packets from the network. @@ -392,4 +494,14 @@ lwmqtt_err_t lwmqtt_yield(lwmqtt_client_t *client, size_t available, uint32_t ti */ lwmqtt_err_t lwmqtt_keep_alive(lwmqtt_client_t *client, uint32_t timeout); +typedef struct { + void (*byte_prop)(void *ref, lwmqtt_prop_t prop, uint8_t value); + void (*int16_prop)(void *ref, lwmqtt_prop_t prop, int16_t value); + void (*int32_prop)(void *ref, lwmqtt_prop_t prop, int32_t value); + void (*str_prop)(void *ref, lwmqtt_prop_t prop, lwmqtt_string_t value); + void (*user_prop)(void *ref, lwmqtt_string_t key, lwmqtt_string_t val); +} lwmqtt_property_callbacks_t; + +lwmqtt_err_t lwmqtt_property_visitor(void *ref, lwmqtt_serialized_properties_t props, lwmqtt_property_callbacks_t cb); + #endif // LWMQTT_H diff --git a/src/client.c b/src/client.c index 806ec74..4896913 100644 --- a/src/client.c +++ b/src/client.c @@ -5,6 +5,7 @@ void lwmqtt_init(lwmqtt_client_t *client, uint8_t *write_buf, size_t write_buf_s client->last_packet_id = 1; client->keep_alive_interval = 0; client->pong_pending = false; + client->protocol = LWMQTT_MQTT311; client->write_buf = write_buf; client->write_buf_size = write_buf_size; @@ -27,6 +28,8 @@ void lwmqtt_init(lwmqtt_client_t *client, uint8_t *write_buf, size_t write_buf_s client->overflow_counter = NULL; } +void lwmqtt_set_protocol(lwmqtt_client_t *client, lwmqtt_protocol_t prot) { client->protocol = prot; } + void lwmqtt_set_network(lwmqtt_client_t *client, void *ref, lwmqtt_network_read_t read, lwmqtt_network_write_t write) { client->network = ref; client->network_read = read; @@ -263,14 +266,16 @@ static lwmqtt_err_t lwmqtt_cycle(lwmqtt_client_t *client, size_t *read, lwmqtt_p uint16_t packet_id; lwmqtt_string_t topic; lwmqtt_message_t msg; - err = lwmqtt_decode_publish(client->read_buf, client->read_buf_size, &dup, &packet_id, &topic, &msg); + lwmqtt_serialized_properties_t props; + err = lwmqtt_decode_publish(client->read_buf, client->read_buf_size, client->protocol, &dup, &packet_id, &topic, + &msg, &props); if (err != LWMQTT_SUCCESS) { return err; } // call callback if set if (client->callback != NULL) { - client->callback(client, client->callback_ref, topic, msg); + client->callback(client, client->callback_ref, topic, msg, props); } // break early on qos zero @@ -288,7 +293,9 @@ static lwmqtt_err_t lwmqtt_cycle(lwmqtt_client_t *client, size_t *read, lwmqtt_p // encode ack packet size_t len; - err = lwmqtt_encode_ack(client->write_buf, client->write_buf_size, &len, ack_type, false, packet_id); + lwmqtt_properties_t ackprops = lwmqtt_empty_props; + err = lwmqtt_encode_ack(client->write_buf, client->write_buf_size, &len, client->protocol, ack_type, false, + packet_id, 0, ackprops); if (err != LWMQTT_SUCCESS) { return err; } @@ -307,14 +314,19 @@ static lwmqtt_err_t lwmqtt_cycle(lwmqtt_client_t *client, size_t *read, lwmqtt_p // decode pubrec packet bool dup; uint16_t packet_id; - err = lwmqtt_decode_ack(client->read_buf, client->read_buf_size, LWMQTT_PUBREC_PACKET, &dup, &packet_id); + uint8_t status; + lwmqtt_serialized_properties_t ackprops; + err = lwmqtt_decode_ack(client->read_buf, client->read_buf_size, client->protocol, LWMQTT_PUBREC_PACKET, &dup, + &packet_id, &status, &ackprops); if (err != LWMQTT_SUCCESS) { return err; } // encode pubrel packet size_t len; - err = lwmqtt_encode_ack(client->write_buf, client->write_buf_size, &len, LWMQTT_PUBREL_PACKET, 0, packet_id); + lwmqtt_properties_t props = lwmqtt_empty_props; + err = lwmqtt_encode_ack(client->write_buf, client->write_buf_size, &len, client->protocol, LWMQTT_PUBREL_PACKET, + 0, packet_id, 0, props); if (err != LWMQTT_SUCCESS) { return err; } @@ -333,14 +345,19 @@ static lwmqtt_err_t lwmqtt_cycle(lwmqtt_client_t *client, size_t *read, lwmqtt_p // decode pubrec packet bool dup; uint16_t packet_id; - err = lwmqtt_decode_ack(client->read_buf, client->read_buf_size, LWMQTT_PUBREL_PACKET, &dup, &packet_id); + uint8_t status; + lwmqtt_serialized_properties_t ackprops; + err = lwmqtt_decode_ack(client->read_buf, client->read_buf_size, client->protocol, LWMQTT_PUBREL_PACKET, &dup, + &packet_id, &status, &ackprops); if (err != LWMQTT_SUCCESS) { return err; } // encode pubcomp packet size_t len; - err = lwmqtt_encode_ack(client->write_buf, client->write_buf_size, &len, LWMQTT_PUBCOMP_PACKET, 0, packet_id); + lwmqtt_properties_t props = lwmqtt_empty_props; + err = lwmqtt_encode_ack(client->write_buf, client->write_buf_size, &len, client->protocol, LWMQTT_PUBCOMP_PACKET, + 0, packet_id, 0, props); if (err != LWMQTT_SUCCESS) { return err; } @@ -363,7 +380,9 @@ static lwmqtt_err_t lwmqtt_cycle(lwmqtt_client_t *client, size_t *read, lwmqtt_p } // handle all other packets - default: { break; } + default: { + break; + } } return LWMQTT_SUCCESS; @@ -429,7 +448,8 @@ lwmqtt_err_t lwmqtt_connect(lwmqtt_client_t *client, lwmqtt_options_t options, l // encode connect packet size_t len; - lwmqtt_err_t err = lwmqtt_encode_connect(client->write_buf, client->write_buf_size, &len, options, will); + lwmqtt_err_t err = + lwmqtt_encode_connect(client->write_buf, client->write_buf_size, &len, client->protocol, options, will); if (err != LWMQTT_SUCCESS) { return err; } @@ -451,7 +471,7 @@ lwmqtt_err_t lwmqtt_connect(lwmqtt_client_t *client, lwmqtt_options_t options, l // decode connack packet bool session_present; - err = lwmqtt_decode_connack(client->read_buf, client->read_buf_size, &session_present, return_code); + err = lwmqtt_decode_connack(client->read_buf, client->read_buf_size, client->protocol, &session_present, return_code); if (err != LWMQTT_SUCCESS) { return err; } @@ -464,15 +484,15 @@ lwmqtt_err_t lwmqtt_connect(lwmqtt_client_t *client, lwmqtt_options_t options, l return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_subscribe(lwmqtt_client_t *client, int count, lwmqtt_string_t *topic_filter, lwmqtt_qos_t *qos, - uint32_t timeout) { +lwmqtt_err_t lwmqtt_subscribe(lwmqtt_client_t *client, int count, lwmqtt_string_t *topic_filter, + lwmqtt_sub_options_t *opts, lwmqtt_properties_t props, uint32_t timeout) { // set command timer client->timer_set(client->command_timer, timeout); // encode subscribe packet size_t len; - lwmqtt_err_t err = lwmqtt_encode_subscribe(client->write_buf, client->write_buf_size, &len, - lwmqtt_get_next_packet_id(client), count, topic_filter, qos); + lwmqtt_err_t err = lwmqtt_encode_subscribe(client->write_buf, client->write_buf_size, &len, client->protocol, + lwmqtt_get_next_packet_id(client), count, topic_filter, opts, props); if (err != LWMQTT_SUCCESS) { return err; } @@ -496,13 +516,15 @@ lwmqtt_err_t lwmqtt_subscribe(lwmqtt_client_t *client, int count, lwmqtt_string_ int suback_count = 0; lwmqtt_qos_t granted_qos[count]; uint16_t packet_id; - err = lwmqtt_decode_suback(client->read_buf, client->read_buf_size, &packet_id, count, &suback_count, granted_qos); + err = lwmqtt_decode_suback(client->read_buf, client->read_buf_size, &packet_id, client->protocol, count, + &suback_count, granted_qos); if (err != LWMQTT_SUCCESS) { return err; } // check suback codes for (int i = 0; i < suback_count; i++) { + // TODO: Reverse this and just consider successes. if (granted_qos[i] == LWMQTT_QOS_FAILURE) { return LWMQTT_FAILED_SUBSCRIPTION; } @@ -511,19 +533,20 @@ lwmqtt_err_t lwmqtt_subscribe(lwmqtt_client_t *client, int count, lwmqtt_string_ return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_subscribe_one(lwmqtt_client_t *client, lwmqtt_string_t topic_filter, lwmqtt_qos_t qos, - uint32_t timeout) { - return lwmqtt_subscribe(client, 1, &topic_filter, &qos, timeout); +lwmqtt_err_t lwmqtt_subscribe_one(lwmqtt_client_t *client, lwmqtt_string_t topic_filter, lwmqtt_sub_options_t opts, + lwmqtt_properties_t props, uint32_t timeout) { + return lwmqtt_subscribe(client, 1, &topic_filter, &opts, props, timeout); } -lwmqtt_err_t lwmqtt_unsubscribe(lwmqtt_client_t *client, int count, lwmqtt_string_t *topic_filter, uint32_t timeout) { +lwmqtt_err_t lwmqtt_unsubscribe(lwmqtt_client_t *client, int count, lwmqtt_string_t *topic_filter, + lwmqtt_properties_t props, uint32_t timeout) { // set command timer client->timer_set(client->command_timer, timeout); // encode unsubscribe packet size_t len; - lwmqtt_err_t err = lwmqtt_encode_unsubscribe(client->write_buf, client->write_buf_size, &len, - lwmqtt_get_next_packet_id(client), count, topic_filter); + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(client->write_buf, client->write_buf_size, &len, client->protocol, + lwmqtt_get_next_packet_id(client), count, topic_filter, props); if (err != LWMQTT_SUCCESS) { return err; } @@ -544,22 +567,32 @@ lwmqtt_err_t lwmqtt_unsubscribe(lwmqtt_client_t *client, int count, lwmqtt_strin } // decode unsuback packet - bool dup; uint16_t packet_id; - err = lwmqtt_decode_ack(client->read_buf, client->read_buf_size, LWMQTT_UNSUBACK_PACKET, &dup, &packet_id); + int ret_count; + lwmqtt_unsubscribe_status_t statuses[count]; + err = lwmqtt_decode_unsuback(client->read_buf, client->read_buf_size, &packet_id, client->protocol, count, &ret_count, + statuses); if (err != LWMQTT_SUCCESS) { return err; } + for (int i = 0; i < ret_count; i++) { + if (statuses[i] != LWMQTT_UNSUB_SUCCESS) { + // TODO: It might be nice to bubble this up (or the properties?) + return LWMQTT_FAILED_UNSUBSCRIPTION; + } + } + return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_unsubscribe_one(lwmqtt_client_t *client, lwmqtt_string_t topic_filter, uint32_t timeout) { - return lwmqtt_unsubscribe(client, 1, &topic_filter, timeout); +lwmqtt_err_t lwmqtt_unsubscribe_one(lwmqtt_client_t *client, lwmqtt_string_t topic_filter, lwmqtt_properties_t props, + uint32_t timeout) { + return lwmqtt_unsubscribe(client, 1, &topic_filter, props, timeout); } lwmqtt_err_t lwmqtt_publish(lwmqtt_client_t *client, lwmqtt_string_t topic, lwmqtt_message_t message, - uint32_t timeout) { + lwmqtt_properties_t props, uint32_t timeout) { // set command timer client->timer_set(client->command_timer, timeout); @@ -571,8 +604,8 @@ lwmqtt_err_t lwmqtt_publish(lwmqtt_client_t *client, lwmqtt_string_t topic, lwmq // encode publish packet size_t len = 0; - lwmqtt_err_t err = - lwmqtt_encode_publish(client->write_buf, client->write_buf_size, &len, 0, packet_id, topic, message); + lwmqtt_err_t err = lwmqtt_encode_publish(client->write_buf, client->write_buf_size, &len, client->protocol, 0, + packet_id, topic, message, props); if (err != LWMQTT_SUCCESS) { return err; } @@ -607,7 +640,10 @@ lwmqtt_err_t lwmqtt_publish(lwmqtt_client_t *client, lwmqtt_string_t topic, lwmq // decode ack packet bool dup; - err = lwmqtt_decode_ack(client->read_buf, client->read_buf_size, ack_type, &dup, &packet_id); + uint8_t status; + lwmqtt_serialized_properties_t ackprops; + err = lwmqtt_decode_ack(client->read_buf, client->read_buf_size, client->protocol, ack_type, &dup, &packet_id, + &status, &ackprops); if (err != LWMQTT_SUCCESS) { return err; } @@ -615,24 +651,18 @@ lwmqtt_err_t lwmqtt_publish(lwmqtt_client_t *client, lwmqtt_string_t topic, lwmq return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_disconnect(lwmqtt_client_t *client, uint32_t timeout) { +lwmqtt_err_t lwmqtt_disconnect(lwmqtt_client_t *client, uint8_t reason, lwmqtt_properties_t props, uint32_t timeout) { // set command timer client->timer_set(client->command_timer, timeout); - // encode disconnect packet - size_t len; - lwmqtt_err_t err = lwmqtt_encode_zero(client->write_buf, client->write_buf_size, &len, LWMQTT_DISCONNECT_PACKET); - if (err != LWMQTT_SUCCESS) { - return err; - } - - // send disconnected packet - err = lwmqtt_send_packet_in_buffer(client, len); + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_disconnect(client->write_buf, client->write_buf_size, &len, client->protocol, reason, props); if (err != LWMQTT_SUCCESS) { return err; } - return LWMQTT_SUCCESS; + return lwmqtt_send_packet_in_buffer(client, len); } lwmqtt_err_t lwmqtt_keep_alive(lwmqtt_client_t *client, uint32_t timeout) { @@ -674,3 +704,119 @@ lwmqtt_err_t lwmqtt_keep_alive(lwmqtt_client_t *client, uint32_t timeout) { return LWMQTT_SUCCESS; } + +lwmqtt_err_t lwmqtt_property_visitor(void *ref, lwmqtt_serialized_properties_t props, lwmqtt_property_callbacks_t cb) { + uint8_t *p = props.start; + uint8_t *end = p + props.size; + lwmqtt_err_t err; + + while (p < end) { + uint8_t prop, bval; + uint16_t i16val; + uint32_t i32val; + lwmqtt_string_t strval, k, v; + err = lwmqtt_read_byte(&p, end, &prop); + if (err != LWMQTT_SUCCESS) { + return err; + } + + switch (prop) { + // one byte + case LWMQTT_PROP_PAYLOAD_FORMAT_INDICATOR: + case LWMQTT_PROP_REQUEST_PROBLEM_INFORMATION: + case LWMQTT_PROP_MAXIMUM_QOS: + case LWMQTT_PROP_RETAIN_AVAILABLE: + case LWMQTT_PROP_REQUEST_RESPONSE_INFORMATION: + case LWMQTT_PROP_WILDCARD_SUBSCRIPTION_AVAILABLE: + case LWMQTT_PROP_SUBSCRIPTION_IDENTIFIER_AVAILABLE: + case LWMQTT_PROP_SHARED_SUBSCRIPTION_AVAILABLE: + err = lwmqtt_read_byte(&p, end, &bval); + if (err != LWMQTT_SUCCESS) { + return err; + } + if (cb.byte_prop) { + cb.byte_prop(ref, prop, bval); + } + break; + + // two byte int + case LWMQTT_PROP_SERVER_KEEP_ALIVE: + case LWMQTT_PROP_RECEIVE_MAXIMUM: + case LWMQTT_PROP_TOPIC_ALIAS_MAXIMUM: + case LWMQTT_PROP_TOPIC_ALIAS: + err = lwmqtt_read_num(&p, end, &i16val); + if (err != LWMQTT_SUCCESS) { + return err; + } + if (cb.int16_prop) { + cb.int16_prop(ref, prop, i16val); + } + break; + + // 4 byte int + case LWMQTT_PROP_MESSAGE_EXPIRY_INTERVAL: + case LWMQTT_PROP_SESSION_EXPIRY_INTERVAL: + case LWMQTT_PROP_WILL_DELAY_INTERVAL: + case LWMQTT_PROP_MAXIMUM_PACKET_SIZE: + err = lwmqtt_read_num32(&p, end, &i32val); + if (err != LWMQTT_SUCCESS) { + return err; + } + if (cb.int32_prop) { + cb.int32_prop(ref, prop, i32val); + } + break; + + // Variable byte int + case LWMQTT_PROP_SUBSCRIPTION_IDENTIFIER: + err = lwmqtt_read_varnum(&p, end, &i32val); + if (err != LWMQTT_SUCCESS) { + return err; + } + if (cb.int32_prop) { + cb.int32_prop(ref, prop, i32val); + } + break; + + // UTF-8 string + case LWMQTT_PROP_CONTENT_TYPE: + case LWMQTT_PROP_RESPONSE_TOPIC: + case LWMQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER: + case LWMQTT_PROP_AUTHENTICATION_METHOD: + case LWMQTT_PROP_RESPONSE_INFORMATION: + case LWMQTT_PROP_SERVER_REFERENCE: + case LWMQTT_PROP_REASON_STRING: + + // Arbitrary blobs as the same encoding. + case LWMQTT_PROP_CORRELATION_DATA: + case LWMQTT_PROP_AUTHENTICATION_DATA: + err = lwmqtt_read_string(&p, end, &strval); + if (err != LWMQTT_SUCCESS) { + return err; + } + if (cb.str_prop) { + cb.str_prop(ref, prop, strval); + } + break; + + case LWMQTT_PROP_USER_PROPERTY: + err = lwmqtt_read_string(&p, end, &k); + if (err != LWMQTT_SUCCESS) { + return err; + } + err = lwmqtt_read_string(&p, end, &v); + if (err != LWMQTT_SUCCESS) { + return err; + } + if (cb.user_prop) { + cb.user_prop(ref, k, v); + } + break; + + default: + return LWMQTT_MISSING_OR_WRONG_PACKET; + } + } + + return LWMQTT_SUCCESS; +} diff --git a/src/helpers.c b/src/helpers.c index c3ae761..3229df7 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -83,6 +83,36 @@ lwmqtt_err_t lwmqtt_write_num(uint8_t **buf, const uint8_t *buf_end, uint16_t nu return LWMQTT_SUCCESS; } +lwmqtt_err_t lwmqtt_write_num32(uint8_t **buf, const uint8_t *buf_end, uint32_t num) { + // check buffer size + if ((size_t)(buf_end - (*buf)) < 4) { + return LWMQTT_BUFFER_TOO_SHORT; + } + + // write bytes + (*buf)[0] = (uint8_t)(num >> 24); + (*buf)[1] = (uint8_t)((num >> 16) & 0xff); + (*buf)[2] = (uint8_t)((num >> 8) & 0xff); + (*buf)[3] = (uint8_t)(num & 0xff); + + // adjust pointer + *buf += 4; + + return LWMQTT_SUCCESS; +} + +lwmqtt_err_t lwmqtt_read_num32(uint8_t **buf, const uint8_t *buf_end, uint32_t *num) { + if ((size_t)(buf_end - (*buf)) < 4) { + return LWMQTT_BUFFER_TOO_SHORT; + } + + // read four byte integer + *num = ((uint32_t)(*buf)[0] << 24) | ((uint32_t)(*buf)[1] << 16) | ((uint32_t)(*buf)[2] << 8) | (uint32_t)(*buf)[3]; + + *buf += 4; + return LWMQTT_SUCCESS; +} + lwmqtt_err_t lwmqtt_read_string(uint8_t **buf, const uint8_t *buf_end, lwmqtt_string_t *str) { // read length uint16_t len; @@ -249,3 +279,162 @@ lwmqtt_err_t lwmqtt_write_varnum(uint8_t **buf, const uint8_t *buf_end, uint32_t return LWMQTT_SUCCESS; } + +static lwmqtt_err_t write_prop(uint8_t **buf, const uint8_t *buf_end, lwmqtt_property_t prop) { + lwmqtt_err_t err = lwmqtt_write_byte(buf, buf_end, prop.prop); + if (err != LWMQTT_SUCCESS) { + return err; + } + + switch (prop.prop) { + // one byte + case LWMQTT_PROP_PAYLOAD_FORMAT_INDICATOR: + case LWMQTT_PROP_REQUEST_PROBLEM_INFORMATION: + case LWMQTT_PROP_MAXIMUM_QOS: + case LWMQTT_PROP_RETAIN_AVAILABLE: + case LWMQTT_PROP_REQUEST_RESPONSE_INFORMATION: + case LWMQTT_PROP_WILDCARD_SUBSCRIPTION_AVAILABLE: + case LWMQTT_PROP_SUBSCRIPTION_IDENTIFIER_AVAILABLE: + case LWMQTT_PROP_SHARED_SUBSCRIPTION_AVAILABLE: + return lwmqtt_write_byte(buf, buf_end, prop.value.byte); + + // two byte int + case LWMQTT_PROP_SERVER_KEEP_ALIVE: + case LWMQTT_PROP_RECEIVE_MAXIMUM: + case LWMQTT_PROP_TOPIC_ALIAS_MAXIMUM: + case LWMQTT_PROP_TOPIC_ALIAS: + return lwmqtt_write_num(buf, buf_end, prop.value.int16); + + // 4 byte int + case LWMQTT_PROP_MESSAGE_EXPIRY_INTERVAL: + case LWMQTT_PROP_SESSION_EXPIRY_INTERVAL: + case LWMQTT_PROP_WILL_DELAY_INTERVAL: + case LWMQTT_PROP_MAXIMUM_PACKET_SIZE: + return lwmqtt_write_num32(buf, buf_end, prop.value.int32); + + // Variable byte int + case LWMQTT_PROP_SUBSCRIPTION_IDENTIFIER: + return lwmqtt_write_varnum(buf, buf_end, prop.value.int32); + + // UTF-8 string + case LWMQTT_PROP_CONTENT_TYPE: + case LWMQTT_PROP_RESPONSE_TOPIC: + case LWMQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER: + case LWMQTT_PROP_AUTHENTICATION_METHOD: + case LWMQTT_PROP_RESPONSE_INFORMATION: + case LWMQTT_PROP_SERVER_REFERENCE: + case LWMQTT_PROP_REASON_STRING: + + // Arbitrary blobs as the same encoding. + case LWMQTT_PROP_CORRELATION_DATA: + case LWMQTT_PROP_AUTHENTICATION_DATA: + return lwmqtt_write_string(buf, buf_end, prop.value.str); + + case LWMQTT_PROP_USER_PROPERTY: + lwmqtt_write_string(buf, buf_end, prop.value.pair.k); + lwmqtt_write_string(buf, buf_end, prop.value.pair.v); + } + + return LWMQTT_SUCCESS; +} + +static size_t proplen(lwmqtt_property_t prop) { + int ll; + switch (prop.prop) { + // one byte + case LWMQTT_PROP_PAYLOAD_FORMAT_INDICATOR: + case LWMQTT_PROP_REQUEST_PROBLEM_INFORMATION: + case LWMQTT_PROP_MAXIMUM_QOS: + case LWMQTT_PROP_RETAIN_AVAILABLE: + case LWMQTT_PROP_REQUEST_RESPONSE_INFORMATION: + case LWMQTT_PROP_WILDCARD_SUBSCRIPTION_AVAILABLE: + case LWMQTT_PROP_SUBSCRIPTION_IDENTIFIER_AVAILABLE: + case LWMQTT_PROP_SHARED_SUBSCRIPTION_AVAILABLE: + return 2; + + // two byte int + case LWMQTT_PROP_SERVER_KEEP_ALIVE: + case LWMQTT_PROP_RECEIVE_MAXIMUM: + case LWMQTT_PROP_TOPIC_ALIAS_MAXIMUM: + case LWMQTT_PROP_TOPIC_ALIAS: + return 3; + + // 4 byte int + case LWMQTT_PROP_MESSAGE_EXPIRY_INTERVAL: + case LWMQTT_PROP_SESSION_EXPIRY_INTERVAL: + case LWMQTT_PROP_WILL_DELAY_INTERVAL: + case LWMQTT_PROP_MAXIMUM_PACKET_SIZE: + return 5; + + // Variable byte int + case LWMQTT_PROP_SUBSCRIPTION_IDENTIFIER: + lwmqtt_varnum_length(prop.value.int32, &ll); + return 1 + ll; + + // UTF-8 string + case LWMQTT_PROP_CONTENT_TYPE: + case LWMQTT_PROP_RESPONSE_TOPIC: + case LWMQTT_PROP_ASSIGNED_CLIENT_IDENTIFIER: + case LWMQTT_PROP_AUTHENTICATION_METHOD: + case LWMQTT_PROP_RESPONSE_INFORMATION: + case LWMQTT_PROP_SERVER_REFERENCE: + case LWMQTT_PROP_REASON_STRING: + + // Arbitrary blobs are the same encoding. + case LWMQTT_PROP_CORRELATION_DATA: + case LWMQTT_PROP_AUTHENTICATION_DATA: + return 3 + prop.value.str.len; + + case LWMQTT_PROP_USER_PROPERTY: + return 1 + 2 + prop.value.pair.k.len + 2 + prop.value.pair.v.len; + } + return 0; +} + +// Length of the properties, not including their length. +static size_t propsintlen(lwmqtt_properties_t props) { + uint32_t l = 0; + + for (int i = 0; i < props.len; i++) { + l += proplen(props.props[i]); + } + + return l; +} + +// Length of a properties set as it may appear on the wire (including +// the length of the length). +size_t lwmqtt_propslen(lwmqtt_protocol_t prot, lwmqtt_properties_t props) { + if (prot == LWMQTT_MQTT311) { + return 0; + } + + uint32_t l = propsintlen(props); + int ll; + // lwmqtt_err_t err = + lwmqtt_varnum_length(l, &ll); + + return l + ll; +} + +lwmqtt_err_t lwmqtt_write_props(uint8_t **buf, const uint8_t *buf_end, lwmqtt_protocol_t prot, + lwmqtt_properties_t props) { + if (prot == LWMQTT_MQTT311) { + return LWMQTT_SUCCESS; + } + + size_t len = propsintlen(props); + lwmqtt_err_t err = lwmqtt_write_varnum(buf, buf_end, len); + if (err != LWMQTT_SUCCESS) { + return err; + } + + for (int i = 0; i < props.len; i++) { + err = write_prop(buf, buf_end, props.props[i]); + if (err != LWMQTT_SUCCESS) { + return err; + } + } + + return LWMQTT_SUCCESS; +} diff --git a/src/helpers.h b/src/helpers.h index 4a62e66..a69fd59 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -65,6 +65,10 @@ lwmqtt_err_t lwmqtt_read_num(uint8_t **buf, const uint8_t *buf_end, uint16_t *nu */ lwmqtt_err_t lwmqtt_write_num(uint8_t **buf, const uint8_t *buf_end, uint16_t num); +lwmqtt_err_t lwmqtt_write_num32(uint8_t **buf, const uint8_t *buf_end, uint32_t num); + +lwmqtt_err_t lwmqtt_read_num32(uint8_t **buf, const uint8_t *buf_end, uint32_t *num); + /** * Reads a string from the specified buffer into the passed object. The pointer is incremented by the bytes read. * @@ -134,4 +138,9 @@ lwmqtt_err_t lwmqtt_read_varnum(uint8_t **buf, const uint8_t *buf_end, uint32_t */ lwmqtt_err_t lwmqtt_write_varnum(uint8_t **buf, const uint8_t *buf_end, uint32_t varnum); +size_t lwmqtt_propslen(lwmqtt_protocol_t prot, lwmqtt_properties_t props); + +lwmqtt_err_t lwmqtt_write_props(uint8_t **buf, const uint8_t *buf_end, lwmqtt_protocol_t prot, + lwmqtt_properties_t props); + #endif diff --git a/src/packet.c b/src/packet.c index 512b44d..ed4bd6c 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1,5 +1,8 @@ #include "packet.h" +static lwmqtt_err_t decode_props(uint8_t **buf, const uint8_t *buf_len, lwmqtt_protocol_t protocol, + lwmqtt_serialized_properties_t *props); + lwmqtt_err_t lwmqtt_detect_packet_type(uint8_t *buf, size_t buf_len, lwmqtt_packet_type_t *packet_type) { // set default packet type *packet_type = LWMQTT_NO_PACKET; @@ -55,14 +58,14 @@ lwmqtt_err_t lwmqtt_detect_remaining_length(uint8_t *buf, size_t buf_len, uint32 return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_options_t options, - lwmqtt_will_t *will) { +lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, + lwmqtt_options_t options, lwmqtt_will_t *will) { // prepare pointers uint8_t *buf_ptr = buf; uint8_t *buf_end = buf + buf_len; // fixed header is 10 - uint32_t rem_len = 10; + uint32_t rem_len = 10 + lwmqtt_propslen(protocol, options.properties); // add client id to remaining length rem_len += options.client_id.len + 2; @@ -70,16 +73,17 @@ lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lw // add will if present to remaining length if (will != NULL) { rem_len += will->topic.len + 2 + will->payload.len + 2; + rem_len += lwmqtt_propslen(protocol, will->properties); } // add username if present to remaining length if (options.username.len > 0) { rem_len += options.username.len + 2; + } - // add password if present to remaining length - if (options.password.len > 0) { - rem_len += options.password.len + 2; - } + // add password if present to remaining length + if ((options.username.len > 0 || protocol == LWMQTT_MQTT5) && options.password.len > 0) { + rem_len += options.password.len + 2; } // check remaining length length @@ -112,7 +116,7 @@ lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lw } // write version number - err = lwmqtt_write_byte(&buf_ptr, buf_end, 4); + err = lwmqtt_write_byte(&buf_ptr, buf_end, protocol == LWMQTT_MQTT311 ? 4 : 5); if (err != LWMQTT_SUCCESS) { return err; } @@ -133,11 +137,10 @@ lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lw // set username flag if present if (options.username.len > 0) { lwmqtt_write_bits(&flags, 1, 7, 1); + } - // set password flag if present - if (options.password.len > 0) { - lwmqtt_write_bits(&flags, 1, 6, 1); - } + if ((options.username.len > 0 || protocol == LWMQTT_MQTT5) && options.password.len > 0) { + lwmqtt_write_bits(&flags, 1, 6, 1); } // write flags @@ -152,6 +155,12 @@ lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lw return err; } + // write connection properties + err = lwmqtt_write_props(&buf_ptr, buf_end, protocol, options.properties); + if (err != LWMQTT_SUCCESS) { + return err; + } + // write client id err = lwmqtt_write_string(&buf_ptr, buf_end, options.client_id); if (err != LWMQTT_SUCCESS) { @@ -160,6 +169,11 @@ lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lw // write will if present if (will != NULL) { + err = lwmqtt_write_props(&buf_ptr, buf_end, protocol, will->properties); + if (err != LWMQTT_SUCCESS) { + return err; + } + // write topic err = lwmqtt_write_string(&buf_ptr, buf_end, will->topic); if (err != LWMQTT_SUCCESS) { @@ -188,7 +202,7 @@ lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lw } // write password if present - if (options.username.len > 0 && options.password.len > 0) { + if ((options.username.len > 0 || protocol == LWMQTT_MQTT5) && options.password.len > 0) { err = lwmqtt_write_string(&buf_ptr, buf_end, options.password); if (err != LWMQTT_SUCCESS) { return err; @@ -201,7 +215,7 @@ lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lw return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, bool *session_present, +lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, lwmqtt_protocol_t protocol, bool *session_present, lwmqtt_return_code_t *return_code) { // prepare pointers uint8_t *buf_ptr = buf; @@ -227,7 +241,7 @@ lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, bool *session_p } // check remaining length - if (rem_len != 2) { + if (protocol == LWMQTT_MQTT311 && rem_len != 2) { return LWMQTT_REMAINING_LENGTH_MISMATCH; } @@ -300,12 +314,16 @@ lwmqtt_err_t lwmqtt_encode_zero(uint8_t *buf, size_t buf_len, size_t *len, lwmqt return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_decode_ack(uint8_t *buf, size_t buf_len, lwmqtt_packet_type_t packet_type, bool *dup, - uint16_t *packet_id) { +lwmqtt_err_t lwmqtt_decode_ack(uint8_t *buf, size_t buf_len, lwmqtt_protocol_t protocol, + lwmqtt_packet_type_t packet_type, bool *dup, uint16_t *packet_id, uint8_t *status, + lwmqtt_serialized_properties_t *props) { // prepare pointer uint8_t *buf_ptr = buf; uint8_t *buf_end = buf + buf_len; + *status = 0; + props->size = 0; + // read header uint8_t header = 0; lwmqtt_err_t err = lwmqtt_read_byte(&buf_ptr, buf_end, &header); @@ -329,7 +347,7 @@ lwmqtt_err_t lwmqtt_decode_ack(uint8_t *buf, size_t buf_len, lwmqtt_packet_type_ } // check remaining length - if (rem_len != 2) { + if (protocol == LWMQTT_MQTT311 && rem_len != 2) { return LWMQTT_REMAINING_LENGTH_MISMATCH; } @@ -339,11 +357,33 @@ lwmqtt_err_t lwmqtt_decode_ack(uint8_t *buf, size_t buf_len, lwmqtt_packet_type_ return err; } + rem_len -= 2; + + if (rem_len > 0) { + lwmqtt_err_t err = lwmqtt_read_byte(&buf_ptr, buf_end, status); + if (err != LWMQTT_SUCCESS) { + return err; + } + rem_len--; + } + + if (rem_len > 0) { + err = decode_props(&buf_ptr, buf_end, protocol, props); + if (err != LWMQTT_SUCCESS) { + return err; + } + } + + if (*status != 0) { + return LWMQTT_PUBACK_NACKED; + } + return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_encode_ack(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_packet_type_t packet_type, bool dup, - uint16_t packet_id) { +lwmqtt_err_t lwmqtt_encode_ack(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, + lwmqtt_packet_type_t packet_type, bool dup, uint16_t packet_id, uint8_t status, + lwmqtt_properties_t props) { // prepare pointer uint8_t *buf_ptr = buf; uint8_t *buf_end = buf + buf_len; @@ -366,8 +406,13 @@ lwmqtt_err_t lwmqtt_encode_ack(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt return err; } + size_t rem_len = 2 + (protocol == LWMQTT_MQTT5 ? 1 : 0); + if (props.len > 0) { + rem_len += lwmqtt_propslen(protocol, props); + } + // write remaining length - err = lwmqtt_write_varnum(&buf_ptr, buf_end, 2); + err = lwmqtt_write_varnum(&buf_ptr, buf_end, rem_len); if (err != LWMQTT_SUCCESS) { return err; } @@ -378,14 +423,46 @@ lwmqtt_err_t lwmqtt_encode_ack(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt return err; } + if (protocol == LWMQTT_MQTT5) { + err = lwmqtt_write_byte(&buf_ptr, buf_end, status); + if (err != LWMQTT_SUCCESS) { + return err; + } + } + + if (props.len > 0) { + err = lwmqtt_write_props(&buf_ptr, buf_end, protocol, props); + if (err != LWMQTT_SUCCESS) { + return err; + } + } + // set written length *len = buf_ptr - buf; return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, bool *dup, uint16_t *packet_id, lwmqtt_string_t *topic, - lwmqtt_message_t *msg) { +static lwmqtt_err_t decode_props(uint8_t **buf, const uint8_t *buf_len, lwmqtt_protocol_t protocol, + lwmqtt_serialized_properties_t *props) { + if (protocol == LWMQTT_MQTT311) { + return LWMQTT_SUCCESS; + } + uint32_t prop_len; + lwmqtt_err_t err = lwmqtt_read_varnum(buf, buf_len, &prop_len); + if (err != LWMQTT_SUCCESS) { + return err; + } + props->size = (size_t)prop_len; + props->start = *buf; + + *buf += prop_len; + return LWMQTT_SUCCESS; +} + +lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, lwmqtt_protocol_t protocol, bool *dup, + uint16_t *packet_id, lwmqtt_string_t *topic, lwmqtt_message_t *msg, + lwmqtt_serialized_properties_t *props) { // prepare pointer uint8_t *buf_ptr = buf; uint8_t *buf_end = buf + buf_len; @@ -460,6 +537,11 @@ lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, bool *dup, uint *packet_id = 0; } + err = decode_props(&buf_ptr, buf_end, protocol, props); + if (err != LWMQTT_SUCCESS) { + return err; + } + // set payload length msg->payload_len = buf_end - buf_ptr; @@ -472,14 +554,15 @@ lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, bool *dup, uint return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_encode_publish(uint8_t *buf, size_t buf_len, size_t *len, bool dup, uint16_t packet_id, - lwmqtt_string_t topic, lwmqtt_message_t msg) { +lwmqtt_err_t lwmqtt_encode_publish(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, bool dup, + uint16_t packet_id, lwmqtt_string_t topic, lwmqtt_message_t msg, + lwmqtt_properties_t props) { // prepare pointer uint8_t *buf_ptr = buf; uint8_t *buf_end = buf + buf_len; // calculate remaining length - uint32_t rem_len = 2 + topic.len + (uint32_t)msg.payload_len; + uint32_t rem_len = 2 + topic.len + (uint32_t)msg.payload_len + lwmqtt_propslen(protocol, props); if (msg.qos > 0) { rem_len += 2; } @@ -532,6 +615,11 @@ lwmqtt_err_t lwmqtt_encode_publish(uint8_t *buf, size_t buf_len, size_t *len, bo } } + err = lwmqtt_write_props(&buf_ptr, buf_end, protocol, props); + if (err != LWMQTT_SUCCESS) { + return err; + } + // write payload err = lwmqtt_write_data(&buf_ptr, buf_end, msg.payload, msg.payload_len); if (err != LWMQTT_SUCCESS) { @@ -544,14 +632,20 @@ lwmqtt_err_t lwmqtt_encode_publish(uint8_t *buf, size_t buf_len, size_t *len, bo return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_encode_subscribe(uint8_t *buf, size_t buf_len, size_t *len, uint16_t packet_id, int count, - lwmqtt_string_t *topic_filters, lwmqtt_qos_t *qos_levels) { +static uint8_t encode_sub_opt(lwmqtt_sub_options_t opt) { + return (uint8_t)opt.qos | ((uint8_t)opt.retain_handling << 4) | (opt.retain_as_published ? 0x08 : 0) | + (opt.no_local ? 0x04 : 0); +} + +lwmqtt_err_t lwmqtt_encode_subscribe(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, + uint16_t packet_id, int count, lwmqtt_string_t *topic_filters, + lwmqtt_sub_options_t *sub_options, lwmqtt_properties_t props) { // prepare pointer uint8_t *buf_ptr = buf; uint8_t *buf_end = buf + buf_len; // calculate remaining length - uint32_t rem_len = 2; + uint32_t rem_len = 2 + lwmqtt_propslen(protocol, props); for (int i = 0; i < count; i++) { rem_len += 2 + topic_filters[i].len + 1; } @@ -590,6 +684,11 @@ lwmqtt_err_t lwmqtt_encode_subscribe(uint8_t *buf, size_t buf_len, size_t *len, return err; } + err = lwmqtt_write_props(&buf_ptr, buf_end, protocol, props); + if (err != LWMQTT_SUCCESS) { + return err; + } + // write all subscriptions for (int i = 0; i < count; i++) { // write topic @@ -598,8 +697,8 @@ lwmqtt_err_t lwmqtt_encode_subscribe(uint8_t *buf, size_t buf_len, size_t *len, return err; } - // write qos level - err = lwmqtt_write_byte(&buf_ptr, buf_end, (uint8_t)qos_levels[i]); + // write subscription options + err = lwmqtt_write_byte(&buf_ptr, buf_end, encode_sub_opt(sub_options[i])); if (err != LWMQTT_SUCCESS) { return err; } @@ -611,8 +710,8 @@ lwmqtt_err_t lwmqtt_encode_subscribe(uint8_t *buf, size_t buf_len, size_t *len, return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet_id, int max_count, int *count, - lwmqtt_qos_t *granted_qos_levels) { +lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet_id, lwmqtt_protocol_t protocol, + int max_count, int *count, lwmqtt_qos_t *granted_qos_levels) { // prepare pointer uint8_t *buf_ptr = buf; uint8_t *buf_end = buf + buf_len; @@ -635,6 +734,7 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet if (err != LWMQTT_SUCCESS) { return err; } + uint8_t *end = buf_ptr + rem_len; // check remaining length (packet id + min. one suback code) if (rem_len < 3) { @@ -647,8 +747,14 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet return err; } + lwmqtt_serialized_properties_t props; + err = decode_props(&buf_ptr, buf_end, protocol, &props); + if (err != LWMQTT_SUCCESS) { + return err; + } + // read all suback codes - for (*count = 0; *count < (int)rem_len - 2; (*count)++) { + for (*count = 0; buf_ptr < end; (*count)++) { // check max count if (*count > max_count) { return LWMQTT_SUBACK_ARRAY_OVERFLOW; @@ -673,7 +779,7 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet granted_qos_levels[*count] = LWMQTT_QOS2; break; default: - granted_qos_levels[*count] = LWMQTT_QOS_FAILURE; + granted_qos_levels[*count] = protocol == LWMQTT_MQTT311 ? 0x80 : (lwmqtt_qos_t)raw_qos_level; break; } } @@ -681,14 +787,80 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet return LWMQTT_SUCCESS; } -lwmqtt_err_t lwmqtt_encode_unsubscribe(uint8_t *buf, size_t buf_len, size_t *len, uint16_t packet_id, int count, - lwmqtt_string_t *topic_filters) { +lwmqtt_err_t lwmqtt_decode_unsuback(uint8_t *buf, size_t buf_len, uint16_t *packet_id, lwmqtt_protocol_t protocol, + int max_count, int *count, lwmqtt_unsubscribe_status_t *statuses) { + // prepare pointer + uint8_t *buf_ptr = buf; + uint8_t *buf_end = buf + buf_len; + + // read header + uint8_t header; + lwmqtt_err_t err = lwmqtt_read_byte(&buf_ptr, buf_end, &header); + if (err != LWMQTT_SUCCESS) { + return err; + } + + // check packet type + if (lwmqtt_read_bits(header, 4, 4) != LWMQTT_UNSUBACK_PACKET) { + return LWMQTT_MISSING_OR_WRONG_PACKET; + } + + // read remaining length + uint32_t rem_len; + err = lwmqtt_read_varnum(&buf_ptr, buf_end, &rem_len); + if (err != LWMQTT_SUCCESS) { + return err; + } + uint8_t *end = buf_ptr + rem_len; + + // read packet id + err = lwmqtt_read_num(&buf_ptr, buf_end, packet_id); + if (err != LWMQTT_SUCCESS) { + return err; + } + + if (protocol == LWMQTT_MQTT311) { + for (int i = 0; i < max_count; i++) { + statuses[i] = LWMQTT_UNSUB_SUCCESS; + } + *count = max_count; + return LWMQTT_SUCCESS; + } + + lwmqtt_serialized_properties_t props = {0, 0}; + err = decode_props(&buf_ptr, buf_end, protocol, &props); + if (err != LWMQTT_SUCCESS) { + return err; + } + + // read all suback codes + for (*count = 0; buf_ptr < end; (*count)++) { + // check max count + if (*count > max_count) { + return LWMQTT_SUBACK_ARRAY_OVERFLOW; + } + + // read qos level + uint8_t st; + err = lwmqtt_read_byte(&buf_ptr, buf_end, &st); + if (err != LWMQTT_SUCCESS) { + return err; + } + statuses[*count] = (lwmqtt_unsubscribe_status_t)st; + } + + return LWMQTT_SUCCESS; +} + +lwmqtt_err_t lwmqtt_encode_unsubscribe(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, + uint16_t packet_id, int count, lwmqtt_string_t *topic_filters, + lwmqtt_properties_t props) { // prepare pointer uint8_t *buf_ptr = buf; uint8_t *buf_end = buf + buf_len; // calculate remaining length - uint32_t rem_len = 2; + uint32_t rem_len = 2 + lwmqtt_propslen(protocol, props); for (int i = 0; i < count; i++) { rem_len += 2 + topic_filters[i].len; } @@ -727,6 +899,11 @@ lwmqtt_err_t lwmqtt_encode_unsubscribe(uint8_t *buf, size_t buf_len, size_t *len return err; } + err = lwmqtt_write_props(&buf_ptr, buf_end, protocol, props); + if (err != LWMQTT_SUCCESS) { + return err; + } + // write topics for (int i = 0; i < count; i++) { err = lwmqtt_write_string(&buf_ptr, buf_end, topic_filters[i]); @@ -740,3 +917,41 @@ lwmqtt_err_t lwmqtt_encode_unsubscribe(uint8_t *buf, size_t buf_len, size_t *len return LWMQTT_SUCCESS; } + +lwmqtt_err_t lwmqtt_encode_disconnect(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, + uint8_t reason, lwmqtt_properties_t props) { + uint8_t *buf_ptr = buf; + uint8_t *buf_end = buf_ptr + buf_len; + + uint8_t header = 0; + lwmqtt_write_bits(&header, LWMQTT_DISCONNECT_PACKET, 4, 4); + lwmqtt_err_t err = lwmqtt_write_byte(&buf_ptr, buf_end, header); + if (err != LWMQTT_SUCCESS) { + return err; + } + + uint32_t rem_len = 0; + if (protocol == LWMQTT_MQTT5) { + rem_len = 1 + lwmqtt_propslen(protocol, props); + } + + err = lwmqtt_write_varnum(&buf_ptr, buf_end, rem_len); + if (err != LWMQTT_SUCCESS) { + return err; + } + + if (protocol == LWMQTT_MQTT5) { + err = lwmqtt_write_byte(&buf_ptr, buf_end, reason); + if (err != LWMQTT_SUCCESS) { + return err; + } + + err = lwmqtt_write_props(&buf_ptr, buf_end, protocol, props); + if (err != LWMQTT_SUCCESS) { + return err; + } + } + + *len = buf_ptr - buf; + return LWMQTT_SUCCESS; +} diff --git a/src/packet.h b/src/packet.h index 5fe9e50..70b7ad0 100644 --- a/src/packet.h +++ b/src/packet.h @@ -53,27 +53,29 @@ lwmqtt_err_t lwmqtt_detect_remaining_length(uint8_t *buf, size_t buf_len, uint32 * @param buf - The buffer into which the packet will be encoded. * @param buf_len - The length of the specified buffer. * @param len - The encoded length of the packet. + * @param protocol - The MQTT protocol to use for this connection. * @param options - The options to be used to build the connect packet. * @param will - The last will and testament. * @return An error value. */ -lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_options_t options, - lwmqtt_will_t *will); +lwmqtt_err_t lwmqtt_encode_connect(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, + lwmqtt_options_t options, lwmqtt_will_t *will); /** * Decodes a connack packet from the supplied buffer. * * @param buf - The raw buffer data. * @param buf_len - The length of the specified buffer. + * @param protocol - The protocol to parse the decode as. * @param session_present - The session present flag. * @param return_code - The return code. * @return An error value. */ -lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, bool *session_present, +lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, lwmqtt_protocol_t protocol, bool *session_present, lwmqtt_return_code_t *return_code); /** - * Encodes a zero (disconnect, pingreq) packet into the supplied buffer. + * Encodes a zero (pingreq) packet into the supplied buffer. * * @param buf - The buffer into which the packet will be encoded. * @param buf_len - The length of the specified buffer. @@ -83,6 +85,9 @@ lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, bool *session_p */ lwmqtt_err_t lwmqtt_encode_zero(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_packet_type_t packet_type); +lwmqtt_err_t lwmqtt_encode_disconnect(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, + uint8_t reason, lwmqtt_properties_t props); + /** * Decodes an ack (puback, pubrec, pubrel, pubcomp, unsuback) packet from the supplied buffer. * @@ -93,8 +98,9 @@ lwmqtt_err_t lwmqtt_encode_zero(uint8_t *buf, size_t buf_len, size_t *len, lwmqt * @param packet_id - The packet id. * @return An error value. */ -lwmqtt_err_t lwmqtt_decode_ack(uint8_t *buf, size_t buf_len, lwmqtt_packet_type_t packet_type, bool *dup, - uint16_t *packet_id); +lwmqtt_err_t lwmqtt_decode_ack(uint8_t *buf, size_t buf_len, lwmqtt_protocol_t protocol, + lwmqtt_packet_type_t packet_type, bool *dup, uint16_t *packet_id, uint8_t *status, + lwmqtt_serialized_properties_t *props); /** * Encodes an ack (puback, pubrec, pubrel, pubcomp) packet into the supplied buffer. @@ -107,8 +113,9 @@ lwmqtt_err_t lwmqtt_decode_ack(uint8_t *buf, size_t buf_len, lwmqtt_packet_type_ * @param packet_id - The packet id. * @return An error value. */ -lwmqtt_err_t lwmqtt_encode_ack(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_packet_type_t packet_type, bool dup, - uint16_t packet_id); +lwmqtt_err_t lwmqtt_encode_ack(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, + lwmqtt_packet_type_t packet_type, bool dup, uint16_t packet_id, uint8_t status, + lwmqtt_properties_t props); /** * Decodes a publish packet from the supplied buffer. @@ -121,8 +128,9 @@ lwmqtt_err_t lwmqtt_encode_ack(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt * @parma msg - The message. * @return An error value. */ -lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, bool *dup, uint16_t *packet_id, lwmqtt_string_t *topic, - lwmqtt_message_t *msg); +lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, lwmqtt_protocol_t protocol, bool *dup, + uint16_t *packet_id, lwmqtt_string_t *topic, lwmqtt_message_t *msg, + lwmqtt_serialized_properties_t *props); /** * Encodes a publish packet into the supplied buffer. @@ -136,8 +144,9 @@ lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, bool *dup, uint * @param msg - The message. * @return An error value. */ -lwmqtt_err_t lwmqtt_encode_publish(uint8_t *buf, size_t buf_len, size_t *len, bool dup, uint16_t packet_id, - lwmqtt_string_t topic, lwmqtt_message_t msg); +lwmqtt_err_t lwmqtt_encode_publish(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, bool dup, + uint16_t packet_id, lwmqtt_string_t topic, lwmqtt_message_t msg, + lwmqtt_properties_t props); /** * Encodes a subscribe packet into the supplied buffer. @@ -148,11 +157,12 @@ lwmqtt_err_t lwmqtt_encode_publish(uint8_t *buf, size_t buf_len, size_t *len, bo * @param packet_id - The packet id. * @param count - The number of members in the topic_filters and qos_levels array. * @param topic_filters - The array of topic filter. - * @param qos_levels - The array of requested QoS levels. + * @param sub_options - The array of requested subscription options. * @return An error value. */ -lwmqtt_err_t lwmqtt_encode_subscribe(uint8_t *buf, size_t buf_len, size_t *len, uint16_t packet_id, int count, - lwmqtt_string_t *topic_filters, lwmqtt_qos_t *qos_levels); +lwmqtt_err_t lwmqtt_encode_subscribe(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t prototocol, + uint16_t packet_id, int count, lwmqtt_string_t *topic_filters, + lwmqtt_sub_options_t *sub_options, lwmqtt_properties_t props); /** * Decodes a suback packet from the supplied buffer. @@ -165,8 +175,11 @@ lwmqtt_err_t lwmqtt_encode_subscribe(uint8_t *buf, size_t buf_len, size_t *len, * @param granted_qos_levels - The granted QoS levels. * @return An error value. */ -lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet_id, int max_count, int *count, - lwmqtt_qos_t *granted_qos_levels); +lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet_id, lwmqtt_protocol_t protocol, + int max_count, int *count, lwmqtt_qos_t *granted_qos_levels); + +lwmqtt_err_t lwmqtt_decode_unsuback(uint8_t *buf, size_t buf_len, uint16_t *packet_id, lwmqtt_protocol_t protocol, + int max_count, int *count, lwmqtt_unsubscribe_status_t *statuses); /** * Encodes the supplied unsubscribe data into the supplied buffer, ready for sending @@ -179,7 +192,8 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet * @param topic_filters - The array of topic filters. * @return An error value. */ -lwmqtt_err_t lwmqtt_encode_unsubscribe(uint8_t *buf, size_t buf_len, size_t *len, uint16_t packet_id, int count, - lwmqtt_string_t *topic_filters); +lwmqtt_err_t lwmqtt_encode_unsubscribe(uint8_t *buf, size_t buf_len, size_t *len, lwmqtt_protocol_t protocol, + uint16_t packet_id, int count, lwmqtt_string_t *topic_filters, + lwmqtt_properties_t props); #endif // LWMQTT_PACKET_H diff --git a/tests/client.cpp b/tests/client.cpp index a90e43b..d312647 100644 --- a/tests/client.cpp +++ b/tests/client.cpp @@ -17,7 +17,10 @@ volatile int counter; const char *custom_ref = "cool"; -static void message_arrived(lwmqtt_client_t *c, void *ref, lwmqtt_string_t t, lwmqtt_message_t m) { +static lwmqtt_properties_t empty_props = lwmqtt_empty_props; + +static void message_arrived(lwmqtt_client_t *c, void *ref, lwmqtt_string_t t, lwmqtt_message_t m, + lwmqtt_serialized_properties_t props) { ASSERT_EQ(ref, custom_ref); int res = lwmqtt_strcmp(t, "lwmqtt"); @@ -30,7 +33,8 @@ static void message_arrived(lwmqtt_client_t *c, void *ref, lwmqtt_string_t t, lw counter++; } -static void big_message_arrived(lwmqtt_client_t *c, void *ref, lwmqtt_string_t t, lwmqtt_message_t m) { +static void big_message_arrived(lwmqtt_client_t *c, void *ref, lwmqtt_string_t t, lwmqtt_message_t m, + lwmqtt_serialized_properties_t props) { ASSERT_EQ(ref, custom_ref); int res = lwmqtt_strcmp(t, "lwmqtt"); @@ -67,7 +71,8 @@ TEST(Client, PublishSubscribeQOS0) { err = lwmqtt_connect(&client, data, nullptr, &return_code, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), LWMQTT_QOS0, COMMAND_TIMEOUT); + lwmqtt_sub_options_t subopts = lwmqtt_default_sub_options; + err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), subopts, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); counter = 0; @@ -78,7 +83,7 @@ TEST(Client, PublishSubscribeQOS0) { msg.payload = payload; msg.payload_len = PAYLOAD_LEN; - err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, COMMAND_TIMEOUT); + err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); } @@ -93,10 +98,10 @@ TEST(Client, PublishSubscribeQOS0) { } } - err = lwmqtt_unsubscribe_one(&client, lwmqtt_string("lwmqtt"), COMMAND_TIMEOUT); + err = lwmqtt_unsubscribe_one(&client, lwmqtt_string("lwmqtt"), empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_disconnect(&client, COMMAND_TIMEOUT); + err = lwmqtt_disconnect(&client, 0, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); lwmqtt_unix_network_disconnect(&network); @@ -126,7 +131,9 @@ TEST(Client, PublishSubscribeQOS1) { err = lwmqtt_connect(&client, options, nullptr, &return_code, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), LWMQTT_QOS1, COMMAND_TIMEOUT); + lwmqtt_sub_options_t subopts = lwmqtt_default_sub_options; + subopts.qos = LWMQTT_QOS1; + err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), subopts, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); counter = 0; @@ -137,7 +144,7 @@ TEST(Client, PublishSubscribeQOS1) { msg.payload = payload; msg.payload_len = PAYLOAD_LEN; - err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, COMMAND_TIMEOUT); + err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); } @@ -152,10 +159,10 @@ TEST(Client, PublishSubscribeQOS1) { } } - err = lwmqtt_unsubscribe_one(&client, lwmqtt_string("lwmqtt"), COMMAND_TIMEOUT); + err = lwmqtt_unsubscribe_one(&client, lwmqtt_string("lwmqtt"), empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_disconnect(&client, COMMAND_TIMEOUT); + err = lwmqtt_disconnect(&client, 0, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); lwmqtt_unix_network_disconnect(&network); @@ -185,7 +192,9 @@ TEST(Client, PublishSubscribeQOS2) { err = lwmqtt_connect(&client, options, nullptr, &return_code, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), LWMQTT_QOS2, COMMAND_TIMEOUT); + lwmqtt_sub_options_t subopts = lwmqtt_default_sub_options; + subopts.qos = LWMQTT_QOS2; + err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), subopts, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); counter = 0; @@ -196,7 +205,7 @@ TEST(Client, PublishSubscribeQOS2) { msg.payload = payload; msg.payload_len = PAYLOAD_LEN; - err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, COMMAND_TIMEOUT); + err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); } @@ -211,10 +220,10 @@ TEST(Client, PublishSubscribeQOS2) { } } - err = lwmqtt_unsubscribe_one(&client, lwmqtt_string("lwmqtt"), COMMAND_TIMEOUT); + err = lwmqtt_unsubscribe_one(&client, lwmqtt_string("lwmqtt"), empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_disconnect(&client, COMMAND_TIMEOUT); + err = lwmqtt_disconnect(&client, 0, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); lwmqtt_unix_network_disconnect(&network); @@ -244,7 +253,8 @@ TEST(Client, BufferOverflow) { err = lwmqtt_connect(&client, options, nullptr, &return_code, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), LWMQTT_QOS0, COMMAND_TIMEOUT); + lwmqtt_sub_options_t subopts = lwmqtt_default_sub_options; + err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), subopts, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); lwmqtt_message_t msg = lwmqtt_default_message; @@ -252,7 +262,7 @@ TEST(Client, BufferOverflow) { msg.payload = big_payload; msg.payload_len = BIG_PAYLOAD_LEN; - err = lwmqtt_publish(&client, lwmqtt_string("error"), msg, COMMAND_TIMEOUT); + err = lwmqtt_publish(&client, lwmqtt_string("error"), msg, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_BUFFER_TOO_SHORT); counter = 0; @@ -262,7 +272,7 @@ TEST(Client, BufferOverflow) { msg.payload = payload; msg.payload_len = PAYLOAD_LEN; - err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, COMMAND_TIMEOUT); + err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); while (counter < 1) { @@ -277,7 +287,7 @@ TEST(Client, BufferOverflow) { } } - err = lwmqtt_disconnect(&client, COMMAND_TIMEOUT); + err = lwmqtt_disconnect(&client, 0, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); lwmqtt_unix_network_disconnect(&network); @@ -310,7 +320,8 @@ TEST(Client, OverflowDropping) { err = lwmqtt_connect(&client, options, nullptr, &return_code, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), LWMQTT_QOS0, COMMAND_TIMEOUT); + lwmqtt_sub_options_t subopts = lwmqtt_default_sub_options; + err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), subopts, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); counter = 0; @@ -320,10 +331,10 @@ TEST(Client, OverflowDropping) { msg.payload = payload; msg.payload_len = PAYLOAD_LEN; - err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, COMMAND_TIMEOUT); + err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, COMMAND_TIMEOUT); + err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); while (dropped < 2) { @@ -337,7 +348,7 @@ TEST(Client, OverflowDropping) { } } - err = lwmqtt_disconnect(&client, COMMAND_TIMEOUT); + err = lwmqtt_disconnect(&client, 0, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); ASSERT_EQ(counter, 0); @@ -370,7 +381,8 @@ TEST(Client, BigBuffersAndPayload) { err = lwmqtt_connect(&client, options, nullptr, &return_code, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), LWMQTT_QOS0, COMMAND_TIMEOUT); + lwmqtt_sub_options_t subopts = lwmqtt_default_sub_options; + err = lwmqtt_subscribe_one(&client, lwmqtt_string("lwmqtt"), subopts, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); counter = 0; @@ -381,7 +393,7 @@ TEST(Client, BigBuffersAndPayload) { msg.payload = big_payload; msg.payload_len = BIG_PAYLOAD_LEN; - err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, COMMAND_TIMEOUT); + err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); } @@ -396,10 +408,10 @@ TEST(Client, BigBuffersAndPayload) { } } - err = lwmqtt_unsubscribe_one(&client, lwmqtt_string("lwmqtt"), COMMAND_TIMEOUT); + err = lwmqtt_unsubscribe_one(&client, lwmqtt_string("lwmqtt"), empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_disconnect(&client, COMMAND_TIMEOUT); + err = lwmqtt_disconnect(&client, 0, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); lwmqtt_unix_network_disconnect(&network); @@ -429,10 +441,11 @@ TEST(Client, MultipleSubscriptions) { err = lwmqtt_connect(&client, options, nullptr, &return_code, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); + lwmqtt_sub_options_t subopts = lwmqtt_default_sub_options; lwmqtt_string_t topic_filters[2] = {lwmqtt_string("foo"), lwmqtt_string("lwmqtt")}; - lwmqtt_qos_t qos_levels[2] = {LWMQTT_QOS0, LWMQTT_QOS0}; + lwmqtt_sub_options_t qos_levels[2] = {subopts, subopts}; - err = lwmqtt_subscribe(&client, 2, topic_filters, qos_levels, COMMAND_TIMEOUT); + err = lwmqtt_subscribe(&client, 2, topic_filters, qos_levels, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); counter = 0; @@ -443,7 +456,7 @@ TEST(Client, MultipleSubscriptions) { msg.payload = payload; msg.payload_len = PAYLOAD_LEN; - err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, COMMAND_TIMEOUT); + err = lwmqtt_publish(&client, lwmqtt_string("lwmqtt"), msg, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); } @@ -458,10 +471,10 @@ TEST(Client, MultipleSubscriptions) { } } - err = lwmqtt_unsubscribe(&client, 2, topic_filters, COMMAND_TIMEOUT); + err = lwmqtt_unsubscribe(&client, 2, topic_filters, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); - err = lwmqtt_disconnect(&client, COMMAND_TIMEOUT); + err = lwmqtt_disconnect(&client, 0, empty_props, COMMAND_TIMEOUT); ASSERT_EQ(err, LWMQTT_SUCCESS); lwmqtt_unix_network_disconnect(&network); diff --git a/tests/generated.cpp b/tests/generated.cpp new file mode 100644 index 0000000..96eba40 --- /dev/null +++ b/tests/generated.cpp @@ -0,0 +1,27322 @@ +#include + +extern "C" { +#include +#include "../src/packet.h" +} + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#ifdef __clang__ +#pragma GCC diagnostic ignored "-Wc99-extensions" +#else +#pragma GCC diagnostic ignored "-Wpedantic" +#endif +#endif + +#define EXPECT_ARRAY_EQ(reference, actual, element_count) \ + { \ + for (size_t cmp_i = 0; cmp_i < element_count; cmp_i++) { \ + EXPECT_EQ(reference[cmp_i], actual[cmp_i]) << "At byte: " << cmp_i; \ + } \ + } + +// PublishRequest {_pubDup = False, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "", _pubPktID = 0, _pubBody = +// "\201\174\&5}Y\150\209fI\146", _pubProps = []} +TEST(Publish311QCTest, Encode1) { + uint8_t pkt[] = {0x31, 0xc, 0x0, 0x0, 0xc9, 0xae, 0x35, 0x7d, 0x59, 0x96, 0xd1, 0x66, 0x49, 0x92}; + uint8_t topic_bytes[] = {0}; + lwmqtt_string_t topic = {0, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = true; + uint8_t msg_bytes[] = {0xc9, 0xae, 0x35, 0x7d, 0x59, 0x96, 0xd1, 0x66, 0x49, 0x92}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 10; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "", _pubPktID = 0, _pubBody = +// "\201\174\&5}Y\150\209fI\146", _pubProps = []} +TEST(Publish311QCTest, Decode1) { + uint8_t pkt[] = {0x31, 0xc, 0x0, 0x0, 0xc9, 0xae, 0x35, 0x7d, 0x59, 0x96, 0xd1, 0x66, 0x49, 0x92}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0}; + lwmqtt_string_t exp_topic = {0, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xc9, 0xae, 0x35, 0x7d, 0x59, 0x96, 0xd1, 0x66, 0x49, 0x92}; + lwmqtt_string_t exp_body = {10, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 0); + EXPECT_EQ(msg.payload_len, 10); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 10); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\178\&4?\195\154\241'~\229S\255\SO\a40\221\ESC\221:N\212F\r\188l", _pubPktID = 2511, _pubBody = +// "'6\224\138\ETB\f{\166\251\224\EM", _pubProps = []} +TEST(Publish311QCTest, Encode2) { + uint8_t pkt[] = {0x33, 0x28, 0x0, 0x19, 0xb2, 0x34, 0x3f, 0xc3, 0x9a, 0xf1, 0x27, 0x7e, 0xe5, 0x53, + 0xff, 0xe, 0x7, 0x34, 0x30, 0xdd, 0x1b, 0xdd, 0x3a, 0x4e, 0xd4, 0x46, 0xd, 0xbc, + 0x6c, 0x9, 0xcf, 0x27, 0x36, 0xe0, 0x8a, 0x17, 0xc, 0x7b, 0xa6, 0xfb, 0xe0, 0x19}; + uint8_t topic_bytes[] = {0xb2, 0x34, 0x3f, 0xc3, 0x9a, 0xf1, 0x27, 0x7e, 0xe5, 0x53, 0xff, 0xe, 0x7, + 0x34, 0x30, 0xdd, 0x1b, 0xdd, 0x3a, 0x4e, 0xd4, 0x46, 0xd, 0xbc, 0x6c}; + lwmqtt_string_t topic = {25, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0x27, 0x36, 0xe0, 0x8a, 0x17, 0xc, 0x7b, 0xa6, 0xfb, 0xe0, 0x19}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 11; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 2511, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\178\&4?\195\154\241'~\229S\255\SO\a40\221\ESC\221:N\212F\r\188l", _pubPktID = 2511, _pubBody = +// "'6\224\138\ETB\f{\166\251\224\EM", _pubProps = []} +TEST(Publish311QCTest, Decode2) { + uint8_t pkt[] = {0x33, 0x28, 0x0, 0x19, 0xb2, 0x34, 0x3f, 0xc3, 0x9a, 0xf1, 0x27, 0x7e, 0xe5, 0x53, + 0xff, 0xe, 0x7, 0x34, 0x30, 0xdd, 0x1b, 0xdd, 0x3a, 0x4e, 0xd4, 0x46, 0xd, 0xbc, + 0x6c, 0x9, 0xcf, 0x27, 0x36, 0xe0, 0x8a, 0x17, 0xc, 0x7b, 0xa6, 0xfb, 0xe0, 0x19}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xb2, 0x34, 0x3f, 0xc3, 0x9a, 0xf1, 0x27, 0x7e, 0xe5, 0x53, 0xff, 0xe, 0x7, + 0x34, 0x30, 0xdd, 0x1b, 0xdd, 0x3a, 0x4e, 0xd4, 0x46, 0xd, 0xbc, 0x6c}; + lwmqtt_string_t exp_topic = {25, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x27, 0x36, 0xe0, 0x8a, 0x17, 0xc, 0x7b, 0xa6, 0xfb, 0xe0, 0x19}; + lwmqtt_string_t exp_body = {11, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 2511); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 25); + EXPECT_EQ(msg.payload_len, 11); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 11); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = +// "J\178\233\r\ETBB\156\DC4\237T\199\169", _pubPktID = 0, _pubBody = +// "\"\231\233q\224v\140\216\174\175\203\242]\142\187\218", _pubProps = []} +TEST(Publish311QCTest, Encode3) { + uint8_t pkt[] = {0x38, 0x1e, 0x0, 0xc, 0x4a, 0xb2, 0xe9, 0xd, 0x17, 0x42, 0x9c, 0x14, 0xed, 0x54, 0xc7, 0xa9, + 0x22, 0xe7, 0xe9, 0x71, 0xe0, 0x76, 0x8c, 0xd8, 0xae, 0xaf, 0xcb, 0xf2, 0x5d, 0x8e, 0xbb, 0xda}; + uint8_t topic_bytes[] = {0x4a, 0xb2, 0xe9, 0xd, 0x17, 0x42, 0x9c, 0x14, 0xed, 0x54, 0xc7, 0xa9}; + lwmqtt_string_t topic = {12, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = false; + uint8_t msg_bytes[] = {0x22, 0xe7, 0xe9, 0x71, 0xe0, 0x76, 0x8c, 0xd8, + 0xae, 0xaf, 0xcb, 0xf2, 0x5d, 0x8e, 0xbb, 0xda}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 16; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = +// "J\178\233\r\ETBB\156\DC4\237T\199\169", _pubPktID = 0, _pubBody = +// "\"\231\233q\224v\140\216\174\175\203\242]\142\187\218", _pubProps = []} +TEST(Publish311QCTest, Decode3) { + uint8_t pkt[] = {0x38, 0x1e, 0x0, 0xc, 0x4a, 0xb2, 0xe9, 0xd, 0x17, 0x42, 0x9c, 0x14, 0xed, 0x54, 0xc7, 0xa9, + 0x22, 0xe7, 0xe9, 0x71, 0xe0, 0x76, 0x8c, 0xd8, 0xae, 0xaf, 0xcb, 0xf2, 0x5d, 0x8e, 0xbb, 0xda}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x4a, 0xb2, 0xe9, 0xd, 0x17, 0x42, 0x9c, 0x14, 0xed, 0x54, 0xc7, 0xa9}; + lwmqtt_string_t exp_topic = {12, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x22, 0xe7, 0xe9, 0x71, 0xe0, 0x76, 0x8c, 0xd8, + 0xae, 0xaf, 0xcb, 0xf2, 0x5d, 0x8e, 0xbb, 0xda}; + lwmqtt_string_t exp_body = {16, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 12); + EXPECT_EQ(msg.payload_len, 16); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 16); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "(\166\195\173\148\GS\175\209g\RS\b\244\191\221\186\\Z\149\158\195\NUL\158\202{\242", _pubPktID = 7293, _pubBody = +// "\177?\SI\SI1\226\146\135\CAN\224\SYNIK\STX\237y\n\SUBT\185\&7$\f\253My\202C", _pubProps = []} +TEST(Publish311QCTest, Encode4) { + uint8_t pkt[] = {0x32, 0x39, 0x0, 0x19, 0x28, 0xa6, 0xc3, 0xad, 0x94, 0x1d, 0xaf, 0xd1, 0x67, 0x1e, 0x8, + 0xf4, 0xbf, 0xdd, 0xba, 0x5c, 0x5a, 0x95, 0x9e, 0xc3, 0x0, 0x9e, 0xca, 0x7b, 0xf2, 0x1c, + 0x7d, 0xb1, 0x3f, 0xf, 0xf, 0x31, 0xe2, 0x92, 0x87, 0x18, 0xe0, 0x16, 0x49, 0x4b, 0x2, + 0xed, 0x79, 0xa, 0x1a, 0x54, 0xb9, 0x37, 0x24, 0xc, 0xfd, 0x4d, 0x79, 0xca, 0x43}; + uint8_t topic_bytes[] = {0x28, 0xa6, 0xc3, 0xad, 0x94, 0x1d, 0xaf, 0xd1, 0x67, 0x1e, 0x8, 0xf4, 0xbf, + 0xdd, 0xba, 0x5c, 0x5a, 0x95, 0x9e, 0xc3, 0x0, 0x9e, 0xca, 0x7b, 0xf2}; + lwmqtt_string_t topic = {25, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = false; + uint8_t msg_bytes[] = {0xb1, 0x3f, 0xf, 0xf, 0x31, 0xe2, 0x92, 0x87, 0x18, 0xe0, 0x16, 0x49, 0x4b, 0x2, + 0xed, 0x79, 0xa, 0x1a, 0x54, 0xb9, 0x37, 0x24, 0xc, 0xfd, 0x4d, 0x79, 0xca, 0x43}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 28; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 7293, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "(\166\195\173\148\GS\175\209g\RS\b\244\191\221\186\\Z\149\158\195\NUL\158\202{\242", _pubPktID = 7293, _pubBody = +// "\177?\SI\SI1\226\146\135\CAN\224\SYNIK\STX\237y\n\SUBT\185\&7$\f\253My\202C", _pubProps = []} +TEST(Publish311QCTest, Decode4) { + uint8_t pkt[] = {0x32, 0x39, 0x0, 0x19, 0x28, 0xa6, 0xc3, 0xad, 0x94, 0x1d, 0xaf, 0xd1, 0x67, 0x1e, 0x8, + 0xf4, 0xbf, 0xdd, 0xba, 0x5c, 0x5a, 0x95, 0x9e, 0xc3, 0x0, 0x9e, 0xca, 0x7b, 0xf2, 0x1c, + 0x7d, 0xb1, 0x3f, 0xf, 0xf, 0x31, 0xe2, 0x92, 0x87, 0x18, 0xe0, 0x16, 0x49, 0x4b, 0x2, + 0xed, 0x79, 0xa, 0x1a, 0x54, 0xb9, 0x37, 0x24, 0xc, 0xfd, 0x4d, 0x79, 0xca, 0x43}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x28, 0xa6, 0xc3, 0xad, 0x94, 0x1d, 0xaf, 0xd1, 0x67, 0x1e, 0x8, 0xf4, 0xbf, + 0xdd, 0xba, 0x5c, 0x5a, 0x95, 0x9e, 0xc3, 0x0, 0x9e, 0xca, 0x7b, 0xf2}; + lwmqtt_string_t exp_topic = {25, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xb1, 0x3f, 0xf, 0xf, 0x31, 0xe2, 0x92, 0x87, 0x18, 0xe0, 0x16, 0x49, 0x4b, 0x2, + 0xed, 0x79, 0xa, 0x1a, 0x54, 0xb9, 0x37, 0x24, 0xc, 0xfd, 0x4d, 0x79, 0xca, 0x43}; + lwmqtt_string_t exp_body = {28, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 7293); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 25); + EXPECT_EQ(msg.payload_len, 28); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 28); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "\239!qf)\DC1R\192\227\STX\227\191\ENQ\163\242\172\201\233\225\150\242\USr\DEL", _pubPktID = 8490, _pubBody = +// "Hj(;\171\211\&2\147\237^\SO\175\143\&0\161\182\EM", _pubProps = []} +TEST(Publish311QCTest, Encode5) { + uint8_t pkt[] = {0x32, 0x2d, 0x0, 0x18, 0xef, 0x21, 0x71, 0x66, 0x29, 0x11, 0x52, 0xc0, 0xe3, 0x2, 0xe3, 0xbf, + 0x5, 0xa3, 0xf2, 0xac, 0xc9, 0xe9, 0xe1, 0x96, 0xf2, 0x1f, 0x72, 0x7f, 0x21, 0x2a, 0x48, 0x6a, + 0x28, 0x3b, 0xab, 0xd3, 0x32, 0x93, 0xed, 0x5e, 0xe, 0xaf, 0x8f, 0x30, 0xa1, 0xb6, 0x19}; + uint8_t topic_bytes[] = {0xef, 0x21, 0x71, 0x66, 0x29, 0x11, 0x52, 0xc0, 0xe3, 0x2, 0xe3, 0xbf, + 0x5, 0xa3, 0xf2, 0xac, 0xc9, 0xe9, 0xe1, 0x96, 0xf2, 0x1f, 0x72, 0x7f}; + lwmqtt_string_t topic = {24, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = false; + uint8_t msg_bytes[] = {0x48, 0x6a, 0x28, 0x3b, 0xab, 0xd3, 0x32, 0x93, 0xed, + 0x5e, 0xe, 0xaf, 0x8f, 0x30, 0xa1, 0xb6, 0x19}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 17; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 8490, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "\239!qf)\DC1R\192\227\STX\227\191\ENQ\163\242\172\201\233\225\150\242\USr\DEL", _pubPktID = 8490, _pubBody = +// "Hj(;\171\211\&2\147\237^\SO\175\143\&0\161\182\EM", _pubProps = []} +TEST(Publish311QCTest, Decode5) { + uint8_t pkt[] = {0x32, 0x2d, 0x0, 0x18, 0xef, 0x21, 0x71, 0x66, 0x29, 0x11, 0x52, 0xc0, 0xe3, 0x2, 0xe3, 0xbf, + 0x5, 0xa3, 0xf2, 0xac, 0xc9, 0xe9, 0xe1, 0x96, 0xf2, 0x1f, 0x72, 0x7f, 0x21, 0x2a, 0x48, 0x6a, + 0x28, 0x3b, 0xab, 0xd3, 0x32, 0x93, 0xed, 0x5e, 0xe, 0xaf, 0x8f, 0x30, 0xa1, 0xb6, 0x19}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xef, 0x21, 0x71, 0x66, 0x29, 0x11, 0x52, 0xc0, 0xe3, 0x2, 0xe3, 0xbf, + 0x5, 0xa3, 0xf2, 0xac, 0xc9, 0xe9, 0xe1, 0x96, 0xf2, 0x1f, 0x72, 0x7f}; + lwmqtt_string_t exp_topic = {24, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x48, 0x6a, 0x28, 0x3b, 0xab, 0xd3, 0x32, 0x93, 0xed, + 0x5e, 0xe, 0xaf, 0x8f, 0x30, 0xa1, 0xb6, 0x19}; + lwmqtt_string_t exp_body = {17, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 8490); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 24); + EXPECT_EQ(msg.payload_len, 17); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 17); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "~\225\DLELiZW,vB\173`\255\CAN+\v\194\238", _pubPktID = 25725, _pubBody = +// "\188\SO\205\140\237\238\138\149\210\239m\246\ACK>\DC4\249\182\183(\131\128\&5\164X\173\&0C", _pubProps = []} +TEST(Publish311QCTest, Encode6) { + uint8_t pkt[] = {0x3c, 0x31, 0x0, 0x12, 0x7e, 0xe1, 0x10, 0x4c, 0x69, 0x5a, 0x57, 0x2c, 0x76, 0x42, 0xad, 0x60, 0xff, + 0x18, 0x2b, 0xb, 0xc2, 0xee, 0x64, 0x7d, 0xbc, 0xe, 0xcd, 0x8c, 0xed, 0xee, 0x8a, 0x95, 0xd2, 0xef, + 0x6d, 0xf6, 0x6, 0x3e, 0x14, 0xf9, 0xb6, 0xb7, 0x28, 0x83, 0x80, 0x35, 0xa4, 0x58, 0xad, 0x30, 0x43}; + uint8_t topic_bytes[] = {0x7e, 0xe1, 0x10, 0x4c, 0x69, 0x5a, 0x57, 0x2c, 0x76, + 0x42, 0xad, 0x60, 0xff, 0x18, 0x2b, 0xb, 0xc2, 0xee}; + lwmqtt_string_t topic = {18, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0xbc, 0xe, 0xcd, 0x8c, 0xed, 0xee, 0x8a, 0x95, 0xd2, 0xef, 0x6d, 0xf6, 0x6, 0x3e, + 0x14, 0xf9, 0xb6, 0xb7, 0x28, 0x83, 0x80, 0x35, 0xa4, 0x58, 0xad, 0x30, 0x43}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 27; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 25725, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "~\225\DLELiZW,vB\173`\255\CAN+\v\194\238", _pubPktID = 25725, _pubBody = +// "\188\SO\205\140\237\238\138\149\210\239m\246\ACK>\DC4\249\182\183(\131\128\&5\164X\173\&0C", _pubProps = []} +TEST(Publish311QCTest, Decode6) { + uint8_t pkt[] = {0x3c, 0x31, 0x0, 0x12, 0x7e, 0xe1, 0x10, 0x4c, 0x69, 0x5a, 0x57, 0x2c, 0x76, 0x42, 0xad, 0x60, 0xff, + 0x18, 0x2b, 0xb, 0xc2, 0xee, 0x64, 0x7d, 0xbc, 0xe, 0xcd, 0x8c, 0xed, 0xee, 0x8a, 0x95, 0xd2, 0xef, + 0x6d, 0xf6, 0x6, 0x3e, 0x14, 0xf9, 0xb6, 0xb7, 0x28, 0x83, 0x80, 0x35, 0xa4, 0x58, 0xad, 0x30, 0x43}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x7e, 0xe1, 0x10, 0x4c, 0x69, 0x5a, 0x57, 0x2c, 0x76, + 0x42, 0xad, 0x60, 0xff, 0x18, 0x2b, 0xb, 0xc2, 0xee}; + lwmqtt_string_t exp_topic = {18, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xbc, 0xe, 0xcd, 0x8c, 0xed, 0xee, 0x8a, 0x95, 0xd2, 0xef, 0x6d, 0xf6, 0x6, 0x3e, + 0x14, 0xf9, 0xb6, 0xb7, 0x28, 0x83, 0x80, 0x35, 0xa4, 0x58, 0xad, 0x30, 0x43}; + lwmqtt_string_t exp_body = {27, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 25725); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 18); + EXPECT_EQ(msg.payload_len, 27); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 27); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "_\173\SI\187N\192\141\207\237\228\129\187v\189VY\232b\187N\179\SO", _pubPktID = 26097, _pubBody = +// "\175\134\253\152O\211\174\USV\DC4\249", _pubProps = []} +TEST(Publish311QCTest, Encode7) { + uint8_t pkt[] = {0x34, 0x25, 0x0, 0x16, 0x5f, 0xad, 0xf, 0xbb, 0x4e, 0xc0, 0x8d, 0xcf, 0xed, + 0xe4, 0x81, 0xbb, 0x76, 0xbd, 0x56, 0x59, 0xe8, 0x62, 0xbb, 0x4e, 0xb3, 0xe, + 0x65, 0xf1, 0xaf, 0x86, 0xfd, 0x98, 0x4f, 0xd3, 0xae, 0x1f, 0x56, 0x14, 0xf9}; + uint8_t topic_bytes[] = {0x5f, 0xad, 0xf, 0xbb, 0x4e, 0xc0, 0x8d, 0xcf, 0xed, 0xe4, 0x81, + 0xbb, 0x76, 0xbd, 0x56, 0x59, 0xe8, 0x62, 0xbb, 0x4e, 0xb3, 0xe}; + lwmqtt_string_t topic = {22, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0xaf, 0x86, 0xfd, 0x98, 0x4f, 0xd3, 0xae, 0x1f, 0x56, 0x14, 0xf9}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 11; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 26097, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "_\173\SI\187N\192\141\207\237\228\129\187v\189VY\232b\187N\179\SO", _pubPktID = 26097, _pubBody = +// "\175\134\253\152O\211\174\USV\DC4\249", _pubProps = []} +TEST(Publish311QCTest, Decode7) { + uint8_t pkt[] = {0x34, 0x25, 0x0, 0x16, 0x5f, 0xad, 0xf, 0xbb, 0x4e, 0xc0, 0x8d, 0xcf, 0xed, + 0xe4, 0x81, 0xbb, 0x76, 0xbd, 0x56, 0x59, 0xe8, 0x62, 0xbb, 0x4e, 0xb3, 0xe, + 0x65, 0xf1, 0xaf, 0x86, 0xfd, 0x98, 0x4f, 0xd3, 0xae, 0x1f, 0x56, 0x14, 0xf9}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x5f, 0xad, 0xf, 0xbb, 0x4e, 0xc0, 0x8d, 0xcf, 0xed, 0xe4, 0x81, + 0xbb, 0x76, 0xbd, 0x56, 0x59, 0xe8, 0x62, 0xbb, 0x4e, 0xb3, 0xe}; + lwmqtt_string_t exp_topic = {22, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xaf, 0x86, 0xfd, 0x98, 0x4f, 0xd3, 0xae, 0x1f, 0x56, 0x14, 0xf9}; + lwmqtt_string_t exp_body = {11, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 26097); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 22); + EXPECT_EQ(msg.payload_len, 11); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 11); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = False, _pubTopic = "\196L\196\FS8\154\173\EOT\225", +// _pubPktID = 3661, _pubBody = "\223\209u\180\&7\134", _pubProps = []} +TEST(Publish311QCTest, Encode8) { + uint8_t pkt[] = {0x3a, 0x13, 0x0, 0x9, 0xc4, 0x4c, 0xc4, 0x1c, 0x38, 0x9a, 0xad, + 0x4, 0xe1, 0xe, 0x4d, 0xdf, 0xd1, 0x75, 0xb4, 0x37, 0x86}; + uint8_t topic_bytes[] = {0xc4, 0x4c, 0xc4, 0x1c, 0x38, 0x9a, 0xad, 0x4, 0xe1}; + lwmqtt_string_t topic = {9, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = false; + uint8_t msg_bytes[] = {0xdf, 0xd1, 0x75, 0xb4, 0x37, 0x86}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 6; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 3661, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = False, _pubTopic = "\196L\196\FS8\154\173\EOT\225", +// _pubPktID = 3661, _pubBody = "\223\209u\180\&7\134", _pubProps = []} +TEST(Publish311QCTest, Decode8) { + uint8_t pkt[] = {0x3a, 0x13, 0x0, 0x9, 0xc4, 0x4c, 0xc4, 0x1c, 0x38, 0x9a, 0xad, + 0x4, 0xe1, 0xe, 0x4d, 0xdf, 0xd1, 0x75, 0xb4, 0x37, 0x86}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xc4, 0x4c, 0xc4, 0x1c, 0x38, 0x9a, 0xad, 0x4, 0xe1}; + lwmqtt_string_t exp_topic = {9, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xdf, 0xd1, 0x75, 0xb4, 0x37, 0x86}; + lwmqtt_string_t exp_body = {6, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 3661); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 9); + EXPECT_EQ(msg.payload_len, 6); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 6); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\b\201MSc\140\128\CANs\162;\213\155\SO\151\139\229\SOH\229\197", _pubPktID = 30138, _pubBody = +// "`6\148\134s,\US`Z\206\157\252jI5w9\138e\176\183\141}", _pubProps = []} +TEST(Publish311QCTest, Encode9) { + uint8_t pkt[] = {0x3b, 0x2f, 0x0, 0x14, 0x8, 0xc9, 0x4d, 0x53, 0x63, 0x8c, 0x80, 0x18, 0x73, 0xa2, 0x3b, 0xd5, 0x9b, + 0xe, 0x97, 0x8b, 0xe5, 0x1, 0xe5, 0xc5, 0x75, 0xba, 0x60, 0x36, 0x94, 0x86, 0x73, 0x2c, 0x1f, 0x60, + 0x5a, 0xce, 0x9d, 0xfc, 0x6a, 0x49, 0x35, 0x77, 0x39, 0x8a, 0x65, 0xb0, 0xb7, 0x8d, 0x7d}; + uint8_t topic_bytes[] = {0x8, 0xc9, 0x4d, 0x53, 0x63, 0x8c, 0x80, 0x18, 0x73, 0xa2, + 0x3b, 0xd5, 0x9b, 0xe, 0x97, 0x8b, 0xe5, 0x1, 0xe5, 0xc5}; + lwmqtt_string_t topic = {20, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0x60, 0x36, 0x94, 0x86, 0x73, 0x2c, 0x1f, 0x60, 0x5a, 0xce, 0x9d, 0xfc, + 0x6a, 0x49, 0x35, 0x77, 0x39, 0x8a, 0x65, 0xb0, 0xb7, 0x8d, 0x7d}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 23; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 30138, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\b\201MSc\140\128\CANs\162;\213\155\SO\151\139\229\SOH\229\197", _pubPktID = 30138, _pubBody = +// "`6\148\134s,\US`Z\206\157\252jI5w9\138e\176\183\141}", _pubProps = []} +TEST(Publish311QCTest, Decode9) { + uint8_t pkt[] = {0x3b, 0x2f, 0x0, 0x14, 0x8, 0xc9, 0x4d, 0x53, 0x63, 0x8c, 0x80, 0x18, 0x73, 0xa2, 0x3b, 0xd5, 0x9b, + 0xe, 0x97, 0x8b, 0xe5, 0x1, 0xe5, 0xc5, 0x75, 0xba, 0x60, 0x36, 0x94, 0x86, 0x73, 0x2c, 0x1f, 0x60, + 0x5a, 0xce, 0x9d, 0xfc, 0x6a, 0x49, 0x35, 0x77, 0x39, 0x8a, 0x65, 0xb0, 0xb7, 0x8d, 0x7d}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x8, 0xc9, 0x4d, 0x53, 0x63, 0x8c, 0x80, 0x18, 0x73, 0xa2, + 0x3b, 0xd5, 0x9b, 0xe, 0x97, 0x8b, 0xe5, 0x1, 0xe5, 0xc5}; + lwmqtt_string_t exp_topic = {20, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x60, 0x36, 0x94, 0x86, 0x73, 0x2c, 0x1f, 0x60, 0x5a, 0xce, 0x9d, 0xfc, + 0x6a, 0x49, 0x35, 0x77, 0x39, 0x8a, 0x65, 0xb0, 0xb7, 0x8d, 0x7d}; + lwmqtt_string_t exp_body = {23, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 30138); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 20); + EXPECT_EQ(msg.payload_len, 23); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 23); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = "\177\SUB\139\129\ETB\208\148", +// _pubPktID = 30010, _pubBody = "`\USq\198\217\144\199Zp9", _pubProps = []} +TEST(Publish311QCTest, Encode10) { + uint8_t pkt[] = {0x32, 0x15, 0x0, 0x7, 0xb1, 0x1a, 0x8b, 0x81, 0x17, 0xd0, 0x94, 0x75, + 0x3a, 0x60, 0x1f, 0x71, 0xc6, 0xd9, 0x90, 0xc7, 0x5a, 0x70, 0x39}; + uint8_t topic_bytes[] = {0xb1, 0x1a, 0x8b, 0x81, 0x17, 0xd0, 0x94}; + lwmqtt_string_t topic = {7, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = false; + uint8_t msg_bytes[] = {0x60, 0x1f, 0x71, 0xc6, 0xd9, 0x90, 0xc7, 0x5a, 0x70, 0x39}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 10; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 30010, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = "\177\SUB\139\129\ETB\208\148", +// _pubPktID = 30010, _pubBody = "`\USq\198\217\144\199Zp9", _pubProps = []} +TEST(Publish311QCTest, Decode10) { + uint8_t pkt[] = {0x32, 0x15, 0x0, 0x7, 0xb1, 0x1a, 0x8b, 0x81, 0x17, 0xd0, 0x94, 0x75, + 0x3a, 0x60, 0x1f, 0x71, 0xc6, 0xd9, 0x90, 0xc7, 0x5a, 0x70, 0x39}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xb1, 0x1a, 0x8b, 0x81, 0x17, 0xd0, 0x94}; + lwmqtt_string_t exp_topic = {7, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x60, 0x1f, 0x71, 0xc6, 0xd9, 0x90, 0xc7, 0x5a, 0x70, 0x39}; + lwmqtt_string_t exp_body = {10, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 30010); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 7); + EXPECT_EQ(msg.payload_len, 10); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 10); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "\203", _pubPktID = 182, _pubBody = +// "\145y\231n\252\238pw\ACK\168Lc~\152\153\129W\\\SIK\134\251\185\SOH\208\EMV\"", _pubProps = []} +TEST(Publish311QCTest, Encode11) { + uint8_t pkt[] = {0x3b, 0x21, 0x0, 0x1, 0xcb, 0x0, 0xb6, 0x91, 0x79, 0xe7, 0x6e, 0xfc, + 0xee, 0x70, 0x77, 0x6, 0xa8, 0x4c, 0x63, 0x7e, 0x98, 0x99, 0x81, 0x57, + 0x5c, 0xf, 0x4b, 0x86, 0xfb, 0xb9, 0x1, 0xd0, 0x19, 0x56, 0x22}; + uint8_t topic_bytes[] = {0xcb}; + lwmqtt_string_t topic = {1, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0x91, 0x79, 0xe7, 0x6e, 0xfc, 0xee, 0x70, 0x77, 0x6, 0xa8, 0x4c, 0x63, 0x7e, 0x98, + 0x99, 0x81, 0x57, 0x5c, 0xf, 0x4b, 0x86, 0xfb, 0xb9, 0x1, 0xd0, 0x19, 0x56, 0x22}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 28; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 182, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "\203", _pubPktID = 182, _pubBody = +// "\145y\231n\252\238pw\ACK\168Lc~\152\153\129W\\\SIK\134\251\185\SOH\208\EMV\"", _pubProps = []} +TEST(Publish311QCTest, Decode11) { + uint8_t pkt[] = {0x3b, 0x21, 0x0, 0x1, 0xcb, 0x0, 0xb6, 0x91, 0x79, 0xe7, 0x6e, 0xfc, + 0xee, 0x70, 0x77, 0x6, 0xa8, 0x4c, 0x63, 0x7e, 0x98, 0x99, 0x81, 0x57, + 0x5c, 0xf, 0x4b, 0x86, 0xfb, 0xb9, 0x1, 0xd0, 0x19, 0x56, 0x22}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xcb}; + lwmqtt_string_t exp_topic = {1, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x91, 0x79, 0xe7, 0x6e, 0xfc, 0xee, 0x70, 0x77, 0x6, 0xa8, 0x4c, 0x63, 0x7e, 0x98, + 0x99, 0x81, 0x57, 0x5c, 0xf, 0x4b, 0x86, 0xfb, 0xb9, 0x1, 0xd0, 0x19, 0x56, 0x22}; + lwmqtt_string_t exp_body = {28, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 182); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 1); + EXPECT_EQ(msg.payload_len, 28); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 28); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = True, _pubTopic = +// "\194\243\142\n\178\204\216XR\184\207o\140\n\176", _pubPktID = 10741, _pubBody = "\135\214\215", _pubProps = []} +TEST(Publish311QCTest, Encode12) { + uint8_t pkt[] = {0x35, 0x16, 0x0, 0xf, 0xc2, 0xf3, 0x8e, 0xa, 0xb2, 0xcc, 0xd8, 0x58, + 0x52, 0xb8, 0xcf, 0x6f, 0x8c, 0xa, 0xb0, 0x29, 0xf5, 0x87, 0xd6, 0xd7}; + uint8_t topic_bytes[] = {0xc2, 0xf3, 0x8e, 0xa, 0xb2, 0xcc, 0xd8, 0x58, 0x52, 0xb8, 0xcf, 0x6f, 0x8c, 0xa, 0xb0}; + lwmqtt_string_t topic = {15, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = true; + uint8_t msg_bytes[] = {0x87, 0xd6, 0xd7}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 3; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 10741, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = True, _pubTopic = +// "\194\243\142\n\178\204\216XR\184\207o\140\n\176", _pubPktID = 10741, _pubBody = "\135\214\215", _pubProps = []} +TEST(Publish311QCTest, Decode12) { + uint8_t pkt[] = {0x35, 0x16, 0x0, 0xf, 0xc2, 0xf3, 0x8e, 0xa, 0xb2, 0xcc, 0xd8, 0x58, + 0x52, 0xb8, 0xcf, 0x6f, 0x8c, 0xa, 0xb0, 0x29, 0xf5, 0x87, 0xd6, 0xd7}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xc2, 0xf3, 0x8e, 0xa, 0xb2, 0xcc, 0xd8, 0x58, 0x52, 0xb8, 0xcf, 0x6f, 0x8c, 0xa, 0xb0}; + lwmqtt_string_t exp_topic = {15, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x87, 0xd6, 0xd7}; + lwmqtt_string_t exp_body = {3, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 10741); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 15); + EXPECT_EQ(msg.payload_len, 3); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 3); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = +// "\180^\180\196\166\GS\142\ETB\np\US\226\226j-\130\242+\138\234A", _pubPktID = 0, _pubBody = +// "\STXN8tdLv\171\220\&3tu\225\159\165V\148\183&W6\202\202\165r\SOH", _pubProps = []} +TEST(Publish311QCTest, Encode13) { + uint8_t pkt[] = {0x38, 0x31, 0x0, 0x15, 0xb4, 0x5e, 0xb4, 0xc4, 0xa6, 0x1d, 0x8e, 0x17, 0xa, 0x70, 0x1f, 0xe2, 0xe2, + 0x6a, 0x2d, 0x82, 0xf2, 0x2b, 0x8a, 0xea, 0x41, 0x2, 0x4e, 0x38, 0x74, 0x64, 0x4c, 0x76, 0xab, 0xdc, + 0x33, 0x74, 0x75, 0xe1, 0x9f, 0xa5, 0x56, 0x94, 0xb7, 0x26, 0x57, 0x36, 0xca, 0xca, 0xa5, 0x72, 0x1}; + uint8_t topic_bytes[] = {0xb4, 0x5e, 0xb4, 0xc4, 0xa6, 0x1d, 0x8e, 0x17, 0xa, 0x70, 0x1f, + 0xe2, 0xe2, 0x6a, 0x2d, 0x82, 0xf2, 0x2b, 0x8a, 0xea, 0x41}; + lwmqtt_string_t topic = {21, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = false; + uint8_t msg_bytes[] = {0x2, 0x4e, 0x38, 0x74, 0x64, 0x4c, 0x76, 0xab, 0xdc, 0x33, 0x74, 0x75, 0xe1, + 0x9f, 0xa5, 0x56, 0x94, 0xb7, 0x26, 0x57, 0x36, 0xca, 0xca, 0xa5, 0x72, 0x1}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 26; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = +// "\180^\180\196\166\GS\142\ETB\np\US\226\226j-\130\242+\138\234A", _pubPktID = 0, _pubBody = +// "\STXN8tdLv\171\220\&3tu\225\159\165V\148\183&W6\202\202\165r\SOH", _pubProps = []} +TEST(Publish311QCTest, Decode13) { + uint8_t pkt[] = {0x38, 0x31, 0x0, 0x15, 0xb4, 0x5e, 0xb4, 0xc4, 0xa6, 0x1d, 0x8e, 0x17, 0xa, 0x70, 0x1f, 0xe2, 0xe2, + 0x6a, 0x2d, 0x82, 0xf2, 0x2b, 0x8a, 0xea, 0x41, 0x2, 0x4e, 0x38, 0x74, 0x64, 0x4c, 0x76, 0xab, 0xdc, + 0x33, 0x74, 0x75, 0xe1, 0x9f, 0xa5, 0x56, 0x94, 0xb7, 0x26, 0x57, 0x36, 0xca, 0xca, 0xa5, 0x72, 0x1}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xb4, 0x5e, 0xb4, 0xc4, 0xa6, 0x1d, 0x8e, 0x17, 0xa, 0x70, 0x1f, + 0xe2, 0xe2, 0x6a, 0x2d, 0x82, 0xf2, 0x2b, 0x8a, 0xea, 0x41}; + lwmqtt_string_t exp_topic = {21, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x2, 0x4e, 0x38, 0x74, 0x64, 0x4c, 0x76, 0xab, 0xdc, 0x33, 0x74, 0x75, 0xe1, + 0x9f, 0xa5, 0x56, 0x94, 0xb7, 0x26, 0x57, 0x36, 0xca, 0xca, 0xa5, 0x72, 0x1}; + lwmqtt_string_t exp_body = {26, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 21); + EXPECT_EQ(msg.payload_len, 26); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 26); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS0, _pubRetain = True, _pubTopic = +// "\243\134\DC4\174\182\NAK\138\171\188\\\180\226\181G\223S\232\138f\172\170", _pubPktID = 0, _pubBody = +// "\b\177(\176\139\216T[#|\147\DC1\157R?$\242", _pubProps = []} +TEST(Publish311QCTest, Encode14) { + uint8_t pkt[] = {0x31, 0x28, 0x0, 0x15, 0xf3, 0x86, 0x14, 0xae, 0xb6, 0x15, 0x8a, 0xab, 0xbc, 0x5c, + 0xb4, 0xe2, 0xb5, 0x47, 0xdf, 0x53, 0xe8, 0x8a, 0x66, 0xac, 0xaa, 0x8, 0xb1, 0x28, + 0xb0, 0x8b, 0xd8, 0x54, 0x5b, 0x23, 0x7c, 0x93, 0x11, 0x9d, 0x52, 0x3f, 0x24, 0xf2}; + uint8_t topic_bytes[] = {0xf3, 0x86, 0x14, 0xae, 0xb6, 0x15, 0x8a, 0xab, 0xbc, 0x5c, 0xb4, + 0xe2, 0xb5, 0x47, 0xdf, 0x53, 0xe8, 0x8a, 0x66, 0xac, 0xaa}; + lwmqtt_string_t topic = {21, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = true; + uint8_t msg_bytes[] = {0x8, 0xb1, 0x28, 0xb0, 0x8b, 0xd8, 0x54, 0x5b, 0x23, + 0x7c, 0x93, 0x11, 0x9d, 0x52, 0x3f, 0x24, 0xf2}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 17; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS0, _pubRetain = True, _pubTopic = +// "\243\134\DC4\174\182\NAK\138\171\188\\\180\226\181G\223S\232\138f\172\170", _pubPktID = 0, _pubBody = +// "\b\177(\176\139\216T[#|\147\DC1\157R?$\242", _pubProps = []} +TEST(Publish311QCTest, Decode14) { + uint8_t pkt[] = {0x31, 0x28, 0x0, 0x15, 0xf3, 0x86, 0x14, 0xae, 0xb6, 0x15, 0x8a, 0xab, 0xbc, 0x5c, + 0xb4, 0xe2, 0xb5, 0x47, 0xdf, 0x53, 0xe8, 0x8a, 0x66, 0xac, 0xaa, 0x8, 0xb1, 0x28, + 0xb0, 0x8b, 0xd8, 0x54, 0x5b, 0x23, 0x7c, 0x93, 0x11, 0x9d, 0x52, 0x3f, 0x24, 0xf2}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xf3, 0x86, 0x14, 0xae, 0xb6, 0x15, 0x8a, 0xab, 0xbc, 0x5c, 0xb4, + 0xe2, 0xb5, 0x47, 0xdf, 0x53, 0xe8, 0x8a, 0x66, 0xac, 0xaa}; + lwmqtt_string_t exp_topic = {21, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x8, 0xb1, 0x28, 0xb0, 0x8b, 0xd8, 0x54, 0x5b, 0x23, + 0x7c, 0x93, 0x11, 0x9d, 0x52, 0x3f, 0x24, 0xf2}; + lwmqtt_string_t exp_body = {17, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 21); + EXPECT_EQ(msg.payload_len, 17); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 17); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "\CAN", _pubPktID = 21185, _pubBody = +// "\242\163\&2\173f\171\141\148\172\254\198\166\220=I\223\188q\204S\NUL\207\&8jS", _pubProps = []} +TEST(Publish311QCTest, Encode15) { + uint8_t pkt[] = {0x3b, 0x1e, 0x0, 0x1, 0x18, 0x52, 0xc1, 0xf2, 0xa3, 0x32, 0xad, 0x66, 0xab, 0x8d, 0x94, 0xac, + 0xfe, 0xc6, 0xa6, 0xdc, 0x3d, 0x49, 0xdf, 0xbc, 0x71, 0xcc, 0x53, 0x0, 0xcf, 0x38, 0x6a, 0x53}; + uint8_t topic_bytes[] = {0x18}; + lwmqtt_string_t topic = {1, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0xf2, 0xa3, 0x32, 0xad, 0x66, 0xab, 0x8d, 0x94, 0xac, 0xfe, 0xc6, 0xa6, 0xdc, + 0x3d, 0x49, 0xdf, 0xbc, 0x71, 0xcc, 0x53, 0x0, 0xcf, 0x38, 0x6a, 0x53}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 25; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 21185, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "\CAN", _pubPktID = 21185, _pubBody = +// "\242\163\&2\173f\171\141\148\172\254\198\166\220=I\223\188q\204S\NUL\207\&8jS", _pubProps = []} +TEST(Publish311QCTest, Decode15) { + uint8_t pkt[] = {0x3b, 0x1e, 0x0, 0x1, 0x18, 0x52, 0xc1, 0xf2, 0xa3, 0x32, 0xad, 0x66, 0xab, 0x8d, 0x94, 0xac, + 0xfe, 0xc6, 0xa6, 0xdc, 0x3d, 0x49, 0xdf, 0xbc, 0x71, 0xcc, 0x53, 0x0, 0xcf, 0x38, 0x6a, 0x53}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x18}; + lwmqtt_string_t exp_topic = {1, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xf2, 0xa3, 0x32, 0xad, 0x66, 0xab, 0x8d, 0x94, 0xac, 0xfe, 0xc6, 0xa6, 0xdc, + 0x3d, 0x49, 0xdf, 0xbc, 0x71, 0xcc, 0x53, 0x0, 0xcf, 0x38, 0x6a, 0x53}; + lwmqtt_string_t exp_body = {25, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 21185); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 1); + EXPECT_EQ(msg.payload_len, 25); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 25); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "\tW7", _pubPktID = 0, _pubBody = +// "<\173\DLE`;<%6\196ne\143\&7_\DC2&K\177\250\145(topic.data), 3); + EXPECT_EQ(msg.payload_len, 26); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 26); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "#rf\225\210\223\183\179#", _pubPktID +// = 0, _pubBody = "\225\141\154:Z\166E\DLEF\164\218\176U\138\191\RSV[\255\160=\DC1@\195r~WH\245", _pubProps = []} +TEST(Publish311QCTest, Encode17) { + uint8_t pkt[] = {0x39, 0x28, 0x0, 0x9, 0x23, 0x72, 0x66, 0xe1, 0xd2, 0xdf, 0xb7, 0xb3, 0x23, 0xe1, + 0x8d, 0x9a, 0x3a, 0x5a, 0xa6, 0x45, 0x10, 0x46, 0xa4, 0xda, 0xb0, 0x55, 0x8a, 0xbf, + 0x1e, 0x56, 0x5b, 0xff, 0xa0, 0x3d, 0x11, 0x40, 0xc3, 0x72, 0x7e, 0x57, 0x48, 0xf5}; + uint8_t topic_bytes[] = {0x23, 0x72, 0x66, 0xe1, 0xd2, 0xdf, 0xb7, 0xb3, 0x23}; + lwmqtt_string_t topic = {9, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = true; + uint8_t msg_bytes[] = {0xe1, 0x8d, 0x9a, 0x3a, 0x5a, 0xa6, 0x45, 0x10, 0x46, 0xa4, 0xda, 0xb0, 0x55, 0x8a, 0xbf, + 0x1e, 0x56, 0x5b, 0xff, 0xa0, 0x3d, 0x11, 0x40, 0xc3, 0x72, 0x7e, 0x57, 0x48, 0xf5}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 29; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "#rf\225\210\223\183\179#", _pubPktID +// = 0, _pubBody = "\225\141\154:Z\166E\DLEF\164\218\176U\138\191\RSV[\255\160=\DC1@\195r~WH\245", _pubProps = []} +TEST(Publish311QCTest, Decode17) { + uint8_t pkt[] = {0x39, 0x28, 0x0, 0x9, 0x23, 0x72, 0x66, 0xe1, 0xd2, 0xdf, 0xb7, 0xb3, 0x23, 0xe1, + 0x8d, 0x9a, 0x3a, 0x5a, 0xa6, 0x45, 0x10, 0x46, 0xa4, 0xda, 0xb0, 0x55, 0x8a, 0xbf, + 0x1e, 0x56, 0x5b, 0xff, 0xa0, 0x3d, 0x11, 0x40, 0xc3, 0x72, 0x7e, 0x57, 0x48, 0xf5}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x23, 0x72, 0x66, 0xe1, 0xd2, 0xdf, 0xb7, 0xb3, 0x23}; + lwmqtt_string_t exp_topic = {9, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xe1, 0x8d, 0x9a, 0x3a, 0x5a, 0xa6, 0x45, 0x10, 0x46, 0xa4, 0xda, 0xb0, 0x55, 0x8a, 0xbf, + 0x1e, 0x56, 0x5b, 0xff, 0xa0, 0x3d, 0x11, 0x40, 0xc3, 0x72, 0x7e, 0x57, 0x48, 0xf5}; + lwmqtt_string_t exp_body = {29, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 9); + EXPECT_EQ(msg.payload_len, 29); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 29); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "\250\DLE\228\172ZB\231\208\ETX\170e\DC3\177\170\203", _pubPktID = 20110, _pubBody = +// "xx\193Br\133\207:\183_\RS:zx\155", _pubProps = []} +TEST(Publish311QCTest, Encode18) { + uint8_t pkt[] = {0x3a, 0x22, 0x0, 0xf, 0xfa, 0x10, 0xe4, 0xac, 0x5a, 0x42, 0xe7, 0xd0, + 0x3, 0xaa, 0x65, 0x13, 0xb1, 0xaa, 0xcb, 0x4e, 0x8e, 0x78, 0x78, 0xc1, + 0x42, 0x72, 0x85, 0xcf, 0x3a, 0xb7, 0x5f, 0x1e, 0x3a, 0x7a, 0x78, 0x9b}; + uint8_t topic_bytes[] = {0xfa, 0x10, 0xe4, 0xac, 0x5a, 0x42, 0xe7, 0xd0, 0x3, 0xaa, 0x65, 0x13, 0xb1, 0xaa, 0xcb}; + lwmqtt_string_t topic = {15, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = false; + uint8_t msg_bytes[] = {0x78, 0x78, 0xc1, 0x42, 0x72, 0x85, 0xcf, 0x3a, 0xb7, 0x5f, 0x1e, 0x3a, 0x7a, 0x78, 0x9b}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 15; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 20110, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "\250\DLE\228\172ZB\231\208\ETX\170e\DC3\177\170\203", _pubPktID = 20110, _pubBody = +// "xx\193Br\133\207:\183_\RS:zx\155", _pubProps = []} +TEST(Publish311QCTest, Decode18) { + uint8_t pkt[] = {0x3a, 0x22, 0x0, 0xf, 0xfa, 0x10, 0xe4, 0xac, 0x5a, 0x42, 0xe7, 0xd0, + 0x3, 0xaa, 0x65, 0x13, 0xb1, 0xaa, 0xcb, 0x4e, 0x8e, 0x78, 0x78, 0xc1, + 0x42, 0x72, 0x85, 0xcf, 0x3a, 0xb7, 0x5f, 0x1e, 0x3a, 0x7a, 0x78, 0x9b}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xfa, 0x10, 0xe4, 0xac, 0x5a, 0x42, 0xe7, 0xd0, 0x3, 0xaa, 0x65, 0x13, 0xb1, 0xaa, 0xcb}; + lwmqtt_string_t exp_topic = {15, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x78, 0x78, 0xc1, 0x42, 0x72, 0x85, 0xcf, 0x3a, 0xb7, 0x5f, 0x1e, 0x3a, 0x7a, 0x78, 0x9b}; + lwmqtt_string_t exp_body = {15, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 20110); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 15); + EXPECT_EQ(msg.payload_len, 15); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 15); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = "\219DL\230\173kI\194", _pubPktID = +// 0, _pubBody = "k@\192\208$\186\173\v\213b\157\255\206\DLE\253xC", _pubProps = []} +TEST(Publish311QCTest, Encode19) { + uint8_t pkt[] = {0x38, 0x1b, 0x0, 0x8, 0xdb, 0x44, 0x4c, 0xe6, 0xad, 0x6b, 0x49, 0xc2, 0x6b, 0x40, 0xc0, + 0xd0, 0x24, 0xba, 0xad, 0xb, 0xd5, 0x62, 0x9d, 0xff, 0xce, 0x10, 0xfd, 0x78, 0x43}; + uint8_t topic_bytes[] = {0xdb, 0x44, 0x4c, 0xe6, 0xad, 0x6b, 0x49, 0xc2}; + lwmqtt_string_t topic = {8, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = false; + uint8_t msg_bytes[] = {0x6b, 0x40, 0xc0, 0xd0, 0x24, 0xba, 0xad, 0xb, 0xd5, + 0x62, 0x9d, 0xff, 0xce, 0x10, 0xfd, 0x78, 0x43}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 17; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = "\219DL\230\173kI\194", _pubPktID = +// 0, _pubBody = "k@\192\208$\186\173\v\213b\157\255\206\DLE\253xC", _pubProps = []} +TEST(Publish311QCTest, Decode19) { + uint8_t pkt[] = {0x38, 0x1b, 0x0, 0x8, 0xdb, 0x44, 0x4c, 0xe6, 0xad, 0x6b, 0x49, 0xc2, 0x6b, 0x40, 0xc0, + 0xd0, 0x24, 0xba, 0xad, 0xb, 0xd5, 0x62, 0x9d, 0xff, 0xce, 0x10, 0xfd, 0x78, 0x43}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xdb, 0x44, 0x4c, 0xe6, 0xad, 0x6b, 0x49, 0xc2}; + lwmqtt_string_t exp_topic = {8, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x6b, 0x40, 0xc0, 0xd0, 0x24, 0xba, 0xad, 0xb, 0xd5, + 0x62, 0x9d, 0xff, 0xce, 0x10, 0xfd, 0x78, 0x43}; + lwmqtt_string_t exp_body = {17, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 8); + EXPECT_EQ(msg.payload_len, 17); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 17); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "{\153\DLEV", _pubPktID = 16334, +// _pubBody = "\SI\238\166\129\190\133\&2k\213\ETBtC\246", _pubProps = []} +TEST(Publish311QCTest, Encode20) { + uint8_t pkt[] = {0x3c, 0x15, 0x0, 0x4, 0x7b, 0x99, 0x10, 0x56, 0x3f, 0xce, 0xf, 0xee, + 0xa6, 0x81, 0xbe, 0x85, 0x32, 0x6b, 0xd5, 0x17, 0x74, 0x43, 0xf6}; + uint8_t topic_bytes[] = {0x7b, 0x99, 0x10, 0x56}; + lwmqtt_string_t topic = {4, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0xf, 0xee, 0xa6, 0x81, 0xbe, 0x85, 0x32, 0x6b, 0xd5, 0x17, 0x74, 0x43, 0xf6}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 13; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 16334, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "{\153\DLEV", _pubPktID = 16334, +// _pubBody = "\SI\238\166\129\190\133\&2k\213\ETBtC\246", _pubProps = []} +TEST(Publish311QCTest, Decode20) { + uint8_t pkt[] = {0x3c, 0x15, 0x0, 0x4, 0x7b, 0x99, 0x10, 0x56, 0x3f, 0xce, 0xf, 0xee, + 0xa6, 0x81, 0xbe, 0x85, 0x32, 0x6b, 0xd5, 0x17, 0x74, 0x43, 0xf6}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x7b, 0x99, 0x10, 0x56}; + lwmqtt_string_t exp_topic = {4, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xf, 0xee, 0xa6, 0x81, 0xbe, 0x85, 0x32, 0x6b, 0xd5, 0x17, 0x74, 0x43, 0xf6}; + lwmqtt_string_t exp_body = {13, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 16334); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 4); + EXPECT_EQ(msg.payload_len, 13); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 13); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "\239\241 \154( +// \247t\"\246\ENQ\203\252\206\225\196\148\STX\222\"(\255\US}\194\188\172", _pubPktID = 17850, _pubBody = +// "\232#X\SOHr.\129\NAK\155\247c\170\231\193Y\254\ESC\ETX\216\&4\235\253EV@\ETB", _pubProps = []} +TEST(Publish311QCTest, Encode21) { + uint8_t pkt[] = {0x3c, 0x39, 0x0, 0x1b, 0xef, 0xf1, 0x20, 0x9a, 0x28, 0x20, 0xf7, 0x74, 0x22, 0xf6, 0x5, + 0xcb, 0xfc, 0xce, 0xe1, 0xc4, 0x94, 0x2, 0xde, 0x22, 0x28, 0xff, 0x1f, 0x7d, 0xc2, 0xbc, + 0xac, 0x45, 0xba, 0xe8, 0x23, 0x58, 0x1, 0x72, 0x2e, 0x81, 0x15, 0x9b, 0xf7, 0x63, 0xaa, + 0xe7, 0xc1, 0x59, 0xfe, 0x1b, 0x3, 0xd8, 0x34, 0xeb, 0xfd, 0x45, 0x56, 0x40, 0x17}; + uint8_t topic_bytes[] = {0xef, 0xf1, 0x20, 0x9a, 0x28, 0x20, 0xf7, 0x74, 0x22, 0xf6, 0x5, 0xcb, 0xfc, 0xce, + 0xe1, 0xc4, 0x94, 0x2, 0xde, 0x22, 0x28, 0xff, 0x1f, 0x7d, 0xc2, 0xbc, 0xac}; + lwmqtt_string_t topic = {27, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0xe8, 0x23, 0x58, 0x1, 0x72, 0x2e, 0x81, 0x15, 0x9b, 0xf7, 0x63, 0xaa, 0xe7, + 0xc1, 0x59, 0xfe, 0x1b, 0x3, 0xd8, 0x34, 0xeb, 0xfd, 0x45, 0x56, 0x40, 0x17}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 26; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 17850, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "\239\241 \154( +// \247t\"\246\ENQ\203\252\206\225\196\148\STX\222\"(\255\US}\194\188\172", _pubPktID = 17850, _pubBody = +// "\232#X\SOHr.\129\NAK\155\247c\170\231\193Y\254\ESC\ETX\216\&4\235\253EV@\ETB", _pubProps = []} +TEST(Publish311QCTest, Decode21) { + uint8_t pkt[] = {0x3c, 0x39, 0x0, 0x1b, 0xef, 0xf1, 0x20, 0x9a, 0x28, 0x20, 0xf7, 0x74, 0x22, 0xf6, 0x5, + 0xcb, 0xfc, 0xce, 0xe1, 0xc4, 0x94, 0x2, 0xde, 0x22, 0x28, 0xff, 0x1f, 0x7d, 0xc2, 0xbc, + 0xac, 0x45, 0xba, 0xe8, 0x23, 0x58, 0x1, 0x72, 0x2e, 0x81, 0x15, 0x9b, 0xf7, 0x63, 0xaa, + 0xe7, 0xc1, 0x59, 0xfe, 0x1b, 0x3, 0xd8, 0x34, 0xeb, 0xfd, 0x45, 0x56, 0x40, 0x17}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xef, 0xf1, 0x20, 0x9a, 0x28, 0x20, 0xf7, 0x74, 0x22, 0xf6, 0x5, 0xcb, 0xfc, 0xce, + 0xe1, 0xc4, 0x94, 0x2, 0xde, 0x22, 0x28, 0xff, 0x1f, 0x7d, 0xc2, 0xbc, 0xac}; + lwmqtt_string_t exp_topic = {27, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xe8, 0x23, 0x58, 0x1, 0x72, 0x2e, 0x81, 0x15, 0x9b, 0xf7, 0x63, 0xaa, 0xe7, + 0xc1, 0x59, 0xfe, 0x1b, 0x3, 0xd8, 0x34, 0xeb, 0xfd, 0x45, 0x56, 0x40, 0x17}; + lwmqtt_string_t exp_body = {26, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 17850); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 27); + EXPECT_EQ(msg.payload_len, 26); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 26); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "\161\229m\129\&2\222w}\252\146\169(\STXu\137Z6\133", _pubPktID = 7546, _pubBody = +// "^\ETX\228\176\224]\220i\211(<\144", _pubProps = []} +TEST(Publish311QCTest, Encode22) { + uint8_t pkt[] = {0x34, 0x22, 0x0, 0x12, 0xa1, 0xe5, 0x6d, 0x81, 0x32, 0xde, 0x77, 0x7d, + 0xfc, 0x92, 0xa9, 0x28, 0x2, 0x75, 0x89, 0x5a, 0x36, 0x85, 0x1d, 0x7a, + 0x5e, 0x3, 0xe4, 0xb0, 0xe0, 0x5d, 0xdc, 0x69, 0xd3, 0x28, 0x3c, 0x90}; + uint8_t topic_bytes[] = {0xa1, 0xe5, 0x6d, 0x81, 0x32, 0xde, 0x77, 0x7d, 0xfc, + 0x92, 0xa9, 0x28, 0x2, 0x75, 0x89, 0x5a, 0x36, 0x85}; + lwmqtt_string_t topic = {18, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0x5e, 0x3, 0xe4, 0xb0, 0xe0, 0x5d, 0xdc, 0x69, 0xd3, 0x28, 0x3c, 0x90}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 12; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 7546, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "\161\229m\129\&2\222w}\252\146\169(\STXu\137Z6\133", _pubPktID = 7546, _pubBody = +// "^\ETX\228\176\224]\220i\211(<\144", _pubProps = []} +TEST(Publish311QCTest, Decode22) { + uint8_t pkt[] = {0x34, 0x22, 0x0, 0x12, 0xa1, 0xe5, 0x6d, 0x81, 0x32, 0xde, 0x77, 0x7d, + 0xfc, 0x92, 0xa9, 0x28, 0x2, 0x75, 0x89, 0x5a, 0x36, 0x85, 0x1d, 0x7a, + 0x5e, 0x3, 0xe4, 0xb0, 0xe0, 0x5d, 0xdc, 0x69, 0xd3, 0x28, 0x3c, 0x90}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xa1, 0xe5, 0x6d, 0x81, 0x32, 0xde, 0x77, 0x7d, 0xfc, + 0x92, 0xa9, 0x28, 0x2, 0x75, 0x89, 0x5a, 0x36, 0x85}; + lwmqtt_string_t exp_topic = {18, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x5e, 0x3, 0xe4, 0xb0, 0xe0, 0x5d, 0xdc, 0x69, 0xd3, 0x28, 0x3c, 0x90}; + lwmqtt_string_t exp_body = {12, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 7546); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 18); + EXPECT_EQ(msg.payload_len, 12); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 12); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "zd\230 jdq?\198\154\202x8", +// _pubPktID = 32533, _pubBody = "\255\DC4\132\246=", _pubProps = []} +TEST(Publish311QCTest, Encode23) { + uint8_t pkt[] = {0x34, 0x16, 0x0, 0xd, 0x7a, 0x64, 0xe6, 0x20, 0x6a, 0x64, 0x71, 0x3f, + 0xc6, 0x9a, 0xca, 0x78, 0x38, 0x7f, 0x15, 0xff, 0x14, 0x84, 0xf6, 0x3d}; + uint8_t topic_bytes[] = {0x7a, 0x64, 0xe6, 0x20, 0x6a, 0x64, 0x71, 0x3f, 0xc6, 0x9a, 0xca, 0x78, 0x38}; + lwmqtt_string_t topic = {13, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0xff, 0x14, 0x84, 0xf6, 0x3d}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 5; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 32533, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "zd\230 jdq?\198\154\202x8", +// _pubPktID = 32533, _pubBody = "\255\DC4\132\246=", _pubProps = []} +TEST(Publish311QCTest, Decode23) { + uint8_t pkt[] = {0x34, 0x16, 0x0, 0xd, 0x7a, 0x64, 0xe6, 0x20, 0x6a, 0x64, 0x71, 0x3f, + 0xc6, 0x9a, 0xca, 0x78, 0x38, 0x7f, 0x15, 0xff, 0x14, 0x84, 0xf6, 0x3d}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x7a, 0x64, 0xe6, 0x20, 0x6a, 0x64, 0x71, 0x3f, 0xc6, 0x9a, 0xca, 0x78, 0x38}; + lwmqtt_string_t exp_topic = {13, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xff, 0x14, 0x84, 0xf6, 0x3d}; + lwmqtt_string_t exp_body = {5, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 32533); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 13); + EXPECT_EQ(msg.payload_len, 5); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 5); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS0, _pubRetain = True, _pubTopic = +// "\ETB\147^4}\135\220\179>\250\156\DELi2\SOH\236\193\164n\239\157\189\229t#`4", _pubPktID = 0, _pubBody = +// "\130\204\173\174\157}\164rT\146\220w\DC1H4\164\DLE\255{", _pubProps = []} +TEST(Publish311QCTest, Encode24) { + uint8_t pkt[] = {0x31, 0x30, 0x0, 0x1b, 0x17, 0x93, 0x5e, 0x34, 0x7d, 0x87, 0xdc, 0xb3, 0x3e, 0xfa, 0x9c, 0x7f, 0x69, + 0x32, 0x1, 0xec, 0xc1, 0xa4, 0x6e, 0xef, 0x9d, 0xbd, 0xe5, 0x74, 0x23, 0x60, 0x34, 0x82, 0xcc, 0xad, + 0xae, 0x9d, 0x7d, 0xa4, 0x72, 0x54, 0x92, 0xdc, 0x77, 0x11, 0x48, 0x34, 0xa4, 0x10, 0xff, 0x7b}; + uint8_t topic_bytes[] = {0x17, 0x93, 0x5e, 0x34, 0x7d, 0x87, 0xdc, 0xb3, 0x3e, 0xfa, 0x9c, 0x7f, 0x69, 0x32, + 0x1, 0xec, 0xc1, 0xa4, 0x6e, 0xef, 0x9d, 0xbd, 0xe5, 0x74, 0x23, 0x60, 0x34}; + lwmqtt_string_t topic = {27, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = true; + uint8_t msg_bytes[] = {0x82, 0xcc, 0xad, 0xae, 0x9d, 0x7d, 0xa4, 0x72, 0x54, 0x92, + 0xdc, 0x77, 0x11, 0x48, 0x34, 0xa4, 0x10, 0xff, 0x7b}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 19; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS0, _pubRetain = True, _pubTopic = +// "\ETB\147^4}\135\220\179>\250\156\DELi2\SOH\236\193\164n\239\157\189\229t#`4", _pubPktID = 0, _pubBody = +// "\130\204\173\174\157}\164rT\146\220w\DC1H4\164\DLE\255{", _pubProps = []} +TEST(Publish311QCTest, Decode24) { + uint8_t pkt[] = {0x31, 0x30, 0x0, 0x1b, 0x17, 0x93, 0x5e, 0x34, 0x7d, 0x87, 0xdc, 0xb3, 0x3e, 0xfa, 0x9c, 0x7f, 0x69, + 0x32, 0x1, 0xec, 0xc1, 0xa4, 0x6e, 0xef, 0x9d, 0xbd, 0xe5, 0x74, 0x23, 0x60, 0x34, 0x82, 0xcc, 0xad, + 0xae, 0x9d, 0x7d, 0xa4, 0x72, 0x54, 0x92, 0xdc, 0x77, 0x11, 0x48, 0x34, 0xa4, 0x10, 0xff, 0x7b}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x17, 0x93, 0x5e, 0x34, 0x7d, 0x87, 0xdc, 0xb3, 0x3e, 0xfa, 0x9c, 0x7f, 0x69, 0x32, + 0x1, 0xec, 0xc1, 0xa4, 0x6e, 0xef, 0x9d, 0xbd, 0xe5, 0x74, 0x23, 0x60, 0x34}; + lwmqtt_string_t exp_topic = {27, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x82, 0xcc, 0xad, 0xae, 0x9d, 0x7d, 0xa4, 0x72, 0x54, 0x92, + 0xdc, 0x77, 0x11, 0x48, 0x34, 0xa4, 0x10, 0xff, 0x7b}; + lwmqtt_string_t exp_body = {19, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 27); + EXPECT_EQ(msg.payload_len, 19); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 19); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "q:@l\229vEU\235iQ\v", _pubPktID = +// 23637, _pubBody = "\169\252\159\196(\144\135\181\129*7\EOT&B\216\183\244\DC3\129\142\224\229", _pubProps = []} +TEST(Publish311QCTest, Encode25) { + uint8_t pkt[] = {0x33, 0x26, 0x0, 0xc, 0x71, 0x3a, 0x40, 0x6c, 0xe5, 0x76, 0x45, 0x55, 0xeb, 0x69, + 0x51, 0xb, 0x5c, 0x55, 0xa9, 0xfc, 0x9f, 0xc4, 0x28, 0x90, 0x87, 0xb5, 0x81, 0x2a, + 0x37, 0x4, 0x26, 0x42, 0xd8, 0xb7, 0xf4, 0x13, 0x81, 0x8e, 0xe0, 0xe5}; + uint8_t topic_bytes[] = {0x71, 0x3a, 0x40, 0x6c, 0xe5, 0x76, 0x45, 0x55, 0xeb, 0x69, 0x51, 0xb}; + lwmqtt_string_t topic = {12, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0xa9, 0xfc, 0x9f, 0xc4, 0x28, 0x90, 0x87, 0xb5, 0x81, 0x2a, 0x37, + 0x4, 0x26, 0x42, 0xd8, 0xb7, 0xf4, 0x13, 0x81, 0x8e, 0xe0, 0xe5}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 22; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, false, 23637, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "q:@l\229vEU\235iQ\v", _pubPktID = +// 23637, _pubBody = "\169\252\159\196(\144\135\181\129*7\EOT&B\216\183\244\DC3\129\142\224\229", _pubProps = []} +TEST(Publish311QCTest, Decode25) { + uint8_t pkt[] = {0x33, 0x26, 0x0, 0xc, 0x71, 0x3a, 0x40, 0x6c, 0xe5, 0x76, 0x45, 0x55, 0xeb, 0x69, + 0x51, 0xb, 0x5c, 0x55, 0xa9, 0xfc, 0x9f, 0xc4, 0x28, 0x90, 0x87, 0xb5, 0x81, 0x2a, + 0x37, 0x4, 0x26, 0x42, 0xd8, 0xb7, 0xf4, 0x13, 0x81, 0x8e, 0xe0, 0xe5}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x71, 0x3a, 0x40, 0x6c, 0xe5, 0x76, 0x45, 0x55, 0xeb, 0x69, 0x51, 0xb}; + lwmqtt_string_t exp_topic = {12, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xa9, 0xfc, 0x9f, 0xc4, 0x28, 0x90, 0x87, 0xb5, 0x81, 0x2a, 0x37, + 0x4, 0x26, 0x42, 0xd8, 0xb7, 0xf4, 0x13, 0x81, 0x8e, 0xe0, 0xe5}; + lwmqtt_string_t exp_body = {22, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 23637); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 12); + EXPECT_EQ(msg.payload_len, 22); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 22); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "n#\187\187\173\198I,k\145\183\237\142\194", _pubPktID = 8993, _pubBody = "\147{\192\230\144\DC3\130j\217\194h +// E\159\201\161s\154\199\201<\227", _pubProps = []} +TEST(Publish311QCTest, Encode26) { + uint8_t pkt[] = {0x3b, 0x28, 0x0, 0xe, 0x6e, 0x23, 0xbb, 0xbb, 0xad, 0xc6, 0x49, 0x2c, 0x6b, 0x91, + 0xb7, 0xed, 0x8e, 0xc2, 0x23, 0x21, 0x93, 0x7b, 0xc0, 0xe6, 0x90, 0x13, 0x82, 0x6a, + 0xd9, 0xc2, 0x68, 0x20, 0x45, 0x9f, 0xc9, 0xa1, 0x73, 0x9a, 0xc7, 0xc9, 0x3c, 0xe3}; + uint8_t topic_bytes[] = {0x6e, 0x23, 0xbb, 0xbb, 0xad, 0xc6, 0x49, 0x2c, 0x6b, 0x91, 0xb7, 0xed, 0x8e, 0xc2}; + lwmqtt_string_t topic = {14, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0x93, 0x7b, 0xc0, 0xe6, 0x90, 0x13, 0x82, 0x6a, 0xd9, 0xc2, 0x68, + 0x20, 0x45, 0x9f, 0xc9, 0xa1, 0x73, 0x9a, 0xc7, 0xc9, 0x3c, 0xe3}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 22; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 8993, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "n#\187\187\173\198I,k\145\183\237\142\194", _pubPktID = 8993, _pubBody = "\147{\192\230\144\DC3\130j\217\194h +// E\159\201\161s\154\199\201<\227", _pubProps = []} +TEST(Publish311QCTest, Decode26) { + uint8_t pkt[] = {0x3b, 0x28, 0x0, 0xe, 0x6e, 0x23, 0xbb, 0xbb, 0xad, 0xc6, 0x49, 0x2c, 0x6b, 0x91, + 0xb7, 0xed, 0x8e, 0xc2, 0x23, 0x21, 0x93, 0x7b, 0xc0, 0xe6, 0x90, 0x13, 0x82, 0x6a, + 0xd9, 0xc2, 0x68, 0x20, 0x45, 0x9f, 0xc9, 0xa1, 0x73, 0x9a, 0xc7, 0xc9, 0x3c, 0xe3}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x6e, 0x23, 0xbb, 0xbb, 0xad, 0xc6, 0x49, 0x2c, 0x6b, 0x91, 0xb7, 0xed, 0x8e, 0xc2}; + lwmqtt_string_t exp_topic = {14, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x93, 0x7b, 0xc0, 0xe6, 0x90, 0x13, 0x82, 0x6a, 0xd9, 0xc2, 0x68, + 0x20, 0x45, 0x9f, 0xc9, 0xa1, 0x73, 0x9a, 0xc7, 0xc9, 0x3c, 0xe3}; + lwmqtt_string_t exp_body = {22, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 8993); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 14); + EXPECT_EQ(msg.payload_len, 22); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 22); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = "'w%\200$\223R\DC4`", _pubPktID = +// 8207, _pubBody = "\253\145\215\176fT\SO\155P\211\218(topic.data), 9); + EXPECT_EQ(msg.payload_len, 19); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 19); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = "m\237T", _pubPktID = 0, _pubBody = +// "K\240\171\DC4,?a}f\GS\244\&7\181\255]\138\150\206|\148\140\128>", _pubProps = []} +TEST(Publish311QCTest, Encode28) { + uint8_t pkt[] = {0x38, 0x1c, 0x0, 0x3, 0x6d, 0xed, 0x54, 0x4b, 0xf0, 0xab, 0x14, 0x2c, 0x3f, 0x61, 0x7d, + 0x66, 0x1d, 0xf4, 0x37, 0xb5, 0xff, 0x5d, 0x8a, 0x96, 0xce, 0x7c, 0x94, 0x8c, 0x80, 0x3e}; + uint8_t topic_bytes[] = {0x6d, 0xed, 0x54}; + lwmqtt_string_t topic = {3, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = false; + uint8_t msg_bytes[] = {0x4b, 0xf0, 0xab, 0x14, 0x2c, 0x3f, 0x61, 0x7d, 0x66, 0x1d, 0xf4, 0x37, + 0xb5, 0xff, 0x5d, 0x8a, 0x96, 0xce, 0x7c, 0x94, 0x8c, 0x80, 0x3e}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 23; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = "m\237T", _pubPktID = 0, _pubBody = +// "K\240\171\DC4,?a}f\GS\244\&7\181\255]\138\150\206|\148\140\128>", _pubProps = []} +TEST(Publish311QCTest, Decode28) { + uint8_t pkt[] = {0x38, 0x1c, 0x0, 0x3, 0x6d, 0xed, 0x54, 0x4b, 0xf0, 0xab, 0x14, 0x2c, 0x3f, 0x61, 0x7d, + 0x66, 0x1d, 0xf4, 0x37, 0xb5, 0xff, 0x5d, 0x8a, 0x96, 0xce, 0x7c, 0x94, 0x8c, 0x80, 0x3e}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x6d, 0xed, 0x54}; + lwmqtt_string_t exp_topic = {3, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x4b, 0xf0, 0xab, 0x14, 0x2c, 0x3f, 0x61, 0x7d, 0x66, 0x1d, 0xf4, 0x37, + 0xb5, 0xff, 0x5d, 0x8a, 0x96, 0xce, 0x7c, 0x94, 0x8c, 0x80, 0x3e}; + lwmqtt_string_t exp_body = {23, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 3); + EXPECT_EQ(msg.payload_len, 23); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 23); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "r\223", _pubPktID = 0, _pubBody = +// "Y&\241\149_\178", _pubProps = []} +TEST(Publish311QCTest, Encode29) { + uint8_t pkt[] = {0x39, 0xa, 0x0, 0x2, 0x72, 0xdf, 0x59, 0x26, 0xf1, 0x95, 0x5f, 0xb2}; + uint8_t topic_bytes[] = {0x72, 0xdf}; + lwmqtt_string_t topic = {2, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = true; + uint8_t msg_bytes[] = {0x59, 0x26, 0xf1, 0x95, 0x5f, 0xb2}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 6; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "r\223", _pubPktID = 0, _pubBody = +// "Y&\241\149_\178", _pubProps = []} +TEST(Publish311QCTest, Decode29) { + uint8_t pkt[] = {0x39, 0xa, 0x0, 0x2, 0x72, 0xdf, 0x59, 0x26, 0xf1, 0x95, 0x5f, 0xb2}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x72, 0xdf}; + lwmqtt_string_t exp_topic = {2, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x59, 0x26, 0xf1, 0x95, 0x5f, 0xb2}; + lwmqtt_string_t exp_body = {6, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 2); + EXPECT_EQ(msg.payload_len, 6); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 6); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\247\220n\163\233a\SO%/\218\186\&6\163Z\GS\ESC3\b\189\140I\131\129\177\185\197\163\188\&6\SYN", _pubPktID = 3711, +// _pubBody = "\205H\232\STX\178\&33\r\237\140\240o\166", _pubProps = []} +TEST(Publish311QCTest, Encode30) { + uint8_t pkt[] = {0x3b, 0x2f, 0x0, 0x1e, 0xf7, 0xdc, 0x6e, 0xa3, 0xe9, 0x61, 0xe, 0x25, 0x2f, 0xda, 0xba, 0x36, 0xa3, + 0x5a, 0x1d, 0x1b, 0x33, 0x8, 0xbd, 0x8c, 0x49, 0x83, 0x81, 0xb1, 0xb9, 0xc5, 0xa3, 0xbc, 0x36, 0x16, + 0xe, 0x7f, 0xcd, 0x48, 0xe8, 0x2, 0xb2, 0x33, 0x33, 0xd, 0xed, 0x8c, 0xf0, 0x6f, 0xa6}; + uint8_t topic_bytes[] = {0xf7, 0xdc, 0x6e, 0xa3, 0xe9, 0x61, 0xe, 0x25, 0x2f, 0xda, 0xba, 0x36, 0xa3, 0x5a, 0x1d, + 0x1b, 0x33, 0x8, 0xbd, 0x8c, 0x49, 0x83, 0x81, 0xb1, 0xb9, 0xc5, 0xa3, 0xbc, 0x36, 0x16}; + lwmqtt_string_t topic = {30, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0xcd, 0x48, 0xe8, 0x2, 0xb2, 0x33, 0x33, 0xd, 0xed, 0x8c, 0xf0, 0x6f, 0xa6}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 13; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT311, true, 3711, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\247\220n\163\233a\SO%/\218\186\&6\163Z\GS\ESC3\b\189\140I\131\129\177\185\197\163\188\&6\SYN", _pubPktID = 3711, +// _pubBody = "\205H\232\STX\178\&33\r\237\140\240o\166", _pubProps = []} +TEST(Publish311QCTest, Decode30) { + uint8_t pkt[] = {0x3b, 0x2f, 0x0, 0x1e, 0xf7, 0xdc, 0x6e, 0xa3, 0xe9, 0x61, 0xe, 0x25, 0x2f, 0xda, 0xba, 0x36, 0xa3, + 0x5a, 0x1d, 0x1b, 0x33, 0x8, 0xbd, 0x8c, 0x49, 0x83, 0x81, 0xb1, 0xb9, 0xc5, 0xa3, 0xbc, 0x36, 0x16, + 0xe, 0x7f, 0xcd, 0x48, 0xe8, 0x2, 0xb2, 0x33, 0x33, 0xd, 0xed, 0x8c, 0xf0, 0x6f, 0xa6}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xf7, 0xdc, 0x6e, 0xa3, 0xe9, 0x61, 0xe, 0x25, 0x2f, 0xda, + 0xba, 0x36, 0xa3, 0x5a, 0x1d, 0x1b, 0x33, 0x8, 0xbd, 0x8c, + 0x49, 0x83, 0x81, 0xb1, 0xb9, 0xc5, 0xa3, 0xbc, 0x36, 0x16}; + lwmqtt_string_t exp_topic = {30, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xcd, 0x48, 0xe8, 0x2, 0xb2, 0x33, 0x33, 0xd, 0xed, 0x8c, 0xf0, 0x6f, 0xa6}; + lwmqtt_string_t exp_body = {13, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 3711); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 30); + EXPECT_EQ(msg.payload_len, 13); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 13); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "", _pubPktID = 0, _pubBody = +// "\201\174\&5}Y\150\209fI\146", _pubProps = [PropServerReference +// "\SO\163\208\252\142?\206\ESCT\225\204",PropSubscriptionIdentifierAvailable 224,PropTopicAlias 17121,PropReasonString +// "\165\239(topic.data), 0); + EXPECT_EQ(msg.payload_len, 10); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 10); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\178\&4?\195\154\241'~\229S\255\SO\a40\221\ESC\221:N\212F\r\188l", _pubPktID = 2511, _pubBody = +// "'6\224\138\ETB\f{\166\251\224\EM", _pubProps = []} +TEST(Publish5QCTest, Encode2) { + uint8_t pkt[] = {0x33, 0x29, 0x0, 0x19, 0xb2, 0x34, 0x3f, 0xc3, 0x9a, 0xf1, 0x27, 0x7e, 0xe5, 0x53, 0xff, + 0xe, 0x7, 0x34, 0x30, 0xdd, 0x1b, 0xdd, 0x3a, 0x4e, 0xd4, 0x46, 0xd, 0xbc, 0x6c, 0x9, + 0xcf, 0x0, 0x27, 0x36, 0xe0, 0x8a, 0x17, 0xc, 0x7b, 0xa6, 0xfb, 0xe0, 0x19}; + uint8_t topic_bytes[] = {0xb2, 0x34, 0x3f, 0xc3, 0x9a, 0xf1, 0x27, 0x7e, 0xe5, 0x53, 0xff, 0xe, 0x7, + 0x34, 0x30, 0xdd, 0x1b, 0xdd, 0x3a, 0x4e, 0xd4, 0x46, 0xd, 0xbc, 0x6c}; + lwmqtt_string_t topic = {25, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0x27, 0x36, 0xe0, 0x8a, 0x17, 0xc, 0x7b, 0xa6, 0xfb, 0xe0, 0x19}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 11; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, false, 2511, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\178\&4?\195\154\241'~\229S\255\SO\a40\221\ESC\221:N\212F\r\188l", _pubPktID = 2511, _pubBody = +// "'6\224\138\ETB\f{\166\251\224\EM", _pubProps = []} +TEST(Publish5QCTest, Decode2) { + uint8_t pkt[] = {0x33, 0x29, 0x0, 0x19, 0xb2, 0x34, 0x3f, 0xc3, 0x9a, 0xf1, 0x27, 0x7e, 0xe5, 0x53, 0xff, + 0xe, 0x7, 0x34, 0x30, 0xdd, 0x1b, 0xdd, 0x3a, 0x4e, 0xd4, 0x46, 0xd, 0xbc, 0x6c, 0x9, + 0xcf, 0x0, 0x27, 0x36, 0xe0, 0x8a, 0x17, 0xc, 0x7b, 0xa6, 0xfb, 0xe0, 0x19}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xb2, 0x34, 0x3f, 0xc3, 0x9a, 0xf1, 0x27, 0x7e, 0xe5, 0x53, 0xff, 0xe, 0x7, + 0x34, 0x30, 0xdd, 0x1b, 0xdd, 0x3a, 0x4e, 0xd4, 0x46, 0xd, 0xbc, 0x6c}; + lwmqtt_string_t exp_topic = {25, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x27, 0x36, 0xe0, 0x8a, 0x17, 0xc, 0x7b, 0xa6, 0xfb, 0xe0, 0x19}; + lwmqtt_string_t exp_body = {11, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 2511); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 25); + EXPECT_EQ(msg.payload_len, 11); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 11); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = +// "J\178\233\r\ETBB\156\DC4\237T\199\169", _pubPktID = 0, _pubBody = +// "\"\231\233q\224v\140\216\174\175\203\242]\142\187\218", _pubProps = [PropMessageExpiryInterval 1264,PropTopicAlias +// 3580,PropWillDelayInterval 9612,PropAuthenticationMethod +// "\r\196\&4\180Y-\231\174\159\&6\DELp)\211\212",PropCorrelationData +// ")\186\234,,p\245f\153\181jO\237\DC3WC\227/Zf\DLEL\238",PropSubscriptionIdentifierAvailable 135,PropReceiveMaximum +// 11740,PropServerKeepAlive 13427,PropAuthenticationData "C\180\221G\f\148/\234",PropResponseTopic +// "?vF@\136\182Yh=-\232\242\221\183\210\238\166",PropTopicAliasMaximum 31328,PropServerReference "\EM",PropUserProperty +// "\234\146\SYNa\222" "b^$l\221a{\216\192\162\DC3\242R",PropRetainAvailable 64,PropResponseInformation +// "\168\223ks\197\RS~\DLE\207",PropResponseTopic +// "\161\192\&4*\167\238\203\137\249\254\187x\169",PropRequestProblemInformation 243,PropTopicAliasMaximum +// 21304,PropCorrelationData "C}\143E",PropResponseInformation "H\STX\237a\229 +// ['i\DEL\135\141W7b\232\196\168\&2",PropSessionExpiryInterval 2527,PropSharedSubscriptionAvailable +// 171,PropAuthenticationMethod "DV\251\195\180\195\&1\t\226w\aY\173Cl:Ie\165",PropAuthenticationData +// "\209\137\NUL^\177\SOH\DC1\226\182IZ\149\236\RS\155\SUB\DEL\SI\144\191E\161\v\239\141y\132",PropAuthenticationMethod +// "\174\137\186\a?\233\DEL\244's\138\202\160",PropReceiveMaximum 4919,PropTopicAliasMaximum +// 27071,PropSubscriptionIdentifierAvailable 123]} +TEST(Publish5QCTest, Encode3) { + uint8_t pkt[] = { + 0x38, 0xb1, 0x2, 0x0, 0xc, 0x4a, 0xb2, 0xe9, 0xd, 0x17, 0x42, 0x9c, 0x14, 0xed, 0x54, 0xc7, 0xa9, 0x91, 0x2, + 0x2, 0x0, 0x0, 0x4, 0xf0, 0x23, 0xd, 0xfc, 0x18, 0x0, 0x0, 0x25, 0x8c, 0x15, 0x0, 0xf, 0xd, 0xc4, 0x34, + 0xb4, 0x59, 0x2d, 0xe7, 0xae, 0x9f, 0x36, 0x7f, 0x70, 0x29, 0xd3, 0xd4, 0x9, 0x0, 0x17, 0x29, 0xba, 0xea, 0x2c, + 0x2c, 0x70, 0xf5, 0x66, 0x99, 0xb5, 0x6a, 0x4f, 0xed, 0x13, 0x57, 0x43, 0xe3, 0x2f, 0x5a, 0x66, 0x10, 0x4c, 0xee, + 0x29, 0x87, 0x21, 0x2d, 0xdc, 0x13, 0x34, 0x73, 0x16, 0x0, 0x8, 0x43, 0xb4, 0xdd, 0x47, 0xc, 0x94, 0x2f, 0xea, + 0x8, 0x0, 0x11, 0x3f, 0x76, 0x46, 0x40, 0x88, 0xb6, 0x59, 0x68, 0x3d, 0x2d, 0xe8, 0xf2, 0xdd, 0xb7, 0xd2, 0xee, + 0xa6, 0x22, 0x7a, 0x60, 0x1c, 0x0, 0x1, 0x19, 0x26, 0x0, 0x5, 0xea, 0x92, 0x16, 0x61, 0xde, 0x0, 0xd, 0x62, + 0x5e, 0x24, 0x6c, 0xdd, 0x61, 0x7b, 0xd8, 0xc0, 0xa2, 0x13, 0xf2, 0x52, 0x25, 0x40, 0x1a, 0x0, 0x9, 0xa8, 0xdf, + 0x6b, 0x73, 0xc5, 0x1e, 0x7e, 0x10, 0xcf, 0x8, 0x0, 0xd, 0xa1, 0xc0, 0x34, 0x2a, 0xa7, 0xee, 0xcb, 0x89, 0xf9, + 0xfe, 0xbb, 0x78, 0xa9, 0x17, 0xf3, 0x22, 0x53, 0x38, 0x9, 0x0, 0x4, 0x43, 0x7d, 0x8f, 0x45, 0x1a, 0x0, 0x13, + 0x48, 0x2, 0xed, 0x61, 0xe5, 0x20, 0x5b, 0x27, 0x69, 0x7f, 0x87, 0x8d, 0x57, 0x37, 0x62, 0xe8, 0xc4, 0xa8, 0x32, + 0x11, 0x0, 0x0, 0x9, 0xdf, 0x2a, 0xab, 0x15, 0x0, 0x13, 0x44, 0x56, 0xfb, 0xc3, 0xb4, 0xc3, 0x31, 0x9, 0xe2, + 0x77, 0x7, 0x59, 0xad, 0x43, 0x6c, 0x3a, 0x49, 0x65, 0xa5, 0x16, 0x0, 0x1b, 0xd1, 0x89, 0x0, 0x5e, 0xb1, 0x1, + 0x11, 0xe2, 0xb6, 0x49, 0x5a, 0x95, 0xec, 0x1e, 0x9b, 0x1a, 0x7f, 0xf, 0x90, 0xbf, 0x45, 0xa1, 0xb, 0xef, 0x8d, + 0x79, 0x84, 0x15, 0x0, 0xd, 0xae, 0x89, 0xba, 0x7, 0x3f, 0xe9, 0x7f, 0xf4, 0x27, 0x73, 0x8a, 0xca, 0xa0, 0x21, + 0x13, 0x37, 0x22, 0x69, 0xbf, 0x29, 0x7b, 0x22, 0xe7, 0xe9, 0x71, 0xe0, 0x76, 0x8c, 0xd8, 0xae, 0xaf, 0xcb, 0xf2, + 0x5d, 0x8e, 0xbb, 0xda}; + uint8_t topic_bytes[] = {0x4a, 0xb2, 0xe9, 0xd, 0x17, 0x42, 0x9c, 0x14, 0xed, 0x54, 0xc7, 0xa9}; + lwmqtt_string_t topic = {12, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = false; + uint8_t msg_bytes[] = {0x22, 0xe7, 0xe9, 0x71, 0xe0, 0x76, 0x8c, 0xd8, + 0xae, 0xaf, 0xcb, 0xf2, 0x5d, 0x8e, 0xbb, 0xda}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 16; + + uint8_t bytesprops0[] = {0xd, 0xc4, 0x34, 0xb4, 0x59, 0x2d, 0xe7, 0xae, 0x9f, 0x36, 0x7f, 0x70, 0x29, 0xd3, 0xd4}; + uint8_t bytesprops1[] = {0x29, 0xba, 0xea, 0x2c, 0x2c, 0x70, 0xf5, 0x66, 0x99, 0xb5, 0x6a, 0x4f, + 0xed, 0x13, 0x57, 0x43, 0xe3, 0x2f, 0x5a, 0x66, 0x10, 0x4c, 0xee}; + uint8_t bytesprops2[] = {0x43, 0xb4, 0xdd, 0x47, 0xc, 0x94, 0x2f, 0xea}; + uint8_t bytesprops3[] = {0x3f, 0x76, 0x46, 0x40, 0x88, 0xb6, 0x59, 0x68, 0x3d, + 0x2d, 0xe8, 0xf2, 0xdd, 0xb7, 0xd2, 0xee, 0xa6}; + uint8_t bytesprops4[] = {0x19}; + uint8_t bytesprops6[] = {0x62, 0x5e, 0x24, 0x6c, 0xdd, 0x61, 0x7b, 0xd8, 0xc0, 0xa2, 0x13, 0xf2, 0x52}; + uint8_t bytesprops5[] = {0xea, 0x92, 0x16, 0x61, 0xde}; + uint8_t bytesprops7[] = {0xa8, 0xdf, 0x6b, 0x73, 0xc5, 0x1e, 0x7e, 0x10, 0xcf}; + uint8_t bytesprops8[] = {0xa1, 0xc0, 0x34, 0x2a, 0xa7, 0xee, 0xcb, 0x89, 0xf9, 0xfe, 0xbb, 0x78, 0xa9}; + uint8_t bytesprops9[] = {0x43, 0x7d, 0x8f, 0x45}; + uint8_t bytesprops10[] = {0x48, 0x2, 0xed, 0x61, 0xe5, 0x20, 0x5b, 0x27, 0x69, 0x7f, + 0x87, 0x8d, 0x57, 0x37, 0x62, 0xe8, 0xc4, 0xa8, 0x32}; + uint8_t bytesprops11[] = {0x44, 0x56, 0xfb, 0xc3, 0xb4, 0xc3, 0x31, 0x9, 0xe2, 0x77, + 0x7, 0x59, 0xad, 0x43, 0x6c, 0x3a, 0x49, 0x65, 0xa5}; + uint8_t bytesprops12[] = {0xd1, 0x89, 0x0, 0x5e, 0xb1, 0x1, 0x11, 0xe2, 0xb6, 0x49, 0x5a, 0x95, 0xec, 0x1e, + 0x9b, 0x1a, 0x7f, 0xf, 0x90, 0xbf, 0x45, 0xa1, 0xb, 0xef, 0x8d, 0x79, 0x84}; + uint8_t bytesprops13[] = {0xae, 0x89, 0xba, 0x7, 0x3f, 0xe9, 0x7f, 0xf4, 0x27, 0x73, 0x8a, 0xca, 0xa0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 1264}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 3580}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 9612}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {15, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {23, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 135}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 11740}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 13427}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {8, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {17, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 31328}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {1, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {5, (char*)&bytesprops5}, .v = {13, (char*)&bytesprops6}}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 64}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {9, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {13, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 243}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 21304}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {4, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {19, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 2527}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 171}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {19, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {27, (char*)&bytesprops12}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {13, (char*)&bytesprops13}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 4919}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 27071}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 123}}, + }; + + lwmqtt_properties_t props = {28, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = +// "J\178\233\r\ETBB\156\DC4\237T\199\169", _pubPktID = 0, _pubBody = +// "\"\231\233q\224v\140\216\174\175\203\242]\142\187\218", _pubProps = [PropMessageExpiryInterval 1264,PropTopicAlias +// 3580,PropWillDelayInterval 9612,PropAuthenticationMethod +// "\r\196\&4\180Y-\231\174\159\&6\DELp)\211\212",PropCorrelationData +// ")\186\234,,p\245f\153\181jO\237\DC3WC\227/Zf\DLEL\238",PropSubscriptionIdentifierAvailable 135,PropReceiveMaximum +// 11740,PropServerKeepAlive 13427,PropAuthenticationData "C\180\221G\f\148/\234",PropResponseTopic +// "?vF@\136\182Yh=-\232\242\221\183\210\238\166",PropTopicAliasMaximum 31328,PropServerReference "\EM",PropUserProperty +// "\234\146\SYNa\222" "b^$l\221a{\216\192\162\DC3\242R",PropRetainAvailable 64,PropResponseInformation +// "\168\223ks\197\RS~\DLE\207",PropResponseTopic +// "\161\192\&4*\167\238\203\137\249\254\187x\169",PropRequestProblemInformation 243,PropTopicAliasMaximum +// 21304,PropCorrelationData "C}\143E",PropResponseInformation "H\STX\237a\229 +// ['i\DEL\135\141W7b\232\196\168\&2",PropSessionExpiryInterval 2527,PropSharedSubscriptionAvailable +// 171,PropAuthenticationMethod "DV\251\195\180\195\&1\t\226w\aY\173Cl:Ie\165",PropAuthenticationData +// "\209\137\NUL^\177\SOH\DC1\226\182IZ\149\236\RS\155\SUB\DEL\SI\144\191E\161\v\239\141y\132",PropAuthenticationMethod +// "\174\137\186\a?\233\DEL\244's\138\202\160",PropReceiveMaximum 4919,PropTopicAliasMaximum +// 27071,PropSubscriptionIdentifierAvailable 123]} +TEST(Publish5QCTest, Decode3) { + uint8_t pkt[] = { + 0x38, 0xb1, 0x2, 0x0, 0xc, 0x4a, 0xb2, 0xe9, 0xd, 0x17, 0x42, 0x9c, 0x14, 0xed, 0x54, 0xc7, 0xa9, 0x91, 0x2, + 0x2, 0x0, 0x0, 0x4, 0xf0, 0x23, 0xd, 0xfc, 0x18, 0x0, 0x0, 0x25, 0x8c, 0x15, 0x0, 0xf, 0xd, 0xc4, 0x34, + 0xb4, 0x59, 0x2d, 0xe7, 0xae, 0x9f, 0x36, 0x7f, 0x70, 0x29, 0xd3, 0xd4, 0x9, 0x0, 0x17, 0x29, 0xba, 0xea, 0x2c, + 0x2c, 0x70, 0xf5, 0x66, 0x99, 0xb5, 0x6a, 0x4f, 0xed, 0x13, 0x57, 0x43, 0xe3, 0x2f, 0x5a, 0x66, 0x10, 0x4c, 0xee, + 0x29, 0x87, 0x21, 0x2d, 0xdc, 0x13, 0x34, 0x73, 0x16, 0x0, 0x8, 0x43, 0xb4, 0xdd, 0x47, 0xc, 0x94, 0x2f, 0xea, + 0x8, 0x0, 0x11, 0x3f, 0x76, 0x46, 0x40, 0x88, 0xb6, 0x59, 0x68, 0x3d, 0x2d, 0xe8, 0xf2, 0xdd, 0xb7, 0xd2, 0xee, + 0xa6, 0x22, 0x7a, 0x60, 0x1c, 0x0, 0x1, 0x19, 0x26, 0x0, 0x5, 0xea, 0x92, 0x16, 0x61, 0xde, 0x0, 0xd, 0x62, + 0x5e, 0x24, 0x6c, 0xdd, 0x61, 0x7b, 0xd8, 0xc0, 0xa2, 0x13, 0xf2, 0x52, 0x25, 0x40, 0x1a, 0x0, 0x9, 0xa8, 0xdf, + 0x6b, 0x73, 0xc5, 0x1e, 0x7e, 0x10, 0xcf, 0x8, 0x0, 0xd, 0xa1, 0xc0, 0x34, 0x2a, 0xa7, 0xee, 0xcb, 0x89, 0xf9, + 0xfe, 0xbb, 0x78, 0xa9, 0x17, 0xf3, 0x22, 0x53, 0x38, 0x9, 0x0, 0x4, 0x43, 0x7d, 0x8f, 0x45, 0x1a, 0x0, 0x13, + 0x48, 0x2, 0xed, 0x61, 0xe5, 0x20, 0x5b, 0x27, 0x69, 0x7f, 0x87, 0x8d, 0x57, 0x37, 0x62, 0xe8, 0xc4, 0xa8, 0x32, + 0x11, 0x0, 0x0, 0x9, 0xdf, 0x2a, 0xab, 0x15, 0x0, 0x13, 0x44, 0x56, 0xfb, 0xc3, 0xb4, 0xc3, 0x31, 0x9, 0xe2, + 0x77, 0x7, 0x59, 0xad, 0x43, 0x6c, 0x3a, 0x49, 0x65, 0xa5, 0x16, 0x0, 0x1b, 0xd1, 0x89, 0x0, 0x5e, 0xb1, 0x1, + 0x11, 0xe2, 0xb6, 0x49, 0x5a, 0x95, 0xec, 0x1e, 0x9b, 0x1a, 0x7f, 0xf, 0x90, 0xbf, 0x45, 0xa1, 0xb, 0xef, 0x8d, + 0x79, 0x84, 0x15, 0x0, 0xd, 0xae, 0x89, 0xba, 0x7, 0x3f, 0xe9, 0x7f, 0xf4, 0x27, 0x73, 0x8a, 0xca, 0xa0, 0x21, + 0x13, 0x37, 0x22, 0x69, 0xbf, 0x29, 0x7b, 0x22, 0xe7, 0xe9, 0x71, 0xe0, 0x76, 0x8c, 0xd8, 0xae, 0xaf, 0xcb, 0xf2, + 0x5d, 0x8e, 0xbb, 0xda}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x4a, 0xb2, 0xe9, 0xd, 0x17, 0x42, 0x9c, 0x14, 0xed, 0x54, 0xc7, 0xa9}; + lwmqtt_string_t exp_topic = {12, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x22, 0xe7, 0xe9, 0x71, 0xe0, 0x76, 0x8c, 0xd8, + 0xae, 0xaf, 0xcb, 0xf2, 0x5d, 0x8e, 0xbb, 0xda}; + lwmqtt_string_t exp_body = {16, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 12); + EXPECT_EQ(msg.payload_len, 16); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 16); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "(\166\195\173\148\GS\175\209g\RS\b\244\191\221\186\\Z\149\158\195\NUL\158\202{\242", _pubPktID = 7293, _pubBody = +// "\177?\SI\SI1\226\146\135\CAN\224\SYNIK\STX\237y\n\SUBT\185\&7$\f\253My\202C", _pubProps = [PropWillDelayInterval +// 18682,PropResponseInformation "H}\155#U\190\244\FS\DC2\220d]\CAN\145?*<",PropMessageExpiryInterval +// 22657,PropReceiveMaximum 20643,PropTopicAlias 12097,PropSessionExpiryInterval 278,PropContentType +// "\221a9\153\217$\152\150\DEL\STX\140V\214\DC3\129\234\254\EOT",PropMaximumQoS 172,PropServerReference +// "\228\173\STX",PropReceiveMaximum 16352,PropMessageExpiryInterval 21359,PropContentType +// "\147\226\217\177\149\SO6\247\138P\160\254\149?\129\NAK\RS}\176\203\tU\160S\244\229/B\b\b",PropSubscriptionIdentifier +// 26,PropServerReference "\250\NAK\tv\r\DC3 \185\199\155+\189\222\190\EOT\201\&3\164^\137",PropSessionExpiryInterval +// 27140,PropMessageExpiryInterval 22865]} +TEST(Publish5QCTest, Encode4) { + uint8_t pkt[] = { + 0x32, 0xcd, 0x1, 0x0, 0x19, 0x28, 0xa6, 0xc3, 0xad, 0x94, 0x1d, 0xaf, 0xd1, 0x67, 0x1e, 0x8, 0xf4, 0xbf, 0xdd, + 0xba, 0x5c, 0x5a, 0x95, 0x9e, 0xc3, 0x0, 0x9e, 0xca, 0x7b, 0xf2, 0x1c, 0x7d, 0x92, 0x1, 0x18, 0x0, 0x0, 0x48, + 0xfa, 0x1a, 0x0, 0x11, 0x48, 0x7d, 0x9b, 0x23, 0x55, 0xbe, 0xf4, 0x1c, 0x12, 0xdc, 0x64, 0x5d, 0x18, 0x91, 0x3f, + 0x2a, 0x3c, 0x2, 0x0, 0x0, 0x58, 0x81, 0x21, 0x50, 0xa3, 0x23, 0x2f, 0x41, 0x11, 0x0, 0x0, 0x1, 0x16, 0x3, + 0x0, 0x12, 0xdd, 0x61, 0x39, 0x99, 0xd9, 0x24, 0x98, 0x96, 0x7f, 0x2, 0x8c, 0x56, 0xd6, 0x13, 0x81, 0xea, 0xfe, + 0x4, 0x24, 0xac, 0x1c, 0x0, 0x3, 0xe4, 0xad, 0x2, 0x21, 0x3f, 0xe0, 0x2, 0x0, 0x0, 0x53, 0x6f, 0x3, 0x0, + 0x1e, 0x93, 0xe2, 0xd9, 0xb1, 0x95, 0xe, 0x36, 0xf7, 0x8a, 0x50, 0xa0, 0xfe, 0x95, 0x3f, 0x81, 0x15, 0x1e, 0x7d, + 0xb0, 0xcb, 0x9, 0x55, 0xa0, 0x53, 0xf4, 0xe5, 0x2f, 0x42, 0x8, 0x8, 0xb, 0x1a, 0x1c, 0x0, 0x14, 0xfa, 0x15, + 0x9, 0x76, 0xd, 0x13, 0x20, 0xb9, 0xc7, 0x9b, 0x2b, 0xbd, 0xde, 0xbe, 0x4, 0xc9, 0x33, 0xa4, 0x5e, 0x89, 0x11, + 0x0, 0x0, 0x6a, 0x4, 0x2, 0x0, 0x0, 0x59, 0x51, 0xb1, 0x3f, 0xf, 0xf, 0x31, 0xe2, 0x92, 0x87, 0x18, 0xe0, + 0x16, 0x49, 0x4b, 0x2, 0xed, 0x79, 0xa, 0x1a, 0x54, 0xb9, 0x37, 0x24, 0xc, 0xfd, 0x4d, 0x79, 0xca, 0x43}; + uint8_t topic_bytes[] = {0x28, 0xa6, 0xc3, 0xad, 0x94, 0x1d, 0xaf, 0xd1, 0x67, 0x1e, 0x8, 0xf4, 0xbf, + 0xdd, 0xba, 0x5c, 0x5a, 0x95, 0x9e, 0xc3, 0x0, 0x9e, 0xca, 0x7b, 0xf2}; + lwmqtt_string_t topic = {25, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = false; + uint8_t msg_bytes[] = {0xb1, 0x3f, 0xf, 0xf, 0x31, 0xe2, 0x92, 0x87, 0x18, 0xe0, 0x16, 0x49, 0x4b, 0x2, + 0xed, 0x79, 0xa, 0x1a, 0x54, 0xb9, 0x37, 0x24, 0xc, 0xfd, 0x4d, 0x79, 0xca, 0x43}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 28; + + uint8_t bytesprops0[] = {0x48, 0x7d, 0x9b, 0x23, 0x55, 0xbe, 0xf4, 0x1c, 0x12, + 0xdc, 0x64, 0x5d, 0x18, 0x91, 0x3f, 0x2a, 0x3c}; + uint8_t bytesprops1[] = {0xdd, 0x61, 0x39, 0x99, 0xd9, 0x24, 0x98, 0x96, 0x7f, + 0x2, 0x8c, 0x56, 0xd6, 0x13, 0x81, 0xea, 0xfe, 0x4}; + uint8_t bytesprops2[] = {0xe4, 0xad, 0x2}; + uint8_t bytesprops3[] = {0x93, 0xe2, 0xd9, 0xb1, 0x95, 0xe, 0x36, 0xf7, 0x8a, 0x50, 0xa0, 0xfe, 0x95, 0x3f, 0x81, + 0x15, 0x1e, 0x7d, 0xb0, 0xcb, 0x9, 0x55, 0xa0, 0x53, 0xf4, 0xe5, 0x2f, 0x42, 0x8, 0x8}; + uint8_t bytesprops4[] = {0xfa, 0x15, 0x9, 0x76, 0xd, 0x13, 0x20, 0xb9, 0xc7, 0x9b, + 0x2b, 0xbd, 0xde, 0xbe, 0x4, 0xc9, 0x33, 0xa4, 0x5e, 0x89}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 18682}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {17, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 22657}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 20643}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 12097}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 278}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {18, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 172}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {3, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 16352}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 21359}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {30, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 26}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {20, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 27140}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 22865}}, + }; + + lwmqtt_properties_t props = {16, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, false, 7293, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "(\166\195\173\148\GS\175\209g\RS\b\244\191\221\186\\Z\149\158\195\NUL\158\202{\242", _pubPktID = 7293, _pubBody = +// "\177?\SI\SI1\226\146\135\CAN\224\SYNIK\STX\237y\n\SUBT\185\&7$\f\253My\202C", _pubProps = [PropWillDelayInterval +// 18682,PropResponseInformation "H}\155#U\190\244\FS\DC2\220d]\CAN\145?*<",PropMessageExpiryInterval +// 22657,PropReceiveMaximum 20643,PropTopicAlias 12097,PropSessionExpiryInterval 278,PropContentType +// "\221a9\153\217$\152\150\DEL\STX\140V\214\DC3\129\234\254\EOT",PropMaximumQoS 172,PropServerReference +// "\228\173\STX",PropReceiveMaximum 16352,PropMessageExpiryInterval 21359,PropContentType +// "\147\226\217\177\149\SO6\247\138P\160\254\149?\129\NAK\RS}\176\203\tU\160S\244\229/B\b\b",PropSubscriptionIdentifier +// 26,PropServerReference "\250\NAK\tv\r\DC3 \185\199\155+\189\222\190\EOT\201\&3\164^\137",PropSessionExpiryInterval +// 27140,PropMessageExpiryInterval 22865]} +TEST(Publish5QCTest, Decode4) { + uint8_t pkt[] = { + 0x32, 0xcd, 0x1, 0x0, 0x19, 0x28, 0xa6, 0xc3, 0xad, 0x94, 0x1d, 0xaf, 0xd1, 0x67, 0x1e, 0x8, 0xf4, 0xbf, 0xdd, + 0xba, 0x5c, 0x5a, 0x95, 0x9e, 0xc3, 0x0, 0x9e, 0xca, 0x7b, 0xf2, 0x1c, 0x7d, 0x92, 0x1, 0x18, 0x0, 0x0, 0x48, + 0xfa, 0x1a, 0x0, 0x11, 0x48, 0x7d, 0x9b, 0x23, 0x55, 0xbe, 0xf4, 0x1c, 0x12, 0xdc, 0x64, 0x5d, 0x18, 0x91, 0x3f, + 0x2a, 0x3c, 0x2, 0x0, 0x0, 0x58, 0x81, 0x21, 0x50, 0xa3, 0x23, 0x2f, 0x41, 0x11, 0x0, 0x0, 0x1, 0x16, 0x3, + 0x0, 0x12, 0xdd, 0x61, 0x39, 0x99, 0xd9, 0x24, 0x98, 0x96, 0x7f, 0x2, 0x8c, 0x56, 0xd6, 0x13, 0x81, 0xea, 0xfe, + 0x4, 0x24, 0xac, 0x1c, 0x0, 0x3, 0xe4, 0xad, 0x2, 0x21, 0x3f, 0xe0, 0x2, 0x0, 0x0, 0x53, 0x6f, 0x3, 0x0, + 0x1e, 0x93, 0xe2, 0xd9, 0xb1, 0x95, 0xe, 0x36, 0xf7, 0x8a, 0x50, 0xa0, 0xfe, 0x95, 0x3f, 0x81, 0x15, 0x1e, 0x7d, + 0xb0, 0xcb, 0x9, 0x55, 0xa0, 0x53, 0xf4, 0xe5, 0x2f, 0x42, 0x8, 0x8, 0xb, 0x1a, 0x1c, 0x0, 0x14, 0xfa, 0x15, + 0x9, 0x76, 0xd, 0x13, 0x20, 0xb9, 0xc7, 0x9b, 0x2b, 0xbd, 0xde, 0xbe, 0x4, 0xc9, 0x33, 0xa4, 0x5e, 0x89, 0x11, + 0x0, 0x0, 0x6a, 0x4, 0x2, 0x0, 0x0, 0x59, 0x51, 0xb1, 0x3f, 0xf, 0xf, 0x31, 0xe2, 0x92, 0x87, 0x18, 0xe0, + 0x16, 0x49, 0x4b, 0x2, 0xed, 0x79, 0xa, 0x1a, 0x54, 0xb9, 0x37, 0x24, 0xc, 0xfd, 0x4d, 0x79, 0xca, 0x43}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x28, 0xa6, 0xc3, 0xad, 0x94, 0x1d, 0xaf, 0xd1, 0x67, 0x1e, 0x8, 0xf4, 0xbf, + 0xdd, 0xba, 0x5c, 0x5a, 0x95, 0x9e, 0xc3, 0x0, 0x9e, 0xca, 0x7b, 0xf2}; + lwmqtt_string_t exp_topic = {25, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xb1, 0x3f, 0xf, 0xf, 0x31, 0xe2, 0x92, 0x87, 0x18, 0xe0, 0x16, 0x49, 0x4b, 0x2, + 0xed, 0x79, 0xa, 0x1a, 0x54, 0xb9, 0x37, 0x24, 0xc, 0xfd, 0x4d, 0x79, 0xca, 0x43}; + lwmqtt_string_t exp_body = {28, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 7293); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 25); + EXPECT_EQ(msg.payload_len, 28); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 28); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "\239!qf)\DC1R\192\227\STX\227\191\ENQ\163\242\172\201\233\225\150\242\USr\DEL", _pubPktID = 8490, _pubBody = +// "Hj(;\171\211\&2\147\237^\SO\175\143\&0\161\182\EM", _pubProps = [PropAuthenticationMethod +// "\155\STXSfY\fa\STXz\ACK\206\226l\168L)\204\196",PropMessageExpiryInterval 19840,PropAssignedClientIdentifier +// "\FS*\218\218\153\&0_\206\235\227\ETBpul\226f\224\180\\S0T\155\SOH`+\228\168\229\&4",PropPayloadFormatIndicator +// 31,PropMessageExpiryInterval 13212,PropSubscriptionIdentifierAvailable 132,PropSubscriptionIdentifierAvailable +// 199,PropWillDelayInterval 1350,PropWillDelayInterval 26412,PropResponseTopic +// "\146\173\SUB{\157\248w+",PropReasonString +// "\170\202\211Z\208\216I\GS\DC4u\r1\134\156<\135+\232K8\164\208R\DEL\217\130\130\SUBU\157"]} +TEST(Publish5QCTest, Encode5) { + uint8_t pkt[] = {0x32, 0xaa, 0x1, 0x0, 0x18, 0xef, 0x21, 0x71, 0x66, 0x29, 0x11, 0x52, 0xc0, 0xe3, 0x2, 0xe3, + 0xbf, 0x5, 0xa3, 0xf2, 0xac, 0xc9, 0xe9, 0xe1, 0x96, 0xf2, 0x1f, 0x72, 0x7f, 0x21, 0x2a, 0x7c, + 0x15, 0x0, 0x12, 0x9b, 0x2, 0x53, 0x66, 0x59, 0xc, 0x61, 0x2, 0x7a, 0x6, 0xce, 0xe2, 0x6c, + 0xa8, 0x4c, 0x29, 0xcc, 0xc4, 0x2, 0x0, 0x0, 0x4d, 0x80, 0x12, 0x0, 0x1e, 0x1c, 0x2a, 0xda, + 0xda, 0x99, 0x30, 0x5f, 0xce, 0xeb, 0xe3, 0x17, 0x70, 0x75, 0x6c, 0xe2, 0x66, 0xe0, 0xb4, 0x5c, + 0x53, 0x30, 0x54, 0x9b, 0x1, 0x60, 0x2b, 0xe4, 0xa8, 0xe5, 0x34, 0x1, 0x1f, 0x2, 0x0, 0x0, + 0x33, 0x9c, 0x29, 0x84, 0x29, 0xc7, 0x18, 0x0, 0x0, 0x5, 0x46, 0x18, 0x0, 0x0, 0x67, 0x2c, + 0x8, 0x0, 0x8, 0x92, 0xad, 0x1a, 0x7b, 0x9d, 0xf8, 0x77, 0x2b, 0x1f, 0x0, 0x1e, 0xaa, 0xca, + 0xd3, 0x5a, 0xd0, 0xd8, 0x49, 0x1d, 0x14, 0x75, 0xd, 0x31, 0x86, 0x9c, 0x3c, 0x87, 0x2b, 0xe8, + 0x4b, 0x38, 0xa4, 0xd0, 0x52, 0x7f, 0xd9, 0x82, 0x82, 0x1a, 0x55, 0x9d, 0x48, 0x6a, 0x28, 0x3b, + 0xab, 0xd3, 0x32, 0x93, 0xed, 0x5e, 0xe, 0xaf, 0x8f, 0x30, 0xa1, 0xb6, 0x19}; + uint8_t topic_bytes[] = {0xef, 0x21, 0x71, 0x66, 0x29, 0x11, 0x52, 0xc0, 0xe3, 0x2, 0xe3, 0xbf, + 0x5, 0xa3, 0xf2, 0xac, 0xc9, 0xe9, 0xe1, 0x96, 0xf2, 0x1f, 0x72, 0x7f}; + lwmqtt_string_t topic = {24, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = false; + uint8_t msg_bytes[] = {0x48, 0x6a, 0x28, 0x3b, 0xab, 0xd3, 0x32, 0x93, 0xed, + 0x5e, 0xe, 0xaf, 0x8f, 0x30, 0xa1, 0xb6, 0x19}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 17; + + uint8_t bytesprops0[] = {0x9b, 0x2, 0x53, 0x66, 0x59, 0xc, 0x61, 0x2, 0x7a, + 0x6, 0xce, 0xe2, 0x6c, 0xa8, 0x4c, 0x29, 0xcc, 0xc4}; + uint8_t bytesprops1[] = {0x1c, 0x2a, 0xda, 0xda, 0x99, 0x30, 0x5f, 0xce, 0xeb, 0xe3, 0x17, 0x70, 0x75, 0x6c, 0xe2, + 0x66, 0xe0, 0xb4, 0x5c, 0x53, 0x30, 0x54, 0x9b, 0x1, 0x60, 0x2b, 0xe4, 0xa8, 0xe5, 0x34}; + uint8_t bytesprops2[] = {0x92, 0xad, 0x1a, 0x7b, 0x9d, 0xf8, 0x77, 0x2b}; + uint8_t bytesprops3[] = {0xaa, 0xca, 0xd3, 0x5a, 0xd0, 0xd8, 0x49, 0x1d, 0x14, 0x75, 0xd, 0x31, 0x86, 0x9c, 0x3c, + 0x87, 0x2b, 0xe8, 0x4b, 0x38, 0xa4, 0xd0, 0x52, 0x7f, 0xd9, 0x82, 0x82, 0x1a, 0x55, 0x9d}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)21, .value = {.str = {18, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 19840}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {30, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 31}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 13212}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 132}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 199}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 1350}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 26412}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {8, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {30, (char*)&bytesprops3}}}, + }; + + lwmqtt_properties_t props = {11, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, false, 8490, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "\239!qf)\DC1R\192\227\STX\227\191\ENQ\163\242\172\201\233\225\150\242\USr\DEL", _pubPktID = 8490, _pubBody = +// "Hj(;\171\211\&2\147\237^\SO\175\143\&0\161\182\EM", _pubProps = [PropAuthenticationMethod +// "\155\STXSfY\fa\STXz\ACK\206\226l\168L)\204\196",PropMessageExpiryInterval 19840,PropAssignedClientIdentifier +// "\FS*\218\218\153\&0_\206\235\227\ETBpul\226f\224\180\\S0T\155\SOH`+\228\168\229\&4",PropPayloadFormatIndicator +// 31,PropMessageExpiryInterval 13212,PropSubscriptionIdentifierAvailable 132,PropSubscriptionIdentifierAvailable +// 199,PropWillDelayInterval 1350,PropWillDelayInterval 26412,PropResponseTopic +// "\146\173\SUB{\157\248w+",PropReasonString +// "\170\202\211Z\208\216I\GS\DC4u\r1\134\156<\135+\232K8\164\208R\DEL\217\130\130\SUBU\157"]} +TEST(Publish5QCTest, Decode5) { + uint8_t pkt[] = {0x32, 0xaa, 0x1, 0x0, 0x18, 0xef, 0x21, 0x71, 0x66, 0x29, 0x11, 0x52, 0xc0, 0xe3, 0x2, 0xe3, + 0xbf, 0x5, 0xa3, 0xf2, 0xac, 0xc9, 0xe9, 0xe1, 0x96, 0xf2, 0x1f, 0x72, 0x7f, 0x21, 0x2a, 0x7c, + 0x15, 0x0, 0x12, 0x9b, 0x2, 0x53, 0x66, 0x59, 0xc, 0x61, 0x2, 0x7a, 0x6, 0xce, 0xe2, 0x6c, + 0xa8, 0x4c, 0x29, 0xcc, 0xc4, 0x2, 0x0, 0x0, 0x4d, 0x80, 0x12, 0x0, 0x1e, 0x1c, 0x2a, 0xda, + 0xda, 0x99, 0x30, 0x5f, 0xce, 0xeb, 0xe3, 0x17, 0x70, 0x75, 0x6c, 0xe2, 0x66, 0xe0, 0xb4, 0x5c, + 0x53, 0x30, 0x54, 0x9b, 0x1, 0x60, 0x2b, 0xe4, 0xa8, 0xe5, 0x34, 0x1, 0x1f, 0x2, 0x0, 0x0, + 0x33, 0x9c, 0x29, 0x84, 0x29, 0xc7, 0x18, 0x0, 0x0, 0x5, 0x46, 0x18, 0x0, 0x0, 0x67, 0x2c, + 0x8, 0x0, 0x8, 0x92, 0xad, 0x1a, 0x7b, 0x9d, 0xf8, 0x77, 0x2b, 0x1f, 0x0, 0x1e, 0xaa, 0xca, + 0xd3, 0x5a, 0xd0, 0xd8, 0x49, 0x1d, 0x14, 0x75, 0xd, 0x31, 0x86, 0x9c, 0x3c, 0x87, 0x2b, 0xe8, + 0x4b, 0x38, 0xa4, 0xd0, 0x52, 0x7f, 0xd9, 0x82, 0x82, 0x1a, 0x55, 0x9d, 0x48, 0x6a, 0x28, 0x3b, + 0xab, 0xd3, 0x32, 0x93, 0xed, 0x5e, 0xe, 0xaf, 0x8f, 0x30, 0xa1, 0xb6, 0x19}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xef, 0x21, 0x71, 0x66, 0x29, 0x11, 0x52, 0xc0, 0xe3, 0x2, 0xe3, 0xbf, + 0x5, 0xa3, 0xf2, 0xac, 0xc9, 0xe9, 0xe1, 0x96, 0xf2, 0x1f, 0x72, 0x7f}; + lwmqtt_string_t exp_topic = {24, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x48, 0x6a, 0x28, 0x3b, 0xab, 0xd3, 0x32, 0x93, 0xed, + 0x5e, 0xe, 0xaf, 0x8f, 0x30, 0xa1, 0xb6, 0x19}; + lwmqtt_string_t exp_body = {17, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 8490); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 24); + EXPECT_EQ(msg.payload_len, 17); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 17); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "~\225\DLELiZW,vB\173`\255\CAN+\v\194\238", _pubPktID = 25725, _pubBody = +// "\188\SO\205\140\237\238\138\149\210\239m\246\ACK>\DC4\249\182\183(\131\128\&5\164X\173\&0C", _pubProps = +// [PropReceiveMaximum 12703]} +TEST(Publish5QCTest, Encode6) { + uint8_t pkt[] = {0x3c, 0x35, 0x0, 0x12, 0x7e, 0xe1, 0x10, 0x4c, 0x69, 0x5a, 0x57, 0x2c, 0x76, 0x42, + 0xad, 0x60, 0xff, 0x18, 0x2b, 0xb, 0xc2, 0xee, 0x64, 0x7d, 0x3, 0x21, 0x31, 0x9f, + 0xbc, 0xe, 0xcd, 0x8c, 0xed, 0xee, 0x8a, 0x95, 0xd2, 0xef, 0x6d, 0xf6, 0x6, 0x3e, + 0x14, 0xf9, 0xb6, 0xb7, 0x28, 0x83, 0x80, 0x35, 0xa4, 0x58, 0xad, 0x30, 0x43}; + uint8_t topic_bytes[] = {0x7e, 0xe1, 0x10, 0x4c, 0x69, 0x5a, 0x57, 0x2c, 0x76, + 0x42, 0xad, 0x60, 0xff, 0x18, 0x2b, 0xb, 0xc2, 0xee}; + lwmqtt_string_t topic = {18, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0xbc, 0xe, 0xcd, 0x8c, 0xed, 0xee, 0x8a, 0x95, 0xd2, 0xef, 0x6d, 0xf6, 0x6, 0x3e, + 0x14, 0xf9, 0xb6, 0xb7, 0x28, 0x83, 0x80, 0x35, 0xa4, 0x58, 0xad, 0x30, 0x43}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 27; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 12703}}, + }; + + lwmqtt_properties_t props = {1, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 25725, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "~\225\DLELiZW,vB\173`\255\CAN+\v\194\238", _pubPktID = 25725, _pubBody = +// "\188\SO\205\140\237\238\138\149\210\239m\246\ACK>\DC4\249\182\183(\131\128\&5\164X\173\&0C", _pubProps = +// [PropReceiveMaximum 12703]} +TEST(Publish5QCTest, Decode6) { + uint8_t pkt[] = {0x3c, 0x35, 0x0, 0x12, 0x7e, 0xe1, 0x10, 0x4c, 0x69, 0x5a, 0x57, 0x2c, 0x76, 0x42, + 0xad, 0x60, 0xff, 0x18, 0x2b, 0xb, 0xc2, 0xee, 0x64, 0x7d, 0x3, 0x21, 0x31, 0x9f, + 0xbc, 0xe, 0xcd, 0x8c, 0xed, 0xee, 0x8a, 0x95, 0xd2, 0xef, 0x6d, 0xf6, 0x6, 0x3e, + 0x14, 0xf9, 0xb6, 0xb7, 0x28, 0x83, 0x80, 0x35, 0xa4, 0x58, 0xad, 0x30, 0x43}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x7e, 0xe1, 0x10, 0x4c, 0x69, 0x5a, 0x57, 0x2c, 0x76, + 0x42, 0xad, 0x60, 0xff, 0x18, 0x2b, 0xb, 0xc2, 0xee}; + lwmqtt_string_t exp_topic = {18, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xbc, 0xe, 0xcd, 0x8c, 0xed, 0xee, 0x8a, 0x95, 0xd2, 0xef, 0x6d, 0xf6, 0x6, 0x3e, + 0x14, 0xf9, 0xb6, 0xb7, 0x28, 0x83, 0x80, 0x35, 0xa4, 0x58, 0xad, 0x30, 0x43}; + lwmqtt_string_t exp_body = {27, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 25725); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 18); + EXPECT_EQ(msg.payload_len, 27); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 27); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "_\173\SI\187N\192\141\207\237\228\129\187v\189VY\232b\187N\179\SO", _pubPktID = 26097, _pubBody = +// "\175\134\253\152O\211\174\USV\DC4\249", _pubProps = [PropSessionExpiryInterval 8242,PropAssignedClientIdentifier +// "=\128<\205\223\254\&0i\134\SI",PropWildcardSubscriptionAvailable 114]} +TEST(Publish5QCTest, Encode7) { + uint8_t pkt[] = {0x34, 0x3a, 0x0, 0x16, 0x5f, 0xad, 0xf, 0xbb, 0x4e, 0xc0, 0x8d, 0xcf, 0xed, 0xe4, 0x81, + 0xbb, 0x76, 0xbd, 0x56, 0x59, 0xe8, 0x62, 0xbb, 0x4e, 0xb3, 0xe, 0x65, 0xf1, 0x14, 0x11, + 0x0, 0x0, 0x20, 0x32, 0x12, 0x0, 0xa, 0x3d, 0x80, 0x3c, 0xcd, 0xdf, 0xfe, 0x30, 0x69, + 0x86, 0xf, 0x28, 0x72, 0xaf, 0x86, 0xfd, 0x98, 0x4f, 0xd3, 0xae, 0x1f, 0x56, 0x14, 0xf9}; + uint8_t topic_bytes[] = {0x5f, 0xad, 0xf, 0xbb, 0x4e, 0xc0, 0x8d, 0xcf, 0xed, 0xe4, 0x81, + 0xbb, 0x76, 0xbd, 0x56, 0x59, 0xe8, 0x62, 0xbb, 0x4e, 0xb3, 0xe}; + lwmqtt_string_t topic = {22, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0xaf, 0x86, 0xfd, 0x98, 0x4f, 0xd3, 0xae, 0x1f, 0x56, 0x14, 0xf9}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 11; + + uint8_t bytesprops0[] = {0x3d, 0x80, 0x3c, 0xcd, 0xdf, 0xfe, 0x30, 0x69, 0x86, 0xf}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 8242}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {10, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 114}}, + }; + + lwmqtt_properties_t props = {3, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, false, 26097, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "_\173\SI\187N\192\141\207\237\228\129\187v\189VY\232b\187N\179\SO", _pubPktID = 26097, _pubBody = +// "\175\134\253\152O\211\174\USV\DC4\249", _pubProps = [PropSessionExpiryInterval 8242,PropAssignedClientIdentifier +// "=\128<\205\223\254\&0i\134\SI",PropWildcardSubscriptionAvailable 114]} +TEST(Publish5QCTest, Decode7) { + uint8_t pkt[] = {0x34, 0x3a, 0x0, 0x16, 0x5f, 0xad, 0xf, 0xbb, 0x4e, 0xc0, 0x8d, 0xcf, 0xed, 0xe4, 0x81, + 0xbb, 0x76, 0xbd, 0x56, 0x59, 0xe8, 0x62, 0xbb, 0x4e, 0xb3, 0xe, 0x65, 0xf1, 0x14, 0x11, + 0x0, 0x0, 0x20, 0x32, 0x12, 0x0, 0xa, 0x3d, 0x80, 0x3c, 0xcd, 0xdf, 0xfe, 0x30, 0x69, + 0x86, 0xf, 0x28, 0x72, 0xaf, 0x86, 0xfd, 0x98, 0x4f, 0xd3, 0xae, 0x1f, 0x56, 0x14, 0xf9}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x5f, 0xad, 0xf, 0xbb, 0x4e, 0xc0, 0x8d, 0xcf, 0xed, 0xe4, 0x81, + 0xbb, 0x76, 0xbd, 0x56, 0x59, 0xe8, 0x62, 0xbb, 0x4e, 0xb3, 0xe}; + lwmqtt_string_t exp_topic = {22, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xaf, 0x86, 0xfd, 0x98, 0x4f, 0xd3, 0xae, 0x1f, 0x56, 0x14, 0xf9}; + lwmqtt_string_t exp_body = {11, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 26097); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 22); + EXPECT_EQ(msg.payload_len, 11); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 11); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = False, _pubTopic = "\196L\196\FS8\154\173\EOT\225", +// _pubPktID = 3661, _pubBody = "\223\209u\180\&7\134", _pubProps = [PropAuthenticationData +// "8\242\149\STX\142\232\236K57\187P\bZ[\155\234\201\FS\234\250\203\228\255\247\128j",PropMaximumPacketSize +// 10847,PropWildcardSubscriptionAvailable 114,PropSubscriptionIdentifier 12,PropReasonString +// "\226\236\192|\209\&9\165\160\192Q\DC1\168\SUB\136 \187\159\SO\236c!\167a\204E\146\194\183\227",PropCorrelationData +// "/x\EM ]\215",PropMaximumPacketSize 19933,PropRequestProblemInformation 192,PropUserProperty +// "\r\132)wI\144\NUL\183\204\232V\251e\ENQ@\230J\206g\234\207kM\137\SUB\221\RS\DEL" +// ":^\230\GS\249\211\203\148\166\SYN\134\RS\158}",PropContentType +// "\242,%fqgX\253\180\154\194i\133\b\NUL\135",PropResponseTopic +// "\141\207\a\SUB\EOT\128\154\162H\169|\145&'\235]\ETB\206\&1D\208\&37\ETB\189\ETB%\227C|",PropPayloadFormatIndicator +// 179,PropSubscriptionIdentifierAvailable 125,PropUserProperty +// "B\152\&6f\189=p\139\238%D\187Pp\149\241R\245o\183\219\138\SI\f\128='\232" +// "\224\213wq0\200l\227Z\162_\218C\230",PropTopicAlias 4914,PropAssignedClientIdentifier +// "n\139}\242\228\177U@iyrc\178",PropAuthenticationData +// "z8\229U|\SI\249\236\ENQ\161\215\SI\248\195\145\154\227\EOTQ\235U",PropAuthenticationMethod +// "\188.\150(topic.data), 9); + EXPECT_EQ(msg.payload_len, 6); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 6); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\b\201MSc\140\128\CANs\162;\213\155\SO\151\139\229\SOH\229\197", _pubPktID = 30138, _pubBody = +// "`6\148\134s,\US`Z\206\157\252jI5w9\138e\176\183\141}", _pubProps = [PropPayloadFormatIndicator +// 239,PropMessageExpiryInterval 25489,PropPayloadFormatIndicator 87,PropCorrelationData +// "\ENQ\204\US\r\STX\\\188qj\SOHE\172\200\250\234\ACK\DC3\232\&2\166\160\211\181\171n",PropResponseTopic +// "V\243\141\153\DC3\251\n\134\151\214j\179\DC4",PropWillDelayInterval 3022,PropSubscriptionIdentifier +// 15,PropMessageExpiryInterval 11715,PropTopicAliasMaximum 13906,PropRetainAvailable 42,PropRetainAvailable +// 76,PropSessionExpiryInterval 27363,PropReceiveMaximum 29328,PropWillDelayInterval 24879,PropServerKeepAlive +// 29253,PropWillDelayInterval 30252,PropMessageExpiryInterval 6762,PropMaximumPacketSize 20996,PropAuthenticationMethod +// "\227",PropRequestResponseInformation 246,PropServerReference +// "\DLE\224oNcK\245R\166\204\226\166\152e8\241\148\187\GS\226\a\178\215\168\&4",PropTopicAlias 4733,PropContentType +// "A\155\212\167\236\169*\253k\DC2\ri\247\246",PropReasonString "-l\234\131"]} +TEST(Publish5QCTest, Encode9) { + uint8_t pkt[] = {0x3b, 0xd5, 0x1, 0x0, 0x14, 0x8, 0xc9, 0x4d, 0x53, 0x63, 0x8c, 0x80, 0x18, 0x73, 0xa2, 0x3b, 0xd5, + 0x9b, 0xe, 0x97, 0x8b, 0xe5, 0x1, 0xe5, 0xc5, 0x75, 0xba, 0xa4, 0x1, 0x1, 0xef, 0x2, 0x0, 0x0, + 0x63, 0x91, 0x1, 0x57, 0x9, 0x0, 0x19, 0x5, 0xcc, 0x1f, 0xd, 0x2, 0x5c, 0xbc, 0x71, 0x6a, 0x1, + 0x45, 0xac, 0xc8, 0xfa, 0xea, 0x6, 0x13, 0xe8, 0x32, 0xa6, 0xa0, 0xd3, 0xb5, 0xab, 0x6e, 0x8, 0x0, + 0xd, 0x56, 0xf3, 0x8d, 0x99, 0x13, 0xfb, 0xa, 0x86, 0x97, 0xd6, 0x6a, 0xb3, 0x14, 0x18, 0x0, 0x0, + 0xb, 0xce, 0xb, 0xf, 0x2, 0x0, 0x0, 0x2d, 0xc3, 0x22, 0x36, 0x52, 0x25, 0x2a, 0x25, 0x4c, 0x11, + 0x0, 0x0, 0x6a, 0xe3, 0x21, 0x72, 0x90, 0x18, 0x0, 0x0, 0x61, 0x2f, 0x13, 0x72, 0x45, 0x18, 0x0, + 0x0, 0x76, 0x2c, 0x2, 0x0, 0x0, 0x1a, 0x6a, 0x27, 0x0, 0x0, 0x52, 0x4, 0x15, 0x0, 0x1, 0xe3, + 0x19, 0xf6, 0x1c, 0x0, 0x19, 0x10, 0xe0, 0x6f, 0x4e, 0x63, 0x4b, 0xf5, 0x52, 0xa6, 0xcc, 0xe2, 0xa6, + 0x98, 0x65, 0x38, 0xf1, 0x94, 0xbb, 0x1d, 0xe2, 0x7, 0xb2, 0xd7, 0xa8, 0x34, 0x23, 0x12, 0x7d, 0x3, + 0x0, 0xe, 0x41, 0x9b, 0xd4, 0xa7, 0xec, 0xa9, 0x2a, 0xfd, 0x6b, 0x12, 0xd, 0x69, 0xf7, 0xf6, 0x1f, + 0x0, 0x4, 0x2d, 0x6c, 0xea, 0x83, 0x60, 0x36, 0x94, 0x86, 0x73, 0x2c, 0x1f, 0x60, 0x5a, 0xce, 0x9d, + 0xfc, 0x6a, 0x49, 0x35, 0x77, 0x39, 0x8a, 0x65, 0xb0, 0xb7, 0x8d, 0x7d}; + uint8_t topic_bytes[] = {0x8, 0xc9, 0x4d, 0x53, 0x63, 0x8c, 0x80, 0x18, 0x73, 0xa2, + 0x3b, 0xd5, 0x9b, 0xe, 0x97, 0x8b, 0xe5, 0x1, 0xe5, 0xc5}; + lwmqtt_string_t topic = {20, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0x60, 0x36, 0x94, 0x86, 0x73, 0x2c, 0x1f, 0x60, 0x5a, 0xce, 0x9d, 0xfc, + 0x6a, 0x49, 0x35, 0x77, 0x39, 0x8a, 0x65, 0xb0, 0xb7, 0x8d, 0x7d}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 23; + + uint8_t bytesprops0[] = {0x5, 0xcc, 0x1f, 0xd, 0x2, 0x5c, 0xbc, 0x71, 0x6a, 0x1, 0x45, 0xac, 0xc8, + 0xfa, 0xea, 0x6, 0x13, 0xe8, 0x32, 0xa6, 0xa0, 0xd3, 0xb5, 0xab, 0x6e}; + uint8_t bytesprops1[] = {0x56, 0xf3, 0x8d, 0x99, 0x13, 0xfb, 0xa, 0x86, 0x97, 0xd6, 0x6a, 0xb3, 0x14}; + uint8_t bytesprops2[] = {0xe3}; + uint8_t bytesprops3[] = {0x10, 0xe0, 0x6f, 0x4e, 0x63, 0x4b, 0xf5, 0x52, 0xa6, 0xcc, 0xe2, 0xa6, 0x98, + 0x65, 0x38, 0xf1, 0x94, 0xbb, 0x1d, 0xe2, 0x7, 0xb2, 0xd7, 0xa8, 0x34}; + uint8_t bytesprops4[] = {0x41, 0x9b, 0xd4, 0xa7, 0xec, 0xa9, 0x2a, 0xfd, 0x6b, 0x12, 0xd, 0x69, 0xf7, 0xf6}; + uint8_t bytesprops5[] = {0x2d, 0x6c, 0xea, 0x83}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 239}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 25489}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 87}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {25, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {13, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 3022}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 15}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 11715}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 13906}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 42}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 76}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 27363}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 29328}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 24879}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 29253}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 30252}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 6762}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 20996}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {1, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 246}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {25, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 4733}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {14, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {4, (char*)&bytesprops5}}}, + }; + + lwmqtt_properties_t props = {24, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 30138, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\b\201MSc\140\128\CANs\162;\213\155\SO\151\139\229\SOH\229\197", _pubPktID = 30138, _pubBody = +// "`6\148\134s,\US`Z\206\157\252jI5w9\138e\176\183\141}", _pubProps = [PropPayloadFormatIndicator +// 239,PropMessageExpiryInterval 25489,PropPayloadFormatIndicator 87,PropCorrelationData +// "\ENQ\204\US\r\STX\\\188qj\SOHE\172\200\250\234\ACK\DC3\232\&2\166\160\211\181\171n",PropResponseTopic +// "V\243\141\153\DC3\251\n\134\151\214j\179\DC4",PropWillDelayInterval 3022,PropSubscriptionIdentifier +// 15,PropMessageExpiryInterval 11715,PropTopicAliasMaximum 13906,PropRetainAvailable 42,PropRetainAvailable +// 76,PropSessionExpiryInterval 27363,PropReceiveMaximum 29328,PropWillDelayInterval 24879,PropServerKeepAlive +// 29253,PropWillDelayInterval 30252,PropMessageExpiryInterval 6762,PropMaximumPacketSize 20996,PropAuthenticationMethod +// "\227",PropRequestResponseInformation 246,PropServerReference +// "\DLE\224oNcK\245R\166\204\226\166\152e8\241\148\187\GS\226\a\178\215\168\&4",PropTopicAlias 4733,PropContentType +// "A\155\212\167\236\169*\253k\DC2\ri\247\246",PropReasonString "-l\234\131"]} +TEST(Publish5QCTest, Decode9) { + uint8_t pkt[] = {0x3b, 0xd5, 0x1, 0x0, 0x14, 0x8, 0xc9, 0x4d, 0x53, 0x63, 0x8c, 0x80, 0x18, 0x73, 0xa2, 0x3b, 0xd5, + 0x9b, 0xe, 0x97, 0x8b, 0xe5, 0x1, 0xe5, 0xc5, 0x75, 0xba, 0xa4, 0x1, 0x1, 0xef, 0x2, 0x0, 0x0, + 0x63, 0x91, 0x1, 0x57, 0x9, 0x0, 0x19, 0x5, 0xcc, 0x1f, 0xd, 0x2, 0x5c, 0xbc, 0x71, 0x6a, 0x1, + 0x45, 0xac, 0xc8, 0xfa, 0xea, 0x6, 0x13, 0xe8, 0x32, 0xa6, 0xa0, 0xd3, 0xb5, 0xab, 0x6e, 0x8, 0x0, + 0xd, 0x56, 0xf3, 0x8d, 0x99, 0x13, 0xfb, 0xa, 0x86, 0x97, 0xd6, 0x6a, 0xb3, 0x14, 0x18, 0x0, 0x0, + 0xb, 0xce, 0xb, 0xf, 0x2, 0x0, 0x0, 0x2d, 0xc3, 0x22, 0x36, 0x52, 0x25, 0x2a, 0x25, 0x4c, 0x11, + 0x0, 0x0, 0x6a, 0xe3, 0x21, 0x72, 0x90, 0x18, 0x0, 0x0, 0x61, 0x2f, 0x13, 0x72, 0x45, 0x18, 0x0, + 0x0, 0x76, 0x2c, 0x2, 0x0, 0x0, 0x1a, 0x6a, 0x27, 0x0, 0x0, 0x52, 0x4, 0x15, 0x0, 0x1, 0xe3, + 0x19, 0xf6, 0x1c, 0x0, 0x19, 0x10, 0xe0, 0x6f, 0x4e, 0x63, 0x4b, 0xf5, 0x52, 0xa6, 0xcc, 0xe2, 0xa6, + 0x98, 0x65, 0x38, 0xf1, 0x94, 0xbb, 0x1d, 0xe2, 0x7, 0xb2, 0xd7, 0xa8, 0x34, 0x23, 0x12, 0x7d, 0x3, + 0x0, 0xe, 0x41, 0x9b, 0xd4, 0xa7, 0xec, 0xa9, 0x2a, 0xfd, 0x6b, 0x12, 0xd, 0x69, 0xf7, 0xf6, 0x1f, + 0x0, 0x4, 0x2d, 0x6c, 0xea, 0x83, 0x60, 0x36, 0x94, 0x86, 0x73, 0x2c, 0x1f, 0x60, 0x5a, 0xce, 0x9d, + 0xfc, 0x6a, 0x49, 0x35, 0x77, 0x39, 0x8a, 0x65, 0xb0, 0xb7, 0x8d, 0x7d}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x8, 0xc9, 0x4d, 0x53, 0x63, 0x8c, 0x80, 0x18, 0x73, 0xa2, + 0x3b, 0xd5, 0x9b, 0xe, 0x97, 0x8b, 0xe5, 0x1, 0xe5, 0xc5}; + lwmqtt_string_t exp_topic = {20, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x60, 0x36, 0x94, 0x86, 0x73, 0x2c, 0x1f, 0x60, 0x5a, 0xce, 0x9d, 0xfc, + 0x6a, 0x49, 0x35, 0x77, 0x39, 0x8a, 0x65, 0xb0, 0xb7, 0x8d, 0x7d}; + lwmqtt_string_t exp_body = {23, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 30138); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 20); + EXPECT_EQ(msg.payload_len, 23); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 23); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = "\177\SUB\139\129\ETB\208\148", +// _pubPktID = 30010, _pubBody = "`\USq\198\217\144\199Zp9", _pubProps = [PropPayloadFormatIndicator +// 223,PropServerKeepAlive 24882,PropAuthenticationMethod "[D\239\248j\152?\212.m47\188H\237!\130",PropMaximumQoS +// 41,PropRequestProblemInformation 197,PropUserProperty " \220\STX\DLEiJ+GG[\147\178\EOTy\238#C\222" +// ",Bu\223\&6\211\175\225\206!\158\132 \227\r\242\168]\195\129\DC1\167k\240",PropRequestProblemInformation +// 36,PropResponseInformation "\242\177\"\249\247Y\252\149K._/j\252\190=>\234\130\RSD\201",PropPayloadFormatIndicator +// 101,PropRetainAvailable 243,PropCorrelationData +// "\150m\tSN/\147H\165\224\137\v}\233\137\230",PropRequestResponseInformation 119,PropTopicAliasMaximum +// 25349,PropAuthenticationData "\218Z\183\155z\172M\SUB\195\170\142\133\247\148&l6X\192\155\253",PropServerKeepAlive +// 3471,PropMessageExpiryInterval 11388,PropCorrelationData +// "\GS\167\216\v\128\FS\SOHrz\159E\170\215\196\195X\CANq<;\201pd\SOH",PropSharedSubscriptionAvailable +// 35,PropSubscriptionIdentifierAvailable 68,PropSharedSubscriptionAvailable 181,PropRetainAvailable +// 173,PropSharedSubscriptionAvailable 104]} +TEST(Publish5QCTest, Encode10) { + uint8_t pkt[] = { + 0x32, 0xdf, 0x1, 0x0, 0x7, 0xb1, 0x1a, 0x8b, 0x81, 0x17, 0xd0, 0x94, 0x75, 0x3a, 0xc8, 0x1, 0x1, 0xdf, 0x13, + 0x61, 0x32, 0x15, 0x0, 0x11, 0x5b, 0x44, 0xef, 0xf8, 0x6a, 0x98, 0x3f, 0xd4, 0x2e, 0x6d, 0x34, 0x37, 0xbc, 0x48, + 0xed, 0x21, 0x82, 0x24, 0x29, 0x17, 0xc5, 0x26, 0x0, 0x12, 0x20, 0xdc, 0x2, 0x10, 0x69, 0x4a, 0x2b, 0x47, 0x47, + 0x5b, 0x93, 0xb2, 0x4, 0x79, 0xee, 0x23, 0x43, 0xde, 0x0, 0x18, 0x2c, 0x42, 0x75, 0xdf, 0x36, 0xd3, 0xaf, 0xe1, + 0xce, 0x21, 0x9e, 0x84, 0x20, 0xe3, 0xd, 0xf2, 0xa8, 0x5d, 0xc3, 0x81, 0x11, 0xa7, 0x6b, 0xf0, 0x17, 0x24, 0x1a, + 0x0, 0x16, 0xf2, 0xb1, 0x22, 0xf9, 0xf7, 0x59, 0xfc, 0x95, 0x4b, 0x2e, 0x5f, 0x2f, 0x6a, 0xfc, 0xbe, 0x3d, 0x3e, + 0xea, 0x82, 0x1e, 0x44, 0xc9, 0x1, 0x65, 0x25, 0xf3, 0x9, 0x0, 0x10, 0x96, 0x6d, 0x9, 0x53, 0x4e, 0x2f, 0x93, + 0x48, 0xa5, 0xe0, 0x89, 0xb, 0x7d, 0xe9, 0x89, 0xe6, 0x19, 0x77, 0x22, 0x63, 0x5, 0x16, 0x0, 0x15, 0xda, 0x5a, + 0xb7, 0x9b, 0x7a, 0xac, 0x4d, 0x1a, 0xc3, 0xaa, 0x8e, 0x85, 0xf7, 0x94, 0x26, 0x6c, 0x36, 0x58, 0xc0, 0x9b, 0xfd, + 0x13, 0xd, 0x8f, 0x2, 0x0, 0x0, 0x2c, 0x7c, 0x9, 0x0, 0x18, 0x1d, 0xa7, 0xd8, 0xb, 0x80, 0x1c, 0x1, 0x72, + 0x7a, 0x9f, 0x45, 0xaa, 0xd7, 0xc4, 0xc3, 0x58, 0x18, 0x71, 0x3c, 0x3b, 0xc9, 0x70, 0x64, 0x1, 0x2a, 0x23, 0x29, + 0x44, 0x2a, 0xb5, 0x25, 0xad, 0x2a, 0x68, 0x60, 0x1f, 0x71, 0xc6, 0xd9, 0x90, 0xc7, 0x5a, 0x70, 0x39}; + uint8_t topic_bytes[] = {0xb1, 0x1a, 0x8b, 0x81, 0x17, 0xd0, 0x94}; + lwmqtt_string_t topic = {7, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = false; + uint8_t msg_bytes[] = {0x60, 0x1f, 0x71, 0xc6, 0xd9, 0x90, 0xc7, 0x5a, 0x70, 0x39}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 10; + + uint8_t bytesprops0[] = {0x5b, 0x44, 0xef, 0xf8, 0x6a, 0x98, 0x3f, 0xd4, 0x2e, + 0x6d, 0x34, 0x37, 0xbc, 0x48, 0xed, 0x21, 0x82}; + uint8_t bytesprops2[] = {0x2c, 0x42, 0x75, 0xdf, 0x36, 0xd3, 0xaf, 0xe1, 0xce, 0x21, 0x9e, 0x84, + 0x20, 0xe3, 0xd, 0xf2, 0xa8, 0x5d, 0xc3, 0x81, 0x11, 0xa7, 0x6b, 0xf0}; + uint8_t bytesprops1[] = {0x20, 0xdc, 0x2, 0x10, 0x69, 0x4a, 0x2b, 0x47, 0x47, + 0x5b, 0x93, 0xb2, 0x4, 0x79, 0xee, 0x23, 0x43, 0xde}; + uint8_t bytesprops3[] = {0xf2, 0xb1, 0x22, 0xf9, 0xf7, 0x59, 0xfc, 0x95, 0x4b, 0x2e, 0x5f, + 0x2f, 0x6a, 0xfc, 0xbe, 0x3d, 0x3e, 0xea, 0x82, 0x1e, 0x44, 0xc9}; + uint8_t bytesprops4[] = {0x96, 0x6d, 0x9, 0x53, 0x4e, 0x2f, 0x93, 0x48, + 0xa5, 0xe0, 0x89, 0xb, 0x7d, 0xe9, 0x89, 0xe6}; + uint8_t bytesprops5[] = {0xda, 0x5a, 0xb7, 0x9b, 0x7a, 0xac, 0x4d, 0x1a, 0xc3, 0xaa, 0x8e, + 0x85, 0xf7, 0x94, 0x26, 0x6c, 0x36, 0x58, 0xc0, 0x9b, 0xfd}; + uint8_t bytesprops6[] = {0x1d, 0xa7, 0xd8, 0xb, 0x80, 0x1c, 0x1, 0x72, 0x7a, 0x9f, 0x45, 0xaa, + 0xd7, 0xc4, 0xc3, 0x58, 0x18, 0x71, 0x3c, 0x3b, 0xc9, 0x70, 0x64, 0x1}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 223}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 24882}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {17, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 41}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 197}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {18, (char*)&bytesprops1}, .v = {24, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 36}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {22, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 101}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 243}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {16, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 119}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 25349}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {21, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 3471}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 11388}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {24, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 35}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 68}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 181}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 173}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 104}}, + }; + + lwmqtt_properties_t props = {22, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, false, 30010, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = "\177\SUB\139\129\ETB\208\148", +// _pubPktID = 30010, _pubBody = "`\USq\198\217\144\199Zp9", _pubProps = [PropPayloadFormatIndicator +// 223,PropServerKeepAlive 24882,PropAuthenticationMethod "[D\239\248j\152?\212.m47\188H\237!\130",PropMaximumQoS +// 41,PropRequestProblemInformation 197,PropUserProperty " \220\STX\DLEiJ+GG[\147\178\EOTy\238#C\222" +// ",Bu\223\&6\211\175\225\206!\158\132 \227\r\242\168]\195\129\DC1\167k\240",PropRequestProblemInformation +// 36,PropResponseInformation "\242\177\"\249\247Y\252\149K._/j\252\190=>\234\130\RSD\201",PropPayloadFormatIndicator +// 101,PropRetainAvailable 243,PropCorrelationData +// "\150m\tSN/\147H\165\224\137\v}\233\137\230",PropRequestResponseInformation 119,PropTopicAliasMaximum +// 25349,PropAuthenticationData "\218Z\183\155z\172M\SUB\195\170\142\133\247\148&l6X\192\155\253",PropServerKeepAlive +// 3471,PropMessageExpiryInterval 11388,PropCorrelationData +// "\GS\167\216\v\128\FS\SOHrz\159E\170\215\196\195X\CANq<;\201pd\SOH",PropSharedSubscriptionAvailable +// 35,PropSubscriptionIdentifierAvailable 68,PropSharedSubscriptionAvailable 181,PropRetainAvailable +// 173,PropSharedSubscriptionAvailable 104]} +TEST(Publish5QCTest, Decode10) { + uint8_t pkt[] = { + 0x32, 0xdf, 0x1, 0x0, 0x7, 0xb1, 0x1a, 0x8b, 0x81, 0x17, 0xd0, 0x94, 0x75, 0x3a, 0xc8, 0x1, 0x1, 0xdf, 0x13, + 0x61, 0x32, 0x15, 0x0, 0x11, 0x5b, 0x44, 0xef, 0xf8, 0x6a, 0x98, 0x3f, 0xd4, 0x2e, 0x6d, 0x34, 0x37, 0xbc, 0x48, + 0xed, 0x21, 0x82, 0x24, 0x29, 0x17, 0xc5, 0x26, 0x0, 0x12, 0x20, 0xdc, 0x2, 0x10, 0x69, 0x4a, 0x2b, 0x47, 0x47, + 0x5b, 0x93, 0xb2, 0x4, 0x79, 0xee, 0x23, 0x43, 0xde, 0x0, 0x18, 0x2c, 0x42, 0x75, 0xdf, 0x36, 0xd3, 0xaf, 0xe1, + 0xce, 0x21, 0x9e, 0x84, 0x20, 0xe3, 0xd, 0xf2, 0xa8, 0x5d, 0xc3, 0x81, 0x11, 0xa7, 0x6b, 0xf0, 0x17, 0x24, 0x1a, + 0x0, 0x16, 0xf2, 0xb1, 0x22, 0xf9, 0xf7, 0x59, 0xfc, 0x95, 0x4b, 0x2e, 0x5f, 0x2f, 0x6a, 0xfc, 0xbe, 0x3d, 0x3e, + 0xea, 0x82, 0x1e, 0x44, 0xc9, 0x1, 0x65, 0x25, 0xf3, 0x9, 0x0, 0x10, 0x96, 0x6d, 0x9, 0x53, 0x4e, 0x2f, 0x93, + 0x48, 0xa5, 0xe0, 0x89, 0xb, 0x7d, 0xe9, 0x89, 0xe6, 0x19, 0x77, 0x22, 0x63, 0x5, 0x16, 0x0, 0x15, 0xda, 0x5a, + 0xb7, 0x9b, 0x7a, 0xac, 0x4d, 0x1a, 0xc3, 0xaa, 0x8e, 0x85, 0xf7, 0x94, 0x26, 0x6c, 0x36, 0x58, 0xc0, 0x9b, 0xfd, + 0x13, 0xd, 0x8f, 0x2, 0x0, 0x0, 0x2c, 0x7c, 0x9, 0x0, 0x18, 0x1d, 0xa7, 0xd8, 0xb, 0x80, 0x1c, 0x1, 0x72, + 0x7a, 0x9f, 0x45, 0xaa, 0xd7, 0xc4, 0xc3, 0x58, 0x18, 0x71, 0x3c, 0x3b, 0xc9, 0x70, 0x64, 0x1, 0x2a, 0x23, 0x29, + 0x44, 0x2a, 0xb5, 0x25, 0xad, 0x2a, 0x68, 0x60, 0x1f, 0x71, 0xc6, 0xd9, 0x90, 0xc7, 0x5a, 0x70, 0x39}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xb1, 0x1a, 0x8b, 0x81, 0x17, 0xd0, 0x94}; + lwmqtt_string_t exp_topic = {7, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x60, 0x1f, 0x71, 0xc6, 0xd9, 0x90, 0xc7, 0x5a, 0x70, 0x39}; + lwmqtt_string_t exp_body = {10, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 30010); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 7); + EXPECT_EQ(msg.payload_len, 10); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 10); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "\203", _pubPktID = 182, _pubBody = +// "\145y\231n\252\238pw\ACK\168Lc~\152\153\129W\\\SIK\134\251\185\SOH\208\EMV\"", _pubProps = [PropUserProperty +// "\210\235\181U\238" "\SI\247\164\241\170/\204\161\229",PropResponseInformation +// "}\vGt\204k9\SOH\250>5h\224",PropReasonString "c:\DC1\138\241\188}\NULqN\146'\164v- \NUL",PropSessionExpiryInterval +// 16818,PropAssignedClientIdentifier "6\152]8\141\a<9@\248\174i>\143\245.\EM",PropWildcardSubscriptionAvailable +// 80,PropSharedSubscriptionAvailable 24,PropSharedSubscriptionAvailable 240]} +TEST(Publish5QCTest, Encode11) { + uint8_t pkt[] = {0x3b, 0x78, 0x0, 0x1, 0xcb, 0x0, 0xb6, 0x56, 0x26, 0x0, 0x5, 0xd2, 0xeb, 0xb5, 0x55, 0xee, + 0x0, 0x9, 0xf, 0xf7, 0xa4, 0xf1, 0xaa, 0x2f, 0xcc, 0xa1, 0xe5, 0x1a, 0x0, 0xd, 0x7d, 0xb, + 0x47, 0x74, 0xcc, 0x6b, 0x39, 0x1, 0xfa, 0x3e, 0x35, 0x68, 0xe0, 0x1f, 0x0, 0x11, 0x63, 0x3a, + 0x11, 0x8a, 0xf1, 0xbc, 0x7d, 0x0, 0x71, 0x4e, 0x92, 0x27, 0xa4, 0x76, 0x2d, 0x20, 0x0, 0x11, + 0x0, 0x0, 0x41, 0xb2, 0x12, 0x0, 0x11, 0x36, 0x98, 0x5d, 0x38, 0x8d, 0x7, 0x3c, 0x39, 0x40, + 0xf8, 0xae, 0x69, 0x3e, 0x8f, 0xf5, 0x2e, 0x19, 0x28, 0x50, 0x2a, 0x18, 0x2a, 0xf0, 0x91, 0x79, + 0xe7, 0x6e, 0xfc, 0xee, 0x70, 0x77, 0x6, 0xa8, 0x4c, 0x63, 0x7e, 0x98, 0x99, 0x81, 0x57, 0x5c, + 0xf, 0x4b, 0x86, 0xfb, 0xb9, 0x1, 0xd0, 0x19, 0x56, 0x22}; + uint8_t topic_bytes[] = {0xcb}; + lwmqtt_string_t topic = {1, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0x91, 0x79, 0xe7, 0x6e, 0xfc, 0xee, 0x70, 0x77, 0x6, 0xa8, 0x4c, 0x63, 0x7e, 0x98, + 0x99, 0x81, 0x57, 0x5c, 0xf, 0x4b, 0x86, 0xfb, 0xb9, 0x1, 0xd0, 0x19, 0x56, 0x22}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 28; + + uint8_t bytesprops1[] = {0xf, 0xf7, 0xa4, 0xf1, 0xaa, 0x2f, 0xcc, 0xa1, 0xe5}; + uint8_t bytesprops0[] = {0xd2, 0xeb, 0xb5, 0x55, 0xee}; + uint8_t bytesprops2[] = {0x7d, 0xb, 0x47, 0x74, 0xcc, 0x6b, 0x39, 0x1, 0xfa, 0x3e, 0x35, 0x68, 0xe0}; + uint8_t bytesprops3[] = {0x63, 0x3a, 0x11, 0x8a, 0xf1, 0xbc, 0x7d, 0x0, 0x71, + 0x4e, 0x92, 0x27, 0xa4, 0x76, 0x2d, 0x20, 0x0}; + uint8_t bytesprops4[] = {0x36, 0x98, 0x5d, 0x38, 0x8d, 0x7, 0x3c, 0x39, 0x40, + 0xf8, 0xae, 0x69, 0x3e, 0x8f, 0xf5, 0x2e, 0x19}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {5, (char*)&bytesprops0}, .v = {9, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {13, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {17, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 16818}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {17, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 80}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 24}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 240}}, + }; + + lwmqtt_properties_t props = {8, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 182, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "\203", _pubPktID = 182, _pubBody = +// "\145y\231n\252\238pw\ACK\168Lc~\152\153\129W\\\SIK\134\251\185\SOH\208\EMV\"", _pubProps = [PropUserProperty +// "\210\235\181U\238" "\SI\247\164\241\170/\204\161\229",PropResponseInformation +// "}\vGt\204k9\SOH\250>5h\224",PropReasonString "c:\DC1\138\241\188}\NULqN\146'\164v- \NUL",PropSessionExpiryInterval +// 16818,PropAssignedClientIdentifier "6\152]8\141\a<9@\248\174i>\143\245.\EM",PropWildcardSubscriptionAvailable +// 80,PropSharedSubscriptionAvailable 24,PropSharedSubscriptionAvailable 240]} +TEST(Publish5QCTest, Decode11) { + uint8_t pkt[] = {0x3b, 0x78, 0x0, 0x1, 0xcb, 0x0, 0xb6, 0x56, 0x26, 0x0, 0x5, 0xd2, 0xeb, 0xb5, 0x55, 0xee, + 0x0, 0x9, 0xf, 0xf7, 0xa4, 0xf1, 0xaa, 0x2f, 0xcc, 0xa1, 0xe5, 0x1a, 0x0, 0xd, 0x7d, 0xb, + 0x47, 0x74, 0xcc, 0x6b, 0x39, 0x1, 0xfa, 0x3e, 0x35, 0x68, 0xe0, 0x1f, 0x0, 0x11, 0x63, 0x3a, + 0x11, 0x8a, 0xf1, 0xbc, 0x7d, 0x0, 0x71, 0x4e, 0x92, 0x27, 0xa4, 0x76, 0x2d, 0x20, 0x0, 0x11, + 0x0, 0x0, 0x41, 0xb2, 0x12, 0x0, 0x11, 0x36, 0x98, 0x5d, 0x38, 0x8d, 0x7, 0x3c, 0x39, 0x40, + 0xf8, 0xae, 0x69, 0x3e, 0x8f, 0xf5, 0x2e, 0x19, 0x28, 0x50, 0x2a, 0x18, 0x2a, 0xf0, 0x91, 0x79, + 0xe7, 0x6e, 0xfc, 0xee, 0x70, 0x77, 0x6, 0xa8, 0x4c, 0x63, 0x7e, 0x98, 0x99, 0x81, 0x57, 0x5c, + 0xf, 0x4b, 0x86, 0xfb, 0xb9, 0x1, 0xd0, 0x19, 0x56, 0x22}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xcb}; + lwmqtt_string_t exp_topic = {1, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x91, 0x79, 0xe7, 0x6e, 0xfc, 0xee, 0x70, 0x77, 0x6, 0xa8, 0x4c, 0x63, 0x7e, 0x98, + 0x99, 0x81, 0x57, 0x5c, 0xf, 0x4b, 0x86, 0xfb, 0xb9, 0x1, 0xd0, 0x19, 0x56, 0x22}; + lwmqtt_string_t exp_body = {28, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 182); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 1); + EXPECT_EQ(msg.payload_len, 28); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 28); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = True, _pubTopic = +// "\194\243\142\n\178\204\216XR\184\207o\140\n\176", _pubPktID = 10741, _pubBody = "\135\214\215", _pubProps = +// [PropRetainAvailable 82,PropSubscriptionIdentifierAvailable 88,PropTopicAliasMaximum 3580,PropServerReference +// "\190,\220\169-:\204VCy",PropAssignedClientIdentifier +// "\141Q\201\184?\242BD[w\242w\205G\STXc\177\163\253\144\140/#\145Y\218\NUL",PropMaximumQoS +// 87,PropMessageExpiryInterval 14105,PropTopicAlias 1102,PropSessionExpiryInterval 9950,PropMaximumPacketSize +// 28308,PropAssignedClientIdentifier "2\ENQ\172\169a2Q\CAN\DC3\167^\174Ln{\162\169\ETX",PropAuthenticationData +// "\ETX\FS\232\172\195\148\STXl\ENQ",PropMessageExpiryInterval 23457,PropMaximumQoS 90,PropSharedSubscriptionAvailable +// 131,PropSubscriptionIdentifier 25,PropAuthenticationMethod "\159\t\NUL\238\&4",PropAuthenticationData +// "\248\135\128$\231\&9k\SOH\211\b\206\148\193\213",PropMessageExpiryInterval 11234,PropMessageExpiryInterval +// 13942,PropSharedSubscriptionAvailable 231,PropWillDelayInterval 28732,PropSubscriptionIdentifierAvailable +// 236,PropAuthenticationData +// "\212\211\r\246\242\135\219*\241\DC3\232H\143?\231\153Y\n\156t\140",PropPayloadFormatIndicator 248,PropTopicAlias +// 21727,PropPayloadFormatIndicator 18]} +TEST(Publish5QCTest, Encode12) { + uint8_t pkt[] = {0x35, 0xd5, 0x1, 0x0, 0xf, 0xc2, 0xf3, 0x8e, 0xa, 0xb2, 0xcc, 0xd8, 0x58, 0x52, 0xb8, 0xcf, 0x6f, + 0x8c, 0xa, 0xb0, 0x29, 0xf5, 0xbd, 0x1, 0x25, 0x52, 0x29, 0x58, 0x22, 0xd, 0xfc, 0x1c, 0x0, 0xa, + 0xbe, 0x2c, 0xdc, 0xa9, 0x2d, 0x3a, 0xcc, 0x56, 0x43, 0x79, 0x12, 0x0, 0x1b, 0x8d, 0x51, 0xc9, 0xb8, + 0x3f, 0xf2, 0x42, 0x44, 0x5b, 0x77, 0xf2, 0x77, 0xcd, 0x47, 0x2, 0x63, 0xb1, 0xa3, 0xfd, 0x90, 0x8c, + 0x2f, 0x23, 0x91, 0x59, 0xda, 0x0, 0x24, 0x57, 0x2, 0x0, 0x0, 0x37, 0x19, 0x23, 0x4, 0x4e, 0x11, + 0x0, 0x0, 0x26, 0xde, 0x27, 0x0, 0x0, 0x6e, 0x94, 0x12, 0x0, 0x12, 0x32, 0x5, 0xac, 0xa9, 0x61, + 0x32, 0x51, 0x18, 0x13, 0xa7, 0x5e, 0xae, 0x4c, 0x6e, 0x7b, 0xa2, 0xa9, 0x3, 0x16, 0x0, 0x9, 0x3, + 0x1c, 0xe8, 0xac, 0xc3, 0x94, 0x2, 0x6c, 0x5, 0x2, 0x0, 0x0, 0x5b, 0xa1, 0x24, 0x5a, 0x2a, 0x83, + 0xb, 0x19, 0x15, 0x0, 0x5, 0x9f, 0x9, 0x0, 0xee, 0x34, 0x16, 0x0, 0xe, 0xf8, 0x87, 0x80, 0x24, + 0xe7, 0x39, 0x6b, 0x1, 0xd3, 0x8, 0xce, 0x94, 0xc1, 0xd5, 0x2, 0x0, 0x0, 0x2b, 0xe2, 0x2, 0x0, + 0x0, 0x36, 0x76, 0x2a, 0xe7, 0x18, 0x0, 0x0, 0x70, 0x3c, 0x29, 0xec, 0x16, 0x0, 0x15, 0xd4, 0xd3, + 0xd, 0xf6, 0xf2, 0x87, 0xdb, 0x2a, 0xf1, 0x13, 0xe8, 0x48, 0x8f, 0x3f, 0xe7, 0x99, 0x59, 0xa, 0x9c, + 0x74, 0x8c, 0x1, 0xf8, 0x23, 0x54, 0xdf, 0x1, 0x12, 0x87, 0xd6, 0xd7}; + uint8_t topic_bytes[] = {0xc2, 0xf3, 0x8e, 0xa, 0xb2, 0xcc, 0xd8, 0x58, 0x52, 0xb8, 0xcf, 0x6f, 0x8c, 0xa, 0xb0}; + lwmqtt_string_t topic = {15, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = true; + uint8_t msg_bytes[] = {0x87, 0xd6, 0xd7}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 3; + + uint8_t bytesprops0[] = {0xbe, 0x2c, 0xdc, 0xa9, 0x2d, 0x3a, 0xcc, 0x56, 0x43, 0x79}; + uint8_t bytesprops1[] = {0x8d, 0x51, 0xc9, 0xb8, 0x3f, 0xf2, 0x42, 0x44, 0x5b, 0x77, 0xf2, 0x77, 0xcd, 0x47, + 0x2, 0x63, 0xb1, 0xa3, 0xfd, 0x90, 0x8c, 0x2f, 0x23, 0x91, 0x59, 0xda, 0x0}; + uint8_t bytesprops2[] = {0x32, 0x5, 0xac, 0xa9, 0x61, 0x32, 0x51, 0x18, 0x13, + 0xa7, 0x5e, 0xae, 0x4c, 0x6e, 0x7b, 0xa2, 0xa9, 0x3}; + uint8_t bytesprops3[] = {0x3, 0x1c, 0xe8, 0xac, 0xc3, 0x94, 0x2, 0x6c, 0x5}; + uint8_t bytesprops4[] = {0x9f, 0x9, 0x0, 0xee, 0x34}; + uint8_t bytesprops5[] = {0xf8, 0x87, 0x80, 0x24, 0xe7, 0x39, 0x6b, 0x1, 0xd3, 0x8, 0xce, 0x94, 0xc1, 0xd5}; + uint8_t bytesprops6[] = {0xd4, 0xd3, 0xd, 0xf6, 0xf2, 0x87, 0xdb, 0x2a, 0xf1, 0x13, 0xe8, + 0x48, 0x8f, 0x3f, 0xe7, 0x99, 0x59, 0xa, 0x9c, 0x74, 0x8c}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 82}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 88}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 3580}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {10, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {27, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 87}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 14105}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 1102}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 9950}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 28308}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {18, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {9, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 23457}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 90}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 131}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 25}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {5, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {14, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 11234}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 13942}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 231}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 28732}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 236}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {21, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 248}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 21727}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 18}}, + }; + + lwmqtt_properties_t props = {27, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, false, 10741, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = True, _pubTopic = +// "\194\243\142\n\178\204\216XR\184\207o\140\n\176", _pubPktID = 10741, _pubBody = "\135\214\215", _pubProps = +// [PropRetainAvailable 82,PropSubscriptionIdentifierAvailable 88,PropTopicAliasMaximum 3580,PropServerReference +// "\190,\220\169-:\204VCy",PropAssignedClientIdentifier +// "\141Q\201\184?\242BD[w\242w\205G\STXc\177\163\253\144\140/#\145Y\218\NUL",PropMaximumQoS +// 87,PropMessageExpiryInterval 14105,PropTopicAlias 1102,PropSessionExpiryInterval 9950,PropMaximumPacketSize +// 28308,PropAssignedClientIdentifier "2\ENQ\172\169a2Q\CAN\DC3\167^\174Ln{\162\169\ETX",PropAuthenticationData +// "\ETX\FS\232\172\195\148\STXl\ENQ",PropMessageExpiryInterval 23457,PropMaximumQoS 90,PropSharedSubscriptionAvailable +// 131,PropSubscriptionIdentifier 25,PropAuthenticationMethod "\159\t\NUL\238\&4",PropAuthenticationData +// "\248\135\128$\231\&9k\SOH\211\b\206\148\193\213",PropMessageExpiryInterval 11234,PropMessageExpiryInterval +// 13942,PropSharedSubscriptionAvailable 231,PropWillDelayInterval 28732,PropSubscriptionIdentifierAvailable +// 236,PropAuthenticationData +// "\212\211\r\246\242\135\219*\241\DC3\232H\143?\231\153Y\n\156t\140",PropPayloadFormatIndicator 248,PropTopicAlias +// 21727,PropPayloadFormatIndicator 18]} +TEST(Publish5QCTest, Decode12) { + uint8_t pkt[] = {0x35, 0xd5, 0x1, 0x0, 0xf, 0xc2, 0xf3, 0x8e, 0xa, 0xb2, 0xcc, 0xd8, 0x58, 0x52, 0xb8, 0xcf, 0x6f, + 0x8c, 0xa, 0xb0, 0x29, 0xf5, 0xbd, 0x1, 0x25, 0x52, 0x29, 0x58, 0x22, 0xd, 0xfc, 0x1c, 0x0, 0xa, + 0xbe, 0x2c, 0xdc, 0xa9, 0x2d, 0x3a, 0xcc, 0x56, 0x43, 0x79, 0x12, 0x0, 0x1b, 0x8d, 0x51, 0xc9, 0xb8, + 0x3f, 0xf2, 0x42, 0x44, 0x5b, 0x77, 0xf2, 0x77, 0xcd, 0x47, 0x2, 0x63, 0xb1, 0xa3, 0xfd, 0x90, 0x8c, + 0x2f, 0x23, 0x91, 0x59, 0xda, 0x0, 0x24, 0x57, 0x2, 0x0, 0x0, 0x37, 0x19, 0x23, 0x4, 0x4e, 0x11, + 0x0, 0x0, 0x26, 0xde, 0x27, 0x0, 0x0, 0x6e, 0x94, 0x12, 0x0, 0x12, 0x32, 0x5, 0xac, 0xa9, 0x61, + 0x32, 0x51, 0x18, 0x13, 0xa7, 0x5e, 0xae, 0x4c, 0x6e, 0x7b, 0xa2, 0xa9, 0x3, 0x16, 0x0, 0x9, 0x3, + 0x1c, 0xe8, 0xac, 0xc3, 0x94, 0x2, 0x6c, 0x5, 0x2, 0x0, 0x0, 0x5b, 0xa1, 0x24, 0x5a, 0x2a, 0x83, + 0xb, 0x19, 0x15, 0x0, 0x5, 0x9f, 0x9, 0x0, 0xee, 0x34, 0x16, 0x0, 0xe, 0xf8, 0x87, 0x80, 0x24, + 0xe7, 0x39, 0x6b, 0x1, 0xd3, 0x8, 0xce, 0x94, 0xc1, 0xd5, 0x2, 0x0, 0x0, 0x2b, 0xe2, 0x2, 0x0, + 0x0, 0x36, 0x76, 0x2a, 0xe7, 0x18, 0x0, 0x0, 0x70, 0x3c, 0x29, 0xec, 0x16, 0x0, 0x15, 0xd4, 0xd3, + 0xd, 0xf6, 0xf2, 0x87, 0xdb, 0x2a, 0xf1, 0x13, 0xe8, 0x48, 0x8f, 0x3f, 0xe7, 0x99, 0x59, 0xa, 0x9c, + 0x74, 0x8c, 0x1, 0xf8, 0x23, 0x54, 0xdf, 0x1, 0x12, 0x87, 0xd6, 0xd7}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xc2, 0xf3, 0x8e, 0xa, 0xb2, 0xcc, 0xd8, 0x58, 0x52, 0xb8, 0xcf, 0x6f, 0x8c, 0xa, 0xb0}; + lwmqtt_string_t exp_topic = {15, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x87, 0xd6, 0xd7}; + lwmqtt_string_t exp_body = {3, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 10741); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 15); + EXPECT_EQ(msg.payload_len, 3); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 3); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = +// "\180^\180\196\166\GS\142\ETB\np\US\226\226j-\130\242+\138\234A", _pubPktID = 0, _pubBody = +// "\STXN8tdLv\171\220\&3tu\225\159\165V\148\183&W6\202\202\165r\SOH", _pubProps = [PropUserProperty +// "C\242\178\130f\163{W\US'\201m\140\230\EM\162\196" +// "\250\v\ESC\n\NAKw\135b2\164\243\&66n\"\nFF8\207\&1e\136\208s",PropTopicAlias 29241,PropReasonString +// "\203\243?\215\209\n\FS\225\ETBE\131z\252%7x\170\187\SOH\230\DC4\205\153\&6\140",PropContentType +// "\198\209i\134\198\251\EM~\155w\ENQ\255\148",PropAuthenticationMethod "n\148\231p\NAK\222<",PropRetainAvailable +// 172,PropPayloadFormatIndicator 179,PropReasonString +// "H3'\190\ESC#\237w'4!\v\139\210\189\224Zc\175U",PropSubscriptionIdentifier 16,PropReasonString +// "\183\&2iwD\212\148x\255\200(\209\&1\250?",PropRequestProblemInformation 206,PropReasonString +// "vFH\237\135\189D\242(^\201\159\EOT\EOT\148",PropWildcardSubscriptionAvailable 38,PropMessageExpiryInterval +// 17391,PropWildcardSubscriptionAvailable 86]} +TEST(Publish5QCTest, Encode13) { + uint8_t pkt[] = {0x38, 0xe7, 0x1, 0x0, 0x15, 0xb4, 0x5e, 0xb4, 0xc4, 0xa6, 0x1d, 0x8e, 0x17, 0xa, 0x70, 0x1f, 0xe2, + 0xe2, 0x6a, 0x2d, 0x82, 0xf2, 0x2b, 0x8a, 0xea, 0x41, 0xb4, 0x1, 0x26, 0x0, 0x11, 0x43, 0xf2, 0xb2, + 0x82, 0x66, 0xa3, 0x7b, 0x57, 0x1f, 0x27, 0xc9, 0x6d, 0x8c, 0xe6, 0x19, 0xa2, 0xc4, 0x0, 0x19, 0xfa, + 0xb, 0x1b, 0xa, 0x15, 0x77, 0x87, 0x62, 0x32, 0xa4, 0xf3, 0x36, 0x36, 0x6e, 0x22, 0xa, 0x46, 0x46, + 0x38, 0xcf, 0x31, 0x65, 0x88, 0xd0, 0x73, 0x23, 0x72, 0x39, 0x1f, 0x0, 0x19, 0xcb, 0xf3, 0x3f, 0xd7, + 0xd1, 0xa, 0x1c, 0xe1, 0x17, 0x45, 0x83, 0x7a, 0xfc, 0x25, 0x37, 0x78, 0xaa, 0xbb, 0x1, 0xe6, 0x14, + 0xcd, 0x99, 0x36, 0x8c, 0x3, 0x0, 0xd, 0xc6, 0xd1, 0x69, 0x86, 0xc6, 0xfb, 0x19, 0x7e, 0x9b, 0x77, + 0x5, 0xff, 0x94, 0x15, 0x0, 0x7, 0x6e, 0x94, 0xe7, 0x70, 0x15, 0xde, 0x3c, 0x25, 0xac, 0x1, 0xb3, + 0x1f, 0x0, 0x14, 0x48, 0x33, 0x27, 0xbe, 0x1b, 0x23, 0xed, 0x77, 0x27, 0x34, 0x21, 0xb, 0x8b, 0xd2, + 0xbd, 0xe0, 0x5a, 0x63, 0xaf, 0x55, 0xb, 0x10, 0x1f, 0x0, 0xf, 0xb7, 0x32, 0x69, 0x77, 0x44, 0xd4, + 0x94, 0x78, 0xff, 0xc8, 0x28, 0xd1, 0x31, 0xfa, 0x3f, 0x17, 0xce, 0x1f, 0x0, 0xf, 0x76, 0x46, 0x48, + 0xed, 0x87, 0xbd, 0x44, 0xf2, 0x28, 0x5e, 0xc9, 0x9f, 0x4, 0x4, 0x94, 0x28, 0x26, 0x2, 0x0, 0x0, + 0x43, 0xef, 0x28, 0x56, 0x2, 0x4e, 0x38, 0x74, 0x64, 0x4c, 0x76, 0xab, 0xdc, 0x33, 0x74, 0x75, 0xe1, + 0x9f, 0xa5, 0x56, 0x94, 0xb7, 0x26, 0x57, 0x36, 0xca, 0xca, 0xa5, 0x72, 0x1}; + uint8_t topic_bytes[] = {0xb4, 0x5e, 0xb4, 0xc4, 0xa6, 0x1d, 0x8e, 0x17, 0xa, 0x70, 0x1f, + 0xe2, 0xe2, 0x6a, 0x2d, 0x82, 0xf2, 0x2b, 0x8a, 0xea, 0x41}; + lwmqtt_string_t topic = {21, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = false; + uint8_t msg_bytes[] = {0x2, 0x4e, 0x38, 0x74, 0x64, 0x4c, 0x76, 0xab, 0xdc, 0x33, 0x74, 0x75, 0xe1, + 0x9f, 0xa5, 0x56, 0x94, 0xb7, 0x26, 0x57, 0x36, 0xca, 0xca, 0xa5, 0x72, 0x1}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 26; + + uint8_t bytesprops1[] = {0xfa, 0xb, 0x1b, 0xa, 0x15, 0x77, 0x87, 0x62, 0x32, 0xa4, 0xf3, 0x36, 0x36, + 0x6e, 0x22, 0xa, 0x46, 0x46, 0x38, 0xcf, 0x31, 0x65, 0x88, 0xd0, 0x73}; + uint8_t bytesprops0[] = {0x43, 0xf2, 0xb2, 0x82, 0x66, 0xa3, 0x7b, 0x57, 0x1f, + 0x27, 0xc9, 0x6d, 0x8c, 0xe6, 0x19, 0xa2, 0xc4}; + uint8_t bytesprops2[] = {0xcb, 0xf3, 0x3f, 0xd7, 0xd1, 0xa, 0x1c, 0xe1, 0x17, 0x45, 0x83, 0x7a, 0xfc, + 0x25, 0x37, 0x78, 0xaa, 0xbb, 0x1, 0xe6, 0x14, 0xcd, 0x99, 0x36, 0x8c}; + uint8_t bytesprops3[] = {0xc6, 0xd1, 0x69, 0x86, 0xc6, 0xfb, 0x19, 0x7e, 0x9b, 0x77, 0x5, 0xff, 0x94}; + uint8_t bytesprops4[] = {0x6e, 0x94, 0xe7, 0x70, 0x15, 0xde, 0x3c}; + uint8_t bytesprops5[] = {0x48, 0x33, 0x27, 0xbe, 0x1b, 0x23, 0xed, 0x77, 0x27, 0x34, + 0x21, 0xb, 0x8b, 0xd2, 0xbd, 0xe0, 0x5a, 0x63, 0xaf, 0x55}; + uint8_t bytesprops6[] = {0xb7, 0x32, 0x69, 0x77, 0x44, 0xd4, 0x94, 0x78, 0xff, 0xc8, 0x28, 0xd1, 0x31, 0xfa, 0x3f}; + uint8_t bytesprops7[] = {0x76, 0x46, 0x48, 0xed, 0x87, 0xbd, 0x44, 0xf2, 0x28, 0x5e, 0xc9, 0x9f, 0x4, 0x4, 0x94}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {17, (char*)&bytesprops0}, .v = {25, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 29241}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {25, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {13, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {7, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 172}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 179}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {20, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 16}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {15, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 206}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {15, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 38}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 17391}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 86}}, + }; + + lwmqtt_properties_t props = {15, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = +// "\180^\180\196\166\GS\142\ETB\np\US\226\226j-\130\242+\138\234A", _pubPktID = 0, _pubBody = +// "\STXN8tdLv\171\220\&3tu\225\159\165V\148\183&W6\202\202\165r\SOH", _pubProps = [PropUserProperty +// "C\242\178\130f\163{W\US'\201m\140\230\EM\162\196" +// "\250\v\ESC\n\NAKw\135b2\164\243\&66n\"\nFF8\207\&1e\136\208s",PropTopicAlias 29241,PropReasonString +// "\203\243?\215\209\n\FS\225\ETBE\131z\252%7x\170\187\SOH\230\DC4\205\153\&6\140",PropContentType +// "\198\209i\134\198\251\EM~\155w\ENQ\255\148",PropAuthenticationMethod "n\148\231p\NAK\222<",PropRetainAvailable +// 172,PropPayloadFormatIndicator 179,PropReasonString +// "H3'\190\ESC#\237w'4!\v\139\210\189\224Zc\175U",PropSubscriptionIdentifier 16,PropReasonString +// "\183\&2iwD\212\148x\255\200(\209\&1\250?",PropRequestProblemInformation 206,PropReasonString +// "vFH\237\135\189D\242(^\201\159\EOT\EOT\148",PropWildcardSubscriptionAvailable 38,PropMessageExpiryInterval +// 17391,PropWildcardSubscriptionAvailable 86]} +TEST(Publish5QCTest, Decode13) { + uint8_t pkt[] = {0x38, 0xe7, 0x1, 0x0, 0x15, 0xb4, 0x5e, 0xb4, 0xc4, 0xa6, 0x1d, 0x8e, 0x17, 0xa, 0x70, 0x1f, 0xe2, + 0xe2, 0x6a, 0x2d, 0x82, 0xf2, 0x2b, 0x8a, 0xea, 0x41, 0xb4, 0x1, 0x26, 0x0, 0x11, 0x43, 0xf2, 0xb2, + 0x82, 0x66, 0xa3, 0x7b, 0x57, 0x1f, 0x27, 0xc9, 0x6d, 0x8c, 0xe6, 0x19, 0xa2, 0xc4, 0x0, 0x19, 0xfa, + 0xb, 0x1b, 0xa, 0x15, 0x77, 0x87, 0x62, 0x32, 0xa4, 0xf3, 0x36, 0x36, 0x6e, 0x22, 0xa, 0x46, 0x46, + 0x38, 0xcf, 0x31, 0x65, 0x88, 0xd0, 0x73, 0x23, 0x72, 0x39, 0x1f, 0x0, 0x19, 0xcb, 0xf3, 0x3f, 0xd7, + 0xd1, 0xa, 0x1c, 0xe1, 0x17, 0x45, 0x83, 0x7a, 0xfc, 0x25, 0x37, 0x78, 0xaa, 0xbb, 0x1, 0xe6, 0x14, + 0xcd, 0x99, 0x36, 0x8c, 0x3, 0x0, 0xd, 0xc6, 0xd1, 0x69, 0x86, 0xc6, 0xfb, 0x19, 0x7e, 0x9b, 0x77, + 0x5, 0xff, 0x94, 0x15, 0x0, 0x7, 0x6e, 0x94, 0xe7, 0x70, 0x15, 0xde, 0x3c, 0x25, 0xac, 0x1, 0xb3, + 0x1f, 0x0, 0x14, 0x48, 0x33, 0x27, 0xbe, 0x1b, 0x23, 0xed, 0x77, 0x27, 0x34, 0x21, 0xb, 0x8b, 0xd2, + 0xbd, 0xe0, 0x5a, 0x63, 0xaf, 0x55, 0xb, 0x10, 0x1f, 0x0, 0xf, 0xb7, 0x32, 0x69, 0x77, 0x44, 0xd4, + 0x94, 0x78, 0xff, 0xc8, 0x28, 0xd1, 0x31, 0xfa, 0x3f, 0x17, 0xce, 0x1f, 0x0, 0xf, 0x76, 0x46, 0x48, + 0xed, 0x87, 0xbd, 0x44, 0xf2, 0x28, 0x5e, 0xc9, 0x9f, 0x4, 0x4, 0x94, 0x28, 0x26, 0x2, 0x0, 0x0, + 0x43, 0xef, 0x28, 0x56, 0x2, 0x4e, 0x38, 0x74, 0x64, 0x4c, 0x76, 0xab, 0xdc, 0x33, 0x74, 0x75, 0xe1, + 0x9f, 0xa5, 0x56, 0x94, 0xb7, 0x26, 0x57, 0x36, 0xca, 0xca, 0xa5, 0x72, 0x1}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xb4, 0x5e, 0xb4, 0xc4, 0xa6, 0x1d, 0x8e, 0x17, 0xa, 0x70, 0x1f, + 0xe2, 0xe2, 0x6a, 0x2d, 0x82, 0xf2, 0x2b, 0x8a, 0xea, 0x41}; + lwmqtt_string_t exp_topic = {21, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x2, 0x4e, 0x38, 0x74, 0x64, 0x4c, 0x76, 0xab, 0xdc, 0x33, 0x74, 0x75, 0xe1, + 0x9f, 0xa5, 0x56, 0x94, 0xb7, 0x26, 0x57, 0x36, 0xca, 0xca, 0xa5, 0x72, 0x1}; + lwmqtt_string_t exp_body = {26, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 21); + EXPECT_EQ(msg.payload_len, 26); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 26); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS0, _pubRetain = True, _pubTopic = +// "\243\134\DC4\174\182\NAK\138\171\188\\\180\226\181G\223S\232\138f\172\170", _pubPktID = 0, _pubBody = +// "\b\177(\176\139\216T[#|\147\DC1\157R?$\242", _pubProps = [PropAssignedClientIdentifier +// ">q\205\132\243\222[\128]{\223\&5g\NUL\201)k~\149G\188\FS\168\DC2~L",PropRequestProblemInformation +// 79,PropRequestResponseInformation 203,PropResponseInformation +// "0\255n\182\ETB)\DC2\179e\219nn\183\209FM3r\191\168+\173\181\205=\EM",PropContentType +// "l\132\200\139`[\207\DC2\NUL\169\195\203\255\196q\205\132\243\222[\128]{\223\&5g\NUL\201)k~\149G\188\FS\168\DC2~L",PropRequestProblemInformation +// 79,PropRequestResponseInformation 203,PropResponseInformation +// "0\255n\182\ETB)\DC2\179e\219nn\183\209FM3r\191\168+\173\181\205=\EM",PropContentType +// "l\132\200\139`[\207\DC2\NUL\169\195\203\255\196(topic.data), 21); + EXPECT_EQ(msg.payload_len, 17); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 17); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "\CAN", _pubPktID = 21185, _pubBody = +// "\242\163\&2\173f\171\141\148\172\254\198\166\220=I\223\188q\204S\NUL\207\&8jS", _pubProps = +// [PropAssignedClientIdentifier +// "\163\179\143\191\207\143\185\145\246\239:cY5;\SOH\207L\150y\176\198",PropSubscriptionIdentifier 13,PropTopicAlias +// 13600,PropServerReference "\ESCjY\169",PropRetainAvailable 92,PropAssignedClientIdentifier +// "\162\147nB\a\131\SUBn\130\RSW\234\FS\164*/G\200\DEL5\ETXr",PropSessionExpiryInterval 9495,PropMessageExpiryInterval +// 17487,PropRetainAvailable 217,PropMessageExpiryInterval 16291,PropServerKeepAlive +// 13809,PropSubscriptionIdentifierAvailable 37,PropReasonString +// "\192i\179\152#\168\157\157\173(\223z\215\171;\152\150\210\214?&p>$\226",PropRequestProblemInformation +// 113,PropTopicAlias 4164]} +TEST(Publish5QCTest, Encode15) { + uint8_t pkt[] = {0x3b, 0x96, 0x1, 0x0, 0x1, 0x18, 0x52, 0xc1, 0x77, 0x12, 0x0, 0x16, 0xa3, 0xb3, 0x8f, 0xbf, + 0xcf, 0x8f, 0xb9, 0x91, 0xf6, 0xef, 0x3a, 0x63, 0x59, 0x35, 0x3b, 0x1, 0xcf, 0x4c, 0x96, 0x79, + 0xb0, 0xc6, 0xb, 0xd, 0x23, 0x35, 0x20, 0x1c, 0x0, 0x4, 0x1b, 0x6a, 0x59, 0xa9, 0x25, 0x5c, + 0x12, 0x0, 0x16, 0xa2, 0x93, 0x6e, 0x42, 0x7, 0x83, 0x1a, 0x6e, 0x82, 0x1e, 0x57, 0xea, 0x1c, + 0xa4, 0x2a, 0x2f, 0x47, 0xc8, 0x7f, 0x35, 0x3, 0x72, 0x11, 0x0, 0x0, 0x25, 0x17, 0x2, 0x0, + 0x0, 0x44, 0x4f, 0x25, 0xd9, 0x2, 0x0, 0x0, 0x3f, 0xa3, 0x13, 0x35, 0xf1, 0x29, 0x25, 0x1f, + 0x0, 0x19, 0xc0, 0x69, 0xb3, 0x98, 0x23, 0xa8, 0x9d, 0x9d, 0xad, 0x28, 0xdf, 0x7a, 0xd7, 0xab, + 0x3b, 0x98, 0x96, 0xd2, 0xd6, 0x3f, 0x26, 0x70, 0x3e, 0x24, 0xe2, 0x17, 0x71, 0x23, 0x10, 0x44, + 0xf2, 0xa3, 0x32, 0xad, 0x66, 0xab, 0x8d, 0x94, 0xac, 0xfe, 0xc6, 0xa6, 0xdc, 0x3d, 0x49, 0xdf, + 0xbc, 0x71, 0xcc, 0x53, 0x0, 0xcf, 0x38, 0x6a, 0x53}; + uint8_t topic_bytes[] = {0x18}; + lwmqtt_string_t topic = {1, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0xf2, 0xa3, 0x32, 0xad, 0x66, 0xab, 0x8d, 0x94, 0xac, 0xfe, 0xc6, 0xa6, 0xdc, + 0x3d, 0x49, 0xdf, 0xbc, 0x71, 0xcc, 0x53, 0x0, 0xcf, 0x38, 0x6a, 0x53}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 25; + + uint8_t bytesprops0[] = {0xa3, 0xb3, 0x8f, 0xbf, 0xcf, 0x8f, 0xb9, 0x91, 0xf6, 0xef, 0x3a, + 0x63, 0x59, 0x35, 0x3b, 0x1, 0xcf, 0x4c, 0x96, 0x79, 0xb0, 0xc6}; + uint8_t bytesprops1[] = {0x1b, 0x6a, 0x59, 0xa9}; + uint8_t bytesprops2[] = {0xa2, 0x93, 0x6e, 0x42, 0x7, 0x83, 0x1a, 0x6e, 0x82, 0x1e, 0x57, + 0xea, 0x1c, 0xa4, 0x2a, 0x2f, 0x47, 0xc8, 0x7f, 0x35, 0x3, 0x72}; + uint8_t bytesprops3[] = {0xc0, 0x69, 0xb3, 0x98, 0x23, 0xa8, 0x9d, 0x9d, 0xad, 0x28, 0xdf, 0x7a, 0xd7, + 0xab, 0x3b, 0x98, 0x96, 0xd2, 0xd6, 0x3f, 0x26, 0x70, 0x3e, 0x24, 0xe2}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)18, .value = {.str = {22, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 13}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 13600}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {4, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 92}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {22, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 9495}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 17487}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 217}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 16291}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 13809}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 37}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {25, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 113}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 4164}}, + }; + + lwmqtt_properties_t props = {15, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 21185, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "\CAN", _pubPktID = 21185, _pubBody = +// "\242\163\&2\173f\171\141\148\172\254\198\166\220=I\223\188q\204S\NUL\207\&8jS", _pubProps = +// [PropAssignedClientIdentifier +// "\163\179\143\191\207\143\185\145\246\239:cY5;\SOH\207L\150y\176\198",PropSubscriptionIdentifier 13,PropTopicAlias +// 13600,PropServerReference "\ESCjY\169",PropRetainAvailable 92,PropAssignedClientIdentifier +// "\162\147nB\a\131\SUBn\130\RSW\234\FS\164*/G\200\DEL5\ETXr",PropSessionExpiryInterval 9495,PropMessageExpiryInterval +// 17487,PropRetainAvailable 217,PropMessageExpiryInterval 16291,PropServerKeepAlive +// 13809,PropSubscriptionIdentifierAvailable 37,PropReasonString +// "\192i\179\152#\168\157\157\173(\223z\215\171;\152\150\210\214?&p>$\226",PropRequestProblemInformation +// 113,PropTopicAlias 4164]} +TEST(Publish5QCTest, Decode15) { + uint8_t pkt[] = {0x3b, 0x96, 0x1, 0x0, 0x1, 0x18, 0x52, 0xc1, 0x77, 0x12, 0x0, 0x16, 0xa3, 0xb3, 0x8f, 0xbf, + 0xcf, 0x8f, 0xb9, 0x91, 0xf6, 0xef, 0x3a, 0x63, 0x59, 0x35, 0x3b, 0x1, 0xcf, 0x4c, 0x96, 0x79, + 0xb0, 0xc6, 0xb, 0xd, 0x23, 0x35, 0x20, 0x1c, 0x0, 0x4, 0x1b, 0x6a, 0x59, 0xa9, 0x25, 0x5c, + 0x12, 0x0, 0x16, 0xa2, 0x93, 0x6e, 0x42, 0x7, 0x83, 0x1a, 0x6e, 0x82, 0x1e, 0x57, 0xea, 0x1c, + 0xa4, 0x2a, 0x2f, 0x47, 0xc8, 0x7f, 0x35, 0x3, 0x72, 0x11, 0x0, 0x0, 0x25, 0x17, 0x2, 0x0, + 0x0, 0x44, 0x4f, 0x25, 0xd9, 0x2, 0x0, 0x0, 0x3f, 0xa3, 0x13, 0x35, 0xf1, 0x29, 0x25, 0x1f, + 0x0, 0x19, 0xc0, 0x69, 0xb3, 0x98, 0x23, 0xa8, 0x9d, 0x9d, 0xad, 0x28, 0xdf, 0x7a, 0xd7, 0xab, + 0x3b, 0x98, 0x96, 0xd2, 0xd6, 0x3f, 0x26, 0x70, 0x3e, 0x24, 0xe2, 0x17, 0x71, 0x23, 0x10, 0x44, + 0xf2, 0xa3, 0x32, 0xad, 0x66, 0xab, 0x8d, 0x94, 0xac, 0xfe, 0xc6, 0xa6, 0xdc, 0x3d, 0x49, 0xdf, + 0xbc, 0x71, 0xcc, 0x53, 0x0, 0xcf, 0x38, 0x6a, 0x53}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x18}; + lwmqtt_string_t exp_topic = {1, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xf2, 0xa3, 0x32, 0xad, 0x66, 0xab, 0x8d, 0x94, 0xac, 0xfe, 0xc6, 0xa6, 0xdc, + 0x3d, 0x49, 0xdf, 0xbc, 0x71, 0xcc, 0x53, 0x0, 0xcf, 0x38, 0x6a, 0x53}; + lwmqtt_string_t exp_body = {25, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 21185); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 1); + EXPECT_EQ(msg.payload_len, 25); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 25); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "\tW7", _pubPktID = 0, _pubBody = +// "<\173\DLE`;<%6\196ne\143\&7_\DC2&K\177\250\145(topic.data), 3); + EXPECT_EQ(msg.payload_len, 26); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 26); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "#rf\225\210\223\183\179#", _pubPktID +// = 0, _pubBody = "\225\141\154:Z\166E\DLEF\164\218\176U\138\191\RSV[\255\160=\DC1@\195r~WH\245", _pubProps = +// [PropUserProperty "Jn\t\166q\DLE\175\&5\131\ETB\176" +// "\225dt\254\144\DC2\ae\t\209?\232y\248\242Kv\184kAj\145\139-",PropTopicAlias 24033,PropPayloadFormatIndicator +// 94,PropReceiveMaximum 9447,PropReceiveMaximum 23844,PropMessageExpiryInterval 12367,PropTopicAlias 32717]} +TEST(Publish5QCTest, Encode17) { + uint8_t pkt[] = {0x39, 0x64, 0x0, 0x9, 0x23, 0x72, 0x66, 0xe1, 0xd2, 0xdf, 0xb7, 0xb3, 0x23, 0x3b, 0x26, + 0x0, 0xb, 0x4a, 0x6e, 0x9, 0xa6, 0x71, 0x10, 0xaf, 0x35, 0x83, 0x17, 0xb0, 0x0, 0x18, + 0xe1, 0x64, 0x74, 0xfe, 0x90, 0x12, 0x7, 0x65, 0x9, 0xd1, 0x3f, 0xe8, 0x79, 0xf8, 0xf2, + 0x4b, 0x76, 0xb8, 0x6b, 0x41, 0x6a, 0x91, 0x8b, 0x2d, 0x23, 0x5d, 0xe1, 0x1, 0x5e, 0x21, + 0x24, 0xe7, 0x21, 0x5d, 0x24, 0x2, 0x0, 0x0, 0x30, 0x4f, 0x23, 0x7f, 0xcd, 0xe1, 0x8d, + 0x9a, 0x3a, 0x5a, 0xa6, 0x45, 0x10, 0x46, 0xa4, 0xda, 0xb0, 0x55, 0x8a, 0xbf, 0x1e, 0x56, + 0x5b, 0xff, 0xa0, 0x3d, 0x11, 0x40, 0xc3, 0x72, 0x7e, 0x57, 0x48, 0xf5}; + uint8_t topic_bytes[] = {0x23, 0x72, 0x66, 0xe1, 0xd2, 0xdf, 0xb7, 0xb3, 0x23}; + lwmqtt_string_t topic = {9, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = true; + uint8_t msg_bytes[] = {0xe1, 0x8d, 0x9a, 0x3a, 0x5a, 0xa6, 0x45, 0x10, 0x46, 0xa4, 0xda, 0xb0, 0x55, 0x8a, 0xbf, + 0x1e, 0x56, 0x5b, 0xff, 0xa0, 0x3d, 0x11, 0x40, 0xc3, 0x72, 0x7e, 0x57, 0x48, 0xf5}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 29; + + uint8_t bytesprops1[] = {0xe1, 0x64, 0x74, 0xfe, 0x90, 0x12, 0x7, 0x65, 0x9, 0xd1, 0x3f, 0xe8, + 0x79, 0xf8, 0xf2, 0x4b, 0x76, 0xb8, 0x6b, 0x41, 0x6a, 0x91, 0x8b, 0x2d}; + uint8_t bytesprops0[] = {0x4a, 0x6e, 0x9, 0xa6, 0x71, 0x10, 0xaf, 0x35, 0x83, 0x17, 0xb0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {11, (char*)&bytesprops0}, .v = {24, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 24033}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 94}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 9447}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 23844}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 12367}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 32717}}, + }; + + lwmqtt_properties_t props = {7, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "#rf\225\210\223\183\179#", _pubPktID +// = 0, _pubBody = "\225\141\154:Z\166E\DLEF\164\218\176U\138\191\RSV[\255\160=\DC1@\195r~WH\245", _pubProps = +// [PropUserProperty "Jn\t\166q\DLE\175\&5\131\ETB\176" +// "\225dt\254\144\DC2\ae\t\209?\232y\248\242Kv\184kAj\145\139-",PropTopicAlias 24033,PropPayloadFormatIndicator +// 94,PropReceiveMaximum 9447,PropReceiveMaximum 23844,PropMessageExpiryInterval 12367,PropTopicAlias 32717]} +TEST(Publish5QCTest, Decode17) { + uint8_t pkt[] = {0x39, 0x64, 0x0, 0x9, 0x23, 0x72, 0x66, 0xe1, 0xd2, 0xdf, 0xb7, 0xb3, 0x23, 0x3b, 0x26, + 0x0, 0xb, 0x4a, 0x6e, 0x9, 0xa6, 0x71, 0x10, 0xaf, 0x35, 0x83, 0x17, 0xb0, 0x0, 0x18, + 0xe1, 0x64, 0x74, 0xfe, 0x90, 0x12, 0x7, 0x65, 0x9, 0xd1, 0x3f, 0xe8, 0x79, 0xf8, 0xf2, + 0x4b, 0x76, 0xb8, 0x6b, 0x41, 0x6a, 0x91, 0x8b, 0x2d, 0x23, 0x5d, 0xe1, 0x1, 0x5e, 0x21, + 0x24, 0xe7, 0x21, 0x5d, 0x24, 0x2, 0x0, 0x0, 0x30, 0x4f, 0x23, 0x7f, 0xcd, 0xe1, 0x8d, + 0x9a, 0x3a, 0x5a, 0xa6, 0x45, 0x10, 0x46, 0xa4, 0xda, 0xb0, 0x55, 0x8a, 0xbf, 0x1e, 0x56, + 0x5b, 0xff, 0xa0, 0x3d, 0x11, 0x40, 0xc3, 0x72, 0x7e, 0x57, 0x48, 0xf5}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x23, 0x72, 0x66, 0xe1, 0xd2, 0xdf, 0xb7, 0xb3, 0x23}; + lwmqtt_string_t exp_topic = {9, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xe1, 0x8d, 0x9a, 0x3a, 0x5a, 0xa6, 0x45, 0x10, 0x46, 0xa4, 0xda, 0xb0, 0x55, 0x8a, 0xbf, + 0x1e, 0x56, 0x5b, 0xff, 0xa0, 0x3d, 0x11, 0x40, 0xc3, 0x72, 0x7e, 0x57, 0x48, 0xf5}; + lwmqtt_string_t exp_body = {29, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 9); + EXPECT_EQ(msg.payload_len, 29); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 29); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "\250\DLE\228\172ZB\231\208\ETX\170e\DC3\177\170\203", _pubPktID = 20110, _pubBody = +// "xx\193Br\133\207:\183_\RS:zx\155", _pubProps = [PropMaximumPacketSize 29548,PropAssignedClientIdentifier +// "e\153\148",PropAuthenticationData "=[\206:\NAK\230\156rO=\NULP\205\172\SUB|\129\204\165",PropAuthenticationMethod +// "V3\b\196\179\r\140\222Qu\157z",PropRequestProblemInformation 94,PropSubscriptionIdentifier 8,PropResponseInformation +// "y\186\EM\211\161\136\181\n\205:\221\DLE8",PropMessageExpiryInterval 27705,PropTopicAliasMaximum +// 28714,PropCorrelationData ";\ENQ\160 +// \133K\ESCl?a\133\142\152\184\154\DC4\254\206\224\r\177\187?S\172\190\130\161",PropResponseTopic ""]} +TEST(Publish5QCTest, Encode18) { + uint8_t pkt[] = {0x3a, 0x91, 0x1, 0x0, 0xf, 0xfa, 0x10, 0xe4, 0xac, 0x5a, 0x42, 0xe7, 0xd0, 0x3, 0xaa, 0x65, 0x13, + 0xb1, 0xaa, 0xcb, 0x4e, 0x8e, 0x6e, 0x27, 0x0, 0x0, 0x73, 0x6c, 0x12, 0x0, 0x3, 0x65, 0x99, 0x94, + 0x16, 0x0, 0x13, 0x3d, 0x5b, 0xce, 0x3a, 0x15, 0xe6, 0x9c, 0x72, 0x4f, 0x3d, 0x0, 0x50, 0xcd, 0xac, + 0x1a, 0x7c, 0x81, 0xcc, 0xa5, 0x15, 0x0, 0xc, 0x56, 0x33, 0x8, 0xc4, 0xb3, 0xd, 0x8c, 0xde, 0x51, + 0x75, 0x9d, 0x7a, 0x17, 0x5e, 0xb, 0x8, 0x1a, 0x0, 0xd, 0x79, 0xba, 0x19, 0xd3, 0xa1, 0x88, 0xb5, + 0xa, 0xcd, 0x3a, 0xdd, 0x10, 0x38, 0x2, 0x0, 0x0, 0x6c, 0x39, 0x22, 0x70, 0x2a, 0x9, 0x0, 0x1c, + 0x3b, 0x5, 0xa0, 0x20, 0x85, 0x4b, 0x1b, 0x6c, 0x3f, 0x61, 0x85, 0x8e, 0x98, 0xb8, 0x9a, 0x14, 0xfe, + 0xce, 0xe0, 0xd, 0xb1, 0xbb, 0x3f, 0x53, 0xac, 0xbe, 0x82, 0xa1, 0x8, 0x0, 0x0, 0x78, 0x78, 0xc1, + 0x42, 0x72, 0x85, 0xcf, 0x3a, 0xb7, 0x5f, 0x1e, 0x3a, 0x7a, 0x78, 0x9b}; + uint8_t topic_bytes[] = {0xfa, 0x10, 0xe4, 0xac, 0x5a, 0x42, 0xe7, 0xd0, 0x3, 0xaa, 0x65, 0x13, 0xb1, 0xaa, 0xcb}; + lwmqtt_string_t topic = {15, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = false; + uint8_t msg_bytes[] = {0x78, 0x78, 0xc1, 0x42, 0x72, 0x85, 0xcf, 0x3a, 0xb7, 0x5f, 0x1e, 0x3a, 0x7a, 0x78, 0x9b}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 15; + + uint8_t bytesprops0[] = {0x65, 0x99, 0x94}; + uint8_t bytesprops1[] = {0x3d, 0x5b, 0xce, 0x3a, 0x15, 0xe6, 0x9c, 0x72, 0x4f, 0x3d, + 0x0, 0x50, 0xcd, 0xac, 0x1a, 0x7c, 0x81, 0xcc, 0xa5}; + uint8_t bytesprops2[] = {0x56, 0x33, 0x8, 0xc4, 0xb3, 0xd, 0x8c, 0xde, 0x51, 0x75, 0x9d, 0x7a}; + uint8_t bytesprops3[] = {0x79, 0xba, 0x19, 0xd3, 0xa1, 0x88, 0xb5, 0xa, 0xcd, 0x3a, 0xdd, 0x10, 0x38}; + uint8_t bytesprops4[] = {0x3b, 0x5, 0xa0, 0x20, 0x85, 0x4b, 0x1b, 0x6c, 0x3f, 0x61, 0x85, 0x8e, 0x98, 0xb8, + 0x9a, 0x14, 0xfe, 0xce, 0xe0, 0xd, 0xb1, 0xbb, 0x3f, 0x53, 0xac, 0xbe, 0x82, 0xa1}; + uint8_t bytesprops5[] = {0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 29548}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {3, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {19, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {12, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 94}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 8}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {13, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 27705}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 28714}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {28, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {0, (char*)&bytesprops5}}}, + }; + + lwmqtt_properties_t props = {11, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 20110, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = False, _pubTopic = +// "\250\DLE\228\172ZB\231\208\ETX\170e\DC3\177\170\203", _pubPktID = 20110, _pubBody = +// "xx\193Br\133\207:\183_\RS:zx\155", _pubProps = [PropMaximumPacketSize 29548,PropAssignedClientIdentifier +// "e\153\148",PropAuthenticationData "=[\206:\NAK\230\156rO=\NULP\205\172\SUB|\129\204\165",PropAuthenticationMethod +// "V3\b\196\179\r\140\222Qu\157z",PropRequestProblemInformation 94,PropSubscriptionIdentifier 8,PropResponseInformation +// "y\186\EM\211\161\136\181\n\205:\221\DLE8",PropMessageExpiryInterval 27705,PropTopicAliasMaximum +// 28714,PropCorrelationData ";\ENQ\160 +// \133K\ESCl?a\133\142\152\184\154\DC4\254\206\224\r\177\187?S\172\190\130\161",PropResponseTopic ""]} +TEST(Publish5QCTest, Decode18) { + uint8_t pkt[] = {0x3a, 0x91, 0x1, 0x0, 0xf, 0xfa, 0x10, 0xe4, 0xac, 0x5a, 0x42, 0xe7, 0xd0, 0x3, 0xaa, 0x65, 0x13, + 0xb1, 0xaa, 0xcb, 0x4e, 0x8e, 0x6e, 0x27, 0x0, 0x0, 0x73, 0x6c, 0x12, 0x0, 0x3, 0x65, 0x99, 0x94, + 0x16, 0x0, 0x13, 0x3d, 0x5b, 0xce, 0x3a, 0x15, 0xe6, 0x9c, 0x72, 0x4f, 0x3d, 0x0, 0x50, 0xcd, 0xac, + 0x1a, 0x7c, 0x81, 0xcc, 0xa5, 0x15, 0x0, 0xc, 0x56, 0x33, 0x8, 0xc4, 0xb3, 0xd, 0x8c, 0xde, 0x51, + 0x75, 0x9d, 0x7a, 0x17, 0x5e, 0xb, 0x8, 0x1a, 0x0, 0xd, 0x79, 0xba, 0x19, 0xd3, 0xa1, 0x88, 0xb5, + 0xa, 0xcd, 0x3a, 0xdd, 0x10, 0x38, 0x2, 0x0, 0x0, 0x6c, 0x39, 0x22, 0x70, 0x2a, 0x9, 0x0, 0x1c, + 0x3b, 0x5, 0xa0, 0x20, 0x85, 0x4b, 0x1b, 0x6c, 0x3f, 0x61, 0x85, 0x8e, 0x98, 0xb8, 0x9a, 0x14, 0xfe, + 0xce, 0xe0, 0xd, 0xb1, 0xbb, 0x3f, 0x53, 0xac, 0xbe, 0x82, 0xa1, 0x8, 0x0, 0x0, 0x78, 0x78, 0xc1, + 0x42, 0x72, 0x85, 0xcf, 0x3a, 0xb7, 0x5f, 0x1e, 0x3a, 0x7a, 0x78, 0x9b}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xfa, 0x10, 0xe4, 0xac, 0x5a, 0x42, 0xe7, 0xd0, 0x3, 0xaa, 0x65, 0x13, 0xb1, 0xaa, 0xcb}; + lwmqtt_string_t exp_topic = {15, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x78, 0x78, 0xc1, 0x42, 0x72, 0x85, 0xcf, 0x3a, 0xb7, 0x5f, 0x1e, 0x3a, 0x7a, 0x78, 0x9b}; + lwmqtt_string_t exp_body = {15, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 20110); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 15); + EXPECT_EQ(msg.payload_len, 15); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 15); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = "\219DL\230\173kI\194", _pubPktID = +// 0, _pubBody = "k@\192\208$\186\173\v\213b\157\255\206\DLE\253xC", _pubProps = [PropCorrelationData +// "\DC1\208\DC1\216%&aX\DLE\175Y\218",PropMessageExpiryInterval 26517,PropSubscriptionIdentifier +// 23,PropMessageExpiryInterval 15730,PropPayloadFormatIndicator 182,PropAuthenticationMethod +// "\248g\201\230)o\167\158\170\DLE\169",PropRequestProblemInformation 200,PropAuthenticationMethod +// "\201|cS",PropCorrelationData "!t\134M@\SUB\241",PropMessageExpiryInterval 25589,PropRequestProblemInformation +// 35,PropSubscriptionIdentifier 24,PropSessionExpiryInterval 2715,PropMaximumQoS 107,PropSessionExpiryInterval +// 20616,PropSessionExpiryInterval 23806,PropSharedSubscriptionAvailable 218,PropWildcardSubscriptionAvailable +// 120,PropRequestProblemInformation 215,PropPayloadFormatIndicator 99,PropContentType +// "\SOM\186\152\249\253\174\186\CAN\222\135K\t\255\172LFGj\ETB)\244\187",PropMessageExpiryInterval +// 30084,PropSubscriptionIdentifier 27,PropUserProperty "&\DC1\230\138\175\196\200\193uD\US>\152P" +// "L}\144\165\175\ENQ\GS=\236u~\136xkm*\DELE\180\ETX\232\&7S\204]%\219",PropWildcardSubscriptionAvailable +// 207,PropTopicAliasMaximum 30302]} +TEST(Publish5QCTest, Encode19) { + uint8_t pkt[] = {0x38, 0xd1, 0x1, 0x0, 0x8, 0xdb, 0x44, 0x4c, 0xe6, 0xad, 0x6b, 0x49, 0xc2, 0xb4, 0x1, 0x9, 0x0, + 0xc, 0x11, 0xd0, 0x11, 0xd8, 0x25, 0x26, 0x61, 0x58, 0x10, 0xaf, 0x59, 0xda, 0x2, 0x0, 0x0, 0x67, + 0x95, 0xb, 0x17, 0x2, 0x0, 0x0, 0x3d, 0x72, 0x1, 0xb6, 0x15, 0x0, 0xb, 0xf8, 0x67, 0xc9, 0xe6, + 0x29, 0x6f, 0xa7, 0x9e, 0xaa, 0x10, 0xa9, 0x17, 0xc8, 0x15, 0x0, 0x4, 0xc9, 0x7c, 0x63, 0x53, 0x9, + 0x0, 0x7, 0x21, 0x74, 0x86, 0x4d, 0x40, 0x1a, 0xf1, 0x2, 0x0, 0x0, 0x63, 0xf5, 0x17, 0x23, 0xb, + 0x18, 0x11, 0x0, 0x0, 0xa, 0x9b, 0x24, 0x6b, 0x11, 0x0, 0x0, 0x50, 0x88, 0x11, 0x0, 0x0, 0x5c, + 0xfe, 0x2a, 0xda, 0x28, 0x78, 0x17, 0xd7, 0x1, 0x63, 0x3, 0x0, 0x17, 0xe, 0x4d, 0xba, 0x98, 0xf9, + 0xfd, 0xae, 0xba, 0x18, 0xde, 0x87, 0x4b, 0x9, 0xff, 0xac, 0x4c, 0x46, 0x47, 0x6a, 0x17, 0x29, 0xf4, + 0xbb, 0x2, 0x0, 0x0, 0x75, 0x84, 0xb, 0x1b, 0x26, 0x0, 0xe, 0x26, 0x11, 0xe6, 0x8a, 0xaf, 0xc4, + 0xc8, 0xc1, 0x75, 0x44, 0x1f, 0x3e, 0x98, 0x50, 0x0, 0x1b, 0x4c, 0x7d, 0x90, 0xa5, 0xaf, 0x5, 0x1d, + 0x3d, 0xec, 0x75, 0x7e, 0x88, 0x78, 0x6b, 0x6d, 0x2a, 0x7f, 0x45, 0xb4, 0x3, 0xe8, 0x37, 0x53, 0xcc, + 0x5d, 0x25, 0xdb, 0x28, 0xcf, 0x22, 0x76, 0x5e, 0x6b, 0x40, 0xc0, 0xd0, 0x24, 0xba, 0xad, 0xb, 0xd5, + 0x62, 0x9d, 0xff, 0xce, 0x10, 0xfd, 0x78, 0x43}; + uint8_t topic_bytes[] = {0xdb, 0x44, 0x4c, 0xe6, 0xad, 0x6b, 0x49, 0xc2}; + lwmqtt_string_t topic = {8, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = false; + uint8_t msg_bytes[] = {0x6b, 0x40, 0xc0, 0xd0, 0x24, 0xba, 0xad, 0xb, 0xd5, + 0x62, 0x9d, 0xff, 0xce, 0x10, 0xfd, 0x78, 0x43}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 17; + + uint8_t bytesprops0[] = {0x11, 0xd0, 0x11, 0xd8, 0x25, 0x26, 0x61, 0x58, 0x10, 0xaf, 0x59, 0xda}; + uint8_t bytesprops1[] = {0xf8, 0x67, 0xc9, 0xe6, 0x29, 0x6f, 0xa7, 0x9e, 0xaa, 0x10, 0xa9}; + uint8_t bytesprops2[] = {0xc9, 0x7c, 0x63, 0x53}; + uint8_t bytesprops3[] = {0x21, 0x74, 0x86, 0x4d, 0x40, 0x1a, 0xf1}; + uint8_t bytesprops4[] = {0xe, 0x4d, 0xba, 0x98, 0xf9, 0xfd, 0xae, 0xba, 0x18, 0xde, 0x87, 0x4b, + 0x9, 0xff, 0xac, 0x4c, 0x46, 0x47, 0x6a, 0x17, 0x29, 0xf4, 0xbb}; + uint8_t bytesprops6[] = {0x4c, 0x7d, 0x90, 0xa5, 0xaf, 0x5, 0x1d, 0x3d, 0xec, 0x75, 0x7e, 0x88, 0x78, 0x6b, + 0x6d, 0x2a, 0x7f, 0x45, 0xb4, 0x3, 0xe8, 0x37, 0x53, 0xcc, 0x5d, 0x25, 0xdb}; + uint8_t bytesprops5[] = {0x26, 0x11, 0xe6, 0x8a, 0xaf, 0xc4, 0xc8, 0xc1, 0x75, 0x44, 0x1f, 0x3e, 0x98, 0x50}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)9, .value = {.str = {12, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 26517}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 23}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 15730}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 182}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {11, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 200}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {4, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {7, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 25589}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 35}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 24}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 2715}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 107}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 20616}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 23806}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 218}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 120}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 215}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 99}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {23, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 30084}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 27}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {14, (char*)&bytesprops5}, .v = {27, (char*)&bytesprops6}}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 207}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 30302}}, + }; + + lwmqtt_properties_t props = {26, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = "\219DL\230\173kI\194", _pubPktID = +// 0, _pubBody = "k@\192\208$\186\173\v\213b\157\255\206\DLE\253xC", _pubProps = [PropCorrelationData +// "\DC1\208\DC1\216%&aX\DLE\175Y\218",PropMessageExpiryInterval 26517,PropSubscriptionIdentifier +// 23,PropMessageExpiryInterval 15730,PropPayloadFormatIndicator 182,PropAuthenticationMethod +// "\248g\201\230)o\167\158\170\DLE\169",PropRequestProblemInformation 200,PropAuthenticationMethod +// "\201|cS",PropCorrelationData "!t\134M@\SUB\241",PropMessageExpiryInterval 25589,PropRequestProblemInformation +// 35,PropSubscriptionIdentifier 24,PropSessionExpiryInterval 2715,PropMaximumQoS 107,PropSessionExpiryInterval +// 20616,PropSessionExpiryInterval 23806,PropSharedSubscriptionAvailable 218,PropWildcardSubscriptionAvailable +// 120,PropRequestProblemInformation 215,PropPayloadFormatIndicator 99,PropContentType +// "\SOM\186\152\249\253\174\186\CAN\222\135K\t\255\172LFGj\ETB)\244\187",PropMessageExpiryInterval +// 30084,PropSubscriptionIdentifier 27,PropUserProperty "&\DC1\230\138\175\196\200\193uD\US>\152P" +// "L}\144\165\175\ENQ\GS=\236u~\136xkm*\DELE\180\ETX\232\&7S\204]%\219",PropWildcardSubscriptionAvailable +// 207,PropTopicAliasMaximum 30302]} +TEST(Publish5QCTest, Decode19) { + uint8_t pkt[] = {0x38, 0xd1, 0x1, 0x0, 0x8, 0xdb, 0x44, 0x4c, 0xe6, 0xad, 0x6b, 0x49, 0xc2, 0xb4, 0x1, 0x9, 0x0, + 0xc, 0x11, 0xd0, 0x11, 0xd8, 0x25, 0x26, 0x61, 0x58, 0x10, 0xaf, 0x59, 0xda, 0x2, 0x0, 0x0, 0x67, + 0x95, 0xb, 0x17, 0x2, 0x0, 0x0, 0x3d, 0x72, 0x1, 0xb6, 0x15, 0x0, 0xb, 0xf8, 0x67, 0xc9, 0xe6, + 0x29, 0x6f, 0xa7, 0x9e, 0xaa, 0x10, 0xa9, 0x17, 0xc8, 0x15, 0x0, 0x4, 0xc9, 0x7c, 0x63, 0x53, 0x9, + 0x0, 0x7, 0x21, 0x74, 0x86, 0x4d, 0x40, 0x1a, 0xf1, 0x2, 0x0, 0x0, 0x63, 0xf5, 0x17, 0x23, 0xb, + 0x18, 0x11, 0x0, 0x0, 0xa, 0x9b, 0x24, 0x6b, 0x11, 0x0, 0x0, 0x50, 0x88, 0x11, 0x0, 0x0, 0x5c, + 0xfe, 0x2a, 0xda, 0x28, 0x78, 0x17, 0xd7, 0x1, 0x63, 0x3, 0x0, 0x17, 0xe, 0x4d, 0xba, 0x98, 0xf9, + 0xfd, 0xae, 0xba, 0x18, 0xde, 0x87, 0x4b, 0x9, 0xff, 0xac, 0x4c, 0x46, 0x47, 0x6a, 0x17, 0x29, 0xf4, + 0xbb, 0x2, 0x0, 0x0, 0x75, 0x84, 0xb, 0x1b, 0x26, 0x0, 0xe, 0x26, 0x11, 0xe6, 0x8a, 0xaf, 0xc4, + 0xc8, 0xc1, 0x75, 0x44, 0x1f, 0x3e, 0x98, 0x50, 0x0, 0x1b, 0x4c, 0x7d, 0x90, 0xa5, 0xaf, 0x5, 0x1d, + 0x3d, 0xec, 0x75, 0x7e, 0x88, 0x78, 0x6b, 0x6d, 0x2a, 0x7f, 0x45, 0xb4, 0x3, 0xe8, 0x37, 0x53, 0xcc, + 0x5d, 0x25, 0xdb, 0x28, 0xcf, 0x22, 0x76, 0x5e, 0x6b, 0x40, 0xc0, 0xd0, 0x24, 0xba, 0xad, 0xb, 0xd5, + 0x62, 0x9d, 0xff, 0xce, 0x10, 0xfd, 0x78, 0x43}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xdb, 0x44, 0x4c, 0xe6, 0xad, 0x6b, 0x49, 0xc2}; + lwmqtt_string_t exp_topic = {8, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x6b, 0x40, 0xc0, 0xd0, 0x24, 0xba, 0xad, 0xb, 0xd5, + 0x62, 0x9d, 0xff, 0xce, 0x10, 0xfd, 0x78, 0x43}; + lwmqtt_string_t exp_body = {17, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 8); + EXPECT_EQ(msg.payload_len, 17); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 17); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "{\153\DLEV", _pubPktID = 16334, +// _pubBody = "\SI\238\166\129\190\133\&2k\213\ETBtC\246", _pubProps = [PropMessageExpiryInterval +// 18569,PropResponseTopic "\179\208\211\237\203\142B\EM^\\o]\148\241\&7\204]",PropPayloadFormatIndicator +// 46,PropAuthenticationMethod +// "o??\237\250\155\151\fl`#\b\229\243\221\185\208\237\136\215\&7\217$",PropPayloadFormatIndicator 8,PropMaximumQoS +// 229,PropRequestProblemInformation 140,PropReasonString +// "\228\234\254\154g\192\191\232\t\188V\218M\189\172R\185\203(\196",PropUserProperty +// "\158;0|\DC1e/\228\142\157BG\198H\193\142c\234\NULb\179`\169" "#6x1\245}eK\205~\254\ACKG\CAN`\242",PropMaximumQoS +// 232]} +TEST(Publish5QCTest, Encode20) { + uint8_t pkt[] = {0x3c, 0x97, 0x1, 0x0, 0x4, 0x7b, 0x99, 0x10, 0x56, 0x3f, 0xce, 0x80, 0x1, 0x2, 0x0, 0x0, + 0x48, 0x89, 0x8, 0x0, 0x11, 0xb3, 0xd0, 0xd3, 0xed, 0xcb, 0x8e, 0x42, 0x19, 0x5e, 0x5c, 0x6f, + 0x5d, 0x94, 0xf1, 0x37, 0xcc, 0x5d, 0x1, 0x2e, 0x15, 0x0, 0x17, 0x6f, 0x3f, 0x3f, 0xed, 0xfa, + 0x9b, 0x97, 0xc, 0x6c, 0x60, 0x23, 0x8, 0xe5, 0xf3, 0xdd, 0xb9, 0xd0, 0xed, 0x88, 0xd7, 0x37, + 0xd9, 0x24, 0x1, 0x8, 0x24, 0xe5, 0x17, 0x8c, 0x1f, 0x0, 0x14, 0xe4, 0xea, 0xfe, 0x9a, 0x67, + 0xc0, 0xbf, 0xe8, 0x9, 0xbc, 0x56, 0xda, 0x4d, 0xbd, 0xac, 0x52, 0xb9, 0xcb, 0x28, 0xc4, 0x26, + 0x0, 0x17, 0x9e, 0x3b, 0x30, 0x7c, 0x11, 0x65, 0x2f, 0xe4, 0x8e, 0x9d, 0x42, 0x47, 0xc6, 0x48, + 0xc1, 0x8e, 0x63, 0xea, 0x0, 0x62, 0xb3, 0x60, 0xa9, 0x0, 0x10, 0x23, 0x36, 0x78, 0x31, 0xf5, + 0x7d, 0x65, 0x4b, 0xcd, 0x7e, 0xfe, 0x6, 0x47, 0x18, 0x60, 0xf2, 0x24, 0xe8, 0xf, 0xee, 0xa6, + 0x81, 0xbe, 0x85, 0x32, 0x6b, 0xd5, 0x17, 0x74, 0x43, 0xf6}; + uint8_t topic_bytes[] = {0x7b, 0x99, 0x10, 0x56}; + lwmqtt_string_t topic = {4, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0xf, 0xee, 0xa6, 0x81, 0xbe, 0x85, 0x32, 0x6b, 0xd5, 0x17, 0x74, 0x43, 0xf6}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 13; + + uint8_t bytesprops0[] = {0xb3, 0xd0, 0xd3, 0xed, 0xcb, 0x8e, 0x42, 0x19, 0x5e, + 0x5c, 0x6f, 0x5d, 0x94, 0xf1, 0x37, 0xcc, 0x5d}; + uint8_t bytesprops1[] = {0x6f, 0x3f, 0x3f, 0xed, 0xfa, 0x9b, 0x97, 0xc, 0x6c, 0x60, 0x23, 0x8, + 0xe5, 0xf3, 0xdd, 0xb9, 0xd0, 0xed, 0x88, 0xd7, 0x37, 0xd9, 0x24}; + uint8_t bytesprops2[] = {0xe4, 0xea, 0xfe, 0x9a, 0x67, 0xc0, 0xbf, 0xe8, 0x9, 0xbc, + 0x56, 0xda, 0x4d, 0xbd, 0xac, 0x52, 0xb9, 0xcb, 0x28, 0xc4}; + uint8_t bytesprops4[] = {0x23, 0x36, 0x78, 0x31, 0xf5, 0x7d, 0x65, 0x4b, + 0xcd, 0x7e, 0xfe, 0x6, 0x47, 0x18, 0x60, 0xf2}; + uint8_t bytesprops3[] = {0x9e, 0x3b, 0x30, 0x7c, 0x11, 0x65, 0x2f, 0xe4, 0x8e, 0x9d, 0x42, 0x47, + 0xc6, 0x48, 0xc1, 0x8e, 0x63, 0xea, 0x0, 0x62, 0xb3, 0x60, 0xa9}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 18569}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {17, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 46}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {23, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 8}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 229}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 140}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {20, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {23, (char*)&bytesprops3}, .v = {16, (char*)&bytesprops4}}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 232}}, + }; + + lwmqtt_properties_t props = {10, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 16334, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "{\153\DLEV", _pubPktID = 16334, +// _pubBody = "\SI\238\166\129\190\133\&2k\213\ETBtC\246", _pubProps = [PropMessageExpiryInterval +// 18569,PropResponseTopic "\179\208\211\237\203\142B\EM^\\o]\148\241\&7\204]",PropPayloadFormatIndicator +// 46,PropAuthenticationMethod +// "o??\237\250\155\151\fl`#\b\229\243\221\185\208\237\136\215\&7\217$",PropPayloadFormatIndicator 8,PropMaximumQoS +// 229,PropRequestProblemInformation 140,PropReasonString +// "\228\234\254\154g\192\191\232\t\188V\218M\189\172R\185\203(\196",PropUserProperty +// "\158;0|\DC1e/\228\142\157BG\198H\193\142c\234\NULb\179`\169" "#6x1\245}eK\205~\254\ACKG\CAN`\242",PropMaximumQoS +// 232]} +TEST(Publish5QCTest, Decode20) { + uint8_t pkt[] = {0x3c, 0x97, 0x1, 0x0, 0x4, 0x7b, 0x99, 0x10, 0x56, 0x3f, 0xce, 0x80, 0x1, 0x2, 0x0, 0x0, + 0x48, 0x89, 0x8, 0x0, 0x11, 0xb3, 0xd0, 0xd3, 0xed, 0xcb, 0x8e, 0x42, 0x19, 0x5e, 0x5c, 0x6f, + 0x5d, 0x94, 0xf1, 0x37, 0xcc, 0x5d, 0x1, 0x2e, 0x15, 0x0, 0x17, 0x6f, 0x3f, 0x3f, 0xed, 0xfa, + 0x9b, 0x97, 0xc, 0x6c, 0x60, 0x23, 0x8, 0xe5, 0xf3, 0xdd, 0xb9, 0xd0, 0xed, 0x88, 0xd7, 0x37, + 0xd9, 0x24, 0x1, 0x8, 0x24, 0xe5, 0x17, 0x8c, 0x1f, 0x0, 0x14, 0xe4, 0xea, 0xfe, 0x9a, 0x67, + 0xc0, 0xbf, 0xe8, 0x9, 0xbc, 0x56, 0xda, 0x4d, 0xbd, 0xac, 0x52, 0xb9, 0xcb, 0x28, 0xc4, 0x26, + 0x0, 0x17, 0x9e, 0x3b, 0x30, 0x7c, 0x11, 0x65, 0x2f, 0xe4, 0x8e, 0x9d, 0x42, 0x47, 0xc6, 0x48, + 0xc1, 0x8e, 0x63, 0xea, 0x0, 0x62, 0xb3, 0x60, 0xa9, 0x0, 0x10, 0x23, 0x36, 0x78, 0x31, 0xf5, + 0x7d, 0x65, 0x4b, 0xcd, 0x7e, 0xfe, 0x6, 0x47, 0x18, 0x60, 0xf2, 0x24, 0xe8, 0xf, 0xee, 0xa6, + 0x81, 0xbe, 0x85, 0x32, 0x6b, 0xd5, 0x17, 0x74, 0x43, 0xf6}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x7b, 0x99, 0x10, 0x56}; + lwmqtt_string_t exp_topic = {4, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xf, 0xee, 0xa6, 0x81, 0xbe, 0x85, 0x32, 0x6b, 0xd5, 0x17, 0x74, 0x43, 0xf6}; + lwmqtt_string_t exp_body = {13, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 16334); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 4); + EXPECT_EQ(msg.payload_len, 13); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 13); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "\239\241 \154( +// \247t\"\246\ENQ\203\252\206\225\196\148\STX\222\"(\255\US}\194\188\172", _pubPktID = 17850, _pubBody = +// "\232#X\SOHr.\129\NAK\155\247c\170\231\193Y\254\ESC\ETX\216\&4\235\253EV@\ETB", _pubProps = [PropTopicAlias +// 11489,PropMaximumPacketSize 27845,PropMaximumPacketSize 26653,PropAssignedClientIdentifier +// "",PropRequestResponseInformation 165,PropResponseInformation "e>'u\164\222",PropTopicAlias +// 19084,PropWillDelayInterval 7069,PropSubscriptionIdentifier 15,PropRetainAvailable 51,PropRequestProblemInformation +// 61,PropServerKeepAlive 30133,PropTopicAliasMaximum 3576,PropPayloadFormatIndicator 207,PropRequestProblemInformation +// 46]} +TEST(Publish5QCTest, Encode21) { + uint8_t pkt[] = {0x3c, 0x6d, 0x0, 0x1b, 0xef, 0xf1, 0x20, 0x9a, 0x28, 0x20, 0xf7, 0x74, 0x22, 0xf6, 0x5, 0xcb, + 0xfc, 0xce, 0xe1, 0xc4, 0x94, 0x2, 0xde, 0x22, 0x28, 0xff, 0x1f, 0x7d, 0xc2, 0xbc, 0xac, 0x45, + 0xba, 0x33, 0x23, 0x2c, 0xe1, 0x27, 0x0, 0x0, 0x6c, 0xc5, 0x27, 0x0, 0x0, 0x68, 0x1d, 0x12, + 0x0, 0x0, 0x19, 0xa5, 0x1a, 0x0, 0x6, 0x65, 0x3e, 0x27, 0x75, 0xa4, 0xde, 0x23, 0x4a, 0x8c, + 0x18, 0x0, 0x0, 0x1b, 0x9d, 0xb, 0xf, 0x25, 0x33, 0x17, 0x3d, 0x13, 0x75, 0xb5, 0x22, 0xd, + 0xf8, 0x1, 0xcf, 0x17, 0x2e, 0xe8, 0x23, 0x58, 0x1, 0x72, 0x2e, 0x81, 0x15, 0x9b, 0xf7, 0x63, + 0xaa, 0xe7, 0xc1, 0x59, 0xfe, 0x1b, 0x3, 0xd8, 0x34, 0xeb, 0xfd, 0x45, 0x56, 0x40, 0x17}; + uint8_t topic_bytes[] = {0xef, 0xf1, 0x20, 0x9a, 0x28, 0x20, 0xf7, 0x74, 0x22, 0xf6, 0x5, 0xcb, 0xfc, 0xce, + 0xe1, 0xc4, 0x94, 0x2, 0xde, 0x22, 0x28, 0xff, 0x1f, 0x7d, 0xc2, 0xbc, 0xac}; + lwmqtt_string_t topic = {27, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0xe8, 0x23, 0x58, 0x1, 0x72, 0x2e, 0x81, 0x15, 0x9b, 0xf7, 0x63, 0xaa, 0xe7, + 0xc1, 0x59, 0xfe, 0x1b, 0x3, 0xd8, 0x34, 0xeb, 0xfd, 0x45, 0x56, 0x40, 0x17}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 26; + + uint8_t bytesprops0[] = {0}; + uint8_t bytesprops1[] = {0x65, 0x3e, 0x27, 0x75, 0xa4, 0xde}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 11489}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 27845}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 26653}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {0, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 165}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {6, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 19084}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 7069}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 15}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 51}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 61}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 30133}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 3576}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 207}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 46}}, + }; + + lwmqtt_properties_t props = {15, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 17850, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "\239\241 \154( +// \247t\"\246\ENQ\203\252\206\225\196\148\STX\222\"(\255\US}\194\188\172", _pubPktID = 17850, _pubBody = +// "\232#X\SOHr.\129\NAK\155\247c\170\231\193Y\254\ESC\ETX\216\&4\235\253EV@\ETB", _pubProps = [PropTopicAlias +// 11489,PropMaximumPacketSize 27845,PropMaximumPacketSize 26653,PropAssignedClientIdentifier +// "",PropRequestResponseInformation 165,PropResponseInformation "e>'u\164\222",PropTopicAlias +// 19084,PropWillDelayInterval 7069,PropSubscriptionIdentifier 15,PropRetainAvailable 51,PropRequestProblemInformation +// 61,PropServerKeepAlive 30133,PropTopicAliasMaximum 3576,PropPayloadFormatIndicator 207,PropRequestProblemInformation +// 46]} +TEST(Publish5QCTest, Decode21) { + uint8_t pkt[] = {0x3c, 0x6d, 0x0, 0x1b, 0xef, 0xf1, 0x20, 0x9a, 0x28, 0x20, 0xf7, 0x74, 0x22, 0xf6, 0x5, 0xcb, + 0xfc, 0xce, 0xe1, 0xc4, 0x94, 0x2, 0xde, 0x22, 0x28, 0xff, 0x1f, 0x7d, 0xc2, 0xbc, 0xac, 0x45, + 0xba, 0x33, 0x23, 0x2c, 0xe1, 0x27, 0x0, 0x0, 0x6c, 0xc5, 0x27, 0x0, 0x0, 0x68, 0x1d, 0x12, + 0x0, 0x0, 0x19, 0xa5, 0x1a, 0x0, 0x6, 0x65, 0x3e, 0x27, 0x75, 0xa4, 0xde, 0x23, 0x4a, 0x8c, + 0x18, 0x0, 0x0, 0x1b, 0x9d, 0xb, 0xf, 0x25, 0x33, 0x17, 0x3d, 0x13, 0x75, 0xb5, 0x22, 0xd, + 0xf8, 0x1, 0xcf, 0x17, 0x2e, 0xe8, 0x23, 0x58, 0x1, 0x72, 0x2e, 0x81, 0x15, 0x9b, 0xf7, 0x63, + 0xaa, 0xe7, 0xc1, 0x59, 0xfe, 0x1b, 0x3, 0xd8, 0x34, 0xeb, 0xfd, 0x45, 0x56, 0x40, 0x17}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xef, 0xf1, 0x20, 0x9a, 0x28, 0x20, 0xf7, 0x74, 0x22, 0xf6, 0x5, 0xcb, 0xfc, 0xce, + 0xe1, 0xc4, 0x94, 0x2, 0xde, 0x22, 0x28, 0xff, 0x1f, 0x7d, 0xc2, 0xbc, 0xac}; + lwmqtt_string_t exp_topic = {27, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xe8, 0x23, 0x58, 0x1, 0x72, 0x2e, 0x81, 0x15, 0x9b, 0xf7, 0x63, 0xaa, 0xe7, + 0xc1, 0x59, 0xfe, 0x1b, 0x3, 0xd8, 0x34, 0xeb, 0xfd, 0x45, 0x56, 0x40, 0x17}; + lwmqtt_string_t exp_body = {26, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 17850); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 27); + EXPECT_EQ(msg.payload_len, 26); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 26); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "\161\229m\129\&2\222w}\252\146\169(\STXu\137Z6\133", _pubPktID = 7546, _pubBody = +// "^\ETX\228\176\224]\220i\211(<\144", _pubProps = [PropRequestResponseInformation 170,PropAuthenticationData +// "",PropWildcardSubscriptionAvailable 121,PropReceiveMaximum 31584,PropCorrelationData +// "\144\220\223\179\203\210V\247\ENQA\EM_\DC1\135-\237>\164\f\143\133\ESCU",PropMessageExpiryInterval +// 2283,PropWildcardSubscriptionAvailable 242,PropTopicAlias 20591]} +TEST(Publish5QCTest, Encode22) { + uint8_t pkt[] = {0x34, 0x51, 0x0, 0x12, 0xa1, 0xe5, 0x6d, 0x81, 0x32, 0xde, 0x77, 0x7d, 0xfc, 0x92, 0xa9, 0x28, 0x2, + 0x75, 0x89, 0x5a, 0x36, 0x85, 0x1d, 0x7a, 0x2e, 0x19, 0xaa, 0x16, 0x0, 0x0, 0x28, 0x79, 0x21, 0x7b, + 0x60, 0x9, 0x0, 0x17, 0x90, 0xdc, 0xdf, 0xb3, 0xcb, 0xd2, 0x56, 0xf7, 0x5, 0x41, 0x19, 0x5f, 0x11, + 0x87, 0x2d, 0xed, 0x3e, 0xa4, 0xc, 0x8f, 0x85, 0x1b, 0x55, 0x2, 0x0, 0x0, 0x8, 0xeb, 0x28, 0xf2, + 0x23, 0x50, 0x6f, 0x5e, 0x3, 0xe4, 0xb0, 0xe0, 0x5d, 0xdc, 0x69, 0xd3, 0x28, 0x3c, 0x90}; + uint8_t topic_bytes[] = {0xa1, 0xe5, 0x6d, 0x81, 0x32, 0xde, 0x77, 0x7d, 0xfc, + 0x92, 0xa9, 0x28, 0x2, 0x75, 0x89, 0x5a, 0x36, 0x85}; + lwmqtt_string_t topic = {18, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0x5e, 0x3, 0xe4, 0xb0, 0xe0, 0x5d, 0xdc, 0x69, 0xd3, 0x28, 0x3c, 0x90}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 12; + + uint8_t bytesprops0[] = {0}; + uint8_t bytesprops1[] = {0x90, 0xdc, 0xdf, 0xb3, 0xcb, 0xd2, 0x56, 0xf7, 0x5, 0x41, 0x19, 0x5f, + 0x11, 0x87, 0x2d, 0xed, 0x3e, 0xa4, 0xc, 0x8f, 0x85, 0x1b, 0x55}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 170}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {0, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 121}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 31584}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {23, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 2283}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 242}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 20591}}, + }; + + lwmqtt_properties_t props = {8, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, false, 7546, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = +// "\161\229m\129\&2\222w}\252\146\169(\STXu\137Z6\133", _pubPktID = 7546, _pubBody = +// "^\ETX\228\176\224]\220i\211(<\144", _pubProps = [PropRequestResponseInformation 170,PropAuthenticationData +// "",PropWildcardSubscriptionAvailable 121,PropReceiveMaximum 31584,PropCorrelationData +// "\144\220\223\179\203\210V\247\ENQA\EM_\DC1\135-\237>\164\f\143\133\ESCU",PropMessageExpiryInterval +// 2283,PropWildcardSubscriptionAvailable 242,PropTopicAlias 20591]} +TEST(Publish5QCTest, Decode22) { + uint8_t pkt[] = {0x34, 0x51, 0x0, 0x12, 0xa1, 0xe5, 0x6d, 0x81, 0x32, 0xde, 0x77, 0x7d, 0xfc, 0x92, 0xa9, 0x28, 0x2, + 0x75, 0x89, 0x5a, 0x36, 0x85, 0x1d, 0x7a, 0x2e, 0x19, 0xaa, 0x16, 0x0, 0x0, 0x28, 0x79, 0x21, 0x7b, + 0x60, 0x9, 0x0, 0x17, 0x90, 0xdc, 0xdf, 0xb3, 0xcb, 0xd2, 0x56, 0xf7, 0x5, 0x41, 0x19, 0x5f, 0x11, + 0x87, 0x2d, 0xed, 0x3e, 0xa4, 0xc, 0x8f, 0x85, 0x1b, 0x55, 0x2, 0x0, 0x0, 0x8, 0xeb, 0x28, 0xf2, + 0x23, 0x50, 0x6f, 0x5e, 0x3, 0xe4, 0xb0, 0xe0, 0x5d, 0xdc, 0x69, 0xd3, 0x28, 0x3c, 0x90}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xa1, 0xe5, 0x6d, 0x81, 0x32, 0xde, 0x77, 0x7d, 0xfc, + 0x92, 0xa9, 0x28, 0x2, 0x75, 0x89, 0x5a, 0x36, 0x85}; + lwmqtt_string_t exp_topic = {18, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x5e, 0x3, 0xe4, 0xb0, 0xe0, 0x5d, 0xdc, 0x69, 0xd3, 0x28, 0x3c, 0x90}; + lwmqtt_string_t exp_body = {12, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 7546); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 18); + EXPECT_EQ(msg.payload_len, 12); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 12); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "zd\230 jdq?\198\154\202x8", +// _pubPktID = 32533, _pubBody = "\255\DC4\132\246=", _pubProps = [PropMaximumPacketSize 15136,PropAuthenticationData +// "\131\&7\153\202F\187\143\DLE\DELp\CAN\\ed\154JK\137\184\192\137\190Z\161\ENQ\181\164",PropAssignedClientIdentifier +// "w\150%\206\129\164\131\203uN+r\206I\SIJr\145\242\247",PropUserProperty "\129i1uD#\224^f\RS\SYN\177Ks>N" +// "@\ETX\DEL\156G\b\128\173\172\&2#",PropMaximumQoS 54,PropAuthenticationMethod +// "\ETX\206\DLE\177Z\255D|\170g\250\133k\254\US\193B\214Jdp9I{L'\ENQ\FS<",PropSessionExpiryInterval +// 31365,PropServerKeepAlive 25016,PropSubscriptionIdentifier 19,PropTopicAlias 18475,PropAuthenticationMethod +// "\f\217\155,\149\231\148\SOH$.\ETX\154g\228mf~",PropServerReference "5\216f\DEL",PropPayloadFormatIndicator +// 225,PropContentType "\179fA\243\179\219\SO\213,\197\189z\201\160\195\163\248n\174\255\234\179\139_1\207{\130x\248"]} +TEST(Publish5QCTest, Encode23) { + uint8_t pkt[] = { + 0x34, 0xdf, 0x1, 0x0, 0xd, 0x7a, 0x64, 0xe6, 0x20, 0x6a, 0x64, 0x71, 0x3f, 0xc6, 0x9a, 0xca, 0x78, 0x38, 0x7f, + 0x15, 0xc7, 0x1, 0x27, 0x0, 0x0, 0x3b, 0x20, 0x16, 0x0, 0x1b, 0x83, 0x37, 0x99, 0xca, 0x46, 0xbb, 0x8f, 0x10, + 0x7f, 0x70, 0x18, 0x5c, 0x65, 0x64, 0x9a, 0x4a, 0x4b, 0x89, 0xb8, 0xc0, 0x89, 0xbe, 0x5a, 0xa1, 0x5, 0xb5, 0xa4, + 0x12, 0x0, 0x14, 0x77, 0x96, 0x25, 0xce, 0x81, 0xa4, 0x83, 0xcb, 0x75, 0x4e, 0x2b, 0x72, 0xce, 0x49, 0xf, 0x4a, + 0x72, 0x91, 0xf2, 0xf7, 0x26, 0x0, 0x10, 0x81, 0x69, 0x31, 0x75, 0x44, 0x23, 0xe0, 0x5e, 0x66, 0x1e, 0x16, 0xb1, + 0x4b, 0x73, 0x3e, 0x4e, 0x0, 0xb, 0x40, 0x3, 0x7f, 0x9c, 0x47, 0x8, 0x80, 0xad, 0xac, 0x32, 0x23, 0x24, 0x36, + 0x15, 0x0, 0x1d, 0x3, 0xce, 0x10, 0xb1, 0x5a, 0xff, 0x44, 0x7c, 0xaa, 0x67, 0xfa, 0x85, 0x6b, 0xfe, 0x1f, 0xc1, + 0x42, 0xd6, 0x4a, 0x64, 0x70, 0x39, 0x49, 0x7b, 0x4c, 0x27, 0x5, 0x1c, 0x3c, 0x11, 0x0, 0x0, 0x7a, 0x85, 0x13, + 0x61, 0xb8, 0xb, 0x13, 0x23, 0x48, 0x2b, 0x15, 0x0, 0x11, 0xc, 0xd9, 0x9b, 0x2c, 0x95, 0xe7, 0x94, 0x1, 0x24, + 0x2e, 0x3, 0x9a, 0x67, 0xe4, 0x6d, 0x66, 0x7e, 0x1c, 0x0, 0x4, 0x35, 0xd8, 0x66, 0x7f, 0x1, 0xe1, 0x3, 0x0, + 0x1e, 0xb3, 0x66, 0x41, 0xf3, 0xb3, 0xdb, 0xe, 0xd5, 0x2c, 0xc5, 0xbd, 0x7a, 0xc9, 0xa0, 0xc3, 0xa3, 0xf8, 0x6e, + 0xae, 0xff, 0xea, 0xb3, 0x8b, 0x5f, 0x31, 0xcf, 0x7b, 0x82, 0x78, 0xf8, 0xff, 0x14, 0x84, 0xf6, 0x3d}; + uint8_t topic_bytes[] = {0x7a, 0x64, 0xe6, 0x20, 0x6a, 0x64, 0x71, 0x3f, 0xc6, 0x9a, 0xca, 0x78, 0x38}; + lwmqtt_string_t topic = {13, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS2; + msg.retained = false; + uint8_t msg_bytes[] = {0xff, 0x14, 0x84, 0xf6, 0x3d}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 5; + + uint8_t bytesprops0[] = {0x83, 0x37, 0x99, 0xca, 0x46, 0xbb, 0x8f, 0x10, 0x7f, 0x70, 0x18, 0x5c, 0x65, 0x64, + 0x9a, 0x4a, 0x4b, 0x89, 0xb8, 0xc0, 0x89, 0xbe, 0x5a, 0xa1, 0x5, 0xb5, 0xa4}; + uint8_t bytesprops1[] = {0x77, 0x96, 0x25, 0xce, 0x81, 0xa4, 0x83, 0xcb, 0x75, 0x4e, + 0x2b, 0x72, 0xce, 0x49, 0xf, 0x4a, 0x72, 0x91, 0xf2, 0xf7}; + uint8_t bytesprops3[] = {0x40, 0x3, 0x7f, 0x9c, 0x47, 0x8, 0x80, 0xad, 0xac, 0x32, 0x23}; + uint8_t bytesprops2[] = {0x81, 0x69, 0x31, 0x75, 0x44, 0x23, 0xe0, 0x5e, + 0x66, 0x1e, 0x16, 0xb1, 0x4b, 0x73, 0x3e, 0x4e}; + uint8_t bytesprops4[] = {0x3, 0xce, 0x10, 0xb1, 0x5a, 0xff, 0x44, 0x7c, 0xaa, 0x67, 0xfa, 0x85, 0x6b, 0xfe, 0x1f, + 0xc1, 0x42, 0xd6, 0x4a, 0x64, 0x70, 0x39, 0x49, 0x7b, 0x4c, 0x27, 0x5, 0x1c, 0x3c}; + uint8_t bytesprops5[] = {0xc, 0xd9, 0x9b, 0x2c, 0x95, 0xe7, 0x94, 0x1, 0x24, + 0x2e, 0x3, 0x9a, 0x67, 0xe4, 0x6d, 0x66, 0x7e}; + uint8_t bytesprops6[] = {0x35, 0xd8, 0x66, 0x7f}; + uint8_t bytesprops7[] = {0xb3, 0x66, 0x41, 0xf3, 0xb3, 0xdb, 0xe, 0xd5, 0x2c, 0xc5, 0xbd, 0x7a, 0xc9, 0xa0, 0xc3, + 0xa3, 0xf8, 0x6e, 0xae, 0xff, 0xea, 0xb3, 0x8b, 0x5f, 0x31, 0xcf, 0x7b, 0x82, 0x78, 0xf8}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 15136}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {27, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {20, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {16, (char*)&bytesprops2}, .v = {11, (char*)&bytesprops3}}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 54}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {29, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 31365}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 25016}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 19}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 18475}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {17, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {4, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 225}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {30, (char*)&bytesprops7}}}, + }; + + lwmqtt_properties_t props = {14, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, false, 32533, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS2, _pubRetain = False, _pubTopic = "zd\230 jdq?\198\154\202x8", +// _pubPktID = 32533, _pubBody = "\255\DC4\132\246=", _pubProps = [PropMaximumPacketSize 15136,PropAuthenticationData +// "\131\&7\153\202F\187\143\DLE\DELp\CAN\\ed\154JK\137\184\192\137\190Z\161\ENQ\181\164",PropAssignedClientIdentifier +// "w\150%\206\129\164\131\203uN+r\206I\SIJr\145\242\247",PropUserProperty "\129i1uD#\224^f\RS\SYN\177Ks>N" +// "@\ETX\DEL\156G\b\128\173\172\&2#",PropMaximumQoS 54,PropAuthenticationMethod +// "\ETX\206\DLE\177Z\255D|\170g\250\133k\254\US\193B\214Jdp9I{L'\ENQ\FS<",PropSessionExpiryInterval +// 31365,PropServerKeepAlive 25016,PropSubscriptionIdentifier 19,PropTopicAlias 18475,PropAuthenticationMethod +// "\f\217\155,\149\231\148\SOH$.\ETX\154g\228mf~",PropServerReference "5\216f\DEL",PropPayloadFormatIndicator +// 225,PropContentType "\179fA\243\179\219\SO\213,\197\189z\201\160\195\163\248n\174\255\234\179\139_1\207{\130x\248"]} +TEST(Publish5QCTest, Decode23) { + uint8_t pkt[] = { + 0x34, 0xdf, 0x1, 0x0, 0xd, 0x7a, 0x64, 0xe6, 0x20, 0x6a, 0x64, 0x71, 0x3f, 0xc6, 0x9a, 0xca, 0x78, 0x38, 0x7f, + 0x15, 0xc7, 0x1, 0x27, 0x0, 0x0, 0x3b, 0x20, 0x16, 0x0, 0x1b, 0x83, 0x37, 0x99, 0xca, 0x46, 0xbb, 0x8f, 0x10, + 0x7f, 0x70, 0x18, 0x5c, 0x65, 0x64, 0x9a, 0x4a, 0x4b, 0x89, 0xb8, 0xc0, 0x89, 0xbe, 0x5a, 0xa1, 0x5, 0xb5, 0xa4, + 0x12, 0x0, 0x14, 0x77, 0x96, 0x25, 0xce, 0x81, 0xa4, 0x83, 0xcb, 0x75, 0x4e, 0x2b, 0x72, 0xce, 0x49, 0xf, 0x4a, + 0x72, 0x91, 0xf2, 0xf7, 0x26, 0x0, 0x10, 0x81, 0x69, 0x31, 0x75, 0x44, 0x23, 0xe0, 0x5e, 0x66, 0x1e, 0x16, 0xb1, + 0x4b, 0x73, 0x3e, 0x4e, 0x0, 0xb, 0x40, 0x3, 0x7f, 0x9c, 0x47, 0x8, 0x80, 0xad, 0xac, 0x32, 0x23, 0x24, 0x36, + 0x15, 0x0, 0x1d, 0x3, 0xce, 0x10, 0xb1, 0x5a, 0xff, 0x44, 0x7c, 0xaa, 0x67, 0xfa, 0x85, 0x6b, 0xfe, 0x1f, 0xc1, + 0x42, 0xd6, 0x4a, 0x64, 0x70, 0x39, 0x49, 0x7b, 0x4c, 0x27, 0x5, 0x1c, 0x3c, 0x11, 0x0, 0x0, 0x7a, 0x85, 0x13, + 0x61, 0xb8, 0xb, 0x13, 0x23, 0x48, 0x2b, 0x15, 0x0, 0x11, 0xc, 0xd9, 0x9b, 0x2c, 0x95, 0xe7, 0x94, 0x1, 0x24, + 0x2e, 0x3, 0x9a, 0x67, 0xe4, 0x6d, 0x66, 0x7e, 0x1c, 0x0, 0x4, 0x35, 0xd8, 0x66, 0x7f, 0x1, 0xe1, 0x3, 0x0, + 0x1e, 0xb3, 0x66, 0x41, 0xf3, 0xb3, 0xdb, 0xe, 0xd5, 0x2c, 0xc5, 0xbd, 0x7a, 0xc9, 0xa0, 0xc3, 0xa3, 0xf8, 0x6e, + 0xae, 0xff, 0xea, 0xb3, 0x8b, 0x5f, 0x31, 0xcf, 0x7b, 0x82, 0x78, 0xf8, 0xff, 0x14, 0x84, 0xf6, 0x3d}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x7a, 0x64, 0xe6, 0x20, 0x6a, 0x64, 0x71, 0x3f, 0xc6, 0x9a, 0xca, 0x78, 0x38}; + lwmqtt_string_t exp_topic = {13, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xff, 0x14, 0x84, 0xf6, 0x3d}; + lwmqtt_string_t exp_body = {5, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS2); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 32533); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 13); + EXPECT_EQ(msg.payload_len, 5); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 5); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS0, _pubRetain = True, _pubTopic = +// "\ETB\147^4}\135\220\179>\250\156\DELi2\SOH\236\193\164n\239\157\189\229t#`4", _pubPktID = 0, _pubBody = +// "\130\204\173\174\157}\164rT\146\220w\DC1H4\164\DLE\255{", _pubProps = [PropSubscriptionIdentifier +// 28,PropRequestProblemInformation 33,PropResponseInformation +// "*\237\238\SYN\179\143\197ci\b\129\254\t\212\249es\201\231[\RSE\215]",PropWildcardSubscriptionAvailable +// 173,PropWildcardSubscriptionAvailable 175,PropSessionExpiryInterval 14786,PropContentType +// "\245u\136R\187y\200\149\138\252:p\151\n\\\234'\132\f\SI\NAK\224b2\208",PropUserProperty +// "\139\182G\198\212V\157\182\230\203d\145\254" +// "q\246\175\&4r\173\ACK7m@\n\210\134\134\SOH\150\153;<\144\NAK\212\frX\174\RSJ\US",PropAssignedClientIdentifier +// "\224\ESC\t\254;n\165w;^\SOw",PropTopicAlias 5234,PropServerKeepAlive 13865,PropCorrelationData +// "\SO\n",PropTopicAlias 23073,PropMaximumPacketSize 19089,PropAuthenticationData +// "\250\156\DELi2\SOH\236\193\164n\239\157\189\229t#`4", _pubPktID = 0, _pubBody = +// "\130\204\173\174\157}\164rT\146\220w\DC1H4\164\DLE\255{", _pubProps = [PropSubscriptionIdentifier +// 28,PropRequestProblemInformation 33,PropResponseInformation +// "*\237\238\SYN\179\143\197ci\b\129\254\t\212\249es\201\231[\RSE\215]",PropWildcardSubscriptionAvailable +// 173,PropWildcardSubscriptionAvailable 175,PropSessionExpiryInterval 14786,PropContentType +// "\245u\136R\187y\200\149\138\252:p\151\n\\\234'\132\f\SI\NAK\224b2\208",PropUserProperty +// "\139\182G\198\212V\157\182\230\203d\145\254" +// "q\246\175\&4r\173\ACK7m@\n\210\134\134\SOH\150\153;<\144\NAK\212\frX\174\RSJ\US",PropAssignedClientIdentifier +// "\224\ESC\t\254;n\165w;^\SOw",PropTopicAlias 5234,PropServerKeepAlive 13865,PropCorrelationData +// "\SO\n",PropTopicAlias 23073,PropMaximumPacketSize 19089,PropAuthenticationData +// "(topic.data), 27); + EXPECT_EQ(msg.payload_len, 19); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 19); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "q:@l\229vEU\235iQ\v", _pubPktID = +// 23637, _pubBody = "\169\252\159\196(\144\135\181\129*7\EOT&B\216\183\244\DC3\129\142\224\229", _pubProps = +// [PropTopicAliasMaximum 21307,PropResponseInformation "\DC3\184\&7\"[\211\238r\163M\tO\183\USU",PropMaximumQoS +// 95,PropWildcardSubscriptionAvailable 148,PropRequestResponseInformation 162,PropWildcardSubscriptionAvailable +// 3,PropAssignedClientIdentifier "%\219\SO4\146l\EM",PropSubscriptionIdentifierAvailable 86]} +TEST(Publish5QCTest, Encode25) { + uint8_t pkt[] = {0x33, 0x50, 0x0, 0xc, 0x71, 0x3a, 0x40, 0x6c, 0xe5, 0x76, 0x45, 0x55, 0xeb, 0x69, 0x51, 0xb, 0x5c, + 0x55, 0x29, 0x22, 0x53, 0x3b, 0x1a, 0x0, 0xf, 0x13, 0xb8, 0x37, 0x22, 0x5b, 0xd3, 0xee, 0x72, 0xa3, + 0x4d, 0x9, 0x4f, 0xb7, 0x1f, 0x55, 0x24, 0x5f, 0x28, 0x94, 0x19, 0xa2, 0x28, 0x3, 0x12, 0x0, 0x7, + 0x25, 0xdb, 0xe, 0x34, 0x92, 0x6c, 0x19, 0x29, 0x56, 0xa9, 0xfc, 0x9f, 0xc4, 0x28, 0x90, 0x87, 0xb5, + 0x81, 0x2a, 0x37, 0x4, 0x26, 0x42, 0xd8, 0xb7, 0xf4, 0x13, 0x81, 0x8e, 0xe0, 0xe5}; + uint8_t topic_bytes[] = {0x71, 0x3a, 0x40, 0x6c, 0xe5, 0x76, 0x45, 0x55, 0xeb, 0x69, 0x51, 0xb}; + lwmqtt_string_t topic = {12, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0xa9, 0xfc, 0x9f, 0xc4, 0x28, 0x90, 0x87, 0xb5, 0x81, 0x2a, 0x37, + 0x4, 0x26, 0x42, 0xd8, 0xb7, 0xf4, 0x13, 0x81, 0x8e, 0xe0, 0xe5}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 22; + + uint8_t bytesprops0[] = {0x13, 0xb8, 0x37, 0x22, 0x5b, 0xd3, 0xee, 0x72, 0xa3, 0x4d, 0x9, 0x4f, 0xb7, 0x1f, 0x55}; + uint8_t bytesprops1[] = {0x25, 0xdb, 0xe, 0x34, 0x92, 0x6c, 0x19}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 21307}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {15, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 95}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 148}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 162}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 3}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {7, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 86}}, + }; + + lwmqtt_properties_t props = {8, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, false, 23637, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = True, _pubTopic = "q:@l\229vEU\235iQ\v", _pubPktID = +// 23637, _pubBody = "\169\252\159\196(\144\135\181\129*7\EOT&B\216\183\244\DC3\129\142\224\229", _pubProps = +// [PropTopicAliasMaximum 21307,PropResponseInformation "\DC3\184\&7\"[\211\238r\163M\tO\183\USU",PropMaximumQoS +// 95,PropWildcardSubscriptionAvailable 148,PropRequestResponseInformation 162,PropWildcardSubscriptionAvailable +// 3,PropAssignedClientIdentifier "%\219\SO4\146l\EM",PropSubscriptionIdentifierAvailable 86]} +TEST(Publish5QCTest, Decode25) { + uint8_t pkt[] = {0x33, 0x50, 0x0, 0xc, 0x71, 0x3a, 0x40, 0x6c, 0xe5, 0x76, 0x45, 0x55, 0xeb, 0x69, 0x51, 0xb, 0x5c, + 0x55, 0x29, 0x22, 0x53, 0x3b, 0x1a, 0x0, 0xf, 0x13, 0xb8, 0x37, 0x22, 0x5b, 0xd3, 0xee, 0x72, 0xa3, + 0x4d, 0x9, 0x4f, 0xb7, 0x1f, 0x55, 0x24, 0x5f, 0x28, 0x94, 0x19, 0xa2, 0x28, 0x3, 0x12, 0x0, 0x7, + 0x25, 0xdb, 0xe, 0x34, 0x92, 0x6c, 0x19, 0x29, 0x56, 0xa9, 0xfc, 0x9f, 0xc4, 0x28, 0x90, 0x87, 0xb5, + 0x81, 0x2a, 0x37, 0x4, 0x26, 0x42, 0xd8, 0xb7, 0xf4, 0x13, 0x81, 0x8e, 0xe0, 0xe5}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x71, 0x3a, 0x40, 0x6c, 0xe5, 0x76, 0x45, 0x55, 0xeb, 0x69, 0x51, 0xb}; + lwmqtt_string_t exp_topic = {12, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xa9, 0xfc, 0x9f, 0xc4, 0x28, 0x90, 0x87, 0xb5, 0x81, 0x2a, 0x37, + 0x4, 0x26, 0x42, 0xd8, 0xb7, 0xf4, 0x13, 0x81, 0x8e, 0xe0, 0xe5}; + lwmqtt_string_t exp_body = {22, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, false); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 23637); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 12); + EXPECT_EQ(msg.payload_len, 22); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 22); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "n#\187\187\173\198I,k\145\183\237\142\194", _pubPktID = 8993, _pubBody = "\147{\192\230\144\DC3\130j\217\194h +// E\159\201\161s\154\199\201<\227", _pubProps = [PropContentType +// "gDe<\244\211\249\144\FS\186\&4.)J|\254\137\STX*\249I",PropResponseTopic +// "\148\ACKL\136}+_\197\134\243`\200F\142\234xP{\225\181\SYNc\143*\DC3",PropReceiveMaximum 24406,PropWillDelayInterval +// 5554,PropResponseTopic "\163\175O\136\235\209\156\178?\NUL\150\ACK+xSp\241",PropReceiveMaximum 8798,PropTopicAlias +// 7024,PropWillDelayInterval 19616,PropRequestProblemInformation 23,PropMessageExpiryInterval +// 32067,PropAuthenticationData "\182z\151\212\192 +// 3\204ci\184\156\n\245\156j\142\162\129\162\DC1\135\154\253\STX]\129\170\247",PropResponseInformation +// "\156,6\197",PropServerReference +// "\246,\195F\168*\184f\248\239\153o8\215\148\241\CAN\168\197]n\181R",PropRequestResponseInformation +// 116,PropPayloadFormatIndicator 245,PropAuthenticationMethod +// "\131?\241\ENQzCk\187\132(zBY\190\175\210!\230?x\166>\186"]} +TEST(Publish5QCTest, Encode26) { + uint8_t pkt[] = { + 0x3b, 0xeb, 0x1, 0x0, 0xe, 0x6e, 0x23, 0xbb, 0xbb, 0xad, 0xc6, 0x49, 0x2c, 0x6b, 0x91, 0xb7, 0xed, 0x8e, 0xc2, + 0x23, 0x21, 0xc1, 0x1, 0x3, 0x0, 0x15, 0x67, 0x44, 0x65, 0x3c, 0xf4, 0xd3, 0xf9, 0x90, 0x1c, 0xba, 0x34, 0x2e, + 0x29, 0x4a, 0x7c, 0xfe, 0x89, 0x2, 0x2a, 0xf9, 0x49, 0x8, 0x0, 0x19, 0x94, 0x6, 0x4c, 0x88, 0x7d, 0x2b, 0x5f, + 0xc5, 0x86, 0xf3, 0x60, 0xc8, 0x46, 0x8e, 0xea, 0x78, 0x50, 0x7b, 0xe1, 0xb5, 0x16, 0x63, 0x8f, 0x2a, 0x13, 0x21, + 0x5f, 0x56, 0x18, 0x0, 0x0, 0x15, 0xb2, 0x8, 0x0, 0x11, 0xa3, 0xaf, 0x4f, 0x88, 0xeb, 0xd1, 0x9c, 0xb2, 0x3f, + 0x0, 0x96, 0x6, 0x2b, 0x78, 0x53, 0x70, 0xf1, 0x21, 0x22, 0x5e, 0x23, 0x1b, 0x70, 0x18, 0x0, 0x0, 0x4c, 0xa0, + 0x17, 0x17, 0x2, 0x0, 0x0, 0x7d, 0x43, 0x16, 0x0, 0x1d, 0xb6, 0x7a, 0x97, 0xd4, 0xc0, 0x20, 0x33, 0xcc, 0x63, + 0x69, 0xb8, 0x9c, 0xa, 0xf5, 0x9c, 0x6a, 0x8e, 0xa2, 0x81, 0xa2, 0x11, 0x87, 0x9a, 0xfd, 0x2, 0x5d, 0x81, 0xaa, + 0xf7, 0x1a, 0x0, 0x4, 0x9c, 0x2c, 0x36, 0xc5, 0x1c, 0x0, 0x17, 0xf6, 0x2c, 0xc3, 0x46, 0xa8, 0x2a, 0xb8, 0x66, + 0xf8, 0xef, 0x99, 0x6f, 0x38, 0xd7, 0x94, 0xf1, 0x18, 0xa8, 0xc5, 0x5d, 0x6e, 0xb5, 0x52, 0x19, 0x74, 0x1, 0xf5, + 0x15, 0x0, 0x17, 0x83, 0x3f, 0xf1, 0x5, 0x7a, 0x43, 0x6b, 0xbb, 0x84, 0x28, 0x7a, 0x42, 0x59, 0xbe, 0xaf, 0xd2, + 0x21, 0xe6, 0x3f, 0x78, 0xa6, 0x3e, 0xba, 0x93, 0x7b, 0xc0, 0xe6, 0x90, 0x13, 0x82, 0x6a, 0xd9, 0xc2, 0x68, 0x20, + 0x45, 0x9f, 0xc9, 0xa1, 0x73, 0x9a, 0xc7, 0xc9, 0x3c, 0xe3}; + uint8_t topic_bytes[] = {0x6e, 0x23, 0xbb, 0xbb, 0xad, 0xc6, 0x49, 0x2c, 0x6b, 0x91, 0xb7, 0xed, 0x8e, 0xc2}; + lwmqtt_string_t topic = {14, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0x93, 0x7b, 0xc0, 0xe6, 0x90, 0x13, 0x82, 0x6a, 0xd9, 0xc2, 0x68, + 0x20, 0x45, 0x9f, 0xc9, 0xa1, 0x73, 0x9a, 0xc7, 0xc9, 0x3c, 0xe3}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 22; + + uint8_t bytesprops0[] = {0x67, 0x44, 0x65, 0x3c, 0xf4, 0xd3, 0xf9, 0x90, 0x1c, 0xba, 0x34, + 0x2e, 0x29, 0x4a, 0x7c, 0xfe, 0x89, 0x2, 0x2a, 0xf9, 0x49}; + uint8_t bytesprops1[] = {0x94, 0x6, 0x4c, 0x88, 0x7d, 0x2b, 0x5f, 0xc5, 0x86, 0xf3, 0x60, 0xc8, 0x46, + 0x8e, 0xea, 0x78, 0x50, 0x7b, 0xe1, 0xb5, 0x16, 0x63, 0x8f, 0x2a, 0x13}; + uint8_t bytesprops2[] = {0xa3, 0xaf, 0x4f, 0x88, 0xeb, 0xd1, 0x9c, 0xb2, 0x3f, + 0x0, 0x96, 0x6, 0x2b, 0x78, 0x53, 0x70, 0xf1}; + uint8_t bytesprops3[] = {0xb6, 0x7a, 0x97, 0xd4, 0xc0, 0x20, 0x33, 0xcc, 0x63, 0x69, 0xb8, 0x9c, 0xa, 0xf5, 0x9c, + 0x6a, 0x8e, 0xa2, 0x81, 0xa2, 0x11, 0x87, 0x9a, 0xfd, 0x2, 0x5d, 0x81, 0xaa, 0xf7}; + uint8_t bytesprops4[] = {0x9c, 0x2c, 0x36, 0xc5}; + uint8_t bytesprops5[] = {0xf6, 0x2c, 0xc3, 0x46, 0xa8, 0x2a, 0xb8, 0x66, 0xf8, 0xef, 0x99, 0x6f, + 0x38, 0xd7, 0x94, 0xf1, 0x18, 0xa8, 0xc5, 0x5d, 0x6e, 0xb5, 0x52}; + uint8_t bytesprops6[] = {0x83, 0x3f, 0xf1, 0x5, 0x7a, 0x43, 0x6b, 0xbb, 0x84, 0x28, 0x7a, 0x42, + 0x59, 0xbe, 0xaf, 0xd2, 0x21, 0xe6, 0x3f, 0x78, 0xa6, 0x3e, 0xba}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)3, .value = {.str = {21, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {25, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 24406}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 5554}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {17, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 8798}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 7024}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 19616}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 23}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 32067}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {29, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {4, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {23, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 116}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 245}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {23, (char*)&bytesprops6}}}, + }; + + lwmqtt_properties_t props = {16, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 8993, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "n#\187\187\173\198I,k\145\183\237\142\194", _pubPktID = 8993, _pubBody = "\147{\192\230\144\DC3\130j\217\194h +// E\159\201\161s\154\199\201<\227", _pubProps = [PropContentType +// "gDe<\244\211\249\144\FS\186\&4.)J|\254\137\STX*\249I",PropResponseTopic +// "\148\ACKL\136}+_\197\134\243`\200F\142\234xP{\225\181\SYNc\143*\DC3",PropReceiveMaximum 24406,PropWillDelayInterval +// 5554,PropResponseTopic "\163\175O\136\235\209\156\178?\NUL\150\ACK+xSp\241",PropReceiveMaximum 8798,PropTopicAlias +// 7024,PropWillDelayInterval 19616,PropRequestProblemInformation 23,PropMessageExpiryInterval +// 32067,PropAuthenticationData "\182z\151\212\192 +// 3\204ci\184\156\n\245\156j\142\162\129\162\DC1\135\154\253\STX]\129\170\247",PropResponseInformation +// "\156,6\197",PropServerReference +// "\246,\195F\168*\184f\248\239\153o8\215\148\241\CAN\168\197]n\181R",PropRequestResponseInformation +// 116,PropPayloadFormatIndicator 245,PropAuthenticationMethod +// "\131?\241\ENQzCk\187\132(zBY\190\175\210!\230?x\166>\186"]} +TEST(Publish5QCTest, Decode26) { + uint8_t pkt[] = { + 0x3b, 0xeb, 0x1, 0x0, 0xe, 0x6e, 0x23, 0xbb, 0xbb, 0xad, 0xc6, 0x49, 0x2c, 0x6b, 0x91, 0xb7, 0xed, 0x8e, 0xc2, + 0x23, 0x21, 0xc1, 0x1, 0x3, 0x0, 0x15, 0x67, 0x44, 0x65, 0x3c, 0xf4, 0xd3, 0xf9, 0x90, 0x1c, 0xba, 0x34, 0x2e, + 0x29, 0x4a, 0x7c, 0xfe, 0x89, 0x2, 0x2a, 0xf9, 0x49, 0x8, 0x0, 0x19, 0x94, 0x6, 0x4c, 0x88, 0x7d, 0x2b, 0x5f, + 0xc5, 0x86, 0xf3, 0x60, 0xc8, 0x46, 0x8e, 0xea, 0x78, 0x50, 0x7b, 0xe1, 0xb5, 0x16, 0x63, 0x8f, 0x2a, 0x13, 0x21, + 0x5f, 0x56, 0x18, 0x0, 0x0, 0x15, 0xb2, 0x8, 0x0, 0x11, 0xa3, 0xaf, 0x4f, 0x88, 0xeb, 0xd1, 0x9c, 0xb2, 0x3f, + 0x0, 0x96, 0x6, 0x2b, 0x78, 0x53, 0x70, 0xf1, 0x21, 0x22, 0x5e, 0x23, 0x1b, 0x70, 0x18, 0x0, 0x0, 0x4c, 0xa0, + 0x17, 0x17, 0x2, 0x0, 0x0, 0x7d, 0x43, 0x16, 0x0, 0x1d, 0xb6, 0x7a, 0x97, 0xd4, 0xc0, 0x20, 0x33, 0xcc, 0x63, + 0x69, 0xb8, 0x9c, 0xa, 0xf5, 0x9c, 0x6a, 0x8e, 0xa2, 0x81, 0xa2, 0x11, 0x87, 0x9a, 0xfd, 0x2, 0x5d, 0x81, 0xaa, + 0xf7, 0x1a, 0x0, 0x4, 0x9c, 0x2c, 0x36, 0xc5, 0x1c, 0x0, 0x17, 0xf6, 0x2c, 0xc3, 0x46, 0xa8, 0x2a, 0xb8, 0x66, + 0xf8, 0xef, 0x99, 0x6f, 0x38, 0xd7, 0x94, 0xf1, 0x18, 0xa8, 0xc5, 0x5d, 0x6e, 0xb5, 0x52, 0x19, 0x74, 0x1, 0xf5, + 0x15, 0x0, 0x17, 0x83, 0x3f, 0xf1, 0x5, 0x7a, 0x43, 0x6b, 0xbb, 0x84, 0x28, 0x7a, 0x42, 0x59, 0xbe, 0xaf, 0xd2, + 0x21, 0xe6, 0x3f, 0x78, 0xa6, 0x3e, 0xba, 0x93, 0x7b, 0xc0, 0xe6, 0x90, 0x13, 0x82, 0x6a, 0xd9, 0xc2, 0x68, 0x20, + 0x45, 0x9f, 0xc9, 0xa1, 0x73, 0x9a, 0xc7, 0xc9, 0x3c, 0xe3}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x6e, 0x23, 0xbb, 0xbb, 0xad, 0xc6, 0x49, 0x2c, 0x6b, 0x91, 0xb7, 0xed, 0x8e, 0xc2}; + lwmqtt_string_t exp_topic = {14, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x93, 0x7b, 0xc0, 0xe6, 0x90, 0x13, 0x82, 0x6a, 0xd9, 0xc2, 0x68, + 0x20, 0x45, 0x9f, 0xc9, 0xa1, 0x73, 0x9a, 0xc7, 0xc9, 0x3c, 0xe3}; + lwmqtt_string_t exp_body = {22, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 8993); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 14); + EXPECT_EQ(msg.payload_len, 22); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 22); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = False, _pubQoS = QoS1, _pubRetain = False, _pubTopic = "'w%\200$\223R\DC4`", _pubPktID = +// 8207, _pubBody = "\253\145\215\176fT\SO\155P\211\218(topic.data), 9); + EXPECT_EQ(msg.payload_len, 19); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 19); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = "m\237T", _pubPktID = 0, _pubBody = +// "K\240\171\DC4,?a}f\GS\244\&7\181\255]\138\150\206|\148\140\128>", _pubProps = [PropSubscriptionIdentifierAvailable +// 120,PropReceiveMaximum 3713,PropMessageExpiryInterval 251,PropSharedSubscriptionAvailable 232,PropTopicAliasMaximum +// 31923,PropMaximumPacketSize 28907,PropAssignedClientIdentifier +// "j\226\188\156\183\196O\rM\212\245\159m\154\198\FS",PropTopicAliasMaximum 29927,PropServerReference "\181\f\CAN"]} +TEST(Publish5QCTest, Encode28) { + uint8_t pkt[] = {0x38, 0x4d, 0x0, 0x3, 0x6d, 0xed, 0x54, 0x30, 0x29, 0x78, 0x21, 0xe, 0x81, 0x2, 0x0, 0x0, + 0x0, 0xfb, 0x2a, 0xe8, 0x22, 0x7c, 0xb3, 0x27, 0x0, 0x0, 0x70, 0xeb, 0x12, 0x0, 0x10, 0x6a, + 0xe2, 0xbc, 0x9c, 0xb7, 0xc4, 0x4f, 0xd, 0x4d, 0xd4, 0xf5, 0x9f, 0x6d, 0x9a, 0xc6, 0x1c, 0x22, + 0x74, 0xe7, 0x1c, 0x0, 0x3, 0xb5, 0xc, 0x18, 0x4b, 0xf0, 0xab, 0x14, 0x2c, 0x3f, 0x61, 0x7d, + 0x66, 0x1d, 0xf4, 0x37, 0xb5, 0xff, 0x5d, 0x8a, 0x96, 0xce, 0x7c, 0x94, 0x8c, 0x80, 0x3e}; + uint8_t topic_bytes[] = {0x6d, 0xed, 0x54}; + lwmqtt_string_t topic = {3, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = false; + uint8_t msg_bytes[] = {0x4b, 0xf0, 0xab, 0x14, 0x2c, 0x3f, 0x61, 0x7d, 0x66, 0x1d, 0xf4, 0x37, + 0xb5, 0xff, 0x5d, 0x8a, 0x96, 0xce, 0x7c, 0x94, 0x8c, 0x80, 0x3e}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 23; + + uint8_t bytesprops0[] = {0x6a, 0xe2, 0xbc, 0x9c, 0xb7, 0xc4, 0x4f, 0xd, + 0x4d, 0xd4, 0xf5, 0x9f, 0x6d, 0x9a, 0xc6, 0x1c}; + uint8_t bytesprops1[] = {0xb5, 0xc, 0x18}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 120}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 3713}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 251}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 232}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 31923}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 28907}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {16, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 29927}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {3, (char*)&bytesprops1}}}, + }; + + lwmqtt_properties_t props = {9, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = False, _pubTopic = "m\237T", _pubPktID = 0, _pubBody = +// "K\240\171\DC4,?a}f\GS\244\&7\181\255]\138\150\206|\148\140\128>", _pubProps = [PropSubscriptionIdentifierAvailable +// 120,PropReceiveMaximum 3713,PropMessageExpiryInterval 251,PropSharedSubscriptionAvailable 232,PropTopicAliasMaximum +// 31923,PropMaximumPacketSize 28907,PropAssignedClientIdentifier +// "j\226\188\156\183\196O\rM\212\245\159m\154\198\FS",PropTopicAliasMaximum 29927,PropServerReference "\181\f\CAN"]} +TEST(Publish5QCTest, Decode28) { + uint8_t pkt[] = {0x38, 0x4d, 0x0, 0x3, 0x6d, 0xed, 0x54, 0x30, 0x29, 0x78, 0x21, 0xe, 0x81, 0x2, 0x0, 0x0, + 0x0, 0xfb, 0x2a, 0xe8, 0x22, 0x7c, 0xb3, 0x27, 0x0, 0x0, 0x70, 0xeb, 0x12, 0x0, 0x10, 0x6a, + 0xe2, 0xbc, 0x9c, 0xb7, 0xc4, 0x4f, 0xd, 0x4d, 0xd4, 0xf5, 0x9f, 0x6d, 0x9a, 0xc6, 0x1c, 0x22, + 0x74, 0xe7, 0x1c, 0x0, 0x3, 0xb5, 0xc, 0x18, 0x4b, 0xf0, 0xab, 0x14, 0x2c, 0x3f, 0x61, 0x7d, + 0x66, 0x1d, 0xf4, 0x37, 0xb5, 0xff, 0x5d, 0x8a, 0x96, 0xce, 0x7c, 0x94, 0x8c, 0x80, 0x3e}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x6d, 0xed, 0x54}; + lwmqtt_string_t exp_topic = {3, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x4b, 0xf0, 0xab, 0x14, 0x2c, 0x3f, 0x61, 0x7d, 0x66, 0x1d, 0xf4, 0x37, + 0xb5, 0xff, 0x5d, 0x8a, 0x96, 0xce, 0x7c, 0x94, 0x8c, 0x80, 0x3e}; + lwmqtt_string_t exp_body = {23, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, false); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 3); + EXPECT_EQ(msg.payload_len, 23); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 23); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "r\223", _pubPktID = 0, _pubBody = +// "Y&\241\149_\178", _pubProps = [PropTopicAlias 29764,PropReceiveMaximum 12538,PropRequestProblemInformation +// 217,PropRequestProblemInformation 212,PropWillDelayInterval 8708]} +TEST(Publish5QCTest, Encode29) { + uint8_t pkt[] = {0x39, 0x1a, 0x0, 0x2, 0x72, 0xdf, 0xf, 0x23, 0x74, 0x44, 0x21, 0x30, 0xfa, 0x17, + 0xd9, 0x17, 0xd4, 0x18, 0x0, 0x0, 0x22, 0x4, 0x59, 0x26, 0xf1, 0x95, 0x5f, 0xb2}; + uint8_t topic_bytes[] = {0x72, 0xdf}; + lwmqtt_string_t topic = {2, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS0; + msg.retained = true; + uint8_t msg_bytes[] = {0x59, 0x26, 0xf1, 0x95, 0x5f, 0xb2}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 6; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 29764}}, {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 12538}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 217}}, {.prop = (lwmqtt_prop_t)23, .value = {.byte = 212}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 8708}}, + }; + + lwmqtt_properties_t props = {5, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 0, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS0, _pubRetain = True, _pubTopic = "r\223", _pubPktID = 0, _pubBody = +// "Y&\241\149_\178", _pubProps = [PropTopicAlias 29764,PropReceiveMaximum 12538,PropRequestProblemInformation +// 217,PropRequestProblemInformation 212,PropWillDelayInterval 8708]} +TEST(Publish5QCTest, Decode29) { + uint8_t pkt[] = {0x39, 0x1a, 0x0, 0x2, 0x72, 0xdf, 0xf, 0x23, 0x74, 0x44, 0x21, 0x30, 0xfa, 0x17, + 0xd9, 0x17, 0xd4, 0x18, 0x0, 0x0, 0x22, 0x4, 0x59, 0x26, 0xf1, 0x95, 0x5f, 0xb2}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0x72, 0xdf}; + lwmqtt_string_t exp_topic = {2, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0x59, 0x26, 0xf1, 0x95, 0x5f, 0xb2}; + lwmqtt_string_t exp_body = {6, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS0); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 0); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 2); + EXPECT_EQ(msg.payload_len, 6); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 6); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\247\220n\163\233a\SO%/\218\186\&6\163Z\GS\ESC3\b\189\140I\131\129\177\185\197\163\188\&6\SYN", _pubPktID = 3711, +// _pubBody = "\205H\232\STX\178\&33\r\237\140\240o\166", _pubProps = [PropSubscriptionIdentifier 2,PropUserProperty +// "\DC2P\161)\246\227\177(" "L\213\139:1\217\245\&0wnk+\182\138",PropMaximumPacketSize 31983,PropMessageExpiryInterval +// 21025,PropAssignedClientIdentifier +// "\219\244~_'T\131\135\255\&2\182\212\239\254\230\SUB\215\DC12\SUB\128q(\191",PropPayloadFormatIndicator +// 83,PropServerKeepAlive 31084,PropServerReference "\212\148J\147\"t\189\222\250\154\251\US",PropTopicAlias +// 8225,PropResponseInformation "\ACK\234\ETB-\180\205\DEL\ah\159",PropAssignedClientIdentifier +// "\183%$:B\181e\r\235\246\160\SI\209xD\238\227",PropResponseInformation "o\182\&2",PropAuthenticationMethod +// "8\DC2\140\191~\SUBZ<)"]} +TEST(Publish5QCTest, Encode30) { + uint8_t pkt[] = {0x3b, 0xbd, 0x1, 0x0, 0x1e, 0xf7, 0xdc, 0x6e, 0xa3, 0xe9, 0x61, 0xe, 0x25, 0x2f, 0xda, 0xba, + 0x36, 0xa3, 0x5a, 0x1d, 0x1b, 0x33, 0x8, 0xbd, 0x8c, 0x49, 0x83, 0x81, 0xb1, 0xb9, 0xc5, 0xa3, + 0xbc, 0x36, 0x16, 0xe, 0x7f, 0x8c, 0x1, 0xb, 0x2, 0x26, 0x0, 0x8, 0x12, 0x50, 0xa1, 0x29, + 0xf6, 0xe3, 0xb1, 0x28, 0x0, 0xe, 0x4c, 0xd5, 0x8b, 0x3a, 0x31, 0xd9, 0xf5, 0x30, 0x77, 0x6e, + 0x6b, 0x2b, 0xb6, 0x8a, 0x27, 0x0, 0x0, 0x7c, 0xef, 0x2, 0x0, 0x0, 0x52, 0x21, 0x12, 0x0, + 0x18, 0xdb, 0xf4, 0x7e, 0x5f, 0x27, 0x54, 0x83, 0x87, 0xff, 0x32, 0xb6, 0xd4, 0xef, 0xfe, 0xe6, + 0x1a, 0xd7, 0x11, 0x32, 0x1a, 0x80, 0x71, 0x28, 0xbf, 0x1, 0x53, 0x13, 0x79, 0x6c, 0x1c, 0x0, + 0xc, 0xd4, 0x94, 0x4a, 0x93, 0x22, 0x74, 0xbd, 0xde, 0xfa, 0x9a, 0xfb, 0x1f, 0x23, 0x20, 0x21, + 0x1a, 0x0, 0xa, 0x6, 0xea, 0x17, 0x2d, 0xb4, 0xcd, 0x7f, 0x7, 0x68, 0x9f, 0x12, 0x0, 0x11, + 0xb7, 0x25, 0x24, 0x3a, 0x42, 0xb5, 0x65, 0xd, 0xeb, 0xf6, 0xa0, 0xf, 0xd1, 0x78, 0x44, 0xee, + 0xe3, 0x1a, 0x0, 0x3, 0x6f, 0xb6, 0x32, 0x15, 0x0, 0x9, 0x38, 0x12, 0x8c, 0xbf, 0x7e, 0x1a, + 0x5a, 0x3c, 0x29, 0xcd, 0x48, 0xe8, 0x2, 0xb2, 0x33, 0x33, 0xd, 0xed, 0x8c, 0xf0, 0x6f, 0xa6}; + uint8_t topic_bytes[] = {0xf7, 0xdc, 0x6e, 0xa3, 0xe9, 0x61, 0xe, 0x25, 0x2f, 0xda, 0xba, 0x36, 0xa3, 0x5a, 0x1d, + 0x1b, 0x33, 0x8, 0xbd, 0x8c, 0x49, 0x83, 0x81, 0xb1, 0xb9, 0xc5, 0xa3, 0xbc, 0x36, 0x16}; + lwmqtt_string_t topic = {30, (char*)&topic_bytes}; + + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_message_t msg = lwmqtt_default_message; + msg.qos = LWMQTT_QOS1; + msg.retained = true; + uint8_t msg_bytes[] = {0xcd, 0x48, 0xe8, 0x2, 0xb2, 0x33, 0x33, 0xd, 0xed, 0x8c, 0xf0, 0x6f, 0xa6}; + msg.payload = (unsigned char*)&msg_bytes; + msg.payload_len = 13; + + uint8_t bytesprops1[] = {0x4c, 0xd5, 0x8b, 0x3a, 0x31, 0xd9, 0xf5, 0x30, 0x77, 0x6e, 0x6b, 0x2b, 0xb6, 0x8a}; + uint8_t bytesprops0[] = {0x12, 0x50, 0xa1, 0x29, 0xf6, 0xe3, 0xb1, 0x28}; + uint8_t bytesprops2[] = {0xdb, 0xf4, 0x7e, 0x5f, 0x27, 0x54, 0x83, 0x87, 0xff, 0x32, 0xb6, 0xd4, + 0xef, 0xfe, 0xe6, 0x1a, 0xd7, 0x11, 0x32, 0x1a, 0x80, 0x71, 0x28, 0xbf}; + uint8_t bytesprops3[] = {0xd4, 0x94, 0x4a, 0x93, 0x22, 0x74, 0xbd, 0xde, 0xfa, 0x9a, 0xfb, 0x1f}; + uint8_t bytesprops4[] = {0x6, 0xea, 0x17, 0x2d, 0xb4, 0xcd, 0x7f, 0x7, 0x68, 0x9f}; + uint8_t bytesprops5[] = {0xb7, 0x25, 0x24, 0x3a, 0x42, 0xb5, 0x65, 0xd, 0xeb, + 0xf6, 0xa0, 0xf, 0xd1, 0x78, 0x44, 0xee, 0xe3}; + uint8_t bytesprops6[] = {0x6f, 0xb6, 0x32}; + uint8_t bytesprops7[] = {0x38, 0x12, 0x8c, 0xbf, 0x7e, 0x1a, 0x5a, 0x3c, 0x29}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 2}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {8, (char*)&bytesprops0}, .v = {14, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 31983}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 21025}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {24, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 83}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 31084}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {12, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 8225}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {10, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {17, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {3, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {9, (char*)&bytesprops7}}}, + }; + + lwmqtt_properties_t props = {13, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_publish(buf, sizeof(buf), &len, LWMQTT_MQTT5, true, 3711, topic, msg, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// PublishRequest {_pubDup = True, _pubQoS = QoS1, _pubRetain = True, _pubTopic = +// "\247\220n\163\233a\SO%/\218\186\&6\163Z\GS\ESC3\b\189\140I\131\129\177\185\197\163\188\&6\SYN", _pubPktID = 3711, +// _pubBody = "\205H\232\STX\178\&33\r\237\140\240o\166", _pubProps = [PropSubscriptionIdentifier 2,PropUserProperty +// "\DC2P\161)\246\227\177(" "L\213\139:1\217\245\&0wnk+\182\138",PropMaximumPacketSize 31983,PropMessageExpiryInterval +// 21025,PropAssignedClientIdentifier +// "\219\244~_'T\131\135\255\&2\182\212\239\254\230\SUB\215\DC12\SUB\128q(\191",PropPayloadFormatIndicator +// 83,PropServerKeepAlive 31084,PropServerReference "\212\148J\147\"t\189\222\250\154\251\US",PropTopicAlias +// 8225,PropResponseInformation "\ACK\234\ETB-\180\205\DEL\ah\159",PropAssignedClientIdentifier +// "\183%$:B\181e\r\235\246\160\SI\209xD\238\227",PropResponseInformation "o\182\&2",PropAuthenticationMethod +// "8\DC2\140\191~\SUBZ<)"]} +TEST(Publish5QCTest, Decode30) { + uint8_t pkt[] = {0x3b, 0xbd, 0x1, 0x0, 0x1e, 0xf7, 0xdc, 0x6e, 0xa3, 0xe9, 0x61, 0xe, 0x25, 0x2f, 0xda, 0xba, + 0x36, 0xa3, 0x5a, 0x1d, 0x1b, 0x33, 0x8, 0xbd, 0x8c, 0x49, 0x83, 0x81, 0xb1, 0xb9, 0xc5, 0xa3, + 0xbc, 0x36, 0x16, 0xe, 0x7f, 0x8c, 0x1, 0xb, 0x2, 0x26, 0x0, 0x8, 0x12, 0x50, 0xa1, 0x29, + 0xf6, 0xe3, 0xb1, 0x28, 0x0, 0xe, 0x4c, 0xd5, 0x8b, 0x3a, 0x31, 0xd9, 0xf5, 0x30, 0x77, 0x6e, + 0x6b, 0x2b, 0xb6, 0x8a, 0x27, 0x0, 0x0, 0x7c, 0xef, 0x2, 0x0, 0x0, 0x52, 0x21, 0x12, 0x0, + 0x18, 0xdb, 0xf4, 0x7e, 0x5f, 0x27, 0x54, 0x83, 0x87, 0xff, 0x32, 0xb6, 0xd4, 0xef, 0xfe, 0xe6, + 0x1a, 0xd7, 0x11, 0x32, 0x1a, 0x80, 0x71, 0x28, 0xbf, 0x1, 0x53, 0x13, 0x79, 0x6c, 0x1c, 0x0, + 0xc, 0xd4, 0x94, 0x4a, 0x93, 0x22, 0x74, 0xbd, 0xde, 0xfa, 0x9a, 0xfb, 0x1f, 0x23, 0x20, 0x21, + 0x1a, 0x0, 0xa, 0x6, 0xea, 0x17, 0x2d, 0xb4, 0xcd, 0x7f, 0x7, 0x68, 0x9f, 0x12, 0x0, 0x11, + 0xb7, 0x25, 0x24, 0x3a, 0x42, 0xb5, 0x65, 0xd, 0xeb, 0xf6, 0xa0, 0xf, 0xd1, 0x78, 0x44, 0xee, + 0xe3, 0x1a, 0x0, 0x3, 0x6f, 0xb6, 0x32, 0x15, 0x0, 0x9, 0x38, 0x12, 0x8c, 0xbf, 0x7e, 0x1a, + 0x5a, 0x3c, 0x29, 0xcd, 0x48, 0xe8, 0x2, 0xb2, 0x33, 0x33, 0xd, 0xed, 0x8c, 0xf0, 0x6f, 0xa6}; + bool dup; + uint16_t packet_id; + lwmqtt_string_t topic; + lwmqtt_message_t msg; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, sizeof(pkt), LWMQTT_MQTT5, &dup, &packet_id, &topic, &msg, &props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + uint8_t exp_topic_bytes[] = {0xf7, 0xdc, 0x6e, 0xa3, 0xe9, 0x61, 0xe, 0x25, 0x2f, 0xda, + 0xba, 0x36, 0xa3, 0x5a, 0x1d, 0x1b, 0x33, 0x8, 0xbd, 0x8c, + 0x49, 0x83, 0x81, 0xb1, 0xb9, 0xc5, 0xa3, 0xbc, 0x36, 0x16}; + lwmqtt_string_t exp_topic = {30, (char*)&exp_topic_bytes}; + uint8_t exp_body_bytes[] = {0xcd, 0x48, 0xe8, 0x2, 0xb2, 0x33, 0x33, 0xd, 0xed, 0x8c, 0xf0, 0x6f, 0xa6}; + lwmqtt_string_t exp_body = {13, (char*)&exp_body_bytes}; + EXPECT_EQ(dup, true); + EXPECT_EQ(msg.qos, LWMQTT_QOS1); + EXPECT_EQ(msg.retained, true); + EXPECT_EQ(packet_id, 3711); + EXPECT_ARRAY_EQ(exp_topic_bytes, reinterpret_cast(topic.data), 30); + EXPECT_EQ(msg.payload_len, 13); + EXPECT_ARRAY_EQ(exp_body_bytes, msg.payload, 13); + lwmqtt_string_t x = exp_topic; + x = exp_body; +} + +// REL (PubREL 27662 0 []) +TEST(PubACKREL311QCTest, Encode1) { + uint8_t pkt[] = {0x62, 0x2, 0x6c, 0xe}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 27662, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 27662 0 []) +TEST(PubACKREL311QCTest, Decode1) { + uint8_t pkt[] = {0x62, 0x2, 0x6c, 0xe}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 27662); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 7224 0 []) +TEST(PubACKREL311QCTest, Encode2) { + uint8_t pkt[] = {0x62, 0x2, 0x1c, 0x38}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 7224, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 7224 0 []) +TEST(PubACKREL311QCTest, Decode2) { + uint8_t pkt[] = {0x62, 0x2, 0x1c, 0x38}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 7224); + EXPECT_EQ(status, 0); +} + +// COMP (PubCOMP 1305 0 []) +TEST(PubACKCOMP311QCTest, Encode3) { + uint8_t pkt[] = {0x70, 0x2, 0x5, 0x19}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, 0, 1305, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 1305 0 []) +TEST(PubACKCOMP311QCTest, Decode3) { + uint8_t pkt[] = {0x70, 0x2, 0x5, 0x19}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 1305); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 1388 0 []) +TEST(PubACKREL311QCTest, Encode4) { + uint8_t pkt[] = {0x62, 0x2, 0x5, 0x6c}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 1388, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 1388 0 []) +TEST(PubACKREL311QCTest, Decode4) { + uint8_t pkt[] = {0x62, 0x2, 0x5, 0x6c}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 1388); + EXPECT_EQ(status, 0); +} + +// REC (PubREC 6133 0 []) +TEST(PubACKREC311QCTest, Encode5) { + uint8_t pkt[] = {0x50, 0x2, 0x17, 0xf5}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREC_PACKET, 0, 6133, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REC (PubREC 6133 0 []) +TEST(PubACKREC311QCTest, Decode5) { + uint8_t pkt[] = {0x50, 0x2, 0x17, 0xf5}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREC_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 6133); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 16008 0 []) +TEST(PubACKREL311QCTest, Encode6) { + uint8_t pkt[] = {0x62, 0x2, 0x3e, 0x88}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 16008, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 16008 0 []) +TEST(PubACKREL311QCTest, Decode6) { + uint8_t pkt[] = {0x62, 0x2, 0x3e, 0x88}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 16008); + EXPECT_EQ(status, 0); +} + +// COMP (PubCOMP 11354 0 []) +TEST(PubACKCOMP311QCTest, Encode7) { + uint8_t pkt[] = {0x70, 0x2, 0x2c, 0x5a}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, 0, 11354, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 11354 0 []) +TEST(PubACKCOMP311QCTest, Decode7) { + uint8_t pkt[] = {0x70, 0x2, 0x2c, 0x5a}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 11354); + EXPECT_EQ(status, 0); +} + +// ACK (PubACK 2046 0 []) +TEST(PubACKACK311QCTest, Encode8) { + uint8_t pkt[] = {0x40, 0x2, 0x7, 0xfe}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, 0, 2046, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ACK (PubACK 2046 0 []) +TEST(PubACKACK311QCTest, Decode8) { + uint8_t pkt[] = {0x40, 0x2, 0x7, 0xfe}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 2046); + EXPECT_EQ(status, 0); +} + +// COMP (PubCOMP 13802 0 []) +TEST(PubACKCOMP311QCTest, Encode9) { + uint8_t pkt[] = {0x70, 0x2, 0x35, 0xea}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, 0, 13802, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 13802 0 []) +TEST(PubACKCOMP311QCTest, Decode9) { + uint8_t pkt[] = {0x70, 0x2, 0x35, 0xea}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 13802); + EXPECT_EQ(status, 0); +} + +// REC (PubREC 16335 0 []) +TEST(PubACKREC311QCTest, Encode10) { + uint8_t pkt[] = {0x50, 0x2, 0x3f, 0xcf}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREC_PACKET, 0, 16335, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REC (PubREC 16335 0 []) +TEST(PubACKREC311QCTest, Decode10) { + uint8_t pkt[] = {0x50, 0x2, 0x3f, 0xcf}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREC_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 16335); + EXPECT_EQ(status, 0); +} + +// COMP (PubCOMP 5460 0 []) +TEST(PubACKCOMP311QCTest, Encode11) { + uint8_t pkt[] = {0x70, 0x2, 0x15, 0x54}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, 0, 5460, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 5460 0 []) +TEST(PubACKCOMP311QCTest, Decode11) { + uint8_t pkt[] = {0x70, 0x2, 0x15, 0x54}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 5460); + EXPECT_EQ(status, 0); +} + +// COMP (PubCOMP 15537 0 []) +TEST(PubACKCOMP311QCTest, Encode12) { + uint8_t pkt[] = {0x70, 0x2, 0x3c, 0xb1}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, 0, 15537, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 15537 0 []) +TEST(PubACKCOMP311QCTest, Decode12) { + uint8_t pkt[] = {0x70, 0x2, 0x3c, 0xb1}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 15537); + EXPECT_EQ(status, 0); +} + +// ACK (PubACK 28091 0 []) +TEST(PubACKACK311QCTest, Encode13) { + uint8_t pkt[] = {0x40, 0x2, 0x6d, 0xbb}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, 0, 28091, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ACK (PubACK 28091 0 []) +TEST(PubACKACK311QCTest, Decode13) { + uint8_t pkt[] = {0x40, 0x2, 0x6d, 0xbb}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 28091); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 10160 0 []) +TEST(PubACKREL311QCTest, Encode14) { + uint8_t pkt[] = {0x62, 0x2, 0x27, 0xb0}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 10160, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 10160 0 []) +TEST(PubACKREL311QCTest, Decode14) { + uint8_t pkt[] = {0x62, 0x2, 0x27, 0xb0}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 10160); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 30332 0 []) +TEST(PubACKREL311QCTest, Encode15) { + uint8_t pkt[] = {0x62, 0x2, 0x76, 0x7c}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 30332, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 30332 0 []) +TEST(PubACKREL311QCTest, Decode15) { + uint8_t pkt[] = {0x62, 0x2, 0x76, 0x7c}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 30332); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 16804 0 []) +TEST(PubACKREL311QCTest, Encode16) { + uint8_t pkt[] = {0x62, 0x2, 0x41, 0xa4}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 16804, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 16804 0 []) +TEST(PubACKREL311QCTest, Decode16) { + uint8_t pkt[] = {0x62, 0x2, 0x41, 0xa4}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 16804); + EXPECT_EQ(status, 0); +} + +// REC (PubREC 5882 0 []) +TEST(PubACKREC311QCTest, Encode17) { + uint8_t pkt[] = {0x50, 0x2, 0x16, 0xfa}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREC_PACKET, 0, 5882, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REC (PubREC 5882 0 []) +TEST(PubACKREC311QCTest, Decode17) { + uint8_t pkt[] = {0x50, 0x2, 0x16, 0xfa}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREC_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 5882); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 9713 0 []) +TEST(PubACKREL311QCTest, Encode18) { + uint8_t pkt[] = {0x62, 0x2, 0x25, 0xf1}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 9713, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 9713 0 []) +TEST(PubACKREL311QCTest, Decode18) { + uint8_t pkt[] = {0x62, 0x2, 0x25, 0xf1}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 9713); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 28230 0 []) +TEST(PubACKREL311QCTest, Encode19) { + uint8_t pkt[] = {0x62, 0x2, 0x6e, 0x46}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 28230, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 28230 0 []) +TEST(PubACKREL311QCTest, Decode19) { + uint8_t pkt[] = {0x62, 0x2, 0x6e, 0x46}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 28230); + EXPECT_EQ(status, 0); +} + +// COMP (PubCOMP 19063 0 []) +TEST(PubACKCOMP311QCTest, Encode20) { + uint8_t pkt[] = {0x70, 0x2, 0x4a, 0x77}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, 0, 19063, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 19063 0 []) +TEST(PubACKCOMP311QCTest, Decode20) { + uint8_t pkt[] = {0x70, 0x2, 0x4a, 0x77}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 19063); + EXPECT_EQ(status, 0); +} + +// ACK (PubACK 459 0 []) +TEST(PubACKACK311QCTest, Encode21) { + uint8_t pkt[] = {0x40, 0x2, 0x1, 0xcb}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, 0, 459, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ACK (PubACK 459 0 []) +TEST(PubACKACK311QCTest, Decode21) { + uint8_t pkt[] = {0x40, 0x2, 0x1, 0xcb}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 459); + EXPECT_EQ(status, 0); +} + +// REC (PubREC 21707 0 []) +TEST(PubACKREC311QCTest, Encode22) { + uint8_t pkt[] = {0x50, 0x2, 0x54, 0xcb}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREC_PACKET, 0, 21707, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REC (PubREC 21707 0 []) +TEST(PubACKREC311QCTest, Decode22) { + uint8_t pkt[] = {0x50, 0x2, 0x54, 0xcb}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREC_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 21707); + EXPECT_EQ(status, 0); +} + +// COMP (PubCOMP 29287 0 []) +TEST(PubACKCOMP311QCTest, Encode23) { + uint8_t pkt[] = {0x70, 0x2, 0x72, 0x67}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, 0, 29287, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 29287 0 []) +TEST(PubACKCOMP311QCTest, Decode23) { + uint8_t pkt[] = {0x70, 0x2, 0x72, 0x67}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 29287); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 18324 0 []) +TEST(PubACKREL311QCTest, Encode24) { + uint8_t pkt[] = {0x62, 0x2, 0x47, 0x94}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 18324, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 18324 0 []) +TEST(PubACKREL311QCTest, Decode24) { + uint8_t pkt[] = {0x62, 0x2, 0x47, 0x94}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 18324); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 29610 0 []) +TEST(PubACKREL311QCTest, Encode25) { + uint8_t pkt[] = {0x62, 0x2, 0x73, 0xaa}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 29610, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 29610 0 []) +TEST(PubACKREL311QCTest, Decode25) { + uint8_t pkt[] = {0x62, 0x2, 0x73, 0xaa}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 29610); + EXPECT_EQ(status, 0); +} + +// REC (PubREC 5042 0 []) +TEST(PubACKREC311QCTest, Encode26) { + uint8_t pkt[] = {0x50, 0x2, 0x13, 0xb2}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREC_PACKET, 0, 5042, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REC (PubREC 5042 0 []) +TEST(PubACKREC311QCTest, Decode26) { + uint8_t pkt[] = {0x50, 0x2, 0x13, 0xb2}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREC_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 5042); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 2316 0 []) +TEST(PubACKREL311QCTest, Encode27) { + uint8_t pkt[] = {0x62, 0x2, 0x9, 0xc}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 2316, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 2316 0 []) +TEST(PubACKREL311QCTest, Decode27) { + uint8_t pkt[] = {0x62, 0x2, 0x9, 0xc}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 2316); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 28050 0 []) +TEST(PubACKREL311QCTest, Encode28) { + uint8_t pkt[] = {0x62, 0x2, 0x6d, 0x92}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, 0, 28050, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 28050 0 []) +TEST(PubACKREL311QCTest, Decode28) { + uint8_t pkt[] = {0x62, 0x2, 0x6d, 0x92}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 28050); + EXPECT_EQ(status, 0); +} + +// COMP (PubCOMP 17627 0 []) +TEST(PubACKCOMP311QCTest, Encode29) { + uint8_t pkt[] = {0x70, 0x2, 0x44, 0xdb}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, 0, 17627, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 17627 0 []) +TEST(PubACKCOMP311QCTest, Decode29) { + uint8_t pkt[] = {0x70, 0x2, 0x44, 0xdb}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 17627); + EXPECT_EQ(status, 0); +} + +// COMP (PubCOMP 5627 0 []) +TEST(PubACKCOMP311QCTest, Encode30) { + uint8_t pkt[] = {0x70, 0x2, 0x15, 0xfb}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, 0, 5627, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 5627 0 []) +TEST(PubACKCOMP311QCTest, Decode30) { + uint8_t pkt[] = {0x70, 0x2, 0x15, 0xfb}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT311, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 5627); + EXPECT_EQ(status, 0); +} + +// REL (PubREL 27662 206 [PropMessageExpiryInterval 28381,PropServerReference +// "\251\162\EM\218\237)\181\158<\EOT",PropMessageExpiryInterval 11155,PropSharedSubscriptionAvailable +// 164,PropTopicAliasMaximum 16670,PropResponseTopic +// "\255\150\179A{\210\189\239s\NUL\140HNJ\228\249t3\191-\154\174\196\DEL\NUL\DC2\241\232-\183",PropMessageExpiryInterval +// 32084,PropAssignedClientIdentifier "\177`\162\ETX{rF\210\215\&2",PropWildcardSubscriptionAvailable +// 244,PropResponseInformation "\231\&7\153\156\222\235\CANe\208\237\DC3o\r\251",PropMessageExpiryInterval +// 5964,PropTopicAlias 24911,PropSessionExpiryInterval 27473,PropMaximumQoS 105,PropContentType +// "\DC4GEK\200Jc\170\153\142\181c\199\188\&3\249\198Z\n\DEL\250\208\DEL\246*p\239\240\143v",PropRetainAvailable 19]) +TEST(PubACKREL5QCTest, Encode1) { + uint8_t pkt[] = {0x62, 0x99, 0x1, 0x6c, 0xe, 0xce, 0x94, 0x1, 0x2, 0x0, 0x0, 0x6e, 0xdd, 0x1c, 0x0, 0xa, + 0xfb, 0xa2, 0x19, 0xda, 0xed, 0x29, 0xb5, 0x9e, 0x3c, 0x4, 0x2, 0x0, 0x0, 0x2b, 0x93, 0x2a, + 0xa4, 0x22, 0x41, 0x1e, 0x8, 0x0, 0x1e, 0xff, 0x96, 0xb3, 0x41, 0x7b, 0xd2, 0xbd, 0xef, 0x73, + 0x0, 0x8c, 0x48, 0x4e, 0x4a, 0xe4, 0xf9, 0x74, 0x33, 0xbf, 0x2d, 0x9a, 0xae, 0xc4, 0x7f, 0x0, + 0x12, 0xf1, 0xe8, 0x2d, 0xb7, 0x2, 0x0, 0x0, 0x7d, 0x54, 0x12, 0x0, 0xa, 0xb1, 0x60, 0xa2, + 0x3, 0x7b, 0x72, 0x46, 0xd2, 0xd7, 0x32, 0x28, 0xf4, 0x1a, 0x0, 0xe, 0xe7, 0x37, 0x99, 0x9c, + 0xde, 0xeb, 0x18, 0x65, 0xd0, 0xed, 0x13, 0x6f, 0xd, 0xfb, 0x2, 0x0, 0x0, 0x17, 0x4c, 0x23, + 0x61, 0x4f, 0x11, 0x0, 0x0, 0x6b, 0x51, 0x24, 0x69, 0x3, 0x0, 0x1e, 0x14, 0x47, 0x45, 0x4b, + 0xc8, 0x4a, 0x63, 0xaa, 0x99, 0x8e, 0xb5, 0x63, 0xc7, 0xbc, 0x33, 0xf9, 0xc6, 0x5a, 0xa, 0x7f, + 0xfa, 0xd0, 0x7f, 0xf6, 0x2a, 0x70, 0xef, 0xf0, 0x8f, 0x76, 0x25, 0x13}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0xfb, 0xa2, 0x19, 0xda, 0xed, 0x29, 0xb5, 0x9e, 0x3c, 0x4}; + uint8_t bytesprops1[] = {0xff, 0x96, 0xb3, 0x41, 0x7b, 0xd2, 0xbd, 0xef, 0x73, 0x0, 0x8c, 0x48, 0x4e, 0x4a, 0xe4, + 0xf9, 0x74, 0x33, 0xbf, 0x2d, 0x9a, 0xae, 0xc4, 0x7f, 0x0, 0x12, 0xf1, 0xe8, 0x2d, 0xb7}; + uint8_t bytesprops2[] = {0xb1, 0x60, 0xa2, 0x3, 0x7b, 0x72, 0x46, 0xd2, 0xd7, 0x32}; + uint8_t bytesprops3[] = {0xe7, 0x37, 0x99, 0x9c, 0xde, 0xeb, 0x18, 0x65, 0xd0, 0xed, 0x13, 0x6f, 0xd, 0xfb}; + uint8_t bytesprops4[] = {0x14, 0x47, 0x45, 0x4b, 0xc8, 0x4a, 0x63, 0xaa, 0x99, 0x8e, 0xb5, 0x63, 0xc7, 0xbc, 0x33, + 0xf9, 0xc6, 0x5a, 0xa, 0x7f, 0xfa, 0xd0, 0x7f, 0xf6, 0x2a, 0x70, 0xef, 0xf0, 0x8f, 0x76}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 28381}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {10, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 11155}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 164}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 16670}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {30, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 32084}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {10, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 244}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {14, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 5964}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 24911}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 27473}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 105}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {30, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 19}}, + }; + + lwmqtt_properties_t props = {16, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 27662, 206, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 27662 206 [PropMessageExpiryInterval 28381,PropServerReference +// "\251\162\EM\218\237)\181\158<\EOT",PropMessageExpiryInterval 11155,PropSharedSubscriptionAvailable +// 164,PropTopicAliasMaximum 16670,PropResponseTopic +// "\255\150\179A{\210\189\239s\NUL\140HNJ\228\249t3\191-\154\174\196\DEL\NUL\DC2\241\232-\183",PropMessageExpiryInterval +// 32084,PropAssignedClientIdentifier "\177`\162\ETX{rF\210\215\&2",PropWildcardSubscriptionAvailable +// 244,PropResponseInformation "\231\&7\153\156\222\235\CANe\208\237\DC3o\r\251",PropMessageExpiryInterval +// 5964,PropTopicAlias 24911,PropSessionExpiryInterval 27473,PropMaximumQoS 105,PropContentType +// "\DC4GEK\200Jc\170\153\142\181c\199\188\&3\249\198Z\n\DEL\250\208\DEL\246*p\239\240\143v",PropRetainAvailable 19]) +TEST(PubACKREL5QCTest, Decode1) { + uint8_t pkt[] = {0x62, 0x99, 0x1, 0x6c, 0xe, 0xce, 0x94, 0x1, 0x2, 0x0, 0x0, 0x6e, 0xdd, 0x1c, 0x0, 0xa, + 0xfb, 0xa2, 0x19, 0xda, 0xed, 0x29, 0xb5, 0x9e, 0x3c, 0x4, 0x2, 0x0, 0x0, 0x2b, 0x93, 0x2a, + 0xa4, 0x22, 0x41, 0x1e, 0x8, 0x0, 0x1e, 0xff, 0x96, 0xb3, 0x41, 0x7b, 0xd2, 0xbd, 0xef, 0x73, + 0x0, 0x8c, 0x48, 0x4e, 0x4a, 0xe4, 0xf9, 0x74, 0x33, 0xbf, 0x2d, 0x9a, 0xae, 0xc4, 0x7f, 0x0, + 0x12, 0xf1, 0xe8, 0x2d, 0xb7, 0x2, 0x0, 0x0, 0x7d, 0x54, 0x12, 0x0, 0xa, 0xb1, 0x60, 0xa2, + 0x3, 0x7b, 0x72, 0x46, 0xd2, 0xd7, 0x32, 0x28, 0xf4, 0x1a, 0x0, 0xe, 0xe7, 0x37, 0x99, 0x9c, + 0xde, 0xeb, 0x18, 0x65, 0xd0, 0xed, 0x13, 0x6f, 0xd, 0xfb, 0x2, 0x0, 0x0, 0x17, 0x4c, 0x23, + 0x61, 0x4f, 0x11, 0x0, 0x0, 0x6b, 0x51, 0x24, 0x69, 0x3, 0x0, 0x1e, 0x14, 0x47, 0x45, 0x4b, + 0xc8, 0x4a, 0x63, 0xaa, 0x99, 0x8e, 0xb5, 0x63, 0xc7, 0xbc, 0x33, 0xf9, 0xc6, 0x5a, 0xa, 0x7f, + 0xfa, 0xd0, 0x7f, 0xf6, 0x2a, 0x70, 0xef, 0xf0, 0x8f, 0x76, 0x25, 0x13}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 27662); + EXPECT_EQ(status, 206); +} + +// REL (PubREL 7224 232 []) +TEST(PubACKREL5QCTest, Encode2) { + uint8_t pkt[] = {0x62, 0x3, 0x1c, 0x38, 0xe8}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 7224, 232, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 7224 232 []) +TEST(PubACKREL5QCTest, Decode2) { + uint8_t pkt[] = {0x62, 0x3, 0x1c, 0x38, 0xe8}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 7224); + EXPECT_EQ(status, 232); +} + +// COMP (PubCOMP 1305 131 [PropRequestResponseInformation 131,PropAuthenticationData +// "\202B\131\147\197Nv0\153d\a\251\133\233tY\226\225eE",PropResponseInformation "\129\173[",PropSessionExpiryInterval +// 17545,PropTopicAlias 28775,PropContentType "\223pT\177\129\"\132\246",PropRetainAvailable 145,PropTopicAlias +// 32536,PropSubscriptionIdentifier 24,PropRetainAvailable 230,PropAuthenticationData +// "\CAN\171\&4m\182\235\207\128\163\&5P\242\&8\GS?\\J",PropTopicAliasMaximum 22478,PropResponseInformation "tE+\fk +// \160\DC1JI\235\247\172\208B",PropServerKeepAlive +// 21968,PropWillDelayInterval 18315,PropServerReference "{3\176\205\b\147\213\r\194\130e",PropPayloadFormatIndicator +// 143,PropUserProperty ";\n\NUL\165\183\230\252\198hG[)\v" +// "\238\250\&5\231%\b;\207\222\198\176\240\169\STX\195\198\133\218\214\SO",PropMaximumQoS 136,PropTopicAlias +// 1903,PropMaximumPacketSize 10248,PropRequestResponseInformation 159,PropRequestProblemInformation +// 126,PropRequestProblemInformation 176,PropResponseTopic +// "\235\SIl\251\ACKc\f\vh/\248\166-\198\vQ\246\160\205F\224\226\252\DC1;\177\161T)\200",PropMaximumPacketSize 27165]) +TEST(PubACKREL5QCTest, Encode4) { + uint8_t pkt[] = {0x62, 0xad, 0x1, 0x5, 0x6c, 0xf0, 0xa8, 0x1, 0x19, 0x94, 0x3, 0x0, 0x5, 0xf0, 0x15, 0x9c, + 0xb6, 0x89, 0x21, 0x5a, 0x22, 0x21, 0x57, 0xcf, 0x24, 0xd4, 0x28, 0x19, 0x1c, 0x0, 0x1d, 0xa9, + 0xa, 0xe, 0x42, 0xff, 0x4d, 0x3d, 0x44, 0x8b, 0xe9, 0xa, 0x97, 0xda, 0x63, 0x72, 0x47, 0xda, + 0xcd, 0x51, 0xfc, 0x19, 0x9f, 0x29, 0x3e, 0xeb, 0xf7, 0xac, 0xd0, 0x42, 0x13, 0x55, 0xd0, 0x18, + 0x0, 0x0, 0x47, 0x8b, 0x1c, 0x0, 0xb, 0x7b, 0x33, 0xb0, 0xcd, 0x8, 0x93, 0xd5, 0xd, 0xc2, + 0x82, 0x65, 0x1, 0x8f, 0x26, 0x0, 0xd, 0x3b, 0xa, 0x0, 0xa5, 0xb7, 0xe6, 0xfc, 0xc6, 0x68, + 0x47, 0x5b, 0x29, 0xb, 0x0, 0x14, 0xee, 0xfa, 0x35, 0xe7, 0x25, 0x8, 0x3b, 0xcf, 0xde, 0xc6, + 0xb0, 0xf0, 0xa9, 0x2, 0xc3, 0xc6, 0x85, 0xda, 0xd6, 0xe, 0x24, 0x88, 0x23, 0x7, 0x6f, 0x27, + 0x0, 0x0, 0x28, 0x8, 0x19, 0x9f, 0x17, 0x7e, 0x17, 0xb0, 0x8, 0x0, 0x1e, 0xeb, 0xf, 0x6c, + 0xfb, 0x6, 0x63, 0xc, 0xb, 0x68, 0x2f, 0xf8, 0xa6, 0x2d, 0xc6, 0xb, 0x51, 0xf6, 0xa0, 0xcd, + 0x46, 0xe0, 0xe2, 0xfc, 0x11, 0x3b, 0xb1, 0xa1, 0x54, 0x29, 0xc8, 0x27, 0x0, 0x0, 0x6a, 0x1d}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0xf0, 0x15, 0x9c, 0xb6, 0x89}; + uint8_t bytesprops1[] = {0xa9, 0xa, 0xe, 0x42, 0xff, 0x4d, 0x3d, 0x44, 0x8b, 0xe9, 0xa, 0x97, 0xda, 0x63, 0x72, + 0x47, 0xda, 0xcd, 0x51, 0xfc, 0x19, 0x9f, 0x29, 0x3e, 0xeb, 0xf7, 0xac, 0xd0, 0x42}; + uint8_t bytesprops2[] = {0x7b, 0x33, 0xb0, 0xcd, 0x8, 0x93, 0xd5, 0xd, 0xc2, 0x82, 0x65}; + uint8_t bytesprops4[] = {0xee, 0xfa, 0x35, 0xe7, 0x25, 0x8, 0x3b, 0xcf, 0xde, 0xc6, + 0xb0, 0xf0, 0xa9, 0x2, 0xc3, 0xc6, 0x85, 0xda, 0xd6, 0xe}; + uint8_t bytesprops3[] = {0x3b, 0xa, 0x0, 0xa5, 0xb7, 0xe6, 0xfc, 0xc6, 0x68, 0x47, 0x5b, 0x29, 0xb}; + uint8_t bytesprops5[] = {0xeb, 0xf, 0x6c, 0xfb, 0x6, 0x63, 0xc, 0xb, 0x68, 0x2f, 0xf8, 0xa6, 0x2d, 0xc6, 0xb, + 0x51, 0xf6, 0xa0, 0xcd, 0x46, 0xe0, 0xe2, 0xfc, 0x11, 0x3b, 0xb1, 0xa1, 0x54, 0x29, 0xc8}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 148}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {5, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 23074}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 22479}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 212}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 25}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {29, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 21968}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 18315}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {11, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 143}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {13, (char*)&bytesprops3}, .v = {20, (char*)&bytesprops4}}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 136}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 1903}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 10248}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 159}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 126}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 176}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {30, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 27165}}, + }; + + lwmqtt_properties_t props = {20, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 1388, 240, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 1388 240 [PropRequestResponseInformation 148,PropContentType "\240\NAK\156\182\137",PropReceiveMaximum +// 23074,PropReceiveMaximum 22479,PropMaximumQoS 212,PropWildcardSubscriptionAvailable 25,PropServerReference +// "\169\n\SOB\255M=D\139\233\n\151\218crG\218\205Q\252\EM\159)>\235\247\172\208B",PropServerKeepAlive +// 21968,PropWillDelayInterval 18315,PropServerReference "{3\176\205\b\147\213\r\194\130e",PropPayloadFormatIndicator +// 143,PropUserProperty ";\n\NUL\165\183\230\252\198hG[)\v" +// "\238\250\&5\231%\b;\207\222\198\176\240\169\STX\195\198\133\218\214\SO",PropMaximumQoS 136,PropTopicAlias +// 1903,PropMaximumPacketSize 10248,PropRequestResponseInformation 159,PropRequestProblemInformation +// 126,PropRequestProblemInformation 176,PropResponseTopic +// "\235\SIl\251\ACKc\f\vh/\248\166-\198\vQ\246\160\205F\224\226\252\DC1;\177\161T)\200",PropMaximumPacketSize 27165]) +TEST(PubACKREL5QCTest, Decode4) { + uint8_t pkt[] = {0x62, 0xad, 0x1, 0x5, 0x6c, 0xf0, 0xa8, 0x1, 0x19, 0x94, 0x3, 0x0, 0x5, 0xf0, 0x15, 0x9c, + 0xb6, 0x89, 0x21, 0x5a, 0x22, 0x21, 0x57, 0xcf, 0x24, 0xd4, 0x28, 0x19, 0x1c, 0x0, 0x1d, 0xa9, + 0xa, 0xe, 0x42, 0xff, 0x4d, 0x3d, 0x44, 0x8b, 0xe9, 0xa, 0x97, 0xda, 0x63, 0x72, 0x47, 0xda, + 0xcd, 0x51, 0xfc, 0x19, 0x9f, 0x29, 0x3e, 0xeb, 0xf7, 0xac, 0xd0, 0x42, 0x13, 0x55, 0xd0, 0x18, + 0x0, 0x0, 0x47, 0x8b, 0x1c, 0x0, 0xb, 0x7b, 0x33, 0xb0, 0xcd, 0x8, 0x93, 0xd5, 0xd, 0xc2, + 0x82, 0x65, 0x1, 0x8f, 0x26, 0x0, 0xd, 0x3b, 0xa, 0x0, 0xa5, 0xb7, 0xe6, 0xfc, 0xc6, 0x68, + 0x47, 0x5b, 0x29, 0xb, 0x0, 0x14, 0xee, 0xfa, 0x35, 0xe7, 0x25, 0x8, 0x3b, 0xcf, 0xde, 0xc6, + 0xb0, 0xf0, 0xa9, 0x2, 0xc3, 0xc6, 0x85, 0xda, 0xd6, 0xe, 0x24, 0x88, 0x23, 0x7, 0x6f, 0x27, + 0x0, 0x0, 0x28, 0x8, 0x19, 0x9f, 0x17, 0x7e, 0x17, 0xb0, 0x8, 0x0, 0x1e, 0xeb, 0xf, 0x6c, + 0xfb, 0x6, 0x63, 0xc, 0xb, 0x68, 0x2f, 0xf8, 0xa6, 0x2d, 0xc6, 0xb, 0x51, 0xf6, 0xa0, 0xcd, + 0x46, 0xe0, 0xe2, 0xfc, 0x11, 0x3b, 0xb1, 0xa1, 0x54, 0x29, 0xc8, 0x27, 0x0, 0x0, 0x6a, 0x1d}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 1388); + EXPECT_EQ(status, 240); +} + +// REC (PubREC 6133 154 [PropRetainAvailable 247,PropWildcardSubscriptionAvailable 253,PropContentType +// ")\252\197",PropMaximumPacketSize 20846,PropSharedSubscriptionAvailable 132,PropSubscriptionIdentifier +// 21,PropMaximumQoS 228]) +TEST(PubACKREC5QCTest, Encode5) { + uint8_t pkt[] = {0x50, 0x19, 0x17, 0xf5, 0x9a, 0x15, 0x25, 0xf7, 0x28, 0xfd, 0x3, 0x0, 0x3, 0x29, + 0xfc, 0xc5, 0x27, 0x0, 0x0, 0x51, 0x6e, 0x2a, 0x84, 0xb, 0x15, 0x24, 0xe4}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x29, 0xfc, 0xc5}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 247}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 253}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {3, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 20846}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 132}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 21}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 228}}, + }; + + lwmqtt_properties_t props = {7, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREC_PACKET, 0, 6133, 154, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REC (PubREC 6133 154 [PropRetainAvailable 247,PropWildcardSubscriptionAvailable 253,PropContentType +// ")\252\197",PropMaximumPacketSize 20846,PropSharedSubscriptionAvailable 132,PropSubscriptionIdentifier +// 21,PropMaximumQoS 228]) +TEST(PubACKREC5QCTest, Decode5) { + uint8_t pkt[] = {0x50, 0x19, 0x17, 0xf5, 0x9a, 0x15, 0x25, 0xf7, 0x28, 0xfd, 0x3, 0x0, 0x3, 0x29, + 0xfc, 0xc5, 0x27, 0x0, 0x0, 0x51, 0x6e, 0x2a, 0x84, 0xb, 0x15, 0x24, 0xe4}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREC_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 6133); + EXPECT_EQ(status, 154); +} + +// REL (PubREL 16008 77 [PropMessageExpiryInterval 24253,PropSubscriptionIdentifier 17,PropCorrelationData +// "+-\bX\211\176yy\158\DC1W\186\214H/V&\189\194B\208\b\142\ENQ\166",PropReasonString +// "\ETB\ENQ\177\US\131\232P",PropMaximumQoS 242,PropRetainAvailable 120,PropResponseTopic +// "\182\208\145\SI\222\199\182\217\128\207\151O\225\RS\253u\ETXa^b\190",PropTopicAlias +// 18988,PropWildcardSubscriptionAvailable 2,PropWillDelayInterval 19083,PropSessionExpiryInterval +// 19792,PropSubscriptionIdentifier 14,PropTopicAlias 26758,PropMessageExpiryInterval 3502,PropMessageExpiryInterval +// 23733,PropCorrelationData +// "H\r4\207l\181\237\212\145\213\DC1n\179\175\189\253\150\237\ACK7t2\247",PropAuthenticationData +// "4\ETB,\229",PropAssignedClientIdentifier "}\219\147\139\177\236\223\160\ACK",PropResponseInformation +// "5Qmm\184\188\232\&4\140\195\187\236\183;\238*\EOT\174"]) +TEST(PubACKREL5QCTest, Encode6) { + uint8_t pkt[] = {0x62, 0xae, 0x1, 0x3e, 0x88, 0x4d, 0xa9, 0x1, 0x2, 0x0, 0x0, 0x5e, 0xbd, 0xb, 0x11, 0x9, 0x0, + 0x19, 0x2b, 0x2d, 0x8, 0x58, 0xd3, 0xb0, 0x79, 0x79, 0x9e, 0x11, 0x57, 0xba, 0xd6, 0x48, 0x2f, 0x56, + 0x26, 0xbd, 0xc2, 0x42, 0xd0, 0x8, 0x8e, 0x5, 0xa6, 0x1f, 0x0, 0x7, 0x17, 0x5, 0xb1, 0x1f, 0x83, + 0xe8, 0x50, 0x24, 0xf2, 0x25, 0x78, 0x8, 0x0, 0x15, 0xb6, 0xd0, 0x91, 0xf, 0xde, 0xc7, 0xb6, 0xd9, + 0x80, 0xcf, 0x97, 0x4f, 0xe1, 0x1e, 0xfd, 0x75, 0x3, 0x61, 0x5e, 0x62, 0xbe, 0x23, 0x4a, 0x2c, 0x28, + 0x2, 0x18, 0x0, 0x0, 0x4a, 0x8b, 0x11, 0x0, 0x0, 0x4d, 0x50, 0xb, 0xe, 0x23, 0x68, 0x86, 0x2, + 0x0, 0x0, 0xd, 0xae, 0x2, 0x0, 0x0, 0x5c, 0xb5, 0x9, 0x0, 0x17, 0x48, 0xd, 0x34, 0xcf, 0x6c, + 0xb5, 0xed, 0xd4, 0x91, 0xd5, 0x11, 0x6e, 0xb3, 0xaf, 0xbd, 0xfd, 0x96, 0xed, 0x6, 0x37, 0x74, 0x32, + 0xf7, 0x16, 0x0, 0x4, 0x34, 0x17, 0x2c, 0xe5, 0x12, 0x0, 0x9, 0x7d, 0xdb, 0x93, 0x8b, 0xb1, 0xec, + 0xdf, 0xa0, 0x6, 0x1a, 0x0, 0x12, 0x35, 0x51, 0x6d, 0x6d, 0xb8, 0xbc, 0xe8, 0x34, 0x8c, 0xc3, 0xbb, + 0xec, 0xb7, 0x3b, 0xee, 0x2a, 0x4, 0xae}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x2b, 0x2d, 0x8, 0x58, 0xd3, 0xb0, 0x79, 0x79, 0x9e, 0x11, 0x57, 0xba, 0xd6, + 0x48, 0x2f, 0x56, 0x26, 0xbd, 0xc2, 0x42, 0xd0, 0x8, 0x8e, 0x5, 0xa6}; + uint8_t bytesprops1[] = {0x17, 0x5, 0xb1, 0x1f, 0x83, 0xe8, 0x50}; + uint8_t bytesprops2[] = {0xb6, 0xd0, 0x91, 0xf, 0xde, 0xc7, 0xb6, 0xd9, 0x80, 0xcf, 0x97, + 0x4f, 0xe1, 0x1e, 0xfd, 0x75, 0x3, 0x61, 0x5e, 0x62, 0xbe}; + uint8_t bytesprops3[] = {0x48, 0xd, 0x34, 0xcf, 0x6c, 0xb5, 0xed, 0xd4, 0x91, 0xd5, 0x11, 0x6e, + 0xb3, 0xaf, 0xbd, 0xfd, 0x96, 0xed, 0x6, 0x37, 0x74, 0x32, 0xf7}; + uint8_t bytesprops4[] = {0x34, 0x17, 0x2c, 0xe5}; + uint8_t bytesprops5[] = {0x7d, 0xdb, 0x93, 0x8b, 0xb1, 0xec, 0xdf, 0xa0, 0x6}; + uint8_t bytesprops6[] = {0x35, 0x51, 0x6d, 0x6d, 0xb8, 0xbc, 0xe8, 0x34, 0x8c, + 0xc3, 0xbb, 0xec, 0xb7, 0x3b, 0xee, 0x2a, 0x4, 0xae}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 24253}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 17}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {25, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {7, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 242}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 120}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {21, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 18988}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 2}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 19083}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 19792}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 14}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 26758}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 3502}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 23733}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {23, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {4, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {9, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {18, (char*)&bytesprops6}}}, + }; + + lwmqtt_properties_t props = {19, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 16008, 77, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 16008 77 [PropMessageExpiryInterval 24253,PropSubscriptionIdentifier 17,PropCorrelationData +// "+-\bX\211\176yy\158\DC1W\186\214H/V&\189\194B\208\b\142\ENQ\166",PropReasonString +// "\ETB\ENQ\177\US\131\232P",PropMaximumQoS 242,PropRetainAvailable 120,PropResponseTopic +// "\182\208\145\SI\222\199\182\217\128\207\151O\225\RS\253u\ETXa^b\190",PropTopicAlias +// 18988,PropWildcardSubscriptionAvailable 2,PropWillDelayInterval 19083,PropSessionExpiryInterval +// 19792,PropSubscriptionIdentifier 14,PropTopicAlias 26758,PropMessageExpiryInterval 3502,PropMessageExpiryInterval +// 23733,PropCorrelationData +// "H\r4\207l\181\237\212\145\213\DC1n\179\175\189\253\150\237\ACK7t2\247",PropAuthenticationData +// "4\ETB,\229",PropAssignedClientIdentifier "}\219\147\139\177\236\223\160\ACK",PropResponseInformation +// "5Qmm\184\188\232\&4\140\195\187\236\183;\238*\EOT\174"]) +TEST(PubACKREL5QCTest, Decode6) { + uint8_t pkt[] = {0x62, 0xae, 0x1, 0x3e, 0x88, 0x4d, 0xa9, 0x1, 0x2, 0x0, 0x0, 0x5e, 0xbd, 0xb, 0x11, 0x9, 0x0, + 0x19, 0x2b, 0x2d, 0x8, 0x58, 0xd3, 0xb0, 0x79, 0x79, 0x9e, 0x11, 0x57, 0xba, 0xd6, 0x48, 0x2f, 0x56, + 0x26, 0xbd, 0xc2, 0x42, 0xd0, 0x8, 0x8e, 0x5, 0xa6, 0x1f, 0x0, 0x7, 0x17, 0x5, 0xb1, 0x1f, 0x83, + 0xe8, 0x50, 0x24, 0xf2, 0x25, 0x78, 0x8, 0x0, 0x15, 0xb6, 0xd0, 0x91, 0xf, 0xde, 0xc7, 0xb6, 0xd9, + 0x80, 0xcf, 0x97, 0x4f, 0xe1, 0x1e, 0xfd, 0x75, 0x3, 0x61, 0x5e, 0x62, 0xbe, 0x23, 0x4a, 0x2c, 0x28, + 0x2, 0x18, 0x0, 0x0, 0x4a, 0x8b, 0x11, 0x0, 0x0, 0x4d, 0x50, 0xb, 0xe, 0x23, 0x68, 0x86, 0x2, + 0x0, 0x0, 0xd, 0xae, 0x2, 0x0, 0x0, 0x5c, 0xb5, 0x9, 0x0, 0x17, 0x48, 0xd, 0x34, 0xcf, 0x6c, + 0xb5, 0xed, 0xd4, 0x91, 0xd5, 0x11, 0x6e, 0xb3, 0xaf, 0xbd, 0xfd, 0x96, 0xed, 0x6, 0x37, 0x74, 0x32, + 0xf7, 0x16, 0x0, 0x4, 0x34, 0x17, 0x2c, 0xe5, 0x12, 0x0, 0x9, 0x7d, 0xdb, 0x93, 0x8b, 0xb1, 0xec, + 0xdf, 0xa0, 0x6, 0x1a, 0x0, 0x12, 0x35, 0x51, 0x6d, 0x6d, 0xb8, 0xbc, 0xe8, 0x34, 0x8c, 0xc3, 0xbb, + 0xec, 0xb7, 0x3b, 0xee, 0x2a, 0x4, 0xae}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 16008); + EXPECT_EQ(status, 77); +} + +// COMP (PubCOMP 11354 201 [PropWildcardSubscriptionAvailable 99,PropWildcardSubscriptionAvailable 193]) +TEST(PubACKCOMP5QCTest, Encode7) { + uint8_t pkt[] = {0x70, 0x8, 0x2c, 0x5a, 0xc9, 0x4, 0x28, 0x63, 0x28, 0xc1}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 99}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 193}}, + }; + + lwmqtt_properties_t props = {2, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, 0, 11354, 201, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 11354 201 [PropWildcardSubscriptionAvailable 99,PropWildcardSubscriptionAvailable 193]) +TEST(PubACKCOMP5QCTest, Decode7) { + uint8_t pkt[] = {0x70, 0x8, 0x2c, 0x5a, 0xc9, 0x4, 0x28, 0x63, 0x28, 0xc1}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 11354); + EXPECT_EQ(status, 201); +} + +// ACK (PubACK 2046 206 [PropSessionExpiryInterval 17445,PropCorrelationData +// "\163L\218I<\DLE\173\r\143\v\160",PropResponseTopic "J\198\190\246",PropResponseInformation "2\156\222 +// \212\&9\ETX\228\154",PropReasonString +// "\bX)\a\173\204\150wL\202*`\247E\225\"\171\222.\157\194ocC\252\170\133",PropTopicAlias +// 18914,PropSubscriptionIdentifierAvailable 143,PropCorrelationData "4\172\DC2Y\236",PropMaximumQoS 43]) +TEST(PubACKACK5QCTest, Encode8) { + uint8_t pkt[] = {0x40, 0x57, 0x7, 0xfe, 0xce, 0x53, 0x11, 0x0, 0x0, 0x44, 0x25, 0x9, 0x0, 0xb, 0xa3, + 0x4c, 0xda, 0x49, 0x3c, 0x10, 0xad, 0xd, 0x8f, 0xb, 0xa0, 0x8, 0x0, 0x4, 0x4a, 0xc6, + 0xbe, 0xf6, 0x1a, 0x0, 0x9, 0x32, 0x9c, 0xde, 0x20, 0xd4, 0x39, 0x3, 0xe4, 0x9a, 0x1f, + 0x0, 0x1b, 0x8, 0x58, 0x29, 0x7, 0xad, 0xcc, 0x96, 0x77, 0x4c, 0xca, 0x2a, 0x60, 0xf7, + 0x45, 0xe1, 0x22, 0xab, 0xde, 0x2e, 0x9d, 0xc2, 0x6f, 0x63, 0x43, 0xfc, 0xaa, 0x85, 0x23, + 0x49, 0xe2, 0x29, 0x8f, 0x9, 0x0, 0x5, 0x34, 0xac, 0x12, 0x59, 0xec, 0x24, 0x2b}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0xa3, 0x4c, 0xda, 0x49, 0x3c, 0x10, 0xad, 0xd, 0x8f, 0xb, 0xa0}; + uint8_t bytesprops1[] = {0x4a, 0xc6, 0xbe, 0xf6}; + uint8_t bytesprops2[] = {0x32, 0x9c, 0xde, 0x20, 0xd4, 0x39, 0x3, 0xe4, 0x9a}; + uint8_t bytesprops3[] = {0x8, 0x58, 0x29, 0x7, 0xad, 0xcc, 0x96, 0x77, 0x4c, 0xca, 0x2a, 0x60, 0xf7, 0x45, + 0xe1, 0x22, 0xab, 0xde, 0x2e, 0x9d, 0xc2, 0x6f, 0x63, 0x43, 0xfc, 0xaa, 0x85}; + uint8_t bytesprops4[] = {0x34, 0xac, 0x12, 0x59, 0xec}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 17445}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {11, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {4, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {9, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {27, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 18914}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 143}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {5, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 43}}, + }; + + lwmqtt_properties_t props = {9, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBACK_PACKET, 0, 2046, 206, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ACK (PubACK 2046 206 [PropSessionExpiryInterval 17445,PropCorrelationData +// "\163L\218I<\DLE\173\r\143\v\160",PropResponseTopic "J\198\190\246",PropResponseInformation "2\156\222 +// \212\&9\ETX\228\154",PropReasonString +// "\bX)\a\173\204\150wL\202*`\247E\225\"\171\222.\157\194ocC\252\170\133",PropTopicAlias +// 18914,PropSubscriptionIdentifierAvailable 143,PropCorrelationData "4\172\DC2Y\236",PropMaximumQoS 43]) +TEST(PubACKACK5QCTest, Decode8) { + uint8_t pkt[] = {0x40, 0x57, 0x7, 0xfe, 0xce, 0x53, 0x11, 0x0, 0x0, 0x44, 0x25, 0x9, 0x0, 0xb, 0xa3, + 0x4c, 0xda, 0x49, 0x3c, 0x10, 0xad, 0xd, 0x8f, 0xb, 0xa0, 0x8, 0x0, 0x4, 0x4a, 0xc6, + 0xbe, 0xf6, 0x1a, 0x0, 0x9, 0x32, 0x9c, 0xde, 0x20, 0xd4, 0x39, 0x3, 0xe4, 0x9a, 0x1f, + 0x0, 0x1b, 0x8, 0x58, 0x29, 0x7, 0xad, 0xcc, 0x96, 0x77, 0x4c, 0xca, 0x2a, 0x60, 0xf7, + 0x45, 0xe1, 0x22, 0xab, 0xde, 0x2e, 0x9d, 0xc2, 0x6f, 0x63, 0x43, 0xfc, 0xaa, 0x85, 0x23, + 0x49, 0xe2, 0x29, 0x8f, 0x9, 0x0, 0x5, 0x34, 0xac, 0x12, 0x59, 0xec, 0x24, 0x2b}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBACK_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 2046); + EXPECT_EQ(status, 206); +} + +// COMP (PubCOMP 13802 137 [PropPayloadFormatIndicator 108,PropCorrelationData +// "2H\163\240\f7]\227\184\tY",PropReasonString "\197\158\221\201\&31",PropPayloadFormatIndicator +// 148,PropResponseInformation "~wQo\ETX\ETX",PropReceiveMaximum 20672,PropUserProperty +// "\210_\nS\SUB\219\217P9\156\188\192\187\209\177\t\STX\"7N\203" +// "\218\233J\142\217\SOH\ETB\181\\B\186",PropServerReference +// "\188~\179\&2z\130\131J\SO\244\223\201\218",PropAssignedClientIdentifier +// "c.\209\DEL\\\208\194\234M",PropMessageExpiryInterval 31572,PropContentType +// "\254{S\158\195\177\220F\239\232a\173\238Az\174~\176\ESC",PropServerReference +// "\247i\132\198)\154w\no*\134pl/\211\149\224\\\a\157\252|\146\197",PropMessageExpiryInterval +// 26929,PropSharedSubscriptionAvailable 94]) +TEST(PubACKCOMP5QCTest, Encode9) { + uint8_t pkt[] = {0x70, 0xaa, 0x1, 0x35, 0xea, 0x89, 0xa5, 0x1, 0x1, 0x6c, 0x9, 0x0, 0xb, 0x32, 0x48, 0xa3, + 0xf0, 0xc, 0x37, 0x5d, 0xe3, 0xb8, 0x9, 0x59, 0x1f, 0x0, 0x6, 0xc5, 0x9e, 0xdd, 0xc9, 0x33, + 0x31, 0x1, 0x94, 0x1a, 0x0, 0x6, 0x7e, 0x77, 0x51, 0x6f, 0x3, 0x3, 0x21, 0x50, 0xc0, 0x26, + 0x0, 0x15, 0xd2, 0x5f, 0xa, 0x53, 0x1a, 0xdb, 0xd9, 0x50, 0x39, 0x9c, 0xbc, 0xc0, 0xbb, 0xd1, + 0xb1, 0x9, 0x2, 0x22, 0x37, 0x4e, 0xcb, 0x0, 0xb, 0xda, 0xe9, 0x4a, 0x8e, 0xd9, 0x1, 0x17, + 0xb5, 0x5c, 0x42, 0xba, 0x1c, 0x0, 0xd, 0xbc, 0x7e, 0xb3, 0x32, 0x7a, 0x82, 0x83, 0x4a, 0xe, + 0xf4, 0xdf, 0xc9, 0xda, 0x12, 0x0, 0x9, 0x63, 0x2e, 0xd1, 0x7f, 0x5c, 0xd0, 0xc2, 0xea, 0x4d, + 0x2, 0x0, 0x0, 0x7b, 0x54, 0x3, 0x0, 0x13, 0xfe, 0x7b, 0x53, 0x9e, 0xc3, 0xb1, 0xdc, 0x46, + 0xef, 0xe8, 0x61, 0xad, 0xee, 0x41, 0x7a, 0xae, 0x7e, 0xb0, 0x1b, 0x1c, 0x0, 0x18, 0xf7, 0x69, + 0x84, 0xc6, 0x29, 0x9a, 0x77, 0xa, 0x6f, 0x2a, 0x86, 0x70, 0x6c, 0x2f, 0xd3, 0x95, 0xe0, 0x5c, + 0x7, 0x9d, 0xfc, 0x7c, 0x92, 0xc5, 0x2, 0x0, 0x0, 0x69, 0x31, 0x2a, 0x5e}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x32, 0x48, 0xa3, 0xf0, 0xc, 0x37, 0x5d, 0xe3, 0xb8, 0x9, 0x59}; + uint8_t bytesprops1[] = {0xc5, 0x9e, 0xdd, 0xc9, 0x33, 0x31}; + uint8_t bytesprops2[] = {0x7e, 0x77, 0x51, 0x6f, 0x3, 0x3}; + uint8_t bytesprops4[] = {0xda, 0xe9, 0x4a, 0x8e, 0xd9, 0x1, 0x17, 0xb5, 0x5c, 0x42, 0xba}; + uint8_t bytesprops3[] = {0xd2, 0x5f, 0xa, 0x53, 0x1a, 0xdb, 0xd9, 0x50, 0x39, 0x9c, 0xbc, + 0xc0, 0xbb, 0xd1, 0xb1, 0x9, 0x2, 0x22, 0x37, 0x4e, 0xcb}; + uint8_t bytesprops5[] = {0xbc, 0x7e, 0xb3, 0x32, 0x7a, 0x82, 0x83, 0x4a, 0xe, 0xf4, 0xdf, 0xc9, 0xda}; + uint8_t bytesprops6[] = {0x63, 0x2e, 0xd1, 0x7f, 0x5c, 0xd0, 0xc2, 0xea, 0x4d}; + uint8_t bytesprops7[] = {0xfe, 0x7b, 0x53, 0x9e, 0xc3, 0xb1, 0xdc, 0x46, 0xef, 0xe8, + 0x61, 0xad, 0xee, 0x41, 0x7a, 0xae, 0x7e, 0xb0, 0x1b}; + uint8_t bytesprops8[] = {0xf7, 0x69, 0x84, 0xc6, 0x29, 0x9a, 0x77, 0xa, 0x6f, 0x2a, 0x86, 0x70, + 0x6c, 0x2f, 0xd3, 0x95, 0xe0, 0x5c, 0x7, 0x9d, 0xfc, 0x7c, 0x92, 0xc5}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 108}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {11, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {6, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 148}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {6, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 20672}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {21, (char*)&bytesprops3}, .v = {11, (char*)&bytesprops4}}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {13, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {9, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 31572}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {19, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {24, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 26929}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 94}}, + }; + + lwmqtt_properties_t props = {14, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, 0, 13802, 137, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 13802 137 [PropPayloadFormatIndicator 108,PropCorrelationData +// "2H\163\240\f7]\227\184\tY",PropReasonString "\197\158\221\201\&31",PropPayloadFormatIndicator +// 148,PropResponseInformation "~wQo\ETX\ETX",PropReceiveMaximum 20672,PropUserProperty +// "\210_\nS\SUB\219\217P9\156\188\192\187\209\177\t\STX\"7N\203" +// "\218\233J\142\217\SOH\ETB\181\\B\186",PropServerReference +// "\188~\179\&2z\130\131J\SO\244\223\201\218",PropAssignedClientIdentifier +// "c.\209\DEL\\\208\194\234M",PropMessageExpiryInterval 31572,PropContentType +// "\254{S\158\195\177\220F\239\232a\173\238Az\174~\176\ESC",PropServerReference +// "\247i\132\198)\154w\no*\134pl/\211\149\224\\\a\157\252|\146\197",PropMessageExpiryInterval +// 26929,PropSharedSubscriptionAvailable 94]) +TEST(PubACKCOMP5QCTest, Decode9) { + uint8_t pkt[] = {0x70, 0xaa, 0x1, 0x35, 0xea, 0x89, 0xa5, 0x1, 0x1, 0x6c, 0x9, 0x0, 0xb, 0x32, 0x48, 0xa3, + 0xf0, 0xc, 0x37, 0x5d, 0xe3, 0xb8, 0x9, 0x59, 0x1f, 0x0, 0x6, 0xc5, 0x9e, 0xdd, 0xc9, 0x33, + 0x31, 0x1, 0x94, 0x1a, 0x0, 0x6, 0x7e, 0x77, 0x51, 0x6f, 0x3, 0x3, 0x21, 0x50, 0xc0, 0x26, + 0x0, 0x15, 0xd2, 0x5f, 0xa, 0x53, 0x1a, 0xdb, 0xd9, 0x50, 0x39, 0x9c, 0xbc, 0xc0, 0xbb, 0xd1, + 0xb1, 0x9, 0x2, 0x22, 0x37, 0x4e, 0xcb, 0x0, 0xb, 0xda, 0xe9, 0x4a, 0x8e, 0xd9, 0x1, 0x17, + 0xb5, 0x5c, 0x42, 0xba, 0x1c, 0x0, 0xd, 0xbc, 0x7e, 0xb3, 0x32, 0x7a, 0x82, 0x83, 0x4a, 0xe, + 0xf4, 0xdf, 0xc9, 0xda, 0x12, 0x0, 0x9, 0x63, 0x2e, 0xd1, 0x7f, 0x5c, 0xd0, 0xc2, 0xea, 0x4d, + 0x2, 0x0, 0x0, 0x7b, 0x54, 0x3, 0x0, 0x13, 0xfe, 0x7b, 0x53, 0x9e, 0xc3, 0xb1, 0xdc, 0x46, + 0xef, 0xe8, 0x61, 0xad, 0xee, 0x41, 0x7a, 0xae, 0x7e, 0xb0, 0x1b, 0x1c, 0x0, 0x18, 0xf7, 0x69, + 0x84, 0xc6, 0x29, 0x9a, 0x77, 0xa, 0x6f, 0x2a, 0x86, 0x70, 0x6c, 0x2f, 0xd3, 0x95, 0xe0, 0x5c, + 0x7, 0x9d, 0xfc, 0x7c, 0x92, 0xc5, 0x2, 0x0, 0x0, 0x69, 0x31, 0x2a, 0x5e}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 13802); + EXPECT_EQ(status, 137); +} + +// REC (PubREC 16335 74 [PropResponseTopic "c\205Wo\244w",PropMessageExpiryInterval 12785,PropUserProperty +// "\213\252\138\142\162\159m9\DC3\SYNm\b,-\255$\143" +// "\244*\SOHw*\216\224\178\n\252\135\193\162%\150\202LZe",PropWildcardSubscriptionAvailable 235,PropUserProperty "\220" +// "\251\246O\SOi\189\128\148\145\128h\208\246a\144\tR\236J\144\175g\170\153_\ETX\206\158",PropTopicAliasMaximum +// 9337,PropSharedSubscriptionAvailable 21,PropServerReference +// "\211s\219\134\133jV*{\208\164\137\210\227\bi",PropSessionExpiryInterval 19679,PropMessageExpiryInterval +// 24758,PropMaximumPacketSize 17805,PropSubscriptionIdentifierAvailable 130,PropSharedSubscriptionAvailable +// 236,PropAuthenticationData "\158\SUB8?F\168",PropRequestProblemInformation 113,PropPayloadFormatIndicator +// 154,PropServerReference +// "\142\167\203h{\177\139\250\204\216\CAN\235X\200\234\209\244#\204\215\246/\222\153\219\212\165\135@",PropResponseInformation +// "w\t\202\177\DC2Ek\235\133\201\160\225",PropAssignedClientIdentifier +// "\222\238\SOH\192f\209.h\ACK?\240\158\210\&0\SYN\a\207\160\227Z\"r\DC13S",PropServerKeepAlive +// 17214,PropMaximumPacketSize 27100,PropReasonString "\194\151t\DEL\178{\162w",PropContentType +// "*U0+\206C(\213\ETB\186W\RS\181\249X\190",PropTopicAlias 27640,PropMessageExpiryInterval 9585,PropReasonString +// ":\SO\192W\180#",PropRequestResponseInformation 233]) +TEST(PubACKREC5QCTest, Encode10) { + uint8_t pkt[] = {0x50, 0x9c, 0x2, 0x3f, 0xcf, 0x4a, 0x97, 0x2, 0x8, 0x0, 0x6, 0x63, 0xcd, 0x57, 0x6f, 0xf4, 0x77, + 0x2, 0x0, 0x0, 0x31, 0xf1, 0x26, 0x0, 0x11, 0xd5, 0xfc, 0x8a, 0x8e, 0xa2, 0x9f, 0x6d, 0x39, 0x13, + 0x16, 0x6d, 0x8, 0x2c, 0x2d, 0xff, 0x24, 0x8f, 0x0, 0x13, 0xf4, 0x2a, 0x1, 0x77, 0x2a, 0xd8, 0xe0, + 0xb2, 0xa, 0xfc, 0x87, 0xc1, 0xa2, 0x25, 0x96, 0xca, 0x4c, 0x5a, 0x65, 0x28, 0xeb, 0x26, 0x0, 0x1, + 0xdc, 0x0, 0x1c, 0xfb, 0xf6, 0x4f, 0xe, 0x69, 0xbd, 0x80, 0x94, 0x91, 0x80, 0x68, 0xd0, 0xf6, 0x61, + 0x90, 0x9, 0x52, 0xec, 0x4a, 0x90, 0xaf, 0x67, 0xaa, 0x99, 0x5f, 0x3, 0xce, 0x9e, 0x22, 0x24, 0x79, + 0x2a, 0x15, 0x1c, 0x0, 0x10, 0xd3, 0x73, 0xdb, 0x86, 0x85, 0x6a, 0x56, 0x2a, 0x7b, 0xd0, 0xa4, 0x89, + 0xd2, 0xe3, 0x8, 0x69, 0x11, 0x0, 0x0, 0x4c, 0xdf, 0x2, 0x0, 0x0, 0x60, 0xb6, 0x27, 0x0, 0x0, + 0x45, 0x8d, 0x29, 0x82, 0x2a, 0xec, 0x16, 0x0, 0x6, 0x9e, 0x1a, 0x38, 0x3f, 0x46, 0xa8, 0x17, 0x71, + 0x1, 0x9a, 0x1c, 0x0, 0x1d, 0x8e, 0xa7, 0xcb, 0x68, 0x7b, 0xb1, 0x8b, 0xfa, 0xcc, 0xd8, 0x18, 0xeb, + 0x58, 0xc8, 0xea, 0xd1, 0xf4, 0x23, 0xcc, 0xd7, 0xf6, 0x2f, 0xde, 0x99, 0xdb, 0xd4, 0xa5, 0x87, 0x40, + 0x1a, 0x0, 0xc, 0x77, 0x9, 0xca, 0xb1, 0x12, 0x45, 0x6b, 0xeb, 0x85, 0xc9, 0xa0, 0xe1, 0x12, 0x0, + 0x19, 0xde, 0xee, 0x1, 0xc0, 0x66, 0xd1, 0x2e, 0x68, 0x6, 0x3f, 0xf0, 0x9e, 0xd2, 0x30, 0x16, 0x7, + 0xcf, 0xa0, 0xe3, 0x5a, 0x22, 0x72, 0x11, 0x33, 0x53, 0x13, 0x43, 0x3e, 0x27, 0x0, 0x0, 0x69, 0xdc, + 0x1f, 0x0, 0x8, 0xc2, 0x97, 0x74, 0x7f, 0xb2, 0x7b, 0xa2, 0x77, 0x3, 0x0, 0x10, 0x2a, 0x55, 0x30, + 0x2b, 0xce, 0x43, 0x28, 0xd5, 0x17, 0xba, 0x57, 0x1e, 0xb5, 0xf9, 0x58, 0xbe, 0x23, 0x6b, 0xf8, 0x2, + 0x0, 0x0, 0x25, 0x71, 0x1f, 0x0, 0x6, 0x3a, 0xe, 0xc0, 0x57, 0xb4, 0x23, 0x19, 0xe9}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x63, 0xcd, 0x57, 0x6f, 0xf4, 0x77}; + uint8_t bytesprops2[] = {0xf4, 0x2a, 0x1, 0x77, 0x2a, 0xd8, 0xe0, 0xb2, 0xa, 0xfc, + 0x87, 0xc1, 0xa2, 0x25, 0x96, 0xca, 0x4c, 0x5a, 0x65}; + uint8_t bytesprops1[] = {0xd5, 0xfc, 0x8a, 0x8e, 0xa2, 0x9f, 0x6d, 0x39, 0x13, + 0x16, 0x6d, 0x8, 0x2c, 0x2d, 0xff, 0x24, 0x8f}; + uint8_t bytesprops4[] = {0xfb, 0xf6, 0x4f, 0xe, 0x69, 0xbd, 0x80, 0x94, 0x91, 0x80, 0x68, 0xd0, 0xf6, 0x61, + 0x90, 0x9, 0x52, 0xec, 0x4a, 0x90, 0xaf, 0x67, 0xaa, 0x99, 0x5f, 0x3, 0xce, 0x9e}; + uint8_t bytesprops3[] = {0xdc}; + uint8_t bytesprops5[] = {0xd3, 0x73, 0xdb, 0x86, 0x85, 0x6a, 0x56, 0x2a, + 0x7b, 0xd0, 0xa4, 0x89, 0xd2, 0xe3, 0x8, 0x69}; + uint8_t bytesprops6[] = {0x9e, 0x1a, 0x38, 0x3f, 0x46, 0xa8}; + uint8_t bytesprops7[] = {0x8e, 0xa7, 0xcb, 0x68, 0x7b, 0xb1, 0x8b, 0xfa, 0xcc, 0xd8, 0x18, 0xeb, 0x58, 0xc8, 0xea, + 0xd1, 0xf4, 0x23, 0xcc, 0xd7, 0xf6, 0x2f, 0xde, 0x99, 0xdb, 0xd4, 0xa5, 0x87, 0x40}; + uint8_t bytesprops8[] = {0x77, 0x9, 0xca, 0xb1, 0x12, 0x45, 0x6b, 0xeb, 0x85, 0xc9, 0xa0, 0xe1}; + uint8_t bytesprops9[] = {0xde, 0xee, 0x1, 0xc0, 0x66, 0xd1, 0x2e, 0x68, 0x6, 0x3f, 0xf0, 0x9e, 0xd2, + 0x30, 0x16, 0x7, 0xcf, 0xa0, 0xe3, 0x5a, 0x22, 0x72, 0x11, 0x33, 0x53}; + uint8_t bytesprops10[] = {0xc2, 0x97, 0x74, 0x7f, 0xb2, 0x7b, 0xa2, 0x77}; + uint8_t bytesprops11[] = {0x2a, 0x55, 0x30, 0x2b, 0xce, 0x43, 0x28, 0xd5, + 0x17, 0xba, 0x57, 0x1e, 0xb5, 0xf9, 0x58, 0xbe}; + uint8_t bytesprops12[] = {0x3a, 0xe, 0xc0, 0x57, 0xb4, 0x23}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)8, .value = {.str = {6, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 12785}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {17, (char*)&bytesprops1}, .v = {19, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 235}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {1, (char*)&bytesprops3}, .v = {28, (char*)&bytesprops4}}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 9337}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 21}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {16, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 19679}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 24758}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 17805}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 130}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 236}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {6, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 113}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 154}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {29, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {12, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {25, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 17214}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 27100}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {8, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {16, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 27640}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 9585}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {6, (char*)&bytesprops12}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 233}}, + }; + + lwmqtt_properties_t props = {27, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREC_PACKET, 0, 16335, 74, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REC (PubREC 16335 74 [PropResponseTopic "c\205Wo\244w",PropMessageExpiryInterval 12785,PropUserProperty +// "\213\252\138\142\162\159m9\DC3\SYNm\b,-\255$\143" +// "\244*\SOHw*\216\224\178\n\252\135\193\162%\150\202LZe",PropWildcardSubscriptionAvailable 235,PropUserProperty "\220" +// "\251\246O\SOi\189\128\148\145\128h\208\246a\144\tR\236J\144\175g\170\153_\ETX\206\158",PropTopicAliasMaximum +// 9337,PropSharedSubscriptionAvailable 21,PropServerReference +// "\211s\219\134\133jV*{\208\164\137\210\227\bi",PropSessionExpiryInterval 19679,PropMessageExpiryInterval +// 24758,PropMaximumPacketSize 17805,PropSubscriptionIdentifierAvailable 130,PropSharedSubscriptionAvailable +// 236,PropAuthenticationData "\158\SUB8?F\168",PropRequestProblemInformation 113,PropPayloadFormatIndicator +// 154,PropServerReference +// "\142\167\203h{\177\139\250\204\216\CAN\235X\200\234\209\244#\204\215\246/\222\153\219\212\165\135@",PropResponseInformation +// "w\t\202\177\DC2Ek\235\133\201\160\225",PropAssignedClientIdentifier +// "\222\238\SOH\192f\209.h\ACK?\240\158\210\&0\SYN\a\207\160\227Z\"r\DC13S",PropServerKeepAlive +// 17214,PropMaximumPacketSize 27100,PropReasonString "\194\151t\DEL\178{\162w",PropContentType +// "*U0+\206C(\213\ETB\186W\RS\181\249X\190",PropTopicAlias 27640,PropMessageExpiryInterval 9585,PropReasonString +// ":\SO\192W\180#",PropRequestResponseInformation 233]) +TEST(PubACKREC5QCTest, Decode10) { + uint8_t pkt[] = {0x50, 0x9c, 0x2, 0x3f, 0xcf, 0x4a, 0x97, 0x2, 0x8, 0x0, 0x6, 0x63, 0xcd, 0x57, 0x6f, 0xf4, 0x77, + 0x2, 0x0, 0x0, 0x31, 0xf1, 0x26, 0x0, 0x11, 0xd5, 0xfc, 0x8a, 0x8e, 0xa2, 0x9f, 0x6d, 0x39, 0x13, + 0x16, 0x6d, 0x8, 0x2c, 0x2d, 0xff, 0x24, 0x8f, 0x0, 0x13, 0xf4, 0x2a, 0x1, 0x77, 0x2a, 0xd8, 0xe0, + 0xb2, 0xa, 0xfc, 0x87, 0xc1, 0xa2, 0x25, 0x96, 0xca, 0x4c, 0x5a, 0x65, 0x28, 0xeb, 0x26, 0x0, 0x1, + 0xdc, 0x0, 0x1c, 0xfb, 0xf6, 0x4f, 0xe, 0x69, 0xbd, 0x80, 0x94, 0x91, 0x80, 0x68, 0xd0, 0xf6, 0x61, + 0x90, 0x9, 0x52, 0xec, 0x4a, 0x90, 0xaf, 0x67, 0xaa, 0x99, 0x5f, 0x3, 0xce, 0x9e, 0x22, 0x24, 0x79, + 0x2a, 0x15, 0x1c, 0x0, 0x10, 0xd3, 0x73, 0xdb, 0x86, 0x85, 0x6a, 0x56, 0x2a, 0x7b, 0xd0, 0xa4, 0x89, + 0xd2, 0xe3, 0x8, 0x69, 0x11, 0x0, 0x0, 0x4c, 0xdf, 0x2, 0x0, 0x0, 0x60, 0xb6, 0x27, 0x0, 0x0, + 0x45, 0x8d, 0x29, 0x82, 0x2a, 0xec, 0x16, 0x0, 0x6, 0x9e, 0x1a, 0x38, 0x3f, 0x46, 0xa8, 0x17, 0x71, + 0x1, 0x9a, 0x1c, 0x0, 0x1d, 0x8e, 0xa7, 0xcb, 0x68, 0x7b, 0xb1, 0x8b, 0xfa, 0xcc, 0xd8, 0x18, 0xeb, + 0x58, 0xc8, 0xea, 0xd1, 0xf4, 0x23, 0xcc, 0xd7, 0xf6, 0x2f, 0xde, 0x99, 0xdb, 0xd4, 0xa5, 0x87, 0x40, + 0x1a, 0x0, 0xc, 0x77, 0x9, 0xca, 0xb1, 0x12, 0x45, 0x6b, 0xeb, 0x85, 0xc9, 0xa0, 0xe1, 0x12, 0x0, + 0x19, 0xde, 0xee, 0x1, 0xc0, 0x66, 0xd1, 0x2e, 0x68, 0x6, 0x3f, 0xf0, 0x9e, 0xd2, 0x30, 0x16, 0x7, + 0xcf, 0xa0, 0xe3, 0x5a, 0x22, 0x72, 0x11, 0x33, 0x53, 0x13, 0x43, 0x3e, 0x27, 0x0, 0x0, 0x69, 0xdc, + 0x1f, 0x0, 0x8, 0xc2, 0x97, 0x74, 0x7f, 0xb2, 0x7b, 0xa2, 0x77, 0x3, 0x0, 0x10, 0x2a, 0x55, 0x30, + 0x2b, 0xce, 0x43, 0x28, 0xd5, 0x17, 0xba, 0x57, 0x1e, 0xb5, 0xf9, 0x58, 0xbe, 0x23, 0x6b, 0xf8, 0x2, + 0x0, 0x0, 0x25, 0x71, 0x1f, 0x0, 0x6, 0x3a, 0xe, 0xc0, 0x57, 0xb4, 0x23, 0x19, 0xe9}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREC_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 16335); + EXPECT_EQ(status, 74); +} + +// COMP (PubCOMP 5460 148 [PropRetainAvailable 100,PropSubscriptionIdentifier 13,PropMaximumQoS 79,PropRetainAvailable +// 87,PropServerReference "\SYN{\196c\225J3\STX\199zBA\128\134\135\USpTL\213|@F",PropRequestResponseInformation +// 114,PropSessionExpiryInterval 4868,PropTopicAlias 4581,PropServerReference "\253\151\&9\ETX +// \249\ETX\140\229\STX\196U\232\&7\174]hV\128RA",PropContentType "\n\145F\171\162>"]) +TEST(PubACKCOMP5QCTest, Encode11) { + uint8_t pkt[] = {0x70, 0x51, 0x15, 0x54, 0x94, 0x4d, 0x25, 0x64, 0xb, 0xd, 0x24, 0x4f, 0x25, 0x57, 0x1c, 0x0, 0x17, + 0x16, 0x7b, 0xc4, 0x63, 0xe1, 0x4a, 0x33, 0x2, 0xc7, 0x7a, 0x42, 0x41, 0x80, 0x86, 0x87, 0x1f, 0x70, + 0x54, 0x4c, 0xd5, 0x7c, 0x40, 0x46, 0x19, 0x72, 0x11, 0x0, 0x0, 0x13, 0x4, 0x23, 0x11, 0xe5, 0x1c, + 0x0, 0x15, 0xfd, 0x97, 0x39, 0x3, 0x20, 0xf9, 0x3, 0x8c, 0xe5, 0x2, 0xc4, 0x55, 0xe8, 0x37, 0xae, + 0x5d, 0x68, 0x56, 0x80, 0x52, 0x41, 0x3, 0x0, 0x6, 0xa, 0x91, 0x46, 0xab, 0xa2, 0x3e}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x16, 0x7b, 0xc4, 0x63, 0xe1, 0x4a, 0x33, 0x2, 0xc7, 0x7a, 0x42, 0x41, + 0x80, 0x86, 0x87, 0x1f, 0x70, 0x54, 0x4c, 0xd5, 0x7c, 0x40, 0x46}; + uint8_t bytesprops1[] = {0xfd, 0x97, 0x39, 0x3, 0x20, 0xf9, 0x3, 0x8c, 0xe5, 0x2, 0xc4, + 0x55, 0xe8, 0x37, 0xae, 0x5d, 0x68, 0x56, 0x80, 0x52, 0x41}; + uint8_t bytesprops2[] = {0xa, 0x91, 0x46, 0xab, 0xa2, 0x3e}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 100}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 13}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 79}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 87}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {23, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 114}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 4868}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 4581}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {21, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {6, (char*)&bytesprops2}}}, + }; + + lwmqtt_properties_t props = {10, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, 0, 5460, 148, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 5460 148 [PropRetainAvailable 100,PropSubscriptionIdentifier 13,PropMaximumQoS 79,PropRetainAvailable +// 87,PropServerReference "\SYN{\196c\225J3\STX\199zBA\128\134\135\USpTL\213|@F",PropRequestResponseInformation +// 114,PropSessionExpiryInterval 4868,PropTopicAlias 4581,PropServerReference "\253\151\&9\ETX +// \249\ETX\140\229\STX\196U\232\&7\174]hV\128RA",PropContentType "\n\145F\171\162>"]) +TEST(PubACKCOMP5QCTest, Decode11) { + uint8_t pkt[] = {0x70, 0x51, 0x15, 0x54, 0x94, 0x4d, 0x25, 0x64, 0xb, 0xd, 0x24, 0x4f, 0x25, 0x57, 0x1c, 0x0, 0x17, + 0x16, 0x7b, 0xc4, 0x63, 0xe1, 0x4a, 0x33, 0x2, 0xc7, 0x7a, 0x42, 0x41, 0x80, 0x86, 0x87, 0x1f, 0x70, + 0x54, 0x4c, 0xd5, 0x7c, 0x40, 0x46, 0x19, 0x72, 0x11, 0x0, 0x0, 0x13, 0x4, 0x23, 0x11, 0xe5, 0x1c, + 0x0, 0x15, 0xfd, 0x97, 0x39, 0x3, 0x20, 0xf9, 0x3, 0x8c, 0xe5, 0x2, 0xc4, 0x55, 0xe8, 0x37, 0xae, + 0x5d, 0x68, 0x56, 0x80, 0x52, 0x41, 0x3, 0x0, 0x6, 0xa, 0x91, 0x46, 0xab, 0xa2, 0x3e}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 5460); + EXPECT_EQ(status, 148); +} + +// COMP (PubCOMP 15537 240 []) +TEST(PubACKCOMP5QCTest, Encode12) { + uint8_t pkt[] = {0x70, 0x3, 0x3c, 0xb1, 0xf0}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, 0, 15537, 240, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 15537 240 []) +TEST(PubACKCOMP5QCTest, Decode12) { + uint8_t pkt[] = {0x70, 0x3, 0x3c, 0xb1, 0xf0}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 15537); + EXPECT_EQ(status, 240); +} + +// ACK (PubACK 28091 75 [PropRequestResponseInformation 147,PropReceiveMaximum 17435,PropTopicAliasMaximum +// 16908,PropReceiveMaximum 12343,PropMaximumPacketSize 29709,PropSessionExpiryInterval +// 15481,PropWildcardSubscriptionAvailable 79,PropServerKeepAlive 16043,PropResponseInformation +// "_\SYNZ4\SO*p\"\FSO\185cv\138"]) +TEST(PubACKACK5QCTest, Encode13) { + uint8_t pkt[] = {0x40, 0x2f, 0x6d, 0xbb, 0x4b, 0x2b, 0x19, 0x93, 0x21, 0x44, 0x1b, 0x22, 0x42, 0xc, 0x21, 0x30, 0x37, + 0x27, 0x0, 0x0, 0x74, 0xd, 0x11, 0x0, 0x0, 0x3c, 0x79, 0x28, 0x4f, 0x13, 0x3e, 0xab, 0x1a, 0x0, + 0xe, 0x5f, 0x16, 0x5a, 0x34, 0xe, 0x2a, 0x70, 0x22, 0x1c, 0x4f, 0xb9, 0x63, 0x76, 0x8a}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x5f, 0x16, 0x5a, 0x34, 0xe, 0x2a, 0x70, 0x22, 0x1c, 0x4f, 0xb9, 0x63, 0x76, 0x8a}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 147}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 17435}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 16908}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 12343}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 29709}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 15481}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 79}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 16043}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {14, (char*)&bytesprops0}}}, + }; + + lwmqtt_properties_t props = {9, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBACK_PACKET, 0, 28091, 75, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ACK (PubACK 28091 75 [PropRequestResponseInformation 147,PropReceiveMaximum 17435,PropTopicAliasMaximum +// 16908,PropReceiveMaximum 12343,PropMaximumPacketSize 29709,PropSessionExpiryInterval +// 15481,PropWildcardSubscriptionAvailable 79,PropServerKeepAlive 16043,PropResponseInformation +// "_\SYNZ4\SO*p\"\FSO\185cv\138"]) +TEST(PubACKACK5QCTest, Decode13) { + uint8_t pkt[] = {0x40, 0x2f, 0x6d, 0xbb, 0x4b, 0x2b, 0x19, 0x93, 0x21, 0x44, 0x1b, 0x22, 0x42, 0xc, 0x21, 0x30, 0x37, + 0x27, 0x0, 0x0, 0x74, 0xd, 0x11, 0x0, 0x0, 0x3c, 0x79, 0x28, 0x4f, 0x13, 0x3e, 0xab, 0x1a, 0x0, + 0xe, 0x5f, 0x16, 0x5a, 0x34, 0xe, 0x2a, 0x70, 0x22, 0x1c, 0x4f, 0xb9, 0x63, 0x76, 0x8a}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBACK_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 28091); + EXPECT_EQ(status, 75); +} + +// REL (PubREL 10160 80 [PropContentType +// "\200\206\164\247+\166z<\214\225\rh\224\219p\223\145\US\161,\234\194~\221x\181\ETX,\209v",PropAuthenticationData +// "\244Q\DC2\139\f\196\207\DC3*\210\237\210\GS\185\162\176\169\171\161\fdY\153\253t\156\133\DC3",PropResponseTopic +// "\182\210\179\213\155\218\176\129",PropResponseInformation +// "\179\132\165f\195\189\133\212\&3\149\161\170\155\244X\\O\RS\246\&4\234\165\233)4\147\DC4\129D\DC3",PropMessageExpiryInterval +// 29734,PropSessionExpiryInterval 29184,PropSubscriptionIdentifier 22,PropAssignedClientIdentifier " +// \210\204\DLE\224",PropPayloadFormatIndicator 180,PropRequestResponseInformation 199,PropContentType +// "\255\150",PropMessageExpiryInterval 30373,PropResponseInformation +// "\ESC\177\247\183\137d4\163;u\208\185I\ENQ\197\240\170",PropAssignedClientIdentifier +// "\211\153\USU",PropAuthenticationMethod "e\135\EOT\189M\251",PropTopicAliasMaximum +// 16386,PropSubscriptionIdentifierAvailable 54,PropSessionExpiryInterval 5264,PropContentType +// "T\232\129wV",PropResponseTopic "S\140\234G4\133\208)\233\t6;\148\235h",PropServerKeepAlive 16844]) +TEST(PubACKREL5QCTest, Encode14) { + uint8_t pkt[] = { + 0x62, 0xde, 0x1, 0x27, 0xb0, 0x50, 0xd9, 0x1, 0x3, 0x0, 0x1e, 0xc8, 0xce, 0xa4, 0xf7, 0x2b, 0xa6, 0x7a, 0x3c, + 0xd6, 0xe1, 0xd, 0x68, 0xe0, 0xdb, 0x70, 0xdf, 0x91, 0x1f, 0xa1, 0x2c, 0xea, 0xc2, 0x7e, 0xdd, 0x78, 0xb5, 0x3, + 0x2c, 0xd1, 0x76, 0x16, 0x0, 0x1c, 0xf4, 0x51, 0x12, 0x8b, 0xc, 0xc4, 0xcf, 0x13, 0x2a, 0xd2, 0xed, 0xd2, 0x1d, + 0xb9, 0xa2, 0xb0, 0xa9, 0xab, 0xa1, 0xc, 0x64, 0x59, 0x99, 0xfd, 0x74, 0x9c, 0x85, 0x13, 0x8, 0x0, 0x8, 0xb6, + 0xd2, 0xb3, 0xd5, 0x9b, 0xda, 0xb0, 0x81, 0x1a, 0x0, 0x1e, 0xb3, 0x84, 0xa5, 0x66, 0xc3, 0xbd, 0x85, 0xd4, 0x33, + 0x95, 0xa1, 0xaa, 0x9b, 0xf4, 0x58, 0x5c, 0x4f, 0x1e, 0xf6, 0x34, 0xea, 0xa5, 0xe9, 0x29, 0x34, 0x93, 0x14, 0x81, + 0x44, 0x13, 0x2, 0x0, 0x0, 0x74, 0x26, 0x11, 0x0, 0x0, 0x72, 0x0, 0xb, 0x16, 0x12, 0x0, 0x5, 0x20, 0xd2, + 0xcc, 0x10, 0xe0, 0x1, 0xb4, 0x19, 0xc7, 0x3, 0x0, 0x2, 0xff, 0x96, 0x2, 0x0, 0x0, 0x76, 0xa5, 0x1a, 0x0, + 0x11, 0x1b, 0xb1, 0xf7, 0xb7, 0x89, 0x64, 0x34, 0xa3, 0x3b, 0x75, 0xd0, 0xb9, 0x49, 0x5, 0xc5, 0xf0, 0xaa, 0x12, + 0x0, 0x4, 0xd3, 0x99, 0x1f, 0x55, 0x15, 0x0, 0x6, 0x65, 0x87, 0x4, 0xbd, 0x4d, 0xfb, 0x22, 0x40, 0x2, 0x29, + 0x36, 0x11, 0x0, 0x0, 0x14, 0x90, 0x3, 0x0, 0x5, 0x54, 0xe8, 0x81, 0x77, 0x56, 0x8, 0x0, 0xf, 0x53, 0x8c, + 0xea, 0x47, 0x34, 0x85, 0xd0, 0x29, 0xe9, 0x9, 0x36, 0x3b, 0x94, 0xeb, 0x68, 0x13, 0x41, 0xcc}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0xc8, 0xce, 0xa4, 0xf7, 0x2b, 0xa6, 0x7a, 0x3c, 0xd6, 0xe1, 0xd, 0x68, 0xe0, 0xdb, 0x70, + 0xdf, 0x91, 0x1f, 0xa1, 0x2c, 0xea, 0xc2, 0x7e, 0xdd, 0x78, 0xb5, 0x3, 0x2c, 0xd1, 0x76}; + uint8_t bytesprops1[] = {0xf4, 0x51, 0x12, 0x8b, 0xc, 0xc4, 0xcf, 0x13, 0x2a, 0xd2, 0xed, 0xd2, 0x1d, 0xb9, + 0xa2, 0xb0, 0xa9, 0xab, 0xa1, 0xc, 0x64, 0x59, 0x99, 0xfd, 0x74, 0x9c, 0x85, 0x13}; + uint8_t bytesprops2[] = {0xb6, 0xd2, 0xb3, 0xd5, 0x9b, 0xda, 0xb0, 0x81}; + uint8_t bytesprops3[] = {0xb3, 0x84, 0xa5, 0x66, 0xc3, 0xbd, 0x85, 0xd4, 0x33, 0x95, 0xa1, 0xaa, 0x9b, 0xf4, 0x58, + 0x5c, 0x4f, 0x1e, 0xf6, 0x34, 0xea, 0xa5, 0xe9, 0x29, 0x34, 0x93, 0x14, 0x81, 0x44, 0x13}; + uint8_t bytesprops4[] = {0x20, 0xd2, 0xcc, 0x10, 0xe0}; + uint8_t bytesprops5[] = {0xff, 0x96}; + uint8_t bytesprops6[] = {0x1b, 0xb1, 0xf7, 0xb7, 0x89, 0x64, 0x34, 0xa3, 0x3b, + 0x75, 0xd0, 0xb9, 0x49, 0x5, 0xc5, 0xf0, 0xaa}; + uint8_t bytesprops7[] = {0xd3, 0x99, 0x1f, 0x55}; + uint8_t bytesprops8[] = {0x65, 0x87, 0x4, 0xbd, 0x4d, 0xfb}; + uint8_t bytesprops9[] = {0x54, 0xe8, 0x81, 0x77, 0x56}; + uint8_t bytesprops10[] = {0x53, 0x8c, 0xea, 0x47, 0x34, 0x85, 0xd0, 0x29, 0xe9, 0x9, 0x36, 0x3b, 0x94, 0xeb, 0x68}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)3, .value = {.str = {30, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {28, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {8, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {30, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 29734}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 29184}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 22}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {5, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 180}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 199}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {2, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 30373}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {17, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {4, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {6, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 16386}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 54}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 5264}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {5, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {15, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 16844}}, + }; + + lwmqtt_properties_t props = {21, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 10160, 80, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 10160 80 [PropContentType +// "\200\206\164\247+\166z<\214\225\rh\224\219p\223\145\US\161,\234\194~\221x\181\ETX,\209v",PropAuthenticationData +// "\244Q\DC2\139\f\196\207\DC3*\210\237\210\GS\185\162\176\169\171\161\fdY\153\253t\156\133\DC3",PropResponseTopic +// "\182\210\179\213\155\218\176\129",PropResponseInformation +// "\179\132\165f\195\189\133\212\&3\149\161\170\155\244X\\O\RS\246\&4\234\165\233)4\147\DC4\129D\DC3",PropMessageExpiryInterval +// 29734,PropSessionExpiryInterval 29184,PropSubscriptionIdentifier 22,PropAssignedClientIdentifier " +// \210\204\DLE\224",PropPayloadFormatIndicator 180,PropRequestResponseInformation 199,PropContentType +// "\255\150",PropMessageExpiryInterval 30373,PropResponseInformation +// "\ESC\177\247\183\137d4\163;u\208\185I\ENQ\197\240\170",PropAssignedClientIdentifier +// "\211\153\USU",PropAuthenticationMethod "e\135\EOT\189M\251",PropTopicAliasMaximum +// 16386,PropSubscriptionIdentifierAvailable 54,PropSessionExpiryInterval 5264,PropContentType +// "T\232\129wV",PropResponseTopic "S\140\234G4\133\208)\233\t6;\148\235h",PropServerKeepAlive 16844]) +TEST(PubACKREL5QCTest, Decode14) { + uint8_t pkt[] = { + 0x62, 0xde, 0x1, 0x27, 0xb0, 0x50, 0xd9, 0x1, 0x3, 0x0, 0x1e, 0xc8, 0xce, 0xa4, 0xf7, 0x2b, 0xa6, 0x7a, 0x3c, + 0xd6, 0xe1, 0xd, 0x68, 0xe0, 0xdb, 0x70, 0xdf, 0x91, 0x1f, 0xa1, 0x2c, 0xea, 0xc2, 0x7e, 0xdd, 0x78, 0xb5, 0x3, + 0x2c, 0xd1, 0x76, 0x16, 0x0, 0x1c, 0xf4, 0x51, 0x12, 0x8b, 0xc, 0xc4, 0xcf, 0x13, 0x2a, 0xd2, 0xed, 0xd2, 0x1d, + 0xb9, 0xa2, 0xb0, 0xa9, 0xab, 0xa1, 0xc, 0x64, 0x59, 0x99, 0xfd, 0x74, 0x9c, 0x85, 0x13, 0x8, 0x0, 0x8, 0xb6, + 0xd2, 0xb3, 0xd5, 0x9b, 0xda, 0xb0, 0x81, 0x1a, 0x0, 0x1e, 0xb3, 0x84, 0xa5, 0x66, 0xc3, 0xbd, 0x85, 0xd4, 0x33, + 0x95, 0xa1, 0xaa, 0x9b, 0xf4, 0x58, 0x5c, 0x4f, 0x1e, 0xf6, 0x34, 0xea, 0xa5, 0xe9, 0x29, 0x34, 0x93, 0x14, 0x81, + 0x44, 0x13, 0x2, 0x0, 0x0, 0x74, 0x26, 0x11, 0x0, 0x0, 0x72, 0x0, 0xb, 0x16, 0x12, 0x0, 0x5, 0x20, 0xd2, + 0xcc, 0x10, 0xe0, 0x1, 0xb4, 0x19, 0xc7, 0x3, 0x0, 0x2, 0xff, 0x96, 0x2, 0x0, 0x0, 0x76, 0xa5, 0x1a, 0x0, + 0x11, 0x1b, 0xb1, 0xf7, 0xb7, 0x89, 0x64, 0x34, 0xa3, 0x3b, 0x75, 0xd0, 0xb9, 0x49, 0x5, 0xc5, 0xf0, 0xaa, 0x12, + 0x0, 0x4, 0xd3, 0x99, 0x1f, 0x55, 0x15, 0x0, 0x6, 0x65, 0x87, 0x4, 0xbd, 0x4d, 0xfb, 0x22, 0x40, 0x2, 0x29, + 0x36, 0x11, 0x0, 0x0, 0x14, 0x90, 0x3, 0x0, 0x5, 0x54, 0xe8, 0x81, 0x77, 0x56, 0x8, 0x0, 0xf, 0x53, 0x8c, + 0xea, 0x47, 0x34, 0x85, 0xd0, 0x29, 0xe9, 0x9, 0x36, 0x3b, 0x94, 0xeb, 0x68, 0x13, 0x41, 0xcc}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 10160); + EXPECT_EQ(status, 80); +} + +// REL (PubREL 30332 194 [PropContentType "0\157\150N +// \243|\175\SOH\250{\228\134\193s\189\133ub4\131i\197\207\203",PropMaximumQoS 240,PropSessionExpiryInterval +// 26171,PropReasonString +// "\152!X!S\217\161\ENQW7\248\168\222\231\227\174\201O\SUB<\144\&7\163\154\175Y\ETB\SI",PropReceiveMaximum +// 22904,PropSessionExpiryInterval 18294,PropTopicAlias 25799,PropResponseInformation +// "\198)\141\178\229\195\231(bp",PropServerReference "C\153F\209\136\DC2\209\139\153\196K~",PropCorrelationData +// "\160\212\&1\220%\143yr",PropMessageExpiryInterval 10541,PropTopicAliasMaximum 20624,PropWillDelayInterval +// 32656,PropSubscriptionIdentifierAvailable 215,PropAuthenticationMethod "\220\156\160\169\208\DC16{\b\172 +// \208\213\243",PropAuthenticationMethod +// "\177\154\SUB\163\EM\237\146\201\167\222\DLE*\149\195Y\173*\183.",PropAuthenticationMethod +// "u\165\133\RSc(Tp\220\DC3\229\150\207\DEL\r\n\184\\\145\181khFBR3\212\207",PropUserProperty "Q-O" +// "+\138,*Z\193\ENQ\232L\NAK\NAKy9",PropServerReference +// "c\181^!\253JRU\231\GS\153m\146\160\SYNzT",PropMessageExpiryInterval 15091,PropMessageExpiryInterval +// 10435,PropMessageExpiryInterval 3913,PropWildcardSubscriptionAvailable 37]) +TEST(PubACKREL5QCTest, Encode15) { + uint8_t pkt[] = {0x62, 0x88, 0x2, 0x76, 0x7c, 0xc2, 0x83, 0x2, 0x3, 0x0, 0x19, 0x30, 0x9d, 0x96, 0x4e, 0x20, 0xf3, + 0x7c, 0xaf, 0x1, 0xfa, 0x7b, 0xe4, 0x86, 0xc1, 0x73, 0xbd, 0x85, 0x75, 0x62, 0x34, 0x83, 0x69, 0xc5, + 0xcf, 0xcb, 0x24, 0xf0, 0x11, 0x0, 0x0, 0x66, 0x3b, 0x1f, 0x0, 0x1c, 0x98, 0x21, 0x58, 0x21, 0x53, + 0xd9, 0xa1, 0x5, 0x57, 0x37, 0xf8, 0xa8, 0xde, 0xe7, 0xe3, 0xae, 0xc9, 0x4f, 0x1a, 0x3c, 0x90, 0x37, + 0xa3, 0x9a, 0xaf, 0x59, 0x17, 0xf, 0x21, 0x59, 0x78, 0x11, 0x0, 0x0, 0x47, 0x76, 0x23, 0x64, 0xc7, + 0x1a, 0x0, 0xa, 0xc6, 0x29, 0x8d, 0xb2, 0xe5, 0xc3, 0xe7, 0x28, 0x62, 0x70, 0x1c, 0x0, 0xc, 0x43, + 0x99, 0x46, 0xd1, 0x88, 0x12, 0xd1, 0x8b, 0x99, 0xc4, 0x4b, 0x7e, 0x9, 0x0, 0x8, 0xa0, 0xd4, 0x31, + 0xdc, 0x25, 0x8f, 0x79, 0x72, 0x2, 0x0, 0x0, 0x29, 0x2d, 0x22, 0x50, 0x90, 0x18, 0x0, 0x0, 0x7f, + 0x90, 0x29, 0xd7, 0x15, 0x0, 0xe, 0xdc, 0x9c, 0xa0, 0xa9, 0xd0, 0x11, 0x36, 0x7b, 0x8, 0xac, 0x20, + 0xd0, 0xd5, 0xf3, 0x15, 0x0, 0x13, 0xb1, 0x9a, 0x1a, 0xa3, 0x19, 0xed, 0x92, 0xc9, 0xa7, 0xde, 0x10, + 0x2a, 0x95, 0xc3, 0x59, 0xad, 0x2a, 0xb7, 0x2e, 0x15, 0x0, 0x1c, 0x75, 0xa5, 0x85, 0x1e, 0x63, 0x28, + 0x54, 0x70, 0xdc, 0x13, 0xe5, 0x96, 0xcf, 0x7f, 0xd, 0xa, 0xb8, 0x5c, 0x91, 0xb5, 0x6b, 0x68, 0x46, + 0x42, 0x52, 0x33, 0xd4, 0xcf, 0x26, 0x0, 0x3, 0x51, 0x2d, 0x4f, 0x0, 0xd, 0x2b, 0x8a, 0x2c, 0x2a, + 0x5a, 0xc1, 0x5, 0xe8, 0x4c, 0x15, 0x15, 0x79, 0x39, 0x1c, 0x0, 0x11, 0x63, 0xb5, 0x5e, 0x21, 0xfd, + 0x4a, 0x52, 0x55, 0xe7, 0x1d, 0x99, 0x6d, 0x92, 0xa0, 0x16, 0x7a, 0x54, 0x2, 0x0, 0x0, 0x3a, 0xf3, + 0x2, 0x0, 0x0, 0x28, 0xc3, 0x2, 0x0, 0x0, 0xf, 0x49, 0x28, 0x25}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x30, 0x9d, 0x96, 0x4e, 0x20, 0xf3, 0x7c, 0xaf, 0x1, 0xfa, 0x7b, 0xe4, 0x86, + 0xc1, 0x73, 0xbd, 0x85, 0x75, 0x62, 0x34, 0x83, 0x69, 0xc5, 0xcf, 0xcb}; + uint8_t bytesprops1[] = {0x98, 0x21, 0x58, 0x21, 0x53, 0xd9, 0xa1, 0x5, 0x57, 0x37, 0xf8, 0xa8, 0xde, 0xe7, + 0xe3, 0xae, 0xc9, 0x4f, 0x1a, 0x3c, 0x90, 0x37, 0xa3, 0x9a, 0xaf, 0x59, 0x17, 0xf}; + uint8_t bytesprops2[] = {0xc6, 0x29, 0x8d, 0xb2, 0xe5, 0xc3, 0xe7, 0x28, 0x62, 0x70}; + uint8_t bytesprops3[] = {0x43, 0x99, 0x46, 0xd1, 0x88, 0x12, 0xd1, 0x8b, 0x99, 0xc4, 0x4b, 0x7e}; + uint8_t bytesprops4[] = {0xa0, 0xd4, 0x31, 0xdc, 0x25, 0x8f, 0x79, 0x72}; + uint8_t bytesprops5[] = {0xdc, 0x9c, 0xa0, 0xa9, 0xd0, 0x11, 0x36, 0x7b, 0x8, 0xac, 0x20, 0xd0, 0xd5, 0xf3}; + uint8_t bytesprops6[] = {0xb1, 0x9a, 0x1a, 0xa3, 0x19, 0xed, 0x92, 0xc9, 0xa7, 0xde, + 0x10, 0x2a, 0x95, 0xc3, 0x59, 0xad, 0x2a, 0xb7, 0x2e}; + uint8_t bytesprops7[] = {0x75, 0xa5, 0x85, 0x1e, 0x63, 0x28, 0x54, 0x70, 0xdc, 0x13, 0xe5, 0x96, 0xcf, 0x7f, + 0xd, 0xa, 0xb8, 0x5c, 0x91, 0xb5, 0x6b, 0x68, 0x46, 0x42, 0x52, 0x33, 0xd4, 0xcf}; + uint8_t bytesprops9[] = {0x2b, 0x8a, 0x2c, 0x2a, 0x5a, 0xc1, 0x5, 0xe8, 0x4c, 0x15, 0x15, 0x79, 0x39}; + uint8_t bytesprops8[] = {0x51, 0x2d, 0x4f}; + uint8_t bytesprops10[] = {0x63, 0xb5, 0x5e, 0x21, 0xfd, 0x4a, 0x52, 0x55, 0xe7, + 0x1d, 0x99, 0x6d, 0x92, 0xa0, 0x16, 0x7a, 0x54}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)3, .value = {.str = {25, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 240}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 26171}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {28, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 22904}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 18294}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 25799}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {10, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {12, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {8, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 10541}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 20624}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 32656}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 215}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {14, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {19, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {28, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {3, (char*)&bytesprops8}, .v = {13, (char*)&bytesprops9}}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {17, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 15091}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 10435}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 3913}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 37}}, + }; + + lwmqtt_properties_t props = {23, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 30332, 194, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 30332 194 [PropContentType "0\157\150N +// \243|\175\SOH\250{\228\134\193s\189\133ub4\131i\197\207\203",PropMaximumQoS 240,PropSessionExpiryInterval +// 26171,PropReasonString +// "\152!X!S\217\161\ENQW7\248\168\222\231\227\174\201O\SUB<\144\&7\163\154\175Y\ETB\SI",PropReceiveMaximum +// 22904,PropSessionExpiryInterval 18294,PropTopicAlias 25799,PropResponseInformation +// "\198)\141\178\229\195\231(bp",PropServerReference "C\153F\209\136\DC2\209\139\153\196K~",PropCorrelationData +// "\160\212\&1\220%\143yr",PropMessageExpiryInterval 10541,PropTopicAliasMaximum 20624,PropWillDelayInterval +// 32656,PropSubscriptionIdentifierAvailable 215,PropAuthenticationMethod "\220\156\160\169\208\DC16{\b\172 +// \208\213\243",PropAuthenticationMethod +// "\177\154\SUB\163\EM\237\146\201\167\222\DLE*\149\195Y\173*\183.",PropAuthenticationMethod +// "u\165\133\RSc(Tp\220\DC3\229\150\207\DEL\r\n\184\\\145\181khFBR3\212\207",PropUserProperty "Q-O" +// "+\138,*Z\193\ENQ\232L\NAK\NAKy9",PropServerReference +// "c\181^!\253JRU\231\GS\153m\146\160\SYNzT",PropMessageExpiryInterval 15091,PropMessageExpiryInterval +// 10435,PropMessageExpiryInterval 3913,PropWildcardSubscriptionAvailable 37]) +TEST(PubACKREL5QCTest, Decode15) { + uint8_t pkt[] = {0x62, 0x88, 0x2, 0x76, 0x7c, 0xc2, 0x83, 0x2, 0x3, 0x0, 0x19, 0x30, 0x9d, 0x96, 0x4e, 0x20, 0xf3, + 0x7c, 0xaf, 0x1, 0xfa, 0x7b, 0xe4, 0x86, 0xc1, 0x73, 0xbd, 0x85, 0x75, 0x62, 0x34, 0x83, 0x69, 0xc5, + 0xcf, 0xcb, 0x24, 0xf0, 0x11, 0x0, 0x0, 0x66, 0x3b, 0x1f, 0x0, 0x1c, 0x98, 0x21, 0x58, 0x21, 0x53, + 0xd9, 0xa1, 0x5, 0x57, 0x37, 0xf8, 0xa8, 0xde, 0xe7, 0xe3, 0xae, 0xc9, 0x4f, 0x1a, 0x3c, 0x90, 0x37, + 0xa3, 0x9a, 0xaf, 0x59, 0x17, 0xf, 0x21, 0x59, 0x78, 0x11, 0x0, 0x0, 0x47, 0x76, 0x23, 0x64, 0xc7, + 0x1a, 0x0, 0xa, 0xc6, 0x29, 0x8d, 0xb2, 0xe5, 0xc3, 0xe7, 0x28, 0x62, 0x70, 0x1c, 0x0, 0xc, 0x43, + 0x99, 0x46, 0xd1, 0x88, 0x12, 0xd1, 0x8b, 0x99, 0xc4, 0x4b, 0x7e, 0x9, 0x0, 0x8, 0xa0, 0xd4, 0x31, + 0xdc, 0x25, 0x8f, 0x79, 0x72, 0x2, 0x0, 0x0, 0x29, 0x2d, 0x22, 0x50, 0x90, 0x18, 0x0, 0x0, 0x7f, + 0x90, 0x29, 0xd7, 0x15, 0x0, 0xe, 0xdc, 0x9c, 0xa0, 0xa9, 0xd0, 0x11, 0x36, 0x7b, 0x8, 0xac, 0x20, + 0xd0, 0xd5, 0xf3, 0x15, 0x0, 0x13, 0xb1, 0x9a, 0x1a, 0xa3, 0x19, 0xed, 0x92, 0xc9, 0xa7, 0xde, 0x10, + 0x2a, 0x95, 0xc3, 0x59, 0xad, 0x2a, 0xb7, 0x2e, 0x15, 0x0, 0x1c, 0x75, 0xa5, 0x85, 0x1e, 0x63, 0x28, + 0x54, 0x70, 0xdc, 0x13, 0xe5, 0x96, 0xcf, 0x7f, 0xd, 0xa, 0xb8, 0x5c, 0x91, 0xb5, 0x6b, 0x68, 0x46, + 0x42, 0x52, 0x33, 0xd4, 0xcf, 0x26, 0x0, 0x3, 0x51, 0x2d, 0x4f, 0x0, 0xd, 0x2b, 0x8a, 0x2c, 0x2a, + 0x5a, 0xc1, 0x5, 0xe8, 0x4c, 0x15, 0x15, 0x79, 0x39, 0x1c, 0x0, 0x11, 0x63, 0xb5, 0x5e, 0x21, 0xfd, + 0x4a, 0x52, 0x55, 0xe7, 0x1d, 0x99, 0x6d, 0x92, 0xa0, 0x16, 0x7a, 0x54, 0x2, 0x0, 0x0, 0x3a, 0xf3, + 0x2, 0x0, 0x0, 0x28, 0xc3, 0x2, 0x0, 0x0, 0xf, 0x49, 0x28, 0x25}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 30332); + EXPECT_EQ(status, 194); +} + +// REL (PubREL 16804 216 [PropReceiveMaximum 16204,PropAuthenticationMethod +// "\195\&9\161\244!C\225\r\204O)\n\253\249\244\SUB\140\251\132",PropSharedSubscriptionAvailable 154,PropResponseTopic +// "\228o\241\136\176\222\201\225\163O?\ENQ*30\204k\239",PropRequestResponseInformation 50,PropPayloadFormatIndicator +// 218,PropAuthenticationMethod "\NUL\192T\156"]) +TEST(PubACKREL5QCTest, Encode16) { + uint8_t pkt[] = {0x62, 0x3f, 0x41, 0xa4, 0xd8, 0x3b, 0x21, 0x3f, 0x4c, 0x15, 0x0, 0x13, 0xc3, 0x39, 0xa1, 0xf4, 0x21, + 0x43, 0xe1, 0xd, 0xcc, 0x4f, 0x29, 0xa, 0xfd, 0xf9, 0xf4, 0x1a, 0x8c, 0xfb, 0x84, 0x2a, 0x9a, 0x8, + 0x0, 0x12, 0xe4, 0x6f, 0xf1, 0x88, 0xb0, 0xde, 0xc9, 0xe1, 0xa3, 0x4f, 0x3f, 0x5, 0x2a, 0x33, 0x30, + 0xcc, 0x6b, 0xef, 0x19, 0x32, 0x1, 0xda, 0x15, 0x0, 0x4, 0x0, 0xc0, 0x54, 0x9c}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0xc3, 0x39, 0xa1, 0xf4, 0x21, 0x43, 0xe1, 0xd, 0xcc, 0x4f, + 0x29, 0xa, 0xfd, 0xf9, 0xf4, 0x1a, 0x8c, 0xfb, 0x84}; + uint8_t bytesprops1[] = {0xe4, 0x6f, 0xf1, 0x88, 0xb0, 0xde, 0xc9, 0xe1, 0xa3, + 0x4f, 0x3f, 0x5, 0x2a, 0x33, 0x30, 0xcc, 0x6b, 0xef}; + uint8_t bytesprops2[] = {0x0, 0xc0, 0x54, 0x9c}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 16204}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {19, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 154}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {18, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 50}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 218}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {4, (char*)&bytesprops2}}}, + }; + + lwmqtt_properties_t props = {7, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 16804, 216, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 16804 216 [PropReceiveMaximum 16204,PropAuthenticationMethod +// "\195\&9\161\244!C\225\r\204O)\n\253\249\244\SUB\140\251\132",PropSharedSubscriptionAvailable 154,PropResponseTopic +// "\228o\241\136\176\222\201\225\163O?\ENQ*30\204k\239",PropRequestResponseInformation 50,PropPayloadFormatIndicator +// 218,PropAuthenticationMethod "\NUL\192T\156"]) +TEST(PubACKREL5QCTest, Decode16) { + uint8_t pkt[] = {0x62, 0x3f, 0x41, 0xa4, 0xd8, 0x3b, 0x21, 0x3f, 0x4c, 0x15, 0x0, 0x13, 0xc3, 0x39, 0xa1, 0xf4, 0x21, + 0x43, 0xe1, 0xd, 0xcc, 0x4f, 0x29, 0xa, 0xfd, 0xf9, 0xf4, 0x1a, 0x8c, 0xfb, 0x84, 0x2a, 0x9a, 0x8, + 0x0, 0x12, 0xe4, 0x6f, 0xf1, 0x88, 0xb0, 0xde, 0xc9, 0xe1, 0xa3, 0x4f, 0x3f, 0x5, 0x2a, 0x33, 0x30, + 0xcc, 0x6b, 0xef, 0x19, 0x32, 0x1, 0xda, 0x15, 0x0, 0x4, 0x0, 0xc0, 0x54, 0x9c}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 16804); + EXPECT_EQ(status, 216); +} + +// REC (PubREC 5882 7 [PropResponseTopic "Zh\223!\177\&2@\254X\243\250f",PropReceiveMaximum 21439,PropUserProperty +// "\SOH\223\139\156mD&\244F\200\DELp7n\182r\f\170\138" +// "\173a\170\159\173\225%\249K\233h\NAK\146\SOH\191\202ZT\238\222X\137",PropResponseTopic "/1\214M",PropRetainAvailable +// 211,PropSharedSubscriptionAvailable 53,PropSubscriptionIdentifierAvailable 232,PropSubscriptionIdentifierAvailable +// 202,PropResponseTopic "\192\134-N\242\173\ACKB",PropAuthenticationMethod +// "\242\"Ww\183H\165}\205\196\174\SOQq\173\&9S\167\189\170\236\234\177\168jB\231q\161",PropWillDelayInterval +// 25352,PropRequestResponseInformation 217,PropMaximumPacketSize 945,PropPayloadFormatIndicator 204,PropMaximumQoS +// 34,PropServerKeepAlive 12947,PropUserProperty "(\204\129" +// "\t\200Q2\137\STX\146B\192\178\176\236\180\133\242\242L\NAK\FS",PropCorrelationData +// "\240\253\&1t\134\a\169\143\234x\229\r"]) +TEST(PubACKREC5QCTest, Encode17) { + uint8_t pkt[] = {0x50, 0xbc, 0x1, 0x16, 0xfa, 0x7, 0xb7, 0x1, 0x8, 0x0, 0xc, 0x5a, 0x68, 0xdf, 0x21, 0xb1, + 0x32, 0x40, 0xfe, 0x58, 0xf3, 0xfa, 0x66, 0x21, 0x53, 0xbf, 0x26, 0x0, 0x13, 0x1, 0xdf, 0x8b, + 0x9c, 0x6d, 0x44, 0x26, 0xf4, 0x46, 0xc8, 0x7f, 0x70, 0x37, 0x6e, 0xb6, 0x72, 0xc, 0xaa, 0x8a, + 0x0, 0x16, 0xad, 0x61, 0xaa, 0x9f, 0xad, 0xe1, 0x25, 0xf9, 0x4b, 0xe9, 0x68, 0x15, 0x92, 0x1, + 0xbf, 0xca, 0x5a, 0x54, 0xee, 0xde, 0x58, 0x89, 0x8, 0x0, 0x4, 0x2f, 0x31, 0xd6, 0x4d, 0x25, + 0xd3, 0x2a, 0x35, 0x29, 0xe8, 0x29, 0xca, 0x8, 0x0, 0x8, 0xc0, 0x86, 0x2d, 0x4e, 0xf2, 0xad, + 0x6, 0x42, 0x15, 0x0, 0x1d, 0xf2, 0x22, 0x57, 0x77, 0xb7, 0x48, 0xa5, 0x7d, 0xcd, 0xc4, 0xae, + 0xe, 0x51, 0x71, 0xad, 0x39, 0x53, 0xa7, 0xbd, 0xaa, 0xec, 0xea, 0xb1, 0xa8, 0x6a, 0x42, 0xe7, + 0x71, 0xa1, 0x18, 0x0, 0x0, 0x63, 0x8, 0x19, 0xd9, 0x27, 0x0, 0x0, 0x3, 0xb1, 0x1, 0xcc, + 0x24, 0x22, 0x13, 0x32, 0x93, 0x26, 0x0, 0x3, 0x28, 0xcc, 0x81, 0x0, 0x13, 0x9, 0xc8, 0x51, + 0x32, 0x89, 0x2, 0x92, 0x42, 0xc0, 0xb2, 0xb0, 0xec, 0xb4, 0x85, 0xf2, 0xf2, 0x4c, 0x15, 0x1c, + 0x9, 0x0, 0xc, 0xf0, 0xfd, 0x31, 0x74, 0x86, 0x7, 0xa9, 0x8f, 0xea, 0x78, 0xe5, 0xd}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x5a, 0x68, 0xdf, 0x21, 0xb1, 0x32, 0x40, 0xfe, 0x58, 0xf3, 0xfa, 0x66}; + uint8_t bytesprops2[] = {0xad, 0x61, 0xaa, 0x9f, 0xad, 0xe1, 0x25, 0xf9, 0x4b, 0xe9, 0x68, + 0x15, 0x92, 0x1, 0xbf, 0xca, 0x5a, 0x54, 0xee, 0xde, 0x58, 0x89}; + uint8_t bytesprops1[] = {0x1, 0xdf, 0x8b, 0x9c, 0x6d, 0x44, 0x26, 0xf4, 0x46, 0xc8, + 0x7f, 0x70, 0x37, 0x6e, 0xb6, 0x72, 0xc, 0xaa, 0x8a}; + uint8_t bytesprops3[] = {0x2f, 0x31, 0xd6, 0x4d}; + uint8_t bytesprops4[] = {0xc0, 0x86, 0x2d, 0x4e, 0xf2, 0xad, 0x6, 0x42}; + uint8_t bytesprops5[] = {0xf2, 0x22, 0x57, 0x77, 0xb7, 0x48, 0xa5, 0x7d, 0xcd, 0xc4, 0xae, 0xe, 0x51, 0x71, 0xad, + 0x39, 0x53, 0xa7, 0xbd, 0xaa, 0xec, 0xea, 0xb1, 0xa8, 0x6a, 0x42, 0xe7, 0x71, 0xa1}; + uint8_t bytesprops7[] = {0x9, 0xc8, 0x51, 0x32, 0x89, 0x2, 0x92, 0x42, 0xc0, 0xb2, + 0xb0, 0xec, 0xb4, 0x85, 0xf2, 0xf2, 0x4c, 0x15, 0x1c}; + uint8_t bytesprops6[] = {0x28, 0xcc, 0x81}; + uint8_t bytesprops8[] = {0xf0, 0xfd, 0x31, 0x74, 0x86, 0x7, 0xa9, 0x8f, 0xea, 0x78, 0xe5, 0xd}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)8, .value = {.str = {12, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 21439}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {19, (char*)&bytesprops1}, .v = {22, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {4, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 211}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 53}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 232}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 202}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {8, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {29, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 25352}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 217}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 945}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 204}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 34}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 12947}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {3, (char*)&bytesprops6}, .v = {19, (char*)&bytesprops7}}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {12, (char*)&bytesprops8}}}, + }; + + lwmqtt_properties_t props = {18, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREC_PACKET, 0, 5882, 7, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REC (PubREC 5882 7 [PropResponseTopic "Zh\223!\177\&2@\254X\243\250f",PropReceiveMaximum 21439,PropUserProperty +// "\SOH\223\139\156mD&\244F\200\DELp7n\182r\f\170\138" +// "\173a\170\159\173\225%\249K\233h\NAK\146\SOH\191\202ZT\238\222X\137",PropResponseTopic "/1\214M",PropRetainAvailable +// 211,PropSharedSubscriptionAvailable 53,PropSubscriptionIdentifierAvailable 232,PropSubscriptionIdentifierAvailable +// 202,PropResponseTopic "\192\134-N\242\173\ACKB",PropAuthenticationMethod +// "\242\"Ww\183H\165}\205\196\174\SOQq\173\&9S\167\189\170\236\234\177\168jB\231q\161",PropWillDelayInterval +// 25352,PropRequestResponseInformation 217,PropMaximumPacketSize 945,PropPayloadFormatIndicator 204,PropMaximumQoS +// 34,PropServerKeepAlive 12947,PropUserProperty "(\204\129" +// "\t\200Q2\137\STX\146B\192\178\176\236\180\133\242\242L\NAK\FS",PropCorrelationData +// "\240\253\&1t\134\a\169\143\234x\229\r"]) +TEST(PubACKREC5QCTest, Decode17) { + uint8_t pkt[] = {0x50, 0xbc, 0x1, 0x16, 0xfa, 0x7, 0xb7, 0x1, 0x8, 0x0, 0xc, 0x5a, 0x68, 0xdf, 0x21, 0xb1, + 0x32, 0x40, 0xfe, 0x58, 0xf3, 0xfa, 0x66, 0x21, 0x53, 0xbf, 0x26, 0x0, 0x13, 0x1, 0xdf, 0x8b, + 0x9c, 0x6d, 0x44, 0x26, 0xf4, 0x46, 0xc8, 0x7f, 0x70, 0x37, 0x6e, 0xb6, 0x72, 0xc, 0xaa, 0x8a, + 0x0, 0x16, 0xad, 0x61, 0xaa, 0x9f, 0xad, 0xe1, 0x25, 0xf9, 0x4b, 0xe9, 0x68, 0x15, 0x92, 0x1, + 0xbf, 0xca, 0x5a, 0x54, 0xee, 0xde, 0x58, 0x89, 0x8, 0x0, 0x4, 0x2f, 0x31, 0xd6, 0x4d, 0x25, + 0xd3, 0x2a, 0x35, 0x29, 0xe8, 0x29, 0xca, 0x8, 0x0, 0x8, 0xc0, 0x86, 0x2d, 0x4e, 0xf2, 0xad, + 0x6, 0x42, 0x15, 0x0, 0x1d, 0xf2, 0x22, 0x57, 0x77, 0xb7, 0x48, 0xa5, 0x7d, 0xcd, 0xc4, 0xae, + 0xe, 0x51, 0x71, 0xad, 0x39, 0x53, 0xa7, 0xbd, 0xaa, 0xec, 0xea, 0xb1, 0xa8, 0x6a, 0x42, 0xe7, + 0x71, 0xa1, 0x18, 0x0, 0x0, 0x63, 0x8, 0x19, 0xd9, 0x27, 0x0, 0x0, 0x3, 0xb1, 0x1, 0xcc, + 0x24, 0x22, 0x13, 0x32, 0x93, 0x26, 0x0, 0x3, 0x28, 0xcc, 0x81, 0x0, 0x13, 0x9, 0xc8, 0x51, + 0x32, 0x89, 0x2, 0x92, 0x42, 0xc0, 0xb2, 0xb0, 0xec, 0xb4, 0x85, 0xf2, 0xf2, 0x4c, 0x15, 0x1c, + 0x9, 0x0, 0xc, 0xf0, 0xfd, 0x31, 0x74, 0x86, 0x7, 0xa9, 0x8f, 0xea, 0x78, 0xe5, 0xd}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREC_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 5882); + EXPECT_EQ(status, 7); +} + +// REL (PubREL 9713 122 [PropCorrelationData "\218\184\US\179O\185u\208f^\137\207*\190\135\158\247",PropCorrelationData +// "\251}8\219d\USr\253\211",PropAuthenticationMethod +// "\176\173iZ|[\156\DC3v\253R\190\255",PropRequestResponseInformation 194,PropResponseInformation +// "\226\ETB\SOH\245\215\255\ETX\241\155\173\v\213\&1\190\EOT",PropContentType +// ")\177-\SYNHnl%\202\177\FSI\183\145_\245\140\226\250\&9QS\ACK-\EM",PropWildcardSubscriptionAvailable +// 243,PropUserProperty "xa\231i\199$^\167{%5\228E\DLE\188\198\\" +// "\240J\136\228\138+\248\133F\178\DC2\160\238\164AXb\FS\SIl\223\189\150#i\r\129i\223"]) +TEST(PubACKREL5QCTest, Encode18) { + uint8_t pkt[] = {0x62, 0x9a, 0x1, 0x25, 0xf1, 0x7a, 0x95, 0x1, 0x9, 0x0, 0x11, 0xda, 0xb8, 0x1f, 0xb3, 0x4f, + 0xb9, 0x75, 0xd0, 0x66, 0x5e, 0x89, 0xcf, 0x2a, 0xbe, 0x87, 0x9e, 0xf7, 0x9, 0x0, 0x9, 0xfb, + 0x7d, 0x38, 0xdb, 0x64, 0x1f, 0x72, 0xfd, 0xd3, 0x15, 0x0, 0xd, 0xb0, 0xad, 0x69, 0x5a, 0x7c, + 0x5b, 0x9c, 0x13, 0x76, 0xfd, 0x52, 0xbe, 0xff, 0x19, 0xc2, 0x1a, 0x0, 0xf, 0xe2, 0x17, 0x1, + 0xf5, 0xd7, 0xff, 0x3, 0xf1, 0x9b, 0xad, 0xb, 0xd5, 0x31, 0xbe, 0x4, 0x3, 0x0, 0x19, 0x29, + 0xb1, 0x2d, 0x16, 0x48, 0x6e, 0x6c, 0x25, 0xca, 0xb1, 0x1c, 0x49, 0xb7, 0x91, 0x5f, 0xf5, 0x8c, + 0xe2, 0xfa, 0x39, 0x51, 0x53, 0x6, 0x2d, 0x19, 0x28, 0xf3, 0x26, 0x0, 0x11, 0x78, 0x61, 0xe7, + 0x69, 0xc7, 0x24, 0x5e, 0xa7, 0x7b, 0x25, 0x35, 0xe4, 0x45, 0x10, 0xbc, 0xc6, 0x5c, 0x0, 0x1d, + 0xf0, 0x4a, 0x88, 0xe4, 0x8a, 0x2b, 0xf8, 0x85, 0x46, 0xb2, 0x12, 0xa0, 0xee, 0xa4, 0x41, 0x58, + 0x62, 0x1c, 0xf, 0x6c, 0xdf, 0xbd, 0x96, 0x23, 0x69, 0xd, 0x81, 0x69, 0xdf}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0xda, 0xb8, 0x1f, 0xb3, 0x4f, 0xb9, 0x75, 0xd0, 0x66, + 0x5e, 0x89, 0xcf, 0x2a, 0xbe, 0x87, 0x9e, 0xf7}; + uint8_t bytesprops1[] = {0xfb, 0x7d, 0x38, 0xdb, 0x64, 0x1f, 0x72, 0xfd, 0xd3}; + uint8_t bytesprops2[] = {0xb0, 0xad, 0x69, 0x5a, 0x7c, 0x5b, 0x9c, 0x13, 0x76, 0xfd, 0x52, 0xbe, 0xff}; + uint8_t bytesprops3[] = {0xe2, 0x17, 0x1, 0xf5, 0xd7, 0xff, 0x3, 0xf1, 0x9b, 0xad, 0xb, 0xd5, 0x31, 0xbe, 0x4}; + uint8_t bytesprops4[] = {0x29, 0xb1, 0x2d, 0x16, 0x48, 0x6e, 0x6c, 0x25, 0xca, 0xb1, 0x1c, 0x49, 0xb7, + 0x91, 0x5f, 0xf5, 0x8c, 0xe2, 0xfa, 0x39, 0x51, 0x53, 0x6, 0x2d, 0x19}; + uint8_t bytesprops6[] = {0xf0, 0x4a, 0x88, 0xe4, 0x8a, 0x2b, 0xf8, 0x85, 0x46, 0xb2, 0x12, 0xa0, 0xee, 0xa4, 0x41, + 0x58, 0x62, 0x1c, 0xf, 0x6c, 0xdf, 0xbd, 0x96, 0x23, 0x69, 0xd, 0x81, 0x69, 0xdf}; + uint8_t bytesprops5[] = {0x78, 0x61, 0xe7, 0x69, 0xc7, 0x24, 0x5e, 0xa7, 0x7b, + 0x25, 0x35, 0xe4, 0x45, 0x10, 0xbc, 0xc6, 0x5c}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)9, .value = {.str = {17, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {9, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {13, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 194}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {15, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {25, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 243}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {17, (char*)&bytesprops5}, .v = {29, (char*)&bytesprops6}}}}, + }; + + lwmqtt_properties_t props = {8, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 9713, 122, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 9713 122 [PropCorrelationData "\218\184\US\179O\185u\208f^\137\207*\190\135\158\247",PropCorrelationData +// "\251}8\219d\USr\253\211",PropAuthenticationMethod +// "\176\173iZ|[\156\DC3v\253R\190\255",PropRequestResponseInformation 194,PropResponseInformation +// "\226\ETB\SOH\245\215\255\ETX\241\155\173\v\213\&1\190\EOT",PropContentType +// ")\177-\SYNHnl%\202\177\FSI\183\145_\245\140\226\250\&9QS\ACK-\EM",PropWildcardSubscriptionAvailable +// 243,PropUserProperty "xa\231i\199$^\167{%5\228E\DLE\188\198\\" +// "\240J\136\228\138+\248\133F\178\DC2\160\238\164AXb\FS\SIl\223\189\150#i\r\129i\223"]) +TEST(PubACKREL5QCTest, Decode18) { + uint8_t pkt[] = {0x62, 0x9a, 0x1, 0x25, 0xf1, 0x7a, 0x95, 0x1, 0x9, 0x0, 0x11, 0xda, 0xb8, 0x1f, 0xb3, 0x4f, + 0xb9, 0x75, 0xd0, 0x66, 0x5e, 0x89, 0xcf, 0x2a, 0xbe, 0x87, 0x9e, 0xf7, 0x9, 0x0, 0x9, 0xfb, + 0x7d, 0x38, 0xdb, 0x64, 0x1f, 0x72, 0xfd, 0xd3, 0x15, 0x0, 0xd, 0xb0, 0xad, 0x69, 0x5a, 0x7c, + 0x5b, 0x9c, 0x13, 0x76, 0xfd, 0x52, 0xbe, 0xff, 0x19, 0xc2, 0x1a, 0x0, 0xf, 0xe2, 0x17, 0x1, + 0xf5, 0xd7, 0xff, 0x3, 0xf1, 0x9b, 0xad, 0xb, 0xd5, 0x31, 0xbe, 0x4, 0x3, 0x0, 0x19, 0x29, + 0xb1, 0x2d, 0x16, 0x48, 0x6e, 0x6c, 0x25, 0xca, 0xb1, 0x1c, 0x49, 0xb7, 0x91, 0x5f, 0xf5, 0x8c, + 0xe2, 0xfa, 0x39, 0x51, 0x53, 0x6, 0x2d, 0x19, 0x28, 0xf3, 0x26, 0x0, 0x11, 0x78, 0x61, 0xe7, + 0x69, 0xc7, 0x24, 0x5e, 0xa7, 0x7b, 0x25, 0x35, 0xe4, 0x45, 0x10, 0xbc, 0xc6, 0x5c, 0x0, 0x1d, + 0xf0, 0x4a, 0x88, 0xe4, 0x8a, 0x2b, 0xf8, 0x85, 0x46, 0xb2, 0x12, 0xa0, 0xee, 0xa4, 0x41, 0x58, + 0x62, 0x1c, 0xf, 0x6c, 0xdf, 0xbd, 0x96, 0x23, 0x69, 0xd, 0x81, 0x69, 0xdf}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 9713); + EXPECT_EQ(status, 122); +} + +// REL (PubREL 28230 9 [PropSubscriptionIdentifierAvailable 125,PropMaximumQoS 124,PropResponseTopic +// "\140\169Hh",PropTopicAlias 30053,PropContentType +// "\236\232\241o\154\129\f\149F(\191\CAN\FS\v`\US^<5\177",PropSubscriptionIdentifierAvailable 226,PropUserProperty +// "S\SOH`\NULNl&\181p\244\&3A\213\SIU\GS,\175\251\171\146\238\&9`2" +// "d\169x\EMI]5\144\222\148\185Y\159\253\129\135\173]\252\148",PropUserProperty "\159\179\ENQ\238;\155R" +// ".\245H",PropSubscriptionIdentifier 17,PropReceiveMaximum 12563,PropSharedSubscriptionAvailable +// 182,PropSubscriptionIdentifierAvailable 24,PropRequestProblemInformation 212,PropUserProperty +// "!\221o\163\211D\252\&9ox" "tP\SUB\235\152\SO,'\194\&9\228\134!\190ht\197D\DC2W",PropRequestResponseInformation +// 220,PropResponseInformation "\202I\231\134",PropResponseInformation +// "3\EMr\180V8J6\220\217\DEL,\142I\255J\190\n\175S\140!\STX\158\SOH",PropReceiveMaximum 6076,PropMaximumQoS +// 37,PropWillDelayInterval 9063]) +TEST(PubACKREL5QCTest, Encode19) { + uint8_t pkt[] = { + 0x62, 0xca, 0x1, 0x6e, 0x46, 0x9, 0xc5, 0x1, 0x29, 0x7d, 0x24, 0x7c, 0x8, 0x0, 0x4, 0x8c, 0xa9, 0x48, 0x68, + 0x23, 0x75, 0x65, 0x3, 0x0, 0x14, 0xec, 0xe8, 0xf1, 0x6f, 0x9a, 0x81, 0xc, 0x95, 0x46, 0x28, 0xbf, 0x18, 0x1c, + 0xb, 0x60, 0x1f, 0x5e, 0x3c, 0x35, 0xb1, 0x29, 0xe2, 0x26, 0x0, 0x19, 0x53, 0x1, 0x60, 0x0, 0x4e, 0x6c, 0x26, + 0xb5, 0x70, 0xf4, 0x33, 0x41, 0xd5, 0xf, 0x55, 0x1d, 0x2c, 0xaf, 0xfb, 0xab, 0x92, 0xee, 0x39, 0x60, 0x32, 0x0, + 0x14, 0x64, 0xa9, 0x78, 0x19, 0x49, 0x5d, 0x35, 0x90, 0xde, 0x94, 0xb9, 0x59, 0x9f, 0xfd, 0x81, 0x87, 0xad, 0x5d, + 0xfc, 0x94, 0x26, 0x0, 0x7, 0x9f, 0xb3, 0x5, 0xee, 0x3b, 0x9b, 0x52, 0x0, 0x3, 0x2e, 0xf5, 0x48, 0xb, 0x11, + 0x21, 0x31, 0x13, 0x2a, 0xb6, 0x29, 0x18, 0x17, 0xd4, 0x26, 0x0, 0xa, 0x21, 0xdd, 0x6f, 0xa3, 0xd3, 0x44, 0xfc, + 0x39, 0x6f, 0x78, 0x0, 0x14, 0x74, 0x50, 0x1a, 0xeb, 0x98, 0xe, 0x2c, 0x27, 0xc2, 0x39, 0xe4, 0x86, 0x21, 0xbe, + 0x68, 0x74, 0xc5, 0x44, 0x12, 0x57, 0x19, 0xdc, 0x1a, 0x0, 0x4, 0xca, 0x49, 0xe7, 0x86, 0x1a, 0x0, 0x19, 0x33, + 0x19, 0x72, 0xb4, 0x56, 0x38, 0x4a, 0x36, 0xdc, 0xd9, 0x7f, 0x2c, 0x8e, 0x49, 0xff, 0x4a, 0xbe, 0xa, 0xaf, 0x53, + 0x8c, 0x21, 0x2, 0x9e, 0x1, 0x21, 0x17, 0xbc, 0x24, 0x25, 0x18, 0x0, 0x0, 0x23, 0x67}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x8c, 0xa9, 0x48, 0x68}; + uint8_t bytesprops1[] = {0xec, 0xe8, 0xf1, 0x6f, 0x9a, 0x81, 0xc, 0x95, 0x46, 0x28, + 0xbf, 0x18, 0x1c, 0xb, 0x60, 0x1f, 0x5e, 0x3c, 0x35, 0xb1}; + uint8_t bytesprops3[] = {0x64, 0xa9, 0x78, 0x19, 0x49, 0x5d, 0x35, 0x90, 0xde, 0x94, + 0xb9, 0x59, 0x9f, 0xfd, 0x81, 0x87, 0xad, 0x5d, 0xfc, 0x94}; + uint8_t bytesprops2[] = {0x53, 0x1, 0x60, 0x0, 0x4e, 0x6c, 0x26, 0xb5, 0x70, 0xf4, 0x33, 0x41, 0xd5, + 0xf, 0x55, 0x1d, 0x2c, 0xaf, 0xfb, 0xab, 0x92, 0xee, 0x39, 0x60, 0x32}; + uint8_t bytesprops5[] = {0x2e, 0xf5, 0x48}; + uint8_t bytesprops4[] = {0x9f, 0xb3, 0x5, 0xee, 0x3b, 0x9b, 0x52}; + uint8_t bytesprops7[] = {0x74, 0x50, 0x1a, 0xeb, 0x98, 0xe, 0x2c, 0x27, 0xc2, 0x39, + 0xe4, 0x86, 0x21, 0xbe, 0x68, 0x74, 0xc5, 0x44, 0x12, 0x57}; + uint8_t bytesprops6[] = {0x21, 0xdd, 0x6f, 0xa3, 0xd3, 0x44, 0xfc, 0x39, 0x6f, 0x78}; + uint8_t bytesprops8[] = {0xca, 0x49, 0xe7, 0x86}; + uint8_t bytesprops9[] = {0x33, 0x19, 0x72, 0xb4, 0x56, 0x38, 0x4a, 0x36, 0xdc, 0xd9, 0x7f, 0x2c, 0x8e, + 0x49, 0xff, 0x4a, 0xbe, 0xa, 0xaf, 0x53, 0x8c, 0x21, 0x2, 0x9e, 0x1}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 125}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 124}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {4, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 30053}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {20, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 226}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {25, (char*)&bytesprops2}, .v = {20, (char*)&bytesprops3}}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {7, (char*)&bytesprops4}, .v = {3, (char*)&bytesprops5}}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 17}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 12563}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 182}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 24}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 212}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {10, (char*)&bytesprops6}, .v = {20, (char*)&bytesprops7}}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 220}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {4, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {25, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 6076}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 37}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 9063}}, + }; + + lwmqtt_properties_t props = {20, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 28230, 9, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 28230 9 [PropSubscriptionIdentifierAvailable 125,PropMaximumQoS 124,PropResponseTopic +// "\140\169Hh",PropTopicAlias 30053,PropContentType +// "\236\232\241o\154\129\f\149F(\191\CAN\FS\v`\US^<5\177",PropSubscriptionIdentifierAvailable 226,PropUserProperty +// "S\SOH`\NULNl&\181p\244\&3A\213\SIU\GS,\175\251\171\146\238\&9`2" +// "d\169x\EMI]5\144\222\148\185Y\159\253\129\135\173]\252\148",PropUserProperty "\159\179\ENQ\238;\155R" +// ".\245H",PropSubscriptionIdentifier 17,PropReceiveMaximum 12563,PropSharedSubscriptionAvailable +// 182,PropSubscriptionIdentifierAvailable 24,PropRequestProblemInformation 212,PropUserProperty +// "!\221o\163\211D\252\&9ox" "tP\SUB\235\152\SO,'\194\&9\228\134!\190ht\197D\DC2W",PropRequestResponseInformation +// 220,PropResponseInformation "\202I\231\134",PropResponseInformation +// "3\EMr\180V8J6\220\217\DEL,\142I\255J\190\n\175S\140!\STX\158\SOH",PropReceiveMaximum 6076,PropMaximumQoS +// 37,PropWillDelayInterval 9063]) +TEST(PubACKREL5QCTest, Decode19) { + uint8_t pkt[] = { + 0x62, 0xca, 0x1, 0x6e, 0x46, 0x9, 0xc5, 0x1, 0x29, 0x7d, 0x24, 0x7c, 0x8, 0x0, 0x4, 0x8c, 0xa9, 0x48, 0x68, + 0x23, 0x75, 0x65, 0x3, 0x0, 0x14, 0xec, 0xe8, 0xf1, 0x6f, 0x9a, 0x81, 0xc, 0x95, 0x46, 0x28, 0xbf, 0x18, 0x1c, + 0xb, 0x60, 0x1f, 0x5e, 0x3c, 0x35, 0xb1, 0x29, 0xe2, 0x26, 0x0, 0x19, 0x53, 0x1, 0x60, 0x0, 0x4e, 0x6c, 0x26, + 0xb5, 0x70, 0xf4, 0x33, 0x41, 0xd5, 0xf, 0x55, 0x1d, 0x2c, 0xaf, 0xfb, 0xab, 0x92, 0xee, 0x39, 0x60, 0x32, 0x0, + 0x14, 0x64, 0xa9, 0x78, 0x19, 0x49, 0x5d, 0x35, 0x90, 0xde, 0x94, 0xb9, 0x59, 0x9f, 0xfd, 0x81, 0x87, 0xad, 0x5d, + 0xfc, 0x94, 0x26, 0x0, 0x7, 0x9f, 0xb3, 0x5, 0xee, 0x3b, 0x9b, 0x52, 0x0, 0x3, 0x2e, 0xf5, 0x48, 0xb, 0x11, + 0x21, 0x31, 0x13, 0x2a, 0xb6, 0x29, 0x18, 0x17, 0xd4, 0x26, 0x0, 0xa, 0x21, 0xdd, 0x6f, 0xa3, 0xd3, 0x44, 0xfc, + 0x39, 0x6f, 0x78, 0x0, 0x14, 0x74, 0x50, 0x1a, 0xeb, 0x98, 0xe, 0x2c, 0x27, 0xc2, 0x39, 0xe4, 0x86, 0x21, 0xbe, + 0x68, 0x74, 0xc5, 0x44, 0x12, 0x57, 0x19, 0xdc, 0x1a, 0x0, 0x4, 0xca, 0x49, 0xe7, 0x86, 0x1a, 0x0, 0x19, 0x33, + 0x19, 0x72, 0xb4, 0x56, 0x38, 0x4a, 0x36, 0xdc, 0xd9, 0x7f, 0x2c, 0x8e, 0x49, 0xff, 0x4a, 0xbe, 0xa, 0xaf, 0x53, + 0x8c, 0x21, 0x2, 0x9e, 0x1, 0x21, 0x17, 0xbc, 0x24, 0x25, 0x18, 0x0, 0x0, 0x23, 0x67}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 28230); + EXPECT_EQ(status, 9); +} + +// COMP (PubCOMP 19063 157 [PropMessageExpiryInterval 415,PropTopicAlias 12355,PropWildcardSubscriptionAvailable +// 214,PropTopicAliasMaximum 21960,PropContentType "_yx\242\&5\209Sg\156U\244\192\189\238",PropAssignedClientIdentifier +// "0\199Ir\141\SO\217\NUL"]) +TEST(PubACKCOMP5QCTest, Encode20) { + uint8_t pkt[] = {0x70, 0x2d, 0x4a, 0x77, 0x9d, 0x29, 0x2, 0x0, 0x0, 0x1, 0x9f, 0x23, 0x30, 0x43, 0x28, 0xd6, + 0x22, 0x55, 0xc8, 0x3, 0x0, 0xe, 0x5f, 0x79, 0x78, 0xf2, 0x35, 0xd1, 0x53, 0x67, 0x9c, 0x55, + 0xf4, 0xc0, 0xbd, 0xee, 0x12, 0x0, 0x8, 0x30, 0xc7, 0x49, 0x72, 0x8d, 0xe, 0xd9, 0x0}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x5f, 0x79, 0x78, 0xf2, 0x35, 0xd1, 0x53, 0x67, 0x9c, 0x55, 0xf4, 0xc0, 0xbd, 0xee}; + uint8_t bytesprops1[] = {0x30, 0xc7, 0x49, 0x72, 0x8d, 0xe, 0xd9, 0x0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 415}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 12355}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 214}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 21960}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {14, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {8, (char*)&bytesprops1}}}, + }; + + lwmqtt_properties_t props = {6, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, 0, 19063, 157, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 19063 157 [PropMessageExpiryInterval 415,PropTopicAlias 12355,PropWildcardSubscriptionAvailable +// 214,PropTopicAliasMaximum 21960,PropContentType "_yx\242\&5\209Sg\156U\244\192\189\238",PropAssignedClientIdentifier +// "0\199Ir\141\SO\217\NUL"]) +TEST(PubACKCOMP5QCTest, Decode20) { + uint8_t pkt[] = {0x70, 0x2d, 0x4a, 0x77, 0x9d, 0x29, 0x2, 0x0, 0x0, 0x1, 0x9f, 0x23, 0x30, 0x43, 0x28, 0xd6, + 0x22, 0x55, 0xc8, 0x3, 0x0, 0xe, 0x5f, 0x79, 0x78, 0xf2, 0x35, 0xd1, 0x53, 0x67, 0x9c, 0x55, + 0xf4, 0xc0, 0xbd, 0xee, 0x12, 0x0, 0x8, 0x30, 0xc7, 0x49, 0x72, 0x8d, 0xe, 0xd9, 0x0}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 19063); + EXPECT_EQ(status, 157); +} + +// ACK (PubACK 459 177 [PropAuthenticationData "\146PO",PropRetainAvailable 34,PropContentType +// "Y\186\225\148\168T\b^\173\250\143?\169\166\CAN\DC1\189fQ\DC4Dn\DC2\SIh",PropResponseTopic +// "~2:\251\DLEJ\197@\240g",PropWildcardSubscriptionAvailable 96,PropSubscriptionIdentifier +// 23,PropRequestResponseInformation 91,PropRequestResponseInformation 251,PropAuthenticationMethod +// "\221\140\237{\246u\STX",PropPayloadFormatIndicator 44,PropMaximumPacketSize 26925,PropTopicAliasMaximum +// 769,PropTopicAliasMaximum 5538,PropRetainAvailable 39,PropCorrelationData +// "\254\136O\198\167;r\b\202\157\&0\134\227Nap\181\ETX\195\235p5r\185n\173\f\DC4\215?",PropRetainAvailable +// 141,PropResponseInformation "\n+\"\RSt\143\SOH\241\SOH\240\227^",PropMaximumQoS 108,PropResponseTopic +// "\146\166\162\DC2\173-\216\207m\NUL\221f\240\242\174+ \172\RSm\168"]) +TEST(PubACKACK5QCTest, Encode21) { + uint8_t pkt[] = {0x40, 0xa3, 0x1, 0x1, 0xcb, 0xb1, 0x9e, 0x1, 0x16, 0x0, 0x3, 0x92, 0x50, 0x4f, 0x25, 0x22, 0x3, + 0x0, 0x19, 0x59, 0xba, 0xe1, 0x94, 0xa8, 0x54, 0x8, 0x5e, 0xad, 0xfa, 0x8f, 0x3f, 0xa9, 0xa6, 0x18, + 0x11, 0xbd, 0x66, 0x51, 0x14, 0x44, 0x6e, 0x12, 0xf, 0x68, 0x8, 0x0, 0xa, 0x7e, 0x32, 0x3a, 0xfb, + 0x10, 0x4a, 0xc5, 0x40, 0xf0, 0x67, 0x28, 0x60, 0xb, 0x17, 0x19, 0x5b, 0x19, 0xfb, 0x15, 0x0, 0x7, + 0xdd, 0x8c, 0xed, 0x7b, 0xf6, 0x75, 0x2, 0x1, 0x2c, 0x27, 0x0, 0x0, 0x69, 0x2d, 0x22, 0x3, 0x1, + 0x22, 0x15, 0xa2, 0x25, 0x27, 0x9, 0x0, 0x1e, 0xfe, 0x88, 0x4f, 0xc6, 0xa7, 0x3b, 0x72, 0x8, 0xca, + 0x9d, 0x30, 0x86, 0xe3, 0x4e, 0x61, 0x70, 0xb5, 0x3, 0xc3, 0xeb, 0x70, 0x35, 0x72, 0xb9, 0x6e, 0xad, + 0xc, 0x14, 0xd7, 0x3f, 0x25, 0x8d, 0x1a, 0x0, 0xc, 0xa, 0x2b, 0x22, 0x1e, 0x74, 0x8f, 0x1, 0xf1, + 0x1, 0xf0, 0xe3, 0x5e, 0x24, 0x6c, 0x8, 0x0, 0x15, 0x92, 0xa6, 0xa2, 0x12, 0xad, 0x2d, 0xd8, 0xcf, + 0x6d, 0x0, 0xdd, 0x66, 0xf0, 0xf2, 0xae, 0x2b, 0x20, 0xac, 0x1e, 0x6d, 0xa8}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x92, 0x50, 0x4f}; + uint8_t bytesprops1[] = {0x59, 0xba, 0xe1, 0x94, 0xa8, 0x54, 0x8, 0x5e, 0xad, 0xfa, 0x8f, 0x3f, 0xa9, + 0xa6, 0x18, 0x11, 0xbd, 0x66, 0x51, 0x14, 0x44, 0x6e, 0x12, 0xf, 0x68}; + uint8_t bytesprops2[] = {0x7e, 0x32, 0x3a, 0xfb, 0x10, 0x4a, 0xc5, 0x40, 0xf0, 0x67}; + uint8_t bytesprops3[] = {0xdd, 0x8c, 0xed, 0x7b, 0xf6, 0x75, 0x2}; + uint8_t bytesprops4[] = {0xfe, 0x88, 0x4f, 0xc6, 0xa7, 0x3b, 0x72, 0x8, 0xca, 0x9d, 0x30, 0x86, 0xe3, 0x4e, 0x61, + 0x70, 0xb5, 0x3, 0xc3, 0xeb, 0x70, 0x35, 0x72, 0xb9, 0x6e, 0xad, 0xc, 0x14, 0xd7, 0x3f}; + uint8_t bytesprops5[] = {0xa, 0x2b, 0x22, 0x1e, 0x74, 0x8f, 0x1, 0xf1, 0x1, 0xf0, 0xe3, 0x5e}; + uint8_t bytesprops6[] = {0x92, 0xa6, 0xa2, 0x12, 0xad, 0x2d, 0xd8, 0xcf, 0x6d, 0x0, 0xdd, + 0x66, 0xf0, 0xf2, 0xae, 0x2b, 0x20, 0xac, 0x1e, 0x6d, 0xa8}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)22, .value = {.str = {3, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 34}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {25, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {10, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 96}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 23}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 91}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 251}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {7, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 44}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 26925}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 769}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 5538}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 39}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {30, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 141}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {12, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 108}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {21, (char*)&bytesprops6}}}, + }; + + lwmqtt_properties_t props = {19, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBACK_PACKET, 0, 459, 177, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ACK (PubACK 459 177 [PropAuthenticationData "\146PO",PropRetainAvailable 34,PropContentType +// "Y\186\225\148\168T\b^\173\250\143?\169\166\CAN\DC1\189fQ\DC4Dn\DC2\SIh",PropResponseTopic +// "~2:\251\DLEJ\197@\240g",PropWildcardSubscriptionAvailable 96,PropSubscriptionIdentifier +// 23,PropRequestResponseInformation 91,PropRequestResponseInformation 251,PropAuthenticationMethod +// "\221\140\237{\246u\STX",PropPayloadFormatIndicator 44,PropMaximumPacketSize 26925,PropTopicAliasMaximum +// 769,PropTopicAliasMaximum 5538,PropRetainAvailable 39,PropCorrelationData +// "\254\136O\198\167;r\b\202\157\&0\134\227Nap\181\ETX\195\235p5r\185n\173\f\DC4\215?",PropRetainAvailable +// 141,PropResponseInformation "\n+\"\RSt\143\SOH\241\SOH\240\227^",PropMaximumQoS 108,PropResponseTopic +// "\146\166\162\DC2\173-\216\207m\NUL\221f\240\242\174+ \172\RSm\168"]) +TEST(PubACKACK5QCTest, Decode21) { + uint8_t pkt[] = {0x40, 0xa3, 0x1, 0x1, 0xcb, 0xb1, 0x9e, 0x1, 0x16, 0x0, 0x3, 0x92, 0x50, 0x4f, 0x25, 0x22, 0x3, + 0x0, 0x19, 0x59, 0xba, 0xe1, 0x94, 0xa8, 0x54, 0x8, 0x5e, 0xad, 0xfa, 0x8f, 0x3f, 0xa9, 0xa6, 0x18, + 0x11, 0xbd, 0x66, 0x51, 0x14, 0x44, 0x6e, 0x12, 0xf, 0x68, 0x8, 0x0, 0xa, 0x7e, 0x32, 0x3a, 0xfb, + 0x10, 0x4a, 0xc5, 0x40, 0xf0, 0x67, 0x28, 0x60, 0xb, 0x17, 0x19, 0x5b, 0x19, 0xfb, 0x15, 0x0, 0x7, + 0xdd, 0x8c, 0xed, 0x7b, 0xf6, 0x75, 0x2, 0x1, 0x2c, 0x27, 0x0, 0x0, 0x69, 0x2d, 0x22, 0x3, 0x1, + 0x22, 0x15, 0xa2, 0x25, 0x27, 0x9, 0x0, 0x1e, 0xfe, 0x88, 0x4f, 0xc6, 0xa7, 0x3b, 0x72, 0x8, 0xca, + 0x9d, 0x30, 0x86, 0xe3, 0x4e, 0x61, 0x70, 0xb5, 0x3, 0xc3, 0xeb, 0x70, 0x35, 0x72, 0xb9, 0x6e, 0xad, + 0xc, 0x14, 0xd7, 0x3f, 0x25, 0x8d, 0x1a, 0x0, 0xc, 0xa, 0x2b, 0x22, 0x1e, 0x74, 0x8f, 0x1, 0xf1, + 0x1, 0xf0, 0xe3, 0x5e, 0x24, 0x6c, 0x8, 0x0, 0x15, 0x92, 0xa6, 0xa2, 0x12, 0xad, 0x2d, 0xd8, 0xcf, + 0x6d, 0x0, 0xdd, 0x66, 0xf0, 0xf2, 0xae, 0x2b, 0x20, 0xac, 0x1e, 0x6d, 0xa8}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBACK_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 459); + EXPECT_EQ(status, 177); +} + +// REC (PubREC 21707 53 [PropAuthenticationData +// "X0\169\193\138\EOT\159M\207\209\187\219\149_\239\229|CU\200\255",PropRetainAvailable 123,PropSubscriptionIdentifier +// 24,PropContentType "\157\168\221K\148\251+\201O\239\DLE\217\141\239\SOH",PropSubscriptionIdentifier +// 36,PropAuthenticationData "\233QF\142r\154\211\128\193",PropServerKeepAlive 2597,PropWillDelayInterval +// 21425,PropResponseTopic +// "\254zyD\226\185\216\221~\235\219\191\219\181n\vd:f\171\FSb;\172",PropRequestResponseInformation +// 142,PropAuthenticationData "\n\NAK\195\154\252\145}\237\SI\186Z\183t\DC3\DC4",PropTopicAliasMaximum +// 16617,PropTopicAliasMaximum 26577,PropRetainAvailable 90,PropPayloadFormatIndicator 174,PropReceiveMaximum +// 15007,PropRequestProblemInformation 46,PropResponseInformation "2h\236",PropRetainAvailable 94]) +TEST(PubACKREC5QCTest, Encode22) { + uint8_t pkt[] = {0x50, 0x8f, 0x1, 0x54, 0xcb, 0x35, 0x8a, 0x1, 0x16, 0x0, 0x15, 0x58, 0x30, 0xa9, 0xc1, 0x8a, 0x4, + 0x9f, 0x4d, 0xcf, 0xd1, 0xbb, 0xdb, 0x95, 0x5f, 0xef, 0xe5, 0x7c, 0x43, 0x55, 0xc8, 0xff, 0x25, 0x7b, + 0xb, 0x18, 0x3, 0x0, 0xf, 0x9d, 0xa8, 0xdd, 0x4b, 0x94, 0xfb, 0x2b, 0xc9, 0x4f, 0xef, 0x10, 0xd9, + 0x8d, 0xef, 0x1, 0xb, 0x24, 0x16, 0x0, 0x9, 0xe9, 0x51, 0x46, 0x8e, 0x72, 0x9a, 0xd3, 0x80, 0xc1, + 0x13, 0xa, 0x25, 0x18, 0x0, 0x0, 0x53, 0xb1, 0x8, 0x0, 0x18, 0xfe, 0x7a, 0x79, 0x44, 0xe2, 0xb9, + 0xd8, 0xdd, 0x7e, 0xeb, 0xdb, 0xbf, 0xdb, 0xb5, 0x6e, 0xb, 0x64, 0x3a, 0x66, 0xab, 0x1c, 0x62, 0x3b, + 0xac, 0x19, 0x8e, 0x16, 0x0, 0xf, 0xa, 0x15, 0xc3, 0x9a, 0xfc, 0x91, 0x7d, 0xed, 0xf, 0xba, 0x5a, + 0xb7, 0x74, 0x13, 0x14, 0x22, 0x40, 0xe9, 0x22, 0x67, 0xd1, 0x25, 0x5a, 0x1, 0xae, 0x21, 0x3a, 0x9f, + 0x17, 0x2e, 0x1a, 0x0, 0x3, 0x32, 0x68, 0xec, 0x25, 0x5e}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x58, 0x30, 0xa9, 0xc1, 0x8a, 0x4, 0x9f, 0x4d, 0xcf, 0xd1, 0xbb, + 0xdb, 0x95, 0x5f, 0xef, 0xe5, 0x7c, 0x43, 0x55, 0xc8, 0xff}; + uint8_t bytesprops1[] = {0x9d, 0xa8, 0xdd, 0x4b, 0x94, 0xfb, 0x2b, 0xc9, 0x4f, 0xef, 0x10, 0xd9, 0x8d, 0xef, 0x1}; + uint8_t bytesprops2[] = {0xe9, 0x51, 0x46, 0x8e, 0x72, 0x9a, 0xd3, 0x80, 0xc1}; + uint8_t bytesprops3[] = {0xfe, 0x7a, 0x79, 0x44, 0xe2, 0xb9, 0xd8, 0xdd, 0x7e, 0xeb, 0xdb, 0xbf, + 0xdb, 0xb5, 0x6e, 0xb, 0x64, 0x3a, 0x66, 0xab, 0x1c, 0x62, 0x3b, 0xac}; + uint8_t bytesprops4[] = {0xa, 0x15, 0xc3, 0x9a, 0xfc, 0x91, 0x7d, 0xed, 0xf, 0xba, 0x5a, 0xb7, 0x74, 0x13, 0x14}; + uint8_t bytesprops5[] = {0x32, 0x68, 0xec}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)22, .value = {.str = {21, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 123}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 24}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {15, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 36}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {9, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 2597}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 21425}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {24, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 142}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {15, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 16617}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 26577}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 90}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 174}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 15007}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 46}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {3, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 94}}, + }; + + lwmqtt_properties_t props = {19, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREC_PACKET, 0, 21707, 53, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REC (PubREC 21707 53 [PropAuthenticationData +// "X0\169\193\138\EOT\159M\207\209\187\219\149_\239\229|CU\200\255",PropRetainAvailable 123,PropSubscriptionIdentifier +// 24,PropContentType "\157\168\221K\148\251+\201O\239\DLE\217\141\239\SOH",PropSubscriptionIdentifier +// 36,PropAuthenticationData "\233QF\142r\154\211\128\193",PropServerKeepAlive 2597,PropWillDelayInterval +// 21425,PropResponseTopic +// "\254zyD\226\185\216\221~\235\219\191\219\181n\vd:f\171\FSb;\172",PropRequestResponseInformation +// 142,PropAuthenticationData "\n\NAK\195\154\252\145}\237\SI\186Z\183t\DC3\DC4",PropTopicAliasMaximum +// 16617,PropTopicAliasMaximum 26577,PropRetainAvailable 90,PropPayloadFormatIndicator 174,PropReceiveMaximum +// 15007,PropRequestProblemInformation 46,PropResponseInformation "2h\236",PropRetainAvailable 94]) +TEST(PubACKREC5QCTest, Decode22) { + uint8_t pkt[] = {0x50, 0x8f, 0x1, 0x54, 0xcb, 0x35, 0x8a, 0x1, 0x16, 0x0, 0x15, 0x58, 0x30, 0xa9, 0xc1, 0x8a, 0x4, + 0x9f, 0x4d, 0xcf, 0xd1, 0xbb, 0xdb, 0x95, 0x5f, 0xef, 0xe5, 0x7c, 0x43, 0x55, 0xc8, 0xff, 0x25, 0x7b, + 0xb, 0x18, 0x3, 0x0, 0xf, 0x9d, 0xa8, 0xdd, 0x4b, 0x94, 0xfb, 0x2b, 0xc9, 0x4f, 0xef, 0x10, 0xd9, + 0x8d, 0xef, 0x1, 0xb, 0x24, 0x16, 0x0, 0x9, 0xe9, 0x51, 0x46, 0x8e, 0x72, 0x9a, 0xd3, 0x80, 0xc1, + 0x13, 0xa, 0x25, 0x18, 0x0, 0x0, 0x53, 0xb1, 0x8, 0x0, 0x18, 0xfe, 0x7a, 0x79, 0x44, 0xe2, 0xb9, + 0xd8, 0xdd, 0x7e, 0xeb, 0xdb, 0xbf, 0xdb, 0xb5, 0x6e, 0xb, 0x64, 0x3a, 0x66, 0xab, 0x1c, 0x62, 0x3b, + 0xac, 0x19, 0x8e, 0x16, 0x0, 0xf, 0xa, 0x15, 0xc3, 0x9a, 0xfc, 0x91, 0x7d, 0xed, 0xf, 0xba, 0x5a, + 0xb7, 0x74, 0x13, 0x14, 0x22, 0x40, 0xe9, 0x22, 0x67, 0xd1, 0x25, 0x5a, 0x1, 0xae, 0x21, 0x3a, 0x9f, + 0x17, 0x2e, 0x1a, 0x0, 0x3, 0x32, 0x68, 0xec, 0x25, 0x5e}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREC_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 21707); + EXPECT_EQ(status, 53); +} + +// COMP (PubCOMP 29287 222 [PropWildcardSubscriptionAvailable 71,PropPayloadFormatIndicator 233,PropTopicAliasMaximum +// 9323,PropPayloadFormatIndicator 12,PropAssignedClientIdentifier "x\DEL\166#\221\229\RS\EOT\175x",PropRetainAvailable +// 69,PropAuthenticationMethod "\192=\220K\ENQ\234\161\246"]) +TEST(PubACKCOMP5QCTest, Encode23) { + uint8_t pkt[] = {0x70, 0x27, 0x72, 0x67, 0xde, 0x23, 0x28, 0x47, 0x1, 0xe9, 0x22, 0x24, 0x6b, 0x1, + 0xc, 0x12, 0x0, 0xa, 0x78, 0x7f, 0xa6, 0x23, 0xdd, 0xe5, 0x1e, 0x4, 0xaf, 0x78, + 0x25, 0x45, 0x15, 0x0, 0x8, 0xc0, 0x3d, 0xdc, 0x4b, 0x5, 0xea, 0xa1, 0xf6}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x78, 0x7f, 0xa6, 0x23, 0xdd, 0xe5, 0x1e, 0x4, 0xaf, 0x78}; + uint8_t bytesprops1[] = {0xc0, 0x3d, 0xdc, 0x4b, 0x5, 0xea, 0xa1, 0xf6}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 71}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 233}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 9323}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 12}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {10, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 69}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {8, (char*)&bytesprops1}}}, + }; + + lwmqtt_properties_t props = {7, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, 0, 29287, 222, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 29287 222 [PropWildcardSubscriptionAvailable 71,PropPayloadFormatIndicator 233,PropTopicAliasMaximum +// 9323,PropPayloadFormatIndicator 12,PropAssignedClientIdentifier "x\DEL\166#\221\229\RS\EOT\175x",PropRetainAvailable +// 69,PropAuthenticationMethod "\192=\220K\ENQ\234\161\246"]) +TEST(PubACKCOMP5QCTest, Decode23) { + uint8_t pkt[] = {0x70, 0x27, 0x72, 0x67, 0xde, 0x23, 0x28, 0x47, 0x1, 0xe9, 0x22, 0x24, 0x6b, 0x1, + 0xc, 0x12, 0x0, 0xa, 0x78, 0x7f, 0xa6, 0x23, 0xdd, 0xe5, 0x1e, 0x4, 0xaf, 0x78, + 0x25, 0x45, 0x15, 0x0, 0x8, 0xc0, 0x3d, 0xdc, 0x4b, 0x5, 0xea, 0xa1, 0xf6}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 29287); + EXPECT_EQ(status, 222); +} + +// REL (PubREL 18324 111 [PropReasonString +// "J:\ESC\222Up\230f\236\167k\DC3\173v\215p\ACKf\204|\166R\FS\173\162\235",PropRetainAvailable +// 190,PropMessageExpiryInterval 878,PropTopicAlias 645,PropPayloadFormatIndicator 48,PropServerReference +// "\239M\214\136\&6m+\217\203\ACK1\129\RS\DC2\139\175\b\222l\129\216\198\135\&3\SI|\205\NUL",PropServerKeepAlive +// 27727,PropServerReference "6\254\177k\f\181\194uB\SOo\203d\FSR\128k\138\DC1\165Ea&",PropSessionExpiryInterval +// 5809,PropResponseInformation "`\171Buw/",PropResponseInformation "A?\196&\207\DC2",PropContentType +// "t#\176SH\250\202\218\209",PropTopicAlias 13127,PropServerKeepAlive 16925,PropTopicAliasMaximum 30413,PropTopicAlias +// 5146,PropRequestResponseInformation 168,PropTopicAliasMaximum 4732,PropMessageExpiryInterval +// 29255,PropCorrelationData "\253\SYN\184\143\224D\197\237\131\139j\208\197A\134\239F%0\229",PropResponseTopic "&\SO +// \138\&3\v",PropReceiveMaximum 7302,PropPayloadFormatIndicator 105]) +TEST(PubACKREL5QCTest, Encode24) { + uint8_t pkt[] = {0x62, 0xc8, 0x1, 0x47, 0x94, 0x6f, 0xc3, 0x1, 0x1f, 0x0, 0x1a, 0x4a, 0x3a, 0x1b, 0xde, 0x55, 0x70, + 0xe6, 0x66, 0xec, 0xa7, 0x6b, 0x13, 0xad, 0x76, 0xd7, 0x70, 0x6, 0x66, 0xcc, 0x7c, 0xa6, 0x52, 0x1c, + 0xad, 0xa2, 0xeb, 0x25, 0xbe, 0x2, 0x0, 0x0, 0x3, 0x6e, 0x23, 0x2, 0x85, 0x1, 0x30, 0x1c, 0x0, + 0x1c, 0xef, 0x4d, 0xd6, 0x88, 0x36, 0x6d, 0x2b, 0xd9, 0xcb, 0x6, 0x31, 0x81, 0x1e, 0x12, 0x8b, 0xaf, + 0x8, 0xde, 0x6c, 0x81, 0xd8, 0xc6, 0x87, 0x33, 0xf, 0x7c, 0xcd, 0x0, 0x13, 0x6c, 0x4f, 0x1c, 0x0, + 0x17, 0x36, 0xfe, 0xb1, 0x6b, 0xc, 0xb5, 0xc2, 0x75, 0x42, 0xe, 0x6f, 0xcb, 0x64, 0x1c, 0x52, 0x80, + 0x6b, 0x8a, 0x11, 0xa5, 0x45, 0x61, 0x26, 0x11, 0x0, 0x0, 0x16, 0xb1, 0x1a, 0x0, 0x6, 0x60, 0xab, + 0x42, 0x75, 0x77, 0x2f, 0x1a, 0x0, 0x6, 0x41, 0x3f, 0xc4, 0x26, 0xcf, 0x12, 0x3, 0x0, 0x9, 0x74, + 0x23, 0xb0, 0x53, 0x48, 0xfa, 0xca, 0xda, 0xd1, 0x23, 0x33, 0x47, 0x13, 0x42, 0x1d, 0x22, 0x76, 0xcd, + 0x23, 0x14, 0x1a, 0x19, 0xa8, 0x22, 0x12, 0x7c, 0x2, 0x0, 0x0, 0x72, 0x47, 0x9, 0x0, 0x14, 0xfd, + 0x16, 0xb8, 0x8f, 0xe0, 0x44, 0xc5, 0xed, 0x83, 0x8b, 0x6a, 0xd0, 0xc5, 0x41, 0x86, 0xef, 0x46, 0x25, + 0x30, 0xe5, 0x8, 0x0, 0x6, 0x26, 0xe, 0x20, 0x8a, 0x33, 0xb, 0x21, 0x1c, 0x86, 0x1, 0x69}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x4a, 0x3a, 0x1b, 0xde, 0x55, 0x70, 0xe6, 0x66, 0xec, 0xa7, 0x6b, 0x13, 0xad, + 0x76, 0xd7, 0x70, 0x6, 0x66, 0xcc, 0x7c, 0xa6, 0x52, 0x1c, 0xad, 0xa2, 0xeb}; + uint8_t bytesprops1[] = {0xef, 0x4d, 0xd6, 0x88, 0x36, 0x6d, 0x2b, 0xd9, 0xcb, 0x6, 0x31, 0x81, 0x1e, 0x12, + 0x8b, 0xaf, 0x8, 0xde, 0x6c, 0x81, 0xd8, 0xc6, 0x87, 0x33, 0xf, 0x7c, 0xcd, 0x0}; + uint8_t bytesprops2[] = {0x36, 0xfe, 0xb1, 0x6b, 0xc, 0xb5, 0xc2, 0x75, 0x42, 0xe, 0x6f, 0xcb, + 0x64, 0x1c, 0x52, 0x80, 0x6b, 0x8a, 0x11, 0xa5, 0x45, 0x61, 0x26}; + uint8_t bytesprops3[] = {0x60, 0xab, 0x42, 0x75, 0x77, 0x2f}; + uint8_t bytesprops4[] = {0x41, 0x3f, 0xc4, 0x26, 0xcf, 0x12}; + uint8_t bytesprops5[] = {0x74, 0x23, 0xb0, 0x53, 0x48, 0xfa, 0xca, 0xda, 0xd1}; + uint8_t bytesprops6[] = {0xfd, 0x16, 0xb8, 0x8f, 0xe0, 0x44, 0xc5, 0xed, 0x83, 0x8b, + 0x6a, 0xd0, 0xc5, 0x41, 0x86, 0xef, 0x46, 0x25, 0x30, 0xe5}; + uint8_t bytesprops7[] = {0x26, 0xe, 0x20, 0x8a, 0x33, 0xb}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)31, .value = {.str = {26, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 190}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 878}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 645}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 48}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {28, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 27727}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {23, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 5809}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {6, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {6, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {9, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 13127}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 16925}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 30413}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 5146}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 168}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 4732}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 29255}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {20, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {6, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 7302}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 105}}, + }; + + lwmqtt_properties_t props = {23, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 18324, 111, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 18324 111 [PropReasonString +// "J:\ESC\222Up\230f\236\167k\DC3\173v\215p\ACKf\204|\166R\FS\173\162\235",PropRetainAvailable +// 190,PropMessageExpiryInterval 878,PropTopicAlias 645,PropPayloadFormatIndicator 48,PropServerReference +// "\239M\214\136\&6m+\217\203\ACK1\129\RS\DC2\139\175\b\222l\129\216\198\135\&3\SI|\205\NUL",PropServerKeepAlive +// 27727,PropServerReference "6\254\177k\f\181\194uB\SOo\203d\FSR\128k\138\DC1\165Ea&",PropSessionExpiryInterval +// 5809,PropResponseInformation "`\171Buw/",PropResponseInformation "A?\196&\207\DC2",PropContentType +// "t#\176SH\250\202\218\209",PropTopicAlias 13127,PropServerKeepAlive 16925,PropTopicAliasMaximum 30413,PropTopicAlias +// 5146,PropRequestResponseInformation 168,PropTopicAliasMaximum 4732,PropMessageExpiryInterval +// 29255,PropCorrelationData "\253\SYN\184\143\224D\197\237\131\139j\208\197A\134\239F%0\229",PropResponseTopic "&\SO +// \138\&3\v",PropReceiveMaximum 7302,PropPayloadFormatIndicator 105]) +TEST(PubACKREL5QCTest, Decode24) { + uint8_t pkt[] = {0x62, 0xc8, 0x1, 0x47, 0x94, 0x6f, 0xc3, 0x1, 0x1f, 0x0, 0x1a, 0x4a, 0x3a, 0x1b, 0xde, 0x55, 0x70, + 0xe6, 0x66, 0xec, 0xa7, 0x6b, 0x13, 0xad, 0x76, 0xd7, 0x70, 0x6, 0x66, 0xcc, 0x7c, 0xa6, 0x52, 0x1c, + 0xad, 0xa2, 0xeb, 0x25, 0xbe, 0x2, 0x0, 0x0, 0x3, 0x6e, 0x23, 0x2, 0x85, 0x1, 0x30, 0x1c, 0x0, + 0x1c, 0xef, 0x4d, 0xd6, 0x88, 0x36, 0x6d, 0x2b, 0xd9, 0xcb, 0x6, 0x31, 0x81, 0x1e, 0x12, 0x8b, 0xaf, + 0x8, 0xde, 0x6c, 0x81, 0xd8, 0xc6, 0x87, 0x33, 0xf, 0x7c, 0xcd, 0x0, 0x13, 0x6c, 0x4f, 0x1c, 0x0, + 0x17, 0x36, 0xfe, 0xb1, 0x6b, 0xc, 0xb5, 0xc2, 0x75, 0x42, 0xe, 0x6f, 0xcb, 0x64, 0x1c, 0x52, 0x80, + 0x6b, 0x8a, 0x11, 0xa5, 0x45, 0x61, 0x26, 0x11, 0x0, 0x0, 0x16, 0xb1, 0x1a, 0x0, 0x6, 0x60, 0xab, + 0x42, 0x75, 0x77, 0x2f, 0x1a, 0x0, 0x6, 0x41, 0x3f, 0xc4, 0x26, 0xcf, 0x12, 0x3, 0x0, 0x9, 0x74, + 0x23, 0xb0, 0x53, 0x48, 0xfa, 0xca, 0xda, 0xd1, 0x23, 0x33, 0x47, 0x13, 0x42, 0x1d, 0x22, 0x76, 0xcd, + 0x23, 0x14, 0x1a, 0x19, 0xa8, 0x22, 0x12, 0x7c, 0x2, 0x0, 0x0, 0x72, 0x47, 0x9, 0x0, 0x14, 0xfd, + 0x16, 0xb8, 0x8f, 0xe0, 0x44, 0xc5, 0xed, 0x83, 0x8b, 0x6a, 0xd0, 0xc5, 0x41, 0x86, 0xef, 0x46, 0x25, + 0x30, 0xe5, 0x8, 0x0, 0x6, 0x26, 0xe, 0x20, 0x8a, 0x33, 0xb, 0x21, 0x1c, 0x86, 0x1, 0x69}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 18324); + EXPECT_EQ(status, 111); +} + +// REL (PubREL 29610 123 [PropPayloadFormatIndicator 161,PropTopicAlias 23805,PropMaximumPacketSize +// 17828,PropReceiveMaximum 22223,PropContentType +// "\SYN\215_#R=\208\180\163\DC4\209u\DLE\169M\180\176P\185\248\167\207A\243\202\222_\DC2c",PropTopicAliasMaximum +// 30063,PropTopicAliasMaximum 13424,PropAssignedClientIdentifier +// "!\252\244=\141\181t\191\218njM\154hQ[-t\206\164",PropSharedSubscriptionAvailable 223,PropReasonString +// "E\165d\207\137V\207\&5\145=\154\ENQ\251Y\136\140\188u\DEL",PropResponseTopic +// "U\136\225\205\138u\158\&5*-\179\157+\146\202",PropReceiveMaximum 16724,PropSharedSubscriptionAvailable +// 240,PropResponseInformation "\226\146\182\174",PropSharedSubscriptionAvailable 155,PropWildcardSubscriptionAvailable +// 20,PropAssignedClientIdentifier +// "]\SI^I\254\185\239\210\183\248~[\146\138\146F\128\233D\201\133\147#\165S\EOT\199Z",PropTopicAliasMaximum +// 2032,PropAuthenticationData "\254\252\176g3\155cxT",PropCorrelationData "\185\243`\164\136\169"]) +TEST(PubACKREL5QCTest, Encode25) { + uint8_t pkt[] = {0x62, 0xc0, 0x1, 0x73, 0xaa, 0x7b, 0xbb, 0x1, 0x1, 0xa1, 0x23, 0x5c, 0xfd, 0x27, 0x0, 0x0, 0x45, + 0xa4, 0x21, 0x56, 0xcf, 0x3, 0x0, 0x1d, 0x16, 0xd7, 0x5f, 0x23, 0x52, 0x3d, 0xd0, 0xb4, 0xa3, 0x14, + 0xd1, 0x75, 0x10, 0xa9, 0x4d, 0xb4, 0xb0, 0x50, 0xb9, 0xf8, 0xa7, 0xcf, 0x41, 0xf3, 0xca, 0xde, 0x5f, + 0x12, 0x63, 0x22, 0x75, 0x6f, 0x22, 0x34, 0x70, 0x12, 0x0, 0x14, 0x21, 0xfc, 0xf4, 0x3d, 0x8d, 0xb5, + 0x74, 0xbf, 0xda, 0x6e, 0x6a, 0x4d, 0x9a, 0x68, 0x51, 0x5b, 0x2d, 0x74, 0xce, 0xa4, 0x2a, 0xdf, 0x1f, + 0x0, 0x13, 0x45, 0xa5, 0x64, 0xcf, 0x89, 0x56, 0xcf, 0x35, 0x91, 0x3d, 0x9a, 0x5, 0xfb, 0x59, 0x88, + 0x8c, 0xbc, 0x75, 0x7f, 0x8, 0x0, 0xf, 0x55, 0x88, 0xe1, 0xcd, 0x8a, 0x75, 0x9e, 0x35, 0x2a, 0x2d, + 0xb3, 0x9d, 0x2b, 0x92, 0xca, 0x21, 0x41, 0x54, 0x2a, 0xf0, 0x1a, 0x0, 0x4, 0xe2, 0x92, 0xb6, 0xae, + 0x2a, 0x9b, 0x28, 0x14, 0x12, 0x0, 0x1c, 0x5d, 0xf, 0x5e, 0x49, 0xfe, 0xb9, 0xef, 0xd2, 0xb7, 0xf8, + 0x7e, 0x5b, 0x92, 0x8a, 0x92, 0x46, 0x80, 0xe9, 0x44, 0xc9, 0x85, 0x93, 0x23, 0xa5, 0x53, 0x4, 0xc7, + 0x5a, 0x22, 0x7, 0xf0, 0x16, 0x0, 0x9, 0xfe, 0xfc, 0xb0, 0x67, 0x33, 0x9b, 0x63, 0x78, 0x54, 0x9, + 0x0, 0x6, 0xb9, 0xf3, 0x60, 0xa4, 0x88, 0xa9}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x16, 0xd7, 0x5f, 0x23, 0x52, 0x3d, 0xd0, 0xb4, 0xa3, 0x14, 0xd1, 0x75, 0x10, 0xa9, 0x4d, + 0xb4, 0xb0, 0x50, 0xb9, 0xf8, 0xa7, 0xcf, 0x41, 0xf3, 0xca, 0xde, 0x5f, 0x12, 0x63}; + uint8_t bytesprops1[] = {0x21, 0xfc, 0xf4, 0x3d, 0x8d, 0xb5, 0x74, 0xbf, 0xda, 0x6e, + 0x6a, 0x4d, 0x9a, 0x68, 0x51, 0x5b, 0x2d, 0x74, 0xce, 0xa4}; + uint8_t bytesprops2[] = {0x45, 0xa5, 0x64, 0xcf, 0x89, 0x56, 0xcf, 0x35, 0x91, 0x3d, + 0x9a, 0x5, 0xfb, 0x59, 0x88, 0x8c, 0xbc, 0x75, 0x7f}; + uint8_t bytesprops3[] = {0x55, 0x88, 0xe1, 0xcd, 0x8a, 0x75, 0x9e, 0x35, 0x2a, 0x2d, 0xb3, 0x9d, 0x2b, 0x92, 0xca}; + uint8_t bytesprops4[] = {0xe2, 0x92, 0xb6, 0xae}; + uint8_t bytesprops5[] = {0x5d, 0xf, 0x5e, 0x49, 0xfe, 0xb9, 0xef, 0xd2, 0xb7, 0xf8, 0x7e, 0x5b, 0x92, 0x8a, + 0x92, 0x46, 0x80, 0xe9, 0x44, 0xc9, 0x85, 0x93, 0x23, 0xa5, 0x53, 0x4, 0xc7, 0x5a}; + uint8_t bytesprops6[] = {0xfe, 0xfc, 0xb0, 0x67, 0x33, 0x9b, 0x63, 0x78, 0x54}; + uint8_t bytesprops7[] = {0xb9, 0xf3, 0x60, 0xa4, 0x88, 0xa9}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 161}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 23805}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 17828}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 22223}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {29, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 30063}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 13424}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {20, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 223}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {19, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {15, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 16724}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 240}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {4, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 155}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 20}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {28, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 2032}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {9, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {6, (char*)&bytesprops7}}}, + }; + + lwmqtt_properties_t props = {20, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 29610, 123, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 29610 123 [PropPayloadFormatIndicator 161,PropTopicAlias 23805,PropMaximumPacketSize +// 17828,PropReceiveMaximum 22223,PropContentType +// "\SYN\215_#R=\208\180\163\DC4\209u\DLE\169M\180\176P\185\248\167\207A\243\202\222_\DC2c",PropTopicAliasMaximum +// 30063,PropTopicAliasMaximum 13424,PropAssignedClientIdentifier +// "!\252\244=\141\181t\191\218njM\154hQ[-t\206\164",PropSharedSubscriptionAvailable 223,PropReasonString +// "E\165d\207\137V\207\&5\145=\154\ENQ\251Y\136\140\188u\DEL",PropResponseTopic +// "U\136\225\205\138u\158\&5*-\179\157+\146\202",PropReceiveMaximum 16724,PropSharedSubscriptionAvailable +// 240,PropResponseInformation "\226\146\182\174",PropSharedSubscriptionAvailable 155,PropWildcardSubscriptionAvailable +// 20,PropAssignedClientIdentifier +// "]\SI^I\254\185\239\210\183\248~[\146\138\146F\128\233D\201\133\147#\165S\EOT\199Z",PropTopicAliasMaximum +// 2032,PropAuthenticationData "\254\252\176g3\155cxT",PropCorrelationData "\185\243`\164\136\169"]) +TEST(PubACKREL5QCTest, Decode25) { + uint8_t pkt[] = {0x62, 0xc0, 0x1, 0x73, 0xaa, 0x7b, 0xbb, 0x1, 0x1, 0xa1, 0x23, 0x5c, 0xfd, 0x27, 0x0, 0x0, 0x45, + 0xa4, 0x21, 0x56, 0xcf, 0x3, 0x0, 0x1d, 0x16, 0xd7, 0x5f, 0x23, 0x52, 0x3d, 0xd0, 0xb4, 0xa3, 0x14, + 0xd1, 0x75, 0x10, 0xa9, 0x4d, 0xb4, 0xb0, 0x50, 0xb9, 0xf8, 0xa7, 0xcf, 0x41, 0xf3, 0xca, 0xde, 0x5f, + 0x12, 0x63, 0x22, 0x75, 0x6f, 0x22, 0x34, 0x70, 0x12, 0x0, 0x14, 0x21, 0xfc, 0xf4, 0x3d, 0x8d, 0xb5, + 0x74, 0xbf, 0xda, 0x6e, 0x6a, 0x4d, 0x9a, 0x68, 0x51, 0x5b, 0x2d, 0x74, 0xce, 0xa4, 0x2a, 0xdf, 0x1f, + 0x0, 0x13, 0x45, 0xa5, 0x64, 0xcf, 0x89, 0x56, 0xcf, 0x35, 0x91, 0x3d, 0x9a, 0x5, 0xfb, 0x59, 0x88, + 0x8c, 0xbc, 0x75, 0x7f, 0x8, 0x0, 0xf, 0x55, 0x88, 0xe1, 0xcd, 0x8a, 0x75, 0x9e, 0x35, 0x2a, 0x2d, + 0xb3, 0x9d, 0x2b, 0x92, 0xca, 0x21, 0x41, 0x54, 0x2a, 0xf0, 0x1a, 0x0, 0x4, 0xe2, 0x92, 0xb6, 0xae, + 0x2a, 0x9b, 0x28, 0x14, 0x12, 0x0, 0x1c, 0x5d, 0xf, 0x5e, 0x49, 0xfe, 0xb9, 0xef, 0xd2, 0xb7, 0xf8, + 0x7e, 0x5b, 0x92, 0x8a, 0x92, 0x46, 0x80, 0xe9, 0x44, 0xc9, 0x85, 0x93, 0x23, 0xa5, 0x53, 0x4, 0xc7, + 0x5a, 0x22, 0x7, 0xf0, 0x16, 0x0, 0x9, 0xfe, 0xfc, 0xb0, 0x67, 0x33, 0x9b, 0x63, 0x78, 0x54, 0x9, + 0x0, 0x6, 0xb9, 0xf3, 0x60, 0xa4, 0x88, 0xa9}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 29610); + EXPECT_EQ(status, 123); +} + +// REC (PubREC 5042 130 [PropReasonString "-:\ENQ\200\128]Qhp",PropTopicAlias 16967,PropMaximumPacketSize +// 19421,PropAuthenticationMethod +// "=\244\181\222c\166\157\165\142]\192\195x\134H\209r.\188\\\148\161\233X\239A\FS\FS",PropMaximumQoS +// 197,PropServerKeepAlive 14666,PropMessageExpiryInterval 23256,PropSharedSubscriptionAvailable 177,PropReasonString +// "\195*\138\162\246\EOTnB!",PropAssignedClientIdentifier +// "[\SYN\209\234,,\142\206\150'i\210i\ETB",PropTopicAliasMaximum 27211,PropTopicAlias 24037,PropPayloadFormatIndicator +// 138,PropContentType "-\130\204\243cF\DC1\175)",PropSubscriptionIdentifierAvailable 43,PropAuthenticationData +// "B\DLE",PropCorrelationData "\151\143\ETB\199\202\184\230\188\193J\202}(\208\166\&4",PropAssignedClientIdentifier +// "\138z\177\EOT\222\&7\194w\215\&9;[0X\SOH\142>\ESC\t\234u\176\197\vf",PropSubscriptionIdentifier 4,PropReasonString +// "\216p\232\SI\213\143\198\158\210IB\138\238Q\148zC\174\b\244\141\224\236U4\229\165\154",PropServerReference +// "\224\207\191"]) +TEST(PubACKREC5QCTest, Encode26) { + uint8_t pkt[] = {0x50, 0xd2, 0x1, 0x13, 0xb2, 0x82, 0xcd, 0x1, 0x1f, 0x0, 0x9, 0x2d, 0x3a, 0x5, 0xc8, 0x80, 0x5d, + 0x51, 0x68, 0x70, 0x23, 0x42, 0x47, 0x27, 0x0, 0x0, 0x4b, 0xdd, 0x15, 0x0, 0x1c, 0x3d, 0xf4, 0xb5, + 0xde, 0x63, 0xa6, 0x9d, 0xa5, 0x8e, 0x5d, 0xc0, 0xc3, 0x78, 0x86, 0x48, 0xd1, 0x72, 0x2e, 0xbc, 0x5c, + 0x94, 0xa1, 0xe9, 0x58, 0xef, 0x41, 0x1c, 0x1c, 0x24, 0xc5, 0x13, 0x39, 0x4a, 0x2, 0x0, 0x0, 0x5a, + 0xd8, 0x2a, 0xb1, 0x1f, 0x0, 0x9, 0xc3, 0x2a, 0x8a, 0xa2, 0xf6, 0x4, 0x6e, 0x42, 0x21, 0x12, 0x0, + 0xe, 0x5b, 0x16, 0xd1, 0xea, 0x2c, 0x2c, 0x8e, 0xce, 0x96, 0x27, 0x69, 0xd2, 0x69, 0x17, 0x22, 0x6a, + 0x4b, 0x23, 0x5d, 0xe5, 0x1, 0x8a, 0x3, 0x0, 0x9, 0x2d, 0x82, 0xcc, 0xf3, 0x63, 0x46, 0x11, 0xaf, + 0x29, 0x29, 0x2b, 0x16, 0x0, 0x2, 0x42, 0x10, 0x9, 0x0, 0x10, 0x97, 0x8f, 0x17, 0xc7, 0xca, 0xb8, + 0xe6, 0xbc, 0xc1, 0x4a, 0xca, 0x7d, 0x28, 0xd0, 0xa6, 0x34, 0x12, 0x0, 0x19, 0x8a, 0x7a, 0xb1, 0x4, + 0xde, 0x37, 0xc2, 0x77, 0xd7, 0x39, 0x3b, 0x5b, 0x30, 0x58, 0x1, 0x8e, 0x3e, 0x1b, 0x9, 0xea, 0x75, + 0xb0, 0xc5, 0xb, 0x66, 0xb, 0x4, 0x1f, 0x0, 0x1c, 0xd8, 0x70, 0xe8, 0xf, 0xd5, 0x8f, 0xc6, 0x9e, + 0xd2, 0x49, 0x42, 0x8a, 0xee, 0x51, 0x94, 0x7a, 0x43, 0xae, 0x8, 0xf4, 0x8d, 0xe0, 0xec, 0x55, 0x34, + 0xe5, 0xa5, 0x9a, 0x1c, 0x0, 0x3, 0xe0, 0xcf, 0xbf}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x2d, 0x3a, 0x5, 0xc8, 0x80, 0x5d, 0x51, 0x68, 0x70}; + uint8_t bytesprops1[] = {0x3d, 0xf4, 0xb5, 0xde, 0x63, 0xa6, 0x9d, 0xa5, 0x8e, 0x5d, 0xc0, 0xc3, 0x78, 0x86, + 0x48, 0xd1, 0x72, 0x2e, 0xbc, 0x5c, 0x94, 0xa1, 0xe9, 0x58, 0xef, 0x41, 0x1c, 0x1c}; + uint8_t bytesprops2[] = {0xc3, 0x2a, 0x8a, 0xa2, 0xf6, 0x4, 0x6e, 0x42, 0x21}; + uint8_t bytesprops3[] = {0x5b, 0x16, 0xd1, 0xea, 0x2c, 0x2c, 0x8e, 0xce, 0x96, 0x27, 0x69, 0xd2, 0x69, 0x17}; + uint8_t bytesprops4[] = {0x2d, 0x82, 0xcc, 0xf3, 0x63, 0x46, 0x11, 0xaf, 0x29}; + uint8_t bytesprops5[] = {0x42, 0x10}; + uint8_t bytesprops6[] = {0x97, 0x8f, 0x17, 0xc7, 0xca, 0xb8, 0xe6, 0xbc, + 0xc1, 0x4a, 0xca, 0x7d, 0x28, 0xd0, 0xa6, 0x34}; + uint8_t bytesprops7[] = {0x8a, 0x7a, 0xb1, 0x4, 0xde, 0x37, 0xc2, 0x77, 0xd7, 0x39, 0x3b, 0x5b, 0x30, + 0x58, 0x1, 0x8e, 0x3e, 0x1b, 0x9, 0xea, 0x75, 0xb0, 0xc5, 0xb, 0x66}; + uint8_t bytesprops8[] = {0xd8, 0x70, 0xe8, 0xf, 0xd5, 0x8f, 0xc6, 0x9e, 0xd2, 0x49, 0x42, 0x8a, 0xee, 0x51, + 0x94, 0x7a, 0x43, 0xae, 0x8, 0xf4, 0x8d, 0xe0, 0xec, 0x55, 0x34, 0xe5, 0xa5, 0x9a}; + uint8_t bytesprops9[] = {0xe0, 0xcf, 0xbf}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)31, .value = {.str = {9, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 16967}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 19421}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {28, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 197}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 14666}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 23256}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 177}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {9, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {14, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 27211}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 24037}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 138}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {9, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 43}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {2, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {16, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {25, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 4}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {28, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {3, (char*)&bytesprops9}}}, + }; + + lwmqtt_properties_t props = {21, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREC_PACKET, 0, 5042, 130, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REC (PubREC 5042 130 [PropReasonString "-:\ENQ\200\128]Qhp",PropTopicAlias 16967,PropMaximumPacketSize +// 19421,PropAuthenticationMethod +// "=\244\181\222c\166\157\165\142]\192\195x\134H\209r.\188\\\148\161\233X\239A\FS\FS",PropMaximumQoS +// 197,PropServerKeepAlive 14666,PropMessageExpiryInterval 23256,PropSharedSubscriptionAvailable 177,PropReasonString +// "\195*\138\162\246\EOTnB!",PropAssignedClientIdentifier +// "[\SYN\209\234,,\142\206\150'i\210i\ETB",PropTopicAliasMaximum 27211,PropTopicAlias 24037,PropPayloadFormatIndicator +// 138,PropContentType "-\130\204\243cF\DC1\175)",PropSubscriptionIdentifierAvailable 43,PropAuthenticationData +// "B\DLE",PropCorrelationData "\151\143\ETB\199\202\184\230\188\193J\202}(\208\166\&4",PropAssignedClientIdentifier +// "\138z\177\EOT\222\&7\194w\215\&9;[0X\SOH\142>\ESC\t\234u\176\197\vf",PropSubscriptionIdentifier 4,PropReasonString +// "\216p\232\SI\213\143\198\158\210IB\138\238Q\148zC\174\b\244\141\224\236U4\229\165\154",PropServerReference +// "\224\207\191"]) +TEST(PubACKREC5QCTest, Decode26) { + uint8_t pkt[] = {0x50, 0xd2, 0x1, 0x13, 0xb2, 0x82, 0xcd, 0x1, 0x1f, 0x0, 0x9, 0x2d, 0x3a, 0x5, 0xc8, 0x80, 0x5d, + 0x51, 0x68, 0x70, 0x23, 0x42, 0x47, 0x27, 0x0, 0x0, 0x4b, 0xdd, 0x15, 0x0, 0x1c, 0x3d, 0xf4, 0xb5, + 0xde, 0x63, 0xa6, 0x9d, 0xa5, 0x8e, 0x5d, 0xc0, 0xc3, 0x78, 0x86, 0x48, 0xd1, 0x72, 0x2e, 0xbc, 0x5c, + 0x94, 0xa1, 0xe9, 0x58, 0xef, 0x41, 0x1c, 0x1c, 0x24, 0xc5, 0x13, 0x39, 0x4a, 0x2, 0x0, 0x0, 0x5a, + 0xd8, 0x2a, 0xb1, 0x1f, 0x0, 0x9, 0xc3, 0x2a, 0x8a, 0xa2, 0xf6, 0x4, 0x6e, 0x42, 0x21, 0x12, 0x0, + 0xe, 0x5b, 0x16, 0xd1, 0xea, 0x2c, 0x2c, 0x8e, 0xce, 0x96, 0x27, 0x69, 0xd2, 0x69, 0x17, 0x22, 0x6a, + 0x4b, 0x23, 0x5d, 0xe5, 0x1, 0x8a, 0x3, 0x0, 0x9, 0x2d, 0x82, 0xcc, 0xf3, 0x63, 0x46, 0x11, 0xaf, + 0x29, 0x29, 0x2b, 0x16, 0x0, 0x2, 0x42, 0x10, 0x9, 0x0, 0x10, 0x97, 0x8f, 0x17, 0xc7, 0xca, 0xb8, + 0xe6, 0xbc, 0xc1, 0x4a, 0xca, 0x7d, 0x28, 0xd0, 0xa6, 0x34, 0x12, 0x0, 0x19, 0x8a, 0x7a, 0xb1, 0x4, + 0xde, 0x37, 0xc2, 0x77, 0xd7, 0x39, 0x3b, 0x5b, 0x30, 0x58, 0x1, 0x8e, 0x3e, 0x1b, 0x9, 0xea, 0x75, + 0xb0, 0xc5, 0xb, 0x66, 0xb, 0x4, 0x1f, 0x0, 0x1c, 0xd8, 0x70, 0xe8, 0xf, 0xd5, 0x8f, 0xc6, 0x9e, + 0xd2, 0x49, 0x42, 0x8a, 0xee, 0x51, 0x94, 0x7a, 0x43, 0xae, 0x8, 0xf4, 0x8d, 0xe0, 0xec, 0x55, 0x34, + 0xe5, 0xa5, 0x9a, 0x1c, 0x0, 0x3, 0xe0, 0xcf, 0xbf}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREC_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 5042); + EXPECT_EQ(status, 130); +} + +// REL (PubREL 2316 5 [PropReasonString "\140\&0\t",PropResponseTopic +// "\167\211\185\vB\243\DC3Rv\t\f$9eBk|\222}",PropWillDelayInterval 7302,PropMessageExpiryInterval +// 20574,PropRequestResponseInformation 236,PropMessageExpiryInterval 20490,PropResponseInformation +// "\237\202t|8\137\CAN\DC2/\129",PropTopicAliasMaximum 18528,PropResponseTopic "4P\169\216$",PropCorrelationData +// "\GS\ACK%@\250\220\&2Pm\233\233\196\228\SYN=7)\SO\173(\199\165x\155nQ",PropAuthenticationData +// "\225\253\211\167a\183B6\237k\EMtP-\129\249\231\SO\141\140",PropMessageExpiryInterval 9082,PropMaximumQoS +// 91,PropServerReference "\205\148 Q\141-8\164\178\208{\SI\213\220.\191\147<",PropPayloadFormatIndicator +// 210,PropWillDelayInterval 6198,PropAuthenticationData +// "y\DEL\231\154\135:J$\146^l3@\241\DC26\DEL,A\NAKyp",PropSubscriptionIdentifier 4,PropAuthenticationData +// "\v\175\166\239T\DC3@p\ETX\170\135V\229\236\SI\140*h\211\191D\137\203p\145$",PropSubscriptionIdentifier +// 6,PropWillDelayInterval 37,PropSubscriptionIdentifier 3,PropRequestResponseInformation 196,PropResponseInformation +// "Uw\153\175\ETB\187\138!"]) +TEST(PubACKREL5QCTest, Encode27) { + uint8_t pkt[] = { + 0x62, 0xef, 0x1, 0x9, 0xc, 0x5, 0xea, 0x1, 0x1f, 0x0, 0x3, 0x8c, 0x30, 0x9, 0x8, 0x0, 0x13, 0xa7, 0xd3, + 0xb9, 0xb, 0x42, 0xf3, 0x13, 0x52, 0x76, 0x9, 0xc, 0x24, 0x39, 0x65, 0x42, 0x6b, 0x7c, 0xde, 0x7d, 0x18, 0x0, + 0x0, 0x1c, 0x86, 0x2, 0x0, 0x0, 0x50, 0x5e, 0x19, 0xec, 0x2, 0x0, 0x0, 0x50, 0xa, 0x1a, 0x0, 0xa, 0xed, + 0xca, 0x74, 0x7c, 0x38, 0x89, 0x18, 0x12, 0x2f, 0x81, 0x22, 0x48, 0x60, 0x8, 0x0, 0x5, 0x34, 0x50, 0xa9, 0xd8, + 0x24, 0x9, 0x0, 0x1a, 0x1d, 0x6, 0x25, 0x40, 0xfa, 0xdc, 0x32, 0x50, 0x6d, 0xe9, 0xe9, 0xc4, 0xe4, 0x16, 0x3d, + 0x37, 0x29, 0xe, 0xad, 0x28, 0xc7, 0xa5, 0x78, 0x9b, 0x6e, 0x51, 0x16, 0x0, 0x14, 0xe1, 0xfd, 0xd3, 0xa7, 0x61, + 0xb7, 0x42, 0x36, 0xed, 0x6b, 0x19, 0x74, 0x50, 0x2d, 0x81, 0xf9, 0xe7, 0xe, 0x8d, 0x8c, 0x2, 0x0, 0x0, 0x23, + 0x7a, 0x24, 0x5b, 0x1c, 0x0, 0x12, 0xcd, 0x94, 0x20, 0x51, 0x8d, 0x2d, 0x38, 0xa4, 0xb2, 0xd0, 0x7b, 0xf, 0xd5, + 0xdc, 0x2e, 0xbf, 0x93, 0x3c, 0x1, 0xd2, 0x18, 0x0, 0x0, 0x18, 0x36, 0x16, 0x0, 0x16, 0x79, 0x7f, 0xe7, 0x9a, + 0x87, 0x3a, 0x4a, 0x24, 0x92, 0x5e, 0x6c, 0x33, 0x40, 0xf1, 0x12, 0x36, 0x7f, 0x2c, 0x41, 0x15, 0x79, 0x70, 0xb, + 0x4, 0x16, 0x0, 0x1a, 0xb, 0xaf, 0xa6, 0xef, 0x54, 0x13, 0x40, 0x70, 0x3, 0xaa, 0x87, 0x56, 0xe5, 0xec, 0xf, + 0x8c, 0x2a, 0x68, 0xd3, 0xbf, 0x44, 0x89, 0xcb, 0x70, 0x91, 0x24, 0xb, 0x6, 0x18, 0x0, 0x0, 0x0, 0x25, 0xb, + 0x3, 0x19, 0xc4, 0x1a, 0x0, 0x8, 0x55, 0x77, 0x99, 0xaf, 0x17, 0xbb, 0x8a, 0x21}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x8c, 0x30, 0x9}; + uint8_t bytesprops1[] = {0xa7, 0xd3, 0xb9, 0xb, 0x42, 0xf3, 0x13, 0x52, 0x76, 0x9, + 0xc, 0x24, 0x39, 0x65, 0x42, 0x6b, 0x7c, 0xde, 0x7d}; + uint8_t bytesprops2[] = {0xed, 0xca, 0x74, 0x7c, 0x38, 0x89, 0x18, 0x12, 0x2f, 0x81}; + uint8_t bytesprops3[] = {0x34, 0x50, 0xa9, 0xd8, 0x24}; + uint8_t bytesprops4[] = {0x1d, 0x6, 0x25, 0x40, 0xfa, 0xdc, 0x32, 0x50, 0x6d, 0xe9, 0xe9, 0xc4, 0xe4, + 0x16, 0x3d, 0x37, 0x29, 0xe, 0xad, 0x28, 0xc7, 0xa5, 0x78, 0x9b, 0x6e, 0x51}; + uint8_t bytesprops5[] = {0xe1, 0xfd, 0xd3, 0xa7, 0x61, 0xb7, 0x42, 0x36, 0xed, 0x6b, + 0x19, 0x74, 0x50, 0x2d, 0x81, 0xf9, 0xe7, 0xe, 0x8d, 0x8c}; + uint8_t bytesprops6[] = {0xcd, 0x94, 0x20, 0x51, 0x8d, 0x2d, 0x38, 0xa4, 0xb2, + 0xd0, 0x7b, 0xf, 0xd5, 0xdc, 0x2e, 0xbf, 0x93, 0x3c}; + uint8_t bytesprops7[] = {0x79, 0x7f, 0xe7, 0x9a, 0x87, 0x3a, 0x4a, 0x24, 0x92, 0x5e, 0x6c, + 0x33, 0x40, 0xf1, 0x12, 0x36, 0x7f, 0x2c, 0x41, 0x15, 0x79, 0x70}; + uint8_t bytesprops8[] = {0xb, 0xaf, 0xa6, 0xef, 0x54, 0x13, 0x40, 0x70, 0x3, 0xaa, 0x87, 0x56, 0xe5, + 0xec, 0xf, 0x8c, 0x2a, 0x68, 0xd3, 0xbf, 0x44, 0x89, 0xcb, 0x70, 0x91, 0x24}; + uint8_t bytesprops9[] = {0x55, 0x77, 0x99, 0xaf, 0x17, 0xbb, 0x8a, 0x21}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)31, .value = {.str = {3, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {19, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 7302}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 20574}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 236}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 20490}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {10, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 18528}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {5, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {26, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {20, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 9082}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 91}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {18, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 210}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 6198}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {22, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 4}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {26, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 6}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 37}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 3}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 196}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {8, (char*)&bytesprops9}}}, + }; + + lwmqtt_properties_t props = {24, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 2316, 5, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 2316 5 [PropReasonString "\140\&0\t",PropResponseTopic +// "\167\211\185\vB\243\DC3Rv\t\f$9eBk|\222}",PropWillDelayInterval 7302,PropMessageExpiryInterval +// 20574,PropRequestResponseInformation 236,PropMessageExpiryInterval 20490,PropResponseInformation +// "\237\202t|8\137\CAN\DC2/\129",PropTopicAliasMaximum 18528,PropResponseTopic "4P\169\216$",PropCorrelationData +// "\GS\ACK%@\250\220\&2Pm\233\233\196\228\SYN=7)\SO\173(\199\165x\155nQ",PropAuthenticationData +// "\225\253\211\167a\183B6\237k\EMtP-\129\249\231\SO\141\140",PropMessageExpiryInterval 9082,PropMaximumQoS +// 91,PropServerReference "\205\148 Q\141-8\164\178\208{\SI\213\220.\191\147<",PropPayloadFormatIndicator +// 210,PropWillDelayInterval 6198,PropAuthenticationData +// "y\DEL\231\154\135:J$\146^l3@\241\DC26\DEL,A\NAKyp",PropSubscriptionIdentifier 4,PropAuthenticationData +// "\v\175\166\239T\DC3@p\ETX\170\135V\229\236\SI\140*h\211\191D\137\203p\145$",PropSubscriptionIdentifier +// 6,PropWillDelayInterval 37,PropSubscriptionIdentifier 3,PropRequestResponseInformation 196,PropResponseInformation +// "Uw\153\175\ETB\187\138!"]) +TEST(PubACKREL5QCTest, Decode27) { + uint8_t pkt[] = { + 0x62, 0xef, 0x1, 0x9, 0xc, 0x5, 0xea, 0x1, 0x1f, 0x0, 0x3, 0x8c, 0x30, 0x9, 0x8, 0x0, 0x13, 0xa7, 0xd3, + 0xb9, 0xb, 0x42, 0xf3, 0x13, 0x52, 0x76, 0x9, 0xc, 0x24, 0x39, 0x65, 0x42, 0x6b, 0x7c, 0xde, 0x7d, 0x18, 0x0, + 0x0, 0x1c, 0x86, 0x2, 0x0, 0x0, 0x50, 0x5e, 0x19, 0xec, 0x2, 0x0, 0x0, 0x50, 0xa, 0x1a, 0x0, 0xa, 0xed, + 0xca, 0x74, 0x7c, 0x38, 0x89, 0x18, 0x12, 0x2f, 0x81, 0x22, 0x48, 0x60, 0x8, 0x0, 0x5, 0x34, 0x50, 0xa9, 0xd8, + 0x24, 0x9, 0x0, 0x1a, 0x1d, 0x6, 0x25, 0x40, 0xfa, 0xdc, 0x32, 0x50, 0x6d, 0xe9, 0xe9, 0xc4, 0xe4, 0x16, 0x3d, + 0x37, 0x29, 0xe, 0xad, 0x28, 0xc7, 0xa5, 0x78, 0x9b, 0x6e, 0x51, 0x16, 0x0, 0x14, 0xe1, 0xfd, 0xd3, 0xa7, 0x61, + 0xb7, 0x42, 0x36, 0xed, 0x6b, 0x19, 0x74, 0x50, 0x2d, 0x81, 0xf9, 0xe7, 0xe, 0x8d, 0x8c, 0x2, 0x0, 0x0, 0x23, + 0x7a, 0x24, 0x5b, 0x1c, 0x0, 0x12, 0xcd, 0x94, 0x20, 0x51, 0x8d, 0x2d, 0x38, 0xa4, 0xb2, 0xd0, 0x7b, 0xf, 0xd5, + 0xdc, 0x2e, 0xbf, 0x93, 0x3c, 0x1, 0xd2, 0x18, 0x0, 0x0, 0x18, 0x36, 0x16, 0x0, 0x16, 0x79, 0x7f, 0xe7, 0x9a, + 0x87, 0x3a, 0x4a, 0x24, 0x92, 0x5e, 0x6c, 0x33, 0x40, 0xf1, 0x12, 0x36, 0x7f, 0x2c, 0x41, 0x15, 0x79, 0x70, 0xb, + 0x4, 0x16, 0x0, 0x1a, 0xb, 0xaf, 0xa6, 0xef, 0x54, 0x13, 0x40, 0x70, 0x3, 0xaa, 0x87, 0x56, 0xe5, 0xec, 0xf, + 0x8c, 0x2a, 0x68, 0xd3, 0xbf, 0x44, 0x89, 0xcb, 0x70, 0x91, 0x24, 0xb, 0x6, 0x18, 0x0, 0x0, 0x0, 0x25, 0xb, + 0x3, 0x19, 0xc4, 0x1a, 0x0, 0x8, 0x55, 0x77, 0x99, 0xaf, 0x17, 0xbb, 0x8a, 0x21}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 2316); + EXPECT_EQ(status, 5); +} + +// REL (PubREL 28050 34 [PropReceiveMaximum 9193,PropTopicAliasMaximum 16058,PropRequestProblemInformation +// 229,PropMaximumQoS 173,PropCorrelationData +// "\190\249\146g^\192\234\138\255`\166\134\US\223r\180\239\242\207",PropUserProperty +// "\179\245\tYAyMx\147\190X,\SYN\v^\144}\153\177\162\168\156\172" +// "\152\DC47\189\147.\248\SIA\249\177j\197\198\207J\247\214\221\172#@\174?",PropAuthenticationMethod +// "\217\155\130\162\ENQ\139\229fj\EOTdOCB",PropServerKeepAlive 11033,PropRetainAvailable 90,PropMessageExpiryInterval +// 5639,PropTopicAlias 25349,PropResponseInformation +// "\197\183C\"\220\240\151\137\FS\158}\FS\218+b\249d\176\135\172",PropTopicAlias 15096]) +TEST(PubACKREL5QCTest, Encode28) { + uint8_t pkt[] = {0x62, 0x91, 0x1, 0x6d, 0x92, 0x22, 0x8c, 0x1, 0x21, 0x23, 0xe9, 0x22, 0x3e, 0xba, 0x17, 0xe5, 0x24, + 0xad, 0x9, 0x0, 0x13, 0xbe, 0xf9, 0x92, 0x67, 0x5e, 0xc0, 0xea, 0x8a, 0xff, 0x60, 0xa6, 0x86, 0x1f, + 0xdf, 0x72, 0xb4, 0xef, 0xf2, 0xcf, 0x26, 0x0, 0x17, 0xb3, 0xf5, 0x9, 0x59, 0x41, 0x79, 0x4d, 0x78, + 0x93, 0xbe, 0x58, 0x2c, 0x16, 0xb, 0x5e, 0x90, 0x7d, 0x99, 0xb1, 0xa2, 0xa8, 0x9c, 0xac, 0x0, 0x18, + 0x98, 0x14, 0x37, 0xbd, 0x93, 0x2e, 0xf8, 0xf, 0x41, 0xf9, 0xb1, 0x6a, 0xc5, 0xc6, 0xcf, 0x4a, 0xf7, + 0xd6, 0xdd, 0xac, 0x23, 0x40, 0xae, 0x3f, 0x15, 0x0, 0xe, 0xd9, 0x9b, 0x82, 0xa2, 0x5, 0x8b, 0xe5, + 0x66, 0x6a, 0x4, 0x64, 0x4f, 0x43, 0x42, 0x13, 0x2b, 0x19, 0x25, 0x5a, 0x2, 0x0, 0x0, 0x16, 0x7, + 0x23, 0x63, 0x5, 0x1a, 0x0, 0x14, 0xc5, 0xb7, 0x43, 0x22, 0xdc, 0xf0, 0x97, 0x89, 0x1c, 0x9e, 0x7d, + 0x1c, 0xda, 0x2b, 0x62, 0xf9, 0x64, 0xb0, 0x87, 0xac, 0x23, 0x3a, 0xf8}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0xbe, 0xf9, 0x92, 0x67, 0x5e, 0xc0, 0xea, 0x8a, 0xff, 0x60, + 0xa6, 0x86, 0x1f, 0xdf, 0x72, 0xb4, 0xef, 0xf2, 0xcf}; + uint8_t bytesprops2[] = {0x98, 0x14, 0x37, 0xbd, 0x93, 0x2e, 0xf8, 0xf, 0x41, 0xf9, 0xb1, 0x6a, + 0xc5, 0xc6, 0xcf, 0x4a, 0xf7, 0xd6, 0xdd, 0xac, 0x23, 0x40, 0xae, 0x3f}; + uint8_t bytesprops1[] = {0xb3, 0xf5, 0x9, 0x59, 0x41, 0x79, 0x4d, 0x78, 0x93, 0xbe, 0x58, 0x2c, + 0x16, 0xb, 0x5e, 0x90, 0x7d, 0x99, 0xb1, 0xa2, 0xa8, 0x9c, 0xac}; + uint8_t bytesprops3[] = {0xd9, 0x9b, 0x82, 0xa2, 0x5, 0x8b, 0xe5, 0x66, 0x6a, 0x4, 0x64, 0x4f, 0x43, 0x42}; + uint8_t bytesprops4[] = {0xc5, 0xb7, 0x43, 0x22, 0xdc, 0xf0, 0x97, 0x89, 0x1c, 0x9e, + 0x7d, 0x1c, 0xda, 0x2b, 0x62, 0xf9, 0x64, 0xb0, 0x87, 0xac}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 9193}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 16058}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 229}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 173}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {19, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {23, (char*)&bytesprops1}, .v = {24, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {14, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 11033}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 90}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 5639}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 25349}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {20, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 15096}}, + }; + + lwmqtt_properties_t props = {13, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, 0, 28050, 34, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// REL (PubREL 28050 34 [PropReceiveMaximum 9193,PropTopicAliasMaximum 16058,PropRequestProblemInformation +// 229,PropMaximumQoS 173,PropCorrelationData +// "\190\249\146g^\192\234\138\255`\166\134\US\223r\180\239\242\207",PropUserProperty +// "\179\245\tYAyMx\147\190X,\SYN\v^\144}\153\177\162\168\156\172" +// "\152\DC47\189\147.\248\SIA\249\177j\197\198\207J\247\214\221\172#@\174?",PropAuthenticationMethod +// "\217\155\130\162\ENQ\139\229fj\EOTdOCB",PropServerKeepAlive 11033,PropRetainAvailable 90,PropMessageExpiryInterval +// 5639,PropTopicAlias 25349,PropResponseInformation +// "\197\183C\"\220\240\151\137\FS\158}\FS\218+b\249d\176\135\172",PropTopicAlias 15096]) +TEST(PubACKREL5QCTest, Decode28) { + uint8_t pkt[] = {0x62, 0x91, 0x1, 0x6d, 0x92, 0x22, 0x8c, 0x1, 0x21, 0x23, 0xe9, 0x22, 0x3e, 0xba, 0x17, 0xe5, 0x24, + 0xad, 0x9, 0x0, 0x13, 0xbe, 0xf9, 0x92, 0x67, 0x5e, 0xc0, 0xea, 0x8a, 0xff, 0x60, 0xa6, 0x86, 0x1f, + 0xdf, 0x72, 0xb4, 0xef, 0xf2, 0xcf, 0x26, 0x0, 0x17, 0xb3, 0xf5, 0x9, 0x59, 0x41, 0x79, 0x4d, 0x78, + 0x93, 0xbe, 0x58, 0x2c, 0x16, 0xb, 0x5e, 0x90, 0x7d, 0x99, 0xb1, 0xa2, 0xa8, 0x9c, 0xac, 0x0, 0x18, + 0x98, 0x14, 0x37, 0xbd, 0x93, 0x2e, 0xf8, 0xf, 0x41, 0xf9, 0xb1, 0x6a, 0xc5, 0xc6, 0xcf, 0x4a, 0xf7, + 0xd6, 0xdd, 0xac, 0x23, 0x40, 0xae, 0x3f, 0x15, 0x0, 0xe, 0xd9, 0x9b, 0x82, 0xa2, 0x5, 0x8b, 0xe5, + 0x66, 0x6a, 0x4, 0x64, 0x4f, 0x43, 0x42, 0x13, 0x2b, 0x19, 0x25, 0x5a, 0x2, 0x0, 0x0, 0x16, 0x7, + 0x23, 0x63, 0x5, 0x1a, 0x0, 0x14, 0xc5, 0xb7, 0x43, 0x22, 0xdc, 0xf0, 0x97, 0x89, 0x1c, 0x9e, 0x7d, + 0x1c, 0xda, 0x2b, 0x62, 0xf9, 0x64, 0xb0, 0x87, 0xac, 0x23, 0x3a, 0xf8}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBREL_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 28050); + EXPECT_EQ(status, 34); +} + +// COMP (PubCOMP 17627 140 [PropAuthenticationMethod +// "\129\DC4\DC4O\189z\EOT\223\251\219\245\159\252\143D\180Tf\255\DC3\175w\185\r;p",PropSubscriptionIdentifierAvailable +// 9,PropServerKeepAlive 19683,PropWillDelayInterval 5690]) +TEST(PubACKCOMP5QCTest, Encode29) { + uint8_t pkt[] = {0x70, 0x2b, 0x44, 0xdb, 0x8c, 0x27, 0x15, 0x0, 0x1a, 0x81, 0x14, 0x14, 0x4f, 0xbd, 0x7a, + 0x4, 0xdf, 0xfb, 0xdb, 0xf5, 0x9f, 0xfc, 0x8f, 0x44, 0xb4, 0x54, 0x66, 0xff, 0x13, 0xaf, + 0x77, 0xb9, 0xd, 0x3b, 0x70, 0x29, 0x9, 0x13, 0x4c, 0xe3, 0x18, 0x0, 0x0, 0x16, 0x3a}; + uint8_t buf[sizeof(pkt) + 10]; + uint8_t bytesprops0[] = {0x81, 0x14, 0x14, 0x4f, 0xbd, 0x7a, 0x4, 0xdf, 0xfb, 0xdb, 0xf5, 0x9f, 0xfc, + 0x8f, 0x44, 0xb4, 0x54, 0x66, 0xff, 0x13, 0xaf, 0x77, 0xb9, 0xd, 0x3b, 0x70}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)21, .value = {.str = {26, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 9}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 19683}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 5690}}, + }; + + lwmqtt_properties_t props = {4, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = + lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, 0, 17627, 140, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 17627 140 [PropAuthenticationMethod +// "\129\DC4\DC4O\189z\EOT\223\251\219\245\159\252\143D\180Tf\255\DC3\175w\185\r;p",PropSubscriptionIdentifierAvailable +// 9,PropServerKeepAlive 19683,PropWillDelayInterval 5690]) +TEST(PubACKCOMP5QCTest, Decode29) { + uint8_t pkt[] = {0x70, 0x2b, 0x44, 0xdb, 0x8c, 0x27, 0x15, 0x0, 0x1a, 0x81, 0x14, 0x14, 0x4f, 0xbd, 0x7a, + 0x4, 0xdf, 0xfb, 0xdb, 0xf5, 0x9f, 0xfc, 0x8f, 0x44, 0xb4, 0x54, 0x66, 0xff, 0x13, 0xaf, + 0x77, 0xb9, 0xd, 0x3b, 0x70, 0x29, 0x9, 0x13, 0x4c, 0xe3, 0x18, 0x0, 0x0, 0x16, 0x3a}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 17627); + EXPECT_EQ(status, 140); +} + +// COMP (PubCOMP 5627 57 [PropRequestResponseInformation 202]) +TEST(PubACKCOMP5QCTest, Encode30) { + uint8_t pkt[] = {0x70, 0x6, 0x15, 0xfb, 0x39, 0x2, 0x19, 0xca}; + uint8_t buf[sizeof(pkt) + 10]; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 202}}, + }; + + lwmqtt_properties_t props = {1, (lwmqtt_property_t*)&propslist}; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_ack(buf, sizeof(buf), &len, LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, 0, 5627, 57, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// COMP (PubCOMP 5627 57 [PropRequestResponseInformation 202]) +TEST(PubACKCOMP5QCTest, Decode30) { + uint8_t pkt[] = {0x70, 0x6, 0x15, 0xfb, 0x39, 0x2, 0x19, 0xca}; + uint16_t packet_id; + uint8_t status; + lwmqtt_serialized_properties_t props; + bool dup; + lwmqtt_err_t err = + lwmqtt_decode_ack(pkt, sizeof(pkt), LWMQTT_MQTT5, LWMQTT_PUBCOMP_PACKET, &dup, &packet_id, &status, &props); + EXPECT_EQ(err, LWMQTT_PUBACK_NACKED); + EXPECT_EQ(packet_id, 5627); + EXPECT_EQ(status, 57); +} + +// ConnectRequest {_username = Just "\153L\a#", _password = Just "\244\162\153\142%\219Js!\226", _lastWill = Nothing, +// _cleanSession = True, _keepAlive = 2234, _connID = "E\DC4X\158P\157\128Y{\243sRl\186'", _properties = []} +TEST(Connect311QCTest, Encode1) { + uint8_t pkt[] = {0x10, 0x2d, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xc2, 0x8, 0xba, 0x0, 0xf, 0x45, 0x14, + 0x58, 0x9e, 0x50, 0x9d, 0x80, 0x59, 0x7b, 0xf3, 0x73, 0x52, 0x6c, 0xba, 0x27, 0x0, 0x4, 0x99, + 0x4c, 0x7, 0x23, 0x0, 0xa, 0xf4, 0xa2, 0x99, 0x8e, 0x25, 0xdb, 0x4a, 0x73, 0x21, 0xe2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 2234; + uint8_t client_id_bytes[] = {0x45, 0x14, 0x58, 0x9e, 0x50, 0x9d, 0x80, 0x59, + 0x7b, 0xf3, 0x73, 0x52, 0x6c, 0xba, 0x27}; + lwmqtt_string_t client_id = {15, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x99, 0x4c, 0x7, 0x23}; + lwmqtt_string_t username = {4, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0xf4, 0xa2, 0x99, 0x8e, 0x25, 0xdb, 0x4a, 0x73, 0x21, 0xe2}; + lwmqtt_string_t password = {10, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Just +// "\254\241\198\183\211\244\131\&2\170\194\EOT\SYN\226H\226\&0\134\t\187'", _lastWill = Just (LastWill {_willRetain = +// True, _willQoS = QoS1, _willTopic = +// "\228\176\251j\SI\151m\GS}\147\222\ft\169!\153b\159\254\208\202\212\233\153\231\SUB\175\224\138", _willMsg = +// "\EOT\138\DC3b\NUL\226X\227XU\t\166\177\SOHR\DEL\DC4vC\132", _willProps = []}), _cleanSession = True, _keepAlive = +// 6210, _connID = "\194\231\179\200\206\DLE\208\132\139\v\171\161\163\159\153", _properties = []} +TEST(Connect311QCTest, Encode2) { + uint8_t pkt[] = {0x10, 0x50, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x2e, 0x18, 0x42, 0x0, 0xf, 0xc2, 0xe7, 0xb3, + 0xc8, 0xce, 0x10, 0xd0, 0x84, 0x8b, 0xb, 0xab, 0xa1, 0xa3, 0x9f, 0x99, 0x0, 0x1d, 0xe4, 0xb0, 0xfb, + 0x6a, 0xf, 0x97, 0x6d, 0x1d, 0x7d, 0x93, 0xde, 0xc, 0x74, 0xa9, 0x21, 0x99, 0x62, 0x9f, 0xfe, 0xd0, + 0xca, 0xd4, 0xe9, 0x99, 0xe7, 0x1a, 0xaf, 0xe0, 0x8a, 0x0, 0x14, 0x4, 0x8a, 0x13, 0x62, 0x0, 0xe2, + 0x58, 0xe3, 0x58, 0x55, 0x9, 0xa6, 0xb1, 0x1, 0x52, 0x7f, 0x14, 0x76, 0x43, 0x84}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0xe4, 0xb0, 0xfb, 0x6a, 0xf, 0x97, 0x6d, 0x1d, 0x7d, 0x93, + 0xde, 0xc, 0x74, 0xa9, 0x21, 0x99, 0x62, 0x9f, 0xfe, 0xd0, + 0xca, 0xd4, 0xe9, 0x99, 0xe7, 0x1a, 0xaf, 0xe0, 0x8a}; + lwmqtt_string_t will_topic = {29, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x4, 0x8a, 0x13, 0x62, 0x0, 0xe2, 0x58, 0xe3, 0x58, 0x55, + 0x9, 0xa6, 0xb1, 0x1, 0x52, 0x7f, 0x14, 0x76, 0x43, 0x84}; + lwmqtt_string_t will_payload = {20, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 6210; + uint8_t client_id_bytes[] = {0xc2, 0xe7, 0xb3, 0xc8, 0xce, 0x10, 0xd0, 0x84, 0x8b, 0xb, 0xab, 0xa1, 0xa3, 0x9f, 0x99}; + lwmqtt_string_t client_id = {15, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t password_bytes[] = {0xfe, 0xf1, 0xc6, 0xb7, 0xd3, 0xf4, 0x83, 0x32, 0xaa, 0xc2, + 0x4, 0x16, 0xe2, 0x48, 0xe2, 0x30, 0x86, 0x9, 0xbb, 0x27}; + lwmqtt_string_t password = {20, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Just "3m\161\216\&1\215\GS", _lastWill = Nothing, _cleanSession = +// True, _keepAlive = 22788, _connID = "", _properties = []} +TEST(Connect311QCTest, Encode3) { + uint8_t pkt[] = {0x10, 0xc, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x2, 0x59, 0x4, 0x0, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 22788; + uint8_t client_id_bytes[] = {0}; + lwmqtt_string_t client_id = {0, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t password_bytes[] = {0x33, 0x6d, 0xa1, 0xd8, 0x31, 0xd7, 0x1d}; + lwmqtt_string_t password = {7, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Just "\240f\237\SUB\151\160\&5", _lastWill = Just (LastWill +// {_willRetain = False, _willQoS = QoS2, _willTopic = "c\213", _willMsg = "\241\&1", _willProps = []}), _cleanSession = +// False, _keepAlive = 3121, _connID = "P\243\168\170I\168\218\209\139\225\251\228n\254", _properties = []} +TEST(Connect311QCTest, Encode4) { + uint8_t pkt[] = {0x10, 0x22, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x14, 0xc, 0x31, + 0x0, 0xe, 0x50, 0xf3, 0xa8, 0xaa, 0x49, 0xa8, 0xda, 0xd1, 0x8b, 0xe1, + 0xfb, 0xe4, 0x6e, 0xfe, 0x0, 0x2, 0x63, 0xd5, 0x0, 0x2, 0xf1, 0x31}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x63, 0xd5}; + lwmqtt_string_t will_topic = {2, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0xf1, 0x31}; + lwmqtt_string_t will_payload = {2, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS2; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 3121; + uint8_t client_id_bytes[] = {0x50, 0xf3, 0xa8, 0xaa, 0x49, 0xa8, 0xda, 0xd1, 0x8b, 0xe1, 0xfb, 0xe4, 0x6e, 0xfe}; + lwmqtt_string_t client_id = {14, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t password_bytes[] = {0xf0, 0x66, 0xed, 0x1a, 0x97, 0xa0, 0x35}; + lwmqtt_string_t password = {7, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\175\229\&0\136\198[\249\141a&\148", _password = Nothing, _lastWill = Just +// (LastWill {_willRetain = False, _willQoS = QoS2, _willTopic = +// "3\140\244\142\233\187\202\128\209\rE\DC2\231\&3/\195\rY$\137", _willMsg = "\166\EM\167Q_\140\204", _willProps = +// []}), _cleanSession = False, _keepAlive = 11555, _connID = "tuXU", _properties = []} +TEST(Connect311QCTest, Encode5) { + uint8_t pkt[] = {0x10, 0x3c, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x94, 0x2d, 0x23, 0x0, 0x4, 0x74, 0x75, + 0x58, 0x55, 0x0, 0x14, 0x33, 0x8c, 0xf4, 0x8e, 0xe9, 0xbb, 0xca, 0x80, 0xd1, 0xd, 0x45, 0x12, + 0xe7, 0x33, 0x2f, 0xc3, 0xd, 0x59, 0x24, 0x89, 0x0, 0x7, 0xa6, 0x19, 0xa7, 0x51, 0x5f, 0x8c, + 0xcc, 0x0, 0xb, 0xaf, 0xe5, 0x30, 0x88, 0xc6, 0x5b, 0xf9, 0x8d, 0x61, 0x26, 0x94}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x33, 0x8c, 0xf4, 0x8e, 0xe9, 0xbb, 0xca, 0x80, 0xd1, 0xd, + 0x45, 0x12, 0xe7, 0x33, 0x2f, 0xc3, 0xd, 0x59, 0x24, 0x89}; + lwmqtt_string_t will_topic = {20, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0xa6, 0x19, 0xa7, 0x51, 0x5f, 0x8c, 0xcc}; + lwmqtt_string_t will_payload = {7, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS2; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 11555; + uint8_t client_id_bytes[] = {0x74, 0x75, 0x58, 0x55}; + lwmqtt_string_t client_id = {4, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xaf, 0xe5, 0x30, 0x88, 0xc6, 0x5b, 0xf9, 0x8d, 0x61, 0x26, 0x94}; + lwmqtt_string_t username = {11, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "e\138\184\246\212D\182\ETX\161", _password = Just "2\150\175\130\&9\161", _lastWill +// = Just (LastWill {_willRetain = False, _willQoS = QoS1, _willTopic = " +// \DC3I\133\229M\236\164\&9\CANY\250\SOH\DC2w\166\185\150\&6Osm\b-RT\156", _willMsg = "\n", _willProps = []}), +// _cleanSession = False, _keepAlive = 7490, _connID = "#\162\232\227\138", _properties = []} +TEST(Connect311QCTest, Encode6) { + uint8_t pkt[] = {0x10, 0x44, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xcc, 0x1d, 0x42, 0x0, 0x5, + 0x23, 0xa2, 0xe8, 0xe3, 0x8a, 0x0, 0x1b, 0x20, 0x13, 0x49, 0x85, 0xe5, 0x4d, 0xec, + 0xa4, 0x39, 0x18, 0x59, 0xfa, 0x1, 0x12, 0x77, 0xa6, 0xb9, 0x96, 0x36, 0x4f, 0x73, + 0x6d, 0x8, 0x2d, 0x52, 0x54, 0x9c, 0x0, 0x1, 0xa, 0x0, 0x9, 0x65, 0x8a, 0xb8, + 0xf6, 0xd4, 0x44, 0xb6, 0x3, 0xa1, 0x0, 0x6, 0x32, 0x96, 0xaf, 0x82, 0x39, 0xa1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x20, 0x13, 0x49, 0x85, 0xe5, 0x4d, 0xec, 0xa4, 0x39, 0x18, 0x59, 0xfa, 0x1, 0x12, + 0x77, 0xa6, 0xb9, 0x96, 0x36, 0x4f, 0x73, 0x6d, 0x8, 0x2d, 0x52, 0x54, 0x9c}; + lwmqtt_string_t will_topic = {27, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0xa}; + lwmqtt_string_t will_payload = {1, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 7490; + uint8_t client_id_bytes[] = {0x23, 0xa2, 0xe8, 0xe3, 0x8a}; + lwmqtt_string_t client_id = {5, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x65, 0x8a, 0xb8, 0xf6, 0xd4, 0x44, 0xb6, 0x3, 0xa1}; + lwmqtt_string_t username = {9, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x32, 0x96, 0xaf, 0x82, 0x39, 0xa1}; + lwmqtt_string_t password = {6, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "y\144\176\238\SUBt\197\&4U\USvH\240\253\227", _password = Nothing, _lastWill = Just +// (LastWill {_willRetain = True, _willQoS = QoS2, _willTopic = "\147\215\133\"", _willMsg = +// ";\EOT}N\aD\177\140\NUL\147Hw\161$'\255\228\194\163\138F\DLE", _willProps = []}), _cleanSession = True, _keepAlive = +// 27162, _connID = "8aP3Sc=\182\ETX|\183Z\254\211Z", _properties = []} +TEST(Connect311QCTest, Encode7) { + uint8_t pkt[] = {0x10, 0x4a, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xb6, 0x6a, 0x1a, 0x0, 0xf, 0x38, 0x61, + 0x50, 0x33, 0x53, 0x63, 0x3d, 0xb6, 0x3, 0x7c, 0xb7, 0x5a, 0xfe, 0xd3, 0x5a, 0x0, 0x4, 0x93, + 0xd7, 0x85, 0x22, 0x0, 0x16, 0x3b, 0x4, 0x7d, 0x4e, 0x7, 0x44, 0xb1, 0x8c, 0x0, 0x93, 0x48, + 0x77, 0xa1, 0x24, 0x27, 0xff, 0xe4, 0xc2, 0xa3, 0x8a, 0x46, 0x10, 0x0, 0xf, 0x79, 0x90, 0xb0, + 0xee, 0x1a, 0x74, 0xc5, 0x34, 0x55, 0x1f, 0x76, 0x48, 0xf0, 0xfd, 0xe3}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x93, 0xd7, 0x85, 0x22}; + lwmqtt_string_t will_topic = {4, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x3b, 0x4, 0x7d, 0x4e, 0x7, 0x44, 0xb1, 0x8c, 0x0, 0x93, 0x48, + 0x77, 0xa1, 0x24, 0x27, 0xff, 0xe4, 0xc2, 0xa3, 0x8a, 0x46, 0x10}; + lwmqtt_string_t will_payload = {22, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS2; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 27162; + uint8_t client_id_bytes[] = {0x38, 0x61, 0x50, 0x33, 0x53, 0x63, 0x3d, 0xb6, 0x3, 0x7c, 0xb7, 0x5a, 0xfe, 0xd3, 0x5a}; + lwmqtt_string_t client_id = {15, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x79, 0x90, 0xb0, 0xee, 0x1a, 0x74, 0xc5, 0x34, 0x55, 0x1f, 0x76, 0x48, 0xf0, 0xfd, 0xe3}; + lwmqtt_string_t username = {15, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\ETB\234W\ETB*\211", _password = Nothing, _lastWill = Nothing, _cleanSession = +// False, _keepAlive = 31957, _connID = "\128x&\145\206\NUL$\207\227V9\229G\NULU2\180", _properties = []} +TEST(Connect311QCTest, Encode8) { + uint8_t pkt[] = {0x10, 0x25, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x80, 0x7c, 0xd5, 0x0, + 0x11, 0x80, 0x78, 0x26, 0x91, 0xce, 0x0, 0x24, 0xcf, 0xe3, 0x56, 0x39, 0xe5, + 0x47, 0x0, 0x55, 0x32, 0xb4, 0x0, 0x6, 0x17, 0xea, 0x57, 0x17, 0x2a, 0xd3}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 31957; + uint8_t client_id_bytes[] = {0x80, 0x78, 0x26, 0x91, 0xce, 0x0, 0x24, 0xcf, 0xe3, + 0x56, 0x39, 0xe5, 0x47, 0x0, 0x55, 0x32, 0xb4}; + lwmqtt_string_t client_id = {17, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x17, 0xea, 0x57, 0x17, 0x2a, 0xd3}; + lwmqtt_string_t username = {6, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Just "\175", _lastWill = Just (LastWill {_willRetain = True, +// _willQoS = QoS0, _willTopic = +// "\CAN#\232\218\132C\SOH\233l\168\204\182\128\&1\147\ETX\185\184Y\254<\192\170M\137\143\185", _willMsg = +// "L\\3\170\149\249|cG", _willProps = []}), _cleanSession = False, _keepAlive = 10327, _connID = "\197F\a\173", +// _properties = []} +TEST(Connect311QCTest, Encode9) { + uint8_t pkt[] = {0x10, 0x38, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x24, 0x28, 0x57, 0x0, 0x4, 0xc5, + 0x46, 0x7, 0xad, 0x0, 0x1b, 0x18, 0x23, 0xe8, 0xda, 0x84, 0x43, 0x1, 0xe9, 0x6c, 0xa8, + 0xcc, 0xb6, 0x80, 0x31, 0x93, 0x3, 0xb9, 0xb8, 0x59, 0xfe, 0x3c, 0xc0, 0xaa, 0x4d, 0x89, + 0x8f, 0xb9, 0x0, 0x9, 0x4c, 0x5c, 0x33, 0xaa, 0x95, 0xf9, 0x7c, 0x63, 0x47}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x18, 0x23, 0xe8, 0xda, 0x84, 0x43, 0x1, 0xe9, 0x6c, 0xa8, 0xcc, 0xb6, 0x80, 0x31, + 0x93, 0x3, 0xb9, 0xb8, 0x59, 0xfe, 0x3c, 0xc0, 0xaa, 0x4d, 0x89, 0x8f, 0xb9}; + lwmqtt_string_t will_topic = {27, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x4c, 0x5c, 0x33, 0xaa, 0x95, 0xf9, 0x7c, 0x63, 0x47}; + lwmqtt_string_t will_payload = {9, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 10327; + uint8_t client_id_bytes[] = {0xc5, 0x46, 0x7, 0xad}; + lwmqtt_string_t client_id = {4, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t password_bytes[] = {0xaf}; + lwmqtt_string_t password = {1, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\161M\139\STX'\150/\148\f\226\225\132", _password = Just "F\225WbF\224\168", +// _lastWill = Nothing, _cleanSession = False, _keepAlive = 18820, _connID = +// "\239\187K\240\&8zO\aU|\SI\206\249i\178\203\168", _properties = []} +TEST(Connect311QCTest, Encode10) { + uint8_t pkt[] = {0x10, 0x34, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xc0, 0x49, 0x84, 0x0, 0x11, + 0xef, 0xbb, 0x4b, 0xf0, 0x38, 0x7a, 0x4f, 0x7, 0x55, 0x7c, 0xf, 0xce, 0xf9, 0x69, + 0xb2, 0xcb, 0xa8, 0x0, 0xc, 0xa1, 0x4d, 0x8b, 0x2, 0x27, 0x96, 0x2f, 0x94, 0xc, + 0xe2, 0xe1, 0x84, 0x0, 0x7, 0x46, 0xe1, 0x57, 0x62, 0x46, 0xe0, 0xa8}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 18820; + uint8_t client_id_bytes[] = {0xef, 0xbb, 0x4b, 0xf0, 0x38, 0x7a, 0x4f, 0x7, 0x55, + 0x7c, 0xf, 0xce, 0xf9, 0x69, 0xb2, 0xcb, 0xa8}; + lwmqtt_string_t client_id = {17, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xa1, 0x4d, 0x8b, 0x2, 0x27, 0x96, 0x2f, 0x94, 0xc, 0xe2, 0xe1, 0x84}; + lwmqtt_string_t username = {12, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x46, 0xe1, 0x57, 0x62, 0x46, 0xe0, 0xa8}; + lwmqtt_string_t password = {7, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\212\246\v\208Q", _password = Nothing, _lastWill = Just (LastWill {_willRetain = +// False, _willQoS = QoS0, _willTopic = "\DC4\STX\237+\169PM5-\137\&2\143\DC1I\143\ETB8R\205\"+\207'\229\244", _willMsg +// = "*\236\193\FS\231\145S\224#\173\"\224\223\227\142\242*i\131\&8\203\156x\161\231Z", _willProps = []}), _cleanSession +// = True, _keepAlive = 25243, _connID = "\183\141\187\211\227F!\186\233+s9c^7\154\b\193Y\148\174w\216=\234K1", +// _properties = []} +TEST(Connect311QCTest, Encode11) { + uint8_t pkt[] = {0x10, 0x65, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x86, 0x62, 0x9b, 0x0, 0x1b, 0xb7, + 0x8d, 0xbb, 0xd3, 0xe3, 0x46, 0x21, 0xba, 0xe9, 0x2b, 0x73, 0x39, 0x63, 0x5e, 0x37, 0x9a, + 0x8, 0xc1, 0x59, 0x94, 0xae, 0x77, 0xd8, 0x3d, 0xea, 0x4b, 0x31, 0x0, 0x19, 0x14, 0x2, + 0xed, 0x2b, 0xa9, 0x50, 0x4d, 0x35, 0x2d, 0x89, 0x32, 0x8f, 0x11, 0x49, 0x8f, 0x17, 0x38, + 0x52, 0xcd, 0x22, 0x2b, 0xcf, 0x27, 0xe5, 0xf4, 0x0, 0x1a, 0x2a, 0xec, 0xc1, 0x1c, 0xe7, + 0x91, 0x53, 0xe0, 0x23, 0xad, 0x22, 0xe0, 0xdf, 0xe3, 0x8e, 0xf2, 0x2a, 0x69, 0x83, 0x38, + 0xcb, 0x9c, 0x78, 0xa1, 0xe7, 0x5a, 0x0, 0x5, 0xd4, 0xf6, 0xb, 0xd0, 0x51}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x14, 0x2, 0xed, 0x2b, 0xa9, 0x50, 0x4d, 0x35, 0x2d, 0x89, 0x32, 0x8f, 0x11, + 0x49, 0x8f, 0x17, 0x38, 0x52, 0xcd, 0x22, 0x2b, 0xcf, 0x27, 0xe5, 0xf4}; + lwmqtt_string_t will_topic = {25, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x2a, 0xec, 0xc1, 0x1c, 0xe7, 0x91, 0x53, 0xe0, 0x23, 0xad, 0x22, 0xe0, 0xdf, + 0xe3, 0x8e, 0xf2, 0x2a, 0x69, 0x83, 0x38, 0xcb, 0x9c, 0x78, 0xa1, 0xe7, 0x5a}; + lwmqtt_string_t will_payload = {26, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 25243; + uint8_t client_id_bytes[] = {0xb7, 0x8d, 0xbb, 0xd3, 0xe3, 0x46, 0x21, 0xba, 0xe9, 0x2b, 0x73, 0x39, 0x63, 0x5e, + 0x37, 0x9a, 0x8, 0xc1, 0x59, 0x94, 0xae, 0x77, 0xd8, 0x3d, 0xea, 0x4b, 0x31}; + lwmqtt_string_t client_id = {27, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xd4, 0xf6, 0xb, 0xd0, 0x51}; + lwmqtt_string_t username = {5, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\202\139\128\189r\251\250\210\176K\157gL\180\ESC\252\232\242\141\NULV\217", +// _password = Nothing, _lastWill = Just (LastWill {_willRetain = False, _willQoS = QoS0, _willTopic = +// "\204\246\221\166\146\242\STXG5", _willMsg = "P\228\ETX:\163\230z\150\184Jo\FS=\189\NUL\196", _willProps = []}), +// _cleanSession = True, _keepAlive = 11253, _connID = "\239\DEL\DC2\154\161@0\234\178\ad", _properties = []} +TEST(Connect311QCTest, Encode12) { + uint8_t pkt[] = {0x10, 0x4c, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x86, 0x2b, 0xf5, 0x0, 0xb, 0xef, 0x7f, + 0x12, 0x9a, 0xa1, 0x40, 0x30, 0xea, 0xb2, 0x7, 0x64, 0x0, 0x9, 0xcc, 0xf6, 0xdd, 0xa6, 0x92, + 0xf2, 0x2, 0x47, 0x35, 0x0, 0x10, 0x50, 0xe4, 0x3, 0x3a, 0xa3, 0xe6, 0x7a, 0x96, 0xb8, 0x4a, + 0x6f, 0x1c, 0x3d, 0xbd, 0x0, 0xc4, 0x0, 0x16, 0xca, 0x8b, 0x80, 0xbd, 0x72, 0xfb, 0xfa, 0xd2, + 0xb0, 0x4b, 0x9d, 0x67, 0x4c, 0xb4, 0x1b, 0xfc, 0xe8, 0xf2, 0x8d, 0x0, 0x56, 0xd9}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0xcc, 0xf6, 0xdd, 0xa6, 0x92, 0xf2, 0x2, 0x47, 0x35}; + lwmqtt_string_t will_topic = {9, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x50, 0xe4, 0x3, 0x3a, 0xa3, 0xe6, 0x7a, 0x96, + 0xb8, 0x4a, 0x6f, 0x1c, 0x3d, 0xbd, 0x0, 0xc4}; + lwmqtt_string_t will_payload = {16, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 11253; + uint8_t client_id_bytes[] = {0xef, 0x7f, 0x12, 0x9a, 0xa1, 0x40, 0x30, 0xea, 0xb2, 0x7, 0x64}; + lwmqtt_string_t client_id = {11, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xca, 0x8b, 0x80, 0xbd, 0x72, 0xfb, 0xfa, 0xd2, 0xb0, 0x4b, 0x9d, + 0x67, 0x4c, 0xb4, 0x1b, 0xfc, 0xe8, 0xf2, 0x8d, 0x0, 0x56, 0xd9}; + lwmqtt_string_t username = {22, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Nothing, _lastWill = Just (LastWill {_willRetain = False, _willQoS = +// QoS1, _willTopic = "\DC2\EOT\246\144\&2c\156AGN\a\249~", _willMsg = +// "\239~\221\167\215\204Q\f\\\186Q\198<\DC4\220~\217%", _willProps = []}), _cleanSession = False, _keepAlive = 28636, +// _connID = "\GS \174N\196\134\134\164\ACK;!#]\239\168\159\231\208f", _properties = []} +TEST(Connect311QCTest, Encode13) { + uint8_t pkt[] = {0x10, 0x42, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xc, 0x6f, 0xdc, 0x0, 0x13, + 0x1d, 0x20, 0xae, 0x4e, 0xc4, 0x86, 0x86, 0xa4, 0x6, 0x3b, 0x21, 0x23, 0x5d, 0xef, + 0xa8, 0x9f, 0xe7, 0xd0, 0x66, 0x0, 0xd, 0x12, 0x4, 0xf6, 0x90, 0x32, 0x63, 0x9c, + 0x41, 0x47, 0x4e, 0x7, 0xf9, 0x7e, 0x0, 0x12, 0xef, 0x7e, 0xdd, 0xa7, 0xd7, 0xcc, + 0x51, 0xc, 0x5c, 0xba, 0x51, 0xc6, 0x3c, 0x14, 0xdc, 0x7e, 0xd9, 0x25}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x12, 0x4, 0xf6, 0x90, 0x32, 0x63, 0x9c, 0x41, 0x47, 0x4e, 0x7, 0xf9, 0x7e}; + lwmqtt_string_t will_topic = {13, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0xef, 0x7e, 0xdd, 0xa7, 0xd7, 0xcc, 0x51, 0xc, 0x5c, + 0xba, 0x51, 0xc6, 0x3c, 0x14, 0xdc, 0x7e, 0xd9, 0x25}; + lwmqtt_string_t will_payload = {18, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 28636; + uint8_t client_id_bytes[] = {0x1d, 0x20, 0xae, 0x4e, 0xc4, 0x86, 0x86, 0xa4, 0x6, 0x3b, + 0x21, 0x23, 0x5d, 0xef, 0xa8, 0x9f, 0xe7, 0xd0, 0x66}; + lwmqtt_string_t client_id = {19, (char*)&client_id_bytes}; + opts.client_id = client_id; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\242\255\248\RSlqy\210\165\223EJs\218\138\195\252~OS0\155s\176", _password = Just +// "+\217", _lastWill = Just (LastWill {_willRetain = False, _willQoS = QoS1, _willTopic = +// "\251\&3\249*?0\b\223!*\150M", _willMsg = "bZ\SO", _willProps = []}), _cleanSession = False, _keepAlive = 5719, +// _connID = "\222\165\251RK\130'\234\242.*\EOT\200~\"\NULJ", _properties = []} +TEST(Connect311QCTest, Encode14) { + uint8_t pkt[] = {0x10, 0x4e, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xcc, 0x16, 0x57, 0x0, 0x11, 0xde, 0xa5, + 0xfb, 0x52, 0x4b, 0x82, 0x27, 0xea, 0xf2, 0x2e, 0x2a, 0x4, 0xc8, 0x7e, 0x22, 0x0, 0x4a, 0x0, + 0xc, 0xfb, 0x33, 0xf9, 0x2a, 0x3f, 0x30, 0x8, 0xdf, 0x21, 0x2a, 0x96, 0x4d, 0x0, 0x3, 0x62, + 0x5a, 0xe, 0x0, 0x18, 0xf2, 0xff, 0xf8, 0x1e, 0x6c, 0x71, 0x79, 0xd2, 0xa5, 0xdf, 0x45, 0x4a, + 0x73, 0xda, 0x8a, 0xc3, 0xfc, 0x7e, 0x4f, 0x53, 0x30, 0x9b, 0x73, 0xb0, 0x0, 0x2, 0x2b, 0xd9}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0xfb, 0x33, 0xf9, 0x2a, 0x3f, 0x30, 0x8, 0xdf, 0x21, 0x2a, 0x96, 0x4d}; + lwmqtt_string_t will_topic = {12, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x62, 0x5a, 0xe}; + lwmqtt_string_t will_payload = {3, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 5719; + uint8_t client_id_bytes[] = {0xde, 0xa5, 0xfb, 0x52, 0x4b, 0x82, 0x27, 0xea, 0xf2, + 0x2e, 0x2a, 0x4, 0xc8, 0x7e, 0x22, 0x0, 0x4a}; + lwmqtt_string_t client_id = {17, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xf2, 0xff, 0xf8, 0x1e, 0x6c, 0x71, 0x79, 0xd2, 0xa5, 0xdf, 0x45, 0x4a, + 0x73, 0xda, 0x8a, 0xc3, 0xfc, 0x7e, 0x4f, 0x53, 0x30, 0x9b, 0x73, 0xb0}; + lwmqtt_string_t username = {24, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x2b, 0xd9}; + lwmqtt_string_t password = {2, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\172\146\231\253\222^\247\183l\232!\133;\b\FS\253\ETX\f~[\211\SYN(P", _password = +// Nothing, _lastWill = Just (LastWill {_willRetain = True, _willQoS = QoS0, _willTopic = +// "[\SO\138\&5\217\\\253\149\212\249s\139\SOH\ENQ\DLEw", _willMsg = +// "\a\252\183\167\137\DC4\248\STX^\DLE\249\242\194\ESC\135\165\&5L\205dn\DC2", _willProps = []}), _cleanSession = +// False, _keepAlive = 27552, _connID = "e\185\229", _properties = []} +TEST(Connect311QCTest, Encode15) { + uint8_t pkt[] = {0x10, 0x53, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xa4, 0x6b, 0xa0, 0x0, 0x3, 0x65, + 0xb9, 0xe5, 0x0, 0x10, 0x5b, 0xe, 0x8a, 0x35, 0xd9, 0x5c, 0xfd, 0x95, 0xd4, 0xf9, 0x73, + 0x8b, 0x1, 0x5, 0x10, 0x77, 0x0, 0x16, 0x7, 0xfc, 0xb7, 0xa7, 0x89, 0x14, 0xf8, 0x2, + 0x5e, 0x10, 0xf9, 0xf2, 0xc2, 0x1b, 0x87, 0xa5, 0x35, 0x4c, 0xcd, 0x64, 0x6e, 0x12, 0x0, + 0x18, 0xac, 0x92, 0xe7, 0xfd, 0xde, 0x5e, 0xf7, 0xb7, 0x6c, 0xe8, 0x21, 0x85, 0x3b, 0x8, + 0x1c, 0xfd, 0x3, 0xc, 0x7e, 0x5b, 0xd3, 0x16, 0x28, 0x50}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x5b, 0xe, 0x8a, 0x35, 0xd9, 0x5c, 0xfd, 0x95, + 0xd4, 0xf9, 0x73, 0x8b, 0x1, 0x5, 0x10, 0x77}; + lwmqtt_string_t will_topic = {16, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x7, 0xfc, 0xb7, 0xa7, 0x89, 0x14, 0xf8, 0x2, 0x5e, 0x10, 0xf9, + 0xf2, 0xc2, 0x1b, 0x87, 0xa5, 0x35, 0x4c, 0xcd, 0x64, 0x6e, 0x12}; + lwmqtt_string_t will_payload = {22, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 27552; + uint8_t client_id_bytes[] = {0x65, 0xb9, 0xe5}; + lwmqtt_string_t client_id = {3, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xac, 0x92, 0xe7, 0xfd, 0xde, 0x5e, 0xf7, 0xb7, 0x6c, 0xe8, 0x21, 0x85, + 0x3b, 0x8, 0x1c, 0xfd, 0x3, 0xc, 0x7e, 0x5b, 0xd3, 0x16, 0x28, 0x50}; + lwmqtt_string_t username = {24, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\208\186;\142\229\ENQ\DC3", _password = Just "k\STX\218\181\207){\"\180\DLE", +// _lastWill = Nothing, _cleanSession = False, _keepAlive = 28695, _connID = +// "\166'RW'\131!\222\228%N\243\227\158\253sF\r\211L", _properties = []} +TEST(Connect311QCTest, Encode16) { + uint8_t pkt[] = {0x10, 0x35, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xc0, 0x70, 0x17, 0x0, 0x14, + 0xa6, 0x27, 0x52, 0x57, 0x27, 0x83, 0x21, 0xde, 0xe4, 0x25, 0x4e, 0xf3, 0xe3, 0x9e, + 0xfd, 0x73, 0x46, 0xd, 0xd3, 0x4c, 0x0, 0x7, 0xd0, 0xba, 0x3b, 0x8e, 0xe5, 0x5, + 0x13, 0x0, 0xa, 0x6b, 0x2, 0xda, 0xb5, 0xcf, 0x29, 0x7b, 0x22, 0xb4, 0x10}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 28695; + uint8_t client_id_bytes[] = {0xa6, 0x27, 0x52, 0x57, 0x27, 0x83, 0x21, 0xde, 0xe4, 0x25, + 0x4e, 0xf3, 0xe3, 0x9e, 0xfd, 0x73, 0x46, 0xd, 0xd3, 0x4c}; + lwmqtt_string_t client_id = {20, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xd0, 0xba, 0x3b, 0x8e, 0xe5, 0x5, 0x13}; + lwmqtt_string_t username = {7, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x6b, 0x2, 0xda, 0xb5, 0xcf, 0x29, 0x7b, 0x22, 0xb4, 0x10}; + lwmqtt_string_t password = {10, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Nothing, _lastWill = Just (LastWill {_willRetain = True, _willQoS = +// QoS1, _willTopic = "\226g", _willMsg = "\148\r}\DEL1ZJ\210\CAN\RS\158C~\249\215\205\219\158\211'4\223\ESC", +// _willProps = []}), _cleanSession = False, _keepAlive = 10322, _connID = "\146\226x\204\ESC:q5\ENQ|,`\206", +// _properties = []} +TEST(Connect311QCTest, Encode17) { + uint8_t pkt[] = {0x10, 0x36, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x2c, 0x28, 0x52, 0x0, 0xd, + 0x92, 0xe2, 0x78, 0xcc, 0x1b, 0x3a, 0x71, 0x35, 0x5, 0x7c, 0x2c, 0x60, 0xce, 0x0, + 0x2, 0xe2, 0x67, 0x0, 0x17, 0x94, 0xd, 0x7d, 0x7f, 0x31, 0x5a, 0x4a, 0xd2, 0x18, + 0x1e, 0x9e, 0x43, 0x7e, 0xf9, 0xd7, 0xcd, 0xdb, 0x9e, 0xd3, 0x27, 0x34, 0xdf, 0x1b}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0xe2, 0x67}; + lwmqtt_string_t will_topic = {2, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x94, 0xd, 0x7d, 0x7f, 0x31, 0x5a, 0x4a, 0xd2, 0x18, 0x1e, 0x9e, 0x43, + 0x7e, 0xf9, 0xd7, 0xcd, 0xdb, 0x9e, 0xd3, 0x27, 0x34, 0xdf, 0x1b}; + lwmqtt_string_t will_payload = {23, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 10322; + uint8_t client_id_bytes[] = {0x92, 0xe2, 0x78, 0xcc, 0x1b, 0x3a, 0x71, 0x35, 0x5, 0x7c, 0x2c, 0x60, 0xce}; + lwmqtt_string_t client_id = {13, (char*)&client_id_bytes}; + opts.client_id = client_id; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\160(\fi\152\189\DC1\183}\167.2[,e\217\&8\238]\207\156\192:B\128\ESC\188\205", +// _password = Just "\223+\207(\246E\243:\221J\144\DLE#\165\162\&3\240\148\196\247\150:@\226\154\174<", _lastWill = +// Nothing, _cleanSession = True, _keepAlive = 19401, _connID = +// "6\204\")V\154L\237\218s#U\227\148\134o\190\&2\ETB\192^\225\201\229\169", _properties = []} +TEST(Connect311QCTest, Encode18) { + uint8_t pkt[] = {0x10, 0x60, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xc2, 0x4b, 0xc9, 0x0, 0x19, 0x36, 0xcc, 0x22, + 0x29, 0x56, 0x9a, 0x4c, 0xed, 0xda, 0x73, 0x23, 0x55, 0xe3, 0x94, 0x86, 0x6f, 0xbe, 0x32, 0x17, 0xc0, + 0x5e, 0xe1, 0xc9, 0xe5, 0xa9, 0x0, 0x1c, 0xa0, 0x28, 0xc, 0x69, 0x98, 0xbd, 0x11, 0xb7, 0x7d, 0xa7, + 0x2e, 0x32, 0x5b, 0x2c, 0x65, 0xd9, 0x38, 0xee, 0x5d, 0xcf, 0x9c, 0xc0, 0x3a, 0x42, 0x80, 0x1b, 0xbc, + 0xcd, 0x0, 0x1b, 0xdf, 0x2b, 0xcf, 0x28, 0xf6, 0x45, 0xf3, 0x3a, 0xdd, 0x4a, 0x90, 0x10, 0x23, 0xa5, + 0xa2, 0x33, 0xf0, 0x94, 0xc4, 0xf7, 0x96, 0x3a, 0x40, 0xe2, 0x9a, 0xae, 0x3c}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 19401; + uint8_t client_id_bytes[] = {0x36, 0xcc, 0x22, 0x29, 0x56, 0x9a, 0x4c, 0xed, 0xda, 0x73, 0x23, 0x55, 0xe3, + 0x94, 0x86, 0x6f, 0xbe, 0x32, 0x17, 0xc0, 0x5e, 0xe1, 0xc9, 0xe5, 0xa9}; + lwmqtt_string_t client_id = {25, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xa0, 0x28, 0xc, 0x69, 0x98, 0xbd, 0x11, 0xb7, 0x7d, 0xa7, 0x2e, 0x32, 0x5b, 0x2c, + 0x65, 0xd9, 0x38, 0xee, 0x5d, 0xcf, 0x9c, 0xc0, 0x3a, 0x42, 0x80, 0x1b, 0xbc, 0xcd}; + lwmqtt_string_t username = {28, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0xdf, 0x2b, 0xcf, 0x28, 0xf6, 0x45, 0xf3, 0x3a, 0xdd, 0x4a, 0x90, 0x10, 0x23, 0xa5, + 0xa2, 0x33, 0xf0, 0x94, 0xc4, 0xf7, 0x96, 0x3a, 0x40, 0xe2, 0x9a, 0xae, 0x3c}; + lwmqtt_string_t password = {27, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "^u#\159", _password = Just +// "y\"\r/\252\&8\144\156Y\221,;\158\GS\207S\130\174\230\ETB\150\150M\148\159\212", _lastWill = Just (LastWill +// {_willRetain = False, _willQoS = QoS0, _willTopic = "\160A\b\242{hJ\240\SOHs\227", _willMsg = +// "+JS\150\209\231\230=\222\231\225\142\244\229\US2\STX\233\240\253\168\RSzG1", _willProps = []}), _cleanSession = +// True, _keepAlive = 22513, _connID = +// "/\179\ENQ:\239\234\242P\129,\b\213A\237\186\243\&9\183\133\147\188\136.\ACK\202\FSS\\", _properties = []} +TEST(Connect311QCTest, Encode19) { + uint8_t pkt[] = {0x10, 0x72, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xc6, 0x57, 0xf1, 0x0, 0x1c, 0x2f, 0xb3, 0x5, + 0x3a, 0xef, 0xea, 0xf2, 0x50, 0x81, 0x2c, 0x8, 0xd5, 0x41, 0xed, 0xba, 0xf3, 0x39, 0xb7, 0x85, 0x93, + 0xbc, 0x88, 0x2e, 0x6, 0xca, 0x1c, 0x53, 0x5c, 0x0, 0xb, 0xa0, 0x41, 0x8, 0xf2, 0x7b, 0x68, 0x4a, + 0xf0, 0x1, 0x73, 0xe3, 0x0, 0x19, 0x2b, 0x4a, 0x53, 0x96, 0xd1, 0xe7, 0xe6, 0x3d, 0xde, 0xe7, 0xe1, + 0x8e, 0xf4, 0xe5, 0x1f, 0x32, 0x2, 0xe9, 0xf0, 0xfd, 0xa8, 0x1e, 0x7a, 0x47, 0x31, 0x0, 0x4, 0x5e, + 0x75, 0x23, 0x9f, 0x0, 0x1a, 0x79, 0x22, 0xd, 0x2f, 0xfc, 0x38, 0x90, 0x9c, 0x59, 0xdd, 0x2c, 0x3b, + 0x9e, 0x1d, 0xcf, 0x53, 0x82, 0xae, 0xe6, 0x17, 0x96, 0x96, 0x4d, 0x94, 0x9f, 0xd4}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0xa0, 0x41, 0x8, 0xf2, 0x7b, 0x68, 0x4a, 0xf0, 0x1, 0x73, 0xe3}; + lwmqtt_string_t will_topic = {11, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x2b, 0x4a, 0x53, 0x96, 0xd1, 0xe7, 0xe6, 0x3d, 0xde, 0xe7, 0xe1, 0x8e, 0xf4, + 0xe5, 0x1f, 0x32, 0x2, 0xe9, 0xf0, 0xfd, 0xa8, 0x1e, 0x7a, 0x47, 0x31}; + lwmqtt_string_t will_payload = {25, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 22513; + uint8_t client_id_bytes[] = {0x2f, 0xb3, 0x5, 0x3a, 0xef, 0xea, 0xf2, 0x50, 0x81, 0x2c, 0x8, 0xd5, 0x41, 0xed, + 0xba, 0xf3, 0x39, 0xb7, 0x85, 0x93, 0xbc, 0x88, 0x2e, 0x6, 0xca, 0x1c, 0x53, 0x5c}; + lwmqtt_string_t client_id = {28, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x5e, 0x75, 0x23, 0x9f}; + lwmqtt_string_t username = {4, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x79, 0x22, 0xd, 0x2f, 0xfc, 0x38, 0x90, 0x9c, 0x59, 0xdd, 0x2c, 0x3b, 0x9e, + 0x1d, 0xcf, 0x53, 0x82, 0xae, 0xe6, 0x17, 0x96, 0x96, 0x4d, 0x94, 0x9f, 0xd4}; + lwmqtt_string_t password = {26, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Just +// "\148\203\247(\RS\253m?\172\246]f\150WW\162\137\245\t\255\243\SUB}", _lastWill = Just (LastWill {_willRetain = True, +// _willQoS = QoS2, _willTopic = "Q&\199s\163,\145Pk\170\212\r\SOH\210I", _willMsg = +// "/y0\n\222\221\178\SO\241\211d\222\211\&0b", _willProps = []}), _cleanSession = False, _keepAlive = 190, _connID = +// "6Y\188\175\229N\156\168\153V\FS", _properties = []} +TEST(Connect311QCTest, Encode20) { + uint8_t pkt[] = {0x10, 0x39, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x34, 0x0, 0xbe, 0x0, 0xb, 0x36, + 0x59, 0xbc, 0xaf, 0xe5, 0x4e, 0x9c, 0xa8, 0x99, 0x56, 0x1c, 0x0, 0xf, 0x51, 0x26, 0xc7, + 0x73, 0xa3, 0x2c, 0x91, 0x50, 0x6b, 0xaa, 0xd4, 0xd, 0x1, 0xd2, 0x49, 0x0, 0xf, 0x2f, + 0x79, 0x30, 0xa, 0xde, 0xdd, 0xb2, 0xe, 0xf1, 0xd3, 0x64, 0xde, 0xd3, 0x30, 0x62}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x51, 0x26, 0xc7, 0x73, 0xa3, 0x2c, 0x91, 0x50, 0x6b, 0xaa, 0xd4, 0xd, 0x1, 0xd2, 0x49}; + lwmqtt_string_t will_topic = {15, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x2f, 0x79, 0x30, 0xa, 0xde, 0xdd, 0xb2, 0xe, + 0xf1, 0xd3, 0x64, 0xde, 0xd3, 0x30, 0x62}; + lwmqtt_string_t will_payload = {15, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS2; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 190; + uint8_t client_id_bytes[] = {0x36, 0x59, 0xbc, 0xaf, 0xe5, 0x4e, 0x9c, 0xa8, 0x99, 0x56, 0x1c}; + lwmqtt_string_t client_id = {11, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t password_bytes[] = {0x94, 0xcb, 0xf7, 0x28, 0x1e, 0xfd, 0x6d, 0x3f, 0xac, 0xf6, 0x5d, 0x66, + 0x96, 0x57, 0x57, 0xa2, 0x89, 0xf5, 0x9, 0xff, 0xf3, 0x1a, 0x7d}; + lwmqtt_string_t password = {23, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\DC4d\128<~\133\193\US", _password = Nothing, _lastWill = Just (LastWill +// {_willRetain = False, _willQoS = QoS1, _willTopic = "#\232\214h;\148\233\ESC\f\238c\v*\178\EM\DC2qs", _willMsg = +// "\250\"\228J*O\RS\174IQV(\146\131\255", _willProps = []}), _cleanSession = True, _keepAlive = 11426, _connID = +// "\204\182", _properties = []} +TEST(Connect311QCTest, Encode21) { + uint8_t pkt[] = {0x10, 0x3d, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x8e, 0x2c, 0xa2, 0x0, 0x2, 0xcc, 0xb6, + 0x0, 0x12, 0x23, 0xe8, 0xd6, 0x68, 0x3b, 0x94, 0xe9, 0x1b, 0xc, 0xee, 0x63, 0xb, 0x2a, 0xb2, + 0x19, 0x12, 0x71, 0x73, 0x0, 0xf, 0xfa, 0x22, 0xe4, 0x4a, 0x2a, 0x4f, 0x1e, 0xae, 0x49, 0x51, + 0x56, 0x28, 0x92, 0x83, 0xff, 0x0, 0x8, 0x14, 0x64, 0x80, 0x3c, 0x7e, 0x85, 0xc1, 0x1f}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x23, 0xe8, 0xd6, 0x68, 0x3b, 0x94, 0xe9, 0x1b, 0xc, + 0xee, 0x63, 0xb, 0x2a, 0xb2, 0x19, 0x12, 0x71, 0x73}; + lwmqtt_string_t will_topic = {18, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0xfa, 0x22, 0xe4, 0x4a, 0x2a, 0x4f, 0x1e, 0xae, + 0x49, 0x51, 0x56, 0x28, 0x92, 0x83, 0xff}; + lwmqtt_string_t will_payload = {15, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 11426; + uint8_t client_id_bytes[] = {0xcc, 0xb6}; + lwmqtt_string_t client_id = {2, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x14, 0x64, 0x80, 0x3c, 0x7e, 0x85, 0xc1, 0x1f}; + lwmqtt_string_t username = {8, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Nothing, _lastWill = Just (LastWill {_willRetain = True, _willQoS = +// QoS0, _willTopic = "30\150m;\145\234\188\240\155\227p8<", _willMsg = "k\131\233ZIw", _willProps = []}), _cleanSession +// = True, _keepAlive = 19711, _connID = "\STX\223\144\245\NAK\216/", _properties = []} +TEST(Connect311QCTest, Encode22) { + uint8_t pkt[] = {0x10, 0x2b, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x26, 0x4c, 0xff, 0x0, 0x7, 0x2, + 0xdf, 0x90, 0xf5, 0x15, 0xd8, 0x2f, 0x0, 0xe, 0x33, 0x30, 0x96, 0x6d, 0x3b, 0x91, 0xea, + 0xbc, 0xf0, 0x9b, 0xe3, 0x70, 0x38, 0x3c, 0x0, 0x6, 0x6b, 0x83, 0xe9, 0x5a, 0x49, 0x77}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x33, 0x30, 0x96, 0x6d, 0x3b, 0x91, 0xea, 0xbc, 0xf0, 0x9b, 0xe3, 0x70, 0x38, 0x3c}; + lwmqtt_string_t will_topic = {14, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x6b, 0x83, 0xe9, 0x5a, 0x49, 0x77}; + lwmqtt_string_t will_payload = {6, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 19711; + uint8_t client_id_bytes[] = {0x2, 0xdf, 0x90, 0xf5, 0x15, 0xd8, 0x2f}; + lwmqtt_string_t client_id = {7, (char*)&client_id_bytes}; + opts.client_id = client_id; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\237\&6f|\US#T\133\189\b", _password = Just +// "\NAK\150YWx\f\184\140\SO3\181\&0[\f\ETB", _lastWill = Nothing, _cleanSession = True, _keepAlive = 23584, _connID = " +// \149\136+\173Ve0s\240\142\225V]\231\US\208\&2\137:.~\229", _properties = []} +TEST(Connect311QCTest, Encode23) { + uint8_t pkt[] = {0x10, 0x40, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xc2, 0x5c, 0x20, 0x0, 0x17, 0x20, 0x95, 0x88, + 0x2b, 0xad, 0x56, 0x65, 0x30, 0x73, 0xf0, 0x8e, 0xe1, 0x56, 0x5d, 0xe7, 0x1f, 0xd0, 0x32, 0x89, 0x3a, + 0x2e, 0x7e, 0xe5, 0x0, 0xa, 0xed, 0x36, 0x66, 0x7c, 0x1f, 0x23, 0x54, 0x85, 0xbd, 0x8, 0x0, 0xf, + 0x15, 0x96, 0x59, 0x57, 0x78, 0xc, 0xb8, 0x8c, 0xe, 0x33, 0xb5, 0x30, 0x5b, 0xc, 0x17}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 23584; + uint8_t client_id_bytes[] = {0x20, 0x95, 0x88, 0x2b, 0xad, 0x56, 0x65, 0x30, 0x73, 0xf0, 0x8e, 0xe1, + 0x56, 0x5d, 0xe7, 0x1f, 0xd0, 0x32, 0x89, 0x3a, 0x2e, 0x7e, 0xe5}; + lwmqtt_string_t client_id = {23, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xed, 0x36, 0x66, 0x7c, 0x1f, 0x23, 0x54, 0x85, 0xbd, 0x8}; + lwmqtt_string_t username = {10, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x15, 0x96, 0x59, 0x57, 0x78, 0xc, 0xb8, 0x8c, 0xe, 0x33, 0xb5, 0x30, 0x5b, 0xc, 0x17}; + lwmqtt_string_t password = {15, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "Y\GS\153\146\134\165\&8^,k\\\EM\SYNh\207", _password = Just +// "D\149?\170\EOT\GSQ\216\139\168\210\247O\138\139[\237w\151\255Q{\"\145L~\172", _lastWill = Just (LastWill +// {_willRetain = True, _willQoS = QoS2, _willTopic = "}2\216h#\194\242\241G:\190{j\185\DC2\157}l", _willMsg = +// "D\196\243E\229\FS[+K\208\170=]o\152\NAKM\207\151\&8\188\CAN\234kd", _willProps = []}), _cleanSession = True, +// _keepAlive = 21608, _connID = "\130&B\t\131\165\255\248=\203\140\NAK\165\235f\226JC\f\212<\181\191", _properties = +// []} +TEST(Connect311QCTest, Encode24) { + uint8_t pkt[] = {0x10, 0x80, 0x1, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xf6, 0x54, 0x68, 0x0, 0x17, 0x82, 0x26, + 0x42, 0x9, 0x83, 0xa5, 0xff, 0xf8, 0x3d, 0xcb, 0x8c, 0x15, 0xa5, 0xeb, 0x66, 0xe2, 0x4a, 0x43, 0xc, + 0xd4, 0x3c, 0xb5, 0xbf, 0x0, 0x12, 0x7d, 0x32, 0xd8, 0x68, 0x23, 0xc2, 0xf2, 0xf1, 0x47, 0x3a, 0xbe, + 0x7b, 0x6a, 0xb9, 0x12, 0x9d, 0x7d, 0x6c, 0x0, 0x19, 0x44, 0xc4, 0xf3, 0x45, 0xe5, 0x1c, 0x5b, 0x2b, + 0x4b, 0xd0, 0xaa, 0x3d, 0x5d, 0x6f, 0x98, 0x15, 0x4d, 0xcf, 0x97, 0x38, 0xbc, 0x18, 0xea, 0x6b, 0x64, + 0x0, 0xf, 0x59, 0x1d, 0x99, 0x92, 0x86, 0xa5, 0x38, 0x5e, 0x2c, 0x6b, 0x5c, 0x19, 0x16, 0x68, 0xcf, + 0x0, 0x1b, 0x44, 0x95, 0x3f, 0xaa, 0x4, 0x1d, 0x51, 0xd8, 0x8b, 0xa8, 0xd2, 0xf7, 0x4f, 0x8a, 0x8b, + 0x5b, 0xed, 0x77, 0x97, 0xff, 0x51, 0x7b, 0x22, 0x91, 0x4c, 0x7e, 0xac}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x7d, 0x32, 0xd8, 0x68, 0x23, 0xc2, 0xf2, 0xf1, 0x47, + 0x3a, 0xbe, 0x7b, 0x6a, 0xb9, 0x12, 0x9d, 0x7d, 0x6c}; + lwmqtt_string_t will_topic = {18, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x44, 0xc4, 0xf3, 0x45, 0xe5, 0x1c, 0x5b, 0x2b, 0x4b, 0xd0, 0xaa, 0x3d, 0x5d, + 0x6f, 0x98, 0x15, 0x4d, 0xcf, 0x97, 0x38, 0xbc, 0x18, 0xea, 0x6b, 0x64}; + lwmqtt_string_t will_payload = {25, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS2; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 21608; + uint8_t client_id_bytes[] = {0x82, 0x26, 0x42, 0x9, 0x83, 0xa5, 0xff, 0xf8, 0x3d, 0xcb, 0x8c, 0x15, + 0xa5, 0xeb, 0x66, 0xe2, 0x4a, 0x43, 0xc, 0xd4, 0x3c, 0xb5, 0xbf}; + lwmqtt_string_t client_id = {23, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x59, 0x1d, 0x99, 0x92, 0x86, 0xa5, 0x38, 0x5e, 0x2c, 0x6b, 0x5c, 0x19, 0x16, 0x68, 0xcf}; + lwmqtt_string_t username = {15, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x44, 0x95, 0x3f, 0xaa, 0x4, 0x1d, 0x51, 0xd8, 0x8b, 0xa8, 0xd2, 0xf7, 0x4f, 0x8a, + 0x8b, 0x5b, 0xed, 0x77, 0x97, 0xff, 0x51, 0x7b, 0x22, 0x91, 0x4c, 0x7e, 0xac}; + lwmqtt_string_t password = {27, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "@\255\f -\161\165\199'wWt4\233\GS|D\153\234\178\201\GS\171c\234\218\227\128yV", +// _password = Just "\GS\f\242\202", _lastWill = Just (LastWill {_willRetain = False, _willQoS = QoS2, _willTopic = +// "t\201\133\209\218\232M\211\&6\137\160\250\176\231N\250K\156\n\154)G8m\230?*\204", _willMsg = +// "x\171H\181\148\190T\200\NAKGX-!", _willProps = []}), _cleanSession = False, _keepAlive = 31084, _connID = +// "x\223t=\142\180\166\&1lQ3\134,\179", _properties = []} +TEST(Connect311QCTest, Encode25) { + uint8_t pkt[] = {0x10, 0x6d, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xd4, 0x79, 0x6c, 0x0, 0xe, 0x78, 0xdf, + 0x74, 0x3d, 0x8e, 0xb4, 0xa6, 0x31, 0x6c, 0x51, 0x33, 0x86, 0x2c, 0xb3, 0x0, 0x1c, 0x74, 0xc9, + 0x85, 0xd1, 0xda, 0xe8, 0x4d, 0xd3, 0x36, 0x89, 0xa0, 0xfa, 0xb0, 0xe7, 0x4e, 0xfa, 0x4b, 0x9c, + 0xa, 0x9a, 0x29, 0x47, 0x38, 0x6d, 0xe6, 0x3f, 0x2a, 0xcc, 0x0, 0xd, 0x78, 0xab, 0x48, 0xb5, + 0x94, 0xbe, 0x54, 0xc8, 0x15, 0x47, 0x58, 0x2d, 0x21, 0x0, 0x1e, 0x40, 0xff, 0xc, 0x20, 0x2d, + 0xa1, 0xa5, 0xc7, 0x27, 0x77, 0x57, 0x74, 0x34, 0xe9, 0x1d, 0x7c, 0x44, 0x99, 0xea, 0xb2, 0xc9, + 0x1d, 0xab, 0x63, 0xea, 0xda, 0xe3, 0x80, 0x79, 0x56, 0x0, 0x4, 0x1d, 0xc, 0xf2, 0xca}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x74, 0xc9, 0x85, 0xd1, 0xda, 0xe8, 0x4d, 0xd3, 0x36, 0x89, 0xa0, 0xfa, 0xb0, 0xe7, + 0x4e, 0xfa, 0x4b, 0x9c, 0xa, 0x9a, 0x29, 0x47, 0x38, 0x6d, 0xe6, 0x3f, 0x2a, 0xcc}; + lwmqtt_string_t will_topic = {28, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x78, 0xab, 0x48, 0xb5, 0x94, 0xbe, 0x54, 0xc8, 0x15, 0x47, 0x58, 0x2d, 0x21}; + lwmqtt_string_t will_payload = {13, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS2; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 31084; + uint8_t client_id_bytes[] = {0x78, 0xdf, 0x74, 0x3d, 0x8e, 0xb4, 0xa6, 0x31, 0x6c, 0x51, 0x33, 0x86, 0x2c, 0xb3}; + lwmqtt_string_t client_id = {14, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x40, 0xff, 0xc, 0x20, 0x2d, 0xa1, 0xa5, 0xc7, 0x27, 0x77, 0x57, 0x74, 0x34, 0xe9, 0x1d, + 0x7c, 0x44, 0x99, 0xea, 0xb2, 0xc9, 0x1d, 0xab, 0x63, 0xea, 0xda, 0xe3, 0x80, 0x79, 0x56}; + lwmqtt_string_t username = {30, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x1d, 0xc, 0xf2, 0xca}; + lwmqtt_string_t password = {4, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "D", _password = Just "\168\254\f\211N\DC2\190*", _lastWill = Just (LastWill +// {_willRetain = False, _willQoS = QoS1, _willTopic = "\DC4l'\158\201oAkY#\147\181d\169\216\161\228\t", _willMsg = +// "\208", _willProps = []}), _cleanSession = True, _keepAlive = 11346, _connID = "\ENQ\142\185\198", _properties = []} +TEST(Connect311QCTest, Encode26) { + uint8_t pkt[] = {0x10, 0x34, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xce, 0x2c, 0x52, 0x0, 0x4, + 0x5, 0x8e, 0xb9, 0xc6, 0x0, 0x12, 0x14, 0x6c, 0x27, 0x9e, 0xc9, 0x6f, 0x41, 0x6b, + 0x59, 0x23, 0x93, 0xb5, 0x64, 0xa9, 0xd8, 0xa1, 0xe4, 0x9, 0x0, 0x1, 0xd0, 0x0, + 0x1, 0x44, 0x0, 0x8, 0xa8, 0xfe, 0xc, 0xd3, 0x4e, 0x12, 0xbe, 0x2a}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x14, 0x6c, 0x27, 0x9e, 0xc9, 0x6f, 0x41, 0x6b, 0x59, + 0x23, 0x93, 0xb5, 0x64, 0xa9, 0xd8, 0xa1, 0xe4, 0x9}; + lwmqtt_string_t will_topic = {18, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0xd0}; + lwmqtt_string_t will_payload = {1, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 11346; + uint8_t client_id_bytes[] = {0x5, 0x8e, 0xb9, 0xc6}; + lwmqtt_string_t client_id = {4, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x44}; + lwmqtt_string_t username = {1, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0xa8, 0xfe, 0xc, 0xd3, 0x4e, 0x12, 0xbe, 0x2a}; + lwmqtt_string_t password = {8, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\207*R\174r\141;b'{=", _password = Just +// "z\205\192_%@\212\199\151\215c|\247\189\171\&4]G\215\ETB", _lastWill = Just (LastWill {_willRetain = True, _willQoS = +// QoS2, _willTopic = "\DC3\145\DC4\145\NUL\135\137|", _willMsg = +// "\161\158s\143&OOq\DC3Z\EM\t\230\252G1A\220j\197i\US5", _willProps = []}), _cleanSession = True, _keepAlive = 13315, +// _connID = "%t\158\172\148\133\248\183\148\DELO\147T\240\DC3+", _properties = []} +TEST(Connect311QCTest, Encode27) { + uint8_t pkt[] = {0x10, 0x62, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xf6, 0x34, 0x3, 0x0, 0x10, 0x25, 0x74, 0x9e, + 0xac, 0x94, 0x85, 0xf8, 0xb7, 0x94, 0x7f, 0x4f, 0x93, 0x54, 0xf0, 0x13, 0x2b, 0x0, 0x8, 0x13, 0x91, + 0x14, 0x91, 0x0, 0x87, 0x89, 0x7c, 0x0, 0x17, 0xa1, 0x9e, 0x73, 0x8f, 0x26, 0x4f, 0x4f, 0x71, 0x13, + 0x5a, 0x19, 0x9, 0xe6, 0xfc, 0x47, 0x31, 0x41, 0xdc, 0x6a, 0xc5, 0x69, 0x1f, 0x35, 0x0, 0xb, 0xcf, + 0x2a, 0x52, 0xae, 0x72, 0x8d, 0x3b, 0x62, 0x27, 0x7b, 0x3d, 0x0, 0x14, 0x7a, 0xcd, 0xc0, 0x5f, 0x25, + 0x40, 0xd4, 0xc7, 0x97, 0xd7, 0x63, 0x7c, 0xf7, 0xbd, 0xab, 0x34, 0x5d, 0x47, 0xd7, 0x17}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x13, 0x91, 0x14, 0x91, 0x0, 0x87, 0x89, 0x7c}; + lwmqtt_string_t will_topic = {8, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0xa1, 0x9e, 0x73, 0x8f, 0x26, 0x4f, 0x4f, 0x71, 0x13, 0x5a, 0x19, 0x9, + 0xe6, 0xfc, 0x47, 0x31, 0x41, 0xdc, 0x6a, 0xc5, 0x69, 0x1f, 0x35}; + lwmqtt_string_t will_payload = {23, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS2; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 13315; + uint8_t client_id_bytes[] = {0x25, 0x74, 0x9e, 0xac, 0x94, 0x85, 0xf8, 0xb7, + 0x94, 0x7f, 0x4f, 0x93, 0x54, 0xf0, 0x13, 0x2b}; + lwmqtt_string_t client_id = {16, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xcf, 0x2a, 0x52, 0xae, 0x72, 0x8d, 0x3b, 0x62, 0x27, 0x7b, 0x3d}; + lwmqtt_string_t username = {11, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x7a, 0xcd, 0xc0, 0x5f, 0x25, 0x40, 0xd4, 0xc7, 0x97, 0xd7, + 0x63, 0x7c, 0xf7, 0xbd, 0xab, 0x34, 0x5d, 0x47, 0xd7, 0x17}; + lwmqtt_string_t password = {20, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Just "9\SUBa", _lastWill = Just (LastWill {_willRetain = False, +// _willQoS = QoS1, _willTopic = "\229Zo\akR\167\175\227\&7\152-\t\SO\240(\CAN+\178\193\170%7\140\228\200\241\175N", +// _willMsg = "\\DN", _willProps = []}), _cleanSession = True, _keepAlive = 2663, _connID = "_", _properties = []} +TEST(Connect311QCTest, Encode28) { + uint8_t pkt[] = {0x10, 0x31, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0xe, 0xa, 0x67, 0x0, 0x1, 0x5f, 0x0, 0x1d, + 0xe5, 0x5a, 0x6f, 0x7, 0x6b, 0x52, 0xa7, 0xaf, 0xe3, 0x37, 0x98, 0x2d, 0x9, 0xe, 0xf0, 0x28, 0x18, + 0x2b, 0xb2, 0xc1, 0xaa, 0x25, 0x37, 0x8c, 0xe4, 0xc8, 0xf1, 0xaf, 0x4e, 0x0, 0x3, 0x5c, 0x44, 0x4e}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0xe5, 0x5a, 0x6f, 0x7, 0x6b, 0x52, 0xa7, 0xaf, 0xe3, 0x37, 0x98, 0x2d, 0x9, 0xe, 0xf0, + 0x28, 0x18, 0x2b, 0xb2, 0xc1, 0xaa, 0x25, 0x37, 0x8c, 0xe4, 0xc8, 0xf1, 0xaf, 0x4e}; + lwmqtt_string_t will_topic = {29, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x5c, 0x44, 0x4e}; + lwmqtt_string_t will_payload = {3, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 2663; + uint8_t client_id_bytes[] = {0x5f}; + lwmqtt_string_t client_id = {1, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t password_bytes[] = {0x39, 0x1a, 0x61}; + lwmqtt_string_t password = {3, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "fF\131\191\&2\166\189\187F", _password = Nothing, _lastWill = Just (LastWill +// {_willRetain = False, _willQoS = QoS1, _willTopic = "\ESC\162W>\201\134", _willMsg = +// "\CAN\EOT\254w\EOT&B2\STX\130\DC2\130\234\202\238\&1\DC4\179\ETB\223\169\132GI&\ACK", _willProps = []}), +// _cleanSession = False, _keepAlive = 16611, _connID = "P\213\SOHx\239\228P", _properties = []} +TEST(Connect311QCTest, Encode29) { + uint8_t pkt[] = {0x10, 0x42, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x4, 0x8c, 0x40, 0xe3, 0x0, 0x7, + 0x50, 0xd5, 0x1, 0x78, 0xef, 0xe4, 0x50, 0x0, 0x6, 0x1b, 0xa2, 0x57, 0x3e, 0xc9, + 0x86, 0x0, 0x1a, 0x18, 0x4, 0xfe, 0x77, 0x4, 0x26, 0x42, 0x32, 0x2, 0x82, 0x12, + 0x82, 0xea, 0xca, 0xee, 0x31, 0x14, 0xb3, 0x17, 0xdf, 0xa9, 0x84, 0x47, 0x49, 0x26, + 0x6, 0x0, 0x9, 0x66, 0x46, 0x83, 0xbf, 0x32, 0xa6, 0xbd, 0xbb, 0x46}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x1b, 0xa2, 0x57, 0x3e, 0xc9, 0x86}; + lwmqtt_string_t will_topic = {6, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x18, 0x4, 0xfe, 0x77, 0x4, 0x26, 0x42, 0x32, 0x2, 0x82, 0x12, 0x82, 0xea, + 0xca, 0xee, 0x31, 0x14, 0xb3, 0x17, 0xdf, 0xa9, 0x84, 0x47, 0x49, 0x26, 0x6}; + lwmqtt_string_t will_payload = {26, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 16611; + uint8_t client_id_bytes[] = {0x50, 0xd5, 0x1, 0x78, 0xef, 0xe4, 0x50}; + lwmqtt_string_t client_id = {7, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x66, 0x46, 0x83, 0xbf, 0x32, 0xa6, 0xbd, 0xbb, 0x46}; + lwmqtt_string_t username = {9, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT311, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "y\204\237\224r>\158", _password = Nothing, _lastWill = Just (LastWill {_willRetain +// = False, _willQoS = QoS1, _willTopic = +// "[J\196H\203W\CAN\171&\151\152S\228\245A\CAN%\DLE\139+/j\217;)r\164P\246\DEL\165v\148A\128",PropContentType +// "\148E\222\165I0\NUL\DLE\206\185W\n",PropWillDelayInterval 29156,PropPayloadFormatIndicator 14,PropAuthenticationData +// "w\146W" +// ".\159\135&\149.\187\148\163\DEL\239\254+\154W\225}#",PropRequestProblemInformation 32,PropTopicAliasMaximum +// 22091,PropMessageExpiryInterval 7460,PropAuthenticationData "\221J\212\&6\208\153",PropPayloadFormatIndicator +// 192,PropRequestResponseInformation 137,PropServerKeepAlive 5239,PropReasonString +// "\EOT\227\138\183\GS\245\v\188\162\243\249",PropSessionExpiryInterval 27741,PropMessageExpiryInterval +// 2221,PropSharedSubscriptionAvailable 223,PropTopicAliasMaximum 5638,PropMessageExpiryInterval +// 30883,PropPayloadFormatIndicator 140,PropCorrelationData "\241\US\202\238\&8{\169\ESC\DC4\181"]}), _cleanSession = +// False, _keepAlive = 10327, _connID = "\197F\a\173", _properties = [PropTopicAlias 29372,PropMaximumPacketSize +// 21608,PropReasonString "\n\\:|\189\220,\129/T\130%\243\171\237\186*\DC2.gjk\v\157\253/",PropServerKeepAlive +// 7092,PropResponseTopic "\DC4\165\249\175\153VA\157\r\SO\130G",PropReceiveMaximum +// 18469,PropSubscriptionIdentifierAvailable 50,PropReceiveMaximum 7905,PropRetainAvailable 127,PropTopicAliasMaximum +// 20888,PropAuthenticationData +// "e\201\169\133\DC3\185\166\211\157\223(5\235\160\217\236",PropSubscriptionIdentifierAvailable +// 102,PropRequestProblemInformation 178,PropMessageExpiryInterval 26119,PropTopicAliasMaximum +// 32114,PropRequestProblemInformation 60,PropTopicAliasMaximum 19694,PropAuthenticationMethod +// "x\181F\191\n\ACK\184^\254{{w\191\184\&4d\134\ACKb!\163",PropRetainAvailable 90,PropMaximumQoS +// 161,PropTopicAliasMaximum 17520,PropReceiveMaximum 3344,PropAssignedClientIdentifier "\DC2",PropUserProperty +// "GI\151\166\EOT\211)}\SI\179\228\148N\138" "\233O\189\172[X0\156\208",PropRequestResponseInformation 185]} +TEST(Connect5QCTest, Encode9) { + uint8_t pkt[] = { + 0x10, 0xc0, 0x3, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0x64, 0x28, 0x57, 0xac, 0x1, 0x23, 0x72, 0xbc, 0x27, + 0x0, 0x0, 0x54, 0x68, 0x1f, 0x0, 0x1a, 0xa, 0x5c, 0x3a, 0x7c, 0xbd, 0xdc, 0x2c, 0x81, 0x2f, 0x54, 0x82, 0x25, + 0xf3, 0xab, 0xed, 0xba, 0x2a, 0x12, 0x2e, 0x67, 0x6a, 0x6b, 0xb, 0x9d, 0xfd, 0x2f, 0x13, 0x1b, 0xb4, 0x8, 0x0, + 0xc, 0x14, 0xa5, 0xf9, 0xaf, 0x99, 0x56, 0x41, 0x9d, 0xd, 0xe, 0x82, 0x47, 0x21, 0x48, 0x25, 0x29, 0x32, 0x21, + 0x1e, 0xe1, 0x25, 0x7f, 0x22, 0x51, 0x98, 0x16, 0x0, 0x10, 0x65, 0xc9, 0xa9, 0x85, 0x13, 0xb9, 0xa6, 0xd3, 0x9d, + 0xdf, 0x28, 0x35, 0xeb, 0xa0, 0xd9, 0xec, 0x29, 0x66, 0x17, 0xb2, 0x2, 0x0, 0x0, 0x66, 0x7, 0x22, 0x7d, 0x72, + 0x17, 0x3c, 0x22, 0x4c, 0xee, 0x15, 0x0, 0x15, 0x78, 0xb5, 0x46, 0xbf, 0xa, 0x6, 0xb8, 0x5e, 0xfe, 0x7b, 0x7b, + 0x77, 0xbf, 0xb8, 0x34, 0x64, 0x86, 0x6, 0x62, 0x21, 0xa3, 0x25, 0x5a, 0x24, 0xa1, 0x22, 0x44, 0x70, 0x21, 0xd, + 0x10, 0x12, 0x0, 0x1, 0x12, 0x26, 0x0, 0xe, 0x47, 0x49, 0x97, 0xa6, 0x4, 0xd3, 0x29, 0x7d, 0xf, 0xb3, 0xe4, + 0x94, 0x4e, 0x8a, 0x0, 0x9, 0xe9, 0x4f, 0xbd, 0xac, 0x5b, 0x58, 0x30, 0x9c, 0xd0, 0x19, 0xb9, 0x0, 0x4, 0xc5, + 0x46, 0x7, 0xad, 0xd5, 0x1, 0x26, 0x0, 0x1d, 0x8, 0x4, 0x57, 0x55, 0x5a, 0xfb, 0xc0, 0x8f, 0x18, 0xeb, 0x3a, + 0x83, 0x53, 0x9d, 0x78, 0x14, 0xfd, 0x7f, 0x4f, 0xc, 0x2c, 0x1, 0xe4, 0x97, 0x73, 0xe8, 0x31, 0x33, 0xbe, 0x0, + 0x13, 0x5f, 0xdf, 0x9f, 0xa9, 0xd2, 0x50, 0x13, 0x37, 0x8e, 0x4e, 0x28, 0x68, 0x5c, 0x49, 0x3f, 0xee, 0x1d, 0xc7, + 0xbd, 0x1a, 0x0, 0x16, 0xe, 0x66, 0xc4, 0xad, 0xa5, 0xf8, 0x8e, 0x48, 0x6b, 0xfc, 0x2d, 0xa8, 0xba, 0xdc, 0x29, + 0x92, 0x4d, 0x6a, 0x5b, 0x44, 0xbc, 0x6c, 0x27, 0x0, 0x0, 0x7, 0x46, 0x27, 0x0, 0x0, 0x76, 0xe, 0x13, 0x43, + 0xf8, 0x26, 0x0, 0x18, 0x86, 0x5f, 0xce, 0x55, 0x1f, 0x78, 0xc9, 0xbc, 0x2f, 0x2a, 0x7b, 0x74, 0xaa, 0x1f, 0x37, + 0x6, 0x2d, 0x1b, 0x52, 0xd4, 0x34, 0xe9, 0x3e, 0x57, 0x0, 0x12, 0x2e, 0x9f, 0x87, 0x26, 0x95, 0x2e, 0xbb, 0x94, + 0xa3, 0x7f, 0xef, 0xfe, 0x2b, 0x9a, 0x57, 0xe1, 0x7d, 0x23, 0x17, 0x20, 0x22, 0x56, 0x4b, 0x2, 0x0, 0x0, 0x1d, + 0x24, 0x16, 0x0, 0x6, 0xdd, 0x4a, 0xd4, 0x36, 0xd0, 0x99, 0x1, 0xc0, 0x19, 0x89, 0x13, 0x14, 0x77, 0x1f, 0x0, + 0xb, 0x4, 0xe3, 0x8a, 0xb7, 0x1d, 0xf5, 0xb, 0xbc, 0xa2, 0xf3, 0xf9, 0x11, 0x0, 0x0, 0x6c, 0x5d, 0x2, 0x0, + 0x0, 0x8, 0xad, 0x2a, 0xdf, 0x22, 0x16, 0x6, 0x2, 0x0, 0x0, 0x78, 0xa3, 0x1, 0x8c, 0x9, 0x0, 0xa, 0xf1, + 0x1f, 0xca, 0xee, 0x38, 0x7b, 0xa9, 0x1b, 0x14, 0xb5, 0x0, 0x1b, 0x18, 0x23, 0xe8, 0xda, 0x84, 0x43, 0x1, 0xe9, + 0x6c, 0xa8, 0xcc, 0xb6, 0x80, 0x31, 0x93, 0x3, 0xb9, 0xb8, 0x59, 0xfe, 0x3c, 0xc0, 0xaa, 0x4d, 0x89, 0x8f, 0xb9, + 0x0, 0x9, 0x4c, 0x5c, 0x33, 0xaa, 0x95, 0xf9, 0x7c, 0x63, 0x47, 0x0, 0x1, 0xaf}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xa, 0x5c, 0x3a, 0x7c, 0xbd, 0xdc, 0x2c, 0x81, 0x2f, 0x54, 0x82, 0x25, 0xf3, + 0xab, 0xed, 0xba, 0x2a, 0x12, 0x2e, 0x67, 0x6a, 0x6b, 0xb, 0x9d, 0xfd, 0x2f}; + uint8_t bytesprops1[] = {0x14, 0xa5, 0xf9, 0xaf, 0x99, 0x56, 0x41, 0x9d, 0xd, 0xe, 0x82, 0x47}; + uint8_t bytesprops2[] = {0x65, 0xc9, 0xa9, 0x85, 0x13, 0xb9, 0xa6, 0xd3, + 0x9d, 0xdf, 0x28, 0x35, 0xeb, 0xa0, 0xd9, 0xec}; + uint8_t bytesprops3[] = {0x78, 0xb5, 0x46, 0xbf, 0xa, 0x6, 0xb8, 0x5e, 0xfe, 0x7b, 0x7b, + 0x77, 0xbf, 0xb8, 0x34, 0x64, 0x86, 0x6, 0x62, 0x21, 0xa3}; + uint8_t bytesprops4[] = {0x12}; + uint8_t bytesprops6[] = {0xe9, 0x4f, 0xbd, 0xac, 0x5b, 0x58, 0x30, 0x9c, 0xd0}; + uint8_t bytesprops5[] = {0x47, 0x49, 0x97, 0xa6, 0x4, 0xd3, 0x29, 0x7d, 0xf, 0xb3, 0xe4, 0x94, 0x4e, 0x8a}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 29372}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 21608}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {26, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 7092}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {12, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 18469}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 50}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 7905}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 127}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 20888}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {16, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 102}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 178}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 26119}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 32114}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 60}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 19694}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {21, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 90}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 161}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 17520}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 3344}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {1, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {14, (char*)&bytesprops5}, .v = {9, (char*)&bytesprops6}}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 185}}, + }; + + lwmqtt_properties_t props = {25, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops1[] = {0x5f, 0xdf, 0x9f, 0xa9, 0xd2, 0x50, 0x13, 0x37, 0x8e, 0x4e, + 0x28, 0x68, 0x5c, 0x49, 0x3f, 0xee, 0x1d, 0xc7, 0xbd}; + uint8_t byteswillprops0[] = {0x8, 0x4, 0x57, 0x55, 0x5a, 0xfb, 0xc0, 0x8f, 0x18, 0xeb, 0x3a, 0x83, 0x53, 0x9d, 0x78, + 0x14, 0xfd, 0x7f, 0x4f, 0xc, 0x2c, 0x1, 0xe4, 0x97, 0x73, 0xe8, 0x31, 0x33, 0xbe}; + uint8_t byteswillprops2[] = {0xe, 0x66, 0xc4, 0xad, 0xa5, 0xf8, 0x8e, 0x48, 0x6b, 0xfc, 0x2d, + 0xa8, 0xba, 0xdc, 0x29, 0x92, 0x4d, 0x6a, 0x5b, 0x44, 0xbc, 0x6c}; + uint8_t byteswillprops4[] = {0x2e, 0x9f, 0x87, 0x26, 0x95, 0x2e, 0xbb, 0x94, 0xa3, + 0x7f, 0xef, 0xfe, 0x2b, 0x9a, 0x57, 0xe1, 0x7d, 0x23}; + uint8_t byteswillprops3[] = {0x86, 0x5f, 0xce, 0x55, 0x1f, 0x78, 0xc9, 0xbc, 0x2f, 0x2a, 0x7b, 0x74, + 0xaa, 0x1f, 0x37, 0x6, 0x2d, 0x1b, 0x52, 0xd4, 0x34, 0xe9, 0x3e, 0x57}; + uint8_t byteswillprops5[] = {0xdd, 0x4a, 0xd4, 0x36, 0xd0, 0x99}; + uint8_t byteswillprops6[] = {0x4, 0xe3, 0x8a, 0xb7, 0x1d, 0xf5, 0xb, 0xbc, 0xa2, 0xf3, 0xf9}; + uint8_t byteswillprops7[] = {0xf1, 0x1f, 0xca, 0xee, 0x38, 0x7b, 0xa9, 0x1b, 0x14, 0xb5}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {29, (char*)&byteswillprops0}, .v = {19, (char*)&byteswillprops1}}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {22, (char*)&byteswillprops2}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 1862}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 30222}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 17400}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {24, (char*)&byteswillprops3}, .v = {18, (char*)&byteswillprops4}}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 32}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 22091}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 7460}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {6, (char*)&byteswillprops5}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 192}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 137}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 5239}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {11, (char*)&byteswillprops6}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 27741}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 2221}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 223}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 5638}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 30883}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 140}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {10, (char*)&byteswillprops7}}}, + }; + + lwmqtt_properties_t willprops = {21, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x18, 0x23, 0xe8, 0xda, 0x84, 0x43, 0x1, 0xe9, 0x6c, 0xa8, 0xcc, 0xb6, 0x80, 0x31, + 0x93, 0x3, 0xb9, 0xb8, 0x59, 0xfe, 0x3c, 0xc0, 0xaa, 0x4d, 0x89, 0x8f, 0xb9}; + lwmqtt_string_t will_topic = {27, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x4c, 0x5c, 0x33, 0xaa, 0x95, 0xf9, 0x7c, 0x63, 0x47}; + lwmqtt_string_t will_payload = {9, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 10327; + uint8_t client_id_bytes[] = {0xc5, 0x46, 0x7, 0xad}; + lwmqtt_string_t client_id = {4, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t password_bytes[] = {0xaf}; + lwmqtt_string_t password = {1, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\161M\139\STX'\150/\148\f\226\225\132", _password = Just "F\225WbF\224\168", +// _lastWill = Nothing, _cleanSession = False, _keepAlive = 18820, _connID = +// "\239\187K\240\&8zO\aU|\SI\206\249i\178\203\168", _properties = [PropWildcardSubscriptionAvailable +// 123,PropTopicAliasMaximum 30304,PropMaximumPacketSize 20871,PropSharedSubscriptionAvailable 108,PropWillDelayInterval +// 29760,PropSubscriptionIdentifierAvailable 98,PropContentType +// "\249\212\147\143\213\157\b}\215\244\EM",PropAssignedClientIdentifier +// "\RS\r10\246+d\NAK\159\141\152\185\244\224F",PropReasonString +// "\230\204-\198d\232\195\135\233\SUB\221n>\141\180\FS\193",PropUserProperty +// "<\183\191\232\DC1\196\162\GS\154\DC1\255\157\RS\183\169" "B\217\247y\f\252N;T\199V",PropSessionExpiryInterval +// 18786,PropAuthenticationData "\238\SI\130_f;\176\140F\213u",PropCorrelationData +// "\236u\195\255\165h\196%=\254\202>\183<9\NUL\174`\236\206\211",PropSharedSubscriptionAvailable +// 9,PropMessageExpiryInterval 6370,PropServerReference "\RS\150"]} +TEST(Connect5QCTest, Encode10) { + uint8_t pkt[] = {0x10, 0xd3, 0x1, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0xc0, 0x49, 0x84, 0x9d, 0x1, 0x28, 0x7b, + 0x22, 0x76, 0x60, 0x27, 0x0, 0x0, 0x51, 0x87, 0x2a, 0x6c, 0x18, 0x0, 0x0, 0x74, 0x40, 0x29, 0x62, + 0x3, 0x0, 0xb, 0xf9, 0xd4, 0x93, 0x8f, 0xd5, 0x9d, 0x8, 0x7d, 0xd7, 0xf4, 0x19, 0x12, 0x0, 0xf, + 0x1e, 0xd, 0x31, 0x30, 0xf6, 0x2b, 0x64, 0x15, 0x9f, 0x8d, 0x98, 0xb9, 0xf4, 0xe0, 0x46, 0x1f, 0x0, + 0x11, 0xe6, 0xcc, 0x2d, 0xc6, 0x64, 0xe8, 0xc3, 0x87, 0xe9, 0x1a, 0xdd, 0x6e, 0x3e, 0x8d, 0xb4, 0x1c, + 0xc1, 0x26, 0x0, 0xf, 0x3c, 0xb7, 0xbf, 0xe8, 0x11, 0xc4, 0xa2, 0x1d, 0x9a, 0x11, 0xff, 0x9d, 0x1e, + 0xb7, 0xa9, 0x0, 0xb, 0x42, 0xd9, 0xf7, 0x79, 0xc, 0xfc, 0x4e, 0x3b, 0x54, 0xc7, 0x56, 0x11, 0x0, + 0x0, 0x49, 0x62, 0x16, 0x0, 0xb, 0xee, 0xf, 0x82, 0x5f, 0x66, 0x3b, 0xb0, 0x8c, 0x46, 0xd5, 0x75, + 0x9, 0x0, 0x15, 0xec, 0x75, 0xc3, 0xff, 0xa5, 0x68, 0xc4, 0x25, 0x3d, 0xfe, 0xca, 0x3e, 0xb7, 0x3c, + 0x39, 0x0, 0xae, 0x60, 0xec, 0xce, 0xd3, 0x2a, 0x9, 0x2, 0x0, 0x0, 0x18, 0xe2, 0x1c, 0x0, 0x2, + 0x1e, 0x96, 0x0, 0x11, 0xef, 0xbb, 0x4b, 0xf0, 0x38, 0x7a, 0x4f, 0x7, 0x55, 0x7c, 0xf, 0xce, 0xf9, + 0x69, 0xb2, 0xcb, 0xa8, 0x0, 0xc, 0xa1, 0x4d, 0x8b, 0x2, 0x27, 0x96, 0x2f, 0x94, 0xc, 0xe2, 0xe1, + 0x84, 0x0, 0x7, 0x46, 0xe1, 0x57, 0x62, 0x46, 0xe0, 0xa8}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xf9, 0xd4, 0x93, 0x8f, 0xd5, 0x9d, 0x8, 0x7d, 0xd7, 0xf4, 0x19}; + uint8_t bytesprops1[] = {0x1e, 0xd, 0x31, 0x30, 0xf6, 0x2b, 0x64, 0x15, 0x9f, 0x8d, 0x98, 0xb9, 0xf4, 0xe0, 0x46}; + uint8_t bytesprops2[] = {0xe6, 0xcc, 0x2d, 0xc6, 0x64, 0xe8, 0xc3, 0x87, 0xe9, + 0x1a, 0xdd, 0x6e, 0x3e, 0x8d, 0xb4, 0x1c, 0xc1}; + uint8_t bytesprops4[] = {0x42, 0xd9, 0xf7, 0x79, 0xc, 0xfc, 0x4e, 0x3b, 0x54, 0xc7, 0x56}; + uint8_t bytesprops3[] = {0x3c, 0xb7, 0xbf, 0xe8, 0x11, 0xc4, 0xa2, 0x1d, 0x9a, 0x11, 0xff, 0x9d, 0x1e, 0xb7, 0xa9}; + uint8_t bytesprops5[] = {0xee, 0xf, 0x82, 0x5f, 0x66, 0x3b, 0xb0, 0x8c, 0x46, 0xd5, 0x75}; + uint8_t bytesprops6[] = {0xec, 0x75, 0xc3, 0xff, 0xa5, 0x68, 0xc4, 0x25, 0x3d, 0xfe, 0xca, + 0x3e, 0xb7, 0x3c, 0x39, 0x0, 0xae, 0x60, 0xec, 0xce, 0xd3}; + uint8_t bytesprops7[] = {0x1e, 0x96}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 123}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 30304}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 20871}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 108}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 29760}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 98}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {11, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {15, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {17, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {15, (char*)&bytesprops3}, .v = {11, (char*)&bytesprops4}}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 18786}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {11, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {21, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 9}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 6370}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {2, (char*)&bytesprops7}}}, + }; + + lwmqtt_properties_t props = {16, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 18820; + uint8_t client_id_bytes[] = {0xef, 0xbb, 0x4b, 0xf0, 0x38, 0x7a, 0x4f, 0x7, 0x55, + 0x7c, 0xf, 0xce, 0xf9, 0x69, 0xb2, 0xcb, 0xa8}; + lwmqtt_string_t client_id = {17, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xa1, 0x4d, 0x8b, 0x2, 0x27, 0x96, 0x2f, 0x94, 0xc, 0xe2, 0xe1, 0x84}; + lwmqtt_string_t username = {12, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x46, 0xe1, 0x57, 0x62, 0x46, 0xe0, 0xa8}; + lwmqtt_string_t password = {7, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\212\246\v\208Q", _password = Nothing, _lastWill = Just (LastWill {_willRetain = +// False, _willQoS = QoS0, _willTopic = "\DC4\STX\237+\169PM5-\137\&2\143\DC1I\143\ETB8R\205\"+\207'\229\244", _willMsg +// = "*\236\193\FS\231\145S\224#\173\"\224\223\227\142\242*i\131\&8\203\156x\161\231Z", _willProps = +// [PropAuthenticationData "@F\SI\189^\211\234s|5\146(\168\164\192 \153\180c\220\252",PropRequestProblemInformation +// 232,PropAuthenticationData "\CAN\254\164\"\fI(\228cd\224y;O\SOK!\167)\154\222Ld",PropTopicAlias +// 21484,PropServerKeepAlive 7099,PropPayloadFormatIndicator 206,PropServerReference +// "\162\&6\244\147`\171\147\SI\NAKo+\182\232\254\143A\213\DC2\163\188",PropResponseTopic +// "Y\211\251'\226n\vS\158\253hL-\ETB\CAN2\238\SO\SO3\201_\NUL\144\ETB\138{\149\ESC\245",PropTopicAlias +// 32745,PropAuthenticationData "Dh\n\DC2W\232t\159\162mH",PropReceiveMaximum 15700,PropContentType +// "0\ETB\239",PropMaximumPacketSize 30512]}), _cleanSession = True, _keepAlive = 25243, _connID = +// "\183\141\187\211\227F!\186\233+s9c^7\154\b\193Y\148\174w\216=\234K1", _properties = [PropWillDelayInterval +// 15341,PropServerKeepAlive 22577,PropPayloadFormatIndicator 170,PropSubscriptionIdentifier +// 18,PropAssignedClientIdentifier +// ";j\ETB\162-\196\v\162\159GIM\202\222\156KXAJ\244\164\177g\242\223\154\ENQ\DLE",PropAssignedClientIdentifier +// "^c\253)\152\255\252\DLE\r\218\251)\246\255\197\168\244\DC4?",PropWillDelayInterval 1372,PropMessageExpiryInterval +// 1820,PropReceiveMaximum 31562,PropAuthenticationMethod +// "qsv@\208d\EM\241Y\239\FS:_1)n8\SI\231\145\195",PropMessageExpiryInterval 3761]} +TEST(Connect5QCTest, Encode11) { + uint8_t pkt[] = { + 0x10, 0xe6, 0x2, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0x86, 0x62, 0x9b, 0x6b, 0x18, 0x0, 0x0, 0x3b, 0xed, + 0x13, 0x58, 0x31, 0x1, 0xaa, 0xb, 0x12, 0x12, 0x0, 0x1c, 0x3b, 0x6a, 0x17, 0xa2, 0x2d, 0xc4, 0xb, 0xa2, 0x9f, + 0x47, 0x49, 0x4d, 0xca, 0xde, 0x9c, 0x4b, 0x58, 0x41, 0x4a, 0xf4, 0xa4, 0xb1, 0x67, 0xf2, 0xdf, 0x9a, 0x5, 0x10, + 0x12, 0x0, 0x13, 0x5e, 0x63, 0xfd, 0x29, 0x98, 0xff, 0xfc, 0x10, 0xd, 0xda, 0xfb, 0x29, 0xf6, 0xff, 0xc5, 0xa8, + 0xf4, 0x14, 0x3f, 0x18, 0x0, 0x0, 0x5, 0x5c, 0x2, 0x0, 0x0, 0x7, 0x1c, 0x21, 0x7b, 0x4a, 0x15, 0x0, 0x15, + 0x71, 0x73, 0x76, 0x40, 0xd0, 0x64, 0x19, 0xf1, 0x59, 0xef, 0x1c, 0x3a, 0x5f, 0x31, 0x29, 0x6e, 0x38, 0xf, 0xe7, + 0x91, 0xc3, 0x2, 0x0, 0x0, 0xe, 0xb1, 0x0, 0x1b, 0xb7, 0x8d, 0xbb, 0xd3, 0xe3, 0x46, 0x21, 0xba, 0xe9, 0x2b, + 0x73, 0x39, 0x63, 0x5e, 0x37, 0x9a, 0x8, 0xc1, 0x59, 0x94, 0xae, 0x77, 0xd8, 0x3d, 0xea, 0x4b, 0x31, 0x93, 0x1, + 0x16, 0x0, 0x15, 0x40, 0x46, 0xf, 0xbd, 0x5e, 0xd3, 0xea, 0x73, 0x7c, 0x35, 0x92, 0x28, 0xa8, 0xa4, 0xc0, 0x20, + 0x99, 0xb4, 0x63, 0xdc, 0xfc, 0x17, 0xe8, 0x16, 0x0, 0x17, 0x18, 0xfe, 0xa4, 0x22, 0xc, 0x49, 0x28, 0xe4, 0x63, + 0x64, 0xe0, 0x79, 0x3b, 0x4f, 0xe, 0x4b, 0x21, 0xa7, 0x29, 0x9a, 0xde, 0x4c, 0x64, 0x23, 0x53, 0xec, 0x13, 0x1b, + 0xbb, 0x1, 0xce, 0x1c, 0x0, 0x14, 0xa2, 0x36, 0xf4, 0x93, 0x60, 0xab, 0x93, 0xf, 0x15, 0x6f, 0x2b, 0xb6, 0xe8, + 0xfe, 0x8f, 0x41, 0xd5, 0x12, 0xa3, 0xbc, 0x8, 0x0, 0x1e, 0x59, 0xd3, 0xfb, 0x27, 0xe2, 0x6e, 0xb, 0x53, 0x9e, + 0xfd, 0x68, 0x4c, 0x2d, 0x17, 0x18, 0x32, 0xee, 0xe, 0xe, 0x33, 0xc9, 0x5f, 0x0, 0x90, 0x17, 0x8a, 0x7b, 0x95, + 0x1b, 0xf5, 0x23, 0x7f, 0xe9, 0x16, 0x0, 0xb, 0x44, 0x68, 0xa, 0x12, 0x57, 0xe8, 0x74, 0x9f, 0xa2, 0x6d, 0x48, + 0x21, 0x3d, 0x54, 0x3, 0x0, 0x3, 0x30, 0x17, 0xef, 0x27, 0x0, 0x0, 0x77, 0x30, 0x0, 0x19, 0x14, 0x2, 0xed, + 0x2b, 0xa9, 0x50, 0x4d, 0x35, 0x2d, 0x89, 0x32, 0x8f, 0x11, 0x49, 0x8f, 0x17, 0x38, 0x52, 0xcd, 0x22, 0x2b, 0xcf, + 0x27, 0xe5, 0xf4, 0x0, 0x1a, 0x2a, 0xec, 0xc1, 0x1c, 0xe7, 0x91, 0x53, 0xe0, 0x23, 0xad, 0x22, 0xe0, 0xdf, 0xe3, + 0x8e, 0xf2, 0x2a, 0x69, 0x83, 0x38, 0xcb, 0x9c, 0x78, 0xa1, 0xe7, 0x5a, 0x0, 0x5, 0xd4, 0xf6, 0xb, 0xd0, 0x51}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x3b, 0x6a, 0x17, 0xa2, 0x2d, 0xc4, 0xb, 0xa2, 0x9f, 0x47, 0x49, 0x4d, 0xca, 0xde, + 0x9c, 0x4b, 0x58, 0x41, 0x4a, 0xf4, 0xa4, 0xb1, 0x67, 0xf2, 0xdf, 0x9a, 0x5, 0x10}; + uint8_t bytesprops1[] = {0x5e, 0x63, 0xfd, 0x29, 0x98, 0xff, 0xfc, 0x10, 0xd, 0xda, + 0xfb, 0x29, 0xf6, 0xff, 0xc5, 0xa8, 0xf4, 0x14, 0x3f}; + uint8_t bytesprops2[] = {0x71, 0x73, 0x76, 0x40, 0xd0, 0x64, 0x19, 0xf1, 0x59, 0xef, 0x1c, + 0x3a, 0x5f, 0x31, 0x29, 0x6e, 0x38, 0xf, 0xe7, 0x91, 0xc3}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 15341}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 22577}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 170}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 18}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {28, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {19, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 1372}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 1820}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 31562}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {21, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 3761}}, + }; + + lwmqtt_properties_t props = {11, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops0[] = {0x40, 0x46, 0xf, 0xbd, 0x5e, 0xd3, 0xea, 0x73, 0x7c, 0x35, 0x92, + 0x28, 0xa8, 0xa4, 0xc0, 0x20, 0x99, 0xb4, 0x63, 0xdc, 0xfc}; + uint8_t byteswillprops1[] = {0x18, 0xfe, 0xa4, 0x22, 0xc, 0x49, 0x28, 0xe4, 0x63, 0x64, 0xe0, 0x79, + 0x3b, 0x4f, 0xe, 0x4b, 0x21, 0xa7, 0x29, 0x9a, 0xde, 0x4c, 0x64}; + uint8_t byteswillprops2[] = {0xa2, 0x36, 0xf4, 0x93, 0x60, 0xab, 0x93, 0xf, 0x15, 0x6f, + 0x2b, 0xb6, 0xe8, 0xfe, 0x8f, 0x41, 0xd5, 0x12, 0xa3, 0xbc}; + uint8_t byteswillprops3[] = {0x59, 0xd3, 0xfb, 0x27, 0xe2, 0x6e, 0xb, 0x53, 0x9e, 0xfd, + 0x68, 0x4c, 0x2d, 0x17, 0x18, 0x32, 0xee, 0xe, 0xe, 0x33, + 0xc9, 0x5f, 0x0, 0x90, 0x17, 0x8a, 0x7b, 0x95, 0x1b, 0xf5}; + uint8_t byteswillprops4[] = {0x44, 0x68, 0xa, 0x12, 0x57, 0xe8, 0x74, 0x9f, 0xa2, 0x6d, 0x48}; + uint8_t byteswillprops5[] = {0x30, 0x17, 0xef}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)22, .value = {.str = {21, (char*)&byteswillprops0}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 232}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {23, (char*)&byteswillprops1}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 21484}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 7099}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 206}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {20, (char*)&byteswillprops2}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {30, (char*)&byteswillprops3}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 32745}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {11, (char*)&byteswillprops4}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 15700}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {3, (char*)&byteswillprops5}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 30512}}, + }; + + lwmqtt_properties_t willprops = {13, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x14, 0x2, 0xed, 0x2b, 0xa9, 0x50, 0x4d, 0x35, 0x2d, 0x89, 0x32, 0x8f, 0x11, + 0x49, 0x8f, 0x17, 0x38, 0x52, 0xcd, 0x22, 0x2b, 0xcf, 0x27, 0xe5, 0xf4}; + lwmqtt_string_t will_topic = {25, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x2a, 0xec, 0xc1, 0x1c, 0xe7, 0x91, 0x53, 0xe0, 0x23, 0xad, 0x22, 0xe0, 0xdf, + 0xe3, 0x8e, 0xf2, 0x2a, 0x69, 0x83, 0x38, 0xcb, 0x9c, 0x78, 0xa1, 0xe7, 0x5a}; + lwmqtt_string_t will_payload = {26, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 25243; + uint8_t client_id_bytes[] = {0xb7, 0x8d, 0xbb, 0xd3, 0xe3, 0x46, 0x21, 0xba, 0xe9, 0x2b, 0x73, 0x39, 0x63, 0x5e, + 0x37, 0x9a, 0x8, 0xc1, 0x59, 0x94, 0xae, 0x77, 0xd8, 0x3d, 0xea, 0x4b, 0x31}; + lwmqtt_string_t client_id = {27, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xd4, 0xf6, 0xb, 0xd0, 0x51}; + lwmqtt_string_t username = {5, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\202\139\128\189r\251\250\210\176K\157gL\180\ESC\252\232\242\141\NULV\217", +// _password = Nothing, _lastWill = Just (LastWill {_willRetain = False, _willQoS = QoS0, _willTopic = +// "\204\246\221\166\146\242\STXG5", _willMsg = "P\228\ETX:\163\230z\150\184Jo\FS=\189\NUL\196", _willProps = +// [PropRequestResponseInformation 204,PropAssignedClientIdentifier "\143\190\156\184&1\203",PropSubscriptionIdentifier +// 14,PropServerReference "\248\USt)x)\DC3\133",PropAuthenticationMethod "m",PropUserProperty "\231\217\172P'\DC1 +// Ji\236\r\180" "\188\135\199\200\&4\207/\175\199\135\181\131\223\GS",PropTopicAlias +// 17325,PropWildcardSubscriptionAvailable 9,PropReceiveMaximum 21760,PropRetainAvailable 175,PropSessionExpiryInterval +// 1287,PropTopicAliasMaximum 5940]}), _cleanSession = True, _keepAlive = 11253, _connID = +// "\239\DEL\DC2\154\161@0\234\178\ad", _properties = [PropResponseTopic "\207 +// l=\\\131i\228\238\216\171\&6m\170\211\182\194\144K\163\196\146Zx\179",PropSubscriptionIdentifier 18,PropUserProperty +// "p%\151\EOT\148\156\254\188\v\RS\199\221\DC4\254D\241\170\214\GS\DC4\RS\r\219\232\183" +// "\223\&4\204\252E\188h\169\218r u\NUL\193~\202\150\ETBBb\186\EOT",PropReceiveMaximum +// 9565,PropSharedSubscriptionAvailable 235,PropAssignedClientIdentifier "\DC2\DC1",PropResponseInformation +// "\DEL\DC4",PropWildcardSubscriptionAvailable 103,PropResponseInformation +// "\\z\137\152\RS\170\233\ETBW,+\154\&3G\208p\189\184\SO\160\ESC\NAK\149\244`\178\197",PropWillDelayInterval +// 2563,PropCorrelationData +// "\ACK\247\tp\US\160|\179}[\SIz\233\175\163V\165\215\EOT\165\231\253\FSA\222>'B9",PropMaximumPacketSize +// 32081,PropSubscriptionIdentifier 1,PropRequestProblemInformation 102,PropAuthenticationMethod +// "\197\235",PropWillDelayInterval 6511,PropResponseTopic "!M\128,\150\163!\143\224\242\EOT\134L",PropReasonString +// "/A\156\166\185\EOTJ\160\237\181>.V\201\224@\242\138(\242\189\f\194",PropAuthenticationData +// "\242\SUB\t\202\181.\DC4\r\215\166\176\214;\\\180\223",PropResponseTopic +// "\158\254\&6D?",PropPayloadFormatIndicator +// 117,PropMaximumQoS 158,PropRetainAvailable 153,PropRetainAvailable 39,PropWildcardSubscriptionAvailable +// 160,PropPayloadFormatIndicator 190,PropMaximumPacketSize 10707,PropCorrelationData +// "\r\212\202\215$\aP\254vA\199\SO",PropAuthenticationData "d+\138\v\214{\130\177|\158\170G\158\190\NUL\156\166"]}), +// _cleanSession = False, _keepAlive = 28636, _connID = "\GS \174N\196\134\134\164\ACK;!#]\239\168\159\231\208f", +// _properties = [PropRetainAvailable 43,PropMessageExpiryInterval 15199,PropServerKeepAlive 3140,PropMaximumQoS +// 195,PropWildcardSubscriptionAvailable 46,PropWillDelayInterval 26473,PropWildcardSubscriptionAvailable +// 10,PropMaximumPacketSize 27203]} +TEST(Connect5QCTest, Encode13) { + uint8_t pkt[] = { + 0x10, 0xab, 0x2, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0xc, 0x6f, 0xdc, 0x1a, 0x25, 0x2b, 0x2, 0x0, 0x0, + 0x3b, 0x5f, 0x13, 0xc, 0x44, 0x24, 0xc3, 0x28, 0x2e, 0x18, 0x0, 0x0, 0x67, 0x69, 0x28, 0xa, 0x27, 0x0, 0x0, + 0x6a, 0x43, 0x0, 0x13, 0x1d, 0x20, 0xae, 0x4e, 0xc4, 0x86, 0x86, 0xa4, 0x6, 0x3b, 0x21, 0x23, 0x5d, 0xef, 0xa8, + 0x9f, 0xe7, 0xd0, 0x66, 0xcc, 0x1, 0x1c, 0x0, 0x11, 0xe9, 0xb7, 0x5a, 0x7, 0xf6, 0xe5, 0x0, 0x8b, 0x18, 0xd, + 0x11, 0x3c, 0xf4, 0xd0, 0x92, 0xcd, 0x69, 0x16, 0x0, 0x10, 0xf2, 0xc3, 0x34, 0x5f, 0xe5, 0x7, 0xf9, 0xbe, 0xb4, + 0xce, 0x7, 0xf2, 0xc3, 0xd9, 0xcf, 0xc0, 0x13, 0x49, 0xf8, 0x19, 0x40, 0x2a, 0x37, 0x16, 0x0, 0xc, 0x5d, 0xb6, + 0xd9, 0xb2, 0x56, 0x72, 0x3c, 0xd0, 0x6, 0xd8, 0xb8, 0x3d, 0x26, 0x0, 0x11, 0xbd, 0x68, 0x80, 0xdc, 0x99, 0x58, + 0x5f, 0xd5, 0x5, 0x8e, 0x93, 0x6d, 0x7d, 0x9a, 0xf1, 0xa8, 0x34, 0x0, 0x7, 0xf3, 0x98, 0xa6, 0x53, 0xbd, 0x33, + 0x11, 0x1f, 0x0, 0xf, 0xd7, 0xe6, 0x64, 0x18, 0x16, 0xec, 0x50, 0xad, 0x2, 0x76, 0x1, 0x80, 0x36, 0x85, 0xcd, + 0x21, 0xc, 0xee, 0x11, 0x0, 0x0, 0x74, 0xc2, 0x23, 0x52, 0xc2, 0x16, 0x0, 0x1e, 0xa5, 0x23, 0x76, 0x41, 0x42, + 0x9c, 0xb, 0x53, 0x1b, 0x9d, 0x8, 0x3, 0x53, 0xe9, 0x9e, 0x30, 0x2a, 0xfe, 0x76, 0xe1, 0x68, 0x36, 0xf0, 0xe7, + 0x3e, 0x9e, 0xfe, 0x36, 0x44, 0x3f, 0x1, 0x75, 0x24, 0x9e, 0x25, 0x99, 0x25, 0x27, 0x28, 0xa0, 0x1, 0xbe, 0x27, + 0x0, 0x0, 0x29, 0xd3, 0x9, 0x0, 0xc, 0xd, 0xd4, 0xca, 0xd7, 0x24, 0x7, 0x50, 0xfe, 0x76, 0x41, 0xc7, 0xe, + 0x16, 0x0, 0x11, 0x64, 0x2b, 0x8a, 0xb, 0xd6, 0x7b, 0x82, 0xb1, 0x7c, 0x9e, 0xaa, 0x47, 0x9e, 0xbe, 0x0, 0x9c, + 0xa6, 0x0, 0xd, 0x12, 0x4, 0xf6, 0x90, 0x32, 0x63, 0x9c, 0x41, 0x47, 0x4e, 0x7, 0xf9, 0x7e, 0x0, 0x12, 0xef, + 0x7e, 0xdd, 0xa7, 0xd7, 0xcc, 0x51, 0xc, 0x5c, 0xba, 0x51, 0xc6, 0x3c, 0x14, 0xdc, 0x7e, 0xd9, 0x25}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 43}}, {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 15199}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 3140}}, {.prop = (lwmqtt_prop_t)36, .value = {.byte = 195}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 46}}, {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 26473}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 10}}, {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 27203}}, + }; + + lwmqtt_properties_t props = {8, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops0[] = {0xe9, 0xb7, 0x5a, 0x7, 0xf6, 0xe5, 0x0, 0x8b, 0x18, + 0xd, 0x11, 0x3c, 0xf4, 0xd0, 0x92, 0xcd, 0x69}; + uint8_t byteswillprops1[] = {0xf2, 0xc3, 0x34, 0x5f, 0xe5, 0x7, 0xf9, 0xbe, + 0xb4, 0xce, 0x7, 0xf2, 0xc3, 0xd9, 0xcf, 0xc0}; + uint8_t byteswillprops2[] = {0x5d, 0xb6, 0xd9, 0xb2, 0x56, 0x72, 0x3c, 0xd0, 0x6, 0xd8, 0xb8, 0x3d}; + uint8_t byteswillprops4[] = {0xf3, 0x98, 0xa6, 0x53, 0xbd, 0x33, 0x11}; + uint8_t byteswillprops3[] = {0xbd, 0x68, 0x80, 0xdc, 0x99, 0x58, 0x5f, 0xd5, 0x5, + 0x8e, 0x93, 0x6d, 0x7d, 0x9a, 0xf1, 0xa8, 0x34}; + uint8_t byteswillprops5[] = {0xd7, 0xe6, 0x64, 0x18, 0x16, 0xec, 0x50, 0xad, 0x2, 0x76, 0x1, 0x80, 0x36, 0x85, 0xcd}; + uint8_t byteswillprops6[] = {0xa5, 0x23, 0x76, 0x41, 0x42, 0x9c, 0xb, 0x53, 0x1b, 0x9d, + 0x8, 0x3, 0x53, 0xe9, 0x9e, 0x30, 0x2a, 0xfe, 0x76, 0xe1, + 0x68, 0x36, 0xf0, 0xe7, 0x3e, 0x9e, 0xfe, 0x36, 0x44, 0x3f}; + uint8_t byteswillprops7[] = {0xd, 0xd4, 0xca, 0xd7, 0x24, 0x7, 0x50, 0xfe, 0x76, 0x41, 0xc7, 0xe}; + uint8_t byteswillprops8[] = {0x64, 0x2b, 0x8a, 0xb, 0xd6, 0x7b, 0x82, 0xb1, 0x7c, + 0x9e, 0xaa, 0x47, 0x9e, 0xbe, 0x0, 0x9c, 0xa6}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)28, .value = {.str = {17, (char*)&byteswillprops0}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {16, (char*)&byteswillprops1}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 18936}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 64}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 55}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {12, (char*)&byteswillprops2}}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {17, (char*)&byteswillprops3}, .v = {7, (char*)&byteswillprops4}}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {15, (char*)&byteswillprops5}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 3310}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 29890}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 21186}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {30, (char*)&byteswillprops6}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 117}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 158}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 153}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 39}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 160}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 190}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 10707}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {12, (char*)&byteswillprops7}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {17, (char*)&byteswillprops8}}}, + }; + + lwmqtt_properties_t willprops = {21, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x12, 0x4, 0xf6, 0x90, 0x32, 0x63, 0x9c, 0x41, 0x47, 0x4e, 0x7, 0xf9, 0x7e}; + lwmqtt_string_t will_topic = {13, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0xef, 0x7e, 0xdd, 0xa7, 0xd7, 0xcc, 0x51, 0xc, 0x5c, + 0xba, 0x51, 0xc6, 0x3c, 0x14, 0xdc, 0x7e, 0xd9, 0x25}; + lwmqtt_string_t will_payload = {18, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 28636; + uint8_t client_id_bytes[] = {0x1d, 0x20, 0xae, 0x4e, 0xc4, 0x86, 0x86, 0xa4, 0x6, 0x3b, + 0x21, 0x23, 0x5d, 0xef, 0xa8, 0x9f, 0xe7, 0xd0, 0x66}; + lwmqtt_string_t client_id = {19, (char*)&client_id_bytes}; + opts.client_id = client_id; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\242\255\248\RSlqy\210\165\223EJs\218\138\195\252~OS0\155s\176", _password = Just +// "+\217", _lastWill = Just (LastWill {_willRetain = False, _willQoS = QoS1, _willTopic = +// "\251\&3\249*?0\b\223!*\150M", _willMsg = "bZ\SO", _willProps = [PropCorrelationData "",PropContentType +// "_\a\DC1\220",PropContentType +// "\213\195\133\ESC#\222\159\168\185,\232\DEL%\168\ESC\200\bx_\134\162\142D\248E\140Il\DC1",PropSessionExpiryInterval +// 5768,PropMessageExpiryInterval 13956,PropMessageExpiryInterval 14376,PropSessionExpiryInterval +// 12032,PropReceiveMaximum 23268,PropResponseTopic "",PropPayloadFormatIndicator 223,PropWillDelayInterval +// 25802,PropResponseTopic "",PropTopicAliasMaximum 24689,PropServerReference +// "\182\223(@\170E\190\164\241o\231V\142\t\EM\195\130\189\161\180\245\213\158.",PropSubscriptionIdentifierAvailable +// 122,PropRequestResponseInformation 35,PropReasonString +// "\156\SO/\231\187\207d,q\ESC\194\254c\DC1\128H\149bo\237$\145\USZ\226\200N",PropAuthenticationData +// "R9\140\235\217L\211\239"]}), _cleanSession = False, _keepAlive = 5719, _connID = +// "\222\165\251RK\130'\234\242.*\EOT\200~\"\NULJ", _properties = [PropWildcardSubscriptionAvailable +// 209,PropUserProperty "\STX^\128\CAN\170hj&x<\184\163\245\183\128\147p\174\152~" +// "\240\251\144\209\203\225\n`P\180;\246\192\168",PropContentType +// "\a\207\189\216\190\ETBX\229>\240+\225\246\180Q*{\194\151",PropMessageExpiryInterval +// 24515,PropRequestProblemInformation 168,PropReceiveMaximum 7245,PropCorrelationData +// "\196\\$\209v\EOT\141\157\205\165\198ksR\250\n\224\205\143\213\"\169N\170\STX\245\193q\r?",PropWildcardSubscriptionAvailable +// 188,PropMaximumPacketSize 20784,PropWildcardSubscriptionAvailable 69,PropServerReference +// "\192\240X\221\197\150\143\140\240d#\234C\200J\236\EOT\197\224\NAK\147\244\&4\154\192",PropCorrelationData "_w"]} +TEST(Connect5QCTest, Encode14) { + uint8_t pkt[] = { + 0x10, 0xff, 0x2, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0xcc, 0x16, 0x57, 0x94, 0x1, 0x28, 0xd1, 0x26, 0x0, + 0x14, 0x2, 0x5e, 0x80, 0x18, 0xaa, 0x68, 0x6a, 0x26, 0x78, 0x3c, 0xb8, 0xa3, 0xf5, 0xb7, 0x80, 0x93, 0x70, 0xae, + 0x98, 0x7e, 0x0, 0xe, 0xf0, 0xfb, 0x90, 0xd1, 0xcb, 0xe1, 0xa, 0x60, 0x50, 0xb4, 0x3b, 0xf6, 0xc0, 0xa8, 0x3, + 0x0, 0x13, 0x7, 0xcf, 0xbd, 0xd8, 0xbe, 0x17, 0x58, 0xe5, 0x3e, 0xf0, 0x2b, 0xe1, 0xf6, 0xb4, 0x51, 0x2a, 0x7b, + 0xc2, 0x97, 0x2, 0x0, 0x0, 0x5f, 0xc3, 0x17, 0xa8, 0x21, 0x1c, 0x4d, 0x9, 0x0, 0x1e, 0xc4, 0x5c, 0x24, 0xd1, + 0x76, 0x4, 0x8d, 0x9d, 0xcd, 0xa5, 0xc6, 0x6b, 0x73, 0x52, 0xfa, 0xa, 0xe0, 0xcd, 0x8f, 0xd5, 0x22, 0xa9, 0x4e, + 0xaa, 0x2, 0xf5, 0xc1, 0x71, 0xd, 0x3f, 0x28, 0xbc, 0x27, 0x0, 0x0, 0x51, 0x30, 0x28, 0x45, 0x1c, 0x0, 0x19, + 0xc0, 0xf0, 0x58, 0xdd, 0xc5, 0x96, 0x8f, 0x8c, 0xf0, 0x64, 0x23, 0xea, 0x43, 0xc8, 0x4a, 0xec, 0x4, 0xc5, 0xe0, + 0x15, 0x93, 0xf4, 0x34, 0x9a, 0xc0, 0x9, 0x0, 0x2, 0x5f, 0x77, 0x0, 0x11, 0xde, 0xa5, 0xfb, 0x52, 0x4b, 0x82, + 0x27, 0xea, 0xf2, 0x2e, 0x2a, 0x4, 0xc8, 0x7e, 0x22, 0x0, 0x4a, 0x99, 0x1, 0x9, 0x0, 0x0, 0x3, 0x0, 0x4, + 0x5f, 0x7, 0x11, 0xdc, 0x3, 0x0, 0x1d, 0xd5, 0xc3, 0x85, 0x1b, 0x23, 0xde, 0x9f, 0xa8, 0xb9, 0x2c, 0xe8, 0x7f, + 0x25, 0xa8, 0x1b, 0xc8, 0x8, 0x78, 0x5f, 0x86, 0xa2, 0x8e, 0x44, 0xf8, 0x45, 0x8c, 0x49, 0x6c, 0x11, 0x11, 0x0, + 0x0, 0x16, 0x88, 0x2, 0x0, 0x0, 0x36, 0x84, 0x2, 0x0, 0x0, 0x38, 0x28, 0x11, 0x0, 0x0, 0x2f, 0x0, 0x21, + 0x5a, 0xe4, 0x8, 0x0, 0x0, 0x1, 0xdf, 0x18, 0x0, 0x0, 0x64, 0xca, 0x8, 0x0, 0x0, 0x22, 0x60, 0x71, 0x1c, + 0x0, 0x18, 0xb6, 0xdf, 0x28, 0x40, 0xaa, 0x45, 0xbe, 0xa4, 0xf1, 0x6f, 0xe7, 0x56, 0x8e, 0x9, 0x19, 0xc3, 0x82, + 0xbd, 0xa1, 0xb4, 0xf5, 0xd5, 0x9e, 0x2e, 0x29, 0x7a, 0x19, 0x23, 0x1f, 0x0, 0x1b, 0x9c, 0xe, 0x2f, 0xe7, 0xbb, + 0xcf, 0x64, 0x2c, 0x71, 0x1b, 0xc2, 0xfe, 0x63, 0x11, 0x80, 0x48, 0x95, 0x62, 0x6f, 0xed, 0x24, 0x91, 0x1f, 0x5a, + 0xe2, 0xc8, 0x4e, 0x16, 0x0, 0x8, 0x52, 0x39, 0x8c, 0xeb, 0xd9, 0x4c, 0xd3, 0xef, 0x0, 0xc, 0xfb, 0x33, 0xf9, + 0x2a, 0x3f, 0x30, 0x8, 0xdf, 0x21, 0x2a, 0x96, 0x4d, 0x0, 0x3, 0x62, 0x5a, 0xe, 0x0, 0x18, 0xf2, 0xff, 0xf8, + 0x1e, 0x6c, 0x71, 0x79, 0xd2, 0xa5, 0xdf, 0x45, 0x4a, 0x73, 0xda, 0x8a, 0xc3, 0xfc, 0x7e, 0x4f, 0x53, 0x30, 0x9b, + 0x73, 0xb0, 0x0, 0x2, 0x2b, 0xd9}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops1[] = {0xf0, 0xfb, 0x90, 0xd1, 0xcb, 0xe1, 0xa, 0x60, 0x50, 0xb4, 0x3b, 0xf6, 0xc0, 0xa8}; + uint8_t bytesprops0[] = {0x2, 0x5e, 0x80, 0x18, 0xaa, 0x68, 0x6a, 0x26, 0x78, 0x3c, + 0xb8, 0xa3, 0xf5, 0xb7, 0x80, 0x93, 0x70, 0xae, 0x98, 0x7e}; + uint8_t bytesprops2[] = {0x7, 0xcf, 0xbd, 0xd8, 0xbe, 0x17, 0x58, 0xe5, 0x3e, 0xf0, + 0x2b, 0xe1, 0xf6, 0xb4, 0x51, 0x2a, 0x7b, 0xc2, 0x97}; + uint8_t bytesprops3[] = {0xc4, 0x5c, 0x24, 0xd1, 0x76, 0x4, 0x8d, 0x9d, 0xcd, 0xa5, 0xc6, 0x6b, 0x73, 0x52, 0xfa, + 0xa, 0xe0, 0xcd, 0x8f, 0xd5, 0x22, 0xa9, 0x4e, 0xaa, 0x2, 0xf5, 0xc1, 0x71, 0xd, 0x3f}; + uint8_t bytesprops4[] = {0xc0, 0xf0, 0x58, 0xdd, 0xc5, 0x96, 0x8f, 0x8c, 0xf0, 0x64, 0x23, 0xea, 0x43, + 0xc8, 0x4a, 0xec, 0x4, 0xc5, 0xe0, 0x15, 0x93, 0xf4, 0x34, 0x9a, 0xc0}; + uint8_t bytesprops5[] = {0x5f, 0x77}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 209}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {20, (char*)&bytesprops0}, .v = {14, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {19, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 24515}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 168}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 7245}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {30, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 188}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 20784}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 69}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {25, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {2, (char*)&bytesprops5}}}, + }; + + lwmqtt_properties_t props = {12, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops0[] = {0}; + uint8_t byteswillprops1[] = {0x5f, 0x7, 0x11, 0xdc}; + uint8_t byteswillprops2[] = {0xd5, 0xc3, 0x85, 0x1b, 0x23, 0xde, 0x9f, 0xa8, 0xb9, 0x2c, 0xe8, 0x7f, 0x25, 0xa8, 0x1b, + 0xc8, 0x8, 0x78, 0x5f, 0x86, 0xa2, 0x8e, 0x44, 0xf8, 0x45, 0x8c, 0x49, 0x6c, 0x11}; + uint8_t byteswillprops3[] = {0}; + uint8_t byteswillprops4[] = {0}; + uint8_t byteswillprops5[] = {0xb6, 0xdf, 0x28, 0x40, 0xaa, 0x45, 0xbe, 0xa4, 0xf1, 0x6f, 0xe7, 0x56, + 0x8e, 0x9, 0x19, 0xc3, 0x82, 0xbd, 0xa1, 0xb4, 0xf5, 0xd5, 0x9e, 0x2e}; + uint8_t byteswillprops6[] = {0x9c, 0xe, 0x2f, 0xe7, 0xbb, 0xcf, 0x64, 0x2c, 0x71, 0x1b, 0xc2, 0xfe, 0x63, 0x11, + 0x80, 0x48, 0x95, 0x62, 0x6f, 0xed, 0x24, 0x91, 0x1f, 0x5a, 0xe2, 0xc8, 0x4e}; + uint8_t byteswillprops7[] = {0x52, 0x39, 0x8c, 0xeb, 0xd9, 0x4c, 0xd3, 0xef}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)9, .value = {.str = {0, (char*)&byteswillprops0}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {4, (char*)&byteswillprops1}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {29, (char*)&byteswillprops2}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 5768}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 13956}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 14376}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 12032}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 23268}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {0, (char*)&byteswillprops3}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 223}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 25802}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {0, (char*)&byteswillprops4}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 24689}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {24, (char*)&byteswillprops5}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 122}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 35}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {27, (char*)&byteswillprops6}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {8, (char*)&byteswillprops7}}}, + }; + + lwmqtt_properties_t willprops = {18, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0xfb, 0x33, 0xf9, 0x2a, 0x3f, 0x30, 0x8, 0xdf, 0x21, 0x2a, 0x96, 0x4d}; + lwmqtt_string_t will_topic = {12, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x62, 0x5a, 0xe}; + lwmqtt_string_t will_payload = {3, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 5719; + uint8_t client_id_bytes[] = {0xde, 0xa5, 0xfb, 0x52, 0x4b, 0x82, 0x27, 0xea, 0xf2, + 0x2e, 0x2a, 0x4, 0xc8, 0x7e, 0x22, 0x0, 0x4a}; + lwmqtt_string_t client_id = {17, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xf2, 0xff, 0xf8, 0x1e, 0x6c, 0x71, 0x79, 0xd2, 0xa5, 0xdf, 0x45, 0x4a, + 0x73, 0xda, 0x8a, 0xc3, 0xfc, 0x7e, 0x4f, 0x53, 0x30, 0x9b, 0x73, 0xb0}; + lwmqtt_string_t username = {24, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x2b, 0xd9}; + lwmqtt_string_t password = {2, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\172\146\231\253\222^\247\183l\232!\133;\b\FS\253\ETX\f~[\211\SYN(P", _password = +// Nothing, _lastWill = Just (LastWill {_willRetain = True, _willQoS = QoS0, _willTopic = +// "[\SO\138\&5\217\\\253\149\212\249s\139\SOH\ENQ\DLEw", _willMsg = +// "\a\252\183\167\137\DC4\248\STX^\DLE\249\242\194\ESC\135\165\&5L\205dn\DC2", _willProps = +// [PropSubscriptionIdentifierAvailable 74,PropWillDelayInterval 14383,PropContentType +// "\167\DC2\162\203/\236\172\248\185\215\&5\EM\208\234N53\DC2-",PropWildcardSubscriptionAvailable +// 138,PropAuthenticationData "\172Z",PropMessageExpiryInterval 17095,PropRequestProblemInformation +// 249,PropResponseInformation "\132&\b\181;\SYN\129\ENQPy\171\222\247b\175\192",PropTopicAliasMaximum +// 18402,PropTopicAlias 12058,PropReasonString "",PropServerReference +// "\144\139E\240\202\201\195\187\221\227\138C\v\196\196\220\134g\201\173i",PropWillDelayInterval +// 9923,PropRetainAvailable 190,PropSubscriptionIdentifierAvailable 210,PropSubscriptionIdentifier 8,PropReasonString +// "\206\145o\212\220\209\216f,o\219\175\189t\238\SO\190\168\253\231\&8\203\170\144",PropUserProperty +// "\EM\173\172\132\222\132o\211\154\a\138$\249\145\SO\226\208\t\220\251" +// "Z\185kd6\189&\210y/@\203\DEL?\182\155\&3\SO\SUB\SUB\192\233g\200\SI3\204\DC2",PropResponseTopic +// "\212\RS@\184\221\240\146\237",PropAuthenticationMethod +// "c\186\133#\148j\tL\149Q\RS\248&\247\f\169\204\DC1\179\173a\243B\234P",PropMessageExpiryInterval 24918]}), +// _cleanSession = False, _keepAlive = 27552, _connID = "e\185\229", _properties = [PropAssignedClientIdentifier +// "FB\131\240y\n\GS\229\235\253\&2",PropMessageExpiryInterval 16517,PropSessionExpiryInterval 5054,PropRetainAvailable +// 156,PropSubscriptionIdentifier 15,PropAuthenticationData "\158o\196Ua",PropMaximumPacketSize +// 25051,PropWillDelayInterval 6996,PropAuthenticationData +// "[\136\GS\DC1\CAN\222^dH/\EM\216\253",PropRequestProblemInformation 237,PropReasonString +// "\175\197X\162\SYN-\234\250X\206\190Z\158\225F\US\172\221A\254\177\&1\159}D\168\213",PropContentType +// ",",PropResponseInformation "\254\163",PropReasonString "\167",PropCorrelationData "4k",PropMaximumPacketSize +// 14000,PropRequestProblemInformation 31,PropSubscriptionIdentifier 17,PropSessionExpiryInterval 1316,PropMaximumQoS +// 15,PropUserProperty "i)\ACK\133\158K\164\236d\213\&1+bmJY\DC1" +// "\EMt[\215rJg\183\SOH\196-\SUBv\154\226\&6{|\247\226",PropTopicAlias 32594,PropSubscriptionIdentifier +// 22,PropTopicAlias 19062,PropMessageExpiryInterval 22830,PropRequestProblemInformation +// 240,PropWildcardSubscriptionAvailable 112,PropCorrelationData ";\v\162R"]} +TEST(Connect5QCTest, Encode15) { + uint8_t pkt[] = { + 0x10, 0xff, 0x3, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0xa4, 0x6b, 0xa0, 0xc2, 0x1, 0x12, 0x0, 0xb, 0x46, + 0x42, 0x83, 0xf0, 0x79, 0xa, 0x1d, 0xe5, 0xeb, 0xfd, 0x32, 0x2, 0x0, 0x0, 0x40, 0x85, 0x11, 0x0, 0x0, 0x13, + 0xbe, 0x25, 0x9c, 0xb, 0xf, 0x16, 0x0, 0x5, 0x9e, 0x6f, 0xc4, 0x55, 0x61, 0x27, 0x0, 0x0, 0x61, 0xdb, 0x18, + 0x0, 0x0, 0x1b, 0x54, 0x16, 0x0, 0xd, 0x5b, 0x88, 0x1d, 0x11, 0x18, 0xde, 0x5e, 0x64, 0x48, 0x2f, 0x19, 0xd8, + 0xfd, 0x17, 0xed, 0x1f, 0x0, 0x1b, 0xaf, 0xc5, 0x58, 0xa2, 0x16, 0x2d, 0xea, 0xfa, 0x58, 0xce, 0xbe, 0x5a, 0x9e, + 0xe1, 0x46, 0x1f, 0xac, 0xdd, 0x41, 0xfe, 0xb1, 0x31, 0x9f, 0x7d, 0x44, 0xa8, 0xd5, 0x3, 0x0, 0x1, 0x2c, 0x1a, + 0x0, 0x2, 0xfe, 0xa3, 0x1f, 0x0, 0x1, 0xa7, 0x9, 0x0, 0x2, 0x34, 0x6b, 0x27, 0x0, 0x0, 0x36, 0xb0, 0x17, + 0x1f, 0xb, 0x11, 0x11, 0x0, 0x0, 0x5, 0x24, 0x24, 0xf, 0x26, 0x0, 0x11, 0x69, 0x29, 0x6, 0x85, 0x9e, 0x4b, + 0xa4, 0xec, 0x64, 0xd5, 0x31, 0x2b, 0x62, 0x6d, 0x4a, 0x59, 0x11, 0x0, 0x14, 0x19, 0x74, 0x5b, 0xd7, 0x72, 0x4a, + 0x67, 0xb7, 0x1, 0xc4, 0x2d, 0x1a, 0x76, 0x9a, 0xe2, 0x36, 0x7b, 0x7c, 0xf7, 0xe2, 0x23, 0x7f, 0x52, 0xb, 0x16, + 0x23, 0x4a, 0x76, 0x2, 0x0, 0x0, 0x59, 0x2e, 0x17, 0xf0, 0x28, 0x70, 0x9, 0x0, 0x4, 0x3b, 0xb, 0xa2, 0x52, + 0x0, 0x3, 0x65, 0xb9, 0xe5, 0xe6, 0x1, 0x29, 0x4a, 0x18, 0x0, 0x0, 0x38, 0x2f, 0x3, 0x0, 0x13, 0xa7, 0x12, + 0xa2, 0xcb, 0x2f, 0xec, 0xac, 0xf8, 0xb9, 0xd7, 0x35, 0x19, 0xd0, 0xea, 0x4e, 0x35, 0x33, 0x12, 0x2d, 0x28, 0x8a, + 0x16, 0x0, 0x2, 0xac, 0x5a, 0x2, 0x0, 0x0, 0x42, 0xc7, 0x17, 0xf9, 0x1a, 0x0, 0x10, 0x84, 0x26, 0x8, 0xb5, + 0x3b, 0x16, 0x81, 0x5, 0x50, 0x79, 0xab, 0xde, 0xf7, 0x62, 0xaf, 0xc0, 0x22, 0x47, 0xe2, 0x23, 0x2f, 0x1a, 0x1f, + 0x0, 0x0, 0x1c, 0x0, 0x15, 0x90, 0x8b, 0x45, 0xf0, 0xca, 0xc9, 0xc3, 0xbb, 0xdd, 0xe3, 0x8a, 0x43, 0xb, 0xc4, + 0xc4, 0xdc, 0x86, 0x67, 0xc9, 0xad, 0x69, 0x18, 0x0, 0x0, 0x26, 0xc3, 0x25, 0xbe, 0x29, 0xd2, 0xb, 0x8, 0x1f, + 0x0, 0x18, 0xce, 0x91, 0x6f, 0xd4, 0xdc, 0xd1, 0xd8, 0x66, 0x2c, 0x6f, 0xdb, 0xaf, 0xbd, 0x74, 0xee, 0xe, 0xbe, + 0xa8, 0xfd, 0xe7, 0x38, 0xcb, 0xaa, 0x90, 0x26, 0x0, 0x14, 0x19, 0xad, 0xac, 0x84, 0xde, 0x84, 0x6f, 0xd3, 0x9a, + 0x7, 0x8a, 0x24, 0xf9, 0x91, 0xe, 0xe2, 0xd0, 0x9, 0xdc, 0xfb, 0x0, 0x1c, 0x5a, 0xb9, 0x6b, 0x64, 0x36, 0xbd, + 0x26, 0xd2, 0x79, 0x2f, 0x40, 0xcb, 0x7f, 0x3f, 0xb6, 0x9b, 0x33, 0xe, 0x1a, 0x1a, 0xc0, 0xe9, 0x67, 0xc8, 0xf, + 0x33, 0xcc, 0x12, 0x8, 0x0, 0x8, 0xd4, 0x1e, 0x40, 0xb8, 0xdd, 0xf0, 0x92, 0xed, 0x15, 0x0, 0x19, 0x63, 0xba, + 0x85, 0x23, 0x94, 0x6a, 0x9, 0x4c, 0x95, 0x51, 0x1e, 0xf8, 0x26, 0xf7, 0xc, 0xa9, 0xcc, 0x11, 0xb3, 0xad, 0x61, + 0xf3, 0x42, 0xea, 0x50, 0x2, 0x0, 0x0, 0x61, 0x56, 0x0, 0x10, 0x5b, 0xe, 0x8a, 0x35, 0xd9, 0x5c, 0xfd, 0x95, + 0xd4, 0xf9, 0x73, 0x8b, 0x1, 0x5, 0x10, 0x77, 0x0, 0x16, 0x7, 0xfc, 0xb7, 0xa7, 0x89, 0x14, 0xf8, 0x2, 0x5e, + 0x10, 0xf9, 0xf2, 0xc2, 0x1b, 0x87, 0xa5, 0x35, 0x4c, 0xcd, 0x64, 0x6e, 0x12, 0x0, 0x18, 0xac, 0x92, 0xe7, 0xfd, + 0xde, 0x5e, 0xf7, 0xb7, 0x6c, 0xe8, 0x21, 0x85, 0x3b, 0x8, 0x1c, 0xfd, 0x3, 0xc, 0x7e, 0x5b, 0xd3, 0x16, 0x28, + 0x50}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x46, 0x42, 0x83, 0xf0, 0x79, 0xa, 0x1d, 0xe5, 0xeb, 0xfd, 0x32}; + uint8_t bytesprops1[] = {0x9e, 0x6f, 0xc4, 0x55, 0x61}; + uint8_t bytesprops2[] = {0x5b, 0x88, 0x1d, 0x11, 0x18, 0xde, 0x5e, 0x64, 0x48, 0x2f, 0x19, 0xd8, 0xfd}; + uint8_t bytesprops3[] = {0xaf, 0xc5, 0x58, 0xa2, 0x16, 0x2d, 0xea, 0xfa, 0x58, 0xce, 0xbe, 0x5a, 0x9e, 0xe1, + 0x46, 0x1f, 0xac, 0xdd, 0x41, 0xfe, 0xb1, 0x31, 0x9f, 0x7d, 0x44, 0xa8, 0xd5}; + uint8_t bytesprops4[] = {0x2c}; + uint8_t bytesprops5[] = {0xfe, 0xa3}; + uint8_t bytesprops6[] = {0xa7}; + uint8_t bytesprops7[] = {0x34, 0x6b}; + uint8_t bytesprops9[] = {0x19, 0x74, 0x5b, 0xd7, 0x72, 0x4a, 0x67, 0xb7, 0x1, 0xc4, + 0x2d, 0x1a, 0x76, 0x9a, 0xe2, 0x36, 0x7b, 0x7c, 0xf7, 0xe2}; + uint8_t bytesprops8[] = {0x69, 0x29, 0x6, 0x85, 0x9e, 0x4b, 0xa4, 0xec, 0x64, + 0xd5, 0x31, 0x2b, 0x62, 0x6d, 0x4a, 0x59, 0x11}; + uint8_t bytesprops10[] = {0x3b, 0xb, 0xa2, 0x52}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)18, .value = {.str = {11, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 16517}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 5054}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 156}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 15}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {5, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 25051}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 6996}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {13, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 237}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {27, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {1, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {2, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {1, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {2, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 14000}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 31}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 17}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 1316}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 15}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {17, (char*)&bytesprops8}, .v = {20, (char*)&bytesprops9}}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 32594}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 22}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 19062}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 22830}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 240}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 112}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {4, (char*)&bytesprops10}}}, + }; + + lwmqtt_properties_t props = {28, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops0[] = {0xa7, 0x12, 0xa2, 0xcb, 0x2f, 0xec, 0xac, 0xf8, 0xb9, 0xd7, + 0x35, 0x19, 0xd0, 0xea, 0x4e, 0x35, 0x33, 0x12, 0x2d}; + uint8_t byteswillprops1[] = {0xac, 0x5a}; + uint8_t byteswillprops2[] = {0x84, 0x26, 0x8, 0xb5, 0x3b, 0x16, 0x81, 0x5, + 0x50, 0x79, 0xab, 0xde, 0xf7, 0x62, 0xaf, 0xc0}; + uint8_t byteswillprops3[] = {0}; + uint8_t byteswillprops4[] = {0x90, 0x8b, 0x45, 0xf0, 0xca, 0xc9, 0xc3, 0xbb, 0xdd, 0xe3, 0x8a, + 0x43, 0xb, 0xc4, 0xc4, 0xdc, 0x86, 0x67, 0xc9, 0xad, 0x69}; + uint8_t byteswillprops5[] = {0xce, 0x91, 0x6f, 0xd4, 0xdc, 0xd1, 0xd8, 0x66, 0x2c, 0x6f, 0xdb, 0xaf, + 0xbd, 0x74, 0xee, 0xe, 0xbe, 0xa8, 0xfd, 0xe7, 0x38, 0xcb, 0xaa, 0x90}; + uint8_t byteswillprops7[] = {0x5a, 0xb9, 0x6b, 0x64, 0x36, 0xbd, 0x26, 0xd2, 0x79, 0x2f, 0x40, 0xcb, 0x7f, 0x3f, + 0xb6, 0x9b, 0x33, 0xe, 0x1a, 0x1a, 0xc0, 0xe9, 0x67, 0xc8, 0xf, 0x33, 0xcc, 0x12}; + uint8_t byteswillprops6[] = {0x19, 0xad, 0xac, 0x84, 0xde, 0x84, 0x6f, 0xd3, 0x9a, 0x7, + 0x8a, 0x24, 0xf9, 0x91, 0xe, 0xe2, 0xd0, 0x9, 0xdc, 0xfb}; + uint8_t byteswillprops8[] = {0xd4, 0x1e, 0x40, 0xb8, 0xdd, 0xf0, 0x92, 0xed}; + uint8_t byteswillprops9[] = {0x63, 0xba, 0x85, 0x23, 0x94, 0x6a, 0x9, 0x4c, 0x95, 0x51, 0x1e, 0xf8, 0x26, + 0xf7, 0xc, 0xa9, 0xcc, 0x11, 0xb3, 0xad, 0x61, 0xf3, 0x42, 0xea, 0x50}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 74}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 14383}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {19, (char*)&byteswillprops0}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 138}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {2, (char*)&byteswillprops1}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 17095}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 249}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {16, (char*)&byteswillprops2}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 18402}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 12058}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {0, (char*)&byteswillprops3}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {21, (char*)&byteswillprops4}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 9923}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 190}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 210}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 8}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {24, (char*)&byteswillprops5}}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {20, (char*)&byteswillprops6}, .v = {28, (char*)&byteswillprops7}}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {8, (char*)&byteswillprops8}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {25, (char*)&byteswillprops9}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 24918}}, + }; + + lwmqtt_properties_t willprops = {21, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x5b, 0xe, 0x8a, 0x35, 0xd9, 0x5c, 0xfd, 0x95, + 0xd4, 0xf9, 0x73, 0x8b, 0x1, 0x5, 0x10, 0x77}; + lwmqtt_string_t will_topic = {16, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x7, 0xfc, 0xb7, 0xa7, 0x89, 0x14, 0xf8, 0x2, 0x5e, 0x10, 0xf9, + 0xf2, 0xc2, 0x1b, 0x87, 0xa5, 0x35, 0x4c, 0xcd, 0x64, 0x6e, 0x12}; + lwmqtt_string_t will_payload = {22, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 27552; + uint8_t client_id_bytes[] = {0x65, 0xb9, 0xe5}; + lwmqtt_string_t client_id = {3, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xac, 0x92, 0xe7, 0xfd, 0xde, 0x5e, 0xf7, 0xb7, 0x6c, 0xe8, 0x21, 0x85, + 0x3b, 0x8, 0x1c, 0xfd, 0x3, 0xc, 0x7e, 0x5b, 0xd3, 0x16, 0x28, 0x50}; + lwmqtt_string_t username = {24, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\208\186;\142\229\ENQ\DC3", _password = Just "k\STX\218\181\207){\"\180\DLE", +// _lastWill = Nothing, _cleanSession = False, _keepAlive = 28695, _connID = +// "\166'RW'\131!\222\228%N\243\227\158\253sF\r\211L", _properties = [PropReasonString +// "@\225\239\135\243j\244\208Ql\231\DC4\164\135h\245\241\ESC\DLE\r\231\&3",PropTopicAliasMaximum +// 24530,PropSubscriptionIdentifier 7,PropMaximumQoS 8,PropTopicAliasMaximum 7012,PropUserProperty +// "(\EOT\RSX~\228n\205\215\253" +// "6.\171.\209\168\237\219\203\174\200\201{\142\241-<\ETX\194\SOHsN\223\170",PropMessageExpiryInterval +// 13666,PropTopicAliasMaximum 806,PropPayloadFormatIndicator 137,PropResponseInformation "\168"]} +TEST(Connect5QCTest, Encode16) { + uint8_t pkt[] = {0x10, 0x8e, 0x1, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0xc0, 0x70, 0x17, 0x58, 0x1f, 0x0, 0x16, + 0x40, 0xe1, 0xef, 0x87, 0xf3, 0x6a, 0xf4, 0xd0, 0x51, 0x6c, 0xe7, 0x14, 0xa4, 0x87, 0x68, 0xf5, 0xf1, + 0x1b, 0x10, 0xd, 0xe7, 0x33, 0x22, 0x5f, 0xd2, 0xb, 0x7, 0x24, 0x8, 0x22, 0x1b, 0x64, 0x26, 0x0, + 0xa, 0x28, 0x4, 0x1e, 0x58, 0x7e, 0xe4, 0x6e, 0xcd, 0xd7, 0xfd, 0x0, 0x18, 0x36, 0x2e, 0xab, 0x2e, + 0xd1, 0xa8, 0xed, 0xdb, 0xcb, 0xae, 0xc8, 0xc9, 0x7b, 0x8e, 0xf1, 0x2d, 0x3c, 0x3, 0xc2, 0x1, 0x73, + 0x4e, 0xdf, 0xaa, 0x2, 0x0, 0x0, 0x35, 0x62, 0x22, 0x3, 0x26, 0x1, 0x89, 0x1a, 0x0, 0x1, 0xa8, + 0x0, 0x14, 0xa6, 0x27, 0x52, 0x57, 0x27, 0x83, 0x21, 0xde, 0xe4, 0x25, 0x4e, 0xf3, 0xe3, 0x9e, 0xfd, + 0x73, 0x46, 0xd, 0xd3, 0x4c, 0x0, 0x7, 0xd0, 0xba, 0x3b, 0x8e, 0xe5, 0x5, 0x13, 0x0, 0xa, 0x6b, + 0x2, 0xda, 0xb5, 0xcf, 0x29, 0x7b, 0x22, 0xb4, 0x10}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x40, 0xe1, 0xef, 0x87, 0xf3, 0x6a, 0xf4, 0xd0, 0x51, 0x6c, 0xe7, + 0x14, 0xa4, 0x87, 0x68, 0xf5, 0xf1, 0x1b, 0x10, 0xd, 0xe7, 0x33}; + uint8_t bytesprops2[] = {0x36, 0x2e, 0xab, 0x2e, 0xd1, 0xa8, 0xed, 0xdb, 0xcb, 0xae, 0xc8, 0xc9, + 0x7b, 0x8e, 0xf1, 0x2d, 0x3c, 0x3, 0xc2, 0x1, 0x73, 0x4e, 0xdf, 0xaa}; + uint8_t bytesprops1[] = {0x28, 0x4, 0x1e, 0x58, 0x7e, 0xe4, 0x6e, 0xcd, 0xd7, 0xfd}; + uint8_t bytesprops3[] = {0xa8}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)31, .value = {.str = {22, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 24530}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 7}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 8}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 7012}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {10, (char*)&bytesprops1}, .v = {24, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 13666}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 806}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 137}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {1, (char*)&bytesprops3}}}, + }; + + lwmqtt_properties_t props = {10, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 28695; + uint8_t client_id_bytes[] = {0xa6, 0x27, 0x52, 0x57, 0x27, 0x83, 0x21, 0xde, 0xe4, 0x25, + 0x4e, 0xf3, 0xe3, 0x9e, 0xfd, 0x73, 0x46, 0xd, 0xd3, 0x4c}; + lwmqtt_string_t client_id = {20, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xd0, 0xba, 0x3b, 0x8e, 0xe5, 0x5, 0x13}; + lwmqtt_string_t username = {7, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x6b, 0x2, 0xda, 0xb5, 0xcf, 0x29, 0x7b, 0x22, 0xb4, 0x10}; + lwmqtt_string_t password = {10, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Nothing, _lastWill = Just (LastWill {_willRetain = True, _willQoS = +// QoS1, _willTopic = "\226g", _willMsg = "\148\r}\DEL1ZJ\210\CAN\RS\158C~\249\215\205\219\158\211'4\223\ESC", +// _willProps = [PropSharedSubscriptionAvailable 93,PropContentType +// "\DLE\135\211u\187\229\131:\243\144\DC4f8\238\&1\213\247\SO",PropRequestResponseInformation 15,PropTopicAliasMaximum +// 29638,PropSharedSubscriptionAvailable 206]}), _cleanSession = False, _keepAlive = 10322, _connID = +// "\146\226x\204\ESC:q5\ENQ|,`\206", _properties = [PropMaximumPacketSize 3645,PropReasonString +// "LI\224\ENQ\250\DEL\168/\SYN\246<\246\160E \254",PropAuthenticationMethod +// "\174orF\219\&9we7M\202Z\\\214\175Z",PropSubscriptionIdentifierAvailable 179,PropPayloadFormatIndicator +// 7,PropWillDelayInterval 251,PropAuthenticationData "\181N\201\RS\159\US\241\&3r"]} +TEST(Connect5QCTest, Encode17) { + uint8_t pkt[] = {0x10, 0x96, 0x1, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0x2c, 0x28, 0x52, 0x40, 0x27, 0x0, + 0x0, 0xe, 0x3d, 0x1f, 0x0, 0x10, 0x4c, 0x49, 0xe0, 0x5, 0xfa, 0x7f, 0xa8, 0x2f, 0x16, 0xf6, + 0x3c, 0xf6, 0xa0, 0x45, 0x20, 0xfe, 0x15, 0x0, 0x10, 0xae, 0x6f, 0x72, 0x46, 0xdb, 0x39, 0x77, + 0x65, 0x37, 0x4d, 0xca, 0x5a, 0x5c, 0xd6, 0xaf, 0x5a, 0x29, 0xb3, 0x1, 0x7, 0x18, 0x0, 0x0, + 0x0, 0xfb, 0x16, 0x0, 0x9, 0xb5, 0x4e, 0xc9, 0x1e, 0x9f, 0x1f, 0xf1, 0x33, 0x72, 0x0, 0xd, + 0x92, 0xe2, 0x78, 0xcc, 0x1b, 0x3a, 0x71, 0x35, 0x5, 0x7c, 0x2c, 0x60, 0xce, 0x1e, 0x2a, 0x5d, + 0x3, 0x0, 0x12, 0x10, 0x87, 0xd3, 0x75, 0xbb, 0xe5, 0x83, 0x3a, 0xf3, 0x90, 0x14, 0x66, 0x38, + 0xee, 0x31, 0xd5, 0xf7, 0xe, 0x19, 0xf, 0x22, 0x73, 0xc6, 0x2a, 0xce, 0x0, 0x2, 0xe2, 0x67, + 0x0, 0x17, 0x94, 0xd, 0x7d, 0x7f, 0x31, 0x5a, 0x4a, 0xd2, 0x18, 0x1e, 0x9e, 0x43, 0x7e, 0xf9, + 0xd7, 0xcd, 0xdb, 0x9e, 0xd3, 0x27, 0x34, 0xdf, 0x1b}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x4c, 0x49, 0xe0, 0x5, 0xfa, 0x7f, 0xa8, 0x2f, + 0x16, 0xf6, 0x3c, 0xf6, 0xa0, 0x45, 0x20, 0xfe}; + uint8_t bytesprops1[] = {0xae, 0x6f, 0x72, 0x46, 0xdb, 0x39, 0x77, 0x65, + 0x37, 0x4d, 0xca, 0x5a, 0x5c, 0xd6, 0xaf, 0x5a}; + uint8_t bytesprops2[] = {0xb5, 0x4e, 0xc9, 0x1e, 0x9f, 0x1f, 0xf1, 0x33, 0x72}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 3645}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {16, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {16, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 179}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 7}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 251}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {9, (char*)&bytesprops2}}}, + }; + + lwmqtt_properties_t props = {7, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops0[] = {0x10, 0x87, 0xd3, 0x75, 0xbb, 0xe5, 0x83, 0x3a, 0xf3, + 0x90, 0x14, 0x66, 0x38, 0xee, 0x31, 0xd5, 0xf7, 0xe}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 93}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {18, (char*)&byteswillprops0}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 15}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 29638}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 206}}, + }; + + lwmqtt_properties_t willprops = {5, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0xe2, 0x67}; + lwmqtt_string_t will_topic = {2, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x94, 0xd, 0x7d, 0x7f, 0x31, 0x5a, 0x4a, 0xd2, 0x18, 0x1e, 0x9e, 0x43, + 0x7e, 0xf9, 0xd7, 0xcd, 0xdb, 0x9e, 0xd3, 0x27, 0x34, 0xdf, 0x1b}; + lwmqtt_string_t will_payload = {23, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 10322; + uint8_t client_id_bytes[] = {0x92, 0xe2, 0x78, 0xcc, 0x1b, 0x3a, 0x71, 0x35, 0x5, 0x7c, 0x2c, 0x60, 0xce}; + lwmqtt_string_t client_id = {13, (char*)&client_id_bytes}; + opts.client_id = client_id; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\160(\fi\152\189\DC1\183}\167.2[,e\217\&8\238]\207\156\192:B\128\ESC\188\205", +// _password = Just "\223+\207(\246E\243:\221J\144\DLE#\165\162\&3\240\148\196\247\150:@\226\154\174<", _lastWill = +// Nothing, _cleanSession = True, _keepAlive = 19401, _connID = +// "6\204\")V\154L\237\218s#U\227\148\134o\190\&2\ETB\192^\225\201\229\169", _properties = [PropResponseInformation +// "C\SUB\229\233\223\DEL\202\158\US\EMk\176\213",PropServerReference +// "\DC3=\204@x`8\DC2\t\233\198\221\135\216\SYN",PropAuthenticationMethod +// "\DLE\167\n\179\DC3?r\207\GS\STX\220;by\213\SOp\231\EOT=\CAN\226,",PropSubscriptionIdentifierAvailable +// 71,PropWildcardSubscriptionAvailable 59,PropMaximumQoS 144,PropMessageExpiryInterval 11561,PropReasonString +// "x\ENQ\231\248\ACKhY\168\NAK9Z]fFD\173_h\157\&20\241v\181\205\185\DC4",PropUserProperty +// "\161@\DC2\130\\Pp\230\134\a\FS\235" +// "CF\128\225TL*\230\184Y\218\NUL\209\&2\ESC\156\GSo\222\221\&7\198=\217}\177\DLE\149",PropAuthenticationData +// "=A6a'\239\144\EM\221C\139\SI\233=\"\149W",PropRequestResponseInformation 158,PropResponseTopic +// "A\200o\t\159\150.\171\147\232"]} +TEST(Connect5QCTest, Encode18) { + uint8_t pkt[] = { + 0x10, 0x97, 0x2, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0xc2, 0x4b, 0xc9, 0xb5, 0x1, 0x1a, 0x0, 0xd, 0x43, + 0x1a, 0xe5, 0xe9, 0xdf, 0x7f, 0xca, 0x9e, 0x1f, 0x19, 0x6b, 0xb0, 0xd5, 0x1c, 0x0, 0xf, 0x13, 0x3d, 0xcc, 0x40, + 0x78, 0x60, 0x38, 0x12, 0x9, 0xe9, 0xc6, 0xdd, 0x87, 0xd8, 0x16, 0x15, 0x0, 0x17, 0x10, 0xa7, 0xa, 0xb3, 0x13, + 0x3f, 0x72, 0xcf, 0x1d, 0x2, 0xdc, 0x3b, 0x62, 0x79, 0xd5, 0xe, 0x70, 0xe7, 0x4, 0x3d, 0x18, 0xe2, 0x2c, 0x29, + 0x47, 0x28, 0x3b, 0x24, 0x90, 0x2, 0x0, 0x0, 0x2d, 0x29, 0x1f, 0x0, 0x1b, 0x78, 0x5, 0xe7, 0xf8, 0x6, 0x68, + 0x59, 0xa8, 0x15, 0x39, 0x5a, 0x5d, 0x66, 0x46, 0x44, 0xad, 0x5f, 0x68, 0x9d, 0x32, 0x30, 0xf1, 0x76, 0xb5, 0xcd, + 0xb9, 0x14, 0x26, 0x0, 0xc, 0xa1, 0x40, 0x12, 0x82, 0x5c, 0x50, 0x70, 0xe6, 0x86, 0x7, 0x1c, 0xeb, 0x0, 0x1c, + 0x43, 0x46, 0x80, 0xe1, 0x54, 0x4c, 0x2a, 0xe6, 0xb8, 0x59, 0xda, 0x0, 0xd1, 0x32, 0x1b, 0x9c, 0x1d, 0x6f, 0xde, + 0xdd, 0x37, 0xc6, 0x3d, 0xd9, 0x7d, 0xb1, 0x10, 0x95, 0x16, 0x0, 0x11, 0x3d, 0x41, 0x36, 0x61, 0x27, 0xef, 0x90, + 0x19, 0xdd, 0x43, 0x8b, 0xf, 0xe9, 0x3d, 0x22, 0x95, 0x57, 0x19, 0x9e, 0x8, 0x0, 0xa, 0x41, 0xc8, 0x6f, 0x9, + 0x9f, 0x96, 0x2e, 0xab, 0x93, 0xe8, 0x0, 0x19, 0x36, 0xcc, 0x22, 0x29, 0x56, 0x9a, 0x4c, 0xed, 0xda, 0x73, 0x23, + 0x55, 0xe3, 0x94, 0x86, 0x6f, 0xbe, 0x32, 0x17, 0xc0, 0x5e, 0xe1, 0xc9, 0xe5, 0xa9, 0x0, 0x1c, 0xa0, 0x28, 0xc, + 0x69, 0x98, 0xbd, 0x11, 0xb7, 0x7d, 0xa7, 0x2e, 0x32, 0x5b, 0x2c, 0x65, 0xd9, 0x38, 0xee, 0x5d, 0xcf, 0x9c, 0xc0, + 0x3a, 0x42, 0x80, 0x1b, 0xbc, 0xcd, 0x0, 0x1b, 0xdf, 0x2b, 0xcf, 0x28, 0xf6, 0x45, 0xf3, 0x3a, 0xdd, 0x4a, 0x90, + 0x10, 0x23, 0xa5, 0xa2, 0x33, 0xf0, 0x94, 0xc4, 0xf7, 0x96, 0x3a, 0x40, 0xe2, 0x9a, 0xae, 0x3c}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x43, 0x1a, 0xe5, 0xe9, 0xdf, 0x7f, 0xca, 0x9e, 0x1f, 0x19, 0x6b, 0xb0, 0xd5}; + uint8_t bytesprops1[] = {0x13, 0x3d, 0xcc, 0x40, 0x78, 0x60, 0x38, 0x12, 0x9, 0xe9, 0xc6, 0xdd, 0x87, 0xd8, 0x16}; + uint8_t bytesprops2[] = {0x10, 0xa7, 0xa, 0xb3, 0x13, 0x3f, 0x72, 0xcf, 0x1d, 0x2, 0xdc, 0x3b, + 0x62, 0x79, 0xd5, 0xe, 0x70, 0xe7, 0x4, 0x3d, 0x18, 0xe2, 0x2c}; + uint8_t bytesprops3[] = {0x78, 0x5, 0xe7, 0xf8, 0x6, 0x68, 0x59, 0xa8, 0x15, 0x39, 0x5a, 0x5d, 0x66, 0x46, + 0x44, 0xad, 0x5f, 0x68, 0x9d, 0x32, 0x30, 0xf1, 0x76, 0xb5, 0xcd, 0xb9, 0x14}; + uint8_t bytesprops5[] = {0x43, 0x46, 0x80, 0xe1, 0x54, 0x4c, 0x2a, 0xe6, 0xb8, 0x59, 0xda, 0x0, 0xd1, 0x32, + 0x1b, 0x9c, 0x1d, 0x6f, 0xde, 0xdd, 0x37, 0xc6, 0x3d, 0xd9, 0x7d, 0xb1, 0x10, 0x95}; + uint8_t bytesprops4[] = {0xa1, 0x40, 0x12, 0x82, 0x5c, 0x50, 0x70, 0xe6, 0x86, 0x7, 0x1c, 0xeb}; + uint8_t bytesprops6[] = {0x3d, 0x41, 0x36, 0x61, 0x27, 0xef, 0x90, 0x19, 0xdd, + 0x43, 0x8b, 0xf, 0xe9, 0x3d, 0x22, 0x95, 0x57}; + uint8_t bytesprops7[] = {0x41, 0xc8, 0x6f, 0x9, 0x9f, 0x96, 0x2e, 0xab, 0x93, 0xe8}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)26, .value = {.str = {13, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {15, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {23, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 71}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 59}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 144}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 11561}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {27, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {12, (char*)&bytesprops4}, .v = {28, (char*)&bytesprops5}}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {17, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 158}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {10, (char*)&bytesprops7}}}, + }; + + lwmqtt_properties_t props = {12, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 19401; + uint8_t client_id_bytes[] = {0x36, 0xcc, 0x22, 0x29, 0x56, 0x9a, 0x4c, 0xed, 0xda, 0x73, 0x23, 0x55, 0xe3, + 0x94, 0x86, 0x6f, 0xbe, 0x32, 0x17, 0xc0, 0x5e, 0xe1, 0xc9, 0xe5, 0xa9}; + lwmqtt_string_t client_id = {25, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xa0, 0x28, 0xc, 0x69, 0x98, 0xbd, 0x11, 0xb7, 0x7d, 0xa7, 0x2e, 0x32, 0x5b, 0x2c, + 0x65, 0xd9, 0x38, 0xee, 0x5d, 0xcf, 0x9c, 0xc0, 0x3a, 0x42, 0x80, 0x1b, 0xbc, 0xcd}; + lwmqtt_string_t username = {28, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0xdf, 0x2b, 0xcf, 0x28, 0xf6, 0x45, 0xf3, 0x3a, 0xdd, 0x4a, 0x90, 0x10, 0x23, 0xa5, + 0xa2, 0x33, 0xf0, 0x94, 0xc4, 0xf7, 0x96, 0x3a, 0x40, 0xe2, 0x9a, 0xae, 0x3c}; + lwmqtt_string_t password = {27, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "^u#\159", _password = Just +// "y\"\r/\252\&8\144\156Y\221,;\158\GS\207S\130\174\230\ETB\150\150M\148\159\212", _lastWill = Just (LastWill +// {_willRetain = False, _willQoS = QoS0, _willTopic = "\160A\b\242{hJ\240\SOHs\227", _willMsg = +// "+JS\150\209\231\230=\222\231\225\142\244\229\US2\STX\233\240\253\168\RSzG1", _willProps = [PropReasonString +// "'g\155\154%&\DLE_ /2\211\198d",PropResponseTopic "\206!\CAN\143\a$\229",PropSessionExpiryInterval +// 25013,PropSubscriptionIdentifier 5,PropSessionExpiryInterval 24584,PropMessageExpiryInterval +// 23541,PropPayloadFormatIndicator 200,PropMaximumPacketSize 4912,PropTopicAlias 16949,PropTopicAlias +// 16583,PropCorrelationData "v\SUB\ETB\240\236\255\128/\204+\"\b",PropAuthenticationMethod +// "\232\248\205#g\198\132b\236|\GS\192#]",PropMaximumQoS 115,PropPayloadFormatIndicator 136,PropServerKeepAlive +// 4856,PropAuthenticationMethod "\228$]\172\DLE[>\r\DC2\DC2\208\221|\200%\137\247Jf\201\250\246?",PropResponseTopic +// "\140",PropUserProperty "DYe\182\DEL\143R\150\206\187\USD\177\ESC\ETX>Dd:\255" +// "W\201\ETBm)UD9@!\172\201\148\176\EM@\162\128\217\\J"]}), _cleanSession = True, _keepAlive = 22513, _connID = +// "/\179\ENQ:\239\234\242P\129,\b\213A\237\186\243\&9\183\133\147\188\136.\ACK\202\FSS\\", _properties = +// [PropCorrelationData "\202\&4\250\CANN\240\191\152\222",PropTopicAlias 8984,PropSubscriptionIdentifierAvailable +// 29,PropRequestProblemInformation 163,PropReceiveMaximum 18790,PropAuthenticationMethod +// "\176\ENQS&\DC1\191\229+\197\152\162\SOH\DELQ]\235\173A\DEL\223\136\149",PropSubscriptionIdentifier +// 30,PropAuthenticationMethod "9\169\250\234\ESC\220\163\204\171\SUB\182\224",PropRetainAvailable +// 41,PropWillDelayInterval 29889,PropWildcardSubscriptionAvailable 124,PropRequestResponseInformation +// 82,PropContentType "\145 +// \255C_\146\209mA\223\169\FS\216F\247\214\181&\SO2\214\"oE\159`C\SOH\SOH",PropMessageExpiryInterval +// 21434,PropServerKeepAlive 5605,PropMaximumPacketSize 10501]} +TEST(Connect5QCTest, Encode19) { + uint8_t pkt[] = { + 0x10, 0x99, 0x3, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0xc6, 0x57, 0xf1, 0x78, 0x9, 0x0, 0x9, 0xca, 0x34, + 0xfa, 0x18, 0x4e, 0xf0, 0xbf, 0x98, 0xde, 0x23, 0x23, 0x18, 0x29, 0x1d, 0x17, 0xa3, 0x21, 0x49, 0x66, 0x15, 0x0, + 0x16, 0xb0, 0x5, 0x53, 0x26, 0x11, 0xbf, 0xe5, 0x2b, 0xc5, 0x98, 0xa2, 0x1, 0x7f, 0x51, 0x5d, 0xeb, 0xad, 0x41, + 0x7f, 0xdf, 0x88, 0x95, 0xb, 0x1e, 0x15, 0x0, 0xc, 0x39, 0xa9, 0xfa, 0xea, 0x1b, 0xdc, 0xa3, 0xcc, 0xab, 0x1a, + 0xb6, 0xe0, 0x25, 0x29, 0x18, 0x0, 0x0, 0x74, 0xc1, 0x28, 0x7c, 0x19, 0x52, 0x3, 0x0, 0x1d, 0x91, 0x20, 0xff, + 0x43, 0x5f, 0x92, 0xd1, 0x6d, 0x41, 0xdf, 0xa9, 0x1c, 0xd8, 0x46, 0xf7, 0xd6, 0xb5, 0x26, 0xe, 0x32, 0xd6, 0x22, + 0x6f, 0x45, 0x9f, 0x60, 0x43, 0x1, 0x1, 0x2, 0x0, 0x0, 0x53, 0xba, 0x13, 0x15, 0xe5, 0x27, 0x0, 0x0, 0x29, + 0x5, 0x0, 0x1c, 0x2f, 0xb3, 0x5, 0x3a, 0xef, 0xea, 0xf2, 0x50, 0x81, 0x2c, 0x8, 0xd5, 0x41, 0xed, 0xba, 0xf3, + 0x39, 0xb7, 0x85, 0x93, 0xbc, 0x88, 0x2e, 0x6, 0xca, 0x1c, 0x53, 0x5c, 0xac, 0x1, 0x1f, 0x0, 0xe, 0x27, 0x67, + 0x9b, 0x9a, 0x25, 0x26, 0x10, 0x5f, 0x20, 0x2f, 0x32, 0xd3, 0xc6, 0x64, 0x8, 0x0, 0x7, 0xce, 0x21, 0x18, 0x8f, + 0x7, 0x24, 0xe5, 0x11, 0x0, 0x0, 0x61, 0xb5, 0xb, 0x5, 0x11, 0x0, 0x0, 0x60, 0x8, 0x2, 0x0, 0x0, 0x5b, + 0xf5, 0x1, 0xc8, 0x27, 0x0, 0x0, 0x13, 0x30, 0x23, 0x42, 0x35, 0x23, 0x40, 0xc7, 0x9, 0x0, 0xc, 0x76, 0x1a, + 0x17, 0xf0, 0xec, 0xff, 0x80, 0x2f, 0xcc, 0x2b, 0x22, 0x8, 0x15, 0x0, 0xe, 0xe8, 0xf8, 0xcd, 0x23, 0x67, 0xc6, + 0x84, 0x62, 0xec, 0x7c, 0x1d, 0xc0, 0x23, 0x5d, 0x24, 0x73, 0x1, 0x88, 0x13, 0x12, 0xf8, 0x15, 0x0, 0x17, 0xe4, + 0x24, 0x5d, 0xac, 0x10, 0x5b, 0x3e, 0xd, 0x12, 0x12, 0xd0, 0xdd, 0x7c, 0xc8, 0x25, 0x89, 0xf7, 0x4a, 0x66, 0xc9, + 0xfa, 0xf6, 0x3f, 0x8, 0x0, 0x1, 0x8c, 0x26, 0x0, 0x14, 0x44, 0x59, 0x65, 0xb6, 0x7f, 0x8f, 0x52, 0x96, 0xce, + 0xbb, 0x1f, 0x44, 0xb1, 0x1b, 0x3, 0x3e, 0x44, 0x64, 0x3a, 0xff, 0x0, 0x15, 0x57, 0xc9, 0x17, 0x6d, 0x29, 0x55, + 0x44, 0x39, 0x40, 0x21, 0xac, 0xc9, 0x94, 0xb0, 0x19, 0x40, 0xa2, 0x80, 0xd9, 0x5c, 0x4a, 0x0, 0xb, 0xa0, 0x41, + 0x8, 0xf2, 0x7b, 0x68, 0x4a, 0xf0, 0x1, 0x73, 0xe3, 0x0, 0x19, 0x2b, 0x4a, 0x53, 0x96, 0xd1, 0xe7, 0xe6, 0x3d, + 0xde, 0xe7, 0xe1, 0x8e, 0xf4, 0xe5, 0x1f, 0x32, 0x2, 0xe9, 0xf0, 0xfd, 0xa8, 0x1e, 0x7a, 0x47, 0x31, 0x0, 0x4, + 0x5e, 0x75, 0x23, 0x9f, 0x0, 0x1a, 0x79, 0x22, 0xd, 0x2f, 0xfc, 0x38, 0x90, 0x9c, 0x59, 0xdd, 0x2c, 0x3b, 0x9e, + 0x1d, 0xcf, 0x53, 0x82, 0xae, 0xe6, 0x17, 0x96, 0x96, 0x4d, 0x94, 0x9f, 0xd4}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xca, 0x34, 0xfa, 0x18, 0x4e, 0xf0, 0xbf, 0x98, 0xde}; + uint8_t bytesprops1[] = {0xb0, 0x5, 0x53, 0x26, 0x11, 0xbf, 0xe5, 0x2b, 0xc5, 0x98, 0xa2, + 0x1, 0x7f, 0x51, 0x5d, 0xeb, 0xad, 0x41, 0x7f, 0xdf, 0x88, 0x95}; + uint8_t bytesprops2[] = {0x39, 0xa9, 0xfa, 0xea, 0x1b, 0xdc, 0xa3, 0xcc, 0xab, 0x1a, 0xb6, 0xe0}; + uint8_t bytesprops3[] = {0x91, 0x20, 0xff, 0x43, 0x5f, 0x92, 0xd1, 0x6d, 0x41, 0xdf, 0xa9, 0x1c, 0xd8, 0x46, 0xf7, + 0xd6, 0xb5, 0x26, 0xe, 0x32, 0xd6, 0x22, 0x6f, 0x45, 0x9f, 0x60, 0x43, 0x1, 0x1}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)9, .value = {.str = {9, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 8984}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 29}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 163}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 18790}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {22, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 30}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {12, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 41}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 29889}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 124}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 82}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {29, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 21434}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 5605}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 10501}}, + }; + + lwmqtt_properties_t props = {16, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops0[] = {0x27, 0x67, 0x9b, 0x9a, 0x25, 0x26, 0x10, 0x5f, 0x20, 0x2f, 0x32, 0xd3, 0xc6, 0x64}; + uint8_t byteswillprops1[] = {0xce, 0x21, 0x18, 0x8f, 0x7, 0x24, 0xe5}; + uint8_t byteswillprops2[] = {0x76, 0x1a, 0x17, 0xf0, 0xec, 0xff, 0x80, 0x2f, 0xcc, 0x2b, 0x22, 0x8}; + uint8_t byteswillprops3[] = {0xe8, 0xf8, 0xcd, 0x23, 0x67, 0xc6, 0x84, 0x62, 0xec, 0x7c, 0x1d, 0xc0, 0x23, 0x5d}; + uint8_t byteswillprops4[] = {0xe4, 0x24, 0x5d, 0xac, 0x10, 0x5b, 0x3e, 0xd, 0x12, 0x12, 0xd0, 0xdd, + 0x7c, 0xc8, 0x25, 0x89, 0xf7, 0x4a, 0x66, 0xc9, 0xfa, 0xf6, 0x3f}; + uint8_t byteswillprops5[] = {0x8c}; + uint8_t byteswillprops7[] = {0x57, 0xc9, 0x17, 0x6d, 0x29, 0x55, 0x44, 0x39, 0x40, 0x21, 0xac, + 0xc9, 0x94, 0xb0, 0x19, 0x40, 0xa2, 0x80, 0xd9, 0x5c, 0x4a}; + uint8_t byteswillprops6[] = {0x44, 0x59, 0x65, 0xb6, 0x7f, 0x8f, 0x52, 0x96, 0xce, 0xbb, + 0x1f, 0x44, 0xb1, 0x1b, 0x3, 0x3e, 0x44, 0x64, 0x3a, 0xff}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)31, .value = {.str = {14, (char*)&byteswillprops0}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {7, (char*)&byteswillprops1}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 25013}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 5}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 24584}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 23541}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 200}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 4912}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 16949}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 16583}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {12, (char*)&byteswillprops2}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {14, (char*)&byteswillprops3}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 115}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 136}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 4856}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {23, (char*)&byteswillprops4}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {1, (char*)&byteswillprops5}}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {20, (char*)&byteswillprops6}, .v = {21, (char*)&byteswillprops7}}}}, + }; + + lwmqtt_properties_t willprops = {18, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0xa0, 0x41, 0x8, 0xf2, 0x7b, 0x68, 0x4a, 0xf0, 0x1, 0x73, 0xe3}; + lwmqtt_string_t will_topic = {11, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x2b, 0x4a, 0x53, 0x96, 0xd1, 0xe7, 0xe6, 0x3d, 0xde, 0xe7, 0xe1, 0x8e, 0xf4, + 0xe5, 0x1f, 0x32, 0x2, 0xe9, 0xf0, 0xfd, 0xa8, 0x1e, 0x7a, 0x47, 0x31}; + lwmqtt_string_t will_payload = {25, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 22513; + uint8_t client_id_bytes[] = {0x2f, 0xb3, 0x5, 0x3a, 0xef, 0xea, 0xf2, 0x50, 0x81, 0x2c, 0x8, 0xd5, 0x41, 0xed, + 0xba, 0xf3, 0x39, 0xb7, 0x85, 0x93, 0xbc, 0x88, 0x2e, 0x6, 0xca, 0x1c, 0x53, 0x5c}; + lwmqtt_string_t client_id = {28, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x5e, 0x75, 0x23, 0x9f}; + lwmqtt_string_t username = {4, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x79, 0x22, 0xd, 0x2f, 0xfc, 0x38, 0x90, 0x9c, 0x59, 0xdd, 0x2c, 0x3b, 0x9e, + 0x1d, 0xcf, 0x53, 0x82, 0xae, 0xe6, 0x17, 0x96, 0x96, 0x4d, 0x94, 0x9f, 0xd4}; + lwmqtt_string_t password = {26, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Just +// "\148\203\247(\RS\253m?\172\246]f\150WW\162\137\245\t\255\243\SUB}", _lastWill = Just (LastWill {_willRetain = True, +// _willQoS = QoS2, _willTopic = "Q&\199s\163,\145Pk\170\212\r\SOH\210I", _willMsg = +// "/y0\n\222\221\178\SO\241\211d\222\211\&0b", _willProps = [PropTopicAliasMaximum 24326,PropTopicAliasMaximum +// 31128,PropReasonString "\EOT(\184q\142\248M\n\231\197\ENQ\145\166Wg6\236\254l",PropRequestResponseInformation +// 127,PropTopicAliasMaximum 24979,PropReasonString " \212 \181\&4\181\183\177\153\&8",PropRetainAvailable +// 93,PropResponseTopic "\249I7z\192\160\139\143y[\ETB\242\209"]}), _cleanSession = False, _keepAlive = 190, _connID = +// "6Y\188\175\229N\156\168\153V\FS", _properties = [PropTopicAliasMaximum 5801,PropMaximumQoS 147,PropReceiveMaximum +// 30524,PropServerKeepAlive 30683,PropCorrelationData +// "]\177\190!\250+\240\237\244\160\249\&4\ETB\172\176\250\172lq\130\246\167\tUA\NAK\137",PropCorrelationData +// "dS\224\235\&7\SYNR",PropResponseTopic "y\221~\245:me,\228(\219$\240]\207q\ETB3\156 \253K",PropAuthenticationMethod +// "t\142\144\&4>\218\246\147\232B\211\139O\245",PropServerKeepAlive 5346,PropTopicAliasMaximum +// 17977,PropRequestProblemInformation 52,PropSharedSubscriptionAvailable 246,PropContentType +// "\161\t\171\r\154\&9\194'p\250]d\205M\190\148\SO#\133\&0|W\201\183\244",PropMaximumPacketSize 19914,PropUserProperty +// "|\212\133R!\tH\254J\140\213\SO\174x\169\FS" "\STX\NUL\EM\RS\155\252\r\188<_(",PropAuthenticationData +// "AZfX\184",PropAuthenticationMethod "{k\222\194\244\156",PropRequestProblemInformation 175,PropSubscriptionIdentifier +// 1,PropMaximumQoS 191,PropServerKeepAlive 18832,PropRequestResponseInformation 70,PropTopicAlias +// 3492,PropRequestResponseInformation 231,PropAuthenticationData +// "\198\174\231U*\NAKko\ACK\170\252\150[\180\163\150",PropWillDelayInterval 31865]} +TEST(Connect5QCTest, Encode20) { + uint8_t pkt[] = { + 0x10, 0xf6, 0x2, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0x74, 0x0, 0xbe, 0xe1, 0x1, 0x22, 0x16, 0xa9, 0x24, + 0x93, 0x21, 0x77, 0x3c, 0x13, 0x77, 0xdb, 0x9, 0x0, 0x1b, 0x5d, 0xb1, 0xbe, 0x21, 0xfa, 0x2b, 0xf0, 0xed, 0xf4, + 0xa0, 0xf9, 0x34, 0x17, 0xac, 0xb0, 0xfa, 0xac, 0x6c, 0x71, 0x82, 0xf6, 0xa7, 0x9, 0x55, 0x41, 0x15, 0x89, 0x9, + 0x0, 0x7, 0x64, 0x53, 0xe0, 0xeb, 0x37, 0x16, 0x52, 0x8, 0x0, 0x16, 0x79, 0xdd, 0x7e, 0xf5, 0x3a, 0x6d, 0x65, + 0x2c, 0xe4, 0x28, 0xdb, 0x24, 0xf0, 0x5d, 0xcf, 0x71, 0x17, 0x33, 0x9c, 0x20, 0xfd, 0x4b, 0x15, 0x0, 0xe, 0x74, + 0x8e, 0x90, 0x34, 0x3e, 0xda, 0xf6, 0x93, 0xe8, 0x42, 0xd3, 0x8b, 0x4f, 0xf5, 0x13, 0x14, 0xe2, 0x22, 0x46, 0x39, + 0x17, 0x34, 0x2a, 0xf6, 0x3, 0x0, 0x19, 0xa1, 0x9, 0xab, 0xd, 0x9a, 0x39, 0xc2, 0x27, 0x70, 0xfa, 0x5d, 0x64, + 0xcd, 0x4d, 0xbe, 0x94, 0xe, 0x23, 0x85, 0x30, 0x7c, 0x57, 0xc9, 0xb7, 0xf4, 0x27, 0x0, 0x0, 0x4d, 0xca, 0x26, + 0x0, 0x10, 0x7c, 0xd4, 0x85, 0x52, 0x21, 0x9, 0x48, 0xfe, 0x4a, 0x8c, 0xd5, 0xe, 0xae, 0x78, 0xa9, 0x1c, 0x0, + 0xb, 0x2, 0x0, 0x19, 0x1e, 0x9b, 0xfc, 0xd, 0xbc, 0x3c, 0x5f, 0x28, 0x16, 0x0, 0x5, 0x41, 0x5a, 0x66, 0x58, + 0xb8, 0x15, 0x0, 0x6, 0x7b, 0x6b, 0xde, 0xc2, 0xf4, 0x9c, 0x17, 0xaf, 0xb, 0x1, 0x24, 0xbf, 0x13, 0x49, 0x90, + 0x19, 0x46, 0x23, 0xd, 0xa4, 0x19, 0xe7, 0x16, 0x0, 0x10, 0xc6, 0xae, 0xe7, 0x55, 0x2a, 0x15, 0x6b, 0x6f, 0x6, + 0xaa, 0xfc, 0x96, 0x5b, 0xb4, 0xa3, 0x96, 0x18, 0x0, 0x0, 0x7c, 0x79, 0x0, 0xb, 0x36, 0x59, 0xbc, 0xaf, 0xe5, + 0x4e, 0x9c, 0xa8, 0x99, 0x56, 0x1c, 0x40, 0x22, 0x5f, 0x6, 0x22, 0x79, 0x98, 0x1f, 0x0, 0x13, 0x4, 0x28, 0xb8, + 0x71, 0x8e, 0xf8, 0x4d, 0xa, 0xe7, 0xc5, 0x5, 0x91, 0xa6, 0x57, 0x67, 0x36, 0xec, 0xfe, 0x6c, 0x19, 0x7f, 0x22, + 0x61, 0x93, 0x1f, 0x0, 0xa, 0x20, 0xd4, 0x20, 0xb5, 0x34, 0xb5, 0xb7, 0xb1, 0x99, 0x38, 0x25, 0x5d, 0x8, 0x0, + 0xd, 0xf9, 0x49, 0x37, 0x7a, 0xc0, 0xa0, 0x8b, 0x8f, 0x79, 0x5b, 0x17, 0xf2, 0xd1, 0x0, 0xf, 0x51, 0x26, 0xc7, + 0x73, 0xa3, 0x2c, 0x91, 0x50, 0x6b, 0xaa, 0xd4, 0xd, 0x1, 0xd2, 0x49, 0x0, 0xf, 0x2f, 0x79, 0x30, 0xa, 0xde, + 0xdd, 0xb2, 0xe, 0xf1, 0xd3, 0x64, 0xde, 0xd3, 0x30, 0x62, 0x0, 0x17, 0x94, 0xcb, 0xf7, 0x28, 0x1e, 0xfd, 0x6d, + 0x3f, 0xac, 0xf6, 0x5d, 0x66, 0x96, 0x57, 0x57, 0xa2, 0x89, 0xf5, 0x9, 0xff, 0xf3, 0x1a, 0x7d}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x5d, 0xb1, 0xbe, 0x21, 0xfa, 0x2b, 0xf0, 0xed, 0xf4, 0xa0, 0xf9, 0x34, 0x17, 0xac, + 0xb0, 0xfa, 0xac, 0x6c, 0x71, 0x82, 0xf6, 0xa7, 0x9, 0x55, 0x41, 0x15, 0x89}; + uint8_t bytesprops1[] = {0x64, 0x53, 0xe0, 0xeb, 0x37, 0x16, 0x52}; + uint8_t bytesprops2[] = {0x79, 0xdd, 0x7e, 0xf5, 0x3a, 0x6d, 0x65, 0x2c, 0xe4, 0x28, 0xdb, + 0x24, 0xf0, 0x5d, 0xcf, 0x71, 0x17, 0x33, 0x9c, 0x20, 0xfd, 0x4b}; + uint8_t bytesprops3[] = {0x74, 0x8e, 0x90, 0x34, 0x3e, 0xda, 0xf6, 0x93, 0xe8, 0x42, 0xd3, 0x8b, 0x4f, 0xf5}; + uint8_t bytesprops4[] = {0xa1, 0x9, 0xab, 0xd, 0x9a, 0x39, 0xc2, 0x27, 0x70, 0xfa, 0x5d, 0x64, 0xcd, + 0x4d, 0xbe, 0x94, 0xe, 0x23, 0x85, 0x30, 0x7c, 0x57, 0xc9, 0xb7, 0xf4}; + uint8_t bytesprops6[] = {0x2, 0x0, 0x19, 0x1e, 0x9b, 0xfc, 0xd, 0xbc, 0x3c, 0x5f, 0x28}; + uint8_t bytesprops5[] = {0x7c, 0xd4, 0x85, 0x52, 0x21, 0x9, 0x48, 0xfe, + 0x4a, 0x8c, 0xd5, 0xe, 0xae, 0x78, 0xa9, 0x1c}; + uint8_t bytesprops7[] = {0x41, 0x5a, 0x66, 0x58, 0xb8}; + uint8_t bytesprops8[] = {0x7b, 0x6b, 0xde, 0xc2, 0xf4, 0x9c}; + uint8_t bytesprops9[] = {0xc6, 0xae, 0xe7, 0x55, 0x2a, 0x15, 0x6b, 0x6f, + 0x6, 0xaa, 0xfc, 0x96, 0x5b, 0xb4, 0xa3, 0x96}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 5801}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 147}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 30524}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 30683}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {27, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {7, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {22, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {14, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 5346}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 17977}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 52}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 246}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {25, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 19914}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {16, (char*)&bytesprops5}, .v = {11, (char*)&bytesprops6}}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {5, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {6, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 175}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 1}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 191}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 18832}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 70}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 3492}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 231}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {16, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 31865}}, + }; + + lwmqtt_properties_t props = {26, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops0[] = {0x4, 0x28, 0xb8, 0x71, 0x8e, 0xf8, 0x4d, 0xa, 0xe7, 0xc5, + 0x5, 0x91, 0xa6, 0x57, 0x67, 0x36, 0xec, 0xfe, 0x6c}; + uint8_t byteswillprops1[] = {0x20, 0xd4, 0x20, 0xb5, 0x34, 0xb5, 0xb7, 0xb1, 0x99, 0x38}; + uint8_t byteswillprops2[] = {0xf9, 0x49, 0x37, 0x7a, 0xc0, 0xa0, 0x8b, 0x8f, 0x79, 0x5b, 0x17, 0xf2, 0xd1}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 24326}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 31128}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {19, (char*)&byteswillprops0}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 127}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 24979}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {10, (char*)&byteswillprops1}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 93}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {13, (char*)&byteswillprops2}}}, + }; + + lwmqtt_properties_t willprops = {8, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x51, 0x26, 0xc7, 0x73, 0xa3, 0x2c, 0x91, 0x50, 0x6b, 0xaa, 0xd4, 0xd, 0x1, 0xd2, 0x49}; + lwmqtt_string_t will_topic = {15, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x2f, 0x79, 0x30, 0xa, 0xde, 0xdd, 0xb2, 0xe, + 0xf1, 0xd3, 0x64, 0xde, 0xd3, 0x30, 0x62}; + lwmqtt_string_t will_payload = {15, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS2; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 190; + uint8_t client_id_bytes[] = {0x36, 0x59, 0xbc, 0xaf, 0xe5, 0x4e, 0x9c, 0xa8, 0x99, 0x56, 0x1c}; + lwmqtt_string_t client_id = {11, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t password_bytes[] = {0x94, 0xcb, 0xf7, 0x28, 0x1e, 0xfd, 0x6d, 0x3f, 0xac, 0xf6, 0x5d, 0x66, + 0x96, 0x57, 0x57, 0xa2, 0x89, 0xf5, 0x9, 0xff, 0xf3, 0x1a, 0x7d}; + lwmqtt_string_t password = {23, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\DC4d\128<~\133\193\US", _password = Nothing, _lastWill = Just (LastWill +// {_willRetain = False, _willQoS = QoS1, _willTopic = "#\232\214h;\148\233\ESC\f\238c\v*\178\EM\DC2qs", _willMsg = +// "\250\"\228J*O\RS\174IQV(\146\131\255", _willProps = [PropSubscriptionIdentifier 12,PropReceiveMaximum +// 25475,PropRequestProblemInformation 241,PropRequestProblemInformation 120,PropServerReference +// "\178\219\192f\198F\206\185V\210\185X\161\250\165\SUB\210sG\ETB\216\219l",PropRequestProblemInformation +// 149,PropAssignedClientIdentifier +// "\STX^G\144\162\173\131y\216\161h\t\189\132\&8\182\&63+IC\b7\255",PropSubscriptionIdentifier +// 10,PropRequestResponseInformation 176,PropSubscriptionIdentifierAvailable 247,PropAuthenticationMethod +// "\138",PropServerReference +// "\176\178]\142\183v\234\b\178\216(\249\144\r\182\219.\161\191C",PropSubscriptionIdentifierAvailable +// 6,PropSessionExpiryInterval 6630,PropCorrelationData +// "\231pU\204C\DLEV\246=\139\210xt\202\230\DLEk\249|R\n\168\EM\238:\EM\DC4",PropResponseTopic +// "\163\167\190\f\232g5\211_\250\225\SO\232\248V\213\239\222\156\129\reC\247\174\162\138\SIf\175",PropTopicAliasMaximum +// 11311]}), _cleanSession = True, _keepAlive = 11426, _connID = "\204\182", _properties = +// [PropWildcardSubscriptionAvailable 241,PropAuthenticationMethod +// "\171\169\231L\227\ETX\168\184\157x\242\128\171\246\130\bT'!\134",PropTopicAlias 31140]} +TEST(Connect5QCTest, Encode21) { + uint8_t pkt[] = { + 0x10, 0x86, 0x2, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0x8e, 0x2c, 0xa2, 0x1c, 0x28, 0xf1, 0x15, 0x0, 0x14, + 0xab, 0xa9, 0xe7, 0x4c, 0xe3, 0x3, 0xa8, 0xb8, 0x9d, 0x78, 0xf2, 0x80, 0xab, 0xf6, 0x82, 0x8, 0x54, 0x27, 0x21, + 0x86, 0x23, 0x79, 0xa4, 0x0, 0x2, 0xcc, 0xb6, 0xaa, 0x1, 0xb, 0xc, 0x21, 0x63, 0x83, 0x17, 0xf1, 0x17, 0x78, + 0x1c, 0x0, 0x17, 0xb2, 0xdb, 0xc0, 0x66, 0xc6, 0x46, 0xce, 0xb9, 0x56, 0xd2, 0xb9, 0x58, 0xa1, 0xfa, 0xa5, 0x1a, + 0xd2, 0x73, 0x47, 0x17, 0xd8, 0xdb, 0x6c, 0x17, 0x95, 0x12, 0x0, 0x18, 0x2, 0x5e, 0x47, 0x90, 0xa2, 0xad, 0x83, + 0x79, 0xd8, 0xa1, 0x68, 0x9, 0xbd, 0x84, 0x38, 0xb6, 0x36, 0x33, 0x2b, 0x49, 0x43, 0x8, 0x37, 0xff, 0xb, 0xa, + 0x19, 0xb0, 0x29, 0xf7, 0x15, 0x0, 0x1, 0x8a, 0x1c, 0x0, 0x14, 0xb0, 0xb2, 0x5d, 0x8e, 0xb7, 0x76, 0xea, 0x8, + 0xb2, 0xd8, 0x28, 0xf9, 0x90, 0xd, 0xb6, 0xdb, 0x2e, 0xa1, 0xbf, 0x43, 0x29, 0x6, 0x11, 0x0, 0x0, 0x19, 0xe6, + 0x9, 0x0, 0x1b, 0xe7, 0x70, 0x55, 0xcc, 0x43, 0x10, 0x56, 0xf6, 0x3d, 0x8b, 0xd2, 0x78, 0x74, 0xca, 0xe6, 0x10, + 0x6b, 0xf9, 0x7c, 0x52, 0xa, 0xa8, 0x19, 0xee, 0x3a, 0x19, 0x14, 0x8, 0x0, 0x1e, 0xa3, 0xa7, 0xbe, 0xc, 0xe8, + 0x67, 0x35, 0xd3, 0x5f, 0xfa, 0xe1, 0xe, 0xe8, 0xf8, 0x56, 0xd5, 0xef, 0xde, 0x9c, 0x81, 0xd, 0x65, 0x43, 0xf7, + 0xae, 0xa2, 0x8a, 0xf, 0x66, 0xaf, 0x22, 0x2c, 0x2f, 0x0, 0x12, 0x23, 0xe8, 0xd6, 0x68, 0x3b, 0x94, 0xe9, 0x1b, + 0xc, 0xee, 0x63, 0xb, 0x2a, 0xb2, 0x19, 0x12, 0x71, 0x73, 0x0, 0xf, 0xfa, 0x22, 0xe4, 0x4a, 0x2a, 0x4f, 0x1e, + 0xae, 0x49, 0x51, 0x56, 0x28, 0x92, 0x83, 0xff, 0x0, 0x8, 0x14, 0x64, 0x80, 0x3c, 0x7e, 0x85, 0xc1, 0x1f}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xab, 0xa9, 0xe7, 0x4c, 0xe3, 0x3, 0xa8, 0xb8, 0x9d, 0x78, + 0xf2, 0x80, 0xab, 0xf6, 0x82, 0x8, 0x54, 0x27, 0x21, 0x86}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 241}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {20, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 31140}}, + }; + + lwmqtt_properties_t props = {3, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops0[] = {0xb2, 0xdb, 0xc0, 0x66, 0xc6, 0x46, 0xce, 0xb9, 0x56, 0xd2, 0xb9, 0x58, + 0xa1, 0xfa, 0xa5, 0x1a, 0xd2, 0x73, 0x47, 0x17, 0xd8, 0xdb, 0x6c}; + uint8_t byteswillprops1[] = {0x2, 0x5e, 0x47, 0x90, 0xa2, 0xad, 0x83, 0x79, 0xd8, 0xa1, 0x68, 0x9, + 0xbd, 0x84, 0x38, 0xb6, 0x36, 0x33, 0x2b, 0x49, 0x43, 0x8, 0x37, 0xff}; + uint8_t byteswillprops2[] = {0x8a}; + uint8_t byteswillprops3[] = {0xb0, 0xb2, 0x5d, 0x8e, 0xb7, 0x76, 0xea, 0x8, 0xb2, 0xd8, + 0x28, 0xf9, 0x90, 0xd, 0xb6, 0xdb, 0x2e, 0xa1, 0xbf, 0x43}; + uint8_t byteswillprops4[] = {0xe7, 0x70, 0x55, 0xcc, 0x43, 0x10, 0x56, 0xf6, 0x3d, 0x8b, 0xd2, 0x78, 0x74, 0xca, + 0xe6, 0x10, 0x6b, 0xf9, 0x7c, 0x52, 0xa, 0xa8, 0x19, 0xee, 0x3a, 0x19, 0x14}; + uint8_t byteswillprops5[] = {0xa3, 0xa7, 0xbe, 0xc, 0xe8, 0x67, 0x35, 0xd3, 0x5f, 0xfa, + 0xe1, 0xe, 0xe8, 0xf8, 0x56, 0xd5, 0xef, 0xde, 0x9c, 0x81, + 0xd, 0x65, 0x43, 0xf7, 0xae, 0xa2, 0x8a, 0xf, 0x66, 0xaf}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 12}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 25475}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 241}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 120}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {23, (char*)&byteswillprops0}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 149}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {24, (char*)&byteswillprops1}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 10}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 176}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 247}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {1, (char*)&byteswillprops2}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {20, (char*)&byteswillprops3}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 6}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 6630}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {27, (char*)&byteswillprops4}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {30, (char*)&byteswillprops5}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 11311}}, + }; + + lwmqtt_properties_t willprops = {17, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x23, 0xe8, 0xd6, 0x68, 0x3b, 0x94, 0xe9, 0x1b, 0xc, + 0xee, 0x63, 0xb, 0x2a, 0xb2, 0x19, 0x12, 0x71, 0x73}; + lwmqtt_string_t will_topic = {18, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0xfa, 0x22, 0xe4, 0x4a, 0x2a, 0x4f, 0x1e, 0xae, + 0x49, 0x51, 0x56, 0x28, 0x92, 0x83, 0xff}; + lwmqtt_string_t will_payload = {15, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 11426; + uint8_t client_id_bytes[] = {0xcc, 0xb6}; + lwmqtt_string_t client_id = {2, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x14, 0x64, 0x80, 0x3c, 0x7e, 0x85, 0xc1, 0x1f}; + lwmqtt_string_t username = {8, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Nothing, _password = Nothing, _lastWill = Just (LastWill {_willRetain = True, _willQoS = +// QoS0, _willTopic = "30\150m;\145\234\188\240\155\227p8<", _willMsg = "k\131\233ZIw", _willProps = [PropReasonString +// "\224oA\US0\179\133\211\236U\128~\145",PropMessageExpiryInterval 7572,PropUserProperty +// "\NUL~\160/\140-c\183\153\247\136j\EM\255\136\FS\141\EOT\161\208Ue" +// "\221\152\253?\ETXj\172\214\145\196\188\188l\190\230\196\ENQ\\V\166\203\247\221",PropSessionExpiryInterval +// 17732,PropContentType "IM",PropTopicAliasMaximum 8436,PropAuthenticationData "8\145\159\&2",PropMaximumQoS +// 146,PropAuthenticationData "\181(\171\201\171$\240*\173\223\189v7\217\159%ZU\DLE\EM\182_Dy",PropUserProperty +// "\167\223" "Un\219pa\230\tU\DEL\166\135\US\177\211R\196\225\&8",PropMessageExpiryInterval 25984,PropCorrelationData +// "\129\157u\211\197\211\&3|!o\147\156'\244\220",PropTopicAlias 24892,PropTopicAliasMaximum 30008,PropReceiveMaximum +// 4122,PropSharedSubscriptionAvailable 90,PropRequestProblemInformation 230,PropSubscriptionIdentifierAvailable +// 40,PropMessageExpiryInterval 17238,PropRequestProblemInformation 235,PropWildcardSubscriptionAvailable +// 218,PropSessionExpiryInterval 1537,PropContentType +// "\186P\224\158\141\135\t\GS\231\ETB\145B\186p\130c",PropTopicAliasMaximum 28928,PropUserProperty "\152\&2\220" +// "\231\141\238Xa\218\223 \132\187\249*\SO[",PropReceiveMaximum 30305,PropUserProperty +// "\234@\160\233\NUL\174r\176\225}\162\175z]00rs\227 \254\193\185" "_\232\186[1\142\FSd",PropReceiveMaximum 25770]}), +// _cleanSession = True, _keepAlive = 19711, _connID = "\STX\223\144\245\NAK\216/", _properties = +// [PropRequestResponseInformation 33,PropRetainAvailable 140,PropRequestResponseInformation +// 128,PropAuthenticationMethod +// "\ENQ\212,\245\246{\182\239\167v\192L9DB\146\152\v\246\&0\173c\233I\235\v\227\230\223",PropMessageExpiryInterval +// 4083,PropContentType "X\189\151 \177\t\158\146\166\192x+ \CAN\194\199\165BGg\170P",PropMaximumQoS 35,PropUserProperty +// "\DC13\ESC\236\187(\136" +// "\240\n)\ESC~\202\162\CAN\144\198\246\230HQ\SOH\138\&6\246\188i\147\133(\136p\130X",PropRequestResponseInformation +// 178,PropRequestProblemInformation 253,PropContentType +// "\t\134\147\242\144!\150\184\139E[\SOHUP\215\143V\211\178\ETX\DC4;S",PropTopicAlias 24281,PropSubscriptionIdentifier +// 12,PropServerReference "\186\235x",PropWillDelayInterval 26708,PropResponseInformation +// "N\173\NUL\132\128\SYN=\206\249\139\146\227\244q`\ETX3]",PropMessageExpiryInterval 11505,PropUserProperty +// "\170\172YF\197\140\EM\148\CAN\DC4\a\182/v\DC4\215\131\r\202\227\138S\183{m\194\245" +// "{\148\ESCm\186)\228\141c\195Xj4\245i\132\ACK!",PropAssignedClientIdentifier +// "\RS\236X\b\232W\191\RS\b\233}KW\152\225fm!PL\EM\250",PropSharedSubscriptionAvailable 158,PropMessageExpiryInterval +// 6848,PropResponseTopic "\142\129\190\156JY\226\EOT\SO\STXjnr"]} +TEST(Connect5QCTest, Encode22) { + uint8_t pkt[] = { + 0x10, 0xe1, 0x4, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0x26, 0x4c, 0xff, 0x97, 0x2, 0x19, 0x21, 0x25, 0x8c, + 0x19, 0x80, 0x15, 0x0, 0x1d, 0x5, 0xd4, 0x2c, 0xf5, 0xf6, 0x7b, 0xb6, 0xef, 0xa7, 0x76, 0xc0, 0x4c, 0x39, 0x44, + 0x42, 0x92, 0x98, 0xb, 0xf6, 0x30, 0xad, 0x63, 0xe9, 0x49, 0xeb, 0xb, 0xe3, 0xe6, 0xdf, 0x2, 0x0, 0x0, 0xf, + 0xf3, 0x3, 0x0, 0x16, 0x58, 0xbd, 0x97, 0x20, 0xb1, 0x9, 0x9e, 0x92, 0xa6, 0xc0, 0x78, 0x2b, 0x20, 0x18, 0xc2, + 0xc7, 0xa5, 0x42, 0x47, 0x67, 0xaa, 0x50, 0x24, 0x23, 0x26, 0x0, 0x7, 0x11, 0x33, 0x1b, 0xec, 0xbb, 0x28, 0x88, + 0x0, 0x1b, 0xf0, 0xa, 0x29, 0x1b, 0x7e, 0xca, 0xa2, 0x18, 0x90, 0xc6, 0xf6, 0xe6, 0x48, 0x51, 0x1, 0x8a, 0x36, + 0xf6, 0xbc, 0x69, 0x93, 0x85, 0x28, 0x88, 0x70, 0x82, 0x58, 0x19, 0xb2, 0x17, 0xfd, 0x3, 0x0, 0x17, 0x9, 0x86, + 0x93, 0xf2, 0x90, 0x21, 0x96, 0xb8, 0x8b, 0x45, 0x5b, 0x1, 0x55, 0x50, 0xd7, 0x8f, 0x56, 0xd3, 0xb2, 0x3, 0x14, + 0x3b, 0x53, 0x23, 0x5e, 0xd9, 0xb, 0xc, 0x1c, 0x0, 0x3, 0xba, 0xeb, 0x78, 0x18, 0x0, 0x0, 0x68, 0x54, 0x1a, + 0x0, 0x12, 0x4e, 0xad, 0x0, 0x84, 0x80, 0x16, 0x3d, 0xce, 0xf9, 0x8b, 0x92, 0xe3, 0xf4, 0x71, 0x60, 0x3, 0x33, + 0x5d, 0x2, 0x0, 0x0, 0x2c, 0xf1, 0x26, 0x0, 0x1b, 0xaa, 0xac, 0x59, 0x46, 0xc5, 0x8c, 0x19, 0x94, 0x18, 0x14, + 0x7, 0xb6, 0x2f, 0x76, 0x14, 0xd7, 0x83, 0xd, 0xca, 0xe3, 0x8a, 0x53, 0xb7, 0x7b, 0x6d, 0xc2, 0xf5, 0x0, 0x12, + 0x7b, 0x94, 0x1b, 0x6d, 0xba, 0x29, 0xe4, 0x8d, 0x63, 0xc3, 0x58, 0x6a, 0x34, 0xf5, 0x69, 0x84, 0x6, 0x21, 0x12, + 0x0, 0x16, 0x1e, 0xec, 0x58, 0x8, 0xe8, 0x57, 0xbf, 0x1e, 0x8, 0xe9, 0x7d, 0x4b, 0x57, 0x98, 0xe1, 0x66, 0x6d, + 0x21, 0x50, 0x4c, 0x19, 0xfa, 0x2a, 0x9e, 0x2, 0x0, 0x0, 0x1a, 0xc0, 0x8, 0x0, 0xd, 0x8e, 0x81, 0xbe, 0x9c, + 0x4a, 0x59, 0xe2, 0x4, 0xe, 0x2, 0x6a, 0x6e, 0x72, 0x0, 0x7, 0x2, 0xdf, 0x90, 0xf5, 0x15, 0xd8, 0x2f, 0x9b, + 0x2, 0x1f, 0x0, 0xd, 0xe0, 0x6f, 0x41, 0x1f, 0x30, 0xb3, 0x85, 0xd3, 0xec, 0x55, 0x80, 0x7e, 0x91, 0x2, 0x0, + 0x0, 0x1d, 0x94, 0x26, 0x0, 0x16, 0x0, 0x7e, 0xa0, 0x2f, 0x8c, 0x2d, 0x63, 0xb7, 0x99, 0xf7, 0x88, 0x6a, 0x19, + 0xff, 0x88, 0x1c, 0x8d, 0x4, 0xa1, 0xd0, 0x55, 0x65, 0x0, 0x17, 0xdd, 0x98, 0xfd, 0x3f, 0x3, 0x6a, 0xac, 0xd6, + 0x91, 0xc4, 0xbc, 0xbc, 0x6c, 0xbe, 0xe6, 0xc4, 0x5, 0x5c, 0x56, 0xa6, 0xcb, 0xf7, 0xdd, 0x11, 0x0, 0x0, 0x45, + 0x44, 0x3, 0x0, 0x2, 0x49, 0x4d, 0x22, 0x20, 0xf4, 0x16, 0x0, 0x4, 0x38, 0x91, 0x9f, 0x32, 0x24, 0x92, 0x16, + 0x0, 0x18, 0xb5, 0x28, 0xab, 0xc9, 0xab, 0x24, 0xf0, 0x2a, 0xad, 0xdf, 0xbd, 0x76, 0x37, 0xd9, 0x9f, 0x25, 0x5a, + 0x55, 0x10, 0x19, 0xb6, 0x5f, 0x44, 0x79, 0x26, 0x0, 0x2, 0xa7, 0xdf, 0x0, 0x12, 0x55, 0x6e, 0xdb, 0x70, 0x61, + 0xe6, 0x9, 0x55, 0x7f, 0xa6, 0x87, 0x1f, 0xb1, 0xd3, 0x52, 0xc4, 0xe1, 0x38, 0x2, 0x0, 0x0, 0x65, 0x80, 0x9, + 0x0, 0xf, 0x81, 0x9d, 0x75, 0xd3, 0xc5, 0xd3, 0x33, 0x7c, 0x21, 0x6f, 0x93, 0x9c, 0x27, 0xf4, 0xdc, 0x23, 0x61, + 0x3c, 0x22, 0x75, 0x38, 0x21, 0x10, 0x1a, 0x2a, 0x5a, 0x17, 0xe6, 0x29, 0x28, 0x2, 0x0, 0x0, 0x43, 0x56, 0x17, + 0xeb, 0x28, 0xda, 0x11, 0x0, 0x0, 0x6, 0x1, 0x3, 0x0, 0x10, 0xba, 0x50, 0xe0, 0x9e, 0x8d, 0x87, 0x9, 0x1d, + 0xe7, 0x17, 0x91, 0x42, 0xba, 0x70, 0x82, 0x63, 0x22, 0x71, 0x0, 0x26, 0x0, 0x3, 0x98, 0x32, 0xdc, 0x0, 0xe, + 0xe7, 0x8d, 0xee, 0x58, 0x61, 0xda, 0xdf, 0x20, 0x84, 0xbb, 0xf9, 0x2a, 0xe, 0x5b, 0x21, 0x76, 0x61, 0x26, 0x0, + 0x17, 0xea, 0x40, 0xa0, 0xe9, 0x0, 0xae, 0x72, 0xb0, 0xe1, 0x7d, 0xa2, 0xaf, 0x7a, 0x5d, 0x30, 0x30, 0x72, 0x73, + 0xe3, 0x20, 0xfe, 0xc1, 0xb9, 0x0, 0x8, 0x5f, 0xe8, 0xba, 0x5b, 0x31, 0x8e, 0x1c, 0x64, 0x21, 0x64, 0xaa, 0x0, + 0xe, 0x33, 0x30, 0x96, 0x6d, 0x3b, 0x91, 0xea, 0xbc, 0xf0, 0x9b, 0xe3, 0x70, 0x38, 0x3c, 0x0, 0x6, 0x6b, 0x83, + 0xe9, 0x5a, 0x49, 0x77}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x5, 0xd4, 0x2c, 0xf5, 0xf6, 0x7b, 0xb6, 0xef, 0xa7, 0x76, 0xc0, 0x4c, 0x39, 0x44, 0x42, + 0x92, 0x98, 0xb, 0xf6, 0x30, 0xad, 0x63, 0xe9, 0x49, 0xeb, 0xb, 0xe3, 0xe6, 0xdf}; + uint8_t bytesprops1[] = {0x58, 0xbd, 0x97, 0x20, 0xb1, 0x9, 0x9e, 0x92, 0xa6, 0xc0, 0x78, + 0x2b, 0x20, 0x18, 0xc2, 0xc7, 0xa5, 0x42, 0x47, 0x67, 0xaa, 0x50}; + uint8_t bytesprops3[] = {0xf0, 0xa, 0x29, 0x1b, 0x7e, 0xca, 0xa2, 0x18, 0x90, 0xc6, 0xf6, 0xe6, 0x48, 0x51, + 0x1, 0x8a, 0x36, 0xf6, 0xbc, 0x69, 0x93, 0x85, 0x28, 0x88, 0x70, 0x82, 0x58}; + uint8_t bytesprops2[] = {0x11, 0x33, 0x1b, 0xec, 0xbb, 0x28, 0x88}; + uint8_t bytesprops4[] = {0x9, 0x86, 0x93, 0xf2, 0x90, 0x21, 0x96, 0xb8, 0x8b, 0x45, 0x5b, 0x1, + 0x55, 0x50, 0xd7, 0x8f, 0x56, 0xd3, 0xb2, 0x3, 0x14, 0x3b, 0x53}; + uint8_t bytesprops5[] = {0xba, 0xeb, 0x78}; + uint8_t bytesprops6[] = {0x4e, 0xad, 0x0, 0x84, 0x80, 0x16, 0x3d, 0xce, 0xf9, + 0x8b, 0x92, 0xe3, 0xf4, 0x71, 0x60, 0x3, 0x33, 0x5d}; + uint8_t bytesprops8[] = {0x7b, 0x94, 0x1b, 0x6d, 0xba, 0x29, 0xe4, 0x8d, 0x63, + 0xc3, 0x58, 0x6a, 0x34, 0xf5, 0x69, 0x84, 0x6, 0x21}; + uint8_t bytesprops7[] = {0xaa, 0xac, 0x59, 0x46, 0xc5, 0x8c, 0x19, 0x94, 0x18, 0x14, 0x7, 0xb6, 0x2f, 0x76, + 0x14, 0xd7, 0x83, 0xd, 0xca, 0xe3, 0x8a, 0x53, 0xb7, 0x7b, 0x6d, 0xc2, 0xf5}; + uint8_t bytesprops9[] = {0x1e, 0xec, 0x58, 0x8, 0xe8, 0x57, 0xbf, 0x1e, 0x8, 0xe9, 0x7d, + 0x4b, 0x57, 0x98, 0xe1, 0x66, 0x6d, 0x21, 0x50, 0x4c, 0x19, 0xfa}; + uint8_t bytesprops10[] = {0x8e, 0x81, 0xbe, 0x9c, 0x4a, 0x59, 0xe2, 0x4, 0xe, 0x2, 0x6a, 0x6e, 0x72}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 33}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 140}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 128}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {29, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 4083}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {22, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 35}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {7, (char*)&bytesprops2}, .v = {27, (char*)&bytesprops3}}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 178}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 253}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {23, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 24281}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 12}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {3, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 26708}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {18, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 11505}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {27, (char*)&bytesprops7}, .v = {18, (char*)&bytesprops8}}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {22, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 158}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 6848}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {13, (char*)&bytesprops10}}}, + }; + + lwmqtt_properties_t props = {22, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops0[] = {0xe0, 0x6f, 0x41, 0x1f, 0x30, 0xb3, 0x85, 0xd3, 0xec, 0x55, 0x80, 0x7e, 0x91}; + uint8_t byteswillprops2[] = {0xdd, 0x98, 0xfd, 0x3f, 0x3, 0x6a, 0xac, 0xd6, 0x91, 0xc4, 0xbc, 0xbc, + 0x6c, 0xbe, 0xe6, 0xc4, 0x5, 0x5c, 0x56, 0xa6, 0xcb, 0xf7, 0xdd}; + uint8_t byteswillprops1[] = {0x0, 0x7e, 0xa0, 0x2f, 0x8c, 0x2d, 0x63, 0xb7, 0x99, 0xf7, 0x88, + 0x6a, 0x19, 0xff, 0x88, 0x1c, 0x8d, 0x4, 0xa1, 0xd0, 0x55, 0x65}; + uint8_t byteswillprops3[] = {0x49, 0x4d}; + uint8_t byteswillprops4[] = {0x38, 0x91, 0x9f, 0x32}; + uint8_t byteswillprops5[] = {0xb5, 0x28, 0xab, 0xc9, 0xab, 0x24, 0xf0, 0x2a, 0xad, 0xdf, 0xbd, 0x76, + 0x37, 0xd9, 0x9f, 0x25, 0x5a, 0x55, 0x10, 0x19, 0xb6, 0x5f, 0x44, 0x79}; + uint8_t byteswillprops7[] = {0x55, 0x6e, 0xdb, 0x70, 0x61, 0xe6, 0x9, 0x55, 0x7f, + 0xa6, 0x87, 0x1f, 0xb1, 0xd3, 0x52, 0xc4, 0xe1, 0x38}; + uint8_t byteswillprops6[] = {0xa7, 0xdf}; + uint8_t byteswillprops8[] = {0x81, 0x9d, 0x75, 0xd3, 0xc5, 0xd3, 0x33, 0x7c, + 0x21, 0x6f, 0x93, 0x9c, 0x27, 0xf4, 0xdc}; + uint8_t byteswillprops9[] = {0xba, 0x50, 0xe0, 0x9e, 0x8d, 0x87, 0x9, 0x1d, + 0xe7, 0x17, 0x91, 0x42, 0xba, 0x70, 0x82, 0x63}; + uint8_t byteswillprops11[] = {0xe7, 0x8d, 0xee, 0x58, 0x61, 0xda, 0xdf, 0x20, 0x84, 0xbb, 0xf9, 0x2a, 0xe, 0x5b}; + uint8_t byteswillprops10[] = {0x98, 0x32, 0xdc}; + uint8_t byteswillprops13[] = {0x5f, 0xe8, 0xba, 0x5b, 0x31, 0x8e, 0x1c, 0x64}; + uint8_t byteswillprops12[] = {0xea, 0x40, 0xa0, 0xe9, 0x0, 0xae, 0x72, 0xb0, 0xe1, 0x7d, 0xa2, 0xaf, + 0x7a, 0x5d, 0x30, 0x30, 0x72, 0x73, 0xe3, 0x20, 0xfe, 0xc1, 0xb9}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)31, .value = {.str = {13, (char*)&byteswillprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 7572}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {22, (char*)&byteswillprops1}, .v = {23, (char*)&byteswillprops2}}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 17732}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {2, (char*)&byteswillprops3}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 8436}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {4, (char*)&byteswillprops4}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 146}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {24, (char*)&byteswillprops5}}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {2, (char*)&byteswillprops6}, .v = {18, (char*)&byteswillprops7}}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 25984}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {15, (char*)&byteswillprops8}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 24892}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 30008}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 4122}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 90}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 230}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 40}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 17238}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 235}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 218}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 1537}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {16, (char*)&byteswillprops9}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 28928}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {3, (char*)&byteswillprops10}, .v = {14, (char*)&byteswillprops11}}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 30305}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {23, (char*)&byteswillprops12}, .v = {8, (char*)&byteswillprops13}}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 25770}}, + }; + + lwmqtt_properties_t willprops = {28, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x33, 0x30, 0x96, 0x6d, 0x3b, 0x91, 0xea, 0xbc, 0xf0, 0x9b, 0xe3, 0x70, 0x38, 0x3c}; + lwmqtt_string_t will_topic = {14, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x6b, 0x83, 0xe9, 0x5a, 0x49, 0x77}; + lwmqtt_string_t will_payload = {6, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS0; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 19711; + uint8_t client_id_bytes[] = {0x2, 0xdf, 0x90, 0xf5, 0x15, 0xd8, 0x2f}; + lwmqtt_string_t client_id = {7, (char*)&client_id_bytes}; + opts.client_id = client_id; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "\237\&6f|\US#T\133\189\b", _password = Just +// "\NAK\150YWx\f\184\140\SO3\181\&0[\f\ETB", _lastWill = Nothing, _cleanSession = True, _keepAlive = 23584, _connID = " +// \149\136+\173Ve0s\240\142\225V]\231\US\208\&2\137:.~\229", _properties = []} +TEST(Connect5QCTest, Encode23) { + uint8_t pkt[] = {0x10, 0x41, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0xc2, 0x5c, 0x20, 0x0, 0x0, 0x17, 0x20, 0x95, + 0x88, 0x2b, 0xad, 0x56, 0x65, 0x30, 0x73, 0xf0, 0x8e, 0xe1, 0x56, 0x5d, 0xe7, 0x1f, 0xd0, 0x32, 0x89, + 0x3a, 0x2e, 0x7e, 0xe5, 0x0, 0xa, 0xed, 0x36, 0x66, 0x7c, 0x1f, 0x23, 0x54, 0x85, 0xbd, 0x8, 0x0, + 0xf, 0x15, 0x96, 0x59, 0x57, 0x78, 0xc, 0xb8, 0x8c, 0xe, 0x33, 0xb5, 0x30, 0x5b, 0xc, 0x17}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 23584; + uint8_t client_id_bytes[] = {0x20, 0x95, 0x88, 0x2b, 0xad, 0x56, 0x65, 0x30, 0x73, 0xf0, 0x8e, 0xe1, + 0x56, 0x5d, 0xe7, 0x1f, 0xd0, 0x32, 0x89, 0x3a, 0x2e, 0x7e, 0xe5}; + lwmqtt_string_t client_id = {23, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0xed, 0x36, 0x66, 0x7c, 0x1f, 0x23, 0x54, 0x85, 0xbd, 0x8}; + lwmqtt_string_t username = {10, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x15, 0x96, 0x59, 0x57, 0x78, 0xc, 0xb8, 0x8c, 0xe, 0x33, 0xb5, 0x30, 0x5b, 0xc, 0x17}; + lwmqtt_string_t password = {15, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, NULL); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "Y\GS\153\146\134\165\&8^,k\\\EM\SYNh\207", _password = Just +// "D\149?\170\EOT\GSQ\216\139\168\210\247O\138\139[\237w\151\255Q{\"\145L~\172", _lastWill = Just (LastWill +// {_willRetain = True, _willQoS = QoS2, _willTopic = "}2\216h#\194\242\241G:\190{j\185\DC2\157}l", _willMsg = +// "D\196\243E\229\FS[+K\208\170=]o\152\NAKM\207\151\&8\188\CAN\234kd", _willProps = [PropMaximumPacketSize +// 13711,PropServerKeepAlive 18793,PropUserProperty "\223\SI\252\188\151" "\rr3\197",PropMessageExpiryInterval +// 4167,PropMessageExpiryInterval 614,PropSubscriptionIdentifierAvailable 52,PropAuthenticationData +// "\179\136\ENQ",PropAuthenticationData +// "\240}\150x\155\128\210\184\228\&4?\190\167\201r\138\&3\b",PropAuthenticationMethod " +// Wc\193\US",PropMessageExpiryInterval 9391,PropAssignedClientIdentifier +// "\225\246l\223\153\197\131$\STX\174\142J\177\147\174\144\NUL\186\243\160\238\212{\DC1\DC2\209H",PropWillDelayInterval +// 9240,PropSubscriptionIdentifier 30,PropRequestProblemInformation 126,PropServerReference +// ">\192\210\237",PropServerKeepAlive 14417,PropWildcardSubscriptionAvailable 12,PropSubscriptionIdentifier +// 17,PropMessageExpiryInterval 32500,PropTopicAlias 20005,PropCorrelationData "\203(\219\246",PropServerKeepAlive +// 6193]}), _cleanSession = True, _keepAlive = 21608, _connID = +// "\130&B\t\131\165\255\248=\203\140\NAK\165\235f\226JC\f\212<\181\191", _properties = [PropResponseTopic +// "\184t\FS\191a\ACK\171s\191\195\170",PropSubscriptionIdentifier 27,PropMessageExpiryInterval +// 29006,PropWildcardSubscriptionAvailable 211,PropMaximumQoS 66,PropServerKeepAlive 29972,PropServerKeepAlive +// 16839,PropMessageExpiryInterval 18851,PropMessageExpiryInterval 6917,PropMaximumQoS +// 144,PropRequestResponseInformation 177,PropWillDelayInterval 3086,PropMessageExpiryInterval +// 25623,PropAssignedClientIdentifier ":='\EM\229.\140NH\238X\202\232\128\243\193\FS;\222",PropServerKeepAlive +// 10186,PropServerReference "\172\139B\\&b\224\195\221\221p",PropRequestProblemInformation 255,PropReasonString +// "\159qa\254\164\202k\155\184\160\147@t"]} +TEST(Connect5QCTest, Encode24) { + uint8_t pkt[] = { + 0x10, 0x84, 0x3, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0xf6, 0x54, 0x68, 0x70, 0x8, 0x0, 0xb, 0xb8, 0x74, + 0x1c, 0xbf, 0x61, 0x6, 0xab, 0x73, 0xbf, 0xc3, 0xaa, 0xb, 0x1b, 0x2, 0x0, 0x0, 0x71, 0x4e, 0x28, 0xd3, 0x24, + 0x42, 0x13, 0x75, 0x14, 0x13, 0x41, 0xc7, 0x2, 0x0, 0x0, 0x49, 0xa3, 0x2, 0x0, 0x0, 0x1b, 0x5, 0x24, 0x90, + 0x19, 0xb1, 0x18, 0x0, 0x0, 0xc, 0xe, 0x2, 0x0, 0x0, 0x64, 0x17, 0x12, 0x0, 0x13, 0x3a, 0x3d, 0x27, 0x19, + 0xe5, 0x2e, 0x8c, 0x4e, 0x48, 0xee, 0x58, 0xca, 0xe8, 0x80, 0xf3, 0xc1, 0x1c, 0x3b, 0xde, 0x13, 0x27, 0xca, 0x1c, + 0x0, 0xb, 0xac, 0x8b, 0x42, 0x5c, 0x26, 0x62, 0xe0, 0xc3, 0xdd, 0xdd, 0x70, 0x17, 0xff, 0x1f, 0x0, 0xd, 0x9f, + 0x71, 0x61, 0xfe, 0xa4, 0xca, 0x6b, 0x9b, 0xb8, 0xa0, 0x93, 0x40, 0x74, 0x0, 0x17, 0x82, 0x26, 0x42, 0x9, 0x83, + 0xa5, 0xff, 0xf8, 0x3d, 0xcb, 0x8c, 0x15, 0xa5, 0xeb, 0x66, 0xe2, 0x4a, 0x43, 0xc, 0xd4, 0x3c, 0xb5, 0xbf, 0x91, + 0x1, 0x27, 0x0, 0x0, 0x35, 0x8f, 0x13, 0x49, 0x69, 0x26, 0x0, 0x5, 0xdf, 0xf, 0xfc, 0xbc, 0x97, 0x0, 0x4, + 0xd, 0x72, 0x33, 0xc5, 0x2, 0x0, 0x0, 0x10, 0x47, 0x2, 0x0, 0x0, 0x2, 0x66, 0x29, 0x34, 0x16, 0x0, 0x3, + 0xb3, 0x88, 0x5, 0x16, 0x0, 0x12, 0xf0, 0x7d, 0x96, 0x78, 0x9b, 0x80, 0xd2, 0xb8, 0xe4, 0x34, 0x3f, 0xbe, 0xa7, + 0xc9, 0x72, 0x8a, 0x33, 0x8, 0x15, 0x0, 0x5, 0x20, 0x57, 0x63, 0xc1, 0x1f, 0x2, 0x0, 0x0, 0x24, 0xaf, 0x12, + 0x0, 0x1b, 0xe1, 0xf6, 0x6c, 0xdf, 0x99, 0xc5, 0x83, 0x24, 0x2, 0xae, 0x8e, 0x4a, 0xb1, 0x93, 0xae, 0x90, 0x0, + 0xba, 0xf3, 0xa0, 0xee, 0xd4, 0x7b, 0x11, 0x12, 0xd1, 0x48, 0x18, 0x0, 0x0, 0x24, 0x18, 0xb, 0x1e, 0x17, 0x7e, + 0x1c, 0x0, 0x4, 0x3e, 0xc0, 0xd2, 0xed, 0x13, 0x38, 0x51, 0x28, 0xc, 0xb, 0x11, 0x2, 0x0, 0x0, 0x7e, 0xf4, + 0x23, 0x4e, 0x25, 0x9, 0x0, 0x4, 0xcb, 0x28, 0xdb, 0xf6, 0x13, 0x18, 0x31, 0x0, 0x12, 0x7d, 0x32, 0xd8, 0x68, + 0x23, 0xc2, 0xf2, 0xf1, 0x47, 0x3a, 0xbe, 0x7b, 0x6a, 0xb9, 0x12, 0x9d, 0x7d, 0x6c, 0x0, 0x19, 0x44, 0xc4, 0xf3, + 0x45, 0xe5, 0x1c, 0x5b, 0x2b, 0x4b, 0xd0, 0xaa, 0x3d, 0x5d, 0x6f, 0x98, 0x15, 0x4d, 0xcf, 0x97, 0x38, 0xbc, 0x18, + 0xea, 0x6b, 0x64, 0x0, 0xf, 0x59, 0x1d, 0x99, 0x92, 0x86, 0xa5, 0x38, 0x5e, 0x2c, 0x6b, 0x5c, 0x19, 0x16, 0x68, + 0xcf, 0x0, 0x1b, 0x44, 0x95, 0x3f, 0xaa, 0x4, 0x1d, 0x51, 0xd8, 0x8b, 0xa8, 0xd2, 0xf7, 0x4f, 0x8a, 0x8b, 0x5b, + 0xed, 0x77, 0x97, 0xff, 0x51, 0x7b, 0x22, 0x91, 0x4c, 0x7e, 0xac}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xb8, 0x74, 0x1c, 0xbf, 0x61, 0x6, 0xab, 0x73, 0xbf, 0xc3, 0xaa}; + uint8_t bytesprops1[] = {0x3a, 0x3d, 0x27, 0x19, 0xe5, 0x2e, 0x8c, 0x4e, 0x48, 0xee, + 0x58, 0xca, 0xe8, 0x80, 0xf3, 0xc1, 0x1c, 0x3b, 0xde}; + uint8_t bytesprops2[] = {0xac, 0x8b, 0x42, 0x5c, 0x26, 0x62, 0xe0, 0xc3, 0xdd, 0xdd, 0x70}; + uint8_t bytesprops3[] = {0x9f, 0x71, 0x61, 0xfe, 0xa4, 0xca, 0x6b, 0x9b, 0xb8, 0xa0, 0x93, 0x40, 0x74}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)8, .value = {.str = {11, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 27}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 29006}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 211}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 66}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 29972}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 16839}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 18851}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 6917}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 144}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 177}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 3086}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 25623}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {19, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 10186}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {11, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 255}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {13, (char*)&bytesprops3}}}, + }; + + lwmqtt_properties_t props = {18, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops1[] = {0xd, 0x72, 0x33, 0xc5}; + uint8_t byteswillprops0[] = {0xdf, 0xf, 0xfc, 0xbc, 0x97}; + uint8_t byteswillprops2[] = {0xb3, 0x88, 0x5}; + uint8_t byteswillprops3[] = {0xf0, 0x7d, 0x96, 0x78, 0x9b, 0x80, 0xd2, 0xb8, 0xe4, + 0x34, 0x3f, 0xbe, 0xa7, 0xc9, 0x72, 0x8a, 0x33, 0x8}; + uint8_t byteswillprops4[] = {0x20, 0x57, 0x63, 0xc1, 0x1f}; + uint8_t byteswillprops5[] = {0xe1, 0xf6, 0x6c, 0xdf, 0x99, 0xc5, 0x83, 0x24, 0x2, 0xae, 0x8e, 0x4a, 0xb1, 0x93, + 0xae, 0x90, 0x0, 0xba, 0xf3, 0xa0, 0xee, 0xd4, 0x7b, 0x11, 0x12, 0xd1, 0x48}; + uint8_t byteswillprops6[] = {0x3e, 0xc0, 0xd2, 0xed}; + uint8_t byteswillprops7[] = {0xcb, 0x28, 0xdb, 0xf6}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 13711}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 18793}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {5, (char*)&byteswillprops0}, .v = {4, (char*)&byteswillprops1}}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 4167}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 614}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 52}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {3, (char*)&byteswillprops2}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {18, (char*)&byteswillprops3}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {5, (char*)&byteswillprops4}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 9391}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {27, (char*)&byteswillprops5}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 9240}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 30}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 126}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {4, (char*)&byteswillprops6}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 14417}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 12}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 17}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 32500}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 20005}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {4, (char*)&byteswillprops7}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 6193}}, + }; + + lwmqtt_properties_t willprops = {22, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x7d, 0x32, 0xd8, 0x68, 0x23, 0xc2, 0xf2, 0xf1, 0x47, + 0x3a, 0xbe, 0x7b, 0x6a, 0xb9, 0x12, 0x9d, 0x7d, 0x6c}; + lwmqtt_string_t will_topic = {18, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x44, 0xc4, 0xf3, 0x45, 0xe5, 0x1c, 0x5b, 0x2b, 0x4b, 0xd0, 0xaa, 0x3d, 0x5d, + 0x6f, 0x98, 0x15, 0x4d, 0xcf, 0x97, 0x38, 0xbc, 0x18, 0xea, 0x6b, 0x64}; + lwmqtt_string_t will_payload = {25, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS2; + will.retained = true; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 21608; + uint8_t client_id_bytes[] = {0x82, 0x26, 0x42, 0x9, 0x83, 0xa5, 0xff, 0xf8, 0x3d, 0xcb, 0x8c, 0x15, + 0xa5, 0xeb, 0x66, 0xe2, 0x4a, 0x43, 0xc, 0xd4, 0x3c, 0xb5, 0xbf}; + lwmqtt_string_t client_id = {23, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x59, 0x1d, 0x99, 0x92, 0x86, 0xa5, 0x38, 0x5e, 0x2c, 0x6b, 0x5c, 0x19, 0x16, 0x68, 0xcf}; + lwmqtt_string_t username = {15, (char*)&username_bytes}; + opts.username = username; + uint8_t password_bytes[] = {0x44, 0x95, 0x3f, 0xaa, 0x4, 0x1d, 0x51, 0xd8, 0x8b, 0xa8, 0xd2, 0xf7, 0x4f, 0x8a, + 0x8b, 0x5b, 0xed, 0x77, 0x97, 0xff, 0x51, 0x7b, 0x22, 0x91, 0x4c, 0x7e, 0xac}; + lwmqtt_string_t password = {27, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "@\255\f -\161\165\199'wWt4\233\GS|D\153\234\178\201\GS\171c\234\218\227\128yV", +// _password = Just "\GS\f\242\202", _lastWill = Just (LastWill {_willRetain = False, _willQoS = QoS2, _willTopic = +// "t\201\133\209\218\232M\211\&6\137\160\250\176\231N\250K\156\n\154)G8m\230?*\204", _willMsg = +// "x\171H\181\148\190T\200\NAKGX-!", _willProps = [PropResponseInformation +// "\SYNn\154\246\\\237\168\161\&11\184\ENQ\137^-\243?\221\&3\232(\SO",PropTopicAliasMaximum 8234,PropUserProperty +// "\205\146\233\SOHu:\133\237v\240\237\164\242\243\246\191[\214\219" +// "14.\207~\159\236\181S\rqM\198\143EA\147\EOT",PropAuthenticationMethod +// "\ACK\232r\ACK\144\135o\168=\188\214\a#\191\251\155,",PropResponseTopic "",PropMessageExpiryInterval +// 25344,PropUserProperty "@\219L\251F/f\173\216\149\252\DC2!",PropAuthenticationData +// "",PropAuthenticationData "o\255\187\207\248\198\150\218\EOT`1\234",PropResponseTopic +// ",\169\214n{\199\229\ESC\203>G\211\188\198<\186\133L",PropUserProperty "j\166\147c\ACK\161\154:" +// "V\225\192\155\218\161\211\188\173r&m\220\222\151\v\226\CAN>o=\SI\v\SUB\255#",PropMaximumPacketSize +// 23390,PropReceiveMaximum 25525,PropRequestResponseInformation 73,PropSessionExpiryInterval +// 29798,PropMaximumPacketSize 783,PropResponseTopic "T",PropResponseTopic +// "\241\128;\167\214\175iX:\255\249",PropRequestResponseInformation 9,PropAuthenticationMethod +// "\229\172zl\183\253\183b\GS:\152l7K\152\rt\240\189\DC1C\165\227\177@",PropRetainAvailable 240,PropSharedSubscriptionAvailable +// 231,PropServerReference +// "\FS\151\STX\SOHG\SYND\243Y\188\138\207\&8V\202\ENQ\154g\203\238\235\177\231",PropMessageExpiryInterval +// 23163,PropMaximumPacketSize 7107,PropSubscriptionIdentifierAvailable 99,PropContentType "",PropAuthenticationMethod +// "\130\185\159m\183\128t-\220\133\227M\207.\SYN_\ETB)\177b\144@\208\150$Qq",PropServerReference +// "\255:\210#1<\"T\132\218\219\DEL\219\EOT\172\247\159`=\134\&7\217",PropSessionExpiryInterval +// 3863,PropTopicAliasMaximum 5913,PropSubscriptionIdentifierAvailable 86,PropMessageExpiryInterval +// 17555,PropSubscriptionIdentifier 16,PropRequestResponseInformation 161,PropRequestProblemInformation 101]} +TEST(Connect5QCTest, Encode28) { + uint8_t pkt[] = { + 0x10, 0x9f, 0x4, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0x4e, 0xa, 0x67, 0x90, 0x2, 0x8, 0x0, 0x8, 0x2, + 0x8b, 0x93, 0x11, 0x76, 0x79, 0x82, 0xdd, 0x1, 0xe7, 0x2, 0x0, 0x0, 0x53, 0x43, 0x18, 0x0, 0x0, 0x78, 0xb7, + 0x21, 0x40, 0x5d, 0x9, 0x0, 0x1a, 0x83, 0x32, 0x1c, 0x64, 0xcb, 0xb8, 0x78, 0x4d, 0x71, 0xf1, 0xe6, 0xa1, 0xb4, + 0x5d, 0x64, 0x22, 0xb3, 0x81, 0xd4, 0xba, 0xad, 0x6, 0x79, 0x8a, 0x20, 0xaa, 0x15, 0x0, 0x0, 0x1a, 0x0, 0x0, + 0x2, 0x0, 0x0, 0x7d, 0x92, 0x26, 0x0, 0x1d, 0x2b, 0x68, 0x7f, 0x7, 0xcd, 0x28, 0x44, 0xc1, 0x45, 0x29, 0x5, + 0x7f, 0x50, 0xc, 0x75, 0x31, 0x1f, 0xf0, 0x67, 0x6d, 0x3f, 0x72, 0x25, 0xa6, 0xf8, 0x76, 0x2, 0x8e, 0x14, 0x0, + 0x1c, 0xb4, 0x4d, 0x43, 0x4a, 0xb5, 0x28, 0xda, 0x15, 0x8d, 0x4e, 0xd0, 0x50, 0xdb, 0x63, 0x4b, 0x2, 0x80, 0x64, + 0x62, 0xbd, 0x21, 0x1f, 0x2c, 0x2f, 0xd3, 0x9d, 0x1e, 0xf5, 0x24, 0xc8, 0x2a, 0x3c, 0x17, 0x41, 0x15, 0x0, 0xe, + 0x92, 0xcf, 0x89, 0x3e, 0xd, 0x74, 0xf0, 0xbd, 0x11, 0x43, 0xa5, 0xe3, 0xb1, 0x40, 0x25, 0xf0, 0x2a, 0xe7, 0x1c, + 0x0, 0x17, 0x1c, 0x97, 0x2, 0x1, 0x47, 0x16, 0x44, 0xf3, 0x59, 0xbc, 0x8a, 0xcf, 0x38, 0x56, 0xca, 0x5, 0x9a, + 0x67, 0xcb, 0xee, 0xeb, 0xb1, 0xe7, 0x2, 0x0, 0x0, 0x5a, 0x7b, 0x27, 0x0, 0x0, 0x1b, 0xc3, 0x29, 0x63, 0x3, + 0x0, 0x0, 0x15, 0x0, 0x1b, 0x82, 0xb9, 0x9f, 0x6d, 0xb7, 0x80, 0x74, 0x2d, 0xdc, 0x85, 0xe3, 0x4d, 0xcf, 0x2e, + 0x16, 0x5f, 0x17, 0x29, 0xb1, 0x62, 0x90, 0x40, 0xd0, 0x96, 0x24, 0x51, 0x71, 0x1c, 0x0, 0x16, 0xff, 0x3a, 0xd2, + 0x23, 0x31, 0x3c, 0x22, 0x54, 0x84, 0xda, 0xdb, 0x7f, 0xdb, 0x4, 0xac, 0xf7, 0x9f, 0x60, 0x3d, 0x86, 0x37, 0xd9, + 0x11, 0x0, 0x0, 0xf, 0x17, 0x22, 0x17, 0x19, 0x29, 0x56, 0x2, 0x0, 0x0, 0x44, 0x93, 0xb, 0x10, 0x19, 0xa1, + 0x17, 0x65, 0x0, 0x1, 0x5f, 0xd5, 0x1, 0x2, 0x0, 0x0, 0x3, 0xd2, 0x22, 0x4d, 0xee, 0x15, 0x0, 0x14, 0xcb, + 0xf4, 0xbb, 0xac, 0x2a, 0x51, 0xd2, 0x18, 0x75, 0x90, 0x1a, 0x3, 0xec, 0x43, 0xb6, 0x22, 0x35, 0x56, 0x1d, 0x17, + 0x12, 0x0, 0x1a, 0xd4, 0x61, 0x28, 0xcd, 0x2a, 0x1, 0xbe, 0x3f, 0x7c, 0xd5, 0x9f, 0xe1, 0xe7, 0x7e, 0x72, 0x3e, + 0xfb, 0x46, 0x2f, 0x66, 0xad, 0xd8, 0x95, 0xfc, 0x12, 0x21, 0x16, 0x0, 0x0, 0x16, 0x0, 0xc, 0x6f, 0xff, 0xbb, + 0xcf, 0xf8, 0xc6, 0x96, 0xda, 0x4, 0x60, 0x31, 0xea, 0x8, 0x0, 0x12, 0x2c, 0xa9, 0xd6, 0x6e, 0x7b, 0xc7, 0xe5, + 0x1b, 0xcb, 0x3e, 0x47, 0xd3, 0xbc, 0xc6, 0x3c, 0xba, 0x85, 0x4c, 0x26, 0x0, 0x8, 0x6a, 0xa6, 0x93, 0x63, 0x6, + 0xa1, 0x9a, 0x3a, 0x0, 0x1a, 0x56, 0xe1, 0xc0, 0x9b, 0xda, 0xa1, 0xd3, 0xbc, 0xad, 0x72, 0x26, 0x6d, 0xdc, 0xde, + 0x97, 0xb, 0xe2, 0x18, 0x3e, 0x6f, 0x3d, 0xf, 0xb, 0x1a, 0xff, 0x23, 0x27, 0x0, 0x0, 0x5b, 0x5e, 0x21, 0x63, + 0xb5, 0x19, 0x49, 0x11, 0x0, 0x0, 0x74, 0x66, 0x27, 0x0, 0x0, 0x3, 0xf, 0x8, 0x0, 0x1, 0x54, 0x8, 0x0, + 0xb, 0xf1, 0x80, 0x3b, 0xa7, 0xd6, 0xaf, 0x69, 0x58, 0x3a, 0xff, 0xf9, 0x19, 0x9, 0x15, 0x0, 0x12, 0xe5, 0xac, + 0x7a, 0x6c, 0xb7, 0xfd, 0xb7, 0x62, 0x1d, 0x3a, 0x98, 0x6c, 0x37, 0x4b, 0x98, 0x3c, 0x63, 0x40, 0x9, 0x0, 0x4, + 0xc2, 0xb9, 0xcd, 0x89, 0x13, 0x7c, 0xb8, 0xb, 0x2, 0x19, 0x84, 0x0, 0x1d, 0xe5, 0x5a, 0x6f, 0x7, 0x6b, 0x52, + 0xa7, 0xaf, 0xe3, 0x37, 0x98, 0x2d, 0x9, 0xe, 0xf0, 0x28, 0x18, 0x2b, 0xb2, 0xc1, 0xaa, 0x25, 0x37, 0x8c, 0xe4, + 0xc8, 0xf1, 0xaf, 0x4e, 0x0, 0x3, 0x5c, 0x44, 0x4e, 0x0, 0x3, 0x39, 0x1a, 0x61}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x2, 0x8b, 0x93, 0x11, 0x76, 0x79, 0x82, 0xdd}; + uint8_t bytesprops1[] = {0x83, 0x32, 0x1c, 0x64, 0xcb, 0xb8, 0x78, 0x4d, 0x71, 0xf1, 0xe6, 0xa1, 0xb4, + 0x5d, 0x64, 0x22, 0xb3, 0x81, 0xd4, 0xba, 0xad, 0x6, 0x79, 0x8a, 0x20, 0xaa}; + uint8_t bytesprops2[] = {0}; + uint8_t bytesprops3[] = {0}; + uint8_t bytesprops5[] = {0xb4, 0x4d, 0x43, 0x4a, 0xb5, 0x28, 0xda, 0x15, 0x8d, 0x4e, 0xd0, 0x50, 0xdb, 0x63, + 0x4b, 0x2, 0x80, 0x64, 0x62, 0xbd, 0x21, 0x1f, 0x2c, 0x2f, 0xd3, 0x9d, 0x1e, 0xf5}; + uint8_t bytesprops4[] = {0x2b, 0x68, 0x7f, 0x7, 0xcd, 0x28, 0x44, 0xc1, 0x45, 0x29, 0x5, 0x7f, 0x50, 0xc, 0x75, + 0x31, 0x1f, 0xf0, 0x67, 0x6d, 0x3f, 0x72, 0x25, 0xa6, 0xf8, 0x76, 0x2, 0x8e, 0x14}; + uint8_t bytesprops6[] = {0x92, 0xcf, 0x89, 0x3e, 0xd, 0x74, 0xf0, 0xbd, 0x11, 0x43, 0xa5, 0xe3, 0xb1, 0x40}; + uint8_t bytesprops7[] = {0x1c, 0x97, 0x2, 0x1, 0x47, 0x16, 0x44, 0xf3, 0x59, 0xbc, 0x8a, 0xcf, + 0x38, 0x56, 0xca, 0x5, 0x9a, 0x67, 0xcb, 0xee, 0xeb, 0xb1, 0xe7}; + uint8_t bytesprops8[] = {0}; + uint8_t bytesprops9[] = {0x82, 0xb9, 0x9f, 0x6d, 0xb7, 0x80, 0x74, 0x2d, 0xdc, 0x85, 0xe3, 0x4d, 0xcf, 0x2e, + 0x16, 0x5f, 0x17, 0x29, 0xb1, 0x62, 0x90, 0x40, 0xd0, 0x96, 0x24, 0x51, 0x71}; + uint8_t bytesprops10[] = {0xff, 0x3a, 0xd2, 0x23, 0x31, 0x3c, 0x22, 0x54, 0x84, 0xda, 0xdb, + 0x7f, 0xdb, 0x4, 0xac, 0xf7, 0x9f, 0x60, 0x3d, 0x86, 0x37, 0xd9}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)8, .value = {.str = {8, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 231}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 21315}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 30903}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 16477}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {26, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {0, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {0, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 32146}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {29, (char*)&bytesprops4}, .v = {28, (char*)&bytesprops5}}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 200}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 60}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 65}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {14, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 240}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 231}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {23, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 23163}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 7107}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 99}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {0, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {27, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {22, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 3863}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 5913}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 86}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 17555}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 16}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 161}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 101}}, + }; + + lwmqtt_properties_t props = {30, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + uint8_t byteswillprops0[] = {0xcb, 0xf4, 0xbb, 0xac, 0x2a, 0x51, 0xd2, 0x18, 0x75, 0x90, + 0x1a, 0x3, 0xec, 0x43, 0xb6, 0x22, 0x35, 0x56, 0x1d, 0x17}; + uint8_t byteswillprops1[] = {0xd4, 0x61, 0x28, 0xcd, 0x2a, 0x1, 0xbe, 0x3f, 0x7c, 0xd5, 0x9f, 0xe1, 0xe7, + 0x7e, 0x72, 0x3e, 0xfb, 0x46, 0x2f, 0x66, 0xad, 0xd8, 0x95, 0xfc, 0x12, 0x21}; + uint8_t byteswillprops2[] = {0}; + uint8_t byteswillprops3[] = {0x6f, 0xff, 0xbb, 0xcf, 0xf8, 0xc6, 0x96, 0xda, 0x4, 0x60, 0x31, 0xea}; + uint8_t byteswillprops4[] = {0x2c, 0xa9, 0xd6, 0x6e, 0x7b, 0xc7, 0xe5, 0x1b, 0xcb, + 0x3e, 0x47, 0xd3, 0xbc, 0xc6, 0x3c, 0xba, 0x85, 0x4c}; + uint8_t byteswillprops6[] = {0x56, 0xe1, 0xc0, 0x9b, 0xda, 0xa1, 0xd3, 0xbc, 0xad, 0x72, 0x26, 0x6d, 0xdc, + 0xde, 0x97, 0xb, 0xe2, 0x18, 0x3e, 0x6f, 0x3d, 0xf, 0xb, 0x1a, 0xff, 0x23}; + uint8_t byteswillprops5[] = {0x6a, 0xa6, 0x93, 0x63, 0x6, 0xa1, 0x9a, 0x3a}; + uint8_t byteswillprops7[] = {0x54}; + uint8_t byteswillprops8[] = {0xf1, 0x80, 0x3b, 0xa7, 0xd6, 0xaf, 0x69, 0x58, 0x3a, 0xff, 0xf9}; + uint8_t byteswillprops9[] = {0xe5, 0xac, 0x7a, 0x6c, 0xb7, 0xfd, 0xb7, 0x62, 0x1d, + 0x3a, 0x98, 0x6c, 0x37, 0x4b, 0x98, 0x3c, 0x63, 0x40}; + uint8_t byteswillprops10[] = {0xc2, 0xb9, 0xcd, 0x89}; + + lwmqtt_property_t willpropslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 978}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 19950}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {20, (char*)&byteswillprops0}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {26, (char*)&byteswillprops1}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {0, (char*)&byteswillprops2}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {12, (char*)&byteswillprops3}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {18, (char*)&byteswillprops4}}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {8, (char*)&byteswillprops5}, .v = {26, (char*)&byteswillprops6}}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 23390}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 25525}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 73}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 29798}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 783}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {1, (char*)&byteswillprops7}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {11, (char*)&byteswillprops8}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 9}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {18, (char*)&byteswillprops9}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {4, (char*)&byteswillprops10}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 31928}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 2}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 132}}, + }; + + lwmqtt_properties_t willprops = {21, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0xe5, 0x5a, 0x6f, 0x7, 0x6b, 0x52, 0xa7, 0xaf, 0xe3, 0x37, 0x98, 0x2d, 0x9, 0xe, 0xf0, + 0x28, 0x18, 0x2b, 0xb2, 0xc1, 0xaa, 0x25, 0x37, 0x8c, 0xe4, 0xc8, 0xf1, 0xaf, 0x4e}; + lwmqtt_string_t will_topic = {29, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x5c, 0x44, 0x4e}; + lwmqtt_string_t will_payload = {3, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = true; + opts.keep_alive = 2663; + uint8_t client_id_bytes[] = {0x5f}; + lwmqtt_string_t client_id = {1, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t password_bytes[] = {0x39, 0x1a, 0x61}; + lwmqtt_string_t password = {3, (char*)&password_bytes}; + opts.password = password; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "fF\131\191\&2\166\189\187F", _password = Nothing, _lastWill = Just (LastWill +// {_willRetain = False, _willQoS = QoS1, _willTopic = "\ESC\162W>\201\134", _willMsg = +// "\CAN\EOT\254w\EOT&B2\STX\130\DC2\130\234\202\238\&1\DC4\179\ETB\223\169\132GI&\ACK", _willProps = []}), +// _cleanSession = False, _keepAlive = 16611, _connID = "P\213\SOHx\239\228P", _properties = []} +TEST(Connect5QCTest, Encode29) { + uint8_t pkt[] = {0x10, 0x44, 0x0, 0x4, 0x4d, 0x51, 0x54, 0x54, 0x5, 0x8c, 0x40, 0xe3, 0x0, 0x0, + 0x7, 0x50, 0xd5, 0x1, 0x78, 0xef, 0xe4, 0x50, 0x0, 0x0, 0x6, 0x1b, 0xa2, 0x57, + 0x3e, 0xc9, 0x86, 0x0, 0x1a, 0x18, 0x4, 0xfe, 0x77, 0x4, 0x26, 0x42, 0x32, 0x2, + 0x82, 0x12, 0x82, 0xea, 0xca, 0xee, 0x31, 0x14, 0xb3, 0x17, 0xdf, 0xa9, 0x84, 0x47, + 0x49, 0x26, 0x6, 0x0, 0x9, 0x66, 0x46, 0x83, 0xbf, 0x32, 0xa6, 0xbd, 0xbb, 0x46}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_will_t will = lwmqtt_default_will; + + lwmqtt_property_t willpropslist[] = {}; + + lwmqtt_properties_t willprops = {0, (lwmqtt_property_t*)&willpropslist}; + uint8_t will_topic_bytes[] = {0x1b, 0xa2, 0x57, 0x3e, 0xc9, 0x86}; + lwmqtt_string_t will_topic = {6, (char*)&will_topic_bytes}; + uint8_t will_payload_bytes[] = {0x18, 0x4, 0xfe, 0x77, 0x4, 0x26, 0x42, 0x32, 0x2, 0x82, 0x12, 0x82, 0xea, + 0xca, 0xee, 0x31, 0x14, 0xb3, 0x17, 0xdf, 0xa9, 0x84, 0x47, 0x49, 0x26, 0x6}; + lwmqtt_string_t will_payload = {26, (char*)&will_payload_bytes}; + will.topic = will_topic; + will.payload = will_payload; + will.qos = LWMQTT_QOS1; + will.retained = false; + will.properties = willprops; + lwmqtt_options_t opts = lwmqtt_default_options; + opts.properties = props; + opts.clean_session = false; + opts.keep_alive = 16611; + uint8_t client_id_bytes[] = {0x50, 0xd5, 0x1, 0x78, 0xef, 0xe4, 0x50}; + lwmqtt_string_t client_id = {7, (char*)&client_id_bytes}; + opts.client_id = client_id; + uint8_t username_bytes[] = {0x66, 0x46, 0x83, 0xbf, 0x32, 0xa6, 0xbd, 0xbb, 0x46}; + lwmqtt_string_t username = {9, (char*)&username_bytes}; + opts.username = username; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_connect(buf, sizeof(buf), &len, LWMQTT_MQTT5, opts, &will); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// ConnectRequest {_username = Just "y\204\237\224r>\158", _password = Nothing, _lastWill = Just (LastWill {_willRetain +// = False, _willQoS = QoS1, _willTopic = +// "[J\196H\203W\CAN\171&\151\152S\228\245A\CAN%\DLE\139+/j\\\198\221l`h\165\131\238\145-\156\v\161\232\183\144=\232v\252\242\198{\140",SubOptions {_retainHandling +// = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("u\191\218\ESC\245\204nb",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal +// = False, _subQoS = QoS1}),("",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = +// False, _subQoS = +// QoS0}),("\176\169\&4\190\&0\241\238\237\150\241\162\234\148\RS\133\243\DC1(9\SYNZ\226\184\199",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("jW\202\231\176\GS\252\217\199\151\250\161\248",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("Q \v\EM\165d\183\254\EOTw\224",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("N\ESCa1\203j8\230\EOT\160q,\148\239p\225RT\NAK",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode1) { + uint8_t pkt[] = { + 0x82, 0xbb, 0x1, 0x76, 0xe3, 0x0, 0x1a, 0x60, 0x68, 0xf1, 0x1e, 0x75, 0xeb, 0xf8, 0xe, 0xbd, 0x1a, 0x53, 0xd6, + 0xe7, 0x23, 0x84, 0x7f, 0xd9, 0x82, 0xa0, 0xd7, 0x97, 0xb6, 0x6a, 0xfc, 0xf0, 0x41, 0x0, 0x0, 0xf, 0x9, 0x20, + 0xd9, 0x94, 0x64, 0xe0, 0x7e, 0xcc, 0x7f, 0x33, 0x4c, 0xe7, 0x93, 0x8b, 0xd9, 0x2, 0x0, 0xc, 0xa7, 0x1b, 0x8a, + 0x7e, 0x97, 0x8b, 0xe5, 0x85, 0xc5, 0x39, 0xa3, 0xee, 0x0, 0x0, 0x1b, 0xa, 0x3e, 0x5c, 0xc6, 0xdd, 0x6c, 0x60, + 0x68, 0xa5, 0x83, 0xee, 0x91, 0x2d, 0x9c, 0xb, 0xa1, 0xe8, 0xb7, 0x90, 0x3d, 0xe8, 0x76, 0xfc, 0xf2, 0xc6, 0x7b, + 0x8c, 0x0, 0x0, 0x8, 0x75, 0xbf, 0xda, 0x1b, 0xf5, 0xcc, 0x6e, 0x62, 0x1, 0x0, 0x0, 0x0, 0x0, 0x18, 0xb0, + 0xa9, 0x34, 0xbe, 0x30, 0xf1, 0xee, 0xed, 0x96, 0xf1, 0xa2, 0xea, 0x94, 0x1e, 0x85, 0xf3, 0x11, 0x28, 0x39, 0x16, + 0x5a, 0xe2, 0xb8, 0xc7, 0x0, 0x0, 0xd, 0x6a, 0x57, 0xca, 0xe7, 0xb0, 0x1d, 0xfc, 0xd9, 0xc7, 0x97, 0xfa, 0xa1, + 0xf8, 0x2, 0x0, 0xb, 0x51, 0x20, 0xb, 0x19, 0xa5, 0x64, 0xb7, 0xfe, 0x4, 0x77, 0xe0, 0x1, 0x0, 0x13, 0x4e, + 0x1b, 0x61, 0x31, 0xcb, 0x6a, 0x38, 0xe6, 0x4, 0xa0, 0x71, 0x2c, 0x94, 0xef, 0x70, 0xe1, 0x52, 0x54, 0x15, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[10]; + uint8_t topic_filter_s0_bytes[] = {0x60, 0x68, 0xf1, 0x1e, 0x75, 0xeb, 0xf8, 0xe, 0xbd, 0x1a, 0x53, 0xd6, 0xe7, + 0x23, 0x84, 0x7f, 0xd9, 0x82, 0xa0, 0xd7, 0x97, 0xb6, 0x6a, 0xfc, 0xf0, 0x41}; + lwmqtt_string_t topic_filter_s0 = {26, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x9, 0x20, 0xd9, 0x94, 0x64, 0xe0, 0x7e, 0xcc, + 0x7f, 0x33, 0x4c, 0xe7, 0x93, 0x8b, 0xd9}; + lwmqtt_string_t topic_filter_s1 = {15, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xa7, 0x1b, 0x8a, 0x7e, 0x97, 0x8b, 0xe5, 0x85, 0xc5, 0x39, 0xa3, 0xee}; + lwmqtt_string_t topic_filter_s2 = {12, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xa, 0x3e, 0x5c, 0xc6, 0xdd, 0x6c, 0x60, 0x68, 0xa5, 0x83, 0xee, 0x91, 0x2d, 0x9c, + 0xb, 0xa1, 0xe8, 0xb7, 0x90, 0x3d, 0xe8, 0x76, 0xfc, 0xf2, 0xc6, 0x7b, 0x8c}; + lwmqtt_string_t topic_filter_s3 = {27, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x75, 0xbf, 0xda, 0x1b, 0xf5, 0xcc, 0x6e, 0x62}; + lwmqtt_string_t topic_filter_s4 = {8, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0}; + lwmqtt_string_t topic_filter_s5 = {0, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xb0, 0xa9, 0x34, 0xbe, 0x30, 0xf1, 0xee, 0xed, 0x96, 0xf1, 0xa2, 0xea, + 0x94, 0x1e, 0x85, 0xf3, 0x11, 0x28, 0x39, 0x16, 0x5a, 0xe2, 0xb8, 0xc7}; + lwmqtt_string_t topic_filter_s6 = {24, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x6a, 0x57, 0xca, 0xe7, 0xb0, 0x1d, 0xfc, 0xd9, 0xc7, 0x97, 0xfa, 0xa1, 0xf8}; + lwmqtt_string_t topic_filter_s7 = {13, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x51, 0x20, 0xb, 0x19, 0xa5, 0x64, 0xb7, 0xfe, 0x4, 0x77, 0xe0}; + lwmqtt_string_t topic_filter_s8 = {11, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x4e, 0x1b, 0x61, 0x31, 0xcb, 0x6a, 0x38, 0xe6, 0x4, 0xa0, + 0x71, 0x2c, 0x94, 0xef, 0x70, 0xe1, 0x52, 0x54, 0x15}; + lwmqtt_string_t topic_filter_s9 = {19, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + lwmqtt_sub_options_t sub_opts[10]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS0; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS2; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS1; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + sub_opts[9].qos = LWMQTT_QOS0; + sub_opts[9].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[9].retain_as_published = false; + sub_opts[9].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 30435, 10, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 2083 +// [("\168\136\255:\130\SUB\133;\147<\234\247\227\169\216d\131:D\219\GS\190\200O2\203\149\212",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\219\203o\224\154\&9\229\144\a\219e\152\161\219hhF\236O\129\192h\ETXY\148\&9\150\204.\250",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS1})] [] +TEST(Subscribe311QCTest, Encode2) { + uint8_t pkt[] = {0x82, 0x42, 0x8, 0x23, 0x0, 0x1c, 0xa8, 0x88, 0xff, 0x3a, 0x82, 0x1a, 0x85, 0x3b, 0x93, 0x3c, 0xea, + 0xf7, 0xe3, 0xa9, 0xd8, 0x64, 0x83, 0x3a, 0x44, 0xdb, 0x1d, 0xbe, 0xc8, 0x4f, 0x32, 0xcb, 0x95, 0xd4, + 0x0, 0x0, 0x1e, 0xdb, 0xcb, 0x6f, 0xe0, 0x9a, 0x39, 0xe5, 0x90, 0x7, 0xdb, 0x65, 0x98, 0xa1, 0xdb, + 0x68, 0x68, 0x46, 0xec, 0x4f, 0x81, 0xc0, 0x68, 0x3, 0x59, 0x94, 0x39, 0x96, 0xcc, 0x2e, 0xfa, 0x1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[2]; + uint8_t topic_filter_s0_bytes[] = {0xa8, 0x88, 0xff, 0x3a, 0x82, 0x1a, 0x85, 0x3b, 0x93, 0x3c, + 0xea, 0xf7, 0xe3, 0xa9, 0xd8, 0x64, 0x83, 0x3a, 0x44, 0xdb, + 0x1d, 0xbe, 0xc8, 0x4f, 0x32, 0xcb, 0x95, 0xd4}; + lwmqtt_string_t topic_filter_s0 = {28, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xdb, 0xcb, 0x6f, 0xe0, 0x9a, 0x39, 0xe5, 0x90, 0x7, 0xdb, + 0x65, 0x98, 0xa1, 0xdb, 0x68, 0x68, 0x46, 0xec, 0x4f, 0x81, + 0xc0, 0x68, 0x3, 0x59, 0x94, 0x39, 0x96, 0xcc, 0x2e, 0xfa}; + lwmqtt_string_t topic_filter_s1 = {30, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + lwmqtt_sub_options_t sub_opts[2]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 2083, 2, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 7451 [("^\181\143}(\238\228\"\243)\\U\DEL\166\161 \193\176\226P\219\EOT\253\191",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("!g\t\b\193\GS\FS\188!\172",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS1}),("D2>\192%7\NUL54",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\172D\201\155j\142)Wc\150\143Cc\217\220\253\GS\238m\161\\f",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1})] [] +TEST(Subscribe311QCTest, Encode3) { + uint8_t pkt[] = {0x82, 0x4f, 0x1d, 0x1b, 0x0, 0x18, 0x5e, 0xb5, 0x8f, 0x7d, 0x28, 0xee, 0xe4, 0x22, 0xf3, 0x29, 0x5c, + 0x55, 0x7f, 0xa6, 0xa1, 0x20, 0xc1, 0xb0, 0xe2, 0x50, 0xdb, 0x4, 0xfd, 0xbf, 0x0, 0x0, 0xa, 0x21, + 0x67, 0x9, 0x8, 0xc1, 0x1d, 0x1c, 0xbc, 0x21, 0xac, 0x1, 0x0, 0x9, 0x44, 0x32, 0x3e, 0xc0, 0x25, + 0x37, 0x0, 0x35, 0x34, 0x0, 0x0, 0x16, 0xac, 0x44, 0xc9, 0x9b, 0x6a, 0x8e, 0x29, 0x57, 0x63, 0x96, + 0x8f, 0x43, 0x63, 0xd9, 0xdc, 0xfd, 0x1d, 0xee, 0x6d, 0xa1, 0x5c, 0x66, 0x1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[4]; + uint8_t topic_filter_s0_bytes[] = {0x5e, 0xb5, 0x8f, 0x7d, 0x28, 0xee, 0xe4, 0x22, 0xf3, 0x29, 0x5c, 0x55, + 0x7f, 0xa6, 0xa1, 0x20, 0xc1, 0xb0, 0xe2, 0x50, 0xdb, 0x4, 0xfd, 0xbf}; + lwmqtt_string_t topic_filter_s0 = {24, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x21, 0x67, 0x9, 0x8, 0xc1, 0x1d, 0x1c, 0xbc, 0x21, 0xac}; + lwmqtt_string_t topic_filter_s1 = {10, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x44, 0x32, 0x3e, 0xc0, 0x25, 0x37, 0x0, 0x35, 0x34}; + lwmqtt_string_t topic_filter_s2 = {9, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xac, 0x44, 0xc9, 0x9b, 0x6a, 0x8e, 0x29, 0x57, 0x63, 0x96, 0x8f, + 0x43, 0x63, 0xd9, 0xdc, 0xfd, 0x1d, 0xee, 0x6d, 0xa1, 0x5c, 0x66}; + lwmqtt_string_t topic_filter_s3 = {22, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + lwmqtt_sub_options_t sub_opts[4]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 7451, 4, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 12482 [("\240\185\219h?\152\186\bA)\215<\169\164\"\193cb\ENQA\175\150%\240PA\255\238",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\191=\159\232\202\226?4",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal +// = False, _subQoS = QoS2}),("E\132\197l\158",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// False, _noLocal = False, _subQoS = QoS1}),("\241\167y\214\226%\t\ETBii\EM\DEL\170\&4g\168",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\241\224o\202\161\218\237%\226a\207.\254\DC2\153\232\150,\214\&4\f\"\137Q\190\n#Y",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\DC4\240C\b\241\141\151\128\ACK\RSY\\\DLE%",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS0}),("\NULMD\CAN\134\155\213\216\137",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\235v\226a\SOHS\196\195R\194,\230\195lcY\213m\211\GS\239\r",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("\177\202\DC4\217\183\255t@4q\RS\194uK",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode4) { + uint8_t pkt[] = {0x82, 0xad, 0x1, 0x30, 0xc2, 0x0, 0x1c, 0xf0, 0xb9, 0xdb, 0x68, 0x3f, 0x98, 0xba, 0x8, 0x41, + 0x29, 0xd7, 0x3c, 0xa9, 0xa4, 0x22, 0xc1, 0x63, 0x62, 0x5, 0x41, 0xaf, 0x96, 0x25, 0xf0, 0x50, + 0x41, 0xff, 0xee, 0x2, 0x0, 0x8, 0xbf, 0x3d, 0x9f, 0xe8, 0xca, 0xe2, 0x3f, 0x34, 0x2, 0x0, + 0x5, 0x45, 0x84, 0xc5, 0x6c, 0x9e, 0x1, 0x0, 0x10, 0xf1, 0xa7, 0x79, 0xd6, 0xe2, 0x25, 0x9, + 0x17, 0x69, 0x69, 0x19, 0x7f, 0xaa, 0x34, 0x67, 0xa8, 0x2, 0x0, 0x1c, 0xf1, 0xe0, 0x6f, 0xca, + 0xa1, 0xda, 0xed, 0x25, 0xe2, 0x61, 0xcf, 0x2e, 0xfe, 0x12, 0x99, 0xe8, 0x96, 0x2c, 0xd6, 0x34, + 0xc, 0x22, 0x89, 0x51, 0xbe, 0xa, 0x23, 0x59, 0x2, 0x0, 0xe, 0x14, 0xf0, 0x43, 0x8, 0xf1, + 0x8d, 0x97, 0x80, 0x6, 0x1e, 0x59, 0x5c, 0x10, 0x25, 0x0, 0x0, 0x9, 0x0, 0x4d, 0x44, 0x18, + 0x86, 0x9b, 0xd5, 0xd8, 0x89, 0x2, 0x0, 0x16, 0xeb, 0x76, 0xe2, 0x61, 0x1, 0x53, 0xc4, 0xc3, + 0x52, 0xc2, 0x2c, 0xe6, 0xc3, 0x6c, 0x63, 0x59, 0xd5, 0x6d, 0xd3, 0x1d, 0xef, 0xd, 0x2, 0x0, + 0xe, 0xb1, 0xca, 0x14, 0xd9, 0xb7, 0xff, 0x74, 0x40, 0x34, 0x71, 0x1e, 0xc2, 0x75, 0x4b, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[9]; + uint8_t topic_filter_s0_bytes[] = {0xf0, 0xb9, 0xdb, 0x68, 0x3f, 0x98, 0xba, 0x8, 0x41, 0x29, + 0xd7, 0x3c, 0xa9, 0xa4, 0x22, 0xc1, 0x63, 0x62, 0x5, 0x41, + 0xaf, 0x96, 0x25, 0xf0, 0x50, 0x41, 0xff, 0xee}; + lwmqtt_string_t topic_filter_s0 = {28, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xbf, 0x3d, 0x9f, 0xe8, 0xca, 0xe2, 0x3f, 0x34}; + lwmqtt_string_t topic_filter_s1 = {8, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x45, 0x84, 0xc5, 0x6c, 0x9e}; + lwmqtt_string_t topic_filter_s2 = {5, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xf1, 0xa7, 0x79, 0xd6, 0xe2, 0x25, 0x9, 0x17, + 0x69, 0x69, 0x19, 0x7f, 0xaa, 0x34, 0x67, 0xa8}; + lwmqtt_string_t topic_filter_s3 = {16, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xf1, 0xe0, 0x6f, 0xca, 0xa1, 0xda, 0xed, 0x25, 0xe2, 0x61, + 0xcf, 0x2e, 0xfe, 0x12, 0x99, 0xe8, 0x96, 0x2c, 0xd6, 0x34, + 0xc, 0x22, 0x89, 0x51, 0xbe, 0xa, 0x23, 0x59}; + lwmqtt_string_t topic_filter_s4 = {28, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x14, 0xf0, 0x43, 0x8, 0xf1, 0x8d, 0x97, 0x80, 0x6, 0x1e, 0x59, 0x5c, 0x10, 0x25}; + lwmqtt_string_t topic_filter_s5 = {14, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x0, 0x4d, 0x44, 0x18, 0x86, 0x9b, 0xd5, 0xd8, 0x89}; + lwmqtt_string_t topic_filter_s6 = {9, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xeb, 0x76, 0xe2, 0x61, 0x1, 0x53, 0xc4, 0xc3, 0x52, 0xc2, 0x2c, + 0xe6, 0xc3, 0x6c, 0x63, 0x59, 0xd5, 0x6d, 0xd3, 0x1d, 0xef, 0xd}; + lwmqtt_string_t topic_filter_s7 = {22, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xb1, 0xca, 0x14, 0xd9, 0xb7, 0xff, 0x74, + 0x40, 0x34, 0x71, 0x1e, 0xc2, 0x75, 0x4b}; + lwmqtt_string_t topic_filter_s8 = {14, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + lwmqtt_sub_options_t sub_opts[9]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS2; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS2; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS2; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS0; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 12482, 9, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 30449 [("",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = +// False, _subQoS = QoS2}),("\141\164\198",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS1}),("n\154\FS\SOH\163",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("%+\\\SOH\ETX\139g?h",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\233\208\172\204\212\234\ETXYP\192\163\217x\DC2\154\144\143@1\240\206\161\250",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("-\143",SubOptions {_retainHandling +// = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode5) { + uint8_t pkt[] = { + 0x82, 0xa8, 0x1, 0x76, 0xf1, 0x0, 0x0, 0x2, 0x0, 0x3, 0x8d, 0xa4, 0xc6, 0x1, 0x0, 0x5, 0x6e, 0x9a, 0x1c, + 0x1, 0xa3, 0x1, 0x0, 0x9, 0x25, 0x2b, 0x5c, 0x1, 0x3, 0x8b, 0x67, 0x3f, 0x68, 0x0, 0x0, 0x1e, 0xe9, 0xd0, + 0xac, 0xcc, 0xd4, 0xea, 0x3, 0x59, 0x50, 0xc0, 0xa3, 0xd9, 0x78, 0x12, 0x9a, 0x90, 0x8f, 0x40, 0x31, 0xf0, 0xce, + 0x3c, 0x43, 0x8b, 0xe9, 0x34, 0x82, 0x31, 0x84, 0xe9, 0x0, 0x0, 0x4, 0x40, 0xf8, 0x55, 0x8e, 0x0, 0x0, 0x1b, + 0x63, 0x26, 0x59, 0x37, 0x8f, 0x2e, 0x93, 0x54, 0x4c, 0x98, 0xa8, 0x9c, 0xb0, 0x4b, 0xce, 0x40, 0x26, 0xf9, 0xf7, + 0xd8, 0x13, 0x55, 0x3, 0x1a, 0xfc, 0x40, 0x57, 0x1, 0x0, 0x3, 0x60, 0x90, 0x37, 0x0, 0x0, 0x1a, 0x1f, 0xcb, + 0x76, 0xd4, 0x8f, 0xb7, 0x17, 0xdb, 0x4b, 0xbd, 0x1e, 0xe8, 0xc9, 0x44, 0x60, 0x7, 0x21, 0xf, 0xc8, 0xfe, 0x6, + 0x59, 0x1e, 0xb7, 0x7c, 0x4d, 0x2, 0x0, 0x18, 0x5b, 0xe, 0xf2, 0xb7, 0x96, 0xdc, 0xe2, 0x8f, 0x15, 0xa1, 0x11, + 0x6a, 0xaf, 0xdd, 0xf0, 0x70, 0x3a, 0x9a, 0x3b, 0x68, 0x5e, 0x3e, 0xa1, 0xfa, 0x2, 0x0, 0x2, 0x2d, 0x8f, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0}; + lwmqtt_string_t topic_filter_s0 = {0, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x8d, 0xa4, 0xc6}; + lwmqtt_string_t topic_filter_s1 = {3, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x6e, 0x9a, 0x1c, 0x1, 0xa3}; + lwmqtt_string_t topic_filter_s2 = {5, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x25, 0x2b, 0x5c, 0x1, 0x3, 0x8b, 0x67, 0x3f, 0x68}; + lwmqtt_string_t topic_filter_s3 = {9, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xe9, 0xd0, 0xac, 0xcc, 0xd4, 0xea, 0x3, 0x59, 0x50, 0xc0, + 0xa3, 0xd9, 0x78, 0x12, 0x9a, 0x90, 0x8f, 0x40, 0x31, 0xf0, + 0xce, 0x3c, 0x43, 0x8b, 0xe9, 0x34, 0x82, 0x31, 0x84, 0xe9}; + lwmqtt_string_t topic_filter_s4 = {30, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x40, 0xf8, 0x55, 0x8e}; + lwmqtt_string_t topic_filter_s5 = {4, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x63, 0x26, 0x59, 0x37, 0x8f, 0x2e, 0x93, 0x54, 0x4c, 0x98, 0xa8, 0x9c, 0xb0, 0x4b, + 0xce, 0x40, 0x26, 0xf9, 0xf7, 0xd8, 0x13, 0x55, 0x3, 0x1a, 0xfc, 0x40, 0x57}; + lwmqtt_string_t topic_filter_s6 = {27, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x60, 0x90, 0x37}; + lwmqtt_string_t topic_filter_s7 = {3, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x1f, 0xcb, 0x76, 0xd4, 0x8f, 0xb7, 0x17, 0xdb, 0x4b, 0xbd, 0x1e, 0xe8, 0xc9, + 0x44, 0x60, 0x7, 0x21, 0xf, 0xc8, 0xfe, 0x6, 0x59, 0x1e, 0xb7, 0x7c, 0x4d}; + lwmqtt_string_t topic_filter_s8 = {26, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x5b, 0xe, 0xf2, 0xb7, 0x96, 0xdc, 0xe2, 0x8f, 0x15, 0xa1, 0x11, 0x6a, + 0xaf, 0xdd, 0xf0, 0x70, 0x3a, 0x9a, 0x3b, 0x68, 0x5e, 0x3e, 0xa1, 0xfa}; + lwmqtt_string_t topic_filter_s9 = {24, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0x2d, 0x8f}; + lwmqtt_string_t topic_filter_s10 = {2, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + lwmqtt_sub_options_t sub_opts[11]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS0; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS1; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS0; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS2; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + sub_opts[9].qos = LWMQTT_QOS2; + sub_opts[9].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[9].retain_as_published = false; + sub_opts[9].no_local = false; + sub_opts[10].qos = LWMQTT_QOS0; + sub_opts[10].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[10].retain_as_published = false; + sub_opts[10].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 30449, 11, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 32182 [("\FS\DC3\128\252X\ETX\252\165T{QD\211\165q\226\248\251q\206\169A",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS1})] [] +TEST(Subscribe311QCTest, Encode6) { + uint8_t pkt[] = {0x82, 0x1b, 0x7d, 0xb6, 0x0, 0x16, 0x1c, 0x13, 0x80, 0xfc, 0x58, 0x3, 0xfc, 0xa5, 0x54, + 0x7b, 0x51, 0x44, 0xd3, 0xa5, 0x71, 0xe2, 0xf8, 0xfb, 0x71, 0xce, 0xa9, 0x41, 0x1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x1c, 0x13, 0x80, 0xfc, 0x58, 0x3, 0xfc, 0xa5, 0x54, 0x7b, 0x51, + 0x44, 0xd3, 0xa5, 0x71, 0xe2, 0xf8, 0xfb, 0x71, 0xce, 0xa9, 0x41}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + lwmqtt_sub_options_t sub_opts[1]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 32182, 1, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 318 [("J\EM\RS\185P\242\251\199\SI\NAKzfK\180\a\175(t\FS\178N\EM",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),(".y\253\aln\145\149/\203\DLE\135\254_\241\215\231:\192\163",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("\251\175[\171\nR\197",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\153\f\DEL0\187\236\132%Lyr\231\f\135\134Mr(f\246",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\173t\NUL)\205\182\DC3\CAN\230V\227e\230\128?\177\&1\179V",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS0}),("\247\129\193tL",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [] +TEST(Subscribe311QCTest, Encode7) { + uint8_t pkt[] = {0x82, 0x71, 0x1, 0x3e, 0x0, 0x16, 0x4a, 0x19, 0x1e, 0xb9, 0x50, 0xf2, 0xfb, 0xc7, 0xf, 0x15, 0x7a, + 0x66, 0x4b, 0xb4, 0x7, 0xaf, 0x28, 0x74, 0x1c, 0xb2, 0x4e, 0x19, 0x2, 0x0, 0x14, 0x2e, 0x79, 0xfd, + 0x7, 0x6c, 0x6e, 0x91, 0x95, 0x2f, 0xcb, 0x10, 0x87, 0xfe, 0x5f, 0xf1, 0xd7, 0xe7, 0x3a, 0xc0, 0xa3, + 0x1, 0x0, 0x7, 0xfb, 0xaf, 0x5b, 0xab, 0xa, 0x52, 0xc5, 0x0, 0x0, 0x14, 0x99, 0xc, 0x7f, 0x30, + 0xbb, 0xec, 0x84, 0x25, 0x4c, 0x79, 0x72, 0xe7, 0xc, 0x87, 0x86, 0x4d, 0x72, 0x28, 0x66, 0xf6, 0x1, + 0x0, 0x13, 0xad, 0x74, 0x0, 0x29, 0xcd, 0xb6, 0x13, 0x18, 0xe6, 0x56, 0xe3, 0x65, 0xe6, 0x80, 0x3f, + 0xb1, 0x31, 0xb3, 0x56, 0x0, 0x0, 0x5, 0xf7, 0x81, 0xc1, 0x74, 0x4c, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[6]; + uint8_t topic_filter_s0_bytes[] = {0x4a, 0x19, 0x1e, 0xb9, 0x50, 0xf2, 0xfb, 0xc7, 0xf, 0x15, 0x7a, + 0x66, 0x4b, 0xb4, 0x7, 0xaf, 0x28, 0x74, 0x1c, 0xb2, 0x4e, 0x19}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x2e, 0x79, 0xfd, 0x7, 0x6c, 0x6e, 0x91, 0x95, 0x2f, 0xcb, + 0x10, 0x87, 0xfe, 0x5f, 0xf1, 0xd7, 0xe7, 0x3a, 0xc0, 0xa3}; + lwmqtt_string_t topic_filter_s1 = {20, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xfb, 0xaf, 0x5b, 0xab, 0xa, 0x52, 0xc5}; + lwmqtt_string_t topic_filter_s2 = {7, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x99, 0xc, 0x7f, 0x30, 0xbb, 0xec, 0x84, 0x25, 0x4c, 0x79, + 0x72, 0xe7, 0xc, 0x87, 0x86, 0x4d, 0x72, 0x28, 0x66, 0xf6}; + lwmqtt_string_t topic_filter_s3 = {20, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xad, 0x74, 0x0, 0x29, 0xcd, 0xb6, 0x13, 0x18, 0xe6, 0x56, + 0xe3, 0x65, 0xe6, 0x80, 0x3f, 0xb1, 0x31, 0xb3, 0x56}; + lwmqtt_string_t topic_filter_s4 = {19, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xf7, 0x81, 0xc1, 0x74, 0x4c}; + lwmqtt_string_t topic_filter_s5 = {5, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + lwmqtt_sub_options_t sub_opts[6]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS0; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS2; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 318, 6, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 31558 [("\186\232\r\SYN\DC4\129Eu\DC1]\160\174]",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("]\SO]\180\174O'\150\129\199\150\128\136B\133\198\140\191\138\FS\ETBvk\239\243",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\a0\ACKvKF\251\218J\SUB\ESC\215\200\147\192\231\206\193",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\196\254\198\168\156\215a\242s\210\168\234u\178\ESC\254\160U\214_4U\230&\184\226\GS\156",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode8) { + uint8_t pkt[] = {0x82, 0x62, 0x7b, 0x46, 0x0, 0xd, 0xba, 0xe8, 0xd, 0x16, 0x14, 0x81, 0x45, 0x75, 0x11, 0x5d, 0xa0, + 0xae, 0x5d, 0x0, 0x0, 0x19, 0x5d, 0xe, 0x5d, 0xb4, 0xae, 0x4f, 0x27, 0x96, 0x81, 0xc7, 0x96, 0x80, + 0x88, 0x42, 0x85, 0xc6, 0x8c, 0xbf, 0x8a, 0x1c, 0x17, 0x76, 0x6b, 0xef, 0xf3, 0x2, 0x0, 0x12, 0x7, + 0x30, 0x6, 0x76, 0x4b, 0x46, 0xfb, 0xda, 0x4a, 0x1a, 0x1b, 0xd7, 0xc8, 0x93, 0xc0, 0xe7, 0xce, 0xc1, + 0x2, 0x0, 0x1c, 0xc4, 0xfe, 0xc6, 0xa8, 0x9c, 0xd7, 0x61, 0xf2, 0x73, 0xd2, 0xa8, 0xea, 0x75, 0xb2, + 0x1b, 0xfe, 0xa0, 0x55, 0xd6, 0x5f, 0x34, 0x55, 0xe6, 0x26, 0xb8, 0xe2, 0x1d, 0x9c, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[4]; + uint8_t topic_filter_s0_bytes[] = {0xba, 0xe8, 0xd, 0x16, 0x14, 0x81, 0x45, 0x75, 0x11, 0x5d, 0xa0, 0xae, 0x5d}; + lwmqtt_string_t topic_filter_s0 = {13, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x5d, 0xe, 0x5d, 0xb4, 0xae, 0x4f, 0x27, 0x96, 0x81, 0xc7, 0x96, 0x80, 0x88, + 0x42, 0x85, 0xc6, 0x8c, 0xbf, 0x8a, 0x1c, 0x17, 0x76, 0x6b, 0xef, 0xf3}; + lwmqtt_string_t topic_filter_s1 = {25, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x7, 0x30, 0x6, 0x76, 0x4b, 0x46, 0xfb, 0xda, 0x4a, + 0x1a, 0x1b, 0xd7, 0xc8, 0x93, 0xc0, 0xe7, 0xce, 0xc1}; + lwmqtt_string_t topic_filter_s2 = {18, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xc4, 0xfe, 0xc6, 0xa8, 0x9c, 0xd7, 0x61, 0xf2, 0x73, 0xd2, + 0xa8, 0xea, 0x75, 0xb2, 0x1b, 0xfe, 0xa0, 0x55, 0xd6, 0x5f, + 0x34, 0x55, 0xe6, 0x26, 0xb8, 0xe2, 0x1d, 0x9c}; + lwmqtt_string_t topic_filter_s3 = {28, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + lwmqtt_sub_options_t sub_opts[4]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 31558, 4, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 10059 [("cF\140\DC1z\250\a\232\178\255\221\154\NUL\134\244",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\172J\178\137\215\158\178n\196\166\\$a\"\143GH\CANW\134Se\bs\162z\153\v",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\146\169\&0\151\152\139\133\211\188\241\SUB\DC2N)\139\165\150",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("\243\168\&6\166",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("G\245\200\151Cv\222\205\151\133\243",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// False, _noLocal = False, _subQoS = QoS1}),("\135oO\NUL\183j-",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("Y;d\189L\226\200\163\134\156\180\242\218(\DC4\254\238\144 ",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1})] [] +TEST(Subscribe311QCTest, Encode9) { + uint8_t pkt[] = {0x82, 0x7c, 0x27, 0x4b, 0x0, 0xf, 0x63, 0x46, 0x8c, 0x11, 0x7a, 0xfa, 0x7, 0xe8, 0xb2, 0xff, + 0xdd, 0x9a, 0x0, 0x86, 0xf4, 0x1, 0x0, 0x1c, 0xac, 0x4a, 0xb2, 0x89, 0xd7, 0x9e, 0xb2, 0x6e, + 0xc4, 0xa6, 0x5c, 0x24, 0x61, 0x22, 0x8f, 0x47, 0x48, 0x18, 0x57, 0x86, 0x53, 0x65, 0x8, 0x73, + 0xa2, 0x7a, 0x99, 0xb, 0x0, 0x0, 0x11, 0x92, 0xa9, 0x30, 0x97, 0x98, 0x8b, 0x85, 0xd3, 0xbc, + 0xf1, 0x1a, 0x12, 0x4e, 0x29, 0x8b, 0xa5, 0x96, 0x2, 0x0, 0x4, 0xf3, 0xa8, 0x36, 0xa6, 0x1, + 0x0, 0xb, 0x47, 0xf5, 0xc8, 0x97, 0x43, 0x76, 0xde, 0xcd, 0x97, 0x85, 0xf3, 0x1, 0x0, 0x7, + 0x87, 0x6f, 0x4f, 0x0, 0xb7, 0x6a, 0x2d, 0x2, 0x0, 0x13, 0x59, 0x3b, 0x64, 0xbd, 0x4c, 0xe2, + 0xc8, 0xa3, 0x86, 0x9c, 0xb4, 0xf2, 0xda, 0x28, 0x14, 0xfe, 0xee, 0x90, 0x20, 0x1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0x63, 0x46, 0x8c, 0x11, 0x7a, 0xfa, 0x7, 0xe8, + 0xb2, 0xff, 0xdd, 0x9a, 0x0, 0x86, 0xf4}; + lwmqtt_string_t topic_filter_s0 = {15, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xac, 0x4a, 0xb2, 0x89, 0xd7, 0x9e, 0xb2, 0x6e, 0xc4, 0xa6, 0x5c, 0x24, 0x61, 0x22, + 0x8f, 0x47, 0x48, 0x18, 0x57, 0x86, 0x53, 0x65, 0x8, 0x73, 0xa2, 0x7a, 0x99, 0xb}; + lwmqtt_string_t topic_filter_s1 = {28, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x92, 0xa9, 0x30, 0x97, 0x98, 0x8b, 0x85, 0xd3, 0xbc, + 0xf1, 0x1a, 0x12, 0x4e, 0x29, 0x8b, 0xa5, 0x96}; + lwmqtt_string_t topic_filter_s2 = {17, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xf3, 0xa8, 0x36, 0xa6}; + lwmqtt_string_t topic_filter_s3 = {4, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x47, 0xf5, 0xc8, 0x97, 0x43, 0x76, 0xde, 0xcd, 0x97, 0x85, 0xf3}; + lwmqtt_string_t topic_filter_s4 = {11, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x87, 0x6f, 0x4f, 0x0, 0xb7, 0x6a, 0x2d}; + lwmqtt_string_t topic_filter_s5 = {7, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x59, 0x3b, 0x64, 0xbd, 0x4c, 0xe2, 0xc8, 0xa3, 0x86, 0x9c, + 0xb4, 0xf2, 0xda, 0x28, 0x14, 0xfe, 0xee, 0x90, 0x20}; + lwmqtt_string_t topic_filter_s6 = {19, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + lwmqtt_sub_options_t sub_opts[7]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS0; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS2; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS1; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 10059, 7, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 17993 [("\174\DC2\180\NUL\142x\203\205\&8\EM\171\148\&3tuFu$\128",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0}),("\157\230\179\155\184",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\176\146\RS\217\&9zmS\US\159\223ODO\200>\166\vR",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("\161@\171\&2\220\208\169\DC1\214\171\191",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("Q\129\191)\186o\207\155\&4C\134,A;\188i\194^\"]r",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("]CN4\DEL\254S\162\235\148\193\251\183",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\194c\DC4",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, +// _subQoS = QoS1}),("c\202\169\191\144\165\DC2%\SYN&\SOH\145\184\228\220\227\185]\163T\187D\253\DC2-\169C",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\195\212\131",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, +// _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode10) { + uint8_t pkt[] = {0x82, 0x96, 0x1, 0x46, 0x49, 0x0, 0x13, 0xae, 0x12, 0xb4, 0x0, 0x8e, 0x78, 0xcb, 0xcd, 0x38, 0x19, + 0xab, 0x94, 0x33, 0x74, 0x75, 0x46, 0x75, 0x24, 0x80, 0x0, 0x0, 0x5, 0x9d, 0xe6, 0xb3, 0x9b, 0xb8, + 0x2, 0x0, 0x13, 0xb0, 0x92, 0x1e, 0xd9, 0x39, 0x7a, 0x6d, 0x53, 0x1f, 0x9f, 0xdf, 0x4f, 0x44, 0x4f, + 0xc8, 0x3e, 0xa6, 0xb, 0x52, 0x1, 0x0, 0xb, 0xa1, 0x40, 0xab, 0x32, 0xdc, 0xd0, 0xa9, 0x11, 0xd6, + 0xab, 0xbf, 0x0, 0x0, 0x15, 0x51, 0x81, 0xbf, 0x29, 0xba, 0x6f, 0xcf, 0x9b, 0x34, 0x43, 0x86, 0x2c, + 0x41, 0x3b, 0xbc, 0x69, 0xc2, 0x5e, 0x22, 0x5d, 0x72, 0x2, 0x0, 0xd, 0x5d, 0x43, 0x4e, 0x34, 0x7f, + 0xfe, 0x53, 0xa2, 0xeb, 0x94, 0xc1, 0xfb, 0xb7, 0x2, 0x0, 0x3, 0xc2, 0x63, 0x14, 0x1, 0x0, 0x1b, + 0x63, 0xca, 0xa9, 0xbf, 0x90, 0xa5, 0x12, 0x25, 0x16, 0x26, 0x1, 0x91, 0xb8, 0xe4, 0xdc, 0xe3, 0xb9, + 0x5d, 0xa3, 0x54, 0xbb, 0x44, 0xfd, 0x12, 0x2d, 0xa9, 0x43, 0x1, 0x0, 0x3, 0xc3, 0xd4, 0x83, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[9]; + uint8_t topic_filter_s0_bytes[] = {0xae, 0x12, 0xb4, 0x0, 0x8e, 0x78, 0xcb, 0xcd, 0x38, 0x19, + 0xab, 0x94, 0x33, 0x74, 0x75, 0x46, 0x75, 0x24, 0x80}; + lwmqtt_string_t topic_filter_s0 = {19, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x9d, 0xe6, 0xb3, 0x9b, 0xb8}; + lwmqtt_string_t topic_filter_s1 = {5, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xb0, 0x92, 0x1e, 0xd9, 0x39, 0x7a, 0x6d, 0x53, 0x1f, 0x9f, + 0xdf, 0x4f, 0x44, 0x4f, 0xc8, 0x3e, 0xa6, 0xb, 0x52}; + lwmqtt_string_t topic_filter_s2 = {19, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xa1, 0x40, 0xab, 0x32, 0xdc, 0xd0, 0xa9, 0x11, 0xd6, 0xab, 0xbf}; + lwmqtt_string_t topic_filter_s3 = {11, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x51, 0x81, 0xbf, 0x29, 0xba, 0x6f, 0xcf, 0x9b, 0x34, 0x43, 0x86, + 0x2c, 0x41, 0x3b, 0xbc, 0x69, 0xc2, 0x5e, 0x22, 0x5d, 0x72}; + lwmqtt_string_t topic_filter_s4 = {21, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x5d, 0x43, 0x4e, 0x34, 0x7f, 0xfe, 0x53, 0xa2, 0xeb, 0x94, 0xc1, 0xfb, 0xb7}; + lwmqtt_string_t topic_filter_s5 = {13, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xc2, 0x63, 0x14}; + lwmqtt_string_t topic_filter_s6 = {3, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x63, 0xca, 0xa9, 0xbf, 0x90, 0xa5, 0x12, 0x25, 0x16, 0x26, 0x1, 0x91, 0xb8, 0xe4, + 0xdc, 0xe3, 0xb9, 0x5d, 0xa3, 0x54, 0xbb, 0x44, 0xfd, 0x12, 0x2d, 0xa9, 0x43}; + lwmqtt_string_t topic_filter_s7 = {27, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xc3, 0xd4, 0x83}; + lwmqtt_string_t topic_filter_s8 = {3, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + lwmqtt_sub_options_t sub_opts[9]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS2; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS1; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS1; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS0; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 17993, 9, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 22386 [("\ESC\146\173A\219\151\151\&3\201\142\247A\240\134\172\207$\SO\214\141\&8J\US\n0",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("%\152",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS +// = QoS1}),("\136\CAN\SOH\212\NUL\t\207.",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS0}),("\244\191\194\f?~)r^\197\&8\143^2\137\183\151\164<\SI",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("1\a\ETB\ENQ*\171-\181\195\200\175\177\204.'t\176\205\&1\130",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode11) { + uint8_t pkt[] = {0x82, 0x5c, 0x57, 0x72, 0x0, 0x19, 0x1b, 0x92, 0xad, 0x41, 0xdb, 0x97, 0x97, 0x33, 0xc9, 0x8e, + 0xf7, 0x41, 0xf0, 0x86, 0xac, 0xcf, 0x24, 0xe, 0xd6, 0x8d, 0x38, 0x4a, 0x1f, 0xa, 0x30, 0x2, + 0x0, 0x2, 0x25, 0x98, 0x1, 0x0, 0x8, 0x88, 0x18, 0x1, 0xd4, 0x0, 0x9, 0xcf, 0x2e, 0x0, + 0x0, 0x14, 0xf4, 0xbf, 0xc2, 0xc, 0x3f, 0x7e, 0x29, 0x72, 0x5e, 0xc5, 0x38, 0x8f, 0x5e, 0x32, + 0x89, 0xb7, 0x97, 0xa4, 0x3c, 0xf, 0x2, 0x0, 0x14, 0x31, 0x7, 0x17, 0x5, 0x2a, 0xab, 0x2d, + 0xb5, 0xc3, 0xc8, 0xaf, 0xb1, 0xcc, 0x2e, 0x27, 0x74, 0xb0, 0xcd, 0x31, 0x82, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0x1b, 0x92, 0xad, 0x41, 0xdb, 0x97, 0x97, 0x33, 0xc9, 0x8e, 0xf7, 0x41, 0xf0, + 0x86, 0xac, 0xcf, 0x24, 0xe, 0xd6, 0x8d, 0x38, 0x4a, 0x1f, 0xa, 0x30}; + lwmqtt_string_t topic_filter_s0 = {25, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x25, 0x98}; + lwmqtt_string_t topic_filter_s1 = {2, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x88, 0x18, 0x1, 0xd4, 0x0, 0x9, 0xcf, 0x2e}; + lwmqtt_string_t topic_filter_s2 = {8, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xf4, 0xbf, 0xc2, 0xc, 0x3f, 0x7e, 0x29, 0x72, 0x5e, 0xc5, + 0x38, 0x8f, 0x5e, 0x32, 0x89, 0xb7, 0x97, 0xa4, 0x3c, 0xf}; + lwmqtt_string_t topic_filter_s3 = {20, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x31, 0x7, 0x17, 0x5, 0x2a, 0xab, 0x2d, 0xb5, 0xc3, 0xc8, + 0xaf, 0xb1, 0xcc, 0x2e, 0x27, 0x74, 0xb0, 0xcd, 0x31, 0x82}; + lwmqtt_string_t topic_filter_s4 = {20, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + lwmqtt_sub_options_t sub_opts[5]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS2; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS0; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 22386, 5, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 7096 [("t\181\243\135\224I\128\&4\216~\NAK",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("oi\ETB\249\n\USG<]vF\175@D\"no\DC3\222T\STX\212",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("\167-\197\214G\192r\204",SubOptions {_retainHandling +// = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("\153!\144t",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\ESC\148<\147\252\182o\137\rT\129\180db\204\246\SOG\227f\167",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("\170\134\239w\241\233\GS",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("f2$\160\161\178\217\&0\EM\234&\146\SYN q\167\202\213\236\142\188\152\205\187t\n\237\166",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [] +TEST(Subscribe311QCTest, Encode12) { + uint8_t pkt[] = {0x82, 0x7c, 0x1b, 0xb8, 0x0, 0xb, 0x74, 0xb5, 0xf3, 0x87, 0xe0, 0x49, 0x80, 0x34, 0xd8, 0x7e, + 0x15, 0x0, 0x0, 0x16, 0x6f, 0x69, 0x17, 0xf9, 0xa, 0x1f, 0x47, 0x3c, 0x5d, 0x76, 0x46, 0xaf, + 0x40, 0x44, 0x22, 0x6e, 0x6f, 0x13, 0xde, 0x54, 0x2, 0xd4, 0x1, 0x0, 0x8, 0xa7, 0x2d, 0xc5, + 0xd6, 0x47, 0xc0, 0x72, 0xcc, 0x2, 0x0, 0x4, 0x99, 0x21, 0x90, 0x74, 0x2, 0x0, 0x15, 0x1b, + 0x94, 0x3c, 0x93, 0xfc, 0xb6, 0x6f, 0x89, 0xd, 0x54, 0x81, 0xb4, 0x64, 0x62, 0xcc, 0xf6, 0xe, + 0x47, 0xe3, 0x66, 0xa7, 0x2, 0x0, 0x7, 0xaa, 0x86, 0xef, 0x77, 0xf1, 0xe9, 0x1d, 0x0, 0x0, + 0x1c, 0x66, 0x32, 0x24, 0xa0, 0xa1, 0xb2, 0xd9, 0x30, 0x19, 0xea, 0x26, 0x92, 0x16, 0x20, 0x71, + 0xa7, 0xca, 0xd5, 0xec, 0x8e, 0xbc, 0x98, 0xcd, 0xbb, 0x74, 0xa, 0xed, 0xa6, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0x74, 0xb5, 0xf3, 0x87, 0xe0, 0x49, 0x80, 0x34, 0xd8, 0x7e, 0x15}; + lwmqtt_string_t topic_filter_s0 = {11, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x6f, 0x69, 0x17, 0xf9, 0xa, 0x1f, 0x47, 0x3c, 0x5d, 0x76, 0x46, + 0xaf, 0x40, 0x44, 0x22, 0x6e, 0x6f, 0x13, 0xde, 0x54, 0x2, 0xd4}; + lwmqtt_string_t topic_filter_s1 = {22, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xa7, 0x2d, 0xc5, 0xd6, 0x47, 0xc0, 0x72, 0xcc}; + lwmqtt_string_t topic_filter_s2 = {8, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x99, 0x21, 0x90, 0x74}; + lwmqtt_string_t topic_filter_s3 = {4, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x1b, 0x94, 0x3c, 0x93, 0xfc, 0xb6, 0x6f, 0x89, 0xd, 0x54, 0x81, + 0xb4, 0x64, 0x62, 0xcc, 0xf6, 0xe, 0x47, 0xe3, 0x66, 0xa7}; + lwmqtt_string_t topic_filter_s4 = {21, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xaa, 0x86, 0xef, 0x77, 0xf1, 0xe9, 0x1d}; + lwmqtt_string_t topic_filter_s5 = {7, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x66, 0x32, 0x24, 0xa0, 0xa1, 0xb2, 0xd9, 0x30, 0x19, 0xea, + 0x26, 0x92, 0x16, 0x20, 0x71, 0xa7, 0xca, 0xd5, 0xec, 0x8e, + 0xbc, 0x98, 0xcd, 0xbb, 0x74, 0xa, 0xed, 0xa6}; + lwmqtt_string_t topic_filter_s6 = {28, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + lwmqtt_sub_options_t sub_opts[7]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS2; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS2; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 7096, 7, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 12819 [("\r\ACKA\165\FS\187\vpF\231\155>\162q\nM\192\252\f{\178\b\a@v\131\215\152f",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("Q\231s7H\ENQ#\143o\a\251\STXW\201\177\196{",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("$\142\140\198",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [] +TEST(Subscribe311QCTest, Encode13) { + uint8_t pkt[] = {0x82, 0x3d, 0x32, 0x13, 0x0, 0x1d, 0xd, 0x6, 0x41, 0xa5, 0x1c, 0xbb, 0xb, 0x70, 0x46, 0xe7, + 0x9b, 0x3e, 0xa2, 0x71, 0xa, 0x4d, 0xc0, 0xfc, 0xc, 0x7b, 0xb2, 0x8, 0x7, 0x40, 0x76, 0x83, + 0xd7, 0x98, 0x66, 0x2, 0x0, 0x11, 0x51, 0xe7, 0x73, 0x37, 0x48, 0x5, 0x23, 0x8f, 0x6f, 0x7, + 0xfb, 0x2, 0x57, 0xc9, 0xb1, 0xc4, 0x7b, 0x2, 0x0, 0x4, 0x24, 0x8e, 0x8c, 0xc6, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[3]; + uint8_t topic_filter_s0_bytes[] = {0xd, 0x6, 0x41, 0xa5, 0x1c, 0xbb, 0xb, 0x70, 0x46, 0xe7, + 0x9b, 0x3e, 0xa2, 0x71, 0xa, 0x4d, 0xc0, 0xfc, 0xc, 0x7b, + 0xb2, 0x8, 0x7, 0x40, 0x76, 0x83, 0xd7, 0x98, 0x66}; + lwmqtt_string_t topic_filter_s0 = {29, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x51, 0xe7, 0x73, 0x37, 0x48, 0x5, 0x23, 0x8f, 0x6f, + 0x7, 0xfb, 0x2, 0x57, 0xc9, 0xb1, 0xc4, 0x7b}; + lwmqtt_string_t topic_filter_s1 = {17, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x24, 0x8e, 0x8c, 0xc6}; + lwmqtt_string_t topic_filter_s2 = {4, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + lwmqtt_sub_options_t sub_opts[3]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 12819, 3, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 26406 [("`\aR\230\193\146\183",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// False, _noLocal = False, _subQoS = QoS2}),("\EOT,\142\SOH\170%",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("P\232L\184\219'\fn\160W\t22",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [] +TEST(Subscribe311QCTest, Encode14) { + uint8_t pkt[] = {0x82, 0x25, 0x67, 0x26, 0x0, 0x7, 0x60, 0x7, 0x52, 0xe6, 0xc1, 0x92, 0xb7, + 0x2, 0x0, 0x6, 0x4, 0x2c, 0x8e, 0x1, 0xaa, 0x25, 0x1, 0x0, 0xd, 0x50, + 0xe8, 0x4c, 0xb8, 0xdb, 0x27, 0xc, 0x6e, 0xa0, 0x57, 0x9, 0x32, 0x32, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[3]; + uint8_t topic_filter_s0_bytes[] = {0x60, 0x7, 0x52, 0xe6, 0xc1, 0x92, 0xb7}; + lwmqtt_string_t topic_filter_s0 = {7, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x4, 0x2c, 0x8e, 0x1, 0xaa, 0x25}; + lwmqtt_string_t topic_filter_s1 = {6, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x50, 0xe8, 0x4c, 0xb8, 0xdb, 0x27, 0xc, 0x6e, 0xa0, 0x57, 0x9, 0x32, 0x32}; + lwmqtt_string_t topic_filter_s2 = {13, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + lwmqtt_sub_options_t sub_opts[3]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 26406, 3, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 13914 [("\198\167\141tI\138S\169\224\226\US\159\SIty",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("1\181Xv\ACK\149\214\232z\136\EOT)\197\DLE\245\&5-\FSK~\SUBO\228\ENQ>1",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\163\252\EOT\234\173\180\EM\\O\240\GS)\232\252=\DC3\152",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [] +TEST(Subscribe311QCTest, Encode15) { + uint8_t pkt[] = {0x82, 0x45, 0x36, 0x5a, 0x0, 0xf, 0xc6, 0xa7, 0x8d, 0x74, 0x49, 0x8a, 0x53, 0xa9, 0xe0, + 0xe2, 0x1f, 0x9f, 0xf, 0x74, 0x79, 0x2, 0x0, 0x1a, 0x31, 0xb5, 0x58, 0x76, 0x6, 0x95, + 0xd6, 0xe8, 0x7a, 0x88, 0x4, 0x29, 0xc5, 0x10, 0xf5, 0x35, 0x2d, 0x1c, 0x4b, 0x7e, 0x1a, + 0x4f, 0xe4, 0x5, 0x3e, 0x31, 0x1, 0x0, 0x11, 0xa3, 0xfc, 0x4, 0xea, 0xad, 0xb4, 0x19, + 0x5c, 0x4f, 0xf0, 0x1d, 0x29, 0xe8, 0xfc, 0x3d, 0x13, 0x98, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[3]; + uint8_t topic_filter_s0_bytes[] = {0xc6, 0xa7, 0x8d, 0x74, 0x49, 0x8a, 0x53, 0xa9, + 0xe0, 0xe2, 0x1f, 0x9f, 0xf, 0x74, 0x79}; + lwmqtt_string_t topic_filter_s0 = {15, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x31, 0xb5, 0x58, 0x76, 0x6, 0x95, 0xd6, 0xe8, 0x7a, 0x88, 0x4, 0x29, 0xc5, + 0x10, 0xf5, 0x35, 0x2d, 0x1c, 0x4b, 0x7e, 0x1a, 0x4f, 0xe4, 0x5, 0x3e, 0x31}; + lwmqtt_string_t topic_filter_s1 = {26, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xa3, 0xfc, 0x4, 0xea, 0xad, 0xb4, 0x19, 0x5c, 0x4f, + 0xf0, 0x1d, 0x29, 0xe8, 0xfc, 0x3d, 0x13, 0x98}; + lwmqtt_string_t topic_filter_s2 = {17, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + lwmqtt_sub_options_t sub_opts[3]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 13914, 3, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 2905 [("\158\194\134\209\SOH \176^\221\235\147\182\230\226\157\a\STX\215",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\STX\165?\213\"\ETX@\DC4\ENQ\178\ACKjo\156",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("\171sk",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\171\167\154\213\250eT\\\165\US\US@\174",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// False, _noLocal = False, _subQoS = QoS1}),("\144O\186\216\f'gm{BI",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\GS]\244\240/\177\178.\246\143\SI-\226j\165\SOH\233",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [] +TEST(Subscribe311QCTest, Encode16) { + uint8_t pkt[] = {0x82, 0x60, 0xb, 0x59, 0x0, 0x12, 0x9e, 0xc2, 0x86, 0xd1, 0x1, 0x20, 0xb0, 0x5e, 0xdd, 0xeb, 0x93, + 0xb6, 0xe6, 0xe2, 0x9d, 0x7, 0x2, 0xd7, 0x2, 0x0, 0xe, 0x2, 0xa5, 0x3f, 0xd5, 0x22, 0x3, 0x40, + 0x14, 0x5, 0xb2, 0x6, 0x6a, 0x6f, 0x9c, 0x1, 0x0, 0x3, 0xab, 0x73, 0x6b, 0x0, 0x0, 0xd, 0xab, + 0xa7, 0x9a, 0xd5, 0xfa, 0x65, 0x54, 0x5c, 0xa5, 0x1f, 0x1f, 0x40, 0xae, 0x1, 0x0, 0xb, 0x90, 0x4f, + 0xba, 0xd8, 0xc, 0x27, 0x67, 0x6d, 0x7b, 0x42, 0x49, 0x0, 0x0, 0x11, 0x1d, 0x5d, 0xf4, 0xf0, 0x2f, + 0xb1, 0xb2, 0x2e, 0xf6, 0x8f, 0xf, 0x2d, 0xe2, 0x6a, 0xa5, 0x1, 0xe9, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[6]; + uint8_t topic_filter_s0_bytes[] = {0x9e, 0xc2, 0x86, 0xd1, 0x1, 0x20, 0xb0, 0x5e, 0xdd, + 0xeb, 0x93, 0xb6, 0xe6, 0xe2, 0x9d, 0x7, 0x2, 0xd7}; + lwmqtt_string_t topic_filter_s0 = {18, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x2, 0xa5, 0x3f, 0xd5, 0x22, 0x3, 0x40, 0x14, 0x5, 0xb2, 0x6, 0x6a, 0x6f, 0x9c}; + lwmqtt_string_t topic_filter_s1 = {14, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xab, 0x73, 0x6b}; + lwmqtt_string_t topic_filter_s2 = {3, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xab, 0xa7, 0x9a, 0xd5, 0xfa, 0x65, 0x54, 0x5c, 0xa5, 0x1f, 0x1f, 0x40, 0xae}; + lwmqtt_string_t topic_filter_s3 = {13, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x90, 0x4f, 0xba, 0xd8, 0xc, 0x27, 0x67, 0x6d, 0x7b, 0x42, 0x49}; + lwmqtt_string_t topic_filter_s4 = {11, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x1d, 0x5d, 0xf4, 0xf0, 0x2f, 0xb1, 0xb2, 0x2e, 0xf6, + 0x8f, 0xf, 0x2d, 0xe2, 0x6a, 0xa5, 0x1, 0xe9}; + lwmqtt_string_t topic_filter_s5 = {17, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + lwmqtt_sub_options_t sub_opts[6]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS0; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS2; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 2905, 6, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 10689 [("\199\210\220",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS0}),("7\161c\189=\151\t\191\238\214\221\130]\254\133\170S",SubOptions {_retainHandling +// = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\207\&0\141\ETB\132\255\137\214\191x\233o\247\ACK\248\177",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("7\137\ETB\205\231s\136!\DC3B\DC1\151T\175\132\DLE[w\159r\162Tp\145\ENQ",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\177\136\US\209\US\188\SOg\EOTe\246CY^`\DEL3\143\ESC\EOTgMo\253\248\236\RSa*&",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [] +TEST(Subscribe311QCTest, Encode17) { + uint8_t pkt[] = {0x82, 0x6c, 0x29, 0xc1, 0x0, 0x3, 0xc7, 0xd2, 0xdc, 0x0, 0x0, 0x11, 0x37, 0xa1, 0x63, 0xbd, + 0x3d, 0x97, 0x9, 0xbf, 0xee, 0xd6, 0xdd, 0x82, 0x5d, 0xfe, 0x85, 0xaa, 0x53, 0x0, 0x0, 0x10, + 0xcf, 0x30, 0x8d, 0x17, 0x84, 0xff, 0x89, 0xd6, 0xbf, 0x78, 0xe9, 0x6f, 0xf7, 0x6, 0xf8, 0xb1, + 0x2, 0x0, 0x19, 0x37, 0x89, 0x17, 0xcd, 0xe7, 0x73, 0x88, 0x21, 0x13, 0x42, 0x11, 0x97, 0x54, + 0xaf, 0x84, 0x10, 0x5b, 0x77, 0x9f, 0x72, 0xa2, 0x54, 0x70, 0x91, 0x5, 0x0, 0x0, 0x1e, 0xb1, + 0x88, 0x1f, 0xd1, 0x1f, 0xbc, 0xe, 0x67, 0x4, 0x65, 0xf6, 0x43, 0x59, 0x5e, 0x60, 0x7f, 0x33, + 0x8f, 0x1b, 0x4, 0x67, 0x4d, 0x6f, 0xfd, 0xf8, 0xec, 0x1e, 0x61, 0x2a, 0x26, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0xc7, 0xd2, 0xdc}; + lwmqtt_string_t topic_filter_s0 = {3, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x37, 0xa1, 0x63, 0xbd, 0x3d, 0x97, 0x9, 0xbf, 0xee, + 0xd6, 0xdd, 0x82, 0x5d, 0xfe, 0x85, 0xaa, 0x53}; + lwmqtt_string_t topic_filter_s1 = {17, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xcf, 0x30, 0x8d, 0x17, 0x84, 0xff, 0x89, 0xd6, + 0xbf, 0x78, 0xe9, 0x6f, 0xf7, 0x6, 0xf8, 0xb1}; + lwmqtt_string_t topic_filter_s2 = {16, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x37, 0x89, 0x17, 0xcd, 0xe7, 0x73, 0x88, 0x21, 0x13, 0x42, 0x11, 0x97, 0x54, + 0xaf, 0x84, 0x10, 0x5b, 0x77, 0x9f, 0x72, 0xa2, 0x54, 0x70, 0x91, 0x5}; + lwmqtt_string_t topic_filter_s3 = {25, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xb1, 0x88, 0x1f, 0xd1, 0x1f, 0xbc, 0xe, 0x67, 0x4, 0x65, + 0xf6, 0x43, 0x59, 0x5e, 0x60, 0x7f, 0x33, 0x8f, 0x1b, 0x4, + 0x67, 0x4d, 0x6f, 0xfd, 0xf8, 0xec, 0x1e, 0x61, 0x2a, 0x26}; + lwmqtt_string_t topic_filter_s4 = {30, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + lwmqtt_sub_options_t sub_opts[5]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS0; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 10689, 5, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 8875 [("q|\160X\159\&9\235\ETB\206]\224\ETB\205\209\149\211>e\193#\168\246){_\173L\172",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\193\166\246\224\235\201\ACK\187k",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// False, _noLocal = False, _subQoS = QoS1}),("\227\247a\181\EOT\235\DC3\222\&1",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("Y\213\224\139\128\253\225\233\238\165\197\166`\174]\204\150\188",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS1})] [] +TEST(Subscribe311QCTest, Encode18) { + uint8_t pkt[] = {0x82, 0x51, 0x22, 0xab, 0x0, 0x1c, 0x71, 0x7c, 0xa0, 0x58, 0x9f, 0x39, 0xeb, 0x17, 0xce, 0x5d, 0xe0, + 0x17, 0xcd, 0xd1, 0x95, 0xd3, 0x3e, 0x65, 0xc1, 0x23, 0xa8, 0xf6, 0x29, 0x7b, 0x5f, 0xad, 0x4c, 0xac, + 0x0, 0x0, 0x9, 0xc1, 0xa6, 0xf6, 0xe0, 0xeb, 0xc9, 0x6, 0xbb, 0x6b, 0x1, 0x0, 0x9, 0xe3, 0xf7, + 0x61, 0xb5, 0x4, 0xeb, 0x13, 0xde, 0x31, 0x2, 0x0, 0x0, 0x0, 0x0, 0x12, 0x59, 0xd5, 0xe0, 0x8b, + 0x80, 0xfd, 0xe1, 0xe9, 0xee, 0xa5, 0xc5, 0xa6, 0x60, 0xae, 0x5d, 0xcc, 0x96, 0xbc, 0x1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0x71, 0x7c, 0xa0, 0x58, 0x9f, 0x39, 0xeb, 0x17, 0xce, 0x5d, + 0xe0, 0x17, 0xcd, 0xd1, 0x95, 0xd3, 0x3e, 0x65, 0xc1, 0x23, + 0xa8, 0xf6, 0x29, 0x7b, 0x5f, 0xad, 0x4c, 0xac}; + lwmqtt_string_t topic_filter_s0 = {28, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xc1, 0xa6, 0xf6, 0xe0, 0xeb, 0xc9, 0x6, 0xbb, 0x6b}; + lwmqtt_string_t topic_filter_s1 = {9, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xe3, 0xf7, 0x61, 0xb5, 0x4, 0xeb, 0x13, 0xde, 0x31}; + lwmqtt_string_t topic_filter_s2 = {9, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0}; + lwmqtt_string_t topic_filter_s3 = {0, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x59, 0xd5, 0xe0, 0x8b, 0x80, 0xfd, 0xe1, 0xe9, 0xee, + 0xa5, 0xc5, 0xa6, 0x60, 0xae, 0x5d, 0xcc, 0x96, 0xbc}; + lwmqtt_string_t topic_filter_s4 = {18, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + lwmqtt_sub_options_t sub_opts[5]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 8875, 5, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 1380 [("K\EM)\237\196\160&(\251\135w+\192\&7,V[\154\210\195\198L",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("\231",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS1})] [] +TEST(Subscribe311QCTest, Encode19) { + uint8_t pkt[] = {0x82, 0x1f, 0x5, 0x64, 0x0, 0x16, 0x4b, 0x19, 0x29, 0xed, 0xc4, 0xa0, 0x26, 0x28, 0xfb, 0x87, 0x77, + 0x2b, 0xc0, 0x37, 0x2c, 0x56, 0x5b, 0x9a, 0xd2, 0xc3, 0xc6, 0x4c, 0x1, 0x0, 0x1, 0xe7, 0x1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[2]; + uint8_t topic_filter_s0_bytes[] = {0x4b, 0x19, 0x29, 0xed, 0xc4, 0xa0, 0x26, 0x28, 0xfb, 0x87, 0x77, + 0x2b, 0xc0, 0x37, 0x2c, 0x56, 0x5b, 0x9a, 0xd2, 0xc3, 0xc6, 0x4c}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xe7}; + lwmqtt_string_t topic_filter_s1 = {1, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + lwmqtt_sub_options_t sub_opts[2]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 1380, 2, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 30364 [("\220f\ENQ\249\ENQv \203Q\135y\NAKd_O\f\253\176",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("\a",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\139\175\147u,R[\ACK\148\199\154\&6\156\218\&3\167",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\165O\255\"\139\185\135\183C\ACKa\214\143X\173\175\225K\200\247\205\133\145",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode20) { + uint8_t pkt[] = {0x82, 0x48, 0x76, 0x9c, 0x0, 0x12, 0xdc, 0x66, 0x5, 0xf9, 0x5, 0x76, 0x20, 0xcb, 0x51, + 0x87, 0x79, 0x15, 0x64, 0x5f, 0x4f, 0xc, 0xfd, 0xb0, 0x1, 0x0, 0x1, 0x7, 0x1, 0x0, + 0x10, 0x8b, 0xaf, 0x93, 0x75, 0x2c, 0x52, 0x5b, 0x6, 0x94, 0xc7, 0x9a, 0x36, 0x9c, 0xda, + 0x33, 0xa7, 0x0, 0x0, 0x17, 0xa5, 0x4f, 0xff, 0x22, 0x8b, 0xb9, 0x87, 0xb7, 0x43, 0x6, + 0x61, 0xd6, 0x8f, 0x58, 0xad, 0xaf, 0xe1, 0x4b, 0xc8, 0xf7, 0xcd, 0x85, 0x91, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[4]; + uint8_t topic_filter_s0_bytes[] = {0xdc, 0x66, 0x5, 0xf9, 0x5, 0x76, 0x20, 0xcb, 0x51, + 0x87, 0x79, 0x15, 0x64, 0x5f, 0x4f, 0xc, 0xfd, 0xb0}; + lwmqtt_string_t topic_filter_s0 = {18, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x7}; + lwmqtt_string_t topic_filter_s1 = {1, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x8b, 0xaf, 0x93, 0x75, 0x2c, 0x52, 0x5b, 0x6, + 0x94, 0xc7, 0x9a, 0x36, 0x9c, 0xda, 0x33, 0xa7}; + lwmqtt_string_t topic_filter_s2 = {16, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xa5, 0x4f, 0xff, 0x22, 0x8b, 0xb9, 0x87, 0xb7, 0x43, 0x6, 0x61, 0xd6, + 0x8f, 0x58, 0xad, 0xaf, 0xe1, 0x4b, 0xc8, 0xf7, 0xcd, 0x85, 0x91}; + lwmqtt_string_t topic_filter_s3 = {23, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + lwmqtt_sub_options_t sub_opts[4]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 30364, 4, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 13751 [("\156f\255\253ey\FSZ\232\SUB\185\t\US\178\&8\232f\133\ETB\162|4\206\CAN",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\177\205\213\234\248\167\223\230\217\206W\NUL",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1})] [] +TEST(Subscribe311QCTest, Encode21) { + uint8_t pkt[] = {0x82, 0x2c, 0x35, 0xb7, 0x0, 0x18, 0x9c, 0x66, 0xff, 0xfd, 0x65, 0x79, 0x1c, 0x5a, 0xe8, 0x1a, + 0xb9, 0x9, 0x1f, 0xb2, 0x38, 0xe8, 0x66, 0x85, 0x17, 0xa2, 0x7c, 0x34, 0xce, 0x18, 0x0, 0x0, + 0xc, 0xb1, 0xcd, 0xd5, 0xea, 0xf8, 0xa7, 0xdf, 0xe6, 0xd9, 0xce, 0x57, 0x0, 0x1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[2]; + uint8_t topic_filter_s0_bytes[] = {0x9c, 0x66, 0xff, 0xfd, 0x65, 0x79, 0x1c, 0x5a, 0xe8, 0x1a, 0xb9, 0x9, + 0x1f, 0xb2, 0x38, 0xe8, 0x66, 0x85, 0x17, 0xa2, 0x7c, 0x34, 0xce, 0x18}; + lwmqtt_string_t topic_filter_s0 = {24, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xb1, 0xcd, 0xd5, 0xea, 0xf8, 0xa7, 0xdf, 0xe6, 0xd9, 0xce, 0x57, 0x0}; + lwmqtt_string_t topic_filter_s1 = {12, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + lwmqtt_sub_options_t sub_opts[2]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 13751, 2, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 5555 [("IB\226\SO\ENQK\215\237\159\218\ETBzX+z\149#\145\153o\204v\161a",SubOptions {_retainHandling +// = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("6\181{\r\135\131?\223\ETB\141\245\141",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// False, _noLocal = False, _subQoS = QoS2}),("\159\tW\206.OY\144\EOT\239\233\137u\SOH",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("&\186\209i\193\255\239e\229\211\225p\239\155\151Lr\130\&1v\174\220p\203\140",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\203w\ENQI\203\206\251\&5W\154cP\177\182\t\205\240m",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("\205\DC4\SYN\172\130\192\ACK\245",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("6\179\251\NUL\150\222\176\147y\USL\208\STXG",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("c\130\178\t\141",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("g=E)SZD\234\245\255\SUB:YA\212\146\GS\203\197\NUL\247\187\r-]\177*\245p\222",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("I\207",SubOptions {_retainHandling +// = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode22) { + uint8_t pkt[] = { + 0x82, 0xbb, 0x1, 0x15, 0xb3, 0x0, 0x18, 0x49, 0x42, 0xe2, 0xe, 0x5, 0x4b, 0xd7, 0xed, 0x9f, 0xda, 0x17, 0x7a, + 0x58, 0x2b, 0x7a, 0x95, 0x23, 0x91, 0x99, 0x6f, 0xcc, 0x76, 0xa1, 0x61, 0x2, 0x0, 0xc, 0x36, 0xb5, 0x7b, 0xd, + 0x87, 0x83, 0x3f, 0xdf, 0x17, 0x8d, 0xf5, 0x8d, 0x2, 0x0, 0xe, 0x9f, 0x9, 0x57, 0xce, 0x2e, 0x4f, 0x59, 0x90, + 0x4, 0xef, 0xe9, 0x89, 0x75, 0x1, 0x2, 0x0, 0x19, 0x26, 0xba, 0xd1, 0x69, 0xc1, 0xff, 0xef, 0x65, 0xe5, 0xd3, + 0xe1, 0x70, 0xef, 0x9b, 0x97, 0x4c, 0x72, 0x82, 0x31, 0x76, 0xae, 0xdc, 0x70, 0xcb, 0x8c, 0x2, 0x0, 0x12, 0xcb, + 0x77, 0x5, 0x49, 0xcb, 0xce, 0xfb, 0x35, 0x57, 0x9a, 0x63, 0x50, 0xb1, 0xb6, 0x9, 0xcd, 0xf0, 0x6d, 0x1, 0x0, + 0x8, 0xcd, 0x14, 0x16, 0xac, 0x82, 0xc0, 0x6, 0xf5, 0x2, 0x0, 0xe, 0x36, 0xb3, 0xfb, 0x0, 0x96, 0xde, 0xb0, + 0x93, 0x79, 0x1f, 0x4c, 0xd0, 0x2, 0x47, 0x1, 0x0, 0x5, 0x63, 0x82, 0xb2, 0x9, 0x8d, 0x2, 0x0, 0x1e, 0x67, + 0x3d, 0x45, 0x29, 0x53, 0x5a, 0x44, 0xea, 0xf5, 0xff, 0x1a, 0x3a, 0x59, 0x41, 0xd4, 0x92, 0x1d, 0xcb, 0xc5, 0x0, + 0xf7, 0xbb, 0xd, 0x2d, 0x5d, 0xb1, 0x2a, 0xf5, 0x70, 0xde, 0x1, 0x0, 0x0, 0x1, 0x0, 0x2, 0x49, 0xcf, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0x49, 0x42, 0xe2, 0xe, 0x5, 0x4b, 0xd7, 0xed, 0x9f, 0xda, 0x17, 0x7a, + 0x58, 0x2b, 0x7a, 0x95, 0x23, 0x91, 0x99, 0x6f, 0xcc, 0x76, 0xa1, 0x61}; + lwmqtt_string_t topic_filter_s0 = {24, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x36, 0xb5, 0x7b, 0xd, 0x87, 0x83, 0x3f, 0xdf, 0x17, 0x8d, 0xf5, 0x8d}; + lwmqtt_string_t topic_filter_s1 = {12, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x9f, 0x9, 0x57, 0xce, 0x2e, 0x4f, 0x59, 0x90, 0x4, 0xef, 0xe9, 0x89, 0x75, 0x1}; + lwmqtt_string_t topic_filter_s2 = {14, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x26, 0xba, 0xd1, 0x69, 0xc1, 0xff, 0xef, 0x65, 0xe5, 0xd3, 0xe1, 0x70, 0xef, + 0x9b, 0x97, 0x4c, 0x72, 0x82, 0x31, 0x76, 0xae, 0xdc, 0x70, 0xcb, 0x8c}; + lwmqtt_string_t topic_filter_s3 = {25, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xcb, 0x77, 0x5, 0x49, 0xcb, 0xce, 0xfb, 0x35, 0x57, + 0x9a, 0x63, 0x50, 0xb1, 0xb6, 0x9, 0xcd, 0xf0, 0x6d}; + lwmqtt_string_t topic_filter_s4 = {18, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xcd, 0x14, 0x16, 0xac, 0x82, 0xc0, 0x6, 0xf5}; + lwmqtt_string_t topic_filter_s5 = {8, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x36, 0xb3, 0xfb, 0x0, 0x96, 0xde, 0xb0, 0x93, 0x79, 0x1f, 0x4c, 0xd0, 0x2, 0x47}; + lwmqtt_string_t topic_filter_s6 = {14, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x63, 0x82, 0xb2, 0x9, 0x8d}; + lwmqtt_string_t topic_filter_s7 = {5, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x67, 0x3d, 0x45, 0x29, 0x53, 0x5a, 0x44, 0xea, 0xf5, 0xff, + 0x1a, 0x3a, 0x59, 0x41, 0xd4, 0x92, 0x1d, 0xcb, 0xc5, 0x0, + 0xf7, 0xbb, 0xd, 0x2d, 0x5d, 0xb1, 0x2a, 0xf5, 0x70, 0xde}; + lwmqtt_string_t topic_filter_s8 = {30, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0}; + lwmqtt_string_t topic_filter_s9 = {0, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0x49, 0xcf}; + lwmqtt_string_t topic_filter_s10 = {2, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + lwmqtt_sub_options_t sub_opts[11]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS2; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS2; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS1; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS2; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS1; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + sub_opts[9].qos = LWMQTT_QOS1; + sub_opts[9].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[9].retain_as_published = false; + sub_opts[9].no_local = false; + sub_opts[10].qos = LWMQTT_QOS0; + sub_opts[10].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[10].retain_as_published = false; + sub_opts[10].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 5555, 11, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 10338 [("&N",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = +// False, _subQoS = QoS0}),("L\139",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal +// = False, _subQoS = QoS2}),("\142\DLE ",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS0}),("o\184\f/M\241\233\236\145",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("1.$\203\166%\139\EOT8\133\134\251j\247\168\&3Z\182pDS\195\&3!",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\239\EM%\FS\EM\DC3v\226cEn",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode23) { + uint8_t pkt[] = {0x82, 0x4a, 0x28, 0x62, 0x0, 0x2, 0x26, 0x4e, 0x0, 0x0, 0x2, 0x4c, 0x8b, 0x2, 0x0, 0x3, + 0x8e, 0x10, 0x20, 0x0, 0x0, 0x9, 0x6f, 0xb8, 0xc, 0x2f, 0x4d, 0xf1, 0xe9, 0xec, 0x91, 0x0, + 0x0, 0x18, 0x31, 0x2e, 0x24, 0xcb, 0xa6, 0x25, 0x8b, 0x4, 0x38, 0x85, 0x86, 0xfb, 0x6a, 0xf7, + 0xa8, 0x33, 0x5a, 0xb6, 0x70, 0x44, 0x53, 0xc3, 0x33, 0x21, 0x2, 0x0, 0x0, 0x0, 0x0, 0xb, + 0xef, 0x19, 0x25, 0x1c, 0x19, 0x13, 0x76, 0xe2, 0x63, 0x45, 0x6e, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0x26, 0x4e}; + lwmqtt_string_t topic_filter_s0 = {2, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x4c, 0x8b}; + lwmqtt_string_t topic_filter_s1 = {2, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x8e, 0x10, 0x20}; + lwmqtt_string_t topic_filter_s2 = {3, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x6f, 0xb8, 0xc, 0x2f, 0x4d, 0xf1, 0xe9, 0xec, 0x91}; + lwmqtt_string_t topic_filter_s3 = {9, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x31, 0x2e, 0x24, 0xcb, 0xa6, 0x25, 0x8b, 0x4, 0x38, 0x85, 0x86, 0xfb, + 0x6a, 0xf7, 0xa8, 0x33, 0x5a, 0xb6, 0x70, 0x44, 0x53, 0xc3, 0x33, 0x21}; + lwmqtt_string_t topic_filter_s4 = {24, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0}; + lwmqtt_string_t topic_filter_s5 = {0, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xef, 0x19, 0x25, 0x1c, 0x19, 0x13, 0x76, 0xe2, 0x63, 0x45, 0x6e}; + lwmqtt_string_t topic_filter_s6 = {11, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + lwmqtt_sub_options_t sub_opts[7]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS0; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 10338, 7, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 14367 [("\STX\239Z\131\175\220\f\217_\189A\"\149\ETX\141\165-\244h\215\171\166)",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\156\b\136\ETX\ETX\r\237\164|",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS0}),("\205.YT\176\145C\172\203\204",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("\246\226\\.\aA),\171\169\221\214\\\142bC",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\195\191\198\v\219\177\249",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS1})] [] +TEST(Subscribe311QCTest, Encode24) { + uint8_t pkt[] = {0x82, 0x52, 0x38, 0x1f, 0x0, 0x17, 0x2, 0xef, 0x5a, 0x83, 0xaf, 0xdc, 0xc, 0xd9, 0x5f, 0xbd, 0x41, + 0x22, 0x95, 0x3, 0x8d, 0xa5, 0x2d, 0xf4, 0x68, 0xd7, 0xab, 0xa6, 0x29, 0x1, 0x0, 0x9, 0x9c, 0x8, + 0x88, 0x3, 0x3, 0xd, 0xed, 0xa4, 0x7c, 0x0, 0x0, 0xa, 0xcd, 0x2e, 0x59, 0x54, 0xb0, 0x91, 0x43, + 0xac, 0xcb, 0xcc, 0x1, 0x0, 0x10, 0xf6, 0xe2, 0x5c, 0x2e, 0x7, 0x41, 0x29, 0x2c, 0xab, 0xa9, 0xdd, + 0xd6, 0x5c, 0x8e, 0x62, 0x43, 0x1, 0x0, 0x7, 0xc3, 0xbf, 0xc6, 0xb, 0xdb, 0xb1, 0xf9, 0x1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0x2, 0xef, 0x5a, 0x83, 0xaf, 0xdc, 0xc, 0xd9, 0x5f, 0xbd, 0x41, 0x22, + 0x95, 0x3, 0x8d, 0xa5, 0x2d, 0xf4, 0x68, 0xd7, 0xab, 0xa6, 0x29}; + lwmqtt_string_t topic_filter_s0 = {23, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x9c, 0x8, 0x88, 0x3, 0x3, 0xd, 0xed, 0xa4, 0x7c}; + lwmqtt_string_t topic_filter_s1 = {9, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xcd, 0x2e, 0x59, 0x54, 0xb0, 0x91, 0x43, 0xac, 0xcb, 0xcc}; + lwmqtt_string_t topic_filter_s2 = {10, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xf6, 0xe2, 0x5c, 0x2e, 0x7, 0x41, 0x29, 0x2c, + 0xab, 0xa9, 0xdd, 0xd6, 0x5c, 0x8e, 0x62, 0x43}; + lwmqtt_string_t topic_filter_s3 = {16, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xc3, 0xbf, 0xc6, 0xb, 0xdb, 0xb1, 0xf9}; + lwmqtt_string_t topic_filter_s4 = {7, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + lwmqtt_sub_options_t sub_opts[5]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS0; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 14367, 5, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 19237 [(">\187+\226\DLE\US\194\164\194\165\171\166\128",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode25) { + uint8_t pkt[] = {0x82, 0x12, 0x4b, 0x25, 0x0, 0xd, 0x3e, 0xbb, 0x2b, 0xe2, + 0x10, 0x1f, 0xc2, 0xa4, 0xc2, 0xa5, 0xab, 0xa6, 0x80, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x3e, 0xbb, 0x2b, 0xe2, 0x10, 0x1f, 0xc2, 0xa4, 0xc2, 0xa5, 0xab, 0xa6, 0x80}; + lwmqtt_string_t topic_filter_s0 = {13, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + lwmqtt_sub_options_t sub_opts[1]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 19237, 1, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 799 [("\156\220HPZ\146\176",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// False, _noLocal = False, _subQoS = QoS2}),("\204\t\251\&4\140^\198\158P\165\GS\253\182\234",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\140\173\170.\149\153\144",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS2}),("s \171\156/-lV\184 +// \155g\165\198sf\180>\233\133\130\221\220\156\178\244\&9\241\225|",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),(":8\155.\207\150\DC1\180c\182",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\232^\US\247\EMU\223ra\135U+K",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS0}),("Py\226\FSi_\194\179\221\138\196\208\239\131r{\173n",SubOptions {_retainHandling +// = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("d\254\197\229\182\216;<*\ETX\ENQ",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS2}),("\141P\243\129=\177V\214",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("\164c",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [] +TEST(Subscribe311QCTest, Encode26) { + uint8_t pkt[] = {0x82, 0x98, 0x1, 0x3, 0x1f, 0x0, 0x7, 0x9c, 0xdc, 0x48, 0x50, 0x5a, 0x92, 0xb0, 0x2, 0x0, + 0xe, 0xcc, 0x9, 0xfb, 0x34, 0x8c, 0x5e, 0xc6, 0x9e, 0x50, 0xa5, 0x1d, 0xfd, 0xb6, 0xea, 0x2, + 0x0, 0x7, 0x8c, 0xad, 0xaa, 0x2e, 0x95, 0x99, 0x90, 0x2, 0x0, 0x1e, 0x73, 0x20, 0xab, 0x9c, + 0x2f, 0x2d, 0x6c, 0x56, 0xb8, 0x20, 0x9b, 0x67, 0xa5, 0xc6, 0x73, 0x66, 0xb4, 0x3e, 0xe9, 0x85, + 0x82, 0xdd, 0xdc, 0x9c, 0xb2, 0xf4, 0x39, 0xf1, 0xe1, 0x7c, 0x2, 0x0, 0xa, 0x3a, 0x38, 0x9b, + 0x2e, 0xcf, 0x96, 0x11, 0xb4, 0x63, 0xb6, 0x2, 0x0, 0xd, 0xe8, 0x5e, 0x1f, 0xf7, 0x19, 0x55, + 0xdf, 0x72, 0x61, 0x87, 0x55, 0x2b, 0x4b, 0x0, 0x0, 0x12, 0x50, 0x79, 0xe2, 0x1c, 0x69, 0x5f, + 0xc2, 0xb3, 0xdd, 0x8a, 0xc4, 0xd0, 0xef, 0x83, 0x72, 0x7b, 0xad, 0x6e, 0x1, 0x0, 0xb, 0x64, + 0xfe, 0xc5, 0xe5, 0xb6, 0xd8, 0x3b, 0x3c, 0x2a, 0x3, 0x5, 0x2, 0x0, 0x8, 0x8d, 0x50, 0xf3, + 0x81, 0x3d, 0xb1, 0x56, 0xd6, 0x1, 0x0, 0x2, 0xa4, 0x63, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[10]; + uint8_t topic_filter_s0_bytes[] = {0x9c, 0xdc, 0x48, 0x50, 0x5a, 0x92, 0xb0}; + lwmqtt_string_t topic_filter_s0 = {7, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xcc, 0x9, 0xfb, 0x34, 0x8c, 0x5e, 0xc6, 0x9e, 0x50, 0xa5, 0x1d, 0xfd, 0xb6, 0xea}; + lwmqtt_string_t topic_filter_s1 = {14, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x8c, 0xad, 0xaa, 0x2e, 0x95, 0x99, 0x90}; + lwmqtt_string_t topic_filter_s2 = {7, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x73, 0x20, 0xab, 0x9c, 0x2f, 0x2d, 0x6c, 0x56, 0xb8, 0x20, + 0x9b, 0x67, 0xa5, 0xc6, 0x73, 0x66, 0xb4, 0x3e, 0xe9, 0x85, + 0x82, 0xdd, 0xdc, 0x9c, 0xb2, 0xf4, 0x39, 0xf1, 0xe1, 0x7c}; + lwmqtt_string_t topic_filter_s3 = {30, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x3a, 0x38, 0x9b, 0x2e, 0xcf, 0x96, 0x11, 0xb4, 0x63, 0xb6}; + lwmqtt_string_t topic_filter_s4 = {10, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xe8, 0x5e, 0x1f, 0xf7, 0x19, 0x55, 0xdf, 0x72, 0x61, 0x87, 0x55, 0x2b, 0x4b}; + lwmqtt_string_t topic_filter_s5 = {13, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x50, 0x79, 0xe2, 0x1c, 0x69, 0x5f, 0xc2, 0xb3, 0xdd, + 0x8a, 0xc4, 0xd0, 0xef, 0x83, 0x72, 0x7b, 0xad, 0x6e}; + lwmqtt_string_t topic_filter_s6 = {18, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x64, 0xfe, 0xc5, 0xe5, 0xb6, 0xd8, 0x3b, 0x3c, 0x2a, 0x3, 0x5}; + lwmqtt_string_t topic_filter_s7 = {11, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x8d, 0x50, 0xf3, 0x81, 0x3d, 0xb1, 0x56, 0xd6}; + lwmqtt_string_t topic_filter_s8 = {8, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0xa4, 0x63}; + lwmqtt_string_t topic_filter_s9 = {2, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + lwmqtt_sub_options_t sub_opts[10]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS2; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS1; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS2; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS1; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + sub_opts[9].qos = LWMQTT_QOS2; + sub_opts[9].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[9].retain_as_published = false; + sub_opts[9].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 799, 10, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 2526 [("\211\175",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS1}),("a?\SUB\v\176$\210A\128\248oSU\134\STX\236J,w",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\EOTO\245G\249\200\n4\SI1\239\b\NAKto3",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// False, _noLocal = False, _subQoS = QoS0}),("t[^\ESC",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1})] [] +TEST(Subscribe311QCTest, Encode27) { + uint8_t pkt[] = {0x82, 0x37, 0x9, 0xde, 0x0, 0x2, 0xd3, 0xaf, 0x1, 0x0, 0x13, 0x61, 0x3f, 0x1a, 0xb, + 0xb0, 0x24, 0xd2, 0x41, 0x80, 0xf8, 0x6f, 0x53, 0x55, 0x86, 0x2, 0xec, 0x4a, 0x2c, 0x77, + 0x0, 0x0, 0x10, 0x4, 0x4f, 0xf5, 0x47, 0xf9, 0xc8, 0xa, 0x34, 0xf, 0x31, 0xef, 0x8, + 0x15, 0x74, 0x6f, 0x33, 0x0, 0x0, 0x4, 0x74, 0x5b, 0x5e, 0x1b, 0x1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[4]; + uint8_t topic_filter_s0_bytes[] = {0xd3, 0xaf}; + lwmqtt_string_t topic_filter_s0 = {2, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x61, 0x3f, 0x1a, 0xb, 0xb0, 0x24, 0xd2, 0x41, 0x80, 0xf8, + 0x6f, 0x53, 0x55, 0x86, 0x2, 0xec, 0x4a, 0x2c, 0x77}; + lwmqtt_string_t topic_filter_s1 = {19, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x4, 0x4f, 0xf5, 0x47, 0xf9, 0xc8, 0xa, 0x34, + 0xf, 0x31, 0xef, 0x8, 0x15, 0x74, 0x6f, 0x33}; + lwmqtt_string_t topic_filter_s2 = {16, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x74, 0x5b, 0x5e, 0x1b}; + lwmqtt_string_t topic_filter_s3 = {4, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + lwmqtt_sub_options_t sub_opts[4]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS0; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 2526, 4, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 20875 [("\204\138\132\154\245\&9=\219v\220Se\229\161Wh\183\183\198zd\248",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\RS\162h\189\t>\133L\199l'\244\164\235\180\194\221\SUB\DEL\226\157",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\254?\146]\b\244ZJ\CAN\SO\132",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS1}),("m\186m/\\gx^\145\214|\209B\210\&4\174o\149`",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\SUBq\181A9\r\162p:\RS0\152-\191\GS\b\ESC\CAN{X\231\237:\158T\155>\209\246\247",SubOptions {_retainHandling +// = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("i\250\186\175\SI\FSa\220\183\EM\160f*o\137n\164\&0",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("6",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS0}),("{4[\185\DC1\b\217\STXA\US",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\253J\226,\219z\148\248 \194\152\ENQ\nD\209\164\199\201N\245\231\&7\216\244",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [] +TEST(Subscribe311QCTest, Encode28) { + uint8_t pkt[] = { + 0x82, 0xb9, 0x1, 0x51, 0x8b, 0x0, 0x16, 0xcc, 0x8a, 0x84, 0x9a, 0xf5, 0x39, 0x3d, 0xdb, 0x76, 0xdc, 0x53, 0x65, + 0xe5, 0xa1, 0x57, 0x68, 0xb7, 0xb7, 0xc6, 0x7a, 0x64, 0xf8, 0x2, 0x0, 0x15, 0x1e, 0xa2, 0x68, 0xbd, 0x9, 0x3e, + 0x85, 0x4c, 0xc7, 0x6c, 0x27, 0xf4, 0xa4, 0xeb, 0xb4, 0xc2, 0xdd, 0x1a, 0x7f, 0xe2, 0x9d, 0x2, 0x0, 0xb, 0xfe, + 0x3f, 0x92, 0x5d, 0x8, 0xf4, 0x5a, 0x4a, 0x18, 0xe, 0x84, 0x1, 0x0, 0x13, 0x6d, 0xba, 0x6d, 0x2f, 0x5c, 0x67, + 0x78, 0x5e, 0x91, 0xd6, 0x7c, 0xd1, 0x42, 0xd2, 0x34, 0xae, 0x6f, 0x95, 0x60, 0x1, 0x0, 0x1e, 0x1a, 0x71, 0xb5, + 0x41, 0x39, 0xd, 0xa2, 0x70, 0x3a, 0x1e, 0x30, 0x98, 0x2d, 0xbf, 0x1d, 0x8, 0x1b, 0x18, 0x7b, 0x58, 0xe7, 0xed, + 0x3a, 0x9e, 0x54, 0x9b, 0x3e, 0xd1, 0xf6, 0xf7, 0x2, 0x0, 0x12, 0x69, 0xfa, 0xba, 0xaf, 0xf, 0x1c, 0x61, 0xdc, + 0xb7, 0x19, 0xa0, 0x66, 0x2a, 0x6f, 0x89, 0x6e, 0xa4, 0x30, 0x1, 0x0, 0x1, 0x36, 0x0, 0x0, 0xa, 0x7b, 0x34, + 0x5b, 0xb9, 0x11, 0x8, 0xd9, 0x2, 0x41, 0x1f, 0x1, 0x0, 0x18, 0xfd, 0x4a, 0xe2, 0x2c, 0xdb, 0x7a, 0x94, 0xf8, + 0x20, 0xc2, 0x98, 0x5, 0xa, 0x44, 0xd1, 0xa4, 0xc7, 0xc9, 0x4e, 0xf5, 0xe7, 0x37, 0xd8, 0xf4, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[9]; + uint8_t topic_filter_s0_bytes[] = {0xcc, 0x8a, 0x84, 0x9a, 0xf5, 0x39, 0x3d, 0xdb, 0x76, 0xdc, 0x53, + 0x65, 0xe5, 0xa1, 0x57, 0x68, 0xb7, 0xb7, 0xc6, 0x7a, 0x64, 0xf8}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x1e, 0xa2, 0x68, 0xbd, 0x9, 0x3e, 0x85, 0x4c, 0xc7, 0x6c, 0x27, + 0xf4, 0xa4, 0xeb, 0xb4, 0xc2, 0xdd, 0x1a, 0x7f, 0xe2, 0x9d}; + lwmqtt_string_t topic_filter_s1 = {21, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xfe, 0x3f, 0x92, 0x5d, 0x8, 0xf4, 0x5a, 0x4a, 0x18, 0xe, 0x84}; + lwmqtt_string_t topic_filter_s2 = {11, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x6d, 0xba, 0x6d, 0x2f, 0x5c, 0x67, 0x78, 0x5e, 0x91, 0xd6, + 0x7c, 0xd1, 0x42, 0xd2, 0x34, 0xae, 0x6f, 0x95, 0x60}; + lwmqtt_string_t topic_filter_s3 = {19, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x1a, 0x71, 0xb5, 0x41, 0x39, 0xd, 0xa2, 0x70, 0x3a, 0x1e, + 0x30, 0x98, 0x2d, 0xbf, 0x1d, 0x8, 0x1b, 0x18, 0x7b, 0x58, + 0xe7, 0xed, 0x3a, 0x9e, 0x54, 0x9b, 0x3e, 0xd1, 0xf6, 0xf7}; + lwmqtt_string_t topic_filter_s4 = {30, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x69, 0xfa, 0xba, 0xaf, 0xf, 0x1c, 0x61, 0xdc, 0xb7, + 0x19, 0xa0, 0x66, 0x2a, 0x6f, 0x89, 0x6e, 0xa4, 0x30}; + lwmqtt_string_t topic_filter_s5 = {18, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x36}; + lwmqtt_string_t topic_filter_s6 = {1, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x7b, 0x34, 0x5b, 0xb9, 0x11, 0x8, 0xd9, 0x2, 0x41, 0x1f}; + lwmqtt_string_t topic_filter_s7 = {10, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xfd, 0x4a, 0xe2, 0x2c, 0xdb, 0x7a, 0x94, 0xf8, 0x20, 0xc2, 0x98, 0x5, + 0xa, 0x44, 0xd1, 0xa4, 0xc7, 0xc9, 0x4e, 0xf5, 0xe7, 0x37, 0xd8, 0xf4}; + lwmqtt_string_t topic_filter_s8 = {24, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + lwmqtt_sub_options_t sub_opts[9]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS1; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS0; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS1; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS0; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 20875, 9, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 22546 [("f\185p\ENQ\162\139-.\158v+^\157\SUB",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS1}),("\164\243\&8\128l\255}\242i4",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("5\223)'\144\189\195\212k{\GS\165\"\ESC/+%m\175\161\235\NAK\223\142\205\225$\224\ETB\f",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("v\167\184F\198B\ENQ\ESC\ACK0\ETB{f6\228\ta\185\207\154\175\171\187~\175\142'",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0}),("\204",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\218\246\&2\EOT\168$\EOTK\222\\S[\243",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// False, _noLocal = False, _subQoS = +// QoS1}),("\212\216\165t\tpPa\167\149\147\v\b\SO\163\236\SO\222*@h\158&\239",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\234kp\252kzk\SI\247\243\&2\172\GS\222\ESC]7\232\166\230S\174h\192%w\152",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("(\DEL\146\a\222 ",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\b_\249n\169r0*w\\_ym\195Mp\253\145\200\213\239]q\136\135",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\174'S\r\251\\\252\192\250\128\&4U\184\168\201s\DEL\STXe1\240",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [] +TEST(Subscribe311QCTest, Encode29) { + uint8_t pkt[] = {0x82, 0xe9, 0x1, 0x58, 0x12, 0x0, 0xe, 0x66, 0xb9, 0x70, 0x5, 0xa2, 0x8b, 0x2d, 0x2e, 0x9e, 0x76, + 0x2b, 0x5e, 0x9d, 0x1a, 0x1, 0x0, 0xa, 0xa4, 0xf3, 0x38, 0x80, 0x6c, 0xff, 0x7d, 0xf2, 0x69, 0x34, + 0x1, 0x0, 0x1e, 0x35, 0xdf, 0x29, 0x27, 0x90, 0xbd, 0xc3, 0xd4, 0x6b, 0x7b, 0x1d, 0xa5, 0x22, 0x1b, + 0x2f, 0x2b, 0x25, 0x6d, 0xaf, 0xa1, 0xeb, 0x15, 0xdf, 0x8e, 0xcd, 0xe1, 0x24, 0xe0, 0x17, 0xc, 0x1, + 0x0, 0x1b, 0x76, 0xa7, 0xb8, 0x46, 0xc6, 0x42, 0x5, 0x1b, 0x6, 0x30, 0x17, 0x7b, 0x66, 0x36, 0xe4, + 0x9, 0x61, 0xb9, 0xcf, 0x9a, 0xaf, 0xab, 0xbb, 0x7e, 0xaf, 0x8e, 0x27, 0x0, 0x0, 0x1, 0xcc, 0x1, + 0x0, 0xd, 0xda, 0xf6, 0x32, 0x4, 0xa8, 0x24, 0x4, 0x4b, 0xde, 0x5c, 0x53, 0x5b, 0xf3, 0x1, 0x0, + 0x18, 0xd4, 0xd8, 0xa5, 0x74, 0x9, 0x70, 0x50, 0x61, 0xa7, 0x95, 0x93, 0xb, 0x8, 0xe, 0xa3, 0xec, + 0xe, 0xde, 0x2a, 0x40, 0x68, 0x9e, 0x26, 0xef, 0x2, 0x0, 0x1b, 0xea, 0x6b, 0x70, 0xfc, 0x6b, 0x7a, + 0x6b, 0xf, 0xf7, 0xf3, 0x32, 0xac, 0x1d, 0xde, 0x1b, 0x5d, 0x37, 0xe8, 0xa6, 0xe6, 0x53, 0xae, 0x68, + 0xc0, 0x25, 0x77, 0x98, 0x2, 0x0, 0x6, 0x28, 0x7f, 0x92, 0x7, 0xde, 0x20, 0x0, 0x0, 0x19, 0x8, + 0x5f, 0xf9, 0x6e, 0xa9, 0x72, 0x30, 0x2a, 0x77, 0x5c, 0x5f, 0x79, 0x6d, 0xc3, 0x4d, 0x70, 0xfd, 0x91, + 0xc8, 0xd5, 0xef, 0x5d, 0x71, 0x88, 0x87, 0x2, 0x0, 0x15, 0xae, 0x27, 0x53, 0xd, 0xfb, 0x5c, 0xfc, + 0xc0, 0xfa, 0x80, 0x34, 0x55, 0xb8, 0xa8, 0xc9, 0x73, 0x7f, 0x2, 0x65, 0x31, 0xf0, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0x66, 0xb9, 0x70, 0x5, 0xa2, 0x8b, 0x2d, 0x2e, 0x9e, 0x76, 0x2b, 0x5e, 0x9d, 0x1a}; + lwmqtt_string_t topic_filter_s0 = {14, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xa4, 0xf3, 0x38, 0x80, 0x6c, 0xff, 0x7d, 0xf2, 0x69, 0x34}; + lwmqtt_string_t topic_filter_s1 = {10, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x35, 0xdf, 0x29, 0x27, 0x90, 0xbd, 0xc3, 0xd4, 0x6b, 0x7b, + 0x1d, 0xa5, 0x22, 0x1b, 0x2f, 0x2b, 0x25, 0x6d, 0xaf, 0xa1, + 0xeb, 0x15, 0xdf, 0x8e, 0xcd, 0xe1, 0x24, 0xe0, 0x17, 0xc}; + lwmqtt_string_t topic_filter_s2 = {30, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x76, 0xa7, 0xb8, 0x46, 0xc6, 0x42, 0x5, 0x1b, 0x6, 0x30, 0x17, 0x7b, 0x66, 0x36, + 0xe4, 0x9, 0x61, 0xb9, 0xcf, 0x9a, 0xaf, 0xab, 0xbb, 0x7e, 0xaf, 0x8e, 0x27}; + lwmqtt_string_t topic_filter_s3 = {27, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xcc}; + lwmqtt_string_t topic_filter_s4 = {1, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xda, 0xf6, 0x32, 0x4, 0xa8, 0x24, 0x4, 0x4b, 0xde, 0x5c, 0x53, 0x5b, 0xf3}; + lwmqtt_string_t topic_filter_s5 = {13, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xd4, 0xd8, 0xa5, 0x74, 0x9, 0x70, 0x50, 0x61, 0xa7, 0x95, 0x93, 0xb, + 0x8, 0xe, 0xa3, 0xec, 0xe, 0xde, 0x2a, 0x40, 0x68, 0x9e, 0x26, 0xef}; + lwmqtt_string_t topic_filter_s6 = {24, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xea, 0x6b, 0x70, 0xfc, 0x6b, 0x7a, 0x6b, 0xf, 0xf7, 0xf3, 0x32, 0xac, 0x1d, 0xde, + 0x1b, 0x5d, 0x37, 0xe8, 0xa6, 0xe6, 0x53, 0xae, 0x68, 0xc0, 0x25, 0x77, 0x98}; + lwmqtt_string_t topic_filter_s7 = {27, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x28, 0x7f, 0x92, 0x7, 0xde, 0x20}; + lwmqtt_string_t topic_filter_s8 = {6, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x8, 0x5f, 0xf9, 0x6e, 0xa9, 0x72, 0x30, 0x2a, 0x77, 0x5c, 0x5f, 0x79, 0x6d, + 0xc3, 0x4d, 0x70, 0xfd, 0x91, 0xc8, 0xd5, 0xef, 0x5d, 0x71, 0x88, 0x87}; + lwmqtt_string_t topic_filter_s9 = {25, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0xae, 0x27, 0x53, 0xd, 0xfb, 0x5c, 0xfc, 0xc0, 0xfa, 0x80, 0x34, + 0x55, 0xb8, 0xa8, 0xc9, 0x73, 0x7f, 0x2, 0x65, 0x31, 0xf0}; + lwmqtt_string_t topic_filter_s10 = {21, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + lwmqtt_sub_options_t sub_opts[11]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS1; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS2; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS2; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS0; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + sub_opts[9].qos = LWMQTT_QOS2; + sub_opts[9].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[9].retain_as_published = false; + sub_opts[9].no_local = false; + sub_opts[10].qos = LWMQTT_QOS2; + sub_opts[10].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[10].retain_as_published = false; + sub_opts[10].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 22546, 11, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 790 [("uR,E\184\234\156:\161\&7Eb\249x\ACK\255KB\185\162Iu",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS1})] [] +TEST(Subscribe311QCTest, Encode30) { + uint8_t pkt[] = {0x82, 0x1b, 0x3, 0x16, 0x0, 0x16, 0x75, 0x52, 0x2c, 0x45, 0xb8, 0xea, 0x9c, 0x3a, 0xa1, + 0x37, 0x45, 0x62, 0xf9, 0x78, 0x6, 0xff, 0x4b, 0x42, 0xb9, 0xa2, 0x49, 0x75, 0x1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x75, 0x52, 0x2c, 0x45, 0xb8, 0xea, 0x9c, 0x3a, 0xa1, 0x37, 0x45, + 0x62, 0xf9, 0x78, 0x6, 0xff, 0x4b, 0x42, 0xb9, 0xa2, 0x49, 0x75}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + lwmqtt_sub_options_t sub_opts[1]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 790, 1, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 30435 +// [("`h\241\RSu\235\248\SO\189\SUBS\214\231#\132\DEL\217\130\160\215\151\182j\252\240A",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = QoS0}),("\t +// \217\148d\224~\204\DEL3L\231\147\139\217",SubOptions {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = +// True, _noLocal = False, _subQoS = QoS2}),("\167\ESC\138~\151\139\229\133\197\&9\163\238",SubOptions {_retainHandling +// = SendOnSubscribeNew, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS0}),("\n>\\\198\221l`h\165\131\238\145-\156\v\161\232\183\144=\232v\252\242\198{\140",SubOptions {_retainHandling +// = SendOnSubscribeNew, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS0}),("u\191\218\ESC\245\204nb",SubOptions {_retainHandling = SendOnSubscribeNew, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS1}),("",SubOptions {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = +// False, _noLocal = False, _subQoS = +// QoS0}),("\176\169\&4\190\&0\241\238\237\150\241\162\234\148\RS\133\243\DC1(9\SYNZ\226\184\199",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS0}),("jW\202\231\176\GS\252\217\199\151\250\161\248",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("Q \v\EM\165d\183\254\EOTw\224",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS1}),("N\ESCa1\203j8\230\EOT\160q,\148\239p\225RT\NAK",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = False, _noLocal = True, _subQoS = QoS0})] [PropPayloadFormatIndicator +// 146,PropResponseInformation "S\186\202^\ACK\175c\230\220\214\186\203\142G\143\217\155",PropAssignedClientIdentifier +// "\143\USS]\209YO\249Vn\US\218\n\214J\183p\188\ACK-\RS",PropAssignedClientIdentifier +// "qO\168\207(\231",PropAssignedClientIdentifier "\DLE\250pO#dg\US",PropAuthenticationData +// "\238\169\249\181T\180",PropSessionExpiryInterval 3239,PropCorrelationData +// "\EM`k\184\179\134\&3\130\247Y\194_<\t\188E\196Y\141\245\212\231~j7\188Hu\192",PropPayloadFormatIndicator +// 123,PropAuthenticationData +// "C!\243\217'\159$\169\GS\242\197z\150\187\159\139\141\&8|\252\201\156IM/",PropSessionExpiryInterval +// 26828,PropRetainAvailable 90,PropRequestResponseInformation 195,PropMaximumQoS 17,PropContentType +// "\192q\229|\b\CAN\235N\145",PropMaximumPacketSize 24089,PropPayloadFormatIndicator +// 200,PropSharedSubscriptionAvailable 68] +TEST(Subscribe5QCTest, Encode1) { + uint8_t pkt[] = { + 0x82, 0xeb, 0x2, 0x76, 0xe3, 0xae, 0x1, 0x1, 0x92, 0x1a, 0x0, 0x11, 0x53, 0xba, 0xca, 0x5e, 0x6, 0xaf, 0x63, + 0xe6, 0xdc, 0xd6, 0xba, 0xcb, 0x8e, 0x47, 0x8f, 0xd9, 0x9b, 0x12, 0x0, 0x15, 0x8f, 0x1f, 0x53, 0x5d, 0xd1, 0x59, + 0x4f, 0xf9, 0x56, 0x6e, 0x1f, 0xda, 0xa, 0xd6, 0x4a, 0xb7, 0x70, 0xbc, 0x6, 0x2d, 0x1e, 0x12, 0x0, 0x6, 0x71, + 0x4f, 0xa8, 0xcf, 0x28, 0xe7, 0x12, 0x0, 0x8, 0x10, 0xfa, 0x70, 0x4f, 0x23, 0x64, 0x67, 0x1f, 0x16, 0x0, 0x6, + 0xee, 0xa9, 0xf9, 0xb5, 0x54, 0xb4, 0x11, 0x0, 0x0, 0xc, 0xa7, 0x9, 0x0, 0x1d, 0x19, 0x60, 0x6b, 0xb8, 0xb3, + 0x86, 0x33, 0x82, 0xf7, 0x59, 0xc2, 0x5f, 0x3c, 0x9, 0xbc, 0x45, 0xc4, 0x59, 0x8d, 0xf5, 0xd4, 0xe7, 0x7e, 0x6a, + 0x37, 0xbc, 0x48, 0x75, 0xc0, 0x1, 0x7b, 0x16, 0x0, 0x19, 0x43, 0x21, 0xf3, 0xd9, 0x27, 0x9f, 0x24, 0xa9, 0x1d, + 0xf2, 0xc5, 0x7a, 0x96, 0xbb, 0x9f, 0x8b, 0x8d, 0x38, 0x7c, 0xfc, 0xc9, 0x9c, 0x49, 0x4d, 0x2f, 0x11, 0x0, 0x0, + 0x68, 0xcc, 0x25, 0x5a, 0x19, 0xc3, 0x24, 0x11, 0x3, 0x0, 0x9, 0xc0, 0x71, 0xe5, 0x7c, 0x8, 0x18, 0xeb, 0x4e, + 0x91, 0x27, 0x0, 0x0, 0x5e, 0x19, 0x1, 0xc8, 0x2a, 0x44, 0x0, 0x1a, 0x60, 0x68, 0xf1, 0x1e, 0x75, 0xeb, 0xf8, + 0xe, 0xbd, 0x1a, 0x53, 0xd6, 0xe7, 0x23, 0x84, 0x7f, 0xd9, 0x82, 0xa0, 0xd7, 0x97, 0xb6, 0x6a, 0xfc, 0xf0, 0x41, + 0xc, 0x0, 0xf, 0x9, 0x20, 0xd9, 0x94, 0x64, 0xe0, 0x7e, 0xcc, 0x7f, 0x33, 0x4c, 0xe7, 0x93, 0x8b, 0xd9, 0x2a, + 0x0, 0xc, 0xa7, 0x1b, 0x8a, 0x7e, 0x97, 0x8b, 0xe5, 0x85, 0xc5, 0x39, 0xa3, 0xee, 0x18, 0x0, 0x1b, 0xa, 0x3e, + 0x5c, 0xc6, 0xdd, 0x6c, 0x60, 0x68, 0xa5, 0x83, 0xee, 0x91, 0x2d, 0x9c, 0xb, 0xa1, 0xe8, 0xb7, 0x90, 0x3d, 0xe8, + 0x76, 0xfc, 0xf2, 0xc6, 0x7b, 0x8c, 0x18, 0x0, 0x8, 0x75, 0xbf, 0xda, 0x1b, 0xf5, 0xcc, 0x6e, 0x62, 0x11, 0x0, + 0x0, 0x20, 0x0, 0x18, 0xb0, 0xa9, 0x34, 0xbe, 0x30, 0xf1, 0xee, 0xed, 0x96, 0xf1, 0xa2, 0xea, 0x94, 0x1e, 0x85, + 0xf3, 0x11, 0x28, 0x39, 0x16, 0x5a, 0xe2, 0xb8, 0xc7, 0x28, 0x0, 0xd, 0x6a, 0x57, 0xca, 0xe7, 0xb0, 0x1d, 0xfc, + 0xd9, 0xc7, 0x97, 0xfa, 0xa1, 0xf8, 0x2, 0x0, 0xb, 0x51, 0x20, 0xb, 0x19, 0xa5, 0x64, 0xb7, 0xfe, 0x4, 0x77, + 0xe0, 0xd, 0x0, 0x13, 0x4e, 0x1b, 0x61, 0x31, 0xcb, 0x6a, 0x38, 0xe6, 0x4, 0xa0, 0x71, 0x2c, 0x94, 0xef, 0x70, + 0xe1, 0x52, 0x54, 0x15, 0x14}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[10]; + uint8_t topic_filter_s0_bytes[] = {0x60, 0x68, 0xf1, 0x1e, 0x75, 0xeb, 0xf8, 0xe, 0xbd, 0x1a, 0x53, 0xd6, 0xe7, + 0x23, 0x84, 0x7f, 0xd9, 0x82, 0xa0, 0xd7, 0x97, 0xb6, 0x6a, 0xfc, 0xf0, 0x41}; + lwmqtt_string_t topic_filter_s0 = {26, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x9, 0x20, 0xd9, 0x94, 0x64, 0xe0, 0x7e, 0xcc, + 0x7f, 0x33, 0x4c, 0xe7, 0x93, 0x8b, 0xd9}; + lwmqtt_string_t topic_filter_s1 = {15, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xa7, 0x1b, 0x8a, 0x7e, 0x97, 0x8b, 0xe5, 0x85, 0xc5, 0x39, 0xa3, 0xee}; + lwmqtt_string_t topic_filter_s2 = {12, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xa, 0x3e, 0x5c, 0xc6, 0xdd, 0x6c, 0x60, 0x68, 0xa5, 0x83, 0xee, 0x91, 0x2d, 0x9c, + 0xb, 0xa1, 0xe8, 0xb7, 0x90, 0x3d, 0xe8, 0x76, 0xfc, 0xf2, 0xc6, 0x7b, 0x8c}; + lwmqtt_string_t topic_filter_s3 = {27, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x75, 0xbf, 0xda, 0x1b, 0xf5, 0xcc, 0x6e, 0x62}; + lwmqtt_string_t topic_filter_s4 = {8, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0}; + lwmqtt_string_t topic_filter_s5 = {0, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xb0, 0xa9, 0x34, 0xbe, 0x30, 0xf1, 0xee, 0xed, 0x96, 0xf1, 0xa2, 0xea, + 0x94, 0x1e, 0x85, 0xf3, 0x11, 0x28, 0x39, 0x16, 0x5a, 0xe2, 0xb8, 0xc7}; + lwmqtt_string_t topic_filter_s6 = {24, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x6a, 0x57, 0xca, 0xe7, 0xb0, 0x1d, 0xfc, 0xd9, 0xc7, 0x97, 0xfa, 0xa1, 0xf8}; + lwmqtt_string_t topic_filter_s7 = {13, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x51, 0x20, 0xb, 0x19, 0xa5, 0x64, 0xb7, 0xfe, 0x4, 0x77, 0xe0}; + lwmqtt_string_t topic_filter_s8 = {11, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x4e, 0x1b, 0x61, 0x31, 0xcb, 0x6a, 0x38, 0xe6, 0x4, 0xa0, + 0x71, 0x2c, 0x94, 0xef, 0x70, 0xe1, 0x52, 0x54, 0x15}; + lwmqtt_string_t topic_filter_s9 = {19, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + lwmqtt_sub_options_t sub_opts[10]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[3].retain_as_published = true; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS0; + sub_opts[6].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[6].retain_as_published = true; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS2; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS1; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = true; + sub_opts[8].no_local = true; + sub_opts[9].qos = LWMQTT_QOS0; + sub_opts[9].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[9].retain_as_published = false; + sub_opts[9].no_local = true; + uint8_t bytesprops0[] = {0x53, 0xba, 0xca, 0x5e, 0x6, 0xaf, 0x63, 0xe6, 0xdc, + 0xd6, 0xba, 0xcb, 0x8e, 0x47, 0x8f, 0xd9, 0x9b}; + uint8_t bytesprops1[] = {0x8f, 0x1f, 0x53, 0x5d, 0xd1, 0x59, 0x4f, 0xf9, 0x56, 0x6e, 0x1f, + 0xda, 0xa, 0xd6, 0x4a, 0xb7, 0x70, 0xbc, 0x6, 0x2d, 0x1e}; + uint8_t bytesprops2[] = {0x71, 0x4f, 0xa8, 0xcf, 0x28, 0xe7}; + uint8_t bytesprops3[] = {0x10, 0xfa, 0x70, 0x4f, 0x23, 0x64, 0x67, 0x1f}; + uint8_t bytesprops4[] = {0xee, 0xa9, 0xf9, 0xb5, 0x54, 0xb4}; + uint8_t bytesprops5[] = {0x19, 0x60, 0x6b, 0xb8, 0xb3, 0x86, 0x33, 0x82, 0xf7, 0x59, 0xc2, 0x5f, 0x3c, 0x9, 0xbc, + 0x45, 0xc4, 0x59, 0x8d, 0xf5, 0xd4, 0xe7, 0x7e, 0x6a, 0x37, 0xbc, 0x48, 0x75, 0xc0}; + uint8_t bytesprops6[] = {0x43, 0x21, 0xf3, 0xd9, 0x27, 0x9f, 0x24, 0xa9, 0x1d, 0xf2, 0xc5, 0x7a, 0x96, + 0xbb, 0x9f, 0x8b, 0x8d, 0x38, 0x7c, 0xfc, 0xc9, 0x9c, 0x49, 0x4d, 0x2f}; + uint8_t bytesprops7[] = {0xc0, 0x71, 0xe5, 0x7c, 0x8, 0x18, 0xeb, 0x4e, 0x91}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 146}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {17, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {21, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {6, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {8, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {6, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 3239}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {29, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 123}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {25, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 26828}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 90}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 195}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 17}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {9, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 24089}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 200}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 68}}, + }; + + lwmqtt_properties_t props = {18, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 30435, 10, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 2083 +// [("\168\136\255:\130\SUB\133;\147<\234\247\227\169\216d\131:D\219\GS\190\200O2\203\149\212",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS0}),("\219\203o\224\154\&9\229\144\a\219e\152\161\219hhF\236O\129\192h\ETXY\148\&9\150\204.\250",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = QoS1})] +// [PropMessageExpiryInterval 3245,PropReceiveMaximum 30130,PropSessionExpiryInterval 10678,PropReceiveMaximum +// 15989,PropTopicAliasMaximum 29133,PropMessageExpiryInterval 5541,PropMessageExpiryInterval 1992,PropUserProperty +// "\156\239w\206\DC2S\244V\220\205G\183t\244K\SYN\r\250z\225\168_\175\223\208o\CANM\148\FS" +// "\153\231\158t\GS'",PropAssignedClientIdentifier "0`\228_P\144\200\STX\DC19\160]",PropMaximumQoS 178,PropReasonString +// "h`rHh\137>\138wU\166\200\254\167\219\193\156\148\162\193\224B="] +TEST(Subscribe5QCTest, Encode2) { + uint8_t pkt[] = {0x82, 0xb4, 0x1, 0x8, 0x23, 0x71, 0x2, 0x0, 0x0, 0xc, 0xad, 0x21, 0x75, 0xb2, 0x11, 0x0, 0x0, + 0x29, 0xb6, 0x21, 0x3e, 0x75, 0x22, 0x71, 0xcd, 0x2, 0x0, 0x0, 0x15, 0xa5, 0x2, 0x0, 0x0, 0x7, + 0xc8, 0x26, 0x0, 0x1e, 0x9c, 0xef, 0x77, 0xce, 0x12, 0x53, 0xf4, 0x56, 0xdc, 0xcd, 0x47, 0xb7, 0x74, + 0xf4, 0x4b, 0x16, 0xd, 0xfa, 0x7a, 0xe1, 0xa8, 0x5f, 0xaf, 0xdf, 0xd0, 0x6f, 0x18, 0x4d, 0x94, 0x1c, + 0x0, 0x6, 0x99, 0xe7, 0x9e, 0x74, 0x1d, 0x27, 0x12, 0x0, 0xc, 0x30, 0x60, 0xe4, 0x5f, 0x50, 0x90, + 0xc8, 0x2, 0x11, 0x39, 0xa0, 0x5d, 0x24, 0xb2, 0x1f, 0x0, 0x17, 0x68, 0x60, 0x72, 0x48, 0x68, 0x89, + 0x3e, 0x8a, 0x77, 0x55, 0xa6, 0xc8, 0xfe, 0xa7, 0xdb, 0xc1, 0x9c, 0x94, 0xa2, 0xc1, 0xe0, 0x42, 0x3d, + 0x0, 0x1c, 0xa8, 0x88, 0xff, 0x3a, 0x82, 0x1a, 0x85, 0x3b, 0x93, 0x3c, 0xea, 0xf7, 0xe3, 0xa9, 0xd8, + 0x64, 0x83, 0x3a, 0x44, 0xdb, 0x1d, 0xbe, 0xc8, 0x4f, 0x32, 0xcb, 0x95, 0xd4, 0x4, 0x0, 0x1e, 0xdb, + 0xcb, 0x6f, 0xe0, 0x9a, 0x39, 0xe5, 0x90, 0x7, 0xdb, 0x65, 0x98, 0xa1, 0xdb, 0x68, 0x68, 0x46, 0xec, + 0x4f, 0x81, 0xc0, 0x68, 0x3, 0x59, 0x94, 0x39, 0x96, 0xcc, 0x2e, 0xfa, 0x25}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[2]; + uint8_t topic_filter_s0_bytes[] = {0xa8, 0x88, 0xff, 0x3a, 0x82, 0x1a, 0x85, 0x3b, 0x93, 0x3c, + 0xea, 0xf7, 0xe3, 0xa9, 0xd8, 0x64, 0x83, 0x3a, 0x44, 0xdb, + 0x1d, 0xbe, 0xc8, 0x4f, 0x32, 0xcb, 0x95, 0xd4}; + lwmqtt_string_t topic_filter_s0 = {28, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xdb, 0xcb, 0x6f, 0xe0, 0x9a, 0x39, 0xe5, 0x90, 0x7, 0xdb, + 0x65, 0x98, 0xa1, 0xdb, 0x68, 0x68, 0x46, 0xec, 0x4f, 0x81, + 0xc0, 0x68, 0x3, 0x59, 0x94, 0x39, 0x96, 0xcc, 0x2e, 0xfa}; + lwmqtt_string_t topic_filter_s1 = {30, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + lwmqtt_sub_options_t sub_opts[2]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = true; + uint8_t bytesprops1[] = {0x99, 0xe7, 0x9e, 0x74, 0x1d, 0x27}; + uint8_t bytesprops0[] = {0x9c, 0xef, 0x77, 0xce, 0x12, 0x53, 0xf4, 0x56, 0xdc, 0xcd, 0x47, 0xb7, 0x74, 0xf4, 0x4b, + 0x16, 0xd, 0xfa, 0x7a, 0xe1, 0xa8, 0x5f, 0xaf, 0xdf, 0xd0, 0x6f, 0x18, 0x4d, 0x94, 0x1c}; + uint8_t bytesprops2[] = {0x30, 0x60, 0xe4, 0x5f, 0x50, 0x90, 0xc8, 0x2, 0x11, 0x39, 0xa0, 0x5d}; + uint8_t bytesprops3[] = {0x68, 0x60, 0x72, 0x48, 0x68, 0x89, 0x3e, 0x8a, 0x77, 0x55, 0xa6, 0xc8, + 0xfe, 0xa7, 0xdb, 0xc1, 0x9c, 0x94, 0xa2, 0xc1, 0xe0, 0x42, 0x3d}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 3245}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 30130}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 10678}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 15989}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 29133}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 5541}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 1992}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {30, (char*)&bytesprops0}, .v = {6, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {12, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 178}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {23, (char*)&bytesprops3}}}, + }; + + lwmqtt_properties_t props = {11, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 2083, 2, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 7451 [("^\181\143}(\238\228\"\243)\\U\DEL\166\161 \193\176\226P\219\EOT\253\191",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS0}),("!g\t\b\193\GS\FS\188!\172",SubOptions {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS1}),("D2>\192%7\NUL54",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS0}),("\172D\201\155j\142)Wc\150\143Cc\217\220\253\GS\238m\161\\f",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = True, _noLocal = False, _subQoS = QoS1})] [PropMessageExpiryInterval +// 3967,PropWildcardSubscriptionAvailable 160,PropWillDelayInterval 11170,PropTopicAlias +// 26969,PropRequestProblemInformation 230,PropSubscriptionIdentifierAvailable 125,PropMessageExpiryInterval +// 656,PropRequestResponseInformation 53,PropServerReference +// "\136\nV\180>s\245\156\231#\209\182\223Y\193\196\130|\DLE\247\188\239/\154\233\nq",PropUserProperty +// "\SOH4K\RSKU\251\164V\176\207\229\228\144\156Z8\222@\172\245\159\147\226\SI#\150" +// "8\183f;\175\222zW\201\218\DC4\187oz2\180\235\r\168H\176\150\&8b\139q",PropMessageExpiryInterval +// 29283,PropMessageExpiryInterval 26688,PropCorrelationData +// "\181\230U\199\247\155E\241\139\254d\215\211S\248|\150\175\128\146x\141",PropWillDelayInterval +// 16284,PropResponseTopic "\173\160S\135\155\220\tg",PropSubscriptionIdentifierAvailable 31,PropReceiveMaximum +// 4328,PropWildcardSubscriptionAvailable 115,PropReceiveMaximum 963,PropRetainAvailable 180,PropMaximumQoS +// 128,PropSubscriptionIdentifier 8] +TEST(Subscribe5QCTest, Encode3) { + uint8_t pkt[] = { + 0x82, 0x86, 0x2, 0x1d, 0x1b, 0xb5, 0x1, 0x2, 0x0, 0x0, 0xf, 0x7f, 0x28, 0xa0, 0x18, 0x0, 0x0, 0x2b, 0xa2, + 0x23, 0x69, 0x59, 0x17, 0xe6, 0x29, 0x7d, 0x2, 0x0, 0x0, 0x2, 0x90, 0x19, 0x35, 0x1c, 0x0, 0x1b, 0x88, 0xa, + 0x56, 0xb4, 0x3e, 0x73, 0xf5, 0x9c, 0xe7, 0x23, 0xd1, 0xb6, 0xdf, 0x59, 0xc1, 0xc4, 0x82, 0x7c, 0x10, 0xf7, 0xbc, + 0xef, 0x2f, 0x9a, 0xe9, 0xa, 0x71, 0x26, 0x0, 0x1b, 0x1, 0x34, 0x4b, 0x1e, 0x4b, 0x55, 0xfb, 0xa4, 0x56, 0xb0, + 0xcf, 0xe5, 0xe4, 0x90, 0x9c, 0x5a, 0x38, 0xde, 0x40, 0xac, 0xf5, 0x9f, 0x93, 0xe2, 0xf, 0x23, 0x96, 0x0, 0x1a, + 0x38, 0xb7, 0x66, 0x3b, 0xaf, 0xde, 0x7a, 0x57, 0xc9, 0xda, 0x14, 0xbb, 0x6f, 0x7a, 0x32, 0xb4, 0xeb, 0xd, 0xa8, + 0x48, 0xb0, 0x96, 0x38, 0x62, 0x8b, 0x71, 0x2, 0x0, 0x0, 0x72, 0x63, 0x2, 0x0, 0x0, 0x68, 0x40, 0x9, 0x0, + 0x16, 0xb5, 0xe6, 0x55, 0xc7, 0xf7, 0x9b, 0x45, 0xf1, 0x8b, 0xfe, 0x64, 0xd7, 0xd3, 0x53, 0xf8, 0x7c, 0x96, 0xaf, + 0x80, 0x92, 0x78, 0x8d, 0x18, 0x0, 0x0, 0x3f, 0x9c, 0x8, 0x0, 0x8, 0xad, 0xa0, 0x53, 0x87, 0x9b, 0xdc, 0x9, + 0x67, 0x29, 0x1f, 0x21, 0x10, 0xe8, 0x28, 0x73, 0x21, 0x3, 0xc3, 0x25, 0xb4, 0x24, 0x80, 0xb, 0x8, 0x0, 0x18, + 0x5e, 0xb5, 0x8f, 0x7d, 0x28, 0xee, 0xe4, 0x22, 0xf3, 0x29, 0x5c, 0x55, 0x7f, 0xa6, 0xa1, 0x20, 0xc1, 0xb0, 0xe2, + 0x50, 0xdb, 0x4, 0xfd, 0xbf, 0x28, 0x0, 0xa, 0x21, 0x67, 0x9, 0x8, 0xc1, 0x1d, 0x1c, 0xbc, 0x21, 0xac, 0x21, + 0x0, 0x9, 0x44, 0x32, 0x3e, 0xc0, 0x25, 0x37, 0x0, 0x35, 0x34, 0x4, 0x0, 0x16, 0xac, 0x44, 0xc9, 0x9b, 0x6a, + 0x8e, 0x29, 0x57, 0x63, 0x96, 0x8f, 0x43, 0x63, 0xd9, 0xdc, 0xfd, 0x1d, 0xee, 0x6d, 0xa1, 0x5c, 0x66, 0x9}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[4]; + uint8_t topic_filter_s0_bytes[] = {0x5e, 0xb5, 0x8f, 0x7d, 0x28, 0xee, 0xe4, 0x22, 0xf3, 0x29, 0x5c, 0x55, + 0x7f, 0xa6, 0xa1, 0x20, 0xc1, 0xb0, 0xe2, 0x50, 0xdb, 0x4, 0xfd, 0xbf}; + lwmqtt_string_t topic_filter_s0 = {24, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x21, 0x67, 0x9, 0x8, 0xc1, 0x1d, 0x1c, 0xbc, 0x21, 0xac}; + lwmqtt_string_t topic_filter_s1 = {10, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x44, 0x32, 0x3e, 0xc0, 0x25, 0x37, 0x0, 0x35, 0x34}; + lwmqtt_string_t topic_filter_s2 = {9, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xac, 0x44, 0xc9, 0x9b, 0x6a, 0x8e, 0x29, 0x57, 0x63, 0x96, 0x8f, + 0x43, 0x63, 0xd9, 0xdc, 0xfd, 0x1d, 0xee, 0x6d, 0xa1, 0x5c, 0x66}; + lwmqtt_string_t topic_filter_s3 = {22, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + lwmqtt_sub_options_t sub_opts[4]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = true; + sub_opts[3].no_local = false; + uint8_t bytesprops0[] = {0x88, 0xa, 0x56, 0xb4, 0x3e, 0x73, 0xf5, 0x9c, 0xe7, 0x23, 0xd1, 0xb6, 0xdf, 0x59, + 0xc1, 0xc4, 0x82, 0x7c, 0x10, 0xf7, 0xbc, 0xef, 0x2f, 0x9a, 0xe9, 0xa, 0x71}; + uint8_t bytesprops2[] = {0x38, 0xb7, 0x66, 0x3b, 0xaf, 0xde, 0x7a, 0x57, 0xc9, 0xda, 0x14, 0xbb, 0x6f, + 0x7a, 0x32, 0xb4, 0xeb, 0xd, 0xa8, 0x48, 0xb0, 0x96, 0x38, 0x62, 0x8b, 0x71}; + uint8_t bytesprops1[] = {0x1, 0x34, 0x4b, 0x1e, 0x4b, 0x55, 0xfb, 0xa4, 0x56, 0xb0, 0xcf, 0xe5, 0xe4, 0x90, + 0x9c, 0x5a, 0x38, 0xde, 0x40, 0xac, 0xf5, 0x9f, 0x93, 0xe2, 0xf, 0x23, 0x96}; + uint8_t bytesprops3[] = {0xb5, 0xe6, 0x55, 0xc7, 0xf7, 0x9b, 0x45, 0xf1, 0x8b, 0xfe, 0x64, + 0xd7, 0xd3, 0x53, 0xf8, 0x7c, 0x96, 0xaf, 0x80, 0x92, 0x78, 0x8d}; + uint8_t bytesprops4[] = {0xad, 0xa0, 0x53, 0x87, 0x9b, 0xdc, 0x9, 0x67}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 3967}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 160}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 11170}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 26969}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 230}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 125}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 656}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 53}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {27, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {27, (char*)&bytesprops1}, .v = {26, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 29283}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 26688}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {22, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 16284}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {8, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 31}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 4328}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 115}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 963}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 180}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 128}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 8}}, + }; + + lwmqtt_properties_t props = {22, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 7451, 4, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 12482 [("\240\185\219h?\152\186\bA)\215<\169\164\"\193cb\ENQA\175\150%\240PA\255\238",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS2}),("\191=\159\232\202\226?4",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal +// = False, _subQoS = QoS2}),("E\132\197l\158",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = True, +// _noLocal = True, _subQoS = QoS1}),("\241\167y\214\226%\t\ETBii\EM\DEL\170\&4g\168",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS2}),("\241\224o\202\161\218\237%\226a\207.\254\DC2\153\232\150,\214\&4\f\"\137Q\190\n#Y",SubOptions +// {_retainHandling = SendOnSubscribeNew, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS2}),("\DC4\240C\b\241\141\151\128\ACK\RSY\\\DLE%",SubOptions {_retainHandling = DoNotSendOnSubscribe, +// _retainAsPublished = True, _noLocal = True, _subQoS = QoS0}),("\NULMD\CAN\134\155\213\216\137",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\235v\226a\SOHS\196\195R\194,\230\195lcY\213m\211\GS\239\r",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS2}),("\177\202\DC4\217\183\255t@4q\RS\194uK",SubOptions {_retainHandling = SendOnSubscribeNew, _retainAsPublished +// = False, _noLocal = False, _subQoS = QoS0})] [PropPayloadFormatIndicator 104,PropServerReference +// "\195\209\223u\154\n\a\140\&5K})/\242\240Z\DC4\149",PropMessageExpiryInterval 8008,PropResponseTopic +// "",PropReceiveMaximum 29528,PropCorrelationData "'\GS^\\6\140t\138\DLE",PropServerReference +// "q\152\237\194\252PN\ACK\247\173\167",PropSubscriptionIdentifier 17,PropResponseTopic "\156\DC2\208",PropContentType +// "\184\209/\139|%",PropSubscriptionIdentifier 25,PropUserProperty "\DEL\224GP<\226\&4" +// "\227\234\190ou\204@\221\157\217\183F\187\b`\212V\245\243}\GS\141\242\151\188",PropReceiveMaximum +// 9250,PropReasonString "\250\247&\183\241\163\200\221\195\US\170\215\173",PropCorrelationData +// "\141\152@\174\189\SOHi\NAK\155\142aX\183\205T\164\US\US?\218\a\249\191\179\250\130\210\185\RS",PropResponseInformation +// "D\186~\143",PropReasonString "\227\SI",PropUserProperty +// "\234\224;\131\DLE\CAN\f\149\148\233iC\213\211\234\NAK\144F\151I\156\160\177\128\203\238" +// "\f+w4\218\246\158F\147Z\191\166\CAN\142\226\254\167Q6G\207H\239\187=\195j",PropRetainAvailable +// 244,PropMessageExpiryInterval 1770,PropResponseInformation "\EOT\139\161\196\251|",PropReasonString +// "g\232_'\228\EM\FSi\217@\155g\vve\250\138$4\146\186\183Y\192\187ak+",PropResponseTopic +// "\255\246U\DC4\SYN$\250",PropMessageExpiryInterval 31299,PropMessageExpiryInterval 13287,PropTopicAlias +// 17495,PropTopicAlias 26693,PropMaximumQoS 133,PropTopicAlias 21058,PropReceiveMaximum 29829] +TEST(Subscribe5QCTest, Encode4) { + uint8_t pkt[] = { + 0x82, 0xed, 0x3, 0x30, 0xc2, 0xbe, 0x2, 0x1, 0x68, 0x1c, 0x0, 0x12, 0xc3, 0xd1, 0xdf, 0x75, 0x9a, 0xa, 0x7, + 0x8c, 0x35, 0x4b, 0x7d, 0x29, 0x2f, 0xf2, 0xf0, 0x5a, 0x14, 0x95, 0x2, 0x0, 0x0, 0x1f, 0x48, 0x8, 0x0, 0x0, + 0x21, 0x73, 0x58, 0x9, 0x0, 0x9, 0x27, 0x1d, 0x5e, 0x5c, 0x36, 0x8c, 0x74, 0x8a, 0x10, 0x1c, 0x0, 0xb, 0x71, + 0x98, 0xed, 0xc2, 0xfc, 0x50, 0x4e, 0x6, 0xf7, 0xad, 0xa7, 0xb, 0x11, 0x8, 0x0, 0x3, 0x9c, 0x12, 0xd0, 0x3, + 0x0, 0x6, 0xb8, 0xd1, 0x2f, 0x8b, 0x7c, 0x25, 0xb, 0x19, 0x26, 0x0, 0x7, 0x7f, 0xe0, 0x47, 0x50, 0x3c, 0xe2, + 0x34, 0x0, 0x19, 0xe3, 0xea, 0xbe, 0x6f, 0x75, 0xcc, 0x40, 0xdd, 0x9d, 0xd9, 0xb7, 0x46, 0xbb, 0x8, 0x60, 0xd4, + 0x56, 0xf5, 0xf3, 0x7d, 0x1d, 0x8d, 0xf2, 0x97, 0xbc, 0x21, 0x24, 0x22, 0x1f, 0x0, 0xd, 0xfa, 0xf7, 0x26, 0xb7, + 0xf1, 0xa3, 0xc8, 0xdd, 0xc3, 0x1f, 0xaa, 0xd7, 0xad, 0x9, 0x0, 0x1d, 0x8d, 0x98, 0x40, 0xae, 0xbd, 0x1, 0x69, + 0x15, 0x9b, 0x8e, 0x61, 0x58, 0xb7, 0xcd, 0x54, 0xa4, 0x1f, 0x1f, 0x3f, 0xda, 0x7, 0xf9, 0xbf, 0xb3, 0xfa, 0x82, + 0xd2, 0xb9, 0x1e, 0x1a, 0x0, 0x4, 0x44, 0xba, 0x7e, 0x8f, 0x1f, 0x0, 0x2, 0xe3, 0xf, 0x26, 0x0, 0x1a, 0xea, + 0xe0, 0x3b, 0x83, 0x10, 0x18, 0xc, 0x95, 0x94, 0xe9, 0x69, 0x43, 0xd5, 0xd3, 0xea, 0x15, 0x90, 0x46, 0x97, 0x49, + 0x9c, 0xa0, 0xb1, 0x80, 0xcb, 0xee, 0x0, 0x1b, 0xc, 0x2b, 0x77, 0x34, 0xda, 0xf6, 0x9e, 0x46, 0x93, 0x5a, 0xbf, + 0xa6, 0x18, 0x8e, 0xe2, 0xfe, 0xa7, 0x51, 0x36, 0x47, 0xcf, 0x48, 0xef, 0xbb, 0x3d, 0xc3, 0x6a, 0x25, 0xf4, 0x2, + 0x0, 0x0, 0x6, 0xea, 0x1a, 0x0, 0x6, 0x4, 0x8b, 0xa1, 0xc4, 0xfb, 0x7c, 0x1f, 0x0, 0x1c, 0x67, 0xe8, 0x5f, + 0x27, 0xe4, 0x19, 0x1c, 0x69, 0xd9, 0x40, 0x9b, 0x67, 0xb, 0x76, 0x65, 0xfa, 0x8a, 0x24, 0x34, 0x92, 0xba, 0xb7, + 0x59, 0xc0, 0xbb, 0x61, 0x6b, 0x2b, 0x8, 0x0, 0x7, 0xff, 0xf6, 0x55, 0x14, 0x16, 0x24, 0xfa, 0x2, 0x0, 0x0, + 0x7a, 0x43, 0x2, 0x0, 0x0, 0x33, 0xe7, 0x23, 0x44, 0x57, 0x23, 0x68, 0x45, 0x24, 0x85, 0x23, 0x52, 0x42, 0x21, + 0x74, 0x85, 0x0, 0x1c, 0xf0, 0xb9, 0xdb, 0x68, 0x3f, 0x98, 0xba, 0x8, 0x41, 0x29, 0xd7, 0x3c, 0xa9, 0xa4, 0x22, + 0xc1, 0x63, 0x62, 0x5, 0x41, 0xaf, 0x96, 0x25, 0xf0, 0x50, 0x41, 0xff, 0xee, 0x6, 0x0, 0x8, 0xbf, 0x3d, 0x9f, + 0xe8, 0xca, 0xe2, 0x3f, 0x34, 0x2, 0x0, 0x5, 0x45, 0x84, 0xc5, 0x6c, 0x9e, 0xd, 0x0, 0x10, 0xf1, 0xa7, 0x79, + 0xd6, 0xe2, 0x25, 0x9, 0x17, 0x69, 0x69, 0x19, 0x7f, 0xaa, 0x34, 0x67, 0xa8, 0x16, 0x0, 0x1c, 0xf1, 0xe0, 0x6f, + 0xca, 0xa1, 0xda, 0xed, 0x25, 0xe2, 0x61, 0xcf, 0x2e, 0xfe, 0x12, 0x99, 0xe8, 0x96, 0x2c, 0xd6, 0x34, 0xc, 0x22, + 0x89, 0x51, 0xbe, 0xa, 0x23, 0x59, 0x1e, 0x0, 0xe, 0x14, 0xf0, 0x43, 0x8, 0xf1, 0x8d, 0x97, 0x80, 0x6, 0x1e, + 0x59, 0x5c, 0x10, 0x25, 0x2c, 0x0, 0x9, 0x0, 0x4d, 0x44, 0x18, 0x86, 0x9b, 0xd5, 0xd8, 0x89, 0x2, 0x0, 0x16, + 0xeb, 0x76, 0xe2, 0x61, 0x1, 0x53, 0xc4, 0xc3, 0x52, 0xc2, 0x2c, 0xe6, 0xc3, 0x6c, 0x63, 0x59, 0xd5, 0x6d, 0xd3, + 0x1d, 0xef, 0xd, 0x16, 0x0, 0xe, 0xb1, 0xca, 0x14, 0xd9, 0xb7, 0xff, 0x74, 0x40, 0x34, 0x71, 0x1e, 0xc2, 0x75, + 0x4b, 0x10}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[9]; + uint8_t topic_filter_s0_bytes[] = {0xf0, 0xb9, 0xdb, 0x68, 0x3f, 0x98, 0xba, 0x8, 0x41, 0x29, + 0xd7, 0x3c, 0xa9, 0xa4, 0x22, 0xc1, 0x63, 0x62, 0x5, 0x41, + 0xaf, 0x96, 0x25, 0xf0, 0x50, 0x41, 0xff, 0xee}; + lwmqtt_string_t topic_filter_s0 = {28, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xbf, 0x3d, 0x9f, 0xe8, 0xca, 0xe2, 0x3f, 0x34}; + lwmqtt_string_t topic_filter_s1 = {8, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x45, 0x84, 0xc5, 0x6c, 0x9e}; + lwmqtt_string_t topic_filter_s2 = {5, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xf1, 0xa7, 0x79, 0xd6, 0xe2, 0x25, 0x9, 0x17, + 0x69, 0x69, 0x19, 0x7f, 0xaa, 0x34, 0x67, 0xa8}; + lwmqtt_string_t topic_filter_s3 = {16, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xf1, 0xe0, 0x6f, 0xca, 0xa1, 0xda, 0xed, 0x25, 0xe2, 0x61, + 0xcf, 0x2e, 0xfe, 0x12, 0x99, 0xe8, 0x96, 0x2c, 0xd6, 0x34, + 0xc, 0x22, 0x89, 0x51, 0xbe, 0xa, 0x23, 0x59}; + lwmqtt_string_t topic_filter_s4 = {28, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x14, 0xf0, 0x43, 0x8, 0xf1, 0x8d, 0x97, 0x80, 0x6, 0x1e, 0x59, 0x5c, 0x10, 0x25}; + lwmqtt_string_t topic_filter_s5 = {14, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x0, 0x4d, 0x44, 0x18, 0x86, 0x9b, 0xd5, 0xd8, 0x89}; + lwmqtt_string_t topic_filter_s6 = {9, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xeb, 0x76, 0xe2, 0x61, 0x1, 0x53, 0xc4, 0xc3, 0x52, 0xc2, 0x2c, + 0xe6, 0xc3, 0x6c, 0x63, 0x59, 0xd5, 0x6d, 0xd3, 0x1d, 0xef, 0xd}; + lwmqtt_string_t topic_filter_s7 = {22, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xb1, 0xca, 0x14, 0xd9, 0xb7, 0xff, 0x74, + 0x40, 0x34, 0x71, 0x1e, 0xc2, 0x75, 0x4b}; + lwmqtt_string_t topic_filter_s8 = {14, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + lwmqtt_sub_options_t sub_opts[9]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS2; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = true; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[4].retain_as_published = true; + sub_opts[4].no_local = true; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[5].retain_as_published = true; + sub_opts[5].no_local = true; + sub_opts[6].qos = LWMQTT_QOS2; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS2; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = true; + sub_opts[8].qos = LWMQTT_QOS0; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + uint8_t bytesprops0[] = {0xc3, 0xd1, 0xdf, 0x75, 0x9a, 0xa, 0x7, 0x8c, 0x35, + 0x4b, 0x7d, 0x29, 0x2f, 0xf2, 0xf0, 0x5a, 0x14, 0x95}; + uint8_t bytesprops1[] = {0}; + uint8_t bytesprops2[] = {0x27, 0x1d, 0x5e, 0x5c, 0x36, 0x8c, 0x74, 0x8a, 0x10}; + uint8_t bytesprops3[] = {0x71, 0x98, 0xed, 0xc2, 0xfc, 0x50, 0x4e, 0x6, 0xf7, 0xad, 0xa7}; + uint8_t bytesprops4[] = {0x9c, 0x12, 0xd0}; + uint8_t bytesprops5[] = {0xb8, 0xd1, 0x2f, 0x8b, 0x7c, 0x25}; + uint8_t bytesprops7[] = {0xe3, 0xea, 0xbe, 0x6f, 0x75, 0xcc, 0x40, 0xdd, 0x9d, 0xd9, 0xb7, 0x46, 0xbb, + 0x8, 0x60, 0xd4, 0x56, 0xf5, 0xf3, 0x7d, 0x1d, 0x8d, 0xf2, 0x97, 0xbc}; + uint8_t bytesprops6[] = {0x7f, 0xe0, 0x47, 0x50, 0x3c, 0xe2, 0x34}; + uint8_t bytesprops8[] = {0xfa, 0xf7, 0x26, 0xb7, 0xf1, 0xa3, 0xc8, 0xdd, 0xc3, 0x1f, 0xaa, 0xd7, 0xad}; + uint8_t bytesprops9[] = {0x8d, 0x98, 0x40, 0xae, 0xbd, 0x1, 0x69, 0x15, 0x9b, 0x8e, 0x61, 0x58, 0xb7, 0xcd, 0x54, + 0xa4, 0x1f, 0x1f, 0x3f, 0xda, 0x7, 0xf9, 0xbf, 0xb3, 0xfa, 0x82, 0xd2, 0xb9, 0x1e}; + uint8_t bytesprops10[] = {0x44, 0xba, 0x7e, 0x8f}; + uint8_t bytesprops11[] = {0xe3, 0xf}; + uint8_t bytesprops13[] = {0xc, 0x2b, 0x77, 0x34, 0xda, 0xf6, 0x9e, 0x46, 0x93, 0x5a, 0xbf, 0xa6, 0x18, 0x8e, + 0xe2, 0xfe, 0xa7, 0x51, 0x36, 0x47, 0xcf, 0x48, 0xef, 0xbb, 0x3d, 0xc3, 0x6a}; + uint8_t bytesprops12[] = {0xea, 0xe0, 0x3b, 0x83, 0x10, 0x18, 0xc, 0x95, 0x94, 0xe9, 0x69, 0x43, 0xd5, + 0xd3, 0xea, 0x15, 0x90, 0x46, 0x97, 0x49, 0x9c, 0xa0, 0xb1, 0x80, 0xcb, 0xee}; + uint8_t bytesprops14[] = {0x4, 0x8b, 0xa1, 0xc4, 0xfb, 0x7c}; + uint8_t bytesprops15[] = {0x67, 0xe8, 0x5f, 0x27, 0xe4, 0x19, 0x1c, 0x69, 0xd9, 0x40, 0x9b, 0x67, 0xb, 0x76, + 0x65, 0xfa, 0x8a, 0x24, 0x34, 0x92, 0xba, 0xb7, 0x59, 0xc0, 0xbb, 0x61, 0x6b, 0x2b}; + uint8_t bytesprops16[] = {0xff, 0xf6, 0x55, 0x14, 0x16, 0x24, 0xfa}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 104}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {18, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 8008}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {0, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 29528}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {9, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {11, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 17}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {3, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {6, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 25}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {7, (char*)&bytesprops6}, .v = {25, (char*)&bytesprops7}}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 9250}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {13, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {29, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {4, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {2, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)38, + .value = {.pair = {.k = {26, (char*)&bytesprops12}, .v = {27, (char*)&bytesprops13}}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 244}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 1770}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {6, (char*)&bytesprops14}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {28, (char*)&bytesprops15}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {7, (char*)&bytesprops16}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 31299}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 13287}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 17495}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 26693}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 133}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 21058}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 29829}}, + }; + + lwmqtt_properties_t props = {30, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 12482, 9, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 30449 [("",SubOptions {_retainHandling = SendOnSubscribeNew, _retainAsPublished = False, _noLocal = +// True, _subQoS = QoS2}),("\141\164\198",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS1}),("n\154\FS\SOH\163",SubOptions {_retainHandling = DoNotSendOnSubscribe, +// _retainAsPublished = True, _noLocal = True, _subQoS = QoS1}),("%+\\\SOH\ETX\139g?h",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS0}),("\233\208\172\204\212\234\ETXYP\192\163\217x\DC2\154\144\143@1\240\206\161\250",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("-\143",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = QoS0})] +// [PropReceiveMaximum 10961,PropPayloadFormatIndicator 104,PropContentType "",PropMaximumQoS 93,PropUserProperty +// "\ETB\200\EOT^\253\224" "\187\v\129\137B\156\US_)H\170z[\247\219\152b\189\207\SUB\149c_",PropContentType +// "6r\174\160\168\144+\227\\\144\129\142\164\EOT\161z~\246z\187=(D\216\152$(O",PropTopicAliasMaximum +// 32704,PropSessionExpiryInterval 10073] +TEST(Subscribe5QCTest, Encode5) { + uint8_t pkt[] = { + 0x82, 0xfc, 0x1, 0x76, 0xf1, 0x53, 0x21, 0x2a, 0xd1, 0x1, 0x68, 0x3, 0x0, 0x0, 0x24, 0x5d, 0x26, 0x0, 0x6, + 0x17, 0xc8, 0x4, 0x5e, 0xfd, 0xe0, 0x0, 0x17, 0xbb, 0xb, 0x81, 0x89, 0x42, 0x9c, 0x1f, 0x5f, 0x29, 0x48, 0xaa, + 0x7a, 0x5b, 0xf7, 0xdb, 0x98, 0x62, 0xbd, 0xcf, 0x1a, 0x95, 0x63, 0x5f, 0x3, 0x0, 0x1c, 0x36, 0x72, 0xae, 0xa0, + 0xa8, 0x90, 0x2b, 0xe3, 0x5c, 0x90, 0x81, 0x8e, 0xa4, 0x4, 0xa1, 0x7a, 0x7e, 0xf6, 0x7a, 0xbb, 0x3d, 0x28, 0x44, + 0xd8, 0x98, 0x24, 0x28, 0x4f, 0x22, 0x7f, 0xc0, 0x11, 0x0, 0x0, 0x27, 0x59, 0x0, 0x0, 0x16, 0x0, 0x3, 0x8d, + 0xa4, 0xc6, 0x1, 0x0, 0x5, 0x6e, 0x9a, 0x1c, 0x1, 0xa3, 0x2d, 0x0, 0x9, 0x25, 0x2b, 0x5c, 0x1, 0x3, 0x8b, + 0x67, 0x3f, 0x68, 0x28, 0x0, 0x1e, 0xe9, 0xd0, 0xac, 0xcc, 0xd4, 0xea, 0x3, 0x59, 0x50, 0xc0, 0xa3, 0xd9, 0x78, + 0x12, 0x9a, 0x90, 0x8f, 0x40, 0x31, 0xf0, 0xce, 0x3c, 0x43, 0x8b, 0xe9, 0x34, 0x82, 0x31, 0x84, 0xe9, 0x10, 0x0, + 0x4, 0x40, 0xf8, 0x55, 0x8e, 0x18, 0x0, 0x1b, 0x63, 0x26, 0x59, 0x37, 0x8f, 0x2e, 0x93, 0x54, 0x4c, 0x98, 0xa8, + 0x9c, 0xb0, 0x4b, 0xce, 0x40, 0x26, 0xf9, 0xf7, 0xd8, 0x13, 0x55, 0x3, 0x1a, 0xfc, 0x40, 0x57, 0x9, 0x0, 0x3, + 0x60, 0x90, 0x37, 0x1c, 0x0, 0x1a, 0x1f, 0xcb, 0x76, 0xd4, 0x8f, 0xb7, 0x17, 0xdb, 0x4b, 0xbd, 0x1e, 0xe8, 0xc9, + 0x44, 0x60, 0x7, 0x21, 0xf, 0xc8, 0xfe, 0x6, 0x59, 0x1e, 0xb7, 0x7c, 0x4d, 0x2, 0x0, 0x18, 0x5b, 0xe, 0xf2, + 0xb7, 0x96, 0xdc, 0xe2, 0x8f, 0x15, 0xa1, 0x11, 0x6a, 0xaf, 0xdd, 0xf0, 0x70, 0x3a, 0x9a, 0x3b, 0x68, 0x5e, 0x3e, + 0xa1, 0xfa, 0x12, 0x0, 0x2, 0x2d, 0x8f, 0x28}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0}; + lwmqtt_string_t topic_filter_s0 = {0, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x8d, 0xa4, 0xc6}; + lwmqtt_string_t topic_filter_s1 = {3, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x6e, 0x9a, 0x1c, 0x1, 0xa3}; + lwmqtt_string_t topic_filter_s2 = {5, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x25, 0x2b, 0x5c, 0x1, 0x3, 0x8b, 0x67, 0x3f, 0x68}; + lwmqtt_string_t topic_filter_s3 = {9, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xe9, 0xd0, 0xac, 0xcc, 0xd4, 0xea, 0x3, 0x59, 0x50, 0xc0, + 0xa3, 0xd9, 0x78, 0x12, 0x9a, 0x90, 0x8f, 0x40, 0x31, 0xf0, + 0xce, 0x3c, 0x43, 0x8b, 0xe9, 0x34, 0x82, 0x31, 0x84, 0xe9}; + lwmqtt_string_t topic_filter_s4 = {30, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x40, 0xf8, 0x55, 0x8e}; + lwmqtt_string_t topic_filter_s5 = {4, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x63, 0x26, 0x59, 0x37, 0x8f, 0x2e, 0x93, 0x54, 0x4c, 0x98, 0xa8, 0x9c, 0xb0, 0x4b, + 0xce, 0x40, 0x26, 0xf9, 0xf7, 0xd8, 0x13, 0x55, 0x3, 0x1a, 0xfc, 0x40, 0x57}; + lwmqtt_string_t topic_filter_s6 = {27, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x60, 0x90, 0x37}; + lwmqtt_string_t topic_filter_s7 = {3, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x1f, 0xcb, 0x76, 0xd4, 0x8f, 0xb7, 0x17, 0xdb, 0x4b, 0xbd, 0x1e, 0xe8, 0xc9, + 0x44, 0x60, 0x7, 0x21, 0xf, 0xc8, 0xfe, 0x6, 0x59, 0x1e, 0xb7, 0x7c, 0x4d}; + lwmqtt_string_t topic_filter_s8 = {26, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x5b, 0xe, 0xf2, 0xb7, 0x96, 0xdc, 0xe2, 0x8f, 0x15, 0xa1, 0x11, 0x6a, + 0xaf, 0xdd, 0xf0, 0x70, 0x3a, 0x9a, 0x3b, 0x68, 0x5e, 0x3e, 0xa1, 0xfa}; + lwmqtt_string_t topic_filter_s9 = {24, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0x2d, 0x8f}; + lwmqtt_string_t topic_filter_s10 = {2, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + lwmqtt_sub_options_t sub_opts[11]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[3].retain_as_published = true; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS0; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[5].retain_as_published = true; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS1; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = true; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS0; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[7].retain_as_published = true; + sub_opts[7].no_local = true; + sub_opts[8].qos = LWMQTT_QOS2; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + sub_opts[9].qos = LWMQTT_QOS2; + sub_opts[9].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[9].retain_as_published = false; + sub_opts[9].no_local = false; + sub_opts[10].qos = LWMQTT_QOS0; + sub_opts[10].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[10].retain_as_published = true; + sub_opts[10].no_local = false; + uint8_t bytesprops0[] = {0}; + uint8_t bytesprops2[] = {0xbb, 0xb, 0x81, 0x89, 0x42, 0x9c, 0x1f, 0x5f, 0x29, 0x48, 0xaa, 0x7a, + 0x5b, 0xf7, 0xdb, 0x98, 0x62, 0xbd, 0xcf, 0x1a, 0x95, 0x63, 0x5f}; + uint8_t bytesprops1[] = {0x17, 0xc8, 0x4, 0x5e, 0xfd, 0xe0}; + uint8_t bytesprops3[] = {0x36, 0x72, 0xae, 0xa0, 0xa8, 0x90, 0x2b, 0xe3, 0x5c, 0x90, 0x81, 0x8e, 0xa4, 0x4, + 0xa1, 0x7a, 0x7e, 0xf6, 0x7a, 0xbb, 0x3d, 0x28, 0x44, 0xd8, 0x98, 0x24, 0x28, 0x4f}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 10961}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 104}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {0, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 93}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {6, (char*)&bytesprops1}, .v = {23, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {28, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 32704}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 10073}}, + }; + + lwmqtt_properties_t props = {8, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 30449, 11, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 32182 [("\FS\DC3\128\252X\ETX\252\165T{QD\211\165q\226\248\251q\206\169A",SubOptions +// {_retainHandling = SendOnSubscribeNew, _retainAsPublished = True, _noLocal = False, _subQoS = QoS1})] +// [PropContentType "VXa\250\218Qr\201\206,\249\143\209(1\180\195\221G\NUL\128X\139\162\&3P\228\225",PropServerReference +// "avZ\231",PropRequestProblemInformation 165,PropReceiveMaximum 26553,PropServerReference +// "\240\STX\212d\171.\bC\145\227\203-\US_\na\211cx\220\205\215\165&o\139\211wg\227",PropSubscriptionIdentifierAvailable +// 184,PropResponseTopic "M#R,\161\247\239w\242\EMd\183gOH\175\DC2\a\151U\254j$I*",PropAuthenticationMethod +// "R\241y\185",PropRequestResponseInformation 201,PropRequestProblemInformation 34,PropMaximumPacketSize +// 8130,PropReceiveMaximum 9709,PropRequestProblemInformation 125,PropResponseInformation +// "\151\213\248\218(eo\210\222S,\DC3\143IN\225\231\DC4\128]\222\236\128\221\211$\209\221d\190",PropResponseInformation +// "l\220r\237\156S\141\196\145\209\155'\235\CAN<\216\175\r\140\206I\173\134\SO\140\186:^\161n",PropContentType +// "7x",PropMessageExpiryInterval 17129] +TEST(Subscribe5QCTest, Encode6) { + uint8_t pkt[] = {0x82, 0xe8, 0x1, 0x7d, 0xb6, 0xcb, 0x1, 0x3, 0x0, 0x1c, 0x56, 0x58, 0x61, 0xfa, 0xda, 0x51, 0x72, + 0xc9, 0xce, 0x2c, 0xf9, 0x8f, 0xd1, 0x28, 0x31, 0xb4, 0xc3, 0xdd, 0x47, 0x0, 0x80, 0x58, 0x8b, 0xa2, + 0x33, 0x50, 0xe4, 0xe1, 0x1c, 0x0, 0x4, 0x61, 0x76, 0x5a, 0xe7, 0x17, 0xa5, 0x21, 0x67, 0xb9, 0x1c, + 0x0, 0x1e, 0xf0, 0x2, 0xd4, 0x64, 0xab, 0x2e, 0x8, 0x43, 0x91, 0xe3, 0xcb, 0x2d, 0x1f, 0x5f, 0xa, + 0x61, 0xd3, 0x63, 0x78, 0xdc, 0xcd, 0xd7, 0xa5, 0x26, 0x6f, 0x8b, 0xd3, 0x77, 0x67, 0xe3, 0x29, 0xb8, + 0x8, 0x0, 0x19, 0x4d, 0x23, 0x52, 0x2c, 0xa1, 0xf7, 0xef, 0x77, 0xf2, 0x19, 0x64, 0xb7, 0x67, 0x4f, + 0x48, 0xaf, 0x12, 0x7, 0x97, 0x55, 0xfe, 0x6a, 0x24, 0x49, 0x2a, 0x15, 0x0, 0x4, 0x52, 0xf1, 0x79, + 0xb9, 0x19, 0xc9, 0x17, 0x22, 0x27, 0x0, 0x0, 0x1f, 0xc2, 0x21, 0x25, 0xed, 0x17, 0x7d, 0x1a, 0x0, + 0x1e, 0x97, 0xd5, 0xf8, 0xda, 0x28, 0x65, 0x6f, 0xd2, 0xde, 0x53, 0x2c, 0x13, 0x8f, 0x49, 0x4e, 0xe1, + 0xe7, 0x14, 0x80, 0x5d, 0xde, 0xec, 0x80, 0xdd, 0xd3, 0x24, 0xd1, 0xdd, 0x64, 0xbe, 0x1a, 0x0, 0x1e, + 0x6c, 0xdc, 0x72, 0xed, 0x9c, 0x53, 0x8d, 0xc4, 0x91, 0xd1, 0x9b, 0x27, 0xeb, 0x18, 0x3c, 0xd8, 0xaf, + 0xd, 0x8c, 0xce, 0x49, 0xad, 0x86, 0xe, 0x8c, 0xba, 0x3a, 0x5e, 0xa1, 0x6e, 0x3, 0x0, 0x2, 0x37, + 0x78, 0x2, 0x0, 0x0, 0x42, 0xe9, 0x0, 0x16, 0x1c, 0x13, 0x80, 0xfc, 0x58, 0x3, 0xfc, 0xa5, 0x54, + 0x7b, 0x51, 0x44, 0xd3, 0xa5, 0x71, 0xe2, 0xf8, 0xfb, 0x71, 0xce, 0xa9, 0x41, 0x19}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x1c, 0x13, 0x80, 0xfc, 0x58, 0x3, 0xfc, 0xa5, 0x54, 0x7b, 0x51, + 0x44, 0xd3, 0xa5, 0x71, 0xe2, 0xf8, 0xfb, 0x71, 0xce, 0xa9, 0x41}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + lwmqtt_sub_options_t sub_opts[1]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = false; + uint8_t bytesprops0[] = {0x56, 0x58, 0x61, 0xfa, 0xda, 0x51, 0x72, 0xc9, 0xce, 0x2c, 0xf9, 0x8f, 0xd1, 0x28, + 0x31, 0xb4, 0xc3, 0xdd, 0x47, 0x0, 0x80, 0x58, 0x8b, 0xa2, 0x33, 0x50, 0xe4, 0xe1}; + uint8_t bytesprops1[] = {0x61, 0x76, 0x5a, 0xe7}; + uint8_t bytesprops2[] = {0xf0, 0x2, 0xd4, 0x64, 0xab, 0x2e, 0x8, 0x43, 0x91, 0xe3, 0xcb, 0x2d, 0x1f, 0x5f, 0xa, + 0x61, 0xd3, 0x63, 0x78, 0xdc, 0xcd, 0xd7, 0xa5, 0x26, 0x6f, 0x8b, 0xd3, 0x77, 0x67, 0xe3}; + uint8_t bytesprops3[] = {0x4d, 0x23, 0x52, 0x2c, 0xa1, 0xf7, 0xef, 0x77, 0xf2, 0x19, 0x64, 0xb7, 0x67, + 0x4f, 0x48, 0xaf, 0x12, 0x7, 0x97, 0x55, 0xfe, 0x6a, 0x24, 0x49, 0x2a}; + uint8_t bytesprops4[] = {0x52, 0xf1, 0x79, 0xb9}; + uint8_t bytesprops5[] = {0x97, 0xd5, 0xf8, 0xda, 0x28, 0x65, 0x6f, 0xd2, 0xde, 0x53, 0x2c, 0x13, 0x8f, 0x49, 0x4e, + 0xe1, 0xe7, 0x14, 0x80, 0x5d, 0xde, 0xec, 0x80, 0xdd, 0xd3, 0x24, 0xd1, 0xdd, 0x64, 0xbe}; + uint8_t bytesprops6[] = {0x6c, 0xdc, 0x72, 0xed, 0x9c, 0x53, 0x8d, 0xc4, 0x91, 0xd1, 0x9b, 0x27, 0xeb, 0x18, 0x3c, + 0xd8, 0xaf, 0xd, 0x8c, 0xce, 0x49, 0xad, 0x86, 0xe, 0x8c, 0xba, 0x3a, 0x5e, 0xa1, 0x6e}; + uint8_t bytesprops7[] = {0x37, 0x78}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)3, .value = {.str = {28, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {4, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 165}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 26553}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {30, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 184}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {25, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {4, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 201}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 34}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 8130}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 9709}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 125}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {30, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {30, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {2, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 17129}}, + }; + + lwmqtt_properties_t props = {17, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 32182, 1, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 318 [("J\EM\RS\185P\242\251\199\SI\NAKzfK\180\a\175(t\FS\178N\EM",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS2}),(".y\253\aln\145\149/\203\DLE\135\254_\241\215\231:\192\163",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = True, _noLocal = False, _subQoS = QoS1}),("\251\175[\171\nR\197",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS0}),("\153\f\DEL0\187\236\132%Lyr\231\f\135\134Mr(f\246",SubOptions {_retainHandling = DoNotSendOnSubscribe, +// _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS1}),("\173t\NUL)\205\182\DC3\CAN\230V\227e\230\128?\177\&1\179V",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = True, _noLocal = True, _subQoS = QoS0}),("\247\129\193tL",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = True, _noLocal = False, _subQoS = QoS2})] [PropUserProperty +// "B/\199V\128\148\148G.F\243\t\182\SUBC" "\NUL\220\253\150\SO{\ENQ\154\SIUK\241\209-\141\178",PropServerKeepAlive +// 20885,PropReasonString "\185\GSs\254qEx\DC1\245\227",PropTopicAlias 447] +TEST(Subscribe5QCTest, Encode7) { + uint8_t pkt[] = {0x82, 0xa9, 0x1, 0x1, 0x3e, 0x37, 0x26, 0x0, 0xf, 0x42, 0x2f, 0xc7, 0x56, 0x80, 0x94, 0x94, + 0x47, 0x2e, 0x46, 0xf3, 0x9, 0xb6, 0x1a, 0x43, 0x0, 0x10, 0x0, 0xdc, 0xfd, 0x96, 0xe, 0x7b, + 0x5, 0x9a, 0xf, 0x55, 0x4b, 0xf1, 0xd1, 0x2d, 0x8d, 0xb2, 0x13, 0x51, 0x95, 0x1f, 0x0, 0xa, + 0xb9, 0x1d, 0x73, 0xfe, 0x71, 0x45, 0x78, 0x11, 0xf5, 0xe3, 0x23, 0x1, 0xbf, 0x0, 0x16, 0x4a, + 0x19, 0x1e, 0xb9, 0x50, 0xf2, 0xfb, 0xc7, 0xf, 0x15, 0x7a, 0x66, 0x4b, 0xb4, 0x7, 0xaf, 0x28, + 0x74, 0x1c, 0xb2, 0x4e, 0x19, 0x6, 0x0, 0x14, 0x2e, 0x79, 0xfd, 0x7, 0x6c, 0x6e, 0x91, 0x95, + 0x2f, 0xcb, 0x10, 0x87, 0xfe, 0x5f, 0xf1, 0xd7, 0xe7, 0x3a, 0xc0, 0xa3, 0x19, 0x0, 0x7, 0xfb, + 0xaf, 0x5b, 0xab, 0xa, 0x52, 0xc5, 0x2c, 0x0, 0x14, 0x99, 0xc, 0x7f, 0x30, 0xbb, 0xec, 0x84, + 0x25, 0x4c, 0x79, 0x72, 0xe7, 0xc, 0x87, 0x86, 0x4d, 0x72, 0x28, 0x66, 0xf6, 0x2d, 0x0, 0x13, + 0xad, 0x74, 0x0, 0x29, 0xcd, 0xb6, 0x13, 0x18, 0xe6, 0x56, 0xe3, 0x65, 0xe6, 0x80, 0x3f, 0xb1, + 0x31, 0xb3, 0x56, 0x1c, 0x0, 0x5, 0xf7, 0x81, 0xc1, 0x74, 0x4c, 0x1a}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[6]; + uint8_t topic_filter_s0_bytes[] = {0x4a, 0x19, 0x1e, 0xb9, 0x50, 0xf2, 0xfb, 0xc7, 0xf, 0x15, 0x7a, + 0x66, 0x4b, 0xb4, 0x7, 0xaf, 0x28, 0x74, 0x1c, 0xb2, 0x4e, 0x19}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x2e, 0x79, 0xfd, 0x7, 0x6c, 0x6e, 0x91, 0x95, 0x2f, 0xcb, + 0x10, 0x87, 0xfe, 0x5f, 0xf1, 0xd7, 0xe7, 0x3a, 0xc0, 0xa3}; + lwmqtt_string_t topic_filter_s1 = {20, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xfb, 0xaf, 0x5b, 0xab, 0xa, 0x52, 0xc5}; + lwmqtt_string_t topic_filter_s2 = {7, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x99, 0xc, 0x7f, 0x30, 0xbb, 0xec, 0x84, 0x25, 0x4c, 0x79, + 0x72, 0xe7, 0xc, 0x87, 0x86, 0x4d, 0x72, 0x28, 0x66, 0xf6}; + lwmqtt_string_t topic_filter_s3 = {20, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xad, 0x74, 0x0, 0x29, 0xcd, 0xb6, 0x13, 0x18, 0xe6, 0x56, + 0xe3, 0x65, 0xe6, 0x80, 0x3f, 0xb1, 0x31, 0xb3, 0x56}; + lwmqtt_string_t topic_filter_s4 = {19, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xf7, 0x81, 0xc1, 0x74, 0x4c}; + lwmqtt_string_t topic_filter_s5 = {5, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + lwmqtt_sub_options_t sub_opts[6]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[3].retain_as_published = true; + sub_opts[3].no_local = true; + sub_opts[4].qos = LWMQTT_QOS0; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[4].retain_as_published = true; + sub_opts[4].no_local = true; + sub_opts[5].qos = LWMQTT_QOS2; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[5].retain_as_published = true; + sub_opts[5].no_local = false; + uint8_t bytesprops1[] = {0x0, 0xdc, 0xfd, 0x96, 0xe, 0x7b, 0x5, 0x9a, 0xf, 0x55, 0x4b, 0xf1, 0xd1, 0x2d, 0x8d, 0xb2}; + uint8_t bytesprops0[] = {0x42, 0x2f, 0xc7, 0x56, 0x80, 0x94, 0x94, 0x47, 0x2e, 0x46, 0xf3, 0x9, 0xb6, 0x1a, 0x43}; + uint8_t bytesprops2[] = {0xb9, 0x1d, 0x73, 0xfe, 0x71, 0x45, 0x78, 0x11, 0xf5, 0xe3}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {15, (char*)&bytesprops0}, .v = {16, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 20885}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {10, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 447}}, + }; + + lwmqtt_properties_t props = {4, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 318, 6, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 31558 [("\186\232\r\SYN\DC4\129Eu\DC1]\160\174]",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS0}),("]\SO]\180\174O'\150\129\199\150\128\136B\133\198\140\191\138\FS\ETBvk\239\243",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS2}),("\a0\ACKvKF\251\218J\SUB\ESC\215\200\147\192\231\206\193",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS2}),("\196\254\198\168\156\215a\242s\210\168\234u\178\ESC\254\160U\214_4U\230&\184\226\GS\156",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = QoS0})] +// [PropSubscriptionIdentifier 6,PropSessionExpiryInterval 25639,PropSharedSubscriptionAvailable 240,PropMaximumQoS +// 232,PropReceiveMaximum 25892,PropAuthenticationData "X\128@\138s\145K\ACK\231\&8",PropRequestProblemInformation +// 7,PropSubscriptionIdentifier 20,PropSubscriptionIdentifierAvailable 222,PropRequestProblemInformation +// 228,PropWildcardSubscriptionAvailable 156,PropMaximumQoS 151,PropReasonString +// "\178*\149\218BAZ\SYN\243X\250\155%\159\EMn\214",PropResponseTopic +// "\219\155\169\205\153",PropSubscriptionIdentifierAvailable 57,PropSessionExpiryInterval 12500] +TEST(Subscribe5QCTest, Encode8) { + uint8_t pkt[] = {0x82, 0xad, 0x1, 0x7b, 0x46, 0x4a, 0xb, 0x6, 0x11, 0x0, 0x0, 0x64, 0x27, 0x2a, 0xf0, 0x24, + 0xe8, 0x21, 0x65, 0x24, 0x16, 0x0, 0xa, 0x58, 0x80, 0x40, 0x8a, 0x73, 0x91, 0x4b, 0x6, 0xe7, + 0x38, 0x17, 0x7, 0xb, 0x14, 0x29, 0xde, 0x17, 0xe4, 0x28, 0x9c, 0x24, 0x97, 0x1f, 0x0, 0x11, + 0xb2, 0x2a, 0x95, 0xda, 0x42, 0x41, 0x5a, 0x16, 0xf3, 0x58, 0xfa, 0x9b, 0x25, 0x9f, 0x19, 0x6e, + 0xd6, 0x8, 0x0, 0x5, 0xdb, 0x9b, 0xa9, 0xcd, 0x99, 0x29, 0x39, 0x11, 0x0, 0x0, 0x30, 0xd4, + 0x0, 0xd, 0xba, 0xe8, 0xd, 0x16, 0x14, 0x81, 0x45, 0x75, 0x11, 0x5d, 0xa0, 0xae, 0x5d, 0x4, + 0x0, 0x19, 0x5d, 0xe, 0x5d, 0xb4, 0xae, 0x4f, 0x27, 0x96, 0x81, 0xc7, 0x96, 0x80, 0x88, 0x42, + 0x85, 0xc6, 0x8c, 0xbf, 0x8a, 0x1c, 0x17, 0x76, 0x6b, 0xef, 0xf3, 0x16, 0x0, 0x12, 0x7, 0x30, + 0x6, 0x76, 0x4b, 0x46, 0xfb, 0xda, 0x4a, 0x1a, 0x1b, 0xd7, 0xc8, 0x93, 0xc0, 0xe7, 0xce, 0xc1, + 0xe, 0x0, 0x1c, 0xc4, 0xfe, 0xc6, 0xa8, 0x9c, 0xd7, 0x61, 0xf2, 0x73, 0xd2, 0xa8, 0xea, 0x75, + 0xb2, 0x1b, 0xfe, 0xa0, 0x55, 0xd6, 0x5f, 0x34, 0x55, 0xe6, 0x26, 0xb8, 0xe2, 0x1d, 0x9c, 0x2c}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[4]; + uint8_t topic_filter_s0_bytes[] = {0xba, 0xe8, 0xd, 0x16, 0x14, 0x81, 0x45, 0x75, 0x11, 0x5d, 0xa0, 0xae, 0x5d}; + lwmqtt_string_t topic_filter_s0 = {13, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x5d, 0xe, 0x5d, 0xb4, 0xae, 0x4f, 0x27, 0x96, 0x81, 0xc7, 0x96, 0x80, 0x88, + 0x42, 0x85, 0xc6, 0x8c, 0xbf, 0x8a, 0x1c, 0x17, 0x76, 0x6b, 0xef, 0xf3}; + lwmqtt_string_t topic_filter_s1 = {25, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x7, 0x30, 0x6, 0x76, 0x4b, 0x46, 0xfb, 0xda, 0x4a, + 0x1a, 0x1b, 0xd7, 0xc8, 0x93, 0xc0, 0xe7, 0xce, 0xc1}; + lwmqtt_string_t topic_filter_s2 = {18, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xc4, 0xfe, 0xc6, 0xa8, 0x9c, 0xd7, 0x61, 0xf2, 0x73, 0xd2, + 0xa8, 0xea, 0x75, 0xb2, 0x1b, 0xfe, 0xa0, 0x55, 0xd6, 0x5f, + 0x34, 0x55, 0xe6, 0x26, 0xb8, 0xe2, 0x1d, 0x9c}; + lwmqtt_string_t topic_filter_s3 = {28, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + lwmqtt_sub_options_t sub_opts[4]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[3].retain_as_published = true; + sub_opts[3].no_local = true; + uint8_t bytesprops0[] = {0x58, 0x80, 0x40, 0x8a, 0x73, 0x91, 0x4b, 0x6, 0xe7, 0x38}; + uint8_t bytesprops1[] = {0xb2, 0x2a, 0x95, 0xda, 0x42, 0x41, 0x5a, 0x16, 0xf3, + 0x58, 0xfa, 0x9b, 0x25, 0x9f, 0x19, 0x6e, 0xd6}; + uint8_t bytesprops2[] = {0xdb, 0x9b, 0xa9, 0xcd, 0x99}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 6}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 25639}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 240}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 232}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 25892}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {10, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 7}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 20}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 222}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 228}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 156}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 151}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {17, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {5, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 57}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 12500}}, + }; + + lwmqtt_properties_t props = {16, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 31558, 4, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 10059 [("cF\140\DC1z\250\a\232\178\255\221\154\NUL\134\244",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS1}),("\172J\178\137\215\158\178n\196\166\\$a\"\143GH\CANW\134Se\bs\162z\153\v",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS0}),("\146\169\&0\151\152\139\133\211\188\241\SUB\DC2N)\139\165\150",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = QoS2}),("\243\168\&6\166",SubOptions +// {_retainHandling = SendOnSubscribeNew, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS1}),("G\245\200\151Cv\222\205\151\133\243",SubOptions {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished +// = True, _noLocal = True, _subQoS = QoS1}),("\135oO\NUL\183j-",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("Y;d\189L\226\200\163\134\156\180\242\218(\DC4\254\238\144 ",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = True, _noLocal = True, _subQoS = QoS1})] [PropServerKeepAlive 12247,PropPayloadFormatIndicator +// 117,PropRetainAvailable 183,PropWildcardSubscriptionAvailable 146,PropServerReference +// "\RS\248\183\186\152a\177G\250s\250\195`\171\&7\148+2)1_\ESCf$Lr",PropReasonString +// "y\215\162\t\150\254\STX\223\170\197\FS\a\173>k\181O\142\174\148\237\&62\176wA\197:",PropPayloadFormatIndicator +// 156,PropUserProperty "\DC2\243\162\232y\233\178f\176\DC3\133\145\222\140T\136" +// "\205\&7\196\189H_\208\169\t\191>\n\151\188%\150\150Z\176\194\152",PropSubscriptionIdentifier +// 6,PropSharedSubscriptionAvailable 135,PropAuthenticationData +// "wg\172\&4J\141\254yr\DC4dH\a\132\227\143[\NAK-\179\243",PropServerReference +// "\207W\206\212\166-E\168\&3\170h\142\228\202",PropUserProperty +// "wu\128\131\173Z\187/\234\180\128-r\156\197\142\136\224 \160}J" "\216\DC1\164fC",PropAssignedClientIdentifier +// "\CAN\215\158\156a\205\CAN8q\155\157?\138\186\142\DEL\ENQ\224`\DLEf?\RSh~\206\239\\\214\251",PropRetainAvailable +// 251,PropWillDelayInterval 20547,PropSharedSubscriptionAvailable 206,PropServerKeepAlive 17138,PropTopicAliasMaximum +// 29125,PropMessageExpiryInterval 31816,PropResponseInformation +// "{\189*\234ZY\SUB\232\130\GS\216\239\177\159\245\188\186\235\153\184\177\223\CAN\169\218AvH\186\170",PropWildcardSubscriptionAvailable +// 8,PropMaximumPacketSize 8949,PropReceiveMaximum 7552,PropPayloadFormatIndicator 78,PropContentType +// "\SYN&7\213{\193q\153\184X*\194\148\237\211=",PropTopicAliasMaximum 1554,PropRequestProblemInformation 28] +TEST(Subscribe5QCTest, Encode9) { + uint8_t pkt[] = { + 0x82, 0xb6, 0x3, 0x27, 0x4b, 0xb8, 0x2, 0x13, 0x2f, 0xd7, 0x1, 0x75, 0x25, 0xb7, 0x28, 0x92, 0x1c, 0x0, 0x1a, + 0x1e, 0xf8, 0xb7, 0xba, 0x98, 0x61, 0xb1, 0x47, 0xfa, 0x73, 0xfa, 0xc3, 0x60, 0xab, 0x37, 0x94, 0x2b, 0x32, 0x29, + 0x31, 0x5f, 0x1b, 0x66, 0x24, 0x4c, 0x72, 0x1f, 0x0, 0x1c, 0x79, 0xd7, 0xa2, 0x9, 0x96, 0xfe, 0x2, 0xdf, 0xaa, + 0xc5, 0x1c, 0x7, 0xad, 0x3e, 0x6b, 0xb5, 0x4f, 0x8e, 0xae, 0x94, 0xed, 0x36, 0x32, 0xb0, 0x77, 0x41, 0xc5, 0x3a, + 0x1, 0x9c, 0x26, 0x0, 0x10, 0x12, 0xf3, 0xa2, 0xe8, 0x79, 0xe9, 0xb2, 0x66, 0xb0, 0x13, 0x85, 0x91, 0xde, 0x8c, + 0x54, 0x88, 0x0, 0x15, 0xcd, 0x37, 0xc4, 0xbd, 0x48, 0x5f, 0xd0, 0xa9, 0x9, 0xbf, 0x3e, 0xa, 0x97, 0xbc, 0x25, + 0x96, 0x96, 0x5a, 0xb0, 0xc2, 0x98, 0xb, 0x6, 0x2a, 0x87, 0x16, 0x0, 0x15, 0x77, 0x67, 0xac, 0x34, 0x4a, 0x8d, + 0xfe, 0x79, 0x72, 0x14, 0x64, 0x48, 0x7, 0x84, 0xe3, 0x8f, 0x5b, 0x15, 0x2d, 0xb3, 0xf3, 0x1c, 0x0, 0xe, 0xcf, + 0x57, 0xce, 0xd4, 0xa6, 0x2d, 0x45, 0xa8, 0x33, 0xaa, 0x68, 0x8e, 0xe4, 0xca, 0x26, 0x0, 0x16, 0x77, 0x75, 0x80, + 0x83, 0xad, 0x5a, 0xbb, 0x2f, 0xea, 0xb4, 0x80, 0x2d, 0x72, 0x9c, 0xc5, 0x8e, 0x88, 0xe0, 0x20, 0xa0, 0x7d, 0x4a, + 0x0, 0x5, 0xd8, 0x11, 0xa4, 0x66, 0x43, 0x12, 0x0, 0x1e, 0x18, 0xd7, 0x9e, 0x9c, 0x61, 0xcd, 0x18, 0x38, 0x71, + 0x9b, 0x9d, 0x3f, 0x8a, 0xba, 0x8e, 0x7f, 0x5, 0xe0, 0x60, 0x10, 0x66, 0x3f, 0x1e, 0x68, 0x7e, 0xce, 0xef, 0x5c, + 0xd6, 0xfb, 0x25, 0xfb, 0x18, 0x0, 0x0, 0x50, 0x43, 0x2a, 0xce, 0x13, 0x42, 0xf2, 0x22, 0x71, 0xc5, 0x2, 0x0, + 0x0, 0x7c, 0x48, 0x1a, 0x0, 0x1e, 0x7b, 0xbd, 0x2a, 0xea, 0x5a, 0x59, 0x1a, 0xe8, 0x82, 0x1d, 0xd8, 0xef, 0xb1, + 0x9f, 0xf5, 0xbc, 0xba, 0xeb, 0x99, 0xb8, 0xb1, 0xdf, 0x18, 0xa9, 0xda, 0x41, 0x76, 0x48, 0xba, 0xaa, 0x28, 0x8, + 0x27, 0x0, 0x0, 0x22, 0xf5, 0x21, 0x1d, 0x80, 0x1, 0x4e, 0x3, 0x0, 0x10, 0x16, 0x26, 0x37, 0xd5, 0x7b, 0xc1, + 0x71, 0x99, 0xb8, 0x58, 0x2a, 0xc2, 0x94, 0xed, 0xd3, 0x3d, 0x22, 0x6, 0x12, 0x17, 0x1c, 0x0, 0xf, 0x63, 0x46, + 0x8c, 0x11, 0x7a, 0xfa, 0x7, 0xe8, 0xb2, 0xff, 0xdd, 0x9a, 0x0, 0x86, 0xf4, 0x2d, 0x0, 0x1c, 0xac, 0x4a, 0xb2, + 0x89, 0xd7, 0x9e, 0xb2, 0x6e, 0xc4, 0xa6, 0x5c, 0x24, 0x61, 0x22, 0x8f, 0x47, 0x48, 0x18, 0x57, 0x86, 0x53, 0x65, + 0x8, 0x73, 0xa2, 0x7a, 0x99, 0xb, 0x28, 0x0, 0x11, 0x92, 0xa9, 0x30, 0x97, 0x98, 0x8b, 0x85, 0xd3, 0xbc, 0xf1, + 0x1a, 0x12, 0x4e, 0x29, 0x8b, 0xa5, 0x96, 0x6, 0x0, 0x4, 0xf3, 0xa8, 0x36, 0xa6, 0x15, 0x0, 0xb, 0x47, 0xf5, + 0xc8, 0x97, 0x43, 0x76, 0xde, 0xcd, 0x97, 0x85, 0xf3, 0x2d, 0x0, 0x7, 0x87, 0x6f, 0x4f, 0x0, 0xb7, 0x6a, 0x2d, + 0x12, 0x0, 0x13, 0x59, 0x3b, 0x64, 0xbd, 0x4c, 0xe2, 0xc8, 0xa3, 0x86, 0x9c, 0xb4, 0xf2, 0xda, 0x28, 0x14, 0xfe, + 0xee, 0x90, 0x20, 0xd}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0x63, 0x46, 0x8c, 0x11, 0x7a, 0xfa, 0x7, 0xe8, + 0xb2, 0xff, 0xdd, 0x9a, 0x0, 0x86, 0xf4}; + lwmqtt_string_t topic_filter_s0 = {15, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xac, 0x4a, 0xb2, 0x89, 0xd7, 0x9e, 0xb2, 0x6e, 0xc4, 0xa6, 0x5c, 0x24, 0x61, 0x22, + 0x8f, 0x47, 0x48, 0x18, 0x57, 0x86, 0x53, 0x65, 0x8, 0x73, 0xa2, 0x7a, 0x99, 0xb}; + lwmqtt_string_t topic_filter_s1 = {28, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x92, 0xa9, 0x30, 0x97, 0x98, 0x8b, 0x85, 0xd3, 0xbc, + 0xf1, 0x1a, 0x12, 0x4e, 0x29, 0x8b, 0xa5, 0x96}; + lwmqtt_string_t topic_filter_s2 = {17, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xf3, 0xa8, 0x36, 0xa6}; + lwmqtt_string_t topic_filter_s3 = {4, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x47, 0xf5, 0xc8, 0x97, 0x43, 0x76, 0xde, 0xcd, 0x97, 0x85, 0xf3}; + lwmqtt_string_t topic_filter_s4 = {11, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x87, 0x6f, 0x4f, 0x0, 0xb7, 0x6a, 0x2d}; + lwmqtt_string_t topic_filter_s5 = {7, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x59, 0x3b, 0x64, 0xbd, 0x4c, 0xe2, 0xc8, 0xa3, 0x86, 0x9c, + 0xb4, 0xf2, 0xda, 0x28, 0x14, 0xfe, 0xee, 0x90, 0x20}; + lwmqtt_string_t topic_filter_s6 = {19, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + lwmqtt_sub_options_t sub_opts[7]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS0; + sub_opts[1].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = true; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[4].retain_as_published = true; + sub_opts[4].no_local = true; + sub_opts[5].qos = LWMQTT_QOS2; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS1; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = true; + sub_opts[6].no_local = true; + uint8_t bytesprops0[] = {0x1e, 0xf8, 0xb7, 0xba, 0x98, 0x61, 0xb1, 0x47, 0xfa, 0x73, 0xfa, 0xc3, 0x60, + 0xab, 0x37, 0x94, 0x2b, 0x32, 0x29, 0x31, 0x5f, 0x1b, 0x66, 0x24, 0x4c, 0x72}; + uint8_t bytesprops1[] = {0x79, 0xd7, 0xa2, 0x9, 0x96, 0xfe, 0x2, 0xdf, 0xaa, 0xc5, 0x1c, 0x7, 0xad, 0x3e, + 0x6b, 0xb5, 0x4f, 0x8e, 0xae, 0x94, 0xed, 0x36, 0x32, 0xb0, 0x77, 0x41, 0xc5, 0x3a}; + uint8_t bytesprops3[] = {0xcd, 0x37, 0xc4, 0xbd, 0x48, 0x5f, 0xd0, 0xa9, 0x9, 0xbf, 0x3e, + 0xa, 0x97, 0xbc, 0x25, 0x96, 0x96, 0x5a, 0xb0, 0xc2, 0x98}; + uint8_t bytesprops2[] = {0x12, 0xf3, 0xa2, 0xe8, 0x79, 0xe9, 0xb2, 0x66, + 0xb0, 0x13, 0x85, 0x91, 0xde, 0x8c, 0x54, 0x88}; + uint8_t bytesprops4[] = {0x77, 0x67, 0xac, 0x34, 0x4a, 0x8d, 0xfe, 0x79, 0x72, 0x14, 0x64, + 0x48, 0x7, 0x84, 0xe3, 0x8f, 0x5b, 0x15, 0x2d, 0xb3, 0xf3}; + uint8_t bytesprops5[] = {0xcf, 0x57, 0xce, 0xd4, 0xa6, 0x2d, 0x45, 0xa8, 0x33, 0xaa, 0x68, 0x8e, 0xe4, 0xca}; + uint8_t bytesprops7[] = {0xd8, 0x11, 0xa4, 0x66, 0x43}; + uint8_t bytesprops6[] = {0x77, 0x75, 0x80, 0x83, 0xad, 0x5a, 0xbb, 0x2f, 0xea, 0xb4, 0x80, + 0x2d, 0x72, 0x9c, 0xc5, 0x8e, 0x88, 0xe0, 0x20, 0xa0, 0x7d, 0x4a}; + uint8_t bytesprops8[] = {0x18, 0xd7, 0x9e, 0x9c, 0x61, 0xcd, 0x18, 0x38, 0x71, 0x9b, 0x9d, 0x3f, 0x8a, 0xba, 0x8e, + 0x7f, 0x5, 0xe0, 0x60, 0x10, 0x66, 0x3f, 0x1e, 0x68, 0x7e, 0xce, 0xef, 0x5c, 0xd6, 0xfb}; + uint8_t bytesprops9[] = {0x7b, 0xbd, 0x2a, 0xea, 0x5a, 0x59, 0x1a, 0xe8, 0x82, 0x1d, 0xd8, 0xef, 0xb1, 0x9f, 0xf5, + 0xbc, 0xba, 0xeb, 0x99, 0xb8, 0xb1, 0xdf, 0x18, 0xa9, 0xda, 0x41, 0x76, 0x48, 0xba, 0xaa}; + uint8_t bytesprops10[] = {0x16, 0x26, 0x37, 0xd5, 0x7b, 0xc1, 0x71, 0x99, + 0xb8, 0x58, 0x2a, 0xc2, 0x94, 0xed, 0xd3, 0x3d}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 12247}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 117}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 183}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 146}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {26, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {28, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 156}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {16, (char*)&bytesprops2}, .v = {21, (char*)&bytesprops3}}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 6}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 135}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {21, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {14, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {22, (char*)&bytesprops6}, .v = {5, (char*)&bytesprops7}}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {30, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 251}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 20547}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 206}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 17138}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 29125}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 31816}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {30, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 8}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 8949}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 7552}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 78}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {16, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 1554}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 28}}, + }; + + lwmqtt_properties_t props = {28, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 10059, 7, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 17993 [("\174\DC2\180\NUL\142x\203\205\&8\EM\171\148\&3tuFu$\128",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS0}),("\157\230\179\155\184",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = True, _noLocal = +// True, _subQoS = QoS2}),("\176\146\RS\217\&9zmS\US\159\223ODO\200>\166\vR",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS1}),("\161@\171\&2\220\208\169\DC1\214\171\191",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("Q\129\191)\186o\207\155\&4C\134,A;\188i\194^\"]r",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = True, _noLocal = True, _subQoS = QoS2}),("]CN4\DEL\254S\162\235\148\193\251\183",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS2}),("\194c\DC4",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = True, _noLocal = False, +// _subQoS = QoS1}),("c\202\169\191\144\165\DC2%\SYN&\SOH\145\184\228\220\227\185]\163T\187D\253\DC2-\169C",SubOptions +// {_retainHandling = SendOnSubscribeNew, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS1}),("\195\212\131",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = True, +// _subQoS = QoS0})] [PropAssignedClientIdentifier "\194",PropResponseTopic +// "vq\253\145\245\205",PropSubscriptionIdentifier 16,PropReasonString +// "\vu\151A\163\245\FS\156\172\170\\\144\145\218mvD\131\252",PropResponseTopic "\151aL",PropPayloadFormatIndicator +// 116,PropAuthenticationData "\ETX\221",PropSharedSubscriptionAvailable 91,PropTopicAlias +// 11087,PropAssignedClientIdentifier "\242\246\248\235\138\198\ETX\152\NUL\151O\"\130\STXG\172\221",PropServerKeepAlive +// 7955,PropMessageExpiryInterval 24117,PropMaximumPacketSize 1501,PropCorrelationData +// "\186O\239\194\234\211\173BT\198",PropResponseInformation +// "\224\239\201\208N\DLE\RS6\155M\200@\175\230\143",PropResponseInformation +// "\156\v\134\243H\228\178,",PropReceiveMaximum 29967,PropServerKeepAlive 30373,PropAssignedClientIdentifier +// "\STX\223FsUx\151&\220 \150\255\214\\\169v>",PropServerReference "\135",PropAuthenticationMethod +// "\185\"\184\&3\NAK",PropReceiveMaximum 1529,PropSubscriptionIdentifier 30,PropSessionExpiryInterval +// 3694,PropServerReference "\164\233\167'\224",PropMaximumPacketSize 20632,PropSessionExpiryInterval +// 13047,PropAuthenticationMethod "6\218\191\\\131\CAN?7[h",PropResponseTopic "T"] +TEST(Subscribe5QCTest, Encode10) { + uint8_t pkt[] = { + 0x82, 0xed, 0x2, 0x46, 0x49, 0xd5, 0x1, 0x12, 0x0, 0x1, 0xc2, 0x8, 0x0, 0x6, 0x76, 0x71, 0xfd, 0x91, 0xf5, + 0xcd, 0xb, 0x10, 0x1f, 0x0, 0x13, 0xb, 0x75, 0x97, 0x41, 0xa3, 0xf5, 0x1c, 0x9c, 0xac, 0xaa, 0x5c, 0x90, 0x91, + 0xda, 0x6d, 0x76, 0x44, 0x83, 0xfc, 0x8, 0x0, 0x3, 0x97, 0x61, 0x4c, 0x1, 0x74, 0x16, 0x0, 0x2, 0x3, 0xdd, + 0x2a, 0x5b, 0x23, 0x2b, 0x4f, 0x12, 0x0, 0x11, 0xf2, 0xf6, 0xf8, 0xeb, 0x8a, 0xc6, 0x3, 0x98, 0x0, 0x97, 0x4f, + 0x22, 0x82, 0x2, 0x47, 0xac, 0xdd, 0x13, 0x1f, 0x13, 0x2, 0x0, 0x0, 0x5e, 0x35, 0x27, 0x0, 0x0, 0x5, 0xdd, + 0x9, 0x0, 0xa, 0xba, 0x4f, 0xef, 0xc2, 0xea, 0xd3, 0xad, 0x42, 0x54, 0xc6, 0x1a, 0x0, 0xf, 0xe0, 0xef, 0xc9, + 0xd0, 0x4e, 0x10, 0x1e, 0x36, 0x9b, 0x4d, 0xc8, 0x40, 0xaf, 0xe6, 0x8f, 0x1a, 0x0, 0x8, 0x9c, 0xb, 0x86, 0xf3, + 0x48, 0xe4, 0xb2, 0x2c, 0x21, 0x75, 0xf, 0x13, 0x76, 0xa5, 0x12, 0x0, 0x11, 0x2, 0xdf, 0x46, 0x73, 0x55, 0x78, + 0x97, 0x26, 0xdc, 0x20, 0x96, 0xff, 0xd6, 0x5c, 0xa9, 0x76, 0x3e, 0x1c, 0x0, 0x1, 0x87, 0x15, 0x0, 0x5, 0xb9, + 0x22, 0xb8, 0x33, 0x15, 0x21, 0x5, 0xf9, 0xb, 0x1e, 0x11, 0x0, 0x0, 0xe, 0x6e, 0x1c, 0x0, 0x5, 0xa4, 0xe9, + 0xa7, 0x27, 0xe0, 0x27, 0x0, 0x0, 0x50, 0x98, 0x11, 0x0, 0x0, 0x32, 0xf7, 0x15, 0x0, 0xa, 0x36, 0xda, 0xbf, + 0x5c, 0x83, 0x18, 0x3f, 0x37, 0x5b, 0x68, 0x8, 0x0, 0x1, 0x54, 0x0, 0x13, 0xae, 0x12, 0xb4, 0x0, 0x8e, 0x78, + 0xcb, 0xcd, 0x38, 0x19, 0xab, 0x94, 0x33, 0x74, 0x75, 0x46, 0x75, 0x24, 0x80, 0x28, 0x0, 0x5, 0x9d, 0xe6, 0xb3, + 0x9b, 0xb8, 0xe, 0x0, 0x13, 0xb0, 0x92, 0x1e, 0xd9, 0x39, 0x7a, 0x6d, 0x53, 0x1f, 0x9f, 0xdf, 0x4f, 0x44, 0x4f, + 0xc8, 0x3e, 0xa6, 0xb, 0x52, 0x2d, 0x0, 0xb, 0xa1, 0x40, 0xab, 0x32, 0xdc, 0xd0, 0xa9, 0x11, 0xd6, 0xab, 0xbf, + 0x10, 0x0, 0x15, 0x51, 0x81, 0xbf, 0x29, 0xba, 0x6f, 0xcf, 0x9b, 0x34, 0x43, 0x86, 0x2c, 0x41, 0x3b, 0xbc, 0x69, + 0xc2, 0x5e, 0x22, 0x5d, 0x72, 0x1e, 0x0, 0xd, 0x5d, 0x43, 0x4e, 0x34, 0x7f, 0xfe, 0x53, 0xa2, 0xeb, 0x94, 0xc1, + 0xfb, 0xb7, 0x2e, 0x0, 0x3, 0xc2, 0x63, 0x14, 0x9, 0x0, 0x1b, 0x63, 0xca, 0xa9, 0xbf, 0x90, 0xa5, 0x12, 0x25, + 0x16, 0x26, 0x1, 0x91, 0xb8, 0xe4, 0xdc, 0xe3, 0xb9, 0x5d, 0xa3, 0x54, 0xbb, 0x44, 0xfd, 0x12, 0x2d, 0xa9, 0x43, + 0x1d, 0x0, 0x3, 0xc3, 0xd4, 0x83, 0x4}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[9]; + uint8_t topic_filter_s0_bytes[] = {0xae, 0x12, 0xb4, 0x0, 0x8e, 0x78, 0xcb, 0xcd, 0x38, 0x19, + 0xab, 0x94, 0x33, 0x74, 0x75, 0x46, 0x75, 0x24, 0x80}; + lwmqtt_string_t topic_filter_s0 = {19, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x9d, 0xe6, 0xb3, 0x9b, 0xb8}; + lwmqtt_string_t topic_filter_s1 = {5, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xb0, 0x92, 0x1e, 0xd9, 0x39, 0x7a, 0x6d, 0x53, 0x1f, 0x9f, + 0xdf, 0x4f, 0x44, 0x4f, 0xc8, 0x3e, 0xa6, 0xb, 0x52}; + lwmqtt_string_t topic_filter_s2 = {19, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xa1, 0x40, 0xab, 0x32, 0xdc, 0xd0, 0xa9, 0x11, 0xd6, 0xab, 0xbf}; + lwmqtt_string_t topic_filter_s3 = {11, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x51, 0x81, 0xbf, 0x29, 0xba, 0x6f, 0xcf, 0x9b, 0x34, 0x43, 0x86, + 0x2c, 0x41, 0x3b, 0xbc, 0x69, 0xc2, 0x5e, 0x22, 0x5d, 0x72}; + lwmqtt_string_t topic_filter_s4 = {21, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x5d, 0x43, 0x4e, 0x34, 0x7f, 0xfe, 0x53, 0xa2, 0xeb, 0x94, 0xc1, 0xfb, 0xb7}; + lwmqtt_string_t topic_filter_s5 = {13, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xc2, 0x63, 0x14}; + lwmqtt_string_t topic_filter_s6 = {3, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x63, 0xca, 0xa9, 0xbf, 0x90, 0xa5, 0x12, 0x25, 0x16, 0x26, 0x1, 0x91, 0xb8, 0xe4, + 0xdc, 0xe3, 0xb9, 0x5d, 0xa3, 0x54, 0xbb, 0x44, 0xfd, 0x12, 0x2d, 0xa9, 0x43}; + lwmqtt_string_t topic_filter_s7 = {27, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xc3, 0xd4, 0x83}; + lwmqtt_string_t topic_filter_s8 = {3, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + lwmqtt_sub_options_t sub_opts[9]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[4].retain_as_published = true; + sub_opts[4].no_local = true; + sub_opts[5].qos = LWMQTT_QOS2; + sub_opts[5].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[5].retain_as_published = true; + sub_opts[5].no_local = true; + sub_opts[6].qos = LWMQTT_QOS1; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = true; + sub_opts[6].no_local = false; + sub_opts[7].qos = LWMQTT_QOS1; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[7].retain_as_published = true; + sub_opts[7].no_local = true; + sub_opts[8].qos = LWMQTT_QOS0; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = true; + uint8_t bytesprops0[] = {0xc2}; + uint8_t bytesprops1[] = {0x76, 0x71, 0xfd, 0x91, 0xf5, 0xcd}; + uint8_t bytesprops2[] = {0xb, 0x75, 0x97, 0x41, 0xa3, 0xf5, 0x1c, 0x9c, 0xac, 0xaa, + 0x5c, 0x90, 0x91, 0xda, 0x6d, 0x76, 0x44, 0x83, 0xfc}; + uint8_t bytesprops3[] = {0x97, 0x61, 0x4c}; + uint8_t bytesprops4[] = {0x3, 0xdd}; + uint8_t bytesprops5[] = {0xf2, 0xf6, 0xf8, 0xeb, 0x8a, 0xc6, 0x3, 0x98, 0x0, + 0x97, 0x4f, 0x22, 0x82, 0x2, 0x47, 0xac, 0xdd}; + uint8_t bytesprops6[] = {0xba, 0x4f, 0xef, 0xc2, 0xea, 0xd3, 0xad, 0x42, 0x54, 0xc6}; + uint8_t bytesprops7[] = {0xe0, 0xef, 0xc9, 0xd0, 0x4e, 0x10, 0x1e, 0x36, 0x9b, 0x4d, 0xc8, 0x40, 0xaf, 0xe6, 0x8f}; + uint8_t bytesprops8[] = {0x9c, 0xb, 0x86, 0xf3, 0x48, 0xe4, 0xb2, 0x2c}; + uint8_t bytesprops9[] = {0x2, 0xdf, 0x46, 0x73, 0x55, 0x78, 0x97, 0x26, 0xdc, + 0x20, 0x96, 0xff, 0xd6, 0x5c, 0xa9, 0x76, 0x3e}; + uint8_t bytesprops10[] = {0x87}; + uint8_t bytesprops11[] = {0xb9, 0x22, 0xb8, 0x33, 0x15}; + uint8_t bytesprops12[] = {0xa4, 0xe9, 0xa7, 0x27, 0xe0}; + uint8_t bytesprops13[] = {0x36, 0xda, 0xbf, 0x5c, 0x83, 0x18, 0x3f, 0x37, 0x5b, 0x68}; + uint8_t bytesprops14[] = {0x54}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)18, .value = {.str = {1, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {6, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 16}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {19, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {3, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 116}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {2, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 91}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 11087}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {17, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 7955}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 24117}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 1501}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {10, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {15, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {8, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 29967}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 30373}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {17, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {1, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {5, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 1529}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 30}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 3694}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {5, (char*)&bytesprops12}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 20632}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 13047}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {10, (char*)&bytesprops13}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {1, (char*)&bytesprops14}}}, + }; + + lwmqtt_properties_t props = {29, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 17993, 9, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 22386 [("\ESC\146\173A\219\151\151\&3\201\142\247A\240\134\172\207$\SO\214\141\&8J\US\n0",SubOptions +// {_retainHandling = SendOnSubscribeNew, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS2}),("%\152",SubOptions {_retainHandling = SendOnSubscribeNew, _retainAsPublished = True, _noLocal = False, +// _subQoS = QoS1}),("\136\CAN\SOH\212\NUL\t\207.",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// True, _noLocal = True, _subQoS = QoS0}),("\244\191\194\f?~)r^\197\&8\143^2\137\183\151\164<\SI",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS2}),("1\a\ETB\ENQ*\171-\181\195\200\175\177\204.'t\176\205\&1\130",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [PropUserProperty +// "\247\\1\250\140\158" "\210\131\\\244\245\192\179\221u\200\163:'\ESC\229\229,\136",PropSubscriptionIdentifier +// 1,PropSharedSubscriptionAvailable 43,PropSessionExpiryInterval 3441,PropRequestResponseInformation +// 220,PropAssignedClientIdentifier "",PropWildcardSubscriptionAvailable 233,PropMessageExpiryInterval +// 18216,PropTopicAlias 25453,PropMessageExpiryInterval 18186,PropMessageExpiryInterval 11116,PropPayloadFormatIndicator +// 157] +TEST(Subscribe5QCTest, Encode11) { + uint8_t pkt[] = {0x82, 0x9e, 0x1, 0x57, 0x72, 0x41, 0x26, 0x0, 0x6, 0xf7, 0x5c, 0x31, 0xfa, 0x8c, 0x9e, 0x0, 0x12, + 0xd2, 0x83, 0x5c, 0xf4, 0xf5, 0xc0, 0xb3, 0xdd, 0x75, 0xc8, 0xa3, 0x3a, 0x27, 0x1b, 0xe5, 0xe5, 0x2c, + 0x88, 0xb, 0x1, 0x2a, 0x2b, 0x11, 0x0, 0x0, 0xd, 0x71, 0x19, 0xdc, 0x12, 0x0, 0x0, 0x28, 0xe9, + 0x2, 0x0, 0x0, 0x47, 0x28, 0x23, 0x63, 0x6d, 0x2, 0x0, 0x0, 0x47, 0xa, 0x2, 0x0, 0x0, 0x2b, + 0x6c, 0x1, 0x9d, 0x0, 0x19, 0x1b, 0x92, 0xad, 0x41, 0xdb, 0x97, 0x97, 0x33, 0xc9, 0x8e, 0xf7, 0x41, + 0xf0, 0x86, 0xac, 0xcf, 0x24, 0xe, 0xd6, 0x8d, 0x38, 0x4a, 0x1f, 0xa, 0x30, 0x1e, 0x0, 0x2, 0x25, + 0x98, 0x19, 0x0, 0x8, 0x88, 0x18, 0x1, 0xd4, 0x0, 0x9, 0xcf, 0x2e, 0xc, 0x0, 0x14, 0xf4, 0xbf, + 0xc2, 0xc, 0x3f, 0x7e, 0x29, 0x72, 0x5e, 0xc5, 0x38, 0x8f, 0x5e, 0x32, 0x89, 0xb7, 0x97, 0xa4, 0x3c, + 0xf, 0x6, 0x0, 0x14, 0x31, 0x7, 0x17, 0x5, 0x2a, 0xab, 0x2d, 0xb5, 0xc3, 0xc8, 0xaf, 0xb1, 0xcc, + 0x2e, 0x27, 0x74, 0xb0, 0xcd, 0x31, 0x82, 0x10}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0x1b, 0x92, 0xad, 0x41, 0xdb, 0x97, 0x97, 0x33, 0xc9, 0x8e, 0xf7, 0x41, 0xf0, + 0x86, 0xac, 0xcf, 0x24, 0xe, 0xd6, 0x8d, 0x38, 0x4a, 0x1f, 0xa, 0x30}; + lwmqtt_string_t topic_filter_s0 = {25, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x25, 0x98}; + lwmqtt_string_t topic_filter_s1 = {2, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x88, 0x18, 0x1, 0xd4, 0x0, 0x9, 0xcf, 0x2e}; + lwmqtt_string_t topic_filter_s2 = {8, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xf4, 0xbf, 0xc2, 0xc, 0x3f, 0x7e, 0x29, 0x72, 0x5e, 0xc5, + 0x38, 0x8f, 0x5e, 0x32, 0x89, 0xb7, 0x97, 0xa4, 0x3c, 0xf}; + lwmqtt_string_t topic_filter_s3 = {20, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x31, 0x7, 0x17, 0x5, 0x2a, 0xab, 0x2d, 0xb5, 0xc3, 0xc8, + 0xaf, 0xb1, 0xcc, 0x2e, 0x27, 0x74, 0xb0, 0xcd, 0x31, 0x82}; + lwmqtt_string_t topic_filter_s4 = {20, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + lwmqtt_sub_options_t sub_opts[5]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS2; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = true; + sub_opts[4].qos = LWMQTT_QOS0; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + uint8_t bytesprops1[] = {0xd2, 0x83, 0x5c, 0xf4, 0xf5, 0xc0, 0xb3, 0xdd, 0x75, + 0xc8, 0xa3, 0x3a, 0x27, 0x1b, 0xe5, 0xe5, 0x2c, 0x88}; + uint8_t bytesprops0[] = {0xf7, 0x5c, 0x31, 0xfa, 0x8c, 0x9e}; + uint8_t bytesprops2[] = {0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {6, (char*)&bytesprops0}, .v = {18, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 1}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 43}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 3441}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 220}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {0, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 233}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 18216}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 25453}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 18186}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 11116}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 157}}, + }; + + lwmqtt_properties_t props = {12, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 22386, 5, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 7096 [("t\181\243\135\224I\128\&4\216~\NAK",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS0}),("oi\ETB\249\n\USG<]vF\175@D\"no\DC3\222T\STX\212",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = True, _subQoS = QoS1}),("\167-\197\214G\192r\204",SubOptions {_retainHandling +// = SendOnSubscribeNew, _retainAsPublished = True, _noLocal = False, _subQoS = QoS2}),("\153!\144t",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS2}),("\ESC\148<\147\252\182o\137\rT\129\180db\204\246\SOG\227f\167",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS2}),("\170\134\239w\241\233\GS",SubOptions {_retainHandling = SendOnSubscribeNew, _retainAsPublished = True, +// _noLocal = False, _subQoS = QoS0}),("f2$\160\161\178\217\&0\EM\234&\146\SYN +// q\167\202\213\236\142\188\152\205\187t\n\237\166",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = False, _noLocal = True, _subQoS = QoS2})] [PropResponseTopic +// "\201#\148F\DC4\177\232P",PropCorrelationData "|\214\226\SYN\252\207\138\\\150"] +TEST(Subscribe5QCTest, Encode12) { + uint8_t pkt[] = {0x82, 0x94, 0x1, 0x1b, 0xb8, 0x17, 0x8, 0x0, 0x8, 0xc9, 0x23, 0x94, 0x46, 0x14, 0xb1, 0xe8, 0x50, + 0x9, 0x0, 0x9, 0x7c, 0xd6, 0xe2, 0x16, 0xfc, 0xcf, 0x8a, 0x5c, 0x96, 0x0, 0xb, 0x74, 0xb5, 0xf3, + 0x87, 0xe0, 0x49, 0x80, 0x34, 0xd8, 0x7e, 0x15, 0x14, 0x0, 0x16, 0x6f, 0x69, 0x17, 0xf9, 0xa, 0x1f, + 0x47, 0x3c, 0x5d, 0x76, 0x46, 0xaf, 0x40, 0x44, 0x22, 0x6e, 0x6f, 0x13, 0xde, 0x54, 0x2, 0xd4, 0x5, + 0x0, 0x8, 0xa7, 0x2d, 0xc5, 0xd6, 0x47, 0xc0, 0x72, 0xcc, 0x1a, 0x0, 0x4, 0x99, 0x21, 0x90, 0x74, + 0xe, 0x0, 0x15, 0x1b, 0x94, 0x3c, 0x93, 0xfc, 0xb6, 0x6f, 0x89, 0xd, 0x54, 0x81, 0xb4, 0x64, 0x62, + 0xcc, 0xf6, 0xe, 0x47, 0xe3, 0x66, 0xa7, 0x2e, 0x0, 0x7, 0xaa, 0x86, 0xef, 0x77, 0xf1, 0xe9, 0x1d, + 0x18, 0x0, 0x1c, 0x66, 0x32, 0x24, 0xa0, 0xa1, 0xb2, 0xd9, 0x30, 0x19, 0xea, 0x26, 0x92, 0x16, 0x20, + 0x71, 0xa7, 0xca, 0xd5, 0xec, 0x8e, 0xbc, 0x98, 0xcd, 0xbb, 0x74, 0xa, 0xed, 0xa6, 0x16}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0x74, 0xb5, 0xf3, 0x87, 0xe0, 0x49, 0x80, 0x34, 0xd8, 0x7e, 0x15}; + lwmqtt_string_t topic_filter_s0 = {11, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x6f, 0x69, 0x17, 0xf9, 0xa, 0x1f, 0x47, 0x3c, 0x5d, 0x76, 0x46, + 0xaf, 0x40, 0x44, 0x22, 0x6e, 0x6f, 0x13, 0xde, 0x54, 0x2, 0xd4}; + lwmqtt_string_t topic_filter_s1 = {22, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xa7, 0x2d, 0xc5, 0xd6, 0x47, 0xc0, 0x72, 0xcc}; + lwmqtt_string_t topic_filter_s2 = {8, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x99, 0x21, 0x90, 0x74}; + lwmqtt_string_t topic_filter_s3 = {4, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x1b, 0x94, 0x3c, 0x93, 0xfc, 0xb6, 0x6f, 0x89, 0xd, 0x54, 0x81, + 0xb4, 0x64, 0x62, 0xcc, 0xf6, 0xe, 0x47, 0xe3, 0x66, 0xa7}; + lwmqtt_string_t topic_filter_s4 = {21, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xaa, 0x86, 0xef, 0x77, 0xf1, 0xe9, 0x1d}; + lwmqtt_string_t topic_filter_s5 = {7, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x66, 0x32, 0x24, 0xa0, 0xa1, 0xb2, 0xd9, 0x30, 0x19, 0xea, + 0x26, 0x92, 0x16, 0x20, 0x71, 0xa7, 0xca, 0xd5, 0xec, 0x8e, + 0xbc, 0x98, 0xcd, 0xbb, 0x74, 0xa, 0xed, 0xa6}; + lwmqtt_string_t topic_filter_s6 = {28, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + lwmqtt_sub_options_t sub_opts[7]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS2; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = true; + sub_opts[3].no_local = true; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[4].retain_as_published = true; + sub_opts[4].no_local = true; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[5].retain_as_published = true; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS2; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = true; + uint8_t bytesprops0[] = {0xc9, 0x23, 0x94, 0x46, 0x14, 0xb1, 0xe8, 0x50}; + uint8_t bytesprops1[] = {0x7c, 0xd6, 0xe2, 0x16, 0xfc, 0xcf, 0x8a, 0x5c, 0x96}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)8, .value = {.str = {8, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {9, (char*)&bytesprops1}}}, + }; + + lwmqtt_properties_t props = {2, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 7096, 7, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 12819 [("\r\ACKA\165\FS\187\vpF\231\155>\162q\nM\192\252\f{\178\b\a@v\131\215\152f",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS2}),("Q\231s7H\ENQ#\143o\a\251\STXW\201\177\196{",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("$\142\140\198",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [PropContentType +// "Wx\137\138\149\213 MO\222\STX\180\209'\134\&3",PropTopicAlias 16280,PropMaximumPacketSize +// 32255,PropTopicAliasMaximum 28531,PropAssignedClientIdentifier +// "\198\219\DC1\214\133\142U",PropSharedSubscriptionAvailable 135,PropUserProperty +// "P\204\216IY\ETX\196I)\166\243\243\207\191g\227\STXSL%\tF\199S\205\204b" +// "\219\&0\241@\GSN9\142B>\242=\152T\240\161\168",PropMaximumPacketSize 18181,PropMaximumPacketSize +// 19439,PropCorrelationData "^\154\173\DC2\148\144\193-a\148x.\DC3\246\162N\SYN\ESC\133",PropMaximumQoS +// 119,PropMaximumQoS 19,PropServerKeepAlive 30628,PropRequestProblemInformation 190,PropServerKeepAlive +// 23203,PropAssignedClientIdentifier "\136r\160t",PropRetainAvailable 240,PropSessionExpiryInterval +// 1968,PropReasonString "7s\210b\252\DEL\147\150\FSp\244\&8%",PropServerKeepAlive 1701,PropResponseInformation +// "\200$\135\220",PropReasonString +// "\FS\218\249D\SI\211\SYN\ACKs\182]\133\171\213\194}\STX\142\208",PropAssignedClientIdentifier +// "9g\132\&6\142\191\233\162AP\176\181\141\179\&8\142HC@\DC3\RS",PropMessageExpiryInterval +// 26022,PropPayloadFormatIndicator 18,PropAuthenticationData +// "1\196\239\194\213\EM-\228\197\SI]\183O\189\255Iwsy",PropWildcardSubscriptionAvailable 197,PropSubscriptionIdentifier +// 11,PropResponseTopic +// "?'\232\v4\213\SYN\171\191\EOT\163_\ACK\135v\DC4\SYN\158u\DEL:\235\ETX\EME\194\&2G",PropServerReference +// "N\DC2\243n\192a+\172t3B@m,h\SUB\248\225Kt\bv\238\254FY\164'"] +TEST(Subscribe5QCTest, Encode13) { + uint8_t pkt[] = { + 0x82, 0xfb, 0x2, 0x32, 0x13, 0xbc, 0x2, 0x3, 0x0, 0x10, 0x57, 0x78, 0x89, 0x8a, 0x95, 0xd5, 0x20, 0x4d, 0x4f, + 0xde, 0x2, 0xb4, 0xd1, 0x27, 0x86, 0x33, 0x23, 0x3f, 0x98, 0x27, 0x0, 0x0, 0x7d, 0xff, 0x22, 0x6f, 0x73, 0x12, + 0x0, 0x7, 0xc6, 0xdb, 0x11, 0xd6, 0x85, 0x8e, 0x55, 0x2a, 0x87, 0x26, 0x0, 0x1b, 0x50, 0xcc, 0xd8, 0x49, 0x59, + 0x3, 0xc4, 0x49, 0x29, 0xa6, 0xf3, 0xf3, 0xcf, 0xbf, 0x67, 0xe3, 0x2, 0x53, 0x4c, 0x25, 0x9, 0x46, 0xc7, 0x53, + 0xcd, 0xcc, 0x62, 0x0, 0x11, 0xdb, 0x30, 0xf1, 0x40, 0x1d, 0x4e, 0x39, 0x8e, 0x42, 0x3e, 0xf2, 0x3d, 0x98, 0x54, + 0xf0, 0xa1, 0xa8, 0x27, 0x0, 0x0, 0x47, 0x5, 0x27, 0x0, 0x0, 0x4b, 0xef, 0x9, 0x0, 0x13, 0x5e, 0x9a, 0xad, + 0x12, 0x94, 0x90, 0xc1, 0x2d, 0x61, 0x94, 0x78, 0x2e, 0x13, 0xf6, 0xa2, 0x4e, 0x16, 0x1b, 0x85, 0x24, 0x77, 0x24, + 0x13, 0x13, 0x77, 0xa4, 0x17, 0xbe, 0x13, 0x5a, 0xa3, 0x12, 0x0, 0x4, 0x88, 0x72, 0xa0, 0x74, 0x25, 0xf0, 0x11, + 0x0, 0x0, 0x7, 0xb0, 0x1f, 0x0, 0xd, 0x37, 0x73, 0xd2, 0x62, 0xfc, 0x7f, 0x93, 0x96, 0x1c, 0x70, 0xf4, 0x38, + 0x25, 0x13, 0x6, 0xa5, 0x1a, 0x0, 0x4, 0xc8, 0x24, 0x87, 0xdc, 0x1f, 0x0, 0x13, 0x1c, 0xda, 0xf9, 0x44, 0xf, + 0xd3, 0x16, 0x6, 0x73, 0xb6, 0x5d, 0x85, 0xab, 0xd5, 0xc2, 0x7d, 0x2, 0x8e, 0xd0, 0x12, 0x0, 0x15, 0x39, 0x67, + 0x84, 0x36, 0x8e, 0xbf, 0xe9, 0xa2, 0x41, 0x50, 0xb0, 0xb5, 0x8d, 0xb3, 0x38, 0x8e, 0x48, 0x43, 0x40, 0x13, 0x1e, + 0x2, 0x0, 0x0, 0x65, 0xa6, 0x1, 0x12, 0x16, 0x0, 0x13, 0x31, 0xc4, 0xef, 0xc2, 0xd5, 0x19, 0x2d, 0xe4, 0xc5, + 0xf, 0x5d, 0xb7, 0x4f, 0xbd, 0xff, 0x49, 0x77, 0x73, 0x79, 0x28, 0xc5, 0xb, 0xb, 0x8, 0x0, 0x1c, 0x3f, 0x27, + 0xe8, 0xb, 0x34, 0xd5, 0x16, 0xab, 0xbf, 0x4, 0xa3, 0x5f, 0x6, 0x87, 0x76, 0x14, 0x16, 0x9e, 0x75, 0x7f, 0x3a, + 0xeb, 0x3, 0x19, 0x45, 0xc2, 0x32, 0x47, 0x1c, 0x0, 0x1c, 0x4e, 0x12, 0xf3, 0x6e, 0xc0, 0x61, 0x2b, 0xac, 0x74, + 0x33, 0x42, 0x40, 0x6d, 0x2c, 0x68, 0x1a, 0xf8, 0xe1, 0x4b, 0x74, 0x8, 0x76, 0xee, 0xfe, 0x46, 0x59, 0xa4, 0x27, + 0x0, 0x1d, 0xd, 0x6, 0x41, 0xa5, 0x1c, 0xbb, 0xb, 0x70, 0x46, 0xe7, 0x9b, 0x3e, 0xa2, 0x71, 0xa, 0x4d, 0xc0, + 0xfc, 0xc, 0x7b, 0xb2, 0x8, 0x7, 0x40, 0x76, 0x83, 0xd7, 0x98, 0x66, 0x6, 0x0, 0x11, 0x51, 0xe7, 0x73, 0x37, + 0x48, 0x5, 0x23, 0x8f, 0x6f, 0x7, 0xfb, 0x2, 0x57, 0xc9, 0xb1, 0xc4, 0x7b, 0x12, 0x0, 0x4, 0x24, 0x8e, 0x8c, + 0xc6, 0x22}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[3]; + uint8_t topic_filter_s0_bytes[] = {0xd, 0x6, 0x41, 0xa5, 0x1c, 0xbb, 0xb, 0x70, 0x46, 0xe7, + 0x9b, 0x3e, 0xa2, 0x71, 0xa, 0x4d, 0xc0, 0xfc, 0xc, 0x7b, + 0xb2, 0x8, 0x7, 0x40, 0x76, 0x83, 0xd7, 0x98, 0x66}; + lwmqtt_string_t topic_filter_s0 = {29, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x51, 0xe7, 0x73, 0x37, 0x48, 0x5, 0x23, 0x8f, 0x6f, + 0x7, 0xfb, 0x2, 0x57, 0xc9, 0xb1, 0xc4, 0x7b}; + lwmqtt_string_t topic_filter_s1 = {17, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x24, 0x8e, 0x8c, 0xc6}; + lwmqtt_string_t topic_filter_s2 = {4, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + lwmqtt_sub_options_t sub_opts[3]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + uint8_t bytesprops0[] = {0x57, 0x78, 0x89, 0x8a, 0x95, 0xd5, 0x20, 0x4d, + 0x4f, 0xde, 0x2, 0xb4, 0xd1, 0x27, 0x86, 0x33}; + uint8_t bytesprops1[] = {0xc6, 0xdb, 0x11, 0xd6, 0x85, 0x8e, 0x55}; + uint8_t bytesprops3[] = {0xdb, 0x30, 0xf1, 0x40, 0x1d, 0x4e, 0x39, 0x8e, 0x42, + 0x3e, 0xf2, 0x3d, 0x98, 0x54, 0xf0, 0xa1, 0xa8}; + uint8_t bytesprops2[] = {0x50, 0xcc, 0xd8, 0x49, 0x59, 0x3, 0xc4, 0x49, 0x29, 0xa6, 0xf3, 0xf3, 0xcf, 0xbf, + 0x67, 0xe3, 0x2, 0x53, 0x4c, 0x25, 0x9, 0x46, 0xc7, 0x53, 0xcd, 0xcc, 0x62}; + uint8_t bytesprops4[] = {0x5e, 0x9a, 0xad, 0x12, 0x94, 0x90, 0xc1, 0x2d, 0x61, 0x94, + 0x78, 0x2e, 0x13, 0xf6, 0xa2, 0x4e, 0x16, 0x1b, 0x85}; + uint8_t bytesprops5[] = {0x88, 0x72, 0xa0, 0x74}; + uint8_t bytesprops6[] = {0x37, 0x73, 0xd2, 0x62, 0xfc, 0x7f, 0x93, 0x96, 0x1c, 0x70, 0xf4, 0x38, 0x25}; + uint8_t bytesprops7[] = {0xc8, 0x24, 0x87, 0xdc}; + uint8_t bytesprops8[] = {0x1c, 0xda, 0xf9, 0x44, 0xf, 0xd3, 0x16, 0x6, 0x73, 0xb6, + 0x5d, 0x85, 0xab, 0xd5, 0xc2, 0x7d, 0x2, 0x8e, 0xd0}; + uint8_t bytesprops9[] = {0x39, 0x67, 0x84, 0x36, 0x8e, 0xbf, 0xe9, 0xa2, 0x41, 0x50, 0xb0, + 0xb5, 0x8d, 0xb3, 0x38, 0x8e, 0x48, 0x43, 0x40, 0x13, 0x1e}; + uint8_t bytesprops10[] = {0x31, 0xc4, 0xef, 0xc2, 0xd5, 0x19, 0x2d, 0xe4, 0xc5, 0xf, + 0x5d, 0xb7, 0x4f, 0xbd, 0xff, 0x49, 0x77, 0x73, 0x79}; + uint8_t bytesprops11[] = {0x3f, 0x27, 0xe8, 0xb, 0x34, 0xd5, 0x16, 0xab, 0xbf, 0x4, 0xa3, 0x5f, 0x6, 0x87, + 0x76, 0x14, 0x16, 0x9e, 0x75, 0x7f, 0x3a, 0xeb, 0x3, 0x19, 0x45, 0xc2, 0x32, 0x47}; + uint8_t bytesprops12[] = {0x4e, 0x12, 0xf3, 0x6e, 0xc0, 0x61, 0x2b, 0xac, 0x74, 0x33, 0x42, 0x40, 0x6d, 0x2c, + 0x68, 0x1a, 0xf8, 0xe1, 0x4b, 0x74, 0x8, 0x76, 0xee, 0xfe, 0x46, 0x59, 0xa4, 0x27}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)3, .value = {.str = {16, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 16280}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 32255}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 28531}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {7, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 135}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {27, (char*)&bytesprops2}, .v = {17, (char*)&bytesprops3}}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 18181}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 19439}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {19, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 119}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 19}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 30628}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 190}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 23203}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {4, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 240}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 1968}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {13, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 1701}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {4, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {19, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {21, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 26022}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 18}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {19, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 197}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 11}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {28, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {28, (char*)&bytesprops12}}}, + }; + + lwmqtt_properties_t props = {30, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 12819, 3, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 26406 [("`\aR\230\193\146\183",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = +// True, _noLocal = True, _subQoS = QoS2}),("\EOT,\142\SOH\170%",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = True, _noLocal = True, _subQoS = QoS1}),("P\232L\184\219'\fn\160W\t22",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = QoS2})] +// [PropMessageExpiryInterval 2977,PropPayloadFormatIndicator 43,PropAssignedClientIdentifier +// "Q\217vjN\198^\v*\222\f\226\171'",PropMessageExpiryInterval 19765,PropAuthenticationData "\197\154\EM\158>"] +TEST(Subscribe5QCTest, Encode14) { + uint8_t pkt[] = {0x82, 0x4b, 0x67, 0x26, 0x25, 0x2, 0x0, 0x0, 0xb, 0xa1, 0x1, 0x2b, 0x12, 0x0, 0xe, 0x51, + 0xd9, 0x76, 0x6a, 0x4e, 0xc6, 0x5e, 0xb, 0x2a, 0xde, 0xc, 0xe2, 0xab, 0x27, 0x2, 0x0, 0x0, + 0x4d, 0x35, 0x16, 0x0, 0x5, 0xc5, 0x9a, 0x19, 0x9e, 0x3e, 0x0, 0x7, 0x60, 0x7, 0x52, 0xe6, + 0xc1, 0x92, 0xb7, 0xe, 0x0, 0x6, 0x4, 0x2c, 0x8e, 0x1, 0xaa, 0x25, 0x1d, 0x0, 0xd, 0x50, + 0xe8, 0x4c, 0xb8, 0xdb, 0x27, 0xc, 0x6e, 0xa0, 0x57, 0x9, 0x32, 0x32, 0x6}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[3]; + uint8_t topic_filter_s0_bytes[] = {0x60, 0x7, 0x52, 0xe6, 0xc1, 0x92, 0xb7}; + lwmqtt_string_t topic_filter_s0 = {7, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x4, 0x2c, 0x8e, 0x1, 0xaa, 0x25}; + lwmqtt_string_t topic_filter_s1 = {6, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x50, 0xe8, 0x4c, 0xb8, 0xdb, 0x27, 0xc, 0x6e, 0xa0, 0x57, 0x9, 0x32, 0x32}; + lwmqtt_string_t topic_filter_s2 = {13, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + lwmqtt_sub_options_t sub_opts[3]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = true; + uint8_t bytesprops0[] = {0x51, 0xd9, 0x76, 0x6a, 0x4e, 0xc6, 0x5e, 0xb, 0x2a, 0xde, 0xc, 0xe2, 0xab, 0x27}; + uint8_t bytesprops1[] = {0xc5, 0x9a, 0x19, 0x9e, 0x3e}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 2977}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 43}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {14, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 19765}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {5, (char*)&bytesprops1}}}, + }; + + lwmqtt_properties_t props = {5, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 26406, 3, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 13914 [("\198\167\141tI\138S\169\224\226\US\159\SIty",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS2}),("1\181Xv\ACK\149\214\232z\136\EOT)\197\DLE\245\&5-\FSK~\SUBO\228\ENQ>1",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS1}),("\163\252\EOT\234\173\180\EM\\O\240\GS)\232\252=\DC3\152",SubOptions {_retainHandling = DoNotSendOnSubscribe, +// _retainAsPublished = False, _noLocal = True, _subQoS = QoS2})] [PropRequestProblemInformation +// 88,PropAssignedClientIdentifier "#\225KF\181\DC2\174",PropReasonString +// "\183\244\143d\213\200eZ\191\156\201XfY\171",PropSubscriptionIdentifier 29,PropMessageExpiryInterval +// 7039,PropSubscriptionIdentifier 19,PropWildcardSubscriptionAvailable 199,PropMaximumQoS 94,PropTopicAliasMaximum +// 13184,PropUserProperty "E\246`\226\145\237`\162\SUB\203\139" +// "S\185j\215\174&\SOHM\192\178\&0\229\191\195\134\233|\SOH\149\212\242",PropReceiveMaximum 48,PropReasonString +// "\243\252\a\171",PropContentType "\r\181*\DEL",PropTopicAlias 5955,PropMessageExpiryInterval +// 31416,PropAssignedClientIdentifier "\243\ENQt#\243\193\221V\253\163\"Zz0\NAK",PropTopicAlias 12949,PropReceiveMaximum +// 13522,PropReasonString "\147\DC1l\226\155\STX\211\177\143\211d\133\132\187\DC2\186\182\207\158\136\r",PropMaximumQoS +// 247,PropSharedSubscriptionAvailable 70] +TEST(Subscribe5QCTest, Encode15) { + uint8_t pkt[] = {0x82, 0xe7, 0x1, 0x36, 0x5a, 0xa0, 0x1, 0x17, 0x58, 0x12, 0x0, 0x7, 0x23, 0xe1, 0x4b, 0x46, 0xb5, + 0x12, 0xae, 0x1f, 0x0, 0xf, 0xb7, 0xf4, 0x8f, 0x64, 0xd5, 0xc8, 0x65, 0x5a, 0xbf, 0x9c, 0xc9, 0x58, + 0x66, 0x59, 0xab, 0xb, 0x1d, 0x2, 0x0, 0x0, 0x1b, 0x7f, 0xb, 0x13, 0x28, 0xc7, 0x24, 0x5e, 0x22, + 0x33, 0x80, 0x26, 0x0, 0xb, 0x45, 0xf6, 0x60, 0xe2, 0x91, 0xed, 0x60, 0xa2, 0x1a, 0xcb, 0x8b, 0x0, + 0x15, 0x53, 0xb9, 0x6a, 0xd7, 0xae, 0x26, 0x1, 0x4d, 0xc0, 0xb2, 0x30, 0xe5, 0xbf, 0xc3, 0x86, 0xe9, + 0x7c, 0x1, 0x95, 0xd4, 0xf2, 0x21, 0x0, 0x30, 0x1f, 0x0, 0x4, 0xf3, 0xfc, 0x7, 0xab, 0x3, 0x0, + 0x4, 0xd, 0xb5, 0x2a, 0x7f, 0x23, 0x17, 0x43, 0x2, 0x0, 0x0, 0x7a, 0xb8, 0x12, 0x0, 0xf, 0xf3, + 0x5, 0x74, 0x23, 0xf3, 0xc1, 0xdd, 0x56, 0xfd, 0xa3, 0x22, 0x5a, 0x7a, 0x30, 0x15, 0x23, 0x32, 0x95, + 0x21, 0x34, 0xd2, 0x1f, 0x0, 0x15, 0x93, 0x11, 0x6c, 0xe2, 0x9b, 0x2, 0xd3, 0xb1, 0x8f, 0xd3, 0x64, + 0x85, 0x84, 0xbb, 0x12, 0xba, 0xb6, 0xcf, 0x9e, 0x88, 0xd, 0x24, 0xf7, 0x2a, 0x46, 0x0, 0xf, 0xc6, + 0xa7, 0x8d, 0x74, 0x49, 0x8a, 0x53, 0xa9, 0xe0, 0xe2, 0x1f, 0x9f, 0xf, 0x74, 0x79, 0x1a, 0x0, 0x1a, + 0x31, 0xb5, 0x58, 0x76, 0x6, 0x95, 0xd6, 0xe8, 0x7a, 0x88, 0x4, 0x29, 0xc5, 0x10, 0xf5, 0x35, 0x2d, + 0x1c, 0x4b, 0x7e, 0x1a, 0x4f, 0xe4, 0x5, 0x3e, 0x31, 0x1d, 0x0, 0x11, 0xa3, 0xfc, 0x4, 0xea, 0xad, + 0xb4, 0x19, 0x5c, 0x4f, 0xf0, 0x1d, 0x29, 0xe8, 0xfc, 0x3d, 0x13, 0x98, 0x26}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[3]; + uint8_t topic_filter_s0_bytes[] = {0xc6, 0xa7, 0x8d, 0x74, 0x49, 0x8a, 0x53, 0xa9, + 0xe0, 0xe2, 0x1f, 0x9f, 0xf, 0x74, 0x79}; + lwmqtt_string_t topic_filter_s0 = {15, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x31, 0xb5, 0x58, 0x76, 0x6, 0x95, 0xd6, 0xe8, 0x7a, 0x88, 0x4, 0x29, 0xc5, + 0x10, 0xf5, 0x35, 0x2d, 0x1c, 0x4b, 0x7e, 0x1a, 0x4f, 0xe4, 0x5, 0x3e, 0x31}; + lwmqtt_string_t topic_filter_s1 = {26, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xa3, 0xfc, 0x4, 0xea, 0xad, 0xb4, 0x19, 0x5c, 0x4f, + 0xf0, 0x1d, 0x29, 0xe8, 0xfc, 0x3d, 0x13, 0x98}; + lwmqtt_string_t topic_filter_s2 = {17, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + lwmqtt_sub_options_t sub_opts[3]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = true; + uint8_t bytesprops0[] = {0x23, 0xe1, 0x4b, 0x46, 0xb5, 0x12, 0xae}; + uint8_t bytesprops1[] = {0xb7, 0xf4, 0x8f, 0x64, 0xd5, 0xc8, 0x65, 0x5a, 0xbf, 0x9c, 0xc9, 0x58, 0x66, 0x59, 0xab}; + uint8_t bytesprops3[] = {0x53, 0xb9, 0x6a, 0xd7, 0xae, 0x26, 0x1, 0x4d, 0xc0, 0xb2, 0x30, + 0xe5, 0xbf, 0xc3, 0x86, 0xe9, 0x7c, 0x1, 0x95, 0xd4, 0xf2}; + uint8_t bytesprops2[] = {0x45, 0xf6, 0x60, 0xe2, 0x91, 0xed, 0x60, 0xa2, 0x1a, 0xcb, 0x8b}; + uint8_t bytesprops4[] = {0xf3, 0xfc, 0x7, 0xab}; + uint8_t bytesprops5[] = {0xd, 0xb5, 0x2a, 0x7f}; + uint8_t bytesprops6[] = {0xf3, 0x5, 0x74, 0x23, 0xf3, 0xc1, 0xdd, 0x56, 0xfd, 0xa3, 0x22, 0x5a, 0x7a, 0x30, 0x15}; + uint8_t bytesprops7[] = {0x93, 0x11, 0x6c, 0xe2, 0x9b, 0x2, 0xd3, 0xb1, 0x8f, 0xd3, 0x64, + 0x85, 0x84, 0xbb, 0x12, 0xba, 0xb6, 0xcf, 0x9e, 0x88, 0xd}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 88}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {7, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {15, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 29}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 7039}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 19}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 199}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 94}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 13184}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {11, (char*)&bytesprops2}, .v = {21, (char*)&bytesprops3}}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 48}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {4, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {4, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 5955}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 31416}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {15, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 12949}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 13522}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {21, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 247}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 70}}, + }; + + lwmqtt_properties_t props = {21, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 13914, 3, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 2905 [("\158\194\134\209\SOH \176^\221\235\147\182\230\226\157\a\STX\215",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\STX\165?\213\"\ETX@\DC4\ENQ\178\ACKjo\156",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = True, _noLocal = True, _subQoS = QoS1}),("\171sk",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = True, _subQoS = QoS0}),("\171\167\154\213\250eT\\\165\US\US@\174",SubOptions +// {_retainHandling = SendOnSubscribeNew, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS1}),("\144O\186\216\f'gm{BI",SubOptions {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = True, +// _noLocal = False, _subQoS = QoS0}),("\GS]\244\240/\177\178.\246\143\SI-\226j\165\SOH\233",SubOptions {_retainHandling +// = SendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = QoS2})] [PropServerKeepAlive +// 12808,PropContentType "0O}\206\&1\174\205U\SYNr\242\244\ACK",PropResponseInformation +// "[\246\192",PropAuthenticationData "\213\RS\SIp\138Q\172\231\nT\EM\146",PropReasonString +// "w\170\&7G\216\192\ETX\EOTO;\RS\DC3RsM\133P\233\EMH\240o\249\NAK\191\131D\156\131\237",PropRetainAvailable +// 154,PropCorrelationData "\185Z\184\132u\159\&0\227\176\197\188^\236\214\239",PropTopicAliasMaximum +// 11949,PropWildcardSubscriptionAvailable 190,PropCorrelationData +// "\241b]\222\155\201\159Q<\178i\243(\186\&4\136\138\154\187\174\222\169\241_",PropMaximumPacketSize +// 22371,PropUserProperty "\183\ETB)0MHZ\130\165\248\142z\GS\EOT\230\136e\237,\199\228\218\169_c\v\212" +// "\212\SYN\228\150}N\233\221\234e\151p\255^\165\233\171\170",PropWillDelayInterval 894] +TEST(Subscribe5QCTest, Encode16) { + uint8_t pkt[] = {0x82, 0x9b, 0x2, 0xb, 0x59, 0xb9, 0x1, 0x13, 0x32, 0x8, 0x3, 0x0, 0xd, 0x30, 0x4f, 0x7d, 0xce, + 0x31, 0xae, 0xcd, 0x55, 0x16, 0x72, 0xf2, 0xf4, 0x6, 0x1a, 0x0, 0x3, 0x5b, 0xf6, 0xc0, 0x16, 0x0, + 0xc, 0xd5, 0x1e, 0xf, 0x70, 0x8a, 0x51, 0xac, 0xe7, 0xa, 0x54, 0x19, 0x92, 0x1f, 0x0, 0x1e, 0x77, + 0xaa, 0x37, 0x47, 0xd8, 0xc0, 0x3, 0x4, 0x4f, 0x3b, 0x1e, 0x13, 0x52, 0x73, 0x4d, 0x85, 0x50, 0xe9, + 0x19, 0x48, 0xf0, 0x6f, 0xf9, 0x15, 0xbf, 0x83, 0x44, 0x9c, 0x83, 0xed, 0x25, 0x9a, 0x9, 0x0, 0xf, + 0xb9, 0x5a, 0xb8, 0x84, 0x75, 0x9f, 0x30, 0xe3, 0xb0, 0xc5, 0xbc, 0x5e, 0xec, 0xd6, 0xef, 0x22, 0x2e, + 0xad, 0x28, 0xbe, 0x9, 0x0, 0x18, 0xf1, 0x62, 0x5d, 0xde, 0x9b, 0xc9, 0x9f, 0x51, 0x3c, 0xb2, 0x69, + 0xf3, 0x28, 0xba, 0x34, 0x88, 0x8a, 0x9a, 0xbb, 0xae, 0xde, 0xa9, 0xf1, 0x5f, 0x27, 0x0, 0x0, 0x57, + 0x63, 0x26, 0x0, 0x1b, 0xb7, 0x17, 0x29, 0x30, 0x4d, 0x48, 0x5a, 0x82, 0xa5, 0xf8, 0x8e, 0x7a, 0x1d, + 0x4, 0xe6, 0x88, 0x65, 0xed, 0x2c, 0xc7, 0xe4, 0xda, 0xa9, 0x5f, 0x63, 0xb, 0xd4, 0x0, 0x12, 0xd4, + 0x16, 0xe4, 0x96, 0x7d, 0x4e, 0xe9, 0xdd, 0xea, 0x65, 0x97, 0x70, 0xff, 0x5e, 0xa5, 0xe9, 0xab, 0xaa, + 0x18, 0x0, 0x0, 0x3, 0x7e, 0x0, 0x12, 0x9e, 0xc2, 0x86, 0xd1, 0x1, 0x20, 0xb0, 0x5e, 0xdd, 0xeb, + 0x93, 0xb6, 0xe6, 0xe2, 0x9d, 0x7, 0x2, 0xd7, 0x2, 0x0, 0xe, 0x2, 0xa5, 0x3f, 0xd5, 0x22, 0x3, + 0x40, 0x14, 0x5, 0xb2, 0x6, 0x6a, 0x6f, 0x9c, 0x1d, 0x0, 0x3, 0xab, 0x73, 0x6b, 0x4, 0x0, 0xd, + 0xab, 0xa7, 0x9a, 0xd5, 0xfa, 0x65, 0x54, 0x5c, 0xa5, 0x1f, 0x1f, 0x40, 0xae, 0x19, 0x0, 0xb, 0x90, + 0x4f, 0xba, 0xd8, 0xc, 0x27, 0x67, 0x6d, 0x7b, 0x42, 0x49, 0x28, 0x0, 0x11, 0x1d, 0x5d, 0xf4, 0xf0, + 0x2f, 0xb1, 0xb2, 0x2e, 0xf6, 0x8f, 0xf, 0x2d, 0xe2, 0x6a, 0xa5, 0x1, 0xe9, 0xa}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[6]; + uint8_t topic_filter_s0_bytes[] = {0x9e, 0xc2, 0x86, 0xd1, 0x1, 0x20, 0xb0, 0x5e, 0xdd, + 0xeb, 0x93, 0xb6, 0xe6, 0xe2, 0x9d, 0x7, 0x2, 0xd7}; + lwmqtt_string_t topic_filter_s0 = {18, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x2, 0xa5, 0x3f, 0xd5, 0x22, 0x3, 0x40, 0x14, 0x5, 0xb2, 0x6, 0x6a, 0x6f, 0x9c}; + lwmqtt_string_t topic_filter_s1 = {14, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xab, 0x73, 0x6b}; + lwmqtt_string_t topic_filter_s2 = {3, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xab, 0xa7, 0x9a, 0xd5, 0xfa, 0x65, 0x54, 0x5c, 0xa5, 0x1f, 0x1f, 0x40, 0xae}; + lwmqtt_string_t topic_filter_s3 = {13, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x90, 0x4f, 0xba, 0xd8, 0xc, 0x27, 0x67, 0x6d, 0x7b, 0x42, 0x49}; + lwmqtt_string_t topic_filter_s4 = {11, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x1d, 0x5d, 0xf4, 0xf0, 0x2f, 0xb1, 0xb2, 0x2e, 0xf6, + 0x8f, 0xf, 0x2d, 0xe2, 0x6a, 0xa5, 0x1, 0xe9}; + lwmqtt_string_t topic_filter_s5 = {17, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + lwmqtt_sub_options_t sub_opts[6]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[3].retain_as_published = true; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS0; + sub_opts[4].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[4].retain_as_published = true; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS2; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = true; + sub_opts[5].no_local = false; + uint8_t bytesprops0[] = {0x30, 0x4f, 0x7d, 0xce, 0x31, 0xae, 0xcd, 0x55, 0x16, 0x72, 0xf2, 0xf4, 0x6}; + uint8_t bytesprops1[] = {0x5b, 0xf6, 0xc0}; + uint8_t bytesprops2[] = {0xd5, 0x1e, 0xf, 0x70, 0x8a, 0x51, 0xac, 0xe7, 0xa, 0x54, 0x19, 0x92}; + uint8_t bytesprops3[] = {0x77, 0xaa, 0x37, 0x47, 0xd8, 0xc0, 0x3, 0x4, 0x4f, 0x3b, 0x1e, 0x13, 0x52, 0x73, 0x4d, + 0x85, 0x50, 0xe9, 0x19, 0x48, 0xf0, 0x6f, 0xf9, 0x15, 0xbf, 0x83, 0x44, 0x9c, 0x83, 0xed}; + uint8_t bytesprops4[] = {0xb9, 0x5a, 0xb8, 0x84, 0x75, 0x9f, 0x30, 0xe3, 0xb0, 0xc5, 0xbc, 0x5e, 0xec, 0xd6, 0xef}; + uint8_t bytesprops5[] = {0xf1, 0x62, 0x5d, 0xde, 0x9b, 0xc9, 0x9f, 0x51, 0x3c, 0xb2, 0x69, 0xf3, + 0x28, 0xba, 0x34, 0x88, 0x8a, 0x9a, 0xbb, 0xae, 0xde, 0xa9, 0xf1, 0x5f}; + uint8_t bytesprops7[] = {0xd4, 0x16, 0xe4, 0x96, 0x7d, 0x4e, 0xe9, 0xdd, 0xea, + 0x65, 0x97, 0x70, 0xff, 0x5e, 0xa5, 0xe9, 0xab, 0xaa}; + uint8_t bytesprops6[] = {0xb7, 0x17, 0x29, 0x30, 0x4d, 0x48, 0x5a, 0x82, 0xa5, 0xf8, 0x8e, 0x7a, 0x1d, 0x4, + 0xe6, 0x88, 0x65, 0xed, 0x2c, 0xc7, 0xe4, 0xda, 0xa9, 0x5f, 0x63, 0xb, 0xd4}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 12808}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {13, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {3, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {12, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {30, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 154}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {15, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 11949}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 190}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {24, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 22371}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {27, (char*)&bytesprops6}, .v = {18, (char*)&bytesprops7}}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 894}}, + }; + + lwmqtt_properties_t props = {13, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 2905, 6, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 10689 [("\199\210\220",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS0}),("7\161c\189=\151\t\191\238\214\221\130]\254\133\170S",SubOptions {_retainHandling +// = SendOnSubscribeNew, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS0}),("\207\&0\141\ETB\132\255\137\214\191x\233o\247\ACK\248\177",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS2}),("7\137\ETB\205\231s\136!\DC3B\DC1\151T\175\132\DLE[w\159r\162Tp\145\ENQ",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\177\136\US\209\US\188\SOg\EOTe\246CY^`\DEL3\143\ESC\EOTgMo\253\248\236\RSa*&",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] [PropAuthenticationData +// "\189\178",PropUserProperty "2\178\\\148h]\158\229\SOH\167\151\222#\191" +// "K\137r'\185\244",PropAssignedClientIdentifier "\154/_\232u\SIW\254\ENQ\SYN)KnO\212`h|'\f\201\&8\134 +// \240\&8\RS\254\&0"] +TEST(Subscribe5QCTest, Encode17) { + uint8_t pkt[] = {0x82, 0xab, 0x1, 0x29, 0xc1, 0x3e, 0x16, 0x0, 0x2, 0xbd, 0xb2, 0x26, 0x0, 0xe, 0x32, 0xb2, + 0x5c, 0x94, 0x68, 0x5d, 0x9e, 0xe5, 0x1, 0xa7, 0x97, 0xde, 0x23, 0xbf, 0x0, 0x6, 0x4b, 0x89, + 0x72, 0x27, 0xb9, 0xf4, 0x12, 0x0, 0x1d, 0x9a, 0x2f, 0x5f, 0xe8, 0x75, 0xf, 0x57, 0xfe, 0x5, + 0x16, 0x29, 0x4b, 0x6e, 0x4f, 0xd4, 0x60, 0x68, 0x7c, 0x27, 0xc, 0xc9, 0x38, 0x86, 0x20, 0xf0, + 0x38, 0x1e, 0xfe, 0x30, 0x0, 0x3, 0xc7, 0xd2, 0xdc, 0x0, 0x0, 0x11, 0x37, 0xa1, 0x63, 0xbd, + 0x3d, 0x97, 0x9, 0xbf, 0xee, 0xd6, 0xdd, 0x82, 0x5d, 0xfe, 0x85, 0xaa, 0x53, 0x14, 0x0, 0x10, + 0xcf, 0x30, 0x8d, 0x17, 0x84, 0xff, 0x89, 0xd6, 0xbf, 0x78, 0xe9, 0x6f, 0xf7, 0x6, 0xf8, 0xb1, + 0x2e, 0x0, 0x19, 0x37, 0x89, 0x17, 0xcd, 0xe7, 0x73, 0x88, 0x21, 0x13, 0x42, 0x11, 0x97, 0x54, + 0xaf, 0x84, 0x10, 0x5b, 0x77, 0x9f, 0x72, 0xa2, 0x54, 0x70, 0x91, 0x5, 0x20, 0x0, 0x1e, 0xb1, + 0x88, 0x1f, 0xd1, 0x1f, 0xbc, 0xe, 0x67, 0x4, 0x65, 0xf6, 0x43, 0x59, 0x5e, 0x60, 0x7f, 0x33, + 0x8f, 0x1b, 0x4, 0x67, 0x4d, 0x6f, 0xfd, 0xf8, 0xec, 0x1e, 0x61, 0x2a, 0x26, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0xc7, 0xd2, 0xdc}; + lwmqtt_string_t topic_filter_s0 = {3, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x37, 0xa1, 0x63, 0xbd, 0x3d, 0x97, 0x9, 0xbf, 0xee, + 0xd6, 0xdd, 0x82, 0x5d, 0xfe, 0x85, 0xaa, 0x53}; + lwmqtt_string_t topic_filter_s1 = {17, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xcf, 0x30, 0x8d, 0x17, 0x84, 0xff, 0x89, 0xd6, + 0xbf, 0x78, 0xe9, 0x6f, 0xf7, 0x6, 0xf8, 0xb1}; + lwmqtt_string_t topic_filter_s2 = {16, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x37, 0x89, 0x17, 0xcd, 0xe7, 0x73, 0x88, 0x21, 0x13, 0x42, 0x11, 0x97, 0x54, + 0xaf, 0x84, 0x10, 0x5b, 0x77, 0x9f, 0x72, 0xa2, 0x54, 0x70, 0x91, 0x5}; + lwmqtt_string_t topic_filter_s3 = {25, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xb1, 0x88, 0x1f, 0xd1, 0x1f, 0xbc, 0xe, 0x67, 0x4, 0x65, + 0xf6, 0x43, 0x59, 0x5e, 0x60, 0x7f, 0x33, 0x8f, 0x1b, 0x4, + 0x67, 0x4d, 0x6f, 0xfd, 0xf8, 0xec, 0x1e, 0x61, 0x2a, 0x26}; + lwmqtt_string_t topic_filter_s4 = {30, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + lwmqtt_sub_options_t sub_opts[5]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS0; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + uint8_t bytesprops0[] = {0xbd, 0xb2}; + uint8_t bytesprops2[] = {0x4b, 0x89, 0x72, 0x27, 0xb9, 0xf4}; + uint8_t bytesprops1[] = {0x32, 0xb2, 0x5c, 0x94, 0x68, 0x5d, 0x9e, 0xe5, 0x1, 0xa7, 0x97, 0xde, 0x23, 0xbf}; + uint8_t bytesprops3[] = {0x9a, 0x2f, 0x5f, 0xe8, 0x75, 0xf, 0x57, 0xfe, 0x5, 0x16, 0x29, 0x4b, 0x6e, 0x4f, 0xd4, + 0x60, 0x68, 0x7c, 0x27, 0xc, 0xc9, 0x38, 0x86, 0x20, 0xf0, 0x38, 0x1e, 0xfe, 0x30}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)22, .value = {.str = {2, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {14, (char*)&bytesprops1}, .v = {6, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {29, (char*)&bytesprops3}}}, + }; + + lwmqtt_properties_t props = {3, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 10689, 5, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 8875 [("q|\160X\159\&9\235\ETB\206]\224\ETB\205\209\149\211>e\193#\168\246){_\173L\172",SubOptions +// {_retainHandling = SendOnSubscribeNew, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\193\166\246\224\235\201\ACK\187k",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = True, +// _noLocal = False, _subQoS = QoS1}),("\227\247a\181\EOT\235\DC3\222\&1",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = False, _noLocal = True, _subQoS = QoS2}),("",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS0}),("Y\213\224\139\128\253\225\233\238\165\197\166`\174]\204\150\188",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = QoS1})] [PropMaximumQoS +// 42,PropRequestResponseInformation 74,PropServerKeepAlive 16546,PropAssignedClientIdentifier +// "C/KZ\144\201\ESC\130)\166MM\241~",PropUserProperty "\EOTT[A2\SUB\161\184\151\239\ETX?",PropCorrelationData +// "zH\242\150\187\203-\166\v':\166]\190/\SOH\139\133\219+4:'h-\246",PropSubscriptionIdentifier 27] +TEST(Subscribe5QCTest, Encode22) { + uint8_t pkt[] = { + 0x82, 0xe2, 0x3, 0x15, 0xb3, 0xa5, 0x2, 0x3, 0x0, 0x19, 0xe7, 0x5a, 0x9b, 0x4b, 0xbc, 0x74, 0x6d, 0x83, 0xce, + 0x9d, 0x94, 0x9d, 0xe1, 0xf2, 0x69, 0x65, 0xd8, 0xa5, 0x91, 0xf8, 0x63, 0xc9, 0xb8, 0xf6, 0xcd, 0x1f, 0x0, 0x6, + 0x25, 0x26, 0x5f, 0x32, 0x6d, 0xaa, 0x2a, 0xa6, 0x1c, 0x0, 0x17, 0x3, 0x3, 0x93, 0x66, 0xe3, 0x32, 0x9, 0xb1, + 0xcc, 0x2b, 0xd0, 0xd2, 0xb, 0x97, 0xa5, 0xaf, 0x6f, 0xc9, 0x27, 0x96, 0x18, 0x89, 0x83, 0x26, 0x0, 0x3, 0x9c, + 0x87, 0xd3, 0x0, 0x14, 0xa4, 0x84, 0x6e, 0x2d, 0x9e, 0x2b, 0xd1, 0x3a, 0x37, 0xc4, 0x76, 0x80, 0xb4, 0x61, 0xc7, + 0x3c, 0x5f, 0xd9, 0x29, 0xe5, 0x23, 0x1c, 0x40, 0x16, 0x0, 0x2, 0xf1, 0x50, 0x29, 0xc4, 0x11, 0x0, 0x0, 0x67, + 0x17, 0x1, 0x62, 0x18, 0x0, 0x0, 0x77, 0xe3, 0x1f, 0x0, 0x19, 0xca, 0x7b, 0xef, 0xa5, 0x1, 0x61, 0x19, 0x3c, + 0xd8, 0xe8, 0x8f, 0x9e, 0x83, 0x2, 0x8e, 0x85, 0xe7, 0x1d, 0xd2, 0xac, 0x41, 0xa5, 0xf4, 0x5c, 0x8, 0x26, 0x0, + 0x3, 0xb3, 0xd4, 0xb3, 0x0, 0x2, 0x72, 0xf5, 0x27, 0x0, 0x0, 0x15, 0xca, 0x15, 0x0, 0x10, 0x1e, 0x8, 0x53, + 0x12, 0xd3, 0x86, 0xcc, 0x6e, 0x60, 0x8f, 0xda, 0xe3, 0x88, 0xed, 0x1e, 0xd8, 0x25, 0xac, 0x13, 0x39, 0xd9, 0x15, + 0x0, 0x1a, 0xeb, 0x2c, 0x8c, 0xba, 0x4, 0xf7, 0x4e, 0xca, 0x9b, 0xc2, 0x69, 0xff, 0x71, 0xe, 0x80, 0xc6, 0x9b, + 0x20, 0xe8, 0xb2, 0xcb, 0x98, 0xc3, 0xa3, 0x31, 0x29, 0x23, 0x51, 0xfc, 0x18, 0x0, 0x0, 0x72, 0x3a, 0x25, 0x8c, + 0x19, 0x1b, 0x28, 0x7a, 0x27, 0x0, 0x0, 0x41, 0x74, 0x28, 0x59, 0x16, 0x0, 0x15, 0x88, 0xe0, 0x51, 0x14, 0xde, + 0xe8, 0xa8, 0x78, 0xe0, 0xd, 0x94, 0x69, 0x2f, 0x2b, 0x24, 0xe3, 0xe, 0xd6, 0x2c, 0x5a, 0xe9, 0x9, 0x0, 0x3, + 0x3e, 0x3, 0x3f, 0x9, 0x0, 0x1a, 0x7a, 0x48, 0xf2, 0x96, 0xbb, 0xcb, 0x2d, 0xa6, 0xb, 0x27, 0x3a, 0xa6, 0x5d, + 0xbe, 0x2f, 0x1, 0x8b, 0x85, 0xdb, 0x2b, 0x34, 0x3a, 0x27, 0x68, 0x2d, 0xf6, 0xb, 0x1b, 0x0, 0x18, 0x49, 0x42, + 0xe2, 0xe, 0x5, 0x4b, 0xd7, 0xed, 0x9f, 0xda, 0x17, 0x7a, 0x58, 0x2b, 0x7a, 0x95, 0x23, 0x91, 0x99, 0x6f, 0xcc, + 0x76, 0xa1, 0x61, 0xe, 0x0, 0xc, 0x36, 0xb5, 0x7b, 0xd, 0x87, 0x83, 0x3f, 0xdf, 0x17, 0x8d, 0xf5, 0x8d, 0x1e, + 0x0, 0xe, 0x9f, 0x9, 0x57, 0xce, 0x2e, 0x4f, 0x59, 0x90, 0x4, 0xef, 0xe9, 0x89, 0x75, 0x1, 0x1e, 0x0, 0x19, + 0x26, 0xba, 0xd1, 0x69, 0xc1, 0xff, 0xef, 0x65, 0xe5, 0xd3, 0xe1, 0x70, 0xef, 0x9b, 0x97, 0x4c, 0x72, 0x82, 0x31, + 0x76, 0xae, 0xdc, 0x70, 0xcb, 0x8c, 0x26, 0x0, 0x12, 0xcb, 0x77, 0x5, 0x49, 0xcb, 0xce, 0xfb, 0x35, 0x57, 0x9a, + 0x63, 0x50, 0xb1, 0xb6, 0x9, 0xcd, 0xf0, 0x6d, 0x15, 0x0, 0x8, 0xcd, 0x14, 0x16, 0xac, 0x82, 0xc0, 0x6, 0xf5, + 0x1e, 0x0, 0xe, 0x36, 0xb3, 0xfb, 0x0, 0x96, 0xde, 0xb0, 0x93, 0x79, 0x1f, 0x4c, 0xd0, 0x2, 0x47, 0x25, 0x0, + 0x5, 0x63, 0x82, 0xb2, 0x9, 0x8d, 0x22, 0x0, 0x1e, 0x67, 0x3d, 0x45, 0x29, 0x53, 0x5a, 0x44, 0xea, 0xf5, 0xff, + 0x1a, 0x3a, 0x59, 0x41, 0xd4, 0x92, 0x1d, 0xcb, 0xc5, 0x0, 0xf7, 0xbb, 0xd, 0x2d, 0x5d, 0xb1, 0x2a, 0xf5, 0x70, + 0xde, 0x1, 0x0, 0x0, 0x15, 0x0, 0x2, 0x49, 0xcf, 0x28}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0x49, 0x42, 0xe2, 0xe, 0x5, 0x4b, 0xd7, 0xed, 0x9f, 0xda, 0x17, 0x7a, + 0x58, 0x2b, 0x7a, 0x95, 0x23, 0x91, 0x99, 0x6f, 0xcc, 0x76, 0xa1, 0x61}; + lwmqtt_string_t topic_filter_s0 = {24, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x36, 0xb5, 0x7b, 0xd, 0x87, 0x83, 0x3f, 0xdf, 0x17, 0x8d, 0xf5, 0x8d}; + lwmqtt_string_t topic_filter_s1 = {12, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x9f, 0x9, 0x57, 0xce, 0x2e, 0x4f, 0x59, 0x90, 0x4, 0xef, 0xe9, 0x89, 0x75, 0x1}; + lwmqtt_string_t topic_filter_s2 = {14, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x26, 0xba, 0xd1, 0x69, 0xc1, 0xff, 0xef, 0x65, 0xe5, 0xd3, 0xe1, 0x70, 0xef, + 0x9b, 0x97, 0x4c, 0x72, 0x82, 0x31, 0x76, 0xae, 0xdc, 0x70, 0xcb, 0x8c}; + lwmqtt_string_t topic_filter_s3 = {25, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xcb, 0x77, 0x5, 0x49, 0xcb, 0xce, 0xfb, 0x35, 0x57, + 0x9a, 0x63, 0x50, 0xb1, 0xb6, 0x9, 0xcd, 0xf0, 0x6d}; + lwmqtt_string_t topic_filter_s4 = {18, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xcd, 0x14, 0x16, 0xac, 0x82, 0xc0, 0x6, 0xf5}; + lwmqtt_string_t topic_filter_s5 = {8, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x36, 0xb3, 0xfb, 0x0, 0x96, 0xde, 0xb0, 0x93, 0x79, 0x1f, 0x4c, 0xd0, 0x2, 0x47}; + lwmqtt_string_t topic_filter_s6 = {14, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x63, 0x82, 0xb2, 0x9, 0x8d}; + lwmqtt_string_t topic_filter_s7 = {5, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x67, 0x3d, 0x45, 0x29, 0x53, 0x5a, 0x44, 0xea, 0xf5, 0xff, + 0x1a, 0x3a, 0x59, 0x41, 0xd4, 0x92, 0x1d, 0xcb, 0xc5, 0x0, + 0xf7, 0xbb, 0xd, 0x2d, 0x5d, 0xb1, 0x2a, 0xf5, 0x70, 0xde}; + lwmqtt_string_t topic_filter_s8 = {30, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0}; + lwmqtt_string_t topic_filter_s9 = {0, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0x49, 0xcf}; + lwmqtt_string_t topic_filter_s10 = {2, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + lwmqtt_sub_options_t sub_opts[11]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS2; + sub_opts[3].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = true; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = true; + sub_opts[5].qos = LWMQTT_QOS2; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[5].retain_as_published = true; + sub_opts[5].no_local = true; + sub_opts[6].qos = LWMQTT_QOS1; + sub_opts[6].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = true; + sub_opts[7].qos = LWMQTT_QOS2; + sub_opts[7].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS1; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + sub_opts[9].qos = LWMQTT_QOS1; + sub_opts[9].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[9].retain_as_published = false; + sub_opts[9].no_local = true; + sub_opts[10].qos = LWMQTT_QOS0; + sub_opts[10].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[10].retain_as_published = true; + sub_opts[10].no_local = false; + uint8_t bytesprops0[] = {0xe7, 0x5a, 0x9b, 0x4b, 0xbc, 0x74, 0x6d, 0x83, 0xce, 0x9d, 0x94, 0x9d, 0xe1, + 0xf2, 0x69, 0x65, 0xd8, 0xa5, 0x91, 0xf8, 0x63, 0xc9, 0xb8, 0xf6, 0xcd}; + uint8_t bytesprops1[] = {0x25, 0x26, 0x5f, 0x32, 0x6d, 0xaa}; + uint8_t bytesprops2[] = {0x3, 0x3, 0x93, 0x66, 0xe3, 0x32, 0x9, 0xb1, 0xcc, 0x2b, 0xd0, 0xd2, + 0xb, 0x97, 0xa5, 0xaf, 0x6f, 0xc9, 0x27, 0x96, 0x18, 0x89, 0x83}; + uint8_t bytesprops4[] = {0xa4, 0x84, 0x6e, 0x2d, 0x9e, 0x2b, 0xd1, 0x3a, 0x37, 0xc4, + 0x76, 0x80, 0xb4, 0x61, 0xc7, 0x3c, 0x5f, 0xd9, 0x29, 0xe5}; + uint8_t bytesprops3[] = {0x9c, 0x87, 0xd3}; + uint8_t bytesprops5[] = {0xf1, 0x50}; + uint8_t bytesprops6[] = {0xca, 0x7b, 0xef, 0xa5, 0x1, 0x61, 0x19, 0x3c, 0xd8, 0xe8, 0x8f, 0x9e, 0x83, + 0x2, 0x8e, 0x85, 0xe7, 0x1d, 0xd2, 0xac, 0x41, 0xa5, 0xf4, 0x5c, 0x8}; + uint8_t bytesprops8[] = {0x72, 0xf5}; + uint8_t bytesprops7[] = {0xb3, 0xd4, 0xb3}; + uint8_t bytesprops9[] = {0x1e, 0x8, 0x53, 0x12, 0xd3, 0x86, 0xcc, 0x6e, + 0x60, 0x8f, 0xda, 0xe3, 0x88, 0xed, 0x1e, 0xd8}; + uint8_t bytesprops10[] = {0xeb, 0x2c, 0x8c, 0xba, 0x4, 0xf7, 0x4e, 0xca, 0x9b, 0xc2, 0x69, 0xff, 0x71, + 0xe, 0x80, 0xc6, 0x9b, 0x20, 0xe8, 0xb2, 0xcb, 0x98, 0xc3, 0xa3, 0x31, 0x29}; + uint8_t bytesprops11[] = {0x88, 0xe0, 0x51, 0x14, 0xde, 0xe8, 0xa8, 0x78, 0xe0, 0xd, 0x94, + 0x69, 0x2f, 0x2b, 0x24, 0xe3, 0xe, 0xd6, 0x2c, 0x5a, 0xe9}; + uint8_t bytesprops12[] = {0x3e, 0x3, 0x3f}; + uint8_t bytesprops13[] = {0x7a, 0x48, 0xf2, 0x96, 0xbb, 0xcb, 0x2d, 0xa6, 0xb, 0x27, 0x3a, 0xa6, 0x5d, + 0xbe, 0x2f, 0x1, 0x8b, 0x85, 0xdb, 0x2b, 0x34, 0x3a, 0x27, 0x68, 0x2d, 0xf6}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)3, .value = {.str = {25, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {6, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 166}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {23, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {3, (char*)&bytesprops3}, .v = {20, (char*)&bytesprops4}}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 7232}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {2, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 196}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 26391}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 98}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 30691}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {25, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {3, (char*)&bytesprops7}, .v = {2, (char*)&bytesprops8}}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 5578}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {16, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 172}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 14809}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {26, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 20988}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 29242}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 140}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 27}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 122}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 16756}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 89}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {21, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {3, (char*)&bytesprops12}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {26, (char*)&bytesprops13}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 27}}, + }; + + lwmqtt_properties_t props = {29, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 5555, 11, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 10338 [("&N",SubOptions {_retainHandling = SendOnSubscribeNew, _retainAsPublished = False, _noLocal +// = True, _subQoS = QoS0}),("L\139",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = True, _noLocal +// = True, _subQoS = QoS2}),("\142\DLE ",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = True, +// _noLocal = True, _subQoS = QoS0}),("o\184\f/M\241\233\236\145",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS0}),("1.$\203\166%\139\EOT8\133\134\251j\247\168\&3Z\182pDS\195\&3!",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS0}),("\239\EM%\FS\EM\DC3v\226cEn",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = True, +// _noLocal = True, _subQoS = QoS0})] [PropResponseInformation +// "On\174\182\203\158w\161.@\r\SI\167{\221\192\176\166\215\249\DLE",PropMessageExpiryInterval 31543,PropRetainAvailable +// 196,PropContentType "\252s\249F\134\154U\228J\212\236\141\201\167D8\241g\210\221\EOT:",PropContentType +// "@\DC2\141U",PropMaximumPacketSize 10132,PropMessageExpiryInterval 22524,PropSessionExpiryInterval +// 27111,PropResponseTopic "\DLEu\158\188cb\141\229\139\&3n\150pj{\189\SO\207\141\EOTJ\216P\240t\133"] +TEST(Subscribe5QCTest, Encode23) { + uint8_t pkt[] = {0x82, 0xb6, 0x1, 0x28, 0x62, 0x6b, 0x1a, 0x0, 0x15, 0x4f, 0x6e, 0xae, 0xb6, 0xcb, 0x9e, 0x77, 0xa1, + 0x2e, 0x40, 0xd, 0xf, 0xa7, 0x7b, 0xdd, 0xc0, 0xb0, 0xa6, 0xd7, 0xf9, 0x10, 0x2, 0x0, 0x0, 0x7b, + 0x37, 0x25, 0xc4, 0x3, 0x0, 0x16, 0xfc, 0x73, 0xf9, 0x46, 0x86, 0x9a, 0x55, 0xe4, 0x4a, 0xd4, 0xec, + 0x8d, 0xc9, 0xa7, 0x44, 0x38, 0xf1, 0x67, 0xd2, 0xdd, 0x4, 0x3a, 0x3, 0x0, 0x4, 0x40, 0x12, 0x8d, + 0x55, 0x27, 0x0, 0x0, 0x27, 0x94, 0x2, 0x0, 0x0, 0x57, 0xfc, 0x11, 0x0, 0x0, 0x69, 0xe7, 0x8, + 0x0, 0x1a, 0x10, 0x75, 0x9e, 0xbc, 0x63, 0x62, 0x8d, 0xe5, 0x8b, 0x33, 0x6e, 0x96, 0x70, 0x6a, 0x7b, + 0xbd, 0xe, 0xcf, 0x8d, 0x4, 0x4a, 0xd8, 0x50, 0xf0, 0x74, 0x85, 0x0, 0x2, 0x26, 0x4e, 0x14, 0x0, + 0x2, 0x4c, 0x8b, 0xe, 0x0, 0x3, 0x8e, 0x10, 0x20, 0xc, 0x0, 0x9, 0x6f, 0xb8, 0xc, 0x2f, 0x4d, + 0xf1, 0xe9, 0xec, 0x91, 0x18, 0x0, 0x18, 0x31, 0x2e, 0x24, 0xcb, 0xa6, 0x25, 0x8b, 0x4, 0x38, 0x85, + 0x86, 0xfb, 0x6a, 0xf7, 0xa8, 0x33, 0x5a, 0xb6, 0x70, 0x44, 0x53, 0xc3, 0x33, 0x21, 0x2, 0x0, 0x0, + 0x0, 0x0, 0xb, 0xef, 0x19, 0x25, 0x1c, 0x19, 0x13, 0x76, 0xe2, 0x63, 0x45, 0x6e, 0xc}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0x26, 0x4e}; + lwmqtt_string_t topic_filter_s0 = {2, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x4c, 0x8b}; + lwmqtt_string_t topic_filter_s1 = {2, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x8e, 0x10, 0x20}; + lwmqtt_string_t topic_filter_s2 = {3, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x6f, 0xb8, 0xc, 0x2f, 0x4d, 0xf1, 0xe9, 0xec, 0x91}; + lwmqtt_string_t topic_filter_s3 = {9, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x31, 0x2e, 0x24, 0xcb, 0xa6, 0x25, 0x8b, 0x4, 0x38, 0x85, 0x86, 0xfb, + 0x6a, 0xf7, 0xa8, 0x33, 0x5a, 0xb6, 0x70, 0x44, 0x53, 0xc3, 0x33, 0x21}; + lwmqtt_string_t topic_filter_s4 = {24, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0}; + lwmqtt_string_t topic_filter_s5 = {0, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xef, 0x19, 0x25, 0x1c, 0x19, 0x13, 0x76, 0xe2, 0x63, 0x45, 0x6e}; + lwmqtt_string_t topic_filter_s6 = {11, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + lwmqtt_sub_options_t sub_opts[7]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[3].retain_as_published = true; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS0; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = true; + sub_opts[6].no_local = true; + uint8_t bytesprops0[] = {0x4f, 0x6e, 0xae, 0xb6, 0xcb, 0x9e, 0x77, 0xa1, 0x2e, 0x40, 0xd, + 0xf, 0xa7, 0x7b, 0xdd, 0xc0, 0xb0, 0xa6, 0xd7, 0xf9, 0x10}; + uint8_t bytesprops1[] = {0xfc, 0x73, 0xf9, 0x46, 0x86, 0x9a, 0x55, 0xe4, 0x4a, 0xd4, 0xec, + 0x8d, 0xc9, 0xa7, 0x44, 0x38, 0xf1, 0x67, 0xd2, 0xdd, 0x4, 0x3a}; + uint8_t bytesprops2[] = {0x40, 0x12, 0x8d, 0x55}; + uint8_t bytesprops3[] = {0x10, 0x75, 0x9e, 0xbc, 0x63, 0x62, 0x8d, 0xe5, 0x8b, 0x33, 0x6e, 0x96, 0x70, + 0x6a, 0x7b, 0xbd, 0xe, 0xcf, 0x8d, 0x4, 0x4a, 0xd8, 0x50, 0xf0, 0x74, 0x85}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)26, .value = {.str = {21, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 31543}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 196}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {22, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {4, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 10132}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 22524}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 27111}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {26, (char*)&bytesprops3}}}, + }; + + lwmqtt_properties_t props = {9, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 10338, 7, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 14367 [("\STX\239Z\131\175\220\f\217_\189A\"\149\ETX\141\165-\244h\215\171\166)",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS1}),("\156\b\136\ETX\ETX\r\237\164|",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = False, _subQoS = QoS0}),("\205.YT\176\145C\172\203\204",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = False, _noLocal = True, _subQoS = QoS1}),("\246\226\\.\aA),\171\169\221\214\\\142bC",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS1}),("\195\191\198\v\219\177\249",SubOptions {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = False, +// _noLocal = True, _subQoS = QoS1})] [PropRetainAvailable 65,PropMaximumQoS 196,PropAuthenticationData +// "\DC4\149\208\148\172y\SIe\DC3\163\138\SUB\170y\234\154\SI\SOH\\\247\242\135\&6\252o\192/",PropSubscriptionIdentifier +// 6,PropResponseTopic "\211I\247r\129\147",PropCorrelationData +// "\210O^!y\209\&1v\132\171\v\230\217K\176:ba\ENQ\138\172\252\139",PropPayloadFormatIndicator 40,PropResponseTopic +// "\220\134\254",PropAuthenticationMethod "fx\167\n\245\242\SI\131\&40Y\DLE",PropResponseTopic +// "\189\&7i\149\&5\178\154\147\159g\210\DC2\194\234\237B\131\171\151Rr\177\\k!\CAN"] +TEST(Subscribe5QCTest, Encode24) { + uint8_t pkt[] = { + 0x82, 0xce, 0x1, 0x38, 0x1f, 0x7b, 0x25, 0x41, 0x24, 0xc4, 0x16, 0x0, 0x1b, 0x14, 0x95, 0xd0, 0x94, 0xac, 0x79, + 0xf, 0x65, 0x13, 0xa3, 0x8a, 0x1a, 0xaa, 0x79, 0xea, 0x9a, 0xf, 0x1, 0x5c, 0xf7, 0xf2, 0x87, 0x36, 0xfc, 0x6f, + 0xc0, 0x2f, 0xb, 0x6, 0x8, 0x0, 0x6, 0xd3, 0x49, 0xf7, 0x72, 0x81, 0x93, 0x9, 0x0, 0x17, 0xd2, 0x4f, 0x5e, + 0x21, 0x79, 0xd1, 0x31, 0x76, 0x84, 0xab, 0xb, 0xe6, 0xd9, 0x4b, 0xb0, 0x3a, 0x62, 0x61, 0x5, 0x8a, 0xac, 0xfc, + 0x8b, 0x1, 0x28, 0x8, 0x0, 0x3, 0xdc, 0x86, 0xfe, 0x15, 0x0, 0xc, 0x66, 0x78, 0xa7, 0xa, 0xf5, 0xf2, 0xf, + 0x83, 0x34, 0x30, 0x59, 0x10, 0x8, 0x0, 0x1a, 0xbd, 0x37, 0x69, 0x95, 0x35, 0xb2, 0x9a, 0x93, 0x9f, 0x67, 0xd2, + 0x12, 0xc2, 0xea, 0xed, 0x42, 0x83, 0xab, 0x97, 0x52, 0x72, 0xb1, 0x5c, 0x6b, 0x21, 0x18, 0x0, 0x17, 0x2, 0xef, + 0x5a, 0x83, 0xaf, 0xdc, 0xc, 0xd9, 0x5f, 0xbd, 0x41, 0x22, 0x95, 0x3, 0x8d, 0xa5, 0x2d, 0xf4, 0x68, 0xd7, 0xab, + 0xa6, 0x29, 0x9, 0x0, 0x9, 0x9c, 0x8, 0x88, 0x3, 0x3, 0xd, 0xed, 0xa4, 0x7c, 0x0, 0x0, 0xa, 0xcd, 0x2e, + 0x59, 0x54, 0xb0, 0x91, 0x43, 0xac, 0xcb, 0xcc, 0x15, 0x0, 0x10, 0xf6, 0xe2, 0x5c, 0x2e, 0x7, 0x41, 0x29, 0x2c, + 0xab, 0xa9, 0xdd, 0xd6, 0x5c, 0x8e, 0x62, 0x43, 0x1, 0x0, 0x7, 0xc3, 0xbf, 0xc6, 0xb, 0xdb, 0xb1, 0xf9, 0x25}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0x2, 0xef, 0x5a, 0x83, 0xaf, 0xdc, 0xc, 0xd9, 0x5f, 0xbd, 0x41, 0x22, + 0x95, 0x3, 0x8d, 0xa5, 0x2d, 0xf4, 0x68, 0xd7, 0xab, 0xa6, 0x29}; + lwmqtt_string_t topic_filter_s0 = {23, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x9c, 0x8, 0x88, 0x3, 0x3, 0xd, 0xed, 0xa4, 0x7c}; + lwmqtt_string_t topic_filter_s1 = {9, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xcd, 0x2e, 0x59, 0x54, 0xb0, 0x91, 0x43, 0xac, 0xcb, 0xcc}; + lwmqtt_string_t topic_filter_s2 = {10, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xf6, 0xe2, 0x5c, 0x2e, 0x7, 0x41, 0x29, 0x2c, + 0xab, 0xa9, 0xdd, 0xd6, 0x5c, 0x8e, 0x62, 0x43}; + lwmqtt_string_t topic_filter_s3 = {16, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xc3, 0xbf, 0xc6, 0xb, 0xdb, 0xb1, 0xf9}; + lwmqtt_string_t topic_filter_s4 = {7, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + lwmqtt_sub_options_t sub_opts[5]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS0; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = false; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = true; + uint8_t bytesprops0[] = {0x14, 0x95, 0xd0, 0x94, 0xac, 0x79, 0xf, 0x65, 0x13, 0xa3, 0x8a, 0x1a, 0xaa, 0x79, + 0xea, 0x9a, 0xf, 0x1, 0x5c, 0xf7, 0xf2, 0x87, 0x36, 0xfc, 0x6f, 0xc0, 0x2f}; + uint8_t bytesprops1[] = {0xd3, 0x49, 0xf7, 0x72, 0x81, 0x93}; + uint8_t bytesprops2[] = {0xd2, 0x4f, 0x5e, 0x21, 0x79, 0xd1, 0x31, 0x76, 0x84, 0xab, 0xb, 0xe6, + 0xd9, 0x4b, 0xb0, 0x3a, 0x62, 0x61, 0x5, 0x8a, 0xac, 0xfc, 0x8b}; + uint8_t bytesprops3[] = {0xdc, 0x86, 0xfe}; + uint8_t bytesprops4[] = {0x66, 0x78, 0xa7, 0xa, 0xf5, 0xf2, 0xf, 0x83, 0x34, 0x30, 0x59, 0x10}; + uint8_t bytesprops5[] = {0xbd, 0x37, 0x69, 0x95, 0x35, 0xb2, 0x9a, 0x93, 0x9f, 0x67, 0xd2, 0x12, 0xc2, + 0xea, 0xed, 0x42, 0x83, 0xab, 0x97, 0x52, 0x72, 0xb1, 0x5c, 0x6b, 0x21, 0x18}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 65}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 196}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {27, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 6}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {6, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {23, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 40}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {3, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {12, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {26, (char*)&bytesprops5}}}, + }; + + lwmqtt_properties_t props = {10, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 14367, 5, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 19237 [(">\187+\226\DLE\US\194\164\194\165\171\166\128",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = QoS0})] [PropTopicAliasMaximum +// 972,PropPayloadFormatIndicator 236,PropMaximumQoS 30,PropResponseInformation +// "\162\238\190\132Z\196yDHMt\220|",PropSessionExpiryInterval 4705,PropWillDelayInterval 27408,PropMaximumPacketSize +// 14655,PropAssignedClientIdentifier +// "\139-\213M\131n\162\USO*\226\214\166\&0\189Z`\182\FS\142\195\217\227",PropMessageExpiryInterval +// 19158,PropSubscriptionIdentifier 11,PropMessageExpiryInterval 65,PropServerReference +// "k?\217\255\190\239f#[\162&\162\180\218\146\206",PropResponseTopic "Tb\157\STX\140)e\RS",PropMessageExpiryInterval +// 15384,PropWillDelayInterval 3292,PropMessageExpiryInterval 6013,PropSharedSubscriptionAvailable +// 142,PropMessageExpiryInterval 634,PropPayloadFormatIndicator 136,PropContentType +// "\145\SOH_\FSt\154\166\245\&0)\188\236\SOH>N\196\"\NAK\215\169y",PropSubscriptionIdentifier 0,PropReceiveMaximum +// 822,PropAssignedClientIdentifier +// "\202\208z\173?B\147||-\229\SO\b\138\253Q\244\178\NAK\206z*t\135\134\253",PropMaximumQoS 58,PropServerKeepAlive +// 32474,PropWildcardSubscriptionAvailable 10,PropMessageExpiryInterval 22868,PropAuthenticationData +// "\214r4z\253\201\226L\224\164:\143\CANf\r\145\209\161o"] +TEST(Subscribe5QCTest, Encode25) { + uint8_t pkt[] = { + 0x82, 0xf2, 0x1, 0x4b, 0x25, 0xde, 0x1, 0x22, 0x3, 0xcc, 0x1, 0xec, 0x24, 0x1e, 0x1a, 0x0, 0xd, 0xa2, 0xee, + 0xbe, 0x84, 0x5a, 0xc4, 0x79, 0x44, 0x48, 0x4d, 0x74, 0xdc, 0x7c, 0x11, 0x0, 0x0, 0x12, 0x61, 0x18, 0x0, 0x0, + 0x6b, 0x10, 0x27, 0x0, 0x0, 0x39, 0x3f, 0x12, 0x0, 0x17, 0x8b, 0x2d, 0xd5, 0x4d, 0x83, 0x6e, 0xa2, 0x1f, 0x4f, + 0x2a, 0xe2, 0xd6, 0xa6, 0x30, 0xbd, 0x5a, 0x60, 0xb6, 0x1c, 0x8e, 0xc3, 0xd9, 0xe3, 0x2, 0x0, 0x0, 0x4a, 0xd6, + 0xb, 0xb, 0x2, 0x0, 0x0, 0x0, 0x41, 0x1c, 0x0, 0x10, 0x6b, 0x3f, 0xd9, 0xff, 0xbe, 0xef, 0x66, 0x23, 0x5b, + 0xa2, 0x26, 0xa2, 0xb4, 0xda, 0x92, 0xce, 0x8, 0x0, 0x8, 0x54, 0x62, 0x9d, 0x2, 0x8c, 0x29, 0x65, 0x1e, 0x2, + 0x0, 0x0, 0x3c, 0x18, 0x18, 0x0, 0x0, 0xc, 0xdc, 0x2, 0x0, 0x0, 0x17, 0x7d, 0x2a, 0x8e, 0x2, 0x0, 0x0, + 0x2, 0x7a, 0x1, 0x88, 0x3, 0x0, 0x15, 0x91, 0x1, 0x5f, 0x1c, 0x74, 0x9a, 0xa6, 0xf5, 0x30, 0x29, 0xbc, 0xec, + 0x1, 0x3e, 0x4e, 0xc4, 0x22, 0x15, 0xd7, 0xa9, 0x79, 0xb, 0x0, 0x21, 0x3, 0x36, 0x12, 0x0, 0x1a, 0xca, 0xd0, + 0x7a, 0xad, 0x3f, 0x42, 0x93, 0x7c, 0x7c, 0x2d, 0xe5, 0xe, 0x8, 0x8a, 0xfd, 0x51, 0xf4, 0xb2, 0x15, 0xce, 0x7a, + 0x2a, 0x74, 0x87, 0x86, 0xfd, 0x24, 0x3a, 0x13, 0x7e, 0xda, 0x28, 0xa, 0x2, 0x0, 0x0, 0x59, 0x54, 0x16, 0x0, + 0x13, 0xd6, 0x72, 0x34, 0x7a, 0xfd, 0xc9, 0xe2, 0x4c, 0xe0, 0xa4, 0x3a, 0x8f, 0x18, 0x66, 0xd, 0x91, 0xd1, 0xa1, + 0x6f, 0x0, 0xd, 0x3e, 0xbb, 0x2b, 0xe2, 0x10, 0x1f, 0xc2, 0xa4, 0xc2, 0xa5, 0xab, 0xa6, 0x80, 0x4}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x3e, 0xbb, 0x2b, 0xe2, 0x10, 0x1f, 0xc2, 0xa4, 0xc2, 0xa5, 0xab, 0xa6, 0x80}; + lwmqtt_string_t topic_filter_s0 = {13, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + lwmqtt_sub_options_t sub_opts[1]; + sub_opts[0].qos = LWMQTT_QOS0; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + uint8_t bytesprops0[] = {0xa2, 0xee, 0xbe, 0x84, 0x5a, 0xc4, 0x79, 0x44, 0x48, 0x4d, 0x74, 0xdc, 0x7c}; + uint8_t bytesprops1[] = {0x8b, 0x2d, 0xd5, 0x4d, 0x83, 0x6e, 0xa2, 0x1f, 0x4f, 0x2a, 0xe2, 0xd6, + 0xa6, 0x30, 0xbd, 0x5a, 0x60, 0xb6, 0x1c, 0x8e, 0xc3, 0xd9, 0xe3}; + uint8_t bytesprops2[] = {0x6b, 0x3f, 0xd9, 0xff, 0xbe, 0xef, 0x66, 0x23, + 0x5b, 0xa2, 0x26, 0xa2, 0xb4, 0xda, 0x92, 0xce}; + uint8_t bytesprops3[] = {0x54, 0x62, 0x9d, 0x2, 0x8c, 0x29, 0x65, 0x1e}; + uint8_t bytesprops4[] = {0x91, 0x1, 0x5f, 0x1c, 0x74, 0x9a, 0xa6, 0xf5, 0x30, 0x29, 0xbc, + 0xec, 0x1, 0x3e, 0x4e, 0xc4, 0x22, 0x15, 0xd7, 0xa9, 0x79}; + uint8_t bytesprops5[] = {0xca, 0xd0, 0x7a, 0xad, 0x3f, 0x42, 0x93, 0x7c, 0x7c, 0x2d, 0xe5, 0xe, 0x8, + 0x8a, 0xfd, 0x51, 0xf4, 0xb2, 0x15, 0xce, 0x7a, 0x2a, 0x74, 0x87, 0x86, 0xfd}; + uint8_t bytesprops6[] = {0xd6, 0x72, 0x34, 0x7a, 0xfd, 0xc9, 0xe2, 0x4c, 0xe0, 0xa4, + 0x3a, 0x8f, 0x18, 0x66, 0xd, 0x91, 0xd1, 0xa1, 0x6f}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 972}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 236}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 30}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {13, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 4705}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 27408}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 14655}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {23, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 19158}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 11}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 65}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {16, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {8, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 15384}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 3292}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 6013}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 142}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 634}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 136}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {21, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 0}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 822}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {26, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 58}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 32474}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 10}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 22868}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {19, (char*)&bytesprops6}}}, + }; + + lwmqtt_properties_t props = {28, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 19237, 1, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 799 [("\156\220HPZ\146\176",SubOptions {_retainHandling = SendOnSubscribeNew, _retainAsPublished = +// False, _noLocal = True, _subQoS = QoS2}),("\204\t\251\&4\140^\198\158P\165\GS\253\182\234",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\140\173\170.\149\153\144",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = True, _subQoS = QoS2}),("s \171\156/-lV\184 +// \155g\165\198sf\180>\233\133\130\221\220\156\178\244\&9\241\225|",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = False, _noLocal = True, _subQoS = QoS2}),(":8\155.\207\150\DC1\180c\182",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS2}),("\232^\US\247\EMU\223ra\135U+K",SubOptions {_retainHandling = SendOnSubscribeNew, _retainAsPublished = False, +// _noLocal = True, _subQoS = QoS0}),("Py\226\FSi_\194\179\221\138\196\208\239\131r{\173n",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS1}),("d\254\197\229\182\216;<*\ETX\ENQ",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = False, +// _noLocal = True, _subQoS = QoS2}),("\141P\243\129=\177V\214",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = True, _noLocal = True, _subQoS = QoS1}),("\164c",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2})] +// [PropWildcardSubscriptionAvailable 139,PropAssignedClientIdentifier "\178\215n\FS\139\147\ETX\EM +// ",PropSubscriptionIdentifierAvailable 226,PropUserProperty "\147\&1%$\222#" +// "\150{\199\241\157\177\&3\ACK\ESC\246\136\FS\172\143\143\207\179\228\224\131\201\154\203\255\242\156\137}",PropSharedSubscriptionAvailable +// 141,PropTopicAliasMaximum 12916,PropSharedSubscriptionAvailable 21,PropUserProperty "\230\&3\189\&6\fl\SYN\NAK\DC2" +// "n8\131b\161\&5\159\154\128\194\194\225>\234O\145\153\&6zV",PropAuthenticationData +// "\221|\143\f",PropPayloadFormatIndicator 153,PropServerKeepAlive 8558,PropSubscriptionIdentifier 26,PropContentType +// "k\172\f\135\155\&7@\142\b\165\154^\144\t,\190\216",PropMessageExpiryInterval 11221,PropMessageExpiryInterval +// 2390,PropUserProperty "" "\128U\206:\255%\145e"] +TEST(Subscribe5QCTest, Encode26) { + uint8_t pkt[] = { + 0x82, 0xb3, 0x2, 0x3, 0x1f, 0x99, 0x1, 0x28, 0x8b, 0x12, 0x0, 0x9, 0xb2, 0xd7, 0x6e, 0x1c, 0x8b, 0x93, 0x3, + 0x19, 0x20, 0x29, 0xe2, 0x26, 0x0, 0x6, 0x93, 0x31, 0x25, 0x24, 0xde, 0x23, 0x0, 0x1c, 0x96, 0x7b, 0xc7, 0xf1, + 0x9d, 0xb1, 0x33, 0x6, 0x1b, 0xf6, 0x88, 0x1c, 0xac, 0x8f, 0x8f, 0xcf, 0xb3, 0xe4, 0xe0, 0x83, 0xc9, 0x9a, 0xcb, + 0xff, 0xf2, 0x9c, 0x89, 0x7d, 0x2a, 0x8d, 0x22, 0x32, 0x74, 0x2a, 0x15, 0x26, 0x0, 0x9, 0xe6, 0x33, 0xbd, 0x36, + 0xc, 0x6c, 0x16, 0x15, 0x12, 0x0, 0x14, 0x6e, 0x38, 0x83, 0x62, 0xa1, 0x35, 0x9f, 0x9a, 0x80, 0xc2, 0xc2, 0xe1, + 0x3e, 0xea, 0x4f, 0x91, 0x99, 0x36, 0x7a, 0x56, 0x16, 0x0, 0x4, 0xdd, 0x7c, 0x8f, 0xc, 0x1, 0x99, 0x13, 0x21, + 0x6e, 0xb, 0x1a, 0x3, 0x0, 0x11, 0x6b, 0xac, 0xc, 0x87, 0x9b, 0x37, 0x40, 0x8e, 0x8, 0xa5, 0x9a, 0x5e, 0x90, + 0x9, 0x2c, 0xbe, 0xd8, 0x2, 0x0, 0x0, 0x2b, 0xd5, 0x2, 0x0, 0x0, 0x9, 0x56, 0x26, 0x0, 0x0, 0x0, 0x8, + 0x80, 0x55, 0xce, 0x3a, 0xff, 0x25, 0x91, 0x65, 0x0, 0x7, 0x9c, 0xdc, 0x48, 0x50, 0x5a, 0x92, 0xb0, 0x16, 0x0, + 0xe, 0xcc, 0x9, 0xfb, 0x34, 0x8c, 0x5e, 0xc6, 0x9e, 0x50, 0xa5, 0x1d, 0xfd, 0xb6, 0xea, 0x22, 0x0, 0x7, 0x8c, + 0xad, 0xaa, 0x2e, 0x95, 0x99, 0x90, 0x6, 0x0, 0x1e, 0x73, 0x20, 0xab, 0x9c, 0x2f, 0x2d, 0x6c, 0x56, 0xb8, 0x20, + 0x9b, 0x67, 0xa5, 0xc6, 0x73, 0x66, 0xb4, 0x3e, 0xe9, 0x85, 0x82, 0xdd, 0xdc, 0x9c, 0xb2, 0xf4, 0x39, 0xf1, 0xe1, + 0x7c, 0x16, 0x0, 0xa, 0x3a, 0x38, 0x9b, 0x2e, 0xcf, 0x96, 0x11, 0xb4, 0x63, 0xb6, 0x2a, 0x0, 0xd, 0xe8, 0x5e, + 0x1f, 0xf7, 0x19, 0x55, 0xdf, 0x72, 0x61, 0x87, 0x55, 0x2b, 0x4b, 0x14, 0x0, 0x12, 0x50, 0x79, 0xe2, 0x1c, 0x69, + 0x5f, 0xc2, 0xb3, 0xdd, 0x8a, 0xc4, 0xd0, 0xef, 0x83, 0x72, 0x7b, 0xad, 0x6e, 0x5, 0x0, 0xb, 0x64, 0xfe, 0xc5, + 0xe5, 0xb6, 0xd8, 0x3b, 0x3c, 0x2a, 0x3, 0x5, 0x6, 0x0, 0x8, 0x8d, 0x50, 0xf3, 0x81, 0x3d, 0xb1, 0x56, 0xd6, + 0xd, 0x0, 0x2, 0xa4, 0x63, 0x12}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[10]; + uint8_t topic_filter_s0_bytes[] = {0x9c, 0xdc, 0x48, 0x50, 0x5a, 0x92, 0xb0}; + lwmqtt_string_t topic_filter_s0 = {7, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xcc, 0x9, 0xfb, 0x34, 0x8c, 0x5e, 0xc6, 0x9e, 0x50, 0xa5, 0x1d, 0xfd, 0xb6, 0xea}; + lwmqtt_string_t topic_filter_s1 = {14, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x8c, 0xad, 0xaa, 0x2e, 0x95, 0x99, 0x90}; + lwmqtt_string_t topic_filter_s2 = {7, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x73, 0x20, 0xab, 0x9c, 0x2f, 0x2d, 0x6c, 0x56, 0xb8, 0x20, + 0x9b, 0x67, 0xa5, 0xc6, 0x73, 0x66, 0xb4, 0x3e, 0xe9, 0x85, + 0x82, 0xdd, 0xdc, 0x9c, 0xb2, 0xf4, 0x39, 0xf1, 0xe1, 0x7c}; + lwmqtt_string_t topic_filter_s3 = {30, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x3a, 0x38, 0x9b, 0x2e, 0xcf, 0x96, 0x11, 0xb4, 0x63, 0xb6}; + lwmqtt_string_t topic_filter_s4 = {10, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xe8, 0x5e, 0x1f, 0xf7, 0x19, 0x55, 0xdf, 0x72, 0x61, 0x87, 0x55, 0x2b, 0x4b}; + lwmqtt_string_t topic_filter_s5 = {13, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x50, 0x79, 0xe2, 0x1c, 0x69, 0x5f, 0xc2, 0xb3, 0xdd, + 0x8a, 0xc4, 0xd0, 0xef, 0x83, 0x72, 0x7b, 0xad, 0x6e}; + lwmqtt_string_t topic_filter_s6 = {18, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x64, 0xfe, 0xc5, 0xe5, 0xb6, 0xd8, 0x3b, 0x3c, 0x2a, 0x3, 0x5}; + lwmqtt_string_t topic_filter_s7 = {11, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x8d, 0x50, 0xf3, 0x81, 0x3d, 0xb1, 0x56, 0xd6}; + lwmqtt_string_t topic_filter_s8 = {8, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0xa4, 0x63}; + lwmqtt_string_t topic_filter_s9 = {2, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + lwmqtt_sub_options_t sub_opts[10]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS2; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS2; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = true; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[4].retain_as_published = true; + sub_opts[4].no_local = false; + sub_opts[5].qos = LWMQTT_QOS0; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = true; + sub_opts[6].qos = LWMQTT_QOS1; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = true; + sub_opts[7].qos = LWMQTT_QOS2; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = true; + sub_opts[8].qos = LWMQTT_QOS1; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = true; + sub_opts[8].no_local = true; + sub_opts[9].qos = LWMQTT_QOS2; + sub_opts[9].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[9].retain_as_published = false; + sub_opts[9].no_local = false; + uint8_t bytesprops0[] = {0xb2, 0xd7, 0x6e, 0x1c, 0x8b, 0x93, 0x3, 0x19, 0x20}; + uint8_t bytesprops2[] = {0x96, 0x7b, 0xc7, 0xf1, 0x9d, 0xb1, 0x33, 0x6, 0x1b, 0xf6, 0x88, 0x1c, 0xac, 0x8f, + 0x8f, 0xcf, 0xb3, 0xe4, 0xe0, 0x83, 0xc9, 0x9a, 0xcb, 0xff, 0xf2, 0x9c, 0x89, 0x7d}; + uint8_t bytesprops1[] = {0x93, 0x31, 0x25, 0x24, 0xde, 0x23}; + uint8_t bytesprops4[] = {0x6e, 0x38, 0x83, 0x62, 0xa1, 0x35, 0x9f, 0x9a, 0x80, 0xc2, + 0xc2, 0xe1, 0x3e, 0xea, 0x4f, 0x91, 0x99, 0x36, 0x7a, 0x56}; + uint8_t bytesprops3[] = {0xe6, 0x33, 0xbd, 0x36, 0xc, 0x6c, 0x16, 0x15, 0x12}; + uint8_t bytesprops5[] = {0xdd, 0x7c, 0x8f, 0xc}; + uint8_t bytesprops6[] = {0x6b, 0xac, 0xc, 0x87, 0x9b, 0x37, 0x40, 0x8e, 0x8, + 0xa5, 0x9a, 0x5e, 0x90, 0x9, 0x2c, 0xbe, 0xd8}; + uint8_t bytesprops8[] = {0x80, 0x55, 0xce, 0x3a, 0xff, 0x25, 0x91, 0x65}; + uint8_t bytesprops7[] = {0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 139}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {9, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 226}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {6, (char*)&bytesprops1}, .v = {28, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 141}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 12916}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 21}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {9, (char*)&bytesprops3}, .v = {20, (char*)&bytesprops4}}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {4, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 153}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 8558}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 26}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {17, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 11221}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 2390}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {0, (char*)&bytesprops7}, .v = {8, (char*)&bytesprops8}}}}, + }; + + lwmqtt_properties_t props = {16, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 799, 10, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 2526 [("\211\175",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = True, _noLocal +// = True, _subQoS = QoS1}),("a?\SUB\v\176$\210A\128\248oSU\134\STX\236J,w",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS0}),("\EOTO\245G\249\200\n4\SI1\239\b\NAKto3",SubOptions {_retainHandling = DoNotSendOnSubscribe, +// _retainAsPublished = False, _noLocal = False, _subQoS = QoS0}),("t[^\ESC",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = QoS1})] [PropPayloadFormatIndicator +// 178,PropWildcardSubscriptionAvailable 190,PropResponseInformation +// "I\159\137k\r\156\168\182\229\221C\b\155\136\\\212|\t",PropAuthenticationMethod +// "\DC2\244o\189z,\EM\214\222\136+\179\252\ENQ\\D^\182\163K.",PropServerKeepAlive 21065,PropMessageExpiryInterval +// 16243,PropCorrelationData "\t\155\238\148\207\157Q+\171\131",PropReceiveMaximum 23618,PropSharedSubscriptionAvailable +// 211,PropMessageExpiryInterval 18766,PropWildcardSubscriptionAvailable 79,PropCorrelationData +// "6e\161\162Q\141\198\SYN\156\189\229\218\135,\216U\136\224\&5",PropUserProperty +// "\248\214\133r^\168\182mw\RS\154g!\245Hm\163\243y*8d\202\228\&6\162\248\208" +// "k\FS\SII\169\EOT\247UD'\140hx\220\ETB",PropServerReference "\SI<:\245",PropMaximumQoS +// 113,PropSharedSubscriptionAvailable 17,PropWildcardSubscriptionAvailable 32,PropResponseInformation +// "\206n8\ACK\174?\DC2\153\194\213:\249m,t\217\&3{\244\157\181\194nV",PropMaximumQoS 30,PropRequestResponseInformation +// 190,PropAuthenticationData "*{Q\SYN\DLE`i3~\210\158~\218i\234\152\227\&0\163\237",PropTopicAlias +// 27790,PropUserProperty "T\SYN5\231B&\t\NAK\251\170)\196&\240\247\253_A\SUB^J_;\238" +// "\247\253\211'\151\229\ETX\153",PropMessageExpiryInterval 4312,PropServerReference +// "]:\SOH\133;o\154\214K\187\161\201\191x\204el\129\131\SOH\137\241ENr\223\192\148",PropSharedSubscriptionAvailable +// 182] +TEST(Subscribe5QCTest, Encode27) { + uint8_t pkt[] = { + 0x82, 0xe2, 0x2, 0x9, 0xde, 0xa9, 0x2, 0x1, 0xb2, 0x28, 0xbe, 0x1a, 0x0, 0x12, 0x49, 0x9f, 0x89, 0x6b, 0xd, + 0x9c, 0xa8, 0xb6, 0xe5, 0xdd, 0x43, 0x8, 0x9b, 0x88, 0x5c, 0xd4, 0x7c, 0x9, 0x15, 0x0, 0x15, 0x12, 0xf4, 0x6f, + 0xbd, 0x7a, 0x2c, 0x19, 0xd6, 0xde, 0x88, 0x2b, 0xb3, 0xfc, 0x5, 0x5c, 0x44, 0x5e, 0xb6, 0xa3, 0x4b, 0x2e, 0x13, + 0x52, 0x49, 0x2, 0x0, 0x0, 0x3f, 0x73, 0x9, 0x0, 0xa, 0x9, 0x9b, 0xee, 0x94, 0xcf, 0x9d, 0x51, 0x2b, 0xab, + 0x83, 0x21, 0x5c, 0x42, 0x2a, 0xd3, 0x2, 0x0, 0x0, 0x49, 0x4e, 0x28, 0x4f, 0x9, 0x0, 0x13, 0x36, 0x65, 0xa1, + 0xa2, 0x51, 0x8d, 0xc6, 0x16, 0x9c, 0xbd, 0xe5, 0xda, 0x87, 0x2c, 0xd8, 0x55, 0x88, 0xe0, 0x35, 0x26, 0x0, 0x1c, + 0xf8, 0xd6, 0x85, 0x72, 0x5e, 0xa8, 0xb6, 0x6d, 0x77, 0x1e, 0x9a, 0x67, 0x21, 0xf5, 0x48, 0x6d, 0xa3, 0xf3, 0x79, + 0x2a, 0x38, 0x64, 0xca, 0xe4, 0x36, 0xa2, 0xf8, 0xd0, 0x0, 0xf, 0x6b, 0x1c, 0xf, 0x49, 0xa9, 0x4, 0xf7, 0x55, + 0x44, 0x27, 0x8c, 0x68, 0x78, 0xdc, 0x17, 0x1c, 0x0, 0x4, 0xf, 0x3c, 0x3a, 0xf5, 0x24, 0x71, 0x2a, 0x11, 0x28, + 0x20, 0x1a, 0x0, 0x18, 0xce, 0x6e, 0x38, 0x6, 0xae, 0x3f, 0x12, 0x99, 0xc2, 0xd5, 0x3a, 0xf9, 0x6d, 0x2c, 0x74, + 0xd9, 0x33, 0x7b, 0xf4, 0x9d, 0xb5, 0xc2, 0x6e, 0x56, 0x24, 0x1e, 0x19, 0xbe, 0x16, 0x0, 0x14, 0x2a, 0x7b, 0x51, + 0x16, 0x10, 0x60, 0x69, 0x33, 0x7e, 0xd2, 0x9e, 0x7e, 0xda, 0x69, 0xea, 0x98, 0xe3, 0x30, 0xa3, 0xed, 0x23, 0x6c, + 0x8e, 0x26, 0x0, 0x18, 0x54, 0x16, 0x35, 0xe7, 0x42, 0x26, 0x9, 0x15, 0xfb, 0xaa, 0x29, 0xc4, 0x26, 0xf0, 0xf7, + 0xfd, 0x5f, 0x41, 0x1a, 0x5e, 0x4a, 0x5f, 0x3b, 0xee, 0x0, 0x8, 0xf7, 0xfd, 0xd3, 0x27, 0x97, 0xe5, 0x3, 0x99, + 0x2, 0x0, 0x0, 0x10, 0xd8, 0x1c, 0x0, 0x1c, 0x5d, 0x3a, 0x1, 0x85, 0x3b, 0x6f, 0x9a, 0xd6, 0x4b, 0xbb, 0xa1, + 0xc9, 0xbf, 0x78, 0xcc, 0x65, 0x6c, 0x81, 0x83, 0x1, 0x89, 0xf1, 0x45, 0x4e, 0x72, 0xdf, 0xc0, 0x94, 0x2a, 0xb6, + 0x0, 0x2, 0xd3, 0xaf, 0xd, 0x0, 0x13, 0x61, 0x3f, 0x1a, 0xb, 0xb0, 0x24, 0xd2, 0x41, 0x80, 0xf8, 0x6f, 0x53, + 0x55, 0x86, 0x2, 0xec, 0x4a, 0x2c, 0x77, 0x8, 0x0, 0x10, 0x4, 0x4f, 0xf5, 0x47, 0xf9, 0xc8, 0xa, 0x34, 0xf, + 0x31, 0xef, 0x8, 0x15, 0x74, 0x6f, 0x33, 0x20, 0x0, 0x4, 0x74, 0x5b, 0x5e, 0x1b, 0x25}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[4]; + uint8_t topic_filter_s0_bytes[] = {0xd3, 0xaf}; + lwmqtt_string_t topic_filter_s0 = {2, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x61, 0x3f, 0x1a, 0xb, 0xb0, 0x24, 0xd2, 0x41, 0x80, 0xf8, + 0x6f, 0x53, 0x55, 0x86, 0x2, 0xec, 0x4a, 0x2c, 0x77}; + lwmqtt_string_t topic_filter_s1 = {19, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x4, 0x4f, 0xf5, 0x47, 0xf9, 0xc8, 0xa, 0x34, + 0xf, 0x31, 0xef, 0x8, 0x15, 0x74, 0x6f, 0x33}; + lwmqtt_string_t topic_filter_s2 = {16, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x74, 0x5b, 0x5e, 0x1b}; + lwmqtt_string_t topic_filter_s3 = {4, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + lwmqtt_sub_options_t sub_opts[4]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS0; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = true; + sub_opts[1].no_local = false; + sub_opts[2].qos = LWMQTT_QOS0; + sub_opts[2].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[2].retain_as_published = false; + sub_opts[2].no_local = false; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = true; + uint8_t bytesprops0[] = {0x49, 0x9f, 0x89, 0x6b, 0xd, 0x9c, 0xa8, 0xb6, 0xe5, + 0xdd, 0x43, 0x8, 0x9b, 0x88, 0x5c, 0xd4, 0x7c, 0x9}; + uint8_t bytesprops1[] = {0x12, 0xf4, 0x6f, 0xbd, 0x7a, 0x2c, 0x19, 0xd6, 0xde, 0x88, 0x2b, + 0xb3, 0xfc, 0x5, 0x5c, 0x44, 0x5e, 0xb6, 0xa3, 0x4b, 0x2e}; + uint8_t bytesprops2[] = {0x9, 0x9b, 0xee, 0x94, 0xcf, 0x9d, 0x51, 0x2b, 0xab, 0x83}; + uint8_t bytesprops3[] = {0x36, 0x65, 0xa1, 0xa2, 0x51, 0x8d, 0xc6, 0x16, 0x9c, 0xbd, + 0xe5, 0xda, 0x87, 0x2c, 0xd8, 0x55, 0x88, 0xe0, 0x35}; + uint8_t bytesprops5[] = {0x6b, 0x1c, 0xf, 0x49, 0xa9, 0x4, 0xf7, 0x55, 0x44, 0x27, 0x8c, 0x68, 0x78, 0xdc, 0x17}; + uint8_t bytesprops4[] = {0xf8, 0xd6, 0x85, 0x72, 0x5e, 0xa8, 0xb6, 0x6d, 0x77, 0x1e, 0x9a, 0x67, 0x21, 0xf5, + 0x48, 0x6d, 0xa3, 0xf3, 0x79, 0x2a, 0x38, 0x64, 0xca, 0xe4, 0x36, 0xa2, 0xf8, 0xd0}; + uint8_t bytesprops6[] = {0xf, 0x3c, 0x3a, 0xf5}; + uint8_t bytesprops7[] = {0xce, 0x6e, 0x38, 0x6, 0xae, 0x3f, 0x12, 0x99, 0xc2, 0xd5, 0x3a, 0xf9, + 0x6d, 0x2c, 0x74, 0xd9, 0x33, 0x7b, 0xf4, 0x9d, 0xb5, 0xc2, 0x6e, 0x56}; + uint8_t bytesprops8[] = {0x2a, 0x7b, 0x51, 0x16, 0x10, 0x60, 0x69, 0x33, 0x7e, 0xd2, + 0x9e, 0x7e, 0xda, 0x69, 0xea, 0x98, 0xe3, 0x30, 0xa3, 0xed}; + uint8_t bytesprops10[] = {0xf7, 0xfd, 0xd3, 0x27, 0x97, 0xe5, 0x3, 0x99}; + uint8_t bytesprops9[] = {0x54, 0x16, 0x35, 0xe7, 0x42, 0x26, 0x9, 0x15, 0xfb, 0xaa, 0x29, 0xc4, + 0x26, 0xf0, 0xf7, 0xfd, 0x5f, 0x41, 0x1a, 0x5e, 0x4a, 0x5f, 0x3b, 0xee}; + uint8_t bytesprops11[] = {0x5d, 0x3a, 0x1, 0x85, 0x3b, 0x6f, 0x9a, 0xd6, 0x4b, 0xbb, 0xa1, 0xc9, 0xbf, 0x78, + 0xcc, 0x65, 0x6c, 0x81, 0x83, 0x1, 0x89, 0xf1, 0x45, 0x4e, 0x72, 0xdf, 0xc0, 0x94}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 178}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 190}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {18, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {21, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 21065}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 16243}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {10, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 23618}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 211}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 18766}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 79}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {19, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {28, (char*)&bytesprops4}, .v = {15, (char*)&bytesprops5}}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {4, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 113}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 17}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 32}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {24, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 30}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 190}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {20, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 27790}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {24, (char*)&bytesprops9}, .v = {8, (char*)&bytesprops10}}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 4312}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {28, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 182}}, + }; + + lwmqtt_properties_t props = {26, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 2526, 4, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 20875 [("\204\138\132\154\245\&9=\219v\220Se\229\161Wh\183\183\198zd\248",SubOptions +// {_retainHandling = SendOnSubscribeNew, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS2}),("\RS\162h\189\t>\133L\199l'\244\164\235\180\194\221\SUB\DEL\226\157",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS2}),("\254?\146]\b\244ZJ\CAN\SO\132",SubOptions {_retainHandling = SendOnSubscribe, _retainAsPublished = True, +// _noLocal = True, _subQoS = QoS1}),("m\186m/\\gx^\145\214|\209B\210\&4\174o\149`",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS1}),("\SUBq\181A9\r\162p:\RS0\152-\191\GS\b\ESC\CAN{X\231\237:\158T\155>\209\246\247",SubOptions {_retainHandling +// = SendOnSubscribeNew, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS2}),("i\250\186\175\SI\FSa\220\183\EM\160f*o\137n\164\&0",SubOptions {_retainHandling = SendOnSubscribeNew, +// _retainAsPublished = False, _noLocal = True, _subQoS = QoS1}),("6",SubOptions {_retainHandling = SendOnSubscribe, +// _retainAsPublished = False, _noLocal = True, _subQoS = QoS0}),("{4[\185\DC1\b\217\STXA\US",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = False, _subQoS = +// QoS1}),("\253J\226,\219z\148\248 \194\152\ENQ\nD\209\164\199\201N\245\231\&7\216\244",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS0})] [PropAuthenticationMethod +// "\170\tH1\145\f\r*\200\&78,\SUB\188\214\164\247<\153",PropCorrelationData +// "}\193\239\200Gc\195\236\136GO\STXl\161}\FS",PropReasonString "\179W\r\197\158\245\&1",PropPayloadFormatIndicator +// 201,PropAuthenticationMethod "\169",PropCorrelationData +// "\FS*\187\&0\DC3\EM\170G{gF\237\ENQh\162d\137\207v",PropRequestResponseInformation 94] +TEST(Subscribe5QCTest, Encode28) { + uint8_t pkt[] = {0x82, 0x8b, 0x2, 0x51, 0x8b, 0x51, 0x15, 0x0, 0x13, 0xaa, 0x9, 0x48, 0x31, 0x91, 0xc, 0xd, 0x2a, + 0xc8, 0x37, 0x38, 0x2c, 0x1a, 0xbc, 0xd6, 0xa4, 0xf7, 0x3c, 0x99, 0x9, 0x0, 0x10, 0x7d, 0xc1, 0xef, + 0xc8, 0x47, 0x63, 0xc3, 0xec, 0x88, 0x47, 0x4f, 0x2, 0x6c, 0xa1, 0x7d, 0x1c, 0x1f, 0x0, 0x7, 0xb3, + 0x57, 0xd, 0xc5, 0x9e, 0xf5, 0x31, 0x1, 0xc9, 0x15, 0x0, 0x1, 0xa9, 0x9, 0x0, 0x13, 0x1c, 0x2a, + 0xbb, 0x30, 0x13, 0x19, 0xaa, 0x47, 0x7b, 0x67, 0x46, 0xed, 0x5, 0x68, 0xa2, 0x64, 0x89, 0xcf, 0x76, + 0x19, 0x5e, 0x0, 0x16, 0xcc, 0x8a, 0x84, 0x9a, 0xf5, 0x39, 0x3d, 0xdb, 0x76, 0xdc, 0x53, 0x65, 0xe5, + 0xa1, 0x57, 0x68, 0xb7, 0xb7, 0xc6, 0x7a, 0x64, 0xf8, 0x1a, 0x0, 0x15, 0x1e, 0xa2, 0x68, 0xbd, 0x9, + 0x3e, 0x85, 0x4c, 0xc7, 0x6c, 0x27, 0xf4, 0xa4, 0xeb, 0xb4, 0xc2, 0xdd, 0x1a, 0x7f, 0xe2, 0x9d, 0x6, + 0x0, 0xb, 0xfe, 0x3f, 0x92, 0x5d, 0x8, 0xf4, 0x5a, 0x4a, 0x18, 0xe, 0x84, 0xd, 0x0, 0x13, 0x6d, + 0xba, 0x6d, 0x2f, 0x5c, 0x67, 0x78, 0x5e, 0x91, 0xd6, 0x7c, 0xd1, 0x42, 0xd2, 0x34, 0xae, 0x6f, 0x95, + 0x60, 0x25, 0x0, 0x1e, 0x1a, 0x71, 0xb5, 0x41, 0x39, 0xd, 0xa2, 0x70, 0x3a, 0x1e, 0x30, 0x98, 0x2d, + 0xbf, 0x1d, 0x8, 0x1b, 0x18, 0x7b, 0x58, 0xe7, 0xed, 0x3a, 0x9e, 0x54, 0x9b, 0x3e, 0xd1, 0xf6, 0xf7, + 0x16, 0x0, 0x12, 0x69, 0xfa, 0xba, 0xaf, 0xf, 0x1c, 0x61, 0xdc, 0xb7, 0x19, 0xa0, 0x66, 0x2a, 0x6f, + 0x89, 0x6e, 0xa4, 0x30, 0x15, 0x0, 0x1, 0x36, 0x4, 0x0, 0xa, 0x7b, 0x34, 0x5b, 0xb9, 0x11, 0x8, + 0xd9, 0x2, 0x41, 0x1f, 0x29, 0x0, 0x18, 0xfd, 0x4a, 0xe2, 0x2c, 0xdb, 0x7a, 0x94, 0xf8, 0x20, 0xc2, + 0x98, 0x5, 0xa, 0x44, 0xd1, 0xa4, 0xc7, 0xc9, 0x4e, 0xf5, 0xe7, 0x37, 0xd8, 0xf4, 0x20}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[9]; + uint8_t topic_filter_s0_bytes[] = {0xcc, 0x8a, 0x84, 0x9a, 0xf5, 0x39, 0x3d, 0xdb, 0x76, 0xdc, 0x53, + 0x65, 0xe5, 0xa1, 0x57, 0x68, 0xb7, 0xb7, 0xc6, 0x7a, 0x64, 0xf8}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x1e, 0xa2, 0x68, 0xbd, 0x9, 0x3e, 0x85, 0x4c, 0xc7, 0x6c, 0x27, + 0xf4, 0xa4, 0xeb, 0xb4, 0xc2, 0xdd, 0x1a, 0x7f, 0xe2, 0x9d}; + lwmqtt_string_t topic_filter_s1 = {21, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xfe, 0x3f, 0x92, 0x5d, 0x8, 0xf4, 0x5a, 0x4a, 0x18, 0xe, 0x84}; + lwmqtt_string_t topic_filter_s2 = {11, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x6d, 0xba, 0x6d, 0x2f, 0x5c, 0x67, 0x78, 0x5e, 0x91, 0xd6, + 0x7c, 0xd1, 0x42, 0xd2, 0x34, 0xae, 0x6f, 0x95, 0x60}; + lwmqtt_string_t topic_filter_s3 = {19, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x1a, 0x71, 0xb5, 0x41, 0x39, 0xd, 0xa2, 0x70, 0x3a, 0x1e, + 0x30, 0x98, 0x2d, 0xbf, 0x1d, 0x8, 0x1b, 0x18, 0x7b, 0x58, + 0xe7, 0xed, 0x3a, 0x9e, 0x54, 0x9b, 0x3e, 0xd1, 0xf6, 0xf7}; + lwmqtt_string_t topic_filter_s4 = {30, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x69, 0xfa, 0xba, 0xaf, 0xf, 0x1c, 0x61, 0xdc, 0xb7, + 0x19, 0xa0, 0x66, 0x2a, 0x6f, 0x89, 0x6e, 0xa4, 0x30}; + lwmqtt_string_t topic_filter_s5 = {18, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x36}; + lwmqtt_string_t topic_filter_s6 = {1, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x7b, 0x34, 0x5b, 0xb9, 0x11, 0x8, 0xd9, 0x2, 0x41, 0x1f}; + lwmqtt_string_t topic_filter_s7 = {10, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xfd, 0x4a, 0xe2, 0x2c, 0xdb, 0x7a, 0x94, 0xf8, 0x20, 0xc2, 0x98, 0x5, + 0xa, 0x44, 0xd1, 0xa4, 0xc7, 0xc9, 0x4e, 0xf5, 0xe7, 0x37, 0xd8, 0xf4}; + lwmqtt_string_t topic_filter_s8 = {24, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + lwmqtt_sub_options_t sub_opts[9]; + sub_opts[0].qos = LWMQTT_QOS2; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = false; + sub_opts[1].qos = LWMQTT_QOS2; + sub_opts[1].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS1; + sub_opts[3].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = true; + sub_opts[4].qos = LWMQTT_QOS2; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = true; + sub_opts[5].qos = LWMQTT_QOS1; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = true; + sub_opts[6].qos = LWMQTT_QOS0; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = false; + sub_opts[6].no_local = true; + sub_opts[7].qos = LWMQTT_QOS1; + sub_opts[7].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[7].retain_as_published = true; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS0; + sub_opts[8].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = false; + uint8_t bytesprops0[] = {0xaa, 0x9, 0x48, 0x31, 0x91, 0xc, 0xd, 0x2a, 0xc8, 0x37, + 0x38, 0x2c, 0x1a, 0xbc, 0xd6, 0xa4, 0xf7, 0x3c, 0x99}; + uint8_t bytesprops1[] = {0x7d, 0xc1, 0xef, 0xc8, 0x47, 0x63, 0xc3, 0xec, + 0x88, 0x47, 0x4f, 0x2, 0x6c, 0xa1, 0x7d, 0x1c}; + uint8_t bytesprops2[] = {0xb3, 0x57, 0xd, 0xc5, 0x9e, 0xf5, 0x31}; + uint8_t bytesprops3[] = {0xa9}; + uint8_t bytesprops4[] = {0x1c, 0x2a, 0xbb, 0x30, 0x13, 0x19, 0xaa, 0x47, 0x7b, 0x67, + 0x46, 0xed, 0x5, 0x68, 0xa2, 0x64, 0x89, 0xcf, 0x76}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)21, .value = {.str = {19, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {16, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {7, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 201}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {1, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {19, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 94}}, + }; + + lwmqtt_properties_t props = {7, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 20875, 9, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 22546 [("f\185p\ENQ\162\139-.\158v+^\157\SUB",SubOptions {_retainHandling = DoNotSendOnSubscribe, +// _retainAsPublished = False, _noLocal = True, _subQoS = QoS1}),("\164\243\&8\128l\255}\242i4",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS1}),("5\223)'\144\189\195\212k{\GS\165\"\ESC/+%m\175\161\235\NAK\223\142\205\225$\224\ETB\f",SubOptions +// {_retainHandling = DoNotSendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS1}),("v\167\184F\198B\ENQ\ESC\ACK0\ETB{f6\228\ta\185\207\154\175\171\187~\175\142'",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = False, _noLocal = True, _subQoS = QoS0}),("\204",SubOptions {_retainHandling +// = SendOnSubscribeNew, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS1}),("\218\246\&2\EOT\168$\EOTK\222\\S[\243",SubOptions {_retainHandling = SendOnSubscribeNew, _retainAsPublished +// = False, _noLocal = False, _subQoS = +// QoS1}),("\212\216\165t\tpPa\167\149\147\v\b\SO\163\236\SO\222*@h\158&\239",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = True, _noLocal = True, _subQoS = +// QoS2}),("\234kp\252kzk\SI\247\243\&2\172\GS\222\ESC]7\232\166\230S\174h\192%w\152",SubOptions {_retainHandling = +// SendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = QoS2}),("(\DEL\146\a\222 ",SubOptions +// {_retainHandling = SendOnSubscribe, _retainAsPublished = False, _noLocal = True, _subQoS = +// QoS0}),("\b_\249n\169r0*w\\_ym\195Mp\253\145\200\213\239]q\136\135",SubOptions {_retainHandling = +// DoNotSendOnSubscribe, _retainAsPublished = False, _noLocal = False, _subQoS = +// QoS2}),("\174'S\r\251\\\252\192\250\128\&4U\184\168\201s\DEL\STXe1\240",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = True, _noLocal = True, _subQoS = QoS2})] [PropAuthenticationMethod +// "m\"!\230\f\208\DLE\190C\182o\GS\\\151\182\SO\\>\EOT\149\158\187\200\149",PropWillDelayInterval +// 3768,PropAssignedClientIdentifier "+5Bz\CAN\199p\169\167}\179\137u8fC~e",PropMessageExpiryInterval +// 24032,PropServerKeepAlive 22317,PropAuthenticationMethod "\\\140\SOH\198\130\183",PropMaximumPacketSize +// 4777,PropAssignedClientIdentifier "\DC1\216\198\195",PropRetainAvailable 37,PropResponseTopic +// "#\163\240*o\223\215P>x\STX\SI\243r\DC2\181\249",PropReceiveMaximum 22096,PropResponseTopic +// "\156\137\182H\204o\202\EOT/\146\233\DEL\136^\SO\137\236M\228\DC4\ACK.\233",PropReasonString "+\232\135{\128\222 +// \163Y\EOT\153\134\245\198\162\167\236\DLE\248\213M>\131Q\208x\207w\\",PropWildcardSubscriptionAvailable +// 207,PropTopicAliasMaximum 7002,PropMessageExpiryInterval 14743] +TEST(Subscribe5QCTest, Encode29) { + uint8_t pkt[] = { + 0x82, 0x9a, 0x3, 0x58, 0x12, 0xaf, 0x1, 0x15, 0x0, 0x18, 0x6d, 0x22, 0x21, 0xe6, 0xc, 0xd0, 0x10, 0xbe, 0x43, + 0xb6, 0x6f, 0x1d, 0x5c, 0x97, 0xb6, 0xe, 0x5c, 0x3e, 0x4, 0x95, 0x9e, 0xbb, 0xc8, 0x95, 0x18, 0x0, 0x0, 0xe, + 0xb8, 0x12, 0x0, 0x12, 0x2b, 0x35, 0x42, 0x7a, 0x18, 0xc7, 0x70, 0xa9, 0xa7, 0x7d, 0xb3, 0x89, 0x75, 0x38, 0x66, + 0x43, 0x7e, 0x65, 0x2, 0x0, 0x0, 0x5d, 0xe0, 0x13, 0x57, 0x2d, 0x15, 0x0, 0x6, 0x5c, 0x8c, 0x1, 0xc6, 0x82, + 0xb7, 0x27, 0x0, 0x0, 0x12, 0xa9, 0x12, 0x0, 0x4, 0x11, 0xd8, 0xc6, 0xc3, 0x25, 0x25, 0x8, 0x0, 0x11, 0x23, + 0xa3, 0xf0, 0x2a, 0x6f, 0xdf, 0xd7, 0x50, 0x3e, 0x78, 0x2, 0xf, 0xf3, 0x72, 0x12, 0xb5, 0xf9, 0x21, 0x56, 0x50, + 0x8, 0x0, 0x17, 0x9c, 0x89, 0xb6, 0x48, 0xcc, 0x6f, 0xca, 0x4, 0x2f, 0x92, 0xe9, 0x7f, 0x88, 0x5e, 0xe, 0x89, + 0xec, 0x4d, 0xe4, 0x14, 0x6, 0x2e, 0xe9, 0x1f, 0x0, 0x1d, 0x2b, 0xe8, 0x87, 0x7b, 0x80, 0xde, 0x20, 0xa3, 0x59, + 0x4, 0x99, 0x86, 0xf5, 0xc6, 0xa2, 0xa7, 0xec, 0x10, 0xf8, 0xd5, 0x4d, 0x3e, 0x83, 0x51, 0xd0, 0x78, 0xcf, 0x77, + 0x5c, 0x28, 0xcf, 0x22, 0x1b, 0x5a, 0x2, 0x0, 0x0, 0x39, 0x97, 0x0, 0xe, 0x66, 0xb9, 0x70, 0x5, 0xa2, 0x8b, + 0x2d, 0x2e, 0x9e, 0x76, 0x2b, 0x5e, 0x9d, 0x1a, 0x25, 0x0, 0xa, 0xa4, 0xf3, 0x38, 0x80, 0x6c, 0xff, 0x7d, 0xf2, + 0x69, 0x34, 0x25, 0x0, 0x1e, 0x35, 0xdf, 0x29, 0x27, 0x90, 0xbd, 0xc3, 0xd4, 0x6b, 0x7b, 0x1d, 0xa5, 0x22, 0x1b, + 0x2f, 0x2b, 0x25, 0x6d, 0xaf, 0xa1, 0xeb, 0x15, 0xdf, 0x8e, 0xcd, 0xe1, 0x24, 0xe0, 0x17, 0xc, 0x2d, 0x0, 0x1b, + 0x76, 0xa7, 0xb8, 0x46, 0xc6, 0x42, 0x5, 0x1b, 0x6, 0x30, 0x17, 0x7b, 0x66, 0x36, 0xe4, 0x9, 0x61, 0xb9, 0xcf, + 0x9a, 0xaf, 0xab, 0xbb, 0x7e, 0xaf, 0x8e, 0x27, 0x14, 0x0, 0x1, 0xcc, 0x15, 0x0, 0xd, 0xda, 0xf6, 0x32, 0x4, + 0xa8, 0x24, 0x4, 0x4b, 0xde, 0x5c, 0x53, 0x5b, 0xf3, 0x11, 0x0, 0x18, 0xd4, 0xd8, 0xa5, 0x74, 0x9, 0x70, 0x50, + 0x61, 0xa7, 0x95, 0x93, 0xb, 0x8, 0xe, 0xa3, 0xec, 0xe, 0xde, 0x2a, 0x40, 0x68, 0x9e, 0x26, 0xef, 0xe, 0x0, + 0x1b, 0xea, 0x6b, 0x70, 0xfc, 0x6b, 0x7a, 0x6b, 0xf, 0xf7, 0xf3, 0x32, 0xac, 0x1d, 0xde, 0x1b, 0x5d, 0x37, 0xe8, + 0xa6, 0xe6, 0x53, 0xae, 0x68, 0xc0, 0x25, 0x77, 0x98, 0x2, 0x0, 0x6, 0x28, 0x7f, 0x92, 0x7, 0xde, 0x20, 0x4, + 0x0, 0x19, 0x8, 0x5f, 0xf9, 0x6e, 0xa9, 0x72, 0x30, 0x2a, 0x77, 0x5c, 0x5f, 0x79, 0x6d, 0xc3, 0x4d, 0x70, 0xfd, + 0x91, 0xc8, 0xd5, 0xef, 0x5d, 0x71, 0x88, 0x87, 0x22, 0x0, 0x15, 0xae, 0x27, 0x53, 0xd, 0xfb, 0x5c, 0xfc, 0xc0, + 0xfa, 0x80, 0x34, 0x55, 0xb8, 0xa8, 0xc9, 0x73, 0x7f, 0x2, 0x65, 0x31, 0xf0, 0x1e}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0x66, 0xb9, 0x70, 0x5, 0xa2, 0x8b, 0x2d, 0x2e, 0x9e, 0x76, 0x2b, 0x5e, 0x9d, 0x1a}; + lwmqtt_string_t topic_filter_s0 = {14, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xa4, 0xf3, 0x38, 0x80, 0x6c, 0xff, 0x7d, 0xf2, 0x69, 0x34}; + lwmqtt_string_t topic_filter_s1 = {10, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x35, 0xdf, 0x29, 0x27, 0x90, 0xbd, 0xc3, 0xd4, 0x6b, 0x7b, + 0x1d, 0xa5, 0x22, 0x1b, 0x2f, 0x2b, 0x25, 0x6d, 0xaf, 0xa1, + 0xeb, 0x15, 0xdf, 0x8e, 0xcd, 0xe1, 0x24, 0xe0, 0x17, 0xc}; + lwmqtt_string_t topic_filter_s2 = {30, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x76, 0xa7, 0xb8, 0x46, 0xc6, 0x42, 0x5, 0x1b, 0x6, 0x30, 0x17, 0x7b, 0x66, 0x36, + 0xe4, 0x9, 0x61, 0xb9, 0xcf, 0x9a, 0xaf, 0xab, 0xbb, 0x7e, 0xaf, 0x8e, 0x27}; + lwmqtt_string_t topic_filter_s3 = {27, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xcc}; + lwmqtt_string_t topic_filter_s4 = {1, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xda, 0xf6, 0x32, 0x4, 0xa8, 0x24, 0x4, 0x4b, 0xde, 0x5c, 0x53, 0x5b, 0xf3}; + lwmqtt_string_t topic_filter_s5 = {13, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xd4, 0xd8, 0xa5, 0x74, 0x9, 0x70, 0x50, 0x61, 0xa7, 0x95, 0x93, 0xb, + 0x8, 0xe, 0xa3, 0xec, 0xe, 0xde, 0x2a, 0x40, 0x68, 0x9e, 0x26, 0xef}; + lwmqtt_string_t topic_filter_s6 = {24, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xea, 0x6b, 0x70, 0xfc, 0x6b, 0x7a, 0x6b, 0xf, 0xf7, 0xf3, 0x32, 0xac, 0x1d, 0xde, + 0x1b, 0x5d, 0x37, 0xe8, 0xa6, 0xe6, 0x53, 0xae, 0x68, 0xc0, 0x25, 0x77, 0x98}; + lwmqtt_string_t topic_filter_s7 = {27, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x28, 0x7f, 0x92, 0x7, 0xde, 0x20}; + lwmqtt_string_t topic_filter_s8 = {6, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x8, 0x5f, 0xf9, 0x6e, 0xa9, 0x72, 0x30, 0x2a, 0x77, 0x5c, 0x5f, 0x79, 0x6d, + 0xc3, 0x4d, 0x70, 0xfd, 0x91, 0xc8, 0xd5, 0xef, 0x5d, 0x71, 0x88, 0x87}; + lwmqtt_string_t topic_filter_s9 = {25, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0xae, 0x27, 0x53, 0xd, 0xfb, 0x5c, 0xfc, 0xc0, 0xfa, 0x80, 0x34, + 0x55, 0xb8, 0xa8, 0xc9, 0x73, 0x7f, 0x2, 0x65, 0x31, 0xf0}; + lwmqtt_string_t topic_filter_s10 = {21, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + lwmqtt_sub_options_t sub_opts[11]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[0].retain_as_published = false; + sub_opts[0].no_local = true; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[1].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[1].retain_as_published = false; + sub_opts[1].no_local = true; + sub_opts[2].qos = LWMQTT_QOS1; + sub_opts[2].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[2].retain_as_published = true; + sub_opts[2].no_local = true; + sub_opts[3].qos = LWMQTT_QOS0; + sub_opts[3].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[3].retain_as_published = false; + sub_opts[3].no_local = true; + sub_opts[4].qos = LWMQTT_QOS1; + sub_opts[4].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[4].retain_as_published = false; + sub_opts[4].no_local = true; + sub_opts[5].qos = LWMQTT_QOS1; + sub_opts[5].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[5].retain_as_published = false; + sub_opts[5].no_local = false; + sub_opts[6].qos = LWMQTT_QOS2; + sub_opts[6].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[6].retain_as_published = true; + sub_opts[6].no_local = true; + sub_opts[7].qos = LWMQTT_QOS2; + sub_opts[7].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[7].retain_as_published = false; + sub_opts[7].no_local = false; + sub_opts[8].qos = LWMQTT_QOS0; + sub_opts[8].retain_handling = LWMQTT_SUB_SEND_ON_SUB; + sub_opts[8].retain_as_published = false; + sub_opts[8].no_local = true; + sub_opts[9].qos = LWMQTT_QOS2; + sub_opts[9].retain_handling = LWMQTT_SUB_NO_SEND_ON_SUB; + sub_opts[9].retain_as_published = false; + sub_opts[9].no_local = false; + sub_opts[10].qos = LWMQTT_QOS2; + sub_opts[10].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[10].retain_as_published = true; + sub_opts[10].no_local = true; + uint8_t bytesprops0[] = {0x6d, 0x22, 0x21, 0xe6, 0xc, 0xd0, 0x10, 0xbe, 0x43, 0xb6, 0x6f, 0x1d, + 0x5c, 0x97, 0xb6, 0xe, 0x5c, 0x3e, 0x4, 0x95, 0x9e, 0xbb, 0xc8, 0x95}; + uint8_t bytesprops1[] = {0x2b, 0x35, 0x42, 0x7a, 0x18, 0xc7, 0x70, 0xa9, 0xa7, + 0x7d, 0xb3, 0x89, 0x75, 0x38, 0x66, 0x43, 0x7e, 0x65}; + uint8_t bytesprops2[] = {0x5c, 0x8c, 0x1, 0xc6, 0x82, 0xb7}; + uint8_t bytesprops3[] = {0x11, 0xd8, 0xc6, 0xc3}; + uint8_t bytesprops4[] = {0x23, 0xa3, 0xf0, 0x2a, 0x6f, 0xdf, 0xd7, 0x50, 0x3e, + 0x78, 0x2, 0xf, 0xf3, 0x72, 0x12, 0xb5, 0xf9}; + uint8_t bytesprops5[] = {0x9c, 0x89, 0xb6, 0x48, 0xcc, 0x6f, 0xca, 0x4, 0x2f, 0x92, 0xe9, 0x7f, + 0x88, 0x5e, 0xe, 0x89, 0xec, 0x4d, 0xe4, 0x14, 0x6, 0x2e, 0xe9}; + uint8_t bytesprops6[] = {0x2b, 0xe8, 0x87, 0x7b, 0x80, 0xde, 0x20, 0xa3, 0x59, 0x4, 0x99, 0x86, 0xf5, 0xc6, 0xa2, + 0xa7, 0xec, 0x10, 0xf8, 0xd5, 0x4d, 0x3e, 0x83, 0x51, 0xd0, 0x78, 0xcf, 0x77, 0x5c}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)21, .value = {.str = {24, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 3768}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {18, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 24032}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 22317}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {6, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 4777}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {4, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 37}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {17, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 22096}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {23, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {29, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 207}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 7002}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 14743}}, + }; + + lwmqtt_properties_t props = {16, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 22546, 11, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeRequest 790 [("uR,E\184\234\156:\161\&7Eb\249x\ACK\255KB\185\162Iu",SubOptions {_retainHandling = +// SendOnSubscribeNew, _retainAsPublished = True, _noLocal = False, _subQoS = QoS1})] [PropMaximumPacketSize +// 2930,PropReceiveMaximum 24517,PropResponseInformation "dj\219\204LK",PropResponseTopic +// "\245\DEL\246\182y\239\196^\164\249\241J\238\ESC\190\137@`\ESC-\241\CAN\235\198B{",PropAssignedClientIdentifier +// "\205\227\216N\191=\191 X#\ESC\\hA\216\129\DELK8\146{",PropReceiveMaximum 32093,PropReasonString +// "\221\197\DEL\247\193\200\233\182\177\SIU\197Z\240\190K\237%\208\192\217\183u\SYN\147",PropServerReference +// "@\DC1\152\173\DC3\219b\133\ETX\f\189\&3",PropAuthenticationData +// "\SYNr\245\249\178\RSRV+\132J",PropRequestProblemInformation 245,PropCorrelationData +// "\154k\147m\155\228\237\ACK\130\SI?\144\180\165\SO<\192\131\198\&1\134",PropResponseTopic +// "N5\GS\211\DLEQ\a\229D\148\ACK\181\248\184\139e8",PropReceiveMaximum 4356,PropAuthenticationData +// "\189\164\215\US\141\163\153_\SUB&\195\209\153C",PropSubscriptionIdentifier 29,PropTopicAlias +// 4405,PropSessionExpiryInterval 2654,PropPayloadFormatIndicator 153,PropMaximumQoS 155] +TEST(Subscribe5QCTest, Encode30) { + uint8_t pkt[] = { + 0x82, 0xef, 0x1, 0x3, 0x16, 0xd2, 0x1, 0x27, 0x0, 0x0, 0xb, 0x72, 0x21, 0x5f, 0xc5, 0x1a, 0x0, 0x6, 0x64, + 0x6a, 0xdb, 0xcc, 0x4c, 0x4b, 0x8, 0x0, 0x1a, 0xf5, 0x7f, 0xf6, 0xb6, 0x79, 0xef, 0xc4, 0x5e, 0xa4, 0xf9, 0xf1, + 0x4a, 0xee, 0x1b, 0xbe, 0x89, 0x40, 0x60, 0x1b, 0x2d, 0xf1, 0x18, 0xeb, 0xc6, 0x42, 0x7b, 0x12, 0x0, 0x15, 0xcd, + 0xe3, 0xd8, 0x4e, 0xbf, 0x3d, 0xbf, 0x20, 0x58, 0x23, 0x1b, 0x5c, 0x68, 0x41, 0xd8, 0x81, 0x7f, 0x4b, 0x38, 0x92, + 0x7b, 0x21, 0x7d, 0x5d, 0x1f, 0x0, 0x19, 0xdd, 0xc5, 0x7f, 0xf7, 0xc1, 0xc8, 0xe9, 0xb6, 0xb1, 0xf, 0x55, 0xc5, + 0x5a, 0xf0, 0xbe, 0x4b, 0xed, 0x25, 0xd0, 0xc0, 0xd9, 0xb7, 0x75, 0x16, 0x93, 0x1c, 0x0, 0xc, 0x40, 0x11, 0x98, + 0xad, 0x13, 0xdb, 0x62, 0x85, 0x3, 0xc, 0xbd, 0x33, 0x16, 0x0, 0xb, 0x16, 0x72, 0xf5, 0xf9, 0xb2, 0x1e, 0x52, + 0x56, 0x2b, 0x84, 0x4a, 0x17, 0xf5, 0x9, 0x0, 0x15, 0x9a, 0x6b, 0x93, 0x6d, 0x9b, 0xe4, 0xed, 0x6, 0x82, 0xf, + 0x3f, 0x90, 0xb4, 0xa5, 0xe, 0x3c, 0xc0, 0x83, 0xc6, 0x31, 0x86, 0x8, 0x0, 0x11, 0x4e, 0x35, 0x1d, 0xd3, 0x10, + 0x51, 0x7, 0xe5, 0x44, 0x94, 0x6, 0xb5, 0xf8, 0xb8, 0x8b, 0x65, 0x38, 0x21, 0x11, 0x4, 0x16, 0x0, 0xe, 0xbd, + 0xa4, 0xd7, 0x1f, 0x8d, 0xa3, 0x99, 0x5f, 0x1a, 0x26, 0xc3, 0xd1, 0x99, 0x43, 0xb, 0x1d, 0x23, 0x11, 0x35, 0x11, + 0x0, 0x0, 0xa, 0x5e, 0x1, 0x99, 0x24, 0x9b, 0x0, 0x16, 0x75, 0x52, 0x2c, 0x45, 0xb8, 0xea, 0x9c, 0x3a, 0xa1, + 0x37, 0x45, 0x62, 0xf9, 0x78, 0x6, 0xff, 0x4b, 0x42, 0xb9, 0xa2, 0x49, 0x75, 0x19}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x75, 0x52, 0x2c, 0x45, 0xb8, 0xea, 0x9c, 0x3a, 0xa1, 0x37, 0x45, + 0x62, 0xf9, 0x78, 0x6, 0xff, 0x4b, 0x42, 0xb9, 0xa2, 0x49, 0x75}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + lwmqtt_sub_options_t sub_opts[1]; + sub_opts[0].qos = LWMQTT_QOS1; + sub_opts[0].retain_handling = LWMQTT_SUB_SEND_ON_SUB_NEW; + sub_opts[0].retain_as_published = true; + sub_opts[0].no_local = false; + uint8_t bytesprops0[] = {0x64, 0x6a, 0xdb, 0xcc, 0x4c, 0x4b}; + uint8_t bytesprops1[] = {0xf5, 0x7f, 0xf6, 0xb6, 0x79, 0xef, 0xc4, 0x5e, 0xa4, 0xf9, 0xf1, 0x4a, 0xee, + 0x1b, 0xbe, 0x89, 0x40, 0x60, 0x1b, 0x2d, 0xf1, 0x18, 0xeb, 0xc6, 0x42, 0x7b}; + uint8_t bytesprops2[] = {0xcd, 0xe3, 0xd8, 0x4e, 0xbf, 0x3d, 0xbf, 0x20, 0x58, 0x23, 0x1b, + 0x5c, 0x68, 0x41, 0xd8, 0x81, 0x7f, 0x4b, 0x38, 0x92, 0x7b}; + uint8_t bytesprops3[] = {0xdd, 0xc5, 0x7f, 0xf7, 0xc1, 0xc8, 0xe9, 0xb6, 0xb1, 0xf, 0x55, 0xc5, 0x5a, + 0xf0, 0xbe, 0x4b, 0xed, 0x25, 0xd0, 0xc0, 0xd9, 0xb7, 0x75, 0x16, 0x93}; + uint8_t bytesprops4[] = {0x40, 0x11, 0x98, 0xad, 0x13, 0xdb, 0x62, 0x85, 0x3, 0xc, 0xbd, 0x33}; + uint8_t bytesprops5[] = {0x16, 0x72, 0xf5, 0xf9, 0xb2, 0x1e, 0x52, 0x56, 0x2b, 0x84, 0x4a}; + uint8_t bytesprops6[] = {0x9a, 0x6b, 0x93, 0x6d, 0x9b, 0xe4, 0xed, 0x6, 0x82, 0xf, 0x3f, + 0x90, 0xb4, 0xa5, 0xe, 0x3c, 0xc0, 0x83, 0xc6, 0x31, 0x86}; + uint8_t bytesprops7[] = {0x4e, 0x35, 0x1d, 0xd3, 0x10, 0x51, 0x7, 0xe5, 0x44, + 0x94, 0x6, 0xb5, 0xf8, 0xb8, 0x8b, 0x65, 0x38}; + uint8_t bytesprops8[] = {0xbd, 0xa4, 0xd7, 0x1f, 0x8d, 0xa3, 0x99, 0x5f, 0x1a, 0x26, 0xc3, 0xd1, 0x99, 0x43}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 2930}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 24517}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {6, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {26, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {21, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 32093}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {25, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {12, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {11, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 245}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {21, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {17, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 4356}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {14, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 29}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 4405}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 2654}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 153}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 155}}, + }; + + lwmqtt_properties_t props = {19, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = + lwmqtt_encode_subscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 790, 1, topic_filters, sub_opts, props); + + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// SubscribeResponse 30338 [Left SubErrPacketIdentifierInUse,Right QoS0] [] +TEST(SubACK311QCTest, Decode1) { + uint8_t pkt[] = {0x90, 0x4, 0x76, 0x82, 0x91, 0x0}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[2]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 2, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 30338); + EXPECT_EQ(count, 2); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS0); +} + +// SubscribeResponse 12367 [Right QoS0,Left SubErrImplementationSpecificError] [] +TEST(SubACK311QCTest, Decode2) { + uint8_t pkt[] = {0x90, 0x4, 0x30, 0x4f, 0x0, 0x83}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[2]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 2, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 12367); + EXPECT_EQ(count, 2); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[1], 0x80); +} + +// SubscribeResponse 12800 [Right QoS0,Right QoS1,Left SubErrPacketIdentifierInUse,Right QoS0,Left +// SubErrSharedSubscriptionsNotSupported] [] +TEST(SubACK311QCTest, Decode3) { + uint8_t pkt[] = {0x90, 0x7, 0x32, 0x0, 0x0, 0x1, 0x91, 0x0, 0x9e}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[5]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 5, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 12800); + EXPECT_EQ(count, 5); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[4], 0x80); +} + +// SubscribeResponse 28686 [Right QoS2,Left SubErrSubscriptionIdentifiersNotSupported,Left SubErrTopicFilterInvalid,Left +// SubErrWildcardSubscriptionsNotSupported,Left SubErrUnspecifiedError,Right QoS2,Left SubErrTopicFilterInvalid] [] +TEST(SubACK311QCTest, Decode4) { + uint8_t pkt[] = {0x90, 0x9, 0x70, 0xe, 0x2, 0xa1, 0x8f, 0xa2, 0x80, 0x2, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[7]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 7, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 28686); + EXPECT_EQ(count, 7); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], 0x80); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[6], 0x80); +} + +// SubscribeResponse 25029 [Left SubErrUnspecifiedError] [] +TEST(SubACK311QCTest, Decode5) { + uint8_t pkt[] = {0x90, 0x3, 0x61, 0xc5, 0x80}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[1]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 1, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 25029); + EXPECT_EQ(count, 1); + EXPECT_EQ(granted_qos_levels[0], 0x80); +} + +// SubscribeResponse 23005 [Left SubErrSubscriptionIdentifiersNotSupported,Left SubErrTopicFilterInvalid,Right QoS0,Left +// SubErrNotAuthorized,Left SubErrUnspecifiedError,Right QoS1,Left SubErrWildcardSubscriptionsNotSupported,Left +// SubErrNotAuthorized] [] +TEST(SubACK311QCTest, Decode6) { + uint8_t pkt[] = {0x90, 0xa, 0x59, 0xdd, 0xa1, 0x8f, 0x0, 0x87, 0x80, 0x1, 0xa2, 0x87}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[8]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 8, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 23005); + EXPECT_EQ(count, 8); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[3], 0x80); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[6], 0x80); + EXPECT_EQ(granted_qos_levels[7], 0x80); +} + +// SubscribeResponse 31483 [Right QoS2,Right QoS1,Right QoS1,Right QoS2,Left SubErrWildcardSubscriptionsNotSupported] [] +TEST(SubACK311QCTest, Decode7) { + uint8_t pkt[] = {0x90, 0x7, 0x7a, 0xfb, 0x2, 0x1, 0x1, 0x2, 0xa2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[5]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 5, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 31483); + EXPECT_EQ(count, 5); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[4], 0x80); +} + +// SubscribeResponse 14121 [Left SubErrSubscriptionIdentifiersNotSupported,Right QoS2,Right QoS1,Right QoS2] [] +TEST(SubACK311QCTest, Decode8) { + uint8_t pkt[] = {0x90, 0x6, 0x37, 0x29, 0xa1, 0x2, 0x1, 0x2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[4]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 4, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 14121); + EXPECT_EQ(count, 4); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS2); +} + +// SubscribeResponse 16636 [Left SubErrPacketIdentifierInUse] [] +TEST(SubACK311QCTest, Decode9) { + uint8_t pkt[] = {0x90, 0x3, 0x40, 0xfc, 0x91}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[1]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 1, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 16636); + EXPECT_EQ(count, 1); + EXPECT_EQ(granted_qos_levels[0], 0x80); +} + +// SubscribeResponse 19978 [Left SubErrQuotaExceeded,Left SubErrUnspecifiedError,Left SubErrPacketIdentifierInUse,Left +// SubErrSubscriptionIdentifiersNotSupported,Left SubErrWildcardSubscriptionsNotSupported,Right QoS0] [] +TEST(SubACK311QCTest, Decode10) { + uint8_t pkt[] = {0x90, 0x8, 0x4e, 0xa, 0x97, 0x80, 0x91, 0xa1, 0xa2, 0x0}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[6]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 6, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 19978); + EXPECT_EQ(count, 6); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], 0x80); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS0); +} + +// SubscribeResponse 1639 [Right QoS2,Right QoS1,Right QoS2,Left SubErrPacketIdentifierInUse,Right QoS0,Left +// SubErrTopicFilterInvalid] [] +TEST(SubACK311QCTest, Decode11) { + uint8_t pkt[] = {0x90, 0x8, 0x6, 0x67, 0x2, 0x1, 0x2, 0x91, 0x0, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[6]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 6, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 1639); + EXPECT_EQ(count, 6); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], 0x80); + EXPECT_EQ(granted_qos_levels[4], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[5], 0x80); +} + +// SubscribeResponse 22530 [Left SubErrQuotaExceeded,Right QoS1,Right QoS1] [] +TEST(SubACK311QCTest, Decode12) { + uint8_t pkt[] = {0x90, 0x5, 0x58, 0x2, 0x97, 0x1, 0x1}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[3]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 3, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 22530); + EXPECT_EQ(count, 3); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS1); +} + +// SubscribeResponse 27526 [Left SubErrSharedSubscriptionsNotSupported,Right QoS2,Left SubErrUnspecifiedError] [] +TEST(SubACK311QCTest, Decode13) { + uint8_t pkt[] = {0x90, 0x5, 0x6b, 0x86, 0x9e, 0x2, 0x80}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[3]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 3, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 27526); + EXPECT_EQ(count, 3); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[2], 0x80); +} + +// SubscribeResponse 31498 [Left SubErrSharedSubscriptionsNotSupported,Left SubErrPacketIdentifierInUse,Left +// SubErrSharedSubscriptionsNotSupported,Left SubErrTopicFilterInvalid] [] +TEST(SubACK311QCTest, Decode14) { + uint8_t pkt[] = {0x90, 0x6, 0x7b, 0xa, 0x9e, 0x91, 0x9e, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[4]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 4, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 31498); + EXPECT_EQ(count, 4); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], 0x80); +} + +// SubscribeResponse 3933 [Left SubErrImplementationSpecificError,Right QoS2] [] +TEST(SubACK311QCTest, Decode15) { + uint8_t pkt[] = {0x90, 0x4, 0xf, 0x5d, 0x83, 0x2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[2]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 2, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 3933); + EXPECT_EQ(count, 2); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); +} + +// SubscribeResponse 30590 [Left SubErrSubscriptionIdentifiersNotSupported,Right QoS2,Left SubErrQuotaExceeded,Right +// QoS0,Left SubErrUnspecifiedError,Left SubErrPacketIdentifierInUse,Left SubErrQuotaExceeded,Right QoS1,Right QoS2] [] +TEST(SubACK311QCTest, Decode16) { + uint8_t pkt[] = {0x90, 0xb, 0x77, 0x7e, 0xa1, 0x2, 0x97, 0x0, 0x80, 0x91, 0x97, 0x1, 0x2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[9]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 9, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 30590); + EXPECT_EQ(count, 9); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], 0x80); + EXPECT_EQ(granted_qos_levels[6], 0x80); + EXPECT_EQ(granted_qos_levels[7], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[8], LWMQTT_QOS2); +} + +// SubscribeResponse 28125 [Left SubErrUnspecifiedError,Left SubErrUnspecifiedError,Right QoS2] [] +TEST(SubACK311QCTest, Decode17) { + uint8_t pkt[] = {0x90, 0x5, 0x6d, 0xdd, 0x80, 0x80, 0x2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[3]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 3, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 28125); + EXPECT_EQ(count, 3); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); +} + +// SubscribeResponse 3160 [Right QoS1,Right QoS0,Left SubErrUnspecifiedError,Left SubErrUnspecifiedError,Right QoS1,Left +// SubErrSharedSubscriptionsNotSupported,Left SubErrUnspecifiedError,Right QoS0,Right QoS0] [] +TEST(SubACK311QCTest, Decode18) { + uint8_t pkt[] = {0x90, 0xb, 0xc, 0x58, 0x1, 0x0, 0x80, 0x80, 0x1, 0x9e, 0x80, 0x0, 0x0}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[9]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 9, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 3160); + EXPECT_EQ(count, 9); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], 0x80); + EXPECT_EQ(granted_qos_levels[4], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[5], 0x80); + EXPECT_EQ(granted_qos_levels[6], 0x80); + EXPECT_EQ(granted_qos_levels[7], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[8], LWMQTT_QOS0); +} + +// SubscribeResponse 13503 [Right QoS1,Left SubErrSubscriptionIdentifiersNotSupported,Right QoS0,Left +// SubErrSubscriptionIdentifiersNotSupported,Right QoS2,Right QoS1,Left SubErrUnspecifiedError,Left +// SubErrImplementationSpecificError,Left SubErrPacketIdentifierInUse] [] +TEST(SubACK311QCTest, Decode19) { + uint8_t pkt[] = {0x90, 0xb, 0x34, 0xbf, 0x1, 0xa1, 0x0, 0xa1, 0x2, 0x1, 0x80, 0x83, 0x91}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[9]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 9, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 13503); + EXPECT_EQ(count, 9); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[3], 0x80); + EXPECT_EQ(granted_qos_levels[4], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[6], 0x80); + EXPECT_EQ(granted_qos_levels[7], 0x80); + EXPECT_EQ(granted_qos_levels[8], 0x80); +} + +// SubscribeResponse 8170 [Left SubErrSharedSubscriptionsNotSupported,Right QoS1,Left SubErrNotAuthorized,Left +// SubErrImplementationSpecificError,Left SubErrSubscriptionIdentifiersNotSupported,Left SubErrUnspecifiedError] [] +TEST(SubACK311QCTest, Decode20) { + uint8_t pkt[] = {0x90, 0x8, 0x1f, 0xea, 0x9e, 0x1, 0x87, 0x83, 0xa1, 0x80}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[6]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 6, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 8170); + EXPECT_EQ(count, 6); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], 0x80); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], 0x80); +} + +// SubscribeResponse 3809 [Left SubErrQuotaExceeded,Left SubErrImplementationSpecificError,Right QoS2,Right QoS1,Right +// QoS2] [] +TEST(SubACK311QCTest, Decode21) { + uint8_t pkt[] = {0x90, 0x7, 0xe, 0xe1, 0x97, 0x83, 0x2, 0x1, 0x2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[5]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 5, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 3809); + EXPECT_EQ(count, 5); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[4], LWMQTT_QOS2); +} + +// SubscribeResponse 6533 [Left SubErrPacketIdentifierInUse,Right QoS2,Left SubErrNotAuthorized,Right QoS0,Left +// SubErrSharedSubscriptionsNotSupported] [] +TEST(SubACK311QCTest, Decode22) { + uint8_t pkt[] = {0x90, 0x7, 0x19, 0x85, 0x91, 0x2, 0x87, 0x0, 0x9e}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[5]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 5, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 6533); + EXPECT_EQ(count, 5); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[4], 0x80); +} + +// SubscribeResponse 28202 [Right QoS1,Left SubErrQuotaExceeded,Left SubErrSharedSubscriptionsNotSupported,Right +// QoS2,Left SubErrUnspecifiedError,Left SubErrSubscriptionIdentifiersNotSupported,Right QoS1,Right QoS0,Right QoS1,Left +// SubErrSharedSubscriptionsNotSupported,Right QoS0] [] +TEST(SubACK311QCTest, Decode23) { + uint8_t pkt[] = {0x90, 0xd, 0x6e, 0x2a, 0x1, 0x97, 0x9e, 0x2, 0x80, 0xa1, 0x1, 0x0, 0x1, 0x9e, 0x0}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[11]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 11, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 28202); + EXPECT_EQ(count, 11); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], 0x80); + EXPECT_EQ(granted_qos_levels[6], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[7], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[8], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[9], 0x80); + EXPECT_EQ(granted_qos_levels[10], LWMQTT_QOS0); +} + +// SubscribeResponse 10740 [Left SubErrSharedSubscriptionsNotSupported,Right QoS2,Right QoS2,Left +// SubErrSharedSubscriptionsNotSupported] [] +TEST(SubACK311QCTest, Decode24) { + uint8_t pkt[] = {0x90, 0x6, 0x29, 0xf4, 0x9e, 0x2, 0x2, 0x9e}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[4]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 4, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 10740); + EXPECT_EQ(count, 4); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], 0x80); +} + +// SubscribeResponse 18996 [Left SubErrPacketIdentifierInUse,Left SubErrImplementationSpecificError,Right QoS0,Right +// QoS0,Left SubErrTopicFilterInvalid,Right QoS1,Left SubErrTopicFilterInvalid,Left +// SubErrWildcardSubscriptionsNotSupported,Left SubErrPacketIdentifierInUse,Right QoS2,Left +// SubErrSubscriptionIdentifiersNotSupported] [] +TEST(SubACK311QCTest, Decode25) { + uint8_t pkt[] = {0x90, 0xd, 0x4a, 0x34, 0x91, 0x83, 0x0, 0x0, 0x8f, 0x1, 0x8f, 0xa2, 0x91, 0x2, 0xa1}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[11]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 11, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 18996); + EXPECT_EQ(count, 11); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[6], 0x80); + EXPECT_EQ(granted_qos_levels[7], 0x80); + EXPECT_EQ(granted_qos_levels[8], 0x80); + EXPECT_EQ(granted_qos_levels[9], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[10], 0x80); +} + +// SubscribeResponse 969 [Left SubErrWildcardSubscriptionsNotSupported,Left SubErrNotAuthorized,Right QoS2,Right +// QoS0,Right QoS2,Left SubErrPacketIdentifierInUse,Right QoS1,Right QoS0,Right QoS2,Left SubErrNotAuthorized,Left +// SubErrWildcardSubscriptionsNotSupported] [] +TEST(SubACK311QCTest, Decode26) { + uint8_t pkt[] = {0x90, 0xd, 0x3, 0xc9, 0xa2, 0x87, 0x2, 0x0, 0x2, 0x91, 0x1, 0x0, 0x2, 0x87, 0xa2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[11]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 11, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 969); + EXPECT_EQ(count, 11); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[4], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[5], 0x80); + EXPECT_EQ(granted_qos_levels[6], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[7], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[8], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[9], 0x80); + EXPECT_EQ(granted_qos_levels[10], 0x80); +} + +// SubscribeResponse 27073 [Left SubErrSubscriptionIdentifiersNotSupported,Left SubErrTopicFilterInvalid,Right +// QoS1,Right QoS2,Left SubErrTopicFilterInvalid,Left SubErrWildcardSubscriptionsNotSupported] [] +TEST(SubACK311QCTest, Decode27) { + uint8_t pkt[] = {0x90, 0x8, 0x69, 0xc1, 0xa1, 0x8f, 0x1, 0x2, 0x8f, 0xa2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[6]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 6, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 27073); + EXPECT_EQ(count, 6); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], 0x80); +} + +// SubscribeResponse 9700 [Right QoS1,Left SubErrSubscriptionIdentifiersNotSupported,Left SubErrUnspecifiedError,Left +// SubErrWildcardSubscriptionsNotSupported,Right QoS2,Right QoS0,Left SubErrSubscriptionIdentifiersNotSupported] [] +TEST(SubACK311QCTest, Decode28) { + uint8_t pkt[] = {0x90, 0x9, 0x25, 0xe4, 0x1, 0xa1, 0x80, 0xa2, 0x2, 0x0, 0xa1}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[7]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 7, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 9700); + EXPECT_EQ(count, 7); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], 0x80); + EXPECT_EQ(granted_qos_levels[4], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[6], 0x80); +} + +// SubscribeResponse 31732 [Left SubErrNotAuthorized,Left SubErrImplementationSpecificError,Right QoS2,Right QoS1,Left +// SubErrImplementationSpecificError,Left SubErrQuotaExceeded,Left SubErrSubscriptionIdentifiersNotSupported,Left +// SubErrUnspecifiedError] [] +TEST(SubACK311QCTest, Decode29) { + uint8_t pkt[] = {0x90, 0xa, 0x7b, 0xf4, 0x87, 0x83, 0x2, 0x1, 0x83, 0x97, 0xa1, 0x80}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[8]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 8, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 31732); + EXPECT_EQ(count, 8); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], 0x80); + EXPECT_EQ(granted_qos_levels[6], 0x80); + EXPECT_EQ(granted_qos_levels[7], 0x80); +} + +// SubscribeResponse 6520 [Right QoS2,Left SubErrUnspecifiedError,Right QoS2,Left SubErrQuotaExceeded] [] +TEST(SubACK311QCTest, Decode30) { + uint8_t pkt[] = {0x90, 0x6, 0x19, 0x78, 0x2, 0x80, 0x2, 0x97}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[4]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT311, 4, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 6520); + EXPECT_EQ(count, 4); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], 0x80); +} + +// SubscribeResponse 30338 [Left SubErrPacketIdentifierInUse,Right QoS0] [PropSubscriptionIdentifier +// 32,PropRetainAvailable 149,PropPayloadFormatIndicator 233,PropPayloadFormatIndicator +// 54,PropSharedSubscriptionAvailable 133,PropServerKeepAlive 19945,PropSubscriptionIdentifierAvailable +// 66,PropMaximumPacketSize 2010,PropWildcardSubscriptionAvailable 232,PropSubscriptionIdentifier 6,PropMaximumQoS +// 157,PropCorrelationData "z",PropResponseTopic "\197\EOTKr\135\195\177\145\241\156\253\133\vs",PropTopicAlias 19346] +TEST(SubACK5QCTest, Decode1) { + uint8_t pkt[] = {0x90, 0x37, 0x76, 0x82, 0x32, 0xb, 0x20, 0x25, 0x95, 0x1, 0xe9, 0x1, 0x36, 0x2a, 0x85, + 0x13, 0x4d, 0xe9, 0x29, 0x42, 0x27, 0x0, 0x0, 0x7, 0xda, 0x28, 0xe8, 0xb, 0x6, 0x24, + 0x9d, 0x9, 0x0, 0x1, 0x7a, 0x8, 0x0, 0xe, 0xc5, 0x4, 0x4b, 0x72, 0x87, 0xc3, 0xb1, + 0x91, 0xf1, 0x9c, 0xfd, 0x85, 0xb, 0x73, 0x23, 0x4b, 0x92, 0x91, 0x0}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[2]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 2, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 30338); + EXPECT_EQ(count, 2); + EXPECT_EQ(granted_qos_levels[0], 0x91); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS0); +} + +// SubscribeResponse 12367 [Right QoS0,Left SubErrImplementationSpecificError] [PropReasonString +// "\191\251",PropMessageExpiryInterval 3754,PropPayloadFormatIndicator 23,PropRequestProblemInformation +// 157,PropCorrelationData "\SUB\170\177O]\n\240\170\225\169P\206%\ACK\174\165\GS\145\226\214\232",PropReceiveMaximum +// 2658,PropTopicAlias 23916,PropSubscriptionIdentifier 31,PropRequestResponseInformation 29,PropAuthenticationData +// "il\SO\163\177c\FSm\US_\132",PropCorrelationData +// "P\193\174\DLEo\150\169%=\151\176\132\220\163\189u|\252\197\130\162\f\170/\tz\190R",PropMessageExpiryInterval +// 25397,PropWillDelayInterval 1033,PropSubscriptionIdentifierAvailable 147,PropUserProperty "<\SI\249\132]\226" +// "\149X8\252Y\FS\RS\166\&3\DC4s?\DC1\FS\EOT\142\212\145\142\191\STXs\207\184\217\162\251\&8",PropMessageExpiryInterval +// 27329] +TEST(SubACK5QCTest, Decode2) { + uint8_t pkt[] = {0x90, 0x9b, 0x1, 0x30, 0x4f, 0x95, 0x1, 0x1f, 0x0, 0x2, 0xbf, 0xfb, 0x2, 0x0, 0x0, 0xe, + 0xaa, 0x1, 0x17, 0x17, 0x9d, 0x9, 0x0, 0x15, 0x1a, 0xaa, 0xb1, 0x4f, 0x5d, 0xa, 0xf0, 0xaa, + 0xe1, 0xa9, 0x50, 0xce, 0x25, 0x6, 0xae, 0xa5, 0x1d, 0x91, 0xe2, 0xd6, 0xe8, 0x21, 0xa, 0x62, + 0x23, 0x5d, 0x6c, 0xb, 0x1f, 0x19, 0x1d, 0x16, 0x0, 0xb, 0x69, 0x6c, 0xe, 0xa3, 0xb1, 0x63, + 0x1c, 0x6d, 0x1f, 0x5f, 0x84, 0x9, 0x0, 0x1c, 0x50, 0xc1, 0xae, 0x10, 0x6f, 0x96, 0xa9, 0x25, + 0x3d, 0x97, 0xb0, 0x84, 0xdc, 0xa3, 0xbd, 0x75, 0x7c, 0xfc, 0xc5, 0x82, 0xa2, 0xc, 0xaa, 0x2f, + 0x9, 0x7a, 0xbe, 0x52, 0x2, 0x0, 0x0, 0x63, 0x35, 0x18, 0x0, 0x0, 0x4, 0x9, 0x29, 0x93, + 0x26, 0x0, 0x6, 0x3c, 0xf, 0xf9, 0x84, 0x5d, 0xe2, 0x0, 0x1c, 0x95, 0x58, 0x38, 0xfc, 0x59, + 0x1c, 0x1e, 0xa6, 0x33, 0x14, 0x73, 0x3f, 0x11, 0x1c, 0x4, 0x8e, 0xd4, 0x91, 0x8e, 0xbf, 0x2, + 0x73, 0xcf, 0xb8, 0xd9, 0xa2, 0xfb, 0x38, 0x2, 0x0, 0x0, 0x6a, 0xc1, 0x0, 0x83}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[2]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 2, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 12367); + EXPECT_EQ(count, 2); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[1], 0x83); +} + +// SubscribeResponse 12800 [Right QoS0,Right QoS1,Left SubErrPacketIdentifierInUse,Right QoS0,Left +// SubErrSharedSubscriptionsNotSupported] [PropRetainAvailable 56,PropUserProperty "Y\226H\232" +// "n\185:N+*\GS\179\171\142\173>\182\191",PropSharedSubscriptionAvailable 203,PropCorrelationData +// "j\GS\SO\155FA_\220\166\242\180\195\171\148\SUB\136\223\244\247\248\128yo\ETXG\146\RS\145\225",PropWildcardSubscriptionAvailable +// 56,PropSessionExpiryInterval 2749,PropAuthenticationData +// "\n\236rn\180\204)(\156_%\DC4g\219d\EOT>n\170",PropMessageExpiryInterval 2583,PropAssignedClientIdentifier +// "x\n",PropSubscriptionIdentifierAvailable 5,PropContentType +// "9E\SUBB\233M\ETB!\ETX\177c|b\CAN\180Y=\166",PropMaximumPacketSize 20424,PropUserProperty +// "\145\&5\216\161G\DEL[1{\139\192\134Z%\142\t/\128:%Q-\"\145\n\178\180\197" +// "\140\177\203\&6]\f\215\136\215!f,lZ\245",PropRetainAvailable 173,PropMessageExpiryInterval +// 3930,PropRequestProblemInformation 231,PropMessageExpiryInterval 31026] +TEST(SubACK5QCTest, Decode3) { + uint8_t pkt[] = {0x90, 0xc5, 0x1, 0x32, 0x0, 0xbc, 0x1, 0x25, 0x38, 0x26, 0x0, 0x4, 0x59, 0xe2, 0x48, 0xe8, 0x0, + 0xe, 0x6e, 0xb9, 0x3a, 0x4e, 0x2b, 0x2a, 0x1d, 0xb3, 0xab, 0x8e, 0xad, 0x3e, 0xb6, 0xbf, 0x2a, 0xcb, + 0x9, 0x0, 0x1d, 0x6a, 0x1d, 0xe, 0x9b, 0x46, 0x41, 0x5f, 0xdc, 0xa6, 0xf2, 0xb4, 0xc3, 0xab, 0x94, + 0x1a, 0x88, 0xdf, 0xf4, 0xf7, 0xf8, 0x80, 0x79, 0x6f, 0x3, 0x47, 0x92, 0x1e, 0x91, 0xe1, 0x28, 0x38, + 0x11, 0x0, 0x0, 0xa, 0xbd, 0x16, 0x0, 0x13, 0xa, 0xec, 0x72, 0x6e, 0xb4, 0xcc, 0x29, 0x28, 0x9c, + 0x5f, 0x25, 0x14, 0x67, 0xdb, 0x64, 0x4, 0x3e, 0x6e, 0xaa, 0x2, 0x0, 0x0, 0xa, 0x17, 0x12, 0x0, + 0x2, 0x78, 0xa, 0x29, 0x5, 0x3, 0x0, 0x12, 0x39, 0x45, 0x1a, 0x42, 0xe9, 0x4d, 0x17, 0x21, 0x3, + 0xb1, 0x63, 0x7c, 0x62, 0x18, 0xb4, 0x59, 0x3d, 0xa6, 0x27, 0x0, 0x0, 0x4f, 0xc8, 0x26, 0x0, 0x1c, + 0x91, 0x35, 0xd8, 0xa1, 0x47, 0x7f, 0x5b, 0x31, 0x7b, 0x8b, 0xc0, 0x86, 0x5a, 0x25, 0x8e, 0x9, 0x2f, + 0x80, 0x3a, 0x25, 0x51, 0x2d, 0x22, 0x91, 0xa, 0xb2, 0xb4, 0xc5, 0x0, 0xf, 0x8c, 0xb1, 0xcb, 0x36, + 0x5d, 0xc, 0xd7, 0x88, 0xd7, 0x21, 0x66, 0x2c, 0x6c, 0x5a, 0xf5, 0x25, 0xad, 0x2, 0x0, 0x0, 0xf, + 0x5a, 0x17, 0xe7, 0x2, 0x0, 0x0, 0x79, 0x32, 0x0, 0x1, 0x91, 0x0, 0x9e}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[5]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 5, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 12800); + EXPECT_EQ(count, 5); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[2], 0x91); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[4], 0x9E); +} + +// SubscribeResponse 28686 [Right QoS2,Left SubErrSubscriptionIdentifiersNotSupported,Left SubErrTopicFilterInvalid,Left +// SubErrWildcardSubscriptionsNotSupported,Left SubErrUnspecifiedError,Right QoS2,Left SubErrTopicFilterInvalid] +// [PropRequestProblemInformation 27,PropServerReference +// "K\161I\135\DLE\162L\169\152I\248\136\191C\233\187\175\ETBU\f\252Qq\CANh\220",PropTopicAliasMaximum +// 12806,PropServerReference "\150\175",PropSessionExpiryInterval 28982,PropRequestResponseInformation +// 5,PropWillDelayInterval 24027,PropRequestResponseInformation 97,PropCorrelationData +// "\ENQ\190\164\195t\184\135\DC2b\183\147",PropReceiveMaximum 5262,PropRequestResponseInformation +// 31,PropWildcardSubscriptionAvailable 84,PropMessageExpiryInterval 10552,PropSubscriptionIdentifier +// 23,PropMaximumPacketSize 1343,PropRequestProblemInformation 197,PropResponseInformation +// "\230\141\DC4%\221\138\129%\147\214'\f\241\157\214\&8\NUL\DC3",PropServerKeepAlive 17321,PropReceiveMaximum +// 19601,PropServerKeepAlive 26403,PropWildcardSubscriptionAvailable 30] +TEST(SubACK5QCTest, Decode4) { + uint8_t pkt[] = {0x90, 0x82, 0x1, 0x70, 0xe, 0x78, 0x17, 0x1b, 0x1c, 0x0, 0x1a, 0x4b, 0xa1, 0x49, 0x87, 0x10, 0xa2, + 0x4c, 0xa9, 0x98, 0x49, 0xf8, 0x88, 0xbf, 0x43, 0xe9, 0xbb, 0xaf, 0x17, 0x55, 0xc, 0xfc, 0x51, 0x71, + 0x18, 0x68, 0xdc, 0x22, 0x32, 0x6, 0x1c, 0x0, 0x2, 0x96, 0xaf, 0x11, 0x0, 0x0, 0x71, 0x36, 0x19, + 0x5, 0x18, 0x0, 0x0, 0x5d, 0xdb, 0x19, 0x61, 0x9, 0x0, 0xb, 0x5, 0xbe, 0xa4, 0xc3, 0x74, 0xb8, + 0x87, 0x12, 0x62, 0xb7, 0x93, 0x21, 0x14, 0x8e, 0x19, 0x1f, 0x28, 0x54, 0x2, 0x0, 0x0, 0x29, 0x38, + 0xb, 0x17, 0x27, 0x0, 0x0, 0x5, 0x3f, 0x17, 0xc5, 0x1a, 0x0, 0x12, 0xe6, 0x8d, 0x14, 0x25, 0xdd, + 0x8a, 0x81, 0x25, 0x93, 0xd6, 0x27, 0xc, 0xf1, 0x9d, 0xd6, 0x38, 0x0, 0x13, 0x13, 0x43, 0xa9, 0x21, + 0x4c, 0x91, 0x13, 0x67, 0x23, 0x28, 0x1e, 0x2, 0xa1, 0x8f, 0xa2, 0x80, 0x2, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[7]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 7, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 28686); + EXPECT_EQ(count, 7); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[1], 0xA1); + EXPECT_EQ(granted_qos_levels[2], 0x8F); + EXPECT_EQ(granted_qos_levels[3], 0xA2); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[6], 0x8F); +} + +// SubscribeResponse 25029 [Left SubErrUnspecifiedError] [PropMaximumQoS 150,PropReasonString +// "~\154\146\214qs\165\DC32mKY\EOT\237\148",PropServerKeepAlive 4819,PropServerKeepAlive 30336,PropRetainAvailable +// 197,PropWillDelayInterval 1016] +TEST(SubACK5QCTest, Decode5) { + uint8_t pkt[] = {0x90, 0x25, 0x61, 0xc5, 0x21, 0x24, 0x96, 0x1f, 0x0, 0xf, 0x7e, 0x9a, 0x92, + 0xd6, 0x71, 0x73, 0xa5, 0x13, 0x32, 0x6d, 0x4b, 0x59, 0x4, 0xed, 0x94, 0x13, + 0x12, 0xd3, 0x13, 0x76, 0x80, 0x25, 0xc5, 0x18, 0x0, 0x0, 0x3, 0xf8, 0x80}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[1]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 1, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 25029); + EXPECT_EQ(count, 1); + EXPECT_EQ(granted_qos_levels[0], 0x80); +} + +// SubscribeResponse 23005 [Left SubErrSubscriptionIdentifiersNotSupported,Left SubErrTopicFilterInvalid,Right QoS0,Left +// SubErrNotAuthorized,Left SubErrUnspecifiedError,Right QoS1,Left SubErrWildcardSubscriptionsNotSupported,Left +// SubErrNotAuthorized] [] +TEST(SubACK5QCTest, Decode6) { + uint8_t pkt[] = {0x90, 0xb, 0x59, 0xdd, 0x0, 0xa1, 0x8f, 0x0, 0x87, 0x80, 0x1, 0xa2, 0x87}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[8]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 8, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 23005); + EXPECT_EQ(count, 8); + EXPECT_EQ(granted_qos_levels[0], 0xA1); + EXPECT_EQ(granted_qos_levels[1], 0x8F); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[3], 0x87); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[6], 0xA2); + EXPECT_EQ(granted_qos_levels[7], 0x87); +} + +// SubscribeResponse 31483 [Right QoS2,Right QoS1,Right QoS1,Right QoS2,Left SubErrWildcardSubscriptionsNotSupported] +// [PropResponseTopic +// "`\222S@\a\SUB+\168\GSPk\248\ETB\ETB\142H\r\138f\205\164\139\SUB\184\158",PropSharedSubscriptionAvailable +// 1,PropReceiveMaximum 6861,PropTopicAlias 28149,PropMessageExpiryInterval 28231,PropRequestResponseInformation +// 51,PropTopicAlias 7811,PropPayloadFormatIndicator 135,PropAuthenticationMethod +// "[\DC2\163\238\216N\151`\DC2\187\ETX\148^\241\154\&1",PropAuthenticationMethod +// "t\151\174\182L\NUL\238\223\171\164\NUL\SUB\173?\ENQU\160R",PropReasonString +// "Fc\255\221\135\155N3zA_TH6\253K",PropAuthenticationData "\215\EM\176?\245\131",PropSubscriptionIdentifier +// 2,PropUserProperty "\STX\154\237\245S" +// "\"\129\n\163\140\NUL\219\199\NAK\162]kJm<\227\DC3",PropSubscriptionIdentifierAvailable 38,PropMaximumQoS +// 159,PropMessageExpiryInterval 14026,PropRequestProblemInformation 132,PropWillDelayInterval +// 16214,PropRequestResponseInformation 58,PropSubscriptionIdentifierAvailable 54,PropSessionExpiryInterval +// 24579,PropMaximumQoS 170,PropMessageExpiryInterval 27088,PropAuthenticationMethod +// "<\206h\185\223M\250\177",PropUserProperty ")\185\228]W\186\DC2\143" "\146b\255",PropTopicAliasMaximum +// 26682,PropServerReference "g",PropSessionExpiryInterval 10950,PropRequestProblemInformation 122] +TEST(SubACK5QCTest, Decode7) { + uint8_t pkt[] = {0x90, 0xe3, 0x1, 0x7a, 0xfb, 0xda, 0x1, 0x8, 0x0, 0x19, 0x60, 0xde, 0x53, 0x40, 0x7, 0x1a, 0x2b, + 0xa8, 0x1d, 0x50, 0x6b, 0xf8, 0x17, 0x17, 0x8e, 0x48, 0xd, 0x8a, 0x66, 0xcd, 0xa4, 0x8b, 0x1a, 0xb8, + 0x9e, 0x2a, 0x1, 0x21, 0x1a, 0xcd, 0x23, 0x6d, 0xf5, 0x2, 0x0, 0x0, 0x6e, 0x47, 0x19, 0x33, 0x23, + 0x1e, 0x83, 0x1, 0x87, 0x15, 0x0, 0x10, 0x5b, 0x12, 0xa3, 0xee, 0xd8, 0x4e, 0x97, 0x60, 0x12, 0xbb, + 0x3, 0x94, 0x5e, 0xf1, 0x9a, 0x31, 0x15, 0x0, 0x12, 0x74, 0x97, 0xae, 0xb6, 0x4c, 0x0, 0xee, 0xdf, + 0xab, 0xa4, 0x0, 0x1a, 0xad, 0x3f, 0x5, 0x55, 0xa0, 0x52, 0x1f, 0x0, 0x10, 0x46, 0x63, 0xff, 0xdd, + 0x87, 0x9b, 0x4e, 0x33, 0x7a, 0x41, 0x5f, 0x54, 0x48, 0x36, 0xfd, 0x4b, 0x16, 0x0, 0x6, 0xd7, 0x19, + 0xb0, 0x3f, 0xf5, 0x83, 0xb, 0x2, 0x26, 0x0, 0x5, 0x2, 0x9a, 0xed, 0xf5, 0x53, 0x0, 0x11, 0x22, + 0x81, 0xa, 0xa3, 0x8c, 0x0, 0xdb, 0xc7, 0x15, 0xa2, 0x5d, 0x6b, 0x4a, 0x6d, 0x3c, 0xe3, 0x13, 0x29, + 0x26, 0x24, 0x9f, 0x2, 0x0, 0x0, 0x36, 0xca, 0x17, 0x84, 0x18, 0x0, 0x0, 0x3f, 0x56, 0x19, 0x3a, + 0x29, 0x36, 0x11, 0x0, 0x0, 0x60, 0x3, 0x24, 0xaa, 0x2, 0x0, 0x0, 0x69, 0xd0, 0x15, 0x0, 0x8, + 0x3c, 0xce, 0x68, 0xb9, 0xdf, 0x4d, 0xfa, 0xb1, 0x26, 0x0, 0x8, 0x29, 0xb9, 0xe4, 0x5d, 0x57, 0xba, + 0x12, 0x8f, 0x0, 0x3, 0x92, 0x62, 0xff, 0x22, 0x68, 0x3a, 0x1c, 0x0, 0x1, 0x67, 0x11, 0x0, 0x0, + 0x2a, 0xc6, 0x17, 0x7a, 0x2, 0x1, 0x1, 0x2, 0xa2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[5]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 5, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 31483); + EXPECT_EQ(count, 5); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[4], 0xA2); +} + +// SubscribeResponse 14121 [Left SubErrSubscriptionIdentifiersNotSupported,Right QoS2,Right QoS1,Right QoS2] +// [PropSessionExpiryInterval 5752,PropResponseTopic "#\216\DEL\241*\DC2\191\&1\229\247\161\EMk\EM",PropContentType +// "\202W\187\191Py`\DC2r\196\209]\240",PropResponseTopic +// "VL\ETB\189\GS`C2\NULY@\DC1\180$\140T\216>7\156\128\221",PropContentType +// "f\220\212p\183\&4\253\141\159\DC2\172\247\232\SYN\r\162\202\211\221\129\142\190\243>",PropTopicAlias +// 24590,PropRetainAvailable 106,PropWildcardSubscriptionAvailable 93,PropWillDelayInterval +// 30960,PropSessionExpiryInterval 2915,PropAuthenticationMethod +// "A\233\252E<\ETBB\207\158AI4\180\210\197\237\140\&2Z}\SOH*s\GS\158e\255\163QI",PropContentType +// "^\200\173\197R\b%\175;\129\190\169\197\ENQ\217\&7\213\SUBZ\158\"\140o\200\240\154\ETXs5",PropSessionExpiryInterval +// 8029,PropServerKeepAlive 6177,PropMessageExpiryInterval 5207,PropSharedSubscriptionAvailable +// 229,PropRequestProblemInformation 236,PropSessionExpiryInterval 14826,PropMessageExpiryInterval 32030] +TEST(SubACK5QCTest, Decode8) { + uint8_t pkt[] = {0x90, 0xcf, 0x1, 0x37, 0x29, 0xc7, 0x1, 0x11, 0x0, 0x0, 0x16, 0x78, 0x8, 0x0, 0xe, 0x23, 0xd8, + 0x7f, 0xf1, 0x2a, 0x12, 0xbf, 0x31, 0xe5, 0xf7, 0xa1, 0x19, 0x6b, 0x19, 0x3, 0x0, 0xd, 0xca, 0x57, + 0xbb, 0xbf, 0x50, 0x79, 0x60, 0x12, 0x72, 0xc4, 0xd1, 0x5d, 0xf0, 0x8, 0x0, 0x16, 0x56, 0x4c, 0x17, + 0xbd, 0x1d, 0x60, 0x43, 0x32, 0x0, 0x59, 0x40, 0x11, 0xb4, 0x24, 0x8c, 0x54, 0xd8, 0x3e, 0x37, 0x9c, + 0x80, 0xdd, 0x3, 0x0, 0x18, 0x66, 0xdc, 0xd4, 0x70, 0xb7, 0x34, 0xfd, 0x8d, 0x9f, 0x12, 0xac, 0xf7, + 0xe8, 0x16, 0xd, 0xa2, 0xca, 0xd3, 0xdd, 0x81, 0x8e, 0xbe, 0xf3, 0x3e, 0x23, 0x60, 0xe, 0x25, 0x6a, + 0x28, 0x5d, 0x18, 0x0, 0x0, 0x78, 0xf0, 0x11, 0x0, 0x0, 0xb, 0x63, 0x15, 0x0, 0x1e, 0x41, 0xe9, + 0xfc, 0x45, 0x3c, 0x17, 0x42, 0xcf, 0x9e, 0x41, 0x49, 0x34, 0xb4, 0xd2, 0xc5, 0xed, 0x8c, 0x32, 0x5a, + 0x7d, 0x1, 0x2a, 0x73, 0x1d, 0x9e, 0x65, 0xff, 0xa3, 0x51, 0x49, 0x3, 0x0, 0x1d, 0x5e, 0xc8, 0xad, + 0xc5, 0x52, 0x8, 0x25, 0xaf, 0x3b, 0x81, 0xbe, 0xa9, 0xc5, 0x5, 0xd9, 0x37, 0xd5, 0x1a, 0x5a, 0x9e, + 0x22, 0x8c, 0x6f, 0xc8, 0xf0, 0x9a, 0x3, 0x73, 0x35, 0x11, 0x0, 0x0, 0x1f, 0x5d, 0x13, 0x18, 0x21, + 0x2, 0x0, 0x0, 0x14, 0x57, 0x2a, 0xe5, 0x17, 0xec, 0x11, 0x0, 0x0, 0x39, 0xea, 0x2, 0x0, 0x0, + 0x7d, 0x1e, 0xa1, 0x2, 0x1, 0x2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[4]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 4, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 14121); + EXPECT_EQ(count, 4); + EXPECT_EQ(granted_qos_levels[0], 0xA1); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS2); +} + +// SubscribeResponse 16636 [Left SubErrPacketIdentifierInUse] [PropTopicAlias 16976,PropResponseInformation +// "\228-\224\254W0\ESC\DEL\222\194\172N\137OM\129Z",PropWildcardSubscriptionAvailable 101,PropTopicAlias +// 12928,PropReasonString +// "\167\179\209)\157^5T\165\219\192S\248PQ\167Yv\141\131\178\183\196)\US\206F\231E",PropServerReference +// "ocPa~5:}B\136q\235\145\239\223\RS\171L\236",PropMaximumPacketSize 4029,PropWillDelayInterval 24096,PropMaximumQoS +// 15,PropWillDelayInterval 25411,PropMaximumQoS 189,PropUserProperty +// "\158#\213\249e'\174E\171\193zf\170S\223*\ETB\208[\254-\162" +// "\177J\218\235\225\ENQv\164\f\145w5\228&`\231",PropReasonString +// "s\DLE\245\207\184v\STX'L\170\158\190\t\177F\ESCi{\154",PropMessageExpiryInterval 15125,PropWillDelayInterval +// 2760,PropAuthenticationMethod "\188\189\140\215\214t_\182\t\"2l9\205\n\253\237/9",PropSubscriptionIdentifier 3] +TEST(SubACK5QCTest, Decode9) { + uint8_t pkt[] = { + 0x90, 0xcd, 0x1, 0x40, 0xfc, 0xc8, 0x1, 0x23, 0x42, 0x50, 0x1a, 0x0, 0x11, 0xe4, 0x2d, 0xe0, 0xfe, 0x57, 0x30, + 0x1b, 0x7f, 0xde, 0xc2, 0xac, 0x4e, 0x89, 0x4f, 0x4d, 0x81, 0x5a, 0x28, 0x65, 0x23, 0x32, 0x80, 0x1f, 0x0, 0x1d, + 0xa7, 0xb3, 0xd1, 0x29, 0x9d, 0x5e, 0x35, 0x54, 0xa5, 0xdb, 0xc0, 0x53, 0xf8, 0x50, 0x51, 0xa7, 0x59, 0x76, 0x8d, + 0x83, 0xb2, 0xb7, 0xc4, 0x29, 0x1f, 0xce, 0x46, 0xe7, 0x45, 0x1c, 0x0, 0x13, 0x6f, 0x63, 0x50, 0x61, 0x7e, 0x35, + 0x3a, 0x7d, 0x42, 0x88, 0x71, 0xeb, 0x91, 0xef, 0xdf, 0x1e, 0xab, 0x4c, 0xec, 0x27, 0x0, 0x0, 0xf, 0xbd, 0x18, + 0x0, 0x0, 0x5e, 0x20, 0x24, 0xf, 0x18, 0x0, 0x0, 0x63, 0x43, 0x24, 0xbd, 0x26, 0x0, 0x16, 0x9e, 0x23, 0xd5, + 0xf9, 0x65, 0x27, 0xae, 0x45, 0xab, 0xc1, 0x7a, 0x66, 0xaa, 0x53, 0xdf, 0x2a, 0x17, 0xd0, 0x5b, 0xfe, 0x2d, 0xa2, + 0x0, 0x10, 0xb1, 0x4a, 0xda, 0xeb, 0xe1, 0x5, 0x76, 0xa4, 0xc, 0x91, 0x77, 0x35, 0xe4, 0x26, 0x60, 0xe7, 0x1f, + 0x0, 0x13, 0x73, 0x10, 0xf5, 0xcf, 0xb8, 0x76, 0x2, 0x27, 0x4c, 0xaa, 0x9e, 0xbe, 0x9, 0xb1, 0x46, 0x1b, 0x69, + 0x7b, 0x9a, 0x2, 0x0, 0x0, 0x3b, 0x15, 0x18, 0x0, 0x0, 0xa, 0xc8, 0x15, 0x0, 0x13, 0xbc, 0xbd, 0x8c, 0xd7, + 0xd6, 0x74, 0x5f, 0xb6, 0x9, 0x22, 0x32, 0x6c, 0x39, 0xcd, 0xa, 0xfd, 0xed, 0x2f, 0x39, 0xb, 0x3, 0x91}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[1]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 1, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 16636); + EXPECT_EQ(count, 1); + EXPECT_EQ(granted_qos_levels[0], 0x91); +} + +// SubscribeResponse 19978 [Left SubErrQuotaExceeded,Left SubErrUnspecifiedError,Left SubErrPacketIdentifierInUse,Left +// SubErrSubscriptionIdentifiersNotSupported,Left SubErrWildcardSubscriptionsNotSupported,Right QoS0] +// [PropAssignedClientIdentifier "Y&jh\131\&2\131\233\193\171\fD\166\138$w\141\149()\SOHguH\SO\a",PropRetainAvailable +// 79,PropSubscriptionIdentifier 8,PropContentType "\128^\134\152\148\t\SUB\144\&7\203\253\200\146\ACK",PropMaximumQoS +// 122,PropSubscriptionIdentifier 24,PropSubscriptionIdentifier 20,PropMaximumPacketSize 11473] +TEST(SubACK5QCTest, Decode10) { + uint8_t pkt[] = {0x90, 0x46, 0x4e, 0xa, 0x3d, 0x12, 0x0, 0x1a, 0x59, 0x26, 0x6a, 0x68, 0x83, 0x32, 0x83, + 0xe9, 0xc1, 0xab, 0xc, 0x44, 0xa6, 0x8a, 0x24, 0x77, 0x8d, 0x95, 0x28, 0x29, 0x1, 0x67, + 0x75, 0x48, 0xe, 0x7, 0x25, 0x4f, 0xb, 0x8, 0x3, 0x0, 0xe, 0x80, 0x5e, 0x86, 0x98, + 0x94, 0x9, 0x1a, 0x90, 0x37, 0xcb, 0xfd, 0xc8, 0x92, 0x6, 0x24, 0x7a, 0xb, 0x18, 0xb, + 0x14, 0x27, 0x0, 0x0, 0x2c, 0xd1, 0x97, 0x80, 0x91, 0xa1, 0xa2, 0x0}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[6]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 6, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 19978); + EXPECT_EQ(count, 6); + EXPECT_EQ(granted_qos_levels[0], 0x97); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], 0x91); + EXPECT_EQ(granted_qos_levels[3], 0xA1); + EXPECT_EQ(granted_qos_levels[4], 0xA2); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS0); +} + +// SubscribeResponse 1639 [Right QoS2,Right QoS1,Right QoS2,Left SubErrPacketIdentifierInUse,Right QoS0,Left +// SubErrTopicFilterInvalid] [PropMessageExpiryInterval 18162,PropRequestProblemInformation 166,PropTopicAlias +// 20962,PropMaximumPacketSize 20480,PropTopicAliasMaximum 17998,PropMaximumQoS 79,PropServerKeepAlive +// 17732,PropTopicAliasMaximum 13320,PropResponseInformation +// "'\253&\166\150\150\188z]+\230\SI\139",PropAuthenticationData "Ks\170\176\171:\135\\\243&",PropTopicAliasMaximum +// 30520,PropMaximumQoS 5,PropUserProperty "3\164cJk\254\170\SO\217\176\&8\190$\156f\245\f\DC2\157\FS" +// "\144\215\172\201*\158K\CAN\SOHH|\SYN\165\203/\147zu\135\244\143Cz \DC3\238\197\204",PropRetainAvailable +// 65,PropMessageExpiryInterval 4670,PropMessageExpiryInterval 6499,PropReceiveMaximum 9076,PropTopicAliasMaximum +// 15026,PropSharedSubscriptionAvailable 56,PropMessageExpiryInterval 29601,PropMaximumPacketSize +// 30923,PropAuthenticationData ")\160,\137aC\197=\218\171\176L\147\236\a",PropRequestProblemInformation +// 105,PropMessageExpiryInterval 8880] +TEST(SubACK5QCTest, Decode11) { + uint8_t pkt[] = {0x90, 0xb2, 0x1, 0x6, 0x67, 0xa8, 0x1, 0x2, 0x0, 0x0, 0x46, 0xf2, 0x17, 0xa6, 0x23, 0x51, 0xe2, + 0x27, 0x0, 0x0, 0x50, 0x0, 0x22, 0x46, 0x4e, 0x24, 0x4f, 0x13, 0x45, 0x44, 0x22, 0x34, 0x8, 0x1a, + 0x0, 0xd, 0x27, 0xfd, 0x26, 0xa6, 0x96, 0x96, 0xbc, 0x7a, 0x5d, 0x2b, 0xe6, 0xf, 0x8b, 0x16, 0x0, + 0xa, 0x4b, 0x73, 0xaa, 0xb0, 0xab, 0x3a, 0x87, 0x5c, 0xf3, 0x26, 0x22, 0x77, 0x38, 0x24, 0x5, 0x26, + 0x0, 0x14, 0x33, 0xa4, 0x63, 0x4a, 0x6b, 0xfe, 0xaa, 0xe, 0xd9, 0xb0, 0x38, 0xbe, 0x24, 0x9c, 0x66, + 0xf5, 0xc, 0x12, 0x9d, 0x1c, 0x0, 0x1c, 0x90, 0xd7, 0xac, 0xc9, 0x2a, 0x9e, 0x4b, 0x18, 0x1, 0x48, + 0x7c, 0x16, 0xa5, 0xcb, 0x2f, 0x93, 0x7a, 0x75, 0x87, 0xf4, 0x8f, 0x43, 0x7a, 0x20, 0x13, 0xee, 0xc5, + 0xcc, 0x25, 0x41, 0x2, 0x0, 0x0, 0x12, 0x3e, 0x2, 0x0, 0x0, 0x19, 0x63, 0x21, 0x23, 0x74, 0x22, + 0x3a, 0xb2, 0x2a, 0x38, 0x2, 0x0, 0x0, 0x73, 0xa1, 0x27, 0x0, 0x0, 0x78, 0xcb, 0x16, 0x0, 0xf, + 0x29, 0xa0, 0x2c, 0x89, 0x61, 0x43, 0xc5, 0x3d, 0xda, 0xab, 0xb0, 0x4c, 0x93, 0xec, 0x7, 0x17, 0x69, + 0x2, 0x0, 0x0, 0x22, 0xb0, 0x2, 0x1, 0x2, 0x91, 0x0, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[6]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 6, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 1639); + EXPECT_EQ(count, 6); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], 0x91); + EXPECT_EQ(granted_qos_levels[4], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[5], 0x8F); +} + +// SubscribeResponse 22530 [Left SubErrQuotaExceeded,Right QoS1,Right QoS1] [PropWildcardSubscriptionAvailable +// 151,PropCorrelationData "\186\212P!&\249\184\&3a\215\182H\160\"\218TA\171G*\DC3\195",PropServerReference +// "hD<\\\155\US\206\201\223\DEL\"\236\149\134^\SYN\132\&2j",PropSharedSubscriptionAvailable 241,PropReceiveMaximum +// 25249,PropServerReference "\232\145\159 +// \188\246X\145\203-l\181\216\ACK\170g\247\224\r\182\200e\160\220\129",PropCorrelationData +// "\230\194J\254I\179\202\SI\STX\226\&3v\167\b\160\188",PropAssignedClientIdentifier +// "y+Eh\191\&6\USbW\200\130\156\191\205^\147mt\176\ACK\223>",PropContentType "",PropReceiveMaximum +// 20599,PropServerKeepAlive 18200,PropSessionExpiryInterval 31439,PropAssignedClientIdentifier +// "\201Ig\245*B\ESC\173\156o\196e\164\172\138\216\176\EOT\149\129E\152\197E&\147Q",PropCorrelationData +// "!\202\133g\195\244\191\&1i=\150@\160\226\233+\130U",PropAssignedClientIdentifier +// "\ETBn(\158\131\SI\155\129\134\193\156\SOU\ACKe\DC2\213",PropResponseInformation +// "\227\134$\RS\220]m\184\165$\141\150\205\146L\201C\224o",PropAssignedClientIdentifier "\134\DLE\253\&2\255\183\SI +// \225q}Qz\RS^\147@",PropSessionExpiryInterval 31819,PropWildcardSubscriptionAvailable 159,PropResponseInformation +// "\200\164\224\233\192^\192\243;\131 \253\130\ETB",PropReceiveMaximum 30788,PropAssignedClientIdentifier +// "\DC2\182\142\SO",PropSubscriptionIdentifierAvailable 172,PropTopicAliasMaximum 17696,PropRequestProblemInformation +// 138,PropAuthenticationMethod "\150\203\207\&1d\190\243\229/\DC2w\141\195\NAKj\243N\229\&6\242\184*3\157\"\180"] +TEST(SubACK5QCTest, Decode12) { + uint8_t pkt[] = { + 0x90, 0xca, 0x2, 0x58, 0x2, 0xc3, 0x2, 0x28, 0x97, 0x9, 0x0, 0x16, 0xba, 0xd4, 0x50, 0x21, 0x26, 0xf9, 0xb8, + 0x33, 0x61, 0xd7, 0xb6, 0x48, 0xa0, 0x22, 0xda, 0x54, 0x41, 0xab, 0x47, 0x2a, 0x13, 0xc3, 0x1c, 0x0, 0x13, 0x68, + 0x44, 0x3c, 0x5c, 0x9b, 0x1f, 0xce, 0xc9, 0xdf, 0x7f, 0x22, 0xec, 0x95, 0x86, 0x5e, 0x16, 0x84, 0x32, 0x6a, 0x2a, + 0xf1, 0x21, 0x62, 0xa1, 0x1c, 0x0, 0x19, 0xe8, 0x91, 0x9f, 0x20, 0xbc, 0xf6, 0x58, 0x91, 0xcb, 0x2d, 0x6c, 0xb5, + 0xd8, 0x6, 0xaa, 0x67, 0xf7, 0xe0, 0xd, 0xb6, 0xc8, 0x65, 0xa0, 0xdc, 0x81, 0x9, 0x0, 0x10, 0xe6, 0xc2, 0x4a, + 0xfe, 0x49, 0xb3, 0xca, 0xf, 0x2, 0xe2, 0x33, 0x76, 0xa7, 0x8, 0xa0, 0xbc, 0x12, 0x0, 0x16, 0x79, 0x2b, 0x45, + 0x68, 0xbf, 0x36, 0x1f, 0x62, 0x57, 0xc8, 0x82, 0x9c, 0xbf, 0xcd, 0x5e, 0x93, 0x6d, 0x74, 0xb0, 0x6, 0xdf, 0x3e, + 0x3, 0x0, 0x0, 0x21, 0x50, 0x77, 0x13, 0x47, 0x18, 0x11, 0x0, 0x0, 0x7a, 0xcf, 0x12, 0x0, 0x1b, 0xc9, 0x49, + 0x67, 0xf5, 0x2a, 0x42, 0x1b, 0xad, 0x9c, 0x6f, 0xc4, 0x65, 0xa4, 0xac, 0x8a, 0xd8, 0xb0, 0x4, 0x95, 0x81, 0x45, + 0x98, 0xc5, 0x45, 0x26, 0x93, 0x51, 0x9, 0x0, 0x12, 0x21, 0xca, 0x85, 0x67, 0xc3, 0xf4, 0xbf, 0x31, 0x69, 0x3d, + 0x96, 0x40, 0xa0, 0xe2, 0xe9, 0x2b, 0x82, 0x55, 0x12, 0x0, 0x11, 0x17, 0x6e, 0x28, 0x9e, 0x83, 0xf, 0x9b, 0x81, + 0x86, 0xc1, 0x9c, 0xe, 0x55, 0x6, 0x65, 0x12, 0xd5, 0x1a, 0x0, 0x13, 0xe3, 0x86, 0x24, 0x1e, 0xdc, 0x5d, 0x6d, + 0xb8, 0xa5, 0x24, 0x8d, 0x96, 0xcd, 0x92, 0x4c, 0xc9, 0x43, 0xe0, 0x6f, 0x12, 0x0, 0x11, 0x86, 0x10, 0xfd, 0x32, + 0xff, 0xb7, 0xf, 0x20, 0xe1, 0x71, 0x7d, 0x51, 0x7a, 0x1e, 0x5e, 0x93, 0x40, 0x11, 0x0, 0x0, 0x7c, 0x4b, 0x28, + 0x9f, 0x1a, 0x0, 0xe, 0xc8, 0xa4, 0xe0, 0xe9, 0xc0, 0x5e, 0xc0, 0xf3, 0x3b, 0x83, 0x20, 0xfd, 0x82, 0x17, 0x21, + 0x78, 0x44, 0x12, 0x0, 0x4, 0x12, 0xb6, 0x8e, 0xe, 0x29, 0xac, 0x22, 0x45, 0x20, 0x17, 0x8a, 0x15, 0x0, 0x1a, + 0x96, 0xcb, 0xcf, 0x31, 0x64, 0xbe, 0xf3, 0xe5, 0x2f, 0x12, 0x77, 0x8d, 0xc3, 0x15, 0x6a, 0xf3, 0x4e, 0xe5, 0x36, + 0xf2, 0xb8, 0x2a, 0x33, 0x9d, 0x22, 0xb4, 0x97, 0x1, 0x1}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[3]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 3, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 22530); + EXPECT_EQ(count, 3); + EXPECT_EQ(granted_qos_levels[0], 0x97); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS1); +} + +// SubscribeResponse 27526 [Left SubErrSharedSubscriptionsNotSupported,Right QoS2,Left SubErrUnspecifiedError] +// [PropRequestResponseInformation 117,PropServerReference "\a\176#4s`",PropSessionExpiryInterval +// 2586,PropReceiveMaximum 19098,PropMaximumPacketSize 16262,PropResponseTopic "\241*-"] +TEST(SubACK5QCTest, Decode13) { + uint8_t pkt[] = {0x90, 0x24, 0x6b, 0x86, 0x1e, 0x19, 0x75, 0x1c, 0x0, 0x6, 0x7, 0xb0, 0x23, + 0x34, 0x73, 0x60, 0x11, 0x0, 0x0, 0xa, 0x1a, 0x21, 0x4a, 0x9a, 0x27, 0x0, + 0x0, 0x3f, 0x86, 0x8, 0x0, 0x3, 0xf1, 0x2a, 0x2d, 0x9e, 0x2, 0x80}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[3]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 3, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 27526); + EXPECT_EQ(count, 3); + EXPECT_EQ(granted_qos_levels[0], 0x9E); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[2], 0x80); +} + +// SubscribeResponse 31498 [Left SubErrSharedSubscriptionsNotSupported,Left SubErrPacketIdentifierInUse,Left +// SubErrSharedSubscriptionsNotSupported,Left SubErrTopicFilterInvalid] [] +TEST(SubACK5QCTest, Decode14) { + uint8_t pkt[] = {0x90, 0x7, 0x7b, 0xa, 0x0, 0x9e, 0x91, 0x9e, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[4]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 4, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 31498); + EXPECT_EQ(count, 4); + EXPECT_EQ(granted_qos_levels[0], 0x9E); + EXPECT_EQ(granted_qos_levels[1], 0x91); + EXPECT_EQ(granted_qos_levels[2], 0x9E); + EXPECT_EQ(granted_qos_levels[3], 0x8F); +} + +// SubscribeResponse 3933 [Left SubErrImplementationSpecificError,Right QoS2] [] +TEST(SubACK5QCTest, Decode15) { + uint8_t pkt[] = {0x90, 0x5, 0xf, 0x5d, 0x0, 0x83, 0x2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[2]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 2, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 3933); + EXPECT_EQ(count, 2); + EXPECT_EQ(granted_qos_levels[0], 0x83); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); +} + +// SubscribeResponse 30590 [Left SubErrSubscriptionIdentifiersNotSupported,Right QoS2,Left SubErrQuotaExceeded,Right +// QoS0,Left SubErrUnspecifiedError,Left SubErrPacketIdentifierInUse,Left SubErrQuotaExceeded,Right QoS1,Right QoS2] +// [PropAuthenticationMethod "\\\140\141\250\DLE\ENQ\DC4.\213",PropSubscriptionIdentifierAvailable +// 34,PropCorrelationData "\163",PropServerReference "\152\192\172",PropMessageExpiryInterval +// 22139,PropResponseInformation +// "ze\161\210U\186\203\212\184E\149;w\bbDW\186d\131\ETX}\183\SI\137>u\SO\185",PropWillDelayInterval +// 32115,PropSubscriptionIdentifier 29,PropWillDelayInterval 10222,PropReasonString "\185\STX,",PropCorrelationData +// "1\SOH\\(\227\236\182J\RSU\a\178[\tvFm\203\DEL_",PropResponseTopic +// "\148k\144L\212\195\255\255\&1j\243\177\236'\173",PropContentType +// "\237\249\131k\DELf\186",PropRequestResponseInformation 147,PropUserProperty "" +// "\147\188\206\237\251\&4\EM)\242\244\230)\250\168\US\148\219\239[\189\162o",PropRequestProblemInformation +// 156,PropSubscriptionIdentifierAvailable 196,PropPayloadFormatIndicator 187,PropResponseInformation +// "\167W\128\175\207y\\j\229\185\132",PropSubscriptionIdentifier 29,PropServerKeepAlive +// 26894,PropSubscriptionIdentifier 20] +TEST(SubACK5QCTest, Decode16) { + uint8_t pkt[] = {0x90, 0xc7, 0x1, 0x77, 0x7e, 0xba, 0x1, 0x15, 0x0, 0x9, 0x5c, 0x8c, 0x8d, 0xfa, 0x10, 0x5, 0x14, + 0x2e, 0xd5, 0x29, 0x22, 0x9, 0x0, 0x1, 0xa3, 0x1c, 0x0, 0x3, 0x98, 0xc0, 0xac, 0x2, 0x0, 0x0, + 0x56, 0x7b, 0x1a, 0x0, 0x1d, 0x7a, 0x65, 0xa1, 0xd2, 0x55, 0xba, 0xcb, 0xd4, 0xb8, 0x45, 0x95, 0x3b, + 0x77, 0x8, 0x62, 0x44, 0x57, 0xba, 0x64, 0x83, 0x3, 0x7d, 0xb7, 0xf, 0x89, 0x3e, 0x75, 0xe, 0xb9, + 0x18, 0x0, 0x0, 0x7d, 0x73, 0xb, 0x1d, 0x18, 0x0, 0x0, 0x27, 0xee, 0x1f, 0x0, 0x3, 0xb9, 0x2, + 0x2c, 0x9, 0x0, 0x14, 0x31, 0x1, 0x5c, 0x28, 0xe3, 0xec, 0xb6, 0x4a, 0x1e, 0x55, 0x7, 0xb2, 0x5b, + 0x9, 0x76, 0x46, 0x6d, 0xcb, 0x7f, 0x5f, 0x8, 0x0, 0xf, 0x94, 0x6b, 0x90, 0x4c, 0xd4, 0xc3, 0xff, + 0xff, 0x31, 0x6a, 0xf3, 0xb1, 0xec, 0x27, 0xad, 0x3, 0x0, 0x7, 0xed, 0xf9, 0x83, 0x6b, 0x7f, 0x66, + 0xba, 0x19, 0x93, 0x26, 0x0, 0x0, 0x0, 0x16, 0x93, 0xbc, 0xce, 0xed, 0xfb, 0x34, 0x19, 0x29, 0xf2, + 0xf4, 0xe6, 0x29, 0xfa, 0xa8, 0x1f, 0x94, 0xdb, 0xef, 0x5b, 0xbd, 0xa2, 0x6f, 0x17, 0x9c, 0x29, 0xc4, + 0x1, 0xbb, 0x1a, 0x0, 0xb, 0xa7, 0x57, 0x80, 0xaf, 0xcf, 0x79, 0x5c, 0x6a, 0xe5, 0xb9, 0x84, 0xb, + 0x1d, 0x13, 0x69, 0xe, 0xb, 0x14, 0xa1, 0x2, 0x97, 0x0, 0x80, 0x91, 0x97, 0x1, 0x2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[9]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 9, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 30590); + EXPECT_EQ(count, 9); + EXPECT_EQ(granted_qos_levels[0], 0xA1); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[2], 0x97); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[4], 0x80); + EXPECT_EQ(granted_qos_levels[5], 0x91); + EXPECT_EQ(granted_qos_levels[6], 0x97); + EXPECT_EQ(granted_qos_levels[7], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[8], LWMQTT_QOS2); +} + +// SubscribeResponse 28125 [Left SubErrUnspecifiedError,Left SubErrUnspecifiedError,Right QoS2] [PropRetainAvailable +// 157,PropSharedSubscriptionAvailable 195,PropRequestProblemInformation 101,PropSubscriptionIdentifierAvailable +// 103,PropRequestResponseInformation 216,PropSubscriptionIdentifierAvailable 245,PropReceiveMaximum +// 30247,PropSubscriptionIdentifierAvailable 137,PropPayloadFormatIndicator 102,PropSubscriptionIdentifierAvailable +// 66,PropTopicAliasMaximum 21408,PropReasonString +// "\188\DC3\DLE\211$\134D$2\146\166\224\161Z\155\"\NAK\194\213BWK\193\ESC' d\173",PropSessionExpiryInterval +// 2424,PropResponseTopic "\DC4\f\143\251 ",PropMessageExpiryInterval 20858,PropTopicAliasMaximum +// 32445,PropRequestResponseInformation 243,PropSubscriptionIdentifier 2,PropRetainAvailable +// 111,PropWildcardSubscriptionAvailable 73,PropWildcardSubscriptionAvailable 2,PropContentType +// "\204\162\181\145\221T\DC3\233\153\rA\150#\DLER\246`\255V\154\DC46\231\195\DC1\DC3",PropSharedSubscriptionAvailable +// 70] +TEST(SubACK5QCTest, Decode17) { + uint8_t pkt[] = {0x90, 0x7b, 0x6d, 0xdd, 0x75, 0x25, 0x9d, 0x2a, 0xc3, 0x17, 0x65, 0x29, 0x67, 0x19, 0xd8, 0x29, + 0xf5, 0x21, 0x76, 0x27, 0x29, 0x89, 0x1, 0x66, 0x29, 0x42, 0x22, 0x53, 0xa0, 0x1f, 0x0, 0x1c, + 0xbc, 0x13, 0x10, 0xd3, 0x24, 0x86, 0x44, 0x24, 0x32, 0x92, 0xa6, 0xe0, 0xa1, 0x5a, 0x9b, 0x22, + 0x15, 0xc2, 0xd5, 0x42, 0x57, 0x4b, 0xc1, 0x1b, 0x27, 0x20, 0x64, 0xad, 0x11, 0x0, 0x0, 0x9, + 0x78, 0x8, 0x0, 0x5, 0x14, 0xc, 0x8f, 0xfb, 0x20, 0x2, 0x0, 0x0, 0x51, 0x7a, 0x22, 0x7e, + 0xbd, 0x19, 0xf3, 0xb, 0x2, 0x25, 0x6f, 0x28, 0x49, 0x28, 0x2, 0x3, 0x0, 0x1a, 0xcc, 0xa2, + 0xb5, 0x91, 0xdd, 0x54, 0x13, 0xe9, 0x99, 0xd, 0x41, 0x96, 0x23, 0x10, 0x52, 0xf6, 0x60, 0xff, + 0x56, 0x9a, 0x14, 0x36, 0xe7, 0xc3, 0x11, 0x13, 0x2a, 0x46, 0x80, 0x80, 0x2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[3]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 3, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 28125); + EXPECT_EQ(count, 3); + EXPECT_EQ(granted_qos_levels[0], 0x80); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); +} + +// SubscribeResponse 3160 [Right QoS1,Right QoS0,Left SubErrUnspecifiedError,Left SubErrUnspecifiedError,Right QoS1,Left +// SubErrSharedSubscriptionsNotSupported,Left SubErrUnspecifiedError,Right QoS0,Right QoS0] +// [PropSharedSubscriptionAvailable 76,PropReceiveMaximum 15225,PropUserProperty "U\238\139\214\154\240" +// "\130G\207\183\208\179t\233t_\SIQ",PropResponseTopic "\STX\166\198\157aZ\157h\254\&0\195\168",PropWillDelayInterval +// 2577,PropUserProperty "+\138\&6m\163\222\142x\vh\254\SI+\213\US\217\134\170`" +// "\213\237\FS\138\163",PropServerReference +// "\DLE\177qU\148}\208\204V\DLEO\NUL}\233\DLE\163\191O\240\199\152\191\199\191{",PropContentType +// "\161\130\246\DC3\CAN\t\160\191h\254^6U\140\RS\EM\CAN\245D\DC1W\218\134\&7\r5\EM\NAK\211\186",PropAuthenticationMethod +// "\135",PropSessionExpiryInterval +// 8714,PropMaximumPacketSize 21604,PropRequestResponseInformation 176,PropTopicAliasMaximum +// 9879,PropAuthenticationMethod "cm\179\170\206\232\153\198d\210w\176v`\193\CAN1g#\229\176e\159\GS\RS",PropRequestProblemInformation +// 222,PropCorrelationData "'L\136\\]\160u3\238\227",PropResponseInformation +// "\238\211\150%\167\DLE>\205\190\217\198\186\&1\158\168\250\250\176\143\&6\251\227\SO\221G\211\206X\DC1\238",PropSubscriptionIdentifier +// 25,PropAuthenticationMethod "P\NUL\168\DC4<\147Y5\198i\151\150",PropReasonString +// "\151\195\244\190\164\128V\198\238\nZ",PropServerReference "*|",PropResponseInformation +// "\153v7\ACKp/\a\240",PropCorrelationData "\208\&2q\235!\n#\v\156\&1\ETXT\172\154",PropPayloadFormatIndicator +// 89,PropAssignedClientIdentifier "X\\/\230%`\173\249/\179V\136\&0s\218#'\245",PropCorrelationData +// "q\230#\254\231\NAK\214E\144\&8\172\204\206\216\254\226\171\177"] +TEST(SubACK5QCTest, Decode24) { + uint8_t pkt[] = { + 0x90, 0xa8, 0x2, 0x29, 0xf4, 0xa0, 0x2, 0x11, 0x0, 0x0, 0x24, 0xde, 0x21, 0x43, 0x19, 0x25, 0x16, 0x26, 0x0, + 0x1d, 0xf1, 0x76, 0x17, 0xdc, 0xc4, 0x6, 0x2e, 0x75, 0xc2, 0xcb, 0x20, 0x6b, 0x52, 0xa0, 0xc3, 0xcc, 0xc2, 0xce, + 0x52, 0x4a, 0xad, 0xdd, 0xc8, 0xa9, 0x1e, 0xf9, 0x86, 0x49, 0x3d, 0x0, 0x14, 0xdb, 0xe, 0x5e, 0xb2, 0x63, 0x0, + 0x25, 0xfb, 0x4a, 0xc1, 0x14, 0x7c, 0x66, 0x14, 0xd4, 0x75, 0x23, 0x81, 0xe5, 0x52, 0x23, 0x4e, 0xca, 0x19, 0x57, + 0x18, 0x0, 0x0, 0x51, 0x57, 0x25, 0x32, 0x3, 0x0, 0xf, 0x91, 0x6e, 0x9a, 0x32, 0x18, 0xab, 0x83, 0x68, 0x98, + 0x99, 0x75, 0xb2, 0x5d, 0x2f, 0xa1, 0x2, 0x0, 0x0, 0x1c, 0xc5, 0x1c, 0x0, 0x1e, 0x3f, 0xc2, 0x2d, 0xc5, 0xf0, + 0xe, 0x31, 0x9e, 0xda, 0x1c, 0xec, 0x66, 0xa0, 0xa6, 0xa7, 0x3e, 0xb0, 0x76, 0x60, 0xc1, 0x18, 0x31, 0x67, 0x23, + 0xe5, 0xb0, 0x65, 0x9f, 0x1d, 0x1e, 0x17, 0xde, 0x9, 0x0, 0xa, 0x27, 0x4c, 0x88, 0x5c, 0x5d, 0xa0, 0x75, 0x33, + 0xee, 0xe3, 0x1a, 0x0, 0x1e, 0xee, 0xd3, 0x96, 0x25, 0xa7, 0x10, 0x3e, 0xcd, 0xbe, 0xd9, 0xc6, 0xba, 0x31, 0x9e, + 0xa8, 0xfa, 0xfa, 0xb0, 0x8f, 0x36, 0xfb, 0xe3, 0xe, 0xdd, 0x47, 0xd3, 0xce, 0x58, 0x11, 0xee, 0xb, 0x19, 0x15, + 0x0, 0xc, 0x50, 0x0, 0xa8, 0x14, 0x3c, 0x93, 0x59, 0x35, 0xc6, 0x69, 0x97, 0x96, 0x1f, 0x0, 0xb, 0x97, 0xc3, + 0xf4, 0xbe, 0xa4, 0x80, 0x56, 0xc6, 0xee, 0xa, 0x5a, 0x1c, 0x0, 0x2, 0x2a, 0x7c, 0x1a, 0x0, 0x8, 0x99, 0x76, + 0x37, 0x6, 0x70, 0x2f, 0x7, 0xf0, 0x9, 0x0, 0xe, 0xd0, 0x32, 0x71, 0xeb, 0x21, 0xa, 0x23, 0xb, 0x9c, 0x31, + 0x3, 0x54, 0xac, 0x9a, 0x1, 0x59, 0x12, 0x0, 0x12, 0x58, 0x5c, 0x2f, 0xe6, 0x25, 0x60, 0xad, 0xf9, 0x2f, 0xb3, + 0x56, 0x88, 0x30, 0x73, 0xda, 0x23, 0x27, 0xf5, 0x9, 0x0, 0x12, 0x71, 0xe6, 0x23, 0xfe, 0xe7, 0x15, 0xd6, 0x45, + 0x90, 0x38, 0xac, 0xcc, 0xce, 0xd8, 0xfe, 0xe2, 0xab, 0xb1, 0x9e, 0x2, 0x2, 0x9e}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[4]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 4, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 10740); + EXPECT_EQ(count, 4); + EXPECT_EQ(granted_qos_levels[0], 0x9E); + EXPECT_EQ(granted_qos_levels[1], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], 0x9E); +} + +// SubscribeResponse 18996 [Left SubErrPacketIdentifierInUse,Left SubErrImplementationSpecificError,Right QoS0,Right +// QoS0,Left SubErrTopicFilterInvalid,Right QoS1,Left SubErrTopicFilterInvalid,Left +// SubErrWildcardSubscriptionsNotSupported,Left SubErrPacketIdentifierInUse,Right QoS2,Left +// SubErrSubscriptionIdentifiersNotSupported] [PropMessageExpiryInterval 6754,PropResponseInformation +// "_Y/r\171\DC2SB\141\195",PropMaximumQoS 246,PropServerKeepAlive 26728,PropContentType +// "5\169b;$U#\t1$Geo\242\246\191\&7,^\232\151\226\&3(=",PropWillDelayInterval 10899,PropRequestResponseInformation +// 14,PropContentType +// "\STX\225JdLV~\SYN\233\252\ACK\"\212\137\128Q\160\218\246\153\215\195\166Z\233FV",PropRetainAvailable +// 209,PropReceiveMaximum 451,PropSessionExpiryInterval 6678,PropRequestProblemInformation 5,PropContentType +// "9\227\170'p\DC1?:W|[\239\151\&0U",PropAssignedClientIdentifier "\224\217\161\227d\248Q{",PropAuthenticationData +// "d.\SUB\151\218=A\188\192\173\248\240b\227\161\214\234\&6j\140B\159\132"] +TEST(SubACK5QCTest, Decode25) { + uint8_t pkt[] = {0x90, 0xaa, 0x1, 0x4a, 0x34, 0x9b, 0x1, 0x2, 0x0, 0x0, 0x1a, 0x62, 0x1a, 0x0, 0xa, 0x5f, + 0x59, 0x2f, 0x72, 0xab, 0x12, 0x53, 0x42, 0x8d, 0xc3, 0x24, 0xf6, 0x13, 0x68, 0x68, 0x3, 0x0, + 0x19, 0x35, 0xa9, 0x62, 0x3b, 0x24, 0x55, 0x23, 0x9, 0x31, 0x24, 0x47, 0x65, 0x6f, 0xf2, 0xf6, + 0xbf, 0x37, 0x2c, 0x5e, 0xe8, 0x97, 0xe2, 0x33, 0x28, 0x3d, 0x18, 0x0, 0x0, 0x2a, 0x93, 0x19, + 0xe, 0x3, 0x0, 0x1b, 0x2, 0xe1, 0x4a, 0x64, 0x4c, 0x56, 0x7e, 0x16, 0xe9, 0xfc, 0x6, 0x22, + 0xd4, 0x89, 0x80, 0x51, 0xa0, 0xda, 0xf6, 0x99, 0xd7, 0xc3, 0xa6, 0x5a, 0xe9, 0x46, 0x56, 0x25, + 0xd1, 0x21, 0x1, 0xc3, 0x11, 0x0, 0x0, 0x1a, 0x16, 0x17, 0x5, 0x3, 0x0, 0xf, 0x39, 0xe3, + 0xaa, 0x27, 0x70, 0x11, 0x3f, 0x3a, 0x57, 0x7c, 0x5b, 0xef, 0x97, 0x30, 0x55, 0x12, 0x0, 0x8, + 0xe0, 0xd9, 0xa1, 0xe3, 0x64, 0xf8, 0x51, 0x7b, 0x16, 0x0, 0x17, 0x64, 0x2e, 0x1a, 0x97, 0xda, + 0x3d, 0x41, 0xbc, 0xc0, 0xad, 0xf8, 0xf0, 0x62, 0xe3, 0xa1, 0xd6, 0xea, 0x36, 0x6a, 0x8c, 0x42, + 0x9f, 0x84, 0x91, 0x83, 0x0, 0x0, 0x8f, 0x1, 0x8f, 0xa2, 0x91, 0x2, 0xa1}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[11]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 11, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 18996); + EXPECT_EQ(count, 11); + EXPECT_EQ(granted_qos_levels[0], 0x91); + EXPECT_EQ(granted_qos_levels[1], 0x83); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[4], 0x8F); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[6], 0x8F); + EXPECT_EQ(granted_qos_levels[7], 0xA2); + EXPECT_EQ(granted_qos_levels[8], 0x91); + EXPECT_EQ(granted_qos_levels[9], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[10], 0xA1); +} + +// SubscribeResponse 969 [Left SubErrWildcardSubscriptionsNotSupported,Left SubErrNotAuthorized,Right QoS2,Right +// QoS0,Right QoS2,Left SubErrPacketIdentifierInUse,Right QoS1,Right QoS0,Right QoS2,Left SubErrNotAuthorized,Left +// SubErrWildcardSubscriptionsNotSupported] [PropAssignedClientIdentifier +// "\ACK\178\151\157:-\148\236z\238",PropSharedSubscriptionAvailable 72,PropSharedSubscriptionAvailable +// 13,PropReceiveMaximum 28208,PropSessionExpiryInterval 22804,PropResponseTopic +// "\a\243o\228y\226\222A\255\214\&3",PropTopicAliasMaximum 26597,PropSharedSubscriptionAvailable 80,PropReasonString +// "5\168\233H,\146\&8\205\168>[\165 \128\245\DEL\161\134n\129\250\b\193ds\217d\208 \f",PropReceiveMaximum +// 5194,PropResponseTopic "%x\222",PropRetainAvailable 84,PropSharedSubscriptionAvailable 98,PropPayloadFormatIndicator +// 151,PropSharedSubscriptionAvailable 202,PropMessageExpiryInterval 22832,PropTopicAlias +// 8014,PropRequestProblemInformation 95,PropContentType +// "\NAK\183o\234\249\240\138\&8\210\138\ESC\242l\138#!\206",PropRequestResponseInformation 74,PropContentType +// "\DC2\152\149W\208\249\173#\195n\r\187"] +TEST(SubACK5QCTest, Decode26) { + uint8_t pkt[] = {0x90, 0x9c, 0x1, 0x3, 0xc9, 0x8d, 0x1, 0x12, 0x0, 0xa, 0x6, 0xb2, 0x97, 0x9d, 0x3a, 0x2d, + 0x94, 0xec, 0x7a, 0xee, 0x2a, 0x48, 0x2a, 0xd, 0x21, 0x6e, 0x30, 0x11, 0x0, 0x0, 0x59, 0x14, + 0x8, 0x0, 0xb, 0x7, 0xf3, 0x6f, 0xe4, 0x79, 0xe2, 0xde, 0x41, 0xff, 0xd6, 0x33, 0x22, 0x67, + 0xe5, 0x2a, 0x50, 0x1f, 0x0, 0x1e, 0x35, 0xa8, 0xe9, 0x48, 0x2c, 0x92, 0x38, 0xcd, 0xa8, 0x3e, + 0x5b, 0xa5, 0x20, 0x80, 0xf5, 0x7f, 0xa1, 0x86, 0x6e, 0x81, 0xfa, 0x8, 0xc1, 0x64, 0x73, 0xd9, + 0x64, 0xd0, 0x20, 0xc, 0x21, 0x14, 0x4a, 0x8, 0x0, 0x3, 0x25, 0x78, 0xde, 0x25, 0x54, 0x2a, + 0x62, 0x1, 0x97, 0x2a, 0xca, 0x2, 0x0, 0x0, 0x59, 0x30, 0x23, 0x1f, 0x4e, 0x17, 0x5f, 0x3, + 0x0, 0x11, 0x15, 0xb7, 0x6f, 0xea, 0xf9, 0xf0, 0x8a, 0x38, 0xd2, 0x8a, 0x1b, 0xf2, 0x6c, 0x8a, + 0x23, 0x21, 0xce, 0x19, 0x4a, 0x3, 0x0, 0xc, 0x12, 0x98, 0x95, 0x57, 0xd0, 0xf9, 0xad, 0x23, + 0xc3, 0x6e, 0xd, 0xbb, 0xa2, 0x87, 0x2, 0x0, 0x2, 0x91, 0x1, 0x0, 0x2, 0x87, 0xa2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[11]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 11, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 969); + EXPECT_EQ(count, 11); + EXPECT_EQ(granted_qos_levels[0], 0xA2); + EXPECT_EQ(granted_qos_levels[1], 0x87); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[4], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[5], 0x91); + EXPECT_EQ(granted_qos_levels[6], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[7], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[8], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[9], 0x87); + EXPECT_EQ(granted_qos_levels[10], 0xA2); +} + +// SubscribeResponse 27073 [Left SubErrSubscriptionIdentifiersNotSupported,Left SubErrTopicFilterInvalid,Right +// QoS1,Right QoS2,Left SubErrTopicFilterInvalid,Left SubErrWildcardSubscriptionsNotSupported] +// [PropMessageExpiryInterval 29081,PropResponseInformation "\184\210\128\CANF\162\218)U\159\182",PropWillDelayInterval +// 16309,PropRetainAvailable 172,PropMaximumPacketSize 9960,PropTopicAliasMaximum 3288,PropResponseInformation +// "\157\178\162\139\163\220\206L\207:\144\242"] +TEST(SubACK5QCTest, Decode27) { + uint8_t pkt[] = {0x90, 0x3a, 0x69, 0xc1, 0x31, 0x2, 0x0, 0x0, 0x71, 0x99, 0x1a, 0x0, 0xb, 0xb8, 0xd2, + 0x80, 0x18, 0x46, 0xa2, 0xda, 0x29, 0x55, 0x9f, 0xb6, 0x18, 0x0, 0x0, 0x3f, 0xb5, 0x25, + 0xac, 0x27, 0x0, 0x0, 0x26, 0xe8, 0x22, 0xc, 0xd8, 0x1a, 0x0, 0xc, 0x9d, 0xb2, 0xa2, + 0x8b, 0xa3, 0xdc, 0xce, 0x4c, 0xcf, 0x3a, 0x90, 0xf2, 0xa1, 0x8f, 0x1, 0x2, 0x8f, 0xa2}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[6]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 6, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 27073); + EXPECT_EQ(count, 6); + EXPECT_EQ(granted_qos_levels[0], 0xA1); + EXPECT_EQ(granted_qos_levels[1], 0x8F); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[4], 0x8F); + EXPECT_EQ(granted_qos_levels[5], 0xA2); +} + +// SubscribeResponse 9700 [Right QoS1,Left SubErrSubscriptionIdentifiersNotSupported,Left SubErrUnspecifiedError,Left +// SubErrWildcardSubscriptionsNotSupported,Right QoS2,Right QoS0,Left SubErrSubscriptionIdentifiersNotSupported] +// [PropContentType "ZX\249\DEL\aP\179\182\161\&7\tz\199\252\244\DC3\ACKczK~{6\ETX\248\202"] +TEST(SubACK5QCTest, Decode28) { + uint8_t pkt[] = {0x90, 0x27, 0x25, 0xe4, 0x1d, 0x3, 0x0, 0x1a, 0x5a, 0x58, 0xf9, 0x7f, 0x7, 0x50, + 0xb3, 0xb6, 0xa1, 0x37, 0x9, 0x7a, 0xc7, 0xfc, 0xf4, 0x13, 0x6, 0x63, 0x7a, 0x4b, + 0x7e, 0x7b, 0x36, 0x3, 0xf8, 0xca, 0x1, 0xa1, 0x80, 0xa2, 0x2, 0x0, 0xa1}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[7]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 7, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 9700); + EXPECT_EQ(count, 7); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[1], 0xA1); + EXPECT_EQ(granted_qos_levels[2], 0x80); + EXPECT_EQ(granted_qos_levels[3], 0xA2); + EXPECT_EQ(granted_qos_levels[4], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[5], LWMQTT_QOS0); + EXPECT_EQ(granted_qos_levels[6], 0xA1); +} + +// SubscribeResponse 31732 [Left SubErrNotAuthorized,Left SubErrImplementationSpecificError,Right QoS2,Right QoS1,Left +// SubErrImplementationSpecificError,Left SubErrQuotaExceeded,Left SubErrSubscriptionIdentifiersNotSupported,Left +// SubErrUnspecifiedError] [PropTopicAlias 10185,PropRetainAvailable 195,PropRequestResponseInformation +// 115,PropSharedSubscriptionAvailable 45,PropRequestResponseInformation 166,PropMessageExpiryInterval +// 31591,PropCorrelationData "\DC1",PropAssignedClientIdentifier +// "\GS\251\165\159d}\248\140v\220\f\150\245",PropReceiveMaximum 31778,PropRequestResponseInformation +// 16,PropAuthenticationData "F\201\f",PropReasonString "x\234r \149\237\133\178",PropRequestProblemInformation +// 219,PropMaximumPacketSize 24668,PropCorrelationData "\196Q\182\172S\224",PropUserProperty +// "\207zm[\239\ah%\154\253-o\SUB" "|8\234\147G\GSmO\142\239E\235BH\SYN\202:\233v@\136\230 g\tFj",PropCorrelationData +// "\130|`\135\139\195\ESC\252O\EOTsp~aJ\155)\220\198H\\\245\166\148C\133",PropTopicAliasMaximum 5742] +TEST(SubACK5QCTest, Decode29) { + uint8_t pkt[] = {0x90, 0xa3, 0x1, 0x7b, 0xf4, 0x97, 0x1, 0x23, 0x27, 0xc9, 0x25, 0xc3, 0x19, 0x73, 0x2a, 0x2d, 0x19, + 0xa6, 0x2, 0x0, 0x0, 0x7b, 0x67, 0x9, 0x0, 0x1, 0x11, 0x12, 0x0, 0xd, 0x1d, 0xfb, 0xa5, 0x9f, + 0x64, 0x7d, 0xf8, 0x8c, 0x76, 0xdc, 0xc, 0x96, 0xf5, 0x21, 0x7c, 0x22, 0x19, 0x10, 0x16, 0x0, 0x3, + 0x46, 0xc9, 0xc, 0x1f, 0x0, 0x8, 0x78, 0xea, 0x72, 0x20, 0x95, 0xed, 0x85, 0xb2, 0x17, 0xdb, 0x27, + 0x0, 0x0, 0x60, 0x5c, 0x9, 0x0, 0x6, 0xc4, 0x51, 0xb6, 0xac, 0x53, 0xe0, 0x26, 0x0, 0xd, 0xcf, + 0x7a, 0x6d, 0x5b, 0xef, 0x7, 0x68, 0x25, 0x9a, 0xfd, 0x2d, 0x6f, 0x1a, 0x0, 0x1b, 0x7c, 0x38, 0xea, + 0x93, 0x47, 0x1d, 0x6d, 0x4f, 0x8e, 0xef, 0x45, 0xeb, 0x42, 0x48, 0x16, 0xca, 0x3a, 0xe9, 0x76, 0x40, + 0x88, 0xe6, 0x20, 0x67, 0x9, 0x46, 0x6a, 0x9, 0x0, 0x1a, 0x82, 0x7c, 0x60, 0x87, 0x8b, 0xc3, 0x1b, + 0xfc, 0x4f, 0x4, 0x73, 0x70, 0x7e, 0x61, 0x4a, 0x9b, 0x29, 0xdc, 0xc6, 0x48, 0x5c, 0xf5, 0xa6, 0x94, + 0x43, 0x85, 0x22, 0x16, 0x6e, 0x87, 0x83, 0x2, 0x1, 0x83, 0x97, 0xa1, 0x80}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[8]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 8, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 31732); + EXPECT_EQ(count, 8); + EXPECT_EQ(granted_qos_levels[0], 0x87); + EXPECT_EQ(granted_qos_levels[1], 0x83); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], LWMQTT_QOS1); + EXPECT_EQ(granted_qos_levels[4], 0x83); + EXPECT_EQ(granted_qos_levels[5], 0x97); + EXPECT_EQ(granted_qos_levels[6], 0xA1); + EXPECT_EQ(granted_qos_levels[7], 0x80); +} + +// SubscribeResponse 6520 [Right QoS2,Left SubErrUnspecifiedError,Right QoS2,Left SubErrQuotaExceeded] +// [PropRequestProblemInformation 181,PropTopicAliasMaximum 22327,PropMessageExpiryInterval +// 17747,PropSubscriptionIdentifier 2,PropPayloadFormatIndicator 251,PropSubscriptionIdentifierAvailable +// 248,PropMaximumQoS 45,PropSharedSubscriptionAvailable 5,PropSubscriptionIdentifierAvailable 48,PropServerKeepAlive +// 27265,PropAssignedClientIdentifier +// "\200\&1`\198\198\170\207\224\r\179o\219\DC4\228\201\209\222\186\130\174\DC1",PropAssignedClientIdentifier +// "=\233\194^J\a\STXwmv",PropMessageExpiryInterval 16237,PropSessionExpiryInterval 17822,PropRetainAvailable +// 225,PropRequestProblemInformation 76,PropWildcardSubscriptionAvailable 184] +TEST(SubACK5QCTest, Decode30) { + uint8_t pkt[] = {0x90, 0x55, 0x19, 0x78, 0x4e, 0x17, 0xb5, 0x22, 0x57, 0x37, 0x2, 0x0, 0x0, 0x45, 0x53, + 0xb, 0x2, 0x1, 0xfb, 0x29, 0xf8, 0x24, 0x2d, 0x2a, 0x5, 0x29, 0x30, 0x13, 0x6a, 0x81, + 0x12, 0x0, 0x15, 0xc8, 0x31, 0x60, 0xc6, 0xc6, 0xaa, 0xcf, 0xe0, 0xd, 0xb3, 0x6f, 0xdb, + 0x14, 0xe4, 0xc9, 0xd1, 0xde, 0xba, 0x82, 0xae, 0x11, 0x12, 0x0, 0xa, 0x3d, 0xe9, 0xc2, + 0x5e, 0x4a, 0x7, 0x2, 0x77, 0x6d, 0x76, 0x2, 0x0, 0x0, 0x3f, 0x6d, 0x11, 0x0, 0x0, + 0x45, 0x9e, 0x25, 0xe1, 0x17, 0x4c, 0x28, 0xb8, 0x2, 0x80, 0x2, 0x97}; + uint16_t packet_id; + int count; + lwmqtt_qos_t granted_qos_levels[4]; + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 4, &count, granted_qos_levels); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 6520); + EXPECT_EQ(count, 4); + EXPECT_EQ(granted_qos_levels[0], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[1], 0x80); + EXPECT_EQ(granted_qos_levels[2], LWMQTT_QOS2); + EXPECT_EQ(granted_qos_levels[3], 0x97); +} + +// UnsubscribeRequest 22317 +// ["\SUB{\230Y\DC1\b\EM\160\232\SUB\CAN\131\NUL\188t\134\180\194a\152K\153\153\177\DLE1\225\161\225"] [] +TEST(Unsubscribe311QCTest, Encode1) { + uint8_t pkt[] = {0xa2, 0x21, 0x57, 0x2d, 0x0, 0x1d, 0x1a, 0x7b, 0xe6, 0x59, 0x11, 0x8, + 0x19, 0xa0, 0xe8, 0x1a, 0x18, 0x83, 0x0, 0xbc, 0x74, 0x86, 0xb4, 0xc2, + 0x61, 0x98, 0x4b, 0x99, 0x99, 0xb1, 0x10, 0x31, 0xe1, 0xa1, 0xe1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x1a, 0x7b, 0xe6, 0x59, 0x11, 0x8, 0x19, 0xa0, 0xe8, 0x1a, + 0x18, 0x83, 0x0, 0xbc, 0x74, 0x86, 0xb4, 0xc2, 0x61, 0x98, + 0x4b, 0x99, 0x99, 0xb1, 0x10, 0x31, 0xe1, 0xa1, 0xe1}; + lwmqtt_string_t topic_filter_s0 = {29, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 22317, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 24293 +// ["\177\195\r\186\208","j)G\249\ACK#[\204\130\&4\DC2\136\221$$\ENQl\\\229\a\166\175\191\237\165V\184!:","\193\&9hv\252]\252\204(","X\SO\SUB\236F\175ZC\230\190XaK\149\137\"\248\233`\DEL\196","\DC4XY\180\EOT\\\198\201\137\155\243\212\224\249\206B\DC2\DC1(","","\EM\159*x\161c%\180\218\254\\\177\172\180\137CU\196\155\248\194"] +// [] +TEST(Unsubscribe311QCTest, Encode2) { + uint8_t pkt[] = {0xa2, 0x78, 0x5e, 0xe5, 0x0, 0x5, 0xb1, 0xc3, 0xd, 0xba, 0xd0, 0x0, 0x1d, 0x6a, 0x29, 0x47, + 0xf9, 0x6, 0x23, 0x5b, 0xcc, 0x82, 0x34, 0x12, 0x88, 0xdd, 0x24, 0x24, 0x5, 0x6c, 0x5c, 0xe5, + 0x7, 0xa6, 0xaf, 0xbf, 0xed, 0xa5, 0x56, 0xb8, 0x21, 0x3a, 0x0, 0x9, 0xc1, 0x39, 0x68, 0x76, + 0xfc, 0x5d, 0xfc, 0xcc, 0x28, 0x0, 0x15, 0x58, 0xe, 0x1a, 0xec, 0x46, 0xaf, 0x5a, 0x43, 0xe6, + 0xbe, 0x58, 0x61, 0x4b, 0x95, 0x89, 0x22, 0xf8, 0xe9, 0x60, 0x7f, 0xc4, 0x0, 0x13, 0x14, 0x58, + 0x59, 0xb4, 0x4, 0x5c, 0xc6, 0xc9, 0x89, 0x9b, 0xf3, 0xd4, 0xe0, 0xf9, 0xce, 0x42, 0x12, 0x11, + 0x28, 0x0, 0x0, 0x0, 0x15, 0x19, 0x9f, 0x2a, 0x78, 0xa1, 0x63, 0x25, 0xb4, 0xda, 0xfe, 0x5c, + 0xb1, 0xac, 0xb4, 0x89, 0x43, 0x55, 0xc4, 0x9b, 0xf8, 0xc2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0xb1, 0xc3, 0xd, 0xba, 0xd0}; + lwmqtt_string_t topic_filter_s0 = {5, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x6a, 0x29, 0x47, 0xf9, 0x6, 0x23, 0x5b, 0xcc, 0x82, 0x34, + 0x12, 0x88, 0xdd, 0x24, 0x24, 0x5, 0x6c, 0x5c, 0xe5, 0x7, + 0xa6, 0xaf, 0xbf, 0xed, 0xa5, 0x56, 0xb8, 0x21, 0x3a}; + lwmqtt_string_t topic_filter_s1 = {29, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xc1, 0x39, 0x68, 0x76, 0xfc, 0x5d, 0xfc, 0xcc, 0x28}; + lwmqtt_string_t topic_filter_s2 = {9, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x58, 0xe, 0x1a, 0xec, 0x46, 0xaf, 0x5a, 0x43, 0xe6, 0xbe, 0x58, + 0x61, 0x4b, 0x95, 0x89, 0x22, 0xf8, 0xe9, 0x60, 0x7f, 0xc4}; + lwmqtt_string_t topic_filter_s3 = {21, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x14, 0x58, 0x59, 0xb4, 0x4, 0x5c, 0xc6, 0xc9, 0x89, 0x9b, + 0xf3, 0xd4, 0xe0, 0xf9, 0xce, 0x42, 0x12, 0x11, 0x28}; + lwmqtt_string_t topic_filter_s4 = {19, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0}; + lwmqtt_string_t topic_filter_s5 = {0, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x19, 0x9f, 0x2a, 0x78, 0xa1, 0x63, 0x25, 0xb4, 0xda, 0xfe, 0x5c, + 0xb1, 0xac, 0xb4, 0x89, 0x43, 0x55, 0xc4, 0x9b, 0xf8, 0xc2}; + lwmqtt_string_t topic_filter_s6 = {21, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 24293, 7, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 10329 +// ["=]\230@","=4\172<\189?\DEL\142X\235",">\180QZX\217\199@","~}\"\182\146\230\151\176\250MD:\144\171\237Q\226X",")\188\182\214\&1\161\144\201>h\192"] +// [] +TEST(Unsubscribe311QCTest, Encode3) { + uint8_t pkt[] = {0xa2, 0x3f, 0x28, 0x59, 0x0, 0x4, 0x3d, 0x5d, 0xe6, 0x40, 0x0, 0xa, 0x3d, 0x34, 0xac, 0x3c, 0xbd, + 0x3f, 0x7f, 0x8e, 0x58, 0xeb, 0x0, 0x8, 0x3e, 0xb4, 0x51, 0x5a, 0x58, 0xd9, 0xc7, 0x40, 0x0, 0x12, + 0x7e, 0x7d, 0x22, 0xb6, 0x92, 0xe6, 0x97, 0xb0, 0xfa, 0x4d, 0x44, 0x3a, 0x90, 0xab, 0xed, 0x51, 0xe2, + 0x58, 0x0, 0xb, 0x29, 0xbc, 0xb6, 0xd6, 0x31, 0xa1, 0x90, 0xc9, 0x3e, 0x68, 0xc0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0x3d, 0x5d, 0xe6, 0x40}; + lwmqtt_string_t topic_filter_s0 = {4, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x3d, 0x34, 0xac, 0x3c, 0xbd, 0x3f, 0x7f, 0x8e, 0x58, 0xeb}; + lwmqtt_string_t topic_filter_s1 = {10, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x3e, 0xb4, 0x51, 0x5a, 0x58, 0xd9, 0xc7, 0x40}; + lwmqtt_string_t topic_filter_s2 = {8, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x7e, 0x7d, 0x22, 0xb6, 0x92, 0xe6, 0x97, 0xb0, 0xfa, + 0x4d, 0x44, 0x3a, 0x90, 0xab, 0xed, 0x51, 0xe2, 0x58}; + lwmqtt_string_t topic_filter_s3 = {18, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x29, 0xbc, 0xb6, 0xd6, 0x31, 0xa1, 0x90, 0xc9, 0x3e, 0x68, 0xc0}; + lwmqtt_string_t topic_filter_s4 = {11, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 10329, 5, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 1566 ["\248f\177\a\209\171O\234C","\r\207\164\185\187[\175","}\213\235~\236\226x"] [] +TEST(Unsubscribe311QCTest, Encode4) { + uint8_t pkt[] = {0xa2, 0x1f, 0x6, 0x1e, 0x0, 0x9, 0xf8, 0x66, 0xb1, 0x7, 0xd1, 0xab, 0x4f, 0xea, 0x43, 0x0, 0x7, + 0xd, 0xcf, 0xa4, 0xb9, 0xbb, 0x5b, 0xaf, 0x0, 0x7, 0x7d, 0xd5, 0xeb, 0x7e, 0xec, 0xe2, 0x78}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[3]; + uint8_t topic_filter_s0_bytes[] = {0xf8, 0x66, 0xb1, 0x7, 0xd1, 0xab, 0x4f, 0xea, 0x43}; + lwmqtt_string_t topic_filter_s0 = {9, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xd, 0xcf, 0xa4, 0xb9, 0xbb, 0x5b, 0xaf}; + lwmqtt_string_t topic_filter_s1 = {7, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x7d, 0xd5, 0xeb, 0x7e, 0xec, 0xe2, 0x78}; + lwmqtt_string_t topic_filter_s2 = {7, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 1566, 3, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 22798 ["\214 +// Y}]\179\173\176\b\251]h\254\ESC\182,\133@\151j\ESC\159\GS","\233.\192\135\197\200\229\&2x\v\225\196\212\CAN}.","<\137}/\159\230\156\167b\178\157\205\GS\185","\198\243\228\142\132\168\RS\131\223\&6\253\217\SYN\SOHZ\159\185\243\244\138\136\SO\178\ESC\235\187\154\137","\213\213\156\129\DC2\206vq\233I\171\193\187}\168b\255\221\EM\253Z\195p\244\130","\SO\131z\DC4,5R\ENQ","\STX\193/\236>\189\241\&2\186v\186V\178\138\n\202\195\244\182\181_\ENQ\222\215\\+\177",")","\161.m\ESC\f\253a\221\167\t\199#","@\213\DC1\188GHQ\153\138\NAK\161A\ESC\161\162I\246Q\200\152?\251"] +// [] +TEST(Unsubscribe311QCTest, Encode5) { + uint8_t pkt[] = {0xa2, 0xc6, 0x1, 0x59, 0xe, 0x0, 0x17, 0xd6, 0x20, 0x59, 0x7d, 0x5d, 0xb3, 0xad, 0xb0, 0x8, 0xfb, + 0x5d, 0x68, 0xfe, 0x1b, 0xb6, 0x2c, 0x85, 0x40, 0x97, 0x6a, 0x1b, 0x9f, 0x1d, 0x0, 0x10, 0xe9, 0x2e, + 0xc0, 0x87, 0xc5, 0xc8, 0xe5, 0x32, 0x78, 0xb, 0xe1, 0xc4, 0xd4, 0x18, 0x7d, 0x2e, 0x0, 0xe, 0x3c, + 0x89, 0x7d, 0x2f, 0x9f, 0xe6, 0x9c, 0xa7, 0x62, 0xb2, 0x9d, 0xcd, 0x1d, 0xb9, 0x0, 0x1c, 0xc6, 0xf3, + 0xe4, 0x8e, 0x84, 0xa8, 0x1e, 0x83, 0xdf, 0x36, 0xfd, 0xd9, 0x16, 0x1, 0x5a, 0x9f, 0xb9, 0xf3, 0xf4, + 0x8a, 0x88, 0xe, 0xb2, 0x1b, 0xeb, 0xbb, 0x9a, 0x89, 0x0, 0x19, 0xd5, 0xd5, 0x9c, 0x81, 0x12, 0xce, + 0x76, 0x71, 0xe9, 0x49, 0xab, 0xc1, 0xbb, 0x7d, 0xa8, 0x62, 0xff, 0xdd, 0x19, 0xfd, 0x5a, 0xc3, 0x70, + 0xf4, 0x82, 0x0, 0x8, 0xe, 0x83, 0x7a, 0x14, 0x2c, 0x35, 0x52, 0x5, 0x0, 0x1b, 0x2, 0xc1, 0x2f, + 0xec, 0x3e, 0xbd, 0xf1, 0x32, 0xba, 0x76, 0xba, 0x56, 0xb2, 0x8a, 0xa, 0xca, 0xc3, 0xf4, 0xb6, 0xb5, + 0x5f, 0x5, 0xde, 0xd7, 0x5c, 0x2b, 0xb1, 0x0, 0x1, 0x29, 0x0, 0xc, 0xa1, 0x2e, 0x6d, 0x1b, 0xc, + 0xfd, 0x61, 0xdd, 0xa7, 0x9, 0xc7, 0x23, 0x0, 0x16, 0x40, 0xd5, 0x11, 0xbc, 0x47, 0x48, 0x51, 0x99, + 0x8a, 0x15, 0xa1, 0x41, 0x1b, 0xa1, 0xa2, 0x49, 0xf6, 0x51, 0xc8, 0x98, 0x3f, 0xfb}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[10]; + uint8_t topic_filter_s0_bytes[] = {0xd6, 0x20, 0x59, 0x7d, 0x5d, 0xb3, 0xad, 0xb0, 0x8, 0xfb, 0x5d, 0x68, + 0xfe, 0x1b, 0xb6, 0x2c, 0x85, 0x40, 0x97, 0x6a, 0x1b, 0x9f, 0x1d}; + lwmqtt_string_t topic_filter_s0 = {23, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xe9, 0x2e, 0xc0, 0x87, 0xc5, 0xc8, 0xe5, 0x32, + 0x78, 0xb, 0xe1, 0xc4, 0xd4, 0x18, 0x7d, 0x2e}; + lwmqtt_string_t topic_filter_s1 = {16, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x3c, 0x89, 0x7d, 0x2f, 0x9f, 0xe6, 0x9c, + 0xa7, 0x62, 0xb2, 0x9d, 0xcd, 0x1d, 0xb9}; + lwmqtt_string_t topic_filter_s2 = {14, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xc6, 0xf3, 0xe4, 0x8e, 0x84, 0xa8, 0x1e, 0x83, 0xdf, 0x36, + 0xfd, 0xd9, 0x16, 0x1, 0x5a, 0x9f, 0xb9, 0xf3, 0xf4, 0x8a, + 0x88, 0xe, 0xb2, 0x1b, 0xeb, 0xbb, 0x9a, 0x89}; + lwmqtt_string_t topic_filter_s3 = {28, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xd5, 0xd5, 0x9c, 0x81, 0x12, 0xce, 0x76, 0x71, 0xe9, 0x49, 0xab, 0xc1, 0xbb, + 0x7d, 0xa8, 0x62, 0xff, 0xdd, 0x19, 0xfd, 0x5a, 0xc3, 0x70, 0xf4, 0x82}; + lwmqtt_string_t topic_filter_s4 = {25, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xe, 0x83, 0x7a, 0x14, 0x2c, 0x35, 0x52, 0x5}; + lwmqtt_string_t topic_filter_s5 = {8, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x2, 0xc1, 0x2f, 0xec, 0x3e, 0xbd, 0xf1, 0x32, 0xba, 0x76, 0xba, 0x56, 0xb2, 0x8a, + 0xa, 0xca, 0xc3, 0xf4, 0xb6, 0xb5, 0x5f, 0x5, 0xde, 0xd7, 0x5c, 0x2b, 0xb1}; + lwmqtt_string_t topic_filter_s6 = {27, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x29}; + lwmqtt_string_t topic_filter_s7 = {1, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xa1, 0x2e, 0x6d, 0x1b, 0xc, 0xfd, 0x61, 0xdd, 0xa7, 0x9, 0xc7, 0x23}; + lwmqtt_string_t topic_filter_s8 = {12, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x40, 0xd5, 0x11, 0xbc, 0x47, 0x48, 0x51, 0x99, 0x8a, 0x15, 0xa1, + 0x41, 0x1b, 0xa1, 0xa2, 0x49, 0xf6, 0x51, 0xc8, 0x98, 0x3f, 0xfb}; + lwmqtt_string_t topic_filter_s9 = {22, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 22798, 10, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 24222 +// ["5\171","\213JI\161N\156\190\210I\")\SUB\177f","r\254N;","\150\129\236\130\164\ESC\186o\184[\228\&4\155\160\"9\181\195Ke\DC3k\228\&5Y\EOT\GS\ENQ\ACK\185","x\173\243\136\&49t\232\193M\EMU\245k1\234s\177\148@\SYN\SO\245\STX\228\138","y\248\215"] +// [] +TEST(Unsubscribe311QCTest, Encode6) { + uint8_t pkt[] = {0xa2, 0x5d, 0x5e, 0x9e, 0x0, 0x2, 0x35, 0xab, 0x0, 0xe, 0xd5, 0x4a, 0x49, 0xa1, 0x4e, 0x9c, + 0xbe, 0xd2, 0x49, 0x22, 0x29, 0x1a, 0xb1, 0x66, 0x0, 0x4, 0x72, 0xfe, 0x4e, 0x3b, 0x0, 0x1e, + 0x96, 0x81, 0xec, 0x82, 0xa4, 0x1b, 0xba, 0x6f, 0xb8, 0x5b, 0xe4, 0x34, 0x9b, 0xa0, 0x22, 0x39, + 0xb5, 0xc3, 0x4b, 0x65, 0x13, 0x6b, 0xe4, 0x35, 0x59, 0x4, 0x1d, 0x5, 0x6, 0xb9, 0x0, 0x1a, + 0x78, 0xad, 0xf3, 0x88, 0x34, 0x39, 0x74, 0xe8, 0xc1, 0x4d, 0x19, 0x55, 0xf5, 0x6b, 0x31, 0xea, + 0x73, 0xb1, 0x94, 0x40, 0x16, 0xe, 0xf5, 0x2, 0xe4, 0x8a, 0x0, 0x3, 0x79, 0xf8, 0xd7}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[6]; + uint8_t topic_filter_s0_bytes[] = {0x35, 0xab}; + lwmqtt_string_t topic_filter_s0 = {2, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xd5, 0x4a, 0x49, 0xa1, 0x4e, 0x9c, 0xbe, + 0xd2, 0x49, 0x22, 0x29, 0x1a, 0xb1, 0x66}; + lwmqtt_string_t topic_filter_s1 = {14, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x72, 0xfe, 0x4e, 0x3b}; + lwmqtt_string_t topic_filter_s2 = {4, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x96, 0x81, 0xec, 0x82, 0xa4, 0x1b, 0xba, 0x6f, 0xb8, 0x5b, + 0xe4, 0x34, 0x9b, 0xa0, 0x22, 0x39, 0xb5, 0xc3, 0x4b, 0x65, + 0x13, 0x6b, 0xe4, 0x35, 0x59, 0x4, 0x1d, 0x5, 0x6, 0xb9}; + lwmqtt_string_t topic_filter_s3 = {30, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x78, 0xad, 0xf3, 0x88, 0x34, 0x39, 0x74, 0xe8, 0xc1, 0x4d, 0x19, 0x55, 0xf5, + 0x6b, 0x31, 0xea, 0x73, 0xb1, 0x94, 0x40, 0x16, 0xe, 0xf5, 0x2, 0xe4, 0x8a}; + lwmqtt_string_t topic_filter_s4 = {26, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x79, 0xf8, 0xd7}; + lwmqtt_string_t topic_filter_s5 = {3, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 24222, 6, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 12540 ["\142\149\170v\174V',D\DELQ=,\212\228v"] [] +TEST(Unsubscribe311QCTest, Encode7) { + uint8_t pkt[] = {0xa2, 0x14, 0x30, 0xfc, 0x0, 0x10, 0x8e, 0x95, 0xaa, 0x76, 0xae, + 0x56, 0x27, 0x2c, 0x44, 0x7f, 0x51, 0x3d, 0x2c, 0xd4, 0xe4, 0x76}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x8e, 0x95, 0xaa, 0x76, 0xae, 0x56, 0x27, 0x2c, + 0x44, 0x7f, 0x51, 0x3d, 0x2c, 0xd4, 0xe4, 0x76}; + lwmqtt_string_t topic_filter_s0 = {16, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 12540, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 30589 +// [",\131\ETB\170\237\194/\147\140iM\159*x\159V\134","\STX\142\DC1r\DC1\130\183\v\211\183\147\192\211\194\165\200\139I\DEL\174P\171\255p\201p\237","\188\US\rg\233 +// \140\235\ETX\218ZA","S\ETB\255w\US\250\184\&8E\171\173","\EM\ETB8\ESCN","2\230c\246\211\&1\216\150\202\221\173w\147\232$\132pD\236","\186\157\201\165\158\210\ETB\232\194\236\&2<","\GS]\181\179\142\190\230\242(&\196`\142\131\184\\\243"] +// [] +TEST(Unsubscribe311QCTest, Encode9) { + uint8_t pkt[] = {0xa2, 0x84, 0x1, 0x6b, 0x56, 0x0, 0x17, 0x81, 0x46, 0x14, 0xa5, 0x65, 0x78, 0x87, 0x57, 0x5e, 0xa3, + 0x37, 0x5b, 0x1c, 0x80, 0x1c, 0xbb, 0xee, 0xcb, 0xf3, 0x24, 0xca, 0x1c, 0x7, 0x0, 0x1d, 0xe4, 0x77, + 0x9e, 0xf2, 0xba, 0xf9, 0x11, 0xea, 0x7, 0xdb, 0xc6, 0xc1, 0xac, 0x87, 0x59, 0xa1, 0x89, 0x39, 0x3e, + 0xd, 0x67, 0xe9, 0x20, 0x8c, 0xeb, 0x3, 0xda, 0x5a, 0x41, 0x0, 0xb, 0x53, 0x17, 0xff, 0x77, 0x1f, + 0xfa, 0xb8, 0x38, 0x45, 0xab, 0xad, 0x0, 0x5, 0x19, 0x17, 0x38, 0x1b, 0x4e, 0x0, 0x13, 0x32, 0xe6, + 0x63, 0xf6, 0xd3, 0x31, 0xd8, 0x96, 0xca, 0xdd, 0xad, 0x77, 0x93, 0xe8, 0x24, 0x84, 0x70, 0x44, 0xec, + 0x0, 0xc, 0xba, 0x9d, 0xc9, 0xa5, 0x9e, 0xd2, 0x17, 0xe8, 0xc2, 0xec, 0x32, 0x3c, 0x0, 0x11, 0x1d, + 0x5d, 0xb5, 0xb3, 0x8e, 0xbe, 0xe6, 0xf2, 0x28, 0x26, 0xc4, 0x60, 0x8e, 0x83, 0xb8, 0x5c, 0xf3}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0x81, 0x46, 0x14, 0xa5, 0x65, 0x78, 0x87, 0x57, 0x5e, 0xa3, 0x37, 0x5b, + 0x1c, 0x80, 0x1c, 0xbb, 0xee, 0xcb, 0xf3, 0x24, 0xca, 0x1c, 0x7}; + lwmqtt_string_t topic_filter_s0 = {23, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xe4, 0x77, 0x9e, 0xf2, 0xba, 0xf9, 0x11, 0xea, 0x7, 0xdb, + 0xc6, 0xc1, 0xac, 0x87, 0x59, 0xa1, 0x89, 0x39, 0x3e, 0xd, + 0x67, 0xe9, 0x20, 0x8c, 0xeb, 0x3, 0xda, 0x5a, 0x41}; + lwmqtt_string_t topic_filter_s1 = {29, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x53, 0x17, 0xff, 0x77, 0x1f, 0xfa, 0xb8, 0x38, 0x45, 0xab, 0xad}; + lwmqtt_string_t topic_filter_s2 = {11, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x19, 0x17, 0x38, 0x1b, 0x4e}; + lwmqtt_string_t topic_filter_s3 = {5, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x32, 0xe6, 0x63, 0xf6, 0xd3, 0x31, 0xd8, 0x96, 0xca, 0xdd, + 0xad, 0x77, 0x93, 0xe8, 0x24, 0x84, 0x70, 0x44, 0xec}; + lwmqtt_string_t topic_filter_s4 = {19, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xba, 0x9d, 0xc9, 0xa5, 0x9e, 0xd2, 0x17, 0xe8, 0xc2, 0xec, 0x32, 0x3c}; + lwmqtt_string_t topic_filter_s5 = {12, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x1d, 0x5d, 0xb5, 0xb3, 0x8e, 0xbe, 0xe6, 0xf2, 0x28, + 0x26, 0xc4, 0x60, 0x8e, 0x83, 0xb8, 0x5c, 0xf3}; + lwmqtt_string_t topic_filter_s6 = {17, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 27478, 7, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 18764 +// ["ui\144\128DK\158\RS-oM\167F\213\134\185\210)\189\188\129\201\220\&1z\155\157","\169\200\213O\SOH\206\141\139\213\236\154}\152u\176\134\227\&0N\207\EOT\156gt;\187k\159H","\206\172\214oS\145\156\204\243\DLE\210\244\SYN\139*\DC2\167B\203&\253\186\f\148\247y","-\DC4\EOTT\178\"\162\b\240\242~n2A","@\138\214D\t>7\224\205.\175\EM\SUB\209\229","\138\r\131\241\214h\241\246\&9N\203\214\a\168z!2\218\192\152wW\224","`s\ESC\204\253\132dr\189^I\148e\253\219Ef_\155\221\157\160ON\239=\148\&3\176\241","\147\146\174g\NAK;=\175\245\251\194\146\SYNT\157lYJ\a\176\255Q])\240\ESC\164L\243\138Z`\202u\183w\n\193}\159.\214\155","\255\206\142`","\208\139\240\191|\DEL\198\233\ETB\CAN\151[\DC2[\175\251vI\ETX;$\162\nv/1\179","\184\196\146D\229\218\FS\DC2\153"] +// [] +TEST(Unsubscribe311QCTest, Encode11) { + uint8_t pkt[] = {0xa2, 0xa9, 0x1, 0x72, 0x9c, 0x0, 0xb, 0x2c, 0x38, 0xde, 0x6c, 0x8d, 0xab, 0xe4, 0x96, 0x25, + 0xb4, 0xee, 0x0, 0x15, 0x66, 0x8b, 0xc6, 0xfa, 0x82, 0xad, 0xc6, 0xd9, 0x76, 0x18, 0xb1, 0x1d, + 0x7e, 0x7a, 0xf4, 0xa7, 0x2d, 0x31, 0xef, 0xf0, 0x5a, 0x0, 0x1e, 0x6d, 0x34, 0xd9, 0x3b, 0x97, + 0x93, 0x39, 0x75, 0x43, 0x77, 0xfd, 0x74, 0x4f, 0x1f, 0xff, 0x57, 0x82, 0xa4, 0x33, 0x7d, 0x23, + 0x98, 0xb5, 0x8f, 0x9f, 0x51, 0x42, 0xae, 0xac, 0xab, 0x0, 0x13, 0x32, 0xdd, 0x96, 0xbb, 0x8f, + 0x30, 0xa, 0xaa, 0x44, 0x97, 0x15, 0xd1, 0xcf, 0xcb, 0x15, 0x36, 0xe9, 0xcb, 0xa0, 0x0, 0x1e, + 0x37, 0xa, 0xc, 0xf8, 0xaa, 0x81, 0x3e, 0xff, 0x51, 0x5d, 0x29, 0xf0, 0x1b, 0xa4, 0x4c, 0xf3, + 0x8a, 0x5a, 0x60, 0xca, 0x75, 0xb7, 0x77, 0xa, 0xc1, 0x7d, 0x9f, 0x2e, 0xd6, 0x9b, 0x0, 0x4, + 0xff, 0xce, 0x8e, 0x60, 0x0, 0x1b, 0xd0, 0x8b, 0xf0, 0xbf, 0x7c, 0x7f, 0xc6, 0xe9, 0x17, 0x18, + 0x97, 0x5b, 0x12, 0x5b, 0xaf, 0xfb, 0x76, 0x49, 0x3, 0x3b, 0x24, 0xa2, 0xa, 0x76, 0x2f, 0x31, + 0xb3, 0x0, 0x9, 0xb8, 0xc4, 0x92, 0x44, 0xe5, 0xda, 0x1c, 0x12, 0x99}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[8]; + uint8_t topic_filter_s0_bytes[] = {0x2c, 0x38, 0xde, 0x6c, 0x8d, 0xab, 0xe4, 0x96, 0x25, 0xb4, 0xee}; + lwmqtt_string_t topic_filter_s0 = {11, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x66, 0x8b, 0xc6, 0xfa, 0x82, 0xad, 0xc6, 0xd9, 0x76, 0x18, 0xb1, + 0x1d, 0x7e, 0x7a, 0xf4, 0xa7, 0x2d, 0x31, 0xef, 0xf0, 0x5a}; + lwmqtt_string_t topic_filter_s1 = {21, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x6d, 0x34, 0xd9, 0x3b, 0x97, 0x93, 0x39, 0x75, 0x43, 0x77, + 0xfd, 0x74, 0x4f, 0x1f, 0xff, 0x57, 0x82, 0xa4, 0x33, 0x7d, + 0x23, 0x98, 0xb5, 0x8f, 0x9f, 0x51, 0x42, 0xae, 0xac, 0xab}; + lwmqtt_string_t topic_filter_s2 = {30, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x32, 0xdd, 0x96, 0xbb, 0x8f, 0x30, 0xa, 0xaa, 0x44, 0x97, + 0x15, 0xd1, 0xcf, 0xcb, 0x15, 0x36, 0xe9, 0xcb, 0xa0}; + lwmqtt_string_t topic_filter_s3 = {19, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x37, 0xa, 0xc, 0xf8, 0xaa, 0x81, 0x3e, 0xff, 0x51, 0x5d, + 0x29, 0xf0, 0x1b, 0xa4, 0x4c, 0xf3, 0x8a, 0x5a, 0x60, 0xca, + 0x75, 0xb7, 0x77, 0xa, 0xc1, 0x7d, 0x9f, 0x2e, 0xd6, 0x9b}; + lwmqtt_string_t topic_filter_s4 = {30, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xff, 0xce, 0x8e, 0x60}; + lwmqtt_string_t topic_filter_s5 = {4, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xd0, 0x8b, 0xf0, 0xbf, 0x7c, 0x7f, 0xc6, 0xe9, 0x17, 0x18, 0x97, 0x5b, 0x12, 0x5b, + 0xaf, 0xfb, 0x76, 0x49, 0x3, 0x3b, 0x24, 0xa2, 0xa, 0x76, 0x2f, 0x31, 0xb3}; + lwmqtt_string_t topic_filter_s6 = {27, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xb8, 0xc4, 0x92, 0x44, 0xe5, 0xda, 0x1c, 0x12, 0x99}; + lwmqtt_string_t topic_filter_s7 = {9, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 29340, 8, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 24289 +// ["\n\b_\177","\SO\173\150\235=\192\GSn\194\230\155","}0\US\\\211\232\235\DC1[\238\231\192\209Z\247","\234\ACK&\142\250","g\nP\ENQ%\231\181O\209\135\180\175q$\ETX75\164\168\EM\128\237\158","\245\184u\183\169S\226\171\US\SI\243\DC4x\154\DC2\228\211\195\243W\202\218\NUL\224\&5\236\132\246","\204\"i\DC4\191\234\255\177|\153\255~","m\211","m\128\ESCiS\128.\143/\172\205\144l\161\DEL[)\168y","!\183*7Kr\181\253\180,\146\166\&9\158\207T5\206\209Wx\225","\229\215Yl={\ETB\216/\212}\170\DEL"] +// [] +TEST(Unsubscribe311QCTest, Encode12) { + uint8_t pkt[] = {0xa2, 0xb2, 0x1, 0x5e, 0xe1, 0x0, 0x4, 0xa, 0x8, 0x5f, 0xb1, 0x0, 0xb, 0xe, 0xad, 0x96, 0xeb, + 0x3d, 0xc0, 0x1d, 0x6e, 0xc2, 0xe6, 0x9b, 0x0, 0xf, 0x7d, 0x30, 0x1f, 0x5c, 0xd3, 0xe8, 0xeb, 0x11, + 0x5b, 0xee, 0xe7, 0xc0, 0xd1, 0x5a, 0xf7, 0x0, 0x5, 0xea, 0x6, 0x26, 0x8e, 0xfa, 0x0, 0x17, 0x67, + 0xa, 0x50, 0x5, 0x25, 0xe7, 0xb5, 0x4f, 0xd1, 0x87, 0xb4, 0xaf, 0x71, 0x24, 0x3, 0x37, 0x35, 0xa4, + 0xa8, 0x19, 0x80, 0xed, 0x9e, 0x0, 0x1c, 0xf5, 0xb8, 0x75, 0xb7, 0xa9, 0x53, 0xe2, 0xab, 0x1f, 0xf, + 0xf3, 0x14, 0x78, 0x9a, 0x12, 0xe4, 0xd3, 0xc3, 0xf3, 0x57, 0xca, 0xda, 0x0, 0xe0, 0x35, 0xec, 0x84, + 0xf6, 0x0, 0xc, 0xcc, 0x22, 0x69, 0x14, 0xbf, 0xea, 0xff, 0xb1, 0x7c, 0x99, 0xff, 0x7e, 0x0, 0x2, + 0x6d, 0xd3, 0x0, 0x13, 0x6d, 0x80, 0x1b, 0x69, 0x53, 0x80, 0x2e, 0x8f, 0x2f, 0xac, 0xcd, 0x90, 0x6c, + 0xa1, 0x7f, 0x5b, 0x29, 0xa8, 0x79, 0x0, 0x16, 0x21, 0xb7, 0x2a, 0x37, 0x4b, 0x72, 0xb5, 0xfd, 0xb4, + 0x2c, 0x92, 0xa6, 0x39, 0x9e, 0xcf, 0x54, 0x35, 0xce, 0xd1, 0x57, 0x78, 0xe1, 0x0, 0xd, 0xe5, 0xd7, + 0x59, 0x6c, 0x3d, 0x7b, 0x17, 0xd8, 0x2f, 0xd4, 0x7d, 0xaa, 0x7f}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0xa, 0x8, 0x5f, 0xb1}; + lwmqtt_string_t topic_filter_s0 = {4, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xe, 0xad, 0x96, 0xeb, 0x3d, 0xc0, 0x1d, 0x6e, 0xc2, 0xe6, 0x9b}; + lwmqtt_string_t topic_filter_s1 = {11, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x7d, 0x30, 0x1f, 0x5c, 0xd3, 0xe8, 0xeb, 0x11, + 0x5b, 0xee, 0xe7, 0xc0, 0xd1, 0x5a, 0xf7}; + lwmqtt_string_t topic_filter_s2 = {15, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xea, 0x6, 0x26, 0x8e, 0xfa}; + lwmqtt_string_t topic_filter_s3 = {5, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x67, 0xa, 0x50, 0x5, 0x25, 0xe7, 0xb5, 0x4f, 0xd1, 0x87, 0xb4, 0xaf, + 0x71, 0x24, 0x3, 0x37, 0x35, 0xa4, 0xa8, 0x19, 0x80, 0xed, 0x9e}; + lwmqtt_string_t topic_filter_s4 = {23, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xf5, 0xb8, 0x75, 0xb7, 0xa9, 0x53, 0xe2, 0xab, 0x1f, 0xf, + 0xf3, 0x14, 0x78, 0x9a, 0x12, 0xe4, 0xd3, 0xc3, 0xf3, 0x57, + 0xca, 0xda, 0x0, 0xe0, 0x35, 0xec, 0x84, 0xf6}; + lwmqtt_string_t topic_filter_s5 = {28, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xcc, 0x22, 0x69, 0x14, 0xbf, 0xea, 0xff, 0xb1, 0x7c, 0x99, 0xff, 0x7e}; + lwmqtt_string_t topic_filter_s6 = {12, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x6d, 0xd3}; + lwmqtt_string_t topic_filter_s7 = {2, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x6d, 0x80, 0x1b, 0x69, 0x53, 0x80, 0x2e, 0x8f, 0x2f, 0xac, + 0xcd, 0x90, 0x6c, 0xa1, 0x7f, 0x5b, 0x29, 0xa8, 0x79}; + lwmqtt_string_t topic_filter_s8 = {19, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x21, 0xb7, 0x2a, 0x37, 0x4b, 0x72, 0xb5, 0xfd, 0xb4, 0x2c, 0x92, + 0xa6, 0x39, 0x9e, 0xcf, 0x54, 0x35, 0xce, 0xd1, 0x57, 0x78, 0xe1}; + lwmqtt_string_t topic_filter_s9 = {22, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0xe5, 0xd7, 0x59, 0x6c, 0x3d, 0x7b, 0x17, 0xd8, 0x2f, 0xd4, 0x7d, 0xaa, 0x7f}; + lwmqtt_string_t topic_filter_s10 = {13, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 24289, 11, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 26276 +// ["U^\138\255\DC2\173G\168Q\178\rw8ZS","\162\\\255\SOHI\247\ETB\199\148e\254\245\221\242\129\161\181_\214\DEL","\166\180j +// ","m\DLEV\240\&7\150\DC1\248lX\136\130\205]\233\142NLy\tB\251ll,`\155E\143\138","\141\GS\195\177)_)w9C\234\132H\154\DC1J\147","\213\215P","\247\239\158","\226\165#\135\230;\245\233\171}","\202>m\132\GS9\145\246\137\NAK\237Q"] +// [] +TEST(Unsubscribe311QCTest, Encode13) { + uint8_t pkt[] = {0xa2, 0x86, 0x1, 0x66, 0xa4, 0x0, 0xf, 0x55, 0x5e, 0x8a, 0xff, 0x12, 0xad, 0x47, 0xa8, 0x51, + 0xb2, 0xd, 0x77, 0x38, 0x5a, 0x53, 0x0, 0x14, 0xa2, 0x5c, 0xff, 0x1, 0x49, 0xf7, 0x17, 0xc7, + 0x94, 0x65, 0xfe, 0xf5, 0xdd, 0xf2, 0x81, 0xa1, 0xb5, 0x5f, 0xd6, 0x7f, 0x0, 0x4, 0xa6, 0xb4, + 0x6a, 0x20, 0x0, 0x1e, 0x6d, 0x10, 0x56, 0xf0, 0x37, 0x96, 0x11, 0xf8, 0x6c, 0x58, 0x88, 0x82, + 0xcd, 0x5d, 0xe9, 0x8e, 0x4e, 0x4c, 0x79, 0x9, 0x42, 0xfb, 0x6c, 0x6c, 0x2c, 0x60, 0x9b, 0x45, + 0x8f, 0x8a, 0x0, 0x11, 0x8d, 0x1d, 0xc3, 0xb1, 0x29, 0x5f, 0x29, 0x77, 0x39, 0x43, 0xea, 0x84, + 0x48, 0x9a, 0x11, 0x4a, 0x93, 0x0, 0x3, 0xd5, 0xd7, 0x50, 0x0, 0x3, 0xf7, 0xef, 0x9e, 0x0, + 0xa, 0xe2, 0xa5, 0x23, 0x87, 0xe6, 0x3b, 0xf5, 0xe9, 0xab, 0x7d, 0x0, 0xc, 0xca, 0x3e, 0x6d, + 0x84, 0x1d, 0x39, 0x91, 0xf6, 0x89, 0x15, 0xed, 0x51}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[9]; + uint8_t topic_filter_s0_bytes[] = {0x55, 0x5e, 0x8a, 0xff, 0x12, 0xad, 0x47, 0xa8, + 0x51, 0xb2, 0xd, 0x77, 0x38, 0x5a, 0x53}; + lwmqtt_string_t topic_filter_s0 = {15, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xa2, 0x5c, 0xff, 0x1, 0x49, 0xf7, 0x17, 0xc7, 0x94, 0x65, + 0xfe, 0xf5, 0xdd, 0xf2, 0x81, 0xa1, 0xb5, 0x5f, 0xd6, 0x7f}; + lwmqtt_string_t topic_filter_s1 = {20, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xa6, 0xb4, 0x6a, 0x20}; + lwmqtt_string_t topic_filter_s2 = {4, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x6d, 0x10, 0x56, 0xf0, 0x37, 0x96, 0x11, 0xf8, 0x6c, 0x58, + 0x88, 0x82, 0xcd, 0x5d, 0xe9, 0x8e, 0x4e, 0x4c, 0x79, 0x9, + 0x42, 0xfb, 0x6c, 0x6c, 0x2c, 0x60, 0x9b, 0x45, 0x8f, 0x8a}; + lwmqtt_string_t topic_filter_s3 = {30, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x8d, 0x1d, 0xc3, 0xb1, 0x29, 0x5f, 0x29, 0x77, 0x39, + 0x43, 0xea, 0x84, 0x48, 0x9a, 0x11, 0x4a, 0x93}; + lwmqtt_string_t topic_filter_s4 = {17, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xd5, 0xd7, 0x50}; + lwmqtt_string_t topic_filter_s5 = {3, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xf7, 0xef, 0x9e}; + lwmqtt_string_t topic_filter_s6 = {3, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xe2, 0xa5, 0x23, 0x87, 0xe6, 0x3b, 0xf5, 0xe9, 0xab, 0x7d}; + lwmqtt_string_t topic_filter_s7 = {10, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xca, 0x3e, 0x6d, 0x84, 0x1d, 0x39, 0x91, 0xf6, 0x89, 0x15, 0xed, 0x51}; + lwmqtt_string_t topic_filter_s8 = {12, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 26276, 9, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 10986 ["\211N\246\229\152\243\228\134\131\ETX\138\162\&1\EOT\161\135L\163\147\186\NUL"] [] +TEST(Unsubscribe311QCTest, Encode14) { + uint8_t pkt[] = {0xa2, 0x19, 0x2a, 0xea, 0x0, 0x15, 0xd3, 0x4e, 0xf6, 0xe5, 0x98, 0xf3, 0xe4, 0x86, + 0x83, 0x3, 0x8a, 0xa2, 0x31, 0x4, 0xa1, 0x87, 0x4c, 0xa3, 0x93, 0xba, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0xd3, 0x4e, 0xf6, 0xe5, 0x98, 0xf3, 0xe4, 0x86, 0x83, 0x3, 0x8a, + 0xa2, 0x31, 0x4, 0xa1, 0x87, 0x4c, 0xa3, 0x93, 0xba, 0x0}; + lwmqtt_string_t topic_filter_s0 = {21, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 10986, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 4312 +// ["\193\221H\191\161\206J\DC1\180\232?","P\140\182\141z\SOH\RS\130=\215\199\SI\253\203k\169","\230\174","\186c\168Ddi\167\152\197"] +// [] +TEST(Unsubscribe311QCTest, Encode15) { + uint8_t pkt[] = {0xa2, 0x30, 0x10, 0xd8, 0x0, 0xb, 0xc1, 0xdd, 0x48, 0xbf, 0xa1, 0xce, 0x4a, 0x11, 0xb4, 0xe8, 0x3f, + 0x0, 0x10, 0x50, 0x8c, 0xb6, 0x8d, 0x7a, 0x1, 0x1e, 0x82, 0x3d, 0xd7, 0xc7, 0xf, 0xfd, 0xcb, 0x6b, + 0xa9, 0x0, 0x2, 0xe6, 0xae, 0x0, 0x9, 0xba, 0x63, 0xa8, 0x44, 0x64, 0x69, 0xa7, 0x98, 0xc5}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[4]; + uint8_t topic_filter_s0_bytes[] = {0xc1, 0xdd, 0x48, 0xbf, 0xa1, 0xce, 0x4a, 0x11, 0xb4, 0xe8, 0x3f}; + lwmqtt_string_t topic_filter_s0 = {11, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x50, 0x8c, 0xb6, 0x8d, 0x7a, 0x1, 0x1e, 0x82, + 0x3d, 0xd7, 0xc7, 0xf, 0xfd, 0xcb, 0x6b, 0xa9}; + lwmqtt_string_t topic_filter_s1 = {16, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xe6, 0xae}; + lwmqtt_string_t topic_filter_s2 = {2, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xba, 0x63, 0xa8, 0x44, 0x64, 0x69, 0xa7, 0x98, 0xc5}; + lwmqtt_string_t topic_filter_s3 = {9, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 4312, 4, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 12998 ["\f\217\182 +\CAN\154)2\SO"] [] +TEST(Unsubscribe311QCTest, Encode16) { + uint8_t pkt[] = {0xa2, 0xe, 0x32, 0xc6, 0x0, 0xa, 0xc, 0xd9, 0xb6, 0x20, 0x2b, 0x18, 0x9a, 0x29, 0x32, 0xe}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0xc, 0xd9, 0xb6, 0x20, 0x2b, 0x18, 0x9a, 0x29, 0x32, 0xe}; + lwmqtt_string_t topic_filter_s0 = {10, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 12998, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 22695 +// ["\US=Q\130p\186\189<~\223\ETB\159\172\RS\"","\154\US\251v\173\148cR#\242{2&OX","","\207\130ja\252\230","w\208\209\&7\221\NAK\201\a\158"," +// \144\157t\SI\181?\209\217\255\240\SUB","\142v\242\219\199","\245v\238\\\DC3D\195\196\EM\a\252\245\160@F\f\226O\180\243YQ7\US\252\242","*\r#(\235\ETX3","\ETB\203\154\ENQ\171sq\ESC","\DC4w\144)\254\161\166\132@\214j\FSn\209A\DLE\fuHCo>\206fKmw"] +// [] +TEST(Unsubscribe311QCTest, Encode17) { + uint8_t pkt[] = {0xa2, 0x9a, 0x1, 0x58, 0xa7, 0x0, 0xf, 0x1f, 0x3d, 0x51, 0x82, 0x70, 0xba, 0xbd, 0x3c, 0x7e, + 0xdf, 0x17, 0x9f, 0xac, 0x1e, 0x22, 0x0, 0xf, 0x9a, 0x1f, 0xfb, 0x76, 0xad, 0x94, 0x63, 0x52, + 0x23, 0xf2, 0x7b, 0x32, 0x26, 0x4f, 0x58, 0x0, 0x0, 0x0, 0x6, 0xcf, 0x82, 0x6a, 0x61, 0xfc, + 0xe6, 0x0, 0x9, 0x77, 0xd0, 0xd1, 0x37, 0xdd, 0x15, 0xc9, 0x7, 0x9e, 0x0, 0xc, 0x20, 0x90, + 0x9d, 0x74, 0xf, 0xb5, 0x3f, 0xd1, 0xd9, 0xff, 0xf0, 0x1a, 0x0, 0x5, 0x8e, 0x76, 0xf2, 0xdb, + 0xc7, 0x0, 0x1a, 0xf5, 0x76, 0xee, 0x5c, 0x13, 0x44, 0xc3, 0xc4, 0x19, 0x7, 0xfc, 0xf5, 0xa0, + 0x40, 0x46, 0xc, 0xe2, 0x4f, 0xb4, 0xf3, 0x59, 0x51, 0x37, 0x1f, 0xfc, 0xf2, 0x0, 0x7, 0x2a, + 0xd, 0x23, 0x28, 0xeb, 0x3, 0x33, 0x0, 0x8, 0x17, 0xcb, 0x9a, 0x5, 0xab, 0x73, 0x71, 0x1b, + 0x0, 0x1b, 0x14, 0x77, 0x90, 0x29, 0xfe, 0xa1, 0xa6, 0x84, 0x40, 0xd6, 0x6a, 0x1c, 0x6e, 0xd1, + 0x41, 0x10, 0xc, 0x75, 0x48, 0x43, 0x6f, 0x3e, 0xce, 0x66, 0x4b, 0x6d, 0x77}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0x1f, 0x3d, 0x51, 0x82, 0x70, 0xba, 0xbd, 0x3c, + 0x7e, 0xdf, 0x17, 0x9f, 0xac, 0x1e, 0x22}; + lwmqtt_string_t topic_filter_s0 = {15, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x9a, 0x1f, 0xfb, 0x76, 0xad, 0x94, 0x63, 0x52, + 0x23, 0xf2, 0x7b, 0x32, 0x26, 0x4f, 0x58}; + lwmqtt_string_t topic_filter_s1 = {15, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0}; + lwmqtt_string_t topic_filter_s2 = {0, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xcf, 0x82, 0x6a, 0x61, 0xfc, 0xe6}; + lwmqtt_string_t topic_filter_s3 = {6, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x77, 0xd0, 0xd1, 0x37, 0xdd, 0x15, 0xc9, 0x7, 0x9e}; + lwmqtt_string_t topic_filter_s4 = {9, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x20, 0x90, 0x9d, 0x74, 0xf, 0xb5, 0x3f, 0xd1, 0xd9, 0xff, 0xf0, 0x1a}; + lwmqtt_string_t topic_filter_s5 = {12, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x8e, 0x76, 0xf2, 0xdb, 0xc7}; + lwmqtt_string_t topic_filter_s6 = {5, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xf5, 0x76, 0xee, 0x5c, 0x13, 0x44, 0xc3, 0xc4, 0x19, 0x7, 0xfc, 0xf5, 0xa0, + 0x40, 0x46, 0xc, 0xe2, 0x4f, 0xb4, 0xf3, 0x59, 0x51, 0x37, 0x1f, 0xfc, 0xf2}; + lwmqtt_string_t topic_filter_s7 = {26, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x2a, 0xd, 0x23, 0x28, 0xeb, 0x3, 0x33}; + lwmqtt_string_t topic_filter_s8 = {7, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x17, 0xcb, 0x9a, 0x5, 0xab, 0x73, 0x71, 0x1b}; + lwmqtt_string_t topic_filter_s9 = {8, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0x14, 0x77, 0x90, 0x29, 0xfe, 0xa1, 0xa6, 0x84, 0x40, + 0xd6, 0x6a, 0x1c, 0x6e, 0xd1, 0x41, 0x10, 0xc, 0x75, + 0x48, 0x43, 0x6f, 0x3e, 0xce, 0x66, 0x4b, 0x6d, 0x77}; + lwmqtt_string_t topic_filter_s10 = {27, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 22695, 11, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 6495 +// ["\144\187\SI\200\142y'N)^\214\NAK?\219\158\254U\230%dp\180","\136\DC3j\179'\202\200\245\NUL","\203'UwJf\198\144=(\SUB\t2\239\vn\ETX\STX\143\223\198\247","\203\207^\SUB\210\&1\139\213N\188\224\207\190\140","\ETB\201","w\233no\170\133\141i\142\ACK\178rv\222\&1\141\195\143U","12","","\181/"] +// [] +TEST(Unsubscribe311QCTest, Encode18) { + uint8_t pkt[] = {0xa2, 0x70, 0x19, 0x5f, 0x0, 0x16, 0x90, 0xbb, 0xf, 0xc8, 0x8e, 0x79, 0x27, 0x4e, 0x29, 0x5e, 0xd6, + 0x15, 0x3f, 0xdb, 0x9e, 0xfe, 0x55, 0xe6, 0x25, 0x64, 0x70, 0xb4, 0x0, 0x9, 0x88, 0x13, 0x6a, 0xb3, + 0x27, 0xca, 0xc8, 0xf5, 0x0, 0x0, 0x16, 0xcb, 0x27, 0x55, 0x77, 0x4a, 0x66, 0xc6, 0x90, 0x3d, 0x28, + 0x1a, 0x9, 0x32, 0xef, 0xb, 0x6e, 0x3, 0x2, 0x8f, 0xdf, 0xc6, 0xf7, 0x0, 0xe, 0xcb, 0xcf, 0x5e, + 0x1a, 0xd2, 0x31, 0x8b, 0xd5, 0x4e, 0xbc, 0xe0, 0xcf, 0xbe, 0x8c, 0x0, 0x2, 0x17, 0xc9, 0x0, 0x13, + 0x77, 0xe9, 0x6e, 0x6f, 0xaa, 0x85, 0x8d, 0x69, 0x8e, 0x6, 0xb2, 0x72, 0x76, 0xde, 0x31, 0x8d, 0xc3, + 0x8f, 0x55, 0x0, 0x2, 0x31, 0x32, 0x0, 0x0, 0x0, 0x2, 0xb5, 0x2f}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[9]; + uint8_t topic_filter_s0_bytes[] = {0x90, 0xbb, 0xf, 0xc8, 0x8e, 0x79, 0x27, 0x4e, 0x29, 0x5e, 0xd6, + 0x15, 0x3f, 0xdb, 0x9e, 0xfe, 0x55, 0xe6, 0x25, 0x64, 0x70, 0xb4}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x88, 0x13, 0x6a, 0xb3, 0x27, 0xca, 0xc8, 0xf5, 0x0}; + lwmqtt_string_t topic_filter_s1 = {9, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xcb, 0x27, 0x55, 0x77, 0x4a, 0x66, 0xc6, 0x90, 0x3d, 0x28, 0x1a, + 0x9, 0x32, 0xef, 0xb, 0x6e, 0x3, 0x2, 0x8f, 0xdf, 0xc6, 0xf7}; + lwmqtt_string_t topic_filter_s2 = {22, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xcb, 0xcf, 0x5e, 0x1a, 0xd2, 0x31, 0x8b, + 0xd5, 0x4e, 0xbc, 0xe0, 0xcf, 0xbe, 0x8c}; + lwmqtt_string_t topic_filter_s3 = {14, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x17, 0xc9}; + lwmqtt_string_t topic_filter_s4 = {2, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x77, 0xe9, 0x6e, 0x6f, 0xaa, 0x85, 0x8d, 0x69, 0x8e, 0x6, + 0xb2, 0x72, 0x76, 0xde, 0x31, 0x8d, 0xc3, 0x8f, 0x55}; + lwmqtt_string_t topic_filter_s5 = {19, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x31, 0x32}; + lwmqtt_string_t topic_filter_s6 = {2, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0}; + lwmqtt_string_t topic_filter_s7 = {0, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xb5, 0x2f}; + lwmqtt_string_t topic_filter_s8 = {2, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 6495, 9, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 21456 +// ["i\172\235\176yA\168\222\209\r","\207\189\131+\244\149$\n\152\138]\252t\DLE\251\212\SUB\188tMDIz\190>\188ZB","#\r\157z\r6\USl\SUB\142\142\217\US\182f\213\161\240","i\167c\137+A\NAKg\221\&0\217\213'\ESC]mc}\222\157\220>","\144\177\&2@\185\r\242\&08N\243\238\144-\SO\146\248e\148\231\FS\196\ETBk\246\248\167\DC2","\129"] +// [] +TEST(Unsubscribe311QCTest, Encode19) { + uint8_t pkt[] = {0xa2, 0x79, 0x53, 0xd0, 0x0, 0xa, 0x69, 0xac, 0xeb, 0xb0, 0x79, 0x41, 0xa8, 0xde, 0xd1, 0xd, + 0x0, 0x1c, 0xcf, 0xbd, 0x83, 0x2b, 0xf4, 0x95, 0x24, 0xa, 0x98, 0x8a, 0x5d, 0xfc, 0x74, 0x10, + 0xfb, 0xd4, 0x1a, 0xbc, 0x74, 0x4d, 0x44, 0x49, 0x7a, 0xbe, 0x3e, 0xbc, 0x5a, 0x42, 0x0, 0x12, + 0x23, 0xd, 0x9d, 0x7a, 0xd, 0x36, 0x1f, 0x6c, 0x1a, 0x8e, 0x8e, 0xd9, 0x1f, 0xb6, 0x66, 0xd5, + 0xa1, 0xf0, 0x0, 0x16, 0x69, 0xa7, 0x63, 0x89, 0x2b, 0x41, 0x15, 0x67, 0xdd, 0x30, 0xd9, 0xd5, + 0x27, 0x1b, 0x5d, 0x6d, 0x63, 0x7d, 0xde, 0x9d, 0xdc, 0x3e, 0x0, 0x1c, 0x90, 0xb1, 0x32, 0x40, + 0xb9, 0xd, 0xf2, 0x30, 0x38, 0x4e, 0xf3, 0xee, 0x90, 0x2d, 0xe, 0x92, 0xf8, 0x65, 0x94, 0xe7, + 0x1c, 0xc4, 0x17, 0x6b, 0xf6, 0xf8, 0xa7, 0x12, 0x0, 0x1, 0x81}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[6]; + uint8_t topic_filter_s0_bytes[] = {0x69, 0xac, 0xeb, 0xb0, 0x79, 0x41, 0xa8, 0xde, 0xd1, 0xd}; + lwmqtt_string_t topic_filter_s0 = {10, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xcf, 0xbd, 0x83, 0x2b, 0xf4, 0x95, 0x24, 0xa, 0x98, 0x8a, + 0x5d, 0xfc, 0x74, 0x10, 0xfb, 0xd4, 0x1a, 0xbc, 0x74, 0x4d, + 0x44, 0x49, 0x7a, 0xbe, 0x3e, 0xbc, 0x5a, 0x42}; + lwmqtt_string_t topic_filter_s1 = {28, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x23, 0xd, 0x9d, 0x7a, 0xd, 0x36, 0x1f, 0x6c, 0x1a, + 0x8e, 0x8e, 0xd9, 0x1f, 0xb6, 0x66, 0xd5, 0xa1, 0xf0}; + lwmqtt_string_t topic_filter_s2 = {18, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x69, 0xa7, 0x63, 0x89, 0x2b, 0x41, 0x15, 0x67, 0xdd, 0x30, 0xd9, + 0xd5, 0x27, 0x1b, 0x5d, 0x6d, 0x63, 0x7d, 0xde, 0x9d, 0xdc, 0x3e}; + lwmqtt_string_t topic_filter_s3 = {22, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x90, 0xb1, 0x32, 0x40, 0xb9, 0xd, 0xf2, 0x30, 0x38, 0x4e, + 0xf3, 0xee, 0x90, 0x2d, 0xe, 0x92, 0xf8, 0x65, 0x94, 0xe7, + 0x1c, 0xc4, 0x17, 0x6b, 0xf6, 0xf8, 0xa7, 0x12}; + lwmqtt_string_t topic_filter_s4 = {28, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x81}; + lwmqtt_string_t topic_filter_s5 = {1, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 21456, 6, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 1638 +// ["I\172\254l\194\132\150\DC1\CAN\173\152\&6ms\215\182\145~\176\NAK(\255p\163\238G\163\DC4\164"] [] +TEST(Unsubscribe311QCTest, Encode20) { + uint8_t pkt[] = {0xa2, 0x21, 0x6, 0x66, 0x0, 0x1d, 0x49, 0xac, 0xfe, 0x6c, 0xc2, 0x84, + 0x96, 0x11, 0x18, 0xad, 0x98, 0x36, 0x6d, 0x73, 0xd7, 0xb6, 0x91, 0x7e, + 0xb0, 0x15, 0x28, 0xff, 0x70, 0xa3, 0xee, 0x47, 0xa3, 0x14, 0xa4}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x49, 0xac, 0xfe, 0x6c, 0xc2, 0x84, 0x96, 0x11, 0x18, 0xad, + 0x98, 0x36, 0x6d, 0x73, 0xd7, 0xb6, 0x91, 0x7e, 0xb0, 0x15, + 0x28, 0xff, 0x70, 0xa3, 0xee, 0x47, 0xa3, 0x14, 0xa4}; + lwmqtt_string_t topic_filter_s0 = {29, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 1638, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 30931 +// ["\242\153y5V\186\NUL\184\153\206\140\ESC\128Z","\217J\203\FS\129\209\190\129\183\211N\167\STX\EOT\145\216\246\204\195\208","\228e\179_t\DC2\ETX\208\189\199\&7!\150\135\155{\150.4Y","T\229\NAK]\171\166\141\193*\174\ESC\ESC?\198\242\\G\242\209\NULRL\DEL\EM","\227\251","","\247\227>\DC1?\SIm\254f\225","R\194\196\DEL\217j\241\169\&6f\155"] +// [] +TEST(Unsubscribe311QCTest, Encode21) { + uint8_t pkt[] = {0xa2, 0x77, 0x78, 0xd3, 0x0, 0xe, 0xf2, 0x99, 0x79, 0x35, 0x56, 0xba, 0x0, 0xb8, 0x99, 0xce, + 0x8c, 0x1b, 0x80, 0x5a, 0x0, 0x14, 0xd9, 0x4a, 0xcb, 0x1c, 0x81, 0xd1, 0xbe, 0x81, 0xb7, 0xd3, + 0x4e, 0xa7, 0x2, 0x4, 0x91, 0xd8, 0xf6, 0xcc, 0xc3, 0xd0, 0x0, 0x14, 0xe4, 0x65, 0xb3, 0x5f, + 0x74, 0x12, 0x3, 0xd0, 0xbd, 0xc7, 0x37, 0x21, 0x96, 0x87, 0x9b, 0x7b, 0x96, 0x2e, 0x34, 0x59, + 0x0, 0x18, 0x54, 0xe5, 0x15, 0x5d, 0xab, 0xa6, 0x8d, 0xc1, 0x2a, 0xae, 0x1b, 0x1b, 0x3f, 0xc6, + 0xf2, 0x5c, 0x47, 0xf2, 0xd1, 0x0, 0x52, 0x4c, 0x7f, 0x19, 0x0, 0x2, 0xe3, 0xfb, 0x0, 0x0, + 0x0, 0xa, 0xf7, 0xe3, 0x3e, 0x11, 0x3f, 0xf, 0x6d, 0xfe, 0x66, 0xe1, 0x0, 0xb, 0x52, 0xc2, + 0xc4, 0x7f, 0xd9, 0x6a, 0xf1, 0xa9, 0x36, 0x66, 0x9b}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[8]; + uint8_t topic_filter_s0_bytes[] = {0xf2, 0x99, 0x79, 0x35, 0x56, 0xba, 0x0, 0xb8, 0x99, 0xce, 0x8c, 0x1b, 0x80, 0x5a}; + lwmqtt_string_t topic_filter_s0 = {14, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xd9, 0x4a, 0xcb, 0x1c, 0x81, 0xd1, 0xbe, 0x81, 0xb7, 0xd3, + 0x4e, 0xa7, 0x2, 0x4, 0x91, 0xd8, 0xf6, 0xcc, 0xc3, 0xd0}; + lwmqtt_string_t topic_filter_s1 = {20, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xe4, 0x65, 0xb3, 0x5f, 0x74, 0x12, 0x3, 0xd0, 0xbd, 0xc7, + 0x37, 0x21, 0x96, 0x87, 0x9b, 0x7b, 0x96, 0x2e, 0x34, 0x59}; + lwmqtt_string_t topic_filter_s2 = {20, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x54, 0xe5, 0x15, 0x5d, 0xab, 0xa6, 0x8d, 0xc1, 0x2a, 0xae, 0x1b, 0x1b, + 0x3f, 0xc6, 0xf2, 0x5c, 0x47, 0xf2, 0xd1, 0x0, 0x52, 0x4c, 0x7f, 0x19}; + lwmqtt_string_t topic_filter_s3 = {24, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xe3, 0xfb}; + lwmqtt_string_t topic_filter_s4 = {2, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0}; + lwmqtt_string_t topic_filter_s5 = {0, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xf7, 0xe3, 0x3e, 0x11, 0x3f, 0xf, 0x6d, 0xfe, 0x66, 0xe1}; + lwmqtt_string_t topic_filter_s6 = {10, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x52, 0xc2, 0xc4, 0x7f, 0xd9, 0x6a, 0xf1, 0xa9, 0x36, 0x66, 0x9b}; + lwmqtt_string_t topic_filter_s7 = {11, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 30931, 8, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 14609 +// ["\STX\186","\216\232'\187\247AC\149\141\&7(\219\ACK\245V\NUL\176q\225","\146\EOTs\135\223\183f\130\217i\200\252%\195\232L\233\STX\202\249\219'#\145\182\197","0]\240\US\255\201i\203.]|\DC3\173e\v","\174!\202\147\162\ESC\200\211\216\194WF\212N{'!^~2\ACKQ\157j\228\244","\163x\"\164\183\175$]\242\129\245'\164\\E","*W\240\217\DC1%D\193S\240\168\186\147\190\153$\f\213\182De\167\239\156\227"] +// [] +TEST(Unsubscribe311QCTest, Encode22) { + uint8_t pkt[] = {0xa2, 0x90, 0x1, 0x39, 0x11, 0x0, 0x2, 0x2, 0xba, 0x0, 0x13, 0xd8, 0xe8, 0x27, 0xbb, 0xf7, 0x41, + 0x43, 0x95, 0x8d, 0x37, 0x28, 0xdb, 0x6, 0xf5, 0x56, 0x0, 0xb0, 0x71, 0xe1, 0x0, 0x1a, 0x92, 0x4, + 0x73, 0x87, 0xdf, 0xb7, 0x66, 0x82, 0xd9, 0x69, 0xc8, 0xfc, 0x25, 0xc3, 0xe8, 0x4c, 0xe9, 0x2, 0xca, + 0xf9, 0xdb, 0x27, 0x23, 0x91, 0xb6, 0xc5, 0x0, 0xf, 0x30, 0x5d, 0xf0, 0x1f, 0xff, 0xc9, 0x69, 0xcb, + 0x2e, 0x5d, 0x7c, 0x13, 0xad, 0x65, 0xb, 0x0, 0x1a, 0xae, 0x21, 0xca, 0x93, 0xa2, 0x1b, 0xc8, 0xd3, + 0xd8, 0xc2, 0x57, 0x46, 0xd4, 0x4e, 0x7b, 0x27, 0x21, 0x5e, 0x7e, 0x32, 0x6, 0x51, 0x9d, 0x6a, 0xe4, + 0xf4, 0x0, 0xf, 0xa3, 0x78, 0x22, 0xa4, 0xb7, 0xaf, 0x24, 0x5d, 0xf2, 0x81, 0xf5, 0x27, 0xa4, 0x5c, + 0x45, 0x0, 0x19, 0x2a, 0x57, 0xf0, 0xd9, 0x11, 0x25, 0x44, 0xc1, 0x53, 0xf0, 0xa8, 0xba, 0x93, 0xbe, + 0x99, 0x24, 0xc, 0xd5, 0xb6, 0x44, 0x65, 0xa7, 0xef, 0x9c, 0xe3}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0x2, 0xba}; + lwmqtt_string_t topic_filter_s0 = {2, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xd8, 0xe8, 0x27, 0xbb, 0xf7, 0x41, 0x43, 0x95, 0x8d, 0x37, + 0x28, 0xdb, 0x6, 0xf5, 0x56, 0x0, 0xb0, 0x71, 0xe1}; + lwmqtt_string_t topic_filter_s1 = {19, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x92, 0x4, 0x73, 0x87, 0xdf, 0xb7, 0x66, 0x82, 0xd9, 0x69, 0xc8, 0xfc, 0x25, + 0xc3, 0xe8, 0x4c, 0xe9, 0x2, 0xca, 0xf9, 0xdb, 0x27, 0x23, 0x91, 0xb6, 0xc5}; + lwmqtt_string_t topic_filter_s2 = {26, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x30, 0x5d, 0xf0, 0x1f, 0xff, 0xc9, 0x69, 0xcb, + 0x2e, 0x5d, 0x7c, 0x13, 0xad, 0x65, 0xb}; + lwmqtt_string_t topic_filter_s3 = {15, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xae, 0x21, 0xca, 0x93, 0xa2, 0x1b, 0xc8, 0xd3, 0xd8, 0xc2, 0x57, 0x46, 0xd4, + 0x4e, 0x7b, 0x27, 0x21, 0x5e, 0x7e, 0x32, 0x6, 0x51, 0x9d, 0x6a, 0xe4, 0xf4}; + lwmqtt_string_t topic_filter_s4 = {26, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xa3, 0x78, 0x22, 0xa4, 0xb7, 0xaf, 0x24, 0x5d, + 0xf2, 0x81, 0xf5, 0x27, 0xa4, 0x5c, 0x45}; + lwmqtt_string_t topic_filter_s5 = {15, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x2a, 0x57, 0xf0, 0xd9, 0x11, 0x25, 0x44, 0xc1, 0x53, 0xf0, 0xa8, 0xba, 0x93, + 0xbe, 0x99, 0x24, 0xc, 0xd5, 0xb6, 0x44, 0x65, 0xa7, 0xef, 0x9c, 0xe3}; + lwmqtt_string_t topic_filter_s6 = {25, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 14609, 7, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 4540 +// ["","","\222\229\236","\133\214\163","F\186I\201-\n\246\DC2\234\245\156l\132o\252[\142t\210o\NAK\221\&6F\150\241","\241\183\179\&7\145]\130\189/",",P\144\130\178\b\202\SYNe\145\240 +// f\158\&2\CAN","\234c\GS\SIR\185\&75\159"] [] +TEST(Unsubscribe311QCTest, Encode23) { + uint8_t pkt[] = {0xa2, 0x54, 0x11, 0xbc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0xde, 0xe5, 0xec, 0x0, 0x3, + 0x85, 0xd6, 0xa3, 0x0, 0x1a, 0x46, 0xba, 0x49, 0xc9, 0x2d, 0xa, 0xf6, 0x12, 0xea, 0xf5, + 0x9c, 0x6c, 0x84, 0x6f, 0xfc, 0x5b, 0x8e, 0x74, 0xd2, 0x6f, 0x15, 0xdd, 0x36, 0x46, 0x96, + 0xf1, 0x0, 0x9, 0xf1, 0xb7, 0xb3, 0x37, 0x91, 0x5d, 0x82, 0xbd, 0x2f, 0x0, 0x10, 0x2c, + 0x50, 0x90, 0x82, 0xb2, 0x8, 0xca, 0x16, 0x65, 0x91, 0xf0, 0x20, 0x66, 0x9e, 0x32, 0x18, + 0x0, 0x9, 0xea, 0x63, 0x1d, 0xf, 0x52, 0xb9, 0x37, 0x35, 0x9f}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[8]; + uint8_t topic_filter_s0_bytes[] = {0}; + lwmqtt_string_t topic_filter_s0 = {0, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0}; + lwmqtt_string_t topic_filter_s1 = {0, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xde, 0xe5, 0xec}; + lwmqtt_string_t topic_filter_s2 = {3, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x85, 0xd6, 0xa3}; + lwmqtt_string_t topic_filter_s3 = {3, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x46, 0xba, 0x49, 0xc9, 0x2d, 0xa, 0xf6, 0x12, 0xea, 0xf5, 0x9c, 0x6c, 0x84, + 0x6f, 0xfc, 0x5b, 0x8e, 0x74, 0xd2, 0x6f, 0x15, 0xdd, 0x36, 0x46, 0x96, 0xf1}; + lwmqtt_string_t topic_filter_s4 = {26, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xf1, 0xb7, 0xb3, 0x37, 0x91, 0x5d, 0x82, 0xbd, 0x2f}; + lwmqtt_string_t topic_filter_s5 = {9, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x2c, 0x50, 0x90, 0x82, 0xb2, 0x8, 0xca, 0x16, + 0x65, 0x91, 0xf0, 0x20, 0x66, 0x9e, 0x32, 0x18}; + lwmqtt_string_t topic_filter_s6 = {16, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xea, 0x63, 0x1d, 0xf, 0x52, 0xb9, 0x37, 0x35, 0x9f}; + lwmqtt_string_t topic_filter_s7 = {9, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 4540, 8, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 16569 +// ["","\170&\222\191\190a\189\220\226\176\DC1|\130\NAK\210\227\141\218\168\DEL\160\156\202\131\134\164"] [] +TEST(Unsubscribe311QCTest, Encode24) { + uint8_t pkt[] = {0xa2, 0x20, 0x40, 0xb9, 0x0, 0x0, 0x0, 0x1a, 0xaa, 0x26, 0xde, 0xbf, + 0xbe, 0x61, 0xbd, 0xdc, 0xe2, 0xb0, 0x11, 0x7c, 0x82, 0x15, 0xd2, 0xe3, + 0x8d, 0xda, 0xa8, 0x7f, 0xa0, 0x9c, 0xca, 0x83, 0x86, 0xa4}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[2]; + uint8_t topic_filter_s0_bytes[] = {0}; + lwmqtt_string_t topic_filter_s0 = {0, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xaa, 0x26, 0xde, 0xbf, 0xbe, 0x61, 0xbd, 0xdc, 0xe2, 0xb0, 0x11, 0x7c, 0x82, + 0x15, 0xd2, 0xe3, 0x8d, 0xda, 0xa8, 0x7f, 0xa0, 0x9c, 0xca, 0x83, 0x86, 0xa4}; + lwmqtt_string_t topic_filter_s1 = {26, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 16569, 2, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 14606 +// [".\DEL\196I\165\SIb1R\244ju\238\DC1\166","3\222\158W\247\213i\STXa","j.\\","G\168\128\184kL\181\SOH2J!\DC4F\DEL\198N+2z\nU\DC4\140.\154\222\SI\137\237","K\213\&7"] +// [] +TEST(Unsubscribe311QCTest, Encode25) { + uint8_t pkt[] = {0xa2, 0x47, 0x39, 0xe, 0x0, 0xf, 0x2e, 0x7f, 0xc4, 0x49, 0xa5, 0xf, 0x62, 0x31, 0x52, + 0xf4, 0x6a, 0x75, 0xee, 0x11, 0xa6, 0x0, 0x9, 0x33, 0xde, 0x9e, 0x57, 0xf7, 0xd5, 0x69, + 0x2, 0x61, 0x0, 0x3, 0x6a, 0x2e, 0x5c, 0x0, 0x1d, 0x47, 0xa8, 0x80, 0xb8, 0x6b, 0x4c, + 0xb5, 0x1, 0x32, 0x4a, 0x21, 0x14, 0x46, 0x7f, 0xc6, 0x4e, 0x2b, 0x32, 0x7a, 0xa, 0x55, + 0x14, 0x8c, 0x2e, 0x9a, 0xde, 0xf, 0x89, 0xed, 0x0, 0x3, 0x4b, 0xd5, 0x37}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0x2e, 0x7f, 0xc4, 0x49, 0xa5, 0xf, 0x62, 0x31, + 0x52, 0xf4, 0x6a, 0x75, 0xee, 0x11, 0xa6}; + lwmqtt_string_t topic_filter_s0 = {15, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x33, 0xde, 0x9e, 0x57, 0xf7, 0xd5, 0x69, 0x2, 0x61}; + lwmqtt_string_t topic_filter_s1 = {9, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x6a, 0x2e, 0x5c}; + lwmqtt_string_t topic_filter_s2 = {3, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x47, 0xa8, 0x80, 0xb8, 0x6b, 0x4c, 0xb5, 0x1, 0x32, 0x4a, + 0x21, 0x14, 0x46, 0x7f, 0xc6, 0x4e, 0x2b, 0x32, 0x7a, 0xa, + 0x55, 0x14, 0x8c, 0x2e, 0x9a, 0xde, 0xf, 0x89, 0xed}; + lwmqtt_string_t topic_filter_s3 = {29, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x4b, 0xd5, 0x37}; + lwmqtt_string_t topic_filter_s4 = {3, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 14606, 5, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 14000 +// ["","l\209\US\STX\SId","\186\198#\203t@D","\179\177g\225l","y\192\ESC\206\153\GSTVb\180\254\139\221\&7\255\219\208\234\DC3\240\137\202tp\SYN\158\149","}\b\152\173Sm\225\172\173{#\199\150N\170\136\217S\229\&7\250\155\168\180\134\181","\133q","\216\211GO\136w\142\SI","\135\212\152\253\ETX\232\227\216\DLE\245\131QC-\ETB2&\237I\219{\132\&20|A\148","&\227\176:l([\140;\250\179\157\b\166\137\242\231\EOTw\164\139","\204Q\203\251\SOHMX\193$\139\&12\178y\195V{\206q\FScT"] +// [] +TEST(Unsubscribe311QCTest, Encode27) { + uint8_t pkt[] = {0xa2, 0xe6, 0x1, 0x75, 0x7, 0x0, 0xc, 0x0, 0x76, 0x5f, 0x47, 0x29, 0xdf, 0x6f, 0x38, 0xf1, 0xf0, + 0xa5, 0xff, 0x0, 0x1a, 0x1e, 0xb6, 0x64, 0x1c, 0x72, 0xa6, 0x4, 0xbd, 0x9, 0xf4, 0xab, 0x77, 0xed, + 0xf7, 0xa2, 0x71, 0xc8, 0x4b, 0x6f, 0x29, 0xe, 0xbb, 0xd, 0x1f, 0x36, 0x52, 0x0, 0x6, 0x8d, 0x28, + 0xa5, 0x2f, 0xd9, 0x38, 0x0, 0x1d, 0x0, 0x4, 0xde, 0x14, 0x6c, 0x6b, 0xab, 0x5a, 0xde, 0xd0, 0x9, + 0x31, 0xce, 0x7d, 0x29, 0xd8, 0xb0, 0xf1, 0x1a, 0xe2, 0x29, 0x99, 0x7f, 0xbc, 0x36, 0x57, 0x76, 0xb0, + 0x3e, 0x0, 0x1b, 0x79, 0xc0, 0x1b, 0xce, 0x99, 0x1d, 0x54, 0x56, 0x62, 0xb4, 0xfe, 0x8b, 0xdd, 0x37, + 0xff, 0xdb, 0xd0, 0xea, 0x13, 0xf0, 0x89, 0xca, 0x74, 0x70, 0x16, 0x9e, 0x95, 0x0, 0x1a, 0x7d, 0x8, + 0x98, 0xad, 0x53, 0x6d, 0xe1, 0xac, 0xad, 0x7b, 0x23, 0xc7, 0x96, 0x4e, 0xaa, 0x88, 0xd9, 0x53, 0xe5, + 0x37, 0xfa, 0x9b, 0xa8, 0xb4, 0x86, 0xb5, 0x0, 0x2, 0x85, 0x71, 0x0, 0x8, 0xd8, 0xd3, 0x47, 0x4f, + 0x88, 0x77, 0x8e, 0xf, 0x0, 0x1b, 0x87, 0xd4, 0x98, 0xfd, 0x3, 0xe8, 0xe3, 0xd8, 0x10, 0xf5, 0x83, + 0x51, 0x43, 0x2d, 0x17, 0x32, 0x26, 0xed, 0x49, 0xdb, 0x7b, 0x84, 0x32, 0x30, 0x7c, 0x41, 0x94, 0x0, + 0x15, 0x26, 0xe3, 0xb0, 0x3a, 0x6c, 0x28, 0x5b, 0x8c, 0x3b, 0xfa, 0xb3, 0x9d, 0x8, 0xa6, 0x89, 0xf2, + 0xe7, 0x4, 0x77, 0xa4, 0x8b, 0x0, 0x16, 0xcc, 0x51, 0xcb, 0xfb, 0x1, 0x4d, 0x58, 0xc1, 0x24, 0x8b, + 0x31, 0x32, 0xb2, 0x79, 0xc3, 0x56, 0x7b, 0xce, 0x71, 0x1c, 0x63, 0x54}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0x0, 0x76, 0x5f, 0x47, 0x29, 0xdf, 0x6f, 0x38, 0xf1, 0xf0, 0xa5, 0xff}; + lwmqtt_string_t topic_filter_s0 = {12, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x1e, 0xb6, 0x64, 0x1c, 0x72, 0xa6, 0x4, 0xbd, 0x9, 0xf4, 0xab, 0x77, 0xed, + 0xf7, 0xa2, 0x71, 0xc8, 0x4b, 0x6f, 0x29, 0xe, 0xbb, 0xd, 0x1f, 0x36, 0x52}; + lwmqtt_string_t topic_filter_s1 = {26, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x8d, 0x28, 0xa5, 0x2f, 0xd9, 0x38}; + lwmqtt_string_t topic_filter_s2 = {6, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x0, 0x4, 0xde, 0x14, 0x6c, 0x6b, 0xab, 0x5a, 0xde, 0xd0, + 0x9, 0x31, 0xce, 0x7d, 0x29, 0xd8, 0xb0, 0xf1, 0x1a, 0xe2, + 0x29, 0x99, 0x7f, 0xbc, 0x36, 0x57, 0x76, 0xb0, 0x3e}; + lwmqtt_string_t topic_filter_s3 = {29, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x79, 0xc0, 0x1b, 0xce, 0x99, 0x1d, 0x54, 0x56, 0x62, 0xb4, 0xfe, 0x8b, 0xdd, 0x37, + 0xff, 0xdb, 0xd0, 0xea, 0x13, 0xf0, 0x89, 0xca, 0x74, 0x70, 0x16, 0x9e, 0x95}; + lwmqtt_string_t topic_filter_s4 = {27, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x7d, 0x8, 0x98, 0xad, 0x53, 0x6d, 0xe1, 0xac, 0xad, 0x7b, 0x23, 0xc7, 0x96, + 0x4e, 0xaa, 0x88, 0xd9, 0x53, 0xe5, 0x37, 0xfa, 0x9b, 0xa8, 0xb4, 0x86, 0xb5}; + lwmqtt_string_t topic_filter_s5 = {26, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x85, 0x71}; + lwmqtt_string_t topic_filter_s6 = {2, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xd8, 0xd3, 0x47, 0x4f, 0x88, 0x77, 0x8e, 0xf}; + lwmqtt_string_t topic_filter_s7 = {8, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x87, 0xd4, 0x98, 0xfd, 0x3, 0xe8, 0xe3, 0xd8, 0x10, 0xf5, 0x83, 0x51, 0x43, 0x2d, + 0x17, 0x32, 0x26, 0xed, 0x49, 0xdb, 0x7b, 0x84, 0x32, 0x30, 0x7c, 0x41, 0x94}; + lwmqtt_string_t topic_filter_s8 = {27, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x26, 0xe3, 0xb0, 0x3a, 0x6c, 0x28, 0x5b, 0x8c, 0x3b, 0xfa, 0xb3, + 0x9d, 0x8, 0xa6, 0x89, 0xf2, 0xe7, 0x4, 0x77, 0xa4, 0x8b}; + lwmqtt_string_t topic_filter_s9 = {21, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0xcc, 0x51, 0xcb, 0xfb, 0x1, 0x4d, 0x58, 0xc1, 0x24, 0x8b, 0x31, + 0x32, 0xb2, 0x79, 0xc3, 0x56, 0x7b, 0xce, 0x71, 0x1c, 0x63, 0x54}; + lwmqtt_string_t topic_filter_s10 = {22, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 29959, 11, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 5839 [""] [] +TEST(Unsubscribe311QCTest, Encode28) { + uint8_t pkt[] = {0xa2, 0x4, 0x16, 0xcf, 0x0, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0}; + lwmqtt_string_t topic_filter_s0 = {0, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 5839, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 8093 +// ["\140\244F\161","k5\NAK\128\246yah\170\t","\154\DC2\209)BN\179P\ETX>:\DC1\174\174\143HZZ","\137\208\145\SO\\\207\ETB\163","\181w4\223bZ\155\243A\162\248\162p\158\190\162\&8\132\v\163\&2\238\"\206k6\132","C\SUB\243\t\186\&0\166\DLE\211\148H\185\196\132\221\228\190%\144@~\243\255","G*","\FS\201\240\&9s\203\239\199\205d","V\\\216CA(\177f\229\172\150R\176r-\217\135","\215\217\143Yxc2f\\\168\229\ETX\SUB\214\207\DEL!\198\223\131%\147\r\ESC\199l8|\159\181"] +// [] +TEST(Unsubscribe311QCTest, Encode29) { + uint8_t pkt[] = {0xa2, 0xab, 0x1, 0x1f, 0x9d, 0x0, 0x4, 0x8c, 0xf4, 0x46, 0xa1, 0x0, 0xa, 0x6b, 0x35, 0x15, + 0x80, 0xf6, 0x79, 0x61, 0x68, 0xaa, 0x9, 0x0, 0x12, 0x9a, 0x12, 0xd1, 0x29, 0x42, 0x4e, 0xb3, + 0x50, 0x3, 0x3e, 0x3a, 0x11, 0xae, 0xae, 0x8f, 0x48, 0x5a, 0x5a, 0x0, 0x8, 0x89, 0xd0, 0x91, + 0xe, 0x5c, 0xcf, 0x17, 0xa3, 0x0, 0x1b, 0xb5, 0x77, 0x34, 0xdf, 0x62, 0x5a, 0x9b, 0xf3, 0x41, + 0xa2, 0xf8, 0xa2, 0x70, 0x9e, 0xbe, 0xa2, 0x38, 0x84, 0xb, 0xa3, 0x32, 0xee, 0x22, 0xce, 0x6b, + 0x36, 0x84, 0x0, 0x17, 0x43, 0x1a, 0xf3, 0x9, 0xba, 0x30, 0xa6, 0x10, 0xd3, 0x94, 0x48, 0xb9, + 0xc4, 0x84, 0xdd, 0xe4, 0xbe, 0x25, 0x90, 0x40, 0x7e, 0xf3, 0xff, 0x0, 0x2, 0x47, 0x2a, 0x0, + 0xa, 0x1c, 0xc9, 0xf0, 0x39, 0x73, 0xcb, 0xef, 0xc7, 0xcd, 0x64, 0x0, 0x11, 0x56, 0x5c, 0xd8, + 0x43, 0x41, 0x28, 0xb1, 0x66, 0xe5, 0xac, 0x96, 0x52, 0xb0, 0x72, 0x2d, 0xd9, 0x87, 0x0, 0x1e, + 0xd7, 0xd9, 0x8f, 0x59, 0x78, 0x63, 0x32, 0x66, 0x5c, 0xa8, 0xe5, 0x3, 0x1a, 0xd6, 0xcf, 0x7f, + 0x21, 0xc6, 0xdf, 0x83, 0x25, 0x93, 0xd, 0x1b, 0xc7, 0x6c, 0x38, 0x7c, 0x9f, 0xb5}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[10]; + uint8_t topic_filter_s0_bytes[] = {0x8c, 0xf4, 0x46, 0xa1}; + lwmqtt_string_t topic_filter_s0 = {4, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x6b, 0x35, 0x15, 0x80, 0xf6, 0x79, 0x61, 0x68, 0xaa, 0x9}; + lwmqtt_string_t topic_filter_s1 = {10, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x9a, 0x12, 0xd1, 0x29, 0x42, 0x4e, 0xb3, 0x50, 0x3, + 0x3e, 0x3a, 0x11, 0xae, 0xae, 0x8f, 0x48, 0x5a, 0x5a}; + lwmqtt_string_t topic_filter_s2 = {18, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x89, 0xd0, 0x91, 0xe, 0x5c, 0xcf, 0x17, 0xa3}; + lwmqtt_string_t topic_filter_s3 = {8, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xb5, 0x77, 0x34, 0xdf, 0x62, 0x5a, 0x9b, 0xf3, 0x41, 0xa2, 0xf8, 0xa2, 0x70, 0x9e, + 0xbe, 0xa2, 0x38, 0x84, 0xb, 0xa3, 0x32, 0xee, 0x22, 0xce, 0x6b, 0x36, 0x84}; + lwmqtt_string_t topic_filter_s4 = {27, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x43, 0x1a, 0xf3, 0x9, 0xba, 0x30, 0xa6, 0x10, 0xd3, 0x94, 0x48, 0xb9, + 0xc4, 0x84, 0xdd, 0xe4, 0xbe, 0x25, 0x90, 0x40, 0x7e, 0xf3, 0xff}; + lwmqtt_string_t topic_filter_s5 = {23, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x47, 0x2a}; + lwmqtt_string_t topic_filter_s6 = {2, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x1c, 0xc9, 0xf0, 0x39, 0x73, 0xcb, 0xef, 0xc7, 0xcd, 0x64}; + lwmqtt_string_t topic_filter_s7 = {10, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x56, 0x5c, 0xd8, 0x43, 0x41, 0x28, 0xb1, 0x66, 0xe5, + 0xac, 0x96, 0x52, 0xb0, 0x72, 0x2d, 0xd9, 0x87}; + lwmqtt_string_t topic_filter_s8 = {17, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0xd7, 0xd9, 0x8f, 0x59, 0x78, 0x63, 0x32, 0x66, 0x5c, 0xa8, + 0xe5, 0x3, 0x1a, 0xd6, 0xcf, 0x7f, 0x21, 0xc6, 0xdf, 0x83, + 0x25, 0x93, 0xd, 0x1b, 0xc7, 0x6c, 0x38, 0x7c, 0x9f, 0xb5}; + lwmqtt_string_t topic_filter_s9 = {30, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 8093, 10, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 18954 +// ["\218\204e\192\250\149/\ENQMK","\241\DLE=","\177\222\GS\183\ETB","","\SUBg^\150\156\ETBMG\237\&0\244\220/\154b\199\DC1\210\161\230\201\129\206\180@","\187","\211\175D\131\203\225\203-\177g&\DC3\RS\214\&1\142\161\&0\ACK\184\217V9f","\238\SI\238\aY\177\140\244\140\203\135\206\131\171\199"] +// [] +TEST(Unsubscribe311QCTest, Encode30) { + uint8_t pkt[] = {0xa2, 0x65, 0x4a, 0xa, 0x0, 0xa, 0xda, 0xcc, 0x65, 0xc0, 0xfa, 0x95, 0x2f, 0x5, 0x4d, + 0x4b, 0x0, 0x3, 0xf1, 0x10, 0x3d, 0x0, 0x5, 0xb1, 0xde, 0x1d, 0xb7, 0x17, 0x0, 0x0, + 0x0, 0x19, 0x1a, 0x67, 0x5e, 0x96, 0x9c, 0x17, 0x4d, 0x47, 0xed, 0x30, 0xf4, 0xdc, 0x2f, + 0x9a, 0x62, 0xc7, 0x11, 0xd2, 0xa1, 0xe6, 0xc9, 0x81, 0xce, 0xb4, 0x40, 0x0, 0x1, 0xbb, + 0x0, 0x18, 0xd3, 0xaf, 0x44, 0x83, 0xcb, 0xe1, 0xcb, 0x2d, 0xb1, 0x67, 0x26, 0x13, 0x1e, + 0xd6, 0x31, 0x8e, 0xa1, 0x30, 0x6, 0xb8, 0xd9, 0x56, 0x39, 0x66, 0x0, 0xf, 0xee, 0xf, + 0xee, 0x7, 0x59, 0xb1, 0x8c, 0xf4, 0x8c, 0xcb, 0x87, 0xce, 0x83, 0xab, 0xc7}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[8]; + uint8_t topic_filter_s0_bytes[] = {0xda, 0xcc, 0x65, 0xc0, 0xfa, 0x95, 0x2f, 0x5, 0x4d, 0x4b}; + lwmqtt_string_t topic_filter_s0 = {10, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xf1, 0x10, 0x3d}; + lwmqtt_string_t topic_filter_s1 = {3, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xb1, 0xde, 0x1d, 0xb7, 0x17}; + lwmqtt_string_t topic_filter_s2 = {5, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0}; + lwmqtt_string_t topic_filter_s3 = {0, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x1a, 0x67, 0x5e, 0x96, 0x9c, 0x17, 0x4d, 0x47, 0xed, 0x30, 0xf4, 0xdc, 0x2f, + 0x9a, 0x62, 0xc7, 0x11, 0xd2, 0xa1, 0xe6, 0xc9, 0x81, 0xce, 0xb4, 0x40}; + lwmqtt_string_t topic_filter_s4 = {25, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xbb}; + lwmqtt_string_t topic_filter_s5 = {1, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xd3, 0xaf, 0x44, 0x83, 0xcb, 0xe1, 0xcb, 0x2d, 0xb1, 0x67, 0x26, 0x13, + 0x1e, 0xd6, 0x31, 0x8e, 0xa1, 0x30, 0x6, 0xb8, 0xd9, 0x56, 0x39, 0x66}; + lwmqtt_string_t topic_filter_s6 = {24, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xee, 0xf, 0xee, 0x7, 0x59, 0xb1, 0x8c, 0xf4, + 0x8c, 0xcb, 0x87, 0xce, 0x83, 0xab, 0xc7}; + lwmqtt_string_t topic_filter_s7 = {15, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT311, 18954, 8, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 22317 +// ["\SUB{\230Y\DC1\b\EM\160\232\SUB\CAN\131\NUL\188t\134\180\194a\152K\153\153\177\DLE1\225\161\225"] +// [PropPayloadFormatIndicator 182,PropRequestResponseInformation 171,PropMaximumPacketSize 20003,PropCorrelationData +// "J\SYN\202\172W3\149\236\ENQe8 Q\NUL\163@\227\n\208\142\129\226\156",PropTopicAlias 26285,PropMaximumPacketSize +// 4046,PropTopicAliasMaximum 15854,PropResponseInformation +// "\252\&4\NUL\164\SI\167\&5\162r\227\141\tO\183\203\SYN\196\138\216_\227,\186~\153\139j\DC2",PropWildcardSubscriptionAvailable +// 63,PropAuthenticationMethod +// "\f\227\&5)\177\STXy\233\213\184\184`\220<;+\140\177;\n\SOH\201\148\171p0",PropCorrelationData +// "J\177\169UK\RS7V\163\ACK\129\190\227=D~\132\227\157\ETBtKx7\220\172p[",PropTopicAliasMaximum 9276,PropMaximumQoS +// 204,PropAuthenticationMethod +// "\149\SI4\ACK\181P\ETX\186\190Gj\163\206#\210\bw\237$\141O\215\DC3\SOH",PropPayloadFormatIndicator +// 248,PropWildcardSubscriptionAvailable 203,PropMaximumQoS 70,PropWildcardSubscriptionAvailable 169,PropContentType +// "\204f\197-",PropAssignedClientIdentifier +// "\253W\136\STX3\247\147>\f\156/\223\157\253Cs\129\146q;\149\128\180+\SYN\136j\134N"] +TEST(Unsubscribe5QCTest, Encode1) { + uint8_t pkt[] = { + 0xa2, 0xfd, 0x1, 0x57, 0x2d, 0xda, 0x1, 0x1, 0xb6, 0x19, 0xab, 0x27, 0x0, 0x0, 0x4e, 0x23, 0x9, 0x0, 0x17, + 0x4a, 0x16, 0xca, 0xac, 0x57, 0x33, 0x95, 0xec, 0x5, 0x65, 0x38, 0x20, 0x51, 0x0, 0xa3, 0x40, 0xe3, 0xa, 0xd0, + 0x8e, 0x81, 0xe2, 0x9c, 0x23, 0x66, 0xad, 0x27, 0x0, 0x0, 0xf, 0xce, 0x22, 0x3d, 0xee, 0x1a, 0x0, 0x1c, 0xfc, + 0x34, 0x0, 0xa4, 0xf, 0xa7, 0x35, 0xa2, 0x72, 0xe3, 0x8d, 0x9, 0x4f, 0xb7, 0xcb, 0x16, 0xc4, 0x8a, 0xd8, 0x5f, + 0xe3, 0x2c, 0xba, 0x7e, 0x99, 0x8b, 0x6a, 0x12, 0x28, 0x3f, 0x15, 0x0, 0x1a, 0xc, 0xe3, 0x35, 0x29, 0xb1, 0x2, + 0x79, 0xe9, 0xd5, 0xb8, 0xb8, 0x60, 0xdc, 0x3c, 0x3b, 0x2b, 0x8c, 0xb1, 0x3b, 0xa, 0x1, 0xc9, 0x94, 0xab, 0x70, + 0x30, 0x9, 0x0, 0x1c, 0x4a, 0xb1, 0xa9, 0x55, 0x4b, 0x1e, 0x37, 0x56, 0xa3, 0x6, 0x81, 0xbe, 0xe3, 0x3d, 0x44, + 0x7e, 0x84, 0xe3, 0x9d, 0x17, 0x74, 0x4b, 0x78, 0x37, 0xdc, 0xac, 0x70, 0x5b, 0x22, 0x24, 0x3c, 0x24, 0xcc, 0x15, + 0x0, 0x18, 0x95, 0xf, 0x34, 0x6, 0xb5, 0x50, 0x3, 0xba, 0xbe, 0x47, 0x6a, 0xa3, 0xce, 0x23, 0xd2, 0x8, 0x77, + 0xed, 0x24, 0x8d, 0x4f, 0xd7, 0x13, 0x1, 0x1, 0xf8, 0x28, 0xcb, 0x24, 0x46, 0x28, 0xa9, 0x3, 0x0, 0x4, 0xcc, + 0x66, 0xc5, 0x2d, 0x12, 0x0, 0x1d, 0xfd, 0x57, 0x88, 0x2, 0x33, 0xf7, 0x93, 0x3e, 0xc, 0x9c, 0x2f, 0xdf, 0x9d, + 0xfd, 0x43, 0x73, 0x81, 0x92, 0x71, 0x3b, 0x95, 0x80, 0xb4, 0x2b, 0x16, 0x88, 0x6a, 0x86, 0x4e, 0x0, 0x1d, 0x1a, + 0x7b, 0xe6, 0x59, 0x11, 0x8, 0x19, 0xa0, 0xe8, 0x1a, 0x18, 0x83, 0x0, 0xbc, 0x74, 0x86, 0xb4, 0xc2, 0x61, 0x98, + 0x4b, 0x99, 0x99, 0xb1, 0x10, 0x31, 0xe1, 0xa1, 0xe1}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x4a, 0x16, 0xca, 0xac, 0x57, 0x33, 0x95, 0xec, 0x5, 0x65, 0x38, 0x20, + 0x51, 0x0, 0xa3, 0x40, 0xe3, 0xa, 0xd0, 0x8e, 0x81, 0xe2, 0x9c}; + uint8_t bytesprops1[] = {0xfc, 0x34, 0x0, 0xa4, 0xf, 0xa7, 0x35, 0xa2, 0x72, 0xe3, 0x8d, 0x9, 0x4f, 0xb7, + 0xcb, 0x16, 0xc4, 0x8a, 0xd8, 0x5f, 0xe3, 0x2c, 0xba, 0x7e, 0x99, 0x8b, 0x6a, 0x12}; + uint8_t bytesprops2[] = {0xc, 0xe3, 0x35, 0x29, 0xb1, 0x2, 0x79, 0xe9, 0xd5, 0xb8, 0xb8, 0x60, 0xdc, + 0x3c, 0x3b, 0x2b, 0x8c, 0xb1, 0x3b, 0xa, 0x1, 0xc9, 0x94, 0xab, 0x70, 0x30}; + uint8_t bytesprops3[] = {0x4a, 0xb1, 0xa9, 0x55, 0x4b, 0x1e, 0x37, 0x56, 0xa3, 0x6, 0x81, 0xbe, 0xe3, 0x3d, + 0x44, 0x7e, 0x84, 0xe3, 0x9d, 0x17, 0x74, 0x4b, 0x78, 0x37, 0xdc, 0xac, 0x70, 0x5b}; + uint8_t bytesprops4[] = {0x95, 0xf, 0x34, 0x6, 0xb5, 0x50, 0x3, 0xba, 0xbe, 0x47, 0x6a, 0xa3, + 0xce, 0x23, 0xd2, 0x8, 0x77, 0xed, 0x24, 0x8d, 0x4f, 0xd7, 0x13, 0x1}; + uint8_t bytesprops5[] = {0xcc, 0x66, 0xc5, 0x2d}; + uint8_t bytesprops6[] = {0xfd, 0x57, 0x88, 0x2, 0x33, 0xf7, 0x93, 0x3e, 0xc, 0x9c, 0x2f, 0xdf, 0x9d, 0xfd, 0x43, + 0x73, 0x81, 0x92, 0x71, 0x3b, 0x95, 0x80, 0xb4, 0x2b, 0x16, 0x88, 0x6a, 0x86, 0x4e}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 182}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 171}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 20003}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {23, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 26285}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 4046}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 15854}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {28, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 63}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {26, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {28, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 9276}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 204}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {24, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 248}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 203}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 70}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 169}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {4, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {29, (char*)&bytesprops6}}}, + }; + + lwmqtt_properties_t props = {20, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x1a, 0x7b, 0xe6, 0x59, 0x11, 0x8, 0x19, 0xa0, 0xe8, 0x1a, + 0x18, 0x83, 0x0, 0xbc, 0x74, 0x86, 0xb4, 0xc2, 0x61, 0x98, + 0x4b, 0x99, 0x99, 0xb1, 0x10, 0x31, 0xe1, 0xa1, 0xe1}; + lwmqtt_string_t topic_filter_s0 = {29, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 22317, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 24293 +// ["\177\195\r\186\208","j)G\249\ACK#[\204\130\&4\DC2\136\221$$\ENQl\\\229\a\166\175\191\237\165V\184!:","\193\&9hv\252]\252\204(","X\SO\SUB\236F\175ZC\230\190XaK\149\137\"\248\233`\DEL\196","\DC4XY\180\EOT\\\198\201\137\155\243\212\224\249\206B\DC2\DC1(","","\EM\159*x\161c%\180\218\254\\\177\172\180\137CU\196\155\248\194"] +// [PropAssignedClientIdentifier +// "\DC4\195\231\161\166\181\188Mn\bA\223\185\GSQK\155\184B\252\238_\223",PropPayloadFormatIndicator 83] +TEST(Unsubscribe5QCTest, Encode2) { + uint8_t pkt[] = {0xa2, 0x95, 0x1, 0x5e, 0xe5, 0x1c, 0x12, 0x0, 0x17, 0x14, 0xc3, 0xe7, 0xa1, 0xa6, 0xb5, 0xbc, 0x4d, + 0x6e, 0x8, 0x41, 0xdf, 0xb9, 0x1d, 0x51, 0x4b, 0x9b, 0xb8, 0x42, 0xfc, 0xee, 0x5f, 0xdf, 0x1, 0x53, + 0x0, 0x5, 0xb1, 0xc3, 0xd, 0xba, 0xd0, 0x0, 0x1d, 0x6a, 0x29, 0x47, 0xf9, 0x6, 0x23, 0x5b, 0xcc, + 0x82, 0x34, 0x12, 0x88, 0xdd, 0x24, 0x24, 0x5, 0x6c, 0x5c, 0xe5, 0x7, 0xa6, 0xaf, 0xbf, 0xed, 0xa5, + 0x56, 0xb8, 0x21, 0x3a, 0x0, 0x9, 0xc1, 0x39, 0x68, 0x76, 0xfc, 0x5d, 0xfc, 0xcc, 0x28, 0x0, 0x15, + 0x58, 0xe, 0x1a, 0xec, 0x46, 0xaf, 0x5a, 0x43, 0xe6, 0xbe, 0x58, 0x61, 0x4b, 0x95, 0x89, 0x22, 0xf8, + 0xe9, 0x60, 0x7f, 0xc4, 0x0, 0x13, 0x14, 0x58, 0x59, 0xb4, 0x4, 0x5c, 0xc6, 0xc9, 0x89, 0x9b, 0xf3, + 0xd4, 0xe0, 0xf9, 0xce, 0x42, 0x12, 0x11, 0x28, 0x0, 0x0, 0x0, 0x15, 0x19, 0x9f, 0x2a, 0x78, 0xa1, + 0x63, 0x25, 0xb4, 0xda, 0xfe, 0x5c, 0xb1, 0xac, 0xb4, 0x89, 0x43, 0x55, 0xc4, 0x9b, 0xf8, 0xc2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x14, 0xc3, 0xe7, 0xa1, 0xa6, 0xb5, 0xbc, 0x4d, 0x6e, 0x8, 0x41, 0xdf, + 0xb9, 0x1d, 0x51, 0x4b, 0x9b, 0xb8, 0x42, 0xfc, 0xee, 0x5f, 0xdf}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)18, .value = {.str = {23, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 83}}, + }; + + lwmqtt_properties_t props = {2, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0xb1, 0xc3, 0xd, 0xba, 0xd0}; + lwmqtt_string_t topic_filter_s0 = {5, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x6a, 0x29, 0x47, 0xf9, 0x6, 0x23, 0x5b, 0xcc, 0x82, 0x34, + 0x12, 0x88, 0xdd, 0x24, 0x24, 0x5, 0x6c, 0x5c, 0xe5, 0x7, + 0xa6, 0xaf, 0xbf, 0xed, 0xa5, 0x56, 0xb8, 0x21, 0x3a}; + lwmqtt_string_t topic_filter_s1 = {29, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xc1, 0x39, 0x68, 0x76, 0xfc, 0x5d, 0xfc, 0xcc, 0x28}; + lwmqtt_string_t topic_filter_s2 = {9, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x58, 0xe, 0x1a, 0xec, 0x46, 0xaf, 0x5a, 0x43, 0xe6, 0xbe, 0x58, + 0x61, 0x4b, 0x95, 0x89, 0x22, 0xf8, 0xe9, 0x60, 0x7f, 0xc4}; + lwmqtt_string_t topic_filter_s3 = {21, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x14, 0x58, 0x59, 0xb4, 0x4, 0x5c, 0xc6, 0xc9, 0x89, 0x9b, + 0xf3, 0xd4, 0xe0, 0xf9, 0xce, 0x42, 0x12, 0x11, 0x28}; + lwmqtt_string_t topic_filter_s4 = {19, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0}; + lwmqtt_string_t topic_filter_s5 = {0, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x19, 0x9f, 0x2a, 0x78, 0xa1, 0x63, 0x25, 0xb4, 0xda, 0xfe, 0x5c, + 0xb1, 0xac, 0xb4, 0x89, 0x43, 0x55, 0xc4, 0x9b, 0xf8, 0xc2}; + lwmqtt_string_t topic_filter_s6 = {21, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 24293, 7, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 10329 +// ["=]\230@","=4\172<\189?\DEL\142X\235",">\180QZX\217\199@","~}\"\182\146\230\151\176\250MD:\144\171\237Q\226X",")\188\182\214\&1\161\144\201>h\192"] +// [PropUserProperty "\219\162J\202\222:V\137\247k\232\239@;f\253`A/\GSSK" +// "\173\GS|\"\ESC\230c\189\GSl\211M\SOH\200",PropMaximumQoS 82,PropMessageExpiryInterval 15648,PropAuthenticationData +// "\152D\195\207\\\210\235\218\175Q`1`\193\DC2(\248\222t",PropResponseTopic +// "3\156]7*\210=ek\176]1\252%\184\205\154\195H\SIW\159v(",PropRetainAvailable 114] +TEST(Unsubscribe5QCTest, Encode3) { + uint8_t pkt[] = {0xa2, 0xa3, 0x1, 0x28, 0x59, 0x63, 0x26, 0x0, 0x16, 0xdb, 0xa2, 0x4a, 0xca, 0xde, 0x3a, 0x56, 0x89, + 0xf7, 0x6b, 0xe8, 0xef, 0x40, 0x3b, 0x66, 0xfd, 0x60, 0x41, 0x2f, 0x1d, 0x53, 0x4b, 0x0, 0xe, 0xad, + 0x1d, 0x7c, 0x22, 0x1b, 0xe6, 0x63, 0xbd, 0x1d, 0x6c, 0xd3, 0x4d, 0x1, 0xc8, 0x24, 0x52, 0x2, 0x0, + 0x0, 0x3d, 0x20, 0x16, 0x0, 0x13, 0x98, 0x44, 0xc3, 0xcf, 0x5c, 0xd2, 0xeb, 0xda, 0xaf, 0x51, 0x60, + 0x31, 0x60, 0xc1, 0x12, 0x28, 0xf8, 0xde, 0x74, 0x8, 0x0, 0x18, 0x33, 0x9c, 0x5d, 0x37, 0x2a, 0xd2, + 0x3d, 0x65, 0x6b, 0xb0, 0x5d, 0x31, 0xfc, 0x25, 0xb8, 0xcd, 0x9a, 0xc3, 0x48, 0xf, 0x57, 0x9f, 0x76, + 0x28, 0x25, 0x72, 0x0, 0x4, 0x3d, 0x5d, 0xe6, 0x40, 0x0, 0xa, 0x3d, 0x34, 0xac, 0x3c, 0xbd, 0x3f, + 0x7f, 0x8e, 0x58, 0xeb, 0x0, 0x8, 0x3e, 0xb4, 0x51, 0x5a, 0x58, 0xd9, 0xc7, 0x40, 0x0, 0x12, 0x7e, + 0x7d, 0x22, 0xb6, 0x92, 0xe6, 0x97, 0xb0, 0xfa, 0x4d, 0x44, 0x3a, 0x90, 0xab, 0xed, 0x51, 0xe2, 0x58, + 0x0, 0xb, 0x29, 0xbc, 0xb6, 0xd6, 0x31, 0xa1, 0x90, 0xc9, 0x3e, 0x68, 0xc0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops1[] = {0xad, 0x1d, 0x7c, 0x22, 0x1b, 0xe6, 0x63, 0xbd, 0x1d, 0x6c, 0xd3, 0x4d, 0x1, 0xc8}; + uint8_t bytesprops0[] = {0xdb, 0xa2, 0x4a, 0xca, 0xde, 0x3a, 0x56, 0x89, 0xf7, 0x6b, 0xe8, + 0xef, 0x40, 0x3b, 0x66, 0xfd, 0x60, 0x41, 0x2f, 0x1d, 0x53, 0x4b}; + uint8_t bytesprops2[] = {0x98, 0x44, 0xc3, 0xcf, 0x5c, 0xd2, 0xeb, 0xda, 0xaf, 0x51, + 0x60, 0x31, 0x60, 0xc1, 0x12, 0x28, 0xf8, 0xde, 0x74}; + uint8_t bytesprops3[] = {0x33, 0x9c, 0x5d, 0x37, 0x2a, 0xd2, 0x3d, 0x65, 0x6b, 0xb0, 0x5d, 0x31, + 0xfc, 0x25, 0xb8, 0xcd, 0x9a, 0xc3, 0x48, 0xf, 0x57, 0x9f, 0x76, 0x28}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {22, (char*)&bytesprops0}, .v = {14, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 82}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 15648}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {19, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {24, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 114}}, + }; + + lwmqtt_properties_t props = {6, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0x3d, 0x5d, 0xe6, 0x40}; + lwmqtt_string_t topic_filter_s0 = {4, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x3d, 0x34, 0xac, 0x3c, 0xbd, 0x3f, 0x7f, 0x8e, 0x58, 0xeb}; + lwmqtt_string_t topic_filter_s1 = {10, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x3e, 0xb4, 0x51, 0x5a, 0x58, 0xd9, 0xc7, 0x40}; + lwmqtt_string_t topic_filter_s2 = {8, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x7e, 0x7d, 0x22, 0xb6, 0x92, 0xe6, 0x97, 0xb0, 0xfa, + 0x4d, 0x44, 0x3a, 0x90, 0xab, 0xed, 0x51, 0xe2, 0x58}; + lwmqtt_string_t topic_filter_s3 = {18, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x29, 0xbc, 0xb6, 0xd6, 0x31, 0xa1, 0x90, 0xc9, 0x3e, 0x68, 0xc0}; + lwmqtt_string_t topic_filter_s4 = {11, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 10329, 5, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 1566 ["\248f\177\a\209\171O\234C","\r\207\164\185\187[\175","}\213\235~\236\226x"] +// [PropPayloadFormatIndicator 43,PropSharedSubscriptionAvailable 23,PropMessageExpiryInterval 84,PropWillDelayInterval +// 19220,PropWillDelayInterval 14718,PropRequestResponseInformation 241,PropRequestResponseInformation +// 131,PropTopicAliasMaximum 18345,PropResponseInformation "@\191\175\182 +// 0\ACK\238E\242\202\226\230iO3\167,\SUBY\167L\192",PropServerKeepAlive 32028,PropServerReference +// "\130e\186\188\244\DLE\141x;\162e\225\DC4\215\147o",PropSessionExpiryInterval 23135,PropTopicAlias +// 14739,PropSubscriptionIdentifier 7,PropWillDelayInterval 32745,PropWillDelayInterval 905,PropAuthenticationMethod +// "kI\237\243\192 u]\240\183\176>\144\161x",PropWildcardSubscriptionAvailable 144,PropSubscriptionIdentifier +// 14,PropTopicAliasMaximum 27090,PropSubscriptionIdentifier 30,PropPayloadFormatIndicator +// 231,PropPayloadFormatIndicator 1,PropServerKeepAlive 17503,PropRequestResponseInformation +// 103,PropSubscriptionIdentifier 3,PropSessionExpiryInterval 2807,PropResponseTopic +// "\244\133d~\141\194F\132ml0\193\148O\242"] +TEST(Unsubscribe5QCTest, Encode4) { + uint8_t pkt[] = {0xa2, 0xbc, 0x1, 0x6, 0x1e, 0x9b, 0x1, 0x1, 0x2b, 0x2a, 0x17, 0x2, 0x0, 0x0, 0x0, 0x54, + 0x18, 0x0, 0x0, 0x4b, 0x14, 0x18, 0x0, 0x0, 0x39, 0x7e, 0x19, 0xf1, 0x19, 0x83, 0x22, 0x47, + 0xa9, 0x1a, 0x0, 0x17, 0x40, 0xbf, 0xaf, 0xb6, 0x20, 0x30, 0x6, 0xee, 0x45, 0xf2, 0xca, 0xe2, + 0xe6, 0x69, 0x4f, 0x33, 0xa7, 0x2c, 0x1a, 0x59, 0xa7, 0x4c, 0xc0, 0x13, 0x7d, 0x1c, 0x1c, 0x0, + 0x10, 0x82, 0x65, 0xba, 0xbc, 0xf4, 0x10, 0x8d, 0x78, 0x3b, 0xa2, 0x65, 0xe1, 0x14, 0xd7, 0x93, + 0x6f, 0x11, 0x0, 0x0, 0x5a, 0x5f, 0x23, 0x39, 0x93, 0xb, 0x7, 0x18, 0x0, 0x0, 0x7f, 0xe9, + 0x18, 0x0, 0x0, 0x3, 0x89, 0x15, 0x0, 0xf, 0x6b, 0x49, 0xed, 0xf3, 0xc0, 0x20, 0x75, 0x5d, + 0xf0, 0xb7, 0xb0, 0x3e, 0x90, 0xa1, 0x78, 0x28, 0x90, 0xb, 0xe, 0x22, 0x69, 0xd2, 0xb, 0x1e, + 0x1, 0xe7, 0x1, 0x1, 0x13, 0x44, 0x5f, 0x19, 0x67, 0xb, 0x3, 0x11, 0x0, 0x0, 0xa, 0xf7, + 0x8, 0x0, 0xf, 0xf4, 0x85, 0x64, 0x7e, 0x8d, 0xc2, 0x46, 0x84, 0x6d, 0x6c, 0x30, 0xc1, 0x94, + 0x4f, 0xf2, 0x0, 0x9, 0xf8, 0x66, 0xb1, 0x7, 0xd1, 0xab, 0x4f, 0xea, 0x43, 0x0, 0x7, 0xd, + 0xcf, 0xa4, 0xb9, 0xbb, 0x5b, 0xaf, 0x0, 0x7, 0x7d, 0xd5, 0xeb, 0x7e, 0xec, 0xe2, 0x78}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x40, 0xbf, 0xaf, 0xb6, 0x20, 0x30, 0x6, 0xee, 0x45, 0xf2, 0xca, 0xe2, + 0xe6, 0x69, 0x4f, 0x33, 0xa7, 0x2c, 0x1a, 0x59, 0xa7, 0x4c, 0xc0}; + uint8_t bytesprops1[] = {0x82, 0x65, 0xba, 0xbc, 0xf4, 0x10, 0x8d, 0x78, + 0x3b, 0xa2, 0x65, 0xe1, 0x14, 0xd7, 0x93, 0x6f}; + uint8_t bytesprops2[] = {0x6b, 0x49, 0xed, 0xf3, 0xc0, 0x20, 0x75, 0x5d, 0xf0, 0xb7, 0xb0, 0x3e, 0x90, 0xa1, 0x78}; + uint8_t bytesprops3[] = {0xf4, 0x85, 0x64, 0x7e, 0x8d, 0xc2, 0x46, 0x84, 0x6d, 0x6c, 0x30, 0xc1, 0x94, 0x4f, 0xf2}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 43}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 23}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 84}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 19220}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 14718}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 241}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 131}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 18345}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {23, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 32028}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {16, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 23135}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 14739}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 7}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 32745}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 905}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {15, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 144}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 14}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 27090}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 30}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 231}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 1}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 17503}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 103}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 3}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 2807}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {15, (char*)&bytesprops3}}}, + }; + + lwmqtt_properties_t props = {28, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[3]; + uint8_t topic_filter_s0_bytes[] = {0xf8, 0x66, 0xb1, 0x7, 0xd1, 0xab, 0x4f, 0xea, 0x43}; + lwmqtt_string_t topic_filter_s0 = {9, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xd, 0xcf, 0xa4, 0xb9, 0xbb, 0x5b, 0xaf}; + lwmqtt_string_t topic_filter_s1 = {7, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x7d, 0xd5, 0xeb, 0x7e, 0xec, 0xe2, 0x78}; + lwmqtt_string_t topic_filter_s2 = {7, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 1566, 3, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 22798 ["\214 +// Y}]\179\173\176\b\251]h\254\ESC\182,\133@\151j\ESC\159\GS","\233.\192\135\197\200\229\&2x\v\225\196\212\CAN}.","<\137}/\159\230\156\167b\178\157\205\GS\185","\198\243\228\142\132\168\RS\131\223\&6\253\217\SYN\SOHZ\159\185\243\244\138\136\SO\178\ESC\235\187\154\137","\213\213\156\129\DC2\206vq\233I\171\193\187}\168b\255\221\EM\253Z\195p\244\130","\SO\131z\DC4,5R\ENQ","\STX\193/\236>\189\241\&2\186v\186V\178\138\n\202\195\244\182\181_\ENQ\222\215\\+\177",")","\161.m\ESC\f\253a\221\167\t\199#","@\213\DC1\188GHQ\153\138\NAK\161A\ESC\161\162I\246Q\200\152?\251"] +// [PropMessageExpiryInterval 3679,PropUserProperty "\192\187F\SI" "Y\142\181\r\161\217",PropSharedSubscriptionAvailable +// 190,PropServerReference "-\ESC\171\&8\136\&2\171\179\139/\EOT[h\r4H",PropServerReference +// "^K\ENQ\201\&4\193\190\147\SI\229ws\229\223\250\\Z",PropSessionExpiryInterval 9553,PropRequestResponseInformation +// 33,PropPayloadFormatIndicator 78,PropAuthenticationData +// "u\214z\250F$\242\NUL\205\SOH\vc\147,\DC15\195\RSj\207\199\200\242\&6\202",PropWildcardSubscriptionAvailable +// 105,PropCorrelationData +// "z~o\221\CAN4M\US\166G\206AK,,\SOH\159\213\228(\148\144\CAN\164F",PropWildcardSubscriptionAvailable +// 9,PropRequestProblemInformation 40,PropResponseTopic "\204\&4/\234\232\252\220\235x\171\162\&3\159\240 +// \223\143\255yl9UplP",PropUserProperty "" +// "\SYN\f\165\250\168\&7l\244\234\161`\r\219\v\250\237\v<\218\158\146\203v\187\214\210",PropSubscriptionIdentifier +// 18,PropRequestResponseInformation 170,PropContentType +// "\246I\220\162y\f\197\247\235~\254p\171\221\209{r\GSW\182",PropResponseTopic +// "/\189\DLE{D\224\ETB\")\153\248L\242\164\216@G\DC3X\NAK\233\143y;\244\222",PropReceiveMaximum +// 7194,PropSessionExpiryInterval 3493,PropMessageExpiryInterval 13254,PropMaximumQoS 49,PropSharedSubscriptionAvailable +// 211,PropCorrelationData "\159\212!\144\194\&7\146",PropWillDelayInterval 5617,PropMaximumPacketSize 28573] +TEST(Unsubscribe5QCTest, Encode5) { + uint8_t pkt[] = { + 0xa2, 0xe4, 0x3, 0x59, 0xe, 0x9c, 0x2, 0x2, 0x0, 0x0, 0xe, 0x5f, 0x26, 0x0, 0x4, 0xc0, 0xbb, 0x46, 0xf, + 0x0, 0x6, 0x59, 0x8e, 0xb5, 0xd, 0xa1, 0xd9, 0x2a, 0xbe, 0x1c, 0x0, 0x10, 0x2d, 0x1b, 0xab, 0x38, 0x88, 0x32, + 0xab, 0xb3, 0x8b, 0x2f, 0x4, 0x5b, 0x68, 0xd, 0x34, 0x48, 0x1c, 0x0, 0x11, 0x5e, 0x4b, 0x5, 0xc9, 0x34, 0xc1, + 0xbe, 0x93, 0xf, 0xe5, 0x77, 0x73, 0xe5, 0xdf, 0xfa, 0x5c, 0x5a, 0x11, 0x0, 0x0, 0x25, 0x51, 0x19, 0x21, 0x1, + 0x4e, 0x16, 0x0, 0x19, 0x75, 0xd6, 0x7a, 0xfa, 0x46, 0x24, 0xf2, 0x0, 0xcd, 0x1, 0xb, 0x63, 0x93, 0x2c, 0x11, + 0x35, 0xc3, 0x1e, 0x6a, 0xcf, 0xc7, 0xc8, 0xf2, 0x36, 0xca, 0x28, 0x69, 0x9, 0x0, 0x19, 0x7a, 0x7e, 0x6f, 0xdd, + 0x18, 0x34, 0x4d, 0x1f, 0xa6, 0x47, 0xce, 0x41, 0x4b, 0x2c, 0x2c, 0x1, 0x9f, 0xd5, 0xe4, 0x28, 0x94, 0x90, 0x18, + 0xa4, 0x46, 0x28, 0x9, 0x17, 0x28, 0x8, 0x0, 0x19, 0xcc, 0x34, 0x2f, 0xea, 0xe8, 0xfc, 0xdc, 0xeb, 0x78, 0xab, + 0xa2, 0x33, 0x9f, 0xf0, 0x20, 0xdf, 0x8f, 0xff, 0x79, 0x6c, 0x39, 0x55, 0x70, 0x6c, 0x50, 0x26, 0x0, 0x0, 0x0, + 0x1a, 0x16, 0xc, 0xa5, 0xfa, 0xa8, 0x37, 0x6c, 0xf4, 0xea, 0xa1, 0x60, 0xd, 0xdb, 0xb, 0xfa, 0xed, 0xb, 0x3c, + 0xda, 0x9e, 0x92, 0xcb, 0x76, 0xbb, 0xd6, 0xd2, 0xb, 0x12, 0x19, 0xaa, 0x3, 0x0, 0x14, 0xf6, 0x49, 0xdc, 0xa2, + 0x79, 0xc, 0xc5, 0xf7, 0xeb, 0x7e, 0xfe, 0x70, 0xab, 0xdd, 0xd1, 0x7b, 0x72, 0x1d, 0x57, 0xb6, 0x8, 0x0, 0x1a, + 0x2f, 0xbd, 0x10, 0x7b, 0x44, 0xe0, 0x17, 0x22, 0x29, 0x99, 0xf8, 0x4c, 0xf2, 0xa4, 0xd8, 0x40, 0x47, 0x13, 0x58, + 0x15, 0xe9, 0x8f, 0x79, 0x3b, 0xf4, 0xde, 0x21, 0x1c, 0x1a, 0x11, 0x0, 0x0, 0xd, 0xa5, 0x2, 0x0, 0x0, 0x33, + 0xc6, 0x24, 0x31, 0x2a, 0xd3, 0x9, 0x0, 0x7, 0x9f, 0xd4, 0x21, 0x90, 0xc2, 0x37, 0x92, 0x18, 0x0, 0x0, 0x15, + 0xf1, 0x27, 0x0, 0x0, 0x6f, 0x9d, 0x0, 0x17, 0xd6, 0x20, 0x59, 0x7d, 0x5d, 0xb3, 0xad, 0xb0, 0x8, 0xfb, 0x5d, + 0x68, 0xfe, 0x1b, 0xb6, 0x2c, 0x85, 0x40, 0x97, 0x6a, 0x1b, 0x9f, 0x1d, 0x0, 0x10, 0xe9, 0x2e, 0xc0, 0x87, 0xc5, + 0xc8, 0xe5, 0x32, 0x78, 0xb, 0xe1, 0xc4, 0xd4, 0x18, 0x7d, 0x2e, 0x0, 0xe, 0x3c, 0x89, 0x7d, 0x2f, 0x9f, 0xe6, + 0x9c, 0xa7, 0x62, 0xb2, 0x9d, 0xcd, 0x1d, 0xb9, 0x0, 0x1c, 0xc6, 0xf3, 0xe4, 0x8e, 0x84, 0xa8, 0x1e, 0x83, 0xdf, + 0x36, 0xfd, 0xd9, 0x16, 0x1, 0x5a, 0x9f, 0xb9, 0xf3, 0xf4, 0x8a, 0x88, 0xe, 0xb2, 0x1b, 0xeb, 0xbb, 0x9a, 0x89, + 0x0, 0x19, 0xd5, 0xd5, 0x9c, 0x81, 0x12, 0xce, 0x76, 0x71, 0xe9, 0x49, 0xab, 0xc1, 0xbb, 0x7d, 0xa8, 0x62, 0xff, + 0xdd, 0x19, 0xfd, 0x5a, 0xc3, 0x70, 0xf4, 0x82, 0x0, 0x8, 0xe, 0x83, 0x7a, 0x14, 0x2c, 0x35, 0x52, 0x5, 0x0, + 0x1b, 0x2, 0xc1, 0x2f, 0xec, 0x3e, 0xbd, 0xf1, 0x32, 0xba, 0x76, 0xba, 0x56, 0xb2, 0x8a, 0xa, 0xca, 0xc3, 0xf4, + 0xb6, 0xb5, 0x5f, 0x5, 0xde, 0xd7, 0x5c, 0x2b, 0xb1, 0x0, 0x1, 0x29, 0x0, 0xc, 0xa1, 0x2e, 0x6d, 0x1b, 0xc, + 0xfd, 0x61, 0xdd, 0xa7, 0x9, 0xc7, 0x23, 0x0, 0x16, 0x40, 0xd5, 0x11, 0xbc, 0x47, 0x48, 0x51, 0x99, 0x8a, 0x15, + 0xa1, 0x41, 0x1b, 0xa1, 0xa2, 0x49, 0xf6, 0x51, 0xc8, 0x98, 0x3f, 0xfb}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops1[] = {0x59, 0x8e, 0xb5, 0xd, 0xa1, 0xd9}; + uint8_t bytesprops0[] = {0xc0, 0xbb, 0x46, 0xf}; + uint8_t bytesprops2[] = {0x2d, 0x1b, 0xab, 0x38, 0x88, 0x32, 0xab, 0xb3, + 0x8b, 0x2f, 0x4, 0x5b, 0x68, 0xd, 0x34, 0x48}; + uint8_t bytesprops3[] = {0x5e, 0x4b, 0x5, 0xc9, 0x34, 0xc1, 0xbe, 0x93, 0xf, + 0xe5, 0x77, 0x73, 0xe5, 0xdf, 0xfa, 0x5c, 0x5a}; + uint8_t bytesprops4[] = {0x75, 0xd6, 0x7a, 0xfa, 0x46, 0x24, 0xf2, 0x0, 0xcd, 0x1, 0xb, 0x63, 0x93, + 0x2c, 0x11, 0x35, 0xc3, 0x1e, 0x6a, 0xcf, 0xc7, 0xc8, 0xf2, 0x36, 0xca}; + uint8_t bytesprops5[] = {0x7a, 0x7e, 0x6f, 0xdd, 0x18, 0x34, 0x4d, 0x1f, 0xa6, 0x47, 0xce, 0x41, 0x4b, + 0x2c, 0x2c, 0x1, 0x9f, 0xd5, 0xe4, 0x28, 0x94, 0x90, 0x18, 0xa4, 0x46}; + uint8_t bytesprops6[] = {0xcc, 0x34, 0x2f, 0xea, 0xe8, 0xfc, 0xdc, 0xeb, 0x78, 0xab, 0xa2, 0x33, 0x9f, + 0xf0, 0x20, 0xdf, 0x8f, 0xff, 0x79, 0x6c, 0x39, 0x55, 0x70, 0x6c, 0x50}; + uint8_t bytesprops8[] = {0x16, 0xc, 0xa5, 0xfa, 0xa8, 0x37, 0x6c, 0xf4, 0xea, 0xa1, 0x60, 0xd, 0xdb, + 0xb, 0xfa, 0xed, 0xb, 0x3c, 0xda, 0x9e, 0x92, 0xcb, 0x76, 0xbb, 0xd6, 0xd2}; + uint8_t bytesprops7[] = {0}; + uint8_t bytesprops9[] = {0xf6, 0x49, 0xdc, 0xa2, 0x79, 0xc, 0xc5, 0xf7, 0xeb, 0x7e, + 0xfe, 0x70, 0xab, 0xdd, 0xd1, 0x7b, 0x72, 0x1d, 0x57, 0xb6}; + uint8_t bytesprops10[] = {0x2f, 0xbd, 0x10, 0x7b, 0x44, 0xe0, 0x17, 0x22, 0x29, 0x99, 0xf8, 0x4c, 0xf2, + 0xa4, 0xd8, 0x40, 0x47, 0x13, 0x58, 0x15, 0xe9, 0x8f, 0x79, 0x3b, 0xf4, 0xde}; + uint8_t bytesprops11[] = {0x9f, 0xd4, 0x21, 0x90, 0xc2, 0x37, 0x92}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 3679}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {4, (char*)&bytesprops0}, .v = {6, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 190}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {16, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {17, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 9553}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 33}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 78}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {25, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 105}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {25, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 9}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 40}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {25, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {0, (char*)&bytesprops7}, .v = {26, (char*)&bytesprops8}}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 18}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 170}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {20, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {26, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 7194}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 3493}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 13254}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 49}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 211}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {7, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 5617}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 28573}}, + }; + + lwmqtt_properties_t props = {27, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[10]; + uint8_t topic_filter_s0_bytes[] = {0xd6, 0x20, 0x59, 0x7d, 0x5d, 0xb3, 0xad, 0xb0, 0x8, 0xfb, 0x5d, 0x68, + 0xfe, 0x1b, 0xb6, 0x2c, 0x85, 0x40, 0x97, 0x6a, 0x1b, 0x9f, 0x1d}; + lwmqtt_string_t topic_filter_s0 = {23, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xe9, 0x2e, 0xc0, 0x87, 0xc5, 0xc8, 0xe5, 0x32, + 0x78, 0xb, 0xe1, 0xc4, 0xd4, 0x18, 0x7d, 0x2e}; + lwmqtt_string_t topic_filter_s1 = {16, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x3c, 0x89, 0x7d, 0x2f, 0x9f, 0xe6, 0x9c, + 0xa7, 0x62, 0xb2, 0x9d, 0xcd, 0x1d, 0xb9}; + lwmqtt_string_t topic_filter_s2 = {14, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xc6, 0xf3, 0xe4, 0x8e, 0x84, 0xa8, 0x1e, 0x83, 0xdf, 0x36, + 0xfd, 0xd9, 0x16, 0x1, 0x5a, 0x9f, 0xb9, 0xf3, 0xf4, 0x8a, + 0x88, 0xe, 0xb2, 0x1b, 0xeb, 0xbb, 0x9a, 0x89}; + lwmqtt_string_t topic_filter_s3 = {28, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xd5, 0xd5, 0x9c, 0x81, 0x12, 0xce, 0x76, 0x71, 0xe9, 0x49, 0xab, 0xc1, 0xbb, + 0x7d, 0xa8, 0x62, 0xff, 0xdd, 0x19, 0xfd, 0x5a, 0xc3, 0x70, 0xf4, 0x82}; + lwmqtt_string_t topic_filter_s4 = {25, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xe, 0x83, 0x7a, 0x14, 0x2c, 0x35, 0x52, 0x5}; + lwmqtt_string_t topic_filter_s5 = {8, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x2, 0xc1, 0x2f, 0xec, 0x3e, 0xbd, 0xf1, 0x32, 0xba, 0x76, 0xba, 0x56, 0xb2, 0x8a, + 0xa, 0xca, 0xc3, 0xf4, 0xb6, 0xb5, 0x5f, 0x5, 0xde, 0xd7, 0x5c, 0x2b, 0xb1}; + lwmqtt_string_t topic_filter_s6 = {27, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x29}; + lwmqtt_string_t topic_filter_s7 = {1, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xa1, 0x2e, 0x6d, 0x1b, 0xc, 0xfd, 0x61, 0xdd, 0xa7, 0x9, 0xc7, 0x23}; + lwmqtt_string_t topic_filter_s8 = {12, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x40, 0xd5, 0x11, 0xbc, 0x47, 0x48, 0x51, 0x99, 0x8a, 0x15, 0xa1, + 0x41, 0x1b, 0xa1, 0xa2, 0x49, 0xf6, 0x51, 0xc8, 0x98, 0x3f, 0xfb}; + lwmqtt_string_t topic_filter_s9 = {22, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 22798, 10, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 24222 +// ["5\171","\213JI\161N\156\190\210I\")\SUB\177f","r\254N;","\150\129\236\130\164\ESC\186o\184[\228\&4\155\160\"9\181\195Ke\DC3k\228\&5Y\EOT\GS\ENQ\ACK\185","x\173\243\136\&49t\232\193M\EMU\245k1\234s\177\148@\SYN\SO\245\STX\228\138","y\248\215"] +// [PropSharedSubscriptionAvailable 157,PropMaximumPacketSize 20413,PropSessionExpiryInterval 3299,PropTopicAlias +// 18064,PropTopicAlias 23902,PropRequestResponseInformation 201,PropPayloadFormatIndicator 200] +TEST(Unsubscribe5QCTest, Encode6) { + uint8_t pkt[] = {0xa2, 0x74, 0x5e, 0x9e, 0x16, 0x2a, 0x9d, 0x27, 0x0, 0x0, 0x4f, 0xbd, 0x11, 0x0, 0x0, 0xc, 0xe3, + 0x23, 0x46, 0x90, 0x23, 0x5d, 0x5e, 0x19, 0xc9, 0x1, 0xc8, 0x0, 0x2, 0x35, 0xab, 0x0, 0xe, 0xd5, + 0x4a, 0x49, 0xa1, 0x4e, 0x9c, 0xbe, 0xd2, 0x49, 0x22, 0x29, 0x1a, 0xb1, 0x66, 0x0, 0x4, 0x72, 0xfe, + 0x4e, 0x3b, 0x0, 0x1e, 0x96, 0x81, 0xec, 0x82, 0xa4, 0x1b, 0xba, 0x6f, 0xb8, 0x5b, 0xe4, 0x34, 0x9b, + 0xa0, 0x22, 0x39, 0xb5, 0xc3, 0x4b, 0x65, 0x13, 0x6b, 0xe4, 0x35, 0x59, 0x4, 0x1d, 0x5, 0x6, 0xb9, + 0x0, 0x1a, 0x78, 0xad, 0xf3, 0x88, 0x34, 0x39, 0x74, 0xe8, 0xc1, 0x4d, 0x19, 0x55, 0xf5, 0x6b, 0x31, + 0xea, 0x73, 0xb1, 0x94, 0x40, 0x16, 0xe, 0xf5, 0x2, 0xe4, 0x8a, 0x0, 0x3, 0x79, 0xf8, 0xd7}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 157}}, {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 20413}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 3299}}, {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 18064}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 23902}}, {.prop = (lwmqtt_prop_t)25, .value = {.byte = 201}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 200}}, + }; + + lwmqtt_properties_t props = {7, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[6]; + uint8_t topic_filter_s0_bytes[] = {0x35, 0xab}; + lwmqtt_string_t topic_filter_s0 = {2, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xd5, 0x4a, 0x49, 0xa1, 0x4e, 0x9c, 0xbe, + 0xd2, 0x49, 0x22, 0x29, 0x1a, 0xb1, 0x66}; + lwmqtt_string_t topic_filter_s1 = {14, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x72, 0xfe, 0x4e, 0x3b}; + lwmqtt_string_t topic_filter_s2 = {4, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x96, 0x81, 0xec, 0x82, 0xa4, 0x1b, 0xba, 0x6f, 0xb8, 0x5b, + 0xe4, 0x34, 0x9b, 0xa0, 0x22, 0x39, 0xb5, 0xc3, 0x4b, 0x65, + 0x13, 0x6b, 0xe4, 0x35, 0x59, 0x4, 0x1d, 0x5, 0x6, 0xb9}; + lwmqtt_string_t topic_filter_s3 = {30, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x78, 0xad, 0xf3, 0x88, 0x34, 0x39, 0x74, 0xe8, 0xc1, 0x4d, 0x19, 0x55, 0xf5, + 0x6b, 0x31, 0xea, 0x73, 0xb1, 0x94, 0x40, 0x16, 0xe, 0xf5, 0x2, 0xe4, 0x8a}; + lwmqtt_string_t topic_filter_s4 = {26, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x79, 0xf8, 0xd7}; + lwmqtt_string_t topic_filter_s5 = {3, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 24222, 6, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 12540 ["\142\149\170v\174V',D\DELQ=,\212\228v"] [PropResponseInformation +// "\160$\163\&7?\212\217fD{\137\245\195\129\218\223\178\EOTQ\EOT\255\&1i\158\246;\213",PropAuthenticationMethod +// "\150\b\134\180-e\SOKU{4\239\171\DC4\191\STX",PropResponseTopic "\180\191( \176\228\SOH\184\196\154",PropMaximumQoS +// 130,PropTopicAliasMaximum 14742,PropCorrelationData "hf\153\162\181\219\&6\237"] +TEST(Unsubscribe5QCTest, Encode7) { + uint8_t pkt[] = {0xa2, 0x63, 0x30, 0xfc, 0x4e, 0x1a, 0x0, 0x1b, 0xa0, 0x24, 0xa3, 0x37, 0x3f, 0xd4, 0xd9, 0x66, 0x44, + 0x7b, 0x89, 0xf5, 0xc3, 0x81, 0xda, 0xdf, 0xb2, 0x4, 0x51, 0x4, 0xff, 0x31, 0x69, 0x9e, 0xf6, 0x3b, + 0xd5, 0x15, 0x0, 0x10, 0x96, 0x8, 0x86, 0xb4, 0x2d, 0x65, 0xe, 0x4b, 0x55, 0x7b, 0x34, 0xef, 0xab, + 0x14, 0xbf, 0x2, 0x8, 0x0, 0xa, 0xb4, 0xbf, 0x28, 0x20, 0xb0, 0xe4, 0x1, 0xb8, 0xc4, 0x9a, 0x24, + 0x82, 0x22, 0x39, 0x96, 0x9, 0x0, 0x8, 0x68, 0x66, 0x99, 0xa2, 0xb5, 0xdb, 0x36, 0xed, 0x0, 0x10, + 0x8e, 0x95, 0xaa, 0x76, 0xae, 0x56, 0x27, 0x2c, 0x44, 0x7f, 0x51, 0x3d, 0x2c, 0xd4, 0xe4, 0x76}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xa0, 0x24, 0xa3, 0x37, 0x3f, 0xd4, 0xd9, 0x66, 0x44, 0x7b, 0x89, 0xf5, 0xc3, 0x81, + 0xda, 0xdf, 0xb2, 0x4, 0x51, 0x4, 0xff, 0x31, 0x69, 0x9e, 0xf6, 0x3b, 0xd5}; + uint8_t bytesprops1[] = {0x96, 0x8, 0x86, 0xb4, 0x2d, 0x65, 0xe, 0x4b, 0x55, 0x7b, 0x34, 0xef, 0xab, 0x14, 0xbf, 0x2}; + uint8_t bytesprops2[] = {0xb4, 0xbf, 0x28, 0x20, 0xb0, 0xe4, 0x1, 0xb8, 0xc4, 0x9a}; + uint8_t bytesprops3[] = {0x68, 0x66, 0x99, 0xa2, 0xb5, 0xdb, 0x36, 0xed}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)26, .value = {.str = {27, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {16, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {10, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 130}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 14742}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {8, (char*)&bytesprops3}}}, + }; + + lwmqtt_properties_t props = {6, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x8e, 0x95, 0xaa, 0x76, 0xae, 0x56, 0x27, 0x2c, + 0x44, 0x7f, 0x51, 0x3d, 0x2c, 0xd4, 0xe4, 0x76}; + lwmqtt_string_t topic_filter_s0 = {16, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 12540, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 30589 +// [",\131\ETB\170\237\194/\147\140iM\159*x\159V\134","\STX\142\DC1r\DC1\130\183\v\211\183\147\192\211\194\165\200\139I\DEL\174P\171\255p\201p\237","\188\US\rg\233 +// \140\235\ETX\218ZA","S\ETB\255w\US\250\184\&8E\171\173","\EM\ETB8\ESCN","2\230c\246\211\&1\216\150\202\221\173w\147\232$\132pD\236","\186\157\201\165\158\210\ETB\232\194\236\&2<","\GS]\181\179\142\190\230\242(&\196`\142\131\184\\\243"] +// [PropServerKeepAlive 17083,PropTopicAliasMaximum 22420,PropResponseTopic +// "y\224\224\ACKA\DC3L\132~\DC2\ETBz\249\SOH\230\206\191g\a\148\175G\nh8\129\EOTk",PropAssignedClientIdentifier +// "\238\152n\236X\244G\161\144\149\a\128",PropServerReference "\ACK\149W\SI*\240(Y",PropContentType +// "\161,5\SO\228\185\169yz\239Y\DC2\238\141^\DC1\245n\177u\b\158$\US7@\160",PropRetainAvailable +// 84,PropSubscriptionIdentifierAvailable 223] +TEST(Unsubscribe5QCTest, Encode9) { + uint8_t pkt[] = {0xa2, 0xe6, 0x1, 0x6b, 0x56, 0x61, 0x13, 0x42, 0xbb, 0x22, 0x57, 0x94, 0x8, 0x0, 0x1c, 0x79, 0xe0, + 0xe0, 0x6, 0x41, 0x13, 0x4c, 0x84, 0x7e, 0x12, 0x17, 0x7a, 0xf9, 0x1, 0xe6, 0xce, 0xbf, 0x67, 0x7, + 0x94, 0xaf, 0x47, 0xa, 0x68, 0x38, 0x81, 0x4, 0x6b, 0x12, 0x0, 0xc, 0xee, 0x98, 0x6e, 0xec, 0x58, + 0xf4, 0x47, 0xa1, 0x90, 0x95, 0x7, 0x80, 0x1c, 0x0, 0x8, 0x6, 0x95, 0x57, 0xf, 0x2a, 0xf0, 0x28, + 0x59, 0x3, 0x0, 0x1b, 0xa1, 0x2c, 0x35, 0xe, 0xe4, 0xb9, 0xa9, 0x79, 0x7a, 0xef, 0x59, 0x12, 0xee, + 0x8d, 0x5e, 0x11, 0xf5, 0x6e, 0xb1, 0x75, 0x8, 0x9e, 0x24, 0x1f, 0x37, 0x40, 0xa0, 0x25, 0x54, 0x29, + 0xdf, 0x0, 0x17, 0x81, 0x46, 0x14, 0xa5, 0x65, 0x78, 0x87, 0x57, 0x5e, 0xa3, 0x37, 0x5b, 0x1c, 0x80, + 0x1c, 0xbb, 0xee, 0xcb, 0xf3, 0x24, 0xca, 0x1c, 0x7, 0x0, 0x1d, 0xe4, 0x77, 0x9e, 0xf2, 0xba, 0xf9, + 0x11, 0xea, 0x7, 0xdb, 0xc6, 0xc1, 0xac, 0x87, 0x59, 0xa1, 0x89, 0x39, 0x3e, 0xd, 0x67, 0xe9, 0x20, + 0x8c, 0xeb, 0x3, 0xda, 0x5a, 0x41, 0x0, 0xb, 0x53, 0x17, 0xff, 0x77, 0x1f, 0xfa, 0xb8, 0x38, 0x45, + 0xab, 0xad, 0x0, 0x5, 0x19, 0x17, 0x38, 0x1b, 0x4e, 0x0, 0x13, 0x32, 0xe6, 0x63, 0xf6, 0xd3, 0x31, + 0xd8, 0x96, 0xca, 0xdd, 0xad, 0x77, 0x93, 0xe8, 0x24, 0x84, 0x70, 0x44, 0xec, 0x0, 0xc, 0xba, 0x9d, + 0xc9, 0xa5, 0x9e, 0xd2, 0x17, 0xe8, 0xc2, 0xec, 0x32, 0x3c, 0x0, 0x11, 0x1d, 0x5d, 0xb5, 0xb3, 0x8e, + 0xbe, 0xe6, 0xf2, 0x28, 0x26, 0xc4, 0x60, 0x8e, 0x83, 0xb8, 0x5c, 0xf3}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x79, 0xe0, 0xe0, 0x6, 0x41, 0x13, 0x4c, 0x84, 0x7e, 0x12, 0x17, 0x7a, 0xf9, 0x1, + 0xe6, 0xce, 0xbf, 0x67, 0x7, 0x94, 0xaf, 0x47, 0xa, 0x68, 0x38, 0x81, 0x4, 0x6b}; + uint8_t bytesprops1[] = {0xee, 0x98, 0x6e, 0xec, 0x58, 0xf4, 0x47, 0xa1, 0x90, 0x95, 0x7, 0x80}; + uint8_t bytesprops2[] = {0x6, 0x95, 0x57, 0xf, 0x2a, 0xf0, 0x28, 0x59}; + uint8_t bytesprops3[] = {0xa1, 0x2c, 0x35, 0xe, 0xe4, 0xb9, 0xa9, 0x79, 0x7a, 0xef, 0x59, 0x12, 0xee, 0x8d, + 0x5e, 0x11, 0xf5, 0x6e, 0xb1, 0x75, 0x8, 0x9e, 0x24, 0x1f, 0x37, 0x40, 0xa0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 17083}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 22420}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {28, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {12, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {8, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {27, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 84}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 223}}, + }; + + lwmqtt_properties_t props = {8, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0x81, 0x46, 0x14, 0xa5, 0x65, 0x78, 0x87, 0x57, 0x5e, 0xa3, 0x37, 0x5b, + 0x1c, 0x80, 0x1c, 0xbb, 0xee, 0xcb, 0xf3, 0x24, 0xca, 0x1c, 0x7}; + lwmqtt_string_t topic_filter_s0 = {23, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xe4, 0x77, 0x9e, 0xf2, 0xba, 0xf9, 0x11, 0xea, 0x7, 0xdb, + 0xc6, 0xc1, 0xac, 0x87, 0x59, 0xa1, 0x89, 0x39, 0x3e, 0xd, + 0x67, 0xe9, 0x20, 0x8c, 0xeb, 0x3, 0xda, 0x5a, 0x41}; + lwmqtt_string_t topic_filter_s1 = {29, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x53, 0x17, 0xff, 0x77, 0x1f, 0xfa, 0xb8, 0x38, 0x45, 0xab, 0xad}; + lwmqtt_string_t topic_filter_s2 = {11, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x19, 0x17, 0x38, 0x1b, 0x4e}; + lwmqtt_string_t topic_filter_s3 = {5, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x32, 0xe6, 0x63, 0xf6, 0xd3, 0x31, 0xd8, 0x96, 0xca, 0xdd, + 0xad, 0x77, 0x93, 0xe8, 0x24, 0x84, 0x70, 0x44, 0xec}; + lwmqtt_string_t topic_filter_s4 = {19, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xba, 0x9d, 0xc9, 0xa5, 0x9e, 0xd2, 0x17, 0xe8, 0xc2, 0xec, 0x32, 0x3c}; + lwmqtt_string_t topic_filter_s5 = {12, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x1d, 0x5d, 0xb5, 0xb3, 0x8e, 0xbe, 0xe6, 0xf2, 0x28, + 0x26, 0xc4, 0x60, 0x8e, 0x83, 0xb8, 0x5c, 0xf3}; + lwmqtt_string_t topic_filter_s6 = {17, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 27478, 7, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 18764 +// ["ui\144\128DK\158\RS-oM\167F\213\134\185\210)\189\188\129\201\220\&1z\155\157","\169\200\213O\SOH\206\141\139\213\236\154}\152u\176\134\227\&0N\207\EOT\156gt;\187k\159H","\206\172\214oS\145\156\204\243\DLE\210\244\SYN\139*\DC2\167B\203&\253\186\f\148\247y","-\DC4\EOTT\178\"\162\b\240\242~n2A","@\138\214D\t>7\224\205.\175\EM\SUB\209\229","\138\r\131\241\214h\241\246\&9N\203\214\a\168z!2\218\192\152wW\224","`s\ESC\204\253\132dr\189^I\148e\253\219Ef_\155\221\157\160ON\239=\148\&3\176\241","\147\146\174g\NAK;=\175\245\251\194\146\SYNT\157lYJ\a\176\255Q])\240\ESC\164L\243\138Z`\202u\183w\n\193}\159.\214\155","\255\206\142`","\208\139\240\191|\DEL\198\233\ETB\CAN\151[\DC2[\175\251vI\ETX;$\162\nv/1\179","\184\196\146D\229\218\FS\DC2\153"] +// [PropReceiveMaximum 2080,PropRequestResponseInformation 113,PropCorrelationData +// "giW\242(\SOHZ\222\181E\248\204\196&\DEL2!\195\250g\139\EMs\183\148\199\rS\156",PropMessageExpiryInterval +// 16043,PropWildcardSubscriptionAvailable 175,PropCorrelationData +// "W\146\150\EOT\143Uq\163\225",PropAuthenticationMethod "\140R$l\EOT\150\SO^\169\t",PropServerReference +// "\178\200u=;",PropUserProperty "\146<\vI=\228\166\FS@^\135P\215!\EM4\220\251" "\238]4",PropSubscriptionIdentifier +// 27,PropRequestProblemInformation 129,PropResponseInformation "\167\NUL\166\f",PropWillDelayInterval +// 9937,PropMaximumQoS 0,PropSubscriptionIdentifier 2,PropReceiveMaximum 6500,PropReasonString "\231|\165+"] +TEST(Unsubscribe5QCTest, Encode11) { + uint8_t pkt[] = { + 0xa2, 0xb0, 0x2, 0x72, 0x9c, 0x85, 0x1, 0x21, 0x8, 0x20, 0x19, 0x71, 0x9, 0x0, 0x1d, 0x67, 0x69, 0x57, 0xf2, + 0x28, 0x1, 0x5a, 0xde, 0xb5, 0x45, 0xf8, 0xcc, 0xc4, 0x26, 0x7f, 0x32, 0x21, 0xc3, 0xfa, 0x67, 0x8b, 0x19, 0x73, + 0xb7, 0x94, 0xc7, 0xd, 0x53, 0x9c, 0x2, 0x0, 0x0, 0x3e, 0xab, 0x28, 0xaf, 0x9, 0x0, 0x9, 0x57, 0x92, 0x96, + 0x4, 0x8f, 0x55, 0x71, 0xa3, 0xe1, 0x15, 0x0, 0xa, 0x8c, 0x52, 0x24, 0x6c, 0x4, 0x96, 0xe, 0x5e, 0xa9, 0x9, + 0x1c, 0x0, 0x5, 0xb2, 0xc8, 0x75, 0x3d, 0x3b, 0x26, 0x0, 0x12, 0x92, 0x3c, 0xb, 0x49, 0x3d, 0xe4, 0xa6, 0x1c, + 0x40, 0x5e, 0x87, 0x50, 0xd7, 0x21, 0x19, 0x34, 0xdc, 0xfb, 0x0, 0x3, 0xee, 0x5d, 0x34, 0xb, 0x1b, 0x17, 0x81, + 0x1a, 0x0, 0x4, 0xa7, 0x0, 0xa6, 0xc, 0x18, 0x0, 0x0, 0x26, 0xd1, 0x24, 0x0, 0xb, 0x2, 0x21, 0x19, 0x64, + 0x1f, 0x0, 0x4, 0xe7, 0x7c, 0xa5, 0x2b, 0x0, 0xb, 0x2c, 0x38, 0xde, 0x6c, 0x8d, 0xab, 0xe4, 0x96, 0x25, 0xb4, + 0xee, 0x0, 0x15, 0x66, 0x8b, 0xc6, 0xfa, 0x82, 0xad, 0xc6, 0xd9, 0x76, 0x18, 0xb1, 0x1d, 0x7e, 0x7a, 0xf4, 0xa7, + 0x2d, 0x31, 0xef, 0xf0, 0x5a, 0x0, 0x1e, 0x6d, 0x34, 0xd9, 0x3b, 0x97, 0x93, 0x39, 0x75, 0x43, 0x77, 0xfd, 0x74, + 0x4f, 0x1f, 0xff, 0x57, 0x82, 0xa4, 0x33, 0x7d, 0x23, 0x98, 0xb5, 0x8f, 0x9f, 0x51, 0x42, 0xae, 0xac, 0xab, 0x0, + 0x13, 0x32, 0xdd, 0x96, 0xbb, 0x8f, 0x30, 0xa, 0xaa, 0x44, 0x97, 0x15, 0xd1, 0xcf, 0xcb, 0x15, 0x36, 0xe9, 0xcb, + 0xa0, 0x0, 0x1e, 0x37, 0xa, 0xc, 0xf8, 0xaa, 0x81, 0x3e, 0xff, 0x51, 0x5d, 0x29, 0xf0, 0x1b, 0xa4, 0x4c, 0xf3, + 0x8a, 0x5a, 0x60, 0xca, 0x75, 0xb7, 0x77, 0xa, 0xc1, 0x7d, 0x9f, 0x2e, 0xd6, 0x9b, 0x0, 0x4, 0xff, 0xce, 0x8e, + 0x60, 0x0, 0x1b, 0xd0, 0x8b, 0xf0, 0xbf, 0x7c, 0x7f, 0xc6, 0xe9, 0x17, 0x18, 0x97, 0x5b, 0x12, 0x5b, 0xaf, 0xfb, + 0x76, 0x49, 0x3, 0x3b, 0x24, 0xa2, 0xa, 0x76, 0x2f, 0x31, 0xb3, 0x0, 0x9, 0xb8, 0xc4, 0x92, 0x44, 0xe5, 0xda, + 0x1c, 0x12, 0x99}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x67, 0x69, 0x57, 0xf2, 0x28, 0x1, 0x5a, 0xde, 0xb5, 0x45, 0xf8, 0xcc, 0xc4, 0x26, 0x7f, + 0x32, 0x21, 0xc3, 0xfa, 0x67, 0x8b, 0x19, 0x73, 0xb7, 0x94, 0xc7, 0xd, 0x53, 0x9c}; + uint8_t bytesprops1[] = {0x57, 0x92, 0x96, 0x4, 0x8f, 0x55, 0x71, 0xa3, 0xe1}; + uint8_t bytesprops2[] = {0x8c, 0x52, 0x24, 0x6c, 0x4, 0x96, 0xe, 0x5e, 0xa9, 0x9}; + uint8_t bytesprops3[] = {0xb2, 0xc8, 0x75, 0x3d, 0x3b}; + uint8_t bytesprops5[] = {0xee, 0x5d, 0x34}; + uint8_t bytesprops4[] = {0x92, 0x3c, 0xb, 0x49, 0x3d, 0xe4, 0xa6, 0x1c, 0x40, + 0x5e, 0x87, 0x50, 0xd7, 0x21, 0x19, 0x34, 0xdc, 0xfb}; + uint8_t bytesprops6[] = {0xa7, 0x0, 0xa6, 0xc}; + uint8_t bytesprops7[] = {0xe7, 0x7c, 0xa5, 0x2b}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 2080}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 113}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {29, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 16043}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 175}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {9, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {10, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {5, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {18, (char*)&bytesprops4}, .v = {3, (char*)&bytesprops5}}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 27}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 129}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {4, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 9937}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 0}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 2}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 6500}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {4, (char*)&bytesprops7}}}, + }; + + lwmqtt_properties_t props = {17, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[8]; + uint8_t topic_filter_s0_bytes[] = {0x2c, 0x38, 0xde, 0x6c, 0x8d, 0xab, 0xe4, 0x96, 0x25, 0xb4, 0xee}; + lwmqtt_string_t topic_filter_s0 = {11, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x66, 0x8b, 0xc6, 0xfa, 0x82, 0xad, 0xc6, 0xd9, 0x76, 0x18, 0xb1, + 0x1d, 0x7e, 0x7a, 0xf4, 0xa7, 0x2d, 0x31, 0xef, 0xf0, 0x5a}; + lwmqtt_string_t topic_filter_s1 = {21, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x6d, 0x34, 0xd9, 0x3b, 0x97, 0x93, 0x39, 0x75, 0x43, 0x77, + 0xfd, 0x74, 0x4f, 0x1f, 0xff, 0x57, 0x82, 0xa4, 0x33, 0x7d, + 0x23, 0x98, 0xb5, 0x8f, 0x9f, 0x51, 0x42, 0xae, 0xac, 0xab}; + lwmqtt_string_t topic_filter_s2 = {30, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x32, 0xdd, 0x96, 0xbb, 0x8f, 0x30, 0xa, 0xaa, 0x44, 0x97, + 0x15, 0xd1, 0xcf, 0xcb, 0x15, 0x36, 0xe9, 0xcb, 0xa0}; + lwmqtt_string_t topic_filter_s3 = {19, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x37, 0xa, 0xc, 0xf8, 0xaa, 0x81, 0x3e, 0xff, 0x51, 0x5d, + 0x29, 0xf0, 0x1b, 0xa4, 0x4c, 0xf3, 0x8a, 0x5a, 0x60, 0xca, + 0x75, 0xb7, 0x77, 0xa, 0xc1, 0x7d, 0x9f, 0x2e, 0xd6, 0x9b}; + lwmqtt_string_t topic_filter_s4 = {30, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xff, 0xce, 0x8e, 0x60}; + lwmqtt_string_t topic_filter_s5 = {4, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xd0, 0x8b, 0xf0, 0xbf, 0x7c, 0x7f, 0xc6, 0xe9, 0x17, 0x18, 0x97, 0x5b, 0x12, 0x5b, + 0xaf, 0xfb, 0x76, 0x49, 0x3, 0x3b, 0x24, 0xa2, 0xa, 0x76, 0x2f, 0x31, 0xb3}; + lwmqtt_string_t topic_filter_s6 = {27, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xb8, 0xc4, 0x92, 0x44, 0xe5, 0xda, 0x1c, 0x12, 0x99}; + lwmqtt_string_t topic_filter_s7 = {9, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 29340, 8, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 24289 +// ["\n\b_\177","\SO\173\150\235=\192\GSn\194\230\155","}0\US\\\211\232\235\DC1[\238\231\192\209Z\247","\234\ACK&\142\250","g\nP\ENQ%\231\181O\209\135\180\175q$\ETX75\164\168\EM\128\237\158","\245\184u\183\169S\226\171\US\SI\243\DC4x\154\DC2\228\211\195\243W\202\218\NUL\224\&5\236\132\246","\204\"i\DC4\191\234\255\177|\153\255~","m\211","m\128\ESCiS\128.\143/\172\205\144l\161\DEL[)\168y","!\183*7Kr\181\253\180,\146\166\&9\158\207T5\206\209Wx\225","\229\215Yl={\ETB\216/\212}\170\DEL"] +// [PropMessageExpiryInterval 6895,PropSubscriptionIdentifierAvailable 6,PropContentType +// "`\134XR",PropPayloadFormatIndicator 244,PropContentType "\189BOp\NUL\132 +// \176P\DC33\NUL\182Z\129*",PropSubscriptionIdentifierAvailable 152,PropCorrelationData +// "\ESCW\229\142C\171\140\236\193\194\177\SYN)\182\152\159C\204\197\&5\DC4\157\169W\241",PropSubscriptionIdentifierAvailable +// 231,PropSharedSubscriptionAvailable 219,PropPayloadFormatIndicator 212,PropRequestResponseInformation +// 233,PropServerReference "\199w\154\209'\216Y\ETB\b\GS1\133z\179\162\SYN",PropRetainAvailable 186,PropUserProperty "" +// "\249\254\252g],/\157M\177\&2u\128\188\154"] +TEST(Unsubscribe5QCTest, Encode12) { + uint8_t pkt[] = { + 0xa2, 0xa5, 0x2, 0x5e, 0xe1, 0x72, 0x2, 0x0, 0x0, 0x1a, 0xef, 0x29, 0x6, 0x3, 0x0, 0x4, 0x60, 0x86, 0x58, + 0x52, 0x1, 0xf4, 0x3, 0x0, 0x10, 0xbd, 0x42, 0x4f, 0x70, 0x0, 0x84, 0x20, 0xb0, 0x50, 0x13, 0x33, 0x0, 0xb6, + 0x5a, 0x81, 0x2a, 0x29, 0x98, 0x9, 0x0, 0x19, 0x1b, 0x57, 0xe5, 0x8e, 0x43, 0xab, 0x8c, 0xec, 0xc1, 0xc2, 0xb1, + 0x16, 0x29, 0xb6, 0x98, 0x9f, 0x43, 0xcc, 0xc5, 0x35, 0x14, 0x9d, 0xa9, 0x57, 0xf1, 0x29, 0xe7, 0x2a, 0xdb, 0x1, + 0xd4, 0x19, 0xe9, 0x1c, 0x0, 0x10, 0xc7, 0x77, 0x9a, 0xd1, 0x27, 0xd8, 0x59, 0x17, 0x8, 0x1d, 0x31, 0x85, 0x7a, + 0xb3, 0xa2, 0x16, 0x25, 0xba, 0x26, 0x0, 0x0, 0x0, 0xf, 0xf9, 0xfe, 0xfc, 0x67, 0x5d, 0x2c, 0x2f, 0x9d, 0x4d, + 0xb1, 0x32, 0x75, 0x80, 0xbc, 0x9a, 0x0, 0x4, 0xa, 0x8, 0x5f, 0xb1, 0x0, 0xb, 0xe, 0xad, 0x96, 0xeb, 0x3d, + 0xc0, 0x1d, 0x6e, 0xc2, 0xe6, 0x9b, 0x0, 0xf, 0x7d, 0x30, 0x1f, 0x5c, 0xd3, 0xe8, 0xeb, 0x11, 0x5b, 0xee, 0xe7, + 0xc0, 0xd1, 0x5a, 0xf7, 0x0, 0x5, 0xea, 0x6, 0x26, 0x8e, 0xfa, 0x0, 0x17, 0x67, 0xa, 0x50, 0x5, 0x25, 0xe7, + 0xb5, 0x4f, 0xd1, 0x87, 0xb4, 0xaf, 0x71, 0x24, 0x3, 0x37, 0x35, 0xa4, 0xa8, 0x19, 0x80, 0xed, 0x9e, 0x0, 0x1c, + 0xf5, 0xb8, 0x75, 0xb7, 0xa9, 0x53, 0xe2, 0xab, 0x1f, 0xf, 0xf3, 0x14, 0x78, 0x9a, 0x12, 0xe4, 0xd3, 0xc3, 0xf3, + 0x57, 0xca, 0xda, 0x0, 0xe0, 0x35, 0xec, 0x84, 0xf6, 0x0, 0xc, 0xcc, 0x22, 0x69, 0x14, 0xbf, 0xea, 0xff, 0xb1, + 0x7c, 0x99, 0xff, 0x7e, 0x0, 0x2, 0x6d, 0xd3, 0x0, 0x13, 0x6d, 0x80, 0x1b, 0x69, 0x53, 0x80, 0x2e, 0x8f, 0x2f, + 0xac, 0xcd, 0x90, 0x6c, 0xa1, 0x7f, 0x5b, 0x29, 0xa8, 0x79, 0x0, 0x16, 0x21, 0xb7, 0x2a, 0x37, 0x4b, 0x72, 0xb5, + 0xfd, 0xb4, 0x2c, 0x92, 0xa6, 0x39, 0x9e, 0xcf, 0x54, 0x35, 0xce, 0xd1, 0x57, 0x78, 0xe1, 0x0, 0xd, 0xe5, 0xd7, + 0x59, 0x6c, 0x3d, 0x7b, 0x17, 0xd8, 0x2f, 0xd4, 0x7d, 0xaa, 0x7f}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x60, 0x86, 0x58, 0x52}; + uint8_t bytesprops1[] = {0xbd, 0x42, 0x4f, 0x70, 0x0, 0x84, 0x20, 0xb0, + 0x50, 0x13, 0x33, 0x0, 0xb6, 0x5a, 0x81, 0x2a}; + uint8_t bytesprops2[] = {0x1b, 0x57, 0xe5, 0x8e, 0x43, 0xab, 0x8c, 0xec, 0xc1, 0xc2, 0xb1, 0x16, 0x29, + 0xb6, 0x98, 0x9f, 0x43, 0xcc, 0xc5, 0x35, 0x14, 0x9d, 0xa9, 0x57, 0xf1}; + uint8_t bytesprops3[] = {0xc7, 0x77, 0x9a, 0xd1, 0x27, 0xd8, 0x59, 0x17, + 0x8, 0x1d, 0x31, 0x85, 0x7a, 0xb3, 0xa2, 0x16}; + uint8_t bytesprops5[] = {0xf9, 0xfe, 0xfc, 0x67, 0x5d, 0x2c, 0x2f, 0x9d, 0x4d, 0xb1, 0x32, 0x75, 0x80, 0xbc, 0x9a}; + uint8_t bytesprops4[] = {0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 6895}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 6}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {4, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 244}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {16, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 152}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {25, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 231}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 219}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 212}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 233}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {16, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 186}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {0, (char*)&bytesprops4}, .v = {15, (char*)&bytesprops5}}}}, + }; + + lwmqtt_properties_t props = {14, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0xa, 0x8, 0x5f, 0xb1}; + lwmqtt_string_t topic_filter_s0 = {4, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xe, 0xad, 0x96, 0xeb, 0x3d, 0xc0, 0x1d, 0x6e, 0xc2, 0xe6, 0x9b}; + lwmqtt_string_t topic_filter_s1 = {11, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x7d, 0x30, 0x1f, 0x5c, 0xd3, 0xe8, 0xeb, 0x11, + 0x5b, 0xee, 0xe7, 0xc0, 0xd1, 0x5a, 0xf7}; + lwmqtt_string_t topic_filter_s2 = {15, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xea, 0x6, 0x26, 0x8e, 0xfa}; + lwmqtt_string_t topic_filter_s3 = {5, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x67, 0xa, 0x50, 0x5, 0x25, 0xe7, 0xb5, 0x4f, 0xd1, 0x87, 0xb4, 0xaf, + 0x71, 0x24, 0x3, 0x37, 0x35, 0xa4, 0xa8, 0x19, 0x80, 0xed, 0x9e}; + lwmqtt_string_t topic_filter_s4 = {23, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xf5, 0xb8, 0x75, 0xb7, 0xa9, 0x53, 0xe2, 0xab, 0x1f, 0xf, + 0xf3, 0x14, 0x78, 0x9a, 0x12, 0xe4, 0xd3, 0xc3, 0xf3, 0x57, + 0xca, 0xda, 0x0, 0xe0, 0x35, 0xec, 0x84, 0xf6}; + lwmqtt_string_t topic_filter_s5 = {28, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xcc, 0x22, 0x69, 0x14, 0xbf, 0xea, 0xff, 0xb1, 0x7c, 0x99, 0xff, 0x7e}; + lwmqtt_string_t topic_filter_s6 = {12, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x6d, 0xd3}; + lwmqtt_string_t topic_filter_s7 = {2, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x6d, 0x80, 0x1b, 0x69, 0x53, 0x80, 0x2e, 0x8f, 0x2f, 0xac, + 0xcd, 0x90, 0x6c, 0xa1, 0x7f, 0x5b, 0x29, 0xa8, 0x79}; + lwmqtt_string_t topic_filter_s8 = {19, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x21, 0xb7, 0x2a, 0x37, 0x4b, 0x72, 0xb5, 0xfd, 0xb4, 0x2c, 0x92, + 0xa6, 0x39, 0x9e, 0xcf, 0x54, 0x35, 0xce, 0xd1, 0x57, 0x78, 0xe1}; + lwmqtt_string_t topic_filter_s9 = {22, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0xe5, 0xd7, 0x59, 0x6c, 0x3d, 0x7b, 0x17, 0xd8, 0x2f, 0xd4, 0x7d, 0xaa, 0x7f}; + lwmqtt_string_t topic_filter_s10 = {13, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 24289, 11, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 26276 +// ["U^\138\255\DC2\173G\168Q\178\rw8ZS","\162\\\255\SOHI\247\ETB\199\148e\254\245\221\242\129\161\181_\214\DEL","\166\180j +// ","m\DLEV\240\&7\150\DC1\248lX\136\130\205]\233\142NLy\tB\251ll,`\155E\143\138","\141\GS\195\177)_)w9C\234\132H\154\DC1J\147","\213\215P","\247\239\158","\226\165#\135\230;\245\233\171}","\202>m\132\GS9\145\246\137\NAK\237Q"] +// [PropReceiveMaximum 23093,PropPayloadFormatIndicator 98,PropAuthenticationData +// "d\SYN\182X\129Gu{h\ENQ\223\\\SO\DC4+\169\203\196\249\216Z\174\185",PropTopicAlias 20078,PropMaximumPacketSize +// 13310,PropContentType "\NAK\183@\DC2Y\131$\139\131yr$\224\247\189{",PropMessageExpiryInterval 13599] +TEST(Unsubscribe5QCTest, Encode13) { + uint8_t pkt[] = {0xa2, 0xc6, 0x1, 0x66, 0xa4, 0x3f, 0x21, 0x5a, 0x35, 0x1, 0x62, 0x16, 0x0, 0x17, 0x64, 0x16, 0xb6, + 0x58, 0x81, 0x47, 0x75, 0x7b, 0x68, 0x5, 0xdf, 0x5c, 0xe, 0x14, 0x2b, 0xa9, 0xcb, 0xc4, 0xf9, 0xd8, + 0x5a, 0xae, 0xb9, 0x23, 0x4e, 0x6e, 0x27, 0x0, 0x0, 0x33, 0xfe, 0x3, 0x0, 0x10, 0x15, 0xb7, 0x40, + 0x12, 0x59, 0x83, 0x24, 0x8b, 0x83, 0x79, 0x72, 0x24, 0xe0, 0xf7, 0xbd, 0x7b, 0x2, 0x0, 0x0, 0x35, + 0x1f, 0x0, 0xf, 0x55, 0x5e, 0x8a, 0xff, 0x12, 0xad, 0x47, 0xa8, 0x51, 0xb2, 0xd, 0x77, 0x38, 0x5a, + 0x53, 0x0, 0x14, 0xa2, 0x5c, 0xff, 0x1, 0x49, 0xf7, 0x17, 0xc7, 0x94, 0x65, 0xfe, 0xf5, 0xdd, 0xf2, + 0x81, 0xa1, 0xb5, 0x5f, 0xd6, 0x7f, 0x0, 0x4, 0xa6, 0xb4, 0x6a, 0x20, 0x0, 0x1e, 0x6d, 0x10, 0x56, + 0xf0, 0x37, 0x96, 0x11, 0xf8, 0x6c, 0x58, 0x88, 0x82, 0xcd, 0x5d, 0xe9, 0x8e, 0x4e, 0x4c, 0x79, 0x9, + 0x42, 0xfb, 0x6c, 0x6c, 0x2c, 0x60, 0x9b, 0x45, 0x8f, 0x8a, 0x0, 0x11, 0x8d, 0x1d, 0xc3, 0xb1, 0x29, + 0x5f, 0x29, 0x77, 0x39, 0x43, 0xea, 0x84, 0x48, 0x9a, 0x11, 0x4a, 0x93, 0x0, 0x3, 0xd5, 0xd7, 0x50, + 0x0, 0x3, 0xf7, 0xef, 0x9e, 0x0, 0xa, 0xe2, 0xa5, 0x23, 0x87, 0xe6, 0x3b, 0xf5, 0xe9, 0xab, 0x7d, + 0x0, 0xc, 0xca, 0x3e, 0x6d, 0x84, 0x1d, 0x39, 0x91, 0xf6, 0x89, 0x15, 0xed, 0x51}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x64, 0x16, 0xb6, 0x58, 0x81, 0x47, 0x75, 0x7b, 0x68, 0x5, 0xdf, 0x5c, + 0xe, 0x14, 0x2b, 0xa9, 0xcb, 0xc4, 0xf9, 0xd8, 0x5a, 0xae, 0xb9}; + uint8_t bytesprops1[] = {0x15, 0xb7, 0x40, 0x12, 0x59, 0x83, 0x24, 0x8b, + 0x83, 0x79, 0x72, 0x24, 0xe0, 0xf7, 0xbd, 0x7b}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 23093}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 98}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {23, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 20078}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 13310}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {16, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 13599}}, + }; + + lwmqtt_properties_t props = {7, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[9]; + uint8_t topic_filter_s0_bytes[] = {0x55, 0x5e, 0x8a, 0xff, 0x12, 0xad, 0x47, 0xa8, + 0x51, 0xb2, 0xd, 0x77, 0x38, 0x5a, 0x53}; + lwmqtt_string_t topic_filter_s0 = {15, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xa2, 0x5c, 0xff, 0x1, 0x49, 0xf7, 0x17, 0xc7, 0x94, 0x65, + 0xfe, 0xf5, 0xdd, 0xf2, 0x81, 0xa1, 0xb5, 0x5f, 0xd6, 0x7f}; + lwmqtt_string_t topic_filter_s1 = {20, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xa6, 0xb4, 0x6a, 0x20}; + lwmqtt_string_t topic_filter_s2 = {4, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x6d, 0x10, 0x56, 0xf0, 0x37, 0x96, 0x11, 0xf8, 0x6c, 0x58, + 0x88, 0x82, 0xcd, 0x5d, 0xe9, 0x8e, 0x4e, 0x4c, 0x79, 0x9, + 0x42, 0xfb, 0x6c, 0x6c, 0x2c, 0x60, 0x9b, 0x45, 0x8f, 0x8a}; + lwmqtt_string_t topic_filter_s3 = {30, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x8d, 0x1d, 0xc3, 0xb1, 0x29, 0x5f, 0x29, 0x77, 0x39, + 0x43, 0xea, 0x84, 0x48, 0x9a, 0x11, 0x4a, 0x93}; + lwmqtt_string_t topic_filter_s4 = {17, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xd5, 0xd7, 0x50}; + lwmqtt_string_t topic_filter_s5 = {3, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xf7, 0xef, 0x9e}; + lwmqtt_string_t topic_filter_s6 = {3, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xe2, 0xa5, 0x23, 0x87, 0xe6, 0x3b, 0xf5, 0xe9, 0xab, 0x7d}; + lwmqtt_string_t topic_filter_s7 = {10, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xca, 0x3e, 0x6d, 0x84, 0x1d, 0x39, 0x91, 0xf6, 0x89, 0x15, 0xed, 0x51}; + lwmqtt_string_t topic_filter_s8 = {12, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 26276, 9, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 10986 ["\211N\246\229\152\243\228\134\131\ETX\138\162\&1\EOT\161\135L\163\147\186\NUL"] +// [PropTopicAlias 18907,PropRequestResponseInformation 76,PropMaximumQoS 0,PropUserProperty +// "\139\173\bi-\151rW\178\186\132\&8s\205U\153\230\216\bn7D\136\FS\SUB\fC" +// ";\144\&9\160\&0\173\236{\EOT\156l:\RS",PropWildcardSubscriptionAvailable 142,PropPayloadFormatIndicator +// 8,PropRequestProblemInformation 96] +TEST(Unsubscribe5QCTest, Encode14) { + uint8_t pkt[] = {0xa2, 0x54, 0x2a, 0xea, 0x3a, 0x23, 0x49, 0xdb, 0x19, 0x4c, 0x24, 0x0, 0x26, 0x0, 0x1b, + 0x8b, 0xad, 0x8, 0x69, 0x2d, 0x97, 0x72, 0x57, 0xb2, 0xba, 0x84, 0x38, 0x73, 0xcd, 0x55, + 0x99, 0xe6, 0xd8, 0x8, 0x6e, 0x37, 0x44, 0x88, 0x1c, 0x1a, 0xc, 0x43, 0x0, 0xd, 0x3b, + 0x90, 0x39, 0xa0, 0x30, 0xad, 0xec, 0x7b, 0x4, 0x9c, 0x6c, 0x3a, 0x1e, 0x28, 0x8e, 0x1, + 0x8, 0x17, 0x60, 0x0, 0x15, 0xd3, 0x4e, 0xf6, 0xe5, 0x98, 0xf3, 0xe4, 0x86, 0x83, 0x3, + 0x8a, 0xa2, 0x31, 0x4, 0xa1, 0x87, 0x4c, 0xa3, 0x93, 0xba, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops1[] = {0x3b, 0x90, 0x39, 0xa0, 0x30, 0xad, 0xec, 0x7b, 0x4, 0x9c, 0x6c, 0x3a, 0x1e}; + uint8_t bytesprops0[] = {0x8b, 0xad, 0x8, 0x69, 0x2d, 0x97, 0x72, 0x57, 0xb2, 0xba, 0x84, 0x38, 0x73, 0xcd, + 0x55, 0x99, 0xe6, 0xd8, 0x8, 0x6e, 0x37, 0x44, 0x88, 0x1c, 0x1a, 0xc, 0x43}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 18907}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 76}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 0}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {27, (char*)&bytesprops0}, .v = {13, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 142}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 8}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 96}}, + }; + + lwmqtt_properties_t props = {7, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0xd3, 0x4e, 0xf6, 0xe5, 0x98, 0xf3, 0xe4, 0x86, 0x83, 0x3, 0x8a, + 0xa2, 0x31, 0x4, 0xa1, 0x87, 0x4c, 0xa3, 0x93, 0xba, 0x0}; + lwmqtt_string_t topic_filter_s0 = {21, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 10986, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 4312 +// ["\193\221H\191\161\206J\DC1\180\232?","P\140\182\141z\SOH\RS\130=\215\199\SI\253\203k\169","\230\174","\186c\168Ddi\167\152\197"] +// [PropReasonString "\177\DC1\245i\223\170\f",PropTopicAlias 8170,PropRequestProblemInformation 127,PropUserProperty +// "\r#\170" "!\212| ",PropSessionExpiryInterval 9961,PropCorrelationData "}\CAN\228M_\210.\ACKV",PropMaximumPacketSize +// 23538,PropResponseInformation +// "\231\249\219eT\159\180\203\200\191R\EOTV}\195\252r\157\212\")\146\213\"o\140",PropSubscriptionIdentifier +// 1,PropAssignedClientIdentifier "\SOz\177\229\185\134\132",PropMaximumPacketSize 21322,PropMessageExpiryInterval +// 19426] +TEST(Unsubscribe5QCTest, Encode15) { + uint8_t pkt[] = {0xa2, 0x95, 0x1, 0x10, 0xd8, 0x64, 0x1f, 0x0, 0x7, 0xb1, 0x11, 0xf5, 0x69, 0xdf, 0xaa, 0xc, 0x23, + 0x1f, 0xea, 0x17, 0x7f, 0x26, 0x0, 0x3, 0xd, 0x23, 0xaa, 0x0, 0x4, 0x21, 0xd4, 0x7c, 0x20, 0x11, + 0x0, 0x0, 0x26, 0xe9, 0x9, 0x0, 0x9, 0x7d, 0x18, 0xe4, 0x4d, 0x5f, 0xd2, 0x2e, 0x6, 0x56, 0x27, + 0x0, 0x0, 0x5b, 0xf2, 0x1a, 0x0, 0x1a, 0xe7, 0xf9, 0xdb, 0x65, 0x54, 0x9f, 0xb4, 0xcb, 0xc8, 0xbf, + 0x52, 0x4, 0x56, 0x7d, 0xc3, 0xfc, 0x72, 0x9d, 0xd4, 0x22, 0x29, 0x92, 0xd5, 0x22, 0x6f, 0x8c, 0xb, + 0x1, 0x12, 0x0, 0x7, 0xe, 0x7a, 0xb1, 0xe5, 0xb9, 0x86, 0x84, 0x27, 0x0, 0x0, 0x53, 0x4a, 0x2, + 0x0, 0x0, 0x4b, 0xe2, 0x0, 0xb, 0xc1, 0xdd, 0x48, 0xbf, 0xa1, 0xce, 0x4a, 0x11, 0xb4, 0xe8, 0x3f, + 0x0, 0x10, 0x50, 0x8c, 0xb6, 0x8d, 0x7a, 0x1, 0x1e, 0x82, 0x3d, 0xd7, 0xc7, 0xf, 0xfd, 0xcb, 0x6b, + 0xa9, 0x0, 0x2, 0xe6, 0xae, 0x0, 0x9, 0xba, 0x63, 0xa8, 0x44, 0x64, 0x69, 0xa7, 0x98, 0xc5}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xb1, 0x11, 0xf5, 0x69, 0xdf, 0xaa, 0xc}; + uint8_t bytesprops2[] = {0x21, 0xd4, 0x7c, 0x20}; + uint8_t bytesprops1[] = {0xd, 0x23, 0xaa}; + uint8_t bytesprops3[] = {0x7d, 0x18, 0xe4, 0x4d, 0x5f, 0xd2, 0x2e, 0x6, 0x56}; + uint8_t bytesprops4[] = {0xe7, 0xf9, 0xdb, 0x65, 0x54, 0x9f, 0xb4, 0xcb, 0xc8, 0xbf, 0x52, 0x4, 0x56, + 0x7d, 0xc3, 0xfc, 0x72, 0x9d, 0xd4, 0x22, 0x29, 0x92, 0xd5, 0x22, 0x6f, 0x8c}; + uint8_t bytesprops5[] = {0xe, 0x7a, 0xb1, 0xe5, 0xb9, 0x86, 0x84}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)31, .value = {.str = {7, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 8170}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 127}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {3, (char*)&bytesprops1}, .v = {4, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 9961}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {9, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 23538}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {26, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 1}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {7, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 21322}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 19426}}, + }; + + lwmqtt_properties_t props = {12, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[4]; + uint8_t topic_filter_s0_bytes[] = {0xc1, 0xdd, 0x48, 0xbf, 0xa1, 0xce, 0x4a, 0x11, 0xb4, 0xe8, 0x3f}; + lwmqtt_string_t topic_filter_s0 = {11, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x50, 0x8c, 0xb6, 0x8d, 0x7a, 0x1, 0x1e, 0x82, + 0x3d, 0xd7, 0xc7, 0xf, 0xfd, 0xcb, 0x6b, 0xa9}; + lwmqtt_string_t topic_filter_s1 = {16, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xe6, 0xae}; + lwmqtt_string_t topic_filter_s2 = {2, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xba, 0x63, 0xa8, 0x44, 0x64, 0x69, 0xa7, 0x98, 0xc5}; + lwmqtt_string_t topic_filter_s3 = {9, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 4312, 4, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 12998 ["\f\217\182 +\CAN\154)2\SO"] [PropCorrelationData +// "\232\193\192zR",PropSubscriptionIdentifierAvailable 146,PropAuthenticationMethod +// "\249\140^\USFo\247o\136\211\&7r)Q\159Q3\228\&3\146\136Zl\145\ESC}",PropReceiveMaximum 5706,PropMaximumPacketSize +// 18696,PropResponseTopic +// "\135\224F\CAN\251\251\DC2\251\180!yd/;O\215$\162\ESC\224\&8}g\133\165\DEL",PropSessionExpiryInterval +// 10454,PropWillDelayInterval 4333,PropTopicAlias 1873,PropSubscriptionIdentifier 20,PropMaximumQoS +// 85,PropSharedSubscriptionAvailable 53,PropWildcardSubscriptionAvailable 206,PropServerKeepAlive +// 14411,PropSubscriptionIdentifierAvailable 22] +TEST(Unsubscribe5QCTest, Encode16) { + uint8_t pkt[] = {0xa2, 0x75, 0x32, 0xc6, 0x66, 0x9, 0x0, 0x5, 0xe8, 0xc1, 0xc0, 0x7a, 0x52, 0x29, 0x92, 0x15, 0x0, + 0x1a, 0xf9, 0x8c, 0x5e, 0x1f, 0x46, 0x6f, 0xf7, 0x6f, 0x88, 0xd3, 0x37, 0x72, 0x29, 0x51, 0x9f, 0x51, + 0x33, 0xe4, 0x33, 0x92, 0x88, 0x5a, 0x6c, 0x91, 0x1b, 0x7d, 0x21, 0x16, 0x4a, 0x27, 0x0, 0x0, 0x49, + 0x8, 0x8, 0x0, 0x1a, 0x87, 0xe0, 0x46, 0x18, 0xfb, 0xfb, 0x12, 0xfb, 0xb4, 0x21, 0x79, 0x64, 0x2f, + 0x3b, 0x4f, 0xd7, 0x24, 0xa2, 0x1b, 0xe0, 0x38, 0x7d, 0x67, 0x85, 0xa5, 0x7f, 0x11, 0x0, 0x0, 0x28, + 0xd6, 0x18, 0x0, 0x0, 0x10, 0xed, 0x23, 0x7, 0x51, 0xb, 0x14, 0x24, 0x55, 0x2a, 0x35, 0x28, 0xce, + 0x13, 0x38, 0x4b, 0x29, 0x16, 0x0, 0xa, 0xc, 0xd9, 0xb6, 0x20, 0x2b, 0x18, 0x9a, 0x29, 0x32, 0xe}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xe8, 0xc1, 0xc0, 0x7a, 0x52}; + uint8_t bytesprops1[] = {0xf9, 0x8c, 0x5e, 0x1f, 0x46, 0x6f, 0xf7, 0x6f, 0x88, 0xd3, 0x37, 0x72, 0x29, + 0x51, 0x9f, 0x51, 0x33, 0xe4, 0x33, 0x92, 0x88, 0x5a, 0x6c, 0x91, 0x1b, 0x7d}; + uint8_t bytesprops2[] = {0x87, 0xe0, 0x46, 0x18, 0xfb, 0xfb, 0x12, 0xfb, 0xb4, 0x21, 0x79, 0x64, 0x2f, + 0x3b, 0x4f, 0xd7, 0x24, 0xa2, 0x1b, 0xe0, 0x38, 0x7d, 0x67, 0x85, 0xa5, 0x7f}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)9, .value = {.str = {5, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 146}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {26, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 5706}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 18696}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {26, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 10454}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 4333}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 1873}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 20}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 85}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 53}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 206}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 14411}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 22}}, + }; + + lwmqtt_properties_t props = {15, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0xc, 0xd9, 0xb6, 0x20, 0x2b, 0x18, 0x9a, 0x29, 0x32, 0xe}; + lwmqtt_string_t topic_filter_s0 = {10, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 12998, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 22695 +// ["\US=Q\130p\186\189<~\223\ETB\159\172\RS\"","\154\US\251v\173\148cR#\242{2&OX","","\207\130ja\252\230","w\208\209\&7\221\NAK\201\a\158"," +// \144\157t\SI\181?\209\217\255\240\SUB","\142v\242\219\199","\245v\238\\\DC3D\195\196\EM\a\252\245\160@F\f\226O\180\243YQ7\US\252\242","*\r#(\235\ETX3","\ETB\203\154\ENQ\171sq\ESC","\DC4w\144)\254\161\166\132@\214j\FSn\209A\DLE\fuHCo>\206fKmw"] +// [PropWillDelayInterval 19852,PropReceiveMaximum 13317,PropMessageExpiryInterval 19311,PropAuthenticationMethod +// "\195\206\DC2\n\244\188C\248:y\183\188\214\237\254\249\t\211\137)\"\194\240p\144\229\a",PropPayloadFormatIndicator +// 116,PropRetainAvailable 185,PropReasonString "\155#\US84+\166\138>\196\230\am~%\v\208@H",PropReasonString +// "\171\n\224\246\160+\199\162\239\143y_\205\174",PropMaximumPacketSize 19819,PropReceiveMaximum +// 21214,PropServerReference "",PropTopicAliasMaximum 24480,PropServerKeepAlive 31268,PropReasonString +// "Ru\f\133\174*;\DC2\142!\247o\179\STX\151\181\148\224\SO",PropAssignedClientIdentifier +// "h\181\180\&8\128\233d\175\"\186\180f\244\161\240\133!\188\130u~b\191\151\240=\164DQ\159"] +TEST(Unsubscribe5QCTest, Encode17) { + uint8_t pkt[] = { + 0xa2, 0xba, 0x2, 0x58, 0xa7, 0x9e, 0x1, 0x18, 0x0, 0x0, 0x4d, 0x8c, 0x21, 0x34, 0x5, 0x2, 0x0, 0x0, 0x4b, + 0x6f, 0x15, 0x0, 0x1b, 0xc3, 0xce, 0x12, 0xa, 0xf4, 0xbc, 0x43, 0xf8, 0x3a, 0x79, 0xb7, 0xbc, 0xd6, 0xed, 0xfe, + 0xf9, 0x9, 0xd3, 0x89, 0x29, 0x22, 0xc2, 0xf0, 0x70, 0x90, 0xe5, 0x7, 0x1, 0x74, 0x25, 0xb9, 0x1f, 0x0, 0x13, + 0x9b, 0x23, 0x1f, 0x38, 0x34, 0x2b, 0xa6, 0x8a, 0x3e, 0xc4, 0xe6, 0x7, 0x6d, 0x7e, 0x25, 0xb, 0xd0, 0x40, 0x48, + 0x1f, 0x0, 0xe, 0xab, 0xa, 0xe0, 0xf6, 0xa0, 0x2b, 0xc7, 0xa2, 0xef, 0x8f, 0x79, 0x5f, 0xcd, 0xae, 0x27, 0x0, + 0x0, 0x4d, 0x6b, 0x21, 0x52, 0xde, 0x1c, 0x0, 0x0, 0x22, 0x5f, 0xa0, 0x13, 0x7a, 0x24, 0x1f, 0x0, 0x13, 0x52, + 0x75, 0xc, 0x85, 0xae, 0x2a, 0x3b, 0x12, 0x8e, 0x21, 0xf7, 0x6f, 0xb3, 0x2, 0x97, 0xb5, 0x94, 0xe0, 0xe, 0x12, + 0x0, 0x1e, 0x68, 0xb5, 0xb4, 0x38, 0x80, 0xe9, 0x64, 0xaf, 0x22, 0xba, 0xb4, 0x66, 0xf4, 0xa1, 0xf0, 0x85, 0x21, + 0xbc, 0x82, 0x75, 0x7e, 0x62, 0xbf, 0x97, 0xf0, 0x3d, 0xa4, 0x44, 0x51, 0x9f, 0x0, 0xf, 0x1f, 0x3d, 0x51, 0x82, + 0x70, 0xba, 0xbd, 0x3c, 0x7e, 0xdf, 0x17, 0x9f, 0xac, 0x1e, 0x22, 0x0, 0xf, 0x9a, 0x1f, 0xfb, 0x76, 0xad, 0x94, + 0x63, 0x52, 0x23, 0xf2, 0x7b, 0x32, 0x26, 0x4f, 0x58, 0x0, 0x0, 0x0, 0x6, 0xcf, 0x82, 0x6a, 0x61, 0xfc, 0xe6, + 0x0, 0x9, 0x77, 0xd0, 0xd1, 0x37, 0xdd, 0x15, 0xc9, 0x7, 0x9e, 0x0, 0xc, 0x20, 0x90, 0x9d, 0x74, 0xf, 0xb5, + 0x3f, 0xd1, 0xd9, 0xff, 0xf0, 0x1a, 0x0, 0x5, 0x8e, 0x76, 0xf2, 0xdb, 0xc7, 0x0, 0x1a, 0xf5, 0x76, 0xee, 0x5c, + 0x13, 0x44, 0xc3, 0xc4, 0x19, 0x7, 0xfc, 0xf5, 0xa0, 0x40, 0x46, 0xc, 0xe2, 0x4f, 0xb4, 0xf3, 0x59, 0x51, 0x37, + 0x1f, 0xfc, 0xf2, 0x0, 0x7, 0x2a, 0xd, 0x23, 0x28, 0xeb, 0x3, 0x33, 0x0, 0x8, 0x17, 0xcb, 0x9a, 0x5, 0xab, + 0x73, 0x71, 0x1b, 0x0, 0x1b, 0x14, 0x77, 0x90, 0x29, 0xfe, 0xa1, 0xa6, 0x84, 0x40, 0xd6, 0x6a, 0x1c, 0x6e, 0xd1, + 0x41, 0x10, 0xc, 0x75, 0x48, 0x43, 0x6f, 0x3e, 0xce, 0x66, 0x4b, 0x6d, 0x77}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xc3, 0xce, 0x12, 0xa, 0xf4, 0xbc, 0x43, 0xf8, 0x3a, 0x79, 0xb7, 0xbc, 0xd6, 0xed, + 0xfe, 0xf9, 0x9, 0xd3, 0x89, 0x29, 0x22, 0xc2, 0xf0, 0x70, 0x90, 0xe5, 0x7}; + uint8_t bytesprops1[] = {0x9b, 0x23, 0x1f, 0x38, 0x34, 0x2b, 0xa6, 0x8a, 0x3e, 0xc4, + 0xe6, 0x7, 0x6d, 0x7e, 0x25, 0xb, 0xd0, 0x40, 0x48}; + uint8_t bytesprops2[] = {0xab, 0xa, 0xe0, 0xf6, 0xa0, 0x2b, 0xc7, 0xa2, 0xef, 0x8f, 0x79, 0x5f, 0xcd, 0xae}; + uint8_t bytesprops3[] = {0}; + uint8_t bytesprops4[] = {0x52, 0x75, 0xc, 0x85, 0xae, 0x2a, 0x3b, 0x12, 0x8e, 0x21, + 0xf7, 0x6f, 0xb3, 0x2, 0x97, 0xb5, 0x94, 0xe0, 0xe}; + uint8_t bytesprops5[] = {0x68, 0xb5, 0xb4, 0x38, 0x80, 0xe9, 0x64, 0xaf, 0x22, 0xba, 0xb4, 0x66, 0xf4, 0xa1, 0xf0, + 0x85, 0x21, 0xbc, 0x82, 0x75, 0x7e, 0x62, 0xbf, 0x97, 0xf0, 0x3d, 0xa4, 0x44, 0x51, 0x9f}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 19852}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 13317}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 19311}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {27, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 116}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 185}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {19, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {14, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 19819}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 21214}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {0, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 24480}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 31268}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {19, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {30, (char*)&bytesprops5}}}, + }; + + lwmqtt_properties_t props = {15, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0x1f, 0x3d, 0x51, 0x82, 0x70, 0xba, 0xbd, 0x3c, + 0x7e, 0xdf, 0x17, 0x9f, 0xac, 0x1e, 0x22}; + lwmqtt_string_t topic_filter_s0 = {15, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x9a, 0x1f, 0xfb, 0x76, 0xad, 0x94, 0x63, 0x52, + 0x23, 0xf2, 0x7b, 0x32, 0x26, 0x4f, 0x58}; + lwmqtt_string_t topic_filter_s1 = {15, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0}; + lwmqtt_string_t topic_filter_s2 = {0, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xcf, 0x82, 0x6a, 0x61, 0xfc, 0xe6}; + lwmqtt_string_t topic_filter_s3 = {6, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x77, 0xd0, 0xd1, 0x37, 0xdd, 0x15, 0xc9, 0x7, 0x9e}; + lwmqtt_string_t topic_filter_s4 = {9, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x20, 0x90, 0x9d, 0x74, 0xf, 0xb5, 0x3f, 0xd1, 0xd9, 0xff, 0xf0, 0x1a}; + lwmqtt_string_t topic_filter_s5 = {12, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x8e, 0x76, 0xf2, 0xdb, 0xc7}; + lwmqtt_string_t topic_filter_s6 = {5, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xf5, 0x76, 0xee, 0x5c, 0x13, 0x44, 0xc3, 0xc4, 0x19, 0x7, 0xfc, 0xf5, 0xa0, + 0x40, 0x46, 0xc, 0xe2, 0x4f, 0xb4, 0xf3, 0x59, 0x51, 0x37, 0x1f, 0xfc, 0xf2}; + lwmqtt_string_t topic_filter_s7 = {26, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x2a, 0xd, 0x23, 0x28, 0xeb, 0x3, 0x33}; + lwmqtt_string_t topic_filter_s8 = {7, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x17, 0xcb, 0x9a, 0x5, 0xab, 0x73, 0x71, 0x1b}; + lwmqtt_string_t topic_filter_s9 = {8, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0x14, 0x77, 0x90, 0x29, 0xfe, 0xa1, 0xa6, 0x84, 0x40, + 0xd6, 0x6a, 0x1c, 0x6e, 0xd1, 0x41, 0x10, 0xc, 0x75, + 0x48, 0x43, 0x6f, 0x3e, 0xce, 0x66, 0x4b, 0x6d, 0x77}; + lwmqtt_string_t topic_filter_s10 = {27, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 22695, 11, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 6495 +// ["\144\187\SI\200\142y'N)^\214\NAK?\219\158\254U\230%dp\180","\136\DC3j\179'\202\200\245\NUL","\203'UwJf\198\144=(\SUB\t2\239\vn\ETX\STX\143\223\198\247","\203\207^\SUB\210\&1\139\213N\188\224\207\190\140","\ETB\201","w\233no\170\133\141i\142\ACK\178rv\222\&1\141\195\143U","12","","\181/"] +// [PropAuthenticationData "\ETB\141M\251\\Di",PropTopicAlias 9249,PropRetainAvailable 236,PropCorrelationData +// "0\178\161\SO\235:\233\221\233\181g\232\139",PropUserProperty "" +// "\238\DLE\164s,t\159\NAK\211\SOH\147\141p4\186\166\229\194v\GS\153\218\199\156l\130\160\238\242",PropReasonString +// "\141\NAK\237\131\240*)\SYNGp\157\251\DC3",PropReceiveMaximum 26390,PropWildcardSubscriptionAvailable +// 42,PropRequestResponseInformation 136,PropWildcardSubscriptionAvailable 16,PropMessageExpiryInterval +// 19909,PropAuthenticationMethod "\164\190\213\217\185j\156\214\133>\212x\SI\139\168X",PropRetainAvailable +// 67,PropReasonString "\137\ESC\209\247\203+\146FV",PropServerKeepAlive 24742,PropSubscriptionIdentifierAvailable +// 23,PropResponseTopic "\183\&4\141\SI0/\203=\SOi\GS",PropContentType "|\SUB",PropMessageExpiryInterval +// 1260,PropRequestResponseInformation 179,PropAssignedClientIdentifier "6+S\200l\SYN\211<\195?",PropMaximumQoS +// 9,PropReceiveMaximum 28565,PropRetainAvailable 217,PropReasonString +// "\233\"A\176\ETX\223\221\210B7b7\148s\144\&7\198F}\168\198\&4\SIqD~\228\251E\SUB",PropSubscriptionIdentifier +// 29,PropPayloadFormatIndicator 197,PropCorrelationData "\CAN\NUL.\235B\247\182",PropServerReference +// "V\209",PropServerKeepAlive 6395] +TEST(Unsubscribe5QCTest, Encode18) { + uint8_t pkt[] = { + 0xa2, 0xdc, 0x2, 0x19, 0x5f, 0xea, 0x1, 0x16, 0x0, 0x7, 0x17, 0x8d, 0x4d, 0xfb, 0x5c, 0x44, 0x69, 0x23, 0x24, + 0x21, 0x25, 0xec, 0x9, 0x0, 0xd, 0x30, 0xb2, 0xa1, 0xe, 0xeb, 0x3a, 0xe9, 0xdd, 0xe9, 0xb5, 0x67, 0xe8, 0x8b, + 0x26, 0x0, 0x0, 0x0, 0x1d, 0xee, 0x10, 0xa4, 0x73, 0x2c, 0x74, 0x9f, 0x15, 0xd3, 0x1, 0x93, 0x8d, 0x70, 0x34, + 0xba, 0xa6, 0xe5, 0xc2, 0x76, 0x1d, 0x99, 0xda, 0xc7, 0x9c, 0x6c, 0x82, 0xa0, 0xee, 0xf2, 0x1f, 0x0, 0xd, 0x8d, + 0x15, 0xed, 0x83, 0xf0, 0x2a, 0x29, 0x16, 0x47, 0x70, 0x9d, 0xfb, 0x13, 0x21, 0x67, 0x16, 0x28, 0x2a, 0x19, 0x88, + 0x28, 0x10, 0x2, 0x0, 0x0, 0x4d, 0xc5, 0x15, 0x0, 0x10, 0xa4, 0xbe, 0xd5, 0xd9, 0xb9, 0x6a, 0x9c, 0xd6, 0x85, + 0x3e, 0xd4, 0x78, 0xf, 0x8b, 0xa8, 0x58, 0x25, 0x43, 0x1f, 0x0, 0x9, 0x89, 0x1b, 0xd1, 0xf7, 0xcb, 0x2b, 0x92, + 0x46, 0x56, 0x13, 0x60, 0xa6, 0x29, 0x17, 0x8, 0x0, 0xb, 0xb7, 0x34, 0x8d, 0xf, 0x30, 0x2f, 0xcb, 0x3d, 0xe, + 0x69, 0x1d, 0x3, 0x0, 0x2, 0x7c, 0x1a, 0x2, 0x0, 0x0, 0x4, 0xec, 0x19, 0xb3, 0x12, 0x0, 0xa, 0x36, 0x2b, + 0x53, 0xc8, 0x6c, 0x16, 0xd3, 0x3c, 0xc3, 0x3f, 0x24, 0x9, 0x21, 0x6f, 0x95, 0x25, 0xd9, 0x1f, 0x0, 0x1e, 0xe9, + 0x22, 0x41, 0xb0, 0x3, 0xdf, 0xdd, 0xd2, 0x42, 0x37, 0x62, 0x37, 0x94, 0x73, 0x90, 0x37, 0xc6, 0x46, 0x7d, 0xa8, + 0xc6, 0x34, 0xf, 0x71, 0x44, 0x7e, 0xe4, 0xfb, 0x45, 0x1a, 0xb, 0x1d, 0x1, 0xc5, 0x9, 0x0, 0x7, 0x18, 0x0, + 0x2e, 0xeb, 0x42, 0xf7, 0xb6, 0x1c, 0x0, 0x2, 0x56, 0xd1, 0x13, 0x18, 0xfb, 0x0, 0x16, 0x90, 0xbb, 0xf, 0xc8, + 0x8e, 0x79, 0x27, 0x4e, 0x29, 0x5e, 0xd6, 0x15, 0x3f, 0xdb, 0x9e, 0xfe, 0x55, 0xe6, 0x25, 0x64, 0x70, 0xb4, 0x0, + 0x9, 0x88, 0x13, 0x6a, 0xb3, 0x27, 0xca, 0xc8, 0xf5, 0x0, 0x0, 0x16, 0xcb, 0x27, 0x55, 0x77, 0x4a, 0x66, 0xc6, + 0x90, 0x3d, 0x28, 0x1a, 0x9, 0x32, 0xef, 0xb, 0x6e, 0x3, 0x2, 0x8f, 0xdf, 0xc6, 0xf7, 0x0, 0xe, 0xcb, 0xcf, + 0x5e, 0x1a, 0xd2, 0x31, 0x8b, 0xd5, 0x4e, 0xbc, 0xe0, 0xcf, 0xbe, 0x8c, 0x0, 0x2, 0x17, 0xc9, 0x0, 0x13, 0x77, + 0xe9, 0x6e, 0x6f, 0xaa, 0x85, 0x8d, 0x69, 0x8e, 0x6, 0xb2, 0x72, 0x76, 0xde, 0x31, 0x8d, 0xc3, 0x8f, 0x55, 0x0, + 0x2, 0x31, 0x32, 0x0, 0x0, 0x0, 0x2, 0xb5, 0x2f}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x17, 0x8d, 0x4d, 0xfb, 0x5c, 0x44, 0x69}; + uint8_t bytesprops1[] = {0x30, 0xb2, 0xa1, 0xe, 0xeb, 0x3a, 0xe9, 0xdd, 0xe9, 0xb5, 0x67, 0xe8, 0x8b}; + uint8_t bytesprops3[] = {0xee, 0x10, 0xa4, 0x73, 0x2c, 0x74, 0x9f, 0x15, 0xd3, 0x1, 0x93, 0x8d, 0x70, 0x34, 0xba, + 0xa6, 0xe5, 0xc2, 0x76, 0x1d, 0x99, 0xda, 0xc7, 0x9c, 0x6c, 0x82, 0xa0, 0xee, 0xf2}; + uint8_t bytesprops2[] = {0}; + uint8_t bytesprops4[] = {0x8d, 0x15, 0xed, 0x83, 0xf0, 0x2a, 0x29, 0x16, 0x47, 0x70, 0x9d, 0xfb, 0x13}; + uint8_t bytesprops5[] = {0xa4, 0xbe, 0xd5, 0xd9, 0xb9, 0x6a, 0x9c, 0xd6, + 0x85, 0x3e, 0xd4, 0x78, 0xf, 0x8b, 0xa8, 0x58}; + uint8_t bytesprops6[] = {0x89, 0x1b, 0xd1, 0xf7, 0xcb, 0x2b, 0x92, 0x46, 0x56}; + uint8_t bytesprops7[] = {0xb7, 0x34, 0x8d, 0xf, 0x30, 0x2f, 0xcb, 0x3d, 0xe, 0x69, 0x1d}; + uint8_t bytesprops8[] = {0x7c, 0x1a}; + uint8_t bytesprops9[] = {0x36, 0x2b, 0x53, 0xc8, 0x6c, 0x16, 0xd3, 0x3c, 0xc3, 0x3f}; + uint8_t bytesprops10[] = {0xe9, 0x22, 0x41, 0xb0, 0x3, 0xdf, 0xdd, 0xd2, 0x42, 0x37, 0x62, 0x37, 0x94, 0x73, 0x90, + 0x37, 0xc6, 0x46, 0x7d, 0xa8, 0xc6, 0x34, 0xf, 0x71, 0x44, 0x7e, 0xe4, 0xfb, 0x45, 0x1a}; + uint8_t bytesprops11[] = {0x18, 0x0, 0x2e, 0xeb, 0x42, 0xf7, 0xb6}; + uint8_t bytesprops12[] = {0x56, 0xd1}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)22, .value = {.str = {7, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 9249}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 236}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {13, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {0, (char*)&bytesprops2}, .v = {29, (char*)&bytesprops3}}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {13, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 26390}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 42}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 136}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 16}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 19909}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {16, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 67}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {9, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 24742}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 23}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {11, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {2, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 1260}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 179}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {10, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 9}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 28565}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 217}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {30, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 29}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 197}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {7, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {2, (char*)&bytesprops12}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 6395}}, + }; + + lwmqtt_properties_t props = {30, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[9]; + uint8_t topic_filter_s0_bytes[] = {0x90, 0xbb, 0xf, 0xc8, 0x8e, 0x79, 0x27, 0x4e, 0x29, 0x5e, 0xd6, + 0x15, 0x3f, 0xdb, 0x9e, 0xfe, 0x55, 0xe6, 0x25, 0x64, 0x70, 0xb4}; + lwmqtt_string_t topic_filter_s0 = {22, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x88, 0x13, 0x6a, 0xb3, 0x27, 0xca, 0xc8, 0xf5, 0x0}; + lwmqtt_string_t topic_filter_s1 = {9, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xcb, 0x27, 0x55, 0x77, 0x4a, 0x66, 0xc6, 0x90, 0x3d, 0x28, 0x1a, + 0x9, 0x32, 0xef, 0xb, 0x6e, 0x3, 0x2, 0x8f, 0xdf, 0xc6, 0xf7}; + lwmqtt_string_t topic_filter_s2 = {22, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0xcb, 0xcf, 0x5e, 0x1a, 0xd2, 0x31, 0x8b, + 0xd5, 0x4e, 0xbc, 0xe0, 0xcf, 0xbe, 0x8c}; + lwmqtt_string_t topic_filter_s3 = {14, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x17, 0xc9}; + lwmqtt_string_t topic_filter_s4 = {2, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x77, 0xe9, 0x6e, 0x6f, 0xaa, 0x85, 0x8d, 0x69, 0x8e, 0x6, + 0xb2, 0x72, 0x76, 0xde, 0x31, 0x8d, 0xc3, 0x8f, 0x55}; + lwmqtt_string_t topic_filter_s5 = {19, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x31, 0x32}; + lwmqtt_string_t topic_filter_s6 = {2, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0}; + lwmqtt_string_t topic_filter_s7 = {0, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0xb5, 0x2f}; + lwmqtt_string_t topic_filter_s8 = {2, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 6495, 9, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 21456 +// ["i\172\235\176yA\168\222\209\r","\207\189\131+\244\149$\n\152\138]\252t\DLE\251\212\SUB\188tMDIz\190>\188ZB","#\r\157z\r6\USl\SUB\142\142\217\US\182f\213\161\240","i\167c\137+A\NAKg\221\&0\217\213'\ESC]mc}\222\157\220>","\144\177\&2@\185\r\242\&08N\243\238\144-\SO\146\248e\148\231\FS\196\ETBk\246\248\167\DC2","\129"] +// [PropServerKeepAlive 29657,PropCorrelationData "5\163\186\&9{",PropRequestResponseInformation 4,PropServerKeepAlive +// 28724,PropSubscriptionIdentifierAvailable 87,PropRetainAvailable 48] +TEST(Unsubscribe5QCTest, Encode19) { + uint8_t pkt[] = {0xa2, 0x8e, 0x1, 0x53, 0xd0, 0x14, 0x13, 0x73, 0xd9, 0x9, 0x0, 0x5, 0x35, 0xa3, 0xba, 0x39, 0x7b, + 0x19, 0x4, 0x13, 0x70, 0x34, 0x29, 0x57, 0x25, 0x30, 0x0, 0xa, 0x69, 0xac, 0xeb, 0xb0, 0x79, 0x41, + 0xa8, 0xde, 0xd1, 0xd, 0x0, 0x1c, 0xcf, 0xbd, 0x83, 0x2b, 0xf4, 0x95, 0x24, 0xa, 0x98, 0x8a, 0x5d, + 0xfc, 0x74, 0x10, 0xfb, 0xd4, 0x1a, 0xbc, 0x74, 0x4d, 0x44, 0x49, 0x7a, 0xbe, 0x3e, 0xbc, 0x5a, 0x42, + 0x0, 0x12, 0x23, 0xd, 0x9d, 0x7a, 0xd, 0x36, 0x1f, 0x6c, 0x1a, 0x8e, 0x8e, 0xd9, 0x1f, 0xb6, 0x66, + 0xd5, 0xa1, 0xf0, 0x0, 0x16, 0x69, 0xa7, 0x63, 0x89, 0x2b, 0x41, 0x15, 0x67, 0xdd, 0x30, 0xd9, 0xd5, + 0x27, 0x1b, 0x5d, 0x6d, 0x63, 0x7d, 0xde, 0x9d, 0xdc, 0x3e, 0x0, 0x1c, 0x90, 0xb1, 0x32, 0x40, 0xb9, + 0xd, 0xf2, 0x30, 0x38, 0x4e, 0xf3, 0xee, 0x90, 0x2d, 0xe, 0x92, 0xf8, 0x65, 0x94, 0xe7, 0x1c, 0xc4, + 0x17, 0x6b, 0xf6, 0xf8, 0xa7, 0x12, 0x0, 0x1, 0x81}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x35, 0xa3, 0xba, 0x39, 0x7b}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 29657}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {5, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 4}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 28724}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 87}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 48}}, + }; + + lwmqtt_properties_t props = {6, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[6]; + uint8_t topic_filter_s0_bytes[] = {0x69, 0xac, 0xeb, 0xb0, 0x79, 0x41, 0xa8, 0xde, 0xd1, 0xd}; + lwmqtt_string_t topic_filter_s0 = {10, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xcf, 0xbd, 0x83, 0x2b, 0xf4, 0x95, 0x24, 0xa, 0x98, 0x8a, + 0x5d, 0xfc, 0x74, 0x10, 0xfb, 0xd4, 0x1a, 0xbc, 0x74, 0x4d, + 0x44, 0x49, 0x7a, 0xbe, 0x3e, 0xbc, 0x5a, 0x42}; + lwmqtt_string_t topic_filter_s1 = {28, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x23, 0xd, 0x9d, 0x7a, 0xd, 0x36, 0x1f, 0x6c, 0x1a, + 0x8e, 0x8e, 0xd9, 0x1f, 0xb6, 0x66, 0xd5, 0xa1, 0xf0}; + lwmqtt_string_t topic_filter_s2 = {18, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x69, 0xa7, 0x63, 0x89, 0x2b, 0x41, 0x15, 0x67, 0xdd, 0x30, 0xd9, + 0xd5, 0x27, 0x1b, 0x5d, 0x6d, 0x63, 0x7d, 0xde, 0x9d, 0xdc, 0x3e}; + lwmqtt_string_t topic_filter_s3 = {22, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x90, 0xb1, 0x32, 0x40, 0xb9, 0xd, 0xf2, 0x30, 0x38, 0x4e, + 0xf3, 0xee, 0x90, 0x2d, 0xe, 0x92, 0xf8, 0x65, 0x94, 0xe7, + 0x1c, 0xc4, 0x17, 0x6b, 0xf6, 0xf8, 0xa7, 0x12}; + lwmqtt_string_t topic_filter_s4 = {28, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x81}; + lwmqtt_string_t topic_filter_s5 = {1, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 21456, 6, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 1638 +// ["I\172\254l\194\132\150\DC1\CAN\173\152\&6ms\215\182\145~\176\NAK(\255p\163\238G\163\DC4\164"] [PropReasonString +// "",PropSubscriptionIdentifier 18,PropRetainAvailable 191,PropMessageExpiryInterval 13150,PropServerKeepAlive +// 17910,PropAuthenticationMethod +// "\USH\171\242\ETX8\184\204\179\&6D\176h\174\197\227\234\170=",PropWildcardSubscriptionAvailable +// 58,PropServerKeepAlive 13408,PropAuthenticationMethod +// "\147\ENQ\235-\152\145\&7\219Wj%X\218\250*\154\137\&0\203>\b\208%\252\255\&1",PropWillDelayInterval +// 7585,PropSharedSubscriptionAvailable 7,PropCorrelationData +// "Lr\SO\141\212\128\245\230C\241\DEL",PropMessageExpiryInterval 29115,PropUserProperty +// "\246\160\213-\ETX\242\149\222Yc2UX\224)\223\191\159\201\184" +// "\189\a\219\189@\240\170\204fWn\173",PropAssignedClientIdentifier "\157\146\145\172\ENQ",PropAuthenticationData +// "\202t\170\168",PropAuthenticationMethod "",PropResponseTopic +// "e><\148um<\224%\fN\233\159'\199\143\149Y\STX\213\&4\166rC]\146\227]",PropAuthenticationData +// "\153M\174V\246.\US\ACK\191\135\225|uKY\136\255\SYN\230\154\146\149><1",PropMaximumQoS +// 96,PropRequestResponseInformation 170,PropCorrelationData +// "\CAN\250SB\250\163\230\186\189V\128M}\215~\178\199\208\137\155",PropRetainAvailable 102,PropSubscriptionIdentifier +// 30,PropTopicAliasMaximum 12459,PropMaximumQoS 181,PropPayloadFormatIndicator 212,PropSubscriptionIdentifier +// 29,PropSubscriptionIdentifierAvailable 44] +TEST(Unsubscribe5QCTest, Encode20) { + uint8_t pkt[] = { + 0xa2, 0xa0, 0x2, 0x6, 0x66, 0xfd, 0x1, 0x1f, 0x0, 0x0, 0xb, 0x12, 0x25, 0xbf, 0x2, 0x0, 0x0, 0x33, 0x5e, + 0x13, 0x45, 0xf6, 0x15, 0x0, 0x13, 0x1f, 0x48, 0xab, 0xf2, 0x3, 0x38, 0xb8, 0xcc, 0xb3, 0x36, 0x44, 0xb0, 0x68, + 0xae, 0xc5, 0xe3, 0xea, 0xaa, 0x3d, 0x28, 0x3a, 0x13, 0x34, 0x60, 0x15, 0x0, 0x1a, 0x93, 0x5, 0xeb, 0x2d, 0x98, + 0x91, 0x37, 0xdb, 0x57, 0x6a, 0x25, 0x58, 0xda, 0xfa, 0x2a, 0x9a, 0x89, 0x30, 0xcb, 0x3e, 0x8, 0xd0, 0x25, 0xfc, + 0xff, 0x31, 0x18, 0x0, 0x0, 0x1d, 0xa1, 0x2a, 0x7, 0x9, 0x0, 0xb, 0x4c, 0x72, 0xe, 0x8d, 0xd4, 0x80, 0xf5, + 0xe6, 0x43, 0xf1, 0x7f, 0x2, 0x0, 0x0, 0x71, 0xbb, 0x26, 0x0, 0x14, 0xf6, 0xa0, 0xd5, 0x2d, 0x3, 0xf2, 0x95, + 0xde, 0x59, 0x63, 0x32, 0x55, 0x58, 0xe0, 0x29, 0xdf, 0xbf, 0x9f, 0xc9, 0xb8, 0x0, 0xc, 0xbd, 0x7, 0xdb, 0xbd, + 0x40, 0xf0, 0xaa, 0xcc, 0x66, 0x57, 0x6e, 0xad, 0x12, 0x0, 0x5, 0x9d, 0x92, 0x91, 0xac, 0x5, 0x16, 0x0, 0x4, + 0xca, 0x74, 0xaa, 0xa8, 0x15, 0x0, 0x0, 0x8, 0x0, 0x1c, 0x65, 0x3e, 0x3c, 0x94, 0x75, 0x6d, 0x3c, 0xe0, 0x25, + 0xc, 0x4e, 0xe9, 0x9f, 0x27, 0xc7, 0x8f, 0x95, 0x59, 0x2, 0xd5, 0x34, 0xa6, 0x72, 0x43, 0x5d, 0x92, 0xe3, 0x5d, + 0x16, 0x0, 0x19, 0x99, 0x4d, 0xae, 0x56, 0xf6, 0x2e, 0x1f, 0x6, 0xbf, 0x87, 0xe1, 0x7c, 0x75, 0x4b, 0x59, 0x88, + 0xff, 0x16, 0xe6, 0x9a, 0x92, 0x95, 0x3e, 0x3c, 0x31, 0x24, 0x60, 0x19, 0xaa, 0x9, 0x0, 0x14, 0x18, 0xfa, 0x53, + 0x42, 0xfa, 0xa3, 0xe6, 0xba, 0xbd, 0x56, 0x80, 0x4d, 0x7d, 0xd7, 0x7e, 0xb2, 0xc7, 0xd0, 0x89, 0x9b, 0x25, 0x66, + 0xb, 0x1e, 0x22, 0x30, 0xab, 0x24, 0xb5, 0x1, 0xd4, 0xb, 0x1d, 0x29, 0x2c, 0x0, 0x1d, 0x49, 0xac, 0xfe, 0x6c, + 0xc2, 0x84, 0x96, 0x11, 0x18, 0xad, 0x98, 0x36, 0x6d, 0x73, 0xd7, 0xb6, 0x91, 0x7e, 0xb0, 0x15, 0x28, 0xff, 0x70, + 0xa3, 0xee, 0x47, 0xa3, 0x14, 0xa4}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0}; + uint8_t bytesprops1[] = {0x1f, 0x48, 0xab, 0xf2, 0x3, 0x38, 0xb8, 0xcc, 0xb3, 0x36, + 0x44, 0xb0, 0x68, 0xae, 0xc5, 0xe3, 0xea, 0xaa, 0x3d}; + uint8_t bytesprops2[] = {0x93, 0x5, 0xeb, 0x2d, 0x98, 0x91, 0x37, 0xdb, 0x57, 0x6a, 0x25, 0x58, 0xda, + 0xfa, 0x2a, 0x9a, 0x89, 0x30, 0xcb, 0x3e, 0x8, 0xd0, 0x25, 0xfc, 0xff, 0x31}; + uint8_t bytesprops3[] = {0x4c, 0x72, 0xe, 0x8d, 0xd4, 0x80, 0xf5, 0xe6, 0x43, 0xf1, 0x7f}; + uint8_t bytesprops5[] = {0xbd, 0x7, 0xdb, 0xbd, 0x40, 0xf0, 0xaa, 0xcc, 0x66, 0x57, 0x6e, 0xad}; + uint8_t bytesprops4[] = {0xf6, 0xa0, 0xd5, 0x2d, 0x3, 0xf2, 0x95, 0xde, 0x59, 0x63, + 0x32, 0x55, 0x58, 0xe0, 0x29, 0xdf, 0xbf, 0x9f, 0xc9, 0xb8}; + uint8_t bytesprops6[] = {0x9d, 0x92, 0x91, 0xac, 0x5}; + uint8_t bytesprops7[] = {0xca, 0x74, 0xaa, 0xa8}; + uint8_t bytesprops8[] = {0}; + uint8_t bytesprops9[] = {0x65, 0x3e, 0x3c, 0x94, 0x75, 0x6d, 0x3c, 0xe0, 0x25, 0xc, 0x4e, 0xe9, 0x9f, 0x27, + 0xc7, 0x8f, 0x95, 0x59, 0x2, 0xd5, 0x34, 0xa6, 0x72, 0x43, 0x5d, 0x92, 0xe3, 0x5d}; + uint8_t bytesprops10[] = {0x99, 0x4d, 0xae, 0x56, 0xf6, 0x2e, 0x1f, 0x6, 0xbf, 0x87, 0xe1, 0x7c, 0x75, + 0x4b, 0x59, 0x88, 0xff, 0x16, 0xe6, 0x9a, 0x92, 0x95, 0x3e, 0x3c, 0x31}; + uint8_t bytesprops11[] = {0x18, 0xfa, 0x53, 0x42, 0xfa, 0xa3, 0xe6, 0xba, 0xbd, 0x56, + 0x80, 0x4d, 0x7d, 0xd7, 0x7e, 0xb2, 0xc7, 0xd0, 0x89, 0x9b}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)31, .value = {.str = {0, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 18}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 191}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 13150}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 17910}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {19, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 58}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 13408}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {26, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 7585}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 7}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {11, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 29115}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {20, (char*)&bytesprops4}, .v = {12, (char*)&bytesprops5}}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {5, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {4, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {0, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {28, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {25, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 96}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 170}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {20, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 102}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 30}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 12459}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 181}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 212}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 29}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 44}}, + }; + + lwmqtt_properties_t props = {29, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0x49, 0xac, 0xfe, 0x6c, 0xc2, 0x84, 0x96, 0x11, 0x18, 0xad, + 0x98, 0x36, 0x6d, 0x73, 0xd7, 0xb6, 0x91, 0x7e, 0xb0, 0x15, + 0x28, 0xff, 0x70, 0xa3, 0xee, 0x47, 0xa3, 0x14, 0xa4}; + lwmqtt_string_t topic_filter_s0 = {29, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 1638, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 30931 +// ["\242\153y5V\186\NUL\184\153\206\140\ESC\128Z","\217J\203\FS\129\209\190\129\183\211N\167\STX\EOT\145\216\246\204\195\208","\228e\179_t\DC2\ETX\208\189\199\&7!\150\135\155{\150.4Y","T\229\NAK]\171\166\141\193*\174\ESC\ESC?\198\242\\G\242\209\NULRL\DEL\EM","\227\251","","\247\227>\DC1?\SIm\254f\225","R\194\196\DEL\217j\241\169\&6f\155"] +// [PropAuthenticationData "\190\&5\251\181\175F\ENQ\160\DC3\129|\DC1\151A\214k",PropSessionExpiryInterval +// 4940,PropAuthenticationData "x\DC2>v\244\229\GS\212\185\DEL2\146\163"] +TEST(Unsubscribe5QCTest, Encode21) { + uint8_t pkt[] = {0xa2, 0xa0, 0x1, 0x78, 0xd3, 0x28, 0x16, 0x0, 0x10, 0xbe, 0x35, 0xfb, 0xb5, 0xaf, 0x46, 0x5, 0xa0, + 0x13, 0x81, 0x7c, 0x11, 0x97, 0x41, 0xd6, 0x6b, 0x11, 0x0, 0x0, 0x13, 0x4c, 0x16, 0x0, 0xd, 0x78, + 0x12, 0x3e, 0x76, 0xf4, 0xe5, 0x1d, 0xd4, 0xb9, 0x7f, 0x32, 0x92, 0xa3, 0x0, 0xe, 0xf2, 0x99, 0x79, + 0x35, 0x56, 0xba, 0x0, 0xb8, 0x99, 0xce, 0x8c, 0x1b, 0x80, 0x5a, 0x0, 0x14, 0xd9, 0x4a, 0xcb, 0x1c, + 0x81, 0xd1, 0xbe, 0x81, 0xb7, 0xd3, 0x4e, 0xa7, 0x2, 0x4, 0x91, 0xd8, 0xf6, 0xcc, 0xc3, 0xd0, 0x0, + 0x14, 0xe4, 0x65, 0xb3, 0x5f, 0x74, 0x12, 0x3, 0xd0, 0xbd, 0xc7, 0x37, 0x21, 0x96, 0x87, 0x9b, 0x7b, + 0x96, 0x2e, 0x34, 0x59, 0x0, 0x18, 0x54, 0xe5, 0x15, 0x5d, 0xab, 0xa6, 0x8d, 0xc1, 0x2a, 0xae, 0x1b, + 0x1b, 0x3f, 0xc6, 0xf2, 0x5c, 0x47, 0xf2, 0xd1, 0x0, 0x52, 0x4c, 0x7f, 0x19, 0x0, 0x2, 0xe3, 0xfb, + 0x0, 0x0, 0x0, 0xa, 0xf7, 0xe3, 0x3e, 0x11, 0x3f, 0xf, 0x6d, 0xfe, 0x66, 0xe1, 0x0, 0xb, 0x52, + 0xc2, 0xc4, 0x7f, 0xd9, 0x6a, 0xf1, 0xa9, 0x36, 0x66, 0x9b}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xbe, 0x35, 0xfb, 0xb5, 0xaf, 0x46, 0x5, 0xa0, + 0x13, 0x81, 0x7c, 0x11, 0x97, 0x41, 0xd6, 0x6b}; + uint8_t bytesprops1[] = {0x78, 0x12, 0x3e, 0x76, 0xf4, 0xe5, 0x1d, 0xd4, 0xb9, 0x7f, 0x32, 0x92, 0xa3}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)22, .value = {.str = {16, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 4940}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {13, (char*)&bytesprops1}}}, + }; + + lwmqtt_properties_t props = {3, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[8]; + uint8_t topic_filter_s0_bytes[] = {0xf2, 0x99, 0x79, 0x35, 0x56, 0xba, 0x0, 0xb8, 0x99, 0xce, 0x8c, 0x1b, 0x80, 0x5a}; + lwmqtt_string_t topic_filter_s0 = {14, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xd9, 0x4a, 0xcb, 0x1c, 0x81, 0xd1, 0xbe, 0x81, 0xb7, 0xd3, + 0x4e, 0xa7, 0x2, 0x4, 0x91, 0xd8, 0xf6, 0xcc, 0xc3, 0xd0}; + lwmqtt_string_t topic_filter_s1 = {20, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xe4, 0x65, 0xb3, 0x5f, 0x74, 0x12, 0x3, 0xd0, 0xbd, 0xc7, + 0x37, 0x21, 0x96, 0x87, 0x9b, 0x7b, 0x96, 0x2e, 0x34, 0x59}; + lwmqtt_string_t topic_filter_s2 = {20, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x54, 0xe5, 0x15, 0x5d, 0xab, 0xa6, 0x8d, 0xc1, 0x2a, 0xae, 0x1b, 0x1b, + 0x3f, 0xc6, 0xf2, 0x5c, 0x47, 0xf2, 0xd1, 0x0, 0x52, 0x4c, 0x7f, 0x19}; + lwmqtt_string_t topic_filter_s3 = {24, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xe3, 0xfb}; + lwmqtt_string_t topic_filter_s4 = {2, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0}; + lwmqtt_string_t topic_filter_s5 = {0, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0xf7, 0xe3, 0x3e, 0x11, 0x3f, 0xf, 0x6d, 0xfe, 0x66, 0xe1}; + lwmqtt_string_t topic_filter_s6 = {10, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0x52, 0xc2, 0xc4, 0x7f, 0xd9, 0x6a, 0xf1, 0xa9, 0x36, 0x66, 0x9b}; + lwmqtt_string_t topic_filter_s7 = {11, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 30931, 8, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 14609 +// ["\STX\186","\216\232'\187\247AC\149\141\&7(\219\ACK\245V\NUL\176q\225","\146\EOTs\135\223\183f\130\217i\200\252%\195\232L\233\STX\202\249\219'#\145\182\197","0]\240\US\255\201i\203.]|\DC3\173e\v","\174!\202\147\162\ESC\200\211\216\194WF\212N{'!^~2\ACKQ\157j\228\244","\163x\"\164\183\175$]\242\129\245'\164\\E","*W\240\217\DC1%D\193S\240\168\186\147\190\153$\f\213\182De\167\239\156\227"] +// [PropSharedSubscriptionAvailable 190,PropMessageExpiryInterval 16387,PropTopicAlias 30829,PropTopicAlias +// 29001,PropMessageExpiryInterval 22909,PropResponseTopic "\USU\aP6M\NUL\201\f",PropServerKeepAlive +// 3934,PropSharedSubscriptionAvailable 130,PropContentType +// "\178\DC2\170\NUL\202\215\169\190\150\ETBj\DC4\EMMq\235\155\227\156!\184\246\249\EM2\130~\216\223\150",PropAssignedClientIdentifier +// "y\241:&\EM\196\169Xba\129^2\248\&1qbd\240\198\159\162k",PropMessageExpiryInterval 2662,PropUserProperty +// "\220\DLE\157\152\142`\186\248\250\134t1\186\193\ACKU\145" "h\174\147a\201",PropResponseTopic +// "om\141y\221\SYNG[z(",PropAssignedClientIdentifier " +// \DEL5F\201]pT\221y\128\133\182\224\172\217",PropAuthenticationMethod +// "\186\249\169h\238\135\130:\188\255FT\233\219\254\253\147\151\219\222\FSKK=\163",PropTopicAliasMaximum 4513] +TEST(Unsubscribe5QCTest, Encode22) { + uint8_t pkt[] = { + 0xa2, 0xcf, 0x2, 0x39, 0x11, 0xbd, 0x1, 0x2a, 0xbe, 0x2, 0x0, 0x0, 0x40, 0x3, 0x23, 0x78, 0x6d, 0x23, 0x71, + 0x49, 0x2, 0x0, 0x0, 0x59, 0x7d, 0x8, 0x0, 0x9, 0x1f, 0x55, 0x7, 0x50, 0x36, 0x4d, 0x0, 0xc9, 0xc, 0x13, + 0xf, 0x5e, 0x2a, 0x82, 0x3, 0x0, 0x1e, 0xb2, 0x12, 0xaa, 0x0, 0xca, 0xd7, 0xa9, 0xbe, 0x96, 0x17, 0x6a, 0x14, + 0x19, 0x4d, 0x71, 0xeb, 0x9b, 0xe3, 0x9c, 0x21, 0xb8, 0xf6, 0xf9, 0x19, 0x32, 0x82, 0x7e, 0xd8, 0xdf, 0x96, 0x12, + 0x0, 0x17, 0x79, 0xf1, 0x3a, 0x26, 0x19, 0xc4, 0xa9, 0x58, 0x62, 0x61, 0x81, 0x5e, 0x32, 0xf8, 0x31, 0x71, 0x62, + 0x64, 0xf0, 0xc6, 0x9f, 0xa2, 0x6b, 0x2, 0x0, 0x0, 0xa, 0x66, 0x26, 0x0, 0x11, 0xdc, 0x10, 0x9d, 0x98, 0x8e, + 0x60, 0xba, 0xf8, 0xfa, 0x86, 0x74, 0x31, 0xba, 0xc1, 0x6, 0x55, 0x91, 0x0, 0x5, 0x68, 0xae, 0x93, 0x61, 0xc9, + 0x8, 0x0, 0xa, 0x6f, 0x6d, 0x8d, 0x79, 0xdd, 0x16, 0x47, 0x5b, 0x7a, 0x28, 0x12, 0x0, 0x10, 0x20, 0x7f, 0x35, + 0x46, 0xc9, 0x5d, 0x70, 0x54, 0xdd, 0x79, 0x80, 0x85, 0xb6, 0xe0, 0xac, 0xd9, 0x15, 0x0, 0x19, 0xba, 0xf9, 0xa9, + 0x68, 0xee, 0x87, 0x82, 0x3a, 0xbc, 0xff, 0x46, 0x54, 0xe9, 0xdb, 0xfe, 0xfd, 0x93, 0x97, 0xdb, 0xde, 0x1c, 0x4b, + 0x4b, 0x3d, 0xa3, 0x22, 0x11, 0xa1, 0x0, 0x2, 0x2, 0xba, 0x0, 0x13, 0xd8, 0xe8, 0x27, 0xbb, 0xf7, 0x41, 0x43, + 0x95, 0x8d, 0x37, 0x28, 0xdb, 0x6, 0xf5, 0x56, 0x0, 0xb0, 0x71, 0xe1, 0x0, 0x1a, 0x92, 0x4, 0x73, 0x87, 0xdf, + 0xb7, 0x66, 0x82, 0xd9, 0x69, 0xc8, 0xfc, 0x25, 0xc3, 0xe8, 0x4c, 0xe9, 0x2, 0xca, 0xf9, 0xdb, 0x27, 0x23, 0x91, + 0xb6, 0xc5, 0x0, 0xf, 0x30, 0x5d, 0xf0, 0x1f, 0xff, 0xc9, 0x69, 0xcb, 0x2e, 0x5d, 0x7c, 0x13, 0xad, 0x65, 0xb, + 0x0, 0x1a, 0xae, 0x21, 0xca, 0x93, 0xa2, 0x1b, 0xc8, 0xd3, 0xd8, 0xc2, 0x57, 0x46, 0xd4, 0x4e, 0x7b, 0x27, 0x21, + 0x5e, 0x7e, 0x32, 0x6, 0x51, 0x9d, 0x6a, 0xe4, 0xf4, 0x0, 0xf, 0xa3, 0x78, 0x22, 0xa4, 0xb7, 0xaf, 0x24, 0x5d, + 0xf2, 0x81, 0xf5, 0x27, 0xa4, 0x5c, 0x45, 0x0, 0x19, 0x2a, 0x57, 0xf0, 0xd9, 0x11, 0x25, 0x44, 0xc1, 0x53, 0xf0, + 0xa8, 0xba, 0x93, 0xbe, 0x99, 0x24, 0xc, 0xd5, 0xb6, 0x44, 0x65, 0xa7, 0xef, 0x9c, 0xe3}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x1f, 0x55, 0x7, 0x50, 0x36, 0x4d, 0x0, 0xc9, 0xc}; + uint8_t bytesprops1[] = {0xb2, 0x12, 0xaa, 0x0, 0xca, 0xd7, 0xa9, 0xbe, 0x96, 0x17, 0x6a, 0x14, 0x19, 0x4d, 0x71, + 0xeb, 0x9b, 0xe3, 0x9c, 0x21, 0xb8, 0xf6, 0xf9, 0x19, 0x32, 0x82, 0x7e, 0xd8, 0xdf, 0x96}; + uint8_t bytesprops2[] = {0x79, 0xf1, 0x3a, 0x26, 0x19, 0xc4, 0xa9, 0x58, 0x62, 0x61, 0x81, 0x5e, + 0x32, 0xf8, 0x31, 0x71, 0x62, 0x64, 0xf0, 0xc6, 0x9f, 0xa2, 0x6b}; + uint8_t bytesprops4[] = {0x68, 0xae, 0x93, 0x61, 0xc9}; + uint8_t bytesprops3[] = {0xdc, 0x10, 0x9d, 0x98, 0x8e, 0x60, 0xba, 0xf8, 0xfa, + 0x86, 0x74, 0x31, 0xba, 0xc1, 0x6, 0x55, 0x91}; + uint8_t bytesprops5[] = {0x6f, 0x6d, 0x8d, 0x79, 0xdd, 0x16, 0x47, 0x5b, 0x7a, 0x28}; + uint8_t bytesprops6[] = {0x20, 0x7f, 0x35, 0x46, 0xc9, 0x5d, 0x70, 0x54, + 0xdd, 0x79, 0x80, 0x85, 0xb6, 0xe0, 0xac, 0xd9}; + uint8_t bytesprops7[] = {0xba, 0xf9, 0xa9, 0x68, 0xee, 0x87, 0x82, 0x3a, 0xbc, 0xff, 0x46, 0x54, 0xe9, + 0xdb, 0xfe, 0xfd, 0x93, 0x97, 0xdb, 0xde, 0x1c, 0x4b, 0x4b, 0x3d, 0xa3}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 190}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 16387}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 30829}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 29001}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 22909}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {9, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 3934}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 130}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {30, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {23, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 2662}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {17, (char*)&bytesprops3}, .v = {5, (char*)&bytesprops4}}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {10, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {16, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {25, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 4513}}, + }; + + lwmqtt_properties_t props = {16, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[7]; + uint8_t topic_filter_s0_bytes[] = {0x2, 0xba}; + lwmqtt_string_t topic_filter_s0 = {2, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xd8, 0xe8, 0x27, 0xbb, 0xf7, 0x41, 0x43, 0x95, 0x8d, 0x37, + 0x28, 0xdb, 0x6, 0xf5, 0x56, 0x0, 0xb0, 0x71, 0xe1}; + lwmqtt_string_t topic_filter_s1 = {19, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x92, 0x4, 0x73, 0x87, 0xdf, 0xb7, 0x66, 0x82, 0xd9, 0x69, 0xc8, 0xfc, 0x25, + 0xc3, 0xe8, 0x4c, 0xe9, 0x2, 0xca, 0xf9, 0xdb, 0x27, 0x23, 0x91, 0xb6, 0xc5}; + lwmqtt_string_t topic_filter_s2 = {26, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x30, 0x5d, 0xf0, 0x1f, 0xff, 0xc9, 0x69, 0xcb, + 0x2e, 0x5d, 0x7c, 0x13, 0xad, 0x65, 0xb}; + lwmqtt_string_t topic_filter_s3 = {15, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0xae, 0x21, 0xca, 0x93, 0xa2, 0x1b, 0xc8, 0xd3, 0xd8, 0xc2, 0x57, 0x46, 0xd4, + 0x4e, 0x7b, 0x27, 0x21, 0x5e, 0x7e, 0x32, 0x6, 0x51, 0x9d, 0x6a, 0xe4, 0xf4}; + lwmqtt_string_t topic_filter_s4 = {26, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xa3, 0x78, 0x22, 0xa4, 0xb7, 0xaf, 0x24, 0x5d, + 0xf2, 0x81, 0xf5, 0x27, 0xa4, 0x5c, 0x45}; + lwmqtt_string_t topic_filter_s5 = {15, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x2a, 0x57, 0xf0, 0xd9, 0x11, 0x25, 0x44, 0xc1, 0x53, 0xf0, 0xa8, 0xba, 0x93, + 0xbe, 0x99, 0x24, 0xc, 0xd5, 0xb6, 0x44, 0x65, 0xa7, 0xef, 0x9c, 0xe3}; + lwmqtt_string_t topic_filter_s6 = {25, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 14609, 7, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 4540 +// ["","","\222\229\236","\133\214\163","F\186I\201-\n\246\DC2\234\245\156l\132o\252[\142t\210o\NAK\221\&6F\150\241","\241\183\179\&7\145]\130\189/",",P\144\130\178\b\202\SYNe\145\240 +// f\158\&2\CAN","\234c\GS\SIR\185\&75\159"] [PropAssignedClientIdentifier +// "\ACK\171\175\ACKzK\147\173\ENQR\184\216",PropRetainAvailable 244,PropRetainAvailable +// 246,PropRequestProblemInformation 84,PropReceiveMaximum 14811,PropServerReference +// "\221\n\207\149ku-\151\\W.\DLE\188\DEL\186^-\171MBA",PropTopicAliasMaximum 13793,PropAssignedClientIdentifier +// "\234H\150\207\214\RSt.4\212R{\238\219\253\ESC",PropResponseInformation +// "\184\SO\128\&2k\135\130\231\193\150\173%\RS\"B",PropWildcardSubscriptionAvailable 123,PropTopicAlias +// 26189,PropMaximumPacketSize 25918,PropMessageExpiryInterval 14888,PropTopicAliasMaximum 3934,PropUserProperty +// "\133\ACK\148\221\252I\248" "v}\228\242\217/\193\SUB9\146\252\199",PropTopicAlias 29560,PropResponseInformation +// "8z\166n\181,\231p\185\NUL\204\237\US\212\DC1h\173\FSZ\168\155\206\130\201",PropMessageExpiryInterval +// 29552,PropReasonString "\128\194%\GS\188\248\b9]J\FS5Q`\fd\198es@\146\235C\238\b\248K\202"] +TEST(Unsubscribe5QCTest, Encode23) { + uint8_t pkt[] = { + 0xa2, 0x9a, 0x2, 0x11, 0xbc, 0xc4, 0x1, 0x12, 0x0, 0xc, 0x6, 0xab, 0xaf, 0x6, 0x7a, 0x4b, 0x93, 0xad, 0x5, + 0x52, 0xb8, 0xd8, 0x25, 0xf4, 0x25, 0xf6, 0x17, 0x54, 0x21, 0x39, 0xdb, 0x1c, 0x0, 0x15, 0xdd, 0xa, 0xcf, 0x95, + 0x6b, 0x75, 0x2d, 0x97, 0x5c, 0x57, 0x2e, 0x10, 0xbc, 0x7f, 0xba, 0x5e, 0x2d, 0xab, 0x4d, 0x42, 0x41, 0x22, 0x35, + 0xe1, 0x12, 0x0, 0x10, 0xea, 0x48, 0x96, 0xcf, 0xd6, 0x1e, 0x74, 0x2e, 0x34, 0xd4, 0x52, 0x7b, 0xee, 0xdb, 0xfd, + 0x1b, 0x1a, 0x0, 0xf, 0xb8, 0xe, 0x80, 0x32, 0x6b, 0x87, 0x82, 0xe7, 0xc1, 0x96, 0xad, 0x25, 0x1e, 0x22, 0x42, + 0x28, 0x7b, 0x23, 0x66, 0x4d, 0x27, 0x0, 0x0, 0x65, 0x3e, 0x2, 0x0, 0x0, 0x3a, 0x28, 0x22, 0xf, 0x5e, 0x26, + 0x0, 0x7, 0x85, 0x6, 0x94, 0xdd, 0xfc, 0x49, 0xf8, 0x0, 0xc, 0x76, 0x7d, 0xe4, 0xf2, 0xd9, 0x2f, 0xc1, 0x1a, + 0x39, 0x92, 0xfc, 0xc7, 0x23, 0x73, 0x78, 0x1a, 0x0, 0x18, 0x38, 0x7a, 0xa6, 0x6e, 0xb5, 0x2c, 0xe7, 0x70, 0xb9, + 0x0, 0xcc, 0xed, 0x1f, 0xd4, 0x11, 0x68, 0xad, 0x1c, 0x5a, 0xa8, 0x9b, 0xce, 0x82, 0xc9, 0x2, 0x0, 0x0, 0x73, + 0x70, 0x1f, 0x0, 0x1c, 0x80, 0xc2, 0x25, 0x1d, 0xbc, 0xf8, 0x8, 0x39, 0x5d, 0x4a, 0x1c, 0x35, 0x51, 0x60, 0xc, + 0x64, 0xc6, 0x65, 0x73, 0x40, 0x92, 0xeb, 0x43, 0xee, 0x8, 0xf8, 0x4b, 0xca, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, + 0xde, 0xe5, 0xec, 0x0, 0x3, 0x85, 0xd6, 0xa3, 0x0, 0x1a, 0x46, 0xba, 0x49, 0xc9, 0x2d, 0xa, 0xf6, 0x12, 0xea, + 0xf5, 0x9c, 0x6c, 0x84, 0x6f, 0xfc, 0x5b, 0x8e, 0x74, 0xd2, 0x6f, 0x15, 0xdd, 0x36, 0x46, 0x96, 0xf1, 0x0, 0x9, + 0xf1, 0xb7, 0xb3, 0x37, 0x91, 0x5d, 0x82, 0xbd, 0x2f, 0x0, 0x10, 0x2c, 0x50, 0x90, 0x82, 0xb2, 0x8, 0xca, 0x16, + 0x65, 0x91, 0xf0, 0x20, 0x66, 0x9e, 0x32, 0x18, 0x0, 0x9, 0xea, 0x63, 0x1d, 0xf, 0x52, 0xb9, 0x37, 0x35, 0x9f}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x6, 0xab, 0xaf, 0x6, 0x7a, 0x4b, 0x93, 0xad, 0x5, 0x52, 0xb8, 0xd8}; + uint8_t bytesprops1[] = {0xdd, 0xa, 0xcf, 0x95, 0x6b, 0x75, 0x2d, 0x97, 0x5c, 0x57, 0x2e, + 0x10, 0xbc, 0x7f, 0xba, 0x5e, 0x2d, 0xab, 0x4d, 0x42, 0x41}; + uint8_t bytesprops2[] = {0xea, 0x48, 0x96, 0xcf, 0xd6, 0x1e, 0x74, 0x2e, + 0x34, 0xd4, 0x52, 0x7b, 0xee, 0xdb, 0xfd, 0x1b}; + uint8_t bytesprops3[] = {0xb8, 0xe, 0x80, 0x32, 0x6b, 0x87, 0x82, 0xe7, 0xc1, 0x96, 0xad, 0x25, 0x1e, 0x22, 0x42}; + uint8_t bytesprops5[] = {0x76, 0x7d, 0xe4, 0xf2, 0xd9, 0x2f, 0xc1, 0x1a, 0x39, 0x92, 0xfc, 0xc7}; + uint8_t bytesprops4[] = {0x85, 0x6, 0x94, 0xdd, 0xfc, 0x49, 0xf8}; + uint8_t bytesprops6[] = {0x38, 0x7a, 0xa6, 0x6e, 0xb5, 0x2c, 0xe7, 0x70, 0xb9, 0x0, 0xcc, 0xed, + 0x1f, 0xd4, 0x11, 0x68, 0xad, 0x1c, 0x5a, 0xa8, 0x9b, 0xce, 0x82, 0xc9}; + uint8_t bytesprops7[] = {0x80, 0xc2, 0x25, 0x1d, 0xbc, 0xf8, 0x8, 0x39, 0x5d, 0x4a, 0x1c, 0x35, 0x51, 0x60, + 0xc, 0x64, 0xc6, 0x65, 0x73, 0x40, 0x92, 0xeb, 0x43, 0xee, 0x8, 0xf8, 0x4b, 0xca}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)18, .value = {.str = {12, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 244}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 246}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 84}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 14811}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {21, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 13793}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {16, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {15, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 123}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 26189}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 25918}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 14888}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 3934}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {7, (char*)&bytesprops4}, .v = {12, (char*)&bytesprops5}}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 29560}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {24, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 29552}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {28, (char*)&bytesprops7}}}, + }; + + lwmqtt_properties_t props = {19, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[8]; + uint8_t topic_filter_s0_bytes[] = {0}; + lwmqtt_string_t topic_filter_s0 = {0, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0}; + lwmqtt_string_t topic_filter_s1 = {0, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0xde, 0xe5, 0xec}; + lwmqtt_string_t topic_filter_s2 = {3, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x85, 0xd6, 0xa3}; + lwmqtt_string_t topic_filter_s3 = {3, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x46, 0xba, 0x49, 0xc9, 0x2d, 0xa, 0xf6, 0x12, 0xea, 0xf5, 0x9c, 0x6c, 0x84, + 0x6f, 0xfc, 0x5b, 0x8e, 0x74, 0xd2, 0x6f, 0x15, 0xdd, 0x36, 0x46, 0x96, 0xf1}; + lwmqtt_string_t topic_filter_s4 = {26, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0xf1, 0xb7, 0xb3, 0x37, 0x91, 0x5d, 0x82, 0xbd, 0x2f}; + lwmqtt_string_t topic_filter_s5 = {9, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x2c, 0x50, 0x90, 0x82, 0xb2, 0x8, 0xca, 0x16, + 0x65, 0x91, 0xf0, 0x20, 0x66, 0x9e, 0x32, 0x18}; + lwmqtt_string_t topic_filter_s6 = {16, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xea, 0x63, 0x1d, 0xf, 0x52, 0xb9, 0x37, 0x35, 0x9f}; + lwmqtt_string_t topic_filter_s7 = {9, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 4540, 8, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 16569 +// ["","\170&\222\191\190a\189\220\226\176\DC1|\130\NAK\210\227\141\218\168\DEL\160\156\202\131\134\164"] +// [PropPayloadFormatIndicator 77,PropContentType +// "\177\246\228y\213\231\219\165\211KT\190*\149@\227",PropRequestResponseInformation 49,PropServerKeepAlive +// 10182,PropCorrelationData "\245\EM\245)m\231\US\165C\244b\226\222\243\DC3\142!\178\206\162\246_"] +TEST(Unsubscribe5QCTest, Encode24) { + uint8_t pkt[] = {0xa2, 0x54, 0x40, 0xb9, 0x33, 0x1, 0x4d, 0x3, 0x0, 0x10, 0xb1, 0xf6, 0xe4, 0x79, 0xd5, + 0xe7, 0xdb, 0xa5, 0xd3, 0x4b, 0x54, 0xbe, 0x2a, 0x95, 0x40, 0xe3, 0x19, 0x31, 0x13, 0x27, + 0xc6, 0x9, 0x0, 0x16, 0xf5, 0x19, 0xf5, 0x29, 0x6d, 0xe7, 0x1f, 0xa5, 0x43, 0xf4, 0x62, + 0xe2, 0xde, 0xf3, 0x13, 0x8e, 0x21, 0xb2, 0xce, 0xa2, 0xf6, 0x5f, 0x0, 0x0, 0x0, 0x1a, + 0xaa, 0x26, 0xde, 0xbf, 0xbe, 0x61, 0xbd, 0xdc, 0xe2, 0xb0, 0x11, 0x7c, 0x82, 0x15, 0xd2, + 0xe3, 0x8d, 0xda, 0xa8, 0x7f, 0xa0, 0x9c, 0xca, 0x83, 0x86, 0xa4}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xb1, 0xf6, 0xe4, 0x79, 0xd5, 0xe7, 0xdb, 0xa5, + 0xd3, 0x4b, 0x54, 0xbe, 0x2a, 0x95, 0x40, 0xe3}; + uint8_t bytesprops1[] = {0xf5, 0x19, 0xf5, 0x29, 0x6d, 0xe7, 0x1f, 0xa5, 0x43, 0xf4, 0x62, + 0xe2, 0xde, 0xf3, 0x13, 0x8e, 0x21, 0xb2, 0xce, 0xa2, 0xf6, 0x5f}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 77}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {16, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 49}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 10182}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {22, (char*)&bytesprops1}}}, + }; + + lwmqtt_properties_t props = {5, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[2]; + uint8_t topic_filter_s0_bytes[] = {0}; + lwmqtt_string_t topic_filter_s0 = {0, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0xaa, 0x26, 0xde, 0xbf, 0xbe, 0x61, 0xbd, 0xdc, 0xe2, 0xb0, 0x11, 0x7c, 0x82, + 0x15, 0xd2, 0xe3, 0x8d, 0xda, 0xa8, 0x7f, 0xa0, 0x9c, 0xca, 0x83, 0x86, 0xa4}; + lwmqtt_string_t topic_filter_s1 = {26, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 16569, 2, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 14606 +// [".\DEL\196I\165\SIb1R\244ju\238\DC1\166","3\222\158W\247\213i\STXa","j.\\","G\168\128\184kL\181\SOH2J!\DC4F\DEL\198N+2z\nU\DC4\140.\154\222\SI\137\237","K\213\&7"] +// [PropTopicAlias 21144,PropSubscriptionIdentifierAvailable 107,PropPayloadFormatIndicator 198,PropMaximumPacketSize +// 25428,PropMessageExpiryInterval 23996,PropPayloadFormatIndicator 95,PropMaximumQoS 196,PropSubscriptionIdentifier +// 12,PropAuthenticationData "\SI1\225.\255\172\242\218P\189\159\148Y9\206\&2P\SI\214",PropResponseInformation +// "w\255^\174&\227\237\189\134-\130\153\&3\182\199E\206\224\178\229",PropRequestResponseInformation +// 236,PropTopicAliasMaximum 26590] +TEST(Unsubscribe5QCTest, Encode25) { + uint8_t pkt[] = {0xa2, 0x91, 0x1, 0x39, 0xe, 0x49, 0x23, 0x52, 0x98, 0x29, 0x6b, 0x1, 0xc6, 0x27, 0x0, 0x0, 0x63, + 0x54, 0x2, 0x0, 0x0, 0x5d, 0xbc, 0x1, 0x5f, 0x24, 0xc4, 0xb, 0xc, 0x16, 0x0, 0x13, 0xf, 0x31, + 0xe1, 0x2e, 0xff, 0xac, 0xf2, 0xda, 0x50, 0xbd, 0x9f, 0x94, 0x59, 0x39, 0xce, 0x32, 0x50, 0xf, 0xd6, + 0x1a, 0x0, 0x14, 0x77, 0xff, 0x5e, 0xae, 0x26, 0xe3, 0xed, 0xbd, 0x86, 0x2d, 0x82, 0x99, 0x33, 0xb6, + 0xc7, 0x45, 0xce, 0xe0, 0xb2, 0xe5, 0x19, 0xec, 0x22, 0x67, 0xde, 0x0, 0xf, 0x2e, 0x7f, 0xc4, 0x49, + 0xa5, 0xf, 0x62, 0x31, 0x52, 0xf4, 0x6a, 0x75, 0xee, 0x11, 0xa6, 0x0, 0x9, 0x33, 0xde, 0x9e, 0x57, + 0xf7, 0xd5, 0x69, 0x2, 0x61, 0x0, 0x3, 0x6a, 0x2e, 0x5c, 0x0, 0x1d, 0x47, 0xa8, 0x80, 0xb8, 0x6b, + 0x4c, 0xb5, 0x1, 0x32, 0x4a, 0x21, 0x14, 0x46, 0x7f, 0xc6, 0x4e, 0x2b, 0x32, 0x7a, 0xa, 0x55, 0x14, + 0x8c, 0x2e, 0x9a, 0xde, 0xf, 0x89, 0xed, 0x0, 0x3, 0x4b, 0xd5, 0x37}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xf, 0x31, 0xe1, 0x2e, 0xff, 0xac, 0xf2, 0xda, 0x50, 0xbd, + 0x9f, 0x94, 0x59, 0x39, 0xce, 0x32, 0x50, 0xf, 0xd6}; + uint8_t bytesprops1[] = {0x77, 0xff, 0x5e, 0xae, 0x26, 0xe3, 0xed, 0xbd, 0x86, 0x2d, + 0x82, 0x99, 0x33, 0xb6, 0xc7, 0x45, 0xce, 0xe0, 0xb2, 0xe5}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 21144}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 107}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 198}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 25428}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 23996}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 95}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 196}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 12}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {19, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {20, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 236}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 26590}}, + }; + + lwmqtt_properties_t props = {12, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[5]; + uint8_t topic_filter_s0_bytes[] = {0x2e, 0x7f, 0xc4, 0x49, 0xa5, 0xf, 0x62, 0x31, + 0x52, 0xf4, 0x6a, 0x75, 0xee, 0x11, 0xa6}; + lwmqtt_string_t topic_filter_s0 = {15, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x33, 0xde, 0x9e, 0x57, 0xf7, 0xd5, 0x69, 0x2, 0x61}; + lwmqtt_string_t topic_filter_s1 = {9, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x6a, 0x2e, 0x5c}; + lwmqtt_string_t topic_filter_s2 = {3, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x47, 0xa8, 0x80, 0xb8, 0x6b, 0x4c, 0xb5, 0x1, 0x32, 0x4a, + 0x21, 0x14, 0x46, 0x7f, 0xc6, 0x4e, 0x2b, 0x32, 0x7a, 0xa, + 0x55, 0x14, 0x8c, 0x2e, 0x9a, 0xde, 0xf, 0x89, 0xed}; + lwmqtt_string_t topic_filter_s3 = {29, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x4b, 0xd5, 0x37}; + lwmqtt_string_t topic_filter_s4 = {3, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 14606, 5, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 14000 +// ["","l\209\US\STX\SId","\186\198#\203t@D","\179\177g\225l","y\192\ESC\206\153\GSTVb\180\254\139\221\&7\255\219\208\234\DC3\240\137\202tp\SYN\158\149","}\b\152\173Sm\225\172\173{#\199\150N\170\136\217S\229\&7\250\155\168\180\134\181","\133q","\216\211GO\136w\142\SI","\135\212\152\253\ETX\232\227\216\DLE\245\131QC-\ETB2&\237I\219{\132\&20|A\148","&\227\176:l([\140;\250\179\157\b\166\137\242\231\EOTw\164\139","\204Q\203\251\SOHMX\193$\139\&12\178y\195V{\206q\FScT"] +// [] +TEST(Unsubscribe5QCTest, Encode27) { + uint8_t pkt[] = {0xa2, 0xe7, 0x1, 0x75, 0x7, 0x0, 0x0, 0xc, 0x0, 0x76, 0x5f, 0x47, 0x29, 0xdf, 0x6f, 0x38, 0xf1, + 0xf0, 0xa5, 0xff, 0x0, 0x1a, 0x1e, 0xb6, 0x64, 0x1c, 0x72, 0xa6, 0x4, 0xbd, 0x9, 0xf4, 0xab, 0x77, + 0xed, 0xf7, 0xa2, 0x71, 0xc8, 0x4b, 0x6f, 0x29, 0xe, 0xbb, 0xd, 0x1f, 0x36, 0x52, 0x0, 0x6, 0x8d, + 0x28, 0xa5, 0x2f, 0xd9, 0x38, 0x0, 0x1d, 0x0, 0x4, 0xde, 0x14, 0x6c, 0x6b, 0xab, 0x5a, 0xde, 0xd0, + 0x9, 0x31, 0xce, 0x7d, 0x29, 0xd8, 0xb0, 0xf1, 0x1a, 0xe2, 0x29, 0x99, 0x7f, 0xbc, 0x36, 0x57, 0x76, + 0xb0, 0x3e, 0x0, 0x1b, 0x79, 0xc0, 0x1b, 0xce, 0x99, 0x1d, 0x54, 0x56, 0x62, 0xb4, 0xfe, 0x8b, 0xdd, + 0x37, 0xff, 0xdb, 0xd0, 0xea, 0x13, 0xf0, 0x89, 0xca, 0x74, 0x70, 0x16, 0x9e, 0x95, 0x0, 0x1a, 0x7d, + 0x8, 0x98, 0xad, 0x53, 0x6d, 0xe1, 0xac, 0xad, 0x7b, 0x23, 0xc7, 0x96, 0x4e, 0xaa, 0x88, 0xd9, 0x53, + 0xe5, 0x37, 0xfa, 0x9b, 0xa8, 0xb4, 0x86, 0xb5, 0x0, 0x2, 0x85, 0x71, 0x0, 0x8, 0xd8, 0xd3, 0x47, + 0x4f, 0x88, 0x77, 0x8e, 0xf, 0x0, 0x1b, 0x87, 0xd4, 0x98, 0xfd, 0x3, 0xe8, 0xe3, 0xd8, 0x10, 0xf5, + 0x83, 0x51, 0x43, 0x2d, 0x17, 0x32, 0x26, 0xed, 0x49, 0xdb, 0x7b, 0x84, 0x32, 0x30, 0x7c, 0x41, 0x94, + 0x0, 0x15, 0x26, 0xe3, 0xb0, 0x3a, 0x6c, 0x28, 0x5b, 0x8c, 0x3b, 0xfa, 0xb3, 0x9d, 0x8, 0xa6, 0x89, + 0xf2, 0xe7, 0x4, 0x77, 0xa4, 0x8b, 0x0, 0x16, 0xcc, 0x51, 0xcb, 0xfb, 0x1, 0x4d, 0x58, 0xc1, 0x24, + 0x8b, 0x31, 0x32, 0xb2, 0x79, 0xc3, 0x56, 0x7b, 0xce, 0x71, 0x1c, 0x63, 0x54}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[11]; + uint8_t topic_filter_s0_bytes[] = {0x0, 0x76, 0x5f, 0x47, 0x29, 0xdf, 0x6f, 0x38, 0xf1, 0xf0, 0xa5, 0xff}; + lwmqtt_string_t topic_filter_s0 = {12, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + uint8_t topic_filter_s1_bytes[] = {0x1e, 0xb6, 0x64, 0x1c, 0x72, 0xa6, 0x4, 0xbd, 0x9, 0xf4, 0xab, 0x77, 0xed, + 0xf7, 0xa2, 0x71, 0xc8, 0x4b, 0x6f, 0x29, 0xe, 0xbb, 0xd, 0x1f, 0x36, 0x52}; + lwmqtt_string_t topic_filter_s1 = {26, (char*)&topic_filter_s1_bytes}; + topic_filters[1] = topic_filter_s1; + uint8_t topic_filter_s2_bytes[] = {0x8d, 0x28, 0xa5, 0x2f, 0xd9, 0x38}; + lwmqtt_string_t topic_filter_s2 = {6, (char*)&topic_filter_s2_bytes}; + topic_filters[2] = topic_filter_s2; + uint8_t topic_filter_s3_bytes[] = {0x0, 0x4, 0xde, 0x14, 0x6c, 0x6b, 0xab, 0x5a, 0xde, 0xd0, + 0x9, 0x31, 0xce, 0x7d, 0x29, 0xd8, 0xb0, 0xf1, 0x1a, 0xe2, + 0x29, 0x99, 0x7f, 0xbc, 0x36, 0x57, 0x76, 0xb0, 0x3e}; + lwmqtt_string_t topic_filter_s3 = {29, (char*)&topic_filter_s3_bytes}; + topic_filters[3] = topic_filter_s3; + uint8_t topic_filter_s4_bytes[] = {0x79, 0xc0, 0x1b, 0xce, 0x99, 0x1d, 0x54, 0x56, 0x62, 0xb4, 0xfe, 0x8b, 0xdd, 0x37, + 0xff, 0xdb, 0xd0, 0xea, 0x13, 0xf0, 0x89, 0xca, 0x74, 0x70, 0x16, 0x9e, 0x95}; + lwmqtt_string_t topic_filter_s4 = {27, (char*)&topic_filter_s4_bytes}; + topic_filters[4] = topic_filter_s4; + uint8_t topic_filter_s5_bytes[] = {0x7d, 0x8, 0x98, 0xad, 0x53, 0x6d, 0xe1, 0xac, 0xad, 0x7b, 0x23, 0xc7, 0x96, + 0x4e, 0xaa, 0x88, 0xd9, 0x53, 0xe5, 0x37, 0xfa, 0x9b, 0xa8, 0xb4, 0x86, 0xb5}; + lwmqtt_string_t topic_filter_s5 = {26, (char*)&topic_filter_s5_bytes}; + topic_filters[5] = topic_filter_s5; + uint8_t topic_filter_s6_bytes[] = {0x85, 0x71}; + lwmqtt_string_t topic_filter_s6 = {2, (char*)&topic_filter_s6_bytes}; + topic_filters[6] = topic_filter_s6; + uint8_t topic_filter_s7_bytes[] = {0xd8, 0xd3, 0x47, 0x4f, 0x88, 0x77, 0x8e, 0xf}; + lwmqtt_string_t topic_filter_s7 = {8, (char*)&topic_filter_s7_bytes}; + topic_filters[7] = topic_filter_s7; + uint8_t topic_filter_s8_bytes[] = {0x87, 0xd4, 0x98, 0xfd, 0x3, 0xe8, 0xe3, 0xd8, 0x10, 0xf5, 0x83, 0x51, 0x43, 0x2d, + 0x17, 0x32, 0x26, 0xed, 0x49, 0xdb, 0x7b, 0x84, 0x32, 0x30, 0x7c, 0x41, 0x94}; + lwmqtt_string_t topic_filter_s8 = {27, (char*)&topic_filter_s8_bytes}; + topic_filters[8] = topic_filter_s8; + uint8_t topic_filter_s9_bytes[] = {0x26, 0xe3, 0xb0, 0x3a, 0x6c, 0x28, 0x5b, 0x8c, 0x3b, 0xfa, 0xb3, + 0x9d, 0x8, 0xa6, 0x89, 0xf2, 0xe7, 0x4, 0x77, 0xa4, 0x8b}; + lwmqtt_string_t topic_filter_s9 = {21, (char*)&topic_filter_s9_bytes}; + topic_filters[9] = topic_filter_s9; + uint8_t topic_filter_s10_bytes[] = {0xcc, 0x51, 0xcb, 0xfb, 0x1, 0x4d, 0x58, 0xc1, 0x24, 0x8b, 0x31, + 0x32, 0xb2, 0x79, 0xc3, 0x56, 0x7b, 0xce, 0x71, 0x1c, 0x63, 0x54}; + lwmqtt_string_t topic_filter_s10 = {22, (char*)&topic_filter_s10_bytes}; + topic_filters[10] = topic_filter_s10; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 29959, 11, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 5839 [""] [PropTopicAlias 20494,PropReasonString +// "\209TK\251\222t\241\153\249\160\137v\173\170\185\\\248",PropMaximumPacketSize 27173,PropAuthenticationData +// "FL\221K\173\149\&8O@T\156\143\DC1\DELL\173\133",PropAuthenticationData +// "\160V\186Q7=\170\r\190\157H\131",PropMessageExpiryInterval 31658,PropResponseInformation +// "\EOT\157v\140+UM.\SI\244\190\218\255\r\CANhF\SOH\241e%",PropCorrelationData +// "\165\141vRF`\252:\143\178\215P\SO(\137\185\129\242r]\235\229v\a\158\n\168\202",PropResponseTopic +// "r<",PropRequestResponseInformation 153,PropRequestResponseInformation 219,PropWildcardSubscriptionAvailable +// 189,PropMessageExpiryInterval 32074,PropRequestResponseInformation 132,PropTopicAlias 30293,PropSessionExpiryInterval +// 18670,PropAuthenticationMethod "\242\\v\226+\158\162",PropCorrelationData +// "\NAK\229\181:\160\215\246R\186\229\196@8gn\142\161-",PropSubscriptionIdentifier 8,PropSessionExpiryInterval +// 1022,PropRequestProblemInformation 139,PropReasonString "m\254iR\242}\220\246\206\&0",PropPayloadFormatIndicator +// 108,PropResponseInformation +// "\GS@\157>iB\206\238O\128\236-\191P)\234\b\CAN\135\242\169\250n\139\SUB",PropAuthenticationData +// "\176\FSs/l\GS\172\165\194;\169\171\ENQ\253\234_\156L(\172",PropAuthenticationMethod +// "7*H\232\235s\US",PropReasonString "v<\197rS\142",PropMaximumQoS 55] +TEST(Unsubscribe5QCTest, Encode28) { + uint8_t pkt[] = { + 0xa2, 0x9a, 0x2, 0x16, 0xcf, 0x94, 0x2, 0x23, 0x50, 0xe, 0x1f, 0x0, 0x11, 0xd1, 0x54, 0x4b, 0xfb, 0xde, 0x74, + 0xf1, 0x99, 0xf9, 0xa0, 0x89, 0x76, 0xad, 0xaa, 0xb9, 0x5c, 0xf8, 0x27, 0x0, 0x0, 0x6a, 0x25, 0x16, 0x0, 0x11, + 0x46, 0x4c, 0xdd, 0x4b, 0xad, 0x95, 0x38, 0x4f, 0x40, 0x54, 0x9c, 0x8f, 0x11, 0x7f, 0x4c, 0xad, 0x85, 0x16, 0x0, + 0xc, 0xa0, 0x56, 0xba, 0x51, 0x37, 0x3d, 0xaa, 0xd, 0xbe, 0x9d, 0x48, 0x83, 0x2, 0x0, 0x0, 0x7b, 0xaa, 0x1a, + 0x0, 0x15, 0x4, 0x9d, 0x76, 0x8c, 0x2b, 0x55, 0x4d, 0x2e, 0xf, 0xf4, 0xbe, 0xda, 0xff, 0xd, 0x18, 0x68, 0x46, + 0x1, 0xf1, 0x65, 0x25, 0x9, 0x0, 0x1c, 0xa5, 0x8d, 0x76, 0x52, 0x46, 0x60, 0xfc, 0x3a, 0x8f, 0xb2, 0xd7, 0x50, + 0xe, 0x28, 0x89, 0xb9, 0x81, 0xf2, 0x72, 0x5d, 0xeb, 0xe5, 0x76, 0x7, 0x9e, 0xa, 0xa8, 0xca, 0x8, 0x0, 0x2, + 0x72, 0x3c, 0x19, 0x99, 0x19, 0xdb, 0x28, 0xbd, 0x2, 0x0, 0x0, 0x7d, 0x4a, 0x19, 0x84, 0x23, 0x76, 0x55, 0x11, + 0x0, 0x0, 0x48, 0xee, 0x15, 0x0, 0x7, 0xf2, 0x5c, 0x76, 0xe2, 0x2b, 0x9e, 0xa2, 0x9, 0x0, 0x12, 0x15, 0xe5, + 0xb5, 0x3a, 0xa0, 0xd7, 0xf6, 0x52, 0xba, 0xe5, 0xc4, 0x40, 0x38, 0x67, 0x6e, 0x8e, 0xa1, 0x2d, 0xb, 0x8, 0x11, + 0x0, 0x0, 0x3, 0xfe, 0x17, 0x8b, 0x1f, 0x0, 0xa, 0x6d, 0xfe, 0x69, 0x52, 0xf2, 0x7d, 0xdc, 0xf6, 0xce, 0x30, + 0x1, 0x6c, 0x1a, 0x0, 0x19, 0x1d, 0x40, 0x9d, 0x3e, 0x69, 0x42, 0xce, 0xee, 0x4f, 0x80, 0xec, 0x2d, 0xbf, 0x50, + 0x29, 0xea, 0x8, 0x18, 0x87, 0xf2, 0xa9, 0xfa, 0x6e, 0x8b, 0x1a, 0x16, 0x0, 0x14, 0xb0, 0x1c, 0x73, 0x2f, 0x6c, + 0x1d, 0xac, 0xa5, 0xc2, 0x3b, 0xa9, 0xab, 0x5, 0xfd, 0xea, 0x5f, 0x9c, 0x4c, 0x28, 0xac, 0x15, 0x0, 0x7, 0x37, + 0x2a, 0x48, 0xe8, 0xeb, 0x73, 0x1f, 0x1f, 0x0, 0x6, 0x76, 0x3c, 0xc5, 0x72, 0x53, 0x8e, 0x24, 0x37, 0x0, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xd1, 0x54, 0x4b, 0xfb, 0xde, 0x74, 0xf1, 0x99, 0xf9, + 0xa0, 0x89, 0x76, 0xad, 0xaa, 0xb9, 0x5c, 0xf8}; + uint8_t bytesprops1[] = {0x46, 0x4c, 0xdd, 0x4b, 0xad, 0x95, 0x38, 0x4f, 0x40, + 0x54, 0x9c, 0x8f, 0x11, 0x7f, 0x4c, 0xad, 0x85}; + uint8_t bytesprops2[] = {0xa0, 0x56, 0xba, 0x51, 0x37, 0x3d, 0xaa, 0xd, 0xbe, 0x9d, 0x48, 0x83}; + uint8_t bytesprops3[] = {0x4, 0x9d, 0x76, 0x8c, 0x2b, 0x55, 0x4d, 0x2e, 0xf, 0xf4, 0xbe, + 0xda, 0xff, 0xd, 0x18, 0x68, 0x46, 0x1, 0xf1, 0x65, 0x25}; + uint8_t bytesprops4[] = {0xa5, 0x8d, 0x76, 0x52, 0x46, 0x60, 0xfc, 0x3a, 0x8f, 0xb2, 0xd7, 0x50, 0xe, 0x28, + 0x89, 0xb9, 0x81, 0xf2, 0x72, 0x5d, 0xeb, 0xe5, 0x76, 0x7, 0x9e, 0xa, 0xa8, 0xca}; + uint8_t bytesprops5[] = {0x72, 0x3c}; + uint8_t bytesprops6[] = {0xf2, 0x5c, 0x76, 0xe2, 0x2b, 0x9e, 0xa2}; + uint8_t bytesprops7[] = {0x15, 0xe5, 0xb5, 0x3a, 0xa0, 0xd7, 0xf6, 0x52, 0xba, + 0xe5, 0xc4, 0x40, 0x38, 0x67, 0x6e, 0x8e, 0xa1, 0x2d}; + uint8_t bytesprops8[] = {0x6d, 0xfe, 0x69, 0x52, 0xf2, 0x7d, 0xdc, 0xf6, 0xce, 0x30}; + uint8_t bytesprops9[] = {0x1d, 0x40, 0x9d, 0x3e, 0x69, 0x42, 0xce, 0xee, 0x4f, 0x80, 0xec, 0x2d, 0xbf, + 0x50, 0x29, 0xea, 0x8, 0x18, 0x87, 0xf2, 0xa9, 0xfa, 0x6e, 0x8b, 0x1a}; + uint8_t bytesprops10[] = {0xb0, 0x1c, 0x73, 0x2f, 0x6c, 0x1d, 0xac, 0xa5, 0xc2, 0x3b, + 0xa9, 0xab, 0x5, 0xfd, 0xea, 0x5f, 0x9c, 0x4c, 0x28, 0xac}; + uint8_t bytesprops11[] = {0x37, 0x2a, 0x48, 0xe8, 0xeb, 0x73, 0x1f}; + uint8_t bytesprops12[] = {0x76, 0x3c, 0xc5, 0x72, 0x53, 0x8e}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 20494}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {17, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 27173}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {17, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {12, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 31658}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {21, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {28, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {2, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 153}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 219}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 189}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 32074}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 132}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 30293}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 18670}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {7, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {18, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 8}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 1022}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 139}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {10, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 108}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {25, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {20, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {7, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {6, (char*)&bytesprops12}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 55}}, + }; + + lwmqtt_properties_t props = {28, (lwmqtt_property_t*)&propslist}; + lwmqtt_string_t topic_filters[1]; + uint8_t topic_filter_s0_bytes[] = {0}; + lwmqtt_string_t topic_filter_s0 = {0, (char*)&topic_filter_s0_bytes}; + topic_filters[0] = topic_filter_s0; + size_t len; + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, sizeof(buf), &len, LWMQTT_MQTT5, 5839, 1, topic_filters, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// UnsubscribeRequest 8093 +// ["\140\244F\161","k5\NAK\128\246yah\170\t","\154\DC2\209)BN\179P\ETX>:\DC1\174\174\143HZZ","\137\208\145\SO\\\207\ETB\163","\181w4\223bZ\155\243A\162\248\162p\158\190\162\&8\132\v\163\&2\238\"\206k6\132","C\SUB\243\t\186\&0\166\DLE\211\148H\185\196\132\221\228\190%\144@~\243\255","G*","\FS\201\240\&9s\203\239\199\205d","V\\\216CA(\177f\229\172\150R\176r-\217\135","\215\217\143Yxc2f\\\168\229\ETX\SUB\214\207\DEL!\198\223\131%\147\r\ESC\199l8|\159\181"] +// [PropAuthenticationMethod "",PropAssignedClientIdentifier ";\255\n\176\141 +// \212\144\EOT\141\249?ZA\ETX\235a\159\233\150\139%\DC1`\250",PropContentType +// "\222\166\132xw\211\137N\244\215|V",PropSubscriptionIdentifierAvailable +// 174,PropTopicAlias 11328,PropTopicAliasMaximum 4253,PropSharedSubscriptionAvailable 133,PropMessageExpiryInterval +// 31868] +// [UnsubSuccess,UnsubNoSubscriptionExisted,UnsubNoSubscriptionExisted,UnsubNoSubscriptionExisted,UnsubPacketIdentifierInUse,UnsubNoSubscriptionExisted,UnsubNoSubscriptionExisted,UnsubTopicFilterInvalid,UnsubNotAuthorized,UnsubTopicFilterInvalid,UnsubNotAuthorized,UnsubImplementationSpecificError,UnsubNotAuthorized] +TEST(UnsubACK5QCTest, Decode5) { + uint8_t pkt[] = {0xb0, 0x5e, 0x54, 0xc4, 0x4e, 0x24, 0x4, 0x17, 0x17, 0x21, 0x2a, 0xfa, 0x17, 0x6f, 0x18, 0x0, + 0x0, 0x34, 0x7d, 0xb, 0xd, 0x19, 0xa9, 0x27, 0x0, 0x0, 0x10, 0x32, 0x26, 0x0, 0x5, 0x68, + 0x7a, 0x69, 0xa7, 0x3b, 0x0, 0x1e, 0x6e, 0x77, 0xa9, 0x28, 0xf6, 0x76, 0xfb, 0x4e, 0x9a, 0x33, + 0xa2, 0x53, 0x5, 0x43, 0xff, 0xaf, 0x6e, 0x1d, 0xdb, 0xde, 0x74, 0x37, 0x63, 0x90, 0x49, 0x1a, + 0xd9, 0x7f, 0x3e, 0x56, 0x29, 0xae, 0x23, 0x2c, 0x40, 0x22, 0x10, 0x9d, 0x2a, 0x85, 0x2, 0x0, + 0x0, 0x7c, 0x7c, 0x0, 0x11, 0x11, 0x11, 0x91, 0x11, 0x11, 0x8f, 0x87, 0x8f, 0x87, 0x83, 0x87}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[13]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 13, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 21700); + EXPECT_EQ(count, 13); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_NOT_AUTHORIZED); +} + +// UnsubscribeResponse 4207 [PropWillDelayInterval 12820,PropSubscriptionIdentifierAvailable 158,PropReasonString +// "\231\v-\RS\153\253\139z\233\147c\fx\ENQ\187",PropMaximumQoS 230,PropContentType +// "\233\172\192\233@\178F*_\182\148]98\178\SUB\175\230\&1\240\196\&7\146\ETBV:",PropPayloadFormatIndicator +// 47,PropResponseTopic "\197R\230p\228\185\217",PropSubscriptionIdentifier 17,PropAssignedClientIdentifier +// "gi\153!\237\157\252-O\162\174\148\166\184\174\136=\218?\138,\186`{\USh\aE\180",PropWillDelayInterval +// 17698,PropRequestProblemInformation 2] +// [UnsubPacketIdentifierInUse,UnsubUnspecifiedError,UnsubUnspecifiedError,UnsubNoSubscriptionExisted,UnsubTopicFilterInvalid,UnsubTopicFilterInvalid,UnsubUnspecifiedError,UnsubNotAuthorized,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubImplementationSpecificError,UnsubNotAuthorized,UnsubSuccess] +TEST(UnsubACK5QCTest, Decode6) { + uint8_t pkt[] = {0xb0, 0x7d, 0x10, 0x6f, 0x6d, 0x18, 0x0, 0x0, 0x32, 0x14, 0x29, 0x9e, 0x1f, 0x0, 0xf, 0xe7, + 0xb, 0x2d, 0x1e, 0x99, 0xfd, 0x8b, 0x7a, 0xe9, 0x93, 0x63, 0xc, 0x78, 0x5, 0xbb, 0x24, 0xe6, + 0x3, 0x0, 0x1a, 0xe9, 0xac, 0xc0, 0xe9, 0x40, 0xb2, 0x46, 0x2a, 0x5f, 0xb6, 0x94, 0x5d, 0x39, + 0x38, 0xb2, 0x1a, 0xaf, 0xe6, 0x31, 0xf0, 0xc4, 0x37, 0x92, 0x17, 0x56, 0x3a, 0x1, 0x2f, 0x8, + 0x0, 0x7, 0xc5, 0x52, 0xe6, 0x70, 0xe4, 0xb9, 0xd9, 0xb, 0x11, 0x12, 0x0, 0x1d, 0x67, 0x69, + 0x99, 0x21, 0xed, 0x9d, 0xfc, 0x2d, 0x4f, 0xa2, 0xae, 0x94, 0xa6, 0xb8, 0xae, 0x88, 0x3d, 0xda, + 0x3f, 0x8a, 0x2c, 0xba, 0x60, 0x7b, 0x1f, 0x68, 0x7, 0x45, 0xb4, 0x18, 0x0, 0x0, 0x45, 0x22, + 0x17, 0x2, 0x91, 0x80, 0x80, 0x11, 0x8f, 0x8f, 0x80, 0x87, 0x83, 0x11, 0x83, 0x87, 0x0}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[13]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 13, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 4207); + EXPECT_EQ(count, 13); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_SUCCESS); +} + +// UnsubscribeResponse 28996 [PropWillDelayInterval 25960,PropRequestProblemInformation 14,PropAssignedClientIdentifier +// "\252\160G|\155\243\ajSU\NUL\192\"\235|_\254\132\232tyC\239\147m\185\147m",PropAssignedClientIdentifier +// "N\239\GS\189y\225q\159\SI",PropRetainAvailable 43,PropServerKeepAlive 3805,PropResponseInformation +// "\228\166\180\151\200h\157H\218T\170\213\131\233\136|",PropResponseTopic "\150",PropCorrelationData +// "B\155\205>C\167]\146\f\135\&3\130\166\FS\128\144\182U}\212\t\210C\186",PropWildcardSubscriptionAvailable +// 1,PropReceiveMaximum 14741,PropPayloadFormatIndicator 144,PropAuthenticationMethod +// "\NAK\"\139\215K\195O\242\182\162\\\248\189P\133n\167\&1\f\206U\201\193\209\203",PropReasonString +// "\144\&9\168,\230\188\208\159\135\236AQp\142\NAK\RS\187\b\131\DEL\241\169",PropMessageExpiryInterval +// 6194,PropCorrelationData +// "\219\147\232\231wg\226p\178#\199\EOT\DC2\231_\210\157\143\203\203\154\SYN\200jop\135\189om",PropUserProperty +// "\198M\161\242_\189?\STX\239" "?\192\189\&2Qx",PropReasonString "\134\243\149\183?Q\255\179\148\134",PropTopicAlias +// 32648,PropTopicAlias 24030,PropAuthenticationData "\239",PropCorrelationData +// "T\188\225\a\237\142Y;s\209\172\&7\237W\208X]",PropWildcardSubscriptionAvailable 92,PropResponseInformation +// "f\187[\194\128",PropSubscriptionIdentifierAvailable 165,PropCorrelationData +// "\SUB\153b\166\SOf\131\v\254\229\&6\DC2q\198\&1~%\141U\203\ACK\ETB\250\215\158\240I",PropWildcardSubscriptionAvailable +// 214,PropTopicAlias 11353] +// [UnsubUnspecifiedError,UnsubNoSubscriptionExisted,UnsubTopicFilterInvalid,UnsubImplementationSpecificError,UnsubImplementationSpecificError,UnsubUnspecifiedError,UnsubImplementationSpecificError,UnsubPacketIdentifierInUse,UnsubNotAuthorized,UnsubNoSubscriptionExisted,UnsubNotAuthorized,UnsubUnspecifiedError,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubNotAuthorized,UnsubPacketIdentifierInUse] +TEST(UnsubACK5QCTest, Decode7) { + uint8_t pkt[] = { + 0xb0, 0xcd, 0x2, 0x71, 0x44, 0xb9, 0x2, 0x18, 0x0, 0x0, 0x65, 0x68, 0x17, 0xe, 0x12, 0x0, 0x1c, 0xfc, 0xa0, + 0x47, 0x7c, 0x9b, 0xf3, 0x7, 0x6a, 0x53, 0x55, 0x0, 0xc0, 0x22, 0xeb, 0x7c, 0x5f, 0xfe, 0x84, 0xe8, 0x74, 0x79, + 0x43, 0xef, 0x93, 0x6d, 0xb9, 0x93, 0x6d, 0x12, 0x0, 0x9, 0x4e, 0xef, 0x1d, 0xbd, 0x79, 0xe1, 0x71, 0x9f, 0xf, + 0x25, 0x2b, 0x13, 0xe, 0xdd, 0x1a, 0x0, 0x10, 0xe4, 0xa6, 0xb4, 0x97, 0xc8, 0x68, 0x9d, 0x48, 0xda, 0x54, 0xaa, + 0xd5, 0x83, 0xe9, 0x88, 0x7c, 0x8, 0x0, 0x1, 0x96, 0x9, 0x0, 0x18, 0x42, 0x9b, 0xcd, 0x3e, 0x43, 0xa7, 0x5d, + 0x92, 0xc, 0x87, 0x33, 0x82, 0xa6, 0x1c, 0x80, 0x90, 0xb6, 0x55, 0x7d, 0xd4, 0x9, 0xd2, 0x43, 0xba, 0x28, 0x1, + 0x21, 0x39, 0x95, 0x1, 0x90, 0x15, 0x0, 0x19, 0x15, 0x22, 0x8b, 0xd7, 0x4b, 0xc3, 0x4f, 0xf2, 0xb6, 0xa2, 0x5c, + 0xf8, 0xbd, 0x50, 0x85, 0x6e, 0xa7, 0x31, 0xc, 0xce, 0x55, 0xc9, 0xc1, 0xd1, 0xcb, 0x1f, 0x0, 0x16, 0x90, 0x39, + 0xa8, 0x2c, 0xe6, 0xbc, 0xd0, 0x9f, 0x87, 0xec, 0x41, 0x51, 0x70, 0x8e, 0x15, 0x1e, 0xbb, 0x8, 0x83, 0x7f, 0xf1, + 0xa9, 0x2, 0x0, 0x0, 0x18, 0x32, 0x9, 0x0, 0x1e, 0xdb, 0x93, 0xe8, 0xe7, 0x77, 0x67, 0xe2, 0x70, 0xb2, 0x23, + 0xc7, 0x4, 0x12, 0xe7, 0x5f, 0xd2, 0x9d, 0x8f, 0xcb, 0xcb, 0x9a, 0x16, 0xc8, 0x6a, 0x6f, 0x70, 0x87, 0xbd, 0x6f, + 0x6d, 0x26, 0x0, 0x9, 0xc6, 0x4d, 0xa1, 0xf2, 0x5f, 0xbd, 0x3f, 0x2, 0xef, 0x0, 0x6, 0x3f, 0xc0, 0xbd, 0x32, + 0x51, 0x78, 0x1f, 0x0, 0xa, 0x86, 0xf3, 0x95, 0xb7, 0x3f, 0x51, 0xff, 0xb3, 0x94, 0x86, 0x23, 0x7f, 0x88, 0x23, + 0x5d, 0xde, 0x16, 0x0, 0x1, 0xef, 0x9, 0x0, 0x11, 0x54, 0xbc, 0xe1, 0x7, 0xed, 0x8e, 0x59, 0x3b, 0x73, 0xd1, + 0xac, 0x37, 0xed, 0x57, 0xd0, 0x58, 0x5d, 0x28, 0x5c, 0x1a, 0x0, 0x5, 0x66, 0xbb, 0x5b, 0xc2, 0x80, 0x29, 0xa5, + 0x9, 0x0, 0x1b, 0x1a, 0x99, 0x62, 0xa6, 0xe, 0x66, 0x83, 0xb, 0xfe, 0xe5, 0x36, 0x12, 0x71, 0xc6, 0x31, 0x7e, + 0x25, 0x8d, 0x55, 0xcb, 0x6, 0x17, 0xfa, 0xd7, 0x9e, 0xf0, 0x49, 0x28, 0xd6, 0x23, 0x2c, 0x59, 0x80, 0x11, 0x8f, + 0x83, 0x83, 0x80, 0x83, 0x91, 0x87, 0x11, 0x87, 0x80, 0x83, 0x11, 0x87, 0x91}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[16]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 16, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 28996); + EXPECT_EQ(count, 16); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[15], LWMQTT_UNSUB_PACKET_ID_IN_USE); +} + +// UnsubscribeResponse 7059 [PropServerKeepAlive 5109,PropRequestProblemInformation 233,PropContentType +// "\166\EM\175\163zdd\EMl@\145t\151?\239\154\162\212v",PropWillDelayInterval 9912,PropMessageExpiryInterval +// 12965,PropMaximumPacketSize 6332,PropTopicAliasMaximum 30771,PropSubscriptionIdentifier 29,PropMaximumQoS +// 207,PropCorrelationData +// "\159\\\CAN\151\158a\254\218\162\SOH\153\ETBC\t\203*x\191\223\NAKM\207\DEL\149w`",PropServerKeepAlive +// 3449,PropMaximumPacketSize 15149,PropReceiveMaximum 25363,PropPayloadFormatIndicator 60,PropSessionExpiryInterval +// 8805,PropResponseInformation +// "\143\194\NAK\178\247\CAN<\190\176\194(\189\225B\134\239\194\138\192m7",PropPayloadFormatIndicator +// 235,PropWildcardSubscriptionAvailable 177,PropRequestProblemInformation 199,PropMaximumPacketSize +// 24444,PropServerKeepAlive 21766,PropPayloadFormatIndicator 161,PropUserProperty "\180GL\149EJ \159\160g\174\137\179:" +// "V\143\196Y\253",PropAuthenticationData +// "G\218\156\225\239h\184\243|8\179mr\192\DC3I\169\240\205,e*\179\174$\241",PropMaximumQoS 6,PropTopicAliasMaximum +// 215,PropWildcardSubscriptionAvailable 148,PropMessageExpiryInterval 13104,PropAssignedClientIdentifier "["] +// [UnsubSuccess,UnsubSuccess,UnsubSuccess,UnsubImplementationSpecificError,UnsubUnspecifiedError,UnsubNotAuthorized,UnsubSuccess,UnsubNoSubscriptionExisted,UnsubPacketIdentifierInUse,UnsubSuccess,UnsubNoSubscriptionExisted,UnsubTopicFilterInvalid,UnsubTopicFilterInvalid,UnsubTopicFilterInvalid,UnsubUnspecifiedError,UnsubTopicFilterInvalid,UnsubPacketIdentifierInUse,UnsubTopicFilterInvalid,UnsubUnspecifiedError,UnsubNotAuthorized,UnsubSuccess,UnsubNoSubscriptionExisted] +TEST(UnsubACK5QCTest, Decode8) { + uint8_t pkt[] = {0xb0, 0xe7, 0x1, 0x1b, 0x93, 0xcd, 0x1, 0x13, 0x13, 0xf5, 0x17, 0xe9, 0x3, 0x0, 0x13, 0xa6, 0x19, + 0xaf, 0xa3, 0x7a, 0x64, 0x64, 0x19, 0x6c, 0x40, 0x91, 0x74, 0x97, 0x3f, 0xef, 0x9a, 0xa2, 0xd4, 0x76, + 0x18, 0x0, 0x0, 0x26, 0xb8, 0x2, 0x0, 0x0, 0x32, 0xa5, 0x27, 0x0, 0x0, 0x18, 0xbc, 0x22, 0x78, + 0x33, 0xb, 0x1d, 0x24, 0xcf, 0x9, 0x0, 0x1a, 0x9f, 0x5c, 0x18, 0x97, 0x9e, 0x61, 0xfe, 0xda, 0xa2, + 0x1, 0x99, 0x17, 0x43, 0x9, 0xcb, 0x2a, 0x78, 0xbf, 0xdf, 0x15, 0x4d, 0xcf, 0x7f, 0x95, 0x77, 0x60, + 0x13, 0xd, 0x79, 0x27, 0x0, 0x0, 0x3b, 0x2d, 0x21, 0x63, 0x13, 0x1, 0x3c, 0x11, 0x0, 0x0, 0x22, + 0x65, 0x1a, 0x0, 0x15, 0x8f, 0xc2, 0x15, 0xb2, 0xf7, 0x18, 0x3c, 0xbe, 0xb0, 0xc2, 0x28, 0xbd, 0xe1, + 0x42, 0x86, 0xef, 0xc2, 0x8a, 0xc0, 0x6d, 0x37, 0x1, 0xeb, 0x28, 0xb1, 0x17, 0xc7, 0x27, 0x0, 0x0, + 0x5f, 0x7c, 0x13, 0x55, 0x6, 0x1, 0xa1, 0x26, 0x0, 0xe, 0xb4, 0x47, 0x4c, 0x95, 0x45, 0x4a, 0x20, + 0x9f, 0xa0, 0x67, 0xae, 0x89, 0xb3, 0x3a, 0x0, 0x5, 0x56, 0x8f, 0xc4, 0x59, 0xfd, 0x16, 0x0, 0x1a, + 0x47, 0xda, 0x9c, 0xe1, 0xef, 0x68, 0xb8, 0xf3, 0x7c, 0x38, 0xb3, 0x6d, 0x72, 0xc0, 0x13, 0x49, 0xa9, + 0xf0, 0xcd, 0x2c, 0x65, 0x2a, 0xb3, 0xae, 0x24, 0xf1, 0x24, 0x6, 0x22, 0x0, 0xd7, 0x28, 0x94, 0x2, + 0x0, 0x0, 0x33, 0x30, 0x12, 0x0, 0x1, 0x5b, 0x0, 0x0, 0x0, 0x83, 0x80, 0x87, 0x0, 0x11, 0x91, + 0x0, 0x11, 0x8f, 0x8f, 0x8f, 0x80, 0x8f, 0x91, 0x8f, 0x80, 0x87, 0x0, 0x11}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[22]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 22, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 7059); + EXPECT_EQ(count, 22); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[15], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[16], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[17], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[18], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[19], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[20], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[21], LWMQTT_UNSUB_NO_SUB_EXISTED); +} + +// UnsubscribeResponse 29663 [PropServerKeepAlive 20618,PropSharedSubscriptionAvailable 245,PropResponseInformation +// "1r\159\138I\144j\SOH#\144\&3\144H\US\175\161\229z\t\200\170\213\153t\201U\DC4",PropWildcardSubscriptionAvailable +// 168,PropSubscriptionIdentifier 5,PropSubscriptionIdentifier 27,PropContentType +// "\203\DLE\NAK\181h\\:\130\230\176?W\GS\141\221\254\237\196\245s\ACK|\129E]\241\186\230\172",PropRequestResponseInformation +// 126,PropAuthenticationMethod +// "D\137B\229'\249\EOT\SUB\193\237\165\233J/\CAN\FSVFQ\209\167\213~",PropAssignedClientIdentifier +// "\232\179\187\216\197\250@\250\133\184n\134\129p\158 5/\193U{\148MLr\"\199ps\227",PropResponseTopic +// "\201\225\SOH\DC3\254\&8\222A\148\197'\135\&4h\181",PropReasonString +// "\205\141\f\173\209\183\171D\209\210\158\167Z\245h\172\239\189\159\215>\210\200",PropSessionExpiryInterval +// 18085,PropRequestProblemInformation 15,PropMessageExpiryInterval 21889,PropAuthenticationData +// "R\241W}",PropServerReference "\220\134\f\179,\193\n*h\201\167\178[<\SOH\SI*F\208\170\149g",PropSessionExpiryInterval +// 31029] [UnsubImplementationSpecificError,UnsubUnspecifiedError] +TEST(UnsubACK5QCTest, Decode9) { + uint8_t pkt[] = {0xb0, 0xe9, 0x1, 0x73, 0xdf, 0xe3, 0x1, 0x13, 0x50, 0x8a, 0x2a, 0xf5, 0x1a, 0x0, 0x1b, 0x31, 0x72, + 0x9f, 0x8a, 0x49, 0x90, 0x6a, 0x1, 0x23, 0x90, 0x33, 0x90, 0x48, 0x1f, 0xaf, 0xa1, 0xe5, 0x7a, 0x9, + 0xc8, 0xaa, 0xd5, 0x99, 0x74, 0xc9, 0x55, 0x14, 0x28, 0xa8, 0xb, 0x5, 0xb, 0x1b, 0x3, 0x0, 0x1d, + 0xcb, 0x10, 0x15, 0xb5, 0x68, 0x5c, 0x3a, 0x82, 0xe6, 0xb0, 0x3f, 0x57, 0x1d, 0x8d, 0xdd, 0xfe, 0xed, + 0xc4, 0xf5, 0x73, 0x6, 0x7c, 0x81, 0x45, 0x5d, 0xf1, 0xba, 0xe6, 0xac, 0x19, 0x7e, 0x15, 0x0, 0x17, + 0x44, 0x89, 0x42, 0xe5, 0x27, 0xf9, 0x4, 0x1a, 0xc1, 0xed, 0xa5, 0xe9, 0x4a, 0x2f, 0x18, 0x1c, 0x56, + 0x46, 0x51, 0xd1, 0xa7, 0xd5, 0x7e, 0x12, 0x0, 0x1e, 0xe8, 0xb3, 0xbb, 0xd8, 0xc5, 0xfa, 0x40, 0xfa, + 0x85, 0xb8, 0x6e, 0x86, 0x81, 0x70, 0x9e, 0x20, 0x35, 0x2f, 0xc1, 0x55, 0x7b, 0x94, 0x4d, 0x4c, 0x72, + 0x22, 0xc7, 0x70, 0x73, 0xe3, 0x8, 0x0, 0xf, 0xc9, 0xe1, 0x1, 0x13, 0xfe, 0x38, 0xde, 0x41, 0x94, + 0xc5, 0x27, 0x87, 0x34, 0x68, 0xb5, 0x1f, 0x0, 0x17, 0xcd, 0x8d, 0xc, 0xad, 0xd1, 0xb7, 0xab, 0x44, + 0xd1, 0xd2, 0x9e, 0xa7, 0x5a, 0xf5, 0x68, 0xac, 0xef, 0xbd, 0x9f, 0xd7, 0x3e, 0xd2, 0xc8, 0x11, 0x0, + 0x0, 0x46, 0xa5, 0x17, 0xf, 0x2, 0x0, 0x0, 0x55, 0x81, 0x16, 0x0, 0x4, 0x52, 0xf1, 0x57, 0x7d, + 0x1c, 0x0, 0x16, 0xdc, 0x86, 0xc, 0xb3, 0x2c, 0xc1, 0xa, 0x2a, 0x68, 0xc9, 0xa7, 0xb2, 0x5b, 0x3c, + 0x1, 0xf, 0x2a, 0x46, 0xd0, 0xaa, 0x95, 0x67, 0x11, 0x0, 0x0, 0x79, 0x35, 0x83, 0x80}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[2]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 2, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 29663); + EXPECT_EQ(count, 2); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_UNSPECIFIED_ERROR); +} + +// UnsubscribeResponse 3853 [PropAuthenticationMethod "\147\249K\209\b\137V\154\v",PropPayloadFormatIndicator +// 182,PropAuthenticationMethod "+Ul\DC3\216",PropUserProperty "\230\193n\DC3p\DEL\"\199 +// \159X\182\169\150\226PA\FS\158\185 \190hs\v!\149\174M" "\193X\167\240\191\176",PropSubscriptionIdentifierAvailable +// 213,PropSubscriptionIdentifier 2,PropAssignedClientIdentifier "{!{\199",PropResponseInformation +// "Vv\244\200\236\&3\129\228*",PropWildcardSubscriptionAvailable 53,PropMessageExpiryInterval +// 18592,PropWillDelayInterval 21248] +// [UnsubPacketIdentifierInUse,UnsubTopicFilterInvalid,UnsubNotAuthorized,UnsubUnspecifiedError,UnsubNotAuthorized,UnsubTopicFilterInvalid,UnsubNotAuthorized,UnsubNoSubscriptionExisted,UnsubTopicFilterInvalid,UnsubPacketIdentifierInUse] +TEST(UnsubACK5QCTest, Decode10) { + uint8_t pkt[] = {0xb0, 0x6e, 0xf, 0xd, 0x61, 0x15, 0x0, 0x9, 0x93, 0xf9, 0x4b, 0xd1, 0x8, 0x89, 0x56, 0x9a, + 0xb, 0x1, 0xb6, 0x15, 0x0, 0x5, 0x2b, 0x55, 0x6c, 0x13, 0xd8, 0x26, 0x0, 0x1d, 0xe6, 0xc1, + 0x6e, 0x13, 0x70, 0x7f, 0x22, 0xc7, 0x20, 0x9f, 0x58, 0xb6, 0xa9, 0x96, 0xe2, 0x50, 0x41, 0x1c, + 0x9e, 0xb9, 0x20, 0xbe, 0x68, 0x73, 0xb, 0x21, 0x95, 0xae, 0x4d, 0x0, 0x6, 0xc1, 0x58, 0xa7, + 0xf0, 0xbf, 0xb0, 0x29, 0xd5, 0xb, 0x2, 0x12, 0x0, 0x4, 0x7b, 0x21, 0x7b, 0xc7, 0x1a, 0x0, + 0x9, 0x56, 0x76, 0xf4, 0xc8, 0xec, 0x33, 0x81, 0xe4, 0x2a, 0x28, 0x35, 0x2, 0x0, 0x0, 0x48, + 0xa0, 0x18, 0x0, 0x0, 0x53, 0x0, 0x91, 0x8f, 0x87, 0x80, 0x87, 0x8f, 0x87, 0x11, 0x8f, 0x91}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[10]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 10, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 3853); + EXPECT_EQ(count, 10); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_PACKET_ID_IN_USE); +} + +// UnsubscribeResponse 32691 [PropAuthenticationMethod +// "\"O\205\186\241\239\168Y\232\251\&5#\177\NAK\139\136\252\159$&d\DC4p\ETX\217~\242",PropServerKeepAlive +// 9377,PropMaximumPacketSize 31850,PropUserProperty ",9\197\208\229\ETX" "(\205ko\CAN\220\173J`\"\178",PropTopicAlias +// 2593,PropMessageExpiryInterval 19546,PropRequestProblemInformation 119,PropMaximumPacketSize 24476,PropMaximumQoS +// 42,PropServerReference "\as\189d^de\138\t\207\247\171\169I\NUL\EM",PropTopicAlias +// 27200,PropRequestResponseInformation 121,PropServerReference "R\232\EM\STX\177o\RSd",PropServerKeepAlive +// 29644,PropResponseInformation "L",PropSubscriptionIdentifier 20,PropMessageExpiryInterval 27352,PropContentType +// "",PropCorrelationData "r8A\131\DLE\185\CAN\173W\US\169N\246\160;r\SYN\134\159\206",PropWillDelayInterval +// 10386,PropServerKeepAlive 14482,PropSubscriptionIdentifier 29,PropServerReference "\ENQ\237\172"] +// [UnsubTopicFilterInvalid,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubSuccess,UnsubNotAuthorized,UnsubNotAuthorized,UnsubUnspecifiedError,UnsubNoSubscriptionExisted,UnsubSuccess,UnsubSuccess,UnsubImplementationSpecificError,UnsubTopicFilterInvalid,UnsubPacketIdentifierInUse,UnsubPacketIdentifierInUse,UnsubUnspecifiedError,UnsubImplementationSpecificError,UnsubNotAuthorized] +TEST(UnsubACK5QCTest, Decode11) { + uint8_t pkt[] = {0xb0, 0xbd, 0x1, 0x7f, 0xb3, 0xa8, 0x1, 0x15, 0x0, 0x1b, 0x22, 0x4f, 0xcd, 0xba, 0xf1, 0xef, + 0xa8, 0x59, 0xe8, 0xfb, 0x35, 0x23, 0xb1, 0x15, 0x8b, 0x88, 0xfc, 0x9f, 0x24, 0x26, 0x64, 0x14, + 0x70, 0x3, 0xd9, 0x7e, 0xf2, 0x13, 0x24, 0xa1, 0x27, 0x0, 0x0, 0x7c, 0x6a, 0x26, 0x0, 0x6, + 0x2c, 0x39, 0xc5, 0xd0, 0xe5, 0x3, 0x0, 0xb, 0x28, 0xcd, 0x6b, 0x6f, 0x18, 0xdc, 0xad, 0x4a, + 0x60, 0x22, 0xb2, 0x23, 0xa, 0x21, 0x2, 0x0, 0x0, 0x4c, 0x5a, 0x17, 0x77, 0x27, 0x0, 0x0, + 0x5f, 0x9c, 0x24, 0x2a, 0x1c, 0x0, 0x10, 0x7, 0x73, 0xbd, 0x64, 0x5e, 0x64, 0x65, 0x8a, 0x9, + 0xcf, 0xf7, 0xab, 0xa9, 0x49, 0x0, 0x19, 0x23, 0x6a, 0x40, 0x19, 0x79, 0x1c, 0x0, 0x8, 0x52, + 0xe8, 0x19, 0x2, 0xb1, 0x6f, 0x1e, 0x64, 0x13, 0x73, 0xcc, 0x1a, 0x0, 0x1, 0x4c, 0xb, 0x14, + 0x2, 0x0, 0x0, 0x6a, 0xd8, 0x3, 0x0, 0x0, 0x9, 0x0, 0x14, 0x72, 0x38, 0x41, 0x83, 0x10, + 0xb9, 0x18, 0xad, 0x57, 0x1f, 0xa9, 0x4e, 0xf6, 0xa0, 0x3b, 0x72, 0x16, 0x86, 0x9f, 0xce, 0x18, + 0x0, 0x0, 0x28, 0x92, 0x13, 0x38, 0x92, 0xb, 0x1d, 0x1c, 0x0, 0x3, 0x5, 0xed, 0xac, 0x8f, + 0x83, 0x11, 0x0, 0x87, 0x87, 0x80, 0x11, 0x0, 0x0, 0x83, 0x8f, 0x91, 0x91, 0x80, 0x83, 0x87}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[17]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 17, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 32691); + EXPECT_EQ(count, 17); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[15], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[16], LWMQTT_UNSUB_NOT_AUTHORIZED); +} + +// UnsubscribeResponse 27806 [PropServerKeepAlive 1965,PropReceiveMaximum 14371,PropRequestResponseInformation +// 200,PropMaximumQoS 1,PropMessageExpiryInterval 6636,PropRequestResponseInformation 193,PropContentType +// "\230f\194\DLEO\DC1\253\231Fn\169a\143\149\239",PropAssignedClientIdentifier "\n\DC4\129\SUB\128",PropRetainAvailable +// 4,PropTopicAlias 17711,PropAuthenticationMethod "\215\141*?\EM\222\173\217\211V)\172\244\166\200;xJ"] +// [UnsubTopicFilterInvalid,UnsubNotAuthorized,UnsubUnspecifiedError,UnsubPacketIdentifierInUse,UnsubSuccess,UnsubNoSubscriptionExisted,UnsubUnspecifiedError,UnsubSuccess,UnsubSuccess,UnsubImplementationSpecificError] +TEST(UnsubACK5QCTest, Decode12) { + uint8_t pkt[] = {0xb0, 0x52, 0x6c, 0x9e, 0x45, 0x13, 0x7, 0xad, 0x21, 0x38, 0x23, 0x19, 0xc8, 0x24, 0x1, 0x2, 0x0, + 0x0, 0x19, 0xec, 0x19, 0xc1, 0x3, 0x0, 0xf, 0xe6, 0x66, 0xc2, 0x10, 0x4f, 0x11, 0xfd, 0xe7, 0x46, + 0x6e, 0xa9, 0x61, 0x8f, 0x95, 0xef, 0x12, 0x0, 0x5, 0xa, 0x14, 0x81, 0x1a, 0x80, 0x25, 0x4, 0x23, + 0x45, 0x2f, 0x15, 0x0, 0x12, 0xd7, 0x8d, 0x2a, 0x3f, 0x19, 0xde, 0xad, 0xd9, 0xd3, 0x56, 0x29, 0xac, + 0xf4, 0xa6, 0xc8, 0x3b, 0x78, 0x4a, 0x8f, 0x87, 0x80, 0x91, 0x0, 0x11, 0x80, 0x0, 0x0, 0x83}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[10]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 10, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 27806); + EXPECT_EQ(count, 10); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); +} + +// UnsubscribeResponse 22916 [PropServerReference +// "\231g\224o\149\232\\\158\181\135\163t\238\188S\228w",PropRequestResponseInformation +// 80,PropSharedSubscriptionAvailable 3,PropMaximumPacketSize 6506,PropRequestResponseInformation +// 234,PropSubscriptionIdentifierAvailable 12,PropMessageExpiryInterval 7767,PropMaximumPacketSize +// 21548,PropReasonString +// "s\USV&B\ETB\142\180\234\171\179A^8\231\168\178\174\222;\147\180b\194",PropMessageExpiryInterval +// 993,PropRequestProblemInformation 176,PropServerReference +// "\186n[\b\248\194s\149\178\165E\231T\193\242\207\v\STX\139\n\t\185:O\211XA\tb",PropSubscriptionIdentifierAvailable +// 82,PropServerKeepAlive 8934,PropSubscriptionIdentifier 1,PropResponseInformation +// "\179\159C-\185R\146\n\ETBU\231\142\209ed,\SUBs\235\139i\DLEAo\199\ETB\186\143",PropRequestProblemInformation +// 120,PropResponseInformation "",PropPayloadFormatIndicator 241,PropResponseTopic "W\154\184d",PropUserProperty +// "<\163\\\233\EM\EOT" "\221\205\187f`\140\182\SO]\137\142",PropWillDelayInterval 807,PropCorrelationData +// "g\219\162\196_\CAN\180\170a\218'\167\131\130\&7\223\130\\",PropSharedSubscriptionAvailable 183,PropUserProperty +// "\254\&5" "\150n\209\SUBlt2\199pd6M\141",PropAuthenticationMethod +// "\235I\ENQ\249\229]\NULF\141\f\200h\130\149\r\238\&2\SOz\192\155$/\133",PropSessionExpiryInterval 495,PropTopicAlias +// 26739,PropTopicAlias 26496,PropRetainAvailable 156] +// [UnsubSuccess,UnsubSuccess,UnsubTopicFilterInvalid,UnsubNoSubscriptionExisted,UnsubImplementationSpecificError,UnsubTopicFilterInvalid,UnsubTopicFilterInvalid,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubImplementationSpecificError,UnsubSuccess,UnsubPacketIdentifierInUse,UnsubImplementationSpecificError,UnsubTopicFilterInvalid,UnsubImplementationSpecificError,UnsubImplementationSpecificError,UnsubPacketIdentifierInUse,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubTopicFilterInvalid] +TEST(UnsubACK5QCTest, Decode13) { + uint8_t pkt[] = { + 0xb0, 0xa7, 0x2, 0x59, 0x84, 0x8f, 0x2, 0x1c, 0x0, 0x11, 0xe7, 0x67, 0xe0, 0x6f, 0x95, 0xe8, 0x5c, 0x9e, 0xb5, + 0x87, 0xa3, 0x74, 0xee, 0xbc, 0x53, 0xe4, 0x77, 0x19, 0x50, 0x2a, 0x3, 0x27, 0x0, 0x0, 0x19, 0x6a, 0x19, 0xea, + 0x29, 0xc, 0x2, 0x0, 0x0, 0x1e, 0x57, 0x27, 0x0, 0x0, 0x54, 0x2c, 0x1f, 0x0, 0x18, 0x73, 0x1f, 0x56, 0x26, + 0x42, 0x17, 0x8e, 0xb4, 0xea, 0xab, 0xb3, 0x41, 0x5e, 0x38, 0xe7, 0xa8, 0xb2, 0xae, 0xde, 0x3b, 0x93, 0xb4, 0x62, + 0xc2, 0x2, 0x0, 0x0, 0x3, 0xe1, 0x17, 0xb0, 0x1c, 0x0, 0x1d, 0xba, 0x6e, 0x5b, 0x8, 0xf8, 0xc2, 0x73, 0x95, + 0xb2, 0xa5, 0x45, 0xe7, 0x54, 0xc1, 0xf2, 0xcf, 0xb, 0x2, 0x8b, 0xa, 0x9, 0xb9, 0x3a, 0x4f, 0xd3, 0x58, 0x41, + 0x9, 0x62, 0x29, 0x52, 0x13, 0x22, 0xe6, 0xb, 0x1, 0x1a, 0x0, 0x1c, 0xb3, 0x9f, 0x43, 0x2d, 0xb9, 0x52, 0x92, + 0xa, 0x17, 0x55, 0xe7, 0x8e, 0xd1, 0x65, 0x64, 0x2c, 0x1a, 0x73, 0xeb, 0x8b, 0x69, 0x10, 0x41, 0x6f, 0xc7, 0x17, + 0xba, 0x8f, 0x17, 0x78, 0x1a, 0x0, 0x0, 0x1, 0xf1, 0x8, 0x0, 0x4, 0x57, 0x9a, 0xb8, 0x64, 0x26, 0x0, 0x6, + 0x3c, 0xa3, 0x5c, 0xe9, 0x19, 0x4, 0x0, 0xb, 0xdd, 0xcd, 0xbb, 0x66, 0x60, 0x8c, 0xb6, 0xe, 0x5d, 0x89, 0x8e, + 0x18, 0x0, 0x0, 0x3, 0x27, 0x9, 0x0, 0x12, 0x67, 0xdb, 0xa2, 0xc4, 0x5f, 0x18, 0xb4, 0xaa, 0x61, 0xda, 0x27, + 0xa7, 0x83, 0x82, 0x37, 0xdf, 0x82, 0x5c, 0x2a, 0xb7, 0x26, 0x0, 0x2, 0xfe, 0x35, 0x0, 0xd, 0x96, 0x6e, 0xd1, + 0x1a, 0x6c, 0x74, 0x32, 0xc7, 0x70, 0x64, 0x36, 0x4d, 0x8d, 0x15, 0x0, 0x18, 0xeb, 0x49, 0x5, 0xf9, 0xe5, 0x5d, + 0x0, 0x46, 0x8d, 0xc, 0xc8, 0x68, 0x82, 0x95, 0xd, 0xee, 0x32, 0xe, 0x7a, 0xc0, 0x9b, 0x24, 0x2f, 0x85, 0x11, + 0x0, 0x0, 0x1, 0xef, 0x23, 0x68, 0x73, 0x23, 0x67, 0x80, 0x25, 0x9c, 0x0, 0x0, 0x8f, 0x11, 0x83, 0x8f, 0x8f, + 0x83, 0x11, 0x83, 0x0, 0x91, 0x83, 0x8f, 0x83, 0x83, 0x91, 0x83, 0x11, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[20]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 20, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 22916); + EXPECT_EQ(count, 20); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[15], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[16], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[17], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[18], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[19], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); +} + +// UnsubscribeResponse 23906 [PropMaximumPacketSize 32722,PropTopicAliasMaximum 9751,PropPayloadFormatIndicator +// 52,PropServerReference "}N+\235\190\250\&4\n\220Pa\224\172BA\187",PropMaximumQoS 123,PropSubscriptionIdentifier +// 5,PropReasonString +// "\234\135B\189\189M\215B\162\217ry\183\200\&9\240\181}\f\228(\185\148\v\226\US",PropRetainAvailable +// 214,PropAuthenticationData "Fl\229!\NAK\SOH\nP5\173\219\217Af\150O@=Db/\NAK\240\142\SO",PropRequestProblemInformation +// 82,PropWildcardSubscriptionAvailable 164,PropRetainAvailable 214,PropRequestResponseInformation 75,PropMaximumQoS +// 153,PropWildcardSubscriptionAvailable 0,PropServerKeepAlive 14267,PropUserProperty "" +// "\165\133\CANv\ETB\237X\SI\232~`\128@#\226\200\235\141\234",PropMessageExpiryInterval 13701,PropReceiveMaximum +// 2557,PropContentType "\248\248d(\156\146\157>oG",PropContentType +// "\CAN\145\249\223\151\208\212\NUL\180\177\222*U\187\234\174?\ACKy\249\134\199\CAN\253\&5\SIP\203\238",PropRequestResponseInformation +// 115,PropReasonString "qk\226\192cE",PropRequestResponseInformation 7,PropSubscriptionIdentifier 17,PropReceiveMaximum +// 11114,PropRetainAvailable 203,PropUserProperty "\191!\CAN\155!\206w\137\t" +// ">\166Y1h\207\142\136I/\229\173\"\228\&3$\246Lt\174\189\218\227\&1sWV",PropSubscriptionIdentifier 20] +// [UnsubUnspecifiedError,UnsubSuccess,UnsubSuccess,UnsubUnspecifiedError,UnsubNoSubscriptionExisted,UnsubPacketIdentifierInUse,UnsubSuccess,UnsubTopicFilterInvalid,UnsubTopicFilterInvalid,UnsubUnspecifiedError,UnsubTopicFilterInvalid,UnsubPacketIdentifierInUse,UnsubNotAuthorized,UnsubSuccess,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubNoSubscriptionExisted,UnsubNoSubscriptionExisted,UnsubSuccess,UnsubUnspecifiedError,UnsubSuccess] +TEST(UnsubACK5QCTest, Decode14) { + uint8_t pkt[] = { + 0xb0, 0x90, 0x2, 0x5d, 0x62, 0xf7, 0x1, 0x27, 0x0, 0x0, 0x7f, 0xd2, 0x22, 0x26, 0x17, 0x1, 0x34, 0x1c, 0x0, + 0x10, 0x7d, 0x4e, 0x2b, 0xeb, 0xbe, 0xfa, 0x34, 0xa, 0xdc, 0x50, 0x61, 0xe0, 0xac, 0x42, 0x41, 0xbb, 0x24, 0x7b, + 0xb, 0x5, 0x1f, 0x0, 0x1a, 0xea, 0x87, 0x42, 0xbd, 0xbd, 0x4d, 0xd7, 0x42, 0xa2, 0xd9, 0x72, 0x79, 0xb7, 0xc8, + 0x39, 0xf0, 0xb5, 0x7d, 0xc, 0xe4, 0x28, 0xb9, 0x94, 0xb, 0xe2, 0x1f, 0x25, 0xd6, 0x16, 0x0, 0x19, 0x46, 0x6c, + 0xe5, 0x21, 0x15, 0x1, 0xa, 0x50, 0x35, 0xad, 0xdb, 0xd9, 0x41, 0x66, 0x96, 0x4f, 0x40, 0x3d, 0x44, 0x62, 0x2f, + 0x15, 0xf0, 0x8e, 0xe, 0x17, 0x52, 0x28, 0xa4, 0x25, 0xd6, 0x19, 0x4b, 0x24, 0x99, 0x28, 0x0, 0x13, 0x37, 0xbb, + 0x26, 0x0, 0x0, 0x0, 0x13, 0xa5, 0x85, 0x18, 0x76, 0x17, 0xed, 0x58, 0xf, 0xe8, 0x7e, 0x60, 0x80, 0x40, 0x23, + 0xe2, 0xc8, 0xeb, 0x8d, 0xea, 0x2, 0x0, 0x0, 0x35, 0x85, 0x21, 0x9, 0xfd, 0x3, 0x0, 0xa, 0xf8, 0xf8, 0x64, + 0x28, 0x9c, 0x92, 0x9d, 0x3e, 0x6f, 0x47, 0x3, 0x0, 0x1d, 0x18, 0x91, 0xf9, 0xdf, 0x97, 0xd0, 0xd4, 0x0, 0xb4, + 0xb1, 0xde, 0x2a, 0x55, 0xbb, 0xea, 0xae, 0x3f, 0x6, 0x79, 0xf9, 0x86, 0xc7, 0x18, 0xfd, 0x35, 0xf, 0x50, 0xcb, + 0xee, 0x19, 0x73, 0x1f, 0x0, 0x6, 0x71, 0x6b, 0xe2, 0xc0, 0x63, 0x45, 0x19, 0x7, 0xb, 0x11, 0x21, 0x2b, 0x6a, + 0x25, 0xcb, 0x26, 0x0, 0x9, 0xbf, 0x21, 0x18, 0x9b, 0x21, 0xce, 0x77, 0x89, 0x9, 0x0, 0x1b, 0x3e, 0xa6, 0x59, + 0x31, 0x68, 0xcf, 0x8e, 0x88, 0x49, 0x2f, 0xe5, 0xad, 0x22, 0xe4, 0x33, 0x24, 0xf6, 0x4c, 0x74, 0xae, 0xbd, 0xda, + 0xe3, 0x31, 0x73, 0x57, 0x56, 0xb, 0x14, 0x80, 0x0, 0x0, 0x80, 0x11, 0x91, 0x0, 0x8f, 0x8f, 0x80, 0x8f, 0x91, + 0x87, 0x0, 0x83, 0x11, 0x11, 0x11, 0x0, 0x80, 0x0}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[21]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 21, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 23906); + EXPECT_EQ(count, 21); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[15], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[16], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[17], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[18], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[19], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[20], LWMQTT_UNSUB_SUCCESS); +} + +// UnsubscribeResponse 6581 [PropSharedSubscriptionAvailable 165,PropResponseInformation +// "\173\180\173V\DEL\136&$!\182mu.\218\254h\188\241\152^",PropReasonString +// "\214\176\172\214\202\179\212R\151K\199\191\204\DLE\176'\236\132+~\STX\245\147.7?2",PropAuthenticationData +// "\206Y\SO\&H"] [UnsubSuccess,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted] +TEST(UnsubACK5QCTest, Decode15) { + uint8_t pkt[] = {0xb0, 0x44, 0x19, 0xb5, 0x3e, 0x2a, 0xa5, 0x1a, 0x0, 0x14, 0xad, 0xb4, 0xad, 0x56, + 0x7f, 0x88, 0x26, 0x24, 0x21, 0xb6, 0x6d, 0x75, 0x2e, 0xda, 0xfe, 0x68, 0xbc, 0xf1, + 0x98, 0x5e, 0x1f, 0x0, 0x1b, 0xd6, 0xb0, 0xac, 0xd6, 0xca, 0xb3, 0xd4, 0x52, 0x97, + 0x4b, 0xc7, 0xbf, 0xcc, 0x10, 0xb0, 0x27, 0xec, 0x84, 0x2b, 0x7e, 0x2, 0xf5, 0x93, + 0x2e, 0x37, 0x3f, 0x32, 0x16, 0x0, 0x4, 0xce, 0x59, 0xe, 0x48, 0x0, 0x83, 0x11}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[3]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 3, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 6581); + EXPECT_EQ(count, 3); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_NO_SUB_EXISTED); +} + +// UnsubscribeResponse 8391 [PropAuthenticationMethod "",PropRetainAvailable 48,PropMessageExpiryInterval +// 5986,PropMaximumQoS 104,PropRetainAvailable 162,PropSubscriptionIdentifierAvailable 112,PropMessageExpiryInterval +// 3803,PropSubscriptionIdentifierAvailable 133,PropCorrelationData "\181\&6",PropResponseInformation +// "",PropMaximumPacketSize 29114,PropContentType "\222N\132\175\177\171\DC2%\170\234",PropSharedSubscriptionAvailable +// 42,PropServerKeepAlive 8259,PropRequestResponseInformation 230,PropRequestResponseInformation +// 229,PropRequestResponseInformation 195,PropServerReference +// "\199#pw!\245\153\b\150\193\RS\153\242O\240r\am\223",PropMessageExpiryInterval 26378,PropCorrelationData +// "\214\FSh\a\173\203H\194t\155\233\206\"\US\174\246j\228dc\153\248\221\158\SUB\219",PropSessionExpiryInterval +// 1825,PropReasonString "\ACK2\226\195\225$qA\141\t\136\183k\178\132\166\192\DLE\208",PropServerReference "\181i\166"] +// [] +TEST(UnsubACK5QCTest, Decode16) { + uint8_t pkt[] = {0xb0, 0x99, 0x1, 0x20, 0xc7, 0x95, 0x1, 0x15, 0x0, 0x0, 0x25, 0x30, 0x2, 0x0, 0x0, 0x17, + 0x62, 0x24, 0x68, 0x25, 0xa2, 0x29, 0x70, 0x2, 0x0, 0x0, 0xe, 0xdb, 0x29, 0x85, 0x9, 0x0, + 0x2, 0xb5, 0x36, 0x1a, 0x0, 0x0, 0x27, 0x0, 0x0, 0x71, 0xba, 0x3, 0x0, 0xa, 0xde, 0x4e, + 0x84, 0xaf, 0xb1, 0xab, 0x12, 0x25, 0xaa, 0xea, 0x2a, 0x2a, 0x13, 0x20, 0x43, 0x19, 0xe6, 0x19, + 0xe5, 0x19, 0xc3, 0x1c, 0x0, 0x13, 0xc7, 0x23, 0x70, 0x77, 0x21, 0xf5, 0x99, 0x8, 0x96, 0xc1, + 0x1e, 0x99, 0xf2, 0x4f, 0xf0, 0x72, 0x7, 0x6d, 0xdf, 0x2, 0x0, 0x0, 0x67, 0xa, 0x9, 0x0, + 0x1a, 0xd6, 0x1c, 0x68, 0x7, 0xad, 0xcb, 0x48, 0xc2, 0x74, 0x9b, 0xe9, 0xce, 0x22, 0x1f, 0xae, + 0xf6, 0x6a, 0xe4, 0x64, 0x63, 0x99, 0xf8, 0xdd, 0x9e, 0x1a, 0xdb, 0x11, 0x0, 0x0, 0x7, 0x21, + 0x1f, 0x0, 0x13, 0x6, 0x32, 0xe2, 0xc3, 0xe1, 0x24, 0x71, 0x41, 0x8d, 0x9, 0x88, 0xb7, 0x6b, + 0xb2, 0x84, 0xa6, 0xc0, 0x10, 0xd0, 0x1c, 0x0, 0x3, 0xb5, 0x69, 0xa6}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[0]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 0, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 8391); + EXPECT_EQ(count, 0); +} + +// UnsubscribeResponse 23519 [PropResponseTopic "\208Km\174\ENQ^\200S",PropContentType +// "\222\161\251\214\199\129g+S8%Ww\130\237\163C\193\219\a\253_\238",PropMessageExpiryInterval 11241,PropServerReference +// "",PropCorrelationData +// "\178\139m\SYN\240\171\185\174\t\195N\ESC\207\131\SOHA\226\144\209J\185\EM\251\US",PropSubscriptionIdentifier +// 23,PropWildcardSubscriptionAvailable 63] +// [UnsubNotAuthorized,UnsubPacketIdentifierInUse,UnsubTopicFilterInvalid,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubUnspecifiedError,UnsubNoSubscriptionExisted,UnsubTopicFilterInvalid,UnsubImplementationSpecificError,UnsubUnspecifiedError,UnsubPacketIdentifierInUse,UnsubTopicFilterInvalid,UnsubImplementationSpecificError,UnsubImplementationSpecificError,UnsubUnspecifiedError] +TEST(UnsubACK5QCTest, Decode17) { + uint8_t pkt[] = {0xb0, 0x5e, 0x5b, 0xdf, 0x4c, 0x8, 0x0, 0x8, 0xd0, 0x4b, 0x6d, 0xae, 0x5, 0x5e, 0xc8, 0x53, + 0x3, 0x0, 0x17, 0xde, 0xa1, 0xfb, 0xd6, 0xc7, 0x81, 0x67, 0x2b, 0x53, 0x38, 0x25, 0x57, 0x77, + 0x82, 0xed, 0xa3, 0x43, 0xc1, 0xdb, 0x7, 0xfd, 0x5f, 0xee, 0x2, 0x0, 0x0, 0x2b, 0xe9, 0x1c, + 0x0, 0x0, 0x9, 0x0, 0x18, 0xb2, 0x8b, 0x6d, 0x16, 0xf0, 0xab, 0xb9, 0xae, 0x9, 0xc3, 0x4e, + 0x1b, 0xcf, 0x83, 0x1, 0x41, 0xe2, 0x90, 0xd1, 0x4a, 0xb9, 0x19, 0xfb, 0x1f, 0xb, 0x17, 0x28, + 0x3f, 0x87, 0x91, 0x8f, 0x83, 0x11, 0x80, 0x11, 0x8f, 0x83, 0x80, 0x91, 0x8f, 0x83, 0x83, 0x80}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[15]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 15, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 23519); + EXPECT_EQ(count, 15); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_UNSPECIFIED_ERROR); +} + +// UnsubscribeResponse 4238 [PropServerKeepAlive 13324,PropReceiveMaximum 25934,PropReceiveMaximum +// 18050,PropSubscriptionIdentifierAvailable 130,PropContentType "\141\159\171w\230\245\208",PropMessageExpiryInterval +// 31646,PropRequestProblemInformation 175,PropWillDelayInterval 6634,PropPayloadFormatIndicator +// 236,PropWillDelayInterval 11738,PropCorrelationData "\248",PropReceiveMaximum 7903,PropSubscriptionIdentifier +// 3,PropResponseInformation +// "\132\189\193\&7\200t\223\139u\165\161\238Y\252\242\222d\SUB\EOT\129\186\142\a\164",PropTopicAlias +// 22856,PropTopicAlias 6361,PropWillDelayInterval 4888,PropTopicAliasMaximum 10791,PropMessageExpiryInterval +// 25990,PropRequestResponseInformation 100,PropPayloadFormatIndicator 94,PropMaximumPacketSize +// 9290,PropSessionExpiryInterval 1190,PropMaximumQoS 96,PropServerKeepAlive 1158,PropTopicAlias +// 10096,PropSubscriptionIdentifierAvailable 189] +// [UnsubNotAuthorized,UnsubTopicFilterInvalid,UnsubTopicFilterInvalid,UnsubNoSubscriptionExisted,UnsubUnspecifiedError,UnsubUnspecifiedError,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubUnspecifiedError,UnsubUnspecifiedError,UnsubNoSubscriptionExisted,UnsubNoSubscriptionExisted,UnsubTopicFilterInvalid,UnsubNotAuthorized,UnsubUnspecifiedError,UnsubUnspecifiedError] +TEST(UnsubACK5QCTest, Decode18) { + uint8_t pkt[] = {0xb0, 0x8a, 0x1, 0x10, 0x8e, 0x77, 0x13, 0x34, 0xc, 0x21, 0x65, 0x4e, 0x21, 0x46, 0x82, 0x29, + 0x82, 0x3, 0x0, 0x7, 0x8d, 0x9f, 0xab, 0x77, 0xe6, 0xf5, 0xd0, 0x2, 0x0, 0x0, 0x7b, 0x9e, + 0x17, 0xaf, 0x18, 0x0, 0x0, 0x19, 0xea, 0x1, 0xec, 0x18, 0x0, 0x0, 0x2d, 0xda, 0x9, 0x0, + 0x1, 0xf8, 0x21, 0x1e, 0xdf, 0xb, 0x3, 0x1a, 0x0, 0x18, 0x84, 0xbd, 0xc1, 0x37, 0xc8, 0x74, + 0xdf, 0x8b, 0x75, 0xa5, 0xa1, 0xee, 0x59, 0xfc, 0xf2, 0xde, 0x64, 0x1a, 0x4, 0x81, 0xba, 0x8e, + 0x7, 0xa4, 0x23, 0x59, 0x48, 0x23, 0x18, 0xd9, 0x18, 0x0, 0x0, 0x13, 0x18, 0x22, 0x2a, 0x27, + 0x2, 0x0, 0x0, 0x65, 0x86, 0x19, 0x64, 0x1, 0x5e, 0x27, 0x0, 0x0, 0x24, 0x4a, 0x11, 0x0, + 0x0, 0x4, 0xa6, 0x24, 0x60, 0x13, 0x4, 0x86, 0x23, 0x27, 0x70, 0x29, 0xbd, 0x87, 0x8f, 0x8f, + 0x11, 0x80, 0x80, 0x83, 0x11, 0x80, 0x80, 0x11, 0x11, 0x8f, 0x87, 0x80, 0x80}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[16]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 16, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 4238); + EXPECT_EQ(count, 16); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[15], LWMQTT_UNSUB_UNSPECIFIED_ERROR); +} + +// UnsubscribeResponse 4066 [PropPayloadFormatIndicator 138,PropRequestProblemInformation 227,PropReasonString +// "9\157\249b\ETB~\207\168\239\172\t$M\SUBg\227\234\SO\161\192N3\163",PropAssignedClientIdentifier +// "\EOT",PropTopicAliasMaximum 18698,PropAuthenticationData +// "z\131\DC1*p\163=d\160\192\155m\241f\183\239\214\223l\ETB\253\168W\136\211\r",PropMaximumQoS 168,PropUserProperty +// "\CAN\185\253\166\213\171\194\202\166\235\254\209\182\238B\212\&2UAA\DC3\250" +// "\217\134[\181\240\132\162\STX\214\229\223L&=\253Y\227Z\rx\253x\b\139\220\158\192\204\152\131",PropMessageExpiryInterval +// 23029,PropCorrelationData "L\171\166\157y\ETXL\135",PropTopicAliasMaximum 15827,PropServerReference +// "`\DC1\199\ETBA\161",PropTopicAlias 21218,PropServerReference "WQPdg\DLE\GS\ACK!B\ACK\143#k4\235\218="] +// [UnsubNoSubscriptionExisted] +TEST(UnsubACK5QCTest, Decode19) { + uint8_t pkt[] = {0xb0, 0xb6, 0x1, 0xf, 0xe2, 0xb1, 0x1, 0x1, 0x8a, 0x17, 0xe3, 0x1f, 0x0, 0x17, 0x39, 0x9d, 0xf9, + 0x62, 0x17, 0x7e, 0xcf, 0xa8, 0xef, 0xac, 0x9, 0x24, 0x4d, 0x1a, 0x67, 0xe3, 0xea, 0xe, 0xa1, 0xc0, + 0x4e, 0x33, 0xa3, 0x12, 0x0, 0x1, 0x4, 0x22, 0x49, 0xa, 0x16, 0x0, 0x1a, 0x7a, 0x83, 0x11, 0x2a, + 0x70, 0xa3, 0x3d, 0x64, 0xa0, 0xc0, 0x9b, 0x6d, 0xf1, 0x66, 0xb7, 0xef, 0xd6, 0xdf, 0x6c, 0x17, 0xfd, + 0xa8, 0x57, 0x88, 0xd3, 0xd, 0x24, 0xa8, 0x26, 0x0, 0x16, 0x18, 0xb9, 0xfd, 0xa6, 0xd5, 0xab, 0xc2, + 0xca, 0xa6, 0xeb, 0xfe, 0xd1, 0xb6, 0xee, 0x42, 0xd4, 0x32, 0x55, 0x41, 0x41, 0x13, 0xfa, 0x0, 0x1e, + 0xd9, 0x86, 0x5b, 0xb5, 0xf0, 0x84, 0xa2, 0x2, 0xd6, 0xe5, 0xdf, 0x4c, 0x26, 0x3d, 0xfd, 0x59, 0xe3, + 0x5a, 0xd, 0x78, 0xfd, 0x78, 0x8, 0x8b, 0xdc, 0x9e, 0xc0, 0xcc, 0x98, 0x83, 0x2, 0x0, 0x0, 0x59, + 0xf5, 0x9, 0x0, 0x8, 0x4c, 0xab, 0xa6, 0x9d, 0x79, 0x3, 0x4c, 0x87, 0x22, 0x3d, 0xd3, 0x1c, 0x0, + 0x6, 0x60, 0x11, 0xc7, 0x17, 0x41, 0xa1, 0x23, 0x52, 0xe2, 0x1c, 0x0, 0x12, 0x57, 0x51, 0x50, 0x64, + 0x67, 0x10, 0x1d, 0x6, 0x21, 0x42, 0x6, 0x8f, 0x23, 0x6b, 0x34, 0xeb, 0xda, 0x3d, 0x11}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[1]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 1, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 4066); + EXPECT_EQ(count, 1); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_NO_SUB_EXISTED); +} + +// UnsubscribeResponse 8672 [PropMaximumPacketSize 4206,PropServerReference +// "Q;+\225njF\167\229\177S\253\ESC\"\234\STX\154\DEL5\243\STX\"*\220\237\157'&\FS",PropResponseInformation +// "C\220\229EM\207\180\138\196VxL\137by\148j\244",PropTopicAlias 9824,PropUserProperty +// "\136$\136\182\136\FS2\161\186wA\SOH\US" "\207\SI\227\135\222m\183L\219\139\131\200B\217\&1"] +// [UnsubTopicFilterInvalid,UnsubTopicFilterInvalid,UnsubNotAuthorized,UnsubNotAuthorized,UnsubNoSubscriptionExisted,UnsubUnspecifiedError,UnsubUnspecifiedError,UnsubUnspecifiedError,UnsubSuccess] +TEST(UnsubACK5QCTest, Decode20) { + uint8_t pkt[] = {0xb0, 0x6a, 0x21, 0xe0, 0x5e, 0x27, 0x0, 0x0, 0x10, 0x6e, 0x1c, 0x0, 0x1d, 0x51, 0x3b, 0x2b, + 0xe1, 0x6e, 0x6a, 0x46, 0xa7, 0xe5, 0xb1, 0x53, 0xfd, 0x1b, 0x22, 0xea, 0x2, 0x9a, 0x7f, 0x35, + 0xf3, 0x2, 0x22, 0x2a, 0xdc, 0xed, 0x9d, 0x27, 0x26, 0x1c, 0x1a, 0x0, 0x12, 0x43, 0xdc, 0xe5, + 0x45, 0x4d, 0xcf, 0xb4, 0x8a, 0xc4, 0x56, 0x78, 0x4c, 0x89, 0x62, 0x79, 0x94, 0x6a, 0xf4, 0x23, + 0x26, 0x60, 0x26, 0x0, 0xd, 0x88, 0x24, 0x88, 0xb6, 0x88, 0x1c, 0x32, 0xa1, 0xba, 0x77, 0x41, + 0x1, 0x1f, 0x0, 0xf, 0xcf, 0xf, 0xe3, 0x87, 0xde, 0x6d, 0xb7, 0x4c, 0xdb, 0x8b, 0x83, 0xc8, + 0x42, 0xd9, 0x31, 0x8f, 0x8f, 0x87, 0x87, 0x11, 0x80, 0x80, 0x80, 0x0}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[9]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 9, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 8672); + EXPECT_EQ(count, 9); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_SUCCESS); +} + +// UnsubscribeResponse 26380 [PropAuthenticationData +// "\175\149\184j\v;`X\191\209\248\191?\ETX\DC3<",PropAuthenticationMethod +// "\130\207\206><\"\193\SO\231T\199&\232\136",PropSharedSubscriptionAvailable 115,PropSharedSubscriptionAvailable +// 12,PropMessageExpiryInterval 25878,PropPayloadFormatIndicator 133,PropSubscriptionIdentifierAvailable +// 184,PropMaximumQoS 14,PropReasonString +// "\211K\202\CAN\205\168\169F\217Xm4\156\NAK,\172\134\EOT,\244\140\a\DC3-6\162<\fC\170",PropRequestProblemInformation +// 93,PropReasonString "\DLE\135k\162\235\128\227\128Z-\132\136 \143\174\DEL\218",PropWillDelayInterval +// 9169,PropReasonString "\ESCk`\194}\133",PropAssignedClientIdentifier +// "\r\243\ENQ\175\253%b\156?\176\245P\198\180\240\159A\216",PropContentType +// ":\227\182R\152\ACK\150\DC1\ETBV\238\158\221\226&\150\ACK\170\DEL+\US\239e\158\212>",PropServerKeepAlive +// 19087,PropServerKeepAlive 1277,PropRetainAvailable 250,PropAuthenticationData "",PropSharedSubscriptionAvailable +// 183,PropSharedSubscriptionAvailable 246,PropMessageExpiryInterval 14131,PropMessageExpiryInterval +// 22025,PropMaximumPacketSize 19055] +// [UnsubSuccess,UnsubPacketIdentifierInUse,UnsubPacketIdentifierInUse,UnsubPacketIdentifierInUse,UnsubImplementationSpecificError,UnsubNotAuthorized,UnsubSuccess,UnsubPacketIdentifierInUse,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubNoSubscriptionExisted,UnsubSuccess,UnsubNoSubscriptionExisted,UnsubPacketIdentifierInUse,UnsubTopicFilterInvalid] +TEST(UnsubACK5QCTest, Decode21) { + uint8_t pkt[] = { + 0xb0, 0xdb, 0x1, 0x67, 0xc, 0xc8, 0x1, 0x16, 0x0, 0x10, 0xaf, 0x95, 0xb8, 0x6a, 0xb, 0x3b, 0x60, 0x58, 0xbf, + 0xd1, 0xf8, 0xbf, 0x3f, 0x3, 0x13, 0x3c, 0x15, 0x0, 0xe, 0x82, 0xcf, 0xce, 0x3e, 0x3c, 0x22, 0xc1, 0xe, 0xe7, + 0x54, 0xc7, 0x26, 0xe8, 0x88, 0x2a, 0x73, 0x2a, 0xc, 0x2, 0x0, 0x0, 0x65, 0x16, 0x1, 0x85, 0x29, 0xb8, 0x24, + 0xe, 0x1f, 0x0, 0x1e, 0xd3, 0x4b, 0xca, 0x18, 0xcd, 0xa8, 0xa9, 0x46, 0xd9, 0x58, 0x6d, 0x34, 0x9c, 0x15, 0x2c, + 0xac, 0x86, 0x4, 0x2c, 0xf4, 0x8c, 0x7, 0x13, 0x2d, 0x36, 0xa2, 0x3c, 0xc, 0x43, 0xaa, 0x17, 0x5d, 0x1f, 0x0, + 0x11, 0x10, 0x87, 0x6b, 0xa2, 0xeb, 0x80, 0xe3, 0x80, 0x5a, 0x2d, 0x84, 0x88, 0x20, 0x8f, 0xae, 0x7f, 0xda, 0x18, + 0x0, 0x0, 0x23, 0xd1, 0x1f, 0x0, 0x6, 0x1b, 0x6b, 0x60, 0xc2, 0x7d, 0x85, 0x12, 0x0, 0x12, 0xd, 0xf3, 0x5, + 0xaf, 0xfd, 0x25, 0x62, 0x9c, 0x3f, 0xb0, 0xf5, 0x50, 0xc6, 0xb4, 0xf0, 0x9f, 0x41, 0xd8, 0x3, 0x0, 0x1a, 0x3a, + 0xe3, 0xb6, 0x52, 0x98, 0x6, 0x96, 0x11, 0x17, 0x56, 0xee, 0x9e, 0xdd, 0xe2, 0x26, 0x96, 0x6, 0xaa, 0x7f, 0x2b, + 0x1f, 0xef, 0x65, 0x9e, 0xd4, 0x3e, 0x13, 0x4a, 0x8f, 0x13, 0x4, 0xfd, 0x25, 0xfa, 0x16, 0x0, 0x0, 0x2a, 0xb7, + 0x2a, 0xf6, 0x2, 0x0, 0x0, 0x37, 0x33, 0x2, 0x0, 0x0, 0x56, 0x9, 0x27, 0x0, 0x0, 0x4a, 0x6f, 0x0, 0x91, + 0x91, 0x91, 0x83, 0x87, 0x0, 0x91, 0x83, 0x11, 0x11, 0x0, 0x11, 0x91, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[15]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 15, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 26380); + EXPECT_EQ(count, 15); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); +} + +// UnsubscribeResponse 8446 [PropMessageExpiryInterval 32522,PropAuthenticationMethod "s",PropUserProperty +// "\245\156\167`\196U\134\160\246\204k\NUL\EOT={V\141\211\169\ENQ%" "V\184\146Ug",PropServerReference +// "#^xQ\179",PropCorrelationData "\191\fkMH\184\214%\217",PropResponseInformation +// "Q+h\134>Q\231B\185\242$F\180m~\205\183[A\178\216",PropMessageExpiryInterval 15326,PropServerReference +// "X?\CAN\\I\135!\210Q0\EM\134\246P"] +// [UnsubSuccess,UnsubImplementationSpecificError,UnsubUnspecifiedError,UnsubNoSubscriptionExisted] +TEST(UnsubACK5QCTest, Decode22) { + uint8_t pkt[] = {0xb0, 0x71, 0x20, 0xfe, 0x6a, 0x2, 0x0, 0x0, 0x7f, 0xa, 0x15, 0x0, 0x1, 0x73, 0x26, 0x0, 0x15, + 0xf5, 0x9c, 0xa7, 0x60, 0xc4, 0x55, 0x86, 0xa0, 0xf6, 0xcc, 0x6b, 0x0, 0x4, 0x3d, 0x7b, 0x56, 0x8d, + 0xd3, 0xa9, 0x5, 0x25, 0x0, 0x5, 0x56, 0xb8, 0x92, 0x55, 0x67, 0x1c, 0x0, 0x5, 0x23, 0x5e, 0x78, + 0x51, 0xb3, 0x9, 0x0, 0x9, 0xbf, 0xc, 0x6b, 0x4d, 0x48, 0xb8, 0xd6, 0x25, 0xd9, 0x1a, 0x0, 0x15, + 0x51, 0x2b, 0x68, 0x86, 0x3e, 0x51, 0xe7, 0x42, 0xb9, 0xf2, 0x24, 0x46, 0xb4, 0x6d, 0x7e, 0xcd, 0xb7, + 0x5b, 0x41, 0xb2, 0xd8, 0x2, 0x0, 0x0, 0x3b, 0xde, 0x1c, 0x0, 0xe, 0x58, 0x3f, 0x18, 0x5c, 0x49, + 0x87, 0x21, 0xd2, 0x51, 0x30, 0x19, 0x86, 0xf6, 0x50, 0x0, 0x83, 0x80, 0x11}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[4]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 4, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 8446); + EXPECT_EQ(count, 4); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_NO_SUB_EXISTED); +} + +// UnsubscribeResponse 19980 [PropServerKeepAlive 7789] +// [UnsubNotAuthorized,UnsubTopicFilterInvalid,UnsubSuccess,UnsubUnspecifiedError,UnsubNoSubscriptionExisted,UnsubNoSubscriptionExisted,UnsubUnspecifiedError,UnsubPacketIdentifierInUse,UnsubSuccess,UnsubTopicFilterInvalid,UnsubPacketIdentifierInUse,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubNotAuthorized,UnsubSuccess,UnsubPacketIdentifierInUse] +TEST(UnsubACK5QCTest, Decode23) { + uint8_t pkt[] = {0xb0, 0x16, 0x4e, 0xc, 0x3, 0x13, 0x1e, 0x6d, 0x87, 0x8f, 0x0, 0x80, + 0x11, 0x11, 0x80, 0x91, 0x0, 0x8f, 0x91, 0x83, 0x11, 0x87, 0x0, 0x91}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[16]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 16, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 19980); + EXPECT_EQ(count, 16); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[15], LWMQTT_UNSUB_PACKET_ID_IN_USE); +} + +// UnsubscribeResponse 4987 [PropResponseTopic "\ETX>\159\&3z\223\DC1\244",PropTopicAliasMaximum 22200,PropMaximumQoS +// 94,PropServerKeepAlive 31146,PropSharedSubscriptionAvailable 134,PropSubscriptionIdentifierAvailable +// 68,PropCorrelationData "vn\151?d\169\174\205\ETX\n\237\190MkT\251",PropMaximumPacketSize +// 18578,PropSubscriptionIdentifier 27,PropRetainAvailable 254,PropMaximumQoS 196,PropServerReference +// "\168/\224%m\206\224/\128\&8R\139\175\197o^\146\249\SIV\137M\238",PropRequestProblemInformation +// 200,PropRequestResponseInformation 92,PropTopicAliasMaximum 29502,PropTopicAlias 68,PropTopicAlias +// 2438,PropWillDelayInterval 5635,PropWildcardSubscriptionAvailable 62,PropWillDelayInterval 20948] +// [UnsubNotAuthorized,UnsubPacketIdentifierInUse,UnsubUnspecifiedError,UnsubSuccess,UnsubNoSubscriptionExisted,UnsubTopicFilterInvalid,UnsubUnspecifiedError,UnsubTopicFilterInvalid,UnsubImplementationSpecificError,UnsubTopicFilterInvalid,UnsubSuccess,UnsubTopicFilterInvalid,UnsubUnspecifiedError,UnsubImplementationSpecificError,UnsubNoSubscriptionExisted,UnsubImplementationSpecificError,UnsubUnspecifiedError,UnsubTopicFilterInvalid,UnsubPacketIdentifierInUse] +TEST(UnsubACK5QCTest, Decode24) { + uint8_t pkt[] = {0xb0, 0x7e, 0x13, 0x7b, 0x68, 0x8, 0x0, 0x8, 0x3, 0x3e, 0x9f, 0x33, 0x7a, 0xdf, 0x11, 0xf4, + 0x22, 0x56, 0xb8, 0x24, 0x5e, 0x13, 0x79, 0xaa, 0x2a, 0x86, 0x29, 0x44, 0x9, 0x0, 0x10, 0x76, + 0x6e, 0x97, 0x3f, 0x64, 0xa9, 0xae, 0xcd, 0x3, 0xa, 0xed, 0xbe, 0x4d, 0x6b, 0x54, 0xfb, 0x27, + 0x0, 0x0, 0x48, 0x92, 0xb, 0x1b, 0x25, 0xfe, 0x24, 0xc4, 0x1c, 0x0, 0x17, 0xa8, 0x2f, 0xe0, + 0x25, 0x6d, 0xce, 0xe0, 0x2f, 0x80, 0x38, 0x52, 0x8b, 0xaf, 0xc5, 0x6f, 0x5e, 0x92, 0xf9, 0xf, + 0x56, 0x89, 0x4d, 0xee, 0x17, 0xc8, 0x19, 0x5c, 0x22, 0x73, 0x3e, 0x23, 0x0, 0x44, 0x23, 0x9, + 0x86, 0x18, 0x0, 0x0, 0x16, 0x3, 0x28, 0x3e, 0x18, 0x0, 0x0, 0x51, 0xd4, 0x87, 0x91, 0x80, + 0x0, 0x11, 0x8f, 0x80, 0x8f, 0x83, 0x8f, 0x0, 0x8f, 0x80, 0x83, 0x11, 0x83, 0x80, 0x8f, 0x91}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[19]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 19, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 4987); + EXPECT_EQ(count, 19); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[15], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[16], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[17], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[18], LWMQTT_UNSUB_PACKET_ID_IN_USE); +} + +// UnsubscribeResponse 13086 [PropResponseTopic "\215\158\193\237\189\FS\136\172v",PropContentType +// "\EM\191\156,1K\249\189\184\154\ESC\n\202n\STX<\EM{4\218\184\ACK\n-",PropServerKeepAlive 27576,PropCorrelationData +// "^\223\219\DC1\239\&2\251\&0\129pW$c}",PropPayloadFormatIndicator 245,PropReceiveMaximum 2551,PropServerKeepAlive +// 22651,PropWillDelayInterval 31428,PropMessageExpiryInterval 21262,PropSharedSubscriptionAvailable +// 130,PropAuthenticationMethod " \175\SOH\248H\253\192\EOT\RS\168|%",PropSubscriptionIdentifierAvailable +// 85,PropRequestResponseInformation 246,PropRequestResponseInformation 111,PropMaximumQoS 4,PropMessageExpiryInterval +// 13660,PropReceiveMaximum 3025,PropAuthenticationData "\146\146\&8\219\&5Z\244",PropTopicAliasMaximum +// 23621,PropMaximumPacketSize 30340] +// [UnsubUnspecifiedError,UnsubPacketIdentifierInUse,UnsubPacketIdentifierInUse,UnsubPacketIdentifierInUse,UnsubNoSubscriptionExisted,UnsubImplementationSpecificError,UnsubNotAuthorized,UnsubNotAuthorized,UnsubSuccess,UnsubNoSubscriptionExisted,UnsubTopicFilterInvalid,UnsubSuccess,UnsubTopicFilterInvalid,UnsubNotAuthorized,UnsubNoSubscriptionExisted,UnsubSuccess,UnsubSuccess,UnsubNoSubscriptionExisted,UnsubNoSubscriptionExisted,UnsubSuccess,UnsubTopicFilterInvalid,UnsubUnspecifiedError,UnsubPacketIdentifierInUse,UnsubSuccess,UnsubNotAuthorized,UnsubSuccess,UnsubImplementationSpecificError,UnsubPacketIdentifierInUse,UnsubTopicFilterInvalid,UnsubNoSubscriptionExisted] +TEST(UnsubACK5QCTest, Decode25) { + uint8_t pkt[] = {0xb0, 0xa2, 0x1, 0x33, 0x1e, 0x80, 0x1, 0x8, 0x0, 0x9, 0xd7, 0x9e, 0xc1, 0xed, 0xbd, 0x1c, 0x88, + 0xac, 0x76, 0x3, 0x0, 0x18, 0x19, 0xbf, 0x9c, 0x2c, 0x31, 0x4b, 0xf9, 0xbd, 0xb8, 0x9a, 0x1b, 0xa, + 0xca, 0x6e, 0x2, 0x3c, 0x19, 0x7b, 0x34, 0xda, 0xb8, 0x6, 0xa, 0x2d, 0x13, 0x6b, 0xb8, 0x9, 0x0, + 0xe, 0x5e, 0xdf, 0xdb, 0x11, 0xef, 0x32, 0xfb, 0x30, 0x81, 0x70, 0x57, 0x24, 0x63, 0x7d, 0x1, 0xf5, + 0x21, 0x9, 0xf7, 0x13, 0x58, 0x7b, 0x18, 0x0, 0x0, 0x7a, 0xc4, 0x2, 0x0, 0x0, 0x53, 0xe, 0x2a, + 0x82, 0x15, 0x0, 0xc, 0x20, 0xaf, 0x1, 0xf8, 0x48, 0xfd, 0xc0, 0x4, 0x1e, 0xa8, 0x7c, 0x25, 0x29, + 0x55, 0x19, 0xf6, 0x19, 0x6f, 0x24, 0x4, 0x2, 0x0, 0x0, 0x35, 0x5c, 0x21, 0xb, 0xd1, 0x16, 0x0, + 0x7, 0x92, 0x92, 0x38, 0xdb, 0x35, 0x5a, 0xf4, 0x22, 0x5c, 0x45, 0x27, 0x0, 0x0, 0x76, 0x84, 0x80, + 0x91, 0x91, 0x91, 0x11, 0x83, 0x87, 0x87, 0x0, 0x11, 0x8f, 0x0, 0x8f, 0x87, 0x11, 0x0, 0x0, 0x11, + 0x11, 0x0, 0x8f, 0x80, 0x91, 0x0, 0x87, 0x0, 0x83, 0x91, 0x8f, 0x11}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[30]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 30, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 13086); + EXPECT_EQ(count, 30); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[15], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[16], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[17], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[18], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[19], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[20], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[21], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[22], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[23], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[24], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[25], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[26], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[27], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[28], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[29], LWMQTT_UNSUB_NO_SUB_EXISTED); +} + +// UnsubscribeResponse 16043 [PropRetainAvailable 148,PropAuthenticationData +// "\EM\144\139\238(\185g\156\220\183\188\&7\tK\ACK\184\ETX\t0\rB\203\157+\b\225\240\230`\SOH",PropReceiveMaximum +// 4793,PropRequestProblemInformation 137,PropCorrelationData "\218<\244\153\&8",PropMaximumQoS 97,PropContentType +// "\207*\DLE\RS\SYN\177\218G\155\249\169\150-,\150\237\ACK\134\169\&5L'D\142\139\226\ETX\206L",PropWillDelayInterval +// 23572,PropTopicAliasMaximum 11986,PropMessageExpiryInterval 10904,PropRetainAvailable 197,PropPayloadFormatIndicator +// 134,PropSessionExpiryInterval 25170,PropSessionExpiryInterval 31305,PropServerKeepAlive 4756,PropReasonString +// "\r\199F",PropServerKeepAlive 24387,PropRequestResponseInformation 107,PropSessionExpiryInterval +// 8036,PropReasonString "\238\159I%\147\195\150\&7\208iP|}\241\r\134\159\149\239",PropServerKeepAlive +// 7365,PropMessageExpiryInterval 23950,PropMaximumPacketSize 26632,PropReceiveMaximum 17416] +// [UnsubNoSubscriptionExisted,UnsubNoSubscriptionExisted,UnsubSuccess,UnsubNotAuthorized,UnsubPacketIdentifierInUse,UnsubUnspecifiedError,UnsubSuccess,UnsubImplementationSpecificError,UnsubImplementationSpecificError,UnsubUnspecifiedError,UnsubNotAuthorized,UnsubTopicFilterInvalid,UnsubNotAuthorized,UnsubTopicFilterInvalid,UnsubPacketIdentifierInUse,UnsubNotAuthorized,UnsubNotAuthorized,UnsubUnspecifiedError,UnsubTopicFilterInvalid] +TEST(UnsubACK5QCTest, Decode26) { + uint8_t pkt[] = {0xb0, 0xbd, 0x1, 0x3e, 0xab, 0xa6, 0x1, 0x25, 0x94, 0x16, 0x0, 0x1e, 0x19, 0x90, 0x8b, 0xee, + 0x28, 0xb9, 0x67, 0x9c, 0xdc, 0xb7, 0xbc, 0x37, 0x9, 0x4b, 0x6, 0xb8, 0x3, 0x9, 0x30, 0xd, + 0x42, 0xcb, 0x9d, 0x2b, 0x8, 0xe1, 0xf0, 0xe6, 0x60, 0x1, 0x21, 0x12, 0xb9, 0x17, 0x89, 0x9, + 0x0, 0x5, 0xda, 0x3c, 0xf4, 0x99, 0x38, 0x24, 0x61, 0x3, 0x0, 0x1d, 0xcf, 0x2a, 0x10, 0x1e, + 0x16, 0xb1, 0xda, 0x47, 0x9b, 0xf9, 0xa9, 0x96, 0x2d, 0x2c, 0x96, 0xed, 0x6, 0x86, 0xa9, 0x35, + 0x4c, 0x27, 0x44, 0x8e, 0x8b, 0xe2, 0x3, 0xce, 0x4c, 0x18, 0x0, 0x0, 0x5c, 0x14, 0x22, 0x2e, + 0xd2, 0x2, 0x0, 0x0, 0x2a, 0x98, 0x25, 0xc5, 0x1, 0x86, 0x11, 0x0, 0x0, 0x62, 0x52, 0x11, + 0x0, 0x0, 0x7a, 0x49, 0x13, 0x12, 0x94, 0x1f, 0x0, 0x3, 0xd, 0xc7, 0x46, 0x13, 0x5f, 0x43, + 0x19, 0x6b, 0x11, 0x0, 0x0, 0x1f, 0x64, 0x1f, 0x0, 0x13, 0xee, 0x9f, 0x49, 0x25, 0x93, 0xc3, + 0x96, 0x37, 0xd0, 0x69, 0x50, 0x7c, 0x7d, 0xf1, 0xd, 0x86, 0x9f, 0x95, 0xef, 0x13, 0x1c, 0xc5, + 0x2, 0x0, 0x0, 0x5d, 0x8e, 0x27, 0x0, 0x0, 0x68, 0x8, 0x21, 0x44, 0x8, 0x11, 0x11, 0x0, + 0x87, 0x91, 0x80, 0x0, 0x83, 0x83, 0x80, 0x87, 0x8f, 0x87, 0x8f, 0x91, 0x87, 0x87, 0x80, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[19]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 19, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 16043); + EXPECT_EQ(count, 19); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_NO_SUB_EXISTED); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[9], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[10], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[11], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[12], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[13], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[14], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[15], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[16], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[17], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[18], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); +} + +// UnsubscribeResponse 31830 [PropWildcardSubscriptionAvailable 73,PropWillDelayInterval 6565,PropPayloadFormatIndicator +// 44,PropReasonString "s\NULj\140\255y1 +// \223\EM\ENQ\248\151\193b\165\130\189f\132\133\182\f\250\248\199\248",PropRequestResponseInformation +// 195,PropMaximumQoS 140,PropMaximumPacketSize 27932,PropResponseInformation +// "\203\154\234=\186\153\n\199\142\207\207\NUL\227~\184\219l+\149\128\166\138\238\185\ETB\218_",PropRequestResponseInformation +// 68,PropPayloadFormatIndicator 154] +// [UnsubUnspecifiedError,UnsubSuccess,UnsubTopicFilterInvalid,UnsubSuccess,UnsubSuccess,UnsubImplementationSpecificError,UnsubImplementationSpecificError,UnsubPacketIdentifierInUse,UnsubTopicFilterInvalid] +TEST(UnsubACK5QCTest, Decode27) { + uint8_t pkt[] = {0xb0, 0x5e, 0x7c, 0x56, 0x52, 0x28, 0x49, 0x18, 0x0, 0x0, 0x19, 0xa5, 0x1, 0x2c, 0x1f, 0x0, + 0x1b, 0x73, 0x0, 0x6a, 0x8c, 0xff, 0x79, 0x31, 0x20, 0xdf, 0x19, 0x5, 0xf8, 0x97, 0xc1, 0x62, + 0xa5, 0x82, 0xbd, 0x66, 0x84, 0x85, 0xb6, 0xc, 0xfa, 0xf8, 0xc7, 0xf8, 0x19, 0xc3, 0x24, 0x8c, + 0x27, 0x0, 0x0, 0x6d, 0x1c, 0x1a, 0x0, 0x1b, 0xcb, 0x9a, 0xea, 0x3d, 0xba, 0x99, 0xa, 0xc7, + 0x8e, 0xcf, 0xcf, 0x0, 0xe3, 0x7e, 0xb8, 0xdb, 0x6c, 0x2b, 0x95, 0x80, 0xa6, 0x8a, 0xee, 0xb9, + 0x17, 0xda, 0x5f, 0x19, 0x44, 0x1, 0x9a, 0x80, 0x0, 0x8f, 0x0, 0x0, 0x83, 0x83, 0x91, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[9]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 9, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 31830); + EXPECT_EQ(count, 9); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_SUCCESS); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[6], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[7], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[8], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); +} + +// UnsubscribeResponse 13530 [PropMaximumPacketSize 718,PropResponseTopic +// "u3\\\ETB\192\241.\143(@\\\130b\140$\154{G\226\145k\178\144\219",PropServerKeepAlive +// 16210,PropRequestResponseInformation 144,PropMessageExpiryInterval 16424,PropMaximumQoS 70,PropAuthenticationMethod +// "\181\239(=\202\149F\157\\\235:\171\180\153\206\t;\ETB\140{\150b\145\NUL\184\150",PropUserProperty +// "\172m\225vX\209\178\224F\246\213\r\193U'\177\138\SO\ETX\209" +// "\156\218\155\246O\SUB\190'\218\NAK\183E1",PropAuthenticationMethod +// "wK\174\203\215j\244,\178\b",PropAuthenticationData +// "\181\136.\150\141\138\141\248=\194\&6CXp\RS\205\\A\150TR\228\197",PropServerKeepAlive 27438,PropMaximumPacketSize +// 15377,PropRetainAvailable 155,PropReceiveMaximum 2324,PropMessageExpiryInterval 4393,PropSubscriptionIdentifier +// 24,PropSubscriptionIdentifier 11,PropContentType +// "\254-\181\b\188H\248\138G\201V#y\ETX\245\195\&4.\132\USP\249\133u\172\162\EOT\200D",PropUserProperty +// "j\SUB\160\131\190\138\151\140Y3" "\182\ESC\SUB\192",PropUserProperty +// "\151c\169L?Cj\213*@]\247;\ESC>\223\164\DLE\142\\\143\252\EM\212\216A\130#\197\193" +// "\STX\EOT\241",PropCorrelationData "\135f\186\168\138",PropMaximumPacketSize +// 29512,PropSubscriptionIdentifierAvailable 88,PropResponseTopic "\GS",PropMessageExpiryInterval 28440] +// [UnsubTopicFilterInvalid,UnsubNotAuthorized,UnsubImplementationSpecificError,UnsubUnspecifiedError,UnsubPacketIdentifierInUse,UnsubNotAuthorized] +TEST(UnsubACK5QCTest, Decode28) { + uint8_t pkt[] = { + 0xb0, 0xa7, 0x2, 0x34, 0xda, 0x9d, 0x2, 0x27, 0x0, 0x0, 0x2, 0xce, 0x8, 0x0, 0x18, 0x75, 0x33, 0x5c, 0x17, + 0xc0, 0xf1, 0x2e, 0x8f, 0x28, 0x40, 0x5c, 0x82, 0x62, 0x8c, 0x24, 0x9a, 0x7b, 0x47, 0xe2, 0x91, 0x6b, 0xb2, 0x90, + 0xdb, 0x13, 0x3f, 0x52, 0x19, 0x90, 0x2, 0x0, 0x0, 0x40, 0x28, 0x24, 0x46, 0x15, 0x0, 0x1a, 0xb5, 0xef, 0x28, + 0x3d, 0xca, 0x95, 0x46, 0x9d, 0x5c, 0xeb, 0x3a, 0xab, 0xb4, 0x99, 0xce, 0x9, 0x3b, 0x17, 0x8c, 0x7b, 0x96, 0x62, + 0x91, 0x0, 0xb8, 0x96, 0x26, 0x0, 0x14, 0xac, 0x6d, 0xe1, 0x76, 0x58, 0xd1, 0xb2, 0xe0, 0x46, 0xf6, 0xd5, 0xd, + 0xc1, 0x55, 0x27, 0xb1, 0x8a, 0xe, 0x3, 0xd1, 0x0, 0xd, 0x9c, 0xda, 0x9b, 0xf6, 0x4f, 0x1a, 0xbe, 0x27, 0xda, + 0x15, 0xb7, 0x45, 0x31, 0x15, 0x0, 0xa, 0x77, 0x4b, 0xae, 0xcb, 0xd7, 0x6a, 0xf4, 0x2c, 0xb2, 0x8, 0x16, 0x0, + 0x17, 0xb5, 0x88, 0x2e, 0x96, 0x8d, 0x8a, 0x8d, 0xf8, 0x3d, 0xc2, 0x36, 0x43, 0x58, 0x70, 0x1e, 0xcd, 0x5c, 0x41, + 0x96, 0x54, 0x52, 0xe4, 0xc5, 0x13, 0x6b, 0x2e, 0x27, 0x0, 0x0, 0x3c, 0x11, 0x25, 0x9b, 0x21, 0x9, 0x14, 0x2, + 0x0, 0x0, 0x11, 0x29, 0xb, 0x18, 0xb, 0xb, 0x3, 0x0, 0x1d, 0xfe, 0x2d, 0xb5, 0x8, 0xbc, 0x48, 0xf8, 0x8a, + 0x47, 0xc9, 0x56, 0x23, 0x79, 0x3, 0xf5, 0xc3, 0x34, 0x2e, 0x84, 0x1f, 0x50, 0xf9, 0x85, 0x75, 0xac, 0xa2, 0x4, + 0xc8, 0x44, 0x26, 0x0, 0xa, 0x6a, 0x1a, 0xa0, 0x83, 0xbe, 0x8a, 0x97, 0x8c, 0x59, 0x33, 0x0, 0x4, 0xb6, 0x1b, + 0x1a, 0xc0, 0x26, 0x0, 0x1e, 0x97, 0x63, 0xa9, 0x4c, 0x3f, 0x43, 0x6a, 0xd5, 0x2a, 0x40, 0x5d, 0xf7, 0x3b, 0x1b, + 0x3e, 0xdf, 0xa4, 0x10, 0x8e, 0x5c, 0x8f, 0xfc, 0x19, 0xd4, 0xd8, 0x41, 0x82, 0x23, 0xc5, 0xc1, 0x0, 0x3, 0x2, + 0x4, 0xf1, 0x9, 0x0, 0x5, 0x87, 0x66, 0xba, 0xa8, 0x8a, 0x27, 0x0, 0x0, 0x73, 0x48, 0x29, 0x58, 0x8, 0x0, + 0x1, 0x1d, 0x2, 0x0, 0x0, 0x6f, 0x18, 0x8f, 0x87, 0x83, 0x80, 0x91, 0x87}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[6]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 6, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 13530); + EXPECT_EQ(count, 6); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_NOT_AUTHORIZED); + EXPECT_EQ(statuses[2], LWMQTT_UNSUB_IMPL_SPECIFIC_ERROR); + EXPECT_EQ(statuses[3], LWMQTT_UNSUB_UNSPECIFIED_ERROR); + EXPECT_EQ(statuses[4], LWMQTT_UNSUB_PACKET_ID_IN_USE); + EXPECT_EQ(statuses[5], LWMQTT_UNSUB_NOT_AUTHORIZED); +} + +// UnsubscribeResponse 29514 [PropMaximumPacketSize 14670,PropServerKeepAlive 4681,PropAuthenticationData +// "\255'\197\248\171\136t\197\204\188\US",PropReceiveMaximum 24642,PropReasonString "y\136\DC1\209",PropResponseTopic +// "F\206\166.1\196",PropRequestProblemInformation 35,PropMessageExpiryInterval 2812,PropTopicAlias +// 27219,PropMaximumPacketSize 29246] [UnsubTopicFilterInvalid,UnsubTopicFilterInvalid] +TEST(UnsubACK5QCTest, Decode29) { + uint8_t pkt[] = {0xb0, 0x3d, 0x73, 0x4a, 0x38, 0x27, 0x0, 0x0, 0x39, 0x4e, 0x13, 0x12, 0x49, 0x16, 0x0, 0xb, + 0xff, 0x27, 0xc5, 0xf8, 0xab, 0x88, 0x74, 0xc5, 0xcc, 0xbc, 0x1f, 0x21, 0x60, 0x42, 0x1f, 0x0, + 0x4, 0x79, 0x88, 0x11, 0xd1, 0x8, 0x0, 0x6, 0x46, 0xce, 0xa6, 0x2e, 0x31, 0xc4, 0x17, 0x23, + 0x2, 0x0, 0x0, 0xa, 0xfc, 0x23, 0x6a, 0x53, 0x27, 0x0, 0x0, 0x72, 0x3e, 0x8f, 0x8f}; + uint16_t packet_id; + int count; + lwmqtt_unsubscribe_status_t statuses[2]; + lwmqtt_err_t err = lwmqtt_decode_unsuback(pkt, sizeof(pkt), &packet_id, LWMQTT_MQTT5, 2, &count, statuses); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(packet_id, 29514); + EXPECT_EQ(count, 2); + EXPECT_EQ(statuses[0], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); + EXPECT_EQ(statuses[1], LWMQTT_UNSUB_TOPIC_FILTER_INVALID); +} + +// UnsubscribeResponse 14096 [PropUserProperty "\246\130\240" "H\170Co\215\187hU",PropWildcardSubscriptionAvailable +// 186,PropAssignedClientIdentifier "\150\ACK\EOT\237\193\ETX=\228$\f\214\220\131G\194\200",PropAuthenticationMethod +// ">\153\226\190%\SUB\244\241d?\174\201Uq\187\SUB",PropWildcardSubscriptionAvailable 41,PropWillDelayInterval +// 233,PropAssignedClientIdentifier +// "PRt\DELe\149|\DC3\234\134h\157a",PropResponseInformation "\246\179M\US\164\214\214\236 +// \203\133e\242\158\139\137\226\170/Z\240>)dp\DEL\225\SOH\204",PropSubscriptionIdentifier 0,PropMessageExpiryInterval +// 16776,PropRetainAvailable 158,PropRequestProblemInformation 157,PropMessageExpiryInterval 3249,PropResponseTopic +// "\SO\nB\198\245\198h}\164\202\255\201\NAK\177\180\211\216c\CANdM\133\170\192b",PropAuthenticationMethod +// "#j\ETB6&\180\207\168S\209\254\192.Cp\214Y\164\241\246\173y\222[",PropSessionExpiryInterval 8286,PropTopicAlias +// 27011,PropMessageExpiryInterval 13397,PropSubscriptionIdentifier 16,PropCorrelationData +// "\214\173\ETB%\204\&3i]%\205\DC4\134\&6`\129\DC1\132U\169",PropCorrelationData +// "\SI2Uk\SI,\227\STX\204]\DLE5\193\&5\174\133\151a\186",PropReasonString +// "v=\211\US\162\223\&1\215\SUB\233\FS",PropRetainAvailable 127,PropReasonString +// "I\196B\213\190p\DC1\205\153\NAKa\219q",PropMaximumQoS 8,PropTopicAliasMaximum 14250] +TEST(Disco5QCTest, Encode13) { + uint8_t pkt[] = { + 0xe0, 0xf2, 0x1, 0x83, 0xef, 0x1, 0x29, 0xca, 0x1a, 0x0, 0x9, 0x92, 0x7b, 0x3f, 0xc2, 0x8f, 0x62, 0xa1, 0x5b, + 0x40, 0x9, 0x0, 0x2, 0xe6, 0x3c, 0x2, 0x0, 0x0, 0x6e, 0x2b, 0x15, 0x0, 0xd, 0xb3, 0x5a, 0x74, 0x1, 0x22, + 0x8, 0xb7, 0xb9, 0x73, 0xe0, 0x11, 0xa2, 0x3e, 0x1a, 0x0, 0x1d, 0xf6, 0xb3, 0x4d, 0x1f, 0xa4, 0xd6, 0xd6, 0xec, + 0x20, 0xcb, 0x85, 0x65, 0xf2, 0x9e, 0x8b, 0x89, 0xe2, 0xaa, 0x2f, 0x5a, 0xf0, 0x3e, 0x29, 0x64, 0x70, 0x7f, 0xe1, + 0x1, 0xcc, 0xb, 0x0, 0x2, 0x0, 0x0, 0x41, 0x88, 0x25, 0x9e, 0x17, 0x9d, 0x2, 0x0, 0x0, 0xc, 0xb1, 0x8, + 0x0, 0x19, 0xe, 0xa, 0x42, 0xc6, 0xf5, 0xc6, 0x68, 0x7d, 0xa4, 0xca, 0xff, 0xc9, 0x15, 0xb1, 0xb4, 0xd3, 0xd8, + 0x63, 0x18, 0x64, 0x4d, 0x85, 0xaa, 0xc0, 0x62, 0x15, 0x0, 0x18, 0x23, 0x6a, 0x17, 0x36, 0x26, 0xb4, 0xcf, 0xa8, + 0x53, 0xd1, 0xfe, 0xc0, 0x2e, 0x43, 0x70, 0xd6, 0x59, 0xa4, 0xf1, 0xf6, 0xad, 0x79, 0xde, 0x5b, 0x11, 0x0, 0x0, + 0x20, 0x5e, 0x23, 0x69, 0x83, 0x2, 0x0, 0x0, 0x34, 0x55, 0xb, 0x10, 0x9, 0x0, 0x13, 0xd6, 0xad, 0x17, 0x25, + 0xcc, 0x33, 0x69, 0x5d, 0x25, 0xcd, 0x14, 0x86, 0x36, 0x60, 0x81, 0x11, 0x84, 0x55, 0xa9, 0x9, 0x0, 0x13, 0xf, + 0x32, 0x55, 0x6b, 0xf, 0x2c, 0xe3, 0x2, 0xcc, 0x5d, 0x10, 0x35, 0xc1, 0x35, 0xae, 0x85, 0x97, 0x61, 0xba, 0x1f, + 0x0, 0xb, 0x76, 0x3d, 0xd3, 0x1f, 0xa2, 0xdf, 0x31, 0xd7, 0x1a, 0xe9, 0x1c, 0x25, 0x7f, 0x1f, 0x0, 0xd, 0x49, + 0xc4, 0x42, 0xd5, 0xbe, 0x70, 0x11, 0xcd, 0x99, 0x15, 0x61, 0xdb, 0x71, 0x24, 0x8, 0x22, 0x37, 0xaa}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x92, 0x7b, 0x3f, 0xc2, 0x8f, 0x62, 0xa1, 0x5b, 0x40}; + uint8_t bytesprops1[] = {0xe6, 0x3c}; + uint8_t bytesprops2[] = {0xb3, 0x5a, 0x74, 0x1, 0x22, 0x8, 0xb7, 0xb9, 0x73, 0xe0, 0x11, 0xa2, 0x3e}; + uint8_t bytesprops3[] = {0xf6, 0xb3, 0x4d, 0x1f, 0xa4, 0xd6, 0xd6, 0xec, 0x20, 0xcb, 0x85, 0x65, 0xf2, 0x9e, 0x8b, + 0x89, 0xe2, 0xaa, 0x2f, 0x5a, 0xf0, 0x3e, 0x29, 0x64, 0x70, 0x7f, 0xe1, 0x1, 0xcc}; + uint8_t bytesprops4[] = {0xe, 0xa, 0x42, 0xc6, 0xf5, 0xc6, 0x68, 0x7d, 0xa4, 0xca, 0xff, 0xc9, 0x15, + 0xb1, 0xb4, 0xd3, 0xd8, 0x63, 0x18, 0x64, 0x4d, 0x85, 0xaa, 0xc0, 0x62}; + uint8_t bytesprops5[] = {0x23, 0x6a, 0x17, 0x36, 0x26, 0xb4, 0xcf, 0xa8, 0x53, 0xd1, 0xfe, 0xc0, + 0x2e, 0x43, 0x70, 0xd6, 0x59, 0xa4, 0xf1, 0xf6, 0xad, 0x79, 0xde, 0x5b}; + uint8_t bytesprops6[] = {0xd6, 0xad, 0x17, 0x25, 0xcc, 0x33, 0x69, 0x5d, 0x25, 0xcd, + 0x14, 0x86, 0x36, 0x60, 0x81, 0x11, 0x84, 0x55, 0xa9}; + uint8_t bytesprops7[] = {0xf, 0x32, 0x55, 0x6b, 0xf, 0x2c, 0xe3, 0x2, 0xcc, 0x5d, + 0x10, 0x35, 0xc1, 0x35, 0xae, 0x85, 0x97, 0x61, 0xba}; + uint8_t bytesprops8[] = {0x76, 0x3d, 0xd3, 0x1f, 0xa2, 0xdf, 0x31, 0xd7, 0x1a, 0xe9, 0x1c}; + uint8_t bytesprops9[] = {0x49, 0xc4, 0x42, 0xd5, 0xbe, 0x70, 0x11, 0xcd, 0x99, 0x15, 0x61, 0xdb, 0x71}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 202}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {9, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {2, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 28203}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {13, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {29, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 0}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 16776}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 158}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 157}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 3249}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {25, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {24, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 8286}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 27011}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 13397}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 16}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {19, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {19, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {11, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 127}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {13, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 8}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 14250}}, + }; + + lwmqtt_properties_t props = {24, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 131, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoDisconnectWithWill [PropUserProperty "\146\161i\179\130J" +// "\177B",PropWildcardSubscriptionAvailable 138,PropRequestProblemInformation 216,PropTopicAlias +// 29685,PropSubscriptionIdentifier 15,PropAssignedClientIdentifier +// "\200\209\130\SO\184\RSk\184\235*T\197\216\149x\a\182\157\159\192\CAN.\ETBS\129t\250\DC30]",PropRetainAvailable +// 193,PropSubscriptionIdentifier 27,PropPayloadFormatIndicator 191,PropAuthenticationData +// "\253\206]\201\159\&5%\155\221\164\187\236'\179\182\212~",PropServerReference "\240\EM\184\230",PropMaximumQoS +// 14,PropRetainAvailable 127,PropMessageExpiryInterval 11452,PropResponseTopic +// "\135|\\y/\224\&6\168\156\153\SO\149",PropSubscriptionIdentifier 5,PropWildcardSubscriptionAvailable +// 84,PropMaximumQoS 177,PropUserProperty "\GS\232\ACKS\241\202\203\212\&4F\241\SYNIN\204\226\183\136 +// 4\233\ESC\187-[\211\204\128\248" "\201|6B,\237\DLE\DC2\DEL\249p\SI\b\215\224\248\154\210ry\249vrB\180\ACK\244U"] +TEST(Disco5QCTest, Encode14) { + uint8_t pkt[] = {0xe0, 0xb7, 0x1, 0x4, 0xb4, 0x1, 0x26, 0x0, 0x6, 0x92, 0xa1, 0x69, 0xb3, 0x82, 0x4a, 0x0, 0x2, + 0xb1, 0x42, 0x28, 0x8a, 0x17, 0xd8, 0x23, 0x73, 0xf5, 0xb, 0xf, 0x12, 0x0, 0x1e, 0xc8, 0xd1, 0x82, + 0xe, 0xb8, 0x1e, 0x6b, 0xb8, 0xeb, 0x2a, 0x54, 0xc5, 0xd8, 0x95, 0x78, 0x7, 0xb6, 0x9d, 0x9f, 0xc0, + 0x18, 0x2e, 0x17, 0x53, 0x81, 0x74, 0xfa, 0x13, 0x30, 0x5d, 0x25, 0xc1, 0xb, 0x1b, 0x1, 0xbf, 0x16, + 0x0, 0x11, 0xfd, 0xce, 0x5d, 0xc9, 0x9f, 0x35, 0x25, 0x9b, 0xdd, 0xa4, 0xbb, 0xec, 0x27, 0xb3, 0xb6, + 0xd4, 0x7e, 0x1c, 0x0, 0x4, 0xf0, 0x19, 0xb8, 0xe6, 0x24, 0xe, 0x25, 0x7f, 0x2, 0x0, 0x0, 0x2c, + 0xbc, 0x8, 0x0, 0xc, 0x87, 0x7c, 0x5c, 0x79, 0x2f, 0xe0, 0x36, 0xa8, 0x9c, 0x99, 0xe, 0x95, 0xb, + 0x5, 0x28, 0x54, 0x24, 0xb1, 0x26, 0x0, 0x1d, 0x1d, 0xe8, 0x6, 0x53, 0xf1, 0xca, 0xcb, 0xd4, 0x34, + 0x46, 0xf1, 0x16, 0x49, 0x4e, 0xcc, 0xe2, 0xb7, 0x88, 0x20, 0x34, 0xe9, 0x1b, 0xbb, 0x2d, 0x5b, 0xd3, + 0xcc, 0x80, 0xf8, 0x0, 0x1c, 0xc9, 0x7c, 0x36, 0x42, 0x2c, 0xed, 0x10, 0x12, 0x7f, 0xf9, 0x70, 0xf, + 0x8, 0xd7, 0xe0, 0xf8, 0x9a, 0xd2, 0x72, 0x79, 0xf9, 0x76, 0x72, 0x42, 0xb4, 0x6, 0xf4, 0x55}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops1[] = {0xb1, 0x42}; + uint8_t bytesprops0[] = {0x92, 0xa1, 0x69, 0xb3, 0x82, 0x4a}; + uint8_t bytesprops2[] = {0xc8, 0xd1, 0x82, 0xe, 0xb8, 0x1e, 0x6b, 0xb8, 0xeb, 0x2a, 0x54, 0xc5, 0xd8, 0x95, 0x78, + 0x7, 0xb6, 0x9d, 0x9f, 0xc0, 0x18, 0x2e, 0x17, 0x53, 0x81, 0x74, 0xfa, 0x13, 0x30, 0x5d}; + uint8_t bytesprops3[] = {0xfd, 0xce, 0x5d, 0xc9, 0x9f, 0x35, 0x25, 0x9b, 0xdd, + 0xa4, 0xbb, 0xec, 0x27, 0xb3, 0xb6, 0xd4, 0x7e}; + uint8_t bytesprops4[] = {0xf0, 0x19, 0xb8, 0xe6}; + uint8_t bytesprops5[] = {0x87, 0x7c, 0x5c, 0x79, 0x2f, 0xe0, 0x36, 0xa8, 0x9c, 0x99, 0xe, 0x95}; + uint8_t bytesprops7[] = {0xc9, 0x7c, 0x36, 0x42, 0x2c, 0xed, 0x10, 0x12, 0x7f, 0xf9, 0x70, 0xf, 0x8, 0xd7, + 0xe0, 0xf8, 0x9a, 0xd2, 0x72, 0x79, 0xf9, 0x76, 0x72, 0x42, 0xb4, 0x6, 0xf4, 0x55}; + uint8_t bytesprops6[] = {0x1d, 0xe8, 0x6, 0x53, 0xf1, 0xca, 0xcb, 0xd4, 0x34, 0x46, 0xf1, 0x16, 0x49, 0x4e, 0xcc, + 0xe2, 0xb7, 0x88, 0x20, 0x34, 0xe9, 0x1b, 0xbb, 0x2d, 0x5b, 0xd3, 0xcc, 0x80, 0xf8}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {6, (char*)&bytesprops0}, .v = {2, (char*)&bytesprops1}}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 138}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 216}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 29685}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 15}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {30, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 193}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 27}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 191}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {17, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {4, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 14}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 127}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 11452}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {12, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 5}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 84}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 177}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {29, (char*)&bytesprops6}, .v = {28, (char*)&bytesprops7}}}}, + }; + + lwmqtt_properties_t props = {19, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 4, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoMaximumConnectTime [PropMessageExpiryInterval 21495,PropRetainAvailable +// 1,PropMessageExpiryInterval 193,PropCorrelationData "",PropServerKeepAlive 6609,PropSessionExpiryInterval +// 3824,PropCorrelationData "\132\&7F\167\136",PropTopicAlias 676,PropServerKeepAlive 6121,PropMessageExpiryInterval +// 9093] +TEST(Disco5QCTest, Encode15) { + uint8_t pkt[] = {0xe0, 0x2c, 0xa0, 0x2a, 0x2, 0x0, 0x0, 0x53, 0xf7, 0x25, 0x1, 0x2, 0x0, 0x0, 0x0, 0xc1, + 0x9, 0x0, 0x0, 0x13, 0x19, 0xd1, 0x11, 0x0, 0x0, 0xe, 0xf0, 0x9, 0x0, 0x5, 0x84, 0x37, + 0x46, 0xa7, 0x88, 0x23, 0x2, 0xa4, 0x13, 0x17, 0xe9, 0x2, 0x0, 0x0, 0x23, 0x85}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0}; + uint8_t bytesprops1[] = {0x84, 0x37, 0x46, 0xa7, 0x88}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 21495}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 1}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 193}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {0, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 6609}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 3824}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {5, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 676}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 6121}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 9093}}, + }; + + lwmqtt_properties_t props = {10, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 160, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoNotAuthorized [PropSubscriptionIdentifier 2,PropRequestResponseInformation 76,PropContentType +// " -\204y\165v(a\232\NAK\148\SI|e}E",PropTopicAliasMaximum 22692,PropCorrelationData +// "o\164\134|^\154\175\SOH\178\244Zx\SOs\128`[\SYN",PropSessionExpiryInterval 5279,PropSessionExpiryInterval 6600] +TEST(Disco5QCTest, Encode16) { + uint8_t pkt[] = {0xe0, 0x3b, 0x87, 0x39, 0xb, 0x2, 0x19, 0x4c, 0x3, 0x0, 0x10, 0x20, 0x2d, 0xcc, 0x79, 0xa5, + 0x76, 0x28, 0x61, 0xe8, 0x15, 0x94, 0xf, 0x7c, 0x65, 0x7d, 0x45, 0x22, 0x58, 0xa4, 0x9, 0x0, + 0x12, 0x6f, 0xa4, 0x86, 0x7c, 0x5e, 0x9a, 0xaf, 0x1, 0xb2, 0xf4, 0x5a, 0x78, 0xe, 0x73, 0x80, + 0x60, 0x5b, 0x16, 0x11, 0x0, 0x0, 0x14, 0x9f, 0x11, 0x0, 0x0, 0x19, 0xc8}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x20, 0x2d, 0xcc, 0x79, 0xa5, 0x76, 0x28, 0x61, + 0xe8, 0x15, 0x94, 0xf, 0x7c, 0x65, 0x7d, 0x45}; + uint8_t bytesprops1[] = {0x6f, 0xa4, 0x86, 0x7c, 0x5e, 0x9a, 0xaf, 0x1, 0xb2, + 0xf4, 0x5a, 0x78, 0xe, 0x73, 0x80, 0x60, 0x5b, 0x16}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 2}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 76}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {16, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 22692}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {18, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 5279}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 6600}}, + }; + + lwmqtt_properties_t props = {7, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 135, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoSharedSubscriptionsNotSupported [PropMessageExpiryInterval 10770,PropMaximumPacketSize +// 25135,PropTopicAliasMaximum 29884] +TEST(Disco5QCTest, Encode17) { + uint8_t pkt[] = {0xe0, 0xf, 0x9e, 0xd, 0x2, 0x0, 0x0, 0x2a, 0x12, 0x27, 0x0, 0x0, 0x62, 0x2f, 0x22, 0x74, 0xbc}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 10770}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 25135}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 29884}}, + }; + + lwmqtt_properties_t props = {3, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 158, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoPacketTooLarge [PropTopicAlias 4988,PropRequestProblemInformation 8,PropMessageExpiryInterval +// 10687,PropAuthenticationMethod "\146\145S?$\224\bN\154`\146\253\SUB\186\213\171",PropRetainAvailable +// 92,PropResponseTopic "r\\\DC4\252v\182.\220\ENQ",PropTopicAlias 10477,PropRequestResponseInformation +// 242,PropUserProperty "\196bD\146\254\RS\202(\219\RS_\128\163\144\135\227\239N\131\EOT\CAN\139\195\171\162" +// "Y#\243v",PropResponseTopic +// "\227`\FS\221\182l\198yF\128q-\EOT\ETB\204%RA\203\207\SI\DC4\196\DC4\144\248\253A",PropTopicAlias +// 16910,PropServerKeepAlive 4442,PropResponseInformation +// "{{\243\220N\DC4\ACK\203\154\209\177a\226\FS;\190\176\138",PropSubscriptionIdentifierAvailable +// 35,PropMaximumPacketSize 14453,PropReasonString "\187\199",PropRequestProblemInformation 120] +TEST(Disco5QCTest, Encode18) { + uint8_t pkt[] = {0xe0, 0x9d, 0x1, 0x95, 0x9a, 0x1, 0x23, 0x13, 0x7c, 0x17, 0x8, 0x2, 0x0, 0x0, 0x29, 0xbf, + 0x15, 0x0, 0x10, 0x92, 0x91, 0x53, 0x3f, 0x24, 0xe0, 0x8, 0x4e, 0x9a, 0x60, 0x92, 0xfd, 0x1a, + 0xba, 0xd5, 0xab, 0x25, 0x5c, 0x8, 0x0, 0x9, 0x72, 0x5c, 0x14, 0xfc, 0x76, 0xb6, 0x2e, 0xdc, + 0x5, 0x23, 0x28, 0xed, 0x19, 0xf2, 0x26, 0x0, 0x19, 0xc4, 0x62, 0x44, 0x92, 0xfe, 0x1e, 0xca, + 0x28, 0xdb, 0x1e, 0x5f, 0x80, 0xa3, 0x90, 0x87, 0xe3, 0xef, 0x4e, 0x83, 0x4, 0x18, 0x8b, 0xc3, + 0xab, 0xa2, 0x0, 0x4, 0x59, 0x23, 0xf3, 0x76, 0x8, 0x0, 0x1c, 0xe3, 0x60, 0x1c, 0xdd, 0xb6, + 0x6c, 0xc6, 0x79, 0x46, 0x80, 0x71, 0x2d, 0x4, 0x17, 0xcc, 0x25, 0x52, 0x41, 0xcb, 0xcf, 0xf, + 0x14, 0xc4, 0x14, 0x90, 0xf8, 0xfd, 0x41, 0x23, 0x42, 0xe, 0x13, 0x11, 0x5a, 0x1a, 0x0, 0x12, + 0x7b, 0x7b, 0xf3, 0xdc, 0x4e, 0x14, 0x6, 0xcb, 0x9a, 0xd1, 0xb1, 0x61, 0xe2, 0x1c, 0x3b, 0xbe, + 0xb0, 0x8a, 0x29, 0x23, 0x27, 0x0, 0x0, 0x38, 0x75, 0x1f, 0x0, 0x2, 0xbb, 0xc7, 0x17, 0x78}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x92, 0x91, 0x53, 0x3f, 0x24, 0xe0, 0x8, 0x4e, + 0x9a, 0x60, 0x92, 0xfd, 0x1a, 0xba, 0xd5, 0xab}; + uint8_t bytesprops1[] = {0x72, 0x5c, 0x14, 0xfc, 0x76, 0xb6, 0x2e, 0xdc, 0x5}; + uint8_t bytesprops3[] = {0x59, 0x23, 0xf3, 0x76}; + uint8_t bytesprops2[] = {0xc4, 0x62, 0x44, 0x92, 0xfe, 0x1e, 0xca, 0x28, 0xdb, 0x1e, 0x5f, 0x80, 0xa3, + 0x90, 0x87, 0xe3, 0xef, 0x4e, 0x83, 0x4, 0x18, 0x8b, 0xc3, 0xab, 0xa2}; + uint8_t bytesprops4[] = {0xe3, 0x60, 0x1c, 0xdd, 0xb6, 0x6c, 0xc6, 0x79, 0x46, 0x80, 0x71, 0x2d, 0x4, 0x17, + 0xcc, 0x25, 0x52, 0x41, 0xcb, 0xcf, 0xf, 0x14, 0xc4, 0x14, 0x90, 0xf8, 0xfd, 0x41}; + uint8_t bytesprops5[] = {0x7b, 0x7b, 0xf3, 0xdc, 0x4e, 0x14, 0x6, 0xcb, 0x9a, + 0xd1, 0xb1, 0x61, 0xe2, 0x1c, 0x3b, 0xbe, 0xb0, 0x8a}; + uint8_t bytesprops6[] = {0xbb, 0xc7}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 4988}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 8}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 10687}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {16, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 92}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {9, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 10477}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 242}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {25, (char*)&bytesprops2}, .v = {4, (char*)&bytesprops3}}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {28, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 16910}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 4442}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {18, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 35}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 14453}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {2, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 120}}, + }; + + lwmqtt_properties_t props = {17, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 149, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoMessageRateTooHigh [] +TEST(Disco5QCTest, Encode19) { + uint8_t pkt[] = {0xe0, 0x2, 0x96, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 150, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoNormalDisconnection [PropTopicAlias 25785,PropResponseTopic +// "&\129,2\231\136c\164\130\b\189",PropPayloadFormatIndicator 186,PropResponseInformation +// "\194y\157M\239\&6;\169A)\189\152 z\SOHk\SUB\240\GS\136\214Nov\155",PropAuthenticationData +// "\211\n\158;\251\219mu\195@\132\227\183\136;\155\234\189" +// "\DC1z\195\138\251\255\251\246\177\&7\ETX\208\215\204\236x\138\134\162\165\135\142'\EM\139",PropMaximumQoS +// 165,PropContentType "\136\240\ACK\ETX~B\223\191\213\199",PropWillDelayInterval 29321,PropAssignedClientIdentifier +// "{'r~6q#\254Jl\214\SOrS\216g\232\171\174\166J\f\227",PropSessionExpiryInterval 32003,PropRequestResponseInformation +// 53,PropAuthenticationData "\131<\143#\\\204\164Lgq\SUBpI\168\SUB\240\157\STX7\ESC",PropServerKeepAlive +// 22451,PropResponseInformation +// "\238H\n\233#J\245\ETBya\189\129\174\227\&0\251\201C\208\187\ENQ\216\172\172\145\252y",PropWillDelayInterval +// 10313,PropServerReference "\248\161\145\a\222m",PropMaximumQoS 33,PropWillDelayInterval +// 14267,PropPayloadFormatIndicator 116,PropRequestProblemInformation 21,PropReasonString +// "\217\&5\FSff\b\227\200z\183\181@-\180\146\160\210\149F]\217Y\218",PropResponseTopic "\166oGm\140\170f7"] +TEST(Disco5QCTest, Encode20) { + uint8_t pkt[] = {0xe0, 0xae, 0x2, 0x0, 0xab, 0x2, 0x23, 0x64, 0xb9, 0x8, 0x0, 0xb, 0x26, 0x81, 0x2c, 0x32, 0xe7, + 0x88, 0x63, 0xa4, 0x82, 0x8, 0xbd, 0x1, 0xba, 0x1a, 0x0, 0x19, 0xc2, 0x79, 0x9d, 0x4d, 0xef, 0x36, + 0x3b, 0xa9, 0x41, 0x29, 0xbd, 0x98, 0x20, 0x7a, 0x1, 0x6b, 0x1a, 0xf0, 0x1d, 0x88, 0xd6, 0x4e, 0x6f, + 0x76, 0x9b, 0x16, 0x0, 0x17, 0xd3, 0xa, 0x9e, 0x3b, 0xfb, 0x3c, 0x6d, 0xc6, 0x72, 0x39, 0xe0, 0xfe, + 0xc3, 0xf9, 0xd7, 0xbd, 0x47, 0x95, 0x73, 0xc8, 0x41, 0xb0, 0xc, 0x18, 0x0, 0x0, 0x3f, 0xea, 0x26, + 0x0, 0x14, 0xea, 0xea, 0x22, 0x39, 0x9f, 0x6a, 0x3e, 0xdb, 0x6d, 0x75, 0xc3, 0x40, 0x84, 0xe3, 0xb7, + 0x88, 0x3b, 0x9b, 0xea, 0xbd, 0x0, 0x19, 0x11, 0x7a, 0xc3, 0x8a, 0xfb, 0xff, 0xfb, 0xf6, 0xb1, 0x37, + 0x3, 0xd0, 0xd7, 0xcc, 0xec, 0x78, 0x8a, 0x86, 0xa2, 0xa5, 0x87, 0x8e, 0x27, 0x19, 0x8b, 0x24, 0xa5, + 0x3, 0x0, 0xa, 0x88, 0xf0, 0x6, 0x3, 0x7e, 0x42, 0xdf, 0xbf, 0xd5, 0xc7, 0x18, 0x0, 0x0, 0x72, + 0x89, 0x12, 0x0, 0x17, 0x7b, 0x27, 0x72, 0x7e, 0x36, 0x71, 0x23, 0xfe, 0x4a, 0x6c, 0xd6, 0xe, 0x72, + 0x53, 0xd8, 0x67, 0xe8, 0xab, 0xae, 0xa6, 0x4a, 0xc, 0xe3, 0x11, 0x0, 0x0, 0x7d, 0x3, 0x19, 0x35, + 0x16, 0x0, 0x14, 0x83, 0x3c, 0x8f, 0x23, 0x5c, 0xcc, 0xa4, 0x4c, 0x67, 0x71, 0x1a, 0x70, 0x49, 0xa8, + 0x1a, 0xf0, 0x9d, 0x2, 0x37, 0x1b, 0x13, 0x57, 0xb3, 0x1a, 0x0, 0x1b, 0xee, 0x48, 0xa, 0xe9, 0x23, + 0x4a, 0xf5, 0x17, 0x79, 0x61, 0xbd, 0x81, 0xae, 0xe3, 0x30, 0xfb, 0xc9, 0x43, 0xd0, 0xbb, 0x5, 0xd8, + 0xac, 0xac, 0x91, 0xfc, 0x79, 0x18, 0x0, 0x0, 0x28, 0x49, 0x1c, 0x0, 0x6, 0xf8, 0xa1, 0x91, 0x7, + 0xde, 0x6d, 0x24, 0x21, 0x18, 0x0, 0x0, 0x37, 0xbb, 0x1, 0x74, 0x17, 0x15, 0x1f, 0x0, 0x17, 0xd9, + 0x35, 0x1c, 0x66, 0x66, 0x8, 0xe3, 0xc8, 0x7a, 0xb7, 0xb5, 0x40, 0x2d, 0xb4, 0x92, 0xa0, 0xd2, 0x95, + 0x46, 0x5d, 0xd9, 0x59, 0xda, 0x8, 0x0, 0x8, 0xa6, 0x6f, 0x47, 0x6d, 0x8c, 0xaa, 0x66, 0x37}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x26, 0x81, 0x2c, 0x32, 0xe7, 0x88, 0x63, 0xa4, 0x82, 0x8, 0xbd}; + uint8_t bytesprops1[] = {0xc2, 0x79, 0x9d, 0x4d, 0xef, 0x36, 0x3b, 0xa9, 0x41, 0x29, 0xbd, 0x98, 0x20, + 0x7a, 0x1, 0x6b, 0x1a, 0xf0, 0x1d, 0x88, 0xd6, 0x4e, 0x6f, 0x76, 0x9b}; + uint8_t bytesprops2[] = {0xd3, 0xa, 0x9e, 0x3b, 0xfb, 0x3c, 0x6d, 0xc6, 0x72, 0x39, 0xe0, 0xfe, + 0xc3, 0xf9, 0xd7, 0xbd, 0x47, 0x95, 0x73, 0xc8, 0x41, 0xb0, 0xc}; + uint8_t bytesprops4[] = {0x11, 0x7a, 0xc3, 0x8a, 0xfb, 0xff, 0xfb, 0xf6, 0xb1, 0x37, 0x3, 0xd0, 0xd7, + 0xcc, 0xec, 0x78, 0x8a, 0x86, 0xa2, 0xa5, 0x87, 0x8e, 0x27, 0x19, 0x8b}; + uint8_t bytesprops3[] = {0xea, 0xea, 0x22, 0x39, 0x9f, 0x6a, 0x3e, 0xdb, 0x6d, 0x75, + 0xc3, 0x40, 0x84, 0xe3, 0xb7, 0x88, 0x3b, 0x9b, 0xea, 0xbd}; + uint8_t bytesprops5[] = {0x88, 0xf0, 0x6, 0x3, 0x7e, 0x42, 0xdf, 0xbf, 0xd5, 0xc7}; + uint8_t bytesprops6[] = {0x7b, 0x27, 0x72, 0x7e, 0x36, 0x71, 0x23, 0xfe, 0x4a, 0x6c, 0xd6, 0xe, + 0x72, 0x53, 0xd8, 0x67, 0xe8, 0xab, 0xae, 0xa6, 0x4a, 0xc, 0xe3}; + uint8_t bytesprops7[] = {0x83, 0x3c, 0x8f, 0x23, 0x5c, 0xcc, 0xa4, 0x4c, 0x67, 0x71, + 0x1a, 0x70, 0x49, 0xa8, 0x1a, 0xf0, 0x9d, 0x2, 0x37, 0x1b}; + uint8_t bytesprops8[] = {0xee, 0x48, 0xa, 0xe9, 0x23, 0x4a, 0xf5, 0x17, 0x79, 0x61, 0xbd, 0x81, 0xae, 0xe3, + 0x30, 0xfb, 0xc9, 0x43, 0xd0, 0xbb, 0x5, 0xd8, 0xac, 0xac, 0x91, 0xfc, 0x79}; + uint8_t bytesprops9[] = {0xf8, 0xa1, 0x91, 0x7, 0xde, 0x6d}; + uint8_t bytesprops10[] = {0xd9, 0x35, 0x1c, 0x66, 0x66, 0x8, 0xe3, 0xc8, 0x7a, 0xb7, 0xb5, 0x40, + 0x2d, 0xb4, 0x92, 0xa0, 0xd2, 0x95, 0x46, 0x5d, 0xd9, 0x59, 0xda}; + uint8_t bytesprops11[] = {0xa6, 0x6f, 0x47, 0x6d, 0x8c, 0xaa, 0x66, 0x37}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 25785}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {11, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 186}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {25, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {23, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 16362}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {20, (char*)&bytesprops3}, .v = {25, (char*)&bytesprops4}}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 165}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {10, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 29321}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {23, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 32003}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 53}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {20, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 22451}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {27, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 10313}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {6, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 33}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 14267}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 116}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 21}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {23, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {8, (char*)&bytesprops11}}}, + }; + + lwmqtt_properties_t props = {24, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoSubscriptionIdentifiersNotSupported [PropMaximumQoS 222,PropMessageExpiryInterval +// 6333,PropSessionExpiryInterval 6463,PropServerReference +// "\146G.T\225L!\255N\CAN\238\186\&1\RS\254\&5\r\153L\188\DLE\219\142wq\t",PropPayloadFormatIndicator +// 9,PropRequestProblemInformation 19,PropTopicAliasMaximum 32175,PropResponseTopic +// "\"\FS\b\SO\234\&4\252^/\155\213C\247\231",PropMessageExpiryInterval 22063,PropMaximumPacketSize +// 8213,PropWildcardSubscriptionAvailable 12,PropTopicAliasMaximum 24294,PropRequestProblemInformation +// 140,PropAssignedClientIdentifier +// "\143\215zR?\238\199\193\167w.\199\209\206\164}\192\153U\150M\128\225\174\162\DEL",PropServerKeepAlive +// 29091,PropResponseTopic "\195\STX$\\\218\SI\151)\148I\t\134\&6\239A\SO +// \ETX\205\196w\218",PropRequestResponseInformation 196,PropResponseTopic +// "\SOH\191\185\DEL\179\SUB\146\249\174\241\&9\234\ENQ=\223\&0\STX\178T\220\158",PropResponseTopic +// "\248\143\NAK|pP",PropTopicAliasMaximum 28364,PropReasonString "hHB\158\160Za\200",PropSessionExpiryInterval 11996] +TEST(Disco5QCTest, Encode21) { + uint8_t pkt[] = {0xe0, 0xc4, 0x1, 0xa1, 0xc1, 0x1, 0x24, 0xde, 0x2, 0x0, 0x0, 0x18, 0xbd, 0x11, 0x0, 0x0, 0x19, + 0x3f, 0x1c, 0x0, 0x1a, 0x92, 0x47, 0x2e, 0x54, 0xe1, 0x4c, 0x21, 0xff, 0x4e, 0x18, 0xee, 0xba, 0x31, + 0x1e, 0xfe, 0x35, 0xd, 0x99, 0x4c, 0xbc, 0x10, 0xdb, 0x8e, 0x77, 0x71, 0x9, 0x1, 0x9, 0x17, 0x13, + 0x22, 0x7d, 0xaf, 0x8, 0x0, 0xe, 0x22, 0x1c, 0x8, 0xe, 0xea, 0x34, 0xfc, 0x5e, 0x2f, 0x9b, 0xd5, + 0x43, 0xf7, 0xe7, 0x2, 0x0, 0x0, 0x56, 0x2f, 0x27, 0x0, 0x0, 0x20, 0x15, 0x28, 0xc, 0x22, 0x5e, + 0xe6, 0x17, 0x8c, 0x12, 0x0, 0x1a, 0x8f, 0xd7, 0x7a, 0x52, 0x3f, 0xee, 0xc7, 0xc1, 0xa7, 0x77, 0x2e, + 0xc7, 0xd1, 0xce, 0xa4, 0x7d, 0xc0, 0x99, 0x55, 0x96, 0x4d, 0x80, 0xe1, 0xae, 0xa2, 0x7f, 0x13, 0x71, + 0xa3, 0x8, 0x0, 0x16, 0xc3, 0x2, 0x24, 0x5c, 0xda, 0xf, 0x97, 0x29, 0x94, 0x49, 0x9, 0x86, 0x36, + 0xef, 0x41, 0xe, 0x20, 0x3, 0xcd, 0xc4, 0x77, 0xda, 0x19, 0xc4, 0x8, 0x0, 0x15, 0x1, 0xbf, 0xb9, + 0x7f, 0xb3, 0x1a, 0x92, 0xf9, 0xae, 0xf1, 0x39, 0xea, 0x5, 0x3d, 0xdf, 0x30, 0x2, 0xb2, 0x54, 0xdc, + 0x9e, 0x8, 0x0, 0x6, 0xf8, 0x8f, 0x15, 0x7c, 0x70, 0x50, 0x22, 0x6e, 0xcc, 0x1f, 0x0, 0x8, 0x68, + 0x48, 0x42, 0x9e, 0xa0, 0x5a, 0x61, 0xc8, 0x11, 0x0, 0x0, 0x2e, 0xdc}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x92, 0x47, 0x2e, 0x54, 0xe1, 0x4c, 0x21, 0xff, 0x4e, 0x18, 0xee, 0xba, 0x31, + 0x1e, 0xfe, 0x35, 0xd, 0x99, 0x4c, 0xbc, 0x10, 0xdb, 0x8e, 0x77, 0x71, 0x9}; + uint8_t bytesprops1[] = {0x22, 0x1c, 0x8, 0xe, 0xea, 0x34, 0xfc, 0x5e, 0x2f, 0x9b, 0xd5, 0x43, 0xf7, 0xe7}; + uint8_t bytesprops2[] = {0x8f, 0xd7, 0x7a, 0x52, 0x3f, 0xee, 0xc7, 0xc1, 0xa7, 0x77, 0x2e, 0xc7, 0xd1, + 0xce, 0xa4, 0x7d, 0xc0, 0x99, 0x55, 0x96, 0x4d, 0x80, 0xe1, 0xae, 0xa2, 0x7f}; + uint8_t bytesprops3[] = {0xc3, 0x2, 0x24, 0x5c, 0xda, 0xf, 0x97, 0x29, 0x94, 0x49, 0x9, + 0x86, 0x36, 0xef, 0x41, 0xe, 0x20, 0x3, 0xcd, 0xc4, 0x77, 0xda}; + uint8_t bytesprops4[] = {0x1, 0xbf, 0xb9, 0x7f, 0xb3, 0x1a, 0x92, 0xf9, 0xae, 0xf1, 0x39, + 0xea, 0x5, 0x3d, 0xdf, 0x30, 0x2, 0xb2, 0x54, 0xdc, 0x9e}; + uint8_t bytesprops5[] = {0xf8, 0x8f, 0x15, 0x7c, 0x70, 0x50}; + uint8_t bytesprops6[] = {0x68, 0x48, 0x42, 0x9e, 0xa0, 0x5a, 0x61, 0xc8}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 222}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 6333}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 6463}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {26, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 9}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 19}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 32175}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {14, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 22063}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 8213}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 12}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 24294}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 140}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {26, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 29091}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {22, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 196}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {21, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {6, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 28364}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {8, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 11996}}, + }; + + lwmqtt_properties_t props = {22, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 161, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoSubscriptionIdentifiersNotSupported [PropSubscriptionIdentifier 18,PropCorrelationData +// "\226\CAN\153\168-\DLE}\NUL\200\&6\242\EM\170J\t\176o\a\175\164",PropUserProperty "\129\156\226\171 +// \223\EMn\187\CAN?:\GS\243)?\239\SOHj" "c6u\DC3?L!\243\221$",PropSubscriptionIdentifier 19,PropContentType +// "\177\146\254\174\DLE (\235D\146",PropTopicAliasMaximum 16812,PropTopicAliasMaximum 10572,PropMessageExpiryInterval +// 14029] +TEST(Disco5QCTest, Encode22) { + uint8_t pkt[] = {0xe0, 0x57, 0xa1, 0x55, 0xb, 0x12, 0x9, 0x0, 0x14, 0xe2, 0x18, 0x99, 0xa8, 0x2d, 0x10, + 0x7d, 0x0, 0xc8, 0x36, 0xf2, 0x19, 0xaa, 0x4a, 0x9, 0xb0, 0x6f, 0x7, 0xaf, 0xa4, 0x26, + 0x0, 0x13, 0x81, 0x9c, 0xe2, 0xab, 0x20, 0xdf, 0x19, 0x6e, 0xbb, 0x18, 0x3f, 0x3a, 0x1d, + 0xf3, 0x29, 0x3f, 0xef, 0x1, 0x6a, 0x0, 0xa, 0x63, 0x36, 0x75, 0x13, 0x3f, 0x4c, 0x21, + 0xf3, 0xdd, 0x24, 0xb, 0x13, 0x3, 0x0, 0xa, 0xb1, 0x92, 0xfe, 0xae, 0x10, 0x20, 0x28, + 0xeb, 0x44, 0x92, 0x22, 0x41, 0xac, 0x22, 0x29, 0x4c, 0x2, 0x0, 0x0, 0x36, 0xcd}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xe2, 0x18, 0x99, 0xa8, 0x2d, 0x10, 0x7d, 0x0, 0xc8, 0x36, + 0xf2, 0x19, 0xaa, 0x4a, 0x9, 0xb0, 0x6f, 0x7, 0xaf, 0xa4}; + uint8_t bytesprops2[] = {0x63, 0x36, 0x75, 0x13, 0x3f, 0x4c, 0x21, 0xf3, 0xdd, 0x24}; + uint8_t bytesprops1[] = {0x81, 0x9c, 0xe2, 0xab, 0x20, 0xdf, 0x19, 0x6e, 0xbb, 0x18, + 0x3f, 0x3a, 0x1d, 0xf3, 0x29, 0x3f, 0xef, 0x1, 0x6a}; + uint8_t bytesprops3[] = {0xb1, 0x92, 0xfe, 0xae, 0x10, 0x20, 0x28, 0xeb, 0x44, 0x92}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 18}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {20, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {19, (char*)&bytesprops1}, .v = {10, (char*)&bytesprops2}}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 19}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {10, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 16812}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 10572}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 14029}}, + }; + + lwmqtt_properties_t props = {8, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 161, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoTopicNameInvalid [PropCorrelationData +// "g<:\200\251\252\136\153\GS\222\166}\175x0@i\164_W(\177\213",PropSubscriptionIdentifier 8,PropMessageExpiryInterval +// 25949,PropCorrelationData "\157|@\164x\239\231\187\US\156\181 {\246Cv\EM|@\213\245\140x",PropWillDelayInterval +// 5293,PropUserProperty "" "[s>v\vR\167<\SUB5\241\202",PropContentType +// "\154\ETX\225\n\203\242\n\186r\v\221\191;\235HY\174,\178\152\234\226\165\205\194k\187Q\249",PropAuthenticationMethod +// "\DEL\150Y",PropAssignedClientIdentifier ":\SOH\187\185\&9m\142\185\SO",PropServerReference +// "\160\EMp[-'\220\168(\230\SOH0p\133%=",PropReceiveMaximum 27055,PropSharedSubscriptionAvailable +// 150,PropRequestProblemInformation 244,PropAuthenticationMethod "",PropWillDelayInterval 9374,PropMaximumQoS +// 39,PropWildcardSubscriptionAvailable 223] +TEST(Disco5QCTest, Encode23) { + uint8_t pkt[] = {0xe0, 0xac, 0x1, 0x90, 0xa9, 0x1, 0x9, 0x0, 0x17, 0x67, 0x3c, 0x3a, 0xc8, 0xfb, 0xfc, 0x88, + 0x99, 0x1d, 0xde, 0xa6, 0x7d, 0xaf, 0x78, 0x30, 0x40, 0x69, 0xa4, 0x5f, 0x57, 0x28, 0xb1, 0xd5, + 0xb, 0x8, 0x2, 0x0, 0x0, 0x65, 0x5d, 0x9, 0x0, 0x17, 0x9d, 0x7c, 0x40, 0xa4, 0x78, 0xef, + 0xe7, 0xbb, 0x1f, 0x9c, 0xb5, 0x20, 0x7b, 0xf6, 0x43, 0x76, 0x19, 0x7c, 0x40, 0xd5, 0xf5, 0x8c, + 0x78, 0x18, 0x0, 0x0, 0x14, 0xad, 0x26, 0x0, 0x0, 0x0, 0xc, 0x5b, 0x73, 0x3e, 0x76, 0xb, + 0x52, 0xa7, 0x3c, 0x1a, 0x35, 0xf1, 0xca, 0x3, 0x0, 0x1d, 0x9a, 0x3, 0xe1, 0xa, 0xcb, 0xf2, + 0xa, 0xba, 0x72, 0xb, 0xdd, 0xbf, 0x3b, 0xeb, 0x48, 0x59, 0xae, 0x2c, 0xb2, 0x98, 0xea, 0xe2, + 0xa5, 0xcd, 0xc2, 0x6b, 0xbb, 0x51, 0xf9, 0x15, 0x0, 0x3, 0x7f, 0x96, 0x59, 0x12, 0x0, 0x9, + 0x3a, 0x1, 0xbb, 0xb9, 0x39, 0x6d, 0x8e, 0xb9, 0xe, 0x1c, 0x0, 0x10, 0xa0, 0x19, 0x70, 0x5b, + 0x2d, 0x27, 0xdc, 0xa8, 0x28, 0xe6, 0x1, 0x30, 0x70, 0x85, 0x25, 0x3d, 0x21, 0x69, 0xaf, 0x2a, + 0x96, 0x17, 0xf4, 0x15, 0x0, 0x0, 0x18, 0x0, 0x0, 0x24, 0x9e, 0x24, 0x27, 0x28, 0xdf}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x67, 0x3c, 0x3a, 0xc8, 0xfb, 0xfc, 0x88, 0x99, 0x1d, 0xde, 0xa6, 0x7d, + 0xaf, 0x78, 0x30, 0x40, 0x69, 0xa4, 0x5f, 0x57, 0x28, 0xb1, 0xd5}; + uint8_t bytesprops1[] = {0x9d, 0x7c, 0x40, 0xa4, 0x78, 0xef, 0xe7, 0xbb, 0x1f, 0x9c, 0xb5, 0x20, + 0x7b, 0xf6, 0x43, 0x76, 0x19, 0x7c, 0x40, 0xd5, 0xf5, 0x8c, 0x78}; + uint8_t bytesprops3[] = {0x5b, 0x73, 0x3e, 0x76, 0xb, 0x52, 0xa7, 0x3c, 0x1a, 0x35, 0xf1, 0xca}; + uint8_t bytesprops2[] = {0}; + uint8_t bytesprops4[] = {0x9a, 0x3, 0xe1, 0xa, 0xcb, 0xf2, 0xa, 0xba, 0x72, 0xb, 0xdd, 0xbf, 0x3b, 0xeb, 0x48, + 0x59, 0xae, 0x2c, 0xb2, 0x98, 0xea, 0xe2, 0xa5, 0xcd, 0xc2, 0x6b, 0xbb, 0x51, 0xf9}; + uint8_t bytesprops5[] = {0x7f, 0x96, 0x59}; + uint8_t bytesprops6[] = {0x3a, 0x1, 0xbb, 0xb9, 0x39, 0x6d, 0x8e, 0xb9, 0xe}; + uint8_t bytesprops7[] = {0xa0, 0x19, 0x70, 0x5b, 0x2d, 0x27, 0xdc, 0xa8, + 0x28, 0xe6, 0x1, 0x30, 0x70, 0x85, 0x25, 0x3d}; + uint8_t bytesprops8[] = {0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)9, .value = {.str = {23, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 8}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 25949}}, + {.prop = (lwmqtt_prop_t)9, .value = {.str = {23, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 5293}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {0, (char*)&bytesprops2}, .v = {12, (char*)&bytesprops3}}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {29, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {3, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {9, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {16, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 27055}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 150}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 244}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {0, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 9374}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 39}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 223}}, + }; + + lwmqtt_properties_t props = {17, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 144, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoQoSNotSupported [PropMessageExpiryInterval 8720,PropReceiveMaximum +// 31958,PropMessageExpiryInterval 31814,PropMessageExpiryInterval 24040,PropSubscriptionIdentifier 2] +TEST(Disco5QCTest, Encode24) { + uint8_t pkt[] = {0xe0, 0x16, 0x9b, 0x14, 0x2, 0x0, 0x0, 0x22, 0x10, 0x21, 0x7c, 0xd6, + 0x2, 0x0, 0x0, 0x7c, 0x46, 0x2, 0x0, 0x0, 0x5d, 0xe8, 0xb, 0x2}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 8720}}, {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 31958}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 31814}}, {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 24040}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 2}}, + }; + + lwmqtt_properties_t props = {5, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 155, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoMalformedPacket [PropRequestResponseInformation 156,PropMaximumPacketSize 26033,PropTopicAlias +// 30140,PropReasonString "G",PropSubscriptionIdentifierAvailable 12,PropSessionExpiryInterval 861,PropReceiveMaximum +// 6155,PropWillDelayInterval 6406,PropTopicAlias 27382,PropResponseInformation +// "!\214\198CVw\194\239\154\255\&3UK\DC2",PropWildcardSubscriptionAvailable 94,PropSubscriptionIdentifier +// 23,PropResponseInformation +// "S\162\211\150\142\241>.g\248\174\216\206\173\200\131\246]\202U\166Bj\DC1",PropMessageExpiryInterval +// 15853,PropRequestResponseInformation 142,PropSessionExpiryInterval 21968,PropAssignedClientIdentifier +// "\165\244\ETB*\144\241\&7\137\ENQ0p\178`\DC2\131\CAN\ETB",PropRetainAvailable 229,PropAuthenticationMethod +// "\158\194\191\227\234CE\237\179\173f\206\221",PropWildcardSubscriptionAvailable 5,PropAuthenticationMethod +// "\CANc:\211\239\217\234\255\SOJ\ACK\223\189\147\ETB\EM\191\254\SOH N\188e\204\149\132\152",PropServerReference +// "\194\RS\189\&0\200U\147\178-\252\229\159\152erp\174&\167|\n7G\194\244\190\233\&9",PropWildcardSubscriptionAvailable +// 252,PropMessageExpiryInterval 31094,PropAuthenticationData "7*\241#",PropTopicAliasMaximum 20164] +TEST(Disco5QCTest, Encode25) { + uint8_t pkt[] = {0xe0, 0xd5, 0x1, 0x81, 0xd2, 0x1, 0x19, 0x9c, 0x27, 0x0, 0x0, 0x65, 0xb1, 0x23, 0x75, 0xbc, 0x1f, + 0x0, 0x1, 0x47, 0x29, 0xc, 0x11, 0x0, 0x0, 0x3, 0x5d, 0x21, 0x18, 0xb, 0x18, 0x0, 0x0, 0x19, + 0x6, 0x23, 0x6a, 0xf6, 0x1a, 0x0, 0xe, 0x21, 0xd6, 0xc6, 0x43, 0x56, 0x77, 0xc2, 0xef, 0x9a, 0xff, + 0x33, 0x55, 0x4b, 0x12, 0x28, 0x5e, 0xb, 0x17, 0x1a, 0x0, 0x18, 0x53, 0xa2, 0xd3, 0x96, 0x8e, 0xf1, + 0x3e, 0x2e, 0x67, 0xf8, 0xae, 0xd8, 0xce, 0xad, 0xc8, 0x83, 0xf6, 0x5d, 0xca, 0x55, 0xa6, 0x42, 0x6a, + 0x11, 0x2, 0x0, 0x0, 0x3d, 0xed, 0x19, 0x8e, 0x11, 0x0, 0x0, 0x55, 0xd0, 0x12, 0x0, 0x11, 0xa5, + 0xf4, 0x17, 0x2a, 0x90, 0xf1, 0x37, 0x89, 0x5, 0x30, 0x70, 0xb2, 0x60, 0x12, 0x83, 0x18, 0x17, 0x25, + 0xe5, 0x15, 0x0, 0xd, 0x9e, 0xc2, 0xbf, 0xe3, 0xea, 0x43, 0x45, 0xed, 0xb3, 0xad, 0x66, 0xce, 0xdd, + 0x28, 0x5, 0x15, 0x0, 0x1b, 0x18, 0x63, 0x3a, 0xd3, 0xef, 0xd9, 0xea, 0xff, 0xe, 0x4a, 0x6, 0xdf, + 0xbd, 0x93, 0x17, 0x19, 0xbf, 0xfe, 0x1, 0x20, 0x4e, 0xbc, 0x65, 0xcc, 0x95, 0x84, 0x98, 0x1c, 0x0, + 0x1c, 0xc2, 0x1e, 0xbd, 0x30, 0xc8, 0x55, 0x93, 0xb2, 0x2d, 0xfc, 0xe5, 0x9f, 0x98, 0x65, 0x72, 0x70, + 0xae, 0x26, 0xa7, 0x7c, 0xa, 0x37, 0x47, 0xc2, 0xf4, 0xbe, 0xe9, 0x39, 0x28, 0xfc, 0x2, 0x0, 0x0, + 0x79, 0x76, 0x16, 0x0, 0x4, 0x37, 0x2a, 0xf1, 0x23, 0x22, 0x4e, 0xc4}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x47}; + uint8_t bytesprops1[] = {0x21, 0xd6, 0xc6, 0x43, 0x56, 0x77, 0xc2, 0xef, 0x9a, 0xff, 0x33, 0x55, 0x4b, 0x12}; + uint8_t bytesprops2[] = {0x53, 0xa2, 0xd3, 0x96, 0x8e, 0xf1, 0x3e, 0x2e, 0x67, 0xf8, 0xae, 0xd8, + 0xce, 0xad, 0xc8, 0x83, 0xf6, 0x5d, 0xca, 0x55, 0xa6, 0x42, 0x6a, 0x11}; + uint8_t bytesprops3[] = {0xa5, 0xf4, 0x17, 0x2a, 0x90, 0xf1, 0x37, 0x89, 0x5, + 0x30, 0x70, 0xb2, 0x60, 0x12, 0x83, 0x18, 0x17}; + uint8_t bytesprops4[] = {0x9e, 0xc2, 0xbf, 0xe3, 0xea, 0x43, 0x45, 0xed, 0xb3, 0xad, 0x66, 0xce, 0xdd}; + uint8_t bytesprops5[] = {0x18, 0x63, 0x3a, 0xd3, 0xef, 0xd9, 0xea, 0xff, 0xe, 0x4a, 0x6, 0xdf, 0xbd, 0x93, + 0x17, 0x19, 0xbf, 0xfe, 0x1, 0x20, 0x4e, 0xbc, 0x65, 0xcc, 0x95, 0x84, 0x98}; + uint8_t bytesprops6[] = {0xc2, 0x1e, 0xbd, 0x30, 0xc8, 0x55, 0x93, 0xb2, 0x2d, 0xfc, 0xe5, 0x9f, 0x98, 0x65, + 0x72, 0x70, 0xae, 0x26, 0xa7, 0x7c, 0xa, 0x37, 0x47, 0xc2, 0xf4, 0xbe, 0xe9, 0x39}; + uint8_t bytesprops7[] = {0x37, 0x2a, 0xf1, 0x23}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 156}}, + {.prop = (lwmqtt_prop_t)39, .value = {.int32 = 26033}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 30140}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {1, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 12}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 861}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 6155}}, + {.prop = (lwmqtt_prop_t)24, .value = {.int32 = 6406}}, + {.prop = (lwmqtt_prop_t)35, .value = {.int16 = 27382}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {14, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 94}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 23}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {24, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 15853}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 142}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 21968}}, + {.prop = (lwmqtt_prop_t)18, .value = {.str = {17, (char*)&bytesprops3}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 229}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {13, (char*)&bytesprops4}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 5}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {27, (char*)&bytesprops5}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {28, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)40, .value = {.byte = 252}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 31094}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {4, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 20164}}, + }; + + lwmqtt_properties_t props = {26, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 129, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoNormalDisconnection [PropAssignedClientIdentifier +// "\ACK\tz\190\DC4\207y\by\201\235\129\145\253\169\231\251\132\148\231\233\&3\217\a",PropContentType +// "",PropUserProperty ")\188\173\181w|^\194+\210/\244\214E%'1*\132\203\NUL" +// "\216\241\222\RS\202H\223\172\214\180d\241p\175Z\DC3#B\183\ESC\GS",PropSessionExpiryInterval 16122,PropReceiveMaximum +// 24484,PropPayloadFormatIndicator 156,PropMessageExpiryInterval 32214,PropTopicAliasMaximum 11695,PropUserProperty +// "\SYN\176R\vjH\131\229p\246\193&A\131\148P\DEL3\171@\DC3k\178\SOH\222\ENQz" +// "\EM\250%\162\189\176n\238\184\235\194MqO\163\168\f\174<\192\217\171",PropReasonString "J\SYN",PropServerReference +// "\DC2\200In\185\170\188\170y|R\252\182A+*\244R\201\165\211",PropResponseInformation +// "\196\181n+\172/\171c\RS\231HyjK\ENQ\CAN\NAKJDN\132\170$\138&\147\134\154\189",PropSharedSubscriptionAvailable +// 88,PropMessageExpiryInterval 3069,PropSubscriptionIdentifier 13,PropRequestResponseInformation +// 117,PropAuthenticationData "Wu/\194\213\237\167\252\251g\185<\244\GS]",PropMessageExpiryInterval 1148,PropMaximumQoS +// 206,PropAuthenticationData "\153\134\GS\184\161*6M\143\192b,\224\EOT\232\GS\181rZ\172\208",PropRetainAvailable +// 56,PropServerKeepAlive 6281,PropResponseInformation "LZ\233\221\205\r1oQ\a0;\247\204\166=<\NUL\EM",PropReasonString +// "\190\226\181\151\128\vC~qZ\187\216\189\224\202",PropAuthenticationMethod +// "\213\242\150\235b\149\155\"\151\246\ENQ\239",PropRequestProblemInformation 146,PropSharedSubscriptionAvailable +// 34,PropPayloadFormatIndicator 230,PropMessageExpiryInterval 16918,PropTopicAliasMaximum 16975] +TEST(Disco5QCTest, Encode26) { + uint8_t pkt[] = { + 0xe0, 0xdb, 0x2, 0x0, 0xd8, 0x2, 0x12, 0x0, 0x18, 0x6, 0x9, 0x7a, 0xbe, 0x14, 0xcf, 0x79, 0x8, 0x79, 0xc9, + 0xeb, 0x81, 0x91, 0xfd, 0xa9, 0xe7, 0xfb, 0x84, 0x94, 0xe7, 0xe9, 0x33, 0xd9, 0x7, 0x3, 0x0, 0x0, 0x26, 0x0, + 0x15, 0x29, 0xbc, 0xad, 0xb5, 0x77, 0x7c, 0x5e, 0xc2, 0x2b, 0xd2, 0x2f, 0xf4, 0xd6, 0x45, 0x25, 0x27, 0x31, 0x2a, + 0x84, 0xcb, 0x0, 0x0, 0x15, 0xd8, 0xf1, 0xde, 0x1e, 0xca, 0x48, 0xdf, 0xac, 0xd6, 0xb4, 0x64, 0xf1, 0x70, 0xaf, + 0x5a, 0x13, 0x23, 0x42, 0xb7, 0x1b, 0x1d, 0x11, 0x0, 0x0, 0x3e, 0xfa, 0x21, 0x5f, 0xa4, 0x1, 0x9c, 0x2, 0x0, + 0x0, 0x7d, 0xd6, 0x22, 0x2d, 0xaf, 0x26, 0x0, 0x1b, 0x16, 0xb0, 0x52, 0xb, 0x6a, 0x48, 0x83, 0xe5, 0x70, 0xf6, + 0xc1, 0x26, 0x41, 0x83, 0x94, 0x50, 0x7f, 0x33, 0xab, 0x40, 0x13, 0x6b, 0xb2, 0x1, 0xde, 0x5, 0x7a, 0x0, 0x16, + 0x19, 0xfa, 0x25, 0xa2, 0xbd, 0xb0, 0x6e, 0xee, 0xb8, 0xeb, 0xc2, 0x4d, 0x71, 0x4f, 0xa3, 0xa8, 0xc, 0xae, 0x3c, + 0xc0, 0xd9, 0xab, 0x1f, 0x0, 0x2, 0x4a, 0x16, 0x1c, 0x0, 0x15, 0x12, 0xc8, 0x49, 0x6e, 0xb9, 0xaa, 0xbc, 0xaa, + 0x79, 0x7c, 0x52, 0xfc, 0xb6, 0x41, 0x2b, 0x2a, 0xf4, 0x52, 0xc9, 0xa5, 0xd3, 0x1a, 0x0, 0x1d, 0xc4, 0xb5, 0x6e, + 0x2b, 0xac, 0x2f, 0xab, 0x63, 0x1e, 0xe7, 0x48, 0x79, 0x6a, 0x4b, 0x5, 0x18, 0x15, 0x4a, 0x44, 0x4e, 0x84, 0xaa, + 0x24, 0x8a, 0x26, 0x93, 0x86, 0x9a, 0xbd, 0x2a, 0x58, 0x2, 0x0, 0x0, 0xb, 0xfd, 0xb, 0xd, 0x19, 0x75, 0x16, + 0x0, 0xf, 0x57, 0x75, 0x2f, 0xc2, 0xd5, 0xed, 0xa7, 0xfc, 0xfb, 0x67, 0xb9, 0x3c, 0xf4, 0x1d, 0x5d, 0x2, 0x0, + 0x0, 0x4, 0x7c, 0x24, 0xce, 0x16, 0x0, 0x15, 0x99, 0x86, 0x1d, 0xb8, 0xa1, 0x2a, 0x36, 0x4d, 0x8f, 0xc0, 0x62, + 0x2c, 0xe0, 0x4, 0xe8, 0x1d, 0xb5, 0x72, 0x5a, 0xac, 0xd0, 0x25, 0x38, 0x13, 0x18, 0x89, 0x1a, 0x0, 0x13, 0x4c, + 0x5a, 0xe9, 0xdd, 0xcd, 0xd, 0x31, 0x6f, 0x51, 0x7, 0x30, 0x3b, 0xf7, 0xcc, 0xa6, 0x3d, 0x3c, 0x0, 0x19, 0x1f, + 0x0, 0xf, 0xbe, 0xe2, 0xb5, 0x97, 0x80, 0xb, 0x43, 0x7e, 0x71, 0x5a, 0xbb, 0xd8, 0xbd, 0xe0, 0xca, 0x15, 0x0, + 0xc, 0xd5, 0xf2, 0x96, 0xeb, 0x62, 0x95, 0x9b, 0x22, 0x97, 0xf6, 0x5, 0xef, 0x17, 0x92, 0x2a, 0x22, 0x1, 0xe6, + 0x2, 0x0, 0x0, 0x42, 0x16, 0x22, 0x42, 0x4f}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x6, 0x9, 0x7a, 0xbe, 0x14, 0xcf, 0x79, 0x8, 0x79, 0xc9, 0xeb, 0x81, + 0x91, 0xfd, 0xa9, 0xe7, 0xfb, 0x84, 0x94, 0xe7, 0xe9, 0x33, 0xd9, 0x7}; + uint8_t bytesprops1[] = {0}; + uint8_t bytesprops3[] = {0xd8, 0xf1, 0xde, 0x1e, 0xca, 0x48, 0xdf, 0xac, 0xd6, 0xb4, 0x64, + 0xf1, 0x70, 0xaf, 0x5a, 0x13, 0x23, 0x42, 0xb7, 0x1b, 0x1d}; + uint8_t bytesprops2[] = {0x29, 0xbc, 0xad, 0xb5, 0x77, 0x7c, 0x5e, 0xc2, 0x2b, 0xd2, 0x2f, + 0xf4, 0xd6, 0x45, 0x25, 0x27, 0x31, 0x2a, 0x84, 0xcb, 0x0}; + uint8_t bytesprops5[] = {0x19, 0xfa, 0x25, 0xa2, 0xbd, 0xb0, 0x6e, 0xee, 0xb8, 0xeb, 0xc2, + 0x4d, 0x71, 0x4f, 0xa3, 0xa8, 0xc, 0xae, 0x3c, 0xc0, 0xd9, 0xab}; + uint8_t bytesprops4[] = {0x16, 0xb0, 0x52, 0xb, 0x6a, 0x48, 0x83, 0xe5, 0x70, 0xf6, 0xc1, 0x26, 0x41, 0x83, + 0x94, 0x50, 0x7f, 0x33, 0xab, 0x40, 0x13, 0x6b, 0xb2, 0x1, 0xde, 0x5, 0x7a}; + uint8_t bytesprops6[] = {0x4a, 0x16}; + uint8_t bytesprops7[] = {0x12, 0xc8, 0x49, 0x6e, 0xb9, 0xaa, 0xbc, 0xaa, 0x79, 0x7c, 0x52, + 0xfc, 0xb6, 0x41, 0x2b, 0x2a, 0xf4, 0x52, 0xc9, 0xa5, 0xd3}; + uint8_t bytesprops8[] = {0xc4, 0xb5, 0x6e, 0x2b, 0xac, 0x2f, 0xab, 0x63, 0x1e, 0xe7, 0x48, 0x79, 0x6a, 0x4b, 0x5, + 0x18, 0x15, 0x4a, 0x44, 0x4e, 0x84, 0xaa, 0x24, 0x8a, 0x26, 0x93, 0x86, 0x9a, 0xbd}; + uint8_t bytesprops9[] = {0x57, 0x75, 0x2f, 0xc2, 0xd5, 0xed, 0xa7, 0xfc, 0xfb, 0x67, 0xb9, 0x3c, 0xf4, 0x1d, 0x5d}; + uint8_t bytesprops10[] = {0x99, 0x86, 0x1d, 0xb8, 0xa1, 0x2a, 0x36, 0x4d, 0x8f, 0xc0, 0x62, + 0x2c, 0xe0, 0x4, 0xe8, 0x1d, 0xb5, 0x72, 0x5a, 0xac, 0xd0}; + uint8_t bytesprops11[] = {0x4c, 0x5a, 0xe9, 0xdd, 0xcd, 0xd, 0x31, 0x6f, 0x51, 0x7, + 0x30, 0x3b, 0xf7, 0xcc, 0xa6, 0x3d, 0x3c, 0x0, 0x19}; + uint8_t bytesprops12[] = {0xbe, 0xe2, 0xb5, 0x97, 0x80, 0xb, 0x43, 0x7e, 0x71, 0x5a, 0xbb, 0xd8, 0xbd, 0xe0, 0xca}; + uint8_t bytesprops13[] = {0xd5, 0xf2, 0x96, 0xeb, 0x62, 0x95, 0x9b, 0x22, 0x97, 0xf6, 0x5, 0xef}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)18, .value = {.str = {24, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)3, .value = {.str = {0, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {21, (char*)&bytesprops2}, .v = {21, (char*)&bytesprops3}}}}, + {.prop = (lwmqtt_prop_t)17, .value = {.int32 = 16122}}, + {.prop = (lwmqtt_prop_t)33, .value = {.int16 = 24484}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 156}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 32214}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 11695}}, + {.prop = (lwmqtt_prop_t)38, .value = {.pair = {.k = {27, (char*)&bytesprops4}, .v = {22, (char*)&bytesprops5}}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {2, (char*)&bytesprops6}}}, + {.prop = (lwmqtt_prop_t)28, .value = {.str = {21, (char*)&bytesprops7}}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {29, (char*)&bytesprops8}}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 88}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 3069}}, + {.prop = (lwmqtt_prop_t)11, .value = {.int32 = 13}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 117}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {15, (char*)&bytesprops9}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 1148}}, + {.prop = (lwmqtt_prop_t)36, .value = {.byte = 206}}, + {.prop = (lwmqtt_prop_t)22, .value = {.str = {21, (char*)&bytesprops10}}}, + {.prop = (lwmqtt_prop_t)37, .value = {.byte = 56}}, + {.prop = (lwmqtt_prop_t)19, .value = {.int16 = 6281}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {19, (char*)&bytesprops11}}}, + {.prop = (lwmqtt_prop_t)31, .value = {.str = {15, (char*)&bytesprops12}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {12, (char*)&bytesprops13}}}, + {.prop = (lwmqtt_prop_t)23, .value = {.byte = 146}}, + {.prop = (lwmqtt_prop_t)42, .value = {.byte = 34}}, + {.prop = (lwmqtt_prop_t)1, .value = {.byte = 230}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 16918}}, + {.prop = (lwmqtt_prop_t)34, .value = {.int16 = 16975}}, + }; + + lwmqtt_properties_t props = {30, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 0, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoMaximumConnectTime [PropMessageExpiryInterval 16379,PropRequestResponseInformation 106] +TEST(Disco5QCTest, Encode27) { + uint8_t pkt[] = {0xe0, 0x9, 0xa0, 0x7, 0x2, 0x0, 0x0, 0x3f, 0xfb, 0x19, 0x6a}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 16379}}, + {.prop = (lwmqtt_prop_t)25, .value = {.byte = 106}}, + }; + + lwmqtt_properties_t props = {2, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 160, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoQoSNotSupported [PropContentType +// "R[\"\140\152M\189\226*\178\197c{\204\&8\207\246w\STX\220",PropAuthenticationMethod +// "\211\248\217*\187lq\237\233\&8\158\ENQh\133\214;\135S:\211\211\182/\248>\196\&2",PropResponseTopic +// "OSi\253\219",PropMessageExpiryInterval 24521,PropResponseInformation +// "\SYN\252\&4\251\t\128\174\206\200\253a\162\149\SO\238}\DC1\253\187\145\144\DC4_g\239iL\166"] +TEST(Disco5QCTest, Encode28) { + uint8_t pkt[] = {0xe0, 0x63, 0x9b, 0x61, 0x3, 0x0, 0x14, 0x52, 0x5b, 0x22, 0x8c, 0x98, 0x4d, 0xbd, 0xe2, 0x2a, 0xb2, + 0xc5, 0x63, 0x7b, 0xcc, 0x38, 0xcf, 0xf6, 0x77, 0x2, 0xdc, 0x15, 0x0, 0x1b, 0xd3, 0xf8, 0xd9, 0x2a, + 0xbb, 0x6c, 0x71, 0xed, 0xe9, 0x38, 0x9e, 0x5, 0x68, 0x85, 0xd6, 0x3b, 0x87, 0x53, 0x3a, 0xd3, 0xd3, + 0xb6, 0x2f, 0xf8, 0x3e, 0xc4, 0x32, 0x8, 0x0, 0x5, 0x4f, 0x53, 0x69, 0xfd, 0xdb, 0x2, 0x0, 0x0, + 0x5f, 0xc9, 0x1a, 0x0, 0x1c, 0x16, 0xfc, 0x34, 0xfb, 0x9, 0x80, 0xae, 0xce, 0xc8, 0xfd, 0x61, 0xa2, + 0x95, 0xe, 0xee, 0x7d, 0x11, 0xfd, 0xbb, 0x91, 0x90, 0x14, 0x5f, 0x67, 0xef, 0x69, 0x4c, 0xa6}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0x52, 0x5b, 0x22, 0x8c, 0x98, 0x4d, 0xbd, 0xe2, 0x2a, 0xb2, + 0xc5, 0x63, 0x7b, 0xcc, 0x38, 0xcf, 0xf6, 0x77, 0x2, 0xdc}; + uint8_t bytesprops1[] = {0xd3, 0xf8, 0xd9, 0x2a, 0xbb, 0x6c, 0x71, 0xed, 0xe9, 0x38, 0x9e, 0x5, 0x68, 0x85, + 0xd6, 0x3b, 0x87, 0x53, 0x3a, 0xd3, 0xd3, 0xb6, 0x2f, 0xf8, 0x3e, 0xc4, 0x32}; + uint8_t bytesprops2[] = {0x4f, 0x53, 0x69, 0xfd, 0xdb}; + uint8_t bytesprops3[] = {0x16, 0xfc, 0x34, 0xfb, 0x9, 0x80, 0xae, 0xce, 0xc8, 0xfd, 0x61, 0xa2, 0x95, 0xe, + 0xee, 0x7d, 0x11, 0xfd, 0xbb, 0x91, 0x90, 0x14, 0x5f, 0x67, 0xef, 0x69, 0x4c, 0xa6}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)3, .value = {.str = {20, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)21, .value = {.str = {27, (char*)&bytesprops1}}}, + {.prop = (lwmqtt_prop_t)8, .value = {.str = {5, (char*)&bytesprops2}}}, + {.prop = (lwmqtt_prop_t)2, .value = {.int32 = 24521}}, + {.prop = (lwmqtt_prop_t)26, .value = {.str = {28, (char*)&bytesprops3}}}, + }; + + lwmqtt_properties_t props = {5, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 155, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoMessageRateTooHigh [] +TEST(Disco5QCTest, Encode29) { + uint8_t pkt[] = {0xe0, 0x2, 0x96, 0x0}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + + lwmqtt_property_t propslist[] = {}; + + lwmqtt_properties_t props = {0, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 150, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} + +// DisconnectRequest DiscoRetainNotSupported [PropAssignedClientIdentifier +// "\169\179\157O\198\141\136jQJ\ESC!\NUL\208\240]\EOT\f\135",PropSubscriptionIdentifierAvailable 24] +TEST(Disco5QCTest, Encode30) { + uint8_t pkt[] = {0xe0, 0x1a, 0x9a, 0x18, 0x12, 0x0, 0x13, 0xa9, 0xb3, 0x9d, 0x4f, 0xc6, 0x8d, 0x88, + 0x6a, 0x51, 0x4a, 0x1b, 0x21, 0x0, 0xd0, 0xf0, 0x5d, 0x4, 0xc, 0x87, 0x29, 0x18}; + uint8_t buf[sizeof(pkt) + 10] = {0}; + uint8_t bytesprops0[] = {0xa9, 0xb3, 0x9d, 0x4f, 0xc6, 0x8d, 0x88, 0x6a, 0x51, 0x4a, + 0x1b, 0x21, 0x0, 0xd0, 0xf0, 0x5d, 0x4, 0xc, 0x87}; + + lwmqtt_property_t propslist[] = { + {.prop = (lwmqtt_prop_t)18, .value = {.str = {19, (char*)&bytesprops0}}}, + {.prop = (lwmqtt_prop_t)41, .value = {.byte = 24}}, + }; + + lwmqtt_properties_t props = {2, (lwmqtt_property_t*)&propslist}; + size_t len = 0; + lwmqtt_err_t err = lwmqtt_encode_disconnect(buf, sizeof(buf), &len, LWMQTT_MQTT5, 154, props); + EXPECT_EQ(err, LWMQTT_SUCCESS); + EXPECT_EQ(len, sizeof(pkt)); + EXPECT_ARRAY_EQ(pkt, buf, len); +} diff --git a/tests/packet.cpp b/tests/packet.cpp index 05fa11e..34aae41 100644 --- a/tests/packet.cpp +++ b/tests/packet.cpp @@ -5,6 +5,8 @@ extern "C" { #include "../src/packet.h" } +static lwmqtt_properties_t empty_props = lwmqtt_empty_props; + #define EXPECT_ARRAY_EQ(reference, actual, element_count) \ { \ for (size_t cmp_i = 0; cmp_i < element_count; cmp_i++) { \ @@ -139,7 +141,7 @@ TEST(ConnectTest, Encode1) { opts.password = lwmqtt_string("verysecret"); size_t len; - lwmqtt_err_t err = lwmqtt_encode_connect(buf, 62, &len, opts, &will); + lwmqtt_err_t err = lwmqtt_encode_connect(buf, 62, &len, LWMQTT_MQTT311, opts, &will); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_ARRAY_EQ(pkt, buf, len); @@ -168,7 +170,7 @@ TEST(ConnectTest, Encode2) { lwmqtt_options_t opts = lwmqtt_default_options; size_t len; - lwmqtt_err_t err = lwmqtt_encode_connect(buf, 14, &len, opts, nullptr); + lwmqtt_err_t err = lwmqtt_encode_connect(buf, 14, &len, LWMQTT_MQTT311, opts, nullptr); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_ARRAY_EQ(pkt, buf, len); @@ -242,7 +244,7 @@ TEST(ConnectTest, Encode3) { opts.username = lwmqtt_string("surgemq"); size_t len; - lwmqtt_err_t err = lwmqtt_encode_connect(buf, 62, &len, opts, &will); + lwmqtt_err_t err = lwmqtt_encode_connect(buf, 62, &len, LWMQTT_MQTT311, opts, &will); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_ARRAY_EQ(pkt, buf, len); @@ -254,7 +256,7 @@ TEST(ConnectTest, EncodeError1) { lwmqtt_options_t opts = lwmqtt_default_options; size_t len; - lwmqtt_err_t err = lwmqtt_encode_connect(buf, 4, &len, opts, nullptr); + lwmqtt_err_t err = lwmqtt_encode_connect(buf, 4, &len, LWMQTT_MQTT311, opts, nullptr); EXPECT_EQ(err, LWMQTT_BUFFER_TOO_SHORT); } @@ -268,7 +270,7 @@ TEST(ConnackTest, Decode1) { bool session_present; lwmqtt_return_code_t return_code; - lwmqtt_err_t err = lwmqtt_decode_connack(pkt, 4, &session_present, &return_code); + lwmqtt_err_t err = lwmqtt_decode_connack(pkt, 4, LWMQTT_MQTT311, &session_present, &return_code); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_EQ(session_present, false); @@ -285,7 +287,7 @@ TEST(ConnackTest, DecodeError1) { bool session_present; lwmqtt_return_code_t return_code; - lwmqtt_err_t err = lwmqtt_decode_connack(pkt, 4, &session_present, &return_code); + lwmqtt_err_t err = lwmqtt_decode_connack(pkt, 4, LWMQTT_MQTT311, &session_present, &return_code); EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH); } @@ -299,7 +301,7 @@ TEST(ConnackTest, DecodeError2) { bool session_present; lwmqtt_return_code_t return_code; - lwmqtt_err_t err = lwmqtt_decode_connack(pkt, 3, &session_present, &return_code); + lwmqtt_err_t err = lwmqtt_decode_connack(pkt, 3, LWMQTT_MQTT311, &session_present, &return_code); EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH); } @@ -325,7 +327,9 @@ TEST(AckTest, Decode1) { bool dup; uint16_t packet_id; - lwmqtt_err_t err = lwmqtt_decode_ack(pkt, 4, LWMQTT_PUBACK_PACKET, &dup, &packet_id); + uint8_t status; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_ack(pkt, 4, LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, &dup, &packet_id, &status, &props); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_EQ(dup, false); @@ -342,7 +346,9 @@ TEST(AckTest, DecodeError1) { bool dup; uint16_t packet_id; - lwmqtt_err_t err = lwmqtt_decode_ack(pkt, 4, LWMQTT_PUBACK_PACKET, &dup, &packet_id); + uint8_t status; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_ack(pkt, 4, LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, &dup, &packet_id, &status, &props); EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH); } @@ -357,7 +363,9 @@ TEST(AckTest, DecodeError2) { bool dup; uint16_t packet_id; - lwmqtt_err_t err = lwmqtt_decode_ack(pkt, 4, LWMQTT_PUBACK_PACKET, &dup, &packet_id); + uint8_t status; + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_ack(pkt, 4, LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, &dup, &packet_id, &status, &props); EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH); } @@ -372,7 +380,7 @@ TEST(AckTest, Encode1) { uint8_t buf[4]; size_t len; - lwmqtt_err_t err = lwmqtt_encode_ack(buf, 4, &len, LWMQTT_PUBACK_PACKET, 0, 7); + lwmqtt_err_t err = lwmqtt_encode_ack(buf, 4, &len, LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, 0, 7, 0, empty_props); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_ARRAY_EQ(pkt, buf, len); @@ -382,7 +390,7 @@ TEST(AckTest, EncodeError1) { uint8_t buf[2]; // <- too small buffer size_t len; - lwmqtt_err_t err = lwmqtt_encode_ack(buf, 2, &len, LWMQTT_PUBACK_PACKET, 0, 7); + lwmqtt_err_t err = lwmqtt_encode_ack(buf, 2, &len, LWMQTT_MQTT311, LWMQTT_PUBACK_PACKET, 0, 7, 0, empty_props); EXPECT_EQ(err, LWMQTT_BUFFER_TOO_SHORT); } @@ -420,7 +428,8 @@ TEST(PublishTest, Decode1) { uint16_t packet_id; lwmqtt_string_t topic; lwmqtt_message_t msg; - lwmqtt_err_t err = lwmqtt_decode_publish(pkt, 25, &dup, &packet_id, &topic, &msg); + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, 25, LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_EQ(dup, true); @@ -463,7 +472,8 @@ TEST(PublishTest, Decode2) { uint16_t packet_id; lwmqtt_string_t topic = lwmqtt_default_string; lwmqtt_message_t msg; - lwmqtt_err_t err = lwmqtt_decode_publish(pkt, 23, &dup, &packet_id, &topic, &msg); + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, 23, LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_EQ(dup, false); @@ -485,7 +495,8 @@ TEST(PublishTest, DecodeError1) { uint16_t packet_id; lwmqtt_string_t topic = lwmqtt_default_string; lwmqtt_message_t msg; - lwmqtt_err_t err = lwmqtt_decode_publish(pkt, 2, &dup, &packet_id, &topic, &msg); + lwmqtt_serialized_properties_t props; + lwmqtt_err_t err = lwmqtt_decode_publish(pkt, 2, LWMQTT_MQTT311, &dup, &packet_id, &topic, &msg, &props); EXPECT_EQ(err, LWMQTT_BUFFER_TOO_SHORT); } @@ -529,7 +540,7 @@ TEST(PublishTest, Encode1) { msg.retained = true; size_t len; - lwmqtt_err_t err = lwmqtt_encode_publish(buf, 25, &len, true, 7, topic, msg); + lwmqtt_err_t err = lwmqtt_encode_publish(buf, 25, &len, LWMQTT_MQTT311, true, 7, topic, msg, empty_props); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_ARRAY_EQ(pkt, buf, len); @@ -570,7 +581,7 @@ TEST(PublishTest, Encode2) { msg.payload_len = 12; size_t len; - lwmqtt_err_t err = lwmqtt_encode_publish(buf, 23, &len, false, 0, topic, msg); + lwmqtt_err_t err = lwmqtt_encode_publish(buf, 23, &len, LWMQTT_MQTT311, false, 0, topic, msg, empty_props); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_ARRAY_EQ(pkt, buf, len); @@ -585,7 +596,7 @@ TEST(PublishTest, EncodeError1) { msg.payload_len = 12; size_t len; - lwmqtt_err_t err = lwmqtt_encode_publish(buf, 2, &len, false, 0, topic, msg); + lwmqtt_err_t err = lwmqtt_encode_publish(buf, 2, &len, LWMQTT_MQTT311, false, 0, topic, msg, empty_props); EXPECT_EQ(err, LWMQTT_BUFFER_TOO_SHORT); } @@ -603,7 +614,7 @@ TEST(SubackTest, Decode1) { uint16_t packet_id; int count; lwmqtt_qos_t granted_qos_levels[2]; - lwmqtt_err_t err = lwmqtt_decode_suback(pkt, 8, &packet_id, 2, &count, granted_qos_levels); + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, 8, &packet_id, LWMQTT_MQTT311, 2, &count, granted_qos_levels); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_EQ(packet_id, 7); @@ -624,11 +635,16 @@ TEST(SubackTest, DecodeError1) { uint16_t packet_id; int count; lwmqtt_qos_t granted_qos_levels[2]; - lwmqtt_err_t err = lwmqtt_decode_suback(pkt, 5, &packet_id, 2, &count, granted_qos_levels); + lwmqtt_err_t err = lwmqtt_decode_suback(pkt, 5, &packet_id, LWMQTT_MQTT311, 2, &count, granted_qos_levels); EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH); } +TEST(SubscribeTest, OptionSize) { + lwmqtt_sub_options_t subopts = {LWMQTT_QOS0, LWMQTT_SUB_SEND_ON_SUB, 0, 0}; + EXPECT_EQ(sizeof(subopts), 1); +} + TEST(SubscribeTest, Encode1) { uint8_t pkt[38] = { LWMQTT_SUBSCRIBE_PACKET << 4u | 2, @@ -678,10 +694,13 @@ TEST(SubscribeTest, Encode1) { topic_filters[1] = lwmqtt_string("/a/b/#/c"); topic_filters[2] = lwmqtt_string("/a/b/#/cdd"); - lwmqtt_qos_t qos_levels[3] = {LWMQTT_QOS0, LWMQTT_QOS1, LWMQTT_QOS2}; + lwmqtt_sub_options_t sub_opts[3] = {lwmqtt_default_sub_options, lwmqtt_default_sub_options, + lwmqtt_default_sub_options}; + sub_opts[1].qos = LWMQTT_QOS1; + sub_opts[2].qos = LWMQTT_QOS2; size_t len; - lwmqtt_err_t err = lwmqtt_encode_subscribe(buf, 38, &len, 7, 3, topic_filters, qos_levels); + lwmqtt_err_t err = lwmqtt_encode_subscribe(buf, 38, &len, LWMQTT_MQTT311, 7, 3, topic_filters, sub_opts, empty_props); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_ARRAY_EQ(pkt, buf, len); @@ -693,10 +712,10 @@ TEST(SubscribeTest, EncodeError1) { lwmqtt_string_t topic_filters[1]; topic_filters[0] = lwmqtt_string("surgemq"); - lwmqtt_qos_t qos_levels[1] = {LWMQTT_QOS0}; + lwmqtt_sub_options_t sub_opts[1] = {lwmqtt_default_sub_options}; size_t len; - lwmqtt_err_t err = lwmqtt_encode_subscribe(buf, 2, &len, 7, 1, topic_filters, qos_levels); + lwmqtt_err_t err = lwmqtt_encode_subscribe(buf, 2, &len, LWMQTT_MQTT311, 7, 1, topic_filters, sub_opts, empty_props); EXPECT_EQ(err, LWMQTT_BUFFER_TOO_SHORT); } @@ -748,7 +767,7 @@ TEST(UnsubscribeTest, Encode1) { topic_filters[2] = lwmqtt_string("/a/b/#/cdd"); size_t len; - lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, 38, &len, 7, 3, topic_filters); + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, 38, &len, LWMQTT_MQTT311, 7, 3, topic_filters, empty_props); EXPECT_EQ(err, LWMQTT_SUCCESS); EXPECT_ARRAY_EQ(pkt, buf, len); @@ -761,7 +780,7 @@ TEST(UnsubscribeTest, EncodeError1) { topic_filters[0] = lwmqtt_string("surgemq"); size_t len; - lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, 2, &len, 7, 1, topic_filters); + lwmqtt_err_t err = lwmqtt_encode_unsubscribe(buf, 2, &len, LWMQTT_MQTT311, 7, 1, topic_filters, empty_props); EXPECT_EQ(err, LWMQTT_BUFFER_TOO_SHORT); }