Line | Branch | Exec | Source |
---|---|---|---|
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 | |||
19 | #include <stdio.h> | ||
20 | |||
21 | #include "libavutil/common.h" | ||
22 | #include "libavutil/mem.h" | ||
23 | #include "libavutil/avstring.h" | ||
24 | |||
25 | 1 | int main(void) | |
26 | { | ||
27 | int i; | ||
28 | char *fullpath, *ptr; | ||
29 | static const char * const strings[] = { | ||
30 | "''", | ||
31 | "", | ||
32 | ":", | ||
33 | "\\", | ||
34 | "'", | ||
35 | " '' :", | ||
36 | " '' '' :", | ||
37 | "foo '' :", | ||
38 | "'foo'", | ||
39 | "foo ", | ||
40 | " ' foo ' ", | ||
41 | "foo\\", | ||
42 | "foo': blah:blah", | ||
43 | "foo\\: blah:blah", | ||
44 | "foo\'", | ||
45 | "'foo : ' :blahblah", | ||
46 | "\\ :blah", | ||
47 | " foo", | ||
48 | " foo ", | ||
49 | " foo \\ ", | ||
50 | "foo ':blah", | ||
51 | " foo bar : blahblah", | ||
52 | "\\f\\o\\o", | ||
53 | "'foo : \\ \\ ' : blahblah", | ||
54 | "'\\fo\\o:': blahblah", | ||
55 | "\\'fo\\o\\:': foo ' :blahblah" | ||
56 | }; | ||
57 | 1 | const char *haystack = "Education consists mainly in what we have unlearned."; | |
58 | const char * const needle[] = {"learned.", "unlearned.", "Unlearned"}; | ||
59 | |||
60 | 1 | printf("Testing av_get_token()\n"); | |
61 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 1 times.
|
27 | for (i = 0; i < FF_ARRAY_ELEMS(strings); i++) { |
62 | 26 | const char *p = strings[i]; | |
63 | char *q; | ||
64 | 26 | printf("|%s|", p); | |
65 | 26 | q = av_get_token(&p, ":"); | |
66 | 26 | printf(" -> |%s|", q); | |
67 | 26 | printf(" + |%s|\n", p); | |
68 | 26 | av_free(q); | |
69 | } | ||
70 | |||
71 | 1 | printf("Testing av_append_path_component()\n"); | |
72 | #define TEST_APPEND_PATH_COMPONENT(path, component, expected) \ | ||
73 | fullpath = av_append_path_component((path), (component)); \ | ||
74 | printf("%s = %s\n", fullpath ? fullpath : "(null)", expected); \ | ||
75 | av_free(fullpath); | ||
76 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | TEST_APPEND_PATH_COMPONENT(NULL, NULL, "(null)") |
77 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_APPEND_PATH_COMPONENT("path", NULL, "path"); |
78 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_APPEND_PATH_COMPONENT(NULL, "comp", "comp"); |
79 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_APPEND_PATH_COMPONENT("path", "comp", "path/comp"); |
80 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_APPEND_PATH_COMPONENT("path/", "comp", "path/comp"); |
81 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_APPEND_PATH_COMPONENT("path", "/comp", "path/comp"); |
82 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_APPEND_PATH_COMPONENT("path/", "/comp", "path/comp"); |
83 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_APPEND_PATH_COMPONENT("path/path2/", "/comp/comp2", "path/path2/comp/comp2"); |
84 | |||
85 | /*Testing av_strnstr()*/ | ||
86 | #define TEST_STRNSTR(haystack, needle, hay_length, expected) \ | ||
87 | ptr = av_strnstr(haystack, needle, hay_length); \ | ||
88 | if (ptr != expected){ \ | ||
89 | printf("expected: %p, received %p\n", expected, ptr); \ | ||
90 | } | ||
91 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | TEST_STRNSTR(haystack, needle [0], strlen(haystack), haystack+44); |
92 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | TEST_STRNSTR(haystack, needle [1], strlen(haystack), haystack+42); |
93 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | TEST_STRNSTR(haystack, needle [2], strlen(haystack), NULL ); |
94 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | TEST_STRNSTR(haystack, strings[1], strlen(haystack), haystack ); |
95 | |||
96 | /*Testing av_strireplace()*/ | ||
97 | #define TEST_STRIREPLACE(haystack, needle, expected) \ | ||
98 | ptr = av_strireplace(haystack, needle, "instead"); \ | ||
99 | if (ptr == NULL) { \ | ||
100 | printf("error, received null pointer!\n"); \ | ||
101 | } else { \ | ||
102 | if (strcmp(ptr, expected) != 0) \ | ||
103 | printf( "expected: %s, received: %s\n", expected, ptr); \ | ||
104 | av_free(ptr); \ | ||
105 | } | ||
106 | |||
107 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | TEST_STRIREPLACE(haystack, needle [0], "Education consists mainly in what we have uninstead"); |
108 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | TEST_STRIREPLACE(haystack, needle [1], "Education consists mainly in what we have instead"); |
109 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | TEST_STRIREPLACE(haystack, needle [2], "Education consists mainly in what we have instead."); |
110 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
|
1 | TEST_STRIREPLACE(haystack, needle [1], "Education consists mainly in what we have instead"); |
111 | |||
112 | 1 | return 0; | |
113 | } | ||
114 |