mirror of
https://github.com/fumiama/fumidb.git
synced 2026-06-05 00:32:44 +08:00
finish int32 int64
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
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(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_executable(binary_test binary_test.c)
|
||||
add_executable(page_test page_test.c ../src/page.c ../src/file.c)
|
||||
#add_executable(types816_test types816_test.c ../src/types.c ../src/types/int8.c ../src/types/int16.c ../src/types/int32.c ../src/types/int64.c ../src/page.c ../src/file.c)
|
||||
add_executable(types32_test types32_test.c ../src/types.c ../src/types/int8.c ../src/types/int16.c ../src/types/int32.c ../src/types/int64.c ../src/page.c ../src/file.c)
|
||||
add_executable(types64_test types64_test.c ../src/types.c ../src/types/int8.c ../src/types/int16.c ../src/types/int32.c ../src/types/int64.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/types/int32.c ../src/types/int64.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_table table_test COMMAND table_test)
|
||||
add_test(test_binary binary_test COMMAND binary_test)
|
||||
add_test(test_page page_test COMMAND page_test)
|
||||
#add_test(test_types816 types816_test COMMAND types816_test)
|
||||
add_test(test_types32 types32_test COMMAND types32_test)
|
||||
add_test(test_types64 types64_test COMMAND types64_test)
|
||||
add_test(test_table table_test COMMAND table_test)
|
||||
|
||||
115
tests/types32_test.c
Normal file
115
tests/types32_test.c
Normal file
@@ -0,0 +1,115 @@
|
||||
#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/types.h"
|
||||
#include "../include/types/int32.h"
|
||||
|
||||
uint8_t buf[INT32_INDEX_SZ];
|
||||
|
||||
int main() {
|
||||
/* test int32 */
|
||||
int 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;
|
||||
void* index = create_index(fd, TYPE_INT32, buf);
|
||||
if(!index) {
|
||||
perror("create_int32_index");
|
||||
return 3;
|
||||
}
|
||||
for(int i = 0, j = 8192; i < INT32_BUCKET_SZ-1; i++, j+=PAGESZ) {
|
||||
if(le64(index+i*(PAGESZ+8)+PAGESZ-8) != j) {
|
||||
printf("index: %d, ptr: %d!=%d\n", i, le64(index+PAGESZ-8), j);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if(le64(index+255*(PAGESZ+8)+PAGESZ-8) != 0) {
|
||||
printf("index: 255, ptr: %d!=%d\n", le64(index+PAGESZ-8), 0);
|
||||
return 3;
|
||||
}
|
||||
int cnt = 0;
|
||||
for(int i = 123456; i < 123456+8192; i++, cnt++) {
|
||||
int n;
|
||||
if((n=count_items(fd, TYPE_INT32, index)) != cnt) {
|
||||
printf("%d != %d\n", cnt, n);
|
||||
return 4;
|
||||
}
|
||||
// printf("c", i);
|
||||
if(insert_item(fd, TYPE_INT32, index, (key_t)i, i)) {
|
||||
printf("%u ", (uint32_t)i);
|
||||
fflush(stdout);
|
||||
perror("insert_int32_item");
|
||||
return 4;
|
||||
}
|
||||
// printf("i ", i);
|
||||
}
|
||||
|
||||
for(int i = 123456; i < 123456+8192; i++) {
|
||||
if((int)find_item_by_key(fd, TYPE_INT32, index, (key_t)i) != i) {
|
||||
printf("%u ", (uint32_t)i);
|
||||
fflush(stdout);
|
||||
perror("find_item_by_key");
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
fd = open("types_test_tmp.bin", O_RDWR, 0644);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
index = load_index(fd, TYPE_INT32, PAGESZ, buf);
|
||||
|
||||
for(int i = 0, j = 8192; i < INT32_BUCKET_SZ-1; i++, j+=PAGESZ) {
|
||||
if(le64(index+i*(PAGESZ+8)+PAGESZ-8) != j) {
|
||||
printf("index: %d, ptr: %d!=%d\n", i, le64(index+PAGESZ-8), j);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
if(le64(index+255*(PAGESZ+8)+PAGESZ-8) != 0) {
|
||||
printf("index: 255, ptr: %d!=%d\n", le64(index+PAGESZ-8), 0);
|
||||
return 3;
|
||||
}
|
||||
|
||||
for(int i = 123456; i < 123456+4098; i++, cnt--) {
|
||||
int n;
|
||||
if((n=count_items(fd, TYPE_INT32, index)) != cnt) {
|
||||
printf("%d != %d\n", cnt, n);
|
||||
return 6;
|
||||
}
|
||||
if(remove_item_by_key(fd, TYPE_INT32, index, (key_t)i) != i) {
|
||||
printf("%u ", (uint32_t)i);
|
||||
fflush(stdout);
|
||||
perror("remove_item_by_key");
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 123456; i < 123456+4098; i++) {
|
||||
if((int)find_item_by_key(fd, TYPE_INT32, index, (key_t)i) != 0) {
|
||||
printf("%u ", (uint32_t)i);
|
||||
fflush(stdout);
|
||||
perror("find_item_by_key");
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 123456+4098; i < 123456+8192; i++) {
|
||||
if((int)find_item_by_key(fd, TYPE_INT32, index, (key_t)i) != i) {
|
||||
printf("%u ", (uint32_t)i);
|
||||
fflush(stdout);
|
||||
perror("find_item_by_key");
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
/* end test int32 */
|
||||
// remove("types_test_tmp.bin");
|
||||
return 0;
|
||||
}
|
||||
115
tests/types64_test.c
Normal file
115
tests/types64_test.c
Normal file
@@ -0,0 +1,115 @@
|
||||
#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/types.h"
|
||||
#include "../include/types/int64.h"
|
||||
|
||||
uint8_t buf[INT64_INDEX_SZ];
|
||||
|
||||
int main() {
|
||||
/* test int64 */
|
||||
int 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;
|
||||
void* index = create_index(fd, TYPE_INT64, buf);
|
||||
if(!index) {
|
||||
perror("create_int64_index");
|
||||
return 3;
|
||||
}
|
||||
for(int64_t i = 0, j = 8192; i < INT64_BUCKET_SZ-1; i++, j+=PAGESZ) {
|
||||
if(le64(index+i*(PAGESZ+8)+PAGESZ-8) != j) {
|
||||
printf("index: %d, ptr: %d!=%d\n", i, le64(index+PAGESZ-8), j);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
if(le64(index+1023*(PAGESZ+8)+PAGESZ-8) != 0) {
|
||||
printf("index: 1023, ptr: %d!=%d\n", le64(index+PAGESZ-8), 0);
|
||||
return 3;
|
||||
}
|
||||
int64_t cnt = 0;
|
||||
for(int64_t i = 1234567890; i < 1234567890+8192; i++, cnt++) {
|
||||
int n;
|
||||
if((n=count_items(fd, TYPE_INT64, index)) != cnt) {
|
||||
printf("%d != %d\n", cnt, n);
|
||||
return 4;
|
||||
}
|
||||
// printf("c", i);
|
||||
if(insert_item(fd, TYPE_INT64, index, (key_t)i, i)) {
|
||||
printf("%u ", (uint64_t)i);
|
||||
fflush(stdout);
|
||||
perror("insert_int64_item");
|
||||
return 4;
|
||||
}
|
||||
// printf("i ", i);
|
||||
}
|
||||
|
||||
for(int64_t i = 1234567890; i < 1234567890+8192; i++) {
|
||||
if((int)find_item_by_key(fd, TYPE_INT64, index, (key_t)i) != i) {
|
||||
printf("%u ", (uint64_t)i);
|
||||
fflush(stdout);
|
||||
perror("find_item_by_key");
|
||||
return 5;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
fd = open("types_test_tmp.bin", O_RDWR, 0644);
|
||||
memset(buf, 0, sizeof(buf));
|
||||
index = load_index(fd, TYPE_INT64, PAGESZ, buf);
|
||||
|
||||
for(int64_t i = 0, j = 8192; i < INT64_BUCKET_SZ-1; i++, j+=PAGESZ) {
|
||||
if(le64(index+i*(PAGESZ+8)+PAGESZ-8) != j) {
|
||||
printf("index: %d, ptr: %d!=%d\n", i, le64(index+PAGESZ-8), j);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
if(le64(index+1023*(PAGESZ+8)+PAGESZ-8) != 0) {
|
||||
printf("index: 1023, ptr: %d!=%d\n", le64(index+PAGESZ-8), 0);
|
||||
return 3;
|
||||
}
|
||||
|
||||
for(int64_t i = 1234567890; i < 1234567890+4098; i++, cnt--) {
|
||||
int n;
|
||||
if((n=count_items(fd, TYPE_INT64, index)) != cnt) {
|
||||
printf("%d != %d\n", cnt, n);
|
||||
return 6;
|
||||
}
|
||||
if(remove_item_by_key(fd, TYPE_INT64, index, (key_t)i) != i) {
|
||||
printf("%u ", (uint64_t)i);
|
||||
fflush(stdout);
|
||||
perror("remove_item_by_key");
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
for(int64_t i = 1234567890; i < 1234567890+4098; i++) {
|
||||
if((int)find_item_by_key(fd, TYPE_INT64, index, (key_t)i) != 0) {
|
||||
printf("%u ", (uint64_t)i);
|
||||
fflush(stdout);
|
||||
perror("find_item_by_key");
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
|
||||
for(int64_t i = 1234567890+4098; i < 1234567890+8192; i++) {
|
||||
if((int)find_item_by_key(fd, TYPE_INT64, index, (key_t)i) != i) {
|
||||
printf("%u ", (uint64_t)i);
|
||||
fflush(stdout);
|
||||
perror("find_item_by_key");
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
/* end test int64 */
|
||||
// remove("types_test_tmp.bin");
|
||||
return 0;
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "../include/page.h"
|
||||
#include "../include/types.h"
|
||||
#include "../include/types/int8.h"
|
||||
#include "../include/types/int16.h"
|
||||
|
||||
uint8_t buf[10290];
|
||||
|
||||
Reference in New Issue
Block a user