3737
3838
3939#include "Arduino.h"
40+ #include "OneWire.h"
41+ #include "DallasTemperature.h"
4042
4143/*
44+ NOTE 2022-06-03: why is unit test disabled.
45+ There are problems with the including of util/crc16.h by Onewire.h
46+ Without it test can't be run.
47+ */
4248
4349
44- // BASED UPON SIMPLE
45- //
50+ unittest_setup()
51+ {
52+ fprintf(stderr, "VERSION: %s\n", DALLASTEMPLIBVERSION);
53+ }
4654
55+ unittest_teardown()
56+ {
57+ fprintf(stderr, "\n");
58+ }
4759
48- #include "OneWire.h"
49- #include "DallasTemperature.h"
5060
51- // Data wire is plugged into port 2 on the Arduino
52- #define ONE_WIRE_BUS 2
61+ unittest(test_models)
62+ {
63+ assertEqual(0x10, DS18S20MODEL);
64+ assertEqual(0x28, DS18B20MODEL);
65+ assertEqual(0x22, DS1822MODEL);
66+ assertEqual(0x3B, DS1825MODEL);
67+ assertEqual(0x42, DS28EA00MODEL);
68+ }
5369
54- // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
55- OneWire oneWire(ONE_WIRE_BUS);
5670
57- // Pass our oneWire reference to Dallas Temperature.
58- DallasTemperature sensors(&oneWire);
71+ unittest(test_error_code)
72+ {
73+ assertEqual(-255, DEVICE_DISCONNECTED_C);
74+ assertEqual(-427, DEVICE_DISCONNECTED_F);
75+ assertEqual(-32640, DEVICE_DISCONNECTED_RAW);
5976
77+ assertEqual(-254, DEVICE_FAULT_OPEN_C);
78+ assertEqualFloat(-425.199982, DEVICE_FAULT_OPEN_F, 0.001);
79+ assertEqual(-32512, DEVICE_FAULT_OPEN_RAW);
6080
81+ assertEqual(-253, DEVICE_FAULT_SHORTGND_C);
82+ assertEqualFloat(-423.399994, DEVICE_FAULT_SHORTGND_F, 0.001);
83+ assertEqual(-32384, DEVICE_FAULT_SHORTGND_RAW);
6184
62- unittest_setup()
63- {
85+ assertEqual(-252, DEVICE_FAULT_SHORTVDD_C);
86+ assertEqualFloat(-421.599976, DEVICE_FAULT_SHORTVDD_F, 0.001);
87+ assertEqual( -32256, DEVICE_FAULT_SHORTVDD_RAW);
6488}
6589
66- unittest_teardown()
67- {
68- }
6990
91+ unittest(test_simple)
92+ {
93+ /*
94+ // BASED UPON SIMPLE (won't run, see above)
95+ //
96+ // Data wire is plugged into port 2 on the Arduino
97+ #define ONE_WIRE_BUS 2
7098
99+ // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
100+ OneWire oneWire(ONE_WIRE_BUS);
71101
72- unittest(test_constructor)
73- {
74- fprintf(stderr, "VERSION: %s\n", DALLASTEMPLIBVERSION);
75-
102+ // Pass our oneWire reference to Dallas Temperature.
103+ DallasTemperature sensors(&oneWire);
76104 sensors.begin();
77105 sensors.requestTemperatures();
78106 float tempC = sensors.getTempCByIndex(0);
@@ -85,10 +113,10 @@ unittest(test_constructor)
85113 {
86114 fprintf(stderr, "Error: Could not read temperature data\n");
87115 }
116+ */
88117
89118 assertEqual(1, 1); // keep unit test happy
90119}
91- */
92120
93121unittest_main()
94122
0 commit comments