From 0c9cba4e71a0c8e812c8f52fe02752fbc1a4d278 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Fri, 5 Nov 2010 11:47:23 +0100 Subject: [PATCH] add test cases for CPUserDefaults --- Tests/Foundation/CPUserDefaultsTest.j | 77 +++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Tests/Foundation/CPUserDefaultsTest.j diff --git a/Tests/Foundation/CPUserDefaultsTest.j b/Tests/Foundation/CPUserDefaultsTest.j new file mode 100644 index 000000000..fd45e2b4d --- /dev/null +++ b/Tests/Foundation/CPUserDefaultsTest.j @@ -0,0 +1,77 @@ +/* + * CPUserDefaultsTest.j + * + * Copyright (C) 2010 Antoine Mercadal + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +@import +@import + + +@implementation CPUserDefaultsTest : OJTestCase +{ + CPUserDefaults target; +} + +- (void)setUp +{ + target = [CPUserDefaults standardUserDefaults]; +} + +- (void)tearDown +{ + [target removeObjectForKey:@"TESTBOOLKEY"]; + [target removeObjectForKey:@"TESTOBJECTKEY"]; +} + +- (void)testSetBoolForKey +{ + [target setBool:YES forKey:@"TESTBOOLKEY"]; + + [self assertTrue:[target boolForKey:@"TESTBOOLKEY"]]; +} + +- (void)testSetObjectForKey +{ + [target setObject:[CPArray arrayWithObjects:@"cell1", @"cell2"] forKey:@"TESTOBJECTKEY"]; + + var cell1 = [[target objectForKey:@"TESTOBJECTKEY"] objectAtIndex:0], + cell2 = [[target objectForKey:@"TESTOBJECTKEY"] objectAtIndex:1]; + + [self assert:cell1 equals:@"cell1"]; + [self assert:cell2 equals:@"cell2"]; +} + +- (void)testRemoveObjectForKey +{ + [target setBool:YES forKey:@"TESTREMOVE"]; + + [target removeObjectForKey:@"TESTREMOVE"]; + + [self assert:[target boolForKey:@"TESTREMOVE"] equals:NO]; +} + +- (void)testAppDefault +{ + var appDefaults = [CPDictionary dictionaryWithObjectsAndKeys:YES, @"TESTAPPDEF-A", @"Hello!", @"TESTAPPDEF-B"]; + [target registerDefaults:appDefaults]; + + [self assert:[target boolForKey:@"TESTAPPDEF-A"] equals:YES]; + [self assert:[target objectForKey:@"TESTAPPDEF-B"] equals:@"Hello!"]; +} + + +@end \ No newline at end of file