Skip to content

Commit 53d2e5d

Browse files
authored
Analysis: Add tests to improve code coverage of oiiotool (#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 af4b6f1 commit 53d2e5d

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",

0 commit comments

Comments
 (0)