AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
MockAndroidSLESObject.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
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  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #ifndef ALEXA_CLIENT_SDK_APPLICATIONUTILITIES_ANDROIDUTILITIES_TEST_ANDROIDUTILITIES_MOCKANDROIDSLESOBJECT_H_
16 #define ALEXA_CLIENT_SDK_APPLICATIONUTILITIES_ANDROIDUTILITIES_TEST_ANDROIDUTILITIES_MOCKANDROIDSLESOBJECT_H_
17 
18 #include <unordered_map>
19 #include <SLES/OpenSLES.h>
20 
22 
23 namespace alexaClientSDK {
24 namespace applicationUtilities {
25 namespace androidUtilities {
26 namespace test {
27 
34 public:
40  void mockRealize(bool succeed = true);
41 
48  void mockGetInterface(SLInterfaceID id, std::shared_ptr<MockInterface> object);
49 
55  SLObjectItf getObject();
56 
61 
66 
67 private:
70  SLObjectItf_** m_slObject;
71 };
72 
73 // Static interface map that will be used to mock getInterface.
74 static std::unordered_map<SLInterfaceID, std::shared_ptr<MockInterface>> g_interfaces;
75 
76 SLresult realizeSucceed(SLObjectItf self, SLboolean async) {
77  return SL_RESULT_SUCCESS;
78 }
79 
80 SLresult realizeFailed(SLObjectItf self, SLboolean async) {
81  return SL_RESULT_INTERNAL_ERROR;
82 }
83 
84 SLresult getMockInterface(SLObjectItf self, SLInterfaceID id, void* interface) {
85  auto it = g_interfaces.find(id);
86  if (it != g_interfaces.end() && it->second != nullptr) {
87  it->second->set(interface);
88  return SL_RESULT_SUCCESS;
89  }
90  return SL_RESULT_CONTENT_NOT_FOUND;
91 }
92 
93 void MockAndroidSLESObject::mockGetInterface(SLInterfaceID id, std::shared_ptr<MockInterface> object) {
94  g_interfaces[id] = object;
95 }
96 
98  (*m_slObject)->Realize = succeed ? realizeSucceed : realizeFailed;
99 }
100 
102  return m_slObject;
103 }
104 
106  auto object = new SLObjectItf_();
107  auto objectPtr = new SLObjectItf_*();
108  *objectPtr = object;
109  m_slObject = objectPtr;
110  (*m_slObject)->Realize = realizeSucceed;
111  (*m_slObject)->GetInterface = getMockInterface;
112  (*m_slObject)->Destroy = [](SLObjectItf obj) {};
113 };
114 
116  delete *m_slObject;
117  delete m_slObject;
118  g_interfaces.clear();
119 }
120 
121 } // namespace test
122 } // namespace androidUtilities
123 } // namespace applicationUtilities
124 } // namespace alexaClientSDK
125 
126 #endif // ALEXA_CLIENT_SDK_APPLICATIONUTILITIES_ANDROIDUTILITIES_TEST_ANDROIDUTILITIES_MOCKANDROIDSLESOBJECT_H_
SLresult realizeFailed(SLObjectItf self, SLboolean async)
Definition: MockAndroidSLESObject.h:80
Definition: AmdMetricWrapperTest.cpp:24
SLresult realizeSucceed(SLObjectItf self, SLboolean async)
Definition: MockAndroidSLESObject.h:76
void mockGetInterface(SLInterfaceID id, std::shared_ptr< MockInterface > object)
Definition: MockAndroidSLESObject.h:93
static std::unordered_map< SLInterfaceID, std::shared_ptr< MockInterface > > g_interfaces
Definition: MockAndroidSLESObject.h:74
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
SLresult getMockInterface(SLObjectItf self, SLInterfaceID id, void *interface)
Definition: MockAndroidSLESObject.h:84
void mockRealize(bool succeed=true)
Definition: MockAndroidSLESObject.h:97

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0