/* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018, 2019, 2020 * 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 "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 { void *pool = objc_autoreleasePoolPush(); 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(@"-[objectByParsingPropertyList:] #1", [PLIST1.objectByParsingPropertyList isEqual: @"Hello"]) TEST(@"-[objectByParsingPropertyList:] #2", [PLIST2.objectByParsingPropertyList isEqual: array]) TEST(@"-[objectByParsingPropertyList:] #3", [PLIST3.objectByParsingPropertyList isEqual: [OFDictionary dictionaryWithKeysAndObjects: @"array", array, @"foo", @"bar", nil]]) EXPECT_EXCEPTION(@"Detecting unsupported version", OFUnsupportedVersionException, [[PLIST(@"") stringByReplacingOccurrencesOfString: @"1.0" withString: @"1.1"] objectByParsingPropertyList]) EXPECT_EXCEPTION( @"-[objectByParsingPropertyList] detecting invalid format #1", OFInvalidFormatException, [PLIST(@"") objectByParsingPropertyList]) EXPECT_EXCEPTION( @"-[objectByParsingPropertyList] detecting invalid format #2", OFInvalidFormatException, [PLIST(@"") objectByParsingPropertyList]) EXPECT_EXCEPTION( @"-[objectByParsingPropertyList] detecting invalid format #3", OFInvalidFormatException, [PLIST(@"") objectByParsingPropertyList]) EXPECT_EXCEPTION( @"-[objectByParsingPropertyList] detecting invalid format #4", OFInvalidFormatException, [PLIST(@"") objectByParsingPropertyList]) EXPECT_EXCEPTION( @"-[objectByParsingPropertyList] detecting invalid format #5", OFInvalidFormatException, [PLIST(@"") objectByParsingPropertyList]) objc_autoreleasePoolPop(pool); } @end