testfmt.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "testutil.h"
  17. #include "fspr.h"
  18. #include "fspr_portable.h"
  19. #include "fspr_strings.h"
  20. static void ssize_t_fmt(abts_case *tc, void *data)
  21. {
  22. char buf[100];
  23. fspr_ssize_t var = 0;
  24. sprintf(buf, "%" APR_SSIZE_T_FMT, var);
  25. ABTS_STR_EQUAL(tc, "0", buf);
  26. fspr_snprintf(buf, sizeof(buf), "%" APR_SSIZE_T_FMT, var);
  27. ABTS_STR_EQUAL(tc, "0", buf);
  28. }
  29. static void size_t_fmt(abts_case *tc, void *data)
  30. {
  31. char buf[100];
  32. fspr_size_t var = 0;
  33. sprintf(buf, "%" APR_SIZE_T_FMT, var);
  34. ABTS_STR_EQUAL(tc, "0", buf);
  35. fspr_snprintf(buf, sizeof(buf), "%" APR_SIZE_T_FMT, var);
  36. ABTS_STR_EQUAL(tc, "0", buf);
  37. }
  38. static void off_t_fmt(abts_case *tc, void *data)
  39. {
  40. char buf[100];
  41. fspr_off_t var = 0;
  42. sprintf(buf, "%" APR_OFF_T_FMT, var);
  43. ABTS_STR_EQUAL(tc, "0", buf);
  44. fspr_snprintf(buf, sizeof(buf), "%" APR_OFF_T_FMT, var);
  45. ABTS_STR_EQUAL(tc, "0", buf);
  46. }
  47. static void pid_t_fmt(abts_case *tc, void *data)
  48. {
  49. char buf[100];
  50. pid_t var = 0;
  51. sprintf(buf, "%" APR_PID_T_FMT, var);
  52. ABTS_STR_EQUAL(tc, "0", buf);
  53. fspr_snprintf(buf, sizeof(buf), "%" APR_PID_T_FMT, var);
  54. ABTS_STR_EQUAL(tc, "0", buf);
  55. }
  56. static void int64_t_fmt(abts_case *tc, void *data)
  57. {
  58. char buf[100];
  59. fspr_int64_t var = 0;
  60. sprintf(buf, "%" APR_INT64_T_FMT, var);
  61. ABTS_STR_EQUAL(tc, "0", buf);
  62. fspr_snprintf(buf, sizeof(buf), "%" APR_INT64_T_FMT, var);
  63. ABTS_STR_EQUAL(tc, "0", buf);
  64. }
  65. static void uint64_t_fmt(abts_case *tc, void *data)
  66. {
  67. char buf[100];
  68. fspr_uint64_t var = APR_UINT64_C(14000000);
  69. sprintf(buf, "%" APR_UINT64_T_FMT, var);
  70. ABTS_STR_EQUAL(tc, "14000000", buf);
  71. fspr_snprintf(buf, sizeof(buf), "%" APR_UINT64_T_FMT, var);
  72. ABTS_STR_EQUAL(tc, "14000000", buf);
  73. }
  74. static void uint64_t_hex_fmt(abts_case *tc, void *data)
  75. {
  76. char buf[100];
  77. fspr_uint64_t var = APR_UINT64_C(14000000);
  78. sprintf(buf, "%" APR_UINT64_T_HEX_FMT, var);
  79. ABTS_STR_EQUAL(tc, "d59f80", buf);
  80. fspr_snprintf(buf, sizeof(buf), "%" APR_UINT64_T_HEX_FMT, var);
  81. ABTS_STR_EQUAL(tc, "d59f80", buf);
  82. }
  83. static void more_int64_fmts(abts_case *tc, void *data)
  84. {
  85. char buf[100];
  86. fspr_int64_t i = APR_INT64_C(-42);
  87. fspr_int64_t ibig = APR_INT64_C(-314159265358979323);
  88. fspr_uint64_t ui = APR_UINT64_C(42);
  89. fspr_uint64_t big = APR_UINT64_C(3141592653589793238);
  90. fspr_snprintf(buf, sizeof buf, "%" APR_INT64_T_FMT, i);
  91. ABTS_STR_EQUAL(tc, buf, "-42");
  92. fspr_snprintf(buf, sizeof buf, "%" APR_UINT64_T_FMT, ui);
  93. ABTS_STR_EQUAL(tc, buf, "42");
  94. fspr_snprintf(buf, sizeof buf, "%" APR_UINT64_T_FMT, big);
  95. ABTS_STR_EQUAL(tc, buf, "3141592653589793238");
  96. fspr_snprintf(buf, sizeof buf, "%" APR_INT64_T_FMT, ibig);
  97. ABTS_STR_EQUAL(tc, buf, "-314159265358979323");
  98. }
  99. abts_suite *testfmt(abts_suite *suite)
  100. {
  101. suite = ADD_SUITE(suite)
  102. abts_run_test(suite, ssize_t_fmt, NULL);
  103. abts_run_test(suite, size_t_fmt, NULL);
  104. abts_run_test(suite, off_t_fmt, NULL);
  105. abts_run_test(suite, pid_t_fmt, NULL);
  106. abts_run_test(suite, int64_t_fmt, NULL);
  107. abts_run_test(suite, uint64_t_fmt, NULL);
  108. abts_run_test(suite, uint64_t_hex_fmt, NULL);
  109. abts_run_test(suite, more_int64_fmts, NULL);
  110. return suite;
  111. }