Skip to content

Commit 6ac6728

Browse files
committed
chore: Added tests for array property pointers
1 parent a91e316 commit 6ac6728

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
#import <Foundation/Foundation.h>
3+
4+
typedef struct TNSPoint {
5+
int x;
6+
int y;
7+
} TNSPoint;
8+
9+
@interface TNSPointCollection : NSObject
10+
- (instancetype)initWithPoints:(const TNSPoint *)points count:(NSUInteger)count;
11+
@property (nonatomic, readonly) TNSPoint *points NS_RETURNS_INNER_POINTER;
12+
@property (nonatomic, readonly) NSUInteger pointCount;
13+
@end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#import "TNSPointCollection.h"
2+
3+
NS_ASSUME_NONNULL_BEGIN
4+
5+
@implementation TNSPointCollection
6+
{
7+
TNSPoint *_points;
8+
NSUInteger _pointCount;
9+
}
10+
11+
- (instancetype)initWithPoints:(const TNSPoint *)points count:(NSUInteger)count
12+
{
13+
self = [super init];
14+
if (self)
15+
{
16+
_pointCount = count;
17+
if (count > 0)
18+
{
19+
_points = malloc(sizeof(TNSPoint) * count);
20+
memcpy(_points, points, sizeof(TNSPoint) * count);
21+
}
22+
else
23+
{
24+
_points = NULL;
25+
}
26+
}
27+
return self;
28+
}
29+
30+
- (NSUInteger)pointCount
31+
{
32+
return _pointCount;
33+
}
34+
35+
- (TNSPoint *)points
36+
{
37+
return _points;
38+
}
39+
40+
@end
41+
42+
NS_ASSUME_NONNULL_END

TestFixtures/TestFixtures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import "Interfaces/TNSConstructorResolution.h"
1515
#import "Interfaces/TNSInheritance.h"
1616
#import "Interfaces/TNSMethodCalls.h"
17+
#import "Interfaces/TNSPointCollection.h"
1718
#import "Interfaces/TNSSwiftLike.h"
1819

1920
#import "Marshalling/TNSAllocLog.h"

TestRunner/app/tests/Marshalling/ReferenceTests.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,62 @@ describe(module.id, function () {
397397
interop.free(ptr);
398398
});
399399

