editor/txmgr/tests/TestTXMgr.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "TestHarness.h"
michael@0 7
michael@0 8 #include "nsITransactionManager.h"
michael@0 9 #include "nsComponentManagerUtils.h"
michael@0 10 #include "mozilla/Likely.h"
michael@0 11
michael@0 12 static int32_t sConstructorCount = 0;
michael@0 13 static int32_t sDestructorCount = 0;
michael@0 14 static int32_t *sDestructorOrderArr = 0;
michael@0 15 static int32_t sDoCount = 0;
michael@0 16 static int32_t *sDoOrderArr = 0;
michael@0 17 static int32_t sUndoCount = 0;
michael@0 18 static int32_t *sUndoOrderArr = 0;
michael@0 19 static int32_t sRedoCount = 0;
michael@0 20 static int32_t *sRedoOrderArr = 0;
michael@0 21
michael@0 22 // #define ENABLE_DEBUG_PRINTFS 1
michael@0 23
michael@0 24 int32_t sSimpleTestDestructorOrderArr[] = {
michael@0 25 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
michael@0 26 16, 17, 18, 19, 20, 21, 1, 22, 23, 24, 25, 26, 27, 28,
michael@0 27 29, 30, 31, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
michael@0 28 53, 54, 55, 56, 57, 58, 59, 60, 61, 41, 40, 62, 39, 38,
michael@0 29 37, 36, 35, 34, 33, 32, 68, 63, 64, 65, 66, 67, 69, 71,
michael@0 30 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
michael@0 31 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,
michael@0 32 99, 100, 101, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 131,
michael@0 33 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117,
michael@0 34 116, 115, 114, 113, 112 };
michael@0 35
michael@0 36 int32_t sSimpleTestDoOrderArr[] = {
michael@0 37 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
michael@0 38 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
michael@0 39 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
michael@0 40 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
michael@0 41 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
michael@0 42 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
michael@0 43 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,
michael@0 44 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
michael@0 45 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
michael@0 46 127, 128, 129, 130, 131 };
michael@0 47
michael@0 48 int32_t sSimpleTestUndoOrderArr[] = {
michael@0 49 41, 40, 39, 38, 62, 39, 38, 37, 69, 71, 70, 111, 110, 109,
michael@0 50 108, 107, 106, 105, 104, 103, 102, 131, 130, 129, 128, 127, 126, 125,
michael@0 51 124, 123, 122 };
michael@0 52
michael@0 53 static int32_t sSimpleTestRedoOrderArr[] = {
michael@0 54 38, 39, 70 };
michael@0 55
michael@0 56 int32_t sAggregateTestDestructorOrderArr[] = {
michael@0 57 14, 13, 12, 11, 10, 9, 8, 21, 20, 19, 18, 17, 16, 15,
michael@0 58 28, 27, 26, 25, 24, 23, 22, 35, 34, 33, 32, 31, 30, 29,
michael@0 59 42, 41, 40, 39, 38, 37, 36, 49, 48, 47, 46, 45, 44, 43,
michael@0 60 56, 55, 54, 53, 52, 51, 50, 63, 62, 61, 60, 59, 58, 57,
michael@0 61 70, 69, 68, 67, 66, 65, 64, 77, 76, 75, 74, 73, 72, 71,
michael@0 62 84, 83, 82, 81, 80, 79, 78, 91, 90, 89, 88, 87, 86, 85,
michael@0 63 98, 97, 96, 95, 94, 93, 92, 105, 104, 103, 102, 101, 100, 99,
michael@0 64 112, 111, 110, 109, 108, 107, 106, 119, 118, 117, 116, 115, 114, 113,
michael@0 65 126, 125, 124, 123, 122, 121, 120, 133, 132, 131, 130, 129, 128, 127,
michael@0 66 140, 139, 138, 137, 136, 135, 134, 147, 146, 145, 144, 143, 142, 141,
michael@0 67 7, 6, 5, 4, 3, 2, 1, 154, 153, 152, 151, 150, 149, 148,
michael@0 68 161, 160, 159, 158, 157, 156, 155, 168, 167, 166, 165, 164, 163, 162,
michael@0 69 175, 174, 173, 172, 171, 170, 169, 182, 181, 180, 179, 178, 177, 176,
michael@0 70 189, 188, 187, 186, 185, 184, 183, 196, 195, 194, 193, 192, 191, 190,
michael@0 71 203, 202, 201, 200, 199, 198, 197, 210, 209, 208, 207, 206, 205, 204,
michael@0 72 217, 216, 215, 214, 213, 212, 211, 294, 293, 292, 291, 290, 289, 288,
michael@0 73 301, 300, 299, 298, 297, 296, 295, 308, 307, 306, 305, 304, 303, 302,
michael@0 74 315, 314, 313, 312, 311, 310, 309, 322, 321, 320, 319, 318, 317, 316,
michael@0 75 329, 328, 327, 326, 325, 324, 323, 336, 335, 334, 333, 332, 331, 330,
michael@0 76 343, 342, 341, 340, 339, 338, 337, 350, 349, 348, 347, 346, 345, 344,
michael@0 77 357, 356, 355, 354, 353, 352, 351, 364, 363, 362, 361, 360, 359, 358,
michael@0 78 371, 370, 369, 368, 367, 366, 365, 378, 377, 376, 375, 374, 373, 372,
michael@0 79 385, 384, 383, 382, 381, 380, 379, 392, 391, 390, 389, 388, 387, 386,
michael@0 80 399, 398, 397, 396, 395, 394, 393, 406, 405, 404, 403, 402, 401, 400,
michael@0 81 413, 412, 411, 410, 409, 408, 407, 420, 419, 418, 417, 416, 415, 414,
michael@0 82 427, 426, 425, 424, 423, 422, 421, 287, 286, 285, 284, 283, 282, 281,
michael@0 83 280, 279, 278, 277, 276, 275, 274, 434, 433, 432, 431, 430, 429, 428,
michael@0 84 273, 272, 271, 270, 269, 268, 267, 266, 265, 264, 263, 262, 261, 260,
michael@0 85 259, 258, 257, 256, 255, 254, 253, 252, 251, 250, 249, 248, 247, 246,
michael@0 86 245, 244, 243, 242, 241, 240, 239, 238, 237, 236, 235, 234, 233, 232,
michael@0 87 231, 230, 229, 228, 227, 226, 225, 224, 223, 222, 221, 220, 219, 218,
michael@0 88 472, 471, 470, 441, 440, 439, 438, 437, 436, 435, 448, 447, 446, 445,
michael@0 89 444, 443, 442, 455, 454, 453, 452, 451, 450, 449, 462, 461, 460, 459,
michael@0 90 458, 457, 456, 469, 468, 467, 466, 465, 464, 463, 479, 478, 477, 476,
michael@0 91 475, 474, 473, 493, 492, 491, 490, 489, 488, 487, 486, 485, 484, 483,
michael@0 92 482, 481, 480, 496, 497, 495, 499, 500, 498, 494, 503, 504, 502, 506,
michael@0 93 507, 505, 501, 510, 511, 509, 513, 514, 512, 508, 517, 518, 516, 520,
michael@0 94 521, 519, 515, 524, 525, 523, 527, 528, 526, 522, 531, 532, 530, 534,
michael@0 95 535, 533, 529, 538, 539, 537, 541, 542, 540, 536, 545, 546, 544, 548,
michael@0 96 549, 547, 543, 552, 553, 551, 555, 556, 554, 550, 559, 560, 558, 562,
michael@0 97 563, 561, 557, 566, 567, 565, 569, 570, 568, 564, 573, 574, 572, 576,
michael@0 98 577, 575, 571, 580, 581, 579, 583, 584, 582, 578, 587, 588, 586, 590,
michael@0 99 591, 589, 585, 594, 595, 593, 597, 598, 596, 592, 601, 602, 600, 604,
michael@0 100 605, 603, 599, 608, 609, 607, 611, 612, 610, 606, 615, 616, 614, 618,
michael@0 101 619, 617, 613, 622, 623, 621, 625, 626, 624, 620, 629, 630, 628, 632,
michael@0 102 633, 631, 627, 640, 639, 638, 637, 636, 635, 634, 647, 646, 645, 644,
michael@0 103 643, 642, 641, 654, 653, 652, 651, 650, 649, 648, 661, 660, 659, 658,
michael@0 104 657, 656, 655, 668, 667, 666, 665, 664, 663, 662, 675, 674, 673, 672,
michael@0 105 671, 670, 669, 682, 681, 680, 679, 678, 677, 676, 689, 688, 687, 686,
michael@0 106 685, 684, 683, 696, 695, 694, 693, 692, 691, 690, 703, 702, 701, 700,
michael@0 107 699, 698, 697, 773, 772, 771, 770, 769, 768, 767, 766, 765, 764, 763,
michael@0 108 762, 761, 760, 759, 758, 757, 756, 755, 754, 753, 752, 751, 750, 749,
michael@0 109 748, 747, 746, 745, 744, 743, 742, 741, 740, 739, 738, 737, 736, 735,
michael@0 110 734, 733, 732, 731, 730, 729, 728, 727, 726, 725, 724, 723, 722, 721,
michael@0 111 720, 719, 718, 717, 716, 715, 714, 713, 712, 711, 710, 709, 708, 707,
michael@0 112 706, 705, 704, 913, 912, 911, 910, 909, 908, 907, 906, 905, 904, 903,
michael@0 113 902, 901, 900, 899, 898, 897, 896, 895, 894, 893, 892, 891, 890, 889,
michael@0 114 888, 887, 886, 885, 884, 883, 882, 881, 880, 879, 878, 877, 876, 875,
michael@0 115 874, 873, 872, 871, 870, 869, 868, 867, 866, 865, 864, 863, 862, 861,
michael@0 116 860, 859, 858, 857, 856, 855, 854, 853, 852, 851, 850, 849, 848, 847,
michael@0 117 846, 845, 844, 843, 842, 841, 840, 839, 838, 837, 836, 835, 834, 833,
michael@0 118 832, 831, 830, 829, 828, 827, 826, 825, 824, 823, 822, 821, 820, 819,
michael@0 119 818, 817, 816, 815, 814, 813, 812, 811, 810, 809, 808, 807, 806, 805,
michael@0 120 804, 803, 802, 801, 800, 799, 798, 797, 796, 795, 794, 793, 792, 791,
michael@0 121 790, 789, 788, 787, 786, 785, 784, 783, 782, 781, 780, 779, 778, 777,
michael@0 122 776, 775, 774 };
michael@0 123
michael@0 124 int32_t sAggregateTestDoOrderArr[] = {
michael@0 125 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
michael@0 126 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
michael@0 127 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
michael@0 128 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
michael@0 129 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
michael@0 130 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
michael@0 131 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,
michael@0 132 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
michael@0 133 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
michael@0 134 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
michael@0 135 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
michael@0 136 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168,
michael@0 137 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182,
michael@0 138 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
michael@0 139 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210,
michael@0 140 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
michael@0 141 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
michael@0 142 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252,
michael@0 143 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
michael@0 144 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280,
michael@0 145 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
michael@0 146 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308,
michael@0 147 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322,
michael@0 148 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336,
michael@0 149 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350,
michael@0 150 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
michael@0 151 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378,
michael@0 152 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392,
michael@0 153 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406,
michael@0 154 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420,
michael@0 155 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434,
michael@0 156 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448,
michael@0 157 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462,
michael@0 158 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476,
michael@0 159 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490,
michael@0 160 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504,
michael@0 161 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518,
michael@0 162 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532,
michael@0 163 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546,
michael@0 164 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560,
michael@0 165 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574,
michael@0 166 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588,
michael@0 167 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602,
michael@0 168 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616,
michael@0 169 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630,
michael@0 170 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644,
michael@0 171 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658,
michael@0 172 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672,
michael@0 173 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686,
michael@0 174 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700,
michael@0 175 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714,
michael@0 176 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728,
michael@0 177 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742,
michael@0 178 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756,
michael@0 179 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770,
michael@0 180 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784,
michael@0 181 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798,
michael@0 182 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812,
michael@0 183 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826,
michael@0 184 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840,
michael@0 185 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854,
michael@0 186 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868,
michael@0 187 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882,
michael@0 188 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896,
michael@0 189 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910,
michael@0 190 911, 912, 913 };
michael@0 191
michael@0 192 int32_t sAggregateTestUndoOrderArr[] = {
michael@0 193 287, 286, 285, 284, 283, 282, 281, 280, 279, 278, 277, 276, 275, 274,
michael@0 194 273, 272, 271, 270, 269, 268, 267, 266, 265, 264, 263, 262, 261, 260,
michael@0 195 434, 433, 432, 431, 430, 429, 428, 273, 272, 271, 270, 269, 268, 267,
michael@0 196 266, 265, 264, 263, 262, 261, 260, 259, 258, 257, 256, 255, 254, 253,
michael@0 197 479, 478, 477, 476, 475, 493, 492, 491, 490, 489, 488, 487, 486, 485,
michael@0 198 484, 483, 482, 481, 480, 485, 484, 483, 482, 481, 480, 773, 772, 771,
michael@0 199 770, 769, 768, 767, 766, 765, 764, 763, 762, 761, 760, 759, 758, 757,
michael@0 200 756, 755, 754, 753, 752, 751, 750, 749, 748, 747, 746, 745, 744, 743,
michael@0 201 742, 741, 740, 739, 738, 737, 736, 735, 734, 733, 732, 731, 730, 729,
michael@0 202 728, 727, 726, 725, 724, 723, 722, 721, 720, 719, 718, 717, 716, 715,
michael@0 203 714, 713, 712, 711, 710, 709, 708, 707, 706, 705, 704, 913, 912, 911,
michael@0 204 910, 909, 908, 907, 906, 905, 904, 903, 902, 901, 900, 899, 898, 897,
michael@0 205 896, 895, 894, 893, 892, 891, 890, 889, 888, 887, 886, 885, 884, 883,
michael@0 206 882, 881, 880, 879, 878, 877, 876, 875, 874, 873, 872, 871, 870, 869,
michael@0 207 868, 867, 866, 865, 864, 863, 862, 861, 860, 859, 858, 857, 856, 855,
michael@0 208 854, 853, 852, 851, 850, 849, 848, 847, 846, 845, 844 };
michael@0 209
michael@0 210 int32_t sAggregateTestRedoOrderArr[] = {
michael@0 211 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273,
michael@0 212 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486 };
michael@0 213
michael@0 214 int32_t sSimpleBatchTestDestructorOrderArr[] = {
michael@0 215 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
michael@0 216 35, 36, 37, 38, 39, 40, 43, 42, 41, 64, 63, 62, 61, 60,
michael@0 217 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46,
michael@0 218 45, 44, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9,
michael@0 219 8, 7, 6, 5, 4, 3, 2, 1, 65, 67, 66, 68, 69, 70,
michael@0 220 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
michael@0 221 85, 86, 87, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97,
michael@0 222 96, 95, 94, 93, 92, 91, 90, 89, 88 };
michael@0 223
michael@0 224 int32_t sSimpleBatchTestDoOrderArr[] = {
michael@0 225 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
michael@0 226 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
michael@0 227 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
michael@0 228 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
michael@0 229 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
michael@0 230 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
michael@0 231 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,
michael@0 232 99, 100, 101, 102, 103, 104, 105, 106, 107 };
michael@0 233
michael@0 234 int32_t sSimpleBatchTestUndoOrderArr[] = {
michael@0 235 43, 42, 41, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
michael@0 236 9, 8, 7, 6, 5, 4, 3, 2, 1, 43, 42, 41, 63, 62,
michael@0 237 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48,
michael@0 238 47, 46, 45, 44, 65, 67, 66, 107, 106, 105, 104, 103, 102, 101,
michael@0 239 100, 99, 98 };
michael@0 240
michael@0 241 int32_t sSimpleBatchTestRedoOrderArr[] = {
michael@0 242 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
michael@0 243 15, 16, 17, 18, 19, 20, 41, 42, 43, 66 };
michael@0 244
michael@0 245 int32_t sAggregateBatchTestDestructorOrderArr[] = {
michael@0 246 147, 146, 145, 144, 143, 142, 141, 154, 153, 152, 151, 150, 149, 148,
michael@0 247 161, 160, 159, 158, 157, 156, 155, 168, 167, 166, 165, 164, 163, 162,
michael@0 248 175, 174, 173, 172, 171, 170, 169, 182, 181, 180, 179, 178, 177, 176,
michael@0 249 189, 188, 187, 186, 185, 184, 183, 196, 195, 194, 193, 192, 191, 190,
michael@0 250 203, 202, 201, 200, 199, 198, 197, 210, 209, 208, 207, 206, 205, 204,
michael@0 251 217, 216, 215, 214, 213, 212, 211, 224, 223, 222, 221, 220, 219, 218,
michael@0 252 231, 230, 229, 228, 227, 226, 225, 238, 237, 236, 235, 234, 233, 232,
michael@0 253 245, 244, 243, 242, 241, 240, 239, 252, 251, 250, 249, 248, 247, 246,
michael@0 254 259, 258, 257, 256, 255, 254, 253, 266, 265, 264, 263, 262, 261, 260,
michael@0 255 273, 272, 271, 270, 269, 268, 267, 280, 279, 278, 277, 276, 275, 274,
michael@0 256 301, 300, 299, 298, 297, 296, 295, 294, 293, 292, 291, 290, 289, 288,
michael@0 257 287, 286, 285, 284, 283, 282, 281, 444, 443, 442, 441, 440, 439, 438,
michael@0 258 437, 436, 435, 434, 433, 432, 431, 430, 429, 428, 427, 426, 425, 424,
michael@0 259 423, 422, 421, 420, 419, 418, 417, 416, 415, 414, 413, 412, 411, 410,
michael@0 260 409, 408, 407, 406, 405, 404, 403, 402, 401, 400, 399, 398, 397, 396,
michael@0 261 395, 394, 393, 392, 391, 390, 389, 388, 387, 386, 385, 384, 383, 382,
michael@0 262 381, 380, 379, 378, 377, 376, 375, 374, 373, 372, 371, 370, 369, 368,
michael@0 263 367, 366, 365, 364, 363, 362, 361, 360, 359, 358, 357, 356, 355, 354,
michael@0 264 353, 352, 351, 350, 349, 348, 347, 346, 345, 344, 343, 342, 341, 340,
michael@0 265 339, 338, 337, 336, 335, 334, 333, 332, 331, 330, 329, 328, 327, 326,
michael@0 266 325, 324, 323, 322, 321, 320, 319, 318, 317, 316, 315, 314, 313, 312,
michael@0 267 311, 310, 309, 308, 307, 306, 305, 304, 303, 302, 140, 139, 138, 137,
michael@0 268 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123,
michael@0 269 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109,
michael@0 270 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95,
michael@0 271 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81,
michael@0 272 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67,
michael@0 273 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53,
michael@0 274 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39,
michael@0 275 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25,
michael@0 276 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11,
michael@0 277 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 451, 450, 449, 448,
michael@0 278 447, 446, 445, 465, 464, 463, 462, 461, 460, 459, 458, 457, 456, 455,
michael@0 279 454, 453, 452, 468, 469, 467, 471, 472, 470, 466, 475, 476, 474, 478,
michael@0 280 479, 477, 473, 482, 483, 481, 485, 486, 484, 480, 489, 490, 488, 492,
michael@0 281 493, 491, 487, 496, 497, 495, 499, 500, 498, 494, 503, 504, 502, 506,
michael@0 282 507, 505, 501, 510, 511, 509, 513, 514, 512, 508, 517, 518, 516, 520,
michael@0 283 521, 519, 515, 524, 525, 523, 527, 528, 526, 522, 531, 532, 530, 534,
michael@0 284 535, 533, 529, 538, 539, 537, 541, 542, 540, 536, 545, 546, 544, 548,
michael@0 285 549, 547, 543, 552, 553, 551, 555, 556, 554, 550, 559, 560, 558, 562,
michael@0 286 563, 561, 557, 566, 567, 565, 569, 570, 568, 564, 573, 574, 572, 576,
michael@0 287 577, 575, 571, 580, 581, 579, 583, 584, 582, 578, 587, 588, 586, 590,
michael@0 288 591, 589, 585, 594, 595, 593, 597, 598, 596, 592, 601, 602, 600, 604,
michael@0 289 605, 603, 599, 745, 744, 743, 742, 741, 740, 739, 738, 737, 736, 735,
michael@0 290 734, 733, 732, 731, 730, 729, 728, 727, 726, 725, 724, 723, 722, 721,
michael@0 291 720, 719, 718, 717, 716, 715, 714, 713, 712, 711, 710, 709, 708, 707,
michael@0 292 706, 705, 704, 703, 702, 701, 700, 699, 698, 697, 696, 695, 694, 693,
michael@0 293 692, 691, 690, 689, 688, 687, 686, 685, 684, 683, 682, 681, 680, 679,
michael@0 294 678, 677, 676, 675, 674, 673, 672, 671, 670, 669, 668, 667, 666, 665,
michael@0 295 664, 663, 662, 661, 660, 659, 658, 657, 656, 655, 654, 653, 652, 651,
michael@0 296 650, 649, 648, 647, 646, 645, 644, 643, 642, 641, 640, 639, 638, 637,
michael@0 297 636, 635, 634, 633, 632, 631, 630, 629, 628, 627, 626, 625, 624, 623,
michael@0 298 622, 621, 620, 619, 618, 617, 616, 615, 614, 613, 612, 611, 610, 609,
michael@0 299 608, 607, 606 };
michael@0 300
michael@0 301 int32_t sAggregateBatchTestDoOrderArr[] = {
michael@0 302 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
michael@0 303 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
michael@0 304 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
michael@0 305 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
michael@0 306 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
michael@0 307 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
michael@0 308 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,
michael@0 309 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
michael@0 310 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
michael@0 311 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
michael@0 312 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
michael@0 313 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168,
michael@0 314 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182,
michael@0 315 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
michael@0 316 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210,
michael@0 317 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
michael@0 318 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
michael@0 319 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252,
michael@0 320 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266,
michael@0 321 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280,
michael@0 322 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
michael@0 323 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308,
michael@0 324 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322,
michael@0 325 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336,
michael@0 326 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350,
michael@0 327 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
michael@0 328 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378,
michael@0 329 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392,
michael@0 330 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406,
michael@0 331 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420,
michael@0 332 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434,
michael@0 333 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448,
michael@0 334 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462,
michael@0 335 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476,
michael@0 336 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490,
michael@0 337 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504,
michael@0 338 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518,
michael@0 339 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532,
michael@0 340 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546,
michael@0 341 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560,
michael@0 342 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574,
michael@0 343 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588,
michael@0 344 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602,
michael@0 345 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616,
michael@0 346 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630,
michael@0 347 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644,
michael@0 348 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658,
michael@0 349 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672,
michael@0 350 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686,
michael@0 351 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700,
michael@0 352 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714,
michael@0 353 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728,
michael@0 354 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742,
michael@0 355 743, 744, 745 };
michael@0 356
michael@0 357 int32_t sAggregateBatchTestUndoOrderArr[] = {
michael@0 358 301, 300, 299, 298, 297, 296, 295, 294, 293, 292, 291, 290, 289, 288,
michael@0 359 287, 286, 285, 284, 283, 282, 281, 140, 139, 138, 137, 136, 135, 134,
michael@0 360 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120,
michael@0 361 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106,
michael@0 362 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92,
michael@0 363 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78,
michael@0 364 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64,
michael@0 365 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50,
michael@0 366 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36,
michael@0 367 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22,
michael@0 368 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8,
michael@0 369 7, 6, 5, 4, 3, 2, 1, 301, 300, 299, 298, 297, 296, 295,
michael@0 370 294, 293, 292, 291, 290, 289, 288, 287, 286, 285, 284, 283, 282, 281,
michael@0 371 441, 440, 439, 438, 437, 436, 435, 434, 433, 432, 431, 430, 429, 428,
michael@0 372 427, 426, 425, 424, 423, 422, 421, 420, 419, 418, 417, 416, 415, 414,
michael@0 373 413, 412, 411, 410, 409, 408, 407, 406, 405, 404, 403, 402, 401, 400,
michael@0 374 399, 398, 397, 396, 395, 394, 393, 392, 391, 390, 389, 388, 387, 386,
michael@0 375 385, 384, 383, 382, 381, 380, 379, 378, 377, 376, 375, 374, 373, 372,
michael@0 376 371, 370, 369, 368, 367, 366, 365, 364, 363, 362, 361, 360, 359, 358,
michael@0 377 357, 356, 355, 354, 353, 352, 351, 350, 349, 348, 347, 346, 345, 344,
michael@0 378 343, 342, 341, 340, 339, 338, 337, 336, 335, 334, 333, 332, 331, 330,
michael@0 379 329, 328, 327, 326, 325, 324, 323, 322, 321, 320, 319, 318, 317, 316,
michael@0 380 315, 314, 313, 312, 311, 310, 309, 308, 307, 306, 305, 304, 303, 302,
michael@0 381 451, 450, 449, 448, 447, 465, 464, 463, 462, 461, 460, 459, 458, 457,
michael@0 382 456, 455, 454, 453, 452, 457, 456, 455, 454, 453, 452, 745, 744, 743,
michael@0 383 742, 741, 740, 739, 738, 737, 736, 735, 734, 733, 732, 731, 730, 729,
michael@0 384 728, 727, 726, 725, 724, 723, 722, 721, 720, 719, 718, 717, 716, 715,
michael@0 385 714, 713, 712, 711, 710, 709, 708, 707, 706, 705, 704, 703, 702, 701,
michael@0 386 700, 699, 698, 697, 696, 695, 694, 693, 692, 691, 690, 689, 688, 687,
michael@0 387 686, 685, 684, 683, 682, 681, 680, 679, 678, 677, 676 };
michael@0 388
michael@0 389 int32_t sAggregateBatchTestRedoOrderArr[] = {
michael@0 390 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
michael@0 391 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
michael@0 392 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
michael@0 393 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
michael@0 394 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
michael@0 395 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
michael@0 396 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98,
michael@0 397 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
michael@0 398 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
michael@0 399 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
michael@0 400 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
michael@0 401 295, 296, 297, 298, 299, 300, 301, 448, 449, 450, 451, 452, 453, 454,
michael@0 402 455, 456, 457, 458 };
michael@0 403
michael@0 404 #define TEST_TXMGR_IF_RELEASE(tx) if (tx) tx->Release(); // Release but don't clear pointer!
michael@0 405
michael@0 406 class TestTransaction : public nsITransaction
michael@0 407 {
michael@0 408 public:
michael@0 409
michael@0 410 TestTransaction() {}
michael@0 411 virtual ~TestTransaction() {}
michael@0 412
michael@0 413 NS_DECL_ISUPPORTS
michael@0 414 };
michael@0 415
michael@0 416 NS_IMPL_ISUPPORTS(TestTransaction, nsITransaction)
michael@0 417
michael@0 418 class SimpleTransaction : public TestTransaction
michael@0 419 {
michael@0 420 protected:
michael@0 421
michael@0 422 #define NONE_FLAG 0
michael@0 423 #define THROWS_DO_ERROR_FLAG 1
michael@0 424 #define THROWS_UNDO_ERROR_FLAG 2
michael@0 425 #define THROWS_REDO_ERROR_FLAG 4
michael@0 426 #define MERGE_FLAG 8
michael@0 427 #define TRANSIENT_FLAG 16
michael@0 428 #define BATCH_FLAG 32
michael@0 429 #define ALL_ERROR_FLAGS (THROWS_DO_ERROR_FLAG|THROWS_UNDO_ERROR_FLAG|THROWS_REDO_ERROR_FLAG)
michael@0 430
michael@0 431 int32_t mVal;
michael@0 432 int32_t mFlags;
michael@0 433
michael@0 434 public:
michael@0 435
michael@0 436 SimpleTransaction(int32_t aFlags=NONE_FLAG)
michael@0 437 : mVal(++sConstructorCount), mFlags(aFlags)
michael@0 438 {}
michael@0 439
michael@0 440 virtual ~SimpleTransaction()
michael@0 441 {
michael@0 442 //
michael@0 443 // Make sure transactions are being destroyed in the order we expect!
michael@0 444 // Notice that we don't check to see if we go past the end of the array.
michael@0 445 // This is done on purpose since we want to crash if the order array is out
michael@0 446 // of date.
michael@0 447 //
michael@0 448 /* Disabled because the current cycle collector doesn't delete
michael@0 449 cycle collectable objects synchronously, nor doesn't guarantee any order.
michael@0 450 if (sDestructorOrderArr && mVal != sDestructorOrderArr[sDestructorCount]) {
michael@0 451 fail("~SimpleTransaction expected %d got %d.\n",
michael@0 452 mVal, sDestructorOrderArr[sDestructorCount]);
michael@0 453 exit(-1);
michael@0 454 }
michael@0 455 */
michael@0 456
michael@0 457 ++sDestructorCount;
michael@0 458
michael@0 459 #ifdef ENABLE_DEBUG_PRINTFS
michael@0 460 printf("\n~SimpleTransaction: %d - 0x%.8x\n", mVal, (int32_t)this);
michael@0 461 #endif // ENABLE_DEBUG_PRINTFS
michael@0 462
michael@0 463 mVal = -1;
michael@0 464 }
michael@0 465
michael@0 466 NS_IMETHOD DoTransaction()
michael@0 467 {
michael@0 468 //
michael@0 469 // Make sure DoTransaction() is called in the order we expect!
michael@0 470 // Notice that we don't check to see if we go past the end of the array.
michael@0 471 // This is done on purpose since we want to crash if the order array is out
michael@0 472 // of date.
michael@0 473 //
michael@0 474 if (sDoOrderArr && mVal != sDoOrderArr[sDoCount]) {
michael@0 475 fail("DoTransaction expected %d got %d.\n",
michael@0 476 mVal, sDoOrderArr[sDoCount]);
michael@0 477 exit(-1);
michael@0 478 }
michael@0 479
michael@0 480 ++sDoCount;
michael@0 481
michael@0 482 #ifdef ENABLE_DEBUG_PRINTFS
michael@0 483 printf("\nSimpleTransaction.DoTransaction: %d - 0x%.8x\n", mVal, (int32_t)this);
michael@0 484 #endif // ENABLE_DEBUG_PRINTFS
michael@0 485
michael@0 486 return (mFlags & THROWS_DO_ERROR_FLAG) ? NS_ERROR_FAILURE : NS_OK;
michael@0 487 }
michael@0 488
michael@0 489 NS_IMETHOD UndoTransaction()
michael@0 490 {
michael@0 491 //
michael@0 492 // Make sure UndoTransaction() is called in the order we expect!
michael@0 493 // Notice that we don't check to see if we go past the end of the array.
michael@0 494 // This is done on purpose since we want to crash if the order array is out
michael@0 495 // of date.
michael@0 496 //
michael@0 497 if (sUndoOrderArr && mVal != sUndoOrderArr[sUndoCount]) {
michael@0 498 fail("UndoTransaction expected %d got %d.\n",
michael@0 499 mVal, sUndoOrderArr[sUndoCount]);
michael@0 500 exit(-1);
michael@0 501 }
michael@0 502
michael@0 503 ++sUndoCount;
michael@0 504
michael@0 505 #ifdef ENABLE_DEBUG_PRINTFS
michael@0 506 printf("\nSimpleTransaction.Undo: %d - 0x%.8x\n", mVal, (int32_t)this);
michael@0 507 #endif // ENABLE_DEBUG_PRINTFS
michael@0 508
michael@0 509 return (mFlags & THROWS_UNDO_ERROR_FLAG) ? NS_ERROR_FAILURE : NS_OK;
michael@0 510 }
michael@0 511
michael@0 512 NS_IMETHOD RedoTransaction()
michael@0 513 {
michael@0 514 //
michael@0 515 // Make sure RedoTransaction() is called in the order we expect!
michael@0 516 // Notice that we don't check to see if we go past the end of the array.
michael@0 517 // This is done on purpose since we want to crash if the order array is out
michael@0 518 // of date.
michael@0 519 //
michael@0 520 if (sRedoOrderArr && mVal != sRedoOrderArr[sRedoCount]) {
michael@0 521 fail("RedoTransaction expected %d got %d.\n",
michael@0 522 mVal, sRedoOrderArr[sRedoCount]);
michael@0 523 exit(-1);
michael@0 524 }
michael@0 525
michael@0 526 ++sRedoCount;
michael@0 527
michael@0 528 #ifdef ENABLE_DEBUG_PRINTFS
michael@0 529 printf("\nSimpleTransaction.Redo: %d - 0x%.8x\n", mVal, (int32_t)this);
michael@0 530 #endif // ENABLE_DEBUG_PRINTFS
michael@0 531
michael@0 532 return (mFlags & THROWS_REDO_ERROR_FLAG) ? NS_ERROR_FAILURE : NS_OK;
michael@0 533 }
michael@0 534
michael@0 535 NS_IMETHOD GetIsTransient(bool *aIsTransient)
michael@0 536 {
michael@0 537 if (aIsTransient)
michael@0 538 *aIsTransient = (mFlags & TRANSIENT_FLAG) ? true : false;
michael@0 539
michael@0 540 return NS_OK;
michael@0 541 }
michael@0 542
michael@0 543 NS_IMETHOD Merge(nsITransaction *aTransaction, bool *aDidMerge)
michael@0 544 {
michael@0 545 if (aDidMerge)
michael@0 546 *aDidMerge = (mFlags & MERGE_FLAG) ? true : false;
michael@0 547
michael@0 548 return NS_OK;
michael@0 549 }
michael@0 550 };
michael@0 551
michael@0 552 class AggregateTransaction : public SimpleTransaction
michael@0 553 {
michael@0 554 private:
michael@0 555
michael@0 556 AggregateTransaction(nsITransactionManager *aTXMgr, int32_t aLevel,
michael@0 557 int32_t aNumber, int32_t aMaxLevel,
michael@0 558 int32_t aNumChildrenPerNode,
michael@0 559 int32_t aFlags)
michael@0 560 {
michael@0 561 mLevel = aLevel;
michael@0 562 mNumber = aNumber;
michael@0 563 mTXMgr = aTXMgr;
michael@0 564 mFlags = aFlags & (~ALL_ERROR_FLAGS);
michael@0 565 mErrorFlags = aFlags & ALL_ERROR_FLAGS;
michael@0 566 mTXMgr = aTXMgr;
michael@0 567 mMaxLevel = aMaxLevel;
michael@0 568 mNumChildrenPerNode = aNumChildrenPerNode;
michael@0 569 }
michael@0 570
michael@0 571 nsITransactionManager *mTXMgr;
michael@0 572
michael@0 573 int32_t mLevel;
michael@0 574 int32_t mNumber;
michael@0 575 int32_t mErrorFlags;
michael@0 576
michael@0 577 int32_t mMaxLevel;
michael@0 578 int32_t mNumChildrenPerNode;
michael@0 579
michael@0 580 public:
michael@0 581
michael@0 582 AggregateTransaction(nsITransactionManager *aTXMgr,
michael@0 583 int32_t aMaxLevel, int32_t aNumChildrenPerNode,
michael@0 584 int32_t aFlags=NONE_FLAG)
michael@0 585 {
michael@0 586 mLevel = 1;
michael@0 587 mNumber = 1;
michael@0 588 mFlags = aFlags & (~ALL_ERROR_FLAGS);
michael@0 589 mErrorFlags = aFlags & ALL_ERROR_FLAGS;
michael@0 590 mTXMgr = aTXMgr;
michael@0 591 mMaxLevel = aMaxLevel;
michael@0 592 mNumChildrenPerNode = aNumChildrenPerNode;
michael@0 593 }
michael@0 594
michael@0 595 virtual ~AggregateTransaction()
michael@0 596 {
michael@0 597 // printf("~AggregateTransaction(0x%.8x) - %3d (%3d)\n", this, mLevel, mVal);
michael@0 598 }
michael@0 599
michael@0 600 NS_IMETHOD DoTransaction()
michael@0 601 {
michael@0 602 if (mLevel >= mMaxLevel) {
michael@0 603 // Only leaf nodes can throw errors!
michael@0 604 mFlags |= mErrorFlags;
michael@0 605 }
michael@0 606
michael@0 607 nsresult result = SimpleTransaction::DoTransaction();
michael@0 608
michael@0 609 if (NS_FAILED(result)) {
michael@0 610 // fail("QueryInterface() failed for transaction level %d. (%d)\n",
michael@0 611 // mLevel, result);
michael@0 612 return result;
michael@0 613 }
michael@0 614
michael@0 615 if (mLevel >= mMaxLevel)
michael@0 616 return NS_OK;
michael@0 617
michael@0 618 if (mFlags & BATCH_FLAG) {
michael@0 619 result = mTXMgr->BeginBatch(nullptr);
michael@0 620 if (NS_FAILED(result)) {
michael@0 621 return result;
michael@0 622 }
michael@0 623 }
michael@0 624
michael@0 625 int32_t cLevel = mLevel + 1;
michael@0 626
michael@0 627 for (int i = 1; i <= mNumChildrenPerNode; i++) {
michael@0 628 int32_t flags = mErrorFlags & THROWS_DO_ERROR_FLAG;
michael@0 629
michael@0 630 if ((mErrorFlags & THROWS_REDO_ERROR_FLAG) && i == mNumChildrenPerNode) {
michael@0 631 // Make the rightmost leaf transaction throw the error!
michael@0 632 flags = THROWS_REDO_ERROR_FLAG;
michael@0 633 mErrorFlags = mErrorFlags & (~THROWS_REDO_ERROR_FLAG);
michael@0 634 }
michael@0 635 else if ((mErrorFlags & THROWS_UNDO_ERROR_FLAG)
michael@0 636 && i == 1) {
michael@0 637 // Make the leftmost leaf transaction throw the error!
michael@0 638 flags = THROWS_UNDO_ERROR_FLAG;
michael@0 639 mErrorFlags = mErrorFlags & (~THROWS_UNDO_ERROR_FLAG);
michael@0 640 }
michael@0 641
michael@0 642 flags |= mFlags & BATCH_FLAG;
michael@0 643
michael@0 644 AggregateTransaction *tximpl =
michael@0 645 new AggregateTransaction(mTXMgr, cLevel, i, mMaxLevel,
michael@0 646 mNumChildrenPerNode, flags);
michael@0 647
michael@0 648 if (!tximpl) {
michael@0 649 fail("Failed to allocate AggregateTransaction %d, level %d. (%d)\n",
michael@0 650 i, mLevel, result);
michael@0 651
michael@0 652 if (mFlags & BATCH_FLAG)
michael@0 653 mTXMgr->EndBatch(false);
michael@0 654
michael@0 655 return NS_ERROR_OUT_OF_MEMORY;
michael@0 656 }
michael@0 657
michael@0 658 nsITransaction *tx = 0;
michael@0 659 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 660 if (NS_FAILED(result)) {
michael@0 661 fail("QueryInterface() failed for transaction %d, level %d. (%d)\n",
michael@0 662 i, mLevel, result);
michael@0 663
michael@0 664 if (mFlags & BATCH_FLAG)
michael@0 665 mTXMgr->EndBatch(false);
michael@0 666
michael@0 667 return result;
michael@0 668 }
michael@0 669
michael@0 670 result = mTXMgr->DoTransaction(tx);
michael@0 671
michael@0 672 if (NS_FAILED(result)) {
michael@0 673 // fail("Failed to execute transaction %d, level %d. (%d)\n",
michael@0 674 // i, mLevel, result);
michael@0 675 tx->Release();
michael@0 676
michael@0 677 if (mFlags & BATCH_FLAG)
michael@0 678 mTXMgr->EndBatch(false);
michael@0 679
michael@0 680 return result;
michael@0 681 }
michael@0 682
michael@0 683 tx->Release();
michael@0 684 }
michael@0 685
michael@0 686 if (mFlags & BATCH_FLAG)
michael@0 687 mTXMgr->EndBatch(false);
michael@0 688
michael@0 689 return result;
michael@0 690 }
michael@0 691 };
michael@0 692
michael@0 693 class TestTransactionFactory
michael@0 694 {
michael@0 695 public:
michael@0 696 virtual TestTransaction *create(nsITransactionManager *txmgr, int32_t flags) = 0;
michael@0 697 };
michael@0 698
michael@0 699 class SimpleTransactionFactory : public TestTransactionFactory
michael@0 700 {
michael@0 701 public:
michael@0 702
michael@0 703 TestTransaction *create(nsITransactionManager *txmgr, int32_t flags)
michael@0 704 {
michael@0 705 return (TestTransaction *)new SimpleTransaction(flags);
michael@0 706 }
michael@0 707 };
michael@0 708
michael@0 709 class AggregateTransactionFactory : public TestTransactionFactory
michael@0 710 {
michael@0 711 private:
michael@0 712
michael@0 713 int32_t mMaxLevel;
michael@0 714 int32_t mNumChildrenPerNode;
michael@0 715 int32_t mFixedFlags;
michael@0 716
michael@0 717 public:
michael@0 718
michael@0 719 AggregateTransactionFactory(int32_t aMaxLevel, int32_t aNumChildrenPerNode,
michael@0 720 int32_t aFixedFlags=NONE_FLAG)
michael@0 721 : mMaxLevel(aMaxLevel), mNumChildrenPerNode(aNumChildrenPerNode),
michael@0 722 mFixedFlags(aFixedFlags)
michael@0 723 {
michael@0 724 }
michael@0 725
michael@0 726 virtual TestTransaction *create(nsITransactionManager *txmgr, int32_t flags)
michael@0 727 {
michael@0 728 return (TestTransaction *)new AggregateTransaction(txmgr, mMaxLevel,
michael@0 729 mNumChildrenPerNode,
michael@0 730 flags | mFixedFlags);
michael@0 731 }
michael@0 732 };
michael@0 733
michael@0 734 void
michael@0 735 reset_globals()
michael@0 736 {
michael@0 737 sConstructorCount = 0;
michael@0 738
michael@0 739 sDestructorCount = 0;
michael@0 740 sDestructorOrderArr = 0;
michael@0 741
michael@0 742 sDoCount = 0;
michael@0 743 sDoOrderArr = 0;
michael@0 744
michael@0 745 sUndoCount = 0;
michael@0 746 sUndoOrderArr = 0;
michael@0 747
michael@0 748 sRedoCount = 0;
michael@0 749 sRedoOrderArr = 0;
michael@0 750 }
michael@0 751
michael@0 752 /**
michael@0 753 * Test behaviors in non-batch mode.
michael@0 754 **/
michael@0 755 nsresult
michael@0 756 quick_test(TestTransactionFactory *factory)
michael@0 757 {
michael@0 758 nsresult result;
michael@0 759
michael@0 760 /*******************************************************************
michael@0 761 *
michael@0 762 * Create a transaction manager implementation:
michael@0 763 *
michael@0 764 *******************************************************************/
michael@0 765
michael@0 766 nsCOMPtr<nsITransactionManager> mgr =
michael@0 767 do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &result);
michael@0 768 if (NS_FAILED(result) || !mgr) {
michael@0 769 fail("Failed to create Transaction Manager instance.\n");
michael@0 770 return NS_ERROR_OUT_OF_MEMORY;
michael@0 771 }
michael@0 772
michael@0 773 passed("Create transaction manager instance");
michael@0 774
michael@0 775 /*******************************************************************
michael@0 776 *
michael@0 777 * Call DoTransaction() with a null transaction:
michael@0 778 *
michael@0 779 *******************************************************************/
michael@0 780
michael@0 781 result = mgr->DoTransaction(0);
michael@0 782
michael@0 783 if (result != NS_ERROR_NULL_POINTER) {
michael@0 784 fail("DoTransaction() returned unexpected error. (%d)\n", result);
michael@0 785 return result;
michael@0 786 }
michael@0 787
michael@0 788 passed("Call DoTransaction() with null transaction");
michael@0 789
michael@0 790 /*******************************************************************
michael@0 791 *
michael@0 792 * Call UndoTransaction() with an empty undo stack:
michael@0 793 *
michael@0 794 *******************************************************************/
michael@0 795
michael@0 796 result = mgr->UndoTransaction();
michael@0 797
michael@0 798 if (NS_FAILED(result)) {
michael@0 799 fail("Undo on empty undo stack failed. (%d)\n", result);
michael@0 800 return result;
michael@0 801 }
michael@0 802
michael@0 803 passed("Call UndoTransaction() with empty undo stack");
michael@0 804
michael@0 805 /*******************************************************************
michael@0 806 *
michael@0 807 * Call RedoTransaction() with an empty redo stack:
michael@0 808 *
michael@0 809 *******************************************************************/
michael@0 810
michael@0 811 result = mgr->RedoTransaction();
michael@0 812
michael@0 813 if (NS_FAILED(result)) {
michael@0 814 fail("Redo on empty redo stack failed. (%d)\n", result);
michael@0 815 return result;
michael@0 816 }
michael@0 817
michael@0 818 passed("Call RedoTransaction() with empty redo stack");
michael@0 819
michael@0 820 /*******************************************************************
michael@0 821 *
michael@0 822 * Call SetMaxTransactionCount(-1) with empty undo and redo stacks:
michael@0 823 *
michael@0 824 *******************************************************************/
michael@0 825
michael@0 826 result = mgr->SetMaxTransactionCount(-1);
michael@0 827
michael@0 828 if (NS_FAILED(result)) {
michael@0 829 fail("SetMaxTransactionCount(-1) failed. (%d)\n", result);
michael@0 830 return result;
michael@0 831 }
michael@0 832
michael@0 833 passed("Call SetMaxTransactionCount(-1) with empty undo and redo stacks");
michael@0 834
michael@0 835 /*******************************************************************
michael@0 836 *
michael@0 837 * Call SetMaxTransactionCount(0) with empty undo and redo stacks:
michael@0 838 *
michael@0 839 *******************************************************************/
michael@0 840
michael@0 841 result = mgr->SetMaxTransactionCount(0);
michael@0 842
michael@0 843 if (NS_FAILED(result)) {
michael@0 844 fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
michael@0 845 return result;
michael@0 846 }
michael@0 847
michael@0 848 passed("Call SetMaxTransactionCount(0) with empty undo and redo stacks");
michael@0 849
michael@0 850 /*******************************************************************
michael@0 851 *
michael@0 852 * Call SetMaxTransactionCount(10) with empty undo and redo stacks:
michael@0 853 *
michael@0 854 *******************************************************************/
michael@0 855
michael@0 856 result = mgr->SetMaxTransactionCount(10);
michael@0 857
michael@0 858 if (NS_FAILED(result)) {
michael@0 859 fail("SetMaxTransactionCount(10) failed. (%d)\n", result);
michael@0 860 return result;
michael@0 861 }
michael@0 862
michael@0 863 passed("Call SetMaxTransactionCount(10) with empty undo and redo stacks");
michael@0 864
michael@0 865 /*******************************************************************
michael@0 866 *
michael@0 867 * Call Clear() with empty undo and redo stacks:
michael@0 868 *
michael@0 869 *******************************************************************/
michael@0 870
michael@0 871 result = mgr->Clear();
michael@0 872 if (NS_FAILED(result)) {
michael@0 873 fail("Clear on empty undo and redo stack failed. (%d)\n", result);
michael@0 874 return result;
michael@0 875 }
michael@0 876
michael@0 877 passed("Call Clear() with empty undo and redo stack");
michael@0 878
michael@0 879 int32_t numitems;
michael@0 880
michael@0 881 /*******************************************************************
michael@0 882 *
michael@0 883 * Call GetNumberOfUndoItems() with an empty undo stack:
michael@0 884 *
michael@0 885 *******************************************************************/
michael@0 886
michael@0 887 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 888
michael@0 889 if (NS_FAILED(result)) {
michael@0 890 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 891 result);
michael@0 892 return result;
michael@0 893 }
michael@0 894
michael@0 895 if (numitems != 0) {
michael@0 896 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 897 numitems, result);
michael@0 898 return NS_ERROR_FAILURE;
michael@0 899 }
michael@0 900
michael@0 901 passed("Call GetNumberOfUndoItems() with empty undo stack");
michael@0 902
michael@0 903 /*******************************************************************
michael@0 904 *
michael@0 905 * Call GetNumberOfRedoItems() with an empty redo stack:
michael@0 906 *
michael@0 907 *******************************************************************/
michael@0 908
michael@0 909 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 910
michael@0 911 if (NS_FAILED(result)) {
michael@0 912 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 913 result);
michael@0 914 return result;
michael@0 915 }
michael@0 916
michael@0 917 if (numitems != 0) {
michael@0 918 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 919 numitems, result);
michael@0 920 return NS_ERROR_FAILURE;
michael@0 921 }
michael@0 922
michael@0 923 passed("Call GetNumberOfRedoItems() with empty redo stack");
michael@0 924
michael@0 925 nsITransaction *tx;
michael@0 926
michael@0 927 /*******************************************************************
michael@0 928 *
michael@0 929 * Call PeekUndoStack() with an empty undo stack:
michael@0 930 *
michael@0 931 *******************************************************************/
michael@0 932
michael@0 933 tx = 0;
michael@0 934 result = mgr->PeekUndoStack(&tx);
michael@0 935
michael@0 936 TEST_TXMGR_IF_RELEASE(tx); // Don't hold onto any references!
michael@0 937
michael@0 938 if (NS_FAILED(result)) {
michael@0 939 fail("PeekUndoStack() on empty undo stack failed. (%d)\n", result);
michael@0 940 return result;
michael@0 941 }
michael@0 942
michael@0 943 if (tx != 0) {
michael@0 944 fail("PeekUndoStack() on empty undo stack failed. (%d)\n", result);
michael@0 945 return NS_ERROR_FAILURE;
michael@0 946 }
michael@0 947
michael@0 948 passed("Call PeekUndoStack() with empty undo stack");
michael@0 949
michael@0 950 /*******************************************************************
michael@0 951 *
michael@0 952 * Call PeekRedoStack() with an empty undo stack:
michael@0 953 *
michael@0 954 *******************************************************************/
michael@0 955
michael@0 956 tx = 0;
michael@0 957 result = mgr->PeekRedoStack(&tx);
michael@0 958
michael@0 959 TEST_TXMGR_IF_RELEASE(tx); // Don't hold onto any references!
michael@0 960
michael@0 961 if (NS_FAILED(result)) {
michael@0 962 fail("PeekRedoStack() on empty redo stack failed. (%d)\n", result);
michael@0 963 return result;
michael@0 964 }
michael@0 965
michael@0 966 if (tx != 0) {
michael@0 967 fail("PeekRedoStack() on empty redo stack failed. (%d)\n", result);
michael@0 968 return NS_ERROR_FAILURE;
michael@0 969 }
michael@0 970
michael@0 971 passed("Call PeekRedoStack() with empty undo stack");
michael@0 972
michael@0 973 /*******************************************************************
michael@0 974 *
michael@0 975 * Call AddListener() with a null listener pointer:
michael@0 976 *
michael@0 977 *******************************************************************/
michael@0 978
michael@0 979 result = mgr->AddListener(0);
michael@0 980
michael@0 981 if (result != NS_ERROR_NULL_POINTER) {
michael@0 982 fail("AddListener() returned unexpected error. (%d)\n", result);
michael@0 983 return result;
michael@0 984 }
michael@0 985
michael@0 986 passed("Call AddListener() with null listener");
michael@0 987
michael@0 988 /*******************************************************************
michael@0 989 *
michael@0 990 * Call RemoveListener() with a null listener pointer:
michael@0 991 *
michael@0 992 *******************************************************************/
michael@0 993
michael@0 994 result = mgr->RemoveListener(0);
michael@0 995
michael@0 996 if (result != NS_ERROR_NULL_POINTER) {
michael@0 997 fail("RemoveListener() returned unexpected error. (%d)\n", result);
michael@0 998 return result;
michael@0 999 }
michael@0 1000
michael@0 1001 passed("Call RemoveListener() with null listener");
michael@0 1002
michael@0 1003 int32_t i;
michael@0 1004 TestTransaction *tximpl;
michael@0 1005 nsITransaction *u1, *u2;
michael@0 1006 nsITransaction *r1, *r2;
michael@0 1007
michael@0 1008 /*******************************************************************
michael@0 1009 *
michael@0 1010 * Test coalescing by executing a transaction that can merge any
michael@0 1011 * command into itself. Then execute 20 transaction. Afterwards,
michael@0 1012 * we should still have the first transaction sitting on the undo
michael@0 1013 * stack. Then clear the undo and redo stacks.
michael@0 1014 *
michael@0 1015 *******************************************************************/
michael@0 1016
michael@0 1017 result = mgr->SetMaxTransactionCount(10);
michael@0 1018
michael@0 1019 if (NS_FAILED(result)) {
michael@0 1020 fail("SetMaxTransactionCount(10) failed. (%d)\n", result);
michael@0 1021 return result;
michael@0 1022 }
michael@0 1023
michael@0 1024
michael@0 1025 tximpl = factory->create(mgr, MERGE_FLAG);
michael@0 1026
michael@0 1027 if (!tximpl) {
michael@0 1028 fail("Failed to allocate initial transaction.\n");
michael@0 1029 return NS_ERROR_OUT_OF_MEMORY;
michael@0 1030 }
michael@0 1031
michael@0 1032 tx = 0;
michael@0 1033
michael@0 1034 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 1035
michael@0 1036 if (NS_FAILED(result)) {
michael@0 1037 fail("QueryInterface() failed for initial transaction. (%d)\n",
michael@0 1038 result);
michael@0 1039 return result;
michael@0 1040 }
michael@0 1041
michael@0 1042 result = mgr->DoTransaction(tx);
michael@0 1043
michael@0 1044 if (NS_FAILED(result)) {
michael@0 1045 fail("Failed to execute initial transaction. (%d)\n", result);
michael@0 1046 return result;
michael@0 1047 }
michael@0 1048
michael@0 1049 tx->Release();
michael@0 1050
michael@0 1051 u1 = u2 = r1 = r2 = 0;
michael@0 1052
michael@0 1053 result = mgr->PeekUndoStack(&u1);
michael@0 1054
michael@0 1055 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 1056
michael@0 1057 if (NS_FAILED(result)) {
michael@0 1058 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 1059 return result;
michael@0 1060 }
michael@0 1061
michael@0 1062 if (u1 != tx) {
michael@0 1063 fail("Top of undo stack is different!. (%d)\n", result);
michael@0 1064 return NS_ERROR_FAILURE;
michael@0 1065 }
michael@0 1066
michael@0 1067 result = mgr->PeekRedoStack(&r1);
michael@0 1068
michael@0 1069 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 1070
michael@0 1071 if (NS_FAILED(result)) {
michael@0 1072 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 1073 return result;
michael@0 1074 }
michael@0 1075
michael@0 1076 for (i = 1; i <= 20; i++) {
michael@0 1077 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 1078
michael@0 1079 if (!tximpl) {
michael@0 1080 fail("Failed to allocate transaction %d.\n", i);
michael@0 1081 return NS_ERROR_OUT_OF_MEMORY;
michael@0 1082 }
michael@0 1083
michael@0 1084 tx = 0;
michael@0 1085 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 1086 if (NS_FAILED(result)) {
michael@0 1087 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 1088 i, result);
michael@0 1089 return result;
michael@0 1090 }
michael@0 1091
michael@0 1092 result = mgr->DoTransaction(tx);
michael@0 1093 if (NS_FAILED(result)) {
michael@0 1094 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 1095 return result;
michael@0 1096 }
michael@0 1097
michael@0 1098 tx->Release();
michael@0 1099 }
michael@0 1100
michael@0 1101 result = mgr->PeekUndoStack(&u2);
michael@0 1102
michael@0 1103 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 1104
michael@0 1105 if (NS_FAILED(result)) {
michael@0 1106 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 1107 return result;
michael@0 1108 }
michael@0 1109
michael@0 1110 if (u1 != u2) {
michael@0 1111 fail("Top of undo stack changed. (%d)\n", result);
michael@0 1112 return NS_ERROR_FAILURE;
michael@0 1113 }
michael@0 1114
michael@0 1115 result = mgr->PeekRedoStack(&r2);
michael@0 1116
michael@0 1117 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 1118
michael@0 1119 if (NS_FAILED(result)) {
michael@0 1120 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 1121 return result;
michael@0 1122 }
michael@0 1123
michael@0 1124 if (r1 != r2) {
michael@0 1125 fail("Top of redo stack changed. (%d)\n", result);
michael@0 1126 return NS_ERROR_FAILURE;
michael@0 1127 }
michael@0 1128
michael@0 1129 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1130
michael@0 1131 if (NS_FAILED(result)) {
michael@0 1132 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 1133 result);
michael@0 1134 return result;
michael@0 1135 }
michael@0 1136
michael@0 1137 if (numitems != 1) {
michael@0 1138 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 1139 numitems, result);
michael@0 1140 return NS_ERROR_FAILURE;
michael@0 1141 }
michael@0 1142
michael@0 1143 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1144
michael@0 1145 if (NS_FAILED(result)) {
michael@0 1146 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 1147 result);
michael@0 1148 return result;
michael@0 1149 }
michael@0 1150
michael@0 1151 if (numitems != 0) {
michael@0 1152 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 1153 numitems, result);
michael@0 1154 return NS_ERROR_FAILURE;
michael@0 1155 }
michael@0 1156
michael@0 1157 result = mgr->Clear();
michael@0 1158 if (NS_FAILED(result)) {
michael@0 1159 fail("Clear() failed. (%d)\n", result);
michael@0 1160 return result;
michael@0 1161 }
michael@0 1162
michael@0 1163 passed("Test coalescing of transactions");
michael@0 1164
michael@0 1165 /*******************************************************************
michael@0 1166 *
michael@0 1167 * Execute 20 transactions. Afterwards, we should have 10
michael@0 1168 * transactions on the undo stack:
michael@0 1169 *
michael@0 1170 *******************************************************************/
michael@0 1171
michael@0 1172 for (i = 1; i <= 20; i++) {
michael@0 1173 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 1174
michael@0 1175 if (!tximpl) {
michael@0 1176 fail("Failed to allocate transaction %d.\n", i);
michael@0 1177 return NS_ERROR_OUT_OF_MEMORY;
michael@0 1178 }
michael@0 1179
michael@0 1180 tx = 0;
michael@0 1181 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 1182 if (NS_FAILED(result)) {
michael@0 1183 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 1184 i, result);
michael@0 1185 return result;
michael@0 1186 }
michael@0 1187
michael@0 1188 result = mgr->DoTransaction(tx);
michael@0 1189 if (NS_FAILED(result)) {
michael@0 1190 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 1191 return result;
michael@0 1192 }
michael@0 1193
michael@0 1194 tx->Release();
michael@0 1195 }
michael@0 1196
michael@0 1197 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1198
michael@0 1199 if (NS_FAILED(result)) {
michael@0 1200 fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
michael@0 1201 result);
michael@0 1202 return result;
michael@0 1203 }
michael@0 1204
michael@0 1205 if (numitems != 10) {
michael@0 1206 fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
michael@0 1207 numitems, result);
michael@0 1208 return NS_ERROR_FAILURE;
michael@0 1209 }
michael@0 1210
michael@0 1211 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1212
michael@0 1213 if (NS_FAILED(result)) {
michael@0 1214 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 1215 result);
michael@0 1216 return result;
michael@0 1217 }
michael@0 1218
michael@0 1219 if (numitems != 0) {
michael@0 1220 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 1221 numitems, result);
michael@0 1222 return NS_ERROR_FAILURE;
michael@0 1223 }
michael@0 1224
michael@0 1225 passed("Execute 20 transactions");
michael@0 1226
michael@0 1227 /*******************************************************************
michael@0 1228 *
michael@0 1229 * Execute 20 transient transactions. Afterwards, we should still
michael@0 1230 * have the same 10 transactions on the undo stack:
michael@0 1231 *
michael@0 1232 *******************************************************************/
michael@0 1233
michael@0 1234 u1 = u2 = r1 = r2 = 0;
michael@0 1235
michael@0 1236 result = mgr->PeekUndoStack(&u1);
michael@0 1237
michael@0 1238 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 1239
michael@0 1240 if (NS_FAILED(result)) {
michael@0 1241 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 1242 return result;
michael@0 1243 }
michael@0 1244
michael@0 1245 result = mgr->PeekRedoStack(&r1);
michael@0 1246
michael@0 1247 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 1248
michael@0 1249 if (NS_FAILED(result)) {
michael@0 1250 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 1251 return result;
michael@0 1252 }
michael@0 1253
michael@0 1254 for (i = 1; i <= 20; i++) {
michael@0 1255 tximpl = factory->create(mgr, TRANSIENT_FLAG);
michael@0 1256
michael@0 1257 if (!tximpl) {
michael@0 1258 fail("Failed to allocate transaction %d.\n", i);
michael@0 1259 return NS_ERROR_OUT_OF_MEMORY;
michael@0 1260 }
michael@0 1261
michael@0 1262 tx = 0;
michael@0 1263 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 1264 if (NS_FAILED(result)) {
michael@0 1265 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 1266 i, result);
michael@0 1267 return result;
michael@0 1268 }
michael@0 1269
michael@0 1270 result = mgr->DoTransaction(tx);
michael@0 1271 if (NS_FAILED(result)) {
michael@0 1272 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 1273 return result;
michael@0 1274 }
michael@0 1275
michael@0 1276 tx->Release();
michael@0 1277 }
michael@0 1278
michael@0 1279 result = mgr->PeekUndoStack(&u2);
michael@0 1280
michael@0 1281 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 1282
michael@0 1283 if (NS_FAILED(result)) {
michael@0 1284 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 1285 return result;
michael@0 1286 }
michael@0 1287
michael@0 1288 if (u1 != u2) {
michael@0 1289 fail("Top of undo stack changed. (%d)\n", result);
michael@0 1290 return NS_ERROR_FAILURE;
michael@0 1291 }
michael@0 1292
michael@0 1293 result = mgr->PeekRedoStack(&r2);
michael@0 1294
michael@0 1295 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 1296
michael@0 1297 if (NS_FAILED(result)) {
michael@0 1298 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 1299 return result;
michael@0 1300 }
michael@0 1301
michael@0 1302 if (r1 != r2) {
michael@0 1303 fail("Top of redo stack changed. (%d)\n", result);
michael@0 1304 return NS_ERROR_FAILURE;
michael@0 1305 }
michael@0 1306
michael@0 1307 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1308
michael@0 1309 if (NS_FAILED(result)) {
michael@0 1310 fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
michael@0 1311 result);
michael@0 1312 return result;
michael@0 1313 }
michael@0 1314
michael@0 1315 if (numitems != 10) {
michael@0 1316 fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
michael@0 1317 numitems, result);
michael@0 1318 return NS_ERROR_FAILURE;
michael@0 1319 }
michael@0 1320
michael@0 1321 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1322
michael@0 1323 if (NS_FAILED(result)) {
michael@0 1324 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 1325 result);
michael@0 1326 return result;
michael@0 1327 }
michael@0 1328
michael@0 1329 if (numitems != 0) {
michael@0 1330 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 1331 numitems, result);
michael@0 1332 return NS_ERROR_FAILURE;
michael@0 1333 }
michael@0 1334
michael@0 1335 passed("Execute 20 transient transactions");
michael@0 1336
michael@0 1337 /*******************************************************************
michael@0 1338 *
michael@0 1339 * Undo 4 transactions. Afterwards, we should have 6 transactions
michael@0 1340 * on the undo stack, and 4 on the redo stack:
michael@0 1341 *
michael@0 1342 *******************************************************************/
michael@0 1343
michael@0 1344 for (i = 1; i <= 4; i++) {
michael@0 1345 result = mgr->UndoTransaction();
michael@0 1346 if (NS_FAILED(result)) {
michael@0 1347 fail("Failed to undo transaction %d. (%d)\n", i, result);
michael@0 1348 return result;
michael@0 1349 }
michael@0 1350 }
michael@0 1351
michael@0 1352 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1353
michael@0 1354 if (NS_FAILED(result)) {
michael@0 1355 fail("GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",
michael@0 1356 result);
michael@0 1357 return result;
michael@0 1358 }
michael@0 1359
michael@0 1360 if (numitems != 6) {
michael@0 1361 fail("GetNumberOfUndoItems() expected 6 got %d. (%d)\n",
michael@0 1362 numitems, result);
michael@0 1363 return NS_ERROR_FAILURE;
michael@0 1364 }
michael@0 1365
michael@0 1366 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1367
michael@0 1368 if (NS_FAILED(result)) {
michael@0 1369 fail("GetNumberOfRedoItems() on redo stack with 4 items failed. (%d)\n",
michael@0 1370 result);
michael@0 1371 return result;
michael@0 1372 }
michael@0 1373
michael@0 1374 if (numitems != 4) {
michael@0 1375 fail("GetNumberOfRedoItems() expected 4 got %d. (%d)\n",
michael@0 1376 numitems, result);
michael@0 1377 return NS_ERROR_FAILURE;
michael@0 1378 }
michael@0 1379
michael@0 1380 passed("Undo 4 transactions");
michael@0 1381
michael@0 1382 /*******************************************************************
michael@0 1383 *
michael@0 1384 * Redo 2 transactions. Afterwards, we should have 8 transactions
michael@0 1385 * on the undo stack, and 2 on the redo stack:
michael@0 1386 *
michael@0 1387 *******************************************************************/
michael@0 1388
michael@0 1389 for (i = 1; i <= 2; ++i) {
michael@0 1390 result = mgr->RedoTransaction();
michael@0 1391 if (NS_FAILED(result)) {
michael@0 1392 fail("Failed to redo transaction %d. (%d)\n", i, result);
michael@0 1393 return result;
michael@0 1394 }
michael@0 1395 }
michael@0 1396
michael@0 1397 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1398
michael@0 1399 if (NS_FAILED(result)) {
michael@0 1400 fail("GetNumberOfUndoItems() on undo stack with 8 items failed. (%d)\n",
michael@0 1401 result);
michael@0 1402 return result;
michael@0 1403 }
michael@0 1404
michael@0 1405 if (numitems != 8) {
michael@0 1406 fail("GetNumberOfUndoItems() expected 8 got %d. (%d)\n",
michael@0 1407 numitems, result);
michael@0 1408 return NS_ERROR_FAILURE;
michael@0 1409 }
michael@0 1410
michael@0 1411 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1412
michael@0 1413 if (NS_FAILED(result)) {
michael@0 1414 fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
michael@0 1415 result);
michael@0 1416 return result;
michael@0 1417 }
michael@0 1418
michael@0 1419 if (numitems != 2) {
michael@0 1420 fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
michael@0 1421 numitems, result);
michael@0 1422 return NS_ERROR_FAILURE;
michael@0 1423 }
michael@0 1424
michael@0 1425 passed("Redo 2 transactions");
michael@0 1426
michael@0 1427 /*******************************************************************
michael@0 1428 *
michael@0 1429 * Execute a new transaction. The redo stack should get pruned!
michael@0 1430 *
michael@0 1431 *******************************************************************/
michael@0 1432
michael@0 1433 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 1434
michael@0 1435 if (!tximpl) {
michael@0 1436 fail("Failed to allocate transaction.\n");
michael@0 1437 return NS_ERROR_OUT_OF_MEMORY;
michael@0 1438 }
michael@0 1439
michael@0 1440 tx = 0;
michael@0 1441
michael@0 1442 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 1443
michael@0 1444 if (NS_FAILED(result)) {
michael@0 1445 fail("QueryInterface() failed for transaction. (%d)\n", result);
michael@0 1446 return result;
michael@0 1447 }
michael@0 1448
michael@0 1449 result = mgr->DoTransaction(tx);
michael@0 1450 if (NS_FAILED(result)) {
michael@0 1451 fail("Failed to execute transaction. (%d)\n", result);
michael@0 1452 return result;
michael@0 1453 }
michael@0 1454
michael@0 1455 tx->Release();
michael@0 1456
michael@0 1457 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1458
michael@0 1459 if (NS_FAILED(result)) {
michael@0 1460 fail("GetNumberOfUndoItems() on undo stack with 9 items failed. (%d)\n",
michael@0 1461 result);
michael@0 1462 return result;
michael@0 1463 }
michael@0 1464
michael@0 1465 if (numitems != 9) {
michael@0 1466 fail("GetNumberOfUndoItems() expected 9 got %d. (%d)\n",
michael@0 1467 numitems, result);
michael@0 1468 return NS_ERROR_FAILURE;
michael@0 1469 }
michael@0 1470
michael@0 1471 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1472
michael@0 1473 if (NS_FAILED(result)) {
michael@0 1474 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 1475 result);
michael@0 1476 return result;
michael@0 1477 }
michael@0 1478
michael@0 1479 if (numitems != 0) {
michael@0 1480 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 1481 numitems, result);
michael@0 1482 return NS_ERROR_FAILURE;
michael@0 1483 }
michael@0 1484
michael@0 1485 passed("Check if new transactions prune the redo stack");
michael@0 1486
michael@0 1487 /*******************************************************************
michael@0 1488 *
michael@0 1489 * Undo 4 transactions then clear the undo and redo stacks.
michael@0 1490 *
michael@0 1491 *******************************************************************/
michael@0 1492
michael@0 1493 for (i = 1; i <= 4; ++i) {
michael@0 1494 result = mgr->UndoTransaction();
michael@0 1495 if (NS_FAILED(result)) {
michael@0 1496 fail("Failed to undo transaction %d. (%d)\n", i, result);
michael@0 1497 return result;
michael@0 1498 }
michael@0 1499 }
michael@0 1500
michael@0 1501 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1502
michael@0 1503 if (NS_FAILED(result)) {
michael@0 1504 fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
michael@0 1505 result);
michael@0 1506 return result;
michael@0 1507 }
michael@0 1508
michael@0 1509 if (numitems != 5) {
michael@0 1510 fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
michael@0 1511 numitems, result);
michael@0 1512 return NS_ERROR_FAILURE;
michael@0 1513 }
michael@0 1514
michael@0 1515 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1516
michael@0 1517 if (NS_FAILED(result)) {
michael@0 1518 fail("GetNumberOfRedoItems() on redo stack with 4 items failed. (%d)\n",
michael@0 1519 result);
michael@0 1520 return result;
michael@0 1521 }
michael@0 1522
michael@0 1523 if (numitems != 4) {
michael@0 1524 fail("GetNumberOfRedoItems() expected 4 got %d. (%d)\n",
michael@0 1525 numitems, result);
michael@0 1526 return NS_ERROR_FAILURE;
michael@0 1527 }
michael@0 1528
michael@0 1529 result = mgr->Clear();
michael@0 1530 if (NS_FAILED(result)) {
michael@0 1531 fail("Clear() failed. (%d)\n", result);
michael@0 1532 return result;
michael@0 1533 }
michael@0 1534
michael@0 1535 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1536
michael@0 1537 if (NS_FAILED(result)) {
michael@0 1538 fail("GetNumberOfUndoItems() on cleared undo stack failed. (%d)\n",
michael@0 1539 result);
michael@0 1540 return result;
michael@0 1541 }
michael@0 1542
michael@0 1543 if (numitems != 0) {
michael@0 1544 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 1545 numitems, result);
michael@0 1546 return NS_ERROR_FAILURE;
michael@0 1547 }
michael@0 1548
michael@0 1549 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1550
michael@0 1551 if (NS_FAILED(result)) {
michael@0 1552 fail("GetNumberOfRedoItems() on cleared redo stack failed. (%d)\n",
michael@0 1553 result);
michael@0 1554 return result;
michael@0 1555 }
michael@0 1556
michael@0 1557 if (numitems != 0) {
michael@0 1558 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 1559 numitems, result);
michael@0 1560 return NS_ERROR_FAILURE;
michael@0 1561 }
michael@0 1562
michael@0 1563 passed("Undo 4 transactions then clear the undo and redo stacks");
michael@0 1564
michael@0 1565 /*******************************************************************
michael@0 1566 *
michael@0 1567 * Execute 5 transactions.
michael@0 1568 *
michael@0 1569 *******************************************************************/
michael@0 1570
michael@0 1571 for (i = 1; i <= 5; i++) {
michael@0 1572 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 1573
michael@0 1574 if (!tximpl) {
michael@0 1575 fail("Failed to allocate transaction %d.\n", i);
michael@0 1576 return NS_ERROR_OUT_OF_MEMORY;
michael@0 1577 }
michael@0 1578
michael@0 1579 tx = 0;
michael@0 1580 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 1581 if (NS_FAILED(result)) {
michael@0 1582 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 1583 i, result);
michael@0 1584 return result;
michael@0 1585 }
michael@0 1586
michael@0 1587 result = mgr->DoTransaction(tx);
michael@0 1588 if (NS_FAILED(result)) {
michael@0 1589 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 1590 return result;
michael@0 1591 }
michael@0 1592
michael@0 1593 tx->Release();
michael@0 1594 }
michael@0 1595
michael@0 1596 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1597
michael@0 1598 if (NS_FAILED(result)) {
michael@0 1599 fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
michael@0 1600 result);
michael@0 1601 return result;
michael@0 1602 }
michael@0 1603
michael@0 1604 if (numitems != 5) {
michael@0 1605 fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
michael@0 1606 numitems, result);
michael@0 1607 return NS_ERROR_FAILURE;
michael@0 1608 }
michael@0 1609
michael@0 1610 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1611
michael@0 1612 if (NS_FAILED(result)) {
michael@0 1613 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 1614 result);
michael@0 1615 return result;
michael@0 1616 }
michael@0 1617
michael@0 1618 if (numitems != 0) {
michael@0 1619 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 1620 numitems, result);
michael@0 1621 return NS_ERROR_FAILURE;
michael@0 1622 }
michael@0 1623
michael@0 1624 passed("Execute 5 transactions");
michael@0 1625
michael@0 1626 /*******************************************************************
michael@0 1627 *
michael@0 1628 * Test transaction DoTransaction() error:
michael@0 1629 *
michael@0 1630 *******************************************************************/
michael@0 1631
michael@0 1632 tximpl = factory->create(mgr, THROWS_DO_ERROR_FLAG);
michael@0 1633
michael@0 1634 if (!tximpl) {
michael@0 1635 fail("Failed to allocate transaction.\n");
michael@0 1636 return NS_ERROR_OUT_OF_MEMORY;
michael@0 1637 }
michael@0 1638
michael@0 1639 tx = 0;
michael@0 1640
michael@0 1641 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 1642
michael@0 1643 if (NS_FAILED(result)) {
michael@0 1644 fail("QueryInterface() failed for transaction. (%d)\n", result);
michael@0 1645 return result;
michael@0 1646 }
michael@0 1647
michael@0 1648 u1 = u2 = r1 = r2 = 0;
michael@0 1649
michael@0 1650 result = mgr->PeekUndoStack(&u1);
michael@0 1651
michael@0 1652 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 1653
michael@0 1654 if (NS_FAILED(result)) {
michael@0 1655 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 1656 return result;
michael@0 1657 }
michael@0 1658
michael@0 1659 result = mgr->PeekRedoStack(&r1);
michael@0 1660
michael@0 1661 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 1662
michael@0 1663 if (NS_FAILED(result)) {
michael@0 1664 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 1665 return result;
michael@0 1666 }
michael@0 1667
michael@0 1668 result = mgr->DoTransaction(tx);
michael@0 1669
michael@0 1670 if (result != NS_ERROR_FAILURE) {
michael@0 1671 fail("DoTransaction() returned unexpected error. (%d)\n", result);
michael@0 1672 return result;
michael@0 1673 }
michael@0 1674
michael@0 1675 tx->Release();
michael@0 1676
michael@0 1677 result = mgr->PeekUndoStack(&u2);
michael@0 1678
michael@0 1679 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 1680
michael@0 1681 if (NS_FAILED(result)) {
michael@0 1682 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 1683 return result;
michael@0 1684 }
michael@0 1685
michael@0 1686 if (u1 != u2) {
michael@0 1687 fail("Top of undo stack changed. (%d)\n", result);
michael@0 1688 return NS_ERROR_FAILURE;
michael@0 1689 }
michael@0 1690
michael@0 1691 result = mgr->PeekRedoStack(&r2);
michael@0 1692
michael@0 1693 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 1694
michael@0 1695 if (NS_FAILED(result)) {
michael@0 1696 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 1697 return result;
michael@0 1698 }
michael@0 1699
michael@0 1700 if (r1 != r2) {
michael@0 1701 fail("Top of redo stack changed. (%d)\n", result);
michael@0 1702 return NS_ERROR_FAILURE;
michael@0 1703 }
michael@0 1704
michael@0 1705 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1706
michael@0 1707 if (NS_FAILED(result)) {
michael@0 1708 fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
michael@0 1709 result);
michael@0 1710 return result;
michael@0 1711 }
michael@0 1712
michael@0 1713 if (numitems != 5) {
michael@0 1714 fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
michael@0 1715 numitems, result);
michael@0 1716 return NS_ERROR_FAILURE;
michael@0 1717 }
michael@0 1718
michael@0 1719 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1720
michael@0 1721 if (NS_FAILED(result)) {
michael@0 1722 fail("GetNumberOfRedoItems() on empty redo stack. (%d)\n",
michael@0 1723 result);
michael@0 1724 return result;
michael@0 1725 }
michael@0 1726
michael@0 1727 if (numitems != 0) {
michael@0 1728 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 1729 numitems, result);
michael@0 1730 return NS_ERROR_FAILURE;
michael@0 1731 }
michael@0 1732
michael@0 1733 passed("Test transaction DoTransaction() error");
michael@0 1734
michael@0 1735 /*******************************************************************
michael@0 1736 *
michael@0 1737 * Test transaction UndoTransaction() error:
michael@0 1738 *
michael@0 1739 *******************************************************************/
michael@0 1740
michael@0 1741 tximpl = factory->create(mgr, THROWS_UNDO_ERROR_FLAG);
michael@0 1742
michael@0 1743 if (!tximpl) {
michael@0 1744 fail("Failed to allocate transaction.\n");
michael@0 1745 return NS_ERROR_OUT_OF_MEMORY;
michael@0 1746 }
michael@0 1747
michael@0 1748 tx = 0;
michael@0 1749
michael@0 1750 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 1751
michael@0 1752 if (NS_FAILED(result)) {
michael@0 1753 fail("QueryInterface() failed for transaction. (%d)\n", result);
michael@0 1754 return result;
michael@0 1755 }
michael@0 1756
michael@0 1757 result = mgr->DoTransaction(tx);
michael@0 1758
michael@0 1759 if (NS_FAILED(result)) {
michael@0 1760 fail("DoTransaction() returned unexpected error. (%d)\n", result);
michael@0 1761 return result;
michael@0 1762 }
michael@0 1763
michael@0 1764 tx->Release();
michael@0 1765
michael@0 1766 u1 = u2 = r1 = r2 = 0;
michael@0 1767
michael@0 1768 result = mgr->PeekUndoStack(&u1);
michael@0 1769
michael@0 1770 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 1771
michael@0 1772 if (NS_FAILED(result)) {
michael@0 1773 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 1774 return result;
michael@0 1775 }
michael@0 1776
michael@0 1777 result = mgr->PeekRedoStack(&r1);
michael@0 1778
michael@0 1779 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 1780
michael@0 1781 if (NS_FAILED(result)) {
michael@0 1782 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 1783 return result;
michael@0 1784 }
michael@0 1785
michael@0 1786 result = mgr->UndoTransaction();
michael@0 1787
michael@0 1788 if (result != NS_ERROR_FAILURE) {
michael@0 1789 fail("UndoTransaction() returned unexpected error. (%d)\n", result);
michael@0 1790 return result;
michael@0 1791 }
michael@0 1792
michael@0 1793 result = mgr->PeekUndoStack(&u2);
michael@0 1794
michael@0 1795 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 1796
michael@0 1797 if (NS_FAILED(result)) {
michael@0 1798 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 1799 return result;
michael@0 1800 }
michael@0 1801
michael@0 1802 if (u1 != u2) {
michael@0 1803 fail("Top of undo stack changed. (%d)\n", result);
michael@0 1804 return NS_ERROR_FAILURE;
michael@0 1805 }
michael@0 1806
michael@0 1807 result = mgr->PeekRedoStack(&r2);
michael@0 1808
michael@0 1809 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 1810
michael@0 1811 if (NS_FAILED(result)) {
michael@0 1812 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 1813 return result;
michael@0 1814 }
michael@0 1815
michael@0 1816 if (r1 != r2) {
michael@0 1817 fail("Top of redo stack changed. (%d)\n", result);
michael@0 1818 return NS_ERROR_FAILURE;
michael@0 1819 }
michael@0 1820
michael@0 1821 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1822
michael@0 1823 if (NS_FAILED(result)) {
michael@0 1824 fail("GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",
michael@0 1825 result);
michael@0 1826 return result;
michael@0 1827 }
michael@0 1828
michael@0 1829 if (numitems != 6) {
michael@0 1830 fail("GetNumberOfUndoItems() expected 6 got %d. (%d)\n",
michael@0 1831 numitems, result);
michael@0 1832 return NS_ERROR_FAILURE;
michael@0 1833 }
michael@0 1834
michael@0 1835 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1836
michael@0 1837 if (NS_FAILED(result)) {
michael@0 1838 fail("GetNumberOfRedoItems() on empty redo stack. (%d)\n",
michael@0 1839 result);
michael@0 1840 return result;
michael@0 1841 }
michael@0 1842
michael@0 1843 if (numitems != 0) {
michael@0 1844 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 1845 numitems, result);
michael@0 1846 return NS_ERROR_FAILURE;
michael@0 1847 }
michael@0 1848
michael@0 1849 passed("Test transaction UndoTransaction() error");
michael@0 1850
michael@0 1851 /*******************************************************************
michael@0 1852 *
michael@0 1853 * Test transaction RedoTransaction() error:
michael@0 1854 *
michael@0 1855 *******************************************************************/
michael@0 1856
michael@0 1857 tximpl = factory->create(mgr, THROWS_REDO_ERROR_FLAG);
michael@0 1858
michael@0 1859 if (!tximpl) {
michael@0 1860 fail("Failed to allocate transaction.\n");
michael@0 1861 return NS_ERROR_OUT_OF_MEMORY;
michael@0 1862 }
michael@0 1863
michael@0 1864 tx = 0;
michael@0 1865
michael@0 1866 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 1867
michael@0 1868 if (NS_FAILED(result)) {
michael@0 1869 fail("QueryInterface() failed for RedoErrorTransaction. (%d)\n",
michael@0 1870 result);
michael@0 1871 return result;
michael@0 1872 }
michael@0 1873
michael@0 1874 result = mgr->DoTransaction(tx);
michael@0 1875
michael@0 1876 if (NS_FAILED(result)) {
michael@0 1877 fail("DoTransaction() returned unexpected error. (%d)\n", result);
michael@0 1878 return result;
michael@0 1879 }
michael@0 1880
michael@0 1881 tx->Release();
michael@0 1882
michael@0 1883 //
michael@0 1884 // Execute a normal transaction to be used in a later test:
michael@0 1885 //
michael@0 1886
michael@0 1887 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 1888
michael@0 1889 if (!tximpl) {
michael@0 1890 fail("Failed to allocate transaction.\n");
michael@0 1891 return NS_ERROR_OUT_OF_MEMORY;
michael@0 1892 }
michael@0 1893
michael@0 1894 tx = 0;
michael@0 1895
michael@0 1896 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 1897
michael@0 1898 if (NS_FAILED(result)) {
michael@0 1899 fail("QueryInterface() failed for transaction. (%d)\n", result);
michael@0 1900 return result;
michael@0 1901 }
michael@0 1902
michael@0 1903 result = mgr->DoTransaction(tx);
michael@0 1904
michael@0 1905 if (NS_FAILED(result)) {
michael@0 1906 fail("DoTransaction() returned unexpected error. (%d)\n", result);
michael@0 1907 return result;
michael@0 1908 }
michael@0 1909
michael@0 1910 tx->Release();
michael@0 1911
michael@0 1912 //
michael@0 1913 // Undo the 2 transactions just executed.
michael@0 1914 //
michael@0 1915
michael@0 1916 for (i = 1; i <= 2; ++i) {
michael@0 1917 result = mgr->UndoTransaction();
michael@0 1918 if (NS_FAILED(result)) {
michael@0 1919 fail("Failed to undo transaction %d. (%d)\n", i, result);
michael@0 1920 return result;
michael@0 1921 }
michael@0 1922 }
michael@0 1923
michael@0 1924 //
michael@0 1925 // The RedoErrorTransaction should now be at the top of the redo stack!
michael@0 1926 //
michael@0 1927
michael@0 1928 u1 = u2 = r1 = r2 = 0;
michael@0 1929
michael@0 1930 result = mgr->PeekUndoStack(&u1);
michael@0 1931
michael@0 1932 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 1933
michael@0 1934 if (NS_FAILED(result)) {
michael@0 1935 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 1936 return result;
michael@0 1937 }
michael@0 1938
michael@0 1939 result = mgr->PeekRedoStack(&r1);
michael@0 1940
michael@0 1941 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 1942
michael@0 1943 if (NS_FAILED(result)) {
michael@0 1944 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 1945 return result;
michael@0 1946 }
michael@0 1947
michael@0 1948 result = mgr->RedoTransaction();
michael@0 1949
michael@0 1950 if (result != NS_ERROR_FAILURE) {
michael@0 1951 fail("RedoTransaction() returned unexpected error. (%d)\n", result);
michael@0 1952 return result;
michael@0 1953 }
michael@0 1954
michael@0 1955 result = mgr->PeekUndoStack(&u2);
michael@0 1956
michael@0 1957 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 1958
michael@0 1959 if (NS_FAILED(result)) {
michael@0 1960 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 1961 return result;
michael@0 1962 }
michael@0 1963
michael@0 1964 if (u1 != u2) {
michael@0 1965 fail("Top of undo stack changed. (%d)\n", result);
michael@0 1966 return NS_ERROR_FAILURE;
michael@0 1967 }
michael@0 1968
michael@0 1969 result = mgr->PeekRedoStack(&r2);
michael@0 1970
michael@0 1971 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 1972
michael@0 1973 if (NS_FAILED(result)) {
michael@0 1974 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 1975 return result;
michael@0 1976 }
michael@0 1977
michael@0 1978 if (r1 != r2) {
michael@0 1979 fail("Top of redo stack changed. (%d)\n", result);
michael@0 1980 return NS_ERROR_FAILURE;
michael@0 1981 }
michael@0 1982
michael@0 1983 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 1984
michael@0 1985 if (NS_FAILED(result)) {
michael@0 1986 fail("GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",
michael@0 1987 result);
michael@0 1988 return result;
michael@0 1989 }
michael@0 1990
michael@0 1991 if (numitems != 6) {
michael@0 1992 fail("GetNumberOfUndoItems() expected 6 got %d. (%d)\n",
michael@0 1993 numitems, result);
michael@0 1994 return NS_ERROR_FAILURE;
michael@0 1995 }
michael@0 1996
michael@0 1997 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 1998
michael@0 1999 if (NS_FAILED(result)) {
michael@0 2000 fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
michael@0 2001 result);
michael@0 2002 return result;
michael@0 2003 }
michael@0 2004
michael@0 2005 if (numitems != 2) {
michael@0 2006 fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
michael@0 2007 numitems, result);
michael@0 2008 return NS_ERROR_FAILURE;
michael@0 2009 }
michael@0 2010
michael@0 2011 passed("Test transaction RedoTransaction() error");
michael@0 2012
michael@0 2013 /*******************************************************************
michael@0 2014 *
michael@0 2015 * Make sure that setting the transaction manager's max transaction
michael@0 2016 * count to zero, clears both the undo and redo stacks, and executes
michael@0 2017 * all new commands without pushing them on the undo stack!
michael@0 2018 *
michael@0 2019 *******************************************************************/
michael@0 2020
michael@0 2021 result = mgr->SetMaxTransactionCount(0);
michael@0 2022
michael@0 2023 if (NS_FAILED(result)) {
michael@0 2024 fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
michael@0 2025 return result;
michael@0 2026 }
michael@0 2027
michael@0 2028 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2029
michael@0 2030 if (NS_FAILED(result)) {
michael@0 2031 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 2032 result);
michael@0 2033 return result;
michael@0 2034 }
michael@0 2035
michael@0 2036 if (numitems != 0) {
michael@0 2037 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 2038 numitems, result);
michael@0 2039 return NS_ERROR_FAILURE;
michael@0 2040 }
michael@0 2041
michael@0 2042 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 2043
michael@0 2044 if (NS_FAILED(result)) {
michael@0 2045 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 2046 result);
michael@0 2047 return result;
michael@0 2048 }
michael@0 2049
michael@0 2050 if (numitems != 0) {
michael@0 2051 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 2052 numitems, result);
michael@0 2053 return NS_ERROR_FAILURE;
michael@0 2054 }
michael@0 2055
michael@0 2056 for (i = 1; i <= 20; i++) {
michael@0 2057 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 2058
michael@0 2059 if (!tximpl) {
michael@0 2060 fail("Failed to allocate transaction %d.\n", i);
michael@0 2061 return NS_ERROR_OUT_OF_MEMORY;
michael@0 2062 }
michael@0 2063
michael@0 2064 tx = 0;
michael@0 2065 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 2066 if (NS_FAILED(result)) {
michael@0 2067 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 2068 i, result);
michael@0 2069 return result;
michael@0 2070 }
michael@0 2071
michael@0 2072 result = mgr->DoTransaction(tx);
michael@0 2073 if (NS_FAILED(result)) {
michael@0 2074 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 2075 return result;
michael@0 2076 }
michael@0 2077
michael@0 2078 tx->Release();
michael@0 2079
michael@0 2080 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2081
michael@0 2082 if (NS_FAILED(result)) {
michael@0 2083 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 2084 result);
michael@0 2085 return result;
michael@0 2086 }
michael@0 2087
michael@0 2088 if (numitems != 0) {
michael@0 2089 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 2090 numitems, result);
michael@0 2091 return NS_ERROR_FAILURE;
michael@0 2092 }
michael@0 2093
michael@0 2094 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 2095
michael@0 2096 if (NS_FAILED(result)) {
michael@0 2097 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 2098 result);
michael@0 2099 return result;
michael@0 2100 }
michael@0 2101
michael@0 2102 if (numitems != 0) {
michael@0 2103 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 2104 numitems, result);
michael@0 2105 return NS_ERROR_FAILURE;
michael@0 2106 }
michael@0 2107 }
michael@0 2108
michael@0 2109 passed("Test max transaction count of zero");
michael@0 2110
michael@0 2111 /*******************************************************************
michael@0 2112 *
michael@0 2113 * Make sure that setting the transaction manager's max transaction
michael@0 2114 * count to something greater than the number of transactions on
michael@0 2115 * both the undo and redo stacks causes no pruning of the stacks:
michael@0 2116 *
michael@0 2117 *******************************************************************/
michael@0 2118
michael@0 2119 result = mgr->SetMaxTransactionCount(-1);
michael@0 2120
michael@0 2121 if (NS_FAILED(result)) {
michael@0 2122 fail("SetMaxTransactionCount(-1) failed. (%d)\n", result);
michael@0 2123 return result;
michael@0 2124 }
michael@0 2125
michael@0 2126 // Push 20 transactions on the undo stack:
michael@0 2127
michael@0 2128 for (i = 1; i <= 20; i++) {
michael@0 2129 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 2130
michael@0 2131 if (!tximpl) {
michael@0 2132 fail("Failed to allocate transaction %d.\n", i);
michael@0 2133 return NS_ERROR_OUT_OF_MEMORY;
michael@0 2134 }
michael@0 2135
michael@0 2136 tx = 0;
michael@0 2137 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 2138 if (NS_FAILED(result)) {
michael@0 2139 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 2140 i, result);
michael@0 2141 return result;
michael@0 2142 }
michael@0 2143
michael@0 2144 result = mgr->DoTransaction(tx);
michael@0 2145 if (NS_FAILED(result)) {
michael@0 2146 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 2147 return result;
michael@0 2148 }
michael@0 2149
michael@0 2150 tx->Release();
michael@0 2151
michael@0 2152 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2153
michael@0 2154 if (NS_FAILED(result)) {
michael@0 2155 fail("GetNumberOfUndoItems() on undo stack with %d items failed. (%d)\n",
michael@0 2156 i, result);
michael@0 2157 return result;
michael@0 2158 }
michael@0 2159
michael@0 2160 if (numitems != i) {
michael@0 2161 fail("GetNumberOfUndoItems() expected %d got %d. (%d)\n",
michael@0 2162 i, numitems, result);
michael@0 2163 return NS_ERROR_FAILURE;
michael@0 2164 }
michael@0 2165
michael@0 2166 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 2167
michael@0 2168 if (NS_FAILED(result)) {
michael@0 2169 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 2170 result);
michael@0 2171 return result;
michael@0 2172 }
michael@0 2173
michael@0 2174 if (numitems != 0) {
michael@0 2175 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 2176 numitems, result);
michael@0 2177 return NS_ERROR_FAILURE;
michael@0 2178 }
michael@0 2179 }
michael@0 2180
michael@0 2181 for (i = 1; i <= 10; i++) {
michael@0 2182
michael@0 2183 result = mgr->UndoTransaction();
michael@0 2184 if (NS_FAILED(result)) {
michael@0 2185 fail("Failed to undo transaction %d. (%d)\n", i, result);
michael@0 2186 return result;
michael@0 2187 }
michael@0 2188 }
michael@0 2189 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2190
michael@0 2191 if (NS_FAILED(result)) {
michael@0 2192 fail("GetNumberOfUndoItems() on empty undo stack with 10 items failed. (%d)\n",
michael@0 2193 result);
michael@0 2194 return result;
michael@0 2195 }
michael@0 2196
michael@0 2197 if (numitems != 10) {
michael@0 2198 fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
michael@0 2199 numitems, result);
michael@0 2200 return NS_ERROR_FAILURE;
michael@0 2201 }
michael@0 2202
michael@0 2203 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 2204
michael@0 2205 if (NS_FAILED(result)) {
michael@0 2206 fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
michael@0 2207 result);
michael@0 2208 return result;
michael@0 2209 }
michael@0 2210
michael@0 2211 if (numitems != 10) {
michael@0 2212 fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
michael@0 2213 numitems, result);
michael@0 2214 return NS_ERROR_FAILURE;
michael@0 2215 }
michael@0 2216
michael@0 2217 u1 = u2 = r1 = r2 = 0;
michael@0 2218
michael@0 2219 result = mgr->PeekUndoStack(&u1);
michael@0 2220
michael@0 2221 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 2222
michael@0 2223 if (NS_FAILED(result)) {
michael@0 2224 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 2225 return result;
michael@0 2226 }
michael@0 2227
michael@0 2228 result = mgr->PeekRedoStack(&r1);
michael@0 2229
michael@0 2230 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 2231
michael@0 2232 if (NS_FAILED(result)) {
michael@0 2233 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 2234 return result;
michael@0 2235 }
michael@0 2236
michael@0 2237 result = mgr->SetMaxTransactionCount(25);
michael@0 2238
michael@0 2239 if (NS_FAILED(result)) {
michael@0 2240 fail("SetMaxTransactionCount(25) failed. (%d)\n", result);
michael@0 2241 return result;
michael@0 2242 }
michael@0 2243
michael@0 2244 result = mgr->PeekUndoStack(&u2);
michael@0 2245
michael@0 2246 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 2247
michael@0 2248 if (NS_FAILED(result)) {
michael@0 2249 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 2250 return result;
michael@0 2251 }
michael@0 2252
michael@0 2253 if (u1 != u2) {
michael@0 2254 fail("Top of undo stack changed. (%d)\n", result);
michael@0 2255 return NS_ERROR_FAILURE;
michael@0 2256 }
michael@0 2257
michael@0 2258 result = mgr->PeekRedoStack(&r2);
michael@0 2259
michael@0 2260 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 2261
michael@0 2262 if (NS_FAILED(result)) {
michael@0 2263 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 2264 return result;
michael@0 2265 }
michael@0 2266
michael@0 2267 if (r1 != r2) {
michael@0 2268 fail("Top of redo stack changed. (%d)\n", result);
michael@0 2269 return NS_ERROR_FAILURE;
michael@0 2270 }
michael@0 2271
michael@0 2272 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2273
michael@0 2274 if (NS_FAILED(result)) {
michael@0 2275 fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
michael@0 2276 result);
michael@0 2277 return result;
michael@0 2278 }
michael@0 2279
michael@0 2280 if (numitems != 10) {
michael@0 2281 fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
michael@0 2282 numitems, result);
michael@0 2283 return NS_ERROR_FAILURE;
michael@0 2284 }
michael@0 2285
michael@0 2286 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 2287
michael@0 2288 if (NS_FAILED(result)) {
michael@0 2289 fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
michael@0 2290 result);
michael@0 2291 return result;
michael@0 2292 }
michael@0 2293
michael@0 2294 if (numitems != 10) {
michael@0 2295 fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
michael@0 2296 numitems, result);
michael@0 2297 return NS_ERROR_FAILURE;
michael@0 2298 }
michael@0 2299
michael@0 2300 passed("Test SetMaxTransactionCount() greater than num stack items");
michael@0 2301
michael@0 2302 /*******************************************************************
michael@0 2303 *
michael@0 2304 * Test undo stack pruning by setting the transaction
michael@0 2305 * manager's max transaction count to a number lower than the
michael@0 2306 * number of transactions on both the undo and redo stacks:
michael@0 2307 *
michael@0 2308 *******************************************************************/
michael@0 2309
michael@0 2310 u1 = u2 = r1 = r2 = 0;
michael@0 2311
michael@0 2312 result = mgr->PeekUndoStack(&u1);
michael@0 2313
michael@0 2314 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 2315
michael@0 2316 if (NS_FAILED(result)) {
michael@0 2317 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 2318 return result;
michael@0 2319 }
michael@0 2320
michael@0 2321 result = mgr->PeekRedoStack(&r1);
michael@0 2322
michael@0 2323 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 2324
michael@0 2325 if (NS_FAILED(result)) {
michael@0 2326 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 2327 return result;
michael@0 2328 }
michael@0 2329
michael@0 2330 result = mgr->SetMaxTransactionCount(15);
michael@0 2331
michael@0 2332 if (NS_FAILED(result)) {
michael@0 2333 fail("SetMaxTransactionCount(15) failed. (%d)\n", result);
michael@0 2334 return result;
michael@0 2335 }
michael@0 2336
michael@0 2337 result = mgr->PeekUndoStack(&u2);
michael@0 2338
michael@0 2339 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 2340
michael@0 2341 if (NS_FAILED(result)) {
michael@0 2342 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 2343 return result;
michael@0 2344 }
michael@0 2345
michael@0 2346 if (u1 != u2) {
michael@0 2347 fail("Top of undo stack changed. (%d)\n", result);
michael@0 2348 return NS_ERROR_FAILURE;
michael@0 2349 }
michael@0 2350
michael@0 2351 result = mgr->PeekRedoStack(&r2);
michael@0 2352
michael@0 2353 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 2354
michael@0 2355 if (NS_FAILED(result)) {
michael@0 2356 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 2357 return result;
michael@0 2358 }
michael@0 2359
michael@0 2360 if (r1 != r2) {
michael@0 2361 fail("Top of redo stack changed. (%d)\n", result);
michael@0 2362 return NS_ERROR_FAILURE;
michael@0 2363 }
michael@0 2364
michael@0 2365 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2366
michael@0 2367 if (NS_FAILED(result)) {
michael@0 2368 fail("GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",
michael@0 2369 result);
michael@0 2370 return result;
michael@0 2371 }
michael@0 2372
michael@0 2373 if (numitems != 5) {
michael@0 2374 fail("GetNumberOfUndoItems() expected 5 got %d. (%d)\n",
michael@0 2375 numitems, result);
michael@0 2376 return NS_ERROR_FAILURE;
michael@0 2377 }
michael@0 2378
michael@0 2379 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 2380
michael@0 2381 if (NS_FAILED(result)) {
michael@0 2382 fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
michael@0 2383 result);
michael@0 2384 return result;
michael@0 2385 }
michael@0 2386
michael@0 2387 if (numitems != 10) {
michael@0 2388 fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
michael@0 2389 numitems, result);
michael@0 2390 return NS_ERROR_FAILURE;
michael@0 2391 }
michael@0 2392
michael@0 2393 passed("Test SetMaxTransactionCount() pruning undo stack");
michael@0 2394
michael@0 2395 /*******************************************************************
michael@0 2396 *
michael@0 2397 * Test redo stack pruning by setting the transaction
michael@0 2398 * manager's max transaction count to a number lower than the
michael@0 2399 * number of transactions on both the undo and redo stacks:
michael@0 2400 *
michael@0 2401 *******************************************************************/
michael@0 2402
michael@0 2403 u1 = u2 = r1 = r2 = 0;
michael@0 2404
michael@0 2405 result = mgr->PeekUndoStack(&u1);
michael@0 2406
michael@0 2407 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 2408
michael@0 2409 if (NS_FAILED(result)) {
michael@0 2410 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 2411 return result;
michael@0 2412 }
michael@0 2413
michael@0 2414 result = mgr->PeekRedoStack(&r1);
michael@0 2415
michael@0 2416 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 2417
michael@0 2418 if (NS_FAILED(result)) {
michael@0 2419 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 2420 return result;
michael@0 2421 }
michael@0 2422
michael@0 2423 result = mgr->SetMaxTransactionCount(5);
michael@0 2424
michael@0 2425 if (NS_FAILED(result)) {
michael@0 2426 fail("SetMaxTransactionCount(5) failed. (%d)\n", result);
michael@0 2427 return result;
michael@0 2428 }
michael@0 2429
michael@0 2430 result = mgr->PeekUndoStack(&u2);
michael@0 2431
michael@0 2432 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 2433
michael@0 2434 if (NS_FAILED(result)) {
michael@0 2435 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 2436 return result;
michael@0 2437 }
michael@0 2438
michael@0 2439 if (u2) {
michael@0 2440 fail("Unexpected item at top of undo stack. (%d)\n", result);
michael@0 2441 return NS_ERROR_FAILURE;
michael@0 2442 }
michael@0 2443
michael@0 2444 result = mgr->PeekRedoStack(&r2);
michael@0 2445
michael@0 2446 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 2447
michael@0 2448 if (NS_FAILED(result)) {
michael@0 2449 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 2450 return result;
michael@0 2451 }
michael@0 2452
michael@0 2453 if (r1 != r2) {
michael@0 2454 fail("Top of redo stack changed. (%d)\n", result);
michael@0 2455 return NS_ERROR_FAILURE;
michael@0 2456 }
michael@0 2457
michael@0 2458 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2459
michael@0 2460 if (NS_FAILED(result)) {
michael@0 2461 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 2462 result);
michael@0 2463 return result;
michael@0 2464 }
michael@0 2465
michael@0 2466 if (numitems != 0) {
michael@0 2467 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 2468 numitems, result);
michael@0 2469 return NS_ERROR_FAILURE;
michael@0 2470 }
michael@0 2471
michael@0 2472 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 2473
michael@0 2474 if (NS_FAILED(result)) {
michael@0 2475 fail("GetNumberOfRedoItems() on redo stack with 5 items failed. (%d)\n",
michael@0 2476 result);
michael@0 2477 return result;
michael@0 2478 }
michael@0 2479
michael@0 2480 if (numitems != 5) {
michael@0 2481 fail("GetNumberOfRedoItems() expected 5 got %d. (%d)\n",
michael@0 2482 numitems, result);
michael@0 2483 return NS_ERROR_FAILURE;
michael@0 2484 }
michael@0 2485
michael@0 2486 passed("Test SetMaxTransactionCount() pruning redo stack");
michael@0 2487
michael@0 2488 /*******************************************************************
michael@0 2489 *
michael@0 2490 * Release the transaction manager. Any transactions on the undo
michael@0 2491 * and redo stack should automatically be released:
michael@0 2492 *
michael@0 2493 *******************************************************************/
michael@0 2494
michael@0 2495 result = mgr->SetMaxTransactionCount(-1);
michael@0 2496
michael@0 2497 if (NS_FAILED(result)) {
michael@0 2498 fail("SetMaxTransactionCount(-1) failed. (%d)\n", result);
michael@0 2499 return result;
michael@0 2500 }
michael@0 2501
michael@0 2502 // Push 20 transactions on the undo stack:
michael@0 2503
michael@0 2504 for (i = 1; i <= 20; i++) {
michael@0 2505 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 2506
michael@0 2507 if (!tximpl) {
michael@0 2508 fail("Failed to allocate transaction %d.\n", i);
michael@0 2509 return NS_ERROR_OUT_OF_MEMORY;
michael@0 2510 }
michael@0 2511
michael@0 2512 tx = 0;
michael@0 2513 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 2514 if (NS_FAILED(result)) {
michael@0 2515 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 2516 i, result);
michael@0 2517 return result;
michael@0 2518 }
michael@0 2519
michael@0 2520 result = mgr->DoTransaction(tx);
michael@0 2521 if (NS_FAILED(result)) {
michael@0 2522 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 2523 return result;
michael@0 2524 }
michael@0 2525
michael@0 2526 tx->Release();
michael@0 2527
michael@0 2528 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2529
michael@0 2530 if (NS_FAILED(result)) {
michael@0 2531 fail("GetNumberOfUndoItems() on undo stack with %d items failed. (%d)\n",
michael@0 2532 i, result);
michael@0 2533 return result;
michael@0 2534 }
michael@0 2535
michael@0 2536 if (numitems != i) {
michael@0 2537 fail("GetNumberOfUndoItems() expected %d got %d. (%d)\n",
michael@0 2538 i, numitems, result);
michael@0 2539 return NS_ERROR_FAILURE;
michael@0 2540 }
michael@0 2541
michael@0 2542 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 2543
michael@0 2544 if (NS_FAILED(result)) {
michael@0 2545 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 2546 result);
michael@0 2547 return result;
michael@0 2548 }
michael@0 2549
michael@0 2550 if (numitems != 0) {
michael@0 2551 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 2552 numitems, result);
michael@0 2553 return NS_ERROR_FAILURE;
michael@0 2554 }
michael@0 2555 }
michael@0 2556
michael@0 2557 for (i = 1; i <= 10; i++) {
michael@0 2558
michael@0 2559 result = mgr->UndoTransaction();
michael@0 2560 if (NS_FAILED(result)) {
michael@0 2561 fail("Failed to undo transaction %d. (%d)\n", i, result);
michael@0 2562 return result;
michael@0 2563 }
michael@0 2564 }
michael@0 2565 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2566
michael@0 2567 if (NS_FAILED(result)) {
michael@0 2568 fail("GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",
michael@0 2569 result);
michael@0 2570 return result;
michael@0 2571 }
michael@0 2572
michael@0 2573 if (numitems != 10) {
michael@0 2574 fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
michael@0 2575 numitems, result);
michael@0 2576 return NS_ERROR_FAILURE;
michael@0 2577 }
michael@0 2578
michael@0 2579 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 2580
michael@0 2581 if (NS_FAILED(result)) {
michael@0 2582 fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
michael@0 2583 result);
michael@0 2584 return result;
michael@0 2585 }
michael@0 2586
michael@0 2587 if (numitems != 10) {
michael@0 2588 fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
michael@0 2589 numitems, result);
michael@0 2590 return NS_ERROR_FAILURE;
michael@0 2591 }
michael@0 2592
michael@0 2593 result = mgr->Clear();
michael@0 2594 if (NS_FAILED(result)) {
michael@0 2595 fail("Clear() failed. (%d)\n", result);
michael@0 2596 return result;
michael@0 2597 }
michael@0 2598
michael@0 2599 passed("Release the transaction manager");
michael@0 2600
michael@0 2601 /*******************************************************************
michael@0 2602 *
michael@0 2603 * Make sure number of transactions created matches number of
michael@0 2604 * transactions destroyed!
michael@0 2605 *
michael@0 2606 *******************************************************************/
michael@0 2607
michael@0 2608 /* Disabled because the current cycle collector doesn't delete
michael@0 2609 cycle collectable objects synchronously.
michael@0 2610 if (sConstructorCount != sDestructorCount) {
michael@0 2611 fail("Transaction constructor count (%d) != destructor count (%d).\n",
michael@0 2612 sConstructorCount, sDestructorCount);
michael@0 2613 return NS_ERROR_FAILURE;
michael@0 2614 }*/
michael@0 2615
michael@0 2616 passed("Number of transactions created and destroyed match");
michael@0 2617 passed("%d transactions processed during quick test", sConstructorCount);
michael@0 2618
michael@0 2619 return NS_OK;
michael@0 2620 }
michael@0 2621
michael@0 2622 nsresult
michael@0 2623 simple_test()
michael@0 2624 {
michael@0 2625 /*******************************************************************
michael@0 2626 *
michael@0 2627 * Initialize globals for test.
michael@0 2628 *
michael@0 2629 *******************************************************************/
michael@0 2630 reset_globals();
michael@0 2631 sDestructorOrderArr = sSimpleTestDestructorOrderArr;
michael@0 2632 sDoOrderArr = sSimpleTestDoOrderArr;
michael@0 2633 sUndoOrderArr = sSimpleTestUndoOrderArr;
michael@0 2634 sRedoOrderArr = sSimpleTestRedoOrderArr;
michael@0 2635
michael@0 2636 /*******************************************************************
michael@0 2637 *
michael@0 2638 * Run the quick test.
michael@0 2639 *
michael@0 2640 *******************************************************************/
michael@0 2641
michael@0 2642 printf("\n-----------------------------------------------------\n");
michael@0 2643 printf("- Begin Simple Transaction Test:\n");
michael@0 2644 printf("-----------------------------------------------------\n");
michael@0 2645
michael@0 2646 SimpleTransactionFactory factory;
michael@0 2647
michael@0 2648 return quick_test(&factory);
michael@0 2649 }
michael@0 2650
michael@0 2651 nsresult
michael@0 2652 aggregation_test()
michael@0 2653 {
michael@0 2654 /*******************************************************************
michael@0 2655 *
michael@0 2656 * Initialize globals for test.
michael@0 2657 *
michael@0 2658 *******************************************************************/
michael@0 2659
michael@0 2660 reset_globals();
michael@0 2661 sDestructorOrderArr = sAggregateTestDestructorOrderArr;
michael@0 2662 sDoOrderArr = sAggregateTestDoOrderArr;
michael@0 2663 sUndoOrderArr = sAggregateTestUndoOrderArr;
michael@0 2664 sRedoOrderArr = sAggregateTestRedoOrderArr;
michael@0 2665
michael@0 2666 /*******************************************************************
michael@0 2667 *
michael@0 2668 * Run the quick test.
michael@0 2669 *
michael@0 2670 *******************************************************************/
michael@0 2671
michael@0 2672 printf("\n-----------------------------------------------------\n");
michael@0 2673 printf("- Begin Aggregate Transaction Test:\n");
michael@0 2674 printf("-----------------------------------------------------\n");
michael@0 2675
michael@0 2676 AggregateTransactionFactory factory(3, 2);
michael@0 2677
michael@0 2678 return quick_test(&factory);
michael@0 2679 }
michael@0 2680
michael@0 2681 /**
michael@0 2682 * Test behaviors in batch mode.
michael@0 2683 **/
michael@0 2684 nsresult
michael@0 2685 quick_batch_test(TestTransactionFactory *factory)
michael@0 2686 {
michael@0 2687 nsresult result;
michael@0 2688
michael@0 2689 /*******************************************************************
michael@0 2690 *
michael@0 2691 * Create a transaction manager implementation:
michael@0 2692 *
michael@0 2693 *******************************************************************/
michael@0 2694
michael@0 2695 nsCOMPtr<nsITransactionManager> mgr =
michael@0 2696 do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &result);
michael@0 2697 if (NS_FAILED(result) || !mgr) {
michael@0 2698 fail("Failed to create Transaction Manager instance.\n");
michael@0 2699 return NS_ERROR_OUT_OF_MEMORY;
michael@0 2700 }
michael@0 2701
michael@0 2702 passed("Create transaction manager instance");
michael@0 2703
michael@0 2704 int32_t numitems;
michael@0 2705
michael@0 2706 /*******************************************************************
michael@0 2707 *
michael@0 2708 * Make sure an unbalanced call to EndBatch(false) with empty undo stack
michael@0 2709 * throws an error!
michael@0 2710 *
michael@0 2711 *******************************************************************/
michael@0 2712
michael@0 2713 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2714
michael@0 2715 if (NS_FAILED(result)) {
michael@0 2716 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 2717 result);
michael@0 2718 return result;
michael@0 2719 }
michael@0 2720
michael@0 2721 if (numitems != 0) {
michael@0 2722 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 2723 numitems, result);
michael@0 2724 return NS_ERROR_FAILURE;
michael@0 2725 }
michael@0 2726
michael@0 2727 result = mgr->EndBatch(false);
michael@0 2728
michael@0 2729 if (result != NS_ERROR_FAILURE) {
michael@0 2730 fail("EndBatch(false) returned unexpected status. (%d)\n", result);
michael@0 2731 return result;
michael@0 2732 }
michael@0 2733
michael@0 2734 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2735
michael@0 2736 if (NS_FAILED(result)) {
michael@0 2737 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 2738 result);
michael@0 2739 return result;
michael@0 2740 }
michael@0 2741
michael@0 2742 if (numitems != 0) {
michael@0 2743 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 2744 numitems, result);
michael@0 2745 return NS_ERROR_FAILURE;
michael@0 2746 }
michael@0 2747
michael@0 2748 passed("Test unbalanced EndBatch(false) with empty undo stack");
michael@0 2749
michael@0 2750 /*******************************************************************
michael@0 2751 *
michael@0 2752 * Make sure that an empty batch is not added to the undo stack
michael@0 2753 * when it is closed.
michael@0 2754 *
michael@0 2755 *******************************************************************/
michael@0 2756
michael@0 2757 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2758
michael@0 2759 if (NS_FAILED(result)) {
michael@0 2760 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 2761 result);
michael@0 2762 return result;
michael@0 2763 }
michael@0 2764
michael@0 2765 if (numitems != 0) {
michael@0 2766 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 2767 numitems, result);
michael@0 2768 return NS_ERROR_FAILURE;
michael@0 2769 }
michael@0 2770
michael@0 2771 result = mgr->BeginBatch(nullptr);
michael@0 2772
michael@0 2773 if (NS_FAILED(result)) {
michael@0 2774 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 2775 return result;
michael@0 2776 }
michael@0 2777
michael@0 2778 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2779
michael@0 2780 if (NS_FAILED(result)) {
michael@0 2781 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 2782 result);
michael@0 2783 return result;
michael@0 2784 }
michael@0 2785
michael@0 2786 if (numitems != 0) {
michael@0 2787 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 2788 numitems, result);
michael@0 2789 return NS_ERROR_FAILURE;
michael@0 2790 }
michael@0 2791
michael@0 2792 result = mgr->EndBatch(false);
michael@0 2793
michael@0 2794 if (NS_FAILED(result)) {
michael@0 2795 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 2796 return result;
michael@0 2797 }
michael@0 2798
michael@0 2799 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2800
michael@0 2801 if (NS_FAILED(result)) {
michael@0 2802 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 2803 result);
michael@0 2804 return result;
michael@0 2805 }
michael@0 2806
michael@0 2807 if (numitems != 0) {
michael@0 2808 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 2809 numitems, result);
michael@0 2810 return NS_ERROR_FAILURE;
michael@0 2811 }
michael@0 2812
michael@0 2813 passed("Test empty batch");
michael@0 2814
michael@0 2815 int32_t i;
michael@0 2816 TestTransaction *tximpl;
michael@0 2817 nsITransaction *tx;
michael@0 2818
michael@0 2819 /*******************************************************************
michael@0 2820 *
michael@0 2821 * Execute 20 transactions. Afterwards, we should have 1
michael@0 2822 * transaction on the undo stack:
michael@0 2823 *
michael@0 2824 *******************************************************************/
michael@0 2825
michael@0 2826 result = mgr->BeginBatch(nullptr);
michael@0 2827
michael@0 2828 if (NS_FAILED(result)) {
michael@0 2829 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 2830 return result;
michael@0 2831 }
michael@0 2832
michael@0 2833 for (i = 1; i <= 20; i++) {
michael@0 2834 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 2835
michael@0 2836 if (!tximpl) {
michael@0 2837 fail("Failed to allocate transaction %d.\n", i);
michael@0 2838 return NS_ERROR_OUT_OF_MEMORY;
michael@0 2839 }
michael@0 2840
michael@0 2841 tx = 0;
michael@0 2842 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 2843 if (NS_FAILED(result)) {
michael@0 2844 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 2845 i, result);
michael@0 2846 return result;
michael@0 2847 }
michael@0 2848
michael@0 2849 result = mgr->DoTransaction(tx);
michael@0 2850 if (NS_FAILED(result)) {
michael@0 2851 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 2852 return result;
michael@0 2853 }
michael@0 2854
michael@0 2855 tx->Release();
michael@0 2856 }
michael@0 2857
michael@0 2858 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2859
michael@0 2860 if (NS_FAILED(result)) {
michael@0 2861 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 2862 result);
michael@0 2863 return result;
michael@0 2864 }
michael@0 2865
michael@0 2866 if (numitems != 0) {
michael@0 2867 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 2868 numitems, result);
michael@0 2869 return NS_ERROR_FAILURE;
michael@0 2870 }
michael@0 2871
michael@0 2872 result = mgr->EndBatch(false);
michael@0 2873
michael@0 2874 if (NS_FAILED(result)) {
michael@0 2875 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 2876 return result;
michael@0 2877 }
michael@0 2878
michael@0 2879 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2880
michael@0 2881 if (NS_FAILED(result)) {
michael@0 2882 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 2883 result);
michael@0 2884 return result;
michael@0 2885 }
michael@0 2886
michael@0 2887 if (numitems != 1) {
michael@0 2888 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 2889 numitems, result);
michael@0 2890 return NS_ERROR_FAILURE;
michael@0 2891 }
michael@0 2892
michael@0 2893 passed("Execute 20 batched transactions");
michael@0 2894
michael@0 2895 nsITransaction *u1, *u2;
michael@0 2896 nsITransaction *r1, *r2;
michael@0 2897
michael@0 2898 /*******************************************************************
michael@0 2899 *
michael@0 2900 * Execute 20 transient transactions. Afterwards, we should still
michael@0 2901 * have the same transaction on the undo stack:
michael@0 2902 *
michael@0 2903 *******************************************************************/
michael@0 2904
michael@0 2905 u1 = u2 = r1 = r2 = 0;
michael@0 2906
michael@0 2907 result = mgr->PeekUndoStack(&u1);
michael@0 2908
michael@0 2909 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 2910
michael@0 2911 if (NS_FAILED(result)) {
michael@0 2912 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 2913 return result;
michael@0 2914 }
michael@0 2915
michael@0 2916 result = mgr->PeekRedoStack(&r1);
michael@0 2917
michael@0 2918 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 2919
michael@0 2920 if (NS_FAILED(result)) {
michael@0 2921 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 2922 return result;
michael@0 2923 }
michael@0 2924
michael@0 2925 result = mgr->BeginBatch(nullptr);
michael@0 2926
michael@0 2927 if (NS_FAILED(result)) {
michael@0 2928 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 2929 return result;
michael@0 2930 }
michael@0 2931
michael@0 2932 for (i = 1; i <= 20; i++) {
michael@0 2933 tximpl = factory->create(mgr, TRANSIENT_FLAG);
michael@0 2934
michael@0 2935 if (!tximpl) {
michael@0 2936 fail("Failed to allocate transaction %d.\n", i);
michael@0 2937 return NS_ERROR_OUT_OF_MEMORY;
michael@0 2938 }
michael@0 2939
michael@0 2940 tx = 0;
michael@0 2941 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 2942 if (NS_FAILED(result)) {
michael@0 2943 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 2944 i, result);
michael@0 2945 return result;
michael@0 2946 }
michael@0 2947
michael@0 2948 result = mgr->DoTransaction(tx);
michael@0 2949 if (NS_FAILED(result)) {
michael@0 2950 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 2951 return result;
michael@0 2952 }
michael@0 2953
michael@0 2954 tx->Release();
michael@0 2955 }
michael@0 2956
michael@0 2957 result = mgr->EndBatch(false);
michael@0 2958
michael@0 2959 if (NS_FAILED(result)) {
michael@0 2960 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 2961 return result;
michael@0 2962 }
michael@0 2963
michael@0 2964 result = mgr->PeekUndoStack(&u2);
michael@0 2965
michael@0 2966 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 2967
michael@0 2968 if (NS_FAILED(result)) {
michael@0 2969 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 2970 return result;
michael@0 2971 }
michael@0 2972
michael@0 2973 if (u1 != u2) {
michael@0 2974 fail("Top of undo stack changed. (%d)\n", result);
michael@0 2975 return NS_ERROR_FAILURE;
michael@0 2976 }
michael@0 2977
michael@0 2978 result = mgr->PeekRedoStack(&r2);
michael@0 2979
michael@0 2980 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 2981
michael@0 2982 if (NS_FAILED(result)) {
michael@0 2983 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 2984 return result;
michael@0 2985 }
michael@0 2986
michael@0 2987 if (r1 != r2) {
michael@0 2988 fail("Top of redo stack changed. (%d)\n", result);
michael@0 2989 return NS_ERROR_FAILURE;
michael@0 2990 }
michael@0 2991
michael@0 2992 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 2993
michael@0 2994 if (NS_FAILED(result)) {
michael@0 2995 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 2996 result);
michael@0 2997 return result;
michael@0 2998 }
michael@0 2999
michael@0 3000 if (numitems != 1) {
michael@0 3001 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3002 numitems, result);
michael@0 3003 return NS_ERROR_FAILURE;
michael@0 3004 }
michael@0 3005
michael@0 3006 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3007
michael@0 3008 if (NS_FAILED(result)) {
michael@0 3009 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 3010 result);
michael@0 3011 return result;
michael@0 3012 }
michael@0 3013
michael@0 3014 if (numitems != 0) {
michael@0 3015 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 3016 numitems, result);
michael@0 3017 return NS_ERROR_FAILURE;
michael@0 3018 }
michael@0 3019
michael@0 3020 passed("Execute 20 batched transient transactions");
michael@0 3021
michael@0 3022 /*******************************************************************
michael@0 3023 *
michael@0 3024 * Test nested batching. Afterwards, we should have 2 transactions
michael@0 3025 * on the undo stack:
michael@0 3026 *
michael@0 3027 *******************************************************************/
michael@0 3028
michael@0 3029 result = mgr->BeginBatch(nullptr);
michael@0 3030
michael@0 3031 if (NS_FAILED(result)) {
michael@0 3032 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 3033 return result;
michael@0 3034 }
michael@0 3035
michael@0 3036 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 3037
michael@0 3038 if (!tximpl) {
michael@0 3039 fail("Failed to allocate transaction.\n");
michael@0 3040 return NS_ERROR_OUT_OF_MEMORY;
michael@0 3041 }
michael@0 3042
michael@0 3043 tx = 0;
michael@0 3044 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 3045 if (NS_FAILED(result)) {
michael@0 3046 fail("QueryInterface() failed for transaction. (%d)\n", result);
michael@0 3047 return result;
michael@0 3048 }
michael@0 3049
michael@0 3050 result = mgr->DoTransaction(tx);
michael@0 3051 if (NS_FAILED(result)) {
michael@0 3052 fail("Failed to execute transaction. (%d)\n", result);
michael@0 3053 return result;
michael@0 3054 }
michael@0 3055
michael@0 3056 tx->Release();
michael@0 3057
michael@0 3058 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3059
michael@0 3060 if (NS_FAILED(result)) {
michael@0 3061 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 3062 result);
michael@0 3063 return result;
michael@0 3064 }
michael@0 3065
michael@0 3066 if (numitems != 1) {
michael@0 3067 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3068 numitems, result);
michael@0 3069 return NS_ERROR_FAILURE;
michael@0 3070 }
michael@0 3071
michael@0 3072 result = mgr->BeginBatch(nullptr);
michael@0 3073
michael@0 3074 if (NS_FAILED(result)) {
michael@0 3075 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 3076 return result;
michael@0 3077 }
michael@0 3078
michael@0 3079 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 3080
michael@0 3081 if (!tximpl) {
michael@0 3082 fail("Failed to allocate transaction.\n");
michael@0 3083 return NS_ERROR_OUT_OF_MEMORY;
michael@0 3084 }
michael@0 3085
michael@0 3086 tx = 0;
michael@0 3087 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 3088 if (NS_FAILED(result)) {
michael@0 3089 fail("QueryInterface() failed for transaction. (%d)\n", result);
michael@0 3090 return result;
michael@0 3091 }
michael@0 3092
michael@0 3093 result = mgr->DoTransaction(tx);
michael@0 3094 if (NS_FAILED(result)) {
michael@0 3095 fail("Failed to execute transaction. (%d)\n", result);
michael@0 3096 return result;
michael@0 3097 }
michael@0 3098
michael@0 3099 tx->Release();
michael@0 3100
michael@0 3101 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3102
michael@0 3103 if (NS_FAILED(result)) {
michael@0 3104 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 3105 result);
michael@0 3106 return result;
michael@0 3107 }
michael@0 3108
michael@0 3109 if (numitems != 1) {
michael@0 3110 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3111 numitems, result);
michael@0 3112 return NS_ERROR_FAILURE;
michael@0 3113 }
michael@0 3114
michael@0 3115 result = mgr->BeginBatch(nullptr);
michael@0 3116
michael@0 3117 if (NS_FAILED(result)) {
michael@0 3118 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 3119 return result;
michael@0 3120 }
michael@0 3121
michael@0 3122 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 3123
michael@0 3124 if (!tximpl) {
michael@0 3125 fail("Failed to allocate transaction.\n");
michael@0 3126 return NS_ERROR_OUT_OF_MEMORY;
michael@0 3127 }
michael@0 3128
michael@0 3129 tx = 0;
michael@0 3130 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 3131 if (NS_FAILED(result)) {
michael@0 3132 fail("QueryInterface() failed for transaction. (%d)\n", result);
michael@0 3133 return result;
michael@0 3134 }
michael@0 3135
michael@0 3136 result = mgr->DoTransaction(tx);
michael@0 3137 if (NS_FAILED(result)) {
michael@0 3138 fail("Failed to execute transaction. (%d)\n", result);
michael@0 3139 return result;
michael@0 3140 }
michael@0 3141
michael@0 3142 tx->Release();
michael@0 3143
michael@0 3144 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3145
michael@0 3146 if (NS_FAILED(result)) {
michael@0 3147 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 3148 result);
michael@0 3149 return result;
michael@0 3150 }
michael@0 3151
michael@0 3152 if (numitems != 1) {
michael@0 3153 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3154 numitems, result);
michael@0 3155 return NS_ERROR_FAILURE;
michael@0 3156 }
michael@0 3157
michael@0 3158 result = mgr->EndBatch(false);
michael@0 3159
michael@0 3160 if (NS_FAILED(result)) {
michael@0 3161 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 3162 return result;
michael@0 3163 }
michael@0 3164
michael@0 3165 result = mgr->EndBatch(false);
michael@0 3166
michael@0 3167 if (NS_FAILED(result)) {
michael@0 3168 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 3169 return result;
michael@0 3170 }
michael@0 3171
michael@0 3172 result = mgr->EndBatch(false);
michael@0 3173
michael@0 3174 if (NS_FAILED(result)) {
michael@0 3175 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 3176 return result;
michael@0 3177 }
michael@0 3178
michael@0 3179 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3180
michael@0 3181 if (NS_FAILED(result)) {
michael@0 3182 fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
michael@0 3183 result);
michael@0 3184 return result;
michael@0 3185 }
michael@0 3186
michael@0 3187 if (numitems != 2) {
michael@0 3188 fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
michael@0 3189 numitems, result);
michael@0 3190 return NS_ERROR_FAILURE;
michael@0 3191 }
michael@0 3192
michael@0 3193 passed("Test nested batched transactions");
michael@0 3194
michael@0 3195 /*******************************************************************
michael@0 3196 *
michael@0 3197 * Undo 2 batch transactions. Afterwards, we should have 0
michael@0 3198 * transactions on the undo stack and 2 on the redo stack.
michael@0 3199 *
michael@0 3200 *******************************************************************/
michael@0 3201
michael@0 3202 for (i = 1; i <= 2; ++i) {
michael@0 3203 result = mgr->UndoTransaction();
michael@0 3204 if (NS_FAILED(result)) {
michael@0 3205 fail("Failed to undo transaction %d. (%d)\n", i, result);
michael@0 3206 return result;
michael@0 3207 }
michael@0 3208 }
michael@0 3209
michael@0 3210 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3211
michael@0 3212 if (NS_FAILED(result)) {
michael@0 3213 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 3214 result);
michael@0 3215 return result;
michael@0 3216 }
michael@0 3217
michael@0 3218 if (numitems != 0) {
michael@0 3219 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 3220 numitems, result);
michael@0 3221 return NS_ERROR_FAILURE;
michael@0 3222 }
michael@0 3223
michael@0 3224 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3225
michael@0 3226 if (NS_FAILED(result)) {
michael@0 3227 fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
michael@0 3228 result);
michael@0 3229 return result;
michael@0 3230 }
michael@0 3231
michael@0 3232 if (numitems != 2) {
michael@0 3233 fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
michael@0 3234 numitems, result);
michael@0 3235 return NS_ERROR_FAILURE;
michael@0 3236 }
michael@0 3237
michael@0 3238 passed("Undo 2 batch transactions");
michael@0 3239
michael@0 3240 /*******************************************************************
michael@0 3241 *
michael@0 3242 * Redo 2 batch transactions. Afterwards, we should have 2
michael@0 3243 * transactions on the undo stack and 0 on the redo stack.
michael@0 3244 *
michael@0 3245 *******************************************************************/
michael@0 3246
michael@0 3247 for (i = 1; i <= 2; ++i) {
michael@0 3248 result = mgr->RedoTransaction();
michael@0 3249 if (NS_FAILED(result)) {
michael@0 3250 fail("Failed to undo transaction %d. (%d)\n", i, result);
michael@0 3251 return result;
michael@0 3252 }
michael@0 3253 }
michael@0 3254
michael@0 3255 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3256
michael@0 3257 if (NS_FAILED(result)) {
michael@0 3258 fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
michael@0 3259 result);
michael@0 3260 return result;
michael@0 3261 }
michael@0 3262
michael@0 3263 if (numitems != 2) {
michael@0 3264 fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
michael@0 3265 numitems, result);
michael@0 3266 return NS_ERROR_FAILURE;
michael@0 3267 }
michael@0 3268
michael@0 3269 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3270
michael@0 3271 if (NS_FAILED(result)) {
michael@0 3272 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 3273 result);
michael@0 3274 return result;
michael@0 3275 }
michael@0 3276
michael@0 3277 if (numitems != 0) {
michael@0 3278 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 3279 numitems, result);
michael@0 3280 return NS_ERROR_FAILURE;
michael@0 3281 }
michael@0 3282
michael@0 3283 passed("Redo 2 batch transactions");
michael@0 3284
michael@0 3285 /*******************************************************************
michael@0 3286 *
michael@0 3287 * Call undo. Afterwards, we should have 1 transaction
michael@0 3288 * on the undo stack, and 1 on the redo stack:
michael@0 3289 *
michael@0 3290 *******************************************************************/
michael@0 3291
michael@0 3292 result = mgr->UndoTransaction();
michael@0 3293
michael@0 3294 if (NS_FAILED(result)) {
michael@0 3295 fail("Failed to undo transaction. (%d)\n", result);
michael@0 3296 return result;
michael@0 3297 }
michael@0 3298
michael@0 3299 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3300
michael@0 3301 if (NS_FAILED(result)) {
michael@0 3302 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 3303 result);
michael@0 3304 return result;
michael@0 3305 }
michael@0 3306
michael@0 3307 if (numitems != 1) {
michael@0 3308 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3309 numitems, result);
michael@0 3310 return NS_ERROR_FAILURE;
michael@0 3311 }
michael@0 3312
michael@0 3313 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3314
michael@0 3315 if (NS_FAILED(result)) {
michael@0 3316 fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
michael@0 3317 result);
michael@0 3318 return result;
michael@0 3319 }
michael@0 3320
michael@0 3321 if (numitems != 1) {
michael@0 3322 fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
michael@0 3323 numitems, result);
michael@0 3324 return NS_ERROR_FAILURE;
michael@0 3325 }
michael@0 3326
michael@0 3327 passed("Undo a batched transaction that was redone");
michael@0 3328
michael@0 3329 /*******************************************************************
michael@0 3330 *
michael@0 3331 * Make sure an unbalanced call to EndBatch(false) throws an error and
michael@0 3332 * doesn't affect the undo and redo stacks!
michael@0 3333 *
michael@0 3334 *******************************************************************/
michael@0 3335
michael@0 3336 result = mgr->EndBatch(false);
michael@0 3337
michael@0 3338 if (result != NS_ERROR_FAILURE) {
michael@0 3339 fail("EndBatch(false) returned unexpected status. (%d)\n", result);
michael@0 3340 return result;
michael@0 3341 }
michael@0 3342
michael@0 3343 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3344
michael@0 3345 if (NS_FAILED(result)) {
michael@0 3346 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 3347 result);
michael@0 3348 return result;
michael@0 3349 }
michael@0 3350
michael@0 3351 if (numitems != 1) {
michael@0 3352 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3353 numitems, result);
michael@0 3354 return NS_ERROR_FAILURE;
michael@0 3355 }
michael@0 3356
michael@0 3357 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3358
michael@0 3359 if (NS_FAILED(result)) {
michael@0 3360 fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
michael@0 3361 result);
michael@0 3362 return result;
michael@0 3363 }
michael@0 3364
michael@0 3365 if (numitems != 1) {
michael@0 3366 fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
michael@0 3367 numitems, result);
michael@0 3368 return NS_ERROR_FAILURE;
michael@0 3369 }
michael@0 3370
michael@0 3371 passed("Test effect of unbalanced EndBatch(false) on undo and redo stacks");
michael@0 3372
michael@0 3373 /*******************************************************************
michael@0 3374 *
michael@0 3375 * Make sure that an empty batch is not added to the undo stack
michael@0 3376 * when it is closed, and that it does not affect the undo and redo
michael@0 3377 * stacks.
michael@0 3378 *
michael@0 3379 *******************************************************************/
michael@0 3380
michael@0 3381 result = mgr->BeginBatch(nullptr);
michael@0 3382
michael@0 3383 if (NS_FAILED(result)) {
michael@0 3384 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 3385 return result;
michael@0 3386 }
michael@0 3387
michael@0 3388 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3389
michael@0 3390 if (NS_FAILED(result)) {
michael@0 3391 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 3392 result);
michael@0 3393 return result;
michael@0 3394 }
michael@0 3395
michael@0 3396 if (numitems != 1) {
michael@0 3397 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3398 numitems, result);
michael@0 3399 return NS_ERROR_FAILURE;
michael@0 3400 }
michael@0 3401
michael@0 3402 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3403
michael@0 3404 if (NS_FAILED(result)) {
michael@0 3405 fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
michael@0 3406 result);
michael@0 3407 return result;
michael@0 3408 }
michael@0 3409
michael@0 3410 if (numitems != 1) {
michael@0 3411 fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
michael@0 3412 numitems, result);
michael@0 3413 return NS_ERROR_FAILURE;
michael@0 3414 }
michael@0 3415
michael@0 3416 result = mgr->EndBatch(false);
michael@0 3417
michael@0 3418 if (NS_FAILED(result)) {
michael@0 3419 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 3420 return result;
michael@0 3421 }
michael@0 3422
michael@0 3423 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3424
michael@0 3425 if (NS_FAILED(result)) {
michael@0 3426 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 3427 result);
michael@0 3428 return result;
michael@0 3429 }
michael@0 3430
michael@0 3431 if (numitems != 1) {
michael@0 3432 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3433 numitems, result);
michael@0 3434 return NS_ERROR_FAILURE;
michael@0 3435 }
michael@0 3436
michael@0 3437 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3438
michael@0 3439 if (NS_FAILED(result)) {
michael@0 3440 fail("GetNumberOfRedoItems() on stack with 1 item failed. (%d)\n",
michael@0 3441 result);
michael@0 3442 return result;
michael@0 3443 }
michael@0 3444
michael@0 3445 if (numitems != 1) {
michael@0 3446 fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
michael@0 3447 numitems, result);
michael@0 3448 return NS_ERROR_FAILURE;
michael@0 3449 }
michael@0 3450
michael@0 3451 passed("Test effect of empty batch on undo and redo stacks");
michael@0 3452
michael@0 3453 /*******************************************************************
michael@0 3454 *
michael@0 3455 * Execute a new transaction. The redo stack should get pruned!
michael@0 3456 *
michael@0 3457 *******************************************************************/
michael@0 3458
michael@0 3459 result = mgr->BeginBatch(nullptr);
michael@0 3460
michael@0 3461 if (NS_FAILED(result)) {
michael@0 3462 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 3463 return result;
michael@0 3464 }
michael@0 3465
michael@0 3466 for (i = 1; i <= 20; i++) {
michael@0 3467 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 3468
michael@0 3469 if (!tximpl) {
michael@0 3470 fail("Failed to allocate transaction %d.\n", i);
michael@0 3471 return NS_ERROR_OUT_OF_MEMORY;
michael@0 3472 }
michael@0 3473
michael@0 3474 tx = 0;
michael@0 3475 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 3476 if (NS_FAILED(result)) {
michael@0 3477 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 3478 i, result);
michael@0 3479 return result;
michael@0 3480 }
michael@0 3481
michael@0 3482 result = mgr->DoTransaction(tx);
michael@0 3483 if (NS_FAILED(result)) {
michael@0 3484 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 3485 return result;
michael@0 3486 }
michael@0 3487
michael@0 3488 tx->Release();
michael@0 3489 }
michael@0 3490
michael@0 3491 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3492
michael@0 3493 if (NS_FAILED(result)) {
michael@0 3494 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 3495 result);
michael@0 3496 return result;
michael@0 3497 }
michael@0 3498
michael@0 3499 if (numitems != 1) {
michael@0 3500 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3501 numitems, result);
michael@0 3502 return NS_ERROR_FAILURE;
michael@0 3503 }
michael@0 3504
michael@0 3505 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3506
michael@0 3507 if (NS_FAILED(result)) {
michael@0 3508 fail("GetNumberOfRedoItems() on redo stack with 1 item failed. (%d)\n",
michael@0 3509 result);
michael@0 3510 return result;
michael@0 3511 }
michael@0 3512
michael@0 3513 if (numitems != 1) {
michael@0 3514 fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
michael@0 3515 numitems, result);
michael@0 3516 return NS_ERROR_FAILURE;
michael@0 3517 }
michael@0 3518
michael@0 3519 result = mgr->EndBatch(false);
michael@0 3520
michael@0 3521 if (NS_FAILED(result)) {
michael@0 3522 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 3523 return result;
michael@0 3524 }
michael@0 3525
michael@0 3526 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3527
michael@0 3528 if (NS_FAILED(result)) {
michael@0 3529 fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
michael@0 3530 result);
michael@0 3531 return result;
michael@0 3532 }
michael@0 3533
michael@0 3534 if (numitems != 2) {
michael@0 3535 fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
michael@0 3536 numitems, result);
michael@0 3537 return NS_ERROR_FAILURE;
michael@0 3538 }
michael@0 3539
michael@0 3540 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3541
michael@0 3542 if (NS_FAILED(result)) {
michael@0 3543 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 3544 result);
michael@0 3545 return result;
michael@0 3546 }
michael@0 3547
michael@0 3548 if (numitems != 0) {
michael@0 3549 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 3550 numitems, result);
michael@0 3551 return NS_ERROR_FAILURE;
michael@0 3552 }
michael@0 3553
michael@0 3554 passed("Check if new batched transactions prune the redo stack");
michael@0 3555
michael@0 3556 /*******************************************************************
michael@0 3557 *
michael@0 3558 * Call undo.
michael@0 3559 *
michael@0 3560 *******************************************************************/
michael@0 3561
michael@0 3562 // Move a transaction over to the redo stack, so that we have one
michael@0 3563 // transaction on the undo stack, and one on the redo stack!
michael@0 3564
michael@0 3565 result = mgr->UndoTransaction();
michael@0 3566
michael@0 3567 if (NS_FAILED(result)) {
michael@0 3568 fail("Failed to undo transaction. (%d)\n", result);
michael@0 3569 return result;
michael@0 3570 }
michael@0 3571
michael@0 3572 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3573
michael@0 3574 if (NS_FAILED(result)) {
michael@0 3575 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 3576 result);
michael@0 3577 return result;
michael@0 3578 }
michael@0 3579
michael@0 3580 if (numitems != 1) {
michael@0 3581 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3582 numitems, result);
michael@0 3583 return NS_ERROR_FAILURE;
michael@0 3584 }
michael@0 3585
michael@0 3586 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3587
michael@0 3588 if (NS_FAILED(result)) {
michael@0 3589 fail("GetNumberOfRedoItems() on redo stack with 1 item failed. (%d)\n",
michael@0 3590 result);
michael@0 3591 return result;
michael@0 3592 }
michael@0 3593
michael@0 3594 if (numitems != 1) {
michael@0 3595 fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
michael@0 3596 numitems, result);
michael@0 3597 return NS_ERROR_FAILURE;
michael@0 3598 }
michael@0 3599
michael@0 3600 passed("Call undo");
michael@0 3601
michael@0 3602 /*******************************************************************
michael@0 3603 *
michael@0 3604 * Test transaction DoTransaction() error:
michael@0 3605 *
michael@0 3606 *******************************************************************/
michael@0 3607
michael@0 3608 tximpl = factory->create(mgr, THROWS_DO_ERROR_FLAG);
michael@0 3609
michael@0 3610 if (!tximpl) {
michael@0 3611 fail("Failed to allocate transaction.\n");
michael@0 3612 return NS_ERROR_OUT_OF_MEMORY;
michael@0 3613 }
michael@0 3614
michael@0 3615 tx = 0;
michael@0 3616
michael@0 3617 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 3618
michael@0 3619 if (NS_FAILED(result)) {
michael@0 3620 fail("QueryInterface() failed for transaction. (%d)\n", result);
michael@0 3621 return result;
michael@0 3622 }
michael@0 3623
michael@0 3624 u1 = u2 = r1 = r2 = 0;
michael@0 3625
michael@0 3626 result = mgr->PeekUndoStack(&u1);
michael@0 3627
michael@0 3628 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 3629
michael@0 3630 if (NS_FAILED(result)) {
michael@0 3631 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 3632 return result;
michael@0 3633 }
michael@0 3634
michael@0 3635 result = mgr->PeekRedoStack(&r1);
michael@0 3636
michael@0 3637 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 3638
michael@0 3639 if (NS_FAILED(result)) {
michael@0 3640 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 3641 return result;
michael@0 3642 }
michael@0 3643
michael@0 3644 result = mgr->BeginBatch(nullptr);
michael@0 3645
michael@0 3646 if (NS_FAILED(result)) {
michael@0 3647 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 3648 return result;
michael@0 3649 }
michael@0 3650
michael@0 3651 result = mgr->DoTransaction(tx);
michael@0 3652
michael@0 3653 if (result != NS_ERROR_FAILURE) {
michael@0 3654 fail("DoTransaction() returned unexpected error. (%d)\n", result);
michael@0 3655 return result;
michael@0 3656 }
michael@0 3657
michael@0 3658 tx->Release();
michael@0 3659
michael@0 3660 result = mgr->EndBatch(false);
michael@0 3661
michael@0 3662 if (NS_FAILED(result)) {
michael@0 3663 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 3664 return result;
michael@0 3665 }
michael@0 3666
michael@0 3667 result = mgr->PeekUndoStack(&u2);
michael@0 3668
michael@0 3669 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 3670
michael@0 3671 if (NS_FAILED(result)) {
michael@0 3672 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 3673 return result;
michael@0 3674 }
michael@0 3675
michael@0 3676 if (u1 != u2) {
michael@0 3677 fail("Top of undo stack changed. (%d)\n", result);
michael@0 3678 return NS_ERROR_FAILURE;
michael@0 3679 }
michael@0 3680
michael@0 3681 result = mgr->PeekRedoStack(&r2);
michael@0 3682
michael@0 3683 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 3684
michael@0 3685 if (NS_FAILED(result)) {
michael@0 3686 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 3687 return result;
michael@0 3688 }
michael@0 3689
michael@0 3690 if (r1 != r2) {
michael@0 3691 fail("Top of redo stack changed. (%d)\n", result);
michael@0 3692 return NS_ERROR_FAILURE;
michael@0 3693 }
michael@0 3694
michael@0 3695 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3696
michael@0 3697 if (NS_FAILED(result)) {
michael@0 3698 fail("GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",
michael@0 3699 result);
michael@0 3700 return result;
michael@0 3701 }
michael@0 3702
michael@0 3703 if (numitems != 1) {
michael@0 3704 fail("GetNumberOfUndoItems() expected 1 got %d. (%d)\n",
michael@0 3705 numitems, result);
michael@0 3706 return NS_ERROR_FAILURE;
michael@0 3707 }
michael@0 3708
michael@0 3709 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3710
michael@0 3711 if (NS_FAILED(result)) {
michael@0 3712 fail("GetNumberOfRedoItems() on redo stack with 1 item failed. (%d)\n",
michael@0 3713 result);
michael@0 3714 return result;
michael@0 3715 }
michael@0 3716
michael@0 3717 if (numitems != 1) {
michael@0 3718 fail("GetNumberOfRedoItems() expected 1 got %d. (%d)\n",
michael@0 3719 numitems, result);
michael@0 3720 return NS_ERROR_FAILURE;
michael@0 3721 }
michael@0 3722
michael@0 3723 passed("Test transaction DoTransaction() error");
michael@0 3724
michael@0 3725 /*******************************************************************
michael@0 3726 *
michael@0 3727 * Test transaction UndoTransaction() error:
michael@0 3728 *
michael@0 3729 *******************************************************************/
michael@0 3730
michael@0 3731 tximpl = factory->create(mgr, THROWS_UNDO_ERROR_FLAG);
michael@0 3732
michael@0 3733 if (!tximpl) {
michael@0 3734 fail("Failed to allocate transaction.\n");
michael@0 3735 return NS_ERROR_OUT_OF_MEMORY;
michael@0 3736 }
michael@0 3737
michael@0 3738 tx = 0;
michael@0 3739
michael@0 3740 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 3741
michael@0 3742 if (NS_FAILED(result)) {
michael@0 3743 fail("QueryInterface() failed for transaction. (%d)\n", result);
michael@0 3744 return result;
michael@0 3745 }
michael@0 3746
michael@0 3747 result = mgr->BeginBatch(nullptr);
michael@0 3748
michael@0 3749 if (NS_FAILED(result)) {
michael@0 3750 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 3751 return result;
michael@0 3752 }
michael@0 3753
michael@0 3754 result = mgr->DoTransaction(tx);
michael@0 3755
michael@0 3756 if (NS_FAILED(result)) {
michael@0 3757 fail("DoTransaction() returned unexpected error. (%d)\n", result);
michael@0 3758 return result;
michael@0 3759 }
michael@0 3760
michael@0 3761 tx->Release();
michael@0 3762
michael@0 3763 result = mgr->EndBatch(false);
michael@0 3764
michael@0 3765 if (NS_FAILED(result)) {
michael@0 3766 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 3767 return result;
michael@0 3768 }
michael@0 3769
michael@0 3770 u1 = u2 = r1 = r2 = 0;
michael@0 3771
michael@0 3772 result = mgr->PeekUndoStack(&u1);
michael@0 3773
michael@0 3774 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 3775
michael@0 3776 if (NS_FAILED(result)) {
michael@0 3777 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 3778 return result;
michael@0 3779 }
michael@0 3780
michael@0 3781 result = mgr->PeekRedoStack(&r1);
michael@0 3782
michael@0 3783 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 3784
michael@0 3785 if (NS_FAILED(result)) {
michael@0 3786 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 3787 return result;
michael@0 3788 }
michael@0 3789
michael@0 3790 result = mgr->UndoTransaction();
michael@0 3791
michael@0 3792 if (result != NS_ERROR_FAILURE) {
michael@0 3793 fail("UndoTransaction() returned unexpected error. (%d)\n", result);
michael@0 3794 return result;
michael@0 3795 }
michael@0 3796
michael@0 3797 result = mgr->PeekUndoStack(&u2);
michael@0 3798
michael@0 3799 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 3800
michael@0 3801 if (NS_FAILED(result)) {
michael@0 3802 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 3803 return result;
michael@0 3804 }
michael@0 3805
michael@0 3806 if (u1 != u2) {
michael@0 3807 fail("Top of undo stack changed. (%d)\n", result);
michael@0 3808 return NS_ERROR_FAILURE;
michael@0 3809 }
michael@0 3810
michael@0 3811 result = mgr->PeekRedoStack(&r2);
michael@0 3812
michael@0 3813 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 3814
michael@0 3815 if (NS_FAILED(result)) {
michael@0 3816 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 3817 return result;
michael@0 3818 }
michael@0 3819
michael@0 3820 if (r1 != r2) {
michael@0 3821 fail("Top of redo stack changed. (%d)\n", result);
michael@0 3822 return NS_ERROR_FAILURE;
michael@0 3823 }
michael@0 3824
michael@0 3825 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 3826
michael@0 3827 if (NS_FAILED(result)) {
michael@0 3828 fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
michael@0 3829 result);
michael@0 3830 return result;
michael@0 3831 }
michael@0 3832
michael@0 3833 if (numitems != 2) {
michael@0 3834 fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
michael@0 3835 numitems, result);
michael@0 3836 return NS_ERROR_FAILURE;
michael@0 3837 }
michael@0 3838
michael@0 3839 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 3840
michael@0 3841 if (NS_FAILED(result)) {
michael@0 3842 fail("GetNumberOfRedoItems() on empty redo stack. (%d)\n",
michael@0 3843 result);
michael@0 3844 return result;
michael@0 3845 }
michael@0 3846
michael@0 3847 if (numitems != 0) {
michael@0 3848 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 3849 numitems, result);
michael@0 3850 return NS_ERROR_FAILURE;
michael@0 3851 }
michael@0 3852
michael@0 3853 passed("Test transaction UndoTransaction() error");
michael@0 3854
michael@0 3855 /*******************************************************************
michael@0 3856 *
michael@0 3857 * Test transaction RedoTransaction() error:
michael@0 3858 *
michael@0 3859 *******************************************************************/
michael@0 3860
michael@0 3861 tximpl = factory->create(mgr, THROWS_REDO_ERROR_FLAG);
michael@0 3862
michael@0 3863 if (!tximpl) {
michael@0 3864 fail("Failed to allocate transaction.\n");
michael@0 3865 return NS_ERROR_OUT_OF_MEMORY;
michael@0 3866 }
michael@0 3867
michael@0 3868 tx = 0;
michael@0 3869
michael@0 3870 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 3871
michael@0 3872 if (NS_FAILED(result)) {
michael@0 3873 fail("QueryInterface() failed for RedoErrorTransaction. (%d)\n",
michael@0 3874 result);
michael@0 3875 return result;
michael@0 3876 }
michael@0 3877
michael@0 3878 result = mgr->BeginBatch(nullptr);
michael@0 3879
michael@0 3880 if (NS_FAILED(result)) {
michael@0 3881 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 3882 return result;
michael@0 3883 }
michael@0 3884
michael@0 3885 result = mgr->DoTransaction(tx);
michael@0 3886
michael@0 3887 if (NS_FAILED(result)) {
michael@0 3888 fail("DoTransaction() returned unexpected error. (%d)\n", result);
michael@0 3889 return result;
michael@0 3890 }
michael@0 3891
michael@0 3892 tx->Release();
michael@0 3893
michael@0 3894 result = mgr->EndBatch(false);
michael@0 3895
michael@0 3896 if (NS_FAILED(result)) {
michael@0 3897 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 3898 return result;
michael@0 3899 }
michael@0 3900
michael@0 3901 //
michael@0 3902 // Execute a normal transaction to be used in a later test:
michael@0 3903 //
michael@0 3904
michael@0 3905 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 3906
michael@0 3907 if (!tximpl) {
michael@0 3908 fail("Failed to allocate transaction.\n");
michael@0 3909 return NS_ERROR_OUT_OF_MEMORY;
michael@0 3910 }
michael@0 3911
michael@0 3912 tx = 0;
michael@0 3913
michael@0 3914 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 3915
michael@0 3916 if (NS_FAILED(result)) {
michael@0 3917 fail("QueryInterface() failed for transaction. (%d)\n", result);
michael@0 3918 return result;
michael@0 3919 }
michael@0 3920
michael@0 3921 result = mgr->DoTransaction(tx);
michael@0 3922
michael@0 3923 if (NS_FAILED(result)) {
michael@0 3924 fail("DoTransaction() returned unexpected error. (%d)\n", result);
michael@0 3925 return result;
michael@0 3926 }
michael@0 3927
michael@0 3928 tx->Release();
michael@0 3929
michael@0 3930 //
michael@0 3931 // Undo the 2 transactions just executed.
michael@0 3932 //
michael@0 3933
michael@0 3934 for (i = 1; i <= 2; ++i) {
michael@0 3935 result = mgr->UndoTransaction();
michael@0 3936 if (NS_FAILED(result)) {
michael@0 3937 fail("Failed to undo transaction %d. (%d)\n", i, result);
michael@0 3938 return result;
michael@0 3939 }
michael@0 3940 }
michael@0 3941
michael@0 3942 //
michael@0 3943 // The RedoErrorTransaction should now be at the top of the redo stack!
michael@0 3944 //
michael@0 3945
michael@0 3946 u1 = u2 = r1 = r2 = 0;
michael@0 3947
michael@0 3948 result = mgr->PeekUndoStack(&u1);
michael@0 3949
michael@0 3950 TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!
michael@0 3951
michael@0 3952 if (NS_FAILED(result)) {
michael@0 3953 fail("Initial PeekUndoStack() failed. (%d)\n", result);
michael@0 3954 return result;
michael@0 3955 }
michael@0 3956
michael@0 3957 result = mgr->PeekRedoStack(&r1);
michael@0 3958
michael@0 3959 TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!
michael@0 3960
michael@0 3961 if (NS_FAILED(result)) {
michael@0 3962 fail("Initial PeekRedoStack() failed. (%d)\n", result);
michael@0 3963 return result;
michael@0 3964 }
michael@0 3965
michael@0 3966 result = mgr->RedoTransaction();
michael@0 3967
michael@0 3968 if (result != NS_ERROR_FAILURE) {
michael@0 3969 fail("RedoTransaction() returned unexpected error. (%d)\n", result);
michael@0 3970 return result;
michael@0 3971 }
michael@0 3972
michael@0 3973 result = mgr->PeekUndoStack(&u2);
michael@0 3974
michael@0 3975 TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!
michael@0 3976
michael@0 3977 if (NS_FAILED(result)) {
michael@0 3978 fail("Second PeekUndoStack() failed. (%d)\n", result);
michael@0 3979 return result;
michael@0 3980 }
michael@0 3981
michael@0 3982 if (u1 != u2) {
michael@0 3983 fail("Top of undo stack changed. (%d)\n", result);
michael@0 3984 return NS_ERROR_FAILURE;
michael@0 3985 }
michael@0 3986
michael@0 3987 result = mgr->PeekRedoStack(&r2);
michael@0 3988
michael@0 3989 TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!
michael@0 3990
michael@0 3991 if (NS_FAILED(result)) {
michael@0 3992 fail("Second PeekRedoStack() failed. (%d)\n", result);
michael@0 3993 return result;
michael@0 3994 }
michael@0 3995
michael@0 3996 if (r1 != r2) {
michael@0 3997 fail("Top of redo stack changed. (%d)\n", result);
michael@0 3998 return NS_ERROR_FAILURE;
michael@0 3999 }
michael@0 4000
michael@0 4001 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 4002
michael@0 4003 if (NS_FAILED(result)) {
michael@0 4004 fail("GetNumberOfUndoItems() on undo stack with 2 items failed. (%d)\n",
michael@0 4005 result);
michael@0 4006 return result;
michael@0 4007 }
michael@0 4008
michael@0 4009 if (numitems != 2) {
michael@0 4010 fail("GetNumberOfUndoItems() expected 2 got %d. (%d)\n",
michael@0 4011 numitems, result);
michael@0 4012 return NS_ERROR_FAILURE;
michael@0 4013 }
michael@0 4014
michael@0 4015 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 4016
michael@0 4017 if (NS_FAILED(result)) {
michael@0 4018 fail("GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",
michael@0 4019 result);
michael@0 4020 return result;
michael@0 4021 }
michael@0 4022
michael@0 4023 if (numitems != 2) {
michael@0 4024 fail("GetNumberOfRedoItems() expected 2 got %d. (%d)\n",
michael@0 4025 numitems, result);
michael@0 4026 return NS_ERROR_FAILURE;
michael@0 4027 }
michael@0 4028
michael@0 4029 passed("Test transaction RedoTransaction() error");
michael@0 4030
michael@0 4031 /*******************************************************************
michael@0 4032 *
michael@0 4033 * Make sure that setting the transaction manager's max transaction
michael@0 4034 * count to zero, clears both the undo and redo stacks, and executes
michael@0 4035 * all new commands without pushing them on the undo stack!
michael@0 4036 *
michael@0 4037 *******************************************************************/
michael@0 4038
michael@0 4039 result = mgr->SetMaxTransactionCount(0);
michael@0 4040
michael@0 4041 if (NS_FAILED(result)) {
michael@0 4042 fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
michael@0 4043 return result;
michael@0 4044 }
michael@0 4045
michael@0 4046 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 4047
michael@0 4048 if (NS_FAILED(result)) {
michael@0 4049 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 4050 result);
michael@0 4051 return result;
michael@0 4052 }
michael@0 4053
michael@0 4054 if (numitems != 0) {
michael@0 4055 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 4056 numitems, result);
michael@0 4057 return NS_ERROR_FAILURE;
michael@0 4058 }
michael@0 4059
michael@0 4060 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 4061
michael@0 4062 if (NS_FAILED(result)) {
michael@0 4063 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 4064 result);
michael@0 4065 return result;
michael@0 4066 }
michael@0 4067
michael@0 4068 if (numitems != 0) {
michael@0 4069 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 4070 numitems, result);
michael@0 4071 return NS_ERROR_FAILURE;
michael@0 4072 }
michael@0 4073
michael@0 4074 for (i = 1; i <= 20; i++) {
michael@0 4075 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 4076
michael@0 4077 if (!tximpl) {
michael@0 4078 fail("Failed to allocate transaction %d.\n", i);
michael@0 4079 return NS_ERROR_OUT_OF_MEMORY;
michael@0 4080 }
michael@0 4081
michael@0 4082 tx = 0;
michael@0 4083 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 4084 if (NS_FAILED(result)) {
michael@0 4085 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 4086 i, result);
michael@0 4087 return result;
michael@0 4088 }
michael@0 4089
michael@0 4090 result = mgr->BeginBatch(nullptr);
michael@0 4091
michael@0 4092 if (NS_FAILED(result)) {
michael@0 4093 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 4094 return result;
michael@0 4095 }
michael@0 4096
michael@0 4097 result = mgr->DoTransaction(tx);
michael@0 4098 if (NS_FAILED(result)) {
michael@0 4099 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 4100 return result;
michael@0 4101 }
michael@0 4102
michael@0 4103 tx->Release();
michael@0 4104
michael@0 4105 result = mgr->EndBatch(false);
michael@0 4106
michael@0 4107 if (NS_FAILED(result)) {
michael@0 4108 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 4109 return result;
michael@0 4110 }
michael@0 4111
michael@0 4112 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 4113
michael@0 4114 if (NS_FAILED(result)) {
michael@0 4115 fail("GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",
michael@0 4116 result);
michael@0 4117 return result;
michael@0 4118 }
michael@0 4119
michael@0 4120 if (numitems != 0) {
michael@0 4121 fail("GetNumberOfUndoItems() expected 0 got %d. (%d)\n",
michael@0 4122 numitems, result);
michael@0 4123 return NS_ERROR_FAILURE;
michael@0 4124 }
michael@0 4125
michael@0 4126 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 4127
michael@0 4128 if (NS_FAILED(result)) {
michael@0 4129 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 4130 result);
michael@0 4131 return result;
michael@0 4132 }
michael@0 4133
michael@0 4134 if (numitems != 0) {
michael@0 4135 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 4136 numitems, result);
michael@0 4137 return NS_ERROR_FAILURE;
michael@0 4138 }
michael@0 4139 }
michael@0 4140
michael@0 4141 passed("Test max transaction count of zero");
michael@0 4142
michael@0 4143 /*******************************************************************
michael@0 4144 *
michael@0 4145 * Release the transaction manager. Any transactions on the undo
michael@0 4146 * and redo stack should automatically be released:
michael@0 4147 *
michael@0 4148 *******************************************************************/
michael@0 4149
michael@0 4150 result = mgr->SetMaxTransactionCount(-1);
michael@0 4151
michael@0 4152 if (NS_FAILED(result)) {
michael@0 4153 fail("SetMaxTransactionCount(0) failed. (%d)\n", result);
michael@0 4154 return result;
michael@0 4155 }
michael@0 4156
michael@0 4157 // Push 20 transactions on the undo stack:
michael@0 4158
michael@0 4159 for (i = 1; i <= 20; i++) {
michael@0 4160 tximpl = factory->create(mgr, NONE_FLAG);
michael@0 4161
michael@0 4162 if (!tximpl) {
michael@0 4163 fail("Failed to allocate transaction %d.\n", i);
michael@0 4164 return NS_ERROR_OUT_OF_MEMORY;
michael@0 4165 }
michael@0 4166
michael@0 4167 tx = 0;
michael@0 4168 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 4169 if (NS_FAILED(result)) {
michael@0 4170 fail("QueryInterface() failed for transaction %d. (%d)\n",
michael@0 4171 i, result);
michael@0 4172 return result;
michael@0 4173 }
michael@0 4174
michael@0 4175 result = mgr->BeginBatch(nullptr);
michael@0 4176
michael@0 4177 if (NS_FAILED(result)) {
michael@0 4178 fail("BeginBatch(nullptr) failed. (%d)\n", result);
michael@0 4179 return result;
michael@0 4180 }
michael@0 4181
michael@0 4182 result = mgr->DoTransaction(tx);
michael@0 4183 if (NS_FAILED(result)) {
michael@0 4184 fail("Failed to execute transaction %d. (%d)\n", i, result);
michael@0 4185 return result;
michael@0 4186 }
michael@0 4187
michael@0 4188 tx->Release();
michael@0 4189
michael@0 4190 result = mgr->EndBatch(false);
michael@0 4191
michael@0 4192 if (NS_FAILED(result)) {
michael@0 4193 fail("EndBatch(false) failed. (%d)\n", result);
michael@0 4194 return result;
michael@0 4195 }
michael@0 4196
michael@0 4197 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 4198
michael@0 4199 if (NS_FAILED(result)) {
michael@0 4200 fail("GetNumberOfUndoItems() on undo stack with %d items failed. (%d)\n",
michael@0 4201 i, result);
michael@0 4202 return result;
michael@0 4203 }
michael@0 4204
michael@0 4205 if (numitems != i) {
michael@0 4206 fail("GetNumberOfUndoItems() expected %d got %d. (%d)\n",
michael@0 4207 i, numitems, result);
michael@0 4208 return NS_ERROR_FAILURE;
michael@0 4209 }
michael@0 4210
michael@0 4211 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 4212
michael@0 4213 if (NS_FAILED(result)) {
michael@0 4214 fail("GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",
michael@0 4215 result);
michael@0 4216 return result;
michael@0 4217 }
michael@0 4218
michael@0 4219 if (numitems != 0) {
michael@0 4220 fail("GetNumberOfRedoItems() expected 0 got %d. (%d)\n",
michael@0 4221 numitems, result);
michael@0 4222 return NS_ERROR_FAILURE;
michael@0 4223 }
michael@0 4224 }
michael@0 4225
michael@0 4226 for (i = 1; i <= 10; i++) {
michael@0 4227
michael@0 4228 result = mgr->UndoTransaction();
michael@0 4229 if (NS_FAILED(result)) {
michael@0 4230 fail("Failed to undo transaction %d. (%d)\n", i, result);
michael@0 4231 return result;
michael@0 4232 }
michael@0 4233 }
michael@0 4234 result = mgr->GetNumberOfUndoItems(&numitems);
michael@0 4235
michael@0 4236 if (NS_FAILED(result)) {
michael@0 4237 fail("GetNumberOfUndoItems() on empty undo stack with 10 items failed. (%d)\n",
michael@0 4238 result);
michael@0 4239 return result;
michael@0 4240 }
michael@0 4241
michael@0 4242 if (numitems != 10) {
michael@0 4243 fail("GetNumberOfUndoItems() expected 10 got %d. (%d)\n",
michael@0 4244 numitems, result);
michael@0 4245 return NS_ERROR_FAILURE;
michael@0 4246 }
michael@0 4247
michael@0 4248 result = mgr->GetNumberOfRedoItems(&numitems);
michael@0 4249
michael@0 4250 if (NS_FAILED(result)) {
michael@0 4251 fail("GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",
michael@0 4252 result);
michael@0 4253 return result;
michael@0 4254 }
michael@0 4255
michael@0 4256 if (numitems != 10) {
michael@0 4257 fail("GetNumberOfRedoItems() expected 10 got %d. (%d)\n",
michael@0 4258 numitems, result);
michael@0 4259 return NS_ERROR_FAILURE;
michael@0 4260 }
michael@0 4261
michael@0 4262 result = mgr->Clear();
michael@0 4263 if (NS_FAILED(result)) {
michael@0 4264 fail("Clear() failed. (%d)\n", result);
michael@0 4265 return result;
michael@0 4266 }
michael@0 4267
michael@0 4268 passed("Release the transaction manager");
michael@0 4269
michael@0 4270 /*******************************************************************
michael@0 4271 *
michael@0 4272 * Make sure number of transactions created matches number of
michael@0 4273 * transactions destroyed!
michael@0 4274 *
michael@0 4275 *******************************************************************/
michael@0 4276
michael@0 4277 /* Disabled because the current cycle collector doesn't delete
michael@0 4278 cycle collectable objects synchronously.
michael@0 4279 if (sConstructorCount != sDestructorCount) {
michael@0 4280 fail("Transaction constructor count (%d) != destructor count (%d).\n",
michael@0 4281 sConstructorCount, sDestructorCount);
michael@0 4282 return NS_ERROR_FAILURE;
michael@0 4283 }*/
michael@0 4284
michael@0 4285 passed("Number of transactions created and destroyed match");
michael@0 4286 passed("%d transactions processed during quick batch test",
michael@0 4287 sConstructorCount);
michael@0 4288
michael@0 4289 return NS_OK;
michael@0 4290 }
michael@0 4291
michael@0 4292 nsresult
michael@0 4293 simple_batch_test()
michael@0 4294 {
michael@0 4295 /*******************************************************************
michael@0 4296 *
michael@0 4297 * Initialize globals for test.
michael@0 4298 *
michael@0 4299 *******************************************************************/
michael@0 4300 reset_globals();
michael@0 4301 sDestructorOrderArr = sSimpleBatchTestDestructorOrderArr;
michael@0 4302 sDoOrderArr = sSimpleBatchTestDoOrderArr;
michael@0 4303 sUndoOrderArr = sSimpleBatchTestUndoOrderArr;
michael@0 4304 sRedoOrderArr = sSimpleBatchTestRedoOrderArr;
michael@0 4305
michael@0 4306 /*******************************************************************
michael@0 4307 *
michael@0 4308 * Run the quick batch test.
michael@0 4309 *
michael@0 4310 *******************************************************************/
michael@0 4311
michael@0 4312 printf("\n-----------------------------------------------------\n");
michael@0 4313 printf("- Begin Batch Transaction Test:\n");
michael@0 4314 printf("-----------------------------------------------------\n");
michael@0 4315
michael@0 4316 SimpleTransactionFactory factory;
michael@0 4317
michael@0 4318 return quick_batch_test(&factory);
michael@0 4319 }
michael@0 4320
michael@0 4321 nsresult
michael@0 4322 aggregation_batch_test()
michael@0 4323 {
michael@0 4324 /*******************************************************************
michael@0 4325 *
michael@0 4326 * Initialize globals for test.
michael@0 4327 *
michael@0 4328 *******************************************************************/
michael@0 4329
michael@0 4330 reset_globals();
michael@0 4331 sDestructorOrderArr = sAggregateBatchTestDestructorOrderArr;
michael@0 4332 sDoOrderArr = sAggregateBatchTestDoOrderArr;
michael@0 4333 sUndoOrderArr = sAggregateBatchTestUndoOrderArr;
michael@0 4334 sRedoOrderArr = sAggregateBatchTestRedoOrderArr;
michael@0 4335
michael@0 4336 /*******************************************************************
michael@0 4337 *
michael@0 4338 * Run the quick batch test.
michael@0 4339 *
michael@0 4340 *******************************************************************/
michael@0 4341
michael@0 4342 printf("\n-----------------------------------------------------\n");
michael@0 4343 printf("- Begin Batch Aggregate Transaction Test:\n");
michael@0 4344 printf("-----------------------------------------------------\n");
michael@0 4345
michael@0 4346 AggregateTransactionFactory factory(3, 2, BATCH_FLAG);
michael@0 4347
michael@0 4348 return quick_batch_test(&factory);
michael@0 4349 }
michael@0 4350
michael@0 4351 /**
michael@0 4352 * Create 'iterations * (iterations + 1) / 2' transactions;
michael@0 4353 * do/undo/redo/undo them.
michael@0 4354 **/
michael@0 4355 nsresult
michael@0 4356 stress_test(TestTransactionFactory *factory, int32_t iterations)
michael@0 4357 {
michael@0 4358 printf("Stress test of %i iterations (may take a while) ... ", iterations);
michael@0 4359 fflush(stdout);
michael@0 4360
michael@0 4361 nsresult result;
michael@0 4362
michael@0 4363 /*******************************************************************
michael@0 4364 *
michael@0 4365 * Create a transaction manager:
michael@0 4366 *
michael@0 4367 *******************************************************************/
michael@0 4368
michael@0 4369 nsCOMPtr<nsITransactionManager> mgr =
michael@0 4370 do_CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, &result);
michael@0 4371 if (NS_FAILED(result) || !mgr) {
michael@0 4372 fail("Failed to create Transaction Manager instance.\n");
michael@0 4373 return NS_ERROR_OUT_OF_MEMORY;
michael@0 4374 }
michael@0 4375
michael@0 4376 int32_t i, j;
michael@0 4377 nsITransaction *tx;
michael@0 4378
michael@0 4379 for (i = 1; i <= iterations; i++) {
michael@0 4380 /*******************************************************************
michael@0 4381 *
michael@0 4382 * Create and execute a bunch of transactions:
michael@0 4383 *
michael@0 4384 *******************************************************************/
michael@0 4385
michael@0 4386 for (j = 1; j <= i; j++) {
michael@0 4387 TestTransaction *tximpl = factory->create(mgr, NONE_FLAG);
michael@0 4388
michael@0 4389 if (!tximpl) {
michael@0 4390 fail("Failed to allocate transaction %d-%d.\n", i, j);
michael@0 4391 return NS_ERROR_OUT_OF_MEMORY;
michael@0 4392 }
michael@0 4393
michael@0 4394 tx = 0;
michael@0 4395 result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);
michael@0 4396 if (NS_FAILED(result)) {
michael@0 4397 fail("QueryInterface() failed for transaction %d-%d. (%d)\n",
michael@0 4398 i, j, result);
michael@0 4399 return result;
michael@0 4400 }
michael@0 4401
michael@0 4402 result = mgr->DoTransaction(tx);
michael@0 4403 if (NS_FAILED(result)) {
michael@0 4404 fail("Failed to execute transaction %d-%d. (%d)\n",
michael@0 4405 i, j, result);
michael@0 4406 return result;
michael@0 4407 }
michael@0 4408
michael@0 4409 tx->Release();
michael@0 4410 }
michael@0 4411
michael@0 4412 /*******************************************************************
michael@0 4413 *
michael@0 4414 * Undo all the transactions:
michael@0 4415 *
michael@0 4416 *******************************************************************/
michael@0 4417
michael@0 4418 for (j = 1; j <= i; j++) {
michael@0 4419 result = mgr->UndoTransaction();
michael@0 4420 if (NS_FAILED(result)) {
michael@0 4421 fail("Failed to undo transaction %d-%d. (%d)\n", i, j, result);
michael@0 4422 return result;
michael@0 4423 }
michael@0 4424 }
michael@0 4425
michael@0 4426 /*******************************************************************
michael@0 4427 *
michael@0 4428 * Redo all the transactions:
michael@0 4429 *
michael@0 4430 *******************************************************************/
michael@0 4431
michael@0 4432 for (j = 1; j <= i; j++) {
michael@0 4433 result = mgr->RedoTransaction();
michael@0 4434 if (NS_FAILED(result)) {
michael@0 4435 fail("Failed to redo transaction %d-%d. (%d)\n", i, j, result);
michael@0 4436 return result;
michael@0 4437 }
michael@0 4438 }
michael@0 4439
michael@0 4440 /*******************************************************************
michael@0 4441 *
michael@0 4442 * Undo all the transactions again so that they all end up on
michael@0 4443 * the redo stack for pruning the next time we execute a new
michael@0 4444 * transaction
michael@0 4445 *
michael@0 4446 *******************************************************************/
michael@0 4447
michael@0 4448 for (j = 1; j <= i; j++) {
michael@0 4449 result = mgr->UndoTransaction();
michael@0 4450 if (NS_FAILED(result)) {
michael@0 4451 fail("Failed to undo transaction %d-%d. (%d)\n", i, j, result);
michael@0 4452 return result;
michael@0 4453 }
michael@0 4454 }
michael@0 4455
michael@0 4456 // Trivial feedback not to let the user think the test is stuck.
michael@0 4457 if (MOZ_UNLIKELY(j % 100 == 0))
michael@0 4458 printf("%i ", j);
michael@0 4459 } // for, iterations.
michael@0 4460
michael@0 4461 printf("passed\n");
michael@0 4462
michael@0 4463 result = mgr->Clear();
michael@0 4464 if (NS_FAILED(result)) {
michael@0 4465 fail("Clear() failed. (%d)\n", result);
michael@0 4466 return result;
michael@0 4467 }
michael@0 4468
michael@0 4469 /* Disabled because the current cycle collector doesn't delete
michael@0 4470 cycle collectable objects synchronously.
michael@0 4471 if (sConstructorCount != sDestructorCount) {
michael@0 4472 fail("Transaction constructor count (%d) != destructor count (%d).\n",
michael@0 4473 sConstructorCount, sDestructorCount);
michael@0 4474 return NS_ERROR_FAILURE;
michael@0 4475 }*/
michael@0 4476
michael@0 4477 passed("%d transactions processed during stress test", sConstructorCount);
michael@0 4478
michael@0 4479 return NS_OK;
michael@0 4480 }
michael@0 4481
michael@0 4482 nsresult
michael@0 4483 simple_stress_test()
michael@0 4484 {
michael@0 4485 /*******************************************************************
michael@0 4486 *
michael@0 4487 * Initialize globals for test.
michael@0 4488 *
michael@0 4489 *******************************************************************/
michael@0 4490
michael@0 4491 reset_globals();
michael@0 4492
michael@0 4493 /*******************************************************************
michael@0 4494 *
michael@0 4495 * Do the stress test:
michael@0 4496 *
michael@0 4497 *******************************************************************/
michael@0 4498
michael@0 4499 printf("\n-----------------------------------------------------\n");
michael@0 4500 printf("- Simple Transaction Stress Test:\n");
michael@0 4501 printf("-----------------------------------------------------\n");
michael@0 4502
michael@0 4503 SimpleTransactionFactory factory;
michael@0 4504
michael@0 4505 int32_t iterations =
michael@0 4506 #ifdef DEBUG
michael@0 4507 10
michael@0 4508 #else
michael@0 4509 //
michael@0 4510 // 1500 iterations sends 1,125,750 transactions through the system!!
michael@0 4511 //
michael@0 4512 1500
michael@0 4513 #endif
michael@0 4514 ;
michael@0 4515 return stress_test(&factory, iterations);
michael@0 4516 }
michael@0 4517
michael@0 4518 nsresult
michael@0 4519 aggregation_stress_test()
michael@0 4520 {
michael@0 4521 /*******************************************************************
michael@0 4522 *
michael@0 4523 * Initialize globals for test.
michael@0 4524 *
michael@0 4525 *******************************************************************/
michael@0 4526
michael@0 4527 reset_globals();
michael@0 4528
michael@0 4529 /*******************************************************************
michael@0 4530 *
michael@0 4531 * Do the stress test:
michael@0 4532 *
michael@0 4533 *******************************************************************/
michael@0 4534
michael@0 4535 printf("\n-----------------------------------------------------\n");
michael@0 4536 printf("- Aggregate Transaction Stress Test:\n");
michael@0 4537 printf("-----------------------------------------------------\n");
michael@0 4538
michael@0 4539 AggregateTransactionFactory factory(3, 4);
michael@0 4540
michael@0 4541 int32_t iterations =
michael@0 4542 #ifdef DEBUG
michael@0 4543 10
michael@0 4544 #else
michael@0 4545 //
michael@0 4546 // 500 iterations sends 2,630,250 transactions through the system!!
michael@0 4547 //
michael@0 4548 500
michael@0 4549 #endif
michael@0 4550 ;
michael@0 4551 return stress_test(&factory, iterations);
michael@0 4552 }
michael@0 4553
michael@0 4554 nsresult
michael@0 4555 aggregation_batch_stress_test()
michael@0 4556 {
michael@0 4557 /*******************************************************************
michael@0 4558 *
michael@0 4559 * Initialize globals for test.
michael@0 4560 *
michael@0 4561 *******************************************************************/
michael@0 4562
michael@0 4563 reset_globals();
michael@0 4564
michael@0 4565 /*******************************************************************
michael@0 4566 *
michael@0 4567 * Do the stress test:
michael@0 4568 *
michael@0 4569 *******************************************************************/
michael@0 4570
michael@0 4571 printf("\n-----------------------------------------------------\n");
michael@0 4572 printf("- Aggregate Batch Transaction Stress Test:\n");
michael@0 4573 printf("-----------------------------------------------------\n");
michael@0 4574
michael@0 4575 AggregateTransactionFactory factory(3, 4, BATCH_FLAG);
michael@0 4576
michael@0 4577 int32_t iterations =
michael@0 4578 #ifdef DEBUG
michael@0 4579 10
michael@0 4580 #else
michael@0 4581 #if defined(MOZ_ASAN) || defined(MOZ_WIDGET_ANDROID)
michael@0 4582 // See Bug 929985: 500 is too many for ASAN and Android, 100 is safe.
michael@0 4583 100
michael@0 4584 #else
michael@0 4585 //
michael@0 4586 // 500 iterations sends 2,630,250 transactions through the system!!
michael@0 4587 //
michael@0 4588 500
michael@0 4589 #endif
michael@0 4590 #endif
michael@0 4591 ;
michael@0 4592 return stress_test(&factory, iterations);
michael@0 4593 }
michael@0 4594
michael@0 4595 int
michael@0 4596 main (int argc, char *argv[])
michael@0 4597 {
michael@0 4598 ScopedXPCOM xpcom("nsITransactionManager");
michael@0 4599 if (xpcom.failed())
michael@0 4600 return 1;
michael@0 4601
michael@0 4602 nsresult result;
michael@0 4603
michael@0 4604 //
michael@0 4605 // quick_test() part:
michael@0 4606 //
michael@0 4607
michael@0 4608 result = simple_test();
michael@0 4609 NS_ENSURE_SUCCESS(result, 1);
michael@0 4610
michael@0 4611 result = aggregation_test();
michael@0 4612 NS_ENSURE_SUCCESS(result, 1);
michael@0 4613
michael@0 4614 //
michael@0 4615 // quick_batch_test() part:
michael@0 4616 //
michael@0 4617
michael@0 4618 result = simple_batch_test();
michael@0 4619 NS_ENSURE_SUCCESS(result, 1);
michael@0 4620
michael@0 4621 result = aggregation_batch_test();
michael@0 4622 NS_ENSURE_SUCCESS(result, 1);
michael@0 4623
michael@0 4624 //
michael@0 4625 // stress_test() part:
michael@0 4626 //
michael@0 4627
michael@0 4628 result = simple_stress_test();
michael@0 4629 NS_ENSURE_SUCCESS(result, 1);
michael@0 4630
michael@0 4631 result = aggregation_stress_test();
michael@0 4632 NS_ENSURE_SUCCESS(result, 1);
michael@0 4633
michael@0 4634 result = aggregation_batch_stress_test();
michael@0 4635 NS_ENSURE_SUCCESS(result, 1);
michael@0 4636
michael@0 4637 return 0;
michael@0 4638 }

mercurial