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

SNMP编程

开发平台:

Unix_Linux

  1. /*
  2.  * T.c
  3.  *
  4.  * Expected SUCCESSes for all tests:    FIX [+ FIX ...]
  5.  *                                      (List number of lines containing the
  6.  *                                       string "SUCCESS" that are expected
  7.  *                                       to be printed to stdout.)
  8.  *
  9.  * Returns:
  10.  *      Number of FAILUREs.
  11.  *
  12.  * FIX  Short test description/table of contents.       SUCCESSes: FIX
  13.  */
  14. #include <net-snmp/net-snmp-config.h>
  15. #include <sys/types.h>
  16. #include <stdio.h>
  17. #ifdef HAVE_STDLIB_H
  18. #include <stdlib.h>
  19. #endif
  20. /*
  21.  * #include ... 
  22.  */
  23. extern char    *optarg;
  24. extern int      optind, optopt, opterr;
  25. /*
  26.  * Globals, &c...
  27.  */
  28. char           *local_progname;
  29. #define USAGE "Usage: %s [-h][-aS]"
  30. #define OPTIONLIST "ahS"
  31. int             doalltests = 0, dosomething = 0;
  32. #define ALLOPTIONS (doalltests + dosomething)
  33. #define LOCAL_MAXBUF (1024 * 8)
  34. #define NL "n"
  35. #define OUTPUT(o) fprintf(stdout, "nn%snn", o);
  36. #define SUCCESS(s)
  37. {
  38. if (!failcount)
  39. fprintf(stdout, "nSUCCESS: %sn", s);
  40. }
  41. #define FAILED(e, f)
  42. {
  43. if (e != SNMPERR_SUCCESS) {
  44. fprintf(stdout, "nFAILED: %sn", f);
  45. failcount += 1;
  46. }
  47. }
  48. /*
  49.  * Prototypes.
  50.  */
  51. void            usage(FILE * ofp);
  52. int             test_dosomething(void);
  53. int
  54. main(int argc, char **argv)
  55. {
  56.     int             rval = SNMPERR_SUCCESS, failcount = 0;
  57.     char            ch;
  58.     local_progname = argv[0];
  59.     EM(-1);                     /* */
  60.     /*
  61.      * Parse.
  62.      */
  63.     while ((ch = getopt(argc, argv, OPTIONLIST)) != EOF) {
  64.         switch (ch) {
  65.         case 'a':
  66.             doalltests = 1;
  67.             break;
  68.         case 'S':
  69.             dosomething = 1;
  70.             break;
  71.         case 'h':
  72.             rval = 0;
  73.         default:
  74.             usage(stdout);
  75.             exit(rval);
  76.         }
  77.         argc -= 1;
  78.         argv += 1;
  79.         if (optarg) {
  80.             argc -= 1;
  81.             argv += 1;
  82.             optarg = NULL;
  83.         }
  84.         optind = 1;
  85.     }                           /* endwhile getopt */
  86.     if ((argc > 1)) {
  87.         usage(stdout);
  88.         exit(1000);
  89.     } else if (ALLOPTIONS != 1) {
  90.         usage(stdout);
  91.         exit(1000);
  92.     }
  93.     /*
  94.      * Test stuff.
  95.      */
  96.     if (dosomething || doalltests) {
  97.         failcount += test_dosomething();
  98.     }
  99.     /*
  100.      * Cleanup.
  101.      */
  102.     return failcount;
  103. }                               /* end main() */
  104. void
  105. usage(FILE * ofp)
  106. {
  107.     fprintf(ofp,
  108.             USAGE
  109.             "" NL
  110.             " -a All tests." NL
  111.             " -S Test something." NL
  112.             " -h Help." NL "" NL, local_progname);
  113. }                               /* end usage() */
  114. #ifdef EXAMPLE
  115. #endif                          /* EXAMPLE */
  116. /*******************************************************************-o-******
  117.  * test_dosomething
  118.  *
  119.  * Returns:
  120.  * Number of failures.
  121.  *
  122.  *
  123.  * Test template.
  124.  */
  125. int
  126. test_dosomething(void)
  127. {
  128.     int             rval = SNMPERR_SUCCESS, failcount = 0;
  129.     EM0(1, "UNIMPLEMENTED");    /* EM(1); /* */
  130.   test_dosomething_quit:
  131.     return failcount;
  132. }                               /* end test_dosomething() */