mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
5976: Add tests for Huffman compression r=def- a=ChillerDragon 5977: Update GitHub actions versions r=def- a=rffontenelle <!-- What is the motivation for the changes of this pull request? --> The following warning is logged in the recent workflow runs: > Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: actions/checkout, actions/checkout So, this pull request updates actions/checkout version to its latest release. I haven't seen any warnings regarding CodeQL's actions but their code was updated to node.js since version 2.1.28 (see [this commit](3d23aade46
)). Same for actions/upload-artifacts, available since version 3.1.1 (see [this commit](2244c82003
)). <!-- Note that builds and other checks will be run for your change. Don't feel intimidated by failures in some of the checks. If you can't resolve them yourself, experienced devs can also resolve them before merging your pull request. --> ## Checklist - [ ] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test (especially base/) or added coverage to integration test - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: ChillerDragon <ChillerDragon@gmail.com> Co-authored-by: Rafael Fontenelle <rafaelff@gnome.org>
This commit is contained in:
commit
6da4b662be
4
.github/workflows/build.yaml
vendored
4
.github/workflows/build.yaml
vendored
|
@ -49,7 +49,7 @@ jobs:
|
||||||
LDFLAGS: /WX
|
LDFLAGS: /WX
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ jobs:
|
||||||
mv ${{ matrix.package-file }} artifacts
|
mv ${{ matrix.package-file }} artifacts
|
||||||
|
|
||||||
- name: Upload Artifacts
|
- name: Upload Artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: ddnet-${{ matrix.os }}
|
name: ddnet-${{ matrix.os }}
|
||||||
path: release/artifacts
|
path: release/artifacts
|
||||||
|
|
2
.github/workflows/clang-sanitizer.yml
vendored
2
.github/workflows/clang-sanitizer.yml
vendored
|
@ -13,7 +13,7 @@ jobs:
|
||||||
check-clang-san:
|
check-clang-san:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
|
|
||||||
|
|
2
.github/workflows/clang-tidy.yml
vendored
2
.github/workflows/clang-tidy.yml
vendored
|
@ -13,7 +13,7 @@ jobs:
|
||||||
check-clang-tidy:
|
check-clang-tidy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
|
|
||||||
|
|
6
.github/workflows/codeql-analysis.yaml
vendored
6
.github/workflows/codeql-analysis.yaml
vendored
|
@ -30,7 +30,7 @@ jobs:
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ jobs:
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@v1
|
uses: github/codeql-action/init@v2
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
@ -59,4 +59,4 @@ jobs:
|
||||||
cmake --build . --config RelWithDebInfo --target everything
|
cmake --build . --config RelWithDebInfo --target everything
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/analyze@v2
|
||||||
|
|
2
.github/workflows/style.yml
vendored
2
.github/workflows/style.yml
vendored
|
@ -13,7 +13,7 @@ jobs:
|
||||||
check-style:
|
check-style:
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- name: Prepare
|
- name: Prepare
|
||||||
|
|
|
@ -2515,6 +2515,7 @@ if(GTEST_FOUND OR DOWNLOAD_GTEST)
|
||||||
fs.cpp
|
fs.cpp
|
||||||
git_revision.cpp
|
git_revision.cpp
|
||||||
hash.cpp
|
hash.cpp
|
||||||
|
huffman.cpp
|
||||||
io.cpp
|
io.cpp
|
||||||
jobs.cpp
|
jobs.cpp
|
||||||
json.cpp
|
json.cpp
|
||||||
|
|
48
src/test/huffman.cpp
Normal file
48
src/test/huffman.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <base/system.h>
|
||||||
|
#include <engine/shared/huffman.h>
|
||||||
|
|
||||||
|
TEST(Huffman, CompressionShouldNotChangeData)
|
||||||
|
{
|
||||||
|
CHuffman Huffman;
|
||||||
|
Huffman.Init();
|
||||||
|
|
||||||
|
unsigned char aInput[64];
|
||||||
|
unsigned char aCompressed[2048];
|
||||||
|
|
||||||
|
mem_zero(aInput, sizeof(aInput));
|
||||||
|
mem_zero(aCompressed, sizeof(aCompressed));
|
||||||
|
|
||||||
|
int Size = Huffman.Compress(aInput, sizeof(aInput), aCompressed, sizeof(aCompressed));
|
||||||
|
|
||||||
|
unsigned char aDecompressed[2048];
|
||||||
|
Huffman.Decompress(aCompressed, sizeof(aCompressed), aDecompressed, sizeof(aDecompressed));
|
||||||
|
|
||||||
|
int match = mem_comp(aInput, aDecompressed, Size);
|
||||||
|
EXPECT_EQ(match, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(Huffman, CompressionCompatible)
|
||||||
|
{
|
||||||
|
CHuffman Huffman;
|
||||||
|
Huffman.Init();
|
||||||
|
|
||||||
|
unsigned char aInput[64];
|
||||||
|
unsigned char aCompressed[2048];
|
||||||
|
|
||||||
|
mem_zero(aInput, sizeof(aInput));
|
||||||
|
mem_zero(aCompressed, sizeof(aCompressed));
|
||||||
|
|
||||||
|
// compress 1-7 followed by a bunch of nullbytes
|
||||||
|
for(int i = 0; i < 8; i++)
|
||||||
|
aInput[i] = i;
|
||||||
|
|
||||||
|
int Size = Huffman.Compress(aInput, sizeof(aInput), aCompressed, sizeof(aCompressed));
|
||||||
|
|
||||||
|
unsigned char aExpected[] = {0x51, 0x58, 0x78, 0x76, 0x1B, 0xB7, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xc5, 0x0D};
|
||||||
|
|
||||||
|
int match = mem_comp(aCompressed, aExpected, Size);
|
||||||
|
EXPECT_EQ(match, 0) << "The compression is not compatible with older/other implementations anymore";
|
||||||
|
EXPECT_EQ(Size, 15);
|
||||||
|
}
|
Loading…
Reference in a new issue