• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#  Copyright 2016 Google Inc. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS-IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from fruit_test_common import *
17
18COMMON_DEFINITIONS = '''
19    #define IN_FRUIT_CPP_FILE 1
20
21    #include "meta/common.h"
22    #include <fruit/impl/meta/component.h>
23
24    struct A1 {};
25    struct B1 {};
26
27    using A = Type<A1>;
28    using B = Type<B1>;
29
30    using AssistedA = Type<Assisted<A1>>;
31    using AssistedB = Type<Assisted<B1>>;
32    '''
33
34def test_NumAssisted():
35    source = '''
36        int main() {
37          AssertSame(Int<0>, NumAssisted(Vector<>));
38          AssertSame(Int<0>, NumAssisted(Vector<A>));
39          AssertSame(Int<1>, NumAssisted(Vector<AssistedA>));
40          AssertSame(Int<0>, NumAssisted(Vector<A, B>));
41          AssertSame(Int<1>, NumAssisted(Vector<AssistedA, B>));
42          AssertSame(Int<1>, NumAssisted(Vector<A, AssistedB>));
43          AssertSame(Int<2>, NumAssisted(Vector<AssistedA, AssistedB>));
44        }
45        '''
46    expect_success(
47        COMMON_DEFINITIONS,
48        source,
49        locals())
50
51def test_NumAssistedBefore():
52    source = '''
53        int main() {
54          AssertSame(Int<0>, NumAssistedBefore(Int<0>, Vector<>));
55
56          AssertSame(Int<0>, NumAssistedBefore(Int<0>, Vector<A>));
57          AssertSame(Int<0>, NumAssistedBefore(Int<1>, Vector<A>));
58
59          AssertSame(Int<0>, NumAssistedBefore(Int<0>, Vector<AssistedA>));
60          AssertSame(Int<1>, NumAssistedBefore(Int<1>, Vector<AssistedA>));
61
62          AssertSame(Int<0>, NumAssistedBefore(Int<0>, Vector<A, B>));
63          AssertSame(Int<0>, NumAssistedBefore(Int<1>, Vector<A, B>));
64          AssertSame(Int<0>, NumAssistedBefore(Int<2>, Vector<A, B>));
65
66          AssertSame(Int<0>, NumAssistedBefore(Int<0>, Vector<AssistedA, B>));
67          AssertSame(Int<1>, NumAssistedBefore(Int<1>, Vector<AssistedA, B>));
68          AssertSame(Int<1>, NumAssistedBefore(Int<2>, Vector<AssistedA, B>));
69
70          AssertSame(Int<0>, NumAssistedBefore(Int<0>, Vector<A, AssistedB>));
71          AssertSame(Int<0>, NumAssistedBefore(Int<1>, Vector<A, AssistedB>));
72          AssertSame(Int<1>, NumAssistedBefore(Int<2>, Vector<A, AssistedB>));
73
74          AssertSame(Int<0>, NumAssistedBefore(Int<0>, Vector<AssistedA, AssistedB>));
75          AssertSame(Int<1>, NumAssistedBefore(Int<1>, Vector<AssistedA, AssistedB>));
76          AssertSame(Int<2>, NumAssistedBefore(Int<2>, Vector<AssistedA, AssistedB>));
77        }
78        '''
79    expect_success(
80        COMMON_DEFINITIONS,
81        source,
82        locals())
83
84if __name__== '__main__':
85    main(__file__)
86