gtest: check if string is equal to one of two strings
16,010
Try it:
std::string s1 = "ab";
std::string s2 = "cd";
std::string str = "ab";
EXPECT_TRUE(s1 == str || s2 == str);
Related videos on Youtube
Author by
David Hovsepyan
Updated on June 08, 2022Comments
-
David Hovsepyan 5 months
Consider that I have two strings:
std::string s1 = "ab"; std::string s2 = "cd";and I want to check (e.g. using EXPECT_EQ) if some given
std::string stris equal either tos1ors2.If gtest's
ASSERT_*andEXPECT_*would returnboolI could have writtenEXPECT_TRUE(EXPECT_EQ(str, s1) || EXPECT_EQ(str, s2));but, unfortunately, they don't.
-
Easton Bornemeier over 4 yearsEXPECT_TRUE(str==s1 || str==s2)?
-
-
hfrmobile over 1 yearI am in the situation that I have used as described and now I don't know why test is failing on server build but locally the tests succeeds. See bellow for a better solution.