@@ -1484,6 +1484,7 @@ erase_attribute(cspan<const char*> argv)
1484
1484
1485
1485
1486
1486
1487
+ #if 0 /* apparently unused */
1487
1488
bool
1488
1489
Oiiotool::get_position(string_view command, string_view geom, int& x, int& y)
1489
1490
{
@@ -1494,6 +1495,7 @@ Oiiotool::get_position(string_view command, string_view geom, int& x, int& y)
1494
1495
errorfmt(command, "Unrecognized position \"{}\"", orig_geom);
1495
1496
return ok;
1496
1497
}
1498
+ #endif
1497
1499
1498
1500
1499
1501
@@ -1577,6 +1579,57 @@ Oiiotool::adjust_geometry(string_view command, int& w, int& h, int& x, int& y,
1577
1579
return true ;
1578
1580
}
1579
1581
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
+
1580
1633
1581
1634
1582
1635
void
@@ -6066,6 +6119,7 @@ oiiotool_unit_tests()
6066
6119
using Strutil::print;
6067
6120
print (" Running unit tests...\n " );
6068
6121
unit_test_scan_box ();
6122
+ unit_test_adjust_geometry ();
6069
6123
print (" ...end of unit tests\n " );
6070
6124
#endif
6071
6125
}
0 commit comments