Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
2d1835b0
Commit
2d1835b0
authored
Sep 27, 2010
by
zhanyong.wan
Browse files
Removes uses of deprecated AssertionFailure() API (by Vlad Losev).
parent
b5d3a178
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
115 deletions
+82
-115
include/gtest/gtest.h
include/gtest/gtest.h
+2
-3
include/gtest/gtest_pred_impl.h
include/gtest/gtest_pred_impl.h
+36
-46
scripts/gen_gtest_pred_impl.py
scripts/gen_gtest_pred_impl.py
+5
-8
src/gtest.cc
src/gtest.cc
+28
-42
test/gtest_pred_impl_unittest.cc
test/gtest_pred_impl_unittest.cc
+11
-16
No files found.
include/gtest/gtest.h
View file @
2d1835b0
...
...
@@ -1385,11 +1385,10 @@ AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
if (val1 op val2) {\
return AssertionSuccess();\
} else {\
Message msg;
\
msg
<< "Expected: (" << expr1 << ") " #op " (" << expr2\
return AssertionFailure()
\
<< "Expected: (" << expr1 << ") " #op " (" << expr2\
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
<< " vs " << FormatForComparisonFailureMessage(val2, val1);\
return AssertionFailure(msg);\
}\
}\
GTEST_API_ AssertionResult CmpHelper##op_name(\
...
...
include/gtest/gtest_pred_impl.h
View file @
2d1835b0
...
...
@@ -27,7 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on
10/02
/200
8
by command
// This file is AUTOMATICALLY GENERATED on
09/24
/20
1
0 by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
//
// Implements a family of generic predicate assertion macros.
...
...
@@ -90,11 +90,9 @@ AssertionResult AssertPred1Helper(const char* pred_text,
const
T1
&
v1
)
{
if
(
pred
(
v1
))
return
AssertionSuccess
();
Message
msg
;
msg
<<
pred_text
<<
"("
<<
e1
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
;
return
AssertionFailure
(
msg
);
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT1.
...
...
@@ -136,13 +134,11 @@ AssertionResult AssertPred2Helper(const char* pred_text,
const
T2
&
v2
)
{
if
(
pred
(
v1
,
v2
))
return
AssertionSuccess
();
Message
msg
;
msg
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
;
return
AssertionFailure
(
msg
);
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2.
...
...
@@ -189,15 +185,13 @@ AssertionResult AssertPred3Helper(const char* pred_text,
const
T3
&
v3
)
{
if
(
pred
(
v1
,
v2
,
v3
))
return
AssertionSuccess
();
Message
msg
;
msg
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
", "
<<
e3
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
v3
;
return
AssertionFailure
(
msg
);
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
", "
<<
e3
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
v3
;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT3.
...
...
@@ -249,17 +243,15 @@ AssertionResult AssertPred4Helper(const char* pred_text,
const
T4
&
v4
)
{
if
(
pred
(
v1
,
v2
,
v3
,
v4
))
return
AssertionSuccess
();
Message
msg
;
msg
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
", "
<<
e3
<<
", "
<<
e4
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
v3
<<
"
\n
"
<<
e4
<<
" evaluates to "
<<
v4
;
return
AssertionFailure
(
msg
);
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
", "
<<
e3
<<
", "
<<
e4
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
v3
<<
"
\n
"
<<
e4
<<
" evaluates to "
<<
v4
;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT4.
...
...
@@ -316,19 +308,17 @@ AssertionResult AssertPred5Helper(const char* pred_text,
const
T5
&
v5
)
{
if
(
pred
(
v1
,
v2
,
v3
,
v4
,
v5
))
return
AssertionSuccess
();
Message
msg
;
msg
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
", "
<<
e3
<<
", "
<<
e4
<<
", "
<<
e5
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
v3
<<
"
\n
"
<<
e4
<<
" evaluates to "
<<
v4
<<
"
\n
"
<<
e5
<<
" evaluates to "
<<
v5
;
return
AssertionFailure
(
msg
);
return
AssertionFailure
()
<<
pred_text
<<
"("
<<
e1
<<
", "
<<
e2
<<
", "
<<
e3
<<
", "
<<
e4
<<
", "
<<
e5
<<
") evaluates to false, where"
<<
"
\n
"
<<
e1
<<
" evaluates to "
<<
v1
<<
"
\n
"
<<
e2
<<
" evaluates to "
<<
v2
<<
"
\n
"
<<
e3
<<
" evaluates to "
<<
v3
<<
"
\n
"
<<
e4
<<
" evaluates to "
<<
v4
<<
"
\n
"
<<
e5
<<
" evaluates to "
<<
v5
;
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT5.
...
...
scripts/gen_gtest_pred_impl.py
View file @
2d1835b0
...
...
@@ -238,21 +238,19 @@ AssertionResult AssertPred%(n)sHelper(const char* pred_text""" % DEFS
impl
+=
""") {
if (pred(%(vs)s)) return AssertionSuccess();
Message msg;
"""
%
DEFS
impl
+=
'
msg
<< pred_text << "("'
impl
+=
'
return AssertionFailure()
<< pred_text << "("'
impl
+=
Iter
(
n
,
"""
<< e%s"""
,
sep
=
' << ", "'
)
<< e%s"""
,
sep
=
' << ", "'
)
impl
+=
' << ") evaluates to false, where"'
impl
+=
Iter
(
n
,
"""
<< "
\\
n" << e%s << " evaluates to " << v%s"""
)
<< "
\\
n" << e%s << " evaluates to " << v%s"""
)
impl
+=
""";
return AssertionFailure(msg);
}
// Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT%(n)s.
...
...
@@ -478,15 +476,14 @@ testing::AssertionResult PredFormatFunction%(n)s(""" % DEFS
if (PredFunction%(n)s(%(vs)s))
return testing::AssertionSuccess();
testing::
Message msg;
msg
<< """
%
DEFS
return
testing::
AssertionFailure()
<< """
%
DEFS
tests
+=
Iter
(
n
,
'e%s'
,
sep
=
' << " + " << '
)
tests
+=
"""
<< " is expected to be positive, but evaluates to "
<< %(v_sum)s << ".";
return testing::AssertionFailure(msg);
}
"""
%
DEFS
...
...
src/gtest.cc
View file @
2d1835b0
...
...
@@ -618,23 +618,21 @@ AssertionResult HasOneFailure(const char* /* results_expr */,
for
(
int
i
=
0
;
i
<
results
.
size
();
i
++
)
{
msg
<<
"
\n
"
<<
results
.
GetTestPartResult
(
i
);
}
return
AssertionFailure
(
msg
)
;
return
AssertionFailure
(
)
<<
msg
;
}
const
TestPartResult
&
r
=
results
.
GetTestPartResult
(
0
);
if
(
r
.
type
()
!=
type
)
{
msg
<<
"Expected: "
<<
expected
<<
"
\n
"
<<
" Actual:
\n
"
<<
r
;
return
AssertionFailure
(
msg
);
return
AssertionFailure
()
<<
"Expected: "
<<
expected
<<
"
\n
"
<<
" Actual:
\n
"
<<
r
;
}
if
(
strstr
(
r
.
message
(),
substr
.
c_str
())
==
NULL
)
{
msg
<<
"Expected: "
<<
expected
<<
" containing
\"
"
<<
substr
<<
"
\"\n
"
<<
" Actual:
\n
"
<<
r
;
return
AssertionFailure
(
msg
);
return
AssertionFailure
()
<<
"Expected: "
<<
expected
<<
" containing
\"
"
<<
substr
<<
"
\"\n
"
<<
" Actual:
\n
"
<<
r
;
}
return
AssertionSuccess
();
...
...
@@ -1011,7 +1009,7 @@ AssertionResult EqFailure(const char* expected_expression,
msg
<<
"
\n
Which is: "
<<
expected_value
;
}
return
AssertionFailure
(
msg
)
;
return
AssertionFailure
(
)
<<
msg
;
}
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
...
...
@@ -1041,13 +1039,12 @@ AssertionResult DoubleNearPredFormat(const char* expr1,
// TODO(wan): do not print the value of an expression if it's
// already a literal.
Message
msg
;
msg
<<
"The difference between "
<<
expr1
<<
" and "
<<
expr2
return
AssertionFailure
()
<<
"The difference between "
<<
expr1
<<
" and "
<<
expr2
<<
" is "
<<
diff
<<
", which exceeds "
<<
abs_error_expr
<<
", where
\n
"
<<
expr1
<<
" evaluates to "
<<
val1
<<
",
\n
"
<<
expr2
<<
" evaluates to "
<<
val2
<<
", and
\n
"
<<
abs_error_expr
<<
" evaluates to "
<<
abs_error
<<
"."
;
return
AssertionFailure
(
msg
);
}
...
...
@@ -1080,12 +1077,10 @@ AssertionResult FloatingPointLE(const char* expr1,
val2_ss
<<
std
::
setprecision
(
std
::
numeric_limits
<
RawType
>::
digits10
+
2
)
<<
val2
;
Message
msg
;
msg
<<
"Expected: ("
<<
expr1
<<
") <= ("
<<
expr2
<<
")
\n
"
return
AssertionFailure
()
<<
"Expected: ("
<<
expr1
<<
") <= ("
<<
expr2
<<
")
\n
"
<<
" Actual: "
<<
StringStreamToString
(
&
val1_ss
)
<<
" vs "
<<
StringStreamToString
(
&
val2_ss
);
return
AssertionFailure
(
msg
);
}
}
// namespace internal
...
...
@@ -1132,11 +1127,10 @@ AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
if (val1 op val2) {\
return AssertionSuccess();\
} else {\
Message msg;
\
msg
<< "Expected: (" << expr1 << ") " #op " (" << expr2\
return AssertionFailure()
\
<< "Expected: (" << expr1 << ") " #op " (" << expr2\
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
<< " vs " << FormatForComparisonFailureMessage(val2, val1);\
return AssertionFailure(msg);\
}\
}
...
...
@@ -1198,11 +1192,9 @@ AssertionResult CmpHelperSTRNE(const char* s1_expression,
if
(
!
String
::
CStringEquals
(
s1
,
s2
))
{
return
AssertionSuccess
();
}
else
{
Message
msg
;
msg
<<
"Expected: ("
<<
s1_expression
<<
") != ("
<<
s2_expression
<<
"), actual:
\"
"
<<
s1
<<
"
\"
vs
\"
"
<<
s2
<<
"
\"
"
;
return
AssertionFailure
(
msg
);
return
AssertionFailure
()
<<
"Expected: ("
<<
s1_expression
<<
") != ("
<<
s2_expression
<<
"), actual:
\"
"
<<
s1
<<
"
\"
vs
\"
"
<<
s2
<<
"
\"
"
;
}
}
...
...
@@ -1214,11 +1206,10 @@ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
if
(
!
String
::
CaseInsensitiveCStringEquals
(
s1
,
s2
))
{
return
AssertionSuccess
();
}
else
{
Message
msg
;
msg
<<
"Expected: ("
<<
s1_expression
<<
") != ("
return
AssertionFailure
()
<<
"Expected: ("
<<
s1_expression
<<
") != ("
<<
s2_expression
<<
") (ignoring case), actual:
\"
"
<<
s1
<<
"
\"
vs
\"
"
<<
s2
<<
"
\"
"
;
return
AssertionFailure
(
msg
);
}
}
...
...
@@ -1267,13 +1258,12 @@ AssertionResult IsSubstringImpl(
const
bool
is_wide_string
=
sizeof
(
needle
[
0
])
>
1
;
const
char
*
const
begin_string_quote
=
is_wide_string
?
"L
\"
"
:
"
\"
"
;
return
AssertionFailure
(
Message
()
return
AssertionFailure
()
<<
"Value of: "
<<
needle_expr
<<
"
\n
"
<<
" Actual: "
<<
begin_string_quote
<<
needle
<<
"
\"\n
"
<<
"Expected: "
<<
(
expected_to_be_substring
?
""
:
"not "
)
<<
"a substring of "
<<
haystack_expr
<<
"
\n
"
<<
"Which is: "
<<
begin_string_quote
<<
haystack
<<
"
\"
"
)
;
<<
"Which is: "
<<
begin_string_quote
<<
haystack
<<
"
\"
"
;
}
}
// namespace
...
...
@@ -1369,11 +1359,9 @@ AssertionResult HRESULTFailureHelper(const char* expr,
#endif // GTEST_OS_WINDOWS_MOBILE
const
String
error_hex
(
String
::
Format
(
"0x%08X "
,
hr
));
Message
msg
;
msg
<<
"Expected: "
<<
expr
<<
" "
<<
expected
<<
".
\n
"
return
::
testing
::
AssertionFailure
()
<<
"Expected: "
<<
expr
<<
" "
<<
expected
<<
".
\n
"
<<
" Actual: "
<<
error_hex
<<
error_text
<<
"
\n
"
;
return
::
testing
::
AssertionFailure
(
msg
);
}
}
// namespace
...
...
@@ -1584,12 +1572,10 @@ AssertionResult CmpHelperSTRNE(const char* s1_expression,
return
AssertionSuccess
();
}
Message
msg
;
msg
<<
"Expected: ("
<<
s1_expression
<<
") != ("
<<
s2_expression
<<
"), actual: "
<<
String
::
ShowWideCStringQuoted
(
s1
)
<<
" vs "
<<
String
::
ShowWideCStringQuoted
(
s2
);
return
AssertionFailure
(
msg
);
return
AssertionFailure
()
<<
"Expected: ("
<<
s1_expression
<<
") != ("
<<
s2_expression
<<
"), actual: "
<<
String
::
ShowWideCStringQuoted
(
s1
)
<<
" vs "
<<
String
::
ShowWideCStringQuoted
(
s2
);
}
// Compares two C strings, ignoring case. Returns true iff they have
...
...
test/gtest_pred_impl_unittest.cc
View file @
2d1835b0
...
...
@@ -27,7 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on
10/02
/200
8
by command
// This file is AUTOMATICALLY GENERATED on
09/24
/20
1
0 by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
// Regression test for gtest_pred_impl.h
...
...
@@ -103,11 +103,10 @@ testing::AssertionResult PredFormatFunction1(const char* e1,
if
(
PredFunction1
(
v1
))
return
testing
::
AssertionSuccess
();
testing
::
Message
msg
;
msg
<<
e1
return
testing
::
AssertionFailure
()
<<
e1
<<
" is expected to be positive, but evaluates to "
<<
v1
<<
"."
;
return
testing
::
AssertionFailure
(
msg
);
}
// A unary predicate-formatter functor.
...
...
@@ -494,11 +493,10 @@ testing::AssertionResult PredFormatFunction2(const char* e1,
if
(
PredFunction2
(
v1
,
v2
))
return
testing
::
AssertionSuccess
();
testing
::
Message
msg
;
msg
<<
e1
<<
" + "
<<
e2
return
testing
::
AssertionFailure
()
<<
e1
<<
" + "
<<
e2
<<
" is expected to be positive, but evaluates to "
<<
v1
+
v2
<<
"."
;
return
testing
::
AssertionFailure
(
msg
);
}
// A binary predicate-formatter functor.
...
...
@@ -927,11 +925,10 @@ testing::AssertionResult PredFormatFunction3(const char* e1,
if
(
PredFunction3
(
v1
,
v2
,
v3
))
return
testing
::
AssertionSuccess
();
testing
::
Message
msg
;
msg
<<
e1
<<
" + "
<<
e2
<<
" + "
<<
e3
return
testing
::
AssertionFailure
()
<<
e1
<<
" + "
<<
e2
<<
" + "
<<
e3
<<
" is expected to be positive, but evaluates to "
<<
v1
+
v2
+
v3
<<
"."
;
return
testing
::
AssertionFailure
(
msg
);
}
// A ternary predicate-formatter functor.
...
...
@@ -1402,11 +1399,10 @@ testing::AssertionResult PredFormatFunction4(const char* e1,
if
(
PredFunction4
(
v1
,
v2
,
v3
,
v4
))
return
testing
::
AssertionSuccess
();
testing
::
Message
msg
;
msg
<<
e1
<<
" + "
<<
e2
<<
" + "
<<
e3
<<
" + "
<<
e4
return
testing
::
AssertionFailure
()
<<
e1
<<
" + "
<<
e2
<<
" + "
<<
e3
<<
" + "
<<
e4
<<
" is expected to be positive, but evaluates to "
<<
v1
+
v2
+
v3
+
v4
<<
"."
;
return
testing
::
AssertionFailure
(
msg
);
}
// A 4-ary predicate-formatter functor.
...
...
@@ -1919,11 +1915,10 @@ testing::AssertionResult PredFormatFunction5(const char* e1,
if
(
PredFunction5
(
v1
,
v2
,
v3
,
v4
,
v5
))
return
testing
::
AssertionSuccess
();
testing
::
Message
msg
;
msg
<<
e1
<<
" + "
<<
e2
<<
" + "
<<
e3
<<
" + "
<<
e4
<<
" + "
<<
e5
return
testing
::
AssertionFailure
()
<<
e1
<<
" + "
<<
e2
<<
" + "
<<
e3
<<
" + "
<<
e4
<<
" + "
<<
e5
<<
" is expected to be positive, but evaluates to "
<<
v1
+
v2
+
v3
+
v4
+
v5
<<
"."
;
return
testing
::
AssertionFailure
(
msg
);
}
// A 5-ary predicate-formatter functor.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment