diff --git a/hal/src/main/java/edu/wpi/first/hal/sim/mockdata/DriverStationDataJNI.java b/hal/src/main/java/edu/wpi/first/hal/sim/mockdata/DriverStationDataJNI.java index 448be75a4f..b9334a8737 100644 --- a/hal/src/main/java/edu/wpi/first/hal/sim/mockdata/DriverStationDataJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/sim/mockdata/DriverStationDataJNI.java @@ -46,7 +46,7 @@ public class DriverStationDataJNI extends JNIWrapper { public static native void setJoystickPOVs(byte joystickNum, short[] povsArray); public static native void setJoystickButtons(byte joystickNum, int buttons, int count); - public static native void setMatchInfo(MatchInfoData info); + public static native void setMatchInfo(String eventName, String gameSpecificMessage, int matchNumber, int replayNumber, int matchType); public static native void registerAllCallbacks(NotifyCallback callback, boolean initialNotify); public static native void notifyNewData(); diff --git a/hal/src/main/native/sim/jni/DriverStationDataJNI.cpp b/hal/src/main/native/sim/jni/DriverStationDataJNI.cpp index 2e76c36d35..621650ae08 100644 --- a/hal/src/main/native/sim/jni/DriverStationDataJNI.cpp +++ b/hal/src/main/native/sim/jni/DriverStationDataJNI.cpp @@ -7,10 +7,16 @@ #include +#include + +#include + #include "CallbackStore.h" #include "edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI.h" #include "mockdata/DriverStationData.h" +using namespace wpi::java; + extern "C" { /* @@ -388,12 +394,28 @@ Java_edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI_setJoystickButtons /* * Class: edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI * Method: setMatchInfo - * Signature: (Ljava/lang/Object;)V + * Signature: (Ljava/lang/String;Ljava/lang/String;III)V */ JNIEXPORT void JNICALL Java_edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI_setMatchInfo - (JNIEnv* env, jclass, jobject info) -{} + (JNIEnv* env, jclass, jstring eventName, jstring gameSpecificMessage, + jint matchNumber, jint replayNumber, jint matchType) +{ + JStringRef eventNameRef{env, eventName}; + JStringRef gameSpecificMessageRef{env, gameSpecificMessage}; + + HAL_MatchInfo halMatchInfo; + std::snprintf(halMatchInfo.eventName, sizeof(halMatchInfo.eventName), "%s", + eventNameRef.c_str()); + std::snprintf(reinterpret_cast(halMatchInfo.gameSpecificMessage), + sizeof(halMatchInfo.gameSpecificMessage), "%s", + gameSpecificMessageRef.c_str()); + halMatchInfo.gameSpecificMessageSize = gameSpecificMessageRef.size(); + halMatchInfo.matchType = (HAL_MatchType)matchType; + halMatchInfo.matchNumber = matchNumber; + halMatchInfo.replayNumber = replayNumber; + HALSIM_SetMatchInfo(&halMatchInfo); +} /* * Class: edu_wpi_first_hal_sim_mockdata_DriverStationDataJNI diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/hal/MatchInfoDataTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/hal/MatchInfoDataTest.java index 04a1bd4c19..8b082c93a6 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/hal/MatchInfoDataTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/hal/MatchInfoDataTest.java @@ -9,13 +9,28 @@ package edu.wpi.first.wpilibj.hal; import org.junit.jupiter.api.Test; +import edu.wpi.first.hal.sim.mockdata.DriverStationDataJNI; +import edu.wpi.first.wpilibj.DriverStation.MatchType; + +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; + class MatchInfoDataTest { @Test - @SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") - void matchInfoDataDoesNotThrow() { - HAL.initialize(500, 0); - MatchInfoData data = new MatchInfoData(); - HAL.getMatchInfo(data); - // Nothing we can assert, so just make sure it didn't throw. + void testSetMatchInfo() { + + MatchType matchType = MatchType.Qualification; + DriverStationDataJNI.setMatchInfo("Event Name", "Game Message", 174, 191, matchType.ordinal()); + + MatchInfoData outMatchInfo = new MatchInfoData(); + HAL.getMatchInfo(outMatchInfo); + + assertAll( + () -> assertEquals("Event Name", outMatchInfo.eventName), + () -> assertEquals(matchType.ordinal(), outMatchInfo.matchType), + () -> assertEquals(174, outMatchInfo.matchNumber), + () -> assertEquals(191, outMatchInfo.replayNumber), + () -> assertEquals("Game Message", outMatchInfo.gameSpecificMessage) + ); } }