mirror of
https://github.com/fumiama/fumidb.git
synced 2026-06-05 00:32:44 +08:00
finish load table
This commit is contained in:
@@ -3,8 +3,10 @@ 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/types/int16.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_executable(table_test table_test.c ../src/table.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)
|
||||
add_test(test_types types_test COMMAND types_test)
|
||||
#add_test(test_types types_test COMMAND types_test)
|
||||
add_test(test_table table_test COMMAND table_test)
|
||||
|
||||
@@ -24,7 +24,7 @@ int main() {
|
||||
perror("create");
|
||||
return 1;
|
||||
}
|
||||
if(init_file_header_page(fd) < 0) return 2;
|
||||
if(init_file_header_page(fd)) return 2;
|
||||
for(int i = 0; i < 16; i++) {
|
||||
void* page = alloc_page(fd, nullpages[i]);
|
||||
if(page == NULL) {
|
||||
|
||||
55
tests/table_test.c
Normal file
55
tests/table_test.c
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include "../include/binary.h"
|
||||
#include "../include/file.h"
|
||||
#include "../include/page.h"
|
||||
#include "../include/table.h"
|
||||
#include "../include/types.h"
|
||||
|
||||
char buf[4106];
|
||||
|
||||
int main() {
|
||||
int fd = open("table_test_tmp.bin", O_RDWR | O_CREAT | O_TRUNC, 0644);
|
||||
if(fd < 0) {
|
||||
perror("create");
|
||||
return 1;
|
||||
}
|
||||
if(init_file_header_page(fd)) return 2;
|
||||
void* table = create_table(
|
||||
fd, buf, "test_table", 5,
|
||||
TYPE_INT16|EXTYPE_NONNULL|EXTYPE_UNIQUE,
|
||||
TYPE_INT64,
|
||||
TYPE_INT8,
|
||||
TYPE_STRING,
|
||||
TYPE_BINARY
|
||||
);
|
||||
if(table == NULL) {
|
||||
perror("create_table");
|
||||
return 3;
|
||||
}
|
||||
int len = get_table_name_length(table);
|
||||
if(len != sizeof("test_table")) return 4;
|
||||
char namebuf[len];
|
||||
if(strcmp(get_table_name(table, namebuf), "test_table")) return 5;
|
||||
close(fd);
|
||||
fd = open("table_test_tmp.bin", O_RDWR, 0644);
|
||||
if(fd < 0) {
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
memset(buf, 0, sizeof(buf));
|
||||
table = load_table(fd, buf, get_first_table(fd));
|
||||
if(table == NULL) {
|
||||
perror("load_table");
|
||||
return 3;
|
||||
}
|
||||
len = get_table_name_length(table);
|
||||
if(len != sizeof("test_table")) {
|
||||
printf("%d\n", len);
|
||||
return 4;
|
||||
}
|
||||
if(strcmp(get_table_name(table, namebuf), "test_table")) return 5;
|
||||
close(fd);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ int main() {
|
||||
perror("create");
|
||||
return 1;
|
||||
}
|
||||
if(init_file_header_page(fd) < 0) return 2;
|
||||
if(init_file_header_page(fd)) return 2;
|
||||
void* index = create_index(fd, TYPE_INT8, buf);
|
||||
if(!index) {
|
||||
perror("create_int8_index");
|
||||
|
||||
Reference in New Issue
Block a user