blob: d85420dc0f9923bd9edac6cf0796b80a45f295e3 [file] [log] [blame]
Paul McLeane6973482018-10-10 08:32:18 -06001/*
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 */
Paul McLean4306c8a2019-02-12 12:19:58 -080016#include <amidi/AMidi.h>
Paul McLeane6973482018-10-10 08:32:18 -060017
18#include <jni.h>
19
20class TestMessage;
21
22class MidiTestManager {
23public:
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.
Mikhail Naganov8c93ad22018-11-08 13:02:48 -080033 int ProcessInput();
Paul McLeane6973482018-10-10 08:32:18 -060034
35private:
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;
Paul McLean4fb41552020-08-25 16:49:49 +000047 static const int MESSAGE_MAX_BYTES = 1024;
Paul McLeane6973482018-10-10 08:32:18 -060048
49 AMidiInputPort* mMidiSendPort;
50 AMidiOutputPort* mMidiReceivePort;
51
52 // The array of messages to send/receive
53 TestMessage* mTestMsgs;
54 int mNumTestMsgs;
55
56 // JNI
57 JavaVM* mJvm;
58 jmethodID mMidEndTest;
59
60 // Test result codes
61 static const int TESTSTATUS_NOTRUN = 0;
62 static const int TESTSTATUS_PASSED = 1;
63 static const int TESTSTATUS_FAILED_MISMATCH = 2;
64 static const int TESTSTATUS_FAILED_TIMEOUT = 3;
65 static const int TESTSTATUS_FAILED_OVERRUN = 4;
66 static const int TESTSTATUS_FAILED_DEVICE = 5;
67 static const int TESTSTATUS_FAILED_JNI = 6;
Paul McLeane6973482018-10-10 08:32:18 -060068
Paul McLean4fb41552020-08-25 16:49:49 +000069
Paul McLeane6973482018-10-10 08:32:18 -060070 bool StartReading(AMidiDevice* nativeReadDevice);
71 bool StartWriting(AMidiDevice* nativeWriteDevice);
72};