Skip to content

Commit

Permalink
Add some tests, fix some tests
Browse files Browse the repository at this point in the history
- Test safeClassNameForObject:
- Test safeObject:respondsToSelector:
- Fix testAssumptionsAboutClasses: which was incorrectly written
  • Loading branch information
NSExceptional committed Dec 31, 2020
1 parent c7850df commit 3b5e095
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 6 deletions.
28 changes: 23 additions & 5 deletions FLEX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
C36B096623E0D4A1008F5D47 /* UIMenu+FLEX.m in Sources */ = {isa = PBXBuildFile; fileRef = C36B096423E0D4A1008F5D47 /* UIMenu+FLEX.m */; };
C36B097023E1EDCD008F5D47 /* FLEXTableViewSection.h in Headers */ = {isa = PBXBuildFile; fileRef = C36B096E23E1EDCD008F5D47 /* FLEXTableViewSection.h */; settings = {ATTRIBUTES = (Public, ); }; };
C36B097123E1EDCD008F5D47 /* FLEXTableViewSection.m in Sources */ = {isa = PBXBuildFile; fileRef = C36B096F23E1EDCD008F5D47 /* FLEXTableViewSection.m */; };
C36E1B26259D64CC00FEFEF6 /* FLEXNewRootClass.m in Sources */ = {isa = PBXBuildFile; fileRef = C36E1B25259D64CC00FEFEF6 /* FLEXNewRootClass.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
C36FBFCB230F3B98008D95D5 /* FLEXMirror.m in Sources */ = {isa = PBXBuildFile; fileRef = C36FBFB9230F3B97008D95D5 /* FLEXMirror.m */; };
C36FBFCC230F3B98008D95D5 /* FLEXProtocolBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = C36FBFBA230F3B97008D95D5 /* FLEXProtocolBuilder.h */; settings = {ATTRIBUTES = (Public, ); }; };
C36FBFCD230F3B98008D95D5 /* FLEXMethod.m in Sources */ = {isa = PBXBuildFile; fileRef = C36FBFBB230F3B97008D95D5 /* FLEXMethod.m */; };
Expand Down Expand Up @@ -567,6 +568,8 @@
C36B096423E0D4A1008F5D47 /* UIMenu+FLEX.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UIMenu+FLEX.m"; sourceTree = "<group>"; };
C36B096E23E1EDCD008F5D47 /* FLEXTableViewSection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEXTableViewSection.h; sourceTree = "<group>"; };
C36B096F23E1EDCD008F5D47 /* FLEXTableViewSection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXTableViewSection.m; sourceTree = "<group>"; };
C36E1B24259D64CC00FEFEF6 /* FLEXNewRootClass.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FLEXNewRootClass.h; sourceTree = "<group>"; };
C36E1B25259D64CC00FEFEF6 /* FLEXNewRootClass.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FLEXNewRootClass.m; sourceTree = "<group>"; };
C36FBFB9230F3B97008D95D5 /* FLEXMirror.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXMirror.m; sourceTree = "<group>"; };
C36FBFBA230F3B97008D95D5 /* FLEXProtocolBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXProtocolBuilder.h; sourceTree = "<group>"; };
C36FBFBB230F3B97008D95D5 /* FLEXMethod.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXMethod.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -738,6 +741,7 @@
1C27A8B81F0E5A0400F0D02D /* FLEXTestsMethodsList.m */,
C3854DEF23F36C1700FCD1E2 /* FLEXTypeEncodingParserTests.m */,
1C27A8BA1F0E5A0400F0D02D /* Info.plist */,
C36E1B27259D64D300FEFEF6 /* Supporting Files */,
);
path = FLEXTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -1180,6 +1184,15 @@
path = Cells;
sourceTree = "<group>";
};
C36E1B27259D64D300FEFEF6 /* Supporting Files */ = {
isa = PBXGroup;
children = (
C36E1B24259D64CC00FEFEF6 /* FLEXNewRootClass.h */,
C36E1B25259D64CC00FEFEF6 /* FLEXNewRootClass.m */,
);
path = "Supporting Files";
sourceTree = "<group>";
};
C36FBFB8230F3B52008D95D5 /* Runtime */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1658,7 +1671,7 @@
3A4C941E1B5B20570088C3F2 = {
CreatedOnToolsVersion = 6.4;
LastSwiftMigration = 1130;
ProvisioningStyle = Manual;
ProvisioningStyle = Automatic;
};
};
};
Expand Down Expand Up @@ -1704,6 +1717,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C36E1B26259D64CC00FEFEF6 /* FLEXNewRootClass.m in Sources */,
C33C825B23159EAF00DD2451 /* FLEXTests.m in Sources */,
1C27A8B91F0E5A0400F0D02D /* FLEXTestsMethodsList.m in Sources */,
C3854DF023F36C1700FCD1E2 /* FLEXTypeEncodingParserTests.m in Sources */,
Expand Down Expand Up @@ -2047,9 +2061,10 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = NO;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO;
CLANG_WARN_STRICT_PROTOTYPES = NO;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CODE_SIGN_STYLE = Manual;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -2066,6 +2081,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.flipboard.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -2080,9 +2096,10 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = NO;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO;
CLANG_WARN_STRICT_PROTOTYPES = NO;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
CODE_SIGN_STYLE = Manual;
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -2099,6 +2116,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "com.flipboard.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 5.0;
WARNING_CFLAGS = "-Wno-unsupported-availability-guard";
Expand Down
21 changes: 20 additions & 1 deletion FLEXTests/FLEXTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#import "FLEXPropertyAttributes.h"
#import "FLEXProperty.h"
#import "FLEXUtility.h"
#import "FLEXRuntimeUtility.h"
#import "FLEXMethod.h"
#import "FLEXIvar.h"
#import "FLEXNewRootClass.h"

