5 #include <UniversalString.h>
6 #include <per_support.h>
9 check_encode_failed(asn_TYPE_descriptor_t *td, const char *buf, size_t buflen) {
10 uint8_t uper_output_buffer[32];
11 UniversalString_t *st_in;
13 size_t error_buf_len = sizeof(error_buf);
15 st_in = OCTET_STRING_new_fromBuf(td, buf, buflen);
17 assert(st_in->size == buflen);
19 /* First signal that something is wrong with the length */
20 int st_in_ct = asn_check_constraints(td, st_in, error_buf, &error_buf_len);
21 assert(st_in_ct != 0);
22 fprintf(stderr, "%s\n", error_buf);
24 /* Second signal that something is wrong with the length */
25 asn_enc_rval_t enc = uper_encode_to_buffer(td, 0, st_in, uper_output_buffer,
26 sizeof(uper_output_buffer));
27 assert(enc.encoded == -1);
29 ASN_STRUCT_FREE(*td, st_in);
33 check_round_trip_OK(asn_TYPE_descriptor_t *td, const char *buf, size_t buflen) {
34 uint8_t uper_output_buffer[32];
35 UniversalString_t *st_in;
36 UniversalString_t *st_out = 0;
38 st_in = OCTET_STRING_new_fromBuf(td, buf, buflen);
40 assert(st_in->size == buflen);
42 int st_in_ct = asn_check_constraints(td, st_in, NULL, NULL);
43 assert(st_in_ct == 0);
45 uper_encode_to_buffer(td, 0, st_in,
46 uper_output_buffer, sizeof(uper_output_buffer));
47 assert(enc.encoded > 0);
50 uper_decode(0, &asn_DEF_UniversalString, (void **)&st_out,
51 uper_output_buffer, (enc.encoded + 7) / 8, 0, 0);
52 int st_out_ct = asn_check_constraints(td, st_out, NULL, NULL);
53 assert(st_out_ct == 0);
54 assert(dec.consumed == (size_t)enc.encoded);
55 assert(st_in->size == st_out->size);
56 assert(memcmp(st_in->buf, st_out->buf, st_in->size) == 0);
57 assert(st_out->size == buflen);
58 assert(memcmp(st_out->buf, buf, buflen) == 0);
60 ASN_STRUCT_FREE(*td, st_in);
61 ASN_STRUCT_FREE(*td, st_out);
66 static char UniversalString_data[] = { 0, 0, 0, 65, 0, 0, 0, 65 };
68 check_round_trip_OK(&asn_DEF_UniversalString, UniversalString_data, 0);
69 check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 1);
70 check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 2);
71 check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 3);
72 check_round_trip_OK(&asn_DEF_UniversalString, UniversalString_data, 4);
73 check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 5);
74 check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 6);
75 check_encode_failed(&asn_DEF_UniversalString, UniversalString_data, 7);
76 check_round_trip_OK(&asn_DEF_UniversalString, UniversalString_data, 8);