diff options
author | michael-west <michael.west@ettus.com> | 2018-10-18 22:56:03 -0700 |
---|---|---|
committer | Brent Stapleton <bstapleton@g.hmc.edu> | 2018-10-25 09:57:16 -0700 |
commit | e9077d3452b1d3204b34ac5ce5125c6f70fc2ac6 (patch) | |
tree | b4a668fd33a080cb07f89e33a579e2fcb395b0d1 /host | |
parent | adfd3d9598eb23751cd9a7a53acce6c16261e828 (diff) | |
download | uhd-e9077d3452b1d3204b34ac5ce5125c6f70fc2ac6.tar.gz uhd-e9077d3452b1d3204b34ac5ce5125c6f70fc2ac6.tar.bz2 uhd-e9077d3452b1d3204b34ac5ce5125c6f70fc2ac6.zip |
Test: Add unit test for eeprom_utils
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/include/uhdlib/utils/eeprom_utils.hpp | 2 | ||||
-rw-r--r-- | host/lib/usrp/x300/x300_mb_eeprom.cpp | 2 | ||||
-rw-r--r-- | host/tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/tests/eeprom_utils_test.cpp | 60 |
4 files changed, 63 insertions, 2 deletions
diff --git a/host/lib/include/uhdlib/utils/eeprom_utils.hpp b/host/lib/include/uhdlib/utils/eeprom_utils.hpp index 3071fd745..5104e1530 100644 --- a/host/lib/include/uhdlib/utils/eeprom_utils.hpp +++ b/host/lib/include/uhdlib/utils/eeprom_utils.hpp @@ -1,5 +1,5 @@ // -// Copyright 2017 Ettus Research (National Instruments Corp.) +// Copyright 2017-18 Ettus Research (National Instruments Corp.) // // SPDX-License-Identifier: GPL-3.0-or-later // diff --git a/host/lib/usrp/x300/x300_mb_eeprom.cpp b/host/lib/usrp/x300/x300_mb_eeprom.cpp index 7bff3d782..26f7f7913 100644 --- a/host/lib/usrp/x300/x300_mb_eeprom.cpp +++ b/host/lib/usrp/x300/x300_mb_eeprom.cpp @@ -1,5 +1,5 @@ // -// Copyright 2017 Ettus Research (National Instruments Corp.) +// Copyright 2017-18 Ettus Research (National Instruments Corp.) // // SPDX-License-Identifier: GPL-3.0-or-later // diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index ba0484e86..44c042f65 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -23,6 +23,7 @@ SET(test_sources constrained_device_args_test.cpp convert_test.cpp dict_test.cpp + eeprom_utils_test.cpp error_test.cpp fp_compare_delta_test.cpp fp_compare_epsilon_test.cpp diff --git a/host/tests/eeprom_utils_test.cpp b/host/tests/eeprom_utils_test.cpp new file mode 100644 index 000000000..4407ad4e4 --- /dev/null +++ b/host/tests/eeprom_utils_test.cpp @@ -0,0 +1,60 @@ +// +// Copyright 2018 Ettus Research, a National Instruments Company +// +// SPDX-License-Identifier: GPL-3.0-or-later +// + +#include <boost/test/unit_test.hpp> +#include <uhdlib/utils/eeprom_utils.hpp> +#include <boost/assign/list_of.hpp> + +using namespace boost::assign; + +class upper_case_char { +public: + upper_case_char(char ch) {value = ch;} + 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); + } +private: + char value; +}; + +BOOST_AUTO_TEST_CASE(test_eeprom_duplicate_check) +{ + 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"}; + + BOOST_CHECK_EQUAL(check_for_duplicates<upper_case_char>( + "TEST", new_eeprom_no_dups, curr_eeprom, "Test Value", keys), false); + 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)); +} |