Reviewed By: jberdine Differential Revision: D3669624 fbshipit-source-id: 559c66emaster
parent
d23c99a4ea
commit
e3132152cb
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
// OkPerson is the only class in the whole hierarchy that invokes removeObserver
|
||||
|
||||
@interface OkPerson : NSObject
|
||||
|
||||
@property(strong) NSNotificationCenter* nc;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OkPerson
|
||||
|
||||
- (void)boo {
|
||||
[self.nc removeObserver:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
@interface OkPerson2 : OkPerson
|
||||
|
||||
@end
|
||||
|
||||
@implementation OkPerson2
|
||||
|
||||
- (void)foo:(NSMutableDictionary*)dict {
|
||||
self.nc = [NSNotificationCenter defaultCenter];
|
||||
[self.nc addObserver:self selector:@selector(foo:) name:nil object:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
@interface OkPerson3 : OkPerson2
|
||||
|
||||
@end
|
||||
|
||||
@implementation OkPerson3
|
||||
|
||||
- (void)foo:(NSMutableDictionary*)dict {
|
||||
self.nc = [NSNotificationCenter defaultCenter];
|
||||
[self.nc addObserver:self selector:@selector(foo:) name:nil object:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
// No one in the whole hierarchy of BadPerson invokes removeObserver
|
||||
|
||||
@interface BadPerson : NSObject
|
||||
|
||||
@property(strong) NSNotificationCenter* nc;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BadPerson
|
||||
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
@interface BadPerson2 : BadPerson
|
||||
|
||||
@property(strong) NSNotificationCenter* nc;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BadPerson2
|
||||
|
||||
- (void)foo:(NSMutableDictionary*)dict {
|
||||
self.nc = [NSNotificationCenter defaultCenter];
|
||||
[self.nc addObserver:self selector:@selector(foo:) name:nil object:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
@interface BadPerson3 : BadPerson2
|
||||
|
||||
@property(strong) NSNotificationCenter* nc;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BadPerson3
|
||||
|
||||
- (void)fooRegister:(NSMutableDictionary*)dict {
|
||||
self.nc = [NSNotificationCenter defaultCenter];
|
||||
[self.nc addObserver:self selector:@selector(foo:) name:nil object:nil];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package endtoend.objc.linters;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
|
||||
|
||||
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 RegisteredObserver4 {
|
||||
|
||||
public static final String VCFile =
|
||||
"infer/tests/codetoanalyze/objc/linters/registered_observer/Person.m";
|
||||
|
||||
private static ImmutableList<String> inferCmd;
|
||||
|
||||
public static final String REGISTERED_OBSERVER = "REGISTERED_OBSERVER_BEING_DEALLOCATED";
|
||||
|
||||
@ClassRule
|
||||
public static DebuggableTemporaryFolder folder = new DebuggableTemporaryFolder();
|
||||
|
||||
@BeforeClass
|
||||
public static void runInfer() throws InterruptedException, IOException {
|
||||
inferCmd = InferRunner.createObjCInferCommandSimple(
|
||||
folder,
|
||||
VCFile,
|
||||
"cf");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void RegisteredObserverShouldBeFound()
|
||||
throws InterruptedException, IOException, InferException {
|
||||
InferResults inferResults = InferRunner.runInferObjC(inferCmd);
|
||||
assertThat(
|
||||
"Results should contain " + REGISTERED_OBSERVER,
|
||||
inferResults,
|
||||
containsOnlyLines(new int[] {80, 97})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue