Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
asn1c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
asn1c
Commits
a93d9971
Commit
a93d9971
authored
7 years ago
by
Ryan Sleevi
Committed by
Lev Walkin
7 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unittest, which revealed that default booleans were not set properly
parent
ae8a6e4d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
201 additions
and
1 deletion
+201
-1
libasn1compiler/asn1c_C.c
libasn1compiler/asn1c_C.c
+3
-1
tests/tests-asn1c-compiler/148-der-default-set-sequence-values-OK.asn1
...sn1c-compiler/148-der-default-set-sequence-values-OK.asn1
+22
-0
tests/tests-c-compiler/Makefile.am
tests/tests-c-compiler/Makefile.am
+1
-0
tests/tests-c-compiler/check-src/check-148.c
tests/tests-c-compiler/check-src/check-148.c
+175
-0
No files found.
libasn1compiler/asn1c_C.c
View file @
a93d9971
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
tests/tests-asn1c-compiler/148-der-default-set-sequence-values-OK.asn1
0 → 100644
View file @
a93d9971
-- 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
This diff is collapsed.
Click to expand it.
tests/tests-c-compiler/Makefile.am
View file @
a93d9971
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
tests/tests-c-compiler/check-src/check-148.c
0 → 100644
View file @
a93d9971
#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
));
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment