コード例 #1
0
        public static bool IsWindows(this EnvironmentV2 self)
        {
            var  sysInfo   = self.systemInfo;
            bool IsWindows = sysInfo.osPlatform.StartsWith("Win", StringComparison.InvariantCultureIgnoreCase);

            return(IsWindows);
        }
コード例 #2
0
ファイル: ZioExtensions.cs プロジェクト: shoshiiran/cscore
 public static FileEntry GetChild(this DirectoryEntry self, string fileName)
 {
     AssertV2.AreEqual(fileName, EnvironmentV2.SanatizeToFileName(fileName));
     return(ResolveFilePath(self, fileName));
 }
コード例 #3
0
ファイル: ZioExtensions.cs プロジェクト: llorch19/cscore
 public static FileEntry GetChild(this DirectoryEntry self, string fileName)
 {
     AssertV2.AreEqual(fileName, EnvironmentV2.SanatizeToFileName(fileName));
     return(new FileEntry(self.FileSystem, self.Path / fileName));
 }
コード例 #4
0
ファイル: ZioExtensions.cs プロジェクト: shoshiiran/cscore
 public static DirectoryEntry GetChildDir(this DirectoryEntry self, string subDirName)
 {
     AssertV2.AreEqual(subDirName, EnvironmentV2.SanatizeToFileName(subDirName));
     return(new DirectoryEntry(self.FileSystem, self.Path / subDirName));
 }
コード例 #5
0
        private IEnumerator AssertNoVisualRegressionCoroutine(string id, StackTrace stacktrace)
        {
            id = EnvironmentV2.SanatizeToFileName(id);
            if (id.IsNullOrEmpty())
            {
                throw new ArgumentNullException("Invalid ID passed");
            }

            var idFolder = GetFolderFor(id);
            var oldImg   = idFolder.GetChild(id + ".regression.jpg");
            var newImg   = idFolder.GetChild(id + ".jpg");
            var backup   = idFolder.GetChild(id + ".jpg.backup");

            Config config = LoadConfigFor(id);

            yield return(new WaitForEndOfFrame());

            Texture2D screenShot = ScreenCapture.CaptureScreenshotAsTexture(config.screenshotUpscaleFactor);

            // Texture2D screenShot = Camera.allCameras.CaptureScreenshot(); // Does not capture UI

            if (newImg.Exists)
            {
                newImg.CopyToV2(backup, replaceExisting: false);
            }
            screenShot.SaveToJpgFile(newImg, config.screenshotQuality);
            screenShot.Destroy();

            var diffImg = CalculateDiffImage(oldImg, newImg, config.maxAllowedDiff, config.errorMetric);

            if (diffImg != null)
            {
                var e = $"Visual diff to previous '{id}' detected! To approve an allowed visual change, delete '{oldImg.Name}'";
                if (!config.customErrorMessage.IsNullOrEmpty())
                {
                    e = config.customErrorMessage + "/n" + e;
                }
                var exeption = new Error(e, stacktrace);
                if (config.throwAssertException)
                {
                    throw exeption;
                }
                else if (config.logAsError)
                {
                    Log.e(exeption);
                }
                else if (config.logAsWarning)
                {
                    Log.w(e);
                }
                if (config.openExternallyOnAssertFail)
                {
                    diffImg.Parent.OpenInExternalApp();
                    diffImg.OpenInExternalApp();
                }
            }
            else     // No difference between oldImg and newImg
            // To prevent git from detecting invalid file changes:
            {
                if (backup.Exists)                               // If there is a backup of newImg..
                {
                    newImg.DeleteV2();                           // Remove the newly generated version ..
                    backup.Rename(newImg.Name, out FileEntry _); // and replace it with the backup
                }
            }
            backup.DeleteV2(); // If a backup file was created during the process delete it
            AssertV2.IsTrue(newImg.Exists, "newImg did not exist after AssertNoVisualChange done");
        }