Example #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;
}
Example #2
0
// Creates a reference to an action file.
// 
// Returns a reference to the new action file if successful. Otherwise returns
// null.
sky_action_file *sky_action_file_create()
{
    sky_action_file *action_file = calloc(sizeof(sky_action_file), 1);
    check_mem(action_file);
    return action_file;
    
error:
    sky_action_file_free(action_file);
    return NULL;
}
Example #3
0
// Initializes and opens the action file on the table.
//
// table - The table to initialize the action file for.
//
// Returns 0 if successful, otherwise returns -1.
int sky_table_unload_action_file(sky_table *table)
{
    check(table != NULL, "Table required");

    if(table->action_file) {
        sky_action_file_free(table->action_file);
        table->action_file = NULL;
    }

    return 0;
error:
    return -1;
}
Example #4
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;
}
Example #5
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;
}