From: Shivam Garg Date: Wed, 28 Jun 2017 06:29:26 +0000 (+0900) Subject: Arastorage utc has been expanded and it now includes testcases testing removal of... X-Git-Tag: 1.1_Public_Release~459^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d1b9aaf90df961b8e74137b644a0e6d91a8ccfd0;p=rtos%2Ftinyara.git Arastorage utc has been expanded and it now includes testcases testing removal of relation, attributes, indexes, tuples, various aggregation queries and combined conditional queries. --- diff --git a/apps/examples/testcase/ta_tc/arastorage/utc/utc_arastorage_main.c b/apps/examples/testcase/ta_tc/arastorage/utc/utc_arastorage_main.c index 9d7e2a4..1349b41 100644 --- a/apps/examples/testcase/ta_tc/arastorage/utc/utc_arastorage_main.c +++ b/apps/examples/testcase/ta_tc/arastorage/utc/utc_arastorage_main.c @@ -35,13 +35,14 @@ #define CONFIG_MOUNT_POINT "/mnt" #endif -#define RELATION_NAME "rel" +#define RELATION_NAME1 "rel1" +#define RELATION_NAME2 "rel2" #define INDEX_BPLUS "bplustree" #define INDEX_INLINE "inline" #define QUERY_LENGTH 128 #define DATA_SET_NUM 10 -#define DATA_SET_MULTIPLIER 40 +#define DATA_SET_MULTIPLIER 80 /**************************************************************************** * Global Variables ****************************************************************************/ @@ -69,6 +70,23 @@ const static struct arastorage_data_type_s g_arastorage_data_set[DATA_SET_NUM] = {20160110, "watermelon", 10.0} }; +void check_query_result(char * query) +{ + db_result_t res; + g_cursor = db_query(query); + TC_ASSERT_NOT_NULL("db_query", g_cursor); + if (DB_SUCCESS(cursor_move_first(g_cursor))) { + do { + res = db_print_tuple(g_cursor); + TC_ASSERT("db_print_tuple",DB_SUCCESS(res)); + } while (DB_SUCCESS(cursor_move_next(g_cursor))); + } + + res = db_cursor_free(g_cursor); + TC_ASSERT("db_cursor_free", DB_SUCCESS(res)); + g_cursor = NULL; +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -123,45 +141,98 @@ void utc_arastorage_db_exec_tc_p(void) char query[QUERY_LENGTH]; int i; - snprintf(query, QUERY_LENGTH, "CREATE RELATION %s;", RELATION_NAME); + snprintf(query, QUERY_LENGTH, "CREATE RELATION %s;", RELATION_NAME1); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); + + snprintf(query, QUERY_LENGTH, "CREATE RELATION %s;", RELATION_NAME2); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); memset(query, 0, QUERY_LENGTH); snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN int IN %s;", g_attribute_set[0], - RELATION_NAME); + RELATION_NAME2); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); memset(query, 0, QUERY_LENGTH); snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN long IN %s;", g_attribute_set[1], - RELATION_NAME); + RELATION_NAME2); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); + + memset(query, 0, QUERY_LENGTH); + sprintf(query, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME2, g_attribute_set[1], INDEX_BPLUS); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); + + for (i = 0; i < DATA_SET_NUM * 10; i++) { + memset(query, 0, QUERY_LENGTH); + snprintf(query, QUERY_LENGTH, "INSERT (%d, %ld) INTO %s;", i, rand()%10000, RELATION_NAME2); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); + } + + snprintf(query, QUERY_LENGTH, "REMOVE RELATION %s;", RELATION_NAME2); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); + + snprintf(query, QUERY_LENGTH, "CREATE RELATION %s;", RELATION_NAME2); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); + + memset(query, 0, QUERY_LENGTH); + snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN int IN %s;", g_attribute_set[0], RELATION_NAME1); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); + + memset(query, 0, QUERY_LENGTH); + snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN long IN %s;", g_attribute_set[1], RELATION_NAME1); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); memset(query, 0, QUERY_LENGTH); - snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN string(32) IN %s;", - g_attribute_set[2], - RELATION_NAME); + snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN string(32) IN %s;", g_attribute_set[2], RELATION_NAME1); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); memset(query, 0, QUERY_LENGTH); - snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN int IN %s;", g_attribute_set[3], - RELATION_NAME); + snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN int IN %s;", g_attribute_set[3], RELATION_NAME1); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); + memset(query, 0, QUERY_LENGTH); + snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN int IN %s;", g_attribute_set[0], RELATION_NAME2); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); memset(query, 0, QUERY_LENGTH); - sprintf(query, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME, g_attribute_set[0], INDEX_INLINE); + snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN long IN %s;", g_attribute_set[1], RELATION_NAME2); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); + + memset(query, 0, QUERY_LENGTH); + sprintf(query, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME1, g_attribute_set[0], INDEX_INLINE); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); + + memset(query, 0, QUERY_LENGTH); + sprintf(query, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME2, g_attribute_set[1], INDEX_BPLUS); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); + + + for (i = 0; i < DATA_SET_NUM * 10; i++) { + memset(query, 0, QUERY_LENGTH); + snprintf(query, QUERY_LENGTH, "INSERT (%d, %ld) INTO %s;", i, rand()%10000, RELATION_NAME2); + res = db_exec(query); + TC_ASSERT("db_exec", DB_SUCCESS(res)); + } + #ifdef CONFIG_ARCH_FLOAT_H memset(query, 0, QUERY_LENGTH); - snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN double IN %s;", g_attribute_set[4], - RELATION_NAME); + snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN double IN %s;", g_attribute_set[4], RELATION_NAME1); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); @@ -170,7 +241,7 @@ void utc_arastorage_db_exec_tc_p(void) snprintf(query, "INSERT (%d, %ld, \'%s\', %d, %f) INTO %s;", QUERY_LENGTH, i, g_arastorage_data_set[i].long_value, g_arastorage_data_set[i].string_value, 1000 - i, - g_arastorage_data_set[i].double_value, RELATION_NAME); + g_arastorage_data_set[i].double_value, RELATION_NAME1); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); } @@ -179,13 +250,13 @@ void utc_arastorage_db_exec_tc_p(void) memset(query, 0, QUERY_LENGTH); snprintf(query, QUERY_LENGTH, "INSERT (%d, %ld, \'%s\', %d) INTO %s;", i, g_arastorage_data_set[i].long_value, - g_arastorage_data_set[i].string_value, 1000 - i, RELATION_NAME); + g_arastorage_data_set[i].string_value, 1000 - i, RELATION_NAME1); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); } #endif memset(query, 0, QUERY_LENGTH); - sprintf(query, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME, g_attribute_set[3], INDEX_BPLUS); + sprintf(query, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME1, g_attribute_set[3], INDEX_BPLUS); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); @@ -197,7 +268,7 @@ void utc_arastorage_db_exec_tc_p(void) snprintf(query, "INSERT (%d, %ld, \'%s\', %d, %f) INTO %s;", QUERY_LENGTH, i, g_arastorage_data_set[i % DATA_SET_NUM].long_value, g_arastorage_data_set[i % DATA_SET_NUM].string_value, 1000 - i, - g_arastorage_data_set[i % DATA_SET_NUM].double_value, RELATION_NAME); + g_arastorage_data_set[i % DATA_SET_NUM].double_value, RELATION_NAME1); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); } @@ -206,23 +277,21 @@ void utc_arastorage_db_exec_tc_p(void) memset(query, 0, QUERY_LENGTH); snprintf(query, QUERY_LENGTH, "INSERT (%d, %ld, \'%s\', %d) INTO %s;", i, g_arastorage_data_set[i % DATA_SET_NUM].long_value, - g_arastorage_data_set[i % DATA_SET_NUM].string_value, 1000 - i, RELATION_NAME); + g_arastorage_data_set[i % DATA_SET_NUM].string_value, 1000 - i, RELATION_NAME1); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); } #endif memset(query, 0, QUERY_LENGTH); - sprintf(query, "REMOVE INDEX %s.%s ;", RELATION_NAME, g_attribute_set[0]); + sprintf(query, "REMOVE INDEX %s.%s ;", RELATION_NAME1, g_attribute_set[0]); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); memset(query, 0, QUERY_LENGTH); - sprintf(query, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME, g_attribute_set[0], INDEX_INLINE); + sprintf(query, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME1, g_attribute_set[0], INDEX_INLINE); res = db_exec(query); TC_ASSERT("db_exec", DB_SUCCESS(res)); - - TC_SUCCESS_RESULT(); } @@ -238,17 +307,17 @@ void utc_arastorage_db_exec_tc_n(void) { db_result_t res; char query[QUERY_LENGTH]; - + char *name = "BAD_RELATION"; + char *attr_name = "attr"; /* Try to create existing relation */ memset(query, 0, QUERY_LENGTH); - snprintf(query, QUERY_LENGTH, "CREATE RELATION %s;", RELATION_NAME); + snprintf(query, QUERY_LENGTH, "CREATE RELATION %s;", RELATION_NAME1); res = db_exec(query); TC_ASSERT("db_exec", DB_ERROR(res)); /* Try to create existing attribute */ memset(query, 0, QUERY_LENGTH); - snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN int IN %s;", g_attribute_set[0], - RELATION_NAME); + snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN int IN %s;", g_attribute_set[0], RELATION_NAME1); res = db_exec(query); TC_ASSERT("db_exec", DB_ERROR(res)); @@ -256,6 +325,30 @@ void utc_arastorage_db_exec_tc_n(void) res = db_exec(NULL); TC_ASSERT("db_exec", DB_ERROR(res)); + /* Try to parse mis-spelt query */ + memset(query, 0, QUERY_LENGTH); + snprintf(query, QUERY_LENGTH, "CRAETE ATTRIBUTE %s DOMAIN int IN %s;", g_attribute_set[0], RELATION_NAME1); + res = db_exec(query); + TC_ASSERT("db_exec", DB_ERROR(res)); + + /* Create duplicate attribute */ + memset(query, 0, QUERY_LENGTH); + snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN int IN %s;", g_attribute_set[0], name); + res = db_exec(query); + TC_ASSERT("db_exec", DB_ERROR(res)); + + /* Index on non-existent attribute */ + memset(query, 0, QUERY_LENGTH); + snprintf(query, QUERY_LENGTH, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME1, attr_name, INDEX_BPLUS); + res = db_exec(query); + TC_ASSERT("db_exec", DB_ERROR(res)); + + /* execute un-implemented operation */ + memset(query, 0, QUERY_LENGTH); + snprintf(query, QUERY_LENGTH, "REMOVE ATTRIBUTE %s.%s;", RELATION_NAME1, g_attribute_set[0]); + res = db_exec(query); + TC_ASSERT("db_exec", DB_ERROR(res)); + TC_SUCCESS_RESULT(); } @@ -272,15 +365,12 @@ void utc_arastorage_db_query_tc_p(void) db_result_t res; char query[QUERY_LENGTH]; + /* Select over bplus-tree index */ #ifdef CONFIG_ARCH_FLOAT_H - snprintf(query, QUERY_LENGTH, "SELECT %s, %s, %s, %s, %s FROM %s WHERE %s < 990;", - g_attribute_set[0], - g_attribute_set[1], g_attribute_set[2], g_attribute_set[3], g_attribute_set[4], RELATION_NAME, - g_attribute_set[3]); + snprintf(query, QUERY_LENGTH, "SELECT id, date, fruit, value, weight FROM %s WHERE value < 990;", RELATION_NAME1); #else - snprintf(query, QUERY_LENGTH, "SELECT %s, %s, %s, %s FROM %s WHERE %s < 990;", g_attribute_set[0], - g_attribute_set[1], g_attribute_set[2], g_attribute_set[3], RELATION_NAME, g_attribute_set[3]); + snprintf(query, QUERY_LENGTH, "SELECT id, date, fruit, value FROM %s WHERE value < 990;", RELATION_NAME1); #endif g_cursor = db_query(query); TC_ASSERT_NOT_NULL("db_query", g_cursor); @@ -289,16 +379,40 @@ void utc_arastorage_db_query_tc_p(void) TC_ASSERT("db_cursor_free", DB_SUCCESS(res)); g_cursor = NULL; + /* Select with AND condition */ + snprintf(query, QUERY_LENGTH, "SELECT id, date FROM %s WHERE id < 25 AND id > 10;", RELATION_NAME2); + check_query_result(query); + + /* Count aggregation operation */ + snprintf(query, QUERY_LENGTH, "SELECT COUNT(id) FROM %s WHERE id = 5 OR id = 85;", RELATION_NAME2); + check_query_result(query); + + /* Mean aggregation operation */ + snprintf(query, QUERY_LENGTH, "SELECT MEAN(id) FROM %s;", RELATION_NAME2); + check_query_result(query); + + /* Sum aggregation operation */ + snprintf(query, QUERY_LENGTH, "SELECT SUM(id) FROM %s;", RELATION_NAME2); + check_query_result(query); + + /* Max aggregation operation */ + snprintf(query, QUERY_LENGTH, "SELECT MAX(id) FROM %s;", RELATION_NAME2); + check_query_result(query); + /* Min aggregation operation */ + snprintf(query, QUERY_LENGTH, "SELECT MIN(id) FROM %s;", RELATION_NAME2); + check_query_result(query); + + /* Remove operation */ + snprintf(query, QUERY_LENGTH, "REMOVE FROM %s WHERE date > 2000 AND date < 8000;", RELATION_NAME2); + check_query_result(query); + + /* Select over inline index */ #ifdef CONFIG_ARCH_FLOAT_H - snprintf(query, QUERY_LENGTH, "SELECT %s, %s, %s, %s FROM %s WHERE %s > 0;", - g_attribute_set[0], - g_attribute_set[1], g_attribute_set[2], g_attribute_set[3], RELATION_NAME, - g_attribute_set[0]); + snprintf(query, QUERY_LENGTH, "SELECT id, date, fruit, weight FROM %s WHERE id > 0;", RELATION_NAME1); #else - snprintf(query, QUERY_LENGTH, "SELECT %s, %s, %s FROM %s WHERE %s > 0;", g_attribute_set[0], - g_attribute_set[1], g_attribute_set[2], RELATION_NAME, g_attribute_set[0]); + snprintf(query, QUERY_LENGTH, "SELECT id, date, fruit FROM %s WHERE id > 0;", RELATION_NAME1); #endif g_cursor = db_query(query); TC_ASSERT_NOT_NULL("db_query", g_cursor); @@ -450,12 +564,8 @@ void utc_arastorage_db_print_tuple_tc_n(void) { db_result_t res; - if (DB_SUCCESS(cursor_move_first(g_cursor))) { - do { - res = db_print_tuple(NULL); - TC_ASSERT("db_print_tuple", DB_ERROR(res)); - } while (DB_SUCCESS(cursor_move_next(g_cursor))); - } + res = db_print_tuple(NULL); + TC_ASSERT("db_print_tuple", DB_ERROR(res)); TC_SUCCESS_RESULT(); } @@ -472,6 +582,12 @@ void utc_arastorage_db_print_value_tc_p(void) { db_result_t res; + res = db_print_value(g_cursor, 0); + TC_ASSERT("db_print_value", DB_SUCCESS(res)); + + res = db_print_value(g_cursor, 1); + TC_ASSERT("db_print_value", DB_SUCCESS(res)); + res = db_print_value(g_cursor, 2); TC_ASSERT("db_print_value", DB_SUCCESS(res)); @@ -493,7 +609,7 @@ void utc_arastorage_db_print_value_tc_n(void) res = db_print_value(NULL, 2); TC_ASSERT("db_print_value", DB_ERROR(res)); - res = db_print_value(g_cursor, 4); + res = db_print_value(g_cursor, 5); TC_ASSERT("db_print_value", DB_ERROR(res)); TC_SUCCESS_RESULT(); @@ -854,7 +970,7 @@ void utc_arastorage_cursor_is_first_row_tc_n(void) /* We need to get valid cursor for this test */ snprintf(query, QUERY_LENGTH, "SELECT %s, %s, %s FROM %s WHERE %s > 0;", g_attribute_set[0], - g_attribute_set[1], g_attribute_set[2], RELATION_NAME, g_attribute_set[0]); + g_attribute_set[1], g_attribute_set[2], RELATION_NAME1, g_attribute_set[0]); g_cursor = db_query(query); TC_ASSERT_NOT_NULL("db_query", g_cursor); res = cursor_move_last(g_cursor); @@ -902,7 +1018,7 @@ void utc_arastorage_cursor_is_last_row_tc_n(void) /* We need to get valid cursor for this test */ snprintf(query, QUERY_LENGTH, "SELECT %s, %s, %s FROM %s WHERE %s > 0;", g_attribute_set[0], - g_attribute_set[1], g_attribute_set[2], RELATION_NAME, g_attribute_set[0]); + g_attribute_set[1], g_attribute_set[2], RELATION_NAME1, g_attribute_set[0]); g_cursor = db_query(query); TC_ASSERT_NOT_NULL("db_query", g_cursor); res = cursor_move_first(g_cursor);