• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 #include <amidi/AMidi.h>
17 
18 #include <jni.h>
19 
20 class TestMessage;
21 
22 class MidiTestManager {
23 public:
24     MidiTestManager();
25     ~MidiTestManager();
26 
27     void jniSetup(JNIEnv* env);
28 
29     bool RunTest(jobject testModuleObj, AMidiDevice* sendDevice, AMidiDevice* receiveDevice);
30     void EndTest(int testCode);
31 
32     // Called by the thread routine.
33     int ProcessInput();
34 
35 private:
36    void buildTestStream();
37     bool matchStream(uint8_t* bytes, int count);
38 
39     int sendMessages();
40 
41     jobject mTestModuleObj;
42 
43     // The send messages in a linear stream for matching.
44     uint8_t*   mTestStream;
45     int     mNumTestStreamBytes;
46     int     mReceiveStreamPos;
47 
48     AMidiInputPort* mMidiSendPort;
49     AMidiOutputPort* mMidiReceivePort;
50 
51     // The array of messages to send/receive
52     TestMessage*    mTestMsgs;
53     int             mNumTestMsgs;
54 
55     // JNI
56     JavaVM* mJvm;
57     jmethodID mMidEndTest;
58 
59     // Test result codes
60     static const int TESTSTATUS_NOTRUN = 0;
61     static const int TESTSTATUS_PASSED = 1;
62     static const int TESTSTATUS_FAILED_MISMATCH = 2;
63     static const int TESTSTATUS_FAILED_TIMEOUT = 3;
64     static const int TESTSTATUS_FAILED_OVERRUN = 4;
65     static const int TESTSTATUS_FAILED_DEVICE = 5;
66     static const int TESTSTATUS_FAILED_JNI = 6;
67 
68     bool StartReading(AMidiDevice* nativeReadDevice);
69     bool StartWriting(AMidiDevice* nativeWriteDevice);
70 };
71