Skip to content

Analysis: Add tests to improve code coverage of oiiotool #3637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/oiiotool/oiiotool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,7 @@ erase_attribute(cspan<const char*> argv)



#if 0 /* apparently unused */
bool
Oiiotool::get_position(string_view command, string_view geom, int& x, int& y)
{
Expand All @@ -1494,6 +1495,7 @@ Oiiotool::get_position(string_view command, string_view geom, int& x, int& y)
errorfmt(command, "Unrecognized position \"{}\"", orig_geom);
return ok;
}
#endif



Expand Down Expand Up @@ -1577,6 +1579,57 @@ Oiiotool::adjust_geometry(string_view command, int& w, int& h, int& x, int& y,
return true;
}

#ifdef OIIO_UNIT_TESTS
static void
unit_test_adjust_geometry()
{
int w, h, x, y;
w = h = x = y = -42;
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10,20,130,145")
&& x == 10 && y == 20 && w == 121 && h == 126);
w = h = x = y = -42;
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20+100+200")
&& x == 100 && y == 200 && w == 10 && h == 20);
w = h = x = y = -42;
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20-100-200")
&& x == -100 && y == -200 && w == 10 && h == 20);
w = h = x = y = -42;
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20") && x == -42
&& y == -42 && w == 10 && h == 20);
w = h = 100;
x = y = -42;
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "200%x50%", true)
&& x == -42 && y == -42 && w == 200 && h == 50);
w = h = 100;
x = y = -42;
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%x50%"));
w = 640;
h = 480;
x = y = -42;
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "200%", true) && x == -42
&& y == -42 && w == 1280 && h == 960);
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%"));
w = h = x = y = -42;
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "+100+200") && x == 100
&& y == 200 && w == -42 && h == -42);
w = 640;
h = 480;
x = y = -42;
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "2", true) && x == -42
&& y == -42 && w == 1280 && h == 960);
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "2"));
w = 640;
h = 480;
x = y = -42;
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "0.5", true) && x == -42
&& y == -42 && w == 320 && h == 240);
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "0.5"));
w = h = x = y = -42;
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "invalid") && x == -42
&& y == -42 && w == -42 && h == -42);
}
#endif



void
Expand Down Expand Up @@ -6066,6 +6119,7 @@ oiiotool_unit_tests()
using Strutil::print;
print("Running unit tests...\n");
unit_test_scan_box();
unit_test_adjust_geometry();
print("...end of unit tests\n");
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/oiiotool/oiiotool.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class Oiiotool {
}

// Parse geom in the form of "x,y" to retrieve a 2D integer position.
bool get_position(string_view command, string_view geom, int& x, int& y);
// bool get_position(string_view command, string_view geom, int& x, int& y);

// Modify the resolution and/or offset according to what's in geom.
// Valid geometries are WxH (resolution), +X+Y (offsets), WxH+X+Y
Expand Down
2 changes: 2 additions & 0 deletions testsuite/oiiotool-attribs/ref/out-jpeg9d.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ noattribs.jpg : 2048 x 1536, 3 channel, uint8 jpeg
initial keywords=
after adding, keywords=foo; bar
after clearing, keywords=
after --origin, 64x64+10+20
after --originoffset, 64x64+110+220
Reading attrib2.exr
attrib2.exr : 64 x 64, 3 channel, half openexr
2 subimages: 64x64 [h,h,h], 64x64 [h,h,h]
Expand Down
2 changes: 2 additions & 0 deletions testsuite/oiiotool-attribs/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ noattribs.jpg : 2048 x 1536, 3 channel, uint8 jpeg
initial keywords=
after adding, keywords=foo; bar
after clearing, keywords=
after --origin, 64x64+10+20
after --originoffset, 64x64+110+220
Reading attrib2.exr
attrib2.exr : 64 x 64, 3 channel, half openexr
2 subimages: 64x64 [h,h,h], 64x64 [h,h,h]
Expand Down
6 changes: 6 additions & 0 deletions testsuite/oiiotool-attribs/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"--clear-keywords " +
"--echo \"after clearing, keywords={TOP[keywords]}\" ")

# Test --origin and --originoffset
command += oiiotool ('--create 64x64 3 --origin +10+20 ' +
'--echo "after --origin, {TOP.geom}" ' +
'--originoffset +100+200 ' +
'--echo "after --originoffset, {TOP.geom}"')

