// Copyright 2018 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <memory> #include <utility> #include <vector> #include "dawn/common/Ref.h" #include "dawn/common/RefCounted.h" #include "dawn/common/Result.h" #include "gtest/gtest.h" namespace dawn { namespace { template <typename T, typename E> void TestError(Result<T, E>* result, E expectedError) { … } template <typename T, typename E> void TestSuccess(Result<T, E>* result, T expectedSuccess) { … } static int placeholderError = …; static float placeholderSuccess = …; static const float placeholderConstSuccess = …; class AClass : public RefCounted { … }; // Tests using the following overload of TestSuccess make // local Ref instances to placeholderSuccessObj. Tests should // ensure any local Ref objects made along the way continue // to point to placeholderSuccessObj. template <typename T, typename E> void TestSuccess(Result<Ref<T>, E>* result, T* expectedSuccess) { … } // Result<void, E*> // Test constructing an error Result<void, E> TEST(ResultOnlyPointerError, ConstructingError) { … } // Test moving an error Result<void, E> TEST(ResultOnlyPointerError, MovingError) { … } // Test returning an error Result<void, E> TEST(ResultOnlyPointerError, ReturningError) { … } // Test constructing a success Result<void, E> TEST(ResultOnlyPointerError, ConstructingSuccess) { … } // Test moving a success Result<void, E> TEST(ResultOnlyPointerError, MovingSuccess) { … } // Test returning a success Result<void, E> TEST(ResultOnlyPointerError, ReturningSuccess) { … } // Result<T*, E*> // Test constructing an error Result<T*, E> TEST(ResultBothPointer, ConstructingError) { … } // Test moving an error Result<T*, E> TEST(ResultBothPointer, MovingError) { … } // Test returning an error Result<T*, E> TEST(ResultBothPointer, ReturningError) { … } // Test constructing a success Result<T*, E> TEST(ResultBothPointer, ConstructingSuccess) { … } // Test moving a success Result<T*, E> TEST(ResultBothPointer, MovingSuccess) { … } // Test returning a success Result<T*, E> TEST(ResultBothPointer, ReturningSuccess) { … } // Tests converting from a Result<TChild*, E> TEST(ResultBothPointer, ConversionFromChildClass) { … } // Result<const T*, E> // Test constructing an error Result<const T*, E> TEST(ResultBothPointerWithConstResult, ConstructingError) { … } // Test moving an error Result<const T*, E> TEST(ResultBothPointerWithConstResult, MovingError) { … } // Test returning an error Result<const T*, E*> TEST(ResultBothPointerWithConstResult, ReturningError) { … } // Test constructing a success Result<const T*, E*> TEST(ResultBothPointerWithConstResult, ConstructingSuccess) { … } // Test moving a success Result<const T*, E*> TEST(ResultBothPointerWithConstResult, MovingSuccess) { … } // Test returning a success Result<const T*, E*> TEST(ResultBothPointerWithConstResult, ReturningSuccess) { … } // Result<Ref<T>, E> // Test constructing an error Result<Ref<T>, E> TEST(ResultRefT, ConstructingError) { … } // Test moving an error Result<Ref<T>, E> TEST(ResultRefT, MovingError) { … } // Test returning an error Result<Ref<T>, E> TEST(ResultRefT, ReturningError) { … } // Test constructing a success Result<Ref<T>, E> TEST(ResultRefT, ConstructingSuccess) { … } // Test moving a success Result<Ref<T>, E> TEST(ResultRefT, MovingSuccess) { … } // Test returning a success Result<Ref<T>, E> TEST(ResultRefT, ReturningSuccess) { … } class OtherClass { … }; class Base : public RefCounted { … }; class Child : public OtherClass, public Base { … }; // Test constructing a Result<Ref<TChild>, E> TEST(ResultRefT, ConversionFromChildConstructor) { … } // Test copy constructing Result<Ref<TChild>, E> TEST(ResultRefT, ConversionFromChildCopyConstructor) { … } // Test assignment operator for Result<Ref<TChild>, E> TEST(ResultRefT, ConversionFromChildAssignmentOperator) { … } // Result<T, E> // Test constructing an error Result<T, E> TEST(ResultGeneric, ConstructingError) { … } // Test moving an error Result<T, E> TEST(ResultGeneric, MovingError) { … } // Test returning an error Result<T, E> TEST(ResultGeneric, ReturningError) { … } // Test constructing a success Result<T, E> TEST(ResultGeneric, ConstructingSuccess) { … } // Test moving a success Result<T, E> TEST(ResultGeneric, MovingSuccess) { … } // Test returning a success Result<T, E> TEST(ResultGeneric, ReturningSuccess) { … } class NonDefaultConstructible { … }; // Test constructing an error Result<T, E> for non-default-constructible T TEST(ResultNonDefaultConstructible, ConstructingError) { … } // Test moving an error Result<T, E> for non-default-constructible T TEST(ResultNonDefaultConstructible, MovingError) { … } // Test returning an error Result<T, E> for non-default-constructible T TEST(ResultNonDefaultConstructible, ReturningError) { … } // Test constructing a success Result<T, E> for non-default-constructible T TEST(ResultNonDefaultConstructible, ConstructingSuccess) { … } // Test moving a success Result<T, E> for non-default-constructible T TEST(ResultNonDefaultConstructible, MovingSuccess) { … } // Test returning a success Result<T, E> for non-default-constructible T TEST(ResultNonDefaultConstructible, ReturningSuccess) { … } } // anonymous namespace } // namespace dawn