2020-12-11 22:22:06 +08:00
|
|
|
|
#include "tkc/fs.h"
|
|
|
|
|
#include "tkc/mmap.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
TEST(MMap, read) {
|
|
|
|
|
const char* str = "test";
|
|
|
|
|
const char* filename = "test.bin";
|
|
|
|
|
file_write(filename, str, strlen(str));
|
|
|
|
|
mmap_t* map = mmap_create(filename, FALSE, FALSE);
|
|
|
|
|
ASSERT_EQ(map->size, strlen(str));
|
|
|
|
|
ASSERT_EQ(memcmp(map->data, str, strlen(str)) == 0, TRUE);
|
|
|
|
|
mmap_destroy(map);
|
|
|
|
|
file_remove(filename);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(MMap, write) {
|
|
|
|
|
const char* str = "test";
|
|
|
|
|
const char* filename = "test.bin";
|
|
|
|
|
file_write(filename, str, strlen(str));
|
|
|
|
|
mmap_t* map = mmap_create(filename, TRUE, FALSE);
|
|
|
|
|
ASSERT_EQ(map->size, strlen(str));
|
|
|
|
|
ASSERT_EQ(memcmp(map->data, str, strlen(str)) == 0, TRUE);
|
|
|
|
|
memcpy(map->data, "1234", 4);
|
2020-12-14 11:33:25 +08:00
|
|
|
|
|
2020-12-11 22:54:23 +08:00
|
|
|
|
str = "1234";
|
2020-12-11 22:22:06 +08:00
|
|
|
|
ASSERT_EQ(memcmp(map->data, str, strlen(str)) == 0, TRUE);
|
|
|
|
|
mmap_destroy(map);
|
2020-12-14 11:33:25 +08:00
|
|
|
|
|
2020-12-11 22:22:06 +08:00
|
|
|
|
file_remove(filename);
|
|
|
|
|
}
|