| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "testutils.h" |
| 24 |
|
| 25 |
|
| 26 |
static _Noreturn void print_version (void) __attribute__ ((unused)); |
| 27 |
static _Noreturn void usage (FILE * out) __attribute__ ((unused)); |
| 28 |
|
| 29 |
#define NPL_TESTING |
| 30 |
#include "../plugins/check_temperature.c" |
| 31 |
#undef NPL_TESTING |
| 32 |
|
| 33 |
typedef struct test_data |
| 34 |
{ |
| 35 |
int unit; |
| 36 |
double expect_value; |
| 37 |
} test_data; |
| 38 |
|
| 39 |
static int |
| 40 |
test_temperature_unit_conversion (const void *tdata) |
| 41 |
{ |
| 42 |
char *scale; |
| 43 |
const struct test_data *data = tdata; |
| 44 |
const unsigned long chk_temp = 1000UL*25; |
| 45 |
int ret = 0; |
| 46 |
|
| 47 |
TEST_ASSERT_EQUAL_NUMERIC (data->expect_value, |
| 48 |
get_real_temp (chk_temp, &scale, data->unit)); |
| 49 |
return ret; |
| 50 |
} |
| 51 |
|
| 52 |
static int |
| 53 |
mymain (void) |
| 54 |
{ |
| 55 |
int ret = 0; |
| 56 |
|
| 57 |
#define DO_TEST(MSG, UNIT, EXPECT_VALUE) \ |
| 58 |
do \ |
| 59 |
{ \ |
| 60 |
test_data data = { \ |
| 61 |
.unit = UNIT, \ |
| 62 |
.expect_value = EXPECT_VALUE, \ |
| 63 |
}; \ |
| 64 |
if (test_run(MSG, test_temperature_unit_conversion, &data) < 0) \ |
| 65 |
ret = -1; \ |
| 66 |
} \ |
| 67 |
while (0) |
| 68 |
|
| 69 |
DO_TEST ("check get_real_temp with temp_units eq TEMP_CELSIUS", |
| 70 |
TEMP_CELSIUS, 25); |
| 71 |
DO_TEST ("check get_real_temp with temp_units eq TEMP_FAHRENHEIT", |
| 72 |
TEMP_FAHRENHEIT, 77); |
| 73 |
DO_TEST ("check get_real_temp with temp_units eq TEMP_KELVIN", |
| 74 |
TEMP_KELVIN, 298.1); |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
| 81 |
} |
| 82 |
|
| 83 |
TEST_MAIN (mymain) |