Example #1
0
// Check every op has a unique name
TEST unique_ops() {
    for (size_t i = 0; i < E_OP__LENGTH; i++) {
        for (size_t j = 0; j < E_OP__LENGTH; j++) {
            if (i == j) continue;
            ASSERTm(tele_ops[i]->name,
                    strcmp(tele_ops[i]->name, tele_ops[j]->name) != 0);
        }
    }
    PASS();
}
TEST test_brick_zero_write() {
    brickContext bc;
    char* zeroString;
    char* refs[24];
    uint32 id1;
    uint32 id2;

    //allocate our intial block of memory:
    void* memref = malloc(24*64);

    //allocate an equally-sized block of zeroed-out memory:
    zeroString = (char*)malloc(24*64);
    memset(zeroString, '\0', 24*64);

    //initialize brick context:
    brickInit(&bc, refs, (char*)memref, 24, 64);

    //allocate memory and load strings into the allocated chunks:
    id1 = brickMalloc(&bc, 91);
    strncpy(refs[id1], "Hola! Welcome to Test-Land, where we run tests, all day long! This is a multi-block string.", 91);
    
    id2 = brickMalloc(&bc, 23);
    strncpy(refs[id2], "This is a nice program.", 23);

    //"free" allocated memory, performing a zero-write behind the scenes:
    brickFree(&bc, id1);
    brickFree(&bc, id2);

    //perform our check:
    ASSERTm("Zero-write failed.", memcmp(zeroString, memref, 24*64) == 0);

    //free our original block of memory:
    free(memref);

    PASS();
}