Index: .fossil-settings/clean-glob ================================================================== --- .fossil-settings/clean-glob +++ .fossil-settings/clean-glob @@ -29,10 +29,11 @@ new_tests/EBOOT.PBP new_tests/PARAM.SFO new_tests/plugin/Info.plist new_tests/subprocess/subprocess new_tests/testfile_bin.m +new_tests/testfile_ini.m new_tests/tests new_tests/tests.3dsx new_tests/tests.arm9 new_tests/tests.nds new_tests/tests.nro @@ -50,11 +51,10 @@ tests/EBOOT.PBP tests/Info.plist tests/PARAM.SFO tests/objc_sync/objc_sync tests/terminal/terminal_tests -tests/testfile_ini.m tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro Index: .fossil-settings/ignore-glob ================================================================== --- .fossil-settings/ignore-glob +++ .fossil-settings/ignore-glob @@ -31,10 +31,11 @@ new_tests/EBOOT.PBP new_tests/PARAM.SFO new_tests/plugin/Info.plist new_tests/subprocess/subprocess new_tests/testfile_bin.m +new_tests/testfile_ini.m new_tests/tests new_tests/tests.3dsx new_tests/tests.arm9 new_tests/tests.nds new_tests/tests.nro @@ -55,11 +56,10 @@ tests/iOS.xcodeproj/*.pbxuser tests/iOS.xcodeproj/project.xcworkspace tests/iOS.xcodeproj/xcuserdata tests/objc_sync/objc_sync tests/terminal/terminal_tests -tests/testfile_ini.m tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro Index: .gitignore ================================================================== --- .gitignore +++ .gitignore @@ -31,10 +31,11 @@ new_tests/EBOOT.PBP new_tests/PARAM.SFO new_tests/plugin/Info.plist new_tests/subprocess/subprocess new_tests/testfile_bin.m +new_tests/testfile_ini.m new_tests/tests new_tests/tests.3dsx new_tests/tests.arm9 new_tests/tests.nds new_tests/tests.nro @@ -55,11 +56,10 @@ tests/iOS.xcodeproj/*.pbxuser tests/iOS.xcodeproj/project.xcworkspace tests/iOS.xcodeproj/xcuserdata tests/objc_sync/objc_sync tests/terminal/terminal_tests -tests/testfile_ini.m tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -1,10 +1,17 @@ include ../extra.mk SUBDIRS = ${TESTPLUGIN} ${SUBPROCESS} -CLEAN = testfile_bin.m +CLEAN = EBOOT.PBP \ + boot.dol \ + ${PROG_NOINST}.arm9 \ + ${PROG_NOINST}.nds \ + ${PROG_NOINST}.nro \ + ${PROG_NOINST}.rpx \ + testfile_bin.m \ + testfile_ini.m PROG_NOINST = tests${PROG_SUFFIX} SRCS = OFArrayTests.m \ OFCharacterSetTests.m \ OFColorTests.m \ @@ -11,10 +18,11 @@ OFConcreteArrayTests.m \ OFConcreteMutableArrayTests.m \ OFCryptographicHashTests.m \ OFDateTests.m \ OFHMACTests.m \ + OFINIFileTests.m \ OFIRITests.m \ OFInvocationTests.m \ OFJSONTests.m \ OFMatrix4x4Tests.m \ OFMethodSignatureTests.m \ @@ -25,20 +33,23 @@ OFScryptTests.m \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ - testfile_bin.m + testfile_bin.m \ + testfile_ini.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFSocketTests.m SRCS_SUBPROCESSES = OFSubprocessTests.m SRCS_THREADS = OFThreadTests.m include ../buildsys.mk testfile_bin.m: testfile.bin ${SHELL} ../utils/objfw-embed testfile.bin testfile.bin $@ +testfile_ini.m: testfile.ini + ${SHELL} ../utils/objfw-embed testfile.ini testfile.ini $@ .PHONY: run run-on-ios run-on-android run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} ADDED new_tests/OFINIFileTests.m Index: new_tests/OFINIFileTests.m ================================================================== --- new_tests/OFINIFileTests.m +++ new_tests/OFINIFileTests.m @@ -0,0 +1,171 @@ +/* + * 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 OFINIFileTests: OTTestCase +{ + OFINIFile *_file; +} +@end + +@implementation OFINIFileTests +- (void)setUp +{ + OFIRI *IRI; + + [super setUp]; + + IRI = [OFIRI IRIWithString: @"embedded:testfile.ini"]; + _file = [[OFINIFile alloc] initWithIRI: IRI + encoding: OFStringEncodingISO8859_1]; +} + +- (void)dealloc +{ + [_file release]; + + [super dealloc]; +} + +- (void)testCategoryForName +{ + OTAssertNotNil([_file categoryForName: @"tests"]); + OTAssertNotNil([_file categoryForName: @"foobar"]); + OTAssertNotNil([_file categoryForName: @"types"]); +} + +- (void)testStringValueForKey +{ + OTAssertEqualObjects( + [[_file categoryForName: @"tests"] stringValueForKey: @"foo"], + @"bar"); + + OTAssertEqualObjects([[_file categoryForName: @"foobar"] + stringValueForKey: @"quxquxqux"], + @"hello\"wörld"); +} + +- (void)testLongLongValueForKeyDefaultValue +{ + OTAssertEqual([[_file categoryForName: @"types"] + longLongValueForKey: @"integer" + defaultValue: 2], + 0x20); +} + +- (void)testBoolValueForKeyDefaultValue +{ + OTAssertTrue([[_file categoryForName: @"types"] + boolValueForKey: @"bool" + defaultValue: false]); +} + +- (void)testFloatValueForKeyDefaultValue +{ + OTAssertEqual([[_file categoryForName: @"types"] + floatValueForKey: @"float" + defaultValue: 1], + 0.5f); +} + +- (void)testDoubleValueForKeyDefaultValue +{ + OTAssertEqual([[_file categoryForName: @"types"] + doubleValueForKey: @"double" + defaultValue: 3], + 0.25); +} + +- (void)testArrayValueForKey +{ + OFINICategory *types = [_file categoryForName: @"types"]; + OFArray *array = [OFArray arrayWithObjects: @"1", @"2", nil]; + + OTAssertEqualObjects([types arrayValueForKey: @"array1"], array); + OTAssertEqualObjects([types arrayValueForKey: @"array2"], array); + OTAssertEqualObjects([types arrayValueForKey: @"array3"], + [OFArray array]); +} + +- (void)testWriteToIRIEncoding +{ + OFString *expectedOutput = @"[tests]\r\n" + @"foo=baz\r\n" + @"foobar=baz\r\n" + @";comment\r\n" + @"new=new\r\n" + @"\r\n" + @"[foobar]\r\n" + @";foobarcomment\r\n" + @"qux=\" asd\"\r\n" + @"quxquxqux=\"hello\\\"wörld\"\r\n" + @"qux2=\"a\\f\"\r\n" + @"qux3=a\fb\r\n" + @"\r\n" + @"[types]\r\n" + @"integer=16\r\n" + @"bool=false\r\n" + @"float=0.25\r\n" + @"array1=foo\r\n" + @"array1=bar\r\n" + @"double=0.75\r\n"; + OFINICategory *tests = [_file categoryForName: @"tests"]; + OFINICategory *foobar = [_file categoryForName: @"foobar"]; + OFINICategory *types = [_file categoryForName: @"types"]; + OFArray *array = [OFArray arrayWithObjects: @"foo", @"bar", nil]; +#if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) + OFIRI *writeIRI; +#endif + + [tests setStringValue: @"baz" forKey: @"foo"]; + [tests setStringValue: @"new" forKey: @"new"]; + [foobar setStringValue: @"a\fb" forKey: @"qux3"]; + [types setLongLongValue: 0x10 forKey: @"integer"]; + [types setBoolValue: false forKey: @"bool"]; + [types setFloatValue: 0.25f forKey: @"float"]; + [types setDoubleValue: 0.75 forKey: @"double"]; + [types setArrayValue: array forKey: @"array1"]; + + [foobar removeValueForKey: @"quxqux "]; + [types removeValueForKey: @"array2"]; + + /* FIXME: Find a way to write files on Nintendo DS */ +#if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) + writeIRI = [OFSystemInfo temporaryDirectoryIRI]; + if (writeIRI == nil) + writeIRI = [[OFFileManager defaultManager] currentDirectoryIRI]; + writeIRI = [writeIRI IRIByAppendingPathComponent: @"objfw-tests.ini" + isDirectory: false]; + + [_file writeToIRI: writeIRI + encoding: OFStringEncodingISO8859_1]; + + @try { + OTAssertEqualObjects([OFString + stringWithContentsOfIRI: writeIRI + encoding: OFStringEncodingISO8859_1], + expectedOutput); + } @finally { + [[OFFileManager defaultManager] removeItemAtIRI: writeIRI]; + } +#else + (void)expectedOutput; +#endif +} +@end ADDED new_tests/testfile.ini Index: new_tests/testfile.ini ================================================================== --- new_tests/testfile.ini +++ new_tests/testfile.ini @@ -0,0 +1,21 @@ +[tests] +foo = bar +foobar=baz +;comment + +[foobar] +;foobarcomment +qux=" asd" +"quxqux " = asd +quxquxqux="hello\"wörld" +qux2="a\f" + +[types] +integer = 0x20 +bool = true +float = 0.5 +array1 = 1 +array2 = 1 +double = 0.25 +array1 = 2 +array2 = 2 Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -6,21 +6,19 @@ CLEAN = EBOOT.PBP \ boot.dol \ ${PROG_NOINST}.arm9 \ ${PROG_NOINST}.nds \ ${PROG_NOINST}.nro \ - ${PROG_NOINST}.rpx \ - testfile_ini.m + ${PROG_NOINST}.rpx DISTCLEAN = Info.plist PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} SRCS = ForwardingTests.m \ ${OF_BLOCK_TESTS_M} \ OFDataTests.m \ OFDictionaryTests.m \ - OFINIFileTests.m \ OFListTests.m \ OFLocaleTests.m \ OFMemoryStreamTests.m \ OFNotificationCenterTests.m \ OFObjectTests.m \ @@ -35,12 +33,11 @@ RuntimeTests.m \ ${RUNTIME_ARC_TESTS_M} \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_SOCKETS} \ - ${USE_SRCS_WINDOWS} \ - testfile_ini.m + ${USE_SRCS_WINDOWS} SRCS_SOCKETS = OFDNSResolverTests.m \ ${OF_HTTP_CLIENT_TESTS_M} \ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m \ @@ -60,13 +57,10 @@ IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test include ../buildsys.mk -testfile_ini.m: testfile.ini - ${SHELL} ../utils/objfw-embed testfile.ini testfile.ini $@ - .PHONY: run run-on-ios run-on-android run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib DELETED tests/OFINIFileTests.m Index: tests/OFINIFileTests.m ================================================================== --- tests/OFINIFileTests.m +++ tests/OFINIFileTests.m @@ -1,138 +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" - -static OFString *module; - -@implementation TestsAppDelegate (OFINIFileTests) -- (void)INIFileTests -{ - void *pool = objc_autoreleasePoolPush(); - OFString *output = @"[tests]\r\n" - @"foo=baz\r\n" - @"foobar=baz\r\n" - @";comment\r\n" - @"new=new\r\n" - @"\r\n" - @"[foobar]\r\n" - @";foobarcomment\r\n" - @"qux=\" asd\"\r\n" - @"quxquxqux=\"hello\\\"wörld\"\r\n" - @"qux2=\"a\\f\"\r\n" - @"qux3=a\fb\r\n" - @"\r\n" - @"[types]\r\n" - @"integer=16\r\n" - @"bool=false\r\n" - @"float=0.25\r\n" - @"array1=foo\r\n" - @"array1=bar\r\n" - @"double=0.75\r\n"; - OFIRI *IRI; - OFINIFile *file; - OFINICategory *tests, *foobar, *types; - OFArray *array; -#if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) - OFIRI *writeIRI; -#endif - - module = @"OFINIFile"; - - IRI = [OFIRI IRIWithString: @"embedded:testfile.ini"]; - TEST(@"+[fileWithIRI:encoding:]", - (file = [OFINIFile fileWithIRI: IRI - encoding: OFStringEncodingCodepage437])) - - tests = [file categoryForName: @"tests"]; - foobar = [file categoryForName: @"foobar"]; - types = [file categoryForName: @"types"]; - TEST(@"-[categoryForName:]", - tests != nil && foobar != nil && types != nil) - - module = @"OFINICategory"; - - TEST(@"-[stringValueForKey:]", - [[tests stringValueForKey: @"foo"] isEqual: @"bar"] && - [[foobar stringValueForKey: @"quxquxqux"] isEqual: @"hello\"wörld"]) - - TEST(@"-[setStringValue:forKey:]", - R([tests setStringValue: @"baz" forKey: @"foo"]) && - R([tests setStringValue: @"new" forKey: @"new"]) && - R([foobar setStringValue: @"a\fb" forKey: @"qux3"])) - - TEST(@"-[longLongValueForKey:defaultValue:]", - [types longLongValueForKey: @"integer" defaultValue: 2] == 0x20) - - TEST(@"-[setLongLongValue:forKey:]", - R([types setLongLongValue: 0x10 forKey: @"integer"])) - - TEST(@"-[boolValueForKey:defaultValue:]", - [types boolValueForKey: @"bool" defaultValue: false] == true) - - TEST(@"-[setBoolValue:forKey:]", - R([types setBoolValue: false forKey: @"bool"])) - - TEST(@"-[floatValueForKey:defaultValue:]", - [types floatValueForKey: @"float" defaultValue: 1] == 0.5f) - - TEST(@"-[setFloatValue:forKey:]", - R([types setFloatValue: 0.25f forKey: @"float"])) - - TEST(@"-[doubleValueForKey:defaultValue:]", - [types doubleValueForKey: @"double" defaultValue: 3] == 0.25) - - TEST(@"-[setDoubleValue:forKey:]", - R([types setDoubleValue: 0.75 forKey: @"double"])) - - array = [OFArray arrayWithObjects: @"1", @"2", nil]; - TEST(@"-[arrayValueForKey:]", - [[types arrayValueForKey: @"array1"] isEqual: array] && - [[types arrayValueForKey: @"array2"] isEqual: array] && - [[types arrayValueForKey: @"array3"] isEqual: [OFArray array]]) - - array = [OFArray arrayWithObjects: @"foo", @"bar", nil]; - TEST(@"-[setArrayValue:forKey:]", - R([types setArrayValue: array forKey: @"array1"])) - - TEST(@"-[removeValueForKey:]", - R([foobar removeValueForKey: @"quxqux "]) && - R([types removeValueForKey: @"array2"])) - - module = @"OFINIFile"; - - /* FIXME: Find a way to write files on Nintendo DS */ -#if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) - writeIRI = [OFSystemInfo temporaryDirectoryIRI]; - if (writeIRI == nil) - writeIRI = [[OFFileManager defaultManager] currentDirectoryIRI]; - writeIRI = [writeIRI IRIByAppendingPathComponent: @"objfw-tests.ini" - isDirectory: false]; - TEST(@"-[writeToFile:encoding:]", - R([file writeToIRI: writeIRI - encoding: OFStringEncodingCodepage437]) && - [[OFString stringWithContentsOfIRI: writeIRI - encoding: OFStringEncodingCodepage437] - isEqual: output]) - [[OFFileManager defaultManager] removeItemAtIRI: writeIRI]; -#else - (void)output; -#endif - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -93,14 +93,10 @@ @interface TestsAppDelegate (OFHTTPCookieManagerTests) - (void)HTTPCookieManagerTests; @end -@interface TestsAppDelegate (OFINIFileTests) -- (void)INIFileTests; -@end - @interface TestsAppDelegate (OFIPXSocketTests) - (void)IPXSocketTests; @end @interface TestsAppDelegate (OFKernelEventObserverTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -386,13 +386,10 @@ [self setTests]; [self valueTests]; [self streamTests]; [self memoryStreamTests]; [self notificationCenterTests]; -#ifdef HAVE_CODEPAGE_437 - [self INIFileTests]; -#endif #ifdef OF_HAVE_SOCKETS [self TCPSocketTests]; [self UDPSocketTests]; # ifdef OF_HAVE_UNIX_SOCKETS [self UNIXDatagramSocketTests]; DELETED tests/testfile.ini Index: tests/testfile.ini ================================================================== --- tests/testfile.ini +++ tests/testfile.ini @@ -1,21 +0,0 @@ -[tests] -foo = bar -foobar=baz -;comment - -[foobar] -;foobarcomment -qux=" asd" -"quxqux " = asd -quxquxqux="hello\"w”rld" -qux2="a\f" - -[types] -integer = 0x20 -bool = true -float = 0.5 -array1 = 1 -array2 = 1 -double = 0.25 -array1 = 2 -array2 = 2