F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title main.cpp
3// \author T. Chieu
4// \brief main cpp file for FPP enum tests
5//
6// \copyright
7// Copyright (C) 2009-2022 California Institute of Technology.
8// ALL RIGHTS RESERVED. United States Government Sponsorship
9// acknowledged.
10//
11// ======================================================================
12
13#include "FppTest/enum/ImplicitEnumAc.hpp"
14#include "FppTest/enum/ExplicitEnumAc.hpp"
15#include "FppTest/enum/DefaultEnumAc.hpp"
16#include "FppTest/enum/IntervalEnumAc.hpp"
17#include "FppTest/enum/SerializeTypeU8EnumAc.hpp"
18#include "FppTest/enum/SerializeTypeU64EnumAc.hpp"
19
21
22#include "STest/Random/Random.hpp"
23#include "gtest/gtest.h"
24
25// Instantiate enum tests
26using EnumTestImplementations = ::testing::Types<
27 Implicit,
28 Explicit,
29 Default,
30 Interval,
31 SerializeTypeU8,
32 SerializeTypeU64
33>;
35 EnumTest,
37
38// Specializations for default value
39template<>
40Explicit::T FppTest::Enum::getDefaultValue<Explicit>() {
41 return Explicit::A;
42}
43
44template<>
45Default::T FppTest::Enum::getDefaultValue<Default>() {
46 return Default::C;
47}
48
49// Specializations for valid value
50template<>
51Explicit::T FppTest::Enum::getValidValue<Explicit>() {
52 U32 val = STest::Pick::startLength(0, Explicit::NUM_CONSTANTS);
53
54 switch (val) {
55 case 0: return Explicit::A;
56 case 1: return Explicit::B;
57 default: return Explicit::C;
58 }
59}
60
61template<>
62Interval::T FppTest::Enum::getValidValue<Interval>() {
63 U32 val = STest::Pick::startLength(0, Interval::NUM_CONSTANTS);
64
65 switch (val) {
66 case 0: return Interval::A;
67 case 1: return Interval::B;
68 case 2: return Interval::C;
69 case 3: return Interval::D;
70 case 4: return Interval::E;
71 case 5: return Interval::F;
72 default: return Interval::G;
73 }
74}
75
76// Specializations for invalid value
77template <>
78Explicit::T FppTest::Enum::getInvalidValue<Explicit>() {
79 U32 sign = STest::Pick::lowerUpper(0, 1);
80
81 switch (sign) {
82 case 0:
83 return static_cast<Explicit::T>(STest::Pick::lowerUpper(
84 Explicit::C + 1,
85 std::numeric_limits<Explicit::SerialType>::max()
86 ));
87 default:
88 return static_cast<Explicit::T>(STest::Pick::lowerUpper(
89 (Explicit::A - 1) * (-1),
90 std::numeric_limits<Explicit::SerialType>::max()
91 ) * (-1));
92 }
93}
94
95template<>
96Interval::T FppTest::Enum::getInvalidValue<Interval>() {
97 return static_cast<Interval::T>(STest::Pick::lowerUpper(
98 Interval::G + 1,
99 std::numeric_limits<Interval::SerialType>::max()
100 ));
101}
102
103int main(int argc, char* argv[]) {
104 ::testing::InitGoogleTest(&argc, argv);
105 STest::Random::seed();
106
107 return RUN_ALL_TESTS();
108}
int main(int argc, char *argv[])
Definition main.cpp:141
INSTANTIATE_TYPED_TEST_SUITE_P(FppTest, ArrayTest, ArrayTestImplementations)
::testing::Types< Implicit, Explicit, Default, Interval, SerializeTypeU8, SerializeTypeU64 > EnumTestImplementations
Definition main.cpp:33