Add unit test for getting data entries. This used to crash at MAXROW.

Change-Id: Ia904f69ddebcbd61e4ad3b97a0ace3db2d3a33e7
(cherry picked from commit 4796d5dde115cc56eeddb67f38ce7b9f490e886d)
fdo#73001: Simplify the selection function logic & calculate correct results.

Fixing a bug and cleaning up the code all at the same time.  And don't forget
to write test for it as well.

Change-Id: Ia0322c4bebd4c5debcbfa4bb0902afbe581208b2
(cherry picked from commit 4a7a6b46c0dc779581f271b9e6c13c365eca7ab8)