]>
git.saurik.com Git - apple/security.git/blob - OSX/utilities/Regressions/su-05-cfwrappers.c
2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 #include <utilities/SecCFRelease.h>
26 #include <utilities/SecCFWrappers.h>
27 #include <utilities/SecIOFormat.h>
29 #include "utilities_regressions.h"
31 #define kCFWrappersTestCount 25
33 static CFDataRef
*testCopyDataPtr(void) {
34 static CFDataRef sData
= NULL
;
36 sData
= CFDataCreate(kCFAllocatorDefault
, NULL
, 0);
43 test_object(CFDataRef data
) {
44 CFDataRef myData
= CFRetainSafe(data
);
45 ok(CFEqual(myData
, data
), "");
46 is(CFGetRetainCount(myData
), 2, "");
47 ok(CFReleaseNull(myData
) == ((CFDataRef
)(0)), "");
50 is(CFGetRetainCount(data
), 1);
51 CFRetainAssign(myData
, data
);
52 is(CFGetRetainCount(data
), 2);
53 CFRetainAssign(myData
, data
);
54 is(CFGetRetainCount(data
), 2);
55 CFRetainAssign(myData
, NULL
);
56 is(CFGetRetainCount(data
), 1);
59 CFDataRef
*pData
= testCopyDataPtr();
60 is(CFGetRetainCount(*pData
), 1);
61 CFDataRef objects
[10] = {}, *object
= objects
;
63 CFRetainAssign(*testCopyDataPtr(), *object
++);
64 is(CFGetRetainCount(*pData
), 2, "CFRetainAssign evaluates it's first argument argument %" PRIdCFIndex
" times", CFGetRetainCount(*pData
) - 1);
65 is(object
- objects
, 1, "CFRetainAssign evaluates it's second argument %td times", object
- objects
);
67 is(CFGetRetainCount(data
), 1);
68 CFAssignRetained(myData
, data
);
69 is(CFGetRetainCount(myData
), 1);
74 CFTypeRef nullObject1
= NULL
;
75 CFTypeRef nullObject2
= NULL
;
77 nullObject1
= CFRetainSafe(NULL
);
79 is(nullObject1
, NULL
, "");
80 is(CFReleaseNull(nullObject1
), NULL
, "CFReleaseNull(nullObject1) returned");
81 is(nullObject1
, NULL
);
82 is(CFReleaseSafe(nullObject1
), NULL
, "CFReleaseSafe(nullObject1) returned");
83 is(CFReleaseSafe(NULL
), NULL
, "CFReleaseSafe(NULL)");
84 is(CFReleaseNull(nullObject2
), NULL
, "CFReleaseNull(nullObject2) returned");
85 is(nullObject2
, NULL
, "nullObject2 still NULL");
87 CFRetainAssign(nullObject2
, nullObject1
);
89 CFTypeRef
*object
, objects
[10] = {};
92 CFRetainSafe(*object
++);
93 is(object
- objects
, 1, "CFRetainSafe evaluates it's argument %td times", object
- objects
);
96 CFReleaseSafe(*object
++);
97 is(object
- objects
, 1, "CFReleaseSafe evaluates it's argument %td times", object
- objects
);
100 CFReleaseNull(*object
++);
101 is(object
- objects
, 1, "CFReleaseNull evaluates it's argument %td times", object
- objects
);
105 su_05_cfwrappers(int argc
, char *const *argv
) {
106 plan_tests(kCFWrappersTestCount
);
109 CFDataRef data
= CFDataCreate(kCFAllocatorDefault
, NULL
, 0);
112 ok(data
== NULL
, "data is NULL now");