set02.c
来自「db.* (pronounced dee-be star) is an adva」· C语言 代码 · 共 416 行
C
416 行
/****************************************************************************** * * db.* * Test Suite * * Database Manipulation Tests * *****************************************************************************/#include "test.h"#include "set02.h"#include "utility.h"#include "db.star.h"#include "testdb.h"#include "data.h"/* Function to run all tests in this subset. */void set02_tests(){ /* Array of tests to be performed */ /* Each test function defined below must be contained within this array */ #define set02_length 15 struct unit_test set02[set02_length] = {{"test_wr_int", &test_wr_int}, {"test_wr_short", &test_wr_short}, {"test_wr_long", &test_wr_long}, {"test_wr_char", &test_wr_char}, {"test_wr_float", &test_wr_float}, {"test_wr_double", &test_wr_double}, {"test_wr_db_addr", &test_wr_db_addr}, {"test_update_int", &test_update_int}, {"test_update_short", &test_update_short}, {"test_update_long", &test_update_long}, {"test_update_char", &test_update_char}, {"test_update_float", &test_update_float}, {"test_update_double", &test_update_double}, {"test_update_db_addr", &test_update_db_addr}, {"test_delete_rec", &test_delete_rec}, }; perform_tests(set02, set02_length);}/* Data type write/read tests *//* ========================================================== *//* test writing and reading a single integer value */bool test_wr_int(DB_TASK *Currtask){ struct rec1 trec1; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_int = arr_int[0]; /* write 1 int to the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* read same int back and compare */ memset(&trec1, 0, sizeof(trec1)); d_recread(&trec1, Currtask, CURR_DB); if(trec1.a_int == arr_int[0]) passtest = TRUE; return passtest;}/* test writing and reading a single short integer value */bool test_wr_short(DB_TASK *Currtask){ struct rec1 trec1; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_short = arr_short[0]; /* write 1 short to the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* read same short back and compare */ memset(&trec1, 0, sizeof(trec1)); d_recread(&trec1, Currtask, CURR_DB); if(trec1.a_short == arr_short[0]) passtest = TRUE; return passtest;}/* test writing and reading a single long integer value */bool test_wr_long(DB_TASK *Currtask){ struct rec1 trec1; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_long = arr_long[0]; /* write 1 long to the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* read same long back and compare */ memset(&trec1, 0, sizeof(trec1)); d_recread(&trec1, Currtask, CURR_DB); if(trec1.a_long == arr_long[0]) passtest = TRUE; return passtest;}/* test writing and reading a single char value */bool test_wr_char(DB_TASK *Currtask){ struct rec1 trec1; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_char = arr_char[0]; /* write 1 char to the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* read same char back and compare */ memset(&trec1, 0, sizeof(trec1)); d_recread(&trec1, Currtask, CURR_DB); if(trec1.a_char == arr_char[0]) passtest = TRUE; return passtest;}/* test writing and reading a single float value */bool test_wr_float(DB_TASK *Currtask){ struct rec1 trec1; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_float = arr_float[0]; /* write 1 float to the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* read same float back and compare */ memset(&trec1, 0, sizeof(trec1)); d_recread(&trec1, Currtask, CURR_DB); if(trec1.a_float == arr_float[0]) passtest = TRUE; return passtest;}/* test writing and reading a single double value */bool test_wr_double(DB_TASK *Currtask){ struct rec1 trec1; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_double = arr_double[0]; /* write 1 double to the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* read same double back and compare */ memset(&trec1, 0, sizeof(trec1)); d_recread(&trec1, Currtask, CURR_DB); if(trec1.a_double == arr_double[0]) passtest = TRUE; return passtest;}/* test writing and reading a single DB_ADDR value *//* TODO: create a record, get it's DB_ADDR then use that as the test value */bool test_wr_db_addr(DB_TASK *Currtask){ struct rec1 trec1; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_db_addr = arr_db_addr[0]; /* write 1 DB_ADDR to the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* read same DB_ADDR back and compare */ memset(&trec1, 0, sizeof(trec1)); d_recread(&trec1, Currtask, CURR_DB); if(trec1.a_db_addr == arr_db_addr[0]) passtest = TRUE; return passtest;}/* Data type update tests *//* ========================================================== *//* test updating a single integer value */bool test_update_int(DB_TASK *Currtask){ struct rec1 trec1; int value = arr_int[1]; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_int = arr_int[0]; /* write an int into the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* update that field with a new value */ d_crwrite(A_INT, &value, Currtask, CURR_DB); value = 0; /* read in that field and compare with original value */ d_crread(A_INT, &value, Currtask, CURR_DB); if(value == arr_int[1]) passtest = TRUE; return passtest;}/* test updating a single short integer value */bool test_update_short(DB_TASK *Currtask){ struct rec1 trec1; short value = arr_short[1]; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_short = arr_short[0]; /* write a short into the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* update that field with a new value */ d_crwrite(A_SHORT, &value, Currtask, CURR_DB); value = 0; /* read in that field and compare with original value */ d_crread(A_SHORT, &value, Currtask, CURR_DB); if(value == arr_short[1]) passtest = TRUE; return passtest;}/* test updating a single long integer value */bool test_update_long(DB_TASK *Currtask){ struct rec1 trec1; long value = arr_long[1]; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_long = arr_long[0]; /* write a long into the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* update that field with a new value */ d_crwrite(A_LONG, &value, Currtask, CURR_DB); value = 0; /* read in that field and compare with original value */ d_crread(A_LONG, &value, Currtask, CURR_DB); if(value == arr_long[1]) passtest = TRUE; return passtest;}/* test updating a single char value */bool test_update_char(DB_TASK *Currtask){ struct rec1 trec1; char value = arr_char[1]; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_char = arr_char[0]; /* write a char into the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* update that field with a new value */ d_crwrite(A_CHAR, &value, Currtask, CURR_DB); value = '\0'; /* read in that field and compare with original value */ d_crread(A_CHAR, &value, Currtask, CURR_DB); if(value == arr_char[1]) passtest = TRUE; return passtest;}/* test updating a single float value */bool test_update_float(DB_TASK *Currtask){ struct rec1 trec1; float value = arr_float[1]; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_float = arr_float[0]; /* write a float into the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* update that field with a new value */ d_crwrite(A_FLOAT, &value, Currtask, CURR_DB); value = 0; /* read in that field and compare with original value */ d_crread(A_FLOAT, &value, Currtask, CURR_DB); if(value == arr_float[1]) passtest = TRUE; return passtest;}/* test updating a single double value */bool test_update_double(DB_TASK *Currtask){ struct rec1 trec1; double value = arr_double[1]; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_double = arr_double[0]; /* write a double into the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* update that field with a new value */ d_crwrite(A_DOUBLE, &value, Currtask, CURR_DB); value = 0; /* read in that field and compare with original value */ d_crread(A_DOUBLE, &value, Currtask, CURR_DB); if(value == arr_double[1]) passtest = TRUE; return passtest;}/* test updating a single DB_ADDR value */bool test_update_db_addr(DB_TASK *Currtask){ struct rec1 trec1; DB_ADDR value = arr_db_addr[1]; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_db_addr = arr_db_addr[0]; /* write a db_addr into the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* update that field with a new value */ d_crwrite(A_DB_ADDR, &value, Currtask, CURR_DB); value = 0x00000000; /* read in that field and compare with original value */ d_crread(A_DB_ADDR, &value, Currtask, CURR_DB); if(value == arr_db_addr[1]) passtest = TRUE; return passtest;}/* Data type delete tests *//* ========================================================== *//* test deleting a record */bool test_delete_rec(DB_TASK *Currtask){ struct rec1 trec1; bool passtest = FALSE; /* assign test data into the test record */ trec1.a_int = arr_int[0]; trec1.a_short = arr_short[0]; trec1.a_long = arr_long[0]; trec1.a_char = arr_char[0]; trec1.a_float = arr_float[0]; trec1.a_double = arr_double[0]; trec1.a_db_addr = arr_db_addr[0]; /* write the record into the database */ d_fillnew(REC1, &trec1, Currtask, CURR_DB); /* read the record back */ memset(&trec1, 0, sizeof(trec1)); d_recread(&trec1, Currtask, CURR_DB); /* delete record */ d_delete(Currtask, CURR_DB); /* check if current record has been deleted */ memset(&trec1, 0, sizeof(trec1)); if(Currtask->curr_rec == NULL_DBA || Currtask->curr_rec == S_DELETED) passtest = TRUE; return passtest;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?