public void TestObjectTypesWithSpace() { Assert.AreEqual("{Boolean:b,Int32:i}", typeof(TestClasses.BooleanAndInt).SosTypeDefinition()); String [] definitions = new String[] { "{Boolean:b,Int32:i}", "{ Boolean:b,Int32:i}", "{ Boolean :b,Int32:i}", "{ Boolean : b,Int32:i}", "{ Boolean : b ,Int32:i}", "{ Boolean : b , Int32:i}", "{ Boolean : b , Int32 :i}", "{ Boolean : b , Int32 : i}", "{ Boolean : b , Int32 : i }", "{ Boolean : b , Int32 : i } ", }; SosObjectDefinition objectDefinition = new SosObjectDefinition( "Boolean", "b", "Int32", "i"); for (int i = 0; i < definitions.Length; i++) { String definition = definitions[i]; Console.WriteLine(definition); Assert.AreEqual(objectDefinition, SosTypes.ParseSosObjectTypeDefinition(definition, 0)); } }
public void ObjectType(SosObjectDefinition objectDefinition) { if (callbackIndex >= expectedCallbacks.Length) { Assert.Fail(String.Format("Only expected '{0}' callbacks but got more", expectedCallbacks.Length, callbackIndex)); } CallbackObject expectedCallback = expectedCallbacks[callbackIndex++]; expectedCallback.AssertObjectTypeCall(objectDefinition); }
public void AssertObjectTypeCall(SosObjectDefinition objectDefinition) { Assert.AreEqual(this.type, type, String.Format("Expected {0} callback but got {1}", ExpectedCallback(), objectDefinition.TypeDefinition())); }
public void ObjectType(SosObjectDefinition type) { }
public CallbackObject(SosObjectDefinition objectDefinition) { this.objectDefinition = objectDefinition; }
public void RoundTripTests() { RoundTripTypeDefinition(typeof(Boolean), new TypeDefinitionVerifier(new CallbackObject(typeof(Boolean)))); RoundTripTypeDefinition(typeof(SByte), new TypeDefinitionVerifier(new CallbackObject(typeof(SByte)))); RoundTripTypeDefinition(typeof(Byte), new TypeDefinitionVerifier(new CallbackObject(typeof(Byte)))); RoundTripTypeDefinition(typeof(Int16), new TypeDefinitionVerifier(new CallbackObject(typeof(Int16)))); RoundTripTypeDefinition(typeof(UInt16), new TypeDefinitionVerifier(new CallbackObject(typeof(UInt16)))); RoundTripTypeDefinition(typeof(Int32), new TypeDefinitionVerifier(new CallbackObject(typeof(Int32)))); RoundTripTypeDefinition(typeof(UInt32), new TypeDefinitionVerifier(new CallbackObject(typeof(UInt32)))); RoundTripTypeDefinition(typeof(Int64), new TypeDefinitionVerifier(new CallbackObject(typeof(Int64)))); RoundTripTypeDefinition(typeof(UInt64), new TypeDefinitionVerifier(new CallbackObject(typeof(UInt64)))); RoundTripTypeDefinition(typeof(Single), new TypeDefinitionVerifier(new CallbackObject(typeof(Single)))); RoundTripTypeDefinition(typeof(Double), new TypeDefinitionVerifier(new CallbackObject(typeof(Double)))); RoundTripTypeDefinition(typeof(Char), new TypeDefinitionVerifier(new CallbackObject(typeof(Char)))); RoundTripTypeDefinition(typeof(String), new TypeDefinitionVerifier(new CallbackObject(typeof(String)))); SosEnumDefinition enumDefinition = new SosEnumDefinition(); enumDefinition.Add(DayOfWeek.Sunday.ToString(), (Int32)DayOfWeek.Sunday); enumDefinition.Add(DayOfWeek.Monday.ToString(), (Int32)DayOfWeek.Monday); enumDefinition.Add(DayOfWeek.Tuesday.ToString(), (Int32)DayOfWeek.Tuesday); enumDefinition.Add(DayOfWeek.Wednesday.ToString(), (Int32)DayOfWeek.Wednesday); enumDefinition.Add(DayOfWeek.Thursday.ToString(), (Int32)DayOfWeek.Thursday); enumDefinition.Add(DayOfWeek.Friday.ToString(), (Int32)DayOfWeek.Friday); enumDefinition.Add(DayOfWeek.Saturday.ToString(), (Int32)DayOfWeek.Saturday); RoundTripTypeDefinition(typeof(DayOfWeek), new TypeDefinitionVerifier(new CallbackObject(enumDefinition))); RoundTripTypeDefinition(typeof(Object), new TypeDefinitionVerifier(new CallbackObject(typeof(Object)))); // // Arrays // RoundTripTypeDefinition(typeof(Boolean[]), new TypeDefinitionVerifier(new CallbackObject("Boolean"))); RoundTripTypeDefinition(typeof(SByte[]), new TypeDefinitionVerifier(new CallbackObject("SByte"))); RoundTripTypeDefinition(typeof(Byte[]), new TypeDefinitionVerifier(new CallbackObject("Byte"))); RoundTripTypeDefinition(typeof(Int16[]), new TypeDefinitionVerifier(new CallbackObject("Int16"))); RoundTripTypeDefinition(typeof(UInt16[]), new TypeDefinitionVerifier(new CallbackObject("UInt16"))); RoundTripTypeDefinition(typeof(Int32[]), new TypeDefinitionVerifier(new CallbackObject("Int32"))); RoundTripTypeDefinition(typeof(UInt32[]), new TypeDefinitionVerifier(new CallbackObject("UInt32"))); RoundTripTypeDefinition(typeof(Int64[]), new TypeDefinitionVerifier(new CallbackObject("Int64"))); RoundTripTypeDefinition(typeof(UInt64[]), new TypeDefinitionVerifier(new CallbackObject("UInt64"))); RoundTripTypeDefinition(typeof(Single[]), new TypeDefinitionVerifier(new CallbackObject("Single"))); RoundTripTypeDefinition(typeof(Double[]), new TypeDefinitionVerifier(new CallbackObject("Double"))); RoundTripTypeDefinition(typeof(Char[]), new TypeDefinitionVerifier(new CallbackObject("Char"))); RoundTripTypeDefinition(typeof(String[]), new TypeDefinitionVerifier(new CallbackObject("String"))); RoundTripTypeDefinition(typeof(Object[]), new TypeDefinitionVerifier(new CallbackObject("System.Object"))); // // User Defined Types // SosObjectDefinition firstObjectDefinition = new SosObjectDefinition( "myBoolean", "Boolean", "myByte", "Byte", "myUshort", "UInt16", "myShort", "Int16", "myUint", "UInt32", "myInt", "Int32", "myUlong", "UInt64", "myLong", "Int64", "dayOfWeek", "System.DayOfWeek", "myObject", "System.Object", "myString", "String" ); RoundTripTypeDefinition(typeof(TestClasses.ClassWithPrimitiveTypes), new TypeDefinitionVerifier(new CallbackObject(firstObjectDefinition))); SosObjectDefinition secondObjectDefinition = new SosObjectDefinition( "booleanArray", "Boolean[]", "sbyteArray", "SByte[]", "byteArray", "Byte[]", "ushortArray", "UInt16[]", "shortArray", "Int16[]", "uintArray", "UInt32[]", "intArray", "Int32[]", "ulongArray", "UInt64[]", "longArray", "Int64[]", "enumArray", "System.DayOfWeek[]", "stringArray", "String[]" ); RoundTripTypeDefinition(typeof(TestClasses.ClassWithArrays), new TypeDefinitionVerifier(new CallbackObject(secondObjectDefinition))); /* * SosObjectDefinition weirdObjectDefinition = new SosObjectDefinition( * * ); * RoundTripTypeDefinition(typeof(TestClasses.ClassWithWeirdTypes), new TypeDefinitionVerifier(new CallbackObject(weirdObjectDefinition))); */ }
public void UpdateAndVerifyEnumAndObjectTypes(NpcVerifyCriteria criteria) { if (threadSafe) { Monitor.Enter(serverEndPoint); } try { // // The reason for the retry logic is because if the underlying socket is disconnected, it may not // fail until after a send and a receive...so the socket should be reconnected and the request should // be repeated only once. // for (UInt32 attempt = 0; ; attempt++) { try { Connect(); socketLineReader.socket.Send(Encoding.UTF8.GetBytes(":type\n")); enumAndObjectTypes.Clear(); while (true) { String typeDefinitionLine = socketLineReader.ReadLine(); if (typeDefinitionLine == null) { if (attempt == 0) { Dispose(); continue; // Retry } throw UnexpectedClose(); } if (typeDefinitionLine.Length == 0) { break; // empty line } Int32 spaceIndex = typeDefinitionLine.IndexOf(' '); String sosTypeName = typeDefinitionLine.Remove(spaceIndex); String typeDefinition = typeDefinitionLine.Substring(spaceIndex + 1); Type type = GetTypeFromSosTypeName(sosTypeName); if (typeDefinition.StartsWith("Enum")) { SosEnumDefinition enumDefinition = SosTypes.ParseSosEnumTypeDefinition(typeDefinition, 4); enumDefinition.VerifyType(type, (SosVerifyCriteria)criteria); } else { SosObjectDefinition objectDefinition = SosTypes.ParseSosObjectTypeDefinition(typeDefinition, 0); objectDefinition.VerifyType(type); } enumAndObjectTypes.Add(type); } return; } catch (SocketException) { if (socketLineReader != null) { socketLineReader.Dispose(); socketLineReader = null; } if (attempt == 0) { continue; // Retry } throw; } } } finally { if (threadSafe) { Monitor.Exit(serverEndPoint); } } }