ObjFW  Diff

Differences From Artifact [0d85330d49]:

To Artifact [edfee9097f]:


1
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27

-
+

















-
+







/*
 * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
 * Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
 *
 * 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 = @"OFINIFile";
static OFString *module;

@implementation TestsAppDelegate (OFINIFileTests)
- (void)INIFileTests
{
	void *pool = objc_autoreleasePoolPush();
	OFString *output = @"[tests]\r\n"
	    @"foo=baz\r\n"
39
40
41
42
43
44
45

46
47
48
49
50


51
52



53
54
55



56
57
58
59
60
61
62
39
40
41
42
43
44
45
46
47
48
49


50
51
52
53
54
55
56



57
58
59
60
61
62
63
64
65
66







+



-
-
+
+


+
+
+
-
-
-
+
+
+







	    @"[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";
	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

	module = @"OFINIFile";

	URL = [OFURL URLWithString: @"objfw-embedded:///testfile.ini"];
	TEST(@"+[fileWithPath:encoding:]",
	    (file = [OFINIFile fileWithPath: @"testfile.ini"
				   encoding: OFStringEncodingCodepage437]))
	TEST(@"+[fileWithURL:encoding:]",
	    (file = [OFINIFile fileWithURL: URL
				  encoding: OFStringEncodingCodepage437]))

	tests = [file categoryForName: @"tests"];
	foobar = [file categoryForName: @"foobar"];
	types = [file categoryForName: @"types"];
	TEST(@"-[categoryForName:]",
	    tests != nil && foobar != nil && types != nil)

107
108
109
110
111
112
113
114
115
116
117




118
119
120
121
122
123
124
125



126
127

128
129

130
131
132
133
134
135
136
111
112
113
114
115
116
117




118
119
120
121




122



123
124
125


126
127

128
129
130
131
132
133
134
135







-
-
-
-
+
+
+
+
-
-
-
-

-
-
-
+
+
+
-
-
+

-
+







	TEST(@"-[removeValueForKey:]",
	    R([foobar removeValueForKey: @"quxqux "]) &&
	    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
#if defined(OF_HAVE_FILES) && !defined(OF_NINTENDO_DS)
	writeURL = [[OFSystemInfo temporaryDirectoryURL]
	    URLByAppendingPathComponent: @"objfw-tests.ini"
			    isDirectory: false];
	writePath = [OFString pathWithComponents: [OFArray arrayWithObjects:
	    [[OFApplication environment] objectForKey: @"HOME"],
	    @"tmp", @"tmpfile.ini", nil]];
# endif
	TEST(@"-[writeToFile:encoding:]",
	    R([file writeToFile: writePath
		       encoding: OFStringEncodingCodepage437]) &&
	    [[OFString
	    R([file writeToURL: writeURL
		      encoding: OFStringEncodingCodepage437]) &&
	    [[OFString stringWithContentsOfURL: writeURL
		stringWithContentsOfFile: writePath
				encoding: OFStringEncodingCodepage437]
				      encoding: OFStringEncodingCodepage437]
	    isEqual: output])
	[[OFFileManager defaultManager] removeItemAtPath: writePath];
	[[OFFileManager defaultManager] removeItemAtURL: writeURL];
#else
	(void)output;
#endif

	objc_autoreleasePoolPop(pool);
}
@end