Skip to content

Add tests for NSClassFromString and NSStringFromClass #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
EA08126B1DA80C3600651B70 /* TestNSProgressFraction.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA08126A1DA80C3600651B70 /* TestNSProgressFraction.swift */; };
EA08126C1DA810BE00651B70 /* ProgressFraction.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0812681DA71C8A00651B70 /* ProgressFraction.swift */; };
EA418C261D57257D005EAD0D /* NSKeyedArchiverHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA418C251D57257D005EAD0D /* NSKeyedArchiverHelpers.swift */; };
EA54A6FB1DB16D53009E0809 /* TestObjCRuntime.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA54A6FA1DB16D53009E0809 /* TestObjCRuntime.swift */; };
EA66F6361BEED03E00136161 /* TargetConditionals.h in Headers */ = {isa = PBXBuildFile; fileRef = EA66F6351BEED03E00136161 /* TargetConditionals.h */; settings = {ATTRIBUTES = (Public, ); }; };
EA66F6481BF1619600136161 /* NSURLTestData.plist in Resources */ = {isa = PBXBuildFile; fileRef = EA66F63B1BF1619600136161 /* NSURLTestData.plist */; };
EA66F6671BF2F2F100136161 /* CoreFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = EA66F6651BF2F2E800136161 /* CoreFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -782,6 +783,7 @@
EA313DFE1BE7F2E90060A403 /* CFURLComponents.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = CFURLComponents.c; sourceTree = "<group>"; };
EA313DFF1BE7F2E90060A403 /* CFURLComponents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFURLComponents.h; sourceTree = "<group>"; };
EA418C251D57257D005EAD0D /* NSKeyedArchiverHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSKeyedArchiverHelpers.swift; sourceTree = "<group>"; };
EA54A6FA1DB16D53009E0809 /* TestObjCRuntime.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestObjCRuntime.swift; sourceTree = "<group>"; };
EA66F6351BEED03E00136161 /* TargetConditionals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TargetConditionals.h; path = CoreFoundation/Base.subproj/SwiftRuntime/TargetConditionals.h; sourceTree = SOURCE_ROOT; };
EA66F6381BF1619600136161 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
EA66F63B1BF1619600136161 /* NSURLTestData.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = NSURLTestData.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1375,6 +1377,7 @@
5B6F17961C48631C00935030 /* TestUtils.swift */,
0383A1741D2E558A0052E5D1 /* TestNSStream.swift */,
5B1FD9E21D6D17B80080E83C /* TestNSURLSession.swift */,
EA54A6FA1DB16D53009E0809 /* TestObjCRuntime.swift */,
);
name = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -2208,6 +2211,7 @@
5B13B3331C582D4C00651CE2 /* TestNSJSONSerialization.swift in Sources */,
5B13B33C1C582D4C00651CE2 /* TestNSOrderedSet.swift in Sources */,
5B13B34A1C582D4C00651CE2 /* TestNSURL.swift in Sources */,
EA54A6FB1DB16D53009E0809 /* TestObjCRuntime.swift in Sources */,
5B13B34D1C582D4C00651CE2 /* TestNSUUID.swift in Sources */,
5B13B3281C582D4C00651CE2 /* TestNSBundle.swift in Sources */,
5B13B32A1C582D4C00651CE2 /* TestNSCharacterSet.swift in Sources */,
Expand Down
53 changes: 53 additions & 0 deletions TestFoundation/TestObjCRuntime.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//

#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
import Foundation
import XCTest
#else
import SwiftFoundation
import SwiftXCTest
#endif

class SwiftClass {
class InnerClass {}
}

struct SwfitStruct {}

enum SwiftEnum {}

class TestObjCRuntime: XCTestCase {
static var allTests: [(String, (TestObjCRuntime) -> () throws -> Void)] {
return [
("testStringFromClass", testStringFromClass),
("testClassFromString", testClassFromString),
]
}

func testStringFromClass() {
XCTAssertEqual(NSStringFromClass(NSObject.self), "NSObject")
XCTAssertEqual(NSStringFromClass(SwiftClass.self), "TestFoundation.SwiftClass")
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
XCTAssertEqual(NSStringFromClass(XCTestCase.self), "XCTest.XCTestCase");
#else
XCTAssertEqual(NSStringFromClass(XCTestCase.self), "SwiftXCTest.XCTestCase");
#endif
}

func testClassFromString() {
XCTAssertNotNil(NSClassFromString("NSObject"))
XCTAssertNotNil(NSClassFromString("TestFoundation.SwiftClass"))
XCTAssertNil(NSClassFromString("TestFoundation.SwiftClass.InnerClass"))
XCTAssertNil(NSClassFromString("SwiftClass"))
XCTAssertNil(NSClassFromString("MadeUpClassName"))
XCTAssertNil(NSClassFromString("SwiftStruct"));
XCTAssertNil(NSClassFromString("SwiftEnum"));
}
}
1 change: 1 addition & 0 deletions TestFoundation/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ XCTMain([
testCase(TestUnitConverter.allTests),
testCase(TestProgressFraction.allTests),
testCase(TestProgress.allTests),
testCase(TestObjCRuntime.allTests),
])