-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kotlin: throw exception rather than returning null from getMappedRange()
In API review it was pointed out that Kotlin APIs should not use null returns when a request is invalid. Bug: 381392576 Test: BufferTest.* Change-Id: Iaf9b15b1083d3c73ee6e26047339b4b0435fc357 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/218594 Commit-Queue: Alex Benton <[email protected]> Reviewed-by: Alex Benton <[email protected]>
- Loading branch information
1 parent
de761f3
commit 6261813
Showing
2 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tools/android/webgpu/src/androidTest/java/android/dawn/BufferTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package android.dawn | ||
|
||
import org.junit.Assert.assertThrows | ||
import org.junit.Test | ||
|
||
class BufferTest { | ||
@Test | ||
/** | ||
* Test that calling getMappedRange() on a mapped buffer does not raise an exception. | ||
*/ | ||
fun bufferMapTest() { | ||
dawnTestLauncher() { device -> | ||
device.createBuffer( | ||
BufferDescriptor( | ||
usage = BufferUsage.Vertex, | ||
size = 1024, | ||
mappedAtCreation = true | ||
) | ||
).apply { | ||
getMappedRange(size = size) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
/** | ||
* Test that calling getMappedRange() on a non-mapped buffer raises an exception. | ||
*/ | ||
fun bufferMapFailureTest() { | ||
dawnTestLauncher() { device -> | ||
assertThrows(Error::class.java) { | ||
device.createBuffer( | ||
BufferDescriptor( | ||
usage = BufferUsage.Vertex, | ||
size = 1024, | ||
mappedAtCreation = false | ||
) | ||
).apply { | ||
getMappedRange(size = size) | ||
} | ||
} | ||
} | ||
} | ||
} |