Bug 369034 - TestTXMgr has error and leaks object; (Av1a) Add mgr->Clear(), use ScopedXPCOM() and run this test; r=benjamin
authorSerge Gautherie <sgautherie.bz@free.fr>
Wed, 06 May 2009 01:11:14 +0200
changeset 28014 9785c406213bea78d5caf49ca10c895373ced1d0
parent 28013 48bc5af4a2751a83e79b42d62574827b9c4437bc
child 28015 f37d7b5e04937e5c78c88fcbf0a48831bc734d10
push id6842
push usersgautherie.bz@free.fr
push dateTue, 05 May 2009 23:24:16 +0000
treeherdermozilla-central@f13ca2edd374 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbenjamin
bugs369034
milestone1.9.2a1pre
Bug 369034 - TestTXMgr has error and leaks object; (Av1a) Add mgr->Clear(), use ScopedXPCOM() and run this test; r=benjamin
editor/txmgr/tests/Makefile.in
editor/txmgr/tests/TestTXMgr.cpp
--- a/editor/txmgr/tests/Makefile.in
+++ b/editor/txmgr/tests/Makefile.in
@@ -15,16 +15,17 @@
 # The Original Code is mozilla.org code.
 #
 # The Initial Developer of the Original Code is
 # Netscape Communications Corporation.
 # Portions created by the Initial Developer are Copyright (C) 1998
 # the Initial Developer. All Rights Reserved.
 #
 # Contributor(s):
+#   Serge Gautherie <sgautherie.bz@free.fr>
 #
 # Alternatively, the contents of this file may be used under the terms of
 # either of the GNU General Public License Version 2 or later (the "GPL"),
 # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 # in which case the provisions of the GPL or the LGPL are applicable instead
 # of those above. If you wish to allow use of your version of this file only
 # under the terms of either the GPL or the LGPL, and not to allow others to
 # use your version of this file under the terms of the MPL, indicate your
@@ -37,23 +38,13 @@
 
 DEPTH		= ../../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
-REQUIRES	= xpcom \
-		  txmgr \
-		  $(NULL)
-
-PROGRAM		= TestTXMgr$(BIN_SUFFIX)
+REQUIRES = txmgr xpcom
 
-CPPSRCS		= TestTXMgr.cpp
-
-LIBS = \
-	$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
-	$(MOZ_COMPONENT_LIBS) \
-	$(NULL)
+CPP_UNIT_TESTS = TestTXMgr.cpp
 
 include $(topsrcdir)/config/rules.mk
-
--- a/editor/txmgr/tests/TestTXMgr.cpp
+++ b/editor/txmgr/tests/TestTXMgr.cpp
@@ -15,36 +15,35 @@
  * The Original Code is mozilla.org code.
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
  * Portions created by the Initial Developer are Copyright (C) 1998
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
+ *   Serge Gautherie <sgautherie.bz@free.fr>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-#include <stdlib.h>
-#include <stdio.h>
-#include "nsXPCOM.h"
+#include "TestHarness.h"
+
 #include "nsITransactionManager.h"
-#include "nsIComponentManager.h"
 #include "nsComponentManagerUtils.h"
 
 static PRInt32 sConstructorCount     = 0;
 static PRInt32 sDestructorCount      = 0;
 static PRInt32 *sDestructorOrderArr  = 0;
 static PRInt32 sDoCount              = 0;
 static PRInt32 *sDoOrderArr          = 0;
 static PRInt32 sUndoCount            = 0;
@@ -901,18 +900,18 @@ quick_test(TestTransactionFactory *facto
 
   /*******************************************************************
    *
    * 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");
 
   /*******************************************************************
@@ -1196,17 +1195,16 @@ quick_test(TestTransactionFactory *facto
 
   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");
 
   /*******************************************************************
@@ -1581,17 +1579,16 @@ quick_test(TestTransactionFactory *facto
 
   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);
 
@@ -2664,16 +2661,22 @@ quick_test(TestTransactionFactory *facto
   }
 
   if (numitems != 10) {
     printf("ERROR: GetNumberOfRedoItems() expected 10 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");
 
   /*******************************************************************
    *
    * Make sure number of transactions created matches number of
    * transactions destroyed!
    *
    *******************************************************************/
@@ -4366,16 +4369,22 @@ quick_batch_test(TestTransactionFactory 
   }
 
   if (numitems != 10) {
     printf("ERROR: GetNumberOfRedoItems() expected 10 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");
 
   /*******************************************************************
    *
    * Make sure number of transactions created matches number of
    * transactions destroyed!
    *
    *******************************************************************/
@@ -4554,17 +4563,21 @@ stress_test(TestTransactionFactory *fact
       result = mgr->UndoTransaction();
       if (NS_FAILED(result)) {
         printf("ERROR: Failed to undo transaction %d-%d. (%d)\n", i, j, result);
         return result;
       }
     }
   }
 
-  // printf("%d  %d -  ", sConstructorCount, sDestructorCount);
+  result = mgr->Clear();
+  if (NS_FAILED(result)) {
+    printf("ERROR: Clear() failed. (%d)\n", result);
+    return result;
+  }
 
   if (sConstructorCount != sDestructorCount) {
     printf("ERROR: Transaction constructor count (%d) != destructor count (%d).\n",
            sConstructorCount, sDestructorCount);
     return NS_ERROR_FAILURE;
   }
 
   printf("passed\n");
@@ -4659,19 +4672,21 @@ aggregation_batch_stress_test()
   // 500 iterations sends 2,630,250 transactions through the system!!
   //
   return stress_test(&factory, 500);
 }
 
 int
 main (int argc, char *argv[])
 {
-  nsresult result = NS_InitXPCOM2(nsnull, nsnull, nsnull);
-  if (NS_FAILED(result))
-    return result;
+  ScopedXPCOM xpcom("nsITransactionManager");
+  if (xpcom.failed())
+    return 1;
+
+  nsresult result;
 
   result = simple_test();
 
   if (NS_FAILED(result))
     return result;
 
   result = simple_batch_test();