Cleanup ResourceLoading and PlatformAbstraction
[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 #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_IMPORT_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 public: // TEST FUNCTIONS
94
95   // Enumeration of Platform Abstraction methods
96   typedef enum
97   {
98     LoadResourceSynchronouslyFunc,
99     LoadShaderBinaryFileFunc,
100     SaveShaderBinaryFileFunc
101   } TestFuncEnum;
102
103   /** Call this every test */
104   void Initialize();
105
106   inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
107   inline void ResetTrace() { mTrace.Reset(); }
108   inline TraceCallStack& GetTrace() { return mTrace; }
109
110   /**
111    * @brief Checks if a platform function was called
112    * @param[in] func The function to check
113    * @return true if the function was called
114    */
115   bool WasCalled(TestFuncEnum func);
116
117   /**
118    * @brief Sets the result to return when IsLoading is called by Core.
119    * @param[in] result The result to set.
120    */
121   void SetIsLoadingResult(bool result);
122
123   /**
124    * @brief Clears all resource queues
125    */
126   void ClearReadyResources();
127
128   /**
129    * @brief Sets the value returned by GetClosestImageSize.
130    * @param[in] size The size that should be returned.
131    */
132   void SetClosestImageSize(const Vector2& size);
133
134   /**
135    * @brief Sets the result return by LoadFile.
136    * @param[in] result The value that LoadFile should return.
137    * @param[in] buffer The buffer of the loaded file.
138    */
139   void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
140
141   /**
142    * @brief Sets the SaveFile result
143    * @param[in] result The value that SaveFile should return
144    */
145   void SetSaveFileResult( bool result );
146
147   /**
148    * @brief Sets the resource loaded by LoadResourceSynchronously
149    * @param[in] resource The loaded resource
150    */
151   void SetSynchronouslyLoadedResource( Integration::ResourcePointer resource );
152
153   /**
154    * @brief Sets the bitmap returned by DecodeBuffer()
155    * @param[in] bitmap The decoded bitmap
156    */
157   void SetDecodedBitmap( Integration::BitmapPtr bitmap );
158
159 private:
160
161   TestPlatformAbstraction( const TestPlatformAbstraction& ); ///< Undefined
162   TestPlatformAbstraction& operator=( const TestPlatformAbstraction& ); ///< Undefined
163
164 private:
165
166   struct LoadFileResult
167   {
168     inline LoadFileResult()
169     : loadResult(false)
170     {
171
172     }
173
174     bool loadResult;
175     Dali::Vector< unsigned char> buffer;
176   };
177
178   mutable TraceCallStack        mTrace;
179   bool                          mIsLoadingResult;
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_TEST_PLATFORM_ABSTRACTION_H__ */