parameters.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Includes
00011 *****************************************************************************/
00012 
00013 #include <gtest/gtest.h>
00014 #include "../../include/ecl/utilities/parameter.hpp"
00015 
00020 /*****************************************************************************
00021  * Classes
00022  ****************************************************************************/
00023 
00024 namespace ecl {
00025 namespace utilities {
00026 namespace tests {
00027 
00028 
00029 class ParameterTest {
00030 public:
00031         ParameterTest() : value(3) {};
00032     Parameter<int> value;
00033 };
00034 
00035 }}}
00036 
00037 /*****************************************************************************
00038 ** Using
00039 *****************************************************************************/
00040 
00041 using ecl::Parameter;
00042 using ecl::utilities::tests::ParameterTest;
00043 
00044 /*****************************************************************************
00045 ** Tests
00046 *****************************************************************************/
00047 
00048 TEST(Parameter,get) {
00049 
00050         ParameterTest test;
00051     int i1 = test.value();
00052     // int &i2 = test.value(); // This one is not permitted the class loses control of the variable.
00053     const int i3 = test.value();
00054     const int &i4 = test.value();
00055     EXPECT_EQ(3,i1);
00056     EXPECT_EQ(3,i3);
00057     EXPECT_EQ(3,i4);
00058 }
00059 
00060 TEST(Parameter,set) {
00061 
00062         ParameterTest test;
00063     int i1 = test.value();
00064         int i_tmp = 3;
00065         int &i2 = i_tmp;
00066         const int i3 = test.value();
00067         const int &i4 = test.value();
00068         test.value(3);      // temporary
00069         EXPECT_EQ(3,test.value());
00070         test.value(i1);     // int
00071         EXPECT_EQ(3,test.value());
00072         test.value(i2);     // int&
00073         EXPECT_EQ(3,test.value());
00074         test.value(i3);     // const int
00075         EXPECT_EQ(3,test.value());
00076         test.value(i4);     // const int&
00077         EXPECT_EQ(3,test.value());
00078 }
00079 
00080 TEST(Parameter,assign) {
00081 
00082         ParameterTest test;
00083     int i1 = test.value();
00084         int i_tmp = 3;
00085         int &i2 = i_tmp;
00086         const int i3 = test.value();
00087         const int &i4 = test.value();
00088 
00089         test.value = 3;      // temporary
00090         EXPECT_EQ(3,test.value());
00091     test.value = i1;     // int
00092         EXPECT_EQ(3,test.value());
00093     test.value = i2;     // int&
00094         EXPECT_EQ(3,test.value());
00095     test.value = i3;     // const int
00096         EXPECT_EQ(3,test.value());
00097     test.value = i4;     // const int&
00098         EXPECT_EQ(3,test.value());
00099 }
00100 
00101 TEST(Parameter,eval) {
00102 
00103         ParameterTest test;
00104         int i1;
00105         i1 = test.value;
00106         EXPECT_EQ(3,i1);
00107 //    int &i5 = test.value; // This one is not permitted the class loses control of the variable.
00108     const int &i5 = test.value;
00109         EXPECT_EQ(3,i5);
00110     const int i6 = test.value;
00111         EXPECT_EQ(3,i6);
00112     i1 = i5;  // remove the warning
00113         EXPECT_EQ(3,i1);
00114     i1 = i6;  // remove the warning
00115         EXPECT_EQ(3,i1);
00116 }
00117 
00118 /*****************************************************************************
00119 ** Main program
00120 *****************************************************************************/
00121 
00122 int main(int argc, char **argv) {
00123         testing::InitGoogleTest(&argc,argv);
00124         return RUN_ALL_TESTS();
00125 }


ecl_utilities
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:17:40