@@ -0,0 +1,90 @@
|
||||
#include "test_transport_tcp.h"
|
||||
#include "transport_tcp.h"
|
||||
#include "test_utils.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
static void test_client_create_delete() {
|
||||
Client* client = client_create();
|
||||
EXPECT_NOT_NULL(client);
|
||||
EXPECT_EQ_INT(client->file_descriptor, -1);
|
||||
EXPECT_EQ_INT(client->ssh_child_pid, -1);
|
||||
client_delete(client);
|
||||
}
|
||||
|
||||
static void test_client_delete_null() {
|
||||
client_delete(NULL);
|
||||
}
|
||||
|
||||
static void test_client_disconnect_null() {
|
||||
client_disconnect(NULL);
|
||||
}
|
||||
|
||||
static void test_client_connect_bad_host() {
|
||||
Client* client = client_create();
|
||||
EXPECT_NOT_NULL(client);
|
||||
|
||||
// Connecting to a non-existent host should fail
|
||||
bool connected = client_connect(client, "192.0.2.999", 12345);
|
||||
EXPECT_FALSE(connected);
|
||||
|
||||
client_disconnect(client);
|
||||
client_delete(client);
|
||||
}
|
||||
|
||||
static void test_client_connect_bad_port() {
|
||||
Client* client = client_create();
|
||||
EXPECT_NOT_NULL(client);
|
||||
|
||||
// Connecting to port 0 should fail
|
||||
bool connected = client_connect(client, "127.0.0.1", 0);
|
||||
EXPECT_FALSE(connected);
|
||||
|
||||
client_disconnect(client);
|
||||
client_delete(client);
|
||||
}
|
||||
|
||||
static void test_client_connect_null_host() {
|
||||
Client* client = client_create();
|
||||
EXPECT_NOT_NULL(client);
|
||||
|
||||
bool connected = client_connect(client, NULL, 8080);
|
||||
EXPECT_FALSE(connected);
|
||||
|
||||
client_disconnect(client);
|
||||
client_delete(client);
|
||||
}
|
||||
|
||||
static void test_server_create_delete() {
|
||||
Server* server = server_create(0);
|
||||
// server_create may return NULL if it fails to bind, but we need to check
|
||||
// if it succeeds. Port 0 should bind to an ephemeral port.
|
||||
if (server != NULL) {
|
||||
EXPECT_NOT_NULL(server);
|
||||
server_delete(&server);
|
||||
EXPECT_NULL(server);
|
||||
} else {
|
||||
// On some systems port 0 may fail; that's okay
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_server_delete_null() {
|
||||
Server* server = NULL;
|
||||
server_delete(&server);
|
||||
EXPECT_NULL(server);
|
||||
}
|
||||
|
||||
void test_transport_tcp() {
|
||||
test_client_create_delete();
|
||||
test_client_delete_null();
|
||||
test_client_disconnect_null();
|
||||
test_client_connect_bad_host();
|
||||
test_client_connect_bad_port();
|
||||
test_client_connect_null_host();
|
||||
test_server_create_delete();
|
||||
test_server_delete_null();
|
||||
}
|
||||
Reference in New Issue
Block a user