File size: 78,447 Bytes
23d354c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 | #include <gtest/gtest.h>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <tcl.h>
#include "Fuzzy.hh"
#include "MinMax.hh"
#include "PatternMatch.hh"
#include "StringUtil.hh"
#include "RiseFallMinMax.hh"
#include "RiseFallValues.hh"
#include "Report.hh"
#include "ReportStd.hh"
#include "Error.hh"
#include "Debug.hh"
#include "Machine.hh"
#include "DispatchQueue.hh"
#include "Stats.hh"
#include "util/gzstream.hh"
namespace sta {
// fuzzyEqual tests
TEST(FuzzyTest, EqualValues)
{
EXPECT_TRUE(fuzzyEqual(1.0f, 1.0f));
EXPECT_TRUE(fuzzyEqual(0.0f, 0.0f));
EXPECT_TRUE(fuzzyEqual(-1.0f, -1.0f));
}
TEST(FuzzyTest, EqualSlightlyDifferent)
{
// Values that differ by a tiny amount should be fuzzy equal
float v = 1.0f;
float small = v + v * 1e-7f;
EXPECT_TRUE(fuzzyEqual(v, small));
}
TEST(FuzzyTest, EqualVeryDifferent)
{
EXPECT_FALSE(fuzzyEqual(1.0f, 2.0f));
EXPECT_FALSE(fuzzyEqual(0.0f, 1.0f));
EXPECT_FALSE(fuzzyEqual(-1.0f, 1.0f));
}
// fuzzyZero tests
TEST(FuzzyTest, ZeroExact)
{
EXPECT_TRUE(fuzzyZero(0.0f));
}
TEST(FuzzyTest, ZeroVerySmall)
{
EXPECT_TRUE(fuzzyZero(1e-20f));
EXPECT_TRUE(fuzzyZero(-1e-20f));
}
TEST(FuzzyTest, ZeroNonZero)
{
EXPECT_FALSE(fuzzyZero(1.0f));
EXPECT_FALSE(fuzzyZero(-1.0f));
}
// fuzzyLess tests
TEST(FuzzyTest, LessTrue)
{
EXPECT_TRUE(fuzzyLess(1.0f, 2.0f));
}
TEST(FuzzyTest, LessEqual)
{
EXPECT_FALSE(fuzzyLess(1.0f, 1.0f));
}
TEST(FuzzyTest, LessGreater)
{
EXPECT_FALSE(fuzzyLess(2.0f, 1.0f));
}
// fuzzyGreater tests
TEST(FuzzyTest, GreaterTrue)
{
EXPECT_TRUE(fuzzyGreater(2.0f, 1.0f));
}
TEST(FuzzyTest, GreaterEqual)
{
EXPECT_FALSE(fuzzyGreater(1.0f, 1.0f));
}
TEST(FuzzyTest, GreaterLess)
{
EXPECT_FALSE(fuzzyGreater(1.0f, 2.0f));
}
// fuzzyInf tests
// fuzzyInf checks against the STA INF constant (a large finite float),
// not IEEE infinity.
TEST(FuzzyTest, InfPositive)
{
EXPECT_TRUE(fuzzyInf(INF));
}
TEST(FuzzyTest, InfNegative)
{
EXPECT_TRUE(fuzzyInf(-INF));
}
TEST(FuzzyTest, InfNormal)
{
EXPECT_FALSE(fuzzyInf(1.0f));
EXPECT_FALSE(fuzzyInf(0.0f));
EXPECT_FALSE(fuzzyInf(-1.0f));
}
// patternMatch tests
TEST(PatternMatchTest, ExactMatch)
{
EXPECT_TRUE(patternMatch("hello", "hello"));
EXPECT_FALSE(patternMatch("hello", "world"));
}
TEST(PatternMatchTest, WildcardStar)
{
EXPECT_TRUE(patternMatch("hel*", "hello"));
EXPECT_TRUE(patternMatch("*llo", "hello"));
EXPECT_TRUE(patternMatch("*", "anything"));
EXPECT_TRUE(patternMatch("h*o", "hello"));
EXPECT_FALSE(patternMatch("h*x", "hello"));
}
TEST(PatternMatchTest, WildcardQuestion)
{
EXPECT_TRUE(patternMatch("hell?", "hello"));
EXPECT_TRUE(patternMatch("?ello", "hello"));
EXPECT_FALSE(patternMatch("hell?", "hell"));
}
TEST(PatternMatchTest, NoMatch)
{
EXPECT_FALSE(patternMatch("abc", "xyz"));
EXPECT_FALSE(patternMatch("abc?", "ab"));
}
// patternMatchNoCase tests
TEST(PatternMatchTest, NoCaseSensitive)
{
// nocase = false: case matters
EXPECT_TRUE(patternMatchNoCase("hello", "hello", false));
EXPECT_FALSE(patternMatchNoCase("Hello", "hello", false));
}
TEST(PatternMatchTest, NoCaseInsensitive)
{
// nocase = true: case ignored
EXPECT_TRUE(patternMatchNoCase("Hello", "hello", true));
EXPECT_TRUE(patternMatchNoCase("HELLO", "hello", true));
EXPECT_TRUE(patternMatchNoCase("H*O", "hello", true));
}
// patternWildcards tests
TEST(PatternMatchTest, HasWildcards)
{
EXPECT_TRUE(patternWildcards("hel*"));
EXPECT_TRUE(patternWildcards("hell?"));
EXPECT_TRUE(patternWildcards("*"));
}
TEST(PatternMatchTest, NoWildcards)
{
EXPECT_FALSE(patternWildcards("hello"));
EXPECT_FALSE(patternWildcards("simple"));
}
// stringEq tests
TEST(StringUtilTest, StringEqEqual)
{
EXPECT_TRUE(stringEq("hello", "hello"));
EXPECT_TRUE(stringEq("", ""));
}
TEST(StringUtilTest, StringEqNotEqual)
{
EXPECT_FALSE(stringEq("hello", "world"));
EXPECT_FALSE(stringEq("hello", "Hello"));
}
// isDigits tests
TEST(StringUtilTest, IsDigitsTrue)
{
EXPECT_TRUE(isDigits("12345"));
EXPECT_TRUE(isDigits("0"));
}
TEST(StringUtilTest, IsDigitsFalse)
{
EXPECT_FALSE(isDigits("abc"));
EXPECT_FALSE(isDigits("123abc"));
// Empty string returns true (no non-digit characters)
EXPECT_TRUE(isDigits(""));
}
// trimRight tests
TEST(StringUtilTest, TrimRightSpaces)
{
std::string s = "hello ";
trimRight(s);
EXPECT_EQ(s, "hello");
}
TEST(StringUtilTest, TrimRightNoSpaces)
{
std::string s = "hello";
trimRight(s);
EXPECT_EQ(s, "hello");
}
TEST(StringUtilTest, TrimRightAllSpaces)
{
std::string s = " ";
trimRight(s);
EXPECT_EQ(s, "");
}
TEST(StringUtilTest, TrimRightEmpty)
{
std::string s = "";
trimRight(s);
EXPECT_EQ(s, "");
}
////////////////////////////////////////////////////////////////
// RiseFallMinMax tests
////////////////////////////////////////////////////////////////
TEST(RiseFallMinMaxTest, DefaultConstructorIsEmpty)
{
RiseFallMinMax rfmm;
EXPECT_TRUE(rfmm.empty());
EXPECT_FALSE(rfmm.hasValue());
}
TEST(RiseFallMinMaxTest, InitValueConstructor)
{
RiseFallMinMax rfmm(5.0f);
EXPECT_FALSE(rfmm.empty());
EXPECT_TRUE(rfmm.hasValue());
EXPECT_TRUE(rfmm.hasValue(RiseFall::rise(), MinMax::min()));
EXPECT_TRUE(rfmm.hasValue(RiseFall::rise(), MinMax::max()));
EXPECT_TRUE(rfmm.hasValue(RiseFall::fall(), MinMax::min()));
EXPECT_TRUE(rfmm.hasValue(RiseFall::fall(), MinMax::max()));
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::rise(), MinMax::min()), 5.0f);
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::rise(), MinMax::max()), 5.0f);
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::fall(), MinMax::min()), 5.0f);
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::fall(), MinMax::max()), 5.0f);
}
TEST(RiseFallMinMaxTest, CopyConstructor)
{
RiseFallMinMax src(3.0f);
RiseFallMinMax copy(&src);
EXPECT_TRUE(copy.equal(&src));
EXPECT_FLOAT_EQ(copy.value(RiseFall::rise(), MinMax::min()), 3.0f);
}
TEST(RiseFallMinMaxTest, SetValueAll)
{
RiseFallMinMax rfmm;
rfmm.setValue(5.0f);
EXPECT_FALSE(rfmm.empty());
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::rise(), MinMax::min()), 5.0f);
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::fall(), MinMax::max()), 5.0f);
}
TEST(RiseFallMinMaxTest, SetValueRiseFallBothMinMaxAll)
{
RiseFallMinMax rfmm;
rfmm.setValue(RiseFallBoth::riseFall(), MinMaxAll::all(), 2.0f);
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::rise(), MinMax::min()), 2.0f);
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::fall(), MinMax::max()), 2.0f);
}
TEST(RiseFallMinMaxTest, SetValueRiseFallBothMinMax)
{
RiseFallMinMax rfmm;
rfmm.setValue(RiseFallBoth::rise(), MinMax::min(), 1.5f);
EXPECT_TRUE(rfmm.hasValue(RiseFall::rise(), MinMax::min()));
EXPECT_FALSE(rfmm.hasValue(RiseFall::rise(), MinMax::max()));
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::rise(), MinMax::min()), 1.5f);
}
TEST(RiseFallMinMaxTest, SetValueRiseFallMinMax)
{
RiseFallMinMax rfmm;
rfmm.setValue(RiseFall::fall(), MinMax::max(), 7.5f);
EXPECT_TRUE(rfmm.hasValue(RiseFall::fall(), MinMax::max()));
EXPECT_FALSE(rfmm.hasValue(RiseFall::rise(), MinMax::min()));
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::fall(), MinMax::max()), 7.5f);
}
TEST(RiseFallMinMaxTest, ValueWithExistsFlag)
{
RiseFallMinMax rfmm;
float val;
bool exists;
// Before setting, exists should be false
rfmm.value(RiseFall::rise(), MinMax::min(), val, exists);
EXPECT_FALSE(exists);
// After setting, exists should be true
rfmm.setValue(RiseFall::rise(), MinMax::min(), 4.0f);
rfmm.value(RiseFall::rise(), MinMax::min(), val, exists);
EXPECT_TRUE(exists);
EXPECT_FLOAT_EQ(val, 4.0f);
}
TEST(RiseFallMinMaxTest, ValueMinMaxOnly)
{
RiseFallMinMax rfmm;
rfmm.setValue(RiseFall::rise(), MinMax::min(), 2.0f);
rfmm.setValue(RiseFall::fall(), MinMax::min(), 4.0f);
// value(MinMax::min()) should return min of rise,fall for min
float v = rfmm.value(MinMax::min());
EXPECT_FLOAT_EQ(v, 2.0f); // min->compare returns true when value1 < value2
rfmm.setValue(RiseFall::rise(), MinMax::max(), 10.0f);
rfmm.setValue(RiseFall::fall(), MinMax::max(), 8.0f);
float v2 = rfmm.value(MinMax::max());
EXPECT_FLOAT_EQ(v2, 10.0f); // max->compare returns true when value1 > value2
}
TEST(RiseFallMinMaxTest, MaxValue)
{
RiseFallMinMax rfmm;
float max_val;
bool exists;
// Empty: no max
rfmm.maxValue(max_val, exists);
EXPECT_FALSE(exists);
// Set some values
rfmm.setValue(RiseFall::rise(), MinMax::min(), 3.0f);
rfmm.setValue(RiseFall::fall(), MinMax::max(), 7.0f);
rfmm.maxValue(max_val, exists);
EXPECT_TRUE(exists);
EXPECT_FLOAT_EQ(max_val, 7.0f);
}
TEST(RiseFallMinMaxTest, Clear)
{
RiseFallMinMax rfmm(10.0f);
EXPECT_FALSE(rfmm.empty());
rfmm.clear();
EXPECT_TRUE(rfmm.empty());
}
TEST(RiseFallMinMaxTest, SetValues)
{
RiseFallMinMax src(2.5f);
RiseFallMinMax dest;
dest.setValues(&src);
EXPECT_TRUE(dest.equal(&src));
}
TEST(RiseFallMinMaxTest, RemoveValueMinMax)
{
RiseFallMinMax rfmm(5.0f);
EXPECT_TRUE(rfmm.hasValue(RiseFall::rise(), MinMax::min()));
rfmm.removeValue(RiseFallBoth::rise(), MinMax::min());
EXPECT_FALSE(rfmm.hasValue(RiseFall::rise(), MinMax::min()));
EXPECT_TRUE(rfmm.hasValue(RiseFall::rise(), MinMax::max()));
}
TEST(RiseFallMinMaxTest, RemoveValueMinMaxAll)
{
RiseFallMinMax rfmm(5.0f);
rfmm.removeValue(RiseFallBoth::rise(), MinMaxAll::all());
EXPECT_FALSE(rfmm.hasValue(RiseFall::rise(), MinMax::min()));
EXPECT_FALSE(rfmm.hasValue(RiseFall::rise(), MinMax::max()));
EXPECT_TRUE(rfmm.hasValue(RiseFall::fall(), MinMax::min()));
}
TEST(RiseFallMinMaxTest, MergeValueRiseFallBothMinMaxAll)
{
RiseFallMinMax rfmm;
rfmm.setValue(RiseFall::rise(), MinMax::min(), 5.0f);
// Merge a smaller value for min -> should take the new value
rfmm.mergeValue(RiseFallBoth::rise(), MinMaxAll::min(), 3.0f);
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::rise(), MinMax::min()), 3.0f);
// Merge a larger value for min -> should keep the old value
rfmm.mergeValue(RiseFallBoth::rise(), MinMaxAll::min(), 8.0f);
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::rise(), MinMax::min()), 3.0f);
}
TEST(RiseFallMinMaxTest, MergeValueRiseFallMinMax)
{
RiseFallMinMax rfmm;
rfmm.setValue(RiseFall::rise(), MinMax::max(), 5.0f);
// Merge a larger value for max -> should take the new value
rfmm.mergeValue(RiseFall::rise(), MinMax::max(), 8.0f);
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::rise(), MinMax::max()), 8.0f);
// Merge a smaller value for max -> should keep old value
rfmm.mergeValue(RiseFall::rise(), MinMax::max(), 2.0f);
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::rise(), MinMax::max()), 8.0f);
}
TEST(RiseFallMinMaxTest, MergeValueIntoEmpty)
{
RiseFallMinMax rfmm;
// Merging into empty should set the value
rfmm.mergeValue(RiseFall::rise(), MinMax::min(), 4.0f);
EXPECT_TRUE(rfmm.hasValue(RiseFall::rise(), MinMax::min()));
EXPECT_FLOAT_EQ(rfmm.value(RiseFall::rise(), MinMax::min()), 4.0f);
}
TEST(RiseFallMinMaxTest, MergeWith)
{
RiseFallMinMax rfmm1;
rfmm1.setValue(RiseFall::rise(), MinMax::min(), 5.0f);
rfmm1.setValue(RiseFall::rise(), MinMax::max(), 10.0f);
RiseFallMinMax rfmm2;
rfmm2.setValue(RiseFall::rise(), MinMax::min(), 3.0f);
rfmm2.setValue(RiseFall::rise(), MinMax::max(), 12.0f);
rfmm2.setValue(RiseFall::fall(), MinMax::min(), 2.0f);
rfmm1.mergeWith(&rfmm2);
// min: take smaller (3.0)
EXPECT_FLOAT_EQ(rfmm1.value(RiseFall::rise(), MinMax::min()), 3.0f);
// max: take larger (12.0)
EXPECT_FLOAT_EQ(rfmm1.value(RiseFall::rise(), MinMax::max()), 12.0f);
// fall/min: was empty in rfmm1, so take from rfmm2
EXPECT_TRUE(rfmm1.hasValue(RiseFall::fall(), MinMax::min()));
EXPECT_FLOAT_EQ(rfmm1.value(RiseFall::fall(), MinMax::min()), 2.0f);
}
TEST(RiseFallMinMaxTest, MergeWithBothEmpty)
{
RiseFallMinMax rfmm1;
RiseFallMinMax rfmm2;
rfmm1.mergeWith(&rfmm2);
EXPECT_TRUE(rfmm1.empty());
}
TEST(RiseFallMinMaxTest, EqualSame)
{
RiseFallMinMax rfmm1(5.0f);
RiseFallMinMax rfmm2(5.0f);
EXPECT_TRUE(rfmm1.equal(&rfmm2));
}
TEST(RiseFallMinMaxTest, EqualDifferentValues)
{
RiseFallMinMax rfmm1(5.0f);
RiseFallMinMax rfmm2(3.0f);
EXPECT_FALSE(rfmm1.equal(&rfmm2));
}
TEST(RiseFallMinMaxTest, EqualDifferentExists)
{
RiseFallMinMax rfmm1(5.0f);
RiseFallMinMax rfmm2(5.0f);
rfmm2.removeValue(RiseFallBoth::rise(), MinMax::min());
EXPECT_FALSE(rfmm1.equal(&rfmm2));
}
TEST(RiseFallMinMaxTest, EqualBothEmpty)
{
RiseFallMinMax rfmm1;
RiseFallMinMax rfmm2;
EXPECT_TRUE(rfmm1.equal(&rfmm2));
}
TEST(RiseFallMinMaxTest, IsOneValueTrue)
{
RiseFallMinMax rfmm(5.0f);
EXPECT_TRUE(rfmm.isOneValue());
float val;
EXPECT_TRUE(rfmm.isOneValue(val));
EXPECT_FLOAT_EQ(val, 5.0f);
}
TEST(RiseFallMinMaxTest, IsOneValueFalse)
{
RiseFallMinMax rfmm(5.0f);
rfmm.setValue(RiseFall::rise(), MinMax::min(), 3.0f);
EXPECT_FALSE(rfmm.isOneValue());
}
TEST(RiseFallMinMaxTest, IsOneValueEmpty)
{
RiseFallMinMax rfmm;
EXPECT_FALSE(rfmm.isOneValue());
float val;
EXPECT_FALSE(rfmm.isOneValue(val));
}
TEST(RiseFallMinMaxTest, IsOneValuePartialExists)
{
RiseFallMinMax rfmm(5.0f);
rfmm.removeValue(RiseFallBoth::fall(), MinMax::max());
float val;
EXPECT_FALSE(rfmm.isOneValue(val));
}
TEST(RiseFallMinMaxTest, IsOneValueMinMax)
{
RiseFallMinMax rfmm;
rfmm.setValue(RiseFall::rise(), MinMax::min(), 5.0f);
rfmm.setValue(RiseFall::fall(), MinMax::min(), 5.0f);
float val;
EXPECT_TRUE(rfmm.isOneValue(MinMax::min(), val));
EXPECT_FLOAT_EQ(val, 5.0f);
}
TEST(RiseFallMinMaxTest, IsOneValueMinMaxDifferent)
{
RiseFallMinMax rfmm;
rfmm.setValue(RiseFall::rise(), MinMax::min(), 5.0f);
rfmm.setValue(RiseFall::fall(), MinMax::min(), 3.0f);
float val;
EXPECT_FALSE(rfmm.isOneValue(MinMax::min(), val));
}
TEST(RiseFallMinMaxTest, IsOneValueMinMaxEmpty)
{
RiseFallMinMax rfmm;
float val;
EXPECT_FALSE(rfmm.isOneValue(MinMax::min(), val));
}
TEST(RiseFallMinMaxTest, IsOneValueMinMaxPartial)
{
RiseFallMinMax rfmm;
rfmm.setValue(RiseFall::rise(), MinMax::max(), 5.0f);
// fall/max is not set
float val;
EXPECT_FALSE(rfmm.isOneValue(MinMax::max(), val));
}
////////////////////////////////////////////////////////////////
// RiseFallValues tests
////////////////////////////////////////////////////////////////
TEST(RiseFallValuesTest, DefaultConstructorEmpty)
{
RiseFallValues rfv;
EXPECT_FALSE(rfv.hasValue(RiseFall::rise()));
EXPECT_FALSE(rfv.hasValue(RiseFall::fall()));
}
TEST(RiseFallValuesTest, InitValueConstructor)
{
RiseFallValues rfv(3.0f);
EXPECT_TRUE(rfv.hasValue(RiseFall::rise()));
EXPECT_TRUE(rfv.hasValue(RiseFall::fall()));
EXPECT_FLOAT_EQ(rfv.value(RiseFall::rise()), 3.0f);
EXPECT_FLOAT_EQ(rfv.value(RiseFall::fall()), 3.0f);
}
TEST(RiseFallValuesTest, SetValueAll)
{
RiseFallValues rfv;
rfv.setValue(5.0f);
EXPECT_TRUE(rfv.hasValue(RiseFall::rise()));
EXPECT_TRUE(rfv.hasValue(RiseFall::fall()));
EXPECT_FLOAT_EQ(rfv.value(RiseFall::rise()), 5.0f);
EXPECT_FLOAT_EQ(rfv.value(RiseFall::fall()), 5.0f);
}
TEST(RiseFallValuesTest, SetValueRiseFallBoth)
{
RiseFallValues rfv;
rfv.setValue(RiseFallBoth::rise(), 1.0f);
EXPECT_TRUE(rfv.hasValue(RiseFall::rise()));
EXPECT_FALSE(rfv.hasValue(RiseFall::fall()));
EXPECT_FLOAT_EQ(rfv.value(RiseFall::rise()), 1.0f);
}
TEST(RiseFallValuesTest, SetValueRiseFallBothBoth)
{
RiseFallValues rfv;
rfv.setValue(RiseFallBoth::riseFall(), 9.0f);
EXPECT_TRUE(rfv.hasValue(RiseFall::rise()));
EXPECT_TRUE(rfv.hasValue(RiseFall::fall()));
EXPECT_FLOAT_EQ(rfv.value(RiseFall::rise()), 9.0f);
EXPECT_FLOAT_EQ(rfv.value(RiseFall::fall()), 9.0f);
}
TEST(RiseFallValuesTest, SetValueRiseFall)
{
RiseFallValues rfv;
rfv.setValue(RiseFall::fall(), 2.5f);
EXPECT_FALSE(rfv.hasValue(RiseFall::rise()));
EXPECT_TRUE(rfv.hasValue(RiseFall::fall()));
EXPECT_FLOAT_EQ(rfv.value(RiseFall::fall()), 2.5f);
}
TEST(RiseFallValuesTest, ValueWithExistsFlag)
{
RiseFallValues rfv;
float val;
bool exists;
rfv.value(RiseFall::rise(), val, exists);
EXPECT_FALSE(exists);
rfv.setValue(RiseFall::rise(), 4.0f);
rfv.value(RiseFall::rise(), val, exists);
EXPECT_TRUE(exists);
EXPECT_FLOAT_EQ(val, 4.0f);
}
TEST(RiseFallValuesTest, SetValues)
{
RiseFallValues src(7.0f);
RiseFallValues dest;
dest.setValues(&src);
EXPECT_TRUE(dest.hasValue(RiseFall::rise()));
EXPECT_TRUE(dest.hasValue(RiseFall::fall()));
EXPECT_FLOAT_EQ(dest.value(RiseFall::rise()), 7.0f);
EXPECT_FLOAT_EQ(dest.value(RiseFall::fall()), 7.0f);
}
TEST(RiseFallValuesTest, Clear)
{
RiseFallValues rfv(5.0f);
EXPECT_TRUE(rfv.hasValue(RiseFall::rise()));
rfv.clear();
EXPECT_FALSE(rfv.hasValue(RiseFall::rise()));
EXPECT_FALSE(rfv.hasValue(RiseFall::fall()));
}
TEST(RiseFallValuesTest, SetRiseThenFall)
{
RiseFallValues rfv;
rfv.setValue(RiseFall::rise(), 1.0f);
rfv.setValue(RiseFall::fall(), 2.0f);
EXPECT_FLOAT_EQ(rfv.value(RiseFall::rise()), 1.0f);
EXPECT_FLOAT_EQ(rfv.value(RiseFall::fall()), 2.0f);
}
TEST(RiseFallValuesTest, OverwriteValue)
{
RiseFallValues rfv(5.0f);
rfv.setValue(RiseFall::rise(), 10.0f);
EXPECT_FLOAT_EQ(rfv.value(RiseFall::rise()), 10.0f);
EXPECT_FLOAT_EQ(rfv.value(RiseFall::fall()), 5.0f);
}
////////////////////////////////////////////////////////////////
// PatternMatch class tests
////////////////////////////////////////////////////////////////
TEST(PatternMatchClassTest, SimpleGlobConstructor)
{
PatternMatch pm("hello");
EXPECT_EQ(pm.pattern(), "hello");
EXPECT_FALSE(pm.isRegexp());
EXPECT_FALSE(pm.nocase());
EXPECT_EQ(pm.tclInterp(), nullptr);
}
TEST(PatternMatchClassTest, GlobMatchExact)
{
PatternMatch pm("hello");
EXPECT_TRUE(pm.match("hello"));
EXPECT_FALSE(pm.match("world"));
}
TEST(PatternMatchClassTest, GlobMatchWithStar)
{
PatternMatch pm("hel*");
EXPECT_TRUE(pm.match("hello"));
EXPECT_TRUE(pm.match("help"));
EXPECT_FALSE(pm.match("world"));
}
TEST(PatternMatchClassTest, GlobMatchWithQuestion)
{
PatternMatch pm("h?llo");
EXPECT_TRUE(pm.match("hello"));
EXPECT_TRUE(pm.match("hallo"));
EXPECT_FALSE(pm.match("hllo"));
}
TEST(PatternMatchClassTest, GlobMatchString)
{
PatternMatch pm("test*");
std::string s = "testing";
EXPECT_TRUE(pm.match(s));
std::string s2 = "other";
EXPECT_FALSE(pm.match(s2));
}
TEST(PatternMatchClassTest, HasWildcardsGlob)
{
PatternMatch pm_wild("he*lo");
EXPECT_TRUE(pm_wild.hasWildcards());
PatternMatch pm_q("he?lo");
EXPECT_TRUE(pm_q.hasWildcards());
PatternMatch pm_none("hello");
EXPECT_FALSE(pm_none.hasWildcards());
}
TEST(PatternMatchClassTest, MatchNoCase)
{
PatternMatch pm("hello", false, true, nullptr);
EXPECT_TRUE(pm.matchNoCase("hello"));
EXPECT_TRUE(pm.matchNoCase("HELLO"));
EXPECT_TRUE(pm.matchNoCase("Hello"));
}
TEST(PatternMatchClassTest, MatchNoCaseSensitive)
{
PatternMatch pm("hello", false, false, nullptr);
EXPECT_TRUE(pm.matchNoCase("hello"));
EXPECT_FALSE(pm.matchNoCase("HELLO"));
}
TEST(PatternMatchClassTest, InheritFromConstructor)
{
PatternMatch parent("base*", false, true, nullptr);
PatternMatch child("child*", &parent);
EXPECT_EQ(child.pattern(), "child*");
EXPECT_FALSE(child.isRegexp());
EXPECT_TRUE(child.nocase());
EXPECT_TRUE(child.match("children"));
}
TEST(PatternMatchClassTest, InheritFromStringConstructor)
{
PatternMatch parent("base*", false, true, nullptr);
std::string childPat = "child*";
PatternMatch child(childPat, &parent);
EXPECT_TRUE(child.nocase());
EXPECT_TRUE(child.match("children"));
}
// Regexp-based PatternMatch tests require a Tcl interpreter
class PatternMatchRegexpTest : public ::testing::Test {
protected:
void SetUp() override {
interp_ = Tcl_CreateInterp();
}
void TearDown() override {
if (interp_)
Tcl_DeleteInterp(interp_);
}
Tcl_Interp *interp_;
};
TEST_F(PatternMatchRegexpTest, RegexpHasWildcards)
{
// Test regexp wildcards detection (uses a different code path)
PatternMatch pm_reg("he.lo", true, false, interp_);
EXPECT_TRUE(pm_reg.hasWildcards());
PatternMatch pm_plus("he+lo", true, false, interp_);
EXPECT_TRUE(pm_plus.hasWildcards());
PatternMatch pm_bracket("he[lL]lo", true, false, interp_);
EXPECT_TRUE(pm_bracket.hasWildcards());
}
TEST_F(PatternMatchRegexpTest, RegexpMatch)
{
PatternMatch pm("hel+o", true, false, interp_);
EXPECT_TRUE(pm.match("hello"));
EXPECT_TRUE(pm.match("helllo"));
EXPECT_FALSE(pm.match("heo"));
}
TEST_F(PatternMatchRegexpTest, RegexpMatchNoCase)
{
PatternMatch pm("hello", true, true, interp_);
EXPECT_TRUE(pm.matchNoCase("HELLO"));
EXPECT_TRUE(pm.matchNoCase("hello"));
}
TEST_F(PatternMatchRegexpTest, RegexpNoWildcards)
{
PatternMatch pm("hello", true, false, interp_);
EXPECT_FALSE(pm.hasWildcards());
}
TEST_F(PatternMatchRegexpTest, RegexpInheritFrom)
{
PatternMatch parent("base.*", true, false, interp_);
PatternMatch child("child.*", &parent);
EXPECT_TRUE(child.isRegexp());
EXPECT_TRUE(child.match("children"));
}
TEST_F(PatternMatchRegexpTest, RegexpInheritFromString)
{
PatternMatch parent("base.*", true, true, interp_);
std::string childPat = "child.*";
PatternMatch child(childPat, &parent);
EXPECT_TRUE(child.isRegexp());
EXPECT_TRUE(child.nocase());
EXPECT_TRUE(child.match("CHILDREN"));
}
TEST_F(PatternMatchRegexpTest, RegexpMatchString)
{
PatternMatch pm("te.t", true, false, interp_);
std::string s = "test";
EXPECT_TRUE(pm.match(s));
std::string s2 = "team";
EXPECT_FALSE(pm.match(s2));
}
TEST_F(PatternMatchRegexpTest, RegexpMatchNoCaseSensitive)
{
// nocase=false means case matters
PatternMatch pm("hello", true, false, interp_);
EXPECT_TRUE(pm.matchNoCase("hello"));
// With nocase=false on the pattern but using matchNoCase,
// it still delegates to the regexp which was compiled without nocase
EXPECT_FALSE(pm.matchNoCase("HELLO"));
}
////////////////////////////////////////////////////////////////
// Report tests
////////////////////////////////////////////////////////////////
TEST(ReportTest, BasicConstruction)
{
Report report;
// Should not crash. defaultReport should be set.
EXPECT_EQ(Report::defaultReport(), &report);
}
TEST(ReportTest, RedirectStringBasic)
{
Report report;
report.redirectStringBegin();
report.reportLine("hello world");
const char *result = report.redirectStringEnd();
EXPECT_NE(result, nullptr);
std::string s(result);
EXPECT_NE(s.find("hello world"), std::string::npos);
}
TEST(ReportTest, RedirectStringMultipleLines)
{
Report report;
report.redirectStringBegin();
report.reportLine("line1");
report.reportLine("line2");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("line1"), std::string::npos);
EXPECT_NE(s.find("line2"), std::string::npos);
}
TEST(ReportTest, RedirectStringStdString)
{
Report report;
report.redirectStringBegin();
std::string line = "std string line";
report.reportLine(line);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("std string line"), std::string::npos);
}
TEST(ReportTest, ReportBlankLine)
{
Report report;
report.redirectStringBegin();
report.reportBlankLine();
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_EQ(s, "\n");
}
TEST(ReportTest, ReportLineFormatted)
{
Report report;
report.redirectStringBegin();
report.report("value={}", 42);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("value=42"), std::string::npos);
}
TEST(ReportTest, LogToFile)
{
Report report;
const char *tmpfile = "/tmp/test_report_log.txt";
report.logBegin(tmpfile);
report.reportLine("log test line");
report.logEnd();
// Verify file was created with content
FILE *f = fopen(tmpfile, "r");
ASSERT_NE(f, nullptr);
char buf[256];
ASSERT_NE(fgets(buf, sizeof(buf), f), nullptr);
fclose(f);
EXPECT_NE(strstr(buf, "log test line"), nullptr);
std::remove(tmpfile);
}
TEST(ReportTest, LogEndWithoutLog)
{
ASSERT_NO_THROW(( [&](){
Report report;
// Should not crash when no log is active
report.logEnd();
}() ));
}
TEST(ReportTest, RedirectFileBegin)
{
Report report;
const char *tmpfile = "/tmp/test_report_redirect.txt";
report.redirectFileBegin(tmpfile);
report.reportLine("redirected line");
report.redirectFileEnd();
FILE *f = fopen(tmpfile, "r");
ASSERT_NE(f, nullptr);
char buf[256];
ASSERT_NE(fgets(buf, sizeof(buf), f), nullptr);
fclose(f);
EXPECT_NE(strstr(buf, "redirected line"), nullptr);
std::remove(tmpfile);
}
TEST(ReportTest, RedirectFileAppendBegin)
{
Report report;
const char *tmpfile = "/tmp/test_report_append.txt";
// Write first
report.redirectFileBegin(tmpfile);
report.reportLine("first");
report.redirectFileEnd();
// Append
report.redirectFileAppendBegin(tmpfile);
report.reportLine("second");
report.redirectFileEnd();
FILE *f = fopen(tmpfile, "r");
ASSERT_NE(f, nullptr);
char content[512] = {};
size_t bytes_read = fread(content, 1, sizeof(content) - 1, f);
EXPECT_GT(bytes_read, 0u);
fclose(f);
EXPECT_NE(strstr(content, "first"), nullptr);
EXPECT_NE(strstr(content, "second"), nullptr);
std::remove(tmpfile);
}
TEST(ReportTest, RedirectFileEndWithoutRedirect)
{
ASSERT_NO_THROW(( [&](){
Report report;
// Should not crash
report.redirectFileEnd();
}() ));
}
TEST(ReportTest, RedirectFileNotWritable)
{
Report report;
EXPECT_THROW(report.redirectFileBegin("/nonexistent/path/file.txt"),
FileNotWritable);
}
TEST(ReportTest, RedirectFileAppendNotWritable)
{
Report report;
EXPECT_THROW(report.redirectFileAppendBegin("/nonexistent/path/file.txt"),
FileNotWritable);
}
TEST(ReportTest, LogNotWritable)
{
Report report;
EXPECT_THROW(report.logBegin("/nonexistent/path/log.txt"),
FileNotWritable);
}
TEST(ReportTest, WarnBasic)
{
Report report;
report.redirectStringBegin();
report.warn(100, "something bad {}", 42);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 100:"), std::string::npos);
EXPECT_NE(s.find("something bad 42"), std::string::npos);
}
TEST(ReportTest, FileWarn)
{
Report report;
report.redirectStringBegin();
report.fileWarn(101, "test.v", 10, "missing {}", "semicolon");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 101:"), std::string::npos);
EXPECT_NE(s.find("test.v"), std::string::npos);
EXPECT_NE(s.find("line 10"), std::string::npos);
EXPECT_NE(s.find("missing semicolon"), std::string::npos);
}
TEST(ReportTest, VwarnBasic)
{
Report report;
report.redirectStringBegin();
// Use vwarn indirectly via warn (vwarn is called by warn internals)
report.warn(102, "warn test {}", "value");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 102:"), std::string::npos);
}
TEST(ReportTest, ErrorThrows)
{
Report report;
EXPECT_THROW(report.error(200, "error message {}", 1), ExceptionMsg);
}
TEST(ReportTest, ErrorMessageContent)
{
Report report;
try {
report.error(200, "specific error {}", "info");
FAIL() << "Expected ExceptionMsg";
} catch (const ExceptionMsg &e) {
std::string what = e.what();
EXPECT_NE(what.find("specific error info"), std::string::npos);
}
}
TEST(ReportTest, FileErrorThrows)
{
Report report;
EXPECT_THROW(report.fileError(201, "test.sdc", 5, "parse error"), ExceptionMsg);
}
TEST(ReportTest, FileErrorContent)
{
Report report;
try {
report.fileError(201, "test.sdc", 5, "unexpected token {}", "foo");
FAIL() << "Expected ExceptionMsg";
} catch (const ExceptionMsg &e) {
std::string what = e.what();
EXPECT_NE(what.find("test.sdc"), std::string::npos);
EXPECT_NE(what.find("line 5"), std::string::npos);
EXPECT_NE(what.find("unexpected token foo"), std::string::npos);
}
}
TEST(ReportTest, VfileErrorThrows)
{
Report report;
// Test vfileError by throwing and catching
try {
report.fileError(202, "a.v", 3, "vfile error");
FAIL();
} catch (const ExceptionMsg &e) {
std::string what = e.what();
EXPECT_NE(what.find("a.v"), std::string::npos);
}
}
TEST(ReportTest, SuppressMsgId)
{
Report report;
EXPECT_FALSE(report.isSuppressed(100));
report.suppressMsgId(100);
EXPECT_TRUE(report.isSuppressed(100));
}
TEST(ReportTest, UnsuppressMsgId)
{
Report report;
report.suppressMsgId(100);
EXPECT_TRUE(report.isSuppressed(100));
report.unsuppressMsgId(100);
EXPECT_FALSE(report.isSuppressed(100));
}
TEST(ReportTest, SuppressedWarn)
{
Report report;
report.suppressMsgId(100);
report.redirectStringBegin();
report.warn(100, "should not appear");
const char *result = report.redirectStringEnd();
std::string s(result);
// Suppressed warning should produce no output
EXPECT_EQ(s.find("should not appear"), std::string::npos);
}
TEST(ReportTest, SuppressedFileWarn)
{
Report report;
report.suppressMsgId(101);
report.redirectStringBegin();
report.fileWarn(101, "test.v", 1, "suppressed file warn");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_EQ(s.find("suppressed file warn"), std::string::npos);
}
TEST(ReportTest, SuppressedErrorIsSuppressed)
{
Report report;
report.suppressMsgId(200);
try {
report.error(200, "suppressed error");
FAIL();
} catch (const ExceptionMsg &e) {
EXPECT_TRUE(e.suppressed());
}
}
TEST(ReportTest, PrintStringDirect)
{
Report report;
report.redirectStringBegin();
report.printString("direct print", 12);
const char *result = report.redirectStringEnd();
EXPECT_STREQ(result, "direct print");
}
TEST(ReportTest, LogAndConsoleSimultaneous)
{
Report report;
const char *logfile = "/tmp/test_report_logconsole.txt";
report.logBegin(logfile);
// Print to console (with log capturing)
report.reportLine("dual output");
report.logEnd();
FILE *f = fopen(logfile, "r");
ASSERT_NE(f, nullptr);
char buf[256];
ASSERT_NE(fgets(buf, sizeof(buf), f), nullptr);
fclose(f);
EXPECT_NE(strstr(buf, "dual output"), nullptr);
std::remove(logfile);
}
////////////////////////////////////////////////////////////////
// Additional StringUtil tests
////////////////////////////////////////////////////////////////
TEST(StringUtilTest, StaFormat)
{
std::string s = sta::format("value={}", 42);
EXPECT_EQ(s, "value=42");
}
TEST(StringUtilTest, StaFormatToStdString)
{
std::string s = sta::format("test {} {}", "abc", 123);
EXPECT_EQ(s, "test abc 123");
}
TEST(StringUtilTest, StaFormatAppendToStdString)
{
std::string s = "prefix ";
s += sta::format("suffix {}", 1);
EXPECT_EQ(s, "prefix suffix 1");
}
TEST(StringUtilTest, StaFormatAllocates)
{
std::string s = sta::format("number {}", 99);
EXPECT_EQ(s, "number 99");
}
TEST(StringUtilTest, StaFormatTmp)
{
std::string s = sta::format("tmp {}", 42);
EXPECT_EQ(s, "tmp 42");
}
TEST(StringUtilTest, StringEqWithLength)
{
EXPECT_TRUE(stringEq("hello world", "hello", 5));
EXPECT_FALSE(stringEq("hello world", "hellx", 5));
}
TEST(StringUtilTest, StringBeginEq)
{
EXPECT_TRUE(stringBeginEq("hello world", "hello"));
EXPECT_FALSE(stringBeginEq("hello world", "world"));
}
TEST(StringUtilTest, StringBeginEqual)
{
EXPECT_TRUE(stringBeginEqual("Hello World", "hello"));
EXPECT_FALSE(stringBeginEqual("Hello World", "world"));
}
TEST(StringUtilTest, StringEqual)
{
EXPECT_TRUE(stringEqual("HELLO", "hello"));
EXPECT_FALSE(stringEqual("hello", "world"));
}
////////////////////////////////////////////////////////////////
// Debug tests
////////////////////////////////////////////////////////////////
TEST(DebugTest, BasicConstruction)
{
Report report;
Debug debug(&report);
// Initial state: level is 0 for any debug key
EXPECT_EQ(debug.level("test"), 0);
EXPECT_EQ(debug.statsLevel(), 0);
}
TEST(DebugTest, SetAndCheckLevel)
{
Report report;
Debug debug(&report);
debug.setLevel("graph", 3);
EXPECT_EQ(debug.level("graph"), 3);
EXPECT_TRUE(debug.check("graph", 1));
EXPECT_TRUE(debug.check("graph", 3));
EXPECT_FALSE(debug.check("graph", 4));
}
TEST(DebugTest, SetLevelStats)
{
Report report;
Debug debug(&report);
debug.setLevel("stats", 2);
EXPECT_EQ(debug.statsLevel(), 2);
}
TEST(DebugTest, SetLevelZeroRemoves)
{
Report report;
Debug debug(&report);
debug.setLevel("test", 3);
EXPECT_TRUE(debug.check("test", 1));
debug.setLevel("test", 0);
EXPECT_FALSE(debug.check("test", 1));
EXPECT_EQ(debug.level("test"), 0);
}
TEST(DebugTest, CheckUnsetKey)
{
Report report;
Debug debug(&report);
EXPECT_FALSE(debug.check("nonexistent", 1));
}
TEST(DebugTest, ReportLine)
{
Report report;
Debug debug(&report);
debug.setLevel("test", 1);
// Redirect output to string to capture the debug line
report.redirectStringBegin();
debug.report("test", "value {}", 42);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("test"), std::string::npos);
EXPECT_NE(s.find("value 42"), std::string::npos);
}
////////////////////////////////////////////////////////////////
// Tests for variadic template Report methods (warn, fileWarn, error, fileError)
////////////////////////////////////////////////////////////////
TEST(ReportVaTest, WarnBasic)
{
Report report;
report.redirectStringBegin();
report.warn(300, "warn message {}", 42);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 300:"), std::string::npos);
EXPECT_NE(s.find("warn message 42"), std::string::npos);
}
TEST(ReportVaTest, WarnSuppressed)
{
Report report;
report.suppressMsgId(300);
report.redirectStringBegin();
report.warn(300, "suppressed warn");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_EQ(s.find("suppressed warn"), std::string::npos);
}
TEST(ReportVaTest, FileWarnBasic)
{
Report report;
report.redirectStringBegin();
report.fileWarn(301, "test.v", 15, "file warn msg {}", "detail");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 301:"), std::string::npos);
EXPECT_NE(s.find("test.v"), std::string::npos);
EXPECT_NE(s.find("line 15"), std::string::npos);
EXPECT_NE(s.find("file warn msg detail"), std::string::npos);
}
TEST(ReportVaTest, FileWarnSuppressed)
{
Report report;
report.suppressMsgId(301);
report.redirectStringBegin();
report.fileWarn(301, "test.v", 15, "suppressed file warn");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_EQ(s.find("suppressed file warn"), std::string::npos);
}
TEST(ReportVaTest, ErrorThrows)
{
Report report;
EXPECT_THROW(report.error(400, "error msg {}", 99), ExceptionMsg);
}
TEST(ReportVaTest, ErrorContent)
{
Report report;
try {
report.error(400, "error content {}", "test");
FAIL();
} catch (const ExceptionMsg &e) {
std::string what = e.what();
EXPECT_NE(what.find("error content test"), std::string::npos);
}
}
TEST(ReportVaTest, FileErrorThrows)
{
Report report;
EXPECT_THROW(report.fileError(401, "myfile.sdc", 20, "file error msg"),
ExceptionMsg);
}
TEST(ReportVaTest, FileErrorContent)
{
Report report;
try {
report.fileError(401, "myfile.sdc", 20, "file error {}", 42);
FAIL();
} catch (const ExceptionMsg &e) {
std::string what = e.what();
EXPECT_NE(what.find("myfile.sdc"), std::string::npos);
EXPECT_NE(what.find("line 20"), std::string::npos);
EXPECT_NE(what.find("file error 42"), std::string::npos);
}
}
// Test Report buffer growth (long format strings that exceed initial buffer)
TEST(ReportTest, LongReportLine)
{
Report report;
report.redirectStringBegin();
// Create a string longer than the initial 1000 char buffer
std::string long_str(2000, 'x');
report.reportLine(long_str);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find(long_str), std::string::npos);
}
TEST(ReportTest, LongWarnLine)
{
Report report;
report.redirectStringBegin();
std::string long_str(2000, 'y');
report.warn(500, "{}", long_str);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 500:"), std::string::npos);
EXPECT_NE(s.find(long_str), std::string::npos);
}
// Test ExceptionMsg suppressed flag
TEST(ReportVaTest, ErrorSuppressedFlag)
{
Report report;
report.suppressMsgId(400);
try {
report.error(400, "suppressed error");
FAIL();
} catch (const ExceptionMsg &e) {
EXPECT_TRUE(e.suppressed());
}
}
TEST(ReportVaTest, ErrorNotSuppressedFlag)
{
Report report;
try {
report.error(400, "not suppressed");
FAIL();
} catch (const ExceptionMsg &e) {
EXPECT_FALSE(e.suppressed());
}
}
// Test FileNotWritable exception
TEST(ExceptionTest, FileNotWritable)
{
try {
throw FileNotWritable("/nonexistent/path");
} catch (const FileNotWritable &e) {
std::string what = e.what();
EXPECT_NE(what.find("/nonexistent/path"), std::string::npos);
}
}
// Test FileNotReadable exception
TEST(ExceptionTest, FileNotReadable)
{
try {
throw FileNotReadable("/missing/file");
} catch (const FileNotReadable &e) {
std::string what = e.what();
EXPECT_NE(what.find("/missing/file"), std::string::npos);
}
}
// Test ExceptionMsg
TEST(ExceptionTest, ExceptionMsg)
{
try {
throw ExceptionMsg("test error message", false);
} catch (const ExceptionMsg &e) {
EXPECT_STREQ(e.what(), "test error message");
EXPECT_FALSE(e.suppressed());
}
}
TEST(ExceptionTest, ExceptionMsgSuppressed)
{
try {
throw ExceptionMsg("suppressed msg", true);
} catch (const ExceptionMsg &e) {
EXPECT_STREQ(e.what(), "suppressed msg");
EXPECT_TRUE(e.suppressed());
}
}
// Test RegexpCompileError
TEST(ExceptionTest, RegexpCompileError)
{
try {
throw RegexpCompileError("bad_pattern");
} catch (const RegexpCompileError &e) {
std::string what = e.what();
EXPECT_NE(what.find("bad_pattern"), std::string::npos);
EXPECT_NE(what.find("regular expression"), std::string::npos);
}
}
////////////////////////////////////////////////////////////////
// Transition class tests (Transition.cc coverage)
////////////////////////////////////////////////////////////////
#include "Transition.hh"
// RiseFall::asTransition
TEST(TransitionCovTest, RiseFallAsTransition)
{
const Transition *tr_rise = RiseFall::rise()->asTransition();
EXPECT_EQ(tr_rise, Transition::rise());
const Transition *tr_fall = RiseFall::fall()->asTransition();
EXPECT_EQ(tr_fall, Transition::fall());
}
// RiseFallBoth::find
TEST(TransitionCovTest, RiseFallBothFind)
{
const RiseFallBoth *r = RiseFallBoth::find("rise");
EXPECT_EQ(r, RiseFallBoth::rise());
const RiseFallBoth *f = RiseFallBoth::find("fall");
EXPECT_EQ(f, RiseFallBoth::fall());
const RiseFallBoth *rf = RiseFallBoth::find("rise_fall");
EXPECT_EQ(rf, RiseFallBoth::riseFall());
const RiseFallBoth *nope = RiseFallBoth::find("nonexistent");
EXPECT_EQ(nope, nullptr);
}
// RiseFallBoth::matches(const Transition*)
TEST(TransitionCovTest, RiseFallBothMatchesTransition)
{
EXPECT_TRUE(RiseFallBoth::rise()->matches(Transition::rise()));
EXPECT_FALSE(RiseFallBoth::rise()->matches(Transition::fall()));
EXPECT_TRUE(RiseFallBoth::fall()->matches(Transition::fall()));
EXPECT_FALSE(RiseFallBoth::fall()->matches(Transition::rise()));
// riseFall matches everything
EXPECT_TRUE(RiseFallBoth::riseFall()->matches(Transition::rise()));
EXPECT_TRUE(RiseFallBoth::riseFall()->matches(Transition::fall()));
EXPECT_TRUE(RiseFallBoth::riseFall()->matches(Transition::tr0Z()));
}
// Transition::asRiseFallBoth
TEST(TransitionCovTest, TransitionAsRiseFallBoth)
{
const RiseFallBoth *rfb_rise = Transition::rise()->asRiseFallBoth();
EXPECT_NE(rfb_rise, nullptr);
const RiseFallBoth *rfb_fall = Transition::fall()->asRiseFallBoth();
EXPECT_NE(rfb_fall, nullptr);
}
// Transition::matches(const Transition*) - non-riseFall case
TEST(TransitionCovTest, TransitionMatchesSelf)
{
EXPECT_TRUE(Transition::rise()->matches(Transition::rise()));
EXPECT_FALSE(Transition::rise()->matches(Transition::fall()));
EXPECT_TRUE(Transition::fall()->matches(Transition::fall()));
EXPECT_FALSE(Transition::fall()->matches(Transition::rise()));
}
// RiseFall::find with short name
TEST(TransitionCovTest, RiseFallFindShortName)
{
const RiseFall *r = RiseFall::find("^");
EXPECT_EQ(r, RiseFall::rise());
const RiseFall *f = RiseFall::find("v");
EXPECT_EQ(f, RiseFall::fall());
const RiseFall *nope = RiseFall::find("x");
EXPECT_EQ(nope, nullptr);
}
// RiseFallBoth::to_string and shortName
TEST(TransitionCovTest, RiseFallBothToString)
{
EXPECT_EQ(RiseFallBoth::rise()->to_string(), "rise");
EXPECT_EQ(RiseFallBoth::fall()->to_string(), "fall");
EXPECT_EQ(RiseFallBoth::rise()->shortName(), "^");
EXPECT_EQ(RiseFallBoth::fall()->shortName(), "v");
}
// RiseFallBoth::index
TEST(TransitionCovTest, RiseFallBothIndex)
{
EXPECT_EQ(RiseFallBoth::rise()->index(), 0);
EXPECT_EQ(RiseFallBoth::fall()->index(), 1);
EXPECT_EQ(RiseFallBoth::riseFall()->index(), 2);
}
// RiseFallBoth::rangeIndex
TEST(TransitionCovTest, RiseFallBothRangeIndex)
{
auto &ri = RiseFallBoth::rise()->rangeIndex();
EXPECT_EQ(ri.size(), 1u);
EXPECT_EQ(ri[0], 0);
auto &fi = RiseFallBoth::fall()->rangeIndex();
EXPECT_EQ(fi.size(), 1u);
EXPECT_EQ(fi[0], 1);
auto &rfi = RiseFallBoth::riseFall()->rangeIndex();
EXPECT_EQ(rfi.size(), 2u);
}
// RiseFallBoth::range
TEST(TransitionCovTest, RiseFallBothRange)
{
auto &rr = RiseFallBoth::rise()->range();
EXPECT_EQ(rr.size(), 1u);
EXPECT_EQ(rr[0], RiseFall::rise());
auto &fr = RiseFallBoth::fall()->range();
EXPECT_EQ(fr.size(), 1u);
EXPECT_EQ(fr[0], RiseFall::fall());
auto &rfr = RiseFallBoth::riseFall()->range();
EXPECT_EQ(rfr.size(), 2u);
}
// RiseFallBoth::asRiseFall returns nullptr for riseFall()
TEST(TransitionCovTest, RiseFallBothAsRiseFall)
{
EXPECT_EQ(RiseFallBoth::rise()->asRiseFall(), RiseFall::rise());
EXPECT_EQ(RiseFallBoth::fall()->asRiseFall(), RiseFall::fall());
EXPECT_EQ(RiseFallBoth::riseFall()->asRiseFall(), nullptr);
}
// Transition::find with init/final strings
TEST(TransitionCovTest, TransitionFindInitFinal)
{
const Transition *t01 = Transition::find("01");
EXPECT_EQ(t01, Transition::rise());
const Transition *t10 = Transition::find("10");
EXPECT_EQ(t10, Transition::fall());
const Transition *t0Z = Transition::find("0Z");
EXPECT_EQ(t0Z, Transition::tr0Z());
const Transition *tZ1 = Transition::find("Z1");
EXPECT_EQ(tZ1, Transition::trZ1());
const Transition *t1Z = Transition::find("1Z");
EXPECT_EQ(t1Z, Transition::tr1Z());
const Transition *tZ0 = Transition::find("Z0");
EXPECT_EQ(tZ0, Transition::trZ0());
}
// Transition index
TEST(TransitionCovTest, TransitionIndex)
{
EXPECT_EQ(Transition::rise()->index(), 0);
EXPECT_EQ(Transition::fall()->index(), 1);
EXPECT_EQ(Transition::tr0Z()->index(), 2);
EXPECT_EQ(Transition::trZ1()->index(), 3);
}
// Transition::asRiseFall for non-rise/fall transitions
TEST(TransitionCovTest, TransitionAsRiseFallExtra)
{
EXPECT_EQ(Transition::tr0Z()->asRiseFall(), RiseFall::rise());
EXPECT_EQ(Transition::trZ1()->asRiseFall(), RiseFall::rise());
EXPECT_EQ(Transition::tr1Z()->asRiseFall(), RiseFall::fall());
EXPECT_EQ(Transition::trZ0()->asRiseFall(), RiseFall::fall());
EXPECT_EQ(Transition::trXZ()->asRiseFall(), nullptr);
EXPECT_EQ(Transition::trZX()->asRiseFall(), nullptr);
EXPECT_EQ(Transition::riseFall()->asRiseFall(), nullptr);
}
// Transition asInitFinalString for various transitions
TEST(TransitionCovTest, TransitionAsInitFinalString)
{
EXPECT_EQ(Transition::rise()->asInitFinalString(), "01");
EXPECT_EQ(Transition::fall()->asInitFinalString(), "10");
EXPECT_EQ(Transition::tr0Z()->asInitFinalString(), "0Z");
EXPECT_EQ(Transition::trZ1()->asInitFinalString(), "Z1");
EXPECT_EQ(Transition::tr1Z()->asInitFinalString(), "1Z");
EXPECT_EQ(Transition::trZ0()->asInitFinalString(), "Z0");
EXPECT_EQ(Transition::tr0X()->asInitFinalString(), "0X");
EXPECT_EQ(Transition::trX1()->asInitFinalString(), "X1");
EXPECT_EQ(Transition::tr1X()->asInitFinalString(), "1X");
EXPECT_EQ(Transition::trX0()->asInitFinalString(), "X0");
EXPECT_EQ(Transition::trXZ()->asInitFinalString(), "XZ");
EXPECT_EQ(Transition::trZX()->asInitFinalString(), "ZX");
EXPECT_EQ(Transition::riseFall()->asInitFinalString(), "**");
}
// Transition::sdfTripleIndex
TEST(TransitionCovTest, TransitionSdfTripleIndex)
{
EXPECT_EQ(Transition::rise()->sdfTripleIndex(), 0);
EXPECT_EQ(Transition::fall()->sdfTripleIndex(), 1);
EXPECT_EQ(Transition::tr0Z()->sdfTripleIndex(), 2);
EXPECT_EQ(Transition::trZ1()->sdfTripleIndex(), 3);
EXPECT_EQ(Transition::tr1Z()->sdfTripleIndex(), 4);
EXPECT_EQ(Transition::trZ0()->sdfTripleIndex(), 5);
EXPECT_EQ(Transition::tr0X()->sdfTripleIndex(), 6);
EXPECT_EQ(Transition::trX1()->sdfTripleIndex(), 7);
EXPECT_EQ(Transition::tr1X()->sdfTripleIndex(), 8);
EXPECT_EQ(Transition::trX0()->sdfTripleIndex(), 9);
EXPECT_EQ(Transition::trXZ()->sdfTripleIndex(), 10);
EXPECT_EQ(Transition::trZX()->sdfTripleIndex(), 11u);
EXPECT_EQ(Transition::riseFall()->sdfTripleIndex(), 12u);
}
// Transition::maxIndex
TEST(TransitionCovTest, TransitionMaxIndex)
{
EXPECT_GE(Transition::maxIndex(), 11);
}
// RiseFall::to_string
TEST(TransitionCovTest, RiseFallToString)
{
EXPECT_EQ(RiseFall::rise()->to_string(), "rise");
EXPECT_EQ(RiseFall::fall()->to_string(), "fall");
}
////////////////////////////////////////////////////////////////
// Additional StringUtil coverage
////////////////////////////////////////////////////////////////
TEST(StringUtilCovTest, StaFormatArgs)
{
// Test sta::format with multiple arguments
std::string s = sta::format("args test {} {}", 42, "hello");
EXPECT_EQ(s, "args test 42 hello");
}
// Long sta::format string
TEST(StringUtilCovTest, LongStaFormat)
{
std::string long_str(500, 'z');
std::string result = sta::format("{}", long_str);
EXPECT_EQ(result, long_str);
}
// std::string append
TEST(StringUtilCovTest, StringAppendStd)
{
std::string s;
s += "hello";
s += " world";
EXPECT_EQ(s, "hello world");
}
////////////////////////////////////////////////////////////////
// Report: printConsole coverage
////////////////////////////////////////////////////////////////
TEST(ReportCovTest, PrintConsoleDirectly)
{
Report report;
// printConsole writes directly to stdout - just ensure it doesn't crash
// and returns a reasonable value
size_t written = report.printString("test output\n", 12);
EXPECT_GT(written, 0u);
}
// Report: printLine via reportLineString with empty string
TEST(ReportCovTest, ReportLineStringEmpty)
{
Report report;
report.redirectStringBegin();
report.reportLine("");
const char *result = report.redirectStringEnd();
std::string s(result);
// Empty line should just have a newline
EXPECT_EQ(s, "\n");
}
// Report: printToBuffer overflow (forces buffer growth)
TEST(ReportCovTest, ReportLineLongFormatted)
{
Report report;
report.redirectStringBegin();
std::string fmt_str(2000, 'a');
report.report("{} end", fmt_str);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find(fmt_str), std::string::npos);
EXPECT_NE(s.find("end"), std::string::npos);
}
// Report: multiple redirects (file then string)
TEST(ReportCovTest, ReportRedirectSequence)
{
Report report;
const char *tmpfile = "/tmp/test_report_seq.txt";
// Redirect to file first
report.redirectFileBegin(tmpfile);
report.reportLine("file output");
report.redirectFileEnd();
// Then redirect to string
report.redirectStringBegin();
report.reportLine("string output");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("string output"), std::string::npos);
std::remove(tmpfile);
}
// Report: log active during string redirect (log should not capture)
TEST(ReportCovTest, LogDuringStringRedirect)
{
Report report;
const char *logfile = "/tmp/test_report_log_str.txt";
report.logBegin(logfile);
report.redirectStringBegin();
report.reportLine("string only");
const char *result = report.redirectStringEnd();
report.logEnd();
std::string s(result);
EXPECT_NE(s.find("string only"), std::string::npos);
std::remove(logfile);
}
// Report: warn with format that triggers printToBufferAppend
TEST(ReportCovTest, WarnWithLongMessage)
{
Report report;
report.redirectStringBegin();
std::string long_msg(1500, 'w');
report.warn(999, "prefix {} suffix", long_msg);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 999:"), std::string::npos);
EXPECT_NE(s.find("prefix"), std::string::npos);
EXPECT_NE(s.find("suffix"), std::string::npos);
}
// Report: fileWarn with long message
TEST(ReportCovTest, FileWarnLongMessage)
{
Report report;
report.redirectStringBegin();
std::string long_msg(1500, 'f');
report.fileWarn(998, "bigfile.v", 100, "detail: {}", long_msg);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 998:"), std::string::npos);
EXPECT_NE(s.find("bigfile.v"), std::string::npos);
EXPECT_NE(s.find("line 100"), std::string::npos);
}
// Report: error with long message (forces buffer growth)
TEST(ReportCovTest, ErrorLongMessage)
{
Report report;
std::string long_msg(1500, 'e');
try {
report.error(997, "err: {}", long_msg);
FAIL();
} catch (const ExceptionMsg &e) {
std::string what = e.what();
EXPECT_NE(what.find("err:"), std::string::npos);
EXPECT_NE(what.find(long_msg), std::string::npos);
}
}
// Report: fileError with long message
TEST(ReportCovTest, FileErrorLongMessage)
{
Report report;
std::string long_msg(1500, 'x');
try {
report.fileError(996, "big.sdc", 50, "detail: {}", long_msg);
FAIL();
} catch (const ExceptionMsg &e) {
std::string what = e.what();
EXPECT_NE(what.find("big.sdc"), std::string::npos);
EXPECT_NE(what.find("line 50"), std::string::npos);
}
}
////////////////////////////////////////////////////////////////
// ReportStd coverage tests
////////////////////////////////////////////////////////////////
TEST(ReportStdCovTest, MakeReportStd)
{
Report *report = makeReportStd();
EXPECT_NE(report, nullptr);
// printConsole and printErrorConsole are called through reportLine/warn/error
report->reportLine("test output from ReportStd");
delete report;
}
TEST(ReportStdCovTest, ReportStdWarn)
{
Report *report = makeReportStd();
report->redirectStringBegin();
report->warn(999, "ReportStd warn test");
const char *result = report->redirectStringEnd();
EXPECT_NE(std::string(result).find("Warning"), std::string::npos);
delete report;
}
TEST(ReportStdCovTest, ReportStdError)
{
Report *report = makeReportStd();
try {
report->error(999, "ReportStd error test");
FAIL();
} catch (const ExceptionMsg &e) {
EXPECT_NE(std::string(e.what()).find("ReportStd error test"), std::string::npos);
}
delete report;
}
TEST(ReportStdCovTest, PrintConsoleDirect)
{
ASSERT_NO_THROW(( [&](){
Report *report = makeReportStd();
// reportLine calls printConsole
report->reportLine("direct console print test");
// printError calls printErrorConsole - triggered by warn
report->warn(998, "stderr test");
delete report;
}() ));
}
////////////////////////////////////////////////////////////////
// DispatchQueue coverage tests
////////////////////////////////////////////////////////////////
TEST(DispatchQueueCovTest, GetThreadCount)
{
DispatchQueue dq(2);
EXPECT_EQ(dq.getThreadCount(), 2u);
}
TEST(DispatchQueueCovTest, DispatchConstRef)
{
DispatchQueue dq(1);
std::atomic<int> counter(0);
std::function<void(int)> task = [&counter](int) { counter++; };
dq.dispatch(task);
dq.finishTasks();
EXPECT_EQ(counter.load(), 1);
}
TEST(DispatchQueueCovTest, DispatchMultiple)
{
DispatchQueue dq(2);
std::atomic<int> counter(0);
for (int i = 0; i < 10; i++) {
dq.dispatch([&counter](int) { counter++; });
}
dq.finishTasks();
EXPECT_EQ(counter.load(), 10);
}
////////////////////////////////////////////////////////////////
// ExceptionLine coverage test
////////////////////////////////////////////////////////////////
TEST(ExceptionCovTest, FileNotReadable)
{
FileNotReadable ex("testfile.cc");
const char *msg = ex.what();
EXPECT_NE(msg, nullptr);
}
TEST(ExceptionCovTest, FileNotWritable)
{
FileNotWritable ex("testfile.cc");
const char *msg = ex.what();
EXPECT_NE(msg, nullptr);
}
// Concrete subclass to test ExceptionLine (which is abstract)
class TestExceptionLine : public ExceptionLine
{
public:
TestExceptionLine(const char *filename, int line)
: ExceptionLine(filename, line) {}
const char *what() const noexcept override { return "test exception line"; }
};
TEST(ExceptionCovTest, ExceptionLineConstructor)
{
TestExceptionLine ex("testfile.cc", 42);
EXPECT_STREQ(ex.what(), "test exception line");
}
////////////////////////////////////////////////////////////////
// RiseFall::asRiseFallBoth non-const coverage test
////////////////////////////////////////////////////////////////
TEST(TransitionCovTest, RiseFallNonConstAsRiseFallBoth)
{
// Non-const version of asRiseFallBoth
RiseFall *rf_rise = const_cast<RiseFall*>(RiseFall::rise());
const RiseFallBoth *rfb = rf_rise->asRiseFallBoth();
EXPECT_EQ(rfb, RiseFallBoth::rise());
RiseFall *rf_fall = const_cast<RiseFall*>(RiseFall::fall());
rfb = rf_fall->asRiseFallBoth();
EXPECT_EQ(rfb, RiseFallBoth::fall());
}
////////////////////////////////////////////////////////////////
// systemRunTime coverage test
////////////////////////////////////////////////////////////////
TEST(MachineCovTest, SystemRunTime)
{
double stime = systemRunTime();
EXPECT_GE(stime, 0.0);
}
////////////////////////////////////////////////////////////////
// Stats coverage test
////////////////////////////////////////////////////////////////
TEST(StatsCovTest, StatsConstructAndReport)
{
ASSERT_NO_THROW(( [&](){
Report report;
Debug debug(&report);
// With debug stats level 0, constructor/report are no-ops
Stats stats(&debug, &report);
stats.report("test step");
// With debug stats level > 0, constructor records timing
debug.setLevel("stats", 1);
Stats stats2(&debug, &report);
stats2.report("test step 2");
}() ));
}
////////////////////////////////////////////////////////////////
// gzstream coverage tests (flush_buffer, overflow)
////////////////////////////////////////////////////////////////
} // namespace sta
#include "util/gzstream.hh"
namespace sta {
TEST(GzstreamCovTest, WriteGzFile)
{
// Writing to ogzstream triggers overflow() and flush_buffer()
const char *tmpgz = "/tmp/test_gzstream.gz";
{
gzstream::ogzstream gz(tmpgz);
ASSERT_TRUE(gz.rdbuf()->is_open());
gz << "hello gzstream test line\n";
// Write enough data to trigger overflow
for (int i = 0; i < 100; i++) {
gz << "line " << i << " padding data for buffer overflow test\n";
}
}
// Read back to verify
{
gzstream::igzstream gz(tmpgz);
ASSERT_TRUE(gz.rdbuf()->is_open());
std::string line;
std::getline(gz, line);
EXPECT_EQ(line, "hello gzstream test line");
}
std::remove(tmpgz);
}
TEST(GzstreamCovTest, FlushExplicit)
{
ASSERT_NO_THROW(( [&](){
const char *tmpgz = "/tmp/test_gzstream_flush.gz";
{
gzstream::ogzstream gz(tmpgz);
gz << "flush test data";
gz.flush(); // This triggers sync() -> flush_buffer()
}
std::remove(tmpgz);
}() ));
}
////////////////////////////////////////////////////////////////
// RiseFallMinMax copy constructor and setValue(float)
////////////////////////////////////////////////////////////////
TEST(RiseFallMinMaxCovTest, CopyConstructor)
{
RiseFallMinMax orig;
orig.setValue(RiseFallBoth::rise(), MinMaxAll::max(), 1.5f);
orig.setValue(RiseFallBoth::fall(), MinMaxAll::min(), 0.5f);
RiseFallMinMax copy(&orig);
float val;
bool exists;
copy.value(RiseFall::rise(), MinMax::max(), val, exists);
EXPECT_TRUE(exists);
EXPECT_FLOAT_EQ(val, 1.5f);
copy.value(RiseFall::fall(), MinMax::min(), val, exists);
EXPECT_TRUE(exists);
EXPECT_FLOAT_EQ(val, 0.5f);
}
TEST(RiseFallMinMaxCovTest, SetValueFloat)
{
RiseFallMinMax rfmm;
rfmm.setValue(3.14f);
// All four combinations should have the value
float val;
bool exists;
rfmm.value(RiseFall::rise(), MinMax::min(), val, exists);
EXPECT_TRUE(exists);
EXPECT_FLOAT_EQ(val, 3.14f);
rfmm.value(RiseFall::rise(), MinMax::max(), val, exists);
EXPECT_TRUE(exists);
EXPECT_FLOAT_EQ(val, 3.14f);
rfmm.value(RiseFall::fall(), MinMax::min(), val, exists);
EXPECT_TRUE(exists);
EXPECT_FLOAT_EQ(val, 3.14f);
rfmm.value(RiseFall::fall(), MinMax::max(), val, exists);
EXPECT_TRUE(exists);
EXPECT_FLOAT_EQ(val, 3.14f);
}
////////////////////////////////////////////////////////////////
// PatternMatch: patternWildcards, patternMatchNoCase standalone
////////////////////////////////////////////////////////////////
TEST(PatternMatchFuncTest, PatternWildcards)
{
EXPECT_TRUE(patternWildcards("hel*lo"));
EXPECT_TRUE(patternWildcards("hel?lo"));
EXPECT_FALSE(patternWildcards("hello"));
EXPECT_FALSE(patternWildcards(""));
}
TEST(PatternMatchFuncTest, PatternMatchNoCaseFunc)
{
EXPECT_TRUE(patternMatchNoCase("hello", "hello", false));
EXPECT_TRUE(patternMatchNoCase("hello", "HELLO", true));
EXPECT_FALSE(patternMatchNoCase("hello", "HELLO", false));
EXPECT_TRUE(patternMatchNoCase("hel*", "HELLO", true));
EXPECT_FALSE(patternMatchNoCase("hel*", "HELLO", false));
}
TEST(PatternMatchFuncTest, EqualCaseNoCase)
{
// Test patternMatchNoCase with question marks
EXPECT_TRUE(patternMatchNoCase("h?llo", "HELLO", true));
EXPECT_FALSE(patternMatchNoCase("h?llo", "HELLO", false));
}
////////////////////////////////////////////////////////////////
// Transition: RiseFallBoth::matches(const Transition*) additional
// and Transition::asRiseFallBoth() const
////////////////////////////////////////////////////////////////
TEST(TransitionCovTest, TransitionAsRiseFallBothConst)
{
// Transition::asRiseFallBoth() const for various transitions
const RiseFallBoth *rfb_rise = Transition::rise()->asRiseFallBoth();
EXPECT_NE(rfb_rise, nullptr);
const RiseFallBoth *rfb_fall = Transition::fall()->asRiseFallBoth();
EXPECT_NE(rfb_fall, nullptr);
// Non-rise/fall transitions may return nullptr or different RiseFallBoth
Transition::tr0Z()->asRiseFallBoth(); // just call for coverage
Transition::tr1Z()->asRiseFallBoth();
}
////////////////////////////////////////////////////////////////
// Report: redirectStringPrint coverage
// This is called when printString is called during string redirect
////////////////////////////////////////////////////////////////
TEST(ReportCovTest, RedirectStringPrintCoverage)
{
Report report;
report.redirectStringBegin();
// printString during redirect calls redirectStringPrint
report.printString("hello ", 6);
report.printString("world", 5);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("hello "), std::string::npos);
EXPECT_NE(s.find("world"), std::string::npos);
}
////////////////////////////////////////////////////////////////
// ReportStd: printErrorConsole
// Called by warn/error which use printError path
////////////////////////////////////////////////////////////////
TEST(ReportStdCovTest, PrintErrorConsole)
{
ASSERT_NO_THROW(( [&](){
Report *report = makeReportStd();
// warn() outputs to stderr via printErrorConsole
report->warn(777, "testing stderr output");
// fileWarn also goes through printErrorConsole
report->fileWarn(778, "test.v", 1, "file warning test");
delete report;
}() ));
}
// Test Report redirectStringPrint with empty string
// Covers: Report::redirectStringPrint
TEST(ReportCovTest, RedirectStringPrintEmpty)
{
Report report;
report.redirectStringBegin();
report.printString("", 0);
const char *result = report.redirectStringEnd();
EXPECT_STREQ(result, "");
}
// Test Report redirectStringPrint with large string
TEST(ReportCovTest, RedirectStringPrintLarge)
{
Report report;
report.redirectStringBegin();
std::string large(500, 'A');
report.printString(large.c_str(), large.size());
const char *result = report.redirectStringEnd();
EXPECT_EQ(std::string(result), large);
}
// Test Report redirectStringPrint multiple times
TEST(ReportCovTest, RedirectStringPrintMultiple)
{
Report report;
report.redirectStringBegin();
report.printString("abc", 3);
report.printString("def", 3);
report.printString("ghi", 3);
const char *result = report.redirectStringEnd();
EXPECT_STREQ(result, "abcdefghi");
}
// Test Report::report with format args
// Covers: Report::report(std::string_view, Args&&...)
TEST(ReportCovTest, ReportFormatViaReport)
{
Report report;
report.redirectStringBegin();
// report() uses std::format style formatting
report.report("value={}", 42);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("value=42"), std::string::npos);
}
// Test Report::reportLineString
TEST(ReportCovTest, ReportLineString)
{
Report report;
report.redirectStringBegin();
report.reportLine("test line");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("test line"), std::string::npos);
}
// Test Report::reportLineString with std::string
TEST(ReportCovTest, ReportLineStringStd)
{
Report report;
report.redirectStringBegin();
std::string line = "std string line";
report.reportLine(line);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("std string line"), std::string::npos);
}
// Test Report::reportBlankLine
TEST(ReportCovTest, ReportBlankLine)
{
Report report;
report.redirectStringBegin();
report.reportBlankLine();
const char *result = report.redirectStringEnd();
// Blank line produces just a newline
EXPECT_STREQ(result, "\n");
}
// Test ReportStd constructor
// Covers: ReportStd::ReportStd()
TEST(ReportStdCovTest, ReportStdConstructor)
{
Report *report = makeReportStd();
EXPECT_NE(report, nullptr);
// Verify it's the default report
EXPECT_EQ(Report::defaultReport(), report);
delete report;
}
// Test ReportStd printErrorConsole via fileError
// Covers: ReportStd::printErrorConsole
TEST(ReportStdCovTest, PrintErrorConsoleViaWarn)
{
ASSERT_NO_THROW(( [&](){
Report *report = makeReportStd();
// warn uses printErrorConsole path
report->warn(9999, "test warning {}", 42);
delete report;
}() ));
}
// Test Report suppress/unsuppress messages
TEST(ReportCovTest, SuppressUnsuppress)
{
Report report;
EXPECT_FALSE(report.isSuppressed(100));
report.suppressMsgId(100);
EXPECT_TRUE(report.isSuppressed(100));
report.unsuppressMsgId(100);
EXPECT_FALSE(report.isSuppressed(100));
}
// Test Report suppressed warn is silent
TEST(ReportCovTest, SuppressedWarn)
{
Report report;
report.suppressMsgId(200);
report.redirectStringBegin();
report.warn(200, "this should be suppressed");
const char *result = report.redirectStringEnd();
// Suppressed message should not appear
EXPECT_STREQ(result, "");
}
// Test Report logBegin/logEnd
TEST(ReportCovTest, LogBeginEnd)
{
Report report;
const char *logfile = "/tmp/sta_test_log_r5.log";
report.logBegin(logfile);
report.report("log line {}", 1);
report.logEnd();
// Verify log file exists and has content
std::ifstream in(logfile);
EXPECT_TRUE(in.is_open());
std::string line;
std::getline(in, line);
EXPECT_NE(line.find("log line 1"), std::string::npos);
in.close();
std::remove(logfile);
}
// Test Report redirectFileBegin/redirectFileEnd
TEST(ReportCovTest, RedirectFileBeginEnd)
{
Report report;
const char *tmpfile = "/tmp/sta_test_redirect_r5.txt";
report.redirectFileBegin(tmpfile);
report.reportLine("redirected line");
report.redirectFileEnd();
std::ifstream in(tmpfile);
EXPECT_TRUE(in.is_open());
std::string line;
std::getline(in, line);
EXPECT_NE(line.find("redirected line"), std::string::npos);
in.close();
std::remove(tmpfile);
}
// Test Report redirectFileAppendBegin
TEST(ReportCovTest, RedirectFileAppendBegin)
{
Report report;
const char *tmpfile = "/tmp/sta_test_append_r5.txt";
// Write initial content
report.redirectFileBegin(tmpfile);
report.reportLine("line1");
report.redirectFileEnd();
// Append
report.redirectFileAppendBegin(tmpfile);
report.reportLine("line2");
report.redirectFileEnd();
std::ifstream in(tmpfile);
EXPECT_TRUE(in.is_open());
std::string line;
std::getline(in, line);
EXPECT_NE(line.find("line1"), std::string::npos);
std::getline(in, line);
EXPECT_NE(line.find("line2"), std::string::npos);
in.close();
std::remove(tmpfile);
}
// Test gzstreambuf basic operations
// Covers: gzstreambuf::~gzstreambufD0Ev (virtual destructor)
TEST(GzStreamTest, GzStreamBufConstruction)
{
// Test igzstream with a non-existent file
gzstream::igzstream stream;
EXPECT_FALSE(stream.is_open());
}
// Test gzstreambuf with actual gz file
TEST(GzStreamTest, GzStreamWriteRead)
{
const char *tmpfile = "/tmp/sta_test_gz_r5.gz";
// Write
{
gzstream::ogzstream out(tmpfile);
EXPECT_TRUE(out.rdbuf()->is_open());
out << "hello gz world" << std::endl;
}
// Read
{
gzstream::igzstream in(tmpfile);
EXPECT_TRUE(in.is_open());
std::string line;
std::getline(in, line);
EXPECT_EQ(line, "hello gz world");
}
std::remove(tmpfile);
}
// Test Report error throws ExceptionMsg
TEST(ReportCovTest, ErrorThrowsException)
{
Report report;
EXPECT_THROW(report.error(1, "test error {}", "msg"), ExceptionMsg);
}
// Test Report fileError throws ExceptionMsg
TEST(ReportCovTest, FileErrorThrowsException)
{
Report report;
EXPECT_THROW(report.fileError(1, "test.v", 10, "file error"), ExceptionMsg);
}
// Test Report verror throws ExceptionMsg
TEST(ReportCovTest, VerrorThrowsException)
{
Report report;
EXPECT_THROW(report.error(1, "verror test"), ExceptionMsg);
}
////////////////////////////////////////////////////////////////
// R6_ tests for Util function coverage
////////////////////////////////////////////////////////////////
// Test Report::critical calls exit (we can't test exit directly,
// but we can test that the function exists and the format works)
// Covers: Report::critical - we test via Report::error which shares formatting
TEST(ReportCovTest, ReportErrorFormatting)
{
Report report;
try {
report.error(999, "critical format test {} {}", "value", 42);
FAIL();
} catch (const ExceptionMsg &e) {
std::string what = e.what();
EXPECT_NE(what.find("critical format test value 42"), std::string::npos);
}
}
// Test Report::fileCritical via fileError (shares code path)
// Covers: Report::fileCritical formatting path
TEST(ReportCovTest, ReportFileErrorFormatting)
{
Report report;
try {
report.fileError(998, "critical.v", 42, "critical file error {}", "detail");
FAIL();
} catch (const ExceptionMsg &e) {
std::string what = e.what();
EXPECT_NE(what.find("critical.v"), std::string::npos);
EXPECT_NE(what.find("line 42"), std::string::npos);
EXPECT_NE(what.find("critical file error detail"), std::string::npos);
}
}
// Test Report D0 destructor through base pointer
// Covers: Report::~Report() D0
TEST(ReportCovTest, ReportD0Destructor)
{
Report *report = new Report();
EXPECT_NE(report, nullptr);
delete report;
// No crash = D0 destructor works
}
// Test ReportStd creation via makeReportStd
// Covers: ReportStd::ReportStd constructor, makeReportStd
TEST(ReportCovTest, ReportStdCreation)
{
Report *report = makeReportStd();
ASSERT_NE(report, nullptr);
// Verify it works as a Report
report->redirectStringBegin();
report->reportLine("test via ReportStd");
const char *result = report->redirectStringEnd();
EXPECT_NE(result, nullptr);
std::string s(result);
EXPECT_NE(s.find("test via ReportStd"), std::string::npos);
delete report;
}
// Test ReportStd warn output
// Covers: ReportStd::printErrorConsole (indirectly via warn)
TEST(ReportCovTest, ReportStdWarn)
{
Report *report = makeReportStd();
ASSERT_NE(report, nullptr);
report->redirectStringBegin();
report->warn(700, "reportstd warn test {}", 99);
const char *result = report->redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 700:"), std::string::npos);
EXPECT_NE(s.find("reportstd warn test 99"), std::string::npos);
delete report;
}
// Test ReportStd error
// Covers: ReportStd error path
TEST(ReportCovTest, ReportStdError)
{
Report *report = makeReportStd();
ASSERT_NE(report, nullptr);
EXPECT_THROW(report->error(700, "reportstd error test"), ExceptionMsg);
delete report;
}
// Test Report printToBuffer with long format (indirectly via reportLine)
// Covers: Report::printToBuffer buffer growth
TEST(ReportCovTest, ReportPrintToBufferLong)
{
Report report;
report.redirectStringBegin();
// Create a string exceeding the initial 1000-char buffer
std::string long_str(3000, 'Z');
report.reportLine(long_str);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find(long_str), std::string::npos);
}
// Test Report redirectStringPrint indirectly via redirectStringBegin/End
// Covers: Report::redirectStringPrint
TEST(ReportCovTest, RedirectStringPrint)
{
Report report;
report.redirectStringBegin();
// printString calls redirectStringPrint when redirect_to_string_ is true
report.printString("direct string data", 18);
const char *result = report.redirectStringEnd();
EXPECT_STREQ(result, "direct string data");
}
// Test Report multiple printString calls during redirect
// Covers: Report::redirectStringPrint concatenation
TEST(ReportCovTest, RedirectStringPrintMultiple2)
{
Report report;
report.redirectStringBegin();
report.printString("part1", 5);
report.printString("part2", 5);
report.printString("part3", 5);
const char *result = report.redirectStringEnd();
EXPECT_STREQ(result, "part1part2part3");
}
// Test gzstreambuf D0 destructor through gzstream objects
// Covers: gzstreambuf::~gzstreambuf() D0
TEST(GzStreamCovTest, GzStreamBufD0Destructor)
{
const char *tmpfile = "/tmp/test_gz_d0.gz";
{
// Create and destroy to exercise D0 destructor
gzstream::ogzstream *out = new gzstream::ogzstream(tmpfile);
*out << "test data" << std::endl;
delete out; // triggers D0 destructor for gzstreambuf
}
{
gzstream::igzstream *in = new gzstream::igzstream(tmpfile);
std::string line;
std::getline(*in, line);
EXPECT_EQ(line, "test data");
delete in; // triggers D0 destructor for gzstreambuf
}
std::remove(tmpfile);
}
// Test Report suppress and unsuppress multiple IDs
// Covers: Report::suppressMsgId, unsuppressMsgId
TEST(ReportCovTest, SuppressMultipleIds)
{
Report report;
report.suppressMsgId(1);
report.suppressMsgId(2);
report.suppressMsgId(3);
EXPECT_TRUE(report.isSuppressed(1));
EXPECT_TRUE(report.isSuppressed(2));
EXPECT_TRUE(report.isSuppressed(3));
EXPECT_FALSE(report.isSuppressed(4));
report.unsuppressMsgId(2);
EXPECT_TRUE(report.isSuppressed(1));
EXPECT_FALSE(report.isSuppressed(2));
EXPECT_TRUE(report.isSuppressed(3));
}
// Test Report warn with long message that exceeds buffer
// Covers: Report::printToBuffer buffer reallocation
TEST(ReportCovTest, WarnLongMessage)
{
Report report;
report.redirectStringBegin();
std::string long_msg(5000, 'W');
report.warn(800, "{}", long_msg);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 800:"), std::string::npos);
EXPECT_NE(s.find(long_msg), std::string::npos);
}
// Test Report fileWarn with long message
// Covers: Report::printToBuffer via fileWarn
TEST(ReportCovTest, FileWarnLongMessage2)
{
Report report;
report.redirectStringBegin();
std::string long_msg(2000, 'F');
report.fileWarn(801, "long_file.v", 999, "{}", long_msg);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning 801:"), std::string::npos);
EXPECT_NE(s.find("long_file.v"), std::string::npos);
EXPECT_NE(s.find(long_msg), std::string::npos);
}
// Test Report error with suppressed flag
// Covers: ExceptionMsg suppression
TEST(ReportCovTest, ErrorSuppressed)
{
Report report;
report.suppressMsgId(900);
try {
report.error(900, "suppressed error");
FAIL();
} catch (const ExceptionMsg &e) {
EXPECT_TRUE(e.suppressed());
}
}
// Test Report error without suppression
// Covers: ExceptionMsg non-suppression
TEST(ReportCovTest, ErrorNotSuppressed)
{
Report report;
try {
report.error(901, "not suppressed error");
FAIL();
} catch (const ExceptionMsg &e) {
EXPECT_FALSE(e.suppressed());
}
}
////////////////////////////////////////////////////////////////
// R8_ tests for UTIL module coverage improvement
////////////////////////////////////////////////////////////////
// Test Report::critical throws/exits
// Covers: Report::critical(int, const char*, ...)
// Note: critical() calls abort(), so we test it carefully
// We can only test that the function exists and is callable through
// other paths. The critical() function cannot be directly tested
// because it calls abort(). Instead, test printToBuffer and
// redirectStringPrint paths.
// Test Report::report with multiple format args
// Covers: Report::report(std::string_view, Args&&...)
TEST(ReportCovTest, ReportFormatViaReport2)
{
Report report;
report.redirectStringBegin();
report.report("test {} {} {:.2f}", 42, "hello", 3.14);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("42"), std::string::npos);
EXPECT_NE(s.find("hello"), std::string::npos);
EXPECT_NE(s.find("3.14"), std::string::npos);
}
// Test Report::redirectStringPrint via redirectStringBegin/End
// Covers: Report::redirectStringPrint(const char*, size_t)
TEST(ReportCovTest, RedirectStringPrint2)
{
Report report;
report.redirectStringBegin();
report.reportLine("line 1");
report.reportLine("line 2");
report.reportLine("line 3");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("line 1"), std::string::npos);
EXPECT_NE(s.find("line 2"), std::string::npos);
EXPECT_NE(s.find("line 3"), std::string::npos);
}
// Test Report::redirectStringPrint with long string
// Covers: Report::redirectStringPrint(const char*, size_t)
TEST(ReportCovTest, RedirectStringPrintLong)
{
Report report;
report.redirectStringBegin();
std::string long_str(5000, 'X');
report.reportLine(long_str);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("XXXXX"), std::string::npos);
}
// Test Report::report with various format strings
// Covers: Report::report(std::string_view, Args&&...)
TEST(ReportCovTest, ReportFormatVariousFormats)
{
Report report;
report.redirectStringBegin();
// Exercise various std::format specifiers
report.report("int: {}", 12345);
report.report("float: {}", 1.5);
report.report("string: {}", "test_string");
report.report("hex: {:x}", 0xFF);
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("12345"), std::string::npos);
EXPECT_NE(s.find("test_string"), std::string::npos);
}
// Test ReportStd constructor and printErrorConsole
// Covers: ReportStd::ReportStd(), ReportStd::printErrorConsole
TEST(ReportStdCovTest, ReportStdConstructorAndPrint)
{
Report *report = makeReportStd();
ASSERT_NE(report, nullptr);
// warn() calls printErrorConsole
report->warn(10001, "R8 test warning {}", "message");
// reportLine calls printConsole
report->report("R8 test print {}", 42);
delete report;
}
// Test ReportStd printErrorConsole through fileWarn
// Covers: ReportStd::printErrorConsole(const char*, size_t)
TEST(ReportStdCovTest, PrintErrorConsoleViaFileWarn)
{
Report *report = makeReportStd();
ASSERT_NE(report, nullptr);
report->fileWarn(10002, "test_file.v", 100, "file warning {}", 99);
delete report;
}
// Test Report::printToBuffer with empty format
// Covers: Report::printToBuffer
TEST(ReportCovTest, PrintToBufferEmpty)
{
Report report;
report.redirectStringBegin();
report.reportLine("");
const char *result = report.redirectStringEnd();
// Should have at least a newline
EXPECT_NE(result, nullptr);
}
// Test Report warn with redirect
// Covers: Report::printToBuffer, Report::redirectStringPrint
TEST(ReportCovTest, WarnWithRedirect)
{
Report report;
report.redirectStringBegin();
report.warn(10003, "warning {}: {}", 1, "test");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning"), std::string::npos);
EXPECT_NE(s.find("test"), std::string::npos);
}
// Test Report fileWarn with redirect
// Covers: Report::printToBuffer, Report::redirectStringPrint
TEST(ReportCovTest, FileWarnWithRedirect)
{
Report report;
report.redirectStringBegin();
report.fileWarn(10004, "myfile.tcl", 42, "file issue {}", "here");
const char *result = report.redirectStringEnd();
std::string s(result);
EXPECT_NE(s.find("Warning"), std::string::npos);
EXPECT_NE(s.find("myfile.tcl"), std::string::npos);
}
// Test gzstream write and read
// Covers: gzstreambuf (exercises gzstream I/O paths)
TEST(GzStreamTest, WriteAndReadGz)
{
const char *tmpfile = "/tmp/test_r8_gzstream.gz";
{
gzstream::ogzstream out(tmpfile);
ASSERT_TRUE(out.good());
out << "test line 1\n";
out << "test line 2\n";
out.close();
}
{
gzstream::igzstream in(tmpfile);
ASSERT_TRUE(in.good());
std::string line1, line2;
std::getline(in, line1);
std::getline(in, line2);
EXPECT_EQ(line1, "test line 1");
EXPECT_EQ(line2, "test line 2");
in.close();
}
std::remove(tmpfile);
}
} // namespace sta
|