public void CompareTest() { string testString1 = MFUtilities.GetRandomString(); string testString2 = MFUtilities.GetRandomString(); String.Compare(testString1, testString2); }
public MFTestResults VerifyFlush() { MFTestResults result = MFTestResults.Pass; try { using (MemoryStream ms = new MemoryStream()) { byte[] data = MFUtilities.GetRandomBytes(5000); ms.Write(data, 0, data.Length); ms.Flush(); if (ms.Length != 5000) { result = MFTestResults.Fail; Log.Exception("Expected 5000 bytes, but got " + ms.Length); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception("Unexpected exception", ex); } return(result); }
public MFTestResults UInt_Ushort_Constructor_Test7() { /// <summary> /// 1. Creates a Guid(uint, ushort, byte, byte ...) /// 2. Verifies exception is not thrown /// </summary> /// MFTestResults testResult = MFTestResults.Pass; Random random = new Random(); int randoInt = random.Next(Int32.MaxValue); uint _uInt = (uint)(randoInt * 2); ushort _uShort1 = (ushort)random.Next(65536); ushort _uShort2 = (ushort)random.Next(65536); Byte[] _bArr = MFUtilities.GetRandomBytes(8); try { Guid _guid = new Guid(_uInt, _uShort1, _uShort1, _bArr[0], _bArr[1], _bArr[2], _bArr[3], _bArr[4], _bArr[5], _bArr[6], _bArr[7]); } catch (Exception ex) { Log.Comment("Caught : " + ex.Message + "when creating Guid(" + _uInt + ", " + _uShort1 + ", " + _uShort1 + ", " + _bArr[0] + ", " + _bArr[1] + ", " + _bArr[2] + ", " + _bArr[3] + ", " + _bArr[4] + ", " + _bArr[5] + ", " + _bArr[6] + ", " + _bArr[7] + ")"); testResult = MFTestResults.Fail; } return(testResult); }
public MFTestResults TextFlow_LineCountTest2() { if (CleaningWindow() != MFTestResults.Pass) { return(MFTestResults.Fail); } Log.Comment("This test gives unpredictable result, skipping it for the moment"); MFTestResults testResult = MFTestResults.Skip; count = 10; int _maxFontWidth = _font.AverageWidth; int _minCharsinaLine = _width / _maxFontWidth; int len = (11 * _minCharsinaLine) / 10; _longStr = MFUtilities.GetRandomString(len); _lineCount = true; UpdateWindow(); txtFlow.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(SetTopLine), null); if (txtFlow.LineCount != count + 2) { Log.Comment("Expectd Line count " + count + 2 + " but got " + txtFlow.LineCount); //testResult = MFTestResults.Fail; } _lineCount = false; return(testResult); }
public void VerifyWrite() { // limit to 512 bytes because of potential // buffer issues with larger strings. int length = new Random().Next(512); string data = MFUtilities.GetRandomString(length); Log.FilteredComment("Using string: '" + data + "'"); this.VerifyWrite(data); }
public TestObj() { Random rand = new Random(DateTime.Now.Millisecond); this.Count = rand.Next(); this.uCount = (uint)rand.Next(); this.LongCount = rand.Next(); this.uLongCount = (ulong)rand.Next(); this.Double = rand.NextDouble(); this.byteArray = new byte[1024]; rand.NextBytes(this.byteArray); this.charArray = MFUtilities.GetRandomString().ToCharArray(); this.Data = new string(this.charArray); }
public SslClient(IPAddress ipAddress, String targetHost, X509Certificate cert, X509Certificate [] ca, SslVerification verify, SslProtocols[] sslProtocols, bool expectedException) { // Initialize the Socket messageSent = MFUtilities.GetRandomSafeString(2000) + TERMINATOR; // Initialize the port that communication is using port = 11111; this.ipAddress = ipAddress; this.messageSent = "hello" + TERMINATOR; this.targetHost = targetHost; this.cert = cert; this.ca = ca; this.verify = verify; this.sslProtocols = sslProtocols; this.expectedException = expectedException; }
public Task <bool> SyncContractInfoAsync(bool forced = false) { var today = DateTime.Now.Date.ToShortDateString(); var key = string.Format("{0}:{1}", nameof(ContractInfo), GetType().Name); if (!forced && MFUtilities.GetSyncVersion(key) == today) { return(Task.FromResult(true)); } var sst = new StringMap(); sst.Header = new DataHeader(); sst.Header.SerialId = NextSerialId; var msgId = (uint)BusinessMessageID.MSG_ID_QUERY_INSTRUMENT; var tcs = new TaskCompletionSource <bool>(); var serialId = NextSerialId; sst.Header = new DataHeader { SerialId = serialId }; MessageWrapper.RegisterAction <PBContractInfoList, ExceptionMessage> (msgId, (resp) => { if (resp.Header?.SerialId == serialId) { OnSyncContractInfo(key, resp); tcs.TrySetResult(true); } }, (bizErr) => { tcs.SetResult(false); } ); MessageWrapper.SendMessage(msgId, sst); return(tcs.Task); }
public MFTestResults LargeSendBuffer() { if (!IsLoopback) { return(MFTestResults.Skip); } result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Handshake = Handshake.RequestToSend; serialPort.Open(); serialPort.AsyncRead = true; string start = MFUtilities.GetRandomSafeString(10000); byte[] buff = Encoding.UTF8.GetBytes(start); serialPort.Write(buff, 0, buff.Length); // wait for data to drain while (serialPort.AsyncResult.Length < start.Length && (serialPort.BytesToWrite > 0 || serialPort.BytesToRead > 0)) { Thread.Sleep(100); } if (serialPort.AsyncResult != start) { Log.Exception("Failed: " + serialPort.AsyncResult + " != " + start); result = MFTestResults.Fail; } // wait to make sure AsyncReader is closed; serialPort.AsyncRead = false; while (serialPort.IsAsyncReading) { Thread.Sleep(100); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults ByteArrayConstructor_Test2() { /// <summary> /// 1. Creates a Guid with byte Array of size 16 and random byte values /// 2. Verifies exception is not thrown /// </summary> /// MFTestResults testResult = MFTestResults.Pass; Byte[] guid16 = MFUtilities.GetRandomBytes(16); try { Guid myGuid1 = new Guid(guid16); } catch (Exception ex) { Log.Comment("Caught : " + ex.Message); testResult = MFTestResults.Fail; } return(testResult); }
public MFTestResults ArgumentException_Test3() { /// <summary> /// 1. Creates a Guid with byte Array of random size b/n 0 to 100 but not 16 /// 2. Verifies ArgumentException is thrown /// </summary> /// MFTestResults testResult = MFTestResults.Fail; int size = 16; //size could be set to any Random number b/n 0 and 2147483647 //System.OutOfMemoryException will be thrown Random random = new Random(); while (size == 16) { size = random.Next(100); } Byte[] guidNot16 = MFUtilities.GetRandomBytes(size); try { Guid myGuid1 = new Guid(guidNot16); } catch (ArgumentException ex) { Log.Comment("Caught : " + ex.Message + " when trying to create Guid with " + size + " bytes long"); testResult = MFTestResults.Pass; } catch (Exception e) { Log.Comment("Expecting ArgumentException got " + e.Message); } return(testResult); }
private byte[] GetByteArray(int length) { return(MFUtilities.GetRandomBytes(length)); }
public MFTestResults Ssid() { int MAX_SSID_LENGTH = 31; char[] specialChars = { '~', '/', '`', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '+', '=', '{', '[', '}', ']', '|', '\\', ':', ';', '"', '\'', }; char[] specialChars2 = { '<', ',', '>', '.', '?', '/' }; string[] testStrings = { " ", MFUtilities.GetRandomSafeString(1), MFUtilities.GetRandomSafeString(MAX_SSID_LENGTH), MFUtilities.GetRandomString(1), MFUtilities.GetRandomString(MAX_SSID_LENGTH), MFUtilities.GetRandomHighByteString(1), MFUtilities.GetRandomHighByteString(8), "?˜???", "??????", "0x0001fd94", new string(specialChars), new string(specialChars2), }; string[] invalidStrings = { MFUtilities.GetRandomSafeString(MAX_SSID_LENGTH + 1), MFUtilities.GetRandomString(MAX_SSID_LENGTH + 1), MFUtilities.GetRandomString(MAX_SSID_LENGTH + 1 + new Random().Next(100)), }; foreach (string testString in testStrings) { try { SetSsid(testString); // Verify. if (MFTestResults.Fail == VerifySsid(testString)) { return(MFTestResults.Fail); } } catch (Exception ex) { Log.Exception(ex.Message); return(MFTestResults.Fail); } } foreach (string invalidString in invalidStrings) { try { SetSsid(invalidString); Log.Comment("Setting ssid to " + invalidString + " succeeded. " + " Expected an exception to be thrown. Returning a failure."); return(MFTestResults.Fail); } catch (Exception ex) { Log.Comment("Test passed - A valid exception was thrown: " + ex.Message); } } SetSsid("SSID_1"); // Return test result. return(MFTestResults.Pass); }
public void LengthTest() { string testString = MFUtilities.GetRandomString(); int length = testString.Length; }
public MFTestResults FunctionalChunkTests() { MFTestResults result = MFTestResults.Pass; HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpTestServer.s_CurrentPort.ToString() + "/"); wr.UserAgent = ".Net Micro Framwork Device/4.0"; wr.KeepAlive = true; HttpTestServer server = new HttpTestServer("http", ref result) { RequestUri = wr.RequestUri, RequestHeaders = wr.Headers, ResponseString = MFUtilities.GetRandomSafeString(5000), }; try { // Setup server server.StartServer(); Log.Comment("Send UnChunked"); wr.SendChunked = false; HttpWebResponse response = (HttpWebResponse)wr.GetResponse(); HttpTests.PrintHeaders("Client", response.Headers); using (Stream responseStream = response.GetResponseStream()) { if (responseStream != null) { string page = HttpTests.ReadStream("Client", responseStream); if (page != server.ResponseString) { result = MFTestResults.Fail; Log.Exception("[Client] Send UnChunked - Corrupt Page!"); Log.Exception("[Client] Expected: " + server.ResponseString); Log.Exception("[Client] Received: " + page); } } else { result = MFTestResults.Fail; Log.Exception("[Client] Expected stream, but got null"); } } Log.Comment("Send Chunked"); wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpTestServer.s_CurrentPort.ToString() + "/"); wr.UserAgent = ".Net Micro Framwork Device/4.0"; wr.SendChunked = true; server.SendChunked = true; server.RequestHeaders = wr.Headers; response = (HttpWebResponse)wr.GetResponse(); HttpTests.PrintHeaders("Client", response.Headers); using (Stream responseStream = response.GetResponseStream()) { if (responseStream != null) { string page = HttpTests.ReadStream("Client", responseStream); if (page != server.ResponseString) { result = MFTestResults.Fail; Log.Exception("[Client] Send Chunked - Corrupt Page!"); Log.Exception("[Client] Expected: " + server.ResponseString); Log.Exception("[Client] Received: " + page); } } else { result = MFTestResults.Fail; Log.Exception("[Client] Expected stream, but got null"); } } } catch (Exception ex) { Log.Exception("[Client] Unexpected Exception", ex); result = MFTestResults.Fail; } finally { // Stop server server.StopServer(); } return(result); }