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 enum EnumType {}; 34 typedef int PrimitiveType; 35 typedef int *PointerType; 36 37 // A few tests that define the contract 38 static void test() { 39 STATIC_ASSERT((IsBaseOf<A, B>::value)); 40 STATIC_ASSERT((IsBaseOf<const A, volatile B>::value)); 41 STATIC_ASSERT((IsBaseOf<volatile A, const B>::value)); 42 STATIC_ASSERT((!IsBaseOf<A, C>::value)); 43 STATIC_ASSERT((!IsBaseOf<const A, volatile C>::value)); 44 STATIC_ASSERT((!IsBaseOf<volatile A, const C>::value)); 45 STATIC_ASSERT((IsBaseOf<A, A>::value)); 46 STATIC_ASSERT((IsBaseOf<const A, A>::value)); 47 STATIC_ASSERT((IsBaseOf<A, const A>::value)); 48 49 STATIC_ASSERT((!IsBaseOf<EnumType, EnumType>::value)); 50 STATIC_ASSERT((!IsBaseOf<PrimitiveType, PrimitiveType>::value)); 51 STATIC_ASSERT((!IsBaseOf<PointerType, PointerType>::value)); 52 } 53 }; 54 55 class IsBaseAndDerivedTest { 56 class AbstractBase { virtual void dummy() = 0;}; 57 58 class A: AbstractBase {}; 59 class B: A {}; 60 class C {}; 61 62 enum EnumType {}; 63 typedef int PrimitiveType; 64 typedef int *PointerType; 65 66 // A few tests that define the contract 67 static void test() { 68 STATIC_ASSERT((IsBaseAndDerived<AbstractBase, A>::value)); 69 STATIC_ASSERT((IsBaseAndDerived<A, B>::value)); 70 STATIC_ASSERT((IsBaseAndDerived<const A, volatile B>::value)); 71 STATIC_ASSERT((IsBaseAndDerived<volatile A, const B>::value)); 72 STATIC_ASSERT((!IsBaseAndDerived<A, C>::value)); 73 STATIC_ASSERT((!IsBaseAndDerived<const A, volatile C>::value)); 74 STATIC_ASSERT((!IsBaseAndDerived<volatile A, const C>::value)); 75 STATIC_ASSERT((!IsBaseAndDerived<A, A>::value)); 76 STATIC_ASSERT((!IsBaseAndDerived<const A, A>::value)); 77 STATIC_ASSERT((!IsBaseAndDerived<A, const A>::value)); 78 79 STATIC_ASSERT((!IsBaseAndDerived<EnumType, EnumType>::value)); 80 STATIC_ASSERT((!IsBaseAndDerived<PrimitiveType, PrimitiveType>::value)); 81 STATIC_ASSERT((!IsBaseAndDerived<PointerType, PointerType>::value)); 82 } 83 }; 84