/* * HandlerAndPolicyTest.cpp * * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0/ * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ #include #include #include "ADSL/HandlerAndPolicy.h" #include "MockDirectiveHandler.h" using namespace ::testing; namespace alexaClientSDK { namespace adsl { namespace test { using namespace alexaClientSDK::avsCommon; /** * HandlerAndPolicyTest */ class HandlerAndPolicyTest : public ::testing::Test { }; /** * Invoke default constructor. Expect @c nameSpace and @c name properties are both empty strings. */ TEST_F(HandlerAndPolicyTest, testDefaultConstructor) { HandlerAndPolicy handlerAndPolicy; ASSERT_EQ(handlerAndPolicy.handler, nullptr); ASSERT_EQ(handlerAndPolicy.policy, BlockingPolicy::NONE); } /** * Invoke constructor with member values. Expect properties match those provided to the constructor. */ TEST_F(HandlerAndPolicyTest, testConstructorWithValues) { auto handler = MockDirectiveHandler::create(); HandlerAndPolicy handlerAndPolicy(handler, BlockingPolicy::NON_BLOCKING); ASSERT_EQ(handlerAndPolicy.handler, handler); ASSERT_EQ(handlerAndPolicy.policy, BlockingPolicy::NON_BLOCKING); } /** * Create empty and non-empty HandlerAndPolicy instances. Expect that empty instances are interpreted as false and * non-empty values are interpreted as true. */ TEST_F(HandlerAndPolicyTest, testOperatorBool) { auto handler = MockDirectiveHandler::create(); HandlerAndPolicy defaultHandlerAndPolicy; HandlerAndPolicy firstHalfEmpty(nullptr, BlockingPolicy::BLOCKING); HandlerAndPolicy secondHalfEmpty(handler, BlockingPolicy::NONE); HandlerAndPolicy nonEmpty(handler, BlockingPolicy::BLOCKING); ASSERT_FALSE(defaultHandlerAndPolicy); ASSERT_FALSE(firstHalfEmpty); ASSERT_FALSE(secondHalfEmpty); ASSERT_TRUE(nonEmpty); } /** * Create instances with different and identical values. Expect that instances with different values test as * not equal and that instances with identical values test as equal. */ TEST_F(HandlerAndPolicyTest, testOperatorEqualandNotEqual) { auto handler1 = MockDirectiveHandler::create(); auto handler2 = MockDirectiveHandler::create(); HandlerAndPolicy defaultHandlerAndPolicy; HandlerAndPolicy handlerAndPolicy1(handler1, BlockingPolicy::NON_BLOCKING); HandlerAndPolicy handlerAndPolicy1Clone(handler1, BlockingPolicy::NON_BLOCKING); HandlerAndPolicy handlerAndPolicy2(handler1, BlockingPolicy::BLOCKING); HandlerAndPolicy handlerAndPolicy3(handler2, BlockingPolicy::NON_BLOCKING); HandlerAndPolicy handlerAndPolicy4(nullptr, BlockingPolicy::NON_BLOCKING); ASSERT_EQ(defaultHandlerAndPolicy, defaultHandlerAndPolicy); ASSERT_NE(defaultHandlerAndPolicy, handlerAndPolicy1); ASSERT_EQ(handlerAndPolicy1, handlerAndPolicy1Clone); ASSERT_NE(handlerAndPolicy1, handlerAndPolicy2); ASSERT_NE(handlerAndPolicy1, handlerAndPolicy3); ASSERT_NE(handlerAndPolicy2, handlerAndPolicy3); ASSERT_NE(handlerAndPolicy3, handlerAndPolicy4); } } // namespace test } // namespace adsl } // namespace alexaClientSDK