FFmpeg
uuid.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Pierre-Anthony Lemieux <pal@palemieux.com>
3  * Zane van Iperen <zane@zanevaniperen.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/uuid.h"
23 #include "libavutil/log.h"
24 
25 static const char *UUID_1 = "6021b21e-894e-43ff-8317-1ca891c1c49b";
26 static const char *UUID_1_UC = "6021B21E-894E-43FF-8317-1CA891C1C49B";
27 static const char *UUID_1_MIXED = "6021b21e-894E-43fF-8317-1CA891C1c49b";
28 static const char *UUID_1_URN = "urn:uuid:6021b21e-894e-43ff-8317-1ca891c1c49b";
29 static const AVUUID UUID_1_BYTES = {0x60, 0x21, 0xb2, 0x1e, 0x89, 0x4e, 0x43, 0xff,
30  0x83, 0x17, 0x1c, 0xa8, 0x91, 0xc1, 0xc4, 0x9b};
31 
32 static const AVUUID UUID_NIL = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
34 
35 static const char *UUID_BAD_1 = "16a2c9f8-afbc-4767-8621-8cb2b27599";
36 static const char *UUID_BAD_2 = "75df62c2999b4bd38c9d8058fcde9123";
37 static const char *UUID_BAD_3 = "a1b9a05e-f1d1-464g-a951-1ba0a374f02";
38 static const char *UUID_BAD_4 = "279c66d432-7b39-41d5-966f-5e8138265c20";
39 
40 int main(int argc, char **argv)
41 {
42  AVUUID uuid;
43  AVUUID uuid2 = {0x32, 0xc7, 0x00, 0xc4, 0xd5, 0xd7, 0x42, 0x0,
44  0x93, 0xc0, 0x3b, 0x6d, 0xea, 0x1b, 0x20, 0x5b};
45 
46  /* test parsing */
47 
48  if (av_uuid_parse(UUID_1, uuid))
49  return 1;
50 
51  if (!av_uuid_equal(uuid, UUID_1_BYTES))
52  return 1;
53 
54  /* test nil */
55 
56  av_uuid_nil(uuid);
57 
58  if (!av_uuid_equal(uuid, UUID_NIL))
59  return 1;
60 
61  /* test equality */
62 
63  if (av_uuid_equal(UUID_1_BYTES, uuid2))
64  return 1;
65 
66  /* test copy */
67 
68  av_uuid_copy(uuid2, UUID_1_BYTES);
69 
70  if (!av_uuid_equal(uuid2, UUID_1_BYTES))
71  return 1;
72 
73  /* test uppercase parsing */
74 
75  if (av_uuid_parse(UUID_1_UC, uuid))
76  return 1;
77 
78  if (!av_uuid_equal(uuid, UUID_1_BYTES))
79  return 1;
80 
81  /* test mixed-case parsing */
82 
83  if (av_uuid_parse(UUID_1_MIXED, uuid))
84  return 1;
85 
86  if (!av_uuid_equal(uuid, UUID_1_BYTES))
87  return 1;
88 
89  /* test URN uuid parse */
90 
91  if (av_uuid_urn_parse(UUID_1_URN, uuid))
92  return 1;
93 
94  if (!av_uuid_equal(uuid, UUID_1_BYTES))
95  return 1;
96 
97  /* test parse range */
98 
99  if (av_uuid_parse_range(UUID_1_URN + 9, UUID_1_URN + 45, uuid))
100  return 1;
101 
102  if (!av_uuid_equal(uuid, UUID_1_BYTES))
103  return 1;
104 
105  /* test bad parse range */
106 
107  if (!av_uuid_parse_range(UUID_1_URN + 9, UUID_1_URN + 44, uuid))
108  return 1;
109 
110  /* test bad parse range 2 */
111 
112  if (!av_uuid_parse_range(UUID_1_URN + 8, UUID_1_URN + 44, uuid))
113  return 1;
114 
115  /* test bad parse range 2 */
116 
117  if (!av_uuid_parse_range(UUID_1_URN + 8, UUID_1_URN + 45, uuid))
118  return 1;
119 
120  /* test bad uuid 1 */
121 
122  if (!av_uuid_parse(UUID_BAD_1, uuid))
123  return 1;
124 
125  /* test bad uuid 2 */
126 
127  if (!av_uuid_parse(UUID_BAD_2, uuid))
128  return 1;
129 
130  /* test bad uuid 3 */
131 
132  if (!av_uuid_parse(UUID_BAD_3, uuid))
133  return 1;
134 
135  /* test bad uuid 4 */
136 
137  if (!av_uuid_parse(UUID_BAD_4, uuid))
138  return 1;
139 
140  return 0;
141 }
AVUUID
uint8_t AVUUID[AV_UUID_LEN]
Definition: uuid.h:60
UUID_BAD_2
static const char * UUID_BAD_2
Definition: uuid.c:36
UUID_1_UC
static const char * UUID_1_UC
Definition: uuid.c:26
UUID_BAD_1
static const char * UUID_BAD_1
Definition: uuid.c:35
UUID_NIL
static const AVUUID UUID_NIL
Definition: uuid.c:32
UUID_1_MIXED
static const char * UUID_1_MIXED
Definition: uuid.c:27
av_uuid_parse
int av_uuid_parse(const char *in, AVUUID uu)
Parses a string representation of a UUID formatted according to IETF RFC 4122 into an AVUUID.
Definition: uuid.c:67
uuid.h
av_uuid_nil
static void av_uuid_nil(AVUUID uu)
Sets a UUID to the nil UUID, i.e.
Definition: uuid.h:141
UUID_1_URN
static const char * UUID_1_URN
Definition: uuid.c:28
av_uuid_equal
static int av_uuid_equal(const AVUUID uu1, const AVUUID uu2)
Compares two UUIDs for equality.
Definition: uuid.h:119
UUID_1
static const char * UUID_1
Definition: uuid.c:25
log.h
UUID_1_BYTES
static const AVUUID UUID_1_BYTES
Definition: uuid.c:29
main
int main(int argc, char **argv)
Definition: uuid.c:40
UUID_BAD_4
static const char * UUID_BAD_4
Definition: uuid.c:38
UUID_BAD_3
static const char * UUID_BAD_3
Definition: uuid.c:37
av_uuid_parse_range
int av_uuid_parse_range(const char *in_start, const char *in_end, AVUUID uu)
Parses a string representation of a UUID formatted according to IETF RFC 4122 into an AVUUID.
Definition: uuid.c:88
av_uuid_copy
static void av_uuid_copy(AVUUID dest, const AVUUID src)
Copies the bytes of src into dest.
Definition: uuid.h:130
av_uuid_urn_parse
int av_uuid_urn_parse(const char *in, AVUUID uu)
Parses a URN representation of a UUID, as specified at IETF RFC 4122, into an AVUUID.
Definition: uuid.c:135