result = mgr->Release();  if (NS_FAILED(result)) { printf("ERROR: nsITransactionManager Release() failed. (%d)\n", result); return result; }
quick_test(TestTransactionFactory *factory){  /*******************************************************************   *   * Create a transaction manager implementation:   *   *******************************************************************/  printf("Create transaction manager instance ... ");  PRInt32 i, numitems = 0;  nsITransactionManager *mgr = 0;  nsITransaction  *tx        = 0;  TestTransaction *tximpl    = 0;  nsITransaction *u1 = 0, *u2 = 0;  nsITransaction *r1 = 0, *r2 = 0;  nsresult result;  result = nsComponentManager::CreateInstance(NS_TRANSACTIONMANAGER_CONTRACTID, nsnull,                                        NS_GET_IID(nsITransactionManager), (void **)&mgr);  if (NS_FAILED(result) || !mgr) {    printf("ERROR: Failed to create Transaction Manager instance.\n");    return NS_ERROR_OUT_OF_MEMORY;  }  printf("passed\n");  /*******************************************************************   *   * Call DoTransaction() with a null transaction:   *   *******************************************************************/  printf("Call DoTransaction() with null transaction ... ");  result = mgr->DoTransaction(0);  if (NS_FAILED(result)      && result != NS_ERROR_NULL_POINTER) {    printf("ERROR: DoTransaction() returned unexpected error. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Call UndoTransaction() with an empty undo stack:   *   *******************************************************************/  printf("Call UndoTransaction() with empty undo stack ... ");  result = mgr->UndoTransaction();  if (NS_FAILED(result)) {    printf("ERROR: Undo on empty undo stack failed. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Call RedoTransaction() with an empty redo stack:   *   *******************************************************************/  printf("Call RedoTransaction() with empty redo stack ... ");  result = mgr->RedoTransaction();  if (NS_FAILED(result)) {    printf("ERROR: Redo on empty redo stack failed. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Call SetMaxTransactionCount(-1) with empty undo and redo stacks:   *   *******************************************************************/  printf("Call SetMaxTransactionCount(-1) with empty undo and redo stacks ... ");  result = mgr->SetMaxTransactionCount(-1);  if (NS_FAILED(result)) {    printf("ERROR: SetMaxTransactionCount(-1) failed. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Call SetMaxTransactionCount(0) with empty undo and redo stacks:   *   *******************************************************************/  printf("Call SetMaxTransactionCount(0) with empty undo and redo stacks ... ");  result = mgr->SetMaxTransactionCount(0);  if (NS_FAILED(result)) {    printf("ERROR: SetMaxTransactionCount(0) failed. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Call SetMaxTransactionCount(10) with empty undo and redo stacks:   *   *******************************************************************/  printf("Call SetMaxTransactionCount(10) with empty undo and redo stacks ... ");  result = mgr->SetMaxTransactionCount(10);  if (NS_FAILED(result)) {    printf("ERROR: SetMaxTransactionCount(10) failed. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Call Clear() with empty undo and redo stacks:   *   *******************************************************************/  printf("Call Clear() with empty undo and redo stack ... ");  result = mgr->Clear();  if (NS_FAILED(result)) {    printf("ERROR: Clear on empty undo and redo stack failed. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Call GetNumberOfUndoItems() with an empty undo stack:   *   *******************************************************************/  numitems = 0;  printf("Call GetNumberOfUndoItems() with empty undo stack ... ");  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfUndoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Call GetNumberOfRedoItems() with an empty redo stack:   *   *******************************************************************/  printf("Call GetNumberOfRedoItems() with empty redo stack ... ");  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Call PeekUndoStack() with an empty undo stack:   *   *******************************************************************/  printf("Call PeekUndoStack() with empty undo stack ... ");  tx = 0;  result = mgr->PeekUndoStack(&tx);  TEST_TXMGR_IF_RELEASE(tx); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: PeekUndoStack() on empty undo stack failed. (%d)\n", result);    return result;  }  if (tx != 0) {    printf("ERROR: PeekUndoStack() on empty undo stack failed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Call PeekRedoStack() with an empty undo stack:   *   *******************************************************************/  printf("Call PeekRedoStack() with empty undo stack ... ");  tx = 0;  result = mgr->PeekRedoStack(&tx);  TEST_TXMGR_IF_RELEASE(tx); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: PeekRedoStack() on empty redo stack failed. (%d)\n", result);    return result;  }  if (tx != 0) {    printf("ERROR: PeekRedoStack() on empty redo stack failed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Call AddListener() with a null listener pointer:   *   *******************************************************************/  printf("Call AddListener() with null listener ... ");  result = mgr->AddListener(0);  if (NS_FAILED(result)      && result != NS_ERROR_NULL_POINTER) {    printf("ERROR: AddListener() returned unexpected error. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Call RemoveListener() with a null listener pointer:   *   *******************************************************************/  printf("Call RemoveListener() with null listener ... ");  result = mgr->RemoveListener(0);  if (NS_FAILED(result)      && result != NS_ERROR_NULL_POINTER) {    printf("ERROR: RemoveListener() returned unexpected error. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Test coalescing by executing a transaction that can merge any   * command into itself. Then execute 20 transaction. Afterwards,   * we should still have the first transaction sitting on the undo   * stack.   *   *******************************************************************/  printf("Test coalescing of transactions ... ");  result = mgr->SetMaxTransactionCount(10);  if (NS_FAILED(result)) {    printf("ERROR: SetMaxTransactionCount(0) failed. (%d)\n", result);    return result;  }  tximpl = factory->create(mgr, MERGE_FLAG);  if (!tximpl) {    printf("ERROR: Failed to allocate initial transaction.\n");    return NS_ERROR_OUT_OF_MEMORY;  }  tx = 0;  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);  if (NS_FAILED(result)) {    printf("ERROR: QueryInterface() failed for initial transaction. (%d)\n",           result);    return result;  }  result = mgr->DoTransaction(tx);  if (NS_FAILED(result)) {    printf("ERROR: Failed to execute initial transaction. (%d)\n", result);    return result;  }  tx->Release();  u1 = u2 = r1 = r2 = 0;  result = mgr->PeekUndoStack(&u1);  TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekUndoStack() failed. (%d)\n", result);    return result;  }  if (u1 != tx) {    printf("ERROR: Top of undo stack is different!. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->PeekRedoStack(&r1);  TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekRedoStack() failed. (%d)\n", result);    return result;  }  for (i = 1; i <= 20; i++) {    tximpl = factory->create(mgr, NONE_FLAG);    if (!tximpl) {      printf("ERROR: Failed to allocate transaction %d.\n", i);      return NS_ERROR_OUT_OF_MEMORY;    }    tx = 0;    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);    if (NS_FAILED(result)) {      printf("ERROR: QueryInterface() failed for transaction %d. (%d)\n",             i, result);      return result;    }    result = mgr->DoTransaction(tx);    if (NS_FAILED(result)) {      printf("ERROR: Failed to execute transaction %d. (%d)\n", i, result);      return result;    }    tx->Release();  }  result = mgr->PeekUndoStack(&u2);  TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekUndoStack() failed. (%d)\n", result);    return result;  }  if (u1 != u2) {    printf("ERROR: Top of undo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->PeekRedoStack(&r2);  TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekRedoStack() failed. (%d)\n", result);    return result;  }  if (r1 != r2) {    printf("ERROR: Top of redo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 1 item failed. (%d)\n",           result);    return result;  }  if (numitems != 1) {    printf("ERROR: GetNumberOfUndoItems() expected 1 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->Clear();  if (NS_FAILED(result)) {    printf("ERROR: Clear() failed. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Execute 20 transactions. Afterwards, we should have 10   * transactions on the undo stack:   *   *******************************************************************/  printf("Execute 20 transactions ... ");  for (i = 1; i <= 20; i++) {    tximpl = factory->create(mgr, NONE_FLAG);    if (!tximpl) {      printf("ERROR: Failed to allocate transaction %d.\n", i);      return NS_ERROR_OUT_OF_MEMORY;    }    tx = 0;    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);    if (NS_FAILED(result)) {      printf("ERROR: QueryInterface() failed for transaction %d. (%d)\n",             i, result);      return result;    }    result = mgr->DoTransaction(tx);    if (NS_FAILED(result)) {      printf("ERROR: Failed to execute transaction %d. (%d)\n", i, result);      return result;    }    tx->Release();  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",           result);    return result;  }  if (numitems != 10) {    printf("ERROR: GetNumberOfUndoItems() expected 10 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Execute 20 transient transactions. Afterwards, we should still   * have the same 10 transactions on the undo stack:   *   *******************************************************************/  printf("Execute 20 transient transactions ... ");  u1 = u2 = r1 = r2 = 0;  result = mgr->PeekUndoStack(&u1);  TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekUndoStack() failed. (%d)\n", result);    return result;  }  result = mgr->PeekRedoStack(&r1);  TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekRedoStack() failed. (%d)\n", result);    return result;  }  for (i = 1; i <= 20; i++) {    tximpl = factory->create(mgr, TRANSIENT_FLAG);    if (!tximpl) {      printf("ERROR: Failed to allocate transaction %d.\n", i);      return NS_ERROR_OUT_OF_MEMORY;    }    tx = 0;    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);    if (NS_FAILED(result)) {      printf("ERROR: QueryInterface() failed for transaction %d. (%d)\n",             i, result);      return result;    }    result = mgr->DoTransaction(tx);    if (NS_FAILED(result)) {      printf("ERROR: Failed to execute transaction %d. (%d)\n", i, result);      return result;    }    tx->Release();  }  result = mgr->PeekUndoStack(&u2);  TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekUndoStack() failed. (%d)\n", result);    return result;  }  if (u1 != u2) {    printf("ERROR: Top of undo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->PeekRedoStack(&r2);  TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekRedoStack() failed. (%d)\n", result);    return result;  }  if (r1 != r2) {    printf("ERROR: Top of redo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",           result);    return result;  }  if (numitems != 10) {    printf("ERROR: GetNumberOfUndoItems() expected 10 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Undo 4 transactions. Afterwards, we should have 6 transactions   * on the undo stack, and 4 on the redo stack:   *   *******************************************************************/  printf("Undo 4 transactions ... ");  for (i = 1; i <= 4; i++) {    result = mgr->UndoTransaction();    if (NS_FAILED(result)) {      printf("ERROR: Failed to undo transaction %d. (%d)\n", i, result);      return result;    }  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",           result);    return result;  }  if (numitems != 6) {    printf("ERROR: GetNumberOfUndoItems() expected 6 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 4) {    printf("ERROR: GetNumberOfRedoItems() expected 4 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Redo 2 transactions. Afterwards, we should have 8 transactions   * on the undo stack, and 2 on the redo stack:   *   *******************************************************************/  printf("Redo 2 transactions ... ");  for (i = 1; i <= 2; ++i) {    result = mgr->RedoTransaction();    if (NS_FAILED(result)) {      printf("ERROR: Failed to redo transaction %d. (%d)\n", i, result);      return result;    }  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 8 items failed. (%d)\n",           result);    return result;  }  if (numitems != 8) {    printf("ERROR: GetNumberOfUndoItems() expected 8 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on redo stack with 2 items failed. (%d)\n",           result);    return result;  }  if (numitems != 2) {    printf("ERROR: GetNumberOfRedoItems() expected 2 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Execute a new transaction. The redo stack should get pruned!   *   *******************************************************************/  printf("Check if new transactions prune the redo stack ... ");  tximpl = factory->create(mgr, NONE_FLAG);  if (!tximpl) {    printf("ERROR: Failed to allocate transaction.\n");    return NS_ERROR_OUT_OF_MEMORY;  }  tx     = 0;  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);  if (NS_FAILED(result)) {    printf("ERROR: QueryInterface() failed for transaction. (%d)\n", result);    return result;  }  result = mgr->DoTransaction(tx);  if (NS_FAILED(result)) {    printf("ERROR: Failed to execute transaction. (%d)\n", result);    return result;  }  tx->Release();  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 9 items failed. (%d)\n",           result);    return result;  }  if (numitems != 9) {    printf("ERROR: GetNumberOfUndoItems() expected 9 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on redo stack with 0 items failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Undo 4 transactions then clear the undo and redo stacks.   *   *******************************************************************/  printf("Undo 4 transactions then clear the undo and redo stacks ... ");  for (i = 1; i <= 4; ++i) {    result = mgr->UndoTransaction();    if (NS_FAILED(result)) {      printf("ERROR: Failed to undo transaction %d. (%d)\n", i, result);      return result;    }  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",           result);    return result;  }  if (numitems != 5) {    printf("ERROR: GetNumberOfUndoItems() expected 5 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on redo stack with 4 items failed. (%d)\n",           result);    return result;  }  if (numitems != 4) {    printf("ERROR: GetNumberOfRedoItems() expected 4 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->Clear();  if (NS_FAILED(result)) {    printf("ERROR: Clear() failed. (%d)\n",           result);    return result;  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on cleared undo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfUndoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty cleared stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Execute 5 transactions.   *   *******************************************************************/  printf("Execute 5 transactions ... ");  for (i = 1; i <= 5; i++) {    tximpl = factory->create(mgr, NONE_FLAG);    if (!tximpl) {      printf("ERROR: Failed to allocate transaction %d.\n", i);      return NS_ERROR_OUT_OF_MEMORY;    }    tx = 0;    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);    if (NS_FAILED(result)) {      printf("ERROR: QueryInterface() failed for transaction %d. (%d)\n",             i, result);      return result;    }    result = mgr->DoTransaction(tx);    if (NS_FAILED(result)) {      printf("ERROR: Failed to execute transaction %d. (%d)\n", i, result);      return result;    }    tx->Release();  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",           result);    return result;  }  if (numitems != 5) {    printf("ERROR: GetNumberOfUndoItems() expected 5 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Test transaction DoTransaction() error:   *   *******************************************************************/  printf("Test transaction DoTransaction() error ... ");  tximpl = factory->create(mgr, THROWS_DO_ERROR_FLAG);  if (!tximpl) {    printf("ERROR: Failed to allocate transaction.\n");    return NS_ERROR_OUT_OF_MEMORY;  }  tx     = 0;  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);  if (NS_FAILED(result)) {    printf("ERROR: QueryInterface() failed for transaction. (%d)\n", result);    return result;  }  u1 = u2 = r1 = r2 = 0;  result = mgr->PeekUndoStack(&u1);  TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekUndoStack() failed. (%d)\n", result);    return result;  }  result = mgr->PeekRedoStack(&r1);  TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekRedoStack() failed. (%d)\n", result);    return result;  }  result = mgr->DoTransaction(tx);  if (NS_FAILED(result) && result != NS_ERROR_FAILURE) {    printf("ERROR: DoTransaction() returned unexpected error. (%d)\n", result);    return result;  }  tx->Release();  result = mgr->PeekUndoStack(&u2);  TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekUndoStack() failed. (%d)\n", result);    return result;  }  if (u1 != u2) {    printf("ERROR: Top of undo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->PeekRedoStack(&r2);  TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekRedoStack() failed. (%d)\n", result);    return result;  }  if (r1 != r2) {    printf("ERROR: Top of redo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 5 items failed. (%d)\n",           result);    return result;  }  if (numitems != 5) {    printf("ERROR: GetNumberOfUndoItems() expected 5 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty redo stack. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Test transaction UndoTransaction() error:   *   *******************************************************************/  printf("Test transaction UndoTransaction() error ... ");  tximpl = factory->create(mgr, THROWS_UNDO_ERROR_FLAG);  if (!tximpl) {    printf("ERROR: Failed to allocate transaction.\n");    return NS_ERROR_OUT_OF_MEMORY;  }  tx     = 0;  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);  if (NS_FAILED(result)) {    printf("ERROR: QueryInterface() failed for transaction. (%d)\n", result);    return result;  }  result = mgr->DoTransaction(tx);  if (NS_FAILED(result)) {    printf("ERROR: DoTransaction() returned unexpected error. (%d)\n", result);    return result;  }  tx->Release();  u1 = u2 = r1 = r2 = 0;  result = mgr->PeekUndoStack(&u1);  TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekUndoStack() failed. (%d)\n", result);    return result;  }  result = mgr->PeekRedoStack(&r1);  TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekRedoStack() failed. (%d)\n", result);    return result;  }  result = mgr->UndoTransaction();  if (NS_FAILED(result) && result != NS_ERROR_FAILURE) {    printf("ERROR: UndoTransaction() returned unexpected error. (%d)\n", result);    return result;  }  result = mgr->PeekUndoStack(&u2);  TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekUndoStack() failed. (%d)\n", result);    return result;  }  if (u1 != u2) {    printf("ERROR: Top of undo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->PeekRedoStack(&r2);  TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekRedoStack() failed. (%d)\n", result);    return result;  }  if (r1 != r2) {    printf("ERROR: Top of redo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",           result);    return result;  }  if (numitems != 6) {    printf("ERROR: GetNumberOfUndoItems() expected 6 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty redo stack. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Test transaction RedoTransaction() error:   *   *******************************************************************/  printf("Test transaction RedoTransaction() error ... ");  tximpl = factory->create(mgr, THROWS_REDO_ERROR_FLAG);  if (!tximpl) {    printf("ERROR: Failed to allocate transaction.\n");    return NS_ERROR_OUT_OF_MEMORY;  }  tx     = 0;  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);  if (NS_FAILED(result)) {    printf("ERROR: QueryInterface() failed for RedoErrorTransaction. (%d)\n",           result);    return result;  }  result = mgr->DoTransaction(tx);  if (NS_FAILED(result)) {    printf("ERROR: DoTransaction() returned unexpected error. (%d)\n", result);    return result;  }  tx->Release();  //  // Execute a normal transaction to be used in a later test:  //  tximpl = factory->create(mgr, NONE_FLAG);  if (!tximpl) {    printf("ERROR: Failed to allocate transaction.\n");    return NS_ERROR_OUT_OF_MEMORY;  }  tx     = 0;  result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);  if (NS_FAILED(result)) {    printf("ERROR: QueryInterface() failed for transaction. (%d)\n", result);    return result;  }  result = mgr->DoTransaction(tx);  if (NS_FAILED(result)) {    printf("ERROR: DoTransaction() returned unexpected error. (%d)\n", result);    return result;  }  tx->Release();  //  // Undo the 2 transactions just executed.  //  for (i = 1; i <= 2; ++i) {    result = mgr->UndoTransaction();    if (NS_FAILED(result)) {      printf("ERROR: Failed to undo transaction %d. (%d)\n", i, result);      return result;    }  }  //  // The RedoErrorTransaction should now be at the top of the redo stack!  //  u1 = u2 = r1 = r2 = 0;  result = mgr->PeekUndoStack(&u1);  TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekUndoStack() failed. (%d)\n", result);    return result;  }  result = mgr->PeekRedoStack(&r1);  TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekRedoStack() failed. (%d)\n", result);    return result;  }  result = mgr->RedoTransaction();  if (NS_FAILED(result) && result != NS_ERROR_FAILURE) {    printf("ERROR: RedoTransaction() returned unexpected error. (%d)\n", result);    return result;  }  result = mgr->PeekUndoStack(&u2);  TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekUndoStack() failed. (%d)\n", result);    return result;  }  if (u1 != u2) {    printf("ERROR: Top of undo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->PeekRedoStack(&r2);  TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekRedoStack() failed. (%d)\n", result);    return result;  }  if (r1 != r2) {    printf("ERROR: Top of redo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 6 items failed. (%d)\n",           result);    return result;  }  if (numitems != 6) {    printf("ERROR: GetNumberOfUndoItems() expected 6 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty redo stack. (%d)\n",           result);    return result;  }  if (numitems != 2) {    printf("ERROR: GetNumberOfRedoItems() expected 2 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Make sure that setting the transaction manager's max transaction   * count to zero, clears both the undo and redo stacks, and executes   * all new commands without pushing them on the undo stack!   *   *******************************************************************/  printf("Test max transaction count of zero ... ");  result = mgr->SetMaxTransactionCount(0);  if (NS_FAILED(result)) {    printf("ERROR: SetMaxTransactionCount(0) failed. (%d)\n", result);    return result;  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfUndoItems() expected 1 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  for (i = 1; i <= 20; i++) {    tximpl = factory->create(mgr, NONE_FLAG);    if (!tximpl) {      printf("ERROR: Failed to allocate transaction %d.\n", i);      return NS_ERROR_OUT_OF_MEMORY;    }    tx = 0;    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);    if (NS_FAILED(result)) {      printf("ERROR: QueryInterface() failed for transaction %d. (%d)\n",             i, result);      return result;    }    result = mgr->DoTransaction(tx);    if (NS_FAILED(result)) {      printf("ERROR: Failed to execute transaction %d. (%d)\n", i, result);      return result;    }    tx->Release();    result = mgr->GetNumberOfUndoItems(&numitems);    if (NS_FAILED(result)) {      printf("ERROR: GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",             result);      return result;    }    if (numitems != 0) {      printf("ERROR: GetNumberOfUndoItems() expected 1 got %d. (%d)\n",             numitems, result);      return NS_ERROR_FAILURE;    }    result = mgr->GetNumberOfRedoItems(&numitems);    if (NS_FAILED(result)) {      printf("ERROR: GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",             result);      return result;    }    if (numitems != 0) {      printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",             numitems, result);      return NS_ERROR_FAILURE;    }  }  printf("passed\n");  /*******************************************************************   *   * Make sure that setting the transaction manager's max transaction   * count to something greater than the number of transactions on   * both the undo and redo stacks causes no pruning of the stacks:   *   *******************************************************************/  printf("Test SetMaxTransactionCount() greater than num stack items ... ");  result = mgr->SetMaxTransactionCount(-1);  if (NS_FAILED(result)) {    printf("ERROR: SetMaxTransactionCount(0) failed. (%d)\n", result);    return result;  }  // Push 20 transactions on the undo stack:  for (i = 1; i <= 20; i++) {    tximpl = factory->create(mgr, NONE_FLAG);    if (!tximpl) {      printf("ERROR: Failed to allocate transaction %d.\n", i);      return NS_ERROR_OUT_OF_MEMORY;    }    tx = 0;    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);    if (NS_FAILED(result)) {      printf("ERROR: QueryInterface() failed for transaction %d. (%d)\n",             i, result);      return result;    }    result = mgr->DoTransaction(tx);    if (NS_FAILED(result)) {      printf("ERROR: Failed to execute transaction %d. (%d)\n", i, result);      return result;    }    tx->Release();    result = mgr->GetNumberOfUndoItems(&numitems);    if (NS_FAILED(result)) {      printf("ERROR: GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",             result);      return result;    }    if (numitems != i) {      printf("ERROR: GetNumberOfUndoItems() expected 1 got %d. (%d)\n",             numitems, result);      return NS_ERROR_FAILURE;    }    result = mgr->GetNumberOfRedoItems(&numitems);    if (NS_FAILED(result)) {      printf("ERROR: GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",             result);      return result;    }    if (numitems != 0) {      printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",             numitems, result);      return NS_ERROR_FAILURE;    }  }  for (i = 1; i <= 10; i++) {    result = mgr->UndoTransaction();    if (NS_FAILED(result)) {      printf("ERROR: Failed to undo transaction %d. (%d)\n", i, result);      return result;    }  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on empty undo stack with 10 items failed. (%d)\n",           result);    return result;  }  if (numitems != 10) {    printf("ERROR: GetNumberOfUndoItems() expected 10 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",           result);    return result;  }  if (numitems != 10) {    printf("ERROR: GetNumberOfRedoItems() expected 10 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  u1 = u2 = r1 = r2 = 0;  result = mgr->PeekUndoStack(&u1);  TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekUndoStack() failed. (%d)\n", result);    return result;  }  result = mgr->PeekRedoStack(&r1);  TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekRedoStack() failed. (%d)\n", result);    return result;  }  result = mgr->SetMaxTransactionCount(25);  if (NS_FAILED(result)) {    printf("ERROR: SetMaxTransactionCount(25) failed. (%d)\n", result);    return result;  }  result = mgr->PeekUndoStack(&u2);  TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekUndoStack() failed. (%d)\n", result);    return result;  }  if (u1 != u2) {    printf("ERROR: Top of undo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->PeekRedoStack(&r2);  TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekRedoStack() failed. (%d)\n", result);    return result;  }  if (r1 != r2) {    printf("ERROR: Top of redo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",           result);    return result;  }  if (numitems != 10) {    printf("ERROR: GetNumberOfUndoItems() expected 10 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",           result);    return result;  }  if (numitems != 10) {    printf("ERROR: GetNumberOfRedoItems() expected 10 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Test undo stack pruning by setting the transaction   * manager's max transaction count to a number lower than the   * number of transactions on both the undo and redo stacks:   *   *******************************************************************/  printf("Test SetMaxTransactionCount() pruning undo stack ... ");  u1 = u2 = r1 = r2 = 0;  result = mgr->PeekUndoStack(&u1);  TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekUndoStack() failed. (%d)\n", result);    return result;  }  result = mgr->PeekRedoStack(&r1);  TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekRedoStack() failed. (%d)\n", result);    return result;  }  result = mgr->SetMaxTransactionCount(15);  if (NS_FAILED(result)) {    printf("ERROR: SetMaxTransactionCount(25) failed. (%d)\n", result);    return result;  }  result = mgr->PeekUndoStack(&u2);  TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekUndoStack() failed. (%d)\n", result);    return result;  }  if (u1 != u2) {    printf("ERROR: Top of undo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->PeekRedoStack(&r2);  TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekRedoStack() failed. (%d)\n", result);    return result;  }  if (r1 != r2) {    printf("ERROR: Top of redo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on undo stack with 10 items failed. (%d)\n",           result);    return result;  }  if (numitems != 5) {    printf("ERROR: GetNumberOfUndoItems() expected 10 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",           result);    return result;  }  if (numitems != 10) {    printf("ERROR: GetNumberOfRedoItems() expected 10 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Test redo stack pruning by setting the transaction   * manager's max transaction count to a number lower than the   * number of transactions on both the undo and redo stacks:   *   *******************************************************************/  printf("Test SetMaxTransactionCount() pruning redo stack ... ");  u1 = u2 = r1 = r2 = 0;  result = mgr->PeekUndoStack(&u1);  TEST_TXMGR_IF_RELEASE(u1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekUndoStack() failed. (%d)\n", result);    return result;  }  result = mgr->PeekRedoStack(&r1);  TEST_TXMGR_IF_RELEASE(r1); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Initial PeekRedoStack() failed. (%d)\n", result);    return result;  }  result = mgr->SetMaxTransactionCount(5);  if (NS_FAILED(result)) {    printf("ERROR: SetMaxTransactionCount(25) failed. (%d)\n", result);    return result;  }  result = mgr->PeekUndoStack(&u2);  TEST_TXMGR_IF_RELEASE(u2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekUndoStack() failed. (%d)\n", result);    return result;  }  if (u1 == u2 || u2) {    printf("ERROR: Unexpected item at top of undo stack. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->PeekRedoStack(&r2);  TEST_TXMGR_IF_RELEASE(r2); // Don't hold onto any references!  if (NS_FAILED(result)) {    printf("ERROR: Second PeekRedoStack() failed. (%d)\n", result);    return result;  }  if (r1 != r2) {    printf("ERROR: Top of redo stack changed. (%d)\n", result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",           result);    return result;  }  if (numitems != 0) {    printf("ERROR: GetNumberOfUndoItems() expected 0 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on redo stack with 5 items failed. (%d)\n",           result);    return result;  }  if (numitems != 5) {    printf("ERROR: GetNumberOfRedoItems() expected 5 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  printf("passed\n");  /*******************************************************************   *   * Release the transaction manager. Any transactions on the undo   * and redo stack should automatically be released:   *   *******************************************************************/  printf("Release the transaction manager ... ");  result = mgr->SetMaxTransactionCount(-1);  if (NS_FAILED(result)) {    printf("ERROR: SetMaxTransactionCount(0) failed. (%d)\n", result);    return result;  }  // Push 20 transactions on the undo stack:  for (i = 1; i <= 20; i++) {    tximpl = factory->create(mgr, NONE_FLAG);    if (!tximpl) {      printf("ERROR: Failed to allocate transaction %d.\n", i);      return NS_ERROR_OUT_OF_MEMORY;    }    tx = 0;    result = tximpl->QueryInterface(NS_GET_IID(nsITransaction), (void **)&tx);    if (NS_FAILED(result)) {      printf("ERROR: QueryInterface() failed for transaction %d. (%d)\n",             i, result);      return result;    }    result = mgr->DoTransaction(tx);    if (NS_FAILED(result)) {      printf("ERROR: Failed to execute transaction %d. (%d)\n", i, result);      return result;    }    tx->Release();    result = mgr->GetNumberOfUndoItems(&numitems);    if (NS_FAILED(result)) {      printf("ERROR: GetNumberOfUndoItems() on empty undo stack failed. (%d)\n",             result);      return result;    }    if (numitems != i) {      printf("ERROR: GetNumberOfUndoItems() expected 1 got %d. (%d)\n",             numitems, result);      return NS_ERROR_FAILURE;    }    result = mgr->GetNumberOfRedoItems(&numitems);    if (NS_FAILED(result)) {      printf("ERROR: GetNumberOfRedoItems() on empty redo stack failed. (%d)\n",             result);      return result;    }    if (numitems != 0) {      printf("ERROR: GetNumberOfRedoItems() expected 0 got %d. (%d)\n",             numitems, result);      return NS_ERROR_FAILURE;    }  }  for (i = 1; i <= 10; i++) {    result = mgr->UndoTransaction();    if (NS_FAILED(result)) {      printf("ERROR: Failed to undo transaction %d. (%d)\n", i, result);      return result;    }  }  result = mgr->GetNumberOfUndoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfUndoItems() on empty undo stack with 10 items failed. (%d)\n",           result);    return result;  }  if (numitems != 10) {    printf("ERROR: GetNumberOfUndoItems() expected 10 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->GetNumberOfRedoItems(&numitems);  if (NS_FAILED(result)) {    printf("ERROR: GetNumberOfRedoItems() on redo stack with 10 items failed. (%d)\n",           result);    return result;  }  if (numitems != 10) {    printf("ERROR: GetNumberOfRedoItems() expected 10 got %d. (%d)\n",           numitems, result);    return NS_ERROR_FAILURE;  }  result = mgr->Release();  if (NS_FAILED(result)) {    printf("ERROR: nsITransactionManager Release() failed. (%d)\n", result);    return result;  }  printf("passed\n");  /*******************************************************************   *   * Make sure number of transactions created matches number of   * transactions destroyed!   *   *******************************************************************/  printf("Number of transactions created and destroyed match ... ");  if (sConstructorCount != sDestructorCount) {    printf("ERROR: Transaction constructor count (%d) != destructor count (%d).\n",           sConstructorCount, sDestructorCount);    return NS_ERROR_FAILURE;  }  if (NS_FAILED(result)) {    printf("ERROR: nsITransactionManager Release() failed. (%d)\n", result);    return result;  }  printf("passed\n");  printf("%d transactions processed during quick test.\n", sConstructorCount);  return NS_OK;}