5 // Created by Mitch Adler on 6/20/12.
6 // Copyright (c) 2012 Apple Inc. All rights reserved.
9 #include "utilities/der_plist.h"
10 #include "utilities/der_plist_internal.h"
12 #include "utilities/SecCFRelease.h"
13 #include "utilities/array_size.h"
15 #include <CoreFoundation/CoreFoundation.h>
17 #include "utilities_regressions.h"
19 #define kMaxResultSize 16
21 #define kTestsPerTestCase 8
22 static void one_test(CFBooleanRef value
, size_t der_size
, const uint8_t *expected_der
)
25 uint8_t buffer
[kMaxResultSize
];
26 uint8_t *buffer_end
= buffer
+ sizeof(buffer
);
28 uint8_t* encoded
= der_encode_plist(value
, NULL
, buffer
, buffer_end
);
31 (der_size
== (buffer_end
- encoded
)) &&
32 (memcmp(encoded
, expected_der
, der_size
) == 0));
34 encoded
= der_encode_boolean(value
, NULL
, buffer
, buffer_end
);
37 (der_size
== (buffer_end
- encoded
)) &&
38 (memcmp(encoded
, expected_der
, der_size
) == 0));
41 printf(".size = %d, .res = { ", (buffer_end
- encoded
));
42 for(int c
= 0; c
< (buffer_end
- encoded
); ++c
)
43 printf("0x%02X, ", encoded
[c
]);
47 CFBooleanRef decoded
= NULL
;
48 const uint8_t* decode_end
= der_decode_boolean(NULL
, kCFPropertyListMutableContainersAndLeaves
,
49 &decoded
, NULL
, encoded
, buffer_end
);
51 ok(decode_end
== buffer_end
);
52 ok((decoded
!= NULL
) && CFEqual(decoded
, value
));
54 CFPropertyListRef decoded_type
= NULL
;
55 decode_end
= der_decode_plist(NULL
, kCFPropertyListMutableContainersAndLeaves
,
56 &decoded_type
, NULL
, encoded
, buffer_end
);
58 ok(decode_end
== buffer_end
);
59 ok((decoded
!= NULL
) && CFEqual(decoded_type
, value
));
61 ok(der_sizeof_boolean(value
, NULL
) == der_size
);
62 ok(der_sizeof_plist(value
, NULL
) == der_size
);
64 CFReleaseNull(decoded
);
65 CFReleaseNull(decoded_type
);
68 #define kTestCount (2 * kTestsPerTestCase)
69 static void tests(void)
71 const uint8_t der_true
[] = { 0x01, 0x01, 0x01 };
73 one_test(kCFBooleanTrue
, sizeof(der_true
), der_true
);
75 const uint8_t der_false
[] = { 0x01, 0x01, 0x00 };
77 one_test(kCFBooleanFalse
, sizeof(der_false
), der_false
);
80 int su_12_cfboolean_der(int argc
, char *const *argv
)
82 plan_tests(kTestCount
);