public void Deserialize(byte[] command) { if (command == null || command.Length < 4) throw new Exception("There is no data to deserialize."); char[] commandChars = new char[command.Length]; //Log.Comment("Deserializing data:"); //string data = new string(System.Text.UTF8Encoding.UTF8.GetChars(command)); //Log.Comment(data); String[] commands = new string[4]; int startIndex = 0; int commandNumber = 0; for (int i = 0; i < command.Length; ++i) { if (command[i] == ' ') { //Put the data into string format commands[commandNumber] = new String(commandChars, startIndex, i - startIndex); commandNumber++; startIndex = i + 1; } else commandChars[i] = (char)command[i]; } //Deserialize the data to what it really means. testToRun = commands[0]; serverTimeoutSeconds = int.Parse(commands[1]); serverTestResult = (MFTestResults)(int.Parse(commands[2])); scenarioToRun = int.Parse(commands[3]); }
private void RunServer() { try { running = true; listener.Start(); Log.Comment("[Server] Starting listener..."); evtStarted.Set(); while (running) { HttpListenerContext context = listener.GetContext(); if (context == null) continue; HttpListenerRequest request = context.Request; // request header validation if (this.RequestHeaders != null) { foreach (string header in this.RequestHeaders.AllKeys) { if (this.RequestHeaders[header] != request.Headers[header]) { this.result = MFTestResults.Fail; Log.Exception("[Server] Expected " + header + ":" + this.RequestHeaders[header] + ", but got " + header + ":" + request.Headers[header]); } } } HttpTests.PrintHeaders("Server", request.Headers); // BUGBUG: Check inbound stream once 54503 & 54507 are fixed //HttpTests.ReadStream("Client", request.InputStream); HttpListenerResponse response = context.Response; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(this.ResponseString); response.Headers.Add("Server", ".Net Micro Framework Device/4.0"); response.SendChunked = this.SendChunked; if (!this.SendChunked) response.ContentLength64 = buffer.Length; response.OutputStream.Write(buffer, 0, buffer.Length); response.Close(); } listener.Stop(); } catch (Exception ex) { Log.Exception("[Server] Unexpected Server Exception", ex); } finally { if (listener.IsListening) listener.Abort(); running = false; } }
public MFTestResults GetSetStopBits() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.StopBits, StopBits.One); serialPort.StopBits = StopBits.Two; serialPort.EvalOpenClose(serialPort.StopBits, StopBits.Two); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults MultiDotPath() { MFTestResults result = MFTestResults.Pass; try { string path = "jabba..de..hutt..."; if (!TestChangeExtension(path, exe)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
/// <summary> /// /// </summary> /// <returns></returns> public MFTestResults HeapTest(int scenarioToRun) { MFTestResults testResult = MFTestResults.Fail; SslServer sslServer = null; try { sslServer = new SslServer(new X509Certificate2(Resource1.desktop, "alden"), false, SslProtocols.Default, false); testResult = sslServer.RunServer(); } catch (CryptographicException ex) { Console.WriteLine(ex.Message); Console.WriteLine( "An error has occurred while using or authenticating " + "this connection. Check to make sure you've exported " + "your certificate and that it is correctly referenced " + "in CreateFromCertFile above."); testResult = MFTestResults.Fail; } catch (AuthenticationException ex) { Console.WriteLine(ex.Message); testResult = MFTestResults.Fail; } catch (SocketException ex) { Console.WriteLine(ex.Message); testResult = MFTestResults.Fail; } catch (IOException ex) { Console.WriteLine(ex.Message); testResult = MFTestResults.Fail; } catch (Exception ex) { Console.WriteLine(ex.Message); testResult = MFTestResults.Fail; } return(testResult); }
public MFTestResults ValidCases() { MFTestResults result = MFTestResults.Pass; try { /// Initial status is Hidden because of the test above. /// Log.Comment("Default Normal attribute"); /// if (!TestGetAttributes(file1Name, FileAttributes.Normal)) /// result = MFTestResults.Fail; Log.Comment("Read Only attribute"); if (!TestSetGetAttributes(file1Name, FileAttributes.ReadOnly)) { result = MFTestResults.Fail; } Log.Comment("Hidden attribute"); if (!TestSetGetAttributes(file1Name, FileAttributes.Hidden)) { result = MFTestResults.Fail; } Log.Comment("ReadOnly & Hidden attribute"); if (!TestSetGetAttributes(file1Name, FileAttributes.Hidden | FileAttributes.ReadOnly)) { result = MFTestResults.Fail; } Log.Comment("Back to Normal attribute"); if (!TestSetGetAttributes(file1Name, FileAttributes.Normal)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
public MFTestResults MoreSchemes() { MFTestResults result = MFTestResults.Pass; var sUris = new string[] { "ws://ws.pusherapp.com:80/app/?client=js&version=1.9.3&protocol=5", "\tftp://abc.com ", "ldap://[2001:db8::7]/c=GB?objectClass?one", "mailto:[email protected]", "mailto://abc/d", "news:comp.infosystems.www.servers.unix", "tel:+1-816-555-1212", "telnet://192.0.2.16:80/", "h323:abc", "h323://abc/d" }; var parseds = new ParsedUri[] { new ParsedUri("ws", "ws.pusherapp.com", UriHostNameType.Dns, 80, "/app/?client=js&version=1.9.3&protocol=5", "ws://ws.pusherapp.com/app/?client=js&version=1.9.3&protocol=5"), new ParsedUri("ftp", "abc.com", UriHostNameType.Dns, 21, "/", "ftp://abc.com/"), new ParsedUri("ldap", "[2001:db8::7]", UriHostNameType.IPv6, 389, "/c=GB?objectClass?one", "ldap://[2001:db8::7]/c=GB?objectClass?one"), new ParsedUri("mailto", "*****@*****.**", UriHostNameType.Dns, 25, string.Empty, "mailto:[email protected]"), new ParsedUri("mailto", string.Empty, UriHostNameType.Basic, 25, "//abc/d", "mailto://abc/d"), new ParsedUri("news", string.Empty, UriHostNameType.Unknown, -1, "comp.infosystems.www.servers.unix", "news:comp.infosystems.www.servers.unix"), new ParsedUri("tel", string.Empty, UriHostNameType.Unknown, -1, "+1-816-555-1212", "tel:+1-816-555-1212"), new ParsedUri("telnet", "192.0.2.16", UriHostNameType.IPv4, 80, "/", "telnet://192.0.2.16:80/"), new ParsedUri("h323", string.Empty, UriHostNameType.Unknown, -1, "abc", "h323:abc"), new ParsedUri("h323", "abc", UriHostNameType.Dns, -1, "/d", "h323://abc/d") }; for (int i = 0; i < sUris.Length; i++) { uri = new Uri(sUris[i]); if (!parseds[i].ValidUri(uri)) { result = MFTestResults.Fail; } } return(result); }
public MFTestResults ValidExtension() { MFTestResults result = MFTestResults.Pass; try { string path = "jabba\\de\\hutt.solo"; if (!TestChangeExtension(path, exe)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
public MFTestResults ConstructorInvalidFuzzed() { MFTestResults testResult = MFTestResults.Fail; Log.Comment("Create a fuzzed X509 Certificate. Should throw exception."); try { X509Certificate cert = new X509Certificate(CertificatesAndCAs.fuzzedCert); Log.Comment("Did not throw exception creating fuzzed Cert."); } catch (Exception e) { Log.Comment("Correctly threw exception creating fuzzed cert: " + e.ToString()); testResult = MFTestResults.Pass; } return(testResult); }
public MFTestResults SpecialSymbolExtension() { MFTestResults result = MFTestResults.Pass; try { string extension = ".$#@$_)+_)!@@!!@##&_$)#_"; if (!TestChangeExtension(defaultPath, extension)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
public MFTestResults OneCharExtension() { MFTestResults result = MFTestResults.Pass; try { string extension = ".z"; if (!TestChangeExtension(defaultPath, extension)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
public MFTestResults ConstructorValid() { MFTestResults testResult = MFTestResults.Fail; Log.Comment("Create an X509 Certificate. No Exceptions should be thrown."); try { X509Certificate cert = new X509Certificate(CertificatesAndCAs.caCert); testResult = MFTestResults.Pass; } catch (Exception e) { Log.Comment("Failed to create a valid certificate with exception: " + e.ToString()); testResult = MFTestResults.Fail; } return(testResult); }
public MFTestResults CheckDescriptors() { MFTestResults result = MFTestResults.Pass; manufacturerIndex = 0; productIndex = 0; descriptorFound = false; displayNameFound = false; friendlyNameFound = false; manufacturerNameFound = false; productNameFound = false; sideshowOsStringFound = false; sideshowXCompatIdFound = false; if (config == null) // If the default configuration was totally bogus { if (UsbController.GetControllers().Length == 0) // If there were no controllers { return(MFTestResults.Skip); // The test should not be run } return(MFTestResults.Fail); } // These tests must be done in this order to work properly if (!DeviceDescriptor()) { result = MFTestResults.Fail; } if (!ConfigurationDescriptor()) { result = MFTestResults.Fail; } if (!StringDescriptors()) { result = MFTestResults.Fail; } if (!GenericDescriptors()) { result = MFTestResults.Fail; } return(result); }
public MFTestResults DeepTree() { MFTestResults result = MFTestResults.Pass; try { string deepTree = "\\root\\Dir1\\Dir2\\Dir1\\Dir2\\Dir1\\Dir2\\Dir1\\Dir2\\Dir1\\Dir2\\Dir1\\Dir2\\Dir1\\Dir2\\Dir1\\Dir2\\Dir1\\Dir2\\Dir1\\Dir2\\Dir1\\Dir2\\Dir2\\Dir1\\Dir2\\Dir1\\Dir2"; if (!TestGetDirectoryName(deepTree + "\\File.exe", deepTree)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
public MFTestResults SpecialSymbolPath() { MFTestResults result = MFTestResults.Pass; try { string path = "foo.bar.fkl;fkds92-509450-4359.213213213@*?2-3203-=210"; if (!TestChangeExtension(path, cool)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
public MFTestResults AcceptHeaderTest() { MFTestResults result = MFTestResults.Pass; HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);; try { Log.Comment("Initial value should be null"); if (wr.Accept != null) { Log.Exception("Unexpected initial value: " + wr.Accept); result = MFTestResults.Fail; } if (!ValidateAccept(wr, "text/plain")) { result = MFTestResults.Fail; } if (!ValidateAccept(wr, "text/plain; q=0.5, text/html,\r\n\ttext/x-dvi; q=0.8, text/x-c")) { result = MFTestResults.Fail; } if (!ValidateAccept(wr, "text/*;q=0.3, text/html;q=0.7, text/html;level=1,\r\n\ttext/html;level=2;q=0.4, */*;q=0.5")) { result = MFTestResults.Fail; } Log.Comment("Clear w/null header"); if (!ValidateAccept(wr, null)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected Exception", ex); result = MFTestResults.Fail; } return(result); }
public MFTestResults CheckBadHeaders() { MFTestResults result = MFTestResults.Pass; try { Log.Comment("low byte"); if (!TestCheckBadHeaders("low byte \u0031 embedded string")) { result = MFTestResults.Fail; } Log.Comment("high byte"); if (!TestCheckBadHeaders("high byte \u0128 embedded string")) { result = MFTestResults.Fail; } Log.Comment("bad nl wrap"); if (!TestCheckBadHeaders("bad\nwrap")) { result = MFTestResults.Fail; } Log.Comment("bad crlf wrap"); if (!TestCheckBadHeaders("bad\r\nwrap")) { result = MFTestResults.Fail; } Log.Comment("embedded tab"); if (!TestCheckBadHeaders("embedded\ttab")) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected Exception", ex); result = MFTestResults.Fail; } return(result); }
public MFTestResults PolygonTest_PolygonFill5() { MFTestResults testResult = MFTestResults.Pass; try { if (ClearingPanel() != MFTestResults.Pass) { return(MFTestResults.Fail); } Log.Comment("Setting the Pen and Brush"); _pen = new Pen(Colors.Red, 1); _brush = new SolidColorBrush(Colors.Green); Log.Comment("Draw a Regular Octagon"); DrawRegularOctagon(); autoEvent.WaitOne(); Thread.Sleep(1000); Log.Comment("Initializing 40 Random Points inside the Horizontal rectangle in the Octagon"); int len = min / 6 + (int)(((double)min / 3) / sqrt2); int w1 = 2 * (len - 1), h1 = (min - 1) / 3; Point[] chkPoints1 = GetRandomPoints_InRectangle(40, w1, h1, midX - w1 / 2, midY - h1 / 2); Log.Comment("Veifying The pixel colors inside the Horizontal rectangle in the Octagon"); MFTestResults tRes1 = VerifyingPixelColor(chkPoints1, Colors.Green); Log.Comment("Initializing 40 Random Points inside the Vertical Rectangle in the Octagon"); int w2 = h1, h2 = w1; Point[] chkPoints2 = GetRandomPoints_InRectangle(40, w2, h2, midX - w2 / 2, midY - h2 / 2); Log.Comment("Veifying The pixel colors inside the Vertical rectangle in the Octagon"); MFTestResults tRes2 = VerifyingPixelColor(chkPoints1, Colors.Green); if ((tRes1 != MFTestResults.Pass) && (tRes2 != MFTestResults.Pass)) { testResult = MFTestResults.Fail; } } catch (Exception ex) { Log.Comment("Caught : " + ex.Message); return(MFTestResults.Fail); } return(testResult); }
public MFTestResults TestMethod1() { MFTestResults testResult = MFTestResults.Fail; Log.Comment("Create the client and server sockets"); SslServer sslServer = new SslServer(); SslClient sslClient = new SslClient(); try { // Set up the server here Log.Comment("Create server thread"); sslServer.RunServer(); // Set up the client here sslClient.serverEp = sslServer.serverEp; sslClient.RunClient(); if (sslClient.messageSent == sslClient.messageReceived) { testResult = MFTestResults.Pass; } } catch (Exception e) { Log.Comment("Incorrect Exception caught: " + e.ToString()); } finally { try { sslServer.Close(); sslClient.Close(); } catch { } } Log.Comment("known issue: 20848 SSL tests don't work with loopback"); return(testResult == MFTestResults.Fail ? MFTestResults.KnownFailure : testResult); }
public MFTestResults ValidCases() { MFTestResults result = MFTestResults.Pass; try { if (!TestGetFileName(@"file.tmp", "file.tmp")) { result = MFTestResults.Fail; } if (!TestGetFileName(@"directory\file.tmp", "file.tmp")) { result = MFTestResults.Fail; } if (!TestGetFileName(@"\directory\file.tmp", "file.tmp")) { result = MFTestResults.Fail; } if (!TestGetFileName(@"\\machine\directory\file.tmp", "file.tmp")) { result = MFTestResults.Fail; } if (!TestGetFileName(@"\\machine\directory\file", "file")) { result = MFTestResults.Fail; } if (!TestGetFileName(@"\\machine\directory\file name", "file name")) { result = MFTestResults.Fail; } if (!TestGetFileName(@"\\machine\directory\file.t name.exe", "file.t name.exe")) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
public MFTestResults LargeBufferTest_DifferentSizeBuff() { MFTestResults res = MFTestResults.Pass; LargeBuffer lb = null; LargeBuffer lb2 = null; try { lb = new LargeBuffer(1000); lb2 = new LargeBuffer(100); LargeBufferMarshaller lbm = new LargeBufferMarshaller(123); lbm.MarshalBuffer(lb); lbm.UnMarshalBuffer(ref lb2); if (lb.Bytes.Length != lb2.Bytes.Length) { Log.Comment("The UnMarshalBuffer call should have changed the byte length of lb2"); res = MFTestResults.Fail; } } catch (Exception e) { Log.Exception("Exception", e); res = MFTestResults.Fail; } finally { if (lb != null) { lb.Dispose(); } if (lb2 != null) { lb2.Dispose(); } } return(res); }
public MFTestResults InvalidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_1() { MFTestResults result = MFTestResults.Pass; HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://ftp"); wr.UserAgent = ".Net Micro Framwork Device/4.0"; Log.Comment("Negative Test case 3:"); Log.Comment("Initial version: " + wr.ProtocolVersion); //Default version is 1.1 Log.Comment("Set Version 1.1"); wr.ProtocolVersion = new Version(1, 1); HttpServer server = new HttpServer("http", ref result) { RequestUri = wr.RequestUri, RequestHeaders = wr.Headers, }; try { // Setup server server.StartServer(); System.Net.WebHeaderCollection wrc = wr.Headers; // Tests Verify(wrc, server.RequestHeaders); } catch (Exception ex) { Log.Exception("[Client] Unexpected Exception", ex); result = MFTestResults.Fail; } finally { // Stop server server.StopServer(); } return(result); }
public MFTestResults ValidCases() { MFTestResults result = MFTestResults.Pass; try { if (!TestGetPathRoot(@"\", @"\")) { result = MFTestResults.Fail; } if (!TestGetPathRoot(@"\dir1", @"\")) { result = MFTestResults.Fail; } if (!TestGetPathRoot(@"\file.text", @"\")) { result = MFTestResults.Fail; } if (!TestGetPathRoot(@"\file\text", @"\")) { result = MFTestResults.Fail; } if (!TestGetPathRoot(@"\sd1\\\\dir\\\\\file\\\\\text\\\\", @"\")) { result = MFTestResults.Fail; } if (!TestGetPathRoot(@"\\machine\dir1\file.tmp", @"\\machine\dir1")) { result = MFTestResults.Fail; } if (!TestGetPathRoot(@"\\machine", @"\\machine")) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
public MFTestResults Sleep_2_ChangeLevelFromManagedCode() { MFTestResults result = MFTestResults.Fail; try { const int c_Timeout = 5000; // ms HardwareEvent newEvents = HardwareEvent.SerialIn | HardwareEvent.USBIn | HardwareEvent.SystemTimer | HardwareEvent.GeneralPurpose; PowerState.OnSleepChange += new SleepChangeEventHandler(this.SleepChange); Timer t = new Timer(new TimerCallback(this.TimerCallback), null, c_Timeout, Timeout.Infinite); PowerState.Sleep(SleepLevel.Sleep, newEvents); // we must have received the heads-up on power change... if (_change.WaitOne(1 * c_Timeout, false)) { // and timers must still work as scheduled if (_timerFired.WaitOne(2 * c_Timeout, false)) { if (_wakeup.WaitOne(3 * c_Timeout, false)) { result = MFTestResults.Pass; } } } t.Dispose(); } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } PowerState.OnSleepChange -= new SleepChangeEventHandler(this.SleepChange); return(result); }
public MFTestResults TimeServiceStartTest1() { MFTestResults result = MFTestResults.Pass; try { DateTime now = DateTime.Now; /// EBS bug returns value in local time instead of UTC. /// Remove following line once they fixed the bug. now = now.AddHours(12); TimeService.SetUtcTime(119600064000000000); /// 1/1/1980. /// TimeServiceSettings settings = new TimeServiceSettings(); settings.PrimaryServer = GetTimeServiceAddress().GetAddressBytes(); settings.Tolerance = 100; settings.RefreshTime = 60; /// Save the settings. TimeService.Settings = settings; TimeService.Start(); /// This should fire a sync event right away. Thread.Sleep(5 * 1000); /// Sleep for some time, we should have time synced by now. if (now.Year == 1980) { throw new ArgumentException("Time not synced correctly."); } } catch (Exception ex) { Log.Exception("Unexpected exception", ex); result = MFTestResults.Fail; } finally { TimeService.Stop(); } return(result); }
public MFTestResults Reflection_Unboxing_Test5() { /// <summary> /// 1. Creates a Guid using a method /// 2. Invokes the method using Reflection /// 3. Casts the returned obj from the method back to Guid /// 4. Verifies Exception is not thrown when castin a Guid obj back to Guid /// </summary> /// MFTestResults testResult = MFTestResults.Pass; Guid[] a = new Guid[] { GetGuid(), GetGuid(), GetGuid() }; IList list = (IList)a; Guid g = (Guid)list[1]; Log.Comment(g.ToString()); Type t = Type.GetType("Microsoft.SPOT.Platform.Tests.ITest"); Type[] apps = Reflection.GetTypesImplementingInterface(t); foreach (Type app in apps) { MethodInfo method = app.GetMethod("GetGuid", BindingFlags.Static | BindingFlags.Public); if (method != null) { object o = method.Invoke(null, null); try { Guid guid = (Guid)o; } catch (Exception ex) { Log.Comment("Caught : " + ex.Message); testResult = MFTestResults.Fail; } } } return(testResult); }
public MFTestResults EllipseTest_EllipseFill9() { MFTestResults testResult = MFTestResults.Pass; int xRad = min / 3; Point pt = new Point(xRad, xRad); try { if (ClearingPanel() != MFTestResults.Pass) { return(MFTestResults.Fail); } Log.Comment("Setting the Pen and Brush"); _pen = new Pen(Colors.Red, 1); _brush = new SolidColorBrush(Colors.Green); Log.Comment("Invoking the Dispatcher on a panel"); Log.Comment("Drawing a Circle(Ellipse)with radius = " + pt.x.ToString() + " and yRadius = " + pt.y.ToString()); Master_Shapes._panel.Dispatcher.Invoke(new TimeSpan(0, 0, 5), new DispatcherOperationCallback(DrawEllipse), new Point(pt.x, pt.y)); autoEvent.WaitOne(); Thread.Sleep(100); Log.Comment("Initializing 40 random points inside the largest square inside the circle"); int s = (int)(2 * xRad / sqrt2); int x = midX - s / 2; int y = midY - s / 2; Point[] chkPoints = GetRandomPoints_InRectangle(40, s - 2, s - 2, x + 1, y + 1); Log.Comment("Veifying The pixel colors inside the Circle"); if (VerifyingPixelColor(chkPoints, Colors.Green) != MFTestResults.Pass) { testResult = MFTestResults.Fail; } } catch (Exception ex) { Log.Comment("Caught : " + ex.Message); return(MFTestResults.Fail); } return(testResult); }
public MFTestResults DataRcdEvent() { if (!IsLoopback) { return(MFTestResults.Skip); } // BUGBUG: 21216 result = MFTestResults.Fail; try { eventCount = 0; eventSerialPort = new SerialPort(Serial.COM1); // register before open eventSerialPort.DataReceived += new SerialDataReceivedEventHandler(eventserialPort_DataReceived_BeforeOpen); eventSerialPort.Open(); eventSerialPort.DataReceived += new SerialDataReceivedEventHandler(eventSerialPort_DataReceived_AfterOpen); eventSerialPort.DataReceived += new SerialDataReceivedEventHandler(eventSerialPort_DataReceived_AfterOpen2); eventSerialPort.Write(sendbuff, 0, sendbuff.Length); eventSerialPort.Flush(); for (int i = 0; i < 100; i++) { Thread.Sleep(100); if (eventCount >= 3) { result = MFTestResults.Pass; break; } } Log.Comment(eventCount + " events fired"); eventSerialPort.Close(); } catch (Exception ex) { Log.Exception(ex.Message); } finally { eventSerialPort.Dispose(); } return(result); }
public MFTestResults WhiteSpace() { MFTestResults result = MFTestResults.Pass; try { string strExtension = Path.ChangeExtension(" ", exe); Log.Comment("BUG? - The Desktop has the same behavior, but this is their test case, so don't know right behavior"); Log.Comment("We will wait to hear back from CLR team to decide what the correct behavior is."); Log.Exception("Expected ArgumentException, got " + strExtension); result = MFTestResults.KnownFailure; } catch (ArgumentException) { /* pass case */ } catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
public MFTestResults Image_GetBitmapTest3() { if (CleaningWindow() != MFTestResults.Pass) { return(MFTestResults.Fail); } MFTestResults testResult = MFTestResults.Pass; Log.Comment("Creating new Image(Bitmap), getting the Bitmap and Verifying"); _default = false; _bitmap = Resources.GetBitmap(Resources.BitmapResources.Yellow); UpdateWindow(); if (_getBitmap != _bitmap) { Log.Comment("Failure : Image.Bitmap returned diff. from what's set" + " in Image constructor new Image(Bitamp)"); testResult = MFTestResults.Fail; } return(testResult); }
public MFTestResults PathTooLong() { MFTestResults result = MFTestResults.Pass; try { string path = new string('x', 500); bool exists = Directory.Exists(path); Log.Exception("Expected IOException, got " + exists); result = MFTestResults.Fail; } catch (IOException) { /* pass case */ } // PathTooLong catch (Exception ex) { Log.Exception("Unexpected exception: " + ex.Message); result = MFTestResults.Fail; } return(result); }
public MFTestResults AddNullCertCA() { MFTestResults testResult = MFTestResults.Fail; try { Log.Comment("Null cert should throw an exception."); CertificateStore.AddCACertificate("cert1", null); } catch (Exception e) { Log.Comment("correctly threw exception on null string name" + e.ToString()); testResult = MFTestResults.Pass; } finally { CertificateStore.ClearAllCertificates(); } return(testResult); }
/// <summary> /// This executes the test case on the server. /// </summary> /// <param name="testToRun">The name of the test to execute.</param> /// <param name="serverTimeoutSeconds">The amount of time that the server should run the test case. If it times out then something is wrong.</param> /// <param name="serverTestResult">The return value that the server sends back to the client.</param> public MFTestResults RunTest(string testToRun, int serverTimeoutSeconds, MFTestResults serverTestResult, int scenarioToRun) { MFTestResults testResult = MFTestResults.Fail; currentTestCase = new TestProxy(); currentTestCase.testToRun = testToRun; currentTestCase.serverTimeoutSeconds = serverTimeoutSeconds; currentTestCase.serverTestResult = serverTestResult; currentTestCase.scenarioToRun = scenarioToRun; try { if (socket != null) { try { Thread.Sleep(350); //send the test that the client wants to execute to the server. socket.Send(currentTestCase.Serialize()); testResult = MFTestResults.Pass; } catch (Exception e) { Debug.Print("Exception trying to send test to run with exception: " + e.ToString()); } } } catch (SocketException e) { Log.Comment("Exception trying to send/receive from server."); Log.Comment("Error Code:" + e.ErrorCode); } catch (Exception e) { Log.Comment("Exception:" + e.ToString()); } return testResult; }
public MFTestResults SerialPortConstructor_1() { result = MFTestResults.Pass; try { // Valid cases ConstructorSuccessTest(Serial.COM1); ConstructorSuccessTest(Serial.COM2); ConstructorSuccessTest(Serial.COM3); ConstructorSuccessTest("com4"); ConstructorSuccessTest("CoM5"); ConstructorSuccessTest("Com10"); ConstructorSuccessTest("Com100"); // Negative cases ArgumentExceptionTest(""); ArgumentExceptionTest(null); ArgumentExceptionTest("COM0"); ArgumentExceptionTest("COM" + int.MaxValue + "0"); ArgumentExceptionTest("COM"); ArgumentExceptionTest("SON1"); string longStr = "Com1 long"; for (int i = 0; i < 10; i++) { longStr += longStr; } ArgumentExceptionTest(longStr); } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetBytesToWrite() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.BytesToWrite, 0); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetPortName() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.PortName, Serial.COM1); } if (portCount > 1) { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM2)) { serialPort.Eval(serialPort.PortName, Serial.COM2); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
private void ValidateSendString(byte[] response) { string readString = new string(Encoding.UTF8.GetChars(response)); if (testString != readString) { result = MFTestResults.Fail; Log.Exception( "<![CDATA[" + testString + " != " + readString + "]]>"); } }
private void ConstructorSuccessTest(string port, int baud, Parity parity, int databits, StopBits stopbits) { try { using (SerialPort serial = new SerialPort(port, baud, parity, databits, stopbits)) { } } catch (ArgumentException) { Log.Comment("Ignore argument exceptions in constructor"); } catch (Exception ex) { Log.Exception("Unexpected exception message for parity: " + parity + " - message: " + ex.Message); result = MFTestResults.Fail; } }
public MFTestResults DataRcdEvent() { if (!IsLoopback) return MFTestResults.Skip; // BUGBUG: 21216 result = MFTestResults.Fail; try { eventCount = 0; eventSerialPort = new SerialPort(Serial.COM1); // register before open eventSerialPort.DataReceived += new SerialDataReceivedEventHandler(eventserialPort_DataReceived_BeforeOpen); eventSerialPort.Open(); eventSerialPort.DataReceived += new SerialDataReceivedEventHandler(eventSerialPort_DataReceived_AfterOpen); eventSerialPort.DataReceived += new SerialDataReceivedEventHandler(eventSerialPort_DataReceived_AfterOpen2); eventSerialPort.Write(sendbuff, 0, sendbuff.Length); eventSerialPort.Flush(); for (int i = 0; i < 100; i++) { Thread.Sleep(100); if (eventCount >= 3) { result = MFTestResults.Pass; break; } } Log.Comment(eventCount + " events fired"); eventSerialPort.Close(); } catch (Exception ex) { Log.Exception(ex.Message); } finally { eventSerialPort.Dispose(); } return result; }
public MFTestResults VerifyValidChars() { if (!IsLoopback) return MFTestResults.Skip; result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Open(); for (int i = 1; i < 255; i++) { string data = new string((char)i, 10); Log.FilteredComment("i = " + i + " chars: " + data); serialPort.VerifyWrite(data); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults SerialPortConstructor_5() { result = MFTestResults.Pass; try { // Valid cases ConstructorSuccessTest(StopBits.None); ConstructorSuccessTest(StopBits.One); ConstructorSuccessTest(StopBits.OnePointFive); ConstructorSuccessTest(StopBits.Two); // No bounds checking so make sure all valid int values are fine. ConstructorSuccessTest(-1); ConstructorSuccessTest(int.MinValue); ConstructorSuccessTest(int.MaxValue); } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults SerialPortConstructor_3() { result = MFTestResults.Pass; try { // Valid cases ConstructorSuccessTest(Parity.Even); ConstructorSuccessTest(Parity.Mark); ConstructorSuccessTest(Parity.None); ConstructorSuccessTest(Parity.Odd); ConstructorSuccessTest(Parity.Space); // No bounds checking so make sure all valid int values are fine. ConstructorSuccessTest(-1); ConstructorSuccessTest(int.MinValue); ConstructorSuccessTest(int.MaxValue); } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults SerialPortConstructor_2() { result = MFTestResults.Pass; try { // Validate all BaudRate values - no casting/bounds tests ConstructorSuccessTest(BaudRate.Baudrate4800); ConstructorSuccessTest(BaudRate.Baudrate9600); ConstructorSuccessTest(BaudRate.Baudrate19200); ConstructorSuccessTest(BaudRate.Baudrate38400); ConstructorSuccessTest(BaudRate.Baudrate57600); ConstructorSuccessTest(BaudRate.Baudrate115200); ConstructorSuccessTest(BaudRate.Baudrate230400); } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
/// <summary> /// Locates the test to run in the classOfTestsToRun and executes that test. Uses reflection to locate the test. /// </summary> /// <param name="classOfTestsToRun">A class that contains tests to be executed.</param> /// <param name="testToRun">The string name of the test to run in the classOfTestsToRun object.</param> /// <returns></returns> private void RunTest() { try { // Get all the types from the class. Type t = classOfTestsToRun.GetType();// System.Reflection.MethodBase.GetCurrentMethod();// FilterTypeNameIgnoreCase.getGetTypesImplementingInterface(typeof(IMFTestInterface)); // Get all the methods and call the one that matches the return type for test methods. MethodInfo[] methods = t.GetMethods(); foreach (MethodInfo method in methods) { //Only get the methods with return type of MFtestResults and that match the name of the function we //are trying to execute. if ((method.ReturnType == typeof(MFTestResults)) && ((method.Name.Trim().ToLower() == testToRun.Trim().ToLower()))) { Console.WriteLine("TEST: " + method.Name + " Starting"); try { object[] param = new object [1]; param[0] = (object)scenarioToRun; object result = method.Invoke(classOfTestsToRun, param); testResult = (MFTestResults)result; if (MFTestResults.Fail == testResult) { Console.WriteLine("TEST: " + method.Name + " " + MFTestResults.Fail.ToString()); } else if (MFTestResults.Pass == testResult) { Console.WriteLine("TEST: " + method.Name + " " + MFTestResults.Pass.ToString()); } else if (MFTestResults.Skip == testResult) { Console.WriteLine("TEST: " + method.Name + " " + MFTestResults.Skip.ToString()); } else if (MFTestResults.KnownFailure == testResult) { Console.WriteLine("TEST: " + method.Name + " " + MFTestResults.KnownFailure.ToString()); } } catch (Exception ex) { Console.WriteLine("Exception trying to run test:" + ex.ToString()); } } } } catch (Exception ex) { Console.WriteLine("Exception trying to run test:" + ex.ToString()); } finally { GC.WaitForPendingFinalizers(); } }
public void Linger(Socket sock) { byte[] bytesReceived = new byte[2]; sock.Receive(bytesReceived); testResult = MFTestResults.Pass; }
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 GetSetBaudRate() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.BaudRate, (int)BaudRate.Baudrate9600); serialPort.BaudRate = (int)BaudRate.Baudrate230400; serialPort.Eval(serialPort.BaudRate, (int)BaudRate.Baudrate230400); serialPort.BaudRate = (int)BaudRate.Baudrate19200; serialPort.EvalOpenClose(serialPort.BaudRate, (int)BaudRate.Baudrate19200); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults AdvancedGetSetTest() { if (!IsLoopback) return MFTestResults.Skip; result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { // Exercise changing rate while open if port is available serialPort.VerifyWrite(); Log.Comment("Change baud and resend"); serialPort.BaudRate = (int)BaudRate.Baudrate19200; serialPort.VerifyWrite(); Log.Comment("Change Parity and resend"); serialPort.Parity = Parity.Even; serialPort.VerifyWrite(); Log.Comment("Change StopBit and resend"); serialPort.StopBits = StopBits.Two; serialPort.VerifyWrite(); Log.Comment("Change DataBits and resend"); serialPort.DataBits = 7; serialPort.VerifyWrite(); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetSetParity() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.Parity, Parity.None); serialPort.Parity = Parity.Even; serialPort.Eval(serialPort.Parity, Parity.Even); serialPort.Parity = Parity.Odd; serialPort.EvalOpenClose(serialPort.Parity, Parity.Odd); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetSetStopBits() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.StopBits, StopBits.One); serialPort.StopBits = StopBits.Two; serialPort.EvalOpenClose(serialPort.StopBits, StopBits.Two); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
public MFTestResults GetSetHandShake() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.Handshake, Handshake.None); serialPort.Handshake = Handshake.RequestToSend; serialPort.EvalOpenClose(serialPort.Handshake, Handshake.RequestToSend); serialPort.Handshake = Handshake.XOnXOff; serialPort.EvalOpenClose(serialPort.Handshake, Handshake.XOnXOff); } if (portCount > 0) { // Validate we can re-reserve all pins using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Handshake = Handshake.RequestToSend; serialPort.EvalOpenClose(serialPort.Handshake, Handshake.RequestToSend); serialPort.Open(); } } // TODO: Write Desktop tests to validate proper function of RTS/XonXoff } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
void eventSerialPort_ErrorReceived_AfterOpen(object sender, SerialErrorReceivedEventArgs e) { if (e.EventType == expectedError) { if (eventCount == 0) { Log.Comment("AfterOpen event fired. Event Type: " + e.EventType); } eventCount++; } // with loopback you can't get a TxFull without an RX FULL else if (!(e.EventType == SerialError.RXOver && expectedError == SerialError.TXFull)) { Log.Exception("Expected EventType " + expectedError + " but received EventType " + e.EventType); result = MFTestResults.Fail; } }
public MFTestResults GetSetWriteTimeout() { result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Eval(serialPort.WriteTimeout, Timeout.Infinite); serialPort.WriteTimeout = 100; serialPort.Eval(serialPort.WriteTimeout, 100); serialPort.WriteTimeout = int.MinValue; serialPort.Eval(serialPort.WriteTimeout, int.MinValue); serialPort.WriteTimeout = int.MaxValue; serialPort.EvalOpenClose(serialPort.WriteTimeout, int.MaxValue); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
private void ArgumentExceptionTest(string port, int baud, Parity parity, int databits, StopBits stopbits, string message) { try { using (SerialPort serial = new SerialPort(port, baud, parity, databits, stopbits)) { } throw new Exception("SerialPort constructor using " + port + " unexpectedly succeeded. ArgumentException expected"); } catch (ArgumentException ex) { if (ex.Message != message) { Log.Exception("Unexpected exception message for port:" + port + " baud:" + baud + " parity:" + parity + " stopbits:" + stopbits + " - message: " + ex.Message); result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected exception for port:" + port + " baud:" + baud + " parity:" + parity + " stopbits:" + stopbits + " - message: " + ex.Message); result = MFTestResults.Fail; } }
public MFTestResults DataBufferTests() { if (!IsLoopback) return MFTestResults.Skip; result = MFTestResults.Pass; try { using (SerialPort serialPort = new SerialPort(Serial.COM1)) { // set flow control so we can fill both RX/TX buffers serialPort.Handshake = Handshake.RequestToSend; serialPort.WriteTimeout = 1000; serialPort.Open(); // buffer data in RX/TX serialPort.Write(sendbuff, 0, sendbuff.Length); Log.Comment("bytes to send: " + serialPort.BytesToWrite); Log.Comment("bytes to read: " + serialPort.BytesToRead); // clear RX buffer serialPort.DiscardInBuffer(); if (serialPort.BytesToRead != 0) { result = MFTestResults.Fail; Log.Exception(serialPort.BytesToRead + " bytes still in buffer after DiscardInBuffer!"); } // clear TX Buffer serialPort.DiscardOutBuffer(); if (serialPort.BytesToWrite != 0) { // BUGBUG: 21224 result = MFTestResults.Fail; Log.Exception(serialPort.BytesToWrite + " bytes still in buffer after DiscardOutBuffer!"); } serialPort.Close(); } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return result; }
internal static void TestResult(string message, MFTestResults result) { if (result == MFTestResults.Pass) { SpotTestLog.StartResultNode("Pass"); Pass(message); } else if (result == MFTestResults.Fail) { SpotTestLog.StartResultNode("Fail"); Fail(message); } else if (result == MFTestResults.Skip) { SpotTestLog.StartResultNode("Skip"); Skip(message); } else if (result == MFTestResults.KnownFailure) { SpotTestLog.StartResultNode("KnownFailure"); KnownFailure(message); } SpotTestLog.EndNode("TestMethodResult"); }
public HttpTestServer(string prefix, ref MFTestResults Result) { listener = new HttpListener(prefix, s_CurrentPort); result = Result; }
public void Linger(Socket sock) { try { byte[] bytesReceived = new byte[400]; sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, m_linger ? 3000: 0 ); int cnt = sock.Receive(bytesReceived); sock.Send(bytesReceived, cnt, SocketFlags.None); testResult = MFTestResults.Pass; sock.Close(); } catch { } }
public HttpServer(string prefix, int Port, ref MFTestResults Result) { serverPrefix = prefix; listener = new HttpListener(prefix, Port); result = Result; }
public MFTestResults ErrorRcvdEvent() { if (!IsLoopback || IsEmulator) return MFTestResults.Skip; result = MFTestResults.Pass; try { eventCount = 0; // create a buffer several bytes bigger then internal buffers byte[] buffer = Encoding.UTF8.GetBytes(new string('a', 512+40)); eventSerialPort = new SerialPort(Serial.COM1); eventSerialPort.WriteTimeout = 1000; eventSerialPort.Handshake = Handshake.None; // register events eventSerialPort.ErrorReceived += new SerialErrorReceivedEventHandler(eventSerialPort_ErrorReceived_BeforeOpen); eventSerialPort.Open(); eventSerialPort.ErrorReceived += new SerialErrorReceivedEventHandler(eventSerialPort_ErrorReceived_AfterOpen); // Test RX overflow (no flow control) expectedError = SerialError.RXOver; eventSerialPort.Write(buffer, 0, buffer.Length / 2); Thread.Sleep(100); eventSerialPort.Write(buffer, 0, buffer.Length / 2); eventSerialPort.Close(); Thread.Sleep(500); if (eventCount == 0) { // BUGBUG: 21222 Log.Exception("Expected RXOver events fired, saw " + eventCount + " fired."); result = MFTestResults.Fail; } eventCount = 0; // Test TX overflow (flow control - HW) expectedError = SerialError.TXFull; eventSerialPort.Open(); for (int i = 0; i < 2; i++) { eventSerialPort.Write(buffer, 0, buffer.Length); } eventSerialPort.Close(); Thread.Sleep(500); if (eventCount == 0) { // BUGBUG: 21222 Log.Exception("Expected TXFull events fired, saw " + eventCount + " fired."); result = MFTestResults.Fail; } // TODO: Need to add PC based tests that allow testing Parity, Overrun, and Frame errors. This is done manually now. } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } finally { eventSerialPort.Dispose(); } return result; }