test.pl
上传用户:wxp200602
上传日期:2007-10-30
资源大小:4028k
文件大小:5k
源码类别:

SNMP编程

开发平台:

Unix_Linux

  1. # Before `make install' is performed this script should be runnable with
  2. # `make test'. After `make install' it should work as `perl test.pl'
  3. ######################### We start with some black magic to print on failure.
  4. # Change 1..1 below to 1..last_test_to_print .
  5. # (It may become useful if the test is moved to ./t subdirectory.)
  6. BEGIN { $| = 1; 
  7. %tests = ( 
  8.                   "NETSNMP_DS_MAX_IDS"                     => 3,
  9.                   "NETSNMP_DS_MAX_SUBIDS"                  => 40,
  10.                   "NETSNMP_DS_LIBRARY_ID"                  => 0,
  11.                   "NETSNMP_DS_APPLICATION_ID"              => 1,
  12.                   "NETSNMP_DS_TOKEN_ID"                    => 2,
  13.                   "NETSNMP_DS_LIB_MIB_ERRORS"              => 0,
  14.                   "NETSNMP_DS_LIB_SAVE_MIB_DESCRS"         => 1,
  15.                   "NETSNMP_DS_LIB_MIB_COMMENT_TERM"        => 2,
  16.                   "NETSNMP_DS_LIB_MIB_PARSE_LABEL"         => 3,
  17.                   "NETSNMP_DS_LIB_DUMP_PACKET"             => 4,
  18.                   "NETSNMP_DS_LIB_LOG_TIMESTAMP"           => 5,
  19.                   "NETSNMP_DS_LIB_DONT_READ_CONFIGS"       => 6,
  20.                   "NETSNMP_DS_LIB_MIB_REPLACE"             => 7,
  21.                   "NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM"      => 8,
  22.                   "NETSNMP_DS_LIB_PRINT_NUMERIC_OIDS"      => 9,
  23.                   "NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS"     => 10,
  24.                   "NETSNMP_DS_LIB_ALARM_DONT_USE_SIG"      => 11,
  25.                   "NETSNMP_DS_LIB_PRINT_FULL_OID"          => 12,
  26.                   "NETSNMP_DS_LIB_QUICK_PRINT"             => 13,
  27.                   "NETSNMP_DS_LIB_RANDOM_ACCESS"           => 14,
  28.                   "NETSNMP_DS_LIB_REGEX_ACCESS"            => 15,
  29.                   "NETSNMP_DS_LIB_DONT_CHECK_RANGE"        => 16,
  30.                   "NETSNMP_DS_LIB_NO_TOKEN_WARNINGS"       => 17,
  31.                   "NETSNMP_DS_LIB_NUMERIC_TIMETICKS"       => 18,
  32.                   "NETSNMP_DS_LIB_ESCAPE_QUOTES"           => 19,
  33.                   "NETSNMP_DS_LIB_REVERSE_ENCODE"          => 20,
  34.                   "NETSNMP_DS_LIB_PRINT_BARE_VALUE"        => 21,
  35.                   "NETSNMP_DS_LIB_EXTENDED_INDEX"          => 22,
  36.                   "NETSNMP_DS_LIB_PRINT_HEX_TEXT"          => 23,
  37.                   "NETSNMP_DS_LIB_PRINT_UCD_STYLE_OID"     => 24,
  38.                   "NETSNMP_DS_LIB_READ_UCD_STYLE_OID"      => 25,
  39.                   "NETSNMP_DS_LIB_HAVE_READ_PREMIB_CONFIG" => 26,
  40.                   "NETSNMP_DS_LIB_HAVE_READ_CONFIG"        => 27,
  41.                   "NETSNMP_DS_LIB_QUICKE_PRINT"            => 28,
  42.                   "NETSNMP_DS_LIB_MIB_WARNINGS"            => 0,
  43.                   "NETSNMP_DS_LIB_SECLEVEL"                => 1,
  44.                   "NETSNMP_DS_LIB_SNMPVERSION"             => 2,
  45.                   "NETSNMP_DS_LIB_DEFAULT_PORT"            => 3,
  46.                   "NETSNMP_DS_LIB_OID_OUTPUT_FORMAT"       => 4,
  47.                   "NETSNMP_DS_SNMP_VERSION_1"              => 128,
  48.                   "NETSNMP_DS_SNMP_VERSION_2c"             => 1,
  49.                   "NETSNMP_DS_SNMP_VERSION_3"              => 3,
  50.                   "NETSNMP_DS_LIB_SECNAME"                 => 0,
  51.                   "NETSNMP_DS_LIB_CONTEXT"                 => 1,
  52.                   "NETSNMP_DS_LIB_PASSPHRASE"              => 2,
  53.                   "NETSNMP_DS_LIB_AUTHPASSPHRASE"          => 3,
  54.                   "NETSNMP_DS_LIB_PRIVPASSPHRASE"          => 4,
  55.                   "NETSNMP_DS_LIB_OPTIONALCONFIG"          => 5,
  56.                   "NETSNMP_DS_LIB_APPTYPE"                 => 6,
  57.                   "NETSNMP_DS_LIB_COMMUNITY"               => 7,
  58.                   "NETSNMP_DS_LIB_PERSISTENT_DIR"          => 8,
  59.                   "NETSNMP_DS_LIB_CONFIGURATION_DIR"       => 9,
  60.                   "NETSNMP_DS_LIB_SECMODEL"                => 10,
  61.                   "NETSNMP_DS_LIB_MIBDIRS"                 => 11,
  62.   );
  63. print "1.." . (scalar(keys(%tests)) + 10) . "n"; 
  64.     }
  65. END {print "not ok 1n" unless $loaded;}
  66. use NetSNMP::default_store (':all');
  67. $loaded = 1;
  68. print "ok 1n";
  69. ######################### End of black magic.
  70. # Insert your test code below (better if it prints "ok 13"
  71. # (correspondingly "not ok 13") depending on the success of chunk 13
  72. # of the test code):
  73. print ((netsnmp_ds_set_string(1, 1, "hi there") == 0) ? "ok 2n" : "not ok 2n"); 
  74. print ((netsnmp_ds_get_string(1, 1) eq "hi there") ? "ok 3n" : "not ok 3n"); 
  75. print ((netsnmp_ds_set_int(1, 1, 42) == 0) ? "ok 4n" : "not ok 4n"); 
  76. print ((netsnmp_ds_get_int(1, 1) == 42) ? "ok 5n" : "not ok 5n"); 
  77. print ((netsnmp_ds_get_int(1, 2) == 0) ? "ok 6n" : "not ok 6n"); 
  78. print ((NETSNMP_DS_LIB_REGEX_ACCESS == 15) ? "ok 7n" : "not ok 7n"); 
  79. print ((netsnmp_ds_get_int(NETSNMP_DS_APPLICATION_ID, 1) == 42) ? "ok 8n" : "not ok 8n"); 
  80. print ((netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, DS_LIB_DEFAULT_PORT, 9161) == 0) ? "ok 9n" : "not ok 9n"); 
  81. print ((netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, DS_LIB_DEFAULT_PORT) == 9161) ? "ok 10n" : "not ok 10n"); 
  82. $c = 10;
  83. foreach my $i (keys(%tests)) {
  84.     my $str = "NetSNMP::default_store::$i";
  85.     my $val = eval $str;
  86. #    print "$i -> $val -> $tests{$i}n";
  87.     $c++;
  88.     print (($val eq $tests{$i})?"ok $cn" : "not ok $cn#  error:  name=$i value_expected=$tests{$i}  value_got=$val n");
  89. }