Codebase list ignition-math2 / 9db921a
Imported Upstream version 2.5.0 Jose Luis Rivero 7 years ago
46 changed file(s) with 33375 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
00 repo: e97318167882c5edd21067dd86576efadebd68ed
1 node: 255fe947055f8de476430ca1ba5cb4e42b61ee0d
1 node: 6c0e329b4808923fba3aa0c91a448fafa2dff549
22 branch: ign-math2
3 latesttag: ignition-math2_2.4.0
4 latesttagdistance: 16
5 changessincelatesttag: 17
3 latesttag: ignition-math2_2.4.1
4 latesttagdistance: 24
5 changessincelatesttag: 48
66 string (TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
77
88 set (PROJECT_MAJOR_VERSION 2)
9 set (PROJECT_MINOR_VERSION 4)
10 set (PROJECT_PATCH_VERSION 1)
9 set (PROJECT_MINOR_VERSION 5)
10 set (PROJECT_PATCH_VERSION 0)
1111
1212 set (PROJECT_VERSION ${PROJECT_MAJOR_VERSION}.${PROJECT_MINOR_VERSION})
1313 set (PROJECT_VERSION_FULL
00 ## Ignition Math 2.x
1
2 ### Ignition Math 2.5
3
4 ### Ignition Math 2.5.0
5
6 1. Added PID class
7 * [Pull request 117](https://bitbucket.org/ignitionrobotics/ign-math/pull-request/117)
8
9 1. Added SphericalCoordinate class
10 * [Pull request 108](https://bitbucket.org/ignitionrobotics/ign-math/pull-request/108)
111
212 ### Ignition Math 2.4
313
1414 MassMatrix3.hh
1515 Matrix3.hh
1616 Matrix4.hh
17 PID.hh
1718 Plane.hh
1819 Pose3.hh
1920 Quaternion.hh
2021 Rand.hh
2122 RotationSpline.hh
2223 SignalStats.hh
24 SphericalCoordinates.hh
2325 Spline.hh
2426 Temperature.hh
2527 Triangle.hh
0 /*
1 * Copyright (C) 2016 Open Source Robotics Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 #ifndef IGNITION_MATH_PID_HH_
17 #define IGNITION_MATH_PID_HH_
18
19 #include <chrono>
20 #include <ignition/math/Helpers.hh>
21
22 namespace ignition
23 {
24 namespace math
25 {
26 /// \class PID PID.hh ignition/math/PID.hh
27 /// \brief Generic PID controller class.
28 /// Generic proportional-integral-derivative controller class that
29 /// keeps track of PID-error states and control inputs given
30 /// the state of a system and a user specified target state.
31 /// It includes a user-adjustable command offset term (feed-forward).
32 class IGNITION_VISIBLE PID
33 {
34 /// \brief Constructor, zeros out Pid values when created and
35 /// initialize Pid-gains and integral term limits:[iMax:iMin]-[I1:I2].
36 ///
37 /// Disable command clamping by setting _cmdMin to a value larger
38 /// than _cmdMax. Command clamping is disabled by default.
39 ///
40 /// Disable integral clamping by setting _iMin to a value larger
41 /// than _iMax. Integral clamping is disabled by default.
42 ///
43 /// \param[in] _p The proportional gain.
44 /// \param[in] _i The integral gain.
45 /// \param[in] _d The derivative gain.
46 /// \param[in] _imax The integral upper limit.
47 /// \param[in] _imin The integral lower limit.
48 /// \param[in] _cmdMax Output max value.
49 /// \param[in] _cmdMin Output min value.
50 /// \param[in] _cmdOffset Command offset (feed-forward).
51 public: PID(const double _p = 0.0,
52 const double _i = 0.0,
53 const double _d = 0.0,
54 const double _imax = -1.0,
55 const double _imin = 0.0,
56 const double _cmdMax = -1.0,
57 const double _cmdMin = 0.0,
58 const double _cmdOffset = 0.0);
59
60 /// \brief Destructor
61 public: ~PID() = default;
62
63 /// \brief Initialize PID-gains and integral term
64 /// limits:[iMax:iMin]-[I1:I2].
65 ///
66 /// Disable command clamping by setting _cmdMin to a value larger
67 /// than _cmdMax. Command clamping is disabled by default.
68 ///
69 /// Disable integral clamping by setting _iMin to a value larger
70 /// than _iMax. Integral clamping is disabled by default.
71 ///
72 /// \param[in] _p The proportional gain.
73 /// \param[in] _i The integral gain.
74 /// \param[in] _d The derivative gain.
75 /// \param[in] _imax The integral upper limit.
76 /// \param[in] _imin The integral lower limit.
77 /// \param[in] _cmdMax Output max value.
78 /// \param[in] _cmdMin Output min value.
79 /// \param[in] _cmdOffset Command offset (feed-forward).
80 public: void Init(const double _p = 0.0,
81 const double _i = 0.0,
82 const double _d = 0.0,
83 const double _imax = -1.0,
84 const double _imin = 0.0,
85 const double _cmdMax = -1.0,
86 const double _cmdMin = 0.0,
87 const double _cmdOffset = 0.0);
88
89 /// \brief Set the proportional Gain.
90 /// \param[in] _p proportional gain value
91 public: void SetPGain(const double _p);
92
93 /// \brief Set the integral Gain.
94 /// \param[in] _i integral gain value
95 public: void SetIGain(const double _i);
96
97 /// \brief Set the derivtive Gain.
98 /// \param[in] _d derivative gain value
99 public: void SetDGain(const double _d);
100
101 /// \brief Set the integral upper limit.
102 /// \param[in] _i integral upper limit value
103 public: void SetIMax(const double _i);
104
105 /// \brief Set the integral lower limit.
106 /// \param[in] _i integral lower limit value
107 public: void SetIMin(const double _i);
108
109 /// \brief Set the maximum value for the command.
110 /// \param[in] _c The maximum value
111 public: void SetCmdMax(const double _c);
112
113 /// \brief Set the minimum value for the command.
114 /// \param[in] _c The minimum value
115 public: void SetCmdMin(const double _c);
116
117 /// \brief Set the offset value for the command,
118 /// which is added to the result of the PID controller.
119 /// \param[in] _c The offset value
120 public: void SetCmdOffset(const double _c);
121
122 /// \brief Get the proportional Gain.
123 /// \return The proportional gain value
124 public: double PGain() const;
125
126 /// \brief Get the integral Gain.
127 /// \return The integral gain value
128 public: double IGain() const;
129
130 /// \brief Get the derivative Gain.
131 /// \return The derivative gain value
132 public: double DGain() const;
133
134 /// \brief Get the integral upper limit.
135 /// \return The integral upper limit value
136 public: double IMax() const;
137
138 /// \brief Get the integral lower limit.
139 /// \return The integral lower limit value
140 public: double IMin() const;
141
142 /// \brief Get the maximum value for the command.
143 /// \return The maximum value
144 public: double CmdMax() const;
145
146 /// \brief Get the maximum value for the command.
147 /// \return The maximum value
148 public: double CmdMin() const;
149
150 /// \brief Get the offset value for the command.
151 /// \return The offset value
152 public: double CmdOffset() const;
153
154 /// \brief Update the Pid loop with nonuniform time step size.
155 /// \param[in] _error Error since last call (p_state - p_target).
156 /// \param[in] _dt Change in time since last update call.
157 /// Normally, this is called at every time step,
158 /// The return value is an updated command to be passed
159 /// to the object being controlled.
160 /// \return the command value
161 public: double Update(const double _error,
162 const std::chrono::duration<double> &_dt);
163
164 /// \brief Set current target command for this PID controller.
165 /// \param[in] _cmd New command
166 public: void SetCmd(const double _cmd);
167
168 /// \brief Return current command for this PID controller.
169 /// \return the command value
170 public: double Cmd() const;
171
172 /// \brief Return PID error terms for the controller.
173 /// \param[in] _pe The proportional error.
174 /// \param[in] _ie The integral of gain times error.
175 /// \param[in] _de The derivative error.
176 public: void Errors(double &_pe, double &_ie, double &_de) const;
177
178 /// \brief Assignment operator
179 /// \param[in] _p a reference to a PID to assign values from
180 /// \return reference to this instance
181 public: PID &operator=(const PID &_p);
182
183 /// \brief Reset the errors and command.
184 public: void Reset();
185
186 /// \brief Error at a previous step.
187 private: double pErrLast = 0.0;
188
189 /// \brief Current error.
190 private: double pErr = 0.0;
191
192 /// \brief Integral of gain times error.
193 private: double iErr = 0.0;
194
195 /// \brief Derivative error.
196 private: double dErr = 0.0;
197
198 /// \brief Gain for proportional control.
199 private: double pGain;
200
201 /// \brief Gain for integral control.
202 private: double iGain = 0.0;
203
204 /// \brief Gain for derivative control.
205 private: double dGain = 0.0;
206
207 /// \brief Maximum clamping value for integral term.
208 private: double iMax = -1.0;
209
210 /// \brief Minim clamping value for integral term.
211 private: double iMin = 0.0;
212
213 /// \brief Command value.
214 private: double cmd = 0.0;
215
216 /// \brief Max command clamping value.
217 private: double cmdMax = -1.0;
218
219 /// \brief Min command clamping value.
220 private: double cmdMin = 0.0;
221
222 /// \brief Command offset.
223 private: double cmdOffset = 0.0;
224 };
225 }
226 }
227 #endif
0 /*
1 * Copyright (C) 2012-2016 Open Source Robotics Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 #ifndef IGNITION_MATH_SPHERICALCOORDINATES_HH_
17 #define IGNITION_MATH_SPHERICALCOORDINATES_HH_
18
19 #include <memory>
20 #include <string>
21
22 #include <ignition/math/Angle.hh>
23 #include <ignition/math/Vector3.hh>
24 #include <ignition/math/Helpers.hh>
25
26 namespace ignition
27 {
28 namespace math
29 {
30 class SphericalCoordinatesPrivate;
31
32 /// \class SphericalCoordinates SphericalCoordinates.hh commmon/common.hh
33 /// \brief Convert spherical coordinates for planetary surfaces.
34 class IGNITION_VISIBLE SphericalCoordinates
35 {
36 /// \enum SurfaceType
37 /// \brief Unique identifiers for planetary surface models.
38 public: enum SurfaceType
39 {
40 /// \brief Model of reference ellipsoid for earth, based on
41 /// WGS 84 standard. see wikipedia: World_Geodetic_System
42 EARTH_WGS84 = 1
43 };
44
45 /// \enum CoordinateType
46 /// \brief Unique identifiers for coordinate types.
47 public: enum CoordinateType
48 {
49 /// \brief Latitude, Longitude and Altitude by SurfaceType
50 SPHERICAL = 1,
51
52 /// \brief Earth centered, earth fixed Cartesian
53 ECEF = 2,
54
55 /// \brief Local tangent plane (East, North, Up)
56 GLOBAL = 3,
57
58 /// \brief Heading-adjusted tangent plane (X, Y, Z)
59 LOCAL = 4
60 };
61
62 /// \brief Constructor.
63 public: SphericalCoordinates();
64
65 /// \brief Constructor with surface type input.
66 /// \param[in] _type SurfaceType specification.
67 public: explicit SphericalCoordinates(const SurfaceType _type);
68
69 /// \brief Constructor with surface type, angle, and elevation inputs.
70 /// \param[in] _type SurfaceType specification.
71 /// \param[in] _latitude Reference latitude.
72 /// \param[in] _longitude Reference longitude.
73 /// \param[in] _elevation Reference elevation.
74 /// \param[in] _heading Heading offset.
75 public: SphericalCoordinates(const SurfaceType _type,
76 const ignition::math::Angle &_latitude,
77 const ignition::math::Angle &_longitude,
78 const double _elevation,
79 const ignition::math::Angle &_heading);
80
81 /// \brief Destructor.
82 public: ~SphericalCoordinates();
83
84 /// \brief Convert a Cartesian position vector to geodetic coordinates.
85 /// \param[in] _xyz Cartesian position vector in the world frame.
86 /// \return Cooordinates: geodetic latitude (deg), longitude (deg),
87 /// altitude above sea level (m).
88 public: ignition::math::Vector3d SphericalFromLocalPosition(
89 const ignition::math::Vector3d &_xyz) const;
90
91 /// \brief Convert a Cartesian velocity vector in the local frame
92 /// to a global Cartesian frame with components East, North, Up.
93 /// \param[in] _xyz Cartesian velocity vector in the world frame.
94 /// \return Rotated vector with components (x,y,z): (East, North, Up).
95 public: ignition::math::Vector3d GlobalFromLocalVelocity(
96 const ignition::math::Vector3d &_xyz) const;
97
98 /// \brief Convert a string to a SurfaceType.
99 /// Allowed values: ["EARTH_WGS84"].
100 /// \param[in] _str String to convert.
101 /// \return Conversion to SurfaceType.
102 public: static SurfaceType Convert(const std::string &_str);
103
104 /// \brief Get the distance between two points expressed in geographic
105 /// latitude and longitude. It assumes that both points are at sea level.
106 /// Example: _latA = 38.0016667 and _lonA = -123.0016667) represents
107 /// the point with latitude 38d 0'6.00"N and longitude 123d 0'6.00"W.
108 /// \param[in] _latA Latitude of point A.
109 /// \param[in] _longA Longitude of point A.
110 /// \param[in] _latB Latitude of point B.
111 /// \param[in] _longB Longitude of point B.
112 /// \return Distance in meters.
113 public: static double Distance(const ignition::math::Angle &_latA,
114 const ignition::math::Angle &_lonA,
115 const ignition::math::Angle &_latB,
116 const ignition::math::Angle &_lonB);
117
118 /// \brief Get SurfaceType currently in use.
119 /// \return Current SurfaceType value.
120 public: SurfaceType Surface() const;
121
122 /// \brief Get reference geodetic latitude.
123 /// \return Reference geodetic latitude.
124 public: ignition::math::Angle LatitudeReference() const;
125
126 /// \brief Get reference longitude.
127 /// \return Reference longitude.
128 public: ignition::math::Angle LongitudeReference() const;
129
130 /// \brief Get reference elevation in meters.
131 /// \return Reference elevation.
132 public: double ElevationReference() const;
133
134 /// \brief Get heading offset for the reference frame, expressed as
135 /// angle from East to x-axis, or equivalently
136 /// from North to y-axis.
137 /// \return Heading offset of reference frame.
138 public: ignition::math::Angle HeadingOffset() const;
139
140 /// \brief Set SurfaceType for planetary surface model.
141 /// \param[in] _type SurfaceType value.
142 public: void SetSurface(const SurfaceType &_type);
143
144 /// \brief Set reference geodetic latitude.
145 /// \param[in] _angle Reference geodetic latitude.
146 public: void SetLatitudeReference(const ignition::math::Angle &_angle);
147
148 /// \brief Set reference longitude.
149 /// \param[in] _angle Reference longitude.
150 public: void SetLongitudeReference(const ignition::math::Angle &_angle);
151
152 /// \brief Set reference elevation above sea level in meters.
153 /// \param[in] _elevation Reference elevation.
154 public: void SetElevationReference(const double _elevation);
155
156 /// \brief Set heading angle offset for the frame.
157 /// \param[in] _angle Heading offset for the frame.
158 public: void SetHeadingOffset(const ignition::math::Angle &_angle);
159
160 /// \brief Convert a geodetic position vector to Cartesian coordinates.
161 /// \param[in] _xyz Geodetic position in the planetary frame of reference
162 /// \return Cartesian position vector in the world frame
163 public: ignition::math::Vector3d LocalFromSphericalPosition(
164 const ignition::math::Vector3d &_xyz) const;
165
166 /// \brief Convert a Cartesian velocity vector with components East,
167 /// North, Up to a local cartesian frame vector XYZ.
168 /// \param[in] Vector with components (x,y,z): (East, North, Up).
169 /// \return Cartesian vector in the world frame.
170 public: ignition::math::Vector3d LocalFromGlobalVelocity(
171 const ignition::math::Vector3d &_xyz) const;
172
173 /// \brief Update coordinate transformation matrix with reference location
174 public: void UpdateTransformationMatrix();
175
176 /// \brief Convert between positions in SPHERICAL/ECEF/LOCAL/GLOBAL frame
177 /// \param[in] _pos Position vector in frame defined by parameter _in
178 /// \param[in] _in CoordinateType for input
179 /// \param[in] _out CoordinateType for output
180 /// \return Transformed coordinate using cached orgin
181 public: ignition::math::Vector3d
182 PositionTransform(const ignition::math::Vector3d &_pos,
183 const CoordinateType &_in, const CoordinateType &_out) const;
184
185 /// \brief Convert between velocity in SPHERICAL/ECEF/LOCAL/GLOBAL frame
186 /// \param[in] _vel Velocity vector in frame defined by parameter _in
187 /// \param[in] _in CoordinateType for input
188 /// \param[in] _out CoordinateType for output
189 /// \return Transformed velocity vector
190 public: ignition::math::Vector3d VelocityTransform(
191 const ignition::math::Vector3d &_vel,
192 const CoordinateType &_in, const CoordinateType &_out) const;
193
194 #ifdef _WIN32
195 // Disable warning C4251 which is triggered by
196 // std::unique_ptr
197 #pragma warning(push)
198 #pragma warning(disable: 4251)
199 #endif
200 /// \internal
201 /// \brief Pointer to the private data
202 private: std::unique_ptr<SphericalCoordinatesPrivate> dataPtr;
203 #ifdef _WIN32
204 #pragma warning(pop)
205 #endif
206 };
207 /// \}
208 }
209 }
210 #endif
77 Helpers.cc
88 IndexException.cc
99 Kmeans.cc
10 PID.cc
1011 Rand.cc
1112 RotationSpline.cc
1213 RotationSplinePrivate.cc
1314 SignalStats.cc
15 SphericalCoordinates.cc
1416 Spline.cc
1517 Temperature.cc
1618 Vector3Stats.cc
2931 MassMatrix3_TEST.cc
3032 Matrix3_TEST.cc
3133 Matrix4_TEST.cc
34 PID_TEST.cc
3235 Plane_TEST.cc
3336 Pose_TEST.cc
3437 Quaternion_TEST.cc
3538 Rand_TEST.cc
3639 RotationSpline_TEST.cc
3740 SignalStats_TEST.cc
41 SphericalCoordinates_TEST.cc
3842 Spline_TEST.cc
3943 Temperature_TEST.cc
4044 Triangle_TEST.cc
0 /*
1 * Copyright (C) 2016 Open Source Robotics Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 #include <chrono>
18 #include <cmath>
19 #include "ignition/math/Helpers.hh"
20 #include "ignition/math/PID.hh"
21
22 using namespace ignition;
23 using namespace math;
24
25 /////////////////////////////////////////////////
26 PID::PID(const double _p, const double _i, const double _d,
27 const double _imax, const double _imin, const double _cmdMax,
28 const double _cmdMin, const double _cmdOffset)
29 : pGain(_p), iGain(_i), dGain(_d), iMax(_imax), iMin(_imin),
30 cmdMax(_cmdMax), cmdMin(_cmdMin), cmdOffset(_cmdOffset)
31 {
32 this->Reset();
33 }
34
35 /////////////////////////////////////////////////
36 void PID::Init(const double _p, const double _i, const double _d,
37 const double _imax, const double _imin, const double _cmdMax,
38 const double _cmdMin, const double _cmdOffset)
39 {
40 this->pGain = _p;
41 this->iGain = _i;
42 this->dGain = _d;
43 this->iMax = _imax;
44 this->iMin = _imin;
45 this->cmdMax = _cmdMax;
46 this->cmdMin = _cmdMin;
47 this->cmdOffset = _cmdOffset;
48
49 this->Reset();
50 }
51
52 /////////////////////////////////////////////////
53 PID &PID::operator=(const PID &_p)
54 {
55 if (this == &_p)
56 return *this;
57
58 this->pGain = _p.pGain;
59 this->iGain = _p.iGain;
60 this->dGain = _p.dGain;
61 this->iMax = _p.iMax;
62 this->iMin = _p.iMin;
63 this->cmdMax = _p.cmdMax;
64 this->cmdMin = _p.cmdMin;
65 this->cmdOffset = _p.cmdOffset;
66 this->pErrLast = _p.pErrLast;
67 this->pErr = _p.pErr;
68 this->iErr = _p.iErr;
69 this->dErr = _p.dErr;
70 this->cmd = _p.cmd;
71
72 return *this;
73 }
74
75 /////////////////////////////////////////////////
76 void PID::SetPGain(const double _p)
77 {
78 this->pGain = _p;
79 }
80
81 /////////////////////////////////////////////////
82 void PID::SetIGain(const double _i)
83 {
84 this->iGain = _i;
85 }
86
87 /////////////////////////////////////////////////
88 void PID::SetDGain(const double _d)
89 {
90 this->dGain = _d;
91 }
92
93 /////////////////////////////////////////////////
94 void PID::SetIMax(const double _i)
95 {
96 this->iMax = _i;
97 }
98
99 /////////////////////////////////////////////////
100 void PID::SetIMin(const double _i)
101 {
102 this->iMin = _i;
103 }
104
105 /////////////////////////////////////////////////
106 void PID::SetCmdMax(const double _c)
107 {
108 this->cmdMax = _c;
109 }
110
111 /////////////////////////////////////////////////
112 void PID::SetCmdMin(const double _c)
113 {
114 this->cmdMin = _c;
115 }
116
117 /////////////////////////////////////////////////
118 void PID::SetCmdOffset(const double _c)
119 {
120 this->cmdOffset = _c;
121 }
122
123 /////////////////////////////////////////////////
124 void PID::Reset()
125 {
126 this->pErrLast = 0.0;
127 this->pErr = 0.0;
128 this->iErr = 0.0;
129 this->dErr = 0.0;
130 this->cmd = 0.0;
131 }
132
133 /////////////////////////////////////////////////
134 double PID::Update(const double _error,
135 const std::chrono::duration<double> &_dt)
136 {
137 if (_dt == std::chrono::duration<double>(0) ||
138 ignition::math::isnan(_error) || std::isinf(_error))
139 {
140 return 0.0;
141 }
142
143 double pTerm, dTerm;
144 this->pErr = _error;
145
146 // Calculate proportional contribution to command
147 pTerm = this->pGain * this->pErr;
148
149 // Calculate the integral error
150 this->iErr = this->iErr + this->iGain * _dt.count() * this->pErr;
151
152 // Check the integral limits
153 // If enabled, this will limit iErr so that the limit is meaningful
154 // in the output
155 if (this->iMax >= this->iMin)
156 this->iErr = clamp(this->iErr, this->iMin, this->iMax);
157
158 // Calculate the derivative error
159 if (_dt != std::chrono::duration<double>(0))
160 {
161 this->dErr = (this->pErr - this->pErrLast) / _dt.count();
162 this->pErrLast = this->pErr;
163 }
164
165 // Calculate derivative contribution to command
166 dTerm = this->dGain * this->dErr;
167 this->cmd = this->cmdOffset -pTerm - this->iErr - dTerm;
168
169 // Check the command limits
170 if (this->cmdMax >= this->cmdMin)
171 this->cmd = clamp(this->cmd, this->cmdMin, this->cmdMax);
172
173 return this->cmd;
174 }
175
176 /////////////////////////////////////////////////
177 void PID::SetCmd(const double _cmd)
178 {
179 this->cmd = _cmd;
180 }
181
182 /////////////////////////////////////////////////
183 double PID::Cmd() const
184 {
185 return this->cmd;
186 }
187
188 /////////////////////////////////////////////////
189 void PID::Errors(double &_pe, double &_ie, double &_de) const
190 {
191 _pe = this->pErr;
192 _ie = this->iErr;
193 _de = this->dErr;
194 }
195
196 /////////////////////////////////////////////////
197 double PID::PGain() const
198 {
199 return this->pGain;
200 }
201
202 /////////////////////////////////////////////////
203 double PID::IGain() const
204 {
205 return this->iGain;
206 }
207
208 /////////////////////////////////////////////////
209 double PID::DGain() const
210 {
211 return this->dGain;
212 }
213
214 /////////////////////////////////////////////////
215 double PID::IMax() const
216 {
217 return this->iMax;
218 }
219
220 /////////////////////////////////////////////////
221 double PID::IMin() const
222 {
223 return this->iMin;
224 }
225
226 /////////////////////////////////////////////////
227 double PID::CmdMax() const
228 {
229 return this->cmdMax;
230 }
231
232 /////////////////////////////////////////////////
233 double PID::CmdMin() const
234 {
235 return this->cmdMin;
236 }
237
238 /////////////////////////////////////////////////
239 double PID::CmdOffset() const
240 {
241 return this->cmdOffset;
242 }
0 /*
1 * Copyright (C) 2016 Open Source Robotics Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 #include <gtest/gtest.h>
18
19 #include "ignition/math/PID.hh"
20 #include "ignition/math/Helpers.hh"
21
22 using namespace ignition;
23
24 /////////////////////////////////////////////////
25 TEST(PidTest, ConstructorDefault)
26 {
27 const math::PID pid;
28 EXPECT_DOUBLE_EQ(0.0, pid.PGain());
29 EXPECT_DOUBLE_EQ(0.0, pid.IGain());
30 EXPECT_DOUBLE_EQ(0.0, pid.DGain());
31 EXPECT_DOUBLE_EQ(-1.0, pid.IMax());
32 EXPECT_DOUBLE_EQ(0.0, pid.IMin());
33 EXPECT_DOUBLE_EQ(-1.0, pid.CmdMax());
34 EXPECT_DOUBLE_EQ(0.0, pid.CmdMin());
35 EXPECT_DOUBLE_EQ(0.0, pid.CmdOffset());
36 EXPECT_DOUBLE_EQ(0.0, pid.Cmd());
37
38 double pe, ie, de;
39 pid.Errors(pe, ie, de);
40 EXPECT_DOUBLE_EQ(pe, 0.0);
41 EXPECT_DOUBLE_EQ(ie, 0.0);
42 EXPECT_DOUBLE_EQ(de, 0.0);
43 }
44
45 /////////////////////////////////////////////////
46 TEST(PidTest, CoverageExtra)
47 {
48 // getting full destructor coverage
49 math::PID *p = new math::PID;
50 EXPECT_TRUE(p != NULL);
51 delete p;
52 }
53
54 /////////////////////////////////////////////////
55 TEST(PidTest, SetValues)
56 {
57 const math::PID pid2(1.0, 2.1, -4.5, 10.5, 1.4, 45, -35, 1.3);
58 EXPECT_DOUBLE_EQ(1.0, pid2.PGain());
59 EXPECT_DOUBLE_EQ(2.1, pid2.IGain());
60 EXPECT_DOUBLE_EQ(-4.5, pid2.DGain());
61 EXPECT_DOUBLE_EQ(10.5, pid2.IMax());
62 EXPECT_DOUBLE_EQ(1.4, pid2.IMin());
63 EXPECT_DOUBLE_EQ(45, pid2.CmdMax());
64 EXPECT_DOUBLE_EQ(-35, pid2.CmdMin());
65 EXPECT_DOUBLE_EQ(1.3, pid2.CmdOffset());
66 EXPECT_DOUBLE_EQ(0.0, pid2.Cmd());
67
68 // Test Set*() functions
69 {
70 const double cmd = 10.4;
71 math::PID pid;
72 pid.SetPGain(pid2.PGain());
73 pid.SetIGain(pid2.IGain());
74 pid.SetDGain(pid2.DGain());
75 pid.SetIMax(pid2.IMax());
76 pid.SetIMin(pid2.IMin());
77 pid.SetCmdMax(pid2.CmdMax());
78 pid.SetCmdMin(pid2.CmdMin());
79 pid.SetCmdOffset(pid2.CmdOffset());
80 pid.SetCmd(cmd);
81
82 EXPECT_DOUBLE_EQ(pid.PGain(), pid2.PGain());
83 EXPECT_DOUBLE_EQ(pid.IGain(), pid2.IGain());
84 EXPECT_DOUBLE_EQ(pid.DGain(), pid2.DGain());
85 EXPECT_DOUBLE_EQ(pid.IMax(), pid2.IMax());
86 EXPECT_DOUBLE_EQ(pid.IMin(), pid2.IMin());
87 EXPECT_DOUBLE_EQ(pid.CmdMax(), pid2.CmdMax());
88 EXPECT_DOUBLE_EQ(pid.CmdMin(), pid2.CmdMin());
89 EXPECT_DOUBLE_EQ(pid.CmdOffset(), pid2.CmdOffset());
90 EXPECT_DOUBLE_EQ(pid.Cmd(), cmd);
91 }
92
93 // Assignment operator
94 {
95 math::PID pid;
96 pid = pid2;
97 EXPECT_DOUBLE_EQ(pid.PGain(), pid2.PGain());
98 EXPECT_DOUBLE_EQ(pid.IGain(), pid2.IGain());
99 EXPECT_DOUBLE_EQ(pid.DGain(), pid2.DGain());
100 EXPECT_DOUBLE_EQ(pid.IMax(), pid2.IMax());
101 EXPECT_DOUBLE_EQ(pid.IMin(), pid2.IMin());
102 EXPECT_DOUBLE_EQ(pid.CmdMax(), pid2.CmdMax());
103 EXPECT_DOUBLE_EQ(pid.CmdMin(), pid2.CmdMin());
104 EXPECT_DOUBLE_EQ(pid.CmdOffset(), pid2.CmdOffset());
105 EXPECT_DOUBLE_EQ(pid.Cmd(), pid2.Cmd());
106 }
107 }
108
109 /////////////////////////////////////////////////
110 TEST(PidTest, EqualOperatorCornerCase)
111 {
112 math::PID pid(1.0, 2.1, -4.5, 10.5, 1.4, 45, -35, 1.23);
113 EXPECT_DOUBLE_EQ(pid.PGain(), 1.0);
114 EXPECT_DOUBLE_EQ(pid.IGain(), 2.1);
115 EXPECT_DOUBLE_EQ(pid.DGain(), -4.5);
116 EXPECT_DOUBLE_EQ(pid.IMax(), 10.5);
117 EXPECT_DOUBLE_EQ(pid.IMin(), 1.4);
118 EXPECT_DOUBLE_EQ(pid.CmdMax(), 45.0);
119 EXPECT_DOUBLE_EQ(pid.CmdMin(), -35.0);
120 EXPECT_DOUBLE_EQ(pid.CmdOffset(), 1.23);
121 EXPECT_DOUBLE_EQ(pid.Cmd(), 0.0);
122
123 pid = pid;
124
125 EXPECT_DOUBLE_EQ(pid.PGain(), 1.0);
126 EXPECT_DOUBLE_EQ(pid.IGain(), 2.1);
127 EXPECT_DOUBLE_EQ(pid.DGain(), -4.5);
128 EXPECT_DOUBLE_EQ(pid.IMax(), 10.5);
129 EXPECT_DOUBLE_EQ(pid.IMin(), 1.4);
130 EXPECT_DOUBLE_EQ(pid.CmdMax(), 45.0);
131 EXPECT_DOUBLE_EQ(pid.CmdMin(), -35.0);
132 EXPECT_DOUBLE_EQ(pid.CmdOffset(), 1.23);
133 EXPECT_DOUBLE_EQ(pid.Cmd(), 0.0);
134 }
135
136 /////////////////////////////////////////////////
137 TEST(PidTest, Update)
138 {
139 math::PID pid;
140 pid.Init(1.0, 0.1, 0.5, 10, 0, 20, -20);
141
142 double result = pid.Update(5.0, std::chrono::duration<double>(0.0));
143 EXPECT_DOUBLE_EQ(result, 0.0);
144
145 result = pid.Update(5.0, std::chrono::duration<double>(10.0));
146 EXPECT_DOUBLE_EQ(result, -10.25);
147
148 double pe, ie, de;
149 pid.Errors(pe, ie, de);
150 EXPECT_DOUBLE_EQ(pe, 5);
151 EXPECT_DOUBLE_EQ(ie, 5);
152 EXPECT_DOUBLE_EQ(de, 0.5);
153
154 // Test max integral term
155 pid.SetIMax(0.2);
156 pid.SetIGain(10.0);
157 result = pid.Update(5.0, std::chrono::duration<double>(10.0));
158 EXPECT_DOUBLE_EQ(result, -5.2);
159 pid.Errors(pe, ie, de);
160 EXPECT_DOUBLE_EQ(pe, 5);
161 EXPECT_DOUBLE_EQ(ie, 0.2);
162 EXPECT_DOUBLE_EQ(de, 0.0);
163
164 // Test min integral term
165 pid.SetIMax(20);
166 pid.SetIMin(1.4);
167 pid.SetIGain(0.01);
168 result = pid.Update(5.0, std::chrono::duration<double>(10.0));
169 EXPECT_DOUBLE_EQ(result, -6.4);
170 pid.Errors(pe, ie, de);
171 EXPECT_DOUBLE_EQ(pe, 5);
172 EXPECT_DOUBLE_EQ(ie, 1.4);
173 EXPECT_DOUBLE_EQ(de, 0.0);
174 }
175
176 /////////////////////////////////////////////////
177 /// \brief Helper function for testing PID::Update
178 /// \param[in] _pid PID object.
179 /// \param[in] _result Expected PID output.
180 /// \param[in] _error Error input to Update.
181 /// \param[in] _dt Time interval.
182 /// \param[in] _pErr Expected proportional error.
183 /// \param[in] _iErr Expected integral error.
184 /// \param[in] _dErr Expected derivative error.
185 void UpdateTest(math::PID &_pid, const double _result, const double _error,
186 const std::chrono::duration<double> &_dt,
187 const double _pErr, const double _iErr, const double _dErr)
188 {
189 EXPECT_DOUBLE_EQ(_result, _pid.Update(_error, _dt));
190 double pErr, iErr, dErr;
191 _pid.Errors(pErr, iErr, dErr);
192 EXPECT_DOUBLE_EQ(pErr, _pErr);
193 EXPECT_DOUBLE_EQ(iErr, _iErr);
194 EXPECT_DOUBLE_EQ(dErr, _dErr);
195 }
196
197 /////////////////////////////////////////////////
198 TEST(PidTest, ZeroGains)
199 {
200 // controller with zero gains, no command limits
201 math::PID pid;
202
203 std::cerr << "zero inputs, expect zero outputs" << std::endl;
204 // repeat once to test derivative and integral error
205 UpdateTest(pid, 0, 0, std::chrono::duration<double>(0), 0, 0, 0);
206 UpdateTest(pid, 0, 0, std::chrono::duration<double>(0), 0, 0, 0);
207
208 std::cerr << "dt = 0, no change since previous state" << std::endl;
209 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
210 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
211 UpdateTest(pid, 0, -1, std::chrono::duration<double>(0), 0, 0, 0);
212 UpdateTest(pid, 0, -1, std::chrono::duration<double>(0), 0, 0, 0);
213 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
214 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
215
216 std::cerr << "dt > 0, but gains still zero" << std::endl;
217 UpdateTest(pid, 0, 1, std::chrono::duration<double>(1), 1, 0, 1);
218 UpdateTest(pid, 0, 1, std::chrono::duration<double>(1), 1, 0, 0);
219 UpdateTest(pid, 0, -1, std::chrono::duration<double>(1), -1, 0, -2);
220 UpdateTest(pid, 0, -1, std::chrono::duration<double>(1), -1, 0, 0);
221 UpdateTest(pid, 0, 1, std::chrono::duration<double>(1), 1, 0, 2);
222 UpdateTest(pid, 0, 1, std::chrono::duration<double>(1), 1, 0, 0);
223
224 std::cerr << "dt = 0, no change since previous state" << std::endl;
225 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 1, 0, 0);
226 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 1, 0, 0);
227 UpdateTest(pid, 0, -1, std::chrono::duration<double>(0), 1, 0, 0);
228 UpdateTest(pid, 0, -1, std::chrono::duration<double>(0), 1, 0, 0);
229 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 1, 0, 0);
230 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 1, 0, 0);
231
232 std::cerr << "dt < 0, but gains still zero" << std::endl;
233 UpdateTest(pid, 0, 1, std::chrono::duration<double>(-1), 1, 0, 0);
234 UpdateTest(pid, 0, 1, std::chrono::duration<double>(-1), 1, 0, 0);
235 UpdateTest(pid, 0, -1, std::chrono::duration<double>(-1), -1, 0, 2);
236 UpdateTest(pid, 0, -1, std::chrono::duration<double>(-1), -1, 0, 0);
237 UpdateTest(pid, 0, 1, std::chrono::duration<double>(-1), 1, 0, -2);
238 UpdateTest(pid, 0, 1, std::chrono::duration<double>(-1), 1, 0, 0);
239
240 std::cerr << "Reset" << std::endl;
241 pid.Reset();
242 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
243
244 std::cerr << "unclamp Cmd values" << std::endl;
245 // CmdMax defaults to -1.0
246 // setting CmdMin to -10.0, means output should now be -1.0
247 // when time is non-zero
248 pid.SetCmdMin(-10.0);
249 EXPECT_DOUBLE_EQ(-10.0, pid.CmdMin());
250 // command hasn't been updated yet
251 EXPECT_DOUBLE_EQ(0.0, pid.Cmd());
252
253 std::cerr << "dt = 0, still report cmd = 0" << std::endl;
254 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
255 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
256 UpdateTest(pid, 0, -1, std::chrono::duration<double>(0), 0, 0, 0);
257 UpdateTest(pid, 0, -1, std::chrono::duration<double>(0), 0, 0, 0);
258 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
259 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
260
261 std::cerr << "dt > 0, report clamped value" << std::endl;
262 UpdateTest(pid, -1, 1, std::chrono::duration<double>(1), 1, 0, 1);
263 UpdateTest(pid, -1, 1, std::chrono::duration<double>(1), 1, 0, 0);
264 UpdateTest(pid, -1, -1, std::chrono::duration<double>(1), -1, 0, -2);
265 UpdateTest(pid, -1, -1, std::chrono::duration<double>(1), -1, 0, 0);
266 UpdateTest(pid, -1, 1, std::chrono::duration<double>(1), 1, 0, 2);
267 UpdateTest(pid, -1, 1, std::chrono::duration<double>(1), 1, 0, 0);
268
269 std::cerr << "Reset" << std::endl;
270 pid.Reset();
271 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
272
273 std::cerr << "unclamp iErr values" << std::endl;
274 // IMax defaults to -1.0
275 // setting IMin to -10.0, means output should now be -1.0
276 // when time is non-zero
277 pid.SetIMin(-10.0);
278 EXPECT_DOUBLE_EQ(-10.0, pid.IMin());
279 // iErr hasn't been updated yet
280 {
281 double pErr, iErr, dErr;
282 pid.Errors(pErr, iErr, dErr);
283 EXPECT_DOUBLE_EQ(0.0, iErr);
284 }
285
286 std::cerr << "dt = 0, still report iErr = 0" << std::endl;
287 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
288 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
289 UpdateTest(pid, 0, -1, std::chrono::duration<double>(0), 0, 0, 0);
290 UpdateTest(pid, 0, -1, std::chrono::duration<double>(0), 0, 0, 0);
291 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
292 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
293
294 std::cerr << "dt > 0, report clamped value" << std::endl;
295 UpdateTest(pid, -1, 1, std::chrono::duration<double>(1), 1, -1, 1);
296 UpdateTest(pid, -1, 1, std::chrono::duration<double>(1), 1, -1, 0);
297 UpdateTest(pid, -1, -1, std::chrono::duration<double>(1), -1, -1, -2);
298 UpdateTest(pid, -1, -1, std::chrono::duration<double>(1), -1, -1, 0);
299 UpdateTest(pid, -1, 1, std::chrono::duration<double>(1), 1, -1, 2);
300 UpdateTest(pid, -1, 1, std::chrono::duration<double>(1), 1, -1, 0);
301
302 std::cerr << "Reset" << std::endl;
303 pid.Reset();
304 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
305
306 std::cerr << "set Cmd Offset" << std::endl;
307 pid.SetCmdOffset(-20.0);
308 EXPECT_DOUBLE_EQ(-20.0, pid.CmdOffset());
309 // Cmd hasn't been updated yet
310 EXPECT_DOUBLE_EQ(0.0, pid.Cmd());
311
312 std::cerr << "dt = 0, still return 0" << std::endl;
313 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
314 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
315 UpdateTest(pid, 0, -1, std::chrono::duration<double>(0), 0, 0, 0);
316 UpdateTest(pid, 0, -1, std::chrono::duration<double>(0), 0, 0, 0);
317 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
318 UpdateTest(pid, 0, 1, std::chrono::duration<double>(0), 0, 0, 0);
319
320 std::cerr << "dt > 0, report negative min value" << std::endl;
321 UpdateTest(pid, -10, 1, std::chrono::duration<double>(1), 1, -1, 1);
322 UpdateTest(pid, -10, 1, std::chrono::duration<double>(1), 1, -1, 0);
323 UpdateTest(pid, -10, -1, std::chrono::duration<double>(1), -1, -1, -2);
324 UpdateTest(pid, -10, -1, std::chrono::duration<double>(1), -1, -1, 0);
325 UpdateTest(pid, -10, 1, std::chrono::duration<double>(1), 1, -1, 2);
326 UpdateTest(pid, -10, 1, std::chrono::duration<double>(1), 1, -1, 0);
327 }
328
329 /////////////////////////////////////////////////
330 TEST(PidTest, Pcontrol)
331 {
332 math::PID pid(1);
333 std::chrono::duration<double> dt(1);
334 const int N = 5;
335 for (int i = 0; i < N; ++i)
336 {
337 double d = static_cast<double>(i);
338 EXPECT_DOUBLE_EQ(-d, pid.Update(d, std::chrono::duration<double>(1)));
339 }
340
341 pid.SetPGain(2);
342 for (int i = 0; i < N; ++i)
343 {
344 double d = static_cast<double>(i);
345 EXPECT_DOUBLE_EQ(-2*d, pid.Update(d, std::chrono::duration<double>(1)));
346 }
347 }
348
349 /////////////////////////////////////////////////
350 TEST(PidTest, Icontrol)
351 {
352 math::PID pid(0, 1);
353 std::chrono::duration<double> dt(1);
354 const int N = 5;
355 for (int i = 0; i < N; ++i)
356 {
357 double d = static_cast<double>(i+1);
358 EXPECT_DOUBLE_EQ(-d, pid.Update(1, std::chrono::duration<double>(1)));
359 }
360
361 pid.SetIGain(2);
362 double I0;
363 {
364 double pErr, iErr, dErr;
365 pid.Errors(pErr, iErr, dErr);
366 EXPECT_DOUBLE_EQ(N, iErr);
367 I0 = iErr;
368 }
369
370 // confirm that changing gain doesn't cause jumps in integral control
371 EXPECT_DOUBLE_EQ(-I0, pid.Update(0, std::chrono::duration<double>(1)));
372 EXPECT_DOUBLE_EQ(-I0, pid.Update(0, std::chrono::duration<double>(1)));
373
374 for (int i = 0; i < N; ++i)
375 {
376 double d = static_cast<double>(i+1);
377 EXPECT_DOUBLE_EQ(-I0-2*d, pid.Update(1, std::chrono::duration<double>(1)));
378 }
379 }
380
381 /////////////////////////////////////////////////
382 TEST(PidTest, Dcontrol)
383 {
384 math::PID pid(0, 0, 1);
385 std::chrono::duration<double> dt(1);
386 EXPECT_DOUBLE_EQ(1, pid.Update(-1, std::chrono::duration<double>(1)));
387 const int N = 5;
388 for (int i = 0; i < N; ++i)
389 {
390 double d = static_cast<double>(i);
391 EXPECT_DOUBLE_EQ(-1, pid.Update(d, std::chrono::duration<double>(1)));
392 }
393
394 pid.SetDGain(2);
395 EXPECT_DOUBLE_EQ(10, pid.Update(-1, std::chrono::duration<double>(1)));
396 for (int i = 0; i < N; ++i)
397 {
398 double d = static_cast<double>(i);
399 EXPECT_DOUBLE_EQ(-2, pid.Update(d, std::chrono::duration<double>(1)));
400 }
401 }
0 /*
1 * Copyright (C) 2012-2016 Open Source Robotics Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 #include <string>
17
18 #include "ignition/math/Matrix3.hh"
19 #include "ignition/math/SphericalCoordinates.hh"
20
21 using namespace ignition;
22 using namespace math;
23
24 // Parameters for EARTH_WGS84 model
25 // wikipedia: World_Geodetic_System#A_new_World_Geodetic_System:_WGS_84
26
27 // a: Equatorial radius. Semi-major axis of the WGS84 spheroid (meters).
28 const double g_EarthWGS84AxisEquatorial = 6378137.0;
29
30 // b: Polar radius. Semi-minor axis of the wgs84 spheroid (meters).
31 const double g_EarthWGS84AxisPolar = 6356752.314245;
32
33 // if: WGS84 inverse flattening parameter (no units)
34 const double g_EarthWGS84Flattening = 1.0/298.257223563;
35
36 // Radius of the Earth (meters).
37 const double g_EarthRadius = 6371000.0;
38
39 // Private data for the SphericalCoordinates class.
40 class ignition::math::SphericalCoordinatesPrivate
41 {
42 /// \brief Type of surface being used.
43 public: SphericalCoordinates::SurfaceType surfaceType;
44
45 /// \brief Latitude of reference point.
46 public: ignition::math::Angle latitudeReference;
47
48 /// \brief Longitude of reference point.
49 public: ignition::math::Angle longitudeReference;
50
51 /// \brief Elevation of reference point relative to sea level in meters.
52 public: double elevationReference;
53
54 /// \brief Heading offset, expressed as angle from East to
55 /// gazebo x-axis, or equivalently from North to gazebo y-axis.
56 public: ignition::math::Angle headingOffset;
57
58 /// \brief Semi-major axis ellipse parameter
59 public: double ellA;
60
61 /// \brief Semi-minor axis ellipse parameter
62 public: double ellB;
63
64 /// \brief Flattening ellipse parameter
65 public: double ellF;
66
67 /// \brief First eccentricity ellipse parameter
68 public: double ellE;
69
70 /// \brief Second eccentricity ellipse parameter
71 public: double ellP;
72
73 /// \brief Rotation matrix that moves ECEF to GLOBAL
74 public: ignition::math::Matrix3d rotECEFToGlobal;
75
76 /// \brief Rotation matrix that moves GLOBAL to ECEF
77 public: ignition::math::Matrix3d rotGlobalToECEF;
78
79 /// \brief Cache the ECEF position of the the origin
80 public: ignition::math::Vector3d origin;
81
82 /// \brief Cache cosine head transform
83 public: double cosHea;
84
85 /// \brief Cache sine head transform
86 public: double sinHea;
87 };
88
89 //////////////////////////////////////////////////
90 SphericalCoordinates::SurfaceType SphericalCoordinates::Convert(
91 const std::string &_str)
92 {
93 if ("EARTH_WGS84" == _str)
94 return EARTH_WGS84;
95
96 std::cerr << "SurfaceType string not recognized, "
97 << "EARTH_WGS84 returned by default" << std::endl;
98 return EARTH_WGS84;
99 }
100
101 //////////////////////////////////////////////////
102 SphericalCoordinates::SphericalCoordinates()
103 : dataPtr(new SphericalCoordinatesPrivate)
104 {
105 this->SetSurface(EARTH_WGS84);
106 this->SetElevationReference(0.0);
107 }
108
109 //////////////////////////////////////////////////
110 SphericalCoordinates::SphericalCoordinates(const SurfaceType _type)
111 : dataPtr(new SphericalCoordinatesPrivate)
112 {
113 this->SetSurface(_type);
114 this->SetElevationReference(0.0);
115 }
116
117 //////////////////////////////////////////////////
118 SphericalCoordinates::SphericalCoordinates(const SurfaceType _type,
119 const ignition::math::Angle &_latitude,
120 const ignition::math::Angle &_longitude,
121 const double _elevation,
122 const ignition::math::Angle &_heading)
123 : dataPtr(new SphericalCoordinatesPrivate)
124 {
125 // Set the reference and calculate ellipse parameters
126 this->SetSurface(_type);
127
128 // Set the coordinate transform parameters
129 this->dataPtr->latitudeReference = _latitude;
130 this->dataPtr->longitudeReference = _longitude;
131 this->dataPtr->elevationReference = _elevation;
132 this->dataPtr->headingOffset = _heading;
133
134 // Generate transformation matrix
135 this->UpdateTransformationMatrix();
136 }
137
138 //////////////////////////////////////////////////
139 SphericalCoordinates::~SphericalCoordinates()
140 {
141 }
142
143 //////////////////////////////////////////////////
144 SphericalCoordinates::SurfaceType SphericalCoordinates::Surface() const
145 {
146 return this->dataPtr->surfaceType;
147 }
148
149 //////////////////////////////////////////////////
150 ignition::math::Angle SphericalCoordinates::LatitudeReference() const
151 {
152 return this->dataPtr->latitudeReference;
153 }
154
155 //////////////////////////////////////////////////
156 ignition::math::Angle SphericalCoordinates::LongitudeReference() const
157 {
158 return this->dataPtr->longitudeReference;
159 }
160
161 //////////////////////////////////////////////////
162 double SphericalCoordinates::ElevationReference() const
163 {
164 return this->dataPtr->elevationReference;
165 }
166
167 //////////////////////////////////////////////////
168 ignition::math::Angle SphericalCoordinates::HeadingOffset() const
169 {
170 return this->dataPtr->headingOffset;
171 }
172
173 //////////////////////////////////////////////////
174 void SphericalCoordinates::SetSurface(const SurfaceType &_type)
175 {
176 this->dataPtr->surfaceType = _type;
177
178 switch (this->dataPtr->surfaceType)
179 {
180 case EARTH_WGS84:
181 {
182 // Set the semi-major axis
183 this->dataPtr->ellA = g_EarthWGS84AxisEquatorial;
184
185 // Set the semi-minor axis
186 this->dataPtr->ellB = g_EarthWGS84AxisPolar;
187
188 // Set the flattening parameter
189 this->dataPtr->ellF = g_EarthWGS84Flattening;
190
191 // Set the first eccentricity ellipse parameter
192 // https://en.wikipedia.org/wiki/Eccentricity_(mathematics)#Ellipses
193 this->dataPtr->ellE = sqrt(1.0 -
194 std::pow(this->dataPtr->ellB, 2) / std::pow(this->dataPtr->ellA, 2));
195
196 // Set the second eccentricity ellipse parameter
197 // https://en.wikipedia.org/wiki/Eccentricity_(mathematics)#Ellipses
198 this->dataPtr->ellP = sqrt(
199 std::pow(this->dataPtr->ellA, 2) / std::pow(this->dataPtr->ellB, 2) -
200 1.0);
201
202 break;
203 }
204 default:
205 {
206 std::cerr << "Unknown surface type["
207 << this->dataPtr->surfaceType << "]\n";
208 break;
209 }
210 }
211 }
212
213 //////////////////////////////////////////////////
214 void SphericalCoordinates::SetLatitudeReference(
215 const ignition::math::Angle &_angle)
216 {
217 this->dataPtr->latitudeReference = _angle;
218 this->UpdateTransformationMatrix();
219 }
220
221 //////////////////////////////////////////////////
222 void SphericalCoordinates::SetLongitudeReference(
223 const ignition::math::Angle &_angle)
224 {
225 this->dataPtr->longitudeReference = _angle;
226 this->UpdateTransformationMatrix();
227 }
228
229 //////////////////////////////////////////////////
230 void SphericalCoordinates::SetElevationReference(const double _elevation)
231 {
232 this->dataPtr->elevationReference = _elevation;
233 this->UpdateTransformationMatrix();
234 }
235
236 //////////////////////////////////////////////////
237 void SphericalCoordinates::SetHeadingOffset(const ignition::math::Angle &_angle)
238 {
239 this->dataPtr->headingOffset.Radian(_angle.Radian());
240 this->UpdateTransformationMatrix();
241 }
242
243 //////////////////////////////////////////////////
244 ignition::math::Vector3d SphericalCoordinates::SphericalFromLocalPosition(
245 const ignition::math::Vector3d &_xyz) const
246 {
247 ignition::math::Vector3d result =
248 this->PositionTransform(_xyz, LOCAL, SPHERICAL);
249 result.X(IGN_RTOD(result.X()));
250 result.Y(IGN_RTOD(result.Y()));
251 return result;
252 }
253
254 //////////////////////////////////////////////////
255 ignition::math::Vector3d SphericalCoordinates::LocalFromSphericalPosition(
256 const ignition::math::Vector3d &_xyz) const
257 {
258 ignition::math::Vector3d result = _xyz;
259 result.X(IGN_DTOR(result.X()));
260 result.Y(IGN_DTOR(result.Y()));
261 return this->PositionTransform(result, SPHERICAL, LOCAL);
262 }
263
264 //////////////////////////////////////////////////
265 ignition::math::Vector3d SphericalCoordinates::GlobalFromLocalVelocity(
266 const ignition::math::Vector3d &_xyz) const
267 {
268 return this->VelocityTransform(_xyz, LOCAL, GLOBAL);
269 }
270
271 //////////////////////////////////////////////////
272 ignition::math::Vector3d SphericalCoordinates::LocalFromGlobalVelocity(
273 const ignition::math::Vector3d &_xyz) const
274 {
275 return this->VelocityTransform(_xyz, GLOBAL, LOCAL);
276 }
277
278 //////////////////////////////////////////////////
279 /// Based on Haversine formula (http://en.wikipedia.org/wiki/Haversine_formula).
280 double SphericalCoordinates::Distance(const ignition::math::Angle &_latA,
281 const ignition::math::Angle &_lonA,
282 const ignition::math::Angle &_latB,
283 const ignition::math::Angle &_lonB)
284 {
285 ignition::math::Angle dLat = _latB - _latA;
286 ignition::math::Angle dLon = _lonB - _lonA;
287
288 double a = sin(dLat.Radian() / 2) * sin(dLat.Radian() / 2) +
289 sin(dLon.Radian() / 2) * sin(dLon.Radian() / 2) *
290 cos(_latA.Radian()) * cos(_latB.Radian());
291
292 double c = 2 * atan2(sqrt(a), sqrt(1 - a));
293 double d = g_EarthRadius * c;
294 return d;
295 }
296
297 //////////////////////////////////////////////////
298 void SphericalCoordinates::UpdateTransformationMatrix()
299 {
300 // Cache trig results
301 double cosLat = cos(this->dataPtr->latitudeReference.Radian());
302 double sinLat = sin(this->dataPtr->latitudeReference.Radian());
303 double cosLon = cos(this->dataPtr->longitudeReference.Radian());
304 double sinLon = sin(this->dataPtr->longitudeReference.Radian());
305
306 // Create a rotation matrix that moves ECEF to GLOBAL
307 // http://www.navipedia.net/index.php/
308 // Transformations_between_ECEF_and_ENU_coordinates
309 this->dataPtr->rotECEFToGlobal = ignition::math::Matrix3d(
310 -sinLon, cosLon, 0.0,
311 -cosLon * sinLat, -sinLon * sinLat, cosLat,
312 cosLon * cosLat, sinLon * cosLat, sinLat);
313
314 // Create a rotation matrix that moves GLOBAL to ECEF
315 // http://www.navipedia.net/index.php/
316 // Transformations_between_ECEF_and_ENU_coordinates
317 this->dataPtr->rotGlobalToECEF = ignition::math::Matrix3d(
318 -sinLon, -cosLon * sinLat, cosLon * cosLat,
319 cosLon, -sinLon * sinLat, sinLon * cosLat,
320 0, cosLat, sinLat);
321
322 // Cache heading transforms -- note that we have to negate the heading in
323 // order to preserve backward compatibility. ie. Gazebo has traditionally
324 // expressed positive angle as a CLOCKWISE rotation that takes the GLOBAL
325 // frame to the LOCAL frame. However, right hand coordinate systems require
326 // this to be expressed as an ANTI-CLOCKWISE rotation. So, we negate it.
327 this->dataPtr->cosHea = cos(-this->dataPtr->headingOffset.Radian());
328 this->dataPtr->sinHea = sin(-this->dataPtr->headingOffset.Radian());
329
330 // Cache the ECEF coordinate of the origin
331 this->dataPtr->origin = ignition::math::Vector3d(
332 this->dataPtr->latitudeReference.Radian(),
333 this->dataPtr->longitudeReference.Radian(),
334 this->dataPtr->elevationReference);
335 this->dataPtr->origin =
336 this->PositionTransform(this->dataPtr->origin, SPHERICAL, ECEF);
337 }
338
339 /////////////////////////////////////////////////
340 ignition::math::Vector3d SphericalCoordinates::PositionTransform(
341 const ignition::math::Vector3d &_pos,
342 const CoordinateType &_in, const CoordinateType &_out) const
343 {
344 ignition::math::Vector3d tmp = _pos;
345
346 // Cache trig results
347 double cosLat = cos(_pos.X());
348 double sinLat = sin(_pos.X());
349 double cosLon = cos(_pos.Y());
350 double sinLon = sin(_pos.Y());
351
352 // Radius of planet curvature (meters)
353 double curvature = 1.0 -
354 this->dataPtr->ellE * this->dataPtr->ellE * sinLat * sinLat;
355 curvature = this->dataPtr->ellA / sqrt(curvature);
356
357 // Convert whatever arrives to a more flexible ECEF coordinate
358 switch (_in)
359 {
360 // East, North, Up (ENU), note no break at end of case
361 case LOCAL:
362 {
363 tmp.X(-_pos.X() * this->dataPtr->cosHea + _pos.Y() *
364 this->dataPtr->sinHea);
365 tmp.Y(-_pos.X() * this->dataPtr->sinHea - _pos.Y() *
366 this->dataPtr->cosHea);
367 }
368
369 case GLOBAL:
370 {
371 tmp = this->dataPtr->origin + this->dataPtr->rotGlobalToECEF * tmp;
372 break;
373 }
374
375 case SPHERICAL:
376 {
377 tmp.X((_pos.Z() + curvature) * cosLat * cosLon);
378 tmp.Y((_pos.Z() + curvature) * cosLat * sinLon);
379 tmp.Z(((this->dataPtr->ellB * this->dataPtr->ellB)/
380 (this->dataPtr->ellA * this->dataPtr->ellA) *
381 curvature + _pos.Z()) * sinLat);
382 break;
383 }
384
385 // Do nothing
386 case ECEF:
387 break;
388 default:
389 {
390 std::cerr << "Invalid coordinate type[" << _in << "]\n";
391 return _pos;
392 }
393 }
394
395 // Convert ECEF to the requested output coordinate system
396 switch (_out)
397 {
398 case SPHERICAL:
399 {
400 // Convert from ECEF to SPHERICAL
401 double p = sqrt(tmp.X() * tmp.X() + tmp.Y() * tmp.Y());
402 double theta = atan((tmp.Z() * this->dataPtr->ellA) /
403 (p * this->dataPtr->ellB));
404
405 // Calculate latitude and longitude
406 double lat = atan(
407 (tmp.Z() + std::pow(this->dataPtr->ellP, 2) * this->dataPtr->ellB *
408 std::pow(sin(theta), 3)) /
409 (p - std::pow(this->dataPtr->ellE, 2) *
410 this->dataPtr->ellA * std::pow(cos(theta), 3)));
411
412 double lon = atan2(tmp.Y(), tmp.X());
413
414 // Recalculate radius of planet curvature at the current latitude.
415 double nCurvature = 1.0 - std::pow(this->dataPtr->ellE, 2) *
416 std::pow(sin(lat), 2);
417 nCurvature = this->dataPtr->ellA / sqrt(nCurvature);
418
419 tmp.X(lat);
420 tmp.Y(lon);
421
422 // Now calculate Z
423 tmp.Z(p/cos(lat) - nCurvature);
424 break;
425 }
426
427 // Convert from ECEF TO GLOBAL
428 case GLOBAL:
429 tmp = this->dataPtr->rotECEFToGlobal * (tmp - this->dataPtr->origin);
430 break;
431
432 // Convert from ECEF TO LOCAL
433 case LOCAL:
434 tmp = this->dataPtr->rotECEFToGlobal * (tmp - this->dataPtr->origin);
435
436 tmp = ignition::math::Vector3d(
437 tmp.X() * this->dataPtr->cosHea - tmp.Y() * this->dataPtr->sinHea,
438 tmp.X() * this->dataPtr->sinHea + tmp.Y() * this->dataPtr->cosHea,
439 tmp.Z());
440 break;
441
442 // Return ECEF (do nothing)
443 case ECEF:
444 break;
445
446 default:
447 std::cerr << "Unknown coordinate type[" << _out << "]\n";
448 return _pos;
449 }
450
451 return tmp;
452 }
453
454 //////////////////////////////////////////////////
455 ignition::math::Vector3d SphericalCoordinates::VelocityTransform(
456 const ignition::math::Vector3d &_vel,
457 const CoordinateType &_in, const CoordinateType &_out) const
458 {
459 // Sanity check -- velocity should not be expressed in spherical coordinates
460 if (_in == SPHERICAL || _out == SPHERICAL)
461 {
462 return _vel;
463 }
464
465 // Intermediate data type
466 ignition::math::Vector3d tmp = _vel;
467
468 // First, convert to an ECEF vector
469 switch (_in)
470 {
471 // ENU (note no break at end of case)
472 case LOCAL:
473 tmp.X(-_vel.X() * this->dataPtr->cosHea + _vel.Y() *
474 this->dataPtr->sinHea);
475 tmp.Y(-_vel.X() * this->dataPtr->sinHea - _vel.Y() *
476 this->dataPtr->cosHea);
477 // spherical
478 case GLOBAL:
479 tmp = this->dataPtr->rotGlobalToECEF * tmp;
480 break;
481 // Do nothing
482 case ECEF:
483 tmp = _vel;
484 break;
485 default:
486 std::cerr << "Unknown coordinate type[" << _in << "]\n";
487 return _vel;
488 }
489
490 // Then, convert to the request coordinate type
491 switch (_out)
492 {
493 // ECEF, do nothing
494 case ECEF:
495 break;
496
497 // Convert from ECEF to global
498 case GLOBAL:
499 tmp = this->dataPtr->rotECEFToGlobal * tmp;
500 break;
501
502 // Convert from ECEF to local
503 case LOCAL:
504 tmp = this->dataPtr->rotECEFToGlobal * tmp;
505 tmp = ignition::math::Vector3d(
506 tmp.X() * this->dataPtr->cosHea - tmp.Y() * this->dataPtr->sinHea,
507 tmp.X() * this->dataPtr->sinHea + tmp.Y() * this->dataPtr->cosHea,
508 tmp.Z());
509 break;
510
511 default:
512 std::cerr << "Unknown coordinate type[" << _out << "]\n";
513 return _vel;
514 }
515
516 return tmp;
517 }
0 /*
1 * Copyright (C) 2012-2016 Open Source Robotics Foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16 #include <gtest/gtest.h>
17
18 #include "ignition/math/SphericalCoordinates.hh"
19
20 using namespace ignition;
21
22 //////////////////////////////////////////////////
23 // Test different constructors, default parameters
24 TEST(SphericalCoordinatesTest, Constructor)
25 {
26 // Default surface type
27 math::SphericalCoordinates::SurfaceType st =
28 math::SphericalCoordinates::EARTH_WGS84;
29
30 // No arguments, default parameters
31 {
32 math::SphericalCoordinates sc;
33 EXPECT_EQ(sc.Surface(), st);
34 EXPECT_EQ(sc.LatitudeReference(), ignition::math::Angle());
35 EXPECT_EQ(sc.LongitudeReference(), ignition::math::Angle());
36 EXPECT_EQ(sc.HeadingOffset(), ignition::math::Angle());
37 EXPECT_NEAR(sc.ElevationReference(), 0.0, 1e-6);
38 }
39
40 // SurfaceType argument, default parameters
41 {
42 math::SphericalCoordinates sc(st);
43 EXPECT_EQ(sc.Surface(), st);
44 EXPECT_EQ(sc.LatitudeReference(), ignition::math::Angle());
45 EXPECT_EQ(sc.LongitudeReference(), ignition::math::Angle());
46 EXPECT_EQ(sc.HeadingOffset(), ignition::math::Angle());
47 EXPECT_NEAR(sc.ElevationReference(), 0.0, 1e-6);
48 }
49
50 // All arguments
51 {
52 ignition::math::Angle lat(0.3), lon(-1.2), heading(0.5);
53 double elev = 354.1;
54 math::SphericalCoordinates sc(st, lat, lon, elev, heading);
55 EXPECT_EQ(sc.Surface(), st);
56 EXPECT_EQ(sc.LatitudeReference(), lat);
57 EXPECT_EQ(sc.LongitudeReference(), lon);
58 EXPECT_EQ(sc.HeadingOffset(), heading);
59 EXPECT_NEAR(sc.ElevationReference(), elev, 1e-6);
60 }
61 }
62
63 //////////////////////////////////////////////////
64 // SurfaceType Convert function
65 TEST(SphericalCoordinatesTest, Convert)
66 {
67 // Default surface type
68 math::SphericalCoordinates::SurfaceType st =
69 math::SphericalCoordinates::EARTH_WGS84;
70
71 EXPECT_EQ(math::SphericalCoordinates::Convert("EARTH_WGS84"), st);
72
73 EXPECT_EQ(math::SphericalCoordinates::EARTH_WGS84,
74 math::SphericalCoordinates::Convert("OTHER-COORD"));
75 }
76
77 //////////////////////////////////////////////////
78 // Test Set functions
79 TEST(SphericalCoordinatesTest, SetFunctions)
80 {
81 // Default surface type
82 math::SphericalCoordinates::SurfaceType st =
83 math::SphericalCoordinates::EARTH_WGS84;
84
85 // Default parameters
86 math::SphericalCoordinates sc;
87 EXPECT_EQ(sc.Surface(), st);
88 EXPECT_EQ(sc.LatitudeReference(), ignition::math::Angle());
89 EXPECT_EQ(sc.LongitudeReference(), ignition::math::Angle());
90 EXPECT_EQ(sc.HeadingOffset(), ignition::math::Angle());
91 EXPECT_NEAR(sc.ElevationReference(), 0.0, 1e-6);
92
93 {
94 ignition::math::Angle lat(0.3), lon(-1.2), heading(0.5);
95 double elev = 354.1;
96 sc.SetSurface(st);
97 sc.SetLatitudeReference(lat);
98 sc.SetLongitudeReference(lon);
99 sc.SetHeadingOffset(heading);
100 sc.SetElevationReference(elev);
101
102 EXPECT_EQ(sc.Surface(), st);
103 EXPECT_EQ(sc.LatitudeReference(), lat);
104 EXPECT_EQ(sc.LongitudeReference(), lon);
105 EXPECT_EQ(sc.HeadingOffset(), heading);
106 EXPECT_NEAR(sc.ElevationReference(), elev, 1e-6);
107 }
108 }
109
110 //////////////////////////////////////////////////
111 // Test coordinate transformations
112 TEST(SphericalCoordinatesTest, CoordinateTransforms)
113 {
114 // Default surface type
115 math::SphericalCoordinates::SurfaceType st =
116 math::SphericalCoordinates::EARTH_WGS84;
117
118 {
119 // Parameters
120 ignition::math::Angle lat(0.3), lon(-1.2),
121 heading(ignition::math::Angle::HalfPi);
122 double elev = 354.1;
123 math::SphericalCoordinates sc(st, lat, lon, elev, heading);
124
125 // Check GlobalFromLocal with heading offset of 90 degrees
126 {
127 // local frame
128 ignition::math::Vector3d xyz;
129 // east, north, up
130 ignition::math::Vector3d enu;
131
132 xyz.Set(1, 0, 0);
133 enu = sc.GlobalFromLocalVelocity(xyz);
134 EXPECT_NEAR(enu.Y(), xyz.X(), 1e-6);
135 EXPECT_NEAR(enu.X(), -xyz.Y(), 1e-6);
136 EXPECT_EQ(xyz, sc.LocalFromGlobalVelocity(enu));
137
138 xyz.Set(0, 1, 0);
139 enu = sc.GlobalFromLocalVelocity(xyz);
140 EXPECT_NEAR(enu.Y(), xyz.X(), 1e-6);
141 EXPECT_NEAR(enu.X(), -xyz.Y(), 1e-6);
142 EXPECT_EQ(xyz, sc.LocalFromGlobalVelocity(enu));
143
144 xyz.Set(1, -1, 0);
145 enu = sc.GlobalFromLocalVelocity(xyz);
146 EXPECT_NEAR(enu.Y(), xyz.X(), 1e-6);
147 EXPECT_NEAR(enu.X(), -xyz.Y(), 1e-6);
148 EXPECT_EQ(xyz, sc.LocalFromGlobalVelocity(enu));
149
150 xyz.Set(2243.52334, 556.35, 435.6553);
151 enu = sc.GlobalFromLocalVelocity(xyz);
152 EXPECT_NEAR(enu.Y(), xyz.X(), 1e-6);
153 EXPECT_NEAR(enu.X(), -xyz.Y(), 1e-6);
154 EXPECT_EQ(xyz, sc.LocalFromGlobalVelocity(enu));
155 }
156
157 // Check SphericalFromLocal
158 {
159 // local frame
160 ignition::math::Vector3d xyz;
161 // spherical coordinates
162 ignition::math::Vector3d sph;
163
164 // No offset
165 xyz.Set(0, 0, 0);
166 sph = sc.SphericalFromLocalPosition(xyz);
167 // latitude
168 EXPECT_NEAR(sph.X(), lat.Degree(), 1e-6);
169 // longitude
170 EXPECT_NEAR(sph.Y(), lon.Degree(), 1e-6);
171 // elevation
172 EXPECT_NEAR(sph.Z(), elev, 1e-6);
173
174 // 200 km offset in x (pi/2 heading offset means North). We use
175 // SphericalFromLocal, which means that xyz is a linear movement on
176 // a plane (not along the curvature of Earth). This will result in
177 // a large height offset.
178 xyz.Set(2e5, 0, 0);
179 sph = sc.SphericalFromLocalPosition(xyz);
180 // increase in latitude about 1.8 degrees
181 EXPECT_NEAR(sph.X(), lat.Degree() + 1.8, 0.008);
182 // no change in longitude
183 EXPECT_NEAR(sph.Z(), 3507.024791, 1e-6);
184
185 ignition::math::Vector3d xyz2 = sc.LocalFromSphericalPosition(sph);
186 EXPECT_EQ(xyz, xyz2);
187 }
188
189 // Check position projection
190 {
191 // WGS84 coordinate obtained from online mapping software
192 // > gdaltransform -s_srs WGS84 -t_srs EPSG:4978
193 // > latitude longitude altitude
194 // > X Y Z
195 ignition::math::Vector3d tmp;
196 ignition::math::Vector3d osrf_s(37.3877349, -122.0651166, 32.0);
197 ignition::math::Vector3d osrf_e(
198 -2693701.91434394, -4299942.14687992, 3851691.0393571);
199 ignition::math::Vector3d goog_s(37.4216719, -122.0821853, 30.0);
200 ignition::math::Vector3d goog_e(
201 -2693766.71906146, -4297199.59926038, 3854681.81878812);
202
203 // Local tangent plane coordinates (ENU = GLOBAL) coordinates of
204 // Google when OSRF is taken as the origin:
205 // > proj +ellps=WGS84 +proj=tmerc
206 // +lat_0=37.3877349 +lon_0=-122.0651166 +k=1 +x_0=0 +y_0=0
207 // > -122.0821853 37.4216719 (LON,LAT)
208 // > -1510.88 3766.64 (EAST,NORTH)
209 ignition::math::Vector3d vec(-1510.88, 3766.64, -3.29);
210
211 // Convert degrees to radians
212 osrf_s.X() *= 0.0174532925;
213 osrf_s.Y() *= 0.0174532925;
214
215 // Set the ORIGIN to be the Open Source Robotics Foundation
216 math::SphericalCoordinates sc2(st, ignition::math::Angle(osrf_s.X()),
217 ignition::math::Angle(osrf_s.Y()), osrf_s.Z(),
218 ignition::math::Angle::Zero);
219
220 // Check that SPHERICAL -> ECEF works
221 tmp = sc2.PositionTransform(osrf_s,
222 math::SphericalCoordinates::SPHERICAL,
223 math::SphericalCoordinates::ECEF);
224
225 EXPECT_NEAR(tmp.X(), osrf_e.X(), 8e-2);
226 EXPECT_NEAR(tmp.Y(), osrf_e.Y(), 8e-2);
227 EXPECT_NEAR(tmp.Z(), osrf_e.Z(), 1e-2);
228
229 // Check that ECEF -> SPHERICAL works
230 tmp = sc2.PositionTransform(tmp,
231 math::SphericalCoordinates::ECEF,
232 math::SphericalCoordinates::SPHERICAL);
233
234 EXPECT_NEAR(tmp.X(), osrf_s.X(), 1e-2);
235 EXPECT_NEAR(tmp.Y(), osrf_s.Y(), 1e-2);
236 EXPECT_NEAR(tmp.Z(), osrf_s.Z(), 1e-2);
237
238 // Check that SPHERICAL -> LOCAL works
239 tmp = sc2.LocalFromSphericalPosition(goog_s);
240 EXPECT_NEAR(tmp.X(), vec.X(), 8e-2);
241 EXPECT_NEAR(tmp.Y(), vec.Y(), 8e-2);
242 EXPECT_NEAR(tmp.Z(), vec.Z(), 1e-2);
243
244 // Check that SPHERICAL -> LOCAL -> SPHERICAL works
245 tmp = sc2.SphericalFromLocalPosition(tmp);
246 EXPECT_NEAR(tmp.X(), goog_s.X(), 8e-2);
247 EXPECT_NEAR(tmp.Y(), goog_s.Y(), 8e-2);
248 EXPECT_NEAR(tmp.Z(), goog_s.Z(), 1e-2);
249 }
250 }
251 }
252
253 //////////////////////////////////////////////////
254 // Test distance
255 TEST(SphericalCoordinatesTest, Distance)
256 {
257 ignition::math::Angle latA, longA, latB, longB;
258 latA.Degree(46.250944);
259 longA.Degree(-122.249972);
260 latB.Degree(46.124953);
261 longB.Degree(-122.251683);
262 double d = math::SphericalCoordinates::Distance(latA, longA, latB, longB);
263
264 EXPECT_NEAR(14002, d, 20);
265 }
266
267 //////////////////////////////////////////////////
268 TEST(SphericalCoordinatesTest, BadSetSurface)
269 {
270 math::SphericalCoordinates sc;
271 sc.SetSurface(static_cast<math::SphericalCoordinates::SurfaceType>(2));
272 EXPECT_EQ(sc.Surface(), 2);
273 }
274
275 //////////////////////////////////////////////////
276 TEST(SphericalCoordinatesTest, Transform)
277 {
278 math::SphericalCoordinates sc;
279 math::Vector3d vel(1, 2, -4);
280 math::Vector3d result = sc.VelocityTransform(vel,
281 math::SphericalCoordinates::ECEF,
282 math::SphericalCoordinates::ECEF);
283
284 EXPECT_EQ(result, vel);
285
286 math::Vector3d pos(-1510.88, 2, -4);
287 result = sc.PositionTransform(pos,
288 math::SphericalCoordinates::ECEF,
289 math::SphericalCoordinates::GLOBAL);
290
291 EXPECT_NEAR(result.X(), 2, 1e-6);
292 EXPECT_NEAR(result.Y(), -4, 1e-6);
293 EXPECT_NEAR(result.Z(), -6379647.8799999999, 1e-6);
294
295 std::cout << "NEW POS[" << result << "]\n";
296 }
297
298 //////////////////////////////////////////////////
299 TEST(SphericalCoordinatesTest, BadCoordinateType)
300 {
301 math::SphericalCoordinates sc;
302 math::Vector3d pos(1, 2, -4);
303 math::Vector3d result = sc.PositionTransform(pos,
304 static_cast<math::SphericalCoordinates::CoordinateType>(5),
305 static_cast<math::SphericalCoordinates::CoordinateType>(6));
306
307 EXPECT_EQ(result, pos);
308
309 result = sc.PositionTransform(pos,
310 static_cast<math::SphericalCoordinates::CoordinateType>(4),
311 static_cast<math::SphericalCoordinates::CoordinateType>(6));
312
313 EXPECT_EQ(result, pos);
314
315 result = sc.VelocityTransform(pos,
316 math::SphericalCoordinates::SPHERICAL,
317 math::SphericalCoordinates::ECEF);
318 EXPECT_EQ(result, pos);
319
320 result = sc.VelocityTransform(pos,
321 math::SphericalCoordinates::ECEF,
322 math::SphericalCoordinates::SPHERICAL);
323 EXPECT_EQ(result, pos);
324
325 result = sc.VelocityTransform(pos,
326 static_cast<math::SphericalCoordinates::CoordinateType>(5),
327 math::SphericalCoordinates::ECEF);
328 EXPECT_EQ(result, pos);
329
330 result = sc.VelocityTransform(pos,
331 math::SphericalCoordinates::ECEF,
332 static_cast<math::SphericalCoordinates::CoordinateType>(5));
333 EXPECT_EQ(result, pos);
334 }
0 # Defines functions and macros useful for building Google Test and
1 # Google Mock.
2 #
3 # Note:
4 #
5 # - This file will be run twice when building Google Mock (once via
6 # Google Test's CMakeLists.txt, and once via Google Mock's).
7 # Therefore it shouldn't have any side effects other than defining
8 # the functions and macros.
9 #
10 # - The functions/macros defined in this file may depend on Google
11 # Test and Google Mock's option() definitions, and thus must be
12 # called *after* the options have been defined.
13
14 # Tweaks CMake's default compiler/linker settings to suit Google Test's needs.
15 #
16 # This must be a macro(), as inside a function string() can only
17 # update variables in the function scope.
18 macro(fix_default_compiler_settings_)
19 if (MSVC)
20 # For MSVC, CMake sets certain flags to defaults we want to override.
21 # This replacement code is taken from sample in the CMake Wiki at
22 # http://www.cmake.org/Wiki/CMake_FAQ#Dynamic_Replace.
23 foreach (flag_var
24 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
25 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
26 if (NOT BUILD_SHARED_LIBS AND NOT gtest_force_shared_crt)
27 # When Google Test is built as a shared library, it should also use
28 # shared runtime libraries. Otherwise, it may end up with multiple
29 # copies of runtime library data in different modules, resulting in
30 # hard-to-find crashes. When it is built as a static library, it is
31 # preferable to use CRT as static libraries, as we don't have to rely
32 # on CRT DLLs being available. CMake always defaults to using shared
33 # CRT libraries, so we override that default here.
34 string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}")
35 endif()
36
37 # We prefer more strict warning checking for building Google Test.
38 # Replaces /W3 with /W4 in defaults.
39 string(REPLACE "/W3" "-W4" ${flag_var} "${${flag_var}}")
40 endforeach()
41 endif()
42 endmacro()
43
44 # Defines the compiler/linker flags used to build Google Test and
45 # Google Mock. You can tweak these definitions to suit your need. A
46 # variable's value is empty before it's explicitly assigned to.
47 macro(config_compiler_and_linker)
48 if (NOT gtest_disable_pthreads)
49 # Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT.
50 find_package(Threads)
51 endif()
52
53 fix_default_compiler_settings_()
54 if (MSVC)
55 # Newlines inside flags variables break CMake's NMake generator.
56 # TODO(vladl@google.com): Add -RTCs and -RTCu to debug builds.
57 set(cxx_base_flags "-GS -W4 -WX -wd4127 -wd4251 -wd4275 -nologo -J -Zi")
58 if (MSVC_VERSION LESS 1400)
59 # Suppress spurious warnings MSVC 7.1 sometimes issues.
60 # Forcing value to bool.
61 set(cxx_base_flags "${cxx_base_flags} -wd4800")
62 # Copy constructor and assignment operator could not be generated.
63 set(cxx_base_flags "${cxx_base_flags} -wd4511 -wd4512")
64 # Compatibility warnings not applicable to Google Test.
65 # Resolved overload was found by argument-dependent lookup.
66 set(cxx_base_flags "${cxx_base_flags} -wd4675")
67 endif()
68 set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32")
69 set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN")
70 set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1")
71 set(cxx_no_exception_flags "-D_HAS_EXCEPTIONS=0")
72 set(cxx_no_rtti_flags "-GR-")
73 elseif (CMAKE_COMPILER_IS_GNUCXX)
74 set(cxx_base_flags "-Wall -Wshadow")
75 set(cxx_exception_flags "-fexceptions")
76 set(cxx_no_exception_flags "-fno-exceptions")
77 # Until version 4.3.2, GCC doesn't define a macro to indicate
78 # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI
79 # explicitly.
80 set(cxx_no_rtti_flags "-fno-rtti -DGTEST_HAS_RTTI=0")
81 set(cxx_strict_flags
82 "-Wextra -Wno-unused-parameter -Wno-missing-field-initializers")
83 elseif (CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
84 set(cxx_exception_flags "-features=except")
85 # Sun Pro doesn't provide macros to indicate whether exceptions and
86 # RTTI are enabled, so we define GTEST_HAS_* explicitly.
87 set(cxx_no_exception_flags "-features=no%except -DGTEST_HAS_EXCEPTIONS=0")
88 set(cxx_no_rtti_flags "-features=no%rtti -DGTEST_HAS_RTTI=0")
89 elseif (CMAKE_CXX_COMPILER_ID STREQUAL "VisualAge" OR
90 CMAKE_CXX_COMPILER_ID STREQUAL "XL")
91 # CMake 2.8 changes Visual Age's compiler ID to "XL".
92 set(cxx_exception_flags "-qeh")
93 set(cxx_no_exception_flags "-qnoeh")
94 # Until version 9.0, Visual Age doesn't define a macro to indicate
95 # whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI
96 # explicitly.
97 set(cxx_no_rtti_flags "-qnortti -DGTEST_HAS_RTTI=0")
98 elseif (CMAKE_CXX_COMPILER_ID STREQUAL "HP")
99 set(cxx_base_flags "-AA -mt")
100 set(cxx_exception_flags "-DGTEST_HAS_EXCEPTIONS=1")
101 set(cxx_no_exception_flags "+noeh -DGTEST_HAS_EXCEPTIONS=0")
102 # RTTI can not be disabled in HP aCC compiler.
103 set(cxx_no_rtti_flags "")
104 endif()
105
106 if (CMAKE_USE_PTHREADS_INIT) # The pthreads library is available and allowed.
107 set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=1")
108 else()
109 set(cxx_base_flags "${cxx_base_flags} -DGTEST_HAS_PTHREAD=0")
110 endif()
111
112 # For building gtest's own tests and samples.
113 set(cxx_exception "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_exception_flags}")
114 set(cxx_no_exception
115 "${CMAKE_CXX_FLAGS} ${cxx_base_flags} ${cxx_no_exception_flags}")
116 set(cxx_default "${cxx_exception}")
117 set(cxx_no_rtti "${cxx_default} ${cxx_no_rtti_flags}")
118 set(cxx_use_own_tuple "${cxx_default} -DGTEST_USE_OWN_TR1_TUPLE=1")
119
120 # For building the gtest libraries.
121 set(cxx_strict "${cxx_default} ${cxx_strict_flags}")
122 endmacro()
123
124 # Defines the gtest & gtest_main libraries. User tests should link
125 # with one of them.
126 function(cxx_library_with_type name type cxx_flags)
127 # type can be either STATIC or SHARED to denote a static or shared library.
128 # ARGN refers to additional arguments after 'cxx_flags'.
129 add_library(${name} ${type} ${ARGN})
130 set_target_properties(${name}
131 PROPERTIES
132 COMPILE_FLAGS "${cxx_flags}")
133 if (BUILD_SHARED_LIBS OR type STREQUAL "SHARED")
134 set_target_properties(${name}
135 PROPERTIES
136 COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1")
137 endif()
138 if (CMAKE_USE_PTHREADS_INIT)
139 target_link_libraries(${name} ${CMAKE_THREAD_LIBS_INIT})
140 endif()
141 endfunction()
142
143 ########################################################################
144 #
145 # Helper functions for creating build targets.
146
147 function(cxx_shared_library name cxx_flags)
148 cxx_library_with_type(${name} SHARED "${cxx_flags}" ${ARGN})
149 endfunction()
150
151 function(cxx_library name cxx_flags)
152 cxx_library_with_type(${name} "" "${cxx_flags}" ${ARGN})
153 endfunction()
154
155 # cxx_executable_with_flags(name cxx_flags libs srcs...)
156 #
157 # creates a named C++ executable that depends on the given libraries and
158 # is built from the given source files with the given compiler flags.
159 function(cxx_executable_with_flags name cxx_flags libs)
160 add_executable(${name} ${ARGN})
161 if (cxx_flags)
162 set_target_properties(${name}
163 PROPERTIES
164 COMPILE_FLAGS "${cxx_flags}")
165 endif()
166 if (BUILD_SHARED_LIBS)
167 set_target_properties(${name}
168 PROPERTIES
169 COMPILE_DEFINITIONS "GTEST_LINKED_AS_SHARED_LIBRARY=1")
170 endif()
171 # To support mixing linking in static and dynamic libraries, link each
172 # library in with an extra call to target_link_libraries.
173 foreach (lib "${libs}")
174 target_link_libraries(${name} ${lib})
175 endforeach()
176 endfunction()
177
178 # cxx_executable(name dir lib srcs...)
179 #
180 # creates a named target that depends on the given libs and is built
181 # from the given source files. dir/name.cc is implicitly included in
182 # the source file list.
183 function(cxx_executable name dir libs)
184 cxx_executable_with_flags(
185 ${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN})
186 endfunction()
187
188 # Sets PYTHONINTERP_FOUND and PYTHON_EXECUTABLE.
189 find_package(PythonInterp)
190
191 # cxx_test_with_flags(name cxx_flags libs srcs...)
192 #
193 # creates a named C++ test that depends on the given libs and is built
194 # from the given source files with the given compiler flags.
195 function(cxx_test_with_flags name cxx_flags libs)
196 cxx_executable_with_flags(${name} "${cxx_flags}" "${libs}" ${ARGN})
197 add_test(${name} ${name})
198 endfunction()
199
200 # cxx_test(name libs srcs...)
201 #
202 # creates a named test target that depends on the given libs and is
203 # built from the given source files. Unlike cxx_test_with_flags,
204 # test/name.cc is already implicitly included in the source file list.
205 function(cxx_test name libs)
206 cxx_test_with_flags("${name}" "${cxx_default}" "${libs}"
207 "test/${name}.cc" ${ARGN})
208 endfunction()
209
210 # py_test(name)
211 #
212 # creates a Python test with the given name whose main module is in
213 # test/name.py. It does nothing if Python is not installed.
214 function(py_test name)
215 # We are not supporting Python tests on Linux yet as they consider
216 # all Linux environments to be google3 and try to use google3 features.
217 if (PYTHONINTERP_FOUND)
218 # ${CMAKE_BINARY_DIR} is known at configuration time, so we can
219 # directly bind it from cmake. ${CTEST_CONFIGURATION_TYPE} is known
220 # only at ctest runtime (by calling ctest -c <Configuration>), so
221 # we have to escape $ to delay variable substitution here.
222 add_test(${name}
223 ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
224 --build_dir=${CMAKE_CURRENT_BINARY_DIR}/\${CTEST_CONFIGURATION_TYPE})
225 endif()
226 endfunction()
0 // Copyright 2005, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30 //
31 // The Google C++ Testing Framework (Google Test)
32 //
33 // This header file defines the public API for death tests. It is
34 // #included by gtest.h so a user doesn't need to include this
35 // directly.
36
37 #ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
38 #define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
39
40 #include "gtest/internal/gtest-death-test-internal.h"
41
42 namespace testing {
43
44 // This flag controls the style of death tests. Valid values are "threadsafe",
45 // meaning that the death test child process will re-execute the test binary
46 // from the start, running only a single death test, or "fast",
47 // meaning that the child process will execute the test logic immediately
48 // after forking.
49 GTEST_DECLARE_string_(death_test_style);
50
51 #if GTEST_HAS_DEATH_TEST
52
53 namespace internal {
54
55 // Returns a Boolean value indicating whether the caller is currently
56 // executing in the context of the death test child process. Tools such as
57 // Valgrind heap checkers may need this to modify their behavior in death
58 // tests. IMPORTANT: This is an internal utility. Using it may break the
59 // implementation of death tests. User code MUST NOT use it.
60 GTEST_API_ bool InDeathTestChild();
61
62 } // namespace internal
63
64 // The following macros are useful for writing death tests.
65
66 // Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is
67 // executed:
68 //
69 // 1. It generates a warning if there is more than one active
70 // thread. This is because it's safe to fork() or clone() only
71 // when there is a single thread.
72 //
73 // 2. The parent process clone()s a sub-process and runs the death
74 // test in it; the sub-process exits with code 0 at the end of the
75 // death test, if it hasn't exited already.
76 //
77 // 3. The parent process waits for the sub-process to terminate.
78 //
79 // 4. The parent process checks the exit code and error message of
80 // the sub-process.
81 //
82 // Examples:
83 //
84 // ASSERT_DEATH(server.SendMessage(56, "Hello"), "Invalid port number");
85 // for (int i = 0; i < 5; i++) {
86 // EXPECT_DEATH(server.ProcessRequest(i),
87 // "Invalid request .* in ProcessRequest()")
88 // << "Failed to die on request " << i;
89 // }
90 //
91 // ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting");
92 //
93 // bool KilledBySIGHUP(int exit_code) {
94 // return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP;
95 // }
96 //
97 // ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!");
98 //
99 // On the regular expressions used in death tests:
100 //
101 // On POSIX-compliant systems (*nix), we use the <regex.h> library,
102 // which uses the POSIX extended regex syntax.
103 //
104 // On other platforms (e.g. Windows), we only support a simple regex
105 // syntax implemented as part of Google Test. This limited
106 // implementation should be enough most of the time when writing
107 // death tests; though it lacks many features you can find in PCRE
108 // or POSIX extended regex syntax. For example, we don't support
109 // union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and
110 // repetition count ("x{5,7}"), among others.
111 //
112 // Below is the syntax that we do support. We chose it to be a
113 // subset of both PCRE and POSIX extended regex, so it's easy to
114 // learn wherever you come from. In the following: 'A' denotes a
115 // literal character, period (.), or a single \\ escape sequence;
116 // 'x' and 'y' denote regular expressions; 'm' and 'n' are for
117 // natural numbers.
118 //
119 // c matches any literal character c
120 // \\d matches any decimal digit
121 // \\D matches any character that's not a decimal digit
122 // \\f matches \f
123 // \\n matches \n
124 // \\r matches \r
125 // \\s matches any ASCII whitespace, including \n
126 // \\S matches any character that's not a whitespace
127 // \\t matches \t
128 // \\v matches \v
129 // \\w matches any letter, _, or decimal digit
130 // \\W matches any character that \\w doesn't match
131 // \\c matches any literal character c, which must be a punctuation
132 // . matches any single character except \n
133 // A? matches 0 or 1 occurrences of A
134 // A* matches 0 or many occurrences of A
135 // A+ matches 1 or many occurrences of A
136 // ^ matches the beginning of a string (not that of each line)
137 // $ matches the end of a string (not that of each line)
138 // xy matches x followed by y
139 //
140 // If you accidentally use PCRE or POSIX extended regex features
141 // not implemented by us, you will get a run-time failure. In that
142 // case, please try to rewrite your regular expression within the
143 // above syntax.
144 //
145 // This implementation is *not* meant to be as highly tuned or robust
146 // as a compiled regex library, but should perform well enough for a
147 // death test, which already incurs significant overhead by launching
148 // a child process.
149 //
150 // Known caveats:
151 //
152 // A "threadsafe" style death test obtains the path to the test
153 // program from argv[0] and re-executes it in the sub-process. For
154 // simplicity, the current implementation doesn't search the PATH
155 // when launching the sub-process. This means that the user must
156 // invoke the test program via a path that contains at least one
157 // path separator (e.g. path/to/foo_test and
158 // /absolute/path/to/bar_test are fine, but foo_test is not). This
159 // is rarely a problem as people usually don't put the test binary
160 // directory in PATH.
161 //
162 // TODO(wan@google.com): make thread-safe death tests search the PATH.
163
164 // Asserts that a given statement causes the program to exit, with an
165 // integer exit status that satisfies predicate, and emitting error output
166 // that matches regex.
167 # define ASSERT_EXIT(statement, predicate, regex) \
168 GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_)
169
170 // Like ASSERT_EXIT, but continues on to successive tests in the
171 // test case, if any:
172 # define EXPECT_EXIT(statement, predicate, regex) \
173 GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_)
174
175 // Asserts that a given statement causes the program to exit, either by
176 // explicitly exiting with a nonzero exit code or being killed by a
177 // signal, and emitting error output that matches regex.
178 # define ASSERT_DEATH(statement, regex) \
179 ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
180
181 // Like ASSERT_DEATH, but continues on to successive tests in the
182 // test case, if any:
183 # define EXPECT_DEATH(statement, regex) \
184 EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex)
185
186 // Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
187
188 // Tests that an exit code describes a normal exit with a given exit code.
189 class GTEST_API_ ExitedWithCode {
190 public:
191 explicit ExitedWithCode(int exit_code);
192 bool operator()(int exit_status) const;
193 private:
194 // No implementation - assignment is unsupported.
195 void operator=(const ExitedWithCode& other);
196
197 const int exit_code_;
198 };
199
200 # if !GTEST_OS_WINDOWS
201 // Tests that an exit code describes an exit due to termination by a
202 // given signal.
203 class GTEST_API_ KilledBySignal {
204 public:
205 explicit KilledBySignal(int signum);
206 bool operator()(int exit_status) const;
207 private:
208 const int signum_;
209 };
210 # endif // !GTEST_OS_WINDOWS
211
212 // EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode.
213 // The death testing framework causes this to have interesting semantics,
214 // since the sideeffects of the call are only visible in opt mode, and not
215 // in debug mode.
216 //
217 // In practice, this can be used to test functions that utilize the
218 // LOG(DFATAL) macro using the following style:
219 //
220 // int DieInDebugOr12(int* sideeffect) {
221 // if (sideeffect) {
222 // *sideeffect = 12;
223 // }
224 // LOG(DFATAL) << "death";
225 // return 12;
226 // }
227 //
228 // TEST(TestCase, TestDieOr12WorksInDgbAndOpt) {
229 // int sideeffect = 0;
230 // // Only asserts in dbg.
231 // EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death");
232 //
233 // #ifdef NDEBUG
234 // // opt-mode has sideeffect visible.
235 // EXPECT_EQ(12, sideeffect);
236 // #else
237 // // dbg-mode no visible sideeffect.
238 // EXPECT_EQ(0, sideeffect);
239 // #endif
240 // }
241 //
242 // This will assert that DieInDebugReturn12InOpt() crashes in debug
243 // mode, usually due to a DCHECK or LOG(DFATAL), but returns the
244 // appropriate fallback value (12 in this case) in opt mode. If you
245 // need to test that a function has appropriate side-effects in opt
246 // mode, include assertions against the side-effects. A general
247 // pattern for this is:
248 //
249 // EXPECT_DEBUG_DEATH({
250 // // Side-effects here will have an effect after this statement in
251 // // opt mode, but none in debug mode.
252 // EXPECT_EQ(12, DieInDebugOr12(&sideeffect));
253 // }, "death");
254 //
255 # ifdef NDEBUG
256
257 # define EXPECT_DEBUG_DEATH(statement, regex) \
258 GTEST_EXECUTE_STATEMENT_(statement, regex)
259
260 # define ASSERT_DEBUG_DEATH(statement, regex) \
261 GTEST_EXECUTE_STATEMENT_(statement, regex)
262
263 # else
264
265 # define EXPECT_DEBUG_DEATH(statement, regex) \
266 EXPECT_DEATH(statement, regex)
267
268 # define ASSERT_DEBUG_DEATH(statement, regex) \
269 ASSERT_DEATH(statement, regex)
270
271 # endif // NDEBUG for EXPECT_DEBUG_DEATH
272 #endif // GTEST_HAS_DEATH_TEST
273
274 // EXPECT_DEATH_IF_SUPPORTED(statement, regex) and
275 // ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if
276 // death tests are supported; otherwise they just issue a warning. This is
277 // useful when you are combining death test assertions with normal test
278 // assertions in one test.
279 #if GTEST_HAS_DEATH_TEST
280 # define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
281 EXPECT_DEATH(statement, regex)
282 # define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
283 ASSERT_DEATH(statement, regex)
284 #else
285 # define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \
286 GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, )
287 # define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \
288 GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, return)
289 #endif
290
291 } // namespace testing
292
293 #endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
0 // Copyright 2005, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30 //
31 // The Google C++ Testing Framework (Google Test)
32 //
33 // This header file defines the Message class.
34 //
35 // IMPORTANT NOTE: Due to limitation of the C++ language, we have to
36 // leave some internal implementation details in this header file.
37 // They are clearly marked by comments like this:
38 //
39 // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
40 //
41 // Such code is NOT meant to be used by a user directly, and is subject
42 // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
43 // program!
44
45 #ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
46 #define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
47
48 #include <limits>
49
50 #include "gtest/internal/gtest-port.h"
51
52 // Ensures that there is at least one operator<< in the global namespace.
53 // See Message& operator<<(...) below for why.
54 void operator<<(const testing::internal::Secret&, int);
55
56 namespace testing {
57
58 // The Message class works like an ostream repeater.
59 //
60 // Typical usage:
61 //
62 // 1. You stream a bunch of values to a Message object.
63 // It will remember the text in a stringstream.
64 // 2. Then you stream the Message object to an ostream.
65 // This causes the text in the Message to be streamed
66 // to the ostream.
67 //
68 // For example;
69 //
70 // testing::Message foo;
71 // foo << 1 << " != " << 2;
72 // std::cout << foo;
73 //
74 // will print "1 != 2".
75 //
76 // Message is not intended to be inherited from. In particular, its
77 // destructor is not virtual.
78 //
79 // Note that stringstream behaves differently in gcc and in MSVC. You
80 // can stream a NULL char pointer to it in the former, but not in the
81 // latter (it causes an access violation if you do). The Message
82 // class hides this difference by treating a NULL char pointer as
83 // "(null)".
84 class GTEST_API_ Message {
85 private:
86 // The type of basic IO manipulators (endl, ends, and flush) for
87 // narrow streams.
88 typedef std::ostream& (*BasicNarrowIoManip)(std::ostream&);
89
90 public:
91 // Constructs an empty Message.
92 Message();
93
94 // Copy constructor.
95 Message(const Message& msg) : ss_(new ::std::stringstream) { // NOLINT
96 *ss_ << msg.GetString();
97 }
98
99 // Constructs a Message from a C-string.
100 explicit Message(const char* str) : ss_(new ::std::stringstream) {
101 *ss_ << str;
102 }
103
104 #if GTEST_OS_SYMBIAN
105 // Streams a value (either a pointer or not) to this object.
106 template <typename T>
107 inline Message& operator <<(const T& value) {
108 StreamHelper(typename internal::is_pointer<T>::type(), value);
109 return *this;
110 }
111 #else
112 // Streams a non-pointer value to this object.
113 template <typename T>
114 inline Message& operator <<(const T& val) {
115 // Some libraries overload << for STL containers. These
116 // overloads are defined in the global namespace instead of ::std.
117 //
118 // C++'s symbol lookup rule (i.e. Koenig lookup) says that these
119 // overloads are visible in either the std namespace or the global
120 // namespace, but not other namespaces, including the testing
121 // namespace which Google Test's Message class is in.
122 //
123 // To allow STL containers (and other types that has a << operator
124 // defined in the global namespace) to be used in Google Test
125 // assertions, testing::Message must access the custom << operator
126 // from the global namespace. With this using declaration,
127 // overloads of << defined in the global namespace and those
128 // visible via Koenig lookup are both exposed in this function.
129 using ::operator <<;
130 *ss_ << val;
131 return *this;
132 }
133
134 // Streams a pointer value to this object.
135 //
136 // This function is an overload of the previous one. When you
137 // stream a pointer to a Message, this definition will be used as it
138 // is more specialized. (The C++ Standard, section
139 // [temp.func.order].) If you stream a non-pointer, then the
140 // previous definition will be used.
141 //
142 // The reason for this overload is that streaming a NULL pointer to
143 // ostream is undefined behavior. Depending on the compiler, you
144 // may get "0", "(nil)", "(null)", or an access violation. To
145 // ensure consistent result across compilers, we always treat NULL
146 // as "(null)".
147 template <typename T>
148 inline Message& operator <<(T* const& pointer) { // NOLINT
149 if (pointer == NULL) {
150 *ss_ << "(null)";
151 } else {
152 *ss_ << pointer;
153 }
154 return *this;
155 }
156 #endif // GTEST_OS_SYMBIAN
157
158 // Since the basic IO manipulators are overloaded for both narrow
159 // and wide streams, we have to provide this specialized definition
160 // of operator <<, even though its body is the same as the
161 // templatized version above. Without this definition, streaming
162 // endl or other basic IO manipulators to Message will confuse the
163 // compiler.
164 Message& operator <<(BasicNarrowIoManip val) {
165 *ss_ << val;
166 return *this;
167 }
168
169 // Instead of 1/0, we want to see true/false for bool values.
170 Message& operator <<(bool b) {
171 return *this << (b ? "true" : "false");
172 }
173
174 // These two overloads allow streaming a wide C string to a Message
175 // using the UTF-8 encoding.
176 Message& operator <<(const wchar_t* wide_c_str);
177 Message& operator <<(wchar_t* wide_c_str);
178
179 #if GTEST_HAS_STD_WSTRING
180 // Converts the given wide string to a narrow string using the UTF-8
181 // encoding, and streams the result to this Message object.
182 Message& operator <<(const ::std::wstring& wstr);
183 #endif // GTEST_HAS_STD_WSTRING
184
185 #if GTEST_HAS_GLOBAL_WSTRING
186 // Converts the given wide string to a narrow string using the UTF-8
187 // encoding, and streams the result to this Message object.
188 Message& operator <<(const ::wstring& wstr);
189 #endif // GTEST_HAS_GLOBAL_WSTRING
190
191 // Gets the text streamed to this object so far as an std::string.
192 // Each '\0' character in the buffer is replaced with "\\0".
193 //
194 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
195 std::string GetString() const;
196
197 private:
198
199 #if GTEST_OS_SYMBIAN
200 // These are needed as the Nokia Symbian Compiler cannot decide between
201 // const T& and const T* in a function template. The Nokia compiler _can_
202 // decide between class template specializations for T and T*, so a
203 // tr1::type_traits-like is_pointer works, and we can overload on that.
204 template <typename T>
205 inline void StreamHelper(internal::true_type /*is_pointer*/, T* pointer) {
206 if (pointer == NULL) {
207 *ss_ << "(null)";
208 } else {
209 *ss_ << pointer;
210 }
211 }
212 template <typename T>
213 inline void StreamHelper(internal::false_type /*is_pointer*/,
214 const T& value) {
215 // See the comments in Message& operator <<(const T&) above for why
216 // we need this using statement.
217 using ::operator <<;
218 *ss_ << value;
219 }
220 #endif // GTEST_OS_SYMBIAN
221
222 // We'll hold the text streamed to this object here.
223 const internal::scoped_ptr< ::std::stringstream> ss_;
224
225 // We declare (but don't implement) this to prevent the compiler
226 // from implementing the assignment operator.
227 void operator=(const Message&);
228 };
229
230 // Streams a Message to an ostream.
231 inline std::ostream& operator <<(std::ostream& os, const Message& sb) {
232 return os << sb.GetString();
233 }
234
235 namespace internal {
236
237 // Converts a streamable value to an std::string. A NULL pointer is
238 // converted to "(null)". When the input value is a ::string,
239 // ::std::string, ::wstring, or ::std::wstring object, each NUL
240 // character in it is replaced with "\\0".
241 template <typename T>
242 std::string StreamableToString(const T& streamable) {
243 return (Message() << streamable).GetString();
244 }
245
246 } // namespace internal
247 } // namespace testing
248
249 #endif // GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
0 // This file was GENERATED by command:
1 // pump.py gtest-param-test.h.pump
2 // DO NOT EDIT BY HAND!!!
3
4 // Copyright 2008, Google Inc.
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
9 // met:
10 //
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Authors: vladl@google.com (Vlad Losev)
34 //
35 // Macros and functions for implementing parameterized tests
36 // in Google C++ Testing Framework (Google Test)
37 //
38 // This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
39 //
40 #ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
41 #define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
42
43
44 // Value-parameterized tests allow you to test your code with different
45 // parameters without writing multiple copies of the same test.
46 //
47 // Here is how you use value-parameterized tests:
48
49 #if 0
50
51 // To write value-parameterized tests, first you should define a fixture
52 // class. It is usually derived from testing::TestWithParam<T> (see below for
53 // another inheritance scheme that's sometimes useful in more complicated
54 // class hierarchies), where the type of your parameter values.
55 // TestWithParam<T> is itself derived from testing::Test. T can be any
56 // copyable type. If it's a raw pointer, you are responsible for managing the
57 // lifespan of the pointed values.
58
59 class FooTest : public ::testing::TestWithParam<const char*> {
60 // You can implement all the usual class fixture members here.
61 };
62
63 // Then, use the TEST_P macro to define as many parameterized tests
64 // for this fixture as you want. The _P suffix is for "parameterized"
65 // or "pattern", whichever you prefer to think.
66
67 TEST_P(FooTest, DoesBlah) {
68 // Inside a test, access the test parameter with the GetParam() method
69 // of the TestWithParam<T> class:
70 EXPECT_TRUE(foo.Blah(GetParam()));
71 ...
72 }
73
74 TEST_P(FooTest, HasBlahBlah) {
75 ...
76 }
77
78 // Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
79 // case with any set of parameters you want. Google Test defines a number
80 // of functions for generating test parameters. They return what we call
81 // (surprise!) parameter generators. Here is a summary of them, which
82 // are all in the testing namespace:
83 //
84 //
85 // Range(begin, end [, step]) - Yields values {begin, begin+step,
86 // begin+step+step, ...}. The values do not
87 // include end. step defaults to 1.
88 // Values(v1, v2, ..., vN) - Yields values {v1, v2, ..., vN}.
89 // ValuesIn(container) - Yields values from a C-style array, an STL
90 // ValuesIn(begin,end) container, or an iterator range [begin, end).
91 // Bool() - Yields sequence {false, true}.
92 // Combine(g1, g2, ..., gN) - Yields all combinations (the Cartesian product
93 // for the math savvy) of the values generated
94 // by the N generators.
95 //
96 // For more details, see comments at the definitions of these functions below
97 // in this file.
98 //
99 // The following statement will instantiate tests from the FooTest test case
100 // each with parameter values "meeny", "miny", and "moe".
101
102 INSTANTIATE_TEST_CASE_P(InstantiationName,
103 FooTest,
104 Values("meeny", "miny", "moe"));
105
106 // To distinguish different instances of the pattern, (yes, you
107 // can instantiate it more then once) the first argument to the
108 // INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the
109 // actual test case name. Remember to pick unique prefixes for different
110 // instantiations. The tests from the instantiation above will have
111 // these names:
112 //
113 // * InstantiationName/FooTest.DoesBlah/0 for "meeny"
114 // * InstantiationName/FooTest.DoesBlah/1 for "miny"
115 // * InstantiationName/FooTest.DoesBlah/2 for "moe"
116 // * InstantiationName/FooTest.HasBlahBlah/0 for "meeny"
117 // * InstantiationName/FooTest.HasBlahBlah/1 for "miny"
118 // * InstantiationName/FooTest.HasBlahBlah/2 for "moe"
119 //
120 // You can use these names in --gtest_filter.
121 //
122 // This statement will instantiate all tests from FooTest again, each
123 // with parameter values "cat" and "dog":
124
125 const char* pets[] = {"cat", "dog"};
126 INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
127
128 // The tests from the instantiation above will have these names:
129 //
130 // * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat"
131 // * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog"
132 // * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
133 // * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
134 //
135 // Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests
136 // in the given test case, whether their definitions come before or
137 // AFTER the INSTANTIATE_TEST_CASE_P statement.
138 //
139 // Please also note that generator expressions (including parameters to the
140 // generators) are evaluated in InitGoogleTest(), after main() has started.
141 // This allows the user on one hand, to adjust generator parameters in order
142 // to dynamically determine a set of tests to run and on the other hand,
143 // give the user a chance to inspect the generated tests with Google Test
144 // reflection API before RUN_ALL_TESTS() is executed.
145 //
146 // You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
147 // for more examples.
148 //
149 // In the future, we plan to publish the API for defining new parameter
150 // generators. But for now this interface remains part of the internal
151 // implementation and is subject to change.
152 //
153 //
154 // A parameterized test fixture must be derived from testing::Test and from
155 // testing::WithParamInterface<T>, where T is the type of the parameter
156 // values. Inheriting from TestWithParam<T> satisfies that requirement because
157 // TestWithParam<T> inherits from both Test and WithParamInterface. In more
158 // complicated hierarchies, however, it is occasionally useful to inherit
159 // separately from Test and WithParamInterface. For example:
160
161 class BaseTest : public ::testing::Test {
162 // You can inherit all the usual members for a non-parameterized test
163 // fixture here.
164 };
165
166 class DerivedTest : public BaseTest, public ::testing::WithParamInterface<int> {
167 // The usual test fixture members go here too.
168 };
169
170 TEST_F(BaseTest, HasFoo) {
171 // This is an ordinary non-parameterized test.
172 }
173
174 TEST_P(DerivedTest, DoesBlah) {
175 // GetParam works just the same here as if you inherit from TestWithParam.
176 EXPECT_TRUE(foo.Blah(GetParam()));
177 }
178
179 #endif // 0
180
181 #include "gtest/internal/gtest-port.h"
182
183 #if !GTEST_OS_SYMBIAN
184 # include <utility>
185 #endif
186
187 // scripts/fuse_gtest.py depends on gtest's own header being #included
188 // *unconditionally*. Therefore these #includes cannot be moved
189 // inside #if GTEST_HAS_PARAM_TEST.
190 #include "gtest/internal/gtest-internal.h"
191 #include "gtest/internal/gtest-param-util.h"
192 #include "gtest/internal/gtest-param-util-generated.h"
193
194 #if GTEST_HAS_PARAM_TEST
195
196 namespace testing {
197
198 // Functions producing parameter generators.
199 //
200 // Google Test uses these generators to produce parameters for value-
201 // parameterized tests. When a parameterized test case is instantiated
202 // with a particular generator, Google Test creates and runs tests
203 // for each element in the sequence produced by the generator.
204 //
205 // In the following sample, tests from test case FooTest are instantiated
206 // each three times with parameter values 3, 5, and 8:
207 //
208 // class FooTest : public TestWithParam<int> { ... };
209 //
210 // TEST_P(FooTest, TestThis) {
211 // }
212 // TEST_P(FooTest, TestThat) {
213 // }
214 // INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8));
215 //
216
217 // Range() returns generators providing sequences of values in a range.
218 //
219 // Synopsis:
220 // Range(start, end)
221 // - returns a generator producing a sequence of values {start, start+1,
222 // start+2, ..., }.
223 // Range(start, end, step)
224 // - returns a generator producing a sequence of values {start, start+step,
225 // start+step+step, ..., }.
226 // Notes:
227 // * The generated sequences never include end. For example, Range(1, 5)
228 // returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2)
229 // returns a generator producing {1, 3, 5, 7}.
230 // * start and end must have the same type. That type may be any integral or
231 // floating-point type or a user defined type satisfying these conditions:
232 // * It must be assignable (have operator=() defined).
233 // * It must have operator+() (operator+(int-compatible type) for
234 // two-operand version).
235 // * It must have operator<() defined.
236 // Elements in the resulting sequences will also have that type.
237 // * Condition start < end must be satisfied in order for resulting sequences
238 // to contain any elements.
239 //
240 template <typename T, typename IncrementT>
241 internal::ParamGenerator<T> Range(T start, T end, IncrementT step) {
242 return internal::ParamGenerator<T>(
243 new internal::RangeGenerator<T, IncrementT>(start, end, step));
244 }
245
246 template <typename T>
247 internal::ParamGenerator<T> Range(T start, T end) {
248 return Range(start, end, 1);
249 }
250
251 // ValuesIn() function allows generation of tests with parameters coming from
252 // a container.
253 //
254 // Synopsis:
255 // ValuesIn(const T (&array)[N])
256 // - returns a generator producing sequences with elements from
257 // a C-style array.
258 // ValuesIn(const Container& container)
259 // - returns a generator producing sequences with elements from
260 // an STL-style container.
261 // ValuesIn(Iterator begin, Iterator end)
262 // - returns a generator producing sequences with elements from
263 // a range [begin, end) defined by a pair of STL-style iterators. These
264 // iterators can also be plain C pointers.
265 //
266 // Please note that ValuesIn copies the values from the containers
267 // passed in and keeps them to generate tests in RUN_ALL_TESTS().
268 //
269 // Examples:
270 //
271 // This instantiates tests from test case StringTest
272 // each with C-string values of "foo", "bar", and "baz":
273 //
274 // const char* strings[] = {"foo", "bar", "baz"};
275 // INSTANTIATE_TEST_CASE_P(StringSequence, SrtingTest, ValuesIn(strings));
276 //
277 // This instantiates tests from test case StlStringTest
278 // each with STL strings with values "a" and "b":
279 //
280 // ::std::vector< ::std::string> GetParameterStrings() {
281 // ::std::vector< ::std::string> v;
282 // v.push_back("a");
283 // v.push_back("b");
284 // return v;
285 // }
286 //
287 // INSTANTIATE_TEST_CASE_P(CharSequence,
288 // StlStringTest,
289 // ValuesIn(GetParameterStrings()));
290 //
291 //
292 // This will also instantiate tests from CharTest
293 // each with parameter values 'a' and 'b':
294 //
295 // ::std::list<char> GetParameterChars() {
296 // ::std::list<char> list;
297 // list.push_back('a');
298 // list.push_back('b');
299 // return list;
300 // }
301 // ::std::list<char> l = GetParameterChars();
302 // INSTANTIATE_TEST_CASE_P(CharSequence2,
303 // CharTest,
304 // ValuesIn(l.begin(), l.end()));
305 //
306 template <typename ForwardIterator>
307 internal::ParamGenerator<
308 typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
309 ValuesIn(ForwardIterator begin, ForwardIterator end) {
310 typedef typename ::testing::internal::IteratorTraits<ForwardIterator>
311 ::value_type ParamType;
312 return internal::ParamGenerator<ParamType>(
313 new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));
314 }
315
316 template <typename T, size_t N>
317 internal::ParamGenerator<T> ValuesIn(const T (&array)[N]) {
318 return ValuesIn(array, array + N);
319 }
320
321 template <class Container>
322 internal::ParamGenerator<typename Container::value_type> ValuesIn(
323 const Container& container) {
324 return ValuesIn(container.begin(), container.end());
325 }
326
327 // Values() allows generating tests from explicitly specified list of
328 // parameters.
329 //
330 // Synopsis:
331 // Values(T v1, T v2, ..., T vN)
332 // - returns a generator producing sequences with elements v1, v2, ..., vN.
333 //
334 // For example, this instantiates tests from test case BarTest each
335 // with values "one", "two", and "three":
336 //
337 // INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three"));
338 //
339 // This instantiates tests from test case BazTest each with values 1, 2, 3.5.
340 // The exact type of values will depend on the type of parameter in BazTest.
341 //
342 // INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
343 //
344 // Currently, Values() supports from 1 to 50 parameters.
345 //
346 template <typename T1>
347 internal::ValueArray1<T1> Values(T1 v1) {
348 return internal::ValueArray1<T1>(v1);
349 }
350
351 template <typename T1, typename T2>
352 internal::ValueArray2<T1, T2> Values(T1 v1, T2 v2) {
353 return internal::ValueArray2<T1, T2>(v1, v2);
354 }
355
356 template <typename T1, typename T2, typename T3>
357 internal::ValueArray3<T1, T2, T3> Values(T1 v1, T2 v2, T3 v3) {
358 return internal::ValueArray3<T1, T2, T3>(v1, v2, v3);
359 }
360
361 template <typename T1, typename T2, typename T3, typename T4>
362 internal::ValueArray4<T1, T2, T3, T4> Values(T1 v1, T2 v2, T3 v3, T4 v4) {
363 return internal::ValueArray4<T1, T2, T3, T4>(v1, v2, v3, v4);
364 }
365
366 template <typename T1, typename T2, typename T3, typename T4, typename T5>
367 internal::ValueArray5<T1, T2, T3, T4, T5> Values(T1 v1, T2 v2, T3 v3, T4 v4,
368 T5 v5) {
369 return internal::ValueArray5<T1, T2, T3, T4, T5>(v1, v2, v3, v4, v5);
370 }
371
372 template <typename T1, typename T2, typename T3, typename T4, typename T5,
373 typename T6>
374 internal::ValueArray6<T1, T2, T3, T4, T5, T6> Values(T1 v1, T2 v2, T3 v3,
375 T4 v4, T5 v5, T6 v6) {
376 return internal::ValueArray6<T1, T2, T3, T4, T5, T6>(v1, v2, v3, v4, v5, v6);
377 }
378
379 template <typename T1, typename T2, typename T3, typename T4, typename T5,
380 typename T6, typename T7>
381 internal::ValueArray7<T1, T2, T3, T4, T5, T6, T7> Values(T1 v1, T2 v2, T3 v3,
382 T4 v4, T5 v5, T6 v6, T7 v7) {
383 return internal::ValueArray7<T1, T2, T3, T4, T5, T6, T7>(v1, v2, v3, v4, v5,
384 v6, v7);
385 }
386
387 template <typename T1, typename T2, typename T3, typename T4, typename T5,
388 typename T6, typename T7, typename T8>
389 internal::ValueArray8<T1, T2, T3, T4, T5, T6, T7, T8> Values(T1 v1, T2 v2,
390 T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8) {
391 return internal::ValueArray8<T1, T2, T3, T4, T5, T6, T7, T8>(v1, v2, v3, v4,
392 v5, v6, v7, v8);
393 }
394
395 template <typename T1, typename T2, typename T3, typename T4, typename T5,
396 typename T6, typename T7, typename T8, typename T9>
397 internal::ValueArray9<T1, T2, T3, T4, T5, T6, T7, T8, T9> Values(T1 v1, T2 v2,
398 T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9) {
399 return internal::ValueArray9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(v1, v2, v3,
400 v4, v5, v6, v7, v8, v9);
401 }
402
403 template <typename T1, typename T2, typename T3, typename T4, typename T5,
404 typename T6, typename T7, typename T8, typename T9, typename T10>
405 internal::ValueArray10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> Values(T1 v1,
406 T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10) {
407 return internal::ValueArray10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(v1,
408 v2, v3, v4, v5, v6, v7, v8, v9, v10);
409 }
410
411 template <typename T1, typename T2, typename T3, typename T4, typename T5,
412 typename T6, typename T7, typename T8, typename T9, typename T10,
413 typename T11>
414 internal::ValueArray11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,
415 T11> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
416 T10 v10, T11 v11) {
417 return internal::ValueArray11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10,
418 T11>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11);
419 }
420
421 template <typename T1, typename T2, typename T3, typename T4, typename T5,
422 typename T6, typename T7, typename T8, typename T9, typename T10,
423 typename T11, typename T12>
424 internal::ValueArray12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
425 T12> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
426 T10 v10, T11 v11, T12 v12) {
427 return internal::ValueArray12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
428 T12>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12);
429 }
430
431 template <typename T1, typename T2, typename T3, typename T4, typename T5,
432 typename T6, typename T7, typename T8, typename T9, typename T10,
433 typename T11, typename T12, typename T13>
434 internal::ValueArray13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
435 T13> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
436 T10 v10, T11 v11, T12 v12, T13 v13) {
437 return internal::ValueArray13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
438 T12, T13>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13);
439 }
440
441 template <typename T1, typename T2, typename T3, typename T4, typename T5,
442 typename T6, typename T7, typename T8, typename T9, typename T10,
443 typename T11, typename T12, typename T13, typename T14>
444 internal::ValueArray14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
445 T14> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
446 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14) {
447 return internal::ValueArray14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
448 T12, T13, T14>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
449 v14);
450 }
451
452 template <typename T1, typename T2, typename T3, typename T4, typename T5,
453 typename T6, typename T7, typename T8, typename T9, typename T10,
454 typename T11, typename T12, typename T13, typename T14, typename T15>
455 internal::ValueArray15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
456 T14, T15> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,
457 T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15) {
458 return internal::ValueArray15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
459 T12, T13, T14, T15>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12,
460 v13, v14, v15);
461 }
462
463 template <typename T1, typename T2, typename T3, typename T4, typename T5,
464 typename T6, typename T7, typename T8, typename T9, typename T10,
465 typename T11, typename T12, typename T13, typename T14, typename T15,
466 typename T16>
467 internal::ValueArray16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
468 T14, T15, T16> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
469 T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
470 T16 v16) {
471 return internal::ValueArray16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
472 T12, T13, T14, T15, T16>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
473 v12, v13, v14, v15, v16);
474 }
475
476 template <typename T1, typename T2, typename T3, typename T4, typename T5,
477 typename T6, typename T7, typename T8, typename T9, typename T10,
478 typename T11, typename T12, typename T13, typename T14, typename T15,
479 typename T16, typename T17>
480 internal::ValueArray17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
481 T14, T15, T16, T17> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
482 T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
483 T16 v16, T17 v17) {
484 return internal::ValueArray17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
485 T12, T13, T14, T15, T16, T17>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10,
486 v11, v12, v13, v14, v15, v16, v17);
487 }
488
489 template <typename T1, typename T2, typename T3, typename T4, typename T5,
490 typename T6, typename T7, typename T8, typename T9, typename T10,
491 typename T11, typename T12, typename T13, typename T14, typename T15,
492 typename T16, typename T17, typename T18>
493 internal::ValueArray18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
494 T14, T15, T16, T17, T18> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6,
495 T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
496 T16 v16, T17 v17, T18 v18) {
497 return internal::ValueArray18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
498 T12, T13, T14, T15, T16, T17, T18>(v1, v2, v3, v4, v5, v6, v7, v8, v9,
499 v10, v11, v12, v13, v14, v15, v16, v17, v18);
500 }
501
502 template <typename T1, typename T2, typename T3, typename T4, typename T5,
503 typename T6, typename T7, typename T8, typename T9, typename T10,
504 typename T11, typename T12, typename T13, typename T14, typename T15,
505 typename T16, typename T17, typename T18, typename T19>
506 internal::ValueArray19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
507 T14, T15, T16, T17, T18, T19> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5,
508 T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14,
509 T15 v15, T16 v16, T17 v17, T18 v18, T19 v19) {
510 return internal::ValueArray19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
511 T12, T13, T14, T15, T16, T17, T18, T19>(v1, v2, v3, v4, v5, v6, v7, v8,
512 v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19);
513 }
514
515 template <typename T1, typename T2, typename T3, typename T4, typename T5,
516 typename T6, typename T7, typename T8, typename T9, typename T10,
517 typename T11, typename T12, typename T13, typename T14, typename T15,
518 typename T16, typename T17, typename T18, typename T19, typename T20>
519 internal::ValueArray20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
520 T14, T15, T16, T17, T18, T19, T20> Values(T1 v1, T2 v2, T3 v3, T4 v4,
521 T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,
522 T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20) {
523 return internal::ValueArray20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
524 T12, T13, T14, T15, T16, T17, T18, T19, T20>(v1, v2, v3, v4, v5, v6, v7,
525 v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20);
526 }
527
528 template <typename T1, typename T2, typename T3, typename T4, typename T5,
529 typename T6, typename T7, typename T8, typename T9, typename T10,
530 typename T11, typename T12, typename T13, typename T14, typename T15,
531 typename T16, typename T17, typename T18, typename T19, typename T20,
532 typename T21>
533 internal::ValueArray21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
534 T14, T15, T16, T17, T18, T19, T20, T21> Values(T1 v1, T2 v2, T3 v3, T4 v4,
535 T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,
536 T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21) {
537 return internal::ValueArray21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
538 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21>(v1, v2, v3, v4, v5, v6,
539 v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21);
540 }
541
542 template <typename T1, typename T2, typename T3, typename T4, typename T5,
543 typename T6, typename T7, typename T8, typename T9, typename T10,
544 typename T11, typename T12, typename T13, typename T14, typename T15,
545 typename T16, typename T17, typename T18, typename T19, typename T20,
546 typename T21, typename T22>
547 internal::ValueArray22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
548 T14, T15, T16, T17, T18, T19, T20, T21, T22> Values(T1 v1, T2 v2, T3 v3,
549 T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
550 T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
551 T21 v21, T22 v22) {
552 return internal::ValueArray22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
553 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22>(v1, v2, v3, v4,
554 v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,
555 v20, v21, v22);
556 }
557
558 template <typename T1, typename T2, typename T3, typename T4, typename T5,
559 typename T6, typename T7, typename T8, typename T9, typename T10,
560 typename T11, typename T12, typename T13, typename T14, typename T15,
561 typename T16, typename T17, typename T18, typename T19, typename T20,
562 typename T21, typename T22, typename T23>
563 internal::ValueArray23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
564 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23> Values(T1 v1, T2 v2,
565 T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
566 T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
567 T21 v21, T22 v22, T23 v23) {
568 return internal::ValueArray23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
569 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23>(v1, v2, v3,
570 v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,
571 v20, v21, v22, v23);
572 }
573
574 template <typename T1, typename T2, typename T3, typename T4, typename T5,
575 typename T6, typename T7, typename T8, typename T9, typename T10,
576 typename T11, typename T12, typename T13, typename T14, typename T15,
577 typename T16, typename T17, typename T18, typename T19, typename T20,
578 typename T21, typename T22, typename T23, typename T24>
579 internal::ValueArray24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
580 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> Values(T1 v1, T2 v2,
581 T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
582 T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
583 T21 v21, T22 v22, T23 v23, T24 v24) {
584 return internal::ValueArray24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
585 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24>(v1, v2,
586 v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18,
587 v19, v20, v21, v22, v23, v24);
588 }
589
590 template <typename T1, typename T2, typename T3, typename T4, typename T5,
591 typename T6, typename T7, typename T8, typename T9, typename T10,
592 typename T11, typename T12, typename T13, typename T14, typename T15,
593 typename T16, typename T17, typename T18, typename T19, typename T20,
594 typename T21, typename T22, typename T23, typename T24, typename T25>
595 internal::ValueArray25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
596 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> Values(T1 v1,
597 T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11,
598 T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19,
599 T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25) {
600 return internal::ValueArray25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
601 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25>(v1,
602 v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17,
603 v18, v19, v20, v21, v22, v23, v24, v25);
604 }
605
606 template <typename T1, typename T2, typename T3, typename T4, typename T5,
607 typename T6, typename T7, typename T8, typename T9, typename T10,
608 typename T11, typename T12, typename T13, typename T14, typename T15,
609 typename T16, typename T17, typename T18, typename T19, typename T20,
610 typename T21, typename T22, typename T23, typename T24, typename T25,
611 typename T26>
612 internal::ValueArray26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
613 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
614 T26> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
615 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
616 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
617 T26 v26) {
618 return internal::ValueArray26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
619 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
620 T26>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15,
621 v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26);
622 }
623
624 template <typename T1, typename T2, typename T3, typename T4, typename T5,
625 typename T6, typename T7, typename T8, typename T9, typename T10,
626 typename T11, typename T12, typename T13, typename T14, typename T15,
627 typename T16, typename T17, typename T18, typename T19, typename T20,
628 typename T21, typename T22, typename T23, typename T24, typename T25,
629 typename T26, typename T27>
630 internal::ValueArray27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
631 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
632 T27> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
633 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
634 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
635 T26 v26, T27 v27) {
636 return internal::ValueArray27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
637 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
638 T26, T27>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14,
639 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27);
640 }
641
642 template <typename T1, typename T2, typename T3, typename T4, typename T5,
643 typename T6, typename T7, typename T8, typename T9, typename T10,
644 typename T11, typename T12, typename T13, typename T14, typename T15,
645 typename T16, typename T17, typename T18, typename T19, typename T20,
646 typename T21, typename T22, typename T23, typename T24, typename T25,
647 typename T26, typename T27, typename T28>
648 internal::ValueArray28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
649 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
650 T28> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
651 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
652 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
653 T26 v26, T27 v27, T28 v28) {
654 return internal::ValueArray28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
655 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
656 T26, T27, T28>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
657 v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27,
658 v28);
659 }
660
661 template <typename T1, typename T2, typename T3, typename T4, typename T5,
662 typename T6, typename T7, typename T8, typename T9, typename T10,
663 typename T11, typename T12, typename T13, typename T14, typename T15,
664 typename T16, typename T17, typename T18, typename T19, typename T20,
665 typename T21, typename T22, typename T23, typename T24, typename T25,
666 typename T26, typename T27, typename T28, typename T29>
667 internal::ValueArray29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
668 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
669 T29> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
670 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
671 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
672 T26 v26, T27 v27, T28 v28, T29 v29) {
673 return internal::ValueArray29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
674 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
675 T26, T27, T28, T29>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12,
676 v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26,
677 v27, v28, v29);
678 }
679
680 template <typename T1, typename T2, typename T3, typename T4, typename T5,
681 typename T6, typename T7, typename T8, typename T9, typename T10,
682 typename T11, typename T12, typename T13, typename T14, typename T15,
683 typename T16, typename T17, typename T18, typename T19, typename T20,
684 typename T21, typename T22, typename T23, typename T24, typename T25,
685 typename T26, typename T27, typename T28, typename T29, typename T30>
686 internal::ValueArray30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
687 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
688 T29, T30> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,
689 T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16,
690 T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24,
691 T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30) {
692 return internal::ValueArray30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
693 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
694 T26, T27, T28, T29, T30>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
695 v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25,
696 v26, v27, v28, v29, v30);
697 }
698
699 template <typename T1, typename T2, typename T3, typename T4, typename T5,
700 typename T6, typename T7, typename T8, typename T9, typename T10,
701 typename T11, typename T12, typename T13, typename T14, typename T15,
702 typename T16, typename T17, typename T18, typename T19, typename T20,
703 typename T21, typename T22, typename T23, typename T24, typename T25,
704 typename T26, typename T27, typename T28, typename T29, typename T30,
705 typename T31>
706 internal::ValueArray31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
707 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
708 T29, T30, T31> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
709 T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
710 T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
711 T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31) {
712 return internal::ValueArray31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
713 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
714 T26, T27, T28, T29, T30, T31>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10,
715 v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24,
716 v25, v26, v27, v28, v29, v30, v31);
717 }
718
719 template <typename T1, typename T2, typename T3, typename T4, typename T5,
720 typename T6, typename T7, typename T8, typename T9, typename T10,
721 typename T11, typename T12, typename T13, typename T14, typename T15,
722 typename T16, typename T17, typename T18, typename T19, typename T20,
723 typename T21, typename T22, typename T23, typename T24, typename T25,
724 typename T26, typename T27, typename T28, typename T29, typename T30,
725 typename T31, typename T32>
726 internal::ValueArray32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
727 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
728 T29, T30, T31, T32> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
729 T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
730 T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
731 T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,
732 T32 v32) {
733 return internal::ValueArray32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
734 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
735 T26, T27, T28, T29, T30, T31, T32>(v1, v2, v3, v4, v5, v6, v7, v8, v9,
736 v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,
737 v24, v25, v26, v27, v28, v29, v30, v31, v32);
738 }
739
740 template <typename T1, typename T2, typename T3, typename T4, typename T5,
741 typename T6, typename T7, typename T8, typename T9, typename T10,
742 typename T11, typename T12, typename T13, typename T14, typename T15,
743 typename T16, typename T17, typename T18, typename T19, typename T20,
744 typename T21, typename T22, typename T23, typename T24, typename T25,
745 typename T26, typename T27, typename T28, typename T29, typename T30,
746 typename T31, typename T32, typename T33>
747 internal::ValueArray33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
748 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
749 T29, T30, T31, T32, T33> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6,
750 T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
751 T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
752 T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,
753 T32 v32, T33 v33) {
754 return internal::ValueArray33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
755 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
756 T26, T27, T28, T29, T30, T31, T32, T33>(v1, v2, v3, v4, v5, v6, v7, v8,
757 v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,
758 v24, v25, v26, v27, v28, v29, v30, v31, v32, v33);
759 }
760
761 template <typename T1, typename T2, typename T3, typename T4, typename T5,
762 typename T6, typename T7, typename T8, typename T9, typename T10,
763 typename T11, typename T12, typename T13, typename T14, typename T15,
764 typename T16, typename T17, typename T18, typename T19, typename T20,
765 typename T21, typename T22, typename T23, typename T24, typename T25,
766 typename T26, typename T27, typename T28, typename T29, typename T30,
767 typename T31, typename T32, typename T33, typename T34>
768 internal::ValueArray34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
769 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
770 T29, T30, T31, T32, T33, T34> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5,
771 T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14,
772 T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22,
773 T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30,
774 T31 v31, T32 v32, T33 v33, T34 v34) {
775 return internal::ValueArray34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
776 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
777 T26, T27, T28, T29, T30, T31, T32, T33, T34>(v1, v2, v3, v4, v5, v6, v7,
778 v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22,
779 v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34);
780 }
781
782 template <typename T1, typename T2, typename T3, typename T4, typename T5,
783 typename T6, typename T7, typename T8, typename T9, typename T10,
784 typename T11, typename T12, typename T13, typename T14, typename T15,
785 typename T16, typename T17, typename T18, typename T19, typename T20,
786 typename T21, typename T22, typename T23, typename T24, typename T25,
787 typename T26, typename T27, typename T28, typename T29, typename T30,
788 typename T31, typename T32, typename T33, typename T34, typename T35>
789 internal::ValueArray35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
790 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
791 T29, T30, T31, T32, T33, T34, T35> Values(T1 v1, T2 v2, T3 v3, T4 v4,
792 T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,
793 T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21,
794 T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29,
795 T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35) {
796 return internal::ValueArray35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
797 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
798 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35>(v1, v2, v3, v4, v5, v6,
799 v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21,
800 v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35);
801 }
802
803 template <typename T1, typename T2, typename T3, typename T4, typename T5,
804 typename T6, typename T7, typename T8, typename T9, typename T10,
805 typename T11, typename T12, typename T13, typename T14, typename T15,
806 typename T16, typename T17, typename T18, typename T19, typename T20,
807 typename T21, typename T22, typename T23, typename T24, typename T25,
808 typename T26, typename T27, typename T28, typename T29, typename T30,
809 typename T31, typename T32, typename T33, typename T34, typename T35,
810 typename T36>
811 internal::ValueArray36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
812 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
813 T29, T30, T31, T32, T33, T34, T35, T36> Values(T1 v1, T2 v2, T3 v3, T4 v4,
814 T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,
815 T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21,
816 T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29,
817 T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36) {
818 return internal::ValueArray36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
819 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
820 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36>(v1, v2, v3, v4,
821 v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,
822 v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33,
823 v34, v35, v36);
824 }
825
826 template <typename T1, typename T2, typename T3, typename T4, typename T5,
827 typename T6, typename T7, typename T8, typename T9, typename T10,
828 typename T11, typename T12, typename T13, typename T14, typename T15,
829 typename T16, typename T17, typename T18, typename T19, typename T20,
830 typename T21, typename T22, typename T23, typename T24, typename T25,
831 typename T26, typename T27, typename T28, typename T29, typename T30,
832 typename T31, typename T32, typename T33, typename T34, typename T35,
833 typename T36, typename T37>
834 internal::ValueArray37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
835 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
836 T29, T30, T31, T32, T33, T34, T35, T36, T37> Values(T1 v1, T2 v2, T3 v3,
837 T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
838 T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
839 T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28,
840 T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36,
841 T37 v37) {
842 return internal::ValueArray37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
843 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
844 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37>(v1, v2, v3,
845 v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,
846 v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33,
847 v34, v35, v36, v37);
848 }
849
850 template <typename T1, typename T2, typename T3, typename T4, typename T5,
851 typename T6, typename T7, typename T8, typename T9, typename T10,
852 typename T11, typename T12, typename T13, typename T14, typename T15,
853 typename T16, typename T17, typename T18, typename T19, typename T20,
854 typename T21, typename T22, typename T23, typename T24, typename T25,
855 typename T26, typename T27, typename T28, typename T29, typename T30,
856 typename T31, typename T32, typename T33, typename T34, typename T35,
857 typename T36, typename T37, typename T38>
858 internal::ValueArray38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
859 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
860 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> Values(T1 v1, T2 v2,
861 T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
862 T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
863 T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28,
864 T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36,
865 T37 v37, T38 v38) {
866 return internal::ValueArray38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
867 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
868 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38>(v1, v2,
869 v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18,
870 v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32,
871 v33, v34, v35, v36, v37, v38);
872 }
873
874 template <typename T1, typename T2, typename T3, typename T4, typename T5,
875 typename T6, typename T7, typename T8, typename T9, typename T10,
876 typename T11, typename T12, typename T13, typename T14, typename T15,
877 typename T16, typename T17, typename T18, typename T19, typename T20,
878 typename T21, typename T22, typename T23, typename T24, typename T25,
879 typename T26, typename T27, typename T28, typename T29, typename T30,
880 typename T31, typename T32, typename T33, typename T34, typename T35,
881 typename T36, typename T37, typename T38, typename T39>
882 internal::ValueArray39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
883 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
884 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> Values(T1 v1, T2 v2,
885 T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12,
886 T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20,
887 T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28,
888 T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36,
889 T37 v37, T38 v38, T39 v39) {
890 return internal::ValueArray39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
891 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
892 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39>(v1,
893 v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17,
894 v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31,
895 v32, v33, v34, v35, v36, v37, v38, v39);
896 }
897
898 template <typename T1, typename T2, typename T3, typename T4, typename T5,
899 typename T6, typename T7, typename T8, typename T9, typename T10,
900 typename T11, typename T12, typename T13, typename T14, typename T15,
901 typename T16, typename T17, typename T18, typename T19, typename T20,
902 typename T21, typename T22, typename T23, typename T24, typename T25,
903 typename T26, typename T27, typename T28, typename T29, typename T30,
904 typename T31, typename T32, typename T33, typename T34, typename T35,
905 typename T36, typename T37, typename T38, typename T39, typename T40>
906 internal::ValueArray40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
907 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
908 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> Values(T1 v1,
909 T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11,
910 T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19,
911 T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27,
912 T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35,
913 T36 v36, T37 v37, T38 v38, T39 v39, T40 v40) {
914 return internal::ValueArray40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
915 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
916 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
917 T40>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15,
918 v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29,
919 v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40);
920 }
921
922 template <typename T1, typename T2, typename T3, typename T4, typename T5,
923 typename T6, typename T7, typename T8, typename T9, typename T10,
924 typename T11, typename T12, typename T13, typename T14, typename T15,
925 typename T16, typename T17, typename T18, typename T19, typename T20,
926 typename T21, typename T22, typename T23, typename T24, typename T25,
927 typename T26, typename T27, typename T28, typename T29, typename T30,
928 typename T31, typename T32, typename T33, typename T34, typename T35,
929 typename T36, typename T37, typename T38, typename T39, typename T40,
930 typename T41>
931 internal::ValueArray41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
932 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
933 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
934 T41> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
935 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
936 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
937 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
938 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41) {
939 return internal::ValueArray41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
940 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
941 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
942 T40, T41>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14,
943 v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28,
944 v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41);
945 }
946
947 template <typename T1, typename T2, typename T3, typename T4, typename T5,
948 typename T6, typename T7, typename T8, typename T9, typename T10,
949 typename T11, typename T12, typename T13, typename T14, typename T15,
950 typename T16, typename T17, typename T18, typename T19, typename T20,
951 typename T21, typename T22, typename T23, typename T24, typename T25,
952 typename T26, typename T27, typename T28, typename T29, typename T30,
953 typename T31, typename T32, typename T33, typename T34, typename T35,
954 typename T36, typename T37, typename T38, typename T39, typename T40,
955 typename T41, typename T42>
956 internal::ValueArray42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
957 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
958 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
959 T42> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
960 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
961 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
962 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
963 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
964 T42 v42) {
965 return internal::ValueArray42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
966 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
967 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
968 T40, T41, T42>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13,
969 v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27,
970 v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41,
971 v42);
972 }
973
974 template <typename T1, typename T2, typename T3, typename T4, typename T5,
975 typename T6, typename T7, typename T8, typename T9, typename T10,
976 typename T11, typename T12, typename T13, typename T14, typename T15,
977 typename T16, typename T17, typename T18, typename T19, typename T20,
978 typename T21, typename T22, typename T23, typename T24, typename T25,
979 typename T26, typename T27, typename T28, typename T29, typename T30,
980 typename T31, typename T32, typename T33, typename T34, typename T35,
981 typename T36, typename T37, typename T38, typename T39, typename T40,
982 typename T41, typename T42, typename T43>
983 internal::ValueArray43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
984 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
985 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
986 T43> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
987 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
988 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
989 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
990 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
991 T42 v42, T43 v43) {
992 return internal::ValueArray43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
993 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
994 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
995 T40, T41, T42, T43>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12,
996 v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26,
997 v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40,
998 v41, v42, v43);
999 }
1000
1001 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1002 typename T6, typename T7, typename T8, typename T9, typename T10,
1003 typename T11, typename T12, typename T13, typename T14, typename T15,
1004 typename T16, typename T17, typename T18, typename T19, typename T20,
1005 typename T21, typename T22, typename T23, typename T24, typename T25,
1006 typename T26, typename T27, typename T28, typename T29, typename T30,
1007 typename T31, typename T32, typename T33, typename T34, typename T35,
1008 typename T36, typename T37, typename T38, typename T39, typename T40,
1009 typename T41, typename T42, typename T43, typename T44>
1010 internal::ValueArray44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
1011 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
1012 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
1013 T44> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1014 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1015 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1016 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
1017 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
1018 T42 v42, T43 v43, T44 v44) {
1019 return internal::ValueArray44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
1020 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
1021 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
1022 T40, T41, T42, T43, T44>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11,
1023 v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25,
1024 v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39,
1025 v40, v41, v42, v43, v44);
1026 }
1027
1028 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1029 typename T6, typename T7, typename T8, typename T9, typename T10,
1030 typename T11, typename T12, typename T13, typename T14, typename T15,
1031 typename T16, typename T17, typename T18, typename T19, typename T20,
1032 typename T21, typename T22, typename T23, typename T24, typename T25,
1033 typename T26, typename T27, typename T28, typename T29, typename T30,
1034 typename T31, typename T32, typename T33, typename T34, typename T35,
1035 typename T36, typename T37, typename T38, typename T39, typename T40,
1036 typename T41, typename T42, typename T43, typename T44, typename T45>
1037 internal::ValueArray45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
1038 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
1039 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
1040 T44, T45> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,
1041 T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16,
1042 T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24,
1043 T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32,
1044 T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40,
1045 T41 v41, T42 v42, T43 v43, T44 v44, T45 v45) {
1046 return internal::ValueArray45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
1047 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
1048 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
1049 T40, T41, T42, T43, T44, T45>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10,
1050 v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24,
1051 v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38,
1052 v39, v40, v41, v42, v43, v44, v45);
1053 }
1054
1055 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1056 typename T6, typename T7, typename T8, typename T9, typename T10,
1057 typename T11, typename T12, typename T13, typename T14, typename T15,
1058 typename T16, typename T17, typename T18, typename T19, typename T20,
1059 typename T21, typename T22, typename T23, typename T24, typename T25,
1060 typename T26, typename T27, typename T28, typename T29, typename T30,
1061 typename T31, typename T32, typename T33, typename T34, typename T35,
1062 typename T36, typename T37, typename T38, typename T39, typename T40,
1063 typename T41, typename T42, typename T43, typename T44, typename T45,
1064 typename T46>
1065 internal::ValueArray46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
1066 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
1067 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
1068 T44, T45, T46> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
1069 T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
1070 T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
1071 T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,
1072 T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39,
1073 T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46) {
1074 return internal::ValueArray46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
1075 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
1076 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
1077 T40, T41, T42, T43, T44, T45, T46>(v1, v2, v3, v4, v5, v6, v7, v8, v9,
1078 v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,
1079 v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37,
1080 v38, v39, v40, v41, v42, v43, v44, v45, v46);
1081 }
1082
1083 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1084 typename T6, typename T7, typename T8, typename T9, typename T10,
1085 typename T11, typename T12, typename T13, typename T14, typename T15,
1086 typename T16, typename T17, typename T18, typename T19, typename T20,
1087 typename T21, typename T22, typename T23, typename T24, typename T25,
1088 typename T26, typename T27, typename T28, typename T29, typename T30,
1089 typename T31, typename T32, typename T33, typename T34, typename T35,
1090 typename T36, typename T37, typename T38, typename T39, typename T40,
1091 typename T41, typename T42, typename T43, typename T44, typename T45,
1092 typename T46, typename T47>
1093 internal::ValueArray47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
1094 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
1095 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
1096 T44, T45, T46, T47> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
1097 T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
1098 T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
1099 T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,
1100 T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39,
1101 T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47) {
1102 return internal::ValueArray47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
1103 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
1104 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
1105 T40, T41, T42, T43, T44, T45, T46, T47>(v1, v2, v3, v4, v5, v6, v7, v8,
1106 v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23,
1107 v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37,
1108 v38, v39, v40, v41, v42, v43, v44, v45, v46, v47);
1109 }
1110
1111 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1112 typename T6, typename T7, typename T8, typename T9, typename T10,
1113 typename T11, typename T12, typename T13, typename T14, typename T15,
1114 typename T16, typename T17, typename T18, typename T19, typename T20,
1115 typename T21, typename T22, typename T23, typename T24, typename T25,
1116 typename T26, typename T27, typename T28, typename T29, typename T30,
1117 typename T31, typename T32, typename T33, typename T34, typename T35,
1118 typename T36, typename T37, typename T38, typename T39, typename T40,
1119 typename T41, typename T42, typename T43, typename T44, typename T45,
1120 typename T46, typename T47, typename T48>
1121 internal::ValueArray48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
1122 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
1123 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
1124 T44, T45, T46, T47, T48> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6,
1125 T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15,
1126 T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23,
1127 T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31,
1128 T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39,
1129 T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47,
1130 T48 v48) {
1131 return internal::ValueArray48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
1132 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
1133 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
1134 T40, T41, T42, T43, T44, T45, T46, T47, T48>(v1, v2, v3, v4, v5, v6, v7,
1135 v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22,
1136 v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36,
1137 v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48);
1138 }
1139
1140 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1141 typename T6, typename T7, typename T8, typename T9, typename T10,
1142 typename T11, typename T12, typename T13, typename T14, typename T15,
1143 typename T16, typename T17, typename T18, typename T19, typename T20,
1144 typename T21, typename T22, typename T23, typename T24, typename T25,
1145 typename T26, typename T27, typename T28, typename T29, typename T30,
1146 typename T31, typename T32, typename T33, typename T34, typename T35,
1147 typename T36, typename T37, typename T38, typename T39, typename T40,
1148 typename T41, typename T42, typename T43, typename T44, typename T45,
1149 typename T46, typename T47, typename T48, typename T49>
1150 internal::ValueArray49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
1151 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
1152 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
1153 T44, T45, T46, T47, T48, T49> Values(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5,
1154 T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13, T14 v14,
1155 T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21, T22 v22,
1156 T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29, T30 v30,
1157 T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37, T38 v38,
1158 T39 v39, T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45, T46 v46,
1159 T47 v47, T48 v48, T49 v49) {
1160 return internal::ValueArray49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
1161 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
1162 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
1163 T40, T41, T42, T43, T44, T45, T46, T47, T48, T49>(v1, v2, v3, v4, v5, v6,
1164 v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21,
1165 v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35,
1166 v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49);
1167 }
1168
1169 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1170 typename T6, typename T7, typename T8, typename T9, typename T10,
1171 typename T11, typename T12, typename T13, typename T14, typename T15,
1172 typename T16, typename T17, typename T18, typename T19, typename T20,
1173 typename T21, typename T22, typename T23, typename T24, typename T25,
1174 typename T26, typename T27, typename T28, typename T29, typename T30,
1175 typename T31, typename T32, typename T33, typename T34, typename T35,
1176 typename T36, typename T37, typename T38, typename T39, typename T40,
1177 typename T41, typename T42, typename T43, typename T44, typename T45,
1178 typename T46, typename T47, typename T48, typename T49, typename T50>
1179 internal::ValueArray50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
1180 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
1181 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
1182 T44, T45, T46, T47, T48, T49, T50> Values(T1 v1, T2 v2, T3 v3, T4 v4,
1183 T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11, T12 v12, T13 v13,
1184 T14 v14, T15 v15, T16 v16, T17 v17, T18 v18, T19 v19, T20 v20, T21 v21,
1185 T22 v22, T23 v23, T24 v24, T25 v25, T26 v26, T27 v27, T28 v28, T29 v29,
1186 T30 v30, T31 v31, T32 v32, T33 v33, T34 v34, T35 v35, T36 v36, T37 v37,
1187 T38 v38, T39 v39, T40 v40, T41 v41, T42 v42, T43 v43, T44 v44, T45 v45,
1188 T46 v46, T47 v47, T48 v48, T49 v49, T50 v50) {
1189 return internal::ValueArray50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
1190 T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
1191 T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
1192 T40, T41, T42, T43, T44, T45, T46, T47, T48, T49, T50>(v1, v2, v3, v4,
1193 v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19,
1194 v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33,
1195 v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47,
1196 v48, v49, v50);
1197 }
1198
1199 // Bool() allows generating tests with parameters in a set of (false, true).
1200 //
1201 // Synopsis:
1202 // Bool()
1203 // - returns a generator producing sequences with elements {false, true}.
1204 //
1205 // It is useful when testing code that depends on Boolean flags. Combinations
1206 // of multiple flags can be tested when several Bool()'s are combined using
1207 // Combine() function.
1208 //
1209 // In the following example all tests in the test case FlagDependentTest
1210 // will be instantiated twice with parameters false and true.
1211 //
1212 // class FlagDependentTest : public testing::TestWithParam<bool> {
1213 // virtual void SetUp() {
1214 // external_flag = GetParam();
1215 // }
1216 // }
1217 // INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());
1218 //
1219 inline internal::ParamGenerator<bool> Bool() {
1220 return Values(false, true);
1221 }
1222
1223 # if GTEST_HAS_COMBINE
1224 // Combine() allows the user to combine two or more sequences to produce
1225 // values of a Cartesian product of those sequences' elements.
1226 //
1227 // Synopsis:
1228 // Combine(gen1, gen2, ..., genN)
1229 // - returns a generator producing sequences with elements coming from
1230 // the Cartesian product of elements from the sequences generated by
1231 // gen1, gen2, ..., genN. The sequence elements will have a type of
1232 // tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
1233 // of elements from sequences produces by gen1, gen2, ..., genN.
1234 //
1235 // Combine can have up to 10 arguments. This number is currently limited
1236 // by the maximum number of elements in the tuple implementation used by Google
1237 // Test.
1238 //
1239 // Example:
1240 //
1241 // This will instantiate tests in test case AnimalTest each one with
1242 // the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
1243 // tuple("dog", BLACK), and tuple("dog", WHITE):
1244 //
1245 // enum Color { BLACK, GRAY, WHITE };
1246 // class AnimalTest
1247 // : public testing::TestWithParam<tuple<const char*, Color> > {...};
1248 //
1249 // TEST_P(AnimalTest, AnimalLooksNice) {...}
1250 //
1251 // INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest,
1252 // Combine(Values("cat", "dog"),
1253 // Values(BLACK, WHITE)));
1254 //
1255 // This will instantiate tests in FlagDependentTest with all variations of two
1256 // Boolean flags:
1257 //
1258 // class FlagDependentTest
1259 // : public testing::TestWithParam<tuple<bool, bool> > {
1260 // virtual void SetUp() {
1261 // // Assigns external_flag_1 and external_flag_2 values from the tuple.
1262 // tie(external_flag_1, external_flag_2) = GetParam();
1263 // }
1264 // };
1265 //
1266 // TEST_P(FlagDependentTest, TestFeature1) {
1267 // // Test your code using external_flag_1 and external_flag_2 here.
1268 // }
1269 // INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest,
1270 // Combine(Bool(), Bool()));
1271 //
1272 template <typename Generator1, typename Generator2>
1273 internal::CartesianProductHolder2<Generator1, Generator2> Combine(
1274 const Generator1& g1, const Generator2& g2) {
1275 return internal::CartesianProductHolder2<Generator1, Generator2>(
1276 g1, g2);
1277 }
1278
1279 template <typename Generator1, typename Generator2, typename Generator3>
1280 internal::CartesianProductHolder3<Generator1, Generator2, Generator3> Combine(
1281 const Generator1& g1, const Generator2& g2, const Generator3& g3) {
1282 return internal::CartesianProductHolder3<Generator1, Generator2, Generator3>(
1283 g1, g2, g3);
1284 }
1285
1286 template <typename Generator1, typename Generator2, typename Generator3,
1287 typename Generator4>
1288 internal::CartesianProductHolder4<Generator1, Generator2, Generator3,
1289 Generator4> Combine(
1290 const Generator1& g1, const Generator2& g2, const Generator3& g3,
1291 const Generator4& g4) {
1292 return internal::CartesianProductHolder4<Generator1, Generator2, Generator3,
1293 Generator4>(
1294 g1, g2, g3, g4);
1295 }
1296
1297 template <typename Generator1, typename Generator2, typename Generator3,
1298 typename Generator4, typename Generator5>
1299 internal::CartesianProductHolder5<Generator1, Generator2, Generator3,
1300 Generator4, Generator5> Combine(
1301 const Generator1& g1, const Generator2& g2, const Generator3& g3,
1302 const Generator4& g4, const Generator5& g5) {
1303 return internal::CartesianProductHolder5<Generator1, Generator2, Generator3,
1304 Generator4, Generator5>(
1305 g1, g2, g3, g4, g5);
1306 }
1307
1308 template <typename Generator1, typename Generator2, typename Generator3,
1309 typename Generator4, typename Generator5, typename Generator6>
1310 internal::CartesianProductHolder6<Generator1, Generator2, Generator3,
1311 Generator4, Generator5, Generator6> Combine(
1312 const Generator1& g1, const Generator2& g2, const Generator3& g3,
1313 const Generator4& g4, const Generator5& g5, const Generator6& g6) {
1314 return internal::CartesianProductHolder6<Generator1, Generator2, Generator3,
1315 Generator4, Generator5, Generator6>(
1316 g1, g2, g3, g4, g5, g6);
1317 }
1318
1319 template <typename Generator1, typename Generator2, typename Generator3,
1320 typename Generator4, typename Generator5, typename Generator6,
1321 typename Generator7>
1322 internal::CartesianProductHolder7<Generator1, Generator2, Generator3,
1323 Generator4, Generator5, Generator6, Generator7> Combine(
1324 const Generator1& g1, const Generator2& g2, const Generator3& g3,
1325 const Generator4& g4, const Generator5& g5, const Generator6& g6,
1326 const Generator7& g7) {
1327 return internal::CartesianProductHolder7<Generator1, Generator2, Generator3,
1328 Generator4, Generator5, Generator6, Generator7>(
1329 g1, g2, g3, g4, g5, g6, g7);
1330 }
1331
1332 template <typename Generator1, typename Generator2, typename Generator3,
1333 typename Generator4, typename Generator5, typename Generator6,
1334 typename Generator7, typename Generator8>
1335 internal::CartesianProductHolder8<Generator1, Generator2, Generator3,
1336 Generator4, Generator5, Generator6, Generator7, Generator8> Combine(
1337 const Generator1& g1, const Generator2& g2, const Generator3& g3,
1338 const Generator4& g4, const Generator5& g5, const Generator6& g6,
1339 const Generator7& g7, const Generator8& g8) {
1340 return internal::CartesianProductHolder8<Generator1, Generator2, Generator3,
1341 Generator4, Generator5, Generator6, Generator7, Generator8>(
1342 g1, g2, g3, g4, g5, g6, g7, g8);
1343 }
1344
1345 template <typename Generator1, typename Generator2, typename Generator3,
1346 typename Generator4, typename Generator5, typename Generator6,
1347 typename Generator7, typename Generator8, typename Generator9>
1348 internal::CartesianProductHolder9<Generator1, Generator2, Generator3,
1349 Generator4, Generator5, Generator6, Generator7, Generator8,
1350 Generator9> Combine(
1351 const Generator1& g1, const Generator2& g2, const Generator3& g3,
1352 const Generator4& g4, const Generator5& g5, const Generator6& g6,
1353 const Generator7& g7, const Generator8& g8, const Generator9& g9) {
1354 return internal::CartesianProductHolder9<Generator1, Generator2, Generator3,
1355 Generator4, Generator5, Generator6, Generator7, Generator8, Generator9>(
1356 g1, g2, g3, g4, g5, g6, g7, g8, g9);
1357 }
1358
1359 template <typename Generator1, typename Generator2, typename Generator3,
1360 typename Generator4, typename Generator5, typename Generator6,
1361 typename Generator7, typename Generator8, typename Generator9,
1362 typename Generator10>
1363 internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
1364 Generator4, Generator5, Generator6, Generator7, Generator8, Generator9,
1365 Generator10> Combine(
1366 const Generator1& g1, const Generator2& g2, const Generator3& g3,
1367 const Generator4& g4, const Generator5& g5, const Generator6& g6,
1368 const Generator7& g7, const Generator8& g8, const Generator9& g9,
1369 const Generator10& g10) {
1370 return internal::CartesianProductHolder10<Generator1, Generator2, Generator3,
1371 Generator4, Generator5, Generator6, Generator7, Generator8, Generator9,
1372 Generator10>(
1373 g1, g2, g3, g4, g5, g6, g7, g8, g9, g10);
1374 }
1375 # endif // GTEST_HAS_COMBINE
1376
1377
1378
1379 # define TEST_P(test_case_name, test_name) \
1380 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
1381 : public test_case_name { \
1382 public: \
1383 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
1384 virtual void TestBody(); \
1385 private: \
1386 static int AddToRegistry() { \
1387 ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
1388 GetTestCasePatternHolder<test_case_name>(\
1389 #test_case_name, __FILE__, __LINE__)->AddTestPattern(\
1390 #test_case_name, \
1391 #test_name, \
1392 new ::testing::internal::TestMetaFactory< \
1393 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \
1394 return 0; \
1395 } \
1396 static int gtest_registering_dummy_; \
1397 GTEST_DISALLOW_COPY_AND_ASSIGN_(\
1398 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
1399 }; \
1400 int GTEST_TEST_CLASS_NAME_(test_case_name, \
1401 test_name)::gtest_registering_dummy_ = \
1402 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
1403 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
1404
1405 # define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
1406 ::testing::internal::ParamGenerator<test_case_name::ParamType> \
1407 gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
1408 int gtest_##prefix##test_case_name##_dummy_ = \
1409 ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
1410 GetTestCasePatternHolder<test_case_name>(\
1411 #test_case_name, __FILE__, __LINE__)->AddTestCaseInstantiation(\
1412 #prefix, \
1413 &gtest_##prefix##test_case_name##_EvalGenerator_, \
1414 __FILE__, __LINE__)
1415
1416 } // namespace testing
1417
1418 #endif // GTEST_HAS_PARAM_TEST
1419
1420 #endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
0 $$ -*- mode: c++; -*-
1 $var n = 50 $$ Maximum length of Values arguments we want to support.
2 $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support.
3 // Copyright 2008, Google Inc.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 // * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 //
32 // Authors: vladl@google.com (Vlad Losev)
33 //
34 // Macros and functions for implementing parameterized tests
35 // in Google C++ Testing Framework (Google Test)
36 //
37 // This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
38 //
39 #ifndef GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
40 #define GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
41
42
43 // Value-parameterized tests allow you to test your code with different
44 // parameters without writing multiple copies of the same test.
45 //
46 // Here is how you use value-parameterized tests:
47
48 #if 0
49
50 // To write value-parameterized tests, first you should define a fixture
51 // class. It is usually derived from testing::TestWithParam<T> (see below for
52 // another inheritance scheme that's sometimes useful in more complicated
53 // class hierarchies), where the type of your parameter values.
54 // TestWithParam<T> is itself derived from testing::Test. T can be any
55 // copyable type. If it's a raw pointer, you are responsible for managing the
56 // lifespan of the pointed values.
57
58 class FooTest : public ::testing::TestWithParam<const char*> {
59 // You can implement all the usual class fixture members here.
60 };
61
62 // Then, use the TEST_P macro to define as many parameterized tests
63 // for this fixture as you want. The _P suffix is for "parameterized"
64 // or "pattern", whichever you prefer to think.
65
66 TEST_P(FooTest, DoesBlah) {
67 // Inside a test, access the test parameter with the GetParam() method
68 // of the TestWithParam<T> class:
69 EXPECT_TRUE(foo.Blah(GetParam()));
70 ...
71 }
72
73 TEST_P(FooTest, HasBlahBlah) {
74 ...
75 }
76
77 // Finally, you can use INSTANTIATE_TEST_CASE_P to instantiate the test
78 // case with any set of parameters you want. Google Test defines a number
79 // of functions for generating test parameters. They return what we call
80 // (surprise!) parameter generators. Here is a summary of them, which
81 // are all in the testing namespace:
82 //
83 //
84 // Range(begin, end [, step]) - Yields values {begin, begin+step,
85 // begin+step+step, ...}. The values do not
86 // include end. step defaults to 1.
87 // Values(v1, v2, ..., vN) - Yields values {v1, v2, ..., vN}.
88 // ValuesIn(container) - Yields values from a C-style array, an STL
89 // ValuesIn(begin,end) container, or an iterator range [begin, end).
90 // Bool() - Yields sequence {false, true}.
91 // Combine(g1, g2, ..., gN) - Yields all combinations (the Cartesian product
92 // for the math savvy) of the values generated
93 // by the N generators.
94 //
95 // For more details, see comments at the definitions of these functions below
96 // in this file.
97 //
98 // The following statement will instantiate tests from the FooTest test case
99 // each with parameter values "meeny", "miny", and "moe".
100
101 INSTANTIATE_TEST_CASE_P(InstantiationName,
102 FooTest,
103 Values("meeny", "miny", "moe"));
104
105 // To distinguish different instances of the pattern, (yes, you
106 // can instantiate it more then once) the first argument to the
107 // INSTANTIATE_TEST_CASE_P macro is a prefix that will be added to the
108 // actual test case name. Remember to pick unique prefixes for different
109 // instantiations. The tests from the instantiation above will have
110 // these names:
111 //
112 // * InstantiationName/FooTest.DoesBlah/0 for "meeny"
113 // * InstantiationName/FooTest.DoesBlah/1 for "miny"
114 // * InstantiationName/FooTest.DoesBlah/2 for "moe"
115 // * InstantiationName/FooTest.HasBlahBlah/0 for "meeny"
116 // * InstantiationName/FooTest.HasBlahBlah/1 for "miny"
117 // * InstantiationName/FooTest.HasBlahBlah/2 for "moe"
118 //
119 // You can use these names in --gtest_filter.
120 //
121 // This statement will instantiate all tests from FooTest again, each
122 // with parameter values "cat" and "dog":
123
124 const char* pets[] = {"cat", "dog"};
125 INSTANTIATE_TEST_CASE_P(AnotherInstantiationName, FooTest, ValuesIn(pets));
126
127 // The tests from the instantiation above will have these names:
128 //
129 // * AnotherInstantiationName/FooTest.DoesBlah/0 for "cat"
130 // * AnotherInstantiationName/FooTest.DoesBlah/1 for "dog"
131 // * AnotherInstantiationName/FooTest.HasBlahBlah/0 for "cat"
132 // * AnotherInstantiationName/FooTest.HasBlahBlah/1 for "dog"
133 //
134 // Please note that INSTANTIATE_TEST_CASE_P will instantiate all tests
135 // in the given test case, whether their definitions come before or
136 // AFTER the INSTANTIATE_TEST_CASE_P statement.
137 //
138 // Please also note that generator expressions (including parameters to the
139 // generators) are evaluated in InitGoogleTest(), after main() has started.
140 // This allows the user on one hand, to adjust generator parameters in order
141 // to dynamically determine a set of tests to run and on the other hand,
142 // give the user a chance to inspect the generated tests with Google Test
143 // reflection API before RUN_ALL_TESTS() is executed.
144 //
145 // You can see samples/sample7_unittest.cc and samples/sample8_unittest.cc
146 // for more examples.
147 //
148 // In the future, we plan to publish the API for defining new parameter
149 // generators. But for now this interface remains part of the internal
150 // implementation and is subject to change.
151 //
152 //
153 // A parameterized test fixture must be derived from testing::Test and from
154 // testing::WithParamInterface<T>, where T is the type of the parameter
155 // values. Inheriting from TestWithParam<T> satisfies that requirement because
156 // TestWithParam<T> inherits from both Test and WithParamInterface. In more
157 // complicated hierarchies, however, it is occasionally useful to inherit
158 // separately from Test and WithParamInterface. For example:
159
160 class BaseTest : public ::testing::Test {
161 // You can inherit all the usual members for a non-parameterized test
162 // fixture here.
163 };
164
165 class DerivedTest : public BaseTest, public ::testing::WithParamInterface<int> {
166 // The usual test fixture members go here too.
167 };
168
169 TEST_F(BaseTest, HasFoo) {
170 // This is an ordinary non-parameterized test.
171 }
172
173 TEST_P(DerivedTest, DoesBlah) {
174 // GetParam works just the same here as if you inherit from TestWithParam.
175 EXPECT_TRUE(foo.Blah(GetParam()));
176 }
177
178 #endif // 0
179
180 #include "gtest/internal/gtest-port.h"
181
182 #if !GTEST_OS_SYMBIAN
183 # include <utility>
184 #endif
185
186 // scripts/fuse_gtest.py depends on gtest's own header being #included
187 // *unconditionally*. Therefore these #includes cannot be moved
188 // inside #if GTEST_HAS_PARAM_TEST.
189 #include "gtest/internal/gtest-internal.h"
190 #include "gtest/internal/gtest-param-util.h"
191 #include "gtest/internal/gtest-param-util-generated.h"
192
193 #if GTEST_HAS_PARAM_TEST
194
195 namespace testing {
196
197 // Functions producing parameter generators.
198 //
199 // Google Test uses these generators to produce parameters for value-
200 // parameterized tests. When a parameterized test case is instantiated
201 // with a particular generator, Google Test creates and runs tests
202 // for each element in the sequence produced by the generator.
203 //
204 // In the following sample, tests from test case FooTest are instantiated
205 // each three times with parameter values 3, 5, and 8:
206 //
207 // class FooTest : public TestWithParam<int> { ... };
208 //
209 // TEST_P(FooTest, TestThis) {
210 // }
211 // TEST_P(FooTest, TestThat) {
212 // }
213 // INSTANTIATE_TEST_CASE_P(TestSequence, FooTest, Values(3, 5, 8));
214 //
215
216 // Range() returns generators providing sequences of values in a range.
217 //
218 // Synopsis:
219 // Range(start, end)
220 // - returns a generator producing a sequence of values {start, start+1,
221 // start+2, ..., }.
222 // Range(start, end, step)
223 // - returns a generator producing a sequence of values {start, start+step,
224 // start+step+step, ..., }.
225 // Notes:
226 // * The generated sequences never include end. For example, Range(1, 5)
227 // returns a generator producing a sequence {1, 2, 3, 4}. Range(1, 9, 2)
228 // returns a generator producing {1, 3, 5, 7}.
229 // * start and end must have the same type. That type may be any integral or
230 // floating-point type or a user defined type satisfying these conditions:
231 // * It must be assignable (have operator=() defined).
232 // * It must have operator+() (operator+(int-compatible type) for
233 // two-operand version).
234 // * It must have operator<() defined.
235 // Elements in the resulting sequences will also have that type.
236 // * Condition start < end must be satisfied in order for resulting sequences
237 // to contain any elements.
238 //
239 template <typename T, typename IncrementT>
240 internal::ParamGenerator<T> Range(T start, T end, IncrementT step) {
241 return internal::ParamGenerator<T>(
242 new internal::RangeGenerator<T, IncrementT>(start, end, step));
243 }
244
245 template <typename T>
246 internal::ParamGenerator<T> Range(T start, T end) {
247 return Range(start, end, 1);
248 }
249
250 // ValuesIn() function allows generation of tests with parameters coming from
251 // a container.
252 //
253 // Synopsis:
254 // ValuesIn(const T (&array)[N])
255 // - returns a generator producing sequences with elements from
256 // a C-style array.
257 // ValuesIn(const Container& container)
258 // - returns a generator producing sequences with elements from
259 // an STL-style container.
260 // ValuesIn(Iterator begin, Iterator end)
261 // - returns a generator producing sequences with elements from
262 // a range [begin, end) defined by a pair of STL-style iterators. These
263 // iterators can also be plain C pointers.
264 //
265 // Please note that ValuesIn copies the values from the containers
266 // passed in and keeps them to generate tests in RUN_ALL_TESTS().
267 //
268 // Examples:
269 //
270 // This instantiates tests from test case StringTest
271 // each with C-string values of "foo", "bar", and "baz":
272 //
273 // const char* strings[] = {"foo", "bar", "baz"};
274 // INSTANTIATE_TEST_CASE_P(StringSequence, SrtingTest, ValuesIn(strings));
275 //
276 // This instantiates tests from test case StlStringTest
277 // each with STL strings with values "a" and "b":
278 //
279 // ::std::vector< ::std::string> GetParameterStrings() {
280 // ::std::vector< ::std::string> v;
281 // v.push_back("a");
282 // v.push_back("b");
283 // return v;
284 // }
285 //
286 // INSTANTIATE_TEST_CASE_P(CharSequence,
287 // StlStringTest,
288 // ValuesIn(GetParameterStrings()));
289 //
290 //
291 // This will also instantiate tests from CharTest
292 // each with parameter values 'a' and 'b':
293 //
294 // ::std::list<char> GetParameterChars() {
295 // ::std::list<char> list;
296 // list.push_back('a');
297 // list.push_back('b');
298 // return list;
299 // }
300 // ::std::list<char> l = GetParameterChars();
301 // INSTANTIATE_TEST_CASE_P(CharSequence2,
302 // CharTest,
303 // ValuesIn(l.begin(), l.end()));
304 //
305 template <typename ForwardIterator>
306 internal::ParamGenerator<
307 typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
308 ValuesIn(ForwardIterator begin, ForwardIterator end) {
309 typedef typename ::testing::internal::IteratorTraits<ForwardIterator>
310 ::value_type ParamType;
311 return internal::ParamGenerator<ParamType>(
312 new internal::ValuesInIteratorRangeGenerator<ParamType>(begin, end));
313 }
314
315 template <typename T, size_t N>
316 internal::ParamGenerator<T> ValuesIn(const T (&array)[N]) {
317 return ValuesIn(array, array + N);
318 }
319
320 template <class Container>
321 internal::ParamGenerator<typename Container::value_type> ValuesIn(
322 const Container& container) {
323 return ValuesIn(container.begin(), container.end());
324 }
325
326 // Values() allows generating tests from explicitly specified list of
327 // parameters.
328 //
329 // Synopsis:
330 // Values(T v1, T v2, ..., T vN)
331 // - returns a generator producing sequences with elements v1, v2, ..., vN.
332 //
333 // For example, this instantiates tests from test case BarTest each
334 // with values "one", "two", and "three":
335 //
336 // INSTANTIATE_TEST_CASE_P(NumSequence, BarTest, Values("one", "two", "three"));
337 //
338 // This instantiates tests from test case BazTest each with values 1, 2, 3.5.
339 // The exact type of values will depend on the type of parameter in BazTest.
340 //
341 // INSTANTIATE_TEST_CASE_P(FloatingNumbers, BazTest, Values(1, 2, 3.5));
342 //
343 // Currently, Values() supports from 1 to $n parameters.
344 //
345 $range i 1..n
346 $for i [[
347 $range j 1..i
348
349 template <$for j, [[typename T$j]]>
350 internal::ValueArray$i<$for j, [[T$j]]> Values($for j, [[T$j v$j]]) {
351 return internal::ValueArray$i<$for j, [[T$j]]>($for j, [[v$j]]);
352 }
353
354 ]]
355
356 // Bool() allows generating tests with parameters in a set of (false, true).
357 //
358 // Synopsis:
359 // Bool()
360 // - returns a generator producing sequences with elements {false, true}.
361 //
362 // It is useful when testing code that depends on Boolean flags. Combinations
363 // of multiple flags can be tested when several Bool()'s are combined using
364 // Combine() function.
365 //
366 // In the following example all tests in the test case FlagDependentTest
367 // will be instantiated twice with parameters false and true.
368 //
369 // class FlagDependentTest : public testing::TestWithParam<bool> {
370 // virtual void SetUp() {
371 // external_flag = GetParam();
372 // }
373 // }
374 // INSTANTIATE_TEST_CASE_P(BoolSequence, FlagDependentTest, Bool());
375 //
376 inline internal::ParamGenerator<bool> Bool() {
377 return Values(false, true);
378 }
379
380 # if GTEST_HAS_COMBINE
381 // Combine() allows the user to combine two or more sequences to produce
382 // values of a Cartesian product of those sequences' elements.
383 //
384 // Synopsis:
385 // Combine(gen1, gen2, ..., genN)
386 // - returns a generator producing sequences with elements coming from
387 // the Cartesian product of elements from the sequences generated by
388 // gen1, gen2, ..., genN. The sequence elements will have a type of
389 // tuple<T1, T2, ..., TN> where T1, T2, ..., TN are the types
390 // of elements from sequences produces by gen1, gen2, ..., genN.
391 //
392 // Combine can have up to $maxtuple arguments. This number is currently limited
393 // by the maximum number of elements in the tuple implementation used by Google
394 // Test.
395 //
396 // Example:
397 //
398 // This will instantiate tests in test case AnimalTest each one with
399 // the parameter values tuple("cat", BLACK), tuple("cat", WHITE),
400 // tuple("dog", BLACK), and tuple("dog", WHITE):
401 //
402 // enum Color { BLACK, GRAY, WHITE };
403 // class AnimalTest
404 // : public testing::TestWithParam<tuple<const char*, Color> > {...};
405 //
406 // TEST_P(AnimalTest, AnimalLooksNice) {...}
407 //
408 // INSTANTIATE_TEST_CASE_P(AnimalVariations, AnimalTest,
409 // Combine(Values("cat", "dog"),
410 // Values(BLACK, WHITE)));
411 //
412 // This will instantiate tests in FlagDependentTest with all variations of two
413 // Boolean flags:
414 //
415 // class FlagDependentTest
416 // : public testing::TestWithParam<tuple<bool, bool> > {
417 // virtual void SetUp() {
418 // // Assigns external_flag_1 and external_flag_2 values from the tuple.
419 // tie(external_flag_1, external_flag_2) = GetParam();
420 // }
421 // };
422 //
423 // TEST_P(FlagDependentTest, TestFeature1) {
424 // // Test your code using external_flag_1 and external_flag_2 here.
425 // }
426 // INSTANTIATE_TEST_CASE_P(TwoBoolSequence, FlagDependentTest,
427 // Combine(Bool(), Bool()));
428 //
429 $range i 2..maxtuple
430 $for i [[
431 $range j 1..i
432
433 template <$for j, [[typename Generator$j]]>
434 internal::CartesianProductHolder$i<$for j, [[Generator$j]]> Combine(
435 $for j, [[const Generator$j& g$j]]) {
436 return internal::CartesianProductHolder$i<$for j, [[Generator$j]]>(
437 $for j, [[g$j]]);
438 }
439
440 ]]
441 # endif // GTEST_HAS_COMBINE
442
443
444
445 # define TEST_P(test_case_name, test_name) \
446 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
447 : public test_case_name { \
448 public: \
449 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {} \
450 virtual void TestBody(); \
451 private: \
452 static int AddToRegistry() { \
453 ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
454 GetTestCasePatternHolder<test_case_name>(\
455 #test_case_name, __FILE__, __LINE__)->AddTestPattern(\
456 #test_case_name, \
457 #test_name, \
458 new ::testing::internal::TestMetaFactory< \
459 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>()); \
460 return 0; \
461 } \
462 static int gtest_registering_dummy_; \
463 GTEST_DISALLOW_COPY_AND_ASSIGN_(\
464 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)); \
465 }; \
466 int GTEST_TEST_CLASS_NAME_(test_case_name, \
467 test_name)::gtest_registering_dummy_ = \
468 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::AddToRegistry(); \
469 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
470
471 # define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator) \
472 ::testing::internal::ParamGenerator<test_case_name::ParamType> \
473 gtest_##prefix##test_case_name##_EvalGenerator_() { return generator; } \
474 int gtest_##prefix##test_case_name##_dummy_ = \
475 ::testing::UnitTest::GetInstance()->parameterized_test_registry(). \
476 GetTestCasePatternHolder<test_case_name>(\
477 #test_case_name, __FILE__, __LINE__)->AddTestCaseInstantiation(\
478 #prefix, \
479 &gtest_##prefix##test_case_name##_EvalGenerator_, \
480 __FILE__, __LINE__)
481
482 } // namespace testing
483
484 #endif // GTEST_HAS_PARAM_TEST
485
486 #endif // GTEST_INCLUDE_GTEST_GTEST_PARAM_TEST_H_
0 // Copyright 2007, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30
31 // Google Test - The Google C++ Testing Framework
32 //
33 // This file implements a universal value printer that can print a
34 // value of any type T:
35 //
36 // void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
37 //
38 // A user can teach this function how to print a class type T by
39 // defining either operator<<() or PrintTo() in the namespace that
40 // defines T. More specifically, the FIRST defined function in the
41 // following list will be used (assuming T is defined in namespace
42 // foo):
43 //
44 // 1. foo::PrintTo(const T&, ostream*)
45 // 2. operator<<(ostream&, const T&) defined in either foo or the
46 // global namespace.
47 //
48 // If none of the above is defined, it will print the debug string of
49 // the value if it is a protocol buffer, or print the raw bytes in the
50 // value otherwise.
51 //
52 // To aid debugging: when T is a reference type, the address of the
53 // value is also printed; when T is a (const) char pointer, both the
54 // pointer value and the NUL-terminated string it points to are
55 // printed.
56 //
57 // We also provide some convenient wrappers:
58 //
59 // // Prints a value to a string. For a (const or not) char
60 // // pointer, the NUL-terminated string (but not the pointer) is
61 // // printed.
62 // std::string ::testing::PrintToString(const T& value);
63 //
64 // // Prints a value tersely: for a reference type, the referenced
65 // // value (but not the address) is printed; for a (const or not) char
66 // // pointer, the NUL-terminated string (but not the pointer) is
67 // // printed.
68 // void ::testing::internal::UniversalTersePrint(const T& value, ostream*);
69 //
70 // // Prints value using the type inferred by the compiler. The difference
71 // // from UniversalTersePrint() is that this function prints both the
72 // // pointer and the NUL-terminated string for a (const or not) char pointer.
73 // void ::testing::internal::UniversalPrint(const T& value, ostream*);
74 //
75 // // Prints the fields of a tuple tersely to a string vector, one
76 // // element for each field. Tuple support must be enabled in
77 // // gtest-port.h.
78 // std::vector<string> UniversalTersePrintTupleFieldsToStrings(
79 // const Tuple& value);
80 //
81 // Known limitation:
82 //
83 // The print primitives print the elements of an STL-style container
84 // using the compiler-inferred type of *iter where iter is a
85 // const_iterator of the container. When const_iterator is an input
86 // iterator but not a forward iterator, this inferred type may not
87 // match value_type, and the print output may be incorrect. In
88 // practice, this is rarely a problem as for most containers
89 // const_iterator is a forward iterator. We'll fix this if there's an
90 // actual need for it. Note that this fix cannot rely on value_type
91 // being defined as many user-defined container types don't have
92 // value_type.
93
94 #ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
95 #define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
96
97 #include <ostream> // NOLINT
98 #include <sstream>
99 #include <string>
100 #include <utility>
101 #include <vector>
102 #include "gtest/internal/gtest-port.h"
103 #include "gtest/internal/gtest-internal.h"
104
105 namespace testing {
106
107 // Definitions in the 'internal' and 'internal2' name spaces are
108 // subject to change without notice. DO NOT USE THEM IN USER CODE!
109 namespace internal2 {
110
111 // Prints the given number of bytes in the given object to the given
112 // ostream.
113 GTEST_API_ void PrintBytesInObjectTo(const unsigned char* obj_bytes,
114 size_t count,
115 ::std::ostream* os);
116
117 // For selecting which printer to use when a given type has neither <<
118 // nor PrintTo().
119 enum TypeKind {
120 kProtobuf, // a protobuf type
121 kConvertibleToInteger, // a type implicitly convertible to BiggestInt
122 // (e.g. a named or unnamed enum type)
123 kOtherType // anything else
124 };
125
126 // TypeWithoutFormatter<T, kTypeKind>::PrintValue(value, os) is called
127 // by the universal printer to print a value of type T when neither
128 // operator<< nor PrintTo() is defined for T, where kTypeKind is the
129 // "kind" of T as defined by enum TypeKind.
130 template <typename T, TypeKind kTypeKind>
131 class TypeWithoutFormatter {
132 public:
133 // This default version is called when kTypeKind is kOtherType.
134 static void PrintValue(const T& value, ::std::ostream* os) {
135 PrintBytesInObjectTo(reinterpret_cast<const unsigned char*>(&value),
136 sizeof(value), os);
137 }
138 };
139
140 // We print a protobuf using its ShortDebugString() when the string
141 // doesn't exceed this many characters; otherwise we print it using
142 // DebugString() for better readability.
143 const size_t kProtobufOneLinerMaxLength = 50;
144
145 template <typename T>
146 class TypeWithoutFormatter<T, kProtobuf> {
147 public:
148 static void PrintValue(const T& value, ::std::ostream* os) {
149 const ::testing::internal::string short_str = value.ShortDebugString();
150 const ::testing::internal::string pretty_str =
151 short_str.length() <= kProtobufOneLinerMaxLength ?
152 short_str : ("\n" + value.DebugString());
153 *os << ("<" + pretty_str + ">");
154 }
155 };
156
157 template <typename T>
158 class TypeWithoutFormatter<T, kConvertibleToInteger> {
159 public:
160 // Since T has no << operator or PrintTo() but can be implicitly
161 // converted to BiggestInt, we print it as a BiggestInt.
162 //
163 // Most likely T is an enum type (either named or unnamed), in which
164 // case printing it as an integer is the desired behavior. In case
165 // T is not an enum, printing it as an integer is the best we can do
166 // given that it has no user-defined printer.
167 static void PrintValue(const T& value, ::std::ostream* os) {
168 const internal::BiggestInt kBigInt = value;
169 *os << kBigInt;
170 }
171 };
172
173 // Prints the given value to the given ostream. If the value is a
174 // protocol message, its debug string is printed; if it's an enum or
175 // of a type implicitly convertible to BiggestInt, it's printed as an
176 // integer; otherwise the bytes in the value are printed. This is
177 // what UniversalPrinter<T>::Print() does when it knows nothing about
178 // type T and T has neither << operator nor PrintTo().
179 //
180 // A user can override this behavior for a class type Foo by defining
181 // a << operator in the namespace where Foo is defined.
182 //
183 // We put this operator in namespace 'internal2' instead of 'internal'
184 // to simplify the implementation, as much code in 'internal' needs to
185 // use << in STL, which would conflict with our own << were it defined
186 // in 'internal'.
187 //
188 // Note that this operator<< takes a generic std::basic_ostream<Char,
189 // CharTraits> type instead of the more restricted std::ostream. If
190 // we define it to take an std::ostream instead, we'll get an
191 // "ambiguous overloads" compiler error when trying to print a type
192 // Foo that supports streaming to std::basic_ostream<Char,
193 // CharTraits>, as the compiler cannot tell whether
194 // operator<<(std::ostream&, const T&) or
195 // operator<<(std::basic_stream<Char, CharTraits>, const Foo&) is more
196 // specific.
197 template <typename Char, typename CharTraits, typename T>
198 ::std::basic_ostream<Char, CharTraits>& operator<<(
199 ::std::basic_ostream<Char, CharTraits>& os, const T& x) {
200 TypeWithoutFormatter<T,
201 (internal::IsAProtocolMessage<T>::value ? kProtobuf :
202 internal::ImplicitlyConvertible<const T&, internal::BiggestInt>::value ?
203 kConvertibleToInteger : kOtherType)>::PrintValue(x, &os);
204 return os;
205 }
206
207 } // namespace internal2
208 } // namespace testing
209
210 // This namespace MUST NOT BE NESTED IN ::testing, or the name look-up
211 // magic needed for implementing UniversalPrinter won't work.
212 namespace testing_internal {
213
214 // Used to print a value that is not an STL-style container when the
215 // user doesn't define PrintTo() for it.
216 template <typename T>
217 void DefaultPrintNonContainerTo(const T& value, ::std::ostream* os) {
218 // With the following statement, during unqualified name lookup,
219 // testing::internal2::operator<< appears as if it was declared in
220 // the nearest enclosing namespace that contains both
221 // ::testing_internal and ::testing::internal2, i.e. the global
222 // namespace. For more details, refer to the C++ Standard section
223 // 7.3.4-1 [namespace.udir]. This allows us to fall back onto
224 // testing::internal2::operator<< in case T doesn't come with a <<
225 // operator.
226 //
227 // We cannot write 'using ::testing::internal2::operator<<;', which
228 // gcc 3.3 fails to compile due to a compiler bug.
229 using namespace ::testing::internal2; // NOLINT
230
231 // Assuming T is defined in namespace foo, in the next statement,
232 // the compiler will consider all of:
233 //
234 // 1. foo::operator<< (thanks to Koenig look-up),
235 // 2. ::operator<< (as the current namespace is enclosed in ::),
236 // 3. testing::internal2::operator<< (thanks to the using statement above).
237 //
238 // The operator<< whose type matches T best will be picked.
239 //
240 // We deliberately allow #2 to be a candidate, as sometimes it's
241 // impossible to define #1 (e.g. when foo is ::std, defining
242 // anything in it is undefined behavior unless you are a compiler
243 // vendor.).
244 *os << value;
245 }
246
247 } // namespace testing_internal
248
249 namespace testing {
250 namespace internal {
251
252 // UniversalPrinter<T>::Print(value, ostream_ptr) prints the given
253 // value to the given ostream. The caller must ensure that
254 // 'ostream_ptr' is not NULL, or the behavior is undefined.
255 //
256 // We define UniversalPrinter as a class template (as opposed to a
257 // function template), as we need to partially specialize it for
258 // reference types, which cannot be done with function templates.
259 template <typename T>
260 class UniversalPrinter;
261
262 template <typename T>
263 void UniversalPrint(const T& value, ::std::ostream* os);
264
265 // Used to print an STL-style container when the user doesn't define
266 // a PrintTo() for it.
267 template <typename C>
268 void DefaultPrintTo(IsContainer /* dummy */,
269 false_type /* is not a pointer */,
270 const C& container, ::std::ostream* os) {
271 const size_t kMaxCount = 32; // The maximum number of elements to print.
272 *os << '{';
273 size_t count = 0;
274 for (typename C::const_iterator it = container.begin();
275 it != container.end(); ++it, ++count) {
276 if (count > 0) {
277 *os << ',';
278 if (count == kMaxCount) { // Enough has been printed.
279 *os << " ...";
280 break;
281 }
282 }
283 *os << ' ';
284 // We cannot call PrintTo(*it, os) here as PrintTo() doesn't
285 // handle *it being a native array.
286 internal::UniversalPrint(*it, os);
287 }
288
289 if (count > 0) {
290 *os << ' ';
291 }
292 *os << '}';
293 }
294
295 // Used to print a pointer that is neither a char pointer nor a member
296 // pointer, when the user doesn't define PrintTo() for it. (A member
297 // variable pointer or member function pointer doesn't really point to
298 // a location in the address space. Their representation is
299 // implementation-defined. Therefore they will be printed as raw
300 // bytes.)
301 template <typename T>
302 void DefaultPrintTo(IsNotContainer /* dummy */,
303 true_type /* is a pointer */,
304 T* p, ::std::ostream* os) {
305 if (p == NULL) {
306 *os << "NULL";
307 } else {
308 // C++ doesn't allow casting from a function pointer to any object
309 // pointer.
310 //
311 // IsTrue() silences warnings: "Condition is always true",
312 // "unreachable code".
313 if (IsTrue(ImplicitlyConvertible<T*, const void*>::value)) {
314 // T is not a function type. We just call << to print p,
315 // relying on ADL to pick up user-defined << for their pointer
316 // types, if any.
317 *os << p;
318 } else {
319 // T is a function type, so '*os << p' doesn't do what we want
320 // (it just prints p as bool). We want to print p as a const
321 // void*. However, we cannot cast it to const void* directly,
322 // even using reinterpret_cast, as earlier versions of gcc
323 // (e.g. 3.4.5) cannot compile the cast when p is a function
324 // pointer. Casting to UInt64 first solves the problem.
325 *os << reinterpret_cast<const void*>(
326 reinterpret_cast<internal::UInt64>(p));
327 }
328 }
329 }
330
331 // Used to print a non-container, non-pointer value when the user
332 // doesn't define PrintTo() for it.
333 template <typename T>
334 void DefaultPrintTo(IsNotContainer /* dummy */,
335 false_type /* is not a pointer */,
336 const T& value, ::std::ostream* os) {
337 ::testing_internal::DefaultPrintNonContainerTo(value, os);
338 }
339
340 // Prints the given value using the << operator if it has one;
341 // otherwise prints the bytes in it. This is what
342 // UniversalPrinter<T>::Print() does when PrintTo() is not specialized
343 // or overloaded for type T.
344 //
345 // A user can override this behavior for a class type Foo by defining
346 // an overload of PrintTo() in the namespace where Foo is defined. We
347 // give the user this option as sometimes defining a << operator for
348 // Foo is not desirable (e.g. the coding style may prevent doing it,
349 // or there is already a << operator but it doesn't do what the user
350 // wants).
351 template <typename T>
352 void PrintTo(const T& value, ::std::ostream* os) {
353 // DefaultPrintTo() is overloaded. The type of its first two
354 // arguments determine which version will be picked. If T is an
355 // STL-style container, the version for container will be called; if
356 // T is a pointer, the pointer version will be called; otherwise the
357 // generic version will be called.
358 //
359 // Note that we check for container types here, prior to we check
360 // for protocol message types in our operator<<. The rationale is:
361 //
362 // For protocol messages, we want to give people a chance to
363 // override Google Mock's format by defining a PrintTo() or
364 // operator<<. For STL containers, other formats can be
365 // incompatible with Google Mock's format for the container
366 // elements; therefore we check for container types here to ensure
367 // that our format is used.
368 //
369 // The second argument of DefaultPrintTo() is needed to bypass a bug
370 // in Symbian's C++ compiler that prevents it from picking the right
371 // overload between:
372 //
373 // PrintTo(const T& x, ...);
374 // PrintTo(T* x, ...);
375 DefaultPrintTo(IsContainerTest<T>(0), is_pointer<T>(), value, os);
376 }
377
378 // The following list of PrintTo() overloads tells
379 // UniversalPrinter<T>::Print() how to print standard types (built-in
380 // types, strings, plain arrays, and pointers).
381
382 // Overloads for various char types.
383 GTEST_API_ void PrintTo(unsigned char c, ::std::ostream* os);
384 GTEST_API_ void PrintTo(signed char c, ::std::ostream* os);
385 inline void PrintTo(char c, ::std::ostream* os) {
386 // When printing a plain char, we always treat it as unsigned. This
387 // way, the output won't be affected by whether the compiler thinks
388 // char is signed or not.
389 PrintTo(static_cast<unsigned char>(c), os);
390 }
391
392 // Overloads for other simple built-in types.
393 inline void PrintTo(bool x, ::std::ostream* os) {
394 *os << (x ? "true" : "false");
395 }
396
397 // Overload for wchar_t type.
398 // Prints a wchar_t as a symbol if it is printable or as its internal
399 // code otherwise and also as its decimal code (except for L'\0').
400 // The L'\0' char is printed as "L'\\0'". The decimal code is printed
401 // as signed integer when wchar_t is implemented by the compiler
402 // as a signed type and is printed as an unsigned integer when wchar_t
403 // is implemented as an unsigned type.
404 GTEST_API_ void PrintTo(wchar_t wc, ::std::ostream* os);
405
406 // Overloads for C strings.
407 GTEST_API_ void PrintTo(const char* s, ::std::ostream* os);
408 inline void PrintTo(char* s, ::std::ostream* os) {
409 PrintTo(ImplicitCast_<const char*>(s), os);
410 }
411
412 // signed/unsigned char is often used for representing binary data, so
413 // we print pointers to it as void* to be safe.
414 inline void PrintTo(const signed char* s, ::std::ostream* os) {
415 PrintTo(ImplicitCast_<const void*>(s), os);
416 }
417 inline void PrintTo(signed char* s, ::std::ostream* os) {
418 PrintTo(ImplicitCast_<const void*>(s), os);
419 }
420 inline void PrintTo(const unsigned char* s, ::std::ostream* os) {
421 PrintTo(ImplicitCast_<const void*>(s), os);
422 }
423 inline void PrintTo(unsigned char* s, ::std::ostream* os) {
424 PrintTo(ImplicitCast_<const void*>(s), os);
425 }
426
427 // MSVC can be configured to define wchar_t as a typedef of unsigned
428 // short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native
429 // type. When wchar_t is a typedef, defining an overload for const
430 // wchar_t* would cause unsigned short* be printed as a wide string,
431 // possibly causing invalid memory accesses.
432 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
433 // Overloads for wide C strings
434 GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os);
435 inline void PrintTo(wchar_t* s, ::std::ostream* os) {
436 PrintTo(ImplicitCast_<const wchar_t*>(s), os);
437 }
438 #endif
439
440 // Overload for C arrays. Multi-dimensional arrays are printed
441 // properly.
442
443 // Prints the given number of elements in an array, without printing
444 // the curly braces.
445 template <typename T>
446 void PrintRawArrayTo(const T a[], size_t count, ::std::ostream* os) {
447 UniversalPrint(a[0], os);
448 for (size_t i = 1; i != count; i++) {
449 *os << ", ";
450 UniversalPrint(a[i], os);
451 }
452 }
453
454 // Overloads for ::string and ::std::string.
455 #if GTEST_HAS_GLOBAL_STRING
456 GTEST_API_ void PrintStringTo(const ::string&s, ::std::ostream* os);
457 inline void PrintTo(const ::string& s, ::std::ostream* os) {
458 PrintStringTo(s, os);
459 }
460 #endif // GTEST_HAS_GLOBAL_STRING
461
462 GTEST_API_ void PrintStringTo(const ::std::string&s, ::std::ostream* os);
463 inline void PrintTo(const ::std::string& s, ::std::ostream* os) {
464 PrintStringTo(s, os);
465 }
466
467 // Overloads for ::wstring and ::std::wstring.
468 #if GTEST_HAS_GLOBAL_WSTRING
469 GTEST_API_ void PrintWideStringTo(const ::wstring&s, ::std::ostream* os);
470 inline void PrintTo(const ::wstring& s, ::std::ostream* os) {
471 PrintWideStringTo(s, os);
472 }
473 #endif // GTEST_HAS_GLOBAL_WSTRING
474
475 #if GTEST_HAS_STD_WSTRING
476 GTEST_API_ void PrintWideStringTo(const ::std::wstring&s, ::std::ostream* os);
477 inline void PrintTo(const ::std::wstring& s, ::std::ostream* os) {
478 PrintWideStringTo(s, os);
479 }
480 #endif // GTEST_HAS_STD_WSTRING
481
482 #if GTEST_HAS_TR1_TUPLE
483 // Overload for ::std::tr1::tuple. Needed for printing function arguments,
484 // which are packed as tuples.
485
486 // Helper function for printing a tuple. T must be instantiated with
487 // a tuple type.
488 template <typename T>
489 void PrintTupleTo(const T& t, ::std::ostream* os);
490
491 // Overloaded PrintTo() for tuples of various arities. We support
492 // tuples of up-to 10 fields. The following implementation works
493 // regardless of whether tr1::tuple is implemented using the
494 // non-standard variadic template feature or not.
495
496 inline void PrintTo(const ::std::tr1::tuple<>& t, ::std::ostream* os) {
497 PrintTupleTo(t, os);
498 }
499
500 template <typename T1>
501 void PrintTo(const ::std::tr1::tuple<T1>& t, ::std::ostream* os) {
502 PrintTupleTo(t, os);
503 }
504
505 template <typename T1, typename T2>
506 void PrintTo(const ::std::tr1::tuple<T1, T2>& t, ::std::ostream* os) {
507 PrintTupleTo(t, os);
508 }
509
510 template <typename T1, typename T2, typename T3>
511 void PrintTo(const ::std::tr1::tuple<T1, T2, T3>& t, ::std::ostream* os) {
512 PrintTupleTo(t, os);
513 }
514
515 template <typename T1, typename T2, typename T3, typename T4>
516 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4>& t, ::std::ostream* os) {
517 PrintTupleTo(t, os);
518 }
519
520 template <typename T1, typename T2, typename T3, typename T4, typename T5>
521 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5>& t,
522 ::std::ostream* os) {
523 PrintTupleTo(t, os);
524 }
525
526 template <typename T1, typename T2, typename T3, typename T4, typename T5,
527 typename T6>
528 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6>& t,
529 ::std::ostream* os) {
530 PrintTupleTo(t, os);
531 }
532
533 template <typename T1, typename T2, typename T3, typename T4, typename T5,
534 typename T6, typename T7>
535 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7>& t,
536 ::std::ostream* os) {
537 PrintTupleTo(t, os);
538 }
539
540 template <typename T1, typename T2, typename T3, typename T4, typename T5,
541 typename T6, typename T7, typename T8>
542 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8>& t,
543 ::std::ostream* os) {
544 PrintTupleTo(t, os);
545 }
546
547 template <typename T1, typename T2, typename T3, typename T4, typename T5,
548 typename T6, typename T7, typename T8, typename T9>
549 void PrintTo(const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>& t,
550 ::std::ostream* os) {
551 PrintTupleTo(t, os);
552 }
553
554 template <typename T1, typename T2, typename T3, typename T4, typename T5,
555 typename T6, typename T7, typename T8, typename T9, typename T10>
556 void PrintTo(
557 const ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>& t,
558 ::std::ostream* os) {
559 PrintTupleTo(t, os);
560 }
561 #endif // GTEST_HAS_TR1_TUPLE
562
563 // Overload for std::pair.
564 template <typename T1, typename T2>
565 void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
566 *os << '(';
567 // We cannot use UniversalPrint(value.first, os) here, as T1 may be
568 // a reference type. The same for printing value.second.
569 UniversalPrinter<T1>::Print(value.first, os);
570 *os << ", ";
571 UniversalPrinter<T2>::Print(value.second, os);
572 *os << ')';
573 }
574
575 // Implements printing a non-reference type T by letting the compiler
576 // pick the right overload of PrintTo() for T.
577 template <typename T>
578 class UniversalPrinter {
579 public:
580 // MSVC warns about adding const to a function type, so we want to
581 // disable the warning.
582 #ifdef _MSC_VER
583 # pragma warning(push) // Saves the current warning state.
584 # pragma warning(disable:4180) // Temporarily disables warning 4180.
585 #endif // _MSC_VER
586
587 // Note: we deliberately don't call this PrintTo(), as that name
588 // conflicts with ::testing::internal::PrintTo in the body of the
589 // function.
590 static void Print(const T& value, ::std::ostream* os) {
591 // By default, ::testing::internal::PrintTo() is used for printing
592 // the value.
593 //
594 // Thanks to Koenig look-up, if T is a class and has its own
595 // PrintTo() function defined in its namespace, that function will
596 // be visible here. Since it is more specific than the generic ones
597 // in ::testing::internal, it will be picked by the compiler in the
598 // following statement - exactly what we want.
599 PrintTo(value, os);
600 }
601
602 #ifdef _MSC_VER
603 # pragma warning(pop) // Restores the warning state.
604 #endif // _MSC_VER
605 };
606
607 // UniversalPrintArray(begin, len, os) prints an array of 'len'
608 // elements, starting at address 'begin'.
609 template <typename T>
610 void UniversalPrintArray(const T* begin, size_t len, ::std::ostream* os) {
611 if (len == 0) {
612 *os << "{}";
613 } else {
614 *os << "{ ";
615 const size_t kThreshold = 18;
616 const size_t kChunkSize = 8;
617 // If the array has more than kThreshold elements, we'll have to
618 // omit some details by printing only the first and the last
619 // kChunkSize elements.
620 // TODO(wan@google.com): let the user control the threshold using a flag.
621 if (len <= kThreshold) {
622 PrintRawArrayTo(begin, len, os);
623 } else {
624 PrintRawArrayTo(begin, kChunkSize, os);
625 *os << ", ..., ";
626 PrintRawArrayTo(begin + len - kChunkSize, kChunkSize, os);
627 }
628 *os << " }";
629 }
630 }
631 // This overload prints a (const) char array compactly.
632 GTEST_API_ void UniversalPrintArray(
633 const char* begin, size_t len, ::std::ostream* os);
634
635 // This overload prints a (const) wchar_t array compactly.
636 GTEST_API_ void UniversalPrintArray(
637 const wchar_t* begin, size_t len, ::std::ostream* os);
638
639 // Implements printing an array type T[N].
640 template <typename T, size_t N>
641 class UniversalPrinter<T[N]> {
642 public:
643 // Prints the given array, omitting some elements when there are too
644 // many.
645 static void Print(const T (&a)[N], ::std::ostream* os) {
646 UniversalPrintArray(a, N, os);
647 }
648 };
649
650 // Implements printing a reference type T&.
651 template <typename T>
652 class UniversalPrinter<T&> {
653 public:
654 // MSVC warns about adding const to a function type, so we want to
655 // disable the warning.
656 #ifdef _MSC_VER
657 # pragma warning(push) // Saves the current warning state.
658 # pragma warning(disable:4180) // Temporarily disables warning 4180.
659 #endif // _MSC_VER
660
661 static void Print(const T& value, ::std::ostream* os) {
662 // Prints the address of the value. We use reinterpret_cast here
663 // as static_cast doesn't compile when T is a function type.
664 *os << "@" << reinterpret_cast<const void*>(&value) << " ";
665
666 // Then prints the value itself.
667 UniversalPrint(value, os);
668 }
669
670 #ifdef _MSC_VER
671 # pragma warning(pop) // Restores the warning state.
672 #endif // _MSC_VER
673 };
674
675 // Prints a value tersely: for a reference type, the referenced value
676 // (but not the address) is printed; for a (const) char pointer, the
677 // NUL-terminated string (but not the pointer) is printed.
678
679 template <typename T>
680 class UniversalTersePrinter {
681 public:
682 static void Print(const T& value, ::std::ostream* os) {
683 UniversalPrint(value, os);
684 }
685 };
686 template <typename T>
687 class UniversalTersePrinter<T&> {
688 public:
689 static void Print(const T& value, ::std::ostream* os) {
690 UniversalPrint(value, os);
691 }
692 };
693 template <typename T, size_t N>
694 class UniversalTersePrinter<T[N]> {
695 public:
696 static void Print(const T (&value)[N], ::std::ostream* os) {
697 UniversalPrinter<T[N]>::Print(value, os);
698 }
699 };
700 template <>
701 class UniversalTersePrinter<const char*> {
702 public:
703 static void Print(const char* str, ::std::ostream* os) {
704 if (str == NULL) {
705 *os << "NULL";
706 } else {
707 UniversalPrint(string(str), os);
708 }
709 }
710 };
711 template <>
712 class UniversalTersePrinter<char*> {
713 public:
714 static void Print(char* str, ::std::ostream* os) {
715 UniversalTersePrinter<const char*>::Print(str, os);
716 }
717 };
718
719 #if GTEST_HAS_STD_WSTRING
720 template <>
721 class UniversalTersePrinter<const wchar_t*> {
722 public:
723 static void Print(const wchar_t* str, ::std::ostream* os) {
724 if (str == NULL) {
725 *os << "NULL";
726 } else {
727 UniversalPrint(::std::wstring(str), os);
728 }
729 }
730 };
731 #endif
732
733 template <>
734 class UniversalTersePrinter<wchar_t*> {
735 public:
736 static void Print(wchar_t* str, ::std::ostream* os) {
737 UniversalTersePrinter<const wchar_t*>::Print(str, os);
738 }
739 };
740
741 template <typename T>
742 void UniversalTersePrint(const T& value, ::std::ostream* os) {
743 UniversalTersePrinter<T>::Print(value, os);
744 }
745
746 // Prints a value using the type inferred by the compiler. The
747 // difference between this and UniversalTersePrint() is that for a
748 // (const) char pointer, this prints both the pointer and the
749 // NUL-terminated string.
750 template <typename T>
751 void UniversalPrint(const T& value, ::std::ostream* os) {
752 // A workarond for the bug in VC++ 7.1 that prevents us from instantiating
753 // UniversalPrinter with T directly.
754 typedef T T1;
755 UniversalPrinter<T1>::Print(value, os);
756 }
757
758 #if GTEST_HAS_TR1_TUPLE
759 typedef ::std::vector<string> Strings;
760
761 // This helper template allows PrintTo() for tuples and
762 // UniversalTersePrintTupleFieldsToStrings() to be defined by
763 // induction on the number of tuple fields. The idea is that
764 // TuplePrefixPrinter<N>::PrintPrefixTo(t, os) prints the first N
765 // fields in tuple t, and can be defined in terms of
766 // TuplePrefixPrinter<N - 1>.
767
768 // The inductive case.
769 template <size_t N>
770 struct TuplePrefixPrinter {
771 // Prints the first N fields of a tuple.
772 template <typename Tuple>
773 static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
774 TuplePrefixPrinter<N - 1>::PrintPrefixTo(t, os);
775 *os << ", ";
776 UniversalPrinter<typename ::std::tr1::tuple_element<N - 1, Tuple>::type>
777 ::Print(::std::tr1::get<N - 1>(t), os);
778 }
779
780 // Tersely prints the first N fields of a tuple to a string vector,
781 // one element for each field.
782 template <typename Tuple>
783 static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
784 TuplePrefixPrinter<N - 1>::TersePrintPrefixToStrings(t, strings);
785 ::std::stringstream ss;
786 UniversalTersePrint(::std::tr1::get<N - 1>(t), &ss);
787 strings->push_back(ss.str());
788 }
789 };
790
791 // Base cases.
792 template <>
793 struct TuplePrefixPrinter<0> {
794 template <typename Tuple>
795 static void PrintPrefixTo(const Tuple&, ::std::ostream*) {}
796
797 template <typename Tuple>
798 static void TersePrintPrefixToStrings(const Tuple&, Strings*) {}
799 };
800 // We have to specialize the entire TuplePrefixPrinter<> class
801 // template here, even though the definition of
802 // TersePrintPrefixToStrings() is the same as the generic version, as
803 // Embarcadero (formerly CodeGear, formerly Borland) C++ doesn't
804 // support specializing a method template of a class template.
805 template <>
806 struct TuplePrefixPrinter<1> {
807 template <typename Tuple>
808 static void PrintPrefixTo(const Tuple& t, ::std::ostream* os) {
809 UniversalPrinter<typename ::std::tr1::tuple_element<0, Tuple>::type>::
810 Print(::std::tr1::get<0>(t), os);
811 }
812
813 template <typename Tuple>
814 static void TersePrintPrefixToStrings(const Tuple& t, Strings* strings) {
815 ::std::stringstream ss;
816 UniversalTersePrint(::std::tr1::get<0>(t), &ss);
817 strings->push_back(ss.str());
818 }
819 };
820
821 // Helper function for printing a tuple. T must be instantiated with
822 // a tuple type.
823 template <typename T>
824 void PrintTupleTo(const T& t, ::std::ostream* os) {
825 *os << "(";
826 TuplePrefixPrinter< ::std::tr1::tuple_size<T>::value>::
827 PrintPrefixTo(t, os);
828 *os << ")";
829 }
830
831 // Prints the fields of a tuple tersely to a string vector, one
832 // element for each field. See the comment before
833 // UniversalTersePrint() for how we define "tersely".
834 template <typename Tuple>
835 Strings UniversalTersePrintTupleFieldsToStrings(const Tuple& value) {
836 Strings result;
837 TuplePrefixPrinter< ::std::tr1::tuple_size<Tuple>::value>::
838 TersePrintPrefixToStrings(value, &result);
839 return result;
840 }
841 #endif // GTEST_HAS_TR1_TUPLE
842
843 } // namespace internal
844
845 template <typename T>
846 ::std::string PrintToString(const T& value) {
847 ::std::stringstream ss;
848 internal::UniversalTersePrinter<T>::Print(value, &ss);
849 return ss.str();
850 }
851
852 } // namespace testing
853
854 #endif // GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_
0 // Copyright 2007, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30 //
31 // Utilities for testing Google Test itself and code that uses Google Test
32 // (e.g. frameworks built on top of Google Test).
33
34 #ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
35 #define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
36
37 #include "gtest/gtest.h"
38
39 namespace testing {
40
41 // This helper class can be used to mock out Google Test failure reporting
42 // so that we can test Google Test or code that builds on Google Test.
43 //
44 // An object of this class appends a TestPartResult object to the
45 // TestPartResultArray object given in the constructor whenever a Google Test
46 // failure is reported. It can either intercept only failures that are
47 // generated in the same thread that created this object or it can intercept
48 // all generated failures. The scope of this mock object can be controlled with
49 // the second argument to the two arguments constructor.
50 class GTEST_API_ ScopedFakeTestPartResultReporter
51 : public TestPartResultReporterInterface {
52 public:
53 // The two possible mocking modes of this object.
54 enum InterceptMode {
55 INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures.
56 INTERCEPT_ALL_THREADS // Intercepts all failures.
57 };
58
59 // The c'tor sets this object as the test part result reporter used
60 // by Google Test. The 'result' parameter specifies where to report the
61 // results. This reporter will only catch failures generated in the current
62 // thread. DEPRECATED
63 explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result);
64
65 // Same as above, but you can choose the interception scope of this object.
66 ScopedFakeTestPartResultReporter(InterceptMode intercept_mode,
67 TestPartResultArray* result);
68
69 // The d'tor restores the previous test part result reporter.
70 virtual ~ScopedFakeTestPartResultReporter();
71
72 // Appends the TestPartResult object to the TestPartResultArray
73 // received in the constructor.
74 //
75 // This method is from the TestPartResultReporterInterface
76 // interface.
77 virtual void ReportTestPartResult(const TestPartResult& result);
78 private:
79 void Init();
80
81 const InterceptMode intercept_mode_;
82 TestPartResultReporterInterface* old_reporter_;
83 TestPartResultArray* const result_;
84
85 GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter);
86 };
87
88 namespace internal {
89
90 // A helper class for implementing EXPECT_FATAL_FAILURE() and
91 // EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given
92 // TestPartResultArray contains exactly one failure that has the given
93 // type and contains the given substring. If that's not the case, a
94 // non-fatal failure will be generated.
95 class GTEST_API_ SingleFailureChecker {
96 public:
97 // The constructor remembers the arguments.
98 SingleFailureChecker(const TestPartResultArray* results,
99 TestPartResult::Type type,
100 const string& substr);
101 ~SingleFailureChecker();
102 private:
103 const TestPartResultArray* const results_;
104 const TestPartResult::Type type_;
105 const string substr_;
106
107 GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
108 };
109
110 } // namespace internal
111
112 } // namespace testing
113
114 // A set of macros for testing Google Test assertions or code that's expected
115 // to generate Google Test fatal failures. It verifies that the given
116 // statement will cause exactly one fatal Google Test failure with 'substr'
117 // being part of the failure message.
118 //
119 // There are two different versions of this macro. EXPECT_FATAL_FAILURE only
120 // affects and considers failures generated in the current thread and
121 // EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
122 //
123 // The verification of the assertion is done correctly even when the statement
124 // throws an exception or aborts the current function.
125 //
126 // Known restrictions:
127 // - 'statement' cannot reference local non-static variables or
128 // non-static members of the current object.
129 // - 'statement' cannot return a value.
130 // - You cannot stream a failure message to this macro.
131 //
132 // Note that even though the implementations of the following two
133 // macros are much alike, we cannot refactor them to use a common
134 // helper macro, due to some peculiarity in how the preprocessor
135 // works. The AcceptsMacroThatExpandsToUnprotectedComma test in
136 // gtest_unittest.cc will fail to compile if we do that.
137 #define EXPECT_FATAL_FAILURE(statement, substr) \
138 do { \
139 class GTestExpectFatalFailureHelper {\
140 public:\
141 static void Execute() { statement; }\
142 };\
143 ::testing::TestPartResultArray gtest_failures;\
144 ::testing::internal::SingleFailureChecker gtest_checker(\
145 &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
146 {\
147 ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
148 ::testing::ScopedFakeTestPartResultReporter:: \
149 INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
150 GTestExpectFatalFailureHelper::Execute();\
151 }\
152 } while (::testing::internal::AlwaysFalse())
153
154 #define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
155 do { \
156 class GTestExpectFatalFailureHelper {\
157 public:\
158 static void Execute() { statement; }\
159 };\
160 ::testing::TestPartResultArray gtest_failures;\
161 ::testing::internal::SingleFailureChecker gtest_checker(\
162 &gtest_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
163 {\
164 ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
165 ::testing::ScopedFakeTestPartResultReporter:: \
166 INTERCEPT_ALL_THREADS, &gtest_failures);\
167 GTestExpectFatalFailureHelper::Execute();\
168 }\
169 } while (::testing::internal::AlwaysFalse())
170
171 // A macro for testing Google Test assertions or code that's expected to
172 // generate Google Test non-fatal failures. It asserts that the given
173 // statement will cause exactly one non-fatal Google Test failure with 'substr'
174 // being part of the failure message.
175 //
176 // There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only
177 // affects and considers failures generated in the current thread and
178 // EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
179 //
180 // 'statement' is allowed to reference local variables and members of
181 // the current object.
182 //
183 // The verification of the assertion is done correctly even when the statement
184 // throws an exception or aborts the current function.
185 //
186 // Known restrictions:
187 // - You cannot stream a failure message to this macro.
188 //
189 // Note that even though the implementations of the following two
190 // macros are much alike, we cannot refactor them to use a common
191 // helper macro, due to some peculiarity in how the preprocessor
192 // works. If we do that, the code won't compile when the user gives
193 // EXPECT_NONFATAL_FAILURE() a statement that contains a macro that
194 // expands to code containing an unprotected comma. The
195 // AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc
196 // catches that.
197 //
198 // For the same reason, we have to write
199 // if (::testing::internal::AlwaysTrue()) { statement; }
200 // instead of
201 // GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
202 // to avoid an MSVC warning on unreachable code.
203 #define EXPECT_NONFATAL_FAILURE(statement, substr) \
204 do {\
205 ::testing::TestPartResultArray gtest_failures;\
206 ::testing::internal::SingleFailureChecker gtest_checker(\
207 &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
208 (substr));\
209 {\
210 ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
211 ::testing::ScopedFakeTestPartResultReporter:: \
212 INTERCEPT_ONLY_CURRENT_THREAD, &gtest_failures);\
213 if (::testing::internal::AlwaysTrue()) { statement; }\
214 }\
215 } while (::testing::internal::AlwaysFalse())
216
217 #define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
218 do {\
219 ::testing::TestPartResultArray gtest_failures;\
220 ::testing::internal::SingleFailureChecker gtest_checker(\
221 &gtest_failures, ::testing::TestPartResult::kNonFatalFailure, \
222 (substr));\
223 {\
224 ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
225 ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, \
226 &gtest_failures);\
227 if (::testing::internal::AlwaysTrue()) { statement; }\
228 }\
229 } while (::testing::internal::AlwaysFalse())
230
231 #endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_
0 // Copyright 2008, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: mheule@google.com (Markus Heule)
30 //
31
32 #ifndef GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
33 #define GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
34
35 #include <iosfwd>
36 #include <vector>
37 #include "gtest/internal/gtest-internal.h"
38 #include "gtest/internal/gtest-string.h"
39
40 namespace testing {
41
42 // A copyable object representing the result of a test part (i.e. an
43 // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()).
44 //
45 // Don't inherit from TestPartResult as its destructor is not virtual.
46 class GTEST_API_ TestPartResult {
47 public:
48 // The possible outcomes of a test part (i.e. an assertion or an
49 // explicit SUCCEED(), FAIL(), or ADD_FAILURE()).
50 enum Type {
51 kSuccess, // Succeeded.
52 kNonFatalFailure, // Failed but the test can continue.
53 kFatalFailure // Failed and the test should be terminated.
54 };
55
56 // C'tor. TestPartResult does NOT have a default constructor.
57 // Always use this constructor (with parameters) to create a
58 // TestPartResult object.
59 TestPartResult(Type a_type,
60 const char* a_file_name,
61 int a_line_number,
62 const char* a_message)
63 : type_(a_type),
64 file_name_(a_file_name == NULL ? "" : a_file_name),
65 line_number_(a_line_number),
66 summary_(ExtractSummary(a_message)),
67 message_(a_message) {
68 }
69
70 // Gets the outcome of the test part.
71 Type type() const { return type_; }
72
73 // Gets the name of the source file where the test part took place, or
74 // NULL if it's unknown.
75 const char* file_name() const {
76 return file_name_.empty() ? NULL : file_name_.c_str();
77 }
78
79 // Gets the line in the source file where the test part took place,
80 // or -1 if it's unknown.
81 int line_number() const { return line_number_; }
82
83 // Gets the summary of the failure message.
84 const char* summary() const { return summary_.c_str(); }
85
86 // Gets the message associated with the test part.
87 const char* message() const { return message_.c_str(); }
88
89 // Returns true iff the test part passed.
90 bool passed() const { return type_ == kSuccess; }
91
92 // Returns true iff the test part failed.
93 bool failed() const { return type_ != kSuccess; }
94
95 // Returns true iff the test part non-fatally failed.
96 bool nonfatally_failed() const { return type_ == kNonFatalFailure; }
97
98 // Returns true iff the test part fatally failed.
99 bool fatally_failed() const { return type_ == kFatalFailure; }
100
101 private:
102 Type type_;
103
104 // Gets the summary of the failure message by omitting the stack
105 // trace in it.
106 static std::string ExtractSummary(const char* message);
107
108 // The name of the source file where the test part took place, or
109 // "" if the source file is unknown.
110 std::string file_name_;
111 // The line in the source file where the test part took place, or -1
112 // if the line number is unknown.
113 int line_number_;
114 std::string summary_; // The test failure summary.
115 std::string message_; // The test failure message.
116 };
117
118 // Prints a TestPartResult object.
119 std::ostream& operator<<(std::ostream& os, const TestPartResult& result);
120
121 // An array of TestPartResult objects.
122 //
123 // Don't inherit from TestPartResultArray as its destructor is not
124 // virtual.
125 class GTEST_API_ TestPartResultArray {
126 public:
127 TestPartResultArray() {}
128
129 // Appends the given TestPartResult to the array.
130 void Append(const TestPartResult& result);
131
132 // Returns the TestPartResult at the given index (0-based).
133 const TestPartResult& GetTestPartResult(int index) const;
134
135 // Returns the number of TestPartResult objects in the array.
136 int size() const;
137
138 private:
139 std::vector<TestPartResult> array_;
140
141 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestPartResultArray);
142 };
143
144 // This interface knows how to report a test part result.
145 class TestPartResultReporterInterface {
146 public:
147 virtual ~TestPartResultReporterInterface() {}
148
149 virtual void ReportTestPartResult(const TestPartResult& result) = 0;
150 };
151
152 namespace internal {
153
154 // This helper class is used by {ASSERT|EXPECT}_NO_FATAL_FAILURE to check if a
155 // statement generates new fatal failures. To do so it registers itself as the
156 // current test part result reporter. Besides checking if fatal failures were
157 // reported, it only delegates the reporting to the former result reporter.
158 // The original result reporter is restored in the destructor.
159 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
160 class GTEST_API_ HasNewFatalFailureHelper
161 : public TestPartResultReporterInterface {
162 public:
163 HasNewFatalFailureHelper();
164 virtual ~HasNewFatalFailureHelper();
165 virtual void ReportTestPartResult(const TestPartResult& result);
166 bool has_new_fatal_failure() const { return has_new_fatal_failure_; }
167 private:
168 bool has_new_fatal_failure_;
169 TestPartResultReporterInterface* original_reporter_;
170
171 GTEST_DISALLOW_COPY_AND_ASSIGN_(HasNewFatalFailureHelper);
172 };
173
174 } // namespace internal
175
176 } // namespace testing
177
178 #endif // GTEST_INCLUDE_GTEST_GTEST_TEST_PART_H_
0 // Copyright 2008 Google Inc.
1 // All Rights Reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30
31 #ifndef GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
32 #define GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
33
34 // This header implements typed tests and type-parameterized tests.
35
36 // Typed (aka type-driven) tests repeat the same test for types in a
37 // list. You must know which types you want to test with when writing
38 // typed tests. Here's how you do it:
39
40 #if 0
41
42 // First, define a fixture class template. It should be parameterized
43 // by a type. Remember to derive it from testing::Test.
44 template <typename T>
45 class FooTest : public testing::Test {
46 public:
47 ...
48 typedef std::list<T> List;
49 static T shared_;
50 T value_;
51 };
52
53 // Next, associate a list of types with the test case, which will be
54 // repeated for each type in the list. The typedef is necessary for
55 // the macro to parse correctly.
56 typedef testing::Types<char, int, unsigned int> MyTypes;
57 TYPED_TEST_CASE(FooTest, MyTypes);
58
59 // If the type list contains only one type, you can write that type
60 // directly without Types<...>:
61 // TYPED_TEST_CASE(FooTest, int);
62
63 // Then, use TYPED_TEST() instead of TEST_F() to define as many typed
64 // tests for this test case as you want.
65 TYPED_TEST(FooTest, DoesBlah) {
66 // Inside a test, refer to TypeParam to get the type parameter.
67 // Since we are inside a derived class template, C++ requires use to
68 // visit the members of FooTest via 'this'.
69 TypeParam n = this->value_;
70
71 // To visit static members of the fixture, add the TestFixture::
72 // prefix.
73 n += TestFixture::shared_;
74
75 // To refer to typedefs in the fixture, add the "typename
76 // TestFixture::" prefix.
77 typename TestFixture::List values;
78 values.push_back(n);
79 ...
80 }
81
82 TYPED_TEST(FooTest, HasPropertyA) { ... }
83
84 #endif // 0
85
86 // Type-parameterized tests are abstract test patterns parameterized
87 // by a type. Compared with typed tests, type-parameterized tests
88 // allow you to define the test pattern without knowing what the type
89 // parameters are. The defined pattern can be instantiated with
90 // different types any number of times, in any number of translation
91 // units.
92 //
93 // If you are designing an interface or concept, you can define a
94 // suite of type-parameterized tests to verify properties that any
95 // valid implementation of the interface/concept should have. Then,
96 // each implementation can easily instantiate the test suite to verify
97 // that it conforms to the requirements, without having to write
98 // similar tests repeatedly. Here's an example:
99
100 #if 0
101
102 // First, define a fixture class template. It should be parameterized
103 // by a type. Remember to derive it from testing::Test.
104 template <typename T>
105 class FooTest : public testing::Test {
106 ...
107 };
108
109 // Next, declare that you will define a type-parameterized test case
110 // (the _P suffix is for "parameterized" or "pattern", whichever you
111 // prefer):
112 TYPED_TEST_CASE_P(FooTest);
113
114 // Then, use TYPED_TEST_P() to define as many type-parameterized tests
115 // for this type-parameterized test case as you want.
116 TYPED_TEST_P(FooTest, DoesBlah) {
117 // Inside a test, refer to TypeParam to get the type parameter.
118 TypeParam n = 0;
119 ...
120 }
121
122 TYPED_TEST_P(FooTest, HasPropertyA) { ... }
123
124 // Now the tricky part: you need to register all test patterns before
125 // you can instantiate them. The first argument of the macro is the
126 // test case name; the rest are the names of the tests in this test
127 // case.
128 REGISTER_TYPED_TEST_CASE_P(FooTest,
129 DoesBlah, HasPropertyA);
130
131 // Finally, you are free to instantiate the pattern with the types you
132 // want. If you put the above code in a header file, you can #include
133 // it in multiple C++ source files and instantiate it multiple times.
134 //
135 // To distinguish different instances of the pattern, the first
136 // argument to the INSTANTIATE_* macro is a prefix that will be added
137 // to the actual test case name. Remember to pick unique prefixes for
138 // different instances.
139 typedef testing::Types<char, int, unsigned int> MyTypes;
140 INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, MyTypes);
141
142 // If the type list contains only one type, you can write that type
143 // directly without Types<...>:
144 // INSTANTIATE_TYPED_TEST_CASE_P(My, FooTest, int);
145
146 #endif // 0
147
148 #include "gtest/internal/gtest-port.h"
149 #include "gtest/internal/gtest-type-util.h"
150
151 // Implements typed tests.
152
153 #if GTEST_HAS_TYPED_TEST
154
155 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
156 //
157 // Expands to the name of the typedef for the type parameters of the
158 // given test case.
159 # define GTEST_TYPE_PARAMS_(TestCaseName) gtest_type_params_##TestCaseName##_
160
161 // The 'Types' template argument below must have spaces around it
162 // since some compilers may choke on '>>' when passing a template
163 // instance (e.g. Types<int>)
164 # define TYPED_TEST_CASE(CaseName, Types) \
165 typedef ::testing::internal::TypeList< Types >::type \
166 GTEST_TYPE_PARAMS_(CaseName)
167
168 # define TYPED_TEST(CaseName, TestName) \
169 template <typename gtest_TypeParam_> \
170 class GTEST_TEST_CLASS_NAME_(CaseName, TestName) \
171 : public CaseName<gtest_TypeParam_> { \
172 private: \
173 typedef CaseName<gtest_TypeParam_> TestFixture; \
174 typedef gtest_TypeParam_ TypeParam; \
175 virtual void TestBody(); \
176 }; \
177 bool gtest_##CaseName##_##TestName##_registered_ GTEST_ATTRIBUTE_UNUSED_ = \
178 ::testing::internal::TypeParameterizedTest< \
179 CaseName, \
180 ::testing::internal::TemplateSel< \
181 GTEST_TEST_CLASS_NAME_(CaseName, TestName)>, \
182 GTEST_TYPE_PARAMS_(CaseName)>::Register(\
183 "", #CaseName, #TestName, 0); \
184 template <typename gtest_TypeParam_> \
185 void GTEST_TEST_CLASS_NAME_(CaseName, TestName)<gtest_TypeParam_>::TestBody()
186
187 #endif // GTEST_HAS_TYPED_TEST
188
189 // Implements type-parameterized tests.
190
191 #if GTEST_HAS_TYPED_TEST_P
192
193 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
194 //
195 // Expands to the namespace name that the type-parameterized tests for
196 // the given type-parameterized test case are defined in. The exact
197 // name of the namespace is subject to change without notice.
198 # define GTEST_CASE_NAMESPACE_(TestCaseName) \
199 gtest_case_##TestCaseName##_
200
201 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
202 //
203 // Expands to the name of the variable used to remember the names of
204 // the defined tests in the given test case.
205 # define GTEST_TYPED_TEST_CASE_P_STATE_(TestCaseName) \
206 gtest_typed_test_case_p_state_##TestCaseName##_
207
208 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE DIRECTLY.
209 //
210 // Expands to the name of the variable used to remember the names of
211 // the registered tests in the given test case.
212 # define GTEST_REGISTERED_TEST_NAMES_(TestCaseName) \
213 gtest_registered_test_names_##TestCaseName##_
214
215 // The variables defined in the type-parameterized test macros are
216 // static as typically these macros are used in a .h file that can be
217 // #included in multiple translation units linked together.
218 # define TYPED_TEST_CASE_P(CaseName) \
219 static ::testing::internal::TypedTestCasePState \
220 GTEST_TYPED_TEST_CASE_P_STATE_(CaseName)
221
222 # define TYPED_TEST_P(CaseName, TestName) \
223 namespace GTEST_CASE_NAMESPACE_(CaseName) { \
224 template <typename gtest_TypeParam_> \
225 class TestName : public CaseName<gtest_TypeParam_> { \
226 private: \
227 typedef CaseName<gtest_TypeParam_> TestFixture; \
228 typedef gtest_TypeParam_ TypeParam; \
229 virtual void TestBody(); \
230 }; \
231 static bool gtest_##TestName##_defined_ GTEST_ATTRIBUTE_UNUSED_ = \
232 GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).AddTestName(\
233 __FILE__, __LINE__, #CaseName, #TestName); \
234 } \
235 template <typename gtest_TypeParam_> \
236 void GTEST_CASE_NAMESPACE_(CaseName)::TestName<gtest_TypeParam_>::TestBody()
237
238 # define REGISTER_TYPED_TEST_CASE_P(CaseName, ...) \
239 namespace GTEST_CASE_NAMESPACE_(CaseName) { \
240 typedef ::testing::internal::Templates<__VA_ARGS__>::type gtest_AllTests_; \
241 } \
242 static const char* const GTEST_REGISTERED_TEST_NAMES_(CaseName) = \
243 GTEST_TYPED_TEST_CASE_P_STATE_(CaseName).VerifyRegisteredTestNames(\
244 __FILE__, __LINE__, #__VA_ARGS__)
245
246 // The 'Types' template argument below must have spaces around it
247 // since some compilers may choke on '>>' when passing a template
248 // instance (e.g. Types<int>)
249 # define INSTANTIATE_TYPED_TEST_CASE_P(Prefix, CaseName, Types) \
250 bool gtest_##Prefix##_##CaseName GTEST_ATTRIBUTE_UNUSED_ = \
251 ::testing::internal::TypeParameterizedTestCase<CaseName, \
252 GTEST_CASE_NAMESPACE_(CaseName)::gtest_AllTests_, \
253 ::testing::internal::TypeList< Types >::type>::Register(\
254 #Prefix, #CaseName, GTEST_REGISTERED_TEST_NAMES_(CaseName))
255
256 #endif // GTEST_HAS_TYPED_TEST_P
257
258 #endif // GTEST_INCLUDE_GTEST_GTEST_TYPED_TEST_H_
0 // Copyright 2005, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30 //
31 // The Google C++ Testing Framework (Google Test)
32 //
33 // This header file defines the public API for Google Test. It should be
34 // included by any test program that uses Google Test.
35 //
36 // IMPORTANT NOTE: Due to limitation of the C++ language, we have to
37 // leave some internal implementation details in this header file.
38 // They are clearly marked by comments like this:
39 //
40 // // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
41 //
42 // Such code is NOT meant to be used by a user directly, and is subject
43 // to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
44 // program!
45 //
46 // Acknowledgment: Google Test borrowed the idea of automatic test
47 // registration from Barthelemy Dagenais' (barthelemy@prologique.com)
48 // easyUnit framework.
49
50 #ifndef GTEST_INCLUDE_GTEST_GTEST_H_
51 #define GTEST_INCLUDE_GTEST_GTEST_H_
52
53 #include <limits>
54 #include <ostream>
55 #include <vector>
56
57 #include "gtest/internal/gtest-internal.h"
58 #include "gtest/internal/gtest-string.h"
59 #include "gtest/gtest-death-test.h"
60 #include "gtest/gtest-message.h"
61 #include "gtest/gtest-param-test.h"
62 #include "gtest/gtest-printers.h"
63 #include "gtest/gtest_prod.h"
64 #include "gtest/gtest-test-part.h"
65 #include "gtest/gtest-typed-test.h"
66
67 // Depending on the platform, different string classes are available.
68 // On Linux, in addition to ::std::string, Google also makes use of
69 // class ::string, which has the same interface as ::std::string, but
70 // has a different implementation.
71 //
72 // The user can define GTEST_HAS_GLOBAL_STRING to 1 to indicate that
73 // ::string is available AND is a distinct type to ::std::string, or
74 // define it to 0 to indicate otherwise.
75 //
76 // If the user's ::std::string and ::string are the same class due to
77 // aliasing, he should define GTEST_HAS_GLOBAL_STRING to 0.
78 //
79 // If the user doesn't define GTEST_HAS_GLOBAL_STRING, it is defined
80 // heuristically.
81
82 namespace testing {
83
84 // Declares the flags.
85
86 // This flag temporary enables the disabled tests.
87 GTEST_DECLARE_bool_(also_run_disabled_tests);
88
89 // This flag brings the debugger on an assertion failure.
90 GTEST_DECLARE_bool_(break_on_failure);
91
92 // This flag controls whether Google Test catches all test-thrown exceptions
93 // and logs them as failures.
94 GTEST_DECLARE_bool_(catch_exceptions);
95
96 // This flag enables using colors in terminal output. Available values are
97 // "yes" to enable colors, "no" (disable colors), or "auto" (the default)
98 // to let Google Test decide.
99 GTEST_DECLARE_string_(color);
100
101 // This flag sets up the filter to select by name using a glob pattern
102 // the tests to run. If the filter is not given all tests are executed.
103 GTEST_DECLARE_string_(filter);
104
105 // This flag causes the Google Test to list tests. None of the tests listed
106 // are actually run if the flag is provided.
107 GTEST_DECLARE_bool_(list_tests);
108
109 // This flag controls whether Google Test emits a detailed XML report to a file
110 // in addition to its normal textual output.
111 GTEST_DECLARE_string_(output);
112
113 // This flags control whether Google Test prints the elapsed time for each
114 // test.
115 GTEST_DECLARE_bool_(print_time);
116
117 // This flag specifies the random number seed.
118 GTEST_DECLARE_int32_(random_seed);
119
120 // This flag sets how many times the tests are repeated. The default value
121 // is 1. If the value is -1 the tests are repeating forever.
122 GTEST_DECLARE_int32_(repeat);
123
124 // This flag controls whether Google Test includes Google Test internal
125 // stack frames in failure stack traces.
126 GTEST_DECLARE_bool_(show_internal_stack_frames);
127
128 // When this flag is specified, tests' order is randomized on every iteration.
129 GTEST_DECLARE_bool_(shuffle);
130
131 // This flag specifies the maximum number of stack frames to be
132 // printed in a failure message.
133 GTEST_DECLARE_int32_(stack_trace_depth);
134
135 // When this flag is specified, a failed assertion will throw an
136 // exception if exceptions are enabled, or exit the program with a
137 // non-zero code otherwise.
138 GTEST_DECLARE_bool_(throw_on_failure);
139
140 // When this flag is set with a "host:port" string, on supported
141 // platforms test results are streamed to the specified port on
142 // the specified host machine.
143 GTEST_DECLARE_string_(stream_result_to);
144
145 // The upper limit for valid stack trace depths.
146 const int kMaxStackTraceDepth = 100;
147
148 namespace internal {
149
150 class AssertHelper;
151 class DefaultGlobalTestPartResultReporter;
152 class ExecDeathTest;
153 class NoExecDeathTest;
154 class FinalSuccessChecker;
155 class GTestFlagSaver;
156 class StreamingListenerTest;
157 class TestResultAccessor;
158 class TestEventListenersAccessor;
159 class TestEventRepeater;
160 class UnitTestRecordPropertyTestHelper;
161 class WindowsDeathTest;
162 class UnitTestImpl* GetUnitTestImpl();
163 void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
164 const std::string& message);
165
166 } // namespace internal
167
168 // The friend relationship of some of these classes is cyclic.
169 // If we don't forward declare them the compiler might confuse the classes
170 // in friendship clauses with same named classes on the scope.
171 class Test;
172 class TestCase;
173 class TestInfo;
174 class UnitTest;
175
176 // A class for indicating whether an assertion was successful. When
177 // the assertion wasn't successful, the AssertionResult object
178 // remembers a non-empty message that describes how it failed.
179 //
180 // To create an instance of this class, use one of the factory functions
181 // (AssertionSuccess() and AssertionFailure()).
182 //
183 // This class is useful for two purposes:
184 // 1. Defining predicate functions to be used with Boolean test assertions
185 // EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts
186 // 2. Defining predicate-format functions to be
187 // used with predicate assertions (ASSERT_PRED_FORMAT*, etc).
188 //
189 // For example, if you define IsEven predicate:
190 //
191 // testing::AssertionResult IsEven(int n) {
192 // if ((n % 2) == 0)
193 // return testing::AssertionSuccess();
194 // else
195 // return testing::AssertionFailure() << n << " is odd";
196 // }
197 //
198 // Then the failed expectation EXPECT_TRUE(IsEven(Fib(5)))
199 // will print the message
200 //
201 // Value of: IsEven(Fib(5))
202 // Actual: false (5 is odd)
203 // Expected: true
204 //
205 // instead of a more opaque
206 //
207 // Value of: IsEven(Fib(5))
208 // Actual: false
209 // Expected: true
210 //
211 // in case IsEven is a simple Boolean predicate.
212 //
213 // If you expect your predicate to be reused and want to support informative
214 // messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up
215 // about half as often as positive ones in our tests), supply messages for
216 // both success and failure cases:
217 //
218 // testing::AssertionResult IsEven(int n) {
219 // if ((n % 2) == 0)
220 // return testing::AssertionSuccess() << n << " is even";
221 // else
222 // return testing::AssertionFailure() << n << " is odd";
223 // }
224 //
225 // Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print
226 //
227 // Value of: IsEven(Fib(6))
228 // Actual: true (8 is even)
229 // Expected: false
230 //
231 // NB: Predicates that support negative Boolean assertions have reduced
232 // performance in positive ones so be careful not to use them in tests
233 // that have lots (tens of thousands) of positive Boolean assertions.
234 //
235 // To use this class with EXPECT_PRED_FORMAT assertions such as:
236 //
237 // // Verifies that Foo() returns an even number.
238 // EXPECT_PRED_FORMAT1(IsEven, Foo());
239 //
240 // you need to define:
241 //
242 // testing::AssertionResult IsEven(const char* expr, int n) {
243 // if ((n % 2) == 0)
244 // return testing::AssertionSuccess();
245 // else
246 // return testing::AssertionFailure()
247 // << "Expected: " << expr << " is even\n Actual: it's " << n;
248 // }
249 //
250 // If Foo() returns 5, you will see the following message:
251 //
252 // Expected: Foo() is even
253 // Actual: it's 5
254 //
255 class GTEST_API_ AssertionResult {
256 public:
257 // Copy constructor.
258 // Used in EXPECT_TRUE/FALSE(assertion_result).
259 AssertionResult(const AssertionResult& other);
260 // Used in the EXPECT_TRUE/FALSE(bool_expression).
261 explicit AssertionResult(bool success) : success_(success) {}
262
263 // Returns true iff the assertion succeeded.
264 operator bool() const { return success_; } // NOLINT
265
266 // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
267 AssertionResult operator!() const;
268
269 // Returns the text streamed into this AssertionResult. Test assertions
270 // use it when they fail (i.e., the predicate's outcome doesn't match the
271 // assertion's expectation). When nothing has been streamed into the
272 // object, returns an empty string.
273 const char* message() const {
274 return message_.get() != NULL ? message_->c_str() : "";
275 }
276 // TODO(vladl@google.com): Remove this after making sure no clients use it.
277 // Deprecated; please use message() instead.
278 const char* failure_message() const { return message(); }
279
280 // Streams a custom failure message into this object.
281 template <typename T> AssertionResult& operator<<(const T& value) {
282 AppendMessage(Message() << value);
283 return *this;
284 }
285
286 // Allows streaming basic output manipulators such as endl or flush into
287 // this object.
288 AssertionResult& operator<<(
289 ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) {
290 AppendMessage(Message() << basic_manipulator);
291 return *this;
292 }
293
294 private:
295 // Appends the contents of message to message_.
296 void AppendMessage(const Message& a_message) {
297 if (message_.get() == NULL)
298 message_.reset(new ::std::string);
299 message_->append(a_message.GetString().c_str());
300 }
301
302 // Stores result of the assertion predicate.
303 bool success_;
304 // Stores the message describing the condition in case the expectation
305 // construct is not satisfied with the predicate's outcome.
306 // Referenced via a pointer to avoid taking too much stack frame space
307 // with test assertions.
308 internal::scoped_ptr< ::std::string> message_;
309
310 GTEST_DISALLOW_ASSIGN_(AssertionResult);
311 };
312
313 // Makes a successful assertion result.
314 GTEST_API_ AssertionResult AssertionSuccess();
315
316 // Makes a failed assertion result.
317 GTEST_API_ AssertionResult AssertionFailure();
318
319 // Makes a failed assertion result with the given failure message.
320 // Deprecated; use AssertionFailure() << msg.
321 GTEST_API_ AssertionResult AssertionFailure(const Message& msg);
322
323 // The abstract class that all tests inherit from.
324 //
325 // In Google Test, a unit test program contains one or many TestCases, and
326 // each TestCase contains one or many Tests.
327 //
328 // When you define a test using the TEST macro, you don't need to
329 // explicitly derive from Test - the TEST macro automatically does
330 // this for you.
331 //
332 // The only time you derive from Test is when defining a test fixture
333 // to be used a TEST_F. For example:
334 //
335 // class FooTest : public testing::Test {
336 // protected:
337 // virtual void SetUp() { ... }
338 // virtual void TearDown() { ... }
339 // ...
340 // };
341 //
342 // TEST_F(FooTest, Bar) { ... }
343 // TEST_F(FooTest, Baz) { ... }
344 //
345 // Test is not copyable.
346 class GTEST_API_ Test {
347 public:
348 friend class TestInfo;
349
350 // Defines types for pointers to functions that set up and tear down
351 // a test case.
352 typedef internal::SetUpTestCaseFunc SetUpTestCaseFunc;
353 typedef internal::TearDownTestCaseFunc TearDownTestCaseFunc;
354
355 // The d'tor is virtual as we intend to inherit from Test.
356 virtual ~Test();
357
358 // Sets up the stuff shared by all tests in this test case.
359 //
360 // Google Test will call Foo::SetUpTestCase() before running the first
361 // test in test case Foo. Hence a sub-class can define its own
362 // SetUpTestCase() method to shadow the one defined in the super
363 // class.
364 static void SetUpTestCase() {}
365
366 // Tears down the stuff shared by all tests in this test case.
367 //
368 // Google Test will call Foo::TearDownTestCase() after running the last
369 // test in test case Foo. Hence a sub-class can define its own
370 // TearDownTestCase() method to shadow the one defined in the super
371 // class.
372 static void TearDownTestCase() {}
373
374 // Returns true iff the current test has a fatal failure.
375 static bool HasFatalFailure();
376
377 // Returns true iff the current test has a non-fatal failure.
378 static bool HasNonfatalFailure();
379
380 // Returns true iff the current test has a (either fatal or
381 // non-fatal) failure.
382 static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
383
384 // Logs a property for the current test, test case, or for the entire
385 // invocation of the test program when used outside of the context of a
386 // test case. Only the last value for a given key is remembered. These
387 // are public static so they can be called from utility functions that are
388 // not members of the test fixture. Calls to RecordProperty made during
389 // lifespan of the test (from the moment its constructor starts to the
390 // moment its destructor finishes) will be output in XML as attributes of
391 // the <testcase> element. Properties recorded from fixture's
392 // SetUpTestCase or TearDownTestCase are logged as attributes of the
393 // corresponding <testsuite> element. Calls to RecordProperty made in the
394 // global context (before or after invocation of RUN_ALL_TESTS and from
395 // SetUp/TearDown method of Environment objects registered with Google
396 // Test) will be output as attributes of the <testsuites> element.
397 static void RecordProperty(const std::string& key, const std::string& value);
398 static void RecordProperty(const std::string& key, int value);
399
400 protected:
401 // Creates a Test object.
402 Test();
403
404 // Sets up the test fixture.
405 virtual void SetUp();
406
407 // Tears down the test fixture.
408 virtual void TearDown();
409
410 private:
411 // Returns true iff the current test has the same fixture class as
412 // the first test in the current test case.
413 static bool HasSameFixtureClass();
414
415 // Runs the test after the test fixture has been set up.
416 //
417 // A sub-class must implement this to define the test logic.
418 //
419 // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
420 // Instead, use the TEST or TEST_F macro.
421 virtual void TestBody() = 0;
422
423 // Sets up, executes, and tears down the test.
424 void Run();
425
426 // Deletes self. We deliberately pick an unusual name for this
427 // internal method to avoid clashing with names used in user TESTs.
428 void DeleteSelf_() { delete this; }
429
430 // Uses a GTestFlagSaver to save and restore all Google Test flags.
431 const internal::GTestFlagSaver* const gtest_flag_saver_;
432
433 // Often a user mis-spells SetUp() as Setup() and spends a long time
434 // wondering why it is never called by Google Test. The declaration of
435 // the following method is solely for catching such an error at
436 // compile time:
437 //
438 // - The return type is deliberately chosen to be not void, so it
439 // will be a conflict if a user declares void Setup() in his test
440 // fixture.
441 //
442 // - This method is private, so it will be another compiler error
443 // if a user calls it from his test fixture.
444 //
445 // DO NOT OVERRIDE THIS FUNCTION.
446 //
447 // If you see an error about overriding the following function or
448 // about it being private, you have mis-spelled SetUp() as Setup().
449 struct Setup_should_be_spelled_SetUp {};
450 virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
451
452 // We disallow copying Tests.
453 GTEST_DISALLOW_COPY_AND_ASSIGN_(Test);
454 };
455
456 typedef internal::TimeInMillis TimeInMillis;
457
458 // A copyable object representing a user specified test property which can be
459 // output as a key/value string pair.
460 //
461 // Don't inherit from TestProperty as its destructor is not virtual.
462 class TestProperty {
463 public:
464 // C'tor. TestProperty does NOT have a default constructor.
465 // Always use this constructor (with parameters) to create a
466 // TestProperty object.
467 TestProperty(const std::string& a_key, const std::string& a_value) :
468 key_(a_key), value_(a_value) {
469 }
470
471 // Gets the user supplied key.
472 const char* key() const {
473 return key_.c_str();
474 }
475
476 // Gets the user supplied value.
477 const char* value() const {
478 return value_.c_str();
479 }
480
481 // Sets a new value, overriding the one supplied in the constructor.
482 void SetValue(const std::string& new_value) {
483 value_ = new_value;
484 }
485
486 private:
487 // The key supplied by the user.
488 std::string key_;
489 // The value supplied by the user.
490 std::string value_;
491 };
492
493 // The result of a single Test. This includes a list of
494 // TestPartResults, a list of TestProperties, a count of how many
495 // death tests there are in the Test, and how much time it took to run
496 // the Test.
497 //
498 // TestResult is not copyable.
499 class GTEST_API_ TestResult {
500 public:
501 // Creates an empty TestResult.
502 TestResult();
503
504 // D'tor. Do not inherit from TestResult.
505 ~TestResult();
506
507 // Gets the number of all test parts. This is the sum of the number
508 // of successful test parts and the number of failed test parts.
509 int total_part_count() const;
510
511 // Returns the number of the test properties.
512 int test_property_count() const;
513
514 // Returns true iff the test passed (i.e. no test part failed).
515 bool Passed() const { return !Failed(); }
516
517 // Returns true iff the test failed.
518 bool Failed() const;
519
520 // Returns true iff the test fatally failed.
521 bool HasFatalFailure() const;
522
523 // Returns true iff the test has a non-fatal failure.
524 bool HasNonfatalFailure() const;
525
526 // Returns the elapsed time, in milliseconds.
527 TimeInMillis elapsed_time() const { return elapsed_time_; }
528
529 // Returns the i-th test part result among all the results. i can range
530 // from 0 to test_property_count() - 1. If i is not in that range, aborts
531 // the program.
532 const TestPartResult& GetTestPartResult(int i) const;
533
534 // Returns the i-th test property. i can range from 0 to
535 // test_property_count() - 1. If i is not in that range, aborts the
536 // program.
537 const TestProperty& GetTestProperty(int i) const;
538
539 private:
540 friend class TestInfo;
541 friend class TestCase;
542 friend class UnitTest;
543 friend class internal::DefaultGlobalTestPartResultReporter;
544 friend class internal::ExecDeathTest;
545 friend class internal::TestResultAccessor;
546 friend class internal::UnitTestImpl;
547 friend class internal::WindowsDeathTest;
548
549 // Gets the vector of TestPartResults.
550 const std::vector<TestPartResult>& test_part_results() const {
551 return test_part_results_;
552 }
553
554 // Gets the vector of TestProperties.
555 const std::vector<TestProperty>& test_properties() const {
556 return test_properties_;
557 }
558
559 // Sets the elapsed time.
560 void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
561
562 // Adds a test property to the list. The property is validated and may add
563 // a non-fatal failure if invalid (e.g., if it conflicts with reserved
564 // key names). If a property is already recorded for the same key, the
565 // value will be updated, rather than storing multiple values for the same
566 // key. xml_element specifies the element for which the property is being
567 // recorded and is used for validation.
568 void RecordProperty(const std::string& xml_element,
569 const TestProperty& test_property);
570
571 // Adds a failure if the key is a reserved attribute of Google Test
572 // testcase tags. Returns true if the property is valid.
573 // TODO(russr): Validate attribute names are legal and human readable.
574 static bool ValidateTestProperty(const std::string& xml_element,
575 const TestProperty& test_property);
576
577 // Adds a test part result to the list.
578 void AddTestPartResult(const TestPartResult& test_part_result);
579
580 // Returns the death test count.
581 int death_test_count() const { return death_test_count_; }
582
583 // Increments the death test count, returning the new count.
584 int increment_death_test_count() { return ++death_test_count_; }
585
586 // Clears the test part results.
587 void ClearTestPartResults();
588
589 // Clears the object.
590 void Clear();
591
592 // Protects mutable state of the property vector and of owned
593 // properties, whose values may be updated.
594 internal::Mutex test_properites_mutex_;
595
596 // The vector of TestPartResults
597 std::vector<TestPartResult> test_part_results_;
598 // The vector of TestProperties
599 std::vector<TestProperty> test_properties_;
600 // Running count of death tests.
601 int death_test_count_;
602 // The elapsed time, in milliseconds.
603 TimeInMillis elapsed_time_;
604
605 // We disallow copying TestResult.
606 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestResult);
607 }; // class TestResult
608
609 // A TestInfo object stores the following information about a test:
610 //
611 // Test case name
612 // Test name
613 // Whether the test should be run
614 // A function pointer that creates the test object when invoked
615 // Test result
616 //
617 // The constructor of TestInfo registers itself with the UnitTest
618 // singleton such that the RUN_ALL_TESTS() macro knows which tests to
619 // run.
620 class GTEST_API_ TestInfo {
621 public:
622 // Destructs a TestInfo object. This function is not virtual, so
623 // don't inherit from TestInfo.
624 ~TestInfo();
625
626 // Returns the test case name.
627 const char* test_case_name() const { return test_case_name_.c_str(); }
628
629 // Returns the test name.
630 const char* name() const { return name_.c_str(); }
631
632 // Returns the name of the parameter type, or NULL if this is not a typed
633 // or a type-parameterized test.
634 const char* type_param() const {
635 if (type_param_.get() != NULL)
636 return type_param_->c_str();
637 return NULL;
638 }
639
640 // Returns the text representation of the value parameter, or NULL if this
641 // is not a value-parameterized test.
642 const char* value_param() const {
643 if (value_param_.get() != NULL)
644 return value_param_->c_str();
645 return NULL;
646 }
647
648 // Returns true if this test should run, that is if the test is not
649 // disabled (or it is disabled but the also_run_disabled_tests flag has
650 // been specified) and its full name matches the user-specified filter.
651 //
652 // Google Test allows the user to filter the tests by their full names.
653 // The full name of a test Bar in test case Foo is defined as
654 // "Foo.Bar". Only the tests that match the filter will run.
655 //
656 // A filter is a colon-separated list of glob (not regex) patterns,
657 // optionally followed by a '-' and a colon-separated list of
658 // negative patterns (tests to exclude). A test is run if it
659 // matches one of the positive patterns and does not match any of
660 // the negative patterns.
661 //
662 // For example, *A*:Foo.* is a filter that matches any string that
663 // contains the character 'A' or starts with "Foo.".
664 bool should_run() const { return should_run_; }
665
666 // Returns true iff this test will appear in the XML report.
667 bool is_reportable() const {
668 // For now, the XML report includes all tests matching the filter.
669 // In the future, we may trim tests that are excluded because of
670 // sharding.
671 return matches_filter_;
672 }
673
674 // Returns the result of the test.
675 const TestResult* result() const { return &result_; }
676
677 private:
678 #if GTEST_HAS_DEATH_TEST
679 friend class internal::DefaultDeathTestFactory;
680 #endif // GTEST_HAS_DEATH_TEST
681 friend class Test;
682 friend class TestCase;
683 friend class internal::UnitTestImpl;
684 friend class internal::StreamingListenerTest;
685 friend TestInfo* internal::MakeAndRegisterTestInfo(
686 const char* test_case_name,
687 const char* name,
688 const char* type_param,
689 const char* value_param,
690 internal::TypeId fixture_class_id,
691 Test::SetUpTestCaseFunc set_up_tc,
692 Test::TearDownTestCaseFunc tear_down_tc,
693 internal::TestFactoryBase* factory);
694
695 // Constructs a TestInfo object. The newly constructed instance assumes
696 // ownership of the factory object.
697 TestInfo(const std::string& test_case_name,
698 const std::string& name,
699 const char* a_type_param, // NULL if not a type-parameterized test
700 const char* a_value_param, // NULL if not a value-parameterized test
701 internal::TypeId fixture_class_id,
702 internal::TestFactoryBase* factory);
703
704 // Increments the number of death tests encountered in this test so
705 // far.
706 int increment_death_test_count() {
707 return result_.increment_death_test_count();
708 }
709
710 // Creates the test object, runs it, records its result, and then
711 // deletes it.
712 void Run();
713
714 static void ClearTestResult(TestInfo* test_info) {
715 test_info->result_.Clear();
716 }
717
718 // These fields are immutable properties of the test.
719 const std::string test_case_name_; // Test case name
720 const std::string name_; // Test name
721 // Name of the parameter type, or NULL if this is not a typed or a
722 // type-parameterized test.
723 const internal::scoped_ptr<const ::std::string> type_param_;
724 // Text representation of the value parameter, or NULL if this is not a
725 // value-parameterized test.
726 const internal::scoped_ptr<const ::std::string> value_param_;
727 const internal::TypeId fixture_class_id_; // ID of the test fixture class
728 bool should_run_; // True iff this test should run
729 bool is_disabled_; // True iff this test is disabled
730 bool matches_filter_; // True if this test matches the
731 // user-specified filter.
732 internal::TestFactoryBase* const factory_; // The factory that creates
733 // the test object
734
735 // This field is mutable and needs to be reset before running the
736 // test for the second time.
737 TestResult result_;
738
739 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestInfo);
740 };
741
742 // A test case, which consists of a vector of TestInfos.
743 //
744 // TestCase is not copyable.
745 class GTEST_API_ TestCase {
746 public:
747 // Creates a TestCase with the given name.
748 //
749 // TestCase does NOT have a default constructor. Always use this
750 // constructor to create a TestCase object.
751 //
752 // Arguments:
753 //
754 // name: name of the test case
755 // a_type_param: the name of the test's type parameter, or NULL if
756 // this is not a type-parameterized test.
757 // set_up_tc: pointer to the function that sets up the test case
758 // tear_down_tc: pointer to the function that tears down the test case
759 TestCase(const char* name, const char* a_type_param,
760 Test::SetUpTestCaseFunc set_up_tc,
761 Test::TearDownTestCaseFunc tear_down_tc);
762
763 // Destructor of TestCase.
764 virtual ~TestCase();
765
766 // Gets the name of the TestCase.
767 const char* name() const { return name_.c_str(); }
768
769 // Returns the name of the parameter type, or NULL if this is not a
770 // type-parameterized test case.
771 const char* type_param() const {
772 if (type_param_.get() != NULL)
773 return type_param_->c_str();
774 return NULL;
775 }
776
777 // Returns true if any test in this test case should run.
778 bool should_run() const { return should_run_; }
779
780 // Gets the number of successful tests in this test case.
781 int successful_test_count() const;
782
783 // Gets the number of failed tests in this test case.
784 int failed_test_count() const;
785
786 // Gets the number of disabled tests that will be reported in the XML report.
787 int reportable_disabled_test_count() const;
788
789 // Gets the number of disabled tests in this test case.
790 int disabled_test_count() const;
791
792 // Gets the number of tests to be printed in the XML report.
793 int reportable_test_count() const;
794
795 // Get the number of tests in this test case that should run.
796 int test_to_run_count() const;
797
798 // Gets the number of all tests in this test case.
799 int total_test_count() const;
800
801 // Returns true iff the test case passed.
802 bool Passed() const { return !Failed(); }
803
804 // Returns true iff the test case failed.
805 bool Failed() const { return failed_test_count() > 0; }
806
807 // Returns the elapsed time, in milliseconds.
808 TimeInMillis elapsed_time() const { return elapsed_time_; }
809
810 // Returns the i-th test among all the tests. i can range from 0 to
811 // total_test_count() - 1. If i is not in that range, returns NULL.
812 const TestInfo* GetTestInfo(int i) const;
813
814 // Returns the TestResult that holds test properties recorded during
815 // execution of SetUpTestCase and TearDownTestCase.
816 const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
817
818 private:
819 friend class Test;
820 friend class internal::UnitTestImpl;
821
822 // Gets the (mutable) vector of TestInfos in this TestCase.
823 std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
824
825 // Gets the (immutable) vector of TestInfos in this TestCase.
826 const std::vector<TestInfo*>& test_info_list() const {
827 return test_info_list_;
828 }
829
830 // Returns the i-th test among all the tests. i can range from 0 to
831 // total_test_count() - 1. If i is not in that range, returns NULL.
832 TestInfo* GetMutableTestInfo(int i);
833
834 // Sets the should_run member.
835 void set_should_run(bool should) { should_run_ = should; }
836
837 // Adds a TestInfo to this test case. Will delete the TestInfo upon
838 // destruction of the TestCase object.
839 void AddTestInfo(TestInfo * test_info);
840
841 // Clears the results of all tests in this test case.
842 void ClearResult();
843
844 // Clears the results of all tests in the given test case.
845 static void ClearTestCaseResult(TestCase* test_case) {
846 test_case->ClearResult();
847 }
848
849 // Runs every test in this TestCase.
850 void Run();
851
852 // Runs SetUpTestCase() for this TestCase. This wrapper is needed
853 // for catching exceptions thrown from SetUpTestCase().
854 void RunSetUpTestCase() { (*set_up_tc_)(); }
855
856 // Runs TearDownTestCase() for this TestCase. This wrapper is
857 // needed for catching exceptions thrown from TearDownTestCase().
858 void RunTearDownTestCase() { (*tear_down_tc_)(); }
859
860 // Returns true iff test passed.
861 static bool TestPassed(const TestInfo* test_info) {
862 return test_info->should_run() && test_info->result()->Passed();
863 }
864
865 // Returns true iff test failed.
866 static bool TestFailed(const TestInfo* test_info) {
867 return test_info->should_run() && test_info->result()->Failed();
868 }
869
870 // Returns true iff the test is disabled and will be reported in the XML
871 // report.
872 static bool TestReportableDisabled(const TestInfo* test_info) {
873 return test_info->is_reportable() && test_info->is_disabled_;
874 }
875
876 // Returns true iff test is disabled.
877 static bool TestDisabled(const TestInfo* test_info) {
878 return test_info->is_disabled_;
879 }
880
881 // Returns true iff this test will appear in the XML report.
882 static bool TestReportable(const TestInfo* test_info) {
883 return test_info->is_reportable();
884 }
885
886 // Returns true if the given test should run.
887 static bool ShouldRunTest(const TestInfo* test_info) {
888 return test_info->should_run();
889 }
890
891 // Shuffles the tests in this test case.
892 void ShuffleTests(internal::Random* random);
893
894 // Restores the test order to before the first shuffle.
895 void UnshuffleTests();
896
897 // Name of the test case.
898 std::string name_;
899 // Name of the parameter type, or NULL if this is not a typed or a
900 // type-parameterized test.
901 const internal::scoped_ptr<const ::std::string> type_param_;
902 // The vector of TestInfos in their original order. It owns the
903 // elements in the vector.
904 std::vector<TestInfo*> test_info_list_;
905 // Provides a level of indirection for the test list to allow easy
906 // shuffling and restoring the test order. The i-th element in this
907 // vector is the index of the i-th test in the shuffled test list.
908 std::vector<int> test_indices_;
909 // Pointer to the function that sets up the test case.
910 Test::SetUpTestCaseFunc set_up_tc_;
911 // Pointer to the function that tears down the test case.
912 Test::TearDownTestCaseFunc tear_down_tc_;
913 // True iff any test in this test case should run.
914 bool should_run_;
915 // Elapsed time, in milliseconds.
916 TimeInMillis elapsed_time_;
917 // Holds test properties recorded during execution of SetUpTestCase and
918 // TearDownTestCase.
919 TestResult ad_hoc_test_result_;
920
921 // We disallow copying TestCases.
922 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestCase);
923 };
924
925 // An Environment object is capable of setting up and tearing down an
926 // environment. The user should subclass this to define his own
927 // environment(s).
928 //
929 // An Environment object does the set-up and tear-down in virtual
930 // methods SetUp() and TearDown() instead of the constructor and the
931 // destructor, as:
932 //
933 // 1. You cannot safely throw from a destructor. This is a problem
934 // as in some cases Google Test is used where exceptions are enabled, and
935 // we may want to implement ASSERT_* using exceptions where they are
936 // available.
937 // 2. You cannot use ASSERT_* directly in a constructor or
938 // destructor.
939 class Environment {
940 public:
941 // The d'tor is virtual as we need to subclass Environment.
942 virtual ~Environment() {}
943
944 // Override this to define how to set up the environment.
945 virtual void SetUp() {}
946
947 // Override this to define how to tear down the environment.
948 virtual void TearDown() {}
949 private:
950 // If you see an error about overriding the following function or
951 // about it being private, you have mis-spelled SetUp() as Setup().
952 struct Setup_should_be_spelled_SetUp {};
953 virtual Setup_should_be_spelled_SetUp* Setup() { return NULL; }
954 };
955
956 // The interface for tracing execution of tests. The methods are organized in
957 // the order the corresponding events are fired.
958 class TestEventListener {
959 public:
960 virtual ~TestEventListener() {}
961
962 // Fired before any test activity starts.
963 virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
964
965 // Fired before each iteration of tests starts. There may be more than
966 // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
967 // index, starting from 0.
968 virtual void OnTestIterationStart(const UnitTest& unit_test,
969 int iteration) = 0;
970
971 // Fired before environment set-up for each iteration of tests starts.
972 virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
973
974 // Fired after environment set-up for each iteration of tests ends.
975 virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
976
977 // Fired before the test case starts.
978 virtual void OnTestCaseStart(const TestCase& test_case) = 0;
979
980 // Fired before the test starts.
981 virtual void OnTestStart(const TestInfo& test_info) = 0;
982
983 // Fired after a failed assertion or a SUCCEED() invocation.
984 virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
985
986 // Fired after the test ends.
987 virtual void OnTestEnd(const TestInfo& test_info) = 0;
988
989 // Fired after the test case ends.
990 virtual void OnTestCaseEnd(const TestCase& test_case) = 0;
991
992 // Fired before environment tear-down for each iteration of tests starts.
993 virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
994
995 // Fired after environment tear-down for each iteration of tests ends.
996 virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
997
998 // Fired after each iteration of tests finishes.
999 virtual void OnTestIterationEnd(const UnitTest& unit_test,
1000 int iteration) = 0;
1001
1002 // Fired after all test activities have ended.
1003 virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
1004 };
1005
1006 // The convenience class for users who need to override just one or two
1007 // methods and are not concerned that a possible change to a signature of
1008 // the methods they override will not be caught during the build. For
1009 // comments about each method please see the definition of TestEventListener
1010 // above.
1011 class EmptyTestEventListener : public TestEventListener {
1012 public:
1013 virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
1014 virtual void OnTestIterationStart(const UnitTest& /*unit_test*/,
1015 int /*iteration*/) {}
1016 virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {}
1017 virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
1018 virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
1019 virtual void OnTestStart(const TestInfo& /*test_info*/) {}
1020 virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {}
1021 virtual void OnTestEnd(const TestInfo& /*test_info*/) {}
1022 virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
1023 virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {}
1024 virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
1025 virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/,
1026 int /*iteration*/) {}
1027 virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
1028 };
1029
1030 // TestEventListeners lets users add listeners to track events in Google Test.
1031 class GTEST_API_ TestEventListeners {
1032 public:
1033 TestEventListeners();
1034 ~TestEventListeners();
1035
1036 // Appends an event listener to the end of the list. Google Test assumes
1037 // the ownership of the listener (i.e. it will delete the listener when
1038 // the test program finishes).
1039 void Append(TestEventListener* listener);
1040
1041 // Removes the given event listener from the list and returns it. It then
1042 // becomes the caller's responsibility to delete the listener. Returns
1043 // NULL if the listener is not found in the list.
1044 TestEventListener* Release(TestEventListener* listener);
1045
1046 // Returns the standard listener responsible for the default console
1047 // output. Can be removed from the listeners list to shut down default
1048 // console output. Note that removing this object from the listener list
1049 // with Release transfers its ownership to the caller and makes this
1050 // function return NULL the next time.
1051 TestEventListener* default_result_printer() const {
1052 return default_result_printer_;
1053 }
1054
1055 // Returns the standard listener responsible for the default XML output
1056 // controlled by the --gtest_output=xml flag. Can be removed from the
1057 // listeners list by users who want to shut down the default XML output
1058 // controlled by this flag and substitute it with custom one. Note that
1059 // removing this object from the listener list with Release transfers its
1060 // ownership to the caller and makes this function return NULL the next
1061 // time.
1062 TestEventListener* default_xml_generator() const {
1063 return default_xml_generator_;
1064 }
1065
1066 private:
1067 friend class TestCase;
1068 friend class TestInfo;
1069 friend class internal::DefaultGlobalTestPartResultReporter;
1070 friend class internal::NoExecDeathTest;
1071 friend class internal::TestEventListenersAccessor;
1072 friend class internal::UnitTestImpl;
1073
1074 // Returns repeater that broadcasts the TestEventListener events to all
1075 // subscribers.
1076 TestEventListener* repeater();
1077
1078 // Sets the default_result_printer attribute to the provided listener.
1079 // The listener is also added to the listener list and previous
1080 // default_result_printer is removed from it and deleted. The listener can
1081 // also be NULL in which case it will not be added to the list. Does
1082 // nothing if the previous and the current listener objects are the same.
1083 void SetDefaultResultPrinter(TestEventListener* listener);
1084
1085 // Sets the default_xml_generator attribute to the provided listener. The
1086 // listener is also added to the listener list and previous
1087 // default_xml_generator is removed from it and deleted. The listener can
1088 // also be NULL in which case it will not be added to the list. Does
1089 // nothing if the previous and the current listener objects are the same.
1090 void SetDefaultXmlGenerator(TestEventListener* listener);
1091
1092 // Controls whether events will be forwarded by the repeater to the
1093 // listeners in the list.
1094 bool EventForwardingEnabled() const;
1095 void SuppressEventForwarding();
1096
1097 // The actual list of listeners.
1098 internal::TestEventRepeater* repeater_;
1099 // Listener responsible for the standard result output.
1100 TestEventListener* default_result_printer_;
1101 // Listener responsible for the creation of the XML output file.
1102 TestEventListener* default_xml_generator_;
1103
1104 // We disallow copying TestEventListeners.
1105 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners);
1106 };
1107
1108 // A UnitTest consists of a vector of TestCases.
1109 //
1110 // This is a singleton class. The only instance of UnitTest is
1111 // created when UnitTest::GetInstance() is first called. This
1112 // instance is never deleted.
1113 //
1114 // UnitTest is not copyable.
1115 //
1116 // This class is thread-safe as long as the methods are called
1117 // according to their specification.
1118 class GTEST_API_ UnitTest {
1119 public:
1120 // Gets the singleton UnitTest object. The first time this method
1121 // is called, a UnitTest object is constructed and returned.
1122 // Consecutive calls will return the same object.
1123 static UnitTest* GetInstance();
1124
1125 // Runs all tests in this UnitTest object and prints the result.
1126 // Returns 0 if successful, or 1 otherwise.
1127 //
1128 // This method can only be called from the main thread.
1129 //
1130 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1131 int Run() GTEST_MUST_USE_RESULT_;
1132
1133 // Returns the working directory when the first TEST() or TEST_F()
1134 // was executed. The UnitTest object owns the string.
1135 const char* original_working_dir() const;
1136
1137 // Returns the TestCase object for the test that's currently running,
1138 // or NULL if no test is running.
1139 const TestCase* current_test_case() const
1140 GTEST_LOCK_EXCLUDED_(mutex_);
1141
1142 // Returns the TestInfo object for the test that's currently running,
1143 // or NULL if no test is running.
1144 const TestInfo* current_test_info() const
1145 GTEST_LOCK_EXCLUDED_(mutex_);
1146
1147 // Returns the random seed used at the start of the current test run.
1148 int random_seed() const;
1149
1150 #if GTEST_HAS_PARAM_TEST
1151 // Returns the ParameterizedTestCaseRegistry object used to keep track of
1152 // value-parameterized tests and instantiate and register them.
1153 //
1154 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1155 internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
1156 GTEST_LOCK_EXCLUDED_(mutex_);
1157 #endif // GTEST_HAS_PARAM_TEST
1158
1159 // Gets the number of successful test cases.
1160 int successful_test_case_count() const;
1161
1162 // Gets the number of failed test cases.
1163 int failed_test_case_count() const;
1164
1165 // Gets the number of all test cases.
1166 int total_test_case_count() const;
1167
1168 // Gets the number of all test cases that contain at least one test
1169 // that should run.
1170 int test_case_to_run_count() const;
1171
1172 // Gets the number of successful tests.
1173 int successful_test_count() const;
1174
1175 // Gets the number of failed tests.
1176 int failed_test_count() const;
1177
1178 // Gets the number of disabled tests that will be reported in the XML report.
1179 int reportable_disabled_test_count() const;
1180
1181 // Gets the number of disabled tests.
1182 int disabled_test_count() const;
1183
1184 // Gets the number of tests to be printed in the XML report.
1185 int reportable_test_count() const;
1186
1187 // Gets the number of all tests.
1188 int total_test_count() const;
1189
1190 // Gets the number of tests that should run.
1191 int test_to_run_count() const;
1192
1193 // Gets the time of the test program start, in ms from the start of the
1194 // UNIX epoch.
1195 TimeInMillis start_timestamp() const;
1196
1197 // Gets the elapsed time, in milliseconds.
1198 TimeInMillis elapsed_time() const;
1199
1200 // Returns true iff the unit test passed (i.e. all test cases passed).
1201 bool Passed() const;
1202
1203 // Returns true iff the unit test failed (i.e. some test case failed
1204 // or something outside of all tests failed).
1205 bool Failed() const;
1206
1207 // Gets the i-th test case among all the test cases. i can range from 0 to
1208 // total_test_case_count() - 1. If i is not in that range, returns NULL.
1209 const TestCase* GetTestCase(int i) const;
1210
1211 // Returns the TestResult containing information on test failures and
1212 // properties logged outside of individual test cases.
1213 const TestResult& ad_hoc_test_result() const;
1214
1215 // Returns the list of event listeners that can be used to track events
1216 // inside Google Test.
1217 TestEventListeners& listeners();
1218
1219 private:
1220 // Registers and returns a global test environment. When a test
1221 // program is run, all global test environments will be set-up in
1222 // the order they were registered. After all tests in the program
1223 // have finished, all global test environments will be torn-down in
1224 // the *reverse* order they were registered.
1225 //
1226 // The UnitTest object takes ownership of the given environment.
1227 //
1228 // This method can only be called from the main thread.
1229 Environment* AddEnvironment(Environment* env);
1230
1231 // Adds a TestPartResult to the current TestResult object. All
1232 // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
1233 // eventually call this to report their results. The user code
1234 // should use the assertion macros instead of calling this directly.
1235 void AddTestPartResult(TestPartResult::Type result_type,
1236 const char* file_name,
1237 int line_number,
1238 const std::string& message,
1239 const std::string& os_stack_trace)
1240 GTEST_LOCK_EXCLUDED_(mutex_);
1241
1242 // Adds a TestProperty to the current TestResult object when invoked from
1243 // inside a test, to current TestCase's ad_hoc_test_result_ when invoked
1244 // from SetUpTestCase or TearDownTestCase, or to the global property set
1245 // when invoked elsewhere. If the result already contains a property with
1246 // the same key, the value will be updated.
1247 void RecordProperty(const std::string& key, const std::string& value);
1248
1249 // Gets the i-th test case among all the test cases. i can range from 0 to
1250 // total_test_case_count() - 1. If i is not in that range, returns NULL.
1251 TestCase* GetMutableTestCase(int i);
1252
1253 // Accessors for the implementation object.
1254 internal::UnitTestImpl* impl() { return impl_; }
1255 const internal::UnitTestImpl* impl() const { return impl_; }
1256
1257 // These classes and funcions are friends as they need to access private
1258 // members of UnitTest.
1259 friend class Test;
1260 friend class internal::AssertHelper;
1261 friend class internal::ScopedTrace;
1262 friend class internal::StreamingListenerTest;
1263 friend class internal::UnitTestRecordPropertyTestHelper;
1264 friend Environment* AddGlobalTestEnvironment(Environment* env);
1265 friend internal::UnitTestImpl* internal::GetUnitTestImpl();
1266 friend void internal::ReportFailureInUnknownLocation(
1267 TestPartResult::Type result_type,
1268 const std::string& message);
1269
1270 // Creates an empty UnitTest.
1271 UnitTest();
1272
1273 // D'tor
1274 virtual ~UnitTest();
1275
1276 // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
1277 // Google Test trace stack.
1278 void PushGTestTrace(const internal::TraceInfo& trace)
1279 GTEST_LOCK_EXCLUDED_(mutex_);
1280
1281 // Pops a trace from the per-thread Google Test trace stack.
1282 void PopGTestTrace()
1283 GTEST_LOCK_EXCLUDED_(mutex_);
1284
1285 // Protects mutable state in *impl_. This is mutable as some const
1286 // methods need to lock it too.
1287 mutable internal::Mutex mutex_;
1288
1289 // Opaque implementation object. This field is never changed once
1290 // the object is constructed. We don't mark it as const here, as
1291 // doing so will cause a warning in the constructor of UnitTest.
1292 // Mutable state in *impl_ is protected by mutex_.
1293 internal::UnitTestImpl* impl_;
1294
1295 // We disallow copying UnitTest.
1296 GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTest);
1297 };
1298
1299 // A convenient wrapper for adding an environment for the test
1300 // program.
1301 //
1302 // You should call this before RUN_ALL_TESTS() is called, probably in
1303 // main(). If you use gtest_main, you need to call this before main()
1304 // starts for it to take effect. For example, you can define a global
1305 // variable like this:
1306 //
1307 // testing::Environment* const foo_env =
1308 // testing::AddGlobalTestEnvironment(new FooEnvironment);
1309 //
1310 // However, we strongly recommend you to write your own main() and
1311 // call AddGlobalTestEnvironment() there, as relying on initialization
1312 // of global variables makes the code harder to read and may cause
1313 // problems when you register multiple environments from different
1314 // translation units and the environments have dependencies among them
1315 // (remember that the compiler doesn't guarantee the order in which
1316 // global variables from different translation units are initialized).
1317 inline Environment* AddGlobalTestEnvironment(Environment* env) {
1318 return UnitTest::GetInstance()->AddEnvironment(env);
1319 }
1320
1321 // Initializes Google Test. This must be called before calling
1322 // RUN_ALL_TESTS(). In particular, it parses a command line for the
1323 // flags that Google Test recognizes. Whenever a Google Test flag is
1324 // seen, it is removed from argv, and *argc is decremented.
1325 //
1326 // No value is returned. Instead, the Google Test flag variables are
1327 // updated.
1328 //
1329 // Calling the function for the second time has no user-visible effect.
1330 GTEST_API_ void InitGoogleTest(int* argc, char** argv);
1331
1332 // This overloaded version can be used in Windows programs compiled in
1333 // UNICODE mode.
1334 GTEST_API_ void InitGoogleTest(int* argc, wchar_t** argv);
1335
1336 namespace internal {
1337
1338 // FormatForComparison<ToPrint, OtherOperand>::Format(value) formats a
1339 // value of type ToPrint that is an operand of a comparison assertion
1340 // (e.g. ASSERT_EQ). OtherOperand is the type of the other operand in
1341 // the comparison, and is used to help determine the best way to
1342 // format the value. In particular, when the value is a C string
1343 // (char pointer) and the other operand is an STL string object, we
1344 // want to format the C string as a string, since we know it is
1345 // compared by value with the string object. If the value is a char
1346 // pointer but the other operand is not an STL string object, we don't
1347 // know whether the pointer is supposed to point to a NUL-terminated
1348 // string, and thus want to print it as a pointer to be safe.
1349 //
1350 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1351
1352 // The default case.
1353 template <typename ToPrint, typename OtherOperand>
1354 class FormatForComparison {
1355 public:
1356 static ::std::string Format(const ToPrint& value) {
1357 return ::testing::PrintToString(value);
1358 }
1359 };
1360
1361 // Array.
1362 template <typename ToPrint, size_t N, typename OtherOperand>
1363 class FormatForComparison<ToPrint[N], OtherOperand> {
1364 public:
1365 static ::std::string Format(const ToPrint* value) {
1366 return FormatForComparison<const ToPrint*, OtherOperand>::Format(value);
1367 }
1368 };
1369
1370 // By default, print C string as pointers to be safe, as we don't know
1371 // whether they actually point to a NUL-terminated string.
1372
1373 #define GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(CharType) \
1374 template <typename OtherOperand> \
1375 class FormatForComparison<CharType*, OtherOperand> { \
1376 public: \
1377 static ::std::string Format(CharType* value) { \
1378 return ::testing::PrintToString(static_cast<const void*>(value)); \
1379 } \
1380 }
1381
1382 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(char);
1383 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const char);
1384 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(wchar_t);
1385 GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_(const wchar_t);
1386
1387 #undef GTEST_IMPL_FORMAT_C_STRING_AS_POINTER_
1388
1389 // If a C string is compared with an STL string object, we know it's meant
1390 // to point to a NUL-terminated string, and thus can print it as a string.
1391
1392 #define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
1393 template <> \
1394 class FormatForComparison<CharType*, OtherStringType> { \
1395 public: \
1396 static ::std::string Format(CharType* value) { \
1397 return ::testing::PrintToString(value); \
1398 } \
1399 }
1400
1401 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::std::string);
1402 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::std::string);
1403
1404 #if GTEST_HAS_GLOBAL_STRING
1405 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, ::string);
1406 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, ::string);
1407 #endif
1408
1409 #if GTEST_HAS_GLOBAL_WSTRING
1410 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::wstring);
1411 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::wstring);
1412 #endif
1413
1414 #if GTEST_HAS_STD_WSTRING
1415 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(wchar_t, ::std::wstring);
1416 GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const wchar_t, ::std::wstring);
1417 #endif
1418
1419 #undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
1420
1421 // Formats a comparison assertion (e.g. ASSERT_EQ, EXPECT_LT, and etc)
1422 // operand to be used in a failure message. The type (but not value)
1423 // of the other operand may affect the format. This allows us to
1424 // print a char* as a raw pointer when it is compared against another
1425 // char* or void*, and print it as a C string when it is compared
1426 // against an std::string object, for example.
1427 //
1428 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1429 template <typename T1, typename T2>
1430 std::string FormatForComparisonFailureMessage(
1431 const T1& value, const T2& /* other_operand */) {
1432 return FormatForComparison<T1, T2>::Format(value);
1433 }
1434
1435 // The helper function for {ASSERT|EXPECT}_EQ.
1436 template <typename T1, typename T2>
1437 AssertionResult CmpHelperEQ(const char* expected_expression,
1438 const char* actual_expression,
1439 const T1& expected,
1440 const T2& actual) {
1441 #ifdef _MSC_VER
1442 # pragma warning(push) // Saves the current warning state.
1443 # pragma warning(disable:4389) // Temporarily disables warning on
1444 // signed/unsigned mismatch.
1445 #endif
1446
1447 if (expected == actual) {
1448 return AssertionSuccess();
1449 }
1450
1451 #ifdef _MSC_VER
1452 # pragma warning(pop) // Restores the warning state.
1453 #endif
1454
1455 return EqFailure(expected_expression,
1456 actual_expression,
1457 FormatForComparisonFailureMessage(expected, actual),
1458 FormatForComparisonFailureMessage(actual, expected),
1459 false);
1460 }
1461
1462 // With this overloaded version, we allow anonymous enums to be used
1463 // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous enums
1464 // can be implicitly cast to BiggestInt.
1465 GTEST_API_ AssertionResult CmpHelperEQ(const char* expected_expression,
1466 const char* actual_expression,
1467 BiggestInt expected,
1468 BiggestInt actual);
1469
1470 // The helper class for {ASSERT|EXPECT}_EQ. The template argument
1471 // lhs_is_null_literal is true iff the first argument to ASSERT_EQ()
1472 // is a null pointer literal. The following default implementation is
1473 // for lhs_is_null_literal being false.
1474 template <bool lhs_is_null_literal>
1475 class EqHelper {
1476 public:
1477 // This templatized version is for the general case.
1478 template <typename T1, typename T2>
1479 static AssertionResult Compare(const char* expected_expression,
1480 const char* actual_expression,
1481 const T1& expected,
1482 const T2& actual) {
1483 return CmpHelperEQ(expected_expression, actual_expression, expected,
1484 actual);
1485 }
1486
1487 // With this overloaded version, we allow anonymous enums to be used
1488 // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
1489 // enums can be implicitly cast to BiggestInt.
1490 //
1491 // Even though its body looks the same as the above version, we
1492 // cannot merge the two, as it will make anonymous enums unhappy.
1493 static AssertionResult Compare(const char* expected_expression,
1494 const char* actual_expression,
1495 BiggestInt expected,
1496 BiggestInt actual) {
1497 return CmpHelperEQ(expected_expression, actual_expression, expected,
1498 actual);
1499 }
1500 };
1501
1502 // This specialization is used when the first argument to ASSERT_EQ()
1503 // is a null pointer literal, like NULL, false, or 0.
1504 template <>
1505 class EqHelper<true> {
1506 public:
1507 // We define two overloaded versions of Compare(). The first
1508 // version will be picked when the second argument to ASSERT_EQ() is
1509 // NOT a pointer, e.g. ASSERT_EQ(0, AnIntFunction()) or
1510 // EXPECT_EQ(false, a_bool).
1511 template <typename T1, typename T2>
1512 static AssertionResult Compare(
1513 const char* expected_expression,
1514 const char* actual_expression,
1515 const T1& expected,
1516 const T2& actual,
1517 // The following line prevents this overload from being considered if T2
1518 // is not a pointer type. We need this because ASSERT_EQ(NULL, my_ptr)
1519 // expands to Compare("", "", NULL, my_ptr), which requires a conversion
1520 // to match the Secret* in the other overload, which would otherwise make
1521 // this template match better.
1522 typename EnableIf<!is_pointer<T2>::value>::type* = 0) {
1523 return CmpHelperEQ(expected_expression, actual_expression, expected,
1524 actual);
1525 }
1526
1527 // This version will be picked when the second argument to ASSERT_EQ() is a
1528 // pointer, e.g. ASSERT_EQ(NULL, a_pointer).
1529 template <typename T>
1530 static AssertionResult Compare(
1531 const char* expected_expression,
1532 const char* actual_expression,
1533 // We used to have a second template parameter instead of Secret*. That
1534 // template parameter would deduce to 'long', making this a better match
1535 // than the first overload even without the first overload's EnableIf.
1536 // Unfortunately, gcc with -Wconversion-null warns when "passing NULL to
1537 // non-pointer argument" (even a deduced integral argument), so the old
1538 // implementation caused warnings in user code.
1539 Secret* /* expected (NULL) */,
1540 T* actual) {
1541 // We already know that 'expected' is a null pointer.
1542 return CmpHelperEQ(expected_expression, actual_expression,
1543 static_cast<T*>(NULL), actual);
1544 }
1545 };
1546
1547 // A macro for implementing the helper functions needed to implement
1548 // ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste
1549 // of similar code.
1550 //
1551 // For each templatized helper function, we also define an overloaded
1552 // version for BiggestInt in order to reduce code bloat and allow
1553 // anonymous enums to be used with {ASSERT|EXPECT}_?? when compiled
1554 // with gcc 4.
1555 //
1556 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1557 #define GTEST_IMPL_CMP_HELPER_(op_name, op)\
1558 template <typename T1, typename T2>\
1559 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
1560 const T1& val1, const T2& val2) {\
1561 if (val1 op val2) {\
1562 return AssertionSuccess();\
1563 } else {\
1564 return AssertionFailure() \
1565 << "Expected: (" << expr1 << ") " #op " (" << expr2\
1566 << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
1567 << " vs " << FormatForComparisonFailureMessage(val2, val1);\
1568 }\
1569 }\
1570 GTEST_API_ AssertionResult CmpHelper##op_name(\
1571 const char* expr1, const char* expr2, BiggestInt val1, BiggestInt val2)
1572
1573 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1574
1575 // Implements the helper function for {ASSERT|EXPECT}_NE
1576 GTEST_IMPL_CMP_HELPER_(NE, !=);
1577 // Implements the helper function for {ASSERT|EXPECT}_LE
1578 GTEST_IMPL_CMP_HELPER_(LE, <=);
1579 // Implements the helper function for {ASSERT|EXPECT}_LT
1580 GTEST_IMPL_CMP_HELPER_(LT, <);
1581 // Implements the helper function for {ASSERT|EXPECT}_GE
1582 GTEST_IMPL_CMP_HELPER_(GE, >=);
1583 // Implements the helper function for {ASSERT|EXPECT}_GT
1584 GTEST_IMPL_CMP_HELPER_(GT, >);
1585
1586 #undef GTEST_IMPL_CMP_HELPER_
1587
1588 // The helper function for {ASSERT|EXPECT}_STREQ.
1589 //
1590 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1591 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
1592 const char* actual_expression,
1593 const char* expected,
1594 const char* actual);
1595
1596 // The helper function for {ASSERT|EXPECT}_STRCASEEQ.
1597 //
1598 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1599 GTEST_API_ AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,
1600 const char* actual_expression,
1601 const char* expected,
1602 const char* actual);
1603
1604 // The helper function for {ASSERT|EXPECT}_STRNE.
1605 //
1606 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1607 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
1608 const char* s2_expression,
1609 const char* s1,
1610 const char* s2);
1611
1612 // The helper function for {ASSERT|EXPECT}_STRCASENE.
1613 //
1614 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1615 GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
1616 const char* s2_expression,
1617 const char* s1,
1618 const char* s2);
1619
1620
1621 // Helper function for *_STREQ on wide strings.
1622 //
1623 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1624 GTEST_API_ AssertionResult CmpHelperSTREQ(const char* expected_expression,
1625 const char* actual_expression,
1626 const wchar_t* expected,
1627 const wchar_t* actual);
1628
1629 // Helper function for *_STRNE on wide strings.
1630 //
1631 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1632 GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
1633 const char* s2_expression,
1634 const wchar_t* s1,
1635 const wchar_t* s2);
1636
1637 } // namespace internal
1638
1639 // IsSubstring() and IsNotSubstring() are intended to be used as the
1640 // first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
1641 // themselves. They check whether needle is a substring of haystack
1642 // (NULL is considered a substring of itself only), and return an
1643 // appropriate error message when they fail.
1644 //
1645 // The {needle,haystack}_expr arguments are the stringified
1646 // expressions that generated the two real arguments.
1647 GTEST_API_ AssertionResult IsSubstring(
1648 const char* needle_expr, const char* haystack_expr,
1649 const char* needle, const char* haystack);
1650 GTEST_API_ AssertionResult IsSubstring(
1651 const char* needle_expr, const char* haystack_expr,
1652 const wchar_t* needle, const wchar_t* haystack);
1653 GTEST_API_ AssertionResult IsNotSubstring(
1654 const char* needle_expr, const char* haystack_expr,
1655 const char* needle, const char* haystack);
1656 GTEST_API_ AssertionResult IsNotSubstring(
1657 const char* needle_expr, const char* haystack_expr,
1658 const wchar_t* needle, const wchar_t* haystack);
1659 GTEST_API_ AssertionResult IsSubstring(
1660 const char* needle_expr, const char* haystack_expr,
1661 const ::std::string& needle, const ::std::string& haystack);
1662 GTEST_API_ AssertionResult IsNotSubstring(
1663 const char* needle_expr, const char* haystack_expr,
1664 const ::std::string& needle, const ::std::string& haystack);
1665
1666 #if GTEST_HAS_STD_WSTRING
1667 GTEST_API_ AssertionResult IsSubstring(
1668 const char* needle_expr, const char* haystack_expr,
1669 const ::std::wstring& needle, const ::std::wstring& haystack);
1670 GTEST_API_ AssertionResult IsNotSubstring(
1671 const char* needle_expr, const char* haystack_expr,
1672 const ::std::wstring& needle, const ::std::wstring& haystack);
1673 #endif // GTEST_HAS_STD_WSTRING
1674
1675 namespace internal {
1676
1677 // Helper template function for comparing floating-points.
1678 //
1679 // Template parameter:
1680 //
1681 // RawType: the raw floating-point type (either float or double)
1682 //
1683 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1684 template <typename RawType>
1685 AssertionResult CmpHelperFloatingPointEQ(const char* expected_expression,
1686 const char* actual_expression,
1687 RawType expected,
1688 RawType actual) {
1689 const FloatingPoint<RawType> lhs(expected), rhs(actual);
1690
1691 if (lhs.AlmostEquals(rhs)) {
1692 return AssertionSuccess();
1693 }
1694
1695 ::std::stringstream expected_ss;
1696 expected_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1697 << expected;
1698
1699 ::std::stringstream actual_ss;
1700 actual_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1701 << actual;
1702
1703 return EqFailure(expected_expression,
1704 actual_expression,
1705 StringStreamToString(&expected_ss),
1706 StringStreamToString(&actual_ss),
1707 false);
1708 }
1709
1710 // Helper function for implementing ASSERT_NEAR.
1711 //
1712 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1713 GTEST_API_ AssertionResult DoubleNearPredFormat(const char* expr1,
1714 const char* expr2,
1715 const char* abs_error_expr,
1716 double val1,
1717 double val2,
1718 double abs_error);
1719
1720 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
1721 // A class that enables one to stream messages to assertion macros
1722 class GTEST_API_ AssertHelper {
1723 public:
1724 // Constructor.
1725 AssertHelper(TestPartResult::Type type,
1726 const char* file,
1727 int line,
1728 const char* message);
1729 ~AssertHelper();
1730
1731 // Message assignment is a semantic trick to enable assertion
1732 // streaming; see the GTEST_MESSAGE_ macro below.
1733 void operator=(const Message& message) const;
1734
1735 private:
1736 // We put our data in a struct so that the size of the AssertHelper class can
1737 // be as small as possible. This is important because gcc is incapable of
1738 // re-using stack space even for temporary variables, so every EXPECT_EQ
1739 // reserves stack space for another AssertHelper.
1740 struct AssertHelperData {
1741 AssertHelperData(TestPartResult::Type t,
1742 const char* srcfile,
1743 int line_num,
1744 const char* msg)
1745 : type(t), file(srcfile), line(line_num), message(msg) { }
1746
1747 TestPartResult::Type const type;
1748 const char* const file;
1749 int const line;
1750 std::string const message;
1751
1752 private:
1753 GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelperData);
1754 };
1755
1756 AssertHelperData* const data_;
1757
1758 GTEST_DISALLOW_COPY_AND_ASSIGN_(AssertHelper);
1759 };
1760
1761 } // namespace internal
1762
1763 #if GTEST_HAS_PARAM_TEST
1764 // The pure interface class that all value-parameterized tests inherit from.
1765 // A value-parameterized class must inherit from both ::testing::Test and
1766 // ::testing::WithParamInterface. In most cases that just means inheriting
1767 // from ::testing::TestWithParam, but more complicated test hierarchies
1768 // may need to inherit from Test and WithParamInterface at different levels.
1769 //
1770 // This interface has support for accessing the test parameter value via
1771 // the GetParam() method.
1772 //
1773 // Use it with one of the parameter generator defining functions, like Range(),
1774 // Values(), ValuesIn(), Bool(), and Combine().
1775 //
1776 // class FooTest : public ::testing::TestWithParam<int> {
1777 // protected:
1778 // FooTest() {
1779 // // Can use GetParam() here.
1780 // }
1781 // virtual ~FooTest() {
1782 // // Can use GetParam() here.
1783 // }
1784 // virtual void SetUp() {
1785 // // Can use GetParam() here.
1786 // }
1787 // virtual void TearDown {
1788 // // Can use GetParam() here.
1789 // }
1790 // };
1791 // TEST_P(FooTest, DoesBar) {
1792 // // Can use GetParam() method here.
1793 // Foo foo;
1794 // ASSERT_TRUE(foo.DoesBar(GetParam()));
1795 // }
1796 // INSTANTIATE_TEST_CASE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
1797
1798 template <typename T>
1799 class WithParamInterface {
1800 public:
1801 typedef T ParamType;
1802 virtual ~WithParamInterface() {}
1803
1804 // The current parameter value. Is also available in the test fixture's
1805 // constructor. This member function is non-static, even though it only
1806 // references static data, to reduce the opportunity for incorrect uses
1807 // like writing 'WithParamInterface<bool>::GetParam()' for a test that
1808 // uses a fixture whose parameter type is int.
1809 const ParamType& GetParam() const {
1810 GTEST_CHECK_(parameter_ != NULL)
1811 << "GetParam() can only be called inside a value-parameterized test "
1812 << "-- did you intend to write TEST_P instead of TEST_F?";
1813 return *parameter_;
1814 }
1815
1816 private:
1817 // Sets parameter value. The caller is responsible for making sure the value
1818 // remains alive and unchanged throughout the current test.
1819 static void SetParam(const ParamType* parameter) {
1820 parameter_ = parameter;
1821 }
1822
1823 // Static value used for accessing parameter during a test lifetime.
1824 static const ParamType* parameter_;
1825
1826 // TestClass must be a subclass of WithParamInterface<T> and Test.
1827 template <class TestClass> friend class internal::ParameterizedTestFactory;
1828 };
1829
1830 template <typename T>
1831 const T* WithParamInterface<T>::parameter_ = NULL;
1832
1833 // Most value-parameterized classes can ignore the existence of
1834 // WithParamInterface, and can just inherit from ::testing::TestWithParam.
1835
1836 template <typename T>
1837 class TestWithParam : public Test, public WithParamInterface<T> {
1838 };
1839
1840 #endif // GTEST_HAS_PARAM_TEST
1841
1842 // Macros for indicating success/failure in test code.
1843
1844 // ADD_FAILURE unconditionally adds a failure to the current test.
1845 // SUCCEED generates a success - it doesn't automatically make the
1846 // current test successful, as a test is only successful when it has
1847 // no failure.
1848 //
1849 // EXPECT_* verifies that a certain condition is satisfied. If not,
1850 // it behaves like ADD_FAILURE. In particular:
1851 //
1852 // EXPECT_TRUE verifies that a Boolean condition is true.
1853 // EXPECT_FALSE verifies that a Boolean condition is false.
1854 //
1855 // FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
1856 // that they will also abort the current function on failure. People
1857 // usually want the fail-fast behavior of FAIL and ASSERT_*, but those
1858 // writing data-driven tests often find themselves using ADD_FAILURE
1859 // and EXPECT_* more.
1860
1861 // Generates a nonfatal failure with a generic message.
1862 #define ADD_FAILURE() GTEST_NONFATAL_FAILURE_("Failed")
1863
1864 // Generates a nonfatal failure at the given source file location with
1865 // a generic message.
1866 #define ADD_FAILURE_AT(file, line) \
1867 GTEST_MESSAGE_AT_(file, line, "Failed", \
1868 ::testing::TestPartResult::kNonFatalFailure)
1869
1870 // Generates a fatal failure with a generic message.
1871 #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
1872
1873 // Define this macro to 1 to omit the definition of FAIL(), which is a
1874 // generic name and clashes with some other libraries.
1875 #if !GTEST_DONT_DEFINE_FAIL
1876 # define FAIL() GTEST_FAIL()
1877 #endif
1878
1879 // Generates a success with a generic message.
1880 #define GTEST_SUCCEED() GTEST_SUCCESS_("Succeeded")
1881
1882 // Define this macro to 1 to omit the definition of SUCCEED(), which
1883 // is a generic name and clashes with some other libraries.
1884 #if !GTEST_DONT_DEFINE_SUCCEED
1885 # define SUCCEED() GTEST_SUCCEED()
1886 #endif
1887
1888 // Macros for testing exceptions.
1889 //
1890 // * {ASSERT|EXPECT}_THROW(statement, expected_exception):
1891 // Tests that the statement throws the expected exception.
1892 // * {ASSERT|EXPECT}_NO_THROW(statement):
1893 // Tests that the statement doesn't throw any exception.
1894 // * {ASSERT|EXPECT}_ANY_THROW(statement):
1895 // Tests that the statement throws an exception.
1896
1897 #define EXPECT_THROW(statement, expected_exception) \
1898 GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)
1899 #define EXPECT_NO_THROW(statement) \
1900 GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)
1901 #define EXPECT_ANY_THROW(statement) \
1902 GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)
1903 #define ASSERT_THROW(statement, expected_exception) \
1904 GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)
1905 #define ASSERT_NO_THROW(statement) \
1906 GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)
1907 #define ASSERT_ANY_THROW(statement) \
1908 GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)
1909
1910 // Boolean assertions. Condition can be either a Boolean expression or an
1911 // AssertionResult. For more information on how to use AssertionResult with
1912 // these macros see comments on that class.
1913 #define EXPECT_TRUE(condition) \
1914 GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
1915 GTEST_NONFATAL_FAILURE_)
1916 #define EXPECT_FALSE(condition) \
1917 GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
1918 GTEST_NONFATAL_FAILURE_)
1919 #define ASSERT_TRUE(condition) \
1920 GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \
1921 GTEST_FATAL_FAILURE_)
1922 #define ASSERT_FALSE(condition) \
1923 GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \
1924 GTEST_FATAL_FAILURE_)
1925
1926 // Includes the auto-generated header that implements a family of
1927 // generic predicate assertion macros.
1928 #include "gtest/gtest_pred_impl.h"
1929
1930 // Macros for testing equalities and inequalities.
1931 //
1932 // * {ASSERT|EXPECT}_EQ(expected, actual): Tests that expected == actual
1933 // * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
1934 // * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
1935 // * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
1936 // * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
1937 // * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
1938 //
1939 // When they are not, Google Test prints both the tested expressions and
1940 // their actual values. The values must be compatible built-in types,
1941 // or you will get a compiler error. By "compatible" we mean that the
1942 // values can be compared by the respective operator.
1943 //
1944 // Note:
1945 //
1946 // 1. It is possible to make a user-defined type work with
1947 // {ASSERT|EXPECT}_??(), but that requires overloading the
1948 // comparison operators and is thus discouraged by the Google C++
1949 // Usage Guide. Therefore, you are advised to use the
1950 // {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
1951 // equal.
1952 //
1953 // 2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
1954 // pointers (in particular, C strings). Therefore, if you use it
1955 // with two C strings, you are testing how their locations in memory
1956 // are related, not how their content is related. To compare two C
1957 // strings by content, use {ASSERT|EXPECT}_STR*().
1958 //
1959 // 3. {ASSERT|EXPECT}_EQ(expected, actual) is preferred to
1960 // {ASSERT|EXPECT}_TRUE(expected == actual), as the former tells you
1961 // what the actual value is when it fails, and similarly for the
1962 // other comparisons.
1963 //
1964 // 4. Do not depend on the order in which {ASSERT|EXPECT}_??()
1965 // evaluate their arguments, which is undefined.
1966 //
1967 // 5. These macros evaluate their arguments exactly once.
1968 //
1969 // Examples:
1970 //
1971 // EXPECT_NE(5, Foo());
1972 // EXPECT_EQ(NULL, a_pointer);
1973 // ASSERT_LT(i, array_size);
1974 // ASSERT_GT(records.size(), 0) << "There is no record left.";
1975
1976 #define EXPECT_EQ(expected, actual) \
1977 EXPECT_PRED_FORMAT2(::testing::internal:: \
1978 EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
1979 expected, actual)
1980 #define EXPECT_NE(expected, actual) \
1981 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, expected, actual)
1982 #define EXPECT_LE(val1, val2) \
1983 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
1984 #define EXPECT_LT(val1, val2) \
1985 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
1986 #define EXPECT_GE(val1, val2) \
1987 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
1988 #define EXPECT_GT(val1, val2) \
1989 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
1990
1991 #define GTEST_ASSERT_EQ(expected, actual) \
1992 ASSERT_PRED_FORMAT2(::testing::internal:: \
1993 EqHelper<GTEST_IS_NULL_LITERAL_(expected)>::Compare, \
1994 expected, actual)
1995 #define GTEST_ASSERT_NE(val1, val2) \
1996 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)
1997 #define GTEST_ASSERT_LE(val1, val2) \
1998 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)
1999 #define GTEST_ASSERT_LT(val1, val2) \
2000 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)
2001 #define GTEST_ASSERT_GE(val1, val2) \
2002 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)
2003 #define GTEST_ASSERT_GT(val1, val2) \
2004 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)
2005
2006 // Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
2007 // ASSERT_XY(), which clashes with some users' own code.
2008
2009 #if !GTEST_DONT_DEFINE_ASSERT_EQ
2010 # define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
2011 #endif
2012
2013 #if !GTEST_DONT_DEFINE_ASSERT_NE
2014 # define ASSERT_NE(val1, val2) GTEST_ASSERT_NE(val1, val2)
2015 #endif
2016
2017 #if !GTEST_DONT_DEFINE_ASSERT_LE
2018 # define ASSERT_LE(val1, val2) GTEST_ASSERT_LE(val1, val2)
2019 #endif
2020
2021 #if !GTEST_DONT_DEFINE_ASSERT_LT
2022 # define ASSERT_LT(val1, val2) GTEST_ASSERT_LT(val1, val2)
2023 #endif
2024
2025 #if !GTEST_DONT_DEFINE_ASSERT_GE
2026 # define ASSERT_GE(val1, val2) GTEST_ASSERT_GE(val1, val2)
2027 #endif
2028
2029 #if !GTEST_DONT_DEFINE_ASSERT_GT
2030 # define ASSERT_GT(val1, val2) GTEST_ASSERT_GT(val1, val2)
2031 #endif
2032
2033 // C-string Comparisons. All tests treat NULL and any non-NULL string
2034 // as different. Two NULLs are equal.
2035 //
2036 // * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2
2037 // * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2
2038 // * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
2039 // * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
2040 //
2041 // For wide or narrow string objects, you can use the
2042 // {ASSERT|EXPECT}_??() macros.
2043 //
2044 // Don't depend on the order in which the arguments are evaluated,
2045 // which is undefined.
2046 //
2047 // These macros evaluate their arguments exactly once.
2048
2049 #define EXPECT_STREQ(expected, actual) \
2050 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
2051 #define EXPECT_STRNE(s1, s2) \
2052 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
2053 #define EXPECT_STRCASEEQ(expected, actual) \
2054 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
2055 #define EXPECT_STRCASENE(s1, s2)\
2056 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
2057
2058 #define ASSERT_STREQ(expected, actual) \
2059 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, expected, actual)
2060 #define ASSERT_STRNE(s1, s2) \
2061 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)
2062 #define ASSERT_STRCASEEQ(expected, actual) \
2063 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, expected, actual)
2064 #define ASSERT_STRCASENE(s1, s2)\
2065 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)
2066
2067 // Macros for comparing floating-point numbers.
2068 //
2069 // * {ASSERT|EXPECT}_FLOAT_EQ(expected, actual):
2070 // Tests that two float values are almost equal.
2071 // * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual):
2072 // Tests that two double values are almost equal.
2073 // * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
2074 // Tests that v1 and v2 are within the given distance to each other.
2075 //
2076 // Google Test uses ULP-based comparison to automatically pick a default
2077 // error bound that is appropriate for the operands. See the
2078 // FloatingPoint template class in gtest-internal.h if you are
2079 // interested in the implementation details.
2080
2081 #define EXPECT_FLOAT_EQ(expected, actual)\
2082 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
2083 expected, actual)
2084
2085 #define EXPECT_DOUBLE_EQ(expected, actual)\
2086 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
2087 expected, actual)
2088
2089 #define ASSERT_FLOAT_EQ(expected, actual)\
2090 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \
2091 expected, actual)
2092
2093 #define ASSERT_DOUBLE_EQ(expected, actual)\
2094 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \
2095 expected, actual)
2096
2097 #define EXPECT_NEAR(val1, val2, abs_error)\
2098 EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
2099 val1, val2, abs_error)
2100
2101 #define ASSERT_NEAR(val1, val2, abs_error)\
2102 ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, \
2103 val1, val2, abs_error)
2104
2105 // These predicate format functions work on floating-point values, and
2106 // can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
2107 //
2108 // EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
2109
2110 // Asserts that val1 is less than, or almost equal to, val2. Fails
2111 // otherwise. In particular, it fails if either val1 or val2 is NaN.
2112 GTEST_API_ AssertionResult FloatLE(const char* expr1, const char* expr2,
2113 float val1, float val2);
2114 GTEST_API_ AssertionResult DoubleLE(const char* expr1, const char* expr2,
2115 double val1, double val2);
2116
2117
2118 #if GTEST_OS_WINDOWS
2119
2120 // Macros that test for HRESULT failure and success, these are only useful
2121 // on Windows, and rely on Windows SDK macros and APIs to compile.
2122 //
2123 // * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
2124 //
2125 // When expr unexpectedly fails or succeeds, Google Test prints the
2126 // expected result and the actual result with both a human-readable
2127 // string representation of the error, if available, as well as the
2128 // hex result code.
2129 # define EXPECT_HRESULT_SUCCEEDED(expr) \
2130 EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
2131
2132 # define ASSERT_HRESULT_SUCCEEDED(expr) \
2133 ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))
2134
2135 # define EXPECT_HRESULT_FAILED(expr) \
2136 EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
2137
2138 # define ASSERT_HRESULT_FAILED(expr) \
2139 ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))
2140
2141 #endif // GTEST_OS_WINDOWS
2142
2143 // Macros that execute statement and check that it doesn't generate new fatal
2144 // failures in the current thread.
2145 //
2146 // * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
2147 //
2148 // Examples:
2149 //
2150 // EXPECT_NO_FATAL_FAILURE(Process());
2151 // ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
2152 //
2153 #define ASSERT_NO_FATAL_FAILURE(statement) \
2154 GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)
2155 #define EXPECT_NO_FATAL_FAILURE(statement) \
2156 GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)
2157
2158 // Causes a trace (including the source file path, the current line
2159 // number, and the given message) to be included in every test failure
2160 // message generated by code in the current scope. The effect is
2161 // undone when the control leaves the current scope.
2162 //
2163 // The message argument can be anything streamable to std::ostream.
2164 //
2165 // In the implementation, we include the current line number as part
2166 // of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
2167 // to appear in the same block - as long as they are on different
2168 // lines.
2169 #define SCOPED_TRACE(message) \
2170 ::testing::internal::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)(\
2171 __FILE__, __LINE__, ::testing::Message() << (message))
2172
2173 // Compile-time assertion for type equality.
2174 // StaticAssertTypeEq<type1, type2>() compiles iff type1 and type2 are
2175 // the same type. The value it returns is not interesting.
2176 //
2177 // Instead of making StaticAssertTypeEq a class template, we make it a
2178 // function template that invokes a helper class template. This
2179 // prevents a user from misusing StaticAssertTypeEq<T1, T2> by
2180 // defining objects of that type.
2181 //
2182 // CAVEAT:
2183 //
2184 // When used inside a method of a class template,
2185 // StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
2186 // instantiated. For example, given:
2187 //
2188 // template <typename T> class Foo {
2189 // public:
2190 // void Bar() { testing::StaticAssertTypeEq<int, T>(); }
2191 // };
2192 //
2193 // the code:
2194 //
2195 // void Test1() { Foo<bool> foo; }
2196 //
2197 // will NOT generate a compiler error, as Foo<bool>::Bar() is never
2198 // actually instantiated. Instead, you need:
2199 //
2200 // void Test2() { Foo<bool> foo; foo.Bar(); }
2201 //
2202 // to cause a compiler error.
2203 template <typename T1, typename T2>
2204 bool StaticAssertTypeEq() {
2205 (void)internal::StaticAssertTypeEqHelper<T1, T2>();
2206 return true;
2207 }
2208
2209 // Defines a test.
2210 //
2211 // The first parameter is the name of the test case, and the second
2212 // parameter is the name of the test within the test case.
2213 //
2214 // The convention is to end the test case name with "Test". For
2215 // example, a test case for the Foo class can be named FooTest.
2216 //
2217 // The user should put his test code between braces after using this
2218 // macro. Example:
2219 //
2220 // TEST(FooTest, InitializesCorrectly) {
2221 // Foo foo;
2222 // EXPECT_TRUE(foo.StatusIsOK());
2223 // }
2224
2225 // Note that we call GetTestTypeId() instead of GetTypeId<
2226 // ::testing::Test>() here to get the type ID of testing::Test. This
2227 // is to work around a suspected linker bug when using Google Test as
2228 // a framework on Mac OS X. The bug causes GetTypeId<
2229 // ::testing::Test>() to return different values depending on whether
2230 // the call is from the Google Test framework itself or from user test
2231 // code. GetTestTypeId() is guaranteed to always return the same
2232 // value, as it always calls GetTypeId<>() from the Google Test
2233 // framework.
2234 #define GTEST_TEST(test_case_name, test_name)\
2235 GTEST_TEST_(test_case_name, test_name, \
2236 ::testing::Test, ::testing::internal::GetTestTypeId())
2237
2238 // Define this macro to 1 to omit the definition of TEST(), which
2239 // is a generic name and clashes with some other libraries.
2240 #if !GTEST_DONT_DEFINE_TEST
2241 # define TEST(test_case_name, test_name) GTEST_TEST(test_case_name, test_name)
2242 #endif
2243
2244 // Defines a test that uses a test fixture.
2245 //
2246 // The first parameter is the name of the test fixture class, which
2247 // also doubles as the test case name. The second parameter is the
2248 // name of the test within the test case.
2249 //
2250 // A test fixture class must be declared earlier. The user should put
2251 // his test code between braces after using this macro. Example:
2252 //
2253 // class FooTest : public testing::Test {
2254 // protected:
2255 // virtual void SetUp() { b_.AddElement(3); }
2256 //
2257 // Foo a_;
2258 // Foo b_;
2259 // };
2260 //
2261 // TEST_F(FooTest, InitializesCorrectly) {
2262 // EXPECT_TRUE(a_.StatusIsOK());
2263 // }
2264 //
2265 // TEST_F(FooTest, ReturnsElementCountCorrectly) {
2266 // EXPECT_EQ(0, a_.size());
2267 // EXPECT_EQ(1, b_.size());
2268 // }
2269
2270 #define TEST_F(test_fixture, test_name)\
2271 GTEST_TEST_(test_fixture, test_name, test_fixture, \
2272 ::testing::internal::GetTypeId<test_fixture>())
2273
2274 } // namespace testing
2275
2276 // Use this function in main() to run all tests. It returns 0 if all
2277 // tests are successful, or 1 otherwise.
2278 //
2279 // RUN_ALL_TESTS() should be invoked after the command line has been
2280 // parsed by InitGoogleTest().
2281 //
2282 // This function was formerly a macro; thus, it is in the global
2283 // namespace and has an all-caps name.
2284 int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_;
2285
2286 inline int RUN_ALL_TESTS() {
2287 return ::testing::UnitTest::GetInstance()->Run();
2288 }
2289
2290 #endif // GTEST_INCLUDE_GTEST_GTEST_H_
0 // Copyright 2006, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 // This file is AUTOMATICALLY GENERATED on 10/31/2011 by command
30 // 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
31 //
32 // Implements a family of generic predicate assertion macros.
33
34 #ifndef GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
35 #define GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
36
37 // Makes sure this header is not included before gtest.h.
38 #ifndef GTEST_INCLUDE_GTEST_GTEST_H_
39 # error Do not include gtest_pred_impl.h directly. Include gtest.h instead.
40 #endif // GTEST_INCLUDE_GTEST_GTEST_H_
41
42 // This header implements a family of generic predicate assertion
43 // macros:
44 //
45 // ASSERT_PRED_FORMAT1(pred_format, v1)
46 // ASSERT_PRED_FORMAT2(pred_format, v1, v2)
47 // ...
48 //
49 // where pred_format is a function or functor that takes n (in the
50 // case of ASSERT_PRED_FORMATn) values and their source expression
51 // text, and returns a testing::AssertionResult. See the definition
52 // of ASSERT_EQ in gtest.h for an example.
53 //
54 // If you don't care about formatting, you can use the more
55 // restrictive version:
56 //
57 // ASSERT_PRED1(pred, v1)
58 // ASSERT_PRED2(pred, v1, v2)
59 // ...
60 //
61 // where pred is an n-ary function or functor that returns bool,
62 // and the values v1, v2, ..., must support the << operator for
63 // streaming to std::ostream.
64 //
65 // We also define the EXPECT_* variations.
66 //
67 // For now we only support predicates whose arity is at most 5.
68 // Please email googletestframework@googlegroups.com if you need
69 // support for higher arities.
70
71 // GTEST_ASSERT_ is the basic statement to which all of the assertions
72 // in this file reduce. Don't use this in your code.
73
74 #define GTEST_ASSERT_(expression, on_failure) \
75 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
76 if (const ::testing::AssertionResult gtest_ar = (expression)) \
77 ; \
78 else \
79 on_failure(gtest_ar.failure_message())
80
81
82 // Helper function for implementing {EXPECT|ASSERT}_PRED1. Don't use
83 // this in your code.
84 template <typename Pred,
85 typename T1>
86 AssertionResult AssertPred1Helper(const char* pred_text,
87 const char* e1,
88 Pred pred,
89 const T1& v1) {
90 if (pred(v1)) return AssertionSuccess();
91
92 return AssertionFailure() << pred_text << "("
93 << e1 << ") evaluates to false, where"
94 << "\n" << e1 << " evaluates to " << v1;
95 }
96
97 // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
98 // Don't use this in your code.
99 #define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure)\
100 GTEST_ASSERT_(pred_format(#v1, v1), \
101 on_failure)
102
103 // Internal macro for implementing {EXPECT|ASSERT}_PRED1. Don't use
104 // this in your code.
105 #define GTEST_PRED1_(pred, v1, on_failure)\
106 GTEST_ASSERT_(::testing::AssertPred1Helper(#pred, \
107 #v1, \
108 pred, \
109 v1), on_failure)
110
111 // Unary predicate assertion macros.
112 #define EXPECT_PRED_FORMAT1(pred_format, v1) \
113 GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_)
114 #define EXPECT_PRED1(pred, v1) \
115 GTEST_PRED1_(pred, v1, GTEST_NONFATAL_FAILURE_)
116 #define ASSERT_PRED_FORMAT1(pred_format, v1) \
117 GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_)
118 #define ASSERT_PRED1(pred, v1) \
119 GTEST_PRED1_(pred, v1, GTEST_FATAL_FAILURE_)
120
121
122
123 // Helper function for implementing {EXPECT|ASSERT}_PRED2. Don't use
124 // this in your code.
125 template <typename Pred,
126 typename T1,
127 typename T2>
128 AssertionResult AssertPred2Helper(const char* pred_text,
129 const char* e1,
130 const char* e2,
131 Pred pred,
132 const T1& v1,
133 const T2& v2) {
134 if (pred(v1, v2)) return AssertionSuccess();
135
136 return AssertionFailure() << pred_text << "("
137 << e1 << ", "
138 << e2 << ") evaluates to false, where"
139 << "\n" << e1 << " evaluates to " << v1
140 << "\n" << e2 << " evaluates to " << v2;
141 }
142
143 // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
144 // Don't use this in your code.
145 #define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure)\
146 GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
147 on_failure)
148
149 // Internal macro for implementing {EXPECT|ASSERT}_PRED2. Don't use
150 // this in your code.
151 #define GTEST_PRED2_(pred, v1, v2, on_failure)\
152 GTEST_ASSERT_(::testing::AssertPred2Helper(#pred, \
153 #v1, \
154 #v2, \
155 pred, \
156 v1, \
157 v2), on_failure)
158
159 // Binary predicate assertion macros.
160 #define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \
161 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_)
162 #define EXPECT_PRED2(pred, v1, v2) \
163 GTEST_PRED2_(pred, v1, v2, GTEST_NONFATAL_FAILURE_)
164 #define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \
165 GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
166 #define ASSERT_PRED2(pred, v1, v2) \
167 GTEST_PRED2_(pred, v1, v2, GTEST_FATAL_FAILURE_)
168
169
170
171 // Helper function for implementing {EXPECT|ASSERT}_PRED3. Don't use
172 // this in your code.
173 template <typename Pred,
174 typename T1,
175 typename T2,
176 typename T3>
177 AssertionResult AssertPred3Helper(const char* pred_text,
178 const char* e1,
179 const char* e2,
180 const char* e3,
181 Pred pred,
182 const T1& v1,
183 const T2& v2,
184 const T3& v3) {
185 if (pred(v1, v2, v3)) return AssertionSuccess();
186
187 return AssertionFailure() << pred_text << "("
188 << e1 << ", "
189 << e2 << ", "
190 << e3 << ") evaluates to false, where"
191 << "\n" << e1 << " evaluates to " << v1
192 << "\n" << e2 << " evaluates to " << v2
193 << "\n" << e3 << " evaluates to " << v3;
194 }
195
196 // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
197 // Don't use this in your code.
198 #define GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, on_failure)\
199 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, v1, v2, v3), \
200 on_failure)
201
202 // Internal macro for implementing {EXPECT|ASSERT}_PRED3. Don't use
203 // this in your code.
204 #define GTEST_PRED3_(pred, v1, v2, v3, on_failure)\
205 GTEST_ASSERT_(::testing::AssertPred3Helper(#pred, \
206 #v1, \
207 #v2, \
208 #v3, \
209 pred, \
210 v1, \
211 v2, \
212 v3), on_failure)
213
214 // Ternary predicate assertion macros.
215 #define EXPECT_PRED_FORMAT3(pred_format, v1, v2, v3) \
216 GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
217 #define EXPECT_PRED3(pred, v1, v2, v3) \
218 GTEST_PRED3_(pred, v1, v2, v3, GTEST_NONFATAL_FAILURE_)
219 #define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3) \
220 GTEST_PRED_FORMAT3_(pred_format, v1, v2, v3, GTEST_FATAL_FAILURE_)
221 #define ASSERT_PRED3(pred, v1, v2, v3) \
222 GTEST_PRED3_(pred, v1, v2, v3, GTEST_FATAL_FAILURE_)
223
224
225
226 // Helper function for implementing {EXPECT|ASSERT}_PRED4. Don't use
227 // this in your code.
228 template <typename Pred,
229 typename T1,
230 typename T2,
231 typename T3,
232 typename T4>
233 AssertionResult AssertPred4Helper(const char* pred_text,
234 const char* e1,
235 const char* e2,
236 const char* e3,
237 const char* e4,
238 Pred pred,
239 const T1& v1,
240 const T2& v2,
241 const T3& v3,
242 const T4& v4) {
243 if (pred(v1, v2, v3, v4)) return AssertionSuccess();
244
245 return AssertionFailure() << pred_text << "("
246 << e1 << ", "
247 << e2 << ", "
248 << e3 << ", "
249 << e4 << ") evaluates to false, where"
250 << "\n" << e1 << " evaluates to " << v1
251 << "\n" << e2 << " evaluates to " << v2
252 << "\n" << e3 << " evaluates to " << v3
253 << "\n" << e4 << " evaluates to " << v4;
254 }
255
256 // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
257 // Don't use this in your code.
258 #define GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, on_failure)\
259 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, v1, v2, v3, v4), \
260 on_failure)
261
262 // Internal macro for implementing {EXPECT|ASSERT}_PRED4. Don't use
263 // this in your code.
264 #define GTEST_PRED4_(pred, v1, v2, v3, v4, on_failure)\
265 GTEST_ASSERT_(::testing::AssertPred4Helper(#pred, \
266 #v1, \
267 #v2, \
268 #v3, \
269 #v4, \
270 pred, \
271 v1, \
272 v2, \
273 v3, \
274 v4), on_failure)
275
276 // 4-ary predicate assertion macros.
277 #define EXPECT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
278 GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
279 #define EXPECT_PRED4(pred, v1, v2, v3, v4) \
280 GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_NONFATAL_FAILURE_)
281 #define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4) \
282 GTEST_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
283 #define ASSERT_PRED4(pred, v1, v2, v3, v4) \
284 GTEST_PRED4_(pred, v1, v2, v3, v4, GTEST_FATAL_FAILURE_)
285
286
287
288 // Helper function for implementing {EXPECT|ASSERT}_PRED5. Don't use
289 // this in your code.
290 template <typename Pred,
291 typename T1,
292 typename T2,
293 typename T3,
294 typename T4,
295 typename T5>
296 AssertionResult AssertPred5Helper(const char* pred_text,
297 const char* e1,
298 const char* e2,
299 const char* e3,
300 const char* e4,
301 const char* e5,
302 Pred pred,
303 const T1& v1,
304 const T2& v2,
305 const T3& v3,
306 const T4& v4,
307 const T5& v5) {
308 if (pred(v1, v2, v3, v4, v5)) return AssertionSuccess();
309
310 return AssertionFailure() << pred_text << "("
311 << e1 << ", "
312 << e2 << ", "
313 << e3 << ", "
314 << e4 << ", "
315 << e5 << ") evaluates to false, where"
316 << "\n" << e1 << " evaluates to " << v1
317 << "\n" << e2 << " evaluates to " << v2
318 << "\n" << e3 << " evaluates to " << v3
319 << "\n" << e4 << " evaluates to " << v4
320 << "\n" << e5 << " evaluates to " << v5;
321 }
322
323 // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
324 // Don't use this in your code.
325 #define GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, on_failure)\
326 GTEST_ASSERT_(pred_format(#v1, #v2, #v3, #v4, #v5, v1, v2, v3, v4, v5), \
327 on_failure)
328
329 // Internal macro for implementing {EXPECT|ASSERT}_PRED5. Don't use
330 // this in your code.
331 #define GTEST_PRED5_(pred, v1, v2, v3, v4, v5, on_failure)\
332 GTEST_ASSERT_(::testing::AssertPred5Helper(#pred, \
333 #v1, \
334 #v2, \
335 #v3, \
336 #v4, \
337 #v5, \
338 pred, \
339 v1, \
340 v2, \
341 v3, \
342 v4, \
343 v5), on_failure)
344
345 // 5-ary predicate assertion macros.
346 #define EXPECT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
347 GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
348 #define EXPECT_PRED5(pred, v1, v2, v3, v4, v5) \
349 GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_NONFATAL_FAILURE_)
350 #define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5) \
351 GTEST_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
352 #define ASSERT_PRED5(pred, v1, v2, v3, v4, v5) \
353 GTEST_PRED5_(pred, v1, v2, v3, v4, v5, GTEST_FATAL_FAILURE_)
354
355
356
357 #endif // GTEST_INCLUDE_GTEST_GTEST_PRED_IMPL_H_
0 // Copyright 2006, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30 //
31 // Google C++ Testing Framework definitions useful in production code.
32
33 #ifndef GTEST_INCLUDE_GTEST_GTEST_PROD_H_
34 #define GTEST_INCLUDE_GTEST_GTEST_PROD_H_
35
36 // When you need to test the private or protected members of a class,
37 // use the FRIEND_TEST macro to declare your tests as friends of the
38 // class. For example:
39 //
40 // class MyClass {
41 // private:
42 // void MyMethod();
43 // FRIEND_TEST(MyClassTest, MyMethod);
44 // };
45 //
46 // class MyClassTest : public testing::Test {
47 // // ...
48 // };
49 //
50 // TEST_F(MyClassTest, MyMethod) {
51 // // Can call MyClass::MyMethod() here.
52 // }
53
54 #define FRIEND_TEST(test_case_name, test_name)\
55 friend class test_case_name##_##test_name##_Test
56
57 #endif // GTEST_INCLUDE_GTEST_GTEST_PROD_H_
0 // Copyright 2005, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
30 //
31 // The Google C++ Testing Framework (Google Test)
32 //
33 // This header file defines internal utilities needed for implementing
34 // death tests. They are subject to change without notice.
35
36 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
37 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
38
39 #include "gtest/internal/gtest-internal.h"
40
41 #include <stdio.h>
42
43 namespace testing {
44 namespace internal {
45
46 GTEST_DECLARE_string_(internal_run_death_test);
47
48 // Names of the flags (needed for parsing Google Test flags).
49 const char kDeathTestStyleFlag[] = "death_test_style";
50 const char kDeathTestUseFork[] = "death_test_use_fork";
51 const char kInternalRunDeathTestFlag[] = "internal_run_death_test";
52
53 #if GTEST_HAS_DEATH_TEST
54
55 // DeathTest is a class that hides much of the complexity of the
56 // GTEST_DEATH_TEST_ macro. It is abstract; its static Create method
57 // returns a concrete class that depends on the prevailing death test
58 // style, as defined by the --gtest_death_test_style and/or
59 // --gtest_internal_run_death_test flags.
60
61 // In describing the results of death tests, these terms are used with
62 // the corresponding definitions:
63 //
64 // exit status: The integer exit information in the format specified
65 // by wait(2)
66 // exit code: The integer code passed to exit(3), _exit(2), or
67 // returned from main()
68 class GTEST_API_ DeathTest {
69 public:
70 // Create returns false if there was an error determining the
71 // appropriate action to take for the current death test; for example,
72 // if the gtest_death_test_style flag is set to an invalid value.
73 // The LastMessage method will return a more detailed message in that
74 // case. Otherwise, the DeathTest pointer pointed to by the "test"
75 // argument is set. If the death test should be skipped, the pointer
76 // is set to NULL; otherwise, it is set to the address of a new concrete
77 // DeathTest object that controls the execution of the current test.
78 static bool Create(const char* statement, const RE* regex,
79 const char* file, int line, DeathTest** test);
80 DeathTest();
81 virtual ~DeathTest() { }
82
83 // A helper class that aborts a death test when it's deleted.
84 class ReturnSentinel {
85 public:
86 explicit ReturnSentinel(DeathTest* test) : test_(test) { }
87 ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
88 private:
89 DeathTest* const test_;
90 GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel);
91 } GTEST_ATTRIBUTE_UNUSED_;
92
93 // An enumeration of possible roles that may be taken when a death
94 // test is encountered. EXECUTE means that the death test logic should
95 // be executed immediately. OVERSEE means that the program should prepare
96 // the appropriate environment for a child process to execute the death
97 // test, then wait for it to complete.
98 enum TestRole { OVERSEE_TEST, EXECUTE_TEST };
99
100 // An enumeration of the three reasons that a test might be aborted.
101 enum AbortReason {
102 TEST_ENCOUNTERED_RETURN_STATEMENT,
103 TEST_THREW_EXCEPTION,
104 TEST_DID_NOT_DIE
105 };
106
107 // Assumes one of the above roles.
108 virtual TestRole AssumeRole() = 0;
109
110 // Waits for the death test to finish and returns its status.
111 virtual int Wait() = 0;
112
113 // Returns true if the death test passed; that is, the test process
114 // exited during the test, its exit status matches a user-supplied
115 // predicate, and its stderr output matches a user-supplied regular
116 // expression.
117 // The user-supplied predicate may be a macro expression rather
118 // than a function pointer or functor, or else Wait and Passed could
119 // be combined.
120 virtual bool Passed(bool exit_status_ok) = 0;
121
122 // Signals that the death test did not die as expected.
123 virtual void Abort(AbortReason reason) = 0;
124
125 // Returns a human-readable outcome message regarding the outcome of
126 // the last death test.
127 static const char* LastMessage();
128
129 static void set_last_death_test_message(const std::string& message);
130
131 private:
132 // A string containing a description of the outcome of the last death test.
133 static std::string last_death_test_message_;
134
135 GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest);
136 };
137
138 // Factory interface for death tests. May be mocked out for testing.
139 class DeathTestFactory {
140 public:
141 virtual ~DeathTestFactory() { }
142 virtual bool Create(const char* statement, const RE* regex,
143 const char* file, int line, DeathTest** test) = 0;
144 };
145
146 // A concrete DeathTestFactory implementation for normal use.
147 class DefaultDeathTestFactory : public DeathTestFactory {
148 public:
149 virtual bool Create(const char* statement, const RE* regex,
150 const char* file, int line, DeathTest** test);
151 };
152
153 // Returns true if exit_status describes a process that was terminated
154 // by a signal, or exited normally with a nonzero exit code.
155 GTEST_API_ bool ExitedUnsuccessfully(int exit_status);
156
157 // Traps C++ exceptions escaping statement and reports them as test
158 // failures. Note that trapping SEH exceptions is not implemented here.
159 # if GTEST_HAS_EXCEPTIONS
160 # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
161 try { \
162 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
163 } catch (const ::std::exception& gtest_exception) { \
164 fprintf(\
165 stderr, \
166 "\n%s: Caught std::exception-derived exception escaping the " \
167 "death test statement. Exception message: %s\n", \
168 ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \
169 gtest_exception.what()); \
170 fflush(stderr); \
171 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
172 } catch (...) { \
173 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
174 }
175
176 # else
177 # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
178 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
179
180 # endif
181
182 // This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
183 // ASSERT_EXIT*, and EXPECT_EXIT*.
184 # define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \
185 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
186 if (::testing::internal::AlwaysTrue()) { \
187 const ::testing::internal::RE& gtest_regex = (regex); \
188 ::testing::internal::DeathTest* gtest_dt; \
189 if (!::testing::internal::DeathTest::Create(#statement, &gtest_regex, \
190 __FILE__, __LINE__, &gtest_dt)) { \
191 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
192 } \
193 if (gtest_dt != NULL) { \
194 ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \
195 gtest_dt_ptr(gtest_dt); \
196 switch (gtest_dt->AssumeRole()) { \
197 case ::testing::internal::DeathTest::OVERSEE_TEST: \
198 if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \
199 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
200 } \
201 break; \
202 case ::testing::internal::DeathTest::EXECUTE_TEST: { \
203 ::testing::internal::DeathTest::ReturnSentinel \
204 gtest_sentinel(gtest_dt); \
205 GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
206 gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
207 break; \
208 } \
209 default: \
210 break; \
211 } \
212 } \
213 } else \
214 GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \
215 fail(::testing::internal::DeathTest::LastMessage())
216 // The symbol "fail" here expands to something into which a message
217 // can be streamed.
218
219 // This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in
220 // NDEBUG mode. In this case we need the statements to be executed, the regex is
221 // ignored, and the macro must accept a streamed message even though the message
222 // is never printed.
223 # define GTEST_EXECUTE_STATEMENT_(statement, regex) \
224 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
225 if (::testing::internal::AlwaysTrue()) { \
226 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
227 } else \
228 ::testing::Message()
229
230 // A class representing the parsed contents of the
231 // --gtest_internal_run_death_test flag, as it existed when
232 // RUN_ALL_TESTS was called.
233 class InternalRunDeathTestFlag {
234 public:
235 InternalRunDeathTestFlag(const std::string& a_file,
236 int a_line,
237 int an_index,
238 int a_write_fd)
239 : file_(a_file), line_(a_line), index_(an_index),
240 write_fd_(a_write_fd) {}
241
242 ~InternalRunDeathTestFlag() {
243 if (write_fd_ >= 0)
244 posix::Close(write_fd_);
245 }
246
247 const std::string& file() const { return file_; }
248 int line() const { return line_; }
249 int index() const { return index_; }
250 int write_fd() const { return write_fd_; }
251
252 private:
253 std::string file_;
254 int line_;
255 int index_;
256 int write_fd_;
257
258 GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag);
259 };
260
261 // Returns a newly created InternalRunDeathTestFlag object with fields
262 // initialized from the GTEST_FLAG(internal_run_death_test) flag if
263 // the flag is specified; otherwise returns NULL.
264 InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
265
266 #else // GTEST_HAS_DEATH_TEST
267
268 // This macro is used for implementing macros such as
269 // EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where
270 // death tests are not supported. Those macros must compile on such systems
271 // iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on
272 // systems that support death tests. This allows one to write such a macro
273 // on a system that does not support death tests and be sure that it will
274 // compile on a death-test supporting system.
275 //
276 // Parameters:
277 // statement - A statement that a macro such as EXPECT_DEATH would test
278 // for program termination. This macro has to make sure this
279 // statement is compiled but not executed, to ensure that
280 // EXPECT_DEATH_IF_SUPPORTED compiles with a certain
281 // parameter iff EXPECT_DEATH compiles with it.
282 // regex - A regex that a macro such as EXPECT_DEATH would use to test
283 // the output of statement. This parameter has to be
284 // compiled but not evaluated by this macro, to ensure that
285 // this macro only accepts expressions that a macro such as
286 // EXPECT_DEATH would accept.
287 // terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED
288 // and a return statement for ASSERT_DEATH_IF_SUPPORTED.
289 // This ensures that ASSERT_DEATH_IF_SUPPORTED will not
290 // compile inside functions where ASSERT_DEATH doesn't
291 // compile.
292 //
293 // The branch that has an always false condition is used to ensure that
294 // statement and regex are compiled (and thus syntactically correct) but
295 // never executed. The unreachable code macro protects the terminator
296 // statement from generating an 'unreachable code' warning in case
297 // statement unconditionally returns or throws. The Message constructor at
298 // the end allows the syntax of streaming additional messages into the
299 // macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH.
300 # define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \
301 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
302 if (::testing::internal::AlwaysTrue()) { \
303 GTEST_LOG_(WARNING) \
304 << "Death tests are not supported on this platform.\n" \
305 << "Statement '" #statement "' cannot be verified."; \
306 } else if (::testing::internal::AlwaysFalse()) { \
307 ::testing::internal::RE::PartialMatch(".*", (regex)); \
308 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
309 terminator; \
310 } else \
311 ::testing::Message()
312
313 #endif // GTEST_HAS_DEATH_TEST
314
315 } // namespace internal
316 } // namespace testing
317
318 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
0 // Copyright 2008, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: keith.ray@gmail.com (Keith Ray)
30 //
31 // Google Test filepath utilities
32 //
33 // This header file declares classes and functions used internally by
34 // Google Test. They are subject to change without notice.
35 //
36 // This file is #included in <gtest/internal/gtest-internal.h>.
37 // Do not include this header file separately!
38
39 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
40 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
41
42 #include "gtest/internal/gtest-string.h"
43
44 namespace testing {
45 namespace internal {
46
47 // FilePath - a class for file and directory pathname manipulation which
48 // handles platform-specific conventions (like the pathname separator).
49 // Used for helper functions for naming files in a directory for xml output.
50 // Except for Set methods, all methods are const or static, which provides an
51 // "immutable value object" -- useful for peace of mind.
52 // A FilePath with a value ending in a path separator ("like/this/") represents
53 // a directory, otherwise it is assumed to represent a file. In either case,
54 // it may or may not represent an actual file or directory in the file system.
55 // Names are NOT checked for syntax correctness -- no checking for illegal
56 // characters, malformed paths, etc.
57
58 class GTEST_API_ FilePath {
59 public:
60 FilePath() : pathname_("") { }
61 FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { }
62
63 explicit FilePath(const std::string& pathname) : pathname_(pathname) {
64 Normalize();
65 }
66
67 FilePath& operator=(const FilePath& rhs) {
68 Set(rhs);
69 return *this;
70 }
71
72 void Set(const FilePath& rhs) {
73 pathname_ = rhs.pathname_;
74 }
75
76 const std::string& string() const { return pathname_; }
77 const char* c_str() const { return pathname_.c_str(); }
78
79 // Returns the current working directory, or "" if unsuccessful.
80 static FilePath GetCurrentDir();
81
82 // Given directory = "dir", base_name = "test", number = 0,
83 // extension = "xml", returns "dir/test.xml". If number is greater
84 // than zero (e.g., 12), returns "dir/test_12.xml".
85 // On Windows platform, uses \ as the separator rather than /.
86 static FilePath MakeFileName(const FilePath& directory,
87 const FilePath& base_name,
88 int number,
89 const char* extension);
90
91 // Given directory = "dir", relative_path = "test.xml",
92 // returns "dir/test.xml".
93 // On Windows, uses \ as the separator rather than /.
94 static FilePath ConcatPaths(const FilePath& directory,
95 const FilePath& relative_path);
96
97 // Returns a pathname for a file that does not currently exist. The pathname
98 // will be directory/base_name.extension or
99 // directory/base_name_<number>.extension if directory/base_name.extension
100 // already exists. The number will be incremented until a pathname is found
101 // that does not already exist.
102 // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
103 // There could be a race condition if two or more processes are calling this
104 // function at the same time -- they could both pick the same filename.
105 static FilePath GenerateUniqueFileName(const FilePath& directory,
106 const FilePath& base_name,
107 const char* extension);
108
109 // Returns true iff the path is "".
110 bool IsEmpty() const { return pathname_.empty(); }
111
112 // If input name has a trailing separator character, removes it and returns
113 // the name, otherwise return the name string unmodified.
114 // On Windows platform, uses \ as the separator, other platforms use /.
115 FilePath RemoveTrailingPathSeparator() const;
116
117 // Returns a copy of the FilePath with the directory part removed.
118 // Example: FilePath("path/to/file").RemoveDirectoryName() returns
119 // FilePath("file"). If there is no directory part ("just_a_file"), it returns
120 // the FilePath unmodified. If there is no file part ("just_a_dir/") it
121 // returns an empty FilePath ("").
122 // On Windows platform, '\' is the path separator, otherwise it is '/'.
123 FilePath RemoveDirectoryName() const;
124
125 // RemoveFileName returns the directory path with the filename removed.
126 // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
127 // If the FilePath is "a_file" or "/a_file", RemoveFileName returns
128 // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
129 // not have a file, like "just/a/dir/", it returns the FilePath unmodified.
130 // On Windows platform, '\' is the path separator, otherwise it is '/'.
131 FilePath RemoveFileName() const;
132
133 // Returns a copy of the FilePath with the case-insensitive extension removed.
134 // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
135 // FilePath("dir/file"). If a case-insensitive extension is not
136 // found, returns a copy of the original FilePath.
137 FilePath RemoveExtension(const char* extension) const;
138
139 // Creates directories so that path exists. Returns true if successful or if
140 // the directories already exist; returns false if unable to create
141 // directories for any reason. Will also return false if the FilePath does
142 // not represent a directory (that is, it doesn't end with a path separator).
143 bool CreateDirectoriesRecursively() const;
144
145 // Create the directory so that path exists. Returns true if successful or
146 // if the directory already exists; returns false if unable to create the
147 // directory for any reason, including if the parent directory does not
148 // exist. Not named "CreateDirectory" because that's a macro on Windows.
149 bool CreateFolder() const;
150
151 // Returns true if FilePath describes something in the file-system,
152 // either a file, directory, or whatever, and that something exists.
153 bool FileOrDirectoryExists() const;
154
155 // Returns true if pathname describes a directory in the file-system
156 // that exists.
157 bool DirectoryExists() const;
158
159 // Returns true if FilePath ends with a path separator, which indicates that
160 // it is intended to represent a directory. Returns false otherwise.
161 // This does NOT check that a directory (or file) actually exists.
162 bool IsDirectory() const;
163
164 // Returns true if pathname describes a root directory. (Windows has one
165 // root directory per disk drive.)
166 bool IsRootDirectory() const;
167
168 // Returns true if pathname describes an absolute path.
169 bool IsAbsolutePath() const;
170
171 private:
172 // Replaces multiple consecutive separators with a single separator.
173 // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
174 // redundancies that might be in a pathname involving "." or "..".
175 //
176 // A pathname with multiple consecutive separators may occur either through
177 // user error or as a result of some scripts or APIs that generate a pathname
178 // with a trailing separator. On other platforms the same API or script
179 // may NOT generate a pathname with a trailing "/". Then elsewhere that
180 // pathname may have another "/" and pathname components added to it,
181 // without checking for the separator already being there.
182 // The script language and operating system may allow paths like "foo//bar"
183 // but some of the functions in FilePath will not handle that correctly. In
184 // particular, RemoveTrailingPathSeparator() only removes one separator, and
185 // it is called in CreateDirectoriesRecursively() assuming that it will change
186 // a pathname from directory syntax (trailing separator) to filename syntax.
187 //
188 // On Windows this method also replaces the alternate path separator '/' with
189 // the primary path separator '\\', so that for example "bar\\/\\foo" becomes
190 // "bar\\foo".
191
192 void Normalize();
193
194 // Returns a pointer to the last occurence of a valid path separator in
195 // the FilePath. On Windows, for example, both '/' and '\' are valid path
196 // separators. Returns NULL if no path separator was found.
197 const char* FindLastPathSeparator() const;
198
199 std::string pathname_;
200 }; // class FilePath
201
202 } // namespace internal
203 } // namespace testing
204
205 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_
0 // Copyright 2005, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
30 //
31 // The Google C++ Testing Framework (Google Test)
32 //
33 // This header file declares functions and macros used internally by
34 // Google Test. They are subject to change without notice.
35
36 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
37 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
38
39 #include "gtest/internal/gtest-port.h"
40
41 #if GTEST_OS_LINUX
42 # include <stdlib.h>
43 # include <sys/types.h>
44 # include <sys/wait.h>
45 # include <unistd.h>
46 #endif // GTEST_OS_LINUX
47
48 #if GTEST_HAS_EXCEPTIONS
49 # include <stdexcept>
50 #endif
51
52 #include <ctype.h>
53 #include <float.h>
54 #include <string.h>
55 #include <iomanip>
56 #include <limits>
57 #include <set>
58
59 #include "gtest/gtest-message.h"
60 #include "gtest/internal/gtest-string.h"
61 #include "gtest/internal/gtest-filepath.h"
62 #include "gtest/internal/gtest-type-util.h"
63
64 // Due to C++ preprocessor weirdness, we need double indirection to
65 // concatenate two tokens when one of them is __LINE__. Writing
66 //
67 // foo ## __LINE__
68 //
69 // will result in the token foo__LINE__, instead of foo followed by
70 // the current line number. For more details, see
71 // http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
72 #define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
73 #define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar
74
75 class ProtocolMessage;
76 namespace proto2 { class Message; }
77
78 namespace testing {
79
80 // Forward declarations.
81
82 class AssertionResult; // Result of an assertion.
83 class Message; // Represents a failure message.
84 class Test; // Represents a test.
85 class TestInfo; // Information about a test.
86 class TestPartResult; // Result of a test part.
87 class UnitTest; // A collection of test cases.
88
89 template <typename T>
90 ::std::string PrintToString(const T& value);
91
92 namespace internal {
93
94 struct TraceInfo; // Information about a trace point.
95 class ScopedTrace; // Implements scoped trace.
96 class TestInfoImpl; // Opaque implementation of TestInfo
97 class UnitTestImpl; // Opaque implementation of UnitTest
98
99 // How many times InitGoogleTest() has been called.
100 GTEST_API_ extern int g_init_gtest_count;
101
102 // The text used in failure messages to indicate the start of the
103 // stack trace.
104 GTEST_API_ extern const char kStackTraceMarker[];
105
106 // Two overloaded helpers for checking at compile time whether an
107 // expression is a null pointer literal (i.e. NULL or any 0-valued
108 // compile-time integral constant). Their return values have
109 // different sizes, so we can use sizeof() to test which version is
110 // picked by the compiler. These helpers have no implementations, as
111 // we only need their signatures.
112 //
113 // Given IsNullLiteralHelper(x), the compiler will pick the first
114 // version if x can be implicitly converted to Secret*, and pick the
115 // second version otherwise. Since Secret is a secret and incomplete
116 // type, the only expression a user can write that has type Secret* is
117 // a null pointer literal. Therefore, we know that x is a null
118 // pointer literal if and only if the first version is picked by the
119 // compiler.
120 char IsNullLiteralHelper(Secret* p);
121 char (&IsNullLiteralHelper(...))[2]; // NOLINT
122
123 // A compile-time bool constant that is true if and only if x is a
124 // null pointer literal (i.e. NULL or any 0-valued compile-time
125 // integral constant).
126 #ifdef GTEST_ELLIPSIS_NEEDS_POD_
127 // We lose support for NULL detection where the compiler doesn't like
128 // passing non-POD classes through ellipsis (...).
129 # define GTEST_IS_NULL_LITERAL_(x) false
130 #else
131 # define GTEST_IS_NULL_LITERAL_(x) \
132 (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1)
133 #endif // GTEST_ELLIPSIS_NEEDS_POD_
134
135 // Appends the user-supplied message to the Google-Test-generated message.
136 GTEST_API_ std::string AppendUserMessage(
137 const std::string& gtest_msg, const Message& user_msg);
138
139 #if GTEST_HAS_EXCEPTIONS
140
141 // This exception is thrown by (and only by) a failed Google Test
142 // assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions
143 // are enabled). We derive it from std::runtime_error, which is for
144 // errors presumably detectable only at run time. Since
145 // std::runtime_error inherits from std::exception, many testing
146 // frameworks know how to extract and print the message inside it.
147 class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error {
148 public:
149 explicit GoogleTestFailureException(const TestPartResult& failure);
150 };
151
152 #endif // GTEST_HAS_EXCEPTIONS
153
154 // A helper class for creating scoped traces in user programs.
155 class GTEST_API_ ScopedTrace {
156 public:
157 // The c'tor pushes the given source file location and message onto
158 // a trace stack maintained by Google Test.
159 ScopedTrace(const char* file, int line, const Message& message);
160
161 // The d'tor pops the info pushed by the c'tor.
162 //
163 // Note that the d'tor is not virtual in order to be efficient.
164 // Don't inherit from ScopedTrace!
165 ~ScopedTrace();
166
167 private:
168 GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedTrace);
169 } GTEST_ATTRIBUTE_UNUSED_; // A ScopedTrace object does its job in its
170 // c'tor and d'tor. Therefore it doesn't
171 // need to be used otherwise.
172
173 // Constructs and returns the message for an equality assertion
174 // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
175 //
176 // The first four parameters are the expressions used in the assertion
177 // and their values, as strings. For example, for ASSERT_EQ(foo, bar)
178 // where foo is 5 and bar is 6, we have:
179 //
180 // expected_expression: "foo"
181 // actual_expression: "bar"
182 // expected_value: "5"
183 // actual_value: "6"
184 //
185 // The ignoring_case parameter is true iff the assertion is a
186 // *_STRCASEEQ*. When it's true, the string " (ignoring case)" will
187 // be inserted into the message.
188 GTEST_API_ AssertionResult EqFailure(const char* expected_expression,
189 const char* actual_expression,
190 const std::string& expected_value,
191 const std::string& actual_value,
192 bool ignoring_case);
193
194 // Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
195 GTEST_API_ std::string GetBoolAssertionFailureMessage(
196 const AssertionResult& assertion_result,
197 const char* expression_text,
198 const char* actual_predicate_value,
199 const char* expected_predicate_value);
200
201 // This template class represents an IEEE floating-point number
202 // (either single-precision or double-precision, depending on the
203 // template parameters).
204 //
205 // The purpose of this class is to do more sophisticated number
206 // comparison. (Due to round-off error, etc, it's very unlikely that
207 // two floating-points will be equal exactly. Hence a naive
208 // comparison by the == operation often doesn't work.)
209 //
210 // Format of IEEE floating-point:
211 //
212 // The most-significant bit being the leftmost, an IEEE
213 // floating-point looks like
214 //
215 // sign_bit exponent_bits fraction_bits
216 //
217 // Here, sign_bit is a single bit that designates the sign of the
218 // number.
219 //
220 // For float, there are 8 exponent bits and 23 fraction bits.
221 //
222 // For double, there are 11 exponent bits and 52 fraction bits.
223 //
224 // More details can be found at
225 // http://en.wikipedia.org/wiki/IEEE_floating-point_standard.
226 //
227 // Template parameter:
228 //
229 // RawType: the raw floating-point type (either float or double)
230 template <typename RawType>
231 class FloatingPoint {
232 public:
233 // Defines the unsigned integer type that has the same size as the
234 // floating point number.
235 typedef typename TypeWithSize<sizeof(RawType)>::UInt Bits;
236
237 // Constants.
238
239 // # of bits in a number.
240 static const size_t kBitCount = 8*sizeof(RawType);
241
242 // # of fraction bits in a number.
243 static const size_t kFractionBitCount =
244 std::numeric_limits<RawType>::digits - 1;
245
246 // # of exponent bits in a number.
247 static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount;
248
249 // The mask for the sign bit.
250 static const Bits kSignBitMask = static_cast<Bits>(1) << (kBitCount - 1);
251
252 // The mask for the fraction bits.
253 static const Bits kFractionBitMask =
254 ~static_cast<Bits>(0) >> (kExponentBitCount + 1);
255
256 // The mask for the exponent bits.
257 static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask);
258
259 // How many ULP's (Units in the Last Place) we want to tolerate when
260 // comparing two numbers. The larger the value, the more error we
261 // allow. A 0 value means that two numbers must be exactly the same
262 // to be considered equal.
263 //
264 // The maximum error of a single floating-point operation is 0.5
265 // units in the last place. On Intel CPU's, all floating-point
266 // calculations are done with 80-bit precision, while double has 64
267 // bits. Therefore, 4 should be enough for ordinary use.
268 //
269 // See the following article for more details on ULP:
270 // http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
271 static const size_t kMaxUlps = 4;
272
273 // Constructs a FloatingPoint from a raw floating-point number.
274 //
275 // On an Intel CPU, passing a non-normalized NAN (Not a Number)
276 // around may change its bits, although the new value is guaranteed
277 // to be also a NAN. Therefore, don't expect this constructor to
278 // preserve the bits in x when x is a NAN.
279 explicit FloatingPoint(const RawType& x) { u_.value_ = x; }
280
281 // Static methods
282
283 // Reinterprets a bit pattern as a floating-point number.
284 //
285 // This function is needed to test the AlmostEquals() method.
286 static RawType ReinterpretBits(const Bits bits) {
287 FloatingPoint fp(0);
288 fp.u_.bits_ = bits;
289 return fp.u_.value_;
290 }
291
292 // Returns the floating-point number that represent positive infinity.
293 static RawType Infinity() {
294 return ReinterpretBits(kExponentBitMask);
295 }
296
297 // Returns the maximum representable finite floating-point number.
298 static RawType Max();
299
300 // Non-static methods
301
302 // Returns the bits that represents this number.
303 const Bits &bits() const { return u_.bits_; }
304
305 // Returns the exponent bits of this number.
306 Bits exponent_bits() const { return kExponentBitMask & u_.bits_; }
307
308 // Returns the fraction bits of this number.
309 Bits fraction_bits() const { return kFractionBitMask & u_.bits_; }
310
311 // Returns the sign bit of this number.
312 Bits sign_bit() const { return kSignBitMask & u_.bits_; }
313
314 // Returns true iff this is NAN (not a number).
315 bool is_nan() const {
316 // It's a NAN if the exponent bits are all ones and the fraction
317 // bits are not entirely zeros.
318 return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0);
319 }
320
321 // Returns true iff this number is at most kMaxUlps ULP's away from
322 // rhs. In particular, this function:
323 //
324 // - returns false if either number is (or both are) NAN.
325 // - treats really large numbers as almost equal to infinity.
326 // - thinks +0.0 and -0.0 are 0 DLP's apart.
327 bool AlmostEquals(const FloatingPoint& rhs) const {
328 // The IEEE standard says that any comparison operation involving
329 // a NAN must return false.
330 if (is_nan() || rhs.is_nan()) return false;
331
332 return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_)
333 <= kMaxUlps;
334 }
335
336 private:
337 // The data type used to store the actual floating-point number.
338 union FloatingPointUnion {
339 RawType value_; // The raw floating-point number.
340 Bits bits_; // The bits that represent the number.
341 };
342
343 // Converts an integer from the sign-and-magnitude representation to
344 // the biased representation. More precisely, let N be 2 to the
345 // power of (kBitCount - 1), an integer x is represented by the
346 // unsigned number x + N.
347 //
348 // For instance,
349 //
350 // -N + 1 (the most negative number representable using
351 // sign-and-magnitude) is represented by 1;
352 // 0 is represented by N; and
353 // N - 1 (the biggest number representable using
354 // sign-and-magnitude) is represented by 2N - 1.
355 //
356 // Read http://en.wikipedia.org/wiki/Signed_number_representations
357 // for more details on signed number representations.
358 static Bits SignAndMagnitudeToBiased(const Bits &sam) {
359 if (kSignBitMask & sam) {
360 // sam represents a negative number.
361 return ~sam + 1;
362 } else {
363 // sam represents a positive number.
364 return kSignBitMask | sam;
365 }
366 }
367
368 // Given two numbers in the sign-and-magnitude representation,
369 // returns the distance between them as an unsigned number.
370 static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1,
371 const Bits &sam2) {
372 const Bits biased1 = SignAndMagnitudeToBiased(sam1);
373 const Bits biased2 = SignAndMagnitudeToBiased(sam2);
374 return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1);
375 }
376
377 FloatingPointUnion u_;
378 };
379
380 // We cannot use std::numeric_limits<T>::max() as it clashes with the max()
381 // macro defined by <windows.h>.
382 template <>
383 inline float FloatingPoint<float>::Max() { return FLT_MAX; }
384 template <>
385 inline double FloatingPoint<double>::Max() { return DBL_MAX; }
386
387 // Typedefs the instances of the FloatingPoint template class that we
388 // care to use.
389 typedef FloatingPoint<float> Float;
390 typedef FloatingPoint<double> Double;
391
392 // In order to catch the mistake of putting tests that use different
393 // test fixture classes in the same test case, we need to assign
394 // unique IDs to fixture classes and compare them. The TypeId type is
395 // used to hold such IDs. The user should treat TypeId as an opaque
396 // type: the only operation allowed on TypeId values is to compare
397 // them for equality using the == operator.
398 typedef const void* TypeId;
399
400 template <typename T>
401 class TypeIdHelper {
402 public:
403 // dummy_ must not have a const type. Otherwise an overly eager
404 // compiler (e.g. MSVC 7.1 & 8.0) may try to merge
405 // TypeIdHelper<T>::dummy_ for different Ts as an "optimization".
406 static bool dummy_;
407 };
408
409 template <typename T>
410 bool TypeIdHelper<T>::dummy_ = false;
411
412 // GetTypeId<T>() returns the ID of type T. Different values will be
413 // returned for different types. Calling the function twice with the
414 // same type argument is guaranteed to return the same ID.
415 template <typename T>
416 TypeId GetTypeId() {
417 // The compiler is required to allocate a different
418 // TypeIdHelper<T>::dummy_ variable for each T used to instantiate
419 // the template. Therefore, the address of dummy_ is guaranteed to
420 // be unique.
421 return &(TypeIdHelper<T>::dummy_);
422 }
423
424 // Returns the type ID of ::testing::Test. Always call this instead
425 // of GetTypeId< ::testing::Test>() to get the type ID of
426 // ::testing::Test, as the latter may give the wrong result due to a
427 // suspected linker bug when compiling Google Test as a Mac OS X
428 // framework.
429 GTEST_API_ TypeId GetTestTypeId();
430
431 // Defines the abstract factory interface that creates instances
432 // of a Test object.
433 class TestFactoryBase {
434 public:
435 virtual ~TestFactoryBase() {}
436
437 // Creates a test instance to run. The instance is both created and destroyed
438 // within TestInfoImpl::Run()
439 virtual Test* CreateTest() = 0;
440
441 protected:
442 TestFactoryBase() {}
443
444 private:
445 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase);
446 };
447
448 // This class provides implementation of TeastFactoryBase interface.
449 // It is used in TEST and TEST_F macros.
450 template <class TestClass>
451 class TestFactoryImpl : public TestFactoryBase {
452 public:
453 virtual Test* CreateTest() { return new TestClass; }
454 };
455
456 #if GTEST_OS_WINDOWS
457
458 // Predicate-formatters for implementing the HRESULT checking macros
459 // {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}
460 // We pass a long instead of HRESULT to avoid causing an
461 // include dependency for the HRESULT type.
462 GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr,
463 long hr); // NOLINT
464 GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
465 long hr); // NOLINT
466
467 #endif // GTEST_OS_WINDOWS
468
469 // Types of SetUpTestCase() and TearDownTestCase() functions.
470 typedef void (*SetUpTestCaseFunc)();
471 typedef void (*TearDownTestCaseFunc)();
472
473 // Creates a new TestInfo object and registers it with Google Test;
474 // returns the created object.
475 //
476 // Arguments:
477 //
478 // test_case_name: name of the test case
479 // name: name of the test
480 // type_param the name of the test's type parameter, or NULL if
481 // this is not a typed or a type-parameterized test.
482 // value_param text representation of the test's value parameter,
483 // or NULL if this is not a type-parameterized test.
484 // fixture_class_id: ID of the test fixture class
485 // set_up_tc: pointer to the function that sets up the test case
486 // tear_down_tc: pointer to the function that tears down the test case
487 // factory: pointer to the factory that creates a test object.
488 // The newly created TestInfo instance will assume
489 // ownership of the factory object.
490 GTEST_API_ TestInfo* MakeAndRegisterTestInfo(
491 const char* test_case_name,
492 const char* name,
493 const char* type_param,
494 const char* value_param,
495 TypeId fixture_class_id,
496 SetUpTestCaseFunc set_up_tc,
497 TearDownTestCaseFunc tear_down_tc,
498 TestFactoryBase* factory);
499
500 // If *pstr starts with the given prefix, modifies *pstr to be right
501 // past the prefix and returns true; otherwise leaves *pstr unchanged
502 // and returns false. None of pstr, *pstr, and prefix can be NULL.
503 GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr);
504
505 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
506
507 // State of the definition of a type-parameterized test case.
508 class GTEST_API_ TypedTestCasePState {
509 public:
510 TypedTestCasePState() : registered_(false) {}
511
512 // Adds the given test name to defined_test_names_ and return true
513 // if the test case hasn't been registered; otherwise aborts the
514 // program.
515 bool AddTestName(const char* file, int line, const char* case_name,
516 const char* test_name) {
517 if (registered_) {
518 fprintf(stderr, "%s Test %s must be defined before "
519 "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n",
520 FormatFileLocation(file, line).c_str(), test_name, case_name);
521 fflush(stderr);
522 posix::Abort();
523 }
524 defined_test_names_.insert(test_name);
525 return true;
526 }
527
528 // Verifies that registered_tests match the test names in
529 // defined_test_names_; returns registered_tests if successful, or
530 // aborts the program otherwise.
531 const char* VerifyRegisteredTestNames(
532 const char* file, int line, const char* registered_tests);
533
534 private:
535 bool registered_;
536 ::std::set<const char*> defined_test_names_;
537 };
538
539 // Skips to the first non-space char after the first comma in 'str';
540 // returns NULL if no comma is found in 'str'.
541 inline const char* SkipComma(const char* str) {
542 const char* comma = strchr(str, ',');
543 if (comma == NULL) {
544 return NULL;
545 }
546 while (IsSpace(*(++comma))) {}
547 return comma;
548 }
549
550 // Returns the prefix of 'str' before the first comma in it; returns
551 // the entire string if it contains no comma.
552 inline std::string GetPrefixUntilComma(const char* str) {
553 const char* comma = strchr(str, ',');
554 return comma == NULL ? str : std::string(str, comma);
555 }
556
557 // TypeParameterizedTest<Fixture, TestSel, Types>::Register()
558 // registers a list of type-parameterized tests with Google Test. The
559 // return value is insignificant - we just need to return something
560 // such that we can call this function in a namespace scope.
561 //
562 // Implementation note: The GTEST_TEMPLATE_ macro declares a template
563 // template parameter. It's defined in gtest-type-util.h.
564 template <GTEST_TEMPLATE_ Fixture, class TestSel, typename Types>
565 class TypeParameterizedTest {
566 public:
567 // 'index' is the index of the test in the type list 'Types'
568 // specified in INSTANTIATE_TYPED_TEST_CASE_P(Prefix, TestCase,
569 // Types). Valid values for 'index' are [0, N - 1] where N is the
570 // length of Types.
571 static bool Register(const char* prefix, const char* case_name,
572 const char* test_names, int index) {
573 typedef typename Types::Head Type;
574 typedef Fixture<Type> FixtureClass;
575 typedef typename GTEST_BIND_(TestSel, Type) TestClass;
576
577 // First, registers the first type-parameterized test in the type
578 // list.
579 MakeAndRegisterTestInfo(
580 (std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + "/"
581 + StreamableToString(index)).c_str(),
582 GetPrefixUntilComma(test_names).c_str(),
583 GetTypeName<Type>().c_str(),
584 NULL, // No value parameter.
585 GetTypeId<FixtureClass>(),
586 TestClass::SetUpTestCase,
587 TestClass::TearDownTestCase,
588 new TestFactoryImpl<TestClass>);
589
590 // Next, recurses (at compile time) with the tail of the type list.
591 return TypeParameterizedTest<Fixture, TestSel, typename Types::Tail>
592 ::Register(prefix, case_name, test_names, index + 1);
593 }
594 };
595
596 // The base case for the compile time recursion.
597 template <GTEST_TEMPLATE_ Fixture, class TestSel>
598 class TypeParameterizedTest<Fixture, TestSel, Types0> {
599 public:
600 static bool Register(const char* /*prefix*/, const char* /*case_name*/,
601 const char* /*test_names*/, int /*index*/) {
602 return true;
603 }
604 };
605
606 // TypeParameterizedTestCase<Fixture, Tests, Types>::Register()
607 // registers *all combinations* of 'Tests' and 'Types' with Google
608 // Test. The return value is insignificant - we just need to return
609 // something such that we can call this function in a namespace scope.
610 template <GTEST_TEMPLATE_ Fixture, typename Tests, typename Types>
611 class TypeParameterizedTestCase {
612 public:
613 static bool Register(const char* prefix, const char* case_name,
614 const char* test_names) {
615 typedef typename Tests::Head Head;
616
617 // First, register the first test in 'Test' for each type in 'Types'.
618 TypeParameterizedTest<Fixture, Head, Types>::Register(
619 prefix, case_name, test_names, 0);
620
621 // Next, recurses (at compile time) with the tail of the test list.
622 return TypeParameterizedTestCase<Fixture, typename Tests::Tail, Types>
623 ::Register(prefix, case_name, SkipComma(test_names));
624 }
625 };
626
627 // The base case for the compile time recursion.
628 template <GTEST_TEMPLATE_ Fixture, typename Types>
629 class TypeParameterizedTestCase<Fixture, Templates0, Types> {
630 public:
631 static bool Register(const char* /*prefix*/, const char* /*case_name*/,
632 const char* /*test_names*/) {
633 return true;
634 }
635 };
636
637 #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
638
639 // Returns the current OS stack trace as an std::string.
640 //
641 // The maximum number of stack frames to be included is specified by
642 // the gtest_stack_trace_depth flag. The skip_count parameter
643 // specifies the number of top frames to be skipped, which doesn't
644 // count against the number of frames to be included.
645 //
646 // For example, if Foo() calls Bar(), which in turn calls
647 // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
648 // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
649 GTEST_API_ std::string GetCurrentOsStackTraceExceptTop(
650 UnitTest* unit_test, int skip_count);
651
652 // Helpers for suppressing warnings on unreachable code or constant
653 // condition.
654
655 // Always returns true.
656 GTEST_API_ bool AlwaysTrue();
657
658 // Always returns false.
659 inline bool AlwaysFalse() { return !AlwaysTrue(); }
660
661 // Helper for suppressing false warning from Clang on a const char*
662 // variable declared in a conditional expression always being NULL in
663 // the else branch.
664 struct GTEST_API_ ConstCharPtr {
665 ConstCharPtr(const char* str) : value(str) {}
666 operator bool() const { return true; }
667 const char* value;
668 };
669
670 // A simple Linear Congruential Generator for generating random
671 // numbers with a uniform distribution. Unlike rand() and srand(), it
672 // doesn't use global state (and therefore can't interfere with user
673 // code). Unlike rand_r(), it's portable. An LCG isn't very random,
674 // but it's good enough for our purposes.
675 class GTEST_API_ Random {
676 public:
677 static const UInt32 kMaxRange = 1u << 31;
678
679 explicit Random(UInt32 seed) : state_(seed) {}
680
681 void Reseed(UInt32 seed) { state_ = seed; }
682
683 // Generates a random number from [0, range). Crashes if 'range' is
684 // 0 or greater than kMaxRange.
685 UInt32 Generate(UInt32 range);
686
687 private:
688 UInt32 state_;
689 GTEST_DISALLOW_COPY_AND_ASSIGN_(Random);
690 };
691
692 // Defining a variable of type CompileAssertTypesEqual<T1, T2> will cause a
693 // compiler error iff T1 and T2 are different types.
694 template <typename T1, typename T2>
695 struct CompileAssertTypesEqual;
696
697 template <typename T>
698 struct CompileAssertTypesEqual<T, T> {
699 };
700
701 // Removes the reference from a type if it is a reference type,
702 // otherwise leaves it unchanged. This is the same as
703 // tr1::remove_reference, which is not widely available yet.
704 template <typename T>
705 struct RemoveReference { typedef T type; }; // NOLINT
706 template <typename T>
707 struct RemoveReference<T&> { typedef T type; }; // NOLINT
708
709 // A handy wrapper around RemoveReference that works when the argument
710 // T depends on template parameters.
711 #define GTEST_REMOVE_REFERENCE_(T) \
712 typename ::testing::internal::RemoveReference<T>::type
713
714 // Removes const from a type if it is a const type, otherwise leaves
715 // it unchanged. This is the same as tr1::remove_const, which is not
716 // widely available yet.
717 template <typename T>
718 struct RemoveConst { typedef T type; }; // NOLINT
719 template <typename T>
720 struct RemoveConst<const T> { typedef T type; }; // NOLINT
721
722 // MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above
723 // definition to fail to remove the const in 'const int[3]' and 'const
724 // char[3][4]'. The following specialization works around the bug.
725 template <typename T, size_t N>
726 struct RemoveConst<const T[N]> {
727 typedef typename RemoveConst<T>::type type[N];
728 };
729
730 #if defined(_MSC_VER) && _MSC_VER < 1400
731 // This is the only specialization that allows VC++ 7.1 to remove const in
732 // 'const int[3] and 'const int[3][4]'. However, it causes trouble with GCC
733 // and thus needs to be conditionally compiled.
734 template <typename T, size_t N>
735 struct RemoveConst<T[N]> {
736 typedef typename RemoveConst<T>::type type[N];
737 };
738 #endif
739
740 // A handy wrapper around RemoveConst that works when the argument
741 // T depends on template parameters.
742 #define GTEST_REMOVE_CONST_(T) \
743 typename ::testing::internal::RemoveConst<T>::type
744
745 // Turns const U&, U&, const U, and U all into U.
746 #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \
747 GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T))
748
749 // Adds reference to a type if it is not a reference type,
750 // otherwise leaves it unchanged. This is the same as
751 // tr1::add_reference, which is not widely available yet.
752 template <typename T>
753 struct AddReference { typedef T& type; }; // NOLINT
754 template <typename T>
755 struct AddReference<T&> { typedef T& type; }; // NOLINT
756
757 // A handy wrapper around AddReference that works when the argument T
758 // depends on template parameters.
759 #define GTEST_ADD_REFERENCE_(T) \
760 typename ::testing::internal::AddReference<T>::type
761
762 // Adds a reference to const on top of T as necessary. For example,
763 // it transforms
764 //
765 // char ==> const char&
766 // const char ==> const char&
767 // char& ==> const char&
768 // const char& ==> const char&
769 //
770 // The argument T must depend on some template parameters.
771 #define GTEST_REFERENCE_TO_CONST_(T) \
772 GTEST_ADD_REFERENCE_(const GTEST_REMOVE_REFERENCE_(T))
773
774 // ImplicitlyConvertible<From, To>::value is a compile-time bool
775 // constant that's true iff type From can be implicitly converted to
776 // type To.
777 template <typename From, typename To>
778 class ImplicitlyConvertible {
779 private:
780 // We need the following helper functions only for their types.
781 // They have no implementations.
782
783 // MakeFrom() is an expression whose type is From. We cannot simply
784 // use From(), as the type From may not have a public default
785 // constructor.
786 static From MakeFrom();
787
788 // These two functions are overloaded. Given an expression
789 // Helper(x), the compiler will pick the first version if x can be
790 // implicitly converted to type To; otherwise it will pick the
791 // second version.
792 //
793 // The first version returns a value of size 1, and the second
794 // version returns a value of size 2. Therefore, by checking the
795 // size of Helper(x), which can be done at compile time, we can tell
796 // which version of Helper() is used, and hence whether x can be
797 // implicitly converted to type To.
798 static char Helper(To);
799 static char (&Helper(...))[2]; // NOLINT
800
801 // We have to put the 'public' section after the 'private' section,
802 // or MSVC refuses to compile the code.
803 public:
804 // MSVC warns about implicitly converting from double to int for
805 // possible loss of data, so we need to temporarily disable the
806 // warning.
807 #ifdef _MSC_VER
808 # pragma warning(push) // Saves the current warning state.
809 # pragma warning(disable:4244) // Temporarily disables warning 4244.
810
811 static const bool value =
812 sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
813 # pragma warning(pop) // Restores the warning state.
814 #elif defined(__BORLANDC__)
815 // C++Builder cannot use member overload resolution during template
816 // instantiation. The simplest workaround is to use its C++0x type traits
817 // functions (C++Builder 2009 and above only).
818 static const bool value = __is_convertible(From, To);
819 #else
820 static const bool value =
821 sizeof(Helper(ImplicitlyConvertible::MakeFrom())) == 1;
822 #endif // _MSV_VER
823 };
824 template <typename From, typename To>
825 const bool ImplicitlyConvertible<From, To>::value;
826
827 // IsAProtocolMessage<T>::value is a compile-time bool constant that's
828 // true iff T is type ProtocolMessage, proto2::Message, or a subclass
829 // of those.
830 template <typename T>
831 struct IsAProtocolMessage
832 : public bool_constant<
833 ImplicitlyConvertible<const T*, const ::ProtocolMessage*>::value ||
834 ImplicitlyConvertible<const T*, const ::proto2::Message*>::value> {
835 };
836
837 // When the compiler sees expression IsContainerTest<C>(0), if C is an
838 // STL-style container class, the first overload of IsContainerTest
839 // will be viable (since both C::iterator* and C::const_iterator* are
840 // valid types and NULL can be implicitly converted to them). It will
841 // be picked over the second overload as 'int' is a perfect match for
842 // the type of argument 0. If C::iterator or C::const_iterator is not
843 // a valid type, the first overload is not viable, and the second
844 // overload will be picked. Therefore, we can determine whether C is
845 // a container class by checking the type of IsContainerTest<C>(0).
846 // The value of the expression is insignificant.
847 //
848 // Note that we look for both C::iterator and C::const_iterator. The
849 // reason is that C++ injects the name of a class as a member of the
850 // class itself (e.g. you can refer to class iterator as either
851 // 'iterator' or 'iterator::iterator'). If we look for C::iterator
852 // only, for example, we would mistakenly think that a class named
853 // iterator is an STL container.
854 //
855 // Also note that the simpler approach of overloading
856 // IsContainerTest(typename C::const_iterator*) and
857 // IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++.
858 typedef int IsContainer;
859 template <class C>
860 IsContainer IsContainerTest(int /* dummy */,
861 typename C::iterator* /* it */ = NULL,
862 typename C::const_iterator* /* const_it */ = NULL) {
863 return 0;
864 }
865
866 typedef char IsNotContainer;
867 template <class C>
868 IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; }
869
870 // EnableIf<condition>::type is void when 'Cond' is true, and
871 // undefined when 'Cond' is false. To use SFINAE to make a function
872 // overload only apply when a particular expression is true, add
873 // "typename EnableIf<expression>::type* = 0" as the last parameter.
874 template<bool> struct EnableIf;
875 template<> struct EnableIf<true> { typedef void type; }; // NOLINT
876
877 // Utilities for native arrays.
878
879 // ArrayEq() compares two k-dimensional native arrays using the
880 // elements' operator==, where k can be any integer >= 0. When k is
881 // 0, ArrayEq() degenerates into comparing a single pair of values.
882
883 template <typename T, typename U>
884 bool ArrayEq(const T* lhs, size_t size, const U* rhs);
885
886 // This generic version is used when k is 0.
887 template <typename T, typename U>
888 inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; }
889
890 // This overload is used when k >= 1.
891 template <typename T, typename U, size_t N>
892 inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) {
893 return internal::ArrayEq(lhs, N, rhs);
894 }
895
896 // This helper reduces code bloat. If we instead put its logic inside
897 // the previous ArrayEq() function, arrays with different sizes would
898 // lead to different copies of the template code.
899 template <typename T, typename U>
900 bool ArrayEq(const T* lhs, size_t size, const U* rhs) {
901 for (size_t i = 0; i != size; i++) {
902 if (!internal::ArrayEq(lhs[i], rhs[i]))
903 return false;
904 }
905 return true;
906 }
907
908 // Finds the first element in the iterator range [begin, end) that
909 // equals elem. Element may be a native array type itself.
910 template <typename Iter, typename Element>
911 Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) {
912 for (Iter it = begin; it != end; ++it) {
913 if (internal::ArrayEq(*it, elem))
914 return it;
915 }
916 return end;
917 }
918
919 // CopyArray() copies a k-dimensional native array using the elements'
920 // operator=, where k can be any integer >= 0. When k is 0,
921 // CopyArray() degenerates into copying a single value.
922
923 template <typename T, typename U>
924 void CopyArray(const T* from, size_t size, U* to);
925
926 // This generic version is used when k is 0.
927 template <typename T, typename U>
928 inline void CopyArray(const T& from, U* to) { *to = from; }
929
930 // This overload is used when k >= 1.
931 template <typename T, typename U, size_t N>
932 inline void CopyArray(const T(&from)[N], U(*to)[N]) {
933 internal::CopyArray(from, N, *to);
934 }
935
936 // This helper reduces code bloat. If we instead put its logic inside
937 // the previous CopyArray() function, arrays with different sizes
938 // would lead to different copies of the template code.
939 template <typename T, typename U>
940 void CopyArray(const T* from, size_t size, U* to) {
941 for (size_t i = 0; i != size; i++) {
942 internal::CopyArray(from[i], to + i);
943 }
944 }
945
946 // The relation between an NativeArray object (see below) and the
947 // native array it represents.
948 enum RelationToSource {
949 kReference, // The NativeArray references the native array.
950 kCopy // The NativeArray makes a copy of the native array and
951 // owns the copy.
952 };
953
954 // Adapts a native array to a read-only STL-style container. Instead
955 // of the complete STL container concept, this adaptor only implements
956 // members useful for Google Mock's container matchers. New members
957 // should be added as needed. To simplify the implementation, we only
958 // support Element being a raw type (i.e. having no top-level const or
959 // reference modifier). It's the client's responsibility to satisfy
960 // this requirement. Element can be an array type itself (hence
961 // multi-dimensional arrays are supported).
962 template <typename Element>
963 class NativeArray {
964 public:
965 // STL-style container typedefs.
966 typedef Element value_type;
967 typedef Element* iterator;
968 typedef const Element* const_iterator;
969
970 // Constructs from a native array.
971 NativeArray(const Element* array, size_t count, RelationToSource relation) {
972 Init(array, count, relation);
973 }
974
975 // Copy constructor.
976 NativeArray(const NativeArray& rhs) {
977 Init(rhs.array_, rhs.size_, rhs.relation_to_source_);
978 }
979
980 ~NativeArray() {
981 // Ensures that the user doesn't instantiate NativeArray with a
982 // const or reference type.
983 static_cast<void>(StaticAssertTypeEqHelper<Element,
984 GTEST_REMOVE_REFERENCE_AND_CONST_(Element)>());
985 if (relation_to_source_ == kCopy)
986 delete[] array_;
987 }
988
989 // STL-style container methods.
990 size_t size() const { return size_; }
991 const_iterator begin() const { return array_; }
992 const_iterator end() const { return array_ + size_; }
993 bool operator==(const NativeArray& rhs) const {
994 return size() == rhs.size() &&
995 ArrayEq(begin(), size(), rhs.begin());
996 }
997
998 private:
999 // Initializes this object; makes a copy of the input array if
1000 // 'relation' is kCopy.
1001 void Init(const Element* array, size_t a_size, RelationToSource relation) {
1002 if (relation == kReference) {
1003 array_ = array;
1004 } else {
1005 Element* const copy = new Element[a_size];
1006 CopyArray(array, a_size, copy);
1007 array_ = copy;
1008 }
1009 size_ = a_size;
1010 relation_to_source_ = relation;
1011 }
1012
1013 const Element* array_;
1014 size_t size_;
1015 RelationToSource relation_to_source_;
1016
1017 GTEST_DISALLOW_ASSIGN_(NativeArray);
1018 };
1019
1020 } // namespace internal
1021 } // namespace testing
1022
1023 #define GTEST_MESSAGE_AT_(file, line, message, result_type) \
1024 ::testing::internal::AssertHelper(result_type, file, line, message) \
1025 = ::testing::Message()
1026
1027 #define GTEST_MESSAGE_(message, result_type) \
1028 GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type)
1029
1030 #define GTEST_FATAL_FAILURE_(message) \
1031 return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure)
1032
1033 #define GTEST_NONFATAL_FAILURE_(message) \
1034 GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure)
1035
1036 #define GTEST_SUCCESS_(message) \
1037 GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess)
1038
1039 // Suppresses MSVC warnings 4072 (unreachable code) for the code following
1040 // statement if it returns or throws (or doesn't return or throw in some
1041 // situations).
1042 #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
1043 if (::testing::internal::AlwaysTrue()) { statement; }
1044
1045 #define GTEST_TEST_THROW_(statement, expected_exception, fail) \
1046 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1047 if (::testing::internal::ConstCharPtr gtest_msg = "") { \
1048 bool gtest_caught_expected = false; \
1049 try { \
1050 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1051 } \
1052 catch (expected_exception const&) { \
1053 gtest_caught_expected = true; \
1054 } \
1055 catch (...) { \
1056 gtest_msg.value = \
1057 "Expected: " #statement " throws an exception of type " \
1058 #expected_exception ".\n Actual: it throws a different type."; \
1059 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1060 } \
1061 if (!gtest_caught_expected) { \
1062 gtest_msg.value = \
1063 "Expected: " #statement " throws an exception of type " \
1064 #expected_exception ".\n Actual: it throws nothing."; \
1065 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
1066 } \
1067 } else \
1068 GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
1069 fail(gtest_msg.value)
1070
1071 #define GTEST_TEST_NO_THROW_(statement, fail) \
1072 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1073 if (::testing::internal::AlwaysTrue()) { \
1074 try { \
1075 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1076 } \
1077 catch (...) { \
1078 goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
1079 } \
1080 } else \
1081 GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
1082 fail("Expected: " #statement " doesn't throw an exception.\n" \
1083 " Actual: it throws.")
1084
1085 #define GTEST_TEST_ANY_THROW_(statement, fail) \
1086 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1087 if (::testing::internal::AlwaysTrue()) { \
1088 bool gtest_caught_any = false; \
1089 try { \
1090 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1091 } \
1092 catch (...) { \
1093 gtest_caught_any = true; \
1094 } \
1095 if (!gtest_caught_any) { \
1096 goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \
1097 } \
1098 } else \
1099 GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \
1100 fail("Expected: " #statement " throws an exception.\n" \
1101 " Actual: it doesn't.")
1102
1103
1104 // Implements Boolean test assertions such as EXPECT_TRUE. expression can be
1105 // either a boolean expression or an AssertionResult. text is a textual
1106 // represenation of expression as it was passed into the EXPECT_TRUE.
1107 #define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \
1108 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1109 if (const ::testing::AssertionResult gtest_ar_ = \
1110 ::testing::AssertionResult(expression)) \
1111 ; \
1112 else \
1113 fail(::testing::internal::GetBoolAssertionFailureMessage(\
1114 gtest_ar_, text, #actual, #expected).c_str())
1115
1116 #define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \
1117 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1118 if (::testing::internal::AlwaysTrue()) { \
1119 ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
1120 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
1121 if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
1122 goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \
1123 } \
1124 } else \
1125 GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \
1126 fail("Expected: " #statement " doesn't generate new fatal " \
1127 "failures in the current thread.\n" \
1128 " Actual: it does.")
1129
1130 // Expands to the name of the class that implements the given test.
1131 #define GTEST_TEST_CLASS_NAME_(test_case_name, test_name) \
1132 test_case_name##_##test_name##_Test
1133
1134 // Helper macro for defining tests.
1135 #define GTEST_TEST_(test_case_name, test_name, parent_class, parent_id)\
1136 class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\
1137 public:\
1138 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)() {}\
1139 private:\
1140 virtual void TestBody();\
1141 static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_;\
1142 GTEST_DISALLOW_COPY_AND_ASSIGN_(\
1143 GTEST_TEST_CLASS_NAME_(test_case_name, test_name));\
1144 };\
1145 \
1146 ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\
1147 ::test_info_ =\
1148 ::testing::internal::MakeAndRegisterTestInfo(\
1149 #test_case_name, #test_name, NULL, NULL, \
1150 (parent_id), \
1151 parent_class::SetUpTestCase, \
1152 parent_class::TearDownTestCase, \
1153 new ::testing::internal::TestFactoryImpl<\
1154 GTEST_TEST_CLASS_NAME_(test_case_name, test_name)>);\
1155 void GTEST_TEST_CLASS_NAME_(test_case_name, test_name)::TestBody()
1156
1157 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_
0 // Copyright 2003 Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Authors: Dan Egnor (egnor@google.com)
30 //
31 // A "smart" pointer type with reference tracking. Every pointer to a
32 // particular object is kept on a circular linked list. When the last pointer
33 // to an object is destroyed or reassigned, the object is deleted.
34 //
35 // Used properly, this deletes the object when the last reference goes away.
36 // There are several caveats:
37 // - Like all reference counting schemes, cycles lead to leaks.
38 // - Each smart pointer is actually two pointers (8 bytes instead of 4).
39 // - Every time a pointer is assigned, the entire list of pointers to that
40 // object is traversed. This class is therefore NOT SUITABLE when there
41 // will often be more than two or three pointers to a particular object.
42 // - References are only tracked as long as linked_ptr<> objects are copied.
43 // If a linked_ptr<> is converted to a raw pointer and back, BAD THINGS
44 // will happen (double deletion).
45 //
46 // A good use of this class is storing object references in STL containers.
47 // You can safely put linked_ptr<> in a vector<>.
48 // Other uses may not be as good.
49 //
50 // Note: If you use an incomplete type with linked_ptr<>, the class
51 // *containing* linked_ptr<> must have a constructor and destructor (even
52 // if they do nothing!).
53 //
54 // Bill Gibbons suggested we use something like this.
55 //
56 // Thread Safety:
57 // Unlike other linked_ptr implementations, in this implementation
58 // a linked_ptr object is thread-safe in the sense that:
59 // - it's safe to copy linked_ptr objects concurrently,
60 // - it's safe to copy *from* a linked_ptr and read its underlying
61 // raw pointer (e.g. via get()) concurrently, and
62 // - it's safe to write to two linked_ptrs that point to the same
63 // shared object concurrently.
64 // TODO(wan@google.com): rename this to safe_linked_ptr to avoid
65 // confusion with normal linked_ptr.
66
67 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
68 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
69
70 #include <stdlib.h>
71 #include <assert.h>
72
73 #include "gtest/internal/gtest-port.h"
74
75 namespace testing {
76 namespace internal {
77
78 // Protects copying of all linked_ptr objects.
79 GTEST_API_ GTEST_DECLARE_STATIC_MUTEX_(g_linked_ptr_mutex);
80
81 // This is used internally by all instances of linked_ptr<>. It needs to be
82 // a non-template class because different types of linked_ptr<> can refer to
83 // the same object (linked_ptr<Superclass>(obj) vs linked_ptr<Subclass>(obj)).
84 // So, it needs to be possible for different types of linked_ptr to participate
85 // in the same circular linked list, so we need a single class type here.
86 //
87 // DO NOT USE THIS CLASS DIRECTLY YOURSELF. Use linked_ptr<T>.
88 class linked_ptr_internal {
89 public:
90 // Create a new circle that includes only this instance.
91 void join_new() {
92 next_ = this;
93 }
94
95 // Many linked_ptr operations may change p.link_ for some linked_ptr
96 // variable p in the same circle as this object. Therefore we need
97 // to prevent two such operations from occurring concurrently.
98 //
99 // Note that different types of linked_ptr objects can coexist in a
100 // circle (e.g. linked_ptr<Base>, linked_ptr<Derived1>, and
101 // linked_ptr<Derived2>). Therefore we must use a single mutex to
102 // protect all linked_ptr objects. This can create serious
103 // contention in production code, but is acceptable in a testing
104 // framework.
105
106 // Join an existing circle.
107 void join(linked_ptr_internal const* ptr)
108 GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) {
109 MutexLock lock(&g_linked_ptr_mutex);
110
111 linked_ptr_internal const* p = ptr;
112 while (p->next_ != ptr) p = p->next_;
113 p->next_ = this;
114 next_ = ptr;
115 }
116
117 // Leave whatever circle we're part of. Returns true if we were the
118 // last member of the circle. Once this is done, you can join() another.
119 bool depart()
120 GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) {
121 MutexLock lock(&g_linked_ptr_mutex);
122
123 if (next_ == this) return true;
124 linked_ptr_internal const* p = next_;
125 while (p->next_ != this) p = p->next_;
126 p->next_ = next_;
127 return false;
128 }
129
130 private:
131 mutable linked_ptr_internal const* next_;
132 };
133
134 template <typename T>
135 class linked_ptr {
136 public:
137 typedef T element_type;
138
139 // Take over ownership of a raw pointer. This should happen as soon as
140 // possible after the object is created.
141 explicit linked_ptr(T* ptr = NULL) { capture(ptr); }
142 ~linked_ptr() { depart(); }
143
144 // Copy an existing linked_ptr<>, adding ourselves to the list of references.
145 template <typename U> linked_ptr(linked_ptr<U> const& ptr) { copy(&ptr); }
146 linked_ptr(linked_ptr const& ptr) { // NOLINT
147 assert(&ptr != this);
148 copy(&ptr);
149 }
150
151 // Assignment releases the old value and acquires the new.
152 template <typename U> linked_ptr& operator=(linked_ptr<U> const& ptr) {
153 depart();
154 copy(&ptr);
155 return *this;
156 }
157
158 linked_ptr& operator=(linked_ptr const& ptr) {
159 if (&ptr != this) {
160 depart();
161 copy(&ptr);
162 }
163 return *this;
164 }
165
166 // Smart pointer members.
167 void reset(T* ptr = NULL) {
168 depart();
169 capture(ptr);
170 }
171 T* get() const { return value_; }
172 T* operator->() const { return value_; }
173 T& operator*() const { return *value_; }
174
175 bool operator==(T* p) const { return value_ == p; }
176 bool operator!=(T* p) const { return value_ != p; }
177 template <typename U>
178 bool operator==(linked_ptr<U> const& ptr) const {
179 return value_ == ptr.get();
180 }
181 template <typename U>
182 bool operator!=(linked_ptr<U> const& ptr) const {
183 return value_ != ptr.get();
184 }
185
186 private:
187 template <typename U>
188 friend class linked_ptr;
189
190 T* value_;
191 linked_ptr_internal link_;
192
193 void depart() {
194 if (link_.depart()) delete value_;
195 }
196
197 void capture(T* ptr) {
198 value_ = ptr;
199 link_.join_new();
200 }
201
202 template <typename U> void copy(linked_ptr<U> const* ptr) {
203 value_ = ptr->get();
204 if (value_)
205 link_.join(&ptr->link_);
206 else
207 link_.join_new();
208 }
209 };
210
211 template<typename T> inline
212 bool operator==(T* ptr, const linked_ptr<T>& x) {
213 return ptr == x.get();
214 }
215
216 template<typename T> inline
217 bool operator!=(T* ptr, const linked_ptr<T>& x) {
218 return ptr != x.get();
219 }
220
221 // A function to convert T* into linked_ptr<T>
222 // Doing e.g. make_linked_ptr(new FooBarBaz<type>(arg)) is a shorter notation
223 // for linked_ptr<FooBarBaz<type> >(new FooBarBaz<type>(arg))
224 template <typename T>
225 linked_ptr<T> make_linked_ptr(T* ptr) {
226 return linked_ptr<T>(ptr);
227 }
228
229 } // namespace internal
230 } // namespace testing
231
232 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_LINKED_PTR_H_
0 // This file was GENERATED by command:
1 // pump.py gtest-param-util-generated.h.pump
2 // DO NOT EDIT BY HAND!!!
3
4 // Copyright 2008 Google Inc.
5 // All Rights Reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
9 // met:
10 //
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Author: vladl@google.com (Vlad Losev)
34
35 // Type and function utilities for implementing parameterized tests.
36 // This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
37 //
38 // Currently Google Test supports at most 50 arguments in Values,
39 // and at most 10 arguments in Combine. Please contact
40 // googletestframework@googlegroups.com if you need more.
41 // Please note that the number of arguments to Combine is limited
42 // by the maximum arity of the implementation of tr1::tuple which is
43 // currently set at 10.
44
45 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
46 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
47
48 // scripts/fuse_gtest.py depends on gtest's own header being #included
49 // *unconditionally*. Therefore these #includes cannot be moved
50 // inside #if GTEST_HAS_PARAM_TEST.
51 #include "gtest/internal/gtest-param-util.h"
52 #include "gtest/internal/gtest-port.h"
53
54 #if GTEST_HAS_PARAM_TEST
55
56 namespace testing {
57
58 // Forward declarations of ValuesIn(), which is implemented in
59 // include/gtest/gtest-param-test.h.
60 template <typename ForwardIterator>
61 internal::ParamGenerator<
62 typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
63 ValuesIn(ForwardIterator begin, ForwardIterator end);
64
65 template <typename T, size_t N>
66 internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
67
68 template <class Container>
69 internal::ParamGenerator<typename Container::value_type> ValuesIn(
70 const Container& container);
71
72 namespace internal {
73
74 // Used in the Values() function to provide polymorphic capabilities.
75 template <typename T1>
76 class ValueArray1 {
77 public:
78 explicit ValueArray1(T1 v1) : v1_(v1) {}
79
80 template <typename T>
81 operator ParamGenerator<T>() const { return ValuesIn(&v1_, &v1_ + 1); }
82
83 private:
84 // No implementation - assignment is unsupported.
85 void operator=(const ValueArray1& other);
86
87 const T1 v1_;
88 };
89
90 template <typename T1, typename T2>
91 class ValueArray2 {
92 public:
93 ValueArray2(T1 v1, T2 v2) : v1_(v1), v2_(v2) {}
94
95 template <typename T>
96 operator ParamGenerator<T>() const {
97 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_)};
98 return ValuesIn(array);
99 }
100
101 private:
102 // No implementation - assignment is unsupported.
103 void operator=(const ValueArray2& other);
104
105 const T1 v1_;
106 const T2 v2_;
107 };
108
109 template <typename T1, typename T2, typename T3>
110 class ValueArray3 {
111 public:
112 ValueArray3(T1 v1, T2 v2, T3 v3) : v1_(v1), v2_(v2), v3_(v3) {}
113
114 template <typename T>
115 operator ParamGenerator<T>() const {
116 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
117 static_cast<T>(v3_)};
118 return ValuesIn(array);
119 }
120
121 private:
122 // No implementation - assignment is unsupported.
123 void operator=(const ValueArray3& other);
124
125 const T1 v1_;
126 const T2 v2_;
127 const T3 v3_;
128 };
129
130 template <typename T1, typename T2, typename T3, typename T4>
131 class ValueArray4 {
132 public:
133 ValueArray4(T1 v1, T2 v2, T3 v3, T4 v4) : v1_(v1), v2_(v2), v3_(v3),
134 v4_(v4) {}
135
136 template <typename T>
137 operator ParamGenerator<T>() const {
138 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
139 static_cast<T>(v3_), static_cast<T>(v4_)};
140 return ValuesIn(array);
141 }
142
143 private:
144 // No implementation - assignment is unsupported.
145 void operator=(const ValueArray4& other);
146
147 const T1 v1_;
148 const T2 v2_;
149 const T3 v3_;
150 const T4 v4_;
151 };
152
153 template <typename T1, typename T2, typename T3, typename T4, typename T5>
154 class ValueArray5 {
155 public:
156 ValueArray5(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5) : v1_(v1), v2_(v2), v3_(v3),
157 v4_(v4), v5_(v5) {}
158
159 template <typename T>
160 operator ParamGenerator<T>() const {
161 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
162 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_)};
163 return ValuesIn(array);
164 }
165
166 private:
167 // No implementation - assignment is unsupported.
168 void operator=(const ValueArray5& other);
169
170 const T1 v1_;
171 const T2 v2_;
172 const T3 v3_;
173 const T4 v4_;
174 const T5 v5_;
175 };
176
177 template <typename T1, typename T2, typename T3, typename T4, typename T5,
178 typename T6>
179 class ValueArray6 {
180 public:
181 ValueArray6(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6) : v1_(v1), v2_(v2),
182 v3_(v3), v4_(v4), v5_(v5), v6_(v6) {}
183
184 template <typename T>
185 operator ParamGenerator<T>() const {
186 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
187 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
188 static_cast<T>(v6_)};
189 return ValuesIn(array);
190 }
191
192 private:
193 // No implementation - assignment is unsupported.
194 void operator=(const ValueArray6& other);
195
196 const T1 v1_;
197 const T2 v2_;
198 const T3 v3_;
199 const T4 v4_;
200 const T5 v5_;
201 const T6 v6_;
202 };
203
204 template <typename T1, typename T2, typename T3, typename T4, typename T5,
205 typename T6, typename T7>
206 class ValueArray7 {
207 public:
208 ValueArray7(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7) : v1_(v1),
209 v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7) {}
210
211 template <typename T>
212 operator ParamGenerator<T>() const {
213 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
214 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
215 static_cast<T>(v6_), static_cast<T>(v7_)};
216 return ValuesIn(array);
217 }
218
219 private:
220 // No implementation - assignment is unsupported.
221 void operator=(const ValueArray7& other);
222
223 const T1 v1_;
224 const T2 v2_;
225 const T3 v3_;
226 const T4 v4_;
227 const T5 v5_;
228 const T6 v6_;
229 const T7 v7_;
230 };
231
232 template <typename T1, typename T2, typename T3, typename T4, typename T5,
233 typename T6, typename T7, typename T8>
234 class ValueArray8 {
235 public:
236 ValueArray8(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7,
237 T8 v8) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
238 v8_(v8) {}
239
240 template <typename T>
241 operator ParamGenerator<T>() const {
242 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
243 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
244 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_)};
245 return ValuesIn(array);
246 }
247
248 private:
249 // No implementation - assignment is unsupported.
250 void operator=(const ValueArray8& other);
251
252 const T1 v1_;
253 const T2 v2_;
254 const T3 v3_;
255 const T4 v4_;
256 const T5 v5_;
257 const T6 v6_;
258 const T7 v7_;
259 const T8 v8_;
260 };
261
262 template <typename T1, typename T2, typename T3, typename T4, typename T5,
263 typename T6, typename T7, typename T8, typename T9>
264 class ValueArray9 {
265 public:
266 ValueArray9(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8,
267 T9 v9) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
268 v8_(v8), v9_(v9) {}
269
270 template <typename T>
271 operator ParamGenerator<T>() const {
272 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
273 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
274 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
275 static_cast<T>(v9_)};
276 return ValuesIn(array);
277 }
278
279 private:
280 // No implementation - assignment is unsupported.
281 void operator=(const ValueArray9& other);
282
283 const T1 v1_;
284 const T2 v2_;
285 const T3 v3_;
286 const T4 v4_;
287 const T5 v5_;
288 const T6 v6_;
289 const T7 v7_;
290 const T8 v8_;
291 const T9 v9_;
292 };
293
294 template <typename T1, typename T2, typename T3, typename T4, typename T5,
295 typename T6, typename T7, typename T8, typename T9, typename T10>
296 class ValueArray10 {
297 public:
298 ValueArray10(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
299 T10 v10) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
300 v8_(v8), v9_(v9), v10_(v10) {}
301
302 template <typename T>
303 operator ParamGenerator<T>() const {
304 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
305 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
306 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
307 static_cast<T>(v9_), static_cast<T>(v10_)};
308 return ValuesIn(array);
309 }
310
311 private:
312 // No implementation - assignment is unsupported.
313 void operator=(const ValueArray10& other);
314
315 const T1 v1_;
316 const T2 v2_;
317 const T3 v3_;
318 const T4 v4_;
319 const T5 v5_;
320 const T6 v6_;
321 const T7 v7_;
322 const T8 v8_;
323 const T9 v9_;
324 const T10 v10_;
325 };
326
327 template <typename T1, typename T2, typename T3, typename T4, typename T5,
328 typename T6, typename T7, typename T8, typename T9, typename T10,
329 typename T11>
330 class ValueArray11 {
331 public:
332 ValueArray11(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
333 T10 v10, T11 v11) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6),
334 v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11) {}
335
336 template <typename T>
337 operator ParamGenerator<T>() const {
338 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
339 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
340 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
341 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_)};
342 return ValuesIn(array);
343 }
344
345 private:
346 // No implementation - assignment is unsupported.
347 void operator=(const ValueArray11& other);
348
349 const T1 v1_;
350 const T2 v2_;
351 const T3 v3_;
352 const T4 v4_;
353 const T5 v5_;
354 const T6 v6_;
355 const T7 v7_;
356 const T8 v8_;
357 const T9 v9_;
358 const T10 v10_;
359 const T11 v11_;
360 };
361
362 template <typename T1, typename T2, typename T3, typename T4, typename T5,
363 typename T6, typename T7, typename T8, typename T9, typename T10,
364 typename T11, typename T12>
365 class ValueArray12 {
366 public:
367 ValueArray12(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
368 T10 v10, T11 v11, T12 v12) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5),
369 v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12) {}
370
371 template <typename T>
372 operator ParamGenerator<T>() const {
373 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
374 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
375 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
376 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
377 static_cast<T>(v12_)};
378 return ValuesIn(array);
379 }
380
381 private:
382 // No implementation - assignment is unsupported.
383 void operator=(const ValueArray12& other);
384
385 const T1 v1_;
386 const T2 v2_;
387 const T3 v3_;
388 const T4 v4_;
389 const T5 v5_;
390 const T6 v6_;
391 const T7 v7_;
392 const T8 v8_;
393 const T9 v9_;
394 const T10 v10_;
395 const T11 v11_;
396 const T12 v12_;
397 };
398
399 template <typename T1, typename T2, typename T3, typename T4, typename T5,
400 typename T6, typename T7, typename T8, typename T9, typename T10,
401 typename T11, typename T12, typename T13>
402 class ValueArray13 {
403 public:
404 ValueArray13(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
405 T10 v10, T11 v11, T12 v12, T13 v13) : v1_(v1), v2_(v2), v3_(v3), v4_(v4),
406 v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11),
407 v12_(v12), v13_(v13) {}
408
409 template <typename T>
410 operator ParamGenerator<T>() const {
411 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
412 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
413 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
414 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
415 static_cast<T>(v12_), static_cast<T>(v13_)};
416 return ValuesIn(array);
417 }
418
419 private:
420 // No implementation - assignment is unsupported.
421 void operator=(const ValueArray13& other);
422
423 const T1 v1_;
424 const T2 v2_;
425 const T3 v3_;
426 const T4 v4_;
427 const T5 v5_;
428 const T6 v6_;
429 const T7 v7_;
430 const T8 v8_;
431 const T9 v9_;
432 const T10 v10_;
433 const T11 v11_;
434 const T12 v12_;
435 const T13 v13_;
436 };
437
438 template <typename T1, typename T2, typename T3, typename T4, typename T5,
439 typename T6, typename T7, typename T8, typename T9, typename T10,
440 typename T11, typename T12, typename T13, typename T14>
441 class ValueArray14 {
442 public:
443 ValueArray14(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
444 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14) : v1_(v1), v2_(v2), v3_(v3),
445 v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),
446 v11_(v11), v12_(v12), v13_(v13), v14_(v14) {}
447
448 template <typename T>
449 operator ParamGenerator<T>() const {
450 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
451 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
452 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
453 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
454 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_)};
455 return ValuesIn(array);
456 }
457
458 private:
459 // No implementation - assignment is unsupported.
460 void operator=(const ValueArray14& other);
461
462 const T1 v1_;
463 const T2 v2_;
464 const T3 v3_;
465 const T4 v4_;
466 const T5 v5_;
467 const T6 v6_;
468 const T7 v7_;
469 const T8 v8_;
470 const T9 v9_;
471 const T10 v10_;
472 const T11 v11_;
473 const T12 v12_;
474 const T13 v13_;
475 const T14 v14_;
476 };
477
478 template <typename T1, typename T2, typename T3, typename T4, typename T5,
479 typename T6, typename T7, typename T8, typename T9, typename T10,
480 typename T11, typename T12, typename T13, typename T14, typename T15>
481 class ValueArray15 {
482 public:
483 ValueArray15(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
484 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15) : v1_(v1), v2_(v2),
485 v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),
486 v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15) {}
487
488 template <typename T>
489 operator ParamGenerator<T>() const {
490 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
491 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
492 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
493 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
494 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
495 static_cast<T>(v15_)};
496 return ValuesIn(array);
497 }
498
499 private:
500 // No implementation - assignment is unsupported.
501 void operator=(const ValueArray15& other);
502
503 const T1 v1_;
504 const T2 v2_;
505 const T3 v3_;
506 const T4 v4_;
507 const T5 v5_;
508 const T6 v6_;
509 const T7 v7_;
510 const T8 v8_;
511 const T9 v9_;
512 const T10 v10_;
513 const T11 v11_;
514 const T12 v12_;
515 const T13 v13_;
516 const T14 v14_;
517 const T15 v15_;
518 };
519
520 template <typename T1, typename T2, typename T3, typename T4, typename T5,
521 typename T6, typename T7, typename T8, typename T9, typename T10,
522 typename T11, typename T12, typename T13, typename T14, typename T15,
523 typename T16>
524 class ValueArray16 {
525 public:
526 ValueArray16(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
527 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16) : v1_(v1),
528 v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9),
529 v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15),
530 v16_(v16) {}
531
532 template <typename T>
533 operator ParamGenerator<T>() const {
534 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
535 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
536 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
537 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
538 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
539 static_cast<T>(v15_), static_cast<T>(v16_)};
540 return ValuesIn(array);
541 }
542
543 private:
544 // No implementation - assignment is unsupported.
545 void operator=(const ValueArray16& other);
546
547 const T1 v1_;
548 const T2 v2_;
549 const T3 v3_;
550 const T4 v4_;
551 const T5 v5_;
552 const T6 v6_;
553 const T7 v7_;
554 const T8 v8_;
555 const T9 v9_;
556 const T10 v10_;
557 const T11 v11_;
558 const T12 v12_;
559 const T13 v13_;
560 const T14 v14_;
561 const T15 v15_;
562 const T16 v16_;
563 };
564
565 template <typename T1, typename T2, typename T3, typename T4, typename T5,
566 typename T6, typename T7, typename T8, typename T9, typename T10,
567 typename T11, typename T12, typename T13, typename T14, typename T15,
568 typename T16, typename T17>
569 class ValueArray17 {
570 public:
571 ValueArray17(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
572 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16,
573 T17 v17) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
574 v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),
575 v15_(v15), v16_(v16), v17_(v17) {}
576
577 template <typename T>
578 operator ParamGenerator<T>() const {
579 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
580 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
581 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
582 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
583 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
584 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_)};
585 return ValuesIn(array);
586 }
587
588 private:
589 // No implementation - assignment is unsupported.
590 void operator=(const ValueArray17& other);
591
592 const T1 v1_;
593 const T2 v2_;
594 const T3 v3_;
595 const T4 v4_;
596 const T5 v5_;
597 const T6 v6_;
598 const T7 v7_;
599 const T8 v8_;
600 const T9 v9_;
601 const T10 v10_;
602 const T11 v11_;
603 const T12 v12_;
604 const T13 v13_;
605 const T14 v14_;
606 const T15 v15_;
607 const T16 v16_;
608 const T17 v17_;
609 };
610
611 template <typename T1, typename T2, typename T3, typename T4, typename T5,
612 typename T6, typename T7, typename T8, typename T9, typename T10,
613 typename T11, typename T12, typename T13, typename T14, typename T15,
614 typename T16, typename T17, typename T18>
615 class ValueArray18 {
616 public:
617 ValueArray18(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
618 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
619 T18 v18) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
620 v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),
621 v15_(v15), v16_(v16), v17_(v17), v18_(v18) {}
622
623 template <typename T>
624 operator ParamGenerator<T>() const {
625 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
626 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
627 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
628 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
629 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
630 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
631 static_cast<T>(v18_)};
632 return ValuesIn(array);
633 }
634
635 private:
636 // No implementation - assignment is unsupported.
637 void operator=(const ValueArray18& other);
638
639 const T1 v1_;
640 const T2 v2_;
641 const T3 v3_;
642 const T4 v4_;
643 const T5 v5_;
644 const T6 v6_;
645 const T7 v7_;
646 const T8 v8_;
647 const T9 v9_;
648 const T10 v10_;
649 const T11 v11_;
650 const T12 v12_;
651 const T13 v13_;
652 const T14 v14_;
653 const T15 v15_;
654 const T16 v16_;
655 const T17 v17_;
656 const T18 v18_;
657 };
658
659 template <typename T1, typename T2, typename T3, typename T4, typename T5,
660 typename T6, typename T7, typename T8, typename T9, typename T10,
661 typename T11, typename T12, typename T13, typename T14, typename T15,
662 typename T16, typename T17, typename T18, typename T19>
663 class ValueArray19 {
664 public:
665 ValueArray19(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
666 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
667 T18 v18, T19 v19) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6),
668 v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13),
669 v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19) {}
670
671 template <typename T>
672 operator ParamGenerator<T>() const {
673 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
674 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
675 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
676 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
677 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
678 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
679 static_cast<T>(v18_), static_cast<T>(v19_)};
680 return ValuesIn(array);
681 }
682
683 private:
684 // No implementation - assignment is unsupported.
685 void operator=(const ValueArray19& other);
686
687 const T1 v1_;
688 const T2 v2_;
689 const T3 v3_;
690 const T4 v4_;
691 const T5 v5_;
692 const T6 v6_;
693 const T7 v7_;
694 const T8 v8_;
695 const T9 v9_;
696 const T10 v10_;
697 const T11 v11_;
698 const T12 v12_;
699 const T13 v13_;
700 const T14 v14_;
701 const T15 v15_;
702 const T16 v16_;
703 const T17 v17_;
704 const T18 v18_;
705 const T19 v19_;
706 };
707
708 template <typename T1, typename T2, typename T3, typename T4, typename T5,
709 typename T6, typename T7, typename T8, typename T9, typename T10,
710 typename T11, typename T12, typename T13, typename T14, typename T15,
711 typename T16, typename T17, typename T18, typename T19, typename T20>
712 class ValueArray20 {
713 public:
714 ValueArray20(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
715 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
716 T18 v18, T19 v19, T20 v20) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5),
717 v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12),
718 v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18),
719 v19_(v19), v20_(v20) {}
720
721 template <typename T>
722 operator ParamGenerator<T>() const {
723 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
724 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
725 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
726 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
727 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
728 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
729 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_)};
730 return ValuesIn(array);
731 }
732
733 private:
734 // No implementation - assignment is unsupported.
735 void operator=(const ValueArray20& other);
736
737 const T1 v1_;
738 const T2 v2_;
739 const T3 v3_;
740 const T4 v4_;
741 const T5 v5_;
742 const T6 v6_;
743 const T7 v7_;
744 const T8 v8_;
745 const T9 v9_;
746 const T10 v10_;
747 const T11 v11_;
748 const T12 v12_;
749 const T13 v13_;
750 const T14 v14_;
751 const T15 v15_;
752 const T16 v16_;
753 const T17 v17_;
754 const T18 v18_;
755 const T19 v19_;
756 const T20 v20_;
757 };
758
759 template <typename T1, typename T2, typename T3, typename T4, typename T5,
760 typename T6, typename T7, typename T8, typename T9, typename T10,
761 typename T11, typename T12, typename T13, typename T14, typename T15,
762 typename T16, typename T17, typename T18, typename T19, typename T20,
763 typename T21>
764 class ValueArray21 {
765 public:
766 ValueArray21(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
767 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
768 T18 v18, T19 v19, T20 v20, T21 v21) : v1_(v1), v2_(v2), v3_(v3), v4_(v4),
769 v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11),
770 v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17),
771 v18_(v18), v19_(v19), v20_(v20), v21_(v21) {}
772
773 template <typename T>
774 operator ParamGenerator<T>() const {
775 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
776 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
777 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
778 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
779 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
780 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
781 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
782 static_cast<T>(v21_)};
783 return ValuesIn(array);
784 }
785
786 private:
787 // No implementation - assignment is unsupported.
788 void operator=(const ValueArray21& other);
789
790 const T1 v1_;
791 const T2 v2_;
792 const T3 v3_;
793 const T4 v4_;
794 const T5 v5_;
795 const T6 v6_;
796 const T7 v7_;
797 const T8 v8_;
798 const T9 v9_;
799 const T10 v10_;
800 const T11 v11_;
801 const T12 v12_;
802 const T13 v13_;
803 const T14 v14_;
804 const T15 v15_;
805 const T16 v16_;
806 const T17 v17_;
807 const T18 v18_;
808 const T19 v19_;
809 const T20 v20_;
810 const T21 v21_;
811 };
812
813 template <typename T1, typename T2, typename T3, typename T4, typename T5,
814 typename T6, typename T7, typename T8, typename T9, typename T10,
815 typename T11, typename T12, typename T13, typename T14, typename T15,
816 typename T16, typename T17, typename T18, typename T19, typename T20,
817 typename T21, typename T22>
818 class ValueArray22 {
819 public:
820 ValueArray22(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
821 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
822 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22) : v1_(v1), v2_(v2), v3_(v3),
823 v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),
824 v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),
825 v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22) {}
826
827 template <typename T>
828 operator ParamGenerator<T>() const {
829 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
830 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
831 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
832 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
833 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
834 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
835 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
836 static_cast<T>(v21_), static_cast<T>(v22_)};
837 return ValuesIn(array);
838 }
839
840 private:
841 // No implementation - assignment is unsupported.
842 void operator=(const ValueArray22& other);
843
844 const T1 v1_;
845 const T2 v2_;
846 const T3 v3_;
847 const T4 v4_;
848 const T5 v5_;
849 const T6 v6_;
850 const T7 v7_;
851 const T8 v8_;
852 const T9 v9_;
853 const T10 v10_;
854 const T11 v11_;
855 const T12 v12_;
856 const T13 v13_;
857 const T14 v14_;
858 const T15 v15_;
859 const T16 v16_;
860 const T17 v17_;
861 const T18 v18_;
862 const T19 v19_;
863 const T20 v20_;
864 const T21 v21_;
865 const T22 v22_;
866 };
867
868 template <typename T1, typename T2, typename T3, typename T4, typename T5,
869 typename T6, typename T7, typename T8, typename T9, typename T10,
870 typename T11, typename T12, typename T13, typename T14, typename T15,
871 typename T16, typename T17, typename T18, typename T19, typename T20,
872 typename T21, typename T22, typename T23>
873 class ValueArray23 {
874 public:
875 ValueArray23(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
876 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
877 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23) : v1_(v1), v2_(v2),
878 v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),
879 v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),
880 v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),
881 v23_(v23) {}
882
883 template <typename T>
884 operator ParamGenerator<T>() const {
885 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
886 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
887 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
888 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
889 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
890 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
891 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
892 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_)};
893 return ValuesIn(array);
894 }
895
896 private:
897 // No implementation - assignment is unsupported.
898 void operator=(const ValueArray23& other);
899
900 const T1 v1_;
901 const T2 v2_;
902 const T3 v3_;
903 const T4 v4_;
904 const T5 v5_;
905 const T6 v6_;
906 const T7 v7_;
907 const T8 v8_;
908 const T9 v9_;
909 const T10 v10_;
910 const T11 v11_;
911 const T12 v12_;
912 const T13 v13_;
913 const T14 v14_;
914 const T15 v15_;
915 const T16 v16_;
916 const T17 v17_;
917 const T18 v18_;
918 const T19 v19_;
919 const T20 v20_;
920 const T21 v21_;
921 const T22 v22_;
922 const T23 v23_;
923 };
924
925 template <typename T1, typename T2, typename T3, typename T4, typename T5,
926 typename T6, typename T7, typename T8, typename T9, typename T10,
927 typename T11, typename T12, typename T13, typename T14, typename T15,
928 typename T16, typename T17, typename T18, typename T19, typename T20,
929 typename T21, typename T22, typename T23, typename T24>
930 class ValueArray24 {
931 public:
932 ValueArray24(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
933 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
934 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24) : v1_(v1),
935 v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9),
936 v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15),
937 v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21),
938 v22_(v22), v23_(v23), v24_(v24) {}
939
940 template <typename T>
941 operator ParamGenerator<T>() const {
942 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
943 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
944 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
945 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
946 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
947 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
948 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
949 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
950 static_cast<T>(v24_)};
951 return ValuesIn(array);
952 }
953
954 private:
955 // No implementation - assignment is unsupported.
956 void operator=(const ValueArray24& other);
957
958 const T1 v1_;
959 const T2 v2_;
960 const T3 v3_;
961 const T4 v4_;
962 const T5 v5_;
963 const T6 v6_;
964 const T7 v7_;
965 const T8 v8_;
966 const T9 v9_;
967 const T10 v10_;
968 const T11 v11_;
969 const T12 v12_;
970 const T13 v13_;
971 const T14 v14_;
972 const T15 v15_;
973 const T16 v16_;
974 const T17 v17_;
975 const T18 v18_;
976 const T19 v19_;
977 const T20 v20_;
978 const T21 v21_;
979 const T22 v22_;
980 const T23 v23_;
981 const T24 v24_;
982 };
983
984 template <typename T1, typename T2, typename T3, typename T4, typename T5,
985 typename T6, typename T7, typename T8, typename T9, typename T10,
986 typename T11, typename T12, typename T13, typename T14, typename T15,
987 typename T16, typename T17, typename T18, typename T19, typename T20,
988 typename T21, typename T22, typename T23, typename T24, typename T25>
989 class ValueArray25 {
990 public:
991 ValueArray25(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
992 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
993 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24,
994 T25 v25) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
995 v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),
996 v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),
997 v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25) {}
998
999 template <typename T>
1000 operator ParamGenerator<T>() const {
1001 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1002 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1003 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1004 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1005 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1006 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1007 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1008 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1009 static_cast<T>(v24_), static_cast<T>(v25_)};
1010 return ValuesIn(array);
1011 }
1012
1013 private:
1014 // No implementation - assignment is unsupported.
1015 void operator=(const ValueArray25& other);
1016
1017 const T1 v1_;
1018 const T2 v2_;
1019 const T3 v3_;
1020 const T4 v4_;
1021 const T5 v5_;
1022 const T6 v6_;
1023 const T7 v7_;
1024 const T8 v8_;
1025 const T9 v9_;
1026 const T10 v10_;
1027 const T11 v11_;
1028 const T12 v12_;
1029 const T13 v13_;
1030 const T14 v14_;
1031 const T15 v15_;
1032 const T16 v16_;
1033 const T17 v17_;
1034 const T18 v18_;
1035 const T19 v19_;
1036 const T20 v20_;
1037 const T21 v21_;
1038 const T22 v22_;
1039 const T23 v23_;
1040 const T24 v24_;
1041 const T25 v25_;
1042 };
1043
1044 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1045 typename T6, typename T7, typename T8, typename T9, typename T10,
1046 typename T11, typename T12, typename T13, typename T14, typename T15,
1047 typename T16, typename T17, typename T18, typename T19, typename T20,
1048 typename T21, typename T22, typename T23, typename T24, typename T25,
1049 typename T26>
1050 class ValueArray26 {
1051 public:
1052 ValueArray26(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1053 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1054 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1055 T26 v26) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
1056 v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),
1057 v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),
1058 v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26) {}
1059
1060 template <typename T>
1061 operator ParamGenerator<T>() const {
1062 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1063 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1064 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1065 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1066 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1067 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1068 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1069 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1070 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_)};
1071 return ValuesIn(array);
1072 }
1073
1074 private:
1075 // No implementation - assignment is unsupported.
1076 void operator=(const ValueArray26& other);
1077
1078 const T1 v1_;
1079 const T2 v2_;
1080 const T3 v3_;
1081 const T4 v4_;
1082 const T5 v5_;
1083 const T6 v6_;
1084 const T7 v7_;
1085 const T8 v8_;
1086 const T9 v9_;
1087 const T10 v10_;
1088 const T11 v11_;
1089 const T12 v12_;
1090 const T13 v13_;
1091 const T14 v14_;
1092 const T15 v15_;
1093 const T16 v16_;
1094 const T17 v17_;
1095 const T18 v18_;
1096 const T19 v19_;
1097 const T20 v20_;
1098 const T21 v21_;
1099 const T22 v22_;
1100 const T23 v23_;
1101 const T24 v24_;
1102 const T25 v25_;
1103 const T26 v26_;
1104 };
1105
1106 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1107 typename T6, typename T7, typename T8, typename T9, typename T10,
1108 typename T11, typename T12, typename T13, typename T14, typename T15,
1109 typename T16, typename T17, typename T18, typename T19, typename T20,
1110 typename T21, typename T22, typename T23, typename T24, typename T25,
1111 typename T26, typename T27>
1112 class ValueArray27 {
1113 public:
1114 ValueArray27(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1115 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1116 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1117 T26 v26, T27 v27) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6),
1118 v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13),
1119 v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19),
1120 v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25),
1121 v26_(v26), v27_(v27) {}
1122
1123 template <typename T>
1124 operator ParamGenerator<T>() const {
1125 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1126 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1127 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1128 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1129 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1130 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1131 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1132 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1133 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1134 static_cast<T>(v27_)};
1135 return ValuesIn(array);
1136 }
1137
1138 private:
1139 // No implementation - assignment is unsupported.
1140 void operator=(const ValueArray27& other);
1141
1142 const T1 v1_;
1143 const T2 v2_;
1144 const T3 v3_;
1145 const T4 v4_;
1146 const T5 v5_;
1147 const T6 v6_;
1148 const T7 v7_;
1149 const T8 v8_;
1150 const T9 v9_;
1151 const T10 v10_;
1152 const T11 v11_;
1153 const T12 v12_;
1154 const T13 v13_;
1155 const T14 v14_;
1156 const T15 v15_;
1157 const T16 v16_;
1158 const T17 v17_;
1159 const T18 v18_;
1160 const T19 v19_;
1161 const T20 v20_;
1162 const T21 v21_;
1163 const T22 v22_;
1164 const T23 v23_;
1165 const T24 v24_;
1166 const T25 v25_;
1167 const T26 v26_;
1168 const T27 v27_;
1169 };
1170
1171 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1172 typename T6, typename T7, typename T8, typename T9, typename T10,
1173 typename T11, typename T12, typename T13, typename T14, typename T15,
1174 typename T16, typename T17, typename T18, typename T19, typename T20,
1175 typename T21, typename T22, typename T23, typename T24, typename T25,
1176 typename T26, typename T27, typename T28>
1177 class ValueArray28 {
1178 public:
1179 ValueArray28(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1180 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1181 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1182 T26 v26, T27 v27, T28 v28) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5),
1183 v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12),
1184 v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18),
1185 v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24),
1186 v25_(v25), v26_(v26), v27_(v27), v28_(v28) {}
1187
1188 template <typename T>
1189 operator ParamGenerator<T>() const {
1190 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1191 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1192 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1193 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1194 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1195 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1196 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1197 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1198 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1199 static_cast<T>(v27_), static_cast<T>(v28_)};
1200 return ValuesIn(array);
1201 }
1202
1203 private:
1204 // No implementation - assignment is unsupported.
1205 void operator=(const ValueArray28& other);
1206
1207 const T1 v1_;
1208 const T2 v2_;
1209 const T3 v3_;
1210 const T4 v4_;
1211 const T5 v5_;
1212 const T6 v6_;
1213 const T7 v7_;
1214 const T8 v8_;
1215 const T9 v9_;
1216 const T10 v10_;
1217 const T11 v11_;
1218 const T12 v12_;
1219 const T13 v13_;
1220 const T14 v14_;
1221 const T15 v15_;
1222 const T16 v16_;
1223 const T17 v17_;
1224 const T18 v18_;
1225 const T19 v19_;
1226 const T20 v20_;
1227 const T21 v21_;
1228 const T22 v22_;
1229 const T23 v23_;
1230 const T24 v24_;
1231 const T25 v25_;
1232 const T26 v26_;
1233 const T27 v27_;
1234 const T28 v28_;
1235 };
1236
1237 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1238 typename T6, typename T7, typename T8, typename T9, typename T10,
1239 typename T11, typename T12, typename T13, typename T14, typename T15,
1240 typename T16, typename T17, typename T18, typename T19, typename T20,
1241 typename T21, typename T22, typename T23, typename T24, typename T25,
1242 typename T26, typename T27, typename T28, typename T29>
1243 class ValueArray29 {
1244 public:
1245 ValueArray29(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1246 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1247 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1248 T26 v26, T27 v27, T28 v28, T29 v29) : v1_(v1), v2_(v2), v3_(v3), v4_(v4),
1249 v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11),
1250 v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17),
1251 v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23),
1252 v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29) {}
1253
1254 template <typename T>
1255 operator ParamGenerator<T>() const {
1256 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1257 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1258 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1259 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1260 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1261 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1262 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1263 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1264 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1265 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_)};
1266 return ValuesIn(array);
1267 }
1268
1269 private:
1270 // No implementation - assignment is unsupported.
1271 void operator=(const ValueArray29& other);
1272
1273 const T1 v1_;
1274 const T2 v2_;
1275 const T3 v3_;
1276 const T4 v4_;
1277 const T5 v5_;
1278 const T6 v6_;
1279 const T7 v7_;
1280 const T8 v8_;
1281 const T9 v9_;
1282 const T10 v10_;
1283 const T11 v11_;
1284 const T12 v12_;
1285 const T13 v13_;
1286 const T14 v14_;
1287 const T15 v15_;
1288 const T16 v16_;
1289 const T17 v17_;
1290 const T18 v18_;
1291 const T19 v19_;
1292 const T20 v20_;
1293 const T21 v21_;
1294 const T22 v22_;
1295 const T23 v23_;
1296 const T24 v24_;
1297 const T25 v25_;
1298 const T26 v26_;
1299 const T27 v27_;
1300 const T28 v28_;
1301 const T29 v29_;
1302 };
1303
1304 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1305 typename T6, typename T7, typename T8, typename T9, typename T10,
1306 typename T11, typename T12, typename T13, typename T14, typename T15,
1307 typename T16, typename T17, typename T18, typename T19, typename T20,
1308 typename T21, typename T22, typename T23, typename T24, typename T25,
1309 typename T26, typename T27, typename T28, typename T29, typename T30>
1310 class ValueArray30 {
1311 public:
1312 ValueArray30(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1313 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1314 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1315 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30) : v1_(v1), v2_(v2), v3_(v3),
1316 v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),
1317 v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),
1318 v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),
1319 v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),
1320 v29_(v29), v30_(v30) {}
1321
1322 template <typename T>
1323 operator ParamGenerator<T>() const {
1324 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1325 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1326 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1327 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1328 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1329 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1330 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1331 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1332 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1333 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
1334 static_cast<T>(v30_)};
1335 return ValuesIn(array);
1336 }
1337
1338 private:
1339 // No implementation - assignment is unsupported.
1340 void operator=(const ValueArray30& other);
1341
1342 const T1 v1_;
1343 const T2 v2_;
1344 const T3 v3_;
1345 const T4 v4_;
1346 const T5 v5_;
1347 const T6 v6_;
1348 const T7 v7_;
1349 const T8 v8_;
1350 const T9 v9_;
1351 const T10 v10_;
1352 const T11 v11_;
1353 const T12 v12_;
1354 const T13 v13_;
1355 const T14 v14_;
1356 const T15 v15_;
1357 const T16 v16_;
1358 const T17 v17_;
1359 const T18 v18_;
1360 const T19 v19_;
1361 const T20 v20_;
1362 const T21 v21_;
1363 const T22 v22_;
1364 const T23 v23_;
1365 const T24 v24_;
1366 const T25 v25_;
1367 const T26 v26_;
1368 const T27 v27_;
1369 const T28 v28_;
1370 const T29 v29_;
1371 const T30 v30_;
1372 };
1373
1374 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1375 typename T6, typename T7, typename T8, typename T9, typename T10,
1376 typename T11, typename T12, typename T13, typename T14, typename T15,
1377 typename T16, typename T17, typename T18, typename T19, typename T20,
1378 typename T21, typename T22, typename T23, typename T24, typename T25,
1379 typename T26, typename T27, typename T28, typename T29, typename T30,
1380 typename T31>
1381 class ValueArray31 {
1382 public:
1383 ValueArray31(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1384 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1385 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1386 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31) : v1_(v1), v2_(v2),
1387 v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),
1388 v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),
1389 v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),
1390 v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),
1391 v29_(v29), v30_(v30), v31_(v31) {}
1392
1393 template <typename T>
1394 operator ParamGenerator<T>() const {
1395 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1396 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1397 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1398 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1399 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1400 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1401 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1402 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1403 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1404 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
1405 static_cast<T>(v30_), static_cast<T>(v31_)};
1406 return ValuesIn(array);
1407 }
1408
1409 private:
1410 // No implementation - assignment is unsupported.
1411 void operator=(const ValueArray31& other);
1412
1413 const T1 v1_;
1414 const T2 v2_;
1415 const T3 v3_;
1416 const T4 v4_;
1417 const T5 v5_;
1418 const T6 v6_;
1419 const T7 v7_;
1420 const T8 v8_;
1421 const T9 v9_;
1422 const T10 v10_;
1423 const T11 v11_;
1424 const T12 v12_;
1425 const T13 v13_;
1426 const T14 v14_;
1427 const T15 v15_;
1428 const T16 v16_;
1429 const T17 v17_;
1430 const T18 v18_;
1431 const T19 v19_;
1432 const T20 v20_;
1433 const T21 v21_;
1434 const T22 v22_;
1435 const T23 v23_;
1436 const T24 v24_;
1437 const T25 v25_;
1438 const T26 v26_;
1439 const T27 v27_;
1440 const T28 v28_;
1441 const T29 v29_;
1442 const T30 v30_;
1443 const T31 v31_;
1444 };
1445
1446 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1447 typename T6, typename T7, typename T8, typename T9, typename T10,
1448 typename T11, typename T12, typename T13, typename T14, typename T15,
1449 typename T16, typename T17, typename T18, typename T19, typename T20,
1450 typename T21, typename T22, typename T23, typename T24, typename T25,
1451 typename T26, typename T27, typename T28, typename T29, typename T30,
1452 typename T31, typename T32>
1453 class ValueArray32 {
1454 public:
1455 ValueArray32(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1456 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1457 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1458 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32) : v1_(v1),
1459 v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9),
1460 v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15),
1461 v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21),
1462 v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27),
1463 v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32) {}
1464
1465 template <typename T>
1466 operator ParamGenerator<T>() const {
1467 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1468 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1469 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1470 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1471 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1472 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1473 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1474 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1475 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1476 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
1477 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_)};
1478 return ValuesIn(array);
1479 }
1480
1481 private:
1482 // No implementation - assignment is unsupported.
1483 void operator=(const ValueArray32& other);
1484
1485 const T1 v1_;
1486 const T2 v2_;
1487 const T3 v3_;
1488 const T4 v4_;
1489 const T5 v5_;
1490 const T6 v6_;
1491 const T7 v7_;
1492 const T8 v8_;
1493 const T9 v9_;
1494 const T10 v10_;
1495 const T11 v11_;
1496 const T12 v12_;
1497 const T13 v13_;
1498 const T14 v14_;
1499 const T15 v15_;
1500 const T16 v16_;
1501 const T17 v17_;
1502 const T18 v18_;
1503 const T19 v19_;
1504 const T20 v20_;
1505 const T21 v21_;
1506 const T22 v22_;
1507 const T23 v23_;
1508 const T24 v24_;
1509 const T25 v25_;
1510 const T26 v26_;
1511 const T27 v27_;
1512 const T28 v28_;
1513 const T29 v29_;
1514 const T30 v30_;
1515 const T31 v31_;
1516 const T32 v32_;
1517 };
1518
1519 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1520 typename T6, typename T7, typename T8, typename T9, typename T10,
1521 typename T11, typename T12, typename T13, typename T14, typename T15,
1522 typename T16, typename T17, typename T18, typename T19, typename T20,
1523 typename T21, typename T22, typename T23, typename T24, typename T25,
1524 typename T26, typename T27, typename T28, typename T29, typename T30,
1525 typename T31, typename T32, typename T33>
1526 class ValueArray33 {
1527 public:
1528 ValueArray33(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1529 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1530 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1531 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32,
1532 T33 v33) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
1533 v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),
1534 v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),
1535 v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),
1536 v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),
1537 v33_(v33) {}
1538
1539 template <typename T>
1540 operator ParamGenerator<T>() const {
1541 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1542 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1543 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1544 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1545 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1546 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1547 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1548 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1549 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1550 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
1551 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
1552 static_cast<T>(v33_)};
1553 return ValuesIn(array);
1554 }
1555
1556 private:
1557 // No implementation - assignment is unsupported.
1558 void operator=(const ValueArray33& other);
1559
1560 const T1 v1_;
1561 const T2 v2_;
1562 const T3 v3_;
1563 const T4 v4_;
1564 const T5 v5_;
1565 const T6 v6_;
1566 const T7 v7_;
1567 const T8 v8_;
1568 const T9 v9_;
1569 const T10 v10_;
1570 const T11 v11_;
1571 const T12 v12_;
1572 const T13 v13_;
1573 const T14 v14_;
1574 const T15 v15_;
1575 const T16 v16_;
1576 const T17 v17_;
1577 const T18 v18_;
1578 const T19 v19_;
1579 const T20 v20_;
1580 const T21 v21_;
1581 const T22 v22_;
1582 const T23 v23_;
1583 const T24 v24_;
1584 const T25 v25_;
1585 const T26 v26_;
1586 const T27 v27_;
1587 const T28 v28_;
1588 const T29 v29_;
1589 const T30 v30_;
1590 const T31 v31_;
1591 const T32 v32_;
1592 const T33 v33_;
1593 };
1594
1595 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1596 typename T6, typename T7, typename T8, typename T9, typename T10,
1597 typename T11, typename T12, typename T13, typename T14, typename T15,
1598 typename T16, typename T17, typename T18, typename T19, typename T20,
1599 typename T21, typename T22, typename T23, typename T24, typename T25,
1600 typename T26, typename T27, typename T28, typename T29, typename T30,
1601 typename T31, typename T32, typename T33, typename T34>
1602 class ValueArray34 {
1603 public:
1604 ValueArray34(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1605 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1606 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1607 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
1608 T34 v34) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
1609 v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),
1610 v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),
1611 v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),
1612 v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),
1613 v33_(v33), v34_(v34) {}
1614
1615 template <typename T>
1616 operator ParamGenerator<T>() const {
1617 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1618 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1619 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1620 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1621 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1622 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1623 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1624 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1625 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1626 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
1627 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
1628 static_cast<T>(v33_), static_cast<T>(v34_)};
1629 return ValuesIn(array);
1630 }
1631
1632 private:
1633 // No implementation - assignment is unsupported.
1634 void operator=(const ValueArray34& other);
1635
1636 const T1 v1_;
1637 const T2 v2_;
1638 const T3 v3_;
1639 const T4 v4_;
1640 const T5 v5_;
1641 const T6 v6_;
1642 const T7 v7_;
1643 const T8 v8_;
1644 const T9 v9_;
1645 const T10 v10_;
1646 const T11 v11_;
1647 const T12 v12_;
1648 const T13 v13_;
1649 const T14 v14_;
1650 const T15 v15_;
1651 const T16 v16_;
1652 const T17 v17_;
1653 const T18 v18_;
1654 const T19 v19_;
1655 const T20 v20_;
1656 const T21 v21_;
1657 const T22 v22_;
1658 const T23 v23_;
1659 const T24 v24_;
1660 const T25 v25_;
1661 const T26 v26_;
1662 const T27 v27_;
1663 const T28 v28_;
1664 const T29 v29_;
1665 const T30 v30_;
1666 const T31 v31_;
1667 const T32 v32_;
1668 const T33 v33_;
1669 const T34 v34_;
1670 };
1671
1672 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1673 typename T6, typename T7, typename T8, typename T9, typename T10,
1674 typename T11, typename T12, typename T13, typename T14, typename T15,
1675 typename T16, typename T17, typename T18, typename T19, typename T20,
1676 typename T21, typename T22, typename T23, typename T24, typename T25,
1677 typename T26, typename T27, typename T28, typename T29, typename T30,
1678 typename T31, typename T32, typename T33, typename T34, typename T35>
1679 class ValueArray35 {
1680 public:
1681 ValueArray35(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1682 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1683 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1684 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
1685 T34 v34, T35 v35) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6),
1686 v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13),
1687 v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19),
1688 v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25),
1689 v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31),
1690 v32_(v32), v33_(v33), v34_(v34), v35_(v35) {}
1691
1692 template <typename T>
1693 operator ParamGenerator<T>() const {
1694 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1695 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1696 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1697 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1698 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1699 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1700 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1701 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1702 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1703 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
1704 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
1705 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_)};
1706 return ValuesIn(array);
1707 }
1708
1709 private:
1710 // No implementation - assignment is unsupported.
1711 void operator=(const ValueArray35& other);
1712
1713 const T1 v1_;
1714 const T2 v2_;
1715 const T3 v3_;
1716 const T4 v4_;
1717 const T5 v5_;
1718 const T6 v6_;
1719 const T7 v7_;
1720 const T8 v8_;
1721 const T9 v9_;
1722 const T10 v10_;
1723 const T11 v11_;
1724 const T12 v12_;
1725 const T13 v13_;
1726 const T14 v14_;
1727 const T15 v15_;
1728 const T16 v16_;
1729 const T17 v17_;
1730 const T18 v18_;
1731 const T19 v19_;
1732 const T20 v20_;
1733 const T21 v21_;
1734 const T22 v22_;
1735 const T23 v23_;
1736 const T24 v24_;
1737 const T25 v25_;
1738 const T26 v26_;
1739 const T27 v27_;
1740 const T28 v28_;
1741 const T29 v29_;
1742 const T30 v30_;
1743 const T31 v31_;
1744 const T32 v32_;
1745 const T33 v33_;
1746 const T34 v34_;
1747 const T35 v35_;
1748 };
1749
1750 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1751 typename T6, typename T7, typename T8, typename T9, typename T10,
1752 typename T11, typename T12, typename T13, typename T14, typename T15,
1753 typename T16, typename T17, typename T18, typename T19, typename T20,
1754 typename T21, typename T22, typename T23, typename T24, typename T25,
1755 typename T26, typename T27, typename T28, typename T29, typename T30,
1756 typename T31, typename T32, typename T33, typename T34, typename T35,
1757 typename T36>
1758 class ValueArray36 {
1759 public:
1760 ValueArray36(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1761 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1762 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1763 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
1764 T34 v34, T35 v35, T36 v36) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5),
1765 v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12),
1766 v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18),
1767 v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24),
1768 v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30),
1769 v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35), v36_(v36) {}
1770
1771 template <typename T>
1772 operator ParamGenerator<T>() const {
1773 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1774 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1775 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1776 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1777 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1778 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1779 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1780 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1781 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1782 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
1783 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
1784 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
1785 static_cast<T>(v36_)};
1786 return ValuesIn(array);
1787 }
1788
1789 private:
1790 // No implementation - assignment is unsupported.
1791 void operator=(const ValueArray36& other);
1792
1793 const T1 v1_;
1794 const T2 v2_;
1795 const T3 v3_;
1796 const T4 v4_;
1797 const T5 v5_;
1798 const T6 v6_;
1799 const T7 v7_;
1800 const T8 v8_;
1801 const T9 v9_;
1802 const T10 v10_;
1803 const T11 v11_;
1804 const T12 v12_;
1805 const T13 v13_;
1806 const T14 v14_;
1807 const T15 v15_;
1808 const T16 v16_;
1809 const T17 v17_;
1810 const T18 v18_;
1811 const T19 v19_;
1812 const T20 v20_;
1813 const T21 v21_;
1814 const T22 v22_;
1815 const T23 v23_;
1816 const T24 v24_;
1817 const T25 v25_;
1818 const T26 v26_;
1819 const T27 v27_;
1820 const T28 v28_;
1821 const T29 v29_;
1822 const T30 v30_;
1823 const T31 v31_;
1824 const T32 v32_;
1825 const T33 v33_;
1826 const T34 v34_;
1827 const T35 v35_;
1828 const T36 v36_;
1829 };
1830
1831 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1832 typename T6, typename T7, typename T8, typename T9, typename T10,
1833 typename T11, typename T12, typename T13, typename T14, typename T15,
1834 typename T16, typename T17, typename T18, typename T19, typename T20,
1835 typename T21, typename T22, typename T23, typename T24, typename T25,
1836 typename T26, typename T27, typename T28, typename T29, typename T30,
1837 typename T31, typename T32, typename T33, typename T34, typename T35,
1838 typename T36, typename T37>
1839 class ValueArray37 {
1840 public:
1841 ValueArray37(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1842 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1843 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1844 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
1845 T34 v34, T35 v35, T36 v36, T37 v37) : v1_(v1), v2_(v2), v3_(v3), v4_(v4),
1846 v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11),
1847 v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17),
1848 v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23),
1849 v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29),
1850 v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35),
1851 v36_(v36), v37_(v37) {}
1852
1853 template <typename T>
1854 operator ParamGenerator<T>() const {
1855 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1856 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1857 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1858 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1859 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1860 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1861 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1862 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1863 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1864 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
1865 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
1866 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
1867 static_cast<T>(v36_), static_cast<T>(v37_)};
1868 return ValuesIn(array);
1869 }
1870
1871 private:
1872 // No implementation - assignment is unsupported.
1873 void operator=(const ValueArray37& other);
1874
1875 const T1 v1_;
1876 const T2 v2_;
1877 const T3 v3_;
1878 const T4 v4_;
1879 const T5 v5_;
1880 const T6 v6_;
1881 const T7 v7_;
1882 const T8 v8_;
1883 const T9 v9_;
1884 const T10 v10_;
1885 const T11 v11_;
1886 const T12 v12_;
1887 const T13 v13_;
1888 const T14 v14_;
1889 const T15 v15_;
1890 const T16 v16_;
1891 const T17 v17_;
1892 const T18 v18_;
1893 const T19 v19_;
1894 const T20 v20_;
1895 const T21 v21_;
1896 const T22 v22_;
1897 const T23 v23_;
1898 const T24 v24_;
1899 const T25 v25_;
1900 const T26 v26_;
1901 const T27 v27_;
1902 const T28 v28_;
1903 const T29 v29_;
1904 const T30 v30_;
1905 const T31 v31_;
1906 const T32 v32_;
1907 const T33 v33_;
1908 const T34 v34_;
1909 const T35 v35_;
1910 const T36 v36_;
1911 const T37 v37_;
1912 };
1913
1914 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1915 typename T6, typename T7, typename T8, typename T9, typename T10,
1916 typename T11, typename T12, typename T13, typename T14, typename T15,
1917 typename T16, typename T17, typename T18, typename T19, typename T20,
1918 typename T21, typename T22, typename T23, typename T24, typename T25,
1919 typename T26, typename T27, typename T28, typename T29, typename T30,
1920 typename T31, typename T32, typename T33, typename T34, typename T35,
1921 typename T36, typename T37, typename T38>
1922 class ValueArray38 {
1923 public:
1924 ValueArray38(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
1925 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
1926 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
1927 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
1928 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38) : v1_(v1), v2_(v2), v3_(v3),
1929 v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),
1930 v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),
1931 v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),
1932 v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),
1933 v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34),
1934 v35_(v35), v36_(v36), v37_(v37), v38_(v38) {}
1935
1936 template <typename T>
1937 operator ParamGenerator<T>() const {
1938 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
1939 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
1940 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
1941 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
1942 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
1943 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
1944 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
1945 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
1946 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
1947 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
1948 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
1949 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
1950 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_)};
1951 return ValuesIn(array);
1952 }
1953
1954 private:
1955 // No implementation - assignment is unsupported.
1956 void operator=(const ValueArray38& other);
1957
1958 const T1 v1_;
1959 const T2 v2_;
1960 const T3 v3_;
1961 const T4 v4_;
1962 const T5 v5_;
1963 const T6 v6_;
1964 const T7 v7_;
1965 const T8 v8_;
1966 const T9 v9_;
1967 const T10 v10_;
1968 const T11 v11_;
1969 const T12 v12_;
1970 const T13 v13_;
1971 const T14 v14_;
1972 const T15 v15_;
1973 const T16 v16_;
1974 const T17 v17_;
1975 const T18 v18_;
1976 const T19 v19_;
1977 const T20 v20_;
1978 const T21 v21_;
1979 const T22 v22_;
1980 const T23 v23_;
1981 const T24 v24_;
1982 const T25 v25_;
1983 const T26 v26_;
1984 const T27 v27_;
1985 const T28 v28_;
1986 const T29 v29_;
1987 const T30 v30_;
1988 const T31 v31_;
1989 const T32 v32_;
1990 const T33 v33_;
1991 const T34 v34_;
1992 const T35 v35_;
1993 const T36 v36_;
1994 const T37 v37_;
1995 const T38 v38_;
1996 };
1997
1998 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1999 typename T6, typename T7, typename T8, typename T9, typename T10,
2000 typename T11, typename T12, typename T13, typename T14, typename T15,
2001 typename T16, typename T17, typename T18, typename T19, typename T20,
2002 typename T21, typename T22, typename T23, typename T24, typename T25,
2003 typename T26, typename T27, typename T28, typename T29, typename T30,
2004 typename T31, typename T32, typename T33, typename T34, typename T35,
2005 typename T36, typename T37, typename T38, typename T39>
2006 class ValueArray39 {
2007 public:
2008 ValueArray39(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2009 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2010 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2011 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2012 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39) : v1_(v1), v2_(v2),
2013 v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),
2014 v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),
2015 v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),
2016 v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),
2017 v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34),
2018 v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39) {}
2019
2020 template <typename T>
2021 operator ParamGenerator<T>() const {
2022 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2023 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2024 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2025 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2026 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2027 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2028 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2029 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2030 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2031 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2032 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2033 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2034 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2035 static_cast<T>(v39_)};
2036 return ValuesIn(array);
2037 }
2038
2039 private:
2040 // No implementation - assignment is unsupported.
2041 void operator=(const ValueArray39& other);
2042
2043 const T1 v1_;
2044 const T2 v2_;
2045 const T3 v3_;
2046 const T4 v4_;
2047 const T5 v5_;
2048 const T6 v6_;
2049 const T7 v7_;
2050 const T8 v8_;
2051 const T9 v9_;
2052 const T10 v10_;
2053 const T11 v11_;
2054 const T12 v12_;
2055 const T13 v13_;
2056 const T14 v14_;
2057 const T15 v15_;
2058 const T16 v16_;
2059 const T17 v17_;
2060 const T18 v18_;
2061 const T19 v19_;
2062 const T20 v20_;
2063 const T21 v21_;
2064 const T22 v22_;
2065 const T23 v23_;
2066 const T24 v24_;
2067 const T25 v25_;
2068 const T26 v26_;
2069 const T27 v27_;
2070 const T28 v28_;
2071 const T29 v29_;
2072 const T30 v30_;
2073 const T31 v31_;
2074 const T32 v32_;
2075 const T33 v33_;
2076 const T34 v34_;
2077 const T35 v35_;
2078 const T36 v36_;
2079 const T37 v37_;
2080 const T38 v38_;
2081 const T39 v39_;
2082 };
2083
2084 template <typename T1, typename T2, typename T3, typename T4, typename T5,
2085 typename T6, typename T7, typename T8, typename T9, typename T10,
2086 typename T11, typename T12, typename T13, typename T14, typename T15,
2087 typename T16, typename T17, typename T18, typename T19, typename T20,
2088 typename T21, typename T22, typename T23, typename T24, typename T25,
2089 typename T26, typename T27, typename T28, typename T29, typename T30,
2090 typename T31, typename T32, typename T33, typename T34, typename T35,
2091 typename T36, typename T37, typename T38, typename T39, typename T40>
2092 class ValueArray40 {
2093 public:
2094 ValueArray40(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2095 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2096 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2097 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2098 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40) : v1_(v1),
2099 v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9),
2100 v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15),
2101 v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21),
2102 v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27),
2103 v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33),
2104 v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39),
2105 v40_(v40) {}
2106
2107 template <typename T>
2108 operator ParamGenerator<T>() const {
2109 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2110 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2111 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2112 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2113 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2114 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2115 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2116 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2117 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2118 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2119 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2120 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2121 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2122 static_cast<T>(v39_), static_cast<T>(v40_)};
2123 return ValuesIn(array);
2124 }
2125
2126 private:
2127 // No implementation - assignment is unsupported.
2128 void operator=(const ValueArray40& other);
2129
2130 const T1 v1_;
2131 const T2 v2_;
2132 const T3 v3_;
2133 const T4 v4_;
2134 const T5 v5_;
2135 const T6 v6_;
2136 const T7 v7_;
2137 const T8 v8_;
2138 const T9 v9_;
2139 const T10 v10_;
2140 const T11 v11_;
2141 const T12 v12_;
2142 const T13 v13_;
2143 const T14 v14_;
2144 const T15 v15_;
2145 const T16 v16_;
2146 const T17 v17_;
2147 const T18 v18_;
2148 const T19 v19_;
2149 const T20 v20_;
2150 const T21 v21_;
2151 const T22 v22_;
2152 const T23 v23_;
2153 const T24 v24_;
2154 const T25 v25_;
2155 const T26 v26_;
2156 const T27 v27_;
2157 const T28 v28_;
2158 const T29 v29_;
2159 const T30 v30_;
2160 const T31 v31_;
2161 const T32 v32_;
2162 const T33 v33_;
2163 const T34 v34_;
2164 const T35 v35_;
2165 const T36 v36_;
2166 const T37 v37_;
2167 const T38 v38_;
2168 const T39 v39_;
2169 const T40 v40_;
2170 };
2171
2172 template <typename T1, typename T2, typename T3, typename T4, typename T5,
2173 typename T6, typename T7, typename T8, typename T9, typename T10,
2174 typename T11, typename T12, typename T13, typename T14, typename T15,
2175 typename T16, typename T17, typename T18, typename T19, typename T20,
2176 typename T21, typename T22, typename T23, typename T24, typename T25,
2177 typename T26, typename T27, typename T28, typename T29, typename T30,
2178 typename T31, typename T32, typename T33, typename T34, typename T35,
2179 typename T36, typename T37, typename T38, typename T39, typename T40,
2180 typename T41>
2181 class ValueArray41 {
2182 public:
2183 ValueArray41(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2184 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2185 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2186 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2187 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40,
2188 T41 v41) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
2189 v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),
2190 v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),
2191 v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),
2192 v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),
2193 v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38),
2194 v39_(v39), v40_(v40), v41_(v41) {}
2195
2196 template <typename T>
2197 operator ParamGenerator<T>() const {
2198 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2199 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2200 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2201 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2202 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2203 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2204 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2205 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2206 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2207 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2208 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2209 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2210 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2211 static_cast<T>(v39_), static_cast<T>(v40_), static_cast<T>(v41_)};
2212 return ValuesIn(array);
2213 }
2214
2215 private:
2216 // No implementation - assignment is unsupported.
2217 void operator=(const ValueArray41& other);
2218
2219 const T1 v1_;
2220 const T2 v2_;
2221 const T3 v3_;
2222 const T4 v4_;
2223 const T5 v5_;
2224 const T6 v6_;
2225 const T7 v7_;
2226 const T8 v8_;
2227 const T9 v9_;
2228 const T10 v10_;
2229 const T11 v11_;
2230 const T12 v12_;
2231 const T13 v13_;
2232 const T14 v14_;
2233 const T15 v15_;
2234 const T16 v16_;
2235 const T17 v17_;
2236 const T18 v18_;
2237 const T19 v19_;
2238 const T20 v20_;
2239 const T21 v21_;
2240 const T22 v22_;
2241 const T23 v23_;
2242 const T24 v24_;
2243 const T25 v25_;
2244 const T26 v26_;
2245 const T27 v27_;
2246 const T28 v28_;
2247 const T29 v29_;
2248 const T30 v30_;
2249 const T31 v31_;
2250 const T32 v32_;
2251 const T33 v33_;
2252 const T34 v34_;
2253 const T35 v35_;
2254 const T36 v36_;
2255 const T37 v37_;
2256 const T38 v38_;
2257 const T39 v39_;
2258 const T40 v40_;
2259 const T41 v41_;
2260 };
2261
2262 template <typename T1, typename T2, typename T3, typename T4, typename T5,
2263 typename T6, typename T7, typename T8, typename T9, typename T10,
2264 typename T11, typename T12, typename T13, typename T14, typename T15,
2265 typename T16, typename T17, typename T18, typename T19, typename T20,
2266 typename T21, typename T22, typename T23, typename T24, typename T25,
2267 typename T26, typename T27, typename T28, typename T29, typename T30,
2268 typename T31, typename T32, typename T33, typename T34, typename T35,
2269 typename T36, typename T37, typename T38, typename T39, typename T40,
2270 typename T41, typename T42>
2271 class ValueArray42 {
2272 public:
2273 ValueArray42(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2274 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2275 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2276 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2277 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
2278 T42 v42) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
2279 v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),
2280 v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),
2281 v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),
2282 v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),
2283 v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38),
2284 v39_(v39), v40_(v40), v41_(v41), v42_(v42) {}
2285
2286 template <typename T>
2287 operator ParamGenerator<T>() const {
2288 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2289 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2290 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2291 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2292 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2293 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2294 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2295 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2296 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2297 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2298 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2299 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2300 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2301 static_cast<T>(v39_), static_cast<T>(v40_), static_cast<T>(v41_),
2302 static_cast<T>(v42_)};
2303 return ValuesIn(array);
2304 }
2305
2306 private:
2307 // No implementation - assignment is unsupported.
2308 void operator=(const ValueArray42& other);
2309
2310 const T1 v1_;
2311 const T2 v2_;
2312 const T3 v3_;
2313 const T4 v4_;
2314 const T5 v5_;
2315 const T6 v6_;
2316 const T7 v7_;
2317 const T8 v8_;
2318 const T9 v9_;
2319 const T10 v10_;
2320 const T11 v11_;
2321 const T12 v12_;
2322 const T13 v13_;
2323 const T14 v14_;
2324 const T15 v15_;
2325 const T16 v16_;
2326 const T17 v17_;
2327 const T18 v18_;
2328 const T19 v19_;
2329 const T20 v20_;
2330 const T21 v21_;
2331 const T22 v22_;
2332 const T23 v23_;
2333 const T24 v24_;
2334 const T25 v25_;
2335 const T26 v26_;
2336 const T27 v27_;
2337 const T28 v28_;
2338 const T29 v29_;
2339 const T30 v30_;
2340 const T31 v31_;
2341 const T32 v32_;
2342 const T33 v33_;
2343 const T34 v34_;
2344 const T35 v35_;
2345 const T36 v36_;
2346 const T37 v37_;
2347 const T38 v38_;
2348 const T39 v39_;
2349 const T40 v40_;
2350 const T41 v41_;
2351 const T42 v42_;
2352 };
2353
2354 template <typename T1, typename T2, typename T3, typename T4, typename T5,
2355 typename T6, typename T7, typename T8, typename T9, typename T10,
2356 typename T11, typename T12, typename T13, typename T14, typename T15,
2357 typename T16, typename T17, typename T18, typename T19, typename T20,
2358 typename T21, typename T22, typename T23, typename T24, typename T25,
2359 typename T26, typename T27, typename T28, typename T29, typename T30,
2360 typename T31, typename T32, typename T33, typename T34, typename T35,
2361 typename T36, typename T37, typename T38, typename T39, typename T40,
2362 typename T41, typename T42, typename T43>
2363 class ValueArray43 {
2364 public:
2365 ValueArray43(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2366 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2367 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2368 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2369 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
2370 T42 v42, T43 v43) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6),
2371 v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13),
2372 v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19),
2373 v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25),
2374 v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31),
2375 v32_(v32), v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37),
2376 v38_(v38), v39_(v39), v40_(v40), v41_(v41), v42_(v42), v43_(v43) {}
2377
2378 template <typename T>
2379 operator ParamGenerator<T>() const {
2380 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2381 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2382 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2383 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2384 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2385 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2386 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2387 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2388 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2389 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2390 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2391 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2392 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2393 static_cast<T>(v39_), static_cast<T>(v40_), static_cast<T>(v41_),
2394 static_cast<T>(v42_), static_cast<T>(v43_)};
2395 return ValuesIn(array);
2396 }
2397
2398 private:
2399 // No implementation - assignment is unsupported.
2400 void operator=(const ValueArray43& other);
2401
2402 const T1 v1_;
2403 const T2 v2_;
2404 const T3 v3_;
2405 const T4 v4_;
2406 const T5 v5_;
2407 const T6 v6_;
2408 const T7 v7_;
2409 const T8 v8_;
2410 const T9 v9_;
2411 const T10 v10_;
2412 const T11 v11_;
2413 const T12 v12_;
2414 const T13 v13_;
2415 const T14 v14_;
2416 const T15 v15_;
2417 const T16 v16_;
2418 const T17 v17_;
2419 const T18 v18_;
2420 const T19 v19_;
2421 const T20 v20_;
2422 const T21 v21_;
2423 const T22 v22_;
2424 const T23 v23_;
2425 const T24 v24_;
2426 const T25 v25_;
2427 const T26 v26_;
2428 const T27 v27_;
2429 const T28 v28_;
2430 const T29 v29_;
2431 const T30 v30_;
2432 const T31 v31_;
2433 const T32 v32_;
2434 const T33 v33_;
2435 const T34 v34_;
2436 const T35 v35_;
2437 const T36 v36_;
2438 const T37 v37_;
2439 const T38 v38_;
2440 const T39 v39_;
2441 const T40 v40_;
2442 const T41 v41_;
2443 const T42 v42_;
2444 const T43 v43_;
2445 };
2446
2447 template <typename T1, typename T2, typename T3, typename T4, typename T5,
2448 typename T6, typename T7, typename T8, typename T9, typename T10,
2449 typename T11, typename T12, typename T13, typename T14, typename T15,
2450 typename T16, typename T17, typename T18, typename T19, typename T20,
2451 typename T21, typename T22, typename T23, typename T24, typename T25,
2452 typename T26, typename T27, typename T28, typename T29, typename T30,
2453 typename T31, typename T32, typename T33, typename T34, typename T35,
2454 typename T36, typename T37, typename T38, typename T39, typename T40,
2455 typename T41, typename T42, typename T43, typename T44>
2456 class ValueArray44 {
2457 public:
2458 ValueArray44(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2459 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2460 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2461 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2462 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
2463 T42 v42, T43 v43, T44 v44) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5),
2464 v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12),
2465 v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17), v18_(v18),
2466 v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23), v24_(v24),
2467 v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29), v30_(v30),
2468 v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35), v36_(v36),
2469 v37_(v37), v38_(v38), v39_(v39), v40_(v40), v41_(v41), v42_(v42),
2470 v43_(v43), v44_(v44) {}
2471
2472 template <typename T>
2473 operator ParamGenerator<T>() const {
2474 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2475 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2476 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2477 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2478 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2479 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2480 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2481 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2482 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2483 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2484 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2485 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2486 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2487 static_cast<T>(v39_), static_cast<T>(v40_), static_cast<T>(v41_),
2488 static_cast<T>(v42_), static_cast<T>(v43_), static_cast<T>(v44_)};
2489 return ValuesIn(array);
2490 }
2491
2492 private:
2493 // No implementation - assignment is unsupported.
2494 void operator=(const ValueArray44& other);
2495
2496 const T1 v1_;
2497 const T2 v2_;
2498 const T3 v3_;
2499 const T4 v4_;
2500 const T5 v5_;
2501 const T6 v6_;
2502 const T7 v7_;
2503 const T8 v8_;
2504 const T9 v9_;
2505 const T10 v10_;
2506 const T11 v11_;
2507 const T12 v12_;
2508 const T13 v13_;
2509 const T14 v14_;
2510 const T15 v15_;
2511 const T16 v16_;
2512 const T17 v17_;
2513 const T18 v18_;
2514 const T19 v19_;
2515 const T20 v20_;
2516 const T21 v21_;
2517 const T22 v22_;
2518 const T23 v23_;
2519 const T24 v24_;
2520 const T25 v25_;
2521 const T26 v26_;
2522 const T27 v27_;
2523 const T28 v28_;
2524 const T29 v29_;
2525 const T30 v30_;
2526 const T31 v31_;
2527 const T32 v32_;
2528 const T33 v33_;
2529 const T34 v34_;
2530 const T35 v35_;
2531 const T36 v36_;
2532 const T37 v37_;
2533 const T38 v38_;
2534 const T39 v39_;
2535 const T40 v40_;
2536 const T41 v41_;
2537 const T42 v42_;
2538 const T43 v43_;
2539 const T44 v44_;
2540 };
2541
2542 template <typename T1, typename T2, typename T3, typename T4, typename T5,
2543 typename T6, typename T7, typename T8, typename T9, typename T10,
2544 typename T11, typename T12, typename T13, typename T14, typename T15,
2545 typename T16, typename T17, typename T18, typename T19, typename T20,
2546 typename T21, typename T22, typename T23, typename T24, typename T25,
2547 typename T26, typename T27, typename T28, typename T29, typename T30,
2548 typename T31, typename T32, typename T33, typename T34, typename T35,
2549 typename T36, typename T37, typename T38, typename T39, typename T40,
2550 typename T41, typename T42, typename T43, typename T44, typename T45>
2551 class ValueArray45 {
2552 public:
2553 ValueArray45(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2554 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2555 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2556 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2557 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
2558 T42 v42, T43 v43, T44 v44, T45 v45) : v1_(v1), v2_(v2), v3_(v3), v4_(v4),
2559 v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10), v11_(v11),
2560 v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16), v17_(v17),
2561 v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22), v23_(v23),
2562 v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28), v29_(v29),
2563 v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34), v35_(v35),
2564 v36_(v36), v37_(v37), v38_(v38), v39_(v39), v40_(v40), v41_(v41),
2565 v42_(v42), v43_(v43), v44_(v44), v45_(v45) {}
2566
2567 template <typename T>
2568 operator ParamGenerator<T>() const {
2569 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2570 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2571 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2572 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2573 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2574 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2575 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2576 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2577 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2578 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2579 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2580 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2581 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2582 static_cast<T>(v39_), static_cast<T>(v40_), static_cast<T>(v41_),
2583 static_cast<T>(v42_), static_cast<T>(v43_), static_cast<T>(v44_),
2584 static_cast<T>(v45_)};
2585 return ValuesIn(array);
2586 }
2587
2588 private:
2589 // No implementation - assignment is unsupported.
2590 void operator=(const ValueArray45& other);
2591
2592 const T1 v1_;
2593 const T2 v2_;
2594 const T3 v3_;
2595 const T4 v4_;
2596 const T5 v5_;
2597 const T6 v6_;
2598 const T7 v7_;
2599 const T8 v8_;
2600 const T9 v9_;
2601 const T10 v10_;
2602 const T11 v11_;
2603 const T12 v12_;
2604 const T13 v13_;
2605 const T14 v14_;
2606 const T15 v15_;
2607 const T16 v16_;
2608 const T17 v17_;
2609 const T18 v18_;
2610 const T19 v19_;
2611 const T20 v20_;
2612 const T21 v21_;
2613 const T22 v22_;
2614 const T23 v23_;
2615 const T24 v24_;
2616 const T25 v25_;
2617 const T26 v26_;
2618 const T27 v27_;
2619 const T28 v28_;
2620 const T29 v29_;
2621 const T30 v30_;
2622 const T31 v31_;
2623 const T32 v32_;
2624 const T33 v33_;
2625 const T34 v34_;
2626 const T35 v35_;
2627 const T36 v36_;
2628 const T37 v37_;
2629 const T38 v38_;
2630 const T39 v39_;
2631 const T40 v40_;
2632 const T41 v41_;
2633 const T42 v42_;
2634 const T43 v43_;
2635 const T44 v44_;
2636 const T45 v45_;
2637 };
2638
2639 template <typename T1, typename T2, typename T3, typename T4, typename T5,
2640 typename T6, typename T7, typename T8, typename T9, typename T10,
2641 typename T11, typename T12, typename T13, typename T14, typename T15,
2642 typename T16, typename T17, typename T18, typename T19, typename T20,
2643 typename T21, typename T22, typename T23, typename T24, typename T25,
2644 typename T26, typename T27, typename T28, typename T29, typename T30,
2645 typename T31, typename T32, typename T33, typename T34, typename T35,
2646 typename T36, typename T37, typename T38, typename T39, typename T40,
2647 typename T41, typename T42, typename T43, typename T44, typename T45,
2648 typename T46>
2649 class ValueArray46 {
2650 public:
2651 ValueArray46(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2652 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2653 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2654 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2655 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
2656 T42 v42, T43 v43, T44 v44, T45 v45, T46 v46) : v1_(v1), v2_(v2), v3_(v3),
2657 v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),
2658 v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),
2659 v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),
2660 v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),
2661 v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34),
2662 v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39), v40_(v40),
2663 v41_(v41), v42_(v42), v43_(v43), v44_(v44), v45_(v45), v46_(v46) {}
2664
2665 template <typename T>
2666 operator ParamGenerator<T>() const {
2667 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2668 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2669 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2670 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2671 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2672 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2673 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2674 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2675 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2676 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2677 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2678 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2679 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2680 static_cast<T>(v39_), static_cast<T>(v40_), static_cast<T>(v41_),
2681 static_cast<T>(v42_), static_cast<T>(v43_), static_cast<T>(v44_),
2682 static_cast<T>(v45_), static_cast<T>(v46_)};
2683 return ValuesIn(array);
2684 }
2685
2686 private:
2687 // No implementation - assignment is unsupported.
2688 void operator=(const ValueArray46& other);
2689
2690 const T1 v1_;
2691 const T2 v2_;
2692 const T3 v3_;
2693 const T4 v4_;
2694 const T5 v5_;
2695 const T6 v6_;
2696 const T7 v7_;
2697 const T8 v8_;
2698 const T9 v9_;
2699 const T10 v10_;
2700 const T11 v11_;
2701 const T12 v12_;
2702 const T13 v13_;
2703 const T14 v14_;
2704 const T15 v15_;
2705 const T16 v16_;
2706 const T17 v17_;
2707 const T18 v18_;
2708 const T19 v19_;
2709 const T20 v20_;
2710 const T21 v21_;
2711 const T22 v22_;
2712 const T23 v23_;
2713 const T24 v24_;
2714 const T25 v25_;
2715 const T26 v26_;
2716 const T27 v27_;
2717 const T28 v28_;
2718 const T29 v29_;
2719 const T30 v30_;
2720 const T31 v31_;
2721 const T32 v32_;
2722 const T33 v33_;
2723 const T34 v34_;
2724 const T35 v35_;
2725 const T36 v36_;
2726 const T37 v37_;
2727 const T38 v38_;
2728 const T39 v39_;
2729 const T40 v40_;
2730 const T41 v41_;
2731 const T42 v42_;
2732 const T43 v43_;
2733 const T44 v44_;
2734 const T45 v45_;
2735 const T46 v46_;
2736 };
2737
2738 template <typename T1, typename T2, typename T3, typename T4, typename T5,
2739 typename T6, typename T7, typename T8, typename T9, typename T10,
2740 typename T11, typename T12, typename T13, typename T14, typename T15,
2741 typename T16, typename T17, typename T18, typename T19, typename T20,
2742 typename T21, typename T22, typename T23, typename T24, typename T25,
2743 typename T26, typename T27, typename T28, typename T29, typename T30,
2744 typename T31, typename T32, typename T33, typename T34, typename T35,
2745 typename T36, typename T37, typename T38, typename T39, typename T40,
2746 typename T41, typename T42, typename T43, typename T44, typename T45,
2747 typename T46, typename T47>
2748 class ValueArray47 {
2749 public:
2750 ValueArray47(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2751 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2752 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2753 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2754 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
2755 T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47) : v1_(v1), v2_(v2),
2756 v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9), v10_(v10),
2757 v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15), v16_(v16),
2758 v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21), v22_(v22),
2759 v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27), v28_(v28),
2760 v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33), v34_(v34),
2761 v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39), v40_(v40),
2762 v41_(v41), v42_(v42), v43_(v43), v44_(v44), v45_(v45), v46_(v46),
2763 v47_(v47) {}
2764
2765 template <typename T>
2766 operator ParamGenerator<T>() const {
2767 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2768 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2769 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2770 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2771 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2772 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2773 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2774 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2775 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2776 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2777 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2778 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2779 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2780 static_cast<T>(v39_), static_cast<T>(v40_), static_cast<T>(v41_),
2781 static_cast<T>(v42_), static_cast<T>(v43_), static_cast<T>(v44_),
2782 static_cast<T>(v45_), static_cast<T>(v46_), static_cast<T>(v47_)};
2783 return ValuesIn(array);
2784 }
2785
2786 private:
2787 // No implementation - assignment is unsupported.
2788 void operator=(const ValueArray47& other);
2789
2790 const T1 v1_;
2791 const T2 v2_;
2792 const T3 v3_;
2793 const T4 v4_;
2794 const T5 v5_;
2795 const T6 v6_;
2796 const T7 v7_;
2797 const T8 v8_;
2798 const T9 v9_;
2799 const T10 v10_;
2800 const T11 v11_;
2801 const T12 v12_;
2802 const T13 v13_;
2803 const T14 v14_;
2804 const T15 v15_;
2805 const T16 v16_;
2806 const T17 v17_;
2807 const T18 v18_;
2808 const T19 v19_;
2809 const T20 v20_;
2810 const T21 v21_;
2811 const T22 v22_;
2812 const T23 v23_;
2813 const T24 v24_;
2814 const T25 v25_;
2815 const T26 v26_;
2816 const T27 v27_;
2817 const T28 v28_;
2818 const T29 v29_;
2819 const T30 v30_;
2820 const T31 v31_;
2821 const T32 v32_;
2822 const T33 v33_;
2823 const T34 v34_;
2824 const T35 v35_;
2825 const T36 v36_;
2826 const T37 v37_;
2827 const T38 v38_;
2828 const T39 v39_;
2829 const T40 v40_;
2830 const T41 v41_;
2831 const T42 v42_;
2832 const T43 v43_;
2833 const T44 v44_;
2834 const T45 v45_;
2835 const T46 v46_;
2836 const T47 v47_;
2837 };
2838
2839 template <typename T1, typename T2, typename T3, typename T4, typename T5,
2840 typename T6, typename T7, typename T8, typename T9, typename T10,
2841 typename T11, typename T12, typename T13, typename T14, typename T15,
2842 typename T16, typename T17, typename T18, typename T19, typename T20,
2843 typename T21, typename T22, typename T23, typename T24, typename T25,
2844 typename T26, typename T27, typename T28, typename T29, typename T30,
2845 typename T31, typename T32, typename T33, typename T34, typename T35,
2846 typename T36, typename T37, typename T38, typename T39, typename T40,
2847 typename T41, typename T42, typename T43, typename T44, typename T45,
2848 typename T46, typename T47, typename T48>
2849 class ValueArray48 {
2850 public:
2851 ValueArray48(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2852 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2853 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2854 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2855 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
2856 T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47, T48 v48) : v1_(v1),
2857 v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7), v8_(v8), v9_(v9),
2858 v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14), v15_(v15),
2859 v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20), v21_(v21),
2860 v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26), v27_(v27),
2861 v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32), v33_(v33),
2862 v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38), v39_(v39),
2863 v40_(v40), v41_(v41), v42_(v42), v43_(v43), v44_(v44), v45_(v45),
2864 v46_(v46), v47_(v47), v48_(v48) {}
2865
2866 template <typename T>
2867 operator ParamGenerator<T>() const {
2868 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2869 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2870 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2871 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2872 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2873 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2874 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2875 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2876 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2877 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2878 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2879 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2880 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2881 static_cast<T>(v39_), static_cast<T>(v40_), static_cast<T>(v41_),
2882 static_cast<T>(v42_), static_cast<T>(v43_), static_cast<T>(v44_),
2883 static_cast<T>(v45_), static_cast<T>(v46_), static_cast<T>(v47_),
2884 static_cast<T>(v48_)};
2885 return ValuesIn(array);
2886 }
2887
2888 private:
2889 // No implementation - assignment is unsupported.
2890 void operator=(const ValueArray48& other);
2891
2892 const T1 v1_;
2893 const T2 v2_;
2894 const T3 v3_;
2895 const T4 v4_;
2896 const T5 v5_;
2897 const T6 v6_;
2898 const T7 v7_;
2899 const T8 v8_;
2900 const T9 v9_;
2901 const T10 v10_;
2902 const T11 v11_;
2903 const T12 v12_;
2904 const T13 v13_;
2905 const T14 v14_;
2906 const T15 v15_;
2907 const T16 v16_;
2908 const T17 v17_;
2909 const T18 v18_;
2910 const T19 v19_;
2911 const T20 v20_;
2912 const T21 v21_;
2913 const T22 v22_;
2914 const T23 v23_;
2915 const T24 v24_;
2916 const T25 v25_;
2917 const T26 v26_;
2918 const T27 v27_;
2919 const T28 v28_;
2920 const T29 v29_;
2921 const T30 v30_;
2922 const T31 v31_;
2923 const T32 v32_;
2924 const T33 v33_;
2925 const T34 v34_;
2926 const T35 v35_;
2927 const T36 v36_;
2928 const T37 v37_;
2929 const T38 v38_;
2930 const T39 v39_;
2931 const T40 v40_;
2932 const T41 v41_;
2933 const T42 v42_;
2934 const T43 v43_;
2935 const T44 v44_;
2936 const T45 v45_;
2937 const T46 v46_;
2938 const T47 v47_;
2939 const T48 v48_;
2940 };
2941
2942 template <typename T1, typename T2, typename T3, typename T4, typename T5,
2943 typename T6, typename T7, typename T8, typename T9, typename T10,
2944 typename T11, typename T12, typename T13, typename T14, typename T15,
2945 typename T16, typename T17, typename T18, typename T19, typename T20,
2946 typename T21, typename T22, typename T23, typename T24, typename T25,
2947 typename T26, typename T27, typename T28, typename T29, typename T30,
2948 typename T31, typename T32, typename T33, typename T34, typename T35,
2949 typename T36, typename T37, typename T38, typename T39, typename T40,
2950 typename T41, typename T42, typename T43, typename T44, typename T45,
2951 typename T46, typename T47, typename T48, typename T49>
2952 class ValueArray49 {
2953 public:
2954 ValueArray49(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
2955 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
2956 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
2957 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
2958 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
2959 T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47, T48 v48,
2960 T49 v49) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
2961 v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),
2962 v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),
2963 v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),
2964 v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),
2965 v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38),
2966 v39_(v39), v40_(v40), v41_(v41), v42_(v42), v43_(v43), v44_(v44),
2967 v45_(v45), v46_(v46), v47_(v47), v48_(v48), v49_(v49) {}
2968
2969 template <typename T>
2970 operator ParamGenerator<T>() const {
2971 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
2972 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
2973 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
2974 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
2975 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
2976 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
2977 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
2978 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
2979 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
2980 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
2981 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
2982 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
2983 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
2984 static_cast<T>(v39_), static_cast<T>(v40_), static_cast<T>(v41_),
2985 static_cast<T>(v42_), static_cast<T>(v43_), static_cast<T>(v44_),
2986 static_cast<T>(v45_), static_cast<T>(v46_), static_cast<T>(v47_),
2987 static_cast<T>(v48_), static_cast<T>(v49_)};
2988 return ValuesIn(array);
2989 }
2990
2991 private:
2992 // No implementation - assignment is unsupported.
2993 void operator=(const ValueArray49& other);
2994
2995 const T1 v1_;
2996 const T2 v2_;
2997 const T3 v3_;
2998 const T4 v4_;
2999 const T5 v5_;
3000 const T6 v6_;
3001 const T7 v7_;
3002 const T8 v8_;
3003 const T9 v9_;
3004 const T10 v10_;
3005 const T11 v11_;
3006 const T12 v12_;
3007 const T13 v13_;
3008 const T14 v14_;
3009 const T15 v15_;
3010 const T16 v16_;
3011 const T17 v17_;
3012 const T18 v18_;
3013 const T19 v19_;
3014 const T20 v20_;
3015 const T21 v21_;
3016 const T22 v22_;
3017 const T23 v23_;
3018 const T24 v24_;
3019 const T25 v25_;
3020 const T26 v26_;
3021 const T27 v27_;
3022 const T28 v28_;
3023 const T29 v29_;
3024 const T30 v30_;
3025 const T31 v31_;
3026 const T32 v32_;
3027 const T33 v33_;
3028 const T34 v34_;
3029 const T35 v35_;
3030 const T36 v36_;
3031 const T37 v37_;
3032 const T38 v38_;
3033 const T39 v39_;
3034 const T40 v40_;
3035 const T41 v41_;
3036 const T42 v42_;
3037 const T43 v43_;
3038 const T44 v44_;
3039 const T45 v45_;
3040 const T46 v46_;
3041 const T47 v47_;
3042 const T48 v48_;
3043 const T49 v49_;
3044 };
3045
3046 template <typename T1, typename T2, typename T3, typename T4, typename T5,
3047 typename T6, typename T7, typename T8, typename T9, typename T10,
3048 typename T11, typename T12, typename T13, typename T14, typename T15,
3049 typename T16, typename T17, typename T18, typename T19, typename T20,
3050 typename T21, typename T22, typename T23, typename T24, typename T25,
3051 typename T26, typename T27, typename T28, typename T29, typename T30,
3052 typename T31, typename T32, typename T33, typename T34, typename T35,
3053 typename T36, typename T37, typename T38, typename T39, typename T40,
3054 typename T41, typename T42, typename T43, typename T44, typename T45,
3055 typename T46, typename T47, typename T48, typename T49, typename T50>
3056 class ValueArray50 {
3057 public:
3058 ValueArray50(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9,
3059 T10 v10, T11 v11, T12 v12, T13 v13, T14 v14, T15 v15, T16 v16, T17 v17,
3060 T18 v18, T19 v19, T20 v20, T21 v21, T22 v22, T23 v23, T24 v24, T25 v25,
3061 T26 v26, T27 v27, T28 v28, T29 v29, T30 v30, T31 v31, T32 v32, T33 v33,
3062 T34 v34, T35 v35, T36 v36, T37 v37, T38 v38, T39 v39, T40 v40, T41 v41,
3063 T42 v42, T43 v43, T44 v44, T45 v45, T46 v46, T47 v47, T48 v48, T49 v49,
3064 T50 v50) : v1_(v1), v2_(v2), v3_(v3), v4_(v4), v5_(v5), v6_(v6), v7_(v7),
3065 v8_(v8), v9_(v9), v10_(v10), v11_(v11), v12_(v12), v13_(v13), v14_(v14),
3066 v15_(v15), v16_(v16), v17_(v17), v18_(v18), v19_(v19), v20_(v20),
3067 v21_(v21), v22_(v22), v23_(v23), v24_(v24), v25_(v25), v26_(v26),
3068 v27_(v27), v28_(v28), v29_(v29), v30_(v30), v31_(v31), v32_(v32),
3069 v33_(v33), v34_(v34), v35_(v35), v36_(v36), v37_(v37), v38_(v38),
3070 v39_(v39), v40_(v40), v41_(v41), v42_(v42), v43_(v43), v44_(v44),
3071 v45_(v45), v46_(v46), v47_(v47), v48_(v48), v49_(v49), v50_(v50) {}
3072
3073 template <typename T>
3074 operator ParamGenerator<T>() const {
3075 const T array[] = {static_cast<T>(v1_), static_cast<T>(v2_),
3076 static_cast<T>(v3_), static_cast<T>(v4_), static_cast<T>(v5_),
3077 static_cast<T>(v6_), static_cast<T>(v7_), static_cast<T>(v8_),
3078 static_cast<T>(v9_), static_cast<T>(v10_), static_cast<T>(v11_),
3079 static_cast<T>(v12_), static_cast<T>(v13_), static_cast<T>(v14_),
3080 static_cast<T>(v15_), static_cast<T>(v16_), static_cast<T>(v17_),
3081 static_cast<T>(v18_), static_cast<T>(v19_), static_cast<T>(v20_),
3082 static_cast<T>(v21_), static_cast<T>(v22_), static_cast<T>(v23_),
3083 static_cast<T>(v24_), static_cast<T>(v25_), static_cast<T>(v26_),
3084 static_cast<T>(v27_), static_cast<T>(v28_), static_cast<T>(v29_),
3085 static_cast<T>(v30_), static_cast<T>(v31_), static_cast<T>(v32_),
3086 static_cast<T>(v33_), static_cast<T>(v34_), static_cast<T>(v35_),
3087 static_cast<T>(v36_), static_cast<T>(v37_), static_cast<T>(v38_),
3088 static_cast<T>(v39_), static_cast<T>(v40_), static_cast<T>(v41_),
3089 static_cast<T>(v42_), static_cast<T>(v43_), static_cast<T>(v44_),
3090 static_cast<T>(v45_), static_cast<T>(v46_), static_cast<T>(v47_),
3091 static_cast<T>(v48_), static_cast<T>(v49_), static_cast<T>(v50_)};
3092 return ValuesIn(array);
3093 }
3094
3095 private:
3096 // No implementation - assignment is unsupported.
3097 void operator=(const ValueArray50& other);
3098
3099 const T1 v1_;
3100 const T2 v2_;
3101 const T3 v3_;
3102 const T4 v4_;
3103 const T5 v5_;
3104 const T6 v6_;
3105 const T7 v7_;
3106 const T8 v8_;
3107 const T9 v9_;
3108 const T10 v10_;
3109 const T11 v11_;
3110 const T12 v12_;
3111 const T13 v13_;
3112 const T14 v14_;
3113 const T15 v15_;
3114 const T16 v16_;
3115 const T17 v17_;
3116 const T18 v18_;
3117 const T19 v19_;
3118 const T20 v20_;
3119 const T21 v21_;
3120 const T22 v22_;
3121 const T23 v23_;
3122 const T24 v24_;
3123 const T25 v25_;
3124 const T26 v26_;
3125 const T27 v27_;
3126 const T28 v28_;
3127 const T29 v29_;
3128 const T30 v30_;
3129 const T31 v31_;
3130 const T32 v32_;
3131 const T33 v33_;
3132 const T34 v34_;
3133 const T35 v35_;
3134 const T36 v36_;
3135 const T37 v37_;
3136 const T38 v38_;
3137 const T39 v39_;
3138 const T40 v40_;
3139 const T41 v41_;
3140 const T42 v42_;
3141 const T43 v43_;
3142 const T44 v44_;
3143 const T45 v45_;
3144 const T46 v46_;
3145 const T47 v47_;
3146 const T48 v48_;
3147 const T49 v49_;
3148 const T50 v50_;
3149 };
3150
3151 # if GTEST_HAS_COMBINE
3152 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
3153 //
3154 // Generates values from the Cartesian product of values produced
3155 // by the argument generators.
3156 //
3157 template <typename T1, typename T2>
3158 class CartesianProductGenerator2
3159 : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2> > {
3160 public:
3161 typedef ::std::tr1::tuple<T1, T2> ParamType;
3162
3163 CartesianProductGenerator2(const ParamGenerator<T1>& g1,
3164 const ParamGenerator<T2>& g2)
3165 : g1_(g1), g2_(g2) {}
3166 virtual ~CartesianProductGenerator2() {}
3167
3168 virtual ParamIteratorInterface<ParamType>* Begin() const {
3169 return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin());
3170 }
3171 virtual ParamIteratorInterface<ParamType>* End() const {
3172 return new Iterator(this, g1_, g1_.end(), g2_, g2_.end());
3173 }
3174
3175 private:
3176 class Iterator : public ParamIteratorInterface<ParamType> {
3177 public:
3178 Iterator(const ParamGeneratorInterface<ParamType>* base,
3179 const ParamGenerator<T1>& g1,
3180 const typename ParamGenerator<T1>::iterator& current1,
3181 const ParamGenerator<T2>& g2,
3182 const typename ParamGenerator<T2>::iterator& current2)
3183 : base_(base),
3184 begin1_(g1.begin()), end1_(g1.end()), current1_(current1),
3185 begin2_(g2.begin()), end2_(g2.end()), current2_(current2) {
3186 ComputeCurrentValue();
3187 }
3188 virtual ~Iterator() {}
3189
3190 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
3191 return base_;
3192 }
3193 // Advance should not be called on beyond-of-range iterators
3194 // so no component iterators must be beyond end of range, either.
3195 virtual void Advance() {
3196 assert(!AtEnd());
3197 ++current2_;
3198 if (current2_ == end2_) {
3199 current2_ = begin2_;
3200 ++current1_;
3201 }
3202 ComputeCurrentValue();
3203 }
3204 virtual ParamIteratorInterface<ParamType>* Clone() const {
3205 return new Iterator(*this);
3206 }
3207 virtual const ParamType* Current() const { return &current_value_; }
3208 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
3209 // Having the same base generator guarantees that the other
3210 // iterator is of the same type and we can downcast.
3211 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
3212 << "The program attempted to compare iterators "
3213 << "from different generators." << std::endl;
3214 const Iterator* typed_other =
3215 CheckedDowncastToActualType<const Iterator>(&other);
3216 // We must report iterators equal if they both point beyond their
3217 // respective ranges. That can happen in a variety of fashions,
3218 // so we have to consult AtEnd().
3219 return (AtEnd() && typed_other->AtEnd()) ||
3220 (
3221 current1_ == typed_other->current1_ &&
3222 current2_ == typed_other->current2_);
3223 }
3224
3225 private:
3226 Iterator(const Iterator& other)
3227 : base_(other.base_),
3228 begin1_(other.begin1_),
3229 end1_(other.end1_),
3230 current1_(other.current1_),
3231 begin2_(other.begin2_),
3232 end2_(other.end2_),
3233 current2_(other.current2_) {
3234 ComputeCurrentValue();
3235 }
3236
3237 void ComputeCurrentValue() {
3238 if (!AtEnd())
3239 current_value_ = ParamType(*current1_, *current2_);
3240 }
3241 bool AtEnd() const {
3242 // We must report iterator past the end of the range when either of the
3243 // component iterators has reached the end of its range.
3244 return
3245 current1_ == end1_ ||
3246 current2_ == end2_;
3247 }
3248
3249 // No implementation - assignment is unsupported.
3250 void operator=(const Iterator& other);
3251
3252 const ParamGeneratorInterface<ParamType>* const base_;
3253 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
3254 // current[i]_ is the actual traversing iterator.
3255 const typename ParamGenerator<T1>::iterator begin1_;
3256 const typename ParamGenerator<T1>::iterator end1_;
3257 typename ParamGenerator<T1>::iterator current1_;
3258 const typename ParamGenerator<T2>::iterator begin2_;
3259 const typename ParamGenerator<T2>::iterator end2_;
3260 typename ParamGenerator<T2>::iterator current2_;
3261 ParamType current_value_;
3262 }; // class CartesianProductGenerator2::Iterator
3263
3264 // No implementation - assignment is unsupported.
3265 void operator=(const CartesianProductGenerator2& other);
3266
3267 const ParamGenerator<T1> g1_;
3268 const ParamGenerator<T2> g2_;
3269 }; // class CartesianProductGenerator2
3270
3271
3272 template <typename T1, typename T2, typename T3>
3273 class CartesianProductGenerator3
3274 : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3> > {
3275 public:
3276 typedef ::std::tr1::tuple<T1, T2, T3> ParamType;
3277
3278 CartesianProductGenerator3(const ParamGenerator<T1>& g1,
3279 const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3)
3280 : g1_(g1), g2_(g2), g3_(g3) {}
3281 virtual ~CartesianProductGenerator3() {}
3282
3283 virtual ParamIteratorInterface<ParamType>* Begin() const {
3284 return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,
3285 g3_.begin());
3286 }
3287 virtual ParamIteratorInterface<ParamType>* End() const {
3288 return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end());
3289 }
3290
3291 private:
3292 class Iterator : public ParamIteratorInterface<ParamType> {
3293 public:
3294 Iterator(const ParamGeneratorInterface<ParamType>* base,
3295 const ParamGenerator<T1>& g1,
3296 const typename ParamGenerator<T1>::iterator& current1,
3297 const ParamGenerator<T2>& g2,
3298 const typename ParamGenerator<T2>::iterator& current2,
3299 const ParamGenerator<T3>& g3,
3300 const typename ParamGenerator<T3>::iterator& current3)
3301 : base_(base),
3302 begin1_(g1.begin()), end1_(g1.end()), current1_(current1),
3303 begin2_(g2.begin()), end2_(g2.end()), current2_(current2),
3304 begin3_(g3.begin()), end3_(g3.end()), current3_(current3) {
3305 ComputeCurrentValue();
3306 }
3307 virtual ~Iterator() {}
3308
3309 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
3310 return base_;
3311 }
3312 // Advance should not be called on beyond-of-range iterators
3313 // so no component iterators must be beyond end of range, either.
3314 virtual void Advance() {
3315 assert(!AtEnd());
3316 ++current3_;
3317 if (current3_ == end3_) {
3318 current3_ = begin3_;
3319 ++current2_;
3320 }
3321 if (current2_ == end2_) {
3322 current2_ = begin2_;
3323 ++current1_;
3324 }
3325 ComputeCurrentValue();
3326 }
3327 virtual ParamIteratorInterface<ParamType>* Clone() const {
3328 return new Iterator(*this);
3329 }
3330 virtual const ParamType* Current() const { return &current_value_; }
3331 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
3332 // Having the same base generator guarantees that the other
3333 // iterator is of the same type and we can downcast.
3334 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
3335 << "The program attempted to compare iterators "
3336 << "from different generators." << std::endl;
3337 const Iterator* typed_other =
3338 CheckedDowncastToActualType<const Iterator>(&other);
3339 // We must report iterators equal if they both point beyond their
3340 // respective ranges. That can happen in a variety of fashions,
3341 // so we have to consult AtEnd().
3342 return (AtEnd() && typed_other->AtEnd()) ||
3343 (
3344 current1_ == typed_other->current1_ &&
3345 current2_ == typed_other->current2_ &&
3346 current3_ == typed_other->current3_);
3347 }
3348
3349 private:
3350 Iterator(const Iterator& other)
3351 : base_(other.base_),
3352 begin1_(other.begin1_),
3353 end1_(other.end1_),
3354 current1_(other.current1_),
3355 begin2_(other.begin2_),
3356 end2_(other.end2_),
3357 current2_(other.current2_),
3358 begin3_(other.begin3_),
3359 end3_(other.end3_),
3360 current3_(other.current3_) {
3361 ComputeCurrentValue();
3362 }
3363
3364 void ComputeCurrentValue() {
3365 if (!AtEnd())
3366 current_value_ = ParamType(*current1_, *current2_, *current3_);
3367 }
3368 bool AtEnd() const {
3369 // We must report iterator past the end of the range when either of the
3370 // component iterators has reached the end of its range.
3371 return
3372 current1_ == end1_ ||
3373 current2_ == end2_ ||
3374 current3_ == end3_;
3375 }
3376
3377 // No implementation - assignment is unsupported.
3378 void operator=(const Iterator& other);
3379
3380 const ParamGeneratorInterface<ParamType>* const base_;
3381 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
3382 // current[i]_ is the actual traversing iterator.
3383 const typename ParamGenerator<T1>::iterator begin1_;
3384 const typename ParamGenerator<T1>::iterator end1_;
3385 typename ParamGenerator<T1>::iterator current1_;
3386 const typename ParamGenerator<T2>::iterator begin2_;
3387 const typename ParamGenerator<T2>::iterator end2_;
3388 typename ParamGenerator<T2>::iterator current2_;
3389 const typename ParamGenerator<T3>::iterator begin3_;
3390 const typename ParamGenerator<T3>::iterator end3_;
3391 typename ParamGenerator<T3>::iterator current3_;
3392 ParamType current_value_;
3393 }; // class CartesianProductGenerator3::Iterator
3394
3395 // No implementation - assignment is unsupported.
3396 void operator=(const CartesianProductGenerator3& other);
3397
3398 const ParamGenerator<T1> g1_;
3399 const ParamGenerator<T2> g2_;
3400 const ParamGenerator<T3> g3_;
3401 }; // class CartesianProductGenerator3
3402
3403
3404 template <typename T1, typename T2, typename T3, typename T4>
3405 class CartesianProductGenerator4
3406 : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4> > {
3407 public:
3408 typedef ::std::tr1::tuple<T1, T2, T3, T4> ParamType;
3409
3410 CartesianProductGenerator4(const ParamGenerator<T1>& g1,
3411 const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,
3412 const ParamGenerator<T4>& g4)
3413 : g1_(g1), g2_(g2), g3_(g3), g4_(g4) {}
3414 virtual ~CartesianProductGenerator4() {}
3415
3416 virtual ParamIteratorInterface<ParamType>* Begin() const {
3417 return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,
3418 g3_.begin(), g4_, g4_.begin());
3419 }
3420 virtual ParamIteratorInterface<ParamType>* End() const {
3421 return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),
3422 g4_, g4_.end());
3423 }
3424
3425 private:
3426 class Iterator : public ParamIteratorInterface<ParamType> {
3427 public:
3428 Iterator(const ParamGeneratorInterface<ParamType>* base,
3429 const ParamGenerator<T1>& g1,
3430 const typename ParamGenerator<T1>::iterator& current1,
3431 const ParamGenerator<T2>& g2,
3432 const typename ParamGenerator<T2>::iterator& current2,
3433 const ParamGenerator<T3>& g3,
3434 const typename ParamGenerator<T3>::iterator& current3,
3435 const ParamGenerator<T4>& g4,
3436 const typename ParamGenerator<T4>::iterator& current4)
3437 : base_(base),
3438 begin1_(g1.begin()), end1_(g1.end()), current1_(current1),
3439 begin2_(g2.begin()), end2_(g2.end()), current2_(current2),
3440 begin3_(g3.begin()), end3_(g3.end()), current3_(current3),
3441 begin4_(g4.begin()), end4_(g4.end()), current4_(current4) {
3442 ComputeCurrentValue();
3443 }
3444 virtual ~Iterator() {}
3445
3446 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
3447 return base_;
3448 }
3449 // Advance should not be called on beyond-of-range iterators
3450 // so no component iterators must be beyond end of range, either.
3451 virtual void Advance() {
3452 assert(!AtEnd());
3453 ++current4_;
3454 if (current4_ == end4_) {
3455 current4_ = begin4_;
3456 ++current3_;
3457 }
3458 if (current3_ == end3_) {
3459 current3_ = begin3_;
3460 ++current2_;
3461 }
3462 if (current2_ == end2_) {
3463 current2_ = begin2_;
3464 ++current1_;
3465 }
3466 ComputeCurrentValue();
3467 }
3468 virtual ParamIteratorInterface<ParamType>* Clone() const {
3469 return new Iterator(*this);
3470 }
3471 virtual const ParamType* Current() const { return &current_value_; }
3472 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
3473 // Having the same base generator guarantees that the other
3474 // iterator is of the same type and we can downcast.
3475 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
3476 << "The program attempted to compare iterators "
3477 << "from different generators." << std::endl;
3478 const Iterator* typed_other =
3479 CheckedDowncastToActualType<const Iterator>(&other);
3480 // We must report iterators equal if they both point beyond their
3481 // respective ranges. That can happen in a variety of fashions,
3482 // so we have to consult AtEnd().
3483 return (AtEnd() && typed_other->AtEnd()) ||
3484 (
3485 current1_ == typed_other->current1_ &&
3486 current2_ == typed_other->current2_ &&
3487 current3_ == typed_other->current3_ &&
3488 current4_ == typed_other->current4_);
3489 }
3490
3491 private:
3492 Iterator(const Iterator& other)
3493 : base_(other.base_),
3494 begin1_(other.begin1_),
3495 end1_(other.end1_),
3496 current1_(other.current1_),
3497 begin2_(other.begin2_),
3498 end2_(other.end2_),
3499 current2_(other.current2_),
3500 begin3_(other.begin3_),
3501 end3_(other.end3_),
3502 current3_(other.current3_),
3503 begin4_(other.begin4_),
3504 end4_(other.end4_),
3505 current4_(other.current4_) {
3506 ComputeCurrentValue();
3507 }
3508
3509 void ComputeCurrentValue() {
3510 if (!AtEnd())
3511 current_value_ = ParamType(*current1_, *current2_, *current3_,
3512 *current4_);
3513 }
3514 bool AtEnd() const {
3515 // We must report iterator past the end of the range when either of the
3516 // component iterators has reached the end of its range.
3517 return
3518 current1_ == end1_ ||
3519 current2_ == end2_ ||
3520 current3_ == end3_ ||
3521 current4_ == end4_;
3522 }
3523
3524 // No implementation - assignment is unsupported.
3525 void operator=(const Iterator& other);
3526
3527 const ParamGeneratorInterface<ParamType>* const base_;
3528 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
3529 // current[i]_ is the actual traversing iterator.
3530 const typename ParamGenerator<T1>::iterator begin1_;
3531 const typename ParamGenerator<T1>::iterator end1_;
3532 typename ParamGenerator<T1>::iterator current1_;
3533 const typename ParamGenerator<T2>::iterator begin2_;
3534 const typename ParamGenerator<T2>::iterator end2_;
3535 typename ParamGenerator<T2>::iterator current2_;
3536 const typename ParamGenerator<T3>::iterator begin3_;
3537 const typename ParamGenerator<T3>::iterator end3_;
3538 typename ParamGenerator<T3>::iterator current3_;
3539 const typename ParamGenerator<T4>::iterator begin4_;
3540 const typename ParamGenerator<T4>::iterator end4_;
3541 typename ParamGenerator<T4>::iterator current4_;
3542 ParamType current_value_;
3543 }; // class CartesianProductGenerator4::Iterator
3544
3545 // No implementation - assignment is unsupported.
3546 void operator=(const CartesianProductGenerator4& other);
3547
3548 const ParamGenerator<T1> g1_;
3549 const ParamGenerator<T2> g2_;
3550 const ParamGenerator<T3> g3_;
3551 const ParamGenerator<T4> g4_;
3552 }; // class CartesianProductGenerator4
3553
3554
3555 template <typename T1, typename T2, typename T3, typename T4, typename T5>
3556 class CartesianProductGenerator5
3557 : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5> > {
3558 public:
3559 typedef ::std::tr1::tuple<T1, T2, T3, T4, T5> ParamType;
3560
3561 CartesianProductGenerator5(const ParamGenerator<T1>& g1,
3562 const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,
3563 const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5)
3564 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5) {}
3565 virtual ~CartesianProductGenerator5() {}
3566
3567 virtual ParamIteratorInterface<ParamType>* Begin() const {
3568 return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,
3569 g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin());
3570 }
3571 virtual ParamIteratorInterface<ParamType>* End() const {
3572 return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),
3573 g4_, g4_.end(), g5_, g5_.end());
3574 }
3575
3576 private:
3577 class Iterator : public ParamIteratorInterface<ParamType> {
3578 public:
3579 Iterator(const ParamGeneratorInterface<ParamType>* base,
3580 const ParamGenerator<T1>& g1,
3581 const typename ParamGenerator<T1>::iterator& current1,
3582 const ParamGenerator<T2>& g2,
3583 const typename ParamGenerator<T2>::iterator& current2,
3584 const ParamGenerator<T3>& g3,
3585 const typename ParamGenerator<T3>::iterator& current3,
3586 const ParamGenerator<T4>& g4,
3587 const typename ParamGenerator<T4>::iterator& current4,
3588 const ParamGenerator<T5>& g5,
3589 const typename ParamGenerator<T5>::iterator& current5)
3590 : base_(base),
3591 begin1_(g1.begin()), end1_(g1.end()), current1_(current1),
3592 begin2_(g2.begin()), end2_(g2.end()), current2_(current2),
3593 begin3_(g3.begin()), end3_(g3.end()), current3_(current3),
3594 begin4_(g4.begin()), end4_(g4.end()), current4_(current4),
3595 begin5_(g5.begin()), end5_(g5.end()), current5_(current5) {
3596 ComputeCurrentValue();
3597 }
3598 virtual ~Iterator() {}
3599
3600 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
3601 return base_;
3602 }
3603 // Advance should not be called on beyond-of-range iterators
3604 // so no component iterators must be beyond end of range, either.
3605 virtual void Advance() {
3606 assert(!AtEnd());
3607 ++current5_;
3608 if (current5_ == end5_) {
3609 current5_ = begin5_;
3610 ++current4_;
3611 }
3612 if (current4_ == end4_) {
3613 current4_ = begin4_;
3614 ++current3_;
3615 }
3616 if (current3_ == end3_) {
3617 current3_ = begin3_;
3618 ++current2_;
3619 }
3620 if (current2_ == end2_) {
3621 current2_ = begin2_;
3622 ++current1_;
3623 }
3624 ComputeCurrentValue();
3625 }
3626 virtual ParamIteratorInterface<ParamType>* Clone() const {
3627 return new Iterator(*this);
3628 }
3629 virtual const ParamType* Current() const { return &current_value_; }
3630 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
3631 // Having the same base generator guarantees that the other
3632 // iterator is of the same type and we can downcast.
3633 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
3634 << "The program attempted to compare iterators "
3635 << "from different generators." << std::endl;
3636 const Iterator* typed_other =
3637 CheckedDowncastToActualType<const Iterator>(&other);
3638 // We must report iterators equal if they both point beyond their
3639 // respective ranges. That can happen in a variety of fashions,
3640 // so we have to consult AtEnd().
3641 return (AtEnd() && typed_other->AtEnd()) ||
3642 (
3643 current1_ == typed_other->current1_ &&
3644 current2_ == typed_other->current2_ &&
3645 current3_ == typed_other->current3_ &&
3646 current4_ == typed_other->current4_ &&
3647 current5_ == typed_other->current5_);
3648 }
3649
3650 private:
3651 Iterator(const Iterator& other)
3652 : base_(other.base_),
3653 begin1_(other.begin1_),
3654 end1_(other.end1_),
3655 current1_(other.current1_),
3656 begin2_(other.begin2_),
3657 end2_(other.end2_),
3658 current2_(other.current2_),
3659 begin3_(other.begin3_),
3660 end3_(other.end3_),
3661 current3_(other.current3_),
3662 begin4_(other.begin4_),
3663 end4_(other.end4_),
3664 current4_(other.current4_),
3665 begin5_(other.begin5_),
3666 end5_(other.end5_),
3667 current5_(other.current5_) {
3668 ComputeCurrentValue();
3669 }
3670
3671 void ComputeCurrentValue() {
3672 if (!AtEnd())
3673 current_value_ = ParamType(*current1_, *current2_, *current3_,
3674 *current4_, *current5_);
3675 }
3676 bool AtEnd() const {
3677 // We must report iterator past the end of the range when either of the
3678 // component iterators has reached the end of its range.
3679 return
3680 current1_ == end1_ ||
3681 current2_ == end2_ ||
3682 current3_ == end3_ ||
3683 current4_ == end4_ ||
3684 current5_ == end5_;
3685 }
3686
3687 // No implementation - assignment is unsupported.
3688 void operator=(const Iterator& other);
3689
3690 const ParamGeneratorInterface<ParamType>* const base_;
3691 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
3692 // current[i]_ is the actual traversing iterator.
3693 const typename ParamGenerator<T1>::iterator begin1_;
3694 const typename ParamGenerator<T1>::iterator end1_;
3695 typename ParamGenerator<T1>::iterator current1_;
3696 const typename ParamGenerator<T2>::iterator begin2_;
3697 const typename ParamGenerator<T2>::iterator end2_;
3698 typename ParamGenerator<T2>::iterator current2_;
3699 const typename ParamGenerator<T3>::iterator begin3_;
3700 const typename ParamGenerator<T3>::iterator end3_;
3701 typename ParamGenerator<T3>::iterator current3_;
3702 const typename ParamGenerator<T4>::iterator begin4_;
3703 const typename ParamGenerator<T4>::iterator end4_;
3704 typename ParamGenerator<T4>::iterator current4_;
3705 const typename ParamGenerator<T5>::iterator begin5_;
3706 const typename ParamGenerator<T5>::iterator end5_;
3707 typename ParamGenerator<T5>::iterator current5_;
3708 ParamType current_value_;
3709 }; // class CartesianProductGenerator5::Iterator
3710
3711 // No implementation - assignment is unsupported.
3712 void operator=(const CartesianProductGenerator5& other);
3713
3714 const ParamGenerator<T1> g1_;
3715 const ParamGenerator<T2> g2_;
3716 const ParamGenerator<T3> g3_;
3717 const ParamGenerator<T4> g4_;
3718 const ParamGenerator<T5> g5_;
3719 }; // class CartesianProductGenerator5
3720
3721
3722 template <typename T1, typename T2, typename T3, typename T4, typename T5,
3723 typename T6>
3724 class CartesianProductGenerator6
3725 : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5,
3726 T6> > {
3727 public:
3728 typedef ::std::tr1::tuple<T1, T2, T3, T4, T5, T6> ParamType;
3729
3730 CartesianProductGenerator6(const ParamGenerator<T1>& g1,
3731 const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,
3732 const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5,
3733 const ParamGenerator<T6>& g6)
3734 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6) {}
3735 virtual ~CartesianProductGenerator6() {}
3736
3737 virtual ParamIteratorInterface<ParamType>* Begin() const {
3738 return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,
3739 g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin());
3740 }
3741 virtual ParamIteratorInterface<ParamType>* End() const {
3742 return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),
3743 g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end());
3744 }
3745
3746 private:
3747 class Iterator : public ParamIteratorInterface<ParamType> {
3748 public:
3749 Iterator(const ParamGeneratorInterface<ParamType>* base,
3750 const ParamGenerator<T1>& g1,
3751 const typename ParamGenerator<T1>::iterator& current1,
3752 const ParamGenerator<T2>& g2,
3753 const typename ParamGenerator<T2>::iterator& current2,
3754 const ParamGenerator<T3>& g3,
3755 const typename ParamGenerator<T3>::iterator& current3,
3756 const ParamGenerator<T4>& g4,
3757 const typename ParamGenerator<T4>::iterator& current4,
3758 const ParamGenerator<T5>& g5,
3759 const typename ParamGenerator<T5>::iterator& current5,
3760 const ParamGenerator<T6>& g6,
3761 const typename ParamGenerator<T6>::iterator& current6)
3762 : base_(base),
3763 begin1_(g1.begin()), end1_(g1.end()), current1_(current1),
3764 begin2_(g2.begin()), end2_(g2.end()), current2_(current2),
3765 begin3_(g3.begin()), end3_(g3.end()), current3_(current3),
3766 begin4_(g4.begin()), end4_(g4.end()), current4_(current4),
3767 begin5_(g5.begin()), end5_(g5.end()), current5_(current5),
3768 begin6_(g6.begin()), end6_(g6.end()), current6_(current6) {
3769 ComputeCurrentValue();
3770 }
3771 virtual ~Iterator() {}
3772
3773 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
3774 return base_;
3775 }
3776 // Advance should not be called on beyond-of-range iterators
3777 // so no component iterators must be beyond end of range, either.
3778 virtual void Advance() {
3779 assert(!AtEnd());
3780 ++current6_;
3781 if (current6_ == end6_) {
3782 current6_ = begin6_;
3783 ++current5_;
3784 }
3785 if (current5_ == end5_) {
3786 current5_ = begin5_;
3787 ++current4_;
3788 }
3789 if (current4_ == end4_) {
3790 current4_ = begin4_;
3791 ++current3_;
3792 }
3793 if (current3_ == end3_) {
3794 current3_ = begin3_;
3795 ++current2_;
3796 }
3797 if (current2_ == end2_) {
3798 current2_ = begin2_;
3799 ++current1_;
3800 }
3801 ComputeCurrentValue();
3802 }
3803 virtual ParamIteratorInterface<ParamType>* Clone() const {
3804 return new Iterator(*this);
3805 }
3806 virtual const ParamType* Current() const { return &current_value_; }
3807 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
3808 // Having the same base generator guarantees that the other
3809 // iterator is of the same type and we can downcast.
3810 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
3811 << "The program attempted to compare iterators "
3812 << "from different generators." << std::endl;
3813 const Iterator* typed_other =
3814 CheckedDowncastToActualType<const Iterator>(&other);
3815 // We must report iterators equal if they both point beyond their
3816 // respective ranges. That can happen in a variety of fashions,
3817 // so we have to consult AtEnd().
3818 return (AtEnd() && typed_other->AtEnd()) ||
3819 (
3820 current1_ == typed_other->current1_ &&
3821 current2_ == typed_other->current2_ &&
3822 current3_ == typed_other->current3_ &&
3823 current4_ == typed_other->current4_ &&
3824 current5_ == typed_other->current5_ &&
3825 current6_ == typed_other->current6_);
3826 }
3827
3828 private:
3829 Iterator(const Iterator& other)
3830 : base_(other.base_),
3831 begin1_(other.begin1_),
3832 end1_(other.end1_),
3833 current1_(other.current1_),
3834 begin2_(other.begin2_),
3835 end2_(other.end2_),
3836 current2_(other.current2_),
3837 begin3_(other.begin3_),
3838 end3_(other.end3_),
3839 current3_(other.current3_),
3840 begin4_(other.begin4_),
3841 end4_(other.end4_),
3842 current4_(other.current4_),
3843 begin5_(other.begin5_),
3844 end5_(other.end5_),
3845 current5_(other.current5_),
3846 begin6_(other.begin6_),
3847 end6_(other.end6_),
3848 current6_(other.current6_) {
3849 ComputeCurrentValue();
3850 }
3851
3852 void ComputeCurrentValue() {
3853 if (!AtEnd())
3854 current_value_ = ParamType(*current1_, *current2_, *current3_,
3855 *current4_, *current5_, *current6_);
3856 }
3857 bool AtEnd() const {
3858 // We must report iterator past the end of the range when either of the
3859 // component iterators has reached the end of its range.
3860 return
3861 current1_ == end1_ ||
3862 current2_ == end2_ ||
3863 current3_ == end3_ ||
3864 current4_ == end4_ ||
3865 current5_ == end5_ ||
3866 current6_ == end6_;
3867 }
3868
3869 // No implementation - assignment is unsupported.
3870 void operator=(const Iterator& other);
3871
3872 const ParamGeneratorInterface<ParamType>* const base_;
3873 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
3874 // current[i]_ is the actual traversing iterator.
3875 const typename ParamGenerator<T1>::iterator begin1_;
3876 const typename ParamGenerator<T1>::iterator end1_;
3877 typename ParamGenerator<T1>::iterator current1_;
3878 const typename ParamGenerator<T2>::iterator begin2_;
3879 const typename ParamGenerator<T2>::iterator end2_;
3880 typename ParamGenerator<T2>::iterator current2_;
3881 const typename ParamGenerator<T3>::iterator begin3_;
3882 const typename ParamGenerator<T3>::iterator end3_;
3883 typename ParamGenerator<T3>::iterator current3_;
3884 const typename ParamGenerator<T4>::iterator begin4_;
3885 const typename ParamGenerator<T4>::iterator end4_;
3886 typename ParamGenerator<T4>::iterator current4_;
3887 const typename ParamGenerator<T5>::iterator begin5_;
3888 const typename ParamGenerator<T5>::iterator end5_;
3889 typename ParamGenerator<T5>::iterator current5_;
3890 const typename ParamGenerator<T6>::iterator begin6_;
3891 const typename ParamGenerator<T6>::iterator end6_;
3892 typename ParamGenerator<T6>::iterator current6_;
3893 ParamType current_value_;
3894 }; // class CartesianProductGenerator6::Iterator
3895
3896 // No implementation - assignment is unsupported.
3897 void operator=(const CartesianProductGenerator6& other);
3898
3899 const ParamGenerator<T1> g1_;
3900 const ParamGenerator<T2> g2_;
3901 const ParamGenerator<T3> g3_;
3902 const ParamGenerator<T4> g4_;
3903 const ParamGenerator<T5> g5_;
3904 const ParamGenerator<T6> g6_;
3905 }; // class CartesianProductGenerator6
3906
3907
3908 template <typename T1, typename T2, typename T3, typename T4, typename T5,
3909 typename T6, typename T7>
3910 class CartesianProductGenerator7
3911 : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6,
3912 T7> > {
3913 public:
3914 typedef ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7> ParamType;
3915
3916 CartesianProductGenerator7(const ParamGenerator<T1>& g1,
3917 const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,
3918 const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5,
3919 const ParamGenerator<T6>& g6, const ParamGenerator<T7>& g7)
3920 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7) {}
3921 virtual ~CartesianProductGenerator7() {}
3922
3923 virtual ParamIteratorInterface<ParamType>* Begin() const {
3924 return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,
3925 g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_,
3926 g7_.begin());
3927 }
3928 virtual ParamIteratorInterface<ParamType>* End() const {
3929 return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),
3930 g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end());
3931 }
3932
3933 private:
3934 class Iterator : public ParamIteratorInterface<ParamType> {
3935 public:
3936 Iterator(const ParamGeneratorInterface<ParamType>* base,
3937 const ParamGenerator<T1>& g1,
3938 const typename ParamGenerator<T1>::iterator& current1,
3939 const ParamGenerator<T2>& g2,
3940 const typename ParamGenerator<T2>::iterator& current2,
3941 const ParamGenerator<T3>& g3,
3942 const typename ParamGenerator<T3>::iterator& current3,
3943 const ParamGenerator<T4>& g4,
3944 const typename ParamGenerator<T4>::iterator& current4,
3945 const ParamGenerator<T5>& g5,
3946 const typename ParamGenerator<T5>::iterator& current5,
3947 const ParamGenerator<T6>& g6,
3948 const typename ParamGenerator<T6>::iterator& current6,
3949 const ParamGenerator<T7>& g7,
3950 const typename ParamGenerator<T7>::iterator& current7)
3951 : base_(base),
3952 begin1_(g1.begin()), end1_(g1.end()), current1_(current1),
3953 begin2_(g2.begin()), end2_(g2.end()), current2_(current2),
3954 begin3_(g3.begin()), end3_(g3.end()), current3_(current3),
3955 begin4_(g4.begin()), end4_(g4.end()), current4_(current4),
3956 begin5_(g5.begin()), end5_(g5.end()), current5_(current5),
3957 begin6_(g6.begin()), end6_(g6.end()), current6_(current6),
3958 begin7_(g7.begin()), end7_(g7.end()), current7_(current7) {
3959 ComputeCurrentValue();
3960 }
3961 virtual ~Iterator() {}
3962
3963 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
3964 return base_;
3965 }
3966 // Advance should not be called on beyond-of-range iterators
3967 // so no component iterators must be beyond end of range, either.
3968 virtual void Advance() {
3969 assert(!AtEnd());
3970 ++current7_;
3971 if (current7_ == end7_) {
3972 current7_ = begin7_;
3973 ++current6_;
3974 }
3975 if (current6_ == end6_) {
3976 current6_ = begin6_;
3977 ++current5_;
3978 }
3979 if (current5_ == end5_) {
3980 current5_ = begin5_;
3981 ++current4_;
3982 }
3983 if (current4_ == end4_) {
3984 current4_ = begin4_;
3985 ++current3_;
3986 }
3987 if (current3_ == end3_) {
3988 current3_ = begin3_;
3989 ++current2_;
3990 }
3991 if (current2_ == end2_) {
3992 current2_ = begin2_;
3993 ++current1_;
3994 }
3995 ComputeCurrentValue();
3996 }
3997 virtual ParamIteratorInterface<ParamType>* Clone() const {
3998 return new Iterator(*this);
3999 }
4000 virtual const ParamType* Current() const { return &current_value_; }
4001 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
4002 // Having the same base generator guarantees that the other
4003 // iterator is of the same type and we can downcast.
4004 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
4005 << "The program attempted to compare iterators "
4006 << "from different generators." << std::endl;
4007 const Iterator* typed_other =
4008 CheckedDowncastToActualType<const Iterator>(&other);
4009 // We must report iterators equal if they both point beyond their
4010 // respective ranges. That can happen in a variety of fashions,
4011 // so we have to consult AtEnd().
4012 return (AtEnd() && typed_other->AtEnd()) ||
4013 (
4014 current1_ == typed_other->current1_ &&
4015 current2_ == typed_other->current2_ &&
4016 current3_ == typed_other->current3_ &&
4017 current4_ == typed_other->current4_ &&
4018 current5_ == typed_other->current5_ &&
4019 current6_ == typed_other->current6_ &&
4020 current7_ == typed_other->current7_);
4021 }
4022
4023 private:
4024 Iterator(const Iterator& other)
4025 : base_(other.base_),
4026 begin1_(other.begin1_),
4027 end1_(other.end1_),
4028 current1_(other.current1_),
4029 begin2_(other.begin2_),
4030 end2_(other.end2_),
4031 current2_(other.current2_),
4032 begin3_(other.begin3_),
4033 end3_(other.end3_),
4034 current3_(other.current3_),
4035 begin4_(other.begin4_),
4036 end4_(other.end4_),
4037 current4_(other.current4_),
4038 begin5_(other.begin5_),
4039 end5_(other.end5_),
4040 current5_(other.current5_),
4041 begin6_(other.begin6_),
4042 end6_(other.end6_),
4043 current6_(other.current6_),
4044 begin7_(other.begin7_),
4045 end7_(other.end7_),
4046 current7_(other.current7_) {
4047 ComputeCurrentValue();
4048 }
4049
4050 void ComputeCurrentValue() {
4051 if (!AtEnd())
4052 current_value_ = ParamType(*current1_, *current2_, *current3_,
4053 *current4_, *current5_, *current6_, *current7_);
4054 }
4055 bool AtEnd() const {
4056 // We must report iterator past the end of the range when either of the
4057 // component iterators has reached the end of its range.
4058 return
4059 current1_ == end1_ ||
4060 current2_ == end2_ ||
4061 current3_ == end3_ ||
4062 current4_ == end4_ ||
4063 current5_ == end5_ ||
4064 current6_ == end6_ ||
4065 current7_ == end7_;
4066 }
4067
4068 // No implementation - assignment is unsupported.
4069 void operator=(const Iterator& other);
4070
4071 const ParamGeneratorInterface<ParamType>* const base_;
4072 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
4073 // current[i]_ is the actual traversing iterator.
4074 const typename ParamGenerator<T1>::iterator begin1_;
4075 const typename ParamGenerator<T1>::iterator end1_;
4076 typename ParamGenerator<T1>::iterator current1_;
4077 const typename ParamGenerator<T2>::iterator begin2_;
4078 const typename ParamGenerator<T2>::iterator end2_;
4079 typename ParamGenerator<T2>::iterator current2_;
4080 const typename ParamGenerator<T3>::iterator begin3_;
4081 const typename ParamGenerator<T3>::iterator end3_;
4082 typename ParamGenerator<T3>::iterator current3_;
4083 const typename ParamGenerator<T4>::iterator begin4_;
4084 const typename ParamGenerator<T4>::iterator end4_;
4085 typename ParamGenerator<T4>::iterator current4_;
4086 const typename ParamGenerator<T5>::iterator begin5_;
4087 const typename ParamGenerator<T5>::iterator end5_;
4088 typename ParamGenerator<T5>::iterator current5_;
4089 const typename ParamGenerator<T6>::iterator begin6_;
4090 const typename ParamGenerator<T6>::iterator end6_;
4091 typename ParamGenerator<T6>::iterator current6_;
4092 const typename ParamGenerator<T7>::iterator begin7_;
4093 const typename ParamGenerator<T7>::iterator end7_;
4094 typename ParamGenerator<T7>::iterator current7_;
4095 ParamType current_value_;
4096 }; // class CartesianProductGenerator7::Iterator
4097
4098 // No implementation - assignment is unsupported.
4099 void operator=(const CartesianProductGenerator7& other);
4100
4101 const ParamGenerator<T1> g1_;
4102 const ParamGenerator<T2> g2_;
4103 const ParamGenerator<T3> g3_;
4104 const ParamGenerator<T4> g4_;
4105 const ParamGenerator<T5> g5_;
4106 const ParamGenerator<T6> g6_;
4107 const ParamGenerator<T7> g7_;
4108 }; // class CartesianProductGenerator7
4109
4110
4111 template <typename T1, typename T2, typename T3, typename T4, typename T5,
4112 typename T6, typename T7, typename T8>
4113 class CartesianProductGenerator8
4114 : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6,
4115 T7, T8> > {
4116 public:
4117 typedef ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8> ParamType;
4118
4119 CartesianProductGenerator8(const ParamGenerator<T1>& g1,
4120 const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,
4121 const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5,
4122 const ParamGenerator<T6>& g6, const ParamGenerator<T7>& g7,
4123 const ParamGenerator<T8>& g8)
4124 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7),
4125 g8_(g8) {}
4126 virtual ~CartesianProductGenerator8() {}
4127
4128 virtual ParamIteratorInterface<ParamType>* Begin() const {
4129 return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,
4130 g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_,
4131 g7_.begin(), g8_, g8_.begin());
4132 }
4133 virtual ParamIteratorInterface<ParamType>* End() const {
4134 return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),
4135 g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end(), g8_,
4136 g8_.end());
4137 }
4138
4139 private:
4140 class Iterator : public ParamIteratorInterface<ParamType> {
4141 public:
4142 Iterator(const ParamGeneratorInterface<ParamType>* base,
4143 const ParamGenerator<T1>& g1,
4144 const typename ParamGenerator<T1>::iterator& current1,
4145 const ParamGenerator<T2>& g2,
4146 const typename ParamGenerator<T2>::iterator& current2,
4147 const ParamGenerator<T3>& g3,
4148 const typename ParamGenerator<T3>::iterator& current3,
4149 const ParamGenerator<T4>& g4,
4150 const typename ParamGenerator<T4>::iterator& current4,
4151 const ParamGenerator<T5>& g5,
4152 const typename ParamGenerator<T5>::iterator& current5,
4153 const ParamGenerator<T6>& g6,
4154 const typename ParamGenerator<T6>::iterator& current6,
4155 const ParamGenerator<T7>& g7,
4156 const typename ParamGenerator<T7>::iterator& current7,
4157 const ParamGenerator<T8>& g8,
4158 const typename ParamGenerator<T8>::iterator& current8)
4159 : base_(base),
4160 begin1_(g1.begin()), end1_(g1.end()), current1_(current1),
4161 begin2_(g2.begin()), end2_(g2.end()), current2_(current2),
4162 begin3_(g3.begin()), end3_(g3.end()), current3_(current3),
4163 begin4_(g4.begin()), end4_(g4.end()), current4_(current4),
4164 begin5_(g5.begin()), end5_(g5.end()), current5_(current5),
4165 begin6_(g6.begin()), end6_(g6.end()), current6_(current6),
4166 begin7_(g7.begin()), end7_(g7.end()), current7_(current7),
4167 begin8_(g8.begin()), end8_(g8.end()), current8_(current8) {
4168 ComputeCurrentValue();
4169 }
4170 virtual ~Iterator() {}
4171
4172 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
4173 return base_;
4174 }
4175 // Advance should not be called on beyond-of-range iterators
4176 // so no component iterators must be beyond end of range, either.
4177 virtual void Advance() {
4178 assert(!AtEnd());
4179 ++current8_;
4180 if (current8_ == end8_) {
4181 current8_ = begin8_;
4182 ++current7_;
4183 }
4184 if (current7_ == end7_) {
4185 current7_ = begin7_;
4186 ++current6_;
4187 }
4188 if (current6_ == end6_) {
4189 current6_ = begin6_;
4190 ++current5_;
4191 }
4192 if (current5_ == end5_) {
4193 current5_ = begin5_;
4194 ++current4_;
4195 }
4196 if (current4_ == end4_) {
4197 current4_ = begin4_;
4198 ++current3_;
4199 }
4200 if (current3_ == end3_) {
4201 current3_ = begin3_;
4202 ++current2_;
4203 }
4204 if (current2_ == end2_) {
4205 current2_ = begin2_;
4206 ++current1_;
4207 }
4208 ComputeCurrentValue();
4209 }
4210 virtual ParamIteratorInterface<ParamType>* Clone() const {
4211 return new Iterator(*this);
4212 }
4213 virtual const ParamType* Current() const { return &current_value_; }
4214 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
4215 // Having the same base generator guarantees that the other
4216 // iterator is of the same type and we can downcast.
4217 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
4218 << "The program attempted to compare iterators "
4219 << "from different generators." << std::endl;
4220 const Iterator* typed_other =
4221 CheckedDowncastToActualType<const Iterator>(&other);
4222 // We must report iterators equal if they both point beyond their
4223 // respective ranges. That can happen in a variety of fashions,
4224 // so we have to consult AtEnd().
4225 return (AtEnd() && typed_other->AtEnd()) ||
4226 (
4227 current1_ == typed_other->current1_ &&
4228 current2_ == typed_other->current2_ &&
4229 current3_ == typed_other->current3_ &&
4230 current4_ == typed_other->current4_ &&
4231 current5_ == typed_other->current5_ &&
4232 current6_ == typed_other->current6_ &&
4233 current7_ == typed_other->current7_ &&
4234 current8_ == typed_other->current8_);
4235 }
4236
4237 private:
4238 Iterator(const Iterator& other)
4239 : base_(other.base_),
4240 begin1_(other.begin1_),
4241 end1_(other.end1_),
4242 current1_(other.current1_),
4243 begin2_(other.begin2_),
4244 end2_(other.end2_),
4245 current2_(other.current2_),
4246 begin3_(other.begin3_),
4247 end3_(other.end3_),
4248 current3_(other.current3_),
4249 begin4_(other.begin4_),
4250 end4_(other.end4_),
4251 current4_(other.current4_),
4252 begin5_(other.begin5_),
4253 end5_(other.end5_),
4254 current5_(other.current5_),
4255 begin6_(other.begin6_),
4256 end6_(other.end6_),
4257 current6_(other.current6_),
4258 begin7_(other.begin7_),
4259 end7_(other.end7_),
4260 current7_(other.current7_),
4261 begin8_(other.begin8_),
4262 end8_(other.end8_),
4263 current8_(other.current8_) {
4264 ComputeCurrentValue();
4265 }
4266
4267 void ComputeCurrentValue() {
4268 if (!AtEnd())
4269 current_value_ = ParamType(*current1_, *current2_, *current3_,
4270 *current4_, *current5_, *current6_, *current7_, *current8_);
4271 }
4272 bool AtEnd() const {
4273 // We must report iterator past the end of the range when either of the
4274 // component iterators has reached the end of its range.
4275 return
4276 current1_ == end1_ ||
4277 current2_ == end2_ ||
4278 current3_ == end3_ ||
4279 current4_ == end4_ ||
4280 current5_ == end5_ ||
4281 current6_ == end6_ ||
4282 current7_ == end7_ ||
4283 current8_ == end8_;
4284 }
4285
4286 // No implementation - assignment is unsupported.
4287 void operator=(const Iterator& other);
4288
4289 const ParamGeneratorInterface<ParamType>* const base_;
4290 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
4291 // current[i]_ is the actual traversing iterator.
4292 const typename ParamGenerator<T1>::iterator begin1_;
4293 const typename ParamGenerator<T1>::iterator end1_;
4294 typename ParamGenerator<T1>::iterator current1_;
4295 const typename ParamGenerator<T2>::iterator begin2_;
4296 const typename ParamGenerator<T2>::iterator end2_;
4297 typename ParamGenerator<T2>::iterator current2_;
4298 const typename ParamGenerator<T3>::iterator begin3_;
4299 const typename ParamGenerator<T3>::iterator end3_;
4300 typename ParamGenerator<T3>::iterator current3_;
4301 const typename ParamGenerator<T4>::iterator begin4_;
4302 const typename ParamGenerator<T4>::iterator end4_;
4303 typename ParamGenerator<T4>::iterator current4_;
4304 const typename ParamGenerator<T5>::iterator begin5_;
4305 const typename ParamGenerator<T5>::iterator end5_;
4306 typename ParamGenerator<T5>::iterator current5_;
4307 const typename ParamGenerator<T6>::iterator begin6_;
4308 const typename ParamGenerator<T6>::iterator end6_;
4309 typename ParamGenerator<T6>::iterator current6_;
4310 const typename ParamGenerator<T7>::iterator begin7_;
4311 const typename ParamGenerator<T7>::iterator end7_;
4312 typename ParamGenerator<T7>::iterator current7_;
4313 const typename ParamGenerator<T8>::iterator begin8_;
4314 const typename ParamGenerator<T8>::iterator end8_;
4315 typename ParamGenerator<T8>::iterator current8_;
4316 ParamType current_value_;
4317 }; // class CartesianProductGenerator8::Iterator
4318
4319 // No implementation - assignment is unsupported.
4320 void operator=(const CartesianProductGenerator8& other);
4321
4322 const ParamGenerator<T1> g1_;
4323 const ParamGenerator<T2> g2_;
4324 const ParamGenerator<T3> g3_;
4325 const ParamGenerator<T4> g4_;
4326 const ParamGenerator<T5> g5_;
4327 const ParamGenerator<T6> g6_;
4328 const ParamGenerator<T7> g7_;
4329 const ParamGenerator<T8> g8_;
4330 }; // class CartesianProductGenerator8
4331
4332
4333 template <typename T1, typename T2, typename T3, typename T4, typename T5,
4334 typename T6, typename T7, typename T8, typename T9>
4335 class CartesianProductGenerator9
4336 : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6,
4337 T7, T8, T9> > {
4338 public:
4339 typedef ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> ParamType;
4340
4341 CartesianProductGenerator9(const ParamGenerator<T1>& g1,
4342 const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,
4343 const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5,
4344 const ParamGenerator<T6>& g6, const ParamGenerator<T7>& g7,
4345 const ParamGenerator<T8>& g8, const ParamGenerator<T9>& g9)
4346 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8),
4347 g9_(g9) {}
4348 virtual ~CartesianProductGenerator9() {}
4349
4350 virtual ParamIteratorInterface<ParamType>* Begin() const {
4351 return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,
4352 g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_,
4353 g7_.begin(), g8_, g8_.begin(), g9_, g9_.begin());
4354 }
4355 virtual ParamIteratorInterface<ParamType>* End() const {
4356 return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),
4357 g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end(), g8_,
4358 g8_.end(), g9_, g9_.end());
4359 }
4360
4361 private:
4362 class Iterator : public ParamIteratorInterface<ParamType> {
4363 public:
4364 Iterator(const ParamGeneratorInterface<ParamType>* base,
4365 const ParamGenerator<T1>& g1,
4366 const typename ParamGenerator<T1>::iterator& current1,
4367 const ParamGenerator<T2>& g2,
4368 const typename ParamGenerator<T2>::iterator& current2,
4369 const ParamGenerator<T3>& g3,
4370 const typename ParamGenerator<T3>::iterator& current3,
4371 const ParamGenerator<T4>& g4,
4372 const typename ParamGenerator<T4>::iterator& current4,
4373 const ParamGenerator<T5>& g5,
4374 const typename ParamGenerator<T5>::iterator& current5,
4375 const ParamGenerator<T6>& g6,
4376 const typename ParamGenerator<T6>::iterator& current6,
4377 const ParamGenerator<T7>& g7,
4378 const typename ParamGenerator<T7>::iterator& current7,
4379 const ParamGenerator<T8>& g8,
4380 const typename ParamGenerator<T8>::iterator& current8,
4381 const ParamGenerator<T9>& g9,
4382 const typename ParamGenerator<T9>::iterator& current9)
4383 : base_(base),
4384 begin1_(g1.begin()), end1_(g1.end()), current1_(current1),
4385 begin2_(g2.begin()), end2_(g2.end()), current2_(current2),
4386 begin3_(g3.begin()), end3_(g3.end()), current3_(current3),
4387 begin4_(g4.begin()), end4_(g4.end()), current4_(current4),
4388 begin5_(g5.begin()), end5_(g5.end()), current5_(current5),
4389 begin6_(g6.begin()), end6_(g6.end()), current6_(current6),
4390 begin7_(g7.begin()), end7_(g7.end()), current7_(current7),
4391 begin8_(g8.begin()), end8_(g8.end()), current8_(current8),
4392 begin9_(g9.begin()), end9_(g9.end()), current9_(current9) {
4393 ComputeCurrentValue();
4394 }
4395 virtual ~Iterator() {}
4396
4397 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
4398 return base_;
4399 }
4400 // Advance should not be called on beyond-of-range iterators
4401 // so no component iterators must be beyond end of range, either.
4402 virtual void Advance() {
4403 assert(!AtEnd());
4404 ++current9_;
4405 if (current9_ == end9_) {
4406 current9_ = begin9_;
4407 ++current8_;
4408 }
4409 if (current8_ == end8_) {
4410 current8_ = begin8_;
4411 ++current7_;
4412 }
4413 if (current7_ == end7_) {
4414 current7_ = begin7_;
4415 ++current6_;
4416 }
4417 if (current6_ == end6_) {
4418 current6_ = begin6_;
4419 ++current5_;
4420 }
4421 if (current5_ == end5_) {
4422 current5_ = begin5_;
4423 ++current4_;
4424 }
4425 if (current4_ == end4_) {
4426 current4_ = begin4_;
4427 ++current3_;
4428 }
4429 if (current3_ == end3_) {
4430 current3_ = begin3_;
4431 ++current2_;
4432 }
4433 if (current2_ == end2_) {
4434 current2_ = begin2_;
4435 ++current1_;
4436 }
4437 ComputeCurrentValue();
4438 }
4439 virtual ParamIteratorInterface<ParamType>* Clone() const {
4440 return new Iterator(*this);
4441 }
4442 virtual const ParamType* Current() const { return &current_value_; }
4443 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
4444 // Having the same base generator guarantees that the other
4445 // iterator is of the same type and we can downcast.
4446 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
4447 << "The program attempted to compare iterators "
4448 << "from different generators." << std::endl;
4449 const Iterator* typed_other =
4450 CheckedDowncastToActualType<const Iterator>(&other);
4451 // We must report iterators equal if they both point beyond their
4452 // respective ranges. That can happen in a variety of fashions,
4453 // so we have to consult AtEnd().
4454 return (AtEnd() && typed_other->AtEnd()) ||
4455 (
4456 current1_ == typed_other->current1_ &&
4457 current2_ == typed_other->current2_ &&
4458 current3_ == typed_other->current3_ &&
4459 current4_ == typed_other->current4_ &&
4460 current5_ == typed_other->current5_ &&
4461 current6_ == typed_other->current6_ &&
4462 current7_ == typed_other->current7_ &&
4463 current8_ == typed_other->current8_ &&
4464 current9_ == typed_other->current9_);
4465 }
4466
4467 private:
4468 Iterator(const Iterator& other)
4469 : base_(other.base_),
4470 begin1_(other.begin1_),
4471 end1_(other.end1_),
4472 current1_(other.current1_),
4473 begin2_(other.begin2_),
4474 end2_(other.end2_),
4475 current2_(other.current2_),
4476 begin3_(other.begin3_),
4477 end3_(other.end3_),
4478 current3_(other.current3_),
4479 begin4_(other.begin4_),
4480 end4_(other.end4_),
4481 current4_(other.current4_),
4482 begin5_(other.begin5_),
4483 end5_(other.end5_),
4484 current5_(other.current5_),
4485 begin6_(other.begin6_),
4486 end6_(other.end6_),
4487 current6_(other.current6_),
4488 begin7_(other.begin7_),
4489 end7_(other.end7_),
4490 current7_(other.current7_),
4491 begin8_(other.begin8_),
4492 end8_(other.end8_),
4493 current8_(other.current8_),
4494 begin9_(other.begin9_),
4495 end9_(other.end9_),
4496 current9_(other.current9_) {
4497 ComputeCurrentValue();
4498 }
4499
4500 void ComputeCurrentValue() {
4501 if (!AtEnd())
4502 current_value_ = ParamType(*current1_, *current2_, *current3_,
4503 *current4_, *current5_, *current6_, *current7_, *current8_,
4504 *current9_);
4505 }
4506 bool AtEnd() const {
4507 // We must report iterator past the end of the range when either of the
4508 // component iterators has reached the end of its range.
4509 return
4510 current1_ == end1_ ||
4511 current2_ == end2_ ||
4512 current3_ == end3_ ||
4513 current4_ == end4_ ||
4514 current5_ == end5_ ||
4515 current6_ == end6_ ||
4516 current7_ == end7_ ||
4517 current8_ == end8_ ||
4518 current9_ == end9_;
4519 }
4520
4521 // No implementation - assignment is unsupported.
4522 void operator=(const Iterator& other);
4523
4524 const ParamGeneratorInterface<ParamType>* const base_;
4525 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
4526 // current[i]_ is the actual traversing iterator.
4527 const typename ParamGenerator<T1>::iterator begin1_;
4528 const typename ParamGenerator<T1>::iterator end1_;
4529 typename ParamGenerator<T1>::iterator current1_;
4530 const typename ParamGenerator<T2>::iterator begin2_;
4531 const typename ParamGenerator<T2>::iterator end2_;
4532 typename ParamGenerator<T2>::iterator current2_;
4533 const typename ParamGenerator<T3>::iterator begin3_;
4534 const typename ParamGenerator<T3>::iterator end3_;
4535 typename ParamGenerator<T3>::iterator current3_;
4536 const typename ParamGenerator<T4>::iterator begin4_;
4537 const typename ParamGenerator<T4>::iterator end4_;
4538 typename ParamGenerator<T4>::iterator current4_;
4539 const typename ParamGenerator<T5>::iterator begin5_;
4540 const typename ParamGenerator<T5>::iterator end5_;
4541 typename ParamGenerator<T5>::iterator current5_;
4542 const typename ParamGenerator<T6>::iterator begin6_;
4543 const typename ParamGenerator<T6>::iterator end6_;
4544 typename ParamGenerator<T6>::iterator current6_;
4545 const typename ParamGenerator<T7>::iterator begin7_;
4546 const typename ParamGenerator<T7>::iterator end7_;
4547 typename ParamGenerator<T7>::iterator current7_;
4548 const typename ParamGenerator<T8>::iterator begin8_;
4549 const typename ParamGenerator<T8>::iterator end8_;
4550 typename ParamGenerator<T8>::iterator current8_;
4551 const typename ParamGenerator<T9>::iterator begin9_;
4552 const typename ParamGenerator<T9>::iterator end9_;
4553 typename ParamGenerator<T9>::iterator current9_;
4554 ParamType current_value_;
4555 }; // class CartesianProductGenerator9::Iterator
4556
4557 // No implementation - assignment is unsupported.
4558 void operator=(const CartesianProductGenerator9& other);
4559
4560 const ParamGenerator<T1> g1_;
4561 const ParamGenerator<T2> g2_;
4562 const ParamGenerator<T3> g3_;
4563 const ParamGenerator<T4> g4_;
4564 const ParamGenerator<T5> g5_;
4565 const ParamGenerator<T6> g6_;
4566 const ParamGenerator<T7> g7_;
4567 const ParamGenerator<T8> g8_;
4568 const ParamGenerator<T9> g9_;
4569 }; // class CartesianProductGenerator9
4570
4571
4572 template <typename T1, typename T2, typename T3, typename T4, typename T5,
4573 typename T6, typename T7, typename T8, typename T9, typename T10>
4574 class CartesianProductGenerator10
4575 : public ParamGeneratorInterface< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6,
4576 T7, T8, T9, T10> > {
4577 public:
4578 typedef ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> ParamType;
4579
4580 CartesianProductGenerator10(const ParamGenerator<T1>& g1,
4581 const ParamGenerator<T2>& g2, const ParamGenerator<T3>& g3,
4582 const ParamGenerator<T4>& g4, const ParamGenerator<T5>& g5,
4583 const ParamGenerator<T6>& g6, const ParamGenerator<T7>& g7,
4584 const ParamGenerator<T8>& g8, const ParamGenerator<T9>& g9,
4585 const ParamGenerator<T10>& g10)
4586 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8),
4587 g9_(g9), g10_(g10) {}
4588 virtual ~CartesianProductGenerator10() {}
4589
4590 virtual ParamIteratorInterface<ParamType>* Begin() const {
4591 return new Iterator(this, g1_, g1_.begin(), g2_, g2_.begin(), g3_,
4592 g3_.begin(), g4_, g4_.begin(), g5_, g5_.begin(), g6_, g6_.begin(), g7_,
4593 g7_.begin(), g8_, g8_.begin(), g9_, g9_.begin(), g10_, g10_.begin());
4594 }
4595 virtual ParamIteratorInterface<ParamType>* End() const {
4596 return new Iterator(this, g1_, g1_.end(), g2_, g2_.end(), g3_, g3_.end(),
4597 g4_, g4_.end(), g5_, g5_.end(), g6_, g6_.end(), g7_, g7_.end(), g8_,
4598 g8_.end(), g9_, g9_.end(), g10_, g10_.end());
4599 }
4600
4601 private:
4602 class Iterator : public ParamIteratorInterface<ParamType> {
4603 public:
4604 Iterator(const ParamGeneratorInterface<ParamType>* base,
4605 const ParamGenerator<T1>& g1,
4606 const typename ParamGenerator<T1>::iterator& current1,
4607 const ParamGenerator<T2>& g2,
4608 const typename ParamGenerator<T2>::iterator& current2,
4609 const ParamGenerator<T3>& g3,
4610 const typename ParamGenerator<T3>::iterator& current3,
4611 const ParamGenerator<T4>& g4,
4612 const typename ParamGenerator<T4>::iterator& current4,
4613 const ParamGenerator<T5>& g5,
4614 const typename ParamGenerator<T5>::iterator& current5,
4615 const ParamGenerator<T6>& g6,
4616 const typename ParamGenerator<T6>::iterator& current6,
4617 const ParamGenerator<T7>& g7,
4618 const typename ParamGenerator<T7>::iterator& current7,
4619 const ParamGenerator<T8>& g8,
4620 const typename ParamGenerator<T8>::iterator& current8,
4621 const ParamGenerator<T9>& g9,
4622 const typename ParamGenerator<T9>::iterator& current9,
4623 const ParamGenerator<T10>& g10,
4624 const typename ParamGenerator<T10>::iterator& current10)
4625 : base_(base),
4626 begin1_(g1.begin()), end1_(g1.end()), current1_(current1),
4627 begin2_(g2.begin()), end2_(g2.end()), current2_(current2),
4628 begin3_(g3.begin()), end3_(g3.end()), current3_(current3),
4629 begin4_(g4.begin()), end4_(g4.end()), current4_(current4),
4630 begin5_(g5.begin()), end5_(g5.end()), current5_(current5),
4631 begin6_(g6.begin()), end6_(g6.end()), current6_(current6),
4632 begin7_(g7.begin()), end7_(g7.end()), current7_(current7),
4633 begin8_(g8.begin()), end8_(g8.end()), current8_(current8),
4634 begin9_(g9.begin()), end9_(g9.end()), current9_(current9),
4635 begin10_(g10.begin()), end10_(g10.end()), current10_(current10) {
4636 ComputeCurrentValue();
4637 }
4638 virtual ~Iterator() {}
4639
4640 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
4641 return base_;
4642 }
4643 // Advance should not be called on beyond-of-range iterators
4644 // so no component iterators must be beyond end of range, either.
4645 virtual void Advance() {
4646 assert(!AtEnd());
4647 ++current10_;
4648 if (current10_ == end10_) {
4649 current10_ = begin10_;
4650 ++current9_;
4651 }
4652 if (current9_ == end9_) {
4653 current9_ = begin9_;
4654 ++current8_;
4655 }
4656 if (current8_ == end8_) {
4657 current8_ = begin8_;
4658 ++current7_;
4659 }
4660 if (current7_ == end7_) {
4661 current7_ = begin7_;
4662 ++current6_;
4663 }
4664 if (current6_ == end6_) {
4665 current6_ = begin6_;
4666 ++current5_;
4667 }
4668 if (current5_ == end5_) {
4669 current5_ = begin5_;
4670 ++current4_;
4671 }
4672 if (current4_ == end4_) {
4673 current4_ = begin4_;
4674 ++current3_;
4675 }
4676 if (current3_ == end3_) {
4677 current3_ = begin3_;
4678 ++current2_;
4679 }
4680 if (current2_ == end2_) {
4681 current2_ = begin2_;
4682 ++current1_;
4683 }
4684 ComputeCurrentValue();
4685 }
4686 virtual ParamIteratorInterface<ParamType>* Clone() const {
4687 return new Iterator(*this);
4688 }
4689 virtual const ParamType* Current() const { return &current_value_; }
4690 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
4691 // Having the same base generator guarantees that the other
4692 // iterator is of the same type and we can downcast.
4693 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
4694 << "The program attempted to compare iterators "
4695 << "from different generators." << std::endl;
4696 const Iterator* typed_other =
4697 CheckedDowncastToActualType<const Iterator>(&other);
4698 // We must report iterators equal if they both point beyond their
4699 // respective ranges. That can happen in a variety of fashions,
4700 // so we have to consult AtEnd().
4701 return (AtEnd() && typed_other->AtEnd()) ||
4702 (
4703 current1_ == typed_other->current1_ &&
4704 current2_ == typed_other->current2_ &&
4705 current3_ == typed_other->current3_ &&
4706 current4_ == typed_other->current4_ &&
4707 current5_ == typed_other->current5_ &&
4708 current6_ == typed_other->current6_ &&
4709 current7_ == typed_other->current7_ &&
4710 current8_ == typed_other->current8_ &&
4711 current9_ == typed_other->current9_ &&
4712 current10_ == typed_other->current10_);
4713 }
4714
4715 private:
4716 Iterator(const Iterator& other)
4717 : base_(other.base_),
4718 begin1_(other.begin1_),
4719 end1_(other.end1_),
4720 current1_(other.current1_),
4721 begin2_(other.begin2_),
4722 end2_(other.end2_),
4723 current2_(other.current2_),
4724 begin3_(other.begin3_),
4725 end3_(other.end3_),
4726 current3_(other.current3_),
4727 begin4_(other.begin4_),
4728 end4_(other.end4_),
4729 current4_(other.current4_),
4730 begin5_(other.begin5_),
4731 end5_(other.end5_),
4732 current5_(other.current5_),
4733 begin6_(other.begin6_),
4734 end6_(other.end6_),
4735 current6_(other.current6_),
4736 begin7_(other.begin7_),
4737 end7_(other.end7_),
4738 current7_(other.current7_),
4739 begin8_(other.begin8_),
4740 end8_(other.end8_),
4741 current8_(other.current8_),
4742 begin9_(other.begin9_),
4743 end9_(other.end9_),
4744 current9_(other.current9_),
4745 begin10_(other.begin10_),
4746 end10_(other.end10_),
4747 current10_(other.current10_) {
4748 ComputeCurrentValue();
4749 }
4750
4751 void ComputeCurrentValue() {
4752 if (!AtEnd())
4753 current_value_ = ParamType(*current1_, *current2_, *current3_,
4754 *current4_, *current5_, *current6_, *current7_, *current8_,
4755 *current9_, *current10_);
4756 }
4757 bool AtEnd() const {
4758 // We must report iterator past the end of the range when either of the
4759 // component iterators has reached the end of its range.
4760 return
4761 current1_ == end1_ ||
4762 current2_ == end2_ ||
4763 current3_ == end3_ ||
4764 current4_ == end4_ ||
4765 current5_ == end5_ ||
4766 current6_ == end6_ ||
4767 current7_ == end7_ ||
4768 current8_ == end8_ ||
4769 current9_ == end9_ ||
4770 current10_ == end10_;
4771 }
4772
4773 // No implementation - assignment is unsupported.
4774 void operator=(const Iterator& other);
4775
4776 const ParamGeneratorInterface<ParamType>* const base_;
4777 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
4778 // current[i]_ is the actual traversing iterator.
4779 const typename ParamGenerator<T1>::iterator begin1_;
4780 const typename ParamGenerator<T1>::iterator end1_;
4781 typename ParamGenerator<T1>::iterator current1_;
4782 const typename ParamGenerator<T2>::iterator begin2_;
4783 const typename ParamGenerator<T2>::iterator end2_;
4784 typename ParamGenerator<T2>::iterator current2_;
4785 const typename ParamGenerator<T3>::iterator begin3_;
4786 const typename ParamGenerator<T3>::iterator end3_;
4787 typename ParamGenerator<T3>::iterator current3_;
4788 const typename ParamGenerator<T4>::iterator begin4_;
4789 const typename ParamGenerator<T4>::iterator end4_;
4790 typename ParamGenerator<T4>::iterator current4_;
4791 const typename ParamGenerator<T5>::iterator begin5_;
4792 const typename ParamGenerator<T5>::iterator end5_;
4793 typename ParamGenerator<T5>::iterator current5_;
4794 const typename ParamGenerator<T6>::iterator begin6_;
4795 const typename ParamGenerator<T6>::iterator end6_;
4796 typename ParamGenerator<T6>::iterator current6_;
4797 const typename ParamGenerator<T7>::iterator begin7_;
4798 const typename ParamGenerator<T7>::iterator end7_;
4799 typename ParamGenerator<T7>::iterator current7_;
4800 const typename ParamGenerator<T8>::iterator begin8_;
4801 const typename ParamGenerator<T8>::iterator end8_;
4802 typename ParamGenerator<T8>::iterator current8_;
4803 const typename ParamGenerator<T9>::iterator begin9_;
4804 const typename ParamGenerator<T9>::iterator end9_;
4805 typename ParamGenerator<T9>::iterator current9_;
4806 const typename ParamGenerator<T10>::iterator begin10_;
4807 const typename ParamGenerator<T10>::iterator end10_;
4808 typename ParamGenerator<T10>::iterator current10_;
4809 ParamType current_value_;
4810 }; // class CartesianProductGenerator10::Iterator
4811
4812 // No implementation - assignment is unsupported.
4813 void operator=(const CartesianProductGenerator10& other);
4814
4815 const ParamGenerator<T1> g1_;
4816 const ParamGenerator<T2> g2_;
4817 const ParamGenerator<T3> g3_;
4818 const ParamGenerator<T4> g4_;
4819 const ParamGenerator<T5> g5_;
4820 const ParamGenerator<T6> g6_;
4821 const ParamGenerator<T7> g7_;
4822 const ParamGenerator<T8> g8_;
4823 const ParamGenerator<T9> g9_;
4824 const ParamGenerator<T10> g10_;
4825 }; // class CartesianProductGenerator10
4826
4827
4828 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
4829 //
4830 // Helper classes providing Combine() with polymorphic features. They allow
4831 // casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is
4832 // convertible to U.
4833 //
4834 template <class Generator1, class Generator2>
4835 class CartesianProductHolder2 {
4836 public:
4837 CartesianProductHolder2(const Generator1& g1, const Generator2& g2)
4838 : g1_(g1), g2_(g2) {}
4839 template <typename T1, typename T2>
4840 operator ParamGenerator< ::std::tr1::tuple<T1, T2> >() const {
4841 return ParamGenerator< ::std::tr1::tuple<T1, T2> >(
4842 new CartesianProductGenerator2<T1, T2>(
4843 static_cast<ParamGenerator<T1> >(g1_),
4844 static_cast<ParamGenerator<T2> >(g2_)));
4845 }
4846
4847 private:
4848 // No implementation - assignment is unsupported.
4849 void operator=(const CartesianProductHolder2& other);
4850
4851 const Generator1 g1_;
4852 const Generator2 g2_;
4853 }; // class CartesianProductHolder2
4854
4855 template <class Generator1, class Generator2, class Generator3>
4856 class CartesianProductHolder3 {
4857 public:
4858 CartesianProductHolder3(const Generator1& g1, const Generator2& g2,
4859 const Generator3& g3)
4860 : g1_(g1), g2_(g2), g3_(g3) {}
4861 template <typename T1, typename T2, typename T3>
4862 operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3> >() const {
4863 return ParamGenerator< ::std::tr1::tuple<T1, T2, T3> >(
4864 new CartesianProductGenerator3<T1, T2, T3>(
4865 static_cast<ParamGenerator<T1> >(g1_),
4866 static_cast<ParamGenerator<T2> >(g2_),
4867 static_cast<ParamGenerator<T3> >(g3_)));
4868 }
4869
4870 private:
4871 // No implementation - assignment is unsupported.
4872 void operator=(const CartesianProductHolder3& other);
4873
4874 const Generator1 g1_;
4875 const Generator2 g2_;
4876 const Generator3 g3_;
4877 }; // class CartesianProductHolder3
4878
4879 template <class Generator1, class Generator2, class Generator3,
4880 class Generator4>
4881 class CartesianProductHolder4 {
4882 public:
4883 CartesianProductHolder4(const Generator1& g1, const Generator2& g2,
4884 const Generator3& g3, const Generator4& g4)
4885 : g1_(g1), g2_(g2), g3_(g3), g4_(g4) {}
4886 template <typename T1, typename T2, typename T3, typename T4>
4887 operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4> >() const {
4888 return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4> >(
4889 new CartesianProductGenerator4<T1, T2, T3, T4>(
4890 static_cast<ParamGenerator<T1> >(g1_),
4891 static_cast<ParamGenerator<T2> >(g2_),
4892 static_cast<ParamGenerator<T3> >(g3_),
4893 static_cast<ParamGenerator<T4> >(g4_)));
4894 }
4895
4896 private:
4897 // No implementation - assignment is unsupported.
4898 void operator=(const CartesianProductHolder4& other);
4899
4900 const Generator1 g1_;
4901 const Generator2 g2_;
4902 const Generator3 g3_;
4903 const Generator4 g4_;
4904 }; // class CartesianProductHolder4
4905
4906 template <class Generator1, class Generator2, class Generator3,
4907 class Generator4, class Generator5>
4908 class CartesianProductHolder5 {
4909 public:
4910 CartesianProductHolder5(const Generator1& g1, const Generator2& g2,
4911 const Generator3& g3, const Generator4& g4, const Generator5& g5)
4912 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5) {}
4913 template <typename T1, typename T2, typename T3, typename T4, typename T5>
4914 operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5> >() const {
4915 return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5> >(
4916 new CartesianProductGenerator5<T1, T2, T3, T4, T5>(
4917 static_cast<ParamGenerator<T1> >(g1_),
4918 static_cast<ParamGenerator<T2> >(g2_),
4919 static_cast<ParamGenerator<T3> >(g3_),
4920 static_cast<ParamGenerator<T4> >(g4_),
4921 static_cast<ParamGenerator<T5> >(g5_)));
4922 }
4923
4924 private:
4925 // No implementation - assignment is unsupported.
4926 void operator=(const CartesianProductHolder5& other);
4927
4928 const Generator1 g1_;
4929 const Generator2 g2_;
4930 const Generator3 g3_;
4931 const Generator4 g4_;
4932 const Generator5 g5_;
4933 }; // class CartesianProductHolder5
4934
4935 template <class Generator1, class Generator2, class Generator3,
4936 class Generator4, class Generator5, class Generator6>
4937 class CartesianProductHolder6 {
4938 public:
4939 CartesianProductHolder6(const Generator1& g1, const Generator2& g2,
4940 const Generator3& g3, const Generator4& g4, const Generator5& g5,
4941 const Generator6& g6)
4942 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6) {}
4943 template <typename T1, typename T2, typename T3, typename T4, typename T5,
4944 typename T6>
4945 operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6> >() const {
4946 return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6> >(
4947 new CartesianProductGenerator6<T1, T2, T3, T4, T5, T6>(
4948 static_cast<ParamGenerator<T1> >(g1_),
4949 static_cast<ParamGenerator<T2> >(g2_),
4950 static_cast<ParamGenerator<T3> >(g3_),
4951 static_cast<ParamGenerator<T4> >(g4_),
4952 static_cast<ParamGenerator<T5> >(g5_),
4953 static_cast<ParamGenerator<T6> >(g6_)));
4954 }
4955
4956 private:
4957 // No implementation - assignment is unsupported.
4958 void operator=(const CartesianProductHolder6& other);
4959
4960 const Generator1 g1_;
4961 const Generator2 g2_;
4962 const Generator3 g3_;
4963 const Generator4 g4_;
4964 const Generator5 g5_;
4965 const Generator6 g6_;
4966 }; // class CartesianProductHolder6
4967
4968 template <class Generator1, class Generator2, class Generator3,
4969 class Generator4, class Generator5, class Generator6, class Generator7>
4970 class CartesianProductHolder7 {
4971 public:
4972 CartesianProductHolder7(const Generator1& g1, const Generator2& g2,
4973 const Generator3& g3, const Generator4& g4, const Generator5& g5,
4974 const Generator6& g6, const Generator7& g7)
4975 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7) {}
4976 template <typename T1, typename T2, typename T3, typename T4, typename T5,
4977 typename T6, typename T7>
4978 operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6,
4979 T7> >() const {
4980 return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7> >(
4981 new CartesianProductGenerator7<T1, T2, T3, T4, T5, T6, T7>(
4982 static_cast<ParamGenerator<T1> >(g1_),
4983 static_cast<ParamGenerator<T2> >(g2_),
4984 static_cast<ParamGenerator<T3> >(g3_),
4985 static_cast<ParamGenerator<T4> >(g4_),
4986 static_cast<ParamGenerator<T5> >(g5_),
4987 static_cast<ParamGenerator<T6> >(g6_),
4988 static_cast<ParamGenerator<T7> >(g7_)));
4989 }
4990
4991 private:
4992 // No implementation - assignment is unsupported.
4993 void operator=(const CartesianProductHolder7& other);
4994
4995 const Generator1 g1_;
4996 const Generator2 g2_;
4997 const Generator3 g3_;
4998 const Generator4 g4_;
4999 const Generator5 g5_;
5000 const Generator6 g6_;
5001 const Generator7 g7_;
5002 }; // class CartesianProductHolder7
5003
5004 template <class Generator1, class Generator2, class Generator3,
5005 class Generator4, class Generator5, class Generator6, class Generator7,
5006 class Generator8>
5007 class CartesianProductHolder8 {
5008 public:
5009 CartesianProductHolder8(const Generator1& g1, const Generator2& g2,
5010 const Generator3& g3, const Generator4& g4, const Generator5& g5,
5011 const Generator6& g6, const Generator7& g7, const Generator8& g8)
5012 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7),
5013 g8_(g8) {}
5014 template <typename T1, typename T2, typename T3, typename T4, typename T5,
5015 typename T6, typename T7, typename T8>
5016 operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7,
5017 T8> >() const {
5018 return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8> >(
5019 new CartesianProductGenerator8<T1, T2, T3, T4, T5, T6, T7, T8>(
5020 static_cast<ParamGenerator<T1> >(g1_),
5021 static_cast<ParamGenerator<T2> >(g2_),
5022 static_cast<ParamGenerator<T3> >(g3_),
5023 static_cast<ParamGenerator<T4> >(g4_),
5024 static_cast<ParamGenerator<T5> >(g5_),
5025 static_cast<ParamGenerator<T6> >(g6_),
5026 static_cast<ParamGenerator<T7> >(g7_),
5027 static_cast<ParamGenerator<T8> >(g8_)));
5028 }
5029
5030 private:
5031 // No implementation - assignment is unsupported.
5032 void operator=(const CartesianProductHolder8& other);
5033
5034 const Generator1 g1_;
5035 const Generator2 g2_;
5036 const Generator3 g3_;
5037 const Generator4 g4_;
5038 const Generator5 g5_;
5039 const Generator6 g6_;
5040 const Generator7 g7_;
5041 const Generator8 g8_;
5042 }; // class CartesianProductHolder8
5043
5044 template <class Generator1, class Generator2, class Generator3,
5045 class Generator4, class Generator5, class Generator6, class Generator7,
5046 class Generator8, class Generator9>
5047 class CartesianProductHolder9 {
5048 public:
5049 CartesianProductHolder9(const Generator1& g1, const Generator2& g2,
5050 const Generator3& g3, const Generator4& g4, const Generator5& g5,
5051 const Generator6& g6, const Generator7& g7, const Generator8& g8,
5052 const Generator9& g9)
5053 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8),
5054 g9_(g9) {}
5055 template <typename T1, typename T2, typename T3, typename T4, typename T5,
5056 typename T6, typename T7, typename T8, typename T9>
5057 operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8,
5058 T9> >() const {
5059 return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8,
5060 T9> >(
5061 new CartesianProductGenerator9<T1, T2, T3, T4, T5, T6, T7, T8, T9>(
5062 static_cast<ParamGenerator<T1> >(g1_),
5063 static_cast<ParamGenerator<T2> >(g2_),
5064 static_cast<ParamGenerator<T3> >(g3_),
5065 static_cast<ParamGenerator<T4> >(g4_),
5066 static_cast<ParamGenerator<T5> >(g5_),
5067 static_cast<ParamGenerator<T6> >(g6_),
5068 static_cast<ParamGenerator<T7> >(g7_),
5069 static_cast<ParamGenerator<T8> >(g8_),
5070 static_cast<ParamGenerator<T9> >(g9_)));
5071 }
5072
5073 private:
5074 // No implementation - assignment is unsupported.
5075 void operator=(const CartesianProductHolder9& other);
5076
5077 const Generator1 g1_;
5078 const Generator2 g2_;
5079 const Generator3 g3_;
5080 const Generator4 g4_;
5081 const Generator5 g5_;
5082 const Generator6 g6_;
5083 const Generator7 g7_;
5084 const Generator8 g8_;
5085 const Generator9 g9_;
5086 }; // class CartesianProductHolder9
5087
5088 template <class Generator1, class Generator2, class Generator3,
5089 class Generator4, class Generator5, class Generator6, class Generator7,
5090 class Generator8, class Generator9, class Generator10>
5091 class CartesianProductHolder10 {
5092 public:
5093 CartesianProductHolder10(const Generator1& g1, const Generator2& g2,
5094 const Generator3& g3, const Generator4& g4, const Generator5& g5,
5095 const Generator6& g6, const Generator7& g7, const Generator8& g8,
5096 const Generator9& g9, const Generator10& g10)
5097 : g1_(g1), g2_(g2), g3_(g3), g4_(g4), g5_(g5), g6_(g6), g7_(g7), g8_(g8),
5098 g9_(g9), g10_(g10) {}
5099 template <typename T1, typename T2, typename T3, typename T4, typename T5,
5100 typename T6, typename T7, typename T8, typename T9, typename T10>
5101 operator ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8,
5102 T9, T10> >() const {
5103 return ParamGenerator< ::std::tr1::tuple<T1, T2, T3, T4, T5, T6, T7, T8,
5104 T9, T10> >(
5105 new CartesianProductGenerator10<T1, T2, T3, T4, T5, T6, T7, T8, T9,
5106 T10>(
5107 static_cast<ParamGenerator<T1> >(g1_),
5108 static_cast<ParamGenerator<T2> >(g2_),
5109 static_cast<ParamGenerator<T3> >(g3_),
5110 static_cast<ParamGenerator<T4> >(g4_),
5111 static_cast<ParamGenerator<T5> >(g5_),
5112 static_cast<ParamGenerator<T6> >(g6_),
5113 static_cast<ParamGenerator<T7> >(g7_),
5114 static_cast<ParamGenerator<T8> >(g8_),
5115 static_cast<ParamGenerator<T9> >(g9_),
5116 static_cast<ParamGenerator<T10> >(g10_)));
5117 }
5118
5119 private:
5120 // No implementation - assignment is unsupported.
5121 void operator=(const CartesianProductHolder10& other);
5122
5123 const Generator1 g1_;
5124 const Generator2 g2_;
5125 const Generator3 g3_;
5126 const Generator4 g4_;
5127 const Generator5 g5_;
5128 const Generator6 g6_;
5129 const Generator7 g7_;
5130 const Generator8 g8_;
5131 const Generator9 g9_;
5132 const Generator10 g10_;
5133 }; // class CartesianProductHolder10
5134
5135 # endif // GTEST_HAS_COMBINE
5136
5137 } // namespace internal
5138 } // namespace testing
5139
5140 #endif // GTEST_HAS_PARAM_TEST
5141
5142 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
0 $$ -*- mode: c++; -*-
1 $var n = 50 $$ Maximum length of Values arguments we want to support.
2 $var maxtuple = 10 $$ Maximum number of Combine arguments we want to support.
3 // Copyright 2008 Google Inc.
4 // All Rights Reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 // * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 //
32 // Author: vladl@google.com (Vlad Losev)
33
34 // Type and function utilities for implementing parameterized tests.
35 // This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
36 //
37 // Currently Google Test supports at most $n arguments in Values,
38 // and at most $maxtuple arguments in Combine. Please contact
39 // googletestframework@googlegroups.com if you need more.
40 // Please note that the number of arguments to Combine is limited
41 // by the maximum arity of the implementation of tr1::tuple which is
42 // currently set at $maxtuple.
43
44 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
45 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
46
47 // scripts/fuse_gtest.py depends on gtest's own header being #included
48 // *unconditionally*. Therefore these #includes cannot be moved
49 // inside #if GTEST_HAS_PARAM_TEST.
50 #include "gtest/internal/gtest-param-util.h"
51 #include "gtest/internal/gtest-port.h"
52
53 #if GTEST_HAS_PARAM_TEST
54
55 namespace testing {
56
57 // Forward declarations of ValuesIn(), which is implemented in
58 // include/gtest/gtest-param-test.h.
59 template <typename ForwardIterator>
60 internal::ParamGenerator<
61 typename ::testing::internal::IteratorTraits<ForwardIterator>::value_type>
62 ValuesIn(ForwardIterator begin, ForwardIterator end);
63
64 template <typename T, size_t N>
65 internal::ParamGenerator<T> ValuesIn(const T (&array)[N]);
66
67 template <class Container>
68 internal::ParamGenerator<typename Container::value_type> ValuesIn(
69 const Container& container);
70
71 namespace internal {
72
73 // Used in the Values() function to provide polymorphic capabilities.
74 template <typename T1>
75 class ValueArray1 {
76 public:
77 explicit ValueArray1(T1 v1) : v1_(v1) {}
78
79 template <typename T>
80 operator ParamGenerator<T>() const { return ValuesIn(&v1_, &v1_ + 1); }
81
82 private:
83 // No implementation - assignment is unsupported.
84 void operator=(const ValueArray1& other);
85
86 const T1 v1_;
87 };
88
89 $range i 2..n
90 $for i [[
91 $range j 1..i
92
93 template <$for j, [[typename T$j]]>
94 class ValueArray$i {
95 public:
96 ValueArray$i($for j, [[T$j v$j]]) : $for j, [[v$(j)_(v$j)]] {}
97
98 template <typename T>
99 operator ParamGenerator<T>() const {
100 const T array[] = {$for j, [[static_cast<T>(v$(j)_)]]};
101 return ValuesIn(array);
102 }
103
104 private:
105 // No implementation - assignment is unsupported.
106 void operator=(const ValueArray$i& other);
107
108 $for j [[
109
110 const T$j v$(j)_;
111 ]]
112
113 };
114
115 ]]
116
117 # if GTEST_HAS_COMBINE
118 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
119 //
120 // Generates values from the Cartesian product of values produced
121 // by the argument generators.
122 //
123 $range i 2..maxtuple
124 $for i [[
125 $range j 1..i
126 $range k 2..i
127
128 template <$for j, [[typename T$j]]>
129 class CartesianProductGenerator$i
130 : public ParamGeneratorInterface< ::std::tr1::tuple<$for j, [[T$j]]> > {
131 public:
132 typedef ::std::tr1::tuple<$for j, [[T$j]]> ParamType;
133
134 CartesianProductGenerator$i($for j, [[const ParamGenerator<T$j>& g$j]])
135 : $for j, [[g$(j)_(g$j)]] {}
136 virtual ~CartesianProductGenerator$i() {}
137
138 virtual ParamIteratorInterface<ParamType>* Begin() const {
139 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.begin()]]);
140 }
141 virtual ParamIteratorInterface<ParamType>* End() const {
142 return new Iterator(this, $for j, [[g$(j)_, g$(j)_.end()]]);
143 }
144
145 private:
146 class Iterator : public ParamIteratorInterface<ParamType> {
147 public:
148 Iterator(const ParamGeneratorInterface<ParamType>* base, $for j, [[
149
150 const ParamGenerator<T$j>& g$j,
151 const typename ParamGenerator<T$j>::iterator& current$(j)]])
152 : base_(base),
153 $for j, [[
154
155 begin$(j)_(g$j.begin()), end$(j)_(g$j.end()), current$(j)_(current$j)
156 ]] {
157 ComputeCurrentValue();
158 }
159 virtual ~Iterator() {}
160
161 virtual const ParamGeneratorInterface<ParamType>* BaseGenerator() const {
162 return base_;
163 }
164 // Advance should not be called on beyond-of-range iterators
165 // so no component iterators must be beyond end of range, either.
166 virtual void Advance() {
167 assert(!AtEnd());
168 ++current$(i)_;
169
170 $for k [[
171 if (current$(i+2-k)_ == end$(i+2-k)_) {
172 current$(i+2-k)_ = begin$(i+2-k)_;
173 ++current$(i+2-k-1)_;
174 }
175
176 ]]
177 ComputeCurrentValue();
178 }
179 virtual ParamIteratorInterface<ParamType>* Clone() const {
180 return new Iterator(*this);
181 }
182 virtual const ParamType* Current() const { return &current_value_; }
183 virtual bool Equals(const ParamIteratorInterface<ParamType>& other) const {
184 // Having the same base generator guarantees that the other
185 // iterator is of the same type and we can downcast.
186 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
187 << "The program attempted to compare iterators "
188 << "from different generators." << std::endl;
189 const Iterator* typed_other =
190 CheckedDowncastToActualType<const Iterator>(&other);
191 // We must report iterators equal if they both point beyond their
192 // respective ranges. That can happen in a variety of fashions,
193 // so we have to consult AtEnd().
194 return (AtEnd() && typed_other->AtEnd()) ||
195 ($for j && [[
196
197 current$(j)_ == typed_other->current$(j)_
198 ]]);
199 }
200
201 private:
202 Iterator(const Iterator& other)
203 : base_(other.base_), $for j, [[
204
205 begin$(j)_(other.begin$(j)_),
206 end$(j)_(other.end$(j)_),
207 current$(j)_(other.current$(j)_)
208 ]] {
209 ComputeCurrentValue();
210 }
211
212 void ComputeCurrentValue() {
213 if (!AtEnd())
214 current_value_ = ParamType($for j, [[*current$(j)_]]);
215 }
216 bool AtEnd() const {
217 // We must report iterator past the end of the range when either of the
218 // component iterators has reached the end of its range.
219 return
220 $for j || [[
221
222 current$(j)_ == end$(j)_
223 ]];
224 }
225
226 // No implementation - assignment is unsupported.
227 void operator=(const Iterator& other);
228
229 const ParamGeneratorInterface<ParamType>* const base_;
230 // begin[i]_ and end[i]_ define the i-th range that Iterator traverses.
231 // current[i]_ is the actual traversing iterator.
232 $for j [[
233
234 const typename ParamGenerator<T$j>::iterator begin$(j)_;
235 const typename ParamGenerator<T$j>::iterator end$(j)_;
236 typename ParamGenerator<T$j>::iterator current$(j)_;
237 ]]
238
239 ParamType current_value_;
240 }; // class CartesianProductGenerator$i::Iterator
241
242 // No implementation - assignment is unsupported.
243 void operator=(const CartesianProductGenerator$i& other);
244
245
246 $for j [[
247 const ParamGenerator<T$j> g$(j)_;
248
249 ]]
250 }; // class CartesianProductGenerator$i
251
252
253 ]]
254
255 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
256 //
257 // Helper classes providing Combine() with polymorphic features. They allow
258 // casting CartesianProductGeneratorN<T> to ParamGenerator<U> if T is
259 // convertible to U.
260 //
261 $range i 2..maxtuple
262 $for i [[
263 $range j 1..i
264
265 template <$for j, [[class Generator$j]]>
266 class CartesianProductHolder$i {
267 public:
268 CartesianProductHolder$i($for j, [[const Generator$j& g$j]])
269 : $for j, [[g$(j)_(g$j)]] {}
270 template <$for j, [[typename T$j]]>
271 operator ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >() const {
272 return ParamGenerator< ::std::tr1::tuple<$for j, [[T$j]]> >(
273 new CartesianProductGenerator$i<$for j, [[T$j]]>(
274 $for j,[[
275
276 static_cast<ParamGenerator<T$j> >(g$(j)_)
277 ]]));
278 }
279
280 private:
281 // No implementation - assignment is unsupported.
282 void operator=(const CartesianProductHolder$i& other);
283
284
285 $for j [[
286 const Generator$j g$(j)_;
287
288 ]]
289 }; // class CartesianProductHolder$i
290
291 ]]
292
293 # endif // GTEST_HAS_COMBINE
294
295 } // namespace internal
296 } // namespace testing
297
298 #endif // GTEST_HAS_PARAM_TEST
299
300 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_GENERATED_H_
0 // Copyright 2008 Google Inc.
1 // All Rights Reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: vladl@google.com (Vlad Losev)
30
31 // Type and function utilities for implementing parameterized tests.
32
33 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
34 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
35
36 #include <iterator>
37 #include <utility>
38 #include <vector>
39
40 // scripts/fuse_gtest.py depends on gtest's own header being #included
41 // *unconditionally*. Therefore these #includes cannot be moved
42 // inside #if GTEST_HAS_PARAM_TEST.
43 #include "gtest/internal/gtest-internal.h"
44 #include "gtest/internal/gtest-linked_ptr.h"
45 #include "gtest/internal/gtest-port.h"
46 #include "gtest/gtest-printers.h"
47
48 #if GTEST_HAS_PARAM_TEST
49
50 namespace testing {
51 namespace internal {
52
53 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
54 //
55 // Outputs a message explaining invalid registration of different
56 // fixture class for the same test case. This may happen when
57 // TEST_P macro is used to define two tests with the same name
58 // but in different namespaces.
59 GTEST_API_ void ReportInvalidTestCaseType(const char* test_case_name,
60 const char* file, int line);
61
62 template <typename> class ParamGeneratorInterface;
63 template <typename> class ParamGenerator;
64
65 // Interface for iterating over elements provided by an implementation
66 // of ParamGeneratorInterface<T>.
67 template <typename T>
68 class ParamIteratorInterface {
69 public:
70 virtual ~ParamIteratorInterface() {}
71 // A pointer to the base generator instance.
72 // Used only for the purposes of iterator comparison
73 // to make sure that two iterators belong to the same generator.
74 virtual const ParamGeneratorInterface<T>* BaseGenerator() const = 0;
75 // Advances iterator to point to the next element
76 // provided by the generator. The caller is responsible
77 // for not calling Advance() on an iterator equal to
78 // BaseGenerator()->End().
79 virtual void Advance() = 0;
80 // Clones the iterator object. Used for implementing copy semantics
81 // of ParamIterator<T>.
82 virtual ParamIteratorInterface* Clone() const = 0;
83 // Dereferences the current iterator and provides (read-only) access
84 // to the pointed value. It is the caller's responsibility not to call
85 // Current() on an iterator equal to BaseGenerator()->End().
86 // Used for implementing ParamGenerator<T>::operator*().
87 virtual const T* Current() const = 0;
88 // Determines whether the given iterator and other point to the same
89 // element in the sequence generated by the generator.
90 // Used for implementing ParamGenerator<T>::operator==().
91 virtual bool Equals(const ParamIteratorInterface& other) const = 0;
92 };
93
94 // Class iterating over elements provided by an implementation of
95 // ParamGeneratorInterface<T>. It wraps ParamIteratorInterface<T>
96 // and implements the const forward iterator concept.
97 template <typename T>
98 class ParamIterator {
99 public:
100 typedef T value_type;
101 typedef const T& reference;
102 typedef ptrdiff_t difference_type;
103
104 // ParamIterator assumes ownership of the impl_ pointer.
105 ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {}
106 ParamIterator& operator=(const ParamIterator& other) {
107 if (this != &other)
108 impl_.reset(other.impl_->Clone());
109 return *this;
110 }
111
112 const T& operator*() const { return *impl_->Current(); }
113 const T* operator->() const { return impl_->Current(); }
114 // Prefix version of operator++.
115 ParamIterator& operator++() {
116 impl_->Advance();
117 return *this;
118 }
119 // Postfix version of operator++.
120 ParamIterator operator++(int /*unused*/) {
121 ParamIteratorInterface<T>* clone = impl_->Clone();
122 impl_->Advance();
123 return ParamIterator(clone);
124 }
125 bool operator==(const ParamIterator& other) const {
126 return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_);
127 }
128 bool operator!=(const ParamIterator& other) const {
129 return !(*this == other);
130 }
131
132 private:
133 friend class ParamGenerator<T>;
134 explicit ParamIterator(ParamIteratorInterface<T>* impl) : impl_(impl) {}
135 scoped_ptr<ParamIteratorInterface<T> > impl_;
136 };
137
138 // ParamGeneratorInterface<T> is the binary interface to access generators
139 // defined in other translation units.
140 template <typename T>
141 class ParamGeneratorInterface {
142 public:
143 typedef T ParamType;
144
145 virtual ~ParamGeneratorInterface() {}
146
147 // Generator interface definition
148 virtual ParamIteratorInterface<T>* Begin() const = 0;
149 virtual ParamIteratorInterface<T>* End() const = 0;
150 };
151
152 // Wraps ParamGeneratorInterface<T> and provides general generator syntax
153 // compatible with the STL Container concept.
154 // This class implements copy initialization semantics and the contained
155 // ParamGeneratorInterface<T> instance is shared among all copies
156 // of the original object. This is possible because that instance is immutable.
157 template<typename T>
158 class ParamGenerator {
159 public:
160 typedef ParamIterator<T> iterator;
161
162 explicit ParamGenerator(ParamGeneratorInterface<T>* impl) : impl_(impl) {}
163 ParamGenerator(const ParamGenerator& other) : impl_(other.impl_) {}
164
165 ParamGenerator& operator=(const ParamGenerator& other) {
166 impl_ = other.impl_;
167 return *this;
168 }
169
170 iterator begin() const { return iterator(impl_->Begin()); }
171 iterator end() const { return iterator(impl_->End()); }
172
173 private:
174 linked_ptr<const ParamGeneratorInterface<T> > impl_;
175 };
176
177 // Generates values from a range of two comparable values. Can be used to
178 // generate sequences of user-defined types that implement operator+() and
179 // operator<().
180 // This class is used in the Range() function.
181 template <typename T, typename IncrementT>
182 class RangeGenerator : public ParamGeneratorInterface<T> {
183 public:
184 RangeGenerator(T begin, T end, IncrementT step)
185 : begin_(begin), end_(end),
186 step_(step), end_index_(CalculateEndIndex(begin, end, step)) {}
187 virtual ~RangeGenerator() {}
188
189 virtual ParamIteratorInterface<T>* Begin() const {
190 return new Iterator(this, begin_, 0, step_);
191 }
192 virtual ParamIteratorInterface<T>* End() const {
193 return new Iterator(this, end_, end_index_, step_);
194 }
195
196 private:
197 class Iterator : public ParamIteratorInterface<T> {
198 public:
199 Iterator(const ParamGeneratorInterface<T>* base, T value, int index,
200 IncrementT step)
201 : base_(base), value_(value), index_(index), step_(step) {}
202 virtual ~Iterator() {}
203
204 virtual const ParamGeneratorInterface<T>* BaseGenerator() const {
205 return base_;
206 }
207 virtual void Advance() {
208 value_ = value_ + step_;
209 index_++;
210 }
211 virtual ParamIteratorInterface<T>* Clone() const {
212 return new Iterator(*this);
213 }
214 virtual const T* Current() const { return &value_; }
215 virtual bool Equals(const ParamIteratorInterface<T>& other) const {
216 // Having the same base generator guarantees that the other
217 // iterator is of the same type and we can downcast.
218 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
219 << "The program attempted to compare iterators "
220 << "from different generators." << std::endl;
221 const int other_index =
222 CheckedDowncastToActualType<const Iterator>(&other)->index_;
223 return index_ == other_index;
224 }
225
226 private:
227 Iterator(const Iterator& other)
228 : ParamIteratorInterface<T>(),
229 base_(other.base_), value_(other.value_), index_(other.index_),
230 step_(other.step_) {}
231
232 // No implementation - assignment is unsupported.
233 void operator=(const Iterator& other);
234
235 const ParamGeneratorInterface<T>* const base_;
236 T value_;
237 int index_;
238 const IncrementT step_;
239 }; // class RangeGenerator::Iterator
240
241 static int CalculateEndIndex(const T& begin,
242 const T& end,
243 const IncrementT& step) {
244 int end_index = 0;
245 for (T i = begin; i < end; i = i + step)
246 end_index++;
247 return end_index;
248 }
249
250 // No implementation - assignment is unsupported.
251 void operator=(const RangeGenerator& other);
252
253 const T begin_;
254 const T end_;
255 const IncrementT step_;
256 // The index for the end() iterator. All the elements in the generated
257 // sequence are indexed (0-based) to aid iterator comparison.
258 const int end_index_;
259 }; // class RangeGenerator
260
261
262 // Generates values from a pair of STL-style iterators. Used in the
263 // ValuesIn() function. The elements are copied from the source range
264 // since the source can be located on the stack, and the generator
265 // is likely to persist beyond that stack frame.
266 template <typename T>
267 class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface<T> {
268 public:
269 template <typename ForwardIterator>
270 ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end)
271 : container_(begin, end) {}
272 virtual ~ValuesInIteratorRangeGenerator() {}
273
274 virtual ParamIteratorInterface<T>* Begin() const {
275 return new Iterator(this, container_.begin());
276 }
277 virtual ParamIteratorInterface<T>* End() const {
278 return new Iterator(this, container_.end());
279 }
280
281 private:
282 typedef typename ::std::vector<T> ContainerType;
283
284 class Iterator : public ParamIteratorInterface<T> {
285 public:
286 Iterator(const ParamGeneratorInterface<T>* base,
287 typename ContainerType::const_iterator iterator)
288 : base_(base), iterator_(iterator) {}
289 virtual ~Iterator() {}
290
291 virtual const ParamGeneratorInterface<T>* BaseGenerator() const {
292 return base_;
293 }
294 virtual void Advance() {
295 ++iterator_;
296 value_.reset();
297 }
298 virtual ParamIteratorInterface<T>* Clone() const {
299 return new Iterator(*this);
300 }
301 // We need to use cached value referenced by iterator_ because *iterator_
302 // can return a temporary object (and of type other then T), so just
303 // having "return &*iterator_;" doesn't work.
304 // value_ is updated here and not in Advance() because Advance()
305 // can advance iterator_ beyond the end of the range, and we cannot
306 // detect that fact. The client code, on the other hand, is
307 // responsible for not calling Current() on an out-of-range iterator.
308 virtual const T* Current() const {
309 if (value_.get() == NULL)
310 value_.reset(new T(*iterator_));
311 return value_.get();
312 }
313 virtual bool Equals(const ParamIteratorInterface<T>& other) const {
314 // Having the same base generator guarantees that the other
315 // iterator is of the same type and we can downcast.
316 GTEST_CHECK_(BaseGenerator() == other.BaseGenerator())
317 << "The program attempted to compare iterators "
318 << "from different generators." << std::endl;
319 return iterator_ ==
320 CheckedDowncastToActualType<const Iterator>(&other)->iterator_;
321 }
322
323 private:
324 Iterator(const Iterator& other)
325 // The explicit constructor call suppresses a false warning
326 // emitted by gcc when supplied with the -Wextra option.
327 : ParamIteratorInterface<T>(),
328 base_(other.base_),
329 iterator_(other.iterator_) {}
330
331 const ParamGeneratorInterface<T>* const base_;
332 typename ContainerType::const_iterator iterator_;
333 // A cached value of *iterator_. We keep it here to allow access by
334 // pointer in the wrapping iterator's operator->().
335 // value_ needs to be mutable to be accessed in Current().
336 // Use of scoped_ptr helps manage cached value's lifetime,
337 // which is bound by the lifespan of the iterator itself.
338 mutable scoped_ptr<const T> value_;
339 }; // class ValuesInIteratorRangeGenerator::Iterator
340
341 // No implementation - assignment is unsupported.
342 void operator=(const ValuesInIteratorRangeGenerator& other);
343
344 const ContainerType container_;
345 }; // class ValuesInIteratorRangeGenerator
346
347 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
348 //
349 // Stores a parameter value and later creates tests parameterized with that
350 // value.
351 template <class TestClass>
352 class ParameterizedTestFactory : public TestFactoryBase {
353 public:
354 typedef typename TestClass::ParamType ParamType;
355 explicit ParameterizedTestFactory(ParamType parameter) :
356 parameter_(parameter) {}
357 virtual Test* CreateTest() {
358 TestClass::SetParam(&parameter_);
359 return new TestClass();
360 }
361
362 private:
363 const ParamType parameter_;
364
365 GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory);
366 };
367
368 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
369 //
370 // TestMetaFactoryBase is a base class for meta-factories that create
371 // test factories for passing into MakeAndRegisterTestInfo function.
372 template <class ParamType>
373 class TestMetaFactoryBase {
374 public:
375 virtual ~TestMetaFactoryBase() {}
376
377 virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0;
378 };
379
380 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
381 //
382 // TestMetaFactory creates test factories for passing into
383 // MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives
384 // ownership of test factory pointer, same factory object cannot be passed
385 // into that method twice. But ParameterizedTestCaseInfo is going to call
386 // it for each Test/Parameter value combination. Thus it needs meta factory
387 // creator class.
388 template <class TestCase>
389 class TestMetaFactory
390 : public TestMetaFactoryBase<typename TestCase::ParamType> {
391 public:
392 typedef typename TestCase::ParamType ParamType;
393
394 TestMetaFactory() {}
395
396 virtual TestFactoryBase* CreateTestFactory(ParamType parameter) {
397 return new ParameterizedTestFactory<TestCase>(parameter);
398 }
399
400 private:
401 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestMetaFactory);
402 };
403
404 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
405 //
406 // ParameterizedTestCaseInfoBase is a generic interface
407 // to ParameterizedTestCaseInfo classes. ParameterizedTestCaseInfoBase
408 // accumulates test information provided by TEST_P macro invocations
409 // and generators provided by INSTANTIATE_TEST_CASE_P macro invocations
410 // and uses that information to register all resulting test instances
411 // in RegisterTests method. The ParameterizeTestCaseRegistry class holds
412 // a collection of pointers to the ParameterizedTestCaseInfo objects
413 // and calls RegisterTests() on each of them when asked.
414 class ParameterizedTestCaseInfoBase {
415 public:
416 virtual ~ParameterizedTestCaseInfoBase() {}
417
418 // Base part of test case name for display purposes.
419 virtual const string& GetTestCaseName() const = 0;
420 // Test case id to verify identity.
421 virtual TypeId GetTestCaseTypeId() const = 0;
422 // UnitTest class invokes this method to register tests in this
423 // test case right before running them in RUN_ALL_TESTS macro.
424 // This method should not be called more then once on any single
425 // instance of a ParameterizedTestCaseInfoBase derived class.
426 virtual void RegisterTests() = 0;
427
428 protected:
429 ParameterizedTestCaseInfoBase() {}
430
431 private:
432 GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfoBase);
433 };
434
435 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
436 //
437 // ParameterizedTestCaseInfo accumulates tests obtained from TEST_P
438 // macro invocations for a particular test case and generators
439 // obtained from INSTANTIATE_TEST_CASE_P macro invocations for that
440 // test case. It registers tests with all values generated by all
441 // generators when asked.
442 template <class TestCase>
443 class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase {
444 public:
445 // ParamType and GeneratorCreationFunc are private types but are required
446 // for declarations of public methods AddTestPattern() and
447 // AddTestCaseInstantiation().
448 typedef typename TestCase::ParamType ParamType;
449 // A function that returns an instance of appropriate generator type.
450 typedef ParamGenerator<ParamType>(GeneratorCreationFunc)();
451
452 explicit ParameterizedTestCaseInfo(const char* name)
453 : test_case_name_(name) {}
454
455 // Test case base name for display purposes.
456 virtual const string& GetTestCaseName() const { return test_case_name_; }
457 // Test case id to verify identity.
458 virtual TypeId GetTestCaseTypeId() const { return GetTypeId<TestCase>(); }
459 // TEST_P macro uses AddTestPattern() to record information
460 // about a single test in a LocalTestInfo structure.
461 // test_case_name is the base name of the test case (without invocation
462 // prefix). test_base_name is the name of an individual test without
463 // parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is
464 // test case base name and DoBar is test base name.
465 void AddTestPattern(const char* test_case_name,
466 const char* test_base_name,
467 TestMetaFactoryBase<ParamType>* meta_factory) {
468 tests_.push_back(linked_ptr<TestInfo>(new TestInfo(test_case_name,
469 test_base_name,
470 meta_factory)));
471 }
472 // INSTANTIATE_TEST_CASE_P macro uses AddGenerator() to record information
473 // about a generator.
474 int AddTestCaseInstantiation(const string& instantiation_name,
475 GeneratorCreationFunc* func,
476 const char* /* file */,
477 int /* line */) {
478 instantiations_.push_back(::std::make_pair(instantiation_name, func));
479 return 0; // Return value used only to run this method in namespace scope.
480 }
481 // UnitTest class invokes this method to register tests in this test case
482 // test cases right before running tests in RUN_ALL_TESTS macro.
483 // This method should not be called more then once on any single
484 // instance of a ParameterizedTestCaseInfoBase derived class.
485 // UnitTest has a guard to prevent from calling this method more then once.
486 virtual void RegisterTests() {
487 for (typename TestInfoContainer::iterator test_it = tests_.begin();
488 test_it != tests_.end(); ++test_it) {
489 linked_ptr<TestInfo> test_info = *test_it;
490 for (typename InstantiationContainer::iterator gen_it =
491 instantiations_.begin(); gen_it != instantiations_.end();
492 ++gen_it) {
493 const string& instantiation_name = gen_it->first;
494 ParamGenerator<ParamType> generator((*gen_it->second)());
495
496 string test_case_name;
497 if ( !instantiation_name.empty() )
498 test_case_name = instantiation_name + "/";
499 test_case_name += test_info->test_case_base_name;
500
501 int i = 0;
502 for (typename ParamGenerator<ParamType>::iterator param_it =
503 generator.begin();
504 param_it != generator.end(); ++param_it, ++i) {
505 Message test_name_stream;
506 test_name_stream << test_info->test_base_name << "/" << i;
507 MakeAndRegisterTestInfo(
508 test_case_name.c_str(),
509 test_name_stream.GetString().c_str(),
510 NULL, // No type parameter.
511 PrintToString(*param_it).c_str(),
512 GetTestCaseTypeId(),
513 TestCase::SetUpTestCase,
514 TestCase::TearDownTestCase,
515 test_info->test_meta_factory->CreateTestFactory(*param_it));
516 } // for param_it
517 } // for gen_it
518 } // for test_it
519 } // RegisterTests
520
521 private:
522 // LocalTestInfo structure keeps information about a single test registered
523 // with TEST_P macro.
524 struct TestInfo {
525 TestInfo(const char* a_test_case_base_name,
526 const char* a_test_base_name,
527 TestMetaFactoryBase<ParamType>* a_test_meta_factory) :
528 test_case_base_name(a_test_case_base_name),
529 test_base_name(a_test_base_name),
530 test_meta_factory(a_test_meta_factory) {}
531
532 const string test_case_base_name;
533 const string test_base_name;
534 const scoped_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
535 };
536 typedef ::std::vector<linked_ptr<TestInfo> > TestInfoContainer;
537 // Keeps pairs of <Instantiation name, Sequence generator creation function>
538 // received from INSTANTIATE_TEST_CASE_P macros.
539 typedef ::std::vector<std::pair<string, GeneratorCreationFunc*> >
540 InstantiationContainer;
541
542 const string test_case_name_;
543 TestInfoContainer tests_;
544 InstantiationContainer instantiations_;
545
546 GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseInfo);
547 }; // class ParameterizedTestCaseInfo
548
549 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
550 //
551 // ParameterizedTestCaseRegistry contains a map of ParameterizedTestCaseInfoBase
552 // classes accessed by test case names. TEST_P and INSTANTIATE_TEST_CASE_P
553 // macros use it to locate their corresponding ParameterizedTestCaseInfo
554 // descriptors.
555 class ParameterizedTestCaseRegistry {
556 public:
557 ParameterizedTestCaseRegistry() {}
558 ~ParameterizedTestCaseRegistry() {
559 for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
560 it != test_case_infos_.end(); ++it) {
561 delete *it;
562 }
563 }
564
565 // Looks up or creates and returns a structure containing information about
566 // tests and instantiations of a particular test case.
567 template <class TestCase>
568 ParameterizedTestCaseInfo<TestCase>* GetTestCasePatternHolder(
569 const char* test_case_name,
570 const char* file,
571 int line) {
572 ParameterizedTestCaseInfo<TestCase>* typed_test_info = NULL;
573 for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
574 it != test_case_infos_.end(); ++it) {
575 if ((*it)->GetTestCaseName() == test_case_name) {
576 if ((*it)->GetTestCaseTypeId() != GetTypeId<TestCase>()) {
577 // Complain about incorrect usage of Google Test facilities
578 // and terminate the program since we cannot guaranty correct
579 // test case setup and tear-down in this case.
580 ReportInvalidTestCaseType(test_case_name, file, line);
581 posix::Abort();
582 } else {
583 // At this point we are sure that the object we found is of the same
584 // type we are looking for, so we downcast it to that type
585 // without further checks.
586 typed_test_info = CheckedDowncastToActualType<
587 ParameterizedTestCaseInfo<TestCase> >(*it);
588 }
589 break;
590 }
591 }
592 if (typed_test_info == NULL) {
593 typed_test_info = new ParameterizedTestCaseInfo<TestCase>(test_case_name);
594 test_case_infos_.push_back(typed_test_info);
595 }
596 return typed_test_info;
597 }
598 void RegisterTests() {
599 for (TestCaseInfoContainer::iterator it = test_case_infos_.begin();
600 it != test_case_infos_.end(); ++it) {
601 (*it)->RegisterTests();
602 }
603 }
604
605 private:
606 typedef ::std::vector<ParameterizedTestCaseInfoBase*> TestCaseInfoContainer;
607
608 TestCaseInfoContainer test_case_infos_;
609
610 GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestCaseRegistry);
611 };
612
613 } // namespace internal
614 } // namespace testing
615
616 #endif // GTEST_HAS_PARAM_TEST
617
618 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_
0 // Copyright 2005, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Authors: wan@google.com (Zhanyong Wan)
30 //
31 // Low-level types and utilities for porting Google Test to various
32 // platforms. They are subject to change without notice. DO NOT USE
33 // THEM IN USER CODE.
34 //
35 // This file is fundamental to Google Test. All other Google Test source
36 // files are expected to #include this. Therefore, it cannot #include
37 // any other Google Test header.
38
39 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
40 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
41
42 // The user can define the following macros in the build script to
43 // control Google Test's behavior. If the user doesn't define a macro
44 // in this list, Google Test will define it.
45 //
46 // GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2)
47 // is/isn't available.
48 // GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exceptions
49 // are enabled.
50 // GTEST_HAS_GLOBAL_STRING - Define it to 1/0 to indicate that ::string
51 // is/isn't available (some systems define
52 // ::string, which is different to std::string).
53 // GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string
54 // is/isn't available (some systems define
55 // ::wstring, which is different to std::wstring).
56 // GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX regular
57 // expressions are/aren't available.
58 // GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h>
59 // is/isn't available.
60 // GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't
61 // enabled.
62 // GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that
63 // std::wstring does/doesn't work (Google Test can
64 // be used where std::wstring is unavailable).
65 // GTEST_HAS_TR1_TUPLE - Define it to 1/0 to indicate tr1::tuple
66 // is/isn't available.
67 // GTEST_HAS_SEH - Define it to 1/0 to indicate whether the
68 // compiler supports Microsoft's "Structured
69 // Exception Handling".
70 // GTEST_HAS_STREAM_REDIRECTION
71 // - Define it to 1/0 to indicate whether the
72 // platform supports I/O stream redirection using
73 // dup() and dup2().
74 // GTEST_USE_OWN_TR1_TUPLE - Define it to 1/0 to indicate whether Google
75 // Test's own tr1 tuple implementation should be
76 // used. Unused when the user sets
77 // GTEST_HAS_TR1_TUPLE to 0.
78 // GTEST_LANG_CXX11 - Define it to 1/0 to indicate that Google Test
79 // is building in C++11/C++98 mode.
80 // GTEST_LINKED_AS_SHARED_LIBRARY
81 // - Define to 1 when compiling tests that use
82 // Google Test as a shared library (known as
83 // DLL on Windows).
84 // GTEST_CREATE_SHARED_LIBRARY
85 // - Define to 1 when compiling Google Test itself
86 // as a shared library.
87
88 // This header defines the following utilities:
89 //
90 // Macros indicating the current platform (defined to 1 if compiled on
91 // the given platform; otherwise undefined):
92 // GTEST_OS_AIX - IBM AIX
93 // GTEST_OS_CYGWIN - Cygwin
94 // GTEST_OS_HPUX - HP-UX
95 // GTEST_OS_LINUX - Linux
96 // GTEST_OS_LINUX_ANDROID - Google Android
97 // GTEST_OS_MAC - Mac OS X
98 // GTEST_OS_IOS - iOS
99 // GTEST_OS_IOS_SIMULATOR - iOS simulator
100 // GTEST_OS_NACL - Google Native Client (NaCl)
101 // GTEST_OS_OPENBSD - OpenBSD
102 // GTEST_OS_QNX - QNX
103 // GTEST_OS_SOLARIS - Sun Solaris
104 // GTEST_OS_SYMBIAN - Symbian
105 // GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile)
106 // GTEST_OS_WINDOWS_DESKTOP - Windows Desktop
107 // GTEST_OS_WINDOWS_MINGW - MinGW
108 // GTEST_OS_WINDOWS_MOBILE - Windows Mobile
109 // GTEST_OS_ZOS - z/OS
110 //
111 // Among the platforms, Cygwin, Linux, Max OS X, and Windows have the
112 // most stable support. Since core members of the Google Test project
113 // don't have access to other platforms, support for them may be less
114 // stable. If you notice any problems on your platform, please notify
115 // googletestframework@googlegroups.com (patches for fixing them are
116 // even more welcome!).
117 //
118 // Note that it is possible that none of the GTEST_OS_* macros are defined.
119 //
120 // Macros indicating available Google Test features (defined to 1 if
121 // the corresponding feature is supported; otherwise undefined):
122 // GTEST_HAS_COMBINE - the Combine() function (for value-parameterized
123 // tests)
124 // GTEST_HAS_DEATH_TEST - death tests
125 // GTEST_HAS_PARAM_TEST - value-parameterized tests
126 // GTEST_HAS_TYPED_TEST - typed tests
127 // GTEST_HAS_TYPED_TEST_P - type-parameterized tests
128 // GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse with
129 // GTEST_HAS_POSIX_RE (see above) which users can
130 // define themselves.
131 // GTEST_USES_SIMPLE_RE - our own simple regex is used;
132 // the above two are mutually exclusive.
133 // GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ().
134 //
135 // Macros for basic C++ coding:
136 // GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning.
137 // GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a
138 // variable don't have to be used.
139 // GTEST_DISALLOW_ASSIGN_ - disables operator=.
140 // GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=.
141 // GTEST_MUST_USE_RESULT_ - declares that a function's result must be used.
142 //
143 // Synchronization:
144 // Mutex, MutexLock, ThreadLocal, GetThreadCount()
145 // - synchronization primitives.
146 // GTEST_IS_THREADSAFE - defined to 1 to indicate that the above
147 // synchronization primitives have real implementations
148 // and Google Test is thread-safe; or 0 otherwise.
149 //
150 // Template meta programming:
151 // is_pointer - as in TR1; needed on Symbian and IBM XL C/C++ only.
152 // IteratorTraits - partial implementation of std::iterator_traits, which
153 // is not available in libCstd when compiled with Sun C++.
154 //
155 // Smart pointers:
156 // scoped_ptr - as in TR2.
157 //
158 // Regular expressions:
159 // RE - a simple regular expression class using the POSIX
160 // Extended Regular Expression syntax on UNIX-like
161 // platforms, or a reduced regular exception syntax on
162 // other platforms, including Windows.
163 //
164 // Logging:
165 // GTEST_LOG_() - logs messages at the specified severity level.
166 // LogToStderr() - directs all log messages to stderr.
167 // FlushInfoLog() - flushes informational log messages.
168 //
169 // Stdout and stderr capturing:
170 // CaptureStdout() - starts capturing stdout.
171 // GetCapturedStdout() - stops capturing stdout and returns the captured
172 // string.
173 // CaptureStderr() - starts capturing stderr.
174 // GetCapturedStderr() - stops capturing stderr and returns the captured
175 // string.
176 //
177 // Integer types:
178 // TypeWithSize - maps an integer to a int type.
179 // Int32, UInt32, Int64, UInt64, TimeInMillis
180 // - integers of known sizes.
181 // BiggestInt - the biggest signed integer type.
182 //
183 // Command-line utilities:
184 // GTEST_FLAG() - references a flag.
185 // GTEST_DECLARE_*() - declares a flag.
186 // GTEST_DEFINE_*() - defines a flag.
187 // GetInjectableArgvs() - returns the command line as a vector of strings.
188 //
189 // Environment variable utilities:
190 // GetEnv() - gets the value of an environment variable.
191 // BoolFromGTestEnv() - parses a bool environment variable.
192 // Int32FromGTestEnv() - parses an Int32 environment variable.
193 // StringFromGTestEnv() - parses a string environment variable.
194
195 #include <ctype.h> // for isspace, etc
196 #include <stddef.h> // for ptrdiff_t
197 #include <stdlib.h>
198 #include <stdio.h>
199 #include <string.h>
200 #ifndef _WIN32_WCE
201 # include <sys/types.h>
202 # include <sys/stat.h>
203 #endif // !_WIN32_WCE
204
205 #if defined __APPLE__
206 # include <AvailabilityMacros.h>
207 # include <TargetConditionals.h>
208 #endif
209
210 #include <iostream> // NOLINT
211 #include <sstream> // NOLINT
212 #include <string> // NOLINT
213
214 #define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
215 #define GTEST_FLAG_PREFIX_ "gtest_"
216 #define GTEST_FLAG_PREFIX_DASH_ "gtest-"
217 #define GTEST_FLAG_PREFIX_UPPER_ "GTEST_"
218 #define GTEST_NAME_ "Google Test"
219 #define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
220
221 // Determines the version of gcc that is used to compile this.
222 #ifdef __GNUC__
223 // 40302 means version 4.3.2.
224 # define GTEST_GCC_VER_ \
225 (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
226 #endif // __GNUC__
227
228 // Determines the platform on which Google Test is compiled.
229 #ifdef __CYGWIN__
230 # define GTEST_OS_CYGWIN 1
231 #elif defined __SYMBIAN32__
232 # define GTEST_OS_SYMBIAN 1
233 #elif defined _WIN32
234 # define GTEST_OS_WINDOWS 1
235 # ifdef _WIN32_WCE
236 # define GTEST_OS_WINDOWS_MOBILE 1
237 # elif defined(__MINGW__) || defined(__MINGW32__)
238 # define GTEST_OS_WINDOWS_MINGW 1
239 # else
240 # define GTEST_OS_WINDOWS_DESKTOP 1
241 # endif // _WIN32_WCE
242 #elif defined __APPLE__
243 # define GTEST_OS_MAC 1
244 # if TARGET_OS_IPHONE
245 # define GTEST_OS_IOS 1
246 # if TARGET_IPHONE_SIMULATOR
247 # define GTEST_OS_IOS_SIMULATOR 1
248 # endif
249 # endif
250 #elif defined __linux__
251 # define GTEST_OS_LINUX 1
252 # if defined __ANDROID__
253 # define GTEST_OS_LINUX_ANDROID 1
254 # endif
255 #elif defined __MVS__
256 # define GTEST_OS_ZOS 1
257 #elif defined(__sun) && defined(__SVR4)
258 # define GTEST_OS_SOLARIS 1
259 #elif defined(_AIX)
260 # define GTEST_OS_AIX 1
261 #elif defined(__hpux)
262 # define GTEST_OS_HPUX 1
263 #elif defined __native_client__
264 # define GTEST_OS_NACL 1
265 #elif defined __OpenBSD__
266 # define GTEST_OS_OPENBSD 1
267 #elif defined __QNX__
268 # define GTEST_OS_QNX 1
269 #endif // __CYGWIN__
270
271 #ifndef GTEST_LANG_CXX11
272 // gcc and clang define __GXX_EXPERIMENTAL_CXX0X__ when
273 // -std={c,gnu}++{0x,11} is passed. The C++11 standard specifies a
274 // value for __cplusplus, and recent versions of clang, gcc, and
275 // probably other compilers set that too in C++11 mode.
276 # if __GXX_EXPERIMENTAL_CXX0X__ || __cplusplus >= 201103L
277 // Compiling in at least C++11 mode.
278 # define GTEST_LANG_CXX11 1
279 # else
280 # define GTEST_LANG_CXX11 0
281 # endif
282 #endif
283
284 // Brings in definitions for functions used in the testing::internal::posix
285 // namespace (read, write, close, chdir, isatty, stat). We do not currently
286 // use them on Windows Mobile.
287 #if !GTEST_OS_WINDOWS
288 // This assumes that non-Windows OSes provide unistd.h. For OSes where this
289 // is not the case, we need to include headers that provide the functions
290 // mentioned above.
291 # include <unistd.h>
292 # include <strings.h>
293 #elif !GTEST_OS_WINDOWS_MOBILE
294 # include <direct.h>
295 # include <io.h>
296 #endif
297
298 #if GTEST_OS_LINUX_ANDROID
299 // Used to define __ANDROID_API__ matching the target NDK API level.
300 # include <android/api-level.h> // NOLINT
301 #endif
302
303 // Defines this to true iff Google Test can use POSIX regular expressions.
304 #ifndef GTEST_HAS_POSIX_RE
305 # if GTEST_OS_LINUX_ANDROID
306 // On Android, <regex.h> is only available starting with Gingerbread.
307 # define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
308 # else
309 # define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
310 # endif
311 #endif
312
313 #if GTEST_HAS_POSIX_RE
314
315 // On some platforms, <regex.h> needs someone to define size_t, and
316 // won't compile otherwise. We can #include it here as we already
317 // included <stdlib.h>, which is guaranteed to define size_t through
318 // <stddef.h>.
319 # include <regex.h> // NOLINT
320
321 # define GTEST_USES_POSIX_RE 1
322
323 #elif GTEST_OS_WINDOWS
324
325 // <regex.h> is not available on Windows. Use our own simple regex
326 // implementation instead.
327 # define GTEST_USES_SIMPLE_RE 1
328
329 #else
330
331 // <regex.h> may not be available on this platform. Use our own
332 // simple regex implementation instead.
333 # define GTEST_USES_SIMPLE_RE 1
334
335 #endif // GTEST_HAS_POSIX_RE
336
337 #ifndef GTEST_HAS_EXCEPTIONS
338 // The user didn't tell us whether exceptions are enabled, so we need
339 // to figure it out.
340 # if defined(_MSC_VER) || defined(__BORLANDC__)
341 // MSVC's and C++Builder's implementations of the STL use the _HAS_EXCEPTIONS
342 // macro to enable exceptions, so we'll do the same.
343 // Assumes that exceptions are enabled by default.
344 # ifndef _HAS_EXCEPTIONS
345 # define _HAS_EXCEPTIONS 1
346 # endif // _HAS_EXCEPTIONS
347 # define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS
348 # elif defined(__GNUC__) && __EXCEPTIONS
349 // gcc defines __EXCEPTIONS to 1 iff exceptions are enabled.
350 # define GTEST_HAS_EXCEPTIONS 1
351 # elif defined(__SUNPRO_CC)
352 // Sun Pro CC supports exceptions. However, there is no compile-time way of
353 // detecting whether they are enabled or not. Therefore, we assume that
354 // they are enabled unless the user tells us otherwise.
355 # define GTEST_HAS_EXCEPTIONS 1
356 # elif defined(__IBMCPP__) && __EXCEPTIONS
357 // xlC defines __EXCEPTIONS to 1 iff exceptions are enabled.
358 # define GTEST_HAS_EXCEPTIONS 1
359 # elif defined(__HP_aCC)
360 // Exception handling is in effect by default in HP aCC compiler. It has to
361 // be turned of by +noeh compiler option if desired.
362 # define GTEST_HAS_EXCEPTIONS 1
363 # else
364 // For other compilers, we assume exceptions are disabled to be
365 // conservative.
366 # define GTEST_HAS_EXCEPTIONS 0
367 # endif // defined(_MSC_VER) || defined(__BORLANDC__)
368 #endif // GTEST_HAS_EXCEPTIONS
369
370 #if !defined(GTEST_HAS_STD_STRING)
371 // Even though we don't use this macro any longer, we keep it in case
372 // some clients still depend on it.
373 # define GTEST_HAS_STD_STRING 1
374 #elif !GTEST_HAS_STD_STRING
375 // The user told us that ::std::string isn't available.
376 # error "Google Test cannot be used where ::std::string isn't available."
377 #endif // !defined(GTEST_HAS_STD_STRING)
378
379 #ifndef GTEST_HAS_GLOBAL_STRING
380 // The user didn't tell us whether ::string is available, so we need
381 // to figure it out.
382
383 # define GTEST_HAS_GLOBAL_STRING 0
384
385 #endif // GTEST_HAS_GLOBAL_STRING
386
387 #ifndef GTEST_HAS_STD_WSTRING
388 // The user didn't tell us whether ::std::wstring is available, so we need
389 // to figure it out.
390 // TODO(wan@google.com): uses autoconf to detect whether ::std::wstring
391 // is available.
392
393 // Cygwin 1.7 and below doesn't support ::std::wstring.
394 // Solaris' libc++ doesn't support it either. Android has
395 // no support for it at least as recent as Froyo (2.2).
396 # define GTEST_HAS_STD_WSTRING \
397 (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS))
398
399 #endif // GTEST_HAS_STD_WSTRING
400
401 #ifndef GTEST_HAS_GLOBAL_WSTRING
402 // The user didn't tell us whether ::wstring is available, so we need
403 // to figure it out.
404 # define GTEST_HAS_GLOBAL_WSTRING \
405 (GTEST_HAS_STD_WSTRING && GTEST_HAS_GLOBAL_STRING)
406 #endif // GTEST_HAS_GLOBAL_WSTRING
407
408 // Determines whether RTTI is available.
409 #ifndef GTEST_HAS_RTTI
410 // The user didn't tell us whether RTTI is enabled, so we need to
411 // figure it out.
412
413 # ifdef _MSC_VER
414
415 # ifdef _CPPRTTI // MSVC defines this macro iff RTTI is enabled.
416 # define GTEST_HAS_RTTI 1
417 # else
418 # define GTEST_HAS_RTTI 0
419 # endif
420
421 // Starting with version 4.3.2, gcc defines __GXX_RTTI iff RTTI is enabled.
422 # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
423
424 # ifdef __GXX_RTTI
425 // When building against STLport with the Android NDK and with
426 // -frtti -fno-exceptions, the build fails at link time with undefined
427 // references to __cxa_bad_typeid. Note sure if STL or toolchain bug,
428 // so disable RTTI when detected.
429 # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \
430 !defined(__EXCEPTIONS)
431 # define GTEST_HAS_RTTI 0
432 # else
433 # define GTEST_HAS_RTTI 1
434 # endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS
435 # else
436 # define GTEST_HAS_RTTI 0
437 # endif // __GXX_RTTI
438
439 // Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends
440 // using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the
441 // first version with C++ support.
442 # elif defined(__clang__)
443
444 # define GTEST_HAS_RTTI __has_feature(cxx_rtti)
445
446 // Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if
447 // both the typeid and dynamic_cast features are present.
448 # elif defined(__IBMCPP__) && (__IBMCPP__ >= 900)
449
450 # ifdef __RTTI_ALL__
451 # define GTEST_HAS_RTTI 1
452 # else
453 # define GTEST_HAS_RTTI 0
454 # endif
455
456 # else
457
458 // For all other compilers, we assume RTTI is enabled.
459 # define GTEST_HAS_RTTI 1
460
461 # endif // _MSC_VER
462
463 #endif // GTEST_HAS_RTTI
464
465 // It's this header's responsibility to #include <typeinfo> when RTTI
466 // is enabled.
467 #if GTEST_HAS_RTTI
468 # include <typeinfo>
469 #endif
470
471 // Determines whether Google Test can use the pthreads library.
472 #ifndef GTEST_HAS_PTHREAD
473 // The user didn't tell us explicitly, so we assume pthreads support is
474 // available on Linux and Mac.
475 //
476 // To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0
477 // to your compiler flags.
478 # define GTEST_HAS_PTHREAD (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX \
479 || GTEST_OS_QNX)
480 #endif // GTEST_HAS_PTHREAD
481
482 #if GTEST_HAS_PTHREAD
483 // gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is
484 // true.
485 # include <pthread.h> // NOLINT
486
487 // For timespec and nanosleep, used below.
488 # include <time.h> // NOLINT
489 #endif
490
491 // Determines whether Google Test can use tr1/tuple. You can define
492 // this macro to 0 to prevent Google Test from using tuple (any
493 // feature depending on tuple with be disabled in this mode).
494 #ifndef GTEST_HAS_TR1_TUPLE
495 # if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR)
496 // STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
497 # define GTEST_HAS_TR1_TUPLE 0
498 # else
499 // The user didn't tell us not to do it, so we assume it's OK.
500 # define GTEST_HAS_TR1_TUPLE 1
501 # endif
502 #endif // GTEST_HAS_TR1_TUPLE
503
504 // Determines whether Google Test's own tr1 tuple implementation
505 // should be used.
506 #ifndef GTEST_USE_OWN_TR1_TUPLE
507 // The user didn't tell us, so we need to figure it out.
508
509 // We use our own TR1 tuple if we aren't sure the user has an
510 // implementation of it already. At this time, libstdc++ 4.0.0+ and
511 // MSVC 2010 are the only mainstream standard libraries that come
512 // with a TR1 tuple implementation. NVIDIA's CUDA NVCC compiler
513 // pretends to be GCC by defining __GNUC__ and friends, but cannot
514 // compile GCC's tuple implementation. MSVC 2008 (9.0) provides TR1
515 // tuple in a 323 MB Feature Pack download, which we cannot assume the
516 // user has. QNX's QCC compiler is a modified GCC but it doesn't
517 // support TR1 tuple. libc++ only provides std::tuple, in C++11 mode,
518 // and it can be used with some compilers that define __GNUC__.
519 # if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \
520 && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) || _MSC_VER >= 1600
521 # define GTEST_ENV_HAS_TR1_TUPLE_ 1
522 # endif
523
524 // C++11 specifies that <tuple> provides std::tuple. Use that if gtest is used
525 // in C++11 mode and libstdc++ isn't very old (binaries targeting OS X 10.6
526 // can build with clang but need to use gcc4.2's libstdc++).
527 # if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325)
528 # define GTEST_ENV_HAS_STD_TUPLE_ 1
529 # endif
530
531 # if GTEST_ENV_HAS_TR1_TUPLE_ || GTEST_ENV_HAS_STD_TUPLE_
532 # define GTEST_USE_OWN_TR1_TUPLE 0
533 # else
534 # define GTEST_USE_OWN_TR1_TUPLE 1
535 # endif
536
537 #endif // GTEST_USE_OWN_TR1_TUPLE
538
539 // To avoid conditional compilation everywhere, we make it
540 // gtest-port.h's responsibility to #include the header implementing
541 // tr1/tuple.
542 #if GTEST_HAS_TR1_TUPLE
543
544 # if GTEST_USE_OWN_TR1_TUPLE
545 # include "gtest/internal/gtest-tuple.h"
546 # elif GTEST_ENV_HAS_STD_TUPLE_
547 # include <tuple>
548 // C++11 puts its tuple into the ::std namespace rather than
549 // ::std::tr1. gtest expects tuple to live in ::std::tr1, so put it there.
550 // This causes undefined behavior, but supported compilers react in
551 // the way we intend.
552 namespace std {
553 namespace tr1 {
554 using ::std::get;
555 using ::std::make_tuple;
556 using ::std::tuple;
557 using ::std::tuple_element;
558 using ::std::tuple_size;
559 }
560 }
561
562 # elif GTEST_OS_SYMBIAN
563
564 // On Symbian, BOOST_HAS_TR1_TUPLE causes Boost's TR1 tuple library to
565 // use STLport's tuple implementation, which unfortunately doesn't
566 // work as the copy of STLport distributed with Symbian is incomplete.
567 // By making sure BOOST_HAS_TR1_TUPLE is undefined, we force Boost to
568 // use its own tuple implementation.
569 # ifdef BOOST_HAS_TR1_TUPLE
570 # undef BOOST_HAS_TR1_TUPLE
571 # endif // BOOST_HAS_TR1_TUPLE
572
573 // This prevents <boost/tr1/detail/config.hpp>, which defines
574 // BOOST_HAS_TR1_TUPLE, from being #included by Boost's <tuple>.
575 # define BOOST_TR1_DETAIL_CONFIG_HPP_INCLUDED
576 # include <tuple>
577
578 # elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40000)
579 // GCC 4.0+ implements tr1/tuple in the <tr1/tuple> header. This does
580 // not conform to the TR1 spec, which requires the header to be <tuple>.
581
582 # if !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
583 // Until version 4.3.2, gcc has a bug that causes <tr1/functional>,
584 // which is #included by <tr1/tuple>, to not compile when RTTI is
585 // disabled. _TR1_FUNCTIONAL is the header guard for
586 // <tr1/functional>. Hence the following #define is a hack to prevent
587 // <tr1/functional> from being included.
588 # define _TR1_FUNCTIONAL 1
589 # include <tr1/tuple>
590 # undef _TR1_FUNCTIONAL // Allows the user to #include
591 // <tr1/functional> if he chooses to.
592 # else
593 # include <tr1/tuple> // NOLINT
594 # endif // !GTEST_HAS_RTTI && GTEST_GCC_VER_ < 40302
595
596 # else
597 // If the compiler is not GCC 4.0+, we assume the user is using a
598 // spec-conforming TR1 implementation.
599 # include <tuple> // NOLINT
600 # endif // GTEST_USE_OWN_TR1_TUPLE
601
602 #endif // GTEST_HAS_TR1_TUPLE
603
604 // Determines whether clone(2) is supported.
605 // Usually it will only be available on Linux, excluding
606 // Linux on the Itanium architecture.
607 // Also see http://linux.die.net/man/2/clone.
608 #ifndef GTEST_HAS_CLONE
609 // The user didn't tell us, so we need to figure it out.
610
611 # if GTEST_OS_LINUX && !defined(__ia64__)
612 # if GTEST_OS_LINUX_ANDROID
613 // On Android, clone() is only available on ARM starting with Gingerbread.
614 # if defined(__arm__) && __ANDROID_API__ >= 9
615 # define GTEST_HAS_CLONE 1
616 # else
617 # define GTEST_HAS_CLONE 0
618 # endif
619 # else
620 # define GTEST_HAS_CLONE 1
621 # endif
622 # else
623 # define GTEST_HAS_CLONE 0
624 # endif // GTEST_OS_LINUX && !defined(__ia64__)
625
626 #endif // GTEST_HAS_CLONE
627
628 // Determines whether to support stream redirection. This is used to test
629 // output correctness and to implement death tests.
630 #ifndef GTEST_HAS_STREAM_REDIRECTION
631 // By default, we assume that stream redirection is supported on all
632 // platforms except known mobile ones.
633 # if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN
634 # define GTEST_HAS_STREAM_REDIRECTION 0
635 # else
636 # define GTEST_HAS_STREAM_REDIRECTION 1
637 # endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN
638 #endif // GTEST_HAS_STREAM_REDIRECTION
639
640 // Determines whether to support death tests.
641 // Google Test does not support death tests for VC 7.1 and earlier as
642 // abort() in a VC 7.1 application compiled as GUI in debug config
643 // pops up a dialog window that cannot be suppressed programmatically.
644 #if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
645 (GTEST_OS_MAC && !GTEST_OS_IOS) || GTEST_OS_IOS_SIMULATOR || \
646 (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
647 GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
648 GTEST_OS_OPENBSD || GTEST_OS_QNX)
649 # define GTEST_HAS_DEATH_TEST 1
650 # include <vector> // NOLINT
651 #endif
652
653 // We don't support MSVC 7.1 with exceptions disabled now. Therefore
654 // all the compilers we care about are adequate for supporting
655 // value-parameterized tests.
656 #define GTEST_HAS_PARAM_TEST 1
657
658 // Determines whether to support type-driven tests.
659
660 // Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
661 // Sun Pro CC, IBM Visual Age, and HP aCC support.
662 #if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
663 defined(__IBMCPP__) || defined(__HP_aCC)
664 # define GTEST_HAS_TYPED_TEST 1
665 # define GTEST_HAS_TYPED_TEST_P 1
666 #endif
667
668 // Determines whether to support Combine(). This only makes sense when
669 // value-parameterized tests are enabled. The implementation doesn't
670 // work on Sun Studio since it doesn't understand templated conversion
671 // operators.
672 #if GTEST_HAS_PARAM_TEST && GTEST_HAS_TR1_TUPLE && !defined(__SUNPRO_CC)
673 # define GTEST_HAS_COMBINE 1
674 #endif
675
676 // Determines whether the system compiler uses UTF-16 for encoding wide strings.
677 #define GTEST_WIDE_STRING_USES_UTF16_ \
678 (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_SYMBIAN || GTEST_OS_AIX)
679
680 // Determines whether test results can be streamed to a socket.
681 #if GTEST_OS_LINUX
682 # define GTEST_CAN_STREAM_RESULTS_ 1
683 #endif
684
685 // Defines some utility macros.
686
687 // The GNU compiler emits a warning if nested "if" statements are followed by
688 // an "else" statement and braces are not used to explicitly disambiguate the
689 // "else" binding. This leads to problems with code like:
690 //
691 // if (gate)
692 // ASSERT_*(condition) << "Some message";
693 //
694 // The "switch (0) case 0:" idiom is used to suppress this.
695 #ifdef __INTEL_COMPILER
696 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_
697 #else
698 # define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT
699 #endif
700
701 // Use this annotation at the end of a struct/class definition to
702 // prevent the compiler from optimizing away instances that are never
703 // used. This is useful when all interesting logic happens inside the
704 // c'tor and / or d'tor. Example:
705 //
706 // struct Foo {
707 // Foo() { ... }
708 // } GTEST_ATTRIBUTE_UNUSED_;
709 //
710 // Also use it after a variable or parameter declaration to tell the
711 // compiler the variable/parameter does not have to be used.
712 #if defined(__GNUC__) && !defined(COMPILER_ICC)
713 # define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused))
714 #else
715 # define GTEST_ATTRIBUTE_UNUSED_
716 #endif
717
718 // A macro to disallow operator=
719 // This should be used in the private: declarations for a class.
720 #define GTEST_DISALLOW_ASSIGN_(type)\
721 void operator=(type const &)
722
723 // A macro to disallow copy constructor and operator=
724 // This should be used in the private: declarations for a class.
725 #define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)\
726 type(type const &);\
727 GTEST_DISALLOW_ASSIGN_(type)
728
729 // Tell the compiler to warn about unused return values for functions declared
730 // with this macro. The macro should be used on function declarations
731 // following the argument list:
732 //
733 // Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_;
734 #if defined(__GNUC__) && (GTEST_GCC_VER_ >= 30400) && !defined(COMPILER_ICC)
735 # define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result))
736 #else
737 # define GTEST_MUST_USE_RESULT_
738 #endif // __GNUC__ && (GTEST_GCC_VER_ >= 30400) && !COMPILER_ICC
739
740 // Determine whether the compiler supports Microsoft's Structured Exception
741 // Handling. This is supported by several Windows compilers but generally
742 // does not exist on any other system.
743 #ifndef GTEST_HAS_SEH
744 // The user didn't tell us, so we need to figure it out.
745
746 # if defined(_MSC_VER) || defined(__BORLANDC__)
747 // These two compilers are known to support SEH.
748 # define GTEST_HAS_SEH 1
749 # else
750 // Assume no SEH.
751 # define GTEST_HAS_SEH 0
752 # endif
753
754 #endif // GTEST_HAS_SEH
755
756 #ifdef _MSC_VER
757
758 # if GTEST_LINKED_AS_SHARED_LIBRARY
759 # define GTEST_API_ __declspec(dllimport)
760 # elif GTEST_CREATE_SHARED_LIBRARY
761 # define GTEST_API_ __declspec(dllexport)
762 # endif
763
764 #endif // _MSC_VER
765
766 #ifndef GTEST_API_
767 # define GTEST_API_
768 #endif
769
770 #ifdef __GNUC__
771 // Ask the compiler to never inline a given function.
772 # define GTEST_NO_INLINE_ __attribute__((noinline))
773 #else
774 # define GTEST_NO_INLINE_
775 #endif
776
777 // _LIBCPP_VERSION is defined by the libc++ library from the LLVM project.
778 #if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION)
779 # define GTEST_HAS_CXXABI_H_ 1
780 #else
781 # define GTEST_HAS_CXXABI_H_ 0
782 #endif
783
784 namespace testing {
785
786 class Message;
787
788 namespace internal {
789
790 // A secret type that Google Test users don't know about. It has no
791 // definition on purpose. Therefore it's impossible to create a
792 // Secret object, which is what we want.
793 class Secret;
794
795 // The GTEST_COMPILE_ASSERT_ macro can be used to verify that a compile time
796 // expression is true. For example, you could use it to verify the
797 // size of a static array:
798 //
799 // GTEST_COMPILE_ASSERT_(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
800 // content_type_names_incorrect_size);
801 //
802 // or to make sure a struct is smaller than a certain size:
803 //
804 // GTEST_COMPILE_ASSERT_(sizeof(foo) < 128, foo_too_large);
805 //
806 // The second argument to the macro is the name of the variable. If
807 // the expression is false, most compilers will issue a warning/error
808 // containing the name of the variable.
809
810 template <bool>
811 struct CompileAssert {
812 };
813
814 #define GTEST_COMPILE_ASSERT_(expr, msg) \
815 typedef ::testing::internal::CompileAssert<(static_cast<bool>(expr))> \
816 msg[static_cast<bool>(expr) ? 1 : -1] GTEST_ATTRIBUTE_UNUSED_
817
818 // Implementation details of GTEST_COMPILE_ASSERT_:
819 //
820 // - GTEST_COMPILE_ASSERT_ works by defining an array type that has -1
821 // elements (and thus is invalid) when the expression is false.
822 //
823 // - The simpler definition
824 //
825 // #define GTEST_COMPILE_ASSERT_(expr, msg) typedef char msg[(expr) ? 1 : -1]
826 //
827 // does not work, as gcc supports variable-length arrays whose sizes
828 // are determined at run-time (this is gcc's extension and not part
829 // of the C++ standard). As a result, gcc fails to reject the
830 // following code with the simple definition:
831 //
832 // int foo;
833 // GTEST_COMPILE_ASSERT_(foo, msg); // not supposed to compile as foo is
834 // // not a compile-time constant.
835 //
836 // - By using the type CompileAssert<(bool(expr))>, we ensures that
837 // expr is a compile-time constant. (Template arguments must be
838 // determined at compile-time.)
839 //
840 // - The outter parentheses in CompileAssert<(bool(expr))> are necessary
841 // to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
842 //
843 // CompileAssert<bool(expr)>
844 //
845 // instead, these compilers will refuse to compile
846 //
847 // GTEST_COMPILE_ASSERT_(5 > 0, some_message);
848 //
849 // (They seem to think the ">" in "5 > 0" marks the end of the
850 // template argument list.)
851 //
852 // - The array size is (bool(expr) ? 1 : -1), instead of simply
853 //
854 // ((expr) ? 1 : -1).
855 //
856 // This is to avoid running into a bug in MS VC 7.1, which
857 // causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
858
859 // StaticAssertTypeEqHelper is used by StaticAssertTypeEq defined in gtest.h.
860 //
861 // This template is declared, but intentionally undefined.
862 template <typename T1, typename T2>
863 struct StaticAssertTypeEqHelper;
864
865 template <typename T>
866 struct StaticAssertTypeEqHelper<T, T> {};
867
868 #if GTEST_HAS_GLOBAL_STRING
869 typedef ::string string;
870 #else
871 typedef ::std::string string;
872 #endif // GTEST_HAS_GLOBAL_STRING
873
874 #if GTEST_HAS_GLOBAL_WSTRING
875 typedef ::wstring wstring;
876 #elif GTEST_HAS_STD_WSTRING
877 typedef ::std::wstring wstring;
878 #endif // GTEST_HAS_GLOBAL_WSTRING
879
880 // A helper for suppressing warnings on constant condition. It just
881 // returns 'condition'.
882 GTEST_API_ bool IsTrue(bool condition);
883
884 // Defines scoped_ptr.
885
886 // This implementation of scoped_ptr is PARTIAL - it only contains
887 // enough stuff to satisfy Google Test's need.
888 template <typename T>
889 class scoped_ptr {
890 public:
891 typedef T element_type;
892
893 explicit scoped_ptr(T* p = NULL) : ptr_(p) {}
894 ~scoped_ptr() { reset(); }
895
896 T& operator*() const { return *ptr_; }
897 T* operator->() const { return ptr_; }
898 T* get() const { return ptr_; }
899
900 T* release() {
901 T* const ptr = ptr_;
902 ptr_ = NULL;
903 return ptr;
904 }
905
906 void reset(T* p = NULL) {
907 if (p != ptr_) {
908 if (IsTrue(sizeof(T) > 0)) { // Makes sure T is a complete type.
909 delete ptr_;
910 }
911 ptr_ = p;
912 }
913 }
914
915 private:
916 T* ptr_;
917
918 GTEST_DISALLOW_COPY_AND_ASSIGN_(scoped_ptr);
919 };
920
921 // Defines RE.
922
923 // A simple C++ wrapper for <regex.h>. It uses the POSIX Extended
924 // Regular Expression syntax.
925 class GTEST_API_ RE {
926 public:
927 // A copy constructor is required by the Standard to initialize object
928 // references from r-values.
929 RE(const RE& other) { Init(other.pattern()); }
930
931 // Constructs an RE from a string.
932 RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT
933
934 #if GTEST_HAS_GLOBAL_STRING
935
936 RE(const ::string& regex) { Init(regex.c_str()); } // NOLINT
937
938 #endif // GTEST_HAS_GLOBAL_STRING
939
940 RE(const char* regex) { Init(regex); } // NOLINT
941 ~RE();
942
943 // Returns the string representation of the regex.
944 const char* pattern() const { return pattern_; }
945
946 // FullMatch(str, re) returns true iff regular expression re matches
947 // the entire str.
948 // PartialMatch(str, re) returns true iff regular expression re
949 // matches a substring of str (including str itself).
950 //
951 // TODO(wan@google.com): make FullMatch() and PartialMatch() work
952 // when str contains NUL characters.
953 static bool FullMatch(const ::std::string& str, const RE& re) {
954 return FullMatch(str.c_str(), re);
955 }
956 static bool PartialMatch(const ::std::string& str, const RE& re) {
957 return PartialMatch(str.c_str(), re);
958 }
959
960 #if GTEST_HAS_GLOBAL_STRING
961
962 static bool FullMatch(const ::string& str, const RE& re) {
963 return FullMatch(str.c_str(), re);
964 }
965 static bool PartialMatch(const ::string& str, const RE& re) {
966 return PartialMatch(str.c_str(), re);
967 }
968
969 #endif // GTEST_HAS_GLOBAL_STRING
970
971 static bool FullMatch(const char* str, const RE& re);
972 static bool PartialMatch(const char* str, const RE& re);
973
974 private:
975 void Init(const char* regex);
976
977 // We use a const char* instead of an std::string, as Google Test used to be
978 // used where std::string is not available. TODO(wan@google.com): change to
979 // std::string.
980 const char* pattern_;
981 bool is_valid_;
982
983 #if GTEST_USES_POSIX_RE
984
985 regex_t full_regex_; // For FullMatch().
986 regex_t partial_regex_; // For PartialMatch().
987
988 #else // GTEST_USES_SIMPLE_RE
989
990 const char* full_pattern_; // For FullMatch();
991
992 #endif
993
994 GTEST_DISALLOW_ASSIGN_(RE);
995 };
996
997 // Formats a source file path and a line number as they would appear
998 // in an error message from the compiler used to compile this code.
999 GTEST_API_ ::std::string FormatFileLocation(const char* file, int line);
1000
1001 // Formats a file location for compiler-independent XML output.
1002 // Although this function is not platform dependent, we put it next to
1003 // FormatFileLocation in order to contrast the two functions.
1004 GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file,
1005 int line);
1006
1007 // Defines logging utilities:
1008 // GTEST_LOG_(severity) - logs messages at the specified severity level. The
1009 // message itself is streamed into the macro.
1010 // LogToStderr() - directs all log messages to stderr.
1011 // FlushInfoLog() - flushes informational log messages.
1012
1013 enum GTestLogSeverity {
1014 GTEST_INFO,
1015 GTEST_WARNING,
1016 GTEST_ERROR,
1017 GTEST_FATAL
1018 };
1019
1020 // Formats log entry severity, provides a stream object for streaming the
1021 // log message, and terminates the message with a newline when going out of
1022 // scope.
1023 class GTEST_API_ GTestLog {
1024 public:
1025 GTestLog(GTestLogSeverity severity, const char* file, int line);
1026
1027 // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
1028 ~GTestLog();
1029
1030 ::std::ostream& GetStream() { return ::std::cerr; }
1031
1032 private:
1033 const GTestLogSeverity severity_;
1034
1035 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog);
1036 };
1037
1038 #define GTEST_LOG_(severity) \
1039 ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \
1040 __FILE__, __LINE__).GetStream()
1041
1042 inline void LogToStderr() {}
1043 inline void FlushInfoLog() { fflush(NULL); }
1044
1045 // INTERNAL IMPLEMENTATION - DO NOT USE.
1046 //
1047 // GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
1048 // is not satisfied.
1049 // Synopsys:
1050 // GTEST_CHECK_(boolean_condition);
1051 // or
1052 // GTEST_CHECK_(boolean_condition) << "Additional message";
1053 //
1054 // This checks the condition and if the condition is not satisfied
1055 // it prints message about the condition violation, including the
1056 // condition itself, plus additional message streamed into it, if any,
1057 // and then it aborts the program. It aborts the program irrespective of
1058 // whether it is built in the debug mode or not.
1059 #define GTEST_CHECK_(condition) \
1060 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
1061 if (::testing::internal::IsTrue(condition)) \
1062 ; \
1063 else \
1064 GTEST_LOG_(FATAL) << "Condition " #condition " failed. "
1065
1066 // An all-mode assert to verify that the given POSIX-style function
1067 // call returns 0 (indicating success). Known limitation: this
1068 // doesn't expand to a balanced 'if' statement, so enclose the macro
1069 // in {} if you need to use it as the only statement in an 'if'
1070 // branch.
1071 #define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \
1072 if (const int gtest_error = (posix_call)) \
1073 GTEST_LOG_(FATAL) << #posix_call << "failed with error " \
1074 << gtest_error
1075
1076 // INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
1077 //
1078 // Use ImplicitCast_ as a safe version of static_cast for upcasting in
1079 // the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a
1080 // const Foo*). When you use ImplicitCast_, the compiler checks that
1081 // the cast is safe. Such explicit ImplicitCast_s are necessary in
1082 // surprisingly many situations where C++ demands an exact type match
1083 // instead of an argument type convertable to a target type.
1084 //
1085 // The syntax for using ImplicitCast_ is the same as for static_cast:
1086 //
1087 // ImplicitCast_<ToType>(expr)
1088 //
1089 // ImplicitCast_ would have been part of the C++ standard library,
1090 // but the proposal was submitted too late. It will probably make
1091 // its way into the language in the future.
1092 //
1093 // This relatively ugly name is intentional. It prevents clashes with
1094 // similar functions users may have (e.g., implicit_cast). The internal
1095 // namespace alone is not enough because the function can be found by ADL.
1096 template<typename To>
1097 inline To ImplicitCast_(To x) { return x; }
1098
1099 // When you upcast (that is, cast a pointer from type Foo to type
1100 // SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts
1101 // always succeed. When you downcast (that is, cast a pointer from
1102 // type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
1103 // how do you know the pointer is really of type SubclassOfFoo? It
1104 // could be a bare Foo, or of type DifferentSubclassOfFoo. Thus,
1105 // when you downcast, you should use this macro. In debug mode, we
1106 // use dynamic_cast<> to double-check the downcast is legal (we die
1107 // if it's not). In normal mode, we do the efficient static_cast<>
1108 // instead. Thus, it's important to test in debug mode to make sure
1109 // the cast is legal!
1110 // This is the only place in the code we should use dynamic_cast<>.
1111 // In particular, you SHOULDN'T be using dynamic_cast<> in order to
1112 // do RTTI (eg code like this:
1113 // if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
1114 // if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
1115 // You should design the code some other way not to need this.
1116 //
1117 // This relatively ugly name is intentional. It prevents clashes with
1118 // similar functions users may have (e.g., down_cast). The internal
1119 // namespace alone is not enough because the function can be found by ADL.
1120 template<typename To, typename From> // use like this: DownCast_<T*>(foo);
1121 inline To DownCast_(From* f) { // so we only accept pointers
1122 // Ensures that To is a sub-type of From *. This test is here only
1123 // for compile-time type checking, and has no overhead in an
1124 // optimized build at run-time, as it will be optimized away
1125 // completely.
1126 if (false) {
1127 const To to = NULL;
1128 ::testing::internal::ImplicitCast_<From*>(to);
1129 }
1130
1131 #if GTEST_HAS_RTTI
1132 // RTTI: debug mode only!
1133 GTEST_CHECK_(f == NULL || dynamic_cast<To>(f) != NULL);
1134 #endif
1135 return static_cast<To>(f);
1136 }
1137
1138 // Downcasts the pointer of type Base to Derived.
1139 // Derived must be a subclass of Base. The parameter MUST
1140 // point to a class of type Derived, not any subclass of it.
1141 // When RTTI is available, the function performs a runtime
1142 // check to enforce this.
1143 template <class Derived, class Base>
1144 Derived* CheckedDowncastToActualType(Base* base) {
1145 #if GTEST_HAS_RTTI
1146 GTEST_CHECK_(typeid(*base) == typeid(Derived));
1147 return dynamic_cast<Derived*>(base); // NOLINT
1148 #else
1149 return static_cast<Derived*>(base); // Poor man's downcast.
1150 #endif
1151 }
1152
1153 #if GTEST_HAS_STREAM_REDIRECTION
1154
1155 // Defines the stderr capturer:
1156 // CaptureStdout - starts capturing stdout.
1157 // GetCapturedStdout - stops capturing stdout and returns the captured string.
1158 // CaptureStderr - starts capturing stderr.
1159 // GetCapturedStderr - stops capturing stderr and returns the captured string.
1160 //
1161 GTEST_API_ void CaptureStdout();
1162 GTEST_API_ std::string GetCapturedStdout();
1163 GTEST_API_ void CaptureStderr();
1164 GTEST_API_ std::string GetCapturedStderr();
1165
1166 #endif // GTEST_HAS_STREAM_REDIRECTION
1167
1168
1169 #if GTEST_HAS_DEATH_TEST
1170
1171 const ::std::vector<testing::internal::string>& GetInjectableArgvs();
1172 void SetInjectableArgvs(const ::std::vector<testing::internal::string>*
1173 new_argvs);
1174
1175 // A copy of all command line arguments. Set by InitGoogleTest().
1176 extern ::std::vector<testing::internal::string> g_argvs;
1177
1178 #endif // GTEST_HAS_DEATH_TEST
1179
1180 // Defines synchronization primitives.
1181
1182 #if GTEST_HAS_PTHREAD
1183
1184 // Sleeps for (roughly) n milli-seconds. This function is only for
1185 // testing Google Test's own constructs. Don't use it in user tests,
1186 // either directly or indirectly.
1187 inline void SleepMilliseconds(int n) {
1188 const timespec time = {
1189 0, // 0 seconds.
1190 n * 1000L * 1000L, // And n ms.
1191 };
1192 nanosleep(&time, NULL);
1193 }
1194
1195 // Allows a controller thread to pause execution of newly created
1196 // threads until notified. Instances of this class must be created
1197 // and destroyed in the controller thread.
1198 //
1199 // This class is only for testing Google Test's own constructs. Do not
1200 // use it in user tests, either directly or indirectly.
1201 class Notification {
1202 public:
1203 Notification() : notified_(false) {
1204 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
1205 }
1206 ~Notification() {
1207 pthread_mutex_destroy(&mutex_);
1208 }
1209
1210 // Notifies all threads created with this notification to start. Must
1211 // be called from the controller thread.
1212 void Notify() {
1213 pthread_mutex_lock(&mutex_);
1214 notified_ = true;
1215 pthread_mutex_unlock(&mutex_);
1216 }
1217
1218 // Blocks until the controller thread notifies. Must be called from a test
1219 // thread.
1220 void WaitForNotification() {
1221 for (;;) {
1222 pthread_mutex_lock(&mutex_);
1223 const bool notified = notified_;
1224 pthread_mutex_unlock(&mutex_);
1225 if (notified)
1226 break;
1227 SleepMilliseconds(10);
1228 }
1229 }
1230
1231 private:
1232 pthread_mutex_t mutex_;
1233 bool notified_;
1234
1235 GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification);
1236 };
1237
1238 // As a C-function, ThreadFuncWithCLinkage cannot be templated itself.
1239 // Consequently, it cannot select a correct instantiation of ThreadWithParam
1240 // in order to call its Run(). Introducing ThreadWithParamBase as a
1241 // non-templated base class for ThreadWithParam allows us to bypass this
1242 // problem.
1243 class ThreadWithParamBase {
1244 public:
1245 virtual ~ThreadWithParamBase() {}
1246 virtual void Run() = 0;
1247 };
1248
1249 // pthread_create() accepts a pointer to a function type with the C linkage.
1250 // According to the Standard (7.5/1), function types with different linkages
1251 // are different even if they are otherwise identical. Some compilers (for
1252 // example, SunStudio) treat them as different types. Since class methods
1253 // cannot be defined with C-linkage we need to define a free C-function to
1254 // pass into pthread_create().
1255 extern "C" inline void* ThreadFuncWithCLinkage(void* thread) {
1256 static_cast<ThreadWithParamBase*>(thread)->Run();
1257 return NULL;
1258 }
1259
1260 // Helper class for testing Google Test's multi-threading constructs.
1261 // To use it, write:
1262 //
1263 // void ThreadFunc(int param) { /* Do things with param */ }
1264 // Notification thread_can_start;
1265 // ...
1266 // // The thread_can_start parameter is optional; you can supply NULL.
1267 // ThreadWithParam<int> thread(&ThreadFunc, 5, &thread_can_start);
1268 // thread_can_start.Notify();
1269 //
1270 // These classes are only for testing Google Test's own constructs. Do
1271 // not use them in user tests, either directly or indirectly.
1272 template <typename T>
1273 class ThreadWithParam : public ThreadWithParamBase {
1274 public:
1275 typedef void (*UserThreadFunc)(T);
1276
1277 ThreadWithParam(
1278 UserThreadFunc func, T param, Notification* thread_can_start)
1279 : func_(func),
1280 param_(param),
1281 thread_can_start_(thread_can_start),
1282 finished_(false) {
1283 ThreadWithParamBase* const base = this;
1284 // The thread can be created only after all fields except thread_
1285 // have been initialized.
1286 GTEST_CHECK_POSIX_SUCCESS_(
1287 pthread_create(&thread_, 0, &ThreadFuncWithCLinkage, base));
1288 }
1289 ~ThreadWithParam() { Join(); }
1290
1291 void Join() {
1292 if (!finished_) {
1293 GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, 0));
1294 finished_ = true;
1295 }
1296 }
1297
1298 virtual void Run() {
1299 if (thread_can_start_ != NULL)
1300 thread_can_start_->WaitForNotification();
1301 func_(param_);
1302 }
1303
1304 private:
1305 const UserThreadFunc func_; // User-supplied thread function.
1306 const T param_; // User-supplied parameter to the thread function.
1307 // When non-NULL, used to block execution until the controller thread
1308 // notifies.
1309 Notification* const thread_can_start_;
1310 bool finished_; // true iff we know that the thread function has finished.
1311 pthread_t thread_; // The native thread object.
1312
1313 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam);
1314 };
1315
1316 // MutexBase and Mutex implement mutex on pthreads-based platforms. They
1317 // are used in conjunction with class MutexLock:
1318 //
1319 // Mutex mutex;
1320 // ...
1321 // MutexLock lock(&mutex); // Acquires the mutex and releases it at the end
1322 // // of the current scope.
1323 //
1324 // MutexBase implements behavior for both statically and dynamically
1325 // allocated mutexes. Do not use MutexBase directly. Instead, write
1326 // the following to define a static mutex:
1327 //
1328 // GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex);
1329 //
1330 // You can forward declare a static mutex like this:
1331 //
1332 // GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex);
1333 //
1334 // To create a dynamic mutex, just define an object of type Mutex.
1335 class MutexBase {
1336 public:
1337 // Acquires this mutex.
1338 void Lock() {
1339 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_));
1340 owner_ = pthread_self();
1341 has_owner_ = true;
1342 }
1343
1344 // Releases this mutex.
1345 void Unlock() {
1346 // Since the lock is being released the owner_ field should no longer be
1347 // considered valid. We don't protect writing to has_owner_ here, as it's
1348 // the caller's responsibility to ensure that the current thread holds the
1349 // mutex when this is called.
1350 has_owner_ = false;
1351 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_));
1352 }
1353
1354 // Does nothing if the current thread holds the mutex. Otherwise, crashes
1355 // with high probability.
1356 void AssertHeld() const {
1357 GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self()))
1358 << "The current thread is not holding the mutex @" << this;
1359 }
1360
1361 // A static mutex may be used before main() is entered. It may even
1362 // be used before the dynamic initialization stage. Therefore we
1363 // must be able to initialize a static mutex object at link time.
1364 // This means MutexBase has to be a POD and its member variables
1365 // have to be public.
1366 public:
1367 pthread_mutex_t mutex_; // The underlying pthread mutex.
1368 // has_owner_ indicates whether the owner_ field below contains a valid thread
1369 // ID and is therefore safe to inspect (e.g., to use in pthread_equal()). All
1370 // accesses to the owner_ field should be protected by a check of this field.
1371 // An alternative might be to memset() owner_ to all zeros, but there's no
1372 // guarantee that a zero'd pthread_t is necessarily invalid or even different
1373 // from pthread_self().
1374 bool has_owner_;
1375 pthread_t owner_; // The thread holding the mutex.
1376 };
1377
1378 // Forward-declares a static mutex.
1379 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
1380 extern ::testing::internal::MutexBase mutex
1381
1382 // Defines and statically (i.e. at link time) initializes a static mutex.
1383 // The initialization list here does not explicitly initialize each field,
1384 // instead relying on default initialization for the unspecified fields. In
1385 // particular, the owner_ field (a pthread_t) is not explicitly initialized.
1386 // This allows initialization to work whether pthread_t is a scalar or struct.
1387 // The flag -Wmissing-field-initializers must not be specified for this to work.
1388 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
1389 ::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER, false }
1390
1391 // The Mutex class can only be used for mutexes created at runtime. It
1392 // shares its API with MutexBase otherwise.
1393 class Mutex : public MutexBase {
1394 public:
1395 Mutex() {
1396 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL));
1397 has_owner_ = false;
1398 }
1399 ~Mutex() {
1400 GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_));
1401 }
1402
1403 private:
1404 GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex);
1405 };
1406
1407 // We cannot name this class MutexLock as the ctor declaration would
1408 // conflict with a macro named MutexLock, which is defined on some
1409 // platforms. Hence the typedef trick below.
1410 class GTestMutexLock {
1411 public:
1412 explicit GTestMutexLock(MutexBase* mutex)
1413 : mutex_(mutex) { mutex_->Lock(); }
1414
1415 ~GTestMutexLock() { mutex_->Unlock(); }
1416
1417 private:
1418 MutexBase* const mutex_;
1419
1420 GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock);
1421 };
1422
1423 typedef GTestMutexLock MutexLock;
1424
1425 // Helpers for ThreadLocal.
1426
1427 // pthread_key_create() requires DeleteThreadLocalValue() to have
1428 // C-linkage. Therefore it cannot be templatized to access
1429 // ThreadLocal<T>. Hence the need for class
1430 // ThreadLocalValueHolderBase.
1431 class ThreadLocalValueHolderBase {
1432 public:
1433 virtual ~ThreadLocalValueHolderBase() {}
1434 };
1435
1436 // Called by pthread to delete thread-local data stored by
1437 // pthread_setspecific().
1438 extern "C" inline void DeleteThreadLocalValue(void* value_holder) {
1439 delete static_cast<ThreadLocalValueHolderBase*>(value_holder);
1440 }
1441
1442 // Implements thread-local storage on pthreads-based systems.
1443 //
1444 // // Thread 1
1445 // ThreadLocal<int> tl(100); // 100 is the default value for each thread.
1446 //
1447 // // Thread 2
1448 // tl.set(150); // Changes the value for thread 2 only.
1449 // EXPECT_EQ(150, tl.get());
1450 //
1451 // // Thread 1
1452 // EXPECT_EQ(100, tl.get()); // In thread 1, tl has the original value.
1453 // tl.set(200);
1454 // EXPECT_EQ(200, tl.get());
1455 //
1456 // The template type argument T must have a public copy constructor.
1457 // In addition, the default ThreadLocal constructor requires T to have
1458 // a public default constructor.
1459 //
1460 // An object managed for a thread by a ThreadLocal instance is deleted
1461 // when the thread exits. Or, if the ThreadLocal instance dies in
1462 // that thread, when the ThreadLocal dies. It's the user's
1463 // responsibility to ensure that all other threads using a ThreadLocal
1464 // have exited when it dies, or the per-thread objects for those
1465 // threads will not be deleted.
1466 //
1467 // Google Test only uses global ThreadLocal objects. That means they
1468 // will die after main() has returned. Therefore, no per-thread
1469 // object managed by Google Test will be leaked as long as all threads
1470 // using Google Test have exited when main() returns.
1471 template <typename T>
1472 class ThreadLocal {
1473 public:
1474 ThreadLocal() : key_(CreateKey()),
1475 default_() {}
1476 explicit ThreadLocal(const T& value) : key_(CreateKey()),
1477 default_(value) {}
1478
1479 ~ThreadLocal() {
1480 // Destroys the managed object for the current thread, if any.
1481 DeleteThreadLocalValue(pthread_getspecific(key_));
1482
1483 // Releases resources associated with the key. This will *not*
1484 // delete managed objects for other threads.
1485 GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_));
1486 }
1487
1488 T* pointer() { return GetOrCreateValue(); }
1489 const T* pointer() const { return GetOrCreateValue(); }
1490 const T& get() const { return *pointer(); }
1491 void set(const T& value) { *pointer() = value; }
1492
1493 private:
1494 // Holds a value of type T.
1495 class ValueHolder : public ThreadLocalValueHolderBase {
1496 public:
1497 explicit ValueHolder(const T& value) : value_(value) {}
1498
1499 T* pointer() { return &value_; }
1500
1501 private:
1502 T value_;
1503 GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder);
1504 };
1505
1506 static pthread_key_t CreateKey() {
1507 pthread_key_t key;
1508 // When a thread exits, DeleteThreadLocalValue() will be called on
1509 // the object managed for that thread.
1510 GTEST_CHECK_POSIX_SUCCESS_(
1511 pthread_key_create(&key, &DeleteThreadLocalValue));
1512 return key;
1513 }
1514
1515 T* GetOrCreateValue() const {
1516 ThreadLocalValueHolderBase* const holder =
1517 static_cast<ThreadLocalValueHolderBase*>(pthread_getspecific(key_));
1518 if (holder != NULL) {
1519 return CheckedDowncastToActualType<ValueHolder>(holder)->pointer();
1520 }
1521
1522 ValueHolder* const new_holder = new ValueHolder(default_);
1523 ThreadLocalValueHolderBase* const holder_base = new_holder;
1524 GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base));
1525 return new_holder->pointer();
1526 }
1527
1528 // A key pthreads uses for looking up per-thread values.
1529 const pthread_key_t key_;
1530 const T default_; // The default value for each thread.
1531
1532 GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal);
1533 };
1534
1535 # define GTEST_IS_THREADSAFE 1
1536
1537 #else // GTEST_HAS_PTHREAD
1538
1539 // A dummy implementation of synchronization primitives (mutex, lock,
1540 // and thread-local variable). Necessary for compiling Google Test where
1541 // mutex is not supported - using Google Test in multiple threads is not
1542 // supported on such platforms.
1543
1544 class Mutex {
1545 public:
1546 Mutex() {}
1547 void Lock() {}
1548 void Unlock() {}
1549 void AssertHeld() const {}
1550 };
1551
1552 # define GTEST_DECLARE_STATIC_MUTEX_(mutex) \
1553 extern ::testing::internal::Mutex mutex
1554
1555 # define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex
1556
1557 class GTestMutexLock {
1558 public:
1559 explicit GTestMutexLock(Mutex*) {} // NOLINT
1560 };
1561
1562 typedef GTestMutexLock MutexLock;
1563
1564 template <typename T>
1565 class ThreadLocal {
1566 public:
1567 ThreadLocal() : value_() {}
1568 explicit ThreadLocal(const T& value) : value_(value) {}
1569 T* pointer() { return &value_; }
1570 const T* pointer() const { return &value_; }
1571 const T& get() const { return value_; }
1572 void set(const T& value) { value_ = value; }
1573 private:
1574 T value_;
1575 };
1576
1577 // The above synchronization primitives have dummy implementations.
1578 // Therefore Google Test is not thread-safe.
1579 # define GTEST_IS_THREADSAFE 0
1580
1581 #endif // GTEST_HAS_PTHREAD
1582
1583 // Returns the number of threads running in the process, or 0 to indicate that
1584 // we cannot detect it.
1585 GTEST_API_ size_t GetThreadCount();
1586
1587 // Passing non-POD classes through ellipsis (...) crashes the ARM
1588 // compiler and generates a warning in Sun Studio. The Nokia Symbian
1589 // and the IBM XL C/C++ compiler try to instantiate a copy constructor
1590 // for objects passed through ellipsis (...), failing for uncopyable
1591 // objects. We define this to ensure that only POD is passed through
1592 // ellipsis on these systems.
1593 #if defined(__SYMBIAN32__) || defined(__IBMCPP__) || defined(__SUNPRO_CC)
1594 // We lose support for NULL detection where the compiler doesn't like
1595 // passing non-POD classes through ellipsis (...).
1596 # define GTEST_ELLIPSIS_NEEDS_POD_ 1
1597 #else
1598 # define GTEST_CAN_COMPARE_NULL 1
1599 #endif
1600
1601 // The Nokia Symbian and IBM XL C/C++ compilers cannot decide between
1602 // const T& and const T* in a function template. These compilers
1603 // _can_ decide between class template specializations for T and T*,
1604 // so a tr1::type_traits-like is_pointer works.
1605 #if defined(__SYMBIAN32__) || defined(__IBMCPP__)
1606 # define GTEST_NEEDS_IS_POINTER_ 1
1607 #endif
1608
1609 template <bool bool_value>
1610 struct bool_constant {
1611 typedef bool_constant<bool_value> type;
1612 static const bool value = bool_value;
1613 };
1614 template <bool bool_value> const bool bool_constant<bool_value>::value;
1615
1616 typedef bool_constant<false> false_type;
1617 typedef bool_constant<true> true_type;
1618
1619 template <typename T>
1620 struct is_pointer : public false_type {};
1621
1622 template <typename T>
1623 struct is_pointer<T*> : public true_type {};
1624
1625 template <typename Iterator>
1626 struct IteratorTraits {
1627 typedef typename Iterator::value_type value_type;
1628 };
1629
1630 template <typename T>
1631 struct IteratorTraits<T*> {
1632 typedef T value_type;
1633 };
1634
1635 template <typename T>
1636 struct IteratorTraits<const T*> {
1637 typedef T value_type;
1638 };
1639
1640 #if GTEST_OS_WINDOWS
1641 # define GTEST_PATH_SEP_ "\\"
1642 # define GTEST_HAS_ALT_PATH_SEP_ 1
1643 // The biggest signed integer type the compiler supports.
1644 typedef __int64 BiggestInt;
1645 #else
1646 # define GTEST_PATH_SEP_ "/"
1647 # define GTEST_HAS_ALT_PATH_SEP_ 0
1648 typedef long long BiggestInt; // NOLINT
1649 #endif // GTEST_OS_WINDOWS
1650
1651 // Utilities for char.
1652
1653 // isspace(int ch) and friends accept an unsigned char or EOF. char
1654 // may be signed, depending on the compiler (or compiler flags).
1655 // Therefore we need to cast a char to unsigned char before calling
1656 // isspace(), etc.
1657
1658 inline bool IsAlpha(char ch) {
1659 return isalpha(static_cast<unsigned char>(ch)) != 0;
1660 }
1661 inline bool IsAlNum(char ch) {
1662 return isalnum(static_cast<unsigned char>(ch)) != 0;
1663 }
1664 inline bool IsDigit(char ch) {
1665 return isdigit(static_cast<unsigned char>(ch)) != 0;
1666 }
1667 inline bool IsLower(char ch) {
1668 return islower(static_cast<unsigned char>(ch)) != 0;
1669 }
1670 inline bool IsSpace(char ch) {
1671 return isspace(static_cast<unsigned char>(ch)) != 0;
1672 }
1673 inline bool IsUpper(char ch) {
1674 return isupper(static_cast<unsigned char>(ch)) != 0;
1675 }
1676 inline bool IsXDigit(char ch) {
1677 return isxdigit(static_cast<unsigned char>(ch)) != 0;
1678 }
1679 inline bool IsXDigit(wchar_t ch) {
1680 const unsigned char low_byte = static_cast<unsigned char>(ch);
1681 return ch == low_byte && isxdigit(low_byte) != 0;
1682 }
1683
1684 inline char ToLower(char ch) {
1685 return static_cast<char>(tolower(static_cast<unsigned char>(ch)));
1686 }
1687 inline char ToUpper(char ch) {
1688 return static_cast<char>(toupper(static_cast<unsigned char>(ch)));
1689 }
1690
1691 // The testing::internal::posix namespace holds wrappers for common
1692 // POSIX functions. These wrappers hide the differences between
1693 // Windows/MSVC and POSIX systems. Since some compilers define these
1694 // standard functions as macros, the wrapper cannot have the same name
1695 // as the wrapped function.
1696
1697 namespace posix {
1698
1699 // Functions with a different name on Windows.
1700
1701 #if GTEST_OS_WINDOWS
1702
1703 typedef struct _stat StatStruct;
1704
1705 # ifdef __BORLANDC__
1706 inline int IsATTY(int fd) { return isatty(fd); }
1707 inline int StrCaseCmp(const char* s1, const char* s2) {
1708 return stricmp(s1, s2);
1709 }
1710 inline char* StrDup(const char* src) { return strdup(src); }
1711 # else // !__BORLANDC__
1712 # if GTEST_OS_WINDOWS_MOBILE
1713 inline int IsATTY(int /* fd */) { return 0; }
1714 # else
1715 inline int IsATTY(int fd) { return _isatty(fd); }
1716 # endif // GTEST_OS_WINDOWS_MOBILE
1717 inline int StrCaseCmp(const char* s1, const char* s2) {
1718 return _stricmp(s1, s2);
1719 }
1720 inline char* StrDup(const char* src) { return _strdup(src); }
1721 # endif // __BORLANDC__
1722
1723 # if GTEST_OS_WINDOWS_MOBILE
1724 inline int FileNo(FILE* file) { return reinterpret_cast<int>(_fileno(file)); }
1725 // Stat(), RmDir(), and IsDir() are not needed on Windows CE at this
1726 // time and thus not defined there.
1727 # else
1728 inline int FileNo(FILE* file) { return _fileno(file); }
1729 inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); }
1730 inline int RmDir(const char* dir) { return _rmdir(dir); }
1731 inline bool IsDir(const StatStruct& st) {
1732 return (_S_IFDIR & st.st_mode) != 0;
1733 }
1734 # endif // GTEST_OS_WINDOWS_MOBILE
1735
1736 #else
1737
1738 typedef struct stat StatStruct;
1739
1740 inline int FileNo(FILE* file) { return fileno(file); }
1741 inline int IsATTY(int fd) { return isatty(fd); }
1742 inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); }
1743 inline int StrCaseCmp(const char* s1, const char* s2) {
1744 return strcasecmp(s1, s2);
1745 }
1746 inline char* StrDup(const char* src) { return strdup(src); }
1747 inline int RmDir(const char* dir) { return rmdir(dir); }
1748 inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
1749
1750 #endif // GTEST_OS_WINDOWS
1751
1752 // Functions deprecated by MSVC 8.0.
1753
1754 #ifdef _MSC_VER
1755 // Temporarily disable warning 4996 (deprecated function).
1756 # pragma warning(push)
1757 # pragma warning(disable:4996)
1758 #endif
1759
1760 inline const char* StrNCpy(char* dest, const char* src, size_t n) {
1761 return strncpy(dest, src, n);
1762 }
1763
1764 // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and
1765 // StrError() aren't needed on Windows CE at this time and thus not
1766 // defined there.
1767
1768 #if !GTEST_OS_WINDOWS_MOBILE
1769 inline int ChDir(const char* dir) { return chdir(dir); }
1770 #endif
1771 inline FILE* FOpen(const char* path, const char* mode) {
1772 return fopen(path, mode);
1773 }
1774 #if !GTEST_OS_WINDOWS_MOBILE
1775 inline FILE *FReopen(const char* path, const char* mode, FILE* stream) {
1776 return freopen(path, mode, stream);
1777 }
1778 inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); }
1779 #endif
1780 inline int FClose(FILE* fp) { return fclose(fp); }
1781 #if !GTEST_OS_WINDOWS_MOBILE
1782 inline int Read(int fd, void* buf, unsigned int count) {
1783 return static_cast<int>(read(fd, buf, count));
1784 }
1785 inline int Write(int fd, const void* buf, unsigned int count) {
1786 return static_cast<int>(write(fd, buf, count));
1787 }
1788 inline int Close(int fd) { return close(fd); }
1789 inline const char* StrError(int errnum) { return strerror(errnum); }
1790 #endif
1791 inline const char* GetEnv(const char* name) {
1792 #if GTEST_OS_WINDOWS_MOBILE
1793 // We are on Windows CE, which has no environment variables.
1794 return NULL;
1795 #elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
1796 // Environment variables which we programmatically clear will be set to the
1797 // empty string rather than unset (NULL). Handle that case.
1798 const char* const env = getenv(name);
1799 return (env != NULL && env[0] != '\0') ? env : NULL;
1800 #else
1801 return getenv(name);
1802 #endif
1803 }
1804
1805 #ifdef _MSC_VER
1806 # pragma warning(pop) // Restores the warning state.
1807 #endif
1808
1809 #if GTEST_OS_WINDOWS_MOBILE
1810 // Windows CE has no C library. The abort() function is used in
1811 // several places in Google Test. This implementation provides a reasonable
1812 // imitation of standard behaviour.
1813 void Abort();
1814 #else
1815 inline void Abort() { abort(); }
1816 #endif // GTEST_OS_WINDOWS_MOBILE
1817
1818 } // namespace posix
1819
1820 // MSVC "deprecates" snprintf and issues warnings wherever it is used. In
1821 // order to avoid these warnings, we need to use _snprintf or _snprintf_s on
1822 // MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate
1823 // function in order to achieve that. We use macro definition here because
1824 // snprintf is a variadic function.
1825 #if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
1826 // MSVC 2005 and above support variadic macros.
1827 # define GTEST_SNPRINTF_(buffer, size, format, ...) \
1828 _snprintf_s(buffer, size, size, format, __VA_ARGS__)
1829 #elif defined(_MSC_VER)
1830 // Windows CE does not define _snprintf_s and MSVC prior to 2005 doesn't
1831 // complain about _snprintf.
1832 # define GTEST_SNPRINTF_ _snprintf
1833 #else
1834 # define GTEST_SNPRINTF_ snprintf
1835 #endif
1836
1837 // The maximum number a BiggestInt can represent. This definition
1838 // works no matter BiggestInt is represented in one's complement or
1839 // two's complement.
1840 //
1841 // We cannot rely on numeric_limits in STL, as __int64 and long long
1842 // are not part of standard C++ and numeric_limits doesn't need to be
1843 // defined for them.
1844 const BiggestInt kMaxBiggestInt =
1845 ~(static_cast<BiggestInt>(1) << (8*sizeof(BiggestInt) - 1));
1846
1847 // This template class serves as a compile-time function from size to
1848 // type. It maps a size in bytes to a primitive type with that
1849 // size. e.g.
1850 //
1851 // TypeWithSize<4>::UInt
1852 //
1853 // is typedef-ed to be unsigned int (unsigned integer made up of 4
1854 // bytes).
1855 //
1856 // Such functionality should belong to STL, but I cannot find it
1857 // there.
1858 //
1859 // Google Test uses this class in the implementation of floating-point
1860 // comparison.
1861 //
1862 // For now it only handles UInt (unsigned int) as that's all Google Test
1863 // needs. Other types can be easily added in the future if need
1864 // arises.
1865 template <size_t size>
1866 class TypeWithSize {
1867 public:
1868 // This prevents the user from using TypeWithSize<N> with incorrect
1869 // values of N.
1870 typedef void UInt;
1871 };
1872
1873 // The specialization for size 4.
1874 template <>
1875 class TypeWithSize<4> {
1876 public:
1877 // unsigned int has size 4 in both gcc and MSVC.
1878 //
1879 // As base/basictypes.h doesn't compile on Windows, we cannot use
1880 // uint32, uint64, and etc here.
1881 typedef int Int;
1882 typedef unsigned int UInt;
1883 };
1884
1885 // The specialization for size 8.
1886 template <>
1887 class TypeWithSize<8> {
1888 public:
1889 #if GTEST_OS_WINDOWS
1890 typedef __int64 Int;
1891 typedef unsigned __int64 UInt;
1892 #else
1893 typedef long long Int; // NOLINT
1894 typedef unsigned long long UInt; // NOLINT
1895 #endif // GTEST_OS_WINDOWS
1896 };
1897
1898 // Integer types of known sizes.
1899 typedef TypeWithSize<4>::Int Int32;
1900 typedef TypeWithSize<4>::UInt UInt32;
1901 typedef TypeWithSize<8>::Int Int64;
1902 typedef TypeWithSize<8>::UInt UInt64;
1903 typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
1904
1905 // Utilities for command line flags and environment variables.
1906
1907 // Macro for referencing flags.
1908 #define GTEST_FLAG(name) FLAGS_gtest_##name
1909
1910 // Macros for declaring flags.
1911 #define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name)
1912 #define GTEST_DECLARE_int32_(name) \
1913 GTEST_API_ extern ::testing::internal::Int32 GTEST_FLAG(name)
1914 #define GTEST_DECLARE_string_(name) \
1915 GTEST_API_ extern ::std::string GTEST_FLAG(name)
1916
1917 // Macros for defining flags.
1918 #define GTEST_DEFINE_bool_(name, default_val, doc) \
1919 GTEST_API_ bool GTEST_FLAG(name) = (default_val)
1920 #define GTEST_DEFINE_int32_(name, default_val, doc) \
1921 GTEST_API_ ::testing::internal::Int32 GTEST_FLAG(name) = (default_val)
1922 #define GTEST_DEFINE_string_(name, default_val, doc) \
1923 GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val)
1924
1925 // Thread annotations
1926 #define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
1927 #define GTEST_LOCK_EXCLUDED_(locks)
1928
1929 // Parses 'str' for a 32-bit signed integer. If successful, writes the result
1930 // to *value and returns true; otherwise leaves *value unchanged and returns
1931 // false.
1932 // TODO(chandlerc): Find a better way to refactor flag and environment parsing
1933 // out of both gtest-port.cc and gtest.cc to avoid exporting this utility
1934 // function.
1935 bool ParseInt32(const Message& src_text, const char* str, Int32* value);
1936
1937 // Parses a bool/Int32/string from the environment variable
1938 // corresponding to the given Google Test flag.
1939 bool BoolFromGTestEnv(const char* flag, bool default_val);
1940 GTEST_API_ Int32 Int32FromGTestEnv(const char* flag, Int32 default_val);
1941 const char* StringFromGTestEnv(const char* flag, const char* default_val);
1942
1943 } // namespace internal
1944 } // namespace testing
1945
1946 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_
0 // Copyright 2005, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Authors: wan@google.com (Zhanyong Wan), eefacm@gmail.com (Sean Mcafee)
30 //
31 // The Google C++ Testing Framework (Google Test)
32 //
33 // This header file declares the String class and functions used internally by
34 // Google Test. They are subject to change without notice. They should not used
35 // by code external to Google Test.
36 //
37 // This header file is #included by <gtest/internal/gtest-internal.h>.
38 // It should not be #included by other files.
39
40 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
41 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
42
43 #ifdef __BORLANDC__
44 // string.h is not guaranteed to provide strcpy on C++ Builder.
45 # include <mem.h>
46 #endif
47
48 #include <string.h>
49 #include <string>
50
51 #include "gtest/internal/gtest-port.h"
52
53 namespace testing {
54 namespace internal {
55
56 // String - an abstract class holding static string utilities.
57 class GTEST_API_ String {
58 public:
59 // Static utility methods
60
61 // Clones a 0-terminated C string, allocating memory using new. The
62 // caller is responsible for deleting the return value using
63 // delete[]. Returns the cloned string, or NULL if the input is
64 // NULL.
65 //
66 // This is different from strdup() in string.h, which allocates
67 // memory using malloc().
68 static const char* CloneCString(const char* c_str);
69
70 #if GTEST_OS_WINDOWS_MOBILE
71 // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be
72 // able to pass strings to Win32 APIs on CE we need to convert them
73 // to 'Unicode', UTF-16.
74
75 // Creates a UTF-16 wide string from the given ANSI string, allocating
76 // memory using new. The caller is responsible for deleting the return
77 // value using delete[]. Returns the wide string, or NULL if the
78 // input is NULL.
79 //
80 // The wide string is created using the ANSI codepage (CP_ACP) to
81 // match the behaviour of the ANSI versions of Win32 calls and the
82 // C runtime.
83 static LPCWSTR AnsiToUtf16(const char* c_str);
84
85 // Creates an ANSI string from the given wide string, allocating
86 // memory using new. The caller is responsible for deleting the return
87 // value using delete[]. Returns the ANSI string, or NULL if the
88 // input is NULL.
89 //
90 // The returned string is created using the ANSI codepage (CP_ACP) to
91 // match the behaviour of the ANSI versions of Win32 calls and the
92 // C runtime.
93 static const char* Utf16ToAnsi(LPCWSTR utf16_str);
94 #endif
95
96 // Compares two C strings. Returns true iff they have the same content.
97 //
98 // Unlike strcmp(), this function can handle NULL argument(s). A
99 // NULL C string is considered different to any non-NULL C string,
100 // including the empty string.
101 static bool CStringEquals(const char* lhs, const char* rhs);
102
103 // Converts a wide C string to a String using the UTF-8 encoding.
104 // NULL will be converted to "(null)". If an error occurred during
105 // the conversion, "(failed to convert from wide string)" is
106 // returned.
107 static std::string ShowWideCString(const wchar_t* wide_c_str);
108
109 // Compares two wide C strings. Returns true iff they have the same
110 // content.
111 //
112 // Unlike wcscmp(), this function can handle NULL argument(s). A
113 // NULL C string is considered different to any non-NULL C string,
114 // including the empty string.
115 static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs);
116
117 // Compares two C strings, ignoring case. Returns true iff they
118 // have the same content.
119 //
120 // Unlike strcasecmp(), this function can handle NULL argument(s).
121 // A NULL C string is considered different to any non-NULL C string,
122 // including the empty string.
123 static bool CaseInsensitiveCStringEquals(const char* lhs,
124 const char* rhs);
125
126 // Compares two wide C strings, ignoring case. Returns true iff they
127 // have the same content.
128 //
129 // Unlike wcscasecmp(), this function can handle NULL argument(s).
130 // A NULL C string is considered different to any non-NULL wide C string,
131 // including the empty string.
132 // NB: The implementations on different platforms slightly differ.
133 // On windows, this method uses _wcsicmp which compares according to LC_CTYPE
134 // environment variable. On GNU platform this method uses wcscasecmp
135 // which compares according to LC_CTYPE category of the current locale.
136 // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the
137 // current locale.
138 static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
139 const wchar_t* rhs);
140
141 // Returns true iff the given string ends with the given suffix, ignoring
142 // case. Any string is considered to end with an empty suffix.
143 static bool EndsWithCaseInsensitive(
144 const std::string& str, const std::string& suffix);
145
146 // Formats an int value as "%02d".
147 static std::string FormatIntWidth2(int value); // "%02d" for width == 2
148
149 // Formats an int value as "%X".
150 static std::string FormatHexInt(int value);
151
152 // Formats a byte as "%02X".
153 static std::string FormatByte(unsigned char value);
154
155 private:
156 String(); // Not meant to be instantiated.
157 }; // class String
158
159 // Gets the content of the stringstream's buffer as an std::string. Each '\0'
160 // character in the buffer is replaced with "\\0".
161 GTEST_API_ std::string StringStreamToString(::std::stringstream* stream);
162
163 } // namespace internal
164 } // namespace testing
165
166 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_
0 // This file was GENERATED by command:
1 // pump.py gtest-tuple.h.pump
2 // DO NOT EDIT BY HAND!!!
3
4 // Copyright 2009 Google Inc.
5 // All Rights Reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
9 // met:
10 //
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Author: wan@google.com (Zhanyong Wan)
34
35 // Implements a subset of TR1 tuple needed by Google Test and Google Mock.
36
37 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
38 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
39
40 #include <utility> // For ::std::pair.
41
42 // The compiler used in Symbian has a bug that prevents us from declaring the
43 // tuple template as a friend (it complains that tuple is redefined). This
44 // hack bypasses the bug by declaring the members that should otherwise be
45 // private as public.
46 // Sun Studio versions < 12 also have the above bug.
47 #if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
48 # define GTEST_DECLARE_TUPLE_AS_FRIEND_ public:
49 #else
50 # define GTEST_DECLARE_TUPLE_AS_FRIEND_ \
51 template <GTEST_10_TYPENAMES_(U)> friend class tuple; \
52 private:
53 #endif
54
55 // GTEST_n_TUPLE_(T) is the type of an n-tuple.
56 #define GTEST_0_TUPLE_(T) tuple<>
57 #define GTEST_1_TUPLE_(T) tuple<T##0, void, void, void, void, void, void, \
58 void, void, void>
59 #define GTEST_2_TUPLE_(T) tuple<T##0, T##1, void, void, void, void, void, \
60 void, void, void>
61 #define GTEST_3_TUPLE_(T) tuple<T##0, T##1, T##2, void, void, void, void, \
62 void, void, void>
63 #define GTEST_4_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, void, void, void, \
64 void, void, void>
65 #define GTEST_5_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, void, void, \
66 void, void, void>
67 #define GTEST_6_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, void, \
68 void, void, void>
69 #define GTEST_7_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
70 void, void, void>
71 #define GTEST_8_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
72 T##7, void, void>
73 #define GTEST_9_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
74 T##7, T##8, void>
75 #define GTEST_10_TUPLE_(T) tuple<T##0, T##1, T##2, T##3, T##4, T##5, T##6, \
76 T##7, T##8, T##9>
77
78 // GTEST_n_TYPENAMES_(T) declares a list of n typenames.
79 #define GTEST_0_TYPENAMES_(T)
80 #define GTEST_1_TYPENAMES_(T) typename T##0
81 #define GTEST_2_TYPENAMES_(T) typename T##0, typename T##1
82 #define GTEST_3_TYPENAMES_(T) typename T##0, typename T##1, typename T##2
83 #define GTEST_4_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
84 typename T##3
85 #define GTEST_5_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
86 typename T##3, typename T##4
87 #define GTEST_6_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
88 typename T##3, typename T##4, typename T##5
89 #define GTEST_7_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
90 typename T##3, typename T##4, typename T##5, typename T##6
91 #define GTEST_8_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
92 typename T##3, typename T##4, typename T##5, typename T##6, typename T##7
93 #define GTEST_9_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
94 typename T##3, typename T##4, typename T##5, typename T##6, \
95 typename T##7, typename T##8
96 #define GTEST_10_TYPENAMES_(T) typename T##0, typename T##1, typename T##2, \
97 typename T##3, typename T##4, typename T##5, typename T##6, \
98 typename T##7, typename T##8, typename T##9
99
100 // In theory, defining stuff in the ::std namespace is undefined
101 // behavior. We can do this as we are playing the role of a standard
102 // library vendor.
103 namespace std {
104 namespace tr1 {
105
106 template <typename T0 = void, typename T1 = void, typename T2 = void,
107 typename T3 = void, typename T4 = void, typename T5 = void,
108 typename T6 = void, typename T7 = void, typename T8 = void,
109 typename T9 = void>
110 class tuple;
111
112 // Anything in namespace gtest_internal is Google Test's INTERNAL
113 // IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code.
114 namespace gtest_internal {
115
116 // ByRef<T>::type is T if T is a reference; otherwise it's const T&.
117 template <typename T>
118 struct ByRef { typedef const T& type; }; // NOLINT
119 template <typename T>
120 struct ByRef<T&> { typedef T& type; }; // NOLINT
121
122 // A handy wrapper for ByRef.
123 #define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef<T>::type
124
125 // AddRef<T>::type is T if T is a reference; otherwise it's T&. This
126 // is the same as tr1::add_reference<T>::type.
127 template <typename T>
128 struct AddRef { typedef T& type; }; // NOLINT
129 template <typename T>
130 struct AddRef<T&> { typedef T& type; }; // NOLINT
131
132 // A handy wrapper for AddRef.
133 #define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef<T>::type
134
135 // A helper for implementing get<k>().
136 template <int k> class Get;
137
138 // A helper for implementing tuple_element<k, T>. kIndexValid is true
139 // iff k < the number of fields in tuple type T.
140 template <bool kIndexValid, int kIndex, class Tuple>
141 struct TupleElement;
142
143 template <GTEST_10_TYPENAMES_(T)>
144 struct TupleElement<true, 0, GTEST_10_TUPLE_(T) > {
145 typedef T0 type;
146 };
147
148 template <GTEST_10_TYPENAMES_(T)>
149 struct TupleElement<true, 1, GTEST_10_TUPLE_(T) > {
150 typedef T1 type;
151 };
152
153 template <GTEST_10_TYPENAMES_(T)>
154 struct TupleElement<true, 2, GTEST_10_TUPLE_(T) > {
155 typedef T2 type;
156 };
157
158 template <GTEST_10_TYPENAMES_(T)>
159 struct TupleElement<true, 3, GTEST_10_TUPLE_(T) > {
160 typedef T3 type;
161 };
162
163 template <GTEST_10_TYPENAMES_(T)>
164 struct TupleElement<true, 4, GTEST_10_TUPLE_(T) > {
165 typedef T4 type;
166 };
167
168 template <GTEST_10_TYPENAMES_(T)>
169 struct TupleElement<true, 5, GTEST_10_TUPLE_(T) > {
170 typedef T5 type;
171 };
172
173 template <GTEST_10_TYPENAMES_(T)>
174 struct TupleElement<true, 6, GTEST_10_TUPLE_(T) > {
175 typedef T6 type;
176 };
177
178 template <GTEST_10_TYPENAMES_(T)>
179 struct TupleElement<true, 7, GTEST_10_TUPLE_(T) > {
180 typedef T7 type;
181 };
182
183 template <GTEST_10_TYPENAMES_(T)>
184 struct TupleElement<true, 8, GTEST_10_TUPLE_(T) > {
185 typedef T8 type;
186 };
187
188 template <GTEST_10_TYPENAMES_(T)>
189 struct TupleElement<true, 9, GTEST_10_TUPLE_(T) > {
190 typedef T9 type;
191 };
192
193 } // namespace gtest_internal
194
195 template <>
196 class tuple<> {
197 public:
198 tuple() {}
199 tuple(const tuple& /* t */) {}
200 tuple& operator=(const tuple& /* t */) { return *this; }
201 };
202
203 template <GTEST_1_TYPENAMES_(T)>
204 class GTEST_1_TUPLE_(T) {
205 public:
206 template <int k> friend class gtest_internal::Get;
207
208 tuple() : f0_() {}
209
210 explicit tuple(GTEST_BY_REF_(T0) f0) : f0_(f0) {}
211
212 tuple(const tuple& t) : f0_(t.f0_) {}
213
214 template <GTEST_1_TYPENAMES_(U)>
215 tuple(const GTEST_1_TUPLE_(U)& t) : f0_(t.f0_) {}
216
217 tuple& operator=(const tuple& t) { return CopyFrom(t); }
218
219 template <GTEST_1_TYPENAMES_(U)>
220 tuple& operator=(const GTEST_1_TUPLE_(U)& t) {
221 return CopyFrom(t);
222 }
223
224 GTEST_DECLARE_TUPLE_AS_FRIEND_
225
226 template <GTEST_1_TYPENAMES_(U)>
227 tuple& CopyFrom(const GTEST_1_TUPLE_(U)& t) {
228 f0_ = t.f0_;
229 return *this;
230 }
231
232 T0 f0_;
233 };
234
235 template <GTEST_2_TYPENAMES_(T)>
236 class GTEST_2_TUPLE_(T) {
237 public:
238 template <int k> friend class gtest_internal::Get;
239
240 tuple() : f0_(), f1_() {}
241
242 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1) : f0_(f0),
243 f1_(f1) {}
244
245 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_) {}
246
247 template <GTEST_2_TYPENAMES_(U)>
248 tuple(const GTEST_2_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_) {}
249 template <typename U0, typename U1>
250 tuple(const ::std::pair<U0, U1>& p) : f0_(p.first), f1_(p.second) {}
251
252 tuple& operator=(const tuple& t) { return CopyFrom(t); }
253
254 template <GTEST_2_TYPENAMES_(U)>
255 tuple& operator=(const GTEST_2_TUPLE_(U)& t) {
256 return CopyFrom(t);
257 }
258 template <typename U0, typename U1>
259 tuple& operator=(const ::std::pair<U0, U1>& p) {
260 f0_ = p.first;
261 f1_ = p.second;
262 return *this;
263 }
264
265 GTEST_DECLARE_TUPLE_AS_FRIEND_
266
267 template <GTEST_2_TYPENAMES_(U)>
268 tuple& CopyFrom(const GTEST_2_TUPLE_(U)& t) {
269 f0_ = t.f0_;
270 f1_ = t.f1_;
271 return *this;
272 }
273
274 T0 f0_;
275 T1 f1_;
276 };
277
278 template <GTEST_3_TYPENAMES_(T)>
279 class GTEST_3_TUPLE_(T) {
280 public:
281 template <int k> friend class gtest_internal::Get;
282
283 tuple() : f0_(), f1_(), f2_() {}
284
285 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
286 GTEST_BY_REF_(T2) f2) : f0_(f0), f1_(f1), f2_(f2) {}
287
288 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {}
289
290 template <GTEST_3_TYPENAMES_(U)>
291 tuple(const GTEST_3_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_) {}
292
293 tuple& operator=(const tuple& t) { return CopyFrom(t); }
294
295 template <GTEST_3_TYPENAMES_(U)>
296 tuple& operator=(const GTEST_3_TUPLE_(U)& t) {
297 return CopyFrom(t);
298 }
299
300 GTEST_DECLARE_TUPLE_AS_FRIEND_
301
302 template <GTEST_3_TYPENAMES_(U)>
303 tuple& CopyFrom(const GTEST_3_TUPLE_(U)& t) {
304 f0_ = t.f0_;
305 f1_ = t.f1_;
306 f2_ = t.f2_;
307 return *this;
308 }
309
310 T0 f0_;
311 T1 f1_;
312 T2 f2_;
313 };
314
315 template <GTEST_4_TYPENAMES_(T)>
316 class GTEST_4_TUPLE_(T) {
317 public:
318 template <int k> friend class gtest_internal::Get;
319
320 tuple() : f0_(), f1_(), f2_(), f3_() {}
321
322 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
323 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3) : f0_(f0), f1_(f1), f2_(f2),
324 f3_(f3) {}
325
326 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_) {}
327
328 template <GTEST_4_TYPENAMES_(U)>
329 tuple(const GTEST_4_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
330 f3_(t.f3_) {}
331
332 tuple& operator=(const tuple& t) { return CopyFrom(t); }
333
334 template <GTEST_4_TYPENAMES_(U)>
335 tuple& operator=(const GTEST_4_TUPLE_(U)& t) {
336 return CopyFrom(t);
337 }
338
339 GTEST_DECLARE_TUPLE_AS_FRIEND_
340
341 template <GTEST_4_TYPENAMES_(U)>
342 tuple& CopyFrom(const GTEST_4_TUPLE_(U)& t) {
343 f0_ = t.f0_;
344 f1_ = t.f1_;
345 f2_ = t.f2_;
346 f3_ = t.f3_;
347 return *this;
348 }
349
350 T0 f0_;
351 T1 f1_;
352 T2 f2_;
353 T3 f3_;
354 };
355
356 template <GTEST_5_TYPENAMES_(T)>
357 class GTEST_5_TUPLE_(T) {
358 public:
359 template <int k> friend class gtest_internal::Get;
360
361 tuple() : f0_(), f1_(), f2_(), f3_(), f4_() {}
362
363 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
364 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3,
365 GTEST_BY_REF_(T4) f4) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4) {}
366
367 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
368 f4_(t.f4_) {}
369
370 template <GTEST_5_TYPENAMES_(U)>
371 tuple(const GTEST_5_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
372 f3_(t.f3_), f4_(t.f4_) {}
373
374 tuple& operator=(const tuple& t) { return CopyFrom(t); }
375
376 template <GTEST_5_TYPENAMES_(U)>
377 tuple& operator=(const GTEST_5_TUPLE_(U)& t) {
378 return CopyFrom(t);
379 }
380
381 GTEST_DECLARE_TUPLE_AS_FRIEND_
382
383 template <GTEST_5_TYPENAMES_(U)>
384 tuple& CopyFrom(const GTEST_5_TUPLE_(U)& t) {
385 f0_ = t.f0_;
386 f1_ = t.f1_;
387 f2_ = t.f2_;
388 f3_ = t.f3_;
389 f4_ = t.f4_;
390 return *this;
391 }
392
393 T0 f0_;
394 T1 f1_;
395 T2 f2_;
396 T3 f3_;
397 T4 f4_;
398 };
399
400 template <GTEST_6_TYPENAMES_(T)>
401 class GTEST_6_TUPLE_(T) {
402 public:
403 template <int k> friend class gtest_internal::Get;
404
405 tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_() {}
406
407 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
408 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
409 GTEST_BY_REF_(T5) f5) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
410 f5_(f5) {}
411
412 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
413 f4_(t.f4_), f5_(t.f5_) {}
414
415 template <GTEST_6_TYPENAMES_(U)>
416 tuple(const GTEST_6_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
417 f3_(t.f3_), f4_(t.f4_), f5_(t.f5_) {}
418
419 tuple& operator=(const tuple& t) { return CopyFrom(t); }
420
421 template <GTEST_6_TYPENAMES_(U)>
422 tuple& operator=(const GTEST_6_TUPLE_(U)& t) {
423 return CopyFrom(t);
424 }
425
426 GTEST_DECLARE_TUPLE_AS_FRIEND_
427
428 template <GTEST_6_TYPENAMES_(U)>
429 tuple& CopyFrom(const GTEST_6_TUPLE_(U)& t) {
430 f0_ = t.f0_;
431 f1_ = t.f1_;
432 f2_ = t.f2_;
433 f3_ = t.f3_;
434 f4_ = t.f4_;
435 f5_ = t.f5_;
436 return *this;
437 }
438
439 T0 f0_;
440 T1 f1_;
441 T2 f2_;
442 T3 f3_;
443 T4 f4_;
444 T5 f5_;
445 };
446
447 template <GTEST_7_TYPENAMES_(T)>
448 class GTEST_7_TUPLE_(T) {
449 public:
450 template <int k> friend class gtest_internal::Get;
451
452 tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_() {}
453
454 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
455 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
456 GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6) : f0_(f0), f1_(f1), f2_(f2),
457 f3_(f3), f4_(f4), f5_(f5), f6_(f6) {}
458
459 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
460 f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {}
461
462 template <GTEST_7_TYPENAMES_(U)>
463 tuple(const GTEST_7_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
464 f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_) {}
465
466 tuple& operator=(const tuple& t) { return CopyFrom(t); }
467
468 template <GTEST_7_TYPENAMES_(U)>
469 tuple& operator=(const GTEST_7_TUPLE_(U)& t) {
470 return CopyFrom(t);
471 }
472
473 GTEST_DECLARE_TUPLE_AS_FRIEND_
474
475 template <GTEST_7_TYPENAMES_(U)>
476 tuple& CopyFrom(const GTEST_7_TUPLE_(U)& t) {
477 f0_ = t.f0_;
478 f1_ = t.f1_;
479 f2_ = t.f2_;
480 f3_ = t.f3_;
481 f4_ = t.f4_;
482 f5_ = t.f5_;
483 f6_ = t.f6_;
484 return *this;
485 }
486
487 T0 f0_;
488 T1 f1_;
489 T2 f2_;
490 T3 f3_;
491 T4 f4_;
492 T5 f5_;
493 T6 f6_;
494 };
495
496 template <GTEST_8_TYPENAMES_(T)>
497 class GTEST_8_TUPLE_(T) {
498 public:
499 template <int k> friend class gtest_internal::Get;
500
501 tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_() {}
502
503 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
504 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
505 GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6,
506 GTEST_BY_REF_(T7) f7) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
507 f5_(f5), f6_(f6), f7_(f7) {}
508
509 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
510 f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {}
511
512 template <GTEST_8_TYPENAMES_(U)>
513 tuple(const GTEST_8_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
514 f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_) {}
515
516 tuple& operator=(const tuple& t) { return CopyFrom(t); }
517
518 template <GTEST_8_TYPENAMES_(U)>
519 tuple& operator=(const GTEST_8_TUPLE_(U)& t) {
520 return CopyFrom(t);
521 }
522
523 GTEST_DECLARE_TUPLE_AS_FRIEND_
524
525 template <GTEST_8_TYPENAMES_(U)>
526 tuple& CopyFrom(const GTEST_8_TUPLE_(U)& t) {
527 f0_ = t.f0_;
528 f1_ = t.f1_;
529 f2_ = t.f2_;
530 f3_ = t.f3_;
531 f4_ = t.f4_;
532 f5_ = t.f5_;
533 f6_ = t.f6_;
534 f7_ = t.f7_;
535 return *this;
536 }
537
538 T0 f0_;
539 T1 f1_;
540 T2 f2_;
541 T3 f3_;
542 T4 f4_;
543 T5 f5_;
544 T6 f6_;
545 T7 f7_;
546 };
547
548 template <GTEST_9_TYPENAMES_(T)>
549 class GTEST_9_TUPLE_(T) {
550 public:
551 template <int k> friend class gtest_internal::Get;
552
553 tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_() {}
554
555 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
556 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
557 GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7,
558 GTEST_BY_REF_(T8) f8) : f0_(f0), f1_(f1), f2_(f2), f3_(f3), f4_(f4),
559 f5_(f5), f6_(f6), f7_(f7), f8_(f8) {}
560
561 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
562 f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_) {}
563
564 template <GTEST_9_TYPENAMES_(U)>
565 tuple(const GTEST_9_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
566 f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_) {}
567
568 tuple& operator=(const tuple& t) { return CopyFrom(t); }
569
570 template <GTEST_9_TYPENAMES_(U)>
571 tuple& operator=(const GTEST_9_TUPLE_(U)& t) {
572 return CopyFrom(t);
573 }
574
575 GTEST_DECLARE_TUPLE_AS_FRIEND_
576
577 template <GTEST_9_TYPENAMES_(U)>
578 tuple& CopyFrom(const GTEST_9_TUPLE_(U)& t) {
579 f0_ = t.f0_;
580 f1_ = t.f1_;
581 f2_ = t.f2_;
582 f3_ = t.f3_;
583 f4_ = t.f4_;
584 f5_ = t.f5_;
585 f6_ = t.f6_;
586 f7_ = t.f7_;
587 f8_ = t.f8_;
588 return *this;
589 }
590
591 T0 f0_;
592 T1 f1_;
593 T2 f2_;
594 T3 f3_;
595 T4 f4_;
596 T5 f5_;
597 T6 f6_;
598 T7 f7_;
599 T8 f8_;
600 };
601
602 template <GTEST_10_TYPENAMES_(T)>
603 class tuple {
604 public:
605 template <int k> friend class gtest_internal::Get;
606
607 tuple() : f0_(), f1_(), f2_(), f3_(), f4_(), f5_(), f6_(), f7_(), f8_(),
608 f9_() {}
609
610 explicit tuple(GTEST_BY_REF_(T0) f0, GTEST_BY_REF_(T1) f1,
611 GTEST_BY_REF_(T2) f2, GTEST_BY_REF_(T3) f3, GTEST_BY_REF_(T4) f4,
612 GTEST_BY_REF_(T5) f5, GTEST_BY_REF_(T6) f6, GTEST_BY_REF_(T7) f7,
613 GTEST_BY_REF_(T8) f8, GTEST_BY_REF_(T9) f9) : f0_(f0), f1_(f1), f2_(f2),
614 f3_(f3), f4_(f4), f5_(f5), f6_(f6), f7_(f7), f8_(f8), f9_(f9) {}
615
616 tuple(const tuple& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_), f3_(t.f3_),
617 f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_), f9_(t.f9_) {}
618
619 template <GTEST_10_TYPENAMES_(U)>
620 tuple(const GTEST_10_TUPLE_(U)& t) : f0_(t.f0_), f1_(t.f1_), f2_(t.f2_),
621 f3_(t.f3_), f4_(t.f4_), f5_(t.f5_), f6_(t.f6_), f7_(t.f7_), f8_(t.f8_),
622 f9_(t.f9_) {}
623
624 tuple& operator=(const tuple& t) { return CopyFrom(t); }
625
626 template <GTEST_10_TYPENAMES_(U)>
627 tuple& operator=(const GTEST_10_TUPLE_(U)& t) {
628 return CopyFrom(t);
629 }
630
631 GTEST_DECLARE_TUPLE_AS_FRIEND_
632
633 template <GTEST_10_TYPENAMES_(U)>
634 tuple& CopyFrom(const GTEST_10_TUPLE_(U)& t) {
635 f0_ = t.f0_;
636 f1_ = t.f1_;
637 f2_ = t.f2_;
638 f3_ = t.f3_;
639 f4_ = t.f4_;
640 f5_ = t.f5_;
641 f6_ = t.f6_;
642 f7_ = t.f7_;
643 f8_ = t.f8_;
644 f9_ = t.f9_;
645 return *this;
646 }
647
648 T0 f0_;
649 T1 f1_;
650 T2 f2_;
651 T3 f3_;
652 T4 f4_;
653 T5 f5_;
654 T6 f6_;
655 T7 f7_;
656 T8 f8_;
657 T9 f9_;
658 };
659
660 // 6.1.3.2 Tuple creation functions.
661
662 // Known limitations: we don't support passing an
663 // std::tr1::reference_wrapper<T> to make_tuple(). And we don't
664 // implement tie().
665
666 inline tuple<> make_tuple() { return tuple<>(); }
667
668 template <GTEST_1_TYPENAMES_(T)>
669 inline GTEST_1_TUPLE_(T) make_tuple(const T0& f0) {
670 return GTEST_1_TUPLE_(T)(f0);
671 }
672
673 template <GTEST_2_TYPENAMES_(T)>
674 inline GTEST_2_TUPLE_(T) make_tuple(const T0& f0, const T1& f1) {
675 return GTEST_2_TUPLE_(T)(f0, f1);
676 }
677
678 template <GTEST_3_TYPENAMES_(T)>
679 inline GTEST_3_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2) {
680 return GTEST_3_TUPLE_(T)(f0, f1, f2);
681 }
682
683 template <GTEST_4_TYPENAMES_(T)>
684 inline GTEST_4_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
685 const T3& f3) {
686 return GTEST_4_TUPLE_(T)(f0, f1, f2, f3);
687 }
688
689 template <GTEST_5_TYPENAMES_(T)>
690 inline GTEST_5_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
691 const T3& f3, const T4& f4) {
692 return GTEST_5_TUPLE_(T)(f0, f1, f2, f3, f4);
693 }
694
695 template <GTEST_6_TYPENAMES_(T)>
696 inline GTEST_6_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
697 const T3& f3, const T4& f4, const T5& f5) {
698 return GTEST_6_TUPLE_(T)(f0, f1, f2, f3, f4, f5);
699 }
700
701 template <GTEST_7_TYPENAMES_(T)>
702 inline GTEST_7_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
703 const T3& f3, const T4& f4, const T5& f5, const T6& f6) {
704 return GTEST_7_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6);
705 }
706
707 template <GTEST_8_TYPENAMES_(T)>
708 inline GTEST_8_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
709 const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7) {
710 return GTEST_8_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7);
711 }
712
713 template <GTEST_9_TYPENAMES_(T)>
714 inline GTEST_9_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
715 const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7,
716 const T8& f8) {
717 return GTEST_9_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7, f8);
718 }
719
720 template <GTEST_10_TYPENAMES_(T)>
721 inline GTEST_10_TUPLE_(T) make_tuple(const T0& f0, const T1& f1, const T2& f2,
722 const T3& f3, const T4& f4, const T5& f5, const T6& f6, const T7& f7,
723 const T8& f8, const T9& f9) {
724 return GTEST_10_TUPLE_(T)(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9);
725 }
726
727 // 6.1.3.3 Tuple helper classes.
728
729 template <typename Tuple> struct tuple_size;
730
731 template <GTEST_0_TYPENAMES_(T)>
732 struct tuple_size<GTEST_0_TUPLE_(T) > {
733 static const int value = 0;
734 };
735
736 template <GTEST_1_TYPENAMES_(T)>
737 struct tuple_size<GTEST_1_TUPLE_(T) > {
738 static const int value = 1;
739 };
740
741 template <GTEST_2_TYPENAMES_(T)>
742 struct tuple_size<GTEST_2_TUPLE_(T) > {
743 static const int value = 2;
744 };
745
746 template <GTEST_3_TYPENAMES_(T)>
747 struct tuple_size<GTEST_3_TUPLE_(T) > {
748 static const int value = 3;
749 };
750
751 template <GTEST_4_TYPENAMES_(T)>
752 struct tuple_size<GTEST_4_TUPLE_(T) > {
753 static const int value = 4;
754 };
755
756 template <GTEST_5_TYPENAMES_(T)>
757 struct tuple_size<GTEST_5_TUPLE_(T) > {
758 static const int value = 5;
759 };
760
761 template <GTEST_6_TYPENAMES_(T)>
762 struct tuple_size<GTEST_6_TUPLE_(T) > {
763 static const int value = 6;
764 };
765
766 template <GTEST_7_TYPENAMES_(T)>
767 struct tuple_size<GTEST_7_TUPLE_(T) > {
768 static const int value = 7;
769 };
770
771 template <GTEST_8_TYPENAMES_(T)>
772 struct tuple_size<GTEST_8_TUPLE_(T) > {
773 static const int value = 8;
774 };
775
776 template <GTEST_9_TYPENAMES_(T)>
777 struct tuple_size<GTEST_9_TUPLE_(T) > {
778 static const int value = 9;
779 };
780
781 template <GTEST_10_TYPENAMES_(T)>
782 struct tuple_size<GTEST_10_TUPLE_(T) > {
783 static const int value = 10;
784 };
785
786 template <int k, class Tuple>
787 struct tuple_element {
788 typedef typename gtest_internal::TupleElement<
789 k < (tuple_size<Tuple>::value), k, Tuple>::type type;
790 };
791
792 #define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element<k, Tuple >::type
793
794 // 6.1.3.4 Element access.
795
796 namespace gtest_internal {
797
798 template <>
799 class Get<0> {
800 public:
801 template <class Tuple>
802 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(0, Tuple))
803 Field(Tuple& t) { return t.f0_; } // NOLINT
804
805 template <class Tuple>
806 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(0, Tuple))
807 ConstField(const Tuple& t) { return t.f0_; }
808 };
809
810 template <>
811 class Get<1> {
812 public:
813 template <class Tuple>
814 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(1, Tuple))
815 Field(Tuple& t) { return t.f1_; } // NOLINT
816
817 template <class Tuple>
818 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(1, Tuple))
819 ConstField(const Tuple& t) { return t.f1_; }
820 };
821
822 template <>
823 class Get<2> {
824 public:
825 template <class Tuple>
826 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(2, Tuple))
827 Field(Tuple& t) { return t.f2_; } // NOLINT
828
829 template <class Tuple>
830 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(2, Tuple))
831 ConstField(const Tuple& t) { return t.f2_; }
832 };
833
834 template <>
835 class Get<3> {
836 public:
837 template <class Tuple>
838 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(3, Tuple))
839 Field(Tuple& t) { return t.f3_; } // NOLINT
840
841 template <class Tuple>
842 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(3, Tuple))
843 ConstField(const Tuple& t) { return t.f3_; }
844 };
845
846 template <>
847 class Get<4> {
848 public:
849 template <class Tuple>
850 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(4, Tuple))
851 Field(Tuple& t) { return t.f4_; } // NOLINT
852
853 template <class Tuple>
854 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(4, Tuple))
855 ConstField(const Tuple& t) { return t.f4_; }
856 };
857
858 template <>
859 class Get<5> {
860 public:
861 template <class Tuple>
862 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(5, Tuple))
863 Field(Tuple& t) { return t.f5_; } // NOLINT
864
865 template <class Tuple>
866 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(5, Tuple))
867 ConstField(const Tuple& t) { return t.f5_; }
868 };
869
870 template <>
871 class Get<6> {
872 public:
873 template <class Tuple>
874 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(6, Tuple))
875 Field(Tuple& t) { return t.f6_; } // NOLINT
876
877 template <class Tuple>
878 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(6, Tuple))
879 ConstField(const Tuple& t) { return t.f6_; }
880 };
881
882 template <>
883 class Get<7> {
884 public:
885 template <class Tuple>
886 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(7, Tuple))
887 Field(Tuple& t) { return t.f7_; } // NOLINT
888
889 template <class Tuple>
890 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(7, Tuple))
891 ConstField(const Tuple& t) { return t.f7_; }
892 };
893
894 template <>
895 class Get<8> {
896 public:
897 template <class Tuple>
898 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(8, Tuple))
899 Field(Tuple& t) { return t.f8_; } // NOLINT
900
901 template <class Tuple>
902 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(8, Tuple))
903 ConstField(const Tuple& t) { return t.f8_; }
904 };
905
906 template <>
907 class Get<9> {
908 public:
909 template <class Tuple>
910 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(9, Tuple))
911 Field(Tuple& t) { return t.f9_; } // NOLINT
912
913 template <class Tuple>
914 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(9, Tuple))
915 ConstField(const Tuple& t) { return t.f9_; }
916 };
917
918 } // namespace gtest_internal
919
920 template <int k, GTEST_10_TYPENAMES_(T)>
921 GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_10_TUPLE_(T)))
922 get(GTEST_10_TUPLE_(T)& t) {
923 return gtest_internal::Get<k>::Field(t);
924 }
925
926 template <int k, GTEST_10_TYPENAMES_(T)>
927 GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_10_TUPLE_(T)))
928 get(const GTEST_10_TUPLE_(T)& t) {
929 return gtest_internal::Get<k>::ConstField(t);
930 }
931
932 // 6.1.3.5 Relational operators
933
934 // We only implement == and !=, as we don't have a need for the rest yet.
935
936 namespace gtest_internal {
937
938 // SameSizeTuplePrefixComparator<k, k>::Eq(t1, t2) returns true if the
939 // first k fields of t1 equals the first k fields of t2.
940 // SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if
941 // k1 != k2.
942 template <int kSize1, int kSize2>
943 struct SameSizeTuplePrefixComparator;
944
945 template <>
946 struct SameSizeTuplePrefixComparator<0, 0> {
947 template <class Tuple1, class Tuple2>
948 static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) {
949 return true;
950 }
951 };
952
953 template <int k>
954 struct SameSizeTuplePrefixComparator<k, k> {
955 template <class Tuple1, class Tuple2>
956 static bool Eq(const Tuple1& t1, const Tuple2& t2) {
957 return SameSizeTuplePrefixComparator<k - 1, k - 1>::Eq(t1, t2) &&
958 ::std::tr1::get<k - 1>(t1) == ::std::tr1::get<k - 1>(t2);
959 }
960 };
961
962 } // namespace gtest_internal
963
964 template <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>
965 inline bool operator==(const GTEST_10_TUPLE_(T)& t,
966 const GTEST_10_TUPLE_(U)& u) {
967 return gtest_internal::SameSizeTuplePrefixComparator<
968 tuple_size<GTEST_10_TUPLE_(T) >::value,
969 tuple_size<GTEST_10_TUPLE_(U) >::value>::Eq(t, u);
970 }
971
972 template <GTEST_10_TYPENAMES_(T), GTEST_10_TYPENAMES_(U)>
973 inline bool operator!=(const GTEST_10_TUPLE_(T)& t,
974 const GTEST_10_TUPLE_(U)& u) { return !(t == u); }
975
976 // 6.1.4 Pairs.
977 // Unimplemented.
978
979 } // namespace tr1
980 } // namespace std
981
982 #undef GTEST_0_TUPLE_
983 #undef GTEST_1_TUPLE_
984 #undef GTEST_2_TUPLE_
985 #undef GTEST_3_TUPLE_
986 #undef GTEST_4_TUPLE_
987 #undef GTEST_5_TUPLE_
988 #undef GTEST_6_TUPLE_
989 #undef GTEST_7_TUPLE_
990 #undef GTEST_8_TUPLE_
991 #undef GTEST_9_TUPLE_
992 #undef GTEST_10_TUPLE_
993
994 #undef GTEST_0_TYPENAMES_
995 #undef GTEST_1_TYPENAMES_
996 #undef GTEST_2_TYPENAMES_
997 #undef GTEST_3_TYPENAMES_
998 #undef GTEST_4_TYPENAMES_
999 #undef GTEST_5_TYPENAMES_
1000 #undef GTEST_6_TYPENAMES_
1001 #undef GTEST_7_TYPENAMES_
1002 #undef GTEST_8_TYPENAMES_
1003 #undef GTEST_9_TYPENAMES_
1004 #undef GTEST_10_TYPENAMES_
1005
1006 #undef GTEST_DECLARE_TUPLE_AS_FRIEND_
1007 #undef GTEST_BY_REF_
1008 #undef GTEST_ADD_REF_
1009 #undef GTEST_TUPLE_ELEMENT_
1010
1011 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
0 $$ -*- mode: c++; -*-
1 $var n = 10 $$ Maximum number of tuple fields we want to support.
2 $$ This meta comment fixes auto-indentation in Emacs. }}
3 // Copyright 2009 Google Inc.
4 // All Rights Reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following disclaimer
14 // in the documentation and/or other materials provided with the
15 // distribution.
16 // * Neither the name of Google Inc. nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 //
32 // Author: wan@google.com (Zhanyong Wan)
33
34 // Implements a subset of TR1 tuple needed by Google Test and Google Mock.
35
36 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
37 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
38
39 #include <utility> // For ::std::pair.
40
41 // The compiler used in Symbian has a bug that prevents us from declaring the
42 // tuple template as a friend (it complains that tuple is redefined). This
43 // hack bypasses the bug by declaring the members that should otherwise be
44 // private as public.
45 // Sun Studio versions < 12 also have the above bug.
46 #if defined(__SYMBIAN32__) || (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x590)
47 # define GTEST_DECLARE_TUPLE_AS_FRIEND_ public:
48 #else
49 # define GTEST_DECLARE_TUPLE_AS_FRIEND_ \
50 template <GTEST_$(n)_TYPENAMES_(U)> friend class tuple; \
51 private:
52 #endif
53
54
55 $range i 0..n-1
56 $range j 0..n
57 $range k 1..n
58 // GTEST_n_TUPLE_(T) is the type of an n-tuple.
59 #define GTEST_0_TUPLE_(T) tuple<>
60
61 $for k [[
62 $range m 0..k-1
63 $range m2 k..n-1
64 #define GTEST_$(k)_TUPLE_(T) tuple<$for m, [[T##$m]]$for m2 [[, void]]>
65
66 ]]
67
68 // GTEST_n_TYPENAMES_(T) declares a list of n typenames.
69
70 $for j [[
71 $range m 0..j-1
72 #define GTEST_$(j)_TYPENAMES_(T) $for m, [[typename T##$m]]
73
74
75 ]]
76
77 // In theory, defining stuff in the ::std namespace is undefined
78 // behavior. We can do this as we are playing the role of a standard
79 // library vendor.
80 namespace std {
81 namespace tr1 {
82
83 template <$for i, [[typename T$i = void]]>
84 class tuple;
85
86 // Anything in namespace gtest_internal is Google Test's INTERNAL
87 // IMPLEMENTATION DETAIL and MUST NOT BE USED DIRECTLY in user code.
88 namespace gtest_internal {
89
90 // ByRef<T>::type is T if T is a reference; otherwise it's const T&.
91 template <typename T>
92 struct ByRef { typedef const T& type; }; // NOLINT
93 template <typename T>
94 struct ByRef<T&> { typedef T& type; }; // NOLINT
95
96 // A handy wrapper for ByRef.
97 #define GTEST_BY_REF_(T) typename ::std::tr1::gtest_internal::ByRef<T>::type
98
99 // AddRef<T>::type is T if T is a reference; otherwise it's T&. This
100 // is the same as tr1::add_reference<T>::type.
101 template <typename T>
102 struct AddRef { typedef T& type; }; // NOLINT
103 template <typename T>
104 struct AddRef<T&> { typedef T& type; }; // NOLINT
105
106 // A handy wrapper for AddRef.
107 #define GTEST_ADD_REF_(T) typename ::std::tr1::gtest_internal::AddRef<T>::type
108
109 // A helper for implementing get<k>().
110 template <int k> class Get;
111
112 // A helper for implementing tuple_element<k, T>. kIndexValid is true
113 // iff k < the number of fields in tuple type T.
114 template <bool kIndexValid, int kIndex, class Tuple>
115 struct TupleElement;
116
117
118 $for i [[
119 template <GTEST_$(n)_TYPENAMES_(T)>
120 struct TupleElement<true, $i, GTEST_$(n)_TUPLE_(T) > {
121 typedef T$i type;
122 };
123
124
125 ]]
126 } // namespace gtest_internal
127
128 template <>
129 class tuple<> {
130 public:
131 tuple() {}
132 tuple(const tuple& /* t */) {}
133 tuple& operator=(const tuple& /* t */) { return *this; }
134 };
135
136
137 $for k [[
138 $range m 0..k-1
139 template <GTEST_$(k)_TYPENAMES_(T)>
140 class $if k < n [[GTEST_$(k)_TUPLE_(T)]] $else [[tuple]] {
141 public:
142 template <int k> friend class gtest_internal::Get;
143
144 tuple() : $for m, [[f$(m)_()]] {}
145
146 explicit tuple($for m, [[GTEST_BY_REF_(T$m) f$m]]) : [[]]
147 $for m, [[f$(m)_(f$m)]] {}
148
149 tuple(const tuple& t) : $for m, [[f$(m)_(t.f$(m)_)]] {}
150
151 template <GTEST_$(k)_TYPENAMES_(U)>
152 tuple(const GTEST_$(k)_TUPLE_(U)& t) : $for m, [[f$(m)_(t.f$(m)_)]] {}
153
154 $if k == 2 [[
155 template <typename U0, typename U1>
156 tuple(const ::std::pair<U0, U1>& p) : f0_(p.first), f1_(p.second) {}
157
158 ]]
159
160 tuple& operator=(const tuple& t) { return CopyFrom(t); }
161
162 template <GTEST_$(k)_TYPENAMES_(U)>
163 tuple& operator=(const GTEST_$(k)_TUPLE_(U)& t) {
164 return CopyFrom(t);
165 }
166
167 $if k == 2 [[
168 template <typename U0, typename U1>
169 tuple& operator=(const ::std::pair<U0, U1>& p) {
170 f0_ = p.first;
171 f1_ = p.second;
172 return *this;
173 }
174
175 ]]
176
177 GTEST_DECLARE_TUPLE_AS_FRIEND_
178
179 template <GTEST_$(k)_TYPENAMES_(U)>
180 tuple& CopyFrom(const GTEST_$(k)_TUPLE_(U)& t) {
181
182 $for m [[
183 f$(m)_ = t.f$(m)_;
184
185 ]]
186 return *this;
187 }
188
189
190 $for m [[
191 T$m f$(m)_;
192
193 ]]
194 };
195
196
197 ]]
198 // 6.1.3.2 Tuple creation functions.
199
200 // Known limitations: we don't support passing an
201 // std::tr1::reference_wrapper<T> to make_tuple(). And we don't
202 // implement tie().
203
204 inline tuple<> make_tuple() { return tuple<>(); }
205
206 $for k [[
207 $range m 0..k-1
208
209 template <GTEST_$(k)_TYPENAMES_(T)>
210 inline GTEST_$(k)_TUPLE_(T) make_tuple($for m, [[const T$m& f$m]]) {
211 return GTEST_$(k)_TUPLE_(T)($for m, [[f$m]]);
212 }
213
214 ]]
215
216 // 6.1.3.3 Tuple helper classes.
217
218 template <typename Tuple> struct tuple_size;
219
220
221 $for j [[
222 template <GTEST_$(j)_TYPENAMES_(T)>
223 struct tuple_size<GTEST_$(j)_TUPLE_(T) > {
224 static const int value = $j;
225 };
226
227
228 ]]
229 template <int k, class Tuple>
230 struct tuple_element {
231 typedef typename gtest_internal::TupleElement<
232 k < (tuple_size<Tuple>::value), k, Tuple>::type type;
233 };
234
235 #define GTEST_TUPLE_ELEMENT_(k, Tuple) typename tuple_element<k, Tuple >::type
236
237 // 6.1.3.4 Element access.
238
239 namespace gtest_internal {
240
241
242 $for i [[
243 template <>
244 class Get<$i> {
245 public:
246 template <class Tuple>
247 static GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple))
248 Field(Tuple& t) { return t.f$(i)_; } // NOLINT
249
250 template <class Tuple>
251 static GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_($i, Tuple))
252 ConstField(const Tuple& t) { return t.f$(i)_; }
253 };
254
255
256 ]]
257 } // namespace gtest_internal
258
259 template <int k, GTEST_$(n)_TYPENAMES_(T)>
260 GTEST_ADD_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T)))
261 get(GTEST_$(n)_TUPLE_(T)& t) {
262 return gtest_internal::Get<k>::Field(t);
263 }
264
265 template <int k, GTEST_$(n)_TYPENAMES_(T)>
266 GTEST_BY_REF_(GTEST_TUPLE_ELEMENT_(k, GTEST_$(n)_TUPLE_(T)))
267 get(const GTEST_$(n)_TUPLE_(T)& t) {
268 return gtest_internal::Get<k>::ConstField(t);
269 }
270
271 // 6.1.3.5 Relational operators
272
273 // We only implement == and !=, as we don't have a need for the rest yet.
274
275 namespace gtest_internal {
276
277 // SameSizeTuplePrefixComparator<k, k>::Eq(t1, t2) returns true if the
278 // first k fields of t1 equals the first k fields of t2.
279 // SameSizeTuplePrefixComparator(k1, k2) would be a compiler error if
280 // k1 != k2.
281 template <int kSize1, int kSize2>
282 struct SameSizeTuplePrefixComparator;
283
284 template <>
285 struct SameSizeTuplePrefixComparator<0, 0> {
286 template <class Tuple1, class Tuple2>
287 static bool Eq(const Tuple1& /* t1 */, const Tuple2& /* t2 */) {
288 return true;
289 }
290 };
291
292 template <int k>
293 struct SameSizeTuplePrefixComparator<k, k> {
294 template <class Tuple1, class Tuple2>
295 static bool Eq(const Tuple1& t1, const Tuple2& t2) {
296 return SameSizeTuplePrefixComparator<k - 1, k - 1>::Eq(t1, t2) &&
297 ::std::tr1::get<k - 1>(t1) == ::std::tr1::get<k - 1>(t2);
298 }
299 };
300
301 } // namespace gtest_internal
302
303 template <GTEST_$(n)_TYPENAMES_(T), GTEST_$(n)_TYPENAMES_(U)>
304 inline bool operator==(const GTEST_$(n)_TUPLE_(T)& t,
305 const GTEST_$(n)_TUPLE_(U)& u) {
306 return gtest_internal::SameSizeTuplePrefixComparator<
307 tuple_size<GTEST_$(n)_TUPLE_(T) >::value,
308 tuple_size<GTEST_$(n)_TUPLE_(U) >::value>::Eq(t, u);
309 }
310
311 template <GTEST_$(n)_TYPENAMES_(T), GTEST_$(n)_TYPENAMES_(U)>
312 inline bool operator!=(const GTEST_$(n)_TUPLE_(T)& t,
313 const GTEST_$(n)_TUPLE_(U)& u) { return !(t == u); }
314
315 // 6.1.4 Pairs.
316 // Unimplemented.
317
318 } // namespace tr1
319 } // namespace std
320
321
322 $for j [[
323 #undef GTEST_$(j)_TUPLE_
324
325 ]]
326
327
328 $for j [[
329 #undef GTEST_$(j)_TYPENAMES_
330
331 ]]
332
333 #undef GTEST_DECLARE_TUPLE_AS_FRIEND_
334 #undef GTEST_BY_REF_
335 #undef GTEST_ADD_REF_
336 #undef GTEST_TUPLE_ELEMENT_
337
338 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TUPLE_H_
0 // This file was GENERATED by command:
1 // pump.py gtest-type-util.h.pump
2 // DO NOT EDIT BY HAND!!!
3
4 // Copyright 2008 Google Inc.
5 // All Rights Reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
9 // met:
10 //
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
16 // distribution.
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Author: wan@google.com (Zhanyong Wan)
34
35 // Type utilities needed for implementing typed and type-parameterized
36 // tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
37 //
38 // Currently we support at most 50 types in a list, and at most 50
39 // type-parameterized tests in one type-parameterized test case.
40 // Please contact googletestframework@googlegroups.com if you need
41 // more.
42
43 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
44 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
45
46 #include "gtest/internal/gtest-port.h"
47
48 // #ifdef __GNUC__ is too general here. It is possible to use gcc without using
49 // libstdc++ (which is where cxxabi.h comes from).
50 # if GTEST_HAS_CXXABI_H_
51 # include <cxxabi.h>
52 # elif defined(__HP_aCC)
53 # include <acxx_demangle.h>
54 # endif // GTEST_HASH_CXXABI_H_
55
56 namespace testing {
57 namespace internal {
58
59 // GetTypeName<T>() returns a human-readable name of type T.
60 // NB: This function is also used in Google Mock, so don't move it inside of
61 // the typed-test-only section below.
62 template <typename T>
63 std::string GetTypeName() {
64 # if GTEST_HAS_RTTI
65
66 const char* const name = typeid(T).name();
67 # if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
68 int status = 0;
69 // gcc's implementation of typeid(T).name() mangles the type name,
70 // so we have to demangle it.
71 # if GTEST_HAS_CXXABI_H_
72 using abi::__cxa_demangle;
73 # endif // GTEST_HAS_CXXABI_H_
74 char* const readable_name = __cxa_demangle(name, 0, 0, &status);
75 const std::string name_str(status == 0 ? readable_name : name);
76 free(readable_name);
77 return name_str;
78 # else
79 return name;
80 # endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
81
82 # else
83
84 return "<type>";
85
86 # endif // GTEST_HAS_RTTI
87 }
88
89 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
90
91 // AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
92 // type. This can be used as a compile-time assertion to ensure that
93 // two types are equal.
94
95 template <typename T1, typename T2>
96 struct AssertTypeEq;
97
98 template <typename T>
99 struct AssertTypeEq<T, T> {
100 typedef bool type;
101 };
102
103 // A unique type used as the default value for the arguments of class
104 // template Types. This allows us to simulate variadic templates
105 // (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
106 // support directly.
107 struct None {};
108
109 // The following family of struct and struct templates are used to
110 // represent type lists. In particular, TypesN<T1, T2, ..., TN>
111 // represents a type list with N types (T1, T2, ..., and TN) in it.
112 // Except for Types0, every struct in the family has two member types:
113 // Head for the first type in the list, and Tail for the rest of the
114 // list.
115
116 // The empty type list.
117 struct Types0 {};
118
119 // Type lists of length 1, 2, 3, and so on.
120
121 template <typename T1>
122 struct Types1 {
123 typedef T1 Head;
124 typedef Types0 Tail;
125 };
126 template <typename T1, typename T2>
127 struct Types2 {
128 typedef T1 Head;
129 typedef Types1<T2> Tail;
130 };
131
132 template <typename T1, typename T2, typename T3>
133 struct Types3 {
134 typedef T1 Head;
135 typedef Types2<T2, T3> Tail;
136 };
137
138 template <typename T1, typename T2, typename T3, typename T4>
139 struct Types4 {
140 typedef T1 Head;
141 typedef Types3<T2, T3, T4> Tail;
142 };
143
144 template <typename T1, typename T2, typename T3, typename T4, typename T5>
145 struct Types5 {
146 typedef T1 Head;
147 typedef Types4<T2, T3, T4, T5> Tail;
148 };
149
150 template <typename T1, typename T2, typename T3, typename T4, typename T5,
151 typename T6>
152 struct Types6 {
153 typedef T1 Head;
154 typedef Types5<T2, T3, T4, T5, T6> Tail;
155 };
156
157 template <typename T1, typename T2, typename T3, typename T4, typename T5,
158 typename T6, typename T7>
159 struct Types7 {
160 typedef T1 Head;
161 typedef Types6<T2, T3, T4, T5, T6, T7> Tail;
162 };
163
164 template <typename T1, typename T2, typename T3, typename T4, typename T5,
165 typename T6, typename T7, typename T8>
166 struct Types8 {
167 typedef T1 Head;
168 typedef Types7<T2, T3, T4, T5, T6, T7, T8> Tail;
169 };
170
171 template <typename T1, typename T2, typename T3, typename T4, typename T5,
172 typename T6, typename T7, typename T8, typename T9>
173 struct Types9 {
174 typedef T1 Head;
175 typedef Types8<T2, T3, T4, T5, T6, T7, T8, T9> Tail;
176 };
177
178 template <typename T1, typename T2, typename T3, typename T4, typename T5,
179 typename T6, typename T7, typename T8, typename T9, typename T10>
180 struct Types10 {
181 typedef T1 Head;
182 typedef Types9<T2, T3, T4, T5, T6, T7, T8, T9, T10> Tail;
183 };
184
185 template <typename T1, typename T2, typename T3, typename T4, typename T5,
186 typename T6, typename T7, typename T8, typename T9, typename T10,
187 typename T11>
188 struct Types11 {
189 typedef T1 Head;
190 typedef Types10<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Tail;
191 };
192
193 template <typename T1, typename T2, typename T3, typename T4, typename T5,
194 typename T6, typename T7, typename T8, typename T9, typename T10,
195 typename T11, typename T12>
196 struct Types12 {
197 typedef T1 Head;
198 typedef Types11<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Tail;
199 };
200
201 template <typename T1, typename T2, typename T3, typename T4, typename T5,
202 typename T6, typename T7, typename T8, typename T9, typename T10,
203 typename T11, typename T12, typename T13>
204 struct Types13 {
205 typedef T1 Head;
206 typedef Types12<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> Tail;
207 };
208
209 template <typename T1, typename T2, typename T3, typename T4, typename T5,
210 typename T6, typename T7, typename T8, typename T9, typename T10,
211 typename T11, typename T12, typename T13, typename T14>
212 struct Types14 {
213 typedef T1 Head;
214 typedef Types13<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> Tail;
215 };
216
217 template <typename T1, typename T2, typename T3, typename T4, typename T5,
218 typename T6, typename T7, typename T8, typename T9, typename T10,
219 typename T11, typename T12, typename T13, typename T14, typename T15>
220 struct Types15 {
221 typedef T1 Head;
222 typedef Types14<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
223 T15> Tail;
224 };
225
226 template <typename T1, typename T2, typename T3, typename T4, typename T5,
227 typename T6, typename T7, typename T8, typename T9, typename T10,
228 typename T11, typename T12, typename T13, typename T14, typename T15,
229 typename T16>
230 struct Types16 {
231 typedef T1 Head;
232 typedef Types15<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
233 T16> Tail;
234 };
235
236 template <typename T1, typename T2, typename T3, typename T4, typename T5,
237 typename T6, typename T7, typename T8, typename T9, typename T10,
238 typename T11, typename T12, typename T13, typename T14, typename T15,
239 typename T16, typename T17>
240 struct Types17 {
241 typedef T1 Head;
242 typedef Types16<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
243 T16, T17> Tail;
244 };
245
246 template <typename T1, typename T2, typename T3, typename T4, typename T5,
247 typename T6, typename T7, typename T8, typename T9, typename T10,
248 typename T11, typename T12, typename T13, typename T14, typename T15,
249 typename T16, typename T17, typename T18>
250 struct Types18 {
251 typedef T1 Head;
252 typedef Types17<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
253 T16, T17, T18> Tail;
254 };
255
256 template <typename T1, typename T2, typename T3, typename T4, typename T5,
257 typename T6, typename T7, typename T8, typename T9, typename T10,
258 typename T11, typename T12, typename T13, typename T14, typename T15,
259 typename T16, typename T17, typename T18, typename T19>
260 struct Types19 {
261 typedef T1 Head;
262 typedef Types18<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
263 T16, T17, T18, T19> Tail;
264 };
265
266 template <typename T1, typename T2, typename T3, typename T4, typename T5,
267 typename T6, typename T7, typename T8, typename T9, typename T10,
268 typename T11, typename T12, typename T13, typename T14, typename T15,
269 typename T16, typename T17, typename T18, typename T19, typename T20>
270 struct Types20 {
271 typedef T1 Head;
272 typedef Types19<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
273 T16, T17, T18, T19, T20> Tail;
274 };
275
276 template <typename T1, typename T2, typename T3, typename T4, typename T5,
277 typename T6, typename T7, typename T8, typename T9, typename T10,
278 typename T11, typename T12, typename T13, typename T14, typename T15,
279 typename T16, typename T17, typename T18, typename T19, typename T20,
280 typename T21>
281 struct Types21 {
282 typedef T1 Head;
283 typedef Types20<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
284 T16, T17, T18, T19, T20, T21> Tail;
285 };
286
287 template <typename T1, typename T2, typename T3, typename T4, typename T5,
288 typename T6, typename T7, typename T8, typename T9, typename T10,
289 typename T11, typename T12, typename T13, typename T14, typename T15,
290 typename T16, typename T17, typename T18, typename T19, typename T20,
291 typename T21, typename T22>
292 struct Types22 {
293 typedef T1 Head;
294 typedef Types21<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
295 T16, T17, T18, T19, T20, T21, T22> Tail;
296 };
297
298 template <typename T1, typename T2, typename T3, typename T4, typename T5,
299 typename T6, typename T7, typename T8, typename T9, typename T10,
300 typename T11, typename T12, typename T13, typename T14, typename T15,
301 typename T16, typename T17, typename T18, typename T19, typename T20,
302 typename T21, typename T22, typename T23>
303 struct Types23 {
304 typedef T1 Head;
305 typedef Types22<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
306 T16, T17, T18, T19, T20, T21, T22, T23> Tail;
307 };
308
309 template <typename T1, typename T2, typename T3, typename T4, typename T5,
310 typename T6, typename T7, typename T8, typename T9, typename T10,
311 typename T11, typename T12, typename T13, typename T14, typename T15,
312 typename T16, typename T17, typename T18, typename T19, typename T20,
313 typename T21, typename T22, typename T23, typename T24>
314 struct Types24 {
315 typedef T1 Head;
316 typedef Types23<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
317 T16, T17, T18, T19, T20, T21, T22, T23, T24> Tail;
318 };
319
320 template <typename T1, typename T2, typename T3, typename T4, typename T5,
321 typename T6, typename T7, typename T8, typename T9, typename T10,
322 typename T11, typename T12, typename T13, typename T14, typename T15,
323 typename T16, typename T17, typename T18, typename T19, typename T20,
324 typename T21, typename T22, typename T23, typename T24, typename T25>
325 struct Types25 {
326 typedef T1 Head;
327 typedef Types24<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
328 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> Tail;
329 };
330
331 template <typename T1, typename T2, typename T3, typename T4, typename T5,
332 typename T6, typename T7, typename T8, typename T9, typename T10,
333 typename T11, typename T12, typename T13, typename T14, typename T15,
334 typename T16, typename T17, typename T18, typename T19, typename T20,
335 typename T21, typename T22, typename T23, typename T24, typename T25,
336 typename T26>
337 struct Types26 {
338 typedef T1 Head;
339 typedef Types25<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
340 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26> Tail;
341 };
342
343 template <typename T1, typename T2, typename T3, typename T4, typename T5,
344 typename T6, typename T7, typename T8, typename T9, typename T10,
345 typename T11, typename T12, typename T13, typename T14, typename T15,
346 typename T16, typename T17, typename T18, typename T19, typename T20,
347 typename T21, typename T22, typename T23, typename T24, typename T25,
348 typename T26, typename T27>
349 struct Types27 {
350 typedef T1 Head;
351 typedef Types26<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
352 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27> Tail;
353 };
354
355 template <typename T1, typename T2, typename T3, typename T4, typename T5,
356 typename T6, typename T7, typename T8, typename T9, typename T10,
357 typename T11, typename T12, typename T13, typename T14, typename T15,
358 typename T16, typename T17, typename T18, typename T19, typename T20,
359 typename T21, typename T22, typename T23, typename T24, typename T25,
360 typename T26, typename T27, typename T28>
361 struct Types28 {
362 typedef T1 Head;
363 typedef Types27<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
364 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28> Tail;
365 };
366
367 template <typename T1, typename T2, typename T3, typename T4, typename T5,
368 typename T6, typename T7, typename T8, typename T9, typename T10,
369 typename T11, typename T12, typename T13, typename T14, typename T15,
370 typename T16, typename T17, typename T18, typename T19, typename T20,
371 typename T21, typename T22, typename T23, typename T24, typename T25,
372 typename T26, typename T27, typename T28, typename T29>
373 struct Types29 {
374 typedef T1 Head;
375 typedef Types28<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
376 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
377 T29> Tail;
378 };
379
380 template <typename T1, typename T2, typename T3, typename T4, typename T5,
381 typename T6, typename T7, typename T8, typename T9, typename T10,
382 typename T11, typename T12, typename T13, typename T14, typename T15,
383 typename T16, typename T17, typename T18, typename T19, typename T20,
384 typename T21, typename T22, typename T23, typename T24, typename T25,
385 typename T26, typename T27, typename T28, typename T29, typename T30>
386 struct Types30 {
387 typedef T1 Head;
388 typedef Types29<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
389 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
390 T30> Tail;
391 };
392
393 template <typename T1, typename T2, typename T3, typename T4, typename T5,
394 typename T6, typename T7, typename T8, typename T9, typename T10,
395 typename T11, typename T12, typename T13, typename T14, typename T15,
396 typename T16, typename T17, typename T18, typename T19, typename T20,
397 typename T21, typename T22, typename T23, typename T24, typename T25,
398 typename T26, typename T27, typename T28, typename T29, typename T30,
399 typename T31>
400 struct Types31 {
401 typedef T1 Head;
402 typedef Types30<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
403 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
404 T30, T31> Tail;
405 };
406
407 template <typename T1, typename T2, typename T3, typename T4, typename T5,
408 typename T6, typename T7, typename T8, typename T9, typename T10,
409 typename T11, typename T12, typename T13, typename T14, typename T15,
410 typename T16, typename T17, typename T18, typename T19, typename T20,
411 typename T21, typename T22, typename T23, typename T24, typename T25,
412 typename T26, typename T27, typename T28, typename T29, typename T30,
413 typename T31, typename T32>
414 struct Types32 {
415 typedef T1 Head;
416 typedef Types31<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
417 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
418 T30, T31, T32> Tail;
419 };
420
421 template <typename T1, typename T2, typename T3, typename T4, typename T5,
422 typename T6, typename T7, typename T8, typename T9, typename T10,
423 typename T11, typename T12, typename T13, typename T14, typename T15,
424 typename T16, typename T17, typename T18, typename T19, typename T20,
425 typename T21, typename T22, typename T23, typename T24, typename T25,
426 typename T26, typename T27, typename T28, typename T29, typename T30,
427 typename T31, typename T32, typename T33>
428 struct Types33 {
429 typedef T1 Head;
430 typedef Types32<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
431 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
432 T30, T31, T32, T33> Tail;
433 };
434
435 template <typename T1, typename T2, typename T3, typename T4, typename T5,
436 typename T6, typename T7, typename T8, typename T9, typename T10,
437 typename T11, typename T12, typename T13, typename T14, typename T15,
438 typename T16, typename T17, typename T18, typename T19, typename T20,
439 typename T21, typename T22, typename T23, typename T24, typename T25,
440 typename T26, typename T27, typename T28, typename T29, typename T30,
441 typename T31, typename T32, typename T33, typename T34>
442 struct Types34 {
443 typedef T1 Head;
444 typedef Types33<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
445 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
446 T30, T31, T32, T33, T34> Tail;
447 };
448
449 template <typename T1, typename T2, typename T3, typename T4, typename T5,
450 typename T6, typename T7, typename T8, typename T9, typename T10,
451 typename T11, typename T12, typename T13, typename T14, typename T15,
452 typename T16, typename T17, typename T18, typename T19, typename T20,
453 typename T21, typename T22, typename T23, typename T24, typename T25,
454 typename T26, typename T27, typename T28, typename T29, typename T30,
455 typename T31, typename T32, typename T33, typename T34, typename T35>
456 struct Types35 {
457 typedef T1 Head;
458 typedef Types34<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
459 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
460 T30, T31, T32, T33, T34, T35> Tail;
461 };
462
463 template <typename T1, typename T2, typename T3, typename T4, typename T5,
464 typename T6, typename T7, typename T8, typename T9, typename T10,
465 typename T11, typename T12, typename T13, typename T14, typename T15,
466 typename T16, typename T17, typename T18, typename T19, typename T20,
467 typename T21, typename T22, typename T23, typename T24, typename T25,
468 typename T26, typename T27, typename T28, typename T29, typename T30,
469 typename T31, typename T32, typename T33, typename T34, typename T35,
470 typename T36>
471 struct Types36 {
472 typedef T1 Head;
473 typedef Types35<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
474 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
475 T30, T31, T32, T33, T34, T35, T36> Tail;
476 };
477
478 template <typename T1, typename T2, typename T3, typename T4, typename T5,
479 typename T6, typename T7, typename T8, typename T9, typename T10,
480 typename T11, typename T12, typename T13, typename T14, typename T15,
481 typename T16, typename T17, typename T18, typename T19, typename T20,
482 typename T21, typename T22, typename T23, typename T24, typename T25,
483 typename T26, typename T27, typename T28, typename T29, typename T30,
484 typename T31, typename T32, typename T33, typename T34, typename T35,
485 typename T36, typename T37>
486 struct Types37 {
487 typedef T1 Head;
488 typedef Types36<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
489 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
490 T30, T31, T32, T33, T34, T35, T36, T37> Tail;
491 };
492
493 template <typename T1, typename T2, typename T3, typename T4, typename T5,
494 typename T6, typename T7, typename T8, typename T9, typename T10,
495 typename T11, typename T12, typename T13, typename T14, typename T15,
496 typename T16, typename T17, typename T18, typename T19, typename T20,
497 typename T21, typename T22, typename T23, typename T24, typename T25,
498 typename T26, typename T27, typename T28, typename T29, typename T30,
499 typename T31, typename T32, typename T33, typename T34, typename T35,
500 typename T36, typename T37, typename T38>
501 struct Types38 {
502 typedef T1 Head;
503 typedef Types37<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
504 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
505 T30, T31, T32, T33, T34, T35, T36, T37, T38> Tail;
506 };
507
508 template <typename T1, typename T2, typename T3, typename T4, typename T5,
509 typename T6, typename T7, typename T8, typename T9, typename T10,
510 typename T11, typename T12, typename T13, typename T14, typename T15,
511 typename T16, typename T17, typename T18, typename T19, typename T20,
512 typename T21, typename T22, typename T23, typename T24, typename T25,
513 typename T26, typename T27, typename T28, typename T29, typename T30,
514 typename T31, typename T32, typename T33, typename T34, typename T35,
515 typename T36, typename T37, typename T38, typename T39>
516 struct Types39 {
517 typedef T1 Head;
518 typedef Types38<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
519 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
520 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> Tail;
521 };
522
523 template <typename T1, typename T2, typename T3, typename T4, typename T5,
524 typename T6, typename T7, typename T8, typename T9, typename T10,
525 typename T11, typename T12, typename T13, typename T14, typename T15,
526 typename T16, typename T17, typename T18, typename T19, typename T20,
527 typename T21, typename T22, typename T23, typename T24, typename T25,
528 typename T26, typename T27, typename T28, typename T29, typename T30,
529 typename T31, typename T32, typename T33, typename T34, typename T35,
530 typename T36, typename T37, typename T38, typename T39, typename T40>
531 struct Types40 {
532 typedef T1 Head;
533 typedef Types39<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
534 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
535 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> Tail;
536 };
537
538 template <typename T1, typename T2, typename T3, typename T4, typename T5,
539 typename T6, typename T7, typename T8, typename T9, typename T10,
540 typename T11, typename T12, typename T13, typename T14, typename T15,
541 typename T16, typename T17, typename T18, typename T19, typename T20,
542 typename T21, typename T22, typename T23, typename T24, typename T25,
543 typename T26, typename T27, typename T28, typename T29, typename T30,
544 typename T31, typename T32, typename T33, typename T34, typename T35,
545 typename T36, typename T37, typename T38, typename T39, typename T40,
546 typename T41>
547 struct Types41 {
548 typedef T1 Head;
549 typedef Types40<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
550 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
551 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41> Tail;
552 };
553
554 template <typename T1, typename T2, typename T3, typename T4, typename T5,
555 typename T6, typename T7, typename T8, typename T9, typename T10,
556 typename T11, typename T12, typename T13, typename T14, typename T15,
557 typename T16, typename T17, typename T18, typename T19, typename T20,
558 typename T21, typename T22, typename T23, typename T24, typename T25,
559 typename T26, typename T27, typename T28, typename T29, typename T30,
560 typename T31, typename T32, typename T33, typename T34, typename T35,
561 typename T36, typename T37, typename T38, typename T39, typename T40,
562 typename T41, typename T42>
563 struct Types42 {
564 typedef T1 Head;
565 typedef Types41<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
566 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
567 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42> Tail;
568 };
569
570 template <typename T1, typename T2, typename T3, typename T4, typename T5,
571 typename T6, typename T7, typename T8, typename T9, typename T10,
572 typename T11, typename T12, typename T13, typename T14, typename T15,
573 typename T16, typename T17, typename T18, typename T19, typename T20,
574 typename T21, typename T22, typename T23, typename T24, typename T25,
575 typename T26, typename T27, typename T28, typename T29, typename T30,
576 typename T31, typename T32, typename T33, typename T34, typename T35,
577 typename T36, typename T37, typename T38, typename T39, typename T40,
578 typename T41, typename T42, typename T43>
579 struct Types43 {
580 typedef T1 Head;
581 typedef Types42<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
582 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
583 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
584 T43> Tail;
585 };
586
587 template <typename T1, typename T2, typename T3, typename T4, typename T5,
588 typename T6, typename T7, typename T8, typename T9, typename T10,
589 typename T11, typename T12, typename T13, typename T14, typename T15,
590 typename T16, typename T17, typename T18, typename T19, typename T20,
591 typename T21, typename T22, typename T23, typename T24, typename T25,
592 typename T26, typename T27, typename T28, typename T29, typename T30,
593 typename T31, typename T32, typename T33, typename T34, typename T35,
594 typename T36, typename T37, typename T38, typename T39, typename T40,
595 typename T41, typename T42, typename T43, typename T44>
596 struct Types44 {
597 typedef T1 Head;
598 typedef Types43<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
599 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
600 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
601 T44> Tail;
602 };
603
604 template <typename T1, typename T2, typename T3, typename T4, typename T5,
605 typename T6, typename T7, typename T8, typename T9, typename T10,
606 typename T11, typename T12, typename T13, typename T14, typename T15,
607 typename T16, typename T17, typename T18, typename T19, typename T20,
608 typename T21, typename T22, typename T23, typename T24, typename T25,
609 typename T26, typename T27, typename T28, typename T29, typename T30,
610 typename T31, typename T32, typename T33, typename T34, typename T35,
611 typename T36, typename T37, typename T38, typename T39, typename T40,
612 typename T41, typename T42, typename T43, typename T44, typename T45>
613 struct Types45 {
614 typedef T1 Head;
615 typedef Types44<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
616 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
617 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
618 T44, T45> Tail;
619 };
620
621 template <typename T1, typename T2, typename T3, typename T4, typename T5,
622 typename T6, typename T7, typename T8, typename T9, typename T10,
623 typename T11, typename T12, typename T13, typename T14, typename T15,
624 typename T16, typename T17, typename T18, typename T19, typename T20,
625 typename T21, typename T22, typename T23, typename T24, typename T25,
626 typename T26, typename T27, typename T28, typename T29, typename T30,
627 typename T31, typename T32, typename T33, typename T34, typename T35,
628 typename T36, typename T37, typename T38, typename T39, typename T40,
629 typename T41, typename T42, typename T43, typename T44, typename T45,
630 typename T46>
631 struct Types46 {
632 typedef T1 Head;
633 typedef Types45<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
634 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
635 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
636 T44, T45, T46> Tail;
637 };
638
639 template <typename T1, typename T2, typename T3, typename T4, typename T5,
640 typename T6, typename T7, typename T8, typename T9, typename T10,
641 typename T11, typename T12, typename T13, typename T14, typename T15,
642 typename T16, typename T17, typename T18, typename T19, typename T20,
643 typename T21, typename T22, typename T23, typename T24, typename T25,
644 typename T26, typename T27, typename T28, typename T29, typename T30,
645 typename T31, typename T32, typename T33, typename T34, typename T35,
646 typename T36, typename T37, typename T38, typename T39, typename T40,
647 typename T41, typename T42, typename T43, typename T44, typename T45,
648 typename T46, typename T47>
649 struct Types47 {
650 typedef T1 Head;
651 typedef Types46<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
652 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
653 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
654 T44, T45, T46, T47> Tail;
655 };
656
657 template <typename T1, typename T2, typename T3, typename T4, typename T5,
658 typename T6, typename T7, typename T8, typename T9, typename T10,
659 typename T11, typename T12, typename T13, typename T14, typename T15,
660 typename T16, typename T17, typename T18, typename T19, typename T20,
661 typename T21, typename T22, typename T23, typename T24, typename T25,
662 typename T26, typename T27, typename T28, typename T29, typename T30,
663 typename T31, typename T32, typename T33, typename T34, typename T35,
664 typename T36, typename T37, typename T38, typename T39, typename T40,
665 typename T41, typename T42, typename T43, typename T44, typename T45,
666 typename T46, typename T47, typename T48>
667 struct Types48 {
668 typedef T1 Head;
669 typedef Types47<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
670 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
671 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
672 T44, T45, T46, T47, T48> Tail;
673 };
674
675 template <typename T1, typename T2, typename T3, typename T4, typename T5,
676 typename T6, typename T7, typename T8, typename T9, typename T10,
677 typename T11, typename T12, typename T13, typename T14, typename T15,
678 typename T16, typename T17, typename T18, typename T19, typename T20,
679 typename T21, typename T22, typename T23, typename T24, typename T25,
680 typename T26, typename T27, typename T28, typename T29, typename T30,
681 typename T31, typename T32, typename T33, typename T34, typename T35,
682 typename T36, typename T37, typename T38, typename T39, typename T40,
683 typename T41, typename T42, typename T43, typename T44, typename T45,
684 typename T46, typename T47, typename T48, typename T49>
685 struct Types49 {
686 typedef T1 Head;
687 typedef Types48<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
688 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
689 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
690 T44, T45, T46, T47, T48, T49> Tail;
691 };
692
693 template <typename T1, typename T2, typename T3, typename T4, typename T5,
694 typename T6, typename T7, typename T8, typename T9, typename T10,
695 typename T11, typename T12, typename T13, typename T14, typename T15,
696 typename T16, typename T17, typename T18, typename T19, typename T20,
697 typename T21, typename T22, typename T23, typename T24, typename T25,
698 typename T26, typename T27, typename T28, typename T29, typename T30,
699 typename T31, typename T32, typename T33, typename T34, typename T35,
700 typename T36, typename T37, typename T38, typename T39, typename T40,
701 typename T41, typename T42, typename T43, typename T44, typename T45,
702 typename T46, typename T47, typename T48, typename T49, typename T50>
703 struct Types50 {
704 typedef T1 Head;
705 typedef Types49<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
706 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
707 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
708 T44, T45, T46, T47, T48, T49, T50> Tail;
709 };
710
711
712 } // namespace internal
713
714 // We don't want to require the users to write TypesN<...> directly,
715 // as that would require them to count the length. Types<...> is much
716 // easier to write, but generates horrible messages when there is a
717 // compiler error, as gcc insists on printing out each template
718 // argument, even if it has the default value (this means Types<int>
719 // will appear as Types<int, None, None, ..., None> in the compiler
720 // errors).
721 //
722 // Our solution is to combine the best part of the two approaches: a
723 // user would write Types<T1, ..., TN>, and Google Test will translate
724 // that to TypesN<T1, ..., TN> internally to make error messages
725 // readable. The translation is done by the 'type' member of the
726 // Types template.
727 template <typename T1 = internal::None, typename T2 = internal::None,
728 typename T3 = internal::None, typename T4 = internal::None,
729 typename T5 = internal::None, typename T6 = internal::None,
730 typename T7 = internal::None, typename T8 = internal::None,
731 typename T9 = internal::None, typename T10 = internal::None,
732 typename T11 = internal::None, typename T12 = internal::None,
733 typename T13 = internal::None, typename T14 = internal::None,
734 typename T15 = internal::None, typename T16 = internal::None,
735 typename T17 = internal::None, typename T18 = internal::None,
736 typename T19 = internal::None, typename T20 = internal::None,
737 typename T21 = internal::None, typename T22 = internal::None,
738 typename T23 = internal::None, typename T24 = internal::None,
739 typename T25 = internal::None, typename T26 = internal::None,
740 typename T27 = internal::None, typename T28 = internal::None,
741 typename T29 = internal::None, typename T30 = internal::None,
742 typename T31 = internal::None, typename T32 = internal::None,
743 typename T33 = internal::None, typename T34 = internal::None,
744 typename T35 = internal::None, typename T36 = internal::None,
745 typename T37 = internal::None, typename T38 = internal::None,
746 typename T39 = internal::None, typename T40 = internal::None,
747 typename T41 = internal::None, typename T42 = internal::None,
748 typename T43 = internal::None, typename T44 = internal::None,
749 typename T45 = internal::None, typename T46 = internal::None,
750 typename T47 = internal::None, typename T48 = internal::None,
751 typename T49 = internal::None, typename T50 = internal::None>
752 struct Types {
753 typedef internal::Types50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
754 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
755 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
756 T41, T42, T43, T44, T45, T46, T47, T48, T49, T50> type;
757 };
758
759 template <>
760 struct Types<internal::None, internal::None, internal::None, internal::None,
761 internal::None, internal::None, internal::None, internal::None,
762 internal::None, internal::None, internal::None, internal::None,
763 internal::None, internal::None, internal::None, internal::None,
764 internal::None, internal::None, internal::None, internal::None,
765 internal::None, internal::None, internal::None, internal::None,
766 internal::None, internal::None, internal::None, internal::None,
767 internal::None, internal::None, internal::None, internal::None,
768 internal::None, internal::None, internal::None, internal::None,
769 internal::None, internal::None, internal::None, internal::None,
770 internal::None, internal::None, internal::None, internal::None,
771 internal::None, internal::None, internal::None, internal::None,
772 internal::None, internal::None> {
773 typedef internal::Types0 type;
774 };
775 template <typename T1>
776 struct Types<T1, internal::None, internal::None, internal::None,
777 internal::None, internal::None, internal::None, internal::None,
778 internal::None, internal::None, internal::None, internal::None,
779 internal::None, internal::None, internal::None, internal::None,
780 internal::None, internal::None, internal::None, internal::None,
781 internal::None, internal::None, internal::None, internal::None,
782 internal::None, internal::None, internal::None, internal::None,
783 internal::None, internal::None, internal::None, internal::None,
784 internal::None, internal::None, internal::None, internal::None,
785 internal::None, internal::None, internal::None, internal::None,
786 internal::None, internal::None, internal::None, internal::None,
787 internal::None, internal::None, internal::None, internal::None,
788 internal::None, internal::None> {
789 typedef internal::Types1<T1> type;
790 };
791 template <typename T1, typename T2>
792 struct Types<T1, T2, internal::None, internal::None, internal::None,
793 internal::None, internal::None, internal::None, internal::None,
794 internal::None, internal::None, internal::None, internal::None,
795 internal::None, internal::None, internal::None, internal::None,
796 internal::None, internal::None, internal::None, internal::None,
797 internal::None, internal::None, internal::None, internal::None,
798 internal::None, internal::None, internal::None, internal::None,
799 internal::None, internal::None, internal::None, internal::None,
800 internal::None, internal::None, internal::None, internal::None,
801 internal::None, internal::None, internal::None, internal::None,
802 internal::None, internal::None, internal::None, internal::None,
803 internal::None, internal::None, internal::None, internal::None,
804 internal::None> {
805 typedef internal::Types2<T1, T2> type;
806 };
807 template <typename T1, typename T2, typename T3>
808 struct Types<T1, T2, T3, internal::None, internal::None, internal::None,
809 internal::None, internal::None, internal::None, internal::None,
810 internal::None, internal::None, internal::None, internal::None,
811 internal::None, internal::None, internal::None, internal::None,
812 internal::None, internal::None, internal::None, internal::None,
813 internal::None, internal::None, internal::None, internal::None,
814 internal::None, internal::None, internal::None, internal::None,
815 internal::None, internal::None, internal::None, internal::None,
816 internal::None, internal::None, internal::None, internal::None,
817 internal::None, internal::None, internal::None, internal::None,
818 internal::None, internal::None, internal::None, internal::None,
819 internal::None, internal::None, internal::None, internal::None> {
820 typedef internal::Types3<T1, T2, T3> type;
821 };
822 template <typename T1, typename T2, typename T3, typename T4>
823 struct Types<T1, T2, T3, T4, internal::None, internal::None, internal::None,
824 internal::None, internal::None, internal::None, internal::None,
825 internal::None, internal::None, internal::None, internal::None,
826 internal::None, internal::None, internal::None, internal::None,
827 internal::None, internal::None, internal::None, internal::None,
828 internal::None, internal::None, internal::None, internal::None,
829 internal::None, internal::None, internal::None, internal::None,
830 internal::None, internal::None, internal::None, internal::None,
831 internal::None, internal::None, internal::None, internal::None,
832 internal::None, internal::None, internal::None, internal::None,
833 internal::None, internal::None, internal::None, internal::None,
834 internal::None, internal::None, internal::None> {
835 typedef internal::Types4<T1, T2, T3, T4> type;
836 };
837 template <typename T1, typename T2, typename T3, typename T4, typename T5>
838 struct Types<T1, T2, T3, T4, T5, internal::None, internal::None,
839 internal::None, internal::None, internal::None, internal::None,
840 internal::None, internal::None, internal::None, internal::None,
841 internal::None, internal::None, internal::None, internal::None,
842 internal::None, internal::None, internal::None, internal::None,
843 internal::None, internal::None, internal::None, internal::None,
844 internal::None, internal::None, internal::None, internal::None,
845 internal::None, internal::None, internal::None, internal::None,
846 internal::None, internal::None, internal::None, internal::None,
847 internal::None, internal::None, internal::None, internal::None,
848 internal::None, internal::None, internal::None, internal::None,
849 internal::None, internal::None, internal::None> {
850 typedef internal::Types5<T1, T2, T3, T4, T5> type;
851 };
852 template <typename T1, typename T2, typename T3, typename T4, typename T5,
853 typename T6>
854 struct Types<T1, T2, T3, T4, T5, T6, internal::None, internal::None,
855 internal::None, internal::None, internal::None, internal::None,
856 internal::None, internal::None, internal::None, internal::None,
857 internal::None, internal::None, internal::None, internal::None,
858 internal::None, internal::None, internal::None, internal::None,
859 internal::None, internal::None, internal::None, internal::None,
860 internal::None, internal::None, internal::None, internal::None,
861 internal::None, internal::None, internal::None, internal::None,
862 internal::None, internal::None, internal::None, internal::None,
863 internal::None, internal::None, internal::None, internal::None,
864 internal::None, internal::None, internal::None, internal::None,
865 internal::None, internal::None> {
866 typedef internal::Types6<T1, T2, T3, T4, T5, T6> type;
867 };
868 template <typename T1, typename T2, typename T3, typename T4, typename T5,
869 typename T6, typename T7>
870 struct Types<T1, T2, T3, T4, T5, T6, T7, internal::None, internal::None,
871 internal::None, internal::None, internal::None, internal::None,
872 internal::None, internal::None, internal::None, internal::None,
873 internal::None, internal::None, internal::None, internal::None,
874 internal::None, internal::None, internal::None, internal::None,
875 internal::None, internal::None, internal::None, internal::None,
876 internal::None, internal::None, internal::None, internal::None,
877 internal::None, internal::None, internal::None, internal::None,
878 internal::None, internal::None, internal::None, internal::None,
879 internal::None, internal::None, internal::None, internal::None,
880 internal::None, internal::None, internal::None, internal::None,
881 internal::None> {
882 typedef internal::Types7<T1, T2, T3, T4, T5, T6, T7> type;
883 };
884 template <typename T1, typename T2, typename T3, typename T4, typename T5,
885 typename T6, typename T7, typename T8>
886 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, internal::None, internal::None,
887 internal::None, internal::None, internal::None, internal::None,
888 internal::None, internal::None, internal::None, internal::None,
889 internal::None, internal::None, internal::None, internal::None,
890 internal::None, internal::None, internal::None, internal::None,
891 internal::None, internal::None, internal::None, internal::None,
892 internal::None, internal::None, internal::None, internal::None,
893 internal::None, internal::None, internal::None, internal::None,
894 internal::None, internal::None, internal::None, internal::None,
895 internal::None, internal::None, internal::None, internal::None,
896 internal::None, internal::None, internal::None, internal::None> {
897 typedef internal::Types8<T1, T2, T3, T4, T5, T6, T7, T8> type;
898 };
899 template <typename T1, typename T2, typename T3, typename T4, typename T5,
900 typename T6, typename T7, typename T8, typename T9>
901 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, internal::None,
902 internal::None, internal::None, internal::None, internal::None,
903 internal::None, internal::None, internal::None, internal::None,
904 internal::None, internal::None, internal::None, internal::None,
905 internal::None, internal::None, internal::None, internal::None,
906 internal::None, internal::None, internal::None, internal::None,
907 internal::None, internal::None, internal::None, internal::None,
908 internal::None, internal::None, internal::None, internal::None,
909 internal::None, internal::None, internal::None, internal::None,
910 internal::None, internal::None, internal::None, internal::None,
911 internal::None, internal::None, internal::None, internal::None> {
912 typedef internal::Types9<T1, T2, T3, T4, T5, T6, T7, T8, T9> type;
913 };
914 template <typename T1, typename T2, typename T3, typename T4, typename T5,
915 typename T6, typename T7, typename T8, typename T9, typename T10>
916 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, internal::None,
917 internal::None, internal::None, internal::None, internal::None,
918 internal::None, internal::None, internal::None, internal::None,
919 internal::None, internal::None, internal::None, internal::None,
920 internal::None, internal::None, internal::None, internal::None,
921 internal::None, internal::None, internal::None, internal::None,
922 internal::None, internal::None, internal::None, internal::None,
923 internal::None, internal::None, internal::None, internal::None,
924 internal::None, internal::None, internal::None, internal::None,
925 internal::None, internal::None, internal::None, internal::None,
926 internal::None, internal::None, internal::None> {
927 typedef internal::Types10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> type;
928 };
929 template <typename T1, typename T2, typename T3, typename T4, typename T5,
930 typename T6, typename T7, typename T8, typename T9, typename T10,
931 typename T11>
932 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, internal::None,
933 internal::None, internal::None, internal::None, internal::None,
934 internal::None, internal::None, internal::None, internal::None,
935 internal::None, internal::None, internal::None, internal::None,
936 internal::None, internal::None, internal::None, internal::None,
937 internal::None, internal::None, internal::None, internal::None,
938 internal::None, internal::None, internal::None, internal::None,
939 internal::None, internal::None, internal::None, internal::None,
940 internal::None, internal::None, internal::None, internal::None,
941 internal::None, internal::None, internal::None, internal::None,
942 internal::None, internal::None> {
943 typedef internal::Types11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> type;
944 };
945 template <typename T1, typename T2, typename T3, typename T4, typename T5,
946 typename T6, typename T7, typename T8, typename T9, typename T10,
947 typename T11, typename T12>
948 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, internal::None,
949 internal::None, internal::None, internal::None, internal::None,
950 internal::None, internal::None, internal::None, internal::None,
951 internal::None, internal::None, internal::None, internal::None,
952 internal::None, internal::None, internal::None, internal::None,
953 internal::None, internal::None, internal::None, internal::None,
954 internal::None, internal::None, internal::None, internal::None,
955 internal::None, internal::None, internal::None, internal::None,
956 internal::None, internal::None, internal::None, internal::None,
957 internal::None, internal::None, internal::None, internal::None,
958 internal::None> {
959 typedef internal::Types12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
960 T12> type;
961 };
962 template <typename T1, typename T2, typename T3, typename T4, typename T5,
963 typename T6, typename T7, typename T8, typename T9, typename T10,
964 typename T11, typename T12, typename T13>
965 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
966 internal::None, internal::None, internal::None, internal::None,
967 internal::None, internal::None, internal::None, internal::None,
968 internal::None, internal::None, internal::None, internal::None,
969 internal::None, internal::None, internal::None, internal::None,
970 internal::None, internal::None, internal::None, internal::None,
971 internal::None, internal::None, internal::None, internal::None,
972 internal::None, internal::None, internal::None, internal::None,
973 internal::None, internal::None, internal::None, internal::None,
974 internal::None, internal::None, internal::None, internal::None,
975 internal::None> {
976 typedef internal::Types13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
977 T13> type;
978 };
979 template <typename T1, typename T2, typename T3, typename T4, typename T5,
980 typename T6, typename T7, typename T8, typename T9, typename T10,
981 typename T11, typename T12, typename T13, typename T14>
982 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
983 internal::None, internal::None, internal::None, internal::None,
984 internal::None, internal::None, internal::None, internal::None,
985 internal::None, internal::None, internal::None, internal::None,
986 internal::None, internal::None, internal::None, internal::None,
987 internal::None, internal::None, internal::None, internal::None,
988 internal::None, internal::None, internal::None, internal::None,
989 internal::None, internal::None, internal::None, internal::None,
990 internal::None, internal::None, internal::None, internal::None,
991 internal::None, internal::None, internal::None, internal::None> {
992 typedef internal::Types14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
993 T13, T14> type;
994 };
995 template <typename T1, typename T2, typename T3, typename T4, typename T5,
996 typename T6, typename T7, typename T8, typename T9, typename T10,
997 typename T11, typename T12, typename T13, typename T14, typename T15>
998 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
999 internal::None, internal::None, internal::None, internal::None,
1000 internal::None, internal::None, internal::None, internal::None,
1001 internal::None, internal::None, internal::None, internal::None,
1002 internal::None, internal::None, internal::None, internal::None,
1003 internal::None, internal::None, internal::None, internal::None,
1004 internal::None, internal::None, internal::None, internal::None,
1005 internal::None, internal::None, internal::None, internal::None,
1006 internal::None, internal::None, internal::None, internal::None,
1007 internal::None, internal::None, internal::None> {
1008 typedef internal::Types15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1009 T13, T14, T15> type;
1010 };
1011 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1012 typename T6, typename T7, typename T8, typename T9, typename T10,
1013 typename T11, typename T12, typename T13, typename T14, typename T15,
1014 typename T16>
1015 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1016 T16, internal::None, internal::None, internal::None, internal::None,
1017 internal::None, internal::None, internal::None, internal::None,
1018 internal::None, internal::None, internal::None, internal::None,
1019 internal::None, internal::None, internal::None, internal::None,
1020 internal::None, internal::None, internal::None, internal::None,
1021 internal::None, internal::None, internal::None, internal::None,
1022 internal::None, internal::None, internal::None, internal::None,
1023 internal::None, internal::None, internal::None, internal::None,
1024 internal::None, internal::None> {
1025 typedef internal::Types16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1026 T13, T14, T15, T16> type;
1027 };
1028 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1029 typename T6, typename T7, typename T8, typename T9, typename T10,
1030 typename T11, typename T12, typename T13, typename T14, typename T15,
1031 typename T16, typename T17>
1032 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1033 T16, T17, internal::None, internal::None, internal::None, internal::None,
1034 internal::None, internal::None, internal::None, internal::None,
1035 internal::None, internal::None, internal::None, internal::None,
1036 internal::None, internal::None, internal::None, internal::None,
1037 internal::None, internal::None, internal::None, internal::None,
1038 internal::None, internal::None, internal::None, internal::None,
1039 internal::None, internal::None, internal::None, internal::None,
1040 internal::None, internal::None, internal::None, internal::None,
1041 internal::None> {
1042 typedef internal::Types17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1043 T13, T14, T15, T16, T17> type;
1044 };
1045 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1046 typename T6, typename T7, typename T8, typename T9, typename T10,
1047 typename T11, typename T12, typename T13, typename T14, typename T15,
1048 typename T16, typename T17, typename T18>
1049 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1050 T16, T17, T18, internal::None, internal::None, internal::None,
1051 internal::None, internal::None, internal::None, internal::None,
1052 internal::None, internal::None, internal::None, internal::None,
1053 internal::None, internal::None, internal::None, internal::None,
1054 internal::None, internal::None, internal::None, internal::None,
1055 internal::None, internal::None, internal::None, internal::None,
1056 internal::None, internal::None, internal::None, internal::None,
1057 internal::None, internal::None, internal::None, internal::None,
1058 internal::None> {
1059 typedef internal::Types18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1060 T13, T14, T15, T16, T17, T18> type;
1061 };
1062 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1063 typename T6, typename T7, typename T8, typename T9, typename T10,
1064 typename T11, typename T12, typename T13, typename T14, typename T15,
1065 typename T16, typename T17, typename T18, typename T19>
1066 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1067 T16, T17, T18, T19, internal::None, internal::None, internal::None,
1068 internal::None, internal::None, internal::None, internal::None,
1069 internal::None, internal::None, internal::None, internal::None,
1070 internal::None, internal::None, internal::None, internal::None,
1071 internal::None, internal::None, internal::None, internal::None,
1072 internal::None, internal::None, internal::None, internal::None,
1073 internal::None, internal::None, internal::None, internal::None,
1074 internal::None, internal::None, internal::None, internal::None> {
1075 typedef internal::Types19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1076 T13, T14, T15, T16, T17, T18, T19> type;
1077 };
1078 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1079 typename T6, typename T7, typename T8, typename T9, typename T10,
1080 typename T11, typename T12, typename T13, typename T14, typename T15,
1081 typename T16, typename T17, typename T18, typename T19, typename T20>
1082 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1083 T16, T17, T18, T19, T20, internal::None, internal::None, internal::None,
1084 internal::None, internal::None, internal::None, internal::None,
1085 internal::None, internal::None, internal::None, internal::None,
1086 internal::None, internal::None, internal::None, internal::None,
1087 internal::None, internal::None, internal::None, internal::None,
1088 internal::None, internal::None, internal::None, internal::None,
1089 internal::None, internal::None, internal::None, internal::None,
1090 internal::None, internal::None, internal::None> {
1091 typedef internal::Types20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1092 T13, T14, T15, T16, T17, T18, T19, T20> type;
1093 };
1094 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1095 typename T6, typename T7, typename T8, typename T9, typename T10,
1096 typename T11, typename T12, typename T13, typename T14, typename T15,
1097 typename T16, typename T17, typename T18, typename T19, typename T20,
1098 typename T21>
1099 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1100 T16, T17, T18, T19, T20, T21, internal::None, internal::None,
1101 internal::None, internal::None, internal::None, internal::None,
1102 internal::None, internal::None, internal::None, internal::None,
1103 internal::None, internal::None, internal::None, internal::None,
1104 internal::None, internal::None, internal::None, internal::None,
1105 internal::None, internal::None, internal::None, internal::None,
1106 internal::None, internal::None, internal::None, internal::None,
1107 internal::None, internal::None, internal::None> {
1108 typedef internal::Types21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1109 T13, T14, T15, T16, T17, T18, T19, T20, T21> type;
1110 };
1111 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1112 typename T6, typename T7, typename T8, typename T9, typename T10,
1113 typename T11, typename T12, typename T13, typename T14, typename T15,
1114 typename T16, typename T17, typename T18, typename T19, typename T20,
1115 typename T21, typename T22>
1116 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1117 T16, T17, T18, T19, T20, T21, T22, internal::None, internal::None,
1118 internal::None, internal::None, internal::None, internal::None,
1119 internal::None, internal::None, internal::None, internal::None,
1120 internal::None, internal::None, internal::None, internal::None,
1121 internal::None, internal::None, internal::None, internal::None,
1122 internal::None, internal::None, internal::None, internal::None,
1123 internal::None, internal::None, internal::None, internal::None,
1124 internal::None, internal::None> {
1125 typedef internal::Types22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1126 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22> type;
1127 };
1128 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1129 typename T6, typename T7, typename T8, typename T9, typename T10,
1130 typename T11, typename T12, typename T13, typename T14, typename T15,
1131 typename T16, typename T17, typename T18, typename T19, typename T20,
1132 typename T21, typename T22, typename T23>
1133 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1134 T16, T17, T18, T19, T20, T21, T22, T23, internal::None, internal::None,
1135 internal::None, internal::None, internal::None, internal::None,
1136 internal::None, internal::None, internal::None, internal::None,
1137 internal::None, internal::None, internal::None, internal::None,
1138 internal::None, internal::None, internal::None, internal::None,
1139 internal::None, internal::None, internal::None, internal::None,
1140 internal::None, internal::None, internal::None, internal::None,
1141 internal::None> {
1142 typedef internal::Types23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1143 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23> type;
1144 };
1145 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1146 typename T6, typename T7, typename T8, typename T9, typename T10,
1147 typename T11, typename T12, typename T13, typename T14, typename T15,
1148 typename T16, typename T17, typename T18, typename T19, typename T20,
1149 typename T21, typename T22, typename T23, typename T24>
1150 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1151 T16, T17, T18, T19, T20, T21, T22, T23, T24, internal::None,
1152 internal::None, internal::None, internal::None, internal::None,
1153 internal::None, internal::None, internal::None, internal::None,
1154 internal::None, internal::None, internal::None, internal::None,
1155 internal::None, internal::None, internal::None, internal::None,
1156 internal::None, internal::None, internal::None, internal::None,
1157 internal::None, internal::None, internal::None, internal::None,
1158 internal::None> {
1159 typedef internal::Types24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1160 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> type;
1161 };
1162 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1163 typename T6, typename T7, typename T8, typename T9, typename T10,
1164 typename T11, typename T12, typename T13, typename T14, typename T15,
1165 typename T16, typename T17, typename T18, typename T19, typename T20,
1166 typename T21, typename T22, typename T23, typename T24, typename T25>
1167 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1168 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, internal::None,
1169 internal::None, internal::None, internal::None, internal::None,
1170 internal::None, internal::None, internal::None, internal::None,
1171 internal::None, internal::None, internal::None, internal::None,
1172 internal::None, internal::None, internal::None, internal::None,
1173 internal::None, internal::None, internal::None, internal::None,
1174 internal::None, internal::None, internal::None, internal::None> {
1175 typedef internal::Types25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1176 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> type;
1177 };
1178 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1179 typename T6, typename T7, typename T8, typename T9, typename T10,
1180 typename T11, typename T12, typename T13, typename T14, typename T15,
1181 typename T16, typename T17, typename T18, typename T19, typename T20,
1182 typename T21, typename T22, typename T23, typename T24, typename T25,
1183 typename T26>
1184 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1185 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, internal::None,
1186 internal::None, internal::None, internal::None, internal::None,
1187 internal::None, internal::None, internal::None, internal::None,
1188 internal::None, internal::None, internal::None, internal::None,
1189 internal::None, internal::None, internal::None, internal::None,
1190 internal::None, internal::None, internal::None, internal::None,
1191 internal::None, internal::None, internal::None> {
1192 typedef internal::Types26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1193 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25,
1194 T26> type;
1195 };
1196 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1197 typename T6, typename T7, typename T8, typename T9, typename T10,
1198 typename T11, typename T12, typename T13, typename T14, typename T15,
1199 typename T16, typename T17, typename T18, typename T19, typename T20,
1200 typename T21, typename T22, typename T23, typename T24, typename T25,
1201 typename T26, typename T27>
1202 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1203 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, internal::None,
1204 internal::None, internal::None, internal::None, internal::None,
1205 internal::None, internal::None, internal::None, internal::None,
1206 internal::None, internal::None, internal::None, internal::None,
1207 internal::None, internal::None, internal::None, internal::None,
1208 internal::None, internal::None, internal::None, internal::None,
1209 internal::None, internal::None> {
1210 typedef internal::Types27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1211 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1212 T27> type;
1213 };
1214 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1215 typename T6, typename T7, typename T8, typename T9, typename T10,
1216 typename T11, typename T12, typename T13, typename T14, typename T15,
1217 typename T16, typename T17, typename T18, typename T19, typename T20,
1218 typename T21, typename T22, typename T23, typename T24, typename T25,
1219 typename T26, typename T27, typename T28>
1220 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1221 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
1222 internal::None, internal::None, internal::None, internal::None,
1223 internal::None, internal::None, internal::None, internal::None,
1224 internal::None, internal::None, internal::None, internal::None,
1225 internal::None, internal::None, internal::None, internal::None,
1226 internal::None, internal::None, internal::None, internal::None,
1227 internal::None, internal::None> {
1228 typedef internal::Types28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1229 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1230 T27, T28> type;
1231 };
1232 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1233 typename T6, typename T7, typename T8, typename T9, typename T10,
1234 typename T11, typename T12, typename T13, typename T14, typename T15,
1235 typename T16, typename T17, typename T18, typename T19, typename T20,
1236 typename T21, typename T22, typename T23, typename T24, typename T25,
1237 typename T26, typename T27, typename T28, typename T29>
1238 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1239 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
1240 internal::None, internal::None, internal::None, internal::None,
1241 internal::None, internal::None, internal::None, internal::None,
1242 internal::None, internal::None, internal::None, internal::None,
1243 internal::None, internal::None, internal::None, internal::None,
1244 internal::None, internal::None, internal::None, internal::None,
1245 internal::None> {
1246 typedef internal::Types29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1247 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1248 T27, T28, T29> type;
1249 };
1250 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1251 typename T6, typename T7, typename T8, typename T9, typename T10,
1252 typename T11, typename T12, typename T13, typename T14, typename T15,
1253 typename T16, typename T17, typename T18, typename T19, typename T20,
1254 typename T21, typename T22, typename T23, typename T24, typename T25,
1255 typename T26, typename T27, typename T28, typename T29, typename T30>
1256 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1257 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1258 internal::None, internal::None, internal::None, internal::None,
1259 internal::None, internal::None, internal::None, internal::None,
1260 internal::None, internal::None, internal::None, internal::None,
1261 internal::None, internal::None, internal::None, internal::None,
1262 internal::None, internal::None, internal::None, internal::None> {
1263 typedef internal::Types30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1264 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1265 T27, T28, T29, T30> type;
1266 };
1267 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1268 typename T6, typename T7, typename T8, typename T9, typename T10,
1269 typename T11, typename T12, typename T13, typename T14, typename T15,
1270 typename T16, typename T17, typename T18, typename T19, typename T20,
1271 typename T21, typename T22, typename T23, typename T24, typename T25,
1272 typename T26, typename T27, typename T28, typename T29, typename T30,
1273 typename T31>
1274 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1275 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1276 T31, internal::None, internal::None, internal::None, internal::None,
1277 internal::None, internal::None, internal::None, internal::None,
1278 internal::None, internal::None, internal::None, internal::None,
1279 internal::None, internal::None, internal::None, internal::None,
1280 internal::None, internal::None, internal::None> {
1281 typedef internal::Types31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1282 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1283 T27, T28, T29, T30, T31> type;
1284 };
1285 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1286 typename T6, typename T7, typename T8, typename T9, typename T10,
1287 typename T11, typename T12, typename T13, typename T14, typename T15,
1288 typename T16, typename T17, typename T18, typename T19, typename T20,
1289 typename T21, typename T22, typename T23, typename T24, typename T25,
1290 typename T26, typename T27, typename T28, typename T29, typename T30,
1291 typename T31, typename T32>
1292 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1293 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1294 T31, T32, internal::None, internal::None, internal::None, internal::None,
1295 internal::None, internal::None, internal::None, internal::None,
1296 internal::None, internal::None, internal::None, internal::None,
1297 internal::None, internal::None, internal::None, internal::None,
1298 internal::None, internal::None> {
1299 typedef internal::Types32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1300 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1301 T27, T28, T29, T30, T31, T32> type;
1302 };
1303 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1304 typename T6, typename T7, typename T8, typename T9, typename T10,
1305 typename T11, typename T12, typename T13, typename T14, typename T15,
1306 typename T16, typename T17, typename T18, typename T19, typename T20,
1307 typename T21, typename T22, typename T23, typename T24, typename T25,
1308 typename T26, typename T27, typename T28, typename T29, typename T30,
1309 typename T31, typename T32, typename T33>
1310 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1311 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1312 T31, T32, T33, internal::None, internal::None, internal::None,
1313 internal::None, internal::None, internal::None, internal::None,
1314 internal::None, internal::None, internal::None, internal::None,
1315 internal::None, internal::None, internal::None, internal::None,
1316 internal::None, internal::None> {
1317 typedef internal::Types33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1318 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1319 T27, T28, T29, T30, T31, T32, T33> type;
1320 };
1321 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1322 typename T6, typename T7, typename T8, typename T9, typename T10,
1323 typename T11, typename T12, typename T13, typename T14, typename T15,
1324 typename T16, typename T17, typename T18, typename T19, typename T20,
1325 typename T21, typename T22, typename T23, typename T24, typename T25,
1326 typename T26, typename T27, typename T28, typename T29, typename T30,
1327 typename T31, typename T32, typename T33, typename T34>
1328 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1329 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1330 T31, T32, T33, T34, internal::None, internal::None, internal::None,
1331 internal::None, internal::None, internal::None, internal::None,
1332 internal::None, internal::None, internal::None, internal::None,
1333 internal::None, internal::None, internal::None, internal::None,
1334 internal::None> {
1335 typedef internal::Types34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1336 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1337 T27, T28, T29, T30, T31, T32, T33, T34> type;
1338 };
1339 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1340 typename T6, typename T7, typename T8, typename T9, typename T10,
1341 typename T11, typename T12, typename T13, typename T14, typename T15,
1342 typename T16, typename T17, typename T18, typename T19, typename T20,
1343 typename T21, typename T22, typename T23, typename T24, typename T25,
1344 typename T26, typename T27, typename T28, typename T29, typename T30,
1345 typename T31, typename T32, typename T33, typename T34, typename T35>
1346 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1347 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1348 T31, T32, T33, T34, T35, internal::None, internal::None, internal::None,
1349 internal::None, internal::None, internal::None, internal::None,
1350 internal::None, internal::None, internal::None, internal::None,
1351 internal::None, internal::None, internal::None, internal::None> {
1352 typedef internal::Types35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1353 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1354 T27, T28, T29, T30, T31, T32, T33, T34, T35> type;
1355 };
1356 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1357 typename T6, typename T7, typename T8, typename T9, typename T10,
1358 typename T11, typename T12, typename T13, typename T14, typename T15,
1359 typename T16, typename T17, typename T18, typename T19, typename T20,
1360 typename T21, typename T22, typename T23, typename T24, typename T25,
1361 typename T26, typename T27, typename T28, typename T29, typename T30,
1362 typename T31, typename T32, typename T33, typename T34, typename T35,
1363 typename T36>
1364 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1365 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1366 T31, T32, T33, T34, T35, T36, internal::None, internal::None,
1367 internal::None, internal::None, internal::None, internal::None,
1368 internal::None, internal::None, internal::None, internal::None,
1369 internal::None, internal::None, internal::None, internal::None> {
1370 typedef internal::Types36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1371 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1372 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36> type;
1373 };
1374 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1375 typename T6, typename T7, typename T8, typename T9, typename T10,
1376 typename T11, typename T12, typename T13, typename T14, typename T15,
1377 typename T16, typename T17, typename T18, typename T19, typename T20,
1378 typename T21, typename T22, typename T23, typename T24, typename T25,
1379 typename T26, typename T27, typename T28, typename T29, typename T30,
1380 typename T31, typename T32, typename T33, typename T34, typename T35,
1381 typename T36, typename T37>
1382 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1383 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1384 T31, T32, T33, T34, T35, T36, T37, internal::None, internal::None,
1385 internal::None, internal::None, internal::None, internal::None,
1386 internal::None, internal::None, internal::None, internal::None,
1387 internal::None, internal::None, internal::None> {
1388 typedef internal::Types37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1389 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1390 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37> type;
1391 };
1392 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1393 typename T6, typename T7, typename T8, typename T9, typename T10,
1394 typename T11, typename T12, typename T13, typename T14, typename T15,
1395 typename T16, typename T17, typename T18, typename T19, typename T20,
1396 typename T21, typename T22, typename T23, typename T24, typename T25,
1397 typename T26, typename T27, typename T28, typename T29, typename T30,
1398 typename T31, typename T32, typename T33, typename T34, typename T35,
1399 typename T36, typename T37, typename T38>
1400 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1401 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1402 T31, T32, T33, T34, T35, T36, T37, T38, internal::None, internal::None,
1403 internal::None, internal::None, internal::None, internal::None,
1404 internal::None, internal::None, internal::None, internal::None,
1405 internal::None, internal::None> {
1406 typedef internal::Types38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1407 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1408 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> type;
1409 };
1410 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1411 typename T6, typename T7, typename T8, typename T9, typename T10,
1412 typename T11, typename T12, typename T13, typename T14, typename T15,
1413 typename T16, typename T17, typename T18, typename T19, typename T20,
1414 typename T21, typename T22, typename T23, typename T24, typename T25,
1415 typename T26, typename T27, typename T28, typename T29, typename T30,
1416 typename T31, typename T32, typename T33, typename T34, typename T35,
1417 typename T36, typename T37, typename T38, typename T39>
1418 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1419 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1420 T31, T32, T33, T34, T35, T36, T37, T38, T39, internal::None,
1421 internal::None, internal::None, internal::None, internal::None,
1422 internal::None, internal::None, internal::None, internal::None,
1423 internal::None, internal::None> {
1424 typedef internal::Types39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1425 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1426 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> type;
1427 };
1428 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1429 typename T6, typename T7, typename T8, typename T9, typename T10,
1430 typename T11, typename T12, typename T13, typename T14, typename T15,
1431 typename T16, typename T17, typename T18, typename T19, typename T20,
1432 typename T21, typename T22, typename T23, typename T24, typename T25,
1433 typename T26, typename T27, typename T28, typename T29, typename T30,
1434 typename T31, typename T32, typename T33, typename T34, typename T35,
1435 typename T36, typename T37, typename T38, typename T39, typename T40>
1436 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1437 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1438 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, internal::None,
1439 internal::None, internal::None, internal::None, internal::None,
1440 internal::None, internal::None, internal::None, internal::None,
1441 internal::None> {
1442 typedef internal::Types40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1443 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1444 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39,
1445 T40> type;
1446 };
1447 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1448 typename T6, typename T7, typename T8, typename T9, typename T10,
1449 typename T11, typename T12, typename T13, typename T14, typename T15,
1450 typename T16, typename T17, typename T18, typename T19, typename T20,
1451 typename T21, typename T22, typename T23, typename T24, typename T25,
1452 typename T26, typename T27, typename T28, typename T29, typename T30,
1453 typename T31, typename T32, typename T33, typename T34, typename T35,
1454 typename T36, typename T37, typename T38, typename T39, typename T40,
1455 typename T41>
1456 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1457 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1458 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, internal::None,
1459 internal::None, internal::None, internal::None, internal::None,
1460 internal::None, internal::None, internal::None, internal::None> {
1461 typedef internal::Types41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1462 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1463 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
1464 T41> type;
1465 };
1466 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1467 typename T6, typename T7, typename T8, typename T9, typename T10,
1468 typename T11, typename T12, typename T13, typename T14, typename T15,
1469 typename T16, typename T17, typename T18, typename T19, typename T20,
1470 typename T21, typename T22, typename T23, typename T24, typename T25,
1471 typename T26, typename T27, typename T28, typename T29, typename T30,
1472 typename T31, typename T32, typename T33, typename T34, typename T35,
1473 typename T36, typename T37, typename T38, typename T39, typename T40,
1474 typename T41, typename T42>
1475 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1476 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1477 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, internal::None,
1478 internal::None, internal::None, internal::None, internal::None,
1479 internal::None, internal::None, internal::None> {
1480 typedef internal::Types42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1481 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1482 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
1483 T41, T42> type;
1484 };
1485 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1486 typename T6, typename T7, typename T8, typename T9, typename T10,
1487 typename T11, typename T12, typename T13, typename T14, typename T15,
1488 typename T16, typename T17, typename T18, typename T19, typename T20,
1489 typename T21, typename T22, typename T23, typename T24, typename T25,
1490 typename T26, typename T27, typename T28, typename T29, typename T30,
1491 typename T31, typename T32, typename T33, typename T34, typename T35,
1492 typename T36, typename T37, typename T38, typename T39, typename T40,
1493 typename T41, typename T42, typename T43>
1494 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1495 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1496 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
1497 internal::None, internal::None, internal::None, internal::None,
1498 internal::None, internal::None, internal::None> {
1499 typedef internal::Types43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1500 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1501 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
1502 T41, T42, T43> type;
1503 };
1504 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1505 typename T6, typename T7, typename T8, typename T9, typename T10,
1506 typename T11, typename T12, typename T13, typename T14, typename T15,
1507 typename T16, typename T17, typename T18, typename T19, typename T20,
1508 typename T21, typename T22, typename T23, typename T24, typename T25,
1509 typename T26, typename T27, typename T28, typename T29, typename T30,
1510 typename T31, typename T32, typename T33, typename T34, typename T35,
1511 typename T36, typename T37, typename T38, typename T39, typename T40,
1512 typename T41, typename T42, typename T43, typename T44>
1513 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1514 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1515 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
1516 internal::None, internal::None, internal::None, internal::None,
1517 internal::None, internal::None> {
1518 typedef internal::Types44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1519 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1520 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
1521 T41, T42, T43, T44> type;
1522 };
1523 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1524 typename T6, typename T7, typename T8, typename T9, typename T10,
1525 typename T11, typename T12, typename T13, typename T14, typename T15,
1526 typename T16, typename T17, typename T18, typename T19, typename T20,
1527 typename T21, typename T22, typename T23, typename T24, typename T25,
1528 typename T26, typename T27, typename T28, typename T29, typename T30,
1529 typename T31, typename T32, typename T33, typename T34, typename T35,
1530 typename T36, typename T37, typename T38, typename T39, typename T40,
1531 typename T41, typename T42, typename T43, typename T44, typename T45>
1532 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1533 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1534 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
1535 internal::None, internal::None, internal::None, internal::None,
1536 internal::None> {
1537 typedef internal::Types45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1538 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1539 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
1540 T41, T42, T43, T44, T45> type;
1541 };
1542 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1543 typename T6, typename T7, typename T8, typename T9, typename T10,
1544 typename T11, typename T12, typename T13, typename T14, typename T15,
1545 typename T16, typename T17, typename T18, typename T19, typename T20,
1546 typename T21, typename T22, typename T23, typename T24, typename T25,
1547 typename T26, typename T27, typename T28, typename T29, typename T30,
1548 typename T31, typename T32, typename T33, typename T34, typename T35,
1549 typename T36, typename T37, typename T38, typename T39, typename T40,
1550 typename T41, typename T42, typename T43, typename T44, typename T45,
1551 typename T46>
1552 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1553 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1554 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
1555 T46, internal::None, internal::None, internal::None, internal::None> {
1556 typedef internal::Types46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1557 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1558 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
1559 T41, T42, T43, T44, T45, T46> type;
1560 };
1561 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1562 typename T6, typename T7, typename T8, typename T9, typename T10,
1563 typename T11, typename T12, typename T13, typename T14, typename T15,
1564 typename T16, typename T17, typename T18, typename T19, typename T20,
1565 typename T21, typename T22, typename T23, typename T24, typename T25,
1566 typename T26, typename T27, typename T28, typename T29, typename T30,
1567 typename T31, typename T32, typename T33, typename T34, typename T35,
1568 typename T36, typename T37, typename T38, typename T39, typename T40,
1569 typename T41, typename T42, typename T43, typename T44, typename T45,
1570 typename T46, typename T47>
1571 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1572 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1573 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
1574 T46, T47, internal::None, internal::None, internal::None> {
1575 typedef internal::Types47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1576 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1577 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
1578 T41, T42, T43, T44, T45, T46, T47> type;
1579 };
1580 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1581 typename T6, typename T7, typename T8, typename T9, typename T10,
1582 typename T11, typename T12, typename T13, typename T14, typename T15,
1583 typename T16, typename T17, typename T18, typename T19, typename T20,
1584 typename T21, typename T22, typename T23, typename T24, typename T25,
1585 typename T26, typename T27, typename T28, typename T29, typename T30,
1586 typename T31, typename T32, typename T33, typename T34, typename T35,
1587 typename T36, typename T37, typename T38, typename T39, typename T40,
1588 typename T41, typename T42, typename T43, typename T44, typename T45,
1589 typename T46, typename T47, typename T48>
1590 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1591 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1592 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
1593 T46, T47, T48, internal::None, internal::None> {
1594 typedef internal::Types48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1595 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1596 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
1597 T41, T42, T43, T44, T45, T46, T47, T48> type;
1598 };
1599 template <typename T1, typename T2, typename T3, typename T4, typename T5,
1600 typename T6, typename T7, typename T8, typename T9, typename T10,
1601 typename T11, typename T12, typename T13, typename T14, typename T15,
1602 typename T16, typename T17, typename T18, typename T19, typename T20,
1603 typename T21, typename T22, typename T23, typename T24, typename T25,
1604 typename T26, typename T27, typename T28, typename T29, typename T30,
1605 typename T31, typename T32, typename T33, typename T34, typename T35,
1606 typename T36, typename T37, typename T38, typename T39, typename T40,
1607 typename T41, typename T42, typename T43, typename T44, typename T45,
1608 typename T46, typename T47, typename T48, typename T49>
1609 struct Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15,
1610 T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30,
1611 T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
1612 T46, T47, T48, T49, internal::None> {
1613 typedef internal::Types49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
1614 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
1615 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
1616 T41, T42, T43, T44, T45, T46, T47, T48, T49> type;
1617 };
1618
1619 namespace internal {
1620
1621 # define GTEST_TEMPLATE_ template <typename T> class
1622
1623 // The template "selector" struct TemplateSel<Tmpl> is used to
1624 // represent Tmpl, which must be a class template with one type
1625 // parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
1626 // as the type Tmpl<T>. This allows us to actually instantiate the
1627 // template "selected" by TemplateSel<Tmpl>.
1628 //
1629 // This trick is necessary for simulating typedef for class templates,
1630 // which C++ doesn't support directly.
1631 template <GTEST_TEMPLATE_ Tmpl>
1632 struct TemplateSel {
1633 template <typename T>
1634 struct Bind {
1635 typedef Tmpl<T> type;
1636 };
1637 };
1638
1639 # define GTEST_BIND_(TmplSel, T) \
1640 TmplSel::template Bind<T>::type
1641
1642 // A unique struct template used as the default value for the
1643 // arguments of class template Templates. This allows us to simulate
1644 // variadic templates (e.g. Templates<int>, Templates<int, double>,
1645 // and etc), which C++ doesn't support directly.
1646 template <typename T>
1647 struct NoneT {};
1648
1649 // The following family of struct and struct templates are used to
1650 // represent template lists. In particular, TemplatesN<T1, T2, ...,
1651 // TN> represents a list of N templates (T1, T2, ..., and TN). Except
1652 // for Templates0, every struct in the family has two member types:
1653 // Head for the selector of the first template in the list, and Tail
1654 // for the rest of the list.
1655
1656 // The empty template list.
1657 struct Templates0 {};
1658
1659 // Template lists of length 1, 2, 3, and so on.
1660
1661 template <GTEST_TEMPLATE_ T1>
1662 struct Templates1 {
1663 typedef TemplateSel<T1> Head;
1664 typedef Templates0 Tail;
1665 };
1666 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2>
1667 struct Templates2 {
1668 typedef TemplateSel<T1> Head;
1669 typedef Templates1<T2> Tail;
1670 };
1671
1672 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3>
1673 struct Templates3 {
1674 typedef TemplateSel<T1> Head;
1675 typedef Templates2<T2, T3> Tail;
1676 };
1677
1678 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1679 GTEST_TEMPLATE_ T4>
1680 struct Templates4 {
1681 typedef TemplateSel<T1> Head;
1682 typedef Templates3<T2, T3, T4> Tail;
1683 };
1684
1685 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1686 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5>
1687 struct Templates5 {
1688 typedef TemplateSel<T1> Head;
1689 typedef Templates4<T2, T3, T4, T5> Tail;
1690 };
1691
1692 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1693 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6>
1694 struct Templates6 {
1695 typedef TemplateSel<T1> Head;
1696 typedef Templates5<T2, T3, T4, T5, T6> Tail;
1697 };
1698
1699 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1700 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1701 GTEST_TEMPLATE_ T7>
1702 struct Templates7 {
1703 typedef TemplateSel<T1> Head;
1704 typedef Templates6<T2, T3, T4, T5, T6, T7> Tail;
1705 };
1706
1707 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1708 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1709 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8>
1710 struct Templates8 {
1711 typedef TemplateSel<T1> Head;
1712 typedef Templates7<T2, T3, T4, T5, T6, T7, T8> Tail;
1713 };
1714
1715 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1716 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1717 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9>
1718 struct Templates9 {
1719 typedef TemplateSel<T1> Head;
1720 typedef Templates8<T2, T3, T4, T5, T6, T7, T8, T9> Tail;
1721 };
1722
1723 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1724 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1725 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1726 GTEST_TEMPLATE_ T10>
1727 struct Templates10 {
1728 typedef TemplateSel<T1> Head;
1729 typedef Templates9<T2, T3, T4, T5, T6, T7, T8, T9, T10> Tail;
1730 };
1731
1732 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1733 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1734 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1735 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11>
1736 struct Templates11 {
1737 typedef TemplateSel<T1> Head;
1738 typedef Templates10<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> Tail;
1739 };
1740
1741 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1742 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1743 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1744 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12>
1745 struct Templates12 {
1746 typedef TemplateSel<T1> Head;
1747 typedef Templates11<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> Tail;
1748 };
1749
1750 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1751 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1752 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1753 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1754 GTEST_TEMPLATE_ T13>
1755 struct Templates13 {
1756 typedef TemplateSel<T1> Head;
1757 typedef Templates12<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> Tail;
1758 };
1759
1760 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1761 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1762 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1763 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1764 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14>
1765 struct Templates14 {
1766 typedef TemplateSel<T1> Head;
1767 typedef Templates13<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
1768 T14> Tail;
1769 };
1770
1771 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1772 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1773 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1774 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1775 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15>
1776 struct Templates15 {
1777 typedef TemplateSel<T1> Head;
1778 typedef Templates14<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1779 T15> Tail;
1780 };
1781
1782 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1783 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1784 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1785 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1786 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1787 GTEST_TEMPLATE_ T16>
1788 struct Templates16 {
1789 typedef TemplateSel<T1> Head;
1790 typedef Templates15<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1791 T15, T16> Tail;
1792 };
1793
1794 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1795 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1796 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1797 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1798 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1799 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17>
1800 struct Templates17 {
1801 typedef TemplateSel<T1> Head;
1802 typedef Templates16<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1803 T15, T16, T17> Tail;
1804 };
1805
1806 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1807 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1808 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1809 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1810 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1811 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18>
1812 struct Templates18 {
1813 typedef TemplateSel<T1> Head;
1814 typedef Templates17<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1815 T15, T16, T17, T18> Tail;
1816 };
1817
1818 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1819 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1820 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1821 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1822 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1823 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1824 GTEST_TEMPLATE_ T19>
1825 struct Templates19 {
1826 typedef TemplateSel<T1> Head;
1827 typedef Templates18<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1828 T15, T16, T17, T18, T19> Tail;
1829 };
1830
1831 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1832 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1833 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1834 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1835 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1836 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1837 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20>
1838 struct Templates20 {
1839 typedef TemplateSel<T1> Head;
1840 typedef Templates19<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1841 T15, T16, T17, T18, T19, T20> Tail;
1842 };
1843
1844 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1845 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1846 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1847 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1848 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1849 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1850 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21>
1851 struct Templates21 {
1852 typedef TemplateSel<T1> Head;
1853 typedef Templates20<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1854 T15, T16, T17, T18, T19, T20, T21> Tail;
1855 };
1856
1857 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1858 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1859 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1860 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1861 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1862 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1863 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
1864 GTEST_TEMPLATE_ T22>
1865 struct Templates22 {
1866 typedef TemplateSel<T1> Head;
1867 typedef Templates21<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1868 T15, T16, T17, T18, T19, T20, T21, T22> Tail;
1869 };
1870
1871 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1872 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1873 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1874 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1875 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1876 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1877 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
1878 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23>
1879 struct Templates23 {
1880 typedef TemplateSel<T1> Head;
1881 typedef Templates22<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1882 T15, T16, T17, T18, T19, T20, T21, T22, T23> Tail;
1883 };
1884
1885 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1886 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1887 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1888 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1889 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1890 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1891 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
1892 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24>
1893 struct Templates24 {
1894 typedef TemplateSel<T1> Head;
1895 typedef Templates23<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1896 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> Tail;
1897 };
1898
1899 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1900 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1901 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1902 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1903 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1904 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1905 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
1906 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
1907 GTEST_TEMPLATE_ T25>
1908 struct Templates25 {
1909 typedef TemplateSel<T1> Head;
1910 typedef Templates24<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1911 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> Tail;
1912 };
1913
1914 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1915 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1916 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1917 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1918 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1919 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1920 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
1921 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
1922 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26>
1923 struct Templates26 {
1924 typedef TemplateSel<T1> Head;
1925 typedef Templates25<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1926 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26> Tail;
1927 };
1928
1929 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1930 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1931 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1932 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1933 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1934 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1935 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
1936 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
1937 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27>
1938 struct Templates27 {
1939 typedef TemplateSel<T1> Head;
1940 typedef Templates26<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1941 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27> Tail;
1942 };
1943
1944 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1945 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1946 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1947 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1948 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1949 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1950 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
1951 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
1952 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
1953 GTEST_TEMPLATE_ T28>
1954 struct Templates28 {
1955 typedef TemplateSel<T1> Head;
1956 typedef Templates27<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1957 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
1958 T28> Tail;
1959 };
1960
1961 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1962 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1963 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1964 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1965 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1966 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1967 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
1968 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
1969 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
1970 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29>
1971 struct Templates29 {
1972 typedef TemplateSel<T1> Head;
1973 typedef Templates28<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1974 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
1975 T29> Tail;
1976 };
1977
1978 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1979 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1980 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1981 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1982 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
1983 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
1984 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
1985 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
1986 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
1987 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30>
1988 struct Templates30 {
1989 typedef TemplateSel<T1> Head;
1990 typedef Templates29<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
1991 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
1992 T29, T30> Tail;
1993 };
1994
1995 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
1996 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
1997 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
1998 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
1999 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2000 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2001 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2002 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2003 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2004 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2005 GTEST_TEMPLATE_ T31>
2006 struct Templates31 {
2007 typedef TemplateSel<T1> Head;
2008 typedef Templates30<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2009 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2010 T29, T30, T31> Tail;
2011 };
2012
2013 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2014 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2015 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2016 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2017 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2018 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2019 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2020 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2021 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2022 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2023 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32>
2024 struct Templates32 {
2025 typedef TemplateSel<T1> Head;
2026 typedef Templates31<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2027 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2028 T29, T30, T31, T32> Tail;
2029 };
2030
2031 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2032 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2033 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2034 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2035 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2036 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2037 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2038 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2039 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2040 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2041 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33>
2042 struct Templates33 {
2043 typedef TemplateSel<T1> Head;
2044 typedef Templates32<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2045 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2046 T29, T30, T31, T32, T33> Tail;
2047 };
2048
2049 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2050 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2051 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2052 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2053 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2054 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2055 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2056 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2057 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2058 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2059 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2060 GTEST_TEMPLATE_ T34>
2061 struct Templates34 {
2062 typedef TemplateSel<T1> Head;
2063 typedef Templates33<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2064 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2065 T29, T30, T31, T32, T33, T34> Tail;
2066 };
2067
2068 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2069 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2070 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2071 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2072 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2073 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2074 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2075 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2076 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2077 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2078 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2079 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35>
2080 struct Templates35 {
2081 typedef TemplateSel<T1> Head;
2082 typedef Templates34<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2083 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2084 T29, T30, T31, T32, T33, T34, T35> Tail;
2085 };
2086
2087 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2088 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2089 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2090 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2091 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2092 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2093 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2094 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2095 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2096 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2097 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2098 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36>
2099 struct Templates36 {
2100 typedef TemplateSel<T1> Head;
2101 typedef Templates35<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2102 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2103 T29, T30, T31, T32, T33, T34, T35, T36> Tail;
2104 };
2105
2106 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2107 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2108 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2109 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2110 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2111 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2112 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2113 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2114 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2115 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2116 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2117 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2118 GTEST_TEMPLATE_ T37>
2119 struct Templates37 {
2120 typedef TemplateSel<T1> Head;
2121 typedef Templates36<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2122 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2123 T29, T30, T31, T32, T33, T34, T35, T36, T37> Tail;
2124 };
2125
2126 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2127 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2128 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2129 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2130 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2131 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2132 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2133 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2134 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2135 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2136 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2137 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2138 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38>
2139 struct Templates38 {
2140 typedef TemplateSel<T1> Head;
2141 typedef Templates37<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2142 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2143 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> Tail;
2144 };
2145
2146 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2147 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2148 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2149 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2150 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2151 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2152 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2153 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2154 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2155 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2156 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2157 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2158 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39>
2159 struct Templates39 {
2160 typedef TemplateSel<T1> Head;
2161 typedef Templates38<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2162 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2163 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> Tail;
2164 };
2165
2166 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2167 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2168 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2169 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2170 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2171 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2172 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2173 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2174 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2175 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2176 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2177 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2178 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2179 GTEST_TEMPLATE_ T40>
2180 struct Templates40 {
2181 typedef TemplateSel<T1> Head;
2182 typedef Templates39<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2183 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2184 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> Tail;
2185 };
2186
2187 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2188 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2189 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2190 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2191 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2192 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2193 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2194 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2195 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2196 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2197 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2198 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2199 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2200 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41>
2201 struct Templates41 {
2202 typedef TemplateSel<T1> Head;
2203 typedef Templates40<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2204 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2205 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41> Tail;
2206 };
2207
2208 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2209 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2210 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2211 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2212 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2213 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2214 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2215 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2216 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2217 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2218 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2219 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2220 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2221 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42>
2222 struct Templates42 {
2223 typedef TemplateSel<T1> Head;
2224 typedef Templates41<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2225 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2226 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
2227 T42> Tail;
2228 };
2229
2230 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2231 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2232 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2233 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2234 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2235 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2236 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2237 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2238 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2239 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2240 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2241 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2242 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2243 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
2244 GTEST_TEMPLATE_ T43>
2245 struct Templates43 {
2246 typedef TemplateSel<T1> Head;
2247 typedef Templates42<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2248 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2249 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
2250 T43> Tail;
2251 };
2252
2253 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2254 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2255 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2256 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2257 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2258 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2259 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2260 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2261 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2262 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2263 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2264 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2265 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2266 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
2267 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44>
2268 struct Templates44 {
2269 typedef TemplateSel<T1> Head;
2270 typedef Templates43<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2271 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2272 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
2273 T43, T44> Tail;
2274 };
2275
2276 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2277 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2278 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2279 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2280 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2281 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2282 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2283 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2284 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2285 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2286 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2287 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2288 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2289 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
2290 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45>
2291 struct Templates45 {
2292 typedef TemplateSel<T1> Head;
2293 typedef Templates44<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2294 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2295 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
2296 T43, T44, T45> Tail;
2297 };
2298
2299 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2300 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2301 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2302 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2303 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2304 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2305 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2306 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2307 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2308 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2309 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2310 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2311 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2312 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
2313 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
2314 GTEST_TEMPLATE_ T46>
2315 struct Templates46 {
2316 typedef TemplateSel<T1> Head;
2317 typedef Templates45<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2318 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2319 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
2320 T43, T44, T45, T46> Tail;
2321 };
2322
2323 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2324 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2325 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2326 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2327 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2328 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2329 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2330 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2331 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2332 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2333 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2334 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2335 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2336 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
2337 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
2338 GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47>
2339 struct Templates47 {
2340 typedef TemplateSel<T1> Head;
2341 typedef Templates46<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2342 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2343 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
2344 T43, T44, T45, T46, T47> Tail;
2345 };
2346
2347 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2348 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2349 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2350 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2351 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2352 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2353 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2354 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2355 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2356 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2357 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2358 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2359 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2360 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
2361 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
2362 GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48>
2363 struct Templates48 {
2364 typedef TemplateSel<T1> Head;
2365 typedef Templates47<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2366 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2367 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
2368 T43, T44, T45, T46, T47, T48> Tail;
2369 };
2370
2371 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2372 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2373 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2374 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2375 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2376 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2377 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2378 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2379 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2380 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2381 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2382 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2383 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2384 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
2385 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
2386 GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48,
2387 GTEST_TEMPLATE_ T49>
2388 struct Templates49 {
2389 typedef TemplateSel<T1> Head;
2390 typedef Templates48<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2391 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2392 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
2393 T43, T44, T45, T46, T47, T48, T49> Tail;
2394 };
2395
2396 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2397 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2398 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2399 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2400 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2401 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2402 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2403 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2404 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2405 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2406 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2407 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
2408 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
2409 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
2410 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
2411 GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48,
2412 GTEST_TEMPLATE_ T49, GTEST_TEMPLATE_ T50>
2413 struct Templates50 {
2414 typedef TemplateSel<T1> Head;
2415 typedef Templates49<T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2416 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2417 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42,
2418 T43, T44, T45, T46, T47, T48, T49, T50> Tail;
2419 };
2420
2421
2422 // We don't want to require the users to write TemplatesN<...> directly,
2423 // as that would require them to count the length. Templates<...> is much
2424 // easier to write, but generates horrible messages when there is a
2425 // compiler error, as gcc insists on printing out each template
2426 // argument, even if it has the default value (this means Templates<list>
2427 // will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
2428 // errors).
2429 //
2430 // Our solution is to combine the best part of the two approaches: a
2431 // user would write Templates<T1, ..., TN>, and Google Test will translate
2432 // that to TemplatesN<T1, ..., TN> internally to make error messages
2433 // readable. The translation is done by the 'type' member of the
2434 // Templates template.
2435 template <GTEST_TEMPLATE_ T1 = NoneT, GTEST_TEMPLATE_ T2 = NoneT,
2436 GTEST_TEMPLATE_ T3 = NoneT, GTEST_TEMPLATE_ T4 = NoneT,
2437 GTEST_TEMPLATE_ T5 = NoneT, GTEST_TEMPLATE_ T6 = NoneT,
2438 GTEST_TEMPLATE_ T7 = NoneT, GTEST_TEMPLATE_ T8 = NoneT,
2439 GTEST_TEMPLATE_ T9 = NoneT, GTEST_TEMPLATE_ T10 = NoneT,
2440 GTEST_TEMPLATE_ T11 = NoneT, GTEST_TEMPLATE_ T12 = NoneT,
2441 GTEST_TEMPLATE_ T13 = NoneT, GTEST_TEMPLATE_ T14 = NoneT,
2442 GTEST_TEMPLATE_ T15 = NoneT, GTEST_TEMPLATE_ T16 = NoneT,
2443 GTEST_TEMPLATE_ T17 = NoneT, GTEST_TEMPLATE_ T18 = NoneT,
2444 GTEST_TEMPLATE_ T19 = NoneT, GTEST_TEMPLATE_ T20 = NoneT,
2445 GTEST_TEMPLATE_ T21 = NoneT, GTEST_TEMPLATE_ T22 = NoneT,
2446 GTEST_TEMPLATE_ T23 = NoneT, GTEST_TEMPLATE_ T24 = NoneT,
2447 GTEST_TEMPLATE_ T25 = NoneT, GTEST_TEMPLATE_ T26 = NoneT,
2448 GTEST_TEMPLATE_ T27 = NoneT, GTEST_TEMPLATE_ T28 = NoneT,
2449 GTEST_TEMPLATE_ T29 = NoneT, GTEST_TEMPLATE_ T30 = NoneT,
2450 GTEST_TEMPLATE_ T31 = NoneT, GTEST_TEMPLATE_ T32 = NoneT,
2451 GTEST_TEMPLATE_ T33 = NoneT, GTEST_TEMPLATE_ T34 = NoneT,
2452 GTEST_TEMPLATE_ T35 = NoneT, GTEST_TEMPLATE_ T36 = NoneT,
2453 GTEST_TEMPLATE_ T37 = NoneT, GTEST_TEMPLATE_ T38 = NoneT,
2454 GTEST_TEMPLATE_ T39 = NoneT, GTEST_TEMPLATE_ T40 = NoneT,
2455 GTEST_TEMPLATE_ T41 = NoneT, GTEST_TEMPLATE_ T42 = NoneT,
2456 GTEST_TEMPLATE_ T43 = NoneT, GTEST_TEMPLATE_ T44 = NoneT,
2457 GTEST_TEMPLATE_ T45 = NoneT, GTEST_TEMPLATE_ T46 = NoneT,
2458 GTEST_TEMPLATE_ T47 = NoneT, GTEST_TEMPLATE_ T48 = NoneT,
2459 GTEST_TEMPLATE_ T49 = NoneT, GTEST_TEMPLATE_ T50 = NoneT>
2460 struct Templates {
2461 typedef Templates50<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2462 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
2463 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
2464 T42, T43, T44, T45, T46, T47, T48, T49, T50> type;
2465 };
2466
2467 template <>
2468 struct Templates<NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2469 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2470 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2471 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2472 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2473 NoneT> {
2474 typedef Templates0 type;
2475 };
2476 template <GTEST_TEMPLATE_ T1>
2477 struct Templates<T1, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2478 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2479 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2480 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2481 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2482 NoneT> {
2483 typedef Templates1<T1> type;
2484 };
2485 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2>
2486 struct Templates<T1, T2, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2487 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2488 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2489 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2490 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2491 NoneT> {
2492 typedef Templates2<T1, T2> type;
2493 };
2494 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3>
2495 struct Templates<T1, T2, T3, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2496 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2497 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2498 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2499 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2500 typedef Templates3<T1, T2, T3> type;
2501 };
2502 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2503 GTEST_TEMPLATE_ T4>
2504 struct Templates<T1, T2, T3, T4, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2505 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2506 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2507 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2508 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2509 typedef Templates4<T1, T2, T3, T4> type;
2510 };
2511 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2512 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5>
2513 struct Templates<T1, T2, T3, T4, T5, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2514 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2515 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2516 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2517 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2518 typedef Templates5<T1, T2, T3, T4, T5> type;
2519 };
2520 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2521 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6>
2522 struct Templates<T1, T2, T3, T4, T5, T6, NoneT, NoneT, NoneT, NoneT, NoneT,
2523 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2524 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2525 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2526 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2527 typedef Templates6<T1, T2, T3, T4, T5, T6> type;
2528 };
2529 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2530 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2531 GTEST_TEMPLATE_ T7>
2532 struct Templates<T1, T2, T3, T4, T5, T6, T7, NoneT, NoneT, NoneT, NoneT, NoneT,
2533 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2534 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2535 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2536 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2537 typedef Templates7<T1, T2, T3, T4, T5, T6, T7> type;
2538 };
2539 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2540 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2541 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8>
2542 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, NoneT, NoneT, NoneT, NoneT,
2543 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2544 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2545 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2546 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2547 typedef Templates8<T1, T2, T3, T4, T5, T6, T7, T8> type;
2548 };
2549 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2550 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2551 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9>
2552 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, NoneT, NoneT, NoneT,
2553 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2554 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2555 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2556 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2557 typedef Templates9<T1, T2, T3, T4, T5, T6, T7, T8, T9> type;
2558 };
2559 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2560 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2561 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2562 GTEST_TEMPLATE_ T10>
2563 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, NoneT, NoneT, NoneT,
2564 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2565 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2566 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2567 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2568 typedef Templates10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> type;
2569 };
2570 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2571 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2572 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2573 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11>
2574 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, NoneT, NoneT,
2575 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2576 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2577 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2578 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2579 typedef Templates11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> type;
2580 };
2581 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2582 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2583 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2584 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12>
2585 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, NoneT,
2586 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2587 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2588 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2589 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2590 typedef Templates12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> type;
2591 };
2592 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2593 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2594 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2595 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2596 GTEST_TEMPLATE_ T13>
2597 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, NoneT,
2598 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2599 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2600 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2601 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2602 typedef Templates13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
2603 T13> type;
2604 };
2605 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2606 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2607 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2608 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2609 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14>
2610 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2611 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2612 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2613 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2614 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2615 typedef Templates14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2616 T14> type;
2617 };
2618 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2619 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2620 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2621 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2622 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15>
2623 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2624 T15, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2625 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2626 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2627 NoneT, NoneT, NoneT, NoneT, NoneT> {
2628 typedef Templates15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2629 T14, T15> type;
2630 };
2631 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2632 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2633 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2634 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2635 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2636 GTEST_TEMPLATE_ T16>
2637 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2638 T15, T16, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2639 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2640 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2641 NoneT, NoneT, NoneT, NoneT, NoneT> {
2642 typedef Templates16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2643 T14, T15, T16> type;
2644 };
2645 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2646 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2647 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2648 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2649 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2650 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17>
2651 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2652 T15, T16, T17, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2653 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2654 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2655 NoneT, NoneT, NoneT, NoneT, NoneT> {
2656 typedef Templates17<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2657 T14, T15, T16, T17> type;
2658 };
2659 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2660 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2661 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2662 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2663 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2664 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18>
2665 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2666 T15, T16, T17, T18, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2667 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2668 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2669 NoneT, NoneT, NoneT, NoneT> {
2670 typedef Templates18<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2671 T14, T15, T16, T17, T18> type;
2672 };
2673 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2674 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2675 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2676 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2677 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2678 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2679 GTEST_TEMPLATE_ T19>
2680 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2681 T15, T16, T17, T18, T19, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2682 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2683 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2684 NoneT, NoneT, NoneT, NoneT> {
2685 typedef Templates19<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2686 T14, T15, T16, T17, T18, T19> type;
2687 };
2688 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2689 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2690 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2691 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2692 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2693 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2694 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20>
2695 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2696 T15, T16, T17, T18, T19, T20, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2697 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2698 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2699 NoneT, NoneT, NoneT, NoneT> {
2700 typedef Templates20<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2701 T14, T15, T16, T17, T18, T19, T20> type;
2702 };
2703 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2704 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2705 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2706 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2707 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2708 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2709 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21>
2710 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2711 T15, T16, T17, T18, T19, T20, T21, NoneT, NoneT, NoneT, NoneT, NoneT,
2712 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2713 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2714 NoneT, NoneT, NoneT, NoneT> {
2715 typedef Templates21<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2716 T14, T15, T16, T17, T18, T19, T20, T21> type;
2717 };
2718 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2719 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2720 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2721 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2722 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2723 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2724 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2725 GTEST_TEMPLATE_ T22>
2726 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2727 T15, T16, T17, T18, T19, T20, T21, T22, NoneT, NoneT, NoneT, NoneT, NoneT,
2728 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2729 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2730 NoneT, NoneT, NoneT> {
2731 typedef Templates22<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2732 T14, T15, T16, T17, T18, T19, T20, T21, T22> type;
2733 };
2734 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2735 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2736 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2737 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2738 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2739 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2740 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2741 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23>
2742 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2743 T15, T16, T17, T18, T19, T20, T21, T22, T23, NoneT, NoneT, NoneT, NoneT,
2744 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2745 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2746 NoneT, NoneT, NoneT> {
2747 typedef Templates23<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2748 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23> type;
2749 };
2750 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2751 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2752 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2753 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2754 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2755 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2756 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2757 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24>
2758 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2759 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, NoneT, NoneT, NoneT,
2760 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2761 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2762 NoneT, NoneT, NoneT> {
2763 typedef Templates24<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2764 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> type;
2765 };
2766 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2767 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2768 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2769 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2770 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2771 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2772 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2773 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2774 GTEST_TEMPLATE_ T25>
2775 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2776 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, NoneT, NoneT, NoneT,
2777 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2778 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2779 NoneT, NoneT> {
2780 typedef Templates25<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2781 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25> type;
2782 };
2783 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2784 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2785 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2786 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2787 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2788 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2789 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2790 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2791 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26>
2792 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2793 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, NoneT, NoneT,
2794 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2795 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2796 NoneT, NoneT> {
2797 typedef Templates26<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2798 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26> type;
2799 };
2800 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2801 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2802 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2803 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2804 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2805 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2806 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2807 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2808 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27>
2809 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2810 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, NoneT,
2811 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2812 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2813 NoneT, NoneT> {
2814 typedef Templates27<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2815 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
2816 T27> type;
2817 };
2818 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2819 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2820 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2821 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2822 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2823 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2824 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2825 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2826 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2827 GTEST_TEMPLATE_ T28>
2828 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2829 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
2830 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2831 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2832 NoneT, NoneT> {
2833 typedef Templates28<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2834 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
2835 T28> type;
2836 };
2837 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2838 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2839 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2840 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2841 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2842 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2843 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2844 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2845 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2846 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29>
2847 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2848 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
2849 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2850 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2851 NoneT> {
2852 typedef Templates29<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2853 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
2854 T28, T29> type;
2855 };
2856 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2857 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2858 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2859 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2860 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2861 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2862 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2863 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2864 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2865 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30>
2866 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2867 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
2868 T30, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2869 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2870 typedef Templates30<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2871 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
2872 T28, T29, T30> type;
2873 };
2874 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2875 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2876 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2877 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2878 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2879 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2880 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2881 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2882 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2883 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2884 GTEST_TEMPLATE_ T31>
2885 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2886 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
2887 T30, T31, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2888 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2889 typedef Templates31<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2890 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
2891 T28, T29, T30, T31> type;
2892 };
2893 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2894 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2895 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2896 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2897 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2898 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2899 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2900 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2901 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2902 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2903 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32>
2904 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2905 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
2906 T30, T31, T32, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2907 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2908 typedef Templates32<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2909 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
2910 T28, T29, T30, T31, T32> type;
2911 };
2912 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2913 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2914 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2915 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2916 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2917 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2918 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2919 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2920 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2921 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2922 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33>
2923 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2924 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
2925 T30, T31, T32, T33, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2926 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2927 typedef Templates33<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2928 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
2929 T28, T29, T30, T31, T32, T33> type;
2930 };
2931 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2932 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2933 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2934 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2935 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2936 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2937 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2938 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2939 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2940 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2941 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2942 GTEST_TEMPLATE_ T34>
2943 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2944 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
2945 T30, T31, T32, T33, T34, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2946 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2947 typedef Templates34<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2948 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
2949 T28, T29, T30, T31, T32, T33, T34> type;
2950 };
2951 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2952 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2953 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2954 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2955 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2956 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2957 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2958 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2959 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2960 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2961 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2962 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35>
2963 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2964 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
2965 T30, T31, T32, T33, T34, T35, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT,
2966 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2967 typedef Templates35<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2968 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
2969 T28, T29, T30, T31, T32, T33, T34, T35> type;
2970 };
2971 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2972 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2973 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2974 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2975 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2976 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2977 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2978 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2979 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
2980 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
2981 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
2982 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36>
2983 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
2984 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
2985 T30, T31, T32, T33, T34, T35, T36, NoneT, NoneT, NoneT, NoneT, NoneT,
2986 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
2987 typedef Templates36<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
2988 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
2989 T28, T29, T30, T31, T32, T33, T34, T35, T36> type;
2990 };
2991 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
2992 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
2993 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
2994 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
2995 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
2996 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
2997 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
2998 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
2999 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3000 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3001 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3002 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3003 GTEST_TEMPLATE_ T37>
3004 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3005 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3006 T30, T31, T32, T33, T34, T35, T36, T37, NoneT, NoneT, NoneT, NoneT, NoneT,
3007 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
3008 typedef Templates37<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3009 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3010 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37> type;
3011 };
3012 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3013 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3014 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3015 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3016 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3017 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3018 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3019 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3020 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3021 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3022 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3023 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3024 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38>
3025 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3026 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3027 T30, T31, T32, T33, T34, T35, T36, T37, T38, NoneT, NoneT, NoneT, NoneT,
3028 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
3029 typedef Templates38<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3030 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3031 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38> type;
3032 };
3033 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3034 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3035 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3036 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3037 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3038 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3039 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3040 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3041 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3042 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3043 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3044 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3045 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39>
3046 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3047 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3048 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, NoneT, NoneT, NoneT,
3049 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
3050 typedef Templates39<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3051 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3052 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39> type;
3053 };
3054 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3055 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3056 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3057 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3058 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3059 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3060 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3061 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3062 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3063 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3064 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3065 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3066 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
3067 GTEST_TEMPLATE_ T40>
3068 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3069 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3070 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, NoneT, NoneT, NoneT,
3071 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
3072 typedef Templates40<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3073 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3074 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40> type;
3075 };
3076 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3077 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3078 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3079 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3080 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3081 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3082 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3083 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3084 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3085 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3086 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3087 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3088 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
3089 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41>
3090 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3091 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3092 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, NoneT, NoneT,
3093 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
3094 typedef Templates41<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3095 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3096 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
3097 T41> type;
3098 };
3099 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3100 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3101 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3102 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3103 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3104 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3105 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3106 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3107 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3108 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3109 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3110 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3111 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
3112 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42>
3113 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3114 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3115 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, NoneT,
3116 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
3117 typedef Templates42<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3118 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3119 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
3120 T42> type;
3121 };
3122 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3123 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3124 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3125 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3126 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3127 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3128 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3129 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3130 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3131 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3132 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3133 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3134 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
3135 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
3136 GTEST_TEMPLATE_ T43>
3137 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3138 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3139 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
3140 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
3141 typedef Templates43<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3142 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3143 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
3144 T42, T43> type;
3145 };
3146 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3147 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3148 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3149 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3150 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3151 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3152 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3153 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3154 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3155 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3156 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3157 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3158 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
3159 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
3160 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44>
3161 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3162 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3163 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
3164 NoneT, NoneT, NoneT, NoneT, NoneT, NoneT> {
3165 typedef Templates44<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3166 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3167 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
3168 T42, T43, T44> type;
3169 };
3170 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3171 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3172 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3173 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3174 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3175 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3176 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3177 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3178 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3179 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3180 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3181 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3182 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
3183 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
3184 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45>
3185 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3186 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3187 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
3188 T45, NoneT, NoneT, NoneT, NoneT, NoneT> {
3189 typedef Templates45<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3190 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3191 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
3192 T42, T43, T44, T45> type;
3193 };
3194 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3195 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3196 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3197 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3198 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3199 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3200 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3201 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3202 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3203 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3204 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3205 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3206 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
3207 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
3208 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
3209 GTEST_TEMPLATE_ T46>
3210 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3211 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3212 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
3213 T45, T46, NoneT, NoneT, NoneT, NoneT> {
3214 typedef Templates46<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3215 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3216 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
3217 T42, T43, T44, T45, T46> type;
3218 };
3219 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3220 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3221 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3222 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3223 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3224 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3225 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3226 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3227 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3228 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3229 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3230 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3231 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
3232 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
3233 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
3234 GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47>
3235 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3236 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3237 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
3238 T45, T46, T47, NoneT, NoneT, NoneT> {
3239 typedef Templates47<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3240 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3241 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
3242 T42, T43, T44, T45, T46, T47> type;
3243 };
3244 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3245 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3246 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3247 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3248 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3249 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3250 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3251 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3252 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3253 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3254 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3255 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3256 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
3257 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
3258 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
3259 GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48>
3260 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3261 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3262 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
3263 T45, T46, T47, T48, NoneT, NoneT> {
3264 typedef Templates48<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3265 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3266 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
3267 T42, T43, T44, T45, T46, T47, T48> type;
3268 };
3269 template <GTEST_TEMPLATE_ T1, GTEST_TEMPLATE_ T2, GTEST_TEMPLATE_ T3,
3270 GTEST_TEMPLATE_ T4, GTEST_TEMPLATE_ T5, GTEST_TEMPLATE_ T6,
3271 GTEST_TEMPLATE_ T7, GTEST_TEMPLATE_ T8, GTEST_TEMPLATE_ T9,
3272 GTEST_TEMPLATE_ T10, GTEST_TEMPLATE_ T11, GTEST_TEMPLATE_ T12,
3273 GTEST_TEMPLATE_ T13, GTEST_TEMPLATE_ T14, GTEST_TEMPLATE_ T15,
3274 GTEST_TEMPLATE_ T16, GTEST_TEMPLATE_ T17, GTEST_TEMPLATE_ T18,
3275 GTEST_TEMPLATE_ T19, GTEST_TEMPLATE_ T20, GTEST_TEMPLATE_ T21,
3276 GTEST_TEMPLATE_ T22, GTEST_TEMPLATE_ T23, GTEST_TEMPLATE_ T24,
3277 GTEST_TEMPLATE_ T25, GTEST_TEMPLATE_ T26, GTEST_TEMPLATE_ T27,
3278 GTEST_TEMPLATE_ T28, GTEST_TEMPLATE_ T29, GTEST_TEMPLATE_ T30,
3279 GTEST_TEMPLATE_ T31, GTEST_TEMPLATE_ T32, GTEST_TEMPLATE_ T33,
3280 GTEST_TEMPLATE_ T34, GTEST_TEMPLATE_ T35, GTEST_TEMPLATE_ T36,
3281 GTEST_TEMPLATE_ T37, GTEST_TEMPLATE_ T38, GTEST_TEMPLATE_ T39,
3282 GTEST_TEMPLATE_ T40, GTEST_TEMPLATE_ T41, GTEST_TEMPLATE_ T42,
3283 GTEST_TEMPLATE_ T43, GTEST_TEMPLATE_ T44, GTEST_TEMPLATE_ T45,
3284 GTEST_TEMPLATE_ T46, GTEST_TEMPLATE_ T47, GTEST_TEMPLATE_ T48,
3285 GTEST_TEMPLATE_ T49>
3286 struct Templates<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14,
3287 T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29,
3288 T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44,
3289 T45, T46, T47, T48, T49, NoneT> {
3290 typedef Templates49<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3291 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27,
3292 T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41,
3293 T42, T43, T44, T45, T46, T47, T48, T49> type;
3294 };
3295
3296 // The TypeList template makes it possible to use either a single type
3297 // or a Types<...> list in TYPED_TEST_CASE() and
3298 // INSTANTIATE_TYPED_TEST_CASE_P().
3299
3300 template <typename T>
3301 struct TypeList {
3302 typedef Types1<T> type;
3303 };
3304
3305 template <typename T1, typename T2, typename T3, typename T4, typename T5,
3306 typename T6, typename T7, typename T8, typename T9, typename T10,
3307 typename T11, typename T12, typename T13, typename T14, typename T15,
3308 typename T16, typename T17, typename T18, typename T19, typename T20,
3309 typename T21, typename T22, typename T23, typename T24, typename T25,
3310 typename T26, typename T27, typename T28, typename T29, typename T30,
3311 typename T31, typename T32, typename T33, typename T34, typename T35,
3312 typename T36, typename T37, typename T38, typename T39, typename T40,
3313 typename T41, typename T42, typename T43, typename T44, typename T45,
3314 typename T46, typename T47, typename T48, typename T49, typename T50>
3315 struct TypeList<Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13,
3316 T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28,
3317 T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43,
3318 T44, T45, T46, T47, T48, T49, T50> > {
3319 typedef typename Types<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
3320 T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26,
3321 T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40,
3322 T41, T42, T43, T44, T45, T46, T47, T48, T49, T50>::type type;
3323 };
3324
3325 #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
3326
3327 } // namespace internal
3328 } // namespace testing
3329
3330 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
0 $$ -*- mode: c++; -*-
1 $var n = 50 $$ Maximum length of type lists we want to support.
2 // Copyright 2008 Google Inc.
3 // All Rights Reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 //
31 // Author: wan@google.com (Zhanyong Wan)
32
33 // Type utilities needed for implementing typed and type-parameterized
34 // tests. This file is generated by a SCRIPT. DO NOT EDIT BY HAND!
35 //
36 // Currently we support at most $n types in a list, and at most $n
37 // type-parameterized tests in one type-parameterized test case.
38 // Please contact googletestframework@googlegroups.com if you need
39 // more.
40
41 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
42 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
43
44 #include "gtest/internal/gtest-port.h"
45
46 // #ifdef __GNUC__ is too general here. It is possible to use gcc without using
47 // libstdc++ (which is where cxxabi.h comes from).
48 # if GTEST_HAS_CXXABI_H_
49 # include <cxxabi.h>
50 # elif defined(__HP_aCC)
51 # include <acxx_demangle.h>
52 # endif // GTEST_HASH_CXXABI_H_
53
54 namespace testing {
55 namespace internal {
56
57 // GetTypeName<T>() returns a human-readable name of type T.
58 // NB: This function is also used in Google Mock, so don't move it inside of
59 // the typed-test-only section below.
60 template <typename T>
61 std::string GetTypeName() {
62 # if GTEST_HAS_RTTI
63
64 const char* const name = typeid(T).name();
65 # if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC)
66 int status = 0;
67 // gcc's implementation of typeid(T).name() mangles the type name,
68 // so we have to demangle it.
69 # if GTEST_HAS_CXXABI_H_
70 using abi::__cxa_demangle;
71 # endif // GTEST_HAS_CXXABI_H_
72 char* const readable_name = __cxa_demangle(name, 0, 0, &status);
73 const std::string name_str(status == 0 ? readable_name : name);
74 free(readable_name);
75 return name_str;
76 # else
77 return name;
78 # endif // GTEST_HAS_CXXABI_H_ || __HP_aCC
79
80 # else
81
82 return "<type>";
83
84 # endif // GTEST_HAS_RTTI
85 }
86
87 #if GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
88
89 // AssertyTypeEq<T1, T2>::type is defined iff T1 and T2 are the same
90 // type. This can be used as a compile-time assertion to ensure that
91 // two types are equal.
92
93 template <typename T1, typename T2>
94 struct AssertTypeEq;
95
96 template <typename T>
97 struct AssertTypeEq<T, T> {
98 typedef bool type;
99 };
100
101 // A unique type used as the default value for the arguments of class
102 // template Types. This allows us to simulate variadic templates
103 // (e.g. Types<int>, Type<int, double>, and etc), which C++ doesn't
104 // support directly.
105 struct None {};
106
107 // The following family of struct and struct templates are used to
108 // represent type lists. In particular, TypesN<T1, T2, ..., TN>
109 // represents a type list with N types (T1, T2, ..., and TN) in it.
110 // Except for Types0, every struct in the family has two member types:
111 // Head for the first type in the list, and Tail for the rest of the
112 // list.
113
114 // The empty type list.
115 struct Types0 {};
116
117 // Type lists of length 1, 2, 3, and so on.
118
119 template <typename T1>
120 struct Types1 {
121 typedef T1 Head;
122 typedef Types0 Tail;
123 };
124
125 $range i 2..n
126
127 $for i [[
128 $range j 1..i
129 $range k 2..i
130 template <$for j, [[typename T$j]]>
131 struct Types$i {
132 typedef T1 Head;
133 typedef Types$(i-1)<$for k, [[T$k]]> Tail;
134 };
135
136
137 ]]
138
139 } // namespace internal
140
141 // We don't want to require the users to write TypesN<...> directly,
142 // as that would require them to count the length. Types<...> is much
143 // easier to write, but generates horrible messages when there is a
144 // compiler error, as gcc insists on printing out each template
145 // argument, even if it has the default value (this means Types<int>
146 // will appear as Types<int, None, None, ..., None> in the compiler
147 // errors).
148 //
149 // Our solution is to combine the best part of the two approaches: a
150 // user would write Types<T1, ..., TN>, and Google Test will translate
151 // that to TypesN<T1, ..., TN> internally to make error messages
152 // readable. The translation is done by the 'type' member of the
153 // Types template.
154
155 $range i 1..n
156 template <$for i, [[typename T$i = internal::None]]>
157 struct Types {
158 typedef internal::Types$n<$for i, [[T$i]]> type;
159 };
160
161 template <>
162 struct Types<$for i, [[internal::None]]> {
163 typedef internal::Types0 type;
164 };
165
166 $range i 1..n-1
167 $for i [[
168 $range j 1..i
169 $range k i+1..n
170 template <$for j, [[typename T$j]]>
171 struct Types<$for j, [[T$j]]$for k[[, internal::None]]> {
172 typedef internal::Types$i<$for j, [[T$j]]> type;
173 };
174
175 ]]
176
177 namespace internal {
178
179 # define GTEST_TEMPLATE_ template <typename T> class
180
181 // The template "selector" struct TemplateSel<Tmpl> is used to
182 // represent Tmpl, which must be a class template with one type
183 // parameter, as a type. TemplateSel<Tmpl>::Bind<T>::type is defined
184 // as the type Tmpl<T>. This allows us to actually instantiate the
185 // template "selected" by TemplateSel<Tmpl>.
186 //
187 // This trick is necessary for simulating typedef for class templates,
188 // which C++ doesn't support directly.
189 template <GTEST_TEMPLATE_ Tmpl>
190 struct TemplateSel {
191 template <typename T>
192 struct Bind {
193 typedef Tmpl<T> type;
194 };
195 };
196
197 # define GTEST_BIND_(TmplSel, T) \
198 TmplSel::template Bind<T>::type
199
200 // A unique struct template used as the default value for the
201 // arguments of class template Templates. This allows us to simulate
202 // variadic templates (e.g. Templates<int>, Templates<int, double>,
203 // and etc), which C++ doesn't support directly.
204 template <typename T>
205 struct NoneT {};
206
207 // The following family of struct and struct templates are used to
208 // represent template lists. In particular, TemplatesN<T1, T2, ...,
209 // TN> represents a list of N templates (T1, T2, ..., and TN). Except
210 // for Templates0, every struct in the family has two member types:
211 // Head for the selector of the first template in the list, and Tail
212 // for the rest of the list.
213
214 // The empty template list.
215 struct Templates0 {};
216
217 // Template lists of length 1, 2, 3, and so on.
218
219 template <GTEST_TEMPLATE_ T1>
220 struct Templates1 {
221 typedef TemplateSel<T1> Head;
222 typedef Templates0 Tail;
223 };
224
225 $range i 2..n
226
227 $for i [[
228 $range j 1..i
229 $range k 2..i
230 template <$for j, [[GTEST_TEMPLATE_ T$j]]>
231 struct Templates$i {
232 typedef TemplateSel<T1> Head;
233 typedef Templates$(i-1)<$for k, [[T$k]]> Tail;
234 };
235
236
237 ]]
238
239 // We don't want to require the users to write TemplatesN<...> directly,
240 // as that would require them to count the length. Templates<...> is much
241 // easier to write, but generates horrible messages when there is a
242 // compiler error, as gcc insists on printing out each template
243 // argument, even if it has the default value (this means Templates<list>
244 // will appear as Templates<list, NoneT, NoneT, ..., NoneT> in the compiler
245 // errors).
246 //
247 // Our solution is to combine the best part of the two approaches: a
248 // user would write Templates<T1, ..., TN>, and Google Test will translate
249 // that to TemplatesN<T1, ..., TN> internally to make error messages
250 // readable. The translation is done by the 'type' member of the
251 // Templates template.
252
253 $range i 1..n
254 template <$for i, [[GTEST_TEMPLATE_ T$i = NoneT]]>
255 struct Templates {
256 typedef Templates$n<$for i, [[T$i]]> type;
257 };
258
259 template <>
260 struct Templates<$for i, [[NoneT]]> {
261 typedef Templates0 type;
262 };
263
264 $range i 1..n-1
265 $for i [[
266 $range j 1..i
267 $range k i+1..n
268 template <$for j, [[GTEST_TEMPLATE_ T$j]]>
269 struct Templates<$for j, [[T$j]]$for k[[, NoneT]]> {
270 typedef Templates$i<$for j, [[T$j]]> type;
271 };
272
273 ]]
274
275 // The TypeList template makes it possible to use either a single type
276 // or a Types<...> list in TYPED_TEST_CASE() and
277 // INSTANTIATE_TYPED_TEST_CASE_P().
278
279 template <typename T>
280 struct TypeList {
281 typedef Types1<T> type;
282 };
283
284
285 $range i 1..n
286 template <$for i, [[typename T$i]]>
287 struct TypeList<Types<$for i, [[T$i]]> > {
288 typedef typename Types<$for i, [[T$i]]>::type type;
289 };
290
291 #endif // GTEST_HAS_TYPED_TEST || GTEST_HAS_TYPED_TEST_P
292
293 } // namespace internal
294 } // namespace testing
295
296 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_
0 // Copyright 2008, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: mheule@google.com (Markus Heule)
30 //
31 // Google C++ Testing Framework (Google Test)
32 //
33 // Sometimes it's desirable to build Google Test by compiling a single file.
34 // This file serves this purpose.
35
36 // This line ensures that gtest.h can be compiled on its own, even
37 // when it's fused.
38 #include "gtest/gtest.h"
39
40 // The following lines pull in the real gtest *.cc files.
41 #include "src/gtest.cc"
42 #include "src/gtest-death-test.cc"
43 #include "src/gtest-filepath.cc"
44 #include "src/gtest-port.cc"
45 #include "src/gtest-printers.cc"
46 #include "src/gtest-test-part.cc"
47 #include "src/gtest-typed-test.cc"
0 // Copyright 2005, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan), vladl@google.com (Vlad Losev)
30 //
31 // This file implements death tests.
32
33 #include "gtest/gtest-death-test.h"
34 #include "gtest/internal/gtest-port.h"
35
36 #if GTEST_HAS_DEATH_TEST
37
38 # if GTEST_OS_MAC
39 # include <crt_externs.h>
40 # endif // GTEST_OS_MAC
41
42 # include <errno.h>
43 # include <fcntl.h>
44 # include <limits.h>
45
46 # if GTEST_OS_LINUX
47 # include <signal.h>
48 # endif // GTEST_OS_LINUX
49
50 # include <stdarg.h>
51
52 # if GTEST_OS_WINDOWS
53 # include <windows.h>
54 # else
55 # include <sys/mman.h>
56 # include <sys/wait.h>
57 # endif // GTEST_OS_WINDOWS
58
59 # if GTEST_OS_QNX
60 # include <spawn.h>
61 # endif // GTEST_OS_QNX
62
63 #endif // GTEST_HAS_DEATH_TEST
64
65 #include "gtest/gtest-message.h"
66 #include "gtest/internal/gtest-string.h"
67
68 // Indicates that this translation unit is part of Google Test's
69 // implementation. It must come before gtest-internal-inl.h is
70 // included, or there will be a compiler error. This trick is to
71 // prevent a user from accidentally including gtest-internal-inl.h in
72 // his code.
73 #define GTEST_IMPLEMENTATION_ 1
74 #include "src/gtest-internal-inl.h"
75 #undef GTEST_IMPLEMENTATION_
76
77 namespace testing {
78
79 // Constants.
80
81 // The default death test style.
82 static const char kDefaultDeathTestStyle[] = "fast";
83
84 GTEST_DEFINE_string_(
85 death_test_style,
86 internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle),
87 "Indicates how to run a death test in a forked child process: "
88 "\"threadsafe\" (child process re-executes the test binary "
89 "from the beginning, running only the specific death test) or "
90 "\"fast\" (child process runs the death test immediately "
91 "after forking).");
92
93 GTEST_DEFINE_bool_(
94 death_test_use_fork,
95 internal::BoolFromGTestEnv("death_test_use_fork", false),
96 "Instructs to use fork()/_exit() instead of clone() in death tests. "
97 "Ignored and always uses fork() on POSIX systems where clone() is not "
98 "implemented. Useful when running under valgrind or similar tools if "
99 "those do not support clone(). Valgrind 3.3.1 will just fail if "
100 "it sees an unsupported combination of clone() flags. "
101 "It is not recommended to use this flag w/o valgrind though it will "
102 "work in 99% of the cases. Once valgrind is fixed, this flag will "
103 "most likely be removed.");
104
105 namespace internal {
106 GTEST_DEFINE_string_(
107 internal_run_death_test, "",
108 "Indicates the file, line number, temporal index of "
109 "the single death test to run, and a file descriptor to "
110 "which a success code may be sent, all separated by "
111 "the '|' characters. This flag is specified if and only if the current "
112 "process is a sub-process launched for running a thread-safe "
113 "death test. FOR INTERNAL USE ONLY.");
114 } // namespace internal
115
116 #if GTEST_HAS_DEATH_TEST
117
118 namespace internal {
119
120 // Valid only for fast death tests. Indicates the code is running in the
121 // child process of a fast style death test.
122 static bool g_in_fast_death_test_child = false;
123
124 // Returns a Boolean value indicating whether the caller is currently
125 // executing in the context of the death test child process. Tools such as
126 // Valgrind heap checkers may need this to modify their behavior in death
127 // tests. IMPORTANT: This is an internal utility. Using it may break the
128 // implementation of death tests. User code MUST NOT use it.
129 bool InDeathTestChild() {
130 # if GTEST_OS_WINDOWS
131
132 // On Windows, death tests are thread-safe regardless of the value of the
133 // death_test_style flag.
134 return !GTEST_FLAG(internal_run_death_test).empty();
135
136 # else
137
138 if (GTEST_FLAG(death_test_style) == "threadsafe")
139 return !GTEST_FLAG(internal_run_death_test).empty();
140 else
141 return g_in_fast_death_test_child;
142 #endif
143 }
144
145 } // namespace internal
146
147 // ExitedWithCode constructor.
148 ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {
149 }
150
151 // ExitedWithCode function-call operator.
152 bool ExitedWithCode::operator()(int exit_status) const {
153 # if GTEST_OS_WINDOWS
154
155 return exit_status == exit_code_;
156
157 # else
158
159 return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_;
160
161 # endif // GTEST_OS_WINDOWS
162 }
163
164 # if !GTEST_OS_WINDOWS
165 // KilledBySignal constructor.
166 KilledBySignal::KilledBySignal(int signum) : signum_(signum) {
167 }
168
169 // KilledBySignal function-call operator.
170 bool KilledBySignal::operator()(int exit_status) const {
171 return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_;
172 }
173 # endif // !GTEST_OS_WINDOWS
174
175 namespace internal {
176
177 // Utilities needed for death tests.
178
179 // Generates a textual description of a given exit code, in the format
180 // specified by wait(2).
181 static std::string ExitSummary(int exit_code) {
182 Message m;
183
184 # if GTEST_OS_WINDOWS
185
186 m << "Exited with exit status " << exit_code;
187
188 # else
189
190 if (WIFEXITED(exit_code)) {
191 m << "Exited with exit status " << WEXITSTATUS(exit_code);
192 } else if (WIFSIGNALED(exit_code)) {
193 m << "Terminated by signal " << WTERMSIG(exit_code);
194 }
195 # ifdef WCOREDUMP
196 if (WCOREDUMP(exit_code)) {
197 m << " (core dumped)";
198 }
199 # endif
200 # endif // GTEST_OS_WINDOWS
201
202 return m.GetString();
203 }
204
205 // Returns true if exit_status describes a process that was terminated
206 // by a signal, or exited normally with a nonzero exit code.
207 bool ExitedUnsuccessfully(int exit_status) {
208 return !ExitedWithCode(0)(exit_status);
209 }
210
211 # if !GTEST_OS_WINDOWS
212 // Generates a textual failure message when a death test finds more than
213 // one thread running, or cannot determine the number of threads, prior
214 // to executing the given statement. It is the responsibility of the
215 // caller not to pass a thread_count of 1.
216 static std::string DeathTestThreadWarning(size_t thread_count) {
217 Message msg;
218 msg << "Death tests use fork(), which is unsafe particularly"
219 << " in a threaded context. For this test, " << GTEST_NAME_ << " ";
220 if (thread_count == 0)
221 msg << "couldn't detect the number of threads.";
222 else
223 msg << "detected " << thread_count << " threads.";
224 return msg.GetString();
225 }
226 # endif // !GTEST_OS_WINDOWS
227
228 // Flag characters for reporting a death test that did not die.
229 static const char kDeathTestLived = 'L';
230 static const char kDeathTestReturned = 'R';
231 static const char kDeathTestThrew = 'T';
232 static const char kDeathTestInternalError = 'I';
233
234 // An enumeration describing all of the possible ways that a death test can
235 // conclude. DIED means that the process died while executing the test
236 // code; LIVED means that process lived beyond the end of the test code;
237 // RETURNED means that the test statement attempted to execute a return
238 // statement, which is not allowed; THREW means that the test statement
239 // returned control by throwing an exception. IN_PROGRESS means the test
240 // has not yet concluded.
241 // TODO(vladl@google.com): Unify names and possibly values for
242 // AbortReason, DeathTestOutcome, and flag characters above.
243 enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
244
245 // Routine for aborting the program which is safe to call from an
246 // exec-style death test child process, in which case the error
247 // message is propagated back to the parent process. Otherwise, the
248 // message is simply printed to stderr. In either case, the program
249 // then exits with status 1.
250 void DeathTestAbort(const std::string& message) {
251 // On a POSIX system, this function may be called from a threadsafe-style
252 // death test child process, which operates on a very small stack. Use
253 // the heap for any additional non-minuscule memory requirements.
254 const InternalRunDeathTestFlag* const flag =
255 GetUnitTestImpl()->internal_run_death_test_flag();
256 if (flag != NULL) {
257 FILE* parent = posix::FDOpen(flag->write_fd(), "w");
258 fputc(kDeathTestInternalError, parent);
259 fprintf(parent, "%s", message.c_str());
260 fflush(parent);
261 _exit(1);
262 } else {
263 fprintf(stderr, "%s", message.c_str());
264 fflush(stderr);
265 posix::Abort();
266 }
267 }
268
269 // A replacement for CHECK that calls DeathTestAbort if the assertion
270 // fails.
271 # define GTEST_DEATH_TEST_CHECK_(expression) \
272 do { \
273 if (!::testing::internal::IsTrue(expression)) { \
274 DeathTestAbort( \
275 ::std::string("CHECK failed: File ") + __FILE__ + ", line " \
276 + ::testing::internal::StreamableToString(__LINE__) + ": " \
277 + #expression); \
278 } \
279 } while (::testing::internal::AlwaysFalse())
280
281 // This macro is similar to GTEST_DEATH_TEST_CHECK_, but it is meant for
282 // evaluating any system call that fulfills two conditions: it must return
283 // -1 on failure, and set errno to EINTR when it is interrupted and
284 // should be tried again. The macro expands to a loop that repeatedly
285 // evaluates the expression as long as it evaluates to -1 and sets
286 // errno to EINTR. If the expression evaluates to -1 but errno is
287 // something other than EINTR, DeathTestAbort is called.
288 # define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \
289 do { \
290 int gtest_retval; \
291 do { \
292 gtest_retval = (expression); \
293 } while (gtest_retval == -1 && errno == EINTR); \
294 if (gtest_retval == -1) { \
295 DeathTestAbort( \
296 ::std::string("CHECK failed: File ") + __FILE__ + ", line " \
297 + ::testing::internal::StreamableToString(__LINE__) + ": " \
298 + #expression + " != -1"); \
299 } \
300 } while (::testing::internal::AlwaysFalse())
301
302 // Returns the message describing the last system error in errno.
303 std::string GetLastErrnoDescription() {
304 return errno == 0 ? "" : posix::StrError(errno);
305 }
306
307 // This is called from a death test parent process to read a failure
308 // message from the death test child process and log it with the FATAL
309 // severity. On Windows, the message is read from a pipe handle. On other
310 // platforms, it is read from a file descriptor.
311 static void FailFromInternalError(int fd) {
312 Message error;
313 char buffer[256];
314 int num_read;
315
316 do {
317 while ((num_read = posix::Read(fd, buffer, 255)) > 0) {
318 buffer[num_read] = '\0';
319 error << buffer;
320 }
321 } while (num_read == -1 && errno == EINTR);
322
323 if (num_read == 0) {
324 GTEST_LOG_(FATAL) << error.GetString();
325 } else {
326 const int last_error = errno;
327 GTEST_LOG_(FATAL) << "Error while reading death test internal: "
328 << GetLastErrnoDescription() << " [" << last_error << "]";
329 }
330 }
331
332 // Death test constructor. Increments the running death test count
333 // for the current test.
334 DeathTest::DeathTest() {
335 TestInfo* const info = GetUnitTestImpl()->current_test_info();
336 if (info == NULL) {
337 DeathTestAbort("Cannot run a death test outside of a TEST or "
338 "TEST_F construct");
339 }
340 }
341
342 // Creates and returns a death test by dispatching to the current
343 // death test factory.
344 bool DeathTest::Create(const char* statement, const RE* regex,
345 const char* file, int line, DeathTest** test) {
346 return GetUnitTestImpl()->death_test_factory()->Create(
347 statement, regex, file, line, test);
348 }
349
350 const char* DeathTest::LastMessage() {
351 return last_death_test_message_.c_str();
352 }
353
354 void DeathTest::set_last_death_test_message(const std::string& message) {
355 last_death_test_message_ = message;
356 }
357
358 std::string DeathTest::last_death_test_message_;
359
360 // Provides cross platform implementation for some death functionality.
361 class DeathTestImpl : public DeathTest {
362 protected:
363 DeathTestImpl(const char* a_statement, const RE* a_regex)
364 : statement_(a_statement),
365 regex_(a_regex),
366 spawned_(false),
367 status_(-1),
368 outcome_(IN_PROGRESS),
369 read_fd_(-1),
370 write_fd_(-1) {}
371
372 // read_fd_ is expected to be closed and cleared by a derived class.
373 ~DeathTestImpl() { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }
374
375 void Abort(AbortReason reason);
376 virtual bool Passed(bool status_ok);
377
378 const char* statement() const { return statement_; }
379 const RE* regex() const { return regex_; }
380 bool spawned() const { return spawned_; }
381 void set_spawned(bool is_spawned) { spawned_ = is_spawned; }
382 int status() const { return status_; }
383 void set_status(int a_status) { status_ = a_status; }
384 DeathTestOutcome outcome() const { return outcome_; }
385 void set_outcome(DeathTestOutcome an_outcome) { outcome_ = an_outcome; }
386 int read_fd() const { return read_fd_; }
387 void set_read_fd(int fd) { read_fd_ = fd; }
388 int write_fd() const { return write_fd_; }
389 void set_write_fd(int fd) { write_fd_ = fd; }
390
391 // Called in the parent process only. Reads the result code of the death
392 // test child process via a pipe, interprets it to set the outcome_
393 // member, and closes read_fd_. Outputs diagnostics and terminates in
394 // case of unexpected codes.
395 void ReadAndInterpretStatusByte();
396
397 private:
398 // The textual content of the code this object is testing. This class
399 // doesn't own this string and should not attempt to delete it.
400 const char* const statement_;
401 // The regular expression which test output must match. DeathTestImpl
402 // doesn't own this object and should not attempt to delete it.
403 const RE* const regex_;
404 // True if the death test child process has been successfully spawned.
405 bool spawned_;
406 // The exit status of the child process.
407 int status_;
408 // How the death test concluded.
409 DeathTestOutcome outcome_;
410 // Descriptor to the read end of the pipe to the child process. It is
411 // always -1 in the child process. The child keeps its write end of the
412 // pipe in write_fd_.
413 int read_fd_;
414 // Descriptor to the child's write end of the pipe to the parent process.
415 // It is always -1 in the parent process. The parent keeps its end of the
416 // pipe in read_fd_.
417 int write_fd_;
418 };
419
420 // Called in the parent process only. Reads the result code of the death
421 // test child process via a pipe, interprets it to set the outcome_
422 // member, and closes read_fd_. Outputs diagnostics and terminates in
423 // case of unexpected codes.
424 void DeathTestImpl::ReadAndInterpretStatusByte() {
425 char flag;
426 int bytes_read;
427
428 // The read() here blocks until data is available (signifying the
429 // failure of the death test) or until the pipe is closed (signifying
430 // its success), so it's okay to call this in the parent before
431 // the child process has exited.
432 do {
433 bytes_read = posix::Read(read_fd(), &flag, 1);
434 } while (bytes_read == -1 && errno == EINTR);
435
436 if (bytes_read == 0) {
437 set_outcome(DIED);
438 } else if (bytes_read == 1) {
439 switch (flag) {
440 case kDeathTestReturned:
441 set_outcome(RETURNED);
442 break;
443 case kDeathTestThrew:
444 set_outcome(THREW);
445 break;
446 case kDeathTestLived:
447 set_outcome(LIVED);
448 break;
449 case kDeathTestInternalError:
450 FailFromInternalError(read_fd()); // Does not return.
451 break;
452 default:
453 GTEST_LOG_(FATAL) << "Death test child process reported "
454 << "unexpected status byte ("
455 << static_cast<unsigned int>(flag) << ")";
456 }
457 } else {
458 GTEST_LOG_(FATAL) << "Read from death test child process failed: "
459 << GetLastErrnoDescription();
460 }
461 GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Close(read_fd()));
462 set_read_fd(-1);
463 }
464
465 // Signals that the death test code which should have exited, didn't.
466 // Should be called only in a death test child process.
467 // Writes a status byte to the child's status file descriptor, then
468 // calls _exit(1).
469 void DeathTestImpl::Abort(AbortReason reason) {
470 // The parent process considers the death test to be a failure if
471 // it finds any data in our pipe. So, here we write a single flag byte
472 // to the pipe, then exit.
473 const char status_ch =
474 reason == TEST_DID_NOT_DIE ? kDeathTestLived :
475 reason == TEST_THREW_EXCEPTION ? kDeathTestThrew : kDeathTestReturned;
476
477 GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Write(write_fd(), &status_ch, 1));
478 // We are leaking the descriptor here because on some platforms (i.e.,
479 // when built as Windows DLL), destructors of global objects will still
480 // run after calling _exit(). On such systems, write_fd_ will be
481 // indirectly closed from the destructor of UnitTestImpl, causing double
482 // close if it is also closed here. On debug configurations, double close
483 // may assert. As there are no in-process buffers to flush here, we are
484 // relying on the OS to close the descriptor after the process terminates
485 // when the destructors are not run.
486 _exit(1); // Exits w/o any normal exit hooks (we were supposed to crash)
487 }
488
489 // Returns an indented copy of stderr output for a death test.
490 // This makes distinguishing death test output lines from regular log lines
491 // much easier.
492 static ::std::string FormatDeathTestOutput(const ::std::string& output) {
493 ::std::string ret;
494 for (size_t at = 0; ; ) {
495 const size_t line_end = output.find('\n', at);
496 ret += "[ DEATH ] ";
497 if (line_end == ::std::string::npos) {
498 ret += output.substr(at);
499 break;
500 }
501 ret += output.substr(at, line_end + 1 - at);
502 at = line_end + 1;
503 }
504 return ret;
505 }
506
507 // Assesses the success or failure of a death test, using both private
508 // members which have previously been set, and one argument:
509 //
510 // Private data members:
511 // outcome: An enumeration describing how the death test
512 // concluded: DIED, LIVED, THREW, or RETURNED. The death test
513 // fails in the latter three cases.
514 // status: The exit status of the child process. On *nix, it is in the
515 // in the format specified by wait(2). On Windows, this is the
516 // value supplied to the ExitProcess() API or a numeric code
517 // of the exception that terminated the program.
518 // regex: A regular expression object to be applied to
519 // the test's captured standard error output; the death test
520 // fails if it does not match.
521 //
522 // Argument:
523 // status_ok: true if exit_status is acceptable in the context of
524 // this particular death test, which fails if it is false
525 //
526 // Returns true iff all of the above conditions are met. Otherwise, the
527 // first failing condition, in the order given above, is the one that is
528 // reported. Also sets the last death test message string.
529 bool DeathTestImpl::Passed(bool status_ok) {
530 if (!spawned())
531 return false;
532
533 const std::string error_message = GetCapturedStderr();
534
535 bool success = false;
536 Message buffer;
537
538 buffer << "Death test: " << statement() << "\n";
539 switch (outcome()) {
540 case LIVED:
541 buffer << " Result: failed to die.\n"
542 << " Error msg:\n" << FormatDeathTestOutput(error_message);
543 break;
544 case THREW:
545 buffer << " Result: threw an exception.\n"
546 << " Error msg:\n" << FormatDeathTestOutput(error_message);
547 break;
548 case RETURNED:
549 buffer << " Result: illegal return in test statement.\n"
550 << " Error msg:\n" << FormatDeathTestOutput(error_message);
551 break;
552 case DIED:
553 if (status_ok) {
554 const bool matched = RE::PartialMatch(error_message.c_str(), *regex());
555 if (matched) {
556 success = true;
557 } else {
558 buffer << " Result: died but not with expected error.\n"
559 << " Expected: " << regex()->pattern() << "\n"
560 << "Actual msg:\n" << FormatDeathTestOutput(error_message);
561 }
562 } else {
563 buffer << " Result: died but not with expected exit code:\n"
564 << " " << ExitSummary(status()) << "\n"
565 << "Actual msg:\n" << FormatDeathTestOutput(error_message);
566 }
567 break;
568 case IN_PROGRESS:
569 default:
570 GTEST_LOG_(FATAL)
571 << "DeathTest::Passed somehow called before conclusion of test";
572 }
573
574 DeathTest::set_last_death_test_message(buffer.GetString());
575 return success;
576 }
577
578 # if GTEST_OS_WINDOWS
579 // WindowsDeathTest implements death tests on Windows. Due to the
580 // specifics of starting new processes on Windows, death tests there are
581 // always threadsafe, and Google Test considers the
582 // --gtest_death_test_style=fast setting to be equivalent to
583 // --gtest_death_test_style=threadsafe there.
584 //
585 // A few implementation notes: Like the Linux version, the Windows
586 // implementation uses pipes for child-to-parent communication. But due to
587 // the specifics of pipes on Windows, some extra steps are required:
588 //
589 // 1. The parent creates a communication pipe and stores handles to both
590 // ends of it.
591 // 2. The parent starts the child and provides it with the information
592 // necessary to acquire the handle to the write end of the pipe.
593 // 3. The child acquires the write end of the pipe and signals the parent
594 // using a Windows event.
595 // 4. Now the parent can release the write end of the pipe on its side. If
596 // this is done before step 3, the object's reference count goes down to
597 // 0 and it is destroyed, preventing the child from acquiring it. The
598 // parent now has to release it, or read operations on the read end of
599 // the pipe will not return when the child terminates.
600 // 5. The parent reads child's output through the pipe (outcome code and
601 // any possible error messages) from the pipe, and its stderr and then
602 // determines whether to fail the test.
603 //
604 // Note: to distinguish Win32 API calls from the local method and function
605 // calls, the former are explicitly resolved in the global namespace.
606 //
607 class WindowsDeathTest : public DeathTestImpl {
608 public:
609 WindowsDeathTest(const char* a_statement,
610 const RE* a_regex,
611 const char* file,
612 int line)
613 : DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {}
614
615 // All of these virtual functions are inherited from DeathTest.
616 virtual int Wait();
617 virtual TestRole AssumeRole();
618
619 private:
620 // The name of the file in which the death test is located.
621 const char* const file_;
622 // The line number on which the death test is located.
623 const int line_;
624 // Handle to the write end of the pipe to the child process.
625 AutoHandle write_handle_;
626 // Child process handle.
627 AutoHandle child_handle_;
628 // Event the child process uses to signal the parent that it has
629 // acquired the handle to the write end of the pipe. After seeing this
630 // event the parent can release its own handles to make sure its
631 // ReadFile() calls return when the child terminates.
632 AutoHandle event_handle_;
633 };
634
635 // Waits for the child in a death test to exit, returning its exit
636 // status, or 0 if no child process exists. As a side effect, sets the
637 // outcome data member.
638 int WindowsDeathTest::Wait() {
639 if (!spawned())
640 return 0;
641
642 // Wait until the child either signals that it has acquired the write end
643 // of the pipe or it dies.
644 const HANDLE wait_handles[2] = { child_handle_.Get(), event_handle_.Get() };
645 switch (::WaitForMultipleObjects(2,
646 wait_handles,
647 FALSE, // Waits for any of the handles.
648 INFINITE)) {
649 case WAIT_OBJECT_0:
650 case WAIT_OBJECT_0 + 1:
651 break;
652 default:
653 GTEST_DEATH_TEST_CHECK_(false); // Should not get here.
654 }
655
656 // The child has acquired the write end of the pipe or exited.
657 // We release the handle on our side and continue.
658 write_handle_.Reset();
659 event_handle_.Reset();
660
661 ReadAndInterpretStatusByte();
662
663 // Waits for the child process to exit if it haven't already. This
664 // returns immediately if the child has already exited, regardless of
665 // whether previous calls to WaitForMultipleObjects synchronized on this
666 // handle or not.
667 GTEST_DEATH_TEST_CHECK_(
668 WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(),
669 INFINITE));
670 DWORD status_code;
671 GTEST_DEATH_TEST_CHECK_(
672 ::GetExitCodeProcess(child_handle_.Get(), &status_code) != FALSE);
673 child_handle_.Reset();
674 set_status(static_cast<int>(status_code));
675 return status();
676 }
677
678 // The AssumeRole process for a Windows death test. It creates a child
679 // process with the same executable as the current process to run the
680 // death test. The child process is given the --gtest_filter and
681 // --gtest_internal_run_death_test flags such that it knows to run the
682 // current death test only.
683 DeathTest::TestRole WindowsDeathTest::AssumeRole() {
684 const UnitTestImpl* const impl = GetUnitTestImpl();
685 const InternalRunDeathTestFlag* const flag =
686 impl->internal_run_death_test_flag();
687 const TestInfo* const info = impl->current_test_info();
688 const int death_test_index = info->result()->death_test_count();
689
690 if (flag != NULL) {
691 // ParseInternalRunDeathTestFlag() has performed all the necessary
692 // processing.
693 set_write_fd(flag->write_fd());
694 return EXECUTE_TEST;
695 }
696
697 // WindowsDeathTest uses an anonymous pipe to communicate results of
698 // a death test.
699 SECURITY_ATTRIBUTES handles_are_inheritable = {
700 sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
701 HANDLE read_handle, write_handle;
702 GTEST_DEATH_TEST_CHECK_(
703 ::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable,
704 0) // Default buffer size.
705 != FALSE);
706 set_read_fd(::_open_osfhandle(reinterpret_cast<intptr_t>(read_handle),
707 O_RDONLY));
708 write_handle_.Reset(write_handle);
709 event_handle_.Reset(::CreateEvent(
710 &handles_are_inheritable,
711 TRUE, // The event will automatically reset to non-signaled state.
712 FALSE, // The initial state is non-signalled.
713 NULL)); // The even is unnamed.
714 GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL);
715 const std::string filter_flag =
716 std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "=" +
717 info->test_case_name() + "." + info->name();
718 const std::string internal_flag =
719 std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag +
720 "=" + file_ + "|" + StreamableToString(line_) + "|" +
721 StreamableToString(death_test_index) + "|" +
722 StreamableToString(static_cast<unsigned int>(::GetCurrentProcessId())) +
723 // size_t has the same width as pointers on both 32-bit and 64-bit
724 // Windows platforms.
725 // See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.
726 "|" + StreamableToString(reinterpret_cast<size_t>(write_handle)) +
727 "|" + StreamableToString(reinterpret_cast<size_t>(event_handle_.Get()));
728
729 char executable_path[_MAX_PATH + 1]; // NOLINT
730 GTEST_DEATH_TEST_CHECK_(
731 _MAX_PATH + 1 != ::GetModuleFileNameA(NULL,
732 executable_path,
733 _MAX_PATH));
734
735 std::string command_line =
736 std::string(::GetCommandLineA()) + " " + filter_flag + " \"" +
737 internal_flag + "\"";
738
739 DeathTest::set_last_death_test_message("");
740
741 CaptureStderr();
742 // Flush the log buffers since the log streams are shared with the child.
743 FlushInfoLog();
744
745 // The child process will share the standard handles with the parent.
746 STARTUPINFOA startup_info;
747 memset(&startup_info, 0, sizeof(STARTUPINFO));
748 startup_info.dwFlags = STARTF_USESTDHANDLES;
749 startup_info.hStdInput = ::GetStdHandle(STD_INPUT_HANDLE);
750 startup_info.hStdOutput = ::GetStdHandle(STD_OUTPUT_HANDLE);
751 startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE);
752
753 PROCESS_INFORMATION process_info;
754 GTEST_DEATH_TEST_CHECK_(::CreateProcessA(
755 executable_path,
756 const_cast<char*>(command_line.c_str()),
757 NULL, // Retuned process handle is not inheritable.
758 NULL, // Retuned thread handle is not inheritable.
759 TRUE, // Child inherits all inheritable handles (for write_handle_).
760 0x0, // Default creation flags.
761 NULL, // Inherit the parent's environment.
762 UnitTest::GetInstance()->original_working_dir(),
763 &startup_info,
764 &process_info) != FALSE);
765 child_handle_.Reset(process_info.hProcess);
766 ::CloseHandle(process_info.hThread);
767 set_spawned(true);
768 return OVERSEE_TEST;
769 }
770 # else // We are not on Windows.
771
772 // ForkingDeathTest provides implementations for most of the abstract
773 // methods of the DeathTest interface. Only the AssumeRole method is
774 // left undefined.
775 class ForkingDeathTest : public DeathTestImpl {
776 public:
777 ForkingDeathTest(const char* statement, const RE* regex);
778
779 // All of these virtual functions are inherited from DeathTest.
780 virtual int Wait();
781
782 protected:
783 void set_child_pid(pid_t child_pid) { child_pid_ = child_pid; }
784
785 private:
786 // PID of child process during death test; 0 in the child process itself.
787 pid_t child_pid_;
788 };
789
790 // Constructs a ForkingDeathTest.
791 ForkingDeathTest::ForkingDeathTest(const char* a_statement, const RE* a_regex)
792 : DeathTestImpl(a_statement, a_regex),
793 child_pid_(-1) {}
794
795 // Waits for the child in a death test to exit, returning its exit
796 // status, or 0 if no child process exists. As a side effect, sets the
797 // outcome data member.
798 int ForkingDeathTest::Wait() {
799 if (!spawned())
800 return 0;
801
802 ReadAndInterpretStatusByte();
803
804 int status_value;
805 GTEST_DEATH_TEST_CHECK_SYSCALL_(waitpid(child_pid_, &status_value, 0));
806 set_status(status_value);
807 return status_value;
808 }
809
810 // A concrete death test class that forks, then immediately runs the test
811 // in the child process.
812 class NoExecDeathTest : public ForkingDeathTest {
813 public:
814 NoExecDeathTest(const char* a_statement, const RE* a_regex) :
815 ForkingDeathTest(a_statement, a_regex) { }
816 virtual TestRole AssumeRole();
817 };
818
819 // The AssumeRole process for a fork-and-run death test. It implements a
820 // straightforward fork, with a simple pipe to transmit the status byte.
821 DeathTest::TestRole NoExecDeathTest::AssumeRole() {
822 const size_t thread_count = GetThreadCount();
823 if (thread_count != 1) {
824 GTEST_LOG_(WARNING) << DeathTestThreadWarning(thread_count);
825 }
826
827 int pipe_fd[2];
828 GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
829
830 DeathTest::set_last_death_test_message("");
831 CaptureStderr();
832 // When we fork the process below, the log file buffers are copied, but the
833 // file descriptors are shared. We flush all log files here so that closing
834 // the file descriptors in the child process doesn't throw off the
835 // synchronization between descriptors and buffers in the parent process.
836 // This is as close to the fork as possible to avoid a race condition in case
837 // there are multiple threads running before the death test, and another
838 // thread writes to the log file.
839 FlushInfoLog();
840
841 const pid_t child_pid = fork();
842 GTEST_DEATH_TEST_CHECK_(child_pid != -1);
843 set_child_pid(child_pid);
844 if (child_pid == 0) {
845 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[0]));
846 set_write_fd(pipe_fd[1]);
847 // Redirects all logging to stderr in the child process to prevent
848 // concurrent writes to the log files. We capture stderr in the parent
849 // process and append the child process' output to a log.
850 LogToStderr();
851 // Event forwarding to the listeners of event listener API mush be shut
852 // down in death test subprocesses.
853 GetUnitTestImpl()->listeners()->SuppressEventForwarding();
854 g_in_fast_death_test_child = true;
855 return EXECUTE_TEST;
856 } else {
857 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
858 set_read_fd(pipe_fd[0]);
859 set_spawned(true);
860 return OVERSEE_TEST;
861 }
862 }
863
864 // A concrete death test class that forks and re-executes the main
865 // program from the beginning, with command-line flags set that cause
866 // only this specific death test to be run.
867 class ExecDeathTest : public ForkingDeathTest {
868 public:
869 ExecDeathTest(const char* a_statement, const RE* a_regex,
870 const char* file, int line) :
871 ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { }
872 virtual TestRole AssumeRole();
873 private:
874 static ::std::vector<testing::internal::string>
875 GetArgvsForDeathTestChildProcess() {
876 ::std::vector<testing::internal::string> args = GetInjectableArgvs();
877 return args;
878 }
879 // The name of the file in which the death test is located.
880 const char* const file_;
881 // The line number on which the death test is located.
882 const int line_;
883 };
884
885 // Utility class for accumulating command-line arguments.
886 class Arguments {
887 public:
888 Arguments() {
889 args_.push_back(NULL);
890 }
891
892 ~Arguments() {
893 for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
894 ++i) {
895 free(*i);
896 }
897 }
898 void AddArgument(const char* argument) {
899 args_.insert(args_.end() - 1, posix::StrDup(argument));
900 }
901
902 template <typename Str>
903 void AddArguments(const ::std::vector<Str>& arguments) {
904 for (typename ::std::vector<Str>::const_iterator i = arguments.begin();
905 i != arguments.end();
906 ++i) {
907 args_.insert(args_.end() - 1, posix::StrDup(i->c_str()));
908 }
909 }
910 char* const* Argv() {
911 return &args_[0];
912 }
913
914 private:
915 std::vector<char*> args_;
916 };
917
918 // A struct that encompasses the arguments to the child process of a
919 // threadsafe-style death test process.
920 struct ExecDeathTestArgs {
921 char* const* argv; // Command-line arguments for the child's call to exec
922 int close_fd; // File descriptor to close; the read end of a pipe
923 };
924
925 # if GTEST_OS_MAC
926 inline char** GetEnviron() {
927 // When Google Test is built as a framework on MacOS X, the environ variable
928 // is unavailable. Apple's documentation (man environ) recommends using
929 // _NSGetEnviron() instead.
930 return *_NSGetEnviron();
931 }
932 # else
933 // Some POSIX platforms expect you to declare environ. extern "C" makes
934 // it reside in the global namespace.
935 extern "C" char** environ;
936 inline char** GetEnviron() { return environ; }
937 # endif // GTEST_OS_MAC
938
939 # if !GTEST_OS_QNX
940 // The main function for a threadsafe-style death test child process.
941 // This function is called in a clone()-ed process and thus must avoid
942 // any potentially unsafe operations like malloc or libc functions.
943 static int ExecDeathTestChildMain(void* child_arg) {
944 ExecDeathTestArgs* const args = static_cast<ExecDeathTestArgs*>(child_arg);
945 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd));
946
947 // We need to execute the test program in the same environment where
948 // it was originally invoked. Therefore we change to the original
949 // working directory first.
950 const char* const original_dir =
951 UnitTest::GetInstance()->original_working_dir();
952 // We can safely call chdir() as it's a direct system call.
953 if (chdir(original_dir) != 0) {
954 DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " +
955 GetLastErrnoDescription());
956 return EXIT_FAILURE;
957 }
958
959 // We can safely call execve() as it's a direct system call. We
960 // cannot use execvp() as it's a libc function and thus potentially
961 // unsafe. Since execve() doesn't search the PATH, the user must
962 // invoke the test program via a valid path that contains at least
963 // one path separator.
964 execve(args->argv[0], args->argv, GetEnviron());
965 DeathTestAbort(std::string("execve(") + args->argv[0] + ", ...) in " +
966 original_dir + " failed: " +
967 GetLastErrnoDescription());
968 return EXIT_FAILURE;
969 }
970 # endif // !GTEST_OS_QNX
971
972 // Two utility routines that together determine the direction the stack
973 // grows.
974 // This could be accomplished more elegantly by a single recursive
975 // function, but we want to guard against the unlikely possibility of
976 // a smart compiler optimizing the recursion away.
977 //
978 // GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining
979 // StackLowerThanAddress into StackGrowsDown, which then doesn't give
980 // correct answer.
981 void StackLowerThanAddress(const void* ptr, bool* result) GTEST_NO_INLINE_;
982 void StackLowerThanAddress(const void* ptr, bool* result) {
983 int dummy;
984 *result = (&dummy < ptr);
985 }
986
987 bool StackGrowsDown() {
988 int dummy;
989 bool result;
990 StackLowerThanAddress(&dummy, &result);
991 return result;
992 }
993
994 // Spawns a child process with the same executable as the current process in
995 // a thread-safe manner and instructs it to run the death test. The
996 // implementation uses fork(2) + exec. On systems where clone(2) is
997 // available, it is used instead, being slightly more thread-safe. On QNX,
998 // fork supports only single-threaded environments, so this function uses
999 // spawn(2) there instead. The function dies with an error message if
1000 // anything goes wrong.
1001 static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
1002 ExecDeathTestArgs args = { argv, close_fd };
1003 pid_t child_pid = -1;
1004
1005 # if GTEST_OS_QNX
1006 // Obtains the current directory and sets it to be closed in the child
1007 // process.
1008 const int cwd_fd = open(".", O_RDONLY);
1009 GTEST_DEATH_TEST_CHECK_(cwd_fd != -1);
1010 GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(cwd_fd, F_SETFD, FD_CLOEXEC));
1011 // We need to execute the test program in the same environment where
1012 // it was originally invoked. Therefore we change to the original
1013 // working directory first.
1014 const char* const original_dir =
1015 UnitTest::GetInstance()->original_working_dir();
1016 // We can safely call chdir() as it's a direct system call.
1017 if (chdir(original_dir) != 0) {
1018 DeathTestAbort(std::string("chdir(\"") + original_dir + "\") failed: " +
1019 GetLastErrnoDescription());
1020 return EXIT_FAILURE;
1021 }
1022
1023 int fd_flags;
1024 // Set close_fd to be closed after spawn.
1025 GTEST_DEATH_TEST_CHECK_SYSCALL_(fd_flags = fcntl(close_fd, F_GETFD));
1026 GTEST_DEATH_TEST_CHECK_SYSCALL_(fcntl(close_fd, F_SETFD,
1027 fd_flags | FD_CLOEXEC));
1028 struct inheritance inherit = {0};
1029 // spawn is a system call.
1030 child_pid = spawn(args.argv[0], 0, NULL, &inherit, args.argv, GetEnviron());
1031 // Restores the current working directory.
1032 GTEST_DEATH_TEST_CHECK_(fchdir(cwd_fd) != -1);
1033 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(cwd_fd));
1034
1035 # else // GTEST_OS_QNX
1036 # if GTEST_OS_LINUX
1037 // When a SIGPROF signal is received while fork() or clone() are executing,
1038 // the process may hang. To avoid this, we ignore SIGPROF here and re-enable
1039 // it after the call to fork()/clone() is complete.
1040 struct sigaction saved_sigprof_action;
1041 struct sigaction ignore_sigprof_action;
1042 memset(&ignore_sigprof_action, 0, sizeof(ignore_sigprof_action));
1043 sigemptyset(&ignore_sigprof_action.sa_mask);
1044 ignore_sigprof_action.sa_handler = SIG_IGN;
1045 GTEST_DEATH_TEST_CHECK_SYSCALL_(sigaction(
1046 SIGPROF, &ignore_sigprof_action, &saved_sigprof_action));
1047 # endif // GTEST_OS_LINUX
1048
1049 # if GTEST_HAS_CLONE
1050 const bool use_fork = GTEST_FLAG(death_test_use_fork);
1051
1052 if (!use_fork) {
1053 static const bool stack_grows_down = StackGrowsDown();
1054 const size_t stack_size = getpagesize();
1055 // MMAP_ANONYMOUS is not defined on Mac, so we use MAP_ANON instead.
1056 void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
1057 MAP_ANON | MAP_PRIVATE, -1, 0);
1058 GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
1059
1060 // Maximum stack alignment in bytes: For a downward-growing stack, this
1061 // amount is subtracted from size of the stack space to get an address
1062 // that is within the stack space and is aligned on all systems we care
1063 // about. As far as I know there is no ABI with stack alignment greater
1064 // than 64. We assume stack and stack_size already have alignment of
1065 // kMaxStackAlignment.
1066 const size_t kMaxStackAlignment = 64;
1067 void* const stack_top =
1068 static_cast<char*>(stack) +
1069 (stack_grows_down ? stack_size - kMaxStackAlignment : 0);
1070 GTEST_DEATH_TEST_CHECK_(stack_size > kMaxStackAlignment &&
1071 reinterpret_cast<intptr_t>(stack_top) % kMaxStackAlignment == 0);
1072
1073 child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);
1074
1075 GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
1076 }
1077 # else
1078 const bool use_fork = true;
1079 # endif // GTEST_HAS_CLONE
1080
1081 if (use_fork && (child_pid = fork()) == 0) {
1082 ExecDeathTestChildMain(&args);
1083 _exit(0);
1084 }
1085 # endif // GTEST_OS_QNX
1086 # if GTEST_OS_LINUX
1087 GTEST_DEATH_TEST_CHECK_SYSCALL_(
1088 sigaction(SIGPROF, &saved_sigprof_action, NULL));
1089 # endif // GTEST_OS_LINUX
1090
1091 GTEST_DEATH_TEST_CHECK_(child_pid != -1);
1092 return child_pid;
1093 }
1094
1095 // The AssumeRole process for a fork-and-exec death test. It re-executes the
1096 // main program from the beginning, setting the --gtest_filter
1097 // and --gtest_internal_run_death_test flags to cause only the current
1098 // death test to be re-run.
1099 DeathTest::TestRole ExecDeathTest::AssumeRole() {
1100 const UnitTestImpl* const impl = GetUnitTestImpl();
1101 const InternalRunDeathTestFlag* const flag =
1102 impl->internal_run_death_test_flag();
1103 const TestInfo* const info = impl->current_test_info();
1104 const int death_test_index = info->result()->death_test_count();
1105
1106 if (flag != NULL) {
1107 set_write_fd(flag->write_fd());
1108 return EXECUTE_TEST;
1109 }
1110
1111 int pipe_fd[2];
1112 GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
1113 // Clear the close-on-exec flag on the write end of the pipe, lest
1114 // it be closed when the child process does an exec:
1115 GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
1116
1117 const std::string filter_flag =
1118 std::string("--") + GTEST_FLAG_PREFIX_ + kFilterFlag + "="
1119 + info->test_case_name() + "." + info->name();
1120 const std::string internal_flag =
1121 std::string("--") + GTEST_FLAG_PREFIX_ + kInternalRunDeathTestFlag + "="
1122 + file_ + "|" + StreamableToString(line_) + "|"
1123 + StreamableToString(death_test_index) + "|"
1124 + StreamableToString(pipe_fd[1]);
1125 Arguments args;
1126 args.AddArguments(GetArgvsForDeathTestChildProcess());
1127 args.AddArgument(filter_flag.c_str());
1128 args.AddArgument(internal_flag.c_str());
1129
1130 DeathTest::set_last_death_test_message("");
1131
1132 CaptureStderr();
1133 // See the comment in NoExecDeathTest::AssumeRole for why the next line
1134 // is necessary.
1135 FlushInfoLog();
1136
1137 const pid_t child_pid = ExecDeathTestSpawnChild(args.Argv(), pipe_fd[0]);
1138 GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
1139 set_child_pid(child_pid);
1140 set_read_fd(pipe_fd[0]);
1141 set_spawned(true);
1142 return OVERSEE_TEST;
1143 }
1144
1145 # endif // !GTEST_OS_WINDOWS
1146
1147 // Creates a concrete DeathTest-derived class that depends on the
1148 // --gtest_death_test_style flag, and sets the pointer pointed to
1149 // by the "test" argument to its address. If the test should be
1150 // skipped, sets that pointer to NULL. Returns true, unless the
1151 // flag is set to an invalid value.
1152 bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
1153 const char* file, int line,
1154 DeathTest** test) {
1155 UnitTestImpl* const impl = GetUnitTestImpl();
1156 const InternalRunDeathTestFlag* const flag =
1157 impl->internal_run_death_test_flag();
1158 const int death_test_index = impl->current_test_info()
1159 ->increment_death_test_count();
1160
1161 if (flag != NULL) {
1162 if (death_test_index > flag->index()) {
1163 DeathTest::set_last_death_test_message(
1164 "Death test count (" + StreamableToString(death_test_index)
1165 + ") somehow exceeded expected maximum ("
1166 + StreamableToString(flag->index()) + ")");
1167 return false;
1168 }
1169
1170 if (!(flag->file() == file && flag->line() == line &&
1171 flag->index() == death_test_index)) {
1172 *test = NULL;
1173 return true;
1174 }
1175 }
1176
1177 # if GTEST_OS_WINDOWS
1178
1179 if (GTEST_FLAG(death_test_style) == "threadsafe" ||
1180 GTEST_FLAG(death_test_style) == "fast") {
1181 *test = new WindowsDeathTest(statement, regex, file, line);
1182 }
1183
1184 # else
1185
1186 if (GTEST_FLAG(death_test_style) == "threadsafe") {
1187 *test = new ExecDeathTest(statement, regex, file, line);
1188 } else if (GTEST_FLAG(death_test_style) == "fast") {
1189 *test = new NoExecDeathTest(statement, regex);
1190 }
1191
1192 # endif // GTEST_OS_WINDOWS
1193
1194 else { // NOLINT - this is more readable than unbalanced brackets inside #if.
1195 DeathTest::set_last_death_test_message(
1196 "Unknown death test style \"" + GTEST_FLAG(death_test_style)
1197 + "\" encountered");
1198 return false;
1199 }
1200
1201 return true;
1202 }
1203
1204 // Splits a given string on a given delimiter, populating a given
1205 // vector with the fields. GTEST_HAS_DEATH_TEST implies that we have
1206 // ::std::string, so we can use it here.
1207 static void SplitString(const ::std::string& str, char delimiter,
1208 ::std::vector< ::std::string>* dest) {
1209 ::std::vector< ::std::string> parsed;
1210 ::std::string::size_type pos = 0;
1211 while (::testing::internal::AlwaysTrue()) {
1212 const ::std::string::size_type colon = str.find(delimiter, pos);
1213 if (colon == ::std::string::npos) {
1214 parsed.push_back(str.substr(pos));
1215 break;
1216 } else {
1217 parsed.push_back(str.substr(pos, colon - pos));
1218 pos = colon + 1;
1219 }
1220 }
1221 dest->swap(parsed);
1222 }
1223
1224 # if GTEST_OS_WINDOWS
1225 // Recreates the pipe and event handles from the provided parameters,
1226 // signals the event, and returns a file descriptor wrapped around the pipe
1227 // handle. This function is called in the child process only.
1228 int GetStatusFileDescriptor(unsigned int parent_process_id,
1229 size_t write_handle_as_size_t,
1230 size_t event_handle_as_size_t) {
1231 AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE,
1232 FALSE, // Non-inheritable.
1233 parent_process_id));
1234 if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) {
1235 DeathTestAbort("Unable to open parent process " +
1236 StreamableToString(parent_process_id));
1237 }
1238
1239 // TODO(vladl@google.com): Replace the following check with a
1240 // compile-time assertion when available.
1241 GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t));
1242
1243 const HANDLE write_handle =
1244 reinterpret_cast<HANDLE>(write_handle_as_size_t);
1245 HANDLE dup_write_handle;
1246
1247 // The newly initialized handle is accessible only in in the parent
1248 // process. To obtain one accessible within the child, we need to use
1249 // DuplicateHandle.
1250 if (!::DuplicateHandle(parent_process_handle.Get(), write_handle,
1251 ::GetCurrentProcess(), &dup_write_handle,
1252 0x0, // Requested privileges ignored since
1253 // DUPLICATE_SAME_ACCESS is used.
1254 FALSE, // Request non-inheritable handler.
1255 DUPLICATE_SAME_ACCESS)) {
1256 DeathTestAbort("Unable to duplicate the pipe handle " +
1257 StreamableToString(write_handle_as_size_t) +
1258 " from the parent process " +
1259 StreamableToString(parent_process_id));
1260 }
1261
1262 const HANDLE event_handle = reinterpret_cast<HANDLE>(event_handle_as_size_t);
1263 HANDLE dup_event_handle;
1264
1265 if (!::DuplicateHandle(parent_process_handle.Get(), event_handle,
1266 ::GetCurrentProcess(), &dup_event_handle,
1267 0x0,
1268 FALSE,
1269 DUPLICATE_SAME_ACCESS)) {
1270 DeathTestAbort("Unable to duplicate the event handle " +
1271 StreamableToString(event_handle_as_size_t) +
1272 " from the parent process " +
1273 StreamableToString(parent_process_id));
1274 }
1275
1276 const int write_fd =
1277 ::_open_osfhandle(reinterpret_cast<intptr_t>(dup_write_handle), O_APPEND);
1278 if (write_fd == -1) {
1279 DeathTestAbort("Unable to convert pipe handle " +
1280 StreamableToString(write_handle_as_size_t) +
1281 " to a file descriptor");
1282 }
1283
1284 // Signals the parent that the write end of the pipe has been acquired
1285 // so the parent can release its own write end.
1286 ::SetEvent(dup_event_handle);
1287
1288 return write_fd;
1289 }
1290 # endif // GTEST_OS_WINDOWS
1291
1292 // Returns a newly created InternalRunDeathTestFlag object with fields
1293 // initialized from the GTEST_FLAG(internal_run_death_test) flag if
1294 // the flag is specified; otherwise returns NULL.
1295 InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
1296 if (GTEST_FLAG(internal_run_death_test) == "") return NULL;
1297
1298 // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we
1299 // can use it here.
1300 int line = -1;
1301 int index = -1;
1302 ::std::vector< ::std::string> fields;
1303 SplitString(GTEST_FLAG(internal_run_death_test).c_str(), '|', &fields);
1304 int write_fd = -1;
1305
1306 # if GTEST_OS_WINDOWS
1307
1308 unsigned int parent_process_id = 0;
1309 size_t write_handle_as_size_t = 0;
1310 size_t event_handle_as_size_t = 0;
1311
1312 if (fields.size() != 6
1313 || !ParseNaturalNumber(fields[1], &line)
1314 || !ParseNaturalNumber(fields[2], &index)
1315 || !ParseNaturalNumber(fields[3], &parent_process_id)
1316 || !ParseNaturalNumber(fields[4], &write_handle_as_size_t)
1317 || !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) {
1318 DeathTestAbort("Bad --gtest_internal_run_death_test flag: " +
1319 GTEST_FLAG(internal_run_death_test));
1320 }
1321 write_fd = GetStatusFileDescriptor(parent_process_id,
1322 write_handle_as_size_t,
1323 event_handle_as_size_t);
1324 # else
1325
1326 if (fields.size() != 4
1327 || !ParseNaturalNumber(fields[1], &line)
1328 || !ParseNaturalNumber(fields[2], &index)
1329 || !ParseNaturalNumber(fields[3], &write_fd)) {
1330 DeathTestAbort("Bad --gtest_internal_run_death_test flag: "
1331 + GTEST_FLAG(internal_run_death_test));
1332 }
1333
1334 # endif // GTEST_OS_WINDOWS
1335
1336 return new InternalRunDeathTestFlag(fields[0], line, index, write_fd);
1337 }
1338
1339 } // namespace internal
1340
1341 #endif // GTEST_HAS_DEATH_TEST
1342
1343 } // namespace testing
0 // Copyright 2008, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Authors: keith.ray@gmail.com (Keith Ray)
30
31 #include "gtest/gtest-message.h"
32 #include "gtest/internal/gtest-filepath.h"
33 #include "gtest/internal/gtest-port.h"
34
35 #include <stdlib.h>
36
37 #if GTEST_OS_WINDOWS_MOBILE
38 # include <windows.h>
39 #elif GTEST_OS_WINDOWS
40 # include <direct.h>
41 # include <io.h>
42 #elif GTEST_OS_SYMBIAN
43 // Symbian OpenC has PATH_MAX in sys/syslimits.h
44 # include <sys/syslimits.h>
45 #else
46 # include <limits.h>
47 # include <climits> // Some Linux distributions define PATH_MAX here.
48 #endif // GTEST_OS_WINDOWS_MOBILE
49
50 #if GTEST_OS_WINDOWS
51 # define GTEST_PATH_MAX_ _MAX_PATH
52 #elif defined(PATH_MAX)
53 # define GTEST_PATH_MAX_ PATH_MAX
54 #elif defined(_XOPEN_PATH_MAX)
55 # define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
56 #else
57 # define GTEST_PATH_MAX_ _POSIX_PATH_MAX
58 #endif // GTEST_OS_WINDOWS
59
60 #include "gtest/internal/gtest-string.h"
61
62 namespace testing {
63 namespace internal {
64
65 #if GTEST_OS_WINDOWS
66 // On Windows, '\\' is the standard path separator, but many tools and the
67 // Windows API also accept '/' as an alternate path separator. Unless otherwise
68 // noted, a file path can contain either kind of path separators, or a mixture
69 // of them.
70 const char kPathSeparator = '\\';
71 const char kAlternatePathSeparator = '/';
72 const char kPathSeparatorString[] = "\\";
73 const char kAlternatePathSeparatorString[] = "/";
74 # if GTEST_OS_WINDOWS_MOBILE
75 // Windows CE doesn't have a current directory. You should not use
76 // the current directory in tests on Windows CE, but this at least
77 // provides a reasonable fallback.
78 const char kCurrentDirectoryString[] = "\\";
79 // Windows CE doesn't define INVALID_FILE_ATTRIBUTES
80 const DWORD kInvalidFileAttributes = 0xffffffff;
81 # else
82 const char kCurrentDirectoryString[] = ".\\";
83 # endif // GTEST_OS_WINDOWS_MOBILE
84 #else
85 const char kPathSeparator = '/';
86 const char kPathSeparatorString[] = "/";
87 const char kCurrentDirectoryString[] = "./";
88 #endif // GTEST_OS_WINDOWS
89
90 // Returns whether the given character is a valid path separator.
91 static bool IsPathSeparator(char c) {
92 #if GTEST_HAS_ALT_PATH_SEP_
93 return (c == kPathSeparator) || (c == kAlternatePathSeparator);
94 #else
95 return c == kPathSeparator;
96 #endif
97 }
98
99 // Returns the current working directory, or "" if unsuccessful.
100 FilePath FilePath::GetCurrentDir() {
101 #if GTEST_OS_WINDOWS_MOBILE
102 // Windows CE doesn't have a current directory, so we just return
103 // something reasonable.
104 return FilePath(kCurrentDirectoryString);
105 #elif GTEST_OS_WINDOWS
106 char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
107 return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
108 #else
109 char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
110 return FilePath(getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
111 #endif // GTEST_OS_WINDOWS_MOBILE
112 }
113
114 // Returns a copy of the FilePath with the case-insensitive extension removed.
115 // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
116 // FilePath("dir/file"). If a case-insensitive extension is not
117 // found, returns a copy of the original FilePath.
118 FilePath FilePath::RemoveExtension(const char* extension) const {
119 const std::string dot_extension = std::string(".") + extension;
120 if (String::EndsWithCaseInsensitive(pathname_, dot_extension)) {
121 return FilePath(pathname_.substr(
122 0, pathname_.length() - dot_extension.length()));
123 }
124 return *this;
125 }
126
127 // Returns a pointer to the last occurence of a valid path separator in
128 // the FilePath. On Windows, for example, both '/' and '\' are valid path
129 // separators. Returns NULL if no path separator was found.
130 const char* FilePath::FindLastPathSeparator() const {
131 const char* const last_sep = strrchr(c_str(), kPathSeparator);
132 #if GTEST_HAS_ALT_PATH_SEP_
133 const char* const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator);
134 // Comparing two pointers of which only one is NULL is undefined.
135 if (last_alt_sep != NULL &&
136 (last_sep == NULL || last_alt_sep > last_sep)) {
137 return last_alt_sep;
138 }
139 #endif
140 return last_sep;
141 }
142
143 // Returns a copy of the FilePath with the directory part removed.
144 // Example: FilePath("path/to/file").RemoveDirectoryName() returns
145 // FilePath("file"). If there is no directory part ("just_a_file"), it returns
146 // the FilePath unmodified. If there is no file part ("just_a_dir/") it
147 // returns an empty FilePath ("").
148 // On Windows platform, '\' is the path separator, otherwise it is '/'.
149 FilePath FilePath::RemoveDirectoryName() const {
150 const char* const last_sep = FindLastPathSeparator();
151 return last_sep ? FilePath(last_sep + 1) : *this;
152 }
153
154 // RemoveFileName returns the directory path with the filename removed.
155 // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
156 // If the FilePath is "a_file" or "/a_file", RemoveFileName returns
157 // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
158 // not have a file, like "just/a/dir/", it returns the FilePath unmodified.
159 // On Windows platform, '\' is the path separator, otherwise it is '/'.
160 FilePath FilePath::RemoveFileName() const {
161 const char* const last_sep = FindLastPathSeparator();
162 std::string dir;
163 if (last_sep) {
164 dir = std::string(c_str(), last_sep + 1 - c_str());
165 } else {
166 dir = kCurrentDirectoryString;
167 }
168 return FilePath(dir);
169 }
170
171 // Helper functions for naming files in a directory for xml output.
172
173 // Given directory = "dir", base_name = "test", number = 0,
174 // extension = "xml", returns "dir/test.xml". If number is greater
175 // than zero (e.g., 12), returns "dir/test_12.xml".
176 // On Windows platform, uses \ as the separator rather than /.
177 FilePath FilePath::MakeFileName(const FilePath& directory,
178 const FilePath& base_name,
179 int number,
180 const char* extension) {
181 std::string file;
182 if (number == 0) {
183 file = base_name.string() + "." + extension;
184 } else {
185 file = base_name.string() + "_" + StreamableToString(number)
186 + "." + extension;
187 }
188 return ConcatPaths(directory, FilePath(file));
189 }
190
191 // Given directory = "dir", relative_path = "test.xml", returns "dir/test.xml".
192 // On Windows, uses \ as the separator rather than /.
193 FilePath FilePath::ConcatPaths(const FilePath& directory,
194 const FilePath& relative_path) {
195 if (directory.IsEmpty())
196 return relative_path;
197 const FilePath dir(directory.RemoveTrailingPathSeparator());
198 return FilePath(dir.string() + kPathSeparator + relative_path.string());
199 }
200
201 // Returns true if pathname describes something findable in the file-system,
202 // either a file, directory, or whatever.
203 bool FilePath::FileOrDirectoryExists() const {
204 #if GTEST_OS_WINDOWS_MOBILE
205 LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
206 const DWORD attributes = GetFileAttributes(unicode);
207 delete [] unicode;
208 return attributes != kInvalidFileAttributes;
209 #else
210 posix::StatStruct file_stat;
211 return posix::Stat(pathname_.c_str(), &file_stat) == 0;
212 #endif // GTEST_OS_WINDOWS_MOBILE
213 }
214
215 // Returns true if pathname describes a directory in the file-system
216 // that exists.
217 bool FilePath::DirectoryExists() const {
218 bool result = false;
219 #if GTEST_OS_WINDOWS
220 // Don't strip off trailing separator if path is a root directory on
221 // Windows (like "C:\\").
222 const FilePath& path(IsRootDirectory() ? *this :
223 RemoveTrailingPathSeparator());
224 #else
225 const FilePath& path(*this);
226 #endif
227
228 #if GTEST_OS_WINDOWS_MOBILE
229 LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
230 const DWORD attributes = GetFileAttributes(unicode);
231 delete [] unicode;
232 if ((attributes != kInvalidFileAttributes) &&
233 (attributes & FILE_ATTRIBUTE_DIRECTORY)) {
234 result = true;
235 }
236 #else
237 posix::StatStruct file_stat;
238 result = posix::Stat(path.c_str(), &file_stat) == 0 &&
239 posix::IsDir(file_stat);
240 #endif // GTEST_OS_WINDOWS_MOBILE
241
242 return result;
243 }
244
245 // Returns true if pathname describes a root directory. (Windows has one
246 // root directory per disk drive.)
247 bool FilePath::IsRootDirectory() const {
248 #if GTEST_OS_WINDOWS
249 // TODO(wan@google.com): on Windows a network share like
250 // \\server\share can be a root directory, although it cannot be the
251 // current directory. Handle this properly.
252 return pathname_.length() == 3 && IsAbsolutePath();
253 #else
254 return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
255 #endif
256 }
257
258 // Returns true if pathname describes an absolute path.
259 bool FilePath::IsAbsolutePath() const {
260 const char* const name = pathname_.c_str();
261 #if GTEST_OS_WINDOWS
262 return pathname_.length() >= 3 &&
263 ((name[0] >= 'a' && name[0] <= 'z') ||
264 (name[0] >= 'A' && name[0] <= 'Z')) &&
265 name[1] == ':' &&
266 IsPathSeparator(name[2]);
267 #else
268 return IsPathSeparator(name[0]);
269 #endif
270 }
271
272 // Returns a pathname for a file that does not currently exist. The pathname
273 // will be directory/base_name.extension or
274 // directory/base_name_<number>.extension if directory/base_name.extension
275 // already exists. The number will be incremented until a pathname is found
276 // that does not already exist.
277 // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
278 // There could be a race condition if two or more processes are calling this
279 // function at the same time -- they could both pick the same filename.
280 FilePath FilePath::GenerateUniqueFileName(const FilePath& directory,
281 const FilePath& base_name,
282 const char* extension) {
283 FilePath full_pathname;
284 int number = 0;
285 do {
286 full_pathname.Set(MakeFileName(directory, base_name, number++, extension));
287 } while (full_pathname.FileOrDirectoryExists());
288 return full_pathname;
289 }
290
291 // Returns true if FilePath ends with a path separator, which indicates that
292 // it is intended to represent a directory. Returns false otherwise.
293 // This does NOT check that a directory (or file) actually exists.
294 bool FilePath::IsDirectory() const {
295 return !pathname_.empty() &&
296 IsPathSeparator(pathname_.c_str()[pathname_.length() - 1]);
297 }
298
299 // Create directories so that path exists. Returns true if successful or if
300 // the directories already exist; returns false if unable to create directories
301 // for any reason.
302 bool FilePath::CreateDirectoriesRecursively() const {
303 if (!this->IsDirectory()) {
304 return false;
305 }
306
307 if (pathname_.length() == 0 || this->DirectoryExists()) {
308 return true;
309 }
310
311 const FilePath parent(this->RemoveTrailingPathSeparator().RemoveFileName());
312 return parent.CreateDirectoriesRecursively() && this->CreateFolder();
313 }
314
315 // Create the directory so that path exists. Returns true if successful or
316 // if the directory already exists; returns false if unable to create the
317 // directory for any reason, including if the parent directory does not
318 // exist. Not named "CreateDirectory" because that's a macro on Windows.
319 bool FilePath::CreateFolder() const {
320 #if GTEST_OS_WINDOWS_MOBILE
321 FilePath removed_sep(this->RemoveTrailingPathSeparator());
322 LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
323 int result = CreateDirectory(unicode, NULL) ? 0 : -1;
324 delete [] unicode;
325 #elif GTEST_OS_WINDOWS
326 int result = _mkdir(pathname_.c_str());
327 #else
328 int result = mkdir(pathname_.c_str(), 0777);
329 #endif // GTEST_OS_WINDOWS_MOBILE
330
331 if (result == -1) {
332 return this->DirectoryExists(); // An error is OK if the directory exists.
333 }
334 return true; // No error.
335 }
336
337 // If input name has a trailing separator character, remove it and return the
338 // name, otherwise return the name string unmodified.
339 // On Windows platform, uses \ as the separator, other platforms use /.
340 FilePath FilePath::RemoveTrailingPathSeparator() const {
341 return IsDirectory()
342 ? FilePath(pathname_.substr(0, pathname_.length() - 1))
343 : *this;
344 }
345
346 // Removes any redundant separators that might be in the pathname.
347 // For example, "bar///foo" becomes "bar/foo". Does not eliminate other
348 // redundancies that might be in a pathname involving "." or "..".
349 // TODO(wan@google.com): handle Windows network shares (e.g. \\server\share).
350 void FilePath::Normalize() {
351 if (pathname_.c_str() == NULL) {
352 pathname_ = "";
353 return;
354 }
355 const char* src = pathname_.c_str();
356 char* const dest = new char[pathname_.length() + 1];
357 char* dest_ptr = dest;
358 memset(dest_ptr, 0, pathname_.length() + 1);
359
360 while (*src != '\0') {
361 *dest_ptr = *src;
362 if (!IsPathSeparator(*src)) {
363 src++;
364 } else {
365 #if GTEST_HAS_ALT_PATH_SEP_
366 if (*dest_ptr == kAlternatePathSeparator) {
367 *dest_ptr = kPathSeparator;
368 }
369 #endif
370 while (IsPathSeparator(*src))
371 src++;
372 }
373 dest_ptr++;
374 }
375 *dest_ptr = '\0';
376 pathname_ = dest;
377 delete[] dest;
378 }
379
380 } // namespace internal
381 } // namespace testing
0 // Copyright 2005, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 // Utility functions and classes used by the Google C++ testing framework.
30 //
31 // Author: wan@google.com (Zhanyong Wan)
32 //
33 // This file contains purely Google Test's internal implementation. Please
34 // DO NOT #INCLUDE IT IN A USER PROGRAM.
35
36 #ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
37 #define GTEST_SRC_GTEST_INTERNAL_INL_H_
38
39 // GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
40 // part of Google Test's implementation; otherwise it's undefined.
41 #if !GTEST_IMPLEMENTATION_
42 // A user is trying to include this from his code - just say no.
43 # error "gtest-internal-inl.h is part of Google Test's internal implementation."
44 # error "It must not be included except by Google Test itself."
45 #endif // GTEST_IMPLEMENTATION_
46
47 #ifndef _WIN32_WCE
48 # include <errno.h>
49 #endif // !_WIN32_WCE
50 #include <stddef.h>
51 #include <stdlib.h> // For strtoll/_strtoul64/malloc/free.
52 #include <string.h> // For memmove.
53
54 #include <algorithm>
55 #include <string>
56 #include <vector>
57
58 #include "gtest/internal/gtest-port.h"
59
60 #if GTEST_CAN_STREAM_RESULTS_
61 # include <arpa/inet.h> // NOLINT
62 # include <netdb.h> // NOLINT
63 #endif
64
65 #if GTEST_OS_WINDOWS
66 # include <windows.h> // NOLINT
67 #endif // GTEST_OS_WINDOWS
68
69 #include "gtest/gtest.h" // NOLINT
70 #include "gtest/gtest-spi.h"
71
72 namespace testing {
73
74 // Declares the flags.
75 //
76 // We don't want the users to modify this flag in the code, but want
77 // Google Test's own unit tests to be able to access it. Therefore we
78 // declare it here as opposed to in gtest.h.
79 GTEST_DECLARE_bool_(death_test_use_fork);
80
81 namespace internal {
82
83 // The value of GetTestTypeId() as seen from within the Google Test
84 // library. This is solely for testing GetTestTypeId().
85 GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
86
87 // Names of the flags (needed for parsing Google Test flags).
88 const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
89 const char kBreakOnFailureFlag[] = "break_on_failure";
90 const char kCatchExceptionsFlag[] = "catch_exceptions";
91 const char kColorFlag[] = "color";
92 const char kFilterFlag[] = "filter";
93 const char kListTestsFlag[] = "list_tests";
94 const char kOutputFlag[] = "output";
95 const char kPrintTimeFlag[] = "print_time";
96 const char kRandomSeedFlag[] = "random_seed";
97 const char kRepeatFlag[] = "repeat";
98 const char kShuffleFlag[] = "shuffle";
99 const char kStackTraceDepthFlag[] = "stack_trace_depth";
100 const char kStreamResultToFlag[] = "stream_result_to";
101 const char kThrowOnFailureFlag[] = "throw_on_failure";
102
103 // A valid random seed must be in [1, kMaxRandomSeed].
104 const int kMaxRandomSeed = 99999;
105
106 // g_help_flag is true iff the --help flag or an equivalent form is
107 // specified on the command line.
108 GTEST_API_ extern bool g_help_flag;
109
110 // Returns the current time in milliseconds.
111 GTEST_API_ TimeInMillis GetTimeInMillis();
112
113 // Returns true iff Google Test should use colors in the output.
114 GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
115
116 // Formats the given time in milliseconds as seconds.
117 GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
118
119 // Converts the given time in milliseconds to a date string in the ISO 8601
120 // format, without the timezone information. N.B.: due to the use the
121 // non-reentrant localtime() function, this function is not thread safe. Do
122 // not use it in any code that can be called from multiple threads.
123 GTEST_API_ std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms);
124
125 // Parses a string for an Int32 flag, in the form of "--flag=value".
126 //
127 // On success, stores the value of the flag in *value, and returns
128 // true. On failure, returns false without changing *value.
129 GTEST_API_ bool ParseInt32Flag(
130 const char* str, const char* flag, Int32* value);
131
132 // Returns a random seed in range [1, kMaxRandomSeed] based on the
133 // given --gtest_random_seed flag value.
134 inline int GetRandomSeedFromFlag(Int32 random_seed_flag) {
135 const unsigned int raw_seed = (random_seed_flag == 0) ?
136 static_cast<unsigned int>(GetTimeInMillis()) :
137 static_cast<unsigned int>(random_seed_flag);
138
139 // Normalizes the actual seed to range [1, kMaxRandomSeed] such that
140 // it's easy to type.
141 const int normalized_seed =
142 static_cast<int>((raw_seed - 1U) %
143 static_cast<unsigned int>(kMaxRandomSeed)) + 1;
144 return normalized_seed;
145 }
146
147 // Returns the first valid random seed after 'seed'. The behavior is
148 // undefined if 'seed' is invalid. The seed after kMaxRandomSeed is
149 // considered to be 1.
150 inline int GetNextRandomSeed(int seed) {
151 GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
152 << "Invalid random seed " << seed << " - must be in [1, "
153 << kMaxRandomSeed << "].";
154 const int next_seed = seed + 1;
155 return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
156 }
157
158 // This class saves the values of all Google Test flags in its c'tor, and
159 // restores them in its d'tor.
160 class GTestFlagSaver {
161 public:
162 // The c'tor.
163 GTestFlagSaver() {
164 also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
165 break_on_failure_ = GTEST_FLAG(break_on_failure);
166 catch_exceptions_ = GTEST_FLAG(catch_exceptions);
167 color_ = GTEST_FLAG(color);
168 death_test_style_ = GTEST_FLAG(death_test_style);
169 death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
170 filter_ = GTEST_FLAG(filter);
171 internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
172 list_tests_ = GTEST_FLAG(list_tests);
173 output_ = GTEST_FLAG(output);
174 print_time_ = GTEST_FLAG(print_time);
175 random_seed_ = GTEST_FLAG(random_seed);
176 repeat_ = GTEST_FLAG(repeat);
177 shuffle_ = GTEST_FLAG(shuffle);
178 stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
179 stream_result_to_ = GTEST_FLAG(stream_result_to);
180 throw_on_failure_ = GTEST_FLAG(throw_on_failure);
181 }
182
183 // The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
184 ~GTestFlagSaver() {
185 GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
186 GTEST_FLAG(break_on_failure) = break_on_failure_;
187 GTEST_FLAG(catch_exceptions) = catch_exceptions_;
188 GTEST_FLAG(color) = color_;
189 GTEST_FLAG(death_test_style) = death_test_style_;
190 GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
191 GTEST_FLAG(filter) = filter_;
192 GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
193 GTEST_FLAG(list_tests) = list_tests_;
194 GTEST_FLAG(output) = output_;
195 GTEST_FLAG(print_time) = print_time_;
196 GTEST_FLAG(random_seed) = random_seed_;
197 GTEST_FLAG(repeat) = repeat_;
198 GTEST_FLAG(shuffle) = shuffle_;
199 GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
200 GTEST_FLAG(stream_result_to) = stream_result_to_;
201 GTEST_FLAG(throw_on_failure) = throw_on_failure_;
202 }
203
204 private:
205 // Fields for saving the original values of flags.
206 bool also_run_disabled_tests_;
207 bool break_on_failure_;
208 bool catch_exceptions_;
209 std::string color_;
210 std::string death_test_style_;
211 bool death_test_use_fork_;
212 std::string filter_;
213 std::string internal_run_death_test_;
214 bool list_tests_;
215 std::string output_;
216 bool print_time_;
217 internal::Int32 random_seed_;
218 internal::Int32 repeat_;
219 bool shuffle_;
220 internal::Int32 stack_trace_depth_;
221 std::string stream_result_to_;
222 bool throw_on_failure_;
223 } GTEST_ATTRIBUTE_UNUSED_;
224
225 // Converts a Unicode code point to a narrow string in UTF-8 encoding.
226 // code_point parameter is of type UInt32 because wchar_t may not be
227 // wide enough to contain a code point.
228 // If the code_point is not a valid Unicode code point
229 // (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted
230 // to "(Invalid Unicode 0xXXXXXXXX)".
231 GTEST_API_ std::string CodePointToUtf8(UInt32 code_point);
232
233 // Converts a wide string to a narrow string in UTF-8 encoding.
234 // The wide string is assumed to have the following encoding:
235 // UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
236 // UTF-32 if sizeof(wchar_t) == 4 (on Linux)
237 // Parameter str points to a null-terminated wide string.
238 // Parameter num_chars may additionally limit the number
239 // of wchar_t characters processed. -1 is used when the entire string
240 // should be processed.
241 // If the string contains code points that are not valid Unicode code points
242 // (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
243 // as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
244 // and contains invalid UTF-16 surrogate pairs, values in those pairs
245 // will be encoded as individual Unicode characters from Basic Normal Plane.
246 GTEST_API_ std::string WideStringToUtf8(const wchar_t* str, int num_chars);
247
248 // Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
249 // if the variable is present. If a file already exists at this location, this
250 // function will write over it. If the variable is present, but the file cannot
251 // be created, prints an error and exits.
252 void WriteToShardStatusFileIfNeeded();
253
254 // Checks whether sharding is enabled by examining the relevant
255 // environment variable values. If the variables are present,
256 // but inconsistent (e.g., shard_index >= total_shards), prints
257 // an error and exits. If in_subprocess_for_death_test, sharding is
258 // disabled because it must only be applied to the original test
259 // process. Otherwise, we could filter out death tests we intended to execute.
260 GTEST_API_ bool ShouldShard(const char* total_shards_str,
261 const char* shard_index_str,
262 bool in_subprocess_for_death_test);
263
264 // Parses the environment variable var as an Int32. If it is unset,
265 // returns default_val. If it is not an Int32, prints an error and
266 // and aborts.
267 GTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val);
268
269 // Given the total number of shards, the shard index, and the test id,
270 // returns true iff the test should be run on this shard. The test id is
271 // some arbitrary but unique non-negative integer assigned to each test
272 // method. Assumes that 0 <= shard_index < total_shards.
273 GTEST_API_ bool ShouldRunTestOnShard(
274 int total_shards, int shard_index, int test_id);
275
276 // STL container utilities.
277
278 // Returns the number of elements in the given container that satisfy
279 // the given predicate.
280 template <class Container, typename Predicate>
281 inline int CountIf(const Container& c, Predicate predicate) {
282 // Implemented as an explicit loop since std::count_if() in libCstd on
283 // Solaris has a non-standard signature.
284 int count = 0;
285 for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
286 if (predicate(*it))
287 ++count;
288 }
289 return count;
290 }
291
292 // Applies a function/functor to each element in the container.
293 template <class Container, typename Functor>
294 void ForEach(const Container& c, Functor functor) {
295 std::for_each(c.begin(), c.end(), functor);
296 }
297
298 // Returns the i-th element of the vector, or default_value if i is not
299 // in range [0, v.size()).
300 template <typename E>
301 inline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
302 return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
303 }
304
305 // Performs an in-place shuffle of a range of the vector's elements.
306 // 'begin' and 'end' are element indices as an STL-style range;
307 // i.e. [begin, end) are shuffled, where 'end' == size() means to
308 // shuffle to the end of the vector.
309 template <typename E>
310 void ShuffleRange(internal::Random* random, int begin, int end,
311 std::vector<E>* v) {
312 const int size = static_cast<int>(v->size());
313 GTEST_CHECK_(0 <= begin && begin <= size)
314 << "Invalid shuffle range start " << begin << ": must be in range [0, "
315 << size << "].";
316 GTEST_CHECK_(begin <= end && end <= size)
317 << "Invalid shuffle range finish " << end << ": must be in range ["
318 << begin << ", " << size << "].";
319
320 // Fisher-Yates shuffle, from
321 // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
322 for (int range_width = end - begin; range_width >= 2; range_width--) {
323 const int last_in_range = begin + range_width - 1;
324 const int selected = begin + random->Generate(range_width);
325 std::swap((*v)[selected], (*v)[last_in_range]);
326 }
327 }
328
329 // Performs an in-place shuffle of the vector's elements.
330 template <typename E>
331 inline void Shuffle(internal::Random* random, std::vector<E>* v) {
332 ShuffleRange(random, 0, static_cast<int>(v->size()), v);
333 }
334
335 // A function for deleting an object. Handy for being used as a
336 // functor.
337 template <typename T>
338 static void Delete(T* x) {
339 delete x;
340 }
341
342 // A predicate that checks the key of a TestProperty against a known key.
343 //
344 // TestPropertyKeyIs is copyable.
345 class TestPropertyKeyIs {
346 public:
347 // Constructor.
348 //
349 // TestPropertyKeyIs has NO default constructor.
350 explicit TestPropertyKeyIs(const std::string& key) : key_(key) {}
351
352 // Returns true iff the test name of test property matches on key_.
353 bool operator()(const TestProperty& test_property) const {
354 return test_property.key() == key_;
355 }
356
357 private:
358 std::string key_;
359 };
360
361 // Class UnitTestOptions.
362 //
363 // This class contains functions for processing options the user
364 // specifies when running the tests. It has only static members.
365 //
366 // In most cases, the user can specify an option using either an
367 // environment variable or a command line flag. E.g. you can set the
368 // test filter using either GTEST_FILTER or --gtest_filter. If both
369 // the variable and the flag are present, the latter overrides the
370 // former.
371 class GTEST_API_ UnitTestOptions {
372 public:
373 // Functions for processing the gtest_output flag.
374
375 // Returns the output format, or "" for normal printed output.
376 static std::string GetOutputFormat();
377
378 // Returns the absolute path of the requested output file, or the
379 // default (test_detail.xml in the original working directory) if
380 // none was explicitly specified.
381 static std::string GetAbsolutePathToOutputFile();
382
383 // Functions for processing the gtest_filter flag.
384
385 // Returns true iff the wildcard pattern matches the string. The
386 // first ':' or '\0' character in pattern marks the end of it.
387 //
388 // This recursive algorithm isn't very efficient, but is clear and
389 // works well enough for matching test names, which are short.
390 static bool PatternMatchesString(const char *pattern, const char *str);
391
392 // Returns true iff the user-specified filter matches the test case
393 // name and the test name.
394 static bool FilterMatchesTest(const std::string &test_case_name,
395 const std::string &test_name);
396
397 #if GTEST_OS_WINDOWS
398 // Function for supporting the gtest_catch_exception flag.
399
400 // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
401 // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
402 // This function is useful as an __except condition.
403 static int GTestShouldProcessSEH(DWORD exception_code);
404 #endif // GTEST_OS_WINDOWS
405
406 // Returns true if "name" matches the ':' separated list of glob-style
407 // filters in "filter".
408 static bool MatchesFilter(const std::string& name, const char* filter);
409 };
410
411 // Returns the current application's name, removing directory path if that
412 // is present. Used by UnitTestOptions::GetOutputFile.
413 GTEST_API_ FilePath GetCurrentExecutableName();
414
415 // The role interface for getting the OS stack trace as a string.
416 class OsStackTraceGetterInterface {
417 public:
418 OsStackTraceGetterInterface() {}
419 virtual ~OsStackTraceGetterInterface() {}
420
421 // Returns the current OS stack trace as an std::string. Parameters:
422 //
423 // max_depth - the maximum number of stack frames to be included
424 // in the trace.
425 // skip_count - the number of top frames to be skipped; doesn't count
426 // against max_depth.
427 virtual string CurrentStackTrace(int max_depth, int skip_count) = 0;
428
429 // UponLeavingGTest() should be called immediately before Google Test calls
430 // user code. It saves some information about the current stack that
431 // CurrentStackTrace() will use to find and hide Google Test stack frames.
432 virtual void UponLeavingGTest() = 0;
433
434 private:
435 GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
436 };
437
438 // A working implementation of the OsStackTraceGetterInterface interface.
439 class OsStackTraceGetter : public OsStackTraceGetterInterface {
440 public:
441 OsStackTraceGetter() : caller_frame_(NULL) {}
442
443 virtual string CurrentStackTrace(int max_depth, int skip_count)
444 GTEST_LOCK_EXCLUDED_(mutex_);
445
446 virtual void UponLeavingGTest() GTEST_LOCK_EXCLUDED_(mutex_);
447
448 // This string is inserted in place of stack frames that are part of
449 // Google Test's implementation.
450 static const char* const kElidedFramesMarker;
451
452 private:
453 Mutex mutex_; // protects all internal state
454
455 // We save the stack frame below the frame that calls user code.
456 // We do this because the address of the frame immediately below
457 // the user code changes between the call to UponLeavingGTest()
458 // and any calls to CurrentStackTrace() from within the user code.
459 void* caller_frame_;
460
461 GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
462 };
463
464 // Information about a Google Test trace point.
465 struct TraceInfo {
466 const char* file;
467 int line;
468 std::string message;
469 };
470
471 // This is the default global test part result reporter used in UnitTestImpl.
472 // This class should only be used by UnitTestImpl.
473 class DefaultGlobalTestPartResultReporter
474 : public TestPartResultReporterInterface {
475 public:
476 explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
477 // Implements the TestPartResultReporterInterface. Reports the test part
478 // result in the current test.
479 virtual void ReportTestPartResult(const TestPartResult& result);
480
481 private:
482 UnitTestImpl* const unit_test_;
483
484 GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);
485 };
486
487 // This is the default per thread test part result reporter used in
488 // UnitTestImpl. This class should only be used by UnitTestImpl.
489 class DefaultPerThreadTestPartResultReporter
490 : public TestPartResultReporterInterface {
491 public:
492 explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
493 // Implements the TestPartResultReporterInterface. The implementation just
494 // delegates to the current global test part result reporter of *unit_test_.
495 virtual void ReportTestPartResult(const TestPartResult& result);
496
497 private:
498 UnitTestImpl* const unit_test_;
499
500 GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);
501 };
502
503 // The private implementation of the UnitTest class. We don't protect
504 // the methods under a mutex, as this class is not accessible by a
505 // user and the UnitTest class that delegates work to this class does
506 // proper locking.
507 class GTEST_API_ UnitTestImpl {
508 public:
509 explicit UnitTestImpl(UnitTest* parent);
510 virtual ~UnitTestImpl();
511
512 // There are two different ways to register your own TestPartResultReporter.
513 // You can register your own repoter to listen either only for test results
514 // from the current thread or for results from all threads.
515 // By default, each per-thread test result repoter just passes a new
516 // TestPartResult to the global test result reporter, which registers the
517 // test part result for the currently running test.
518
519 // Returns the global test part result reporter.
520 TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
521
522 // Sets the global test part result reporter.
523 void SetGlobalTestPartResultReporter(
524 TestPartResultReporterInterface* reporter);
525
526 // Returns the test part result reporter for the current thread.
527 TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
528
529 // Sets the test part result reporter for the current thread.
530 void SetTestPartResultReporterForCurrentThread(
531 TestPartResultReporterInterface* reporter);
532
533 // Gets the number of successful test cases.
534 int successful_test_case_count() const;
535
536 // Gets the number of failed test cases.
537 int failed_test_case_count() const;
538
539 // Gets the number of all test cases.
540 int total_test_case_count() const;
541
542 // Gets the number of all test cases that contain at least one test
543 // that should run.
544 int test_case_to_run_count() const;
545
546 // Gets the number of successful tests.
547 int successful_test_count() const;
548
549 // Gets the number of failed tests.
550 int failed_test_count() const;
551
552 // Gets the number of disabled tests that will be reported in the XML report.
553 int reportable_disabled_test_count() const;
554
555 // Gets the number of disabled tests.
556 int disabled_test_count() const;
557
558 // Gets the number of tests to be printed in the XML report.
559 int reportable_test_count() const;
560
561 // Gets the number of all tests.
562 int total_test_count() const;
563
564 // Gets the number of tests that should run.
565 int test_to_run_count() const;
566
567 // Gets the time of the test program start, in ms from the start of the
568 // UNIX epoch.
569 TimeInMillis start_timestamp() const { return start_timestamp_; }
570
571 // Gets the elapsed time, in milliseconds.
572 TimeInMillis elapsed_time() const { return elapsed_time_; }
573
574 // Returns true iff the unit test passed (i.e. all test cases passed).
575 bool Passed() const { return !Failed(); }
576
577 // Returns true iff the unit test failed (i.e. some test case failed
578 // or something outside of all tests failed).
579 bool Failed() const {
580 return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
581 }
582
583 // Gets the i-th test case among all the test cases. i can range from 0 to
584 // total_test_case_count() - 1. If i is not in that range, returns NULL.
585 const TestCase* GetTestCase(int i) const {
586 const int index = GetElementOr(test_case_indices_, i, -1);
587 return index < 0 ? NULL : test_cases_[i];
588 }
589
590 // Gets the i-th test case among all the test cases. i can range from 0 to
591 // total_test_case_count() - 1. If i is not in that range, returns NULL.
592 TestCase* GetMutableTestCase(int i) {
593 const int index = GetElementOr(test_case_indices_, i, -1);
594 return index < 0 ? NULL : test_cases_[index];
595 }
596
597 // Provides access to the event listener list.
598 TestEventListeners* listeners() { return &listeners_; }
599
600 // Returns the TestResult for the test that's currently running, or
601 // the TestResult for the ad hoc test if no test is running.
602 TestResult* current_test_result();
603
604 // Returns the TestResult for the ad hoc test.
605 const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
606
607 // Sets the OS stack trace getter.
608 //
609 // Does nothing if the input and the current OS stack trace getter
610 // are the same; otherwise, deletes the old getter and makes the
611 // input the current getter.
612 void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);
613
614 // Returns the current OS stack trace getter if it is not NULL;
615 // otherwise, creates an OsStackTraceGetter, makes it the current
616 // getter, and returns it.
617 OsStackTraceGetterInterface* os_stack_trace_getter();
618
619 // Returns the current OS stack trace as an std::string.
620 //
621 // The maximum number of stack frames to be included is specified by
622 // the gtest_stack_trace_depth flag. The skip_count parameter
623 // specifies the number of top frames to be skipped, which doesn't
624 // count against the number of frames to be included.
625 //
626 // For example, if Foo() calls Bar(), which in turn calls
627 // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
628 // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
629 std::string CurrentOsStackTraceExceptTop(int skip_count) GTEST_NO_INLINE_;
630
631 // Finds and returns a TestCase with the given name. If one doesn't
632 // exist, creates one and returns it.
633 //
634 // Arguments:
635 //
636 // test_case_name: name of the test case
637 // type_param: the name of the test's type parameter, or NULL if
638 // this is not a typed or a type-parameterized test.
639 // set_up_tc: pointer to the function that sets up the test case
640 // tear_down_tc: pointer to the function that tears down the test case
641 TestCase* GetTestCase(const char* test_case_name,
642 const char* type_param,
643 Test::SetUpTestCaseFunc set_up_tc,
644 Test::TearDownTestCaseFunc tear_down_tc);
645
646 // Adds a TestInfo to the unit test.
647 //
648 // Arguments:
649 //
650 // set_up_tc: pointer to the function that sets up the test case
651 // tear_down_tc: pointer to the function that tears down the test case
652 // test_info: the TestInfo object
653 void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
654 Test::TearDownTestCaseFunc tear_down_tc,
655 TestInfo* test_info) {
656 // In order to support thread-safe death tests, we need to
657 // remember the original working directory when the test program
658 // was first invoked. We cannot do this in RUN_ALL_TESTS(), as
659 // the user may have changed the current directory before calling
660 // RUN_ALL_TESTS(). Therefore we capture the current directory in
661 // AddTestInfo(), which is called to register a TEST or TEST_F
662 // before main() is reached.
663 if (original_working_dir_.IsEmpty()) {
664 original_working_dir_.Set(FilePath::GetCurrentDir());
665 GTEST_CHECK_(!original_working_dir_.IsEmpty())
666 << "Failed to get the current working directory.";
667 }
668
669 GetTestCase(test_info->test_case_name(),
670 test_info->type_param(),
671 set_up_tc,
672 tear_down_tc)->AddTestInfo(test_info);
673 }
674
675 #if GTEST_HAS_PARAM_TEST
676 // Returns ParameterizedTestCaseRegistry object used to keep track of
677 // value-parameterized tests and instantiate and register them.
678 internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
679 return parameterized_test_registry_;
680 }
681 #endif // GTEST_HAS_PARAM_TEST
682
683 // Sets the TestCase object for the test that's currently running.
684 void set_current_test_case(TestCase* a_current_test_case) {
685 current_test_case_ = a_current_test_case;
686 }
687
688 // Sets the TestInfo object for the test that's currently running. If
689 // current_test_info is NULL, the assertion results will be stored in
690 // ad_hoc_test_result_.
691 void set_current_test_info(TestInfo* a_current_test_info) {
692 current_test_info_ = a_current_test_info;
693 }
694
695 // Registers all parameterized tests defined using TEST_P and
696 // INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
697 // combination. This method can be called more then once; it has guards
698 // protecting from registering the tests more then once. If
699 // value-parameterized tests are disabled, RegisterParameterizedTests is
700 // present but does nothing.
701 void RegisterParameterizedTests();
702
703 // Runs all tests in this UnitTest object, prints the result, and
704 // returns true if all tests are successful. If any exception is
705 // thrown during a test, this test is considered to be failed, but
706 // the rest of the tests will still be run.
707 bool RunAllTests();
708
709 // Clears the results of all tests, except the ad hoc tests.
710 void ClearNonAdHocTestResult() {
711 ForEach(test_cases_, TestCase::ClearTestCaseResult);
712 }
713
714 // Clears the results of ad-hoc test assertions.
715 void ClearAdHocTestResult() {
716 ad_hoc_test_result_.Clear();
717 }
718
719 // Adds a TestProperty to the current TestResult object when invoked in a
720 // context of a test or a test case, or to the global property set. If the
721 // result already contains a property with the same key, the value will be
722 // updated.
723 void RecordProperty(const TestProperty& test_property);
724
725 enum ReactionToSharding {
726 HONOR_SHARDING_PROTOCOL,
727 IGNORE_SHARDING_PROTOCOL
728 };
729
730 // Matches the full name of each test against the user-specified
731 // filter to decide whether the test should run, then records the
732 // result in each TestCase and TestInfo object.
733 // If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
734 // based on sharding variables in the environment.
735 // Returns the number of tests that should run.
736 int FilterTests(ReactionToSharding shard_tests);
737
738 // Prints the names of the tests matching the user-specified filter flag.
739 void ListTestsMatchingFilter();
740
741 const TestCase* current_test_case() const { return current_test_case_; }
742 TestInfo* current_test_info() { return current_test_info_; }
743 const TestInfo* current_test_info() const { return current_test_info_; }
744
745 // Returns the vector of environments that need to be set-up/torn-down
746 // before/after the tests are run.
747 std::vector<Environment*>& environments() { return environments_; }
748
749 // Getters for the per-thread Google Test trace stack.
750 std::vector<TraceInfo>& gtest_trace_stack() {
751 return *(gtest_trace_stack_.pointer());
752 }
753 const std::vector<TraceInfo>& gtest_trace_stack() const {
754 return gtest_trace_stack_.get();
755 }
756
757 #if GTEST_HAS_DEATH_TEST
758 void InitDeathTestSubprocessControlInfo() {
759 internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
760 }
761 // Returns a pointer to the parsed --gtest_internal_run_death_test
762 // flag, or NULL if that flag was not specified.
763 // This information is useful only in a death test child process.
764 // Must not be called before a call to InitGoogleTest.
765 const InternalRunDeathTestFlag* internal_run_death_test_flag() const {
766 return internal_run_death_test_flag_.get();
767 }
768
769 // Returns a pointer to the current death test factory.
770 internal::DeathTestFactory* death_test_factory() {
771 return death_test_factory_.get();
772 }
773
774 void SuppressTestEventsIfInSubprocess();
775
776 friend class ReplaceDeathTestFactory;
777 #endif // GTEST_HAS_DEATH_TEST
778
779 // Initializes the event listener performing XML output as specified by
780 // UnitTestOptions. Must not be called before InitGoogleTest.
781 void ConfigureXmlOutput();
782
783 #if GTEST_CAN_STREAM_RESULTS_
784 // Initializes the event listener for streaming test results to a socket.
785 // Must not be called before InitGoogleTest.
786 void ConfigureStreamingOutput();
787 #endif
788
789 // Performs initialization dependent upon flag values obtained in
790 // ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
791 // ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
792 // this function is also called from RunAllTests. Since this function can be
793 // called more than once, it has to be idempotent.
794 void PostFlagParsingInit();
795
796 // Gets the random seed used at the start of the current test iteration.
797 int random_seed() const { return random_seed_; }
798
799 // Gets the random number generator.
800 internal::Random* random() { return &random_; }
801
802 // Shuffles all test cases, and the tests within each test case,
803 // making sure that death tests are still run first.
804 void ShuffleTests();
805
806 // Restores the test cases and tests to their order before the first shuffle.
807 void UnshuffleTests();
808
809 // Returns the value of GTEST_FLAG(catch_exceptions) at the moment
810 // UnitTest::Run() starts.
811 bool catch_exceptions() const { return catch_exceptions_; }
812
813 private:
814 friend class ::testing::UnitTest;
815
816 // Used by UnitTest::Run() to capture the state of
817 // GTEST_FLAG(catch_exceptions) at the moment it starts.
818 void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
819
820 // The UnitTest object that owns this implementation object.
821 UnitTest* const parent_;
822
823 // The working directory when the first TEST() or TEST_F() was
824 // executed.
825 internal::FilePath original_working_dir_;
826
827 // The default test part result reporters.
828 DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
829 DefaultPerThreadTestPartResultReporter
830 default_per_thread_test_part_result_reporter_;
831
832 // Points to (but doesn't own) the global test part result reporter.
833 TestPartResultReporterInterface* global_test_part_result_repoter_;
834
835 // Protects read and write access to global_test_part_result_reporter_.
836 internal::Mutex global_test_part_result_reporter_mutex_;
837
838 // Points to (but doesn't own) the per-thread test part result reporter.
839 internal::ThreadLocal<TestPartResultReporterInterface*>
840 per_thread_test_part_result_reporter_;
841
842 // The vector of environments that need to be set-up/torn-down
843 // before/after the tests are run.
844 std::vector<Environment*> environments_;
845
846 // The vector of TestCases in their original order. It owns the
847 // elements in the vector.
848 std::vector<TestCase*> test_cases_;
849
850 // Provides a level of indirection for the test case list to allow
851 // easy shuffling and restoring the test case order. The i-th
852 // element of this vector is the index of the i-th test case in the
853 // shuffled order.
854 std::vector<int> test_case_indices_;
855
856 #if GTEST_HAS_PARAM_TEST
857 // ParameterizedTestRegistry object used to register value-parameterized
858 // tests.
859 internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
860
861 // Indicates whether RegisterParameterizedTests() has been called already.
862 bool parameterized_tests_registered_;
863 #endif // GTEST_HAS_PARAM_TEST
864
865 // Index of the last death test case registered. Initially -1.
866 int last_death_test_case_;
867
868 // This points to the TestCase for the currently running test. It
869 // changes as Google Test goes through one test case after another.
870 // When no test is running, this is set to NULL and Google Test
871 // stores assertion results in ad_hoc_test_result_. Initially NULL.
872 TestCase* current_test_case_;
873
874 // This points to the TestInfo for the currently running test. It
875 // changes as Google Test goes through one test after another. When
876 // no test is running, this is set to NULL and Google Test stores
877 // assertion results in ad_hoc_test_result_. Initially NULL.
878 TestInfo* current_test_info_;
879
880 // Normally, a user only writes assertions inside a TEST or TEST_F,
881 // or inside a function called by a TEST or TEST_F. Since Google
882 // Test keeps track of which test is current running, it can
883 // associate such an assertion with the test it belongs to.
884 //
885 // If an assertion is encountered when no TEST or TEST_F is running,
886 // Google Test attributes the assertion result to an imaginary "ad hoc"
887 // test, and records the result in ad_hoc_test_result_.
888 TestResult ad_hoc_test_result_;
889
890 // The list of event listeners that can be used to track events inside
891 // Google Test.
892 TestEventListeners listeners_;
893
894 // The OS stack trace getter. Will be deleted when the UnitTest
895 // object is destructed. By default, an OsStackTraceGetter is used,
896 // but the user can set this field to use a custom getter if that is
897 // desired.
898 OsStackTraceGetterInterface* os_stack_trace_getter_;
899
900 // True iff PostFlagParsingInit() has been called.
901 bool post_flag_parse_init_performed_;
902
903 // The random number seed used at the beginning of the test run.
904 int random_seed_;
905
906 // Our random number generator.
907 internal::Random random_;
908
909 // The time of the test program start, in ms from the start of the
910 // UNIX epoch.
911 TimeInMillis start_timestamp_;
912
913 // How long the test took to run, in milliseconds.
914 TimeInMillis elapsed_time_;
915
916 #if GTEST_HAS_DEATH_TEST
917 // The decomposed components of the gtest_internal_run_death_test flag,
918 // parsed when RUN_ALL_TESTS is called.
919 internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
920 internal::scoped_ptr<internal::DeathTestFactory> death_test_factory_;
921 #endif // GTEST_HAS_DEATH_TEST
922
923 // A per-thread stack of traces created by the SCOPED_TRACE() macro.
924 internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
925
926 // The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
927 // starts.
928 bool catch_exceptions_;
929
930 GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
931 }; // class UnitTestImpl
932
933 // Convenience function for accessing the global UnitTest
934 // implementation object.
935 inline UnitTestImpl* GetUnitTestImpl() {
936 return UnitTest::GetInstance()->impl();
937 }
938
939 #if GTEST_USES_SIMPLE_RE
940
941 // Internal helper functions for implementing the simple regular
942 // expression matcher.
943 GTEST_API_ bool IsInSet(char ch, const char* str);
944 GTEST_API_ bool IsAsciiDigit(char ch);
945 GTEST_API_ bool IsAsciiPunct(char ch);
946 GTEST_API_ bool IsRepeat(char ch);
947 GTEST_API_ bool IsAsciiWhiteSpace(char ch);
948 GTEST_API_ bool IsAsciiWordChar(char ch);
949 GTEST_API_ bool IsValidEscape(char ch);
950 GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
951 GTEST_API_ bool ValidateRegex(const char* regex);
952 GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
953 GTEST_API_ bool MatchRepetitionAndRegexAtHead(
954 bool escaped, char ch, char repeat, const char* regex, const char* str);
955 GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
956
957 #endif // GTEST_USES_SIMPLE_RE
958
959 // Parses the command line for Google Test flags, without initializing
960 // other parts of Google Test.
961 GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
962 GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
963
964 #if GTEST_HAS_DEATH_TEST
965
966 // Returns the message describing the last system error, regardless of the
967 // platform.
968 GTEST_API_ std::string GetLastErrnoDescription();
969
970 # if GTEST_OS_WINDOWS
971 // Provides leak-safe Windows kernel handle ownership.
972 class AutoHandle {
973 public:
974 AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
975 explicit AutoHandle(HANDLE handle) : handle_(handle) {}
976
977 ~AutoHandle() { Reset(); }
978
979 HANDLE Get() const { return handle_; }
980 void Reset() { Reset(INVALID_HANDLE_VALUE); }
981 void Reset(HANDLE handle) {
982 if (handle != handle_) {
983 if (handle_ != INVALID_HANDLE_VALUE)
984 ::CloseHandle(handle_);
985 handle_ = handle;
986 }
987 }
988
989 private:
990 HANDLE handle_;
991
992 GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
993 };
994 # endif // GTEST_OS_WINDOWS
995
996 // Attempts to parse a string into a positive integer pointed to by the
997 // number parameter. Returns true if that is possible.
998 // GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
999 // it here.
1000 template <typename Integer>
1001 bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
1002 // Fail fast if the given string does not begin with a digit;
1003 // this bypasses strtoXXX's "optional leading whitespace and plus
1004 // or minus sign" semantics, which are undesirable here.
1005 if (str.empty() || !IsDigit(str[0])) {
1006 return false;
1007 }
1008 errno = 0;
1009
1010 char* end;
1011 // BiggestConvertible is the largest integer type that system-provided
1012 // string-to-number conversion routines can return.
1013
1014 # if GTEST_OS_WINDOWS && !defined(__GNUC__)
1015
1016 // MSVC and C++ Builder define __int64 instead of the standard long long.
1017 typedef unsigned __int64 BiggestConvertible;
1018 const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
1019
1020 # else
1021
1022 typedef unsigned long long BiggestConvertible; // NOLINT
1023 const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
1024
1025 # endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
1026
1027 const bool parse_success = *end == '\0' && errno == 0;
1028
1029 // TODO(vladl@google.com): Convert this to compile time assertion when it is
1030 // available.
1031 GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
1032
1033 const Integer result = static_cast<Integer>(parsed);
1034 if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
1035 *number = result;
1036 return true;
1037 }
1038 return false;
1039 }
1040 #endif // GTEST_HAS_DEATH_TEST
1041
1042 // TestResult contains some private methods that should be hidden from
1043 // Google Test user but are required for testing. This class allow our tests
1044 // to access them.
1045 //
1046 // This class is supplied only for the purpose of testing Google Test's own
1047 // constructs. Do not use it in user tests, either directly or indirectly.
1048 class TestResultAccessor {
1049 public:
1050 static void RecordProperty(TestResult* test_result,
1051 const std::string& xml_element,
1052 const TestProperty& property) {
1053 test_result->RecordProperty(xml_element, property);
1054 }
1055
1056 static void ClearTestPartResults(TestResult* test_result) {
1057 test_result->ClearTestPartResults();
1058 }
1059
1060 static const std::vector<testing::TestPartResult>& test_part_results(
1061 const TestResult& test_result) {
1062 return test_result.test_part_results();
1063 }
1064 };
1065
1066 #if GTEST_CAN_STREAM_RESULTS_
1067
1068 // Streams test results to the given port on the given host machine.
1069 class StreamingListener : public EmptyTestEventListener {
1070 public:
1071 // Abstract base class for writing strings to a socket.
1072 class AbstractSocketWriter {
1073 public:
1074 virtual ~AbstractSocketWriter() {}
1075
1076 // Sends a string to the socket.
1077 virtual void Send(const string& message) = 0;
1078
1079 // Closes the socket.
1080 virtual void CloseConnection() {}
1081
1082 // Sends a string and a newline to the socket.
1083 void SendLn(const string& message) {
1084 Send(message + "\n");
1085 }
1086 };
1087
1088 // Concrete class for actually writing strings to a socket.
1089 class SocketWriter : public AbstractSocketWriter {
1090 public:
1091 SocketWriter(const string& host, const string& port)
1092 : sockfd_(-1), host_name_(host), port_num_(port) {
1093 MakeConnection();
1094 }
1095
1096 virtual ~SocketWriter() {
1097 if (sockfd_ != -1)
1098 CloseConnection();
1099 }
1100
1101 // Sends a string to the socket.
1102 virtual void Send(const string& message) {
1103 GTEST_CHECK_(sockfd_ != -1)
1104 << "Send() can be called only when there is a connection.";
1105
1106 const int len = static_cast<int>(message.length());
1107 if (write(sockfd_, message.c_str(), len) != len) {
1108 GTEST_LOG_(WARNING)
1109 << "stream_result_to: failed to stream to "
1110 << host_name_ << ":" << port_num_;
1111 }
1112 }
1113
1114 private:
1115 // Creates a client socket and connects to the server.
1116 void MakeConnection();
1117
1118 // Closes the socket.
1119 void CloseConnection() {
1120 GTEST_CHECK_(sockfd_ != -1)
1121 << "CloseConnection() can be called only when there is a connection.";
1122
1123 close(sockfd_);
1124 sockfd_ = -1;
1125 }
1126
1127 int sockfd_; // socket file descriptor
1128 const string host_name_;
1129 const string port_num_;
1130
1131 GTEST_DISALLOW_COPY_AND_ASSIGN_(SocketWriter);
1132 }; // class SocketWriter
1133
1134 // Escapes '=', '&', '%', and '\n' characters in str as "%xx".
1135 static string UrlEncode(const char* str);
1136
1137 StreamingListener(const string& host, const string& port)
1138 : socket_writer_(new SocketWriter(host, port)) { Start(); }
1139
1140 explicit StreamingListener(AbstractSocketWriter* socket_writer)
1141 : socket_writer_(socket_writer) { Start(); }
1142
1143 void OnTestProgramStart(const UnitTest& /* unit_test */) {
1144 SendLn("event=TestProgramStart");
1145 }
1146
1147 void OnTestProgramEnd(const UnitTest& unit_test) {
1148 // Note that Google Test current only report elapsed time for each
1149 // test iteration, not for the entire test program.
1150 SendLn("event=TestProgramEnd&passed=" + FormatBool(unit_test.Passed()));
1151
1152 // Notify the streaming server to stop.
1153 socket_writer_->CloseConnection();
1154 }
1155
1156 void OnTestIterationStart(const UnitTest& /* unit_test */, int iteration) {
1157 SendLn("event=TestIterationStart&iteration=" +
1158 StreamableToString(iteration));
1159 }
1160
1161 void OnTestIterationEnd(const UnitTest& unit_test, int /* iteration */) {
1162 SendLn("event=TestIterationEnd&passed=" +
1163 FormatBool(unit_test.Passed()) + "&elapsed_time=" +
1164 StreamableToString(unit_test.elapsed_time()) + "ms");
1165 }
1166
1167 void OnTestCaseStart(const TestCase& test_case) {
1168 SendLn(std::string("event=TestCaseStart&name=") + test_case.name());
1169 }
1170
1171 void OnTestCaseEnd(const TestCase& test_case) {
1172 SendLn("event=TestCaseEnd&passed=" + FormatBool(test_case.Passed())
1173 + "&elapsed_time=" + StreamableToString(test_case.elapsed_time())
1174 + "ms");
1175 }
1176
1177 void OnTestStart(const TestInfo& test_info) {
1178 SendLn(std::string("event=TestStart&name=") + test_info.name());
1179 }
1180
1181 void OnTestEnd(const TestInfo& test_info) {
1182 SendLn("event=TestEnd&passed=" +
1183 FormatBool((test_info.result())->Passed()) +
1184 "&elapsed_time=" +
1185 StreamableToString((test_info.result())->elapsed_time()) + "ms");
1186 }
1187
1188 void OnTestPartResult(const TestPartResult& test_part_result) {
1189 const char* file_name = test_part_result.file_name();
1190 if (file_name == NULL)
1191 file_name = "";
1192 SendLn("event=TestPartResult&file=" + UrlEncode(file_name) +
1193 "&line=" + StreamableToString(test_part_result.line_number()) +
1194 "&message=" + UrlEncode(test_part_result.message()));
1195 }
1196
1197 private:
1198 // Sends the given message and a newline to the socket.
1199 void SendLn(const string& message) { socket_writer_->SendLn(message); }
1200
1201 // Called at the start of streaming to notify the receiver what
1202 // protocol we are using.
1203 void Start() { SendLn("gtest_streaming_protocol_version=1.0"); }
1204
1205 string FormatBool(bool value) { return value ? "1" : "0"; }
1206
1207 const scoped_ptr<AbstractSocketWriter> socket_writer_;
1208
1209 GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);
1210 }; // class StreamingListener
1211
1212 #endif // GTEST_CAN_STREAM_RESULTS_
1213
1214 } // namespace internal
1215 } // namespace testing
1216
1217 #endif // GTEST_SRC_GTEST_INTERNAL_INL_H_
0 // Copyright 2008, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30
31 #include "gtest/internal/gtest-port.h"
32
33 #include <limits.h>
34 #include <stdlib.h>
35 #include <stdio.h>
36 #include <string.h>
37
38 #if GTEST_OS_WINDOWS_MOBILE
39 # include <windows.h> // For TerminateProcess()
40 #elif GTEST_OS_WINDOWS
41 # include <io.h>
42 # include <sys/stat.h>
43 #else
44 # include <unistd.h>
45 #endif // GTEST_OS_WINDOWS_MOBILE
46
47 #if GTEST_OS_MAC
48 # include <mach/mach_init.h>
49 # include <mach/task.h>
50 # include <mach/vm_map.h>
51 #endif // GTEST_OS_MAC
52
53 #if GTEST_OS_QNX
54 # include <devctl.h>
55 # include <sys/procfs.h>
56 #endif // GTEST_OS_QNX
57
58 #include "gtest/gtest-spi.h"
59 #include "gtest/gtest-message.h"
60 #include "gtest/internal/gtest-internal.h"
61 #include "gtest/internal/gtest-string.h"
62
63 // Indicates that this translation unit is part of Google Test's
64 // implementation. It must come before gtest-internal-inl.h is
65 // included, or there will be a compiler error. This trick is to
66 // prevent a user from accidentally including gtest-internal-inl.h in
67 // his code.
68 #define GTEST_IMPLEMENTATION_ 1
69 #include "src/gtest-internal-inl.h"
70 #undef GTEST_IMPLEMENTATION_
71
72 namespace testing {
73 namespace internal {
74
75 #if defined(_MSC_VER) || defined(__BORLANDC__)
76 // MSVC and C++Builder do not provide a definition of STDERR_FILENO.
77 const int kStdOutFileno = 1;
78 const int kStdErrFileno = 2;
79 #else
80 const int kStdOutFileno = STDOUT_FILENO;
81 const int kStdErrFileno = STDERR_FILENO;
82 #endif // _MSC_VER
83
84 #if GTEST_OS_MAC
85
86 // Returns the number of threads running in the process, or 0 to indicate that
87 // we cannot detect it.
88 size_t GetThreadCount() {
89 const task_t task = mach_task_self();
90 mach_msg_type_number_t thread_count;
91 thread_act_array_t thread_list;
92 const kern_return_t status = task_threads(task, &thread_list, &thread_count);
93 if (status == KERN_SUCCESS) {
94 // task_threads allocates resources in thread_list and we need to free them
95 // to avoid leaks.
96 vm_deallocate(task,
97 reinterpret_cast<vm_address_t>(thread_list),
98 sizeof(thread_t) * thread_count);
99 return static_cast<size_t>(thread_count);
100 } else {
101 return 0;
102 }
103 }
104
105 #elif GTEST_OS_QNX
106
107 // Returns the number of threads running in the process, or 0 to indicate that
108 // we cannot detect it.
109 size_t GetThreadCount() {
110 const int fd = open("/proc/self/as", O_RDONLY);
111 if (fd < 0) {
112 return 0;
113 }
114 procfs_info process_info;
115 const int status =
116 devctl(fd, DCMD_PROC_INFO, &process_info, sizeof(process_info), NULL);
117 close(fd);
118 if (status == EOK) {
119 return static_cast<size_t>(process_info.num_threads);
120 } else {
121 return 0;
122 }
123 }
124
125 #else
126
127 size_t GetThreadCount() {
128 // There's no portable way to detect the number of threads, so we just
129 // return 0 to indicate that we cannot detect it.
130 return 0;
131 }
132
133 #endif // GTEST_OS_MAC
134
135 #if GTEST_USES_POSIX_RE
136
137 // Implements RE. Currently only needed for death tests.
138
139 RE::~RE() {
140 if (is_valid_) {
141 // regfree'ing an invalid regex might crash because the content
142 // of the regex is undefined. Since the regex's are essentially
143 // the same, one cannot be valid (or invalid) without the other
144 // being so too.
145 regfree(&partial_regex_);
146 regfree(&full_regex_);
147 }
148 free(const_cast<char*>(pattern_));
149 }
150
151 // Returns true iff regular expression re matches the entire str.
152 bool RE::FullMatch(const char* str, const RE& re) {
153 if (!re.is_valid_) return false;
154
155 regmatch_t match;
156 return regexec(&re.full_regex_, str, 1, &match, 0) == 0;
157 }
158
159 // Returns true iff regular expression re matches a substring of str
160 // (including str itself).
161 bool RE::PartialMatch(const char* str, const RE& re) {
162 if (!re.is_valid_) return false;
163
164 regmatch_t match;
165 return regexec(&re.partial_regex_, str, 1, &match, 0) == 0;
166 }
167
168 // Initializes an RE from its string representation.
169 void RE::Init(const char* regex) {
170 pattern_ = posix::StrDup(regex);
171
172 // Reserves enough bytes to hold the regular expression used for a
173 // full match.
174 const size_t full_regex_len = strlen(regex) + 10;
175 char* const full_pattern = new char[full_regex_len];
176
177 snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
178 is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0;
179 // We want to call regcomp(&partial_regex_, ...) even if the
180 // previous expression returns false. Otherwise partial_regex_ may
181 // not be properly initialized can may cause trouble when it's
182 // freed.
183 //
184 // Some implementation of POSIX regex (e.g. on at least some
185 // versions of Cygwin) doesn't accept the empty string as a valid
186 // regex. We change it to an equivalent form "()" to be safe.
187 if (is_valid_) {
188 const char* const partial_regex = (*regex == '\0') ? "()" : regex;
189 is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0;
190 }
191 EXPECT_TRUE(is_valid_)
192 << "Regular expression \"" << regex
193 << "\" is not a valid POSIX Extended regular expression.";
194
195 delete[] full_pattern;
196 }
197
198 #elif GTEST_USES_SIMPLE_RE
199
200 // Returns true iff ch appears anywhere in str (excluding the
201 // terminating '\0' character).
202 bool IsInSet(char ch, const char* str) {
203 return ch != '\0' && strchr(str, ch) != NULL;
204 }
205
206 // Returns true iff ch belongs to the given classification. Unlike
207 // similar functions in <ctype.h>, these aren't affected by the
208 // current locale.
209 bool IsAsciiDigit(char ch) { return '0' <= ch && ch <= '9'; }
210 bool IsAsciiPunct(char ch) {
211 return IsInSet(ch, "^-!\"#$%&'()*+,./:;<=>?@[\\]_`{|}~");
212 }
213 bool IsRepeat(char ch) { return IsInSet(ch, "?*+"); }
214 bool IsAsciiWhiteSpace(char ch) { return IsInSet(ch, " \f\n\r\t\v"); }
215 bool IsAsciiWordChar(char ch) {
216 return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') ||
217 ('0' <= ch && ch <= '9') || ch == '_';
218 }
219
220 // Returns true iff "\\c" is a supported escape sequence.
221 bool IsValidEscape(char c) {
222 return (IsAsciiPunct(c) || IsInSet(c, "dDfnrsStvwW"));
223 }
224
225 // Returns true iff the given atom (specified by escaped and pattern)
226 // matches ch. The result is undefined if the atom is invalid.
227 bool AtomMatchesChar(bool escaped, char pattern_char, char ch) {
228 if (escaped) { // "\\p" where p is pattern_char.
229 switch (pattern_char) {
230 case 'd': return IsAsciiDigit(ch);
231 case 'D': return !IsAsciiDigit(ch);
232 case 'f': return ch == '\f';
233 case 'n': return ch == '\n';
234 case 'r': return ch == '\r';
235 case 's': return IsAsciiWhiteSpace(ch);
236 case 'S': return !IsAsciiWhiteSpace(ch);
237 case 't': return ch == '\t';
238 case 'v': return ch == '\v';
239 case 'w': return IsAsciiWordChar(ch);
240 case 'W': return !IsAsciiWordChar(ch);
241 }
242 return IsAsciiPunct(pattern_char) && pattern_char == ch;
243 }
244
245 return (pattern_char == '.' && ch != '\n') || pattern_char == ch;
246 }
247
248 // Helper function used by ValidateRegex() to format error messages.
249 std::string FormatRegexSyntaxError(const char* regex, int index) {
250 return (Message() << "Syntax error at index " << index
251 << " in simple regular expression \"" << regex << "\": ").GetString();
252 }
253
254 // Generates non-fatal failures and returns false if regex is invalid;
255 // otherwise returns true.
256 bool ValidateRegex(const char* regex) {
257 if (regex == NULL) {
258 // TODO(wan@google.com): fix the source file location in the
259 // assertion failures to match where the regex is used in user
260 // code.
261 ADD_FAILURE() << "NULL is not a valid simple regular expression.";
262 return false;
263 }
264
265 bool is_valid = true;
266
267 // True iff ?, *, or + can follow the previous atom.
268 bool prev_repeatable = false;
269 for (int i = 0; regex[i]; i++) {
270 if (regex[i] == '\\') { // An escape sequence
271 i++;
272 if (regex[i] == '\0') {
273 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
274 << "'\\' cannot appear at the end.";
275 return false;
276 }
277
278 if (!IsValidEscape(regex[i])) {
279 ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
280 << "invalid escape sequence \"\\" << regex[i] << "\".";
281 is_valid = false;
282 }
283 prev_repeatable = true;
284 } else { // Not an escape sequence.
285 const char ch = regex[i];
286
287 if (ch == '^' && i > 0) {
288 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
289 << "'^' can only appear at the beginning.";
290 is_valid = false;
291 } else if (ch == '$' && regex[i + 1] != '\0') {
292 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
293 << "'$' can only appear at the end.";
294 is_valid = false;
295 } else if (IsInSet(ch, "()[]{}|")) {
296 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
297 << "'" << ch << "' is unsupported.";
298 is_valid = false;
299 } else if (IsRepeat(ch) && !prev_repeatable) {
300 ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
301 << "'" << ch << "' can only follow a repeatable token.";
302 is_valid = false;
303 }
304
305 prev_repeatable = !IsInSet(ch, "^$?*+");
306 }
307 }
308
309 return is_valid;
310 }
311
312 // Matches a repeated regex atom followed by a valid simple regular
313 // expression. The regex atom is defined as c if escaped is false,
314 // or \c otherwise. repeat is the repetition meta character (?, *,
315 // or +). The behavior is undefined if str contains too many
316 // characters to be indexable by size_t, in which case the test will
317 // probably time out anyway. We are fine with this limitation as
318 // std::string has it too.
319 bool MatchRepetitionAndRegexAtHead(
320 bool escaped, char c, char repeat, const char* regex,
321 const char* str) {
322 const size_t min_count = (repeat == '+') ? 1 : 0;
323 const size_t max_count = (repeat == '?') ? 1 :
324 static_cast<size_t>(-1) - 1;
325 // We cannot call numeric_limits::max() as it conflicts with the
326 // max() macro on Windows.
327
328 for (size_t i = 0; i <= max_count; ++i) {
329 // We know that the atom matches each of the first i characters in str.
330 if (i >= min_count && MatchRegexAtHead(regex, str + i)) {
331 // We have enough matches at the head, and the tail matches too.
332 // Since we only care about *whether* the pattern matches str
333 // (as opposed to *how* it matches), there is no need to find a
334 // greedy match.
335 return true;
336 }
337 if (str[i] == '\0' || !AtomMatchesChar(escaped, c, str[i]))
338 return false;
339 }
340 return false;
341 }
342
343 // Returns true iff regex matches a prefix of str. regex must be a
344 // valid simple regular expression and not start with "^", or the
345 // result is undefined.
346 bool MatchRegexAtHead(const char* regex, const char* str) {
347 if (*regex == '\0') // An empty regex matches a prefix of anything.
348 return true;
349
350 // "$" only matches the end of a string. Note that regex being
351 // valid guarantees that there's nothing after "$" in it.
352 if (*regex == '$')
353 return *str == '\0';
354
355 // Is the first thing in regex an escape sequence?
356 const bool escaped = *regex == '\\';
357 if (escaped)
358 ++regex;
359 if (IsRepeat(regex[1])) {
360 // MatchRepetitionAndRegexAtHead() calls MatchRegexAtHead(), so
361 // here's an indirect recursion. It terminates as the regex gets
362 // shorter in each recursion.
363 return MatchRepetitionAndRegexAtHead(
364 escaped, regex[0], regex[1], regex + 2, str);
365 } else {
366 // regex isn't empty, isn't "$", and doesn't start with a
367 // repetition. We match the first atom of regex with the first
368 // character of str and recurse.
369 return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) &&
370 MatchRegexAtHead(regex + 1, str + 1);
371 }
372 }
373
374 // Returns true iff regex matches any substring of str. regex must be
375 // a valid simple regular expression, or the result is undefined.
376 //
377 // The algorithm is recursive, but the recursion depth doesn't exceed
378 // the regex length, so we won't need to worry about running out of
379 // stack space normally. In rare cases the time complexity can be
380 // exponential with respect to the regex length + the string length,
381 // but usually it's must faster (often close to linear).
382 bool MatchRegexAnywhere(const char* regex, const char* str) {
383 if (regex == NULL || str == NULL)
384 return false;
385
386 if (*regex == '^')
387 return MatchRegexAtHead(regex + 1, str);
388
389 // A successful match can be anywhere in str.
390 do {
391 if (MatchRegexAtHead(regex, str))
392 return true;
393 } while (*str++ != '\0');
394 return false;
395 }
396
397 // Implements the RE class.
398
399 RE::~RE() {
400 free(const_cast<char*>(pattern_));
401 free(const_cast<char*>(full_pattern_));
402 }
403
404 // Returns true iff regular expression re matches the entire str.
405 bool RE::FullMatch(const char* str, const RE& re) {
406 return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_, str);
407 }
408
409 // Returns true iff regular expression re matches a substring of str
410 // (including str itself).
411 bool RE::PartialMatch(const char* str, const RE& re) {
412 return re.is_valid_ && MatchRegexAnywhere(re.pattern_, str);
413 }
414
415 // Initializes an RE from its string representation.
416 void RE::Init(const char* regex) {
417 pattern_ = full_pattern_ = NULL;
418 if (regex != NULL) {
419 pattern_ = posix::StrDup(regex);
420 }
421
422 is_valid_ = ValidateRegex(regex);
423 if (!is_valid_) {
424 // No need to calculate the full pattern when the regex is invalid.
425 return;
426 }
427
428 const size_t len = strlen(regex);
429 // Reserves enough bytes to hold the regular expression used for a
430 // full match: we need space to prepend a '^', append a '$', and
431 // terminate the string with '\0'.
432 char* buffer = static_cast<char*>(malloc(len + 3));
433 full_pattern_ = buffer;
434
435 if (*regex != '^')
436 *buffer++ = '^'; // Makes sure full_pattern_ starts with '^'.
437
438 // We don't use snprintf or strncpy, as they trigger a warning when
439 // compiled with VC++ 8.0.
440 memcpy(buffer, regex, len);
441 buffer += len;
442
443 if (len == 0 || regex[len - 1] != '$')
444 *buffer++ = '$'; // Makes sure full_pattern_ ends with '$'.
445
446 *buffer = '\0';
447 }
448
449 #endif // GTEST_USES_POSIX_RE
450
451 const char kUnknownFile[] = "unknown file";
452
453 // Formats a source file path and a line number as they would appear
454 // in an error message from the compiler used to compile this code.
455 GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {
456 const std::string file_name(file == NULL ? kUnknownFile : file);
457
458 if (line < 0) {
459 return file_name + ":";
460 }
461 #ifdef _MSC_VER
462 return file_name + "(" + StreamableToString(line) + "):";
463 #else
464 return file_name + ":" + StreamableToString(line) + ":";
465 #endif // _MSC_VER
466 }
467
468 // Formats a file location for compiler-independent XML output.
469 // Although this function is not platform dependent, we put it next to
470 // FormatFileLocation in order to contrast the two functions.
471 // Note that FormatCompilerIndependentFileLocation() does NOT append colon
472 // to the file location it produces, unlike FormatFileLocation().
473 GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(
474 const char* file, int line) {
475 const std::string file_name(file == NULL ? kUnknownFile : file);
476
477 if (line < 0)
478 return file_name;
479 else
480 return file_name + ":" + StreamableToString(line);
481 }
482
483
484 GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line)
485 : severity_(severity) {
486 const char* const marker =
487 severity == GTEST_INFO ? "[ INFO ]" :
488 severity == GTEST_WARNING ? "[WARNING]" :
489 severity == GTEST_ERROR ? "[ ERROR ]" : "[ FATAL ]";
490 GetStream() << ::std::endl << marker << " "
491 << FormatFileLocation(file, line).c_str() << ": ";
492 }
493
494 // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
495 GTestLog::~GTestLog() {
496 GetStream() << ::std::endl;
497 if (severity_ == GTEST_FATAL) {
498 fflush(stderr);
499 posix::Abort();
500 }
501 }
502 // Disable Microsoft deprecation warnings for POSIX functions called from
503 // this class (creat, dup, dup2, and close)
504 #ifdef _MSC_VER
505 # pragma warning(push)
506 # pragma warning(disable: 4996)
507 #endif // _MSC_VER
508
509 #if GTEST_HAS_STREAM_REDIRECTION
510
511 // Object that captures an output stream (stdout/stderr).
512 class CapturedStream {
513 public:
514 // The ctor redirects the stream to a temporary file.
515 explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
516 # if GTEST_OS_WINDOWS
517 char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT
518 char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT
519
520 ::GetTempPathA(sizeof(temp_dir_path), temp_dir_path);
521 const UINT success = ::GetTempFileNameA(temp_dir_path,
522 "gtest_redir",
523 0, // Generate unique file name.
524 temp_file_path);
525 GTEST_CHECK_(success != 0)
526 << "Unable to create a temporary file in " << temp_dir_path;
527 const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE);
528 GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file "
529 << temp_file_path;
530 filename_ = temp_file_path;
531 # else
532 // There's no guarantee that a test has write access to the current
533 // directory, so we create the temporary file in the /tmp directory
534 // instead. We use /tmp on most systems, and /sdcard on Android.
535 // That's because Android doesn't have /tmp.
536 # if GTEST_OS_LINUX_ANDROID
537 // Note: Android applications are expected to call the framework's
538 // Context.getExternalStorageDirectory() method through JNI to get
539 // the location of the world-writable SD Card directory. However,
540 // this requires a Context handle, which cannot be retrieved
541 // globally from native code. Doing so also precludes running the
542 // code as part of a regular standalone executable, which doesn't
543 // run in a Dalvik process (e.g. when running it through 'adb shell').
544 //
545 // The location /sdcard is directly accessible from native code
546 // and is the only location (unofficially) supported by the Android
547 // team. It's generally a symlink to the real SD Card mount point
548 // which can be /mnt/sdcard, /mnt/sdcard0, /system/media/sdcard, or
549 // other OEM-customized locations. Never rely on these, and always
550 // use /sdcard.
551 char name_template[] = "/sdcard/gtest_captured_stream.XXXXXX";
552 # else
553 char name_template[] = "/tmp/captured_stream.XXXXXX";
554 # endif // GTEST_OS_LINUX_ANDROID
555 const int captured_fd = mkstemp(name_template);
556 filename_ = name_template;
557 # endif // GTEST_OS_WINDOWS
558 fflush(NULL);
559 dup2(captured_fd, fd_);
560 close(captured_fd);
561 }
562
563 ~CapturedStream() {
564 remove(filename_.c_str());
565 }
566
567 std::string GetCapturedString() {
568 if (uncaptured_fd_ != -1) {
569 // Restores the original stream.
570 fflush(NULL);
571 dup2(uncaptured_fd_, fd_);
572 close(uncaptured_fd_);
573 uncaptured_fd_ = -1;
574 }
575
576 FILE* const file = posix::FOpen(filename_.c_str(), "r");
577 const std::string content = ReadEntireFile(file);
578 posix::FClose(file);
579 return content;
580 }
581
582 private:
583 // Reads the entire content of a file as an std::string.
584 static std::string ReadEntireFile(FILE* file);
585
586 // Returns the size (in bytes) of a file.
587 static size_t GetFileSize(FILE* file);
588
589 const int fd_; // A stream to capture.
590 int uncaptured_fd_;
591 // Name of the temporary file holding the stderr output.
592 ::std::string filename_;
593
594 GTEST_DISALLOW_COPY_AND_ASSIGN_(CapturedStream);
595 };
596
597 // Returns the size (in bytes) of a file.
598 size_t CapturedStream::GetFileSize(FILE* file) {
599 fseek(file, 0, SEEK_END);
600 return static_cast<size_t>(ftell(file));
601 }
602
603 // Reads the entire content of a file as a string.
604 std::string CapturedStream::ReadEntireFile(FILE* file) {
605 const size_t file_size = GetFileSize(file);
606 char* const buffer = new char[file_size];
607
608 size_t bytes_last_read = 0; // # of bytes read in the last fread()
609 size_t bytes_read = 0; // # of bytes read so far
610
611 fseek(file, 0, SEEK_SET);
612
613 // Keeps reading the file until we cannot read further or the
614 // pre-determined file size is reached.
615 do {
616 bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file);
617 bytes_read += bytes_last_read;
618 } while (bytes_last_read > 0 && bytes_read < file_size);
619
620 const std::string content(buffer, bytes_read);
621 delete[] buffer;
622
623 return content;
624 }
625
626 # ifdef _MSC_VER
627 # pragma warning(pop)
628 # endif // _MSC_VER
629
630 static CapturedStream* g_captured_stderr = NULL;
631 static CapturedStream* g_captured_stdout = NULL;
632
633 // Starts capturing an output stream (stdout/stderr).
634 void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) {
635 if (*stream != NULL) {
636 GTEST_LOG_(FATAL) << "Only one " << stream_name
637 << " capturer can exist at a time.";
638 }
639 *stream = new CapturedStream(fd);
640 }
641
642 // Stops capturing the output stream and returns the captured string.
643 std::string GetCapturedStream(CapturedStream** captured_stream) {
644 const std::string content = (*captured_stream)->GetCapturedString();
645
646 delete *captured_stream;
647 *captured_stream = NULL;
648
649 return content;
650 }
651
652 // Starts capturing stdout.
653 void CaptureStdout() {
654 CaptureStream(kStdOutFileno, "stdout", &g_captured_stdout);
655 }
656
657 // Starts capturing stderr.
658 void CaptureStderr() {
659 CaptureStream(kStdErrFileno, "stderr", &g_captured_stderr);
660 }
661
662 // Stops capturing stdout and returns the captured string.
663 std::string GetCapturedStdout() {
664 return GetCapturedStream(&g_captured_stdout);
665 }
666
667 // Stops capturing stderr and returns the captured string.
668 std::string GetCapturedStderr() {
669 return GetCapturedStream(&g_captured_stderr);
670 }
671
672 #endif // GTEST_HAS_STREAM_REDIRECTION
673
674 #if GTEST_HAS_DEATH_TEST
675
676 // A copy of all command line arguments. Set by InitGoogleTest().
677 ::std::vector<testing::internal::string> g_argvs;
678
679 static const ::std::vector<testing::internal::string>* g_injected_test_argvs =
680 NULL; // Owned.
681
682 void SetInjectableArgvs(const ::std::vector<testing::internal::string>* argvs) {
683 if (g_injected_test_argvs != argvs)
684 delete g_injected_test_argvs;
685 g_injected_test_argvs = argvs;
686 }
687
688 const ::std::vector<testing::internal::string>& GetInjectableArgvs() {
689 if (g_injected_test_argvs != NULL) {
690 return *g_injected_test_argvs;
691 }
692 return g_argvs;
693 }
694 #endif // GTEST_HAS_DEATH_TEST
695
696 #if GTEST_OS_WINDOWS_MOBILE
697 namespace posix {
698 void Abort() {
699 DebugBreak();
700 TerminateProcess(GetCurrentProcess(), 1);
701 }
702 } // namespace posix
703 #endif // GTEST_OS_WINDOWS_MOBILE
704
705 // Returns the name of the environment variable corresponding to the
706 // given flag. For example, FlagToEnvVar("foo") will return
707 // "GTEST_FOO" in the open-source version.
708 static std::string FlagToEnvVar(const char* flag) {
709 const std::string full_flag =
710 (Message() << GTEST_FLAG_PREFIX_ << flag).GetString();
711
712 Message env_var;
713 for (size_t i = 0; i != full_flag.length(); i++) {
714 env_var << ToUpper(full_flag.c_str()[i]);
715 }
716
717 return env_var.GetString();
718 }
719
720 // Parses 'str' for a 32-bit signed integer. If successful, writes
721 // the result to *value and returns true; otherwise leaves *value
722 // unchanged and returns false.
723 bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
724 // Parses the environment variable as a decimal integer.
725 char* end = NULL;
726 const long long_value = strtol(str, &end, 10); // NOLINT
727
728 // Has strtol() consumed all characters in the string?
729 if (*end != '\0') {
730 // No - an invalid character was encountered.
731 Message msg;
732 msg << "WARNING: " << src_text
733 << " is expected to be a 32-bit integer, but actually"
734 << " has value \"" << str << "\".\n";
735 printf("%s", msg.GetString().c_str());
736 fflush(stdout);
737 return false;
738 }
739
740 // Is the parsed value in the range of an Int32?
741 const Int32 result = static_cast<Int32>(long_value);
742 if (long_value == LONG_MAX || long_value == LONG_MIN ||
743 // The parsed value overflows as a long. (strtol() returns
744 // LONG_MAX or LONG_MIN when the input overflows.)
745 result != long_value
746 // The parsed value overflows as an Int32.
747 ) {
748 Message msg;
749 msg << "WARNING: " << src_text
750 << " is expected to be a 32-bit integer, but actually"
751 << " has value " << str << ", which overflows.\n";
752 printf("%s", msg.GetString().c_str());
753 fflush(stdout);
754 return false;
755 }
756
757 *value = result;
758 return true;
759 }
760
761 // Reads and returns the Boolean environment variable corresponding to
762 // the given flag; if it's not set, returns default_value.
763 //
764 // The value is considered true iff it's not "0".
765 bool BoolFromGTestEnv(const char* flag, bool default_value) {
766 const std::string env_var = FlagToEnvVar(flag);
767 const char* const string_value = posix::GetEnv(env_var.c_str());
768 return string_value == NULL ?
769 default_value : strcmp(string_value, "0") != 0;
770 }
771
772 // Reads and returns a 32-bit integer stored in the environment
773 // variable corresponding to the given flag; if it isn't set or
774 // doesn't represent a valid 32-bit integer, returns default_value.
775 Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
776 const std::string env_var = FlagToEnvVar(flag);
777 const char* const string_value = posix::GetEnv(env_var.c_str());
778 if (string_value == NULL) {
779 // The environment variable is not set.
780 return default_value;
781 }
782
783 Int32 result = default_value;
784 if (!ParseInt32(Message() << "Environment variable " << env_var,
785 string_value, &result)) {
786 printf("The default value %s is used.\n",
787 (Message() << default_value).GetString().c_str());
788 fflush(stdout);
789 return default_value;
790 }
791
792 return result;
793 }
794
795 // Reads and returns the string environment variable corresponding to
796 // the given flag; if it's not set, returns default_value.
797 const char* StringFromGTestEnv(const char* flag, const char* default_value) {
798 const std::string env_var = FlagToEnvVar(flag);
799 const char* const value = posix::GetEnv(env_var.c_str());
800 return value == NULL ? default_value : value;
801 }
802
803 } // namespace internal
804 } // namespace testing
0 // Copyright 2007, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30
31 // Google Test - The Google C++ Testing Framework
32 //
33 // This file implements a universal value printer that can print a
34 // value of any type T:
35 //
36 // void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
37 //
38 // It uses the << operator when possible, and prints the bytes in the
39 // object otherwise. A user can override its behavior for a class
40 // type Foo by defining either operator<<(::std::ostream&, const Foo&)
41 // or void PrintTo(const Foo&, ::std::ostream*) in the namespace that
42 // defines Foo.
43
44 #include "gtest/gtest-printers.h"
45 #include <ctype.h>
46 #include <stdio.h>
47 #include <ostream> // NOLINT
48 #include <string>
49 #include "gtest/internal/gtest-port.h"
50
51 namespace testing {
52
53 namespace {
54
55 using ::std::ostream;
56
57 // Prints a segment of bytes in the given object.
58 void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
59 size_t count, ostream* os) {
60 char text[5] = "";
61 for (size_t i = 0; i != count; i++) {
62 const size_t j = start + i;
63 if (i != 0) {
64 // Organizes the bytes into groups of 2 for easy parsing by
65 // human.
66 if ((j % 2) == 0)
67 *os << ' ';
68 else
69 *os << '-';
70 }
71 GTEST_SNPRINTF_(text, sizeof(text), "%02X", obj_bytes[j]);
72 *os << text;
73 }
74 }
75
76 // Prints the bytes in the given value to the given ostream.
77 void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,
78 ostream* os) {
79 // Tells the user how big the object is.
80 *os << count << "-byte object <";
81
82 const size_t kThreshold = 132;
83 const size_t kChunkSize = 64;
84 // If the object size is bigger than kThreshold, we'll have to omit
85 // some details by printing only the first and the last kChunkSize
86 // bytes.
87 // TODO(wan): let the user control the threshold using a flag.
88 if (count < kThreshold) {
89 PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
90 } else {
91 PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);
92 *os << " ... ";
93 // Rounds up to 2-byte boundary.
94 const size_t resume_pos = (count - kChunkSize + 1)/2*2;
95 PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os);
96 }
97 *os << ">";
98 }
99
100 } // namespace
101
102 namespace internal2 {
103
104 // Delegates to PrintBytesInObjectToImpl() to print the bytes in the
105 // given object. The delegation simplifies the implementation, which
106 // uses the << operator and thus is easier done outside of the
107 // ::testing::internal namespace, which contains a << operator that
108 // sometimes conflicts with the one in STL.
109 void PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count,
110 ostream* os) {
111 PrintBytesInObjectToImpl(obj_bytes, count, os);
112 }
113
114 } // namespace internal2
115
116 namespace internal {
117
118 // Depending on the value of a char (or wchar_t), we print it in one
119 // of three formats:
120 // - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
121 // - as a hexidecimal escape sequence (e.g. '\x7F'), or
122 // - as a special escape sequence (e.g. '\r', '\n').
123 enum CharFormat {
124 kAsIs,
125 kHexEscape,
126 kSpecialEscape
127 };
128
129 // Returns true if c is a printable ASCII character. We test the
130 // value of c directly instead of calling isprint(), which is buggy on
131 // Windows Mobile.
132 inline bool IsPrintableAscii(wchar_t c) {
133 return 0x20 <= c && c <= 0x7E;
134 }
135
136 // Prints a wide or narrow char c as a character literal without the
137 // quotes, escaping it when necessary; returns how c was formatted.
138 // The template argument UnsignedChar is the unsigned version of Char,
139 // which is the type of c.
140 template <typename UnsignedChar, typename Char>
141 static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {
142 switch (static_cast<wchar_t>(c)) {
143 case L'\0':
144 *os << "\\0";
145 break;
146 case L'\'':
147 *os << "\\'";
148 break;
149 case L'\\':
150 *os << "\\\\";
151 break;
152 case L'\a':
153 *os << "\\a";
154 break;
155 case L'\b':
156 *os << "\\b";
157 break;
158 case L'\f':
159 *os << "\\f";
160 break;
161 case L'\n':
162 *os << "\\n";
163 break;
164 case L'\r':
165 *os << "\\r";
166 break;
167 case L'\t':
168 *os << "\\t";
169 break;
170 case L'\v':
171 *os << "\\v";
172 break;
173 default:
174 if (IsPrintableAscii(c)) {
175 *os << static_cast<char>(c);
176 return kAsIs;
177 } else {
178 *os << "\\x" + String::FormatHexInt(static_cast<UnsignedChar>(c));
179 return kHexEscape;
180 }
181 }
182 return kSpecialEscape;
183 }
184
185 // Prints a wchar_t c as if it's part of a string literal, escaping it when
186 // necessary; returns how c was formatted.
187 static CharFormat PrintAsStringLiteralTo(wchar_t c, ostream* os) {
188 switch (c) {
189 case L'\'':
190 *os << "'";
191 return kAsIs;
192 case L'"':
193 *os << "\\\"";
194 return kSpecialEscape;
195 default:
196 return PrintAsCharLiteralTo<wchar_t>(c, os);
197 }
198 }
199
200 // Prints a char c as if it's part of a string literal, escaping it when
201 // necessary; returns how c was formatted.
202 static CharFormat PrintAsStringLiteralTo(char c, ostream* os) {
203 return PrintAsStringLiteralTo(
204 static_cast<wchar_t>(static_cast<unsigned char>(c)), os);
205 }
206
207 // Prints a wide or narrow character c and its code. '\0' is printed
208 // as "'\\0'", other unprintable characters are also properly escaped
209 // using the standard C++ escape sequence. The template argument
210 // UnsignedChar is the unsigned version of Char, which is the type of c.
211 template <typename UnsignedChar, typename Char>
212 void PrintCharAndCodeTo(Char c, ostream* os) {
213 // First, print c as a literal in the most readable form we can find.
214 *os << ((sizeof(c) > 1) ? "L'" : "'");
215 const CharFormat format = PrintAsCharLiteralTo<UnsignedChar>(c, os);
216 *os << "'";
217
218 // To aid user debugging, we also print c's code in decimal, unless
219 // it's 0 (in which case c was printed as '\\0', making the code
220 // obvious).
221 if (c == 0)
222 return;
223 *os << " (" << static_cast<int>(c);
224
225 // For more convenience, we print c's code again in hexidecimal,
226 // unless c was already printed in the form '\x##' or the code is in
227 // [1, 9].
228 if (format == kHexEscape || (1 <= c && c <= 9)) {
229 // Do nothing.
230 } else {
231 *os << ", 0x" << String::FormatHexInt(static_cast<UnsignedChar>(c));
232 }
233 *os << ")";
234 }
235
236 void PrintTo(unsigned char c, ::std::ostream* os) {
237 PrintCharAndCodeTo<unsigned char>(c, os);
238 }
239 void PrintTo(signed char c, ::std::ostream* os) {
240 PrintCharAndCodeTo<unsigned char>(c, os);
241 }
242
243 // Prints a wchar_t as a symbol if it is printable or as its internal
244 // code otherwise and also as its code. L'\0' is printed as "L'\\0'".
245 void PrintTo(wchar_t wc, ostream* os) {
246 PrintCharAndCodeTo<wchar_t>(wc, os);
247 }
248
249 // Prints the given array of characters to the ostream. CharType must be either
250 // char or wchar_t.
251 // The array starts at begin, the length is len, it may include '\0' characters
252 // and may not be NUL-terminated.
253 template <typename CharType>
254 static void PrintCharsAsStringTo(
255 const CharType* begin, size_t len, ostream* os) {
256 const char* const kQuoteBegin = sizeof(CharType) == 1 ? "\"" : "L\"";
257 *os << kQuoteBegin;
258 bool is_previous_hex = false;
259 for (size_t index = 0; index < len; ++index) {
260 const CharType cur = begin[index];
261 if (is_previous_hex && IsXDigit(cur)) {
262 // Previous character is of '\x..' form and this character can be
263 // interpreted as another hexadecimal digit in its number. Break string to
264 // disambiguate.
265 *os << "\" " << kQuoteBegin;
266 }
267 is_previous_hex = PrintAsStringLiteralTo(cur, os) == kHexEscape;
268 }
269 *os << "\"";
270 }
271
272 // Prints a (const) char/wchar_t array of 'len' elements, starting at address
273 // 'begin'. CharType must be either char or wchar_t.
274 template <typename CharType>
275 static void UniversalPrintCharArray(
276 const CharType* begin, size_t len, ostream* os) {
277 // The code
278 // const char kFoo[] = "foo";
279 // generates an array of 4, not 3, elements, with the last one being '\0'.
280 //
281 // Therefore when printing a char array, we don't print the last element if
282 // it's '\0', such that the output matches the string literal as it's
283 // written in the source code.
284 if (len > 0 && begin[len - 1] == '\0') {
285 PrintCharsAsStringTo(begin, len - 1, os);
286 return;
287 }
288
289 // If, however, the last element in the array is not '\0', e.g.
290 // const char kFoo[] = { 'f', 'o', 'o' };
291 // we must print the entire array. We also print a message to indicate
292 // that the array is not NUL-terminated.
293 PrintCharsAsStringTo(begin, len, os);
294 *os << " (no terminating NUL)";
295 }
296
297 // Prints a (const) char array of 'len' elements, starting at address 'begin'.
298 void UniversalPrintArray(const char* begin, size_t len, ostream* os) {
299 UniversalPrintCharArray(begin, len, os);
300 }
301
302 // Prints a (const) wchar_t array of 'len' elements, starting at address
303 // 'begin'.
304 void UniversalPrintArray(const wchar_t* begin, size_t len, ostream* os) {
305 UniversalPrintCharArray(begin, len, os);
306 }
307
308 // Prints the given C string to the ostream.
309 void PrintTo(const char* s, ostream* os) {
310 if (s == NULL) {
311 *os << "NULL";
312 } else {
313 *os << ImplicitCast_<const void*>(s) << " pointing to ";
314 PrintCharsAsStringTo(s, strlen(s), os);
315 }
316 }
317
318 // MSVC compiler can be configured to define whar_t as a typedef
319 // of unsigned short. Defining an overload for const wchar_t* in that case
320 // would cause pointers to unsigned shorts be printed as wide strings,
321 // possibly accessing more memory than intended and causing invalid
322 // memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
323 // wchar_t is implemented as a native type.
324 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
325 // Prints the given wide C string to the ostream.
326 void PrintTo(const wchar_t* s, ostream* os) {
327 if (s == NULL) {
328 *os << "NULL";
329 } else {
330 *os << ImplicitCast_<const void*>(s) << " pointing to ";
331 PrintCharsAsStringTo(s, wcslen(s), os);
332 }
333 }
334 #endif // wchar_t is native
335
336 // Prints a ::string object.
337 #if GTEST_HAS_GLOBAL_STRING
338 void PrintStringTo(const ::string& s, ostream* os) {
339 PrintCharsAsStringTo(s.data(), s.size(), os);
340 }
341 #endif // GTEST_HAS_GLOBAL_STRING
342
343 void PrintStringTo(const ::std::string& s, ostream* os) {
344 PrintCharsAsStringTo(s.data(), s.size(), os);
345 }
346
347 // Prints a ::wstring object.
348 #if GTEST_HAS_GLOBAL_WSTRING
349 void PrintWideStringTo(const ::wstring& s, ostream* os) {
350 PrintCharsAsStringTo(s.data(), s.size(), os);
351 }
352 #endif // GTEST_HAS_GLOBAL_WSTRING
353
354 #if GTEST_HAS_STD_WSTRING
355 void PrintWideStringTo(const ::std::wstring& s, ostream* os) {
356 PrintCharsAsStringTo(s.data(), s.size(), os);
357 }
358 #endif // GTEST_HAS_STD_WSTRING
359
360 } // namespace internal
361
362 } // namespace testing
0 // Copyright 2008, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: mheule@google.com (Markus Heule)
30 //
31 // The Google C++ Testing Framework (Google Test)
32
33 #include "gtest/gtest-test-part.h"
34
35 // Indicates that this translation unit is part of Google Test's
36 // implementation. It must come before gtest-internal-inl.h is
37 // included, or there will be a compiler error. This trick is to
38 // prevent a user from accidentally including gtest-internal-inl.h in
39 // his code.
40 #define GTEST_IMPLEMENTATION_ 1
41 #include "src/gtest-internal-inl.h"
42 #undef GTEST_IMPLEMENTATION_
43
44 namespace testing {
45
46 using internal::GetUnitTestImpl;
47
48 // Gets the summary of the failure message by omitting the stack trace
49 // in it.
50 std::string TestPartResult::ExtractSummary(const char* message) {
51 const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
52 return stack_trace == NULL ? message :
53 std::string(message, stack_trace);
54 }
55
56 // Prints a TestPartResult object.
57 std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
58 return os
59 << result.file_name() << ":" << result.line_number() << ": "
60 << (result.type() == TestPartResult::kSuccess ? "Success" :
61 result.type() == TestPartResult::kFatalFailure ? "Fatal failure" :
62 "Non-fatal failure") << ":\n"
63 << result.message() << std::endl;
64 }
65
66 // Appends a TestPartResult to the array.
67 void TestPartResultArray::Append(const TestPartResult& result) {
68 array_.push_back(result);
69 }
70
71 // Returns the TestPartResult at the given index (0-based).
72 const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {
73 if (index < 0 || index >= size()) {
74 printf("\nInvalid index (%d) into TestPartResultArray.\n", index);
75 internal::posix::Abort();
76 }
77
78 return array_[index];
79 }
80
81 // Returns the number of TestPartResult objects in the array.
82 int TestPartResultArray::size() const {
83 return static_cast<int>(array_.size());
84 }
85
86 namespace internal {
87
88 HasNewFatalFailureHelper::HasNewFatalFailureHelper()
89 : has_new_fatal_failure_(false),
90 original_reporter_(GetUnitTestImpl()->
91 GetTestPartResultReporterForCurrentThread()) {
92 GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this);
93 }
94
95 HasNewFatalFailureHelper::~HasNewFatalFailureHelper() {
96 GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(
97 original_reporter_);
98 }
99
100 void HasNewFatalFailureHelper::ReportTestPartResult(
101 const TestPartResult& result) {
102 if (result.fatally_failed())
103 has_new_fatal_failure_ = true;
104 original_reporter_->ReportTestPartResult(result);
105 }
106
107 } // namespace internal
108
109 } // namespace testing
0 // Copyright 2008 Google Inc.
1 // All Rights Reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30
31 #include "gtest/gtest-typed-test.h"
32 #include "gtest/gtest.h"
33
34 namespace testing {
35 namespace internal {
36
37 #if GTEST_HAS_TYPED_TEST_P
38
39 // Skips to the first non-space char in str. Returns an empty string if str
40 // contains only whitespace characters.
41 static const char* SkipSpaces(const char* str) {
42 while (IsSpace(*str))
43 str++;
44 return str;
45 }
46
47 // Verifies that registered_tests match the test names in
48 // defined_test_names_; returns registered_tests if successful, or
49 // aborts the program otherwise.
50 const char* TypedTestCasePState::VerifyRegisteredTestNames(
51 const char* file, int line, const char* registered_tests) {
52 typedef ::std::set<const char*>::const_iterator DefinedTestIter;
53 registered_ = true;
54
55 // Skip initial whitespace in registered_tests since some
56 // preprocessors prefix stringizied literals with whitespace.
57 registered_tests = SkipSpaces(registered_tests);
58
59 Message errors;
60 ::std::set<std::string> tests;
61 for (const char* names = registered_tests; names != NULL;
62 names = SkipComma(names)) {
63 const std::string name = GetPrefixUntilComma(names);
64 if (tests.count(name) != 0) {
65 errors << "Test " << name << " is listed more than once.\n";
66 continue;
67 }
68
69 bool found = false;
70 for (DefinedTestIter it = defined_test_names_.begin();
71 it != defined_test_names_.end();
72 ++it) {
73 if (name == *it) {
74 found = true;
75 break;
76 }
77 }
78
79 if (found) {
80 tests.insert(name);
81 } else {
82 errors << "No test named " << name
83 << " can be found in this test case.\n";
84 }
85 }
86
87 for (DefinedTestIter it = defined_test_names_.begin();
88 it != defined_test_names_.end();
89 ++it) {
90 if (tests.count(*it) == 0) {
91 errors << "You forgot to list test " << *it << ".\n";
92 }
93 }
94
95 const std::string& errors_str = errors.GetString();
96 if (errors_str != "") {
97 fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
98 errors_str.c_str());
99 fflush(stderr);
100 posix::Abort();
101 }
102
103 return registered_tests;
104 }
105
106 #endif // GTEST_HAS_TYPED_TEST_P
107
108 } // namespace internal
109 } // namespace testing
0 // Copyright 2005, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Author: wan@google.com (Zhanyong Wan)
30 //
31 // The Google C++ Testing Framework (Google Test)
32
33 #include "gtest/gtest.h"
34 #include "gtest/gtest-spi.h"
35
36 #include <ctype.h>
37 #include <math.h>
38 #include <stdarg.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <time.h>
42 #include <wchar.h>
43 #include <wctype.h>
44
45 #include <algorithm>
46 #include <iomanip>
47 #include <limits>
48 #include <ostream> // NOLINT
49 #include <sstream>
50 #include <vector>
51
52 #if GTEST_OS_LINUX
53
54 // TODO(kenton@google.com): Use autoconf to detect availability of
55 // gettimeofday().
56 # define GTEST_HAS_GETTIMEOFDAY_ 1
57
58 # include <fcntl.h> // NOLINT
59 # include <limits.h> // NOLINT
60 # include <sched.h> // NOLINT
61 // Declares vsnprintf(). This header is not available on Windows.
62 # include <strings.h> // NOLINT
63 # include <sys/mman.h> // NOLINT
64 # include <sys/time.h> // NOLINT
65 # include <unistd.h> // NOLINT
66 # include <string>
67
68 #elif GTEST_OS_SYMBIAN
69 # define GTEST_HAS_GETTIMEOFDAY_ 1
70 # include <sys/time.h> // NOLINT
71
72 #elif GTEST_OS_ZOS
73 # define GTEST_HAS_GETTIMEOFDAY_ 1
74 # include <sys/time.h> // NOLINT
75
76 // On z/OS we additionally need strings.h for strcasecmp.
77 # include <strings.h> // NOLINT
78
79 #elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE.
80
81 # include <windows.h> // NOLINT
82
83 #elif GTEST_OS_WINDOWS // We are on Windows proper.
84
85 # include <io.h> // NOLINT
86 # include <sys/timeb.h> // NOLINT
87 # include <sys/types.h> // NOLINT
88 # include <sys/stat.h> // NOLINT
89
90 # if GTEST_OS_WINDOWS_MINGW
91 // MinGW has gettimeofday() but not _ftime64().
92 // TODO(kenton@google.com): Use autoconf to detect availability of
93 // gettimeofday().
94 // TODO(kenton@google.com): There are other ways to get the time on
95 // Windows, like GetTickCount() or GetSystemTimeAsFileTime(). MinGW
96 // supports these. consider using them instead.
97 # define GTEST_HAS_GETTIMEOFDAY_ 1
98 # include <sys/time.h> // NOLINT
99 # endif // GTEST_OS_WINDOWS_MINGW
100
101 // cpplint thinks that the header is already included, so we want to
102 // silence it.
103 # include <windows.h> // NOLINT
104
105 #else
106
107 // Assume other platforms have gettimeofday().
108 // TODO(kenton@google.com): Use autoconf to detect availability of
109 // gettimeofday().
110 # define GTEST_HAS_GETTIMEOFDAY_ 1
111
112 // cpplint thinks that the header is already included, so we want to
113 // silence it.
114 # include <sys/time.h> // NOLINT
115 # include <unistd.h> // NOLINT
116
117 #endif // GTEST_OS_LINUX
118
119 #if GTEST_HAS_EXCEPTIONS
120 # include <stdexcept>
121 #endif
122
123 #if GTEST_CAN_STREAM_RESULTS_
124 # include <arpa/inet.h> // NOLINT
125 # include <netdb.h> // NOLINT
126 #endif
127
128 // Indicates that this translation unit is part of Google Test's
129 // implementation. It must come before gtest-internal-inl.h is
130 // included, or there will be a compiler error. This trick is to
131 // prevent a user from accidentally including gtest-internal-inl.h in
132 // his code.
133 #define GTEST_IMPLEMENTATION_ 1
134 #include "src/gtest-internal-inl.h"
135 #undef GTEST_IMPLEMENTATION_
136
137 #if GTEST_OS_WINDOWS
138 # define vsnprintf _vsnprintf
139 #endif // GTEST_OS_WINDOWS
140
141 namespace testing {
142
143 using internal::CountIf;
144 using internal::ForEach;
145 using internal::GetElementOr;
146 using internal::Shuffle;
147
148 // Constants.
149
150 // A test whose test case name or test name matches this filter is
151 // disabled and not run.
152 static const char kDisableTestFilter[] = "DISABLED_*:*/DISABLED_*";
153
154 // A test case whose name matches this filter is considered a death
155 // test case and will be run before test cases whose name doesn't
156 // match this filter.
157 static const char kDeathTestCaseFilter[] = "*DeathTest:*DeathTest/*";
158
159 // A test filter that matches everything.
160 static const char kUniversalFilter[] = "*";
161
162 // The default output file for XML output.
163 static const char kDefaultOutputFile[] = "test_detail.xml";
164
165 // The environment variable name for the test shard index.
166 static const char kTestShardIndex[] = "GTEST_SHARD_INDEX";
167 // The environment variable name for the total number of test shards.
168 static const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS";
169 // The environment variable name for the test shard status file.
170 static const char kTestShardStatusFile[] = "GTEST_SHARD_STATUS_FILE";
171
172 namespace internal {
173
174 // The text used in failure messages to indicate the start of the
175 // stack trace.
176 const char kStackTraceMarker[] = "\nStack trace:\n";
177
178 // g_help_flag is true iff the --help flag or an equivalent form is
179 // specified on the command line.
180 bool g_help_flag = false;
181
182 } // namespace internal
183
184 static const char* GetDefaultFilter() {
185 return kUniversalFilter;
186 }
187
188 GTEST_DEFINE_bool_(
189 also_run_disabled_tests,
190 internal::BoolFromGTestEnv("also_run_disabled_tests", false),
191 "Run disabled tests too, in addition to the tests normally being run.");
192
193 GTEST_DEFINE_bool_(
194 break_on_failure,
195 internal::BoolFromGTestEnv("break_on_failure", false),
196 "True iff a failed assertion should be a debugger break-point.");
197
198 GTEST_DEFINE_bool_(
199 catch_exceptions,
200 internal::BoolFromGTestEnv("catch_exceptions", true),
201 "True iff " GTEST_NAME_
202 " should catch exceptions and treat them as test failures.");
203
204 GTEST_DEFINE_string_(
205 color,
206 internal::StringFromGTestEnv("color", "auto"),
207 "Whether to use colors in the output. Valid values: yes, no, "
208 "and auto. 'auto' means to use colors if the output is "
209 "being sent to a terminal and the TERM environment variable "
210 "is set to a terminal type that supports colors.");
211
212 GTEST_DEFINE_string_(
213 filter,
214 internal::StringFromGTestEnv("filter", GetDefaultFilter()),
215 "A colon-separated list of glob (not regex) patterns "
216 "for filtering the tests to run, optionally followed by a "
217 "'-' and a : separated list of negative patterns (tests to "
218 "exclude). A test is run if it matches one of the positive "
219 "patterns and does not match any of the negative patterns.");
220
221 GTEST_DEFINE_bool_(list_tests, false,
222 "List all tests without running them.");
223
224 GTEST_DEFINE_string_(
225 output,
226 internal::StringFromGTestEnv("output", ""),
227 "A format (currently must be \"xml\"), optionally followed "
228 "by a colon and an output file name or directory. A directory "
229 "is indicated by a trailing pathname separator. "
230 "Examples: \"xml:filename.xml\", \"xml::directoryname/\". "
231 "If a directory is specified, output files will be created "
232 "within that directory, with file-names based on the test "
233 "executable's name and, if necessary, made unique by adding "
234 "digits.");
235
236 GTEST_DEFINE_bool_(
237 print_time,
238 internal::BoolFromGTestEnv("print_time", true),
239 "True iff " GTEST_NAME_
240 " should display elapsed time in text output.");
241
242 GTEST_DEFINE_int32_(
243 random_seed,
244 internal::Int32FromGTestEnv("random_seed", 0),
245 "Random number seed to use when shuffling test orders. Must be in range "
246 "[1, 99999], or 0 to use a seed based on the current time.");
247
248 GTEST_DEFINE_int32_(
249 repeat,
250 internal::Int32FromGTestEnv("repeat", 1),
251 "How many times to repeat each test. Specify a negative number "
252 "for repeating forever. Useful for shaking out flaky tests.");
253
254 GTEST_DEFINE_bool_(
255 show_internal_stack_frames, false,
256 "True iff " GTEST_NAME_ " should include internal stack frames when "
257 "printing test failure stack traces.");
258
259 GTEST_DEFINE_bool_(
260 shuffle,
261 internal::BoolFromGTestEnv("shuffle", false),
262 "True iff " GTEST_NAME_
263 " should randomize tests' order on every run.");
264
265 GTEST_DEFINE_int32_(
266 stack_trace_depth,
267 internal::Int32FromGTestEnv("stack_trace_depth", kMaxStackTraceDepth),
268 "The maximum number of stack frames to print when an "
269 "assertion fails. The valid range is 0 through 100, inclusive.");
270
271 GTEST_DEFINE_string_(
272 stream_result_to,
273 internal::StringFromGTestEnv("stream_result_to", ""),
274 "This flag specifies the host name and the port number on which to stream "
275 "test results. Example: \"localhost:555\". The flag is effective only on "
276 "Linux.");
277
278 GTEST_DEFINE_bool_(
279 throw_on_failure,
280 internal::BoolFromGTestEnv("throw_on_failure", false),
281 "When this flag is specified, a failed assertion will throw an exception "
282 "if exceptions are enabled or exit the program with a non-zero code "
283 "otherwise.");
284
285 namespace internal {
286
287 // Generates a random number from [0, range), using a Linear
288 // Congruential Generator (LCG). Crashes if 'range' is 0 or greater
289 // than kMaxRange.
290 UInt32 Random::Generate(UInt32 range) {
291 // These constants are the same as are used in glibc's rand(3).
292 state_ = (1103515245U*state_ + 12345U) % kMaxRange;
293
294 GTEST_CHECK_(range > 0)
295 << "Cannot generate a number in the range [0, 0).";
296 GTEST_CHECK_(range <= kMaxRange)
297 << "Generation of a number in [0, " << range << ") was requested, "
298 << "but this can only generate numbers in [0, " << kMaxRange << ").";
299
300 // Converting via modulus introduces a bit of downward bias, but
301 // it's simple, and a linear congruential generator isn't too good
302 // to begin with.
303 return state_ % range;
304 }
305
306 // GTestIsInitialized() returns true iff the user has initialized
307 // Google Test. Useful for catching the user mistake of not initializing
308 // Google Test before calling RUN_ALL_TESTS().
309 //
310 // A user must call testing::InitGoogleTest() to initialize Google
311 // Test. g_init_gtest_count is set to the number of times
312 // InitGoogleTest() has been called. We don't protect this variable
313 // under a mutex as it is only accessed in the main thread.
314 GTEST_API_ int g_init_gtest_count = 0;
315 static bool GTestIsInitialized() { return g_init_gtest_count != 0; }
316
317 // Iterates over a vector of TestCases, keeping a running sum of the
318 // results of calling a given int-returning method on each.
319 // Returns the sum.
320 static int SumOverTestCaseList(const std::vector<TestCase*>& case_list,
321 int (TestCase::*method)() const) {
322 int sum = 0;
323 for (size_t i = 0; i < case_list.size(); i++) {
324 sum += (case_list[i]->*method)();
325 }
326 return sum;
327 }
328
329 // Returns true iff the test case passed.
330 static bool TestCasePassed(const TestCase* test_case) {
331 return test_case->should_run() && test_case->Passed();
332 }
333
334 // Returns true iff the test case failed.
335 static bool TestCaseFailed(const TestCase* test_case) {
336 return test_case->should_run() && test_case->Failed();
337 }
338
339 // Returns true iff test_case contains at least one test that should
340 // run.
341 static bool ShouldRunTestCase(const TestCase* test_case) {
342 return test_case->should_run();
343 }
344
345 // AssertHelper constructor.
346 AssertHelper::AssertHelper(TestPartResult::Type type,
347 const char* file,
348 int line,
349 const char* message)
350 : data_(new AssertHelperData(type, file, line, message)) {
351 }
352
353 AssertHelper::~AssertHelper() {
354 delete data_;
355 }
356
357 // Message assignment, for assertion streaming support.
358 void AssertHelper::operator=(const Message& message) const {
359 UnitTest::GetInstance()->
360 AddTestPartResult(data_->type, data_->file, data_->line,
361 AppendUserMessage(data_->message, message),
362 UnitTest::GetInstance()->impl()
363 ->CurrentOsStackTraceExceptTop(1)
364 // Skips the stack frame for this function itself.
365 ); // NOLINT
366 }
367
368 // Mutex for linked pointers.
369 GTEST_API_ GTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex);
370
371 // Application pathname gotten in InitGoogleTest.
372 std::string g_executable_path;
373
374 // Returns the current application's name, removing directory path if that
375 // is present.
376 FilePath GetCurrentExecutableName() {
377 FilePath result;
378
379 #if GTEST_OS_WINDOWS
380 result.Set(FilePath(g_executable_path).RemoveExtension("exe"));
381 #else
382 result.Set(FilePath(g_executable_path));
383 #endif // GTEST_OS_WINDOWS
384
385 return result.RemoveDirectoryName();
386 }
387
388 // Functions for processing the gtest_output flag.
389
390 // Returns the output format, or "" for normal printed output.
391 std::string UnitTestOptions::GetOutputFormat() {
392 const char* const gtest_output_flag = GTEST_FLAG(output).c_str();
393 if (gtest_output_flag == NULL) return std::string("");
394
395 const char* const colon = strchr(gtest_output_flag, ':');
396 return (colon == NULL) ?
397 std::string(gtest_output_flag) :
398 std::string(gtest_output_flag, colon - gtest_output_flag);
399 }
400
401 // Returns the name of the requested output file, or the default if none
402 // was explicitly specified.
403 std::string UnitTestOptions::GetAbsolutePathToOutputFile() {
404 const char* const gtest_output_flag = GTEST_FLAG(output).c_str();
405 if (gtest_output_flag == NULL)
406 return "";
407
408 const char* const colon = strchr(gtest_output_flag, ':');
409 if (colon == NULL)
410 return internal::FilePath::ConcatPaths(
411 internal::FilePath(
412 UnitTest::GetInstance()->original_working_dir()),
413 internal::FilePath(kDefaultOutputFile)).string();
414
415 internal::FilePath output_name(colon + 1);
416 if (!output_name.IsAbsolutePath())
417 // TODO(wan@google.com): on Windows \some\path is not an absolute
418 // path (as its meaning depends on the current drive), yet the
419 // following logic for turning it into an absolute path is wrong.
420 // Fix it.
421 output_name = internal::FilePath::ConcatPaths(
422 internal::FilePath(UnitTest::GetInstance()->original_working_dir()),
423 internal::FilePath(colon + 1));
424
425 if (!output_name.IsDirectory())
426 return output_name.string();
427
428 internal::FilePath result(internal::FilePath::GenerateUniqueFileName(
429 output_name, internal::GetCurrentExecutableName(),
430 GetOutputFormat().c_str()));
431 return result.string();
432 }
433
434 // Returns true iff the wildcard pattern matches the string. The
435 // first ':' or '\0' character in pattern marks the end of it.
436 //
437 // This recursive algorithm isn't very efficient, but is clear and
438 // works well enough for matching test names, which are short.
439 bool UnitTestOptions::PatternMatchesString(const char *pattern,
440 const char *str) {
441 switch (*pattern) {
442 case '\0':
443 case ':': // Either ':' or '\0' marks the end of the pattern.
444 return *str == '\0';
445 case '?': // Matches any single character.
446 return *str != '\0' && PatternMatchesString(pattern + 1, str + 1);
447 case '*': // Matches any string (possibly empty) of characters.
448 return (*str != '\0' && PatternMatchesString(pattern, str + 1)) ||
449 PatternMatchesString(pattern + 1, str);
450 default: // Non-special character. Matches itself.
451 return *pattern == *str &&
452 PatternMatchesString(pattern + 1, str + 1);
453 }
454 }
455
456 bool UnitTestOptions::MatchesFilter(
457 const std::string& name, const char* filter) {
458 const char *cur_pattern = filter;
459 for (;;) {
460 if (PatternMatchesString(cur_pattern, name.c_str())) {
461 return true;
462 }
463
464 // Finds the next pattern in the filter.
465 cur_pattern = strchr(cur_pattern, ':');
466
467 // Returns if no more pattern can be found.
468 if (cur_pattern == NULL) {
469 return false;
470 }
471
472 // Skips the pattern separater (the ':' character).
473 cur_pattern++;
474 }
475 }
476
477 // Returns true iff the user-specified filter matches the test case
478 // name and the test name.
479 bool UnitTestOptions::FilterMatchesTest(const std::string &test_case_name,
480 const std::string &test_name) {
481 const std::string& full_name = test_case_name + "." + test_name.c_str();
482
483 // Split --gtest_filter at '-', if there is one, to separate into
484 // positive filter and negative filter portions
485 const char* const p = GTEST_FLAG(filter).c_str();
486 const char* const dash = strchr(p, '-');
487 std::string positive;
488 std::string negative;
489 if (dash == NULL) {
490 positive = GTEST_FLAG(filter).c_str(); // Whole string is a positive filter
491 negative = "";
492 } else {
493 positive = std::string(p, dash); // Everything up to the dash
494 negative = std::string(dash + 1); // Everything after the dash
495 if (positive.empty()) {
496 // Treat '-test1' as the same as '*-test1'
497 positive = kUniversalFilter;
498 }
499 }
500
501 // A filter is a colon-separated list of patterns. It matches a
502 // test if any pattern in it matches the test.
503 return (MatchesFilter(full_name, positive.c_str()) &&
504 !MatchesFilter(full_name, negative.c_str()));
505 }
506
507 #if GTEST_HAS_SEH
508 // Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
509 // given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
510 // This function is useful as an __except condition.
511 int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
512 // Google Test should handle a SEH exception if:
513 // 1. the user wants it to, AND
514 // 2. this is not a breakpoint exception, AND
515 // 3. this is not a C++ exception (VC++ implements them via SEH,
516 // apparently).
517 //
518 // SEH exception code for C++ exceptions.
519 // (see http://support.microsoft.com/kb/185294 for more information).
520 const DWORD kCxxExceptionCode = 0xe06d7363;
521
522 bool should_handle = true;
523
524 if (!GTEST_FLAG(catch_exceptions))
525 should_handle = false;
526 else if (exception_code == EXCEPTION_BREAKPOINT)
527 should_handle = false;
528 else if (exception_code == kCxxExceptionCode)
529 should_handle = false;
530
531 return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
532 }
533 #endif // GTEST_HAS_SEH
534
535 } // namespace internal
536
537 // The c'tor sets this object as the test part result reporter used by
538 // Google Test. The 'result' parameter specifies where to report the
539 // results. Intercepts only failures from the current thread.
540 ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
541 TestPartResultArray* result)
542 : intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
543 result_(result) {
544 Init();
545 }
546
547 // The c'tor sets this object as the test part result reporter used by
548 // Google Test. The 'result' parameter specifies where to report the
549 // results.
550 ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
551 InterceptMode intercept_mode, TestPartResultArray* result)
552 : intercept_mode_(intercept_mode),
553 result_(result) {
554 Init();
555 }
556
557 void ScopedFakeTestPartResultReporter::Init() {
558 internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
559 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
560 old_reporter_ = impl->GetGlobalTestPartResultReporter();
561 impl->SetGlobalTestPartResultReporter(this);
562 } else {
563 old_reporter_ = impl->GetTestPartResultReporterForCurrentThread();
564 impl->SetTestPartResultReporterForCurrentThread(this);
565 }
566 }
567
568 // The d'tor restores the test part result reporter used by Google Test
569 // before.
570 ScopedFakeTestPartResultReporter::~ScopedFakeTestPartResultReporter() {
571 internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
572 if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
573 impl->SetGlobalTestPartResultReporter(old_reporter_);
574 } else {
575 impl->SetTestPartResultReporterForCurrentThread(old_reporter_);
576 }
577 }
578
579 // Increments the test part result count and remembers the result.
580 // This method is from the TestPartResultReporterInterface interface.
581 void ScopedFakeTestPartResultReporter::ReportTestPartResult(
582 const TestPartResult& result) {
583 result_->Append(result);
584 }
585
586 namespace internal {
587
588 // Returns the type ID of ::testing::Test. We should always call this
589 // instead of GetTypeId< ::testing::Test>() to get the type ID of
590 // testing::Test. This is to work around a suspected linker bug when
591 // using Google Test as a framework on Mac OS X. The bug causes
592 // GetTypeId< ::testing::Test>() to return different values depending
593 // on whether the call is from the Google Test framework itself or
594 // from user test code. GetTestTypeId() is guaranteed to always
595 // return the same value, as it always calls GetTypeId<>() from the
596 // gtest.cc, which is within the Google Test framework.
597 TypeId GetTestTypeId() {
598 return GetTypeId<Test>();
599 }
600
601 // The value of GetTestTypeId() as seen from within the Google Test
602 // library. This is solely for testing GetTestTypeId().
603 extern const TypeId kTestTypeIdInGoogleTest = GetTestTypeId();
604
605 // This predicate-formatter checks that 'results' contains a test part
606 // failure of the given type and that the failure message contains the
607 // given substring.
608 AssertionResult HasOneFailure(const char* /* results_expr */,
609 const char* /* type_expr */,
610 const char* /* substr_expr */,
611 const TestPartResultArray& results,
612 TestPartResult::Type type,
613 const string& substr) {
614 const std::string expected(type == TestPartResult::kFatalFailure ?
615 "1 fatal failure" :
616 "1 non-fatal failure");
617 Message msg;
618 if (results.size() != 1) {
619 msg << "Expected: " << expected << "\n"
620 << " Actual: " << results.size() << " failures";
621 for (int i = 0; i < results.size(); i++) {
622 msg << "\n" << results.GetTestPartResult(i);
623 }
624 return AssertionFailure() << msg;
625 }
626
627 const TestPartResult& r = results.GetTestPartResult(0);
628 if (r.type() != type) {
629 return AssertionFailure() << "Expected: " << expected << "\n"
630 << " Actual:\n"
631 << r;
632 }
633
634 if (strstr(r.message(), substr.c_str()) == NULL) {
635 return AssertionFailure() << "Expected: " << expected << " containing \""
636 << substr << "\"\n"
637 << " Actual:\n"
638 << r;
639 }
640
641 return AssertionSuccess();
642 }
643
644 // The constructor of SingleFailureChecker remembers where to look up
645 // test part results, what type of failure we expect, and what
646 // substring the failure message should contain.
647 SingleFailureChecker:: SingleFailureChecker(
648 const TestPartResultArray* results,
649 TestPartResult::Type type,
650 const string& substr)
651 : results_(results),
652 type_(type),
653 substr_(substr) {}
654
655 // The destructor of SingleFailureChecker verifies that the given
656 // TestPartResultArray contains exactly one failure that has the given
657 // type and contains the given substring. If that's not the case, a
658 // non-fatal failure will be generated.
659 SingleFailureChecker::~SingleFailureChecker() {
660 EXPECT_PRED_FORMAT3(HasOneFailure, *results_, type_, substr_);
661 }
662
663 DefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter(
664 UnitTestImpl* unit_test) : unit_test_(unit_test) {}
665
666 void DefaultGlobalTestPartResultReporter::ReportTestPartResult(
667 const TestPartResult& result) {
668 unit_test_->current_test_result()->AddTestPartResult(result);
669 unit_test_->listeners()->repeater()->OnTestPartResult(result);
670 }
671
672 DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter(
673 UnitTestImpl* unit_test) : unit_test_(unit_test) {}
674
675 void DefaultPerThreadTestPartResultReporter::ReportTestPartResult(
676 const TestPartResult& result) {
677 unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(result);
678 }
679
680 // Returns the global test part result reporter.
681 TestPartResultReporterInterface*
682 UnitTestImpl::GetGlobalTestPartResultReporter() {
683 internal::MutexLock lock(&global_test_part_result_reporter_mutex_);
684 return global_test_part_result_repoter_;
685 }
686
687 // Sets the global test part result reporter.
688 void UnitTestImpl::SetGlobalTestPartResultReporter(
689 TestPartResultReporterInterface* reporter) {
690 internal::MutexLock lock(&global_test_part_result_reporter_mutex_);
691 global_test_part_result_repoter_ = reporter;
692 }
693
694 // Returns the test part result reporter for the current thread.
695 TestPartResultReporterInterface*
696 UnitTestImpl::GetTestPartResultReporterForCurrentThread() {
697 return per_thread_test_part_result_reporter_.get();
698 }
699
700 // Sets the test part result reporter for the current thread.
701 void UnitTestImpl::SetTestPartResultReporterForCurrentThread(
702 TestPartResultReporterInterface* reporter) {
703 per_thread_test_part_result_reporter_.set(reporter);
704 }
705
706 // Gets the number of successful test cases.
707 int UnitTestImpl::successful_test_case_count() const {
708 return CountIf(test_cases_, TestCasePassed);
709 }
710
711 // Gets the number of failed test cases.
712 int UnitTestImpl::failed_test_case_count() const {
713 return CountIf(test_cases_, TestCaseFailed);
714 }
715
716 // Gets the number of all test cases.
717 int UnitTestImpl::total_test_case_count() const {
718 return static_cast<int>(test_cases_.size());
719 }
720
721 // Gets the number of all test cases that contain at least one test
722 // that should run.
723 int UnitTestImpl::test_case_to_run_count() const {
724 return CountIf(test_cases_, ShouldRunTestCase);
725 }
726
727 // Gets the number of successful tests.
728 int UnitTestImpl::successful_test_count() const {
729 return SumOverTestCaseList(test_cases_, &TestCase::successful_test_count);
730 }
731
732 // Gets the number of failed tests.
733 int UnitTestImpl::failed_test_count() const {
734 return SumOverTestCaseList(test_cases_, &TestCase::failed_test_count);
735 }
736
737 // Gets the number of disabled tests that will be reported in the XML report.
738 int UnitTestImpl::reportable_disabled_test_count() const {
739 return SumOverTestCaseList(test_cases_,
740 &TestCase::reportable_disabled_test_count);
741 }
742
743 // Gets the number of disabled tests.
744 int UnitTestImpl::disabled_test_count() const {
745 return SumOverTestCaseList(test_cases_, &TestCase::disabled_test_count);
746 }
747
748 // Gets the number of tests to be printed in the XML report.
749 int UnitTestImpl::reportable_test_count() const {
750 return SumOverTestCaseList(test_cases_, &TestCase::reportable_test_count);
751 }
752
753 // Gets the number of all tests.
754 int UnitTestImpl::total_test_count() const {
755 return SumOverTestCaseList(test_cases_, &TestCase::total_test_count);
756 }
757
758 // Gets the number of tests that should run.
759 int UnitTestImpl::test_to_run_count() const {
760 return SumOverTestCaseList(test_cases_, &TestCase::test_to_run_count);
761 }
762
763 // Returns the current OS stack trace as an std::string.
764 //
765 // The maximum number of stack frames to be included is specified by
766 // the gtest_stack_trace_depth flag. The skip_count parameter
767 // specifies the number of top frames to be skipped, which doesn't
768 // count against the number of frames to be included.
769 //
770 // For example, if Foo() calls Bar(), which in turn calls
771 // CurrentOsStackTraceExceptTop(1), Foo() will be included in the
772 // trace but Bar() and CurrentOsStackTraceExceptTop() won't.
773 std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
774 (void)skip_count;
775 return "";
776 }
777
778 // Returns the current time in milliseconds.
779 TimeInMillis GetTimeInMillis() {
780 #if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__)
781 // Difference between 1970-01-01 and 1601-01-01 in milliseconds.
782 // http://analogous.blogspot.com/2005/04/epoch.html
783 const TimeInMillis kJavaEpochToWinFileTimeDelta =
784 static_cast<TimeInMillis>(116444736UL) * 100000UL;
785 const DWORD kTenthMicrosInMilliSecond = 10000;
786
787 SYSTEMTIME now_systime;
788 FILETIME now_filetime;
789 ULARGE_INTEGER now_int64;
790 // TODO(kenton@google.com): Shouldn't this just use
791 // GetSystemTimeAsFileTime()?
792 GetSystemTime(&now_systime);
793 if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
794 now_int64.LowPart = now_filetime.dwLowDateTime;
795 now_int64.HighPart = now_filetime.dwHighDateTime;
796 now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -
797 kJavaEpochToWinFileTimeDelta;
798 return now_int64.QuadPart;
799 }
800 return 0;
801 #elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_
802 __timeb64 now;
803
804 # ifdef _MSC_VER
805
806 // MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996
807 // (deprecated function) there.
808 // TODO(kenton@google.com): Use GetTickCount()? Or use
809 // SystemTimeToFileTime()
810 # pragma warning(push) // Saves the current warning state.
811 # pragma warning(disable:4996) // Temporarily disables warning 4996.
812 _ftime64(&now);
813 # pragma warning(pop) // Restores the warning state.
814 # else
815
816 _ftime64(&now);
817
818 # endif // _MSC_VER
819
820 return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;
821 #elif GTEST_HAS_GETTIMEOFDAY_
822 struct timeval now;
823 gettimeofday(&now, NULL);
824 return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000;
825 #else
826 # error "Don't know how to get the current time on your system."
827 #endif
828 }
829
830 // Utilities
831
832 // class String.
833
834 #if GTEST_OS_WINDOWS_MOBILE
835 // Creates a UTF-16 wide string from the given ANSI string, allocating
836 // memory using new. The caller is responsible for deleting the return
837 // value using delete[]. Returns the wide string, or NULL if the
838 // input is NULL.
839 LPCWSTR String::AnsiToUtf16(const char* ansi) {
840 if (!ansi) return NULL;
841 const int length = strlen(ansi);
842 const int unicode_length =
843 MultiByteToWideChar(CP_ACP, 0, ansi, length,
844 NULL, 0);
845 WCHAR* unicode = new WCHAR[unicode_length + 1];
846 MultiByteToWideChar(CP_ACP, 0, ansi, length,
847 unicode, unicode_length);
848 unicode[unicode_length] = 0;
849 return unicode;
850 }
851
852 // Creates an ANSI string from the given wide string, allocating
853 // memory using new. The caller is responsible for deleting the return
854 // value using delete[]. Returns the ANSI string, or NULL if the
855 // input is NULL.
856 const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
857 if (!utf16_str) return NULL;
858 const int ansi_length =
859 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
860 NULL, 0, NULL, NULL);
861 char* ansi = new char[ansi_length + 1];
862 WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
863 ansi, ansi_length, NULL, NULL);
864 ansi[ansi_length] = 0;
865 return ansi;
866 }
867
868 #endif // GTEST_OS_WINDOWS_MOBILE
869
870 // Compares two C strings. Returns true iff they have the same content.
871 //
872 // Unlike strcmp(), this function can handle NULL argument(s). A NULL
873 // C string is considered different to any non-NULL C string,
874 // including the empty string.
875 bool String::CStringEquals(const char * lhs, const char * rhs) {
876 if ( lhs == NULL ) return rhs == NULL;
877
878 if ( rhs == NULL ) return false;
879
880 return strcmp(lhs, rhs) == 0;
881 }
882
883 #if GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING
884
885 // Converts an array of wide chars to a narrow string using the UTF-8
886 // encoding, and streams the result to the given Message object.
887 static void StreamWideCharsToMessage(const wchar_t* wstr, size_t length,
888 Message* msg) {
889 for (size_t i = 0; i != length; ) { // NOLINT
890 if (wstr[i] != L'\0') {
891 *msg << WideStringToUtf8(wstr + i, static_cast<int>(length - i));
892 while (i != length && wstr[i] != L'\0')
893 i++;
894 } else {
895 *msg << '\0';
896 i++;
897 }
898 }
899 }
900
901 #endif // GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING
902
903 } // namespace internal
904
905 // Constructs an empty Message.
906 // We allocate the stringstream separately because otherwise each use of
907 // ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's
908 // stack frame leading to huge stack frames in some cases; gcc does not reuse
909 // the stack space.
910 Message::Message() : ss_(new ::std::stringstream) {
911 // By default, we want there to be enough precision when printing
912 // a double to a Message.
913 *ss_ << std::setprecision(std::numeric_limits<double>::digits10 + 2);
914 }
915
916 // These two overloads allow streaming a wide C string to a Message
917 // using the UTF-8 encoding.
918 Message& Message::operator <<(const wchar_t* wide_c_str) {
919 return *this << internal::String::ShowWideCString(wide_c_str);
920 }
921 Message& Message::operator <<(wchar_t* wide_c_str) {
922 return *this << internal::String::ShowWideCString(wide_c_str);
923 }
924
925 #if GTEST_HAS_STD_WSTRING
926 // Converts the given wide string to a narrow string using the UTF-8
927 // encoding, and streams the result to this Message object.
928 Message& Message::operator <<(const ::std::wstring& wstr) {
929 internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(), this);
930 return *this;
931 }
932 #endif // GTEST_HAS_STD_WSTRING
933
934 #if GTEST_HAS_GLOBAL_WSTRING
935 // Converts the given wide string to a narrow string using the UTF-8
936 // encoding, and streams the result to this Message object.
937 Message& Message::operator <<(const ::wstring& wstr) {
938 internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(), this);
939 return *this;
940 }
941 #endif // GTEST_HAS_GLOBAL_WSTRING
942
943 // Gets the text streamed to this object so far as an std::string.
944 // Each '\0' character in the buffer is replaced with "\\0".
945 std::string Message::GetString() const {
946 return internal::StringStreamToString(ss_.get());
947 }
948
949 // AssertionResult constructors.
950 // Used in EXPECT_TRUE/FALSE(assertion_result).
951 AssertionResult::AssertionResult(const AssertionResult& other)
952 : success_(other.success_),
953 message_(other.message_.get() != NULL ?
954 new ::std::string(*other.message_) :
955 static_cast< ::std::string*>(NULL)) {
956 }
957
958 // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
959 AssertionResult AssertionResult::operator!() const {
960 AssertionResult negation(!success_);
961 if (message_.get() != NULL)
962 negation << *message_;
963 return negation;
964 }
965
966 // Makes a successful assertion result.
967 AssertionResult AssertionSuccess() {
968 return AssertionResult(true);
969 }
970
971 // Makes a failed assertion result.
972 AssertionResult AssertionFailure() {
973 return AssertionResult(false);
974 }
975
976 // Makes a failed assertion result with the given failure message.
977 // Deprecated; use AssertionFailure() << message.
978 AssertionResult AssertionFailure(const Message& message) {
979 return AssertionFailure() << message;
980 }
981
982 namespace internal {
983
984 // Constructs and returns the message for an equality assertion
985 // (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
986 //
987 // The first four parameters are the expressions used in the assertion
988 // and their values, as strings. For example, for ASSERT_EQ(foo, bar)
989 // where foo is 5 and bar is 6, we have:
990 //
991 // expected_expression: "foo"
992 // actual_expression: "bar"
993 // expected_value: "5"
994 // actual_value: "6"
995 //
996 // The ignoring_case parameter is true iff the assertion is a
997 // *_STRCASEEQ*. When it's true, the string " (ignoring case)" will
998 // be inserted into the message.
999 AssertionResult EqFailure(const char* expected_expression,
1000 const char* actual_expression,
1001 const std::string& expected_value,
1002 const std::string& actual_value,
1003 bool ignoring_case) {
1004 Message msg;
1005 msg << "Value of: " << actual_expression;
1006 if (actual_value != actual_expression) {
1007 msg << "\n Actual: " << actual_value;
1008 }
1009
1010 msg << "\nExpected: " << expected_expression;
1011 if (ignoring_case) {
1012 msg << " (ignoring case)";
1013 }
1014 if (expected_value != expected_expression) {
1015 msg << "\nWhich is: " << expected_value;
1016 }
1017
1018 return AssertionFailure() << msg;
1019 }
1020
1021 // Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
1022 std::string GetBoolAssertionFailureMessage(
1023 const AssertionResult& assertion_result,
1024 const char* expression_text,
1025 const char* actual_predicate_value,
1026 const char* expected_predicate_value) {
1027 const char* actual_message = assertion_result.message();
1028 Message msg;
1029 msg << "Value of: " << expression_text
1030 << "\n Actual: " << actual_predicate_value;
1031 if (actual_message[0] != '\0')
1032 msg << " (" << actual_message << ")";
1033 msg << "\nExpected: " << expected_predicate_value;
1034 return msg.GetString();
1035 }
1036
1037 // Helper function for implementing ASSERT_NEAR.
1038 AssertionResult DoubleNearPredFormat(const char* expr1,
1039 const char* expr2,
1040 const char* abs_error_expr,
1041 double val1,
1042 double val2,
1043 double abs_error) {
1044 const double diff = fabs(val1 - val2);
1045 if (diff <= abs_error) return AssertionSuccess();
1046
1047 // TODO(wan): do not print the value of an expression if it's
1048 // already a literal.
1049 return AssertionFailure()
1050 << "The difference between " << expr1 << " and " << expr2
1051 << " is " << diff << ", which exceeds " << abs_error_expr << ", where\n"
1052 << expr1 << " evaluates to " << val1 << ",\n"
1053 << expr2 << " evaluates to " << val2 << ", and\n"
1054 << abs_error_expr << " evaluates to " << abs_error << ".";
1055 }
1056
1057
1058 // Helper template for implementing FloatLE() and DoubleLE().
1059 template <typename RawType>
1060 AssertionResult FloatingPointLE(const char* expr1,
1061 const char* expr2,
1062 RawType val1,
1063 RawType val2) {
1064 // Returns success if val1 is less than val2,
1065 if (val1 < val2) {
1066 return AssertionSuccess();
1067 }
1068
1069 // or if val1 is almost equal to val2.
1070 const FloatingPoint<RawType> lhs(val1), rhs(val2);
1071 if (lhs.AlmostEquals(rhs)) {
1072 return AssertionSuccess();
1073 }
1074
1075 // Note that the above two checks will both fail if either val1 or
1076 // val2 is NaN, as the IEEE floating-point standard requires that
1077 // any predicate involving a NaN must return false.
1078
1079 ::std::stringstream val1_ss;
1080 val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1081 << val1;
1082
1083 ::std::stringstream val2_ss;
1084 val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
1085 << val2;
1086
1087 return AssertionFailure()
1088 << "Expected: (" << expr1 << ") <= (" << expr2 << ")\n"
1089 << " Actual: " << StringStreamToString(&val1_ss) << " vs "
1090 << StringStreamToString(&val2_ss);
1091 }
1092
1093 } // namespace internal
1094
1095 // Asserts that val1 is less than, or almost equal to, val2. Fails
1096 // otherwise. In particular, it fails if either val1 or val2 is NaN.
1097 AssertionResult FloatLE(const char* expr1, const char* expr2,
1098 float val1, float val2) {
1099 return internal::FloatingPointLE<float>(expr1, expr2, val1, val2);
1100 }
1101
1102 // Asserts that val1 is less than, or almost equal to, val2. Fails
1103 // otherwise. In particular, it fails if either val1 or val2 is NaN.
1104 AssertionResult DoubleLE(const char* expr1, const char* expr2,
1105 double val1, double val2) {
1106 return internal::FloatingPointLE<double>(expr1, expr2, val1, val2);
1107 }
1108
1109 namespace internal {
1110
1111 // The helper function for {ASSERT|EXPECT}_EQ with int or enum
1112 // arguments.
1113 AssertionResult CmpHelperEQ(const char* expected_expression,
1114 const char* actual_expression,
1115 BiggestInt expected,
1116 BiggestInt actual) {
1117 if (expected == actual) {
1118 return AssertionSuccess();
1119 }
1120
1121 return EqFailure(expected_expression,
1122 actual_expression,
1123 FormatForComparisonFailureMessage(expected, actual),
1124 FormatForComparisonFailureMessage(actual, expected),
1125 false);
1126 }
1127
1128 // A macro for implementing the helper functions needed to implement
1129 // ASSERT_?? and EXPECT_?? with integer or enum arguments. It is here
1130 // just to avoid copy-and-paste of similar code.
1131 #define GTEST_IMPL_CMP_HELPER_(op_name, op)\
1132 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
1133 BiggestInt val1, BiggestInt val2) {\
1134 if (val1 op val2) {\
1135 return AssertionSuccess();\
1136 } else {\
1137 return AssertionFailure() \
1138 << "Expected: (" << expr1 << ") " #op " (" << expr2\
1139 << "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
1140 << " vs " << FormatForComparisonFailureMessage(val2, val1);\
1141 }\
1142 }
1143
1144 // Implements the helper function for {ASSERT|EXPECT}_NE with int or
1145 // enum arguments.
1146 GTEST_IMPL_CMP_HELPER_(NE, !=)
1147 // Implements the helper function for {ASSERT|EXPECT}_LE with int or
1148 // enum arguments.
1149 GTEST_IMPL_CMP_HELPER_(LE, <=)
1150 // Implements the helper function for {ASSERT|EXPECT}_LT with int or
1151 // enum arguments.
1152 GTEST_IMPL_CMP_HELPER_(LT, < )
1153 // Implements the helper function for {ASSERT|EXPECT}_GE with int or
1154 // enum arguments.
1155 GTEST_IMPL_CMP_HELPER_(GE, >=)
1156 // Implements the helper function for {ASSERT|EXPECT}_GT with int or
1157 // enum arguments.
1158 GTEST_IMPL_CMP_HELPER_(GT, > )
1159
1160 #undef GTEST_IMPL_CMP_HELPER_
1161
1162 // The helper function for {ASSERT|EXPECT}_STREQ.
1163 AssertionResult CmpHelperSTREQ(const char* expected_expression,
1164 const char* actual_expression,
1165 const char* expected,
1166 const char* actual) {
1167 if (String::CStringEquals(expected, actual)) {
1168 return AssertionSuccess();
1169 }
1170
1171 return EqFailure(expected_expression,
1172 actual_expression,
1173 PrintToString(expected),
1174 PrintToString(actual),
1175 false);
1176 }
1177
1178 // The helper function for {ASSERT|EXPECT}_STRCASEEQ.
1179 AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,
1180 const char* actual_expression,
1181 const char* expected,
1182 const char* actual) {
1183 if (String::CaseInsensitiveCStringEquals(expected, actual)) {
1184 return AssertionSuccess();
1185 }
1186
1187 return EqFailure(expected_expression,
1188 actual_expression,
1189 PrintToString(expected),
1190 PrintToString(actual),
1191 true);
1192 }
1193
1194 // The helper function for {ASSERT|EXPECT}_STRNE.
1195 AssertionResult CmpHelperSTRNE(const char* s1_expression,
1196 const char* s2_expression,
1197 const char* s1,
1198 const char* s2) {
1199 if (!String::CStringEquals(s1, s2)) {
1200 return AssertionSuccess();
1201 } else {
1202 return AssertionFailure() << "Expected: (" << s1_expression << ") != ("
1203 << s2_expression << "), actual: \""
1204 << s1 << "\" vs \"" << s2 << "\"";
1205 }
1206 }
1207
1208 // The helper function for {ASSERT|EXPECT}_STRCASENE.
1209 AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
1210 const char* s2_expression,
1211 const char* s1,
1212 const char* s2) {
1213 if (!String::CaseInsensitiveCStringEquals(s1, s2)) {
1214 return AssertionSuccess();
1215 } else {
1216 return AssertionFailure()
1217 << "Expected: (" << s1_expression << ") != ("
1218 << s2_expression << ") (ignoring case), actual: \""
1219 << s1 << "\" vs \"" << s2 << "\"";
1220 }
1221 }
1222
1223 } // namespace internal
1224
1225 namespace {
1226
1227 // Helper functions for implementing IsSubString() and IsNotSubstring().
1228
1229 // This group of overloaded functions return true iff needle is a
1230 // substring of haystack. NULL is considered a substring of itself
1231 // only.
1232
1233 bool IsSubstringPred(const char* needle, const char* haystack) {
1234 if (needle == NULL || haystack == NULL)
1235 return needle == haystack;
1236
1237 return strstr(haystack, needle) != NULL;
1238 }
1239
1240 bool IsSubstringPred(const wchar_t* needle, const wchar_t* haystack) {
1241 if (needle == NULL || haystack == NULL)
1242 return needle == haystack;
1243
1244 return wcsstr(haystack, needle) != NULL;
1245 }
1246
1247 // StringType here can be either ::std::string or ::std::wstring.
1248 template <typename StringType>
1249 bool IsSubstringPred(const StringType& needle,
1250 const StringType& haystack) {
1251 return haystack.find(needle) != StringType::npos;
1252 }
1253
1254 // This function implements either IsSubstring() or IsNotSubstring(),
1255 // depending on the value of the expected_to_be_substring parameter.
1256 // StringType here can be const char*, const wchar_t*, ::std::string,
1257 // or ::std::wstring.
1258 template <typename StringType>
1259 AssertionResult IsSubstringImpl(
1260 bool expected_to_be_substring,
1261 const char* needle_expr, const char* haystack_expr,
1262 const StringType& needle, const StringType& haystack) {
1263 if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
1264 return AssertionSuccess();
1265
1266 const bool is_wide_string = sizeof(needle[0]) > 1;
1267 const char* const begin_string_quote = is_wide_string ? "L\"" : "\"";
1268 return AssertionFailure()
1269 << "Value of: " << needle_expr << "\n"
1270 << " Actual: " << begin_string_quote << needle << "\"\n"
1271 << "Expected: " << (expected_to_be_substring ? "" : "not ")
1272 << "a substring of " << haystack_expr << "\n"
1273 << "Which is: " << begin_string_quote << haystack << "\"";
1274 }
1275
1276 } // namespace
1277
1278 // IsSubstring() and IsNotSubstring() check whether needle is a
1279 // substring of haystack (NULL is considered a substring of itself
1280 // only), and return an appropriate error message when they fail.
1281
1282 AssertionResult IsSubstring(
1283 const char* needle_expr, const char* haystack_expr,
1284 const char* needle, const char* haystack) {
1285 return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
1286 }
1287
1288 AssertionResult IsSubstring(
1289 const char* needle_expr, const char* haystack_expr,
1290 const wchar_t* needle, const wchar_t* haystack) {
1291 return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
1292 }
1293
1294 AssertionResult IsNotSubstring(
1295 const char* needle_expr, const char* haystack_expr,
1296 const char* needle, const char* haystack) {
1297 return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
1298 }
1299
1300 AssertionResult IsNotSubstring(
1301 const char* needle_expr, const char* haystack_expr,
1302 const wchar_t* needle, const wchar_t* haystack) {
1303 return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
1304 }
1305
1306 AssertionResult IsSubstring(
1307 const char* needle_expr, const char* haystack_expr,
1308 const ::std::string& needle, const ::std::string& haystack) {
1309 return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
1310 }
1311
1312 AssertionResult IsNotSubstring(
1313 const char* needle_expr, const char* haystack_expr,
1314 const ::std::string& needle, const ::std::string& haystack) {
1315 return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
1316 }
1317
1318 #if GTEST_HAS_STD_WSTRING
1319 AssertionResult IsSubstring(
1320 const char* needle_expr, const char* haystack_expr,
1321 const ::std::wstring& needle, const ::std::wstring& haystack) {
1322 return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
1323 }
1324
1325 AssertionResult IsNotSubstring(
1326 const char* needle_expr, const char* haystack_expr,
1327 const ::std::wstring& needle, const ::std::wstring& haystack) {
1328 return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
1329 }
1330 #endif // GTEST_HAS_STD_WSTRING
1331
1332 namespace internal {
1333
1334 #if GTEST_OS_WINDOWS
1335
1336 namespace {
1337
1338 // Helper function for IsHRESULT{SuccessFailure} predicates
1339 AssertionResult HRESULTFailureHelper(const char* expr,
1340 const char* expected,
1341 long hr) { // NOLINT
1342 # if GTEST_OS_WINDOWS_MOBILE
1343
1344 // Windows CE doesn't support FormatMessage.
1345 const char error_text[] = "";
1346
1347 # else
1348
1349 // Looks up the human-readable system message for the HRESULT code
1350 // and since we're not passing any params to FormatMessage, we don't
1351 // want inserts expanded.
1352 const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
1353 FORMAT_MESSAGE_IGNORE_INSERTS;
1354 const DWORD kBufSize = 4096;
1355 // Gets the system's human readable message string for this HRESULT.
1356 char error_text[kBufSize] = { '\0' };
1357 DWORD message_length = ::FormatMessageA(kFlags,
1358 0, // no source, we're asking system
1359 hr, // the error
1360 0, // no line width restrictions
1361 error_text, // output buffer
1362 kBufSize, // buf size
1363 NULL); // no arguments for inserts
1364 // Trims tailing white space (FormatMessage leaves a trailing CR-LF)
1365 for (; message_length && IsSpace(error_text[message_length - 1]);
1366 --message_length) {
1367 error_text[message_length - 1] = '\0';
1368 }
1369
1370 # endif // GTEST_OS_WINDOWS_MOBILE
1371
1372 const std::string error_hex("0x" + String::FormatHexInt(hr));
1373 return ::testing::AssertionFailure()
1374 << "Expected: " << expr << " " << expected << ".\n"
1375 << " Actual: " << error_hex << " " << error_text << "\n";
1376 }
1377
1378 } // namespace
1379
1380 AssertionResult IsHRESULTSuccess(const char* expr, long hr) { // NOLINT
1381 if (SUCCEEDED(hr)) {
1382 return AssertionSuccess();
1383 }
1384 return HRESULTFailureHelper(expr, "succeeds", hr);
1385 }
1386
1387 AssertionResult IsHRESULTFailure(const char* expr, long hr) { // NOLINT
1388 if (FAILED(hr)) {
1389 return AssertionSuccess();
1390 }
1391 return HRESULTFailureHelper(expr, "fails", hr);
1392 }
1393
1394 #endif // GTEST_OS_WINDOWS
1395
1396 // Utility functions for encoding Unicode text (wide strings) in
1397 // UTF-8.
1398
1399 // A Unicode code-point can have upto 21 bits, and is encoded in UTF-8
1400 // like this:
1401 //
1402 // Code-point length Encoding
1403 // 0 - 7 bits 0xxxxxxx
1404 // 8 - 11 bits 110xxxxx 10xxxxxx
1405 // 12 - 16 bits 1110xxxx 10xxxxxx 10xxxxxx
1406 // 17 - 21 bits 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
1407
1408 // The maximum code-point a one-byte UTF-8 sequence can represent.
1409 const UInt32 kMaxCodePoint1 = (static_cast<UInt32>(1) << 7) - 1;
1410
1411 // The maximum code-point a two-byte UTF-8 sequence can represent.
1412 const UInt32 kMaxCodePoint2 = (static_cast<UInt32>(1) << (5 + 6)) - 1;
1413
1414 // The maximum code-point a three-byte UTF-8 sequence can represent.
1415 const UInt32 kMaxCodePoint3 = (static_cast<UInt32>(1) << (4 + 2*6)) - 1;
1416
1417 // The maximum code-point a four-byte UTF-8 sequence can represent.
1418 const UInt32 kMaxCodePoint4 = (static_cast<UInt32>(1) << (3 + 3*6)) - 1;
1419
1420 // Chops off the n lowest bits from a bit pattern. Returns the n
1421 // lowest bits. As a side effect, the original bit pattern will be
1422 // shifted to the right by n bits.
1423 inline UInt32 ChopLowBits(UInt32* bits, int n) {
1424 const UInt32 low_bits = *bits & ((static_cast<UInt32>(1) << n) - 1);
1425 *bits >>= n;
1426 return low_bits;
1427 }
1428
1429 // Converts a Unicode code point to a narrow string in UTF-8 encoding.
1430 // code_point parameter is of type UInt32 because wchar_t may not be
1431 // wide enough to contain a code point.
1432 // If the code_point is not a valid Unicode code point
1433 // (i.e. outside of Unicode range U+0 to U+10FFFF) it will be converted
1434 // to "(Invalid Unicode 0xXXXXXXXX)".
1435 std::string CodePointToUtf8(UInt32 code_point) {
1436 if (code_point > kMaxCodePoint4) {
1437 return "(Invalid Unicode 0x" + String::FormatHexInt(code_point) + ")";
1438 }
1439
1440 char str[5]; // Big enough for the largest valid code point.
1441 if (code_point <= kMaxCodePoint1) {
1442 str[1] = '\0';
1443 str[0] = static_cast<char>(code_point); // 0xxxxxxx
1444 } else if (code_point <= kMaxCodePoint2) {
1445 str[2] = '\0';
1446 str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
1447 str[0] = static_cast<char>(0xC0 | code_point); // 110xxxxx
1448 } else if (code_point <= kMaxCodePoint3) {
1449 str[3] = '\0';
1450 str[2] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
1451 str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
1452 str[0] = static_cast<char>(0xE0 | code_point); // 1110xxxx
1453 } else { // code_point <= kMaxCodePoint4
1454 str[4] = '\0';
1455 str[3] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
1456 str[2] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
1457 str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
1458 str[0] = static_cast<char>(0xF0 | code_point); // 11110xxx
1459 }
1460 return str;
1461 }
1462
1463 // The following two functions only make sense if the the system
1464 // uses UTF-16 for wide string encoding. All supported systems
1465 // with 16 bit wchar_t (Windows, Cygwin, Symbian OS) do use UTF-16.
1466
1467 // Determines if the arguments constitute UTF-16 surrogate pair
1468 // and thus should be combined into a single Unicode code point
1469 // using CreateCodePointFromUtf16SurrogatePair.
1470 inline bool IsUtf16SurrogatePair(wchar_t first, wchar_t second) {
1471 return sizeof(wchar_t) == 2 &&
1472 (first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00;
1473 }
1474
1475 // Creates a Unicode code point from UTF16 surrogate pair.
1476 inline UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first,
1477 wchar_t second) {
1478 const UInt32 mask = (1 << 10) - 1;
1479 return (sizeof(wchar_t) == 2) ?
1480 (((first & mask) << 10) | (second & mask)) + 0x10000 :
1481 // This function should not be called when the condition is
1482 // false, but we provide a sensible default in case it is.
1483 static_cast<UInt32>(first);
1484 }
1485
1486 // Converts a wide string to a narrow string in UTF-8 encoding.
1487 // The wide string is assumed to have the following encoding:
1488 // UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
1489 // UTF-32 if sizeof(wchar_t) == 4 (on Linux)
1490 // Parameter str points to a null-terminated wide string.
1491 // Parameter num_chars may additionally limit the number
1492 // of wchar_t characters processed. -1 is used when the entire string
1493 // should be processed.
1494 // If the string contains code points that are not valid Unicode code points
1495 // (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
1496 // as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
1497 // and contains invalid UTF-16 surrogate pairs, values in those pairs
1498 // will be encoded as individual Unicode characters from Basic Normal Plane.
1499 std::string WideStringToUtf8(const wchar_t* str, int num_chars) {
1500 if (num_chars == -1)
1501 num_chars = static_cast<int>(wcslen(str));
1502
1503 ::std::stringstream stream;
1504 for (int i = 0; i < num_chars; ++i) {
1505 UInt32 unicode_code_point;
1506
1507 if (str[i] == L'\0') {
1508 break;
1509 } else if (i + 1 < num_chars && IsUtf16SurrogatePair(str[i], str[i + 1])) {
1510 unicode_code_point = CreateCodePointFromUtf16SurrogatePair(str[i],
1511 str[i + 1]);
1512 i++;
1513 } else {
1514 unicode_code_point = static_cast<UInt32>(str[i]);
1515 }
1516
1517 stream << CodePointToUtf8(unicode_code_point);
1518 }
1519 return StringStreamToString(&stream);
1520 }
1521
1522 // Converts a wide C string to an std::string using the UTF-8 encoding.
1523 // NULL will be converted to "(null)".
1524 std::string String::ShowWideCString(const wchar_t * wide_c_str) {
1525 if (wide_c_str == NULL) return "(null)";
1526
1527 return internal::WideStringToUtf8(wide_c_str, -1);
1528 }
1529
1530 // Compares two wide C strings. Returns true iff they have the same
1531 // content.
1532 //
1533 // Unlike wcscmp(), this function can handle NULL argument(s). A NULL
1534 // C string is considered different to any non-NULL C string,
1535 // including the empty string.
1536 bool String::WideCStringEquals(const wchar_t * lhs, const wchar_t * rhs) {
1537 if (lhs == NULL) return rhs == NULL;
1538
1539 if (rhs == NULL) return false;
1540
1541 return wcscmp(lhs, rhs) == 0;
1542 }
1543
1544 // Helper function for *_STREQ on wide strings.
1545 AssertionResult CmpHelperSTREQ(const char* expected_expression,
1546 const char* actual_expression,
1547 const wchar_t* expected,
1548 const wchar_t* actual) {
1549 if (String::WideCStringEquals(expected, actual)) {
1550 return AssertionSuccess();
1551 }
1552
1553 return EqFailure(expected_expression,
1554 actual_expression,
1555 PrintToString(expected),
1556 PrintToString(actual),
1557 false);
1558 }
1559
1560 // Helper function for *_STRNE on wide strings.
1561 AssertionResult CmpHelperSTRNE(const char* s1_expression,
1562 const char* s2_expression,
1563 const wchar_t* s1,
1564 const wchar_t* s2) {
1565 if (!String::WideCStringEquals(s1, s2)) {
1566 return AssertionSuccess();
1567 }
1568
1569 return AssertionFailure() << "Expected: (" << s1_expression << ") != ("
1570 << s2_expression << "), actual: "
1571 << PrintToString(s1)
1572 << " vs " << PrintToString(s2);
1573 }
1574
1575 // Compares two C strings, ignoring case. Returns true iff they have
1576 // the same content.
1577 //
1578 // Unlike strcasecmp(), this function can handle NULL argument(s). A
1579 // NULL C string is considered different to any non-NULL C string,
1580 // including the empty string.
1581 bool String::CaseInsensitiveCStringEquals(const char * lhs, const char * rhs) {
1582 if (lhs == NULL)
1583 return rhs == NULL;
1584 if (rhs == NULL)
1585 return false;
1586 return posix::StrCaseCmp(lhs, rhs) == 0;
1587 }
1588
1589 // Compares two wide C strings, ignoring case. Returns true iff they
1590 // have the same content.
1591 //
1592 // Unlike wcscasecmp(), this function can handle NULL argument(s).
1593 // A NULL C string is considered different to any non-NULL wide C string,
1594 // including the empty string.
1595 // NB: The implementations on different platforms slightly differ.
1596 // On windows, this method uses _wcsicmp which compares according to LC_CTYPE
1597 // environment variable. On GNU platform this method uses wcscasecmp
1598 // which compares according to LC_CTYPE category of the current locale.
1599 // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the
1600 // current locale.
1601 bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
1602 const wchar_t* rhs) {
1603 if (lhs == NULL) return rhs == NULL;
1604
1605 if (rhs == NULL) return false;
1606
1607 #if GTEST_OS_WINDOWS
1608 return _wcsicmp(lhs, rhs) == 0;
1609 #elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID
1610 return wcscasecmp(lhs, rhs) == 0;
1611 #else
1612 // Android, Mac OS X and Cygwin don't define wcscasecmp.
1613 // Other unknown OSes may not define it either.
1614 wint_t left, right;
1615 do {
1616 left = towlower(*lhs++);
1617 right = towlower(*rhs++);
1618 } while (left && left == right);
1619 return left == right;
1620 #endif // OS selector
1621 }
1622
1623 // Returns true iff str ends with the given suffix, ignoring case.
1624 // Any string is considered to end with an empty suffix.
1625 bool String::EndsWithCaseInsensitive(
1626 const std::string& str, const std::string& suffix) {
1627 const size_t str_len = str.length();
1628 const size_t suffix_len = suffix.length();
1629 return (str_len >= suffix_len) &&
1630 CaseInsensitiveCStringEquals(str.c_str() + str_len - suffix_len,
1631 suffix.c_str());
1632 }
1633
1634 // Formats an int value as "%02d".
1635 std::string String::FormatIntWidth2(int value) {
1636 std::stringstream ss;
1637 ss << std::setfill('0') << std::setw(2) << value;
1638 return ss.str();
1639 }
1640
1641 // Formats an int value as "%X".
1642 std::string String::FormatHexInt(int value) {
1643 std::stringstream ss;
1644 ss << std::hex << std::uppercase << value;
1645 return ss.str();
1646 }
1647
1648 // Formats a byte as "%02X".
1649 std::string String::FormatByte(unsigned char value) {
1650 std::stringstream ss;
1651 ss << std::setfill('0') << std::setw(2) << std::hex << std::uppercase
1652 << static_cast<unsigned int>(value);
1653 return ss.str();
1654 }
1655
1656 // Converts the buffer in a stringstream to an std::string, converting NUL
1657 // bytes to "\\0" along the way.
1658 std::string StringStreamToString(::std::stringstream* ss) {
1659 const ::std::string& str = ss->str();
1660 const char* const start = str.c_str();
1661 const char* const end = start + str.length();
1662
1663 std::string result;
1664 result.reserve(2 * (end - start));
1665 for (const char* ch = start; ch != end; ++ch) {
1666 if (*ch == '\0') {
1667 result += "\\0"; // Replaces NUL with "\\0";
1668 } else {
1669 result += *ch;
1670 }
1671 }
1672
1673 return result;
1674 }
1675
1676 // Appends the user-supplied message to the Google-Test-generated message.
1677 std::string AppendUserMessage(const std::string& gtest_msg,
1678 const Message& user_msg) {
1679 // Appends the user message if it's non-empty.
1680 const std::string user_msg_string = user_msg.GetString();
1681 if (user_msg_string.empty()) {
1682 return gtest_msg;
1683 }
1684
1685 return gtest_msg + "\n" + user_msg_string;
1686 }
1687
1688 } // namespace internal
1689
1690 // class TestResult
1691
1692 // Creates an empty TestResult.
1693 TestResult::TestResult()
1694 : death_test_count_(0),
1695 elapsed_time_(0) {
1696 }
1697
1698 // D'tor.
1699 TestResult::~TestResult() {
1700 }
1701
1702 // Returns the i-th test part result among all the results. i can
1703 // range from 0 to total_part_count() - 1. If i is not in that range,
1704 // aborts the program.
1705 const TestPartResult& TestResult::GetTestPartResult(int i) const {
1706 if (i < 0 || i >= total_part_count())
1707 internal::posix::Abort();
1708 return test_part_results_.at(i);
1709 }
1710
1711 // Returns the i-th test property. i can range from 0 to
1712 // test_property_count() - 1. If i is not in that range, aborts the
1713 // program.
1714 const TestProperty& TestResult::GetTestProperty(int i) const {
1715 if (i < 0 || i >= test_property_count())
1716 internal::posix::Abort();
1717 return test_properties_.at(i);
1718 }
1719
1720 // Clears the test part results.
1721 void TestResult::ClearTestPartResults() {
1722 test_part_results_.clear();
1723 }
1724
1725 // Adds a test part result to the list.
1726 void TestResult::AddTestPartResult(const TestPartResult& test_part_result) {
1727 test_part_results_.push_back(test_part_result);
1728 }
1729
1730 // Adds a test property to the list. If a property with the same key as the
1731 // supplied property is already represented, the value of this test_property
1732 // replaces the old value for that key.
1733 void TestResult::RecordProperty(const std::string& xml_element,
1734 const TestProperty& test_property) {
1735 if (!ValidateTestProperty(xml_element, test_property)) {
1736 return;
1737 }
1738 internal::MutexLock lock(&test_properites_mutex_);
1739 const std::vector<TestProperty>::iterator property_with_matching_key =
1740 std::find_if(test_properties_.begin(), test_properties_.end(),
1741 internal::TestPropertyKeyIs(test_property.key()));
1742 if (property_with_matching_key == test_properties_.end()) {
1743 test_properties_.push_back(test_property);
1744 return;
1745 }
1746 property_with_matching_key->SetValue(test_property.value());
1747 }
1748
1749 // The list of reserved attributes used in the <testsuites> element of XML
1750 // output.
1751 static const char* const kReservedTestSuitesAttributes[] = {
1752 "disabled",
1753 "errors",
1754 "failures",
1755 "name",
1756 "random_seed",
1757 "tests",
1758 "time",
1759 "timestamp"
1760 };
1761
1762 // The list of reserved attributes used in the <testsuite> element of XML
1763 // output.
1764 static const char* const kReservedTestSuiteAttributes[] = {
1765 "disabled",
1766 "errors",
1767 "failures",
1768 "name",
1769 "tests",
1770 "time"
1771 };
1772
1773 // The list of reserved attributes used in the <testcase> element of XML output.
1774 static const char* const kReservedTestCaseAttributes[] = {
1775 "classname",
1776 "name",
1777 "status",
1778 "time",
1779 "type_param",
1780 "value_param"
1781 };
1782
1783 template <int kSize>
1784 std::vector<std::string> ArrayAsVector(const char* const (&array)[kSize]) {
1785 return std::vector<std::string>(array, array + kSize);
1786 }
1787
1788 static std::vector<std::string> GetReservedAttributesForElement(
1789 const std::string& xml_element) {
1790 if (xml_element == "testsuites") {
1791 return ArrayAsVector(kReservedTestSuitesAttributes);
1792 } else if (xml_element == "testsuite") {
1793 return ArrayAsVector(kReservedTestSuiteAttributes);
1794 } else if (xml_element == "testcase") {
1795 return ArrayAsVector(kReservedTestCaseAttributes);
1796 } else {
1797 GTEST_CHECK_(false) << "Unrecognized xml_element provided: " << xml_element;
1798 }
1799 // This code is unreachable but some compilers may not realizes that.
1800 return std::vector<std::string>();
1801 }
1802
1803 static std::string FormatWordList(const std::vector<std::string>& words) {
1804 Message word_list;
1805 for (size_t i = 0; i < words.size(); ++i) {
1806 if (i > 0 && words.size() > 2) {
1807 word_list << ", ";
1808 }
1809 if (i == words.size() - 1) {
1810 word_list << "and ";
1811 }
1812 word_list << "'" << words[i] << "'";
1813 }
1814 return word_list.GetString();
1815 }
1816
1817 bool ValidateTestPropertyName(const std::string& property_name,
1818 const std::vector<std::string>& reserved_names) {
1819 if (std::find(reserved_names.begin(), reserved_names.end(), property_name) !=
1820 reserved_names.end()) {
1821 ADD_FAILURE() << "Reserved key used in RecordProperty(): " << property_name
1822 << " (" << FormatWordList(reserved_names)
1823 << " are reserved by " << GTEST_NAME_ << ")";
1824 return false;
1825 }
1826 return true;
1827 }
1828
1829 // Adds a failure if the key is a reserved attribute of the element named
1830 // xml_element. Returns true if the property is valid.
1831 bool TestResult::ValidateTestProperty(const std::string& xml_element,
1832 const TestProperty& test_property) {
1833 return ValidateTestPropertyName(test_property.key(),
1834 GetReservedAttributesForElement(xml_element));
1835 }
1836
1837 // Clears the object.
1838 void TestResult::Clear() {
1839 test_part_results_.clear();
1840 test_properties_.clear();
1841 death_test_count_ = 0;
1842 elapsed_time_ = 0;
1843 }
1844
1845 // Returns true iff the test failed.
1846 bool TestResult::Failed() const {
1847 for (int i = 0; i < total_part_count(); ++i) {
1848 if (GetTestPartResult(i).failed())
1849 return true;
1850 }
1851 return false;
1852 }
1853
1854 // Returns true iff the test part fatally failed.
1855 static bool TestPartFatallyFailed(const TestPartResult& result) {
1856 return result.fatally_failed();
1857 }
1858
1859 // Returns true iff the test fatally failed.
1860 bool TestResult::HasFatalFailure() const {
1861 return CountIf(test_part_results_, TestPartFatallyFailed) > 0;
1862 }
1863
1864 // Returns true iff the test part non-fatally failed.
1865 static bool TestPartNonfatallyFailed(const TestPartResult& result) {
1866 return result.nonfatally_failed();
1867 }
1868
1869 // Returns true iff the test has a non-fatal failure.
1870 bool TestResult::HasNonfatalFailure() const {
1871 return CountIf(test_part_results_, TestPartNonfatallyFailed) > 0;
1872 }
1873
1874 // Gets the number of all test parts. This is the sum of the number
1875 // of successful test parts and the number of failed test parts.
1876 int TestResult::total_part_count() const {
1877 return static_cast<int>(test_part_results_.size());
1878 }
1879
1880 // Returns the number of the test properties.
1881 int TestResult::test_property_count() const {
1882 return static_cast<int>(test_properties_.size());
1883 }
1884
1885 // class Test
1886
1887 // Creates a Test object.
1888
1889 // The c'tor saves the values of all Google Test flags.
1890 Test::Test()
1891 : gtest_flag_saver_(new internal::GTestFlagSaver) {
1892 }
1893
1894 // The d'tor restores the values of all Google Test flags.
1895 Test::~Test() {
1896 delete gtest_flag_saver_;
1897 }
1898
1899 // Sets up the test fixture.
1900 //
1901 // A sub-class may override this.
1902 void Test::SetUp() {
1903 }
1904
1905 // Tears down the test fixture.
1906 //
1907 // A sub-class may override this.
1908 void Test::TearDown() {
1909 }
1910
1911 // Allows user supplied key value pairs to be recorded for later output.
1912 void Test::RecordProperty(const std::string& key, const std::string& value) {
1913 UnitTest::GetInstance()->RecordProperty(key, value);
1914 }
1915
1916 // Allows user supplied key value pairs to be recorded for later output.
1917 void Test::RecordProperty(const std::string& key, int value) {
1918 Message value_message;
1919 value_message << value;
1920 RecordProperty(key, value_message.GetString().c_str());
1921 }
1922
1923 namespace internal {
1924
1925 void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
1926 const std::string& message) {
1927 // This function is a friend of UnitTest and as such has access to
1928 // AddTestPartResult.
1929 UnitTest::GetInstance()->AddTestPartResult(
1930 result_type,
1931 NULL, // No info about the source file where the exception occurred.
1932 -1, // We have no info on which line caused the exception.
1933 message,
1934 ""); // No stack trace, either.
1935 }
1936
1937 } // namespace internal
1938
1939 // Google Test requires all tests in the same test case to use the same test
1940 // fixture class. This function checks if the current test has the
1941 // same fixture class as the first test in the current test case. If
1942 // yes, it returns true; otherwise it generates a Google Test failure and
1943 // returns false.
1944 bool Test::HasSameFixtureClass() {
1945 internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
1946 const TestCase* const test_case = impl->current_test_case();
1947
1948 // Info about the first test in the current test case.
1949 const TestInfo* const first_test_info = test_case->test_info_list()[0];
1950 const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;
1951 const char* const first_test_name = first_test_info->name();
1952
1953 // Info about the current test.
1954 const TestInfo* const this_test_info = impl->current_test_info();
1955 const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_;
1956 const char* const this_test_name = this_test_info->name();
1957
1958 if (this_fixture_id != first_fixture_id) {
1959 // Is the first test defined using TEST?
1960 const bool first_is_TEST = first_fixture_id == internal::GetTestTypeId();
1961 // Is this test defined using TEST?
1962 const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId();
1963
1964 if (first_is_TEST || this_is_TEST) {
1965 // The user mixed TEST and TEST_F in this test case - we'll tell
1966 // him/her how to fix it.
1967
1968 // Gets the name of the TEST and the name of the TEST_F. Note
1969 // that first_is_TEST and this_is_TEST cannot both be true, as
1970 // the fixture IDs are different for the two tests.
1971 const char* const TEST_name =
1972 first_is_TEST ? first_test_name : this_test_name;
1973 const char* const TEST_F_name =
1974 first_is_TEST ? this_test_name : first_test_name;
1975
1976 ADD_FAILURE()
1977 << "All tests in the same test case must use the same test fixture\n"
1978 << "class, so mixing TEST_F and TEST in the same test case is\n"
1979 << "illegal. In test case " << this_test_info->test_case_name()
1980 << ",\n"
1981 << "test " << TEST_F_name << " is defined using TEST_F but\n"
1982 << "test " << TEST_name << " is defined using TEST. You probably\n"
1983 << "want to change the TEST to TEST_F or move it to another test\n"
1984 << "case.";
1985 } else {
1986 // The user defined two fixture classes with the same name in
1987 // two namespaces - we'll tell him/her how to fix it.
1988 ADD_FAILURE()
1989 << "All tests in the same test case must use the same test fixture\n"
1990 << "class. However, in test case "
1991 << this_test_info->test_case_name() << ",\n"
1992 << "you defined test " << first_test_name
1993 << " and test " << this_test_name << "\n"
1994 << "using two different test fixture classes. This can happen if\n"
1995 << "the two classes are from different namespaces or translation\n"
1996 << "units and have the same name. You should probably rename one\n"
1997 << "of the classes to put the tests into different test cases.";
1998 }
1999 return false;
2000 }
2001
2002 return true;
2003 }
2004
2005 #if GTEST_HAS_SEH
2006
2007 // Adds an "exception thrown" fatal failure to the current test. This
2008 // function returns its result via an output parameter pointer because VC++
2009 // prohibits creation of objects with destructors on stack in functions
2010 // using __try (see error C2712).
2011 static std::string* FormatSehExceptionMessage(DWORD exception_code,
2012 const char* location) {
2013 Message message;
2014 message << "SEH exception with code 0x" << std::setbase(16) <<
2015 exception_code << std::setbase(10) << " thrown in " << location << ".";
2016
2017 return new std::string(message.GetString());
2018 }
2019
2020 #endif // GTEST_HAS_SEH
2021
2022 namespace internal {
2023
2024 #if GTEST_HAS_EXCEPTIONS
2025
2026 // Adds an "exception thrown" fatal failure to the current test.
2027 static std::string FormatCxxExceptionMessage(const char* description,
2028 const char* location) {
2029 Message message;
2030 if (description != NULL) {
2031 message << "C++ exception with description \"" << description << "\"";
2032 } else {
2033 message << "Unknown C++ exception";
2034 }
2035 message << " thrown in " << location << ".";
2036
2037 return message.GetString();
2038 }
2039
2040 static std::string PrintTestPartResultToString(
2041 const TestPartResult& test_part_result);
2042
2043 GoogleTestFailureException::GoogleTestFailureException(
2044 const TestPartResult& failure)
2045 : ::std::runtime_error(PrintTestPartResultToString(failure).c_str()) {}
2046
2047 #endif // GTEST_HAS_EXCEPTIONS
2048
2049 // We put these helper functions in the internal namespace as IBM's xlC
2050 // compiler rejects the code if they were declared static.
2051
2052 // Runs the given method and handles SEH exceptions it throws, when
2053 // SEH is supported; returns the 0-value for type Result in case of an
2054 // SEH exception. (Microsoft compilers cannot handle SEH and C++
2055 // exceptions in the same function. Therefore, we provide a separate
2056 // wrapper function for handling SEH exceptions.)
2057 template <class T, typename Result>
2058 Result HandleSehExceptionsInMethodIfSupported(
2059 T* object, Result (T::*method)(), const char* location) {
2060 #if GTEST_HAS_SEH
2061 __try {
2062 return (object->*method)();
2063 } __except (internal::UnitTestOptions::GTestShouldProcessSEH( // NOLINT
2064 GetExceptionCode())) {
2065 // We create the exception message on the heap because VC++ prohibits
2066 // creation of objects with destructors on stack in functions using __try
2067 // (see error C2712).
2068 std::string* exception_message = FormatSehExceptionMessage(
2069 GetExceptionCode(), location);
2070 internal::ReportFailureInUnknownLocation(TestPartResult::kFatalFailure,
2071 *exception_message);
2072 delete exception_message;
2073 return static_cast<Result>(0);
2074 }
2075 #else
2076 (void)location;
2077 return (object->*method)();
2078 #endif // GTEST_HAS_SEH
2079 }
2080
2081 // Runs the given method and catches and reports C++ and/or SEH-style
2082 // exceptions, if they are supported; returns the 0-value for type
2083 // Result in case of an SEH exception.
2084 template <class T, typename Result>
2085 Result HandleExceptionsInMethodIfSupported(
2086 T* object, Result (T::*method)(), const char* location) {
2087 // NOTE: The user code can affect the way in which Google Test handles
2088 // exceptions by setting GTEST_FLAG(catch_exceptions), but only before
2089 // RUN_ALL_TESTS() starts. It is technically possible to check the flag
2090 // after the exception is caught and either report or re-throw the
2091 // exception based on the flag's value:
2092 //
2093 // try {
2094 // // Perform the test method.
2095 // } catch (...) {
2096 // if (GTEST_FLAG(catch_exceptions))
2097 // // Report the exception as failure.
2098 // else
2099 // throw; // Re-throws the original exception.
2100 // }
2101 //
2102 // However, the purpose of this flag is to allow the program to drop into
2103 // the debugger when the exception is thrown. On most platforms, once the
2104 // control enters the catch block, the exception origin information is
2105 // lost and the debugger will stop the program at the point of the
2106 // re-throw in this function -- instead of at the point of the original
2107 // throw statement in the code under test. For this reason, we perform
2108 // the check early, sacrificing the ability to affect Google Test's
2109 // exception handling in the method where the exception is thrown.
2110 if (internal::GetUnitTestImpl()->catch_exceptions()) {
2111 #if GTEST_HAS_EXCEPTIONS
2112 try {
2113 return HandleSehExceptionsInMethodIfSupported(object, method, location);
2114 } catch (const internal::GoogleTestFailureException&) { // NOLINT
2115 // This exception type can only be thrown by a failed Google
2116 // Test assertion with the intention of letting another testing
2117 // framework catch it. Therefore we just re-throw it.
2118 throw;
2119 } catch (const std::exception& e) { // NOLINT
2120 internal::ReportFailureInUnknownLocation(
2121 TestPartResult::kFatalFailure,
2122 FormatCxxExceptionMessage(e.what(), location));
2123 } catch (...) { // NOLINT
2124 internal::ReportFailureInUnknownLocation(
2125 TestPartResult::kFatalFailure,
2126 FormatCxxExceptionMessage(NULL, location));
2127 }
2128 return static_cast<Result>(0);
2129 #else
2130 return HandleSehExceptionsInMethodIfSupported(object, method, location);
2131 #endif // GTEST_HAS_EXCEPTIONS
2132 } else {
2133 return (object->*method)();
2134 }
2135 }
2136
2137 } // namespace internal
2138
2139 // Runs the test and updates the test result.
2140 void Test::Run() {
2141 if (!HasSameFixtureClass()) return;
2142
2143 internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
2144 impl->os_stack_trace_getter()->UponLeavingGTest();
2145 internal::HandleExceptionsInMethodIfSupported(this, &Test::SetUp, "SetUp()");
2146 // We will run the test only if SetUp() was successful.
2147 if (!HasFatalFailure()) {
2148 impl->os_stack_trace_getter()->UponLeavingGTest();
2149 internal::HandleExceptionsInMethodIfSupported(
2150 this, &Test::TestBody, "the test body");
2151 }
2152
2153 // However, we want to clean up as much as possible. Hence we will
2154 // always call TearDown(), even if SetUp() or the test body has
2155 // failed.
2156 impl->os_stack_trace_getter()->UponLeavingGTest();
2157 internal::HandleExceptionsInMethodIfSupported(
2158 this, &Test::TearDown, "TearDown()");
2159 }
2160
2161 // Returns true iff the current test has a fatal failure.
2162 bool Test::HasFatalFailure() {
2163 return internal::GetUnitTestImpl()->current_test_result()->HasFatalFailure();
2164 }
2165
2166 // Returns true iff the current test has a non-fatal failure.
2167 bool Test::HasNonfatalFailure() {
2168 return internal::GetUnitTestImpl()->current_test_result()->
2169 HasNonfatalFailure();
2170 }
2171
2172 // class TestInfo
2173
2174 // Constructs a TestInfo object. It assumes ownership of the test factory
2175 // object.
2176 TestInfo::TestInfo(const std::string& a_test_case_name,
2177 const std::string& a_name,
2178 const char* a_type_param,
2179 const char* a_value_param,
2180 internal::TypeId fixture_class_id,
2181 internal::TestFactoryBase* factory)
2182 : test_case_name_(a_test_case_name),
2183 name_(a_name),
2184 type_param_(a_type_param ? new std::string(a_type_param) : NULL),
2185 value_param_(a_value_param ? new std::string(a_value_param) : NULL),
2186 fixture_class_id_(fixture_class_id),
2187 should_run_(false),
2188 is_disabled_(false),
2189 matches_filter_(false),
2190 factory_(factory),
2191 result_() {}
2192
2193 // Destructs a TestInfo object.
2194 TestInfo::~TestInfo() { delete factory_; }
2195
2196 namespace internal {
2197
2198 // Creates a new TestInfo object and registers it with Google Test;
2199 // returns the created object.
2200 //
2201 // Arguments:
2202 //
2203 // test_case_name: name of the test case
2204 // name: name of the test
2205 // type_param: the name of the test's type parameter, or NULL if
2206 // this is not a typed or a type-parameterized test.
2207 // value_param: text representation of the test's value parameter,
2208 // or NULL if this is not a value-parameterized test.
2209 // fixture_class_id: ID of the test fixture class
2210 // set_up_tc: pointer to the function that sets up the test case
2211 // tear_down_tc: pointer to the function that tears down the test case
2212 // factory: pointer to the factory that creates a test object.
2213 // The newly created TestInfo instance will assume
2214 // ownership of the factory object.
2215 TestInfo* MakeAndRegisterTestInfo(
2216 const char* test_case_name,
2217 const char* name,
2218 const char* type_param,
2219 const char* value_param,
2220 TypeId fixture_class_id,
2221 SetUpTestCaseFunc set_up_tc,
2222 TearDownTestCaseFunc tear_down_tc,
2223 TestFactoryBase* factory) {
2224 TestInfo* const test_info =
2225 new TestInfo(test_case_name, name, type_param, value_param,
2226 fixture_class_id, factory);
2227 GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info);
2228 return test_info;
2229 }
2230
2231 #if GTEST_HAS_PARAM_TEST
2232 void ReportInvalidTestCaseType(const char* test_case_name,
2233 const char* file, int line) {
2234 Message errors;
2235 errors
2236 << "Attempted redefinition of test case " << test_case_name << ".\n"
2237 << "All tests in the same test case must use the same test fixture\n"
2238 << "class. However, in test case " << test_case_name << ", you tried\n"
2239 << "to define a test using a fixture class different from the one\n"
2240 << "used earlier. This can happen if the two fixture classes are\n"
2241 << "from different namespaces and have the same name. You should\n"
2242 << "probably rename one of the classes to put the tests into different\n"
2243 << "test cases.";
2244
2245 fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
2246 errors.GetString().c_str());
2247 }
2248 #endif // GTEST_HAS_PARAM_TEST
2249
2250 } // namespace internal
2251
2252 namespace {
2253
2254 // A predicate that checks the test name of a TestInfo against a known
2255 // value.
2256 //
2257 // This is used for implementation of the TestCase class only. We put
2258 // it in the anonymous namespace to prevent polluting the outer
2259 // namespace.
2260 //
2261 // TestNameIs is copyable.
2262 class TestNameIs {
2263 public:
2264 // Constructor.
2265 //
2266 // TestNameIs has NO default constructor.
2267 explicit TestNameIs(const char* name)
2268 : name_(name) {}
2269
2270 // Returns true iff the test name of test_info matches name_.
2271 bool operator()(const TestInfo * test_info) const {
2272 return test_info && test_info->name() == name_;
2273 }
2274
2275 private:
2276 std::string name_;
2277 };
2278
2279 } // namespace
2280
2281 namespace internal {
2282
2283 // This method expands all parameterized tests registered with macros TEST_P
2284 // and INSTANTIATE_TEST_CASE_P into regular tests and registers those.
2285 // This will be done just once during the program runtime.
2286 void UnitTestImpl::RegisterParameterizedTests() {
2287 #if GTEST_HAS_PARAM_TEST
2288 if (!parameterized_tests_registered_) {
2289 parameterized_test_registry_.RegisterTests();
2290 parameterized_tests_registered_ = true;
2291 }
2292 #endif
2293 }
2294
2295 } // namespace internal
2296
2297 // Creates the test object, runs it, records its result, and then
2298 // deletes it.
2299 void TestInfo::Run() {
2300 if (!should_run_) return;
2301
2302 // Tells UnitTest where to store test result.
2303 internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
2304 impl->set_current_test_info(this);
2305
2306 TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
2307
2308 // Notifies the unit test event listeners that a test is about to start.
2309 repeater->OnTestStart(*this);
2310
2311 const TimeInMillis start = internal::GetTimeInMillis();
2312
2313 impl->os_stack_trace_getter()->UponLeavingGTest();
2314
2315 // Creates the test object.
2316 Test* const test = internal::HandleExceptionsInMethodIfSupported(
2317 factory_, &internal::TestFactoryBase::CreateTest,
2318 "the test fixture's constructor");
2319
2320 // Runs the test only if the test object was created and its
2321 // constructor didn't generate a fatal failure.
2322 if ((test != NULL) && !Test::HasFatalFailure()) {
2323 // This doesn't throw as all user code that can throw are wrapped into
2324 // exception handling code.
2325 test->Run();
2326 }
2327
2328 // Deletes the test object.
2329 impl->os_stack_trace_getter()->UponLeavingGTest();
2330 internal::HandleExceptionsInMethodIfSupported(
2331 test, &Test::DeleteSelf_, "the test fixture's destructor");
2332
2333 result_.set_elapsed_time(internal::GetTimeInMillis() - start);
2334
2335 // Notifies the unit test event listener that a test has just finished.
2336 repeater->OnTestEnd(*this);
2337
2338 // Tells UnitTest to stop associating assertion results to this
2339 // test.
2340 impl->set_current_test_info(NULL);
2341 }
2342
2343 // class TestCase
2344
2345 // Gets the number of successful tests in this test case.
2346 int TestCase::successful_test_count() const {
2347 return CountIf(test_info_list_, TestPassed);
2348 }
2349
2350 // Gets the number of failed tests in this test case.
2351 int TestCase::failed_test_count() const {
2352 return CountIf(test_info_list_, TestFailed);
2353 }
2354
2355 // Gets the number of disabled tests that will be reported in the XML report.
2356 int TestCase::reportable_disabled_test_count() const {
2357 return CountIf(test_info_list_, TestReportableDisabled);
2358 }
2359
2360 // Gets the number of disabled tests in this test case.
2361 int TestCase::disabled_test_count() const {
2362 return CountIf(test_info_list_, TestDisabled);
2363 }
2364
2365 // Gets the number of tests to be printed in the XML report.
2366 int TestCase::reportable_test_count() const {
2367 return CountIf(test_info_list_, TestReportable);
2368 }
2369
2370 // Get the number of tests in this test case that should run.
2371 int TestCase::test_to_run_count() const {
2372 return CountIf(test_info_list_, ShouldRunTest);
2373 }
2374
2375 // Gets the number of all tests.
2376 int TestCase::total_test_count() const {
2377 return static_cast<int>(test_info_list_.size());
2378 }
2379
2380 // Creates a TestCase with the given name.
2381 //
2382 // Arguments:
2383 //
2384 // name: name of the test case
2385 // a_type_param: the name of the test case's type parameter, or NULL if
2386 // this is not a typed or a type-parameterized test case.
2387 // set_up_tc: pointer to the function that sets up the test case
2388 // tear_down_tc: pointer to the function that tears down the test case
2389 TestCase::TestCase(const char* a_name, const char* a_type_param,
2390 Test::SetUpTestCaseFunc set_up_tc,
2391 Test::TearDownTestCaseFunc tear_down_tc)
2392 : name_(a_name),
2393 type_param_(a_type_param ? new std::string(a_type_param) : NULL),
2394 set_up_tc_(set_up_tc),
2395 tear_down_tc_(tear_down_tc),
2396 should_run_(false),
2397 elapsed_time_(0) {
2398 }
2399
2400 // Destructor of TestCase.
2401 TestCase::~TestCase() {
2402 // Deletes every Test in the collection.
2403 ForEach(test_info_list_, internal::Delete<TestInfo>);
2404 }
2405
2406 // Returns the i-th test among all the tests. i can range from 0 to
2407 // total_test_count() - 1. If i is not in that range, returns NULL.
2408 const TestInfo* TestCase::GetTestInfo(int i) const {
2409 const int index = GetElementOr(test_indices_, i, -1);
2410 return index < 0 ? NULL : test_info_list_[index];
2411 }
2412
2413 // Returns the i-th test among all the tests. i can range from 0 to
2414 // total_test_count() - 1. If i is not in that range, returns NULL.
2415 TestInfo* TestCase::GetMutableTestInfo(int i) {
2416 const int index = GetElementOr(test_indices_, i, -1);
2417 return index < 0 ? NULL : test_info_list_[index];
2418 }
2419
2420 // Adds a test to this test case. Will delete the test upon
2421 // destruction of the TestCase object.
2422 void TestCase::AddTestInfo(TestInfo * test_info) {
2423 test_info_list_.push_back(test_info);
2424 test_indices_.push_back(static_cast<int>(test_indices_.size()));
2425 }
2426
2427 // Runs every test in this TestCase.
2428 void TestCase::Run() {
2429 if (!should_run_) return;
2430
2431 internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
2432 impl->set_current_test_case(this);
2433
2434 TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
2435
2436 repeater->OnTestCaseStart(*this);
2437 impl->os_stack_trace_getter()->UponLeavingGTest();
2438 internal::HandleExceptionsInMethodIfSupported(
2439 this, &TestCase::RunSetUpTestCase, "SetUpTestCase()");
2440
2441 const internal::TimeInMillis start = internal::GetTimeInMillis();
2442 for (int i = 0; i < total_test_count(); i++) {
2443 GetMutableTestInfo(i)->Run();
2444 }
2445 elapsed_time_ = internal::GetTimeInMillis() - start;
2446
2447 impl->os_stack_trace_getter()->UponLeavingGTest();
2448 internal::HandleExceptionsInMethodIfSupported(
2449 this, &TestCase::RunTearDownTestCase, "TearDownTestCase()");
2450
2451 repeater->OnTestCaseEnd(*this);
2452 impl->set_current_test_case(NULL);
2453 }
2454
2455 // Clears the results of all tests in this test case.
2456 void TestCase::ClearResult() {
2457 ad_hoc_test_result_.Clear();
2458 ForEach(test_info_list_, TestInfo::ClearTestResult);
2459 }
2460
2461 // Shuffles the tests in this test case.
2462 void TestCase::ShuffleTests(internal::Random* random) {
2463 Shuffle(random, &test_indices_);
2464 }
2465
2466 // Restores the test order to before the first shuffle.
2467 void TestCase::UnshuffleTests() {
2468 for (size_t i = 0; i < test_indices_.size(); i++) {
2469 test_indices_[i] = static_cast<int>(i);
2470 }
2471 }
2472
2473 // Formats a countable noun. Depending on its quantity, either the
2474 // singular form or the plural form is used. e.g.
2475 //
2476 // FormatCountableNoun(1, "formula", "formuli") returns "1 formula".
2477 // FormatCountableNoun(5, "book", "books") returns "5 books".
2478 static std::string FormatCountableNoun(int count,
2479 const char * singular_form,
2480 const char * plural_form) {
2481 return internal::StreamableToString(count) + " " +
2482 (count == 1 ? singular_form : plural_form);
2483 }
2484
2485 // Formats the count of tests.
2486 static std::string FormatTestCount(int test_count) {
2487 return FormatCountableNoun(test_count, "test", "tests");
2488 }
2489
2490 // Formats the count of test cases.
2491 static std::string FormatTestCaseCount(int test_case_count) {
2492 return FormatCountableNoun(test_case_count, "test case", "test cases");
2493 }
2494
2495 // Converts a TestPartResult::Type enum to human-friendly string
2496 // representation. Both kNonFatalFailure and kFatalFailure are translated
2497 // to "Failure", as the user usually doesn't care about the difference
2498 // between the two when viewing the test result.
2499 static const char * TestPartResultTypeToString(TestPartResult::Type type) {
2500 switch (type) {
2501 case TestPartResult::kSuccess:
2502 return "Success";
2503
2504 case TestPartResult::kNonFatalFailure:
2505 case TestPartResult::kFatalFailure:
2506 #ifdef _MSC_VER
2507 return "error: ";
2508 #else
2509 return "Failure\n";
2510 #endif
2511 default:
2512 return "Unknown result type";
2513 }
2514 }
2515
2516 namespace internal {
2517
2518 // Prints a TestPartResult to an std::string.
2519 static std::string PrintTestPartResultToString(
2520 const TestPartResult& test_part_result) {
2521 return (Message()
2522 << internal::FormatFileLocation(test_part_result.file_name(),
2523 test_part_result.line_number())
2524 << " " << TestPartResultTypeToString(test_part_result.type())
2525 << test_part_result.message()).GetString();
2526 }
2527
2528 // Prints a TestPartResult.
2529 static void PrintTestPartResult(const TestPartResult& test_part_result) {
2530 const std::string& result =
2531 PrintTestPartResultToString(test_part_result);
2532 printf("%s\n", result.c_str());
2533 fflush(stdout);
2534 // If the test program runs in Visual Studio or a debugger, the
2535 // following statements add the test part result message to the Output
2536 // window such that the user can double-click on it to jump to the
2537 // corresponding source code location; otherwise they do nothing.
2538 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
2539 // We don't call OutputDebugString*() on Windows Mobile, as printing
2540 // to stdout is done by OutputDebugString() there already - we don't
2541 // want the same message printed twice.
2542 ::OutputDebugStringA(result.c_str());
2543 ::OutputDebugStringA("\n");
2544 #endif
2545 }
2546
2547 // class PrettyUnitTestResultPrinter
2548
2549 enum GTestColor {
2550 COLOR_DEFAULT,
2551 COLOR_RED,
2552 COLOR_GREEN,
2553 COLOR_YELLOW
2554 };
2555
2556 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
2557
2558 // Returns the character attribute for the given color.
2559 WORD GetColorAttribute(GTestColor color) {
2560 switch (color) {
2561 case COLOR_RED: return FOREGROUND_RED;
2562 case COLOR_GREEN: return FOREGROUND_GREEN;
2563 case COLOR_YELLOW: return FOREGROUND_RED | FOREGROUND_GREEN;
2564 default: return 0;
2565 }
2566 }
2567
2568 #else
2569
2570 // Returns the ANSI color code for the given color. COLOR_DEFAULT is
2571 // an invalid input.
2572 const char* GetAnsiColorCode(GTestColor color) {
2573 switch (color) {
2574 case COLOR_RED: return "1";
2575 case COLOR_GREEN: return "2";
2576 case COLOR_YELLOW: return "3";
2577 default: return NULL;
2578 };
2579 }
2580
2581 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
2582
2583 // Returns true iff Google Test should use colors in the output.
2584 bool ShouldUseColor(bool stdout_is_tty) {
2585 const char* const gtest_color = GTEST_FLAG(color).c_str();
2586
2587 if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) {
2588 #if GTEST_OS_WINDOWS
2589 // On Windows the TERM variable is usually not set, but the
2590 // console there does support colors.
2591 return stdout_is_tty;
2592 #else
2593 // On non-Windows platforms, we rely on the TERM variable.
2594 const char* const term = posix::GetEnv("TERM");
2595 const bool term_supports_color =
2596 String::CStringEquals(term, "xterm") ||
2597 String::CStringEquals(term, "xterm-color") ||
2598 String::CStringEquals(term, "xterm-256color") ||
2599 String::CStringEquals(term, "screen") ||
2600 String::CStringEquals(term, "screen-256color") ||
2601 String::CStringEquals(term, "linux") ||
2602 String::CStringEquals(term, "cygwin");
2603 return stdout_is_tty && term_supports_color;
2604 #endif // GTEST_OS_WINDOWS
2605 }
2606
2607 return String::CaseInsensitiveCStringEquals(gtest_color, "yes") ||
2608 String::CaseInsensitiveCStringEquals(gtest_color, "true") ||
2609 String::CaseInsensitiveCStringEquals(gtest_color, "t") ||
2610 String::CStringEquals(gtest_color, "1");
2611 // We take "yes", "true", "t", and "1" as meaning "yes". If the
2612 // value is neither one of these nor "auto", we treat it as "no" to
2613 // be conservative.
2614 }
2615
2616 // Helpers for printing colored strings to stdout. Note that on Windows, we
2617 // cannot simply emit special characters and have the terminal change colors.
2618 // This routine must actually emit the characters rather than return a string
2619 // that would be colored when printed, as can be done on Linux.
2620 void ColoredPrintf(GTestColor color, const char* fmt, ...) {
2621 va_list args;
2622 va_start(args, fmt);
2623
2624 #if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS || GTEST_OS_IOS
2625 const bool use_color = false;
2626 #else
2627 static const bool in_color_mode =
2628 ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0);
2629 const bool use_color = in_color_mode && (color != COLOR_DEFAULT);
2630 #endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS
2631 // The '!= 0' comparison is necessary to satisfy MSVC 7.1.
2632
2633 if (!use_color) {
2634 vprintf(fmt, args);
2635 va_end(args);
2636 return;
2637 }
2638
2639 #if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
2640 const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
2641
2642 // Gets the current text color.
2643 CONSOLE_SCREEN_BUFFER_INFO buffer_info;
2644 GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
2645 const WORD old_color_attrs = buffer_info.wAttributes;
2646
2647 // We need to flush the stream buffers into the console before each
2648 // SetConsoleTextAttribute call lest it affect the text that is already
2649 // printed but has not yet reached the console.
2650 fflush(stdout);
2651 SetConsoleTextAttribute(stdout_handle,
2652 GetColorAttribute(color) | FOREGROUND_INTENSITY);
2653 vprintf(fmt, args);
2654
2655 fflush(stdout);
2656 // Restores the text color.
2657 SetConsoleTextAttribute(stdout_handle, old_color_attrs);
2658 #else
2659 printf("\033[0;3%sm", GetAnsiColorCode(color));
2660 vprintf(fmt, args);
2661 printf("\033[m"); // Resets the terminal to default.
2662 #endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
2663 va_end(args);
2664 }
2665
2666 // Text printed in Google Test's text output and --gunit_list_tests
2667 // output to label the type parameter and value parameter for a test.
2668 static const char kTypeParamLabel[] = "TypeParam";
2669 static const char kValueParamLabel[] = "GetParam()";
2670
2671 void PrintFullTestCommentIfPresent(const TestInfo& test_info) {
2672 const char* const type_param = test_info.type_param();
2673 const char* const value_param = test_info.value_param();
2674
2675 if (type_param != NULL || value_param != NULL) {
2676 printf(", where ");
2677 if (type_param != NULL) {
2678 printf("%s = %s", kTypeParamLabel, type_param);
2679 if (value_param != NULL)
2680 printf(" and ");
2681 }
2682 if (value_param != NULL) {
2683 printf("%s = %s", kValueParamLabel, value_param);
2684 }
2685 }
2686 }
2687
2688 // This class implements the TestEventListener interface.
2689 //
2690 // Class PrettyUnitTestResultPrinter is copyable.
2691 class PrettyUnitTestResultPrinter : public TestEventListener {
2692 public:
2693 PrettyUnitTestResultPrinter() {}
2694 static void PrintTestName(const char * test_case, const char * test) {
2695 printf("%s.%s", test_case, test);
2696 }
2697
2698 // The following methods override what's in the TestEventListener class.
2699 virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
2700 virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration);
2701 virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);
2702 virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
2703 virtual void OnTestCaseStart(const TestCase& test_case);
2704 virtual void OnTestStart(const TestInfo& test_info);
2705 virtual void OnTestPartResult(const TestPartResult& result);
2706 virtual void OnTestEnd(const TestInfo& test_info);
2707 virtual void OnTestCaseEnd(const TestCase& test_case);
2708 virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);
2709 virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
2710 virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
2711 virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
2712
2713 private:
2714 static void PrintFailedTests(const UnitTest& unit_test);
2715 };
2716
2717 // Fired before each iteration of tests starts.
2718 void PrettyUnitTestResultPrinter::OnTestIterationStart(
2719 const UnitTest& unit_test, int iteration) {
2720 if (GTEST_FLAG(repeat) != 1)
2721 printf("\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
2722
2723 const char* const filter = GTEST_FLAG(filter).c_str();
2724
2725 // Prints the filter if it's not *. This reminds the user that some
2726 // tests may be skipped.
2727 if (!String::CStringEquals(filter, kUniversalFilter)) {
2728 ColoredPrintf(COLOR_YELLOW,
2729 "Note: %s filter = %s\n", GTEST_NAME_, filter);
2730 }
2731
2732 if (internal::ShouldShard(kTestTotalShards, kTestShardIndex, false)) {
2733 const Int32 shard_index = Int32FromEnvOrDie(kTestShardIndex, -1);
2734 ColoredPrintf(COLOR_YELLOW,
2735 "Note: This is test shard %d of %s.\n",
2736 static_cast<int>(shard_index) + 1,
2737 internal::posix::GetEnv(kTestTotalShards));
2738 }
2739
2740 if (GTEST_FLAG(shuffle)) {
2741 ColoredPrintf(COLOR_YELLOW,
2742 "Note: Randomizing tests' orders with a seed of %d .\n",
2743 unit_test.random_seed());
2744 }
2745
2746 ColoredPrintf(COLOR_GREEN, "[==========] ");
2747 printf("Running %s from %s.\n",
2748 FormatTestCount(unit_test.test_to_run_count()).c_str(),
2749 FormatTestCaseCount(unit_test.test_case_to_run_count()).c_str());
2750 fflush(stdout);
2751 }
2752
2753 void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart(
2754 const UnitTest& /*unit_test*/) {
2755 ColoredPrintf(COLOR_GREEN, "[----------] ");
2756 printf("Global test environment set-up.\n");
2757 fflush(stdout);
2758 }
2759
2760 void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) {
2761 const std::string counts =
2762 FormatCountableNoun(test_case.test_to_run_count(), "test", "tests");
2763 ColoredPrintf(COLOR_GREEN, "[----------] ");
2764 printf("%s from %s", counts.c_str(), test_case.name());
2765 if (test_case.type_param() == NULL) {
2766 printf("\n");
2767 } else {
2768 printf(", where %s = %s\n", kTypeParamLabel, test_case.type_param());
2769 }
2770 fflush(stdout);
2771 }
2772
2773 void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {
2774 ColoredPrintf(COLOR_GREEN, "[ RUN ] ");
2775 PrintTestName(test_info.test_case_name(), test_info.name());
2776 printf("\n");
2777 fflush(stdout);
2778 }
2779
2780 // Called after an assertion failure.
2781 void PrettyUnitTestResultPrinter::OnTestPartResult(
2782 const TestPartResult& result) {
2783 // If the test part succeeded, we don't need to do anything.
2784 if (result.type() == TestPartResult::kSuccess)
2785 return;
2786
2787 // Print failure message from the assertion (e.g. expected this and got that).
2788 PrintTestPartResult(result);
2789 fflush(stdout);
2790 }
2791
2792 void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
2793 if (test_info.result()->Passed()) {
2794 ColoredPrintf(COLOR_GREEN, "[ OK ] ");
2795 } else {
2796 ColoredPrintf(COLOR_RED, "[ FAILED ] ");
2797 }
2798 PrintTestName(test_info.test_case_name(), test_info.name());
2799 if (test_info.result()->Failed())
2800 PrintFullTestCommentIfPresent(test_info);
2801
2802 if (GTEST_FLAG(print_time)) {
2803 printf(" (%s ms)\n", internal::StreamableToString(
2804 test_info.result()->elapsed_time()).c_str());
2805 } else {
2806 printf("\n");
2807 }
2808 fflush(stdout);
2809 }
2810
2811 void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestCase& test_case) {
2812 if (!GTEST_FLAG(print_time)) return;
2813
2814 const std::string counts =
2815 FormatCountableNoun(test_case.test_to_run_count(), "test", "tests");
2816 ColoredPrintf(COLOR_GREEN, "[----------] ");
2817 printf("%s from %s (%s ms total)\n\n",
2818 counts.c_str(), test_case.name(),
2819 internal::StreamableToString(test_case.elapsed_time()).c_str());
2820 fflush(stdout);
2821 }
2822
2823 void PrettyUnitTestResultPrinter::OnEnvironmentsTearDownStart(
2824 const UnitTest& /*unit_test*/) {
2825 ColoredPrintf(COLOR_GREEN, "[----------] ");
2826 printf("Global test environment tear-down\n");
2827 fflush(stdout);
2828 }
2829
2830 // Internal helper for printing the list of failed tests.
2831 void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) {
2832 const int failed_test_count = unit_test.failed_test_count();
2833 if (failed_test_count == 0) {
2834 return;
2835 }
2836
2837 for (int i = 0; i < unit_test.total_test_case_count(); ++i) {
2838 const TestCase& test_case = *unit_test.GetTestCase(i);
2839 if (!test_case.should_run() || (test_case.failed_test_count() == 0)) {
2840 continue;
2841 }
2842 for (int j = 0; j < test_case.total_test_count(); ++j) {
2843 const TestInfo& test_info = *test_case.GetTestInfo(j);
2844 if (!test_info.should_run() || test_info.result()->Passed()) {
2845 continue;
2846 }
2847 ColoredPrintf(COLOR_RED, "[ FAILED ] ");
2848 printf("%s.%s", test_case.name(), test_info.name());
2849 PrintFullTestCommentIfPresent(test_info);
2850 printf("\n");
2851 }
2852 }
2853 }
2854
2855 void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
2856 int /*iteration*/) {
2857 ColoredPrintf(COLOR_GREEN, "[==========] ");
2858 printf("%s from %s ran.",
2859 FormatTestCount(unit_test.test_to_run_count()).c_str(),
2860 FormatTestCaseCount(unit_test.test_case_to_run_count()).c_str());
2861 if (GTEST_FLAG(print_time)) {
2862 printf(" (%s ms total)",
2863 internal::StreamableToString(unit_test.elapsed_time()).c_str());
2864 }
2865 printf("\n");
2866 ColoredPrintf(COLOR_GREEN, "[ PASSED ] ");
2867 printf("%s.\n", FormatTestCount(unit_test.successful_test_count()).c_str());
2868
2869 int num_failures = unit_test.failed_test_count();
2870 if (!unit_test.Passed()) {
2871 const int failed_test_count = unit_test.failed_test_count();
2872 ColoredPrintf(COLOR_RED, "[ FAILED ] ");
2873 printf("%s, listed below:\n", FormatTestCount(failed_test_count).c_str());
2874 PrintFailedTests(unit_test);
2875 printf("\n%2d FAILED %s\n", num_failures,
2876 num_failures == 1 ? "TEST" : "TESTS");
2877 }
2878
2879 int num_disabled = unit_test.reportable_disabled_test_count();
2880 if (num_disabled && !GTEST_FLAG(also_run_disabled_tests)) {
2881 if (!num_failures) {
2882 printf("\n"); // Add a spacer if no FAILURE banner is displayed.
2883 }
2884 ColoredPrintf(COLOR_YELLOW,
2885 " YOU HAVE %d DISABLED %s\n\n",
2886 num_disabled,
2887 num_disabled == 1 ? "TEST" : "TESTS");
2888 }
2889 // Ensure that Google Test output is printed before, e.g., heapchecker output.
2890 fflush(stdout);
2891 }
2892
2893 // End PrettyUnitTestResultPrinter
2894
2895 // class TestEventRepeater
2896 //
2897 // This class forwards events to other event listeners.
2898 class TestEventRepeater : public TestEventListener {
2899 public:
2900 TestEventRepeater() : forwarding_enabled_(true) {}
2901 virtual ~TestEventRepeater();
2902 void Append(TestEventListener *listener);
2903 TestEventListener* Release(TestEventListener* listener);
2904
2905 // Controls whether events will be forwarded to listeners_. Set to false
2906 // in death test child processes.
2907 bool forwarding_enabled() const { return forwarding_enabled_; }
2908 void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; }
2909
2910 virtual void OnTestProgramStart(const UnitTest& unit_test);
2911 virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration);
2912 virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);
2913 virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test);
2914 virtual void OnTestCaseStart(const TestCase& test_case);
2915 virtual void OnTestStart(const TestInfo& test_info);
2916 virtual void OnTestPartResult(const TestPartResult& result);
2917 virtual void OnTestEnd(const TestInfo& test_info);
2918 virtual void OnTestCaseEnd(const TestCase& test_case);
2919 virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);
2920 virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test);
2921 virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
2922 virtual void OnTestProgramEnd(const UnitTest& unit_test);
2923
2924 private:
2925 // Controls whether events will be forwarded to listeners_. Set to false
2926 // in death test child processes.
2927 bool forwarding_enabled_;
2928 // The list of listeners that receive events.
2929 std::vector<TestEventListener*> listeners_;
2930
2931 GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventRepeater);
2932 };
2933
2934 TestEventRepeater::~TestEventRepeater() {
2935 ForEach(listeners_, Delete<TestEventListener>);
2936 }
2937
2938 void TestEventRepeater::Append(TestEventListener *listener) {
2939 listeners_.push_back(listener);
2940 }
2941
2942 // TODO(vladl@google.com): Factor the search functionality into Vector::Find.
2943 TestEventListener* TestEventRepeater::Release(TestEventListener *listener) {
2944 for (size_t i = 0; i < listeners_.size(); ++i) {
2945 if (listeners_[i] == listener) {
2946 listeners_.erase(listeners_.begin() + i);
2947 return listener;
2948 }
2949 }
2950
2951 return NULL;
2952 }
2953
2954 // Since most methods are very similar, use macros to reduce boilerplate.
2955 // This defines a member that forwards the call to all listeners.
2956 #define GTEST_REPEATER_METHOD_(Name, Type) \
2957 void TestEventRepeater::Name(const Type& parameter) { \
2958 if (forwarding_enabled_) { \
2959 for (size_t i = 0; i < listeners_.size(); i++) { \
2960 listeners_[i]->Name(parameter); \
2961 } \
2962 } \
2963 }
2964 // This defines a member that forwards the call to all listeners in reverse
2965 // order.
2966 #define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \
2967 void TestEventRepeater::Name(const Type& parameter) { \
2968 if (forwarding_enabled_) { \
2969 for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) { \
2970 listeners_[i]->Name(parameter); \
2971 } \
2972 } \
2973 }
2974
2975 GTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest)
2976 GTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest)
2977 GTEST_REPEATER_METHOD_(OnTestCaseStart, TestCase)
2978 GTEST_REPEATER_METHOD_(OnTestStart, TestInfo)
2979 GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult)
2980 GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest)
2981 GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest)
2982 GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsTearDownEnd, UnitTest)
2983 GTEST_REVERSE_REPEATER_METHOD_(OnTestEnd, TestInfo)
2984 GTEST_REVERSE_REPEATER_METHOD_(OnTestCaseEnd, TestCase)
2985 GTEST_REVERSE_REPEATER_METHOD_(OnTestProgramEnd, UnitTest)
2986
2987 #undef GTEST_REPEATER_METHOD_
2988 #undef GTEST_REVERSE_REPEATER_METHOD_
2989
2990 void TestEventRepeater::OnTestIterationStart(const UnitTest& unit_test,
2991 int iteration) {
2992 if (forwarding_enabled_) {
2993 for (size_t i = 0; i < listeners_.size(); i++) {
2994 listeners_[i]->OnTestIterationStart(unit_test, iteration);
2995 }
2996 }
2997 }
2998
2999 void TestEventRepeater::OnTestIterationEnd(const UnitTest& unit_test,
3000 int iteration) {
3001 if (forwarding_enabled_) {
3002 for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) {
3003 listeners_[i]->OnTestIterationEnd(unit_test, iteration);
3004 }
3005 }
3006 }
3007
3008 // End TestEventRepeater
3009
3010 // This class generates an XML output file.
3011 class XmlUnitTestResultPrinter : public EmptyTestEventListener {
3012 public:
3013 explicit XmlUnitTestResultPrinter(const char* output_file);
3014
3015 virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
3016
3017 private:
3018 // Is c a whitespace character that is normalized to a space character
3019 // when it appears in an XML attribute value?
3020 static bool IsNormalizableWhitespace(char c) {
3021 return c == 0x9 || c == 0xA || c == 0xD;
3022 }
3023
3024 // May c appear in a well-formed XML document?
3025 static bool IsValidXmlCharacter(char c) {
3026 return IsNormalizableWhitespace(c) || c >= 0x20;
3027 }
3028
3029 // Returns an XML-escaped copy of the input string str. If
3030 // is_attribute is true, the text is meant to appear as an attribute
3031 // value, and normalizable whitespace is preserved by replacing it
3032 // with character references.
3033 static std::string EscapeXml(const std::string& str, bool is_attribute);
3034
3035 // Returns the given string with all characters invalid in XML removed.
3036 static std::string RemoveInvalidXmlCharacters(const std::string& str);
3037
3038 // Convenience wrapper around EscapeXml when str is an attribute value.
3039 static std::string EscapeXmlAttribute(const std::string& str) {
3040 return EscapeXml(str, true);
3041 }
3042
3043 // Convenience wrapper around EscapeXml when str is not an attribute value.
3044 static std::string EscapeXmlText(const char* str) {
3045 return EscapeXml(str, false);
3046 }
3047
3048 // Verifies that the given attribute belongs to the given element and
3049 // streams the attribute as XML.
3050 static void OutputXmlAttribute(std::ostream* stream,
3051 const std::string& element_name,
3052 const std::string& name,
3053 const std::string& value);
3054
3055 // Streams an XML CDATA section, escaping invalid CDATA sequences as needed.
3056 static void OutputXmlCDataSection(::std::ostream* stream, const char* data);
3057
3058 // Streams an XML representation of a TestInfo object.
3059 static void OutputXmlTestInfo(::std::ostream* stream,
3060 const char* test_case_name,
3061 const TestInfo& test_info);
3062
3063 // Prints an XML representation of a TestCase object
3064 static void PrintXmlTestCase(::std::ostream* stream,
3065 const TestCase& test_case);
3066
3067 // Prints an XML summary of unit_test to output stream out.
3068 static void PrintXmlUnitTest(::std::ostream* stream,
3069 const UnitTest& unit_test);
3070
3071 // Produces a string representing the test properties in a result as space
3072 // delimited XML attributes based on the property key="value" pairs.
3073 // When the std::string is not empty, it includes a space at the beginning,
3074 // to delimit this attribute from prior attributes.
3075 static std::string TestPropertiesAsXmlAttributes(const TestResult& result);
3076
3077 // The output file.
3078 const std::string output_file_;
3079
3080 GTEST_DISALLOW_COPY_AND_ASSIGN_(XmlUnitTestResultPrinter);
3081 };
3082
3083 // Creates a new XmlUnitTestResultPrinter.
3084 XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file)
3085 : output_file_(output_file) {
3086 if (output_file_.c_str() == NULL || output_file_.empty()) {
3087 fprintf(stderr, "XML output file may not be null\n");
3088 fflush(stderr);
3089 exit(EXIT_FAILURE);
3090 }
3091 }
3092
3093 // Called after the unit test ends.
3094 void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
3095 int /*iteration*/) {
3096 FILE* xmlout = NULL;
3097 FilePath output_file(output_file_);
3098 FilePath output_dir(output_file.RemoveFileName());
3099
3100 if (output_dir.CreateDirectoriesRecursively()) {
3101 xmlout = posix::FOpen(output_file_.c_str(), "w");
3102 }
3103 if (xmlout == NULL) {
3104 // TODO(wan): report the reason of the failure.
3105 //
3106 // We don't do it for now as:
3107 //
3108 // 1. There is no urgent need for it.
3109 // 2. It's a bit involved to make the errno variable thread-safe on
3110 // all three operating systems (Linux, Windows, and Mac OS).
3111 // 3. To interpret the meaning of errno in a thread-safe way,
3112 // we need the strerror_r() function, which is not available on
3113 // Windows.
3114 fprintf(stderr,
3115 "Unable to open file \"%s\"\n",
3116 output_file_.c_str());
3117 fflush(stderr);
3118 exit(EXIT_FAILURE);
3119 }
3120 std::stringstream stream;
3121 PrintXmlUnitTest(&stream, unit_test);
3122 fprintf(xmlout, "%s", StringStreamToString(&stream).c_str());
3123 fclose(xmlout);
3124 }
3125
3126 // Returns an XML-escaped copy of the input string str. If is_attribute
3127 // is true, the text is meant to appear as an attribute value, and
3128 // normalizable whitespace is preserved by replacing it with character
3129 // references.
3130 //
3131 // Invalid XML characters in str, if any, are stripped from the output.
3132 // It is expected that most, if not all, of the text processed by this
3133 // module will consist of ordinary English text.
3134 // If this module is ever modified to produce version 1.1 XML output,
3135 // most invalid characters can be retained using character references.
3136 // TODO(wan): It might be nice to have a minimally invasive, human-readable
3137 // escaping scheme for invalid characters, rather than dropping them.
3138 std::string XmlUnitTestResultPrinter::EscapeXml(
3139 const std::string& str, bool is_attribute) {
3140 Message m;
3141
3142 for (size_t i = 0; i < str.size(); ++i) {
3143 const char ch = str[i];
3144 switch (ch) {
3145 case '<':
3146 m << "&lt;";
3147 break;
3148 case '>':
3149 m << "&gt;";
3150 break;
3151 case '&':
3152 m << "&amp;";
3153 break;
3154 case '\'':
3155 if (is_attribute)
3156 m << "&apos;";
3157 else
3158 m << '\'';
3159 break;
3160 case '"':
3161 if (is_attribute)
3162 m << "&quot;";
3163 else
3164 m << '"';
3165 break;
3166 default:
3167 if (IsValidXmlCharacter(ch)) {
3168 if (is_attribute && IsNormalizableWhitespace(ch))
3169 m << "&#x" << String::FormatByte(static_cast<unsigned char>(ch))
3170 << ";";
3171 else
3172 m << ch;
3173 }
3174 break;
3175 }
3176 }
3177
3178 return m.GetString();
3179 }
3180
3181 // Returns the given string with all characters invalid in XML removed.
3182 // Currently invalid characters are dropped from the string. An
3183 // alternative is to replace them with certain characters such as . or ?.
3184 std::string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(
3185 const std::string& str) {
3186 std::string output;
3187 output.reserve(str.size());
3188 for (std::string::const_iterator it = str.begin(); it != str.end(); ++it)
3189 if (IsValidXmlCharacter(*it))
3190 output.push_back(*it);
3191
3192 return output;
3193 }
3194
3195 // The following routines generate an XML representation of a UnitTest
3196 // object.
3197 //
3198 // This is how Google Test concepts map to the DTD:
3199 //
3200 // <testsuites name="AllTests"> <-- corresponds to a UnitTest object
3201 // <testsuite name="testcase-name"> <-- corresponds to a TestCase object
3202 // <testcase name="test-name"> <-- corresponds to a TestInfo object
3203 // <failure message="...">...</failure>
3204 // <failure message="...">...</failure>
3205 // <failure message="...">...</failure>
3206 // <-- individual assertion failures
3207 // </testcase>
3208 // </testsuite>
3209 // </testsuites>
3210
3211 // Formats the given time in milliseconds as seconds.
3212 std::string FormatTimeInMillisAsSeconds(TimeInMillis ms) {
3213 ::std::stringstream ss;
3214 ss << ms/1000.0;
3215 return ss.str();
3216 }
3217
3218 // Converts the given epoch time in milliseconds to a date string in the ISO
3219 // 8601 format, without the timezone information.
3220 std::string FormatEpochTimeInMillisAsIso8601(TimeInMillis ms) {
3221 // Using non-reentrant version as localtime_r is not portable.
3222 time_t seconds = static_cast<time_t>(ms / 1000);
3223 #ifdef _MSC_VER
3224 # pragma warning(push) // Saves the current warning state.
3225 # pragma warning(disable:4996) // Temporarily disables warning 4996
3226 // (function or variable may be unsafe).
3227 const struct tm* const time_struct = localtime(&seconds); // NOLINT
3228 # pragma warning(pop) // Restores the warning state again.
3229 #else
3230 const struct tm* const time_struct = localtime(&seconds); // NOLINT
3231 #endif
3232 if (time_struct == NULL)
3233 return ""; // Invalid ms value
3234
3235 // YYYY-MM-DDThh:mm:ss
3236 return StreamableToString(time_struct->tm_year + 1900) + "-" +
3237 String::FormatIntWidth2(time_struct->tm_mon + 1) + "-" +
3238 String::FormatIntWidth2(time_struct->tm_mday) + "T" +
3239 String::FormatIntWidth2(time_struct->tm_hour) + ":" +
3240 String::FormatIntWidth2(time_struct->tm_min) + ":" +
3241 String::FormatIntWidth2(time_struct->tm_sec);
3242 }
3243
3244 // Streams an XML CDATA section, escaping invalid CDATA sequences as needed.
3245 void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream,
3246 const char* data) {
3247 const char* segment = data;
3248 *stream << "<![CDATA[";
3249 for (;;) {
3250 const char* const next_segment = strstr(segment, "]]>");
3251 if (next_segment != NULL) {
3252 stream->write(
3253 segment, static_cast<std::streamsize>(next_segment - segment));
3254 *stream << "]]>]]&gt;<![CDATA[";
3255 segment = next_segment + strlen("]]>");
3256 } else {
3257 *stream << segment;
3258 break;
3259 }
3260 }
3261 *stream << "]]>";
3262 }
3263
3264 void XmlUnitTestResultPrinter::OutputXmlAttribute(
3265 std::ostream* stream,
3266 const std::string& element_name,
3267 const std::string& name,
3268 const std::string& value) {
3269 const std::vector<std::string>& allowed_names =
3270 GetReservedAttributesForElement(element_name);
3271
3272 GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
3273 allowed_names.end())
3274 << "Attribute " << name << " is not allowed for element <" << element_name
3275 << ">.";
3276
3277 *stream << " " << name << "=\"" << EscapeXmlAttribute(value) << "\"";
3278 }
3279
3280 // Prints an XML representation of a TestInfo object.
3281 // TODO(wan): There is also value in printing properties with the plain printer.
3282 void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
3283 const char* test_case_name,
3284 const TestInfo& test_info) {
3285 const TestResult& result = *test_info.result();
3286 const std::string kTestcase = "testcase";
3287
3288 *stream << " <testcase";
3289 OutputXmlAttribute(stream, kTestcase, "name", test_info.name());
3290
3291 if (test_info.value_param() != NULL) {
3292 OutputXmlAttribute(stream, kTestcase, "value_param",
3293 test_info.value_param());
3294 }
3295 if (test_info.type_param() != NULL) {
3296 OutputXmlAttribute(stream, kTestcase, "type_param", test_info.type_param());
3297 }
3298
3299 OutputXmlAttribute(stream, kTestcase, "status",
3300 test_info.should_run() ? "run" : "notrun");
3301 OutputXmlAttribute(stream, kTestcase, "time",
3302 FormatTimeInMillisAsSeconds(result.elapsed_time()));
3303 OutputXmlAttribute(stream, kTestcase, "classname", test_case_name);
3304 *stream << TestPropertiesAsXmlAttributes(result);
3305
3306 int failures = 0;
3307 for (int i = 0; i < result.total_part_count(); ++i) {
3308 const TestPartResult& part = result.GetTestPartResult(i);
3309 if (part.failed()) {
3310 if (++failures == 1) {
3311 *stream << ">\n";
3312 }
3313 const string location = internal::FormatCompilerIndependentFileLocation(
3314 part.file_name(), part.line_number());
3315 const string summary = location + "\n" + part.summary();
3316 *stream << " <failure message=\""
3317 << EscapeXmlAttribute(summary.c_str())
3318 << "\" type=\"\">";
3319 const string detail = location + "\n" + part.message();
3320 OutputXmlCDataSection(stream, RemoveInvalidXmlCharacters(detail).c_str());
3321 *stream << "</failure>\n";
3322 }
3323 }
3324
3325 if (failures == 0)
3326 *stream << " />\n";
3327 else
3328 *stream << " </testcase>\n";
3329 }
3330
3331 // Prints an XML representation of a TestCase object
3332 void XmlUnitTestResultPrinter::PrintXmlTestCase(std::ostream* stream,
3333 const TestCase& test_case) {
3334 const std::string kTestsuite = "testsuite";
3335 *stream << " <" << kTestsuite;
3336 OutputXmlAttribute(stream, kTestsuite, "name", test_case.name());
3337 OutputXmlAttribute(stream, kTestsuite, "tests",
3338 StreamableToString(test_case.reportable_test_count()));
3339 OutputXmlAttribute(stream, kTestsuite, "failures",
3340 StreamableToString(test_case.failed_test_count()));
3341 OutputXmlAttribute(
3342 stream, kTestsuite, "disabled",
3343 StreamableToString(test_case.reportable_disabled_test_count()));
3344 OutputXmlAttribute(stream, kTestsuite, "errors", "0");
3345 OutputXmlAttribute(stream, kTestsuite, "time",
3346 FormatTimeInMillisAsSeconds(test_case.elapsed_time()));
3347 *stream << TestPropertiesAsXmlAttributes(test_case.ad_hoc_test_result())
3348 << ">\n";
3349
3350 for (int i = 0; i < test_case.total_test_count(); ++i) {
3351 if (test_case.GetTestInfo(i)->is_reportable())
3352 OutputXmlTestInfo(stream, test_case.name(), *test_case.GetTestInfo(i));
3353 }
3354 *stream << " </" << kTestsuite << ">\n";
3355 }
3356
3357 // Prints an XML summary of unit_test to output stream out.
3358 void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream,
3359 const UnitTest& unit_test) {
3360 const std::string kTestsuites = "testsuites";
3361
3362 *stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
3363 *stream << "<" << kTestsuites;
3364
3365 OutputXmlAttribute(stream, kTestsuites, "tests",
3366 StreamableToString(unit_test.reportable_test_count()));
3367 OutputXmlAttribute(stream, kTestsuites, "failures",
3368 StreamableToString(unit_test.failed_test_count()));
3369 OutputXmlAttribute(
3370 stream, kTestsuites, "disabled",
3371 StreamableToString(unit_test.reportable_disabled_test_count()));
3372 OutputXmlAttribute(stream, kTestsuites, "errors", "0");
3373 OutputXmlAttribute(
3374 stream, kTestsuites, "timestamp",
3375 FormatEpochTimeInMillisAsIso8601(unit_test.start_timestamp()));
3376 OutputXmlAttribute(stream, kTestsuites, "time",
3377 FormatTimeInMillisAsSeconds(unit_test.elapsed_time()));
3378
3379 if (GTEST_FLAG(shuffle)) {
3380 OutputXmlAttribute(stream, kTestsuites, "random_seed",
3381 StreamableToString(unit_test.random_seed()));
3382 }
3383
3384 *stream << TestPropertiesAsXmlAttributes(unit_test.ad_hoc_test_result());
3385
3386 OutputXmlAttribute(stream, kTestsuites, "name", "AllTests");
3387 *stream << ">\n";
3388
3389 for (int i = 0; i < unit_test.total_test_case_count(); ++i) {
3390 if (unit_test.GetTestCase(i)->reportable_test_count() > 0)
3391 PrintXmlTestCase(stream, *unit_test.GetTestCase(i));
3392 }
3393 *stream << "</" << kTestsuites << ">\n";
3394 }
3395
3396 // Produces a string representing the test properties in a result as space
3397 // delimited XML attributes based on the property key="value" pairs.
3398 std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
3399 const TestResult& result) {
3400 Message attributes;
3401 for (int i = 0; i < result.test_property_count(); ++i) {
3402 const TestProperty& property = result.GetTestProperty(i);
3403 attributes << " " << property.key() << "="
3404 << "\"" << EscapeXmlAttribute(property.value()) << "\"";
3405 }
3406 return attributes.GetString();
3407 }
3408
3409 // End XmlUnitTestResultPrinter
3410
3411 #if GTEST_CAN_STREAM_RESULTS_
3412
3413 // Checks if str contains '=', '&', '%' or '\n' characters. If yes,
3414 // replaces them by "%xx" where xx is their hexadecimal value. For
3415 // example, replaces "=" with "%3D". This algorithm is O(strlen(str))
3416 // in both time and space -- important as the input str may contain an
3417 // arbitrarily long test failure message and stack trace.
3418 string StreamingListener::UrlEncode(const char* str) {
3419 string result;
3420 result.reserve(strlen(str) + 1);
3421 for (char ch = *str; ch != '\0'; ch = *++str) {
3422 switch (ch) {
3423 case '%':
3424 case '=':
3425 case '&':
3426 case '\n':
3427 result.append("%" + String::FormatByte(static_cast<unsigned char>(ch)));
3428 break;
3429 default:
3430 result.push_back(ch);
3431 break;
3432 }
3433 }
3434 return result;
3435 }
3436
3437 void StreamingListener::SocketWriter::MakeConnection() {
3438 GTEST_CHECK_(sockfd_ == -1)
3439 << "MakeConnection() can't be called when there is already a connection.";
3440
3441 addrinfo hints;
3442 memset(&hints, 0, sizeof(hints));
3443 hints.ai_family = AF_UNSPEC; // To allow both IPv4 and IPv6 addresses.
3444 hints.ai_socktype = SOCK_STREAM;
3445 addrinfo* servinfo = NULL;
3446
3447 // Use the getaddrinfo() to get a linked list of IP addresses for
3448 // the given host name.
3449 const int error_num = getaddrinfo(
3450 host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
3451 if (error_num != 0) {
3452 GTEST_LOG_(WARNING) << "stream_result_to: getaddrinfo() failed: "
3453 << gai_strerror(error_num);
3454 }
3455
3456 // Loop through all the results and connect to the first we can.
3457 for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != NULL;
3458 cur_addr = cur_addr->ai_next) {
3459 sockfd_ = socket(
3460 cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
3461 if (sockfd_ != -1) {
3462 // Connect the client socket to the server socket.
3463 if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
3464 close(sockfd_);
3465 sockfd_ = -1;
3466 }
3467 }
3468 }
3469
3470 freeaddrinfo(servinfo); // all done with this structure
3471
3472 if (sockfd_ == -1) {
3473 GTEST_LOG_(WARNING) << "stream_result_to: failed to connect to "
3474 << host_name_ << ":" << port_num_;
3475 }
3476 }
3477
3478 // End of class Streaming Listener
3479 #endif // GTEST_CAN_STREAM_RESULTS__
3480
3481 // Class ScopedTrace
3482
3483 // Pushes the given source file location and message onto a per-thread
3484 // trace stack maintained by Google Test.
3485 ScopedTrace::ScopedTrace(const char* file, int line, const Message& message)
3486 GTEST_LOCK_EXCLUDED_(&UnitTest::mutex_) {
3487 TraceInfo trace;
3488 trace.file = file;
3489 trace.line = line;
3490 trace.message = message.GetString();
3491
3492 UnitTest::GetInstance()->PushGTestTrace(trace);
3493 }
3494
3495 // Pops the info pushed by the c'tor.
3496 ScopedTrace::~ScopedTrace()
3497 GTEST_LOCK_EXCLUDED_(&UnitTest::mutex_) {
3498 UnitTest::GetInstance()->PopGTestTrace();
3499 }
3500
3501
3502 // class OsStackTraceGetter
3503
3504 // Returns the current OS stack trace as an std::string. Parameters:
3505 //
3506 // max_depth - the maximum number of stack frames to be included
3507 // in the trace.
3508 // skip_count - the number of top frames to be skipped; doesn't count
3509 // against max_depth.
3510 //
3511 string OsStackTraceGetter::CurrentStackTrace(int /* max_depth */,
3512 int /* skip_count */)
3513 GTEST_LOCK_EXCLUDED_(mutex_) {
3514 return "";
3515 }
3516
3517 void OsStackTraceGetter::UponLeavingGTest()
3518 GTEST_LOCK_EXCLUDED_(mutex_) {
3519 }
3520
3521 const char* const
3522 OsStackTraceGetter::kElidedFramesMarker =
3523 "... " GTEST_NAME_ " internal frames ...";
3524
3525 // A helper class that creates the premature-exit file in its
3526 // constructor and deletes the file in its destructor.
3527 class ScopedPrematureExitFile {
3528 public:
3529 explicit ScopedPrematureExitFile(const char* premature_exit_filepath)
3530 : premature_exit_filepath_(premature_exit_filepath) {
3531 // If a path to the premature-exit file is specified...
3532 if (premature_exit_filepath != NULL && *premature_exit_filepath != '\0') {
3533 // create the file with a single "0" character in it. I/O
3534 // errors are ignored as there's nothing better we can do and we
3535 // don't want to fail the test because of this.
3536 FILE* pfile = posix::FOpen(premature_exit_filepath, "w");
3537 fwrite("0", 1, 1, pfile);
3538 fclose(pfile);
3539 }
3540 }
3541
3542 ~ScopedPrematureExitFile() {
3543 if (premature_exit_filepath_ != NULL && *premature_exit_filepath_ != '\0') {
3544 remove(premature_exit_filepath_);
3545 }
3546 }
3547
3548 private:
3549 const char* const premature_exit_filepath_;
3550
3551 GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedPrematureExitFile);
3552 };
3553
3554 } // namespace internal
3555
3556 // class TestEventListeners
3557
3558 TestEventListeners::TestEventListeners()
3559 : repeater_(new internal::TestEventRepeater()),
3560 default_result_printer_(NULL),
3561 default_xml_generator_(NULL) {
3562 }
3563
3564 TestEventListeners::~TestEventListeners() { delete repeater_; }
3565
3566 // Returns the standard listener responsible for the default console
3567 // output. Can be removed from the listeners list to shut down default
3568 // console output. Note that removing this object from the listener list
3569 // with Release transfers its ownership to the user.
3570 void TestEventListeners::Append(TestEventListener* listener) {
3571 repeater_->Append(listener);
3572 }
3573
3574 // Removes the given event listener from the list and returns it. It then
3575 // becomes the caller's responsibility to delete the listener. Returns
3576 // NULL if the listener is not found in the list.
3577 TestEventListener* TestEventListeners::Release(TestEventListener* listener) {
3578 if (listener == default_result_printer_)
3579 default_result_printer_ = NULL;
3580 else if (listener == default_xml_generator_)
3581 default_xml_generator_ = NULL;
3582 return repeater_->Release(listener);
3583 }
3584
3585 // Returns repeater that broadcasts the TestEventListener events to all
3586 // subscribers.
3587 TestEventListener* TestEventListeners::repeater() { return repeater_; }
3588
3589 // Sets the default_result_printer attribute to the provided listener.
3590 // The listener is also added to the listener list and previous
3591 // default_result_printer is removed from it and deleted. The listener can
3592 // also be NULL in which case it will not be added to the list. Does
3593 // nothing if the previous and the current listener objects are the same.
3594 void TestEventListeners::SetDefaultResultPrinter(TestEventListener* listener) {
3595 if (default_result_printer_ != listener) {
3596 // It is an error to pass this method a listener that is already in the
3597 // list.
3598 delete Release(default_result_printer_);
3599 default_result_printer_ = listener;
3600 if (listener != NULL)
3601 Append(listener);
3602 }
3603 }
3604
3605 // Sets the default_xml_generator attribute to the provided listener. The
3606 // listener is also added to the listener list and previous
3607 // default_xml_generator is removed from it and deleted. The listener can
3608 // also be NULL in which case it will not be added to the list. Does
3609 // nothing if the previous and the current listener objects are the same.
3610 void TestEventListeners::SetDefaultXmlGenerator(TestEventListener* listener) {
3611 if (default_xml_generator_ != listener) {
3612 // It is an error to pass this method a listener that is already in the
3613 // list.
3614 delete Release(default_xml_generator_);
3615 default_xml_generator_ = listener;
3616 if (listener != NULL)
3617 Append(listener);
3618 }
3619 }
3620
3621 // Controls whether events will be forwarded by the repeater to the
3622 // listeners in the list.
3623 bool TestEventListeners::EventForwardingEnabled() const {
3624 return repeater_->forwarding_enabled();
3625 }
3626
3627 void TestEventListeners::SuppressEventForwarding() {
3628 repeater_->set_forwarding_enabled(false);
3629 }
3630
3631 // class UnitTest
3632
3633 // Gets the singleton UnitTest object. The first time this method is
3634 // called, a UnitTest object is constructed and returned. Consecutive
3635 // calls will return the same object.
3636 //
3637 // We don't protect this under mutex_ as a user is not supposed to
3638 // call this before main() starts, from which point on the return
3639 // value will never change.
3640 UnitTest* UnitTest::GetInstance() {
3641 // When compiled with MSVC 7.1 in optimized mode, destroying the
3642 // UnitTest object upon exiting the program messes up the exit code,
3643 // causing successful tests to appear failed. We have to use a
3644 // different implementation in this case to bypass the compiler bug.
3645 // This implementation makes the compiler happy, at the cost of
3646 // leaking the UnitTest object.
3647
3648 // CodeGear C++Builder insists on a public destructor for the
3649 // default implementation. Use this implementation to keep good OO
3650 // design with private destructor.
3651
3652 #if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
3653 static UnitTest* const instance = new UnitTest;
3654 return instance;
3655 #else
3656 static UnitTest instance;
3657 return &instance;
3658 #endif // (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
3659 }
3660
3661 // Gets the number of successful test cases.
3662 int UnitTest::successful_test_case_count() const {
3663 return impl()->successful_test_case_count();
3664 }
3665
3666 // Gets the number of failed test cases.
3667 int UnitTest::failed_test_case_count() const {
3668 return impl()->failed_test_case_count();
3669 }
3670
3671 // Gets the number of all test cases.
3672 int UnitTest::total_test_case_count() const {
3673 return impl()->total_test_case_count();
3674 }
3675
3676 // Gets the number of all test cases that contain at least one test
3677 // that should run.
3678 int UnitTest::test_case_to_run_count() const {
3679 return impl()->test_case_to_run_count();
3680 }
3681
3682 // Gets the number of successful tests.
3683 int UnitTest::successful_test_count() const {
3684 return impl()->successful_test_count();
3685 }
3686
3687 // Gets the number of failed tests.
3688 int UnitTest::failed_test_count() const { return impl()->failed_test_count(); }
3689
3690 // Gets the number of disabled tests that will be reported in the XML report.
3691 int UnitTest::reportable_disabled_test_count() const {
3692 return impl()->reportable_disabled_test_count();
3693 }
3694
3695 // Gets the number of disabled tests.
3696 int UnitTest::disabled_test_count() const {
3697 return impl()->disabled_test_count();
3698 }
3699
3700 // Gets the number of tests to be printed in the XML report.
3701 int UnitTest::reportable_test_count() const {
3702 return impl()->reportable_test_count();
3703 }
3704
3705 // Gets the number of all tests.
3706 int UnitTest::total_test_count() const { return impl()->total_test_count(); }
3707
3708 // Gets the number of tests that should run.
3709 int UnitTest::test_to_run_count() const { return impl()->test_to_run_count(); }
3710
3711 // Gets the time of the test program start, in ms from the start of the
3712 // UNIX epoch.
3713 internal::TimeInMillis UnitTest::start_timestamp() const {
3714 return impl()->start_timestamp();
3715 }
3716
3717 // Gets the elapsed time, in milliseconds.
3718 internal::TimeInMillis UnitTest::elapsed_time() const {
3719 return impl()->elapsed_time();
3720 }
3721
3722 // Returns true iff the unit test passed (i.e. all test cases passed).
3723 bool UnitTest::Passed() const { return impl()->Passed(); }
3724
3725 // Returns true iff the unit test failed (i.e. some test case failed
3726 // or something outside of all tests failed).
3727 bool UnitTest::Failed() const { return impl()->Failed(); }
3728
3729 // Gets the i-th test case among all the test cases. i can range from 0 to
3730 // total_test_case_count() - 1. If i is not in that range, returns NULL.
3731 const TestCase* UnitTest::GetTestCase(int i) const {
3732 return impl()->GetTestCase(i);
3733 }
3734
3735 // Returns the TestResult containing information on test failures and
3736 // properties logged outside of individual test cases.
3737 const TestResult& UnitTest::ad_hoc_test_result() const {
3738 return *impl()->ad_hoc_test_result();
3739 }
3740
3741 // Gets the i-th test case among all the test cases. i can range from 0 to
3742 // total_test_case_count() - 1. If i is not in that range, returns NULL.
3743 TestCase* UnitTest::GetMutableTestCase(int i) {
3744 return impl()->GetMutableTestCase(i);
3745 }
3746
3747 // Returns the list of event listeners that can be used to track events
3748 // inside Google Test.
3749 TestEventListeners& UnitTest::listeners() {
3750 return *impl()->listeners();
3751 }
3752
3753 // Registers and returns a global test environment. When a test
3754 // program is run, all global test environments will be set-up in the
3755 // order they were registered. After all tests in the program have
3756 // finished, all global test environments will be torn-down in the
3757 // *reverse* order they were registered.
3758 //
3759 // The UnitTest object takes ownership of the given environment.
3760 //
3761 // We don't protect this under mutex_, as we only support calling it
3762 // from the main thread.
3763 Environment* UnitTest::AddEnvironment(Environment* env) {
3764 if (env == NULL) {
3765 return NULL;
3766 }
3767
3768 impl_->environments().push_back(env);
3769 return env;
3770 }
3771
3772 // Adds a TestPartResult to the current TestResult object. All Google Test
3773 // assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) eventually call
3774 // this to report their results. The user code should use the
3775 // assertion macros instead of calling this directly.
3776 void UnitTest::AddTestPartResult(
3777 TestPartResult::Type result_type,
3778 const char* file_name,
3779 int line_number,
3780 const std::string& message,
3781 const std::string& os_stack_trace) GTEST_LOCK_EXCLUDED_(mutex_) {
3782 Message msg;
3783 msg << message;
3784
3785 internal::MutexLock lock(&mutex_);
3786 if (impl_->gtest_trace_stack().size() > 0) {
3787 msg << "\n" << GTEST_NAME_ << " trace:";
3788
3789 for (int i = static_cast<int>(impl_->gtest_trace_stack().size());
3790 i > 0; --i) {
3791 const internal::TraceInfo& trace = impl_->gtest_trace_stack()[i - 1];
3792 msg << "\n" << internal::FormatFileLocation(trace.file, trace.line)
3793 << " " << trace.message;
3794 }
3795 }
3796
3797 if (os_stack_trace.c_str() != NULL && !os_stack_trace.empty()) {
3798 msg << internal::kStackTraceMarker << os_stack_trace;
3799 }
3800
3801 const TestPartResult result =
3802 TestPartResult(result_type, file_name, line_number,
3803 msg.GetString().c_str());
3804 impl_->GetTestPartResultReporterForCurrentThread()->
3805 ReportTestPartResult(result);
3806
3807 if (result_type != TestPartResult::kSuccess) {
3808 // gtest_break_on_failure takes precedence over
3809 // gtest_throw_on_failure. This allows a user to set the latter
3810 // in the code (perhaps in order to use Google Test assertions
3811 // with another testing framework) and specify the former on the
3812 // command line for debugging.
3813 if (GTEST_FLAG(break_on_failure)) {
3814 #if GTEST_OS_WINDOWS
3815 // Using DebugBreak on Windows allows gtest to still break into a debugger
3816 // when a failure happens and both the --gtest_break_on_failure and
3817 // the --gtest_catch_exceptions flags are specified.
3818 DebugBreak();
3819 #else
3820 // Dereference NULL through a volatile pointer to prevent the compiler
3821 // from removing. We use this rather than abort() or __builtin_trap() for
3822 // portability: Symbian doesn't implement abort() well, and some debuggers
3823 // don't correctly trap abort().
3824 *static_cast<volatile int*>(NULL) = 1;
3825 #endif // GTEST_OS_WINDOWS
3826 } else if (GTEST_FLAG(throw_on_failure)) {
3827 #if GTEST_HAS_EXCEPTIONS
3828 throw internal::GoogleTestFailureException(result);
3829 #else
3830 // We cannot call abort() as it generates a pop-up in debug mode
3831 // that cannot be suppressed in VC 7.1 or below.
3832 exit(1);
3833 #endif
3834 }
3835 }
3836 }
3837
3838 // Adds a TestProperty to the current TestResult object when invoked from
3839 // inside a test, to current TestCase's ad_hoc_test_result_ when invoked
3840 // from SetUpTestCase or TearDownTestCase, or to the global property set
3841 // when invoked elsewhere. If the result already contains a property with
3842 // the same key, the value will be updated.
3843 void UnitTest::RecordProperty(const std::string& key,
3844 const std::string& value) {
3845 impl_->RecordProperty(TestProperty(key, value));
3846 }
3847
3848 // Runs all tests in this UnitTest object and prints the result.
3849 // Returns 0 if successful, or 1 otherwise.
3850 //
3851 // We don't protect this under mutex_, as we only support calling it
3852 // from the main thread.
3853 int UnitTest::Run() {
3854 const bool in_death_test_child_process =
3855 internal::GTEST_FLAG(internal_run_death_test).length() > 0;
3856
3857 // Google Test implements this protocol for catching that a test
3858 // program exits before returning control to Google Test:
3859 //
3860 // 1. Upon start, Google Test creates a file whose absolute path
3861 // is specified by the environment variable
3862 // TEST_PREMATURE_EXIT_FILE.
3863 // 2. When Google Test has finished its work, it deletes the file.
3864 //
3865 // This allows a test runner to set TEST_PREMATURE_EXIT_FILE before
3866 // running a Google-Test-based test program and check the existence
3867 // of the file at the end of the test execution to see if it has
3868 // exited prematurely.
3869
3870 // If we are in the child process of a death test, don't
3871 // create/delete the premature exit file, as doing so is unnecessary
3872 // and will confuse the parent process. Otherwise, create/delete
3873 // the file upon entering/leaving this function. If the program
3874 // somehow exits before this function has a chance to return, the
3875 // premature-exit file will be left undeleted, causing a test runner
3876 // that understands the premature-exit-file protocol to report the
3877 // test as having failed.
3878 const internal::ScopedPrematureExitFile premature_exit_file(
3879 in_death_test_child_process ?
3880 NULL : internal::posix::GetEnv("TEST_PREMATURE_EXIT_FILE"));
3881
3882 // Captures the value of GTEST_FLAG(catch_exceptions). This value will be
3883 // used for the duration of the program.
3884 impl()->set_catch_exceptions(GTEST_FLAG(catch_exceptions));
3885
3886 #if GTEST_HAS_SEH
3887 // Either the user wants Google Test to catch exceptions thrown by the
3888 // tests or this is executing in the context of death test child
3889 // process. In either case the user does not want to see pop-up dialogs
3890 // about crashes - they are expected.
3891 if (impl()->catch_exceptions() || in_death_test_child_process) {
3892 # if !GTEST_OS_WINDOWS_MOBILE
3893 // SetErrorMode doesn't exist on CE.
3894 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
3895 SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
3896 # endif // !GTEST_OS_WINDOWS_MOBILE
3897
3898 # if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
3899 // Death test children can be terminated with _abort(). On Windows,
3900 // _abort() can show a dialog with a warning message. This forces the
3901 // abort message to go to stderr instead.
3902 _set_error_mode(_OUT_TO_STDERR);
3903 # endif
3904
3905 # if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
3906 // In the debug version, Visual Studio pops up a separate dialog
3907 // offering a choice to debug the aborted program. We need to suppress
3908 // this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
3909 // executed. Google Test will notify the user of any unexpected
3910 // failure via stderr.
3911 //
3912 // VC++ doesn't define _set_abort_behavior() prior to the version 8.0.
3913 // Users of prior VC versions shall suffer the agony and pain of
3914 // clicking through the countless debug dialogs.
3915 // TODO(vladl@google.com): find a way to suppress the abort dialog() in the
3916 // debug mode when compiled with VC 7.1 or lower.
3917 if (!GTEST_FLAG(break_on_failure))
3918 _set_abort_behavior(
3919 0x0, // Clear the following flags:
3920 _WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump.
3921 # endif
3922 }
3923 #endif // GTEST_HAS_SEH
3924
3925 return internal::HandleExceptionsInMethodIfSupported(
3926 impl(),
3927 &internal::UnitTestImpl::RunAllTests,
3928 "auxiliary test code (environments or event listeners)") ? 0 : 1;
3929 }
3930
3931 // Returns the working directory when the first TEST() or TEST_F() was
3932 // executed.
3933 const char* UnitTest::original_working_dir() const {
3934 return impl_->original_working_dir_.c_str();
3935 }
3936
3937 // Returns the TestCase object for the test that's currently running,
3938 // or NULL if no test is running.
3939 const TestCase* UnitTest::current_test_case() const
3940 GTEST_LOCK_EXCLUDED_(mutex_) {
3941 internal::MutexLock lock(&mutex_);
3942 return impl_->current_test_case();
3943 }
3944
3945 // Returns the TestInfo object for the test that's currently running,
3946 // or NULL if no test is running.
3947 const TestInfo* UnitTest::current_test_info() const
3948 GTEST_LOCK_EXCLUDED_(mutex_) {
3949 internal::MutexLock lock(&mutex_);
3950 return impl_->current_test_info();
3951 }
3952
3953 // Returns the random seed used at the start of the current test run.
3954 int UnitTest::random_seed() const { return impl_->random_seed(); }
3955
3956 #if GTEST_HAS_PARAM_TEST
3957 // Returns ParameterizedTestCaseRegistry object used to keep track of
3958 // value-parameterized tests and instantiate and register them.
3959 internal::ParameterizedTestCaseRegistry&
3960 UnitTest::parameterized_test_registry()
3961 GTEST_LOCK_EXCLUDED_(mutex_) {
3962 return impl_->parameterized_test_registry();
3963 }
3964 #endif // GTEST_HAS_PARAM_TEST
3965
3966 // Creates an empty UnitTest.
3967 UnitTest::UnitTest() {
3968 impl_ = new internal::UnitTestImpl(this);
3969 }
3970
3971 // Destructor of UnitTest.
3972 UnitTest::~UnitTest() {
3973 delete impl_;
3974 }
3975
3976 // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
3977 // Google Test trace stack.
3978 void UnitTest::PushGTestTrace(const internal::TraceInfo& trace)
3979 GTEST_LOCK_EXCLUDED_(mutex_) {
3980 internal::MutexLock lock(&mutex_);
3981 impl_->gtest_trace_stack().push_back(trace);
3982 }
3983
3984 // Pops a trace from the per-thread Google Test trace stack.
3985 void UnitTest::PopGTestTrace()
3986 GTEST_LOCK_EXCLUDED_(mutex_) {
3987 internal::MutexLock lock(&mutex_);
3988 impl_->gtest_trace_stack().pop_back();
3989 }
3990
3991 namespace internal {
3992
3993 UnitTestImpl::UnitTestImpl(UnitTest* parent)
3994 : parent_(parent),
3995 #ifdef _MSC_VER
3996 # pragma warning(push) // Saves the current warning state.
3997 # pragma warning(disable:4355) // Temporarily disables warning 4355
3998 // (using this in initializer).
3999 default_global_test_part_result_reporter_(this),
4000 default_per_thread_test_part_result_reporter_(this),
4001 # pragma warning(pop) // Restores the warning state again.
4002 #else
4003 default_global_test_part_result_reporter_(this),
4004 default_per_thread_test_part_result_reporter_(this),
4005 #endif // _MSC_VER
4006 global_test_part_result_repoter_(
4007 &default_global_test_part_result_reporter_),
4008 per_thread_test_part_result_reporter_(
4009 &default_per_thread_test_part_result_reporter_),
4010 #if GTEST_HAS_PARAM_TEST
4011 parameterized_test_registry_(),
4012 parameterized_tests_registered_(false),
4013 #endif // GTEST_HAS_PARAM_TEST
4014 last_death_test_case_(-1),
4015 current_test_case_(NULL),
4016 current_test_info_(NULL),
4017 ad_hoc_test_result_(),
4018 os_stack_trace_getter_(NULL),
4019 post_flag_parse_init_performed_(false),
4020 random_seed_(0), // Will be overridden by the flag before first use.
4021 random_(0), // Will be reseeded before first use.
4022 start_timestamp_(0),
4023 elapsed_time_(0),
4024 #if GTEST_HAS_DEATH_TEST
4025 death_test_factory_(new DefaultDeathTestFactory),
4026 #endif
4027 // Will be overridden by the flag before first use.
4028 catch_exceptions_(false) {
4029 listeners()->SetDefaultResultPrinter(new PrettyUnitTestResultPrinter);
4030 }
4031
4032 UnitTestImpl::~UnitTestImpl() {
4033 // Deletes every TestCase.
4034 ForEach(test_cases_, internal::Delete<TestCase>);
4035
4036 // Deletes every Environment.
4037 ForEach(environments_, internal::Delete<Environment>);
4038
4039 delete os_stack_trace_getter_;
4040 }
4041
4042 // Adds a TestProperty to the current TestResult object when invoked in a
4043 // context of a test, to current test case's ad_hoc_test_result when invoke
4044 // from SetUpTestCase/TearDownTestCase, or to the global property set
4045 // otherwise. If the result already contains a property with the same key,
4046 // the value will be updated.
4047 void UnitTestImpl::RecordProperty(const TestProperty& test_property) {
4048 std::string xml_element;
4049 TestResult* test_result; // TestResult appropriate for property recording.
4050
4051 if (current_test_info_ != NULL) {
4052 xml_element = "testcase";
4053 test_result = &(current_test_info_->result_);
4054 } else if (current_test_case_ != NULL) {
4055 xml_element = "testsuite";
4056 test_result = &(current_test_case_->ad_hoc_test_result_);
4057 } else {
4058 xml_element = "testsuites";
4059 test_result = &ad_hoc_test_result_;
4060 }
4061 test_result->RecordProperty(xml_element, test_property);
4062 }
4063
4064 #if GTEST_HAS_DEATH_TEST
4065 // Disables event forwarding if the control is currently in a death test
4066 // subprocess. Must not be called before InitGoogleTest.
4067 void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
4068 if (internal_run_death_test_flag_.get() != NULL)
4069 listeners()->SuppressEventForwarding();
4070 }
4071 #endif // GTEST_HAS_DEATH_TEST
4072
4073 // Initializes event listeners performing XML output as specified by
4074 // UnitTestOptions. Must not be called before InitGoogleTest.
4075 void UnitTestImpl::ConfigureXmlOutput() {
4076 const std::string& output_format = UnitTestOptions::GetOutputFormat();
4077 if (output_format == "xml") {
4078 listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter(
4079 UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
4080 } else if (output_format != "") {
4081 printf("WARNING: unrecognized output format \"%s\" ignored.\n",
4082 output_format.c_str());
4083 fflush(stdout);
4084 }
4085 }
4086
4087 #if GTEST_CAN_STREAM_RESULTS_
4088 // Initializes event listeners for streaming test results in string form.
4089 // Must not be called before InitGoogleTest.
4090 void UnitTestImpl::ConfigureStreamingOutput() {
4091 const std::string& target = GTEST_FLAG(stream_result_to);
4092 if (!target.empty()) {
4093 const size_t pos = target.find(':');
4094 if (pos != std::string::npos) {
4095 listeners()->Append(new StreamingListener(target.substr(0, pos),
4096 target.substr(pos+1)));
4097 } else {
4098 printf("WARNING: unrecognized streaming target \"%s\" ignored.\n",
4099 target.c_str());
4100 fflush(stdout);
4101 }
4102 }
4103 }
4104 #endif // GTEST_CAN_STREAM_RESULTS_
4105
4106 // Performs initialization dependent upon flag values obtained in
4107 // ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
4108 // ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
4109 // this function is also called from RunAllTests. Since this function can be
4110 // called more than once, it has to be idempotent.
4111 void UnitTestImpl::PostFlagParsingInit() {
4112 // Ensures that this function does not execute more than once.
4113 if (!post_flag_parse_init_performed_) {
4114 post_flag_parse_init_performed_ = true;
4115
4116 #if GTEST_HAS_DEATH_TEST
4117 InitDeathTestSubprocessControlInfo();
4118 SuppressTestEventsIfInSubprocess();
4119 #endif // GTEST_HAS_DEATH_TEST
4120
4121 // Registers parameterized tests. This makes parameterized tests
4122 // available to the UnitTest reflection API without running
4123 // RUN_ALL_TESTS.
4124 RegisterParameterizedTests();
4125
4126 // Configures listeners for XML output. This makes it possible for users
4127 // to shut down the default XML output before invoking RUN_ALL_TESTS.
4128 ConfigureXmlOutput();
4129
4130 #if GTEST_CAN_STREAM_RESULTS_
4131 // Configures listeners for streaming test results to the specified server.
4132 ConfigureStreamingOutput();
4133 #endif // GTEST_CAN_STREAM_RESULTS_
4134 }
4135 }
4136
4137 // A predicate that checks the name of a TestCase against a known
4138 // value.
4139 //
4140 // This is used for implementation of the UnitTest class only. We put
4141 // it in the anonymous namespace to prevent polluting the outer
4142 // namespace.
4143 //
4144 // TestCaseNameIs is copyable.
4145 class TestCaseNameIs {
4146 public:
4147 // Constructor.
4148 explicit TestCaseNameIs(const std::string& name)
4149 : name_(name) {}
4150
4151 // Returns true iff the name of test_case matches name_.
4152 bool operator()(const TestCase* test_case) const {
4153 return test_case != NULL && strcmp(test_case->name(), name_.c_str()) == 0;
4154 }
4155
4156 private:
4157 std::string name_;
4158 };
4159
4160 // Finds and returns a TestCase with the given name. If one doesn't
4161 // exist, creates one and returns it. It's the CALLER'S
4162 // RESPONSIBILITY to ensure that this function is only called WHEN THE
4163 // TESTS ARE NOT SHUFFLED.
4164 //
4165 // Arguments:
4166 //
4167 // test_case_name: name of the test case
4168 // type_param: the name of the test case's type parameter, or NULL if
4169 // this is not a typed or a type-parameterized test case.
4170 // set_up_tc: pointer to the function that sets up the test case
4171 // tear_down_tc: pointer to the function that tears down the test case
4172 TestCase* UnitTestImpl::GetTestCase(const char* test_case_name,
4173 const char* type_param,
4174 Test::SetUpTestCaseFunc set_up_tc,
4175 Test::TearDownTestCaseFunc tear_down_tc) {
4176 // Can we find a TestCase with the given name?
4177 const std::vector<TestCase*>::const_iterator test_case =
4178 std::find_if(test_cases_.begin(), test_cases_.end(),
4179 TestCaseNameIs(test_case_name));
4180
4181 if (test_case != test_cases_.end())
4182 return *test_case;
4183
4184 // No. Let's create one.
4185 TestCase* const new_test_case =
4186 new TestCase(test_case_name, type_param, set_up_tc, tear_down_tc);
4187
4188 // Is this a death test case?
4189 if (internal::UnitTestOptions::MatchesFilter(test_case_name,
4190 kDeathTestCaseFilter)) {
4191 // Yes. Inserts the test case after the last death test case
4192 // defined so far. This only works when the test cases haven't
4193 // been shuffled. Otherwise we may end up running a death test
4194 // after a non-death test.
4195 ++last_death_test_case_;
4196 test_cases_.insert(test_cases_.begin() + last_death_test_case_,
4197 new_test_case);
4198 } else {
4199 // No. Appends to the end of the list.
4200 test_cases_.push_back(new_test_case);
4201 }
4202
4203 test_case_indices_.push_back(static_cast<int>(test_case_indices_.size()));
4204 return new_test_case;
4205 }
4206
4207 // Helpers for setting up / tearing down the given environment. They
4208 // are for use in the ForEach() function.
4209 static void SetUpEnvironment(Environment* env) { env->SetUp(); }
4210 static void TearDownEnvironment(Environment* env) { env->TearDown(); }
4211
4212 // Runs all tests in this UnitTest object, prints the result, and
4213 // returns true if all tests are successful. If any exception is
4214 // thrown during a test, the test is considered to be failed, but the
4215 // rest of the tests will still be run.
4216 //
4217 // When parameterized tests are enabled, it expands and registers
4218 // parameterized tests first in RegisterParameterizedTests().
4219 // All other functions called from RunAllTests() may safely assume that
4220 // parameterized tests are ready to be counted and run.
4221 bool UnitTestImpl::RunAllTests() {
4222 // Makes sure InitGoogleTest() was called.
4223 if (!GTestIsInitialized()) {
4224 printf("%s",
4225 "\nThis test program did NOT call ::testing::InitGoogleTest "
4226 "before calling RUN_ALL_TESTS(). Please fix it.\n");
4227 return false;
4228 }
4229
4230 // Do not run any test if the --help flag was specified.
4231 if (g_help_flag)
4232 return true;
4233
4234 // Repeats the call to the post-flag parsing initialization in case the
4235 // user didn't call InitGoogleTest.
4236 PostFlagParsingInit();
4237
4238 // Even if sharding is not on, test runners may want to use the
4239 // GTEST_SHARD_STATUS_FILE to query whether the test supports the sharding
4240 // protocol.
4241 internal::WriteToShardStatusFileIfNeeded();
4242
4243 // True iff we are in a subprocess for running a thread-safe-style
4244 // death test.
4245 bool in_subprocess_for_death_test = false;
4246
4247 #if GTEST_HAS_DEATH_TEST
4248 in_subprocess_for_death_test = (internal_run_death_test_flag_.get() != NULL);
4249 #endif // GTEST_HAS_DEATH_TEST
4250
4251 const bool should_shard = ShouldShard(kTestTotalShards, kTestShardIndex,
4252 in_subprocess_for_death_test);
4253
4254 // Compares the full test names with the filter to decide which
4255 // tests to run.
4256 const bool has_tests_to_run = FilterTests(should_shard
4257 ? HONOR_SHARDING_PROTOCOL
4258 : IGNORE_SHARDING_PROTOCOL) > 0;
4259
4260 // Lists the tests and exits if the --gtest_list_tests flag was specified.
4261 if (GTEST_FLAG(list_tests)) {
4262 // This must be called *after* FilterTests() has been called.
4263 ListTestsMatchingFilter();
4264 return true;
4265 }
4266
4267 random_seed_ = GTEST_FLAG(shuffle) ?
4268 GetRandomSeedFromFlag(GTEST_FLAG(random_seed)) : 0;
4269
4270 // True iff at least one test has failed.
4271 bool failed = false;
4272
4273 TestEventListener* repeater = listeners()->repeater();
4274
4275 start_timestamp_ = GetTimeInMillis();
4276 repeater->OnTestProgramStart(*parent_);
4277
4278 // How many times to repeat the tests? We don't want to repeat them
4279 // when we are inside the subprocess of a death test.
4280 const int repeat = in_subprocess_for_death_test ? 1 : GTEST_FLAG(repeat);
4281 // Repeats forever if the repeat count is negative.
4282 const bool forever = repeat < 0;
4283 for (int i = 0; forever || i != repeat; i++) {
4284 // We want to preserve failures generated by ad-hoc test
4285 // assertions executed before RUN_ALL_TESTS().
4286 ClearNonAdHocTestResult();
4287
4288 const TimeInMillis start = GetTimeInMillis();
4289
4290 // Shuffles test cases and tests if requested.
4291 if (has_tests_to_run && GTEST_FLAG(shuffle)) {
4292 random()->Reseed(random_seed_);
4293 // This should be done before calling OnTestIterationStart(),
4294 // such that a test event listener can see the actual test order
4295 // in the event.
4296 ShuffleTests();
4297 }
4298
4299 // Tells the unit test event listeners that the tests are about to start.
4300 repeater->OnTestIterationStart(*parent_, i);
4301
4302 // Runs each test case if there is at least one test to run.
4303 if (has_tests_to_run) {
4304 // Sets up all environments beforehand.
4305 repeater->OnEnvironmentsSetUpStart(*parent_);
4306 ForEach(environments_, SetUpEnvironment);
4307 repeater->OnEnvironmentsSetUpEnd(*parent_);
4308
4309 // Runs the tests only if there was no fatal failure during global
4310 // set-up.
4311 if (!Test::HasFatalFailure()) {
4312 for (int test_index = 0; test_index < total_test_case_count();
4313 test_index++) {
4314 GetMutableTestCase(test_index)->Run();
4315 }
4316 }
4317
4318 // Tears down all environments in reverse order afterwards.
4319 repeater->OnEnvironmentsTearDownStart(*parent_);
4320 std::for_each(environments_.rbegin(), environments_.rend(),
4321 TearDownEnvironment);
4322 repeater->OnEnvironmentsTearDownEnd(*parent_);
4323 }
4324
4325 elapsed_time_ = GetTimeInMillis() - start;
4326
4327 // Tells the unit test event listener that the tests have just finished.
4328 repeater->OnTestIterationEnd(*parent_, i);
4329
4330 // Gets the result and clears it.
4331 if (!Passed()) {
4332 failed = true;
4333 }
4334
4335 // Restores the original test order after the iteration. This
4336 // allows the user to quickly repro a failure that happens in the
4337 // N-th iteration without repeating the first (N - 1) iterations.
4338 // This is not enclosed in "if (GTEST_FLAG(shuffle)) { ... }", in
4339 // case the user somehow changes the value of the flag somewhere
4340 // (it's always safe to unshuffle the tests).
4341 UnshuffleTests();
4342
4343 if (GTEST_FLAG(shuffle)) {
4344 // Picks a new random seed for each iteration.
4345 random_seed_ = GetNextRandomSeed(random_seed_);
4346 }
4347 }
4348
4349 repeater->OnTestProgramEnd(*parent_);
4350
4351 return !failed;
4352 }
4353
4354 // Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
4355 // if the variable is present. If a file already exists at this location, this
4356 // function will write over it. If the variable is present, but the file cannot
4357 // be created, prints an error and exits.
4358 void WriteToShardStatusFileIfNeeded() {
4359 const char* const test_shard_file = posix::GetEnv(kTestShardStatusFile);
4360 if (test_shard_file != NULL) {
4361 FILE* const file = posix::FOpen(test_shard_file, "w");
4362 if (file == NULL) {
4363 ColoredPrintf(COLOR_RED,
4364 "Could not write to the test shard status file \"%s\" "
4365 "specified by the %s environment variable.\n",
4366 test_shard_file, kTestShardStatusFile);
4367 fflush(stdout);
4368 exit(EXIT_FAILURE);
4369 }
4370 fclose(file);
4371 }
4372 }
4373
4374 // Checks whether sharding is enabled by examining the relevant
4375 // environment variable values. If the variables are present,
4376 // but inconsistent (i.e., shard_index >= total_shards), prints
4377 // an error and exits. If in_subprocess_for_death_test, sharding is
4378 // disabled because it must only be applied to the original test
4379 // process. Otherwise, we could filter out death tests we intended to execute.
4380 bool ShouldShard(const char* total_shards_env,
4381 const char* shard_index_env,
4382 bool in_subprocess_for_death_test) {
4383 if (in_subprocess_for_death_test) {
4384 return false;
4385 }
4386
4387 const Int32 total_shards = Int32FromEnvOrDie(total_shards_env, -1);
4388 const Int32 shard_index = Int32FromEnvOrDie(shard_index_env, -1);
4389
4390 if (total_shards == -1 && shard_index == -1) {
4391 return false;
4392 } else if (total_shards == -1 && shard_index != -1) {
4393 const Message msg = Message()
4394 << "Invalid environment variables: you have "
4395 << kTestShardIndex << " = " << shard_index
4396 << ", but have left " << kTestTotalShards << " unset.\n";
4397 ColoredPrintf(COLOR_RED, msg.GetString().c_str());
4398 fflush(stdout);
4399 exit(EXIT_FAILURE);
4400 } else if (total_shards != -1 && shard_index == -1) {
4401 const Message msg = Message()
4402 << "Invalid environment variables: you have "
4403 << kTestTotalShards << " = " << total_shards
4404 << ", but have left " << kTestShardIndex << " unset.\n";
4405 ColoredPrintf(COLOR_RED, msg.GetString().c_str());
4406 fflush(stdout);
4407 exit(EXIT_FAILURE);
4408 } else if (shard_index < 0 || shard_index >= total_shards) {
4409 const Message msg = Message()
4410 << "Invalid environment variables: we require 0 <= "
4411 << kTestShardIndex << " < " << kTestTotalShards
4412 << ", but you have " << kTestShardIndex << "=" << shard_index
4413 << ", " << kTestTotalShards << "=" << total_shards << ".\n";
4414 ColoredPrintf(COLOR_RED, msg.GetString().c_str());
4415 fflush(stdout);
4416 exit(EXIT_FAILURE);
4417 }
4418
4419 return total_shards > 1;
4420 }
4421
4422 // Parses the environment variable var as an Int32. If it is unset,
4423 // returns default_val. If it is not an Int32, prints an error
4424 // and aborts.
4425 Int32 Int32FromEnvOrDie(const char* var, Int32 default_val) {
4426 const char* str_val = posix::GetEnv(var);
4427 if (str_val == NULL) {
4428 return default_val;
4429 }
4430
4431 Int32 result;
4432 if (!ParseInt32(Message() << "The value of environment variable " << var,
4433 str_val, &result)) {
4434 exit(EXIT_FAILURE);
4435 }
4436 return result;
4437 }
4438
4439 // Given the total number of shards, the shard index, and the test id,
4440 // returns true iff the test should be run on this shard. The test id is
4441 // some arbitrary but unique non-negative integer assigned to each test
4442 // method. Assumes that 0 <= shard_index < total_shards.
4443 bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) {
4444 return (test_id % total_shards) == shard_index;
4445 }
4446
4447 // Compares the name of each test with the user-specified filter to
4448 // decide whether the test should be run, then records the result in
4449 // each TestCase and TestInfo object.
4450 // If shard_tests == true, further filters tests based on sharding
4451 // variables in the environment - see
4452 // http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide.
4453 // Returns the number of tests that should run.
4454 int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
4455 const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ?
4456 Int32FromEnvOrDie(kTestTotalShards, -1) : -1;
4457 const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
4458 Int32FromEnvOrDie(kTestShardIndex, -1) : -1;
4459
4460 // num_runnable_tests are the number of tests that will
4461 // run across all shards (i.e., match filter and are not disabled).
4462 // num_selected_tests are the number of tests to be run on
4463 // this shard.
4464 int num_runnable_tests = 0;
4465 int num_selected_tests = 0;
4466 for (size_t i = 0; i < test_cases_.size(); i++) {
4467 TestCase* const test_case = test_cases_[i];
4468 const std::string &test_case_name = test_case->name();
4469 test_case->set_should_run(false);
4470
4471 for (size_t j = 0; j < test_case->test_info_list().size(); j++) {
4472 TestInfo* const test_info = test_case->test_info_list()[j];
4473 const std::string test_name(test_info->name());
4474 // A test is disabled if test case name or test name matches
4475 // kDisableTestFilter.
4476 const bool is_disabled =
4477 internal::UnitTestOptions::MatchesFilter(test_case_name,
4478 kDisableTestFilter) ||
4479 internal::UnitTestOptions::MatchesFilter(test_name,
4480 kDisableTestFilter);
4481 test_info->is_disabled_ = is_disabled;
4482
4483 const bool matches_filter =
4484 internal::UnitTestOptions::FilterMatchesTest(test_case_name,
4485 test_name);
4486 test_info->matches_filter_ = matches_filter;
4487
4488 const bool is_runnable =
4489 (GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
4490 matches_filter;
4491
4492 const bool is_selected = is_runnable &&
4493 (shard_tests == IGNORE_SHARDING_PROTOCOL ||
4494 ShouldRunTestOnShard(total_shards, shard_index,
4495 num_runnable_tests));
4496
4497 num_runnable_tests += is_runnable;
4498 num_selected_tests += is_selected;
4499
4500 test_info->should_run_ = is_selected;
4501 test_case->set_should_run(test_case->should_run() || is_selected);
4502 }
4503 }
4504 return num_selected_tests;
4505 }
4506
4507 // Prints the given C-string on a single line by replacing all '\n'
4508 // characters with string "\\n". If the output takes more than
4509 // max_length characters, only prints the first max_length characters
4510 // and "...".
4511 static void PrintOnOneLine(const char* str, int max_length) {
4512 if (str != NULL) {
4513 for (int i = 0; *str != '\0'; ++str) {
4514 if (i >= max_length) {
4515 printf("...");
4516 break;
4517 }
4518 if (*str == '\n') {
4519 printf("\\n");
4520 i += 2;
4521 } else {
4522 printf("%c", *str);
4523 ++i;
4524 }
4525 }
4526 }
4527 }
4528
4529 // Prints the names of the tests matching the user-specified filter flag.
4530 void UnitTestImpl::ListTestsMatchingFilter() {
4531 // Print at most this many characters for each type/value parameter.
4532 const int kMaxParamLength = 250;
4533
4534 for (size_t i = 0; i < test_cases_.size(); i++) {
4535 const TestCase* const test_case = test_cases_[i];
4536 bool printed_test_case_name = false;
4537
4538 for (size_t j = 0; j < test_case->test_info_list().size(); j++) {
4539 const TestInfo* const test_info =
4540 test_case->test_info_list()[j];
4541 if (test_info->matches_filter_) {
4542 if (!printed_test_case_name) {
4543 printed_test_case_name = true;
4544 printf("%s.", test_case->name());
4545 if (test_case->type_param() != NULL) {
4546 printf(" # %s = ", kTypeParamLabel);
4547 // We print the type parameter on a single line to make
4548 // the output easy to parse by a program.
4549 PrintOnOneLine(test_case->type_param(), kMaxParamLength);
4550 }
4551 printf("\n");
4552 }
4553 printf(" %s", test_info->name());
4554 if (test_info->value_param() != NULL) {
4555 printf(" # %s = ", kValueParamLabel);
4556 // We print the value parameter on a single line to make the
4557 // output easy to parse by a program.
4558 PrintOnOneLine(test_info->value_param(), kMaxParamLength);
4559 }
4560 printf("\n");
4561 }
4562 }
4563 }
4564 fflush(stdout);
4565 }
4566
4567 // Sets the OS stack trace getter.
4568 //
4569 // Does nothing if the input and the current OS stack trace getter are
4570 // the same; otherwise, deletes the old getter and makes the input the
4571 // current getter.
4572 void UnitTestImpl::set_os_stack_trace_getter(
4573 OsStackTraceGetterInterface* getter) {
4574 if (os_stack_trace_getter_ != getter) {
4575 delete os_stack_trace_getter_;
4576 os_stack_trace_getter_ = getter;
4577 }
4578 }
4579
4580 // Returns the current OS stack trace getter if it is not NULL;
4581 // otherwise, creates an OsStackTraceGetter, makes it the current
4582 // getter, and returns it.
4583 OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() {
4584 if (os_stack_trace_getter_ == NULL) {
4585 os_stack_trace_getter_ = new OsStackTraceGetter;
4586 }
4587
4588 return os_stack_trace_getter_;
4589 }
4590
4591 // Returns the TestResult for the test that's currently running, or
4592 // the TestResult for the ad hoc test if no test is running.
4593 TestResult* UnitTestImpl::current_test_result() {
4594 return current_test_info_ ?
4595 &(current_test_info_->result_) : &ad_hoc_test_result_;
4596 }
4597
4598 // Shuffles all test cases, and the tests within each test case,
4599 // making sure that death tests are still run first.
4600 void UnitTestImpl::ShuffleTests() {
4601 // Shuffles the death test cases.
4602 ShuffleRange(random(), 0, last_death_test_case_ + 1, &test_case_indices_);
4603
4604 // Shuffles the non-death test cases.
4605 ShuffleRange(random(), last_death_test_case_ + 1,
4606 static_cast<int>(test_cases_.size()), &test_case_indices_);
4607
4608 // Shuffles the tests inside each test case.
4609 for (size_t i = 0; i < test_cases_.size(); i++) {
4610 test_cases_[i]->ShuffleTests(random());
4611 }
4612 }
4613
4614 // Restores the test cases and tests to their order before the first shuffle.
4615 void UnitTestImpl::UnshuffleTests() {
4616 for (size_t i = 0; i < test_cases_.size(); i++) {
4617 // Unshuffles the tests in each test case.
4618 test_cases_[i]->UnshuffleTests();
4619 // Resets the index of each test case.
4620 test_case_indices_[i] = static_cast<int>(i);
4621 }
4622 }
4623
4624 // Returns the current OS stack trace as an std::string.
4625 //
4626 // The maximum number of stack frames to be included is specified by
4627 // the gtest_stack_trace_depth flag. The skip_count parameter
4628 // specifies the number of top frames to be skipped, which doesn't
4629 // count against the number of frames to be included.
4630 //
4631 // For example, if Foo() calls Bar(), which in turn calls
4632 // GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
4633 // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
4634 std::string GetCurrentOsStackTraceExceptTop(UnitTest* /*unit_test*/,
4635 int skip_count) {
4636 // We pass skip_count + 1 to skip this wrapper function in addition
4637 // to what the user really wants to skip.
4638 return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1);
4639 }
4640
4641 // Used by the GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_ macro to
4642 // suppress unreachable code warnings.
4643 namespace {
4644 class ClassUniqueToAlwaysTrue {};
4645 }
4646
4647 bool IsTrue(bool condition) { return condition; }
4648
4649 bool AlwaysTrue() {
4650 #if GTEST_HAS_EXCEPTIONS
4651 // This condition is always false so AlwaysTrue() never actually throws,
4652 // but it makes the compiler think that it may throw.
4653 if (IsTrue(false))
4654 throw ClassUniqueToAlwaysTrue();
4655 #endif // GTEST_HAS_EXCEPTIONS
4656 return true;
4657 }
4658
4659 // If *pstr starts with the given prefix, modifies *pstr to be right
4660 // past the prefix and returns true; otherwise leaves *pstr unchanged
4661 // and returns false. None of pstr, *pstr, and prefix can be NULL.
4662 bool SkipPrefix(const char* prefix, const char** pstr) {
4663 const size_t prefix_len = strlen(prefix);
4664 if (strncmp(*pstr, prefix, prefix_len) == 0) {
4665 *pstr += prefix_len;
4666 return true;
4667 }
4668 return false;
4669 }
4670
4671 // Parses a string as a command line flag. The string should have
4672 // the format "--flag=value". When def_optional is true, the "=value"
4673 // part can be omitted.
4674 //
4675 // Returns the value of the flag, or NULL if the parsing failed.
4676 const char* ParseFlagValue(const char* str,
4677 const char* flag,
4678 bool def_optional) {
4679 // str and flag must not be NULL.
4680 if (str == NULL || flag == NULL) return NULL;
4681
4682 // The flag must start with "--" followed by GTEST_FLAG_PREFIX_.
4683 const std::string flag_str = std::string("--") + GTEST_FLAG_PREFIX_ + flag;
4684 const size_t flag_len = flag_str.length();
4685 if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL;
4686
4687 // Skips the flag name.
4688 const char* flag_end = str + flag_len;
4689
4690 // When def_optional is true, it's OK to not have a "=value" part.
4691 if (def_optional && (flag_end[0] == '\0')) {
4692 return flag_end;
4693 }
4694
4695 // If def_optional is true and there are more characters after the
4696 // flag name, or if def_optional is false, there must be a '=' after
4697 // the flag name.
4698 if (flag_end[0] != '=') return NULL;
4699
4700 // Returns the string after "=".
4701 return flag_end + 1;
4702 }
4703
4704 // Parses a string for a bool flag, in the form of either
4705 // "--flag=value" or "--flag".
4706 //
4707 // In the former case, the value is taken as true as long as it does
4708 // not start with '0', 'f', or 'F'.
4709 //
4710 // In the latter case, the value is taken as true.
4711 //
4712 // On success, stores the value of the flag in *value, and returns
4713 // true. On failure, returns false without changing *value.
4714 bool ParseBoolFlag(const char* str, const char* flag, bool* value) {
4715 // Gets the value of the flag as a string.
4716 const char* const value_str = ParseFlagValue(str, flag, true);
4717
4718 // Aborts if the parsing failed.
4719 if (value_str == NULL) return false;
4720
4721 // Converts the string value to a bool.
4722 *value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F');
4723 return true;
4724 }
4725
4726 // Parses a string for an Int32 flag, in the form of
4727 // "--flag=value".
4728 //
4729 // On success, stores the value of the flag in *value, and returns
4730 // true. On failure, returns false without changing *value.
4731 bool ParseInt32Flag(const char* str, const char* flag, Int32* value) {
4732 // Gets the value of the flag as a string.
4733 const char* const value_str = ParseFlagValue(str, flag, false);
4734
4735 // Aborts if the parsing failed.
4736 if (value_str == NULL) return false;
4737
4738 // Sets *value to the value of the flag.
4739 return ParseInt32(Message() << "The value of flag --" << flag,
4740 value_str, value);
4741 }
4742
4743 // Parses a string for a string flag, in the form of
4744 // "--flag=value".
4745 //
4746 // On success, stores the value of the flag in *value, and returns
4747 // true. On failure, returns false without changing *value.
4748 bool ParseStringFlag(const char* str, const char* flag, std::string* value) {
4749 // Gets the value of the flag as a string.
4750 const char* const value_str = ParseFlagValue(str, flag, false);
4751
4752 // Aborts if the parsing failed.
4753 if (value_str == NULL) return false;
4754
4755 // Sets *value to the value of the flag.
4756 *value = value_str;
4757 return true;
4758 }
4759
4760 // Determines whether a string has a prefix that Google Test uses for its
4761 // flags, i.e., starts with GTEST_FLAG_PREFIX_ or GTEST_FLAG_PREFIX_DASH_.
4762 // If Google Test detects that a command line flag has its prefix but is not
4763 // recognized, it will print its help message. Flags starting with
4764 // GTEST_INTERNAL_PREFIX_ followed by "internal_" are considered Google Test
4765 // internal flags and do not trigger the help message.
4766 static bool HasGoogleTestFlagPrefix(const char* str) {
4767 return (SkipPrefix("--", &str) ||
4768 SkipPrefix("-", &str) ||
4769 SkipPrefix("/", &str)) &&
4770 !SkipPrefix(GTEST_FLAG_PREFIX_ "internal_", &str) &&
4771 (SkipPrefix(GTEST_FLAG_PREFIX_, &str) ||
4772 SkipPrefix(GTEST_FLAG_PREFIX_DASH_, &str));
4773 }
4774
4775 // Prints a string containing code-encoded text. The following escape
4776 // sequences can be used in the string to control the text color:
4777 //
4778 // @@ prints a single '@' character.
4779 // @R changes the color to red.
4780 // @G changes the color to green.
4781 // @Y changes the color to yellow.
4782 // @D changes to the default terminal text color.
4783 //
4784 // TODO(wan@google.com): Write tests for this once we add stdout
4785 // capturing to Google Test.
4786 static void PrintColorEncoded(const char* str) {
4787 GTestColor color = COLOR_DEFAULT; // The current color.
4788
4789 // Conceptually, we split the string into segments divided by escape
4790 // sequences. Then we print one segment at a time. At the end of
4791 // each iteration, the str pointer advances to the beginning of the
4792 // next segment.
4793 for (;;) {
4794 const char* p = strchr(str, '@');
4795 if (p == NULL) {
4796 ColoredPrintf(color, "%s", str);
4797 return;
4798 }
4799
4800 ColoredPrintf(color, "%s", std::string(str, p).c_str());
4801
4802 const char ch = p[1];
4803 str = p + 2;
4804 if (ch == '@') {
4805 ColoredPrintf(color, "@");
4806 } else if (ch == 'D') {
4807 color = COLOR_DEFAULT;
4808 } else if (ch == 'R') {
4809 color = COLOR_RED;
4810 } else if (ch == 'G') {
4811 color = COLOR_GREEN;
4812 } else if (ch == 'Y') {
4813 color = COLOR_YELLOW;
4814 } else {
4815 --str;
4816 }
4817 }
4818 }
4819
4820 static const char kColorEncodedHelpMessage[] =
4821 "This program contains tests written using " GTEST_NAME_ ". You can use the\n"
4822 "following command line flags to control its behavior:\n"
4823 "\n"
4824 "Test Selection:\n"
4825 " @G--" GTEST_FLAG_PREFIX_ "list_tests@D\n"
4826 " List the names of all tests instead of running them. The name of\n"
4827 " TEST(Foo, Bar) is \"Foo.Bar\".\n"
4828 " @G--" GTEST_FLAG_PREFIX_ "filter=@YPOSTIVE_PATTERNS"
4829 "[@G-@YNEGATIVE_PATTERNS]@D\n"
4830 " Run only the tests whose name matches one of the positive patterns but\n"
4831 " none of the negative patterns. '?' matches any single character; '*'\n"
4832 " matches any substring; ':' separates two patterns.\n"
4833 " @G--" GTEST_FLAG_PREFIX_ "also_run_disabled_tests@D\n"
4834 " Run all disabled tests too.\n"
4835 "\n"
4836 "Test Execution:\n"
4837 " @G--" GTEST_FLAG_PREFIX_ "repeat=@Y[COUNT]@D\n"
4838 " Run the tests repeatedly; use a negative count to repeat forever.\n"
4839 " @G--" GTEST_FLAG_PREFIX_ "shuffle@D\n"
4840 " Randomize tests' orders on every iteration.\n"
4841 " @G--" GTEST_FLAG_PREFIX_ "random_seed=@Y[NUMBER]@D\n"
4842 " Random number seed to use for shuffling test orders (between 1 and\n"
4843 " 99999, or 0 to use a seed based on the current time).\n"
4844 "\n"
4845 "Test Output:\n"
4846 " @G--" GTEST_FLAG_PREFIX_ "color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\n"
4847 " Enable/disable colored output. The default is @Gauto@D.\n"
4848 " -@G-" GTEST_FLAG_PREFIX_ "print_time=0@D\n"
4849 " Don't print the elapsed time of each test.\n"
4850 " @G--" GTEST_FLAG_PREFIX_ "output=xml@Y[@G:@YDIRECTORY_PATH@G"
4851 GTEST_PATH_SEP_ "@Y|@G:@YFILE_PATH]@D\n"
4852 " Generate an XML report in the given directory or with the given file\n"
4853 " name. @YFILE_PATH@D defaults to @Gtest_details.xml@D.\n"
4854 #if GTEST_CAN_STREAM_RESULTS_
4855 " @G--" GTEST_FLAG_PREFIX_ "stream_result_to=@YHOST@G:@YPORT@D\n"
4856 " Stream test results to the given server.\n"
4857 #endif // GTEST_CAN_STREAM_RESULTS_
4858 "\n"
4859 "Assertion Behavior:\n"
4860 #if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
4861 " @G--" GTEST_FLAG_PREFIX_ "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n"
4862 " Set the default death test style.\n"
4863 #endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
4864 " @G--" GTEST_FLAG_PREFIX_ "break_on_failure@D\n"
4865 " Turn assertion failures into debugger break-points.\n"
4866 " @G--" GTEST_FLAG_PREFIX_ "throw_on_failure@D\n"
4867 " Turn assertion failures into C++ exceptions.\n"
4868 " @G--" GTEST_FLAG_PREFIX_ "catch_exceptions=0@D\n"
4869 " Do not report exceptions as test failures. Instead, allow them\n"
4870 " to crash the program or throw a pop-up (on Windows).\n"
4871 "\n"
4872 "Except for @G--" GTEST_FLAG_PREFIX_ "list_tests@D, you can alternatively set "
4873 "the corresponding\n"
4874 "environment variable of a flag (all letters in upper-case). For example, to\n"
4875 "disable colored text output, you can either specify @G--" GTEST_FLAG_PREFIX_
4876 "color=no@D or set\n"
4877 "the @G" GTEST_FLAG_PREFIX_UPPER_ "COLOR@D environment variable to @Gno@D.\n"
4878 "\n"
4879 "For more information, please read the " GTEST_NAME_ " documentation at\n"
4880 "@G" GTEST_PROJECT_URL_ "@D. If you find a bug in " GTEST_NAME_ "\n"
4881 "(not one in your own code or tests), please report it to\n"
4882 "@G<" GTEST_DEV_EMAIL_ ">@D.\n";
4883
4884 // Parses the command line for Google Test flags, without initializing
4885 // other parts of Google Test. The type parameter CharType can be
4886 // instantiated to either char or wchar_t.
4887 template <typename CharType>
4888 void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
4889 for (int i = 1; i < *argc; i++) {
4890 const std::string arg_string = StreamableToString(argv[i]);
4891 const char* const arg = arg_string.c_str();
4892
4893 using internal::ParseBoolFlag;
4894 using internal::ParseInt32Flag;
4895 using internal::ParseStringFlag;
4896
4897 // Do we see a Google Test flag?
4898 if (ParseBoolFlag(arg, kAlsoRunDisabledTestsFlag,
4899 &GTEST_FLAG(also_run_disabled_tests)) ||
4900 ParseBoolFlag(arg, kBreakOnFailureFlag,
4901 &GTEST_FLAG(break_on_failure)) ||
4902 ParseBoolFlag(arg, kCatchExceptionsFlag,
4903 &GTEST_FLAG(catch_exceptions)) ||
4904 ParseStringFlag(arg, kColorFlag, &GTEST_FLAG(color)) ||
4905 ParseStringFlag(arg, kDeathTestStyleFlag,
4906 &GTEST_FLAG(death_test_style)) ||
4907 ParseBoolFlag(arg, kDeathTestUseFork,
4908 &GTEST_FLAG(death_test_use_fork)) ||
4909 ParseStringFlag(arg, kFilterFlag, &GTEST_FLAG(filter)) ||
4910 ParseStringFlag(arg, kInternalRunDeathTestFlag,
4911 &GTEST_FLAG(internal_run_death_test)) ||
4912 ParseBoolFlag(arg, kListTestsFlag, &GTEST_FLAG(list_tests)) ||
4913 ParseStringFlag(arg, kOutputFlag, &GTEST_FLAG(output)) ||
4914 ParseBoolFlag(arg, kPrintTimeFlag, &GTEST_FLAG(print_time)) ||
4915 ParseInt32Flag(arg, kRandomSeedFlag, &GTEST_FLAG(random_seed)) ||
4916 ParseInt32Flag(arg, kRepeatFlag, &GTEST_FLAG(repeat)) ||
4917 ParseBoolFlag(arg, kShuffleFlag, &GTEST_FLAG(shuffle)) ||
4918 ParseInt32Flag(arg, kStackTraceDepthFlag,
4919 &GTEST_FLAG(stack_trace_depth)) ||
4920 ParseStringFlag(arg, kStreamResultToFlag,
4921 &GTEST_FLAG(stream_result_to)) ||
4922 ParseBoolFlag(arg, kThrowOnFailureFlag,
4923 &GTEST_FLAG(throw_on_failure))
4924 ) {
4925 // Yes. Shift the remainder of the argv list left by one. Note
4926 // that argv has (*argc + 1) elements, the last one always being
4927 // NULL. The following loop moves the trailing NULL element as
4928 // well.
4929 for (int j = i; j != *argc; j++) {
4930 argv[j] = argv[j + 1];
4931 }
4932
4933 // Decrements the argument count.
4934 (*argc)--;
4935
4936 // We also need to decrement the iterator as we just removed
4937 // an element.
4938 i--;
4939 } else if (arg_string == "--help" || arg_string == "-h" ||
4940 arg_string == "-?" || arg_string == "/?" ||
4941 HasGoogleTestFlagPrefix(arg)) {
4942 // Both help flag and unrecognized Google Test flags (excluding
4943 // internal ones) trigger help display.
4944 g_help_flag = true;
4945 }
4946 }
4947
4948 if (g_help_flag) {
4949 // We print the help here instead of in RUN_ALL_TESTS(), as the
4950 // latter may not be called at all if the user is using Google
4951 // Test with another testing framework.
4952 PrintColorEncoded(kColorEncodedHelpMessage);
4953 }
4954 }
4955
4956 // Parses the command line for Google Test flags, without initializing
4957 // other parts of Google Test.
4958 void ParseGoogleTestFlagsOnly(int* argc, char** argv) {
4959 ParseGoogleTestFlagsOnlyImpl(argc, argv);
4960 }
4961 void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv) {
4962 ParseGoogleTestFlagsOnlyImpl(argc, argv);
4963 }
4964
4965 // The internal implementation of InitGoogleTest().
4966 //
4967 // The type parameter CharType can be instantiated to either char or
4968 // wchar_t.
4969 template <typename CharType>
4970 void InitGoogleTestImpl(int* argc, CharType** argv) {
4971 g_init_gtest_count++;
4972
4973 // We don't want to run the initialization code twice.
4974 if (g_init_gtest_count != 1) return;
4975
4976 if (*argc <= 0) return;
4977
4978 internal::g_executable_path = internal::StreamableToString(argv[0]);
4979
4980 #if GTEST_HAS_DEATH_TEST
4981
4982 g_argvs.clear();
4983 for (int i = 0; i != *argc; i++) {
4984 g_argvs.push_back(StreamableToString(argv[i]));
4985 }
4986
4987 #endif // GTEST_HAS_DEATH_TEST
4988
4989 ParseGoogleTestFlagsOnly(argc, argv);
4990 GetUnitTestImpl()->PostFlagParsingInit();
4991 }
4992
4993 } // namespace internal
4994
4995 // Initializes Google Test. This must be called before calling
4996 // RUN_ALL_TESTS(). In particular, it parses a command line for the
4997 // flags that Google Test recognizes. Whenever a Google Test flag is
4998 // seen, it is removed from argv, and *argc is decremented.
4999 //
5000 // No value is returned. Instead, the Google Test flag variables are
5001 // updated.
5002 //
5003 // Calling the function for the second time has no user-visible effect.
5004 void InitGoogleTest(int* argc, char** argv) {
5005 internal::InitGoogleTestImpl(argc, argv);
5006 }
5007
5008 // This overloaded version can be used in Windows programs compiled in
5009 // UNICODE mode.
5010 void InitGoogleTest(int* argc, wchar_t** argv) {
5011 internal::InitGoogleTestImpl(argc, argv);
5012 }
5013
5014 } // namespace testing
0 // Copyright 2006, Google Inc.
1 // All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 // * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 #include <stdio.h>
30
31 #include "gtest/gtest.h"
32
33 GTEST_API_ int main(int argc, char **argv) {
34 printf("Running main() from gtest_main.cc\n");
35 testing::InitGoogleTest(&argc, argv);
36 return RUN_ALL_TESTS();
37 }