|
37 | 37 | #include <OpenImageIO/sysutil.h>
|
38 | 38 | #include <OpenImageIO/timer.h>
|
39 | 39 |
|
| 40 | +#ifndef NDEBUG |
| 41 | +# define OIIO_UNIT_TEST_QUIET_SUCCESS |
| 42 | +# include <OpenImageIO/unittest.h> |
| 43 | +#endif |
| 44 | + |
40 | 45 | using namespace OIIO;
|
41 | 46 | using namespace OiioTool;
|
42 | 47 | using namespace ImageBufAlgo;
|
@@ -276,10 +281,10 @@ unit_test_scan_box()
|
276 | 281 | {
|
277 | 282 | Strutil::print("unit test scan_box...\n");
|
278 | 283 | int xmin = -1, ymin = -1, xmax = -1, ymax = -1;
|
279 |
| - OIIO_ASSERT(scan_box("11,12,13,14", xmin, ymin, xmax, ymax) && xmin == 11 |
280 |
| - && ymin == 12 && xmax == 13 && ymax == 14); |
281 |
| - OIIO_ASSERT(scan_box("1,2,3", xmin, ymin, xmax, ymax) == false); |
282 |
| - OIIO_ASSERT(scan_box("1,2,3,4,5", xmin, ymin, xmax, ymax) == false); |
| 284 | + OIIO_CHECK_ASSERT(scan_box("11,12,13,14", xmin, ymin, xmax, ymax) |
| 285 | + && xmin == 11 && ymin == 12 && xmax == 13 && ymax == 14); |
| 286 | + OIIO_CHECK_ASSERT(scan_box("1,2,3", xmin, ymin, xmax, ymax) == false); |
| 287 | + OIIO_CHECK_ASSERT(scan_box("1,2,3,4,5", xmin, ymin, xmax, ymax) == false); |
283 | 288 | }
|
284 | 289 | #endif
|
285 | 290 |
|
@@ -493,8 +498,10 @@ Oiiotool::error(string_view command, string_view explanation) const
|
493 | 498 | // Repeat the command line, so if oiiotool is being called from a
|
494 | 499 | // script, it's easy to debug how the command was mangled.
|
495 | 500 | errstream << "Full command line was:\n> " << full_command_line << "\n";
|
496 |
| - ot.ap.abort(); // Cease further processing of the command line |
497 |
| - ot.return_value = EXIT_FAILURE; |
| 501 | + if (!ot.noerrexit) { |
| 502 | + ot.ap.abort(); // Cease further processing of the command line |
| 503 | + ot.return_value = EXIT_FAILURE; |
| 504 | + } |
498 | 505 | }
|
499 | 506 |
|
500 | 507 |
|
@@ -1583,50 +1590,79 @@ Oiiotool::adjust_geometry(string_view command, int& w, int& h, int& x, int& y,
|
1583 | 1590 | static void
|
1584 | 1591 | unit_test_adjust_geometry()
|
1585 | 1592 | {
|
| 1593 | + // box |
1586 | 1594 | int w, h, x, y;
|
1587 | 1595 | 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); |
| 1596 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10,20,130,145") |
| 1597 | + && x == 10 && y == 20 && w == 121 && h == 126); |
| 1598 | + |
| 1599 | + // geom |
1590 | 1600 | 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); |
| 1601 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20+100+200") |
| 1602 | + && x == 100 && y == 200 && w == 10 && h == 20); |
1593 | 1603 | 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); |
| 1604 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20-100-200") |
| 1605 | + && x == -100 && y == -200 && w == 10 && h == 20); |
| 1606 | + w = 100, h = 50, x = y = 0; |
| 1607 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "20x0+100+200") |
| 1608 | + && x == 100 && y == 200 && w == 20 && h == 10); |
| 1609 | + w = 100, h = 50, x = y = 0; |
| 1610 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "0x20+100+200") |
| 1611 | + && x == 100 && y == 200 && w == 40 && h == 20); |
| 1612 | + OIIO_CHECK_ASSERT( |
| 1613 | + !ot.adjust_geometry("foo", w, h, x, y, "10x20+100+200", true, false)); |
| 1614 | + |
| 1615 | + // res |
1596 | 1616 | 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); |
| 1617 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "10x20") && x == -42 |
| 1618 | + && y == -42 && w == 10 && h == 20); |
| 1619 | + w = 100, h = 50, x = y = 0; |
| 1620 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "20x0") && x == 0 |
| 1621 | + && y == 0 && w == 20 && h == 10); |
| 1622 | + w = 100, h = 50, x = y = 0; |
| 1623 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "0x20") && x == 0 |
| 1624 | + && y == 0 && w == 40 && h == 20); |
| 1625 | + OIIO_CHECK_ASSERT( |
| 1626 | + !ot.adjust_geometry("foo", w, h, x, y, "10x20", true, false)); |
| 1627 | + |
| 1628 | + // scale by percentage |
1599 | 1629 | w = h = 100;
|
1600 | 1630 | 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); |
| 1631 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "200%x50%", true) |
| 1632 | + && x == -42 && y == -42 && w == 200 && h == 50); |
1603 | 1633 | w = h = 100;
|
1604 | 1634 | x = y = -42;
|
1605 |
| - OIIO_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%x50%")); |
| 1635 | + OIIO_CHECK_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%x50%")); |
1606 | 1636 | w = 640;
|
1607 | 1637 | h = 480;
|
1608 | 1638 | 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%")); |
| 1639 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "200%", true) |
| 1640 | + && x == -42 && y == -42 && w == 1280 && h == 960); |
| 1641 | + OIIO_CHECK_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "200%")); |
| 1642 | + |
| 1643 | + // offset |
1612 | 1644 | 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); |
| 1645 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "+100+200") |
| 1646 | + && x == 100 && y == 200 && w == -42 && h == -42); |
| 1647 | + |
| 1648 | + // scale by factor |
1615 | 1649 | w = 640;
|
1616 | 1650 | h = 480;
|
1617 | 1651 | 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")); |
| 1652 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "2", true) |
| 1653 | + && x == -42 && y == -42 && w == 1280 && h == 960); |
| 1654 | + OIIO_CHECK_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "2")); |
1621 | 1655 | w = 640;
|
1622 | 1656 | h = 480;
|
1623 | 1657 | 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")); |
| 1658 | + OIIO_CHECK_ASSERT(ot.adjust_geometry("foo", w, h, x, y, "0.5", true) |
| 1659 | + && x == -42 && y == -42 && w == 320 && h == 240); |
| 1660 | + OIIO_CHECK_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "0.5")); |
| 1661 | + |
| 1662 | + // errors |
1627 | 1663 | 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); |
| 1664 | + OIIO_CHECK_ASSERT(!ot.adjust_geometry("foo", w, h, x, y, "invalid") |
| 1665 | + && x == -42 && y == -42 && w == -42 && h == -42); |
1630 | 1666 | }
|
1631 | 1667 | #endif
|
1632 | 1668 |
|
@@ -6127,8 +6163,11 @@ oiiotool_unit_tests()
|
6127 | 6163 | #ifdef OIIO_UNIT_TESTS
|
6128 | 6164 | using Strutil::print;
|
6129 | 6165 | print("Running unit tests...\n");
|
| 6166 | + auto e = ot.noerrexit; |
| 6167 | + ot.noerrexit = true; |
6130 | 6168 | unit_test_scan_box();
|
6131 | 6169 | unit_test_adjust_geometry();
|
| 6170 | + ot.noerrexit = e; |
6132 | 6171 | print("...end of unit tests\n");
|
6133 | 6172 | #endif
|
6134 | 6173 | }
|
@@ -6178,6 +6217,8 @@ Oiiotool::getargs(int argc, char* argv[])
|
6178 | 6217 | .help("Quiet mode (turn verbose off)");
|
6179 | 6218 | ap.arg("-n", &ot.dryrun)
|
6180 | 6219 | .help("No saved output (dry run)");
|
| 6220 | + ap.arg("--no-error-exit", ot.noerrexit) |
| 6221 | + .help("Do not exit upon error, try to process additional comands (danger!)"); |
6181 | 6222 | ap.arg("-a", &ot.allsubimages)
|
6182 | 6223 | .help("Do operations on all subimages/miplevels");
|
6183 | 6224 | ap.arg("--debug", &ot.debug)
|
|
0 commit comments