Summary:public We model it as the builtin __instanceof which models the instanceof construct of Java. The behaviour is the same. Reviewed By: jvillard Differential Revision: D2938969 fb-gh-sync-id: 2258de3 shipit-source-id: 2258de3master
parent
efd3aeccc6
commit
7721743f46
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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/NSObject.h>
|
||||
|
||||
|
||||
@interface Base : NSObject
|
||||
|
||||
+(int) returnsZero1: (Base*) b;
|
||||
|
||||
@end
|
||||
|
||||
@implementation Base
|
||||
|
||||
+(int) returnsZero1: (Base*) b {
|
||||
if ([b isKindOfClass:[self class]]) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface Derived : Base
|
||||
|
||||
@end
|
||||
|
||||
@implementation Derived
|
||||
|
||||
@end
|
||||
|
||||
int returnsZero2(Base* b) {
|
||||
if ([b isKindOfClass:[Derived class]]) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int shouldThrowDivideByZero1() {
|
||||
Base* base = [[Base alloc] init];
|
||||
return 1/[Base returnsZero1:base];
|
||||
}
|
||||
|
||||
int shouldThrowDivideByZero2() {
|
||||
Base* base = [[Base alloc] init];
|
||||
return 1/returnsZero2(base);
|
||||
}
|
||||
|
||||
int shouldThrowDivideByZero3() {
|
||||
Base* b = [[Derived alloc] init];
|
||||
if ([b isKindOfClass:[Derived class]]) {
|
||||
return 1/0;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2013 - 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.ResultContainsErrorInMethod.contains;
|
||||
import static utils.matchers.ResultContainsExactly.containsExactly;
|
||||
import static utils.matchers.ResultContainsNoErrorInMethod.doesNotContain;
|
||||
|
||||
|
||||
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 KindOfClassTest {
|
||||
|
||||
public static final String FILE =
|
||||
"infer/tests/codetoanalyze/objc/errors/subtyping/KindOfClassExample.m";
|
||||
|
||||
public static final String DIVIDE_BY_ZERO = "DIVIDE_BY_ZERO";
|
||||
|
||||
private static ImmutableList<String> inferCmd;
|
||||
|
||||
@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 nullDereferenceTest() throws InterruptedException, IOException, InferException {
|
||||
InferResults inferResults = InferRunner.runInferC(inferCmd);
|
||||
String[] procedures = {
|
||||
"shouldThrowDivideByZero1",
|
||||
"shouldThrowDivideByZero2",
|
||||
"shouldThrowDivideByZero3"
|
||||
};
|
||||
assertThat(
|
||||
"Results should contain divide by zero",
|
||||
inferResults,
|
||||
containsExactly(
|
||||
DIVIDE_BY_ZERO,
|
||||
FILE,
|
||||
procedures
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue