public.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright (c) 2015 the Civetweb developers
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. #include <stdlib.h>
  22. #include "public.h"
  23. #include <civetweb.h>
  24. /* This unit test file uses the excellent Check unit testing library.
  25. * The API documentation is available here:
  26. * http://check.sourceforge.net/doc/check_html/index.html
  27. */
  28. START_TEST (test_mg_get_cookie)
  29. {
  30. char buf[20];
  31. ck_assert_int_eq(-2, mg_get_cookie("", "foo", NULL, sizeof(buf)));
  32. ck_assert_int_eq(-2, mg_get_cookie("", "foo", buf, 0));
  33. ck_assert_int_eq(-1, mg_get_cookie("", "foo", buf, sizeof(buf)));
  34. ck_assert_int_eq(-1, mg_get_cookie("", NULL, buf, sizeof(buf)));
  35. ck_assert_int_eq(1, mg_get_cookie("a=1; b=2; c; d", "a", buf, sizeof(buf)));
  36. ck_assert_str_eq("1", buf);
  37. ck_assert_int_eq(1, mg_get_cookie("a=1; b=2; c; d", "b", buf, sizeof(buf)));
  38. ck_assert_str_eq("2", buf);
  39. ck_assert_int_eq(3, mg_get_cookie("a=1; b=123", "b", buf, sizeof(buf)));
  40. ck_assert_str_eq("123", buf);
  41. ck_assert_int_eq(-1, mg_get_cookie("a=1; b=2; c; d", "c", buf, sizeof(buf)));
  42. }
  43. END_TEST
  44. Suite * make_public_suite (void) {
  45. Suite * const suite = suite_create("Public");
  46. TCase * const cookies = tcase_create("Cookies");
  47. tcase_add_test(cookies, test_mg_get_cookie);
  48. suite_add_tcase(suite, cookies);
  49. return suite;
  50. }