1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "utilities/debug.hpp" 26 #include "utilities/traits/isBaseOf.hpp" 27 28 class IsBaseOfTest { 29 class A {}; 30 class B: A {}; 31 class C {}; 32 33 class U; 34 35 enum EnumType {}; 36 union UnionType {}; 37 typedef int PrimitiveType; 38 typedef int *PointerType; 39 40 // A few tests that define the contract 41 static void test() { 42 STATIC_ASSERT((IsBaseOf<A, B>::value)); 43 STATIC_ASSERT((IsBaseOf<const A, volatile B>::value)); 44 STATIC_ASSERT((IsBaseOf<volatile A, const B>::value)); 45 STATIC_ASSERT((!IsBaseOf<A, C>::value)); 46 STATIC_ASSERT((!IsBaseOf<const A, volatile C>::value)); 47 STATIC_ASSERT((!IsBaseOf<volatile A, const C>::value)); 48 STATIC_ASSERT((!IsBaseOf<A, U>::value)); 49 STATIC_ASSERT((!IsBaseOf<U, A>::value)); 50 STATIC_ASSERT((IsBaseOf<U, U>::value)); 51 STATIC_ASSERT((IsBaseOf<A, A>::value)); 52 STATIC_ASSERT((IsBaseOf<const A, A>::value)); 53 STATIC_ASSERT((IsBaseOf<A, const A>::value)); 54 55 STATIC_ASSERT((!IsBaseOf<EnumType, EnumType>::value)); 56 STATIC_ASSERT((!IsBaseOf<PrimitiveType, PrimitiveType>::value)); 57 STATIC_ASSERT((!IsBaseOf<PointerType, PointerType>::value)); 58 59 // The behaviour below is subject to change, when compiler compatibility is better 60 STATIC_ASSERT((IsBaseOf<UnionType, UnionType>::value)); 61 } 62 }; 63 64 class IsBaseOfAndDerivedTest { 65 class A {}; 66 class B: A {}; 67 class C {}; 68 69 class U; 70 71 enum EnumType {}; 72 union UnionType {}; 73 typedef int PrimitiveType; 74 typedef int *PointerType; 75 76 // A few tests that define the contract 77 void test() { 78 STATIC_ASSERT((IsBaseOfAndDerived<A, B>::value)); 79 STATIC_ASSERT((IsBaseOfAndDerived<const A, volatile B>::value)); 80 STATIC_ASSERT((IsBaseOfAndDerived<volatile A, const B>::value)); 81 STATIC_ASSERT((!IsBaseOfAndDerived<A, C>::value)); 82 STATIC_ASSERT((!IsBaseOfAndDerived<const A, volatile C>::value)); 83 STATIC_ASSERT((!IsBaseOfAndDerived<volatile A, const C>::value)); 84 STATIC_ASSERT((!IsBaseOfAndDerived<A, U>::value)); 85 STATIC_ASSERT((!IsBaseOfAndDerived<U, A>::value)); 86 STATIC_ASSERT((!IsBaseOfAndDerived<U, U>::value)); 87 STATIC_ASSERT((!IsBaseOfAndDerived<A, A>::value)); 88 STATIC_ASSERT((!IsBaseOfAndDerived<const A, A>::value)); 89 STATIC_ASSERT((!IsBaseOfAndDerived<A, const A>::value)); 90 91 STATIC_ASSERT((!IsBaseOfAndDerived<EnumType, EnumType>::value)); 92 STATIC_ASSERT((!IsBaseOfAndDerived<PrimitiveType, PrimitiveType>::value)); 93 STATIC_ASSERT((!IsBaseOfAndDerived<PointerType, PointerType>::value)); 94 STATIC_ASSERT((!IsBaseOfAndDerived<UnionType, UnionType>::value)); 95 } 96 }; 97