static void testValues(CustomerRecord * record, const char * name, const char * address,
        const char * postalCode, const char * town) {
    ASSERT_EQUAL_STRING(record->name, name);
    ASSERT_EQUAL_STRING(record->address, address);
    ASSERT_EQUAL_STRING(record->postalCode, postalCode);
    ASSERT_EQUAL_STRING(record->town, town);
}
static void test_readAndWriteString(void) {
    FILE * file;
    char * result;

    file = fopen("../readwritestring-unittest.db", "w+b");

    writeString("abc", file);
    writeString("abc\ndef", file);
    writeString("abc\n\tdef\n", file);

    fseek(file, 0, SEEK_SET);

    result = readString(file);
    ASSERT_EQUAL_STRING(result, "abc");
    free(result);

    result = readString(file);
    ASSERT_EQUAL_STRING(result, "abc\ndef");
    free(result);

    result = readString(file);
    ASSERT_EQUAL_STRING(result, "abc\n\tdef\n");
    free(result);

    fclose(file);
}
static void test_OperatorTable_findOperator(void) {

    int idx;
    OperatorTable * table = OperatorTable_create();

    idx = OperatorTable_setOperator(table, "moi", "pass");
    idx = OperatorTable_setOperator(table, "toi", "tonpass");
    idx = OperatorTable_setOperator(table, "moi", "monpass");
    idx = OperatorTable_setOperator(table, "elle", "sonpass");
    idx = OperatorTable_setOperator(table, "lui", "sonpass");
    idx = OperatorTable_setOperator(table, "eux", "leurpass");

    idx = OperatorTable_findOperator(table, "toi");
    ASSERT_EQUAL(idx, 1);
    ASSERT_EQUAL_STRING(OperatorTable_getName(table, idx), "toi");

    idx = OperatorTable_findOperator(table, "moi");
    ASSERT_EQUAL(idx, 0);
    ASSERT_EQUAL_STRING(OperatorTable_getName(table, idx), "moi");

    idx = OperatorTable_findOperator(table, "elle");
    ASSERT_EQUAL(idx, 2);
    ASSERT_EQUAL_STRING(OperatorTable_getName(table, idx), "elle");

    idx = OperatorTable_findOperator(table, "lui");
    ASSERT_EQUAL(idx, 3);
    ASSERT_EQUAL_STRING(OperatorTable_getName(table, idx), "lui");

    idx = OperatorTable_findOperator(table, "eux");
    ASSERT_EQUAL(idx, 4);
    ASSERT_EQUAL_STRING(OperatorTable_getName(table, idx), "eux");

    OperatorTable_destroy(table);
}
Beispiel #4
0
void AppendTest()
{
    StringBuffer buffer;
    TextStatus status;
    char* string;
    InitializeStringBuffer(&buffer);
    status = AppendString(&buffer, "Buffer");
    ASSERT_EQUAL_INT(TEXT_OK, status);
    EXPECT_EQUAL_INT(6, buffer.length);
    EXPECT_EQUAL_INT(64, buffer.capacity);
    ASSERT_EQUAL_STRING("Buffer", buffer.buffer);
    status = AppendString(&buffer, " test");
    ASSERT_EQUAL_INT(TEXT_OK, status);
    EXPECT_EQUAL_INT(11, buffer.length);
    EXPECT_EQUAL_INT(64, buffer.capacity);
    ASSERT_EQUAL_STRING("Buffer test", buffer.buffer);
    string = DetachString(&buffer);
    EXPECT_EQUAL_STRING("Buffer test", string);
    free(string);
}
static void test_OperatorTable_loadAndSave(void) {
    OperatorTable * table1 = OperatorTable_create();
    OperatorTable * table2;

    OperatorTable_setOperator(table1, "moi", "pass");
    OperatorTable_setOperator(table1, "toi", "tonpass");
    OperatorTable_setOperator(table1, "moi", "monpass");
    OperatorTable_setOperator(table1, "elle", "sonpass");
    OperatorTable_setOperator(table1, "lui", "sonpass");
    OperatorTable_setOperator(table1, "eux", "leurpass");

    OperatorTable_saveToFile(table1, "../operator-unittest.db");
    table2 = OperatorTable_loadFromFile("../operator-unittest.db");

    ASSERT_EQUAL(OperatorTable_getRecordCount(table2), 5);
    ASSERT_EQUAL_STRING(OperatorTable_getName(table2, OperatorTable_findOperator(table2, "moi")),
            "moi");
    ASSERT_EQUAL_STRING(
            OperatorTable_getPassword(table2, OperatorTable_findOperator(table2, "moi")), "monpass");
    ASSERT_EQUAL_STRING(OperatorTable_getName(table2, OperatorTable_findOperator(table2, "toi")),
            "toi");
    ASSERT_EQUAL_STRING(
            OperatorTable_getPassword(table2, OperatorTable_findOperator(table2, "toi")), "tonpass");
    ASSERT_EQUAL_STRING(OperatorTable_getName(table2, OperatorTable_findOperator(table2, "elle")),
            "elle");
    ASSERT_EQUAL_STRING(OperatorTable_getPassword(table2,
            OperatorTable_findOperator(table2, "elle")), "sonpass");
    ASSERT_EQUAL_STRING(OperatorTable_getName(table2, OperatorTable_findOperator(table2, "lui")),
            "lui");
    ASSERT_EQUAL_STRING(
            OperatorTable_getPassword(table2, OperatorTable_findOperator(table2, "lui")), "sonpass");
    ASSERT_EQUAL_STRING(OperatorTable_getName(table2, OperatorTable_findOperator(table2, "eux")),
            "eux");
    ASSERT_EQUAL_STRING(
            OperatorTable_getPassword(table2, OperatorTable_findOperator(table2, "eux")),
            "leurpass");

    OperatorTable_destroy(table1);
    OperatorTable_destroy(table2);
}
static void test_CustomerRecord_accessors(void) {
    char * str;
    CustomerRecord record;
    CustomerRecord_FieldProperties properties;

    CustomerRecord_init(&record);

    properties = CustomerRecord_getFieldProperties(CUSTOMERRECORD_NAME_FIELD);
    properties.setValue(&record, "NAME");
    str = properties.getValue(&record);
    ASSERT_EQUAL_STRING(str, "NAME");
    free(str);
    ASSERT_EQUAL_STRING(record.name, "NAME");

    properties = CustomerRecord_getFieldProperties(CUSTOMERRECORD_ADDRESS_FIELD);
    properties.setValue(&record, "ADDRESS");
    str = properties.getValue(&record);
    ASSERT_EQUAL_STRING(str, "ADDRESS");
    free(str);
    ASSERT_EQUAL_STRING(record.address, "ADDRESS");

    properties = CustomerRecord_getFieldProperties(CUSTOMERRECORD_POSTALCODE_FIELD);
    properties.setValue(&record, "POSTAL");
    str = properties.getValue(&record);
    ASSERT_EQUAL_STRING(str, "POSTAL");
    free(str);
    ASSERT_EQUAL_STRING(record.postalCode, "POSTAL");

    properties = CustomerRecord_getFieldProperties(CUSTOMERRECORD_TOWN_FIELD);
    properties.setValue(&record, "TOWN");
    str = properties.getValue(&record);
    ASSERT_EQUAL_STRING(str, "TOWN");
    free(str);
    ASSERT_EQUAL_STRING(record.town, "TOWN");

    CustomerRecord_finalize(&record);
}
static void test_formatDate(void) {
    char * result = formatDate(1, 9, 2010);
    ASSERT_EQUAL_STRING(result, "01/09/2010");
    free(result);
}
static void test_computeDocumentNumber(void) {
    char * result = computeDocumentNumber(123456789);
    ASSERT_EQUAL_STRING(result, "21I3V9");
    free(result);
}
static void test_OperatorTable_getAndSetOperator(void) {
    int idx;
    OperatorTable * table = OperatorTable_create();

    idx = OperatorTable_setOperator(table, "moi", "pass");
    ASSERT_EQUAL(idx, 0);
    ASSERT_EQUAL(1, OperatorTable_getRecordCount(table));
    ASSERT_EQUAL_STRING(table->records[0][0], "moi");
    ASSERT_EQUAL_STRING(table->records[0][1], "pass");
    ASSERT_EQUAL_STRING(OperatorTable_getName(table, 0), "moi");
    ASSERT_EQUAL_STRING(OperatorTable_getPassword(table, 0), "pass");

    idx = OperatorTable_setOperator(table, "toi", "tonpass");
    ASSERT_EQUAL(idx, 1);
    ASSERT_EQUAL(2, OperatorTable_getRecordCount(table));
    ASSERT_EQUAL_STRING(table->records[1][0], "toi");
    ASSERT_EQUAL_STRING(table->records[1][1], "tonpass");
    ASSERT_EQUAL_STRING(OperatorTable_getName(table, 1), "toi");
    ASSERT_EQUAL_STRING(OperatorTable_getPassword(table, 1), "tonpass");

    idx = OperatorTable_setOperator(table, "moi", "monpass");
    ASSERT_EQUAL(idx, 0);
    ASSERT_EQUAL(2, OperatorTable_getRecordCount(table));
    ASSERT_EQUAL_STRING(table->records[0][0], "moi");
    ASSERT_EQUAL_STRING(table->records[0][1], "monpass");
    ASSERT_EQUAL_STRING(OperatorTable_getName(table, 0), "moi");
    ASSERT_EQUAL_STRING(OperatorTable_getPassword(table, 0), "monpass");

    OperatorTable_destroy(table);
}