-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make all hal::Can::Id functions constexpr and add static assert…
… tests (#803) * feat: make all hal::Can::Id functions constexpr and add static assert tests * chore: separate implementation from declaration * Update hal/interfaces/Can.hpp
- Loading branch information
1 parent
6284b6f
commit 6184a66
Showing
4 changed files
with
104 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,65 @@ | ||
#include "hal/interfaces/Can.hpp" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
|
||
static_assert(hal::Can::Id::Create11BitId(0).Is11BitId()); | ||
static_assert(!hal::Can::Id::Create11BitId(0).Is29BitId()); | ||
static_assert(hal::Can::Id::Create11BitId(0).Get11BitId() == 0); | ||
|
||
static_assert(!hal::Can::Id::Create29BitId(0).Is11BitId()); | ||
static_assert(hal::Can::Id::Create29BitId(0).Is29BitId()); | ||
static_assert(hal::Can::Id::Create29BitId(0).Get29BitId() == 0); | ||
|
||
static_assert(hal::Can::Id::Create11BitId(0) == hal::Can::Id::Create11BitId(0)); | ||
static_assert(hal::Can::Id::Create11BitId(0) != hal::Can::Id::Create11BitId(1)); | ||
static_assert(hal::Can::Id::Create11BitId(0) != hal::Can::Id::Create29BitId(0)); | ||
|
||
static_assert(hal::Can::Id::Create29BitId(2) == hal::Can::Id::Create29BitId(2)); | ||
static_assert(hal::Can::Id::Create29BitId(2) != hal::Can::Id::Create29BitId(1)); | ||
static_assert(hal::Can::Id::Create29BitId(2) != hal::Can::Id::Create11BitId(2)); | ||
|
||
TEST(CanTest, generate_11_bit_id) | ||
{ | ||
auto id = hal::Can::Id::Create11BitId(0); | ||
const auto id = hal::Can::Id::Create11BitId(0); | ||
|
||
EXPECT_TRUE(id.Is11BitId()); | ||
EXPECT_EQ(0, id.Get11BitId()); | ||
EXPECT_THAT(id.Is11BitId(), testing::IsTrue()); | ||
EXPECT_THAT(id.Is29BitId(), testing::IsFalse()); | ||
EXPECT_THAT(id.Get11BitId(), testing::Eq(0)); | ||
} | ||
|
||
TEST(CanTest, generate_29_bit_id) | ||
{ | ||
auto id = hal::Can::Id::Create29BitId(0); | ||
const auto id = hal::Can::Id::Create29BitId(0); | ||
|
||
EXPECT_TRUE(id.Is29BitId()); | ||
EXPECT_EQ(0, id.Get29BitId()); | ||
EXPECT_THAT(id.Is29BitId(), testing::IsTrue()); | ||
EXPECT_THAT(id.Is11BitId(), testing::IsFalse()); | ||
EXPECT_THAT(id.Get29BitId(), testing::Eq(0)); | ||
} | ||
|
||
TEST(CanTest, test_equality_mixed) | ||
{ | ||
auto id11_0 = hal::Can::Id::Create11BitId(0); | ||
auto id11_1 = hal::Can::Id::Create11BitId(1); | ||
auto id29_0 = hal::Can::Id::Create29BitId(0); | ||
auto id29_1 = hal::Can::Id::Create29BitId(1); | ||
|
||
EXPECT_TRUE(id11_0 == hal::Can::Id::Create11BitId(0)); | ||
EXPECT_TRUE(id11_0 != id11_1); | ||
EXPECT_TRUE(id11_0 != id29_0); | ||
EXPECT_TRUE(id11_0 != id29_1); | ||
|
||
EXPECT_TRUE(id11_1 != id11_0); | ||
EXPECT_TRUE(id11_1 == hal::Can::Id::Create11BitId(1)); | ||
EXPECT_TRUE(id11_1 != id29_0); | ||
EXPECT_TRUE(id11_1 != id29_1); | ||
|
||
EXPECT_TRUE(id29_0 != id11_0); | ||
EXPECT_TRUE(id29_0 != id11_1); | ||
EXPECT_TRUE(id29_0 == hal::Can::Id::Create29BitId(0)); | ||
EXPECT_TRUE(id29_0 != id29_1); | ||
|
||
EXPECT_TRUE(id29_1 != id11_0); | ||
EXPECT_TRUE(id29_1 != id11_1); | ||
EXPECT_TRUE(id29_1 != id29_0); | ||
EXPECT_TRUE(id29_1 == hal::Can::Id::Create29BitId(1)); | ||
const auto id11_0 = hal::Can::Id::Create11BitId(0); | ||
const auto id11_1 = hal::Can::Id::Create11BitId(1); | ||
const auto id29_0 = hal::Can::Id::Create29BitId(0); | ||
const auto id29_1 = hal::Can::Id::Create29BitId(1); | ||
|
||
EXPECT_THAT(id11_0, testing::Eq(hal::Can::Id::Create11BitId(0))); | ||
EXPECT_THAT(id11_0, testing::Ne(id11_1)); | ||
EXPECT_THAT(id11_0, testing::Ne(id29_0)); | ||
EXPECT_THAT(id11_0, testing::Ne(id29_1)); | ||
|
||
EXPECT_THAT(id11_1, testing::Ne(id11_0)); | ||
EXPECT_THAT(id11_1, testing::Eq(hal::Can::Id::Create11BitId(1))); | ||
EXPECT_THAT(id11_1, testing::Ne(id29_0)); | ||
EXPECT_THAT(id11_1, testing::Ne(id29_1)); | ||
|
||
EXPECT_THAT(id29_0, testing::Ne(id11_0)); | ||
EXPECT_THAT(id29_0, testing::Ne(id11_1)); | ||
EXPECT_THAT(id29_0, testing::Eq(hal::Can::Id::Create29BitId(0))); | ||
EXPECT_THAT(id29_0, testing::Ne(id29_1)); | ||
|
||
EXPECT_THAT(id29_1, testing::Ne(id11_0)); | ||
EXPECT_THAT(id29_1, testing::Ne(id11_1)); | ||
EXPECT_THAT(id29_1, testing::Ne(id29_0)); | ||
EXPECT_THAT(id29_1, testing::Eq(hal::Can::Id::Create29BitId(1))); | ||
} |