Skip to content

Commit 8c7e9a5

Browse files
JordanYateskartben
authored andcommitted
tests: sensor: generic: test new conversions
Add tests for `sensor_value_to_deci` and `sensor_value_to_centi`. Signed-off-by: Jordan Yates <[email protected]>
1 parent 9286b0b commit 8c7e9a5

File tree

1 file changed

+14
-0
lines changed
  • tests/drivers/sensor/generic/src

1 file changed

+14
-0
lines changed

tests/drivers/sensor/generic/src/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,32 @@ ZTEST(sensor_api, test_sensor_unit_conversion)
329329
/* reset test data to positive value */
330330
data.val1 = 3;
331331
data.val2 = 300000;
332+
zassert_equal(sensor_value_to_deci(&data), 33LL,
333+
"the result does not match");
334+
zassert_equal(sensor_value_to_centi(&data), 330LL,
335+
"the result does not match");
332336
zassert_equal(sensor_value_to_milli(&data), 3300LL,
333337
"the result does not match");
334338
zassert_equal(sensor_value_to_micro(&data), 3300000LL,
335339
"the result does not match");
336340
/* reset test data to negative value */
337341
data.val1 = -data.val1;
338342
data.val2 = -data.val2;
343+
zassert_equal(sensor_value_to_deci(&data), -33LL,
344+
"the result does not match");
345+
zassert_equal(sensor_value_to_centi(&data), -330LL,
346+
"the result does not match");
339347
zassert_equal(sensor_value_to_milli(&data), -3300LL,
340348
"the result does not match");
341349
zassert_equal(sensor_value_to_micro(&data), -3300000LL,
342350
"the result does not match");
343351
/* Test when result is greater than 32-bit wide */
352+
data.val1 = 2123456789;
353+
data.val2 = 876543;
354+
zassert_equal(sensor_value_to_deci(&data), 21234567898LL,
355+
"the result does not match");
356+
zassert_equal(sensor_value_to_centi(&data), 212345678987LL,
357+
"the result does not match");
344358
data.val1 = 5432109;
345359
data.val2 = 876543;
346360
zassert_equal(sensor_value_to_milli(&data), 5432109876LL,

0 commit comments

Comments
 (0)