400+
it("Reference access indexed values from pointer array property", function () {
401+
const structs = [
402+
new TNSPoint({x: 1, y: 2}),
403+
new TNSPoint({x: 3, y: 4}),
404+
new TNSPoint({x: 5, y: 6})
405+
];
406+
const length = structs.length;
407+
const ptr = interop.alloc(interop.sizeof(TNSPoint) * length);
408+
409+
const ref = new interop.Reference(TNSPoint, ptr);
410+
for (let i = 0; i < length; i++) {
411+
ref[i] = structs[i];
412+
}
413+
414+
const pointCollection = TNSPointCollection.alloc().initWithPointsCount(ptr, length);
415+
416+
// Runtime converts pointers into references for cases with type so use handleof to get pointer
417+
const pointsPtr = interop.handleof(pointCollection.points);
418+
419+
// Check if values were retrieved from pointer
420+
const resultRef = new interop.Reference(TNSPoint, pointsPtr);
421+
for (let i = 0; i < length; i++) {
422+
expect(TNSPoint.equals(resultRef[i], structs[i])).toBe(true);
423+
}
424+
425+
interop.free(ptr);
426+
interop.free(pointsPtr);
427+
});
428+
429+
it("Reference access value from pointer array property", function () {
430+
const structs = [
431+
new TNSPoint({x: 1, y: 2}),
432+
new TNSPoint({x: 3, y: 4}),
433+
new TNSPoint({x: 5, y: 6})
434+
];
435+
const length = structs.length;
436+
const ptr = interop.alloc(interop.sizeof(TNSPoint) * length);
437+
438+
const ref = new interop.Reference(TNSPoint, ptr);
439+
for (let i = 0; i < length; i++) {
440+
ref[i] = structs[i];
441+
}
442+
443+
const pointCollection = TNSPointCollection.alloc().initWithPointsCount(ptr, length);
444+
445+
// Runtime converts pointers into references for cases with type so use handleof to get pointer
446+
const pointsPtr = interop.handleof(pointCollection.points);
447+
448+
// Check if values were retrieved from pointer
449+
const resultRef = new interop.Reference(TNSPoint, pointsPtr);
450+
expect(TNSPoint.equals(resultRef.value, structs[0])).toBe(true);
451+
452+
interop.free(ptr);
453+
interop.free(pointsPtr);
454+
});
455+
400456
it("interops string from CString with fixed length", function () {
401457
const str = "te\0st";
402458
const ptr = interop.alloc((str.length + 1) * interop.sizeof(interop.types.uint8));

v8ios.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
6573B9EA291FE2A700B0ED7C /* jsilib.h in Headers */ = {isa = PBXBuildFile; fileRef = 6573B9E1291FE2A700B0ED7C /* jsilib.h */; };
4747
6573B9ED291FE5B700B0ED7C /* JSIRuntime.h in Headers */ = {isa = PBXBuildFile; fileRef = 6573B9EB291FE5B700B0ED7C /* JSIRuntime.h */; };
4848
6573B9EE291FE5B700B0ED7C /* JSIRuntime.m in Sources */ = {isa = PBXBuildFile; fileRef = 6573B9EC291FE5B700B0ED7C /* JSIRuntime.m */; };
49+
68E0071A2EB0F7EC00B923AE /* TNSPointCollection.m in Sources */ = {isa = PBXBuildFile; fileRef = 68E007192EB0F7EC00B923AE /* TNSPointCollection.m */; };
4950
9160C065291ED41F000641C0 /* SpinLock.h in Headers */ = {isa = PBXBuildFile; fileRef = 9160C064291ED41F000641C0 /* SpinLock.h */; };
5051
91B25A0A29DAC83D00E3CE04 /* ns-v8-tracing-agent-impl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 91B25A0829DAC83D00E3CE04 /* ns-v8-tracing-agent-impl.mm */; };
5152
91B25A0B29DAC83D00E3CE04 /* ns-v8-tracing-agent-impl.h in Headers */ = {isa = PBXBuildFile; fileRef = 91B25A0929DAC83D00E3CE04 /* ns-v8-tracing-agent-impl.h */; };
@@ -479,6 +480,8 @@
479480
6573B9E1291FE2A700B0ED7C /* jsilib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsilib.h; sourceTree = "<group>"; };
480481
6573B9EB291FE5B700B0ED7C /* JSIRuntime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSIRuntime.h; sourceTree = "<group>"; };
481482
6573B9EC291FE5B700B0ED7C /* JSIRuntime.m */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; path = JSIRuntime.m; sourceTree = "<group>"; };
483+
68E007192EB0F7EC00B923AE /* TNSPointCollection.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TNSPointCollection.m; sourceTree = "<group>"; };
484+
68E0071B2EB0F80D00B923AE /* TNSPointCollection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TNSPointCollection.h; sourceTree = "<group>"; };
482485
9160C064291ED41F000641C0 /* SpinLock.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SpinLock.h; path = NativeScript/runtime/SpinLock.h; sourceTree = "<group>"; };
483486
91B25A0829DAC83D00E3CE04 /* ns-v8-tracing-agent-impl.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = "ns-v8-tracing-agent-impl.mm"; sourceTree = "<group>"; };
484487
91B25A0929DAC83D00E3CE04 /* ns-v8-tracing-agent-impl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ns-v8-tracing-agent-impl.h"; sourceTree = "<group>"; };
@@ -1134,6 +1137,8 @@
11341137
C29374EF229FC1600075CB16 /* TNSClassWithPlaceholder.m */,
11351138
C22EF68C2379414300D67CBF /* TNSSwiftLike.h */,
11361139
C22EF68A2379412100D67CBF /* TNSSwiftLike.m */,
1140+
68E007192EB0F7EC00B923AE /* TNSPointCollection.m */,
1141+
68E0071B2EB0F80D00B923AE /* TNSPointCollection.h */,
11371142
);
11381143
path = Interfaces;
11391144
sourceTree = "<group>";
@@ -2160,6 +2165,7 @@
21602165
C293751B229FC1600075CB16 /* TNSTestNativeCallbacks.m in Sources */,
21612166
C293751D229FC1600075CB16 /* TNSTestCommon.m in Sources */,
21622167
C293751F229FC1600075CB16 /* TNSBridgedTypes.m in Sources */,
2168+
68E0071A2EB0F7EC00B923AE /* TNSPointCollection.m in Sources */,
21632169
C2937528229FC1600075CB16 /* TNSObjCTypes.m in Sources */,
21642170
C2937526229FC1600075CB16 /* TNSRecords.m in Sources */,
21652171
C2937522229FC1600075CB16 /* TNSReturnsRetained.m in Sources */,

0 commit comments

Comments
 (0)