Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wasm-watermarker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
wasm-watermarker
Commits
df1c22fa
Commit
df1c22fa
authored
Jul 08, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add: Add unit test
parent
e6723dd1
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
90 additions
and
4 deletions
+90
-4
CMakeLists.txt
CMakeLists.txt
+1
-0
CMakeLists.txt
src/CMakeLists.txt
+1
-1
BitStreamReader.hpp
src/kyut/BitStreamReader.hpp
+3
-3
CMakeLists.txt
test/CMakeLists.txt
+9
-0
test_BitStreamReader.cpp
test/test_BitStreamReader.cpp
+74
-0
test_kyut.cpp
test/test_kyut.cpp
+2
-0
No files found.
CMakeLists.txt
View file @
df1c22fa
...
@@ -25,3 +25,4 @@ include_directories(
...
@@ -25,3 +25,4 @@ include_directories(
)
)
add_subdirectory
(
src
)
add_subdirectory
(
src
)
add_subdirectory
(
test
)
src/CMakeLists.txt
View file @
df1c22fa
...
@@ -11,6 +11,6 @@ add_executable(snpi
...
@@ -11,6 +11,6 @@ add_executable(snpi
)
)
target_link_libraries
(
snpi
target_link_libraries
(
snpi
binaryen::binaryen
fmt::fmt
fmt::fmt
binaryen::binaryen
)
)
src/kyut/BitStreamReader.hpp
View file @
df1c22fa
...
@@ -40,9 +40,9 @@ namespace kyut {
...
@@ -40,9 +40,9 @@ namespace kyut {
}
}
const
auto
pos
=
pos_read_
;
const
auto
pos
=
pos_read_
;
pos_read_
=
(
pos_read_
+
1
)
%
data_
.
size
(
);
pos_read_
=
(
pos_read_
+
1
)
%
(
data_
.
size
()
*
8
);
return
(
data_
[
pos
/
8
]
>>
(
pos
%
8
))
&
1
;
return
(
(
data_
[
pos
/
8
]
<<
(
pos
%
8
))
&
0x80
)
!=
0
;
}
}
std
::
uint64_t
read
(
std
::
size_t
countBits
)
{
std
::
uint64_t
read
(
std
::
size_t
countBits
)
{
...
@@ -50,7 +50,7 @@ namespace kyut {
...
@@ -50,7 +50,7 @@ namespace kyut {
for
(
std
::
size_t
i
=
0
;
i
<
countBits
;
i
++
)
{
for
(
std
::
size_t
i
=
0
;
i
<
countBits
;
i
++
)
{
value
<<=
1
;
value
<<=
1
;
value
|=
readBit
();
value
|=
readBit
()
?
1
:
0
;
}
}
return
value
;
return
value
;
...
...
test/CMakeLists.txt
0 → 100644
View file @
df1c22fa
add_executable
(
test_kyut
test_kyut.cpp
test_BitStreamReader.cpp
)
target_link_libraries
(
test_kyut
fmt::fmt
binaryen::binaryen
)
test/test_BitStreamReader.cpp
0 → 100644
View file @
df1c22fa
#include <kyut/BitStreamReader.hpp>
#include <boost/test/unit_test.hpp>
namespace
{
constexpr
std
::
size_t
operator
""
_zu
(
unsigned
long
long
x
)
noexcept
{
return
static_cast
<
std
::
size_t
>
(
x
);
}
constexpr
std
::
uint64_t
operator
""
_u64
(
unsigned
long
long
x
)
noexcept
{
return
static_cast
<
std
::
uint64_t
>
(
x
);
}
}
// namespace
BOOST_AUTO_TEST_SUITE
(
kyut
)
BOOST_AUTO_TEST_SUITE
(
bit_stream_reader
)
BOOST_AUTO_TEST_CASE
(
read_bit
)
{
constexpr
std
::
uint8_t
data
[
1
]
=
{
0x89
};
BitStreamReader
reader
{
std
::
begin
(
data
),
std
::
end
(
data
)};
// 0x89 == 0b1000'1001
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
0
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
true
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
1
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
2
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
3
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
4
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
true
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
5
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
6
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
7
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
true
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
0
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
true
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
1
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
2
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
3
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
readBit
(),
false
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
4
_zu
);
}
BOOST_AUTO_TEST_CASE
(
read
)
{
constexpr
std
::
uint8_t
data
[
4
]
=
{
0x89
,
0xab
,
0xcd
,
0xef
};
BitStreamReader
reader
{
std
::
begin
(
data
),
std
::
end
(
data
)};
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
0
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
4
),
0x8
_u64
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
4
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
4
),
0x9
_u64
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
8
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
8
),
0xab
_u64
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
16
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
16
),
0xcdef
_u64
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
0
_zu
);
BOOST_REQUIRE_EQUAL
(
reader
.
read
(
24
),
0x89abcd
_u64
);
BOOST_REQUIRE_EQUAL
(
reader
.
tell
(),
24
_zu
);
}
BOOST_AUTO_TEST_SUITE_END
()
BOOST_AUTO_TEST_SUITE_END
()
test/test_kyut.cpp
0 → 100644
View file @
df1c22fa
#define BOOST_TEST_MAIN // Define main function in Boost::UnitTest
#include <boost/test/included/unit_test.hpp>
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