Skip to content

Commit c228b5e

Browse files
authoredJan 23, 2025
Merge pull request #272 from milesburton/fix/restore-unit-tests-part-2
fix: Restore the next set of unit tests
2 parents eb995ea + 14fc0cf commit c228b5e

File tree

2 files changed

+76
-81
lines changed

2 files changed

+76
-81
lines changed
 

‎test/unit_test_001.cpp

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// FILE: unit_test_001.cpp
2+
// AUTHOR: Miles Burton / Rob Tillaart
3+
// DATE: 2021-01-10
4+
// PURPOSE: unit tests for the Arduino-Temperature-Control-Library
5+
// https://github.com/MilesBurton/Arduino-Temperature-Control-Library
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", DALLASTEMPLIBVERSION);
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()

‎test/unit_test_001.cpp.disabled

-81
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.