/* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFString.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFNumber.h" #import "OFAutoreleasePool.h" #import "OFInvalidFormatException.h" #import "OFUnsupportedVersionException.h" #import "TestsAppDelegate.h" #define PLIST(x) \ @"" \ @"" \ @"\n" \ x @"\n" \ @"" static OFString *module = @"OFPropertyList"; static OFString *PLIST1 = PLIST(@"Hello"); static OFString *PLIST2 = PLIST( @"" @" Hello" @" V29ybGQh" @" 2018-03-14T12:34:56Z" @" " @" " @" 12.25" @" -10" @""); static OFString *PLIST3 = PLIST( @"" @" array" @" " @" Hello" @" V29ybGQh" @" 2018-03-14T12:34:56Z" @" " @" " @" 12.25" @" -10" @" " @" foo" @" bar" @""); @implementation TestsAppDelegate (OFPLISTParser) - (void)propertyListTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFArray *array = [OFArray arrayWithObjects: @"Hello", [OFData dataWithItems: "World!" count: 6], [OFDate dateWithTimeIntervalSince1970: 1521030896], [OFNumber numberWithBool: true], [OFNumber numberWithBool: false], [OFNumber numberWithFloat: 12.25], [OFNumber numberWithInt: -10], nil]; TEST(@"-[propertyListValue:] #1", [[PLIST1 propertyListValue] isEqual: @"Hello"]) TEST(@"-[propertyListValue:] #2", [[PLIST2 propertyListValue] isEqual: array]) TEST(@"-[propertyListValue:] #3", [[PLIST3 propertyListValue] isEqual: [OFDictionary dictionaryWithKeysAndObjects: @"array", array, @"foo", @"bar", nil]]) EXPECT_EXCEPTION(@"-[propertyListValue] detecting unsupported version", OFUnsupportedVersionException, [[PLIST(@"") stringByReplacingOccurrencesOfString: @"1.0" withString: @"1.1"] propertyListValue]) EXPECT_EXCEPTION( @"-[propertyListValue] detecting invalid format #1", OFInvalidFormatException, [PLIST(@"") propertyListValue]) EXPECT_EXCEPTION( @"-[propertyListValue] detecting invalid format #2", OFInvalidFormatException, [PLIST(@"") propertyListValue]) EXPECT_EXCEPTION( @"-[propertyListValue] detecting invalid format #3", OFInvalidFormatException, [PLIST(@"") propertyListValue]) EXPECT_EXCEPTION( @"-[propertyListValue] detecting invalid format #4", OFInvalidFormatException, [PLIST(@"") propertyListValue]) EXPECT_EXCEPTION( @"-[propertyListValue] detecting invalid format #5", OFInvalidFormatException, [PLIST(@"") propertyListValue]) [pool drain]; } @end