Allow creating new dive site with specific uuid

Test cases require deterministic results and thus we should allow uuid
to be specified when needed.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Miika Turkia 2015-07-24 19:53:21 +03:00 committed by Dirk Hohndel
parent 0d2d91a28c
commit 76fe262a0f
4 changed files with 10 additions and 7 deletions

View file

@ -86,7 +86,7 @@ static uint32_t dive_site_getUniqId()
return id; return id;
} }
struct dive_site *alloc_dive_site() struct dive_site *alloc_dive_site(uint32_t uuid)
{ {
int nr = dive_site_table.nr, allocated = dive_site_table.allocated; int nr = dive_site_table.nr, allocated = dive_site_table.allocated;
struct dive_site **sites = dive_site_table.dive_sites; struct dive_site **sites = dive_site_table.dive_sites;
@ -104,7 +104,10 @@ struct dive_site *alloc_dive_site()
exit(1); exit(1);
sites[nr] = ds; sites[nr] = ds;
dive_site_table.nr = nr + 1; dive_site_table.nr = nr + 1;
ds->uuid = dive_site_getUniqId(); if (uuid)
ds->uuid = uuid;
else
ds->uuid = dive_site_getUniqId();
return ds; return ds;
} }
@ -157,7 +160,7 @@ void delete_dive_site(uint32_t id)
/* allocate a new site and add it to the table */ /* allocate a new site and add it to the table */
uint32_t create_dive_site(const char *name) uint32_t create_dive_site(const char *name)
{ {
struct dive_site *ds = alloc_dive_site(); struct dive_site *ds = alloc_dive_site(0);
ds->name = copy_string(name); ds->name = copy_string(name);
return ds->uuid; return ds->uuid;
@ -166,7 +169,7 @@ uint32_t create_dive_site(const char *name)
/* same as before, but with GPS data */ /* same as before, but with GPS data */
uint32_t create_dive_site_with_gps(const char *name, degrees_t latitude, degrees_t longitude) uint32_t create_dive_site_with_gps(const char *name, degrees_t latitude, degrees_t longitude)
{ {
struct dive_site *ds = alloc_dive_site(); struct dive_site *ds = alloc_dive_site(0);
ds->name = copy_string(name); ds->name = copy_string(name);
ds->latitude = latitude; ds->latitude = latitude;
ds->longitude = longitude; ds->longitude = longitude;

View file

@ -49,7 +49,7 @@ static inline struct dive_site *get_dive_site_by_uuid(uint32_t uuid)
return NULL; return NULL;
} }
struct dive_site *alloc_dive_site(); struct dive_site *alloc_dive_site(uint32_t uuid);
int nr_of_dives_at_dive_site(uint32_t uuid, bool select_only); int nr_of_dives_at_dive_site(uint32_t uuid, bool select_only);
bool is_dive_site_used(uint32_t uuid, bool select_only); bool is_dive_site_used(uint32_t uuid, bool select_only);
void delete_dive_site(uint32_t id); void delete_dive_site(uint32_t id);

View file

@ -1437,7 +1437,7 @@ static int parse_site_entry(git_repository *repo, const git_tree_entry *entry, c
{ {
if (*suffix == '\0') if (*suffix == '\0')
return report_error("Dive site without uuid"); return report_error("Dive site without uuid");
struct dive_site *ds = alloc_dive_site(); struct dive_site *ds = alloc_dive_site(0);
ds->uuid = strtoul(suffix, NULL, 16); ds->uuid = strtoul(suffix, NULL, 16);
git_blob *blob = git_tree_entry_blob(repo, entry); git_blob *blob = git_tree_entry_blob(repo, entry);
if (!blob) if (!blob)

View file

@ -1517,7 +1517,7 @@ static void dive_site_end(void)
if (!cur_dive_site) if (!cur_dive_site)
return; return;
if (cur_dive_site->uuid) { if (cur_dive_site->uuid) {
struct dive_site *ds = alloc_dive_site(); struct dive_site *ds = alloc_dive_site(0);
if (cur_dive_site->taxonomy.nr == 0) { if (cur_dive_site->taxonomy.nr == 0) {
free(cur_dive_site->taxonomy.category); free(cur_dive_site->taxonomy.category);
cur_dive_site->taxonomy.category = NULL; cur_dive_site->taxonomy.category = NULL;