X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftest-trace-call-stack.h;h=137bfafefd920a27c50694cb370a9ac3fbc80dee;hp=76d6061f6852981f8e2f3f78f7e7c3016152f4ba;hb=fc3b9f75eedc1e29b78507d170a7dccd13784178;hpb=fa6279fb2830427d5ab569ca14e6ade1557ef2fa diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-trace-call-stack.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-trace-call-stack.h index 76d6061..137bfaf 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-trace-call-stack.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-trace-call-stack.h @@ -1,27 +1,33 @@ -#ifndef __TEST_TRACE_CALL_STACK_H__ -#define __TEST_TRACE_CALL_STACK_H__ - -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License 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. -// +#ifndef TEST_TRACE_CALL_STACK_H +#define TEST_TRACE_CALL_STACK_H + +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License 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 +#include namespace Dali { +std::string ToString(int x); +std::string ToString(unsigned int x); +std::string ToString(float x); /** * Helper class to track method calls in the abstraction and search for them in test cases @@ -29,6 +35,10 @@ namespace Dali class TraceCallStack { public: + + /// Typedef for passing and storing named parameters + typedef std::map< std::string, std::string > NamedParams; + /** * Constructor */ @@ -44,6 +54,8 @@ public: */ void Enable(bool enable); + bool IsEnabled(); + /** * Push a call onto the stack if the trace is active * @param[in] method The name of the method @@ -51,6 +63,13 @@ public: */ void PushCall(std::string method, std::string params); + /** + * Push a call onto the stack if the trace is active + * @param[in] method The name of the method + * @param[in] params A comma separated list of parameter values + * @param[in] altParams A map of named parameter values + */ + void PushCall(std::string method, std::string params, const NamedParams& altParams); /** * Search for a method in the stack @@ -60,6 +79,13 @@ public: bool FindMethod(std::string method) const; /** + * Count how many times a method was called + * @param[in] method The name of the method + * @return The number of times it was called + */ + int CountMethod(std::string method) const; + + /** * Search for a method in the stack with the given parameter list * @param[in] method The name of the method * @param[in] params A comma separated list of parameter values @@ -68,6 +94,30 @@ public: bool FindMethodAndParams(std::string method, std::string params) const; /** + * Search for a method in the stack with the given parameter list + * @param[in] method The name of the method + * @param[in] params A map of named parameters to test for + * @return true if the method was in the stack + */ + bool FindMethodAndParams(std::string method, const NamedParams& params) const; + + /** + * Search for a method in the stack with the given parameter list + * @param[in] method The name of the method + * @param[in] params A comma separated list of parameter values + * @return index in the stack where the method was found or -1 otherwise + */ + int FindIndexFromMethodAndParams(std::string method, std::string params) const; + + /** + * Search for a method in the stack with the given parameter list + * @param[in] method The name of the method + * @param[in] params A map of named parameter values to match + * @return index in the stack where the method was found or -1 otherwise + */ + int FindIndexFromMethodAndParams(std::string method, const NamedParams& params) const; + + /** * Test if the given method and parameters are at a given index in the stack * @param[in] index Index in the call stack * @param[in] method Name of method to test @@ -81,16 +131,43 @@ public: void Reset(); /** - * Get the call stack - * @return The call stack object (Vector of vector[2] of method/paramlist strings) + * Method to display contents of the TraceCallStack. + * @return A string containing a list of function calls and parameters (may contain newline characters) */ - inline const std::vector< std::vector< std::string > >& GetCallStack() { return mCallStack; } + std::string GetTraceString() + { + std::stringstream traceStream; + int functionCount = mCallStack.size(); + for( int i = 0; i < functionCount; ++i ) + { + Dali::TraceCallStack::FunctionCall functionCall = mCallStack[ i ]; + traceStream << "StackTrace: Index:" << i << ", Function:" << functionCall.method << ", ParamList:" << functionCall.paramList << std::endl; + } + + return traceStream.str(); + } private: bool mTraceActive; ///< True if the trace is active - std::vector< std::vector< std::string > > mCallStack; ///< The call stack + + struct FunctionCall + { + std::string method; + std::string paramList; + NamedParams namedParams; + FunctionCall( const std::string& aMethod, const std::string& aParamList ) + : method( aMethod ), paramList( aParamList ) + { + } + FunctionCall( const std::string& aMethod, const std::string& aParamList, const NamedParams& altParams ) + : method( aMethod ), paramList( aParamList ), namedParams( altParams ) + { + } + }; + + std::vector< FunctionCall > mCallStack; ///< The call stack }; } // namespace dali -#endif //__TEST_TRACE_CALL_STACK_H__ +#endif // TEST_TRACE_CALL_STACK_H