From 863df0f0234bb8be8ac1e04c1d551550249f4319 Mon Sep 17 00:00:00 2001 From: Howard Su Date: Sat, 23 Feb 2019 00:04:45 +0800 Subject: [PATCH] Fix the tests --- src/config/model.c | 6 +++--- src/tests/models/fx071.ini | 2 +- src/tests/models/yacht.ini | 4 ---- src/tests/test_config.c | 20 +++++++++++++++++- src/tests/test_model.c | 43 ++++++++++++++++++++++---------------- 5 files changed, 48 insertions(+), 27 deletions(-) diff --git a/src/config/model.c b/src/config/model.c index 81ca3d8b1c..6d410301aa 100644 --- a/src/config/model.c +++ b/src/config/model.c @@ -536,7 +536,7 @@ static const struct struct_map _secmixer[] = { {MIXER_OFFSET, OFFSETS(struct Mixer, offset)}, }; static const u16 _secmixer_defaults[] = { - 100 + 100, 0, 0 }; static const struct struct_map _seclimit[] = { {CHAN_LIMIT_SAFETYSW, OFFSET_SRC(struct Limit, safetysw)}, @@ -557,7 +557,7 @@ static const struct struct_map _sectrim[] = { {TRIM_NEG, OFFSET_BUT(struct Trim, neg)}, }; static const u16 _sectrim_defaults[] = { - 1 + 1, 0, 0 }; static const struct struct_map _sectrim_rdonly[] = { {TRIM_SOURCE, OFFSET_SRC(struct Trim, src)}, @@ -570,7 +570,7 @@ static const struct struct_map _secswash[] = { {SWASH_TYPE, OFFSET_STRCALL(struct Model, swash_type, MIXER_SwashType, SWASH_TYPE_LAST)}, }; static const u16 _secswash_defaults[] = { - 60, 60, 60 + 60, 60, 60, 0 }; static const struct struct_map _sectimer[] = { diff --git a/src/tests/models/fx071.ini b/src/tests/models/fx071.ini index d3d68a35f6..9f116f199e 100644 --- a/src/tests/models/fx071.ini +++ b/src/tests/models/fx071.ini @@ -2,7 +2,7 @@ name=FX071-Kiwi.Craig mixermode=Advanced icon=FX071.BMP [radio] -protocol=KNFX +protocol=KN num_channels=10 fixed_id=123456 tx_power=100mW diff --git a/src/tests/models/yacht.ini b/src/tests/models/yacht.ini index 46d85c47c3..385779e5d2 100644 --- a/src/tests/models/yacht.ini +++ b/src/tests/models/yacht.ini @@ -61,10 +61,6 @@ resetsrc=ELE DR1 type=permanent src=Ch3 val=19187434 -[telemalarm1] -source=RxV -above=1 -value=500 [datalog] switch=None rate=1 sec diff --git a/src/tests/test_config.c b/src/tests/test_config.c index 97ac20a1cd..a3a3224fd8 100644 --- a/src/tests/test_config.c +++ b/src/tests/test_config.c @@ -12,6 +12,8 @@ struct config_values { u16 color_val; u8 str_index_val; u8 font_val; + + u8 mixer; } TestConfig; enum { @@ -27,6 +29,13 @@ static const char * const ALIGN_VAL[] = { [STR_RIGHT] = "right", }; +static const char *string_values(int i) { + if (i == 0) + return "standard"; + else + return "advanced"; +} + static const struct struct_map _secgeneral[] = { {"u8val", OFFSET(struct config_values, u8_val)}, @@ -38,9 +47,9 @@ static const struct struct_map _secgeneral[] = {"index", OFFSET_STRLIST(struct config_values, str_index_val, ALIGN_VAL, ARRAYSIZE(ALIGN_VAL))}, {"color", OFFSET_COL(struct config_values, color_val)}, {"font", OFFSET_FON(struct config_values, font_val)}, + {"mixer", OFFSET_STRCALL(struct config_values, mixer, string_values, 2)}, }; - void TestConfigBasic(CuTest* t) { memset(&TestConfig, 0, sizeof(TestConfig)); @@ -90,3 +99,12 @@ void TestConfigFont(CuTest* t) CuAssertTrue(t, assign_int(&TestConfig, _secgeneral, ARRAYSIZE(_secgeneral), "font", "font1")); CuAssertIntEquals(t, fontindex, TestConfig.font_val); } + +void TestConfigStringCallback(CuTest* t) +{ + CuAssertTrue(t, assign_int(&TestConfig, _secgeneral, ARRAYSIZE(_secgeneral), "mixer", "standard")); + CuAssertIntEquals(t, 0, TestConfig.mixer); + + CuAssertTrue(t, assign_int(&TestConfig, _secgeneral, ARRAYSIZE(_secgeneral), "mixer", "advanced")); + CuAssertIntEquals(t, 1, TestConfig.mixer); +} diff --git a/src/tests/test_model.c b/src/tests/test_model.c index f4754db55e..a4ec040959 100644 --- a/src/tests/test_model.c +++ b/src/tests/test_model.c @@ -14,6 +14,7 @@ u8 CONFIG_ReadModel_new(const char* file) { CONFIG_ReadLayout("layout/default.ini"); if(! PROTOCOL_HasPowerAmp(Model.protocol)) Model.tx_power = TXPOWER_150mW; + Model.radio = PROTOCOL_GetRadio(Model.protocol); MIXER_SetMixers(NULL, 0); if(auto_map) RemapChannelsForProtocol(EATRG0); @@ -23,22 +24,25 @@ u8 CONFIG_ReadModel_new(const char* file) { } const char* const names[] = { -"tests/models/280qav.ini", -"tests/models/bixler2.ini", -"tests/models/geniuscp.ini", -"tests/models/yacht.ini", - -"tests/models/4g6s.ini", -"tests/models/blade130x.ini", -"tests/models/nazath.ini", - -"tests/models/apm.ini", -"tests/models/deltaray.ini", -"tests/models/trex150dfc.ini", - -"tests/models/ardrone2.ini", -"tests/models/fx071.ini", -"tests/models/wltoys931.ini", +// "../../tests/models/geniuscp.ini", + +"../../tests/models/fx071.ini", + +"../../tests/models/280qav.ini", +"../../tests/models/bixler2.ini", + +"../../tests/models/yacht.ini", + +"../../tests/models/4g6s.ini", +"../../tests/models/blade130x.ini", +"../../tests/models/nazath.ini", + +"../../tests/models/apm.ini", +"../../tests/models/deltaray.ini", +"../../tests/models/trex150dfc.ini", + +"../../tests/models/ardrone2.ini", +"../../tests/models/wltoys931.ini", }; void TestNewAndOld(CuTest *t) @@ -48,15 +52,18 @@ void TestNewAndOld(CuTest *t) for (unsigned i = 0; i < ARRAYSIZE(names); i++) { const char *filename = names[i]; printf("Test model: %s\n", filename); - CONFIG_ReadModel_old(filename); + CuAssertTrue(t, CONFIG_ReadModel_old(filename)); memcpy(&ValidateModel, &Model, sizeof(Model)); - CONFIG_ReadModel_new(filename); + CuAssertTrue(t, CONFIG_ReadModel_new(filename)); + printf("\tRead successfully\n", filename); CuAssertTrue(t, memcmp(&ValidateModel, &Model, sizeof(Model)) == 0); + printf("\tRead result is identical\n", filename); CONFIG_WriteModel(1); CONFIG_ReadModel(1); CuAssertTrue(t, memcmp(&ValidateModel, &Model, sizeof(Model)) == 0); + printf("\tWrite result is identical\n", filename); } }