Skip to content

Commit 6aab697

Browse files
committed
Analysis: Add tests to improve code coverage of oiiotool (AcademySoftwareFoundation#3637)
* Unit test adjust_geometry * Tests of --set for various implicit and explicit types not previously covered in the testsuite * Comment out Oiiotool:get_position, which seems to be unused * Exercise --iconfig for explicit types * Add test for --origin and --originoffset * Add test for --ociodisplay * Add test for --unmip and --selectmip
1 parent c7c2830 commit 6aab697

File tree

17 files changed

+155
-2
lines changed

17 files changed

+155
-2
lines changed

src/oiiotool/oiiotool.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,6 +1484,7 @@ erase_attribute(cspan<const char*> argv)
14841484

14851485

14861486

1487+
#if 0 /* apparently unused */
14871488
bool
14881489
Oiiotool::get_position(string_view command, string_view geom, int& x, int& y)
14891490
{
@@ -1494,6 +1495,7 @@ Oiiotool::get_position(string_view command, string_view geom, int& x, int& y)
14941495
errorfmt(command, "Unrecognized position \"{}\"", orig_geom);
14951496
return ok;
14961497
}
1498+
#endif
14971499

14981500

14991501

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

1582+
#ifdef OIIO_UNIT_TESTS
1583+
static void
1584+
unit_test_adjust_geometry()
1585+
{
1586+
int w, h, x, y;
1587+
w = h = x = y = -42;
1588+
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10,20,130,145")
1589+
&& x == 10 && y == 20 && w == 121 && h == 126);
1590+
w = h = x = y = -42;
1591+
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20+100+200")
1592+
&& x == 100 && y == 200 && w == 10 && h == 20);
1593+
w = h = x = y = -42;
1594+
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20-100-200")
1595+
&& x == -100 && y == -200 && w == 10 && h == 20);
1596+
w = h = x = y = -42;
1597+
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20") && x == -42
1598+
&& y == -42 && w == 10 && h == 20);
1599+
w = h = 100;
1600+
x = y = -42;
1601+
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "200%x50%", true)
1602+
&& x == -42 && y == -42 && w == 200 && h == 50);
1603+
w = h = 100;
1604+
x = y = -42;
1605+
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%x50%"));
1606+
w = 640;
1607+
h = 480;
1608+
x = y = -42;
1609+
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "200%", true) && x == -42
1610+
&& y == -42 && w == 1280 && h == 960);
1611+
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%"));
1612+
w = h = x = y = -42;
1613+
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "+100+200") && x == 100
1614+
&& y == 200 && w == -42 && h == -42);
1615+
w = 640;
1616+
h = 480;
1617+
x = y = -42;
1618+
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "2", true) && x == -42
1619+
&& y == -42 && w == 1280 && h == 960);
1620+
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "2"));
1621+
w = 640;
1622+
h = 480;
1623+
x = y = -42;
1624+
OIIO_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "0.5", true) && x == -42
1625+
&& y == -42 && w == 320 && h == 240);
1626+
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "0.5"));
1627+
w = h = x = y = -42;
1628+
OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "invalid") && x == -42
1629+
&& y == -42 && w == -42 && h == -42);
1630+
}
1631+
#endif
1632+
15801633

15811634

15821635
void
@@ -6066,6 +6119,7 @@ oiiotool_unit_tests()
60666119
using Strutil::print;
60676120
print("Running unit tests...\n");
60686121
unit_test_scan_box();
6122+
unit_test_adjust_geometry();
60696123
print("...end of unit tests\n");
60706124
#endif
60716125
}

src/oiiotool/oiiotool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class Oiiotool {
283283
}
284284

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

288288
// Modify the resolution and/or offset according to what's in geom.
289289
// Valid geometries are WxH (resolution), +X+Y (offsets), WxH+X+Y

testsuite/oiiotool-attribs/ref/out-jpeg9d.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ noattribs.jpg : 2048 x 1536, 3 channel, uint8 jpeg
5656
initial keywords=
5757
after adding, keywords=foo; bar
5858
after clearing, keywords=
59+
after --origin, 64x64+10+20
60+
after --originoffset, 64x64+110+220
5961
Reading attrib2.exr
6062
attrib2.exr : 64 x 64, 3 channel, half openexr
6163
2 subimages: 64x64 [h,h,h], 64x64 [h,h,h]

testsuite/oiiotool-attribs/ref/out.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ noattribs.jpg : 2048 x 1536, 3 channel, uint8 jpeg
5656
initial keywords=
5757
after adding, keywords=foo; bar
5858
after clearing, keywords=
59+
after --origin, 64x64+10+20
60+
after --originoffset, 64x64+110+220
5961
Reading attrib2.exr
6062
attrib2.exr : 64 x 64, 3 channel, half openexr
6163
2 subimages: 64x64 [h,h,h], 64x64 [h,h,h]

testsuite/oiiotool-attribs/run.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"--clear-keywords " +
2626
"--echo \"after clearing, keywords={TOP[keywords]}\" ")
2727

