8553e62e09039bc7a389f9b913c636d502e43150
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-platform-abstraction / resource-collector.h
1 #ifndef __DALI_ADAPTOR_TCT_RESOURCE_COLLECTOR_H_
2 #define __DALI_ADAPTOR_TCT_RESOURCE_COLLECTOR_H_
3 /*
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19 #include <dali/dali.h>
20 #include <dali/integration-api/resource-cache.h>
21
22 #include <map>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 namespace Platform
29 {
30   /** Stores true for success and false for a failure for each completed
31    *  resource id.*/
32   typedef std::map<Integration::ResourceId, bool> ResourceStatusMap;
33   /** Stores an integer counter for a resource ID, e.g., to count the number of
34    *  times a load or a fail is reported.*/
35   typedef std::map<Integration::ResourceId, unsigned> ResourceCounterMap;
36   /** Used to track the order in which a sequence of requests is completed.*/
37   typedef std::vector<Integration::ResourceId> ResourceSequence;
38
39 /**
40  * @brief Used for platform testing to record the result of resource requests
41  * initiated by tests.
42  */
43 class ResourceCollector : public Integration::ResourceCache
44 {
45 public:
46
47   ResourceCollector();
48   virtual ~ResourceCollector();
49
50   virtual void LoadResponse(Dali::Integration::ResourceId id, Dali::Integration::ResourceTypeId type, Dali::Integration::ResourcePointer resource, Dali::Integration::LoadStatus status);
51
52   virtual void SaveComplete(Dali::Integration::ResourceId id, Dali::Integration::ResourceTypeId type) {}
53
54   virtual void LoadFailed(Dali::Integration::ResourceId id, Dali::Integration::ResourceFailure failure);
55
56   virtual void SaveFailed(Dali::Integration::ResourceId id, Dali::Integration::ResourceFailure failure) {}
57
58   // Data:
59   /** Record of the status of each completed resource. */
60   ResourceStatusMap mCompletionStatuses;
61   /** Record of how many times each resource completed (every value should be 1,
62    *  else we are broken). */
63   ResourceCounterMap mCompletionCounts;
64   /** Record of how many times each resource succeeded (every value should be 0 or
65    *  1, else we are broken). */
66   ResourceCounterMap mSuccessCounts;
67   /** Record of how many times each resource failed (every value should be 0 or 1,
68    * else we are broken).
69    * Only resource IDs that correspond to deliberately unloadable resources
70    * should have counts other than 0. */
71   ResourceCounterMap mFailureCounts;
72   /** Remember the order of request completions so request priority can be tested. */
73   ResourceSequence mCompletionSequence;
74   /** Count of all successes and failures.*/
75   unsigned mGrandTotalCompletions;
76
77 };
78
79 } /* namespace Platform */
80 } /* namespace Internal */
81 } /* namespace Dali */
82
83 #endif /* __DALI_ADAPTOR_TCT_RESOURCE_COLLECTOR_H_ */