Dali 3D User Interface Engine
utc-image-loading-cancel-all-loads.cpp
Go to the documentation of this file.
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 
19 
21 {
23 }
24 
26 {
28 }
29 
42 {
43  tet_printf( "Running load cancel-all test.\n" );
44 
46 
47  // Start a bunch of loads that should work:
48 
50  unsigned loadsLaunched = 0;
52 
53  for( unsigned loadGroup = 0; loadGroup < NUM_CANCELLED_LOAD_GROUPS_TO_ISSUE; ++loadGroup )
54  {
55  // Issue load requests for a batch of images:
56  for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
57  {
58  const ImageParameters & loadParams = gCancelAttributes[ loadsLaunched % gCancelAttributes.size() ];
59  const BitmapResourceType bitmapResourceType( loadParams.first, loadParams.second.first, loadParams.second.second.first, loadParams.second.second.second );
60  const ResourceId resourceId = loadGroup * NUM_VALID_IMAGES + validImage + 1;
61  gAbstraction->LoadResource( ResourceRequest( resourceId, bitmapResourceType, VALID_IMAGES[validImage], priority ) );
62  loadsLaunched += 1;
63  }
64 
65  // Poll for at least one completed load so we have a good chance of catching an
66  // in-flight load as we run through the cancellations further below:
67  PollForNotification( resourceSink, *gAbstraction, 100 );
68 
69  // Cancel all the launched loads in the batch from oldest to newest:
70  for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
71  {
72  const ResourceId resourceId = loadGroup * NUM_VALID_IMAGES + validImage + 1;
73  gAbstraction->CancelLoad( resourceId, ResourceBitmap );
74  }
75  }
76 
77  // Drain the completed loads:
78 
79  unsigned lastNotifications = -1;
80  for( unsigned i = 0; resourceSink.mGrandTotalCompletions < loadsLaunched && resourceSink.mGrandTotalNotifications != lastNotifications; )
81  {
82  lastNotifications = resourceSink.mGrandTotalNotifications;
83  gAbstraction->GetResources( resourceSink );
84 
85  ++i;
86  if( i < MAX_NUM_RESOURCE_TRIES && resourceSink.mGrandTotalCompletions < loadsLaunched )
87  {
88  usleep( 1000 * 10 );
89  }
90  else
91  {
92  break;
93  }
94  }
95 
96  // Check the loads completed as expected:
97 
98  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()) );
99  DALI_TEST_CHECK( loadsLaunched > resourceSink.mGrandTotalCompletions );
100  DALI_TEST_CHECK( loadsLaunched > resourceSink.mSuccessCounts.size() );
101  DALI_TEST_CHECK( 0 == resourceSink.mFailureCounts.size() );
102 
103  // Check that each success was reported exactly once:
104  for( ResourceCounterMap::const_iterator it = resourceSink.mSuccessCounts.begin(), end = resourceSink.mSuccessCounts.end(); it != end; ++it )
105  {
106  DALI_TEST_CHECK( it->second == 1u );
107  }
108 
109  END_TEST;
110 }
Dali Docs Home
Read more about Dali