Stabilize metadata field order, which seems to be causing test flakiness

This commit is contained in:
Eric Fischer
2016-01-28 15:46:58 -08:00
parent e786379358
commit 2aa1510de8
5 changed files with 32 additions and 5 deletions
+28 -1
View File
@@ -113,6 +113,18 @@ static void aprintf(char **buf, const char *format, ...) {
free(tmp);
}
static int pvcmp(const void *v1, const void *v2) {
const struct pool_val *const *pv1 = v1;
const struct pool_val *const *pv2 = v2;
int n = strcmp((*pv1)->s, (*pv2)->s);
if (n != 0) {
return n;
}
return (*pv1)->type - (*pv2)->type;
}
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, char **layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, struct pool **file_keys, int nlayers) {
char *sql, *err;
@@ -192,8 +204,23 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, char **layername,
quote(&buf, layername[i]);
aprintf(&buf, "\", \"description\": \"\", \"minzoom\": %d, \"maxzoom\": %d, \"fields\": {", minzoom, maxzoom);
int n = 0;
struct pool_val *pv;
for (pv = file_keys[i]->head; pv != NULL; pv = pv->next) {
n++;
}
struct pool_val *vals[n];
n = 0;
for (pv = file_keys[i]->head; pv != NULL; pv = pv->next) {
vals[n++] = pv;
}
qsort(vals, n, sizeof(struct pool_val *), pvcmp);
int j;
for (j = 0; j < n; j++) {
pv = vals[j];
aprintf(&buf, "\"");
quote(&buf, pv->s);
@@ -205,7 +232,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, char **layername,
aprintf(&buf, "\": \"String\"");
}
if (pv->next != NULL) {
if (j + 1 < n) {
aprintf(&buf, ", ");
}
}