Skip to content

Commit 3656a37

Browse files
committed
Merge branch 'pr/121'
2 parents 7a1893a + 7aec76e commit 3656a37

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ extern Boolean _CFURLInitAbsoluteURLWithBytes(CFURLRef url, const UInt8 *relativ
218218
extern CFHashCode CFHashBytes(uint8_t *bytes, CFIndex length);
219219
extern CFIndex __CFProcessorCount();
220220
extern uint64_t __CFMemorySize();
221+
extern CFStringRef _CFProcessNameString(void);
221222
extern CFIndex __CFActiveProcessorCount();
222223
extern CFDictionaryRef __CFGetEnvironment();
223224
extern int32_t __CFGetPid();

Foundation.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
22B9C1E11C165D7A00DECFF9 /* TestNSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */; };
11+
400E22651C1A4E58007C5933 /* TestNSProcessInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 400E22641C1A4E58007C5933 /* TestNSProcessInfo.swift */; };
1112
4AE109271C17CCBF007367B5 /* TestNSIndexPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AE109261C17CCBF007367B5 /* TestNSIndexPath.swift */; };
1213
4DC1D0801C12EEEF00B5948A /* TestNSPipe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DC1D07F1C12EEEF00B5948A /* TestNSPipe.swift */; };
1314
525AECED1BF2C9C500D15BB0 /* TestNSFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525AECEB1BF2C96400D15BB0 /* TestNSFileManager.swift */; };
@@ -332,6 +333,7 @@
332333

333334
/* Begin PBXFileReference section */
334335
22B9C1E01C165D7A00DECFF9 /* TestNSDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSDate.swift; sourceTree = "<group>"; };
336+
400E22641C1A4E58007C5933 /* TestNSProcessInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSProcessInfo.swift; sourceTree = "<group>"; };
335337
4AE109261C17CCBF007367B5 /* TestNSIndexPath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSIndexPath.swift; sourceTree = "<group>"; };
336338
4DC1D07F1C12EEEF00B5948A /* TestNSPipe.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestNSPipe.swift; sourceTree = "<group>"; };
337339
522C253A1BF16E1600804FC6 /* FoundationErrors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FoundationErrors.swift; sourceTree = "<group>"; };
@@ -1054,6 +1056,7 @@
10541056
5EB6A15C1C188FC40037DCB8 /* TestNSJSONSerialization.swift */,
10551057
EA66F63F1BF1619600136161 /* TestNSNumber.swift */,
10561058
4DC1D07F1C12EEEF00B5948A /* TestNSPipe.swift */,
1059+
400E22641C1A4E58007C5933 /* TestNSProcessInfo.swift */,
10571060
EA66F6401BF1619600136161 /* TestNSPropertyList.swift */,
10581061
E876A73D1C1180E000F279EC /* TestNSRange.swift */,
10591062
EA66F6411BF1619600136161 /* TestNSSet.swift */,
@@ -1759,6 +1762,7 @@
17591762
isa = PBXSourcesBuildPhase;
17601763
buildActionMask = 2147483647;
17611764
files = (
1765+
400E22651C1A4E58007C5933 /* TestNSProcessInfo.swift in Sources */,
17621766
525AECED1BF2C9C500D15BB0 /* TestNSFileManager.swift in Sources */,
17631767
5B915F0F1C1A320E00BE40C5 /* TestNSJSONSerialization.swift in Sources */,
17641768
EA66F6501BF1619600136161 /* TestNSNumber.swift in Sources */,

Foundation/NSProcessInfo.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,7 @@ public class NSProcessInfo : NSObject {
7272
}
7373
}
7474

75-
public var processName: String {
76-
get {
77-
NSUnimplemented()
78-
}
79-
set {
80-
NSUnimplemented()
81-
}
82-
}
75+
public var processName: String = _CFProcessNameString()._swiftObject
8376

8477
public var processIdentifier: Int32 {
8578
get {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This source file is part of the Swift.org open source project
2+
//
3+
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
4+
// Licensed under Apache License v2.0 with Runtime Library Exception
5+
//
6+
// See http://swift.org/LICENSE.txt for license information
7+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
//
9+
10+
11+
#if DEPLOYMENT_RUNTIME_OBJC || os(Linux)
12+
import Foundation
13+
import XCTest
14+
#else
15+
import SwiftFoundation
16+
import SwiftXCTest
17+
#endif
18+
19+
20+
class TestNSProcessInfo : XCTestCase {
21+
22+
var allTests : [(String, () -> ())] {
23+
return [
24+
("test_processName", test_processName ),
25+
]
26+
}
27+
28+
func test_processName() {
29+
// Assert that the original process name is "TestFoundation". This test
30+
// will fail if the test target ever gets renamed, so maybe it should
31+
// just test that the initial name is not empty or something?
32+
let processInfo = NSProcessInfo.processInfo()
33+
let targetName = "TestFoundation"
34+
let originalProcessName = processInfo.processName
35+
XCTAssertEqual(originalProcessName, targetName, "\"\(originalProcessName)\" not equal to \"TestFoundation\"")
36+
37+
// Try assigning a new process name.
38+
let newProcessName = "TestProcessName"
39+
processInfo.processName = newProcessName
40+
XCTAssertEqual(processInfo.processName, newProcessName, "\"\(processInfo.processName)\" not equal to \"\(newProcessName)\"")
41+
42+
// Assign back to the original process name.
43+
processInfo.processName = originalProcessName
44+
XCTAssertEqual(processInfo.processName, originalProcessName, "\"\(processInfo.processName)\" not equal to \"\(originalProcessName)\"")
45+
}
46+
}

TestFoundation/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ XCTMain([
3939
TestNSNotificationCenter(),
4040
TestNSNumber(),
4141
TestNSPipe(),
42+
TestNSProcessInfo(),
4243
TestNSPropertyList(),
4344
TestNSRange(),
4445
TestNSScanner(),

0 commit comments

Comments
 (0)