Update adaptor stub code in toolkit automated test to include new Adaptor APIs
[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) 2019 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 #include <dali/public-api/math/vector2.h>
30
31 #include "test-trace-call-stack.h"
32
33 namespace Dali
34 {
35
36 /**
37  * Concrete implementation of the platform abstraction class.
38  */
39 class DALI_CORE_API TestPlatformAbstraction : public Dali::Integration::PlatformAbstraction
40 {
41
42 public:
43
44   /**
45    * Constructor
46    */
47   TestPlatformAbstraction();
48
49   /**
50    * Destructor
51    */
52   virtual ~TestPlatformAbstraction();
53
54   /**
55    * @copydoc PlatformAbstraction::GetClosestImageSize()
56    */
57   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
58                                                  ImageDimensions size,
59                                                  FittingMode::Type fittingMode,
60                                                  SamplingMode::Type samplingMode,
61                                                  bool orientationCorrection );
62
63   /**
64    * @copydoc PlatformAbstraction::GetClosestImageSize()
65    */
66   virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
67                                                ImageDimensions size,
68                                                FittingMode::Type fittingMode,
69                                                SamplingMode::Type samplingMode,
70                                                bool orientationCorrection );
71
72   /**
73    * @copydoc PlatformAbstraction::LoadResourceSynchronously()
74    */
75   virtual Integration::ResourcePointer LoadImageSynchronously( const Integration::BitmapResourceType& resourceType, const std::string& resourcePath );
76
77   /**
78    * @copydoc PlatformAbstraction::DecodeBuffer()
79    */
80   virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::BitmapResourceType& resourceType, uint8_t * buffer, size_t size );
81
82   /**
83    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
84    */
85   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
86
87   /**
88    * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
89    */
90   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
91
92   /**
93    * @copydoc PlatformAbstraction::StartTimer()
94    */
95   virtual uint32_t StartTimer( uint32_t milliseconds, CallbackBase* callback );
96
97   /*
98    * @copydoc PlatformAbstraction::CancelTimer()
99    */
100   virtual void CancelTimer ( uint32_t timerId );
101
102 public: // TEST FUNCTIONS
103
104   // Enumeration of Platform Abstraction methods
105   typedef enum
106   {
107     LoadResourceSynchronouslyFunc,
108     LoadShaderBinaryFileFunc,
109     SaveShaderBinaryFileFunc
110   } TestFuncEnum;
111
112   /** Call this every test */
113   void Initialize();
114
115   inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
116   inline void ResetTrace() { mTrace.Reset(); }
117   inline TraceCallStack& GetTrace() { return mTrace; }
118
119   /**
120    * @brief Checks if a platform function was called
121    * @param[in] func The function to check
122    * @return true if the function was called
123    */
124   bool WasCalled(TestFuncEnum func);
125
126   /**
127    * @brief Sets the result to return when IsLoading is called by Core.
128    * @param[in] result The result to set.
129    */
130   void SetIsLoadingResult(bool result);
131
132   /**
133    * @brief Clears all resource queues
134    */
135   void ClearReadyResources();
136
137   /**
138    * @brief Sets the value returned by GetClosestImageSize.
139    * @param[in] size The size that should be returned.
140    */
141   void SetClosestImageSize( const Vector2& size );
142
143   /**
144    * @brief Sets the result return by LoadFile.
145    * @param[in] result The value that LoadFile should return.
146    * @param[in] buffer The buffer of the loaded file.
147    */
148   void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
149
150   /**
151    * @brief Sets the SaveFile result
152    * @param[in] result The value that SaveFile should return
153    */
154   void SetSaveFileResult( bool result );
155
156   /**
157    * @brief Sets the resource loaded by LoadResourceSynchronously
158    * @param[in] resource The loaded resource
159    */
160   void SetSynchronouslyLoadedResource( Integration::ResourcePointer resource );
161
162   /**
163    * @brief Sets the bitmap returned by DecodeBuffer()
164    * @param[in] bitmap The decoded bitmap
165    */
166   void SetDecodedBitmap( Integration::BitmapPtr bitmap );
167
168   /**
169    * @brief Triggers the previously stored callback function
170    */
171   void TriggerTimer();
172
173 private:
174
175   TestPlatformAbstraction( const TestPlatformAbstraction& ); ///< Undefined
176   TestPlatformAbstraction& operator=( const TestPlatformAbstraction& ); ///< Undefined
177
178 private:
179
180   struct LoadFileResult
181   {
182     inline LoadFileResult()
183     : loadResult(false)
184     {
185
186     }
187
188     bool loadResult;
189     Dali::Vector< unsigned char> buffer;
190   };
191
192   mutable TraceCallStack        mTrace;
193   bool                          mIsLoadingResult;
194   ImageDimensions               mClosestSize;
195
196   LoadFileResult                mLoadFileResult;
197   bool                          mSaveFileResult;
198
199   Integration::ResourcePointer  mSynchronouslyLoadedResource;
200   Integration::BitmapPtr        mDecodedBitmap;
201
202   uint32_t                      mTimerId;
203   CallbackBase*                 mCallbackFunction;
204 };
205
206 } // Dali
207
208 #endif /* DALI_TEST_PLATFORM_ABSTRACTION_H */