googletest-param-test-test.cc 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. // Copyright 2008, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. //
  30. // Tests for Google Test itself. This file verifies that the parameter
  31. // generators objects produce correct parameter sequences and that
  32. // Google Test runtime instantiates correct tests from those sequences.
  33. #include "gtest/gtest.h"
  34. # include <algorithm>
  35. # include <iostream>
  36. # include <list>
  37. # include <sstream>
  38. # include <string>
  39. # include <vector>
  40. # include "src/gtest-internal-inl.h" // for UnitTestOptions
  41. # include "test/googletest-param-test-test.h"
  42. using ::std::vector;
  43. using ::std::sort;
  44. using ::testing::AddGlobalTestEnvironment;
  45. using ::testing::Bool;
  46. using ::testing::Message;
  47. using ::testing::Range;
  48. using ::testing::TestWithParam;
  49. using ::testing::Values;
  50. using ::testing::ValuesIn;
  51. # if GTEST_HAS_COMBINE
  52. using ::testing::Combine;
  53. using ::testing::get;
  54. using ::testing::make_tuple;
  55. using ::testing::tuple;
  56. # endif // GTEST_HAS_COMBINE
  57. using ::testing::internal::ParamGenerator;
  58. using ::testing::internal::UnitTestOptions;
  59. // Prints a value to a string.
  60. //
  61. // FIXME: remove PrintValue() when we move matchers and
  62. // EXPECT_THAT() from Google Mock to Google Test. At that time, we
  63. // can write EXPECT_THAT(x, Eq(y)) to compare two tuples x and y, as
  64. // EXPECT_THAT() and the matchers know how to print tuples.
  65. template <typename T>
  66. ::std::string PrintValue(const T& value) {
  67. ::std::stringstream stream;
  68. stream << value;
  69. return stream.str();
  70. }
  71. # if GTEST_HAS_COMBINE
  72. // These overloads allow printing tuples in our tests. We cannot
  73. // define an operator<< for tuples, as that definition needs to be in
  74. // the std namespace in order to be picked up by Google Test via
  75. // Argument-Dependent Lookup, yet defining anything in the std
  76. // namespace in non-STL code is undefined behavior.
  77. template <typename T1, typename T2>
  78. ::std::string PrintValue(const tuple<T1, T2>& value) {
  79. ::std::stringstream stream;
  80. stream << "(" << get<0>(value) << ", " << get<1>(value) << ")";
  81. return stream.str();
  82. }
  83. template <typename T1, typename T2, typename T3>
  84. ::std::string PrintValue(const tuple<T1, T2, T3>& value) {
  85. ::std::stringstream stream;
  86. stream << "(" << get<0>(value) << ", " << get<1>(value)
  87. << ", "<< get<2>(value) << ")";
  88. return stream.str();
  89. }
  90. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  91. typename T6, typename T7, typename T8, typename T9, typename T10>
  92. ::std::string PrintValue(
  93. const tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& value) {
  94. ::std::stringstream stream;
  95. stream << "(" << get<0>(value) << ", " << get<1>(value)
  96. << ", "<< get<2>(value) << ", " << get<3>(value)
  97. << ", "<< get<4>(value) << ", " << get<5>(value)
  98. << ", "<< get<6>(value) << ", " << get<7>(value)
  99. << ", "<< get<8>(value) << ", " << get<9>(value) << ")";
  100. return stream.str();
  101. }
  102. # endif // GTEST_HAS_COMBINE
  103. // Verifies that a sequence generated by the generator and accessed
  104. // via the iterator object matches the expected one using Google Test
  105. // assertions.
  106. template <typename T, size_t N>
  107. void VerifyGenerator(const ParamGenerator<T>& generator,
  108. const T (&expected_values)[N]) {
  109. typename ParamGenerator<T>::iterator it = generator.begin();
  110. for (size_t i = 0; i < N; ++i) {
  111. ASSERT_FALSE(it == generator.end())
  112. << "At element " << i << " when accessing via an iterator "
  113. << "created with the copy constructor.\n";
  114. // We cannot use EXPECT_EQ() here as the values may be tuples,
  115. // which don't support <<.
  116. EXPECT_TRUE(expected_values[i] == *it)
  117. << "where i is " << i
  118. << ", expected_values[i] is " << PrintValue(expected_values[i])
  119. << ", *it is " << PrintValue(*it)
  120. << ", and 'it' is an iterator created with the copy constructor.\n";
  121. ++it;
  122. }
  123. EXPECT_TRUE(it == generator.end())
  124. << "At the presumed end of sequence when accessing via an iterator "
  125. << "created with the copy constructor.\n";
  126. // Test the iterator assignment. The following lines verify that
  127. // the sequence accessed via an iterator initialized via the
  128. // assignment operator (as opposed to a copy constructor) matches
  129. // just the same.
  130. it = generator.begin();
  131. for (size_t i = 0; i < N; ++i) {
  132. ASSERT_FALSE(it == generator.end())
  133. << "At element " << i << " when accessing via an iterator "
  134. << "created with the assignment operator.\n";
  135. EXPECT_TRUE(expected_values[i] == *it)
  136. << "where i is " << i
  137. << ", expected_values[i] is " << PrintValue(expected_values[i])
  138. << ", *it is " << PrintValue(*it)
  139. << ", and 'it' is an iterator created with the copy constructor.\n";
  140. ++it;
  141. }
  142. EXPECT_TRUE(it == generator.end())
  143. << "At the presumed end of sequence when accessing via an iterator "
  144. << "created with the assignment operator.\n";
  145. }
  146. template <typename T>
  147. void VerifyGeneratorIsEmpty(const ParamGenerator<T>& generator) {
  148. typename ParamGenerator<T>::iterator it = generator.begin();
  149. EXPECT_TRUE(it == generator.end());
  150. it = generator.begin();
  151. EXPECT_TRUE(it == generator.end());
  152. }
  153. // Generator tests. They test that each of the provided generator functions
  154. // generates an expected sequence of values. The general test pattern
  155. // instantiates a generator using one of the generator functions,
  156. // checks the sequence produced by the generator using its iterator API,
  157. // and then resets the iterator back to the beginning of the sequence
  158. // and checks the sequence again.
  159. // Tests that iterators produced by generator functions conform to the
  160. // ForwardIterator concept.
  161. TEST(IteratorTest, ParamIteratorConformsToForwardIteratorConcept) {
  162. const ParamGenerator<int> gen = Range(0, 10);
  163. ParamGenerator<int>::iterator it = gen.begin();
  164. // Verifies that iterator initialization works as expected.
  165. ParamGenerator<int>::iterator it2 = it;
  166. EXPECT_TRUE(*it == *it2) << "Initialized iterators must point to the "
  167. << "element same as its source points to";
  168. // Verifies that iterator assignment works as expected.
  169. ++it;
  170. EXPECT_FALSE(*it == *it2);
  171. it2 = it;
  172. EXPECT_TRUE(*it == *it2) << "Assigned iterators must point to the "
  173. << "element same as its source points to";
  174. // Verifies that prefix operator++() returns *this.
  175. EXPECT_EQ(&it, &(++it)) << "Result of the prefix operator++ must be "
  176. << "refer to the original object";
  177. // Verifies that the result of the postfix operator++ points to the value
  178. // pointed to by the original iterator.
  179. int original_value = *it; // Have to compute it outside of macro call to be
  180. // unaffected by the parameter evaluation order.
  181. EXPECT_EQ(original_value, *(it++));
  182. // Verifies that prefix and postfix operator++() advance an iterator
  183. // all the same.
  184. it2 = it;
  185. ++it;
  186. ++it2;
  187. EXPECT_TRUE(*it == *it2);
  188. }
  189. // Tests that Range() generates the expected sequence.
  190. TEST(RangeTest, IntRangeWithDefaultStep) {
  191. const ParamGenerator<int> gen = Range(0, 3);
  192. const int expected_values[] = {0, 1, 2};
  193. VerifyGenerator(gen, expected_values);
  194. }
  195. // Edge case. Tests that Range() generates the single element sequence
  196. // as expected when provided with range limits that are equal.
  197. TEST(RangeTest, IntRangeSingleValue) {
  198. const ParamGenerator<int> gen = Range(0, 1);
  199. const int expected_values[] = {0};
  200. VerifyGenerator(gen, expected_values);
  201. }
  202. // Edge case. Tests that Range() with generates empty sequence when
  203. // supplied with an empty range.
  204. TEST(RangeTest, IntRangeEmpty) {
  205. const ParamGenerator<int> gen = Range(0, 0);
  206. VerifyGeneratorIsEmpty(gen);
  207. }
  208. // Tests that Range() with custom step (greater then one) generates
  209. // the expected sequence.
  210. TEST(RangeTest, IntRangeWithCustomStep) {
  211. const ParamGenerator<int> gen = Range(0, 9, 3);
  212. const int expected_values[] = {0, 3, 6};
  213. VerifyGenerator(gen, expected_values);
  214. }
  215. // Tests that Range() with custom step (greater then one) generates
  216. // the expected sequence when the last element does not fall on the
  217. // upper range limit. Sequences generated by Range() must not have
  218. // elements beyond the range limits.
  219. TEST(RangeTest, IntRangeWithCustomStepOverUpperBound) {
  220. const ParamGenerator<int> gen = Range(0, 4, 3);
  221. const int expected_values[] = {0, 3};
  222. VerifyGenerator(gen, expected_values);
  223. }
  224. // Verifies that Range works with user-defined types that define
  225. // copy constructor, operator=(), operator+(), and operator<().
  226. class DogAdder {
  227. public:
  228. explicit DogAdder(const char* a_value) : value_(a_value) {}
  229. DogAdder(const DogAdder& other) : value_(other.value_.c_str()) {}
  230. DogAdder operator=(const DogAdder& other) {
  231. if (this != &other)
  232. value_ = other.value_;
  233. return *this;
  234. }
  235. DogAdder operator+(const DogAdder& other) const {
  236. Message msg;
  237. msg << value_.c_str() << other.value_.c_str();
  238. return DogAdder(msg.GetString().c_str());
  239. }
  240. bool operator<(const DogAdder& other) const {
  241. return value_ < other.value_;
  242. }
  243. const std::string& value() const { return value_; }
  244. private:
  245. std::string value_;
  246. };
  247. TEST(RangeTest, WorksWithACustomType) {
  248. const ParamGenerator<DogAdder> gen =
  249. Range(DogAdder("cat"), DogAdder("catdogdog"), DogAdder("dog"));
  250. ParamGenerator<DogAdder>::iterator it = gen.begin();
  251. ASSERT_FALSE(it == gen.end());
  252. EXPECT_STREQ("cat", it->value().c_str());
  253. ASSERT_FALSE(++it == gen.end());
  254. EXPECT_STREQ("catdog", it->value().c_str());
  255. EXPECT_TRUE(++it == gen.end());
  256. }
  257. class IntWrapper {
  258. public:
  259. explicit IntWrapper(int a_value) : value_(a_value) {}
  260. IntWrapper(const IntWrapper& other) : value_(other.value_) {}
  261. IntWrapper operator=(const IntWrapper& other) {
  262. value_ = other.value_;
  263. return *this;
  264. }
  265. // operator+() adds a different type.
  266. IntWrapper operator+(int other) const { return IntWrapper(value_ + other); }
  267. bool operator<(const IntWrapper& other) const {
  268. return value_ < other.value_;
  269. }
  270. int value() const { return value_; }
  271. private:
  272. int value_;
  273. };
  274. TEST(RangeTest, WorksWithACustomTypeWithDifferentIncrementType) {
  275. const ParamGenerator<IntWrapper> gen = Range(IntWrapper(0), IntWrapper(2));
  276. ParamGenerator<IntWrapper>::iterator it = gen.begin();
  277. ASSERT_FALSE(it == gen.end());
  278. EXPECT_EQ(0, it->value());
  279. ASSERT_FALSE(++it == gen.end());
  280. EXPECT_EQ(1, it->value());
  281. EXPECT_TRUE(++it == gen.end());
  282. }
  283. // Tests that ValuesIn() with an array parameter generates
  284. // the expected sequence.
  285. TEST(ValuesInTest, ValuesInArray) {
  286. int array[] = {3, 5, 8};
  287. const ParamGenerator<int> gen = ValuesIn(array);
  288. VerifyGenerator(gen, array);
  289. }
  290. // Tests that ValuesIn() with a const array parameter generates
  291. // the expected sequence.
  292. TEST(ValuesInTest, ValuesInConstArray) {
  293. const int array[] = {3, 5, 8};
  294. const ParamGenerator<int> gen = ValuesIn(array);
  295. VerifyGenerator(gen, array);
  296. }
  297. // Edge case. Tests that ValuesIn() with an array parameter containing a
  298. // single element generates the single element sequence.
  299. TEST(ValuesInTest, ValuesInSingleElementArray) {
  300. int array[] = {42};
  301. const ParamGenerator<int> gen = ValuesIn(array);
  302. VerifyGenerator(gen, array);
  303. }
  304. // Tests that ValuesIn() generates the expected sequence for an STL
  305. // container (vector).
  306. TEST(ValuesInTest, ValuesInVector) {
  307. typedef ::std::vector<int> ContainerType;
  308. ContainerType values;
  309. values.push_back(3);
  310. values.push_back(5);
  311. values.push_back(8);
  312. const ParamGenerator<int> gen = ValuesIn(values);
  313. const int expected_values[] = {3, 5, 8};
  314. VerifyGenerator(gen, expected_values);
  315. }
  316. // Tests that ValuesIn() generates the expected sequence.
  317. TEST(ValuesInTest, ValuesInIteratorRange) {
  318. typedef ::std::vector<int> ContainerType;
  319. ContainerType values;
  320. values.push_back(3);
  321. values.push_back(5);
  322. values.push_back(8);
  323. const ParamGenerator<int> gen = ValuesIn(values.begin(), values.end());
  324. const int expected_values[] = {3, 5, 8};
  325. VerifyGenerator(gen, expected_values);
  326. }
  327. // Edge case. Tests that ValuesIn() provided with an iterator range specifying a
  328. // single value generates a single-element sequence.
  329. TEST(ValuesInTest, ValuesInSingleElementIteratorRange) {
  330. typedef ::std::vector<int> ContainerType;
  331. ContainerType values;
  332. values.push_back(42);
  333. const ParamGenerator<int> gen = ValuesIn(values.begin(), values.end());
  334. const int expected_values[] = {42};
  335. VerifyGenerator(gen, expected_values);
  336. }
  337. // Edge case. Tests that ValuesIn() provided with an empty iterator range
  338. // generates an empty sequence.
  339. TEST(ValuesInTest, ValuesInEmptyIteratorRange) {
  340. typedef ::std::vector<int> ContainerType;
  341. ContainerType values;
  342. const ParamGenerator<int> gen = ValuesIn(values.begin(), values.end());
  343. VerifyGeneratorIsEmpty(gen);
  344. }
  345. // Tests that the Values() generates the expected sequence.
  346. TEST(ValuesTest, ValuesWorks) {
  347. const ParamGenerator<int> gen = Values(3, 5, 8);
  348. const int expected_values[] = {3, 5, 8};
  349. VerifyGenerator(gen, expected_values);
  350. }
  351. // Tests that Values() generates the expected sequences from elements of
  352. // different types convertible to ParamGenerator's parameter type.
  353. TEST(ValuesTest, ValuesWorksForValuesOfCompatibleTypes) {
  354. const ParamGenerator<double> gen = Values(3, 5.0f, 8.0);
  355. const double expected_values[] = {3.0, 5.0, 8.0};
  356. VerifyGenerator(gen, expected_values);
  357. }
  358. TEST(ValuesTest, ValuesWorksForMaxLengthList) {
  359. const ParamGenerator<int> gen = Values(
  360. 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
  361. 110, 120, 130, 140, 150, 160, 170, 180, 190, 200,
  362. 210, 220, 230, 240, 250, 260, 270, 280, 290, 300,
  363. 310, 320, 330, 340, 350, 360, 370, 380, 390, 400,
  364. 410, 420, 430, 440, 450, 460, 470, 480, 490, 500);
  365. const int expected_values[] = {
  366. 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
  367. 110, 120, 130, 140, 150, 160, 170, 180, 190, 200,
  368. 210, 220, 230, 240, 250, 260, 270, 280, 290, 300,
  369. 310, 320, 330, 340, 350, 360, 370, 380, 390, 400,
  370. 410, 420, 430, 440, 450, 460, 470, 480, 490, 500};
  371. VerifyGenerator(gen, expected_values);
  372. }
  373. // Edge case test. Tests that single-parameter Values() generates the sequence
  374. // with the single value.
  375. TEST(ValuesTest, ValuesWithSingleParameter) {
  376. const ParamGenerator<int> gen = Values(42);
  377. const int expected_values[] = {42};
  378. VerifyGenerator(gen, expected_values);
  379. }
  380. // Tests that Bool() generates sequence (false, true).
  381. TEST(BoolTest, BoolWorks) {
  382. const ParamGenerator<bool> gen = Bool();
  383. const bool expected_values[] = {false, true};
  384. VerifyGenerator(gen, expected_values);
  385. }
  386. # if GTEST_HAS_COMBINE
  387. // Tests that Combine() with two parameters generates the expected sequence.
  388. TEST(CombineTest, CombineWithTwoParameters) {
  389. const char* foo = "foo";
  390. const char* bar = "bar";
  391. const ParamGenerator<tuple<const char*, int> > gen =
  392. Combine(Values(foo, bar), Values(3, 4));
  393. tuple<const char*, int> expected_values[] = {
  394. make_tuple(foo, 3), make_tuple(foo, 4),
  395. make_tuple(bar, 3), make_tuple(bar, 4)};
  396. VerifyGenerator(gen, expected_values);
  397. }
  398. // Tests that Combine() with three parameters generates the expected sequence.
  399. TEST(CombineTest, CombineWithThreeParameters) {
  400. const ParamGenerator<tuple<int, int, int> > gen = Combine(Values(0, 1),
  401. Values(3, 4),
  402. Values(5, 6));
  403. tuple<int, int, int> expected_values[] = {
  404. make_tuple(0, 3, 5), make_tuple(0, 3, 6),
  405. make_tuple(0, 4, 5), make_tuple(0, 4, 6),
  406. make_tuple(1, 3, 5), make_tuple(1, 3, 6),
  407. make_tuple(1, 4, 5), make_tuple(1, 4, 6)};
  408. VerifyGenerator(gen, expected_values);
  409. }
  410. // Tests that the Combine() with the first parameter generating a single value
  411. // sequence generates a sequence with the number of elements equal to the
  412. // number of elements in the sequence generated by the second parameter.
  413. TEST(CombineTest, CombineWithFirstParameterSingleValue) {
  414. const ParamGenerator<tuple<int, int> > gen = Combine(Values(42),
  415. Values(0, 1));
  416. tuple<int, int> expected_values[] = {make_tuple(42, 0), make_tuple(42, 1)};
  417. VerifyGenerator(gen, expected_values);
  418. }
  419. // Tests that the Combine() with the second parameter generating a single value
  420. // sequence generates a sequence with the number of elements equal to the
  421. // number of elements in the sequence generated by the first parameter.
  422. TEST(CombineTest, CombineWithSecondParameterSingleValue) {
  423. const ParamGenerator<tuple<int, int> > gen = Combine(Values(0, 1),
  424. Values(42));
  425. tuple<int, int> expected_values[] = {make_tuple(0, 42), make_tuple(1, 42)};
  426. VerifyGenerator(gen, expected_values);
  427. }
  428. // Tests that when the first parameter produces an empty sequence,
  429. // Combine() produces an empty sequence, too.
  430. TEST(CombineTest, CombineWithFirstParameterEmptyRange) {
  431. const ParamGenerator<tuple<int, int> > gen = Combine(Range(0, 0),
  432. Values(0, 1));
  433. VerifyGeneratorIsEmpty(gen);
  434. }
  435. // Tests that when the second parameter produces an empty sequence,
  436. // Combine() produces an empty sequence, too.
  437. TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
  438. const ParamGenerator<tuple<int, int> > gen = Combine(Values(0, 1),
  439. Range(1, 1));
  440. VerifyGeneratorIsEmpty(gen);
  441. }
  442. // Edge case. Tests that combine works with the maximum number
  443. // of parameters supported by Google Test (currently 10).
  444. TEST(CombineTest, CombineWithMaxNumberOfParameters) {
  445. const char* foo = "foo";
  446. const char* bar = "bar";
  447. const ParamGenerator<tuple<const char*, int, int, int, int, int, int, int,
  448. int, int> > gen = Combine(Values(foo, bar),
  449. Values(1), Values(2),
  450. Values(3), Values(4),
  451. Values(5), Values(6),
  452. Values(7), Values(8),
  453. Values(9));
  454. tuple<const char*, int, int, int, int, int, int, int, int, int>
  455. expected_values[] = {make_tuple(foo, 1, 2, 3, 4, 5, 6, 7, 8, 9),
  456. make_tuple(bar, 1, 2, 3, 4, 5, 6, 7, 8, 9)};
  457. VerifyGenerator(gen, expected_values);
  458. }
  459. #if GTEST_LANG_CXX11
  460. class NonDefaultConstructAssignString {
  461. public:
  462. NonDefaultConstructAssignString(const std::string& s) : str_(s) {}
  463. const std::string& str() const { return str_; }
  464. private:
  465. std::string str_;
  466. // Not default constructible
  467. NonDefaultConstructAssignString();
  468. // Not assignable
  469. void operator=(const NonDefaultConstructAssignString&);
  470. };
  471. TEST(CombineTest, NonDefaultConstructAssign) {
  472. const ParamGenerator<tuple<int, NonDefaultConstructAssignString> > gen =
  473. Combine(Values(0, 1), Values(NonDefaultConstructAssignString("A"),
  474. NonDefaultConstructAssignString("B")));
  475. ParamGenerator<tuple<int, NonDefaultConstructAssignString> >::iterator it =
  476. gen.begin();
  477. EXPECT_EQ(0, std::get<0>(*it));
  478. EXPECT_EQ("A", std::get<1>(*it).str());
  479. ++it;
  480. EXPECT_EQ(0, std::get<0>(*it));
  481. EXPECT_EQ("B", std::get<1>(*it).str());
  482. ++it;
  483. EXPECT_EQ(1, std::get<0>(*it));
  484. EXPECT_EQ("A", std::get<1>(*it).str());
  485. ++it;
  486. EXPECT_EQ(1, std::get<0>(*it));
  487. EXPECT_EQ("B", std::get<1>(*it).str());
  488. ++it;
  489. EXPECT_TRUE(it == gen.end());
  490. }
  491. #endif // GTEST_LANG_CXX11
  492. # endif // GTEST_HAS_COMBINE
  493. // Tests that an generator produces correct sequence after being
  494. // assigned from another generator.
  495. TEST(ParamGeneratorTest, AssignmentWorks) {
  496. ParamGenerator<int> gen = Values(1, 2);
  497. const ParamGenerator<int> gen2 = Values(3, 4);
  498. gen = gen2;
  499. const int expected_values[] = {3, 4};
  500. VerifyGenerator(gen, expected_values);
  501. }
  502. // This test verifies that the tests are expanded and run as specified:
  503. // one test per element from the sequence produced by the generator
  504. // specified in INSTANTIATE_TEST_CASE_P. It also verifies that the test's
  505. // fixture constructor, SetUp(), and TearDown() have run and have been
  506. // supplied with the correct parameters.
  507. // The use of environment object allows detection of the case where no test
  508. // case functionality is run at all. In this case TestCaseTearDown will not
  509. // be able to detect missing tests, naturally.
  510. template <int kExpectedCalls>
  511. class TestGenerationEnvironment : public ::testing::Environment {
  512. public:
  513. static TestGenerationEnvironment* Instance() {
  514. static TestGenerationEnvironment* instance = new TestGenerationEnvironment;
  515. return instance;
  516. }
  517. void FixtureConstructorExecuted() { fixture_constructor_count_++; }
  518. void SetUpExecuted() { set_up_count_++; }
  519. void TearDownExecuted() { tear_down_count_++; }
  520. void TestBodyExecuted() { test_body_count_++; }
  521. virtual void TearDown() {
  522. // If all MultipleTestGenerationTest tests have been de-selected
  523. // by the filter flag, the following checks make no sense.
  524. bool perform_check = false;
  525. for (int i = 0; i < kExpectedCalls; ++i) {
  526. Message msg;
  527. msg << "TestsExpandedAndRun/" << i;
  528. if (UnitTestOptions::FilterMatchesTest(
  529. "TestExpansionModule/MultipleTestGenerationTest",
  530. msg.GetString().c_str())) {
  531. perform_check = true;
  532. }
  533. }
  534. if (perform_check) {
  535. EXPECT_EQ(kExpectedCalls, fixture_constructor_count_)
  536. << "Fixture constructor of ParamTestGenerationTest test case "
  537. << "has not been run as expected.";
  538. EXPECT_EQ(kExpectedCalls, set_up_count_)
  539. << "Fixture SetUp method of ParamTestGenerationTest test case "
  540. << "has not been run as expected.";
  541. EXPECT_EQ(kExpectedCalls, tear_down_count_)
  542. << "Fixture TearDown method of ParamTestGenerationTest test case "
  543. << "has not been run as expected.";
  544. EXPECT_EQ(kExpectedCalls, test_body_count_)
  545. << "Test in ParamTestGenerationTest test case "
  546. << "has not been run as expected.";
  547. }
  548. }
  549. private:
  550. TestGenerationEnvironment() : fixture_constructor_count_(0), set_up_count_(0),
  551. tear_down_count_(0), test_body_count_(0) {}
  552. int fixture_constructor_count_;
  553. int set_up_count_;
  554. int tear_down_count_;
  555. int test_body_count_;
  556. GTEST_DISALLOW_COPY_AND_ASSIGN_(TestGenerationEnvironment);
  557. };
  558. const int test_generation_params[] = {36, 42, 72};
  559. class TestGenerationTest : public TestWithParam<int> {
  560. public:
  561. enum {
  562. PARAMETER_COUNT =
  563. sizeof(test_generation_params)/sizeof(test_generation_params[0])
  564. };
  565. typedef TestGenerationEnvironment<PARAMETER_COUNT> Environment;
  566. TestGenerationTest() {
  567. Environment::Instance()->FixtureConstructorExecuted();
  568. current_parameter_ = GetParam();
  569. }
  570. virtual void SetUp() {
  571. Environment::Instance()->SetUpExecuted();
  572. EXPECT_EQ(current_parameter_, GetParam());
  573. }
  574. virtual void TearDown() {
  575. Environment::Instance()->TearDownExecuted();
  576. EXPECT_EQ(current_parameter_, GetParam());
  577. }
  578. static void SetUpTestCase() {
  579. bool all_tests_in_test_case_selected = true;
  580. for (int i = 0; i < PARAMETER_COUNT; ++i) {
  581. Message test_name;
  582. test_name << "TestsExpandedAndRun/" << i;
  583. if ( !UnitTestOptions::FilterMatchesTest(
  584. "TestExpansionModule/MultipleTestGenerationTest",
  585. test_name.GetString())) {
  586. all_tests_in_test_case_selected = false;
  587. }
  588. }
  589. EXPECT_TRUE(all_tests_in_test_case_selected)
  590. << "When running the TestGenerationTest test case all of its tests\n"
  591. << "must be selected by the filter flag for the test case to pass.\n"
  592. << "If not all of them are enabled, we can't reliably conclude\n"
  593. << "that the correct number of tests have been generated.";
  594. collected_parameters_.clear();
  595. }
  596. static void TearDownTestCase() {
  597. vector<int> expected_values(test_generation_params,
  598. test_generation_params + PARAMETER_COUNT);
  599. // Test execution order is not guaranteed by Google Test,
  600. // so the order of values in collected_parameters_ can be
  601. // different and we have to sort to compare.
  602. sort(expected_values.begin(), expected_values.end());
  603. sort(collected_parameters_.begin(), collected_parameters_.end());
  604. EXPECT_TRUE(collected_parameters_ == expected_values);
  605. }
  606. protected:
  607. int current_parameter_;
  608. static vector<int> collected_parameters_;
  609. private:
  610. GTEST_DISALLOW_COPY_AND_ASSIGN_(TestGenerationTest);
  611. };
  612. vector<int> TestGenerationTest::collected_parameters_;
  613. TEST_P(TestGenerationTest, TestsExpandedAndRun) {
  614. Environment::Instance()->TestBodyExecuted();
  615. EXPECT_EQ(current_parameter_, GetParam());
  616. collected_parameters_.push_back(GetParam());
  617. }
  618. INSTANTIATE_TEST_CASE_P(TestExpansionModule, TestGenerationTest,
  619. ValuesIn(test_generation_params));
  620. // This test verifies that the element sequence (third parameter of
  621. // INSTANTIATE_TEST_CASE_P) is evaluated in InitGoogleTest() and neither at
  622. // the call site of INSTANTIATE_TEST_CASE_P nor in RUN_ALL_TESTS(). For
  623. // that, we declare param_value_ to be a static member of
  624. // GeneratorEvaluationTest and initialize it to 0. We set it to 1 in
  625. // main(), just before invocation of InitGoogleTest(). After calling
  626. // InitGoogleTest(), we set the value to 2. If the sequence is evaluated
  627. // before or after InitGoogleTest, INSTANTIATE_TEST_CASE_P will create a
  628. // test with parameter other than 1, and the test body will fail the
  629. // assertion.
  630. class GeneratorEvaluationTest : public TestWithParam<int> {
  631. public:
  632. static int param_value() { return param_value_; }
  633. static void set_param_value(int param_value) { param_value_ = param_value; }
  634. private:
  635. static int param_value_;
  636. };
  637. int GeneratorEvaluationTest::param_value_ = 0;
  638. TEST_P(GeneratorEvaluationTest, GeneratorsEvaluatedInMain) {
  639. EXPECT_EQ(1, GetParam());
  640. }
  641. INSTANTIATE_TEST_CASE_P(GenEvalModule,
  642. GeneratorEvaluationTest,
  643. Values(GeneratorEvaluationTest::param_value()));
  644. // Tests that generators defined in a different translation unit are
  645. // functional. Generator extern_gen is defined in gtest-param-test_test2.cc.
  646. extern ParamGenerator<int> extern_gen;
  647. class ExternalGeneratorTest : public TestWithParam<int> {};
  648. TEST_P(ExternalGeneratorTest, ExternalGenerator) {
  649. // Sequence produced by extern_gen contains only a single value
  650. // which we verify here.
  651. EXPECT_EQ(GetParam(), 33);
  652. }
  653. INSTANTIATE_TEST_CASE_P(ExternalGeneratorModule,
  654. ExternalGeneratorTest,
  655. extern_gen);
  656. // Tests that a parameterized test case can be defined in one translation
  657. // unit and instantiated in another. This test will be instantiated in
  658. // gtest-param-test_test2.cc. ExternalInstantiationTest fixture class is
  659. // defined in gtest-param-test_test.h.
  660. TEST_P(ExternalInstantiationTest, IsMultipleOf33) {
  661. EXPECT_EQ(0, GetParam() % 33);
  662. }
  663. // Tests that a parameterized test case can be instantiated with multiple
  664. // generators.
  665. class MultipleInstantiationTest : public TestWithParam<int> {};
  666. TEST_P(MultipleInstantiationTest, AllowsMultipleInstances) {
  667. }
  668. INSTANTIATE_TEST_CASE_P(Sequence1, MultipleInstantiationTest, Values(1, 2));
  669. INSTANTIATE_TEST_CASE_P(Sequence2, MultipleInstantiationTest, Range(3, 5));
  670. // Tests that a parameterized test case can be instantiated
  671. // in multiple translation units. This test will be instantiated
  672. // here and in gtest-param-test_test2.cc.
  673. // InstantiationInMultipleTranslationUnitsTest fixture class
  674. // is defined in gtest-param-test_test.h.
  675. TEST_P(InstantiationInMultipleTranslaionUnitsTest, IsMultipleOf42) {
  676. EXPECT_EQ(0, GetParam() % 42);
  677. }
  678. INSTANTIATE_TEST_CASE_P(Sequence1,
  679. InstantiationInMultipleTranslaionUnitsTest,
  680. Values(42, 42*2));
  681. // Tests that each iteration of parameterized test runs in a separate test
  682. // object.
  683. class SeparateInstanceTest : public TestWithParam<int> {
  684. public:
  685. SeparateInstanceTest() : count_(0) {}
  686. static void TearDownTestCase() {
  687. EXPECT_GE(global_count_, 2)
  688. << "If some (but not all) SeparateInstanceTest tests have been "
  689. << "filtered out this test will fail. Make sure that all "
  690. << "GeneratorEvaluationTest are selected or de-selected together "
  691. << "by the test filter.";
  692. }
  693. protected:
  694. int count_;
  695. static int global_count_;
  696. };
  697. int SeparateInstanceTest::global_count_ = 0;
  698. TEST_P(SeparateInstanceTest, TestsRunInSeparateInstances) {
  699. EXPECT_EQ(0, count_++);
  700. global_count_++;
  701. }
  702. INSTANTIATE_TEST_CASE_P(FourElemSequence, SeparateInstanceTest, Range(1, 4));
  703. // Tests that all instantiations of a test have named appropriately. Test
  704. // defined with TEST_P(TestCaseName, TestName) and instantiated with
  705. // INSTANTIATE_TEST_CASE_P(SequenceName, TestCaseName, generator) must be named
  706. // SequenceName/TestCaseName.TestName/i, where i is the 0-based index of the
  707. // sequence element used to instantiate the test.
  708. class NamingTest : public TestWithParam<int> {};
  709. TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) {
  710. const ::testing::TestInfo* const test_info =
  711. ::testing::UnitTest::GetInstance()->current_test_info();
  712. EXPECT_STREQ("ZeroToFiveSequence/NamingTest", test_info->test_case_name());
  713. Message index_stream;
  714. index_stream << "TestsReportCorrectNamesAndParameters/" << GetParam();
  715. EXPECT_STREQ(index_stream.GetString().c_str(), test_info->name());
  716. EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param());
  717. }
  718. INSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5));
  719. // Tests that macros in test names are expanded correctly.
  720. class MacroNamingTest : public TestWithParam<int> {};
  721. #define PREFIX_WITH_FOO(test_name) Foo##test_name
  722. #define PREFIX_WITH_MACRO(test_name) Macro##test_name
  723. TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) {
  724. const ::testing::TestInfo* const test_info =
  725. ::testing::UnitTest::GetInstance()->current_test_info();
  726. EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_case_name());
  727. EXPECT_STREQ("FooSomeTestName", test_info->name());
  728. }
  729. INSTANTIATE_TEST_CASE_P(FortyTwo, MacroNamingTest, Values(42));
  730. // Tests the same thing for non-parametrized tests.
  731. class MacroNamingTestNonParametrized : public ::testing::Test {};
  732. TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized),
  733. PREFIX_WITH_FOO(SomeTestName)) {
  734. const ::testing::TestInfo* const test_info =
  735. ::testing::UnitTest::GetInstance()->current_test_info();
  736. EXPECT_STREQ("MacroNamingTestNonParametrized", test_info->test_case_name());
  737. EXPECT_STREQ("FooSomeTestName", test_info->name());
  738. }
  739. // Tests that user supplied custom parameter names are working correctly.
  740. // Runs the test with a builtin helper method which uses PrintToString,
  741. // as well as a custom function and custom functor to ensure all possible
  742. // uses work correctly.
  743. class CustomFunctorNamingTest : public TestWithParam<std::string> {};
  744. TEST_P(CustomFunctorNamingTest, CustomTestNames) {}
  745. struct CustomParamNameFunctor {
  746. std::string operator()(const ::testing::TestParamInfo<std::string>& inf) {
  747. return inf.param;
  748. }
  749. };
  750. INSTANTIATE_TEST_CASE_P(CustomParamNameFunctor,
  751. CustomFunctorNamingTest,
  752. Values(std::string("FunctorName")),
  753. CustomParamNameFunctor());
  754. INSTANTIATE_TEST_CASE_P(AllAllowedCharacters,
  755. CustomFunctorNamingTest,
  756. Values("abcdefghijklmnopqrstuvwxyz",
  757. "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
  758. "01234567890_"),
  759. CustomParamNameFunctor());
  760. inline std::string CustomParamNameFunction(
  761. const ::testing::TestParamInfo<std::string>& inf) {
  762. return inf.param;
  763. }
  764. class CustomFunctionNamingTest : public TestWithParam<std::string> {};
  765. TEST_P(CustomFunctionNamingTest, CustomTestNames) {}
  766. INSTANTIATE_TEST_CASE_P(CustomParamNameFunction,
  767. CustomFunctionNamingTest,
  768. Values(std::string("FunctionName")),
  769. CustomParamNameFunction);
  770. #if GTEST_LANG_CXX11
  771. // Test custom naming with a lambda
  772. class CustomLambdaNamingTest : public TestWithParam<std::string> {};
  773. TEST_P(CustomLambdaNamingTest, CustomTestNames) {}
  774. INSTANTIATE_TEST_CASE_P(CustomParamNameLambda, CustomLambdaNamingTest,
  775. Values(std::string("LambdaName")),
  776. [](const ::testing::TestParamInfo<std::string>& inf) {
  777. return inf.param;
  778. });
  779. #endif // GTEST_LANG_CXX11
  780. TEST(CustomNamingTest, CheckNameRegistry) {
  781. ::testing::UnitTest* unit_test = ::testing::UnitTest::GetInstance();
  782. std::set<std::string> test_names;
  783. for (int case_num = 0;
  784. case_num < unit_test->total_test_case_count();
  785. ++case_num) {
  786. const ::testing::TestCase* test_case = unit_test->GetTestCase(case_num);
  787. for (int test_num = 0;
  788. test_num < test_case->total_test_count();
  789. ++test_num) {
  790. const ::testing::TestInfo* test_info = test_case->GetTestInfo(test_num);
  791. test_names.insert(std::string(test_info->name()));
  792. }
  793. }
  794. EXPECT_EQ(1u, test_names.count("CustomTestNames/FunctorName"));
  795. EXPECT_EQ(1u, test_names.count("CustomTestNames/FunctionName"));
  796. #if GTEST_LANG_CXX11
  797. EXPECT_EQ(1u, test_names.count("CustomTestNames/LambdaName"));
  798. #endif // GTEST_LANG_CXX11
  799. }
  800. // Test a numeric name to ensure PrintToStringParamName works correctly.
  801. class CustomIntegerNamingTest : public TestWithParam<int> {};
  802. TEST_P(CustomIntegerNamingTest, TestsReportCorrectNames) {
  803. const ::testing::TestInfo* const test_info =
  804. ::testing::UnitTest::GetInstance()->current_test_info();
  805. Message test_name_stream;
  806. test_name_stream << "TestsReportCorrectNames/" << GetParam();
  807. EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
  808. }
  809. INSTANTIATE_TEST_CASE_P(PrintToString,
  810. CustomIntegerNamingTest,
  811. Range(0, 5),
  812. ::testing::PrintToStringParamName());
  813. // Test a custom struct with PrintToString.
  814. struct CustomStruct {
  815. explicit CustomStruct(int value) : x(value) {}
  816. int x;
  817. };
  818. std::ostream& operator<<(std::ostream& stream, const CustomStruct& val) {
  819. stream << val.x;
  820. return stream;
  821. }
  822. class CustomStructNamingTest : public TestWithParam<CustomStruct> {};
  823. TEST_P(CustomStructNamingTest, TestsReportCorrectNames) {
  824. const ::testing::TestInfo* const test_info =
  825. ::testing::UnitTest::GetInstance()->current_test_info();
  826. Message test_name_stream;
  827. test_name_stream << "TestsReportCorrectNames/" << GetParam();
  828. EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
  829. }
  830. INSTANTIATE_TEST_CASE_P(PrintToString,
  831. CustomStructNamingTest,
  832. Values(CustomStruct(0), CustomStruct(1)),
  833. ::testing::PrintToStringParamName());
  834. // Test that using a stateful parameter naming function works as expected.
  835. struct StatefulNamingFunctor {
  836. StatefulNamingFunctor() : sum(0) {}
  837. std::string operator()(const ::testing::TestParamInfo<int>& info) {
  838. int value = info.param + sum;
  839. sum += info.param;
  840. return ::testing::PrintToString(value);
  841. }
  842. int sum;
  843. };
  844. class StatefulNamingTest : public ::testing::TestWithParam<int> {
  845. protected:
  846. StatefulNamingTest() : sum_(0) {}
  847. int sum_;
  848. };
  849. TEST_P(StatefulNamingTest, TestsReportCorrectNames) {
  850. const ::testing::TestInfo* const test_info =
  851. ::testing::UnitTest::GetInstance()->current_test_info();
  852. sum_ += GetParam();
  853. Message test_name_stream;
  854. test_name_stream << "TestsReportCorrectNames/" << sum_;
  855. EXPECT_STREQ(test_name_stream.GetString().c_str(), test_info->name());
  856. }
  857. INSTANTIATE_TEST_CASE_P(StatefulNamingFunctor,
  858. StatefulNamingTest,
  859. Range(0, 5),
  860. StatefulNamingFunctor());
  861. // Class that cannot be streamed into an ostream. It needs to be copyable
  862. // (and, in case of MSVC, also assignable) in order to be a test parameter
  863. // type. Its default copy constructor and assignment operator do exactly
  864. // what we need.
  865. class Unstreamable {
  866. public:
  867. explicit Unstreamable(int value) : value_(value) {}
  868. private:
  869. int value_;
  870. };
  871. class CommentTest : public TestWithParam<Unstreamable> {};
  872. TEST_P(CommentTest, TestsCorrectlyReportUnstreamableParams) {
  873. const ::testing::TestInfo* const test_info =
  874. ::testing::UnitTest::GetInstance()->current_test_info();
  875. EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param());
  876. }
  877. INSTANTIATE_TEST_CASE_P(InstantiationWithComments,
  878. CommentTest,
  879. Values(Unstreamable(1)));
  880. // Verify that we can create a hierarchy of test fixtures, where the base
  881. // class fixture is not parameterized and the derived class is. In this case
  882. // ParameterizedDerivedTest inherits from NonParameterizedBaseTest. We
  883. // perform simple tests on both.
  884. class NonParameterizedBaseTest : public ::testing::Test {
  885. public:
  886. NonParameterizedBaseTest() : n_(17) { }
  887. protected:
  888. int n_;
  889. };
  890. class ParameterizedDerivedTest : public NonParameterizedBaseTest,
  891. public ::testing::WithParamInterface<int> {
  892. protected:
  893. ParameterizedDerivedTest() : count_(0) { }
  894. int count_;
  895. static int global_count_;
  896. };
  897. int ParameterizedDerivedTest::global_count_ = 0;
  898. TEST_F(NonParameterizedBaseTest, FixtureIsInitialized) {
  899. EXPECT_EQ(17, n_);
  900. }
  901. TEST_P(ParameterizedDerivedTest, SeesSequence) {
  902. EXPECT_EQ(17, n_);
  903. EXPECT_EQ(0, count_++);
  904. EXPECT_EQ(GetParam(), global_count_++);
  905. }
  906. class ParameterizedDeathTest : public ::testing::TestWithParam<int> { };
  907. TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
  908. EXPECT_DEATH_IF_SUPPORTED(GetParam(),
  909. ".* value-parameterized test .*");
  910. }
  911. INSTANTIATE_TEST_CASE_P(RangeZeroToFive, ParameterizedDerivedTest, Range(0, 5));
  912. int main(int argc, char **argv) {
  913. // Used in TestGenerationTest test case.
  914. AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance());
  915. // Used in GeneratorEvaluationTest test case. Tests that the updated value
  916. // will be picked up for instantiating tests in GeneratorEvaluationTest.
  917. GeneratorEvaluationTest::set_param_value(1);
  918. ::testing::InitGoogleTest(&argc, argv);
  919. // Used in GeneratorEvaluationTest test case. Tests that value updated
  920. // here will NOT be used for instantiating tests in
  921. // GeneratorEvaluationTest.
  922. GeneratorEvaluationTest::set_param_value(2);
  923. return RUN_ALL_TESTS();
  924. }