public Test(int id, string name, TestType type, TestKind kind) { Id = id; Name = name; Type = type; Kind = kind; }
/// <summary> /// Установить текущее направление перевода /// </summary> /// <param name="value"></param> /// <param name="saveOnDisk"></param> public void SetCurrentTestKind(TestKind value, bool saveOnDisk) { _currentTestKind = value; if (saveOnDisk) { Helpers.WriteDiscContent(CURRENT_TEST_KIND_FILE, ((int)value).ToString()); } }
protected void AssertResourceTestBinary(string resourceBasePath, TestKind kind) { var expectedAssemblyPath = resourceBasePath.GetPathOfBinaryResource("Expected.dll", kind); var tbc = ReadResource(resourceBasePath, "cs", kind); var actualAssemblyPath = Path.Combine(Path.GetTempPath(), "CecilifierTests/", resourceBasePath + ".dll"); AssertResourceTest(actualAssemblyPath, expectedAssemblyPath, tbc); }
private void CheckTemplate <T>(BaseChecksum <T> check, string fileName, TestKind kind, T expected) { check.Reset(); try { string filePath = Path.Combine(TestSetup.SampleDir, fileName); using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { switch (kind) { case TestKind.Array: { int bytesRead = 0; byte[] buffer = new byte[64 * 1024]; do { bytesRead = fs.Read(buffer, 0, buffer.Length); check.Append(buffer, 0, bytesRead); }while (0 < bytesRead); } break; case TestKind.Span: { int bytesRead = 0; byte[] buffer = new byte[64 * 1024]; do { bytesRead = fs.Read(buffer, 0, buffer.Length); check.Append(buffer.AsSpan(0, bytesRead)); }while (0 < bytesRead); } break; case TestKind.Stream: check.Append(fs); break; } } Console.WriteLine($"(Check) Expected checksum of {fileName} : 0x{expected:X16}"); Console.WriteLine($"(Check) Calculated checksum of {fileName} : 0x{check.Checksum:X16}"); Assert.AreEqual(expected, check.Checksum); } finally { check.Reset(); } }
internal void AssertResourceTest(string resourceName, TestKind kind, IAssemblyDiffVisitor visitor) { using (var tbc = ReadResource(resourceName, "cs", kind)) { var cecilifierTestsFolder = Path.Combine(Path.GetTempPath(), "CecilifierTests"); var cecilifiedAssemblyPath = Path.Combine(cecilifierTestsFolder, resourceName + ".dll"); var resourceCompiledAssemblyPath = CompilationServices.CompileDLL( Path.Combine(Path.GetDirectoryName(cecilifiedAssemblyPath), Path.GetFileNameWithoutExtension(cecilifiedAssemblyPath) + "_expected"), ReadToEnd(tbc), Utils.GetTrustedAssembliesPath().ToArray()); Console.WriteLine(); Console.WriteLine("Compiled from res : {0}", resourceCompiledAssemblyPath); Console.WriteLine("Generated from Cecilifier: {0}", cecilifiedAssemblyPath); AssertResourceTest(cecilifiedAssemblyPath, resourceCompiledAssemblyPath, tbc, visitor); } }
public static string GetPathOfTextResource(this string resourceName, string type, TestKind kind) { return(GetPathOfResource(resourceName, "." + type + ".txt", kind)); }
private static string GetPathOfResource(string resourceName, string type, TestKind kind) { var basePath = Path.Combine("TestResources", kind.ToString()); return(Path.Combine(basePath, resourceName + type)); }
public static string GetPathOfBinaryResource(this string resourceName, string type, TestKind kind) { return(GetPathOfResource(resourceName, type, kind)); }
/// <summary> /// 设置参数 /// </summary> /// <param name="testKind">选择实验类型</param> /// <param name="ClickNum">按键次数</param> /// <returns></returns> public async Task <bool> SetTestPra(TestKind testKind, byte ClickNum, CancellationToken token) { try { var rec = new byte[2]; byte TestKindByte = 0x00; byte Mark = 0x00; if (testKind == TestKind.ControlsVolateUP) { TestKindByte = 0x01; Mark = 0x01; } if (testKind == TestKind.ControlsVolateDown) { TestKindByte = 0x01; Mark = 0x02; } if (testKind == TestKind.ControlsFreUp) { TestKindByte = 0x02; Mark = 0x03; } if (testKind == TestKind.ControlsFreDown) { TestKindByte = 0x02; Mark = 0x04; } if (testKind == TestKind.Setting) { TestKindByte = 0x03; Mark = 0x05; } if (testKind == TestKind.Start) { TestKindByte = 0x04; Mark = 0x06; } if (testKind == TestKind.Stop) { TestKindByte = 0x05; Mark = 0x07; } byte[] sendc = new byte[5] { 0xA5, TestKindByte, ClickNum, Mark, (byte)(0xA5 + TestKindByte + ClickNum + Mark) }; await Task.Run(() => { Comport.Serial.upserialport.SendCommand(sendc, ref rec, ClickNum * 1000); }); if (rec[0] == 0xaa && rec[1] == Mark) { return(true); } return(false); } catch { _logger.Writer("Class: CommunicationProtocol.SetTestPra出错"); await Task.Delay(100); return(false); } }
public TestId(TestKind testKind, uint number) { Kind = testKind; Number = number; }
public void ModifyMeasurementParameters(byte TestChannel, byte TestSpeed, byte Cn, byte Volate, byte Fre, TestKind kind) { if (kind == TestKind.SetTestChannel) { ChangeTestChannel(TestChannel); } if (kind == TestKind.SetTestSpeed) { ChangeTestSpeed(TestSpeed); } if (kind == TestKind.SetTestCn) { ChangeTestCn(Cn); } if (kind == TestKind.SetTestConfireVolate) { ChangeVolate(Volate); } if (kind == TestKind.SetTestConfireFre) { ChangeFre(Fre); } if (kind == TestKind.StartBooster) { startUpVolate(); } if (kind == TestKind.StartBuck) { startDownVolate(); } }
/// <summary> /// Получить произвольное слово по всем главам в целом /// </summary> /// <param name="chapter"></param> /// <param name="testKind"></param> /// <returns></returns> public static (string value, string valueTranslate) GetRandomWord([NotNull] this TestChapter chapter, TestKind testKind) { var pair = chapter.Pairs[Rnd.Next(chapter.Pairs.Length)]; return(testKind == TestKind.WordIsEnglish ? (pair.rus, pair.eng) : (pair.eng, pair.rus)); }
protected void AssertResourceTest(string resourceName, TestKind kind) { AssertResourceTest(resourceName, kind, new StrictAssemblyDiffVisitor()); }
private Stream ReadResource(string resourceName, string type, TestKind kind) { return(ReadResource(resourceName.GetPathOfTextResource(type, kind))); }
public TestId(TestKind testKind, uint number, string version = "5.0") { Kind = testKind; Number = number; Version = version; }