[cfe-commits] [libcxxabi] r149453 - in /libcxxabi/trunk/test: catch_class_01.cpp catch_class_02.cpp catch_class_03.cpp catch_class_04.cpp dynamic_cast_stress.cpp
Howard Hinnant
hhinnant at apple.com
Tue Jan 31 15:52:21 PST 2012
Author: hhinnant
Date: Tue Jan 31 17:52:20 2012
New Revision: 149453
URL: http://llvm.org/viewvc/llvm-project?rev=149453&view=rev
Log:
More test cases concentrating on catching class types.
Added:
libcxxabi/trunk/test/catch_class_01.cpp
libcxxabi/trunk/test/catch_class_02.cpp
libcxxabi/trunk/test/catch_class_03.cpp
libcxxabi/trunk/test/catch_class_04.cpp
Modified:
libcxxabi/trunk/test/dynamic_cast_stress.cpp
Added: libcxxabi/trunk/test/catch_class_01.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/catch_class_01.cpp?rev=149453&view=auto
==============================================================================
--- libcxxabi/trunk/test/catch_class_01.cpp (added)
+++ libcxxabi/trunk/test/catch_class_01.cpp Tue Jan 31 17:52:20 2012
@@ -0,0 +1,58 @@
+//===---------------------- catch_class_01.cpp ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <exception>
+#include <stdlib.h>
+#include <assert.h>
+
+struct A
+{
+ static int count;
+ int id_;
+ explicit A(int id) : id_(id) {count++;}
+ A(const A& a) : id_(a.id_) {count++;}
+ ~A() {count--;}
+};
+
+int A::count = 0;
+
+void f1()
+{
+ throw A(3);
+}
+
+void f2()
+{
+ try
+ {
+ assert(A::count == 0);
+ f1();
+ }
+ catch (A a)
+ {
+ assert(A::count != 0);
+ assert(a.id_ == 3);
+ throw;
+ }
+}
+
+int main()
+{
+ try
+ {
+ f2();
+ assert(false);
+ }
+ catch (const A& a)
+ {
+ assert(A::count != 0);
+ assert(a.id_ == 3);
+ }
+ assert(A::count == 0);
+}
Added: libcxxabi/trunk/test/catch_class_02.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/catch_class_02.cpp?rev=149453&view=auto
==============================================================================
--- libcxxabi/trunk/test/catch_class_02.cpp (added)
+++ libcxxabi/trunk/test/catch_class_02.cpp Tue Jan 31 17:52:20 2012
@@ -0,0 +1,83 @@
+//===---------------------- catch_class_02.cpp ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <exception>
+#include <stdlib.h>
+#include <assert.h>
+
+struct B
+{
+ static int count;
+ int id_;
+ explicit B(int id) : id_(id) {count++;}
+ B(const B& a) : id_(a.id_) {count++;}
+ ~B() {count--;}
+};
+
+int B::count = 0;
+
+struct A
+ : B
+{
+ static int count;
+ int id_;
+ explicit A(int id) : B(id-1), id_(id) {count++;}
+ A(const A& a) : B(a.id_-1), id_(a.id_) {count++;}
+ ~A() {count--;}
+};
+
+int A::count = 0;
+
+void f1()
+{
+ assert(A::count == 0);
+ assert(B::count == 0);
+ A a(3);
+ assert(A::count == 1);
+ assert(B::count == 1);
+ throw a;
+ assert(false);
+}
+
+void f2()
+{
+ try
+ {
+ assert(A::count == 0);
+ f1();
+ assert(false);
+ }
+ catch (A a)
+ {
+ assert(A::count != 0);
+ assert(B::count != 0);
+ assert(a.id_ == 3);
+ throw;
+ }
+ catch (B b)
+ {
+ assert(false);
+ }
+}
+
+int main()
+{
+ try
+ {
+ f2();
+ assert(false);
+ }
+ catch (const B& b)
+ {
+ assert(B::count != 0);
+ assert(b.id_ == 2);
+ }
+ assert(A::count == 0);
+ assert(B::count == 0);
+}
Added: libcxxabi/trunk/test/catch_class_03.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/catch_class_03.cpp?rev=149453&view=auto
==============================================================================
--- libcxxabi/trunk/test/catch_class_03.cpp (added)
+++ libcxxabi/trunk/test/catch_class_03.cpp Tue Jan 31 17:52:20 2012
@@ -0,0 +1,190 @@
+//===---------------------- catch_class_03.cpp ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+/*
+ This test checks that adjustedPtr is correct as there exist offsets in this
+ object for the various subobjects, all of which have a unique id_ to
+ check against.
+*/
+
+#include <exception>
+#include <stdlib.h>
+#include <assert.h>
+
+struct B
+{
+ static int count;
+ int id_;
+ explicit B(int id) : id_(id) {count++;}
+ B(const B& a) : id_(a.id_) {count++;}
+ ~B() {count--;}
+};
+
+int B::count = 0;
+
+struct C1
+ : B
+{
+ static int count;
+ int id_;
+ explicit C1(int id) : B(id-2), id_(id) {count++;}
+ C1(const C1& a) : B(a.id_-2), id_(a.id_) {count++;}
+ ~C1() {count--;}
+};
+
+int C1::count = 0;
+
+struct C2
+ : B
+{
+ static int count;
+ int id_;
+ explicit C2(int id) : B(id-2), id_(id) {count++;}
+ C2(const C2& a) : B(a.id_-2), id_(a.id_) {count++;}
+ ~C2() {count--;}
+};
+
+int C2::count = 0;
+
+struct A
+ : C1, C2
+{
+ static int count;
+ int id_;
+ explicit A(int id) : C1(id-1), C2(id-2), id_(id) {count++;}
+ A(const A& a) : C1(a.id_-1), C2(a.id_-2), id_(a.id_) {count++;}
+ ~A() {count--;}
+};
+
+int A::count = 0;
+
+void f1()
+{
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+ A a(5);
+ assert(A::count == 1);
+ assert(C1::count == 1);
+ assert(C2::count == 1);
+ assert(B::count == 2);
+
+ assert(a.id_ == 5);
+ assert(static_cast<C1&>(a).id_ == 4);
+ assert(static_cast<C2&>(a).id_ == 3);
+ assert(static_cast<B&>(static_cast<C1&>(a)).id_ == 2);
+ assert(static_cast<B&>(static_cast<C2&>(a)).id_ == 1);
+ throw a;
+ assert(false);
+}
+
+void f2()
+{
+ try
+ {
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+ f1();
+ assert(false);
+ }
+ catch (const A& a) // can catch A
+ {
+ assert(a.id_ == 5);
+ assert(static_cast<const C1&>(a).id_ == 4);
+ assert(static_cast<const C2&>(a).id_ == 3);
+ assert(static_cast<const B&>(static_cast<const C1&>(a)).id_ == 2);
+ assert(static_cast<const B&>(static_cast<const C2&>(a)).id_ == 1);
+ throw;
+ }
+ catch (const C1&)
+ {
+ assert(false);
+ }
+ catch (const C2&)
+ {
+ assert(false);
+ }
+ catch (const B&)
+ {
+ assert(false);
+ }
+}
+
+void f3()
+{
+ try
+ {
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+ f2();
+ assert(false);
+ }
+ catch (const B& a) // can not catch B (ambiguous base)
+ {
+ assert(false);
+ }
+ catch (const C1& c1) // can catch C1
+ {
+ assert(c1.id_ == 4);
+ assert(static_cast<const B&>(c1).id_ == 2);
+ throw;
+ }
+ catch (const C2&)
+ {
+ assert(false);
+ }
+}
+
+void f4()
+{
+ try
+ {
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+ f3();
+ assert(false);
+ }
+ catch (const B& a) // can not catch B (ambiguous base)
+ {
+ assert(false);
+ }
+ catch (const C2& c2) // can catch C2
+ {
+ assert(c2.id_ == 3);
+ assert(static_cast<const B&>(c2).id_ == 1);
+ throw;
+ }
+ catch (const C1&)
+ {
+ assert(false);
+ }
+}
+
+int main()
+{
+ try
+ {
+ f4();
+ assert(false);
+ }
+ catch (...)
+ {
+ }
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+}
Added: libcxxabi/trunk/test/catch_class_04.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/catch_class_04.cpp?rev=149453&view=auto
==============================================================================
--- libcxxabi/trunk/test/catch_class_04.cpp (added)
+++ libcxxabi/trunk/test/catch_class_04.cpp Tue Jan 31 17:52:20 2012
@@ -0,0 +1,213 @@
+//===---------------------- catch_class_04.cpp ----------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+/*
+ This test checks that adjustedPtr is correct as there exist offsets in this
+ object for the various subobjects, all of which have a unique id_ to
+ check against. It also checks that virtual bases work properly
+*/
+
+#include <exception>
+#include <stdlib.h>
+#include <assert.h>
+
+struct B
+{
+ static int count;
+ int id_;
+ explicit B(int id) : id_(id) {count++;}
+ B(const B& a) : id_(a.id_) {count++;}
+ ~B() {count--;}
+};
+
+int B::count = 0;
+
+struct C1
+ : virtual B
+{
+ static int count;
+ int id_;
+ explicit C1(int id) : B(id-2), id_(id) {count++;}
+ C1(const C1& a) : B(a.id_-2), id_(a.id_) {count++;}
+ ~C1() {count--;}
+};
+
+int C1::count = 0;
+
+struct C2
+ : virtual private B
+{
+ static int count;
+ int id_;
+ explicit C2(int id) : B(id-2), id_(id) {count++;}
+ C2(const C2& a) : B(a.id_-2), id_(a.id_) {count++;}
+ ~C2() {count--;}
+};
+
+int C2::count = 0;
+
+struct A
+ : C1, C2
+{
+ static int count;
+ int id_;
+ explicit A(int id) : C1(id-1), C2(id-2), B(id+3), id_(id) {count++;}
+ A(const A& a) : C1(a.id_-1), C2(a.id_-2), B(a.id_+3), id_(a.id_) {count++;}
+ ~A() {count--;}
+};
+
+int A::count = 0;
+
+void f1()
+{
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+ A a(5);
+ assert(A::count == 1);
+ assert(C1::count == 1);
+ assert(C2::count == 1);
+ assert(B::count == 1);
+
+ assert(a.id_ == 5);
+ assert(static_cast<C1&>(a).id_ == 4);
+ assert(static_cast<C2&>(a).id_ == 3);
+ assert(static_cast<B&>(a).id_ == 8);
+ throw a;
+ assert(false);
+}
+
+void f2()
+{
+ try
+ {
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+ f1();
+ assert(false);
+ }
+ catch (const A& a) // can catch A
+ {
+ assert(a.id_ == 5);
+ assert(static_cast<const C1&>(a).id_ == 4);
+ assert(static_cast<const C2&>(a).id_ == 3);
+ assert(static_cast<const B&>(a).id_ == 8);
+ throw;
+ }
+ catch (const C1&)
+ {
+ assert(false);
+ }
+ catch (const C2&)
+ {
+ assert(false);
+ }
+ catch (const B&)
+ {
+ assert(false);
+ }
+}
+
+void f3()
+{
+ try
+ {
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+ f2();
+ assert(false);
+ }
+ catch (const B& a) // can catch B
+ {
+ assert(static_cast<const B&>(a).id_ == 8);
+ throw;
+ }
+ catch (const C1& c1)
+ {
+ assert(false);
+ }
+ catch (const C2&)
+ {
+ assert(false);
+ }
+}
+
+void f4()
+{
+ try
+ {
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+ f3();
+ assert(false);
+ }
+ catch (const C2& c2) // can catch C2
+ {
+ assert(c2.id_ == 3);
+ throw;
+ }
+ catch (const B& a) // can not catch B (ambiguous base)
+ {
+ assert(false);
+ }
+ catch (const C1&)
+ {
+ assert(false);
+ }
+}
+
+void f5()
+{
+ try
+ {
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+ f4();
+ assert(false);
+ }
+ catch (const C1& c1) // can catch C1
+ {
+ assert(c1.id_ == 4);
+ assert(static_cast<const B&>(c1).id_ == 8);
+ throw;
+ }
+ catch (const B& a)
+ {
+ assert(false);
+ }
+ catch (const C2&)
+ {
+ assert(false);
+ }
+}
+
+int main()
+{
+ try
+ {
+ f5();
+ assert(false);
+ }
+ catch (...)
+ {
+ }
+ assert(A::count == 0);
+ assert(C1::count == 0);
+ assert(C2::count == 0);
+ assert(B::count == 0);
+}
Modified: libcxxabi/trunk/test/dynamic_cast_stress.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/dynamic_cast_stress.cpp?rev=149453&r1=149452&r2=149453&view=diff
==============================================================================
--- libcxxabi/trunk/test/dynamic_cast_stress.cpp (original)
+++ libcxxabi/trunk/test/dynamic_cast_stress.cpp Tue Jan 31 17:52:20 2012
@@ -52,8 +52,8 @@
{
typedef std::chrono::high_resolution_clock Clock;
typedef std::chrono::duration<double, std::micro> US;
- const std::size_t Width = 20;
- const std::size_t Depth = 6;
+ const std::size_t Width = 10;
+ const std::size_t Depth = 5;
A<Width, Depth> a;
typedef B<Width/2, Depth> Destination;
// typedef A<Width, Depth> Destination;
More information about the cfe-commits
mailing list