@@ -145,6 +145,66 @@ public void testHyperAlignedDst() {
145
145
MemorySegment .copy (segment , JAVA_BYTE .withByteAlignment (2 ), 0 , segment , 0 , 4 );
146
146
}
147
147
148
+ @ Test
149
+ public void testCopy5ArgWithNegativeValues () {
150
+ MemorySegment src = MemorySegment .ofArray (new byte [] {1 , 2 , 3 , 4 });
151
+ MemorySegment dst = MemorySegment .ofArray (new byte [] {1 , 2 , 3 , 4 });
152
+ assertThrows (IndexOutOfBoundsException .class , () ->
153
+ MemorySegment .copy (src , -1 , dst , 0 , 4 )
154
+ );
155
+ assertThrows (IndexOutOfBoundsException .class , () ->
156
+ MemorySegment .copy (src , 0 , dst , -1 , 4 )
157
+ );
158
+ assertThrows (IndexOutOfBoundsException .class , () ->
159
+ MemorySegment .copy (src , 0 , dst , 0 , -1 )
160
+ );
161
+ }
162
+
163
+ @ Test
164
+ public void testCopy7ArgWithNegativeValues () {
165
+ MemorySegment src = MemorySegment .ofArray (new byte [] {1 , 2 , 3 , 4 });
166
+ MemorySegment dst = MemorySegment .ofArray (new byte [] {1 , 2 , 3 , 4 });
167
+ assertThrows (IndexOutOfBoundsException .class , () ->
168
+ MemorySegment .copy (src , JAVA_BYTE , -1 , dst , JAVA_BYTE , 0 , 4 )
169
+ );
170
+ assertThrows (IndexOutOfBoundsException .class , () ->
171
+ MemorySegment .copy (src , JAVA_BYTE , 0 , dst , JAVA_BYTE , -1 , 4 )
172
+ );
173
+ assertThrows (IndexOutOfBoundsException .class , () ->
174
+ MemorySegment .copy (src , JAVA_BYTE , 0 , dst , JAVA_BYTE , 0 , -1 )
175
+ );
176
+ }
177
+
178
+ @ Test
179
+ public void testCopyFromArrayWithNegativeValues () {
180
+ MemorySegment src = MemorySegment .ofArray (new byte [] {1 , 2 , 3 , 4 });
181
+ byte [] dst = new byte [] {1 , 2 , 3 , 4 };
182
+ assertThrows (IndexOutOfBoundsException .class , () ->
183
+ MemorySegment .copy (src , JAVA_BYTE , -1 , dst , 0 , 4 )
184
+ );
185
+ assertThrows (IndexOutOfBoundsException .class , () ->
186
+ MemorySegment .copy (src , JAVA_BYTE , 0 , dst , -1 , 4 )
187
+ );
188
+ assertThrows (IndexOutOfBoundsException .class , () ->
189
+ MemorySegment .copy (src , JAVA_BYTE , 0 , dst , 0 , -1 )
190
+ );
191
+ }
192
+
193
+ @ Test
194
+ public void testCopyToArrayWithNegativeValues () {
195
+ byte [] src = new byte [] {1 , 2 , 3 , 4 };
196
+ MemorySegment dst = MemorySegment .ofArray (new byte [] {1 , 2 , 3 , 4 });
197
+ assertThrows (IndexOutOfBoundsException .class , () ->
198
+ MemorySegment .copy (src , -1 , dst , JAVA_BYTE , 0 , 4 )
199
+ );
200
+ assertThrows (IndexOutOfBoundsException .class , () ->
201
+ MemorySegment .copy (src , 0 , dst , JAVA_BYTE , -1 , 4 )
202
+ );
203
+ assertThrows (IndexOutOfBoundsException .class , () ->
204
+ MemorySegment .copy (src , 0 , dst , JAVA_BYTE , 0 , -1 )
205
+ );
206
+ }
207
+
148
208
enum Type {
149
209
// Byte
150
210
BYTE (byte .class , JAVA_BYTE , i -> (byte )i ),
0 commit comments