Updated and Validated
[betaflight.git] / src / test / unit / pg_unittest.cc
blob89d1a6a0d1b4f37d6dc38e83e6b88a5609eebeef
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdbool.h>
19 #include <stdint.h>
20 #include <string.h>
22 #include <limits.h>
24 extern "C" {
25 #include <platform.h>
26 #include "build/debug.h"
27 #include "pg/pg.h"
28 #include "pg/pg_ids.h"
29 #include "pg/motor.h"
31 #include "flight/mixer.h"
33 //PG_DECLARE(motorConfig_t, motorConfig);
35 PG_REGISTER_WITH_RESET_TEMPLATE(motorConfig_t, motorConfig, PG_MOTOR_CONFIG, 1);
37 PG_RESET_TEMPLATE(motorConfig_t, motorConfig,
38 .minthrottle = 1150,
39 .maxthrottle = 1850,
40 .mincommand = 1000,
41 .dev = {.motorPwmRate = 400}
46 #include "unittest_macros.h"
47 #include "gtest/gtest.h"
49 TEST(ParameterGroupsfTest, Test_pgResetAll)
51 memset(motorConfigMutable(), 0, sizeof(motorConfig_t));
52 pgResetAll();
53 EXPECT_EQ(1150, motorConfig()->minthrottle);
54 EXPECT_EQ(1850, motorConfig()->maxthrottle);
55 EXPECT_EQ(1000, motorConfig()->mincommand);
56 EXPECT_EQ(400, motorConfig()->dev.motorPwmRate);
59 TEST(ParameterGroupsfTest, Test_pgFind)
61 memset(motorConfigMutable(), 0, sizeof(motorConfig_t));
62 const pgRegistry_t *pgRegistry = pgFind(PG_MOTOR_CONFIG);
63 pgReset(pgRegistry);
64 EXPECT_EQ(1150, motorConfig()->minthrottle);
65 EXPECT_EQ(1850, motorConfig()->maxthrottle);
66 EXPECT_EQ(1000, motorConfig()->mincommand);
67 EXPECT_EQ(400, motorConfig()->dev.motorPwmRate);
69 motorConfig_t motorConfig2;
70 memset(&motorConfig2, 0, sizeof(motorConfig_t));
71 motorConfigMutable()->dev.motorPwmRate = 500;
72 pgStore(pgRegistry, &motorConfig2, sizeof(motorConfig_t));
73 EXPECT_EQ(1150, motorConfig2.minthrottle);
74 EXPECT_EQ(1850, motorConfig2.maxthrottle);
75 EXPECT_EQ(1000, motorConfig2.mincommand);
76 EXPECT_EQ(500, motorConfig2.dev.motorPwmRate);
78 motorConfig_t motorConfig3;
79 memset(&motorConfig3, 0, sizeof(motorConfig_t));
80 pgResetCopy(&motorConfig3, PG_MOTOR_CONFIG);
81 EXPECT_EQ(1150, motorConfig3.minthrottle);
82 EXPECT_EQ(1850, motorConfig3.maxthrottle);
83 EXPECT_EQ(1000, motorConfig3.mincommand);
84 EXPECT_EQ(400, motorConfig3.dev.motorPwmRate);
87 // STUBS
89 extern "C" {