public async Task ReadAsync_Length_IsNegative() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadAsync(-1); connection.MockReceiveDelayed("Test"); string data = await t; }
public async Task ReadLineAsync() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadLineAsync(); connection.MockReceiveDelayed("Test" + session.NewLine); string data = await t; Assert.AreEqual("Test", data); }
public async Task ReadAsync_4Characters() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadAsync(4); connection.MockReceiveDelayed("Test"); string data = await t; Assert.AreEqual("Test", data); }
public async Task ReadToAsync() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadToAsync(','); connection.MockReceiveDelayed("alpha,beta,gamma"); string data = await t; Assert.AreEqual("alpha", data); }
public async Task Read_NegativeLength() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(-1); } ); connection.MockReceiveDelayed("Hello!!!"); await t; }
public async Task ReceivedStringBufferOverflow() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(2048); } ); connection.MockReceiveDelayed(new string('*', 40480)); await t; }
public async Task ReadTo_EmptyString() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.ReadTo(';'); Assert.AreEqual(string.Empty, data); } ); connection.MockReceiveDelayed(";"); await t; }
public async Task ReadTo() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.ReadTo('.'); Assert.AreEqual("A line", data); } ); connection.MockReceiveDelayed("A line."); await t; }
public async Task Read_StringBlock() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(6); Assert.AreEqual("Hello!", data); } ); connection.MockReceiveDelayed("Hello!!!"); await t; }
//[TestMethod] public void StringReceived() { string s = null; var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.NewLine = "\n"; session.StringReceived += (o, e) => { s = e.Text; }; connection.MockReceiveDelayed("ACME\n"); Assert.AreEqual("ACME", s); }
public async Task Read_OneCharacter() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(); Assert.AreEqual("Z", data); } ); connection.MockReceiveDelayed("Zxxxx"); await t; }
public async Task ReadLine_CarriageReturn() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.NewLine = "\r"; var t = Task.Run(() => { string data = session.ReadLine(); Assert.AreEqual("A line.", data); } ); connection.MockReceiveDelayed("A line." + session.NewLine); await t; }
public void test() { var connection = new MockSerialConnection(); var session = CreateFirmataSession(connection, 3); //发送获取固件信息 Arduino-Firmata-Serial.ino V 2.10 //F0 79 F7 connection.MockReceiveDelayed(new byte[] { 0xF0, 0x79, 0x02, 0x0a, 0x41, 0x00, 0x72, 0x00, 0x64, 0x00, 0x75, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x6f, 0x00, 0x2d, 0x00, 0x46, 0x00, 0x69, 0x00, 0x72, 0x00, 0x6d, 0x00, 0x61, 0x00, 0x74, 0x00, 0x61, 0x00, 0x2d, 0x00, 0x53, 0x00, 0x65, 0x00, 0x72, 0x00, 0x69, 0x00, 0x61, 0x00, 0x6c, 0x00, 0x2e, 0x00, 0x69, 0x00, 0x6e, 0x00, 0x6f, 0x00, 0xF7 }); //connection.EnqueueResponse(Name.To14BitIso()); //connection.EnqueueResponse(0xF7); var f = session.GetMessageFromQueue <Firmware>().Value; }
//[TestMethod] // Verdacht public async Task RequestBufferOverflow() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var tasks = new List <Task <string> >(100); for (int x = 0; x < 100; x++) { tasks.Add(session.ReadAsync()); } Thread.Sleep(250); connection.MockReceiveDelayed(new string('*', 100)); await Task.WhenAll(tasks); foreach (Task <string> t in tasks) { Assert.AreEqual("*", t.Result); } }
public async Task Read_OneCharacter() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(); Assert.AreEqual("Z", data); } ); connection.MockReceiveDelayed("Zxxxx"); await t; }
public async Task ReadToAsync() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadToAsync(','); connection.MockReceiveDelayed("alpha,beta,gamma"); string data = await t; Assert.AreEqual("alpha", data); }
public async Task ReadLineAsync() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadLineAsync(); connection.MockReceiveDelayed("Test" + session.NewLine); string data = await t; Assert.AreEqual("Test", data); }
public async Task ReadAsync_Length_IsNegative() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadAsync(-1); connection.MockReceiveDelayed("Test"); string data = await t; }
public async Task ReadAsync_4Characters() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = session.ReadAsync(4); connection.MockReceiveDelayed("Test"); string data = await t; Assert.AreEqual("Test", data); }
public async Task ReadTo_EmptyString() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.ReadTo(';'); Assert.AreEqual(string.Empty, data); } ); connection.MockReceiveDelayed(";"); await t; }
public async Task ReadTo() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.ReadTo('.'); Assert.AreEqual("A line", data); } ); connection.MockReceiveDelayed("A line."); await t; }
public async Task ReadLine_CarriageReturnPlusLinefeed() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.NewLine = "\r\n"; var t = Task.Run(() => { string data = session.ReadLine(); Assert.AreEqual("A line.", data); data = session.ReadLine(); Assert.AreEqual("Second line.", data); } ); connection.MockReceiveDelayed("A line." + session.NewLine + "Second line." + session.NewLine); await t; }
public async Task Read_NegativeLength() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(-1); } ); connection.MockReceiveDelayed("Hello!!!"); await t; }
public async Task Read_StringBlock() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(6); Assert.AreEqual("Hello!", data); } ); connection.MockReceiveDelayed("Hello!!!"); await t; }
//[TestMethod] // Verdacht public async Task RequestBufferOverflow() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var tasks = new List<Task<string>>(100); for (int x = 0; x < 100; x++) tasks.Add(session.ReadAsync()); Thread.Sleep(250); connection.MockReceiveDelayed(new string('*', 100)); await Task.WhenAll(tasks); foreach (Task<string> t in tasks) { Assert.AreEqual("*", t.Result); } }
public async Task ReceivedStringBufferOverflow() { var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); var t = Task.Run(() => { string data = session.Read(1000); } ); connection.MockReceiveDelayed(new string('*', 3000)); await t; }
//[TestMethod] public void StringReceived() { string s = null; var connection = new MockSerialConnection(); var session = CreateSerialSession(connection); session.NewLine = "\n"; session.StringReceived += (o, e) => { s = e.Text; }; connection.MockReceiveDelayed("ACME\n"); Assert.AreEqual("ACME", s); }