Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -50,10 +50,11 @@ RuntimeTests.m \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ + ${USE_SRCS_WINDOWS} \ testfile_bin.m \ testfile_ini.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ OFSocketTests.m \ @@ -68,10 +69,11 @@ OFSPXStreamSocketTests.m SRCS_UNIX_SOCKETS = OFUNIXDatagramSocketTests.m \ OFUNIXStreamSocketTests.m SRCS_SUBPROCESSES = OFSubprocessTests.m SRCS_THREADS = OFThreadTests.m +SRCS_WINDOWS = OFWindowsRegistryKeyTests.m include ../buildsys.mk testfile_bin.m: testfile.bin ${SHELL} ../utils/objfw-embed testfile.bin testfile.bin $@ ADDED new_tests/OFWindowsRegistryKeyTests.m Index: new_tests/OFWindowsRegistryKeyTests.m ================================================================== --- new_tests/OFWindowsRegistryKeyTests.m +++ new_tests/OFWindowsRegistryKeyTests.m @@ -0,0 +1,127 @@ +/* + * 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 OFWindowsRegistryKeyTests: OTTestCase +{ + OFWindowsRegistryKey *_softwareKey, *_objFWKey; +} +@end + +@implementation OFWindowsRegistryKeyTests +- (void)setUp +{ + [super setUp]; + + _softwareKey = [[[OFWindowsRegistryKey currentUserKey] + openSubkeyAtPath: @"Software" + accessRights: KEY_ALL_ACCESS + options: 0] retain]; + _objFWKey = [[_softwareKey createSubkeyAtPath: @"ObjFW" + accessRights: KEY_ALL_ACCESS + securityAttributes: NULL + options: 0 + disposition: NULL] retain]; +} + +- (void)tearDown +{ + [_softwareKey deleteSubkeyAtPath: @"ObjFW"]; + + [super tearDown]; +} + +- (void)dealloc +{ + [_softwareKey release]; + [_objFWKey release]; + + [super dealloc]; +} + +- (void)testClassesRootKey +{ + OTAssertEqual([[OFWindowsRegistryKey classesRootKey] class], + [OFWindowsRegistryKey class]); +} + +- (void)testCurrentConfigKey +{ + OTAssertEqual([[OFWindowsRegistryKey currentConfigKey] class], + [OFWindowsRegistryKey class]); +} + +- (void)testCurrentUserKey +{ + OTAssertEqual([[OFWindowsRegistryKey currentUserKey] class], + [OFWindowsRegistryKey class]); +} + +- (void)testLocalMachineKey +{ + OTAssertEqual([[OFWindowsRegistryKey localMachineKey] class], + [OFWindowsRegistryKey class]); +} + +- (void)testOpenSubkeyAtPathAccessRightsOptionsThrowsForNonExistentKey +{ + OTAssertThrowsSpecific([[OFWindowsRegistryKey currentUserKey] + openSubkeyAtPath: @"nonexistent" + accessRights: KEY_ALL_ACCESS + options: 0], OFOpenWindowsRegistryKeyFailedException); +} + +- (void)testSetAndGetData +{ + OFData *data = [OFData dataWithItems: "abcdef" count: 6]; + DWORD type; + + [_objFWKey setData: data forValueNamed: @"data" type: REG_BINARY]; + OTAssertEqualObjects([_objFWKey dataForValueNamed: @"data" type: &type], + data); + OTAssertEqual(type, REG_BINARY); +} + +- (void)testSetAndGetString +{ + DWORD type; + + [_objFWKey setString: @"foobar" forValueNamed: @"string"]; + OTAssertEqualObjects([_objFWKey stringForValueNamed: @"string"], + @"foobar"); + + [_objFWKey setString: @"%PATH%;foo" + forValueNamed: @"expand" + type: REG_EXPAND_SZ]; + OTAssertEqualObjects([_objFWKey stringForValueNamed: @"expand" + type: &type], + @"%PATH%;foo"); + OTAssertEqual(type, REG_EXPAND_SZ); +} + +- (void)testDeleteValue +{ + [_objFWKey setString: @"foobar" forValueNamed: @"deleteme"]; + OTAssertEqualObjects([_objFWKey stringForValueNamed: @"deleteme"], + @"foobar"); + + [_objFWKey deleteValueNamed: @"deleteme"]; + OTAssertNil([_objFWKey stringForValueNamed: @"deleteme"]); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -21,17 +21,15 @@ OFValueTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ - ${USE_SRCS_SOCKETS} \ - ${USE_SRCS_WINDOWS} + ${USE_SRCS_SOCKETS} 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 DELETED tests/OFWindowsRegistryKeyTests.m Index: tests/OFWindowsRegistryKeyTests.m ================================================================== --- tests/OFWindowsRegistryKeyTests.m +++ tests/OFWindowsRegistryKeyTests.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 = @"OFWindowsRegistryKey"; - -@implementation TestsAppDelegate (OFWindowsRegistryKeyTests) -- (void)windowsRegistryKeyTests -{ - void *pool = objc_autoreleasePoolPush(); - OFData *data = [OFData dataWithItems: "abcdef" count: 6]; - OFWindowsRegistryKey *softwareKey, *objFWKey; - DWORD type; - - TEST(@"+[OFWindowsRegistryKey classesRootKey]", - [OFWindowsRegistryKey classesRootKey]) - - TEST(@"+[OFWindowsRegistryKey currentConfigKey]", - [OFWindowsRegistryKey currentConfigKey]) - - TEST(@"+[OFWindowsRegistryKey currentUserKey]", - [OFWindowsRegistryKey currentUserKey]) - - TEST(@"+[OFWindowsRegistryKey localMachineKey]", - [OFWindowsRegistryKey localMachineKey]) - - TEST(@"+[OFWindowsRegistryKey usersKey]", - [OFWindowsRegistryKey usersKey]) - - TEST(@"-[openSubkeyAtPath:accessRights:options:] #1", - (softwareKey = [[OFWindowsRegistryKey currentUserKey] - openSubkeyAtPath: @"Software" - accessRights: KEY_ALL_ACCESS - options: 0])) - - EXPECT_EXCEPTION(@"-[openSubkeyAtPath:accessRights:options:] #2", - OFOpenWindowsRegistryKeyFailedException, - [[OFWindowsRegistryKey currentUserKey] - openSubkeyAtPath: @"nonexistent" - accessRights: KEY_ALL_ACCESS - options: 0]) - - TEST(@"-[createSubkeyAtPath:accessRights:securityAttributes:options:" - @"disposition:]", - (objFWKey = [softwareKey createSubkeyAtPath: @"ObjFW" - accessRights: KEY_ALL_ACCESS - securityAttributes: NULL - options: 0 - disposition: NULL])) - - TEST(@"-[setData:forValueNamed:type:]", - R([objFWKey setData: data forValueNamed: @"data" type: REG_BINARY])) - - TEST(@"-[dataForValueNamed:subkeyPath:flags:type:]", - [[objFWKey dataForValueNamed: @"data" type: &type] isEqual: data] && - type == REG_BINARY) - - TEST(@"-[setString:forValueNamed:type:]", - R([objFWKey setString: @"foobar" forValueNamed: @"string"]) && - R([objFWKey setString: @"%PATH%;foo" - forValueNamed: @"expand" - type: REG_EXPAND_SZ])) - - TEST(@"-[stringForValue:subkeyPath:]", - [[objFWKey stringForValueNamed: @"string"] isEqual: @"foobar"] && - [[objFWKey stringForValueNamed: @"expand" type: &type] - isEqual: @"%PATH%;foo"] && - type == REG_EXPAND_SZ) - - TEST(@"-[deleteValueNamed:]", R([objFWKey deleteValueNamed: @"data"])) - - TEST(@"-[deleteSubkeyAtPath:]", - R([softwareKey deleteSubkeyAtPath: @"ObjFW"])) - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -97,17 +97,13 @@ @interface TestsAppDelegate (OFValueTests) - (void)valueTests; @end -@interface TestsAppDelegate (OFWindowsRegistryKeyTests) -- (void)windowsRegistryKeyTests; -@end - @interface TestsAppDelegate (OFXMLNodeTests) - (void)XMLNodeTests; @end @interface TestsAppDelegate (OFXMLParserTests) - (void)XMLParserTests; @end Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -387,14 +387,10 @@ [self HTTPCookieManagerTests]; #endif [self XMLParserTests]; [self XMLNodeTests]; -#ifdef OF_WINDOWS - [self windowsRegistryKeyTests]; -#endif - [OFStdOut reset]; #if defined(OF_IOS) [OFStdOut writeFormat: @"%d tests failed!", _fails]; [OFApplication terminateWithStatus: _fails];