Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hammer
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vyrus
hammer
Commits
6e087ac7
Commit
6e087ac7
authored
12 years ago
by
Meredith L. Patterson
Browse files
Options
Downloads
Patches
Plain Diff
Test harness macros extended. Need to implement bodies of primitive parsers.
parent
990a19e1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/hammer.c
+8
-8
8 additions, 8 deletions
src/hammer.c
src/test_suite.h
+26
-9
26 additions, 9 deletions
src/test_suite.h
with
34 additions
and
17 deletions
src/hammer.c
+
8
−
8
View file @
6e087ac7
...
@@ -441,10 +441,10 @@ parse_result_t* parse(const parser_t* parser, const uint8_t* input, size_t lengt
...
@@ -441,10 +441,10 @@ parse_result_t* parse(const parser_t* parser, const uint8_t* input, size_t lengt
#include
"test_suite.h"
#include
"test_suite.h"
static
void
test_token
(
void
)
{
static
void
test_token
(
void
)
{
//
uint8_t test[3] = { '9', '5', 0xa2 };
uint8_t
test
[
3
]
=
{
'9'
,
'5'
,
0xa2
};
//
const parser_t *token_ = token(test , 3);
const
parser_t
*
token_
=
token
(
test
,
3
);
//
parse_result_t *ret = parse(token_, test, 3);
parse_result_t
*
ret
=
parse
(
token_
,
test
,
3
);
// need a g_check_cmpstr function for this :P
g_check_bytes
((
ret
->
ast
)[
0
].
bytes
.
len
,
(
ret
->
ast
)[
0
].
bytes
.
token
,
==
,
test
);
}
}
static
void
test_ch
(
void
)
{
static
void
test_ch
(
void
)
{
...
@@ -465,28 +465,28 @@ static void test_int64(void) {
...
@@ -465,28 +465,28 @@ static void test_int64(void) {
uint8_t
test
[
8
]
=
{
0xff
,
0xff
,
0xff
,
0xfe
,
0x00
,
0x00
,
0x00
,
0x00
};
uint8_t
test
[
8
]
=
{
0xff
,
0xff
,
0xff
,
0xfe
,
0x00
,
0x00
,
0x00
,
0x00
};
const
parser_t
*
int64_
=
int64
();
const
parser_t
*
int64_
=
int64
();
parse_result_t
*
ret
=
parse
(
int64_
,
test
,
8
);
parse_result_t
*
ret
=
parse
(
int64_
,
test
,
8
);
g_check_cmp
int
((
long
long
int
)
(
ret
->
ast
)[
0
].
sint
,
==
,
-
8589934592L
);
g_check_cmp
long
(
(
ret
->
ast
)[
0
].
sint
,
==
,
-
8589934592L
);
}
}
static
void
test_int32
(
void
)
{
static
void
test_int32
(
void
)
{
uint8_t
test
[
4
]
=
{
0xff
,
0xfe
,
0x00
,
0x00
};
uint8_t
test
[
4
]
=
{
0xff
,
0xfe
,
0x00
,
0x00
};
const
parser_t
*
int32_
=
int32
();
const
parser_t
*
int32_
=
int32
();
parse_result_t
*
ret
=
parse
(
int32_
,
test
,
4
);
parse_result_t
*
ret
=
parse
(
int32_
,
test
,
4
);
g_check_cmpint
((
long
long
int
)(
ret
->
ast
)[
0
].
sint
,
==
,
-
131072
);
g_check_cmpint
((
ret
->
ast
)[
0
].
sint
,
==
,
-
131072
);
}
}
static
void
test_int16
(
void
)
{
static
void
test_int16
(
void
)
{
uint8_t
test
[
2
]
=
{
0xfe
,
0x00
};
uint8_t
test
[
2
]
=
{
0xfe
,
0x00
};
const
parser_t
*
int16_
=
int16
();
const
parser_t
*
int16_
=
int16
();
parse_result_t
*
ret
=
parse
(
int16_
,
test
,
2
);
parse_result_t
*
ret
=
parse
(
int16_
,
test
,
2
);
g_check_cmpint
((
long
long
int
)(
ret
->
ast
)[
0
].
sint
,
==
,
-
512
);
g_check_cmpint
((
ret
->
ast
)[
0
].
sint
,
==
,
-
512
);
}
}
static
void
test_int8
(
void
)
{
static
void
test_int8
(
void
)
{
uint8_t
test
[
1
]
=
{
0x88
};
uint8_t
test
[
1
]
=
{
0x88
};
const
parser_t
*
int8_
=
int8
();
const
parser_t
*
int8_
=
int8
();
parse_result_t
*
ret
=
parse
(
int8_
,
test
,
1
);
parse_result_t
*
ret
=
parse
(
int8_
,
test
,
1
);
g_check_cmpint
((
long
long
int
)(
ret
->
ast
)[
0
].
sint
,
==
,
-
120
);
g_check_cmpint
((
ret
->
ast
)[
0
].
sint
,
==
,
-
120
);
}
}
static
void
test_uint64
(
void
)
{
static
void
test_uint64
(
void
)
{
...
...
This diff is collapsed.
Click to expand it.
src/test_suite.h
+
26
−
9
View file @
6e087ac7
...
@@ -2,16 +2,33 @@
...
@@ -2,16 +2,33 @@
#define HAMMER_TEST_SUITE__H
#define HAMMER_TEST_SUITE__H
// Equivalent to g_assert_*, but not using g_assert...
// Equivalent to g_assert_*, but not using g_assert...
#define g_check_
cmpint(
n1, op, n2) { \
#define g_check_
inttype(fmt, typ,
n1, op, n2) {
\
typ
eof (n1)
_n1 = (n1); \
typ _n1 = (n1);
\
typ
eof (n2)
_n2 = (n2); \
typ _n2 = (n2);
\
if (!(_n1 op _n2)) { \
if (!(_n1 op _n2)) {
\
g_test_message("Check failed: (%s): (
%lld %s %d
)", \
g_test_message("Check failed: (%s): (
" fmt " %s " fmt "
)", \
#n1 " " #op " " #n2, \
#n1 " " #op " " #n2,
\
_n1, #op, _n2); \
_n1, #op, _n2);
\
g_test_fail(); \
g_test_fail();
\
} \
}
\
}
}
#define g_check_bytes(len, n1, op, n2) { \
const uint8_t *_n1 = (n1); \
uint8_t *_n2 = (n2); \
if (!(memcmp(_n1, _n2, len) op 0)) { \
g_test_message("Check failed: (%s)", \
#n1 " " #op " " #n2); \
g_test_fail(); \
} \
}
#define g_check_cmpint(n1, op, n2) g_check_inttype("%d", int, n1, op, n2)
#define g_check_cmplong(n1, op, n2) g_check_inttype("%ld", long, n1, op, n2)
#define g_check_cmplonglong(n1, op, n2) g_check_inttype("%lld", long long, n1, op, n2)
#define g_check_cmpuint(n1, op, n2) g_check_inttype("%u", unsigned int, n1, op, n2)
#define g_check_cmpulong(n1, op, n2) g_check_inttype("%lu", unsigned long, n1, op, n2)
#define g_check_cmpulonglong(n1, op, n2) g_check_inttype("%llu", unsigned long long, n1, op, n2)
#endif // #ifndef HAMMER_TEST_SUITE__H
#endif // #ifndef HAMMER_TEST_SUITE__H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment