diff options
| author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-12-22 16:53:56 +0100 | 
|---|---|---|
| committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-12-22 16:53:56 +0100 | 
| commit | e9fc58cb304323f07aba736fc523903481404cff (patch) | |
| tree | 59db450412ca101aa9601b3f2174436898f955c1 /unittest/Catch/include/internal/catch_generators_impl.hpp | |
| parent | 8150ee4edc7e32d5c27cd3e0f68c630d90865638 (diff) | |
| parent | 48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391 (diff) | |
| download | libnitrokey-e9fc58cb304323f07aba736fc523903481404cff.tar.gz libnitrokey-e9fc58cb304323f07aba736fc523903481404cff.tar.bz2 | |
Merge commit '48b3d82ffe1ed19db9ba3cf7e6536ecf92e27391' as 'unittest/Catch'
Diffstat (limited to 'unittest/Catch/include/internal/catch_generators_impl.hpp')
| -rw-r--r-- | unittest/Catch/include/internal/catch_generators_impl.hpp | 86 | 
1 files changed, 86 insertions, 0 deletions
| diff --git a/unittest/Catch/include/internal/catch_generators_impl.hpp b/unittest/Catch/include/internal/catch_generators_impl.hpp new file mode 100644 index 0000000..fea699a --- /dev/null +++ b/unittest/Catch/include/internal/catch_generators_impl.hpp @@ -0,0 +1,86 @@ +/* + *  Created by Phil on 28/01/2011. + *  Copyright 2011 Two Blue Cubes Ltd. All rights reserved. + * + *  Distributed under the Boost Software License, Version 1.0. (See accompanying + *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED + +#include "catch_interfaces_generators.h" + +#include "catch_common.h" + +#include <vector> +#include <string> +#include <map> + +namespace Catch { + +    struct GeneratorInfo : IGeneratorInfo { + +        GeneratorInfo( std::size_t size ) +        :   m_size( size ), +            m_currentIndex( 0 ) +        {} + +        bool moveNext() { +            if( ++m_currentIndex == m_size ) { +                m_currentIndex = 0; +                return false; +            } +            return true; +        } + +        std::size_t getCurrentIndex() const { +            return m_currentIndex; +        } + +        std::size_t m_size; +        std::size_t m_currentIndex; +    }; + +    /////////////////////////////////////////////////////////////////////////// + +    class GeneratorsForTest : public IGeneratorsForTest { + +    public: +        ~GeneratorsForTest() { +            deleteAll( m_generatorsInOrder ); +        } + +        IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) { +            std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo ); +            if( it == m_generatorsByName.end() ) { +                IGeneratorInfo* info = new GeneratorInfo( size ); +                m_generatorsByName.insert( std::make_pair( fileInfo, info ) ); +                m_generatorsInOrder.push_back( info ); +                return *info; +            } +            return *it->second; +        } + +        bool moveNext() { +            std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin(); +            std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end(); +            for(; it != itEnd; ++it ) { +                if( (*it)->moveNext() ) +                    return true; +            } +            return false; +        } + +    private: +        std::map<std::string, IGeneratorInfo*> m_generatorsByName; +        std::vector<IGeneratorInfo*> m_generatorsInOrder; +    }; + +    IGeneratorsForTest* createGeneratorsForTest() +    { +        return new GeneratorsForTest(); +    } + +} // end namespace Catch + +#endif // TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED | 
