~compiz-team/compiz/compiz.fix_1041535

« back to all changes in this revision

Viewing changes to compizconfig/tests/compizconfig_ccs_item_in_list_matcher.h

  • Committer: Tarmac
  • Author(s): Sam Spilsbury
  • Date: 2012-09-10 02:57:47 UTC
  • mfrom: (3354.1.1 compiz)
  • Revision ID: tarmac-20120910025747-uykqy567tqaj09mq
Revert r3353 as it was unreviewed and somehow got merged. Fixes: . Approved by Daniel van Vugt, jenkins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Compiz configuration system library
3
 
 *
4
 
 * Copyright (C) 2012 Canonical Ltd.
5
 
 *
6
 
 * This library is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU Lesser General Public
8
 
 * License as published by the Free Software Foundation; either
9
 
 * version 2.1 of the License, or (at your option) any later version.
10
 
 
11
 
 * This library is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 * Lesser General Public License for more details.
15
 
 
16
 
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with this library; if not, write to the Free Software
18
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 *
20
 
 * Authored By:
21
 
 * Sam Spilsbury <sam.spilsbury@canonical.com>
22
 
 */
23
 
#ifndef _COMPIZCONFIG_CCS_ITEM_IN_LIST_MATCHER_H
24
 
#define _COMPIZCONFIG_CCS_ITEM_IN_LIST_MATCHER_H
25
 
 
26
 
using ::testing::Matcher;
27
 
using ::testing::MatcherInterface;
28
 
using ::testing::MatchResultListener;
29
 
using ::testing::MakeMatcher;
30
 
 
31
 
template <typename I, typename L>
32
 
class ItemInCCSListMatcher :
33
 
    public ::testing::MatcherInterface <L>
34
 
{
35
 
    public:
36
 
 
37
 
        ItemInCCSListMatcher (const Matcher<I> &matcher) :
38
 
            mMatcher (matcher)
39
 
        {
40
 
        }
41
 
 
42
 
        virtual bool MatchAndExplain (L list, MatchResultListener *listener) const
43
 
        {
44
 
            L iter = list;
45
 
 
46
 
            while (iter)
47
 
            {
48
 
                const I &i = *(reinterpret_cast <I *> (iter->data));
49
 
 
50
 
                if (mMatcher.MatchAndExplain (i, listener))
51
 
                    return true;
52
 
 
53
 
                iter = iter->next;
54
 
            }
55
 
 
56
 
            return false;
57
 
        }
58
 
 
59
 
        virtual void DescribeTo (std::ostream *os) const
60
 
        {
61
 
            *os << "found in list (";
62
 
            mMatcher.DescribeTo (os);
63
 
            *os << ")";
64
 
        }
65
 
 
66
 
        virtual void DescribeNegationTo (std::ostream *os) const
67
 
        {
68
 
            *os << "not found in list (";
69
 
            mMatcher.DescribeNegationTo (os);
70
 
            *os << ")";
71
 
        }
72
 
 
73
 
    private:
74
 
 
75
 
        Matcher<I> mMatcher;
76
 
};
77
 
 
78
 
template <typename I, typename L>
79
 
Matcher<L> IsItemInCCSList (const Matcher<I> &matcher)
80
 
{
81
 
    return MakeMatcher (new ItemInCCSListMatcher <I, L> (matcher));
82
 
}
83
 
 
84
 
typedef struct _CCSString             CCSString;
85
 
typedef struct _CCSStringList *       CCSStringList;
86
 
typedef struct _CCSSettingValue       CCSSettingValue;
87
 
typedef struct _CCSSettingValueList * CCSSettingValueList;
88
 
 
89
 
/* A workaround for templates inside of macros not
90
 
 * expanding correctly */
91
 
namespace
92
 
{
93
 
    Matcher <CCSStringList>
94
 
    IsStringItemInStringCCSList (const Matcher <CCSString> &matcher)
95
 
    {
96
 
        return IsItemInCCSList <CCSString, CCSStringList> (matcher);
97
 
    }
98
 
 
99
 
    Matcher <CCSSettingValueList>
100
 
    IsSettingValueInSettingValueCCSList (const Matcher <CCSSettingValue> &matcher)
101
 
    {
102
 
        return IsItemInCCSList <CCSSettingValue, CCSSettingValueList> (matcher);
103
 
    }
104
 
}
105
 
 
106
 
#endif