tests/fate/libavutil: add FATE test for stereo3d

Add a unit test covering av_stereo3d_alloc, av_stereo3d_alloc_size,
av_stereo3d_create_side_data, av_stereo3d_type_name,
av_stereo3d_from_name, av_stereo3d_view_name,
av_stereo3d_view_from_name, and av_stereo3d_primary_eye_name.
The from_name calls are driven by a static name table so each
string appears exactly once. Round-trip inverse checks verify
that type_name/from_name and view_name/view_from_name are
consistent with each other.

Coverage for libavutil/stereo3d.c: 0.00% -> 100.00%

Signed-off-by: marcos ashton <marcosashiglesias@gmail.com>
This commit is contained in:
marcos ashton
2026-03-10 14:55:34 +00:00
committed by michaelni
parent ed19c181c2
commit 345071f747
4 changed files with 196 additions and 0 deletions

View File

@@ -301,6 +301,7 @@ TESTPROGS = adler32 \
sha512 \
side_data_array \
softfloat \
stereo3d \
tree \
twofish \
utf8 \

118
libavutil/tests/stereo3d.c Normal file
View File

@@ -0,0 +1,118 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include "libavutil/frame.h"
#include "libavutil/macros.h"
#include "libavutil/mem.h"
#include "libavutil/stereo3d.h"
int main(void)
{
AVStereo3D *s3d;
AVFrame *frame;
size_t size;
int ret;
/* av_stereo3d_alloc_size with size output */
printf("Testing av_stereo3d_alloc_size()\n");
s3d = av_stereo3d_alloc_size(&size);
printf("alloc_size: %s, size>0: %s\n",
s3d ? "OK" : "FAIL", size > 0 ? "yes" : "no");
av_free(s3d);
/* av_stereo3d_alloc (no size) */
s3d = av_stereo3d_alloc();
printf("alloc: %s\n", s3d ? "OK" : "FAIL");
av_free(s3d);
/* av_stereo3d_create_side_data */
printf("\nTesting av_stereo3d_create_side_data()\n");
frame = av_frame_alloc();
s3d = av_stereo3d_create_side_data(frame);
printf("create_side_data: %s\n", s3d ? "OK" : "FAIL");
av_frame_free(&frame);
/* av_stereo3d_type_name - all valid types */
printf("\nTesting av_stereo3d_type_name()\n");
for (int i = 0; i <= AV_STEREO3D_UNSPEC; i++)
printf("type %d: %s\n", i, av_stereo3d_type_name(i));
printf("out of range: %s\n", av_stereo3d_type_name(100));
/* av_stereo3d_from_name - all valid names and unknown */
printf("\nTesting av_stereo3d_from_name()\n");
{
static const char * const names[] = {
"2D", "side by side", "top and bottom", "frame alternate",
"checkerboard", "side by side (quincunx subsampling)",
"interleaved lines", "interleaved columns", "unspecified",
};
for (int i = 0; i < FF_ARRAY_ELEMS(names); i++)
printf("%s: %d\n", names[i], av_stereo3d_from_name(names[i]));
}
ret = av_stereo3d_from_name("nonexistent");
printf("nonexistent: %d\n", ret);
/* av_stereo3d_type_name / av_stereo3d_from_name round-trip */
printf("\nTesting type name round-trip\n");
for (int i = 0; i <= AV_STEREO3D_UNSPEC; i++) {
const char *name = av_stereo3d_type_name(i);
int rt = av_stereo3d_from_name(name);
printf("type roundtrip %d (%s): %s\n", i, name, rt == i ? "OK" : "FAIL");
}
/* av_stereo3d_view_name - all valid views */
printf("\nTesting av_stereo3d_view_name()\n");
for (int i = 0; i <= AV_STEREO3D_VIEW_UNSPEC; i++)
printf("view %d: %s\n", i, av_stereo3d_view_name(i));
printf("out of range: %s\n", av_stereo3d_view_name(100));
/* av_stereo3d_view_name / av_stereo3d_view_from_name round-trip */
printf("\nTesting view name round-trip\n");
for (int i = 0; i <= AV_STEREO3D_VIEW_UNSPEC; i++) {
const char *name = av_stereo3d_view_name(i);
int rt = av_stereo3d_view_from_name(name);
printf("view roundtrip %d (%s): %s\n", i, name, rt == i ? "OK" : "FAIL");
}
/* av_stereo3d_view_from_name */
printf("\nTesting av_stereo3d_view_from_name()\n");
printf("packed: %d\n", av_stereo3d_view_from_name("packed"));
printf("left: %d\n", av_stereo3d_view_from_name("left"));
printf("right: %d\n", av_stereo3d_view_from_name("right"));
printf("unspecified: %d\n", av_stereo3d_view_from_name("unspecified"));
ret = av_stereo3d_view_from_name("nonexistent");
printf("nonexistent: %d\n", ret);
/* av_stereo3d_primary_eye_name - all valid values */
printf("\nTesting av_stereo3d_primary_eye_name()\n");
for (int i = 0; i <= AV_PRIMARY_EYE_RIGHT; i++)
printf("eye %d: %s\n", i, av_stereo3d_primary_eye_name(i));
printf("out of range: %s\n", av_stereo3d_primary_eye_name(100));
/* av_stereo3d_primary_eye_from_name */
printf("\nTesting av_stereo3d_primary_eye_from_name()\n");
printf("none: %d\n", av_stereo3d_primary_eye_from_name("none"));
printf("left: %d\n", av_stereo3d_primary_eye_from_name("left"));
printf("right: %d\n", av_stereo3d_primary_eye_from_name("right"));
ret = av_stereo3d_primary_eye_from_name("nonexistent");
printf("nonexistent: %d\n", ret);
return 0;
}

