-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSelect.c
More file actions
78 lines (61 loc) · 2.1 KB
/
testSelect.c
File metadata and controls
78 lines (61 loc) · 2.1 KB
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
#include <stdio.h>
#include <stdlib.h>
#include "compiled_query.h"
#include "table.h"
#include "column_types.h"
#include "column.h"
#include "compiled_column.h"
extern FILE * getDataFile(char * tableName, char * mode);
extern void log(char * msg);
extern int select(CompiledQuery *compiledQueryMock, Table * tableMock, FILE * dataFileMock, int filePointer);
extern int delete(CompiledQuery *compiledQueryMock, Table * tableMock, FILE * dataFileMock, int filePointer);
int testSelect()
{
log("Unit test on selecting from data file. \n");
// Mock data
CompiledQuery * compiledQueryMock;
compiledQueryMock = malloc(sizeof(CompiledQuery));
compiledQueryMock->type = SELECT;
compiledQueryMock->columnCount = 2;
compiledQueryMock->target = "test_insert";
CompiledColumn column1;
column1.name = "first";
compiledQueryMock->queryColumns[0] = &column1;
CompiledColumn column2;
column2.name = "second";
compiledQueryMock->queryColumns[1] = &column2;
CompiledColumn column3;
compiledQueryMock->queryColumns[2] = &column3;
Table * table;
table = malloc(sizeof(Table));
table->info.columnCount = 3;
table->info.rowSize = (sizeof(char[VARCHAR_DEFAULT_LENGTH]) * 2) + sizeof(int);
Column tableColumn1;
strcpy(tableColumn1.name, "first");
tableColumn1.type = VARCHAR;
table->columns[0] = &tableColumn1;
Column tableColumn2;
strcpy(tableColumn2.name, "second");
tableColumn2.type = INT;
table->columns[1] = &tableColumn2;
Column tableColumn3;
strcpy(tableColumn3.name, "third");
tableColumn3.type = VARCHAR;
table->columns[2] = &tableColumn3;
log("Mocking done. \n");
// Run command
log("Running select command. \n");
executeSelect(compiledQueryMock, table);
log("Command ran. \n");
//pointer = table->info.rowSize;
//delete(compiledQueryMock, table, testFile, pointer);
//pointer = 0;
//for (i = 0; i < 3; i++)
//{
// select(compiledQueryMock, table, testFile, pointer);
// pointer += table->info.rowSize;
//}
free(table);
free(compiledQueryMock);
return 0;
}