-
-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified test suit names
- Loading branch information
John Wellbelove
committed
Dec 7, 2023
1 parent
6a48eef
commit 4b97e82
Showing
15 changed files
with
253 additions
and
10 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 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 |
---|---|---|
@@ -0,0 +1,105 @@ | ||
///\file | ||
|
||
/****************************************************************************** | ||
The MIT License(MIT) | ||
Embedded Template Library. | ||
https://github.com/ETLCPP/etl | ||
https://www.etlcpp.com | ||
Copyright(c) 2023 John Wellbelove | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files(the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions : | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
******************************************************************************/ | ||
|
||
#ifndef ETL_CRC1_INCLUDED | ||
#define ETL_CRC1_INCLUDED | ||
|
||
#include "platform.h" | ||
#include "frame_check_sequence.h" | ||
#include "binary.h" | ||
|
||
namespace etl | ||
{ | ||
//*************************************************************************** | ||
/// fnv_1 policy. | ||
/// Calculates FNV1. | ||
//*************************************************************************** | ||
struct crc1_policy | ||
{ | ||
typedef uint8_t value_type; | ||
|
||
enum | ||
{ | ||
Odd_Parity = 1, | ||
Even_Parity = 0 | ||
}; | ||
|
||
//********************************* | ||
value_type initial() const | ||
{ | ||
return Even_Parity; | ||
} | ||
|
||
//********************************* | ||
uint8_t add(int parity, uint8_t value) const | ||
{ | ||
return parity ^ etl::parity(value); | ||
} | ||
|
||
//********************************* | ||
uint8_t final(uint8_t parity) const | ||
{ | ||
return parity; | ||
} | ||
}; | ||
|
||
class crc1 : public etl::frame_check_sequence<crc1_policy> | ||
{ | ||
public: | ||
|
||
enum | ||
{ | ||
Odd_Parity = crc1_policy::Odd_Parity, | ||
Even_Parity = crc1_policy::Even_Parity | ||
}; | ||
|
||
//************************************************************************* | ||
/// Default constructor. | ||
//************************************************************************* | ||
crc1() | ||
{ | ||
this->reset(); | ||
} | ||
|
||
//************************************************************************* | ||
/// Constructor from range. | ||
/// \param begin Start of the range. | ||
/// \param end End of the range. | ||
//************************************************************************* | ||
template<typename TIterator> | ||
crc1(TIterator begin, const TIterator end) | ||
{ | ||
this->reset(); | ||
this->add(begin, end); | ||
} | ||
}; | ||
} | ||
|
||
#endif |
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 |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/****************************************************************************** | ||
The MIT License(MIT) | ||
Embedded Template Library. | ||
https://github.com/ETLCPP/etl | ||
https://www.etlcpp.com | ||
Copyright(c) 2023 John Wellbelove | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files(the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions : | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
******************************************************************************/ | ||
|
||
#include "unit_test_framework.h" | ||
|
||
#include <iterator> | ||
#include <string> | ||
#include <vector> | ||
#include <stdint.h> | ||
|
||
#include "etl/crc1.h" | ||
|
||
namespace | ||
{ | ||
//*************************************************************************** | ||
template <typename TIterator> | ||
int calculate_parity(TIterator b, TIterator e) | ||
{ | ||
size_t count = 0; | ||
|
||
while (b != e) | ||
{ | ||
count += etl::count_bits(*b); | ||
++b; | ||
} | ||
|
||
return ((count &= 1) == 0) ? etl::crc1::Even_Parity : etl::crc1::Odd_Parity; | ||
} | ||
|
||
SUITE(test_crc1) | ||
{ | ||
//************************************************************************* | ||
TEST(test_crc1_constructor) | ||
{ | ||
std::string data("123456789"); | ||
|
||
uint8_t crc = etl::crc1(data.begin(), data.end()); | ||
|
||
CHECK_EQUAL(calculate_parity(data.begin(), data.end()), int(crc)); | ||
} | ||
|
||
//************************************************************************* | ||
TEST(test_crc1_add_values) | ||
{ | ||
std::string data("123456789"); | ||
|
||
etl::crc1 crc_calculator; | ||
|
||
for (size_t i = 0UL; i < data.size(); ++i) | ||
{ | ||
crc_calculator.add(data[i]); | ||
} | ||
|
||
uint8_t crc = crc_calculator; | ||
|
||
CHECK_EQUAL(calculate_parity(data.begin(), data.end()), int(crc)); | ||
} | ||
|
||
//************************************************************************* | ||
TEST(test_crc1_add_range) | ||
{ | ||
std::string data("123456789"); | ||
|
||
etl::crc1 crc_calculator; | ||
|
||
crc_calculator.add(data.begin(), data.end()); | ||
|
||
uint8_t crc = crc_calculator.value(); | ||
|
||
CHECK_EQUAL(calculate_parity(data.begin(), data.end()), int(crc)); | ||
} | ||
|
||
//************************************************************************* | ||
TEST(test_crc1_add_range_via_iterator) | ||
{ | ||
std::string data("123456789"); | ||
|
||
etl::crc1 crc_calculator; | ||
|
||
std::copy(data.begin(), data.end(), crc_calculator.input()); | ||
|
||
uint8_t crc = crc_calculator.value(); | ||
|
||
CHECK_EQUAL(calculate_parity(data.begin(), data.end()), int(crc)); | ||
} | ||
|
||
//************************************************************************* | ||
TEST(test_crc1_add_range_endian) | ||
{ | ||
std::vector<uint8_t> data1 = { 0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08U }; | ||
std::vector<uint32_t> data2 = { 0x04030201UL, 0x08070605UL }; | ||
std::vector<uint8_t> data3 = { 0x08U, 0x07U, 0x06U, 0x05U, 0x04U, 0x03U, 0x02U, 0x01U }; | ||
|
||
uint8_t crc1 = etl::crc1(data1.begin(), data1.end()); | ||
uint8_t crc2 = etl::crc1((uint8_t*)&data2[0], (uint8_t*)(&data2[0] + data2.size())); | ||
CHECK_EQUAL(int(crc1), int(crc2)); | ||
|
||
uint8_t crc3 = etl::crc1(data3.rbegin(), data3.rend()); | ||
CHECK_EQUAL(int(crc1), int(crc3)); | ||
} | ||
}; | ||
} | ||
|
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
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
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
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
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
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