avstring.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdio.h>
  19. #include "libavutil/common.h"
  20. #include "libavutil/mem.h"
  21. #include "libavutil/avstring.h"
  22. int main(void)
  23. {
  24. int i;
  25. char *fullpath;
  26. static const char * const strings[] = {
  27. "''",
  28. "",
  29. ":",
  30. "\\",
  31. "'",
  32. " '' :",
  33. " '' '' :",
  34. "foo '' :",
  35. "'foo'",
  36. "foo ",
  37. " ' foo ' ",
  38. "foo\\",
  39. "foo': blah:blah",
  40. "foo\\: blah:blah",
  41. "foo\'",
  42. "'foo : ' :blahblah",
  43. "\\ :blah",
  44. " foo",
  45. " foo ",
  46. " foo \\ ",
  47. "foo ':blah",
  48. " foo bar : blahblah",
  49. "\\f\\o\\o",
  50. "'foo : \\ \\ ' : blahblah",
  51. "'\\fo\\o:': blahblah",
  52. "\\'fo\\o\\:': foo ' :blahblah"
  53. };
  54. printf("Testing av_get_token()\n");
  55. for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) {
  56. const char *p = strings[i];
  57. char *q;
  58. printf("|%s|", p);
  59. q = av_get_token(&p, ":");
  60. printf(" -> |%s|", q);
  61. printf(" + |%s|\n", p);
  62. av_free(q);
  63. }
  64. printf("Testing av_append_path_component()\n");
  65. #define TEST_APPEND_PATH_COMPONENT(path, component, expected) \
  66. fullpath = av_append_path_component((path), (component)); \
  67. printf("%s = %s\n", fullpath ? fullpath : "(null)", expected); \
  68. av_free(fullpath);
  69. TEST_APPEND_PATH_COMPONENT(NULL, NULL, "(null)")
  70. TEST_APPEND_PATH_COMPONENT("path", NULL, "path");
  71. TEST_APPEND_PATH_COMPONENT(NULL, "comp", "comp");
  72. TEST_APPEND_PATH_COMPONENT("path", "comp", "path/comp");
  73. TEST_APPEND_PATH_COMPONENT("path/", "comp", "path/comp");
  74. TEST_APPEND_PATH_COMPONENT("path", "/comp", "path/comp");
  75. TEST_APPEND_PATH_COMPONENT("path/", "/comp", "path/comp");
  76. TEST_APPEND_PATH_COMPONENT("path/path2/", "/comp/comp2", "path/path2/comp/comp2");
  77. return 0;
  78. }