예제 #1
0
Test(test_run_id, second_run__run_id_is_two)
{
  PersistState *state;

  state = create_persist_state("test_run_id__second_run__run_id_is_two");

  run_id_init(state);

  state = restart_persist_state(state);

  run_id_init(state);
  cr_assert_eq(run_id_get(), RUN_ID_FIRST + 1, "Running run_id_init twice is not the second id!");

  destroy_persist_state(state);
};
예제 #2
0
Test(test_run_id, is_same_run__differs_when_not_same_run)
{
  PersistState *state;

  state = create_persist_state("test_run_id__is_same_run__differs_when_not_same_run");

  run_id_init(state);
  int prev_run_id = run_id_get();

  state = restart_persist_state(state);

  run_id_init(state);

  cr_assert_not(run_id_is_same_run(prev_run_id), "Run_id_is_same_run returned true when the run differs");

  destroy_persist_state(state);
};
예제 #3
0
void
test_persist_state_remove_entry(void)
{
    guint8 version;
    gsize size;

    PersistState *state = clean_and_create_persist_state_for_test("test_persist_state_remove_entry.persist");

    PersistEntryHandle handle = persist_state_alloc_entry(state, "test", sizeof(TestState));

    handle = persist_state_lookup_entry(state, "test", &size, &version);
    assert_true(handle != 0, "lookup failed before removing entry");

    persist_state_remove_entry(state, "test");

    state = restart_persist_state(state);

    handle = persist_state_lookup_entry(state, "test", &size, &version);
    assert_true(handle == 0, "lookup succeeded after removing entry");

    cancel_and_destroy_persist_state(state);
}
예제 #4
0
static void
test_rcptid_is_persistent_across_persist_backend_reinits(void)
{
  guint64 rcptid;

  setup_persist_id_test();

  rcptid_set_id(0x0000FFFFFFFFFFFE);
  rcptid = rcptid_generate_id();

  assert_guint64(rcptid, 0x0000FFFFFFFFFFFE, "Rcptid initialization to specific value failed!");
  
  state = restart_persist_state(state);

  rcptid_deinit();
  rcptid_init(state, TRUE);

  rcptid = rcptid_generate_id();

  assert_guint64(rcptid, 0x0000FFFFFFFFFFFF, "Rcptid did not persisted across persist backend reinit!");

  teardown_persist_id_test();
}
예제 #5
0
void
test_values(void)
{
    PersistState *state;
    gint i, j;
    gchar *data;

    state = clean_and_create_persist_state_for_test("test_values.persist");

    for (i = 0; i < 1000; i++)
    {
        gchar buf[16];
        PersistEntryHandle handle;

        g_snprintf(buf, sizeof(buf), "testkey%d", i);
        if (!(handle = persist_state_alloc_entry(state, buf, 128)))
        {
            fprintf(stderr, "Error allocating value in the persist file: %s\n", buf);
            exit(1);
        }
        data = persist_state_map_entry(state, handle);
        for (j = 0; j < 128; j++)
        {
            data[j] = (i % 26) + 'A';
        }
        persist_state_unmap_entry(state, handle);
    }
    for (i = 0; i < 1000; i++)
    {
        gchar buf[16];
        PersistEntryHandle handle;
        gsize size;
        guint8 version;

        g_snprintf(buf, sizeof(buf), "testkey%d", i);
        if (!(handle = persist_state_lookup_entry(state, buf, &size, &version)))
        {
            fprintf(stderr, "Error retrieving value from the persist file: %s\n", buf);
            exit(1);
        }
        data = persist_state_map_entry(state, handle);
        for (j = 0; j < 128; j++)
        {
            if (data[j] != (i % 26) + 'A')
            {
                fprintf(stderr, "Invalid data in persistent entry\n");
                exit(1);
            }
        }
        persist_state_unmap_entry(state, handle);
    }

    state = restart_persist_state(state);

    for (i = 0; i < 1000; i++)
    {
        gchar buf[16];
        PersistEntryHandle handle;
        gsize size;
        guint8 version;

        g_snprintf(buf, sizeof(buf), "testkey%d", i);
        if (!(handle = persist_state_lookup_entry(state, buf, &size, &version)))
        {
            fprintf(stderr, "Error retrieving value from the persist file: %s\n", buf);
            exit(1);
        }
        if (size != 128 || version != 4)
        {
            fprintf(stderr, "Error retrieving value from the persist file: %s, invalid size (%d) or version (%d)\n", buf, (gint) size, version);
            exit(1);
        }
        data = persist_state_map_entry(state, handle);
        for (j = 0; j < 128; j++)
        {
            if (data[j] != (i % 26) + 'A')
            {
                fprintf(stderr, "Invalid data in persistent entry\n");
                exit(1);
            }
        }
        persist_state_unmap_entry(state, handle);
    }
    cancel_and_destroy_persist_state(state);
}