Add tftp_custom_write and test functions
This commit is contained in:
2023-11-13 16:03:14 +01:00
parent c97d24e578
commit 623cf3749c
7 changed files with 54 additions and 3 deletions

View File

@@ -9,6 +9,11 @@ link_directories(${GTEST_LIB_DIR})
file(GLOB_RECURSE TEST_SOURCES "*.cpp" "*.c")
add_executable(tests)
target_compile_definitions(tests
PRIVATE
"TESTING"
)
target_sources(tests
PRIVATE
${TEST_SOURCES}

View File

@@ -17,3 +17,7 @@ uint32_t logger_get_timestamp(void) {
int tftp_init(struct tftp_context* context) {
return 0;
}
void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT *font) {
}

View File

@@ -12,6 +12,12 @@ tftp_custom_file_t file = {
.name = (char*)"test.txt",
.ofset = 0
};
tftp_custom_file_t write_file = {
.data = NULL,
.len = 0,
.name = (char*)"test.txt",
.ofset = 0
};
TEST(TFTP, custom_fseek)
{
@@ -28,6 +34,7 @@ TEST(TFTP, custom_fread)
size_t bytes = tftp_custom_fread(buf, 11, &file);
EXPECT_EQ(bytes, 11);
EXPECT_EQ(file.ofset, 11);
EXPECT_EQ(memcmp(buf, "1234567890", 10), 0);
memset(buf, 0, 11);
@@ -50,4 +57,20 @@ TEST(TFTP, custom_fread)
EXPECT_EQ(memcmp(buf, "67890", 5), 0);
}
TEST(TFTP, custom_fwrite) {
write_file.data = (char*)malloc(21 * sizeof(char));
write_file.len = 21;
tftp_custom_fwrite("0987654321", 10, &write_file);
EXPECT_EQ(write_file.ofset, 10);
EXPECT_EQ(write_file.len, 21);
EXPECT_EQ(memcmp(write_file.data, "0987654321", 10), 0);
tftp_custom_fwrite("1234567890", 10, &write_file);
EXPECT_EQ(write_file.ofset, 20);
EXPECT_EQ(write_file.len, 21);
EXPECT_EQ(memcmp(write_file.data, "09876543211234567890", 20), 0);
free(write_file.data);
write_file.data = NULL;
write_file.len = 0;
}

View File

@@ -18,8 +18,13 @@ struct pbuf {
uint8_t if_idx;
};
typedef void sFONT;
#define ERR_OK 0
#define LCD_COLOR_BLACK 0
#define LCD_COLOR_WHITE 1
#define LCD_FONT16 0
struct tftp_context {
void* (*open)(const char* fname, const char* mode, uint8_t write);
@@ -31,6 +36,7 @@ struct tftp_context {
void tftp_cleanup(void);
uint32_t logger_get_timestamp(void);
int tftp_init(struct tftp_context* context);
void lcd_display_text(uint8_t* text, uint16_t x_pos, uint16_t y_pos, uint32_t color, uint32_t bg_color, sFONT *font);
#ifdef __cplusplus
}