X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Ftest%2FOptionalTest.cpp;h=b7484dfa978b6488050eab02470ad15982ea9f67;hb=19e3e9fe724a363e342e92a5b08378900d6ab539;hp=bcf08476a768411a52328658378dff0d0f6938f3;hpb=d69f6a7a3523aea7cbe5578cdbaea6e3a9920d8c;p=folly.git diff --git a/folly/test/OptionalTest.cpp b/folly/test/OptionalTest.cpp index bcf08476..b7484dfa 100644 --- a/folly/test/OptionalTest.cpp +++ b/folly/test/OptionalTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,16 @@ */ #include +#include -#include -#include #include #include +#include #include #include +#include +#include -#include -#include #include using std::unique_ptr; @@ -173,26 +173,12 @@ struct ExpectingDeleter { } }; -TEST(Optional, value_life_extention) { - // Extends the life of the value. - const auto& ptr = Optional>( - {new int(42), ExpectingDeleter{1337}}).value(); - *ptr = 1337; -} - TEST(Optional, value_move) { auto ptr = Optional>( {new int(42), ExpectingDeleter{1337}}).value(); *ptr = 1337; } -TEST(Optional, dereference_life_extention) { - // Extends the life of the value. - const auto& ptr = *Optional>( - {new int(42), ExpectingDeleter{1337}}); - *ptr = 1337; -} - TEST(Optional, dereference_move) { auto ptr = *Optional>( {new int(42), ExpectingDeleter{1337}}); @@ -473,7 +459,7 @@ TEST(Optional, MakeOptional) { EXPECT_EQ(**optIntPtr, 3); } -#if __CLANG_PREREQ(3, 6) +#if __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wself-move" #endif @@ -488,7 +474,7 @@ TEST(Optional, SelfAssignment) { ASSERT_TRUE(b.hasValue() && b.value() == 23333333); } -#if __CLANG_PREREQ(3, 6) +#if __clang__ # pragma clang diagnostic pop #endif @@ -545,4 +531,25 @@ TEST(Optional, NoThrowDefaultConstructible) { EXPECT_TRUE(std::is_nothrow_default_constructible>::value); } +struct NoDestructor {}; + +struct WithDestructor { + ~WithDestructor(); +}; + +TEST(Optional, TriviallyDestructible) { + // These could all be static_asserts but EXPECT_* give much nicer output on + // failure. + EXPECT_TRUE(std::is_trivially_destructible>::value); + EXPECT_TRUE(std::is_trivially_destructible>::value); + EXPECT_FALSE(std::is_trivially_destructible>::value); +} + +TEST(Optional, Hash) { + // Test it's usable in std::unordered map (compile time check) + std::unordered_map, Optional> obj; + // Also check the std::hash template can be instantiated by the compiler + std::hash>()(none); + std::hash>()(3); +} }