@@ -21,19 +21,19 @@ # include #endif #import "TestsAppDelegate.h" -static OFString *module = @"OFMethodSignature"; +static OFString *const module = @"OFMethodSignature"; -struct test1_struct { +struct Test1Struct { char c; int i; char d; }; -struct test2_struct { +struct Test2Struct { char c; struct { short s; int i; } st; @@ -43,23 +43,23 @@ } u; double d; }; #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) -struct test3_struct { +struct Test3Struct { char c; complex double cd; }; #endif -union test3_union { +union Test3Union { char c; int i; double d; }; -union test4_union { +union Test4Union { char c; struct { short x, y; } st; int i; @@ -71,38 +71,42 @@ @implementation TestsAppDelegate (OFMethodSignatureTests) - (void)methodSignatureTests { void *pool = objc_autoreleasePoolPush(); - OFMethodSignature *ms; + OFMethodSignature *methodSignature; TEST(@"-[signatureWithObjCTypes:] #1", - (ms = [OFMethodSignature signatureWithObjCTypes: - "i28@0:8S16*20"]) && ms.numberOfArguments == 4 && - strcmp(ms.methodReturnType, "i") == 0 && - strcmp([ms argumentTypeAtIndex: 0], "@") == 0 && - strcmp([ms argumentTypeAtIndex: 1], ":") == 0 && - strcmp([ms argumentTypeAtIndex: 2], "S") == 0 && - strcmp([ms argumentTypeAtIndex: 3], "*") == 0 && - ms.frameLength == 28 && [ms argumentOffsetAtIndex: 0] == 0 && - [ms argumentOffsetAtIndex: 1] == 8 && - [ms argumentOffsetAtIndex: 2] == 16 && - [ms argumentOffsetAtIndex: 3] == 20) + (methodSignature = [OFMethodSignature signatureWithObjCTypes: + "i28@0:8S16*20"]) && + methodSignature.numberOfArguments == 4 && + strcmp(methodSignature.methodReturnType, "i") == 0 && + strcmp([methodSignature argumentTypeAtIndex: 0], "@") == 0 && + strcmp([methodSignature argumentTypeAtIndex: 1], ":") == 0 && + strcmp([methodSignature argumentTypeAtIndex: 2], "S") == 0 && + strcmp([methodSignature argumentTypeAtIndex: 3], "*") == 0 && + methodSignature.frameLength == 28 && + [methodSignature argumentOffsetAtIndex: 0] == 0 && + [methodSignature argumentOffsetAtIndex: 1] == 8 && + [methodSignature argumentOffsetAtIndex: 2] == 16 && + [methodSignature argumentOffsetAtIndex: 3] == 20) TEST(@"-[signatureWithObjCTypes:] #2", - (ms = [OFMethodSignature signatureWithObjCTypes: + (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"]) && - ms.numberOfArguments == 3 && strcmp(ms.methodReturnType, + methodSignature.numberOfArguments == 3 && + strcmp(methodSignature.methodReturnType, "{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}") == 0 && - strcmp([ms argumentTypeAtIndex: 0], "@") == 0 && - strcmp([ms argumentTypeAtIndex: 1], ":") == 0 && - strcmp([ms argumentTypeAtIndex: 2], + strcmp([methodSignature argumentTypeAtIndex: 0], "@") == 0 && + strcmp([methodSignature argumentTypeAtIndex: 1], ":") == 0 && + strcmp([methodSignature argumentTypeAtIndex: 2], "^{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}") == 0 && - ms.frameLength == 24 && [ms argumentOffsetAtIndex: 0] == 0 && - [ms argumentOffsetAtIndex: 1] == 8 && - [ms argumentOffsetAtIndex: 2] == 16) + methodSignature.frameLength == 24 && + [methodSignature argumentOffsetAtIndex: 0] == 0 && + [methodSignature argumentOffsetAtIndex: 1] == 8 && + [methodSignature argumentOffsetAtIndex: 2] == 16) EXPECT_EXCEPTION(@"-[signatureWithObjCTypes:] #3", OFInvalidFormatException, [OFMethodSignature signatureWithObjCTypes: "{ii"]) @@ -116,62 +120,62 @@ EXPECT_EXCEPTION(@"-[signatureWithObjCTypes:] #6", OFInvalidFormatException, [OFMethodSignature signatureWithObjCTypes: "{{}0"]) - TEST(@"of_sizeof_type_encoding() #1", - of_sizeof_type_encoding(@encode(struct test1_struct)) == - sizeof(struct test1_struct)) - - TEST(@"of_sizeof_type_encoding() #2", - of_sizeof_type_encoding(@encode(struct test2_struct)) == - sizeof(struct test2_struct)) - -#if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) && \ - OF_GCC_VERSION >= 402 - TEST(@"of_sizeof_type_encoding() #3", - of_sizeof_type_encoding(@encode(struct test3_struct)) == - sizeof(struct test3_struct)) -#endif - - TEST(@"of_sizeof_type_encoding() #4", - of_sizeof_type_encoding(@encode(union test3_union)) == - sizeof(union test3_union)) - - TEST(@"of_sizeof_type_encoding() #5", - of_sizeof_type_encoding(@encode(union test4_union)) == - sizeof(union test4_union)) - - TEST(@"of_sizeof_type_encoding() #6", - of_sizeof_type_encoding(@encode(struct test1_struct [5])) == - sizeof(struct test1_struct [5])) - - TEST(@"of_alignof_type_encoding() #1", - of_alignof_type_encoding(@encode(struct test1_struct)) == - OF_ALIGNOF(struct test1_struct)) - - TEST(@"of_alignof_type_encoding() #2", - of_alignof_type_encoding(@encode(struct test2_struct)) == - OF_ALIGNOF(struct test2_struct)) - -#if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) && \ - OF_GCC_VERSION >= 402 - TEST(@"of_alignof_type_encoding() #3", - of_alignof_type_encoding(@encode(struct test3_struct)) == - OF_ALIGNOF(struct test3_struct)) -#endif - - TEST(@"of_alignof_type_encoding() #4", - of_alignof_type_encoding(@encode(union test3_union)) == - OF_ALIGNOF(union test3_union)) - - TEST(@"of_alignof_type_encoding() #5", - of_alignof_type_encoding(@encode(union test4_union)) == - OF_ALIGNOF(union test4_union)) - - TEST(@"of_alignof_type_encoding() #6", - of_alignof_type_encoding(@encode(struct test1_struct [5])) == - OF_ALIGNOF(struct test1_struct [5])) + TEST(@"OFSizeOfTypeEncoding() #1", + OFSizeOfTypeEncoding(@encode(struct Test1Struct)) == + sizeof(struct Test1Struct)) + + TEST(@"OFSizeOfTypeEncoding() #2", + OFSizeOfTypeEncoding(@encode(struct Test2Struct)) == + sizeof(struct Test2Struct)) + +#if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) && \ + OF_GCC_VERSION >= 402 + TEST(@"OFSizeOfTypeEncoding() #3", + OFSizeOfTypeEncoding(@encode(struct Test3Struct)) == + sizeof(struct Test3Struct)) +#endif + + TEST(@"OFSizeOfTypeEncoding() #4", + OFSizeOfTypeEncoding(@encode(union Test3Union)) == + sizeof(union Test3Union)) + + TEST(@"OFSizeOfTypeEncoding() #5", + OFSizeOfTypeEncoding(@encode(union Test4Union)) == + sizeof(union Test4Union)) + + TEST(@"OFSizeOfTypeEncoding() #6", + OFSizeOfTypeEncoding(@encode(struct Test1Struct [5])) == + sizeof(struct Test1Struct [5])) + + TEST(@"OFAlignmentOfTypeEncoding() #1", + OFAlignmentOfTypeEncoding(@encode(struct Test1Struct)) == + OF_ALIGNOF(struct Test1Struct)) + + TEST(@"OFAlignmentOfTypeEncoding() #2", + OFAlignmentOfTypeEncoding(@encode(struct Test2Struct)) == + OF_ALIGNOF(struct Test2Struct)) + +#if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) && \ + OF_GCC_VERSION >= 402 + TEST(@"OFAlignmentOfTypeEncoding() #3", + OFAlignmentOfTypeEncoding(@encode(struct Test3Struct)) == + OF_ALIGNOF(struct Test3Struct)) +#endif + + TEST(@"OFAlignmentOfTypeEncoding() #4", + OFAlignmentOfTypeEncoding(@encode(union Test3Union)) == + OF_ALIGNOF(union Test3Union)) + + TEST(@"OFAlignmentOfTypeEncoding() #5", + OFAlignmentOfTypeEncoding(@encode(union Test4Union)) == + OF_ALIGNOF(union Test4Union)) + + TEST(@"OFAlignmentOfTypeEncoding() #6", + OFAlignmentOfTypeEncoding(@encode(struct Test1Struct [5])) == + OF_ALIGNOF(struct Test1Struct [5])) objc_autoreleasePoolPop(pool); } @end