Exemplo n.º 1
0
/* 0 files to go -> "0s " */
TEST word_adds_find_dupes() {
    set *s = set_new(2, dumb_hash, cmp);
    int duplicates[word_count];
    bzero(duplicates, word_count * sizeof(int));

    for (int i=0; i<word_count; i++) {
        char *w = words[i];
        ASSERT(w);
        if (set_known(s, w)) {
            duplicates[i] = 1;
        } else {
            if (set_store(s, (void *) w) == TABLE_SET_FAIL) FAIL();
        }
    }

    for (int i=0; i<word_count; i++) {
        if (0) printf("%d - %s %d\n", i, words[i], duplicates[i]);
    }

    for (int i=0; i<18; i++) {
        ASSERT_EQm("none of the first 18 are duplicates", 0, duplicates[i]);
    }

    ASSERT_EQm("words[19] (\"onion\") is a dup", 1, duplicates[19]);
    ASSERT_EQm("the last word (\"fennel\") is a dup", 1, duplicates[word_count - 1]);

    set_free(s, NULL);
    PASS();
}
Exemplo n.º 2
0
// Check every op manipulates the stack correctly
TEST op_stack_size() {
    for (size_t i = 0; i < E_OP__LENGTH; i++) {
        const tele_op_t *op = tele_ops[i];

        if (op->get != NULL) {
            scene_state_t ss = {};  // initalise to empty
                                    // (needs dedicated initaliser)
            exec_state_t es;
            es_init(&es);
            es_push(&es);
            es_variables(&es)->script_number = 1;
            command_state_t cs;
            cs_init(&cs);

            // add params to stack (plus an extra 2, to check that too many
            // values aren't removed, warning: note the maximum stack size in
            // state.h)
            const int16_t stack_extra = 2;
            for (int j = 0; j < op->params + stack_extra; j++) cs_push(&cs, 0);

            // execute get
            op->get(op->data, &ss, &es, &cs);

            // check that the stack has the correct number of items in it
            if (op->returns) {
                ASSERT_EQm(op->name, cs_stack_size(&cs), stack_extra + 1);
            }
            else {
                ASSERT_EQm(op->name, cs_stack_size(&cs), stack_extra);
            }
        }

        if (op->set != NULL) {
            scene_state_t ss = {};  // initalise to empty
                                    // (needs dedicated initaliser)
            exec_state_t es;
            es_init(&es);
            command_state_t cs;
            cs_init(&cs);

            // add params to stack (plus an extra 2, to check that too many
            // values aren't removed, warning: note the maximum stack size in
            // state.h)
            // set functions require an extra value on the stack
            const int16_t stack_extra = 2;
            for (int j = 0; j < op->params + stack_extra + 1; j++)
                cs_push(&cs, 0);

            // execute get
            op->set(op->data, &ss, &es, &cs);

            // check that the stack has the correct number of items in it
            ASSERT_EQm(op->name, cs_stack_size(&cs), stack_extra);
        }
    }
    PASS();
}
Exemplo n.º 3
0
// As match_token_should_return_op, but for mods.
TEST match_token_should_return_mod() {
    for (size_t i = 0; i < E_MOD__LENGTH; i++) {
        const tele_mod_t* mod = tele_mods[i];
        const char* text = mod->name;
        tele_data_t data;
        bool result = match_token(text, strlen(text), &data);
        ASSERT_EQm(text, result, true);
        ASSERT_EQm(text, data.tag, MOD);
        ASSERT_EQm(text, data.value, (int16_t)i);
    }
    PASS();
}
Exemplo n.º 4
0
// This test asserts that match_token always returns the correct op, it does
// this by starting with the op in question, extracting the name and running
// that through match_token.
TEST match_token_should_return_op() {
    for (size_t i = 0; i < E_OP__LENGTH; i++) {
        const tele_op_t* op = tele_ops[i];
        const char* text = op->name;
        tele_data_t data;
        bool result = match_token(text, strlen(text), &data);
        ASSERT_EQm(text, result, true);
        ASSERT_EQm(text, data.tag, OP);
        ASSERT_EQm(text, data.value, (int16_t)i);
    }
    PASS();
}
Exemplo n.º 5
0
// Check every mod manipulates the stack correctly
TEST mod_stack_size() {
    for (size_t i = 0; i < E_MOD__LENGTH; i++) {
        const tele_mod_t *mod = tele_mods[i];

        scene_state_t ss = {};  // initalise to empty
                                // (needs dedicated initaliser)
        exec_state_t es;
        es_init(&es);
        command_state_t cs;
        cs_init(&cs);

        // add params to stack (plus an extra 2, to check that too many
        // values aren't removed, warning: note the maximum stack size in
        // state.h)
        const int16_t stack_extra = 2;
        for (int j = 0; j < mod->params + stack_extra; j++) cs_push(&cs, 0);

        // execute func
        const tele_command_t sub_command = { .length = 1,
                                             .separator = 0,
                                             .data = { { .tag = OP,
                                                         .value = E_OP_A } } };
        mod->func(&ss, &es, &cs, &sub_command);

        // check that the stack has the correct number of items in it
        ASSERT_EQm(mod->name, cs_stack_size(&cs), stack_extra);
    }
Exemplo n.º 6
0
TEST test_fixed_xor(void)
{
    uint8_t buff[] = {0x13, 0x37};
    uint8_t expected[] = {0x00, 0x00};

    uint8_t *outbuff = NULL;

    // Positive tests.
    ASSERT_EQm("fixed_xor didn't work", CALL_OK, fixed_xor(sizeof(buff), buff, buff, &outbuff));
    ASSERT_EQm("Result didn't match expected", 0, memcmp(outbuff, expected, sizeof(buff)));

    // Negative tests.
    ASSERT_EQm("Bad length fail", CALL_BAD_INPUT, fixed_xor(0, NULL, NULL, NULL));

    ASSERT_EQm("Valid buff1 fail", CALL_BUFFER_NULL, fixed_xor(sizeof(buff), buff, NULL, NULL));
    ASSERT_EQm("Valid buff2 fail", CALL_BUFFER_NULL, fixed_xor(sizeof(buff), buff, buff, NULL));

    PASS();
}
Exemplo n.º 7
0
TEST unicode_ucs2 ()
{
	ASSERT_EQm("ucs2 length", tm_ucs2_str_length(pileofpoo, -1), 23);
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(pileofpoo, -1, 0), 'I');
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(pileofpoo, -1, 21), 0xd83d);
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(pileofpoo, -1, 22), 0xdca9);

	ASSERT_EQm("ucs2 length", tm_ucs2_str_length(moreutf, -1), 13);
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(moreutf, -1, 12), '!');
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(moreutf, -1, 5), 0xD834);
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(moreutf, -1, 6), 0xDF06);

	PASS();
}
Exemplo n.º 8
0
TEST unicode_case ()
{	
	uint8_t utf8char[4] = {0};
	ssize_t utf8char_len = tm_utf8_char_encode(0x1F4A9, (uint8_t*) &utf8char);
	ASSERT_EQm("utf8 encode", utf8char[0], 0xf0);
	ASSERT_EQm("utf8 encode", utf8char[1], 0x9f);
	ASSERT_EQm("utf8 encode", utf8char[2], 0x92);
	ASSERT_EQm("utf8 encode", utf8char[3], 0xa9);

	uint8_t* pileofuppercasepoo_cmp = NULL;
	tm_utf8_str_toupper(pileofpoo, -1, &pileofuppercasepoo_cmp);
	ASSERT_EQm("ucs2 length", tm_ucs2_str_length(pileofuppercasepoo_cmp, -1), 23);
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(pileofuppercasepoo_cmp, -1, 2), 'T');
	for (int i = 0; i < strlen((char*) pileofuppercasepoo); i++) {
		ASSERT_EQm("ucs2 equal", pileofuppercasepoo[i], pileofuppercasepoo_cmp[i]);
	}
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(pileofuppercasepoo_cmp, -1, 21), 0xd83d);
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(pileofuppercasepoo_cmp, -1, 22), 0xdca9);

	PASS();
}
Exemplo n.º 9
0
TEST set1_challenge2(void)
{
    char *buff1 = "1c0111001f010100061a024b53535009181c";
    char *buff2 = "686974207468652062756c6c277320657965";
    char *expected = "746865206b696420646f6e277420706c6179";

    uint8_t *buff1_bytes = (uint8_t *)malloc(strlen(buff1));
    uint8_t *buff2_bytes = (uint8_t *)malloc(strlen(buff2));
    uint8_t *expected_bytes = (uint8_t *)malloc(strlen(expected));

    size_t numbytes = strlen(expected) / 2;

    if(buff1_bytes == NULL || buff2_bytes == NULL || expected_bytes == NULL) {
        FAILm("Unable to allocate buffers.");
    }

    retval_t retval = hex2bytes(buff1, numbytes, buff1_bytes);
    if(retval != CALL_OK) {
        FAILm("Unable to convert buff1 to bytes.");
    }
    retval = hex2bytes(buff2, numbytes, buff2_bytes);
    if(retval != CALL_OK) {
        FAILm("Unable to convert buff2 to bytes.");
    }
    retval = hex2bytes(expected, numbytes, expected_bytes);
    if(retval != CALL_OK) {
        FAILm("Unable to convert expected to bytes.");
    }

    uint8_t *result = NULL;
    retval = fixed_xor(numbytes, buff1_bytes, buff2_bytes, &result);
    if(retval != CALL_OK) {
        FAILm("fixed_xor() failed");
    }

    ASSERT_EQm("Result didn't match expected", 0, memcmp(result, expected_bytes, numbytes));

    free(result);
    free(expected_bytes);
    free(buff2_bytes);
    free(buff1_bytes);

    PASS();
}