Make Kotlin API object constructors private. This prevents direct instantiation of these objects from Java/Kotlin code, as they should only be created via the C++ API. Convert Texture bad width unit test to integration test. Bug: b/373607496 Change-Id: Iaf52b61815b0b84a0637656abe09c490b0713257 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/268195 Reviewed-by: Jim Blackler <jimblackler@google.com> Commit-Queue: Tarun Saini <sainitarun@google.com>
diff --git a/generator/templates/art/api_kotlin_object.kt b/generator/templates/art/api_kotlin_object.kt index 614f287..dbc8475 100644 --- a/generator/templates/art/api_kotlin_object.kt +++ b/generator/templates/art/api_kotlin_object.kt
@@ -43,7 +43,7 @@ {% if doc_str | trim %} {{ generate_simple_kdoc(doc_str) }} {% endif %} -public class {{ kotlin_name(obj) }}(public val handle: Long): AutoCloseable { +public class {{ kotlin_name(obj) }} private constructor(public val handle: Long): AutoCloseable { {% set all_method_info = object_info.methods if object_info else {} %} {% for method in obj.methods if include_method(obj, method) %} //* Generating KDocs
diff --git a/tools/android/webgpu/src/androidTest/java/androidx/webgpu/TextureTest.kt b/tools/android/webgpu/src/androidTest/java/androidx/webgpu/TextureTest.kt index 6cc9b2a..ed82d6d 100644 --- a/tools/android/webgpu/src/androidTest/java/androidx/webgpu/TextureTest.kt +++ b/tools/android/webgpu/src/androidTest/java/androidx/webgpu/TextureTest.kt
@@ -1,8 +1,10 @@ package androidx.webgpu import androidx.test.filters.SmallTest +import androidx.webgpu.helper.DawnException import androidx.webgpu.helper.ValidationException import androidx.webgpu.helper.WebGpu +import androidx.webgpu.helper.createBitmap import androidx.webgpu.helper.createWebGpu import kotlinx.coroutines.runBlocking import org.junit.After @@ -119,4 +121,22 @@ encoder.close() } } + + /** + * Verifies that creating a bitmap from a texture with an invalid width fails. + */ + @Test + fun createBitmap_withInvalidWidth_fails() { + val descriptor = TextureDescriptor( + size = Extent3D(width = 65, height = 16, depthOrArrayLayers = 1), + format = TextureFormat.RGBA8Unorm, + usage = TextureUsage.CopySrc + ) + val texture = device.createTexture(descriptor) + assertThrows(DawnException::class.java) { + runBlocking { + texture.createBitmap(device) + } + } + } } \ No newline at end of file
diff --git a/tools/android/webgpu/src/test/java/androidx/webgpu/TexturesTest.kt b/tools/android/webgpu/src/test/java/androidx/webgpu/TexturesTest.kt deleted file mode 100644 index edc9c1b..0000000 --- a/tools/android/webgpu/src/test/java/androidx/webgpu/TexturesTest.kt +++ /dev/null
@@ -1,26 +0,0 @@ -package androidx.webgpu - -import androidx.webgpu.helper.DawnException -import androidx.webgpu.helper.createBitmap -import kotlin.test.assertFailsWith -import kotlinx.coroutines.test.runTest -import org.junit.Test -import org.mockito.Mockito.doReturn -import org.mockito.Mockito.spy -import org.mockito.kotlin.mock -import org.mockito.kotlin.whenever - -class TexturesTest { - - @Test - @kotlinx.coroutines.ExperimentalCoroutinesApi - fun testBadWidthIsCaught() = runTest { - val mockDevice = mock<GPUDevice>() - val partialMockTexture = spy(GPUTexture(0)) - - doReturn(65).whenever(partialMockTexture).width - assertFailsWith<DawnException>{ - partialMockTexture.createBitmap(mockDevice) - } - } -}