From 3daaecf2c9af8ca64d651e1238849b6d5e0a4596 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 30 May 2012 15:12:51 +0200 Subject: [PATCH] Added test to validate the date format strings in translations --- tests/src/com/fsck/k9/TranslationTest.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/src/com/fsck/k9/TranslationTest.java diff --git a/tests/src/com/fsck/k9/TranslationTest.java b/tests/src/com/fsck/k9/TranslationTest.java new file mode 100644 index 000000000..2cd39ed26 --- /dev/null +++ b/tests/src/com/fsck/k9/TranslationTest.java @@ -0,0 +1,41 @@ +package com.fsck.k9; + +import com.fsck.k9.activity.K9Activity; +import com.fsck.k9.helper.DateFormatter; + +import android.content.Context; +import android.content.res.Resources; +import android.test.AndroidTestCase; + +public class TranslationTest extends AndroidTestCase { + public void testDateFormats() { + forAllLanguages(new LanguageSpecific() { + @Override + public void runWithLanguage(Context context, String language) { + Resources res = context.getResources(); + String dateFormatCommon = res.getString(R.string.date_format_common); + try { + DateFormatter.getDateFormat(mContext, dateFormatCommon); + } catch (Exception e) { + fail("Invalid date format string \"" + dateFormatCommon + + "\" for language \"" + language + "\""); + } + } + }); + } + + private void forAllLanguages(LanguageSpecific action) { + Resources res = mContext.getResources(); + String[] languages = res.getStringArray(R.array.supported_languages); + + for (String lang : languages) { + K9Activity.setLanguage(mContext, lang); + + action.runWithLanguage(mContext, lang); + } + } + + interface LanguageSpecific { + void runWithLanguage(Context context, String language); + } +}