Skip to content

Commit

Permalink
updated error names
Browse files Browse the repository at this point in the history
  • Loading branch information
256dpi committed Aug 19, 2017
1 parent f24ad89 commit c41a4a6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions include/lwmqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ typedef enum {
LWMQTT_UNANSWERED_PING = -1,
LWMQTT_BUFFER_TOO_SHORT = -2,
LWMQTT_REMAINING_LENGTH_OVERFLOW = -3,
LWMQTT_LENGTH_MISMATCH = -4,
LWMQTT_REMAINING_LENGTH_MISMATCH = -4,
LWMQTT_NOT_ENOUGH_DATA = -5,
LWMQTT_NETWORK_CONNECT_ERROR = -6,
LWMQTT_NETWORK_READ_ERROR = -7,
LWMQTT_NETWORK_WRITE_ERROR = -8,
LWMQTT_MISSING_OR_WRONG_PACKET = -9,
LWMQTT_CONNECTION_DENIED = -10,
LWMQTT_FAILED_SUBSCRIPTION = -11,
LWMQTT_DECODE_ERROR = -12,
LWMQTT_SUBACK_ARRAY_OVERFLOW = -12,
LWMQTT_VARNUM_OVERFLOW = -13
} lwmqtt_err_t;

Expand Down
18 changes: 9 additions & 9 deletions src/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ lwmqtt_err_t lwmqtt_detect_packet_type(uint8_t *buf, size_t buf_len, lwmqtt_pack
return LWMQTT_SUCCESS;
default:
*packet_type = LWMQTT_NO_PACKET;
return LWMQTT_DECODE_ERROR;
return LWMQTT_MISSING_OR_WRONG_PACKET;
}
}

Expand Down Expand Up @@ -246,7 +246,7 @@ lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, bool *session_p
if (err != LWMQTT_SUCCESS) {
return err;
} else if (header.bits.type != LWMQTT_CONNACK_PACKET) {
return LWMQTT_DECODE_ERROR;
return LWMQTT_MISSING_OR_WRONG_PACKET;
}

// read remaining length
Expand All @@ -258,7 +258,7 @@ lwmqtt_err_t lwmqtt_decode_connack(uint8_t *buf, size_t buf_len, bool *session_p

// check remaining length
if (rem_len != 2) {
return LWMQTT_LENGTH_MISMATCH;
return LWMQTT_REMAINING_LENGTH_MISMATCH;
}

// read flags
Expand Down Expand Up @@ -333,7 +333,7 @@ lwmqtt_err_t lwmqtt_decode_ack(uint8_t *buf, size_t buf_len, lwmqtt_packet_type_

// check remaining length
if (rem_len != 2) {
return LWMQTT_LENGTH_MISMATCH;
return LWMQTT_REMAINING_LENGTH_MISMATCH;
}

// read packet id
Expand Down Expand Up @@ -393,7 +393,7 @@ lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, bool *dup, uint
if (err != LWMQTT_SUCCESS) {
return err;
} else if (header.bits.type != LWMQTT_PUBLISH_PACKET) {
return LWMQTT_DECODE_ERROR;
return LWMQTT_MISSING_OR_WRONG_PACKET;
}

// set variables
Expand All @@ -410,7 +410,7 @@ lwmqtt_err_t lwmqtt_decode_publish(uint8_t *buf, size_t buf_len, bool *dup, uint

// check remaining length (topic length)
if (rem_len < 2) {
return LWMQTT_LENGTH_MISMATCH;
return LWMQTT_REMAINING_LENGTH_MISMATCH;
}

// read topic
Expand Down Expand Up @@ -578,7 +578,7 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet
if (err != LWMQTT_SUCCESS) {
return err;
} else if (header.bits.type != LWMQTT_SUBACK_PACKET) {
return LWMQTT_DECODE_ERROR;
return LWMQTT_MISSING_OR_WRONG_PACKET;
}

// read remaining length
Expand All @@ -590,7 +590,7 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet

// check remaining length (packet id + min. one suback code)
if (rem_len < 3) {
return LWMQTT_LENGTH_MISMATCH;
return LWMQTT_REMAINING_LENGTH_MISMATCH;
}

// read packet id
Expand All @@ -603,7 +603,7 @@ lwmqtt_err_t lwmqtt_decode_suback(uint8_t *buf, size_t buf_len, uint16_t *packet
for (*count = 0; *count < (int)rem_len - 2; (*count)++) {
// check max count
if (*count > max_count) {
return LWMQTT_DECODE_ERROR;
return LWMQTT_SUBACK_ARRAY_OVERFLOW;
}

// read qos level
Expand Down
12 changes: 6 additions & 6 deletions tests/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TEST(DetectPacketType, Invalid) {
lwmqtt_packet_type_t p;
lwmqtt_err_t err = lwmqtt_detect_packet_type(&h, 1, &p);
EXPECT_EQ(p, LWMQTT_NO_PACKET);
EXPECT_EQ(err, LWMQTT_DECODE_ERROR);
EXPECT_EQ(err, LWMQTT_MISSING_OR_WRONG_PACKET);
}

TEST(DetectRemainingLength, Valid1) {
Expand Down Expand Up @@ -213,7 +213,7 @@ TEST(ConnackTest, DecodeError1) {
lwmqtt_return_code_t return_code;
lwmqtt_err_t err = lwmqtt_decode_connack(pkt, 4, &session_present, &return_code);

EXPECT_EQ(err, LWMQTT_LENGTH_MISMATCH);
EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH);
}

TEST(ConnackTest, DecodeError2) {
Expand All @@ -227,7 +227,7 @@ TEST(ConnackTest, DecodeError2) {
lwmqtt_return_code_t return_code;
lwmqtt_err_t err = lwmqtt_decode_connack(pkt, 3, &session_present, &return_code);

EXPECT_EQ(err, LWMQTT_LENGTH_MISMATCH);
EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH);
}

TEST(ZeroTest, Encode1) {
Expand Down Expand Up @@ -273,7 +273,7 @@ TEST(AckTest, DecodeError1) {
uint16_t packet_id;
lwmqtt_err_t err = lwmqtt_decode_ack(pkt, 4, &packet_type, &dup, &packet_id);

EXPECT_EQ(err, LWMQTT_LENGTH_MISMATCH);
EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH);
}

TEST(AckTest, DecodeError2) {
Expand All @@ -289,7 +289,7 @@ TEST(AckTest, DecodeError2) {
uint16_t packet_id;
lwmqtt_err_t err = lwmqtt_decode_ack(pkt, 4, &packet_type, &dup, &packet_id);

EXPECT_EQ(err, LWMQTT_LENGTH_MISMATCH);
EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH);
}

TEST(AckTest, Encode1) {
Expand Down Expand Up @@ -554,7 +554,7 @@ TEST(SubackTest, DecodeError1) {
lwmqtt_qos_t granted_qos_levels[2];
lwmqtt_err_t err = lwmqtt_decode_suback(pkt, 5, &packet_id, 2, &count, granted_qos_levels);

EXPECT_EQ(err, LWMQTT_LENGTH_MISMATCH);
EXPECT_EQ(err, LWMQTT_REMAINING_LENGTH_MISMATCH);
}

TEST(SubscribeTest, Encode1) {
Expand Down

0 comments on commit c41a4a6

Please sign in to comment.