Adding ObjectDestructionTracker to dali-test-suite-utils for testing object destruction
[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
27 namespace Integration
28 {
29 class PlatformAbstraction;
30 }
31
32 namespace Internal
33 {
34 namespace Platform
35 {
36   /** Stores true for success and false for a failure for each completed
37    *  resource id.*/
38   typedef std::map<Integration::ResourceId, bool> ResourceStatusMap;
39   /** Stores an integer counter for a resource ID, e.g., to count the number of
40    *  times a load or a fail is reported.*/
41   typedef std::map<Integration::ResourceId, unsigned> ResourceCounterMap;
42   /** Used to track the order in which a sequence of requests is completed.*/
43   typedef std::vector<Integration::ResourceId> ResourceSequence;
44
45 /**
46  * @brief Used for platform testing to record the result of resource requests
47  * initiated by tests.
48  */
49 class ResourceCollector : public Integration::ResourceCache
50 {
51 public:
52
53   ResourceCollector();
54   virtual ~ResourceCollector();
55
56   virtual void LoadResponse(Dali::Integration::ResourceId id, Dali::Integration::ResourceTypeId type, Dali::Integration::ResourcePointer resource, Dali::Integration::LoadStatus status);
57
58   virtual void LoadFailed(Dali::Integration::ResourceId id, Dali::Integration::ResourceFailure failure);
59
60   // Data:
61   /** Record of the status of each completed resource. */
62   ResourceStatusMap mCompletionStatuses;
63   /** Record of how many times each resource completed (every value should be 1,
64    *  else we are broken). */
65   ResourceCounterMap mCompletionCounts;
66   /** Record of how many times each resource succeeded (every value should be 0 or
67    *  1, else we are broken). */
68   ResourceCounterMap mSuccessCounts;
69   /** Record of how many times each resource failed (every value should be 0 or 1,
70    * else we are broken).
71    * Only resource IDs that correspond to deliberately unloadable resources
72    * should have counts other than 0. */
73   ResourceCounterMap mFailureCounts;
74   /** Remember the order of request completions so request priority can be tested. */
75   ResourceSequence mCompletionSequence;
76   /** Count of all successes and failures.*/
77   unsigned mGrandTotalCompletions;
78   /** Count of all successes, failures, loading notifications and partially loaded notifications.*/
79   unsigned mGrandTotalNotifications;
80
81 };
82
83 /**
84  * Helper to poll the abstraction for notifications assuming loads have been
85  * issued to it previously and are in-flight.
86  */
87 void PollForNotification( ResourceCollector& collector, Integration::PlatformAbstraction&  abstraction, const unsigned maxPolls = 100 );
88
89 } /* namespace Platform */
90 } /* namespace Internal */
91 } /* namespace Dali */
92
93 #endif /* __DALI_ADAPTOR_TCT_RESOURCE_COLLECTOR_H_ */