This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[libstdc++] Additional testsuite hook and testcase



I started to try and write a testcase for the deque memory leak fixed
last month.  (It isn't possible, by the way, without changing stl_deque.h
itself -- possibly a useful idea, but not during Phase 3 development.)

Anyhow, I noticed that we're testing basic operations of list and vector,
but not deque, and so I wrote this as an example.  Passes fine on i686-linux
and powerpc-eabisim.


2001-12-27  Phil Edwards  <pme@gcc.gnu.org>

	* testsuite/testsuite_hooks.h (gnu_counting_struct):  Add.
	* testsuite/23_containers/deque_ctor.cc:  New file.


Index: testsuite/testsuite_hooks.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/testsuite_hooks.h,v
retrieving revision 1.3
diff -u -3 -p -r1.3 testsuite_hooks.h
--- testsuite_hooks.h	2001/12/10 08:41:03	1.3
+++ testsuite_hooks.h	2001/12/27 21:50:33
@@ -40,6 +40,12 @@
 //   calling application.  The argument to __set_testsuite_memlimit() is the
 //   limit in megabytes (a floating-point number).  If _GLIBCPP_MEM_LIMITS is
 //   #defined before including this header, then no limiting is attempted.
+//
+// 3)  gnu_counting_struct
+//   This is a POD with a static data member, gnu_counting_struct::count,
+//   which starts at zero, increments on instance construction, and decrements
+//   on instance destruction.  "assert_count(n)" can be called to VERIFY()
+//   that the count equals N.
 
 #ifndef _GLIBCPP_TESTSUITE_HOOKS_H
 #define _GLIBCPP_TESTSUITE_HOOKS_H
@@ -98,6 +104,24 @@ __set_testsuite_memlimit(float __size = 
 #endif
 }
 #endif
+
+
+struct gnu_counting_struct
+{
+    // Specifically and glaringly-obviously marked 'signed' so that when
+    // count mistakenly goes negative, we can track the patterns of
+    // deletions easier.
+    typedef  signed int     size_type;
+    static size_type   count;
+    gnu_counting_struct() { ++count; }
+    gnu_counting_struct (const gnu_counting_struct&) { ++count; }
+    ~gnu_counting_struct() { --count; }
+};
+
+#define assert_count(n)   VERIFY(gnu_counting_struct::count == n)
+
+gnu_counting_struct::size_type  gnu_counting_struct::count = 0;
+
 
 #endif // _GLIBCPP_TESTSUITE_HOOKS_H
 
Index: testsuite/23_containers/deque_ctor.cc
===================================================================
RCS file: deque_ctor.cc
diff -N deque_ctor.cc
--- /dev/null	Tue May  5 13:32:27 1998
+++ deque_ctor.cc	Thu Dec 27 13:50:33 2001
@@ -0,0 +1,46 @@
+// 2001-12-27 pme
+//
+// Copyright (C) 2001 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING.  If not, write to the Free
+// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 23.2.1.1 deque constructors, copy, and assignment
+
+#include <deque>
+#include <testsuite_hooks.h>
+
+typedef std::deque<gnu_counting_struct>   gdeque;
+
+
+// basic alloc/dealloc sanity check
+void
+test01()
+{
+  assert_count (0);
+  {
+     gdeque   d(10);
+     assert_count (10);
+  }
+  assert_count (0);
+}
+
+int main()
+{
+  test01();
+
+  return 0;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]