Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-platform-abstraction / utc-image-loading-load-completion.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "utc-image-loading-common.h"
19
20 void utc_image_loading_load_completion_startup(void)
21 {
22   utc_dali_loading_startup();
23 }
24
25 void utc_image_loading_load_completion_cleanup(void)
26 {
27   utc_dali_loading_cleanup();
28 }
29
30 // Positive test case for loading. Load lots and be sure it has succeeded.
31 int UtcDaliLoadCompletion(void)
32 {
33   tet_printf("Running load completion test \n");
34
35   DALI_ASSERT_ALWAYS( gAbstraction != 0 );
36
37   // Start a bunch of loads that should work:
38
39   Dali::Integration::BitmapResourceType bitmapResourceType;
40   Dali::Integration::LoadResourcePriority priority = Dali::Integration::LoadPriorityNormal;
41   unsigned loadsLaunched = 0;
42
43   for( unsigned loadGroup = 0; loadGroup < NUM_LOAD_GROUPS_TO_ISSUE; ++loadGroup )
44   {
45     for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
46     {
47       Dali::Integration::ResourceRequest request( loadGroup * NUM_VALID_IMAGES + validImage + 1, bitmapResourceType, VALID_IMAGES[validImage], priority );
48       gAbstraction->LoadResource( request );
49     }
50     loadsLaunched += NUM_VALID_IMAGES;
51   }
52
53   // Drain the completed loads:
54   Dali::Internal::Platform::ResourceCollector resourceSink;
55   gAbstraction->GetResources( resourceSink );
56   usleep( 500 * 1000 );
57   gAbstraction->GetResources( resourceSink );
58
59   const double startDrainTime = GetTimeMilliseconds( *gAbstraction );
60   while( resourceSink.mGrandTotalCompletions < loadsLaunched && GetTimeMilliseconds( *gAbstraction ) - startDrainTime < MAX_MILLIS_TO_WAIT_FOR_KNOWN_LOADS )
61   {
62     usleep( 100 * 40 );
63     gAbstraction->GetResources( resourceSink );
64   }
65
66   // Check the loads completed as expected:
67
68   tet_printf( "Issued Loads: %u, Completed Loads: %u, Successful Loads: %u, Failed Loads: %u \n", loadsLaunched, resourceSink.mGrandTotalCompletions, unsigned(resourceSink.mSuccessCounts.size()), unsigned(resourceSink.mFailureCounts.size()) );
69   DALI_TEST_CHECK( loadsLaunched == resourceSink.mGrandTotalCompletions );
70   DALI_TEST_CHECK( loadsLaunched == resourceSink.mSuccessCounts.size() );
71   DALI_TEST_CHECK( 0 == resourceSink.mFailureCounts.size() );
72
73   // Check that each success was reported exactly once:
74   for( ResourceCounterMap::const_iterator it = resourceSink.mSuccessCounts.begin(), end = resourceSink.mSuccessCounts.end(); it != end; ++it )
75   {
76     DALI_TEST_CHECK( it->second == 1u );
77   }
78
79   END_TEST;
80 }