Changes In Branch objfwtest Through [87d92e4803] Excluding Merge-Ins
This is equivalent to a diff from 2547c1c4ce to 87d92e4803
2024-02-18
| ||
13:53 | OFMapTable: Improve enumeration mutation detection check-in: ab14af79d2 user: js tags: trunk | |
2024-02-14
| ||
23:55 | ObjFWTest: Implement output on Nintendo 3DS check-in: 12d7d274f1 user: js tags: objfwtest | |
22:28 | ObjFWTest: Implement output on Wii check-in: 87d92e4803 user: js tags: objfwtest | |
00:47 | Fix `make check` with nbmake check-in: 9842ae0680 user: js tags: objfwtest | |
2024-02-13
| ||
22:43 | Merge trunk into branch "objfwtest" check-in: ac3ec432a6 user: js tags: objfwtest | |
22:40 | Make sure objects are correctly aligned on Windows check-in: 2547c1c4ce user: js tags: trunk | |
22:06 | Don't use max_align_t for OF_BIGGEST_ALIGNMENT check-in: c80075f6e4 user: js tags: trunk | |
Modified .fossil-settings/clean-glob from [2a90f48586] to [e643e584dc].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | config.log config.status configure docs extra.mk generators/library/gen_libraries generators/unicode/gen_tables src/Info.plist src/bridge/Info.plist src/libobjfw.* src/objfw-defs.h src/runtime/Info.plist src/runtime/libobjfwrt.* src/test/libobjfwtest.a src/tls/Info.plist src/tls/libobjfwtls.* tests/DerivedData tests/EBOOT.PBP tests/Info.plist tests/PARAM.SFO tests/objc_sync/objc_sync | > > > > > > > > > > > > < < < < | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 67 | config.log config.status configure docs extra.mk generators/library/gen_libraries generators/unicode/gen_tables 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 new_tests/tests.rpx src/Info.plist src/bridge/Info.plist src/libobjfw.* src/objfw-defs.h src/runtime/Info.plist src/runtime/libobjfwrt.* src/test/libobjfwtest.a src/tls/Info.plist src/tls/libobjfwtls.* tests/DerivedData tests/EBOOT.PBP tests/Info.plist tests/PARAM.SFO tests/objc_sync/objc_sync tests/terminal/terminal_tests tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config utils/objfw-new/objfw-new utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp |
Modified .fossil-settings/ignore-glob from [1998337625] to [c6f3c5d302].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | config.log config.status configure docs extra.mk generators/library/gen_libraries generators/unicode/gen_tables src/Info.plist src/bridge/Info.plist src/libobjfw.* src/objfw-defs.h src/runtime/Info.plist src/runtime/libobjfwrt.* src/test/libobjfwtest.a src/tls/Info.plist src/tls/libobjfwtls.* tests/DerivedData tests/EBOOT.PBP tests/Info.plist tests/PARAM.SFO tests/iOS.xcodeproj/*.pbxuser tests/iOS.xcodeproj/project.xcworkspace tests/iOS.xcodeproj/xcuserdata tests/objc_sync/objc_sync | > > > > > > > > > > > > < < < < | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 67 68 69 70 71 72 | config.log config.status configure docs extra.mk generators/library/gen_libraries generators/unicode/gen_tables 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 new_tests/tests.rpx src/Info.plist src/bridge/Info.plist src/libobjfw.* src/objfw-defs.h src/runtime/Info.plist src/runtime/libobjfwrt.* src/test/libobjfwtest.a src/tls/Info.plist src/tls/libobjfwtls.* tests/DerivedData tests/EBOOT.PBP tests/Info.plist tests/PARAM.SFO tests/iOS.xcodeproj/*.pbxuser tests/iOS.xcodeproj/project.xcworkspace tests/iOS.xcodeproj/xcuserdata tests/objc_sync/objc_sync tests/terminal/terminal_tests tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config utils/objfw-new/objfw-new utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp |
Modified .gitignore from [f4069ec503] to [fdf5c85348].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | config.log config.status configure docs extra.mk generators/library/gen_libraries generators/unicode/gen_tables src/Info.plist src/bridge/Info.plist src/libobjfw.* src/objfw-defs.h src/runtime/Info.plist src/runtime/libobjfwrt.* src/test/libobjfwtest.a src/tls/Info.plist src/tls/libobjfwtls.* tests/DerivedData tests/EBOOT.PBP tests/Info.plist tests/PARAM.SFO tests/iOS.xcodeproj/*.pbxuser tests/iOS.xcodeproj/project.xcworkspace tests/iOS.xcodeproj/xcuserdata tests/objc_sync/objc_sync | > > > > > > > > > > > > < < < < | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 67 68 69 70 71 72 | config.log config.status configure docs extra.mk generators/library/gen_libraries generators/unicode/gen_tables 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 new_tests/tests.rpx src/Info.plist src/bridge/Info.plist src/libobjfw.* src/objfw-defs.h src/runtime/Info.plist src/runtime/libobjfwrt.* src/test/libobjfwtest.a src/tls/Info.plist src/tls/libobjfwtls.* tests/DerivedData tests/EBOOT.PBP tests/Info.plist tests/PARAM.SFO tests/iOS.xcodeproj/*.pbxuser tests/iOS.xcodeproj/project.xcworkspace tests/iOS.xcodeproj/xcuserdata tests/objc_sync/objc_sync tests/terminal/terminal_tests tests/tests tests/tests.3dsx tests/tests.arm9 tests/tests.nds tests/tests.nro tests/tests.rpx utils/objfw-config utils/objfw-new/objfw-new utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp |
Modified Makefile from [a04c0a2490] to [81e989ea4a].
1 2 | include extra.mk | | | | | > | 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 28 | include extra.mk SUBDIRS = src utils tests new_tests DISTCLEAN = Info.plist \ aclocal.m4 \ autom4te.cache \ buildsys.mk \ config.h \ config.log \ config.status \ extra.mk include buildsys.mk .PHONY: check docs release utils tests new_tests: src check: tests new_tests ${MAKE} -C tests -s run ${MAKE} -C new_tests -s run docs: rm -fr docs doxygen >/dev/null release: docs echo "Generating tarball for version ${PACKAGE_VERSION}..." |
︙ | ︙ |
Modified configure.ac from [fbf20e13cc] to [6a93c0743b].
︙ | ︙ | |||
437 438 439 440 441 442 443 | ]) AC_DEFINE_UNQUOTED(PLUGIN_SUFFIX, "$PLUGIN_SUFFIX", [Suffix for plugins]) AS_IF([test x"$enable_files" != x"no" -a x"$PLUGIN_SUFFIX" != x""], [ AC_SUBST(USE_SRCS_PLUGINS, '${SRCS_PLUGINS}') AC_SUBST(TESTPLUGIN, "plugin") AC_DEFINE(OF_HAVE_PLUGINS, 1, [Whether we have plugin support]) | | | 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | ]) AC_DEFINE_UNQUOTED(PLUGIN_SUFFIX, "$PLUGIN_SUFFIX", [Suffix for plugins]) AS_IF([test x"$enable_files" != x"no" -a x"$PLUGIN_SUFFIX" != x""], [ AC_SUBST(USE_SRCS_PLUGINS, '${SRCS_PLUGINS}') AC_SUBST(TESTPLUGIN, "plugin") AC_DEFINE(OF_HAVE_PLUGINS, 1, [Whether we have plugin support]) AC_CONFIG_FILES(new_tests/plugin/Info.plist) AS_IF([test x"$build_framework" = x"yes"], [ TESTPLUGIN_LIBS="-F../../src -F../../src/runtime" TESTPLUGIN_LIBS="$TESTPLUGIN_LIBS -framework ObjFW" TESTPLUGIN_LIBS="$TESTPLUGIN_LIBS \${RUNTIME_FRAMEWORK_LIBS}" ], [ TESTPLUGIN_LIBS="-L../../src -L../../src/runtime" |
︙ | ︙ | |||
1974 1975 1976 1977 1978 1979 1980 | ]) ], [ break ]) ]) ]) AS_IF([test x"$have_subprocesses" = x"yes"], [ | | | 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 | ]) ], [ break ]) ]) ]) AS_IF([test x"$have_subprocesses" = x"yes"], [ AC_SUBST(USE_SRCS_SUBPROCESSES, '${SRCS_SUBPROCESSES}') AC_SUBST(SUBPROCESS, "subprocess") AC_DEFINE(OF_HAVE_SUBPROCESSES, 1, [Whether we have subprocesses]) ]) AC_CHECK_HEADERS_ONCE([complex.h sys/ioctl.h sys/ttycom.h]) AC_CHECK_FUNCS(ioctl isatty) |
︙ | ︙ |
Modified extra.mk.in from [3687ff7a31] to [5cc5b370f7].
︙ | ︙ | |||
82 83 84 85 86 87 88 | UNICODE_M = @UNICODE_M@ USE_INCLUDES_ATOMIC = @USE_INCLUDES_ATOMIC@ USE_SRCS_APPLETALK = @USE_SRCS_APPLETALK@ USE_SRCS_FILES = @USE_SRCS_FILES@ USE_SRCS_IPX = @USE_SRCS_IPX@ USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@ USE_SRCS_SOCKETS = @USE_SRCS_SOCKETS@ | | | 82 83 84 85 86 87 88 89 90 91 92 93 94 | UNICODE_M = @UNICODE_M@ USE_INCLUDES_ATOMIC = @USE_INCLUDES_ATOMIC@ USE_SRCS_APPLETALK = @USE_SRCS_APPLETALK@ USE_SRCS_FILES = @USE_SRCS_FILES@ USE_SRCS_IPX = @USE_SRCS_IPX@ USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@ USE_SRCS_SOCKETS = @USE_SRCS_SOCKETS@ USE_SRCS_SUBPROCESSES = @USE_SRCS_SUBPROCESSES@ USE_SRCS_TAGGED_POINTERS = @USE_SRCS_TAGGED_POINTERS@ USE_SRCS_THREADS = @USE_SRCS_THREADS@ USE_SRCS_UNIX_SOCKETS = @USE_SRCS_UNIX_SOCKETS@ USE_SRCS_WINDOWS = @USE_SRCS_WINDOWS@ WRAPPER = @WRAPPER@ |
Added new_tests/ForwardingTests.m version [f769714063].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | /* * Copyright (c) 2008-2024 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" #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" #define FORMAT @"%@ %@ %@ %@ %@ %@ %@ %@ %@ %g %g %g %g %g %g %g %g %g" #define ARGS @"a", @"b", @"c", @"d", @"e", @"f", @"g", @"h", @"i", \ 1.5, 2.25, 3.125, 4.0625, 5.03125, 6.5, 7.25, 8.0, 9.0 #define RESULT @"a b c d e f g h i 1.5 2.25 3.125 4.0625 5.03125 6.5 7.25 8 9" @interface ForwardingTests: OTTestCase @end static size_t forwardingsCount = 0; static bool success = false; static id target = nil; struct StretTest { char buffer[1024]; }; @interface ForwardingTestObject: OFObject @end @interface ForwardingTestObject (NonExistentMethods) + (void)test; - (void)test; - (uint32_t)forwardingTargetTest: (intptr_t)a0 : (intptr_t)a1 : (double)a2 : (double)a3; - (OFString *)forwardingTargetVarArgTest: (OFConstantString *)format, ...; - (long double)forwardingTargetFPRetTest; - (struct StretTest)forwardingTargetStRetTest; - (void)forwardingTargetNilTest; - (void)forwardingTargetSelfTest; - (struct StretTest)forwardingTargetNilStRetTest; - (struct StretTest)forwardingTargetSelfStRetTest; @end @interface ForwardingTarget: OFObject @end static void test(id self, SEL _cmd) { success = true; } @implementation ForwardingTests - (void)setUp { [super setUp]; forwardingsCount = 0; success = false; target = nil; } - (void)testForwardingMessageAndAddingClassMethod { [ForwardingTestObject test]; OTAssertTrue(success); OTAssertEqual(forwardingsCount, 1); [ForwardingTestObject test]; OTAssertEqual(forwardingsCount, 1); } - (void)forwardingMessageAndAddingInstanceMethod { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; [testObject test]; OTAssertTrue(success); OTAssertEqual(forwardingsCount, 1); [testObject test]; OTAssertEqual(forwardingsCount, 1); } #ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR - (void)testForwardingTargetForSelector { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertEqual( [testObject forwardingTargetTest: 0xDEADBEEF : -1 : 1.25 : 2.75], 0x12345678); } - (void)testForwardingTargetForSelectorWithVariableArguments { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertEqualObjects( ([testObject forwardingTargetVarArgTest: FORMAT, ARGS]), RESULT); } /* * Don't try fpret on Win64 if we don't have stret forwarding, as long double * is handled as a struct there. */ # if !defined(OF_WINDOWS) || !defined(OF_AMD64) || \ defined(OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET) - (void)testForwardingTargetForSelectorFPRet { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertEqual([testObject forwardingTargetFPRetTest], 12345678.00006103515625); } # endif # ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET - (void)testForwardingTargetForSelectorStRet { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertEqual(memcmp([testObject forwardingTargetStRetTest].buffer, "abcdefghijklmnopqrstuvwxyz", 27), 0); } # endif - (void)testForwardingTargetForSelectorReturningNilThrows { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertThrowsSpecific([testObject forwardingTargetNilTest], OFNotImplementedException); } - (void)testForwardingTargetForSelectorReturningSelfThrows { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertThrowsSpecific([testObject forwardingTargetSelfTest], OFNotImplementedException); } # ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET - (void)testForwardingTargetForSelectorStRetReturningNilThrows { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertThrowsSpecific([testObject forwardingTargetNilStRetTest], OFNotImplementedException); } - (void)testForwardingTargetForSelectorStRetReturningSelfThrows { ForwardingTestObject *testObject = [[[ForwardingTestObject alloc] init] autorelease]; target = [[[ForwardingTarget alloc] init] autorelease]; OTAssertThrowsSpecific([testObject forwardingTargetSelfStRetTest], OFNotImplementedException); } # endif #endif @end @implementation ForwardingTestObject + (bool)resolveClassMethod: (SEL)selector { forwardingsCount++; if (sel_isEqual(selector, @selector(test))) { class_replaceMethod(object_getClass(self), @selector(test), (IMP)test, "v#:"); return YES; } return NO; } + (bool)resolveInstanceMethod: (SEL)selector { forwardingsCount++; if (sel_isEqual(selector, @selector(test))) { class_replaceMethod(self, @selector(test), (IMP)test, "v@:"); return YES; } return NO; } - (id)forwardingTargetForSelector: (SEL)selector { /* * Do some useless calculations in as many registers as possible to * check if the arguments are properly saved and restored. */ volatile register intptr_t r0 = 0, r1 = 1, r2 = 2, r3 = 3, r4 = 4, r5 = 5, r6 = 6, r7 = 7, r8 = 8, r9 = 9, r10 = 10, r11 = 11; volatile register double f0 = 0.5, f1 = 1.5, f2 = 2.5, f3 = 3.5, f4 = 4.5, f5 = 5.5, f6 = 6.5, f7 = 7.5, f8 = 8.5, f9 = 9.5, f10 = 10.5, f11 = 11.5; double add = r0 * r1 * r2 * r3 * r4 * r5 * r6 * r7 * r8 * r9 * r10 * r11 * f0 * f1 * f2 * f3 * f4 * f5 * f6 * f7 * f8 * f9 * f10 * f11; if (sel_isEqual(selector, @selector(forwardingTargetTest::::)) || sel_isEqual(selector, @selector(forwardingTargetVarArgTest:)) || sel_isEqual(selector, @selector(forwardingTargetFPRetTest)) || sel_isEqual(selector, @selector(forwardingTargetStRetTest))) return (id)((char *)target + (ptrdiff_t)add); if (sel_isEqual(selector, @selector(forwardingTargetNilTest)) || sel_isEqual(selector, @selector(forwardingTargetNilStRetTest))) return nil; if (sel_isEqual(selector, @selector(forwardingTargetSelfTest)) || sel_isEqual(selector, @selector(forwardingTargetSelfStRetTest))) return self; abort(); OF_UNREACHABLE } @end @implementation ForwardingTarget - (uint32_t)forwardingTargetTest: (intptr_t)a0 : (intptr_t)a1 : (double)a2 : (double)a3 { OFEnsure(self == target); if (a0 != (intptr_t)0xDEADBEEF) return 0; if (a1 != -1) return 0; if (a2 != 1.25) return 0; if (a3 != 2.75) return 0; return 0x12345678; } - (OFString *)forwardingTargetVarArgTest: (OFConstantString *)format, ... { va_list args; OFString *ret; OFEnsure(self == target); va_start(args, format); ret = [[[OFString alloc] initWithFormat: format arguments: args] autorelease]; va_end(args); return ret; } - (long double)forwardingTargetFPRetTest { OFEnsure(self == target); return 12345678.00006103515625; } - (struct StretTest)forwardingTargetStRetTest { struct StretTest ret = { { 0 } }; OFEnsure(self == target); memcpy(ret.buffer, "abcdefghijklmnopqrstuvwxyz", 27); return ret; } @end |
Added new_tests/Makefile version [18f60fc107].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | include ../extra.mk SUBDIRS = ${TESTPLUGIN} ${SUBPROCESS} 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 = ${OF_BLOCK_TESTS_M} \ ForwardingTests.m \ OFArrayTests.m \ OFCharacterSetTests.m \ OFColorTests.m \ OFConcreteArrayTests.m \ OFConcreteMutableArrayTests.m \ OFConcreteMutableSetTests.m \ OFConcreteSetTests.m \ OFCryptographicHashTests.m \ OFDateTests.m \ OFHMACTests.m \ OFINIFileTests.m \ OFIRITests.m \ OFInvocationTests.m \ OFJSONTests.m \ OFLocaleTests.m \ OFMatrix4x4Tests.m \ OFMethodSignatureTests.m \ OFMutableArrayTests.m \ OFMutableSetTests.m \ OFNumberTests.m \ OFObjectTests.m \ OFPBKDF2Tests.m \ OFPropertyListTests.m \ OFScryptTests.m \ OFSetTests.m \ OFSystemInfoTests.m \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ testfile_bin.m \ testfile_ini.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ OFSocketTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ ${USE_SRCS_IPX} \ ${USE_SRCS_UNIX_SOCKETS} \ ${USE_SRCS_APPLETALK} SRCS_APPLETALK = OFDDPSocketTests.m SRCS_IPX = OFIPXSocketTests.m \ OFSPXSocketTests.m \ OFSPXStreamSocketTests.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m \ OFUNIXStreamSocketTests.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} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib if test -f ../src/libobjfw.so; then \ ${LN_S} ../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ ${LN_S} ../src/libobjfw.so \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ elif test -f ../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ ${LN_S} ../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ fi if test -f ../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ ${LN_S} ../src/objfw${OBJFW_LIB_MAJOR}.dll \ objfw${OBJFW_LIB_MAJOR}.dll; \ fi if test -f ../src/libobjfw.dylib; then \ ${LN_S} ../src/libobjfw.dylib \ libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ fi if test -f ../src/runtime/libobjfwrt.so; then \ ${LN_S} ../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ ${LN_S} ../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ elif test -f ../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ ${LN_S} ../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ fi if test -f ../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ ${LN_S} ../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ fi if test -f ../src/runtime/libobjfwrt.dylib; then \ ${LN_S} ../src/runtime/libobjfwrt.dylib \ libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ fi LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ DYLD_FRAMEWORK_PATH=../src:../src/runtime$${DYLD_FRAMEWORK_PATH+:}$$DYLD_FRAMEWORK_PATH \ DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ ASAN_OPTIONS=allocator_may_return_null=1 \ ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT run-on-android: all echo "Uploading files to Android device..." if test -f ../src/libobjfw.so; then \ adb push ../src/libobjfw.so \ /data/local/tmp/objfw/libobjfw.so.${OBJFW_LIB_MAJOR}; \ fi if test -f ../src/runtime/libobjfwrt.so; then \ adb push ../src/runtime/libobjfwrt.so \ /data/local/tmp/objfw/libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ fi adb push tests /data/local/tmp/objfw/tests adb push testfile.txt /data/local/tmp/objfw/testfile.txt if test -f plugin/TestPlugin.so; then \ adb push plugin/TestPlugin.so \ /data/local/tmp/objfw/plugin/TestPlugin.so; \ fi echo "Running tests binary on Android device..." adb shell 'cd /data/local/tmp/objfw && LD_LIBRARY_PATH=. exec ${WRAPPER} ./tests' EBOOT.PBP: ${PROG_NOINST} psp-fixup-imports ${PROG_NOINST} mksfo "ObjFW Tests" PARAM.SFO psp-strip ${PROG_NOINST} pack-pbp $@ PARAM.SFO NULL NULL NULL NULL NULL ${PROG_NOINST} NULL boot.dol: ${PROG_NOINST} elf2dol ${PROG_NOINST} $@ ${PROG_NOINST}: ${LIBOBJFW_DEP} ${LIBOBJFWRT_DEP} ../src/test/libobjfwtest.a ${PROG_NOINST}.3dsx: ${PROG_NOINST} 3dsxtool $< $@ ${PROG_NOINST}.arm9: ${PROG_NOINST} arm-none-eabi-objcopy -O binary $< $@ ${PROG_NOINST}.nds: ${PROG_NOINST}.arm9 testfile.txt rm -fr nds-data mkdir -p nds-data cp testfile.txt nds-data ndstool -c $@ -9 ${PROG_NOINST} -d nds-data rm -fr nds-data ${PROG_NOINST}.nro: ${PROG_NOINST} testfile.txt rm -fr romfs mkdir -p romfs cp testfile.txt romfs nacptool --create "ObjFW tests" "Jonathan Schleifer" \ "${PACKAGE_VERSION}" tests.nacp elf2nro ${PROG_NOINST} $@ --nacp=tests.nacp --romfsdir=romfs rm -fr romfs tests.nacp ${PROG_NOINST}.rpx: ${PROG_NOINST} elf2rpl $< $@ CPPFLAGS += -I../src \ -I../src/exceptions \ -I../src/runtime \ -I../src/test \ -I.. \ -DOBJFWTEST_LOCAL_INCLUDES \ -DPROG_SUFFIX=\"${PROG_SUFFIX}\" # Repetition is required for Wii U, as otherwise it cannot find main. Just # moving -lobjfwtest later doesn't work either, as then the linker cannot find # ObjFW symbols. So the only solution is to list everything twice. LIBS := -L../src/test \ -lobjfwtest \ ${TESTS_LIBS} \ ${LIBS} \ -lobjfwtest \ ${TESTS_LIBS} \ ${LIBS} LDFLAGS += ${MAP_LDFLAGS} LD = ${OBJC} |
Added new_tests/OFArrayTests.h version [8f8b5c5038].
> > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * Copyright (c) 2008-2024 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. */ #import "ObjFW.h" #import "ObjFWTest.h" @interface OFArrayTests: OTTestCase { OFArray *_array; } @property (readonly, nonatomic) Class arrayClass; @end |
Added new_tests/OFArrayTests.m version [805893a2b1].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | /* * Copyright (c) 2008-2024 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 "OFArrayTests.h" @interface CustomArray: OFArray { OFArray *_array; } @end static OFString *const cArray[] = { @"Foo", @"Bar", @"Baz" }; @implementation OFArrayTests - (Class)arrayClass { return [CustomArray class]; } - (void)setUp { [super setUp]; _array = [[self.arrayClass alloc] initWithObjects: cArray count: sizeof(cArray) / sizeof(*cArray)]; } - (void)dealloc { [_array release]; [super dealloc]; } - (void)testArray { OFArray *array = [self.arrayClass array]; OTAssertNotNil(array); OTAssertEqual(array.count, 0); } - (void)testArrayWithObjects { OFArray *array = [self.arrayClass arrayWithObjects: @"Foo", @"Bar", @"Baz", nil]; OTAssertNotNil(array); OTAssertEqual(array.count, 3); OTAssertEqualObjects([array objectAtIndex: 0], @"Foo"); OTAssertEqualObjects([array objectAtIndex: 1], @"Bar"); OTAssertEqualObjects([array objectAtIndex: 2], @"Baz"); } - (void)testArrayWithObjectsCount { OFArray *array1 = [self.arrayClass arrayWithObjects: @"Foo", @"Bar", @"Baz", nil]; OFArray *array2 = [self.arrayClass arrayWithObjects: cArray count: 3]; OTAssertEqualObjects(array1, array2); } - (void)testDescription { OTAssertEqualObjects(_array.description, @"(\n\tFoo,\n\tBar,\n\tBaz\n)"); } - (void)testCount { OTAssertEqual(_array.count, 3); } - (void)testIsEqual { OFArray *array = [self.arrayClass arrayWithObjects: cArray count: 3]; OTAssertEqualObjects(array, _array); OTAssertNotEqual(array, _array); } - (void)testObjectAtIndex { OTAssertEqualObjects([_array objectAtIndex: 0], cArray[0]); OTAssertEqualObjects([_array objectAtIndex: 1], cArray[1]); OTAssertEqualObjects([_array objectAtIndex: 2], cArray[2]); } - (void)testObjectAtIndexFailsWhenOutOfRange { OTAssertThrowsSpecific([_array objectAtIndex: _array.count], OFOutOfRangeException); } - (void)testContainsObject { OTAssertTrue([_array containsObject: cArray[1]]); OTAssertFalse([_array containsObject: @"nonexistent"]); } - (void)testContainsObjectIdenticalTo { OTAssertTrue([_array containsObjectIdenticalTo: cArray[1]]); OTAssertFalse([_array containsObjectIdenticalTo: [OFString stringWithString: cArray[1]]]); } - (void)testIndexOfObject { OTAssertEqual([_array indexOfObject: cArray[1]], 1); OTAssertEqual([_array indexOfObject: @"nonexistent"], OFNotFound); } - (void)testIndexOfObjectIdenticalTo { OTAssertEqual([_array indexOfObjectIdenticalTo: cArray[1]], 1); OTAssertEqual([_array indexOfObjectIdenticalTo: [OFString stringWithString: cArray[1]]], OFNotFound); } - (void)objectsInRange { OTAssertEqualObjects([_array objectsInRange: OFMakeRange(1, 2)], ([self.arrayClass arrayWithObjects: cArray[1], cArray[2], nil])); } - (void)testEnumerator { OFEnumerator *enumerator = [_array objectEnumerator]; OTAssertEqualObjects([enumerator nextObject], cArray[0]); OTAssertEqualObjects([enumerator nextObject], cArray[1]); OTAssertEqualObjects([enumerator nextObject], cArray[2]); OTAssertNil([enumerator nextObject]); } - (void)testFastEnumeration { size_t i = 0; for (OFString *object in _array) { OTAssertLessThan(i, 3); OTAssertEqualObjects(object, cArray[i++]); } } - (void)testComponentsJoinedByString { OFArray *array; array = [self.arrayClass arrayWithObjects: @"", @"a", @"b", @"c", nil]; OTAssertEqualObjects([array componentsJoinedByString: @" "], @" a b c"); array = [self.arrayClass arrayWithObject: @"foo"]; OTAssertEqualObjects([array componentsJoinedByString: @" "], @"foo"); } - (void)testComponentsJoinedByStringOptions { OFArray *array; array = [self.arrayClass arrayWithObjects: @"", @"foo", @"", @"", @"bar", @"", nil]; OTAssertEqualObjects( [array componentsJoinedByString: @" " options: OFArraySkipEmptyComponents], @"foo bar"); } - (void)testSortedArray { OFArray *array = [_array arrayByAddingObjectsFromArray: [OFArray arrayWithObjects: @"0", @"z", nil]]; OTAssertEqualObjects([array sortedArray], ([OFArray arrayWithObjects: @"0", @"Bar", @"Baz", @"Foo", @"z", nil])); OTAssertEqualObjects( [array sortedArrayUsingSelector: @selector(compare:) options: OFArraySortDescending], ([OFArray arrayWithObjects: @"z", @"Foo", @"Baz", @"Bar", @"0", nil])); } - (void)testReversedArray { OTAssertEqualObjects(_array.reversedArray, ([OFArray arrayWithObjects: cArray[2], cArray[1], cArray[0], nil])); } #ifdef OF_HAVE_BLOCKS - (void)testEnumerateObjectsUsingBlock { __block size_t i = 0; [_array enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { OTAssertEqualObjects(object, [_array objectAtIndex: i++]); }]; OTAssertEqual(i, _array.count); } - (void)testMappedArrayUsingBlock { OTAssertEqualObjects( [_array mappedArrayUsingBlock: ^ id (id object, size_t idx) { switch (idx) { case 0: return @"foobar"; case 1: return @"qux"; } return @""; }].description, @"(\n\tfoobar,\n\tqux,\n\t\n)"); } - (void)testFilteredArrayUsingBlock { OTAssertEqualObjects( [_array filteredArrayUsingBlock: ^ bool (id object, size_t idx) { return [object isEqual: @"Foo"]; }].description, @"(\n\tFoo\n)"); } - (void)testFoldUsingBlock { OTAssertEqualObjects( [([self.arrayClass arrayWithObjects: [OFMutableString string], @"foo", @"bar", @"baz", nil]) foldUsingBlock: ^ id (id left, id right) { [left appendString: right]; return left; }], @"foobarbaz"); } #endif - (void)testValueForKey { OTAssertEqualObjects( [([self.arrayClass arrayWithObjects: @"foo", @"bar", @"quxqux", nil]) valueForKey: @"length"], ([self.arrayClass arrayWithObjects: [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 6], nil])); OTAssertEqualObjects( [([self.arrayClass arrayWithObjects: @"1", @"2", nil]) valueForKey: @"@count"], [OFNumber numberWithInt: 2]); } @end @implementation CustomArray - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { _array = [[OFArray alloc] initWithObjects: objects count: count]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_array release]; [super dealloc]; } - (id)objectAtIndex: (size_t)idx { return [_array objectAtIndex: idx]; } - (size_t)count { return [_array count]; } @end |
Added new_tests/OFBlockTests.m version [b2a3854f7c].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFBlockTests: OTTestCase @end #if defined(OF_OBJFW_RUNTIME) extern struct objc_class _NSConcreteStackBlock; extern struct objc_class _NSConcreteGlobalBlock; extern struct objc_class _NSConcreteMallocBlock; #elif defined(OF_APPLE_RUNTIME) extern void *_NSConcreteStackBlock; extern void *_NSConcreteGlobalBlock; extern void *_NSConcreteMallocBlock; #endif /* Clang on Win32 generates broken code that crashes for global blocks. */ #if !defined(OF_WINDOWS) || !defined(__clang__) static void (^globalBlock)(void) = ^ {}; #endif static int (^returnStackBlock(void))(void) { __block int i = 42; return [Block_copy(^ int { return ++i; }) autorelease]; } static double forwardTest(void) { __block double d; void (^block)(void) = Block_copy(^ { d = 5; }); block(); Block_release(block); return d; } @implementation OFBlockTests - (void)testClassOfStackBlock { __block int x; void (^stackBlock)(void) = ^ { x = 0; (void)x; }; OTAssertEqual((Class)&_NSConcreteStackBlock, objc_getClass("OFStackBlock")); OTAssertTrue([stackBlock isKindOfClass: [OFBlock class]]); } #if !defined(OF_WINDOWS) || !defined(__clang__) - (void)testClassOfGlobalBlock { OTAssertEqual((Class)&_NSConcreteGlobalBlock, objc_getClass("OFGlobalBlock")); OTAssertTrue([globalBlock isKindOfClass: [OFBlock class]]); } #endif - (void)testClassOfMallocBlock { OTAssertEqual((Class)&_NSConcreteMallocBlock, objc_getClass("OFMallocBlock")); } - (void)testCopyStackBlock { __block int x; void (^stackBlock)(void) = ^ { x = 0; (void)x; }; void (^mallocBlock)(void); mallocBlock = [[stackBlock copy] autorelease]; OTAssertEqual([mallocBlock class], objc_getClass("OFMallocBlock")); OTAssertTrue([mallocBlock isKindOfClass: [OFBlock class]]); } - (void)testCopyStackBlockAndReferenceVariable { OTAssertEqual(forwardTest(), 5); } - (void)testCopyStackBlockAndReferenceCopiedVariable { int (^voidBlock)(void) = returnStackBlock(); OTAssertEqual(voidBlock(), 43); OTAssertEqual(voidBlock(), 44); OTAssertEqual(voidBlock(), 45); } #if !defined(OF_WINDOWS) || !defined(__clang__) - (void)testCopyGlobalBlock { OTAssertEqual([[globalBlock copy] autorelease], (id)globalBlock); } #endif - (void)testCopyMallocBlock { __block int x; void (^stackBlock)(void) = ^ { x = 0; (void)x; }; void (^mallocBlock)(void); mallocBlock = [[stackBlock copy] autorelease]; OTAssertEqual([[mallocBlock copy] autorelease], (id)mallocBlock); OTAssertEqual([mallocBlock retainCount], 2); } @end |
Added new_tests/OFCharacterSetTests.m version [2ac90291b5].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" #import "OFCharacterSet.h" #import "OFBitSetCharacterSet.h" #import "OFRangeCharacterSet.h" @interface OFCharacterSetTests: OTTestCase @end @interface CustomCharacterSet: OFCharacterSet @end @implementation CustomCharacterSet - (bool)characterIsMember: (OFUnichar)character { return (character % 2 == 0); } @end @implementation OFCharacterSetTests - (void)testCustomCharacterSet { OFCharacterSet *characterSet = [[[CustomCharacterSet alloc] init] autorelease]; for (OFUnichar c = 0; c < 65536; c++) if (c % 2 == 0) OTAssertTrue([characterSet characterIsMember: c]); else OTAssertFalse([characterSet characterIsMember: c]); } - (void)testBitSetCharacterSet { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithCharactersInString: @"0123456789"]; OTAssertTrue( [characterSet isKindOfClass: [OFBitSetCharacterSet class]]); for (OFUnichar c = 0; c < 65536; c++) if (c >= '0' && c <= '9') OTAssertTrue([characterSet characterIsMember: c]); else if ([characterSet characterIsMember: c]) OTAssertFalse([characterSet characterIsMember: c]); } - (void)testRangeCharacterSet { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithRange: OFMakeRange('0', 10)]; OTAssertTrue( [characterSet isKindOfClass: [OFRangeCharacterSet class]]); for (OFUnichar c = 0; c < 65536; c++) if (c >= '0' && c <= '9') OTAssertTrue([characterSet characterIsMember: c]); else OTAssertFalse([characterSet characterIsMember: c]); } - (void)testInvertedCharacterSet { OFCharacterSet *characterSet = [[OFCharacterSet characterSetWithRange: OFMakeRange('0', 10)] invertedSet]; for (OFUnichar c = 0; c < 65536; c++) if (c >= '0' && c <= '9') OTAssertFalse([characterSet characterIsMember: c]); else OTAssertTrue([characterSet characterIsMember: c]); } - (void)testInvertingInvertedSetReturnsOriginal { OFCharacterSet *characterSet = [OFCharacterSet characterSetWithRange: OFMakeRange('0', 10)]; OTAssertEqual(characterSet, characterSet.invertedSet.invertedSet); } @end |
Added new_tests/OFColorTests.m version [f2116a7a9c].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFColorTests: OTTestCase { OFColor *_color; } @end @implementation OFColorTests - (void)setUp { [super setUp]; _color = [[OFColor alloc] initWithRed: 63.f / 255 green: 127.f / 255 blue: 1 alpha: 1]; } - (void)dealloc { [_color release]; [super dealloc]; } #ifdef OF_OBJFW_RUNTIME - (void)testReturnsTaggedPointer { OTAssertTrue(object_isTaggedPointer(_color)); } #endif - (void)testGetRedGreenBlueAlpha { float red, green, blue, alpha; [_color getRed: &red green: &green blue: &blue alpha: &alpha]; OTAssertEqual(red, 63.f / 255); OTAssertEqual(green, 127.f / 255); OTAssertEqual(blue, 1); OTAssertEqual(alpha, 1); } @end |
Added new_tests/OFConcreteArrayTests.m version [70542429e0].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 | /* * Copyright (c) 2008-2024 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 "OFArrayTests.h" #import "OFConcreteArray.h" @interface OFConcreteArrayTests: OFArrayTests @end @implementation OFConcreteArrayTests - (Class)arrayClass { return [OFConcreteArray class]; } @end |
Added new_tests/OFConcreteMutableArrayTests.m version [b38f014238].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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 "OFMutableArrayTests.h" #import "OFConcreteMutableArray.h" @interface OFConcreteMutableArrayTests: OFMutableArrayTests @end static OFString *const cArray[] = { @"Foo", @"Bar", @"Baz" }; @implementation OFConcreteMutableArrayTests - (Class)arrayClass { return [OFConcreteMutableArray class]; } - (void)testDetectMutationDuringEnumeration { OFEnumerator *enumerator = [_mutableArray objectEnumerator]; OFString *object; size_t i; i = 0; while ((object = [enumerator nextObject]) != nil) { OTAssertEqualObjects(object, cArray[i]); [_mutableArray replaceObjectAtIndex: i withObject: @""]; i++; } OTAssertEqual(i, _mutableArray.count); [_mutableArray removeObjectAtIndex: 0]; OTAssertThrowsSpecific([enumerator nextObject], OFEnumerationMutationException); } - (void)testDetectMutationDuringFastEnumeration { bool detected = false; size_t i; i = 0; for (OFString *object in _mutableArray) { OTAssertEqualObjects(object, cArray[i]); [_mutableArray replaceObjectAtIndex: i withObject: @""]; i++; } OTAssertEqual(i, _mutableArray.count); @try { for (OFString *object in _mutableArray) { (void)object; [_mutableArray removeObjectAtIndex: 0]; } } @catch (OFEnumerationMutationException *e) { detected = true; } OTAssertTrue(detected); } #ifdef OF_HAVE_BLOCKS - (void)testDetectMutationDuringEnumerateObjectsUsingBlock { __block size_t i; i = 0; [_mutableArray enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { OTAssertEqualObjects(object, cArray[idx]); [_mutableArray replaceObjectAtIndex: idx withObject: @""]; i++; }]; OTAssertEqual(i, _mutableArray.count); OTAssertThrowsSpecific( [_mutableArray enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { [_mutableArray removeObjectAtIndex: 0]; }], OFEnumerationMutationException); } #endif @end |
Added new_tests/OFConcreteMutableSetTests.m version [b0e6f39f4d].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 | /* * Copyright (c) 2008-2024 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 "OFMutableSetTests.h" #import "OFConcreteMutableSet.h" @interface OFConcreteMutableSetTests: OFMutableSetTests @end @implementation OFConcreteMutableSetTests - (Class)setClass { return [OFConcreteMutableSet class]; } - (void)testDetectMutationDuringEnumeration { OFEnumerator *enumerator = [_mutableSet objectEnumerator]; [_mutableSet removeObject: @"foo"]; OTAssertThrowsSpecific([enumerator nextObject], OFEnumerationMutationException); } - (void)testDetectMutationDuringFastEnumeration { bool detected = false; @try { for (OFString *object in _mutableSet) [_mutableSet removeObject: object]; } @catch (OFEnumerationMutationException *e) { detected = true; } OTAssertTrue(detected); } #ifdef OF_HAVE_BLOCKS - (void)testDetectMutationDuringEnumerateObjectsUsingBlock { OTAssertThrowsSpecific( [_mutableSet enumerateObjectsUsingBlock: ^ (id object, bool *stop) { [_mutableSet removeObject: object]; }], OFEnumerationMutationException); } #endif @end |
Added new_tests/OFConcreteSetTests.m version [8b35e67bcd].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 | /* * Copyright (c) 2008-2024 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 "OFSetTests.h" #import "OFConcreteSet.h" @interface OFConcreteSetTests: OFSetTests @end @implementation OFConcreteSetTests - (Class)setClass { return [OFConcreteSet class]; } @end |
Added new_tests/OFCryptographicHashTests.m version [9a95ece37d].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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" #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFCryptographicHashTests: OTTestCase { OFStream *_stream; } @end const unsigned char testFileMD5[16] = "\x00\x8B\x9D\x1B\x58\xDF\xF8\xFE\xEE\xF3\xAE\x8D\xBB\x68\x2D\x38"; const unsigned char testFileRIPEMD160[20] = "\x46\x02\x97\xF5\x85\xDF\xB9\x21\x00\xC8\xF9\x87\xC6\xEC\x84\x0D" "\xCE\xE6\x08\x8B"; const unsigned char testFileSHA1[20] = "\xC9\x9A\xB8\x7E\x1E\xC8\xEC\x65\xD5\xEB\xE4\x2E\x0D\xA6\x80\x96" "\xF5\x94\xE7\x17"; const unsigned char testFileSHA224[28] = "\x27\x69\xD8\x04\x2D\x0F\xCA\x84\x6C\xF1\x62\x44\xBA\x0C\xBD\x46" "\x64\x5F\x4F\x20\x02\x4D\x15\xED\x1C\x61\x1F\xF7"; const unsigned char testFileSHA256[32] = "\x1A\x02\xD6\x46\xF5\xA6\xBA\xAA\xFF\x7F\xD5\x87\xBA\xC3\xF6\xC6" "\xB5\x67\x93\x8F\x0F\x44\x90\xB8\xF5\x35\x89\xF0\x5A\x23\x7F\x69"; const unsigned char testFileSHA384[48] = "\x7E\xDE\x62\xE2\x10\xA5\x1E\x18\x8A\x11\x7F\x78\xD7\xC7\x55\xB6" "\x43\x94\x1B\xD2\x78\x5C\xCF\xF3\x8A\xB8\x98\x22\xC7\x0E\xFE\xF1" "\xEC\x53\xE9\x1A\xB3\x51\x70\x8C\x1F\x3F\x56\x12\x44\x01\x91\x54"; const unsigned char testFileSHA512[64] = "\x8F\x36\x6E\x3C\x19\x4B\xBB\xC7\x82\xAA\xCD\x7D\x55\xA2\xD3\x29" "\x29\x97\x6A\x3F\xEB\x9B\xB2\xCB\x75\xC9\xEC\xC8\x10\x07\xD6\x07" "\x31\x4A\xB1\x30\x97\x82\x58\xA5\x1F\x71\x42\xE6\x56\x07\x99\x57" "\xB2\xB8\x3B\xA1\x8A\x41\x64\x33\x69\x21\x8C\x2A\x44\x6D\xF2\xA0"; @implementation OFCryptographicHashTests - (void)setUp { OFIRI *IRI; [super setUp]; IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; _stream = [[OFIRIHandler openItemAtIRI: IRI mode: @"r"] retain]; } - (void)tearDown { [_stream close]; [super tearDown]; } - (void)dealloc { [_stream release]; [super dealloc]; } - (void)testHash: (Class)hashClass expectedDigest: (const unsigned char *)expectedDigest { id <OFCryptographicHash> hash = [hashClass hashWithAllowsSwappableMemory: true]; id <OFCryptographicHash> copy; OTAssertNotNil(hash); while (!_stream.atEndOfStream) { char buffer[64]; size_t length = [_stream readIntoBuffer: buffer length: 64]; [hash updateWithBuffer: buffer length: length]; } copy = [[hash copy] autorelease]; [hash calculate]; [copy calculate]; OTAssertEqual(memcmp(hash.digest, expectedDigest, hash.digestSize), 0); OTAssertEqual(memcmp(hash.digest, expectedDigest, hash.digestSize), 0); OTAssertThrowsSpecific([hash updateWithBuffer: "" length: 1], OFHashAlreadyCalculatedException); } - (void)testMD5 { [self testHash: [OFMD5Hash class] expectedDigest: testFileMD5]; } - (void)testRIPEMD160 { [self testHash: [OFRIPEMD160Hash class] expectedDigest: testFileRIPEMD160]; } - (void)testSHA1 { [self testHash: [OFSHA1Hash class] expectedDigest: testFileSHA1]; } - (void)testSHA224 { [self testHash: [OFSHA224Hash class] expectedDigest: testFileSHA224]; } - (void)testSHA256 { [self testHash: [OFSHA256Hash class] expectedDigest: testFileSHA256]; } - (void)testSHA384 { [self testHash: [OFSHA384Hash class] expectedDigest: testFileSHA384]; } - (void)testSHA512 { [self testHash: [OFSHA512Hash class] expectedDigest: testFileSHA512]; } @end |
Added new_tests/OFDDPSocketTests.m version [d03a653eed].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 | /* * Copyright (c) 2008-2024 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" #include <errno.h> #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFDDPSocketTests: OTTestCase @end @implementation OFDDPSocketTests - (void)testDDPSocket { OFDDPSocket *sock; OFSocketAddress address1, address2; char buffer[5]; sock = [OFDDPSocket socket]; @try { address1 = [sock bindToNetwork: 0 node: 0 port: 0 protocolType: 11]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: case EPROTONOSUPPORT: OTSkip(@"AppleTalk unsupported"); case EADDRNOTAVAIL: OTSkip(@"AppleTalk not configured"); default: @throw e; } } [sock sendBuffer: "Hello" length: 5 receiver: &address1]; OTAssertEqual([sock receiveIntoBuffer: buffer length: 5 sender: &address2], 5); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); OTAssertTrue(OFSocketAddressEqual(&address1, &address2)); OTAssertEqual(OFSocketAddressHash(&address1), OFSocketAddressHash(&address2)); } @end |
Added new_tests/OFDNSResolverTests.m version [09e6956470].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 67 68 69 70 71 72 73 74 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFDNSResolverTests: OTTestCase @end @implementation OFDNSResolverTests + (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary { OFMutableArray *summary = [OFMutableArray array]; OFDNSResolver *resolver = [OFDNSResolver resolver]; OFMutableString *staticHosts = [OFMutableString string]; #define ADD(name, value) \ [summary addObject: [OFPair pairWithFirstObject: name \ secondObject: value]]; #define ADD_DOUBLE(name, value) \ ADD(name, [OFNumber numberWithDouble: value]) #define ADD_UINT(name, value) \ ADD(name, [OFNumber numberWithUnsignedInt: value]); #define ADD_BOOL(name, value) \ ADD(name, [OFNumber numberWithBool: value]); for (OFString *host in resolver.staticHosts) { OFString *IPs; if (staticHosts.length > 0) [staticHosts appendString: @"; "]; IPs = [[resolver.staticHosts objectForKey: host] componentsJoinedByString: @", "]; [staticHosts appendFormat: @"%@=(%@)", host, IPs]; } ADD(@"Static hosts", staticHosts) ADD(@"Name servers", [resolver.nameServers componentsJoinedByString: @", "]); ADD(@"Local domain", resolver.localDomain); ADD(@"Search domains", [resolver.searchDomains componentsJoinedByString: @", "]); ADD_DOUBLE(@"Timeout", resolver.timeout); ADD_UINT(@"Max attempts", resolver.maxAttempts); ADD_UINT(@"Min number of dots in absolute name", resolver.minNumberOfDotsInAbsoluteName); ADD_BOOL(@"Forces TCP", resolver.forcesTCP); ADD_DOUBLE(@"Config reload interval", resolver.configReloadInterval); #undef ADD #undef ADD_DOUBLE #undef ADD_UINT #undef ADD_BOOL return summary; } @end |
Added new_tests/OFDateTests.m version [f4f700dfaa].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | /* * Copyright (c) 2008-2024 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" #include <time.h> #import "ObjFW.h" #import "ObjFWTest.h" #import "OFStrPTime.h" @interface OFDateTests: OTTestCase { OFDate *_date[2]; } @end @implementation OFDateTests - (void)setUp { [super setUp]; _date[0] = [[OFDate alloc] initWithTimeIntervalSince1970: 0]; _date[1] = [[OFDate alloc] initWithTimeIntervalSince1970: 3600 * 25 + 5.000002]; } - (void)dealloc { [_date[0] release]; [_date[1] release]; [super dealloc]; } - (void)testStrPTime { struct tm tm; int16_t timeZone; const char *dateString = "Wed, 09 Jun 2021 +0200x"; OTAssertEqual(OFStrPTime(dateString, "%a, %d %b %Y %z", &tm, &timeZone), dateString + 22); OTAssertEqual(tm.tm_wday, 3); OTAssertEqual(tm.tm_mday, 9); OTAssertEqual(tm.tm_mon, 5); OTAssertEqual(tm.tm_year, 2021 - 1900); OTAssertEqual(timeZone, 2 * 60); } - (void)testDateByAddingTimeInterval { OTAssertEqualObjects( [_date[0] dateByAddingTimeInterval: 3600 * 25 + 5.000002], _date[1]); } - (void)testDescription { OTAssertEqualObjects(_date[0].description, @"1970-01-01T00:00:00Z"); OTAssertEqualObjects(_date[1].description, @"1970-01-02T01:00:05Z"); } - (void)testDateWithDateStringFormat { OTAssertEqualObjects( [[OFDate dateWithDateString: @"2000-06-20T12:34:56+0200" format: @"%Y-%m-%dT%H:%M:%S%z"] description], @"2000-06-20T10:34:56Z"); } - (void)testDateWithDateStringFormatFailsWithTrailingCharacters { OTAssertThrowsSpecific( [OFDate dateWithDateString: @"2000-06-20T12:34:56+0200x" format: @"%Y-%m-%dT%H:%M:%S%z"], OFInvalidFormatException); } - (void)testDateWithLocalDateStringFormatFormat { OTAssertEqualObjects( [[OFDate dateWithLocalDateString: @"2000-06-20T12:34:56" format: @"%Y-%m-%dT%H:%M:%S"] localDateStringWithFormat: @"%Y-%m-%dT%H:%M:%S"], @"2000-06-20T12:34:56"); OTAssertEqualObjects( [[OFDate dateWithLocalDateString: @"2000-06-20T12:34:56-0200" format: @"%Y-%m-%dT%H:%M:%S%z"] description], @"2000-06-20T14:34:56Z"); } - (void)testDateWithLocalDateStringFormatFailsWithTrailingCharacters { OTAssertThrowsSpecific( [OFDate dateWithLocalDateString: @"2000-06-20T12:34:56x" format: @"%Y-%m-%dT%H:%M:%S"], OFInvalidFormatException); OTAssertThrowsSpecific( [OFDate dateWithLocalDateString: @"2000-06-20T12:34:56+0200x" format: @"%Y-%m-%dT%H:%M:%S%z"], OFInvalidFormatException); } - (void)testIsEqual { OTAssertEqualObjects(_date[0], [OFDate dateWithTimeIntervalSince1970: 0]); OTAssertNotEqualObjects(_date[0], [OFDate dateWithTimeIntervalSince1970: 0.0000001]); } - (void)testCompare { OTAssertEqual([_date[0] compare: _date[1]], OFOrderedAscending); } - (void)testSecond { OTAssertEqual(_date[0].second, 0); OTAssertEqual(_date[1].second, 5); } - (void)testMicrosecond { OTAssertEqual(_date[0].microsecond, 0); OTAssertEqual(_date[1].microsecond, 2); } - (void)testMinute { OTAssertEqual(_date[0].minute, 0); OTAssertEqual(_date[1].minute, 0); } - (void)testHour { OTAssertEqual(_date[0].hour, 0); OTAssertEqual(_date[1].hour, 1); } - (void)testDayOfMonth { OTAssertEqual(_date[0].dayOfMonth, 1); OTAssertEqual(_date[1].dayOfMonth, 2); } - (void)testMonthOfYear { OTAssertEqual(_date[0].monthOfYear, 1); OTAssertEqual(_date[1].monthOfYear, 1); } - (void)testYear { OTAssertEqual(_date[0].year, 1970); OTAssertEqual(_date[1].year, 1970); } - (void)testDayOfWeek { OTAssertEqual(_date[0].dayOfWeek, 4); OTAssertEqual(_date[1].dayOfWeek, 5); } - (void)testDayOfYear { OTAssertEqual(_date[0].dayOfYear, 1); OTAssertEqual(_date[1].dayOfYear, 2); } - (void)testEarlierDate { OTAssertEqualObjects([_date[0] earlierDate: _date[1]], _date[0]); } - (void)testLaterDate { OTAssertEqualObjects([_date[0] laterDate: _date[1]], _date[1]); } @end |
Added new_tests/OFHMACTests.m version [726dca6e51].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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" #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFHMACTests: OTTestCase { OFStream *_stream; } @end static const uint8_t key[] = "yM9h8K6IWnJRvxC/0F8XRWG7RnACDBz8wqK2tbXrYVLoKC3vPLeJikyJSM47tVHc" "DlXHww9zULAC2sJUlm2Kg1z4oz2aXY3Y1PQSB4VkC/m0DQ7hCI6cAg4TWnKdzWTy" "cvYGX+Y6HWeDY79/PGSd8fNItme6I8w4HDBqU7BP2sum3jbePJqoiSnhcyJZQTeZ" "jw0ZXoyrfHgOYD2M+NsTDaGpLblFtQ7n5CczjKtafG40PkEwx1dcrd46U9i3GyTK"; static const size_t keyLength = sizeof(key); static const uint8_t MD5Digest[] = "\xCC\x1F\xEF\x09\x29\xA3\x25\x1A\x06\xA9\x83\x99\xF9\xBC\x8F\x42"; static const uint8_t SHA1Digest[] = "\x94\xB9\x0A\x6F\xFB\xA7\x13\x6A\x75\x55" "\xD5\x7F\x5D\xB7\xF4\xCA\xEB\x4A\xDE\xBF"; static const uint8_t RIPEMD160Digest[] = "\x2C\xE1\xED\x41\xC6\xF3\x51\xA8\x04\xD2" "\xC3\x9B\x08\x33\x3B\xD5\xC9\x00\x39\x50"; static const uint8_t SHA256Digest[] = "\xFB\x8C\xDA\x88\xB3\x81\x32\x16\xD7\xD8\x62\xD4\xA6\x26\x9D\x77" "\x01\x99\x62\x65\x29\x02\x41\xE6\xEF\xA1\x02\x31\xA8\x9D\x77\x5D"; static const uint8_t SHA384Digest[] = "\x2F\x4A\x47\xAE\x13\x8E\x96\x52\xF1\x8F\x05\xFD\x65\xCD\x9A\x97" "\x93\x2F\xC9\x02\xD6\xC6\xAB\x2E\x15\x76\xC0\xA7\xA0\x05\xF4\xEF" "\x14\x52\x33\x4B\x9C\x5F\xD8\x07\x4E\x98\xAE\x97\x46\x29\x24\xB4"; static const uint8_t SHA512Digest[] = "\xF5\x8C\x3F\x9C\xA2\x2F\x0A\xF3\x26\xD8\xC0\x7E\x20\x63\x88\x61" "\xC9\xE1\x1F\xD7\xC7\xE5\x59\x33\xD5\x2F\xAF\x56\x1C\x94\xC8\xA4" "\x61\xB3\xF9\x1A\xE3\x09\x43\xA6\x5B\x85\xB1\x50\x5B\xCB\x1A\x2E" "\xB7\xE8\x87\xC1\x73\x19\x63\xF6\xA2\x91\x8D\x7E\x2E\xCC\xEC\x99"; @implementation OFHMACTests - (void)setUp { OFIRI *IRI; [super setUp]; IRI = [OFIRI IRIWithString: @"embedded:testfile.bin"]; _stream = [[OFIRIHandler openItemAtIRI: IRI mode: @"r"] retain]; } - (void)tearDown { [_stream close]; [super tearDown]; } - (void)dealloc { [_stream release]; [super dealloc]; } - (void)testWithHashClass: (Class)hashClass expectedDigest: (const unsigned char *)expectedDigest { OFHMAC *HMAC = [OFHMAC HMACWithHashClass: hashClass allowsSwappableMemory: true]; OTAssertNotNil(HMAC); OTAssertThrowsSpecific([HMAC updateWithBuffer: "" length: 0], OFInvalidArgumentException); [HMAC setKey: key length: keyLength]; while (!_stream.atEndOfStream) { char buffer[64]; size_t length = [_stream readIntoBuffer: buffer length: 64]; [HMAC updateWithBuffer: buffer length: length]; } [HMAC calculate]; OTAssertEqual(memcmp(HMAC.digest, expectedDigest, HMAC.digestSize), 0); } - (void)testHMACWithMD5 { [self testWithHashClass: [OFMD5Hash class] expectedDigest: MD5Digest]; } - (void)testHMACWithRIPEMD160 { [self testWithHashClass: [OFRIPEMD160Hash class] expectedDigest: RIPEMD160Digest]; } - (void)testHMACWithSHA1 { [self testWithHashClass: [OFSHA1Hash class] expectedDigest: SHA1Digest]; } - (void)testHMACWithSHA256 { [self testWithHashClass: [OFSHA256Hash class] expectedDigest: SHA256Digest]; } - (void)testHMACWithSHA384 { [self testWithHashClass: [OFSHA384Hash class] expectedDigest: SHA384Digest]; } - (void)testHMACWithSHA512 { [self testWithHashClass: [OFSHA512Hash class] expectedDigest: SHA512Digest]; } @end |
Added new_tests/OFINIFileTests.m version [878892df10].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | /* * Copyright (c) 2008-2024 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 "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/OFIPXSocketTests.m version [1646dd280e].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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" #include <errno.h> #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFIPXSocketTests: OTTestCase @end @implementation OFIPXSocketTests - (void)testIPXSocket { OFIPXSocket *sock = [OFIPXSocket socket]; const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; OFSocketAddress address1, address2; OFDictionary *networkInterfaces; char buffer[5]; unsigned char node1[IPX_NODE_LEN], node2[IPX_NODE_LEN]; unsigned char node[IPX_NODE_LEN]; @try { address1 = [sock bindToNetwork: 0 node: zeroNode port: 0 packetType: 0]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: OTSkip(@"IPX unsupported"); case EADDRNOTAVAIL: OTSkip(@"IPX not configured"); default: @throw e; } } /* * Find any network interface with IPX and send to it. Any should be * fine since we bound to 0.0. */ networkInterfaces = [OFSystemInfo networkInterfaces]; for (OFString *name in networkInterfaces) { OFNetworkInterface interface = [networkInterfaces objectForKey: name]; OFData *addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]; if (addresses.count == 0) continue; OFSocketAddressSetIPXNetwork(&address1, OFSocketAddressIPXNetwork([addresses itemAtIndex: 0])); OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); OFSocketAddressSetIPXNode(&address1, node); } OFSocketAddressGetIPXNode(&address1, node); if (OFSocketAddressIPXNetwork(&address1) == 0 && memcmp(node, zeroNode, 6) == 0) OTSkip(@"Could not determine own IPX address"); [sock sendBuffer: "Hello" length: 5 receiver: &address1]; OTAssertEqual([sock receiveIntoBuffer: buffer length: 5 sender: &address2], 5); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); OFSocketAddressGetIPXNode(&address1, node1); OFSocketAddressGetIPXNode(&address2, node2); OTAssertEqual(memcmp(node1, node2, IPX_NODE_LEN), 0); OTAssertEqual(OFSocketAddressIPXPort(&address1), OFSocketAddressIPXPort(&address2)); } @end |
Added new_tests/OFIRITests.m version [55f0cf3dc6].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFIRITests: OTTestCase { OFIRI *_IRI[11]; OFMutableIRI *_mutableIRI; } @end static OFString *IRI0String = @"ht+tp://us%3Aer:p%40w@ho%3Ast:1234/" @"pa%3Fth?que%23ry=1&f%26oo=b%3dar#frag%23ment"; @implementation OFIRITests - (void)setUp { [super setUp]; _IRI[0] = [[OFIRI alloc] initWithString: IRI0String]; _IRI[1] = [[OFIRI alloc] initWithString: @"http://foo:80"]; _IRI[2] = [[OFIRI alloc] initWithString: @"http://bar/"]; _IRI[3] = [[OFIRI alloc] initWithString: @"file:///etc/passwd"]; _IRI[4] = [[OFIRI alloc] initWithString: @"http://foo/bar/qux/foo%2fbar"]; _IRI[5] = [[OFIRI alloc] initWithString: @"https://[12:34::56:abcd]/"]; _IRI[6] = [[OFIRI alloc] initWithString: @"https://[12:34::56:abcd]:234/"]; _IRI[7] = [[OFIRI alloc] initWithString: @"urn:qux:foo"]; _IRI[8] = [[OFIRI alloc] initWithString: @"file:/foo?query#frag"]; _IRI[9] = [[OFIRI alloc] initWithString: @"file:foo@bar/qux?query#frag"]; _IRI[10] = [[OFIRI alloc] initWithString: @"http://ä/ö?ü"]; _mutableIRI = [[OFMutableIRI alloc] initWithScheme: @"dummy"]; } - (void)dealloc { for (uint_fast8_t i = 0; i < 11; i++) [_IRI[i] release]; [_mutableIRI release]; [super dealloc]; } - (void)testIRIWithStringFailsWithInvalidCharacters { OTAssertThrowsSpecific([OFIRI IRIWithString: @"ht,tp://foo"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"http://f`oo"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"http://foo/`"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"http://foo/foo?`"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"http://foo/foo?foo#`"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"https://[g]/"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"https://[f]:/"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"https://[f]:f/"], OFInvalidFormatException); OTAssertThrowsSpecific([OFIRI IRIWithString: @"foo:"], OFInvalidFormatException); } - (void)testIRIWithStringRelativeToIRI { OTAssertEqualObjects([[OFIRI IRIWithString: @"/foo" relativeToIRI: _IRI[0]] string], @"ht+tp://us%3Aer:p%40w@ho%3Ast:1234/foo"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"foo/bar?q" relativeToIRI: [OFIRI IRIWithString: @"http://h/qux/quux"]] string], @"http://h/qux/foo/bar?q"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"foo/bar" relativeToIRI: [OFIRI IRIWithString: @"http://h/qux/?x"]] string], @"http://h/qux/foo/bar"); OTAssertEqualObjects([[OFIRI IRIWithString: @"http://foo/?q" relativeToIRI: _IRI[0]] string], @"http://foo/?q"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"foo" relativeToIRI: [OFIRI IRIWithString: @"http://foo/bar"]] string], @"http://foo/foo"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"foo" relativeToIRI: [OFIRI IRIWithString: @"http://foo"]] string], @"http://foo/foo"); } - (void)testIRIWithStringRelativeToIRIFailsWithInvalidCharacters { OTAssertThrowsSpecific( [OFIRI IRIWithString: @"`" relativeToIRI: _IRI[0]], OFInvalidFormatException); OTAssertThrowsSpecific( [OFIRI IRIWithString: @"/`" relativeToIRI: _IRI[0]], OFInvalidFormatException); OTAssertThrowsSpecific( [OFIRI IRIWithString: @"?`" relativeToIRI: _IRI[0]], OFInvalidFormatException); OTAssertThrowsSpecific( [OFIRI IRIWithString: @"#`" relativeToIRI: _IRI[0]], OFInvalidFormatException); } #ifdef OF_HAVE_FILES - (void)testFileIRIWithPath { OTAssertEqualObjects( [[OFIRI fileIRIWithPath: @"testfile.txt"] fileSystemRepresentation], [[OFFileManager defaultManager].currentDirectoryPath stringByAppendingPathComponent: @"testfile.txt"]); } # if defined(OF_WINDOWS) || defined(OF_MSDOS) - (void)testFileIRWithPathC { OFIRI *IRI = [OFIRI fileIRIWithPath: @"c:\\"]; OTAssertEqualObjects(IRI.string, @"file:/c:/"); OTAssertEqualObjects(IRI.fileSystemRepresentation, @"c:\\"); } # endif # ifdef OF_WINDOWS - (void)testFileIRIWithPathUNC { OFIRI *IRI; IRI = [OFIRI fileIRIWithPath: @"\\\\foo\\bar" isDirectory: false]; OTAssertEqualObjects(IRI.host, @"foo"); OTAssertEqualObjects(IRI.path, @"/bar"); OTAssertEqualObjects(IRI.string, @"file://foo/bar"); OTAssertEqualObjects(IRI.fileSystemRepresentation, @"\\\\foo\\bar"); IRI = [OFIRI fileIRIWithPath: @"\\\\test" isDirectory: true]; OTAssertEqualObjects(IRI.host, @"test"); OTAssertEqualObjects(IRI.path, @"/"); OTAssertEqualObjects(IRI.string, @"file://test/"); OTAssertEqualObjects(IRI.fileSystemRepresentation, @"\\\\test"); } # endif #endif - (void)testString { OTAssertEqualObjects(_IRI[0].string, IRI0String); OTAssertEqualObjects(_IRI[1].string, @"http://foo:80"); OTAssertEqualObjects(_IRI[2].string, @"http://bar/"); OTAssertEqualObjects(_IRI[3].string, @"file:///etc/passwd"); OTAssertEqualObjects(_IRI[4].string, @"http://foo/bar/qux/foo%2fbar"); OTAssertEqualObjects(_IRI[5].string, @"https://[12:34::56:abcd]/"); OTAssertEqualObjects(_IRI[6].string, @"https://[12:34::56:abcd]:234/"); OTAssertEqualObjects(_IRI[7].string, @"urn:qux:foo"); OTAssertEqualObjects(_IRI[8].string, @"file:/foo?query#frag"); OTAssertEqualObjects(_IRI[9].string, @"file:foo@bar/qux?query#frag"); OTAssertEqualObjects(_IRI[10].string, @"http://ä/ö?ü"); } - (void)testScheme { OTAssertEqualObjects(_IRI[0].scheme, @"ht+tp"); OTAssertEqualObjects(_IRI[3].scheme, @"file"); OTAssertEqualObjects(_IRI[8].scheme, @"file"); OTAssertEqualObjects(_IRI[9].scheme, @"file"); OTAssertEqualObjects(_IRI[10].scheme, @"http"); } - (void)testUser { OTAssertEqualObjects(_IRI[0].user, @"us:er"); OTAssertNil(_IRI[3].user); OTAssertNil(_IRI[9].user); OTAssertNil(_IRI[10].user); } - (void)testPassword { OTAssertEqualObjects(_IRI[0].password, @"p@w"); OTAssertNil(_IRI[3].password); OTAssertNil(_IRI[9].password); OTAssertNil(_IRI[10].password); } - (void)testHost { OTAssertEqualObjects(_IRI[0].host, @"ho:st"); OTAssertEqualObjects(_IRI[5].host, @"12:34::56:abcd"); OTAssertEqualObjects(_IRI[6].host, @"12:34::56:abcd"); OTAssertNil(_IRI[7].host); OTAssertNil(_IRI[8].host); OTAssertNil(_IRI[9].host); OTAssertEqualObjects(_IRI[10].host, @"ä"); } - (void)testPort { OTAssertEqual(_IRI[0].port.unsignedShortValue, 1234); OTAssertNil(_IRI[3].port); OTAssertEqual(_IRI[6].port.unsignedShortValue, 234); OTAssertNil(_IRI[7].port); OTAssertNil(_IRI[8].port); OTAssertNil(_IRI[9].port); OTAssertNil(_IRI[10].port); } - (void)testPath { OTAssertEqualObjects(_IRI[0].path, @"/pa?th"); OTAssertEqualObjects(_IRI[3].path, @"/etc/passwd"); OTAssertEqualObjects(_IRI[7].path, @"qux:foo"); OTAssertEqualObjects(_IRI[8].path, @"/foo"); OTAssertEqualObjects(_IRI[9].path, @"foo@bar/qux"); OTAssertEqualObjects(_IRI[10].path, @"/ö"); } - (void)testPathComponents { OTAssertEqualObjects(_IRI[0].pathComponents, ([OFArray arrayWithObjects: @"/", @"pa?th", nil])); OTAssertEqualObjects(_IRI[3].pathComponents, ([OFArray arrayWithObjects: @"/", @"etc", @"passwd", nil])); OTAssertEqualObjects(_IRI[4].pathComponents, ([OFArray arrayWithObjects: @"/", @"bar", @"qux", @"foo/bar", nil])); } - (void)testLastPathComponent { OTAssertEqualObjects([[OFIRI IRIWithString: @"http://host/foo//bar/baz"] lastPathComponent], @"baz"); OTAssertEqualObjects( [[OFIRI IRIWithString: @"http://host/foo//bar/baz/"] lastPathComponent], @"baz"); OTAssertEqualObjects([[OFIRI IRIWithString: @"http://host/foo/"] lastPathComponent], @"foo"); OTAssertEqualObjects([[OFIRI IRIWithString: @"http://host/"] lastPathComponent], @"/"); OTAssertEqualObjects(_IRI[4].lastPathComponent, @"foo/bar"); } - (void)testQuery { OTAssertEqualObjects(_IRI[0].query, @"que#ry=1&f&oo=b=ar"); OTAssertNil(_IRI[3].query); OTAssertEqualObjects(_IRI[8].query, @"query"); OTAssertEqualObjects(_IRI[9].query, @"query"); OTAssertEqualObjects(_IRI[10].query, @"ü"); } - (void)testQueryItems { OTAssertEqualObjects(_IRI[0].queryItems, ([OFArray arrayWithObjects: [OFPair pairWithFirstObject: @"que#ry" secondObject: @"1"], [OFPair pairWithFirstObject: @"f&oo" secondObject: @"b=ar"], nil])); } - (void)testFragment { OTAssertEqualObjects(_IRI[0].fragment, @"frag#ment"); OTAssertNil(_IRI[3].fragment); OTAssertEqualObjects(_IRI[8].fragment, @"frag"); OTAssertEqualObjects(_IRI[9].fragment, @"frag"); } - (void)testCopy { OTAssertEqualObjects([[_IRI[0] copy] autorelease], _IRI[0]); } - (void)testIsEqual { OTAssertEqualObjects(_IRI[0], [OFIRI IRIWithString: IRI0String]); OTAssertNotEqualObjects(_IRI[1], _IRI[2]); OTAssertEqualObjects([OFIRI IRIWithString: @"HTTP://bar/"], _IRI[2]); } - (void)testHash { OTAssertEqual(_IRI[0].hash, [[OFIRI IRIWithString: IRI0String] hash]); OTAssertNotEqual(_IRI[1].hash, _IRI[2].hash); } - (void)testIRIWithStringFailsWithInvalidFormat { OTAssertThrowsSpecific([OFIRI IRIWithString: @"http"], OFInvalidFormatException); } - (void)testIRIByAddingPercentEncodingForUnicodeCharacters { OTAssertEqualObjects( _IRI[10].IRIByAddingPercentEncodingForUnicodeCharacters, [OFIRI IRIWithString: @"http://%C3%A4/%C3%B6?%C3%BC"]); } - (void)testSetPercentEncodedSchemeFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.scheme = @"%20", OFInvalidFormatException); } - (void)testSetHost { _mutableIRI.host = @"ho:st"; OTAssertEqualObjects(_mutableIRI.percentEncodedHost, @"ho%3Ast"); _mutableIRI.host = @"12:34:ab"; OTAssertEqualObjects(_mutableIRI.percentEncodedHost, @"[12:34:ab]"); _mutableIRI.host = @"12:34:aB"; OTAssertEqualObjects(_mutableIRI.percentEncodedHost, @"[12:34:aB]"); _mutableIRI.host = @"12:34:g"; OTAssertEqualObjects(_mutableIRI.percentEncodedHost, @"12%3A34%3Ag"); } - (void)testSetPercentEncodedHost { _mutableIRI.percentEncodedHost = @"ho%3Ast"; OTAssertEqualObjects(_mutableIRI.host, @"ho:st"); _mutableIRI.percentEncodedHost = @"[12:34]"; OTAssertEqualObjects(_mutableIRI.host, @"12:34"); _mutableIRI.percentEncodedHost = @"[12::ab]"; OTAssertEqualObjects(_mutableIRI.host, @"12::ab"); } - (void)testSetPercentEncodedHostFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedHost = @"/", OFInvalidFormatException); OTAssertThrowsSpecific(_mutableIRI.percentEncodedHost = @"[12:34", OFInvalidFormatException); OTAssertThrowsSpecific(_mutableIRI.percentEncodedHost = @"[a::g]", OFInvalidFormatException); } - (void)testSetUser { _mutableIRI.user = @"us:er"; OTAssertEqualObjects(_mutableIRI.percentEncodedUser, @"us%3Aer"); } - (void)testSetPercentEncodedUser { _mutableIRI.percentEncodedUser = @"us%3Aer"; OTAssertEqualObjects(_mutableIRI.user, @"us:er"); } - (void)testSetPercentEncodedUserFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedHost = @"/", OFInvalidFormatException); } - (void)testSetPassword { _mutableIRI.password = @"pass:word"; OTAssertEqualObjects(_mutableIRI.percentEncodedPassword, @"pass%3Aword"); } - (void)testSetPercentEncodedPassword { _mutableIRI.percentEncodedPassword = @"pass%3Aword"; OTAssertEqualObjects(_mutableIRI.password, @"pass:word"); } - (void)testSetPercentEncodedPasswordFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedPassword = @"/", OFInvalidFormatException); } - (void)testSetPath { _mutableIRI.path = @"pa/th@?"; OTAssertEqualObjects(_mutableIRI.percentEncodedPath, @"pa/th@%3F"); } - (void)testSetPercentEncodedPath { _mutableIRI.percentEncodedPath = @"pa/th@%3F"; OTAssertEqualObjects(_mutableIRI.path, @"pa/th@?"); } - (void)testSetPercentEncodedPathFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedPath = @"?", OFInvalidFormatException); } - (void)testSetQuery { _mutableIRI.query = @"que/ry?#"; OTAssertEqualObjects(_mutableIRI.percentEncodedQuery, @"que/ry?%23"); } - (void)testSetPercentEncodedQuery { _mutableIRI.percentEncodedQuery = @"que/ry?%23"; OTAssertEqualObjects(_mutableIRI.query, @"que/ry?#"); } - (void)testSetPercentEncodedQueryFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedQuery = @"`", OFInvalidFormatException); } - (void)testSetQueryItems { _mutableIRI.queryItems = [OFArray arrayWithObjects: [OFPair pairWithFirstObject: @"foo&bar" secondObject: @"baz=qux"], [OFPair pairWithFirstObject: @"f=oobar" secondObject: @"b&azqux"], nil]; OTAssertEqualObjects(_mutableIRI.percentEncodedQuery, @"foo%26bar=baz%3Dqux&f%3Doobar=b%26azqux"); } - (void)testSetFragment { _mutableIRI.fragment = @"frag/ment?#"; OTAssertEqualObjects(_mutableIRI.percentEncodedFragment, @"frag/ment?%23"); } - (void)testSetPercentEncodedFragment { _mutableIRI.percentEncodedFragment = @"frag/ment?%23"; OTAssertEqualObjects(_mutableIRI.fragment, @"frag/ment?#"); } - (void)testSetPercentEncodedFragmentFailsWithInvalidCharacters { OTAssertThrowsSpecific(_mutableIRI.percentEncodedFragment = @"`", OFInvalidFormatException); } -(void)testIRIByAppendingPathComponentIsDirectory { OTAssertEqualObjects([[OFIRI IRIWithString: @"file:///foo/bar"] IRIByAppendingPathComponent: @"qux" isDirectory: false], [OFIRI IRIWithString: @"file:///foo/bar/qux"]); OTAssertEqualObjects([[OFIRI IRIWithString: @"file:///foo/bar/"] IRIByAppendingPathComponent: @"qux" isDirectory: false], [OFIRI IRIWithString: @"file:///foo/bar/qux"]); OTAssertEqualObjects([[OFIRI IRIWithString: @"file:///foo/bar/"] IRIByAppendingPathComponent: @"qu?x" isDirectory: false], [OFIRI IRIWithString: @"file:///foo/bar/qu%3Fx"]); OTAssertEqualObjects([[OFIRI IRIWithString: @"file:///foo/bar/"] IRIByAppendingPathComponent: @"qu?x" isDirectory: true], [OFIRI IRIWithString: @"file:///foo/bar/qu%3Fx/"]); } - (void)testIRIByStandardizingPath { OTAssertEqualObjects([[OFIRI IRIWithString: @"http://foo/bar/.."] IRIByStandardizingPath], [OFIRI IRIWithString: @"http://foo/"]); OTAssertEqualObjects( [[OFIRI IRIWithString: @"http://foo/bar/%2E%2E/../qux/"] IRIByStandardizingPath], [OFIRI IRIWithString: @"http://foo/bar/qux/"]); OTAssertEqualObjects( [[OFIRI IRIWithString: @"http://foo/bar/./././qux/./"] IRIByStandardizingPath], [OFIRI IRIWithString: @"http://foo/bar/qux/"]); OTAssertEqualObjects([[OFIRI IRIWithString: @"http://foo/bar/../../qux"] IRIByStandardizingPath], [OFIRI IRIWithString: @"http://foo/../qux"]); } @end |
Added new_tests/OFInvocationTests.m version [11b71f5c4f].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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" #include <string.h> #if defined(HAVE_COMPLEX_H) && !defined(__STDC_NO_COMPLEX__) # include <complex.h> #endif #import "ObjFW.h" #import "ObjFWTest.h" @interface OFInvocationTests: OTTestCase { OFInvocation *_invocation; } @end struct TestStruct { unsigned char c; unsigned int i; }; @implementation OFInvocationTests - (struct TestStruct)invocationTestMethod1: (unsigned char)c : (unsigned int)i : (struct TestStruct *)testStructPtr : (struct TestStruct)testStruct { return testStruct; } - (void)setUp { [super setUp]; SEL selector = @selector(invocationTestMethod1::::); OFMethodSignature *signature = [self methodSignatureForSelector: selector]; _invocation = [[OFInvocation alloc] initWithMethodSignature: signature]; } - (void)dealloc { [_invocation release]; [super dealloc]; } - (void)testSetAndGetReturnValue { struct TestStruct testStruct, testStruct2; memset(&testStruct, 0xFF, sizeof(testStruct)); testStruct.c = 0x55; testStruct.i = 0xAAAAAAAA; [_invocation setReturnValue: &testStruct]; [_invocation getReturnValue: &testStruct2]; OTAssertEqual(memcmp(&testStruct, &testStruct2, sizeof(testStruct)), 0); } - (void)testSetAndGetArgumentAtIndex { struct TestStruct testStruct, testStruct2; struct TestStruct *testStructPtr = &testStruct, *testStructPtr2; unsigned const char c = 0xAA; unsigned char c2; const unsigned int i = 0x55555555; unsigned int i2; memset(&testStruct, 0xFF, sizeof(testStruct)); testStruct.c = 0x55; testStruct.i = 0xAAAAAAAA; memset(&testStruct2, 0, sizeof(testStruct2)); [_invocation setArgument: &c atIndex: 2]; [_invocation setArgument: &i atIndex: 3]; [_invocation setArgument: &testStructPtr atIndex: 4]; [_invocation setArgument: &testStruct atIndex: 5]; [_invocation getArgument: &c2 atIndex: 2]; OTAssertEqual(c, c2); [_invocation getArgument: &i2 atIndex: 3]; OTAssertEqual(i, i2); [_invocation getArgument: &testStructPtr2 atIndex: 4]; OTAssertEqual(testStructPtr, testStructPtr2); [_invocation getArgument: &testStruct2 atIndex: 5]; OTAssertEqual(memcmp(&testStruct, &testStruct2, sizeof(testStruct)), 0); } @end |
Added new_tests/OFJSONTests.m version [2e899d37b6].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFJSONTests: OTTestCase { OFDictionary *_dictionary; } @end static OFString *string = @"{\"foo\"\t:'b\\na\\r', \"x\":/*foo*/ [.5\r,0xF," @"null//bar\n,\"foo\",false]}"; @implementation OFJSONTests - (void)setUp { [super setUp]; _dictionary = [[OTOrderedDictionary alloc] initWithKeysAndObjects: @"foo", @"b\na\r", @"x", [OFArray arrayWithObjects: [OFNumber numberWithFloat: .5f], [OFNumber numberWithInt: 0xF], [OFNull null], @"foo", [OFNumber numberWithBool: false], nil], nil]; } - (void)dealloc { [_dictionary release]; [super dealloc]; } - (void)testObjectByParsingJSON { OTAssertEqualObjects(string.objectByParsingJSON, _dictionary); } - (void)testJSONRepresentation { OTAssert(_dictionary.JSONRepresentation, @"{\"foo\":\"b\\na\\r\",\"x\":[0.5,15,null,\"foo\",false]}"); } - (void)testPrettyJSONRepresentation { OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions: OFJSONRepresentationOptionPretty], @"{\n\t\"foo\": \"b\\na\\r\",\n\t\"x\": [\n\t\t0.5,\n\t\t15," @"\n\t\tnull,\n\t\t\"foo\",\n\t\tfalse\n\t]\n}"); } - (void)testJSON5Representation { OTAssertEqualObjects([_dictionary JSONRepresentationWithOptions: OFJSONRepresentationOptionJSON5], @"{foo:\"b\\\na\\r\",x:[0.5,15,null,\"foo\",false]}"); } - (void)testObjectByParsingJSONFailsWithInvalidJSON { OTAssertThrowsSpecific([@"{" objectByParsingJSON], OFInvalidJSONException); OTAssertThrowsSpecific([@"]" objectByParsingJSON], OFInvalidJSONException); OTAssertThrowsSpecific([@"bar" objectByParsingJSON], OFInvalidJSONException); OTAssertThrowsSpecific([@"[\"a\" \"b\"]" objectByParsingJSON], OFInvalidJSONException); } - (void)testObjectByParsingJSONWithDeepNesting { OTAssertEqualObjects( @"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" .objectByParsingJSON, [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFArray arrayWithObject: [OFDictionary dictionary]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]); } - (void)testObjectByParsingJSONFailsWithTooDeepNesting { OTAssertThrowsSpecific( [@"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[{}]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]" objectByParsingJSON], OFInvalidJSONException); } @end |
Added new_tests/OFLocaleTests.m version [c000e04b91].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFLocaleTests: OTTestCase @end @implementation OFLocaleTests + (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary { OFMutableArray *summary = [OFMutableArray array]; #define ADD(name, value) \ [summary addObject: [OFPair pairWithFirstObject: name \ secondObject: value]]; ADD(@"Language code", [OFLocale languageCode]) ADD(@"Country code", [OFLocale countryCode]) ADD(@"Encoding", OFStringEncodingName([OFLocale encoding])) ADD(@"Decimal separator", [OFLocale decimalSeparator]) #undef ADD return summary; } @end |
Added new_tests/OFMatrix4x4Tests.m version [25395304c9].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFMatrix4x4Tests: OTTestCase { OFMatrix4x4 *_matrix; } @end @implementation OFMatrix4x4Tests - (void)setUp { [super setUp]; _matrix = [[OFMatrix4x4 alloc] initWithValues: (const float [4][4]){ { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } }]; } - (void)dealloc { [_matrix release]; [super dealloc]; } - (void)testIdentityMatrix { OTAssertEqual(memcmp([[OFMatrix4x4 identityMatrix] values], (const float [4][4]){ { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }, 16 * sizeof(float)), 0); } - (void)testDescription { OTAssertEqualObjects(_matrix.description, @"<OFMatrix4x4: {\n" @"\t1 2 3 4\n" @"\t5 6 7 8\n" @"\t9 10 11 12\n" @"\t13 14 15 16\n" @"}>"); } - (void)testIsEqual { OTAssertEqualObjects([OFMatrix4x4 identityMatrix], ([OFMatrix4x4 matrixWithValues: (const float [4][4]){ { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }])); } - (void)testHash { OTAssertEqual([[OFMatrix4x4 identityMatrix] hash], [([OFMatrix4x4 matrixWithValues: (const float [4][4]){ { 1, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 } }]) hash]); } - (void)testCopy { OTAssertEqualObjects([[_matrix copy] autorelease], _matrix); } - (void)testMultiplyWithMatrix { OFMatrix4x4 *matrix; matrix = [[_matrix copy] autorelease]; [matrix multiplyWithMatrix: [OFMatrix4x4 identityMatrix]]; OTAssertEqualObjects(matrix, _matrix); matrix = [OFMatrix4x4 matrixWithValues: (const float [4][4]){ { 100, 200, 300, 400 }, { 500, 600, 700, 800 }, { 900, 1000, 1100, 1200 }, { 1300, 1400, 1500, 1600 } }]; [matrix multiplyWithMatrix: _matrix]; OTAssertEqualObjects(matrix, ([OFMatrix4x4 matrixWithValues: (const float [4][4]){ { 9000, 10000, 11000, 12000 }, { 20200, 22800, 25400, 28000 }, { 31400, 35600, 39800, 44000 }, { 42600, 48400, 54200, 60000 } }])); } - (void)testTranslateWithVector { OFMatrix4x4 *matrix = [OFMatrix4x4 identityMatrix]; OFVector4D point; [matrix translateWithVector: OFMakeVector3D(1, 2, 3)]; point = [matrix transformedVector: OFMakeVector4D(2, 3, 4, 1)]; OTAssertEqual(point.x, 3); OTAssertEqual(point.y, 5); OTAssertEqual(point.z, 7); OTAssertEqual(point.w, 1); } - (void)testScaleWithVector { OFMatrix4x4 *matrix = [OFMatrix4x4 identityMatrix]; OFVector4D point; [matrix translateWithVector: OFMakeVector3D(1, 2, 3)]; [matrix scaleWithVector: OFMakeVector3D(-1, 0.5f, 2)]; point = [matrix transformedVector: OFMakeVector4D(2, 3, 4, 1)]; OTAssertEqual(point.x, -3); OTAssertEqual(point.y, 2.5); OTAssertEqual(point.z, 14); OTAssertEqual(point.w, 1); } - (void)testTransformVectorsCount { OFVector4D points[2] = {{ 1, 2, 3, 1 }, { 7, 8, 9, 2 }}; [_matrix transformVectors: points count: 2]; OTAssertEqual(points[0].x, 18); OTAssertEqual(points[0].y, 46); OTAssertEqual(points[0].z, 74); OTAssertEqual(points[0].w, 102); OTAssertEqual(points[1].x, 58); OTAssertEqual(points[1].y, 162); OTAssertEqual(points[1].z, 266); OTAssertEqual(points[1].w, 370); } @end |
Added new_tests/OFMethodSignatureTests.m version [27f044c8f7].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | /* * Copyright (c) 2008-2024 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" #include <string.h> #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) # include <complex.h> #endif #import "ObjFW.h" #import "ObjFWTest.h" @interface OFMethodSignatureTests: OTTestCase @end struct Test1Struct { char c; int i; char d; }; struct Test2Struct { char c; struct { short s; int i; } st; union { char c; int i; } u; double d; }; #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) struct Test3Struct { char c; complex double cd; }; #endif union Test3Union { char c; int i; double d; }; union Test4Union { char c; struct { short x, y; } st; int i; union { float f; double d; } u; }; @implementation OFMethodSignatureTests - (void)testSignatureWithObjCTypes { OFMethodSignature *methodSignature; methodSignature = [OFMethodSignature signatureWithObjCTypes: "i28@0:8S16*20"]; OTAssertEqual(methodSignature.numberOfArguments, 4); OTAssertEqual(strcmp(methodSignature.methodReturnType, "i"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 0], "@"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 1], ":"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 2], "S"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 3], "*"), 0); OTAssertEqual(methodSignature.frameLength, 28); OTAssertEqual([methodSignature argumentOffsetAtIndex: 0], 0); OTAssertEqual([methodSignature argumentOffsetAtIndex: 1], 8); OTAssertEqual([methodSignature argumentOffsetAtIndex: 2], 16); OTAssertEqual([methodSignature argumentOffsetAtIndex: 3], 20); methodSignature = [OFMethodSignature signatureWithObjCTypes: "{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}24@0:8" "^{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}16"]; OTAssertEqual(methodSignature.numberOfArguments, 3); OTAssertEqual(strcmp(methodSignature.methodReturnType, "{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 0], "@"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 1], ":"), 0); OTAssertEqual(strcmp([methodSignature argumentTypeAtIndex: 2], "^{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}"), 0); OTAssertEqual(methodSignature.frameLength, 24); OTAssertEqual([methodSignature argumentOffsetAtIndex: 0], 0); OTAssertEqual([methodSignature argumentOffsetAtIndex: 1], 8); OTAssertEqual([methodSignature argumentOffsetAtIndex: 2], 16); } - (void)testSignatureWithObjCTypesFailsWithInvalidFormat { OTAssertThrowsSpecific( [OFMethodSignature signatureWithObjCTypes: "{ii"], OFInvalidFormatException); OTAssertThrowsSpecific([OFMethodSignature signatureWithObjCTypes: ""], OFInvalidFormatException); OTAssertThrowsSpecific([OFMethodSignature signatureWithObjCTypes: "0"], OFInvalidFormatException); OTAssertThrowsSpecific( [OFMethodSignature signatureWithObjCTypes: "{{}0"], OFInvalidFormatException); } - (void)testSizeOfTypeEncoding { OTAssertEqual(OFSizeOfTypeEncoding(@encode(struct Test1Struct)), sizeof(struct Test1Struct)); OTAssertEqual(OFSizeOfTypeEncoding(@encode(struct Test2Struct)), sizeof(struct Test2Struct)); #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) && \ OF_GCC_VERSION >= 402 OTAssertEqual(OFSizeOfTypeEncoding(@encode(struct Test3Struct)), sizeof(struct Test3Struct)); #endif OTAssertEqual(OFSizeOfTypeEncoding(@encode(union Test3Union)), sizeof(union Test3Union)); OTAssertEqual(OFSizeOfTypeEncoding(@encode(union Test4Union)), sizeof(union Test4Union)); OTAssertEqual(OFSizeOfTypeEncoding(@encode(struct Test1Struct [5])), sizeof(struct Test1Struct [5])); } - (void)testAlignmentOfTypeEncoding { OTAssertEqual(OFAlignmentOfTypeEncoding(@encode(struct Test1Struct)), OF_ALIGNOF(struct Test1Struct)); OTAssertEqual(OFAlignmentOfTypeEncoding(@encode(struct Test2Struct)), OF_ALIGNOF(struct Test2Struct)); #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) && \ OF_GCC_VERSION >= 402 OTAssertEqual(OFAlignmentOfTypeEncoding(@encode(struct Test3Struct)), OF_ALIGNOF(struct Test3Struct)); #endif OTAssertEqual(OFAlignmentOfTypeEncoding(@encode(union Test3Union)), OF_ALIGNOF(union Test3Union)); OTAssertEqual(OFAlignmentOfTypeEncoding(@encode(union Test4Union)), OF_ALIGNOF(union Test4Union)); OTAssertEqual( OFAlignmentOfTypeEncoding(@encode(struct Test1Struct [5])), OF_ALIGNOF(struct Test1Struct [5])); } @end |
Added new_tests/OFMutableArrayTests.h version [5ae96e61d9].
> > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /* * Copyright (c) 2008-2024 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. */ #import "OFArrayTests.h" @interface OFMutableArrayTests: OFArrayTests { OFMutableArray *_mutableArray; } @end |
Added new_tests/OFMutableArrayTests.m version [29c5b449b7].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | /* * Copyright (c) 2008-2024 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 "OFMutableArrayTests.h" #import "OFArray+Private.h" @interface CustomMutableArray: OFMutableArray { OFMutableArray *_array; } @end static OFString *const cArray[] = { @"Foo", @"Bar", @"Baz" }; @implementation OFMutableArrayTests - (Class)arrayClass { return [CustomMutableArray class]; } - (void)setUp { [super setUp]; _mutableArray = [[self.arrayClass alloc] initWithObjects: cArray count: sizeof(cArray) / sizeof(*cArray)]; } - (void)dealloc { [_mutableArray release]; [super dealloc]; } - (void)testAddObject { [_mutableArray addObject: cArray[0]]; [_mutableArray addObject: cArray[2]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Bar", @"Baz", @"Foo", @"Baz", nil])); } - (void)testInsertObjectAtIndex { [_mutableArray insertObject: cArray[1] atIndex: 1]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Bar", @"Bar", @"Baz", nil])); } - (void)testReplaceObjectWithObject { [_mutableArray insertObject: cArray[1] atIndex: 1]; [_mutableArray replaceObject: cArray[1] withObject: cArray[0]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Foo", @"Foo", @"Baz", nil])); } - (void)testReplaceObjectIdenticalToWithObject { [_mutableArray insertObject: [[cArray[1] mutableCopy] autorelease] atIndex: 1]; [_mutableArray replaceObjectIdenticalTo: cArray[1] withObject: cArray[0]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Bar", @"Foo", @"Baz", nil])); } - (void)testReplaceObjectAtIndexWithObject { [_mutableArray replaceObjectAtIndex: 1 withObject: cArray[0]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Foo", @"Baz", nil])); } - (void)testRemoveObject { [_mutableArray removeObject: cArray[1]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Baz", nil])); } - (void)testRemoveObjectIdenticalTo { [_mutableArray removeObjectIdenticalTo: cArray[1]]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Baz", nil])); } - (void)testRemoveObjectAtIndex { [_mutableArray removeObjectAtIndex: 1]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Foo", @"Baz", nil])); } - (void)testRemoveObjectsInRange { [_mutableArray removeObjectsInRange: OFMakeRange(1, 2)]; OTAssertEqualObjects(_mutableArray, [OFArray arrayWithObject: @"Foo"]); } - (void)testRemoveObjectsInRangeFailsWhenOutOfRange { OTAssertThrowsSpecific([_mutableArray removeObjectsInRange: OFMakeRange(0, _mutableArray.count + 1)], OFOutOfRangeException); } - (void)testReverse { [_mutableArray reverse]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"Baz", @"Bar", @"Foo", nil])); } #ifdef OF_HAVE_BLOCKS - (void)testReplaceObjectsUsingBlock { [_mutableArray replaceObjectsUsingBlock: ^ id (id object, size_t idx) { return [object lowercaseString]; }]; OTAssertEqualObjects(_mutableArray, ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil])); } #endif - (void)testSetValueForKey { OFMutableArray *array = [self.arrayClass arrayWithObjects: [OFMutableIRI IRIWithString: @"http://foo.bar/"], [OFMutableIRI IRIWithString: @"http://bar.qux/"], [OFMutableIRI IRIWithString: @"http://qux.quxqux/"], nil]; [array setValue: [OFNumber numberWithShort: 1234] forKey: @"port"]; OTAssertEqualObjects(array, ([OFArray arrayWithObjects: [OFIRI IRIWithString: @"http://foo.bar:1234/"], [OFIRI IRIWithString: @"http://bar.qux:1234/"], [OFIRI IRIWithString: @"http://qux.quxqux:1234/"], nil])); } @end @implementation CustomMutableArray - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { _array = [[OFMutableArray alloc] initWithObjects: objects count: count]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_array release]; [super dealloc]; } - (id)objectAtIndex: (size_t)idx { return [_array objectAtIndex: idx]; } - (size_t)count { return [_array count]; } - (void)insertObject: (id)object atIndex: (size_t)idx { [_array insertObject: object atIndex: idx]; } - (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object { [_array replaceObjectAtIndex: idx withObject: object]; } - (void)removeObjectAtIndex: (size_t)idx { [_array removeObjectAtIndex: idx]; } @end |
Added new_tests/OFMutableSetTests.h version [a531cff94b].
> > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | /* * Copyright (c) 2008-2024 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. */ #import "OFSetTests.h" @interface OFMutableSetTests: OFSetTests { OFMutableSet *_mutableSet; } @end |
Added new_tests/OFMutableSetTests.m version [8420adbe6c].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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 "OFMutableSetTests.h" @interface CustomMutableSet: OFMutableSet { OFMutableSet *_set; } @end @implementation OFMutableSetTests - (Class)setClass { return [CustomMutableSet class]; } - (void)setUp { [super setUp]; _mutableSet = [[OFMutableSet alloc] initWithObjects: @"foo", @"bar", @"baz", nil]; } - (void)dealloc { [_mutableSet release]; [super dealloc]; } - (void)testAddObject { [_mutableSet addObject: @"x"]; OTAssertEqualObjects(_mutableSet, ([OFSet setWithObjects: @"foo", @"bar", @"baz", @"x", nil])); } - (void)testRemoveObject { [_mutableSet removeObject: @"foo"]; OTAssertEqualObjects(_mutableSet, ([OFSet setWithObjects: @"bar", @"baz", nil])); } - (void)testMinusSet { [_mutableSet minusSet: [OFSet setWithObjects: @"foo", @"bar", nil]]; OTAssertEqualObjects(_mutableSet, ([OFSet setWithObjects: @"baz", nil])); } - (void)testIntersectSet { [_mutableSet intersectSet: [OFSet setWithObjects: @"foo", @"qux", nil]]; OTAssertEqualObjects(_mutableSet, ([OFSet setWithObjects: @"foo", nil])); } - (void)testUnionSet { [_mutableSet unionSet: [OFSet setWithObjects: @"x", @"y", nil]]; OTAssertEqualObjects(_mutableSet, ([OFSet setWithObjects: @"foo", @"bar", @"baz", @"x", @"y", nil])); } - (void)testRemoveAllObjects { [_mutableSet removeAllObjects]; OTAssertEqual(_mutableSet.count, 0); } @end @implementation CustomMutableSet - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { _set = [[OFMutableSet alloc] initWithObjects: objects count: count]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_set release]; [super dealloc]; } - (size_t)count { return _set.count; } - (bool)containsObject: (id)object { return [_set containsObject: object]; } - (OFEnumerator *)objectEnumerator { return [_set objectEnumerator]; } - (void)addObject: (id)object { [_set addObject: object]; } - (void)removeObject: (id)object { [_set removeObject: object]; } @end |
Added new_tests/OFNumberTests.m version [79e5b7d8e7].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFNumberTests: OTTestCase { OFNumber *_number; } @end @implementation OFNumberTests - (void)setUp { [super setUp]; _number = [[OFNumber alloc] initWithLongLong: 123456789]; } - (void)dealloc { [_number release]; [super dealloc]; } - (void)testIsEqual { OTAssertEqualObjects(_number, [OFNumber numberWithLong: 123456789]); } - (void)testHash { OTAssertEqual(_number.hash, [[OFNumber numberWithLong: 123456789] hash]); } - (void)testCharValue { OTAssertEqual(_number.charValue, 21); } - (void)testDoubleValue { OTAssertEqual(_number.doubleValue, 123456789.L); } - (void)testSignedCharMinAndMaxUnmodified { OTAssertEqual([[OFNumber numberWithChar: SCHAR_MIN] charValue], SCHAR_MIN); OTAssertEqual([[OFNumber numberWithChar: SCHAR_MAX] charValue], SCHAR_MAX); } - (void)testShortMinAndMaxUnmodified { OTAssertEqual([[OFNumber numberWithShort: SHRT_MIN] shortValue], SHRT_MIN); OTAssertEqual([[OFNumber numberWithShort: SHRT_MAX] shortValue], SHRT_MAX); } - (void)testIntMinAndMaxUnmodified { OTAssertEqual([[OFNumber numberWithInt: INT_MIN] intValue], INT_MIN); OTAssertEqual([[OFNumber numberWithInt: INT_MAX] intValue], INT_MAX); } - (void)testLongMinAndMaxUnmodified { OTAssertEqual([[OFNumber numberWithLong: LONG_MIN] longValue], LONG_MIN); OTAssertEqual([[OFNumber numberWithLong: LONG_MAX] longValue], LONG_MAX);; } - (void)testLongLongMinAndMaxUnmodified { OTAssertEqual([[OFNumber numberWithLongLong: LLONG_MIN] longLongValue], LLONG_MIN); OTAssertEqual([[OFNumber numberWithLongLong: LLONG_MAX] longLongValue], LLONG_MAX); } - (void)testUnsignedCharMaxUnmodified { OTAssertEqual([[OFNumber numberWithUnsignedChar: UCHAR_MAX] unsignedCharValue], UCHAR_MAX); } - (void)testUnsignedShortMaxUnmodified { OTAssertEqual([[OFNumber numberWithUnsignedShort: USHRT_MAX] unsignedShortValue], USHRT_MAX); } - (void)testUnsignedIntMaxUnmodified { OTAssertEqual([[OFNumber numberWithUnsignedInt: UINT_MAX] unsignedIntValue], UINT_MAX); } - (void)testUnsignedLongMaxUnmodified { OTAssertEqual([[OFNumber numberWithUnsignedLong: ULONG_MAX] unsignedLongValue], ULONG_MAX); } - (void)testUnsignedLongLongMaxUnmodified { OTAssertEqual([[OFNumber numberWithUnsignedLongLong: ULLONG_MAX] unsignedLongLongValue], ULLONG_MAX); } @end |
Added new_tests/OFObjectTests.m version [289bb9d695].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface MyObject: OFObject { id _objectValue; Class _classValue; bool _boolValue; char _charValue; short _shortValue; int _intValue; long _longValue; long long _longLongValue; unsigned char _unsignedCharValue; unsigned short _unsignedShortValue; unsigned int _unsignedIntValue; unsigned long _unsignedLongValue; unsigned long long _unsignedLongLongValue; float _floatValue; double _doubleValue; } @property (nonatomic, retain) id objectValue; @property (nonatomic) Class classValue; @property (nonatomic, getter=isBoolValue) bool boolValue; @property (nonatomic) char charValue; @property (nonatomic) short shortValue; @property (nonatomic) int intValue; @property (nonatomic) long longValue; @property (nonatomic) long long longLongValue; @property (nonatomic) unsigned char unsignedCharValue; @property (nonatomic) unsigned short unsignedShortValue; @property (nonatomic) unsigned int unsignedIntValue; @property (nonatomic) unsigned long unsignedLongValue; @property (nonatomic) unsigned long long unsignedLongLongValue; @property (nonatomic) float floatValue; @property (nonatomic) double doubleValue; @end @interface OFObjectTests: OTTestCase { MyObject *_myObject; } @end @implementation OFObjectTests - (void)setUp { [super setUp]; _myObject = [[MyObject alloc] init]; } - (void)dealloc { [_myObject release]; [super dealloc]; } - (void)testClassDescription { OTAssertEqualObjects([OFObject description], @"OFObject"); OTAssertEqualObjects([MyObject description], @"MyObject"); } - (void)testInstanceDescription { OFObject *object = [[[OFObject alloc] init] autorelease]; OTAssertEqualObjects(object.description, @"<OFObject>"); OTAssertEqualObjects(_myObject.description, @"<MyObject>"); } - (void)testValueForKey { _myObject.objectValue = @"Hello"; _myObject.classValue = _myObject.class; OTAssertEqualObjects([_myObject valueForKey: @"objectValue"], @"Hello"); OTAssertEqualObjects([_myObject valueForKey: @"classValue"], _myObject.class); OTAssertEqualObjects([_myObject valueForKey: @"class"], _myObject.class); } - (void)testValueForKeyWithUndefinedKeyThrows { OTAssertThrowsSpecific([_myObject valueForKey: @"undefined"], OFUndefinedKeyException); } - (void)testSetValueForKey { [_myObject setValue: @"World" forKey: @"objectValue"]; [_myObject setValue: [OFObject class] forKey: @"classValue"]; OTAssertEqualObjects(_myObject.objectValue, @"World"); OTAssertEqualObjects(_myObject.classValue, [OFObject class]); } - (void)testSetValueWithUndefinedKeyThrows { OTAssertThrowsSpecific([_myObject setValue: @"x" forKey: @"undefined"], OFUndefinedKeyException); } - (void)testAutoWrappingOfValueForKey { _myObject.boolValue = 1; _myObject.charValue = 2; _myObject.shortValue = 3; _myObject.intValue = 4; _myObject.longValue = 5; _myObject.longLongValue = 6; _myObject.unsignedCharValue = 7; _myObject.unsignedShortValue = 8; _myObject.unsignedIntValue = 9; _myObject.unsignedLongValue = 10; _myObject.unsignedLongLongValue = 11; _myObject.floatValue = 12; _myObject.doubleValue = 13; OTAssertEqualObjects([_myObject valueForKey: @"boolValue"], [OFNumber numberWithBool: 1]); OTAssertEqualObjects([_myObject valueForKey: @"charValue"], [OFNumber numberWithChar: 2]); OTAssertEqualObjects([_myObject valueForKey: @"shortValue"], [OFNumber numberWithShort: 3]); OTAssertEqualObjects([_myObject valueForKey: @"intValue"], [OFNumber numberWithInt: 4]); OTAssertEqualObjects([_myObject valueForKey: @"longValue"], [OFNumber numberWithLong: 5]); OTAssertEqualObjects([_myObject valueForKey: @"longLongValue"], [OFNumber numberWithLongLong: 6]); OTAssertEqualObjects([_myObject valueForKey: @"unsignedCharValue"], [OFNumber numberWithUnsignedChar: 7]); OTAssertEqualObjects([_myObject valueForKey: @"unsignedShortValue"], [OFNumber numberWithUnsignedShort: 8]); OTAssertEqualObjects([_myObject valueForKey: @"unsignedIntValue"], [OFNumber numberWithUnsignedInt: 9]); OTAssertEqualObjects([_myObject valueForKey: @"unsignedLongValue"], [OFNumber numberWithUnsignedLong: 10]); OTAssertEqualObjects([_myObject valueForKey: @"unsignedLongLongValue"], [OFNumber numberWithUnsignedLongLong: 11]); OTAssertEqualObjects([_myObject valueForKey: @"floatValue"], [OFNumber numberWithFloat: 12]); OTAssertEqualObjects([_myObject valueForKey: @"doubleValue"], [OFNumber numberWithDouble: 13]); } - (void)testAutoWrappingOfSetValueForKey { [_myObject setValue: [OFNumber numberWithBool: 0] forKey: @"boolValue"]; [_myObject setValue: [OFNumber numberWithChar: 10] forKey: @"charValue"]; [_myObject setValue: [OFNumber numberWithShort: 20] forKey: @"shortValue"]; [_myObject setValue: [OFNumber numberWithInt: 30] forKey: @"intValue"]; [_myObject setValue: [OFNumber numberWithLong: 40] forKey: @"longValue"]; [_myObject setValue: [OFNumber numberWithLongLong: 50] forKey: @"longLongValue"]; [_myObject setValue: [OFNumber numberWithUnsignedChar: 60] forKey: @"unsignedCharValue"]; [_myObject setValue: [OFNumber numberWithUnsignedShort: 70] forKey: @"unsignedShortValue"]; [_myObject setValue: [OFNumber numberWithUnsignedInt: 80] forKey: @"unsignedIntValue"]; [_myObject setValue: [OFNumber numberWithUnsignedLong: 90] forKey: @"unsignedLongValue"]; [_myObject setValue: [OFNumber numberWithUnsignedLongLong: 100] forKey: @"unsignedLongLongValue"]; [_myObject setValue: [OFNumber numberWithFloat: 110] forKey: @"floatValue"]; [_myObject setValue: [OFNumber numberWithDouble: 120] forKey: @"doubleValue"]; OTAssertEqual(_myObject.isBoolValue, 0); OTAssertEqual(_myObject.charValue, 10); OTAssertEqual(_myObject.shortValue, 20); OTAssertEqual(_myObject.intValue, 30); OTAssertEqual(_myObject.longValue, 40); OTAssertEqual(_myObject.longLongValue, 50); OTAssertEqual(_myObject.unsignedCharValue, 60); OTAssertEqual(_myObject.unsignedShortValue, 70); OTAssertEqual(_myObject.unsignedIntValue, 80); OTAssertEqual(_myObject.unsignedLongValue, 90); OTAssertEqual(_myObject.unsignedLongLongValue, 100); OTAssertEqual(_myObject.floatValue, 110); OTAssertEqual(_myObject.doubleValue, 120); } - (void)testSetValueForKeyWithNilThrows { OTAssertThrowsSpecific( [_myObject setValue: (id _Nonnull)nil forKey: @"intValue"], OFInvalidArgumentException); } - (void)testValueForKeyPath { _myObject.objectValue = [[[MyObject alloc] init] autorelease]; [_myObject.objectValue setObjectValue: [[[MyObject alloc] init] autorelease]]; [[_myObject.objectValue objectValue] setDoubleValue: 0.5]; OTAssertEqual([[_myObject valueForKeyPath: @"objectValue.objectValue.doubleValue"] doubleValue], 0.5); } - (void)testSetValueForKeyPath { _myObject.objectValue = [[[MyObject alloc] init] autorelease]; [_myObject.objectValue setObjectValue: [[[MyObject alloc] init] autorelease]]; [_myObject setValue: [OFNumber numberWithDouble: 0.75] forKeyPath: @"objectValue.objectValue.doubleValue"]; OTAssertEqual([[_myObject.objectValue objectValue] doubleValue], 0.75); } @end @implementation MyObject @synthesize objectValue = _objectValue, classValue = _classValue; @synthesize boolValue = _boolValue, charValue = _charValue; @synthesize shortValue = _shortValue, intValue = _intValue; @synthesize longValue = _longValue, longLongValue = _longLongValue; @synthesize unsignedCharValue = _unsignedCharValue; @synthesize unsignedShortValue = _unsignedShortValue; @synthesize unsignedIntValue = _unsignedIntValue; @synthesize unsignedLongValue = _unsignedLongValue; @synthesize unsignedLongLongValue = _unsignedLongLongValue; @synthesize floatValue = _floatValue, doubleValue = _doubleValue; - (void)dealloc { [_objectValue release]; [super dealloc]; } @end |
Added new_tests/OFPBKDF2Tests.m version [cd8293bb12].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | /* * Copyright (c) 2008-2024 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" #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFPBKDF2Tests: OTTestCase { OFHMAC *_HMAC; } @end @implementation OFPBKDF2Tests - (void)setUp { [super setUp]; _HMAC = [[OFHMAC alloc] initWithHashClass: [OFSHA1Hash class] allowsSwappableMemory: true]; } - (void)dealloc { [_HMAC release]; [super dealloc]; } /* Test vectors from RFC 6070 */ - (void)testRFC6070TestVector1 { unsigned char key[25]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 1, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\x0C\x60\xC8\x0F\x96\x1F\x0E\x71\xF3\xA9\xB5" "\x24\xAF\x60\x12\x06\x2F\xE0\x37\xA6", 20), 0); } - (void)testRFC6070TestVector2 { unsigned char key[25]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 2, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\xEA\x6C\x01\x4D\xC7\x2D\x6F\x8C\xCD\x1E\xD9" "\x2A\xCE\x1D\x41\xF0\xD8\xDE\x89\x57", 20), 0); } - (void)testRFC6070TestVector3 { unsigned char key[25]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 4096, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\x4B\x00\x79\x01\xB7\x65\x48\x9A\xBE\xAD\x49" "\xD9\x26\xF7\x21\xD0\x65\xA4\x29\xC1", 20), 0); } #if 0 /* This test takes too long, even on a fast machine. */ - (void)testRFC6070TestVector4 { unsigned char key[25]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 16777216, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\xEE\xFE\x3D\x61\xCD\x4D\xA4\xE4\xE9\x94\x5B" "\x3D\x6B\xA2\x15\x8C\x26\x34\xE9\x84", 20), 0); } #endif - (void)testRFC6070TestVector5 { unsigned char key[25]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 4096, .salt = (unsigned char *)"saltSALTsaltSALTsalt" "SALTsaltSALTsalt", .saltLength = 36, .password = "passwordPASSWORDpassword", .passwordLength = 24, .key = key, .keyLength = 25, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\x3D\x2E\xEC\x4F\xE4\x1C\x84\x9B\x80\xC8\xD8" "\x36\x62\xC0\xE4\x4A\x8B\x29\x1A\x96\x4C\xF2\xF0\x70\x38", 25), 0); } - (void)testRFC6070TestVector6 { unsigned char key[25]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = _HMAC, .iterations = 4096, .salt = (unsigned char *)"sa\0lt", .saltLength = 5, .password = "pass\0word", .passwordLength = 9, .key = key, .keyLength = 16, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(key, "\x56\xFA\x6A\xA7\x55\x48\x09\x9D\xCC\x37\xD7" "\xF0\x34\x25\xE0\xC3", 16), 0); } @end |
Added new_tests/OFPluginTests.m version [b4655165af].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" #import "plugin/TestPlugin.h" @interface OFPluginTests: OTTestCase @end @implementation OFPluginTests - (void)testPlugin { TestPlugin *test = nil; OFString *path; OFPlugin *plugin; Class (*class)(void); #ifndef OF_IOS path = [OFPlugin pathForName: @"plugin/TestPlugin"]; #else path = [OFPlugin pathForName: @"PlugIns/TestPlugin"]; #endif OTAssertNotNil(path); plugin = [OFPlugin pluginWithPath: path]; OTAssertNotNil(plugin); class = (Class (*)(void))(uintptr_t)[plugin addressForSymbol: @"class"]; OTAssert(class != NULL); @try { test = [[class() alloc] init]; OTAssertEqual([test test: 1234], 2468); } @finally { [test release]; } } @end |
Added new_tests/OFPropertyListTests.m version [2c2f0ce2a0].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFPropertyListTests: OTTestCase @end #define PLIST(x) \ @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \ @"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " \ @"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" \ @"<plist version=\"1.0\">\n" \ x @"\n" \ @"</plist>" @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( @"<string>Hello</string>") objectByParsingPropertyList], @"Hello"); OTAssertEqualObjects([PLIST( @"<array>" @" <string>Hello</string>" @" <data>V29ybGQh</data>" @" <date>2018-03-14T12:34:56Z</date>" @" <true/>" @" <false/>" @" <real>12.25</real>" @" <integer>-10</integer>" @"</array>") objectByParsingPropertyList], array); OTAssertEqualObjects([PLIST( @"<dict>" @" <key>array</key>" @" <array>" @" <string>Hello</string>" @" <data>V29ybGQh</data>" @" <date>2018-03-14T12:34:56Z</date>" @" <true/>" @" <false/>" @" <real>12.25</real>" @" <integer>-10</integer>" @" </array>" @" <key>foo</key>" @" <string>bar</string>" @"</dict>") objectByParsingPropertyList], ([OFDictionary dictionaryWithKeysAndObjects: @"array", array, @"foo", @"bar", nil])); } - (void)testDetectUnsupportedVersion { OTAssertThrowsSpecific( [[PLIST(@"<string/>") stringByReplacingOccurrencesOfString: @"1.0" withString: @"1.1"] objectByParsingPropertyList], OFUnsupportedVersionException); } - (void)testDetectInvalidFormat { OTAssertThrowsSpecific( [PLIST(@"<string x='b'/>") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"<string xmlns='foo'/>") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"<dict count='0'/>") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"<dict><key/><string/><key/></dict>") objectByParsingPropertyList], OFInvalidFormatException); OTAssertThrowsSpecific( [PLIST(@"<dict><key x='x'/><string/></dict>") objectByParsingPropertyList], OFInvalidFormatException); } @end |
Added new_tests/OFSPXSocketTests.m version [7025b286e5].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | /* * Copyright (c) 2008-2024 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" #include <errno.h> #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFSPXSocketTests: OTTestCase { OFSPXSocket *_sockServer; OFSocketAddress _addrServer; } @end @interface SPXSocketDelegate: OFObject <OFSPXSocketDelegate> { @public OFSequencedPacketSocket *_expectedServerSocket; OFSPXSocket *_expectedClientSocket; unsigned char _expectedNode[IPX_NODE_LEN]; uint32_t _expectedNetwork; uint16_t _expectedPort; bool _accepted; bool _connected; } @end @implementation OFSPXSocketTests - (void)setUp { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; _sockServer = [[OFSPXSocket alloc] init]; @try { _addrServer = [_sockServer bindToNetwork: 0 node: zeroNode port: 0]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: OTSkip(@"IPX unsupported"); case ESOCKTNOSUPPORT: OTSkip(@"SPX unsupported"); case EADDRNOTAVAIL: OTSkip(@"IPX not configured"); default: @throw e; } } } - (void)dealloc { [_sockServer release]; [super dealloc]; } - (void)testSPXSocket { OFSPXSocket *sockClient, *sockAccepted; const OFSocketAddress *addrAccepted; uint32_t network; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint16_t port; OFDictionary *networkInterfaces; char buffer[5]; sockClient = [OFSPXSocket socket]; network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); port = OFSocketAddressIPXPort(&_addrServer); [_sockServer listen]; /* * Find any network interface with IPX and send to it. Any should be * fine since we bound to 0.0. */ networkInterfaces = [OFSystemInfo networkInterfaces]; for (OFString *name in networkInterfaces) { OFNetworkInterface interface = [networkInterfaces objectForKey: name]; OFData *addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]; if (addresses.count == 0) continue; network = OFSocketAddressIPXNetwork([addresses itemAtIndex: 0]); OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); } [sockClient connectToNetwork: network node: node port: port]; sockAccepted = [_sockServer accept]; [sockAccepted sendBuffer: "Hello" length: 5]; OTAssertEqual([sockClient receiveIntoBuffer: buffer length: 5], 5); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); addrAccepted = sockAccepted.remoteAddress; OFSocketAddressGetIPXNode(addrAccepted, node2); OTAssertEqual(memcmp(node, node2, IPX_NODE_LEN), 0); } - (void)testAsyncSPXSocket { SPXSocketDelegate *delegate = [[[SPXSocketDelegate alloc] init] autorelease]; uint32_t network; unsigned char node[IPX_NODE_LEN]; uint16_t port; OFDictionary *networkInterfaces; OFSPXSocket *sockClient; delegate->_expectedServerSocket = _sockServer; _sockServer.delegate = delegate; sockClient = [OFSPXSocket socket]; delegate->_expectedClientSocket = sockClient; sockClient.delegate = delegate; [_sockServer listen]; [_sockServer asyncAccept]; network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); port = OFSocketAddressIPXPort(&_addrServer); /* * Find any network interface with IPX and send to it. Any should be * fine since we bound to 0.0. */ networkInterfaces = [OFSystemInfo networkInterfaces]; for (OFString *name in networkInterfaces) { OFNetworkInterface interface = [networkInterfaces objectForKey: name]; OFData *addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]; if (addresses.count == 0) continue; network = OFSocketAddressIPXNetwork([addresses itemAtIndex: 0]); OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); } delegate->_expectedNetwork = network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); delegate->_expectedPort = port = OFSocketAddressIPXPort(&_addrServer); @try { [sockClient asyncConnectToNetwork: network node: node port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; OTAssertTrue(delegate->_accepted); OTAssertTrue(delegate->_connected); } @catch (OFObserveKernelEventsFailedException *e) { /* * Make sure it doesn't stay in the run loop and throws again * next time we run the run loop. */ [sockClient cancelAsyncRequests]; [_sockServer cancelAsyncRequests]; switch (e.errNo) { case ENOTSOCK: OTSkip(@"select() not supported for SPX"); default: @throw e; } } } @end @implementation SPXSocketDelegate - (bool)socket: (OFSequencedPacketSocket *)sock didAcceptSocket: (OFSequencedPacketSocket *)accepted exception: (id)exception { OFEnsure(!_accepted); _accepted = (sock == _expectedServerSocket && accepted != nil && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; return false; } - (void)socket: (OFSPXSocket *)sock didConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port exception: (id)exception { OFEnsure(!_connected); _connected = (sock == _expectedClientSocket && network == _expectedNetwork && memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 && port == _expectedPort && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; } @end |
Added new_tests/OFSPXStreamSocketTests.m version [096521a07d].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | /* * Copyright (c) 2008-2024 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" #include <errno.h> #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFSPXStreamSocketTests: OTTestCase { OFSPXStreamSocket *_sockServer; OFSocketAddress _addrServer; } @end @interface SPXStreamSocketDelegate: OFObject <OFSPXStreamSocketDelegate> { @public OFStreamSocket *_expectedServerSocket; OFSPXStreamSocket *_expectedClientSocket; uint32_t _expectedNetwork; unsigned char _expectedNode[IPX_NODE_LEN]; uint16_t _expectedPort; bool _accepted; bool _connected; } @end @implementation OFSPXStreamSocketTests - (void)setUp { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; _sockServer = [[OFSPXStreamSocket alloc] init]; @try { _addrServer = [_sockServer bindToNetwork: 0 node: zeroNode port: 0]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: OTSkip(@"IPX unsupported"); case ESOCKTNOSUPPORT: case EPROTONOSUPPORT: OTSkip(@"SPX unsupported"); case EADDRNOTAVAIL: OTSkip(@"IPX not configured"); default: @throw e; } } } - (void)dealloc { [_sockServer release]; [super dealloc]; } - (void)testSPXStreamSocket { OFSPXStreamSocket *sockClient, *sockAccepted; const OFSocketAddress *addrAccepted; uint32_t network; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint16_t port; OFDictionary *networkInterfaces; char buffer[5]; sockClient = [OFSPXStreamSocket socket]; network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); port = OFSocketAddressIPXPort(&_addrServer); [_sockServer listen]; /* * Find any network interface with IPX and send to it. Any should be * fine since we bound to 0.0. */ networkInterfaces = [OFSystemInfo networkInterfaces]; for (OFString *name in networkInterfaces) { OFNetworkInterface interface = [networkInterfaces objectForKey: name]; OFData *addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]; if (addresses.count == 0) continue; network = OFSocketAddressIPXNetwork([addresses itemAtIndex: 0]); OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); } [sockClient connectToNetwork: network node: node port: port]; sockAccepted = [_sockServer accept]; [sockAccepted writeBuffer: "Hello" length: 5]; /* Test reassembly (this would not work with OFSPXSocket) */ OTAssertEqual([sockClient readIntoBuffer: buffer length: 2], 2); OTAssertEqual([sockClient readIntoBuffer: buffer + 2 length: 3], 3); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); addrAccepted = sockAccepted.remoteAddress; OFSocketAddressGetIPXNode(addrAccepted, node2); OTAssertEqual(memcmp(node, node2, IPX_NODE_LEN), 0); } - (void)testAsyncSPXStreamSocket { SPXStreamSocketDelegate *delegate = [[[SPXStreamSocketDelegate alloc] init] autorelease]; uint32_t network; unsigned char node[IPX_NODE_LEN]; uint16_t port; OFDictionary *networkInterfaces; OFSPXStreamSocket *sockClient; delegate->_expectedServerSocket = _sockServer; _sockServer.delegate = delegate; sockClient = [OFSPXStreamSocket socket]; delegate->_expectedClientSocket = sockClient; sockClient.delegate = delegate; [_sockServer listen]; [_sockServer asyncAccept]; network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); port = OFSocketAddressIPXPort(&_addrServer); /* * Find any network interface with IPX and send to it. Any should be * fine since we bound to 0.0. */ networkInterfaces = [OFSystemInfo networkInterfaces]; for (OFString *name in networkInterfaces) { OFNetworkInterface interface = [networkInterfaces objectForKey: name]; OFData *addresses = [interface objectForKey: OFNetworkInterfaceIPXAddresses]; if (addresses.count == 0) continue; network = OFSocketAddressIPXNetwork([addresses itemAtIndex: 0]); OFSocketAddressGetIPXNode([addresses itemAtIndex: 0], node); } delegate->_expectedNetwork = network = OFSocketAddressIPXNetwork(&_addrServer); OFSocketAddressGetIPXNode(&_addrServer, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); delegate->_expectedPort = port = OFSocketAddressIPXPort(&_addrServer); @try { [sockClient asyncConnectToNetwork: network node: node port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; OTAssertTrue(delegate->_accepted); OTAssertTrue(delegate->_connected); } @catch (OFObserveKernelEventsFailedException *e) { /* * Make sure it doesn't stay in the run loop and throws again * next time we run the run loop. */ [sockClient cancelAsyncRequests]; [_sockServer cancelAsyncRequests]; switch (e.errNo) { case ENOTSOCK: OTSkip(@"select() not supported for SPX"); default: @throw e; } } } @end @implementation SPXStreamSocketDelegate - (bool)socket: (OFStreamSocket *)sock didAcceptSocket: (OFStreamSocket *)accepted exception: (id)exception { OFEnsure(!_accepted); _accepted = (sock == _expectedServerSocket && accepted != nil && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; return false; } - (void)socket: (OFSPXStreamSocket *)sock didConnectToNetwork: (uint32_t)network node: (const unsigned char [IPX_NODE_LEN])node port: (uint16_t)port exception: (id)exception { OFEnsure(!_connected); _connected = (sock == _expectedClientSocket && network == _expectedNetwork && memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 && port == _expectedPort && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; } @end |
Added new_tests/OFScryptTests.m version [0924135d9a].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | /* * Copyright (c) 2008-2024 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" #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFScryptTests: OTTestCase @end /* Test vectors form RFC 7914 */ static const unsigned char salsa20Input[64] = { 0x7E, 0x87, 0x9A, 0x21, 0x4F, 0x3E, 0xC9, 0x86, 0x7C, 0xA9, 0x40, 0xE6, 0x41, 0x71, 0x8F, 0x26, 0xBA, 0xEE, 0x55, 0x5B, 0x8C, 0x61, 0xC1, 0xB5, 0x0D, 0xF8, 0x46, 0x11, 0x6D, 0xCD, 0x3B, 0x1D, 0xEE, 0x24, 0xF3, 0x19, 0xDF, 0x9B, 0x3D, 0x85, 0x14, 0x12, 0x1E, 0x4B, 0x5A, 0xC5, 0xAA, 0x32, 0x76, 0x02, 0x1D, 0x29, 0x09, 0xC7, 0x48, 0x29, 0xED, 0xEB, 0xC6, 0x8D, 0xB8, 0xB8, 0xC2, 0x5E }; static const unsigned char salsa20Output[64] = { 0xA4, 0x1F, 0x85, 0x9C, 0x66, 0x08, 0xCC, 0x99, 0x3B, 0x81, 0xCA, 0xCB, 0x02, 0x0C, 0xEF, 0x05, 0x04, 0x4B, 0x21, 0x81, 0xA2, 0xFD, 0x33, 0x7D, 0xFD, 0x7B, 0x1C, 0x63, 0x96, 0x68, 0x2F, 0x29, 0xB4, 0x39, 0x31, 0x68, 0xE3, 0xC9, 0xE6, 0xBC, 0xFE, 0x6B, 0xC5, 0xB7, 0xA0, 0x6D, 0x96, 0xBA, 0xE4, 0x24, 0xCC, 0x10, 0x2C, 0x91, 0x74, 0x5C, 0x24, 0xAD, 0x67, 0x3D, 0xC7, 0x61, 0x8F, 0x81 }; static const union { unsigned char uc[128]; uint32_t u32[32]; } blockMixInput = { .uc = { 0xF7, 0xCE, 0x0B, 0x65, 0x3D, 0x2D, 0x72, 0xA4, 0x10, 0x8C, 0xF5, 0xAB, 0xE9, 0x12, 0xFF, 0xDD, 0x77, 0x76, 0x16, 0xDB, 0xBB, 0x27, 0xA7, 0x0E, 0x82, 0x04, 0xF3, 0xAE, 0x2D, 0x0F, 0x6F, 0xAD, 0x89, 0xF6, 0x8F, 0x48, 0x11, 0xD1, 0xE8, 0x7B, 0xCC, 0x3B, 0xD7, 0x40, 0x0A, 0x9F, 0xFD, 0x29, 0x09, 0x4F, 0x01, 0x84, 0x63, 0x95, 0x74, 0xF3, 0x9A, 0xE5, 0xA1, 0x31, 0x52, 0x17, 0xBC, 0xD7, 0x89, 0x49, 0x91, 0x44, 0x72, 0x13, 0xBB, 0x22, 0x6C, 0x25, 0xB5, 0x4D, 0xA8, 0x63, 0x70, 0xFB, 0xCD, 0x98, 0x43, 0x80, 0x37, 0x46, 0x66, 0xBB, 0x8F, 0xFC, 0xB5, 0xBF, 0x40, 0xC2, 0x54, 0xB0, 0x67, 0xD2, 0x7C, 0x51, 0xCE, 0x4A, 0xD5, 0xFE, 0xD8, 0x29, 0xC9, 0x0B, 0x50, 0x5A, 0x57, 0x1B, 0x7F, 0x4D, 0x1C, 0xAD, 0x6A, 0x52, 0x3C, 0xDA, 0x77, 0x0E, 0x67, 0xBC, 0xEA, 0xAF, 0x7E, 0x89 }}; static const unsigned char blockMixOutput[128] = { 0xA4, 0x1F, 0x85, 0x9C, 0x66, 0x08, 0xCC, 0x99, 0x3B, 0x81, 0xCA, 0xCB, 0x02, 0x0C, 0xEF, 0x05, 0x04, 0x4B, 0x21, 0x81, 0xA2, 0xFD, 0x33, 0x7D, 0xFD, 0x7B, 0x1C, 0x63, 0x96, 0x68, 0x2F, 0x29, 0xB4, 0x39, 0x31, 0x68, 0xE3, 0xC9, 0xE6, 0xBC, 0xFE, 0x6B, 0xC5, 0xB7, 0xA0, 0x6D, 0x96, 0xBA, 0xE4, 0x24, 0xCC, 0x10, 0x2C, 0x91, 0x74, 0x5C, 0x24, 0xAD, 0x67, 0x3D, 0xC7, 0x61, 0x8F, 0x81, 0x20, 0xED, 0xC9, 0x75, 0x32, 0x38, 0x81, 0xA8, 0x05, 0x40, 0xF6, 0x4C, 0x16, 0x2D, 0xCD, 0x3C, 0x21, 0x07, 0x7C, 0xFE, 0x5F, 0x8D, 0x5F, 0xE2, 0xB1, 0xA4, 0x16, 0x8F, 0x95, 0x36, 0x78, 0xB7, 0x7D, 0x3B, 0x3D, 0x80, 0x3B, 0x60, 0xE4, 0xAB, 0x92, 0x09, 0x96, 0xE5, 0x9B, 0x4D, 0x53, 0xB6, 0x5D, 0x2A, 0x22, 0x58, 0x77, 0xD5, 0xED, 0xF5, 0x84, 0x2C, 0xB9, 0xF1, 0x4E, 0xEF, 0xE4, 0x25 }; static const unsigned char ROMixInput[128] = { 0xF7, 0xCE, 0x0B, 0x65, 0x3D, 0x2D, 0x72, 0xA4, 0x10, 0x8C, 0xF5, 0xAB, 0xE9, 0x12, 0xFF, 0xDD, 0x77, 0x76, 0x16, 0xDB, 0xBB, 0x27, 0xA7, 0x0E, 0x82, 0x04, 0xF3, 0xAE, 0x2D, 0x0F, 0x6F, 0xAD, 0x89, 0xF6, 0x8F, 0x48, 0x11, 0xD1, 0xE8, 0x7B, 0xCC, 0x3B, 0xD7, 0x40, 0x0A, 0x9F, 0xFD, 0x29, 0x09, 0x4F, 0x01, 0x84, 0x63, 0x95, 0x74, 0xF3, 0x9A, 0xE5, 0xA1, 0x31, 0x52, 0x17, 0xBC, 0xD7, 0x89, 0x49, 0x91, 0x44, 0x72, 0x13, 0xBB, 0x22, 0x6C, 0x25, 0xB5, 0x4D, 0xA8, 0x63, 0x70, 0xFB, 0xCD, 0x98, 0x43, 0x80, 0x37, 0x46, 0x66, 0xBB, 0x8F, 0xFC, 0xB5, 0xBF, 0x40, 0xC2, 0x54, 0xB0, 0x67, 0xD2, 0x7C, 0x51, 0xCE, 0x4A, 0xD5, 0xFE, 0xD8, 0x29, 0xC9, 0x0B, 0x50, 0x5A, 0x57, 0x1B, 0x7F, 0x4D, 0x1C, 0xAD, 0x6A, 0x52, 0x3C, 0xDA, 0x77, 0x0E, 0x67, 0xBC, 0xEA, 0xAF, 0x7E, 0x89 }; static const unsigned char ROMixOutput[128] = { 0x79, 0xCC, 0xC1, 0x93, 0x62, 0x9D, 0xEB, 0xCA, 0x04, 0x7F, 0x0B, 0x70, 0x60, 0x4B, 0xF6, 0xB6, 0x2C, 0xE3, 0xDD, 0x4A, 0x96, 0x26, 0xE3, 0x55, 0xFA, 0xFC, 0x61, 0x98, 0xE6, 0xEA, 0x2B, 0x46, 0xD5, 0x84, 0x13, 0x67, 0x3B, 0x99, 0xB0, 0x29, 0xD6, 0x65, 0xC3, 0x57, 0x60, 0x1F, 0xB4, 0x26, 0xA0, 0xB2, 0xF4, 0xBB, 0xA2, 0x00, 0xEE, 0x9F, 0x0A, 0x43, 0xD1, 0x9B, 0x57, 0x1A, 0x9C, 0x71, 0xEF, 0x11, 0x42, 0xE6, 0x5D, 0x5A, 0x26, 0x6F, 0xDD, 0xCA, 0x83, 0x2C, 0xE5, 0x9F, 0xAA, 0x7C, 0xAC, 0x0B, 0x9C, 0xF1, 0xBE, 0x2B, 0xFF, 0xCA, 0x30, 0x0D, 0x01, 0xEE, 0x38, 0x76, 0x19, 0xC4, 0xAE, 0x12, 0xFD, 0x44, 0x38, 0xF2, 0x03, 0xA0, 0xE4, 0xE1, 0xC4, 0x7E, 0xC3, 0x14, 0x86, 0x1F, 0x4E, 0x90, 0x87, 0xCB, 0x33, 0x39, 0x6A, 0x68, 0x73, 0xE8, 0xF9, 0xD2, 0x53, 0x9A, 0x4B, 0x8E }; static const unsigned char testVector1[64] = { 0x77, 0xD6, 0x57, 0x62, 0x38, 0x65, 0x7B, 0x20, 0x3B, 0x19, 0xCA, 0x42, 0xC1, 0x8A, 0x04, 0x97, 0xF1, 0x6B, 0x48, 0x44, 0xE3, 0x07, 0x4A, 0xE8, 0xDF, 0xDF, 0xFA, 0x3F, 0xED, 0xE2, 0x14, 0x42, 0xFC, 0xD0, 0x06, 0x9D, 0xED, 0x09, 0x48, 0xF8, 0x32, 0x6A, 0x75, 0x3A, 0x0F, 0xC8, 0x1F, 0x17, 0xE8, 0xD3, 0xE0, 0xFB, 0x2E, 0x0D, 0x36, 0x28, 0xCF, 0x35, 0xE2, 0x0C, 0x38, 0xD1, 0x89, 0x06 }; static const unsigned char testVector2[64] = { 0xFD, 0xBA, 0xBE, 0x1C, 0x9D, 0x34, 0x72, 0x00, 0x78, 0x56, 0xE7, 0x19, 0x0D, 0x01, 0xE9, 0xFE, 0x7C, 0x6A, 0xD7, 0xCB, 0xC8, 0x23, 0x78, 0x30, 0xE7, 0x73, 0x76, 0x63, 0x4B, 0x37, 0x31, 0x62, 0x2E, 0xAF, 0x30, 0xD9, 0x2E, 0x22, 0xA3, 0x88, 0x6F, 0xF1, 0x09, 0x27, 0x9D, 0x98, 0x30, 0xDA, 0xC7, 0x27, 0xAF, 0xB9, 0x4A, 0x83, 0xEE, 0x6D, 0x83, 0x60, 0xCB, 0xDF, 0xA2, 0xCC, 0x06, 0x40 }; /* The third test vector is too expensive for m68k. */ #ifndef OF_M68K static const unsigned char testVector3[64] = { 0x70, 0x23, 0xBD, 0xCB, 0x3A, 0xFD, 0x73, 0x48, 0x46, 0x1C, 0x06, 0xCD, 0x81, 0xFD, 0x38, 0xEB, 0xFD, 0xA8, 0xFB, 0xBA, 0x90, 0x4F, 0x8E, 0x3E, 0xA9, 0xB5, 0x43, 0xF6, 0x54, 0x5D, 0xA1, 0xF2, 0xD5, 0x43, 0x29, 0x55, 0x61, 0x3F, 0x0F, 0xCF, 0x62, 0xD4, 0x97, 0x05, 0x24, 0x2A, 0x9A, 0xF9, 0xE6, 0x1E, 0x85, 0xDC, 0x0D, 0x65, 0x1E, 0x40, 0xDF, 0xCF, 0x01, 0x7B, 0x45, 0x57, 0x58, 0x87 }; #endif /* The forth test vector is too expensive to include it in the tests. */ #if 0 static const unsigned char testVector4[64] = { 0x21, 0x01, 0xCB, 0x9B, 0x6A, 0x51, 0x1A, 0xAE, 0xAD, 0xDB, 0xBE, 0x09, 0xCF, 0x70, 0xF8, 0x81, 0xEC, 0x56, 0x8D, 0x57, 0x4A, 0x2F, 0xFD, 0x4D, 0xAB, 0xE5, 0xEE, 0x98, 0x20, 0xAD, 0xAA, 0x47, 0x8E, 0x56, 0xFD, 0x8F, 0x4B, 0xA5, 0xD0, 0x9F, 0xFA, 0x1C, 0x6D, 0x92, 0x7C, 0x40, 0xF4, 0xC3, 0x37, 0x30, 0x40, 0x49, 0xE8, 0xA9, 0x52, 0xFB, 0xCB, 0xF4, 0x5C, 0x6F, 0xA7, 0x7A, 0x41, 0xA4 }; #endif @implementation OFScryptTests - (void)testSalsa20_8Core { uint32_t salsa20Buffer[16]; memcpy(salsa20Buffer, salsa20Input, 64); OFSalsa20_8Core(salsa20Buffer); OTAssertEqual(memcmp(salsa20Buffer, salsa20Output, 64), 0); } - (void)testBlockMix { uint32_t blockMixBuffer[32]; OFScryptBlockMix(blockMixBuffer, blockMixInput.u32, 1); OTAssertEqual(memcmp(blockMixBuffer, blockMixOutput, 128), 0); } - (void)testROMix { uint32_t ROMixBuffer[32], ROMixTmp[17 * 32]; memcpy(ROMixBuffer, ROMixInput, 128); OFScryptROMix(ROMixBuffer, 1, 16, ROMixTmp); OTAssertEqual(memcmp(ROMixBuffer, ROMixOutput, 128), 0); } - (void)testRFC7941TestVector1 { unsigned char output[64]; OFScrypt((OFScryptParameters){ .blockSize = 1, .costFactor = 16, .parallelization = 1, .salt = (unsigned char *)"", .saltLength = 0, .password = "", .passwordLength = 0, .key = output, .keyLength = 64, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(output, testVector1, 64), 0); } - (void)testRFC7941TestVector2 { unsigned char output[64]; OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 1024, .parallelization = 16, .salt = (unsigned char *)"NaCl", .saltLength = 4, .password = "password", .passwordLength = 8, .key = output, .keyLength = 64, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(output, testVector2, 64), 0); } /* The third test vector is too expensive for m68k. */ #ifndef OF_M68K - (void)testRFC7941TestVector3 { unsigned char output[64]; OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 16384, .parallelization = 1, .salt = (unsigned char *)"SodiumChloride", .saltLength = 14, .password = "pleaseletmein", .passwordLength = 13, .key = output, .keyLength = 64, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(output, testVector3, 64), 0); } #endif /* The forth test vector is too expensive to include it in the tests. */ #if 0 - (void)testRFC7941TestVector4 { unsigned char output[64]; OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 1048576, .parallelization = 1, .salt = (unsigned char *)"SodiumChloride", .saltLength = 14, .password = "pleaseletmein", .passwordLength = 13, .key = output, .keyLength = 64, .allowsSwappableMemory = true }); OTAssertEqual(memcmp(output, testVector4, 64), 0); } #endif @end |
Added new_tests/OFSetTests.h version [bf9db612f3].
> > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * Copyright (c) 2008-2024 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. */ #import "ObjFW.h" #import "ObjFWTest.h" @interface OFSetTests: OTTestCase { OFSet *_set; } @property (readonly, nonatomic) Class setClass; @end |
Added new_tests/OFSetTests.m version [7ee6122d59].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | /* * Copyright (c) 2008-2024 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 "OFSetTests.h" @interface CustomSet: OFSet { OFSet *_set; } @end @implementation OFSetTests - (Class)setClass { return [CustomSet class]; } - (void)setUp { [super setUp]; _set = [[OFSet alloc] initWithObjects: @"foo", @"bar", @"baz", nil]; } - (void)dealloc { [_set release]; [super dealloc]; } - (void)testSetWithArray { OTAssertEqualObjects([self.setClass setWithArray: ([OFArray arrayWithObjects: @"foo", @"bar", @"baz", @"foo", nil])], _set); } - (void)testIsEqual { OTAssertEqualObjects(_set, ([OFSet setWithObjects: @"foo", @"bar", @"baz", nil])); } - (void)testHash { OTAssertEqual(_set.hash, [([OFSet setWithObjects: @"foo", @"bar", @"baz", nil]) hash]); } - (void)testDescription { OFString *description = _set.description; OTAssert( [description isEqual: @"{(\n\tfoo,\n\tbar,\n\tbaz\n)}"] || [description isEqual: @"{(\n\tfoo,\n\tbaz,\n\tbar\n)}"] || [description isEqual: @"{(\n\tbar,\n\tfoo,\n\tbaz\n)}"] || [description isEqual: @"{(\n\tbar,\n\tbaz,\n\tfoo\n)}"] || [description isEqual: @"{(\n\tbaz,\n\tfoo,\n\tbar\n)}"] || [description isEqual: @"{(\n\tbaz,\n\tbar,\n\tfoo\n)}"]); } - (void)testCopy { OTAssertEqualObjects([[_set copy] autorelease], _set); } - (void)testIsSubsetOfSet { OTAssertTrue([([OFSet setWithObjects: @"foo", nil]) isSubsetOfSet: _set]); OTAssertFalse([([OFSet setWithObjects: @"foo", @"Foo", nil]) isSubsetOfSet: _set]); } - (void)testIntersectsSet { OTAssertTrue([([OFSet setWithObjects: @"foo", @"Foo", nil]) intersectsSet: _set]); OTAssertFalse([([OFSet setWithObjects: @"Foo", nil]) intersectsSet: _set]); } - (void)testEnumerator { OFEnumerator *enumerator = [_set objectEnumerator]; bool seenFoo = false, seenBar = false, seenBaz = false; OFString *object; while ((object = [enumerator nextObject]) != nil) { if ([object isEqual: @"foo"]) { OTAssertFalse(seenFoo); seenFoo = true; } else if ([object isEqual: @"bar"]) { OTAssertFalse(seenBar); seenBar = true; } else if ([object isEqual: @"baz"]) { OTAssertFalse(seenBaz); seenBaz = true; } else OTAssert(false, @"Unexpected object seen: %@", object); } OTAssert(seenFoo && seenBar && seenBaz); } - (void)testFastEnumeration { bool seenFoo = false, seenBar = false, seenBaz = false; for (OFString *object in _set) { if ([object isEqual: @"foo"]) { OTAssertFalse(seenFoo); seenFoo = true; } else if ([object isEqual: @"bar"]) { OTAssertFalse(seenBar); seenBar = true; } else if ([object isEqual: @"baz"]) { OTAssertFalse(seenBaz); seenBaz = true; } else OTAssert(false, @"Unexpected object seen: %@", object); } OTAssert(seenFoo && seenBar && seenBaz); } #ifdef OF_HAVE_BLOCKS - (void)testEnumerateObjectsUsingBlock { __block bool seenFoo = false, seenBar = false, seenBaz = false; [_set enumerateObjectsUsingBlock: ^ (id object, bool *stop) { if ([object isEqual: @"foo"]) { OTAssertFalse(seenFoo); seenFoo = true; } else if ([object isEqual: @"bar"]) { OTAssertFalse(seenBar); seenBar = true; } else if ([object isEqual: @"baz"]) { OTAssertFalse(seenBaz); seenBaz = true; } else OTAssert(false, @"Unexpected object seen: %@", object); }]; OTAssert(seenFoo && seenBar && seenBaz); } - (void)testFilteredSetUsingBlock { OFSet *filteredSet = [_set filteredSetUsingBlock: ^ (id object) { return [object hasPrefix: @"ba"]; }]; OTAssertEqualObjects(filteredSet, ([OFSet setWithObjects: @"bar", @"baz", nil])); } #endif - (void)testValueForKey { OFSet *set = [[self.setClass setWithObjects: @"a", @"ab", @"abc", @"b", nil] valueForKey: @"length"]; OTAssertEqualObjects(set, ([OFSet setWithObjects: [OFNumber numberWithInt: 1], [OFNumber numberWithInt: 2], [OFNumber numberWithInt: 3], nil])); OTAssertEqualObjects([set valueForKey: @"@count"], [OFNumber numberWithInt: 3]); } @end @implementation CustomSet - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { _set = [[OFSet alloc] initWithObjects: objects count: count]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_set release]; [super dealloc]; } - (size_t)count { return _set.count; } - (bool)containsObject: (id)object { return [_set containsObject: object]; } - (OFEnumerator *)objectEnumerator { return [_set objectEnumerator]; } @end |
Added new_tests/OFSocketTests.m version [a25ea91bad].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFSocketTests: OTTestCase @end #define COMPARE_V6(a, a0, a1, a2, a3, a4, a5, a6, a7) \ (a.sockaddr.in6.sin6_addr.s6_addr[0] == (a0 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[1] == (a0 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[2] == (a1 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[3] == (a1 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[4] == (a2 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[5] == (a2 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[6] == (a3 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[7] == (a3 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[8] == (a4 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[9] == (a4 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[10] == (a5 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[11] == (a5 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[12] == (a6 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[13] == (a6 & 0xFF) && \ a.sockaddr.in6.sin6_addr.s6_addr[14] == (a7 >> 8) && \ a.sockaddr.in6.sin6_addr.s6_addr[15] == (a7 & 0xFF)) #define SET_V6(a, a0, a1, a2, a3, a4, a5, a6, a7) \ a.sockaddr.in6.sin6_addr.s6_addr[0] = a0 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[1] = a0 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[2] = a1 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[3] = a1 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[4] = a2 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[5] = a2 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[6] = a3 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[7] = a3 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[8] = a4 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[9] = a4 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[10] = a5 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[11] = a5 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[12] = a6 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[13] = a6 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[14] = a7 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[15] = a7 & 0xFF; @implementation OFSocketTests - (void)testParseIPv4 { OFSocketAddress address = OFSocketAddressParseIP(@"127.0.0.1", 1234); OTAssertEqual(OFFromBigEndian32(address.sockaddr.in.sin_addr.s_addr), 0x7F000001); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in.sin_port), 1234); } - (void)testParseRejectsInvalidIPv4 { OTAssertThrowsSpecific(OFSocketAddressParseIP(@"127.0.0.0.1", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"127.0.0.256", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"127.0.0. 1", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@" 127.0.0.1", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"127.0.a.1", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"127.0..1", 1234), OFInvalidFormatException); } - (void)testPortForIPv4 { OFSocketAddress address = OFSocketAddressParseIP(@"127.0.0.1", 1234); OTAssertEqual(OFSocketAddressIPPort(&address), 1234); } - (void)testStringForIPv4 { OFSocketAddress address = OFSocketAddressParseIP(@"127.0.0.1", 1234); OTAssertEqualObjects(OFSocketAddressString(&address), @"127.0.0.1"); } - (void)testParseIPv6 { OFSocketAddress address; address = OFSocketAddressParseIP( @"1122:3344:5566:7788:99aa:bbCc:ddee:ff00", 1234); OTAssert(COMPARE_V6(address, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"::", 1234); OTAssert(COMPARE_V6(address, 0, 0, 0, 0, 0, 0, 0, 0)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"aaAa::bBbb", 1234); OTAssert(COMPARE_V6(address, 0xAAAA, 0, 0, 0, 0, 0, 0, 0xBBBB)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"aaAa::", 1234); OTAssert(COMPARE_V6(address, 0xAAAA, 0, 0, 0, 0, 0, 0, 0)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"::aaAa", 1234); OTAssert(COMPARE_V6(address, 0, 0, 0, 0, 0, 0, 0, 0xAAAA)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"fd00::1%123", 1234); OTAssert(COMPARE_V6(address, 0xFD00, 0, 0, 0, 0, 0, 0, 1)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); OTAssertEqual(address.sockaddr.in6.sin6_scope_id, 123); address = OFSocketAddressParseIP(@"::ffff:127.0.0.1", 1234); OTAssert(COMPARE_V6(address, 0, 0, 0, 0, 0, 0xFFFF, 0x7F00, 1)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); address = OFSocketAddressParseIP(@"64:ff9b::127.0.0.1", 1234); OTAssert(COMPARE_V6(address, 0x64, 0xFF9B, 0, 0, 0, 0, 0x7F00, 1)); OTAssertEqual(OFFromBigEndian16(address.sockaddr.in6.sin6_port), 1234); } - (void)testParseRejectsInvalidIPv6 { OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1:::2", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1: ::2", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1:: :2", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1::2::3", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"10000::1", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"::10000", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"::1::", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1:2:3:4:5:6:7:", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1:2:3:4:5:6:7::", 1234), OFInvalidFormatException); OTAssertThrowsSpecific(OFSocketAddressParseIP(@"1:2", 1234), OFInvalidFormatException); } - (void)testPortForIPv6 { OFSocketAddress address = OFSocketAddressParseIP(@"::", 1234); OTAssertEqual(OFSocketAddressIPPort(&address), 1234); } - (void)testStringForIPv6 { OFSocketAddress address = OFSocketAddressParseIP(@"::", 1234); OTAssertEqualObjects(OFSocketAddressString(&address), @"::"); SET_V6(address, 0, 0, 0, 0, 0, 0, 0, 1) OTAssertEqualObjects(OFSocketAddressString(&address), @"::1"); SET_V6(address, 1, 0, 0, 0, 0, 0, 0, 0) OTAssertEqualObjects(OFSocketAddressString(&address), @"1::"); SET_V6(address, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) OTAssertEqualObjects(OFSocketAddressString(&address), @"1122:3344:5566:7788:99aa:bbcc:ddee:ff00"); SET_V6(address, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0) OTAssertEqualObjects(OFSocketAddressString(&address), @"1122:3344:5566:7788:99aa:bbcc:ddee:0"); SET_V6(address, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0, 0) OTAssertEqualObjects(OFSocketAddressString(&address), @"1122:3344:5566:7788:99aa:bbcc::"); SET_V6(address, 0, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) OTAssertEqualObjects(OFSocketAddressString(&address), @"0:3344:5566:7788:99aa:bbcc:ddee:ff00"); SET_V6(address, 0, 0, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) OTAssertEqualObjects(OFSocketAddressString(&address), @"::5566:7788:99aa:bbcc:ddee:ff00"); SET_V6(address, 0, 0, 0x5566, 0, 0, 0, 0xDDEE, 0xFF00) OTAssertEqualObjects(OFSocketAddressString(&address), @"0:0:5566::ddee:ff00"); SET_V6(address, 0, 0, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0, 0) OTAssertEqualObjects(OFSocketAddressString(&address), @"::5566:7788:99aa:bbcc:0:0"); address.sockaddr.in6.sin6_scope_id = 123; OTAssertEqualObjects(OFSocketAddressString(&address), @"::5566:7788:99aa:bbcc:0:0%123"); } - (void)testAddressEqual { OFSocketAddress addr1 = OFSocketAddressParseIP(@"127.0.0.1", 1234); OFSocketAddress addr2 = OFSocketAddressParseIP(@"127.0.0.1", 1234); OFSocketAddress addr3 = OFSocketAddressParseIP(@"127.0.0.1", 1235); OTAssertTrue(OFSocketAddressEqual(&addr1, &addr2)); OTAssertFalse(OFSocketAddressEqual(&addr1, &addr3)); } - (void)testAddressHash { OFSocketAddress addr1 = OFSocketAddressParseIP(@"127.0.0.1", 1234); OFSocketAddress addr2 = OFSocketAddressParseIP(@"127.0.0.1", 1234); OFSocketAddress addr3 = OFSocketAddressParseIP(@"127.0.0.1", 1235); OTAssertEqual(OFSocketAddressHash(&addr1), OFSocketAddressHash(&addr2)); OTAssertNotEqual(OFSocketAddressHash(&addr1), OFSocketAddressHash(&addr3)); } @end |
Added new_tests/OFSubprocessTests.m version [bf448d2b80].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFSubprocessTests: OTTestCase @end @implementation OFSubprocessTests - (void)testSubprocess { #ifdef OF_HAVE_FILES OFString *program = [@"subprocess" stringByAppendingPathComponent: @"subprocess" @PROG_SUFFIX]; #else OFString *program = @"subprocess/subprocess" @PROG_SUFFIX; #endif OFArray *arguments = [OFArray arrayWithObjects: @"tést", @"123", nil]; OFMutableDictionary *environment = [[[OFApplication environment] mutableCopy] autorelease]; OFSubprocess *subprocess; [environment setObject: @"yés" forKey: @"tëst"]; subprocess = [OFSubprocess subprocessWithProgram: program programName: program arguments: arguments environment: environment]; [subprocess writeLine: @"Hellö world!"]; OTAssertEqualObjects([subprocess readLine], @"HELLÖ WORLD!"); [subprocess closeForWriting]; OTAssertEqual([subprocess waitForTermination], 0); } @end |
Added new_tests/OFSystemInfoTests.m version [0545403f54].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFSystemInfoTests: OTTestCase @end #ifdef OF_HAVE_SOCKETS static void appendAddresses(OFMutableString *string, OFData *addresses, bool *firstAddress) { size_t count = addresses.count; for (size_t i = 0; i < count; i++) { const OFSocketAddress *address = [addresses itemAtIndex: i]; if (!*firstAddress) [string appendString: @", "]; *firstAddress = false; [string appendString: OFSocketAddressString(address)]; } } #endif @implementation OFSystemInfoTests + (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary { OFMutableArray *summary = [OFMutableArray array]; #ifdef OF_HAVE_SOCKETS OFDictionary *networkInterfaces; OFMutableString *networkInterfacesString; bool firstInterface = true; #endif #define ADD(name, value) \ [summary addObject: [OFPair pairWithFirstObject: name \ secondObject: value]]; #define ADD_UINT(name, value) \ ADD(name, [OFNumber numberWithUnsignedInt: value]); #define ADD_ULONGLONG(name, value) \ ADD(name, [OFNumber numberWithUnsignedLongLong: value]); #define ADD_BOOL(name, value) \ ADD(name, [OFNumber numberWithBool: value]); ADD(@"ObjFW version", [OFSystemInfo ObjFWVersion]) ADD_UINT(@"ObjFW version major", [OFSystemInfo ObjFWVersionMajor]) ADD_UINT(@"ObjFW version minor", [OFSystemInfo ObjFWVersionMinor]) ADD(@"Operating system name", [OFSystemInfo operatingSystemName]); ADD(@"Operating system version", [OFSystemInfo operatingSystemVersion]); ADD_ULONGLONG(@"Page size", [OFSystemInfo pageSize]); ADD_ULONGLONG(@"Number of CPUs", [OFSystemInfo numberOfCPUs]); ADD(@"User config IRI", [OFSystemInfo userConfigIRI].string); ADD(@"User data IRI", [OFSystemInfo userDataIRI].string); ADD(@"Temporary directory IRI", [OFSystemInfo temporaryDirectoryIRI].string); ADD(@"CPU vendor", [OFSystemInfo CPUVendor]); ADD(@"CPU model", [OFSystemInfo CPUModel]); #if defined(OF_AMD64) || defined(OF_X86) ADD_BOOL(@"Supports MMX", [OFSystemInfo supportsMMX]); ADD_BOOL(@"Supports 3DNow!", [OFSystemInfo supports3DNow]); ADD_BOOL(@"Supports enhanced 3DNow!", [OFSystemInfo supportsEnhanced3DNow]); ADD_BOOL(@"Supports SSE", [OFSystemInfo supportsSSE]); ADD_BOOL(@"Supports SSE2", [OFSystemInfo supportsSSE2]); ADD_BOOL(@"Supports SSE3", [OFSystemInfo supportsSSE3]); ADD_BOOL(@"Supports SSSE3", [OFSystemInfo supportsSSSE3]); ADD_BOOL(@"Supports SSE4.1", [OFSystemInfo supportsSSE41]); ADD_BOOL(@"Supports SSE4.2", [OFSystemInfo supportsSSE42]); ADD_BOOL(@"Supports AVX", [OFSystemInfo supportsAVX]); ADD_BOOL(@"Supports AVX2", [OFSystemInfo supportsAVX2]); ADD_BOOL(@"Supports AES-NI", [OFSystemInfo supportsAESNI]); ADD_BOOL(@"Supports SHA extensions", [OFSystemInfo supportsSHAExtensions]); ADD_BOOL(@"Supports fused multiply-add", [OFSystemInfo supportsFusedMultiplyAdd]); ADD_BOOL(@"Supports F16C", [OFSystemInfo supportsF16C]); ADD_BOOL(@"Supports AVX-512 Foundation", [OFSystemInfo supportsAVX512Foundation]); ADD_BOOL(@"Supports AVX-512 Conflict Detection Instructions", [OFSystemInfo supportsAVX512ConflictDetectionInstructions]); ADD_BOOL(@"Supports AVX-512 Exponential and Reciprocal Instructions", [OFSystemInfo supportsAVX512ExponentialAndReciprocalInstructions]); ADD_BOOL(@"Supports AVX-512 Prefetch Instructions", [OFSystemInfo supportsAVX512PrefetchInstructions]); ADD_BOOL(@"Supports AVX-512 Vector Length Extensions", [OFSystemInfo supportsAVX512VectorLengthExtensions]); ADD_BOOL(@"Supports AVX-512 Doubleword and Quadword Instructions", [OFSystemInfo supportsAVX512DoublewordAndQuadwordInstructions]); ADD_BOOL(@"Supports AVX-512 Byte and Word Instructions", [OFSystemInfo supportsAVX512ByteAndWordInstructions]); ADD_BOOL(@"Supports AVX-512 Integer Fused Multiply Add", [OFSystemInfo supportsAVX512IntegerFusedMultiplyAdd]); ADD_BOOL(@"Supports AVX-512 Vector Byte Manipulation Instructions", [OFSystemInfo supportsAVX512VectorByteManipulationInstructions]); ADD_BOOL(@"Supports AVX-512 Vector Population Count Instruction", [OFSystemInfo supportsAVX512VectorPopulationCountInstruction]); ADD_BOOL(@"Supports AVX-512 Vector Neutral Network Instructions", [OFSystemInfo supportsAVX512VectorNeuralNetworkInstructions]); ADD_BOOL(@"Supports AVX-512 Vector Byte Manipulation Instructions 2", [OFSystemInfo supportsAVX512VectorByteManipulationInstructions2]); ADD_BOOL(@"Supports AVX-512 Bit Algorithms", [OFSystemInfo supportsAVX512BitAlgorithms]); ADD_BOOL(@"Supports AVX-512 Float16 Instructions", [OFSystemInfo supportsAVX512Float16Instructions]); ADD_BOOL(@"Supports AVX-512 BFloat16 Instructions", [OFSystemInfo supportsAVX512BFloat16Instructions]); #endif #ifdef OF_POWERPC ADD_BOOL(@"Supports AltiVec", [OFSystemInfo supportsAltiVec]); #endif #undef ADD #undef ADD_UINT #undef ADD_ULONGLONG #undef ADD_BOOL #ifdef OF_HAVE_SOCKETS networkInterfaces = [OFSystemInfo networkInterfaces]; networkInterfacesString = [OFMutableString string]; for (OFString *name in networkInterfaces) { bool firstAddress = true; OFNetworkInterface interface; OFData *hardwareAddress; if (!firstInterface) [networkInterfacesString appendString: @"; "]; firstInterface = false; [networkInterfacesString appendFormat: @"%@(", name]; interface = [networkInterfaces objectForKey: name]; appendAddresses(networkInterfacesString, [interface objectForKey: OFNetworkInterfaceIPv4Addresses], &firstAddress); # ifdef OF_HAVE_IPV6 appendAddresses(networkInterfacesString, [interface objectForKey: OFNetworkInterfaceIPv6Addresses], &firstAddress); # endif # ifdef OF_HAVE_IPX appendAddresses(networkInterfacesString, [interface objectForKey: OFNetworkInterfaceIPXAddresses], &firstAddress); # endif # ifdef OF_HAVE_APPLETALK appendAddresses(networkInterfacesString, [interface objectForKey: OFNetworkInterfaceAppleTalkAddresses], &firstAddress); # endif hardwareAddress = [interface objectForKey: OFNetworkInterfaceHardwareAddress]; if (hardwareAddress != nil) { const unsigned char *bytes = hardwareAddress.items; size_t length = hardwareAddress.count; if (!firstAddress) [networkInterfacesString appendString: @", "]; for (size_t i = 0; i < length; i++) { if (i > 0) [networkInterfacesString appendString: @":"]; [networkInterfacesString appendFormat: @"%02X", bytes[i]]; } } [networkInterfacesString appendString: @")"]; } [summary addObject: [OFPair pairWithFirstObject: @"Network interfaces" secondObject: networkInterfacesString]]; #endif return summary; } @end |
Added new_tests/OFTCPSocketTests.m version [5aca96f5ad].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | /* * Copyright (c) 2008-2024 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" #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFTCPSocketTests: OTTestCase @end @implementation OFTCPSocketTests - (void)testTCPSocket { OFTCPSocket *server, *client, *accepted; OFSocketAddress address; char buffer[6]; server = [OFTCPSocket socket]; client = [OFTCPSocket socket]; address = [server bindToHost: @"127.0.0.1" port: 0]; [server listen]; [client connectToHost: @"127.0.0.1" port: OFSocketAddressIPPort(&address)]; accepted = [server accept]; OTAssertEqualObjects(OFSocketAddressString(accepted.remoteAddress), @"127.0.0.1"); [client writeString: @"Hello!"]; [accepted readIntoBuffer: buffer exactLength: 6]; OTAssertEqual(memcmp(buffer, "Hello!", 6), 0); } @end |
Added new_tests/OFThreadTests.m version [b2b1434e44].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" #import "ObjFWTest.h" @interface OFThreadTests: OTTestCase @end @interface TestThread: OFThread @end @implementation TestThread - (id)main { [[OFThread threadDictionary] setObject: @"bar" forKey: @"foo"]; OFEnsure([[[OFThread threadDictionary] objectForKey: @"foo"] isEqual: @"bar"]); return @"success"; } @end @implementation OFThreadTests - (void)testThread { TestThread *thread = [TestThread thread]; [thread start]; OTAssertEqualObjects([thread join], @"success"); OTAssertNil([[OFThread threadDictionary] objectForKey: @"foo"]); } @end |
Added new_tests/OFUDPSocketTests.m version [b806dc5c9a].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | /* * Copyright (c) 2008-2024 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" #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFUDPSocketTests: OTTestCase @end @implementation OFUDPSocketTests - (void)testUDPSocket { OFUDPSocket *sock = [OFUDPSocket socket]; OFSocketAddress addr1, addr2; char buffer[6]; sock = [OFUDPSocket socket]; addr1 = [sock bindToHost: @"127.0.0.1" port: 0]; OTAssertEqualObjects(OFSocketAddressString(&addr1), @"127.0.0.1"); [sock sendBuffer: "Hello" length: 6 receiver: &addr1]; [sock receiveIntoBuffer: buffer length: 6 sender: &addr2]; OTAssertEqual(memcmp(buffer, "Hello", 6), 0); OTAssertEqualObjects(OFSocketAddressString(&addr2), @"127.0.0.1"); OTAssertEqual(OFSocketAddressIPPort(&addr2), OFSocketAddressIPPort(&addr1)); } @end |
Added new_tests/OFUNIXDatagramSocketTests.m version [cd285c23b4].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 67 68 69 70 71 72 73 74 75 76 77 78 79 | /* * Copyright (c) 2008-2024 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" #include <errno.h> #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFUNIXDatagramSocketTests: OTTestCase @end @implementation OFUNIXDatagramSocketTests - (void)testUNIXDatagramSocket { OFUNIXDatagramSocket *sock = [OFUNIXDatagramSocket socket]; OFString *path; OFSocketAddress address1, address2; char buffer[5]; #if defined(OF_HAVE_FILES) && !defined(OF_IOS) path = [[OFSystemInfo temporaryDirectoryIRI] IRIByAppendingPathComponent: [[OFUUID UUID] UUIDString]] .fileSystemRepresentation; #else /* * We can have sockets, including UNIX sockets, while file support is * disabled. * * We also use this code path for iOS, as the temporaryDirectoryIRI is * too long on the iOS simulator. */ path = [OFString stringWithFormat: @"/tmp/%@", [[OFUUID UUID] UUIDString]]; #endif @try { address1 = [sock bindToPath: path]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: case EPERM: OTSkip(@"UNIX datagram sockets unsupported"); default: @throw e; } } @try { [sock sendBuffer: "Hello" length: 5 receiver: &address1]; OTAssertEqual([sock receiveIntoBuffer: buffer length: 5 sender: &address2], 5); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); OTAssertTrue(OFSocketAddressEqual(&address1, &address2)); OTAssertEqual(OFSocketAddressHash(&address1), OFSocketAddressHash(&address2)); } @finally { #ifdef OF_HAVE_FILES [[OFFileManager defaultManager] removeItemAtPath: path]; #endif } } @end |
Added new_tests/OFUNIXStreamSocketTests.m version [404c597141].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | /* * Copyright (c) 2008-2024 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" #include <errno.h> #include <string.h> #import "ObjFW.h" #import "ObjFWTest.h" @interface OFUNIXStreamSocketTests: OTTestCase @end @implementation OFUNIXStreamSocketTests - (void)testUNIXStreamSocket { OFString *path; OFUNIXStreamSocket *sockClient, *sockServer, *sockAccepted; char buffer[5]; #if defined(OF_HAVE_FILES) && !defined(OF_IOS) path = [[OFSystemInfo temporaryDirectoryIRI] IRIByAppendingPathComponent: [[OFUUID UUID] UUIDString]] .fileSystemRepresentation; #else /* * We can have sockets, including UNIX sockets, while file support is * disabled. * * We also use this code path for iOS, as the temporaryDirectory:RI is * too long on the iOS simulator. */ path = [OFString stringWithFormat: @"/tmp/%@", [[OFUUID UUID] UUIDString]]; #endif sockClient = [OFUNIXStreamSocket socket]; sockServer = [OFUNIXStreamSocket socket]; @try { [sockServer bindToPath: path]; } @catch (OFBindSocketFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: case EPERM: OTSkip(@"UNIX stream sockets unsupported"); default: @throw e; } } @try { [sockServer listen]; [sockClient connectToPath: path]; sockAccepted = [sockServer accept]; [sockAccepted writeBuffer: "Hello" length: 5]; OTAssertEqual([sockClient readIntoBuffer: buffer length: 5], 5); OTAssertEqual(memcmp(buffer, "Hello", 5), 0); OTAssertEqual(OFSocketAddressUNIXPath( sockAccepted.remoteAddress).length, 0); } @finally { #ifdef OF_HAVE_FILES [[OFFileManager defaultManager] removeItemAtPath: path]; #endif } } @end |
Added new_tests/plugin/Info.plist.in version [bbe65d4bbd].
> > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleExecutable</key> <string>TestPlugin</string> <key>CFBundleName</key> <string>TestPlugin</string> <key>CFBundleIdentifier</key> <string>im.nil.objfw.tests.plugin</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>BNDL</string> <key>CFBundleVersion</key> <string>@BUNDLE_VERSION@</string> <key>CFBundleShortVersionString</key> <string>@BUNDLE_SHORT_VERSION@</string> <key>MinimumOSVersion</key> <string>9.0</string> </dict> </plist> |
Added new_tests/plugin/Makefile version [a32249aa5e].
> > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 | DISTCLEAN = Info.plist PLUGIN_NOINST = TestPlugin${PLUGIN_SUFFIX} SRCS = TestPlugin.m include ../../buildsys.mk include ../../extra.mk CPPFLAGS += -I../.. -I../../src -I../../src/runtime LIBS := ${TESTPLUGIN_LIBS} ${LIBS} LD = ${OBJC} |
Added new_tests/plugin/TestPlugin.h version [0bf4ece135].
> > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | /* * Copyright (c) 2008-2024 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. */ #import "OFObject.h" @interface TestPlugin: OFObject - (int)test: (int)num; @end |
Added new_tests/plugin/TestPlugin.m version [f9d32844b0].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | /* * Copyright (c) 2008-2024 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 "TestPlugin.h" #ifdef OF_OBJFW_RUNTIME # import "runtime/private.h" OF_DESTRUCTOR() { Class class = objc_getClass("TestPlugin"); if (class == Nil) /* * musl has broken dlclose(): Instead of calling the destructor * on dlclose(), they call it on exit(). This of course means * that our tests might have already called objc_deinit() and * the class is already gone. */ return; objc_unregisterClass(class); } #endif @implementation TestPlugin - (int)test: (int)num { return num * 2; } @end Class class(void) { return [TestPlugin class]; } |
Added new_tests/subprocess/Makefile version [0c326652cc].
> > > > > > > > > | 1 2 3 4 5 6 7 8 9 | PROG_NOINST = subprocess${PROG_SUFFIX} SRCS = Subprocess.m include ../../buildsys.mk include ../../extra.mk CPPFLAGS += -I../../src -I../../src/exceptions -I../../src/runtime -I../.. LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} LD = ${OBJC} |
Added new_tests/subprocess/Subprocess.m version [31a1046120].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | /* * Copyright (c) 2008-2024 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 "ObjFW.h" @interface Subprocess: OFObject <OFApplicationDelegate> @end OF_APPLICATION_DELEGATE(Subprocess) @implementation Subprocess - (void)applicationDidFinishLaunching: (OFNotification *)notification { OFString *line; if (![[OFApplication arguments] isEqual: [OFArray arrayWithObjects: @"tést", @"123", nil]]) [OFApplication terminateWithStatus: 1]; if (![[[OFApplication environment] objectForKey: @"tëst"] isEqual: @"yés"]) [OFApplication terminateWithStatus: 2]; while ((line = [OFStdIn readLine]) != nil) [OFStdOut writeLine: line.uppercaseString]; [OFApplication terminate]; } @end |
Added new_tests/testfile.bin version [ac78121630].
cannot compute difference between binary files
Added new_tests/testfile.ini version [9e2ef2dc1a].
> > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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 |
Modified src/Makefile from [faa3d6a6cb] to [cca3d2063b].
︙ | ︙ | |||
107 108 109 110 111 112 113 | OFXMLParser.m \ OFXMLProcessingInstruction.m \ OFZIPArchive.m \ OFZIPArchiveEntry.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | OFXMLParser.m \ OFXMLProcessingInstruction.m \ OFZIPArchive.m \ OFZIPArchiveEntry.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_FILES = OFFile.m \ OFString+PathAdditions.m SRCS_PLUGINS = OFPlugin.m SRCS_SOCKETS = OFAAAADNSResourceRecord.m \ OFADNSResourceRecord.m \ |
︙ | ︙ | |||
153 154 155 156 157 158 159 | ${USE_SRCS_UNIX_SOCKETS} SRCS_APPLETALK = OFDDPSocket.m SRCS_IPX = OFIPXSocket.m \ OFSPXSocket.m \ OFSPXStreamSocket.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocket.m \ OFUNIXStreamSocket.m | | | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | ${USE_SRCS_UNIX_SOCKETS} SRCS_APPLETALK = OFDDPSocket.m SRCS_IPX = OFIPXSocket.m \ OFSPXSocket.m \ OFSPXStreamSocket.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocket.m \ OFUNIXStreamSocket.m SRCS_SUBPROCESSES = OFSubprocess.m SRCS_THREADS = OFCondition.m \ OFMutex.m \ OFPlainCondition.m \ OFPlainMutex.m \ OFPlainThread.m \ OFRecursiveMutex.m \ OFTLSKey.m |
︙ | ︙ |
Modified src/OFStdIOStream.m from [4bd5de9454] to [ca9e9a8b30].
︙ | ︙ | |||
115 116 117 118 119 120 121 | [OFStdErr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString, date.microsecond / 1000, me, getpid(), msg]; objc_autoreleasePoolPop(pool); } | < | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | [OFStdErr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString, date.microsecond / 1000, me, getpid(), msg]; objc_autoreleasePoolPop(pool); } static int colorToANSI(OFColor *color) { if ([color isEqual: [OFColor black]]) return 30; if ([color isEqual: [OFColor maroon]]) return 31; |
︙ | ︙ | |||
154 155 156 157 158 159 160 | if ([color isEqual: [OFColor aqua]]) return 96; if ([color isEqual: [OFColor white]]) return 97; return -1; } | < | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | if ([color isEqual: [OFColor aqua]]) return 96; if ([color isEqual: [OFColor white]]) return 97; return -1; } @implementation OFStdIOStream #ifndef OF_WINDOWS + (void)load { if (self != [OFStdIOStream class]) return; |
︙ | ︙ | |||
428 429 430 431 432 433 434 | - (unsigned int)retainCount { return OFMaxRetainCount; } - (bool)hasTerminal { | > > | | 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | - (unsigned int)retainCount { return OFMaxRetainCount; } - (bool)hasTerminal { #if defined(OF_WII) return true; #elif defined(HAVE_ISATTY) && !defined(OF_WII_U) return isatty(_fd); #else return false; #endif } - (int)columns |
︙ | ︙ | |||
467 468 469 470 471 472 473 | #else return -1; #endif } - (void)setForegroundColor: (OFColor *)color { | < | < < | < < | < < | < < | < < | < < | < < | < | 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | #else return -1; #endif } - (void)setForegroundColor: (OFColor *)color { int code; if (!self.hasTerminal) return; if ((code = colorToANSI(color)) == -1) return; [self writeFormat: @"\033[%um", code]; } - (void)setBackgroundColor: (OFColor *)color { int code; if (!self.hasTerminal) return; if ((code = colorToANSI(color)) == -1) return; [self writeFormat: @"\033[%um", code + 10]; } - (void)reset { if (!self.hasTerminal) return; [self writeString: @"\033[0m"]; } - (void)clear { if (!self.hasTerminal) return; [self writeString: @"\033[2J"]; } - (void)eraseLine { if (!self.hasTerminal) return; [self writeString: @"\033[2K"]; } - (void)setCursorColumn: (unsigned int)column { if (!self.hasTerminal) return; [self writeFormat: @"\033[%uG", column + 1]; } - (void)setCursorPosition: (OFPoint)position { if (position.x < 0 || position.y < 0) @throw [OFInvalidArgumentException exception]; if (!self.hasTerminal) return; [self writeFormat: @"\033[%u;%uH", (unsigned)position.y + 1, (unsigned)position.x + 1]; } - (void)setRelativeCursorPosition: (OFPoint)position { if (!self.hasTerminal) return; if (position.x > 0) [self writeFormat: @"\033[%uC", (unsigned)position.x]; else if (position.x < 0) [self writeFormat: @"\033[%uD", (unsigned)-position.x]; if (position.y > 0) [self writeFormat: @"\033[%uB", (unsigned)position.y]; else if (position.y < 0) [self writeFormat: @"\033[%uA", (unsigned)-position.y]; } @end |
Modified src/test/Makefile from [b269c69e19] to [c3118bd230].
1 2 3 4 5 6 | include ../../extra.mk DISTCLEAN = Info.plist STATIC_LIB = libobjfwtest.a | | > | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | include ../../extra.mk DISTCLEAN = Info.plist STATIC_LIB = libobjfwtest.a SRCS = OTAssert.m \ OTOrderedDictionary.m \ OTTestCase.m INCLUDES := ${SRCS:.m=.h} \ ObjFWTest.h SRCS += OTAppDelegate.m \ OTAssertionFailedException.m \ OTTestSkippedException.m includesubdir = ObjFWTest include ../../buildsys.mk CPPFLAGS += -I. \ -I.. \ |
︙ | ︙ |
Deleted src/test/OTAppDelegate.h version [64bf862003].
|
| < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/test/OTAppDelegate.m from [3e448c799c] to [6921cb8cdc].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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" | > | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 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 | * 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 "OFApplication.h" #import "OFColor.h" #import "OFDictionary.h" #import "OFMethodSignature.h" #import "OFSet.h" #import "OFStdIOStream.h" #import "OFValue.h" #import "OTTestCase.h" #import "OTAssertionFailedException.h" #import "OTTestSkippedException.h" #ifdef OF_WII # define asm __asm__ # include <gccore.h> # include <wiiuse/wpad.h> # undef asm #endif @interface OTAppDelegate: OFObject <OFApplicationDelegate> @end enum Status { StatusRunning, StatusOk, StatusFailed, StatusSkipped }; OF_APPLICATION_DELEGATE(OTAppDelegate) static bool isSubclassOfClass(Class class, Class superclass) { for (Class iter = class; iter != Nil; iter = class_getSuperclass(iter)) if (iter == superclass) return true; return false; } @implementation OTAppDelegate #ifdef OF_WII + (void)initialize { GXRModeObj *mode; void *nextFB; VIDEO_Init(); WPAD_Init(); mode = VIDEO_GetPreferredMode(NULL); nextFB = MEM_K0_TO_K1(SYS_AllocateFramebuffer(mode)); VIDEO_Configure(mode); VIDEO_SetNextFramebuffer(nextFB); VIDEO_SetBlack(FALSE); VIDEO_Flush(); VIDEO_WaitVSync(); if (mode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); CON_InitEx(mode, 2, 2, mode->fbWidth - 4, mode->xfbHeight - 4); VIDEO_ClearFrameBuffer(mode, nextFB, COLOR_BLACK); } #endif - (OFSet OF_GENERIC(Class) *)testClasses { Class *classes = objc_copyClassList(NULL); OFMutableSet *testClasses; if (classes == NULL) return nil; |
︙ | ︙ | |||
85 86 87 88 89 90 91 92 93 94 95 | return nil; @try { tests = [OFMutableSet set]; for (Method *iter = methods; *iter != NULL; iter++) { SEL selector = method_getName(*iter); if (selector == NULL) continue; | > > | > > > > > > > > > > > > > > > > | | | | > > > > > > > > > > > > > | > > > > > > > > > > > | > > > > > > > > | | > > < | | | > > > > > > | | | | > > | > > > | > > > > > > > > > > > > > > > > > > > > > | > > > | > > > > > > > > > > > > > > > > | | > > > > > > | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | return nil; @try { tests = [OFMutableSet set]; for (Method *iter = methods; *iter != NULL; iter++) { SEL selector = method_getName(*iter); void *pool; OFMethodSignature *sig; if (selector == NULL) continue; if (strncmp(sel_getName(selector), "test", 4) != 0) continue; pool = objc_autoreleasePoolPush(); sig = [OFMethodSignature signatureWithObjCTypes: method_getTypeEncoding(*iter)]; if (strcmp(sig.methodReturnType, "v") == 0 && sig.numberOfArguments == 2 && strcmp([sig argumentTypeAtIndex: 0], "@") == 0 && strcmp([sig argumentTypeAtIndex: 1], ":") == 0) [tests addObject: [OFValue valueWithPointer: selector]]; objc_autoreleasePoolPop(pool); } } @finally { OFFreeMemory(methods); } if (class_getSuperclass(class) != Nil) [tests unionSet: [self testsInClass: class_getSuperclass(class)]]; [tests makeImmutable]; return tests; } - (void)printStatusForTest: (SEL)test inClass: (Class)class status: (enum Status)status description: (OFString *)description { switch (status) { case StatusRunning: [OFStdOut setForegroundColor: [OFColor olive]]; [OFStdOut writeFormat: @"-[%@ ", class]; [OFStdOut setForegroundColor: [OFColor yellow]]; [OFStdOut writeFormat: @"%s", sel_getName(test)]; [OFStdOut setForegroundColor: [OFColor olive]]; [OFStdOut writeString: @"]: "]; break; case StatusOk: [OFStdOut setForegroundColor: [OFColor green]]; [OFStdOut writeFormat: @"\r-[%@ ", class]; [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeFormat: @"%s", sel_getName(test)]; [OFStdOut setForegroundColor: [OFColor green]]; [OFStdOut writeLine: @"]: ok"]; break; case StatusFailed: [OFStdOut setForegroundColor: [OFColor maroon]]; [OFStdOut writeFormat: @"\r-[%@ ", class]; [OFStdOut setForegroundColor: [OFColor red]]; [OFStdOut writeFormat: @"%s", sel_getName(test)]; [OFStdOut setForegroundColor: [OFColor maroon]]; [OFStdOut writeLine: @"]: failed"]; [OFStdOut writeLine: description]; break; case StatusSkipped: [OFStdOut setForegroundColor: [OFColor gray]]; [OFStdOut writeFormat: @"\r-[%@ ", class]; [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeFormat: @"%s", sel_getName(test)]; [OFStdOut setForegroundColor: [OFColor gray]]; [OFStdOut writeLine: @"]: skipped"]; if (description != nil) [OFStdOut writeLine: description]; break; } #ifdef OF_WII if (status == StatusFailed) { [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press A to continue"]; for (;;) { WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) return; VIDEO_WaitVSync(); } } #endif } - (void)applicationDidFinishLaunching: (OFNotification *)notification { OFSet OF_GENERIC(Class) *testClasses = [self testClasses]; size_t numSucceeded = 0, numFailed = 0, numSkipped = 0; OFMutableDictionary *summaries = [OFMutableDictionary dictionary]; [OFStdOut setForegroundColor: [OFColor purple]]; [OFStdOut writeString: @"Found "]; #ifndef OF_WII [OFStdOut setForegroundColor: [OFColor fuchsia]]; #endif [OFStdOut writeFormat: @"%zu", testClasses.count]; [OFStdOut setForegroundColor: [OFColor purple]]; [OFStdOut writeFormat: @" test case%s\n", (testClasses.count != 1 ? "s" : "")]; for (Class class in testClasses) { OFArray *summary; [OFStdOut setForegroundColor: [OFColor teal]]; [OFStdOut writeFormat: @"Running ", class]; [OFStdOut setForegroundColor: [OFColor aqua]]; [OFStdOut writeFormat: @"%@\n", class]; for (OFValue *test in [self testsInClass: class]) { void *pool = objc_autoreleasePoolPush(); bool failed = false, skipped = false; OTTestCase *instance; [self printStatusForTest: test.pointerValue inClass: class status: StatusRunning description: nil]; instance = [[[class alloc] init] autorelease]; @try { [instance setUp]; [instance performSelector: test.pointerValue]; } @catch (OTAssertionFailedException *e) { /* * If an assertion fails during -[setUp], don't * run the test. * If an assertion fails during a test, abort * the test. */ [self printStatusForTest: test.pointerValue inClass: class status: StatusFailed description: e.description]; failed = true; } @catch (OTTestSkippedException *e) { [self printStatusForTest: test.pointerValue inClass: class status: StatusSkipped description: e.description]; skipped = true; } @try { [instance tearDown]; } @catch (OTAssertionFailedException *e) { /* * If an assertion fails during -[tearDown], * abort the tear down. */ if (!failed) { SEL selector = test.pointerValue; OFString *description = e.description; [self printStatusForTest: selector inClass: class status: StatusFailed description: description]; failed = true; } } if (!failed && !skipped) { [self printStatusForTest: test.pointerValue inClass: class status: StatusOk description: nil]; numSucceeded++; } else if (failed) numFailed++; else if (skipped) numSkipped++; objc_autoreleasePoolPop(pool); } summary = [class summary]; if (summary != nil) [summaries setObject: summary forKey: class]; } for (Class class in summaries) { OFArray *summary = [summaries objectForKey: class]; [OFStdOut setForegroundColor: [OFColor teal]]; [OFStdOut writeString: @"Summary for "]; [OFStdOut setForegroundColor: [OFColor aqua]]; [OFStdOut writeFormat: @"%@\n", class]; for (OFPair *line in summary) { [OFStdOut setForegroundColor: [OFColor navy]]; [OFStdOut writeFormat: @"%@: ", line.firstObject]; [OFStdOut setForegroundColor: [OFColor blue]]; [OFStdOut writeFormat: @"%@\n", line.secondObject]; } } #ifndef OF_WII [OFStdOut setForegroundColor: [OFColor fuchsia]]; #else [OFStdOut setForegroundColor: [OFColor purple]]; #endif [OFStdOut writeFormat: @"%zu", numSucceeded]; [OFStdOut setForegroundColor: [OFColor purple]]; [OFStdOut writeFormat: @" test%s succeeded, ", (numSucceeded != 1 ? "s" : "")]; #ifndef OF_WII [OFStdOut setForegroundColor: [OFColor fuchsia]]; #endif [OFStdOut writeFormat: @"%zu", numFailed]; [OFStdOut setForegroundColor: [OFColor purple]]; [OFStdOut writeFormat: @" test%s failed, ", (numFailed != 1 ? "s" : "")]; #ifndef OF_WII [OFStdOut setForegroundColor: [OFColor fuchsia]]; #endif [OFStdOut writeFormat: @"%zu", numSkipped]; [OFStdOut setForegroundColor: [OFColor purple]]; [OFStdOut writeFormat: @" test%s skipped\n", (numSkipped != 1 ? "s" : "")]; [OFStdOut reset]; #ifdef OF_WII [OFStdOut setForegroundColor: [OFColor silver]]; [OFStdOut writeLine: @"Press home button to exit"]; for (;;) { WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) [OFApplication terminateWithStatus: (int)numFailed]; VIDEO_WaitVSync(); } #else [OFApplication terminateWithStatus: (int)numFailed]; #endif } @end |
Modified src/test/OTAssert.h from [4079f8ef1f] to [5c08862032].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #define OTAssert(cond, ...) \ OTAssertImpl(self, _cmd, cond, @#cond, @__FILE__, __LINE__, \ ## __VA_ARGS__, nil) #define OTAssertTrue(cond, ...) OTAssert(cond == true, ## __VA_ARGS__) #define OTAssertFalse(cond, ...) OTAssert(cond == false, ## __VA_ARGS__) #define OTAssertEqual(a, b, ...) OTAssert(a == b, ## __VA_ARGS__) #define OTAssertNotEqual(a, b, ...) OTAssert(a != b, ## __VA_ARGS__) #define OTAssertEqualObjects(a, b, ...) OTAssert([a isEqual: b], ## __VA_ARGS__) #define OTAssertNotEqualObjects(a, b, ...) \ OTAssert(![a isEqual: b], ## __VA_ARGS__) #define OTAssertNil(object, ...) OTAssert(object == nil, ## __VA_ARGS__) #define OTAssertNotNil(object, ...) OTAssert(object != nil, ## __VA_ARGS__) #define OTAssertThrows(expression, ...) \ { \ | > > > > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #define OTAssert(cond, ...) \ OTAssertImpl(self, _cmd, cond, @#cond, @__FILE__, __LINE__, \ ## __VA_ARGS__, nil) #define OTAssertTrue(cond, ...) OTAssert(cond == true, ## __VA_ARGS__) #define OTAssertFalse(cond, ...) OTAssert(cond == false, ## __VA_ARGS__) #define OTAssertEqual(a, b, ...) OTAssert(a == b, ## __VA_ARGS__) #define OTAssertNotEqual(a, b, ...) OTAssert(a != b, ## __VA_ARGS__) #define OTAssertLessThan(a, b, ...) OTAssert(a < b, ## __VA_ARGS__) #define OTAssertLessThanOrEqual(a, b, ...) OTAssert(a <= b, ## __VA_ARGS__) #define OTAssertGreaterThan(a, b, ...) OTAssert(a > b, ## __VA_ARGS__) #define OTAssertGreaterThanOrEqual(a, b, ...) OTAssert(a >= b, ## __VA_ARGS__) #define OTAssertEqualObjects(a, b, ...) OTAssert([a isEqual: b], ## __VA_ARGS__) #define OTAssertNotEqualObjects(a, b, ...) \ OTAssert(![a isEqual: b], ## __VA_ARGS__) #define OTAssertNil(object, ...) OTAssert(object == nil, ## __VA_ARGS__) #define OTAssertNotNil(object, ...) OTAssert(object != nil, ## __VA_ARGS__) #define OTAssertThrows(expression, ...) \ { \ |
︙ | ︙ | |||
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | @try { \ expression; \ } @catch (exception *e) { \ OTThrown = true; \ } \ OTAssert(OTThrown, ## __VA_ARGS__); \ } #ifdef __cplusplus extern "C" { #endif extern void OTAssertImpl(id testCase, SEL test, bool condition, OFString *check, OFString *file, size_t line, ...); #ifdef __cplusplus } #endif | > > > | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | @try { \ expression; \ } @catch (exception *e) { \ OTThrown = true; \ } \ OTAssert(OTThrown, ## __VA_ARGS__); \ } #define OTSkip(...) \ OTSkipImpl(self, _cmd, @__FILE__, __LINE__, ## __VA_ARGS__, nil) #ifdef __cplusplus extern "C" { #endif extern void OTAssertImpl(id testCase, SEL test, bool condition, OFString *check, OFString *file, size_t line, ...); extern void OTSkipImpl(id testCase, SEL test, OFString *file, size_t line, ...); #ifdef __cplusplus } #endif |
Modified src/test/OTAssert.m from [dfc3f7ba82] to [27e2adc076].
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | */ #include "config.h" #import "OFString.h" #import "OTAssertionFailedException.h" void OTAssertImpl(id testCase, SEL test, bool condition, OFString *check, OFString *file, size_t line, ...) { va_list arguments; OFConstantString *format; | > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | */ #include "config.h" #import "OFString.h" #import "OTAssertionFailedException.h" #import "OTTestSkippedException.h" void OTAssertImpl(id testCase, SEL test, bool condition, OFString *check, OFString *file, size_t line, ...) { va_list arguments; OFConstantString *format; |
︙ | ︙ | |||
39 40 41 42 43 44 45 | arguments: arguments] autorelease]; va_end(arguments); @throw [OTAssertionFailedException exceptionWithCondition: check message: message]; } | > > > > > > > > > > > > > > > > > > > > | 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 | arguments: arguments] autorelease]; va_end(arguments); @throw [OTAssertionFailedException exceptionWithCondition: check message: message]; } void OTSkipImpl(id testCase, SEL test, OFString *file, size_t line, ...) { va_list arguments; OFConstantString *format; OFString *message = nil; va_start(arguments, line); format = va_arg(arguments, OFConstantString *); if (format != nil) message = [[[OFString alloc] initWithFormat: format arguments: arguments] autorelease]; va_end(arguments); @throw [OTTestSkippedException exceptionWithMessage: message]; } |
Added src/test/OTOrderedDictionary.h version [b6c6515436].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 | /* * Copyright (c) 2008-2024 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. */ #ifdef OBJFWTEST_LOCAL_INCLUDES # import "ObjFW.h" #else # import <ObjFW/ObjFW.h> #endif OF_ASSUME_NONNULL_BEGIN @interface OTOrderedDictionary: OFDictionary { OFArray *_keys; OFArray *_objects; } @end OF_ASSUME_NONNULL_END |
Added src/test/OTOrderedDictionary.m version [fea7c7d9b6].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | /* * Copyright (c) 2008-2024 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 "OTOrderedDictionary.h" @implementation OTOrderedDictionary - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { self = [super init]; @try { OFMutableArray *mutableKeys, *mutableObjects; mutableKeys = [[OFMutableArray alloc] initWithCapacity: count]; _keys = mutableKeys; mutableObjects = [[OFMutableArray alloc] initWithCapacity: count]; _objects = mutableObjects; for (size_t i = 0; i < count; i++) { [mutableKeys addObject: keys[i]]; [mutableObjects addObject: objects[i]]; } [mutableKeys makeImmutable]; [mutableObjects makeImmutable]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_keys release]; [_objects release]; [super dealloc]; } - (id)objectForKey: (id)key { size_t i = 0; for (id iter in _keys) { if ([iter isEqual: key]) return [_objects objectAtIndex: i]; i++; } return nil; } - (size_t)count { return _keys.count; } - (OFEnumerator *)keyEnumerator { return [_keys objectEnumerator]; } - (OFEnumerator *)objectEnumerator { return [_objects objectEnumerator]; } @end |
Modified src/test/OTTestCase.h from [2add704de5] to [a61157e757].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * 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. */ #ifdef OBJFWTEST_LOCAL_INCLUDES | | | > > > > > > | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | * 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. */ #ifdef OBJFWTEST_LOCAL_INCLUDES # import "ObjFW.h" #else # import <ObjFW/ObjFW.h> #endif OF_ASSUME_NONNULL_BEGIN @interface OTTestCase: OFObject #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nullable, nonatomic) OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *summary; #endif + (nullable OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary; - (void)setUp; - (void)tearDown; @end OF_ASSUME_NONNULL_END |
Modified src/test/OTTestCase.m from [3c3d45f200] to [fdb0a500c1].
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | */ #include "config.h" #import "OTTestCase.h" @implementation OTTestCase: OFObject - (void)setUp { } - (void)tearDown { } | > > > > > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | */ #include "config.h" #import "OTTestCase.h" @implementation OTTestCase: OFObject + (OFArray OF_GENERIC(OFPair OF_GENERIC(OFString *, id) *) *)summary { return nil; } - (void)setUp { } - (void)tearDown { } |
︙ | ︙ |
Added src/test/OTTestSkippedException.h version [499842bf2f].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 | /* * Copyright (c) 2008-2024 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. */ #import "OFException.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @interface OTTestSkippedException: OFException { OFString *_Nullable _message; } @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *message; + (instancetype)exceptionWithMessage: (nullable OFString *)message; + (instancetype)exception OF_UNAVAILABLE; - (instancetype)initWithMessage: (nullable OFString *)message; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Added src/test/OTTestSkippedException.m version [b2f5e97a93].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 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 67 | /* * Copyright (c) 2008-2024 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 "OTTestSkippedException.h" @implementation OTTestSkippedException @synthesize message = _message; + (instancetype)exceptionWithMessage: (OFString *)message { return [[[self alloc] initWithMessage: message] autorelease]; } + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } - (instancetype)initWithMessage: (OFString *)message { self = [super init]; @try { _message = [message copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { [_message release]; [super dealloc]; } - (OFString *)description { if (_message != nil) return [OFString stringWithFormat: @"Test skipped: %@", _message]; else return nil; } @end |
Modified src/test/ObjFWTest.h from [c6fa64803a] to [e2709fe53c].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * 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. */ #import "OTTestCase.h" #import "OTAssert.h" | > | 11 12 13 14 15 16 17 18 | * 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. */ #import "OTTestCase.h" #import "OTAssert.h" #import "OTOrderedDictionary.h" |
Deleted tests/ForwardingTests.m version [1d203d1fb8].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified tests/Makefile from [f85e00f0ed] to [33d6256e99].
1 2 | include ../extra.mk | < | < | < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < | | < < < < < < < < < < < < < < < < < < < | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | include ../extra.mk SUBDIRS = ${OBJC_SYNC} \ terminal CLEAN = EBOOT.PBP \ boot.dol \ ${PROG_NOINST}.arm9 \ ${PROG_NOINST}.nds \ ${PROG_NOINST}.nro \ ${PROG_NOINST}.rpx DISTCLEAN = Info.plist PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} SRCS = OFDataTests.m \ OFDictionaryTests.m \ OFListTests.m \ OFMemoryStreamTests.m \ OFNotificationCenterTests.m \ OFStreamTests.m \ OFStringTests.m \ OFValueTests.m \ OFXMLElementBuilderTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ RuntimeTests.m \ ${RUNTIME_ARC_TESTS_M} \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_WINDOWS} SRCS_SOCKETS = ${OF_HTTP_CLIENT_TESTS_M} \ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m SRCS_WINDOWS = OFWindowsRegistryKeyTests.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test include ../buildsys.mk .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 rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} |
︙ | ︙ | |||
152 153 154 155 156 157 158 | rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT | < < < < < < < < < < < < < < < < < < < < < < | 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 | rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT run-on-android: all echo "Uploading files to Android device..." if test -f ../src/libobjfw.so; then \ adb push ../src/libobjfw.so \ /data/local/tmp/objfw/libobjfw.so.${OBJFW_LIB_MAJOR}; \ fi if test -f ../src/runtime/libobjfwrt.so; then \ adb push ../src/runtime/libobjfwrt.so \ /data/local/tmp/objfw/libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ fi adb push tests /data/local/tmp/objfw/tests adb push testfile.txt /data/local/tmp/objfw/testfile.txt echo "Running tests binary on Android device..." adb shell 'cd /data/local/tmp/objfw && LD_LIBRARY_PATH=. exec ${WRAPPER} ./tests' EBOOT.PBP: ${PROG_NOINST} psp-fixup-imports ${PROG_NOINST} mksfo "ObjFW Tests" PARAM.SFO psp-strip ${PROG_NOINST} |
︙ | ︙ | |||
229 230 231 232 233 234 235 | ${PROG_NOINST}.rpx: ${PROG_NOINST} elf2rpl $< $@ CPPFLAGS += -I../src \ -I../src/exceptions \ -I../src/runtime \ -I.. \ | | < | 149 150 151 152 153 154 155 156 157 158 159 160 | ${PROG_NOINST}.rpx: ${PROG_NOINST} elf2rpl $< $@ CPPFLAGS += -I../src \ -I../src/exceptions \ -I../src/runtime \ -I.. \ -DSTDOUT OBJCFLAGS_RuntimeARCTests.m = -fobjc-arc -fobjc-arc-exceptions LIBS := ${TESTS_LIBS} ${LIBS} LDFLAGS += ${MAP_LDFLAGS} LD = ${OBJC} |
Deleted tests/OFArrayTests.m version [1024ac5260].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFBlockTests.m version [41100ed0e1].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFCharacterSetTests.m version [cbaf41131b].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFColorTests.m version [43c0fcb4d4].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFDDPSocketTests.m version [5433dc7a16].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFDNSResolverTests.m version [979544c90c].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFDateTests.m version [a09d2c22e2].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFHMACTests.m version [b03d7ee96c].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFINIFileTests.m version [793add569b].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFIPXSocketTests.m version [0ae4e44d89].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFIRITests.m version [3036a831f2].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFInvocationTests.m version [23f57f7d3a].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFJSONTests.m version [92f1f602a7].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFLocaleTests.m version [bb15c236d6].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFMD5HashTests.m version [96fc59cb59].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFMatrix4x4Tests.m version [29d0338fbf].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFMethodSignatureTests.m version [f874f8bb5c].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFNumberTests.m version [8e6e4b486d].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFObjectTests.m version [39c729edc8].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFPBKDF2Tests.m version [2febb34313].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFPluginTests.m version [278848818e].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFPropertyListTests.m version [f48a04b761].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFRIPEMD160HashTests.m version [4768731328].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSHA1HashTests.m version [7856801f0e].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSHA224HashTests.m version [74da8c08a3].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSHA256HashTests.m version [1004803a7d].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSHA384HashTests.m version [7039b1bf58].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSHA512HashTests.m version [11c494533c].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSPXSocketTests.m version [262f8617dc].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSPXStreamSocketTests.m version [37e7d0cfd1].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFScryptTests.m version [3717bd0eab].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSetTests.m version [4668cbb71a].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSocketTests.m version [2289bf230f].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSubprocessTests.m version [846e8d88e2].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFSystemInfoTests.m version [f3db5fbea9].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFTCPSocketTests.m version [4cfbc85ac3].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFThreadTests.m version [bbeb8a5fbf].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFUDPSocketTests.m version [9c08c02308].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFUNIXDatagramSocketTests.m version [588aa866e4].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFUNIXStreamSocketTests.m version [b3f4ed0fcd].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified tests/TestsAppDelegate.h from [7482d2d1ef] to [d0f720ed69].
︙ | ︙ | |||
55 56 57 58 59 60 61 | } - (void)outputTesting: (OFString *)test inModule: (OFString *)module; - (void)outputSuccess: (OFString *)test inModule: (OFString *)module; - (void)outputFailure: (OFString *)test inModule: (OFString *)module; @end | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 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 | } - (void)outputTesting: (OFString *)test inModule: (OFString *)module; - (void)outputSuccess: (OFString *)test inModule: (OFString *)module; - (void)outputFailure: (OFString *)test inModule: (OFString *)module; @end @interface TestsAppDelegate (OFDataTests) - (void)dataTests; @end @interface TestsAppDelegate (OFDictionaryTests) - (void)dictionaryTests; @end @interface TestsAppDelegate (OFHTTPClientTests) - (void)HTTPClientTests; @end @interface TestsAppDelegate (OFHTTPCookieTests) - (void)HTTPCookieTests; @end @interface TestsAppDelegate (OFHTTPCookieManagerTests) - (void)HTTPCookieManagerTests; @end @interface TestsAppDelegate (OFKernelEventObserverTests) - (void)kernelEventObserverTests; @end @interface TestsAppDelegate (OFListTests) - (void)listTests; @end @interface TestsAppDelegate (OFMemoryStreamTests) - (void)memoryStreamTests; @end @interface TestsAppDelegate (OFNotificationCenterTests) - (void)notificationCenterTests; @end @interface TestsAppDelegate (RuntimeTests) - (void)runtimeTests; @end @interface TestsAppDelegate (RuntimeARCTests) - (void)runtimeARCTests; @end @interface TestsAppDelegate (OFStreamTests) - (void)streamTests; @end @interface TestsAppDelegate (OFStringTests) - (void)stringTests; @end @interface TestsAppDelegate (OFValueTests) - (void)valueTests; @end @interface TestsAppDelegate (OFWindowsRegistryKeyTests) - (void)windowsRegistryKeyTests; @end |
︙ | ︙ |
Modified tests/TestsAppDelegate.m from [08be9d3a13] to [01275bfcd5].
︙ | ︙ | |||
370 371 372 373 374 375 376 | changeCurrentDirectoryPath: @"/apps/objfw-tests"]; #endif [self runtimeTests]; #ifdef COMPILER_SUPPORTS_ARC [self runtimeARCTests]; #endif | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | changeCurrentDirectoryPath: @"/apps/objfw-tests"]; #endif [self runtimeTests]; #ifdef COMPILER_SUPPORTS_ARC [self runtimeARCTests]; #endif [self stringTests]; [self dataTests]; [self dictionaryTests]; [self listTests]; [self valueTests]; [self streamTests]; [self memoryStreamTests]; [self notificationCenterTests]; #ifdef OF_HAVE_SOCKETS [self kernelEventObserverTests]; #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) [self HTTPClientTests]; #endif #ifdef OF_HAVE_SOCKETS [self HTTPCookieTests]; [self HTTPCookieManagerTests]; #endif [self XMLParserTests]; [self XMLNodeTests]; [self XMLElementBuilderTests]; #ifdef OF_WINDOWS [self windowsRegistryKeyTests]; #endif [OFStdOut reset]; #if defined(OF_IOS) [OFStdOut writeFormat: @"%d tests failed!", _fails]; [OFApplication terminateWithStatus: _fails]; #elif defined(OF_WII) [OFStdOut writeString: @"Press home button to exit!"]; |
︙ | ︙ |
Deleted tests/plugin/Info.plist.in version [bbe65d4bbd].
|
| < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/plugin/Makefile version [a32249aa5e].
|
| < < < < < < < < < < < |
Deleted tests/plugin/TestPlugin.h version [0bf4ece135].
|
| < < < < < < < < < < < < < < < < < < < < |
Deleted tests/plugin/TestPlugin.m version [f9d32844b0].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/subprocess/Makefile version [0c326652cc].
|
| < < < < < < < < < |
Deleted tests/subprocess/Subprocess.m version [31a1046120].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/testfile.bin version [ac78121630].
cannot compute difference between binary files
Deleted tests/testfile.ini version [70f0fff498].
|
| < < < < < < < < < < < < < < < < < < < < < |
Modified utils/objfw-new/Makefile from [b67c1400ab] to [8cc4a388ef].
1 2 3 4 5 6 7 8 9 10 11 12 | include ../../extra.mk PROG = objfw-new${PROG_SUFFIX} SRCS = NewApp.m \ NewClass.m \ ObjFWNew.m \ Property.m include ../../buildsys.mk ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 | include ../../extra.mk PROG = objfw-new${PROG_SUFFIX} SRCS = NewApp.m \ NewClass.m \ NewTest.m \ ObjFWNew.m \ Property.m include ../../buildsys.mk ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} |
︙ | ︙ |
Added utils/objfw-new/NewTest.m version [0991f0679f].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | /* * Copyright (c) 2008-2024 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" #include <errno.h> #import "OFApplication.h" #import "OFFile.h" #import "OFStdIOStream.h" #import "OFString.h" #import "OFOpenItemFailedException.h" void newTest(OFString *name) { OFString *path = [name stringByAppendingPathExtension: @"m"]; OFFile *file = nil; @try { file = [OFFile fileWithPath: path mode: @"wx"]; } @catch (OFOpenItemFailedException *e) { if (e.errNo != EEXIST) @throw e; [OFStdErr writeFormat: @"File %@ already exists! Aborting...\n", e.path]; [OFApplication terminateWithStatus: 1]; } [file writeFormat: @"#import <ObjFW/ObjFW.h>\n" @"#import <ObjFWTest/ObjFWTest.h>\n" @"\n" @"@interface %@: OTTestCase\n" @"@end\n" @"\n" @"@implementation %@\n" @"@end\n", name, name]; [file close]; } |
Modified utils/objfw-new/ObjFWNew.m from [5f604351d2] to [0b89b26b9a].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #import "OFString.h" @interface ObjFWNew: OFObject <OFApplicationDelegate> @end extern void newApp(OFString *); extern void newClass(OFString *, OFString *, OFMutableArray *); OF_APPLICATION_DELEGATE(ObjFWNew) static void help(OFStream *stream, bool full, int status) { [stream writeFormat: | > | > < < | > > > | > | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 67 68 69 70 71 72 73 74 75 76 77 78 79 | #import "OFString.h" @interface ObjFWNew: OFObject <OFApplicationDelegate> @end extern void newApp(OFString *); extern void newClass(OFString *, OFString *, OFMutableArray *); extern void newTest(OFString *); OF_APPLICATION_DELEGATE(ObjFWNew) static void help(OFStream *stream, bool full, int status) { [stream writeFormat: @"Usage: %@ --app|--class|--test [--superclass=] [--property=] name" @"\n", [OFApplication programName]]; if (full) { [stream writeString: @"\n"]; [stream writeLine: @"Options:\n" @" -a --app Create a new app\n" @" -c --class Create a new class\n" @" -h --help Show this help\n" @" -p --property= Add a property to the class.\n" @" E.g.: --property='(readonly, " @"nonatomic) id foo'\n" @" -s --superclass= Specify the superclass for the " @"class\n" @" -t --test Create a new test\n"]; } [OFApplication terminateWithStatus: status]; } @implementation ObjFWNew - (void)applicationDidFinishLaunching: (OFNotification *)notification { bool app, class, test; OFString *superclass = nil, *name; OFMutableArray OF_GENERIC(OFString *) *properties = nil; const OFOptionsParserOption options[] = { { 'a', @"app", 0, &app, NULL }, { 'c', @"class", 0, &class, NULL }, { 'h', @"help", 0, NULL, NULL }, { 'p', @"property", 1, NULL, NULL }, { 's', @"superclass", 1, NULL, &superclass }, { 't', @"test", 0, &test, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser; OFUnichar option; if ([OFApplication arguments].count == 0) help(OFStdErr, true, 1); |
︙ | ︙ | |||
90 91 92 93 94 95 96 | case ':': case '=': help(OFStdErr, false, 1); break; } } | > | > > | 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 | case ':': case '=': help(OFStdErr, false, 1); break; } } if (app + class + test != 1 || optionsParser.remainingArguments.count != 1) help(OFStdErr, false, 1); if ((superclass && !class) || (properties != nil && !class)) help(OFStdErr, false, 1); name = optionsParser.remainingArguments.firstObject; if ([name rangeOfString: @"."].location != OFNotFound) { [OFStdErr writeLine: @"Name must not contain dots!"]; [OFApplication terminate]; } if (app) newApp(name); else if (class) newClass(name, superclass, properties); else if (test) newTest(name); else help(OFStdErr, false, 1); [OFApplication terminate]; } @end |