Skip to content

Commit afd00eb

Browse files
committed
Merge fix: file pointer not right
1 parent fef734c commit afd00eb

File tree

4 files changed

+56
-6
lines changed

4 files changed

+56
-6
lines changed

AVOS/AVOS.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@
304304
D32AA482263BF39C0044E74E /* Realtime.h in Headers */ = {isa = PBXBuildFile; fileRef = D32AA481263BF39C0044E74E /* Realtime.h */; settings = {ATTRIBUTES = (Public, ); }; };
305305
D365E42426C3D29F00148DE8 /* LCLeaderboard.h in Headers */ = {isa = PBXBuildFile; fileRef = D365E42226C3D29F00148DE8 /* LCLeaderboard.h */; settings = {ATTRIBUTES = (Public, ); }; };
306306
D365E42526C3D29F00148DE8 /* LCLeaderboard.m in Sources */ = {isa = PBXBuildFile; fileRef = D365E42326C3D29F00148DE8 /* LCLeaderboard.m */; };
307+
D33127D326CBAD6D00BBDE09 /* LCFileTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33127D226CBAD6D00BBDE09 /* LCFileTestCase.swift */; };
307308
D36A095A25BEA75000A4F312 /* IMMessageTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D36A095925BEA75000A4F312 /* IMMessageTestCase.swift */; };
308309
D39724C424A5CD3C0099A518 /* RTMBaseTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39724C324A5CD3C0099A518 /* RTMBaseTestCase.swift */; };
309310
D39724C624A852400099A518 /* IMClientTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D39724C524A852400099A518 /* IMClientTestCase.swift */; };
@@ -550,6 +551,7 @@
550551
D328B8E720FEE2200039091A /* LCIMClientInternalConversationManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LCIMClientInternalConversationManager.m; sourceTree = "<group>"; };
551552
D32AA47F263BF2F30044E74E /* Foundation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Foundation.h; sourceTree = "<group>"; };
552553
D32AA481263BF39C0044E74E /* Realtime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Realtime.h; sourceTree = "<group>"; };
554+
D33127D226CBAD6D00BBDE09 /* LCFileTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LCFileTestCase.swift; sourceTree = "<group>"; };
553555
D34C417D2483C3FD00CD2459 /* LCRTMConnection_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCRTMConnection_Internal.h; sourceTree = "<group>"; };
554556
D34EBDCC211C20FF0092A538 /* LCRouter_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCRouter_Internal.h; sourceTree = "<group>"; };
555557
D34FD72B2068CFE900B7C11B /* LCLiveQuery_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LCLiveQuery_Internal.h; sourceTree = "<group>"; };
@@ -1236,6 +1238,7 @@
12361238
D30B6B6124A0A933006ABE09 /* BaseTestCase.swift */,
12371239
D3AD74AA24BC216200D1BBEE /* LCUserTestCase.swift */,
12381240
D313717F26BBDAC200123756 /* LCQueryTestCase.swift */,
1241+
D33127D226CBAD6D00BBDE09 /* LCFileTestCase.swift */,
12391242
D39724C324A5CD3C0099A518 /* RTMBaseTestCase.swift */,
12401243
D3A397F024A5A4670087D6F8 /* RTMConnectionTestCase.swift */,
12411244
D39724C524A852400099A518 /* IMClientTestCase.swift */,
@@ -1794,6 +1797,7 @@
17941797
D313718026BBDAC200123756 /* LCQueryTestCase.swift in Sources */,
17951798
D36A095A25BEA75000A4F312 /* IMMessageTestCase.swift in Sources */,
17961799
D3AD74AB24BC216200D1BBEE /* LCUserTestCase.swift in Sources */,
1800+
D33127D326CBAD6D00BBDE09 /* LCFileTestCase.swift in Sources */,
17971801
D3A397F124A5A4670087D6F8 /* RTMConnectionTestCase.swift in Sources */,
17981802
D39724C624A852400099A518 /* IMClientTestCase.swift in Sources */,
17991803
D39724C424A5CD3C0099A518 /* RTMBaseTestCase.swift in Sources */,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// LCFileTestCase.swift
3+
// LeanCloudObjcTests
4+
//
5+
// Created by pzheng on 2021/08/17.
6+
// Copyright © 2021 LeanCloud Inc. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import LeanCloudObjc
11+
12+
class LCFileTestCase: BaseTestCase {
13+
14+
func testObjectAssociation() {
15+
let data = uuid.data(using: .utf8)!
16+
let file = LCFile(data: data)
17+
expecting { exp in
18+
file.saveInBackground { succeeded, error in
19+
XCTAssertTrue(succeeded)
20+
XCTAssertNil(error)
21+
exp.fulfill()
22+
}
23+
}
24+
25+
let fileFieldKey = "fileField"
26+
let object = LCObject()
27+
object[fileFieldKey] = file;
28+
XCTAssertTrue(object.save())
29+
30+
guard let objectId = object.objectId else {
31+
XCTFail()
32+
return
33+
}
34+
35+
let object0 = LCObject(objectId: objectId)
36+
XCTAssertTrue(object0.fetch())
37+
XCTAssertTrue(object0[fileFieldKey] is LCFile)
38+
}
39+
}

AVOS/Sources/Foundation/Object/LCObjectUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
+(NSDictionary *)dictionaryFromObjectPointer:(LCObject *)object;
4646
+(NSDictionary *)dictionaryFromGeoPoint:(LCGeoPoint *)point;
4747
+(NSDictionary *)dictionaryFromData:(NSData *)data;
48-
+(NSDictionary *)dictionaryFromFile:(LCFile *)file;
48+
+ (NSDictionary *)dictionaryFromFile:(LCFile *)file;
4949
+(NSDictionary *)dictionaryFromACL:(LCACL *)acl;
5050
+ (id)dictionaryFromObject:(id)obj;
5151
+ (id)dictionaryFromObject:(id)obj topObject:(BOOL)topObject;

AVOS/Sources/Foundation/Object/LCObjectUtils.m

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,18 @@ +(NSDictionary *)dictionaryFromData:(NSData *)data
616616
return @{@"__type": @"Bytes", @"base64":base64};
617617
}
618618

619-
+(NSDictionary *)dictionaryFromFile:(LCFile *)file
620-
{
621-
NSMutableDictionary *dic = [file rawJSONDataMutableCopy];
622-
[dic setObject:@"File" forKey:@"__type"];
623-
return dic;
619+
+ (NSDictionary *)dictionaryFromFile:(LCFile *)file {
620+
NSDictionary *dictionary;
621+
NSString *objectId = file.objectId;
622+
if (objectId && objectId.length != 0) {
623+
dictionary = @{
624+
@"id" : objectId,
625+
@"__type" : @"File",
626+
};
627+
} else {
628+
dictionary = [file rawJSONDataMutableCopy];
629+
}
630+
return dictionary;
624631
}
625632

626633
+(NSDictionary *)dictionaryFromACL:(LCACL *)acl {

0 commit comments

Comments
 (0)