Пример #1
0
int test_connect_properly_formatted() {
    IT("sends a properly formatted connect packet and succeeds");
    ShimClient shimClient;

    shimClient.setAllowConnect(true);
    byte expectServer[] = { 172, 16, 0, 2 };
    shimClient.expectConnect(expectServer,1883);
    byte connect[] = {0x10,0x18,0x0,0x4,0x4d,0x51,0x54,0x54,0x4,0x2,0x0,0xf,0x0,0xc,0x63,0x6c,0x69,0x65,0x6e,0x74,0x5f,0x74,0x65,0x73,0x74,0x31};
    byte connack[] = { 0x20, 0x02, 0x00, 0x00 };

    shimClient.expect(connect,26);
    shimClient.respond(connack,4);

    PubSubClient client(server, 1883, callback, shimClient);
    int state = client.state();
    IS_TRUE(state == MQTT_DISCONNECTED);

    int rc = client.connect((char*)"client_test1");
    IS_TRUE(rc);
    IS_FALSE(shimClient.error());

    state = client.state();
    IS_TRUE(state == MQTT_CONNECTED);

    END_IT
}
Пример #2
0
int test_connect_properly_formatted_hostname() {
    IT("accepts a hostname");
    ShimClient shimClient;
    
    shimClient.setAllowConnect(true);
    shimClient.expectConnect((char* const)"localhost",1883);
    byte connack[] = { 0x20, 0x02, 0x00, 0x00 };
    shimClient.respond(connack,4);
    
    PubSubClient client((char* const)"localhost", 1883, callback, shimClient);
    int rc = client.connect((char*)"client_test1");
    IS_TRUE(rc);
    IS_FALSE(shimClient.error());
    
    END_IT
}
Пример #3
0
int test_connect_disconnect_connect() {
    IT("connects, disconnects and connects again");
    ShimClient shimClient;

    shimClient.setAllowConnect(true);
    byte expectServer[] = { 172, 16, 0, 2 };
    shimClient.expectConnect(expectServer,1883);
    byte connect[] = {0x10,0x18,0x0,0x4,0x4d,0x51,0x54,0x54,0x4,0x2,0x0,0xf,0x0,0xc,0x63,0x6c,0x69,0x65,0x6e,0x74,0x5f,0x74,0x65,0x73,0x74,0x31};
    byte connack[] = { 0x20, 0x02, 0x00, 0x00 };

    shimClient.expect(connect,26);
    shimClient.respond(connack,4);

    PubSubClient client(server, 1883, callback, shimClient);

    int state = client.state();
    IS_TRUE(state == MQTT_DISCONNECTED);

    int rc = client.connect((char*)"client_test1");
    IS_TRUE(rc);
    IS_FALSE(shimClient.error());

    state = client.state();
    IS_TRUE(state == MQTT_CONNECTED);

    byte disconnect[] = {0xE0,0x00};
    shimClient.expect(disconnect,2);

    client.disconnect();

    IS_FALSE(client.connected());
    IS_FALSE(shimClient.connected());
    IS_FALSE(shimClient.error());

    state = client.state();
    IS_TRUE(state == MQTT_DISCONNECTED);

    shimClient.expect(connect,28);
    shimClient.respond(connack,4);
    rc = client.connect((char*)"client_test1");
    IS_TRUE(rc);
    IS_FALSE(shimClient.error());
    state = client.state();
    IS_TRUE(state == MQTT_CONNECTED);

    END_IT
}