Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
tests: Add a test for the orientation threshold switch
Browse files Browse the repository at this point in the history
See #279
  • Loading branch information
hadess committed Sep 4, 2019
1 parent 818a990 commit 1400548
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/test-orientation.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,54 @@ test_orientation (void)
g_test_fail ();
}

static void
test_orientation_threshold (void)
{
static struct {
int x;
int y;
int z;
OrientationUp expected;
} orientations[] = {
{ 0, -ONEG, 0, ORIENTATION_NORMAL },
{ 183, -ONEG, 0, ORIENTATION_LEFT_UP },
{ 176, -ONEG, 0, ORIENTATION_NORMAL },
{ 183, -ONEG, 0, ORIENTATION_LEFT_UP },
};
guint i, num_failures;
OrientationUp prev;

num_failures = 0;
prev = ORIENTATION_UNDEFINED;

for (i = 0; i < G_N_ELEMENTS (orientations); i++) {
OrientationUp o;
const char *expected, *result;

o = orientation_calc (prev,
orientations[i].x,
orientations[i].y,
orientations[i].z,
9.81 / ONEG);
result = orientation_to_string (o);
expected = orientation_to_string (orientations[i].expected);
/* Fail straight away when not verbose */
if (g_test_verbose ()) {
if (g_strcmp0 (result, expected) != 0) {
g_test_message ("Expected %s, got %s (orientation #%d)", expected, result, i);
num_failures++;
}
} else {
g_assert_cmpstr (result, ==, expected);
}
g_assert_cmpstr (result, ==, expected);
prev = orientations[i].expected;
}

if (num_failures > 0)
g_test_fail ();
}

static void
test_mount_matrix_orientation (void)
{
Expand Down Expand Up @@ -171,6 +219,7 @@ int main (int argc, char **argv)

g_test_add_func ("/iio-sensor-proxy/orientation", test_orientation);
g_test_add_func ("/iio-sensor-proxy/quirking", test_mount_matrix_orientation);
g_test_add_func ("/iio-sensor-proxy/threshold", test_orientation_threshold);

return g_test_run ();
}

0 comments on commit 1400548

Please sign in to comment.