mosquitto/test/lib/cpp/02-subscribe-qos0.cpp

70 lines
1 KiB
C++
Raw Normal View History

#include <cassert>
2023-12-23 13:59:58 +01:00
#include <mosquitto/libmosquittopp.h>
2014-05-08 00:27:00 +02:00
static int run = -1;
class mosquittopp_test : public mosqpp::mosquittopp
{
2025-09-17 12:19:46 +02:00
public:
mosquittopp_test(const char *id);
2014-05-08 00:27:00 +02:00
2025-09-17 12:19:46 +02:00
void on_connect(int rc);
void on_disconnect(int rc);
void on_subscribe(int mid, int qos_count, const int *granted_qos);
2014-05-08 00:27:00 +02:00
};
mosquittopp_test::mosquittopp_test(const char *id) : mosqpp::mosquittopp(id)
{
}
2025-09-17 12:19:46 +02:00
2014-05-08 00:27:00 +02:00
void mosquittopp_test::on_connect(int rc)
{
if(rc){
exit(1);
}else{
subscribe(NULL, "qos0/test", 0);
}
}
2025-09-17 12:19:46 +02:00
2014-05-08 00:27:00 +02:00
void mosquittopp_test::on_disconnect(int rc)
{
run = rc;
}
2025-09-17 12:19:46 +02:00
2014-05-08 00:27:00 +02:00
void mosquittopp_test::on_subscribe(int mid, int qos_count, const int *granted_qos)
{
assert(mid == 1);
assert(qos_count == 1);
assert(granted_qos[0] == 0);
2014-05-08 00:27:00 +02:00
disconnect();
}
2025-09-17 12:19:46 +02:00
2014-05-08 00:27:00 +02:00
int main(int argc, char *argv[])
{
2024-02-26 01:19:49 +01:00
mosquittopp_test *mosq;
2014-05-08 00:27:00 +02:00
if(argc != 2){
return 1;
}
int port = atoi(argv[1]);
2014-05-08 00:27:00 +02:00
mosqpp::lib_init();
mosq = new mosquittopp_test("subscribe-qos0-test");
mosq->connect("localhost", port, 60);
2014-05-08 00:27:00 +02:00
while(run == -1){
mosq->loop();
}
2020-05-05 12:56:10 +02:00
delete mosq;
2014-05-08 00:27:00 +02:00
mosqpp::lib_cleanup();
return run;
}