From: Nicholas Ormrod Date: Wed, 20 Aug 2014 01:23:44 +0000 (-0700) Subject: Fix Optional test for -fb platform X-Git-Tag: v0.22.0~391 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1cab639b34226bb2fe6934e2e271db3131e74f68;p=folly.git Fix Optional test for -fb platform Summary: The Optional test relied on std::string clearing its data when it is the source of a move. This does not happen for in-situ fbstrings, so the test breaks in the -fb platform. The solution: wrap the string in a class that explicitly invalidates its data upon a move. Test Plan: fbconfig --platform-all=gcc-4.8.1-glibc-2.17-fb -r folly fbmake runtests fbconfig -r folly fbmake runtests Reviewed By: tudorb@fb.com Subscribers: sdwilsh FB internal diff: D1506840 Tasks: 4943996 --- diff --git a/folly/test/OptionalTest.cpp b/folly/test/OptionalTest.cpp index efea777f..58a20685 100644 --- a/folly/test/OptionalTest.cpp +++ b/folly/test/OptionalTest.cpp @@ -108,9 +108,28 @@ TEST(Optional, Simple) { EXPECT_FALSE(bool(opt)); } +class MoveTester { +public: + /* implicit */ MoveTester(const char* s) : s_(s) {} + MoveTester(const MoveTester&) = default; + MoveTester(MoveTester&& other) noexcept { + s_ = std::move(other.s_); + other.s_ = ""; + } + MoveTester& operator=(const MoveTester&) = default; + MoveTester& operator=(MoveTester&&) = default; +private: + friend bool operator==(const MoveTester& o1, const MoveTester& o2); + std::string s_; +}; + +bool operator==(const MoveTester& o1, const MoveTester& o2) { + return o1.s_ == o2.s_; +} + TEST(Optional, value_or_rvalue_arg) { - Optional opt; - std::string dflt = "hello"; + Optional opt; + MoveTester dflt = "hello"; EXPECT_EQ("hello", opt.value_or(dflt)); EXPECT_EQ("hello", dflt); EXPECT_EQ("hello", opt.value_or(std::move(dflt)));