Skip to content

Commit b5d1542

Browse files
committed
Add unit test for trimURLSpacing
* This is not testable in Swift due to type safety, making it hard to pass in NSNull * But it is very possible for this method that expects NSString to receive NSNull due to processing a payload * Therefore, a test file in OneSignalCoreTests is created in Objective-C * As tests expand, these can be moved to more specific files
1 parent 72c1437 commit b5d1542

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
3C14E39F2AFAE39B006ED053 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C14E39E2AFAE39B006ED053 /* PrivacyInfo.xcprivacy */; };
6969
3C14E3A12AFAE461006ED053 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 3C14E3A02AFAE461006ED053 /* PrivacyInfo.xcprivacy */; };
7070
3C14E3A42AFAE54C006ED053 /* OneSignalSwiftInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = DEC08AFF2947D4E900C81DA3 /* OneSignalSwiftInterface.swift */; };
71+
3C24B0EC2BD09D7A0052E771 /* OneSignalCoreObjCTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C24B0EB2BD09D7A0052E771 /* OneSignalCoreObjCTests.m */; };
7172
3C2C7DC8288F3C020020F9AE /* OSSubscriptionModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C2C7DC7288F3C020020F9AE /* OSSubscriptionModel.swift */; };
7273
3C2D8A5928B4C4E300BE41F6 /* OSDelta.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C2D8A5828B4C4E300BE41F6 /* OSDelta.swift */; };
7374
3C44673E296D099D0039A49E /* OneSignalMobileProvision.m in Sources */ = {isa = PBXBuildFile; fileRef = 912411FD1E73342200E41FD7 /* OneSignalMobileProvision.m */; };
@@ -956,6 +957,8 @@
956957
3C11518C289AF5E800565C41 /* OSModelChangedHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSModelChangedHandler.swift; sourceTree = "<group>"; };
957958
3C14E39E2AFAE39B006ED053 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
958959
3C14E3A02AFAE461006ED053 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
960+
3C24B0EA2BD09D790052E771 /* OneSignalCoreTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "OneSignalCoreTests-Bridging-Header.h"; sourceTree = "<group>"; };
961+
3C24B0EB2BD09D7A0052E771 /* OneSignalCoreObjCTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalCoreObjCTests.m; sourceTree = "<group>"; };
959962
3C2C7DC2288E007E0020F9AE /* UnitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UnitTests-Bridging-Header.h"; sourceTree = "<group>"; };
960963
3C2C7DC7288F3C020020F9AE /* OSSubscriptionModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSSubscriptionModel.swift; sourceTree = "<group>"; };
961964
3C2D8A5828B4C4E300BE41F6 /* OSDelta.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSDelta.swift; sourceTree = "<group>"; };
@@ -1720,6 +1723,8 @@
17201723
isa = PBXGroup;
17211724
children = (
17221725
3CC063A62B6D7A8E002BB07F /* OneSignalCoreTests.swift */,
1726+
3C24B0EB2BD09D7A0052E771 /* OneSignalCoreObjCTests.m */,
1727+
3C24B0EA2BD09D790052E771 /* OneSignalCoreTests-Bridging-Header.h */,
17231728
);
17241729
path = OneSignalCoreTests;
17251730
sourceTree = "<group>";
@@ -3015,6 +3020,7 @@
30153020
3CC063A02B6D7A8D002BB07F = {
30163021
CreatedOnToolsVersion = 15.2;
30173022
DevelopmentTeam = 99SW8E36CT;
3023+
LastSwiftMigration = 1520;
30183024
ProvisioningStyle = Automatic;
30193025
TestTargetID = DEF5CCF02539321A0003E9CC;
30203026
};
@@ -3358,6 +3364,7 @@
33583364
buildActionMask = 2147483647;
33593365
files = (
33603366
3CC063A72B6D7A8E002BB07F /* OneSignalCoreTests.swift in Sources */,
3367+
3C24B0EC2BD09D7A0052E771 /* OneSignalCoreObjCTests.m in Sources */,
33613368
);
33623369
runOnlyForDeploymentPostprocessing = 0;
33633370
};
@@ -4245,6 +4252,7 @@
42454252
PRODUCT_NAME = "$(TARGET_NAME)";
42464253
SWIFT_COMPILATION_MODE = wholemodule;
42474254
SWIFT_EMIT_LOC_STRINGS = NO;
4255+
SWIFT_OBJC_BRIDGING_HEADER = "OneSignalCoreTests/OneSignalCoreTests-Bridging-Header.h";
42484256
SWIFT_VERSION = 5.0;
42494257
TARGETED_DEVICE_FAMILY = "1,2";
42504258
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/UnitTestApp";
@@ -4299,6 +4307,7 @@
42994307
PRODUCT_NAME = "$(TARGET_NAME)";
43004308
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
43014309
SWIFT_EMIT_LOC_STRINGS = NO;
4310+
SWIFT_OBJC_BRIDGING_HEADER = "OneSignalCoreTests/OneSignalCoreTests-Bridging-Header.h";
43024311
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
43034312
SWIFT_VERSION = 5.0;
43044313
TARGETED_DEVICE_FAMILY = "1,2";
@@ -4348,6 +4357,7 @@
43484357
PRODUCT_NAME = "$(TARGET_NAME)";
43494358
SWIFT_COMPILATION_MODE = wholemodule;
43504359
SWIFT_EMIT_LOC_STRINGS = NO;
4360+
SWIFT_OBJC_BRIDGING_HEADER = "OneSignalCoreTests/OneSignalCoreTests-Bridging-Header.h";
43514361
SWIFT_VERSION = 5.0;
43524362
TARGETED_DEVICE_FAMILY = "1,2";
43534363
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/UnitTestApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/UnitTestApp";
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Modified MIT License
3+
4+
Copyright 2024 OneSignal
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
1. The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
2. All copies of substantial portions of the Software may only be used in connection
17+
18+
with services provided by OneSignal.
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
*/
27+
28+
#import <XCTest/XCTest.h>
29+
#import <OneSignalCore/OneSignalCore.h>
30+
31+
@interface OneSignalCoreObjCTests : XCTestCase
32+
33+
@end
34+
35+
@implementation OneSignalCoreObjCTests
36+
37+
- (void)setUp {
38+
}
39+
40+
- (void)tearDown {
41+
}
42+
43+
// See https://github.com/OneSignal/OneSignal-iOS-SDK/issues/1400
44+
- (void)testOneSignalCoreHelper_trimURLSpacing_handlesNullishValues {
45+
NSString *nsNullResult = [OneSignalCoreHelper trimURLSpacing:[NSNull null]];
46+
XCTAssertNil(nsNullResult);
47+
48+
NSString *nilResult = [OneSignalCoreHelper trimURLSpacing:nil];
49+
XCTAssertNil(nilResult);
50+
51+
NSString *stringResult = [OneSignalCoreHelper trimURLSpacing:@" test "];
52+
XCTAssertEqualObjects(@"test", stringResult);
53+
}
54+
55+
@end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//
4+

0 commit comments

Comments
 (0)