public override bool Matches(object expected, object actual, MatchingContext context, Action <object, object, MatchingContext> deepMatch) { var expectedQuery = expected?.ToString()?.Trim()?.TrimStart('?')?.TrimEnd('&'); var actualQuery = actual?.ToString()?.Trim()?.TrimStart('?')?.TrimEnd('&'); if (string.IsNullOrEmpty(expectedQuery) && string.IsNullOrEmpty(actualQuery)) { return(true); } if (string.IsNullOrEmpty(expectedQuery) || string.IsNullOrEmpty(actualQuery)) { return(false); } var expectedValues = HttpUtility.ParseQueryString(expectedQuery); var actualValues = HttpUtility.ParseQueryString(actualQuery); if (expectedValues.AllKeys.Except(actualValues.AllKeys).Any() || actualValues.AllKeys.Except(expectedValues.AllKeys).Any()) { return(false); } return(expectedValues.AllKeys.All(k => expectedValues.Get(k).Equals(actualValues.Get(k)))); }
public override bool Matches(object expected, object actual, MatchingContext context, Action <object, object, MatchingContext> deepMatch) { var expectedValue = expected?.ToString()?.Trim(); var actualValue = actual?.ToString()?.Trim(); if (!string.IsNullOrEmpty(expectedValue) && !string.IsNullOrEmpty(actualValue) && expectedValue.Contains(",") && actualValue.Contains(",")) { context.Terminate(); var expectedValues = expectedValue.Split(',').Select(v => v.Trim()).ToArray(); var actualValues = actualValue.Split(',').Select(v => v.Trim()).ToArray(); if (expectedValues.Length != actualValues.Length) { return(false); } for (int i = 0; i < expectedValues.Length; i++) { if (expectedValues[i] != actualValues[i]) { return(false); } } } else if (expected?.ToString() != actual?.ToString()) { return(false); } return(true); }
private void notifySignalingCallback(int ctxId) { MatchingContext context = contextMap[ctxId]; if (context == null || !context.Started || signalingCallbackFunction == 0) { return; } pspBaseCallback signalingCallback = Modules.ThreadManForUserModule.hleKernelCreateCallback(signalingCallbackFunction, 8); if (Modules.ThreadManForUserModule.hleKernelRegisterCallback(THREAD_CALLBACK_USER_DEFINED, signalingCallback)) { long roomId = 0x123456789ABCDEF0L; int peerMemberId = 0x1111; int @event = 0x5101; // 0x5101 - 0x5106 int errorCode = 0; signalingCallback.setArgument(0, ctxId); signalingCallback.setArgument(2, (int)roomId); signalingCallback.setArgument(3, (int)((long)((ulong)roomId >> 32))); signalingCallback.setArgument(4, peerMemberId); signalingCallback.setArgument(5, @event); signalingCallback.setArgument(6, errorCode); signalingCallback.setArgument(7, signalingCallbackArgument); Modules.ThreadManForUserModule.hleKernelNotifyCallback(THREAD_CALLBACK_USER_DEFINED, signalingCallback); } }
private void notifyRoomEventCallback(int ctxId) { MatchingContext context = contextMap[ctxId]; if (context == null || !context.Started || defaultRoomEventCallbackFunction == 0) { return; } pspBaseCallback roomEventCallback = Modules.ThreadManForUserModule.hleKernelCreateCallback(defaultRoomEventCallbackFunction, 7); if (Modules.ThreadManForUserModule.hleKernelRegisterCallback(THREAD_CALLBACK_USER_DEFINED, roomEventCallback)) { long roomId = 0x123456789ABCDEF0L; int @event = 0x1101; // 0x1101 - 0x1109 int errorCode = 0; roomEventCallback.setArgument(0, ctxId); roomEventCallback.setArgument(2, (int)roomId); roomEventCallback.setArgument(3, (int)((long)((ulong)roomId >> 32))); roomEventCallback.setArgument(4, @event); roomEventCallback.setArgument(5, errorCode); roomEventCallback.setArgument(6, defaultRoomEventCallbackArgument); Modules.ThreadManForUserModule.hleKernelNotifyCallback(THREAD_CALLBACK_USER_DEFINED, roomEventCallback); } }
public virtual int sceNpMatching2CreateContext(TPointer communicationId, TPointer passPhrase, TPointer16 ctxId, int unknown) { //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceNpMatching2CreateContext communicationId={0}, passPhrase={1}", Utilities.getMemoryDump(communicationId.Address, 12), Utilities.getMemoryDump(passPhrase.Address, 128))); } // Returning a ctxId in range [1..7] int uid = SceUidManager.getNewId(idContextPurpose, 1, 7); if (uid == SceUidManager.INVALID_ID) { return(-1); } contextMap[uid] = new MatchingContext(); //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceNpMatching2CreateContext returning 0x{0:X}", uid)); } ctxId.Value = uid; return(0); }
public override bool Matches(object expected, object actual, MatchingContext context, Action <object, object, MatchingContext> deepMatch) { var expectedMethod = expected?.ToString() ?? ""; var actualMethod = actual?.ToString() ?? ""; return(actualMethod.Equals(expectedMethod, StringComparison.InvariantCultureIgnoreCase)); }
private WithMatcher GetAnyWatcher <T>() { using (var context = new MatchingContext()) { With.Any <T>(); return(context.LastMatcher); } }
internal bool Matches(object request, ITransportMatchers transportMatchers) { var context = new MatchingContext(transportMatchers.RequestMatchers.Concat(requestMatchers).ToArray(), true); var checker = new MatchChecker(); checker.Matches(this.request, request, context); return(context.Result.Matches); }
public override bool Matches(object expected, object actual, MatchingContext context, Action <object, object, MatchingContext> deepMatch) { if (ReferenceEquals(actual, null)) { return(false); } return(regex.IsMatch(actual.ToString())); }
private bool HasCatchAllItemsMatcherForAnythingBelow(MatchingContext context) { var catchAllItems = new List <IPropertyPathPart>(context.PropertyPath) { new ArrayIndexPathPart("*", exact: true) }; return(context.Matchers.Any(m => StartsWith(m.PropertyPathParts, catchAllItems))); }
public override bool Matches(object expected, object actual, MatchingContext context, Action <object, object, MatchingContext> deepMatch) { if (HasCatchAllItemsMatcherForAnythingBelow(context)) { return(true); } return(((JToken[])expected).Length >= ((JToken[])actual).Length); }
public override bool AppliesTo(object expected, object actual, MatchingContext context) { if (!base.AppliesTo(expected, actual, context)) { return(false); } return(!context.IgnoreExpected && expected is JToken[] && actual is JToken[]); }
public override bool Matches(object expected, object actual, MatchingContext context, Action <object, object, MatchingContext> deepMatch) { var actualBody = (JObject)actual; foreach (var property in actualBody.Properties()) { deepMatch(null, property.Value, context.For(new PropertyPathPart(property.Name))); } return(true); }
public override bool Matches(object expected, object actual, MatchingContext context, Action <object, object, MatchingContext> deepMatch) { if (expected.GetType() != actual.GetType()) { return(false); } var count = Count(actual, true); return(!count.HasValue || count.Value <= max); }
public virtual int sceNpMatching2ContextStop(int ctxId) { MatchingContext context = contextMap[ctxId]; if (context == null) { return(-1); } context.Started = false; return(0); }
private void notifyRoomMessageCallback(int ctxId) { MatchingContext context = contextMap[ctxId]; if (context == null || !context.Started || defaultRoomMessageCallbackFunction == 0) { return; } pspBaseCallback roomMessageCallback = Modules.ThreadManForUserModule.hleKernelCreateCallback(defaultRoomMessageCallbackFunction, 8); if (Modules.ThreadManForUserModule.hleKernelRegisterCallback(THREAD_CALLBACK_USER_DEFINED, roomMessageCallback)) { if (dataBuffer == null) { dataBuffer = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.KERNEL_PARTITION_ID, "sceNpMatching2-DataBuffer", SysMemUserForUser.PSP_SMEM_Low, 128, 0); //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceNpMatching2.notifyRoomMessageCallback allocated dataBuffer {0}", dataBuffer)); } } Memory mem = Emulator.Memory; mem.memset(dataBuffer.addr, (sbyte)0, dataBuffer.size); long roomId = 0x123456789ABCDEF0L; int srcMemberId = 0x1111; int @event = 0x2101; // 0x2101, 0x2102 int data = dataBuffer.addr; string dummyString = "Hello, world!"; int stringData = data + 24; mem.write32(data + 12, stringData); mem.write32(data + 16, dummyString.Length); mem.write32(data + 20, 1); // Seems to be a flag having value 0 or 1 Utilities.writeStringZ(mem, stringData, dummyString); roomMessageCallback.setArgument(0, ctxId); roomMessageCallback.setArgument(2, (int)roomId); roomMessageCallback.setArgument(3, (int)((long)((ulong)roomId >> 32))); roomMessageCallback.setArgument(4, srcMemberId); roomMessageCallback.setArgument(5, @event); roomMessageCallback.setArgument(6, data); roomMessageCallback.setArgument(7, defaultRoomMessageCallbackArgument); Modules.ThreadManForUserModule.hleKernelNotifyCallback(THREAD_CALLBACK_USER_DEFINED, roomMessageCallback); } }
public override bool Matches(object expected, object actual, MatchingContext context, Action <object, object, MatchingContext> deepMatch) { if (expected is JObject expectedObject && actual is JObject actualObject) { foreach (var property in expectedObject.Properties().Concat(actualObject.Properties()).Select(p => p.Name).Distinct().ToArray()) { var expectedProperty = expectedObject.Properties().FirstOrDefault(p => p.Name.Equals(property)); var actualProperty = actualObject.Properties().FirstOrDefault(p => p.Name.Equals(property)); var propertyName = (expectedProperty ?? actualProperty)?.Name ?? property; deepMatch(expectedProperty?.Value, actualProperty?.Value, context.For(new PropertyPathPart(propertyName), null, new TypePropertyMatcher(PropertyPath + "." + propertyName, applyToAll))); } context.Terminate(); return(context.Result.Matches); } return(expected.GetType() == actual.GetType()); }
public virtual int sceNpMatching2ContextStart(int ctxId) { MatchingContext context = contextMap[ctxId]; if (context == null) { return(-1); } context.Started = true; notifyRequestCallback(ctxId); notifySignalingCallback(ctxId); notifyRoomEventCallback(ctxId); notifyRoomMessageCallback(ctxId); return(0); }
public async Task <InteractionVerificationResult> Honour() { if (!string.IsNullOrEmpty(providerState)) { await ensureProviderState(providerState); } var actualResponse = await transport.Respond(request); var context = new MatchingContext(matchers, false); var checker = new MatchChecker(); var roundTrippedResponse = transport.Format.DeserializeResponse(transport.Format.SerializeResponse(actualResponse)); checker.Matches(response, roundTrippedResponse, context); return(new InteractionVerificationResult(description, context.Result.Matches, context.Result.FailureReasons)); }
public object Respond(object request, ITransportMatchers transportMatchers) { var response = responseFactory(request); var expectedResponse = responseFactory(this.request); var context = new MatchingContext(transportMatchers.ResponseMatchers.Concat(responseMatchers).ToArray(), false); var checker = new MatchChecker(); checker.Matches(expectedResponse, response, context); if (!context.Result.Matches) { throw new Exception("Invalid interaction setup - the generated response does not match the expected format: " + context.Result.FailureReasons); } CallCount++; return(response); }
public override bool AppliesTo(object expected, object actual, MatchingContext context) { if (!base.AppliesTo(expected, actual, context)) { return(false); } if (context.IgnoreExpected) { return(false); } if (context.MatchersForProperty.Any(m => m != this)) { return(false); } return(true); }
public void V2Specs(string name, bool isRequest, JObject testCase) { var shouldMatch = (bool)testCase["match"]; var actual = testCase["actual"]; var expected = testCase["expected"]; Assert.Null(actual["matchingRules"]); var rulesJsonProperty = expected["matchingRules"]; var rules = new IMatcher[0]; if (rulesJsonProperty != null) { rules = MatcherParser.Parse(rulesJsonProperty as JObject); ((JObject)expected).Remove("matchingRules"); } var transportMatchers = new PactV2CompliantHttpTransportMatchers(); if (isRequest) { rules = transportMatchers.RequestMatchers.Concat(rules).ToArray(); } else { rules = transportMatchers.ResponseMatchers.Concat(rules).ToArray(); } var context = new MatchingContext(rules, isRequest); var matchChecker = new MatchChecker(); matchChecker.Matches(expected, actual, context); if (shouldMatch) { Assert.True(context.Result.Matches, name + ": " + context.Result.FailureReasons); } else { Assert.False(context.Result.Matches, name + ": did match although it shouldn't"); } }
public override bool Matches(object expected, object actual, MatchingContext context, Action <object, object, MatchingContext> deepMatch) { var e = (JObject)expected ?? new JObject(); var a = (JObject)actual ?? new JObject(); var expectedHeaders = e.Properties().Select(p => p.Name.ToLowerInvariant()).ToArray(); var actualHeaders = a.Properties().Select(p => p.Name.ToLowerInvariant()).ToArray(); foreach (var header in actualHeaders) { var expectedHeader = e.Properties().FirstOrDefault(p => p.Name.Equals(header, StringComparison.InvariantCultureIgnoreCase))?.Value as JValue; var actualHeader = a.Properties().FirstOrDefault(p => p.Name.Equals(header, StringComparison.InvariantCultureIgnoreCase))?.Value as JValue; var childContext = context.For(new PropertyPathPart(header), ignoreExpected: expectedHeader == null); deepMatch(expectedHeader ?? JValue.CreateString(""), actualHeader, childContext); } context.Terminate(); return(!expectedHeaders.Except(actualHeaders).Any()); }
/// <summary> /// Matcheses the specified matching context. /// </summary> /// <param name="matchingContext">The matching context.</param> /// <returns></returns> public Match Matches(MatchingContext matchingContext) { return(new Regex("^" + test + "$", RegexOptions.IgnoreCase).Match(matchingContext.Statement)); }
public abstract bool Matches(object expected, object actual, MatchingContext context, Action <object, object, MatchingContext> deepMatch);
public virtual bool AppliesTo(object expected, object actual, MatchingContext context) { return(true); }
public override bool AppliesTo(object expected, object actual, MatchingContext context) { return(applyToAll || base.AppliesTo(expected, actual, context)); }
private void notifyRequestCallback(int ctxId) { MatchingContext context = contextMap[ctxId]; if (context == null || !context.Started || defaultRequestCallbackFunction == 0) { return; } pspBaseCallback requestCallback = Modules.ThreadManForUserModule.hleKernelCreateCallback(defaultRequestCallbackFunction, 6); if (Modules.ThreadManForUserModule.hleKernelRegisterCallback(THREAD_CALLBACK_USER_DEFINED, requestCallback)) { if (dataBuffer == null) { dataBuffer = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.KERNEL_PARTITION_ID, "sceNpMatching2-DataBuffer", SysMemUserForUser.PSP_SMEM_Low, 128, 0); //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceNpMatching2.notifyRequestCallback allocated dataBuffer {0}", dataBuffer)); } } Memory mem = Emulator.Memory; mem.memset(dataBuffer.addr, (sbyte)0, dataBuffer.size); int reqId = 0x00011111; // Dummy value for debugging int @event = 0x2222; // Dummy value for debugging int data = dataBuffer.addr; int errorCode = 0; // Write unknown values to data buffer for debugging // The reqId contains a special value in the upper 16-bit // which seems to be in range [0..16]. switch ((int)((uint)reqId >> 16)) { case 0: case 6: case 7: case 9: case 10: case 11: case 13: case 16: { // In those cases, the data buffer doesn't seem to be used data = 0; break; } case 1: { mem.write16(data, (short)0x3333); mem.write8(data + 2, (sbyte)0x44); break; } case 2: { int ptr = data + 8; mem.write32(data, ptr); // Pointer to 64 bytes mem.write32(data + 4, 0); mem.write32(ptr, 0); // Pointer to next 64 bytes or NULL for (int i = 4; i < 64; i += 4) { mem.write32(ptr + i, 0x12345600 + i); } break; } case 3: { mem.write32(data + 0, 0x33333333); mem.write32(data + 4, 0x44444444); mem.write32(data + 8, 0x55555555); mem.write32(data + 12, 0x66666666); break; } case 4: case 5: { int ptr = data + 4; mem.write32(data, ptr); // Pointer to 64 bytes mem.write16(ptr, (short)0x3333); for (int i = 4; i < 64; i += 4) { mem.write32(ptr + i, 0x12345600 + i); } int ptr2 = ptr + 64; mem.write32(ptr + 44, ptr2); // Pointer to 58 bytes mem.write16(ptr2 + 56, (short)0x4444); break; } case 8: { mem.write32(data, 1); // Seems to be a flag having value 0 or 1 break; } case 12: case 14: case 15: { // Two 32-bit values (a 64-bit timestamp maybe?) mem.write32(data + 0, 0x12345678); mem.write32(data + 4, unchecked ((int)0x9ABCDEF0)); break; } } requestCallback.setArgument(0, ctxId); requestCallback.setArgument(1, reqId); requestCallback.setArgument(2, @event); requestCallback.setArgument(3, errorCode); requestCallback.setArgument(4, data); requestCallback.setArgument(5, defaultRequestCallbackArgument); Modules.ThreadManForUserModule.hleKernelNotifyCallback(THREAD_CALLBACK_USER_DEFINED, requestCallback); } }
public override bool AppliesTo(object expected, object actual, MatchingContext context) { return(base.AppliesTo(expected, actual, context) && expected == null && actual is JObject); }