Merge "Adding Uniform stack trace" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-platform-abstraction.h
1 #ifndef __DALI_TEST_PLATFORM_ABSTRACTION_H__
2 #define __DALI_TEST_PLATFORM_ABSTRACTION_H__
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <stdint.h>
23 #include <cstring>
24 #include <string>
25 #include <vector>
26
27 // INTERNAL INCLUDES
28 #include <dali/integration-api/platform-abstraction.h>
29
30 #include "test-trace-call-stack.h"
31
32 namespace Dali
33 {
34
35 /**
36  * Concrete implementation of the platform abstraction class.
37  */
38 class DALI_IMPORT_API TestPlatformAbstraction : public Dali::Integration::PlatformAbstraction
39 {
40
41 public:
42
43   /**
44    * Constructor
45    */
46   TestPlatformAbstraction();
47
48   /**
49    * Destructor
50    */
51   virtual ~TestPlatformAbstraction();
52
53   /**
54    * @copydoc PlatformAbstraction::GetClosestImageSize()
55    */
56   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
57                                                  ImageDimensions size,
58                                                  FittingMode::Type fittingMode,
59                                                  SamplingMode::Type samplingMode,
60                                                  bool orientationCorrection );
61
62   /**
63    * @copydoc PlatformAbstraction::GetClosestImageSize()
64    */
65   virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
66                                                ImageDimensions size,
67                                                FittingMode::Type fittingMode,
68                                                SamplingMode::Type samplingMode,
69                                                bool orientationCorrection );
70
71   /**
72    * @copydoc PlatformAbstraction::LoadResourceSynchronously()
73    */
74   virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
75
76   /**
77    * @copydoc PlatformAbstraction::DecodeBuffer()
78    */
79   virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::ResourceType& resourceType, uint8_t * buffer, size_t size );
80
81   /**
82    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
83    */
84   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
85
86   /**
87    * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
88    */
89   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
90
91
92 public: // TEST FUNCTIONS
93
94   // Enumeration of Platform Abstraction methods
95   typedef enum
96   {
97     LoadResourceSynchronouslyFunc,
98     LoadShaderBinaryFileFunc,
99     SaveShaderBinaryFileFunc
100   } TestFuncEnum;
101
102   /** Call this every test */
103   void Initialize();
104
105   inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
106   inline void ResetTrace() { mTrace.Reset(); }
107   inline TraceCallStack& GetTrace() { return mTrace; }
108
109   /**
110    * @brief Checks if a platform function was called
111    * @param[in] func The function to check
112    * @return true if the function was called
113    */
114   bool WasCalled(TestFuncEnum func);
115
116   /**
117    * @brief Sets the result to return when IsLoading is called by Core.
118    * @param[in] result The result to set.
119    */
120   void SetIsLoadingResult(bool result);
121
122   /**
123    * @brief Clears all resource queues
124    */
125   void ClearReadyResources();
126
127   /**
128    * @brief Sets the value returned by GetClosestImageSize.
129    * @param[in] size The size that should be returned.
130    */
131   void SetClosestImageSize(const Vector2& size);
132
133   /**
134    * @brief Sets the result return by LoadFile.
135    * @param[in] result The value that LoadFile should return.
136    * @param[in] buffer The buffer of the loaded file.
137    */
138   void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
139
140   /**
141    * @brief Sets the SaveFile result
142    * @param[in] result The value that SaveFile should return
143    */
144   void SetSaveFileResult( bool result );
145
146   /**
147    * @brief Sets the resource loaded by LoadResourceSynchronously
148    * @param[in] resource The loaded resource
149    */
150   void SetSynchronouslyLoadedResource( Integration::ResourcePointer resource );
151
152   /**
153    * @brief Sets the bitmap returned by DecodeBuffer()
154    * @param[in] bitmap The decoded bitmap
155    */
156   void SetDecodedBitmap( Integration::BitmapPtr bitmap );
157
158 private:
159
160   TestPlatformAbstraction( const TestPlatformAbstraction& ); ///< Undefined
161   TestPlatformAbstraction& operator=( const TestPlatformAbstraction& ); ///< Undefined
162
163 private:
164
165   struct LoadFileResult
166   {
167     inline LoadFileResult()
168     : loadResult(false)
169     {
170
171     }
172
173     bool loadResult;
174     Dali::Vector< unsigned char> buffer;
175   };
176
177   mutable TraceCallStack        mTrace;
178   bool                          mIsLoadingResult;
179   Vector2                       mSize;
180   Vector2                       mClosestSize;
181
182   LoadFileResult                mLoadFileResult;
183   bool                          mSaveFileResult;
184
185   Integration::ResourcePointer  mSynchronouslyLoadedResource;
186   Integration::BitmapPtr        mDecodedBitmap;
187 };
188
189 } // Dali
190
191 #endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */