aboutsummaryrefslogtreecommitdiff
path: root/test/interop/testclient.c
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2017-03-18 09:29:19 +0200
committerOskari Timperi <oskari.timperi@iki.fi>2017-03-18 09:29:19 +0200
commit7aeef53b089272f4633cc40512296bfd884a58d4 (patch)
tree894753ced0495f725ad8362859f88d5b61e29eb7 /test/interop/testclient.c
parente9958e8a0f5aa5fbe0a4a03be42b8bf640add6f7 (diff)
parent2c76b0da9e0aba2211d5b4a8e51c79e47ad9b6c8 (diff)
downloadmqtt-0.5.tar.gz
mqtt-0.5.zip
Merge branch 'the-great-refactor'v0.5
* the-great-refactor: Add big_message_test Fix publish message serialization Modify the code to use nonblocking sockets Fix indentation Free userName and password in MqttClientFree() Add forgotten files Massive refactoring of the internals
Diffstat (limited to 'test/interop/testclient.c')
-rw-r--r--test/interop/testclient.c44
1 files changed, 40 insertions, 4 deletions
diff --git a/test/interop/testclient.c b/test/interop/testclient.c
index 8d616f6..09782b2 100644
--- a/test/interop/testclient.c
+++ b/test/interop/testclient.c
@@ -14,12 +14,15 @@ static void TestClientOnConnect(MqttClient *client,
}
static void TestClientOnSubscribe(MqttClient *client, int id,
- const char *filter,
- MqttSubscriptionStatus status)
+ int *qos, int count)
{
TestClient *testClient = (TestClient *) MqttClientGetUserData(client);
testClient->subId = id;
- testClient->subStatus[testClient->subCount++] = status;
+ for (testClient->subCount = 0; testClient->subCount < count;
+ ++testClient->subCount)
+ {
+ testClient->subStatus[testClient->subCount] = qos[testClient->subCount];
+ }
}
static void TestClientOnPublish(MqttClient *client, int id)
@@ -37,6 +40,12 @@ static void TestClientOnMessage(MqttClient *client, const char *topic,
SIMPLEQ_INSERT_TAIL(&testClient->messages, msg, chain);
}
+static void TestClientOnUnsubscribe(MqttClient *client, int id)
+{
+ TestClient *testClient = (TestClient *) MqttClientGetUserData(client);
+ testClient->unsubId = id;
+}
+
Message *MessageNew(const char *topic, const void *data, size_t size,
int qos, int retain)
{
@@ -69,6 +78,8 @@ TestClient *TestClientNew(const char *clientId)
{
TestClient *client = calloc(1, sizeof(*client));
+ client->clientId = clientId;
+
client->client = MqttClientNew(clientId);
MqttClientSetUserData(client->client, client);
@@ -79,6 +90,7 @@ TestClient *TestClientNew(const char *clientId)
MqttClientSetOnSubscribe(client->client, TestClientOnSubscribe);
MqttClientSetOnPublish(client->client, TestClientOnPublish);
MqttClientSetOnMessage(client->client, TestClientOnMessage);
+ MqttClientSetOnUnsubscribe(client->client, TestClientOnUnsubscribe);
SIMPLEQ_INIT(&client->messages);
@@ -235,8 +247,8 @@ int TestClientWait(TestClient *client, int timeout)
printf("TestClientWait timeout:%d rc:%d\n", timeout, rc);
int64_t now = MqttGetCurrentTime();
int64_t elapsed = now - start;
- timeout -= elapsed;
printf("TestClientWait elapsed:%d\n", (int) elapsed);
+ timeout = timeout - elapsed;
if (timeout <= 0)
{
break;
@@ -245,3 +257,27 @@ int TestClientWait(TestClient *client, int timeout)
return rc != -1;
}
+
+int TestClientUnsubscribe(TestClient *client, const char *topic)
+{
+ int id = MqttClientUnsubscribe(client->client, topic);
+ int rc;
+
+ client->unsubId = -1;
+
+ while ((rc = MqttClientRunOnce(client->client, -1)) != -1)
+ {
+ if (client->unsubId != -1)
+ {
+ if (client->unsubId != id)
+ {
+ printf(
+ "WARNING: unsubscribe id mismatch: expected %d, got %d\n",
+ id, client->unsubId);
+ }
+ break;
+ }
+ }
+
+ return rc != -1;
+}