@@ -1,7 +1,7 @@ /* - * Copyright (c) 2008-2021 Jonathan Schleifer + * Copyright (c) 2008-2022 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 @@ -15,11 +15,11 @@ #include "config.h" #import "TestsAppDelegate.h" -static OFString *module = @"OFINIFile"; +static OFString *module; @implementation TestsAppDelegate (OFINIFileTests) - (void)INIFileTests { void *pool = objc_autoreleasePoolPush(); @@ -41,20 +41,24 @@ @"bool=false\r\n" @"float=0.25\r\n" @"array1=foo\r\n" @"array1=bar\r\n" @"double=0.75\r\n"; + OFURL *URL; OFINIFile *file; OFINICategory *tests, *foobar, *types; OFArray *array; -#ifndef OF_NINTENDO_DS - OFString *writePath; +#if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) + OFURL *writeURL; #endif - TEST(@"+[fileWithPath:encoding:]", - (file = [OFINIFile fileWithPath: @"testfile.ini" - encoding: OFStringEncodingCodepage437])) + module = @"OFINIFile"; + + URL = [OFURL URLWithString: @"objfw-embedded:///testfile.ini"]; + TEST(@"+[fileWithURL:encoding:]", + (file = [OFINIFile fileWithURL: URL + encoding: OFStringEncodingCodepage437])) tests = [file categoryForName: @"tests"]; foobar = [file categoryForName: @"foobar"]; types = [file categoryForName: @"types"]; TEST(@"-[categoryForName:]", @@ -109,28 +113,23 @@ R([types removeValueForKey: @"array2"])) module = @"OFINIFile"; /* FIXME: Find a way to write files on Nintendo DS */ -#ifndef OF_NINTENDO_DS -# ifndef OF_IOS - writePath = @"tmpfile.ini"; -# else - writePath = [OFString pathWithComponents: [OFArray arrayWithObjects: - [[OFApplication environment] objectForKey: @"HOME"], - @"tmp", @"tmpfile.ini", nil]]; -# endif +#if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS) + writeURL = [[OFSystemInfo temporaryDirectoryURL] + URLByAppendingPathComponent: @"objfw-tests.ini" + isDirectory: false]; TEST(@"-[writeToFile:encoding:]", - R([file writeToFile: writePath - encoding: OFStringEncodingCodepage437]) && - [[OFString - stringWithContentsOfFile: writePath - encoding: OFStringEncodingCodepage437] + R([file writeToURL: writeURL + encoding: OFStringEncodingCodepage437]) && + [[OFString stringWithContentsOfURL: writeURL + encoding: OFStringEncodingCodepage437] isEqual: output]) - [[OFFileManager defaultManager] removeItemAtPath: writePath]; + [[OFFileManager defaultManager] removeItemAtURL: writeURL]; #else (void)output; #endif objc_autoreleasePoolPop(pool); } @end