/**
 * Test characters that should be unchanged
 * Mostly a copy from URL encoding
 */
static char* testXmlDecodeUntouched(void)
{
    const char* lower   = "abcdefghijklmnopqrstuvwxyz";
    const char* upper   = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const char* digits  = "0123456789";
    const char* special = ".-_~!$()*,;:@/?";
    char buf[1000];

    size_t d = 0;

    memset(buf, 0, sizeof(buf));
    d = modp_xml_decode(buf, lower, strlen(lower));
    mu_assert_int_equals(d, strlen(lower));
    mu_assert_str_equals(buf, lower);

    memset(buf, 0, sizeof(buf));
    d = modp_xml_decode(buf, upper, strlen(upper));
    mu_assert_int_equals(d, strlen(upper));
    mu_assert_str_equals(buf, upper);

    memset(buf, 0, sizeof(buf));
    d = modp_xml_decode(buf, digits, strlen(digits));
    mu_assert_int_equals(d, strlen(digits));
    mu_assert_str_equals(buf, digits);

    memset(buf, 0, sizeof(buf));
    d = modp_xml_decode(buf, special, strlen(special));
    mu_assert_int_equals(d, strlen(special));
    mu_assert_str_equals(buf, special);

    return 0;
}
Esempio n. 2
0
int test_sky_action_file_save() {
    int rc;
    struct tagbstring path = bsStatic("tmp/actions");
    
    // Initialize action file.
    sky_action_file *action_file = sky_action_file_create();
    sky_action_file_set_path(action_file, &path);
    
    // Action 1
    sky_action *action1 = sky_action_create();
    action1->name = bfromcstr("foo");
    rc = sky_action_file_add_action(action_file, action1);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(action_file->action_count, 1);

    // Action 2
    sky_action *action2 = sky_action_create();
    action2->name = bfromcstr("this_is_a_really_long_action_name_woohoo");
    rc = sky_action_file_add_action(action_file, action2);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(action_file->action_count, 2);

    // Save
    rc = sky_action_file_save(action_file);
    mu_assert_int_equals(rc, 0);
    mu_assert_file("tmp/actions", "tests/fixtures/action_files/0");

    sky_action_file_free(action_file);
    return 0;
}
Esempio n. 3
0
static char* testSimpleEscape()
{
    char buf[100];
    const char* s1 = "\\this\nis a string\n";
    const char* s2 = "\\\\this\\nis a string\\n";
    const int len1 = strlen(s1);
    const int len2 = strlen(s2);
    int d = modp_bjavascript_encode(buf, s1, len1);

    mu_assert_int_equals(len2, d);
    mu_assert_str_equals(buf, s2);

    int sz = modp_bjavascript_encode_strlen(s1, len1);
    mu_assert_int_equals(sz, len2);

    /*
     * Test the Raw escape '\' --> '\\'
     */
    char ibuf[] = {'\\', '\0'};
    memset(buf, 0, sizeof(buf));   
    d = modp_bjavascript_encode(buf,ibuf, 1);
    mu_assert_int_equals(buf[0], '\\');
    mu_assert_int_equals(buf[1], '\\');
    mu_assert_int_equals(buf[2], 0);

    return 0;
}
Esempio n. 4
0
int test_sky_data_file_load_empty() {
    cleantmp();
    
    int rc;
    sky_data_file *data_file = sky_data_file_create();
    data_file->block_size = 128;
    data_file->path = bfromcstr("tmp/data");
    data_file->header_path = bfromcstr("tmp/header");
    
    rc = sky_data_file_load(data_file);
    mu_assert_int_equals(rc, 0);

    mu_assert_bool(data_file->data != NULL);
    mu_assert_bool(data_file->data_fd != 0);
    mu_assert_long_equals(data_file->data_length, 128L);
    mu_assert_bool(data_file->blocks != NULL);
    mu_assert_int_equals(data_file->block_count, 1);
    mu_assert_file("tmp/data", "tests/fixtures/data_files/0/data");
    mu_assert_file("tmp/header", "tests/fixtures/data_files/0/header");

    rc = sky_data_file_unload(data_file);
    mu_assert_int_equals(rc, 0);
    
    mu_assert_bool(data_file->data == NULL);
    mu_assert_bool(data_file->data_fd == 0);
    mu_assert_long_equals(data_file->data_length, 0L);
    mu_assert_bool(data_file->blocks == NULL);
    mu_assert_int_equals(data_file->block_count, 0);

    sky_data_file_free(data_file);
    return 0;
}
Esempio n. 5
0
int test_sky_table_open() {
    struct tagbstring lock_file_path = bsStatic("tmp/.skylock");
    struct tagbstring data_file_path = bsStatic("tmp/0/data");
    struct tagbstring header_file_path = bsStatic("tmp/0/header");
    cleantmp();
    
    int rc;
    sky_table *table = sky_table_create();
    table->path = bfromcstr("tmp");
    
    // Open table.
    rc = sky_table_open(table);
    mu_assert_int_equals(rc, 0);
    mu_assert(sky_file_exists(&lock_file_path), "");
    mu_assert(sky_file_exists(&data_file_path), "");
    mu_assert(sky_file_exists(&header_file_path), "");
    
    // Close table.
    rc = sky_table_close(table);
    mu_assert_int_equals(rc, 0);
    mu_assert(!sky_file_exists(&lock_file_path), "");
    mu_assert(sky_file_exists(&data_file_path), "");
    mu_assert(sky_file_exists(&header_file_path), "");

    sky_table_free(table);
    return 0;
}
Esempio n. 6
0
/** \brief test bad input lengths
 * The b85 encode only accepts multiples of 4.
 *
 * The b85 decoder only accepts a multiple of 5.
 *
 */
