Skip to content

Commit

Permalink
wording, formatting, minor
Browse files Browse the repository at this point in the history
  • Loading branch information
windytan committed Aug 6, 2024
1 parent d998e75 commit 6436165
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
32 changes: 17 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,33 +41,35 @@ CI pipeline in place to ensure that the build works and no basic functionality
breaks. So no worries. Our maintainer can help complete the PR as time allows.
However, note that this is still a hobby project.

Let's face it, C++ is memory-unsafe and not the easiest language at that. But
there are things we can do to make it safer and more usable for us:

* Squashed commits with clear and concise [commit messages](https://www.gitkraken.com/learn/git/best-practices/git-commit-message) are preferred. Use force-push to update the PR branch if necessary.
* Since 1.0, we wish to have tests in repo for all new features or bugfixes. The tests
can be unit tests written in [Catch2](https://github.com/catchorg/Catch2/) (see `test/unit.cc`),
or they can be end-to-end tests against the CLI executable itself (some Perl examples
in `test/cli.pl`). Perl is only used for testing; all code should pass Perl::Critic
level 3.
* C++ style is described in `.clang-format`, but this is not strict and serious for
every commit.
* But we are serious about C++14 compatibility, so unfortunately more modern
features can't be used.
* C++ style is described in `.clang-format`; format-on-save is recommended.
* We aim for C++14 compatibility, so unfortunately more modern features can't be used.
* We have some static analysis rules described in `.clang-tidy`.
* Keep in mind redsea has a real-time requirement and it might be run on some
low-end 32-bit embedded platform. Unfortunately we don't have automated tests for
this.
* Try to avoid resorting to manual memory management. We have an address sanitizer in
CI but currently no leak checks.
* Some design philosophy:
* Each JSON line should somehow correspond to a single RDS group. But this may
well change in the future, for any good reason.
* All JSON output should validate successfully against `schema.json`.
* Data spread over multiple groups should be withdrawn until fully received, unless
the user specifies the `--show-partial` option.
* The hex output should be compatible with RDS Spy, the (unaffiliated) Windows GUI software. (Yes,
it's difficult to automate this test)
* GUI features are outside of our scope
* Preferably redsea should not create any files in the file system; instead all
output should be via stdout if possible

Some design philosophy:
* Each JSON line should somehow correspond to a single RDS group. But this may
well change in the future, for any good reason.
* All JSON output should validate successfully against `schema.json`.
* Data spread over multiple groups should be withdrawn until fully received, unless
the user specifies the `--show-partial` option.
* The hex output should be compatible with RDS Spy, the (unaffiliated) Windows GUI software. (Yes,
it's difficult to automate this test)
* GUI features are outside of our scope
* Preferably redsea should not create any files in the file system; instead all
output should be via stdout if possible

The project uses [semantic versioning](https://semver.org/).

Expand Down
2 changes: 1 addition & 1 deletion test/cli.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package cli;

use warnings;
use strict;
use IPC::Cmd qw(can_run);
use IPC::Cmd qw/can_run/;
use Carp;
use utf8;
use open qw/:std :utf8/;
Expand Down
32 changes: 16 additions & 16 deletions test/unit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@
#include "test_helpers.h"

TEST_CASE("Bitfield extraction") {
const std::uint16_t block1{0x1234};
const std::uint16_t block2{0x5678};
constexpr std::uint16_t block1{0b0001'0010'0011'0100};
constexpr std::uint16_t block2{0b0101'0110'0111'1000};

SECTION("Works with single block") {
CHECK(redsea::getBits<4>(block1, 0) == 4);
CHECK(redsea::getBits<4>(block1, 0) == 0b0100);

CHECK(redsea::getBits<5>(block1, 4) == 0x3);
CHECK(redsea::getBits<6>(block1, 4) == 0x23);
CHECK(redsea::getBits<8>(block1, 4) == 0x23);
CHECK(redsea::getBits<9>(block1, 4) == 0x123);
CHECK(redsea::getBits<5>(block1, 4) == 0b0'0011);
CHECK(redsea::getBits<6>(block1, 4) == 0b10'0011);
CHECK(redsea::getBits<8>(block1, 4) == 0b0010'0011);
CHECK(redsea::getBits<9>(block1, 4) == 0b1'0010'0011);

CHECK(redsea::getBits<5>(block1, 5) == 0x11);
CHECK(redsea::getBits<8>(block1, 5) == 0x91);
CHECK(redsea::getBits<5>(block1, 5) == 0b10'001);
CHECK(redsea::getBits<8>(block1, 5) == 0b1'0010'001);

CHECK(redsea::getBool(block1, 12) == true);
}

SECTION("Works with concatenation of two blocks") {
CHECK(redsea::getBits<4>(block1, block2, 0) == 8);
CHECK(redsea::getBits<4>(block1, block2, 0) == 0b1000);

CHECK(redsea::getBits<5>(block1, block2, 4) == 0x7);
CHECK(redsea::getBits<6>(block1, block2, 4) == 0x27);
CHECK(redsea::getBits<8>(block1, block2, 4) == 0x67);
CHECK(redsea::getBits<9>(block1, block2, 4) == 0x167);
CHECK(redsea::getBits<5>(block1, block2, 4) == 0b0'0111);
CHECK(redsea::getBits<6>(block1, block2, 4) == 0b10'0111);
CHECK(redsea::getBits<8>(block1, block2, 4) == 0b0110'0111);
CHECK(redsea::getBits<9>(block1, block2, 4) == 0b1'0110'0111);

CHECK(redsea::getBits<12>(block1, block2, 8) == 0x456);
CHECK(redsea::getBits<12>(block1, block2, 9) == 0xA2B);
CHECK(redsea::getBits<12>(block1, block2, 8) == 0b0100'0101'0110);
CHECK(redsea::getBits<12>(block1, block2, 9) == 0b1'0100'0101'011);
}
}

Expand Down

0 comments on commit 6436165

Please sign in to comment.