127
125
using testing::Message;
128
126
using testing::ScopedFakeTestPartResultReporter;
129
127
using testing::StaticAssertTypeEq;
128
using testing::TPRT_FATAL_FAILURE;
129
using testing::TPRT_NONFATAL_FAILURE;
130
using testing::TPRT_SUCCESS;
130
131
using testing::Test;
131
132
using testing::TestPartResult;
132
133
using testing::TestPartResultArray;
133
using testing::TPRT_FATAL_FAILURE;
134
using testing::TPRT_NONFATAL_FAILURE;
135
using testing::TPRT_SUCCESS;
136
134
using testing::UnitTest;
135
using testing::internal::kMaxRandomSeed;
137
136
using testing::internal::kTestTypeIdInGoogleTest;
138
137
using testing::internal::AppendUserMessage;
139
using testing::internal::ClearCurrentTestPartResults;
140
138
using testing::internal::CodePointToUtf8;
141
139
using testing::internal::EqFailure;
142
140
using testing::internal::FloatingPoint;
141
using testing::internal::GTestFlagSaver;
143
142
using testing::internal::GetCurrentOsStackTraceExceptTop;
144
using testing::internal::GetFailedPartCount;
143
using testing::internal::GetNextRandomSeed;
144
using testing::internal::GetRandomSeedFromFlag;
145
145
using testing::internal::GetTestTypeId;
146
146
using testing::internal::GetTypeId;
147
using testing::internal::GTestFlagSaver;
147
using testing::internal::GetUnitTestImpl;
148
148
using testing::internal::Int32;
149
149
using testing::internal::Int32FromEnvOrDie;
150
using testing::internal::List;
151
150
using testing::internal::ShouldRunTestOnShard;
152
151
using testing::internal::ShouldShard;
153
152
using testing::internal::ShouldUseColor;
154
153
using testing::internal::StreamableToString;
155
154
using testing::internal::String;
155
using testing::internal::TestCase;
156
156
using testing::internal::TestProperty;
157
157
using testing::internal::TestResult;
158
using testing::internal::TestResultAccessor;
158
159
using testing::internal::ThreadLocal;
159
using testing::internal::UnitTestImpl;
160
using testing::internal::Vector;
160
161
using testing::internal::WideStringToUtf8;
162
using testing::internal::kTestTypeIdInGoogleTest;
162
164
// This line tests that we can define tests in an unnamed namespace.
167
TEST(GetRandomSeedFromFlagTest, HandlesZero) {
168
const int seed = GetRandomSeedFromFlag(0);
170
EXPECT_LE(seed, static_cast<int>(kMaxRandomSeed));
173
TEST(GetRandomSeedFromFlagTest, PreservesValidSeed) {
174
EXPECT_EQ(1, GetRandomSeedFromFlag(1));
175
EXPECT_EQ(2, GetRandomSeedFromFlag(2));
176
EXPECT_EQ(kMaxRandomSeed - 1, GetRandomSeedFromFlag(kMaxRandomSeed - 1));
177
EXPECT_EQ(static_cast<int>(kMaxRandomSeed),
178
GetRandomSeedFromFlag(kMaxRandomSeed));
181
TEST(GetRandomSeedFromFlagTest, NormalizesInvalidSeed) {
182
const int seed1 = GetRandomSeedFromFlag(-1);
184
EXPECT_LE(seed1, static_cast<int>(kMaxRandomSeed));
186
const int seed2 = GetRandomSeedFromFlag(kMaxRandomSeed + 1);
188
EXPECT_LE(seed2, static_cast<int>(kMaxRandomSeed));
191
TEST(GetNextRandomSeedTest, WorksForValidInput) {
192
EXPECT_EQ(2, GetNextRandomSeed(1));
193
EXPECT_EQ(3, GetNextRandomSeed(2));
194
EXPECT_EQ(static_cast<int>(kMaxRandomSeed),
195
GetNextRandomSeed(kMaxRandomSeed - 1));
196
EXPECT_EQ(1, GetNextRandomSeed(kMaxRandomSeed));
198
// We deliberately don't test GetNextRandomSeed() with invalid
199
// inputs, as that requires death tests, which are expensive. This
200
// is fine as GetNextRandomSeed() is internal and has a
201
// straightforward definition.
204
static void ClearCurrentTestPartResults() {
205
TestResultAccessor::ClearTestPartResults(
206
GetUnitTestImpl()->current_test_result());
165
209
// Tests GetTypeId.
167
211
TEST(GetTypeIdTest, ReturnsSameValueForSameType) {
429
473
#endif // !GTEST_WIDE_STRING_USES_UTF16_
431
// Tests the List template class.
433
// Tests List::PushFront().
434
TEST(ListTest, PushFront) {
436
ASSERT_EQ(0u, a.size());
438
// Calls PushFront() on an empty list.
475
// Tests the Vector class template.
477
// Tests Vector::Clear().
478
TEST(VectorTest, Clear) {
482
EXPECT_EQ(0, a.size());
487
EXPECT_EQ(0, a.size());
490
// Tests Vector::PushBack().
491
TEST(VectorTest, PushBack) {
494
ASSERT_EQ(1, a.size());
495
EXPECT_EQ('a', a.GetElement(0));
498
ASSERT_EQ(2, a.size());
499
EXPECT_EQ('a', a.GetElement(0));
500
EXPECT_EQ('b', a.GetElement(1));
503
// Tests Vector::PushFront().
504
TEST(VectorTest, PushFront) {
506
ASSERT_EQ(0, a.size());
508
// Calls PushFront() on an empty Vector.
440
ASSERT_EQ(1u, a.size());
441
EXPECT_EQ(1, a.Head()->element());
442
ASSERT_EQ(a.Head(), a.Last());
510
ASSERT_EQ(1, a.size());
511
EXPECT_EQ(1, a.GetElement(0));
444
// Calls PushFront() on a singleton list.
513
// Calls PushFront() on a singleton Vector.
446
ASSERT_EQ(2u, a.size());
447
EXPECT_EQ(2, a.Head()->element());
448
EXPECT_EQ(1, a.Last()->element());
515
ASSERT_EQ(2, a.size());
516
EXPECT_EQ(2, a.GetElement(0));
517
EXPECT_EQ(1, a.GetElement(1));
450
// Calls PushFront() on a list with more than one elements.
519
// Calls PushFront() on a Vector with more than one elements.
452
ASSERT_EQ(3u, a.size());
453
EXPECT_EQ(3, a.Head()->element());
454
EXPECT_EQ(2, a.Head()->next()->element());
455
EXPECT_EQ(1, a.Last()->element());
521
ASSERT_EQ(3, a.size());
522
EXPECT_EQ(3, a.GetElement(0));
523
EXPECT_EQ(2, a.GetElement(1));
524
EXPECT_EQ(1, a.GetElement(2));
458
// Tests List::PopFront().
459
TEST(ListTest, PopFront) {
527
// Tests Vector::PopFront().
528
TEST(VectorTest, PopFront) {
462
// Popping on an empty list should fail.
531
// Popping on an empty Vector should fail.
463
532
EXPECT_FALSE(a.PopFront(NULL));
465
// Popping again on an empty list should fail, and the result element
534
// Popping again on an empty Vector should fail, and the result element
466
535
// shouldn't be overwritten.
468
537
EXPECT_FALSE(a.PopFront(&element));
474
// PopFront() should pop the element in the front of the list.
543
// PopFront() should pop the element in the front of the Vector.
475
544
EXPECT_TRUE(a.PopFront(&element));
476
545
EXPECT_EQ(3, element);
478
// After popping the last element, the list should be empty.
547
// After popping the last element, the Vector should be empty.
479
548
EXPECT_TRUE(a.PopFront(NULL));
480
EXPECT_EQ(0u, a.size());
549
EXPECT_EQ(0, a.size());
483
// Tests inserting at the beginning using List::InsertAfter().
484
TEST(ListTest, InsertAfterAtBeginning) {
486
ASSERT_EQ(0u, a.size());
488
// Inserts into an empty list.
489
a.InsertAfter(NULL, 1);
490
ASSERT_EQ(1u, a.size());
491
EXPECT_EQ(1, a.Head()->element());
492
ASSERT_EQ(a.Head(), a.Last());
494
// Inserts at the beginning of a singleton list.
495
a.InsertAfter(NULL, 2);
496
ASSERT_EQ(2u, a.size());
497
EXPECT_EQ(2, a.Head()->element());
498
EXPECT_EQ(1, a.Last()->element());
500
// Inserts at the beginning of a list with more than one elements.
501
a.InsertAfter(NULL, 3);
502
ASSERT_EQ(3u, a.size());
503
EXPECT_EQ(3, a.Head()->element());
504
EXPECT_EQ(2, a.Head()->next()->element());
505
EXPECT_EQ(1, a.Last()->element());
552
// Tests inserting at the beginning using Vector::Insert().
553
TEST(VectorTest, InsertAtBeginning) {
555
ASSERT_EQ(0, a.size());
557
// Inserts into an empty Vector.
559
ASSERT_EQ(1, a.size());
560
EXPECT_EQ(1, a.GetElement(0));
562
// Inserts at the beginning of a singleton Vector.
564
ASSERT_EQ(2, a.size());
565
EXPECT_EQ(2, a.GetElement(0));
566
EXPECT_EQ(1, a.GetElement(1));
568
// Inserts at the beginning of a Vector with more than one elements.
570
ASSERT_EQ(3, a.size());
571
EXPECT_EQ(3, a.GetElement(0));
572
EXPECT_EQ(2, a.GetElement(1));
573
EXPECT_EQ(1, a.GetElement(2));
508
576
// Tests inserting at a location other than the beginning using
509
// List::InsertAfter().
510
TEST(ListTest, InsertAfterNotAtBeginning) {
511
// Prepares a singleton list.
515
// Inserts at the end of a singleton list.
516
a.InsertAfter(a.Last(), 2);
517
ASSERT_EQ(2u, a.size());
518
EXPECT_EQ(1, a.Head()->element());
519
EXPECT_EQ(2, a.Last()->element());
521
// Inserts at the end of a list with more than one elements.
522
a.InsertAfter(a.Last(), 3);
523
ASSERT_EQ(3u, a.size());
524
EXPECT_EQ(1, a.Head()->element());
525
EXPECT_EQ(2, a.Head()->next()->element());
526
EXPECT_EQ(3, a.Last()->element());
528
// Inserts in the middle of a list.
529
a.InsertAfter(a.Head(), 4);
530
ASSERT_EQ(4u, a.size());
531
EXPECT_EQ(1, a.Head()->element());
532
EXPECT_EQ(4, a.Head()->next()->element());
533
EXPECT_EQ(2, a.Head()->next()->next()->element());
534
EXPECT_EQ(3, a.Last()->element());
578
TEST(VectorTest, InsertNotAtBeginning) {
579
// Prepares a singleton Vector.
583
// Inserts at the end of a singleton Vector.
584
a.Insert(2, a.size());
585
ASSERT_EQ(2, a.size());
586
EXPECT_EQ(1, a.GetElement(0));
587
EXPECT_EQ(2, a.GetElement(1));
589
// Inserts at the end of a Vector with more than one elements.
590
a.Insert(3, a.size());
591
ASSERT_EQ(3, a.size());
592
EXPECT_EQ(1, a.GetElement(0));
593
EXPECT_EQ(2, a.GetElement(1));
594
EXPECT_EQ(3, a.GetElement(2));
596
// Inserts in the middle of a Vector.
598
ASSERT_EQ(4, a.size());
599
EXPECT_EQ(1, a.GetElement(0));
600
EXPECT_EQ(4, a.GetElement(1));
601
EXPECT_EQ(2, a.GetElement(2));
602
EXPECT_EQ(3, a.GetElement(3));
605
// Tests Vector::GetElementOr().
606
TEST(VectorTest, GetElementOr) {
608
EXPECT_EQ('x', a.GetElementOr(0, 'x'));
612
EXPECT_EQ('a', a.GetElementOr(0, 'x'));
613
EXPECT_EQ('b', a.GetElementOr(1, 'x'));
614
EXPECT_EQ('x', a.GetElementOr(-2, 'x'));
615
EXPECT_EQ('x', a.GetElementOr(2, 'x'));
618
// Tests Vector::Erase().
619
TEST(VectorDeathTest, Erase) {
622
// Tests erasing from an empty vector.
623
EXPECT_DEATH_IF_SUPPORTED(
625
"Invalid Vector index 0: must be in range \\[0, -1\\]\\.");
627
// Tests erasing from a singleton vector.
631
EXPECT_EQ(0, a.size());
633
// Tests Erase parameters beyond the bounds of the vector.
639
EXPECT_DEATH_IF_SUPPORTED(
641
"Invalid Vector index 3: must be in range \\[0, 2\\]\\.");
642
EXPECT_DEATH_IF_SUPPORTED(
644
"Invalid Vector index -1: must be in range \\[0, 2\\]\\.");
646
// Tests erasing at the end of the vector.
653
ASSERT_EQ(2, a2.size());
654
EXPECT_EQ(0, a2.GetElement(0));
655
EXPECT_EQ(1, a2.GetElement(1));
657
// Tests erasing in the middle of the vector.
664
ASSERT_EQ(2, a3.size());
665
EXPECT_EQ(0, a3.GetElement(0));
666
EXPECT_EQ(2, a3.GetElement(1));
668
// Tests erasing at the beginning of the vector.
675
ASSERT_EQ(2, a4.size());
676
EXPECT_EQ(1, a4.GetElement(0));
677
EXPECT_EQ(2, a4.GetElement(1));
680
// Tests the GetElement accessor.
681
TEST(ListDeathTest, GetElement) {
687
EXPECT_EQ(0, a.GetElement(0));
688
EXPECT_EQ(1, a.GetElement(1));
689
EXPECT_EQ(2, a.GetElement(2));
690
EXPECT_DEATH_IF_SUPPORTED(
692
"Invalid Vector index 3: must be in range \\[0, 2\\]\\.");
693
EXPECT_DEATH_IF_SUPPORTED(
695
"Invalid Vector index -1: must be in range \\[0, 2\\]\\.");
538
698
// Tests the String class.
1038
1198
#endif // GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD
1200
// Tests the TestProperty class.
1202
TEST(TestPropertyTest, ConstructorWorks) {
1203
const TestProperty property("key", "value");
1204
EXPECT_STREQ("key", property.key());
1205
EXPECT_STREQ("value", property.value());
1208
TEST(TestPropertyTest, SetValue) {
1209
TestProperty property("key", "value_1");
1210
EXPECT_STREQ("key", property.key());
1211
property.SetValue("value_2");
1212
EXPECT_STREQ("key", property.key());
1213
EXPECT_STREQ("value_2", property.value());
1216
// Tests the TestPartResult class.
1218
TEST(TestPartResultTest, ConstructorWorks) {
1220
message << "something is terribly wrong";
1221
message << static_cast<const char*>(testing::internal::kStackTraceMarker);
1222
message << "some unimportant stack trace";
1224
const TestPartResult result(TPRT_NONFATAL_FAILURE,
1227
message.GetString().c_str());
1229
EXPECT_EQ(TPRT_NONFATAL_FAILURE, result.type());
1230
EXPECT_STREQ("some_file.cc", result.file_name());
1231
EXPECT_EQ(42, result.line_number());
1232
EXPECT_STREQ(message.GetString().c_str(), result.message());
1233
EXPECT_STREQ("something is terribly wrong", result.summary());
1236
TEST(TestPartResultTest, ResultAccessorsWork) {
1237
const TestPartResult success(TPRT_SUCCESS, "file.cc", 42, "message");
1238
EXPECT_TRUE(success.passed());
1239
EXPECT_FALSE(success.failed());
1240
EXPECT_FALSE(success.nonfatally_failed());
1241
EXPECT_FALSE(success.fatally_failed());
1243
const TestPartResult nonfatal_failure(TPRT_NONFATAL_FAILURE,
1247
EXPECT_FALSE(nonfatal_failure.passed());
1248
EXPECT_TRUE(nonfatal_failure.failed());
1249
EXPECT_TRUE(nonfatal_failure.nonfatally_failed());
1250
EXPECT_FALSE(nonfatal_failure.fatally_failed());
1252
const TestPartResult fatal_failure(TPRT_FATAL_FAILURE,
1256
EXPECT_FALSE(fatal_failure.passed());
1257
EXPECT_TRUE(fatal_failure.failed());
1258
EXPECT_FALSE(fatal_failure.nonfatally_failed());
1259
EXPECT_TRUE(fatal_failure.fatally_failed());
1040
1262
// Tests the TestResult class
1042
1264
// The test fixture for testing TestResult.
1043
1265
class TestResultTest : public Test {
1045
typedef List<TestPartResult> TPRList;
1267
typedef Vector<TestPartResult> TPRVector;
1047
1269
// We make use of 2 TestPartResult objects,
1048
1270
TestPartResult * pr1, * pr2;
1318
// Helper that compares two two TestPartResults.
1319
static void CompareTestPartResult(const TestPartResult& expected,
1320
const TestPartResult& actual) {
1321
EXPECT_EQ(expected.type(), actual.type());
1322
EXPECT_STREQ(expected.file_name(), actual.file_name());
1323
EXPECT_EQ(expected.line_number(), actual.line_number());
1324
EXPECT_STREQ(expected.summary(), actual.summary());
1325
EXPECT_STREQ(expected.message(), actual.message());
1326
EXPECT_EQ(expected.passed(), actual.passed());
1327
EXPECT_EQ(expected.failed(), actual.failed());
1328
EXPECT_EQ(expected.nonfatally_failed(), actual.nonfatally_failed());
1329
EXPECT_EQ(expected.fatally_failed(), actual.fatally_failed());
1098
// Tests TestResult::test_part_results()
1099
TEST_F(TestResultTest, test_part_results) {
1100
ASSERT_EQ(0u, r0->test_part_results().size());
1101
ASSERT_EQ(1u, r1->test_part_results().size());
1102
ASSERT_EQ(2u, r2->test_part_results().size());
1105
// Tests TestResult::successful_part_count()
1106
TEST_F(TestResultTest, successful_part_count) {
1107
ASSERT_EQ(0u, r0->successful_part_count());
1108
ASSERT_EQ(1u, r1->successful_part_count());
1109
ASSERT_EQ(1u, r2->successful_part_count());
1112
// Tests TestResult::failed_part_count()
1113
TEST_F(TestResultTest, failed_part_count) {
1114
ASSERT_EQ(0u, r0->failed_part_count());
1115
ASSERT_EQ(0u, r1->failed_part_count());
1116
ASSERT_EQ(1u, r2->failed_part_count());
1119
// Tests testing::internal::GetFailedPartCount().
1120
TEST_F(TestResultTest, GetFailedPartCount) {
1121
ASSERT_EQ(0u, GetFailedPartCount(r0));
1122
ASSERT_EQ(0u, GetFailedPartCount(r1));
1123
ASSERT_EQ(1u, GetFailedPartCount(r2));
1126
// Tests TestResult::total_part_count()
1333
// Tests TestResult::total_part_count().
1127
1334
TEST_F(TestResultTest, total_part_count) {
1128
ASSERT_EQ(0u, r0->total_part_count());
1129
ASSERT_EQ(1u, r1->total_part_count());
1130
ASSERT_EQ(2u, r2->total_part_count());
1335
ASSERT_EQ(0, r0->total_part_count());
1336
ASSERT_EQ(1, r1->total_part_count());
1337
ASSERT_EQ(2, r2->total_part_count());
1133
// Tests TestResult::Passed()
1340
// Tests TestResult::Passed().
1134
1341
TEST_F(TestResultTest, Passed) {
1135
1342
ASSERT_TRUE(r0->Passed());
1136
1343
ASSERT_TRUE(r1->Passed());
1137
1344
ASSERT_FALSE(r2->Passed());
1140
// Tests TestResult::Failed()
1347
// Tests TestResult::Failed().
1141
1348
TEST_F(TestResultTest, Failed) {
1142
1349
ASSERT_FALSE(r0->Failed());
1143
1350
ASSERT_FALSE(r1->Failed());
1144
1351
ASSERT_TRUE(r2->Failed());
1147
// Tests TestResult::test_properties() has no properties when none are added.
1354
// Tests TestResult::GetTestPartResult().
1356
typedef TestResultTest TestResultDeathTest;
1358
TEST_F(TestResultDeathTest, GetTestPartResult) {
1359
CompareTestPartResult(*pr1, r2->GetTestPartResult(0));
1360
CompareTestPartResult(*pr2, r2->GetTestPartResult(1));
1361
EXPECT_DEATH_IF_SUPPORTED(
1362
r2->GetTestPartResult(2),
1363
"Invalid Vector index 2: must be in range \\[0, 1\\]\\.");
1364
EXPECT_DEATH_IF_SUPPORTED(
1365
r2->GetTestPartResult(-1),
1366
"Invalid Vector index -1: must be in range \\[0, 1\\]\\.");
1369
// Tests TestResult has no properties when none are added.
1148
1370
TEST(TestResultPropertyTest, NoPropertiesFoundWhenNoneAreAdded) {
1149
1371
TestResult test_result;
1150
ASSERT_EQ(0u, test_result.test_properties().size());
1372
ASSERT_EQ(0, test_result.test_property_count());
1153
// Tests TestResult::test_properties() has the expected property when added.
1375
// Tests TestResult has the expected property when added.
1154
1376
TEST(TestResultPropertyTest, OnePropertyFoundWhenAdded) {
1155
1377
TestResult test_result;
1156
1378
TestProperty property("key_1", "1");
1157
test_result.RecordProperty(property);
1158
const List<TestProperty>& properties = test_result.test_properties();
1159
ASSERT_EQ(1u, properties.size());
1160
TestProperty actual_property = properties.Head()->element();
1379
TestResultAccessor::RecordProperty(&test_result, property);
1380
ASSERT_EQ(1, test_result.test_property_count());
1381
const TestProperty& actual_property = test_result.GetTestProperty(0);
1161
1382
EXPECT_STREQ("key_1", actual_property.key());
1162
1383
EXPECT_STREQ("1", actual_property.value());
1165
// Tests TestResult::test_properties() has multiple properties when added.
1386
// Tests TestResult has multiple properties when added.
1166
1387
TEST(TestResultPropertyTest, MultiplePropertiesFoundWhenAdded) {
1167
1388
TestResult test_result;
1168
1389
TestProperty property_1("key_1", "1");
1169
1390
TestProperty property_2("key_2", "2");
1170
test_result.RecordProperty(property_1);
1171
test_result.RecordProperty(property_2);
1172
const List<TestProperty>& properties = test_result.test_properties();
1173
ASSERT_EQ(2u, properties.size());
1174
TestProperty actual_property_1 = properties.Head()->element();
1391
TestResultAccessor::RecordProperty(&test_result, property_1);
1392
TestResultAccessor::RecordProperty(&test_result, property_2);
1393
ASSERT_EQ(2, test_result.test_property_count());
1394
const TestProperty& actual_property_1 = test_result.GetTestProperty(0);
1175
1395
EXPECT_STREQ("key_1", actual_property_1.key());
1176
1396
EXPECT_STREQ("1", actual_property_1.value());
1178
TestProperty actual_property_2 = properties.Last()->element();
1398
const TestProperty& actual_property_2 = test_result.GetTestProperty(1);
1179
1399
EXPECT_STREQ("key_2", actual_property_2.key());
1180
1400
EXPECT_STREQ("2", actual_property_2.value());
1183
// Tests TestResult::test_properties() overrides values for duplicate keys.
1403
// Tests TestResult::RecordProperty() overrides values for duplicate keys.
1184
1404
TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
1185
1405
TestResult test_result;
1186
1406
TestProperty property_1_1("key_1", "1");
1187
1407
TestProperty property_2_1("key_2", "2");
1188
1408
TestProperty property_1_2("key_1", "12");
1189
1409
TestProperty property_2_2("key_2", "22");
1190
test_result.RecordProperty(property_1_1);
1191
test_result.RecordProperty(property_2_1);
1192
test_result.RecordProperty(property_1_2);
1193
test_result.RecordProperty(property_2_2);
1410
TestResultAccessor::RecordProperty(&test_result, property_1_1);
1411
TestResultAccessor::RecordProperty(&test_result, property_2_1);
1412
TestResultAccessor::RecordProperty(&test_result, property_1_2);
1413
TestResultAccessor::RecordProperty(&test_result, property_2_2);
1195
const List<TestProperty>& properties = test_result.test_properties();
1196
ASSERT_EQ(2u, properties.size());
1197
TestProperty actual_property_1 = properties.Head()->element();
1415
ASSERT_EQ(2, test_result.test_property_count());
1416
const TestProperty& actual_property_1 = test_result.GetTestProperty(0);
1198
1417
EXPECT_STREQ("key_1", actual_property_1.key());
1199
1418
EXPECT_STREQ("12", actual_property_1.value());
1201
TestProperty actual_property_2 = properties.Last()->element();
1420
const TestProperty& actual_property_2 = test_result.GetTestProperty(1);
1202
1421
EXPECT_STREQ("key_2", actual_property_2.key());
1203
1422
EXPECT_STREQ("22", actual_property_2.value());
1425
// Tests TestResult::GetTestProperty().
1426
TEST(TestResultPropertyDeathTest, GetTestProperty) {
1427
TestResult test_result;
1428
TestProperty property_1("key_1", "1");
1429
TestProperty property_2("key_2", "2");
1430
TestProperty property_3("key_3", "3");
1431
TestResultAccessor::RecordProperty(&test_result, property_1);
1432
TestResultAccessor::RecordProperty(&test_result, property_2);
1433
TestResultAccessor::RecordProperty(&test_result, property_3);
1435
const TestProperty& fetched_property_1 = test_result.GetTestProperty(0);
1436
const TestProperty& fetched_property_2 = test_result.GetTestProperty(1);
1437
const TestProperty& fetched_property_3 = test_result.GetTestProperty(2);
1439
EXPECT_STREQ("key_1", fetched_property_1.key());
1440
EXPECT_STREQ("1", fetched_property_1.value());
1442
EXPECT_STREQ("key_2", fetched_property_2.key());
1443
EXPECT_STREQ("2", fetched_property_2.value());
1445
EXPECT_STREQ("key_3", fetched_property_3.key());
1446
EXPECT_STREQ("3", fetched_property_3.value());
1448
EXPECT_DEATH_IF_SUPPORTED(
1449
test_result.GetTestProperty(3),
1450
"Invalid Vector index 3: must be in range \\[0, 2\\]\\.");
1451
EXPECT_DEATH_IF_SUPPORTED(
1452
test_result.GetTestProperty(-1),
1453
"Invalid Vector index -1: must be in range \\[0, 2\\]\\.");
1206
1456
// When a property using a reserved key is supplied to this function, it tests
1207
1457
// that a non-fatal failure is added, a fatal failure is not added, and that the
1208
1458
// property is not recorded.
1209
1459
void ExpectNonFatalFailureRecordingPropertyWithReservedKey(const char* key) {
1210
1460
TestResult test_result;
1211
1461
TestProperty property(key, "1");
1212
EXPECT_NONFATAL_FAILURE(test_result.RecordProperty(property), "Reserved key");
1213
ASSERT_TRUE(test_result.test_properties().IsEmpty()) << "Not recorded";
1462
EXPECT_NONFATAL_FAILURE(
1463
TestResultAccessor::RecordProperty(&test_result, property),
1465
ASSERT_EQ(0, test_result.test_property_count()) << "Not recorded";
1216
1468
// Attempting to recording a property with the Reserved literal "name"