Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hugo Beauzée-Luyssen
flac
Commits
096a63d3
Commit
096a63d3
authored
May 19, 2018
by
Robert Kausch
Committed by
Erik de Castro Lopo
May 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for CRC calculation.
parent
fcec829b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
234 additions
and
3 deletions
+234
-3
src/test_libFLAC/Makefile.am
src/test_libFLAC/Makefile.am
+3
-1
src/test_libFLAC/Makefile.lite
src/test_libFLAC/Makefile.lite
+2
-1
src/test_libFLAC/crc.c
src/test_libFLAC/crc.c
+182
-0
src/test_libFLAC/crc.h
src/test_libFLAC/crc.h
+26
-0
src/test_libFLAC/main.c
src/test_libFLAC/main.c
+5
-1
src/test_libFLAC/test_libFLAC.vcproj
src/test_libFLAC/test_libFLAC.vcproj
+8
-0
src/test_libFLAC/test_libFLAC.vcxproj
src/test_libFLAC/test_libFLAC.vcxproj
+2
-0
src/test_libFLAC/test_libFLAC.vcxproj.filters
src/test_libFLAC/test_libFLAC.vcxproj.filters
+6
-0
No files found.
src/test_libFLAC/Makefile.am
View file @
096a63d3
# test_libFLAC - Unit tester for libFLAC
# Copyright (C) 2000-2009 Josh Coalson
# Copyright (C) 2011-201
6
Xiph.Org Foundation
# Copyright (C) 2011-201
8
Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
...
...
@@ -36,6 +36,7 @@ test_libFLAC_LDADD = \
test_libFLAC_SOURCES
=
\
bitwriter.c
\
crc.c
\
decoders.c
\
encoders.c
\
endswap.c
\
...
...
@@ -46,6 +47,7 @@ test_libFLAC_SOURCES = \
metadata_object.c
\
md5.c
\
bitwriter.h
\
crc.h
\
decoders.h
\
encoders.h
\
endswap.h
\
...
...
src/test_libFLAC/Makefile.lite
View file @
096a63d3
# test_libFLAC - Unit tester for libFLAC
# Copyright (C) 2000-2009 Josh Coalson
# Copyright (C) 2011-201
6
Xiph.Org Foundation
# Copyright (C) 2011-201
8
Xiph.Org Foundation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
...
...
@@ -37,6 +37,7 @@ endif
SRCS_C
=
\
bitwriter.c
\
crc.c
\
decoders.c
\
encoders.c
\
endswap.c
\
...
...
src/test_libFLAC/crc.c
0 → 100644
View file @
096a63d3
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2014-2018 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include "FLAC/assert.h"
#include "share/compat.h"
#include "private/crc.h"
#include "crc.h"
static
FLAC__uint8
crc8_update_ref
(
FLAC__byte
byte
,
FLAC__uint8
crc
);
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
);
#define DATA_SIZE 32768
FLAC__bool
test_crc
(
void
)
{
uint32_t
i
;
FLAC__byte
data
[
DATA_SIZE
]
=
{
0
};
/* Initialize data reproducibly with pseudo-random values. */
for
(
i
=
1
;
i
<
DATA_SIZE
;
i
++
)
data
[
i
]
=
crc8_update_ref
(
i
%
256
,
data
[
i
-
1
]);
printf
(
"
\n
+++ libFLAC unit test: crc
\n\n
"
);
if
(
!
test_crc8
(
data
,
DATA_SIZE
))
return
false
;
if
(
!
test_crc16
(
data
,
DATA_SIZE
))
return
false
;
if
(
!
test_crc16_update
(
data
,
DATA_SIZE
))
return
false
;
printf
(
"
\n
PASSED!
\n
"
);
return
true
;
}
/*----------------------------------------------------------------------------*/
/* Reference implementations of CRC-8 and CRC-16 to check against. */
#define CRC8_POLYNOMIAL 0x07
static
FLAC__uint8
crc8_update_ref
(
FLAC__byte
byte
,
FLAC__uint8
crc
)
{
uint32_t
i
;
crc
^=
byte
;
for
(
i
=
0
;
i
<
8
;
i
++
)
{
crc
=
(
crc
<<
1
)
^
((
crc
>>
7
)
?
CRC8_POLYNOMIAL
:
0
);
}
return
crc
;
}
#define CRC16_POLYNOMIAL 0x8005
static
FLAC__uint16
crc16_update_ref
(
FLAC__byte
byte
,
FLAC__uint16
crc
)
{
uint32_t
i
;
crc
^=
byte
<<
8
;
for
(
i
=
0
;
i
<
8
;
i
++
)
{
crc
=
(
crc
<<
1
)
^
((
crc
>>
15
)
?
CRC16_POLYNOMIAL
:
0
);
}
return
crc
;
}
/*----------------------------------------------------------------------------*/
static
FLAC__bool
test_crc8
(
const
FLAC__byte
*
data
,
size_t
size
)
{
uint32_t
i
;
FLAC__uint8
crc0
,
crc1
;
printf
(
"testing FLAC__crc8 ... "
);
crc0
=
0
;
crc1
=
FLAC__crc8
(
data
,
0
);
if
(
crc1
!=
crc0
)
{
printf
(
"FAILED, FLAC__crc8 returned non-zero CRC for zero bytes of data
\n
"
);
return
false
;
}
for
(
i
=
0
;
i
<
size
;
i
++
)
{
crc0
=
crc8_update_ref
(
data
[
i
],
crc0
);
crc1
=
FLAC__crc8
(
data
,
i
+
1
);
if
(
crc1
!=
crc0
)
{
printf
(
"FAILED, FLAC__crc8 result did not match reference CRC for %i bytes of test data
\n
"
,
i
+
1
);
return
false
;
}
}
printf
(
"OK
\n
"
);
return
true
;
}
static
FLAC__bool
test_crc16
(
const
FLAC__byte
*
data
,
size_t
size
)
{
uint32_t
i
;
FLAC__uint16
crc0
,
crc1
;
printf
(
"testing FLAC__crc16 ... "
);
crc0
=
0
;
crc1
=
FLAC__crc16
(
data
,
0
);
if
(
crc1
!=
crc0
)
{
printf
(
"FAILED, FLAC__crc16 returned non-zero CRC for zero bytes of data
\n
"
);
return
false
;
}
for
(
i
=
0
;
i
<
size
;
i
++
)
{
crc0
=
crc16_update_ref
(
data
[
i
],
crc0
);
crc1
=
FLAC__crc16
(
data
,
i
+
1
);
if
(
crc1
!=
crc0
)
{
printf
(
"FAILED, FLAC__crc16 result did not match reference CRC for %i bytes of test data
\n
"
,
i
+
1
);
return
false
;
}
}
printf
(
"OK
\n
"
);
return
true
;
}
static
FLAC__bool
test_crc16_update
(
const
FLAC__byte
*
data
,
size_t
size
)
{
uint32_t
i
;
FLAC__uint16
crc0
,
crc1
;
printf
(
"testing FLAC__CRC16_UPDATE macro ... "
);
crc0
=
0
;
crc1
=
0
;
for
(
i
=
0
;
i
<
size
;
i
++
)
{
crc0
=
crc16_update_ref
(
data
[
i
],
crc0
);
crc1
=
FLAC__CRC16_UPDATE
(
data
[
i
],
crc1
);
if
(
crc1
!=
crc0
)
{
printf
(
"FAILED, FLAC__CRC16_UPDATE result did not match reference CRC after %i bytes of test data
\n
"
,
i
+
1
);
return
false
;
}
}
printf
(
"OK
\n
"
);
return
true
;
}
src/test_libFLAC/crc.h
0 → 100644
View file @
096a63d3
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2014-2018 Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef FLAC__TEST_LIBFLAC_CRC_H
#define FLAC__TEST_LIBFLAC_CRC_H
#include "FLAC/ordinals.h"
FLAC__bool
test_crc
(
void
);
#endif
src/test_libFLAC/main.c
View file @
096a63d3
/* test_libFLAC - Unit tester for libFLAC
* Copyright (C) 2000-2009 Josh Coalson
* Copyright (C) 2011-201
6
Xiph.Org Foundation
* Copyright (C) 2011-201
8
Xiph.Org Foundation
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
...
...
@@ -22,6 +22,7 @@
#endif
#include "bitwriter.h"
#include "crc.h"
#include "decoders.h"
#include "encoders.h"
#include "endswap.h"
...
...
@@ -34,6 +35,9 @@ int main(void)
if
(
!
test_endswap
())
return
1
;
if
(
!
test_crc
())
return
1
;
if
(
!
test_md5
())
return
1
;
...
...
src/test_libFLAC/test_libFLAC.vcproj
View file @
096a63d3
...
...
@@ -188,6 +188,10 @@
RelativePath=
".\bitwriter.h"
>
</File>
<File
RelativePath=
".\crc.h"
>
</File>
<File
RelativePath=
".\decoders.h"
>
...
...
@@ -222,6 +226,10 @@
RelativePath=
".\bitwriter.c"
>
</File>
<File
RelativePath=
".\crc.c"
>
</File>
<File
RelativePath=
".\decoders.c"
>
...
...
src/test_libFLAC/test_libFLAC.vcxproj
View file @
096a63d3
...
...
@@ -166,6 +166,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude
Include=
"bitwriter.h"
/>
<ClInclude
Include=
"crc.h"
/>
<ClInclude
Include=
"decoders.h"
/>
<ClInclude
Include=
"encoders.h"
/>
<ClInclude
Include=
"endswap.h"
/>
...
...
@@ -175,6 +176,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"bitwriter.c"
/>
<ClCompile
Include=
"crc.c"
/>
<ClCompile
Include=
"decoders.c"
/>
<ClCompile
Include=
"encoders.c"
/>
<ClCompile
Include=
"endswap.c"
/>
...
...
src/test_libFLAC/test_libFLAC.vcxproj.filters
View file @
096a63d3
...
...
@@ -14,6 +14,9 @@
<ClInclude
Include=
"bitwriter.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"crc.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
<ClInclude
Include=
"decoders.h"
>
<Filter>
Header Files
</Filter>
</ClInclude>
...
...
@@ -37,6 +40,9 @@
<ClCompile
Include=
"bitwriter.c"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"crc.c"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"decoders.c"
>
<Filter>
Source Files
</Filter>
</ClCompile>
...
...
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