Skip to content

Commit

Permalink
feat: visionOS unit tests (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanWalker authored Jan 19, 2025
1 parent b73693a commit ac52442
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 62 deletions.
2 changes: 1 addition & 1 deletion NativeScript/NativeScript-Prefix.pch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef NativeScript_Prefix_pch
#define NativeScript_Prefix_pch

#define NATIVESCRIPT_VERSION "8.7.2"
#define NATIVESCRIPT_VERSION "8.8.1"

#ifdef DEBUG
#define SIZEOF_OFF_T 8
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ To start diving into the v8 iOS runtime make sure you have Xcode and [Homebrew](
# Install CMake
brew install cmake

# Install jq (for scripting json replacements)
brew install jq

# (Optional) Install clang-format to format the code
brew install clang-format

Expand Down
111 changes: 57 additions & 54 deletions TestFixtures/Api/TNSVersions.h
Original file line number Diff line number Diff line change
@@ -1,61 +1,59 @@
#define generateVersionDeclarations(V1, V2) \
__attribute__((availability(ios, introduced = V1))) \
@interface TNSInterface \
##V2##Plus : NSObject \
@end \
\
@interface TNSInterfaceMembers \
##V2 : NSObject \
@property int property \
__attribute__((availability(ios, introduced = V1))); \
\
+(void)staticMethod \
__attribute__((availability(ios, introduced = V1))); \
\
-(void)instanceMethod \
__attribute__((availability(ios, introduced = V1))); \
@end \
\
__attribute__((availability(ios, introduced = V1))) void TNSFunction##V2##Plus(); \
\
__attribute__((availability(ios, introduced = V1))) extern const int TNSConstant##V2##Plus; \
\
enum TNSEnum##V2##Plus { \
TNSEnum##V2##Member \
} \
__attribute__((availability(ios, introduced = V1)))
#define generateVersionDeclarations(V1, V2) \
__attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1))) @interface TNSInterface \
##V2##Plus : NSObject @end \
\
@interface TNSInterfaceMembers \
##V2 : NSObject @property int property __attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1))); \
\
+(void)staticMethod __attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1))); \
\
-(void)instanceMethod __attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1))); \
@end \
\
__attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1))) void TNSFunction##V2##Plus(); \
\
__attribute__((availability(ios, introduced = V1))) __attribute__( \
(availability(visionos, introduced = V1))) extern const int TNSConstant##V2##Plus; \
\
enum TNSEnum##V2##Plus { TNSEnum##V2##Member } \
__attribute__((availability(ios, introduced = V1))) \
__attribute__((availability(visionos, introduced = V1)))

#ifndef generateVersionImpl
#define generateVersion(V1, V2) \
generateVersionDeclarations(V1, V2)
#define generateVersion(V1, V2) generateVersionDeclarations(V1, V2)
#else
#define generateVersion(V1, V2) \
generateVersionDeclarations(V1, V2); \
\
@implementation TNSInterface \
##V2##Plus \
@end \
\
@implementation TNSInterfaceMembers \
##V2 \
+ (void)staticMethod{} \
\
- (void)instanceMethod {} \
@end \
\
void TNSFunction##V2##Plus() {} \
\
const int TNSConstant##V2##Plus = 0
#define generateVersion(V1, V2) \
generateVersionDeclarations(V1, V2); \
\
@implementation TNSInterface \
##V2##Plus @end \
\
@implementation TNSInterfaceMembers \
##V2 + (void)staticMethod{} \
\
- (void)instanceMethod {} \
@end \
\
void TNSFunction##V2##Plus() {} \
\
const int TNSConstant##V2##Plus = 0
#endif

