| 23 | |
| 24 | |
| 25 | int main() |
| 26 | { |
| 27 | bool test_passed = true; |
| 28 | try |
| 29 | { |
| 30 | struct log_facility_mapping_t |
| 31 | { |
| 32 | const std::string name; |
| 33 | const int facility; |
| 34 | const bool should_pass; |
| 35 | }; |
| 36 | |
| 37 | // Various inputs to test, with their expected test result |
| 38 | static const struct log_facility_mapping_t test_facilities[] = { |
| 39 | // clang-format off |
| 40 | {"LOG_AUTH", LOG_AUTH, true}, |
| 41 | {"LOG_AUTHPRIV", LOG_AUTHPRIV, true}, |
| 42 | {"LOG_CRON", LOG_CRON, true}, |
| 43 | {"LOG_DAEMON", LOG_DAEMON, true}, |
| 44 | {"LOG_FTP", LOG_FTP, true}, |
| 45 | {"LOG_KERN", LOG_KERN, true}, |
| 46 | {"LOG_LOCAL0", LOG_LOCAL0, true}, |
| 47 | {"LOG_LOCAL1", LOG_LOCAL1, true}, |
| 48 | {"LOG_LOCAL2", LOG_LOCAL2, true}, |
| 49 | {"LOG_LOCAL3", LOG_LOCAL3, true}, |
| 50 | {"LOG_LOCAL4", LOG_LOCAL4, true}, |
| 51 | {"LOG_LOCAL5", LOG_LOCAL5, true}, |
| 52 | {"LOG_LOCAL6", LOG_LOCAL6, true}, |
| 53 | {"LOG_LOCAL7", LOG_LOCAL7, true}, |
| 54 | {"LOG_LPR", LOG_LPR, true}, |
| 55 | {"LOG_MAIL", LOG_MAIL, true}, |
| 56 | {"LOG_NEWS", LOG_NEWS, true}, |
| 57 | {"LOG_SYSLOG", LOG_SYSLOG, true}, |
| 58 | {"LOG_USER", LOG_USER, true}, |
| 59 | {"LOG_UUCP", LOG_UUCP, true}, |
| 60 | {"LOG_INVALID", -1, false}, |
| 61 | {"", -1, false} |
| 62 | // clang-format on |
| 63 | }; |
| 64 | |
| 65 | for (auto const &fac : test_facilities) |
| 66 | { |
| 67 | try |
| 68 | { |
| 69 | int r = SyslogWriter::ConvertLogFacility(fac.name); |
| 70 | if (!fac.should_pass || r < 0) |
| 71 | { |
| 72 | test_passed = false; |
| 73 | std::cout << "FAIL: Syslog facility \"" << fac.name |
| 74 | << "\" returned " << std::to_string(r) |
| 75 | << " but should NOT have passed" |
| 76 | << std::endl; |
| 77 | continue; |
| 78 | } |
| 79 | |
| 80 | if (fac.facility != r) |
| 81 | { |
| 82 | test_passed = false; |