1
0
mirror of https://github.com/fumiama/fumidb.git synced 2026-06-09 20:50:38 +08:00
This commit is contained in:
源文雨
2022-05-03 01:29:08 +08:00
parent e24f761f34
commit bd6ce1d778
11 changed files with 636 additions and 35 deletions

View File

@@ -3,7 +3,7 @@ project(fumidb_test VERSION 1.0)
add_executable(binary_test binary_test.c)
add_executable(page_test page_test.c ../src/page.c ../src/file.c)
add_executable(types_test types_test.c ../src/types.c ../src/types/int8.c ../src/page.c ../src/file.c)
add_executable(types_test types_test.c ../src/types.c ../src/types/int8.c ../src/types/int16.c ../src/page.c ../src/file.c)
add_test(test_binary binary_test COMMAND binary_test)
add_test(test_page page_test COMMAND page_test)

View File

@@ -1,4 +1,4 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
@@ -8,7 +8,7 @@
#include "../include/types.h"
#include "../include/types/int8.h"
uint8_t int8buf[INT8_INDEX_SZ+10];
uint8_t buf[10290];
int main() {
/* test int8 */
@@ -18,9 +18,9 @@ int main() {
return 1;
}
if(init_file_header_page(fd) < 0) return 2;
void* index = create_index(fd, TYPE_INT8, int8buf);
void* index = create_index(fd, TYPE_INT8, buf);
if(!index) {
perror("create_index");
perror("create_int8_index");
return 3;
}
if(le64(index-10) != HEADERSZ) {
@@ -36,6 +36,7 @@ int main() {
insert_item(fd, TYPE_INT8, index, 45, 345743415);
insert_item(fd, TYPE_INT8, index, 67, 56787145);
insert_item(fd, TYPE_INT8, index, 123, 123567854424);
if(count_items(fd, TYPE_INT8, index) != 5) return 6;
if(find_item_by_key(fd, TYPE_INT8, index, 1) != 3456432) return 6;
if(find_item_by_key(fd, TYPE_INT8, index, 3) != 7654323456) return 7;
if(find_item_by_key(fd, TYPE_INT8, index, 45) != 345743415) return 8;
@@ -45,8 +46,8 @@ int main() {
index = NULL;
close(fd);
fd = open("types_test_tmp.bin", O_RDWR, 0644);
memset(int8buf, 0, INT8_INDEX_SZ+10);
index = load_index(fd, TYPE_INT8, HEADERSZ, int8buf);
memset(buf, 0, INT8_INDEX_SZ+10);
index = load_index(fd, TYPE_INT8, HEADERSZ, buf);
if(find_item_by_key(fd, TYPE_INT8, index, 1) != 3456432) return 6;
if(find_item_by_key(fd, TYPE_INT8, index, 3) != 7654323456) return 7;
if(find_item_by_key(fd, TYPE_INT8, index, 45) != 345743415) return 8;
@@ -55,7 +56,44 @@ int main() {
if(find_item_by_key(fd, TYPE_INT8, index, 255) != 0) return 11;
remove_item_by_key(fd, TYPE_INT8, index, 123);
if(find_item_by_key(fd, TYPE_INT8, index, 123) != 0) return 12;
if(count_items(fd, TYPE_INT8, index) != 4) return 13;
if(remove_index(fd, TYPE_INT8, index)) return 14;
index = create_index(fd, TYPE_INT8, buf);
if(!index) {
perror("create_int8_index");
return 3;
}
if(count_items(fd, TYPE_INT8, index) != 0) return 15;
close(fd);
/* end test int8 */
/* test int16 */
fd = open("types_test_tmp.bin", O_RDWR | O_CREAT | O_TRUNC, 0644);
if(fd < 0) {
perror("create");
return 1;
}
if(init_file_header_page(fd) < 0) return 2;
index = create_index(fd, TYPE_INT16, buf);
if(!index) {
perror("create_int16_index");
return 3;
}
for(int i = 57344, cnt = 0; i < 65536+4099; i++, cnt++) {
int n;
if((n=count_items(fd, TYPE_INT16, index)) != cnt) {
printf("%d != %d\n", cnt, n);
return 4;
}
if(insert_item(fd, TYPE_INT16, index, (key_t)i, i)) {
printf("%u ", (uint16_t)i);
fflush(stdout);
perror("insert_int16_item");
return 4;
}
}
close(fd);
/* end test int16 */
// remove("types_test_tmp.bin");
}