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 int matchStream(uint8_t* bytes, int count); 41 42 bool setupMessages(); 43 int sendMessages(); 44 45 jobject mTestModuleObj; 46 47 // build the stream for matching. 48 std::vector<uint8_t> mMatchStream; 49 50 int mReceiveStreamPos; 51 static const int MESSAGE_MAX_BYTES = 1024; 52 53 AMidiInputPort* mMidiSendPort; 54 AMidiOutputPort* mMidiReceivePort; 55 56 // The array of messages to send/receive 57 std::vector<TestMessage> mTestMsgs; 58 int mNumTestMsgs; 59 60 bool mThrottleData; 61 62 // JNI 63 JavaVM* mJvm; 64 jmethodID mMidEndTest; 65 66 // Test result codes 67 static const int TESTSTATUS_NOTRUN = 0; 68 static const int TESTSTATUS_PASSED = 1; 69 static const int TESTSTATUS_FAILED_MISMATCH = 2; 70 static const int TESTSTATUS_FAILED_TIMEOUT = 3; 71 static const int TESTSTATUS_FAILED_OVERRUN = 4; 72 static const int TESTSTATUS_FAILED_DEVICE = 5; 73 static const int TESTSTATUS_FAILED_JNI = 6; 74 static const int TESTSTATUS_FAILED_SETUP = 7; 75 static const int TESTSTATUS_FAILED_SEND = 8; 76 77 bool StartReading(AMidiDevice* nativeReadDevice); 78 bool StartWriting(AMidiDevice* nativeWriteDevice); 79 }; 80