teststrnatcmp.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "fspr_file_io.h"
  17. #include "fspr_errno.h"
  18. #include "fspr_strings.h"
  19. #include "testutil.h"
  20. static void less0(abts_case *tc, void *data)
  21. {
  22. int rv = fspr_strnatcmp("a", "b");
  23. ABTS_ASSERT(tc, "didn't compare simple strings properly", rv < 0);
  24. }
  25. static void str_equal(abts_case *tc, void *data)
  26. {
  27. int rv = fspr_strnatcmp("a", "a");
  28. ABTS_ASSERT(tc, "didn't compare simple strings properly", rv == 0);
  29. }
  30. static void more0(abts_case *tc, void *data)
  31. {
  32. int rv = fspr_strnatcmp("b", "a");
  33. ABTS_ASSERT(tc, "didn't compare simple strings properly", rv > 0);
  34. }
  35. static void less_ignore_case(abts_case *tc, void *data)
  36. {
  37. int rv = fspr_strnatcasecmp("a", "B");
  38. ABTS_ASSERT(tc, "didn't compare simple strings properly", rv < 0);
  39. }
  40. static void str_equal_ignore_case(abts_case *tc, void *data)
  41. {
  42. int rv = fspr_strnatcasecmp("a", "A");
  43. ABTS_ASSERT(tc, "didn't compare simple strings properly", rv == 0);
  44. }
  45. static void more_ignore_case(abts_case *tc, void *data)
  46. {
  47. int rv = fspr_strnatcasecmp("b", "A");
  48. ABTS_ASSERT(tc, "didn't compare simple strings properly", rv > 0);
  49. }
  50. static void natcmp(abts_case *tc, void *data)
  51. {
  52. int rv = fspr_strnatcasecmp("a2", "a10");
  53. ABTS_ASSERT(tc, "didn't compare simple strings properly", rv < 0);
  54. }
  55. abts_suite *teststrnatcmp(abts_suite *suite)
  56. {
  57. suite = ADD_SUITE(suite)
  58. abts_run_test(suite, less0, NULL);
  59. abts_run_test(suite, str_equal, NULL);
  60. abts_run_test(suite, more0, NULL);
  61. abts_run_test(suite, less_ignore_case, NULL);
  62. abts_run_test(suite, str_equal_ignore_case, NULL);
  63. abts_run_test(suite, more_ignore_case, NULL);
  64. abts_run_test(suite, natcmp, NULL);
  65. return suite;
  66. }