2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "utc-image-loading-common.h"
20 void utc_image_loading_cancel_all_loads_startup(void)
22 utc_dali_loading_startup();
25 void utc_image_loading_cancel_all_loads_cleanup(void)
27 utc_dali_loading_cleanup();
31 * @brief Test case for load cancellation.
33 * Load lots of images in batches, cancelling all in a batch after a small delay to
34 * allow the first of a batch to be launched before cancellation starts.
35 * Assert that all loads issued are either completed or cancelled.
37 * @note Many loads will succeed despite our cancellations due to the coarse
38 * granularity of the waits we introduce after loading each batch. That is
41 int UtcDaliCancelAllLoads(void)
43 tet_printf( "Running load cancel-all test.\n" );
45 DALI_ASSERT_ALWAYS( gAbstraction != 0 );
47 // Start a bunch of loads that should work:
49 Dali::Integration::LoadResourcePriority priority = LoadPriorityNormal;
50 unsigned loadsLaunched = 0;
51 Dali::Internal::Platform::ResourceCollector resourceSink;
53 for( unsigned loadGroup = 0; loadGroup < NUM_CANCELLED_LOAD_GROUPS_TO_ISSUE; ++loadGroup )
55 // Issue load requests for a batch of images:
56 for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
58 const BitmapResourceType bitmapResourceType( gCancelAttributes[ loadsLaunched % gCancelAttributes.size() ] );
59 const ResourceId resourceId = loadGroup * NUM_VALID_IMAGES + validImage + 1;
60 gAbstraction->LoadResource( ResourceRequest( resourceId, bitmapResourceType, VALID_IMAGES[validImage], priority ) );
64 // Poll for at least one completed load so we have a good chance of catching an
65 // in-flight load as we run through the cancellations further below:
66 PollForNotification( resourceSink, *gAbstraction, 100 );
68 // Cancel all the launched loads in the batch from oldest to newest:
69 for( unsigned validImage = 0; validImage < NUM_VALID_IMAGES; ++validImage )
71 const ResourceId resourceId = loadGroup * NUM_VALID_IMAGES + validImage + 1;
72 gAbstraction->CancelLoad( resourceId, ResourceBitmap );
76 // Drain the completed loads:
78 unsigned lastNotifications = -1;
79 for( unsigned i = 0; resourceSink.mGrandTotalCompletions < loadsLaunched && resourceSink.mGrandTotalNotifications != lastNotifications; )
81 lastNotifications = resourceSink.mGrandTotalNotifications;
82 gAbstraction->GetResources( resourceSink );
85 if( i < MAX_NUM_RESOURCE_TRIES && resourceSink.mGrandTotalCompletions < loadsLaunched )
95 // Check the loads completed as expected:
97 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()) );
98 DALI_TEST_CHECK( loadsLaunched > resourceSink.mGrandTotalCompletions );
99 DALI_TEST_CHECK( loadsLaunched > resourceSink.mSuccessCounts.size() );
100 DALI_TEST_CHECK( 0 == resourceSink.mFailureCounts.size() );
102 // Check that each success was reported exactly once:
103 for( ResourceCounterMap::const_iterator it = resourceSink.mSuccessCounts.begin(), end = resourceSink.mSuccessCounts.end(); it != end; ++it )
105 DALI_TEST_CHECK( it->second == 1u );