Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -1,8 +1,9 @@ PROG_NOINST = tests${PROG_SUFFIX} -SRCS = OFNumberTests.m \ - OFPBKDF2Tests.m +SRCS = OFNumberTests.m \ + OFPBKDF2Tests.m \ + OFPropertyListTests.m include ../buildsys.mk include ../extra.mk .PHONY: run run-on-ios run-on-android ADDED new_tests/OFPropertyListTests.m Index: new_tests/OFPropertyListTests.m ================================================================== --- new_tests/OFPropertyListTests.m +++ new_tests/OFPropertyListTests.m @@ -0,0 +1,140 @@ +/* + * 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 +{ + bool caught = false; + @try { + [[PLIST(@"") + stringByReplacingOccurrencesOfString: @"1.0" + withString: @"1.1"] + objectByParsingPropertyList]; + } @catch (OFUnsupportedVersionException *e) { + caught = true; + } + OTAssertTrue(caught); +} + +- (void)testDetectInvalidFormat +{ + bool caught; + + caught = false; + @try { + [PLIST(@"") objectByParsingPropertyList]; + } @catch (OFInvalidFormatException *e) { + caught = true; + } + OTAssertTrue(caught); + + caught = false; + @try { + [PLIST(@"") objectByParsingPropertyList]; + } @catch (OFInvalidFormatException *e) { + caught = true; + } + OTAssertTrue(caught); + + caught = false; + @try { + [PLIST(@"") objectByParsingPropertyList]; + } @catch (OFInvalidFormatException *e) { + caught = true; + } + OTAssertTrue(caught); + + caught = false; + @try { + [PLIST(@"") + objectByParsingPropertyList]; + } @catch (OFInvalidFormatException *e) { + caught = true; + } + OTAssertTrue(caught); + + caught = false; + @try { + [PLIST(@"") + objectByParsingPropertyList]; + } @catch (OFInvalidFormatException *e) { + caught = true; + } + OTAssertTrue(caught); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -36,11 +36,10 @@ OFMatrix4x4Tests.m \ OFMemoryStreamTests.m \ OFMethodSignatureTests.m \ OFNotificationCenterTests.m \ OFObjectTests.m \ - OFPropertyListTests.m \ OFRIPEMD160HashTests.m \ OFSHA1HashTests.m \ OFSHA224HashTests.m \ OFSHA256HashTests.m \ OFSHA384HashTests.m \ DELETED tests/OFPropertyListTests.m Index: tests/OFPropertyListTests.m ================================================================== --- tests/OFPropertyListTests.m +++ tests/OFPropertyListTests.m @@ -1,118 +0,0 @@ -/* - * 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 "TestsAppDelegate.h" - -#define PLIST(x) \ - @"" \ - @"" \ - @"\n" \ - x @"\n" \ - @"" - -static OFString *const module = @"OFPropertyList"; -static OFString *const PLIST1 = PLIST(@"Hello"); -static OFString *const PLIST2 = PLIST( - @"" - @" Hello" - @" V29ybGQh" - @" 2018-03-14T12:34:56Z" - @" " - @" " - @" 12.25" - @" -10" - @""); -static OFString *const 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.25f], - [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 Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -169,14 +169,10 @@ @interface TestsAppDelegate (OFObjectTests) - (void)objectTests; @end -@interface TestsAppDelegate (OFPropertyListTests) -- (void)propertyListTests; -@end - @interface TestsAppDelegate (OFPluginTests) - (void)pluginTests; @end @interface TestsAppDelegate (RuntimeTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -437,11 +437,10 @@ #endif [self XMLParserTests]; [self XMLNodeTests]; [self XMLElementBuilderTests]; [self JSONTests]; - [self propertyListTests]; [self matrix4x4Tests]; #ifdef OF_HAVE_PLUGINS [self pluginTests]; #endif