nsITransactionManager  *mgr = 0;
nsCOMPtr<nsITransactionManager> mgr;
stress_test(TestTransactionFactory *factory, PRInt32 iterations){  /*******************************************************************   *   * Create a transaction manager:   *   *******************************************************************/  printf("Stress test (may take a while) ... ");  fflush(stdout);  PRInt32 i, j;  nsITransactionManager  *mgr = 0;  nsITransaction *tx          = 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;  }  for (i = 1; i <= iterations; i++) {    /*******************************************************************     *     * Execute a bunch of transactions:     *     *******************************************************************/    for (j = 1; j <= i; j++) {      TestTransaction *tximpl = factory->create(mgr, NONE_FLAG);      if (!tximpl) {        printf("ERROR: Failed to allocate transaction %d.\n", j);        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();    }    /*******************************************************************     *     * Undo all the transactions:     *     *******************************************************************/    for (j = 1; j <= i; j++) {      result = mgr->UndoTransaction();      if (NS_FAILED(result)) {        printf("ERROR: Failed to undo transaction %d-%d. (%d)\n", i, j, result);        return result;      }    }    /*******************************************************************     *     * Redo all the transactions:     *     *******************************************************************/    for (j = 1; j <= i; j++) {      result = mgr->RedoTransaction();      if (NS_FAILED(result)) {        printf("ERROR: Failed to redo transaction %d-%d. (%d)\n", i, j, result);        return result;      }    }    /*******************************************************************     *     * Undo all the transactions again so that they all end up on     * the redo stack for pruning the next time we execute a new     * transaction     *     *******************************************************************/    for (j = 1; j <= i; j++) {      result = mgr->UndoTransaction();      if (NS_FAILED(result)) {        printf("ERROR: Failed to undo transaction %d-%d. (%d)\n", i, j, result);        return result;      }    }  }  result = mgr->Release();  if (NS_FAILED(result)) {    printf("ERROR: nsITransactionManager Release() failed. (%d)\n", result);    return result;  }  // printf("%d  %d -  ", sConstructorCount, sDestructorCount);  if (sConstructorCount != sDestructorCount) {    printf("ERROR: Transaction constructor count (%d) != destructor count (%d).\n",           sConstructorCount, sDestructorCount);    return NS_ERROR_FAILURE;  }  printf("passed\n");  printf("%d transactions processed during stress test.\n", sConstructorCount);  return NS_OK;}