Index: .fossil-settings/clean-glob ================================================================== --- .fossil-settings/clean-glob +++ .fossil-settings/clean-glob @@ -24,10 +24,18 @@ configure docs extra.mk generators/library/gen_libraries generators/unicode/gen_tables +new_tests/EBOOT.PBP +new_tests/PARAM.SFO +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 Index: .fossil-settings/ignore-glob ================================================================== --- .fossil-settings/ignore-glob +++ .fossil-settings/ignore-glob @@ -26,10 +26,18 @@ configure docs extra.mk generators/library/gen_libraries generators/unicode/gen_tables +new_tests/EBOOT.PBP +new_tests/PARAM.SFO +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 Index: .gitignore ================================================================== --- .gitignore +++ .gitignore @@ -26,10 +26,18 @@ configure docs extra.mk generators/library/gen_libraries generators/unicode/gen_tables +new_tests/EBOOT.PBP +new_tests/PARAM.SFO +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 Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -1,8 +1,8 @@ include extra.mk -SUBDIRS = src utils tests +SUBDIRS = src utils tests new_tests DISTCLEAN = Info.plist \ aclocal.m4 \ autom4te.cache \ buildsys.mk \ config.h \ @@ -12,14 +12,15 @@ include buildsys.mk .PHONY: check docs release -utils tests: src +utils tests new_tests: src -check: tests +check: tests new_tests cd tests && ${MAKE} -s run + cd new_tests && ${MAKE} -s run docs: rm -fr docs doxygen >/dev/null ADDED new_tests/Makefile Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -0,0 +1,138 @@ +PROG_NOINST = tests${PROG_SUFFIX} +SRCS = OFNumberTests.m \ + OFPBKDF2Tests.m \ + OFPropertyListTests.m + +include ../buildsys.mk +include ../extra.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} + 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 +# 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/OFNumberTests.m Index: new_tests/OFNumberTests.m ================================================================== --- new_tests/OFNumberTests.m +++ new_tests/OFNumberTests.m @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFNumberTests: OTTestCase +@end + +extern unsigned long long OFHashSeed; + +@implementation OFNumberTests +- (void)testIsEqual +{ + OFNumber *number = [OFNumber numberWithLongLong: 123456789]; + OTAssertEqualObjects(number, [OFNumber numberWithLong: 123456789]); +} + +- (void)testHash +{ + unsigned long long hashSeed = OFHashSeed; + OFHashSeed = 0; + @try { + OFNumber *number = [OFNumber numberWithLongLong: 123456789]; + OTAssertEqual(number.hash, 0x82D8BC42); + } @finally { + OFHashSeed = hashSeed; + }; +} + +- (void)testCharValue +{ + OFNumber *number = [OFNumber numberWithLongLong: 123456789]; + OTAssertEqual(number.charValue, 21); +} + +- (void)testDoubleValue +{ + OFNumber *number = [OFNumber numberWithLongLong: 123456789]; + 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/OFPBKDF2Tests.m Index: new_tests/OFPBKDF2Tests.m ================================================================== --- new_tests/OFPBKDF2Tests.m +++ new_tests/OFPBKDF2Tests.m @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#include + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFPBKDF2Tests: OTTestCase +{ + OFHMAC *_HMAC; +} +@end + +@implementation OFPBKDF2Tests +- (void)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/OFPropertyListTests.m Index: new_tests/OFPropertyListTests.m ================================================================== --- new_tests/OFPropertyListTests.m +++ new_tests/OFPropertyListTests.m @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFPropertyListTests: OTTestCase +@end + +#define PLIST(x) \ + @"" \ + @"" \ + @"\n" \ + x @"\n" \ + @"" + +@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( + @"Hello") objectByParsingPropertyList], + @"Hello"); + OTAssertEqualObjects([PLIST( + @"" + @" Hello" + @" V29ybGQh" + @" 2018-03-14T12:34:56Z" + @" " + @" " + @" 12.25" + @" -10" + @"") objectByParsingPropertyList], + array); + OTAssertEqualObjects([PLIST( + @"" + @" array" + @" " + @" Hello" + @" V29ybGQh" + @" 2018-03-14T12:34:56Z" + @" " + @" " + @" 12.25" + @" -10" + @" " + @" foo" + @" bar" + @"") objectByParsingPropertyList], + ([OFDictionary dictionaryWithKeysAndObjects: + @"array", array, + @"foo", @"bar", + nil])); +} + +- (void)testDetectUnsupportedVersion +{ + bool caught = false; + @try { + [[PLIST(@"") + stringByReplacingOccurrencesOfString: @"1.0" + withString: @"1.1"] + objectByParsingPropertyList]; + } @catch (OFUnsupportedVersionException *e) { + caught = true; + } + OTAssertTrue(caught); +} + +- (void)testDetectInvalidFormat +{ + bool caught; + + caught = false; + @try { + [PLIST(@"") objectByParsingPropertyList]; + } @catch (OFInvalidFormatException *e) { + caught = true; + } + OTAssertTrue(caught); + + caught = false; + @try { + [PLIST(@"") objectByParsingPropertyList]; + } @catch (OFInvalidFormatException *e) { + caught = true; + } + OTAssertTrue(caught); + + caught = false; + @try { + [PLIST(@"") objectByParsingPropertyList]; + } @catch (OFInvalidFormatException *e) { + caught = true; + } + OTAssertTrue(caught); + + caught = false; + @try { + [PLIST(@"") + objectByParsingPropertyList]; + } @catch (OFInvalidFormatException *e) { + caught = true; + } + OTAssertTrue(caught); + + caught = false; + @try { + [PLIST(@"") + objectByParsingPropertyList]; + } @catch (OFInvalidFormatException *e) { + caught = true; + } + OTAssertTrue(caught); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -35,14 +35,11 @@ OFMD5HashTests.m \ OFMatrix4x4Tests.m \ OFMemoryStreamTests.m \ OFMethodSignatureTests.m \ OFNotificationCenterTests.m \ - OFNumberTests.m \ OFObjectTests.m \ - OFPBKDF2Tests.m \ - OFPropertyListTests.m \ OFRIPEMD160HashTests.m \ OFSHA1HashTests.m \ OFSHA224HashTests.m \ OFSHA256HashTests.m \ OFSHA384HashTests.m \ DELETED tests/OFNumberTests.m Index: tests/OFNumberTests.m ================================================================== --- tests/OFNumberTests.m +++ tests/OFNumberTests.m @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFNumber"; - -@implementation TestsAppDelegate (OFNumberTests) -- (void)numberTests -{ - void *pool = objc_autoreleasePoolPush(); - OFNumber *number; - - TEST(@"+[numberWithLongLong:]", - (number = [OFNumber numberWithLongLong: 123456789])) - - TEST(@"-[isEqual:]", - [number isEqual: [OFNumber numberWithLong: 123456789]]) - - TEST(@"-[hash]", number.hash == 0x82D8BC42) - - TEST(@"-[charValue]", number.charValue == 21) - - TEST(@"-[doubleValue]", number.doubleValue == 123456789.L) - - TEST(@"signed char minimum & maximum unmodified", - (number = [OFNumber numberWithChar: SCHAR_MIN]) && - number.charValue == SCHAR_MIN && - (number = [OFNumber numberWithChar: SCHAR_MAX]) && - number.charValue == SCHAR_MAX) - - TEST(@"short minimum & maximum unmodified", - (number = [OFNumber numberWithShort: SHRT_MIN]) && - number.shortValue == SHRT_MIN && - (number = [OFNumber numberWithShort: SHRT_MAX]) && - number.shortValue == SHRT_MAX) - - TEST(@"int minimum & maximum unmodified", - (number = [OFNumber numberWithInt: INT_MIN]) && - number.intValue == INT_MIN && - (number = [OFNumber numberWithInt: INT_MAX]) && - number.intValue == INT_MAX) - - TEST(@"long minimum & maximum unmodified", - (number = [OFNumber numberWithLong: LONG_MIN]) && - number.longValue == LONG_MIN && - (number = [OFNumber numberWithLong: LONG_MAX]) && - number.longValue == LONG_MAX) - - TEST(@"long long minimum & maximum unmodified", - (number = [OFNumber numberWithLongLong: LLONG_MIN]) && - number.longLongValue == LLONG_MIN && - (number = [OFNumber numberWithLongLong: LLONG_MAX]) && - number.longLongValue == LLONG_MAX) - - TEST(@"unsigned char maximum unmodified", - (number = [OFNumber numberWithUnsignedChar: UCHAR_MAX]) && - number.unsignedCharValue == UCHAR_MAX) - - TEST(@"unsigned short maximum unmodified", - (number = [OFNumber numberWithUnsignedShort: USHRT_MAX]) && - number.unsignedShortValue == USHRT_MAX) - - TEST(@"unsigned int maximum unmodified", - (number = [OFNumber numberWithUnsignedInt: UINT_MAX]) && - number.unsignedIntValue == UINT_MAX) - - TEST(@"unsigned long maximum unmodified", - (number = [OFNumber numberWithUnsignedLong: ULONG_MAX]) && - number.unsignedLongValue == ULONG_MAX) - - TEST(@"unsigned long long maximum unmodified", - (number = [OFNumber numberWithUnsignedLongLong: ULLONG_MAX]) && - number.unsignedLongLongValue == ULLONG_MAX) - - objc_autoreleasePoolPop(pool); -} -@end DELETED tests/OFPBKDF2Tests.m Index: tests/OFPBKDF2Tests.m ================================================================== --- tests/OFPBKDF2Tests.m +++ tests/OFPBKDF2Tests.m @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#include - -#import "TestsAppDelegate.h" - -static OFString *const module = @"OFPBKDF2"; - -@implementation TestsAppDelegate (OFPBKDF2Tests) -- (void)PBKDF2Tests -{ - void *pool = objc_autoreleasePoolPush(); - OFHMAC *HMAC = [OFHMAC HMACWithHashClass: [OFSHA1Hash class] - allowsSwappableMemory: true]; - unsigned char key[25]; - - /* Test vectors from RFC 6070 */ - - TEST(@"PBKDF2-SHA1, 1 iteration", - R(OFPBKDF2((OFPBKDF2Parameters){ - .HMAC = HMAC, - .iterations = 1, - .salt = (unsigned char *)"salt", - .saltLength = 4, - .password = "password", - .passwordLength = 8, - .key = key, - .keyLength = 20, - .allowsSwappableMemory = true - })) && memcmp(key, "\x0C\x60\xC8\x0F\x96\x1F\x0E\x71\xF3\xA9\xB5" - "\x24\xAF\x60\x12\x06\x2F\xE0\x37\xA6", 20) == 0) - - TEST(@"PBKDF2-SHA1, 2 iterations", - R(OFPBKDF2((OFPBKDF2Parameters){ - .HMAC = HMAC, - .iterations = 2, - .salt = (unsigned char *)"salt", - .saltLength = 4, - .password = "password", - .passwordLength = 8, - .key = key, - .keyLength = 20, - .allowsSwappableMemory = true - })) && memcmp(key, "\xEA\x6C\x01\x4D\xC7\x2D\x6F\x8C\xCD\x1E\xD9" - "\x2A\xCE\x1D\x41\xF0\xD8\xDE\x89\x57", 20) == 0) - - TEST(@"PBKDF2-SHA1, 4096 iterations", - R(OFPBKDF2((OFPBKDF2Parameters){ - .HMAC = HMAC, - .iterations = 4096, - .salt = (unsigned char *)"salt", - .saltLength = 4, - .password = "password", - .passwordLength = 8, - .key = key, - .keyLength = 20, - .allowsSwappableMemory = true - })) && memcmp(key, "\x4B\x00\x79\x01\xB7\x65\x48\x9A\xBE\xAD\x49" - "\xD9\x26\xF7\x21\xD0\x65\xA4\x29\xC1", 20) == 0) - - /* This test takes too long, even on a fast machine. */ -#if 0 - TEST(@"PBKDF2-SHA1, 16777216 iterations", - R(OFPBKDF2((OFPBKDF2Parameters){ - .HMAC = HMAC, - .iterations = 16777216, - .salt = (unsigned char *)"salt", - .saltLength = 4, - .password = "password", - .passwordLength = 8, - .key = key, - .keyLength = 20, - .allowsSwappableMemory = true - })) && 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 - - TEST(@"PBKDF2-SHA1, 4096 iterations, key > 1 block", - R(OFPBKDF2((OFPBKDF2Parameters){ - .HMAC = HMAC, - .iterations = 4096, - .salt = (unsigned char *)"saltSALTsaltSALTsalt" - "SALTsaltSALTsalt", - .saltLength = 36, - .password = "passwordPASSWORDpassword", - .passwordLength = 24, - .key = key, - .keyLength = 25, - .allowsSwappableMemory = true - })) && - 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) - - TEST(@"PBKDF2-SHA1, 4096 iterations, key < 1 block", - R(OFPBKDF2((OFPBKDF2Parameters){ - .HMAC = HMAC, - .iterations = 4096, - .salt = (unsigned char *)"sa\0lt", - .saltLength = 5, - .password = "pass\0word", - .passwordLength = 9, - .key = key, - .keyLength = 16, - .allowsSwappableMemory = true - })) && memcmp(key, "\x56\xFA\x6A\xA7\x55\x48\x09\x9D\xCC\x37\xD7" - "\xF0\x34\x25\xE0\xC3", 16) == 0) - - objc_autoreleasePoolPop(pool); -} -@end DELETED tests/OFPropertyListTests.m Index: tests/OFPropertyListTests.m ================================================================== --- tests/OFPropertyListTests.m +++ tests/OFPropertyListTests.m @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "TestsAppDelegate.h" - -#define PLIST(x) \ - @"" \ - @"" \ - @"\n" \ - x @"\n" \ - @"" - -static OFString *const module = @"OFPropertyList"; -static OFString *const PLIST1 = PLIST(@"Hello"); -static OFString *const PLIST2 = PLIST( - @"" - @" Hello" - @" V29ybGQh" - @" 2018-03-14T12:34:56Z" - @" " - @" " - @" 12.25" - @" -10" - @""); -static OFString *const PLIST3 = PLIST( - @"" - @" array" - @" " - @" Hello" - @" V29ybGQh" - @" 2018-03-14T12:34:56Z" - @" " - @" " - @" 12.25" - @" -10" - @" " - @" foo" - @" bar" - @""); - -@implementation TestsAppDelegate (OFPLISTParser) -- (void)propertyListTests -{ - void *pool = objc_autoreleasePoolPush(); - 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]; - - TEST(@"-[objectByParsingPropertyList:] #1", - [PLIST1.objectByParsingPropertyList isEqual: @"Hello"]) - - TEST(@"-[objectByParsingPropertyList:] #2", - [PLIST2.objectByParsingPropertyList isEqual: array]) - - TEST(@"-[objectByParsingPropertyList:] #3", - [PLIST3.objectByParsingPropertyList isEqual: - [OFDictionary dictionaryWithKeysAndObjects: - @"array", array, - @"foo", @"bar", - nil]]) - - EXPECT_EXCEPTION(@"Detecting unsupported version", - OFUnsupportedVersionException, - [[PLIST(@"") stringByReplacingOccurrencesOfString: @"1.0" - withString: @"1.1"] - objectByParsingPropertyList]) - - EXPECT_EXCEPTION( - @"-[objectByParsingPropertyList] detecting invalid format #1", - OFInvalidFormatException, - [PLIST(@"") objectByParsingPropertyList]) - - EXPECT_EXCEPTION( - @"-[objectByParsingPropertyList] detecting invalid format #2", - OFInvalidFormatException, - [PLIST(@"") objectByParsingPropertyList]) - - EXPECT_EXCEPTION( - @"-[objectByParsingPropertyList] detecting invalid format #3", - OFInvalidFormatException, - [PLIST(@"") objectByParsingPropertyList]) - - EXPECT_EXCEPTION( - @"-[objectByParsingPropertyList] detecting invalid format #4", - OFInvalidFormatException, - [PLIST(@"") - objectByParsingPropertyList]) - - EXPECT_EXCEPTION( - @"-[objectByParsingPropertyList] detecting invalid format #5", - OFInvalidFormatException, - [PLIST(@"") - objectByParsingPropertyList]) - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -165,26 +165,14 @@ @interface TestsAppDelegate (OFNotificationCenterTests) - (void)notificationCenterTests; @end -@interface TestsAppDelegate (OFNumberTests) -- (void)numberTests; -@end - @interface TestsAppDelegate (OFObjectTests) - (void)objectTests; @end -@interface TestsAppDelegate (OFPBKDF2Tests) -- (void)PBKDF2Tests; -@end - -@interface TestsAppDelegate (OFPropertyListTests) -- (void)propertyListTests; -@end - @interface TestsAppDelegate (OFPluginTests) - (void)pluginTests; @end @interface TestsAppDelegate (RuntimeTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -388,11 +388,10 @@ [self dictionaryTests]; [self listTests]; [self setTests]; [self dateTests]; [self valueTests]; - [self numberTests]; [self colorTests]; [self streamTests]; [self memoryStreamTests]; [self notificationCenterTests]; [self MD5HashTests]; @@ -401,11 +400,10 @@ [self SHA224HashTests]; [self SHA256HashTests]; [self SHA384HashTests]; [self SHA512HashTests]; [self HMACTests]; - [self PBKDF2Tests]; [self scryptTests]; #ifdef HAVE_CODEPAGE_437 [self INIFileTests]; #endif #ifdef OF_HAVE_SOCKETS @@ -439,11 +437,10 @@ #endif [self XMLParserTests]; [self XMLNodeTests]; [self XMLElementBuilderTests]; [self JSONTests]; - [self propertyListTests]; [self matrix4x4Tests]; #ifdef OF_HAVE_PLUGINS [self pluginTests]; #endif