public static SortFilesSettings FillFromUI(SortFilesAction action, string skipDirs, string skipFiles, string dirLeft, string dirRight, bool checkbox1, bool checkbox2, bool mirror, bool previewOnly) { var settings = new SortFilesSettings(); settings.SkipDirectories.AddRange(TextLineByLineToList(skipDirs)); settings.SkipFiles.AddRange(TextLineByLineToList(skipFiles)); settings.LeftDirectory = dirLeft; settings.RightDirectory = dirRight; settings.AllowFiletimesDifferForFAT = checkbox1; settings.AllowFiletimesDifferForDST = checkbox2; settings.Mirror = mirror; settings.PreviewOnly = previewOnly; settings.LogFile = Path.Combine(TestUtil.GetTestWriteDirectory(), "log" + Utils.GetRandomDigits() + ".txt"); // the right directory field isn't shown in UI, we need to set it manually if (action == SortFilesAction.SearchDuplicatesInOneDir) { settings.RightDirectory = settings.LeftDirectory; } else if (action == SortFilesAction.SearchDuplicates) { settings.SearchDuplicatesCanUseFiletimes = checkbox1; } if (!Directory.Exists(settings.LeftDirectory)) { Utils.MessageErr("Directory does not exist " + settings.LeftDirectory, true); return(null); } else if (!Directory.Exists(settings.RightDirectory) && action != SortFilesAction.SearchDuplicatesInOneDir) { Utils.MessageErr("Directory does not exist " + settings.RightDirectory, true); return(null); } if (settings.LeftDirectory.EndsWith(Utils.Sep, StringComparison.Ordinal) || settings.RightDirectory.EndsWith(Utils.Sep, StringComparison.Ordinal)) { Utils.MessageErr("directory should not end with slash.", true); return(null); } if (action != SortFilesAction.SearchDuplicatesInOneDir && !Utils.ArePathsDistinct( settings.LeftDirectory, settings.RightDirectory)) { Utils.MessageErr("directories must be distinct.", true); return(null); } return(settings); }
static void TestMethod_TestSha512() { var path = Path.Combine(TestUtil.GetTestWriteDirectory(), "testhash.txt"); File.WriteAllText(path, "12345678"); TestUtil.IsEq("filenotfound:", Utils.GetSha512(null)); TestUtil.IsEq("filenotfound:notexist", Utils.GetSha512("notexist")); TestUtil.IsEq("+lhdichR3TOKcNz1Naoqkv7ng23Wr/EiZYPojgmWK" + "T8WvACcZSgm4PxccGaVoDzdzjcvE57/TROVnabx9dPqvg==", Utils.GetSha512(path)); }
static void TestMethod_GetFileAttributes() { var path = Path.Combine(TestUtil.GetTestWriteDirectory(), "testhash.txt"); File.WriteAllText(path, "12345678"); TestUtil.IsEq(File.GetAttributes(path), Utils.GetFileAttributesOrNone(path)); var pathNotExist = Path.Combine(TestUtil.GetTestWriteDirectory(), "testhash2.txt"); TestUtil.IsEq(false, File.Exists(pathNotExist)); TestUtil.IsEq(FileAttributes.Normal, Utils.GetFileAttributesOrNone(pathNotExist)); }
public static void RunTests() { // for the case where FilepathDeletedFilesDir isn't set, // we shouldn't leave junk behind. var localTrash = Path.Combine(Configs.Current.Directory, "(deleted)"); var shouldCleanLocalTrash = !Directory.Exists(localTrash); if (Utils.GetSoftDeleteDestination("abc" + Utils.Sep + "abc") == null) { Utils.MessageBox("Skipping tests until a trash directory is chosen."); return; } try { string dir = TestUtil.GetTestWriteDirectory(); if (Directory.Exists(dir)) { Directory.Delete(dir, true); } } catch (Exception) { Utils.MessageErr("Could not clear unit test directory. Is another instance of " + "coordinate pictures already running?"); return; } Configs.Current.SuppressDialogs = true; try { TestUtil.CallAllTestMethods(typeof(CoordinatePicturesTests), null); TestUtil.CallAllTestMethods(typeof(CoordinateFilesTests), null); } finally { Configs.Current.SuppressDialogs = false; if (shouldCleanLocalTrash && Directory.Exists(localTrash)) { Directory.Delete(localTrash, false); } } }