WPrototyped_test.h 3.95 KB
Newer Older
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WPROTOTYPED_TEST_H
#define WPROTOTYPED_TEST_H

Sebastian Eichelbaum's avatar
[STYLE]  
Sebastian Eichelbaum committed
28 29
#include <string>

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#include <cxxtest/TestSuite.h>

#include "../WPrototyped.h"

/**
 * Helper class derived from WPrototyped to check WPrototypes functionality.
 */
class SomePrototypeClass1: public WPrototyped
{
public:
    /**
     * Gets the name of this prototype.
     *
     * \return the name.
     */
    virtual const std::string getName() const
    {
        return "test1";
    };

    /**
     * Gets the description for this prototype.
     *
     * \return the description
     */
    virtual const std::string getDescription() const
    {
        return "test1";
    };
};


/**
63
 * Another helper class derived from \ref SomePrototypeClass1. Used to check against \ref SomePrototypeClass1.
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
64
 */
65
class SomePrototypeClass2: public SomePrototypeClass1
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
{
public:
    /**
     * Gets the name of this prototype.
     *
     * \return the name.
     */
    virtual const std::string getName() const
    {
        return "test2";
    };

    /**
     * Gets the description for this prototype.
     *
     * \return the description
     */
    virtual const std::string getDescription() const
    {
        return "test2";
    };
};

89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
/**
 * Another helper class derived from WPrototyped. Used to check against \ref SomePrototypeClass1.
 */
class SomePrototypeClass3: public WPrototyped
{
public:
    /**
     * Gets the name of this prototype.
     *
     * \return the name.
     */
    virtual const std::string getName() const
    {
        return "test3";
    };

    /**
     * Gets the description for this prototype.
     *
     * \return the description
     */
    virtual const std::string getDescription() const
    {
        return "test3";
    };
};

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
116 117 118 119 120 121 122 123 124 125 126 127 128
/**
 * Test WPrototyped
 */
class WPrototypedTest : public CxxTest::TestSuite
{
public:
    /**
     * Test the runtime type check
     */
    void testType( void )
    {
        SomePrototypeClass1 a;
        SomePrototypeClass2 b;
129
        SomePrototypeClass3 c;
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
130 131 132 133 134 135

        // check the type checking mechanism in WPrototyped

        // these should be true
        TS_ASSERT( a.isA< SomePrototypeClass1 >() );
        TS_ASSERT( b.isA< SomePrototypeClass2 >() );
136 137 138 139 140 141 142 143 144
        TS_ASSERT( b.isA< SomePrototypeClass1 >() );

        // The following lines would cause a warning
        // "nonnull argument 'this' compared to NULL"
        // because they would be always true,
        // thus they are commented out.
        //TS_ASSERT( a.isA< WPrototyped >() );
        //TS_ASSERT( b.isA< WPrototyped >() );
        //TS_ASSERT( c.isA< WPrototyped >() );
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
145 146 147

        // check against other types not in polymorphic relation to each other (except the base class)
        TS_ASSERT( !a.isA< SomePrototypeClass2 >() );
148 149 150 151
        TS_ASSERT( !a.isA< SomePrototypeClass3 >() );
        TS_ASSERT( !b.isA< SomePrototypeClass3 >() );
        TS_ASSERT( !c.isA< SomePrototypeClass1 >() );
        TS_ASSERT( !c.isA< SomePrototypeClass2 >() );
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
152 153 154 155
    }
};

#endif  // WPROTOTYPED_TEST_H