From 66b1d297ba5f122aea4c03b2aadf41f2f36eee33 Mon Sep 17 00:00:00 2001 From: Alexandre Wilhelm Date: Wed, 22 Apr 2015 15:11:47 -0700 Subject: [PATCH] Test: added unit test CPBundleTest --- Tests/Foundation/BundleTest/Info.plist | 16 +++++ .../Resources/fr.lproj/Localizable.strings | 5 ++ Tests/Foundation/CPBundleTest.j | 69 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 Tests/Foundation/BundleTest/Info.plist create mode 100644 Tests/Foundation/BundleTest/Resources/fr.lproj/Localizable.strings create mode 100644 Tests/Foundation/CPBundleTest.j diff --git a/Tests/Foundation/BundleTest/Info.plist b/Tests/Foundation/BundleTest/Info.plist new file mode 100644 index 000000000..6a2f0fe2d --- /dev/null +++ b/Tests/Foundation/BundleTest/Info.plist @@ -0,0 +1,16 @@ + + + + + Main cib file base name + MainMenu.cib + CPBundleName + BundleTest + CPBundleLocalizableStrings + + Localizable.strings + + CPBundleDefaultLanguage + fr + + diff --git a/Tests/Foundation/BundleTest/Resources/fr.lproj/Localizable.strings b/Tests/Foundation/BundleTest/Resources/fr.lproj/Localizable.strings new file mode 100644 index 000000000..1c16f3ac7 --- /dev/null +++ b/Tests/Foundation/BundleTest/Resources/fr.lproj/Localizable.strings @@ -0,0 +1,5 @@ +/* My first context. */ +"Label from file" = "Label traduit de fr.lproj du premier context"; + +/* My second context. */ +"Label from file" = "Label traduit de fr.lproj du second context"; \ No newline at end of file diff --git a/Tests/Foundation/CPBundleTest.j b/Tests/Foundation/CPBundleTest.j new file mode 100644 index 000000000..f301175fc --- /dev/null +++ b/Tests/Foundation/CPBundleTest.j @@ -0,0 +1,69 @@ +@import + +@implementation CPBundleTest : OJTestCase +{ + +} + ++ (void)setUp +{ + +} + ++ (void)tearDown +{ + +} + +- (void)setUp +{ + +} + +- (void)tearDown +{ + +} + +- (void)testCreationMainBundle +{ + var bundle = [CPBundle mainBundle]; +} + +- (void)testLoadingBundle +{ + var bundle = [CPBundle bundleWithPath:@"Tests/Foundation/BundleTest"]; + [bundle loadWithDelegate:self]; + + [self assert:[bundle objectForInfoDictionaryKey:"CPBundleDefaultLanguage"] equals:"fr"]; + [self assert:[bundle objectForInfoDictionaryKey:"CPBundleLocalizableStrings"] equals:["Localizable.strings"]]; +} + +- (void)testLocalization +{ + var bundle = [CPBundle bundleWithPath:@"Tests/Foundation/BundleTest"]; + [bundle loadWithDelegate:self]; + + [self assert:[bundle localizedStringForKey:"Label from file" value:"" table:"Localizable"] equals:"Label traduit de fr.lproj du premier context"]; + [self assert:[bundle localizedStringForKey:"Wrong key" value:"Default value" table:"Localizable"] equals:"Default value"]; + [self assert:[bundle localizedStringForKey:"Wrong key" value:"" table:"Localizable"] equals:"Wrong key"]; + + [self assert:CPCopyLocalizedStringFromTableInBundle("Label from file", "Localizable", bundle, "My first context.") equals:"Label traduit de fr.lproj du premier context"]; + [self assert:CPCopyLocalizedStringFromTableInBundle("Label from file", "", bundle, "My first context.") equals:"Label traduit de fr.lproj du premier context"]; + [self assert:CPCopyLocalizedStringFromTableInBundle("Label from file", "Localizable", bundle, "") equals:"Label traduit de fr.lproj du premier context"]; + [self assert:CPCopyLocalizedStringFromTableInBundle("Wrong key", "Localizable", bundle, "") equals:"Wrong key"]; + [self assert:CPCopyLocalizedStringFromTableInBundle("Wrong key", "coucou", bundle, "") equals:"Wrong key"]; + + [self assert:CPCopyLocalizedStringFromTableInBundle("Label from file", "Localizable", bundle, "My second context.") equals:"Label traduit de fr.lproj du second context"]; +} + +@end + +@implementation CPBundleTest (CPBundleTestBundleDelegate) + +- (void)bundleDidFinishLoading:(CPBundle)aBundle +{ + +} + +@end \ No newline at end of file