#define generateMinors(MAJOR) \
generateVersion(MAJOR##.0, MAJOR##_0); \
generateVersion(MAJOR##.1, MAJOR##_1); \
generateVersion(MAJOR##.2, MAJOR##_2); \
generateVersion(MAJOR##.3, MAJOR##_3); \
generateVersion(MAJOR##.4, MAJOR##_4); \
generateVersion(MAJOR##.5, MAJOR##_5);
#define generateMinors(MAJOR) \
generateVersion(MAJOR##.0, MAJOR##_0); \
generateVersion(MAJOR##.1, MAJOR##_1); \
generateVersion(MAJOR##.2, MAJOR##_2); \
generateVersion(MAJOR##.3, MAJOR##_3); \
generateVersion(MAJOR##.4, MAJOR##_4); \
generateVersion(MAJOR##.5, MAJOR##_5);

generateMinors(1);
generateMinors(2);
generateMinors(9);
generateMinors(10);
generateMinors(11);
Expand All @@ -64,10 +62,12 @@ generateMinors(13);
generateMinors(14);
generateMinors(15);

// max availability version that can be currently represented in the binary metadata is 31.7 (major << 3 | minor) -> uint8_t
// max availability version that can be currently represented in the binary metadata is 31.7 (major
// << 3 | minor) -> uint8_t
#define MAX_AVAILABILITY 31.7

__attribute__((availability(ios, introduced = MAX_AVAILABILITY)))
__attribute__((availability(visionos, introduced = MAX_AVAILABILITY)))
@protocol TNSProtocolNeverAvailable<NSObject>

@property(class, readonly) int staticPropertyFromProtocolNeverAvailable;
Expand All @@ -85,6 +85,7 @@ __attribute__((availability(ios, introduced = MAX_AVAILABILITY)))
@end

__attribute__((availability(ios, introduced = 1.0)))
__attribute__((availability(visionos, introduced = 1.0)))
@protocol TNSProtocolAlwaysAvailable<NSObject>

@property(class, readonly) int staticPropertyFromProtocolAlwaysAvailable;
Expand All @@ -97,10 +98,12 @@ __attribute__((availability(ios, introduced = 1.0)))

@end

@interface TNSInterfaceAlwaysAvailable : NSObject <TNSProtocolNeverAvailable, TNSProtocolAlwaysAvailable>
@interface TNSInterfaceAlwaysAvailable
: NSObject <TNSProtocolNeverAvailable, TNSProtocolAlwaysAvailable>
@end

__attribute__((availability(ios, introduced = MAX_AVAILABILITY)))
__attribute__((availability(visionos, introduced = MAX_AVAILABILITY)))
@interface TNSInterfaceNeverAvailable : TNSInterfaceAlwaysAvailable
@end

Expand Down
9 changes: 9 additions & 0 deletions TestFixtures/exported-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ _functionWithUShortPtr
_TNSIsConfigurationDebug
_TNSClearOutput
_TNSConstant
_TNSConstant1_0Plus
_TNSConstant1_1Plus
_TNSConstant1_2Plus
_TNSConstant10_0Plus
_TNSConstant10_1Plus
_TNSConstant10_2Plus
Expand Down Expand Up @@ -94,12 +97,18 @@ _TNSConstant15_2Plus
_TNSConstant15_3Plus
_TNSConstant15_4Plus
_TNSConstant15_5Plus
_TNSConstant1_0Plus
_TNSConstant1_1Plus
_TNSConstant1_2Plus
_TNSConstant9_0Plus
_TNSConstant9_1Plus
_TNSConstant9_2Plus
_TNSConstant9_3Plus
_TNSConstant9_4Plus
_TNSConstant9_5Plus
_TNSFunction1_0Plus
_TNSFunction1_1Plus
_TNSFunction1_2Plus
_TNSFunction9_0Plus
_TNSFunction9_1Plus
_TNSFunction9_2Plus
Expand Down
6 changes: 6 additions & 0 deletions TestRunner/app/tests/Infrastructure/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ function isSimulator() {
}

global.isSimulator = isSimulator();

function isVision() {
return UIDevice.currentDevice.model.toLowerCase().includes('vision');
}

global.isVision = isVision();
8 changes: 7 additions & 1 deletion TestRunner/app/tests/MetadataTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ describe("Metadata", function () {
const swiftLikeObj = TNSSwiftLikeFactory.create();
expect(swiftLikeObj.constructor).toBe(global.TNSSwiftLike);
expect(swiftLikeObj.constructor.name).toBe("_TtC17NativeScriptTests12TNSSwiftLike");
var expectedName = NSProcessInfo.processInfo.isOperatingSystemAtLeastVersion({ majorVersion: 13, minorVersion: 4, patchVersion: 0 })
let majorVersion = 13;
let minorVersion = 4;
if (isVision) {
majorVersion = 1;
minorVersion = 0;
}
var expectedName = NSProcessInfo.processInfo.isOperatingSystemAtLeastVersion({ majorVersion: majorVersion, minorVersion: minorVersion, patchVersion: 0 })
? "_TtC17NativeScriptTests12TNSSwiftLike"
: "NativeScriptTests.TNSSwiftLike";
expect(NSString.stringWithUTF8String(class_getName(swiftLikeObj.constructor)).toString()).toBe(expectedName);
Expand Down
16 changes: 14 additions & 2 deletions TestRunner/app/tests/VersionDiffTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ describe(module.id, function() {
}

function forEachVersion(action) {
for (var major = 9; major <= 15; major++) {
for (var minor = 0; minor <= 5; minor++) {
let majorMinVersion = 9;
let majorMaxVersion = 15;
let minorMaxVersion = 5;
if (isVision) {
majorMinVersion = 1;
majorMaxVersion = 1;
minorMaxVersion = 2;
}
for (var major = majorMinVersion; major <= majorMaxVersion; major++) {
for (var minor = 0; minor <= minorMaxVersion; minor++) {
action(major, minor);
}
}
Expand Down Expand Up @@ -74,6 +82,10 @@ describe(module.id, function() {
});

it("Base class which is unavailable should be skipped", function() {
if (isVision) {
pending();
return;
}
// Test case inspired from MTLArrayType(8.0) : MTLType(11.0) : NSObject
// TNSInterfaceNeverAvailableDescendant : TNSInterfaceNeverAvailable(API31.7 - skipped) : TNSInterfaceAlwaysAvailable
expect(Object.getPrototypeOf(TNSInterfaceNeverAvailableDescendant).toString()).toBe(TNSInterfaceAlwaysAvailable.toString(), "TNSInterfaceNeverAvailable base class should be skipped as it is unavailable");
Expand Down
26 changes: 22 additions & 4 deletions v8ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
2B5088A62BBEB92300F6EB68 /* metadata-arm64.bin in Resources */ = {isa = PBXBuildFile; fileRef = 2BFE21ED2AC1AC3100307752 /* metadata-arm64.bin */; };
2B5088A72BBEC1BC00F6EB68 /* TNSWidgets.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = C20525A72577D86600C12A5C /* TNSWidgets.xcframework */; };
2B5088A82BBEC1BC00F6EB68 /* TNSWidgets.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C20525A72577D86600C12A5C /* TNSWidgets.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2B7EA6AF2353477000E5184E /* NativeScriptException.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2B7EA6AD2353476F00E5184E /* NativeScriptException.mm */; };
2B7EA6B02353477000E5184E /* NativeScriptException.h in Headers */ = {isa = PBXBuildFile; fileRef = 2B7EA6AE2353477000E5184E /* NativeScriptException.h */; };
2BFE22062AC1C93100307752 /* metadata-arm64.bin in Resources */ = {isa = PBXBuildFile; fileRef = 2BFE22052AC1C93100307752 /* metadata-arm64.bin */; };
Expand Down Expand Up @@ -1843,7 +1841,6 @@
files = (
C27E5DB522F3206B00498ED0 /* app in Resources */,
C27E5DBA22F324C200498ED0 /* [email protected] in Resources */,
2B5088A62BBEB92300F6EB68 /* metadata-arm64.bin in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2282,7 +2279,6 @@
};
C293752B229FC4740075CB16 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilter = ios;
target = C29374E1229FC0F60075CB16 /* TestFixtures */;
targetProxy = C293752A229FC4740075CB16 /* PBXContainerItemProxy */;
};
Expand Down Expand Up @@ -2376,6 +2372,7 @@
C23992CE236C2D6E00D2F720 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO;
CLANG_ENABLE_MODULES = NO;
CODE_SIGN_STYLE = Automatic;
Expand All @@ -2391,6 +2388,8 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.TestRunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
Expand All @@ -2402,6 +2401,7 @@
C23992CF236C2D6E00D2F720 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = NO;
CLANG_ENABLE_MODULES = NO;
CODE_SIGN_STYLE = Automatic;
Expand All @@ -2417,6 +2417,8 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.TestRunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
Expand Down Expand Up @@ -2549,6 +2551,7 @@
C27E5D9F22F31CCC00498ED0 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
CLANG_CXX_LIBRARY = "compiler-default";
Expand Down Expand Up @@ -2580,13 +2583,16 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.AppWithModules;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
};
C27E5DA022F31CCC00498ED0 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
CLANG_CXX_LIBRARY = "compiler-default";
Expand Down Expand Up @@ -2618,13 +2624,16 @@
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.AppWithModules;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
};
C29374E9229FC0F60075CB16 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
CLANG_ENABLE_MODULES = NO;
CLANG_WARN_STRICT_PROTOTYPES = NO;
DEFINES_MODULE = YES;
Expand All @@ -2633,7 +2642,10 @@
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
SYMROOT = build;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -2642,6 +2654,7 @@
C29374EA229FC0F60075CB16 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
CLANG_ENABLE_MODULES = NO;
CLANG_WARN_STRICT_PROTOTYPES = NO;
DEFINES_MODULE = YES;
Expand All @@ -2651,7 +2664,10 @@
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "xrsimulator xros iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = YES;
SYMROOT = build;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down Expand Up @@ -2839,6 +2855,7 @@
__DATA,
__TNSMetadata,
"\"$(SRCROOT)/NativeScript/metadata-arm64.bin\"",
"-w",
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.NativeScript;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down Expand Up @@ -2931,6 +2948,7 @@
__DATA,
__TNSMetadata,
"\"$(SRCROOT)/NativeScript/metadata-arm64.bin\"",
"-w",
);
PRODUCT_BUNDLE_IDENTIFIER = org.nativescript.NativeScript;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down

0 comments on commit ac52442

Please sign in to comment.