From e892ec3a25fc315d58ae7aafbd138b79aff2ca34 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Fri, 2 Mar 2012 10:21:58 +0000 Subject: [PATCH] - reset db before test --- src/namestore/test_namestore_api.c | 19 +++++++++++++++++++ src/namestore/test_namestore_api_lookup.c | 19 +++++++++++++++++++ src/namestore/test_namestore_api_put.c | 18 ++++++++++++++++++ src/namestore/test_namestore_api_remove.c | 19 +++++++++++++++++++ ...namestore_api_remove_not_existing_record.c | 19 +++++++++++++++++++ .../test_namestore_api_zone_iteration.c | 19 +++++++++++++++++++ 6 files changed, 113 insertions(+) diff --git a/src/namestore/test_namestore_api.c b/src/namestore/test_namestore_api.c index ebd8be3f6..a69f27665 100644 --- a/src/namestore/test_namestore_api.c +++ b/src/namestore/test_namestore_api.c @@ -142,10 +142,29 @@ void put_cont (void *cls, int32_t success, const char *emsg) GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0, &name_lookup_proc, NULL); } +void +delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + char *afsdir; + + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", + "FILENAME", &afsdir)) + { + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); + GNUNET_free (afsdir); + } + +} + static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + delete_existing_db(cfg); endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); diff --git a/src/namestore/test_namestore_api_lookup.c b/src/namestore/test_namestore_api_lookup.c index 3943d9db2..daca07b14 100644 --- a/src/namestore/test_namestore_api_lookup.c +++ b/src/namestore/test_namestore_api_lookup.c @@ -227,10 +227,29 @@ create_record (int count) return rd; } +void +delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + char *afsdir; + + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", + "FILENAME", &afsdir)) + { + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); + GNUNET_free (afsdir); + } + +} + static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + delete_existing_db(cfg); endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); size_t rd_ser_len; diff --git a/src/namestore/test_namestore_api_put.c b/src/namestore/test_namestore_api_put.c index 211c19696..f65b533b3 100644 --- a/src/namestore/test_namestore_api_put.c +++ b/src/namestore/test_namestore_api_put.c @@ -151,10 +151,28 @@ create_record (int count) return rd; } +void +delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + char *afsdir; + + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", + "FILENAME", &afsdir)) + { + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); + GNUNET_free (afsdir); + } +} + static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + delete_existing_db(cfg); endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); /* load privat key */ diff --git a/src/namestore/test_namestore_api_remove.c b/src/namestore/test_namestore_api_remove.c index 6b0943f3d..9bd25b3a2 100644 --- a/src/namestore/test_namestore_api_remove.c +++ b/src/namestore/test_namestore_api_remove.c @@ -261,10 +261,29 @@ create_record (int count) return rd; } +void +delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + char *afsdir; + + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", + "FILENAME", &afsdir)) + { + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); + GNUNET_free (afsdir); + } + +} + static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + delete_existing_db(cfg); endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); size_t rd_ser_len; diff --git a/src/namestore/test_namestore_api_remove_not_existing_record.c b/src/namestore/test_namestore_api_remove_not_existing_record.c index 85652874c..4ee633598 100644 --- a/src/namestore/test_namestore_api_remove_not_existing_record.c +++ b/src/namestore/test_namestore_api_remove_not_existing_record.c @@ -195,10 +195,29 @@ create_record (int count) return rd; } +void +delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + char *afsdir; + + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", + "FILENAME", &afsdir)) + { + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); + GNUNET_free (afsdir); + } + +} + static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + delete_existing_db(cfg); endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); size_t rd_ser_len; diff --git a/src/namestore/test_namestore_api_zone_iteration.c b/src/namestore/test_namestore_api_zone_iteration.c index c0ef8c809..95755ceee 100644 --- a/src/namestore/test_namestore_api_zone_iteration.c +++ b/src/namestore/test_namestore_api_zone_iteration.c @@ -153,10 +153,29 @@ void zone_proc (void *cls, stopiteration_task = GNUNET_SCHEDULER_add_now (&stop_iteration, NULL); } +void +delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + char *afsdir; + + if (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_filename (cfg, "namestore-sqlite", + "FILENAME", &afsdir)) + { + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_file_test (afsdir)) + if (GNUNET_OK == GNUNET_DISK_directory_remove(afsdir)) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted existing database `%s' \n", afsdir); + GNUNET_free (afsdir); + } + +} + static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + delete_existing_db(cfg); endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL); privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); -- 2.25.1