mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 12:08:16 +08:00
34 lines
922 B
C++
34 lines
922 B
C++
|
#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);
|
|||
|
mmap_destroy(map);
|
|||
|
|
|||
|
map = mmap_create(filename, TRUE, FALSE);
|
|||
|
ASSERT_EQ(map->size, strlen(str));
|
|||
|
ASSERT_EQ(memcmp(map->data, str, strlen(str)) == 0, TRUE);
|
|||
|
mmap_destroy(map);
|
|||
|
|
|||
|
file_remove(filename);
|
|||
|
}
|