Lev Walkin | 190419b | 2010-10-25 19:19:17 -0700 | [diff] [blame] | 1 | #undef NDEBUG |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <string.h> |
| 6 | #include <assert.h> |
| 7 | |
| 8 | #include "T.h" |
| 9 | #include "per_opentype.h" |
| 10 | |
| 11 | int |
| 12 | main() { |
| 13 | asn_per_data_t pd; |
| 14 | asn_per_outp_t po; |
| 15 | asn_dec_rval_t rv; |
| 16 | T_t t; |
| 17 | T_t *t2 = 0; |
| 18 | size_t i; |
| 19 | |
| 20 | memset(&po, 0, sizeof po); |
| 21 | po.buffer = po.tmpspace; |
| 22 | po.nbits = sizeof(po.tmpspace) * 8; |
| 23 | |
| 24 | memset(&t, 0, sizeof t); |
| 25 | |
| 26 | printf("Checking uper_open_type_put():\n"); |
| 27 | assert(0 == uper_open_type_put(&asn_DEF_T, 0, &t, &po)); |
Lev Walkin | a75b247 | 2017-09-18 00:38:43 -0700 | [diff] [blame] | 28 | assert(po.nbits == (-1 + (int)sizeof(po.tmpspace)) * 8); |
Lev Walkin | 1715b32 | 2013-03-28 04:02:13 -0700 | [diff] [blame] | 29 | printf("po{nboff=%zd; nbits=%zd; buffer=%p; tmpspace=%p}\n", |
Lev Walkin | 190419b | 2010-10-25 19:19:17 -0700 | [diff] [blame] | 30 | po.nboff, po.nbits, po.buffer, po.tmpspace); |
| 31 | /* One byte length and one byte 0x00 */ |
| 32 | assert( (po.nboff == 8 && po.buffer == &po.tmpspace[1]) |
| 33 | || (po.nboff == 0 && po.buffer == &po.tmpspace[2])); |
| 34 | assert(po.tmpspace[0] == 0x01); |
| 35 | assert(po.tmpspace[1] == 0x00); |
| 36 | |
| 37 | printf("\nChecking uper_open_type_get():\n"); |
| 38 | for(i = 0; i < 16; i++) { |
| 39 | FREEMEM(t2); t2 = 0; |
| 40 | memset(&pd, 0, sizeof pd); |
| 41 | pd.buffer = po.tmpspace; |
| 42 | pd.nboff = 0; |
| 43 | pd.nbits = i; |
| 44 | rv = uper_open_type_get(0, &asn_DEF_T, 0, (void **)&t2, &pd); |
| 45 | assert(rv.code == RC_WMORE); |
| 46 | } |
| 47 | |
| 48 | memset(&pd, 0, sizeof pd); |
| 49 | pd.buffer = po.tmpspace; |
| 50 | pd.nboff = 0; |
| 51 | pd.nbits = 16; |
| 52 | rv = uper_open_type_get(0, &asn_DEF_T, 0, (void **)&t2, &pd); |
| 53 | assert(rv.code == RC_OK); |
| 54 | assert( (pd.nboff == 8 && pd.buffer == &po.tmpspace[1]) |
| 55 | || (pd.nboff == 16 && pd.buffer == &po.tmpspace[0])); |
| 56 | assert(pd.nboff + pd.nbits == 16); |
| 57 | |
| 58 | return 0; |
| 59 | } |