hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 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 | // Unit Test for TranscodingClientManager |
| 18 | |
| 19 | // #define LOG_NDEBUG 0 |
| 20 | #define LOG_TAG "TranscodingClientManagerTest" |
| 21 | |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 22 | #include <aidl/android/media/BnTranscodingClientCallback.h> |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 23 | #include <aidl/android/media/IMediaTranscodingService.h> |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 24 | #include <android-base/logging.h> |
| 25 | #include <android/binder_manager.h> |
| 26 | #include <android/binder_process.h> |
| 27 | #include <gtest/gtest.h> |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 28 | #include <media/ControllerClientInterface.h> |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 29 | #include <media/TranscodingClientManager.h> |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 30 | #include <media/TranscodingRequest.h> |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 31 | #include <utils/Log.h> |
| 32 | |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 33 | #include <list> |
| 34 | |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 35 | namespace android { |
| 36 | |
| 37 | using Status = ::ndk::ScopedAStatus; |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 38 | using ::aidl::android::media::BnTranscodingClientCallback; |
| 39 | using ::aidl::android::media::IMediaTranscodingService; |
| 40 | using ::aidl::android::media::TranscodingErrorCode; |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 41 | using ::aidl::android::media::TranscodingRequestParcel; |
| 42 | using ::aidl::android::media::TranscodingResultParcel; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 43 | using ::aidl::android::media::TranscodingSessionParcel; |
| 44 | using ::aidl::android::media::TranscodingSessionPriority; |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 45 | |
Chong Zhang | 3f23e98 | 2020-09-24 14:03:41 -0700 | [diff] [blame] | 46 | constexpr pid_t kInvalidClientPid = -5; |
| 47 | constexpr pid_t kInvalidClientUid = -10; |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 48 | constexpr const char* kInvalidClientName = ""; |
| 49 | constexpr const char* kInvalidClientPackage = ""; |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 50 | |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 51 | constexpr const char* kClientName = "TestClientName"; |
| 52 | constexpr const char* kClientPackage = "TestClientPackage"; |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 53 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 54 | #define SESSION(n) (n) |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 55 | |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 56 | struct TestClientCallback : public BnTranscodingClientCallback { |
| 57 | TestClientCallback() { ALOGI("TestClientCallback Created"); } |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 58 | |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 59 | virtual ~TestClientCallback() { ALOGI("TestClientCallback destroyed"); }; |
| 60 | |
hkuang | 1925309 | 2020-06-01 09:10:49 -0700 | [diff] [blame] | 61 | Status openFileDescriptor(const std::string& /*in_fileUri*/, const std::string& /*in_mode*/, |
| 62 | ::ndk::ScopedFileDescriptor* /*_aidl_return*/) override { |
| 63 | return Status::ok(); |
| 64 | } |
| 65 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 66 | Status onTranscodingStarted(int32_t /*in_sessionId*/) override { return Status::ok(); } |
hkuang | 96471b8 | 2020-06-08 11:12:46 -0700 | [diff] [blame] | 67 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 68 | Status onTranscodingPaused(int32_t /*in_sessionId*/) override { return Status::ok(); } |
hkuang | 96471b8 | 2020-06-08 11:12:46 -0700 | [diff] [blame] | 69 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 70 | Status onTranscodingResumed(int32_t /*in_sessionId*/) override { return Status::ok(); } |
hkuang | 96471b8 | 2020-06-08 11:12:46 -0700 | [diff] [blame] | 71 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 72 | Status onTranscodingFinished(int32_t in_sessionId, |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 73 | const TranscodingResultParcel& in_result) override { |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 74 | EXPECT_EQ(in_sessionId, in_result.sessionId); |
| 75 | mEventQueue.push_back(Finished(in_sessionId)); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 76 | return Status::ok(); |
| 77 | } |
| 78 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 79 | Status onTranscodingFailed(int32_t in_sessionId, |
| 80 | TranscodingErrorCode /*in_errorCode */) override { |
| 81 | mEventQueue.push_back(Failed(in_sessionId)); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 82 | return Status::ok(); |
| 83 | } |
| 84 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 85 | Status onAwaitNumberOfSessionsChanged(int32_t /* in_sessionId */, |
| 86 | int32_t /* in_oldAwaitNumber */, |
| 87 | int32_t /* in_newAwaitNumber */) override { |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 88 | return Status::ok(); |
| 89 | } |
| 90 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 91 | Status onProgressUpdate(int32_t /* in_sessionId */, int32_t /* in_progress */) override { |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 92 | return Status::ok(); |
| 93 | } |
| 94 | |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 95 | struct Event { |
| 96 | enum { |
| 97 | NoEvent, |
| 98 | Finished, |
| 99 | Failed, |
| 100 | } type; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 101 | SessionIdType sessionId; |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static constexpr Event NoEvent = {Event::NoEvent, 0}; |
| 105 | #define DECLARE_EVENT(action) \ |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 106 | static Event action(SessionIdType sessionId) { return {Event::action, sessionId}; } |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 107 | |
| 108 | DECLARE_EVENT(Finished); |
| 109 | DECLARE_EVENT(Failed); |
| 110 | |
| 111 | const Event& popEvent() { |
| 112 | if (mEventQueue.empty()) { |
| 113 | mPoppedEvent = NoEvent; |
| 114 | } else { |
| 115 | mPoppedEvent = *mEventQueue.begin(); |
| 116 | mEventQueue.pop_front(); |
| 117 | } |
| 118 | return mPoppedEvent; |
| 119 | } |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 120 | |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 121 | private: |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 122 | Event mPoppedEvent; |
| 123 | std::list<Event> mEventQueue; |
| 124 | |
| 125 | TestClientCallback(const TestClientCallback&) = delete; |
| 126 | TestClientCallback& operator=(const TestClientCallback&) = delete; |
| 127 | }; |
| 128 | |
| 129 | bool operator==(const TestClientCallback::Event& lhs, const TestClientCallback::Event& rhs) { |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 130 | return lhs.type == rhs.type && lhs.sessionId == rhs.sessionId; |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 133 | struct TestController : public ControllerClientInterface { |
| 134 | TestController() { ALOGI("TestController Created"); } |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 135 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 136 | virtual ~TestController() { ALOGI("TestController Destroyed"); } |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 137 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 138 | bool submit(ClientIdType clientId, SessionIdType sessionId, uid_t /*uid*/, |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 139 | const TranscodingRequestParcel& request, |
| 140 | const std::weak_ptr<ITranscodingClientCallback>& clientCallback) override { |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 141 | SessionKeyType sessionKey = std::make_pair(clientId, sessionId); |
| 142 | if (mSessions.count(sessionKey) > 0) { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 143 | return false; |
| 144 | } |
| 145 | |
| 146 | // This is the secret name we'll check, to test error propagation from |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 147 | // the controller back to client. |
hkuang | 72d105f | 2020-05-21 10:48:55 -0700 | [diff] [blame] | 148 | if (request.sourceFilePath == "bad_source_file") { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 149 | return false; |
| 150 | } |
| 151 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 152 | mSessions[sessionKey].request = request; |
| 153 | mSessions[sessionKey].callback = clientCallback; |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 154 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 155 | mLastSession = sessionKey; |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 156 | return true; |
| 157 | } |
| 158 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 159 | bool cancel(ClientIdType clientId, SessionIdType sessionId) override { |
| 160 | SessionKeyType sessionKey = std::make_pair(clientId, sessionId); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 161 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 162 | if (mSessions.count(sessionKey) == 0) { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 163 | return false; |
| 164 | } |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 165 | mSessions.erase(sessionKey); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 166 | return true; |
| 167 | } |
| 168 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 169 | bool getSession(ClientIdType clientId, SessionIdType sessionId, |
| 170 | TranscodingRequestParcel* request) override { |
| 171 | SessionKeyType sessionKey = std::make_pair(clientId, sessionId); |
| 172 | if (mSessions.count(sessionKey) == 0) { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 173 | return false; |
| 174 | } |
| 175 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 176 | *(TranscodingRequest*)request = mSessions[sessionKey].request; |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 177 | return true; |
| 178 | } |
| 179 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 180 | void finishLastSession() { |
| 181 | auto it = mSessions.find(mLastSession); |
| 182 | if (it == mSessions.end()) { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 183 | return; |
| 184 | } |
| 185 | { |
| 186 | auto clientCallback = it->second.callback.lock(); |
| 187 | if (clientCallback != nullptr) { |
| 188 | clientCallback->onTranscodingFinished( |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 189 | mLastSession.second, |
| 190 | TranscodingResultParcel({mLastSession.second, 0, std::nullopt})); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 193 | mSessions.erase(it); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 194 | } |
| 195 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 196 | void abortLastSession() { |
| 197 | auto it = mSessions.find(mLastSession); |
| 198 | if (it == mSessions.end()) { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 199 | return; |
| 200 | } |
| 201 | { |
| 202 | auto clientCallback = it->second.callback.lock(); |
| 203 | if (clientCallback != nullptr) { |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 204 | clientCallback->onTranscodingFailed(mLastSession.second, |
Chong Zhang | 7ae4e2f | 2020-04-17 15:24:34 -0700 | [diff] [blame] | 205 | TranscodingErrorCode::kUnknown); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 206 | } |
| 207 | } |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 208 | mSessions.erase(it); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 211 | struct Session { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 212 | TranscodingRequest request; |
| 213 | std::weak_ptr<ITranscodingClientCallback> callback; |
| 214 | }; |
| 215 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 216 | typedef std::pair<ClientIdType, SessionIdType> SessionKeyType; |
| 217 | std::map<SessionKeyType, Session> mSessions; |
| 218 | SessionKeyType mLastSession; |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | class TranscodingClientManagerTest : public ::testing::Test { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 222 | public: |
| 223 | TranscodingClientManagerTest() |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 224 | : mController(new TestController()), |
| 225 | mClientManager(new TranscodingClientManager(mController)) { |
hkuang | 5172cab | 2020-01-31 12:40:28 -0800 | [diff] [blame] | 226 | ALOGD("TranscodingClientManagerTest created"); |
| 227 | } |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 228 | |
| 229 | void SetUp() override { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 230 | mClientCallback1 = ::ndk::SharedRefBase::make<TestClientCallback>(); |
| 231 | mClientCallback2 = ::ndk::SharedRefBase::make<TestClientCallback>(); |
| 232 | mClientCallback3 = ::ndk::SharedRefBase::make<TestClientCallback>(); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 235 | void TearDown() override { ALOGI("TranscodingClientManagerTest tear down"); } |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 236 | |
| 237 | ~TranscodingClientManagerTest() { ALOGD("TranscodingClientManagerTest destroyed"); } |
| 238 | |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 239 | void addMultipleClients() { |
Chong Zhang | 0579c6f | 2020-10-05 12:03:34 -0700 | [diff] [blame] | 240 | EXPECT_EQ( |
| 241 | mClientManager->addClient(mClientCallback1, kClientName, kClientPackage, &mClient1), |
| 242 | OK); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 243 | EXPECT_NE(mClient1, nullptr); |
| 244 | |
Chong Zhang | 0579c6f | 2020-10-05 12:03:34 -0700 | [diff] [blame] | 245 | EXPECT_EQ( |
| 246 | mClientManager->addClient(mClientCallback2, kClientName, kClientPackage, &mClient2), |
| 247 | OK); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 248 | EXPECT_NE(mClient2, nullptr); |
| 249 | |
Chong Zhang | 0579c6f | 2020-10-05 12:03:34 -0700 | [diff] [blame] | 250 | EXPECT_EQ( |
| 251 | mClientManager->addClient(mClientCallback3, kClientName, kClientPackage, &mClient3), |
| 252 | OK); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 253 | EXPECT_NE(mClient3, nullptr); |
| 254 | |
| 255 | EXPECT_EQ(mClientManager->getNumOfClients(), 3); |
| 256 | } |
| 257 | |
| 258 | void unregisterMultipleClients() { |
| 259 | EXPECT_TRUE(mClient1->unregister().isOk()); |
| 260 | EXPECT_TRUE(mClient2->unregister().isOk()); |
| 261 | EXPECT_TRUE(mClient3->unregister().isOk()); |
| 262 | EXPECT_EQ(mClientManager->getNumOfClients(), 0); |
| 263 | } |
| 264 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 265 | std::shared_ptr<TestController> mController; |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 266 | std::shared_ptr<TranscodingClientManager> mClientManager; |
| 267 | std::shared_ptr<ITranscodingClient> mClient1; |
| 268 | std::shared_ptr<ITranscodingClient> mClient2; |
| 269 | std::shared_ptr<ITranscodingClient> mClient3; |
| 270 | std::shared_ptr<TestClientCallback> mClientCallback1; |
| 271 | std::shared_ptr<TestClientCallback> mClientCallback2; |
| 272 | std::shared_ptr<TestClientCallback> mClientCallback3; |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 273 | }; |
| 274 | |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 275 | TEST_F(TranscodingClientManagerTest, TestAddingWithInvalidClientCallback) { |
| 276 | // Add a client with null callback and expect failure. |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 277 | std::shared_ptr<ITranscodingClient> client; |
Chong Zhang | 0579c6f | 2020-10-05 12:03:34 -0700 | [diff] [blame] | 278 | status_t err = mClientManager->addClient(nullptr, kClientName, kClientPackage, &client); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 279 | EXPECT_EQ(err, IMediaTranscodingService::ERROR_ILLEGAL_ARGUMENT); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 280 | } |
Chong Zhang | 3f23e98 | 2020-09-24 14:03:41 -0700 | [diff] [blame] | 281 | // |
| 282 | //TEST_F(TranscodingClientManagerTest, TestAddingWithInvalidClientPid) { |
| 283 | // // Add a client with invalid Pid and expect failure. |
| 284 | // std::shared_ptr<ITranscodingClient> client; |
| 285 | // status_t err = mClientManager->addClient(mClientCallback1, |
| 286 | // kClientName, kClientPackage, &client); |
| 287 | // EXPECT_EQ(err, IMediaTranscodingService::ERROR_ILLEGAL_ARGUMENT); |
| 288 | //} |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 289 | |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 290 | TEST_F(TranscodingClientManagerTest, TestAddingWithInvalidClientName) { |
| 291 | // Add a client with invalid name and expect failure. |
| 292 | std::shared_ptr<ITranscodingClient> client; |
Chong Zhang | 0579c6f | 2020-10-05 12:03:34 -0700 | [diff] [blame] | 293 | status_t err = mClientManager->addClient(mClientCallback1, kInvalidClientName, kClientPackage, |
| 294 | &client); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 295 | EXPECT_EQ(err, IMediaTranscodingService::ERROR_ILLEGAL_ARGUMENT); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | TEST_F(TranscodingClientManagerTest, TestAddingWithInvalidClientPackageName) { |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 299 | // Add a client with invalid packagename and expect failure. |
| 300 | std::shared_ptr<ITranscodingClient> client; |
Chong Zhang | 0579c6f | 2020-10-05 12:03:34 -0700 | [diff] [blame] | 301 | status_t err = mClientManager->addClient(mClientCallback1, kClientName, kInvalidClientPackage, |
| 302 | &client); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 303 | EXPECT_EQ(err, IMediaTranscodingService::ERROR_ILLEGAL_ARGUMENT); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | TEST_F(TranscodingClientManagerTest, TestAddingValidClient) { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 307 | // Add a valid client, should succeed. |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 308 | std::shared_ptr<ITranscodingClient> client; |
Chong Zhang | 0579c6f | 2020-10-05 12:03:34 -0700 | [diff] [blame] | 309 | status_t err = |
| 310 | mClientManager->addClient(mClientCallback1, kClientName, kClientPackage, &client); |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 311 | EXPECT_EQ(err, OK); |
| 312 | EXPECT_NE(client.get(), nullptr); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 313 | EXPECT_EQ(mClientManager->getNumOfClients(), 1); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 314 | |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 315 | // Unregister client, should succeed. |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 316 | Status status = client->unregister(); |
| 317 | EXPECT_TRUE(status.isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 318 | EXPECT_EQ(mClientManager->getNumOfClients(), 0); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | TEST_F(TranscodingClientManagerTest, TestAddingDupliacteClient) { |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 322 | std::shared_ptr<ITranscodingClient> client; |
Chong Zhang | 0579c6f | 2020-10-05 12:03:34 -0700 | [diff] [blame] | 323 | status_t err = |
| 324 | mClientManager->addClient(mClientCallback1, kClientName, kClientPackage, &client); |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 325 | EXPECT_EQ(err, OK); |
| 326 | EXPECT_NE(client.get(), nullptr); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 327 | EXPECT_EQ(mClientManager->getNumOfClients(), 1); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 328 | |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 329 | std::shared_ptr<ITranscodingClient> dupClient; |
Chong Zhang | 0579c6f | 2020-10-05 12:03:34 -0700 | [diff] [blame] | 330 | err = mClientManager->addClient(mClientCallback1, "dupClient", "dupPackage", &dupClient); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 331 | EXPECT_EQ(err, IMediaTranscodingService::ERROR_ALREADY_EXISTS); |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 332 | EXPECT_EQ(dupClient.get(), nullptr); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 333 | EXPECT_EQ(mClientManager->getNumOfClients(), 1); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 334 | |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 335 | Status status = client->unregister(); |
| 336 | EXPECT_TRUE(status.isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 337 | EXPECT_EQ(mClientManager->getNumOfClients(), 0); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 338 | |
Chong Zhang | 3f23e98 | 2020-09-24 14:03:41 -0700 | [diff] [blame] | 339 | err = mClientManager->addClient(mClientCallback1, "dupClient", "dupPackage", &dupClient); |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 340 | EXPECT_EQ(err, OK); |
| 341 | EXPECT_NE(dupClient.get(), nullptr); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 342 | EXPECT_EQ(mClientManager->getNumOfClients(), 1); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 343 | |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 344 | status = dupClient->unregister(); |
| 345 | EXPECT_TRUE(status.isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 346 | EXPECT_EQ(mClientManager->getNumOfClients(), 0); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | TEST_F(TranscodingClientManagerTest, TestAddingMultipleClient) { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 350 | addMultipleClients(); |
| 351 | unregisterMultipleClients(); |
| 352 | } |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 353 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 354 | TEST_F(TranscodingClientManagerTest, TestSubmitCancelGetSessions) { |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 355 | addMultipleClients(); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 356 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 357 | // Test sessionId assignment. |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 358 | TranscodingRequestParcel request; |
hkuang | 72d105f | 2020-05-21 10:48:55 -0700 | [diff] [blame] | 359 | request.sourceFilePath = "test_source_file_0"; |
| 360 | request.destinationFilePath = "test_desintaion_file_0"; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 361 | TranscodingSessionParcel session; |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 362 | bool result; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 363 | EXPECT_TRUE(mClient1->submitRequest(request, &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 364 | EXPECT_TRUE(result); |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 365 | EXPECT_EQ(session.sessionId, SESSION(0)); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 366 | |
hkuang | 72d105f | 2020-05-21 10:48:55 -0700 | [diff] [blame] | 367 | request.sourceFilePath = "test_source_file_1"; |
| 368 | request.destinationFilePath = "test_desintaion_file_1"; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 369 | EXPECT_TRUE(mClient1->submitRequest(request, &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 370 | EXPECT_TRUE(result); |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 371 | EXPECT_EQ(session.sessionId, SESSION(1)); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 372 | |
hkuang | 72d105f | 2020-05-21 10:48:55 -0700 | [diff] [blame] | 373 | request.sourceFilePath = "test_source_file_2"; |
| 374 | request.destinationFilePath = "test_desintaion_file_2"; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 375 | EXPECT_TRUE(mClient1->submitRequest(request, &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 376 | EXPECT_TRUE(result); |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 377 | EXPECT_EQ(session.sessionId, SESSION(2)); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 378 | |
hkuang | 72d105f | 2020-05-21 10:48:55 -0700 | [diff] [blame] | 379 | // Test submit bad request (no valid sourceFilePath) fails. |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 380 | TranscodingRequestParcel badRequest; |
hkuang | 72d105f | 2020-05-21 10:48:55 -0700 | [diff] [blame] | 381 | badRequest.sourceFilePath = "bad_source_file"; |
| 382 | badRequest.destinationFilePath = "bad_destination_file"; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 383 | EXPECT_TRUE(mClient1->submitRequest(badRequest, &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 384 | EXPECT_FALSE(result); |
| 385 | |
Chong Zhang | 3f23e98 | 2020-09-24 14:03:41 -0700 | [diff] [blame] | 386 | // Test submit with bad pid/uid. |
| 387 | badRequest.sourceFilePath = "test_source_file_3"; |
| 388 | badRequest.destinationFilePath = "test_desintaion_file_3"; |
| 389 | badRequest.clientPid = kInvalidClientPid; |
| 390 | badRequest.clientUid = kInvalidClientUid; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 391 | EXPECT_TRUE(mClient1->submitRequest(badRequest, &session, &result).isOk()); |
Chong Zhang | 3f23e98 | 2020-09-24 14:03:41 -0700 | [diff] [blame] | 392 | EXPECT_FALSE(result); |
| 393 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 394 | // Test get sessions by id. |
| 395 | EXPECT_TRUE(mClient1->getSessionWithId(SESSION(2), &session, &result).isOk()); |
| 396 | EXPECT_EQ(session.sessionId, SESSION(2)); |
| 397 | EXPECT_EQ(session.request.sourceFilePath, "test_source_file_2"); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 398 | EXPECT_TRUE(result); |
| 399 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 400 | // Test get sessions by invalid id fails. |
| 401 | EXPECT_TRUE(mClient1->getSessionWithId(SESSION(100), &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 402 | EXPECT_FALSE(result); |
| 403 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 404 | // Test cancel non-existent session fail. |
| 405 | EXPECT_TRUE(mClient2->cancelSession(SESSION(100), &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 406 | EXPECT_FALSE(result); |
| 407 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 408 | // Test cancel valid sessionId in arbitrary order. |
| 409 | EXPECT_TRUE(mClient1->cancelSession(SESSION(2), &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 410 | EXPECT_TRUE(result); |
| 411 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 412 | EXPECT_TRUE(mClient1->cancelSession(SESSION(0), &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 413 | EXPECT_TRUE(result); |
| 414 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 415 | EXPECT_TRUE(mClient1->cancelSession(SESSION(1), &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 416 | EXPECT_TRUE(result); |
| 417 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 418 | // Test cancel session again fails. |
| 419 | EXPECT_TRUE(mClient1->cancelSession(SESSION(1), &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 420 | EXPECT_FALSE(result); |
| 421 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 422 | // Test get session after cancel fails. |
| 423 | EXPECT_TRUE(mClient1->getSessionWithId(SESSION(2), &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 424 | EXPECT_FALSE(result); |
| 425 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 426 | // Test sessionId independence for each client. |
| 427 | EXPECT_TRUE(mClient2->submitRequest(request, &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 428 | EXPECT_TRUE(result); |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 429 | EXPECT_EQ(session.sessionId, SESSION(0)); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 430 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 431 | EXPECT_TRUE(mClient2->submitRequest(request, &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 432 | EXPECT_TRUE(result); |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 433 | EXPECT_EQ(session.sessionId, SESSION(1)); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 434 | |
| 435 | unregisterMultipleClients(); |
| 436 | } |
| 437 | |
| 438 | TEST_F(TranscodingClientManagerTest, TestClientCallback) { |
| 439 | addMultipleClients(); |
| 440 | |
| 441 | TranscodingRequestParcel request; |
hkuang | 72d105f | 2020-05-21 10:48:55 -0700 | [diff] [blame] | 442 | request.sourceFilePath = "test_source_file_name"; |
| 443 | request.destinationFilePath = "test_destination_file_name"; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 444 | TranscodingSessionParcel session; |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 445 | bool result; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 446 | EXPECT_TRUE(mClient1->submitRequest(request, &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 447 | EXPECT_TRUE(result); |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 448 | EXPECT_EQ(session.sessionId, SESSION(0)); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 449 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 450 | mController->finishLastSession(); |
| 451 | EXPECT_EQ(mClientCallback1->popEvent(), TestClientCallback::Finished(session.sessionId)); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 452 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 453 | EXPECT_TRUE(mClient1->submitRequest(request, &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 454 | EXPECT_TRUE(result); |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 455 | EXPECT_EQ(session.sessionId, SESSION(1)); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 456 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 457 | mController->abortLastSession(); |
| 458 | EXPECT_EQ(mClientCallback1->popEvent(), TestClientCallback::Failed(session.sessionId)); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 459 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 460 | EXPECT_TRUE(mClient1->submitRequest(request, &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 461 | EXPECT_TRUE(result); |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 462 | EXPECT_EQ(session.sessionId, SESSION(2)); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 463 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 464 | EXPECT_TRUE(mClient2->submitRequest(request, &session, &result).isOk()); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 465 | EXPECT_TRUE(result); |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 466 | EXPECT_EQ(session.sessionId, SESSION(0)); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 467 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 468 | mController->finishLastSession(); |
| 469 | EXPECT_EQ(mClientCallback2->popEvent(), TestClientCallback::Finished(session.sessionId)); |
Chong Zhang | 6d58e4b | 2020-03-31 09:41:10 -0700 | [diff] [blame] | 470 | |
| 471 | unregisterMultipleClients(); |
hkuang | 26587cb | 2020-01-16 10:36:08 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 474 | TEST_F(TranscodingClientManagerTest, TestUseAfterUnregister) { |
| 475 | // Add a client. |
| 476 | std::shared_ptr<ITranscodingClient> client; |
Chong Zhang | 0579c6f | 2020-10-05 12:03:34 -0700 | [diff] [blame] | 477 | status_t err = |
| 478 | mClientManager->addClient(mClientCallback1, kClientName, kClientPackage, &client); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 479 | EXPECT_EQ(err, OK); |
| 480 | EXPECT_NE(client.get(), nullptr); |
| 481 | |
| 482 | // Submit 2 requests, 1 offline and 1 realtime. |
| 483 | TranscodingRequestParcel request; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 484 | TranscodingSessionParcel session; |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 485 | bool result; |
| 486 | |
hkuang | 72d105f | 2020-05-21 10:48:55 -0700 | [diff] [blame] | 487 | request.sourceFilePath = "test_source_file_0"; |
| 488 | request.destinationFilePath = "test_destination_file_0"; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 489 | request.priority = TranscodingSessionPriority::kUnspecified; |
| 490 | EXPECT_TRUE(client->submitRequest(request, &session, &result).isOk() && result); |
| 491 | EXPECT_EQ(session.sessionId, SESSION(0)); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 492 | |
hkuang | 72d105f | 2020-05-21 10:48:55 -0700 | [diff] [blame] | 493 | request.sourceFilePath = "test_source_file_1"; |
| 494 | request.destinationFilePath = "test_destination_file_1"; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 495 | request.priority = TranscodingSessionPriority::kNormal; |
| 496 | EXPECT_TRUE(client->submitRequest(request, &session, &result).isOk() && result); |
| 497 | EXPECT_EQ(session.sessionId, SESSION(1)); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 498 | |
| 499 | // Unregister client, should succeed. |
| 500 | Status status = client->unregister(); |
| 501 | EXPECT_TRUE(status.isOk()); |
| 502 | |
| 503 | // Test submit new request after unregister, should fail with ERROR_DISCONNECTED. |
hkuang | 72d105f | 2020-05-21 10:48:55 -0700 | [diff] [blame] | 504 | request.sourceFilePath = "test_source_file_2"; |
| 505 | request.destinationFilePath = "test_destination_file_2"; |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 506 | request.priority = TranscodingSessionPriority::kNormal; |
| 507 | status = client->submitRequest(request, &session, &result); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 508 | EXPECT_FALSE(status.isOk()); |
| 509 | EXPECT_EQ(status.getServiceSpecificError(), IMediaTranscodingService::ERROR_DISCONNECTED); |
| 510 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 511 | // Test cancel sessions after unregister, should fail with ERROR_DISCONNECTED |
| 512 | // regardless of realtime or offline session, or whether the sessionId is valid. |
| 513 | status = client->cancelSession(SESSION(0), &result); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 514 | EXPECT_FALSE(status.isOk()); |
| 515 | EXPECT_EQ(status.getServiceSpecificError(), IMediaTranscodingService::ERROR_DISCONNECTED); |
| 516 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 517 | status = client->cancelSession(SESSION(1), &result); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 518 | EXPECT_FALSE(status.isOk()); |
| 519 | EXPECT_EQ(status.getServiceSpecificError(), IMediaTranscodingService::ERROR_DISCONNECTED); |
| 520 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 521 | status = client->cancelSession(SESSION(2), &result); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 522 | EXPECT_FALSE(status.isOk()); |
| 523 | EXPECT_EQ(status.getServiceSpecificError(), IMediaTranscodingService::ERROR_DISCONNECTED); |
| 524 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 525 | // Test get sessions, should fail with ERROR_DISCONNECTED regardless of realtime |
| 526 | // or offline session, or whether the sessionId is valid. |
| 527 | status = client->getSessionWithId(SESSION(0), &session, &result); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 528 | EXPECT_FALSE(status.isOk()); |
| 529 | EXPECT_EQ(status.getServiceSpecificError(), IMediaTranscodingService::ERROR_DISCONNECTED); |
| 530 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 531 | status = client->getSessionWithId(SESSION(1), &session, &result); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 532 | EXPECT_FALSE(status.isOk()); |
| 533 | EXPECT_EQ(status.getServiceSpecificError(), IMediaTranscodingService::ERROR_DISCONNECTED); |
| 534 | |
Chong Zhang | bc06248 | 2020-10-14 16:43:53 -0700 | [diff] [blame] | 535 | status = client->getSessionWithId(SESSION(2), &session, &result); |
Chong Zhang | 15c192a | 2020-05-05 16:24:00 -0700 | [diff] [blame] | 536 | EXPECT_FALSE(status.isOk()); |
| 537 | EXPECT_EQ(status.getServiceSpecificError(), IMediaTranscodingService::ERROR_DISCONNECTED); |
| 538 | } |
| 539 | |
Chong Zhang | 8e06263 | 2020-03-31 10:56:37 -0700 | [diff] [blame] | 540 | } // namespace android |