Skip to content

Commit

Permalink
add back unit test for JSON string
Browse files Browse the repository at this point in the history
Summary: In D15005995, test for JSON string was removed, because we need to migrate util functions to Basics. This diff is to add this unit test back.

Reviewed By: KylinChang

Differential Revision: D15216498

fbshipit-source-id: b9b199bec20549b973d9469c5fcf7b5ec1dc365d
  • Loading branch information
tianqibt authored and facebook-github-bot committed May 7, 2019
1 parent 6d0b5aa commit ed024a1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
12 changes: 12 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
52D4F0D51D91A1950030B7FC /* FBSDKDeviceRequestsHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 520223F51D83C8D200CE0AB5 /* FBSDKDeviceRequestsHelper.h */; };
5D2165E122264453004952D8 /* FBSDKAppEventsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2165E022264453004952D8 /* FBSDKAppEventsTests.m */; };
5D2165F22229C6A3004952D8 /* FBSDKGraphRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D2165F12229C6A3004952D8 /* FBSDKGraphRequestTests.m */; };
5DBB0447227FEF700009E0A6 /* FBSDKBasicUtilityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DBB0446227FEF700009E0A6 /* FBSDKBasicUtilityTests.m */; };
5DEF22CF226A3E06004056C1 /* FBSDKBasicUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DEF22CE226A3E06004056C1 /* FBSDKBasicUtility.m */; };
5DEF22D0226A3E06004056C1 /* FBSDKBasicUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DEF22CE226A3E06004056C1 /* FBSDKBasicUtility.m */; };
5DEF22D1226A3E06004056C1 /* FBSDKBasicUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DEF22CE226A3E06004056C1 /* FBSDKBasicUtility.m */; };
Expand Down Expand Up @@ -897,6 +898,7 @@
52963AAB2159A16E00C7B252 /* FBSDKMeasurementEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBSDKMeasurementEvent.m; sourceTree = "<group>"; };
5D2165E022264453004952D8 /* FBSDKAppEventsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBSDKAppEventsTests.m; sourceTree = "<group>"; };
5D2165F12229C6A3004952D8 /* FBSDKGraphRequestTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBSDKGraphRequestTests.m; sourceTree = "<group>"; };
5DBB0446227FEF700009E0A6 /* FBSDKBasicUtilityTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBSDKBasicUtilityTests.m; sourceTree = "<group>"; };
5DEF22CE226A3E06004056C1 /* FBSDKBasicUtility.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBSDKBasicUtility.m; sourceTree = "<group>"; };
5DEF22E5226A3F10004056C1 /* FBSDKBasicUtility.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FBSDKBasicUtility.h; sourceTree = "<group>"; };
5F7063FA1AF733F300E42ED7 /* FBSDKAppEventsDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBSDKAppEventsDeviceInfo.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1239,6 +1241,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
5DBB0438227FEF510009E0A6 /* Basics */ = {
isa = PBXGroup;
children = (
5DBB0446227FEF700009E0A6 /* FBSDKBasicUtilityTests.m */,
);
path = Basics;
sourceTree = "<group>";
};
5DF60D07225DB6B200934A0E /* Basics */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1422,6 +1432,7 @@
893F44A41A644552001DB0B6 /* Internal */ = {
isa = PBXGroup;
children = (
5DBB0438227FEF510009E0A6 /* Basics */,
9D18A8D91A95403F00A41042 /* AppEvents */,
7E5557391A8D833800344F86 /* AppLinks */,
894C0B481A705244009137EF /* Base64 */,
Expand Down Expand Up @@ -2996,6 +3007,7 @@
C5F6EC861FA24FAF009EB258 /* FBSDKPaymentObserverTests.m in Sources */,
89C8B19C1A8D7A27009B07F5 /* FBSDKUtilityTests.m in Sources */,
C51121CC20A27EF50041DC94 /* FBSDKSampleEventBinding.m in Sources */,
5DBB0447227FEF700009E0A6 /* FBSDKBasicUtilityTests.m in Sources */,
9D3AF4661A9ED47900EEF724 /* FBSDKGraphRequestConnectionTests.m in Sources */,
C51122A020A4BCEB0041DC94 /* FBSDKApplicationDelegateTests.m in Sources */,
C51121CB20A27EF50041DC94 /* FBSDKEventBindingTests.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
//
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
// copy, modify, and distribute this software in source code or binary form for use
// in connection with the web services and APIs provided by Facebook.
//
// As with any software that integrates with the Facebook platform, your use of
// this software is subject to the Facebook Developer Principles and Policies
// [http://developers.facebook.com/policy/]. This copyright notice shall be
// included in all copies or substantial portions of the software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#import <XCTest/XCTest.h>

#import "FBSDKBasicUtility+Internal.h"
#import "FBSDKCoreKit.h"

@interface FBSDKBasicUtilityTests : XCTestCase
@end

@implementation FBSDKBasicUtilityTests

- (void)testJSONString
{
NSString *URLString = @"https://www.facebook.com";
NSURL *URL = [NSURL URLWithString:URLString];
NSDictionary<NSString *, id> *dictionary = @{
@"url": URL,
};
NSError *error;
NSString *JSONString = [FBSDKBasicUtility JSONStringForObject:dictionary error:&error invalidObjectHandler:NULL];
XCTAssertNil(error);
XCTAssertEqualObjects(JSONString, @"{\"url\":\"https:\\/\\/www.facebook.com\"}");
NSDictionary<id, id> *decoded = [FBSDKBasicUtility objectForJSONString:JSONString error:&error];
XCTAssertNil(error);
XCTAssertEqualObjects([decoded allKeys], @[@"url"]);
XCTAssertEqualObjects(decoded[@"url"], URLString);
}

@end

0 comments on commit ed024a1

Please sign in to comment.