Test(test_run_id, first_run__run_id_is_one) { PersistState *state; state = create_persist_state("test_run_id__first_run__run_id_is_one.persist"); run_id_init(state); cr_assert_eq(run_id_get(), RUN_ID_FIRST, "Newly initialized run id is not the first id!"); destroy_persist_state(state); };
Test(test_run_id, second_run_but_with_non_commit__run_id_is_one) { PersistState *state; state = create_persist_state("test_run_id__second_run_but_with_non_commit__run_id_is_one"); run_id_init(state); state = restart_persist_state_with_cancel(state, "test_run_id__second_run_but_with_non_commit__run_id_is_one"); run_id_init(state); cr_assert_eq(run_id_get(), RUN_ID_FIRST, "Not committing persist state still increases run_id"); destroy_persist_state(state); };
Test(test_run_id, macro_has_the_same_value_as_run_id) { PersistState *state; GString *res = g_string_sized_new(0); state = create_persist_state("test_run_id__macro_has_the_same_value_as_run_id"); run_id_init(state); run_id_append_formatted_id(res); cr_assert_str_eq(res->str, "1", "Run id is formatted incorrectly: %s", res->str); destroy_persist_state(state); g_string_free(res, TRUE); };
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); };
static void create_persist_file_with_hostid(const gchar *persist_file, guint32 hostid) { PersistState *state; PersistEntryHandle handle; HostIdState *host_id_state; unlink(persist_file); state = create_persist_state(persist_file); handle = persist_state_alloc_entry(state, HOST_ID_PERSIST_KEY, sizeof(HostIdState)); host_id_state = persist_state_map_entry(state, handle); host_id_state->host_id = hostid; persist_state_unmap_entry(state, handle); persist_state_commit(state); persist_state_free(state); }
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); };
static guint32 load_hostid_from_persist(const gchar *persist_file) { PersistState *state; PersistEntryHandle handle; HostIdState *host_id_state; gsize size; guint8 version; guint32 result; state = create_persist_state(persist_file); handle = persist_state_lookup_entry(state, HOST_ID_PERSIST_KEY, &size, &version); assert_true(handle != 0, "cannot find hostid in persist file"); host_id_state = persist_state_map_entry(state, handle); result = host_id_state->host_id; persist_state_unmap_entry(state, handle); persist_state_free(state); return result; }