prftest1.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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: prftest1.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. ***********************************************************************/
  18. /***********************************************************************
  19. ** Includes
  20. ***********************************************************************/
  21. /* Used to get the command line option */
  22. #include "plgetopt.h"
  23. #include "prttools.h"
  24. #include "prinit.h"
  25. #include "prlong.h"
  26. #include "prprf.h"
  27. #include <string.h>
  28. #define BUF_SIZE 128
  29. /***********************************************************************
  30. ** PRIVATE FUNCTION: Test_Result
  31. ** DESCRIPTION: Used in conjunction with the regress tool, prints out the
  32. ** status of the test case.
  33. ** INPUTS: PASS/FAIL
  34. ** OUTPUTS: None
  35. ** RETURN: None
  36. ** SIDE EFFECTS:
  37. **
  38. ** RESTRICTIONS:
  39. ** None
  40. ** MEMORY: NA
  41. ** ALGORITHM: Determine what the status is and print accordingly.
  42. **
  43. ***********************************************************************/
  44. static void Test_Result (int result)
  45. {
  46. if (result == PASS) {
  47. printf ("PASS\n");
  48. }
  49. else {
  50. printf ("FAIL\n");
  51. }
  52. }
  53. int main(int argc, char **argv)
  54. {
  55. PRInt16 i16;
  56. PRIntn n;
  57. PRInt32 i32;
  58. PRInt64 i64;
  59. char buf[BUF_SIZE];
  60. char answer[BUF_SIZE];
  61. int i;
  62. /* The command line argument: -d is used to determine if the test is being run
  63. in debug mode. The regress tool requires only one line output:PASS or FAIL.
  64. All of the printfs associated with this test has been handled with a if (debug_mode)
  65. test.
  66. Usage: test_name -d
  67. */
  68. PLOptStatus os;
  69. PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
  70. while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
  71. {
  72. if (PL_OPT_BAD == os) {
  73. continue;
  74. }
  75. switch (opt->option)
  76. {
  77. case 'd': /* debug mode */
  78. debug_mode = 1;
  79. break;
  80. default:
  81. break;
  82. }
  83. }
  84. PL_DestroyOptState(opt);
  85. /* main test */
  86. PR_STDIO_INIT();
  87. i16 = -1;
  88. n = -1;
  89. i32 = -1;
  90. LL_I2L(i64, i32);
  91. PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
  92. strcpy(answer, "ffff ");
  93. for (i = PR_BYTES_PER_INT * 2; i; i--) {
  94. strcat(answer, "f");
  95. }
  96. strcat(answer, " ffffffff ffffffffffffffff");
  97. if (!strcmp(buf, answer)) {
  98. if (debug_mode) {
  99. printf("PR_snprintf test 1 passed\n");
  100. }
  101. else {
  102. Test_Result (PASS);
  103. }
  104. } else {
  105. if (debug_mode) {
  106. printf("PR_snprintf test 1 failed\n");
  107. printf("Converted string is %s\n", buf);
  108. printf("Should be %s\n", answer);
  109. }
  110. else {
  111. Test_Result (FAIL);
  112. }
  113. }
  114. return 0;
  115. }