Add test cases for MFD text

feature/test-new-mem-api
nirenjan 2017-08-14 22:58:22 -07:00
parent 2e96378f80
commit b5f4e72148
3 changed files with 96 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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