|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
| 5 | +#import <Foundation/Foundation.h> |
5 | 6 | #import <OCMock/OCMock.h> |
6 | 7 | #import <XCTest/XCTest.h> |
7 | 8 |
|
@@ -30,6 +31,62 @@ - (void)testCreate { |
30 | 31 | XCTAssertNotNil(engine); |
31 | 32 | } |
32 | 33 |
|
| 34 | +- (void)testInfoPlist { |
| 35 | + // Check the embedded Flutter.framework Info.plist, not the linked dylib. |
| 36 | + NSURL* flutterFrameworkURL = |
| 37 | + [NSBundle.mainBundle.privateFrameworksURL URLByAppendingPathComponent:@"Flutter.framework"]; |
| 38 | + NSBundle* flutterBundle = [NSBundle bundleWithURL:flutterFrameworkURL]; |
| 39 | + XCTAssertEqualObjects(flutterBundle.bundleIdentifier, @"io.flutter.flutter"); |
| 40 | + |
| 41 | + NSDictionary<NSString*, id>* infoDictionary = flutterBundle.infoDictionary; |
| 42 | + |
| 43 | + // OS version can have one, two, or three digits: "8", "8.0", "8.0.0" |
| 44 | + NSError* regexError = NULL; |
| 45 | + NSRegularExpression* osVersionRegex = |
| 46 | + [NSRegularExpression regularExpressionWithPattern:@"((0|[1-9]\\d*)\\.)*(0|[1-9]\\d*)" |
| 47 | + options:NSRegularExpressionCaseInsensitive |
| 48 | + error:®exError]; |
| 49 | + XCTAssertNil(regexError); |
| 50 | + |
| 51 | + // Smoke test the test regex. |
| 52 | + NSString* testString = @"9"; |
| 53 | + NSUInteger versionMatches = |
| 54 | + [osVersionRegex numberOfMatchesInString:testString |
| 55 | + options:NSMatchingAnchored |
| 56 | + range:NSMakeRange(0, testString.length)]; |
| 57 | + XCTAssertEqual(versionMatches, 1UL); |
| 58 | + testString = @"9.1"; |
| 59 | + versionMatches = [osVersionRegex numberOfMatchesInString:testString |
| 60 | + options:NSMatchingAnchored |
| 61 | + range:NSMakeRange(0, testString.length)]; |
| 62 | + XCTAssertEqual(versionMatches, 1UL); |
| 63 | + testString = @"9.0.1"; |
| 64 | + versionMatches = [osVersionRegex numberOfMatchesInString:testString |
| 65 | + options:NSMatchingAnchored |
| 66 | + range:NSMakeRange(0, testString.length)]; |
| 67 | + XCTAssertEqual(versionMatches, 1UL); |
| 68 | + testString = @".0.1"; |
| 69 | + versionMatches = [osVersionRegex numberOfMatchesInString:testString |
| 70 | + options:NSMatchingAnchored |
| 71 | + range:NSMakeRange(0, testString.length)]; |
| 72 | + XCTAssertEqual(versionMatches, 0UL); |
| 73 | + |
| 74 | + // Test Info.plist values. |
| 75 | + NSString* minimumOSVersion = infoDictionary[@"MinimumOSVersion"]; |
| 76 | + versionMatches = [osVersionRegex numberOfMatchesInString:minimumOSVersion |
| 77 | + options:NSMatchingAnchored |
| 78 | + range:NSMakeRange(0, minimumOSVersion.length)]; |
| 79 | + XCTAssertEqual(versionMatches, 1UL); |
| 80 | + |
| 81 | + // SHA length is 40. |
| 82 | + XCTAssertEqual(((NSString*)infoDictionary[@"FlutterEngine"]).length, 40UL); |
| 83 | + |
| 84 | + // {clang_version} placeholder is 15 characters. The clang string version |
| 85 | + // is longer than that, so check if the placeholder has been replaced, without |
| 86 | + // actually checking a literal string, which could be different on various machines. |
| 87 | + XCTAssertTrue(((NSString*)infoDictionary[@"ClangVersion"]).length > 15UL); |
| 88 | +} |
| 89 | + |
33 | 90 | - (void)testDeallocated { |
34 | 91 | __weak FlutterEngine* weakEngine = nil; |
35 | 92 | { |
|
0 commit comments