|
6 | 6 | using ObjCRuntime; |
7 | 7 | #endif |
8 | 8 |
|
| 9 | +#if ENABLE_RUNTIME_DRIFT_CASE_ABTESTING_VALIDATERUNNINGEXPERIMENTS |
| 10 | +using Firebase.ABTesting; |
| 11 | +using Foundation; |
| 12 | +using ObjCRuntime; |
| 13 | +#endif |
| 14 | + |
9 | 15 | #if ENABLE_RUNTIME_DRIFT_CASE_CLOUDFIRESTORE_GETQUERYNAMED |
10 | 16 | using Firebase.CloudFirestore; |
11 | 17 | using Foundation; |
@@ -126,6 +132,66 @@ void OnMarshalObjectiveCException(object? sender, MarshalObjectiveCExceptionEven |
126 | 132 | } |
127 | 133 | #endif |
128 | 134 |
|
| 135 | +#if ENABLE_RUNTIME_DRIFT_CASE_ABTESTING_VALIDATERUNNINGEXPERIMENTS |
| 136 | + static Task<string> VerifyABTestingValidateRunningExperimentsAsync() |
| 137 | + { |
| 138 | + const string selector = "validateRunningExperimentsForServiceOrigin:runningExperimentPayloads:"; |
| 139 | + |
| 140 | + var controller = ExperimentController.SharedInstance; |
| 141 | + if (controller is null) |
| 142 | + { |
| 143 | + throw new InvalidOperationException("Firebase.ABTesting.ExperimentController.SharedInstance returned null after App.Configure()."); |
| 144 | + } |
| 145 | + |
| 146 | + var payloads = Array.Empty<ExperimentPayload>(); |
| 147 | + var origin = "codex"; |
| 148 | + NSException? marshaledException = null; |
| 149 | + MarshalObjectiveCExceptionMode? marshaledExceptionMode = null; |
| 150 | + |
| 151 | + void OnMarshalObjectiveCException(object? sender, MarshalObjectiveCExceptionEventArgs args) |
| 152 | + { |
| 153 | + marshaledException ??= args.Exception; |
| 154 | + marshaledExceptionMode ??= args.ExceptionMode; |
| 155 | + } |
| 156 | + |
| 157 | + Runtime.MarshalObjectiveCException += OnMarshalObjectiveCException; |
| 158 | + try |
| 159 | + { |
| 160 | + try |
| 161 | + { |
| 162 | + controller.ValidateRunningExperiments(origin, payloads); |
| 163 | + } |
| 164 | + catch (ObjCException ex) |
| 165 | + { |
| 166 | + throw new InvalidOperationException( |
| 167 | + $"Selector '{selector}' should not throw after the binding fix, but observed {ex.GetType().FullName}. " + |
| 168 | + $"Managed payload array type: {payloads.GetType().FullName}. Payload count: {payloads.Length}. " + |
| 169 | + $"Origin argument type: {origin.GetType().FullName}. " + |
| 170 | + $"NSException.Name: {FormatDetail(marshaledException?.Name?.ToString())}. " + |
| 171 | + $"NSException.Reason: {FormatDetail(marshaledException?.Reason)}. " + |
| 172 | + $"Marshal mode: {FormatDetail(marshaledExceptionMode?.ToString())}.", |
| 173 | + ex); |
| 174 | + } |
| 175 | + |
| 176 | + if (marshaledException is not null) |
| 177 | + { |
| 178 | + throw new InvalidOperationException( |
| 179 | + $"Selector '{selector}' completed, but Runtime.MarshalObjectiveCException captured unexpected NSException.Name '{marshaledException.Name}'. " + |
| 180 | + $"Reason: {FormatDetail(marshaledException.Reason)}. Marshal mode: {FormatDetail(marshaledExceptionMode?.ToString())}."); |
| 181 | + } |
| 182 | + |
| 183 | + return Task.FromResult( |
| 184 | + $"Selector '{selector}' completed without ObjC exception after the binding fix. " + |
| 185 | + $"Managed payload array type: {payloads.GetType().FullName}. Payload count: {payloads.Length}. " + |
| 186 | + $"Origin argument type: {origin.GetType().FullName}."); |
| 187 | + } |
| 188 | + finally |
| 189 | + { |
| 190 | + Runtime.MarshalObjectiveCException -= OnMarshalObjectiveCException; |
| 191 | + } |
| 192 | + } |
| 193 | +#endif |
| 194 | + |
129 | 195 | #if ENABLE_RUNTIME_DRIFT_CASE_CLOUDFIRESTORE_GETQUERYNAMED |
130 | 196 | static async Task<string> VerifyCloudFirestoreGetQueryNamedAsync() |
131 | 197 | { |
|
0 commit comments