2 * Copyright (c) 2012,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/der_plist.h"
26 #include "utilities/der_plist_internal.h"
28 #include "utilities/SecCFRelease.h"
29 #include "utilities/array_size.h"
31 #include <CoreFoundation/CoreFoundation.h>
33 #include "utilities_regressions.h"
35 #define kMaxResultSize 16
37 #define kTestsPerTestCase 8
38 static void one_test(CFBooleanRef value
, size_t der_size
, const uint8_t *expected_der
)
41 uint8_t buffer
[kMaxResultSize
];
42 uint8_t *buffer_end
= buffer
+ sizeof(buffer
);
44 uint8_t* encoded
= der_encode_plist(value
, NULL
, buffer
, buffer_end
);
47 (der_size
== (buffer_end
- encoded
)) &&
48 (memcmp(encoded
, expected_der
, der_size
) == 0));
50 encoded
= der_encode_boolean(value
, NULL
, buffer
, buffer_end
);
53 (der_size
== (buffer_end
- encoded
)) &&
54 (memcmp(encoded
, expected_der
, der_size
) == 0));
57 printf(".size = %d, .res = { ", (buffer_end
- encoded
));
58 for(int c
= 0; c
< (buffer_end
- encoded
); ++c
)
59 printf("0x%02X, ", encoded
[c
]);
63 CFBooleanRef decoded
= NULL
;
64 const uint8_t* decode_end
= der_decode_boolean(NULL
, kCFPropertyListMutableContainersAndLeaves
,
65 &decoded
, NULL
, encoded
, buffer_end
);
67 ok(decode_end
== buffer_end
);
68 ok((decoded
!= NULL
) && CFEqual(decoded
, value
));
70 CFPropertyListRef decoded_type
= NULL
;
71 decode_end
= der_decode_plist(NULL
, kCFPropertyListMutableContainersAndLeaves
,
72 &decoded_type
, NULL
, encoded
, buffer_end
);
74 ok(decode_end
== buffer_end
);
75 ok((decoded
!= NULL
) && CFEqual(decoded_type
, value
));
77 ok(der_sizeof_boolean(value
, NULL
) == der_size
);
78 ok(der_sizeof_plist(value
, NULL
) == der_size
);
80 CFReleaseNull(decoded
);
81 CFReleaseNull(decoded_type
);
84 #define kTestCount (2 * kTestsPerTestCase)
85 static void tests(void)
87 const uint8_t der_true
[] = { 0x01, 0x01, 0x01 };
89 one_test(kCFBooleanTrue
, sizeof(der_true
), der_true
);
91 const uint8_t der_false
[] = { 0x01, 0x01, 0x00 };
93 one_test(kCFBooleanFalse
, sizeof(der_false
), der_false
);
96 int su_12_cfboolean_der(int argc
, char *const *argv
)
98 plan_tests(kTestCount
);