Tasmota/lib/IRremoteESP8266-2.2.1.02/test/ir_Pronto_test.cpp
arendst 3403ca1e0a v5.10.0
5.10.0 20171201
 * Upgrade library ArduinoJson to 5.11.2
 * Upgrade
library IRRemoteEsp8266 to 2.2.1 + 2 commits but disabled some protocols
(code size reduction)
 * Upgrade library NeoPixelBus to 2.2.9
 * Upgrade
library OneWire to 2.3.3 + 6 commits and disabled CRC lookup-table
(#define ONEWIRE_CRC8_TABLE 0) (code size reduction)
 * Update library
PubSubClient to 2.6 + 9 commits and additional delay (#790)
 * Update
core_esp8266_wiring_digital.c to latest (staged) level
 * Patch library
I2Cdevlib-Core for esp8266-core 2.4.0-rc2 compatibility
 * Remove
command EnergyReset 1..3 now replaced by ENergyReset1 to EnergyReset3
 *
Remove spaces in JSON messages (code size reduction)
 * Renamed
xsns_05_ds18x20.ino to xsns_05_ds18x20_legacy.ino still using library
OneWire and providing dynamic sensor scan
 * Fix possible iram1_0_seg
compile error by shrinking ICACHE_RAM_ATTR code usage
 * Fix PWM
watchdog timeout if Dimmer is set to 100 or Color set to 0xFF (#1146)
 *
Fix Sonoff Bridge Learn Mode hang caused by unrecognised RF code
(#1181)
 * Fix blank console log window by using XML character encoding
(#1187)
 * Fix wrong response name for command HlwISet (#1214)
 * Fix
DHT type sensor timeout recognition by distinguish "signal already
there" from "timeout" (#1233)
 * Add fixed color options 1..12 to
command Color
 * Add + (plus) and - (minus) to commands Dimmer
(+10/-10), Speed and Scheme
 * Add + (plus) and - (minus) to command
Color to select 1 out of 12 preset colors
 * Add + (plus) and - (minus)
to command Ct to control ColdWarm led ColorTemperature (+34/-34)
 * Add
commands EnergyReset1 0..42500, EnergyReset2 0..42500 and EnergyReset3
0..42500000
 *  to (Re)set Energy Today, Yesterday or Total respectively
in Wh (#406, #685, #1202)
 * Add optional ADS1115 driver as alternative
for unsupported I2Cdevlib in esp8266-core 2.4.0-rc2
 * Add support for
INA219 Voltage and Current sensor to be enabled in user_config.h with
define USE_INA219
 * Add support for Arilux LC11 (Clearing RF home code
when selecting no Arilux module)
 * Add support for WS2812 RGBW
ledstrips to be enabled in user_config.h with define USE_WS2812_CTYPE
(#1156)
 * Add SettingsSaveAll routine to command SaveData to be used
before controlled power down (#1202)
 * Add option PUSHBUTTON_TOGGLE
(SwitchMode 7) to allow toggling on any switch change (#1221)
 * Add new
xdrv_05_ds18x20.ino free from library OneWire and add the following
features:
 *  Add support for DS1822
 *  Add forced setting of 12-bit
resolution for selected device types (#1222)
 *  Add read temperature
retry counter (#1215)
 *  Fix lost sensors by performing sensor probe at
restart only thereby removing dynamic sensor probe (#1215)
 *  Fix
sensor address sorting using ascending sort on sensor type followed by
sensor address
 *  Rewrite JSON resulting in shorter message allowing
more sensors in default firmware image:
 *
"DS18B20-1":{"Id":"00000483C23A","Temperature":19.5},"DS18B20-2":{"Id":"0000048EC44C","Temperature":19.6}

* Add additional define in user_config.h to select either single sensor
(defines disabled), new multi sensor (USE_DS18X20) or legacy multi
sensor (USE_DS18X20_LEGACY)
 * Add clock support for more different
pixel counts (#1226)
 * Add support for Sonoff Dual R2 (#1249)
 * Add
FriendlyName to web page tab and add program information to web page
footer (#1275)
2017-12-01 14:42:22 +01:00

359 lines
14 KiB
C++

// Copyright 2017 David Conran
#include "IRsend.h"
#include "IRsend_test.h"
#include "gtest/gtest.h"
// Tests for sendPronto().
TEST(TestSendPronto, CodeTooShort) {
IRsendTest irsend(4);
irsend.begin();
irsend.reset();
// Less entries than the smallest possible (practical) Pronto code.
uint16_t pronto_test[5] = {0x0000, 0x0067, 0x0034, 0x0000, 0x0000};
irsend.sendPronto(pronto_test, 5);
EXPECT_EQ("", irsend.outputStr()); // Should do nothing.
}
TEST(TestSendPronto, NormalSequenceTooLong) {
IRsendTest irsend(4);
irsend.begin();
irsend.reset();
// The First 'Normal' sequence is declared to be longer than the data we have.
uint16_t pronto_test[6] = {0x0000, 0x0067, 0x0010, 0x0000, 0x0000, 0x0000};
irsend.sendPronto(pronto_test, 6);
EXPECT_EQ("", irsend.outputStr()); // Should do nothing.
}
TEST(TestSendPronto, RepeatSequenceTooLong) {
IRsendTest irsend(4);
irsend.begin();
irsend.reset();
// The 2nd 'Repeat' sequence is declared to be longer than the data we have.
uint16_t pronto_test[6] = {0x0000, 0x0067, 0x0000, 0x0010, 0x0000, 0x0000};
irsend.sendPronto(pronto_test, 6);
EXPECT_EQ("", irsend.outputStr()); // Should do nothing.
}
TEST(TestSendPronto, BothSequencesTooLong) {
IRsendTest irsend(4);
irsend.begin();
irsend.reset();
// All sequences are declared to be longer than the data we have.
uint16_t pronto_test[6] = {0x0000, 0x0067, 0x0010, 0x0010, 0x0000, 0x0000};
irsend.sendPronto(pronto_test, 6);
EXPECT_EQ("", irsend.outputStr()); // Should do nothing.
}
TEST(TestSendPronto, MoreDataThanNeededInNormal) {
IRsendTest irsend(4);
irsend.begin();
irsend.reset();
// We should handle when we are given more data than needed. (normal seq.)
uint16_t pronto_test[8] = {0x0000, 0x0067, 0x0001, 0x0000,
0x0001, 0x0002, 0x0003, 0x0004};
irsend.sendPronto(pronto_test, 8);
EXPECT_EQ("m25s50", irsend.outputStr()); // Only send the data required.
}
TEST(TestSendPronto, MoreDataThanNeededInRepeat) {
IRsendTest irsend(4);
irsend.begin();
irsend.reset();
// We should handle when we are given more data than needed. (repeat seq.)
uint16_t pronto_test[8] = {0x0000, 0x0067, 0x0000, 0x0001,
0x0001, 0x0002, 0x0003, 0x0004};
irsend.sendPronto(pronto_test, 8);
EXPECT_EQ("m25s50", irsend.outputStr()); // Only send the data required.
}
TEST(TestSendPronto, MoreDataThanNeededInBoth) {
IRsendTest irsend(4);
irsend.begin();
irsend.reset();
// We should handle when we are given more data than needed. (repeat seq.)
uint16_t pronto_test[10] = {0x0000, 0x0067, 0x0001, 0x0001,
0x0001, 0x0002, 0x0003, 0x0004, 0x5, 0x6};
irsend.sendPronto(pronto_test, 10);
EXPECT_EQ("m25s50", irsend.outputStr()); // Only send the data required.
irsend.sendPronto(pronto_test, 10, 1);
EXPECT_EQ("m25s50m75s100", irsend.outputStr()); // Only the data required.
}
TEST(TestSendPronto, ShortestValidCodeThatSendsNothing) {
IRsendTest irsend(4);
irsend.begin();
irsend.reset();
uint16_t pronto_test[6] = {0x0000, 0x0067, 0x0000, 0x0000, 0x0001, 0x0002};
irsend.sendPronto(pronto_test, 6);
EXPECT_EQ("", irsend.outputStr()); // Nothing Happens.
irsend.sendPronto(pronto_test, 6, 1);
EXPECT_EQ("", irsend.outputStr()); // Twice as much Nothing Happens. ;-)
}
// Test sending a Pronto code that only has a normal (first) sequence.
// i.e. No Pronto repeat sequence.
TEST(TestSendPronto, NonRepeatingCode) {
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
// A random Pronto code I found on the Internet that has no repeat sequence.
// It was an example of a poor Pronto code.
// It turned out to be a 4 copies of a Sony 12-bit code. Who knew!?!
uint16_t pronto_test[108] = {
0x0000, 0x0067, 0x0034, 0x0000,
0x0060, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
0x0030, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
0x0018, 0x0452, 0x0060, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
0x0018, 0x0018, 0x0030, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
0x0018, 0x0018, 0x0018, 0x0452, 0x0060, 0x0018, 0x0018, 0x0018,
0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
0x0018, 0x0018, 0x0018, 0x0018, 0x0030, 0x0018, 0x0018, 0x0018,
0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0452, 0x0060, 0x0018,
0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0030, 0x0018,
0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018};
// Send the Pronto code without any repeats set.
irsend.reset();
irsend.sendPronto(pronto_test, 108);
irsend.makeDecodeResult();
EXPECT_EQ(
"m2400s600"
"m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
"m600s600m600s600m600s600m600s27650"
"m2400s600"
"m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
"m600s600m600s600m600s600m600s27650"
"m2400s600"
"m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
"m600s600m600s600m600s600m600s27650"
"m2400s600"
"m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
"m600s600m600s600m600s600m600s600", irsend.outputStr());
EXPECT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(SONY, irsend.capture.decode_type);
EXPECT_EQ(SONY_12_BITS, irsend.capture.bits);
EXPECT_EQ(0x10, irsend.capture.value);
EXPECT_EQ(0x1, irsend.capture.address);
EXPECT_EQ(0x0, irsend.capture.command);
// Now try repeating it.
// As it has no repeat sequence, we shouldn't repeat it. (I think)
irsend.reset();
irsend.sendPronto(pronto_test, 108, 3);
irsend.makeDecodeResult();
EXPECT_EQ(
"m2400s600"
"m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
"m600s600m600s600m600s600m600s27650"
"m2400s600"
"m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
"m600s600m600s600m600s600m600s27650"
"m2400s600"
"m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
"m600s600m600s600m600s600m600s27650"
"m2400s600"
"m600s600m600s600m600s600m600s600m600s600m600s600m600s600m1200s600"
"m600s600m600s600m600s600m600s600", irsend.outputStr());
EXPECT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(SONY, irsend.capture.decode_type);
EXPECT_EQ(SONY_12_BITS, irsend.capture.bits);
EXPECT_EQ(0x10, irsend.capture.value);
EXPECT_EQ(0x1, irsend.capture.address);
EXPECT_EQ(0x0, irsend.capture.command);
}
// Test sending a Pronto code that only has a repeat sequence (Sony).
TEST(TestSendPronto, RepeatSequenceOnlyForSony) {
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
// Sony 20-bit command.
uint16_t pronto_test[46] = {
0x0000, 0x0067, 0x0000, 0x0015,
0x0060, 0x0018, 0x0018, 0x0018, 0x0030, 0x0018, 0x0030, 0x0018,
0x0030, 0x0018, 0x0018, 0x0018, 0x0030, 0x0018, 0x0018, 0x0018,
0x0018, 0x0018, 0x0030, 0x0018, 0x0018, 0x0018, 0x0030, 0x0018,
0x0030, 0x0018, 0x0030, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018,
0x0030, 0x0018, 0x0018, 0x0018, 0x0018, 0x0018, 0x0030, 0x0018,
0x0018, 0x03f6};
// Send the Pronto code without any repeats set.
irsend.reset();
irsend.sendPronto(pronto_test, 46);
irsend.makeDecodeResult();
EXPECT_EQ(
"m2400s600"
"m600s600m1200s600m1200s600m1200s600m600s600m1200s600m600s600m600s600"
"m1200s600m600s600m1200s600m1200s600m1200s600m600s600m600s600m1200s600"
"m600s600m600s600m1200s600m600s25350", irsend.outputStr());
EXPECT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(SONY, irsend.capture.decode_type);
EXPECT_EQ(SONY_20_BITS, irsend.capture.bits);
EXPECT_EQ(0x74B92, irsend.capture.value);
EXPECT_EQ(0x1A, irsend.capture.address);
EXPECT_EQ(0x24AE, irsend.capture.command);
// Send the Pronto code with 2 repeats.
irsend.reset();
irsend.sendPronto(pronto_test, 46, SONY_MIN_REPEAT);
irsend.makeDecodeResult();
EXPECT_EQ(
"m2400s600"
"m600s600m1200s600m1200s600m1200s600m600s600m1200s600m600s600m600s600"
"m1200s600m600s600m1200s600m1200s600m1200s600m600s600m600s600m1200s600"
"m600s600m600s600m1200s600m600s25350"
"m2400s600"
"m600s600m1200s600m1200s600m1200s600m600s600m1200s600m600s600m600s600"
"m1200s600m600s600m1200s600m1200s600m1200s600m600s600m600s600m1200s600"
"m600s600m600s600m1200s600m600s25350"
"m2400s600"
"m600s600m1200s600m1200s600m1200s600m600s600m1200s600m600s600m600s600"
"m1200s600m600s600m1200s600m1200s600m1200s600m600s600m600s600m1200s600"
"m600s600m600s600m1200s600m600s25350", irsend.outputStr());
EXPECT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(SONY, irsend.capture.decode_type);
EXPECT_EQ(SONY_20_BITS, irsend.capture.bits);
EXPECT_EQ(0x74B92, irsend.capture.value);
EXPECT_EQ(0x1A, irsend.capture.address);
EXPECT_EQ(0x24AE, irsend.capture.command);
}
// Test sending a Pronto code that only has a repeat sequence (Panasonic).
TEST(TestSendPronto, RepeatSequenceOnlyForPanasonic) {
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
// Panasonic Plasma TV Descrete code (Power On).
uint16_t pronto_test[104] = {
0x0000, 0x0071, 0x0000, 0x0032,
0x0080, 0x003F, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0030, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0030,
0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0010,
0x0010, 0x0010, 0x0010, 0x0010, 0x0010, 0x0030, 0x0010, 0x0030,
0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0030, 0x0010, 0x0010,
0x0010, 0x0030, 0x0010, 0x0A98};
// Send the Pronto code without any repeats set.
irsend.reset();
irsend.sendPronto(pronto_test, 104);
irsend.makeDecodeResult();
EXPECT_EQ(
"m3456s1701"
"m432s432m432s1296m432s432m432s432m432s432m432s432m432s432m432s432"
"m432s432m432s432m432s432m432s432m432s432m432s1296m432s432m432s432"
"m432s432m432s432m432s432m432s432m432s432m432s432m432s432m432s1296"
"m432s432m432s432m432s432m432s432m432s432m432s432m432s432m432s432"
"m432s432m432s1296m432s1296m432s1296m432s1296m432s1296m432s432m432s432"
"m432s432m432s1296m432s1296m432s1296m432s1296m432s1296m432s432m432s1296"
"m432s73224", irsend.outputStr());
EXPECT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(PANASONIC, irsend.capture.decode_type);
EXPECT_EQ(PANASONIC_BITS, irsend.capture.bits);
EXPECT_EQ(0x400401007C7D, irsend.capture.value);
EXPECT_EQ(0x4004, irsend.capture.address);
EXPECT_EQ(0x1007C7D, irsend.capture.command);
}
// Test sending a Pronto code that has a normal & arepeat sequence (NEC).
TEST(TestSendPronto, NormalPlusRepeatSequence) {
IRsendTest irsend(4);
IRrecv irrecv(4);
irsend.begin();
// NEC 32 bit power on command.
uint16_t pronto_test[76] = {
0x0000, 0x006D, 0x0022, 0x0002,
0x0156, 0x00AB, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0040, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015, 0x0015,
0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x0015, 0x0015, 0x0040, 0x0015, 0x0040, 0x0015, 0x0040,
0x0015, 0x0040, 0x0015, 0x05FD,
0x0156, 0x0055, 0x0015, 0x0E4E};
// Send the Pronto code without any repeats set.
irsend.reset();
irsend.sendPronto(pronto_test, 76);
irsend.makeDecodeResult();
EXPECT_EQ(
"m8892s4446"
"m546s546m546s546m546s546m546s1664m546s1664m546s546m546s546m546s546"
"m546s1664m546s1664m546s1664m546s546m546s546m546s1664m546s1664m546s1664"
"m546s546m546s546m546s546m546s1664m546s546m546s546m546s546m546s546"
"m546s1664m546s1664m546s1664m546s546m546s1664m546s1664m546s1664m546s1664"
"m546s39858", irsend.outputStr());
EXPECT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(NEC, irsend.capture.decode_type);
EXPECT_EQ(NEC_BITS, irsend.capture.bits);
EXPECT_EQ(0x18E710EF, irsend.capture.value);
EXPECT_EQ(0x18, irsend.capture.address);
EXPECT_EQ(0x8, irsend.capture.command);
// Send it again with a single repeat.
irsend.reset();
irsend.sendPronto(pronto_test, 76, 1);
irsend.makeDecodeResult();
EXPECT_EQ(
"m8892s4446"
"m546s546m546s546m546s546m546s1664m546s1664m546s546m546s546m546s546"
"m546s1664m546s1664m546s1664m546s546m546s546m546s1664m546s1664m546s1664"
"m546s546m546s546m546s546m546s1664m546s546m546s546m546s546m546s546"
"m546s1664m546s1664m546s1664m546s546m546s1664m546s1664m546s1664m546s1664"
"m546s39858"
"m8892s2210m546s95212", irsend.outputStr());
EXPECT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(NEC, irsend.capture.decode_type);
EXPECT_EQ(NEC_BITS, irsend.capture.bits);
EXPECT_EQ(0x18E710EF, irsend.capture.value);
EXPECT_EQ(0x18, irsend.capture.address);
EXPECT_EQ(0x8, irsend.capture.command);
// Send it again with a two repeats.
irsend.reset();
irsend.sendPronto(pronto_test, 76, 2);
irsend.makeDecodeResult();
EXPECT_EQ(
"m8892s4446"
"m546s546m546s546m546s546m546s1664m546s1664m546s546m546s546m546s546"
"m546s1664m546s1664m546s1664m546s546m546s546m546s1664m546s1664m546s1664"
"m546s546m546s546m546s546m546s1664m546s546m546s546m546s546m546s546"
"m546s1664m546s1664m546s1664m546s546m546s1664m546s1664m546s1664m546s1664"
"m546s39858"
"m8892s2210m546s95212"
"m8892s2210m546s95212", irsend.outputStr());
EXPECT_TRUE(irrecv.decode(&irsend.capture));
EXPECT_EQ(NEC, irsend.capture.decode_type);
EXPECT_EQ(NEC_BITS, irsend.capture.bits);
EXPECT_EQ(0x18E710EF, irsend.capture.value);
EXPECT_EQ(0x18, irsend.capture.address);
EXPECT_EQ(0x8, irsend.capture.command);
}