Skip to content

Commit

Permalink
Add decodeToState() unit tests to all supported protocols
Browse files Browse the repository at this point in the history
Add Unit tests where possible to all protocols. Some in multiple places.
Fixes #1067
  • Loading branch information
crankyoldgit committed Mar 23, 2020
1 parent 26d30f9 commit c5b6644
Show file tree
Hide file tree
Showing 24 changed files with 188 additions and 40 deletions.
75 changes: 75 additions & 0 deletions test/IRac_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ TEST(TestIRac, Amcor) {
ASSERT_EQ(AMCOR, ac._irsend.capture.decode_type);
ASSERT_EQ(kAmcorBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Argo) {
Expand Down Expand Up @@ -103,6 +105,8 @@ TEST(TestIRac, Coolix) {
ASSERT_EQ(COOLIX, ac._irsend.capture.decode_type);
ASSERT_EQ(kCoolixBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
// Confirm we are sending with a repeat of 1. i.e. two messages.
EXPECT_EQ(
"f38000d50" // 38kHz Frequency and 50% duty-cycle.
Expand Down Expand Up @@ -165,6 +169,8 @@ TEST(TestIRac, Daikin) {
ASSERT_EQ(DAIKIN, ac._irsend.capture.decode_type);
ASSERT_EQ(kDaikinBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Daikin128) {
Expand Down Expand Up @@ -196,6 +202,8 @@ TEST(TestIRac, Daikin128) {
ASSERT_EQ(DAIKIN128, ac._irsend.capture.decode_type);
ASSERT_EQ(kDaikin128Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Daikin152) {
Expand All @@ -222,6 +230,8 @@ TEST(TestIRac, Daikin152) {
ASSERT_EQ(DAIKIN152, ac._irsend.capture.decode_type);
ASSERT_EQ(kDaikin152Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Daikin160) {
Expand All @@ -245,6 +255,8 @@ TEST(TestIRac, Daikin160) {
ASSERT_EQ(DAIKIN160, ac._irsend.capture.decode_type);
ASSERT_EQ(kDaikin160Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Daikin176) {
Expand All @@ -267,6 +279,8 @@ TEST(TestIRac, Daikin176) {
ASSERT_EQ(DAIKIN176, ac._irsend.capture.decode_type);
ASSERT_EQ(kDaikin176Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Daikin2) {
Expand Down Expand Up @@ -303,6 +317,8 @@ TEST(TestIRac, Daikin2) {
ASSERT_EQ(DAIKIN2, ac._irsend.capture.decode_type);
ASSERT_EQ(kDaikin2Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Daikin216) {
Expand All @@ -329,6 +345,8 @@ TEST(TestIRac, Daikin216) {
ASSERT_EQ(DAIKIN216, ac._irsend.capture.decode_type);
ASSERT_EQ(kDaikin216Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Electra) {
Expand Down Expand Up @@ -392,6 +410,8 @@ TEST(TestIRac, Fujitsu) {
ASSERT_EQ(FUJITSU_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kFujitsuAcBits - 8, ac._irsend.capture.bits);
ASSERT_EQ(ardb1_expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));

ac._irsend.reset();
irac.fujitsu(&ac,
Expand All @@ -413,6 +433,7 @@ TEST(TestIRac, Fujitsu) {
ASSERT_EQ(FUJITSU_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kFujitsuAcBits, ac._irsend.capture.bits);
ASSERT_EQ(arrah2e_expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
ac._irsend.reset();
irac.fujitsu(&ac,
fujitsu_ac_remote_model_t::ARRY4, // Model
Expand All @@ -433,6 +454,7 @@ TEST(TestIRac, Fujitsu) {
ASSERT_EQ(FUJITSU_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kFujitsuAcBits, ac._irsend.capture.bits);
ASSERT_EQ(arry4_expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Goodweather) {
Expand All @@ -459,6 +481,8 @@ TEST(TestIRac, Goodweather) {
ASSERT_EQ(GOODWEATHER, ac._irsend.capture.decode_type);
ASSERT_EQ(kGoodweatherBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Gree) {
Expand Down Expand Up @@ -489,6 +513,8 @@ TEST(TestIRac, Gree) {
ASSERT_EQ(GREE, ac._irsend.capture.decode_type);
ASSERT_EQ(kGreeBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Haier) {
Expand Down Expand Up @@ -516,6 +542,8 @@ TEST(TestIRac, Haier) {
ASSERT_EQ(HAIER_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kHaierACBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}


Expand Down Expand Up @@ -544,6 +572,8 @@ TEST(TestIRac, HaierYrwo2) {
ASSERT_EQ(HAIER_AC_YRW02, ac._irsend.capture.decode_type);
ASSERT_EQ(kHaierACYRW02Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Hitachi) {
Expand All @@ -569,6 +599,8 @@ TEST(TestIRac, Hitachi) {
ASSERT_EQ(HITACHI_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kHitachiAcBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Hitachi424) {
Expand Down Expand Up @@ -596,6 +628,8 @@ TEST(TestIRac, Hitachi424) {
ASSERT_EQ(HITACHI_AC424, ac._irsend.capture.decode_type);
ASSERT_EQ(kHitachiAc424Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));

ac._irsend.reset();
irac.hitachi424(&ac,
Expand All @@ -611,6 +645,7 @@ TEST(TestIRac, Hitachi424) {
ASSERT_EQ(HITACHI_AC424, ac._irsend.capture.decode_type);
ASSERT_EQ(kHitachiAc424Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected_swingv, IRAcUtils::resultAcToString(&ac._irsend.capture));
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Kelvinator) {
Expand Down Expand Up @@ -642,6 +677,8 @@ TEST(TestIRac, Kelvinator) {
ASSERT_EQ(KELVINATOR, ac._irsend.capture.decode_type);
ASSERT_EQ(kKelvinatorBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, LG) {
Expand All @@ -666,6 +703,8 @@ TEST(TestIRac, LG) {
ASSERT_EQ(LG, ac._irsend.capture.decode_type);
ASSERT_EQ(kLgBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Midea) {
Expand All @@ -692,6 +731,8 @@ TEST(TestIRac, Midea) {
ASSERT_EQ(MIDEA, ac._irsend.capture.decode_type);
ASSERT_EQ(kMideaBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Mitsubishi) {
Expand Down Expand Up @@ -719,6 +760,8 @@ TEST(TestIRac, Mitsubishi) {
ASSERT_EQ(MITSUBISHI_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kMitsubishiACBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Mitsubishi136) {
Expand All @@ -743,6 +786,8 @@ TEST(TestIRac, Mitsubishi136) {
ASSERT_EQ(MITSUBISHI136, ac._irsend.capture.decode_type);
ASSERT_EQ(kMitsubishi136Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, MitsubishiHeavy88) {
Expand Down Expand Up @@ -771,6 +816,8 @@ TEST(TestIRac, MitsubishiHeavy88) {
ASSERT_EQ(MITSUBISHI_HEAVY_88, ac._irsend.capture.decode_type);
ASSERT_EQ(kMitsubishiHeavy88Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, MitsubishiHeavy152) {
Expand Down Expand Up @@ -802,6 +849,8 @@ TEST(TestIRac, MitsubishiHeavy152) {
ASSERT_EQ(MITSUBISHI_HEAVY_152, ac._irsend.capture.decode_type);
ASSERT_EQ(kMitsubishiHeavy152Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Neoclima) {
Expand Down Expand Up @@ -832,6 +881,8 @@ TEST(TestIRac, Neoclima) {
ASSERT_EQ(decode_type_t::NEOCLIMA, ac._irsend.capture.decode_type);
ASSERT_EQ(kNeoclimaBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Panasonic) {
Expand Down Expand Up @@ -862,6 +913,8 @@ TEST(TestIRac, Panasonic) {
ASSERT_EQ(PANASONIC_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kPanasonicAcBits, ac._irsend.capture.bits);
ASSERT_EQ(expected_nke, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));

char expected_dke[] =
"Model: 3 (DKE), Power: On, Mode: 3 (Cool), Temp: 18C, Fan: 4 (High), "
Expand All @@ -887,6 +940,7 @@ TEST(TestIRac, Panasonic) {
ASSERT_EQ(PANASONIC_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kPanasonicAcBits, ac._irsend.capture.bits);
ASSERT_EQ(expected_dke, IRAcUtils::resultAcToString(&ac._irsend.capture));
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Samsung) {
Expand Down Expand Up @@ -918,6 +972,8 @@ TEST(TestIRac, Samsung) {
ASSERT_EQ(SAMSUNG_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kSamsungAcBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));

ac._irsend.reset();
irac.samsung(&ac,
Expand Down Expand Up @@ -945,6 +1001,7 @@ TEST(TestIRac, Samsung) {
"Power: On, Mode: 1 (Cool), Temp: 24C, Fan: 0 (Auto), Swing: Off, "
"Beep: Off, Clean: Off, Quiet: Off, Powerful: Off, Light: On, Ion: Off";
ASSERT_EQ(expected_on, IRAcUtils::resultAcToString(&ac._irsend.capture));
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Sharp) {
Expand All @@ -966,6 +1023,8 @@ TEST(TestIRac, Sharp) {
ASSERT_EQ(SHARP_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kSharpAcBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Tcl112) {
Expand Down Expand Up @@ -994,6 +1053,8 @@ TEST(TestIRac, Tcl112) {
ASSERT_EQ(TCL112AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kTcl112AcBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Teco) {
Expand All @@ -1019,6 +1080,8 @@ TEST(TestIRac, Teco) {
ASSERT_EQ(TECO, ac._irsend.capture.decode_type);
ASSERT_EQ(kTecoBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Toshiba) {
Expand All @@ -1039,6 +1102,8 @@ TEST(TestIRac, Toshiba) {
ASSERT_EQ(TOSHIBA_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kToshibaACBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Trotec) {
Expand Down Expand Up @@ -1066,6 +1131,8 @@ TEST(TestIRac, Trotec) {
ASSERT_EQ(TROTEC, ac._irsend.capture.decode_type);
ASSERT_EQ(kTrotecBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, Vestel) {
Expand Down Expand Up @@ -1093,6 +1160,8 @@ TEST(TestIRac, Vestel) {
ASSERT_EQ(VESTEL_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kVestelAcBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));

ac._irsend.reset();
char expected_clocks[] =
Expand All @@ -1117,6 +1186,7 @@ TEST(TestIRac, Vestel) {
ASSERT_EQ(VESTEL_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kVestelAcBits, ac._irsend.capture.bits);
ASSERT_EQ(expected_clocks, IRAcUtils::resultAcToString(&ac._irsend.capture));
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));

// Now check it sends both messages during normal operation when the
// clock is set.
Expand Down Expand Up @@ -1183,6 +1253,8 @@ TEST(TestIRac, Whirlpool) {
ASSERT_EQ(WHIRLPOOL_AC, ac._irsend.capture.decode_type);
ASSERT_EQ(kWhirlpoolAcBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

TEST(TestIRac, cmpStates) {
Expand Down Expand Up @@ -1577,6 +1649,8 @@ TEST(TestIRac, Issue1001) {
"On Timer: Off, Off Timer: Off, Sleep: Off, Super: Off, "
"Command: 1 (Power)",
IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));

// Now check if the mode is set to "Off" instead of just change to power off.
// i.e. How Home Assistant expects things to work.
Expand Down Expand Up @@ -1606,6 +1680,7 @@ TEST(TestIRac, Issue1001) {
"On Timer: Off, Off Timer: Off, Sleep: Off, Super: Off, "
"Command: 1 (Power)",
IRAcUtils::resultAcToString(&ac._irsend.capture));
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

// Check power switching in Daikin2 common a/c handling when from an IR message.
Expand Down
7 changes: 7 additions & 0 deletions test/ir_Argo_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright 2019 David Conran
#include "ir_Argo.h"
#include "IRac.h"
#include "IRrecv.h"
#include "IRrecv_test.h"
#include "IRsend.h"
Expand Down Expand Up @@ -105,6 +106,12 @@ TEST(TestDecodeArgo, SyntheticDecode) {
EXPECT_EQ(decode_type_t::ARGO, irsend.capture.decode_type);
EXPECT_EQ(kArgoBits, irsend.capture.bits);
EXPECT_STATE_EQ(expectedState, irsend.capture.state, irsend.capture.bits);
EXPECT_EQ(
"Power: On, Mode: 0 (Cool), Fan: 0 (Auto), Temp: 20C, Room Temp: 21C, "
"Max: On, IFeel: On, Night: On",
IRAcUtils::resultAcToString(&irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &r, &p));
}


Expand Down
Loading

0 comments on commit c5b6644

Please sign in to comment.