Merge "Further relax line verification in primitive bbox tests" into nougat-cts-dev...
[platform/upstream/VK-GL-CTS.git] / framework / platform / android / tcuAndroidAssets.cpp
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Tester Core
3  * ----------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Resource wrapper for AAssetManager.
22  *//*--------------------------------------------------------------------*/
23
24 #include "tcuAndroidAssets.hpp"
25
26 namespace tcu
27 {
28 namespace Android
29 {
30
31 AssetArchive::AssetArchive (AAssetManager* assetMgr)
32         : m_assetMgr(assetMgr)
33 {
34 }
35
36 AssetArchive::~AssetArchive (void)
37 {
38 }
39
40 Resource* AssetArchive::getResource (const char* name) const
41 {
42         return new AssetResource(m_assetMgr, name);
43 }
44
45 AssetResource::AssetResource (AAssetManager* assetMgr, const char* name)
46         : Resource      (name)
47         , m_asset       (DE_NULL)
48 {
49         m_asset = AAssetManager_open(assetMgr, name, AASSET_MODE_RANDOM);
50
51         if (!m_asset)
52                 throw ResourceError("Failed to open asset resource", name, __FILE__, __LINE__);
53 }
54
55 AssetResource::~AssetResource (void)
56 {
57         AAsset_close(m_asset);
58 }
59
60 void AssetResource::read (deUint8* dst, int numBytes)
61 {
62         TCU_CHECK(AAsset_read(m_asset, dst, numBytes) == numBytes);
63 }
64
65 int AssetResource::getPosition (void) const
66 {
67         return (int)AAsset_getLength(m_asset) - (int)AAsset_getRemainingLength(m_asset);
68 }
69
70 void AssetResource::setPosition (int position)
71 {
72         TCU_CHECK(AAsset_seek(m_asset, position, SEEK_SET) == position);
73 }
74
75 bool AssetResource::isFinished (void) const
76 {
77         return AAsset_getRemainingLength(m_asset) <= 0;
78 }
79
80 int AssetResource::getSize (void) const
81 {
82         return (int)AAsset_getLength(m_asset);
83 }
84
85 } // Android
86 } // tcu