1 /**
2  * Copyright (C) 2022 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 #include <nuplayer/NuPlayerStreamListener.h>
18 #include <stdlib.h>
19 
20 #include "../includes/common.h"
21 
22 const size_t kBufferSize = 1024;
23 
24 using namespace android;
25 
26 bool isTestInProgress = false;
27 
28 struct sigaction new_action, old_action;
29 
sigabrt_handler(int signum,siginfo_t * info,void * context)30 void sigabrt_handler(int signum, siginfo_t *info, void *context) {
31     if (isTestInProgress && info->si_signo == SIGABRT) {
32         (*old_action.sa_sigaction)(signum, info, context);
33         return;
34     }
35     exit(EXIT_FAILURE);
36 }
37 
38 class StreamSource : public IStreamSource {
39 public:
setListener(const sp<IStreamListener> & listener)40     void setListener(const sp<IStreamListener> &listener __attribute__((unused))) {}
setBuffers(const Vector<sp<IMemory>> & buffers)41     void setBuffers(const Vector<sp<IMemory>> &buffers __attribute__((unused))) {}
onBufferAvailable(size_t index)42     void onBufferAvailable(size_t index __attribute__((unused))) {}
43 
44 protected:
onAsBinder()45     IBinder *onAsBinder() { return (IBinder *)malloc(kBufferSize); }
46 };
47 
main()48 int main() {
49     sigemptyset(&new_action.sa_mask);
50     new_action.sa_flags = SA_SIGINFO;
51     new_action.sa_sigaction = sigabrt_handler;
52     sigaction(SIGABRT, &new_action, &old_action);
53 
54     const sp<StreamSource> source = new StreamSource();
55     FAIL_CHECK(source != nullptr);
56     isTestInProgress = true;
57     sp<NuPlayer::NuPlayerStreamListener> listener =
58             new NuPlayer::NuPlayerStreamListener(source, nullptr);
59     isTestInProgress = false;
60     return EXIT_SUCCESS;
61 }
62