Commit a93d9971 authored by Ryan Sleevi's avatar Ryan Sleevi Committed by Lev Walkin

Add unittest, which revealed that default booleans were not set properly

parent ae8a6e4d
......@@ -2585,7 +2585,9 @@ try_inline_default(arg_t *arg, asn1p_expr_t *expr, int out) {
case ASN_BASIC_INTEGER:
case ASN_BASIC_ENUMERATED:
if(expr->marker.default_value == NULL
|| expr->marker.default_value->type != ATV_INTEGER)
|| (expr->marker.default_value->type != ATV_INTEGER &&
expr->marker.default_value->type != ATV_TRUE &&
expr->marker.default_value->type != ATV_FALSE))
break;
if(!fits_long)
fits_long = asn1c_type_fits_long(arg, expr)!=FL_NOTFIT;
......
-- OK: Everything is fine
-- iso.org.dod.internet.private.enterprise (1.3.6.1.4.1)
-- .spelio.software.asn1c.test (9363.1.5.1)
-- .148
ModuleTestDerSetSequenceValues
{ iso org(3) dod(6) internet(1) private(4) enterprise(1)
spelio(9363) software(1) asn1c(5) test(1) 148 }
DEFINITIONS AUTOMATIC TAGS ::= BEGIN
DefaultSequence ::= SEQUENCE {
aBool BOOLEAN DEFAULT FALSE,
anInteger INTEGER OPTIONAL
}
DefaultSet ::= SET {
aBool [0] IMPLICIT BOOLEAN DEFAULT FALSE,
anInteger [1] IMPLICIT INTEGER OPTIONAL
}
END
......@@ -28,6 +28,7 @@ TESTS += check-src/check-131.-gen-PER.c
TESTS += check-src/check-132.-gen-PER.c
TESTS += check-src/check-133.-gen-PER.c
TESTS += check-src/check-135.-gen-OER.c
TESTS += check-src/check-148.c
TESTS += check-src/check-19.c
TESTS += check-src/check-22.-fwide-types.c
TESTS += check-src/check-24.-fwide-types.c
......
#undef NDEBUG
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <assert.h>
#include <DefaultSequence.h>
#include <DefaultSet.h>
uint8_t berSeq1[] = {
32 | 16, /* [UNIVERSAL 16], constructed */
6, /* L */
/* aBool BOOLEAN */
((2 << 6) + 0), /* [0], primitive */
1, /* L */
0, /* FALSE */
/* anInteger INTEGER */
((2 << 6) + 1), /* [1], primitive */
1, /* L */
1
};
uint8_t derSeq1[] = {
32 | 16, /* [UNIVERSAL 16], constructed */
3, /* L */
/* anInteger INTEGER */
((2 << 6) + 1), /* [1], primitive */
1, /* L */
1
};
uint8_t berSeq2[] = {
32 | 16, /* [UNIVERSAL 16], constructed */
3, /* L */
/* aBool BOOLEAN */
((2 << 6) + 0), /* [0], primitive */
1, /* L */
0 /* FALSE */
};
uint8_t derSeq2[] = {
32 | 16, /* [UNIVERSAL 16], constructed */
0 /* L */
};
uint8_t berSet1[] = {
32 | 17, /* [UNIVERSAL 17], constructed */
6, /* L */
/* aBool BOOLEAN */
((2 << 6) + 0), /* [0], primitive */
1, /* L */
0, /* FALSE */
/* anInteger INTEGER */
((2 << 6) + 1), /* [1], primitive */
1, /* L */
1
};
uint8_t derSet1[] = {
32 | 17, /* [UNIVERSAL 17], constructed */
3, /* L */
/* anInteger INTEGER */
((2 << 6) + 1), /* [1], primitive */
1, /* L */
1
};
uint8_t berSet2[] = {
32 | 17, /* [UNIVERSAL 17], constructed */
3, /* L */
/* aBool BOOLEAN */
((2 << 6) + 0), /* [0], primitive */
1, /* L */
0 /* FALSE */
};
uint8_t derSet2[] = {
32 | 17, /* [UNIVERSAL 17], constructed */
0 /* L */
};
uint8_t buf2[128];
int buf2_pos;
static int
buf2_fill(const void *buffer, size_t size, void *app_key) {
(void)app_key;
if(buf2_pos + size > sizeof(buf2))
return -1;
memcpy(buf2 + buf2_pos, buffer, size);
buf2_pos += size;
return 0;
}
static void
compare_encoding(asn_enc_rval_t *erval, uint8_t *expected, size_t expected_size,
uint8_t *actual) {
int i;
assert(erval->encoded != -1);
if(erval->encoded != expected_size) {
printf("%d != %d\n", (int)erval->encoded, (int)expected_size);
}
assert(erval->encoded == (ssize_t)expected_size);
for(i = 0; i < expected_size; i++) {
if(expected[i] != actual[i]) {
fprintf(stderr, "Recreated buffer content mismatch:\n");
fprintf(stderr, "Byte %d, %x != %x (%d != %d)\n",
i,
expected[i], actual[i],
expected[i], actual[i]
);
}
assert(expected[i] == actual[i]);
}
}
static void
check_sequence(uint8_t *in, size_t in_size, uint8_t *expected,
size_t expected_size) {
DefaultSequence_t t, *tp;
void *tpp = &tp;
asn_dec_rval_t rval;
asn_enc_rval_t erval;
tp = memset(&t, 0, sizeof(t));
/* Try to decode the BER encoding. */
rval = ber_decode(0, &asn_DEF_DefaultSequence, (void**)tpp, in, in_size);
assert(rval.code == RC_OK);
assert(rval.consumed == in_size);
/* Try to re-create using DER encoding. */
buf2_pos = 0;
erval = der_encode(&asn_DEF_DefaultSequence, tp, buf2_fill, 0);
compare_encoding(&erval, expected, expected_size, buf2);
}
static void
check_set(uint8_t *in, size_t in_size, uint8_t *expected,
size_t expected_size) {
DefaultSet_t t, *tp;
void *tpp = &tp;
asn_dec_rval_t rval;
asn_enc_rval_t erval;
tp = memset(&t, 0, sizeof(t));
/* Try to decode the BER encoding. */
rval = ber_decode(0, &asn_DEF_DefaultSet, (void**)tpp, in, in_size);
assert(rval.code == RC_OK);
assert(rval.consumed == in_size);
/* Try to re-create using DER encoding. */
buf2_pos = 0;
erval = der_encode(&asn_DEF_DefaultSet, tp, buf2_fill, 0);
compare_encoding(&erval, expected, expected_size, buf2);
}
int
main(int ac, char **av) {
(void)ac; /* Unused argument */
(void)av; /* Unused argument */
check_sequence(berSeq1, sizeof(berSeq1), derSeq1, sizeof(derSeq1));
check_sequence(berSeq2, sizeof(berSeq2), derSeq2, sizeof(derSeq2));
check_set(berSet1, sizeof(berSet1), derSet1, sizeof(derSet1));
check_set(berSet2, sizeof(berSet2), derSet2, sizeof(derSet2));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment