diff --git a/.gitignore b/.gitignore index 67b2e6e..be84e51 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .build -.DS_Store \ No newline at end of file +.DS_Store +xcuserdata/ diff --git a/BlueSocket.xcodeproj/project.pbxproj b/BlueSocket.xcodeproj/project.pbxproj index 1724f83..e9fca2c 100644 --- a/BlueSocket.xcodeproj/project.pbxproj +++ b/BlueSocket.xcodeproj/project.pbxproj @@ -7,16 +7,13 @@ objects = { /* Begin PBXBuildFile section */ - 8C0F4BFA1C4E84CC008B2B0A /* Socket.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C0F4BF91C4E84CC008B2B0A /* Socket.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 8C0F4C051C4E8630008B2B0A /* SocketProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C0F4C021C4E8630008B2B0A /* SocketProtocols.swift */; }; - 8C0F4C061C4E8630008B2B0A /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C0F4C031C4E8630008B2B0A /* Socket.swift */; }; - 8C0F4C071C4E8630008B2B0A /* SocketUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C0F4C041C4E8630008B2B0A /* SocketUtils.swift */; }; + 595218011F61E34E001A94A2 /* SocketUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 595217FC1F61E34E001A94A2 /* SocketUtils.swift */; }; + 595218041F61E34E001A94A2 /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 595217FF1F61E34E001A94A2 /* Socket.swift */; }; + 595218051F61E34E001A94A2 /* SocketProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 595218001F61E34E001A94A2 /* SocketProtocols.swift */; }; + 5952180B1F61E84E001A94A2 /* Socket.h in Headers */ = {isa = PBXBuildFile; fileRef = 595218091F61E84E001A94A2 /* Socket.h */; settings = {ATTRIBUTES = (Public, ); }; }; 8C51FD591E7C8C8A00C2FDA6 /* BlueSocket.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 8C51FD581E7C8C8A00C2FDA6 /* BlueSocket.podspec */; }; 8C5605D21D50D60400958292 /* Socket.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8C0F4BF61C4E84CC008B2B0A /* Socket.framework */; }; 8C8540B21E9FC1DE00E41C1D /* VerifyLinuxTestCount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C8540B01E9FC14E00E41C1D /* VerifyLinuxTestCount.swift */; }; - 8CC36DF81C4EA1BE00BAA659 /* SocketProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C0F4C021C4E8630008B2B0A /* SocketProtocols.swift */; }; - 8CC36DF91C4EA1BE00BAA659 /* Socket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C0F4C031C4E8630008B2B0A /* Socket.swift */; }; - 8CC36DFA1C4EA1BE00BAA659 /* SocketUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C0F4C041C4E8630008B2B0A /* SocketUtils.swift */; }; 8CC7217B1D4BCB1D00F5FD19 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 8CC7217A1D4BCB1D00F5FD19 /* LICENSE */; }; 8CF04E291D4FCE4A00C27814 /* SocketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8CC721761D4BCA9400F5FD19 /* SocketTests.swift */; }; /* End PBXBuildFile section */ @@ -32,12 +29,12 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 595217FC1F61E34E001A94A2 /* SocketUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketUtils.swift; path = Socket/SocketUtils.swift; sourceTree = ""; }; + 595217FF1F61E34E001A94A2 /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Socket.swift; path = Socket/Socket.swift; sourceTree = ""; }; + 595218001F61E34E001A94A2 /* SocketProtocols.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SocketProtocols.swift; path = Socket/SocketProtocols.swift; sourceTree = ""; }; + 595218091F61E84E001A94A2 /* Socket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Socket.h; path = Socket/Socket.h; sourceTree = ""; }; + 5952180C1F61E8A2001A94A2 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Socket/Info.plist; sourceTree = ""; }; 8C0F4BF61C4E84CC008B2B0A /* Socket.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Socket.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 8C0F4BF91C4E84CC008B2B0A /* Socket.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Socket.h; sourceTree = ""; }; - 8C0F4BFB1C4E84CC008B2B0A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 8C0F4C021C4E8630008B2B0A /* SocketProtocols.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketProtocols.swift; sourceTree = ""; }; - 8C0F4C031C4E8630008B2B0A /* Socket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Socket.swift; sourceTree = ""; }; - 8C0F4C041C4E8630008B2B0A /* SocketUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocketUtils.swift; sourceTree = ""; }; 8C0F4C081C4E866E008B2B0A /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = ""; }; 8C51FD581E7C8C8A00C2FDA6 /* BlueSocket.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = BlueSocket.podspec; sourceTree = ""; }; 8C8540B01E9FC14E00E41C1D /* VerifyLinuxTestCount.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = VerifyLinuxTestCount.swift; path = Tests/SocketTests/VerifyLinuxTestCount.swift; sourceTree = ""; }; @@ -103,9 +100,9 @@ 8C0F4BF81C4E84CC008B2B0A /* Sources */ = { isa = PBXGroup; children = ( - 8C0F4C031C4E8630008B2B0A /* Socket.swift */, - 8C0F4C021C4E8630008B2B0A /* SocketProtocols.swift */, - 8C0F4C041C4E8630008B2B0A /* SocketUtils.swift */, + 595217FF1F61E34E001A94A2 /* Socket.swift */, + 595218001F61E34E001A94A2 /* SocketProtocols.swift */, + 595217FC1F61E34E001A94A2 /* SocketUtils.swift */, 8C0F4C011C4E85F7008B2B0A /* Supporting Files */, ); path = Sources; @@ -114,8 +111,8 @@ 8C0F4C011C4E85F7008B2B0A /* Supporting Files */ = { isa = PBXGroup; children = ( - 8C0F4BF91C4E84CC008B2B0A /* Socket.h */, - 8C0F4BFB1C4E84CC008B2B0A /* Info.plist */, + 595218091F61E84E001A94A2 /* Socket.h */, + 5952180C1F61E8A2001A94A2 /* Info.plist */, ); name = "Supporting Files"; sourceTree = ""; @@ -146,7 +143,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 8C0F4BFA1C4E84CC008B2B0A /* Socket.h in Headers */, + 5952180B1F61E84E001A94A2 /* Socket.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -287,9 +284,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8C0F4C051C4E8630008B2B0A /* SocketProtocols.swift in Sources */, - 8C0F4C061C4E8630008B2B0A /* Socket.swift in Sources */, - 8C0F4C071C4E8630008B2B0A /* SocketUtils.swift in Sources */, + 595218041F61E34E001A94A2 /* Socket.swift in Sources */, + 595218011F61E34E001A94A2 /* SocketUtils.swift in Sources */, + 595218051F61E34E001A94A2 /* SocketProtocols.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -306,9 +303,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 8CC36DF81C4EA1BE00BAA659 /* SocketProtocols.swift in Sources */, - 8CC36DF91C4EA1BE00BAA659 /* Socket.swift in Sources */, - 8CC36DFA1C4EA1BE00BAA659 /* SocketUtils.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -440,7 +434,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; - INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Sources/Socket/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; @@ -462,7 +456,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; - INFOPLIST_FILE = "$(SRCROOT)/Sources/Info.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Sources/Socket/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; diff --git a/Package.swift b/Package.swift index 2a1f4db..64ef66e 100644 --- a/Package.swift +++ b/Package.swift @@ -4,31 +4,31 @@ // // Copyright © 2016 IBM. All rights reserved. // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. // import PackageDescription #if os(Linux) || os(macOS) || os(iOS) || os(tvOS) || os(watchOS) - - let package = Package( - name: "Socket", - targets: [Target(name: "Socket")], - exclude: ["BlueSocket.xcodeproj", "BlueSocket.xcworkspace", "README.md", "Sources/Info.plist", "Sources/Socket.h"] - ) - + +let package = Package( + name: "Socket", + targets: [Target(name: "Socket")], + exclude: ["BlueSocket.xcodeproj", "BlueSocket.xcworkspace", "README.md", "Sources/Info.plist", "Sources/Socket.h"] +) + #else - - fatalError("Unsupported OS") - + +fatalError("Unsupported OS") + #endif diff --git a/Package@swift-4.swift b/Package@swift-4.swift new file mode 100644 index 0000000..d1d0a36 --- /dev/null +++ b/Package@swift-4.swift @@ -0,0 +1,51 @@ +// swift-tools-version:4.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. +// +// BlueSocket.swift +// BlueSocket +// +// Copyright © 2017 IBM. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +import PackageDescription + +#if os(Linux) || os(macOS) || os(iOS) || os(tvOS) || os(watchOS) +let package = Package( + name: "Socket", + products: [ + // Products define the executables and libraries produced by a package, and make them visible to other packages. + .library( + name: "Socket", + targets: ["Socket"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target defines a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "Socket", + dependencies: [], + exclude: ["BlueSocket.xcodeproj", "BlueSocket.xcworkspace", "README.md", "Sources/Info.plist", "Sources/Socket.h"]), + .testTarget( + name: "SocketTests", + dependencies: ["Socket"]), + ] +) +#else +fatalError("Unsupported OS") +#endif diff --git a/Sources/Info.plist b/Sources/Socket/Info.plist similarity index 100% rename from Sources/Info.plist rename to Sources/Socket/Info.plist diff --git a/Sources/Socket.h b/Sources/Socket/Socket.h similarity index 100% rename from Sources/Socket.h rename to Sources/Socket/Socket.h diff --git a/Sources/Socket.swift b/Sources/Socket/Socket.swift similarity index 100% rename from Sources/Socket.swift rename to Sources/Socket/Socket.swift diff --git a/Sources/SocketProtocols.swift b/Sources/Socket/SocketProtocols.swift similarity index 100% rename from Sources/SocketProtocols.swift rename to Sources/Socket/SocketProtocols.swift diff --git a/Sources/SocketUtils.swift b/Sources/Socket/SocketUtils.swift similarity index 100% rename from Sources/SocketUtils.swift rename to Sources/Socket/SocketUtils.swift diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift index bf4de96..2f02f20 100644 --- a/Tests/LinuxMain.swift +++ b/Tests/LinuxMain.swift @@ -20,27 +20,45 @@ import Glibc @testable import SocketTests // http://stackoverflow.com/questions/24026510/how-do-i-shuffle-an-array-in-swift -extension MutableCollection where Indices.Iterator.Element == Index { - - mutating func shuffle() { - let c = count - guard c > 1 else { return } - - srand(UInt32(time(nil))) - for (firstUnshuffled, unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) { - - let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount)) - guard d != 0 else { continue } - let i = index(firstUnshuffled, offsetBy: d) - swap(&self[firstUnshuffled], &self[i]) + +#if swift(>=4) + + extension MutableCollection { + mutating func shuffle() { + let c = count + guard c > 1 else { return } + + srand(UInt32(time(nil))) + for (firstUnshuffled, unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) { + let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount)) + guard d != 0 else { continue } + let i = index(firstUnshuffled, offsetBy: d) + swapAt(firstUnshuffled, i) + } } } -} + +#else + + extension MutableCollection where Indices.Iterator.Element == Index { + mutating func shuffle() { + let c = count + guard c > 1 else { return } + + srand(UInt32(time(nil))) + for (firstUnshuffled, unshuffledCount) in zip(indices, stride(from: c, to: 1, by: -1)) { + let d: IndexDistance = numericCast(random() % numericCast(unshuffledCount)) + guard d != 0 else { continue } + let i = index(firstUnshuffled, offsetBy: d) + swap(&self[firstUnshuffled], &self[i]) + } + } + } + +#endif extension Sequence { - func shuffled() -> [Iterator.Element] { - var result = Array(self) result.shuffle() return result @@ -48,6 +66,5 @@ extension Sequence { } XCTMain([ - - testCase(SocketTests.allTests.shuffled()), + testCase(SocketTests.allTests.shuffled()) ]) diff --git a/Tests/SocketTests/VerifyLinuxTestCount.swift b/Tests/SocketTests/VerifyLinuxTestCount.swift index bcc6486..23c5c42 100644 --- a/Tests/SocketTests/VerifyLinuxTestCount.swift +++ b/Tests/SocketTests/VerifyLinuxTestCount.swift @@ -14,16 +14,15 @@ * limitations under the License. **/ -#if os(macOS) + +#if os(macOS) && !swift(>=3.2) import XCTest - + class VerifyLinuxTestCount: XCTestCase { - func testVerifyLinuxTestCount() { var linuxCount: Int var darwinCount: Int - - // SocketTests + linuxCount = SocketTests.allTests.count darwinCount = Int(SocketTests.defaultTestSuite().testCaseCount) XCTAssertEqual(linuxCount, darwinCount, "\(darwinCount - linuxCount) tests are missing from SocketTests.allTests")