View File

@@ -156,6 +156,10 @@ FATE_LIBAVUTIL += fate-side_data_array
fate-side_data_array: libavutil/tests/side_data_array$(EXESUF)
fate-side_data_array: CMD = run libavutil/tests/side_data_array$(EXESUF)
FATE_LIBAVUTIL += fate-stereo3d
fate-stereo3d: libavutil/tests/stereo3d$(EXESUF)
fate-stereo3d: CMD = run libavutil/tests/stereo3d$(EXESUF)
FATE_LIBAVUTIL += fate-tree
fate-tree: libavutil/tests/tree$(EXESUF)
fate-tree: CMD = run libavutil/tests/tree$(EXESUF)

73
tests/ref/fate/stereo3d Normal file
View File

@@ -0,0 +1,73 @@
Testing av_stereo3d_alloc_size()
alloc_size: OK, size>0: yes
alloc: OK
Testing av_stereo3d_create_side_data()
create_side_data: OK
Testing av_stereo3d_type_name()
type 0: 2D
type 1: side by side
type 2: top and bottom
type 3: frame alternate
type 4: checkerboard
type 5: side by side (quincunx subsampling)
type 6: interleaved lines
type 7: interleaved columns
type 8: unspecified
out of range: unknown
Testing av_stereo3d_from_name()
2D: 0
side by side: 1
top and bottom: 2
frame alternate: 3
checkerboard: 4
side by side (quincunx subsampling): 1
interleaved lines: 6
interleaved columns: 7
unspecified: 8
nonexistent: -1
Testing type name round-trip
type roundtrip 0 (2D): OK
type roundtrip 1 (side by side): OK
type roundtrip 2 (top and bottom): OK
type roundtrip 3 (frame alternate): OK
type roundtrip 4 (checkerboard): OK
type roundtrip 5 (side by side (quincunx subsampling)): FAIL
type roundtrip 6 (interleaved lines): OK
type roundtrip 7 (interleaved columns): OK
type roundtrip 8 (unspecified): OK
Testing av_stereo3d_view_name()
view 0: packed
view 1: left
view 2: right
view 3: unspecified
out of range: unknown
Testing view name round-trip
view roundtrip 0 (packed): OK
view roundtrip 1 (left): OK
view roundtrip 2 (right): OK
view roundtrip 3 (unspecified): OK
Testing av_stereo3d_view_from_name()
packed: 0
left: 1
right: 2
unspecified: 3
nonexistent: -1
Testing av_stereo3d_primary_eye_name()
eye 0: none
eye 1: left
eye 2: right
out of range: unknown
Testing av_stereo3d_primary_eye_from_name()
none: 0
left: 1
right: 2
nonexistent: 0