parameters.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <gtest/gtest.h>
14 #include "../../include/ecl/utilities/parameter.hpp"
15 
20 /*****************************************************************************
21  * Classes
22  ****************************************************************************/
23 
24 namespace ecl {
25 namespace utilities {
26 namespace tests {
27 
28 
29 class ParameterTest {
30 public:
31  ParameterTest() : value(3) {};
32  Parameter<int> value;
33 };
34 
35 }}}
36 
37 /*****************************************************************************
38 ** Using
39 *****************************************************************************/
40 
41 using ecl::Parameter;
42 using ecl::utilities::tests::ParameterTest;
43 
44 /*****************************************************************************
45 ** Tests
46 *****************************************************************************/
47 
48 TEST(Parameter,get) {
49 
50  ParameterTest test;
51  int i1 = test.value();
52  // int &i2 = test.value(); // This one is not permitted the class loses control of the variable.
53  const int i3 = test.value();
54  const int &i4 = test.value();
55  EXPECT_EQ(3,i1);
56  EXPECT_EQ(3,i3);
57  EXPECT_EQ(3,i4);
58 }
59 
60 TEST(Parameter,set) {
61 
62  ParameterTest test;
63  int i1 = test.value();
64  int i_tmp = 3;
65  int &i2 = i_tmp;
66  const int i3 = test.value();
67  const int &i4 = test.value();
68  test.value(3); // temporary
69  EXPECT_EQ(3,test.value());
70  test.value(i1); // int
71  EXPECT_EQ(3,test.value());
72  test.value(i2); // int&
73  EXPECT_EQ(3,test.value());
74  test.value(i3); // const int
75  EXPECT_EQ(3,test.value());
76  test.value(i4); // const int&
77  EXPECT_EQ(3,test.value());
78 }
79 
80 TEST(Parameter,assign) {
81 
82  ParameterTest test;
83  int i1 = test.value();
84  int i_tmp = 3;
85  int &i2 = i_tmp;
86  const int i3 = test.value();
87  const int &i4 = test.value();
88 
89  test.value = 3; // temporary
90  EXPECT_EQ(3,test.value());
91  test.value = i1; // int
92  EXPECT_EQ(3,test.value());
93  test.value = i2; // int&
94  EXPECT_EQ(3,test.value());
95  test.value = i3; // const int
96  EXPECT_EQ(3,test.value());
97  test.value = i4; // const int&
98  EXPECT_EQ(3,test.value());
99 }
100 
101 TEST(Parameter,eval) {
102 
103  ParameterTest test;
104  int i1;
105  i1 = test.value;
106  EXPECT_EQ(3,i1);
107 // int &i5 = test.value; // This one is not permitted the class loses control of the variable.
108  const int &i5 = test.value;
109  EXPECT_EQ(3,i5);
110  const int i6 = test.value;
111  EXPECT_EQ(3,i6);
112  i1 = i5; // remove the warning
113  EXPECT_EQ(3,i1);
114  i1 = i6; // remove the warning
115  EXPECT_EQ(3,i1);
116 }
117 
118 /*****************************************************************************
119 ** Main program
120 *****************************************************************************/
121 
122 int main(int argc, char **argv) {
123  testing::InitGoogleTest(&argc,argv);
124  return RUN_ALL_TESTS();
125 }
ecl::Parameter
General parameter type for member variables of a pre-specified class.
Definition: parameter.hpp:60
TEST
TEST(TypeTests, fundamentals)
main
int main(int argc, char **argv)
ecl
Embedded control libraries.


ecl_utilities
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:32