|
1 | 1 | using System.Reflection; |
2 | 2 |
|
| 3 | +#if ENABLE_RUNTIME_DRIFT_CASE_ABTESTING_ACTIVATEEXPERIMENT |
| 4 | +using Firebase.ABTesting; |
| 5 | +using Foundation; |
| 6 | +using ObjCRuntime; |
| 7 | +#endif |
| 8 | + |
3 | 9 | #if ENABLE_RUNTIME_DRIFT_CASE_CLOUDFIRESTORE_GETQUERYNAMED |
4 | 10 | using Firebase.CloudFirestore; |
5 | 11 | using Foundation; |
@@ -60,6 +66,66 @@ public static async Task<string> ExecuteConfiguredCaseAsync() |
60 | 66 | ?.Value; |
61 | 67 | } |
62 | 68 |
|
| 69 | +#if ENABLE_RUNTIME_DRIFT_CASE_ABTESTING_ACTIVATEEXPERIMENT |
| 70 | + static Task<string> VerifyABTestingActivateExperimentAsync() |
| 71 | + { |
| 72 | + const string selector = "activateExperiment:forServiceOrigin:"; |
| 73 | + |
| 74 | + var controller = ExperimentController.SharedInstance; |
| 75 | + if (controller is null) |
| 76 | + { |
| 77 | + throw new InvalidOperationException("Firebase.ABTesting.ExperimentController.SharedInstance returned null after App.Configure()."); |
| 78 | + } |
| 79 | + |
| 80 | + var payload = new ExperimentPayload(); |
| 81 | + var origin = "codex"; |
| 82 | + NSException? marshaledException = null; |
| 83 | + MarshalObjectiveCExceptionMode? marshaledExceptionMode = null; |
| 84 | + |
| 85 | + void OnMarshalObjectiveCException(object? sender, MarshalObjectiveCExceptionEventArgs args) |
| 86 | + { |
| 87 | + marshaledException ??= args.Exception; |
| 88 | + marshaledExceptionMode ??= args.ExceptionMode; |
| 89 | + } |
| 90 | + |
| 91 | + Runtime.MarshalObjectiveCException += OnMarshalObjectiveCException; |
| 92 | + try |
| 93 | + { |
| 94 | + try |
| 95 | + { |
| 96 | + controller.ActivateExperiment(payload, origin); |
| 97 | + } |
| 98 | + catch (ObjCException ex) |
| 99 | + { |
| 100 | + throw new InvalidOperationException( |
| 101 | + $"Selector '{selector}' should not throw after the binding fix, but observed {ex.GetType().FullName}. " + |
| 102 | + $"Managed payload type: {payload.GetType().FullName}. " + |
| 103 | + $"Origin argument type: {origin.GetType().FullName}. " + |
| 104 | + $"NSException.Name: {FormatDetail(marshaledException?.Name?.ToString())}. " + |
| 105 | + $"NSException.Reason: {FormatDetail(marshaledException?.Reason)}. " + |
| 106 | + $"Marshal mode: {FormatDetail(marshaledExceptionMode?.ToString())}.", |
| 107 | + ex); |
| 108 | + } |
| 109 | + |
| 110 | + if (marshaledException is not null) |
| 111 | + { |
| 112 | + throw new InvalidOperationException( |
| 113 | + $"Selector '{selector}' completed, but Runtime.MarshalObjectiveCException captured unexpected NSException.Name '{marshaledException.Name}'. " + |
| 114 | + $"Reason: {FormatDetail(marshaledException.Reason)}. Marshal mode: {FormatDetail(marshaledExceptionMode?.ToString())}."); |
| 115 | + } |
| 116 | + |
| 117 | + return Task.FromResult( |
| 118 | + $"Selector '{selector}' completed without ObjC exception after the binding fix. " + |
| 119 | + $"Managed payload type: {payload.GetType().FullName}. " + |
| 120 | + $"Origin argument type: {origin.GetType().FullName}."); |
| 121 | + } |
| 122 | + finally |
| 123 | + { |
| 124 | + Runtime.MarshalObjectiveCException -= OnMarshalObjectiveCException; |
| 125 | + } |
| 126 | + } |
| 127 | +#endif |
| 128 | + |
63 | 129 | #if ENABLE_RUNTIME_DRIFT_CASE_CLOUDFIRESTORE_GETQUERYNAMED |
64 | 130 | static async Task<string> VerifyCloudFirestoreGetQueryNamedAsync() |
65 | 131 | { |
|
0 commit comments