| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | // | |||
| 2 | // Created by kifir on 11/12/24. | |||
| 3 | // | |||
| 4 | ||||
| 5 | #include "pch.h" | |||
| 6 | ||||
| 7 | #include "rusefi_lua.h" | |||
| 8 | #include "lua_lib.h" | |||
| 9 | ||||
| 10 | namespace { | |||
| 11 | class LuaBitRangeMsbTest : public testing::Test { | |||
| 12 | protected: | |||
| 13 | void checkSetAndGet(int bitStart, int length, int testValue); | |||
| 14 | }; | |||
| 15 | ||||
| 16 | 8 | void LuaBitRangeMsbTest::checkSetAndGet(const int bitStart, const int length, const int testValue) { | ||
| 17 | 8 | const char* const luaCodeFormatString = SET_BIT_RANGE_MSB GET_BIT_RANGE_MSB R"( | ||
| 18 | ||||
| 19 | function testFunc() | |||
| 20 | data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} | |||
| 21 | setBitRangeMsb(data, %d, %d, %d) | |||
| 22 | return getBitRangeMsb(data, %d, %d) | |||
| 23 | end)"; | |||
| 24 | 8 | char luaCode[4096]; | ||
| 25 | 8 | std::snprintf(luaCode, sizeof(luaCode), luaCodeFormatString, bitStart, length, testValue, bitStart, length); | ||
| 26 |
3/7✓ Branch 3 taken 8 times.
✓ Branch 7 taken 8 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 8 times.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
8 | EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(luaCode).value_or(0), testValue) | |
| 27 |
0/8✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
8 | << "bitStart=" << bitStart << ", length=" << length << ", testValue=" << testValue << std::endl << luaCode; | |
| 28 | 8 | } | ||
| 29 | ||||
| 30 | 4 | TEST_F(LuaBitRangeMsbTest, checkVariousBitRanges) { | ||
| 31 | 1 | checkSetAndGet(24, 4, 0xB); | ||
| 32 | 1 | checkSetAndGet(24, 7, 0x59); | ||
| 33 | 1 | checkSetAndGet(24, 8, 0xB3); | ||
| 34 | 1 | checkSetAndGet(24, 10, 0x2C9); | ||
| 35 | 1 | checkSetAndGet(24, 9, 0x173); | ||
| 36 | 1 | checkSetAndGet(22, 8, 0xB3); | ||
| 37 | 1 | checkSetAndGet(22, 9, 0x167); | ||
| 38 | 1 | checkSetAndGet(23, 8, 0xB3); | ||
| 39 | 1 | } | ||
| 40 | ||||
| 41 | 4 | TEST_F(LuaBitRangeMsbTest, checkWithTotalBitIndex22AndBitWidth8) { | ||
| 42 | 1 | const char* realdata = SET_BIT_RANGE_MSB GET_BIT_RANGE_MSB R"( | ||
| 43 | ||||
| 44 | function testFunc() | |||
| 45 | data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} | |||
| 46 | setBitRangeMsb(data, 22, 8, 0xB3) | |||
| 47 | return getBitRangeMsb(data, 22, 8) | |||
| 48 | end)"; | |||
| 49 | ||||
| 50 |
3/7✓ Branch 3 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 12 taken 1 time.
✗ Branch 15 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0xB3); | |
| 51 | 1 | } | ||
| 52 | } | |||
| 53 |