# Test adding and erasing attribs to multiple subimages
command += oiiotool ("--create 64x64 3 -dup --siappend " +
"--attrib:allsubimages=1 foo bar -d half -o attrib2.exr")
Expand Down
Binary file added testsuite/oiiotool-color/ref/display-sRGB.tif
Binary file not shown.
2 changes: 2 additions & 0 deletions testsuite/oiiotool-color/ref/out-ocio1.1.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Comparing "contrast-threshold.tif" and "ref/contrast-threshold.tif"
PASS
Comparing "contrast-sigmoid5.tif" and "ref/contrast-sigmoid5.tif"
PASS
Comparing "display-sRGB.tif" and "ref/display-sRGB.tif"
PASS
Comparing "rgbfromtga.png" and "ref/rgbfromtga.png"
PASS
Comparing "greyalpha_sRGB.tif" and "ref/greyalpha_sRGB.tif"
Expand Down
2 changes: 2 additions & 0 deletions testsuite/oiiotool-color/ref/out-ocio1.1.0b.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Comparing "contrast-threshold.tif" and "ref/contrast-threshold.tif"
PASS
Comparing "contrast-sigmoid5.tif" and "ref/contrast-sigmoid5.tif"
PASS
Comparing "display-sRGB.tif" and "ref/display-sRGB.tif"
PASS
Comparing "rgbfromtga.png" and "ref/rgbfromtga.png"
PASS
Comparing "greyalpha_sRGB.tif" and "ref/greyalpha_sRGB.tif"
Expand Down
2 changes: 2 additions & 0 deletions testsuite/oiiotool-color/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Comparing "contrast-threshold.tif" and "ref/contrast-threshold.tif"
PASS
Comparing "contrast-sigmoid5.tif" and "ref/contrast-sigmoid5.tif"
PASS
Comparing "display-sRGB.tif" and "ref/display-sRGB.tif"
PASS
Comparing "rgbfromtga.png" and "ref/rgbfromtga.png"
PASS
Comparing "greyalpha_sRGB.tif" and "ref/greyalpha_sRGB.tif"
Expand Down
7 changes: 7 additions & 0 deletions testsuite/oiiotool-color/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
+ "--ccmatrix 0.805,0.506,-0.311,0,-0.311,0.805,0.506,0,0.506,-0.311,0.805,0,0,0,0,1 "
+ "-d uint8 -o tahoe-ccmatrix.tif")

# Apply a display
command += oiiotool ("greyalpha_linear.tif --ociodisplay default sRGB -o display-sRGB.tif")

# TODO: should test applying a look
# TODO: should test applying a file transform

# test various behaviors and misbehaviors related to OCIO configs.
command += oiiotool ("--nostderr --colorconfig missing.ocio -echo 'Nonexistent config'", failureok=True)

Expand All @@ -90,6 +96,7 @@
"contrast-inverse.tif",
"contrast-threshold.tif",
"contrast-sigmoid5.tif",
"display-sRGB.tif",
"rgbfromtga.png",
"greyalpha_sRGB.tif",
"greyalpha_Cineon.tif",
Expand Down
4 changes: 4 additions & 0 deletions testsuite/oiiotool-control/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Testing --set, expr i:
Testing --set, expr var(i):
i = 1
now i = 42
Testing --set of implied types:
i = 42, f = 3.5, s = hello world
Testing --set of various explicit types:
i = 42, f = 3.5, s = hello world, tc = 01:02:03:04, rat = 1/2
Expr getattribute(limits:channels) = 1024
Testing if with true cond (expect output):
inside if clause, i=42
Expand Down
10 changes: 10 additions & 0 deletions testsuite/oiiotool-control/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
# Test user variables
command += oiiotool ('-echo "Testing --set, expr i:" -set i 1 -echo " i = {i}" -set i "{i+41}" -echo " now i = {i}"')
command += oiiotool ('-echo "Testing --set, expr var(i):" -set i 1 -echo " i = {var(i)}" -set i "{i+41}" -echo " now i = {var(i)}"')
command += oiiotool ('-echo "Testing --set of implied types:" ' +
'-set i 42 -set f 3.5 ' +
'-set s "hello world" ' +
'-echo " i = {i}, f = {f}, s = {s}"')
command += oiiotool ('-echo "Testing --set of various explicit types:" ' +
'-set:type=int i 42 -set:type=float f 3.5 ' +
'-set:type=string s "hello world" ' +
'-set:type=timecode tc 01:02:03:04 ' +
'-set:type=rational rat 1/2 ' +
'-echo " i = {i}, f = {f}, s = {s}, tc = {tc}, rat = {rat}"')