28+
# Test --origin and --originoffset
29+
command += oiiotool ('--create 64x64 3 --origin +10+20 ' +
30+
'--echo "after --origin, {TOP.geom}" ' +
31+
'--originoffset +100+200 ' +
32+
'--echo "after --originoffset, {TOP.geom}"')
33+
2834
# Test adding and erasing attribs to multiple subimages
2935
command += oiiotool ("--create 64x64 3 -dup --siappend " +
3036
"--attrib:allsubimages=1 foo bar -d half -o attrib2.exr")
6.08 KB
Binary file not shown.

testsuite/oiiotool-color/ref/out-ocio1.1.0.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Comparing "contrast-threshold.tif" and "ref/contrast-threshold.tif"
2222
PASS
2323
Comparing "contrast-sigmoid5.tif" and "ref/contrast-sigmoid5.tif"
2424
PASS
25+
Comparing "display-sRGB.tif" and "ref/display-sRGB.tif"
26+
PASS
2527
Comparing "rgbfromtga.png" and "ref/rgbfromtga.png"
2628
PASS
2729
Comparing "greyalpha_sRGB.tif" and "ref/greyalpha_sRGB.tif"

testsuite/oiiotool-color/ref/out-ocio1.1.0b.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Comparing "contrast-threshold.tif" and "ref/contrast-threshold.tif"
2222
PASS
2323
Comparing "contrast-sigmoid5.tif" and "ref/contrast-sigmoid5.tif"
2424
PASS
25+
Comparing "display-sRGB.tif" and "ref/display-sRGB.tif"
26+
PASS
2527
Comparing "rgbfromtga.png" and "ref/rgbfromtga.png"
2628
PASS
2729
Comparing "greyalpha_sRGB.tif" and "ref/greyalpha_sRGB.tif"

testsuite/oiiotool-color/ref/out.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Comparing "contrast-threshold.tif" and "ref/contrast-threshold.tif"
2020
PASS
2121
Comparing "contrast-sigmoid5.tif" and "ref/contrast-sigmoid5.tif"
2222
PASS
23+
Comparing "display-sRGB.tif" and "ref/display-sRGB.tif"
24+
PASS
2325
Comparing "rgbfromtga.png" and "ref/rgbfromtga.png"
2426
PASS
2527
Comparing "greyalpha_sRGB.tif" and "ref/greyalpha_sRGB.tif"

testsuite/oiiotool-color/run.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
+ "--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 "
6868
+ "-d uint8 -o tahoe-ccmatrix.tif")
6969

70+
# Apply a display
71+
command += oiiotool ("greyalpha_linear.tif --ociodisplay default sRGB -o display-sRGB.tif")
72+
73+
# TODO: should test applying a look
74+
# TODO: should test applying a file transform
75+
7076
# test various behaviors and misbehaviors related to OCIO configs.
7177
command += oiiotool ("--nostderr --colorconfig missing.ocio -echo 'Nonexistent config'", failureok=True)
7278

@@ -90,6 +96,7 @@
9096
"contrast-inverse.tif",
9197
"contrast-threshold.tif",
9298
"contrast-sigmoid5.tif",
99+
"display-sRGB.tif",
93100
"rgbfromtga.png",
94101
"greyalpha_sRGB.tif",
95102
"greyalpha_Cineon.tif",

testsuite/oiiotool-control/ref/out.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Testing --set, expr i:
5454
Testing --set, expr var(i):
5555
i = 1
5656
now i = 42
57+
Testing --set of implied types:
58+
i = 42, f = 3.5, s = hello world
59+
Testing --set of various explicit types:
60+
i = 42, f = 3.5, s = hello world, tc = 01:02:03:04, rat = 1/2
5761
Expr getattribute(limits:channels) = 1024
5862
Testing if with true cond (expect output):
5963
inside if clause, i=42

testsuite/oiiotool-control/run.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@
7171
# Test user variables
7272
command += oiiotool ('-echo "Testing --set, expr i:" -set i 1 -echo " i = {i}" -set i "{i+41}" -echo " now i = {i}"')
7373
command += oiiotool ('-echo "Testing --set, expr var(i):" -set i 1 -echo " i = {var(i)}" -set i "{i+41}" -echo " now i = {var(i)}"')
74+
command += oiiotool ('-echo "Testing --set of implied types:" ' +
75+
'-set i 42 -set f 3.5 ' +
76+
'-set s "hello world" ' +
77+
'-echo " i = {i}, f = {f}, s = {s}"')
78+
command += oiiotool ('-echo "Testing --set of various explicit types:" ' +
79+
'-set:type=int i 42 -set:type=float f 3.5 ' +
80+
'-set:type=string s "hello world" ' +
81+
'-set:type=timecode tc 01:02:03:04 ' +
82+
'-set:type=rational rat 1/2 ' +
83+
'-echo " i = {i}, f = {f}, s = {s}, tc = {tc}, rat = {rat}"')
7484

7585
# Test getattribute in an expression
7686
command += oiiotool ('-echo "Expr getattribute(\"limits:channels\") = {getattribute(\"limits:channels\")}"')
6.04 KB
Binary file not shown.

