check_hpjd.t 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # HP JetDirect Test via check_hpjd
  4. #
  5. #
  6. use strict;
  7. use Test::More;
  8. use NPTest;
  9. plan skip_all => "check_hpjd not compiled" unless (-x "check_hpjd");
  10. my $successOutput = '/^Printer ok - /';
  11. my $failureOutput = '/Timeout: No [Rr]esponse from /';
  12. my $host_tcp_hpjd = getTestParameter(
  13. "NP_HOST_TCP_HPJD",
  14. "A host (usually a printer) providing the HP-JetDirect Services"
  15. );
  16. my $host_hpjd_port_invalid = getTestParameter(
  17. "NP_HOST_HPJD_PORT_INVALID",
  18. "A port that HP-JetDirect Services is not listening on",
  19. "162"
  20. );
  21. my $host_hpjd_port_valid = getTestParameter(
  22. "NP_HOST_HPJD_PORT_VALID",
  23. "The port that HP-JetDirect Services is currently listening on",
  24. "161"
  25. );
  26. my $host_nonresponsive = getTestParameter(
  27. "NP_HOST_NONRESPONSIVE",
  28. "The hostname of system not responsive to network requests",
  29. "10.0.0.1"
  30. );
  31. my $hostname_invalid = getTestParameter(
  32. "NP_HOSTNAME_INVALID",
  33. "An invalid (not known to DNS) hostname",
  34. "nosuchhost"
  35. );
  36. my $tests = $host_tcp_hpjd ? 9 : 5;
  37. plan tests => $tests;
  38. my $res;
  39. SKIP: {
  40. skip "No HP JetDirect defined", 2 unless $host_tcp_hpjd;
  41. $res = NPTest->testCmd("./check_hpjd -H $host_tcp_hpjd");
  42. cmp_ok( $res->return_code, 'eq', 0, "Jetdirect responding" );
  43. like ( $res->output, $successOutput, "Output correct" );
  44. $res = NPTest->testCmd("./check_hpjd -H $host_tcp_hpjd -p $host_hpjd_port_valid");
  45. cmp_ok( $res->return_code, 'eq', 0, "Jetdirect responding on port $host_hpjd_port_valid" );
  46. like ( $res->output, $successOutput, "Output correct" );
  47. $res = NPTest->testCmd("./check_hpjd -H $host_tcp_hpjd -p $host_hpjd_port_invalid");
  48. cmp_ok( $res->return_code, 'eq', 2, "Jetdirect not responding on port $host_hpjd_port_invalid" );
  49. like ( $res->output, $failureOutput, "Output correct" );
  50. }
  51. $res = NPTest->testCmd("./check_hpjd -H $host_nonresponsive");
  52. cmp_ok( $res->return_code, 'eq', 2, "Host not responding");
  53. like ( $res->output, $failureOutput, "Output OK" );
  54. $res = NPTest->testCmd("./check_hpjd -H $hostname_invalid");
  55. cmp_ok( $res->return_code, 'eq', 3, "Hostname invalid");