| 1353 | |
| 1354 | template <class StringType> |
| 1355 | void TestGetMapItemWithDef() { |
| 1356 | struct TestCase { |
| 1357 | std::string name; |
| 1358 | |
| 1359 | std::map<StringType, StringType> m; |
| 1360 | StringType key; |
| 1361 | StringType defval; |
| 1362 | |
| 1363 | StringType want_result; |
| 1364 | }; |
| 1365 | std::vector<TestCase> test_cases; |
| 1366 | |
| 1367 | test_cases.emplace_back( |
| 1368 | TestCase{ |
| 1369 | .name = "case 1", |
| 1370 | .m = {{"k1", "v1"}, {"k2", "v2"}}, |
| 1371 | .key = "k1", |
| 1372 | .defval = "", |
| 1373 | .want_result = "v1"}); |
| 1374 | test_cases.emplace_back( |
| 1375 | TestCase{ |
| 1376 | .name = "case 2", |
| 1377 | .m = {{"k1", "v1"}, {"k2", "v2"}}, |
| 1378 | .key = "k3", |
| 1379 | .defval = "", |
| 1380 | .want_result = ""}); |
| 1381 | test_cases.emplace_back( |
| 1382 | TestCase{ |
| 1383 | .name = "case 3", |
| 1384 | .m = {{"k1", "v1"}, {"k2", "v2"}}, |
| 1385 | .key = "", |
| 1386 | .defval = "abc", |
| 1387 | .want_result = "abc"}); |
| 1388 | |
| 1389 | for (size_t ii = 0; ii < test_cases.size(); ++ii) { |
| 1390 | TestCase& cur_test_case = test_cases[ii]; |
| 1391 | auto ret = GetMapItemWithDef(cur_test_case.m, cur_test_case.key, |
| 1392 | cur_test_case.defval); |
| 1393 | EXPECT_EQ(ret, cur_test_case.want_result) |
| 1394 | << "Test " << cur_test_case.name << " failed, index " << ii; |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | TEST(STRING_UTIL_TEST, GetMapItemWithDef_test) { |
| 1399 | TestGetMapItemWithDef<std::string>(); |
nothing calls this directly
no outgoing calls
no test coverage detected