Exemple #1
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;
}
Exemple #2
0
int sky_importer_process_action(sky_importer *importer, bstring source,
                                jsmntok_t *tokens, uint32_t *index)
{
    int rc;
    assert(importer != NULL);
    assert(source != NULL);
    assert(tokens != NULL);
    assert(index != NULL);

    jsmntok_t *action_token = &tokens[*index];
    (*index)++;
    
    // Create the action object.
    sky_action *action = sky_action_create(); check_mem(action);
    
    // Process over child tokens.
    int32_t i;
    for(i=0; i<(action_token->size/2); i++) {
        jsmntok_t *token = &tokens[*index];
        (*index)++;
        
        if(sky_importer_tokstr_equal(source, token, "name")) {
            action->name = sky_importer_token_parse_bstring(source, &tokens[*index]);
        }
        else {
            sentinel("Invalid token at char %d", tokens[*index].start);
        }
        (*index)++;
    }
    
    // Add action.
    if(!importer->table->opened) {
        check(sky_table_open(importer->table) == 0, "Unable to open table");
    }
    rc = sky_action_file_add_action(importer->table->action_file, action);
    check(rc == 0, "Unable to add action: %s", bdata(action->name));
    
    return 0;

error:
    return -1;
}