Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -11,10 +11,11 @@ testfile_bin.m \ testfile_ini.m PROG_NOINST = tests${PROG_SUFFIX} SRCS = OFASN1DERParsingTests.m \ + OFASN1DERRepresentationTests.m \ OFArrayTests.m \ OFCharacterSetTests.m \ OFColorTests.m \ OFConcreteArrayTests.m \ OFConcreteMutableArrayTests.m \ ADDED new_tests/OFASN1DERRepresentationTests.m Index: new_tests/OFASN1DERRepresentationTests.m ================================================================== --- new_tests/OFASN1DERRepresentationTests.m +++ new_tests/OFASN1DERRepresentationTests.m @@ -0,0 +1,63 @@ +/* + * 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 OFASN1DERRepresentationTests: OTTestCase +@end + +@implementation OFASN1DERRepresentationTests +- (void)testBitString +{ + OFData *data; + + data = [OFData dataWithItems: "\xFF\x00\xF8" count: 3]; + OTAssertEqualObjects([[OFASN1BitString + bitStringWithBitString: data + length: 21] ASN1DERRepresentation], + [OFData dataWithItems: "\x03\x04\x03\xFF\x00\xF8" count: 6]); + + data = [OFData dataWithItems: "abcdefäöü" count: 12]; + OTAssertEqualObjects([[OFASN1BitString + bitStringWithBitString: data + length: 12 * 8] ASN1DERRepresentation], + [OFData dataWithItems: "\x03\x0D\x00" "abcdefäöü" count: 15]); + + OTAssertEqualObjects([[OFASN1BitString + bitStringWithBitString: [OFData data] + length: 0] ASN1DERRepresentation], + [OFData dataWithItems: "\x03\x01\x00" count: 3]); +} + +- (void)testInteger +{ + OTAssertEqualObjects( + [[OFNumber numberWithBool: false] ASN1DERRepresentation], + [OFData dataWithItems: "\x01\x01\x00" count: 3]); + + OTAssertEqualObjects( + [[OFNumber numberWithBool: true] ASN1DERRepresentation], + [OFData dataWithItems: "\x01\x01\xFF" count: 3]); +} + +- (void)testNull +{ + OTAssertEqualObjects([[OFNull null] ASN1DERRepresentation], + [OFData dataWithItems: "\x05\x00" count: 2]); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -12,11 +12,10 @@ DISTCLEAN = Info.plist PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} SRCS = ForwardingTests.m \ - OFASN1DERRepresentationTests.m \ ${OF_BLOCK_TESTS_M} \ OFDataTests.m \ OFDictionaryTests.m \ OFListTests.m \ OFLocaleTests.m \ DELETED tests/OFASN1DERRepresentationTests.m Index: tests/OFASN1DERRepresentationTests.m ================================================================== --- tests/OFASN1DERRepresentationTests.m +++ tests/OFASN1DERRepresentationTests.m @@ -1,57 +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 *module; - -@implementation TestsAppDelegate (OFASN1DERRepresentationTests) -- (void)ASN1DERRepresentationTests -{ - void *pool = objc_autoreleasePoolPush(); - OFData *data; - - module = @"OFASN1BitString"; - TEST(@"-[ASN1DERRepresentation]", - (data = [OFData dataWithItems: "\xFF\x00\xF8" count: 3]) && - [[[OFASN1BitString bitStringWithBitString: data length: 21] - ASN1DERRepresentation] isEqual: - [OFData dataWithItems: "\x03\x04\x03\xFF\x00\xF8" count: 6]] && - (data = [OFData dataWithItems: "abcdefäöü" count: 12]) && - [[[OFASN1BitString bitStringWithBitString: data length: 12 * 8] - ASN1DERRepresentation] isEqual: - [OFData dataWithItems: "\x03\x0D\x00" "abcdefäöü" count: 15]] && - (data = [OFData dataWithItems: "" count: 0]) && - [[[OFASN1BitString bitStringWithBitString: data length: 0] - ASN1DERRepresentation] isEqual: - [OFData dataWithItems: "\x03\x01\x00" count: 3]]) - - module = @"OFNumber"; - TEST(@"-[ASN1DERRepresentation] for bool", - [[[OFNumber numberWithBool: false] ASN1DERRepresentation] - isEqual: [OFData dataWithItems: "\x01\x01\x00" count: 3]] && - [[[OFNumber numberWithBool: true] ASN1DERRepresentation] - isEqual: [OFData dataWithItems: "\x01\x01\xFF" count: 3]]) - - module = @"OFNull"; - TEST(@"-[OFASN1DERRepresentation]", - [[[OFNull null] ASN1DERRepresentation] isEqual: - [OFData dataWithItems: "\x05\x00" count: 2]]) - - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -57,14 +57,10 @@ - (void)outputTesting: (OFString *)test inModule: (OFString *)module; - (void)outputSuccess: (OFString *)test inModule: (OFString *)module; - (void)outputFailure: (OFString *)test inModule: (OFString *)module; @end -@interface TestsAppDelegate (OFASN1DERRepresentationTests) -- (void)ASN1DERRepresentationTests; -@end - @interface TestsAppDelegate (OFBlockTests) - (void)blockTests; @end @interface TestsAppDelegate (OFDDPSocketTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -413,11 +413,10 @@ [self HTTPCookieManagerTests]; #endif [self XMLParserTests]; [self XMLNodeTests]; [self XMLElementBuilderTests]; - [self ASN1DERRepresentationTests]; #ifdef OF_WINDOWS [self windowsRegistryKeyTests]; #endif