Reviewed By: cristianoc Differential Revision: D2891269 fb-gh-sync-id: 794a616 shipit-source-id: 794a616master
							parent
							
								
									208021fc7e
								
							
						
					
					
						commit
						ac7959f2df
					
				| @ -0,0 +1,87 @@ | ||||
| /* | ||||
|  * Copyright (c) 2016 - present Facebook, Inc. | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * This source code is licensed under the BSD style license found in the | ||||
|  * LICENSE file in the root directory of this source tree. An additional grant | ||||
|  * of patent rights can be found in the PATENTS file in the same directory. | ||||
|  */ | ||||
| 
 | ||||
| #import <Foundation/Foundation.h> | ||||
| 
 | ||||
| @interface Person : NSObject | ||||
| 
 | ||||
| { | ||||
|     NSString *personName; | ||||
|     int personAge; | ||||
| } | ||||
| 
 | ||||
| - (id)initWithName:(NSString *)name andAge:(int)age; | ||||
| 
 | ||||
| - (void) setAge:(int) age; | ||||
| 
 | ||||
| - (int) getAge; | ||||
| 
 | ||||
| @end | ||||
| 
 | ||||
| @implementation Person | ||||
| 
 | ||||
| - (id)initWithName:(NSString *)name andAge:(int)age{ | ||||
|     personName = name; | ||||
|     personAge = age; | ||||
|     return self; | ||||
| } | ||||
| 
 | ||||
| - (void) setAge:(int) age { | ||||
|     self->personAge = age; | ||||
| } | ||||
| 
 | ||||
| - (int) getAge { | ||||
|     return self->personAge; | ||||
| } | ||||
| 
 | ||||
| @end | ||||
| 
 | ||||
| @interface Employee : Person | ||||
| 
 | ||||
| { | ||||
|     NSString *employeeEducation; | ||||
| } | ||||
| 
 | ||||
| - (id)initWithName:(NSString *)name andAge:(int)age | ||||
|       andEducation:(NSString *)education; | ||||
| 
 | ||||
| - (void) setEmployeeEducation:(NSString*) employeeEducation; | ||||
| 
 | ||||
| @end | ||||
| 
 | ||||
| 
 | ||||
| @implementation Employee | ||||
| 
 | ||||
| - (id)initWithName:(NSString *)name andAge:(int)age | ||||
|       andEducation: (NSString *)education | ||||
| { | ||||
|     if (self = [super initWithName:name andAge:age]) { | ||||
|         employeeEducation = education; | ||||
|     } | ||||
|     int x = 1/0; | ||||
|     return self; | ||||
| } | ||||
| 
 | ||||
| - (void) setEmployeeEducation:(NSString*) employeeEducation { | ||||
|     self->employeeEducation = employeeEducation; | ||||
| } | ||||
| 
 | ||||
| @end | ||||
| 
 | ||||
| int testFields() { | ||||
|     Employee* employee = [Employee new]; | ||||
|     [employee setEmployeeEducation:@"Master"]; | ||||
|     [employee setAge:29]; | ||||
|     [employee setEmployeeEducation:@"PhD"]; | ||||
|     return [employee getAge]; | ||||
| } | ||||
| 
 | ||||
| int test() { | ||||
|     return 1/(testFields() - 29); | ||||
| } | ||||
| @ -0,0 +1,64 @@ | ||||
| /* | ||||
|  * Copyright (c) 2015 - present Facebook, Inc. | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * This source code is licensed under the BSD style license found in the | ||||
|  * LICENSE file in the root directory of this source tree. An additional grant | ||||
|  * of patent rights can be found in the PATENTS file in the same directory. | ||||
|  */ | ||||
| 
 | ||||
| package endtoend.objc; | ||||
| 
 | ||||
| import static org.hamcrest.MatcherAssert.assertThat; | ||||
| import static utils.matchers.ResultContainsExactly.containsExactly; | ||||
| 
 | ||||
| import com.google.common.collect.ImmutableList; | ||||
| 
 | ||||
| import org.junit.BeforeClass; | ||||
| import org.junit.ClassRule; | ||||
| import org.junit.Test; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| 
 | ||||
| import utils.DebuggableTemporaryFolder; | ||||
| import utils.InferException; | ||||
| import utils.InferResults; | ||||
| import utils.InferRunner; | ||||
| 
 | ||||
| public class SubtypingTest { | ||||
| 
 | ||||
|   public static final String FILE = | ||||
|       "infer/tests/codetoanalyze/objc/errors/field_superclass/SubtypingExample.m"; | ||||
| 
 | ||||
|   private static ImmutableList<String> inferCmd; | ||||
| 
 | ||||
|   public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO"; | ||||
| 
 | ||||
|   @ClassRule | ||||
|   public static DebuggableTemporaryFolder folder = | ||||
|       new DebuggableTemporaryFolder(); | ||||
| 
 | ||||
|   @BeforeClass | ||||
|   public static void runInfer() throws InterruptedException, IOException { | ||||
|     inferCmd = InferRunner.createiOSInferCommandWithMLBuckets(folder, FILE, "cf", true); | ||||
|   } | ||||
| 
 | ||||
|   @Test | ||||
|   public void whenInferRunsOnDiv0MethodsErrorIsFound() | ||||
|       throws InterruptedException, IOException, InferException { | ||||
|     InferResults inferResults = InferRunner.runInferC(inferCmd); | ||||
|     String[] procedures = { | ||||
|         "Employee_initWithName:andAge:andEducation:", | ||||
|         "test" | ||||
|     }; | ||||
|     assertThat( | ||||
|         "Results should contain the expected divide by zero", | ||||
|         inferResults, | ||||
|         containsExactly( | ||||
|             DIVIDE_BY_ZERO, | ||||
|             FILE, | ||||
|             procedures | ||||
|         ) | ||||
|     ); | ||||
|   } | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue