Commit 6254dca6 authored by Michael Tremer's avatar Michael Tremer

test: Generate random temporary files

Debian runs the testsuite in parallel which fails when mutliple
process write to the same file at the same time.

This patch will now create and later delete a temporary file.
Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 9b2971cb
......@@ -295,7 +295,6 @@ TESTS = \
src/test-signature
CLEANFILES += \
test.db \
testdata.db
testdata.db: examples/python/create-database.py
......
......@@ -49,7 +49,7 @@ int main(int argc, char** argv) {
loc_as_unref(as);
}
FILE* f = fopen("test.db", "w+");
FILE* f = tmpfile();
if (!f) {
fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno));
exit(EXIT_FAILURE);
......@@ -60,17 +60,10 @@ int main(int argc, char** argv) {
fprintf(stderr, "Could not write database: %s\n", strerror(-err));
exit(EXIT_FAILURE);
}
fclose(f);
loc_writer_unref(writer);
// And open it again from disk
f = fopen("test.db", "r");
if (!f) {
fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
struct loc_database* db;
err = loc_database_new(ctx, &db, f);
if (err) {
......@@ -125,6 +118,7 @@ int main(int argc, char** argv) {
loc_database_enumerator_unref(enumerator);
loc_database_unref(db);
loc_unref(ctx);
fclose(f);
return EXIT_SUCCESS;
}
......@@ -75,7 +75,7 @@ int main(int argc, char** argv) {
}
loc_country_unref(country);
FILE* f = fopen("test.db", "w+");
FILE* f = tmpfile();
if (!f) {
fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno));
exit(EXIT_FAILURE);
......@@ -86,17 +86,9 @@ int main(int argc, char** argv) {
fprintf(stderr, "Could not write database: %s\n", strerror(-err));
exit(EXIT_FAILURE);
}
fclose(f);
loc_writer_unref(writer);
// And open it again from disk
f = fopen("test.db", "r");
if (!f) {
fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
struct loc_database* db;
err = loc_database_new(ctx, &db, f);
if (err) {
......@@ -114,6 +106,7 @@ int main(int argc, char** argv) {
loc_database_unref(db);
loc_unref(ctx);
fclose(f);
return EXIT_SUCCESS;
}
......@@ -135,7 +135,7 @@ int main(int argc, char** argv) {
exit(EXIT_FAILURE);
}
FILE* f = fopen("test.db", "w+");
FILE* f = tmpfile();
if (!f) {
fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno));
exit(EXIT_FAILURE);
......@@ -148,16 +148,7 @@ int main(int argc, char** argv) {
}
loc_writer_unref(writer);
// Close the file
fclose(f);
// And open it again from disk
f = fopen("test.db", "r");
if (!f) {
fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
struct loc_database* db;
err = loc_database_new(ctx, &db, f);
if (err) {
......@@ -177,8 +168,8 @@ int main(int argc, char** argv) {
// Close the database
loc_database_unref(db);
loc_unref(ctx);
fclose(f);
return EXIT_SUCCESS;
}
......@@ -120,7 +120,7 @@ int main(int argc, char** argv) {
// Set ASN
loc_network_set_asn(network4, 1024);
FILE* f = fopen("test.db", "w+");
FILE* f = tmpfile();
if (!f) {
fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno));
exit(EXIT_FAILURE);
......@@ -131,8 +131,6 @@ int main(int argc, char** argv) {
fprintf(stderr, "Could not write database: %s\n", strerror(-err));
exit(EXIT_FAILURE);
}
fclose(f);
loc_writer_unref(writer);
loc_network_unref(network1);
......@@ -142,12 +140,6 @@ int main(int argc, char** argv) {
loc_network_tree_unref(tree);
// And open it again from disk
f = fopen("test.db", "r");
if (!f) {
fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
struct loc_database* db;
err = loc_database_new(ctx, &db, f);
if (err) {
......@@ -172,6 +164,7 @@ int main(int argc, char** argv) {
loc_network_unref(network1);
loc_unref(ctx);
fclose(f);
return EXIT_SUCCESS;
}
......@@ -61,7 +61,7 @@ int main(int argc, char** argv) {
if (err < 0)
exit(EXIT_FAILURE);
FILE* f = fopen("test.db", "w+");
FILE* f = tmpfile();
if (!f) {
fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno));
exit(EXIT_FAILURE);
......@@ -74,16 +74,7 @@ int main(int argc, char** argv) {
}
loc_writer_unref(writer);
// Close the file
fclose(f);
// And open it again from disk
f = fopen("test.db", "r");
if (!f) {
fprintf(stderr, "Could not open file for reading: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
struct loc_database* db;
err = loc_database_new(ctx, &db, f);
if (err) {
......@@ -114,8 +105,8 @@ int main(int argc, char** argv) {
// Close the database
loc_database_unref(db);
loc_unref(ctx);
fclose(f);
fclose(private_key1);
fclose(private_key2);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment