From e9077d3452b1d3204b34ac5ce5125c6f70fc2ac6 Mon Sep 17 00:00:00 2001 From: michael-west Date: Thu, 18 Oct 2018 22:56:03 -0700 Subject: Test: Add unit test for eeprom_utils --- host/lib/include/uhdlib/utils/eeprom_utils.hpp | 2 +- host/lib/usrp/x300/x300_mb_eeprom.cpp | 2 +- host/tests/CMakeLists.txt | 1 + host/tests/eeprom_utils_test.cpp | 60 ++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 host/tests/eeprom_utils_test.cpp (limited to 'host') 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 +#include +#include + +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 curr_eeprom = map_list_of + ("0","A") + ("1","B") + ("2","C") + ; + const uhd::dict new_eeprom_no_dups = map_list_of + ("0","d") + ("1","e") + ; + const uhd::dict new_eeprom_dups_in_curr = map_list_of + ("0","b") + ; + const uhd::dict new_eeprom_dups_in_new = map_list_of + ("0","c") + ("1","c") + ; + const uhd::dict new_eeprom_dups_in_both = map_list_of + ("0","b") + ("1","B") + ; + const std::vector keys = {"0","1","2"}; + + BOOST_CHECK_EQUAL(check_for_duplicates( + "TEST", new_eeprom_no_dups, curr_eeprom, "Test Value", keys), false); + BOOST_CHECK(check_for_duplicates( + "TEST", new_eeprom_dups_in_curr, curr_eeprom, "Test Value", keys)); + BOOST_CHECK(check_for_duplicates( + "TEST", new_eeprom_dups_in_new, curr_eeprom, "Test Value", keys)); + BOOST_CHECK(check_for_duplicates( + "TEST", new_eeprom_dups_in_both, curr_eeprom, "Test Value", keys)); +} -- cgit v1.2.3