diff --git a/tests/Makefile.am b/tests/Makefile.am index 9857a7e..ab666e8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -7,6 +7,7 @@ TESTS = \ libx52/test_leds.sh \ libx52/test_brightness.sh \ libx52/test_indicator.sh \ + libx52/test_mfd.sh \ libx52/test_clock.sh EXTRA_DIST = common_infra.sh $(TESTS) diff --git a/tests/common_infra.sh b/tests/common_infra.sh index 90a6576..c75c82c 100644 --- a/tests/common_infra.sh +++ b/tests/common_infra.sh @@ -64,6 +64,13 @@ X52_CLOCK_3_INDEX='00c2' X52_CLOCK_DATE_INDEX='00c4' X52_CLOCK_YEAR_INDEX='00c8' +X52_MFD_LINE_0_SET_INDEX='00d1' +X52_MFD_LINE_1_SET_INDEX='00d2' +X52_MFD_LINE_2_SET_INDEX='00d4' +X52_MFD_LINE_0_CLR_INDEX='00d9' +X52_MFD_LINE_1_CLR_INDEX='00da' +X52_MFD_LINE_2_CLR_INDEX='00dc' + find_programs() { # Tests and distcheck do not work on OSX, skip the tests diff --git a/tests/libx52/test_mfd.sh b/tests/libx52/test_mfd.sh new file mode 100644 index 0000000..2537879 --- /dev/null +++ b/tests/libx52/test_mfd.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +source $(dirname $0)/../common_infra.sh + +TEST_SUITE_ID="libx52 MFD text tests" + +# Take in input as a string, and convert them to list of MFD set format +format_text() +{ + local clear_index=`eval echo $1` + local set_index=`eval echo $2` + local input_string=$3 + local output_list="$clear_index 0" + local count=0 + + while [[ ${#input_string} -gt 1 ]] + do + char1=${input_string:0:1} + char2=${input_string:1:1} + input_string=${input_string:2} + output_list="$output_list $set_index $(printf '%02x%02x' \'$char2 \'$char1)" + ((count+=2)) + + # The library ignores strings longer than 16 characters + if [[ $count -eq 16 ]] + then + # Discard the rest of the input string + input_string= + fi + done + + if [[ ${#input_string} -eq 1 ]] + then + # Add the remaining character, but pad with a space + output_list="$output_list $set_index $(printf '20%02x' \'$input_string)" + fi + + echo $output_list + return 0 +} + +mfd_text_test() +{ + local line=$1 + local clear_index="\$X52_MFD_LINE_${line}_CLR_INDEX" + local set_index="\$X52_MFD_LINE_${line}_SET_INDEX" + local text="$2" + TEST_ID="Test setting MFD line $line to '$text'" + + set -x + pattern=$(format_text $clear_index $set_index "$text") + expect_pattern $pattern + set +x + + $X52CLI mfd $line "$text" + + verify_output +} + +for text in \ + a \ + ab \ + abc \ + abcd \ + abcde \ + abcdef \ + abcdefg \ + abcdefgh \ + abcdefghi \ + abcdefghij \ + abcdefghijk \ + abcdefghijkl \ + abcdefghijklm \ + abcdefghijklmn \ + abcdefghijklmno \ + abcdefghijklmnop \ + abcdefghijklmnopq \ + abcdefghijklmnopqr \ + ; +do + for line in 0 1 2 + do + mfd_text_test $line "$text" + done +done + +verify_test_suite +