# HG changeset patch # User IBBoard # Date 1270825967 0 # Node ID e9bad86c1360658c2e9f5bf69111db43842ccf67 # Parent 2834da2b88916b893b43a67dc12aa49f93798d65 Fixes #35: Add multi-level cascading of translations * Add tests to check for handling of looping diff -r 2834da2b8891 -r e9bad86c1360 Lang/AbstractTranslationSetTest.cs --- a/Lang/AbstractTranslationSetTest.cs Wed Apr 07 19:36:08 2010 +0000 +++ b/Lang/AbstractTranslationSetTest.cs Fri Apr 09 15:12:47 2010 +0000 @@ -49,6 +49,25 @@ } [Test()] + [ExpectedException(typeof(TranslationLoadException), ExpectedMessage = "Translations contained an inheritence loop")] + public void TestTranslationsThrowExceptionWithDirectLoop() + { + AbstractTranslationSet loopTranslations = GetTranslationSetWithDirectLoop(); + String trans = loopTranslations["missing"]; + Assert.Fail("Exception not thrown: " + trans); + } + + [Test()] + [ExpectedException(typeof(TranslationLoadException), ExpectedMessage = "Translations contained an inheritence loop")] + public void TestTranslationsThrowExceptionWithIndirectLoop() + { + AbstractTranslationSet loopTranslations = GetTranslationSetWithIndirectLoop(); + String trans = loopTranslations["missing"]; + Assert.Fail("Exception not thrown: " + trans); + } + + + [Test()] public void TestEquality() { Assert.AreEqual(GetTranslationSet("en"), GetTranslationSet("en")); @@ -69,5 +88,7 @@ protected abstract AbstractTranslationSet GetTranslationSet(string language); protected abstract AbstractTranslationSet GetTranslationSetWithInheritance(string language, string parentLanguage); protected abstract AbstractTranslationSet GetTranslationSetWithFixedValue(); + protected abstract AbstractTranslationSet GetTranslationSetWithDirectLoop(); + protected abstract AbstractTranslationSet GetTranslationSetWithIndirectLoop(); } } diff -r 2834da2b8891 -r e9bad86c1360 Lang/ModifiableTranslationSetTest.cs --- a/Lang/ModifiableTranslationSetTest.cs Wed Apr 07 19:36:08 2010 +0000 +++ b/Lang/ModifiableTranslationSetTest.cs Fri Apr 09 15:12:47 2010 +0000 @@ -26,10 +26,30 @@ } protected override AbstractTranslationSet GetTranslationSetWithFixedValue() - { + { ModifiableTranslationSet translations = new ModifiableTranslationSet("en"); translations.SetTranslation(TEST_KEY, TEST_VALUE); return translations; } + + protected override AbstractTranslationSet GetTranslationSetWithDirectLoop() + { + ModifiableTranslationSet translations = new ModifiableTranslationSet("en-US"); + ModifiableTranslationSet parentTranslations = new ModifiableTranslationSet("en"); + translations.SetParentTranslations(parentTranslations); + parentTranslations.SetParentTranslations(translations); + return translations; + } + + protected override AbstractTranslationSet GetTranslationSetWithIndirectLoop() + { + ModifiableTranslationSet translations = new ModifiableTranslationSet("it"); + ModifiableTranslationSet parentTranslations = new ModifiableTranslationSet("en-US"); + ModifiableTranslationSet parentParentTranslations = new ModifiableTranslationSet("en"); + translations.SetParentTranslations(parentTranslations); + parentTranslations.SetParentTranslations(parentParentTranslations); + parentParentTranslations.SetParentTranslations(translations); + return translations; + } } }