TFTP
Add tftp_custom_write and test functions
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user