-
Notifications
You must be signed in to change notification settings - Fork 562
/
utc_arastorage_main.c
1589 lines (1339 loc) · 52.2 KB
/
utc_arastorage_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
*
* Copyright 2016 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <tinyara/config.h>
#include <stdio.h>
#include <string.h>
#include <semaphore.h>
#include <arastorage/arastorage.h>
#include <tinyara/fs/fs_utils.h>
#include "tc_common.h"
/****************************************************************************
* Definitions
****************************************************************************/
#ifndef CONFIG_MOUNT_POINT
#define CONFIG_MOUNT_POINT "/mnt"
#endif
#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 80
/****************************************************************************
* Global Variables
****************************************************************************/
static db_cursor_t *g_cursor;
const static char *g_attribute_set[] = {"id", "date", "fruit", "value", "weight"};
struct arastorage_data_type_s {
long long_value;
char *string_value;
double double_value;
};
const static struct arastorage_data_type_s g_arastorage_data_set[DATA_SET_NUM] = {
{20160101, "apple" , 1.0 },
{20160102, "banana" , 2.0 },
{20160103, "mango" , 3.0 },
{20160104, "orange" , 4.0 },
{20160105, "melon" , 5.0 },
{20160106, "kiwi" , 6.0 },
{20160107, "peach" , 7.0 },
{20160108, "cherry" , 8.0 },
{20160109, "strawberry", 9.0 },
{20160110, "watermelon", 10.0}
};
static void check_query_result(char * query)
{
db_result_t res;
g_cursor = db_query(query);
TC_ASSERT_NEQ("db_query", g_cursor, NULL);
if (DB_SUCCESS(cursor_move_first(g_cursor))) {
do {
res = db_print_tuple(g_cursor);
TC_ASSERT_EQ("db_print_tuple", DB_SUCCESS(res), true);
} while (DB_SUCCESS(cursor_move_next(g_cursor)));
}
res = db_cursor_free(g_cursor);
TC_ASSERT_EQ("db_cursor_free", DB_SUCCESS(res), true);
g_cursor = NULL;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/* Clean up all components used in these TCs */
static void cleanup(void)
{
char query[QUERY_LENGTH];
memset(query, 0, QUERY_LENGTH);
snprintf(query, QUERY_LENGTH, "REMOVE RELATION %s;", RELATION_NAME1);
db_exec(query);
memset(query, 0, QUERY_LENGTH);
snprintf(query, QUERY_LENGTH, "REMOVE RELATION %s;", RELATION_NAME2);
db_exec(query);
}
/**
* @testcase utc_arastorage_db_init_p
* @brief Initialize database resources
* @scenario Initialize resources used in database
* @apicovered db_init
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_init_p(void)
{
db_result_t res;
res = db_init();
TC_ASSERT_EQ("db_init", DB_SUCCESS(res), true);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_deinit_p
* @brief De-initialize database resources
* @scenario Release any resources used in database
* @apicovered db_deinit
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_deinit_p(void)
{
db_result_t res;
res = db_deinit();
TC_ASSERT_EQ("db_deinit", DB_SUCCESS(res), true);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_exec_p
* @brief Excute database operations
* @scenario Create relation, attributes, index and insert data
* @apicovered db_exec
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_exec_p(void)
{
db_result_t res;
char query[QUERY_LENGTH];
int i;
/* cleanup called for cleaning all undeleted resources */
cleanup();
snprintf(query, QUERY_LENGTH, "CREATE RELATION %s;", RELATION_NAME1);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
snprintf(query, QUERY_LENGTH, "CREATE RELATION %s;", RELATION_NAME2);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
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_EQ("db_exec", DB_SUCCESS(res), true);
memset(query, 0, QUERY_LENGTH);
snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN long IN %s;", g_attribute_set[1],
RELATION_NAME2);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
memset(query, 0, QUERY_LENGTH);
snprintf(query, QUERY_LENGTH, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME2, g_attribute_set[1], INDEX_BPLUS);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
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_EQ("db_exec", DB_SUCCESS(res), true);
}
memset(query, 0, QUERY_LENGTH);
snprintf(query, QUERY_LENGTH, "REMOVE RELATION %s;", RELATION_NAME2);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
memset(query, 0, QUERY_LENGTH);
snprintf(query, QUERY_LENGTH, "CREATE RELATION %s;", RELATION_NAME2);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
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_EQ("db_exec", DB_SUCCESS(res), true);
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_EQ("db_exec", DB_SUCCESS(res), true);
memset(query, 0, QUERY_LENGTH);
snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN string(32) IN %s;", g_attribute_set[2], RELATION_NAME1);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
memset(query, 0, QUERY_LENGTH);
snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN int IN %s;", g_attribute_set[3], RELATION_NAME1);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
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_EQ("db_exec", DB_SUCCESS(res), true);
memset(query, 0, QUERY_LENGTH);
snprintf(query, QUERY_LENGTH, "CREATE ATTRIBUTE %s DOMAIN long IN %s;", g_attribute_set[1], RELATION_NAME2);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
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_EQ("db_exec", DB_SUCCESS(res), true);
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_EQ("db_exec", DB_SUCCESS(res), true);
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_EQ("db_exec", DB_SUCCESS(res), true);
}
#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_NAME1);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
for (i = 0; i < DATA_SET_NUM; i++) {
memset(query, 0, QUERY_LENGTH);
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_NAME1);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
}
#else
for (i = 0; i < DATA_SET_NUM; i++) {
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_NAME1);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
}
#endif
memset(query, 0, QUERY_LENGTH);
sprintf(query, "CREATE INDEX %s.%s TYPE %s;", RELATION_NAME1, g_attribute_set[3], INDEX_BPLUS);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
#ifdef CONFIG_ARCH_FLOAT_H
for (; i < DATA_SET_NUM * DATA_SET_MULTIPLIER; i++) {
memset(query, 0, QUERY_LENGTH);
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_NAME1);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
}
#else
for (; i < DATA_SET_NUM * DATA_SET_MULTIPLIER; i++) {
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_NAME1);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
}
#endif
memset(query, 0, QUERY_LENGTH);
sprintf(query, "REMOVE INDEX %s.%s ;", RELATION_NAME1, g_attribute_set[0]);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_SUCCESS(res), true);
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_EQ("db_exec", DB_SUCCESS(res), true);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_exec_n
* @brief Excute database operations with invalid argument
* @scenario Create exiting relation, attribute and excute db with NULL value
* @apicovered db_exec
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_exec_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_NAME1);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_ERROR(res), true);
/* 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_NAME1);
res = db_exec(query);
TC_ASSERT_EQ("db_exec", DB_ERROR(res), true);
/* Try to excute db with NULL value */
res = db_exec(NULL);
TC_ASSERT_EQ("db_exec", DB_ERROR(res), true);
/* 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_EQ("db_exec", DB_ERROR(res), true);
/* 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_EQ("db_exec", DB_ERROR(res), true);
/* 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_EQ("db_exec", DB_ERROR(res), true);
/* 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_EQ("db_exec", DB_ERROR(res), true);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_query_p
* @brief Query a database
* @scenario Select data and get returned cursor
* @apicovered db_query
* @precondition utc_arastorage_db_exec_p should be passed
* @postcondition none
*/
static void utc_arastorage_db_query_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 id, date, fruit, value, weight FROM %s WHERE value < 990;", RELATION_NAME1);
#else
snprintf(query, QUERY_LENGTH, "SELECT id, date, fruit, value FROM %s WHERE value < 990;", RELATION_NAME1);
#endif
g_cursor = db_query(query);
TC_ASSERT_NEQ("db_query", g_cursor, NULL);
res = db_cursor_free(g_cursor);
TC_ASSERT_EQ("db_cursor_free", DB_SUCCESS(res), true);
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 id, date, fruit, weight FROM %s WHERE id > 0;", RELATION_NAME1);
#else
snprintf(query, QUERY_LENGTH, "SELECT id, date, fruit FROM %s WHERE id > 0;", RELATION_NAME1);
#endif
g_cursor = db_query(query);
TC_ASSERT_NEQ("db_query", g_cursor, NULL);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_query_n
* @brief Query a database with invalid argument
* @scenario Select data from invalid relation and query db with NULL value
* @apicovered db_query
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_query_n(void)
{
char query[QUERY_LENGTH];
char *name = "BAD_RELATION";
snprintf(query, QUERY_LENGTH, "SELECT %s, %s, %s FROM %s WHERE %s > 5;", g_attribute_set[0],
g_attribute_set[1], g_attribute_set[2], name, g_attribute_set[0]);
g_cursor = db_query(query);
TC_ASSERT_EQ("db_query", g_cursor, NULL);
g_cursor = db_query(NULL);
TC_ASSERT_EQ("db_query", g_cursor, NULL);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_get_result_message_p
* @brief Get database result message
* @scenario Get database result message corresponding to result value
* @apicovered db_get_result_message
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_get_result_message_p(void)
{
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_FINISHED_MSG, db_get_result_message(DB_FINISHED)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_OK_MSG, db_get_result_message(DB_OK)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_LIMIT_ERROR_MSG, db_get_result_message(DB_LIMIT_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_ALLOCATION_ERROR_MSG, db_get_result_message(DB_ALLOCATION_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_STORAGE_ERROR_MSG, db_get_result_message(DB_STORAGE_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_PARSING_ERROR_MSG, db_get_result_message(DB_PARSING_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_NAME_ERROR_MSG, db_get_result_message(DB_NAME_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_RELATIONAL_ERROR_MSG, db_get_result_message(DB_RELATIONAL_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_TYPE_ERROR_MSG, db_get_result_message(DB_TYPE_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_IMPLEMENTATION_ERROR_MSG, db_get_result_message(DB_IMPLEMENTATION_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_INDEX_ERROR_MSG, db_get_result_message(DB_INDEX_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_BUSY_ERROR_MSG, db_get_result_message(DB_BUSY_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_INCONSISTENCY_ERROR_MSG, db_get_result_message(DB_INCONSISTENCY_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_ARGUMENT_ERROR_MSG, db_get_result_message(DB_ARGUMENT_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_FULL_ERROR_MSG, db_get_result_message(DB_FULL_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_CURSOR_ERROR_MSG, db_get_result_message(DB_CURSOR_ERROR)), 0);
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_EMPTY_CURSOR_ERROR_MSG, db_get_result_message(DB_EMPTY_CURSOR_ERROR)), 0);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_get_result_message_n
* @brief Get database result message with invalid argument
* @scenario Get database result message with out of range result value
* @apicovered db_get_result_message
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_get_result_message_n(void)
{
int num;
srand(18);
num = rand() - 15;
TC_ASSERT_EQ("db_get_result_message", strcmp(DB_UNKNOWN_ERROR_MSG, db_get_result_message(num)), 0);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_print_header_p
* @brief Print a header of query result
* @scenario Print relation, attribute name of query result
* @apicovered db_print_header
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_db_print_header_p(void)
{
db_result_t res;
res = db_print_header(g_cursor);
TC_ASSERT_EQ("db_print_header", DB_SUCCESS(res), true);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_print_header_n
* @brief Print a header of query result with invalid argument
* @scenario Print relation, attribute name of query result with NULL value
* @apicovered db_print_header
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_print_header_n(void)
{
db_result_t res;
res = db_print_header(NULL);
TC_ASSERT_EQ("db_print_header", DB_ERROR(res), true);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_print_tuple_p
* @brief Print tuple pointed by cursor
* @scenario Print tuple values from the first to the last row
* @apicovered cursor_move_first, db_print_tuple, cursor_move_next
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_db_print_tuple_p(void)
{
db_result_t res;
if (DB_SUCCESS(cursor_move_first(g_cursor))) {
do {
res = db_print_tuple(g_cursor);
TC_ASSERT_EQ("db_print_tuple", DB_SUCCESS(res), true);
} while (DB_SUCCESS(cursor_move_next(g_cursor)));
}
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_print_tuple_n
* @brief Print tuple pointed by cursor with invalid argument
* @scenario Print tuple values from the first to the last row with NULL value
* @apicovered cursor_move_first, db_print_tuple, cursor_move_next
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_print_tuple_n(void)
{
db_result_t res;
res = db_print_tuple(NULL);
TC_ASSERT_EQ("db_print_tuple", DB_ERROR(res), true);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_print_value_p
* @brief Print a attribute value of tuple pointed by cursor
* @scenario Print a specific attribute value of tuple pointed by cursor
* @apicovered db_print_value
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_db_print_value_p(void)
{
db_result_t res;
res = db_print_value(g_cursor, 0);
TC_ASSERT_EQ("db_print_value", DB_SUCCESS(res), true);
res = db_print_value(g_cursor, 1);
TC_ASSERT_EQ("db_print_value", DB_SUCCESS(res), true);
res = db_print_value(g_cursor, 2);
TC_ASSERT_EQ("db_print_value", DB_SUCCESS(res), true);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_print_value_n
* @brief Print a attribute value of tuple pointed by cursor with invalid argument
* @scenario Print a specific attribute value of tuple pointed by cursor with NULL value
* @apicovered db_print_value
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_print_value_n(void)
{
db_result_t res;
res = db_print_value(NULL, 2);
TC_ASSERT_EQ("db_print_value", DB_ERROR(res), true);
res = db_print_value(g_cursor, 5);
TC_ASSERT_EQ("db_print_value", DB_ERROR(res), true);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_cursor_free_p
* @brief Free cursor
* @scenario Free allocated resources for cursor
* @apicovered db_cursor_free
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_db_cursor_free_p(void)
{
db_result_t res;
res = db_cursor_free(g_cursor);
TC_ASSERT_EQ("db_cursor_free", DB_SUCCESS(res), true);
g_cursor = NULL;
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_db_cursor_free_n
* @brief Free cursor with invalid argument
* @scenario Free allocated resources for cursor with NULL value
* @apicovered db_cursor_free
* @precondition none
* @postcondition none
*/
static void utc_arastorage_db_cursor_free_n(void)
{
db_result_t res;
res = db_cursor_free(NULL);
TC_ASSERT_EQ("db_cursor_free", DB_ERROR(res), true);
/* free cursor properly here to prevent memory leak */
res = db_cursor_free(g_cursor);
TC_ASSERT_EQ("db_cursor_free", DB_SUCCESS(res), true);
g_cursor = NULL;
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_get_count_p
* @brief Get the number of tuples in cursor
* @scenario Get the number of tuples in cursor
* @apicovered cursor_get_count
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_cursor_get_count_p(void)
{
tuple_id_t count;
count = cursor_get_count(g_cursor);
TC_ASSERT_GT("cursor_get_count", count, 0);
printf("cursor count : %d\n", count);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_get_count_n
* @brief Get the number of tuples in cursor with invalid argument
* @scenario Get the number of tuples in cursor with NULL value
* @apicovered cursor_get_count
* @precondition none
* @postcondition none
*/
static void utc_arastorage_cursor_get_count_n(void)
{
tuple_id_t count;
count = cursor_get_count(NULL);
TC_ASSERT_EQ("cursor_get_count", count, INVALID_CURSOR_VALUE);
printf("cursor count : %d\n", count);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_move_first_p
* @brief Move cursor to the first row
* @scenario Move cursor to the first row and check whether current row is set as the first row
* @apicovered cursor_move_first, cursor_get_row
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_cursor_move_first_p(void)
{
db_result_t res;
res = cursor_move_first(g_cursor);
TC_ASSERT_EQ("cursor_move_first", DB_SUCCESS(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_ASSERT_EQ("cursor_get_row", cursor_get_row(g_cursor), 0);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_move_first_n
* @brief Move cursor to the first row with invalid argument
* @scenario Move cursor to the first row with NULL value
* @apicovered cursor_move_first, cursor_get_row
* @precondition none
* @postcondition none
*/
static void utc_arastorage_cursor_move_first_n(void)
{
db_result_t res;
res = cursor_move_first(NULL);
TC_ASSERT_EQ("cursor_move_first", DB_ERROR(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_move_next_p
* @brief Move cursor to next row
* @scenario Move cursor to next row and check whether current row is set as the next row
* @apicovered cursor_move_next, cursor_get_row
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_cursor_move_next_p(void)
{
db_result_t res;
res = cursor_move_next(g_cursor);
TC_ASSERT_EQ("cursor_move_next", DB_SUCCESS(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_ASSERT_EQ("cursor_get_row", cursor_get_row(g_cursor), 1);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_move_next_n
* @brief Move cursor to next row with invalid argument
* @scenario Move cursor to next row with NULL value
* @apicovered cursor_move_next, cursor_get_row
* @precondition none
* @postcondition none
*/
static void utc_arastorage_cursor_move_next_n(void)
{
db_result_t res;
res = cursor_move_next(NULL);
TC_ASSERT_EQ("cursor_move_next", DB_ERROR(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_move_prev_p
* @brief Move cursor to previous row
* @scenario Move cursor to previous row and checkwhether current row is set as the previous row
* @apicovered cursor_move_next, cursor_get_row
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_cursor_move_prev_p(void)
{
db_result_t res;
res = cursor_move_prev(g_cursor);
TC_ASSERT_EQ("cursor_move_prev", DB_SUCCESS(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_ASSERT_EQ("cursor_get_row", cursor_get_row(g_cursor), 0);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_move_prev_n
* @brief Move cursor to previous row with invalid argument
* @scenario Move cursor to previous row with NULL value
* @apicovered cursor_move_prev, cursor_get_row
* @precondition none
* @postcondition none
*/
static void utc_arastorage_cursor_move_prev_n(void)
{
db_result_t res;
res = cursor_move_prev(NULL);
TC_ASSERT_EQ("cursor_move_prev", DB_ERROR(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_move_last_p
* @brief Move cursor to the last row
* @scenario Move cursor to the last row and check whether current row is set as the last row
* @apicovered cursor_move_last, cursor_get_row
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_cursor_move_last_p(void)
{
db_result_t res;
res = cursor_move_last(g_cursor);
TC_ASSERT_EQ("cursor_move_last", DB_SUCCESS(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_ASSERT_EQ("cursor_get_row", cursor_get_row(g_cursor), DATA_SET_NUM * DATA_SET_MULTIPLIER - 2);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_move_last_n
* @brief Move cursor to the last row with invalid argument
* @scenario Move cursor to the last row with NULL value
* @apicovered cursor_move_last, cursor_get_row
* @precondition none
* @postcondition none
*/
static void utc_arastorage_cursor_move_last_n(void)
{
db_result_t res;
res = cursor_move_last(NULL);
TC_ASSERT_EQ("cursor_move_last", DB_ERROR(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_move_last_p
* @brief Move cursor to specific row
* @scenario Move cursor to specific row and check whether current row is set as the specific row
* @apicovered cursor_move_to, cursor_get_row
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_cursor_move_to_p(void)
{
db_result_t res;
tuple_id_t row = 3;
res = cursor_move_to(g_cursor, row);
TC_ASSERT_EQ("cursor_move_to", DB_SUCCESS(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_ASSERT_EQ("cursor_get_row", cursor_get_row(g_cursor), row);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_move_last_n
* @brief Move cursor to specific row with invalid argument
* @scenario Move cursor to out of range row value and valid row value with NULL cursor value
* @apicovered cursor_move_to, cursor_get_row
* @precondition none
* @postcondition none
*/
static void utc_arastorage_cursor_move_to_n(void)
{
db_result_t res;
tuple_id_t row = 3;
res = cursor_move_to(g_cursor, -1);
TC_ASSERT_EQ("cursor_move_to", DB_ERROR(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_ASSERT_NEQ("cursor_get_row", cursor_get_row(g_cursor), row);
res = cursor_move_to(NULL, 0);
TC_ASSERT_EQ("cursor_move_to", DB_ERROR(res), true);
printf("cursor row = %d\n", cursor_get_row(g_cursor));
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_get_row_p
* @brief Get current row in cursor
* @scenario Get current row in cursor
* @apicovered cursor_get_row
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_cursor_get_row_p(void)
{
cursor_row_t row;
tuple_id_t id = 3;
row = cursor_get_row(g_cursor);
TC_ASSERT_EQ("cursor_get_row", row, id);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_get_row_n
* @brief Get current row in cursor with invalid argument
* @scenario Get current row in cursor with NULL value
* @apicovered cursor_get_row
* @precondition none
* @postcondition none
*/
static void utc_arastorage_cursor_get_row_n(void)
{
cursor_row_t row;
tuple_id_t id = 3;
row = cursor_get_row(g_cursor);
TC_ASSERT_NEQ("cursor_get_row", row, id);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_is_first_row_p
* @brief Check whether cursor points the first row
* @scenario Move cursor to the first row and check whether cursor points the first row
* @apicovered cursor_move_first, cursor_is_first_row
* @precondition utc_arastorage_db_exec_p, utc_arastorage_db_query_p should be passed
* @postcondition none
*/
static void utc_arastorage_cursor_is_first_row_p(void)
{
db_result_t res;
res = cursor_move_first(g_cursor);
TC_ASSERT_EQ("cursor_move_first", DB_SUCCESS(res), true);
TC_ASSERT_EQ("cursor_is_first_row", cursor_is_first_row(g_cursor), true);
TC_SUCCESS_RESULT();
}
/**
* @testcase utc_arastorage_cursor_is_first_row_n
* @brief Check whether cursor points the first row with invalid argument
* @scenario Move cursor to the last row and check whether current row is set as the first row,
* Check whether cursor points the first row with NULL value
* @apicovered db_query, cursor_move_last, cursor_is_first_row
* @precondition none
* @postcondition none
*/
static void utc_arastorage_cursor_is_first_row_n(void)
{
db_result_t res;
char query[QUERY_LENGTH];
/* 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_NAME1, g_attribute_set[0]);
g_cursor = db_query(query);
TC_ASSERT_NEQ("db_query", g_cursor, NULL);
res = cursor_move_last(g_cursor);
TC_ASSERT_EQ("cursor_move_last", DB_SUCCESS(res), true);
/* Cursor is valid, but it isn't pointing first row */
TC_ASSERT_NEQ("cursor_is_first_row", cursor_is_first_row(g_cursor), true);
/* Invalid argument */