/* Tests for int to string functions. */ #include #include #include "mosquitto.h" struct prop_id { const char *name; int proptype; }; static void TEST_string_to_property_info(void) { const struct prop_id checks[50] = { { NULL, 0 }, { "payload-format-indicator", MQTT_PROP_TYPE_BYTE }, { "message-expiry-interval", MQTT_PROP_TYPE_INT32 }, { "content-type", MQTT_PROP_TYPE_STRING }, { NULL, 0 }, { NULL, 0 }, { NULL, 0 }, { NULL, 0 }, { "response-topic", MQTT_PROP_TYPE_STRING }, { "correlation-data", MQTT_PROP_TYPE_BINARY }, { NULL, 0 }, { "subscription-identifier", MQTT_PROP_TYPE_VARINT }, { NULL, 0 }, { NULL, 0 }, { NULL, 0 }, { NULL, 0 }, { NULL, 0 }, { "session-expiry-interval", MQTT_PROP_TYPE_INT32 }, { "assigned-client-identifier", MQTT_PROP_TYPE_STRING }, { "server-keep-alive", MQTT_PROP_TYPE_INT16 }, { NULL, 0 }, { "authentication-method", MQTT_PROP_TYPE_STRING }, { "authentication-data", MQTT_PROP_TYPE_BINARY }, { "request-problem-information", MQTT_PROP_TYPE_BYTE }, { "will-delay-interval", MQTT_PROP_TYPE_INT32 }, { "request-response-information", MQTT_PROP_TYPE_BYTE }, { "response-information", MQTT_PROP_TYPE_STRING }, { NULL, 0 }, { "server-reference", MQTT_PROP_TYPE_STRING }, { NULL, 0 }, { NULL, 0 }, { "reason-string", MQTT_PROP_TYPE_STRING }, { NULL, 0 }, { "receive-maximum", MQTT_PROP_TYPE_INT16 }, { "topic-alias-maximum", MQTT_PROP_TYPE_INT16 }, { "topic-alias", MQTT_PROP_TYPE_INT16 }, { "maximum-qos", MQTT_PROP_TYPE_BYTE }, { "retain-available", MQTT_PROP_TYPE_BYTE }, { "user-property", MQTT_PROP_TYPE_STRING_PAIR }, { "maximum-packet-size", MQTT_PROP_TYPE_INT32 }, { "wildcard-subscription-available", MQTT_PROP_TYPE_BYTE }, { "subscription-identifier-available", MQTT_PROP_TYPE_BYTE }, { "shared-subscription-available", MQTT_PROP_TYPE_BYTE }, { NULL, 0 }, { NULL, 0 }, { NULL, 0 }, { NULL, 0 }, { NULL, 0 }, { NULL, 0 }, { NULL, 0 }, }; for(int i=0; i<50; i++){ int rc, identifier, proptype; rc = mosquitto_string_to_property_info(checks[i].name, &identifier, &proptype); if(checks[i].name == NULL){ CU_ASSERT_EQUAL(rc, MOSQ_ERR_INVAL); }else{ CU_ASSERT_EQUAL(rc, MOSQ_ERR_SUCCESS); CU_ASSERT_EQUAL(identifier, i); CU_ASSERT_EQUAL(proptype, checks[i].proptype); } } } static void TEST_mosquitto_strerror(void) { const char *str; int used[] = { -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, /* 13, */ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 31, 32, 33, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162 }; /* Iterate over all possible errors, checking we have a place holder for all * unused errors, and that all used errors do not have place holder text. */ for(int err=-256; err<256; err++){ str = mosquitto_strerror(err); CU_ASSERT_PTR_NOT_NULL(str); if(str){ bool is_used = false; for(size_t i=0; i= 128){ errstr = "Unknown reason"; }else{ errstr = "Unknown error"; } if(is_used){ CU_ASSERT_STRING_NOT_EQUAL(str, errstr); if(!strcmp(str, errstr)){ printf("%d: %s (!=)\n", err, str); } }else{ CU_ASSERT_STRING_EQUAL(str, errstr); if(strcmp(str, errstr)){ printf("%d: %s (==)\n", err, str); } } } } } static void TEST_mosquitto_connack_string(void) { const char *str; uint8_t used[] = {0, 1, 2, 3, 4, 5}; /* Iterate over all possible codes, checking we have a place holder for all * unused codes, and that all used codes do not have place holder text. */ for(int code=0; code<256; code++){ str = mosquitto_connack_string(code); CU_ASSERT_PTR_NOT_NULL(str); if(str){ bool is_used = false; for(size_t i=0; i