void testRetrieve(void) { // This depends on testStore being run. because reasons! char names[FIELD_SIZE][NAME_LIMIT] = { "name4", "name2", "name3", "name1", }; FieldType types[FIELD_SIZE][1] = { INTEGER, TEXT, DATE, INTEGER, }; struct Field* projection = createFieldList(names, NULL, types, 4); struct Field* whereField = createField("name1", "2", INTEGER); struct Where* compare = createWhere(whereField, EQUAL); struct Command* selectCmd = createSelectCommand("table", projection, compare); struct Table* results = retrieve(selectCmd); printTable(results); assert(results->count == 1, "Did not retrieve correct number of records"); assert(strcmp(results->name, "table") == 0, "Table name was not set in the resultset"); assert(strcmp(results->tuples[0].fields[0].name, "name1") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[1].name, "name2") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[2].name, "name3") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[3].name, "name4") == 0 , "Problem with resultset"); assert(results->tuples[0].fields[4].name == 0 , "Problem with resultset"); // make sure null terminated assert(strcmp((char*) results->tuples[0].fields[0].value, "2") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[1].value, "value2") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[2].value, "1/1/2015") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[3].value, "3") == 0 , "Problem with resultset"); assert(results->tuples[0].fields[4].name == 0 , "Problem with resultset"); }
void testRetrieve(void) { // This depends on testStore being run. because reasons! char names[FIELD_SIZE][NAME_LIMIT] = { "name1", "name2", "name3", "name4", }; char values[FIELD_SIZE][VALUE_LIMIT] = { "1", "value2", "1/1/2015", "3", }; char names[FIELD_SIZE][NAME_LIMIT] = { "name4", "name2", "name3", "name1", }; FieldType types[FIELD_SIZE][1] = { INTEGER_t, TEXT_t, DATE_t, INTEGER_t, }; for (int i=0; i<4; i++) struct Field* projection[i] = createField(names[i], NULL, types[i]); struct Command* selectCmd = createSelectCommand("table", projection, NULL); struct Table* results = retrieve(selectCmd); assert(results->count == 2, "Did not retrieve correct number of records"); assert(strcmp(results->name, "table") == 0, "Table name was not set in the resultset"); assert(strcmp(results->tuples[0].fields[0].name, "name1") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[1].name, "name2") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[2].name, "name3") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[3].name, "name4") == 0 , "Problem with resultset"); assert(results->tuples[0].fields[4].name == 0 , "Problem with resultset"); // make sure null terminated assert(strcmp((char*) results->tuples[0].fields[0].value, "1") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[1].value, "value2") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[2].value, "1/1/2015") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[3].value, "3") == 0 , "Problem with resultset"); assert(results->tuples[0].fields[4].name == 0 , "Problem with resultset"); assert(strcmp(results->tuples[1].fields[0].name, "name1") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[1].fields[1].name, "name2") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[1].fields[2].name, "name3") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[1].fields[3].name, "name4") == 0 , "Problem with resultset"); assert(results->tuples[1].fields[4].name == 0 , "Problem with resultset"); // make sure null terminated assert(strcmp((char*) results->tuples[1].fields[0].value, "1") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[1].fields[1].value, "value2") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[1].fields[2].value, "1/1/2015") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[1].fields[3].value, "3") == 0 , "Problem with resultset"); assert(results->tuples[1].fields[4].name == 0 , "Problem with resultset"); }