2018-10-19 05:56:03 +00:00
|
|
|
//
|
|
|
|
|
// Copyright 2018 Ettus Research, a National Instruments Company
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include <uhdlib/utils/eeprom_utils.hpp>
|
|
|
|
|
#include <boost/assign/list_of.hpp>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2018-10-19 05:56:03 +00:00
|
|
|
|
|
|
|
|
using namespace boost::assign;
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
class upper_case_char
|
|
|
|
|
{
|
2018-10-19 05:56:03 +00:00
|
|
|
public:
|
2019-01-14 18:35:25 +00:00
|
|
|
upper_case_char(char ch)
|
|
|
|
|
{
|
|
|
|
|
value = ch;
|
|
|
|
|
}
|
2018-10-19 05:56:03 +00:00
|
|
|
static upper_case_char from_string(std::string str)
|
|
|
|
|
{
|
|
|
|
|
return upper_case_char(toupper(str[0]));
|
|
|
|
|
}
|
|
|
|
|
std::string to_string()
|
|
|
|
|
{
|
|
|
|
|
return std::string(1, value);
|
|
|
|
|
}
|
2019-01-14 18:35:25 +00:00
|
|
|
|
2018-10-19 05:56:03 +00:00
|
|
|
private:
|
|
|
|
|
char value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_eeprom_duplicate_check)
|
|
|
|
|
{
|
2019-01-14 18:35:25 +00:00
|
|
|
const uhd::dict<std::string, std::string> curr_eeprom =
|
|
|
|
|
map_list_of("0", "A")("1", "B")("2", "C");
|
|
|
|
|
const uhd::dict<std::string, std::string> new_eeprom_no_dups =
|
|
|
|
|
map_list_of("0", "d")("1", "e");
|
|
|
|
|
const uhd::dict<std::string, std::string> new_eeprom_dups_in_curr =
|
|
|
|
|
map_list_of("0", "b");
|
|
|
|
|
const uhd::dict<std::string, std::string> new_eeprom_dups_in_new =
|
|
|
|
|
map_list_of("0", "c")("1", "c");
|
|
|
|
|
const uhd::dict<std::string, std::string> new_eeprom_dups_in_both =
|
|
|
|
|
map_list_of("0", "b")("1", "B");
|
|
|
|
|
const std::vector<std::string> keys = {"0", "1", "2"};
|
2018-10-19 05:56:03 +00:00
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(check_for_duplicates<upper_case_char>(
|
2019-01-14 18:35:25 +00:00
|
|
|
"TEST", new_eeprom_no_dups, curr_eeprom, "Test Value", keys),
|
|
|
|
|
false);
|
2018-10-19 05:56:03 +00:00
|
|
|
BOOST_CHECK(check_for_duplicates<upper_case_char>(
|
|
|
|
|
"TEST", new_eeprom_dups_in_curr, curr_eeprom, "Test Value", keys));
|
|
|
|
|
BOOST_CHECK(check_for_duplicates<upper_case_char>(
|
|
|
|
|
"TEST", new_eeprom_dups_in_new, curr_eeprom, "Test Value", keys));
|
|
|
|
|
BOOST_CHECK(check_for_duplicates<upper_case_char>(
|
|
|
|
|
"TEST", new_eeprom_dups_in_both, curr_eeprom, "Test Value", keys));
|
|
|
|
|
}
|