Skip to content

Commit

Permalink
test: fix testing and tabbing
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertByrnes committed Aug 26, 2023
1 parent 784c790 commit 3157867
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 201 deletions.
29 changes: 23 additions & 6 deletions src/ssl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,29 @@ static int client_net_send( void *ctx, const unsigned char *buf, size_t len ) {
return -2;
}

// esp_log_buffer_hexdump_internal("SSL.WR", buf, (uint16_t)len, ESP_LOG_VERBOSE);

int result = client->write(buf, len);
if (result == 0) {
log_e("write failed");
result= MBEDTLS_ERR_NET_SEND_FAILED;
// esp_log_buffer_hexdump_internal("SSL.WR", buf, (uint16_t)len, ESP_LOG_VERBOSE);BEDTLS_ERR_NET_SEND_FAILED;

int result = 0;
for (int i = 0; i < len; i += SSL_CLIENT_SEND_BUFFER_SIZE) {
int bytesToWrite;

if (SSL_CLIENT_SEND_BUFFER_SIZE > len - i) {
bytesToWrite = len - i;
} else {
bytesToWrite = SSL_CLIENT_SEND_BUFFER_SIZE;
}

// Create a new buffer for each chunk
unsigned char buffer[bytesToWrite];
memcpy(buffer, &buf[i], bytesToWrite);

// Send the buffer to the client
result += client->write(buffer, bytesToWrite);
if (result == 0) {
log_e("write failed");
result = MBEDTLS_ERR_NET_SEND_FAILED;
break;
}
}

log_d("SSL client TX res=%d len=%zu", result, len);
Expand Down
19 changes: 10 additions & 9 deletions src/ssl_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@
#define SSL_CLIENT_DEFAULT_HANDSHAKE_TIMEOUT 15000U
#define SSL_CLIENT_SLOW_NETWORK_HANDSHAKE_TIMEOUT 30000U
#define SSL_CLIENT_UNRELIABLE_NETWORK_HANDSHAKE_TIMEOUT 45000U
#define SSL_CLIENT_SEND_BUFFER_SIZE 1024U

using namespace std;

typedef struct sslclient_context {
Client* client;
Client* client;

mbedtls_ssl_context ssl_ctx;
mbedtls_ssl_config ssl_conf;
mbedtls_ssl_context ssl_ctx;
mbedtls_ssl_config ssl_conf;

mbedtls_ctr_drbg_context drbg_ctx;
mbedtls_entropy_context entropy_ctx;
mbedtls_ctr_drbg_context drbg_ctx;
mbedtls_entropy_context entropy_ctx;

mbedtls_x509_crt ca_cert;
mbedtls_x509_crt client_cert;
mbedtls_pk_context client_key;
mbedtls_x509_crt ca_cert;
mbedtls_x509_crt client_cert;
mbedtls_pk_context client_key;

unsigned long handshake_timeout;
unsigned long handshake_timeout;
} sslclient_context;

static int configure_default_ssl(sslclient_context *ssl_client);
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/ESPClass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class ESPClass {
public:
inline int getFreeHeap() { return 1000; }
inline int getFreeHeap() { return 1000; }
};

ESPClass ESP;
Expand Down
78 changes: 32 additions & 46 deletions test/mocks/TestClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,49 @@

class TestClient : public Client, public Emulator {
public:
int connect(IPAddress ip, uint16_t port) override {
// Dummy implementation
return 1; // 1 means successful connection, you can change based on test requirements.
}
int connect(IPAddress ip, uint16_t port) override {
return 1; // 1 means successful connection, you can change based on test requirements.
}

int connect(const char *host, uint16_t port) override {
// Dummy implementation
return 1;
}
int connect(const char *host, uint16_t port) override {
return 1;
}

size_t write(uint8_t byte) override {
// Dummy implementation
return 1; // 1 byte written
}
size_t write(uint8_t byte) override {
return 1; // 1 byte written
}

size_t write(const uint8_t *buf, size_t size) override {
// Dummy implementation
return this->mock<size_t>("write");
}
size_t write(const uint8_t *buf, size_t size) override {
return this->mock<size_t>("write");
}

int available() override {
// Dummy implementation
return 0; // No bytes available
}
int available() override {
return 0; // No bytes available
}

int read() override {
// Dummy implementation
return -1; // -1 generally indicates no bytes available
}
int read() override {
return -1; // -1 generally indicates no bytes available
}

int read(uint8_t *buf, size_t size) override {
// Dummy implementation
return 0; // No bytes read
}
int read(uint8_t *buf, size_t size) override {
return 0; // No bytes read
}

int peek() override {
// Dummy implementation
return -1; // -1 generally indicates no bytes available
}
int peek() override {
return -1; // -1 generally indicates no bytes available
}

void flush() override {
// Dummy implementation, does nothing
}
void flush() override {}

void stop() override {
// Dummy implementation, does nothing
}
void stop() override {}

uint8_t connected() override {
// Dummy implementation
return this->mock<uint8_t>("connected");
}
uint8_t connected() override {
return this->mock<uint8_t>("connected");
}

operator bool() override {
// Dummy implementation
return true; // Always true for testing
}
operator bool() override {
return true; // Always true for testing
}
};

#endif // TESTCLIENT_H
139 changes: 0 additions & 139 deletions test/test_SSLCLient.cpp

This file was deleted.

Loading

0 comments on commit 3157867

Please sign in to comment.