MOS Source Code
Loading...
Searching...
No Matches
infinity_nan_test.c
Go to the documentation of this file.
1/* Tests for floating point default values +-infinity and nan. */
2#undef __STRICT_ANSI__
3#include <math.h>
4#include <pb_decode.h>
5#include "floats.pb.h"
6#include "unittests.h"
7
8bool check_floats(Floats *floats)
9{
10 int status = 0;
11
12 TEST(!floats->has_float_pos_inf);
13 TEST(isinf(floats->float_pos_inf));
14 TEST(!signbit(floats->float_pos_inf));
15
16 TEST(!floats->has_float_neg_inf);
17 TEST(isinf(floats->float_neg_inf));
18 TEST(signbit(floats->float_neg_inf));
19
20 TEST(!floats->has_float_pos_nan);
21 TEST(isnan(floats->float_pos_nan));
22
23 TEST(!floats->has_float_neg_nan);
24 TEST(isnan(floats->float_neg_nan));
25
26 TEST(!floats->has_double_pos_inf);
27 TEST(isinf(floats->double_pos_inf));
28 TEST(!signbit(floats->double_pos_inf));
29
30 TEST(!floats->has_double_neg_inf);
31 TEST(isinf(floats->double_neg_inf));
32 TEST(signbit(floats->double_neg_inf));
33
34 TEST(!floats->has_double_pos_nan);
35 TEST(isnan(floats->double_pos_nan));
36
37 TEST(!floats->has_double_neg_nan);
38 TEST(isnan(floats->double_neg_nan));
39
40 return status == 0;
41}
42
43int main()
44{
45 int status = 0;
46
47 {
48 Floats floats = Floats_init_default;
49 COMMENT("Checking init_default");
50 TEST(check_floats(&floats));
51 }
52
53 {
54 Floats floats = {0};
55 pb_istream_t stream = pb_istream_from_buffer(NULL, 0);
56 COMMENT("Check decoded");
57 TEST(pb_decode(&stream, Floats_fields, &floats));
58 TEST(check_floats(&floats));
59 }
60
61 return status;
62}
int main()
bool check_floats(Floats *floats)
bool pb_decode(pb_istream_t *stream, const pb_msgdesc_t *fields, void *dest_struct)
Definition pb_decode.c:1182
pb_istream_t pb_istream_from_buffer(const pb_byte_t *buf, size_t msglen)
Definition pb_decode.c:143
#define NULL
Definition pb_syshdr.h:46
#define TEST(x)
Definition test.h:3
#define COMMENT(x)
Definition unittests.h:17