test_procmon.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Copyright (c) 2010-2015, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #define PROCMON_PRIVATE
  4. #include "orconfig.h"
  5. #include "or.h"
  6. #include "test.h"
  7. #include "procmon.h"
  8. #include "log_test_helpers.h"
  9. #define NS_MODULE procmon
  10. struct event_base;
  11. static void
  12. test_procmon_tor_process_monitor_new(void *ignored)
  13. {
  14. (void)ignored;
  15. tor_process_monitor_t *res;
  16. const char *msg;
  17. res = tor_process_monitor_new(NULL, "probably invalid", 0, NULL, NULL, &msg);
  18. tt_assert(!res);
  19. tt_str_op(msg, OP_EQ, "invalid PID");
  20. res = tor_process_monitor_new(NULL, "243443535345454", 0, NULL, NULL, &msg);
  21. tt_assert(!res);
  22. tt_str_op(msg, OP_EQ, "invalid PID");
  23. res = tor_process_monitor_new(tor_libevent_get_base(), "43", 0, NULL, NULL, &msg);
  24. tt_assert(res);
  25. tt_assert(!msg);
  26. res = tor_process_monitor_new(tor_libevent_get_base(), "44 hello", 0, NULL, NULL, &msg);
  27. tt_assert(res);
  28. tt_assert(!msg);
  29. res = tor_process_monitor_new(tor_libevent_get_base(), "45:hello", 0, NULL, NULL, &msg);
  30. tt_assert(res);
  31. tt_assert(!msg);
  32. done:
  33. (void)0;
  34. }
  35. struct testcase_t procmon_tests[] = {
  36. { "tor_process_monitor_new", test_procmon_tor_process_monitor_new, TT_FORK, NULL, NULL },
  37. END_OF_TESTCASES
  38. };