TFTP
Add custom fseek and fread Add test framework gtest and added my custom fread and fseek tests + functions
This commit is contained in:
45
tests/tfpt_tests.cpp
Normal file
45
tests/tfpt_tests.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tftp.hpp"
|
||||
|
||||
tftp_custom_file_t file = {
|
||||
.data = (char*)"1234567890",
|
||||
.len = 11,
|
||||
.name = (char*)"test.txt",
|
||||
.ofset = 0
|
||||
};
|
||||
|
||||
TEST(TFTP, custom_fseek)
|
||||
{
|
||||
tftp_custom_fseek(&file, 5, SEEK_SET);
|
||||
EXPECT_EQ(file.ofset, 5);
|
||||
tftp_custom_fseek(&file, 5, SEEK_CUR);
|
||||
EXPECT_EQ(file.ofset, 10);
|
||||
}
|
||||
|
||||
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.ofset, 11);
|
||||
|
||||
memset(buf, 0, 11);
|
||||
|
||||
tftp_custom_fseek(&file, 0, SEEK_SET);
|
||||
bytes = tftp_custom_fread(buf, 11, &file);
|
||||
EXPECT_EQ(bytes, 11);
|
||||
EXPECT_EQ(memcmp(buf, "1234567890", 10), 0);
|
||||
|
||||
tftp_custom_fseek(&file, 0, SEEK_SET);
|
||||
bytes = tftp_custom_fread(buf, 5, &file);
|
||||
EXPECT_EQ(bytes, 5);
|
||||
EXPECT_EQ(memcmp(buf, "12345", 5), 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user