public void OnBuildScriptExit() { void ScriptTemplate(string treePath, string entrySection, ErrorCheck check = ErrorCheck.Success) { (EngineState s, _) = EngineTests.EvalScript(treePath, check, entrySection); string destStr = s.Variables["Dest"]; Assert.IsTrue(destStr.Equals("T", StringComparison.Ordinal)); } string scPath = Path.Combine(EngineTests.Project.ProjectName, "System", "Callback.script"); // OnBuildExit ScriptTemplate(scPath, "Process-BuildCallback"); // OnScriptExit ScriptTemplate(scPath, "Process-ScriptCallback"); }
public void WriteTemplate(EngineState s, string rawCode, string listStr, string destCheck, ErrorCheck check = ErrorCheck.Success) { if (listStr == null) { s.Variables.DeleteKey(VarsType.Local, "listStr"); } else { s.Variables["ListStr"] = listStr; } EngineTests.Eval(s, rawCode, CodeType.List, check); if (check == ErrorCheck.Success || check == ErrorCheck.Warning) { string dest = s.Variables["ListStr"]; Assert.IsTrue(dest.Equals(destCheck, StringComparison.Ordinal)); } }
public void BitShift() { EngineState s = EngineTests.CreateEngineState(); // BitShift SuccessTemplate(s, "Math,BitShift,%Dest%,8,LEFT,2,32", "32"); // 32bit SuccessTemplate(s, "Math,BitShift,%Dest%,9,RIGHT,1,32", "4"); // 32bit SuccessTemplate(s, "Math,BitShift,%Dest%,7,LEFT,7,16", "896"); // 16bit SuccessTemplate(s, "Math,BitShift,%Dest%,7,LEFT,7,8", "128"); // 8bit // Test Error ErrorTemplate(s, "Math,BitShift,%Dest%,8,LEFT,2", ErrorCheck.ParserError); // Had been valid prior to 0.9.6 beta6 ErrorTemplate(s, "Math,BitShift,%Dest%,9,RIGHT,1", ErrorCheck.ParserError); // Had been valid prior to 0.9.6 beta6 ErrorTemplate(s, "Math,BitShift,Dest,8,LEFT,2", ErrorCheck.ParserError); ErrorTemplate(s, "Math,BitShift,%Dest%,12,9", ErrorCheck.ParserError); ErrorTemplate(s, "Math,BitShift,%Dest%,123,LEFT,7,19", ErrorCheck.ParserError); ErrorTemplate(s, "Math,BitShift,%Dest%,XYZ,LEFT,7,16", ErrorCheck.RuntimeError); }
public void CodeParserEx() { StringBuilder b = new StringBuilder(); b.AppendLine("If,ExistDir,%BaseDir%,Begin"); b.AppendLine(" Set,%A%,True"); b.AppendLine(" Echo,Hello"); b.AppendLine("End"); b.AppendLine("Else,Echo,World"); b.AppendLine(@"FileCopy,1,2"); PEBakeryScriptParser parser = Setup(b.ToString()); CodesVisitor visitor = new CodesVisitor(EngineTests.DummySectionAddress()); List <CodeCommand> cmds = visitor.Visit(parser.codes()); Assert.IsTrue(cmds != null); }
public void Dec() { EngineState s = EngineTests.CreateEngineState(); s.Variables["BitSize"] = "16"; s.Variables["Garbage"] = "128"; // 8bit SuccessTemplate(s, "Math,Dec,%Dest%,0x0F,8", "15"); SuccessTemplate(s, "Math,Dec,%Dest%,0xFF,8", "255"); SuccessTemplate(s, "Math,Dec,%Dest%,-1,8", "255"); SuccessTemplate(s, "Math,Dec,%Dest%,255,8", "255"); ErrorTemplate(s, "Math,Dec,%Dest%,0xFFFF,8", ErrorCheck.RuntimeError); // 16bit SuccessTemplate(s, "Math,Dec,%Dest%,0x000F,16", "15"); SuccessTemplate(s, "Math,Dec,%Dest%,-1,16", "65535"); SuccessTemplate(s, "Math,Dec,%Dest%,0xFFFF,16", "65535"); ErrorTemplate(s, "Math,Dec,%Dest%,0x10000,16", ErrorCheck.RuntimeError); // 16bit (Variable) SuccessTemplate(s, "Math,Dec,%Dest%,0x000F,%BitSize%", "15"); SuccessTemplate(s, "Math,Dec,%Dest%,-1,%BitSize%", "65535"); SuccessTemplate(s, "Math,Dec,%Dest%,0xFFFF,%BitSize%", "65535"); ErrorTemplate(s, "Math,Dec,%Dest%,0x10000,%BitSize%", ErrorCheck.RuntimeError); // 32bit SuccessTemplate(s, "Math,Dec,%Dest%,0x0F,32", "15"); SuccessTemplate(s, "Math,Dec,%Dest%,-1,32", "4294967295"); ErrorTemplate(s, "Math,Dec,%Dest%,0x100000000,32", ErrorCheck.RuntimeError); ErrorTemplate(s, "Math,Dec,%Dest%,0x0F", ErrorCheck.ParserError); // Had been valid prior to 0.9.6 beta6 ErrorTemplate(s, "Math,Dec,%Dest%,-1", ErrorCheck.ParserError); // Had been valid prior to 0.9.6 beta6 ErrorTemplate(s, "Math,Dec,%Dest%,0x100000000", ErrorCheck.ParserError); // 64bit SuccessTemplate(s, "Math,Dec,%Dest%,0x0F,64", "15"); SuccessTemplate(s, "Math,Dec,%Dest%,-1,64", "18446744073709551615"); // Test Error ErrorTemplate(s, "Math,Dec,%Dest%,0x000F,%Garbage%", ErrorCheck.RuntimeError); ErrorTemplate(s, "Math,Dec,%Dest%", ErrorCheck.ParserError); ErrorTemplate(s, "Math,Dec,%Dest%,256,9", ErrorCheck.ParserError); ErrorTemplate(s, "Math,Dec,%Dest%,256,9,12", ErrorCheck.ParserError); }
public void Math_Arithmetic() { EngineState s = EngineTests.CreateEngineState(); // Add Math_Template(s, "Math,Add,%Dest%,100,200", "300"); Math_Template(s, "Math,Add,%Dest%,100.1,200", "300.1"); Math_Template(s, "Math,Add,%Dest%,100,200.2", "300.2"); Math_Template(s, "Math,Add,%Dest%,100.1,200.2", "300.3"); Math_Template(s, "Math,Add,%Dest%,100.0,200.0", "300.0"); Math_Template(s, "Math,Add,%Dest%,-300,100", "-200"); // Sub Math_Template(s, "Math,Sub,%Dest%,200,100", "100"); Math_Template(s, "Math,Sub,%Dest%,200.1,100", "100.1"); Math_Template(s, "Math,Sub,%Dest%,200,100.2", "99.8"); Math_Template(s, "Math,Sub,%Dest%,200.1,100.2", "99.9"); Math_Template(s, "Math,Sub,%Dest%,200.0,100.0", "100.0"); Math_Template(s, "Math,Sub,%Dest%,100,200", "-100"); Math_Template(s, "Math,Sub,%Dest%,100,-200", "300"); // Mul Math_Template(s, "Math,Mul,%Dest%,3,2", "6"); Math_Template(s, "Math,Mul,%Dest%,3,2.1", "6.3"); Math_Template(s, "Math,Mul,%Dest%,3.2,2", "6.4"); Math_Template(s, "Math,Mul,%Dest%,3.2,2.1", "6.72"); Math_Template(s, "Math,Mul,%Dest%,3.0,2.0", "6.00"); Math_Template(s, "Math,Mul,%Dest%,-3,2", "-6"); Math_Template(s, "Math,Mul,%Dest%,0.2,0.5", "0.10"); // Div Math_Template(s, "Math,Div,%Dest%,4,2", "2"); Math_Template(s, "Math,Div,%Dest%,4.5,1.5", "3"); Math_Template(s, "Math,Div,%Dest%,4.5,-1.5", "-3"); Math_Template(s, "Math,Div,%Dest%,10,3", "3.3333333333333333333333333333"); // 소숫점 이하 28자리 // Test Error Math_Template_Error(s, "Math,Add,Dest,4", ErrorCheck.ParserError); Math_Template_Error(s, "Math,Sub,3,4", ErrorCheck.ParserError); Math_Template_Error(s, "Math,Mul,%Dest%,4", ErrorCheck.ParserError); Math_Template_Error(s, "Math,Div,%Dest%,4,2,1", ErrorCheck.ParserError); Math_Template_Error(s, "Math,Add,%Dest%,T,3", ErrorCheck.Error); }
public void File_FileCreateBlank() { // FileCreateBlank,<FilePath>[,PRESERVE][,NOWARN][,UTF8|UTF16|UTF16BE|ANSI] EngineState s = EngineTests.CreateEngineState(); string scriptDirPath = Path.Combine("%TestBench%", "CommandFile"); string scriptDestDir = Path.Combine(scriptDirPath, DestDir_FileCreateBlank); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt", "A.txt", Encoding.Default, false); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt,UTF8", "A.txt", Encoding.UTF8, false); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt,UTF16", "A.txt", Encoding.Unicode, false); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt,UTF16BE", "A.txt", Encoding.BigEndianUnicode, false); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt", "A.txt", Encoding.Default, true, ErrorCheck.Overwrite); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt,PRESERVE", "A.txt", Encoding.Default, true, ErrorCheck.Overwrite); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt,PRESERVE", "A.txt", Encoding.Default, false); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt,NOWARN", "A.txt", Encoding.Default, true); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt,NOWARN", "A.txt", Encoding.Default, false); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt,PRESERVE,NOWARN", "A.txt", Encoding.Default, true); FileCreateBlank_Template(s, $@"FileCreateBlank,{scriptDestDir}\A.txt,PRESERVE,NOWARN", "A.txt", Encoding.Default, false); }
public void IniRead() { EngineState s = EngineTests.CreateEngineState(); string sampleStr = SampleStr(); string tempDir = FileHelper.GetTempDir(); try { string tempFile = Path.Combine(tempDir, "sample.ini"); string tempFile2 = Path.Combine(tempDir, "empty.ini"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec1,A,%Dest%", tempFile, sampleStr, "1"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec1,B,%Dest%", tempFile, sampleStr, "2"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec2,Z,%Dest%", tempFile, sampleStr, "6"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec3,나,%Dest%", tempFile, sampleStr, "8"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec2,無,%Dest%", tempFile, sampleStr, string.Empty); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec2,Z", tempFile, string.Empty, null, ErrorCheck.ParserError); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Doublequote,DQ1,%Dest%", tempFile, sampleStr, "#$qA B C#$q"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Doublequote,DQ2,%Dest%", tempFile, sampleStr, "#$qX\\Y\\Z#$q"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Doublequote,CUR_DIR,%Dest%", tempFile, sampleStr, "#$qCursors\\Material Design Cursors#$q"); // Optimization ReadOptTemplate(s, CodeType.IniReadOp, new List <string> { $@"IniRead,{tempFile},Sec1,A,%Dest0%", $@"IniRead,{tempFile},Sec1,B,%Dest1%", $@"IniRead,{tempFile},Sec2,Z,%Dest2%", $@"IniRead,{tempFile},Sec3,나,%Dest3%", }, tempFile, sampleStr, new string[] { "1", "2", "6", "8" }); ReadOptTemplate(s, null, new List <string> { $@"IniRead,{tempFile},Sec1,A,%Dest0%", $@"IniRead,{tempFile},Sec1,B,%Dest1%", $@"IniRead,{tempFile},Sec2,Z,%Dest2%", $@"IniRead,{tempFile2},Sec3,나,%Dest3%", }, tempFile, sampleStr, new string[] { "1", "2", "6" }); } finally { Directory.Delete(tempDir, true); } }
public void Arithmetic() { EngineState s = EngineTests.CreateEngineState(); // Add SuccessTemplate(s, "Math,Add,%Dest%,100,200", "300"); SuccessTemplate(s, "Math,Add,%Dest%,100.1,200", "300.1"); SuccessTemplate(s, "Math,Add,%Dest%,100,200.2", "300.2"); SuccessTemplate(s, "Math,Add,%Dest%,100.1,200.2", "300.3"); SuccessTemplate(s, "Math,Add,%Dest%,100.0,200.0", "300.0"); SuccessTemplate(s, "Math,Add,%Dest%,-300,100", "-200"); // Sub SuccessTemplate(s, "Math,Sub,%Dest%,200,100", "100"); SuccessTemplate(s, "Math,Sub,%Dest%,200.1,100", "100.1"); SuccessTemplate(s, "Math,Sub,%Dest%,200,100.2", "99.8"); SuccessTemplate(s, "Math,Sub,%Dest%,200.1,100.2", "99.9"); SuccessTemplate(s, "Math,Sub,%Dest%,200.0,100.0", "100.0"); SuccessTemplate(s, "Math,Sub,%Dest%,100,200", "-100"); SuccessTemplate(s, "Math,Sub,%Dest%,100,-200", "300"); // Mul SuccessTemplate(s, "Math,Mul,%Dest%,3,2", "6"); SuccessTemplate(s, "Math,Mul,%Dest%,3,2.1", "6.3"); SuccessTemplate(s, "Math,Mul,%Dest%,3.2,2", "6.4"); SuccessTemplate(s, "Math,Mul,%Dest%,3.2,2.1", "6.72"); SuccessTemplate(s, "Math,Mul,%Dest%,3.0,2.0", "6.00"); SuccessTemplate(s, "Math,Mul,%Dest%,-3,2", "-6"); SuccessTemplate(s, "Math,Mul,%Dest%,0.2,0.5", "0.10"); // Div SuccessTemplate(s, "Math,Div,%Dest%,4,2", "2"); SuccessTemplate(s, "Math,Div,%Dest%,4.5,1.5", "3"); SuccessTemplate(s, "Math,Div,%Dest%,4.5,-1.5", "-3"); SuccessTemplate(s, "Math,Div,%Dest%,10,3", "3.3333333333333333333333333333"); // 28 numbers after dot // Test Error ErrorTemplate(s, "Math,Add,Dest,4", ErrorCheck.ParserError); ErrorTemplate(s, "Math,Sub,3,4", ErrorCheck.ParserError); ErrorTemplate(s, "Math,Mul,%Dest%,4", ErrorCheck.ParserError); ErrorTemplate(s, "Math,Div,%Dest%,4,2,1", ErrorCheck.ParserError); ErrorTemplate(s, "Math,Add,%Dest%,T,3", ErrorCheck.RuntimeError); }
private static void ReadOptTemplate( EngineState s, CodeType?opType, List <string> rawCodes, string testFile, string sampleStr, string[] compStrs, ErrorCheck check = ErrorCheck.Success) { if (File.Exists(testFile)) { File.Delete(testFile); } File.Create(testFile).Close(); try { EncodingHelper.WriteTextBom(testFile, Encoding.UTF8); using (StreamWriter w = new StreamWriter(testFile, true, Encoding.UTF8)) { w.Write(sampleStr); } for (int i = 0; i < compStrs.Length; i++) { s.Variables.Delete(VarsType.Local, $"Dest{i}"); } EngineTests.EvalOptLines(s, opType, rawCodes, check); if (check == ErrorCheck.Success || check == ErrorCheck.Warning) { for (int i = 0; i < compStrs.Length; i++) { string compStr = compStrs[i]; string destKey = $"Dest{i}"; Assert.IsTrue(s.Variables.ContainsKey(destKey)); Assert.IsTrue(s.Variables[destKey].Equals(compStr, StringComparison.Ordinal)); } } } finally { if (File.Exists(testFile)) { File.Delete(testFile); } } }
public void Compress_FileTemplate(string arcType, string srcFilePath, string destArc, ArchiveHelper.CompressLevel level, string encodingStr = null) { // Compress,<ArchiveType>,<SrcPath>,<DestArchive>,[CompressLevel],[UTF8|UTF16|UTF16BE|ANSI] EngineState s = EngineTests.CreateEngineState(); string dirPath = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandArchive")); string destDir = Path.Combine(dirPath, "Compress_Dest"); string compRootDir = Path.Combine(dirPath, "Compress_Comp"); string compDir = Path.Combine(compRootDir, destArc); string srcFullPath = Path.Combine(dirPath, srcFilePath); string destFullPath = Path.Combine(destDir, destArc); string srcFileName = Path.GetFileName(srcFilePath); try { Directory.CreateDirectory(destDir); Directory.CreateDirectory(compDir); string rawCode = $"Compress,{arcType},\"%TestBench%\\CommandArchive\\{srcFilePath}\",\"%TestBench%\\CommandArchive\\Compress_Dest\\{destArc}\""; if (encodingStr != null) { rawCode += "," + encodingStr; } EngineTests.Eval(s, rawCode, CodeType.Compress, ErrorCheck.Success, out CodeCommand cmd); Debug.Assert(cmd.Info.GetType() == typeof(CodeInfo_Compress)); CodeInfo_Compress info = cmd.Info as CodeInfo_Compress; ArchiveHelper.DecompressManaged(destFullPath, compDir, true, info.Encoding); using (FileStream srcStream = new FileStream(srcFullPath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (FileStream destStream = new FileStream(Path.Combine(compDir, srcFileName), FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] srcDigest = HashHelper.CalcHash(HashType.SHA256, srcStream); byte[] destDigest = HashHelper.CalcHash(HashType.SHA256, destStream); Assert.IsTrue(srcDigest.SequenceEqual(destDigest)); } } finally { Directory.Delete(destDir, true); Directory.Delete(compRootDir, true); } }
public void Expand_DirTemplate(EngineState s, string archiveFile, string compDir, int rev, string rawCode, ErrorCheck check, bool testPreserve = false, bool checkIfPreserve = true) { string dirPath = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandArchive")); string srcPath = Path.Combine(dirPath, "Cab"); string destPath = Path.Combine(dirPath, $"Expand_{rev}"); try { if (testPreserve) // Check preserve { File.Create(destPath).Close(); } EngineTests.Eval(s, rawCode, CodeType.Expand, check); string[] srcFiles = Directory.GetFiles(srcPath, "*", SearchOption.AllDirectories); string[] destFiles = Directory.GetFiles(destPath, "*", SearchOption.AllDirectories); Assert.IsTrue(srcFiles.Length == destFiles.Length); if ((!testPreserve && Directory.Exists(destPath)) || (testPreserve && checkIfPreserve)) { for (int i = 0; i < srcFiles.Length; i++) { using (FileStream srcStream = new FileStream(srcFiles[i], FileMode.Open, FileAccess.Read, FileShare.Read)) using (FileStream destStream = new FileStream(destFiles[i], FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] srcDigest = HashHelper.CalcHash(HashType.SHA256, srcStream); byte[] destDigest = HashHelper.CalcHash(HashType.SHA256, destStream); Assert.IsTrue(srcDigest.SequenceEqual(destDigest)); } } } Console.WriteLine($"{archiveFile} Success"); } finally { Directory.Delete(destPath, true); } }
private void Text_Template( EngineState s, CodeType type, string rawCode, string testFile, string sampleStr, string comp, ErrorCheck check = ErrorCheck.Success) { if (File.Exists(testFile)) { File.Delete(testFile); } File.Create(testFile).Close(); try { FileHelper.WriteTextBOM(testFile, Encoding.UTF8); using (StreamWriter w = new StreamWriter(testFile, true, Encoding.UTF8)) { w.Write(sampleStr); } EngineTests.Eval(s, rawCode, type, check); if (check == ErrorCheck.Success || check == ErrorCheck.Warning) { string dest; using (StreamReader r = new StreamReader(testFile, Encoding.UTF8)) { dest = r.ReadToEnd(); } Assert.IsTrue(dest.Equals(comp, StringComparison.Ordinal)); } } finally { if (File.Exists(testFile)) { File.Delete(testFile); } } }
public void Branch_IfExistSection() { EngineState s = EngineTests.CreateEngineState(); BranchCondition cond; BranchConditionType type = BranchConditionType.ExistSection; string tempPath = Path.GetTempFileName(); try { using (StreamWriter w = new StreamWriter(tempPath, false, Encoding.UTF8)) { w.WriteLine("[Hello]"); w.WriteLine("A=1"); w.WriteLine(); w.WriteLine("[World]"); w.WriteLine("B=2"); } cond = new BranchCondition(type, false, tempPath, "Hello"); Assert.IsTrue(cond.Check(s, out string d)); cond = new BranchCondition(type, false, tempPath, "PEBakery"); Assert.IsFalse(cond.Check(s, out d)); cond = new BranchCondition(type, true, tempPath, "Hello"); Assert.IsFalse(cond.Check(s, out d)); cond = new BranchCondition(type, true, tempPath, "PEBakery"); Assert.IsTrue(cond.Check(s, out d)); BranchCondition_Single_Template(s, $"If,ExistSection,{tempPath},Hello,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,ExistSection,{tempPath},PEBakery,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,ExistSection,{tempPath},Hello,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,ExistSection,{tempPath},PEBakery,Set,%Dest%,T", "T"); } finally { if (File.Exists(tempPath)) { File.Delete(tempPath); } } }
private void RegDelete_Template(EngineState s, string rawCode, RegistryKey hKey, string keyPath, string valueName, bool createDummy = true, ErrorCheck check = ErrorCheck.Success) { // RegDelete,<HKey>,<KeyPath>,[ValueName] if (createDummy) { using (RegistryKey subKey = hKey.CreateSubKey(keyPath, true)) { Assert.IsNotNull(subKey); subKey.SetValue(valueName, 0, RegistryValueKind.DWord); } } EngineTests.Eval(s, rawCode, CodeType.RegDelete, check); if (check == ErrorCheck.Success || check == ErrorCheck.Warning) { if (valueName == null) { using (RegistryKey subKey = hKey.OpenSubKey(keyPath, false)) { Assert.IsNull(subKey); } } else { using (RegistryKey subKey = hKey.OpenSubKey(keyPath, false)) { if (createDummy) { Assert.IsNotNull(subKey); object valueData = subKey.GetValue(valueName); Assert.IsNull(valueData); } else { Assert.IsNull(subKey); } } } } }
public void Math_IntDiv() { EngineState s = EngineTests.CreateEngineState(); // IntDiv Math_IntDiv_Template(s, "Math,IntDiv,%DestQ%,%DestR%,0x3,2", "1", "1"); Math_IntDiv_Template(s, "Math,IntDiv,%DestQ%,%DestR%,10,3", "3", "1"); Math_IntDiv_Template(s, "Math,IntDiv,%DestQ%,%DestR%,10,-3", "-3", "1"); Math_IntDiv_Template(s, "Math,IntDiv,%DestQ%,%DestR%,-10,3", "-3", "-1"); Math_IntDiv_Template(s, "Math,IntDiv,%DestQ%,%DestR%,-10,-3", "3", "-1"); // Test Error Math_Template_Error(s, "Math,IntDiv,DestQ,%DestR%,3,2", ErrorCheck.ParserError); Math_Template_Error(s, "Math,IntDiv,%DestQ%,DestR,3,2", ErrorCheck.ParserError); Math_Template_Error(s, "Math,IntDiv,%DestQ%,%DestR%,3,2,1", ErrorCheck.ParserError); Math_Template_Error(s, "Math,IntDiv,%DestQ%,%DestR%,3", ErrorCheck.ParserError); Math_Template_Error(s, "Math,IntDiv,%DestQ%,%DestR%,3,F", ErrorCheck.Error); Math_Template_Error(s, "Math,IntDiv,%DestQ%,%DestR%,A,F", ErrorCheck.Error); Math_Template_Error(s, "Math,IntDiv,%DestQ%,%DestR%,B,C", ErrorCheck.Error); }
public void FileVersion() { EngineState s = EngineTests.CreateEngineState(); string scriptDirPath = Path.Combine("%TestBench%", "CommandFile"); string scriptSrcDir = Path.Combine(scriptDirPath, SrcDirFile); void Template(string rawCode, string comp, ErrorCheck check = ErrorCheck.Success) { EngineTests.Eval(s, rawCode, CodeType.FileVersion, check); if (check == ErrorCheck.Success) { Assert.IsTrue(s.Variables["Dest"].Equals(comp, StringComparison.Ordinal)); } } // bt11_exe and bt20_exe BatteryLine's binary (https://github.com/ied206/BatteryLine) Template($@"FileVersion,{scriptSrcDir}\bt11_exe,%Dest%", "0.0.0.0"); Template($@"FileVersion,{scriptSrcDir}\bt20_exe,%Dest%", "2.0.0.0"); Template($@"Retrieve,FileVersion,{scriptSrcDir}\bt20_exe,%Dest%", "2.0.0.0"); }
public void File_FileCopy() { // FileCopy,<SrcFile>,<DestPath>[,PRESERVE][,NOWARN][,NOREC] EngineState s = EngineTests.CreateEngineState(); string scriptDirPath = Path.Combine("%TestBench%", "CommandFile"); string scriptSrcDir = Path.Combine(scriptDirPath, SrcDir_File); string scriptDestDir = Path.Combine(scriptDirPath, DestDir_FileCopy); FileCopy_SingleTemplate(s, $@"FileCopy,{scriptSrcDir}\A.txt,{scriptDestDir}", "A.txt", null); FileCopy_SingleTemplate(s, $@"FileCopy,{scriptSrcDir}\A.txt,{scriptDestDir}\B.txt", "A.txt", "B.txt"); FileCopy_SingleTemplate(s, $@"FileCopy,{scriptSrcDir}\Z\Y.ini,{scriptDestDir}", Path.Combine("Z", "Y.ini"), "Y.ini"); FileCopy_MultiTemplate(s, $@"FileCopy,{scriptSrcDir}\*.txt,{scriptDestDir}", "*.txt", true); FileCopy_MultiTemplate(s, $@"FileCopy,{scriptSrcDir}\*.ini,{scriptDestDir},NOREC", "*.ini", false); FileCopy_SingleTemplate(s, $@"FileCopy,{scriptSrcDir}\P.txt,{scriptDestDir}", "P.txt", null, ErrorCheck.Error); FileCopy_SingleTemplate(s, $@"FileCopy,{scriptSrcDir}\C.txt,{scriptDestDir}", "C.txt", null, ErrorCheck.Overwrite, true); FileCopy_SingleTemplate(s, $@"FileCopy,{scriptSrcDir}\C.txt,{scriptDestDir},NOWARN", "C.txt", null, ErrorCheck.Success, true); FileCopy_SingleTemplate(s, $@"FileCopy,{scriptSrcDir}\C.txt,{scriptDestDir},PRESERVE", "C.txt", null, ErrorCheck.Overwrite, true); FileCopy_SingleTemplate(s, $@"FileCopy,{scriptSrcDir}\C.txt,{scriptDestDir},PRESERVE,NOWARN", "C.txt", null, ErrorCheck.Success, true, true); }
public void Hex() { EngineState s = EngineTests.CreateEngineState(); // 8bit SuccessTemplate(s, "Math,Hex,%Dest%,15,8", "0x0F"); SuccessTemplate(s, "Math,Hex,%Dest%,0x0F,8", "0x0F"); SuccessTemplate(s, "Math,Hex,%Dest%,-1,8", "0xFF"); SuccessTemplate(s, "Math,Hex,%Dest%,255,8", "0xFF"); ErrorTemplate(s, "Math,Hex,%Dest%,2000,8", ErrorCheck.Error); // 16bit SuccessTemplate(s, "Math,Hex,%Dest%,15,16", "0x000F"); SuccessTemplate(s, "Math,Hex,%Dest%,0x0F,16", "0x000F"); SuccessTemplate(s, "Math,Hex,%Dest%,-1,16", "0xFFFF"); SuccessTemplate(s, "Math,Hex,%Dest%,255,16", "0x00FF"); // 32bit SuccessTemplate(s, "Math,Hex,%Dest%,15,32", "0x0000000F"); SuccessTemplate(s, "Math,Hex,%Dest%,0x0F,32", "0x0000000F"); SuccessTemplate(s, "Math,Hex,%Dest%,-1,32", "0xFFFFFFFF"); SuccessTemplate(s, "Math,Hex,%Dest%,255,32", "0x000000FF"); // 32bit (default) SuccessTemplate(s, "Math,Hex,%Dest%,15", "0x0000000F"); SuccessTemplate(s, "Math,Hex,%Dest%,0x0F", "0x0000000F"); SuccessTemplate(s, "Math,Hex,%Dest%,-1", "0xFFFFFFFF"); SuccessTemplate(s, "Math,Hex,%Dest%,255", "0x000000FF"); // 64bit SuccessTemplate(s, "Math,Hex,%Dest%,15,64", "0x000000000000000F"); SuccessTemplate(s, "Math,Hex,%Dest%,0x0F,64", "0x000000000000000F"); SuccessTemplate(s, "Math,Hex,%Dest%,-1,64", "0xFFFFFFFFFFFFFFFF"); SuccessTemplate(s, "Math,Hex,%Dest%,255,64", "0x00000000000000FF"); // Test Error ErrorTemplate(s, "Math,Hex,%Dest%", ErrorCheck.ParserError); ErrorTemplate(s, "Math,Hex,%Dest%,256,9", ErrorCheck.ParserError); ErrorTemplate(s, "Math,Hex,%Dest%,256,9,12", ErrorCheck.ParserError); ErrorTemplate(s, "Math,Hex,%Dest%,256,8", ErrorCheck.Error); }
public void Branch_IfWimExistIndex() { EngineState s = EngineTests.CreateEngineState(); BranchCondition cond; BranchConditionType type = BranchConditionType.WimExistIndex; string srcWim = Path.Combine("%TestBench%", "CommandWim", "MultiImage.wim"); cond = new BranchCondition(type, false, srcWim, "0"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, srcWim, "1"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, srcWim, "2"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, srcWim, "3"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, false, srcWim, "4"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, srcWim, "0"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, srcWim, "1"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, srcWim, "2"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, srcWim, "3"); Assert.IsFalse(CommandBranch.CheckBranchCondition(s, cond, out _)); cond = new BranchCondition(type, true, srcWim, "4"); Assert.IsTrue(CommandBranch.CheckBranchCondition(s, cond, out _)); BranchCondition_Single_Template(s, $"If,WimExistIndex,{srcWim},0,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,WimExistIndex,{srcWim},1,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,WimExistIndex,{srcWim},2,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,WimExistIndex,{srcWim},3,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,WimExistIndex,{srcWim},4,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,WimExistIndex,{srcWim},0,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, $"If,Not,WimExistIndex,{srcWim},1,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,WimExistIndex,{srcWim},2,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,WimExistIndex,{srcWim},3,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, $"If,Not,WimExistIndex,{srcWim},4,Set,%Dest%,T", "T"); }
private void DirMake_Template(EngineState s, string rawCode, string dirName, ErrorCheck check = ErrorCheck.Success, bool createDir = false, bool createFile = false) { string dirPath = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandFile")); string destDir = Path.Combine(dirPath, DestDir_DirMake); string destFullPath = Path.Combine(destDir, dirName); if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } try { if (createDir) { Directory.CreateDirectory(destFullPath); } else if (createFile) { Directory.CreateDirectory(destDir); File.Create(destFullPath).Close(); } EngineTests.Eval(s, rawCode, CodeType.DirMake, check); if (check == ErrorCheck.Success) { Assert.IsTrue(Directory.Exists(destFullPath)); } } finally { if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } } }
public void IniRead() { EngineState s = EngineTests.CreateEngineState(); string sampleStr = SampleStr(); string tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); try { Directory.CreateDirectory(tempDir); string tempFile = Path.Combine(tempDir, Path.GetRandomFileName()); string tempFile2 = Path.Combine(tempDir, Path.GetRandomFileName()); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec1,A,%Dest%", tempFile, sampleStr, "1"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec1,B,%Dest%", tempFile, sampleStr, "2"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec2,Z,%Dest%", tempFile, sampleStr, "6"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec3,나,%Dest%", tempFile, sampleStr, "8"); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec2,無,%Dest%", tempFile, sampleStr, string.Empty); ReadTemplate(s, CodeType.IniRead, $@"IniRead,{tempFile},Sec2,Z", tempFile, string.Empty, null, ErrorCheck.ParserError); // Optimization ReadOptTemplate(s, CodeType.IniReadOp, new List <string> { $@"IniRead,{tempFile},Sec1,A,%Dest0%", $@"IniRead,{tempFile},Sec1,B,%Dest1%", $@"IniRead,{tempFile},Sec2,Z,%Dest2%", $@"IniRead,{tempFile},Sec3,나,%Dest3%", }, tempFile, sampleStr, new string[] { "1", "2", "6", "8" }); ReadOptTemplate(s, null, new List <string> { $@"IniRead,{tempFile},Sec1,A,%Dest0%", $@"IniRead,{tempFile},Sec1,B,%Dest1%", $@"IniRead,{tempFile},Sec2,Z,%Dest2%", $@"IniRead,{tempFile2},Sec3,나,%Dest3%", }, tempFile, sampleStr, new string[] { "1", "2", "6" }); } finally { Directory.Delete(tempDir, true); } }
private void FileDelete_MultiTemplate(EngineState s, string rawCode, string wildCard, ErrorCheck check = ErrorCheck.Success, bool recursive = true) { string dirPath = StringEscaper.Preprocess(s, Path.Combine("%TestBench%", "CommandFile")); string srcDir = Path.Combine(dirPath, SrcDir_File); string destDir = Path.Combine(dirPath, DestDir_FileDelete); string destFullPath = Path.Combine(destDir, wildCard); if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } FileHelper.DirectoryCopy(srcDir, destDir, true, true); try { string[] destFiles; if (recursive) { destFiles = Directory.GetFiles(destDir, wildCard, SearchOption.AllDirectories); } else { destFiles = Directory.GetFiles(destDir, wildCard); } EngineTests.Eval(s, rawCode, CodeType.FileDelete, check); if (check == ErrorCheck.Success) { for (int i = 0; i < destFiles.Length; i++) { Assert.IsFalse(File.Exists(destFullPath)); } } } finally { Directory.Delete(destDir, true); } }
public void DirMove() { EngineState s = EngineTests.CreateEngineState(); string varSrcDir = Path.Combine("%TestBench%", "CommandFile", SrcDirDir); string srcDir = StringEscaper.Preprocess(s, varSrcDir); string destDir = FileHelper.GetTempDir(); void Template(string rawCode, string srcDirName, string destDirName, ErrorCheck check = ErrorCheck.Success) { string srcFullPath = Path.Combine(destDir, srcDirName); string destFullPath = Path.Combine(destDir, destDirName); if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } FileHelper.DirCopy(srcDir, destDir, new DirCopyOptions { CopySubDirs = true, Overwrite = true, }); try { EngineTests.Eval(s, rawCode, CodeType.DirMove, check); if (check == ErrorCheck.Success) { Assert.IsFalse(Directory.Exists(srcFullPath)); Assert.IsTrue(Directory.Exists(destFullPath)); } } finally { Directory.Delete(destDir, true); } } Template($@"DirMove,{destDir}\ABCD,{destDir}\XYZ", "ABCD", "XYZ"); Template($@"DirMove,{destDir}\ABDE,{destDir}\ABCD", "ABDE", Path.Combine("ABCD", "ABDE")); Template($@"DirMove,{destDir}\XYZ,{destDir}\WUV", "XYZ", "WUV", ErrorCheck.RuntimeError); Template($@"DirMove,{destDir}\ACDE.txt,{destDir}\XYZ", "ACDE.txt", "XYZ", ErrorCheck.RuntimeError); }
public void Math_BitLogicOper() { EngineState s = EngineTests.CreateEngineState(); // BitAnd Math_Template(s, "Math,BitAnd,%Dest%,0x1,0x3", "1"); Math_Template(s, "Math,BitAnd,%Dest%,0x7,0x8", "0"); // BitOr Math_Template(s, "Math,BitOr,%Dest%,0x1,0x3", "3"); Math_Template(s, "Math,BitOr,%Dest%,0x7,0x8", "15"); // BitXor Math_Template(s, "Math,BitXor,%Dest%,0x1,0x3", "2"); Math_Template(s, "Math,BitXor,%Dest%,0x7,0x8", "15"); // Test Error Math_Template_Error(s, "Math,BitAnd,Dest,4", ErrorCheck.ParserError); Math_Template_Error(s, "Math,BitOr,%Dest%,1,2,37", ErrorCheck.ParserError); Math_Template_Error(s, "Math,BoolXor,%Dest%,B,E", ErrorCheck.Error); }
public void Set_3(EngineState s) { string pPath = s.Project.MainScript.FullPath; Ini.DeleteKey(pPath, "Variables", "%Set_3%"); string rawCode = "Set,%Set_3%,PEBakery,PERMANENT"; EngineTests.Eval(s, rawCode, CodeType.Set, ErrorCheck.Success); string comp = "PEBakery"; string dest = s.Variables.GetValue(VarsType.Global, "Set_3"); Assert.IsTrue(dest.Equals(comp, StringComparison.Ordinal)); string permanent = Ini.GetKey(pPath, "Variables", "%Set_3%"); Assert.IsTrue(dest.Equals(comp, StringComparison.Ordinal)); Ini.DeleteKey(pPath, "Variables", "%Set_3%"); }
public void BitLogicOper() { EngineState s = EngineTests.CreateEngineState(); // BitAnd SuccessTemplate(s, "Math,BitAnd,%Dest%,0x1,0x3", "1"); SuccessTemplate(s, "Math,BitAnd,%Dest%,0x7,0x8", "0"); // BitOr SuccessTemplate(s, "Math,BitOr,%Dest%,0x1,0x3", "3"); SuccessTemplate(s, "Math,BitOr,%Dest%,0x7,0x8", "15"); // BitXor SuccessTemplate(s, "Math,BitXor,%Dest%,0x1,0x3", "2"); SuccessTemplate(s, "Math,BitXor,%Dest%,0x7,0x8", "15"); // Test Error ErrorTemplate(s, "Math,BitAnd,Dest,4", ErrorCheck.ParserError); ErrorTemplate(s, "Math,BitOr,%Dest%,1,2,37", ErrorCheck.ParserError); ErrorTemplate(s, "Math,BoolXor,%Dest%,B,E", ErrorCheck.RuntimeError); }
public void Branch_IfExistRegSubKey() { EngineState s = EngineTests.CreateEngineState(); BranchConditionType type = BranchConditionType.ExistRegSubKey; BranchCondition cond; cond = new BranchCondition(type, false, "HKLM", @"SOFTWARE\Microsoft\DirectMusic"); Assert.IsTrue(cond.Check(s, out string d)); cond = new BranchCondition(type, false, "HKLM", @"SOFTWARE\Microsoft\DirectMusicNotExist"); Assert.IsFalse(cond.Check(s, out d)); cond = new BranchCondition(type, true, "HKLM", @"SOFTWARE\Microsoft\DirectMusic"); Assert.IsFalse(cond.Check(s, out d)); cond = new BranchCondition(type, true, "HKLM", @"SOFTWARE\Microsoft\DirectMusicNotExist"); Assert.IsTrue(cond.Check(s, out d)); BranchCondition_Single_Template(s, @"If,ExistRegSection,HKLM,SOFTWARE\Microsoft\DirectMusic,Set,%Dest%,T", "T"); BranchCondition_Single_Template(s, @"If,ExistRegSubKey,HKLM,SOFTWARE\Microsoft\DirectMusicNotExist,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistRegSection,HKLM,SOFTWARE\Microsoft\DirectMusic,Set,%Dest%,T", "F"); BranchCondition_Single_Template(s, @"If,Not,ExistRegSubKey,HKLM,SOFTWARE\Microsoft\DirectMusicNotExist,Set,%Dest%,T", "T"); }
public void FileSize() { EngineState s = EngineTests.CreateEngineState(); string scriptDirPath = Path.Combine("%TestBench%", "CommandFile"); string scriptSrcDir = Path.Combine(scriptDirPath, SrcDirFile); void Template(string rawCode, string comp, ErrorCheck check = ErrorCheck.Success) { EngineTests.Eval(s, rawCode, CodeType.FileSize, check); if (check == ErrorCheck.Success) { Assert.IsTrue(s.Variables["Dest"].Equals(comp, StringComparison.Ordinal)); } } Template($@"FileSize,{scriptSrcDir}\A.txt,%Dest%", "1"); Template($@"FileSize,{scriptSrcDir}\B.txt,%Dest%", "2"); Template($@"FileSize,{scriptSrcDir}\C.txt,%Dest%", "3"); Template($@"Retrieve,FileSize,{scriptSrcDir}\C.txt,%Dest%", "3"); Template($@"FileSize,{scriptSrcDir}\NotExist,%Dest%", string.Empty, ErrorCheck.RuntimeError); }
public void Reg_RegRead() { // RegRead,<HKey>,<KeyPath>,<ValueName>,<DestVar> EngineState s = EngineTests.CreateEngineState(); // Use subKey which will not be changed // REG_SZ RegDestVar_Template(s, CodeType.RegRead, @"RegRead,HKLM,SOFTWARE\Microsoft\DirectX,Version,%Dest%", "4.09.00.0904"); // REG_BINARY RegDestVar_Template(s, CodeType.RegRead, @"RegRead,HKLM,SOFTWARE\Microsoft\DirectX,InstalledVersion,%Dest%", "00,00,00,09,00,00,00,00"); // REG_MULTI_SZ -> Will be expanded automatically by Windows RegDestVar_Template(s, CodeType.RegRead, @"RegRead,HKLM,SOFTWARE\Microsoft\DirectMusic,GMFilePath,%Dest%", @"#$pSystemRoot#$p\system32\drivers\GM.DLS"); // REG_DWORD RegDestVar_Template(s, CodeType.RegRead, @"RegRead,HKLM,""SOFTWARE\Microsoft\Internet Explorer"",IntegratedBrowser,%Dest%", "1"); // Error RegDestVar_Template(s, CodeType.RegRead, @"RegRead,HKLM,SOFTWARE\Microsoft\DirectX,NotExistValue,%Dest%", string.Empty, ErrorCheck.Error); }