# Test getattribute in an expression
command += oiiotool ('-echo "Expr getattribute(\"limits:channels\") = {getattribute(\"limits:channels\")}"')
Expand Down
Binary file added testsuite/oiiotool-subimage/ref/mip4.tif
Binary file not shown.
25 changes: 25 additions & 0 deletions testsuite/oiiotool-subimage/ref/out-oldfreetype.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ gpgr.exr : 64 x 64, 3 channel, half openexr
oiio:subimagename: "layerD"
oiio:subimages: 4
openexr:chunkCount: 4
Reading mip4.tif
mip4.tif : 64 x 64, 4 channel, uint8 tiff
SHA-1: 36CE573A20E682720B020FC689E2067579DE5B37
channel list: R, G, B, A
tile size: 64 x 64
compression: "zip"
DocumentName: "g.tif"
fovcot: 1
Orientation: 1 (normal)
PixelAspectRatio: 1
planarconfig: "contig"
ResolutionUnit: "in"
wrapmodes: "black,black"
XResolution: 72
YResolution: 72
oiio:BitsPerSample: 8
tiff:Compression: 8
tiff:PhotometricInterpretation: 2
tiff:PlanarConfiguration: 1
../common/textures/grid.tx : 1024 x 1024, 4 channel, uint8 tiff (+mipmap)
SHA-1: 7DB3F1E464C5F38CAAECE8ABC8684EC66FC9FA68
unmip.tif : 1024 x 1024, 4 channel, uint8 tiff
SHA-1: 7DB3F1E464C5F38CAAECE8ABC8684EC66FC9FA68
Comparing "subimages-2.exr" and "ref/subimages-2.exr"
PASS
Comparing "subimages-4.exr" and "ref/subimages-4-freetype2.7.exr"
Expand All @@ -65,3 +88,5 @@ Comparing "subimageD3.exr" and "ref/subimageD3-freetype2.7.exr"
PASS
Comparing "subimageB1.exr" and "ref/subimageB1-freetype2.7.exr"
PASS
Comparing "mip4.tif" and "ref/mip4.tif"
PASS
25 changes: 25 additions & 0 deletions testsuite/oiiotool-subimage/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ gpgr.exr : 64 x 64, 3 channel, half openexr
oiio:subimagename: "layerD"
oiio:subimages: 4
openexr:chunkCount: 4
Reading mip4.tif
mip4.tif : 64 x 64, 4 channel, uint8 tiff
SHA-1: 36CE573A20E682720B020FC689E2067579DE5B37
channel list: R, G, B, A
tile size: 64 x 64
compression: "zip"
DocumentName: "g.tif"
fovcot: 1
Orientation: 1 (normal)
PixelAspectRatio: 1
planarconfig: "contig"
ResolutionUnit: "in"
wrapmodes: "black,black"
XResolution: 72
YResolution: 72
oiio:BitsPerSample: 8
tiff:Compression: 8
tiff:PhotometricInterpretation: 2
tiff:PlanarConfiguration: 1
../common/textures/grid.tx : 1024 x 1024, 4 channel, uint8 tiff (+mipmap)
SHA-1: 7DB3F1E464C5F38CAAECE8ABC8684EC66FC9FA68
unmip.tif : 1024 x 1024, 4 channel, uint8 tiff
SHA-1: 7DB3F1E464C5F38CAAECE8ABC8684EC66FC9FA68
Comparing "subimages-2.exr" and "ref/subimages-2.exr"
PASS
Comparing "subimages-4.exr" and "ref/subimages-4.exr"
Expand All @@ -65,3 +88,5 @@ Comparing "subimageD3.exr" and "ref/subimageD3.exr"
PASS
Comparing "subimageB1.exr" and "ref/subimageB1.exr"
PASS
Comparing "mip4.tif" and "ref/mip4.tif"
PASS
8 changes: 8 additions & 0 deletions testsuite/oiiotool-subimage/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,19 @@
command += oiiotool ("subimages-4.exr --attrib:subimages=0 Beatle John --attrib:subimages=1 Beatle Paul --attrib:subimages=2 Beatle George --attrib:subimages=3 Beatle Ringo -o gpgr.exr")
command += info_command ("-a -v gpgr.exr", safematch=1)

# Test extraction of MIP levels
command += oiiotool ("../common/textures/grid.tx --selectmip 4 -o mip4.tif")
command += info_command ("mip4.tif", safematch=True)
command += oiiotool ("../common/textures/grid.tx --unmip -o unmip.tif")
command += info_command ("../common/textures/grid.tx", verbose=False)
command += info_command ("unmip.tif", verbose=False)

# Outputs to check against references
outputs = [
"subimages-2.exr", "subimages-4.exr",
"subimage1.exr", "subimage2.exr",
"subimageD3.exr", "subimageB1.exr",
"mip4.tif",
"out.txt"
]

Expand Down
6 changes: 5 additions & 1 deletion testsuite/oiiotool/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@
command += oiiotool ("../common/tahoe-tiny.tif --printstats:window=10x10+50+50 --echo \" \"")

# test --iconfig
command += oiiotool ("--info -v -metamatch Debug --iconfig oiio:DebugOpenConfig! 1 black.tif")
command += oiiotool ("--info -v -metamatch Debug --iconfig oiio:DebugOpenConfig! 1 " +
"--iconfig:type=float oiio:DebugOpenConfigInt! 2 " +
"--iconfig:type=float oiio:DebugOpenConfigFloat! 3 " +
"--iconfig:type=string oiio:DebugOpenConfigStr! 4 " +
"black.tif")

# test -i:ch=...
command += oiiotool ("--pattern fill:color=.6,.5,.4,.3,.2 64x64 5 -d uint8 -o const5.tif")
Expand Down