@bugsee/react-native 0.0.0-stage → 7.0.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +552 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +944 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
@import XCTest;
|
|
2
|
+
@import Bugsee;
|
|
3
|
+
@import BugseeRNSupport;
|
|
4
|
+
|
|
5
|
+
#import "BGSRNFakeReport.h"
|
|
6
|
+
|
|
7
|
+
/// The iOS half of the object transport: JSON text in, Foundation out. Mirrors
|
|
8
|
+
/// Android's `BridgeJsonTest` by name where the rule is shared.
|
|
9
|
+
///
|
|
10
|
+
/// The defect it exists for: React Native's TurboModule conversion of an
|
|
11
|
+
/// object argument (`convertJSIObjectToNSDictionary`) skips every member whose
|
|
12
|
+
/// value is JS `null`, unless an app-level feature flag is on. A dictionary
|
|
13
|
+
/// that reaches native with the key missing cannot say "clear this".
|
|
14
|
+
@interface BGSRNJSONTests : XCTestCase
|
|
15
|
+
@end
|
|
16
|
+
|
|
17
|
+
@implementation BGSRNJSONTests
|
|
18
|
+
|
|
19
|
+
- (NSDictionary *)parse:(NSString *)json {
|
|
20
|
+
NSError *error = nil;
|
|
21
|
+
NSDictionary *result = BGSRNJSONObject(json, &error);
|
|
22
|
+
XCTAssertNotNil(result, @"rejected %@: %@", json, error);
|
|
23
|
+
XCTAssertNil(error);
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
- (void)assertBad:(NSString *_Nullable)json {
|
|
28
|
+
NSError *error = nil;
|
|
29
|
+
XCTAssertNil(BGSRNJSONObject(json, &error), @"accepted %@", json);
|
|
30
|
+
XCTAssertNotNil(error, @"no error for %@", json);
|
|
31
|
+
XCTAssertEqualObjects(error.domain, BGSRNJSONErrorDomain);
|
|
32
|
+
XCTAssertGreaterThan(BGSRNErrorMessage(error).length, 0u);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static BOOL IsCFBoolean(id value) {
|
|
36
|
+
return [value isKindOfClass:NSNumber.class] &&
|
|
37
|
+
CFGetTypeID((__bridge CFTypeRef)value) == CFBooleanGetTypeID();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static BOOL IsIntegerNumber(id value) {
|
|
41
|
+
return [value isKindOfClass:NSNumber.class] && !IsCFBoolean(value) &&
|
|
42
|
+
!CFNumberIsFloatType((__bridge CFNumberRef)value);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static BOOL IsFloatNumber(id value) {
|
|
46
|
+
return [value isKindOfClass:NSNumber.class] && !IsCFBoolean(value) &&
|
|
47
|
+
CFNumberIsFloatType((__bridge CFNumberRef)value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#pragma mark - Null
|
|
51
|
+
|
|
52
|
+
- (void)testATopLevelNullIsKeptAsNSNull {
|
|
53
|
+
NSDictionary *map = [self parse:@"{\"nil\":null,\"s\":\"x\"}"];
|
|
54
|
+
XCTAssertEqualObjects(map[@"nil"], NSNull.null);
|
|
55
|
+
XCTAssertEqualObjects(map[@"s"], @"x");
|
|
56
|
+
XCTAssertEqual(map.count, 2u);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
- (void)testANestedNullIsKeptInAnObjectAndInAnArray {
|
|
60
|
+
NSDictionary *map = [self parse:@"{\"attributes\":{\"gone\":null},\"list\":[null,1]}"];
|
|
61
|
+
XCTAssertEqualObjects(map[@"attributes"], @{ @"gone" : NSNull.null });
|
|
62
|
+
XCTAssertEqualObjects(map[@"list"], (@[ NSNull.null, @1 ]));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#pragma mark - Numbers and booleans
|
|
66
|
+
|
|
67
|
+
/// The SDK's JSON writer prints an integer NSNumber as `3`; a float-typed one
|
|
68
|
+
/// holding 3 would still print `3`, but the attribute and param stores take
|
|
69
|
+
/// the number as given, so the type is pinned, not only the value.
|
|
70
|
+
- (void)testIntegralNumbersAreIntegerNumbers {
|
|
71
|
+
NSDictionary *map =
|
|
72
|
+
[self parse:@"{\"int\":3,\"neg\":-7,\"zero\":0,\"big\":9007199254740991,\"minSafe\":-9007199254740992}"];
|
|
73
|
+
for (NSString *key in @[ @"int", @"neg", @"zero", @"big", @"minSafe" ]) {
|
|
74
|
+
XCTAssertTrue(IsIntegerNumber(map[key]), @"%@ is %@ (%s)", key, [map[key] class], [map[key] objCType]);
|
|
75
|
+
}
|
|
76
|
+
XCTAssertEqual([map[@"int"] longLongValue], 3);
|
|
77
|
+
XCTAssertEqual([map[@"neg"] longLongValue], -7);
|
|
78
|
+
XCTAssertEqual([map[@"zero"] longLongValue], 0);
|
|
79
|
+
XCTAssertEqual([map[@"big"] longLongValue], 9007199254740991LL);
|
|
80
|
+
XCTAssertEqual([map[@"minSafe"] longLongValue], -9007199254740992LL);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
- (void)testFractionalNumbersAreDoubles {
|
|
84
|
+
NSDictionary *map = [self parse:@"{\"frac\":1.5,\"tiny\":1e-7,\"huge\":1e+300,\"neg\":-0.25}"];
|
|
85
|
+
for (NSString *key in @[ @"frac", @"tiny", @"huge", @"neg" ]) {
|
|
86
|
+
XCTAssertTrue(IsFloatNumber(map[key]), @"%@ is %@ (%s)", key, [map[key] class], [map[key] objCType]);
|
|
87
|
+
}
|
|
88
|
+
XCTAssertEqual([map[@"frac"] doubleValue], 1.5);
|
|
89
|
+
XCTAssertEqual([map[@"tiny"] doubleValue], 1e-7);
|
|
90
|
+
XCTAssertEqual([map[@"huge"] doubleValue], 1e300);
|
|
91
|
+
XCTAssertEqual([map[@"neg"] doubleValue], -0.25);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// By identity: the SDK's writer special-cases CFBoolean, and anything else
|
|
95
|
+
/// holding 1 prints as `1`.
|
|
96
|
+
- (void)testBooleansAreCFBooleans {
|
|
97
|
+
NSDictionary *map = [self parse:@"{\"yes\":true,\"no\":false}"];
|
|
98
|
+
XCTAssertEqual((__bridge CFBooleanRef)map[@"yes"], kCFBooleanTrue);
|
|
99
|
+
XCTAssertEqual((__bridge CFBooleanRef)map[@"no"], kCFBooleanFalse);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// And a number is never one: 1 and 0 must not come back as true and false.
|
|
103
|
+
- (void)testOneAndZeroAreNotBooleans {
|
|
104
|
+
NSDictionary *map = [self parse:@"{\"one\":1,\"zero\":0}"];
|
|
105
|
+
XCTAssertFalse(IsCFBoolean(map[@"one"]));
|
|
106
|
+
XCTAssertFalse(IsCFBoolean(map[@"zero"]));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/// An integer literal past `long long` range -- what `JSON.stringify` writes
|
|
110
|
+
/// for 1e20 -- is not a plain NSNumber: `NSJSONSerialization` returns an
|
|
111
|
+
/// `NSDecimalNumber`. Pinned so the report path below is known to see one.
|
|
112
|
+
- (void)testAnIntegerPastLongLongRangeIsADecimalNumber {
|
|
113
|
+
id big = [self parse:@"{\"n\":100000000000000000000}"][@"n"];
|
|
114
|
+
XCTAssertTrue([big isKindOfClass:NSDecimalNumber.class], @"%@ (%s)", [big class], [big objCType]);
|
|
115
|
+
XCTAssertFalse(IsCFBoolean(big));
|
|
116
|
+
XCTAssertEqual([big doubleValue], 1e20);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// ...and `BGSRNReportOps` handles it: `IsFiniteNumber` accepts it as an
|
|
120
|
+
/// attribute value, `WireNumber` stores it as a double (it is past 2^53, so
|
|
121
|
+
/// not an exact integer), and as a severity it is out of range, not a crash.
|
|
122
|
+
- (void)testADecimalNumberAttributeIsStoredAsADouble {
|
|
123
|
+
BGSRNFakeReport *report = [BGSRNFakeReport new];
|
|
124
|
+
NSError *error = nil;
|
|
125
|
+
XCTAssertTrue([BGSRNReportOps applyPatchJSON:@"{\"attributes\":{\"big\":100000000000000000000}}"
|
|
126
|
+
toReport:report
|
|
127
|
+
error:&error],
|
|
128
|
+
@"%@", error);
|
|
129
|
+
id stored = report.fakeAttributes[@"big"];
|
|
130
|
+
XCTAssertFalse([stored isKindOfClass:NSDecimalNumber.class], @"%@", [stored class]);
|
|
131
|
+
XCTAssertTrue(IsFloatNumber(stored), @"%@ (%s)", [stored class], [stored objCType]);
|
|
132
|
+
XCTAssertEqual([stored doubleValue], 1e20);
|
|
133
|
+
|
|
134
|
+
error = nil;
|
|
135
|
+
XCTAssertFalse([BGSRNReportOps applyPatchJSON:@"{\"severity\":100000000000000000000}"
|
|
136
|
+
toReport:report
|
|
137
|
+
error:&error]);
|
|
138
|
+
XCTAssertEqual(error.code, BGSRNReportErrorBadArgument);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#pragma mark - Lone surrogates
|
|
142
|
+
|
|
143
|
+
/// Why `encodeBridgeObject` replaces lone surrogates in JS: `JSON.stringify`
|
|
144
|
+
/// escapes one as `\ud800`, and `NSJSONSerialization` rejects the WHOLE text
|
|
145
|
+
/// for it. Unnormalised, a summary cut mid-emoji rejected on iOS alone.
|
|
146
|
+
- (void)testNSJSONSerializationRejectsALoneSurrogateEscape {
|
|
147
|
+
[self assertBad:@"{\"s\":\"\\ud800\"}"];
|
|
148
|
+
[self assertBad:@"{\"s\":\"a\\udc00b\"}"];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/// What JS sends instead -- U+FFFD, raw or escaped -- and a valid escaped pair, parse.
|
|
152
|
+
- (void)testTheReplacementCharacterAndAValidPairParse {
|
|
153
|
+
XCTAssertEqualObjects([self parse:@"{\"s\":\"a\uFFFD\"}"][@"s"], @"a\uFFFD");
|
|
154
|
+
XCTAssertEqualObjects([self parse:@"{\"s\":\"a\\ufffd\"}"][@"s"], @"a\uFFFD");
|
|
155
|
+
XCTAssertEqualObjects([self parse:@"{\"s\":\"\\ud83d\\ude00\"}"][@"s"], @"\U0001F600");
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#pragma mark - Structure
|
|
159
|
+
|
|
160
|
+
- (void)testNestedArraysAndObjectsBecomeArraysAndDictionaries {
|
|
161
|
+
NSDictionary *map = [self
|
|
162
|
+
parse:@"{\"nested\":{\"list\":[1,\"two\",{\"deep\":false},[true]],\"empty\":{}},\"none\":[]}"];
|
|
163
|
+
NSArray *list = map[@"nested"][@"list"];
|
|
164
|
+
XCTAssertEqualObjects(list[0], @1);
|
|
165
|
+
XCTAssertEqualObjects(list[1], @"two");
|
|
166
|
+
XCTAssertEqualObjects(list[2], @{ @"deep" : @NO });
|
|
167
|
+
XCTAssertEqualObjects(list[3], @[ @YES ]);
|
|
168
|
+
XCTAssertEqualObjects(map[@"nested"][@"empty"], @{});
|
|
169
|
+
XCTAssertEqualObjects(map[@"none"], @[]);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
- (void)testStringsAreUnescaped {
|
|
173
|
+
XCTAssertEqualObjects([self parse:@"{\"s\":\"a\\\"b\\\\c\\nd\\u00e9\"}"][@"s"], @"a\"b\\c\ndé");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
- (void)testProtoIsAnOrdinaryKey {
|
|
177
|
+
XCTAssertEqualObjects([self parse:@"{\"__proto__\":\"x\"}"][@"__proto__"], @"x");
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
- (void)testAnEmptyObjectIsAnEmptyDictionary {
|
|
181
|
+
XCTAssertEqualObjects([self parse:@"{}"], @{});
|
|
182
|
+
XCTAssertEqualObjects([self parse:@" {}\n"], @{});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
#pragma mark - Bad input
|
|
186
|
+
|
|
187
|
+
- (void)testMalformedJsonIsBad {
|
|
188
|
+
[self assertBad:@"{\"a\":"];
|
|
189
|
+
[self assertBad:@"{\"a\" 1}"];
|
|
190
|
+
[self assertBad:@""];
|
|
191
|
+
[self assertBad:@" "];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
- (void)testAnythingButAnObjectIsBad {
|
|
195
|
+
[self assertBad:@"[1,2]"];
|
|
196
|
+
[self assertBad:@"\"s\""];
|
|
197
|
+
[self assertBad:@"3"];
|
|
198
|
+
[self assertBad:@"null"];
|
|
199
|
+
[self assertBad:@"true"];
|
|
200
|
+
[self assertBad:@"not json"];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
- (void)testTrailingTextAfterTheObjectIsBad {
|
|
204
|
+
[self assertBad:@"{\"a\":1} x"];
|
|
205
|
+
[self assertBad:@"{\"a\":1}{}"];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
- (void)testANilStringIsBad {
|
|
209
|
+
[self assertBad:nil];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/// A NULL error out-parameter is allowed, as everywhere in Foundation.
|
|
213
|
+
- (void)testANullErrorPointerIsAllowed {
|
|
214
|
+
XCTAssertNil(BGSRNJSONObject(@"[", NULL));
|
|
215
|
+
XCTAssertEqualObjects(BGSRNJSONObject(@"{}", NULL), @{});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
#pragma mark - The report patch, end to end
|
|
219
|
+
|
|
220
|
+
/// `reportUpdate` as it now arrives: JSON text. The three edits the object
|
|
221
|
+
/// conversion dropped -- a null summary, a null description, a null
|
|
222
|
+
/// attribute -- all take effect.
|
|
223
|
+
- (void)testAParsedPatchClearsAndRemoves {
|
|
224
|
+
BGSRNFakeReport *report = [BGSRNFakeReport new];
|
|
225
|
+
report.fakeSummary = @"old summary";
|
|
226
|
+
report.fakeDescription = @"old description";
|
|
227
|
+
report.fakeAttributes[@"gone"] = @"value";
|
|
228
|
+
report.fakeAttributes[@"kept"] = @"value";
|
|
229
|
+
|
|
230
|
+
NSError *error = nil;
|
|
231
|
+
XCTAssertTrue([BGSRNReportOps applyPatchJSON:@"{\"summary\":null,\"description\":null,"
|
|
232
|
+
@"\"attributes\":{\"gone\":null,\"count\":3}}"
|
|
233
|
+
toReport:report
|
|
234
|
+
error:&error],
|
|
235
|
+
@"%@", error);
|
|
236
|
+
XCTAssertNil(error);
|
|
237
|
+
XCTAssertNil(report.fakeSummary);
|
|
238
|
+
XCTAssertNil(report.fakeDescription);
|
|
239
|
+
XCTAssertNil(report.fakeAttributes[@"gone"]);
|
|
240
|
+
XCTAssertEqualObjects(report.fakeAttributes[@"kept"], @"value");
|
|
241
|
+
XCTAssertEqualObjects(report.fakeAttributes[@"count"], @3);
|
|
242
|
+
XCTAssertTrue([report.mutations containsObject:@"removeAttributeForName:"]);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/// Text that is not a JSON object is a bad argument, and touches nothing.
|
|
246
|
+
- (void)testMalformedPatchJsonIsABadArgument {
|
|
247
|
+
BGSRNFakeReport *report = [BGSRNFakeReport new];
|
|
248
|
+
report.fakeSummary = @"old summary";
|
|
249
|
+
for (NSString *json in @[ @"{\"summary\":", @"[]", @"" ]) {
|
|
250
|
+
NSError *error = nil;
|
|
251
|
+
XCTAssertFalse([BGSRNReportOps applyPatchJSON:json toReport:report error:&error], @"accepted %@", json);
|
|
252
|
+
XCTAssertEqualObjects(error.domain, BGSRNReportErrorDomain);
|
|
253
|
+
XCTAssertEqual(error.code, BGSRNReportErrorBadArgument);
|
|
254
|
+
XCTAssertEqualObjects(BGSRNReportErrorWireCode(error), @"E_REPORT_BAD_ARGUMENT");
|
|
255
|
+
}
|
|
256
|
+
XCTAssertEqualObjects(report.fakeSummary, @"old summary");
|
|
257
|
+
XCTAssertEqualObjects(report.mutations, @[]);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/// Parsing does not bypass validation: a bad field still applies nothing.
|
|
261
|
+
- (void)testAParsedPatchIsStillAllOrNothing {
|
|
262
|
+
BGSRNFakeReport *report = [BGSRNFakeReport new];
|
|
263
|
+
report.fakeSummary = @"old summary";
|
|
264
|
+
NSError *error = nil;
|
|
265
|
+
XCTAssertFalse([BGSRNReportOps applyPatchJSON:@"{\"summary\":null,\"attributes\":{\"gone\":null},\"severity\":0}"
|
|
266
|
+
toReport:report
|
|
267
|
+
error:&error]);
|
|
268
|
+
XCTAssertEqual(error.code, BGSRNReportErrorBadArgument);
|
|
269
|
+
XCTAssertEqualObjects(report.fakeSummary, @"old summary");
|
|
270
|
+
XCTAssertEqualObjects(report.mutations, @[]);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/// The system parser's own diagnostic can repeat fragments of the text it
|
|
274
|
+
/// choked on; the message is fixed instead.
|
|
275
|
+
- (void)testMalformedTextIsAFixedMessage {
|
|
276
|
+
NSError *error = nil;
|
|
277
|
+
XCTAssertNil(BGSRNJSONObject(@"{\"a\": \"s3cret", &error));
|
|
278
|
+
XCTAssertEqualObjects(BGSRNErrorMessage(error), @"malformed JSON");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
@end
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
@import XCTest;
|
|
2
|
+
@import BugseeRNSupport;
|
|
3
|
+
|
|
4
|
+
/// Pins `BGSRNLaunchHold`, the WORKAROUND for bugsee-cocoa#227: beta5 drops a
|
|
5
|
+
/// report-creating call made while the SDK is Launching, and `launch()`
|
|
6
|
+
/// resolves before Launched. Calls made then are held and replayed in order
|
|
7
|
+
/// on Launched; a launch that does not complete settles them as dropped.
|
|
8
|
+
/// Every test runs on main, where the hold lives.
|
|
9
|
+
@interface BGSRNLaunchHoldTests : XCTestCase
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
@implementation BGSRNLaunchHoldTests {
|
|
13
|
+
BugseeStatus _status;
|
|
14
|
+
NSMutableArray<NSString *> *_runs;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
- (void)setUp {
|
|
18
|
+
[super setUp];
|
|
19
|
+
_status = BugseeStatusLaunching;
|
|
20
|
+
_runs = [NSMutableArray array];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (BGSRNLaunchHold *)holdWithCapacity:(NSUInteger)capacity deadlineMs:(int64_t)deadlineMs {
|
|
24
|
+
__weak __typeof(self) weakSelf = self;
|
|
25
|
+
return [[BGSRNLaunchHold alloc] initWithCapacity:capacity
|
|
26
|
+
deadlineMs:deadlineMs
|
|
27
|
+
status:^BugseeStatus {
|
|
28
|
+
__typeof(self) strongSelf = weakSelf;
|
|
29
|
+
return strongSelf != nil ? strongSelf->_status : BugseeStatusStopped;
|
|
30
|
+
}];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (BGSRNGatedCall)recorder:(NSString *)name {
|
|
34
|
+
NSMutableArray<NSString *> *runs = _runs;
|
|
35
|
+
return ^(BGSRNGatedRun run) {
|
|
36
|
+
NSString *how = run == BGSRNGatedRunNow ? @"now" : run == BGSRNGatedRunReplay ? @"replay" : @"drop";
|
|
37
|
+
[runs addObject:[NSString stringWithFormat:@"%@:%@", name, how]];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// Lets a main-queue hop or a short deadline run. Pumps the main run loop for
|
|
42
|
+
/// `seconds` and asserts nothing about timing: a starved runner only makes it
|
|
43
|
+
/// return late.
|
|
44
|
+
- (void)spinMain:(NSTimeInterval)seconds {
|
|
45
|
+
NSDate *end = [NSDate dateWithTimeIntervalSinceNow:seconds];
|
|
46
|
+
while (end.timeIntervalSinceNow > 0) {
|
|
47
|
+
if (![NSRunLoop.mainRunLoop runMode:NSDefaultRunLoopMode beforeDate:end]) {
|
|
48
|
+
[NSThread sleepForTimeInterval:0.005];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/// Pumps main until `done` holds. The generous limit (runner main-queue
|
|
54
|
+
/// starvation) is only a backstop; the wait asserts nothing about timing.
|
|
55
|
+
- (void)spinMainUntil:(BOOL (^)(void))done {
|
|
56
|
+
NSDate *limit = [NSDate dateWithTimeIntervalSinceNow:30];
|
|
57
|
+
while (!done() && limit.timeIntervalSinceNow > 0) {
|
|
58
|
+
[NSRunLoop.mainRunLoop runMode:NSDefaultRunLoopMode
|
|
59
|
+
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
|
|
60
|
+
}
|
|
61
|
+
XCTAssertTrue(done(), @"main never reached the expected state");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
- (void)testTheSharedHoldHasTheDocumentedBounds {
|
|
65
|
+
XCTAssertEqual(BGSRNLaunchHoldCapacity, 64u);
|
|
66
|
+
XCTAssertEqual(BGSRNLaunchHoldDeadlineMs, 30000);
|
|
67
|
+
XCTAssertNotNil(BGSRNLaunchHold.shared);
|
|
68
|
+
XCTAssertEqual(BGSRNLaunchHold.shared, BGSRNLaunchHold.shared);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
- (void)testACallWhileLaunchingIsHeldNotRun {
|
|
72
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:8 deadlineMs:0];
|
|
73
|
+
[hold submit:@"a" call:[self recorder:@"a"]];
|
|
74
|
+
XCTAssertEqualObjects(_runs, @[]);
|
|
75
|
+
XCTAssertEqual(hold.heldCount, 1u);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
- (void)testLaunchedReplaysHeldCallsInOrder {
|
|
79
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:8 deadlineMs:0];
|
|
80
|
+
[hold submit:@"a" call:[self recorder:@"a"]];
|
|
81
|
+
[hold submit:@"b" call:[self recorder:@"b"]];
|
|
82
|
+
[hold submit:@"c" call:[self recorder:@"c"]];
|
|
83
|
+
_status = BugseeStatusLaunched;
|
|
84
|
+
[hold lifecycleEvent:@"com.bugsee.lifecycle.Launched"];
|
|
85
|
+
NSArray *expected = @[ @"a:replay", @"b:replay", @"c:replay" ];
|
|
86
|
+
XCTAssertEqualObjects(_runs, expected);
|
|
87
|
+
XCTAssertEqual(hold.heldCount, 0u);
|
|
88
|
+
// Once only: a second Launched has nothing left to replay.
|
|
89
|
+
[hold lifecycleEvent:@"com.bugsee.lifecycle.Launched"];
|
|
90
|
+
XCTAssertEqualObjects(_runs, expected);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// The SDK delivers the event on its own queue; the hold hops to main.
|
|
94
|
+
- (void)testLaunchedFromAnotherThreadReplaysOnMain {
|
|
95
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:8 deadlineMs:0];
|
|
96
|
+
__block BOOL onMain = NO;
|
|
97
|
+
[hold submit:@"a" call:^(BGSRNGatedRun run) {
|
|
98
|
+
onMain = NSThread.isMainThread;
|
|
99
|
+
}];
|
|
100
|
+
_status = BugseeStatusLaunched;
|
|
101
|
+
dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
|
|
102
|
+
[hold lifecycleEvent:@"com.bugsee.lifecycle.Launched"];
|
|
103
|
+
});
|
|
104
|
+
[self spinMain:0.2];
|
|
105
|
+
XCTAssertTrue(onMain);
|
|
106
|
+
XCTAssertEqual(hold.heldCount, 0u);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/// Launched can be visible before its event arrives: a new call then runs
|
|
110
|
+
/// after the held ones, never ahead of them.
|
|
111
|
+
- (void)testACallAfterLaunchedRunsBehindTheHeldOnes {
|
|
112
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:8 deadlineMs:0];
|
|
113
|
+
[hold submit:@"a" call:[self recorder:@"a"]];
|
|
114
|
+
_status = BugseeStatusLaunched;
|
|
115
|
+
[hold submit:@"b" call:[self recorder:@"b"]];
|
|
116
|
+
XCTAssertEqualObjects(_runs, (@[ @"a:replay", @"b:now" ]));
|
|
117
|
+
XCTAssertEqual(hold.heldCount, 0u);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/// Unchanged behaviour: with nothing held, a call runs at once whatever the
|
|
121
|
+
/// status -- after Launched, and before launch() (where the SDK drops it).
|
|
122
|
+
- (void)testNothingIsHeldOutsideLaunching {
|
|
123
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:8 deadlineMs:0];
|
|
124
|
+
_status = BugseeStatusLaunched;
|
|
125
|
+
[hold submit:@"a" call:[self recorder:@"a"]];
|
|
126
|
+
_status = BugseeStatusStopped;
|
|
127
|
+
[hold submit:@"b" call:[self recorder:@"b"]];
|
|
128
|
+
_status = BugseeStatusStopping;
|
|
129
|
+
[hold submit:@"c" call:[self recorder:@"c"]];
|
|
130
|
+
XCTAssertEqualObjects(_runs, (@[ @"a:now", @"b:now", @"c:now" ]));
|
|
131
|
+
XCTAssertEqual(hold.heldCount, 0u);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
- (void)testTheCapDropsTheCallThatWouldExceedIt {
|
|
135
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:2 deadlineMs:0];
|
|
136
|
+
[hold submit:@"a" call:[self recorder:@"a"]];
|
|
137
|
+
[hold submit:@"b" call:[self recorder:@"b"]];
|
|
138
|
+
[hold submit:@"c" call:[self recorder:@"c"]];
|
|
139
|
+
XCTAssertEqualObjects(_runs, @[ @"c:drop" ]);
|
|
140
|
+
XCTAssertEqual(hold.heldCount, 2u);
|
|
141
|
+
_status = BugseeStatusLaunched;
|
|
142
|
+
[hold lifecycleEvent:@"com.bugsee.lifecycle.Launched"];
|
|
143
|
+
XCTAssertEqualObjects(_runs, (@[ @"c:drop", @"a:replay", @"b:replay" ]));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// A stop overtaking the launch: the SDK never reaches Launched, so the held
|
|
147
|
+
/// calls settle as dropped calls do, and are not replayed later.
|
|
148
|
+
- (void)testAStopDropsTheHeldCalls {
|
|
149
|
+
for (NSString *event in @[ @"com.bugsee.lifecycle.Stopping", @"com.bugsee.lifecycle.Stopped" ]) {
|
|
150
|
+
[_runs removeAllObjects];
|
|
151
|
+
_status = BugseeStatusLaunching;
|
|
152
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:8 deadlineMs:0];
|
|
153
|
+
[hold submit:@"a" call:[self recorder:@"a"]];
|
|
154
|
+
[hold submit:@"b" call:[self recorder:@"b"]];
|
|
155
|
+
_status = [event hasSuffix:@"Stopping"] ? BugseeStatusStopping : BugseeStatusStopped;
|
|
156
|
+
[hold lifecycleEvent:event];
|
|
157
|
+
XCTAssertEqualObjects(_runs, (@[ @"a:drop", @"b:drop" ]), @"%@", event);
|
|
158
|
+
XCTAssertEqual(hold.heldCount, 0u);
|
|
159
|
+
_status = BugseeStatusLaunched;
|
|
160
|
+
[hold lifecycleEvent:@"com.bugsee.lifecycle.Launched"];
|
|
161
|
+
XCTAssertEqualObjects(_runs, (@[ @"a:drop", @"b:drop" ]), @"%@", event);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/// A Launched from an earlier launch, arriving after a stop and a relaunch,
|
|
166
|
+
/// must not release the new launch's calls, and unrelated events do nothing.
|
|
167
|
+
- (void)testOnlyALaunchedStatusReleases {
|
|
168
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:8 deadlineMs:0];
|
|
169
|
+
[hold submit:@"a" call:[self recorder:@"a"]];
|
|
170
|
+
[hold lifecycleEvent:@"com.bugsee.lifecycle.Launched"];
|
|
171
|
+
[hold lifecycleEvent:@"com.bugsee.lifecycle.BlackoutStarted"];
|
|
172
|
+
[hold lifecycleEvent:@"com.bugsee.lifecycle.Launching"];
|
|
173
|
+
XCTAssertEqualObjects(_runs, @[]);
|
|
174
|
+
XCTAssertEqual(hold.heldCount, 1u);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/// A launch that never completes: the deadline settles the held calls as
|
|
178
|
+
/// dropped, so no promise stays pending for good.
|
|
179
|
+
- (void)testTheDeadlineDropsCallsStillHeld {
|
|
180
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:8 deadlineMs:50];
|
|
181
|
+
[hold submit:@"a" call:[self recorder:@"a"]];
|
|
182
|
+
[hold submit:@"b" call:[self recorder:@"b"]];
|
|
183
|
+
[self spinMain:0.3];
|
|
184
|
+
XCTAssertEqualObjects(_runs, (@[ @"a:drop", @"b:drop" ]));
|
|
185
|
+
XCTAssertEqual(hold.heldCount, 0u);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/// A deadline armed for a batch that Launched already released does nothing
|
|
189
|
+
/// to the next batch, which gets its own.
|
|
190
|
+
///
|
|
191
|
+
/// No wall-clock race: the "b is still held" check runs inside a main-queue
|
|
192
|
+
/// block due BETWEEN a's stale timer and b's own, so it runs after the former
|
|
193
|
+
/// and before the latter whatever the runner does (timers fire in due order).
|
|
194
|
+
/// With D = 2 s, t = seconds after a was submitted:
|
|
195
|
+
/// a's stale timer due t=2.0 < the check due t=2.5 < b's timer due >= t=3.0
|
|
196
|
+
/// (b is submitted no earlier than t=1.0, and its deadline is D after that).
|
|
197
|
+
- (void)testAnOldDeadlineDoesNotTouchALaterBatch {
|
|
198
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:8 deadlineMs:2000];
|
|
199
|
+
[hold submit:@"a" call:[self recorder:@"a"]];
|
|
200
|
+
_status = BugseeStatusLaunched;
|
|
201
|
+
[hold lifecycleEvent:@"com.bugsee.lifecycle.Launched"];
|
|
202
|
+
_status = BugseeStatusLaunching;
|
|
203
|
+
__block BOOL checked = NO;
|
|
204
|
+
__weak __typeof(self) weakSelf = self;
|
|
205
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
206
|
+
__typeof(self) strongSelf = weakSelf;
|
|
207
|
+
// a's stale timer has run; b's has not.
|
|
208
|
+
XCTAssertEqualObjects(strongSelf->_runs, @[ @"a:replay" ]);
|
|
209
|
+
XCTAssertEqual(hold.heldCount, 1u);
|
|
210
|
+
checked = YES;
|
|
211
|
+
});
|
|
212
|
+
[self spinMain:1.0];
|
|
213
|
+
[hold submit:@"b" call:[self recorder:@"b"]];
|
|
214
|
+
XCTAssertEqual(hold.heldCount, 1u);
|
|
215
|
+
[self spinMainUntil:^BOOL {
|
|
216
|
+
return checked && hold.heldCount == 0;
|
|
217
|
+
}];
|
|
218
|
+
XCTAssertEqualObjects(_runs, (@[ @"a:replay", @"b:drop" ]));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/// At the deadline the status decides: Launched (its event lost) replays.
|
|
222
|
+
- (void)testTheDeadlineReplaysWhenTheSDKIsLaunched {
|
|
223
|
+
BGSRNLaunchHold *hold = [self holdWithCapacity:8 deadlineMs:50];
|
|
224
|
+
[hold submit:@"a" call:[self recorder:@"a"]];
|
|
225
|
+
_status = BugseeStatusLaunched;
|
|
226
|
+
[self spinMain:0.3];
|
|
227
|
+
XCTAssertEqualObjects(_runs, @[ @"a:replay" ]);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
@end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
@import XCTest;
|
|
2
|
+
@import BugseeRNSupport;
|
|
3
|
+
|
|
4
|
+
@interface BGSRNMainThreadTests : XCTestCase
|
|
5
|
+
@end
|
|
6
|
+
|
|
7
|
+
@implementation BGSRNMainThreadTests
|
|
8
|
+
|
|
9
|
+
/// The property that matters: whatever thread the caller is on, the block runs
|
|
10
|
+
/// on the main one. Without the hop, an off-main caller's block runs off-main
|
|
11
|
+
/// and the SDK touches UIKit from a background queue.
|
|
12
|
+
- (void)testRunsOnMainWhenCalledFromABackgroundQueue {
|
|
13
|
+
XCTestExpectation *ran = [self expectationWithDescription:@"block ran"];
|
|
14
|
+
__block BOOL onMain = NO;
|
|
15
|
+
|
|
16
|
+
dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
|
|
17
|
+
XCTAssertFalse([NSThread isMainThread], @"the probe must start off-main");
|
|
18
|
+
BGSRNRunOnMain(^{
|
|
19
|
+
onMain = [NSThread isMainThread];
|
|
20
|
+
[ran fulfill];
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
[self waitForExpectations:@[ ran ] timeout:5];
|
|
25
|
+
XCTAssertTrue(onMain, @"block did not reach the main thread");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// dispatch_sync onto the main queue from the main thread is a hard deadlock.
|
|
29
|
+
/// If this test ever hangs rather than fails, the implementation went back to
|
|
30
|
+
/// dispatch_sync.
|
|
31
|
+
- (void)testDoesNotDeadlockWhenAlreadyOnMain {
|
|
32
|
+
XCTAssertTrue([NSThread isMainThread], @"XCTest runs -test methods on main");
|
|
33
|
+
|
|
34
|
+
__block BOOL ran = NO;
|
|
35
|
+
BGSRNRunOnMain(^{
|
|
36
|
+
ran = YES;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Synchronously true: the already-on-main path must run the block inline
|
|
40
|
+
// rather than deferring it, or a caller that reads state straight after the
|
|
41
|
+
// call sees it unset.
|
|
42
|
+
XCTAssertTrue(ran, @"block was deferred instead of run inline");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
- (void)testRunsTheBlockExactlyOnce {
|
|
46
|
+
__block NSInteger count = 0;
|
|
47
|
+
BGSRNRunOnMain(^{
|
|
48
|
+
count += 1;
|
|
49
|
+
});
|
|
50
|
+
XCTAssertEqual(count, 1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)testToleratesANilBlock {
|
|
54
|
+
XCTAssertNoThrow(BGSRNRunOnMain(nil));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// The init registration must not return until `+[Bugsee setWrapper:]` has
|
|
58
|
+
/// run. Off main that means the hop waits; an async queue leaves a race with
|
|
59
|
+
/// a later main-thread `startBlackout`.
|
|
60
|
+
- (void)testSyncWaitsForBlockWhenCalledOffMain {
|
|
61
|
+
XCTestExpectation *done = [self expectationWithDescription:@"off-main call returned"];
|
|
62
|
+
|
|
63
|
+
dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
|
|
64
|
+
XCTAssertFalse([NSThread isMainThread], @"the probe must start off-main");
|
|
65
|
+
|
|
66
|
+
__block BOOL finished = NO;
|
|
67
|
+
BGSRNRunOnMainSync(^{
|
|
68
|
+
// A real main-queue turn so an async hop cannot finish the block before
|
|
69
|
+
// the caller checks `finished` by accident of scheduling luck.
|
|
70
|
+
XCTAssertTrue([NSThread isMainThread]);
|
|
71
|
+
finished = YES;
|
|
72
|
+
});
|
|
73
|
+
XCTAssertTrue(finished,
|
|
74
|
+
@"BGSRNRunOnMainSync returned before the block finished; "
|
|
75
|
+
@"off-main registration would still be pending");
|
|
76
|
+
[done fulfill];
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
[self waitForExpectations:@[ done ] timeout:5];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// Same deadlock rule as BGSRNRunOnMain: sync onto main from main hangs.
|
|
83
|
+
- (void)testSyncDoesNotDeadlockWhenAlreadyOnMain {
|
|
84
|
+
XCTAssertTrue([NSThread isMainThread], @"XCTest runs -test methods on main");
|
|
85
|
+
|
|
86
|
+
__block BOOL ran = NO;
|
|
87
|
+
BGSRNRunOnMainSync(^{
|
|
88
|
+
ran = YES;
|
|
89
|
+
});
|
|
90
|
+
XCTAssertTrue(ran, @"block was deferred instead of run inline");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
- (void)testSyncToleratesANilBlock {
|
|
94
|
+
XCTAssertNoThrow(BGSRNRunOnMainSync(nil));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@end
|