Store loggers in conftest separately, not on charon
authorTobias Brunner <tobias@strongswan.org>
Tue, 2 Oct 2012 12:49:26 +0000 (14:49 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 18 Oct 2012 12:42:10 +0000 (14:42 +0200)
src/conftest/conftest.c
src/conftest/conftest.h

index 6491fd2..8df5d6f 100644 (file)
@@ -322,6 +322,7 @@ static bool load_hooks()
  */
 static void cleanup()
 {
+       file_logger_t *logger;
        hook_t *hook;
 
        DESTROY_IF(conftest->test);
@@ -344,6 +345,13 @@ static void cleanup()
                }
                conftest->config->destroy(conftest->config);
        }
+       while (conftest->loggers->remove_last(conftest->loggers,
+                                                                                 (void**)&logger) == SUCCESS)
+       {
+               charon->bus->remove_logger(charon->bus, &logger->logger);
+               logger->destroy(logger);
+       }
+       conftest->loggers->destroy(conftest->loggers);
        free(conftest->suite_dir);
        free(conftest);
        libcharon_deinit();
@@ -394,7 +402,7 @@ static void load_loggers(file_logger_t *logger)
                        logger = file_logger_create(file, NULL, FALSE);
                        load_log_levels(logger, section);
                        charon->bus->add_logger(charon->bus, &logger->logger);
-                       charon->file_loggers->insert_last(charon->file_loggers, logger);
+                       conftest->loggers->insert_last(conftest->loggers, logger);
                }
        }
        enumerator->destroy(enumerator);
@@ -433,16 +441,16 @@ int main(int argc, char *argv[])
 
        INIT(conftest,
                .creds = mem_cred_create(),
+               .config = config_create(),
+               .hooks = linked_list_create(),
+               .loggers = linked_list_create(),
        );
+       lib->credmgr->add_set(lib->credmgr, &conftest->creds->set);
 
        logger = file_logger_create(stdout, NULL, FALSE);
        logger->set_level(logger, DBG_ANY, LEVEL_CTRL);
        charon->bus->add_logger(charon->bus, &logger->logger);
-       charon->file_loggers->insert_last(charon->file_loggers, logger);
-
-       lib->credmgr->add_set(lib->credmgr, &conftest->creds->set);
-       conftest->hooks = linked_list_create();
-       conftest->config = config_create();
+       conftest->loggers->insert_last(conftest->loggers, logger);
 
        atexit(cleanup);
 
index 2caf9b3..6bbdabd 100644 (file)
@@ -64,6 +64,11 @@ struct conftest_t {
         * Action handling
         */
        actions_t *actions;
+
+       /**
+        * Test specific loggers
+        */
+       linked_list_t *loggers;
 };
 
 /**