@interface Subclass : NSObject {
@public
Expand All @@ -39,6 +41,7 @@ - (void)testRuntimeAdditions {
- (void)testAssumptionsAboutClasses {
Class cls = [self class];
Class meta = objc_getMetaClass(NSStringFromClass(cls).UTF8String);
Class rootMeta = object_getClass(meta);

// Subsequent `class` calls yield self
XCTAssertEqual(cls, [cls class]);
Expand All @@ -50,7 +53,7 @@ - (void)testAssumptionsAboutClasses {

// Subsequent object_getClass calls yield metaclass
XCTAssertEqual(object_getClass(cls), meta);
XCTAssertEqual(object_getClass(meta), meta);
XCTAssertEqual(object_getClass(object_getClass(meta)), rootMeta);

// Superclass of a root class is nil
XCTAssertNil(NSObject.superclass);
Expand Down Expand Up @@ -121,4 +124,20 @@ - (void)testIvarUnboxing {
XCTAssertEqual(pointerValue[0], 0xaa);
}

- (void)testSafeRespondsToSelector {
XCTAssertFalse([FLEXRuntimeUtility
safeObject:[NSObject class] respondsToSelector:@selector(testSafeRespondsToSelector)
]);

Class root = NSClassFromString(@"FLEXNewRootClass");
XCTAssertTrue([FLEXRuntimeUtility safeObject:root respondsToSelector:@selector(theOnlyMethod)]);
XCTAssertFalse([FLEXRuntimeUtility safeObject:root respondsToSelector:@selector(class)]);
}

- (void)testSafeGetClassName {
id instance = [NSClassFromString(@"FLEXNewRootClass") alloc];
NSString *className = [FLEXRuntimeUtility safeClassNameForObject:instance];
XCTAssertEqualObjects(@"FLEXNewRootClass", className);
}

@end
19 changes: 19 additions & 0 deletions FLEXTests/Supporting Files/FLEXNewRootClass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// FLEXNewRootClass.h
// FLEXTests
//
// Created by Tanner on 12/30/20.
// Copyright © 2020 Flipboard. All rights reserved.
//

#import <Foundation/Foundation.h>

/// Root class with one method
OBJC_ROOT_CLASS
@interface FLEXNewRootClass {
Class isa OBJC_ISA_AVAILABILITY;
}

- (void)theOnlyMethod;

@end
25 changes: 25 additions & 0 deletions FLEXTests/Supporting Files/FLEXNewRootClass.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// FLEXNewRootClass.m
// FLEXTests
//
// Created by Tanner on 12/30/20.
// Copyright © 2020 Flipboard. All rights reserved.
//

#import "FLEXNewRootClass.h"
#import <objc/runtime.h>

@implementation FLEXNewRootClass

+ (id)alloc {
FLEXNewRootClass *obj = (__bridge id)calloc(1, class_getInstanceSize(self));
object_setClass(obj, self);
return obj;
}

- (void)theOnlyMethod { }

- (void)retain { }
- (void)release { }

@end

0 comments on commit 3b5e095

Please sign in to comment.