update serTcpOpen declaration to fix compile errors (#14113)
[betaflight.git] / src / test / unit / pg_unittest.cc
blob8746dd34e602a71e193bcf2933756cccc1943b3f
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 .dev = {.motorPwmRate = 400},
39 .maxthrottle = 1850,
40 .mincommand = 1000,
45 #include "unittest_macros.h"
46 #include "gtest/gtest.h"
48 TEST(ParameterGroupsfTest, Test_pgResetAll)
50 memset(motorConfigMutable(), 0, sizeof(motorConfig_t));
51 pgResetAll();
52 EXPECT_EQ(1850, motorConfig()->maxthrottle);
53 EXPECT_EQ(1000, motorConfig()->mincommand);
54 EXPECT_EQ(400, motorConfig()->dev.motorPwmRate);
57 TEST(ParameterGroupsfTest, Test_pgFind)
59 memset(motorConfigMutable(), 0, sizeof(motorConfig_t));
60 const pgRegistry_t *pgRegistry = pgFind(PG_MOTOR_CONFIG);
61 pgReset(pgRegistry);
62 EXPECT_EQ(1850, motorConfig()->maxthrottle);
63 EXPECT_EQ(1000, motorConfig()->mincommand);
64 EXPECT_EQ(400, motorConfig()->dev.motorPwmRate);
66 motorConfig_t motorConfig2;
67 memset(&motorConfig2, 0, sizeof(motorConfig_t));
68 motorConfigMutable()->dev.motorPwmRate = 500;
69 pgStore(pgRegistry, &motorConfig2, sizeof(motorConfig_t));
70 EXPECT_EQ(1850, motorConfig2.maxthrottle);
71 EXPECT_EQ(1000, motorConfig2.mincommand);
72 EXPECT_EQ(500, motorConfig2.dev.motorPwmRate);
74 motorConfig_t motorConfig3;
75 memset(&motorConfig3, 0, sizeof(motorConfig_t));
76 pgResetCopy(&motorConfig3, PG_MOTOR_CONFIG);
77 EXPECT_EQ(1850, motorConfig3.maxthrottle);
78 EXPECT_EQ(1000, motorConfig3.mincommand);
79 EXPECT_EQ(400, motorConfig3.dev.motorPwmRate);
82 // STUBS
84 extern "C" {