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

View file

@ -49,7 +49,7 @@ static inline struct dive_site *get_dive_site_by_uuid(uint32_t uuid)
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);
bool is_dive_site_used(uint32_t uuid, bool select_only);
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')
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);
git_blob *blob = git_tree_entry_blob(repo, entry);
if (!blob)

View file

@ -1517,7 +1517,7 @@ static void dive_site_end(void)
if (!cur_dive_site)
return;
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) {
free(cur_dive_site->taxonomy.category);
cur_dive_site->taxonomy.category = NULL;