From 38accc87c3a3098f6e048a16aefce1513b12b329 Mon Sep 17 00:00:00 2001 From: lukeIam <2lukeiam@gmail.com> Date: Thu, 15 Mar 2018 13:52:40 +0100 Subject: [PATCH] Removed the few old tests --- Vocaluxe.sln.DotSettings | 8 + VocaluxeTests/CTestHelpers.cs | 21 - VocaluxeTests/CombinatoricsTest.cs | 75 --- VocaluxeTests/PartyModeTests.cs | 73 --- VocaluxeTests/Properties/AssemblyInfo.cs | 39 -- VocaluxeTests/TestXmlFiles/Dictionary`2.xml | 34 -- VocaluxeTests/TestXmlFiles/SConfig.xml | 97 ---- VocaluxeTests/TestXmlFiles/SDefaultFonts.xml | 35 -- VocaluxeTests/TestXmlFiles/SSkin.xml | 268 ---------- VocaluxeTests/TestXmlFiles/STheme.xml | 16 - VocaluxeTests/TestXmlFiles/SThemeCover.xml | 37 -- VocaluxeTests/TestXmlFiles/SThemeScreen.xml | 256 ---------- VocaluxeTests/VocaluxeTests.csproj | 121 ----- VocaluxeTests/XmlSerializerTest.cs | 490 ------------------- 14 files changed, 8 insertions(+), 1562 deletions(-) delete mode 100644 VocaluxeTests/CTestHelpers.cs delete mode 100644 VocaluxeTests/CombinatoricsTest.cs delete mode 100644 VocaluxeTests/PartyModeTests.cs delete mode 100644 VocaluxeTests/Properties/AssemblyInfo.cs delete mode 100644 VocaluxeTests/TestXmlFiles/Dictionary`2.xml delete mode 100644 VocaluxeTests/TestXmlFiles/SConfig.xml delete mode 100644 VocaluxeTests/TestXmlFiles/SDefaultFonts.xml delete mode 100644 VocaluxeTests/TestXmlFiles/SSkin.xml delete mode 100644 VocaluxeTests/TestXmlFiles/STheme.xml delete mode 100644 VocaluxeTests/TestXmlFiles/SThemeCover.xml delete mode 100644 VocaluxeTests/TestXmlFiles/SThemeScreen.xml delete mode 100644 VocaluxeTests/VocaluxeTests.csproj delete mode 100644 VocaluxeTests/XmlSerializerTest.cs diff --git a/Vocaluxe.sln.DotSettings b/Vocaluxe.sln.DotSettings index 5821e368..a7008703 100644 --- a/Vocaluxe.sln.DotSettings +++ b/Vocaluxe.sln.DotSettings @@ -29,7 +29,10 @@ ONLY_FOR_MULTILINE 1 True + ALWAYS + NEVER True + NEVER LINE_BREAK False True @@ -117,7 +120,12 @@ along with $SOLUTION$. If not, see <http://www.gnu.org/licenses/>.<Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private, Protected, ProtectedInternal, Internal, Public" Description="Classes"><ElementKinds><Kind Name="CLASS" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="C" Suffix="" Style="AaBb" /></Policy> <Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private, Protected" Description="Fields (not public)"><ElementKinds><Kind Name="FIELD" /><Kind Name="READONLY_FIELD" /><Kind Name="METHOD" /><Kind Name="PROPERTY" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="_" Suffix="" Style="AaBb" /></Policy> <Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private, Protected, ProtectedInternal, Internal, Public" Description="Structs"><ElementKinds><Kind Name="STRUCT" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="S" Suffix="" Style="AaBb" /></Policy> + True + True + True + True True + True True True False diff --git a/VocaluxeTests/CTestHelpers.cs b/VocaluxeTests/CTestHelpers.cs deleted file mode 100644 index 4ad00bf3..00000000 --- a/VocaluxeTests/CTestHelpers.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace VocaluxeTests -{ - static class CTestHelpers - { - public static void AssertFail(Action test) where T : Exception - { - try - { - test.Invoke(); - Assert.Fail("Exception " + typeof(T).Name + " not thrown!"); - } - catch (Exception e) - { - Assert.IsInstanceOfType(e, typeof(T)); - } - } - } -} \ No newline at end of file diff --git a/VocaluxeTests/CombinatoricsTest.cs b/VocaluxeTests/CombinatoricsTest.cs deleted file mode 100644 index 50d274e1..00000000 --- a/VocaluxeTests/CombinatoricsTest.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using VocaluxeLib.Utils.Combinatorics; - -namespace VocaluxeTests -{ - [TestClass] - public class CCombinatoricsTest - { - [TestMethod] - public void TestCounts() - { - Assert.AreEqual(4, CCombinations.Count(4, 3)); - Assert.AreEqual(6, CCombinations.Count(4, 2)); - Assert.AreEqual(66, CCombinations.Count(12, 2)); - // Corner cases - for (int i = 1; i < 12; i++) - { - Assert.AreEqual(1, CCombinations.Count(i, 0)); - Assert.AreEqual(1, CCombinations.Count(i, i)); - Assert.AreEqual(0, CCombinations.Count(i, i + 1)); - } - // Check identity (n k) = (n n-k) - for (int i = 0; i <= 12; i++) - Assert.AreEqual(CCombinations.Count(12, i), CCombinations.Count(12, 12 - i)); - CTestHelpers.AssertFail(() => CCombinations.Count(-1, -1)); - CTestHelpers.AssertFail(() => CCombinations.Count(-1, 1)); - CTestHelpers.AssertFail(() => CCombinations.Count(1, -1)); - } - - // ReSharper disable UnusedParameter.Local - private static void _CheckResults(CCombinations combs, List input) - // ReSharper restore UnusedParameter.Local - { - List> results = new List>(); - foreach (List comb in combs) - { - foreach (List other in results) - Assert.IsFalse(other.SequenceEqual(comb), "Result must be unique"); - for (int i = 0; i < comb.Count - 1; i++) - { - Assert.IsTrue(comb.IndexOf(comb[i], i + 1) < 0, "Repetition not allowed"); - Assert.IsTrue(input.Contains(comb[i]), "Output must be in input sequence"); - } - results.Add(comb); - } - Assert.AreEqual(combs.Count(), results.Count); - List> results2 = combs.GetAll(); - Assert.AreEqual(results.Count, results2.Count); - for (int i = 0; i < results2.Count; i++) - Assert.IsTrue(results[i].SequenceEqual(results2[i])); - } - - [TestMethod] - public void TestResults() - { - Random rand = new Random(); - for (int n = 0; n < 8; n++) - { - for (int k = 0; k <= n; k++) - { - List collection = new List(n); - int r = rand.Next(1000); - for (int i = 0; i < n; i++) - collection.Add(i + r); - CCombinations combs = new CCombinations(collection, k); - Assert.AreEqual(CCombinations.Count(n, k), combs.Count()); - _CheckResults(combs, collection); - } - } - } - } -} \ No newline at end of file diff --git a/VocaluxeTests/PartyModeTests.cs b/VocaluxeTests/PartyModeTests.cs deleted file mode 100644 index e5c1eda6..00000000 --- a/VocaluxeTests/PartyModeTests.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Vocaluxe.Base; -using Vocaluxe.Reporting; -using VocaluxeLib; -using VocaluxeLib.Log; -using VocaluxeLib.PartyModes.Challenge; - -namespace VocaluxeTests -{ - [TestClass] - public class CPartyModeTests - { - [TestMethod] - public void TestRoundBoundaries() - { - // ReSharper disable ObjectCreationAsStatement - new CChallengeRounds(1, 1, 1); // Should succeed - // ReSharper restore ObjectCreationAsStatement - for (int inv = -1; inv <= 0; inv++) - { - int invL = inv; - CTestHelpers.AssertFail(() => new CChallengeRounds(invL, 1, 1)); - CTestHelpers.AssertFail(() => new CChallengeRounds(1, invL, 1)); - CTestHelpers.AssertFail(() => new CChallengeRounds(1, 1, invL)); - } - } - - private static void _CheckRounds(CChallengeRounds rounds, int numPlayer) - { - List numSongs = new List(numPlayer); - for (int i = 0; i < numPlayer; i++) - numSongs.Add(0); - for (int i = 0; i < rounds.Count; i++) - { - foreach (int player in rounds[i].Players) - { - Assert.IsTrue(player >= 0 && player < numPlayer); - numSongs[player]++; - } - } - Assert.IsTrue(numSongs.Min() == numSongs.Max(), "Some players have more songs than others"); - } - - [TestMethod] - public void TestRoundGeneration() - { - CBase.Game = new CBGame(); - CLog.Init(CSettings.FolderNameLogs, CSettings.FileNameMainLog, CSettings.FileNameSongLog, CSettings.FileNameCrashMarker, CSettings.GetFullVersionText(), CReporter.ShowReporterFunc); - for (int i = 0; i < 10; i++) - { - for (int numPlayer = 1; numPlayer <= 20; numPlayer++) - { - for (int numMic = 1; numMic <= 6; numMic++) - { - int roundFactor = (numPlayer % numMic == 0) ? numPlayer / numMic : numPlayer; - for (int numRounds = roundFactor; numRounds <= 100 && numRounds <= roundFactor * 5; numRounds += roundFactor) - { - CChallengeRounds rounds = new CChallengeRounds(numRounds, numPlayer, numMic); - Assert.IsTrue(rounds.Count >= numRounds); - _CheckRounds(rounds, numPlayer); - if (rounds.Count != numRounds) - CLog.Debug("Number of rounds does not match. Expected: " + numRounds + ", Is: " + rounds.Count + " for " + numPlayer + "/" + - ((numPlayer < numMic) ? numPlayer : numMic)); - } - } - } - } - } - } -} \ No newline at end of file diff --git a/VocaluxeTests/Properties/AssemblyInfo.cs b/VocaluxeTests/Properties/AssemblyInfo.cs deleted file mode 100644 index 6001c0da..00000000 --- a/VocaluxeTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// Allgemeine Informationen über eine Assembly werden über folgende -// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, -// die einer Assembly zugeordnet sind. - -[assembly: AssemblyTitle("VocaluxeTests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("VocaluxeTests")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Wenn ComVisible auf "false" festgelegt wird, sind die Typen innerhalb dieser Assembly -// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von -// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. - -[assembly: ComVisible(false)] - -// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird - -[assembly: Guid("3bdc6da5-a651-452e-903c-deec310288ad")] - -// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: -// -// Hauptversion -// Nebenversion -// Buildnummer -// Revision -// -// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern -// durch Einsatz von '*', wie in nachfolgendem Beispiel: -// [Assembly: AssemblyVersion("1.0.*")] - -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/VocaluxeTests/TestXmlFiles/Dictionary`2.xml b/VocaluxeTests/TestXmlFiles/Dictionary`2.xml deleted file mode 100644 index 299972ec..00000000 --- a/VocaluxeTests/TestXmlFiles/Dictionary`2.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - Deutsch - Vocaluxe - und - Exit - Speichern - Zurück - Start - Audio-Streams - Video-Streams - Textures - ToneAbs - Max. Volume - Geladene Songs - Maus - Speicherverbrauch - Normal - Duett - Medley - Kurz-Version - Vocal Hero - Superstar - Hit-Künstler - Sternchen - Fortgeschritten - Möchtegern - Amateur - Nichtskönner - Gast - Normaler Benutzer - Administrator - Tastatur - \ No newline at end of file diff --git a/VocaluxeTests/TestXmlFiles/SConfig.xml b/VocaluxeTests/TestXmlFiles/SConfig.xml deleted file mode 100644 index c2258062..00000000 --- a/VocaluxeTests/TestXmlFiles/SConfig.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - TR_CONFIG_LEVEL_MAX - TR_CONFIG_ON - - - TR_CONFIG_DIRECT3D - TR_CONFIG_TEXTURE_HIGH - 128 - 1024 - 576 - Middle - 0 - 1 - 0 - 0 - X0 - 60 - TR_CONFIG_ON - TR_CONFIG_OFF - 0.4 - - - Ambient - Blue - Blue - TR_CONFIG_ON - TR_CONFIG_ON - TR_CONFIG_TIMERLOOK_EXPANDED - TR_CONFIG_PLAYERINFO_BOTH - TR_CONFIG_FADEPLAYERINFO_OFF - TR_CONFIG_COVERLOADING_ATSTART - Slide - - - GstreamerSharp - PortAudio - B2048 - 0 - TR_CONFIG_ON - 20 - TR_CONFIG_NO_OWN_MUSIC - TR_CONFIG_ON - 50 - 100 - - - Deutsch - E:\Songs - TR_CONFIG_TILE_BOARD - TR_CONFIG_ARTIST_LETTER - TR_CONFIG_ON - 10 - TR_CONFIG_TIMERMODE_REMAINING - 1 - TR_CONFIG_ON - TR_CONFIG_LYRICSPOSITION_BOTTOM - 0.1 - - guest1.xml - guest1.xml - guest1.xml - guest1.xml - - - - - - - - Mikrofon (C-Media USB Headphone Set ) - Mikrofon (C-Media USB Headphone Set )6 - 1 - - 120 - - - TR_CONFIG_ON - TR_CONFIG_ON - 3000 - - \ No newline at end of file diff --git a/VocaluxeTests/TestXmlFiles/SDefaultFonts.xml b/VocaluxeTests/TestXmlFiles/SDefaultFonts.xml deleted file mode 100644 index ad954596..00000000 --- a/VocaluxeTests/TestXmlFiles/SDefaultFonts.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - Normal - 0 - - 0 - 0 - 0 - 1 - - FreeSans - FreeSans.ttf - FreeSansBold.ttf - FreeSansOblique.ttf - FreeSansBoldOblique.ttf - - - Outline - 0.1 - - 0 - 0 - 0 - 1 - - FreeSans - FreeSans.ttf - FreeSansBold.ttf - FreeSansOblique.ttf - FreeSansBoldOblique.ttf - - - \ No newline at end of file diff --git a/VocaluxeTests/TestXmlFiles/SSkin.xml b/VocaluxeTests/TestXmlFiles/SSkin.xml deleted file mode 100644 index 23f2a3df..00000000 --- a/VocaluxeTests/TestXmlFiles/SSkin.xml +++ /dev/null @@ -1,268 +0,0 @@ - - - 4 - - Blue - bohning - 0 - 0 - - - - 0 - 0 - 1 - 1 - - - 1 - 0 - 0 - 1 - - - 0 - 1 - 0 - 1 - - - 0.5 - 0 - 1 - 1 - - - 1 - 0.8 - 0 - 1 - - - 1 - 0 - 0.5 - 1 - - - 0 - 0 - 0.75 - 1 - - - 0.675 - 0.89 - 0.969 - 1 - - - 0.675 - 0.89 - 0.969 - 0.5 - - - 0.675 - 0.89 - 0.969 - 0.6 - - - 0.675 - 0.89 - 0.969 - 0.3 - - - 0.675 - 0.89 - 0.969 - 1 - - - 0.675 - 0.89 - 0.969 - 0.5 - - - 0.675 - 0.89 - 0.969 - 1 - - - 0.675 - 0.89 - 0.969 - 1 - - - 0.675 - 0.89 - 0.969 - 0.5 - - - 0.675 - 0.89 - 0.969 - 0.5 - - - 0.675 - 0.89 - 0.969 - 0.3 - - - 0.675 - 0.89 - 0.969 - 1 - - - 0.675 - 0.89 - 0.969 - 0.5 - - - 0.675 - 0.89 - 0.969 - 1 - - - 1 - 0 - 0 - 1 - - - 0 - 0 - 0 - 1 - - - 1 - 1 - 1 - 1 - - - 1 - 1 - 1 - 1 - - - 1 - 1 - 1 - 0 - - - 0 - 0 - 1 - 1 - - - 0 - 0 - 0 - 1 - - - 0.3 - 0.3 - 0.3 - 1 - - - 0 - 0 - 1 - 0.5 - - - 0.8 - 0.95 - 1 - 0.5 - - - 0.8 - 0.95 - 1 - 0.85 - - - - [Blue]BG_Default.png - [Blue]BG_Options.png - Menu.png - - CoverTile.png - CoverBackground.png - Cursor.png - TimeBar.png - TimeLine.png - Pointer.png - SelectSlide.png - SelectSlidePlayer.png - SelectSlideArrowLeft.png - SelectSlideArrowRight.png - notes_left.png - notes_mid.png - notes_right.png - notes_bg_left.png - notes_bg_mid.png - notes_bg_right.png - points_bar.png - points_bar_bg.png - Lyrics.png - LyricHelper.png - ToneHelper.png - TextBG.png - Score.png - Star.png - Snowflake.png - SongMenu.png - PerfectNoteStar.png - Pause.png - EnergyBeam.png - DuetIcon.png - VideoIcon.png - VideoIconCO.png - VideoIconBG.png - MedleyCalcIcon.png - MedleyTagIcon.png - PlayerSelector.png - PreviousIcon.png - NextIcon.png - PlayIcon.png - PauseIcon.png - RepeatIcon.png - SongMenuBG.png - Close.png - Delete.png - Save.png - Sing.png - Minus.png - Plus.png - Random.png - Popup.png - ScrollUp.png - ScrollDown.png - - - [Blue]BG_Video.mp4 - [Blue]IntroIn.mp4 - [Blue]IntroMid.mp4 - [Blue]IntroOut.mp4 - - \ No newline at end of file diff --git a/VocaluxeTests/TestXmlFiles/STheme.xml b/VocaluxeTests/TestXmlFiles/STheme.xml deleted file mode 100644 index 91b0c674..00000000 --- a/VocaluxeTests/TestXmlFiles/STheme.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - 5 - - Ambient - bohning - 0 - 2 - - - Cursor - 40 - 40 - - - \ No newline at end of file diff --git a/VocaluxeTests/TestXmlFiles/SThemeCover.xml b/VocaluxeTests/TestXmlFiles/SThemeCover.xml deleted file mode 100644 index bb43c51f..00000000 --- a/VocaluxeTests/TestXmlFiles/SThemeCover.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - Blue - Blue - flokuep - - - - %TEXT% - - Normal - - 500 - - - 1 - 1 - 1 - 0.8 - - - 24 - - 100 - - - 1 - 1 - 1 - 1 - - EmptyCover.png - 0.75 - True - - \ No newline at end of file diff --git a/VocaluxeTests/TestXmlFiles/SThemeScreen.xml b/VocaluxeTests/TestXmlFiles/SThemeScreen.xml deleted file mode 100644 index a6751013..00000000 --- a/VocaluxeTests/TestXmlFiles/SThemeScreen.xml +++ /dev/null @@ -1,256 +0,0 @@ - - - - ScreenMain - 2 - - - - Video - - - BG_Default - - - - - - Menu - - - 49 - 32 - 1181 - 50 - 0 - - - - TextBG - - - 150 - 610 - 355 - 30 - -1.9 - - - - - - 10 - 690 - -1 - 15 - 0 - - - Left - Center - - Normal - Vocaluxe "Shining Heaven" v0.3.0 (x64) Beta (0083) - - - 320 - 612 - -2 - 27 - 355 - - - Center - Center - - Outline - TR_SCREENMAIN_TEXT_NOPROFILES - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/VocaluxeTests/VocaluxeTests.csproj b/VocaluxeTests/VocaluxeTests.csproj deleted file mode 100644 index 772672eb..00000000 --- a/VocaluxeTests/VocaluxeTests.csproj +++ /dev/null @@ -1,121 +0,0 @@ - - - - Debug - AnyCPU - {93356718-3A0B-4784-AAE1-215065BFFC66} - Library - Properties - VocaluxeTests - VocaluxeTests - v4.7.1 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 10.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - true - bin\x64\Debug\ - TRACE;DEBUG - full - x64 - prompt - MinimumRecommendedRules.ruleset - - - bin\x64\Release\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - - - true - bin\x86\Debug\ - DEBUG;TRACE - full - x86 - prompt - MinimumRecommendedRules.ruleset - - - bin\x86\Release\ - TRACE - true - pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - - - - - - False - ..\Output\libs\managed\VocaluxeLib.dll - - - - - - - - - - - - - - - - - - - - - - - - {5a4053f1-5ad5-441f-b254-d97a088127b6} - PartyModeChallenge - - - {2a1e0f2d-5392-4bb7-b0a1-a9dfa13e79ff} - Vocaluxe - - - - - - - False - - - False - - - False - - - False - - - - - - - - \ No newline at end of file diff --git a/VocaluxeTests/XmlSerializerTest.cs b/VocaluxeTests/XmlSerializerTest.cs deleted file mode 100644 index 91605a7e..00000000 --- a/VocaluxeTests/XmlSerializerTest.cs +++ /dev/null @@ -1,490 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Xml.Serialization; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using Vocaluxe.Base; -using VocaluxeLib; -using VocaluxeLib.Menu; -using VocaluxeLib.Xml; - -namespace VocaluxeTests -{ - [TestClass] - public class CXmlSerializerTest - { - private const string _Head = "\r\n"; - private const string _Empty = _Head + @""; - -#pragma warning disable 649 -#pragma warning disable 169 - private struct SBasic - { - public int I; - public string S; - public float F; - public double D; - } - - [XmlType("Entry")] - private struct SEntry - { - public int I; - } - - private struct SList - { - [XmlArray] public List Ints; - } - - private struct SArray - { - [XmlArray] public SEntry[] Ints; - } - - private struct SListEmb - { - public int I; - [XmlElement("Entry")] public List Ints; - public int J; - } - - private struct SArrayEmb - { - public int I; - [XmlElement("Entry")] public SEntry[] Ints; - public int J; - } - - private struct SProperty - { - [XmlIgnore] public int Private; - // ReSharper disable UnusedMember.Local - public int Public - { - get { return Private - 1; } - set { Private = value + 1; } - } - // ReSharper restore UnusedMember.Local - // ReSharper disable UnusedAutoPropertyAccessor.Local - public int Auto { get; set; } - // ReSharper restore UnusedAutoPropertyAccessor.Local - } - - private struct SBytes - { - public byte[] B; - } - - private struct SIgnore - { - [XmlIgnore] public int I; - public int J; - } - - private class CIgnore - { - [XmlIgnore] public int I; - public int J; - } - - private struct SDefaultSub - { - [DefaultValue(111)] public int I; - } - - private struct SDefault - { - [DefaultValue(1337)] public int I; - [DefaultValue("Foo")] public string S; - public float? F; - [DefaultValue(666.0)] public double D; - public SDefaultSub Sub; - } - -#pragma warning restore 169 -#pragma warning restore 649 - - private static void _AssertFail(String xmlString) where T2 : Exception where T : new() - { - var deserializer = new CXmlDeserializer(); - CTestHelpers.AssertFail(() => deserializer.DeserializeString(xmlString)); - } - - private static T _AssertSerDeserMatch(string xmlString) where T : new() - { - var deserializer = new CXmlDeserializer(); - var serializer = new CXmlSerializer(); - T foo = deserializer.DeserializeString(xmlString); - string xmlNew = serializer.Serialize(foo); - Assert.AreEqual(xmlString, xmlNew); - return foo; - } - - [TestMethod] - public void TestBasic() - { - const string s = @" - 1 - 2 - 3 - 4 -"; - const string sUnordered = @" - 4 - 1 - 3 - 2 -"; - var xml = new CXmlDeserializer(); - SBasic foo = xml.DeserializeString(s); - Assert.AreEqual(1, foo.I); - Assert.AreEqual("2", foo.S); - Assert.AreEqual(3, foo.F, 0.0001); - Assert.AreEqual(4, foo.D, 0.0001); - foo = xml.DeserializeString(sUnordered); - Assert.AreEqual(1, foo.I); - Assert.AreEqual("2", foo.S); - Assert.AreEqual(3, foo.F, 0.0001); - Assert.AreEqual(4, foo.D, 0.0001); - } - - [TestMethod] - public void TestMissingXmlElement() - { - string[] s = new string[] {@" - 2 - 3 - 4 -", @" - 1 - 3 - 4 -", @" - 1 - 2 - 3 -"}; - foreach (string s1 in s) - { - string sTmp = s1; - _AssertFail(sTmp); - } - } - - [TestMethod] - public void TestMissingStructElement() - { - string[] s = new string[] {@" - 1 - 1 - 2 - 3 - 4 -", @" - 1 - 1 - 2 - 3 - 4 -", @" - 1 - 2 - 3 - 4 - 1 -"}; - foreach (string s1 in s) - { - string sTmp = s1; - _AssertFail(sTmp); - } - } - - [TestMethod] - public void TestBasicSerialization() - { - const string s = _Head + @" - 1 - 2 - 3 - 4 -"; - _AssertSerDeserMatch(s); - } - - private readonly string[] _XmlList = new string[] - { - _Head + @" - - - 1 - - - 1 - - -", - _Head + @" - - -", - _Head + @" - -" - }; - - [TestMethod] - public void TestList() - { - var xml = new CXmlDeserializer(); - var ser = new CXmlSerializer(); - SList foo = xml.DeserializeString(_XmlList[0]); - Assert.AreEqual(foo.Ints.Count, 2, "Deserialization failed"); - Assert.AreEqual(foo.Ints[0].I, 1, "Deserialization failed"); - Assert.AreEqual(foo.Ints[1].I, 1, "Deserialization failed"); - string res = ser.Serialize(foo); - Assert.AreEqual(_XmlList[0], res, "Serialization failed"); - foo = xml.DeserializeString(_XmlList[1]); - Assert.AreEqual(foo.Ints.Count, 0, "Deserialization2 failed"); - res = ser.Serialize(foo); - Assert.AreEqual(_XmlList[2], res, "Serialization2 failed"); - foo = xml.DeserializeString(_XmlList[2]); - Assert.AreEqual(foo.Ints.Count, 0, "Deserialization2 failed"); - _AssertSerDeserMatch(_XmlList[2]); - res = ser.Serialize(foo); - Assert.AreEqual(_XmlList[2], res, "Serialization2 failed"); - _AssertFail(_Empty); - } - - [TestMethod] - public void TestArray() - { - var xml = new CXmlDeserializer(); - var ser = new CXmlSerializer(); - SArray foo = xml.DeserializeString(_XmlList[0]); - Assert.AreEqual(foo.Ints.Length, 2, "Deserialization failed"); - Assert.AreEqual(foo.Ints[0].I, 1, "Deserialization failed"); - Assert.AreEqual(foo.Ints[1].I, 1, "Deserialization failed"); - string res = ser.Serialize(foo); - Assert.AreEqual(_XmlList[0], res, "Serialization failed"); - foo = xml.DeserializeString(_XmlList[1]); - Assert.AreEqual(foo.Ints.Length, 0, "Deserialization2 failed"); - res = ser.Serialize(foo); - Assert.AreEqual(_XmlList[2], res, "Serialization2 failed"); - foo = xml.DeserializeString(_XmlList[2]); - Assert.AreEqual(foo.Ints.Length, 0, "Deserialization2 failed"); - res = ser.Serialize(foo); - Assert.AreEqual(_XmlList[2], res, "Serialization2 failed"); - _AssertFail(_Empty); - } - - private const string _XmlListEmb = _Head + @" - 2 - - 1 - - 3 -"; - private const string _XmlListEmb2 = _Head + @" - 2 - - 1 - - - 2 - - 3 -"; - private const string _XmlListEmb3 = _Head + @" - 2 - 3 -"; - private const string _XmlListEmb4 = _Head + @" - 2 - - 3 -"; - - [TestMethod] - public void TestListEmbedded() - { - var xml = new CXmlDeserializer(); - var ser = new CXmlSerializer(); - SListEmb foo = xml.DeserializeString(_XmlListEmb); - Assert.AreEqual(foo.Ints.Count, 1, "Deserialization failed"); - Assert.AreEqual(foo.Ints[0].I, 1, "Deserialization failed"); - string res = ser.Serialize(foo); - Assert.AreEqual(_XmlListEmb, res, "Serialization failed"); - foo = xml.DeserializeString(_XmlListEmb2); - Assert.AreEqual(foo.Ints.Count, 2, "Deserialization failed"); - Assert.AreEqual(foo.Ints[1].I, 2, "Deserialization failed"); - res = ser.Serialize(foo); - Assert.AreEqual(_XmlListEmb2, res, "Serialization failed"); - foo = xml.DeserializeString(_XmlListEmb3); - Assert.AreEqual(foo.Ints.Count, 0, "Deserialization failed"); - res = ser.Serialize(foo); - Assert.AreEqual(_XmlListEmb3, res, "Serialization failed"); - ser = new CXmlSerializer(true); - foo.Ints.Clear(); - res = ser.Serialize(foo); - Assert.AreEqual(_XmlListEmb4, res, "Serialization failed"); - _AssertFail(_Empty); - } - - [TestMethod] - public void TestArrayEmbedded() - { - var xml = new CXmlDeserializer(); - var ser = new CXmlSerializer(); - SArrayEmb foo = xml.DeserializeString(_XmlListEmb); - Assert.AreEqual(foo.Ints.Length, 1, "Deserialization failed"); - Assert.AreEqual(foo.Ints[0].I, 1, "Deserialization failed"); - string res = ser.Serialize(foo); - Assert.AreEqual(_XmlListEmb, res, "Serialization failed"); - foo = xml.DeserializeString(_XmlListEmb2); - Assert.AreEqual(foo.Ints.Length, 2, "Deserialization failed"); - Assert.AreEqual(foo.Ints[1].I, 2, "Deserialization failed"); - res = ser.Serialize(foo); - Assert.AreEqual(_XmlListEmb2, res, "Serialization failed"); - foo = xml.DeserializeString(_XmlListEmb3); - Assert.AreEqual(foo.Ints.Length, 0, "Deserialization failed"); - res = ser.Serialize(foo); - Assert.AreEqual(_XmlListEmb3, res, "Serialization failed"); - ser = new CXmlSerializer(true); - foo.Ints = new SEntry[0]; - res = ser.Serialize(foo); - Assert.AreEqual(_XmlListEmb4, res, "Serialization failed"); - _AssertFail(_Empty); - } - - [TestMethod] - public void TestProperty() - { - const string xmlString = _Head + @" - 2 - 3 -"; - SProperty foo = _AssertSerDeserMatch(xmlString); - Assert.AreEqual(3, foo.Private); - Assert.AreEqual(3, foo.Auto); - } - - [TestMethod] - public void TestByteArray() - { - const string xmlString = _Head + @" - MTMzNw== -"; - _AssertSerDeserMatch(xmlString); - } - - private const string _XmlIgnore = _Head + @" - 2 -"; - private const string _XmlIgnore2 = _Head + @" - 2 - 2 -"; - - [TestMethod] - public void TestIgnore() - { - _AssertSerDeserMatch(_XmlIgnore); - _AssertFail(_XmlIgnore2); - } - - [TestMethod] - public void TestExisting() - { - var foo = new SIgnore {I = 1}; - var xml = new CXmlDeserializer(); - var ser = new CXmlSerializer(); - SIgnore bar = xml.DeserializeString(_XmlIgnore, foo); - Assert.AreEqual(1, bar.I); - Assert.AreEqual(_XmlIgnore, ser.Serialize(bar)); - - var foo2 = new CIgnore {I = 1}; - CIgnore bar2 = xml.DeserializeString(_XmlIgnore, foo2); - Assert.AreEqual(1, bar2.I); - Assert.AreEqual(foo2.J, bar2.J, "Original classes should be modified by the deserialization"); - Assert.AreEqual(_XmlIgnore, ser.Serialize(bar2)); - } - - [TestMethod] - public void TestOnlyList() - { - const string s = _Head + @" - 2 - 3 -"; - _AssertSerDeserMatch>(s); - } - - [TestMethod] - public void TestOnlyDict() - { - const string s = _Head + @" - 2 - 3 -"; - _AssertSerDeserMatch>(s); - } - - [TestMethod] - public void TestDefaultValues() - { - const string s = _Head + @" - 1 - 2 - 3 - 4 - - 22 - -"; - _AssertSerDeserMatch(s); - var xml = new CXmlDeserializer(new CXmlErrorHandler(exception => { })); - SDefault foo = xml.DeserializeString(@""); - Assert.AreEqual(foo.I, 1337); - Assert.AreEqual(foo.F, null); - Assert.AreEqual(foo.S, "Foo"); - Assert.AreEqual(foo.D, 666); - Assert.AreEqual(foo.Sub.I, 111); - string newXml = new CXmlSerializer().Serialize(foo); - Assert.AreEqual(_Head + @" - -", newXml); - } - - [TestMethod] - public void TestRealFiles() - { - Type[] types = new Type[] - {typeof(SThemeCover), typeof(CConfig.SConfig), typeof(SThemeScreen), typeof(SDefaultFonts), typeof(SSkin), typeof(STheme), typeof(Dictionary)}; - string filePath = Path.Combine(new string[] {AppDomain.CurrentDomain.BaseDirectory, "..", "..", "..", "TestXmlFiles"}); - foreach (Type type in types) - { - string xmlPath = Path.Combine(filePath, type.Name + ".xml"); - var deser = new CXmlDeserializer(); - object foo = null; - try - { - foo = deser.Deserialize(xmlPath, Activator.CreateInstance(type)); - } - catch (Exception e) - { - Assert.Fail("Exception with " + type.Name + ": {0}", new object[] {e.Message}); - } - Assert.IsInstanceOfType(foo, type, "Wrong type with " + type.Name); - var ser = new CXmlSerializer(type == typeof(CConfig.SConfig)); - string newXml = ser.Serialize(foo, type == typeof(Dictionary) ? "resources" : null); - // Typename will be uppercase but input is lowercase - newXml = newXml.Replace("