From e0bedb88a9b7449de38516de0a2f66c5333b4f6f Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Sun, 25 Jul 2021 14:49:50 +0100 Subject: [PATCH] Tests fixes and minor refactoring: - Fixed broken test due to missing static images. - Fixed NUnitEngineExeption thrown due to StackOverflowException when searching for non-existing assembly (due to wrong branding). - Commented out ignored tests causing the overall NUnit result to be reported as Warning instead of Passed. Signed-off-by: Konstantina Chremmou --- Branding/Branding.resx | 3 + XenAdmin/Controls/Folders/FolderListItem.cs | 12 +--- XenAdmin/Images.cs | 2 + XenAdminTests/CodeTests/AssemblyTests.cs | 56 ++++++++++++++----- .../Controls/Folders/FolderListItemTests.cs | 5 +- XenModel/BrandManager.cs | 2 + 6 files changed, 55 insertions(+), 25 deletions(-) diff --git a/Branding/Branding.resx b/Branding/Branding.resx index 68f26ec13..6c38eff7d 100644 --- a/Branding/Branding.resx +++ b/Branding/Branding.resx @@ -122,6 +122,9 @@ [XenCenter] + + [XenCenter_No_Space] + Citrix Insight Services diff --git a/XenAdmin/Controls/Folders/FolderListItem.cs b/XenAdmin/Controls/Folders/FolderListItem.cs index 08e610976..5c19bbb9b 100644 --- a/XenAdmin/Controls/Folders/FolderListItem.cs +++ b/XenAdmin/Controls/Folders/FolderListItem.cs @@ -175,8 +175,8 @@ namespace XenAdmin.Controls { get { - int t1, t2; - return CalcSizeAndTrunc(int.MaxValue, out t1, out t2); + using (var g = Parent.CreateGraphics()) + return CalcSizeAndTrunc(g, int.MaxValue, out _, out _); } } @@ -264,14 +264,6 @@ namespace XenAdmin.Controls return theSize; } - private Size CalcSizeAndTrunc(int width, out int trunc1, out int trunc2) - { - Graphics g = this.Parent.CreateGraphics(); - Size sz = CalcSizeAndTrunc(g, width, out trunc1, out trunc2); - g.Dispose(); - return sz; - } - private FLIControl OnControl(Point point) { foreach (FLIControl control in controls) diff --git a/XenAdmin/Images.cs b/XenAdmin/Images.cs index 472abea6a..d2390ac0a 100644 --- a/XenAdmin/Images.cs +++ b/XenAdmin/Images.cs @@ -861,6 +861,8 @@ namespace XenAdmin public static Bitmap pool_up_16 = Properties.Resources.pool_up_16; public static Bitmap redhat_16x = Properties.Resources.redhat_16x; public static Bitmap Refresh16 = Properties.Resources.Refresh16; + public static Bitmap RightArrow = Properties.Resources.RightArrow; + public static Bitmap LeftArrow = Properties.Resources.LeftArrow; public static Bitmap RunningDC_16 = Properties.Resources.RunningDC_16; public static Bitmap saved_searches_16 = Properties.Resources.saved_searches_16; public static Bitmap saved_searches_24 = Properties.Resources.saved_searches_24; diff --git a/XenAdminTests/CodeTests/AssemblyTests.cs b/XenAdminTests/CodeTests/AssemblyTests.cs index 18cbd6171..def4db289 100644 --- a/XenAdminTests/CodeTests/AssemblyTests.cs +++ b/XenAdminTests/CodeTests/AssemblyTests.cs @@ -37,6 +37,7 @@ using System.Configuration; using System.Drawing; using System.Reflection; using NUnit.Framework; +using XenAdmin.Core; namespace XenAdminTests.CodeTests @@ -44,6 +45,38 @@ namespace XenAdminTests.CodeTests [TestFixture, Category(TestCategories.Unit)] public class AssemblyTests { + private static readonly string MainAssemblyName = $"{BrandManager.BrandConsoleNoSpace}Main"; + + public class TestDataClass + { + public string AssemblyName { get; set; } + public string Locale { get; set; } + } + + private static IEnumerable TestCasesForI18NFiles + { + get + { + yield return new TestDataClass {AssemblyName = MainAssemblyName, Locale = "ja"}; + yield return new TestDataClass {AssemblyName = MainAssemblyName, Locale = "zh-CN"}; + yield return new TestDataClass {AssemblyName = "XenModel", Locale = "ja"}; + yield return new TestDataClass {AssemblyName = "XenModel", Locale = "zh-CN"}; + yield return new TestDataClass {AssemblyName = "XenOvf", Locale = "ja"}; + yield return new TestDataClass {AssemblyName = "XenOvf", Locale = "zh-CN"}; + } + } + + private static IEnumerable TestCasesForRoaming + { + get + { + yield return new TestDataClass {AssemblyName = MainAssemblyName}; + yield return new TestDataClass {AssemblyName = "XenOvf"}; + yield return new TestDataClass {AssemblyName = "XenServerHealthCheck"}; + } + } + + [Test] [Description("Checks that there are no Bitmaps in XenAdmin.Resources" + "without a counterpart in XenAdmin.Images.StaticImages")] @@ -72,14 +105,12 @@ namespace XenAdminTests.CodeTests $"Resources without a static counterpart: {string.Join(", ", extraImages)}"); } - [Test, Combinatorial] + [Test, TestCaseSource(typeof(AssemblyTests), nameof(TestCasesForI18NFiles))] [Description("Checks all resx files in the project have their i18n counterparts in place")] - public void TestEnsureI18NFilesInPlace( - [Values("ja", "zh-CN")] string locale, - [Values("XenCenterMain", "XenModel", "XenOvf")] string assemblyName) + public void TestEnsureI18NFilesInPlace(TestDataClass tc) { - var assembly = FindAssemblyByNameRecursively(assemblyName); - Assert.NotNull($"Assembly {assemblyName} was not found."); + var assembly = FindAssemblyByNameRecursively(tc.AssemblyName); + Assert.NotNull($"Assembly {tc.AssemblyName} was not found."); var excludeFromCheck = new[] {"XenAdmin.Help.HelpManager", "XenAdmin.Branding", "DotNetVnc.KeyMap"}; var missing = new List(); @@ -87,7 +118,7 @@ namespace XenAdminTests.CodeTests List defaultResx = new List(assembly.GetManifestResourceNames().Where(resource => resource.EndsWith("resources"))); - CultureInfo cultureInfo = new CultureInfo(locale); + CultureInfo cultureInfo = new CultureInfo(tc.Locale); Assembly localeDll = assembly.GetSatelliteAssembly(cultureInfo); List localeResx = new List(localeDll.GetManifestResourceNames()); @@ -96,7 +127,7 @@ namespace XenAdminTests.CodeTests var name = def.Substring(0, def.Length - ".resources".Length); var exclude = excludeFromCheck.Contains(name); - string localName = $"{name}.{locale}.resources"; + string localName = $"{name}.{tc.Locale}.resources"; var localized = localeResx.Contains(localName); if (localized && exclude) @@ -109,13 +140,12 @@ namespace XenAdminTests.CodeTests Assert.IsEmpty(extra, "Unnecessary resources detected."); } - [Test] + [Test, TestCaseSource(typeof(AssemblyTests), nameof(TestCasesForRoaming))] [Description("Checks that if there are user-scoped settings in an assembly, these have roaming=true")] - public void TestUserSettingsAreRoaming( - [Values("XenCenterMain", "XenOvf", "XenServerHealthCheck")] string assemblyName) + public void TestUserSettingsAreRoaming(TestDataClass tc) { - var assembly = FindAssemblyByNameRecursively(assemblyName); - Assert.NotNull($"Assembly {assemblyName} was not found."); + var assembly = FindAssemblyByNameRecursively(tc.AssemblyName); + Assert.NotNull($"Assembly {tc.AssemblyName} was not found."); var nonRoaming = new List(); diff --git a/XenAdminTests/Controls/Folders/FolderListItemTests.cs b/XenAdminTests/Controls/Folders/FolderListItemTests.cs index 91594bf38..a290a81b8 100644 --- a/XenAdminTests/Controls/Folders/FolderListItemTests.cs +++ b/XenAdminTests/Controls/Folders/FolderListItemTests.cs @@ -54,12 +54,13 @@ namespace XenAdminTests.Controls.Folders parent.Dispose(); } - [Ignore("Needs revisiting")] + /*TODO: needs revisiting [Test] [TestCase("", ExpectedResult = 43)] [TestCase("mypath", ExpectedResult = 44)] [TestCase("mypathmypathmypathmypathmypathmypathmypathmypathmypathmypathmypath", ExpectedResult = 454)] - public int CalculatePreferedSizes(string path) + */ + public int CalculatePreferredSizes(string path) { var item = new FolderListItem(path, FolderListItem.AllowSearch.None, false) { diff --git a/XenModel/BrandManager.cs b/XenModel/BrandManager.cs index 2ce7bf1c5..2f2416c70 100644 --- a/XenModel/BrandManager.cs +++ b/XenModel/BrandManager.cs @@ -42,6 +42,8 @@ namespace XenAdmin.Core public static readonly string BrandConsole = Get("BRAND_CONSOLE"); + public static readonly string BrandConsoleNoSpace = Get("BRAND_CONSOLE_NO_SPACE"); + public static readonly string Cis = Get("CIS"); public static readonly string CompanyNameLegal = Get("COMPANY_NAME_LEGAL");