2 * Copyright (c) 1999 - 2005 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 #include <asn1-common.h>
46 #include <test_asn1.h>
48 #include "check-common.h"
51 cmp_dummy (void *a
, void *b
)
59 struct test_case tests
[] = {
60 { NULL
, 3, "\x02\x01\x00", "uint64 0" },
61 { NULL
, 7, "\x02\x05\x01\xff\xff\xff\xff", "uint64 1" },
62 { NULL
, 7, "\x02\x05\x02\x00\x00\x00\x00", "uint64 2" },
63 { NULL
, 9, "\x02\x07\x7f\xff\xff\xff\xff\xff\xff", "uint64 3" },
64 { NULL
, 10, "\x02\x08\x00\x80\x00\x00\x00\x00\x00\x00", "uint64 4" },
65 { NULL
, 10, "\x02\x08\x7f\xff\xff\xff\xff\xff\xff\xff", "uint64 5" },
66 { NULL
, 11, "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff", "uint64 6" }
70 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
71 TESTuint64 values
[] = { 0, 8589934591LL, 8589934592LL,
72 36028797018963967LL, 36028797018963968LL,
73 9223372036854775807LL, 18446744073709551615ULL };
75 for (i
= 0; i
< ntests
; i
++)
76 tests
[i
].val
= &values
[i
];
78 if (sizeof(TESTuint64
) != sizeof(uint64_t)) {
80 printf("sizeof(TESTuint64) %d != sizeof(uint64_t) %d\n",
81 (int)sizeof(TESTuint64
), (int)sizeof(uint64_t));
84 ret
+= generic_test (tests
, ntests
, sizeof(TESTuint64
),
85 (generic_encode
)encode_TESTuint64
,
86 (generic_length
)length_TESTuint64
,
87 (generic_decode
)decode_TESTuint64
,
88 (generic_free
)free_TESTuint64
,
97 struct test_case tests
[] = {
102 "\x30\x07\x30\x05\xa0\x03\x02\x01\x00",
105 "\x30\x0e\x30\x05\xa0\x03\x02\x01\x00\x30\x05\xa0\x03\x02\x01\x01",
109 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
110 TESTSeqOfSeq c0
, c1
, c2
;
111 struct TESTSeqOfSeq_val i
[2];
128 ret
+= generic_test (tests
, ntests
, sizeof(TESTSeqOfSeq
),
129 (generic_encode
)encode_TESTSeqOfSeq
,
130 (generic_length
)length_TESTSeqOfSeq
,
131 (generic_decode
)decode_TESTSeqOfSeq
,
132 (generic_free
)free_TESTSeqOfSeq
,
141 struct test_case tests
[] = {
146 "\x30\x09\x30\x07\xa0\x05\x1b\x03\x65\x74\x74",
149 "\x30\x13\x30\x07\xa0\x05\x1b\x03\x65\x74\x74\x30\x08\xa0"
150 "\x06\x1b\x04\x74\x76\x61\x61",
154 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
155 TESTSeqOfSeq2 c0
, c1
, c2
;
156 struct TESTSeqOfSeq2_val i
[2];
159 i
[1].string
= "tvaa";
173 ret
+= generic_test (tests
, ntests
, sizeof(TESTSeqOfSeq2
),
174 (generic_encode
)encode_TESTSeqOfSeq2
,
175 (generic_length
)length_TESTSeqOfSeq2
,
176 (generic_decode
)decode_TESTSeqOfSeq2
,
177 (generic_free
)free_TESTSeqOfSeq2
,
186 struct test_case tests
[] = {
191 "\x30\x07\x30\x05\x1b\x03\x66\x6f\x6f",
194 "\x30\x0c\x30\x0a\x1b\x03\x66\x6f\x6f\x1b\x03\x62\x61\x72",
198 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
199 TESTSeqOf2 c0
, c1
, c2
;
200 heim_general_string i
[2];
205 c0
.strings
.val
= NULL
;
217 ret
+= generic_test (tests
, ntests
, sizeof(TESTSeqOf2
),
218 (generic_encode
)encode_TESTSeqOf2
,
219 (generic_length
)length_TESTSeqOf2
,
220 (generic_decode
)decode_TESTSeqOf2
,
221 (generic_free
)free_TESTSeqOf2
,
230 struct test_case tests
[] = {
238 "\x30\x07\x30\x05\x1b\x03\x66\x6f\x6f",
241 "\x30\x0c\x30\x0a\x1b\x03\x66\x6f\x6f\x1b\x03\x62\x61\x72",
245 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
246 TESTSeqOf3 c0
, c1
, c2
, c3
;
247 struct TESTSeqOf3_strings s1
, s2
, s3
;
248 heim_general_string i
[2];
271 ret
+= generic_test (tests
, ntests
, sizeof(TESTSeqOf3
),
272 (generic_encode
)encode_TESTSeqOf3
,
273 (generic_length
)length_TESTSeqOf3
,
274 (generic_decode
)decode_TESTSeqOf3
,
275 (generic_free
)free_TESTSeqOf3
,
285 struct test_case tests
[] = {
290 "\x30\x02" "\xa1\x00",
293 "\x30\x06" "\xa0\x02\x30\x00" "\xa1\x00",
295 { NULL
, 2 + (2 + 0x18) + (2 + 0x27) + (2 + 0x31),
296 "\x30\x76" /* 2 SEQ */
297 "\xa0\x18\x30\x16" /* 4 [0] SEQ */
298 "\x30\x14" /* 2 SEQ */
299 "\x04\x00" /* 2 OCTET-STRING */
300 "\x04\x02\x01\x02" /* 4 OCTET-STRING */
301 "\x02\x01\x01" /* 3 INT */
302 "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff"
304 "\xa1\x27" /* 2 [1] IMPL SEQ */
305 "\x30\x25" /* 2 SEQ */
306 "\x02\x01\x01" /* 3 INT */
307 "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff"
309 "\x02\x09\x00\x80\x00\x00\x00\x00\x00\x00\x00"
311 "\x04\x00" /* 2 OCTET-STRING */
312 "\x04\x02\x01\x02" /* 4 OCTET-STRING */
313 "\x04\x04\x00\x01\x02\x03" /* 6 OCTET-STRING */
314 "\xa2\x31" /* 2 [2] IMPL SEQ */
315 "\x30\x2f" /* 2 SEQ */
316 "\x04\x00" /* 2 OCTET-STRING */
317 "\x02\x01\x01" /* 3 INT */
318 "\x04\x02\x01\x02" /* 4 OCTET-STRING */
319 "\x02\x09\x00\xff\xff\xff\xff\xff\xff\xff\xff"
321 "\x04\x04\x00\x01\x02\x03" /* 6 OCTET-STRING */
322 "\x02\x09\x00\x80\x00\x00\x00\x00\x00\x00\x00"
324 "\x04\x01\x00" /* 3 OCTET-STRING */
325 "\x02\x05\x01\x00\x00\x00\x00", /* 7 INT */
329 int ret
= 0, ntests
= sizeof(tests
) / sizeof(*tests
);
331 struct TESTSeqOf4_b1 b1
[4];
332 struct TESTSeqOf4_b2 b2
[4];
333 struct TESTSeqOf4_b3 b3
[4];
334 struct TESTSeqOf4_b1_val b1val
[4];
335 struct TESTSeqOf4_b2_val b2val
[4];
336 struct TESTSeqOf4_b3_val b3val
[4];
341 tests
[0].val
= &c
[0];
348 tests
[1].val
= &c
[1];
357 tests
[2].val
= &c
[2];
359 b1val
[3].s1
.data
= "";
360 b1val
[3].s1
.length
= 0;
362 b1val
[3].s2
.data
= "\x01\x02";
363 b1val
[3].s2
.length
= 2;
366 b2val
[3].s1
.data
= "";
367 b2val
[3].s1
.length
= 0;
369 b2val
[3].s2
.data
= "\x01\x02";
370 b2val
[3].s2
.length
= 2;
372 b2val
[3].s3
.data
= "\x00\x01\x02\x03";
373 b2val
[3].s3
.length
= 4;
374 b2val
[3].u3
= 1LL<<63;
376 b3val
[3].s1
.data
= "";
377 b3val
[3].s1
.length
= 0;
379 b3val
[3].s2
.data
= "\x01\x02";
380 b3val
[3].s2
.length
= 2;
382 b3val
[3].s3
.data
= "\x00\x01\x02\x03";
383 b3val
[3].s3
.length
= 4;
384 b3val
[3].u3
= 1LL<<63;
385 b3val
[3].s4
.data
= "\x00";
386 b3val
[3].s4
.length
= 1;
387 b3val
[3].u4
= 1LL<<32;
390 b1
[3].val
= &b1val
[3];
392 b2
[3].val
= &b2val
[3];
394 b3
[3].val
= &b3val
[3];
398 tests
[3].val
= &c
[3];
400 ret
+= generic_test (tests
, ntests
, sizeof(TESTSeqOf4
),
401 (generic_encode
)encode_TESTSeqOf4
,
402 (generic_length
)length_TESTSeqOf4
,
403 (generic_decode
)decode_TESTSeqOf4
,
404 (generic_free
)free_TESTSeqOf4
,
411 main(int argc
, char **argv
)
415 ret
+= test_uint64();
416 ret
+= test_seqofseq();
417 ret
+= test_seqofseq2();
418 ret
+= test_seqof2();
419 ret
+= test_seqof3();
420 ret
+= test_seqof4();