00001 #include "base.hpp"
00002
00003
00005
00009 void ExpectTestParameterDescriptorParameterDescriptors(
00010 const char* declarations,
00011 const char* values,
00012 const std::vector<TestParameterDescriptor>& expected
00013 )
00014 {
00015 std::stringstream testDescStream;
00016 testDescStream << "TestParameterDescriptor(\""
00017 << declarations
00018 << "\", \""
00019 << values
00020 << "\")";
00021 std::string testDesc = testDescStream.str();
00022
00023 SCOPED_TRACE(testDescStream.str());
00024
00025 TestParametersDescriptor desc(declarations, values);
00026 const std::vector<TestParameterDescriptor>& actual = desc.Parameters();
00027
00028 EXPECT_EQ(expected.size(), actual.size())
00029 << "Expected " << expected.size() << " parameters, but got "
00030 << actual.size();
00031
00032 std::size_t i = 0;
00033
00034 while ((i < actual.size()) && (i < expected.size()))
00035 {
00036 if ((expected[i].Declaration != actual[i].Declaration) ||
00037 (expected[i].Value != actual[i].Value))
00038 {
00039 ADD_FAILURE_STREAM("Expected Parameter[" << i << "] to be " <<
00040 expected[i] << " but it is " << actual[i]);
00041 }
00042
00043 ++i;
00044 }
00045
00046 if (i < actual.size())
00047 {
00048 std::stringstream msg;
00049 msg << "Unexpected parameters: ";
00050
00051 for (std::size_t j = i; j < actual.size(); ++j)
00052 {
00053 if (j > i)
00054 {
00055 msg << ", ";
00056 }
00057
00058 msg << actual[j];
00059 }
00060
00061 ADD_FAILURE() << msg;
00062 }
00063 else if (i < expected.size())
00064 {
00065 std::stringstream msg;
00066 msg << "Expected parameters: ";
00067
00068 for (std::size_t j = i; j < expected.size(); ++j)
00069 {
00070 if (j > i)
00071 {
00072 msg << ", ";
00073 }
00074
00075 msg << expected[j];
00076 }
00077
00078 ADD_FAILURE() << msg;
00079 }
00080 }
00081
00082
00083 TEST(TestParameterDescriptor, Constructor)
00084 {
00085
00086 {
00087 std::vector<TestParameterDescriptor> expected;
00088 ExpectTestParameterDescriptorParameterDescriptors("", "", expected);
00089 ExpectTestParameterDescriptorParameterDescriptors("()", "()", expected);
00090 }
00091
00092 {
00093 std::vector<TestParameterDescriptor> expected;
00094 expected.push_back(TestParameterDescriptor(
00095 "std::string a",
00096 "\"x\""
00097 ));
00098
00099 ExpectTestParameterDescriptorParameterDescriptors("(std::string a)",
00100 "(\"x\")",
00101 expected);
00102 }
00103
00104
00105 {
00106 std::vector<TestParameterDescriptor> expected;
00107 expected.push_back(TestParameterDescriptor(
00108 "std::string& a",
00109 "\"x\""
00110 ));
00111
00112 ExpectTestParameterDescriptorParameterDescriptors("(std::string& a)",
00113 "(\"x\")",
00114 expected);
00115 }
00116
00117 {
00118 std::vector<TestParameterDescriptor> expected;
00119 expected.push_back(TestParameterDescriptor(
00120 "std::string* a",
00121 "\"x\""
00122 ));
00123
00124 ExpectTestParameterDescriptorParameterDescriptors("(std::string* a)",
00125 "(\"x\")",
00126 expected);
00127 }
00128
00129 {
00130 std::vector<TestParameterDescriptor> expected;
00131 expected.push_back(TestParameterDescriptor(
00132 "std::string &a",
00133 "\"x\""
00134 ));
00135
00136 ExpectTestParameterDescriptorParameterDescriptors("(std::string &a)",
00137 "(\"x\")",
00138 expected);
00139 }
00140
00141 {
00142 std::vector<TestParameterDescriptor> expected;
00143 expected.push_back(TestParameterDescriptor(
00144 "std::string *a",
00145 "\"x\""
00146 ));
00147
00148 ExpectTestParameterDescriptorParameterDescriptors("(std::string *a)",
00149 "(\"x\")",
00150 expected);
00151 }
00152
00153
00154 {
00155 std::vector<TestParameterDescriptor> expected;
00156 expected.push_back(TestParameterDescriptor(
00157 "const std::string& a",
00158 "\"x\""
00159 ));
00160
00161 ExpectTestParameterDescriptorParameterDescriptors(
00162 "(const std::string& a)",
00163 "(\"x\")",
00164 expected
00165 );
00166 }
00167
00168 {
00169 std::vector<TestParameterDescriptor> expected;
00170 expected.push_back(TestParameterDescriptor(
00171 "const std::string &a",
00172 "\"x\""
00173 ));
00174
00175 ExpectTestParameterDescriptorParameterDescriptors(
00176 "(const std::string &a)",
00177 "(\"x\")",
00178 expected
00179 );
00180 }
00181
00182 {
00183 std::vector<TestParameterDescriptor> expected;
00184 expected.push_back(TestParameterDescriptor(
00185 "std::string a",
00186 "\"x\""
00187 ));
00188 expected.push_back(TestParameterDescriptor(
00189 "std::wstring b",
00190 "\"y\""
00191 ));
00192
00193 ExpectTestParameterDescriptorParameterDescriptors(
00194 "(std::string a, std::wstring b)",
00195 "(\"x\", \"y\")",
00196 expected
00197 );
00198 }
00199
00200
00201 {
00202 std::vector<TestParameterDescriptor> expected;
00203 expected.push_back(TestParameterDescriptor(
00204 "std::string a",
00205 "\"x\""
00206 ));
00207 expected.push_back(TestParameterDescriptor(
00208 "CrazyTemplate<'\\'', std::vector<std::string> > horse",
00209 "CrazyTemplate<'\\'', std::vector<std::string> >()"
00210 ));
00211
00212 ExpectTestParameterDescriptorParameterDescriptors(
00213 "(std::string a, CrazyTemplate<'\\'', std::vector<std::string> > horse)",
00214 "(\"x\", CrazyTemplate<'\\'', std::vector<std::string> >())",
00215 expected
00216 );
00217 }
00218
00219
00220 {
00221 std::vector<TestParameterDescriptor> expected;
00222 expected.push_back(TestParameterDescriptor(
00223 "std::string a",
00224 "\"x\""
00225 ));
00226 expected.push_back(TestParameterDescriptor(
00227 "int b",
00228 "-1"
00229 ));
00230
00231 ExpectTestParameterDescriptorParameterDescriptors(
00232 "(std::string a, int b = -1)",
00233 "(\"x\")",
00234 expected
00235 );
00236 ExpectTestParameterDescriptorParameterDescriptors(
00237 "(std::string a,int b=-1)",
00238 "(\"x\")",
00239 expected
00240 );
00241 }
00242
00243
00244 {
00245 std::vector<TestParameterDescriptor> expected;
00246 expected.push_back(TestParameterDescriptor(
00247 "...",
00248 "1, 2, 3"
00249 ));
00250
00251 ExpectTestParameterDescriptorParameterDescriptors(
00252 "(...)",
00253 "(1, 2, 3)",
00254 expected
00255 );
00256 }
00257
00258 {
00259 std::vector<TestParameterDescriptor> expected;
00260 expected.push_back(TestParameterDescriptor(
00261 "const char* fmt",
00262 "\"x\""
00263 ));
00264 expected.push_back(TestParameterDescriptor(
00265 "...",
00266 "1, 2, 3"
00267 ));
00268
00269 ExpectTestParameterDescriptorParameterDescriptors(
00270 "(const char* fmt, ...)",
00271 "(\"x\", 1, 2, 3)",
00272 expected
00273 );
00274 }
00275 }
00276
00277 int main(int argc, char** argv)
00278 {
00279 testing::InitGoogleTest(&argc, argv);
00280 return RUN_ALL_TESTS();
00281 }