prftest2.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /*
  6. ** File: prftest2.c
  7. ** Description:
  8. ** This is a simple test of the PR_snprintf() function defined
  9. ** in prprf.c.
  10. **
  11. ** Modification History:
  12. ** 14-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
  13. ** The debug mode will print all of the printfs associated with this test.
  14. ** The regress mode will be the default mode. Since the regress tool limits
  15. ** the output to a one line status:PASS or FAIL,all of the printf statements
  16. ** have been handled with an if (debug_mode) statement.
  17. ** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
  18. ** recognize the return code from tha main program.
  19. ***********************************************************************/
  20. /***********************************************************************
  21. ** Includes
  22. ***********************************************************************/
  23. /* Used to get the command line option */
  24. #include "plgetopt.h"
  25. #include "prlong.h"
  26. #include "prinit.h"
  27. #include "prprf.h"
  28. #include <string.h>
  29. #define BUF_SIZE 128
  30. PRIntn failed_already=0;
  31. PRIntn debug_mode;
  32. int main(int argc, char **argv)
  33. {
  34. PRInt16 i16;
  35. PRIntn n;
  36. PRInt32 i32;
  37. PRInt64 i64;
  38. char buf[BUF_SIZE];
  39. /* The command line argument: -d is used to determine if the test is being run
  40. in debug mode. The regress tool requires only one line output:PASS or FAIL.
  41. All of the printfs associated with this test has been handled with a if (debug_mode)
  42. test.
  43. Usage: test_name -d
  44. */
  45. PLOptStatus os;
  46. PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
  47. while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  48. {
  49. if (PL_OPT_BAD == os) {
  50. continue;
  51. }
  52. switch (opt->option)
  53. {
  54. case 'd': /* debug mode */
  55. debug_mode = 1;
  56. break;
  57. default:
  58. break;
  59. }
  60. }
  61. PL_DestroyOptState(opt);
  62. /* main test */
  63. PR_STDIO_INIT();
  64. i16 = -32;
  65. n = 30;
  66. i32 = 64;
  67. LL_I2L(i64, 333);
  68. PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
  69. if (!strcmp(buf, "30 -32 333 64")) {
  70. if (debug_mode) {
  71. printf("PR_snprintf test 2 passed\n");
  72. }
  73. } else {
  74. if (debug_mode) {
  75. printf("PR_snprintf test 2 failed\n");
  76. printf("Converted string is %s\n", buf);
  77. printf("Should be 30 -32 333 64\n");
  78. }
  79. else {
  80. failed_already=1;
  81. }
  82. }
  83. if(failed_already)
  84. {
  85. printf("FAILED\n");
  86. return 1;
  87. }
  88. else
  89. {
  90. printf("PASSED\n");
  91. return 0;
  92. }
  93. }