From fc997e1aac06ca063602ddea9df277dff7519095 Mon Sep 17 00:00:00 2001 From: Sander Speetjens Date: Wed, 6 Dec 2023 08:23:12 +0100 Subject: [PATCH] tftp fix tests --- tests/tfpt_tests.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/tfpt_tests.cpp b/tests/tfpt_tests.cpp index 4a70f51..aba9a79 100644 --- a/tests/tfpt_tests.cpp +++ b/tests/tfpt_tests.cpp @@ -33,15 +33,15 @@ TEST(TFTP, custom_fread) char buf[11]; tftp_custom_fseek(&file, 0, SEEK_SET); size_t bytes = tftp_custom_fread(buf, 11, &file); - EXPECT_EQ(bytes, 11); - EXPECT_EQ(file.offset, 11); + EXPECT_EQ(bytes, 10); + EXPECT_EQ(file.offset, 10); EXPECT_EQ(memcmp(buf, "1234567890", 10), 0); memset(buf, 0, 11); tftp_custom_fseek(&file, 0, SEEK_SET); bytes = tftp_custom_fread(buf, 11, &file); - EXPECT_EQ(bytes, 11); + EXPECT_EQ(bytes, 10); EXPECT_EQ(memcmp(buf, "1234567890", 10), 0); memset(buf, 0, 11); @@ -59,17 +59,17 @@ TEST(TFTP, custom_fread) } TEST(TFTP, custom_fwrite) { - write_file.data = (char*)malloc(21 * sizeof(char)); - write_file.len = 21; + write_file.data = (char*)malloc(22 * sizeof(char)); + write_file.len = 22; tftp_custom_fwrite("0987654321", 10, &write_file); EXPECT_EQ(write_file.offset, 10); - EXPECT_EQ(write_file.len, 21); + EXPECT_EQ(write_file.len, 22); EXPECT_EQ(memcmp(write_file.data, "0987654321", 10), 0); tftp_custom_fwrite("1234567890", 10, &write_file); EXPECT_EQ(write_file.offset, 20); - EXPECT_EQ(write_file.len, 21); - EXPECT_EQ(memcmp(write_file.data, "09876543211234567890", 20), 0); + EXPECT_EQ(write_file.len, 22); + EXPECT_EQ(memcmp(write_file.data, "09876543211234567890", 21), 0); free(write_file.data); write_file.data = NULL; @@ -85,11 +85,13 @@ TEST(TFTP, custom_fread_fwrite_suggested_by_Lorenz) { tftp_custom_fwrite("0987654321", 10, &write_file); EXPECT_EQ(write_file.offset, 20); EXPECT_EQ(write_file.len, 21); - EXPECT_EQ(memcmp(write_file.data, "12345678901234567890", 20), 0); + EXPECT_EQ(memcmp(write_file.data, "12345678901234567890", 21), 0); free(write_file.data); + write_file.data = NULL; + write_file.len = 0; char buf[21]; file.offset = 9; tftp_custom_fread(buf, 20, &file); - EXPECT_EQ(memcmp(buf, "0", 1), 0); + EXPECT_EQ(memcmp(buf, "0", 2), 0); } \ No newline at end of file