Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unit_test_pstree.rs 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #[cfg(test)]
  2. mod tests {
  3. use pstree::Process;
  4. use pstree::print;
  5. #[test]
  6. #[should_panic]
  7. fn new_invalid_pid() {
  8. Process::new(-1000);
  9. }
  10. #[test]
  11. fn new_valid_pid() {
  12. Process::new(1);
  13. }
  14. #[test]
  15. fn hasparent_no() {
  16. assert_eq!(false, Process::has_parent(&Process::new(1)));
  17. }
  18. #[test]
  19. fn hasparent_yes() {
  20. assert_eq!(true, Process::has_parent(&Process::me()));
  21. }
  22. #[test]
  23. #[should_panic]
  24. fn parent_not_existing() {
  25. Process::parent(&Process::new(1));
  26. }
  27. #[test]
  28. fn parent_existing() {
  29. Process::parent(&Process::me());
  30. }
  31. #[test]
  32. fn hasparent_with_pid_not_existing() {
  33. assert_eq!(false, Process::has_parent_with_pid(&Process::me(), -1000));
  34. }
  35. #[test]
  36. fn hasparent_with_pid_existing() {
  37. assert_eq!(true, Process::me().has_parent_with_pid(1));
  38. }
  39. #[test]
  40. fn print_not_existing() {
  41. assert_eq!(false, print(-1000));
  42. }
  43. #[test]
  44. fn print_existing() {
  45. assert_eq!(true, print(1));
  46. }
  47. #[test]
  48. fn print_recursive_existing_pid() {
  49. let prc = Process::new(1);
  50. let mut str = String::new();
  51. prc.print_recursive(1, &mut str);
  52. assert_eq!("systemd(1)", str);
  53. }
  54. }