|
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,86 @@ 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 signature = typeof(ExperimentController).GetMethod( |
| 147 | + nameof(ExperimentController.ValidateRunningExperiments), |
| 148 | + BindingFlags.Instance | BindingFlags.Public, |
| 149 | + binder: null, |
| 150 | + types: new[] { typeof(string), typeof(ExperimentPayload[]) }, |
| 151 | + modifiers: null); |
| 152 | + if (signature is null) |
| 153 | + { |
| 154 | + throw new InvalidOperationException( |
| 155 | + $"Expected managed API '{nameof(ExperimentController.ValidateRunningExperiments)}(string, {typeof(ExperimentPayload[]).FullName})' was not found."); |
| 156 | + } |
| 157 | + |
| 158 | + var parameters = signature.GetParameters(); |
| 159 | + if (parameters.Length != 2 || parameters[1].ParameterType != typeof(ExperimentPayload[])) |
| 160 | + { |
| 161 | + throw new InvalidOperationException( |
| 162 | + $"Managed signature regression: expected payload parameter type '{typeof(ExperimentPayload[]).FullName}', observed '{parameters.ElementAtOrDefault(1)?.ParameterType.FullName ?? "<missing>"}'."); |
| 163 | + } |
| 164 | + |
| 165 | + var payloads = Array.Empty<ExperimentPayload>(); |
| 166 | + var origin = "codex"; |
| 167 | + NSException? marshaledException = null; |
| 168 | + MarshalObjectiveCExceptionMode? marshaledExceptionMode = null; |
| 169 | + |
| 170 | + void OnMarshalObjectiveCException(object? sender, MarshalObjectiveCExceptionEventArgs args) |
| 171 | + { |
| 172 | + marshaledException ??= args.Exception; |
| 173 | + marshaledExceptionMode ??= args.ExceptionMode; |
| 174 | + } |
| 175 | + |
| 176 | + Runtime.MarshalObjectiveCException += OnMarshalObjectiveCException; |
| 177 | + try |
| 178 | + { |
| 179 | + try |
| 180 | + { |
| 181 | + controller.ValidateRunningExperiments(origin, payloads); |
| 182 | + } |
| 183 | + catch (ObjCException ex) |
| 184 | + { |
| 185 | + throw new InvalidOperationException( |
| 186 | + $"Selector '{selector}' should not throw after the binding fix, but observed {ex.GetType().FullName}. " + |
| 187 | + $"Managed payload array type: {payloads.GetType().FullName}. Payload count: {payloads.Length}. " + |
| 188 | + $"Origin argument type: {origin.GetType().FullName}. " + |
| 189 | + $"NSException.Name: {FormatDetail(marshaledException?.Name?.ToString())}. " + |
| 190 | + $"NSException.Reason: {FormatDetail(marshaledException?.Reason)}. " + |
| 191 | + $"Marshal mode: {FormatDetail(marshaledExceptionMode?.ToString())}.", |
| 192 | + ex); |
| 193 | + } |
| 194 | + |
| 195 | + if (marshaledException is not null) |
| 196 | + { |
| 197 | + throw new InvalidOperationException( |
| 198 | + $"Selector '{selector}' completed, but Runtime.MarshalObjectiveCException captured unexpected NSException.Name '{marshaledException.Name}'. " + |
| 199 | + $"Reason: {FormatDetail(marshaledException.Reason)}. Marshal mode: {FormatDetail(marshaledExceptionMode?.ToString())}."); |
| 200 | + } |
| 201 | + |
| 202 | + return Task.FromResult( |
| 203 | + $"Selector '{selector}' completed without ObjC exception after the binding fix. " + |
| 204 | + $"Managed signature payload type: {parameters[1].ParameterType.FullName}. " + |
| 205 | + $"Managed payload array type: {payloads.GetType().FullName}. Payload count: {payloads.Length}. " + |
| 206 | + $"Origin argument type: {origin.GetType().FullName}."); |
| 207 | + } |
| 208 | + finally |
| 209 | + { |
| 210 | + Runtime.MarshalObjectiveCException -= OnMarshalObjectiveCException; |
| 211 | + } |
| 212 | + } |
| 213 | +#endif |
| 214 | + |
129 | 215 | #if ENABLE_RUNTIME_DRIFT_CASE_CLOUDFIRESTORE_GETQUERYNAMED |
130 | 216 | static async Task<string> VerifyCloudFirestoreGetQueryNamedAsync() |
131 | 217 | { |
|
0 commit comments