You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
2.7KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdint.h>
  19. #include <stdio.h>
  20. #include "libavutil/common.h"
  21. #include "libavutil/log.h"
  22. #include "libavutil/rational.h"
  23. #include "libavutil/parseutils.h"
  24. int main(void)
  25. {
  26. int i;
  27. uint8_t rgba[4];
  28. static const char *const rates[] = {
  29. "-inf",
  30. "inf",
  31. "nan",
  32. "123/0",
  33. "-123 / 0",
  34. "",
  35. "/",
  36. " 123 / 321",
  37. "foo/foo",
  38. "foo/1",
  39. "1/foo",
  40. "0/0",
  41. "/0",
  42. "1/",
  43. "1",
  44. "0",
  45. "-123/123",
  46. "-foo",
  47. "123.23",
  48. ".23",
  49. "-.23",
  50. "-0.234",
  51. "-0.0000001",
  52. " 21332.2324 ",
  53. " -21332.2324 ",
  54. };
  55. static const char *const color_names[] = {
  56. "foo",
  57. "red",
  58. "Red ",
  59. "RED",
  60. "Violet",
  61. "Yellow",
  62. "Red",
  63. "0x000000",
  64. "0x0000000",
  65. "0xff000000",
  66. "0x3e34ff",
  67. "0x3e34ffaa",
  68. "0xffXXee",
  69. "0xfoobar",
  70. "0xffffeeeeeeee",
  71. "#ff0000",
  72. "#ffXX00",
  73. "ff0000",
  74. "ffXX00",
  75. "red@foo",
  76. "random@10",
  77. "0xff0000@1.0",
  78. "red@",
  79. "red@0xfff",
  80. "red@0xf",
  81. "red@2",
  82. "red@0.1",
  83. "red@-1",
  84. "red@0.5",
  85. "red@1.0",
  86. "red@256",
  87. "red@10foo",
  88. "red@-1.0",
  89. "red@-0.0",
  90. };
  91. printf("Testing av_parse_video_rate()\n");
  92. for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) {
  93. int ret;
  94. AVRational q = { 0, 0 };
  95. ret = av_parse_video_rate(&q, rates[i]);
  96. printf("'%s' -> %d/%d %s\n",
  97. rates[i], q.num, q.den, ret ? "ERROR" : "OK");
  98. }
  99. printf("\nTesting av_parse_color()\n");
  100. av_log_set_level(AV_LOG_DEBUG);
  101. for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) {
  102. if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0)
  103. printf("%s -> R(%d) G(%d) B(%d) A(%d)\n",
  104. color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]);
  105. }
  106. return 0;
  107. }