ObjFW  Diff

Differences From Artifact [cacad5286a]:

To Artifact [c77a7c32e4]:


13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
13
14
15
16
17
18
19

20
21
22
23
24
25
26
27







-
+







 * 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"
45
46
47
48
49
50
51


52
53
54
55

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

71
72

73
74

75
76
77

78
79

80
81
82


83
84
85

86
87
88

89
90
91
92

93
94
95
96


97
98
99

100
101
102
103


104
105
106
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
137
138
139
140
141
142
143
144
45
46
47
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

72


73


74

75

76


77
78


79
80
81
82

83

84

85

86
87

88

89


90
91
92
93

94

95


96
97
98
99




100
101
102
103
104
105


106
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
137
138







+
+



-
+














-
+
-
-
+
-
-
+
-

-
+
-
-
+

-
-
+
+


-
+
-

-
+
-


-
+
-

-
-
+
+


-
+
-

-
-
+
+


-
-
-
-
+
+
+
+


-
-
+
+


















-
+


-
+









	    @"double=0.75\r\n";
	OFINIFile *file;
	OFINICategory *tests, *foobar, *types;
	OFArray *array;
#ifndef OF_NINTENDO_DS
	OFString *writePath;
#endif

	module = @"OFINIFile";

	TEST(@"+[fileWithPath:encoding:]",
	    (file = [OFINIFile fileWithPath: @"testfile.ini"
				   encoding: OF_STRING_ENCODING_CODEPAGE_437]))
				   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(@"-[stringForKey:]",
	    [[tests stringForKey: @"foo"] isEqual: @"bar"] &&
	    [[foobar stringForKey: @"quxquxqux"] isEqual: @"hello\"wörld"])

	TEST(@"-[setString:forKey:]",
	    R([tests setString: @"baz"
	    R([tests setString: @"baz" forKey: @"foo"]) &&
			forKey: @"foo"]) &&
	    R([tests setString: @"new"
	    R([tests setString: @"new" forKey: @"new"]) &&
			forKey: @"new"]) &&
	    R([foobar setString: @"a\fb"
	    R([foobar setString: @"a\fb" forKey: @"qux3"]))
			 forKey: @"qux3"]))

	TEST(@"-[integerForKey:defaultValue:]",
	TEST(@"-[longLongForKey:defaultValue:]",
	    [types integerForKey: @"integer"
		    defaultValue: 2] == 0x20)
	    [types longLongForKey: @"integer" defaultValue: 2] == 0x20)

	TEST(@"-[setInteger:forKey:]", R([types setInteger: 0x10
						    forKey: @"integer"]))
	TEST(@"-[setLongLong:forKey:]",
	    R([types setLongLong: 0x10 forKey: @"integer"]))

	TEST(@"-[boolForKey:defaultValue:]",
	    [types boolForKey: @"bool"
	    [types boolForKey: @"bool" defaultValue: false] == true)
		 defaultValue: false] == true)

	TEST(@"-[setBool:forKey:]", R([types setBool: false
	TEST(@"-[setBool:forKey:]", R([types setBool: false forKey: @"bool"]))
					      forKey: @"bool"]))

	TEST(@"-[floatForKey:defaultValue:]",
	    [types floatForKey: @"float"
	    [types floatForKey: @"float" defaultValue: 1] == 0.5f)
		  defaultValue: 1] == 0.5f)

	TEST(@"-[setFloat:forKey:]", R([types setFloat: 0.25f
						forKey: @"float"]))
	TEST(@"-[setFloat:forKey:]",
	    R([types setFloat: 0.25f forKey: @"float"]))

	TEST(@"-[doubleForKey:defaultValue:]",
	    [types doubleForKey: @"double"
	    [types doubleForKey: @"double" defaultValue: 3] == 0.25)
		   defaultValue: 3] == 0.25)

	TEST(@"-[setDouble:forKey:]", R([types setDouble: 0.75
						  forKey: @"double"]))
	TEST(@"-[setDouble:forKey:]",
	    R([types setDouble: 0.75 forKey: @"double"]))

	array = [OFArray arrayWithObjects: @"1", @"2", nil];
	TEST(@"-[arrayForKey:]",
	    [[types arrayForKey: @"array1"] isEqual: array] &&
	    [[types arrayForKey: @"array2"] isEqual: array] &&
	    [[types arrayForKey: @"array3"] isEqual: [OFArray array]])
	TEST(@"-[stringArrayForKey:]",
	    [[types stringArrayForKey: @"array1"] isEqual: array] &&
	    [[types stringArrayForKey: @"array2"] isEqual: array] &&
	    [[types stringArrayForKey: @"array3"] isEqual: [OFArray array]])

	array = [OFArray arrayWithObjects: @"foo", @"bar", nil];
	TEST(@"-[setArray:forKey:]", R([types setArray: array
						forKey: @"array1"]))
	TEST(@"-[setStringArray:forKey:]",
	    R([types setStringArray: 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 */
#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
	TEST(@"-[writeToFile:encoding:]",
	    R([file writeToFile: writePath
		       encoding: OF_STRING_ENCODING_CODEPAGE_437]) &&
		       encoding: OFStringEncodingCodepage437]) &&
	    [[OFString
		stringWithContentsOfFile: writePath
				encoding: OF_STRING_ENCODING_CODEPAGE_437]
				encoding: OFStringEncodingCodepage437]
	    isEqual: output])
	[[OFFileManager defaultManager] removeItemAtPath: writePath];
#else
	(void)output;
#endif

	objc_autoreleasePoolPop(pool);
}
@end