<commit_before>#include <gtest/gtest.h>

extern "C" {
#include "../src/client.h"
#include "../src/packet.h"
}

#include "macros.h"

TEST(ConnectTest, ConnectPacketSerialize1) {
  unsigned char pkt[62] = {
      LWMQTT_CONNECT_PACKET << 4,
      60,
      0,  // Protocol String MSB
      4,  // Protocol String LSB
      'M',
      'Q',
      'T',
      'T',
      4,    // Protocol level 4
      204,  // Connect Flags
      0,    // Keep Alive MSB
      10,   // Keep Alive LSB
      0,    // Client ID MSB
      7,    // Client ID LSB
      's',
      'u',
      'r',
      'g',
      'e',
      'm',
      'q',
      0,  // Will Topic MSB
      4,  // Will Topic LSB
      'w',
      'i',
      'l',
      'l',
      0,   // Will Message MSB
      12,  // Will Message LSB
      's',
      'e',
      'n',
      'd',
      ' ',
      'm',
      'e',
      ' ',
      'h',
      'o',
      'm',
      'e',
      0,  // Username ID MSB
      7,  // Username ID LSB
      's',
      'u',
      'r',
      'g',
      'e',
      'm',
      'q',
      0,   // Password ID MSB
      10,  // Password ID LSB
      'v',
      'e',
      'r',
      'y',
      's',
      'e',
      'c',
      'r',
      'e',
      't',
  };

  unsigned char buf[62];

  lwmqtt_will_t will = lwmqtt_default_will;
  will.topic.c_string = (char*)"will";
  will.message.c_string = (char*)"send me home";
  will.qos = LWMQTT_QOS1;

  lwmqtt_options_t opts = lwmqtt_default_options;
  opts.clean_session = 0;
  opts.keep_alive = 10;
  opts.client_id.c_string = (char*)"surgemq";
  opts.username.c_string = (char*)"surgemq";
  opts.password.c_string = (char*)"<PASSWORD>";

  int l = lwmqtt_serialize_connect(buf, 62, &opts, &will);

  EXPECT_ARRAY_EQ(unsigned char, pkt, buf, l);
}

TEST(ConnectTest, ConnectPacketSerialize2) {
  unsigned char pkt[14] = {
      LWMQTT_CONNECT_PACKET << 4,
      12,
      0, // Protocol String MSB
      4, // Protocol String LSB
      'M', 'Q', 'T', 'T',
      4,  // Protocol level 4
      2,  // Connect Flags
      0,  // Keep Alive MSB
      60, // Keep Alive LSB
      0,  // Client ID MSB
      0,  // Client ID LSB
  };

  unsigned char buf[14];

  lwmqtt_options_t opts = lwmqtt_default_options;

  int l = lwmqtt_serialize_connect(buf, 14, &opts, NULL);

  EXPECT_ARRAY_EQ(unsigned char, pkt, buf, l);
}<commit_msg>finish connect tests<commit_after>#include <gtest/gtest.h>

extern "C" {
#include "../src/client.h"
#include "../src/packet.h"
}

#include "macros.h"

TEST(ConnectTest, ConnectPacketSerialize1) {
  unsigned char pkt[62] = {
      LWMQTT_CONNECT_PACKET << 4,
      60,
      0,  // Protocol String MSB
      4,  // Protocol String LSB
      'M',
      'Q',
      'T',
      'T',
      4,    // Protocol level 4
      204,  // Connect Flags
      0,    // Keep Alive MSB
      10,   // Keep Alive LSB
      0,    // Client ID MSB
      7,    // Client ID LSB
      's',
      'u',
      'r',
      'g',
      'e',
      'm',
      'q',
      0,  // Will Topic MSB
      4,  // Will Topic LSB
      'w',
      'i',
      'l',
      'l',
      0,   // Will Message MSB
      12,  // Will Message LSB
      's',
      'e',
      'n',
      'd',
      ' ',
      'm',
      'e',
      ' ',
      'h',
      'o',
      'm',
      'e',
      0,  // Username ID MSB
      7,  // Username ID LSB
      's',
      'u',
      'r',
      'g',
      'e',
      'm',
      'q',
      0,   // Password ID MSB
      10,  // Password ID LSB
      'v',
      'e',
      'r',
      'y',
      's',
      'e',
      'c',
      'r',
      'e',
      't',
  };

  unsigned char buf[62];

  lwmqtt_will_t will = lwmqtt_default_will;
  will.topic.c_string = (char*)"will";
  will.message.c_string = (char*)"send me home";
  will.qos = LWMQTT_QOS1;

  lwmqtt_options_t opts = lwmqtt_default_options;
  opts.clean_session = 0;
  opts.keep_alive = 10;
  opts.client_id.c_string = (char*)"surgemq";
  opts.username.c_string = (char*)"surgemq";
  opts.password.c_string = (char*)"<PASSWORD>";

  int l = lwmqtt_serialize_connect(buf, 62, &opts, &will);

  EXPECT_ARRAY_EQ(unsigned char, pkt, buf, l);
}

TEST(ConnectTest, ConnectPacketSerialize2) {
  unsigned char pkt[14] = {
      LWMQTT_CONNECT_PACKET << 4,
      12,
      0,  // Protocol String MSB
      4,  // Protocol String LSB
      'M',
      'Q',
      'T',
      'T',
      4,   // Protocol level 4
      2,   // Connect Flags
      0,   // Keep Alive MSB
      60,  // Keep Alive LSB
      0,   // Client ID MSB
      0,   // Client ID LSB
  };

  unsigned char buf[14];

  lwmqtt_options_t opts = lwmqtt_default_options;

  int l = lwmqtt_serialize_connect(buf, 14, &opts, NULL);

  EXPECT_ARRAY_EQ(unsigned char, pkt, buf, l);
}

TEST(ConnectTest, ConnectPacketSerializeError1) {
  unsigned char buf[4];  // <- too small buffer

  lwmqtt_options_t opts = lwmqtt_default_options;

  int l = lwmqtt_serialize_connect(buf, 4, &opts, NULL);

  EXPECT_EQ(l, LWMQTT_BUFFER_TOO_SHORT);
}
{'fraction_non_alphanumeric': 0.1568627450980392, 'fraction_numerical': 0.023246411966848596, 'mean_word_length': 1.7216721672167217, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2083100', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1930, 'n_words': 463}