Skip to content
Snippets Groups Projects
Commit 0324c6dd authored by Stephan Bosch's avatar Stephan Bosch Committed by timo.sirainen
Browse files

testsuite: Reformat testsuite-common.c.

parent f5a7bbb0
No related branches found
No related tags found
No related merge requests found
...@@ -68,7 +68,8 @@ bool testsuite_validator_context_initialize(struct sieve_validator *valdtr) ...@@ -68,7 +68,8 @@ bool testsuite_validator_context_initialize(struct sieve_validator *valdtr)
p_new(pool, struct testsuite_validator_context, 1); p_new(pool, struct testsuite_validator_context, 1);
/* Setup object registry */ /* Setup object registry */
ctx->object_registrations = sieve_validator_object_registry_create(valdtr); ctx->object_registrations =
sieve_validator_object_registry_create(valdtr);
testsuite_register_core_objects(ctx); testsuite_register_core_objects(ctx);
sieve_validator_extension_set_context(valdtr, testsuite_ext, ctx); sieve_validator_extension_set_context(valdtr, testsuite_ext, ctx);
...@@ -76,8 +77,8 @@ bool testsuite_validator_context_initialize(struct sieve_validator *valdtr) ...@@ -76,8 +77,8 @@ bool testsuite_validator_context_initialize(struct sieve_validator *valdtr)
return TRUE; return TRUE;
} }
struct testsuite_validator_context *testsuite_validator_context_get struct testsuite_validator_context *
(struct sieve_validator *valdtr) testsuite_validator_context_get(struct sieve_validator *valdtr)
{ {
return (struct testsuite_validator_context *) return (struct testsuite_validator_context *)
sieve_validator_extension_get_context(valdtr, testsuite_ext); sieve_validator_extension_get_context(valdtr, testsuite_ext);
...@@ -87,8 +88,8 @@ struct testsuite_validator_context *testsuite_validator_context_get ...@@ -87,8 +88,8 @@ struct testsuite_validator_context *testsuite_validator_context_get
* Generator context * Generator context
*/ */
bool testsuite_generator_context_initialize bool testsuite_generator_context_initialize(
(struct sieve_generator *gentr, const struct sieve_extension *this_ext) struct sieve_generator *gentr, const struct sieve_extension *this_ext)
{ {
pool_t pool = sieve_generator_pool(gentr); pool_t pool = sieve_generator_pool(gentr);
struct sieve_binary_block *sblock = sieve_generator_get_block(gentr); struct sieve_binary_block *sblock = sieve_generator_get_block(gentr);
...@@ -107,37 +108,38 @@ bool testsuite_generator_context_initialize ...@@ -107,37 +108,38 @@ bool testsuite_generator_context_initialize
* Interpreter context * Interpreter context
*/ */
static void testsuite_interpreter_free static void
(const struct sieve_extension *ext ATTR_UNUSED, testsuite_interpreter_free(const struct sieve_extension *ext ATTR_UNUSED,
struct sieve_interpreter *interp ATTR_UNUSED, void *context) struct sieve_interpreter *interp ATTR_UNUSED,
void *context)
{ {
struct testsuite_interpreter_context *ctx = struct testsuite_interpreter_context *ctx =
(struct testsuite_interpreter_context *)context; (struct testsuite_interpreter_context *)context;
if ( ctx->compiled_script != NULL ) if (ctx->compiled_script != NULL)
sieve_binary_unref(&ctx->compiled_script); sieve_binary_unref(&ctx->compiled_script);
} }
const struct sieve_interpreter_extension const struct sieve_interpreter_extension testsuite_interpreter_ext = {
testsuite_interpreter_ext = {
.ext_def = &testsuite_extension, .ext_def = &testsuite_extension,
.free = testsuite_interpreter_free, .free = testsuite_interpreter_free,
}; };
bool testsuite_interpreter_context_initialize bool testsuite_interpreter_context_initialize(
(struct sieve_interpreter *interp, const struct sieve_extension *this_ext) struct sieve_interpreter *interp, const struct sieve_extension *this_ext)
{ {
pool_t pool = sieve_interpreter_pool(interp); pool_t pool = sieve_interpreter_pool(interp);
struct testsuite_interpreter_context *ctx = struct testsuite_interpreter_context *ctx =
p_new(pool, struct testsuite_interpreter_context, 1); p_new(pool, struct testsuite_interpreter_context, 1);
sieve_interpreter_extension_register sieve_interpreter_extension_register(interp, this_ext,
(interp, this_ext, &testsuite_interpreter_ext, ctx); &testsuite_interpreter_ext, ctx);
return TRUE; return TRUE;
} }
struct testsuite_interpreter_context *testsuite_interpreter_context_get struct testsuite_interpreter_context *
(struct sieve_interpreter *interp, const struct sieve_extension *this_ext) testsuite_interpreter_context_get(struct sieve_interpreter *interp,
const struct sieve_extension *this_ext)
{ {
struct testsuite_interpreter_context *ctx = struct testsuite_interpreter_context *ctx =
sieve_interpreter_extension_get_context(interp, this_ext); sieve_interpreter_extension_get_context(interp, this_ext);
...@@ -181,17 +183,19 @@ void testsuite_test_failf(const char *fmt, ...) ...@@ -181,17 +183,19 @@ void testsuite_test_failf(const char *fmt, ...)
void testsuite_test_fail_cstr(const char *reason) void testsuite_test_fail_cstr(const char *reason)
{ {
if ( str_len(test_name) == 0 ) { if (str_len(test_name) == 0) {
if ( reason == NULL || *reason == '\0' ) if (reason == NULL || *reason == '\0')
printf("%2d: Test FAILED\n", test_index); printf("%2d: Test FAILED\n", test_index);
else else
printf("%2d: Test FAILED: %s\n", test_index, reason); printf("%2d: Test FAILED: %s\n", test_index, reason);
} else { } else {
if ( reason == NULL || *reason == '\0' ) if (reason == NULL || *reason == '\0') {
printf("%2d: Test '%s' FAILED\n", test_index, str_c(test_name)); printf("%2d: Test '%s' FAILED\n",
else test_index, str_c(test_name));
printf("%2d: Test '%s' FAILED: %s\n", test_index, } else {
str_c(test_name), reason); printf("%2d: Test '%s' FAILED: %s\n",
test_index, str_c(test_name), reason);
}
} }
str_truncate(test_name, 0); str_truncate(test_name, 0);
...@@ -201,7 +205,7 @@ void testsuite_test_fail_cstr(const char *reason) ...@@ -201,7 +205,7 @@ void testsuite_test_fail_cstr(const char *reason)
void testsuite_testcase_fail(const char *reason) void testsuite_testcase_fail(const char *reason)
{ {
if ( reason == NULL || *reason == '\0' ) if (reason == NULL || *reason == '\0')
printf("XX: Test CASE FAILED\n"); printf("XX: Test CASE FAILED\n");
else else
printf("XX: Test CASE FAILED: %s\n", reason); printf("XX: Test CASE FAILED: %s\n", reason);
...@@ -211,17 +215,21 @@ void testsuite_testcase_fail(const char *reason) ...@@ -211,17 +215,21 @@ void testsuite_testcase_fail(const char *reason)
void testsuite_test_succeed(string_t *reason) void testsuite_test_succeed(string_t *reason)
{ {
if ( str_len(test_name) == 0 ) { if (str_len(test_name) == 0) {
if ( reason == NULL || str_len(reason) == 0 ) if (reason == NULL || str_len(reason) == 0)
printf("%2d: Test SUCCEEDED\n", test_index); printf("%2d: Test SUCCEEDED\n", test_index);
else else {
printf("%2d: Test SUCCEEDED: %s\n", test_index, str_c(reason)); printf("%2d: Test SUCCEEDED: %s\n",
test_index, str_c(reason));
}
} else { } else {
if ( reason == NULL || str_len(reason) == 0 ) if (reason == NULL || str_len(reason) == 0) {
printf("%2d: Test '%s' SUCCEEDED\n", test_index, str_c(test_name)); printf("%2d: Test '%s' SUCCEEDED\n",
else test_index, str_c(test_name));
} else {
printf("%2d: Test '%s' SUCCEEDED: %s\n", test_index, printf("%2d: Test '%s' SUCCEEDED: %s\n", test_index,
str_c(test_name), str_c(reason)); str_c(test_name), str_c(reason));
}
} }
str_truncate(test_name, 0); str_truncate(test_name, 0);
} }
...@@ -233,8 +241,9 @@ static void testsuite_test_context_deinit(void) ...@@ -233,8 +241,9 @@ static void testsuite_test_context_deinit(void)
bool testsuite_testcase_result(void) bool testsuite_testcase_result(void)
{ {
if ( test_failures > 0 ) { if (test_failures > 0) {
printf("\nFAIL: %d of %d tests failed.\n\n", test_failures, test_index); printf("\nFAIL: %d of %d tests failed.\n\n",
test_failures, test_index);
return FALSE; return FALSE;
} }
...@@ -250,10 +259,11 @@ static char *testsuite_tmp_dir; ...@@ -250,10 +259,11 @@ static char *testsuite_tmp_dir;
static void testsuite_tmp_dir_init(void) static void testsuite_tmp_dir_init(void)
{ {
testsuite_tmp_dir = i_strdup_printf testsuite_tmp_dir = i_strdup_printf("/tmp/dsieve-testsuite.%s.%s",
("/tmp/dsieve-testsuite.%s.%s", dec2str(time(NULL)), dec2str(getpid())); dec2str(time(NULL)),
dec2str(getpid()));
if ( mkdir(testsuite_tmp_dir, 0700) < 0 ) { if (mkdir(testsuite_tmp_dir, 0700) < 0) {
i_fatal("failed to create temporary directory '%s': %m.", i_fatal("failed to create temporary directory '%s': %m.",
testsuite_tmp_dir); testsuite_tmp_dir);
} }
...@@ -263,9 +273,10 @@ static void testsuite_tmp_dir_deinit(void) ...@@ -263,9 +273,10 @@ static void testsuite_tmp_dir_deinit(void)
{ {
const char *error; const char *error;
if ( unlink_directory(testsuite_tmp_dir, UNLINK_DIRECTORY_FLAG_RMDIR, &error) < 0 ) if (unlink_directory(testsuite_tmp_dir,
UNLINK_DIRECTORY_FLAG_RMDIR, &error) < 0)
i_warning("failed to remove temporary directory '%s': %s.", i_warning("failed to remove temporary directory '%s': %s.",
testsuite_tmp_dir, error); testsuite_tmp_dir, error);
i_free(testsuite_tmp_dir); i_free(testsuite_tmp_dir);
} }
...@@ -279,8 +290,8 @@ const char *testsuite_tmp_dir_get(void) ...@@ -279,8 +290,8 @@ const char *testsuite_tmp_dir_get(void)
* Main testsuite init/deinit * Main testsuite init/deinit
*/ */
void testsuite_init void testsuite_init(struct sieve_instance *svinst, const char *test_path,
(struct sieve_instance *svinst, const char *test_path, bool log_stdout) bool log_stdout)
{ {
testsuite_sieve_instance = svinst; testsuite_sieve_instance = svinst;
...@@ -292,9 +303,8 @@ void testsuite_init ...@@ -292,9 +303,8 @@ void testsuite_init
testsuite_binary_init(); testsuite_binary_init();
testsuite_smtp_init(); testsuite_smtp_init();
testsuite_ext = sieve_extension_register testsuite_ext =
(svinst, &testsuite_extension, TRUE); sieve_extension_register(svinst, &testsuite_extension, TRUE);
testsuite_test_path = i_strdup(test_path); testsuite_test_path = i_strdup(test_path);
} }
...@@ -311,4 +321,3 @@ void testsuite_deinit(void) ...@@ -311,4 +321,3 @@ void testsuite_deinit(void)
testsuite_log_deinit(); testsuite_log_deinit();
testsuite_test_context_deinit(); testsuite_test_context_deinit();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.