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);
Share:
16,010

Related videos on Youtube

Author by

David Hovsepyan

Updated on June 08, 2022

Comments

  • 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 str is equal either to s1 or s2.

    If gtest's ASSERT_* and EXPECT_* would return bool I could have written

    EXPECT_TRUE(EXPECT_EQ(str, s1) || EXPECT_EQ(str, s2));
    

    but, unfortunately, they don't.

    • Easton Bornemeier
      Easton Bornemeier over 4 years
      EXPECT_TRUE(str==s1 || str==s2) ?
  • hfrmobile
    hfrmobile over 1 year
    I 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.

Related