Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flac
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
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
Hugo Beauzée-Luyssen
flac
Commits
c2673daf
Commit
c2673daf
authored
May 20, 2018
by
Robert Kausch
Committed by
Erik de Castro Lopo
May 21, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for word-wise CRC16 functions
Update FLAC__BitReader structure in unit test.
parent
65c27964
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
0 deletions
+93
-0
src/test_libFLAC/bitreader.c
src/test_libFLAC/bitreader.c
+1
-0
src/test_libFLAC/crc.c
src/test_libFLAC/crc.c
+92
-0
No files found.
src/test_libFLAC/bitreader.c
View file @
c2673daf
...
...
@@ -57,6 +57,7 @@ struct FLAC__BitReader {
uint32_t
consumed_words
;
/* #words ... */
uint32_t
consumed_bits
;
/* ... + (#bits of head word) already consumed from the front of buffer */
uint32_t
read_crc16
;
/* the running frame CRC */
uint32_t
crc16_offset
;
/* the number of words in the current buffer that should not be CRC'd */
uint32_t
crc16_align
;
/* the number of bits in the current consumed word that should not be CRC'd */
FLAC__BitReaderReadCallback
read_callback
;
void
*
client_data
;
...
...
src/test_libFLAC/crc.c
View file @
c2673daf
...
...
@@ -33,6 +33,8 @@ static FLAC__uint16 crc16_update_ref(FLAC__byte byte, FLAC__uint16 crc);
static
FLAC__bool
test_crc8
(
const
FLAC__byte
*
data
,
size_t
size
);
static
FLAC__bool
test_crc16
(
const
FLAC__byte
*
data
,
size_t
size
);
static
FLAC__bool
test_crc16_update
(
const
FLAC__byte
*
data
,
size_t
size
);
static
FLAC__bool
test_crc16_32bit_words
(
const
FLAC__uint32
*
words
,
size_t
size
);
static
FLAC__bool
test_crc16_64bit_words
(
const
FLAC__uint64
*
words
,
size_t
size
);
#define DATA_SIZE 32768
...
...
@@ -56,6 +58,12 @@ FLAC__bool test_crc(void)
if
(
!
test_crc16_update
(
data
,
DATA_SIZE
))
return
false
;
if
(
!
test_crc16_32bit_words
((
FLAC__uint32
*
)
data
,
DATA_SIZE
/
4
))
return
false
;
if
(
!
test_crc16_64bit_words
((
FLAC__uint64
*
)
data
,
DATA_SIZE
/
8
))
return
false
;
printf
(
"
\n
PASSED!
\n
"
);
return
true
;
}
...
...
@@ -180,3 +188,87 @@ static FLAC__bool test_crc16_update(const FLAC__byte *data, size_t size)
return
true
;
}
static
FLAC__bool
test_crc16_32bit_words
(
const
FLAC__uint32
*
words
,
size_t
size
)
{
uint32_t
n
,
i
,
k
;
FLAC__uint16
crc0
,
crc1
;
for
(
n
=
1
;
n
<=
16
;
n
++
)
{
printf
(
"testing FLAC__crc16_update_words32 (length=%i) ... "
,
n
);
crc0
=
0
;
crc1
=
0
;
for
(
i
=
0
;
i
<=
size
-
n
;
i
+=
n
)
{
for
(
k
=
0
;
k
<
n
;
k
++
)
{
crc0
=
crc16_update_ref
(
words
[
i
+
k
]
>>
24
,
crc0
);
crc0
=
crc16_update_ref
((
words
[
i
+
k
]
>>
16
)
&
0xFF
,
crc0
);
crc0
=
crc16_update_ref
((
words
[
i
+
k
]
>>
8
)
&
0xFF
,
crc0
);
crc0
=
crc16_update_ref
(
words
[
i
+
k
]
&
0xFF
,
crc0
);
}
crc1
=
FLAC__crc16_update_words32
(
words
+
i
,
n
,
crc1
);
if
(
crc1
!=
crc0
)
{
printf
(
"FAILED, FLAC__crc16_update_words32 result did not match reference CRC after %i words of test data
\n
"
,
i
+
n
);
return
false
;
}
}
crc1
=
FLAC__crc16_update_words32
(
words
,
0
,
crc1
);
if
(
crc1
!=
crc0
)
{
printf
(
"FAILED, FLAC__crc16_update_words32 called with zero bytes changed CRC value
\n
"
);
return
false
;
}
printf
(
"OK
\n
"
);
}
return
true
;
}
static
FLAC__bool
test_crc16_64bit_words
(
const
FLAC__uint64
*
words
,
size_t
size
)
{
uint32_t
n
,
i
,
k
;
FLAC__uint16
crc0
,
crc1
;
for
(
n
=
1
;
n
<=
16
;
n
++
)
{
printf
(
"testing FLAC__crc16_update_words64 (length=%i) ... "
,
n
);
crc0
=
0
;
crc1
=
0
;
for
(
i
=
0
;
i
<=
size
-
n
;
i
+=
n
)
{
for
(
k
=
0
;
k
<
n
;
k
++
)
{
crc0
=
crc16_update_ref
(
words
[
i
+
k
]
>>
56
,
crc0
);
crc0
=
crc16_update_ref
((
words
[
i
+
k
]
>>
48
)
&
0xFF
,
crc0
);
crc0
=
crc16_update_ref
((
words
[
i
+
k
]
>>
40
)
&
0xFF
,
crc0
);
crc0
=
crc16_update_ref
((
words
[
i
+
k
]
>>
32
)
&
0xFF
,
crc0
);
crc0
=
crc16_update_ref
((
words
[
i
+
k
]
>>
24
)
&
0xFF
,
crc0
);
crc0
=
crc16_update_ref
((
words
[
i
+
k
]
>>
16
)
&
0xFF
,
crc0
);
crc0
=
crc16_update_ref
((
words
[
i
+
k
]
>>
8
)
&
0xFF
,
crc0
);
crc0
=
crc16_update_ref
(
words
[
i
+
k
]
&
0xFF
,
crc0
);
}
crc1
=
FLAC__crc16_update_words64
(
words
+
i
,
n
,
crc1
);
if
(
crc1
!=
crc0
)
{
printf
(
"FAILED, FLAC__crc16_update_words64 result did not match reference CRC after %i words of test data
\n
"
,
i
+
n
);
return
false
;
}
}
crc1
=
FLAC__crc16_update_words64
(
words
,
0
,
crc1
);
if
(
crc1
!=
crc0
)
{
printf
(
"FAILED, FLAC__crc16_update_words64 called with zero bytes changed CRC value
\n
"
);
return
false
;
}
printf
(
"OK
\n
"
);
}
return
true
;
}
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