00001
00002
00003
00005
00006
00008 #include <string>
00009 #include <vector>
00010 #include "Config/Param.h"
00011
00012 bool testConstructors()
00013 {
00014 std::cerr << "** begin[testConstructors] **" << std::endl;
00015 bool p1 = true;
00016 int p2 = 11121970;
00017 float p3 = 1112.1970;
00018 double p4 = 1112.1970;
00019 std::string p5 = "pumpkin juice";
00020 time_t p6 = time(NULL);
00021
00022 cfg::Param prm0;
00023 cfg::Param prm1("prm1",p1,"test bool");
00024 cfg::Param prm2("prm2",p2,"test int");
00025 cfg::Param prm3("prm3",p3,"test float");
00026 cfg::Param prm4("prm4",p4,"test double");
00027 cfg::Param prm5("prm5",p5,"test string");
00028 cfg::Param prm6(prm1);
00029 cfg::Param prm7(prm2);
00030 cfg::Param prm8(prm3);
00031 cfg::Param prm9(prm4);
00032 cfg::Param prm10(prm5);
00033 cfg::Param prm11("prm11",p6,"test time_t");
00034 cfg::Param prm12(prm11);
00035
00036 std::cerr <<
00037 prm1 << " | " <<
00038 prm2 << " | " <<
00039 prm3 << " | " <<
00040 prm4 << " | " <<
00041 prm5 << " | " <<
00042 prm11 << " | " <<
00043 std::endl <<
00044 prm6 << " | " <<
00045 prm7 << " | " <<
00046 prm8 << " | " <<
00047 prm9 << " | " <<
00048 prm10 << " | " <<
00049 prm12 << " * " <<
00050 std::endl;
00051
00052 std::vector<bool> pv1(3);
00053 std::vector<int> pv2(3);
00054 std::vector<float> pv3(3);
00055 std::vector<double> pv4(3);
00056 std::vector<std::string> pv5(3);
00057
00058 pv1[0] = true; pv1[1] = false; pv1[2] = true;
00059 pv2[0] = 11; pv2[1] = 22; pv2[2] = 33;
00060 pv3[0] = 11.1; pv3[1] = 22.2; pv3[2] = 33.3;
00061 pv4[0] = 11.1; pv4[1] = 22.2; pv4[2] = 33.3;
00062 pv5[0] = "One"; pv5[1] = "Two"; pv5[2] = "Three";
00063
00064 cfg::Param prmv1("prmv1",pv1,"vector of bools");
00065 cfg::Param prmv2("prmv2",pv2,"vector of ints");
00066 cfg::Param prmv3("prmv3",pv3,"vector of floats");
00067 cfg::Param prmv4("prmv4",pv4,"vector of doubles");
00068 cfg::Param prmv5("prmv5",pv5,"vector of strings");
00069 cfg::Param prmv6(prmv1);
00070 cfg::Param prmv7(prmv2);
00071 cfg::Param prmv8(prmv3);
00072 cfg::Param prmv9(prmv4);
00073 cfg::Param prmv10(prmv5);
00074
00075 std::cerr <<
00076 prmv1 << " | " <<
00077 prmv2 << " | " <<
00078 prmv3 << " | " <<
00079 prmv4 << " | " <<
00080 prmv5 << " | " <<
00081 std::endl <<
00082 prmv6 << " | " <<
00083 prmv7 << " | " <<
00084 prmv8 << " | " <<
00085 prmv9 << " | " <<
00086 prmv10 << " * " <<
00087 std::endl;
00088
00089 std::cerr << "** end[testConstructors] **" << std::endl;
00090
00091 return true;
00092 }
00093
00094
00095
00096 bool testSet()
00097 {
00098 std::cerr << "** begin[testSet] **" << std::endl;
00099 bool b = true;
00100 int i = 99;
00101 float f = 99.9;
00102 double d = 99.9;
00103 std::string s = "stringy";
00104 time_t t = time(NULL);
00105
00106 cfg::Param p("p1","test parameter");
00107
00108 p.Set(b); std::cerr << p << std::endl;
00109 p.Set(i); std::cerr << p << std::endl;
00110 p.Set(f); std::cerr << p << std::endl;
00111 p.Set(d); std::cerr << p << std::endl;
00112 p.Set(s); std::cerr << p << std::endl;
00113 p.Set(t); std::cerr << p << std::endl;
00114
00115 std::cerr << "** end[testSet] **" << std::endl;
00116 return true;
00117 }
00118
00119
00120
00121 bool testGet()
00122 {
00123 std::cerr << "** begin[testGet] **" << std::endl;
00124 bool b1 = true;
00125 int i1 = 99;
00126 float f1 = 99.9;
00127 double d1 = 99.9;
00128 std::string s1 = "stringy";
00129 time_t t1 = time(NULL);
00130
00131 bool b2;
00132 int i2;
00133 float f2;
00134 double d2;
00135 std::string s2;
00136 time_t t2;
00137
00138 cfg::Param p1("p1",b1,"b1");
00139 cfg::Param p2("p2",i1,"i1");
00140 cfg::Param p3("p3",f1,"f1");
00141 cfg::Param p4("p4",d1,"d1");
00142 cfg::Param p5("p5",s1,"s1");
00143 cfg::Param p6("p6",t1,"t1");
00144
00145 p1.Get(b2); if (b1!=b2) abort();
00146 p2.Get(i2); if (i1!=i2) abort();
00147 p3.Get(f2); if (f1!=f2) abort();
00148 p4.Get(d2); if (d1!=d2) abort();
00149 p5.Get(s2); if (s1!=s2) abort();
00150 p6.Get(t2); if (t1!=t2) abort();
00151
00152 int i3;
00153 try {
00154 std::cerr << "Test exception on type-mismatch:" << std::endl;
00155 p3.Get(i3);
00156 }
00157 catch (cfg::Exception& e) {
00158 std::cerr << "Exception thrown: correct behavior!" << std::endl;
00159 }
00160
00161 std::cerr
00162 << p1 << " | "
00163 << p2 << " | "
00164 << p3 << " | "
00165 << p4 << " | "
00166 << p5
00167 << std::endl;
00168
00169 std::cerr << "** end[testGet] **" << std::endl;
00170 return true;
00171 }
00172
00173
00174
00175 int main(void)
00176 {
00177 if (testConstructors() == false) return 1;
00178 if (testSet() == false) return 1;
00179 if (testGet() == false) return 1;
00180 return 0;
00181 }
00182