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 16 from fruit_test_common import * 17 18 COMMON_DEFINITIONS = ''' 19 #include "test_common.h" 20 21 struct X1 {}; 22 struct X2 {}; 23 struct X3 {}; 24 struct X4 {}; 25 struct X5 {}; 26 struct X6 {}; 27 struct X7 {}; 28 ''' 29 30 def test_semistatic_map_hash_selection(): 31 source = ''' 32 fruit::Component<> getComponent() { 33 return fruit::createComponent() 34 .registerConstructor<X1()>() 35 .registerConstructor<X2()>() 36 .registerConstructor<X3()>() 37 .registerConstructor<X4()>() 38 .registerConstructor<X5()>() 39 .registerConstructor<X6()>() 40 .registerConstructor<X7()>(); 41 } 42 43 int main() { 44 // The component normalization generates a random hash. By looping 50 times it's very likely that we'll get at 45 // least one hash with too many collisions (and we'll generate another). 46 for (int i = 0; i < 50; i++) { 47 fruit::NormalizedComponent<> normalizedComponent(getComponent); 48 (void) normalizedComponent; 49 } 50 } 51 ''' 52 expect_success( 53 COMMON_DEFINITIONS, 54 source, 55 locals()) 56 57 if __name__== '__main__': 58 main(__file__) 59