testsuite/oiiotool-subimage/ref/out-oldfreetype.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ gpgr.exr : 64 x 64, 3 channel, half openexr
5353
oiio:subimagename: "layerD"
5454
oiio:subimages: 4
5555
openexr:chunkCount: 4
56+
Reading mip4.tif
57+
mip4.tif : 64 x 64, 4 channel, uint8 tiff
58+
SHA-1: 36CE573A20E682720B020FC689E2067579DE5B37
59+
channel list: R, G, B, A
60+
tile size: 64 x 64
61+
compression: "zip"
62+
DocumentName: "g.tif"
63+
fovcot: 1
64+
Orientation: 1 (normal)
65+
PixelAspectRatio: 1
66+
planarconfig: "contig"
67+
ResolutionUnit: "in"
68+
wrapmodes: "black,black"
69+
XResolution: 72
70+
YResolution: 72
71+
oiio:BitsPerSample: 8
72+
tiff:Compression: 8
73+
tiff:PhotometricInterpretation: 2
74+
tiff:PlanarConfiguration: 1
75+
../common/textures/grid.tx : 1024 x 1024, 4 channel, uint8 tiff (+mipmap)
76+
SHA-1: 7DB3F1E464C5F38CAAECE8ABC8684EC66FC9FA68
77+
unmip.tif : 1024 x 1024, 4 channel, uint8 tiff
78+
SHA-1: 7DB3F1E464C5F38CAAECE8ABC8684EC66FC9FA68
5679
Comparing "subimages-2.exr" and "ref/subimages-2.exr"
5780
PASS
5881
Comparing "subimages-4.exr" and "ref/subimages-4-freetype2.7.exr"
@@ -65,3 +88,5 @@ Comparing "subimageD3.exr" and "ref/subimageD3-freetype2.7.exr"
6588
PASS
6689
Comparing "subimageB1.exr" and "ref/subimageB1-freetype2.7.exr"
6790
PASS
91+
Comparing "mip4.tif" and "ref/mip4.tif"
92+
PASS

testsuite/oiiotool-subimage/ref/out.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,29 @@ gpgr.exr : 64 x 64, 3 channel, half openexr
5353
oiio:subimagename: "layerD"
5454
oiio:subimages: 4
5555
openexr:chunkCount: 4
56+
Reading mip4.tif
57+
mip4.tif : 64 x 64, 4 channel, uint8 tiff
58+
SHA-1: 36CE573A20E682720B020FC689E2067579DE5B37
59+
channel list: R, G, B, A
60+
tile size: 64 x 64
61+
compression: "zip"
62+
DocumentName: "g.tif"
63+
fovcot: 1
64+
Orientation: 1 (normal)
65+
PixelAspectRatio: 1
66+
planarconfig: "contig"
67+
ResolutionUnit: "in"
68+
wrapmodes: "black,black"
69+
XResolution: 72
70+
YResolution: 72
71+
oiio:BitsPerSample: 8
72+
tiff:Compression: 8
73+
tiff:PhotometricInterpretation: 2
74+
tiff:PlanarConfiguration: 1
75+
../common/textures/grid.tx : 1024 x 1024, 4 channel, uint8 tiff (+mipmap)
76+
SHA-1: 7DB3F1E464C5F38CAAECE8ABC8684EC66FC9FA68
77+
unmip.tif : 1024 x 1024, 4 channel, uint8 tiff
78+
SHA-1: 7DB3F1E464C5F38CAAECE8ABC8684EC66FC9FA68
5679
Comparing "subimages-2.exr" and "ref/subimages-2.exr"
5780
PASS
5881
Comparing "subimages-4.exr" and "ref/subimages-4.exr"
@@ -65,3 +88,5 @@ Comparing "subimageD3.exr" and "ref/subimageD3.exr"
6588
PASS
6689
Comparing "subimageB1.exr" and "ref/subimageB1.exr"
6790
PASS
91+
Comparing "mip4.tif" and "ref/mip4.tif"
92+
PASS

testsuite/oiiotool-subimage/run.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,19 @@
2121
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")
2222
command += info_command ("-a -v gpgr.exr", safematch=1)
2323

24+
# Test extraction of MIP levels
25+
command += oiiotool ("../common/textures/grid.tx --selectmip 4 -o mip4.tif")
26+
command += info_command ("mip4.tif", safematch=True)
27+
command += oiiotool ("../common/textures/grid.tx --unmip -o unmip.tif")
28+
command += info_command ("../common/textures/grid.tx", verbose=False)
29+
command += info_command ("unmip.tif", verbose=False)
30+
2431
# Outputs to check against references
2532
outputs = [
2633
"subimages-2.exr", "subimages-4.exr",
2734
"subimage1.exr", "subimage2.exr",
2835
"subimageD3.exr", "subimageB1.exr",
36+
"mip4.tif",
2937
"out.txt"
3038
]
3139

testsuite/oiiotool/run.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@
214214
command += oiiotool ("../common/tahoe-tiny.tif --printstats:window=10x10+50+50 --echo \" \"")
215215

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

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

0 commit comments

Comments
 (0)