2
0

testud.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <stdio.h>
  17. #include <stdlib.h>
  18. #include "fspr_file_io.h"
  19. #include "fspr_errno.h"
  20. #include "fspr_general.h"
  21. #include "fspr_lib.h"
  22. #include "fspr_strings.h"
  23. #include "testutil.h"
  24. static fspr_pool_t *pool;
  25. static char *testdata;
  26. static int cleanup_called = 0;
  27. static fspr_status_t string_cleanup(void *data)
  28. {
  29. cleanup_called = 1;
  30. return APR_SUCCESS;
  31. }
  32. static void set_userdata(abts_case *tc, void *data)
  33. {
  34. fspr_status_t rv;
  35. rv = fspr_pool_userdata_set(testdata, "TEST", string_cleanup, pool);
  36. ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
  37. }
  38. static void get_userdata(abts_case *tc, void *data)
  39. {
  40. fspr_status_t rv;
  41. void *retdata;
  42. rv = fspr_pool_userdata_get(&retdata, "TEST", pool);
  43. ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
  44. ABTS_STR_EQUAL(tc, retdata, testdata);
  45. }
  46. static void get_nonexistkey(abts_case *tc, void *data)
  47. {
  48. fspr_status_t rv;
  49. void *retdata;
  50. rv = fspr_pool_userdata_get(&retdata, "DOESNTEXIST", pool);
  51. ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
  52. ABTS_PTR_EQUAL(tc, retdata, NULL);
  53. }
  54. static void post_pool_clear(abts_case *tc, void *data)
  55. {
  56. fspr_status_t rv;
  57. void *retdata;
  58. rv = fspr_pool_userdata_get(&retdata, "DOESNTEXIST", pool);
  59. ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
  60. ABTS_PTR_EQUAL(tc, retdata, NULL);
  61. }
  62. abts_suite *testud(abts_suite *suite)
  63. {
  64. suite = ADD_SUITE(suite)
  65. fspr_pool_create(&pool, p);
  66. testdata = fspr_pstrdup(pool, "This is a test\n");
  67. abts_run_test(suite, set_userdata, NULL);
  68. abts_run_test(suite, get_userdata, NULL);
  69. abts_run_test(suite, get_nonexistkey, NULL);
  70. fspr_pool_clear(pool);
  71. abts_run_test(suite, post_pool_clear, NULL);
  72. return suite;
  73. }