/* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFPropertyListTests: OTTestCase @end #define PLIST(x) \ @"" \ @"" \ @"\n" \ x @"\n" \ @"" @implementation OFPropertyListTests - (void)testObjectByParsingPropertyList { OFArray *array = [OFArray arrayWithObjects: @"Hello", [OFData dataWithItems: "World!" count: 6], [OFDate dateWithTimeIntervalSince1970: 1521030896], [OFNumber numberWithBool: true], [OFNumber numberWithBool: false], [OFNumber numberWithFloat: 12.25f], [OFNumber numberWithInt: -10], nil]; OTAssertEqualObjects([PLIST( @"Hello") objectByParsingPropertyList], @"Hello"); OTAssertEqualObjects([PLIST( @"" @" Hello" @" V29ybGQh" @" 2018-03-14T12:34:56Z" @" " @" " @" 12.25" @" -10" @"") objectByParsingPropertyList], array); OTAssertEqualObjects([PLIST( @"" @" array" @" " @" Hello" @" V29ybGQh" @" 2018-03-14T12:34:56Z" @" " @" " @" 12.25" @" -10" @" " @" foo" @" bar" @"") objectByParsingPropertyList], ([OFDictionary dictionaryWithKeysAndObjects: @"array", array, @"foo", @"bar", nil])); } - (void)testDetectUnsupportedVersion { OTAssertThrowsSpecific( [[PLIST(@"") stringByReplacingOccurrencesOfString: @"1.0" withString: @"1.1"] objectByParsingPropertyList], OFUnsupportedVersionException); } - (void)testDetectInvalidFormat { OTAssertThrowsSpecific( [PLIST(@"") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"") objectByParsingPropertyList], OFInvalidFormatException); } @end