test_log_level_override.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #define ZF_LOG_LEVEL 0
  2. #define ZF_LOG_OUTPUT_LEVEL g_output_level
  3. #include <zf_log.c>
  4. #include <zf_test.h>
  5. static const int c_levels[] =
  6. {
  7. ZF_LOG_VERBOSE,
  8. ZF_LOG_DEBUG,
  9. ZF_LOG_INFO,
  10. ZF_LOG_WARN,
  11. ZF_LOG_ERROR,
  12. ZF_LOG_FATAL,
  13. ZF_LOG_NONE,
  14. };
  15. static int g_output_level = 0;
  16. static void test_level_checks()
  17. {
  18. for (unsigned i = 0; _countof(c_levels) > i; ++i)
  19. {
  20. /* must not effect anything */
  21. zf_log_set_output_level(c_levels[i]);
  22. for (unsigned j = 0; _countof(c_levels) > j; ++j)
  23. {
  24. g_output_level = c_levels[j];
  25. TEST_VERIFY_EQUAL(!!ZF_LOG_ON_VERBOSE, g_output_level <= ZF_LOG_VERBOSE);
  26. TEST_VERIFY_EQUAL(!!ZF_LOG_ON_DEBUG, g_output_level <= ZF_LOG_DEBUG);
  27. TEST_VERIFY_EQUAL(!!ZF_LOG_ON_INFO, g_output_level <= ZF_LOG_INFO);
  28. TEST_VERIFY_EQUAL(!!ZF_LOG_ON_WARN, g_output_level <= ZF_LOG_WARN);
  29. TEST_VERIFY_EQUAL(!!ZF_LOG_ON_ERROR, g_output_level <= ZF_LOG_ERROR);
  30. TEST_VERIFY_EQUAL(!!ZF_LOG_ON_FATAL, g_output_level <= ZF_LOG_FATAL);
  31. }
  32. }
  33. }
  34. int main(int argc, char *argv[])
  35. {
  36. TEST_RUNNER_CREATE(argc, argv);
  37. TEST_EXECUTE(test_level_checks());
  38. return TEST_RUNNER_EXIT_CODE();
  39. }