static char* testBadInputLength(void)
{
    char buf[100];
    mu_assert_int_equals(-1, modp_b85_encode(buf, buf, (size_t)5));
    mu_assert_int_equals(-1, modp_b85_decode(buf, buf, (size_t)11));
    return 0;
}
static char* testUtf8ValidateAscii(void)
{
    int d = modp_utf8_validate("abc", (size_t)3);
    mu_assert_int_equals(d, 0);

    /* with null and highest ASCII character 127 */
    d = modp_utf8_validate("a\x00\x7Fz", (size_t) 4);
    mu_assert_int_equals(d, 0);
    return 0;
}
Esempio n. 8
0
/** \brief test input that is a multiple of 2 (special case in code)
 */
static char* testDecodeMutlipleOf2(void)
{
    char obuf[100];
    memset(obuf, 0xff, sizeof(obuf));

    mu_assert_int_equals(1, modp_b16_decode(obuf, "01", (size_t)2));
    mu_assert_int_equals(1, obuf[0]);

    return 0;
}
Esempio n. 9
0
int test_sky_aggregate() {
    importtmp("tests/fixtures/sky_lua/1/data.json");
    sky_table *table = sky_table_create();
    table->path = bfromcstr("tmp");
    sky_table_open(table);
    sky_data_descriptor *descriptor = sky_data_descriptor_create();

    // Initialize the path iterator.
    sky_path_iterator iterator;
    sky_path_iterator_init(&iterator);
    iterator.cursor.data_descriptor = descriptor;
    sky_path_iterator_set_tablet(&iterator, table->tablets[0]);

    struct tagbstring source = bsStatic(
        "function aggregate(cursor, data)\n"
        "  data.path_count = (data.path_count or 0) + 1\n"
        "  while cursor:next() do\n"
        "    data.event_count = (data.event_count or 0) + 1\n"
        "    data.z = (data.z or 0) + cursor.event.x + cursor.event.y\n"
        "  end\n"
        "end\n"
    );
    lua_State *L = NULL;
    int rc = sky_lua_initscript_with_table(&source, table, descriptor, &L);
    mu_assert_int_equals(rc, 0);

    // Allocate data.
    mu_assert_int_equals(descriptor->data_sz, 24);
    iterator.cursor.data = calloc(1, descriptor->data_sz);

    // Start benchmark.
    struct timeval tv;
    gettimeofday(&tv, NULL);
    int64_t t0 = (tv.tv_sec*1000) + (tv.tv_usec/1000);

    // Call sky_aggregate() function.
    uint32_t i;
    for(i=0; i<1; i++) {
        //sky_path_iterator_set_tablet(&iterator, table->tablets[0]);
        lua_getglobal(L, "sky_aggregate");
        lua_pushlightuserdata(L, &iterator);
        lua_call(L, 1, 0);
    }

    // End benchmark.
    gettimeofday(&tv, NULL);
    int64_t t1 = (tv.tv_sec*1000) + (tv.tv_usec/1000);
    printf("[lua] t=%.3fs\n", ((float)(t1-t0))/1000);

    sky_path_iterator_uninit(&iterator);
    sky_table_free(table);
    free(iterator.cursor.data);
    return 0;
}
Esempio n. 10
0
int test_sky_block_get_path_stats_with_no_event() {
    sky_data_file *data_file;
    INIT_DATA_FILE("tests/fixtures/blocks/path_stats/a");
    sky_block_path_stat *paths = NULL;
    uint32_t path_count = 0;
    int rc = sky_block_get_path_stats(data_file->blocks[0], NULL, &paths, &path_count);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(path_count, 2);
    ASSERT_PATH_STAT(paths[0], 3, 0L, 41L, 41L);
    ASSERT_PATH_STAT(paths[1], 10, 41L, 60L, 19L);
    sky_data_file_free(data_file);
    return 0;
}
Esempio n. 11
0
int test_sky_block_unpack() {
    sky_block *block = sky_block_create(NULL);
    size_t sz;
    int rc = sky_block_unpack(block, &DATA, &sz);
    mu_assert_int_equals(rc, 0);
    mu_assert_long_equals(sz, SKY_BLOCK_HEADER_SIZE);
    mu_assert_int_equals(block->min_object_id, 10);
    mu_assert_int_equals(block->max_object_id, 20);
    mu_assert_int64_equals(block->min_timestamp, 30LL);
    mu_assert_int64_equals(block->max_timestamp, 40LL);
    sky_block_free(block);
    return 0;
}
Esempio n. 12
0
int test_sky_cursor_set_string() {
    size_t sz;
    sky_cursor *cursor = sky_cursor_new(0, 1);
    sky_cursor_set_data_sz(cursor, sizeof(test2_t));
    sky_cursor_set_property(cursor, 1, offsetof(test2_t, string_value), sizeof(sky_string), "string");
    mu_assert_int_equals(cursor->property_zero_descriptor[1].offset, 32);
    sky_cursor_set_value(cursor, cursor->data, 1, STRING_DATA, &sz);
    mu_assert_long_equals(sz, 4L);
    mu_assert_int_equals(((test2_t*)cursor->data)->string_value.length, 3);
    mu_assert_bool(((test2_t*)cursor->data)->string_value.data == &STRING_DATA[1]);
    sky_cursor_free(cursor);
    return 0;
}
Esempio n. 13
0
int test_sky_path_iterator_single_block_next() {
    loadtmp("tests/fixtures/path_iterator/0");
    int rc;
    void *block_ptr, *ptr;
    sky_data_file *data_file = sky_data_file_create();
    data_file->path = bfromcstr("tmp/data");
    data_file->header_path = bfromcstr("tmp/header");
    sky_data_file_load(data_file);

    sky_block_get_ptr(data_file->blocks[0], &block_ptr);
    
    sky_path_iterator *iterator = sky_path_iterator_create();
    sky_path_iterator_set_block(iterator, data_file->blocks[0]);
    mu_assert(iterator->block == data_file->blocks[0], "");
    mu_assert(iterator->data_file == NULL, "");
    mu_assert_int_equals(iterator->block_index, 0);

    // Path 1
    rc = sky_path_iterator_get_ptr(iterator, &ptr);
    mu_assert_int_equals(rc, 0);
    mu_assert_long_equals(ptr-block_ptr, 0L);
    mu_assert_bool(!iterator->eof);

    // Path 2
    rc = sky_path_iterator_next(iterator);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(iterator->byte_index, 19);
    mu_assert_bool(!iterator->eof);
    rc = sky_path_iterator_get_ptr(iterator, &ptr);
    mu_assert_int_equals(rc, 0);
    mu_assert_long_equals(ptr-block_ptr, 19L);
    
    // Path 3
    rc = sky_path_iterator_next(iterator);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(iterator->byte_index, 47);
    mu_assert_bool(!iterator->eof);
    rc = sky_path_iterator_get_ptr(iterator, &ptr);
    mu_assert_int_equals(rc, 0);
    mu_assert_long_equals(ptr-block_ptr, 47L);
    
    // EOF
    rc = sky_path_iterator_next(iterator);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(iterator->byte_index, 0);
    mu_assert_bool(iterator->eof);

    sky_path_iterator_free(iterator);
    sky_data_file_free(data_file);
    return 0;
}
Esempio n. 14
0
int test_sky_data_file_deduplicate_insertion_event_data() {
    struct tagbstring STR1 = bsStatic("foo");
    struct tagbstring STR2 = bsStatic("bar");
    struct tagbstring STR3 = bsStatic("zzz");
    int rc;
    sky_event *event;
    sky_data_file *data_file;
    INIT_DATA_FILE("tests/fixtures/data_files/dedup/0/a", 0);

    // Add initial event.
    event = sky_event_create(1, 10LL, 1);
    event->data_count = 8;
    event->data = calloc(event->data_count, sizeof(*event->data));
    event->data[0] = sky_event_data_create_string(-1, &STR2);
    event->data[1] = sky_event_data_create_int(-2, 200);
    event->data[2] = sky_event_data_create_double(-3, 1.0);
    event->data[3] = sky_event_data_create_boolean(-4, false);
    event->data[4] = sky_event_data_create_string(1, &STR1);
    event->data[5] = sky_event_data_create_int(2, 100);
    event->data[6] = sky_event_data_create_double(3, 100.2);
    event->data[7] = sky_event_data_create_boolean(4, true);
    rc = sky_data_file_add_event(data_file, event);
    mu_assert_int_equals(rc, 0);
    
    ASSERT_DATA_FILE("tests/fixtures/data_files/dedup/0/b");

    // Add the same event data, different timestamp.
    event->timestamp = 11LL;
    rc = sky_data_file_add_event(data_file, event);
    mu_assert_int_equals(rc, 0);
    sky_event_free(event);
    
    ASSERT_DATA_FILE("tests/fixtures/data_files/dedup/0/c");

    // Add somewhat different object state event.
    event = sky_event_create(1, 12LL, 0);
    event->data_count = 4;
    event->data = calloc(event->data_count, sizeof(*event->data));
    event->data[0] = sky_event_data_create_string(1, &STR3);
    event->data[1] = sky_event_data_create_int(2, 20);
    event->data[2] = sky_event_data_create_double(3, 100.2);
    event->data[3] = sky_event_data_create_boolean(4, false);
    rc = sky_data_file_add_event(data_file, event);
    mu_assert_int_equals(rc, 0);
    sky_event_free(event);

    ASSERT_DATA_FILE("tests/fixtures/data_files/dedup/0/d");

    sky_data_file_free(data_file);
    return 0;
}
Esempio n. 15
0
static char* test_qs_parse8()
{
    struct qsiter_t qsi;
    
    const char* s = "&&";

    qsiter_reset(&qsi, s, strlen(s));

    bool ok = qsiter_next(&qsi);
    mu_assert(ok);
    mu_assert_int_equals(qsi.pos, 1);
    mu_assert_int_equals(qsi.len, strlen(s));
    mu_assert_int_equals(qsi.keylen, 0);
    mu_assert_int_equals(qsi.vallen, 0);
    mu_assert(!memcmp("", qsi.key, qsi.keylen));
    mu_assert(!memcmp("", qsi.val, qsi.vallen));
    
    ok = qsiter_next(&qsi);
    mu_assert(ok);
    mu_assert_int_equals(qsi.pos, 2);
    mu_assert_int_equals(qsi.len, strlen(s));
    mu_assert_int_equals(qsi.keylen, 0);
    mu_assert_int_equals(qsi.vallen, 0);
    mu_assert(!memcmp("", qsi.key, qsi.keylen));
    mu_assert(!memcmp("", qsi.val, qsi.vallen));

    ok = qsiter_next(&qsi);
    mu_assert(!ok);

    return 0;
}
Esempio n. 16
0
static char* test_qs_parse3()
{
    struct qsiter_t qsi;
    
    const char* s = "foo=bar&ding=bat";

    qsiter_reset(&qsi, s, strlen(s));

    bool ok = qsiter_next(&qsi);
    mu_assert(ok);
    mu_assert_int_equals(qsi.pos, 8);
    mu_assert_int_equals(qsi.len, strlen(s));
    mu_assert_int_equals(qsi.keylen, 3);
    mu_assert_int_equals(qsi.vallen, 3);
    mu_assert(!memcmp("foo", qsi.key, qsi.keylen));
    mu_assert(!memcmp("bar", qsi.val, qsi.vallen));

    ok = qsiter_next(&qsi);
    mu_assert(ok);
    mu_assert_int_equals(qsi.pos, strlen(s));
    mu_assert_int_equals(qsi.len, strlen(s));
    mu_assert_int_equals(qsi.keylen, 4);
    mu_assert_int_equals(qsi.vallen, 3);
    mu_assert(!memcmp("ding", qsi.key, qsi.keylen));
    mu_assert(!memcmp("bat", qsi.val, qsi.vallen));

    ok = qsiter_next(&qsi);
    mu_assert(!ok);

    return 0;
}
Esempio n. 17
0
static char* testEncodeDecode(void)
{
    char ibuf[10]; /* input */
    char obuf[10]; /* output */
    char rbuf[10]; /* final result */
    size_t d;
    int i, j, k, l;
    for (i = 0; i < 256; ++i) {
        for (j = 0; j < 256; j += 16) { /* save some time +=16 */
            for (k = 0; k < 256; k += 8) { /* save some time += 8 */
                for (l = 0; l < 256; ++l) {
                    ibuf[0] = (char)i;
                    ibuf[1] = (char)j;
                    ibuf[2] = (char)k;
                    ibuf[3] = (char)l;
                    memset(obuf, 255, sizeof(obuf));
                    d = modp_b85_encode(obuf, ibuf, (size_t)4);
                    mu_assert_int_equals(5, d);
                    mu_assert_int_equals(0, obuf[5]);
                    memset(rbuf, 255, sizeof(rbuf));
                    d = modp_b85_decode(rbuf, obuf, (size_t)5);
                    mu_assert_int_equals(4, d);
                    mu_assert_int_equals(ibuf[0], rbuf[0]);
                    mu_assert_int_equals(ibuf[1], rbuf[1]);
                    mu_assert_int_equals(ibuf[2], rbuf[2]);
                    mu_assert_int_equals(ibuf[3], rbuf[3]);
                    mu_assert_int_equals(-1, rbuf[4]);
                }
            }
        }
    }
    return 0;
}
Esempio n. 18
0
/**
 * Test empty input to encode and decode
 */
