Skip to content

Commit

Permalink
Fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
howard0su committed Feb 22, 2019
1 parent b3051d1 commit 863df0f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/config/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand All @@ -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)},
Expand All @@ -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[] = {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/models/fx071.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions src/tests/models/yacht.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion src/tests/test_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct config_values {
u16 color_val;
u8 str_index_val;
u8 font_val;

u8 mixer;
} TestConfig;

enum {
Expand All @@ -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)},
Expand All @@ -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));

Expand Down Expand Up @@ -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);
}
43 changes: 25 additions & 18 deletions src/tests/test_model.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 863df0f

Please sign in to comment.