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