1- //  DISABLED AS NOT ALL STD LIBRARIES ARE MOCKED / INCLUDEABLE
2- 
3- // 
41//     FILE: unit_test_001.cpp
52//   AUTHOR: Miles Burton / Rob Tillaart
63//     DATE: 2021-01-10
74//  PURPOSE: unit tests for the Arduino-Temperature-Control-Library
85//           https://github.com/MilesBurton/Arduino-Temperature-Control-Library
9- // 
10- 
11- //  #include <ArduinoUnitTests.h>
12- //  #include <Arduino.h>
13- //  #include <OneWire.h>
14- //  #include <DallasTemperature.h>
15- 
16- //  // Mock pin for testing
17- //  #define ONE_WIRE_BUS 2
18- 
19- //  unittest_setup() {
20- //      fprintf(stderr, "VERSION: %s\n", DALLASTEMPLIBVERSION);
21- //  }
22- 
23- //  unittest_teardown() {
24- //      fprintf(stderr, "\n");
25- //  }
26- 
27- //  // Test constants defined in the library
28- //  unittest(test_models) {
29- //      assertEqual(0x10, DS18S20MODEL);
30- //      assertEqual(0x28, DS18B20MODEL);
31- //      assertEqual(0x22, DS1822MODEL);
32- //      assertEqual(0x3B, DS1825MODEL);
33- //      assertEqual(0x42, DS28EA00MODEL);
34- //  }
35- 
36- //  // Test error codes defined in the library
37- //  unittest(test_error_code) {
38- //      assertEqual(DEVICE_DISCONNECTED_C, -127);
39- //      assertEqual(DEVICE_DISCONNECTED_F, -196.6);
40- //      assertEqual(DEVICE_DISCONNECTED_RAW, -7040);
41- 
42- //      assertEqual(DEVICE_FAULT_OPEN_C, -254);
43- //      assertEqualFloat(DEVICE_FAULT_OPEN_F, -425.2, 0.1);
44- //      assertEqual(DEVICE_FAULT_OPEN_RAW, -32512);
45- 
46- //      assertEqual(DEVICE_FAULT_SHORTGND_C, -253);
47- //      assertEqualFloat(DEVICE_FAULT_SHORTGND_F, -423.4, 0.1);
48- //      assertEqual(DEVICE_FAULT_SHORTGND_RAW, -32384);
49- 
50- //      assertEqual(DEVICE_FAULT_SHORTVDD_C, -252);
51- //      assertEqualFloat(DEVICE_FAULT_SHORTVDD_F, -421.6, 0.1);
52- //      assertEqual(DEVICE_FAULT_SHORTVDD_RAW, -32256);
53- //  }
54- 
55- //  // Test basic initialization and functionality of the DallasTemperature library
56- //  unittest(test_initialization) {
57- //      OneWire oneWire(ONE_WIRE_BUS);
58- //      DallasTemperature sensors(&oneWire);
59- 
60- //      sensors.begin();
61- 
62- //      // Initially, there should be no devices detected
63- //      assertEqual(0, sensors.getDeviceCount());
64- //      assertFalse(sensors.isParasitePowerMode());
65- //  }
66- 
67- //  // Simulate a basic temperature read (mocked)
68- //  unittest(test_temperature_read) {
69- //      OneWire oneWire(ONE_WIRE_BUS);
70- //      DallasTemperature sensors(&oneWire);
71- 
72- //      sensors.begin();
73- 
74- //      // Mock reading temperature
75- //      float tempC = sensors.getTempCByIndex(0);
76- //      assertEqual(DEVICE_DISCONNECTED_C, tempC); // Simulated no device connected
77- //  }
78- 
79- //  unittest_main()
80- 
81- //  --------
6+ 
7+ 
8+ #include  < ArduinoUnitTests.h> 
9+ #include  < Arduino.h> 
10+ #include  < OneWire.h> 
11+ #include  < DallasTemperature.h> 
12+ 
13+ //  Mock pin for testing
14+ #define  ONE_WIRE_BUS  2 
15+ 
16+ unittest_setup () {
17+     fprintf (stderr, " VERSION: %s\n " 
18+ }
19+ 
20+ unittest_teardown () {
21+     fprintf (stderr, " \n " 
22+ }
23+ 
24+ //  Test constants defined in the library
25+ unittest (test_models) {
26+     assertEqual (0x10 , DS18S20MODEL);
27+     assertEqual (0x28 , DS18B20MODEL);
28+     assertEqual (0x22 , DS1822MODEL);
29+     assertEqual (0x3B , DS1825MODEL);
30+     assertEqual (0x42 , DS28EA00MODEL);
31+ }
32+ 
33+ //  Test error codes defined in the library
34+ unittest (test_error_code) {
35+     assertEqual (DEVICE_DISCONNECTED_C, -127 );
36+     assertEqual (DEVICE_DISCONNECTED_F, -196.6 );
37+     assertEqual (DEVICE_DISCONNECTED_RAW, -7040 );
38+ 
39+     assertEqual (DEVICE_FAULT_OPEN_C, -254 );
40+     assertEqualFloat (DEVICE_FAULT_OPEN_F, -425.2 , 0.1 );
41+     assertEqual (DEVICE_FAULT_OPEN_RAW, -32512 );
42+ 
43+     assertEqual (DEVICE_FAULT_SHORTGND_C, -253 );
44+     assertEqualFloat (DEVICE_FAULT_SHORTGND_F, -423.4 , 0.1 );
45+     assertEqual (DEVICE_FAULT_SHORTGND_RAW, -32384 );
46+ 
47+     assertEqual (DEVICE_FAULT_SHORTVDD_C, -252 );
48+     assertEqualFloat (DEVICE_FAULT_SHORTVDD_F, -421.6 , 0.1 );
49+     assertEqual (DEVICE_FAULT_SHORTVDD_RAW, -32256 );
50+ }
51+ 
52+ //  Test basic initialization and functionality of the DallasTemperature library
53+ unittest (test_initialization) {
54+     OneWire oneWire (ONE_WIRE_BUS);
55+     DallasTemperature sensors (&oneWire);
56+ 
57+     sensors.begin ();
58+ 
59+     //  Initially, there should be no devices detected
60+     assertEqual (0 , sensors.getDeviceCount ());
61+     assertFalse (sensors.isParasitePowerMode ());
62+ }
63+ 
64+ //  Simulate a basic temperature read (mocked)
65+ unittest (test_temperature_read) {
66+     OneWire oneWire (ONE_WIRE_BUS);
67+     DallasTemperature sensors (&oneWire);
68+ 
69+     sensors.begin ();
70+ 
71+     //  Mock reading temperature
72+     float  tempC = sensors.getTempCByIndex (0 );
73+     assertEqual (DEVICE_DISCONNECTED_C, tempC); //  Simulated no device connected
74+ }
75+ 
76+ unittest_main ()
0 commit comments