-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit test for log_target_to_str
Fixes: #805 It adds an unit test for log_target_to_str. Also, it fixes mixed up stderr and stderr-full in the function under test. Signed-off-by: Michael Engel <mengel@redhat.com>
- Loading branch information
Showing
3 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* SPDX-License-Identifier: LGPL-2.1-or-later */ | ||
#include <assert.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include "libbluechi/common/string-util.h" | ||
#include "libbluechi/log/log.h" | ||
|
||
bool test_log_target_to_str(LogFn fn, const char *expected_log_target) { | ||
const char *result = log_target_to_str(fn); | ||
if (result != NULL && expected_log_target != NULL && streq(result, expected_log_target)) { | ||
return true; | ||
} | ||
if (result == NULL && expected_log_target == NULL) { | ||
return true; | ||
} | ||
fprintf(stdout, | ||
"FAILED: string_to_log_level - Expected '%s', but got '%s'\n", | ||
expected_log_target, | ||
result); | ||
return false; | ||
} | ||
|
||
int main() { | ||
bool result = true; | ||
|
||
result = result && test_log_target_to_str(bc_log_to_journald_with_location, BC_LOG_TARGET_JOURNALD); | ||
result = result && | ||
test_log_target_to_str(bc_log_to_stderr_full_with_location, BC_LOG_TARGET_STDERR_FULL); | ||
result = result && test_log_target_to_str(bc_log_to_stderr_with_location, BC_LOG_TARGET_STDERR); | ||
result = result && test_log_target_to_str(NULL, NULL); | ||
|
||
if (result) { | ||
return EXIT_SUCCESS; | ||
} | ||
return EXIT_FAILURE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
common_src = [ | ||
'string_to_log_level_test', | ||
'log_target_to_str_test', | ||
'bc_log_init_test', | ||
] | ||
|
||
|