static char* test_qs_init()
{
    struct qsiter_t qsi;
    
    const char* s = "foobar";

    qsiter_reset(&qsi, s, strlen(s));

    mu_assert_int_equals(qsi.pos, 0);
    mu_assert_int_equals(qsi.len, strlen(s));
    mu_assert_int_equals(qsi.keylen, 0);
    mu_assert_int_equals(qsi.vallen, 0);
    
    return 0;
}
Esempio n. 19
0
/**
 * Tests input where no escaping happens
 */
static char* testNoEscape()
{
    char buf[100];
    const char* s1 = "this is a string";
    const int len1 = strlen(s1);
    int d = modp_bjavascript_encode(buf, s1, len1);

    mu_assert_int_equals(len1, d);
    mu_assert_str_equals(buf, s1);

    int sz = modp_bjavascript_encode_strlen(s1, len1);
    mu_assert_int_equals(sz, len1);

    return 0;
}
Esempio n. 20
0
static char* testDecodeErrors(void)
{
    int i;
    size_t y;
    char out[1000];
    char decode[5];
    char msg[100];

    /* negative length */
    memset(decode, 1, sizeof(decode));
    y = modp_b64_decode(out, decode, (size_t)-1);
    mu_assert_int_equals(-1, y);

    /* test bad input -  all combinations */
    char goodchar = 'A';
    char badchar = '~';
    for (i = 1; i < 16; ++i) {
        decode[0] = (char)(((i & 0x01) == 0) ? goodchar : badchar);
        decode[1] = (char)(((i & 0x02) == 0) ? goodchar : badchar);
        decode[2] = (char)(((i & 0x04) == 0) ? goodchar : badchar);
        decode[3] = (char)(((i & 0x08) == 0) ? goodchar : badchar);
        decode[4] = '\0';

        sprintf(msg, "i = %d, %s", i, decode);
        y = modp_b64_decode(out, decode, (size_t)4);
        mu_assert_int_equals_msg(msg, (size_t)-1, y);
    }


    /*  test just 1-4 padchars */
    for (i = 0; i < 4; ++i) {
        decode[i] = '=';
        decode[i+1] = '\0';
        y = modp_b64_decode(out, decode, (size_t)(i+1));
        sprintf(msg, "i=%d, b64=%s", i, decode);
        mu_assert_int_equals_msg(msg, (size_t)-1, y);
    }

    /* Test good+3 pad chars (should be impossible) */
    decode[0] = 'A';
    decode[1] = '=';
    decode[2] = '=';
    decode[3] = '=';
    y = modp_b64_decode(out, decode, (size_t)4);
    mu_assert_int_equals(-1, y);

    return 0;
}
Esempio n. 21
0
static char* testBinaryEscape()
{
    char buf[100];
    const char s1[] = {1,2,3,4,0};
    const char* s2 = "\\x01\\x02\\x03\\x04";
    const int len1 = strlen(s1);
    const int len2 = strlen(s2);
    int d = modp_bjavascript_encode(buf, s1, len1);

    mu_assert_int_equals(len2, d);
    mu_assert_str_equals(buf, s2);

    int sz = modp_bjavascript_encode_strlen(s1, len1);
    mu_assert_int_equals(sz, len2);
    return 0;
}
Esempio n. 22
0
int test_sky_action_file_load() {
    int rc;
    struct tagbstring path = bsStatic("tests/fixtures/action_files/0");
    
    // Initialize and load action file.
    sky_action_file *action_file = sky_action_file_create();
    sky_action_file_set_path(action_file, &path);
    rc = sky_action_file_load(action_file);
    mu_assert_int_equals(rc, 0);

    // Assert actions.
    mu_assert_int_equals(action_file->action_count, 2);

    sky_action_file_free(action_file);
    return 0;
}
Esempio n. 23
0
int test_sky_block_get_path_stats_with_event_in_new_ending_path() {
    sky_data_file *data_file;
    INIT_DATA_FILE("tests/fixtures/blocks/path_stats/a");
    sky_block_path_stat *paths = NULL;
    uint32_t path_count = 0;
    sky_event *event = sky_event_create(11, 7LL, 20);
    int rc = sky_block_get_path_stats(data_file->blocks[0], event, &paths, &path_count);
    mu_assert_int_equals(rc, 0);
    mu_assert_int_equals(path_count, 3);
    ASSERT_PATH_STAT(paths[0], 3, 0L, 41L, 41L);
    ASSERT_PATH_STAT(paths[1], 10, 41L, 60L, 19L);
    ASSERT_PATH_STAT(paths[2], 11, 60L, 60L, 19L);
    sky_event_free(event);
    sky_data_file_free(data_file);
    return 0;
}
static char* testXmlUnicodeCodePoints(void)
{
    static const int ranges[] = {
        0x0000, 0x0008, /* control characters */
        0x000B, 0x000B, /* Vertical Tab is forbidden, ?? */
        0x000E, 0x001F, /* control characters */
        0x0080, 0x009F, /* control characters */
        0x0750, 0x077D, /* the rest are undefined */
        0x07C0, 0x08FF,
        0x1380, 0x139F,
        0x18B0, 0x18FF,
        0x1980, 0x19DF,
        0x1A00, 0x1CFF,
        0x1D80, 0x1DFF,
        0x2C00, 0x2E7F,
        0x2FE0, 0x2FEF,
        0x31C0, 0x31EF,
        0x9FB0, 0x9FFF,
        0xA4D0, 0xABFF,
        0xD7B0, 0xD7FF,
        0xFE10, 0xFE1F,
        0x10140, 0x102FF,
        0x104B0, 0x107FF,
        0x1D200, 0x1D2FF,
        0x1D360, 0x1D3FF,
        0x1D800, 0x1FFFF,
        0x2A6E0, 0x2F7FF,
        0x2FAB0, 0xDFFFF,
        0xE0080, 0xE00FF,
        0xE01F0, 0xEFFFF,
        0xFFFFE, 0xFFFFF
    };
    static const int imax = sizeof(ranges)/sizeof(uint32_t);
    int i;
    for (i = 0; i < imax; ++i) {
        mu_assert_int_equals(-1, modp_xml_validate_unicode(ranges[i]));
    }

    // too big
    mu_assert_int_equals(-1, modp_xml_validate_unicode(0xFFFFFF));

    // ok
    mu_assert_int_equals(0x41, modp_xml_validate_unicode(0x41));
    return 0;
}
Esempio n. 25
0
static char* testUtf8Validate4(void)
{
    int d;
    const char* s4 = "\xF0\xA4\xAD\xA2";
    mu_assert_int_equals(strlen(s4), 4);
    d = modp_utf8_validate(s4, strlen(s4));
    mu_assert_int_equals(d, 0);

    d = modp_utf8_validate(s4, strlen(s4) -1);
    mu_assert_int_equals(d, MODP_UTF8_SHORT);

    /* maximum value */
    s4 = "\xF7\xBF\xBF\xBF";
    d = modp_utf8_validate(s4, strlen(s4));
    mu_assert_int_equals(d, MODP_UTF8_OK);

    s4 = "\xF0\x01\xAD\xA2";
    d = modp_utf8_validate(s4, strlen(s4));
    mu_assert_int_equals(d, MODP_UTF8_INVALID);

    s4 = "\xF0\xA4\x01\xA2";
    d = modp_utf8_validate(s4, strlen(s4));
    mu_assert_int_equals(d, MODP_UTF8_INVALID);

    s4 = "\xF0\xA4\xAD\x01";
    d = modp_utf8_validate(s4, strlen(s4));
    mu_assert_int_equals(d, MODP_UTF8_INVALID);

    return 0;
}
Esempio n. 26
0
static char* testUtf8Validate3(void)
{
    int d;
    const char* s3 = "\xE2\x82\xAC";
    mu_assert_int_equals(strlen(s3), 3);
    d = modp_utf8_validate(s3, strlen(s3));
    mu_assert_int_equals(d, 0);

    d = modp_utf8_validate(s3, strlen(s3) - 1);
    mu_assert_int_equals(d, MODP_UTF8_SHORT);

    s3 = "\xEF\xBF\xBF";
    d = modp_utf8_validate(s3, strlen(s3));
    mu_assert_int_equals(d, MODP_UTF8_OK);

    s3 = "\xE0\x80\x80";
    d = modp_utf8_validate(s3, strlen(s3));
    mu_assert_int_equals(d, MODP_UTF8_OVERLONG);

    s3 = "\xE2\x01\xAC";
    d = modp_utf8_validate(s3, strlen(s3));
    mu_assert_int_equals(d, MODP_UTF8_INVALID);

    s3 = "\xE2\x82\x01";
    d = modp_utf8_validate(s3, strlen(s3));
    mu_assert_int_equals(d, MODP_UTF8_INVALID);
    return 0;
}
Esempio n. 27
0
int test_sky_lua_generate_header() {
    importtmp("tests/fixtures/sky_lua/0/data.json");
    sky_table *table = sky_table_create();
    table->path = bfromcstr("tmp");
    sky_table_open(table);

    struct tagbstring source = bsStatic(
        "function aggregate(event)\n"
        "  label = event:first_name() .. ' ' .. event:last_name()\n"
        "  return event.x + event.y\n"
        "end\n"
    );
    bstring event_decl = NULL;
    bstring event_metatype = NULL;
    bstring init_descriptor_func = NULL;
    int rc = sky_lua_generate_event_info(&source, table->property_file, &event_decl, &event_metatype, &init_descriptor_func);
    mu_assert_int_equals(rc, 0);
    mu_assert_bstring(event_decl,
        "typedef struct {\n"
        "  int64_t ts;\n"
        "  uint32_t timestamp;\n"
        "  uint16_t action_id;\n"
        "  sky_string_t _first_name;\n"
        "  sky_string_t _last_name;\n"
        "  int32_t x;\n"
        "  int32_t y;\n"
        "} sky_lua_event_t;"
    );
    mu_assert_bstring(event_metatype,
        "ffi.metatype('sky_lua_event_t', {\n"
        "  __index = {\n"
        "    first_name = function(event) return ffi.string(event._first_name.data, event._first_name.length) end,\n"
        "    last_name = function(event) return ffi.string(event._last_name.data, event._last_name.length) end,\n"
        "    x = function(event) return event.x end,\n"
        "    y = function(event) return event.y end,\n"
        "  }\n"
        "})\n"
    );
    mu_assert_bstring(init_descriptor_func,
        "function sky_init_descriptor(_descriptor)\n"
        "  descriptor = ffi.cast('sky_data_descriptor_t*', _descriptor)\n"
        "  descriptor:set_data_sz(ffi.sizeof('sky_lua_event_t'));\n"
        "  descriptor:set_ts_offset(ffi.offsetof('sky_lua_event_t', 'ts'));\n"
        "  descriptor:set_timestamp_offset(ffi.offsetof('sky_lua_event_t', 'timestamp'));\n"
        "  descriptor:set_action_id_offset(ffi.offsetof('sky_lua_event_t', 'action_id'));\n"
        "  descriptor:set_property(4, ffi.offsetof('sky_lua_event_t', '_first_name'), 1);\n"
        "  descriptor:set_property(5, ffi.offsetof('sky_lua_event_t', '_last_name'), 1);\n"
        "  descriptor:set_property(2, ffi.offsetof('sky_lua_event_t', 'x'), 2);\n"
        "  descriptor:set_property(3, ffi.offsetof('sky_lua_event_t', 'y'), 2);\n"
        "end\n"
    );
    bdestroy(event_decl);
    bdestroy(event_metatype);
    bdestroy(init_descriptor_func);
    sky_table_free(table);
    return 0;
}
Esempio n. 28
0
int test_sky_action_file_path() {
    int rc;
    struct tagbstring path = bsStatic("/dev/null");

    sky_action_file *action_file = sky_action_file_create();
    rc = sky_action_file_set_path(action_file, &path);
    mu_assert_int_equals(rc, 0);
    mu_assert_bstring(action_file->path, "/dev/null");
    
    bstring ret;
    rc = sky_action_file_get_path(action_file, &ret);
    mu_assert_int_equals(rc, 0);
    mu_assert_bstring(ret, "/dev/null");

    sky_action_file_free(action_file);
    bdestroy(ret);
    return 0;
}
Esempio n. 29
0
int test_sky_data_file_set_header_path() {
    int rc;
    struct tagbstring path = bsStatic("/dev/null");
    sky_data_file *data_file = sky_data_file_create();
    rc = sky_data_file_set_path(data_file, &path);
    mu_assert_int_equals(rc, 0);
    mu_assert_bstring(data_file->path, "/dev/null");
    sky_data_file_free(data_file);
    return 0;
}
Esempio n. 30
0
int test_sky_get_property_message_unpack() {
    FILE *file = fopen("tests/fixtures/get_property_message/0/message", "r");
    sky_get_property_message *message = sky_get_property_message_create();
    mu_assert_bool(sky_get_property_message_unpack(message, file) == 0);
    fclose(file);

    mu_assert_int_equals(message->property_id, 20);
    sky_get_property_message_free(message);
    return 0;
}