diff --git a/ParticleSDK.xcodeproj/project.pbxproj b/ParticleSDK.xcodeproj/project.pbxproj index e6bac65..4071820 100644 --- a/ParticleSDK.xcodeproj/project.pbxproj +++ b/ParticleSDK.xcodeproj/project.pbxproj @@ -12,9 +12,9 @@ 5069CB30215993D5000B842A /* ParticleNetwork.h in Headers */ = {isa = PBXBuildFile; fileRef = 5069CB2C215993C1000B842A /* ParticleNetwork.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5069CB4C215F3756000B842A /* ParticleNetwork.m in Sources */ = {isa = PBXBuildFile; fileRef = 5069CB2D215993C1000B842A /* ParticleNetwork.m */; }; 604F6CF16FFFB58A8C6C685C /* libPods-ParticleSDKPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1BA016110586E35DA989AB67 /* libPods-ParticleSDKPods.a */; }; + 9305F5A9239FB25F00F3620F /* ParticleCloudTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9305F5A8239FB25F00F3620F /* ParticleCloudTests.swift */; }; + 9305F5AC23A1319700F3620F /* ParticleSessionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9305F5AB23A1319700F3620F /* ParticleSessionTests.swift */; }; 930EECBB2397F7A00043D980 /* ParticleSDK.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93944D85210BAF6F00C2DC16 /* ParticleSDK.framework */; }; - 930EECC12397F7AC0043D980 /* KeychainHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9358DA3720FE2241003FF8DC /* KeychainHelperTests.m */; }; - 930EECC22397F7AC0043D980 /* ParticleErrorHelperTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 93E849B820F795A000CBEFEC /* ParticleErrorHelperTests.m */; }; 930EECEA2397FA1A0043D980 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 930EECE92397FA1A0043D980 /* AppDelegate.m */; }; 930EECED2397FA1A0043D980 /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 930EECEC2397FA1A0043D980 /* SceneDelegate.m */; }; 930EECF02397FA1A0043D980 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 930EECEF2397FA1A0043D980 /* ViewController.m */; }; @@ -42,6 +42,8 @@ 93536EB12257CFEC00A65A94 /* ParticleSimInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 93536EAE2257CFEC00A65A94 /* ParticleSimInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; 93536EB22257CFEC00A65A94 /* ParticleSimInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 93536EAE2257CFEC00A65A94 /* ParticleSimInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; 936F14C3210B986A0095A12F /* AFNetworking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93B6689C2109F90700DFF793 /* AFNetworking.framework */; }; + 937AF30923A3C1780022A60C /* KeychainHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 937AF30823A3C1780022A60C /* KeychainHelperTests.swift */; }; + 937AF30B23A3CB960022A60C /* ParticleErrorHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 937AF30A23A3CB960022A60C /* ParticleErrorHelperTests.swift */; }; 93944D6E210BAF6F00C2DC16 /* KeychainHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F9744D20EA7F2200015D9D /* KeychainHelper.m */; }; 93944D6F210BAF6F00C2DC16 /* EventSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F9744E20EA7F2200015D9D /* EventSource.m */; }; 93944D70210BAF6F00C2DC16 /* ParticleErrorHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = C810B0BB68419CEE10A16B09 /* ParticleErrorHelper.m */; }; @@ -65,6 +67,7 @@ 93B0F83F2180D17C00D8F8C0 /* ParticlePricingInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B0F83C2180D17C00D8F8C0 /* ParticlePricingInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; 93B0F8402180D17C00D8F8C0 /* ParticlePricingInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 93B0F83D2180D17C00D8F8C0 /* ParticlePricingInfo.m */; }; 93B0F8412180D17C00D8F8C0 /* ParticlePricingInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 93B0F83D2180D17C00D8F8C0 /* ParticlePricingInfo.m */; }; + 96CEC8BD9E3CA1601FACDB07 /* libPods-ParticleSDKPods-ParticleSDKTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 062CEC15EC692AF8217196DA /* libPods-ParticleSDKPods-ParticleSDKTests.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -85,10 +88,15 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 062CEC15EC692AF8217196DA /* libPods-ParticleSDKPods-ParticleSDKTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ParticleSDKPods-ParticleSDKTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 1BA016110586E35DA989AB67 /* libPods-ParticleSDKPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ParticleSDKPods.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 5069CB2C215993C1000B842A /* ParticleNetwork.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ParticleNetwork.h; path = SDK/ParticleNetwork.h; sourceTree = ""; }; 5069CB2D215993C1000B842A /* ParticleNetwork.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = ParticleNetwork.m; path = SDK/ParticleNetwork.m; sourceTree = ""; }; 703FE20FE4C4BEFB88B42F49 /* Pods-ParticleSDKPods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ParticleSDKPods.release.xcconfig"; path = "Target Support Files/Pods-ParticleSDKPods/Pods-ParticleSDKPods.release.xcconfig"; sourceTree = ""; }; + 8786FEA8D4397A4B9A515534 /* Pods-ParticleSDKPods-ParticleSDKTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ParticleSDKPods-ParticleSDKTests.release.xcconfig"; path = "Target Support Files/Pods-ParticleSDKPods-ParticleSDKTests/Pods-ParticleSDKPods-ParticleSDKTests.release.xcconfig"; sourceTree = ""; }; + 9305F5A7239FB25F00F3620F /* ParticleSDKTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ParticleSDKTests-Bridging-Header.h"; sourceTree = ""; }; + 9305F5A8239FB25F00F3620F /* ParticleCloudTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParticleCloudTests.swift; sourceTree = ""; }; + 9305F5AB23A1319700F3620F /* ParticleSessionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParticleSessionTests.swift; sourceTree = ""; }; 930EECB62397F7A00043D980 /* ParticleSDKTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ParticleSDKTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 930EECBA2397F7A00043D980 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 930EECE62397FA1A0043D980 /* ParticleSDKTestsHost.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ParticleSDKTestsHost.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -108,14 +116,14 @@ 9352CD4C210B8296005EB505 /* InfoPods.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = InfoPods.plist; path = Framework/InfoPods.plist; sourceTree = ""; }; 93536EAD2257CFEC00A65A94 /* ParticleSimInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ParticleSimInfo.m; path = SDK/ParticleSimInfo.m; sourceTree = ""; }; 93536EAE2257CFEC00A65A94 /* ParticleSimInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParticleSimInfo.h; path = SDK/ParticleSimInfo.h; sourceTree = ""; }; - 9358DA3720FE2241003FF8DC /* KeychainHelperTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KeychainHelperTests.m; sourceTree = ""; }; + 937AF30823A3C1780022A60C /* KeychainHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainHelperTests.swift; sourceTree = ""; }; + 937AF30A23A3CB960022A60C /* ParticleErrorHelperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParticleErrorHelperTests.swift; sourceTree = ""; }; 93944D85210BAF6F00C2DC16 /* ParticleSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ParticleSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 939CA80221AD906D00A5ED93 /* ParticleLogger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = ParticleLogger.h; path = Helpers/ParticleLogger.h; sourceTree = ""; }; 939CA80321AD906D00A5ED93 /* ParticleLogger.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = ParticleLogger.m; path = Helpers/ParticleLogger.m; sourceTree = ""; }; 93B0F83C2180D17C00D8F8C0 /* ParticlePricingInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParticlePricingInfo.h; path = SDK/ParticlePricingInfo.h; sourceTree = ""; }; 93B0F83D2180D17C00D8F8C0 /* ParticlePricingInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ParticlePricingInfo.m; path = SDK/ParticlePricingInfo.m; sourceTree = ""; }; 93B6689C2109F90700DFF793 /* AFNetworking.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AFNetworking.framework; path = Carthage/Build/iOS/AFNetworking.framework; sourceTree = ""; }; - 93E849B820F795A000CBEFEC /* ParticleErrorHelperTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ParticleErrorHelperTests.m; sourceTree = ""; }; 93F9743720EA7E5600015D9D /* InfoCarthage.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = InfoCarthage.plist; path = Framework/InfoCarthage.plist; sourceTree = SOURCE_ROOT; }; 93F9743820EA7E5600015D9D /* ParticleSDK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParticleSDK.h; path = Framework/ParticleSDK.h; sourceTree = SOURCE_ROOT; }; 93F9744B20EA7F2200015D9D /* EventSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EventSource.h; path = Helpers/EventSource.h; sourceTree = ""; }; @@ -123,6 +131,7 @@ 93F9744D20EA7F2200015D9D /* KeychainHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = KeychainHelper.m; path = Helpers/KeychainHelper.m; sourceTree = ""; }; 93F9744E20EA7F2200015D9D /* EventSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EventSource.m; path = Helpers/EventSource.m; sourceTree = ""; }; 93FB8ACA21134A4C00C2CB2B /* Particle-SDK.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Particle-SDK.h"; sourceTree = ""; }; + B16C42D9726BD9612468A815 /* Pods-ParticleSDKPods-ParticleSDKTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ParticleSDKPods-ParticleSDKTests.debug.xcconfig"; path = "Target Support Files/Pods-ParticleSDKPods-ParticleSDKTests/Pods-ParticleSDKPods-ParticleSDKTests.debug.xcconfig"; sourceTree = ""; }; C810B01CA34C4A6C2000B1A2 /* ParticleCloud.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParticleCloud.h; path = SDK/ParticleCloud.h; sourceTree = ""; }; C810B035D36C9EB63EF1A92F /* ParticleErrorHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ParticleErrorHelper.h; path = Helpers/ParticleErrorHelper.h; sourceTree = ""; }; C810B0BB68419CEE10A16B09 /* ParticleErrorHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ParticleErrorHelper.m; path = Helpers/ParticleErrorHelper.m; sourceTree = ""; }; @@ -142,6 +151,7 @@ buildActionMask = 2147483647; files = ( 930EECBB2397F7A00043D980 /* ParticleSDK.framework in Frameworks */, + 96CEC8BD9E3CA1601FACDB07 /* libPods-ParticleSDKPods-ParticleSDKTests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -220,11 +230,20 @@ name = Helpers; sourceTree = ""; }; + 9305F5A2239FAF4A00F3620F /* SDK */ = { + isa = PBXGroup; + children = ( + 9305F5A8239FB25F00F3620F /* ParticleCloudTests.swift */, + 9305F5AB23A1319700F3620F /* ParticleSessionTests.swift */, + ); + path = SDK; + sourceTree = ""; + }; 930EECB72397F7A00043D980 /* ParticleSDKTests */ = { isa = PBXGroup; children = ( - 9358DA3720FE2241003FF8DC /* KeychainHelperTests.m */, - 93E849B820F795A000CBEFEC /* ParticleErrorHelperTests.m */, + 930EED01239AAEB40043D980 /* Cases */, + 9305F5A7239FB25F00F3620F /* ParticleSDKTests-Bridging-Header.h */, 930EECBA2397F7A00043D980 /* Info.plist */, ); path = ParticleSDKTests; @@ -248,6 +267,24 @@ path = ParticleSDKTestsHost; sourceTree = ""; }; + 930EED01239AAEB40043D980 /* Cases */ = { + isa = PBXGroup; + children = ( + 9305F5A2239FAF4A00F3620F /* SDK */, + 930EED02239AAEBC0043D980 /* Helpers */, + ); + path = Cases; + sourceTree = ""; + }; + 930EED02239AAEBC0043D980 /* Helpers */ = { + isa = PBXGroup; + children = ( + 937AF30823A3C1780022A60C /* KeychainHelperTests.swift */, + 937AF30A23A3CB960022A60C /* ParticleErrorHelperTests.swift */, + ); + path = Helpers; + sourceTree = ""; + }; 93F9743620EA7E4300015D9D /* Supporting Files */ = { isa = PBXGroup; children = ( @@ -264,6 +301,7 @@ 93331581210BA9C800BEFAD9 /* Security.framework */, 93B6689C2109F90700DFF793 /* AFNetworking.framework */, 1BA016110586E35DA989AB67 /* libPods-ParticleSDKPods.a */, + 062CEC15EC692AF8217196DA /* libPods-ParticleSDKPods-ParticleSDKTests.a */, ); name = Frameworks; sourceTree = ""; @@ -294,8 +332,9 @@ children = ( EEA3C2FAF8A858A381A90725 /* Pods-ParticleSDKPods.debug.xcconfig */, 703FE20FE4C4BEFB88B42F49 /* Pods-ParticleSDKPods.release.xcconfig */, + B16C42D9726BD9612468A815 /* Pods-ParticleSDKPods-ParticleSDKTests.debug.xcconfig */, + 8786FEA8D4397A4B9A515534 /* Pods-ParticleSDKPods-ParticleSDKTests.release.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -347,6 +386,7 @@ isa = PBXNativeTarget; buildConfigurationList = 930EECBE2397F7A00043D980 /* Build configuration list for PBXNativeTarget "ParticleSDKTests" */; buildPhases = ( + 3CBFE42747B6E4CF7F385BE5 /* [CP] Check Pods Manifest.lock */, 930EECB22397F7A00043D980 /* Sources */, 930EECB32397F7A00043D980 /* Frameworks */, 930EECB42397F7A00043D980 /* Resources */, @@ -430,6 +470,7 @@ 930EECB52397F7A00043D980 = { CreatedOnToolsVersion = 11.2.1; DevelopmentTeam = TNJ67X9MQD; + LastSwiftMigration = 1120; ProvisioningStyle = Automatic; TestTargetID = 930EECE52397FA1A0043D980; }; @@ -505,6 +546,28 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 3CBFE42747B6E4CF7F385BE5 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-ParticleSDKPods-ParticleSDKTests-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; 422F3AEDE7A78436634CE4B1 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -549,8 +612,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 930EECC22397F7AC0043D980 /* ParticleErrorHelperTests.m in Sources */, - 930EECC12397F7AC0043D980 /* KeychainHelperTests.m in Sources */, + 937AF30B23A3CB960022A60C /* ParticleErrorHelperTests.swift in Sources */, + 937AF30923A3C1780022A60C /* KeychainHelperTests.swift in Sources */, + 9305F5AC23A1319700F3620F /* ParticleSessionTests.swift in Sources */, + 9305F5A9239FB25F00F3620F /* ParticleCloudTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -752,8 +817,10 @@ }; 930EECBF2397F7A00043D980 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = B16C42D9726BD9612468A815 /* Pods-ParticleSDKPods-ParticleSDKTests.debug.xcconfig */; buildSettings = { CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; @@ -766,6 +833,9 @@ MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = io.particle.ParticleSDKTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "ParticleSDKTests/ParticleSDKTests-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ParticleSDKTestsHost.app/ParticleSDKTestsHost"; }; @@ -773,8 +843,10 @@ }; 930EECC02397F7A00043D980 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 8786FEA8D4397A4B9A515534 /* Pods-ParticleSDKPods-ParticleSDKTests.release.xcconfig */; buildSettings = { CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_STYLE = Automatic; @@ -786,6 +858,8 @@ MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = io.particle.ParticleSDKTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OBJC_BRIDGING_HEADER = "ParticleSDKTests/ParticleSDKTests-Bridging-Header.h"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ParticleSDKTestsHost.app/ParticleSDKTestsHost"; }; diff --git a/ParticleSDK/SDK/ParticleCloud.h b/ParticleSDK/SDK/ParticleCloud.h index cf691c4..43fca94 100644 --- a/ParticleSDK/SDK/ParticleCloud.h +++ b/ParticleSDK/SDK/ParticleCloud.h @@ -23,6 +23,7 @@ #import "ParticleNetwork.h" #import "ParticlePricingInfo.h" #import "ParticleSimInfo.h" +#import "ParticleSession.h" NS_ASSUME_NONNULL_BEGIN diff --git a/ParticleSDK/SDK/ParticleSession.h b/ParticleSDK/SDK/ParticleSession.h index 872e7d3..327a73f 100644 --- a/ParticleSDK/SDK/ParticleSession.h +++ b/ParticleSDK/SDK/ParticleSession.h @@ -18,6 +18,7 @@ // limitations under the License. #import +#import "KeychainHelper.h" NS_ASSUME_NONNULL_BEGIN diff --git a/ParticleSDK/SDK/ParticleSession.m b/ParticleSDK/SDK/ParticleSession.m index 0f9a7a5..2671276 100644 --- a/ParticleSDK/SDK/ParticleSession.m +++ b/ParticleSDK/SDK/ParticleSession.m @@ -8,7 +8,6 @@ #import "ParticleSession.h" #import "ParticleCloud.h" -#import "KeychainHelper.h" NS_ASSUME_NONNULL_BEGIN diff --git a/ParticleSDKTests/Cases/Helpers/KeychainHelperTests.swift b/ParticleSDKTests/Cases/Helpers/KeychainHelperTests.swift new file mode 100644 index 0000000..562bef4 --- /dev/null +++ b/ParticleSDKTests/Cases/Helpers/KeychainHelperTests.swift @@ -0,0 +1,69 @@ +// +// KeychainHelperTests.swift +// ParticleSDKTests +// +// Created by Raimundas Sakalauskas on 13/12/2019. +// Copyright © 2019 Particle Inc. All rights reserved. +// + +import XCTest +@testable import ParticleSDK + + +class KeychainHelperTests: XCTestCase { + + var key:String! + var expectedValue:String! + var expectedValue2:String! + + override func setUp() { + key = self.randomString(withLength: 20) + expectedValue = self.randomString(withLength: 20) + expectedValue2 = self.randomString(withLength: 20) + } + + override func tearDown() { + KeychainHelper.resetKeychainValue(forKey: key) + } + + func test_keychainValueNotSet_valueIsNil(){ + XCTAssertNil(KeychainHelper.keychainValue(forKey: key)) + } + + func test_keychainValueSet_valueNotNil() { + KeychainHelper.setKeychainValue(expectedValue, forKey: key) + XCTAssertNotNil(KeychainHelper.keychainValue(forKey: key)) + } + + func test_keychainValueSet_valueIsSet() { + KeychainHelper.setKeychainValue(expectedValue, forKey: key) + XCTAssertEqual(KeychainHelper.keychainValue(forKey: key)!, expectedValue) + } + + func test_keychainValueOverwritten_valueIsSet() { + KeychainHelper.setKeychainValue(expectedValue, forKey: key) + + KeychainHelper.setKeychainValue(expectedValue2, forKey: key) + XCTAssertEqual(KeychainHelper.keychainValue(forKey: key)!, expectedValue2) + } + + func test_keychainValueReset_valueIsNil() { + KeychainHelper.setKeychainValue(expectedValue, forKey: key) + XCTAssertNotNil(KeychainHelper.keychainValue(forKey: key)) + + KeychainHelper.resetKeychainValue(forKey: key) + XCTAssertNil(KeychainHelper.keychainValue(forKey: key)) + } + + let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" + + func randomString(withLength len: Int) -> String { + var randomString = "" + + for _ in 0 ..< len { + randomString.append(letters.randomElement()!) + } + + return randomString + } +} diff --git a/ParticleSDKTests/Cases/Helpers/ParticleErrorHelperTests.swift b/ParticleSDKTests/Cases/Helpers/ParticleErrorHelperTests.swift new file mode 100644 index 0000000..c2235be --- /dev/null +++ b/ParticleSDKTests/Cases/Helpers/ParticleErrorHelperTests.swift @@ -0,0 +1,83 @@ +// +// ParticleErrorHelperTests.swift +// ParticleSDKTests +// +// Created by Raimundas Sakalauskas on 13/12/2019. +// Copyright © 2019 Particle Inc. All rights reserved. +// + +import XCTest +@testable import ParticleSDK + +class ParticleErrorHelperTests: XCTestCase { + + func test_errorDescriptionSet_PrioritizedOverError() { + let json = "{ \"error\" : \"error1\", \"error_description\": \"error2\" }" + let expectedMessage = "error2" + + let message = ParticleErrorHelper.getErrorMessage(getJSONDict(withJSONString: json)) + XCTAssertEqual(message, expectedMessage) + } + + func test_errorSet_parsedCorrectly() { + let json = "{ \"error\" : \"error1\" }" + let expectedMessage = "error1" + + let message = ParticleErrorHelper.getErrorMessage(getJSONDict(withJSONString: json)) + XCTAssertEqual(message, expectedMessage) + } + + func test_errSet_parsedCorrectly() { + let json = "{ \"err\" : \"error1\" }" + let expectedMessage = "error1" + + let message = ParticleErrorHelper.getErrorMessage(getJSONDict(withJSONString: json)) + XCTAssertEqual(message, expectedMessage) + } + + func test_infoSet_parsedCorrectly() { + let json = "{ \"info\" : \"error1\" }" + let expectedMessage = "error1" + + let message = ParticleErrorHelper.getErrorMessage(getJSONDict(withJSONString: json)) + XCTAssertEqual(message, expectedMessage) + } + + func test_multipleErrorsSet_parsedCorrectly() { + let json = "{ \"errors\" : [ \"error1\", \"error2\" ] }" + let expectedMessage = "error1\r\nerror2" + + let message = ParticleErrorHelper.getErrorMessage(getJSONDict(withJSONString: json)) + XCTAssertEqual(message, expectedMessage) + } + + func test_errorDictionarySet_parsedCorrectly() { + let json = "{ \"errors\" : [ {\"error\" : \"error1\"}, {\"error\" : \"error2\"} ] }" + let expectedMessage = "error1\r\nerror2" + + let message = ParticleErrorHelper.getErrorMessage(getJSONDict(withJSONString: json)) + XCTAssertEqual(message, expectedMessage) + } + + func test_errorAndStatusDictionarySet_parsedCorrectly() { + let json = "{ \"errors\" : [ {\"error\" : { \"status\" : \"error1\"} }, {\"error\" : { \"status\" : \"error2\"} } ] }" + let expectedMessage = "error1\r\nerror2" + + let message = ParticleErrorHelper.getErrorMessage(getJSONDict(withJSONString: json)) + XCTAssertEqual(message, expectedMessage) + } + + func test_noErrorSet_templateErrorReturned() { + let json = "{ }" + let expectedMessage = "Unknown error occurred." + + let message = ParticleErrorHelper.getErrorMessage(getJSONDict(withJSONString: json)) + XCTAssertEqual(message, expectedMessage) + } + + + func getJSONDict(withJSONString inputString: String) -> [AnyHashable: Any] { + let data = inputString.data(using: .utf8)! + return try! JSONSerialization.jsonObject(with: data, options: []) as! [AnyHashable: Any] + } +} diff --git a/ParticleSDKTests/Cases/SDK/ParticleCloudTests.swift b/ParticleSDKTests/Cases/SDK/ParticleCloudTests.swift new file mode 100644 index 0000000..4973aea --- /dev/null +++ b/ParticleSDKTests/Cases/SDK/ParticleCloudTests.swift @@ -0,0 +1,127 @@ +// +// ParticleCloudTests.swift +// ParticleSDKTests +// +// Created by Raimundas Sakalauskas on 10/12/2019. +// Copyright © 2019 Particle Inc. All rights reserved. +// + +import XCTest +@testable import ParticleSDK +import OHHTTPStubs + +class ParticleCloudTests: XCTestCase { + + private var sut: ParticleCloud! + + override func setUp() { + sut = ParticleCloud.sharedInstance() + } + + override func tearDown() { + sut = nil + OHHTTPStubs.removeAllStubs() + } + + func test_whenInitialized_baseURLNotNil() { + XCTAssertNotNil(sut.currentBaseURL) + } + + let expectedAccessToken: String = "some+access+token" + let expectedTokenType: String = "bearer" + let expectedExpiresIn: String = "6000" + let expectedRefreshToken: String = "some+refresh+token" + + let expectedClaimCode: String = "some+claim+code" + let expectedDevice1: String = "some+device+id1" + let expectedDevice2: String = "some+device+id2" + + func setupAccessTokenDict() -> Dictionary { + let string = """ + { + "token_type": "\(expectedTokenType)", + "access_token": "\(expectedAccessToken)", + "expires_in": \(expectedExpiresIn), + "refresh_token": "\(expectedRefreshToken)" + } + """ + let data = string.data(using: .utf8)! + return try! JSONSerialization.jsonObject(with: data, options : .allowFragments) as! Dictionary + } + + func setupClaimCodeDict() -> Dictionary { + let string = """ + { + "claim_code": "\(expectedClaimCode)", + "device_ids": [ + "\(expectedDevice1)", + "\(expectedDevice2)" + ] + } + """ + let data = string.data(using: .utf8)! + return try! JSONSerialization.jsonObject(with: data, options : .allowFragments) as! Dictionary + } + + func test_generateAccessToken_notNil() { + let json = setupAccessTokenDict() + stub(condition: isPath("/oauth/token")) { + _ -> OHHTTPStubsResponse in + return OHHTTPStubsResponse(jsonObject: json as Any, statusCode: 200, headers: nil) + } + + let expected = expectation(description: "Login endpoint returns request") + sut.login(withUser: "user", password: "password") { (error) in + expected.fulfill() + } + + wait(for: [expected], timeout: 1) + XCTAssertEqual(sut.accessToken, self.expectedAccessToken) + } + + + func test_generateClaimCode_notNil() { + let json = setupClaimCodeDict() + stub(condition: isPath("/v1/device_claims")) { + _ -> OHHTTPStubsResponse in + return OHHTTPStubsResponse(jsonObject: json as Any, statusCode: 200, headers: nil) + } + + let expected = expectation(description: "Generate claim code endpoint returns request") + + + var generatedClaimCode: String! + var receivedDevices: [String]! + sut.generateClaimCode { claimCode, devices, error in + generatedClaimCode = claimCode + receivedDevices = devices as? [String] + expected.fulfill() + } + wait(for: [expected], timeout: 1) + XCTAssertEqual(generatedClaimCode, self.expectedClaimCode) + } + + func test_generateClaimCode_deviceIdsAreCorrect() { + let json = setupClaimCodeDict() + stub(condition: isPath("/v1/device_claims")) { + _ -> OHHTTPStubsResponse in + return OHHTTPStubsResponse(jsonObject: json as Any, statusCode: 200, headers: nil) + } + + let expected = expectation(description: "Generate claim code endpoint returns request") + + + var generatedClaimCode: String! + var receivedDevices: [String]! + sut.generateClaimCode { claimCode, devices, error in + generatedClaimCode = claimCode + receivedDevices = devices as? [String] + expected.fulfill() + } + wait(for: [expected], timeout: 1) + XCTAssertTrue(receivedDevices.contains(self.expectedDevice1)) + XCTAssertTrue(receivedDevices.contains(self.expectedDevice2)) + } + + +} diff --git a/ParticleSDKTests/Cases/SDK/ParticleSessionTests.swift b/ParticleSDKTests/Cases/SDK/ParticleSessionTests.swift new file mode 100644 index 0000000..bd5ab4f --- /dev/null +++ b/ParticleSDKTests/Cases/SDK/ParticleSessionTests.swift @@ -0,0 +1,87 @@ +// +// ParticleSessionTests.swift +// ParticleSDKTests +// +// Created by Raimundas Sakalauskas on 11/12/2019. +// Copyright © 2019 Particle Inc. All rights reserved. +// + +import XCTest +@testable import ParticleSDK + +class ParticleSessionTests: XCTestCase { + + let expectedAccessToken: String = "some+access+token" + let expectedRefreshToken: String = "some+refresh+token" + + func setupCorrectDict() -> Dictionary { + let string = """ + { + "token_type": "bearer", + "expires_in": 6000, + "access_token": "\(expectedAccessToken)", + "refresh_token": "\(expectedRefreshToken)" + } + """ + let data = string.data(using: .utf8)! + return try! JSONSerialization.jsonObject(with: data, options : .allowFragments) as! Dictionary + } + + func test_initWithDict_sessionNotNil(){ + let dict = setupCorrectDict() + let sut = ParticleSession(newSession: dict) + + XCTAssertNotNil(sut) + } + + func test_initWithoutBearer_sessionNil() { + var dict = setupCorrectDict() + dict["token_type"] = nil + + let sut = ParticleSession(newSession: dict) + + XCTAssertNil(sut) + } + + func test_initWithoutExpiresIn_sessionNil() { + var dict = setupCorrectDict() + dict["expires_in"] = nil + + let sut = ParticleSession(newSession: dict) + + XCTAssertNil(sut) + } + + func test_initWithDict_allButUsernameValuesAreNotNil(){ + let dict = setupCorrectDict() + let sut = ParticleSession(newSession: dict) + + XCTAssertNotNil(sut?.accessToken) + XCTAssertNotNil(sut?.refreshToken) + XCTAssertNil(sut?.username) + } + + func test_initWithDict_valuesAsExpected() { + let dict = setupCorrectDict() + let sut = ParticleSession(newSession: dict) + + XCTAssertEqual(sut?.accessToken, expectedAccessToken) + XCTAssertEqual(sut?.refreshToken, expectedRefreshToken) + } + + + func test_initWithToken_sessionNotNil() { + let sut = ParticleSession(token: expectedAccessToken) + + XCTAssertNotNil(sut) + } + + func test_initWithToken_valuesAreSet(){ + let sut = ParticleSession(token: expectedAccessToken) + + XCTAssertEqual(sut?.accessToken, expectedAccessToken) + XCTAssertNil(sut?.refreshToken) + XCTAssertNil(sut?.username) + } + +} diff --git a/ParticleSDKTests/KeychainHelperTests.m b/ParticleSDKTests/KeychainHelperTests.m deleted file mode 100644 index f728b8b..0000000 --- a/ParticleSDKTests/KeychainHelperTests.m +++ /dev/null @@ -1,52 +0,0 @@ -// -// KeychainHelperTests.m -// ParticleSDKTests -// -// Created by Raimundas Sakalauskas on 17/07/2018. -// Copyright © 2018 Particle Inc. All rights reserved. -// - -#import -#import "KeychainHelper.h" - -@interface KeychainHelperTests : XCTestCase - -@end - -@implementation KeychainHelperTests - -- (void)testKeychainHelperValueCycle { - NSString *key = [self randomStringWithLength:20]; - NSString *value = [self randomStringWithLength:20]; - NSString *value2 = [self randomStringWithLength:20]; - - NSString *retrievedValue; - - XCTAssertNil([KeychainHelper keychainValueForKey:key]); - - [KeychainHelper setKeychainValue:value forKey:key]; - retrievedValue = [KeychainHelper keychainValueForKey:key]; - XCTAssertTrue([retrievedValue isEqualToString:value]); - - [KeychainHelper setKeychainValue:value2 forKey:key]; - retrievedValue = [KeychainHelper keychainValueForKey:key]; - XCTAssertTrue([retrievedValue isEqualToString:value2]); - - [KeychainHelper resetKeychainValueForKey:key]; - XCTAssertNil([KeychainHelper keychainValueForKey:key]); -} - -NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - --(NSString *) randomStringWithLength: (int) len { - - NSMutableString *randomString = [NSMutableString stringWithCapacity: len]; - - for (int i=0; i -#import "ParticleErrorHelper.h" - -@interface ParticleErrorHelperTests : XCTestCase - -@end - -@implementation ParticleErrorHelperTests - -- (void)testErrorMessage { - NSString *message; - - //error_description should be prioritized against error - //{ error: 'error1', error_description: 'error2' } - message = [ParticleErrorHelper getErrorMessage:[self getJSONDictionary: - @"{ \"error\" : \"error1\", \"error_description\": \"error2\" }"]]; - XCTAssertTrue([message isEqualToString:@"error2"]); - - //{ error: 'error1' } - message = [ParticleErrorHelper getErrorMessage:[self getJSONDictionary: - @"{ \"error\" : \"error1\" }"]]; - XCTAssertTrue([message isEqualToString:@"error1"]); - - - //{ err: 'error1' } - message = [ParticleErrorHelper getErrorMessage:[self getJSONDictionary: - @"{ \"err\" : \"error1\" }"]]; - XCTAssertTrue([message isEqualToString:@"error1"]); - - - //{ info: 'error1' } - message = [ParticleErrorHelper getErrorMessage:[self getJSONDictionary: - @"{ \"info\" : \"error1\" }"]]; - XCTAssertTrue([message isEqualToString:@"error1"]); - - - - //{ errors: ['error1', 'error2'] } - message = [ParticleErrorHelper getErrorMessage:[self getJSONDictionary: - @"{ \"errors\" : [ \"error1\", \"error2\" ] }"]]; - XCTAssertTrue([message isEqualToString:@"error1\r\nerror2"]); - - - - //{ errors: [ { error: 'error1' }, { error: 'error2' } ] } - message = [ParticleErrorHelper getErrorMessage:[self getJSONDictionary: - @"{ \"errors\" : [ {\"error\" : \"error1\"}, {\"error\" : \"error2\"} ] }"]]; - XCTAssertTrue([message isEqualToString:@"error1\r\nerror2"]); - - - - //{ errors: [ { error: { status: 'error1' } }, { error: { status: 'error2' } } ] } - message = [ParticleErrorHelper getErrorMessage:[self getJSONDictionary: - @"{ \"errors\" : [ {\"error\" : { \"status\" : \"error1\"} }, {\"error\" : { \"status\" : \"error2\"} } ] }"]]; - XCTAssertTrue([message isEqualToString:@"error1\r\nerror2"]); - - - - // { } - message = [ParticleErrorHelper getErrorMessage:[self getJSONDictionary:@"{ }"]]; - XCTAssertTrue([message isEqualToString:@"Unknown error occurred."]); -} - -- (NSDictionary *)getJSONDictionary:(NSString *)jsonString { - NSData* data = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; - return [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; -} - -@end diff --git a/ParticleSDKTests/ParticleSDKTests-Bridging-Header.h b/ParticleSDKTests/ParticleSDKTests-Bridging-Header.h new file mode 100644 index 0000000..1b2cb5d --- /dev/null +++ b/ParticleSDKTests/ParticleSDKTests-Bridging-Header.h @@ -0,0 +1,4 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + diff --git a/Podfile b/Podfile index cde3931..f497d58 100644 --- a/Podfile +++ b/Podfile @@ -5,8 +5,13 @@ platform :ios, '8.0' target 'ParticleSDKPods' do pod 'AFNetworking' + + target 'ParticleSDKTests' do + pod 'OHHTTPStubs/Swift' + end end + post_install do |pi| pi.pods_project.targets.each do |t| t.build_configurations.each do |config| diff --git a/Podfile.lock b/Podfile.lock index 5b63f4b..cb4a4ae 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -14,17 +14,34 @@ PODS: - AFNetworking/Serialization (3.2.1) - AFNetworking/UIKit (3.2.1): - AFNetworking/NSURLSession + - OHHTTPStubs/Core (8.0.0) + - OHHTTPStubs/Default (8.0.0): + - OHHTTPStubs/Core + - OHHTTPStubs/JSON + - OHHTTPStubs/NSURLSession + - OHHTTPStubs/OHPathHelpers + - OHHTTPStubs/JSON (8.0.0): + - OHHTTPStubs/Core + - OHHTTPStubs/NSURLSession (8.0.0): + - OHHTTPStubs/Core + - OHHTTPStubs/OHPathHelpers (8.0.0) + - OHHTTPStubs/Swift (8.0.0): + - OHHTTPStubs/Default DEPENDENCIES: - AFNetworking + - OHHTTPStubs/Swift SPEC REPOS: https://github.com/CocoaPods/Specs.git: - AFNetworking + trunk: + - OHHTTPStubs SPEC CHECKSUMS: AFNetworking: b6f891fdfaed196b46c7a83cf209e09697b94057 + OHHTTPStubs: 9cbce6364bec557cc3439aa6bb7514670d780881 -PODFILE CHECKSUM: c67655cfae78f0fc0cb53dc0ecacce48fd2cd907 +PODFILE CHECKSUM: aeb0467b75a043cb4733421f2b08474ffa4f9431 COCOAPODS: 1.8.4