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
|
/*
* Copyright (C) 2013 Intel Corporation
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Tristan Van Berkom <tristanvb@openismus.com>
*/
#include "evolution-data-server-config.h"
#include <libebook/libebook.h>
#include "e-test-server-utils.h"
#include "client-test-utils.h"
#include "e-dbus-localed.h"
/* Filter which tests we want to try with a regexp */
static GRegex *test_regex = NULL;
static gchar *test_filter = NULL;
static GOptionEntry entries[] = {
{ "filter", 'f', 0, G_OPTION_ARG_STRING, &test_filter,
"A regular expression to filter which tests should be added", NULL },
{ NULL }
};
/* This is based on the sorted-%02d.vcf contacts from 1-20,
* a full table describing the expected order under various
* locales can be found in tests/libedata-book/data-test-utils.h
*/
#define N_SORTED_CONTACTS 20
/* 13 contacts in the test data have an email address ending with ".com" */
#define N_FILTERED_CONTACTS 13
/* How long to wait before aborting an async test */
#define TIMEOUT 30 * 1000
/* Standard number of iterations for a parallelized operation */
#define THREAD_ITERATIONS 20
/* Number of threads to use in the concurrent thread tests */
#define CONCURRENT_THREADS 5
typedef struct _CursorClosure CursorClosure;
typedef struct _CursorFixture CursorFixture;
typedef enum _CursorTestType CursorTestType;
typedef struct _CursorTest CursorTest;
typedef struct _CursorThread CursorThread;
typedef struct _CursorThreadTest CursorThreadTest;
typedef struct _CursorParams CursorParams;
typedef void (*CursorThreadFunc) (CursorFixture *fixture,
CursorClosure *closure,
CursorThread *thread,
gpointer user_data);
/* Main Cursor Test Fixture */
static void cursor_fixture_setup (CursorFixture *fixture,
gconstpointer user_data);
static void cursor_fixture_teardown (CursorFixture *fixture,
gconstpointer user_data);
static void cursor_fixture_set_locale (CursorFixture *fixture,
const gchar *locale);
static void cursor_fixture_timeout_start (CursorFixture *fixture,
const gchar *error_message);
static void cursor_fixture_timeout_cancel (CursorFixture *fixture);
/* Main Cursor Test Closure */
static CursorClosure *cursor_closure_new (CursorParams *params,
const gchar *locale);
static void cursor_closure_free (CursorClosure *closure);
static void cursor_test_free (CursorTest *test);
static void cursor_closure_add (CursorClosure *closure,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
/* Move By Tests */
static void cursor_closure_step (CursorClosure *closure,
EBookCursorStepFlags flags,
EBookCursorOrigin origin,
gint count,
gint expected,
...);
static void cursor_test_step (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test);
static void cursor_test_step_free (CursorTest *test);
/* Set Sexp Tests */
static void cursor_closure_set_sexp (CursorClosure *closure,
EBookQuery *query);
static void cursor_test_set_sexp (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test);
static void cursor_test_set_sexp_free (CursorTest *test);
/* Position Tests */
static void cursor_closure_position (CursorClosure *closure,
gint total,
gint position,
gboolean immediate);
static void cursor_test_position (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test);
static void cursor_test_position_free (CursorTest *test);
/* Add / Remove Tests */
static void cursor_closure_add_contact (CursorClosure *closure,
const gchar *case_name);
static void cursor_closure_remove_contact (CursorClosure *closure,
const gchar *case_name);
static void cursor_test_add_remove (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test);
static void cursor_test_add_remove_free (CursorTest *test);
/* Alphabet Index Tests */
static void cursor_closure_alphabet_index (CursorClosure *closure,
gint index);
static void cursor_test_alphabet_index (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test);
static void cursor_test_alphabet_index_free (CursorTest *test);
/* Change Locale Tests */
static void cursor_closure_change_locale (CursorClosure *closure,
const gchar *locale);
static void cursor_test_change_locale (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test);
static void cursor_test_change_locale_free (CursorTest *test);
/* Alphabet Tests */
static void cursor_closure_alphabet (CursorClosure *closure,
gboolean immediate,
const gchar *letter0,
const gchar *letter1,
const gchar *letter2,
const gchar *letter3,
const gchar *letter4);
static void cursor_test_alphabet (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test);
static void cursor_test_alphabet_free (CursorTest *test);
/* Thread Tests */
static CursorThread *cursor_closure_thread (CursorClosure *closure,
gboolean create_cursor,
const gchar *format,
...) G_GNUC_PRINTF (3, 4);
static void cursor_test_thread (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test);
static void cursor_test_thread_free (CursorTest *test);
static void cursor_thread_add_test (CursorThread *thread,
CursorThreadFunc test_func,
gpointer data,
GDestroyNotify destroy_data);
/* Thread Join Tests */
static void cursor_closure_thread_join (CursorClosure *closure,
CursorThread *thread);
static void cursor_test_thread_join (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test);
static void cursor_test_thread_join_free (CursorTest *test);
/* Spinning the main loop */
static void cursor_closure_spin_loop (CursorClosure *closure,
guint ms);
static void cursor_test_spin_loop (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test);
static void cursor_test_spin_loop_free (CursorTest *test);
struct _CursorFixture {
ETestServerFixture parent_fixture;
EBookClientCursor *cursor;
EContact *contacts[N_SORTED_CONTACTS];
EBookQuery *query;
GSource *timeout_source;
EDBusLocale1 *locale1;
guint own_id;
};
struct _CursorClosure {
ETestServerClosure parent_closure;
gchar *locale;
gboolean async;
GList *tests;
};
enum _CursorTestType {
CURSOR_TEST_STEP,
CURSOR_TEST_SET_SEXP,
CURSOR_TEST_POSITION,
CURSOR_TEST_ADD_REMOVE,
CURSOR_TEST_ALPHABET_INDEX,
CURSOR_TEST_CHANGE_LOCALE,
CURSOR_TEST_ALPHABET,
CURSOR_TEST_THREAD,
CURSOR_TEST_THREAD_JOIN,
CURSOR_TEST_SPIN_LOOP
};
struct _CursorTest {
CursorTestType type;
};
/******************************************************
* Main Cursor Test Fixture *
******************************************************/
#define N_SORT_FIELDS 2
static EContactField sort_fields[] = { E_CONTACT_FAMILY_NAME, E_CONTACT_GIVEN_NAME };
static EBookCursorSortType sort_types[] = { E_BOOK_CURSOR_SORT_ASCENDING, E_BOOK_CURSOR_SORT_ASCENDING };
struct _CursorParams {
const gchar *base_path;
gboolean async;
gboolean dra;
gboolean empty_summary;
};
static gboolean
cursor_timeout (const gchar *error_message)
{
g_error ("%s", error_message);
return FALSE;
}
static void
timeout_start (GMainContext *context,
GSource **source,
const gchar *error_message)
{
g_assert_true (source && *source == NULL);
if (!context)
context = g_main_context_default ();
*source = g_timeout_source_new (TIMEOUT);
g_source_set_callback (
*source, (GSourceFunc) cursor_timeout,
g_strdup (error_message),
(GDestroyNotify) g_free);
g_source_attach (*source, context);
}
static void
timeout_cancel (GSource **source)
{
g_assert_true (source && *source != NULL);
g_source_destroy (*source);
g_source_unref (*source);
*source = NULL;
}
static void
cursor_fixture_timeout_start (CursorFixture *fixture,
const gchar *error_message)
{
timeout_start (NULL, &fixture->timeout_source, error_message);
}
static void
cursor_fixture_timeout_cancel (CursorFixture *fixture)
{
timeout_cancel (&fixture->timeout_source);
}
static void
cursor_fixture_add_contacts (CursorFixture *fixture,
ETestServerClosure *closure)
{
EBookClient *book_client;
GError *error = NULL;
GSList *contacts = NULL;
gint i;
book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
for (i = 0; i < N_SORTED_CONTACTS; i++) {
gchar *case_name = g_strdup_printf ("sorted-%d", i + 1);
gchar *vcard;
EContact *contact;
vcard = new_vcard_from_test_case (case_name);
contact = e_contact_new_from_vcard (vcard);
contacts = g_slist_prepend (contacts, contact);
g_free (vcard);
g_free (case_name);
fixture->contacts[i] = contact;
}
if (!e_book_client_add_contacts_sync (book_client, contacts, E_BOOK_OPERATION_FLAG_NONE, NULL, NULL, &error)) {
/* Dont complain here, we re-use the same addressbook for multiple tests
* and we can't add the same contacts twice
*/
if (g_error_matches (error, E_BOOK_CLIENT_ERROR,
E_BOOK_CLIENT_ERROR_CONTACT_ID_ALREADY_EXISTS))
g_clear_error (&error);
else
g_error ("Failed to add test contacts: %s", error->message);
}
g_slist_free (contacts);
}
static void
cursor_ready_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
CursorFixture *fixture = (CursorFixture *) user_data;
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
GError *error = NULL;
if (!e_book_client_get_cursor_finish (E_BOOK_CLIENT (source_object),
result, &(fixture->cursor), &error))
g_error ("Failed to create a cursor: %s", error->message);
g_main_loop_quit (server_fixture->loop);
}
static void
cursor_fixture_setup (CursorFixture *fixture,
gconstpointer user_data)
{
CursorClosure *closure = (CursorClosure *) user_data;
ETestServerClosure *server_closure = (ETestServerClosure *) user_data;
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
EBookClient *book_client;
GError *error = NULL;
gchar *sexp = NULL;
e_test_server_utils_setup (server_fixture, user_data);
/* Set the initial locale before adding the contacts */
if (closure->locale)
cursor_fixture_set_locale (fixture, closure->locale);
else
cursor_fixture_set_locale (fixture, "en_US.UTF-8");
cursor_fixture_add_contacts (fixture, server_closure);
book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
/* Allow a surrounding fixture setup
* to add a query here
*/
if (fixture->query) {
sexp = e_book_query_to_string (fixture->query);
e_book_query_unref (fixture->query);
fixture->query = NULL;
}
if (server_closure->use_async_connect) {
e_book_client_get_cursor (
book_client,
sexp,
sort_fields,
sort_types,
N_SORT_FIELDS,
NULL,
cursor_ready_cb,
fixture);
cursor_fixture_timeout_start (fixture, "Timeout reached while trying to create a cursor");
g_main_loop_run (server_fixture->loop);
cursor_fixture_timeout_cancel (fixture);
} else {
if (!e_book_client_get_cursor_sync (book_client,
sexp,
sort_fields,
sort_types,
N_SORT_FIELDS,
&fixture->cursor,
NULL, &error))
g_error ("Failed to create a cursor with an empty query: %s", error->message);
}
g_free (sexp);
}
static void
cursor_fixture_teardown (CursorFixture *fixture,
gconstpointer user_data)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
gint i;
g_object_unref (fixture->cursor);
for (i = 0; i < N_SORTED_CONTACTS; i++) {
if (fixture->contacts[i])
g_clear_object (&(fixture->contacts[i]));
}
if (fixture->locale1)
g_object_unref (fixture->locale1);
if (fixture->own_id > 0)
g_bus_unown_name (fixture->own_id);
e_test_server_utils_teardown (server_fixture, user_data);
}
typedef struct {
CursorFixture *fixture;
const gchar *locale;
} ChangeLocaleData;
static void
book_client_locale_change (EBookClient *book,
GParamSpec *pspec,
ChangeLocaleData *data)
{
ETestServerFixture *base_fixture = (ETestServerFixture *) data->fixture;
if (!g_strcmp0 (e_book_client_get_locale (book), data->locale))
g_main_loop_quit (base_fixture->loop);
}
static void
cursor_fixture_set_locale (CursorFixture *fixture,
const gchar *locale)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
EBookClient *book_client;
ChangeLocaleData data = { fixture, locale };
gulong handler_id;
gchar *strv[2] = { NULL, NULL };
book_client = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
/* We're already in the right locale */
if (g_strcmp0 (locale, e_book_client_get_locale (book_client)) == 0)
return;
if (!fixture->locale1) {
GDBusConnection *bus;
GError *error = NULL;
/* We use the 'org.freedesktop.locale1 on the session bus instead
* of the system bus only for testing purposes... in real life
* this service is on the system bus.
*/
bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (!bus)
g_error ("Failed to get system bus: %s", error->message);
fixture->locale1 = e_dbus_locale1_skeleton_new ();
/* Set initial locale before exporting on the bus */
strv[0] = g_strdup_printf ("LANG=%s", locale);
e_dbus_locale1_set_locale (fixture->locale1, (const gchar * const *) strv);
g_free (strv[0]);
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (fixture->locale1),
bus, "/org/freedesktop/locale1", &error))
g_error ("Failed to export org.freedesktop.locale1: %s", error->message);
fixture->own_id =
g_bus_own_name_on_connection (
bus,
"org.freedesktop.locale1",
G_BUS_NAME_OWNER_FLAGS_REPLACE,
NULL, NULL, NULL, NULL);
g_object_unref (bus);
} else {
/* Send locale change message */
strv[0] = g_strdup_printf ("LANG=%s", locale);
e_dbus_locale1_set_locale (fixture->locale1, (const gchar * const *) strv);
g_free (strv[0]);
}
handler_id = g_signal_connect (
book_client, "notify::locale",
G_CALLBACK (book_client_locale_change), &data);
cursor_fixture_timeout_start (fixture, "Timeout reached while waiting for locale change");
g_main_loop_run (server_fixture->loop);
cursor_fixture_timeout_cancel (fixture);
g_signal_handler_disconnect (book_client, handler_id);
}
static void
cursor_fixture_test (CursorFixture *fixture,
gconstpointer user_data)
{
CursorClosure *closure = (CursorClosure *) user_data;
GList *l;
/* Run all the tests */
for (l = closure->tests; l; l = l->next) {
CursorTest *test = l->data;
switch (test->type) {
case CURSOR_TEST_STEP:
cursor_test_step (fixture, closure, test);
break;
case CURSOR_TEST_SET_SEXP:
cursor_test_set_sexp (fixture, closure, test);
break;
case CURSOR_TEST_POSITION:
cursor_test_position (fixture, closure, test);
break;
case CURSOR_TEST_ADD_REMOVE:
cursor_test_add_remove (fixture, closure, test);
break;
case CURSOR_TEST_ALPHABET_INDEX:
cursor_test_alphabet_index (fixture, closure, test);
break;
case CURSOR_TEST_CHANGE_LOCALE:
cursor_test_change_locale (fixture, closure, test);
break;
case CURSOR_TEST_ALPHABET:
cursor_test_alphabet (fixture, closure, test);
break;
case CURSOR_TEST_THREAD:
cursor_test_thread (fixture, closure, test);
break;
case CURSOR_TEST_THREAD_JOIN:
cursor_test_thread_join (fixture, closure, test);
break;
case CURSOR_TEST_SPIN_LOOP:
cursor_test_spin_loop (fixture, closure, test);
break;
}
}
}
/******************************************************
* Main Cursor Test Closure *
******************************************************/
static void
cursor_test_free (CursorTest *test)
{
switch (test->type) {
case CURSOR_TEST_STEP:
cursor_test_step_free (test);
break;
case CURSOR_TEST_SET_SEXP:
cursor_test_set_sexp_free (test);
break;
case CURSOR_TEST_POSITION:
cursor_test_position_free (test);
break;
case CURSOR_TEST_ADD_REMOVE:
cursor_test_add_remove_free (test);
break;
case CURSOR_TEST_ALPHABET_INDEX:
cursor_test_alphabet_index_free (test);
break;
case CURSOR_TEST_CHANGE_LOCALE:
cursor_test_change_locale_free (test);
break;
case CURSOR_TEST_ALPHABET:
cursor_test_alphabet_free (test);
break;
case CURSOR_TEST_THREAD:
cursor_test_thread_free (test);
break;
case CURSOR_TEST_THREAD_JOIN:
cursor_test_thread_join_free (test);
break;
case CURSOR_TEST_SPIN_LOOP:
cursor_test_spin_loop_free (test);
break;
}
}
static void
cursor_closure_free (CursorClosure *closure)
{
if (closure) {
g_list_free_full (closure->tests, (GDestroyNotify) cursor_test_free);
g_free (closure->locale);
g_slice_free (CursorClosure, closure);
}
}
static void
cursor_closure_setup_empty_summary (ESource *scratch,
ETestServerClosure *closure)
{
ESourceBackendSummarySetup *setup;
/* Setup the book for fallback mode, make sure the
* summary is empty to provoke the backend into enacting the fallback routines
*/
g_type_ensure (E_TYPE_SOURCE_BACKEND_SUMMARY_SETUP);
setup = e_source_get_extension (scratch, E_SOURCE_EXTENSION_BACKEND_SUMMARY_SETUP);
e_source_backend_summary_setup_set_summary_fields (
setup,
/* Just one boolean field */
E_CONTACT_WANTS_HTML,
0);
}
static CursorClosure *
cursor_closure_new (CursorParams *params,
const gchar *locale)
{
CursorClosure *closure = g_slice_new0 (CursorClosure);
ETestServerClosure *server_closure = (ETestServerClosure *) closure;
if (params->dra)
server_closure->type = E_TEST_SERVER_DIRECT_ADDRESS_BOOK;
else
server_closure->type = E_TEST_SERVER_ADDRESS_BOOK;
if (params->empty_summary)
server_closure->customize = cursor_closure_setup_empty_summary;
server_closure->use_async_connect = params->async;
server_closure->destroy_closure_func = (GDestroyNotify) cursor_closure_free;
closure->locale = g_strdup (locale);
closure->async = params->async;
return closure;
}
static void
cursor_closure_add (CursorClosure *closure,
const gchar *format,
...)
{
gchar *test_path;
va_list args;
va_start (args, format);
test_path = g_strdup_vprintf (format, args);
va_end (args);
/* Filter out anything that was not specified in the test filter */
if (test_regex == NULL ||
g_regex_match (test_regex, test_path, 0, NULL))
g_test_add (
test_path, CursorFixture, closure,
cursor_fixture_setup,
cursor_fixture_test,
cursor_fixture_teardown);
g_free (test_path);
}
/******************************************************
* Step Tests *
******************************************************/
typedef struct {
CursorTestType type;
EBookCursorStepFlags flags; /* The flags for this step */
EBookCursorOrigin origin; /* The origin to step from */
gint count; /* The amount of contacts to step the cursor by (positive or negative) */
gint expected; /* The amount of actual results expected */
gint expected_order[N_SORTED_CONTACTS]; /* The expected results */
} CursorTestStep;
typedef struct {
CursorFixture *fixture;
CursorTestStep *test;
gboolean out_of_sync;
} StepReadyData;
static gint
find_contact_link (EContact *contact,
const gchar *uid)
{
const gchar *contact_uid =
(const gchar *) e_contact_get_const (contact, E_CONTACT_UID);
return g_strcmp0 (contact_uid, uid);
}
static void
assert_contacts_order_slist (GSList *results,
GSList *uids)
{
gint position = -1;
GSList *link, *l;
/* Assert that all passed UIDs are found in the
* results, and that those UIDs are in the
* specified order.
*/
for (l = uids; l; l = l->next) {
const gchar *uid = l->data;
gint new_position;
link = g_slist_find_custom (results, uid, (GCompareFunc) find_contact_link);
if (!link)
g_error ("Specified uid '%s' was not found in results", uid);
new_position = g_slist_position (results, link);
g_assert_cmpint (new_position, >, position);
position = new_position;
}
}
static void
step_print_results (GSList *results,
GSList *uids)
{
GSList *l;
if (g_getenv ("TEST_DEBUG") == NULL)
return;
g_print ("\nPRINTING EXPECTED RESULTS:\n");
for (l = uids; l; l = l->next) {
gchar *uid = l->data;
g_print ("\t%s\n", uid);
}
g_print ("\nEXPECTED RESULTS FINISHED\n");
g_print ("\nPRINTING RESULTS:\n");
for (l = results; l; l = l->next) {
EContact *contact = l->data;
gchar *vcard = e_vcard_to_string (E_VCARD (contact), EVC_FORMAT_VCARD_30);
g_print ("\n%s\n", vcard);
g_free (vcard);
}
g_print ("\nRESULT LIST FINISHED\n");
}
static void
cursor_test_assert_results (CursorFixture *fixture,
CursorTestStep *test,
GSList *results,
gint n_reported_results)
{
GSList *uids = NULL;
gint i;
for (i = 0; i < test->expected; i++) {
gchar *uid;
gint index = test->expected_order[i];
uid = (gchar *) e_contact_get_const (fixture->contacts[index], E_CONTACT_UID);
uids = g_slist_append (uids, uid);
}
step_print_results (results, uids);
/* Assert the exact amount of requested results */
g_assert_cmpint (g_slist_length (results), ==, test->expected);
g_assert_cmpint (n_reported_results, ==, test->expected);
assert_contacts_order_slist (results, uids);
g_slist_free (uids);
}
static void
cursor_test_step_free (CursorTest *test)
{
CursorTestStep *step = (CursorTestStep *) test;
g_slice_free (CursorTestStep, step);
}
static void
cursor_test_step_ready_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
StepReadyData *data = (StepReadyData *) user_data;
ETestServerFixture *server_fixture = (ETestServerFixture *) data->fixture;
GSList *results = NULL;
gint n_reported_results;
gboolean end_of_list = FALSE;
GError *error = NULL;
n_reported_results =
e_book_client_cursor_step_finish (
E_BOOK_CLIENT_CURSOR (source_object),
result, &results, &error);
if (n_reported_results < 0) {
if (g_error_matches (error,
E_CLIENT_ERROR,
E_CLIENT_ERROR_OUT_OF_SYNC)) {
data->out_of_sync = TRUE;
g_clear_error (&error);
} else if (g_error_matches (error,
E_CLIENT_ERROR,
E_CLIENT_ERROR_QUERY_REFUSED)) {
end_of_list = TRUE;
g_clear_error (&error);
} else {
g_error (
"Error calling e_book_client_cursor_step_finish(): %s",
error->message);
}
}
if (!data->out_of_sync) {
if (data->test->expected < 0) {
g_assert_cmpint (n_reported_results, <, 0);
g_assert_cmpint (end_of_list, ==, TRUE);
} else
cursor_test_assert_results (data->fixture, data->test, results, n_reported_results);
}
g_slist_free_full (results, (GDestroyNotify) g_object_unref);
g_main_loop_quit (server_fixture->loop);
}
static gboolean
cursor_test_try_step (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
CursorTestStep *step = (CursorTestStep *) test;
gboolean out_of_sync = FALSE;
gboolean end_of_list = FALSE;
if (closure->async) {
StepReadyData data = { fixture, step, FALSE };
e_book_client_cursor_step (
fixture->cursor,
step->flags,
step->origin,
step->count,
NULL,
cursor_test_step_ready_cb,
&data);
/* Wait for result with an error timeout */
cursor_fixture_timeout_start (fixture, "Timeout reached while moving the cursor");
g_main_loop_run (server_fixture->loop);
cursor_fixture_timeout_cancel (fixture);
} else {
GError *error = NULL;
GSList *results = NULL;
gint n_reported_results;
n_reported_results =
e_book_client_cursor_step_sync (
fixture->cursor,
step->flags,
step->origin,
step->count,
&results,
NULL, &error);
if (n_reported_results < 0) {
if (g_error_matches (error,
E_CLIENT_ERROR,
E_CLIENT_ERROR_OUT_OF_SYNC)) {
out_of_sync = TRUE;
g_clear_error (&error);
} else if (g_error_matches (error,
E_CLIENT_ERROR,
E_CLIENT_ERROR_QUERY_REFUSED)) {
end_of_list = TRUE;
g_clear_error (&error);
} else {
g_error (
"Error calling e_book_client_cursor_step_sync(): %s",
error->message);
}
}
if (step->expected < 0) {
g_assert_cmpint (n_reported_results, <, 0);
g_assert_cmpint (end_of_list, ==, TRUE);
} else
cursor_test_assert_results (fixture, step, results, n_reported_results);
g_slist_free_full (results, g_object_unref);
}
return out_of_sync == FALSE;
}
static void
step_refreshed (EBookClientCursor *cursor,
GMainLoop *loop)
{
g_main_loop_quit (loop);
}
static void
cursor_test_step (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
gint i;
gboolean success = FALSE;
/* Should only ever really be once, but in practice code
* should be written to continually fallback until a synchronized
* step() call passes */
for (i = 0; i < 3 && success == FALSE; i++) {
gulong refresh_id;
/* Wait for a refresh which follows an out-of-sync move by */
refresh_id = g_signal_connect (
fixture->cursor, "refresh",
G_CALLBACK (step_refreshed),
server_fixture->loop);
/* Stop trying after the first step() is not out-of-sync */
success = cursor_test_try_step (fixture, closure, test);
if (!success) {
cursor_fixture_timeout_start (fixture, "Timeout reached while waiting for refresh event");
g_main_loop_run (server_fixture->loop);
cursor_fixture_timeout_cancel (fixture);
}
g_signal_handler_disconnect (fixture->cursor, refresh_id);
}
}
/* Expected is the number of expected results,
* the var args are the result indexes as
* listed in data-test-utils.h
*
* If expected is -1, then E_CLIENT_ERROR_QUERY_REFUSED
* is expected to be triggered by this step.
*/
static void
cursor_closure_step (CursorClosure *closure,
EBookCursorStepFlags flags,
EBookCursorOrigin origin,
gint count,
gint expected,
...)
{
CursorTestStep *test = g_slice_new0 (CursorTestStep);
va_list args;
gint i;
g_assert_true (expected <= N_SORTED_CONTACTS);
g_assert_true (ABS (count) <= N_SORTED_CONTACTS);
test->type = CURSOR_TEST_STEP;
test->flags = flags;
test->origin = origin;
test->count = count;
test->expected = expected;
va_start (args, expected);
for (i = 0; i < expected; i++) {
gint expected_position = va_arg (args, gint);
/* Sanity check while building the test case */
g_assert_cmpint (expected_position, >, 0);
test->expected_order[i] = expected_position - 1;
}
va_end (args);
closure->tests = g_list_append (closure->tests, test);
}
/******************************************************
* Set Sexp Tests *
******************************************************/
typedef struct {
CursorTestType type;
gchar *sexp;
} CursorTestSetSexp;
typedef struct {
CursorFixture *fixture;
CursorTestSetSexp *test;
} SetSexpReadyData;
static void
cursor_closure_set_sexp (CursorClosure *closure,
EBookQuery *query)
{
CursorTestSetSexp *test = g_slice_new0 (CursorTestSetSexp);
g_assert_true (query != NULL);
test->type = CURSOR_TEST_SET_SEXP;
test->sexp = e_book_query_to_string (query);
e_book_query_unref (query);
closure->tests = g_list_append (closure->tests, test);
}
static void
cursor_test_set_sexp_assert (CursorTestSetSexp *test,
gboolean success,
GError *error)
{
if (!success)
g_error (
"Failed to set sexp '%s': %s",
test->sexp, error->message);
}
static void
cursor_test_set_sexp_ready_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
SetSexpReadyData *data = (SetSexpReadyData *) user_data;
ETestServerFixture *server_fixture = (ETestServerFixture *) data->fixture;
gboolean success;
GError *error = NULL;
success = e_book_client_cursor_set_sexp_finish (
E_BOOK_CLIENT_CURSOR (source_object),
result, &error);
cursor_test_set_sexp_assert (data->test, success, error);
g_clear_error (&error);
g_main_loop_quit (server_fixture->loop);
}
static void
cursor_test_set_sexp (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
CursorTestSetSexp *set_sexp = (CursorTestSetSexp *) test;
if (closure->async) {
SetSexpReadyData data = { fixture, set_sexp };
e_book_client_cursor_set_sexp (
fixture->cursor,
set_sexp->sexp,
NULL,
cursor_test_set_sexp_ready_cb,
&data);
/* Wait for result with an error timeout */
cursor_fixture_timeout_start (fixture, "Timeout reached while setting search expression");
g_main_loop_run (server_fixture->loop);
cursor_fixture_timeout_cancel (fixture);
} else {
gboolean success;
GError *error = NULL;
success = e_book_client_cursor_set_sexp_sync (
fixture->cursor,
set_sexp->sexp,
NULL,
&error);
cursor_test_set_sexp_assert (set_sexp, success, error);
g_clear_error (&error);
}
}
static void
cursor_test_set_sexp_free (CursorTest *test)
{
CursorTestSetSexp *set_sexp = (CursorTestSetSexp *) test;
g_free (set_sexp->sexp);
g_slice_free (CursorTestSetSexp, set_sexp);
}
/******************************************************
* Position Tests *
******************************************************/
typedef struct {
CursorTestType type;
gint total;
gint position;
gboolean immediate;
gulong total_id;
gulong position_id;
} CursorTestPosition;
typedef struct {
CursorFixture *fixture;
CursorTestPosition *test;
} PositionData;
static void
cursor_closure_position (CursorClosure *closure,
gint total,
gint position,
gboolean immediate)
{
CursorTestPosition *test = g_slice_new0 (CursorTestPosition);
test->type = CURSOR_TEST_POSITION;
test->total = total;
test->position = position;
test->immediate = immediate;
closure->tests = g_list_append (closure->tests, test);
}
static void
position_or_total_changed (EBookClientCursor *cursor,
GParamSpec *pspec,
PositionData *data)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) data->fixture;
if (g_getenv ("TEST_DEBUG") != NULL) {
g_print (
"Position changed, total: %d position: %d (expecting total: %d position: %d)\n",
e_book_client_cursor_get_total (cursor),
e_book_client_cursor_get_position (cursor),
data->test->total,
data->test->position);
}
if (data->test->total == e_book_client_cursor_get_total (cursor) &&
data->test->position == e_book_client_cursor_get_position (cursor))
g_main_loop_quit (server_fixture->loop);
}
static void
cursor_test_position (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
CursorTestPosition *position = (CursorTestPosition *) test;
PositionData data = { fixture, position };
if (g_getenv ("TEST_DEBUG") != NULL) {
g_print (
"Actual total: %d position: %d, %s for total: %d position: %d\n",
e_book_client_cursor_get_total (fixture->cursor),
e_book_client_cursor_get_position (fixture->cursor),
position->immediate ? "Checking" : "Waiting",
position->total,
position->position);
}
/* If testing immediate mode, just assert the immediate position and don't wait for asynchronous updates*/
if (position->immediate) {
g_assert_cmpint (e_book_client_cursor_get_total (fixture->cursor), ==, position->total);
g_assert_cmpint (e_book_client_cursor_get_position (fixture->cursor), ==, position->position);
}
/* Position is already correct */
if (position->total == e_book_client_cursor_get_total (fixture->cursor) &&
position->position == e_book_client_cursor_get_position (fixture->cursor))
return;
/* Position & Total is notified asynchronously, connect to signals and
* timeout error if the correct position / total is never reached.
*/
position->total_id = g_signal_connect (
fixture->cursor, "notify::total",
G_CALLBACK (position_or_total_changed),
&data);
position->position_id = g_signal_connect (
fixture->cursor, "notify::position",
G_CALLBACK (position_or_total_changed),
&data);
cursor_fixture_timeout_start (fixture, "Timeout waiting for expected position and total");
g_main_loop_run (server_fixture->loop);
cursor_fixture_timeout_cancel (fixture);
g_signal_handler_disconnect (fixture->cursor, position->total_id);
g_signal_handler_disconnect (fixture->cursor, position->position_id);
}
static void
cursor_test_position_free (CursorTest *test)
{
CursorTestPosition *position = (CursorTestPosition *) test;
g_slice_free (CursorTestPosition, position);
}
/******************************************************
* Add / Remove Tests *
******************************************************/
typedef struct {
CursorTestType type;
gchar *case_name;
gboolean add;
} CursorTestAddRemove;
typedef struct {
CursorFixture *fixture;
CursorTestAddRemove *test;
EContact *contact;
} AddRemoveReadyData;
static void
cursor_closure_add_remove_contact (CursorClosure *closure,
const gchar *case_name,
gboolean add)
{
CursorTestAddRemove *test = g_slice_new0 (CursorTestAddRemove);
test->type = CURSOR_TEST_ADD_REMOVE;
test->case_name = g_strdup (case_name);
test->add = add;
closure->tests = g_list_append (closure->tests, test);
}
static void
cursor_closure_add_contact (CursorClosure *closure,
const gchar *case_name)
{
cursor_closure_add_remove_contact (closure, case_name, TRUE);
}
static void
cursor_closure_remove_contact (CursorClosure *closure,
const gchar *case_name)
{
cursor_closure_add_remove_contact (closure, case_name, FALSE);
}
static void
cursor_test_add_remove_ready_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
AddRemoveReadyData *data = (AddRemoveReadyData *) user_data;
ETestServerFixture *server_fixture = (ETestServerFixture *) data->fixture;
gchar *new_uid = NULL;
const gchar *contact_uid;
gboolean success;
GError *error = NULL;
if (data->test->add) {
success = e_book_client_add_contact_finish (
E_BOOK_CLIENT (source_object),
result, &new_uid, &error);
if (!success)
g_error ("Error adding contact: %s", error->message);
} else {
success = e_book_client_remove_contact_finish (
E_BOOK_CLIENT (source_object),
result, &error);
if (!success)
g_error ("Error adding contact: %s", error->message);
}
g_clear_error (&error);
if (data->test->add) {
contact_uid = e_contact_get_const (data->contact, E_CONTACT_UID);
if (contact_uid)
g_assert_cmpstr (contact_uid, ==, new_uid);
}
g_free (new_uid);
g_main_loop_quit (server_fixture->loop);
}
static void
cursor_test_add_remove (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
CursorTestAddRemove *modify = (CursorTestAddRemove *) test;
EBookClient *book_client;
EContact *contact;
gchar *vcard;
vcard = new_vcard_from_test_case (modify->case_name);
contact = e_contact_new_from_vcard (vcard);
g_free (vcard);
book_client = E_TEST_SERVER_UTILS_SERVICE (server_fixture, EBookClient);
if (closure->async) {
AddRemoveReadyData data = { fixture, modify, contact };
if (modify->add)
e_book_client_add_contact (
book_client, contact, E_BOOK_OPERATION_FLAG_NONE,
NULL, cursor_test_add_remove_ready_cb, &data);
else
e_book_client_remove_contact (
book_client, contact, E_BOOK_OPERATION_FLAG_NONE,
NULL, cursor_test_add_remove_ready_cb, &data);
/* Wait for result with an error timeout */
cursor_fixture_timeout_start (fixture, "Timeout reached while adding a contact");
g_main_loop_run (server_fixture->loop);
cursor_fixture_timeout_cancel (fixture);
} else {
gboolean success;
GError *error = NULL;
gchar *new_uid = NULL;
const gchar *contact_uid;
if (modify->add)
success = e_book_client_add_contact_sync (
book_client, contact, E_BOOK_OPERATION_FLAG_NONE,
&new_uid, NULL, &error);
else
success = e_book_client_remove_contact_sync (
book_client, contact, E_BOOK_OPERATION_FLAG_NONE,
NULL, &error);
if (!success)
g_error ("Error adding contact: %s", error->message);
g_clear_error (&error);
if (modify->add) {
contact_uid = e_contact_get_const (contact, E_CONTACT_UID);
if (contact_uid)
g_assert_cmpstr (contact_uid, ==, new_uid);
}
g_free (new_uid);
}
g_object_unref (contact);
}
static void
cursor_test_add_remove_free (CursorTest *test)
{
CursorTestAddRemove *modify = (CursorTestAddRemove *) test;
g_free (modify->case_name);
g_slice_free (CursorTestAddRemove, modify);
}
/******************************************************
* Alphabet Index Tests *
******************************************************/
typedef struct {
CursorTestType type;
gint index;
} CursorTestAlphabetIndex;
typedef struct {
CursorFixture *fixture;
CursorTestAlphabetIndex *test;
} AlphabetIndexReadyData;
static void
cursor_closure_alphabet_index (CursorClosure *closure,
gint index)
{
CursorTestAlphabetIndex *test = g_slice_new0 (CursorTestAlphabetIndex);
test->type = CURSOR_TEST_ALPHABET_INDEX;
test->index = index;
closure->tests = g_list_append (closure->tests, test);
}
static void
cursor_test_alphabet_index_ready_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
AlphabetIndexReadyData *data = (AlphabetIndexReadyData *) user_data;
ETestServerFixture *server_fixture = (ETestServerFixture *) data->fixture;
GError *error = NULL;
if (!e_book_client_cursor_set_alphabetic_index_finish (E_BOOK_CLIENT_CURSOR (source_object),
result, &error))
g_error ("Error setting alphabet index: %s", error->message);
g_main_loop_quit (server_fixture->loop);
}
static void
cursor_test_alphabet_index (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
CursorTestAlphabetIndex *alphabet_index = (CursorTestAlphabetIndex *) test;
if (closure->async) {
AlphabetIndexReadyData data = { fixture, alphabet_index };
e_book_client_cursor_set_alphabetic_index (
fixture->cursor, alphabet_index->index,
NULL, cursor_test_alphabet_index_ready_cb, &data);
/* Wait for result with an error timeout */
cursor_fixture_timeout_start (fixture, "Timeout reached while setting alphabet index");
g_main_loop_run (server_fixture->loop);
cursor_fixture_timeout_cancel (fixture);
} else {
GError *error = NULL;
if (!e_book_client_cursor_set_alphabetic_index_sync (fixture->cursor,
alphabet_index->index,
NULL, &error))
g_error ("Error setting alphabet index: %s", error->message);
}
}
static void
cursor_test_alphabet_index_free (CursorTest *test)
{
CursorTestAlphabetIndex *alphabet_index = (CursorTestAlphabetIndex *) test;
g_slice_free (CursorTestAlphabetIndex, alphabet_index);
}
/******************************************************
* Change Locale Tests *
******************************************************/
typedef struct {
CursorTestType type;
gchar *locale;
} CursorTestChangeLocale;
static void
cursor_closure_change_locale (CursorClosure *closure,
const gchar *locale)
{
CursorTestChangeLocale *test = g_slice_new0 (CursorTestChangeLocale);
test->type = CURSOR_TEST_CHANGE_LOCALE;
test->locale = g_strdup (locale);
closure->tests = g_list_append (closure->tests, test);
}
static void
cursor_test_change_locale (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
CursorTestChangeLocale *change_locale = (CursorTestChangeLocale *) test;
/* There is no sync/async for this */
cursor_fixture_set_locale (fixture, change_locale->locale);
}
static void
cursor_test_change_locale_free (CursorTest *test)
{
CursorTestChangeLocale *change_locale = (CursorTestChangeLocale *) test;
g_free (change_locale->locale);
g_slice_free (CursorTestChangeLocale, change_locale);
}
/******************************************************
* Alphabet Tests *
******************************************************/
#define ALPHABET_TEST_LETTERS 5
typedef struct {
CursorTestType type;
gchar *letters[ALPHABET_TEST_LETTERS];
gboolean immediate;
gulong alphabet_id;
} CursorTestAlphabet;
typedef struct {
CursorFixture *fixture;
CursorTestAlphabet *test;
} AlphabetData;
static void
cursor_closure_alphabet (CursorClosure *closure,
gboolean immediate,
const gchar *letter0,
const gchar *letter1,
const gchar *letter2,
const gchar *letter3,
const gchar *letter4)
{
CursorTestAlphabet *test = g_slice_new0 (CursorTestAlphabet);
test->type = CURSOR_TEST_ALPHABET;
test->immediate = immediate;
test->letters[0] = g_strdup (letter0);
test->letters[1] = g_strdup (letter1);
test->letters[2] = g_strdup (letter2);
test->letters[3] = g_strdup (letter3);
test->letters[4] = g_strdup (letter4);
closure->tests = g_list_append (closure->tests, test);
}
static gboolean
expected_alpabet_check (EBookClientCursor *cursor,
CursorTestAlphabet *test,
gboolean assert_letters)
{
const gchar * const * alphabet;
gint i, n_labels = 0;
gboolean expected = TRUE;
alphabet = e_book_client_cursor_get_alphabet (cursor, &n_labels, NULL, NULL, NULL);
for (i = 0; i < ALPHABET_TEST_LETTERS && expected; i++) {
/* We compare letters[i] with alphabet[i + 1]
* so 'i' must fit into 'n_labels - 2'
*/
if (test->letters[i] != NULL && i > (n_labels - 2)) {
if (assert_letters)
g_error ("Not enough letters in the expected alphabet");
else
expected = FALSE;
} else if (test->letters[i] != NULL) {
if (assert_letters)
g_assert_cmpstr (test->letters[i], ==, alphabet[i + 1]);
else
expected = (g_strcmp0 (test->letters[i], alphabet[i + 1]) == 0);
}
}
return expected;
}
static void
alphabet_changed (EBookClientCursor *cursor,
GParamSpec *pspec,
AlphabetData *data)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) data->fixture;
if (expected_alpabet_check (cursor, data->test, FALSE))
g_main_loop_quit (server_fixture->loop);
}
static void
cursor_test_alphabet (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
CursorTestAlphabet *alphabet = (CursorTestAlphabet *) test;
AlphabetData data = { fixture, alphabet };
/* Alphabet is already correct */
if (expected_alpabet_check (fixture->cursor, alphabet, alphabet->immediate))
return;
/* Alphabet is notified asynchronously, connect to signal and
* timeout error if the correct alphabet is never reached.
*/
alphabet->alphabet_id = g_signal_connect (
fixture->cursor, "notify::alphabet",
G_CALLBACK (alphabet_changed),
&data);
cursor_fixture_timeout_start (fixture, "Timeout waiting for expected alphabet");
g_main_loop_run (server_fixture->loop);
cursor_fixture_timeout_cancel (fixture);
g_signal_handler_disconnect (fixture->cursor, alphabet->alphabet_id);
}
static void
cursor_test_alphabet_free (CursorTest *test)
{
CursorTestAlphabet *alphabet = (CursorTestAlphabet *) test;
gint i;
for (i = 0; i < ALPHABET_TEST_LETTERS; i++)
g_free (alphabet->letters[i]);
g_slice_free (CursorTestAlphabet, alphabet);
}
/******************************************************
* Thread Tests *
******************************************************/
struct _CursorThreadTest {
CursorThreadFunc test_func;
GDestroyNotify destroy_data;
gpointer data;
};
struct _CursorThread {
CursorTestType type;
CursorFixture *fixture;
CursorClosure *closure;
gchar *thread_name;
GThread *thread;
GMutex mutex;
GCond cond;
GMainContext *context;
GMainLoop *loop;
GSource *timeout_source;
EBookClientCursor *cursor;
GList *tests;
guint create_cursor : 1;
guint running : 1;
};
static CursorThread *
cursor_closure_thread (CursorClosure *closure,
gboolean create_cursor,
const gchar *format,
...)
{
CursorThread *test = g_slice_new0 (CursorThread);
va_list args;
test->type = CURSOR_TEST_THREAD;
va_start (args, format);
test->thread_name = g_strdup_vprintf (format, args);
va_end (args);
test->create_cursor = create_cursor;
g_mutex_init (&test->mutex);
g_cond_init (&test->cond);
closure->tests = g_list_append (closure->tests, test);
return test;
}
static gpointer
cursor_thread_func (gpointer data)
{
CursorThread *thread = (CursorThread *) data;
GList *l;
/* Allocate thread local resources */
thread->context = g_main_context_new ();
thread->loop = g_main_loop_new (thread->context, FALSE);
g_main_context_push_thread_default (thread->context);
if (thread->create_cursor) {
/* Use a separate cursor from a different thread */
ETestServerFixture *server_fixture = (ETestServerFixture *) thread->fixture;
EBookClient *book_client;
GError *error;
book_client = E_TEST_SERVER_UTILS_SERVICE (server_fixture, EBookClient);
if (!e_book_client_get_cursor_sync (book_client,
NULL,
sort_fields,
sort_types,
N_SORT_FIELDS,
&thread->cursor,
NULL, &error))
g_error ("Error creating cursor in thread: %s", error->message);
} else {
/* Use the same cursor from a different thread */
thread->cursor = g_object_ref (thread->fixture->cursor);
}
/* Signal that we're running */
g_mutex_lock (&thread->mutex);
thread->running = TRUE;
g_cond_signal (&thread->cond);
g_mutex_unlock (&thread->mutex);
/* Run tests */
for (l = thread->tests; l; l = l->next) {
CursorThreadTest *test = l->data;
test->test_func (thread->fixture,
thread->closure,
thread,
test->data);
}
/* Cleanup and return */
g_mutex_lock (&thread->mutex);
g_object_unref (thread->cursor);
g_main_context_pop_thread_default (thread->context);
g_main_loop_unref (thread->loop);
g_main_context_unref (thread->context);
thread->context = NULL;
thread->loop = NULL;
thread->cursor = NULL;
g_mutex_unlock (&thread->mutex);
return NULL;
}
static void
cursor_test_thread (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
CursorThread *thread = (CursorThread *) test;
thread->fixture = fixture;
thread->closure = closure;
thread->thread = g_thread_new (
thread->thread_name,
cursor_thread_func,
thread);
/* Wait for the thread to start */
g_mutex_lock (&thread->mutex);
while (!thread->running)
g_cond_wait (&thread->cond, &thread->mutex);
g_mutex_unlock (&thread->mutex);
}
static void
cursor_thread_test_free (CursorThreadTest *thread_test)
{
if (thread_test->destroy_data)
thread_test->destroy_data (thread_test->data);
g_slice_free (CursorThreadTest, thread_test);
}
static void
cursor_test_thread_free (CursorTest *test)
{
CursorThread *thread = (CursorThread *) test;
if (thread->thread)
g_error ("Freeing thread test before the thread has been joined");
g_free (thread->thread_name);
g_mutex_clear (&thread->mutex);
g_cond_clear (&thread->cond);
g_list_free_full (thread->tests, (GDestroyNotify) cursor_thread_test_free);
g_slice_free (CursorThread, thread);
}
static void
cursor_thread_add_test (CursorThread *thread,
CursorThreadFunc test_func,
gpointer data,
GDestroyNotify destroy_data)
{
CursorThreadTest *thread_test = g_slice_new0 (CursorThreadTest);
thread_test->test_func = test_func;
thread_test->destroy_data = destroy_data;
thread_test->data = data;
thread->tests = g_list_append (thread->tests, thread_test);
}
static void
cursor_thread_timeout_start (CursorThread *thread,
const gchar *error_message)
{
timeout_start (thread->context, &thread->timeout_source, error_message);
}
static void
cursor_thread_timeout_cancel (CursorThread *thread)
{
timeout_cancel (&thread->timeout_source);
}
/******************************************************
* Thread Join Tests *
******************************************************/
typedef struct {
CursorTestType type;
CursorThread *thread;
} CursorThreadJoin;
static void
cursor_closure_thread_join (CursorClosure *closure,
CursorThread *thread)
{
CursorThreadJoin *test = g_slice_new0 (CursorThreadJoin);
test->type = CURSOR_TEST_THREAD_JOIN;
test->thread = thread;
closure->tests = g_list_append (closure->tests, test);
}
static gboolean
quit_thread_cb (gpointer data)
{
CursorThread *thread = (CursorThread *) data;
g_main_loop_quit (thread->loop);
return FALSE;
}
static void
cursor_test_thread_join (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
CursorThreadJoin *join = (CursorThreadJoin *) test;
GSource *source;
g_mutex_lock (&(join->thread->mutex));
if (join->thread->context) {
source = g_idle_source_new ();
g_source_set_callback (source, quit_thread_cb, join->thread, NULL);
g_source_attach (source, join->thread->context);
g_source_unref (source);
}
g_mutex_unlock (&(join->thread->mutex));
g_thread_join (join->thread->thread);
join->thread->thread = NULL;
}
static void
cursor_test_thread_join_free (CursorTest *test)
{
CursorThreadJoin *join = (CursorThreadJoin *) test;
g_slice_free (CursorThreadJoin, join);
}
/******************************************************
* Tests *
******************************************************/
typedef struct {
CursorTestType type;
guint ms;
} CursorTestSpinLoop;
static void
cursor_closure_spin_loop (CursorClosure *closure,
guint ms)
{
CursorTestSpinLoop *test = g_slice_new0 (CursorTestSpinLoop);
test->type = CURSOR_TEST_SPIN_LOOP;
test->ms = ms;
closure->tests = g_list_append (closure->tests, test);
}
static gboolean
quit_loop_cb (gpointer data)
{
GMainLoop *loop = (GMainLoop *) data;
g_main_loop_quit (loop);
return FALSE;
}
static void
cursor_test_spin_loop (CursorFixture *fixture,
CursorClosure *closure,
CursorTest *test)
{
ETestServerFixture *server_fixture = (ETestServerFixture *) fixture;
CursorTestSpinLoop *spin = (CursorTestSpinLoop *) test;
if (spin->ms > 0)
g_timeout_add (spin->ms, quit_loop_cb, server_fixture->loop);
else
g_idle_add (quit_loop_cb, server_fixture->loop);
g_main_loop_run (server_fixture->loop);
}
static void
cursor_test_spin_loop_free (CursorTest *test)
{
CursorTestSpinLoop *spin = (CursorTestSpinLoop *) test;
g_slice_free (CursorTestSpinLoop, spin);
}
/******************************************************
* Threaded Test Functions *
******************************************************/
typedef struct {
CursorFixture *fixture;
CursorClosure *closure;
CursorThread *thread;
guint async : 1;
guint out_of_sync : 1;
guint end_of_list : 1;
} StepLoopData;
static void
step_loop_ready_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
StepLoopData *data = (StepLoopData *) user_data;
GSList *results = NULL;
GError *error = NULL;
if (e_book_client_cursor_step_finish (E_BOOK_CLIENT_CURSOR (source_object),
result, &results, &error) < 0) {
if (g_error_matches (error,
E_CLIENT_ERROR,
E_CLIENT_ERROR_OUT_OF_SYNC)) {
data->out_of_sync = TRUE;
g_clear_error (&error);
} else if (g_error_matches (error,
E_CLIENT_ERROR,
E_CLIENT_ERROR_QUERY_REFUSED)) {
data->end_of_list = TRUE;
g_clear_error (&error);
} else {
g_error (
"Error calling e_book_client_cursor_step_finish(): %s",
error->message);
}
}
g_slist_free_full (results, (GDestroyNotify) g_object_unref);
g_main_loop_quit (data->thread->loop);
}
static void
step_loop_refreshed (EBookClientCursor *cursor,
StepLoopData *data)
{
g_main_loop_quit (data->thread->loop);
}
static void
step_loop_iteration (StepLoopData *data)
{
EBookCursorOrigin origin = E_BOOK_CURSOR_ORIGIN_CURRENT;
GError *error = NULL;
GSList *results = NULL;
if (data->end_of_list) {
origin = E_BOOK_CURSOR_ORIGIN_BEGIN;
data->end_of_list = FALSE;
}
if (data->async) {
e_book_client_cursor_step (
data->thread->cursor,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
origin,
3,
NULL,
step_loop_ready_cb,
data);
cursor_thread_timeout_start (data->thread, "Timeout reached waiting for step() reply in a thread");
g_main_loop_run (data->thread->loop);
cursor_thread_timeout_cancel (data->thread);
} else {
if (e_book_client_cursor_step_sync (data->thread->cursor,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
origin,
3,
&results,
NULL, &error) < 0) {
if (g_error_matches (error,
E_CLIENT_ERROR,
E_CLIENT_ERROR_OUT_OF_SYNC)) {
data->out_of_sync = TRUE;
g_clear_error (&error);
} else if (g_error_matches (error,
E_CLIENT_ERROR,
E_CLIENT_ERROR_QUERY_REFUSED)) {
data->end_of_list = TRUE;
g_clear_error (&error);
} else {
g_error (
"Error calling e_book_client_cursor_step_sync(): %s",
error->message);
}
}
g_slist_free_full (results, (GDestroyNotify) g_object_unref);
}
/* Pause here and wait for a refresh if we're out of sync */
if (data->out_of_sync) {
gulong refresh_id = g_signal_connect (
data->thread->cursor, "refresh",
G_CALLBACK (step_loop_refreshed),
data);
cursor_thread_timeout_start (
data->thread,
"Timeout reached waiting for a refresh "
"event after an out-of-sync return by step()");
g_main_loop_run (data->thread->loop);
cursor_thread_timeout_cancel (data->thread);
g_signal_handler_disconnect (data->thread->cursor, refresh_id);
data->out_of_sync = FALSE;
}
}
static void
step_loop (CursorFixture *fixture,
CursorClosure *closure,
CursorThread *thread,
gpointer user_data)
{
gboolean async = GPOINTER_TO_INT (user_data);
StepLoopData data = { fixture, closure, thread, async, FALSE, FALSE };
gint i;
for (i = 0; i < THREAD_ITERATIONS; i++) {
step_loop_iteration (&data);
}
}
/******************************************************
* Main, tests defined here *
******************************************************/
typedef struct {
const gchar *base_path;
gboolean async;
gboolean dedicated_cursor;
} ThreadParams;
static CursorParams base_params[] = {
{ "/FullSummary/Standard/Sync", FALSE, FALSE, FALSE },
{ "/FullSummary/Standard/Async", TRUE, FALSE, FALSE },
{ "/FullSummary/Direct/Sync", FALSE, TRUE, FALSE },
{ "/FullSummary/Direct/Async", TRUE, TRUE, FALSE },
{ "/EmptySummary/Standard/Sync", FALSE, FALSE, TRUE },
{ "/EmptySummary/Standard/Async", TRUE, FALSE, TRUE },
{ "/EmptySummary/Direct/Sync", FALSE, TRUE, TRUE },
{ "/EmptySummary/Direct/Async", TRUE, TRUE, TRUE },
};
static ThreadParams thread_params[] = {
{ "/SharedCursor/ThreadSync", FALSE, FALSE },
{ "/SharedCursor/ThreadAsync", TRUE, FALSE },
{ "/DedicatedCursor/ThreadSync", FALSE, TRUE },
{ "/DedicatedCursor/ThreadAsync", TRUE, TRUE },
};
gint
main (gint argc,
gchar **argv)
{
GOptionContext *context;
CursorClosure *closure;
CursorThread *thread;
CursorThread *threads[CONCURRENT_THREADS];
gint i, j, k;
/* Parse our regex first */
context = g_option_context_new (NULL);
g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
if (test_filter)
test_regex = g_regex_new (test_filter, 0, 0, NULL);
g_test_init (&argc, &argv, NULL);
g_test_bug_base ("https://gitlab.gnome.org/GNOME/evolution-data-server/");
client_test_utils_read_args (argc, argv);
for (i = 0; i < G_N_ELEMENTS (base_params); i++) {
/****************************************************
* BASIC SORT ORDERING TESTS *
****************************************************
*
* Note that all sort ordering can be confirmed with the
* chart found in tests/libedata-book/data-test-utils.h
*/
/* POSIX Order */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 2, 6, 3, 8, 1, 5, 4, 7, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
10, /* Count */
10, /* Expected results */
17, 16, 18, 10, 14, 12, 13, 9, 19, 20);
cursor_closure_position (closure, 20, 20, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/Order/POSIX%s", base_params[i].base_path);
/* en_US Order */
closure = cursor_closure_new (&base_params[i], "en_US.utf8");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 1, 2, 5, 6, 4, 3, 7, 8, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
10, /* Count */
10, /* Expected results */
17, 16, 18, 10, 14, 12, 13, 9, 19, 20);
cursor_closure_position (closure, 20, 20, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/Order/en_US%s", base_params[i].base_path);
/* fr_CA Order */
closure = cursor_closure_new (&base_params[i], "fr_CA.utf8");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 1, 2, 5, 6, 4, 3, 7, 8, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
10, /* Count */
10, /* Expected results */
17, 16, 18, 10, 14, 13, 12, 9, 19, 20);
cursor_closure_position (closure, 20, 20, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/Order/fr_CA%s", base_params[i].base_path);
/* de_DE Order */
closure = cursor_closure_new (&base_params[i], "de_DE.utf8");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 1, 2, 5, 6, 7, 8, 4, 3, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
10, /* Count */
10, /* Expected results */
17, 16, 18, 10, 14, 12, 13, 9, 20, 19);
cursor_closure_position (closure, 20, 20, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/Order/de_DE%s", base_params[i].base_path);
/****************************************************
* Step / Origins Test *
****************************************************/
/* Overshooting the contact list causes position to become total + 1 */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 2, 6, 3, 8, 1, 5, 4, 7, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
11, /* Count */
10, /* Expected results */
17, 16, 18, 10, 14, 12, 13, 9, 19, 20);
cursor_closure_position (closure, 20, 21, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/Step/Overshoot%s", base_params[i].base_path);
/* Undershooting the contact list (in reverse) causes position to become 0 */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_END,
-10, /* Count */
10, /* Expected results */
20, 19, 9, 13, 12, 14, 10, 18, 16, 17);
cursor_closure_position (closure, 20, 11, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
-11, /* Count */
10, /* Expected results */
15, 7, 4, 5, 1, 8, 3, 6, 2, 11);
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/Step/Undershoot%s", base_params[i].base_path);
/* Stepping past the end position causes an E_CLIENT_ERROR_QUERY_REFUSED */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 2, 6, 3, 8, 1, 5, 4, 7, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
11, /* Count */
10, /* Expected results */
17, 16, 18, 10, 14, 12, 13, 9, 19, 20);
cursor_closure_position (closure, 20, 21, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
1, /* Count */
-1); /* Expect E_CLIENT_ERROR_QUERY_REFUSED */
cursor_closure_add (closure, "/EBookClientCursor/Step/EndOfListError/End%s", base_params[i].base_path);
/* Stepping backwards past the beginning position causes an E_CLIENT_ERROR_QUERY_REFUSED */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_END,
-10, /* Count */
10, /* Expected results */
20, 19, 9, 13, 12, 14, 10, 18, 16, 17);
cursor_closure_position (closure, 20, 11, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
-11, /* Count */
10, /* Expected results */
15, 7, 4, 5, 1, 8, 3, 6, 2, 11);
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
-1, /* Count */
-1); /* Expect E_CLIENT_ERROR_QUERY_REFUSED */
cursor_closure_add (closure, "/EBookClientCursor/Step/EndOfListError/Begin%s", base_params[i].base_path);
/* Resetting query to get the beginning of the results */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 2, 6, 3, 8, 1, 5, 4, 7, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 2, 6, 3, 8, 1, 5, 4, 7, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/Step/Reset/Forward%s", base_params[i].base_path);
/* Resetting query to get the ending of the results (backwards) */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_END,
-10, /* Count */
10, /* Expected results */
20, 19, 9, 13, 12, 14, 10, 18, 16, 17);
cursor_closure_position (closure, 20, 11, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_END,
-10, /* Count */
10, /* Expected results */
20, 19, 9, 13, 12, 14, 10, 18, 16, 17);
cursor_closure_position (closure, 20, 11, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/Step/Reset/Backwards%s", base_params[i].base_path);
/* Move twice and then repeat query */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 2, 6, 3, 8, 1, 5, 4, 7, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
5, /* Count */
5, /* Expected results */
17, 16, 18, 10, 14);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
5, /* Count */
5, /* Expected results */
17, 16, 18, 10, 14);
cursor_closure_position (closure, 20, 15, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/Step/RepeatPrevious/Forward%s", base_params[i].base_path);
/* Move twice and then repeat query */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_END,
-10, /* Count */
10, /* Expected results */
20, 19, 9, 13, 12, 14, 10, 18, 16, 17);
cursor_closure_position (closure, 20, 11, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
-5, /* Count */
5, /* Expected results */
15, 7, 4, 5, 1);
cursor_closure_position (closure, 20, 11, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
-5, /* Count */
5, /* Expected results */
15, 7, 4, 5, 1);
cursor_closure_position (closure, 20, 6, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/Step/RepeatPrevious/Backwards%s", base_params[i].base_path);
/****************************************************
* BASIC SEARCH EXPRESSION TESTS *
****************************************************/
/* Query Changes Position */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 2, 6, 3, 8, 1, 5, 4, 7, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_set_sexp (
closure,
e_book_query_field_test (
E_CONTACT_EMAIL,
E_BOOK_QUERY_ENDS_WITH,
".com"));
/* In POSIX Locale, the 10th contact out of 20 becomes the 6th contact out of
* 13 contacts bearing a '.com' email address
*/
cursor_closure_position (closure, 13, 6, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/SearchExpression/EffectsPosition%s", base_params[i].base_path);
/****************************************************
* Address Book Modifications *
****************************************************/
/* Test that adding a contact changes the total / position appropriately */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 2, 6, 3, 8, 1, 5, 4, 7, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_add_contact (closure, "custom-3");
cursor_closure_position (closure, 21, 11, FALSE);
cursor_closure_add (closure, "/EBookClientCursor/AddContact/TestForward%s", base_params[i].base_path);
/* Test that adding a contact changes the total / position appropriately after having moved from the end */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_END,
-10, /* Count */
10, /* Expected results */
20, 19, 9, 13, 12, 14, 10, 18, 16, 17);
cursor_closure_position (closure, 20, 11, TRUE);
cursor_closure_add_contact (closure, "custom-3");
cursor_closure_position (closure, 21, 12, FALSE);
cursor_closure_add (closure, "/EBookClientCursor/AddContact/TestBackwards%s", base_params[i].base_path);
/* Test that removing a contact changes the total / position appropriately */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 2, 6, 3, 8, 1, 5, 4, 7, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_remove_contact (closure, "sorted-14");
cursor_closure_position (closure, 19, 10, FALSE);
cursor_closure_add (closure, "/EBookClientCursor/RemoveContact/TestForward%s", base_params[i].base_path);
/* Test that removing a contact changes the total / position appropriately after having moved from the end */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_END,
-10, /* Count */
10, /* Expected results */
20, 19, 9, 13, 12, 14, 10, 18, 16, 17);
cursor_closure_position (closure, 20, 11, TRUE);
cursor_closure_remove_contact (closure, "sorted-14");
cursor_closure_position (closure, 19, 11, FALSE);
cursor_closure_add (closure, "/EBookClientCursor/RemoveContact/TestBackwards%s", base_params[i].base_path);
/****************************************************
* Alphabet Index Tests *
****************************************************/
/* POSIX locale & Latin indexes */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_alphabet_index (closure, 2);
cursor_closure_position (closure, 20, 1, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/AlphabetIndex/Position/B%s", base_params[i].base_path);
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_alphabet_index (closure, 3);
cursor_closure_position (closure, 20, 13, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/AlphabetIndex/Position/C%s", base_params[i].base_path);
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_alphabet_index (closure, 13);
cursor_closure_position (closure, 20, 18, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/AlphabetIndex/Position/M%s", base_params[i].base_path);
/****************************************************
* Dynamic Locale Changes *
****************************************************
*
* Locale changes take effect asynchronously, so we have to
* check that the total/position automatically resets itself
* asynchronously, not synchronously.
*
* Other direct e_book_client_cursor_() apis however result
* in synchronous updates of the position / total values.
*
* These tests add an idle pause after setting the locale
* using 'cursor_closure_spin_loop (closure, 0)'.
*
* The locale setting test only blocks until the EBookClient
* receives a new locale, but the EBookClientCursor::alphabet
* notification may have not been notified, so we add this
* idle to ensure that it is before adding any assertions.
*/
/* Start in POSIX */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_position (closure, 20, 0, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 2, 6, 3, 8, 1, 5, 4, 7, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
10, /* Count */
10, /* Expected results */
17, 16, 18, 10, 14, 12, 13, 9, 19, 20);
cursor_closure_position (closure, 20, 20, TRUE);
/* Now in en_US */
cursor_closure_change_locale (closure, "en_US.utf8");
cursor_closure_spin_loop (closure, 0);
cursor_closure_position (closure, 20, 0, FALSE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 1, 2, 5, 6, 4, 3, 7, 8, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
10, /* Count */
10, /* Expected results */
17, 16, 18, 10, 14, 12, 13, 9, 19, 20);
cursor_closure_position (closure, 20, 20, TRUE);
/* Now in fr_CA */
cursor_closure_change_locale (closure, "fr_CA.utf8");
cursor_closure_spin_loop (closure, 0);
cursor_closure_position (closure, 20, 0, FALSE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 1, 2, 5, 6, 4, 3, 7, 8, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
10, /* Count */
10, /* Expected results */
17, 16, 18, 10, 14, 13, 12, 9, 19, 20);
cursor_closure_position (closure, 20, 20, TRUE);
/* Now in de_DE */
cursor_closure_change_locale (closure, "de_DE.utf8");
cursor_closure_spin_loop (closure, 0);
cursor_closure_position (closure, 20, 0, FALSE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_BEGIN,
10, /* Count */
10, /* Expected results */
11, 1, 2, 5, 6, 7, 8, 4, 3, 15);
cursor_closure_position (closure, 20, 10, TRUE);
cursor_closure_step (
closure,
E_BOOK_CURSOR_STEP_MOVE | E_BOOK_CURSOR_STEP_FETCH,
E_BOOK_CURSOR_ORIGIN_CURRENT,
10, /* Count */
10, /* Expected results */
17, 16, 18, 10, 14, 12, 13, 9, 20, 19);
cursor_closure_position (closure, 20, 20, TRUE);
cursor_closure_add (closure, "/EBookClientCursor/ChangeLocale/Order%s", base_params[i].base_path);
/*
* Check that alphabets are updated after changing locale
*
* For a variety of locales, check first that the alphabet is latin for
* "POSIX" locale (synchronously), and then check that the alphabet changes
* to the new expected alphabet for the new locale after dynamically changing
* the locale (allow a timeout, alphabet changes are delivered only asynchronously).
*/
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_change_locale (closure, "en_US.utf8");
cursor_closure_alphabet (closure, FALSE, "A", "B", "C", "D", "E");
cursor_closure_add (closure, "/EBookClientCursor/ChangeLocale/Alphabet/en_US%s", base_params[i].base_path);
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_change_locale (closure, "el_GR.utf8");
cursor_closure_alphabet (closure, FALSE, "Α", "Β", "Γ", "Δ", "Ε");
cursor_closure_add (closure, "/EBookClientCursor/ChangeLocale/Alphabet/el_GR%s", base_params[i].base_path);
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_change_locale (closure, "ru_RU.utf8");
cursor_closure_alphabet (closure, FALSE, "А", "Б", "В", "Г", "Д");
cursor_closure_add (closure, "/EBookClientCursor/ChangeLocale/Alphabet/ru_RU%s", base_params[i].base_path);
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_change_locale (closure, "ja_JP.utf8");
cursor_closure_alphabet (closure, FALSE, "あ", "か", "さ", "た", "な");
cursor_closure_add (closure, "/EBookClientCursor/ChangeLocale/Alphabet/ja_JP%s", base_params[i].base_path);
/* The alphabet doesn't change for chinese */
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_change_locale (closure, "zh_CN.utf8");
cursor_closure_alphabet (closure, FALSE, "A", "B", "C", "D", "E");
cursor_closure_add (closure, "/EBookClientCursor/ChangeLocale/Alphabet/zh_CN%s", base_params[i].base_path);
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_change_locale (closure, "ko_KR.utf8");
cursor_closure_alphabet (closure, FALSE, "ㄱ", "ㄴ", "ㄷ", "ㄹ", "ㅁ");
cursor_closure_add (closure, "/EBookClientCursor/ChangeLocale/Alphabet/ko_KR%s", base_params[i].base_path);
closure = cursor_closure_new (&base_params[i], "POSIX");
cursor_closure_alphabet (closure, TRUE, "A", "B", "C", "D", "E");
cursor_closure_change_locale (closure, "ar_TN.utf8");
cursor_closure_alphabet (closure, FALSE, "ا", "ب", "ت", "ث", "ج");
cursor_closure_add (closure, "/EBookClientCursor/ChangeLocale/Alphabet/ar_TN%s", base_params[i].base_path);
/****************************************************
* Threaded Tests *
****************************************************/
for (j = 0; j < G_N_ELEMENTS (thread_params); j++) {
/*
* This test performs a series of cursor moves in a dedicated
* thread while the main thread is repeatedly modifying the addressbook
*
* The step_loop() will encounter races where it finds that the addressbook
* has been modified, when E_CLIENT_ERROR_OUT_OF_SYNC is reported then it will
* wait for a refresh and then continue.
*
* The test will fail if it crashes from unprotected concurrent memory accesses,
* and it will fail if ever an out-of-sync error is not followed by an asynchronous
* "refresh" signal.
*/
closure = cursor_closure_new (&base_params[i], "POSIX");
thread = cursor_closure_thread (closure, thread_params[j].dedicated_cursor, "move-by-thread");
cursor_thread_add_test (
thread, step_loop,
GINT_TO_POINTER (thread_params[j].async), NULL);
for (k = 0; k < THREAD_ITERATIONS; k++) {
cursor_closure_add_contact (closure, "custom-3");
cursor_closure_spin_loop (closure, 0);
cursor_closure_remove_contact (closure, "custom-3");
cursor_closure_spin_loop (closure, 0);
}
cursor_closure_thread_join (closure, thread);
cursor_closure_add (
closure, "/EBookClientCursor/Thread/Step/AddingAndRemoving%s%s",
base_params[i].base_path,
thread_params[j].base_path);
/* The same test as above, except that the addressbook is changing locale instead
* of adding / removing contacts
*/
closure = cursor_closure_new (&base_params[i], "POSIX");
thread = cursor_closure_thread (closure, thread_params[j].dedicated_cursor, "move-by-thread");
cursor_thread_add_test (
thread, step_loop,
GINT_TO_POINTER (thread_params[j].async), NULL);
for (k = 0; k < THREAD_ITERATIONS; k++) {
cursor_closure_change_locale (closure, "de_DE.utf8");
cursor_closure_spin_loop (closure, 0);
cursor_closure_change_locale (closure, "fr_CA.utf8");
cursor_closure_spin_loop (closure, 0);
}
cursor_closure_thread_join (closure, thread);
cursor_closure_add (
closure, "/EBookClientCursor/Thread/Step/ChangingLocale%s%s",
base_params[i].base_path,
thread_params[j].base_path);
/* Add / Remove contacts with multiple threaded step() operations going on concurrently */
closure = cursor_closure_new (&base_params[i], "POSIX");
for (k = 0; k < CONCURRENT_THREADS; k++) {
threads[k] = cursor_closure_thread (closure, thread_params[j].dedicated_cursor, "move-by-thread");
cursor_thread_add_test (
threads[k], step_loop,
GINT_TO_POINTER (thread_params[j].async), NULL);
}
for (k = 0; k < THREAD_ITERATIONS; k++) {
cursor_closure_add_contact (closure, "custom-3");
cursor_closure_spin_loop (closure, 0);
cursor_closure_remove_contact (closure, "custom-3");
cursor_closure_spin_loop (closure, 0);
}
for (k = 0; k < CONCURRENT_THREADS; k++)
cursor_closure_thread_join (closure, threads[k]);
cursor_closure_add (
closure, "/EBookClientCursor/MultipleThreads/Step/AddingAndRemoving%s%s",
base_params[i].base_path,
thread_params[j].base_path);
}
}
return e_test_server_utils_run (argc, argv);
}
|