|
| 1 | +/* |
| 2 | +This file is licensed to you under the Apache License, Version 2.0 |
| 3 | +(http://www.apache.org/licenses/LICENSE-2.0) or the MIT license |
| 4 | +(http://opensource.org/licenses/MIT), at your option. |
| 5 | +
|
| 6 | +Unless required by applicable law or agreed to in writing, this software is |
| 7 | +distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF |
| 8 | +ANY KIND, either express or implied. See the LICENSE-MIT and LICENSE-APACHE |
| 9 | +files for the specific language governing permissions and limitations under |
| 10 | +each license. |
| 11 | +*/ |
| 12 | +package org.contentauth.c2pa |
| 13 | + |
| 14 | +import android.content.Context |
| 15 | +import androidx.test.ext.junit.runners.AndroidJUnit4 |
| 16 | +import androidx.test.platform.app.InstrumentationRegistry |
| 17 | +import kotlinx.coroutines.runBlocking |
| 18 | +import org.contentauth.c2pa.test.shared.ManifestTests |
| 19 | +import org.junit.Test |
| 20 | +import org.junit.runner.RunWith |
| 21 | +import java.io.File |
| 22 | +import kotlin.test.assertTrue |
| 23 | + |
| 24 | +/** Android instrumented tests for Manifest definition types. */ |
| 25 | +@RunWith(AndroidJUnit4::class) |
| 26 | +class AndroidManifestTests : ManifestTests() { |
| 27 | + |
| 28 | + private val targetContext = InstrumentationRegistry.getInstrumentation().targetContext |
| 29 | + |
| 30 | + override fun getContext(): Context = targetContext |
| 31 | + |
| 32 | + override fun loadResourceAsBytes(resourceName: String): ByteArray = |
| 33 | + ResourceTestHelper.loadResourceAsBytes(resourceName) |
| 34 | + |
| 35 | + override fun loadResourceAsString(resourceName: String): String = |
| 36 | + ResourceTestHelper.loadResourceAsString(resourceName) |
| 37 | + |
| 38 | + override fun copyResourceToFile(resourceName: String, fileName: String): File = |
| 39 | + ResourceTestHelper.copyResourceToFile(targetContext, resourceName, fileName) |
| 40 | + |
| 41 | + @Test |
| 42 | + fun runTestMinimal() = runBlocking { |
| 43 | + val result = testMinimal() |
| 44 | + assertTrue(result.success, "Manifest Minimal test failed: ${result.message}") |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + fun runTestCreated() = runBlocking { |
| 49 | + val result = testCreated() |
| 50 | + assertTrue(result.success, "Manifest Created test failed: ${result.message}") |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + fun runTestEnumRendering() = runBlocking { |
| 55 | + val result = testEnumRendering() |
| 56 | + assertTrue(result.success, "Enum Rendering test failed: ${result.message}") |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + fun runTestRegionOfInterest() = runBlocking { |
| 61 | + val result = testRegionOfInterest() |
| 62 | + assertTrue(result.success, "Region of Interest test failed: ${result.message}") |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + fun runTestResourceRef() = runBlocking { |
| 67 | + val result = testResourceRef() |
| 68 | + assertTrue(result.success, "ResourceRef test failed: ${result.message}") |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + fun runTestHashedUri() = runBlocking { |
| 73 | + val result = testHashedUri() |
| 74 | + assertTrue(result.success, "HashedUri test failed: ${result.message}") |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + fun runTestUriOrResource() = runBlocking { |
| 79 | + val result = testUriOrResource() |
| 80 | + assertTrue(result.success, "UriOrResource test failed: ${result.message}") |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + fun runTestMassInit() = runBlocking { |
| 85 | + val result = testMassInit() |
| 86 | + assertTrue(result.success, "Mass Init test failed: ${result.message}") |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + fun runTestManifestToJson() = runBlocking { |
| 91 | + val result = testManifestToJson() |
| 92 | + assertTrue(result.success, "Manifest to JSON test failed: ${result.message}") |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + fun runTestShapeFactoryMethods() = runBlocking { |
| 97 | + val result = testShapeFactoryMethods() |
| 98 | + assertTrue(result.success, "Shape Factory Methods test failed: ${result.message}") |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + fun runTestManifestWithBuilder() = runBlocking { |
| 103 | + val result = testManifestWithBuilder() |
| 104 | + assertTrue(result.success, "Manifest with Builder test failed: ${result.message}") |
| 105 | + } |
| 106 | + |
| 107 | + @Test |
| 108 | + fun runTestAllAssertionTypes() = runBlocking { |
| 109 | + val result = testAllAssertionTypes() |
| 110 | + assertTrue(result.success, "All Assertion Types test failed: ${result.message}") |
| 111 | + } |
| 112 | + |
| 113 | + @Test |
| 114 | + fun runTestIngredients() = runBlocking { |
| 115 | + val result = testIngredients() |
| 116 | + assertTrue(result.success, "Ingredients test failed: ${result.message}") |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + fun runTestActionWithRegions() = runBlocking { |
| 121 | + val result = testActionWithRegions() |
| 122 | + assertTrue(result.success, "Action with Regions test failed: ${result.message}") |
| 123 | + } |
| 124 | + |
| 125 | + @Test |
| 126 | + fun runTestMalformedJson() = runBlocking { |
| 127 | + val result = testMalformedJson() |
| 128 | + assertTrue(result.success, "Malformed JSON test failed: ${result.message}") |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + fun runTestSpecialCharacters() = runBlocking { |
| 133 | + val result = testSpecialCharacters() |
| 134 | + assertTrue(result.success, "Special Characters test failed: ${result.message}") |
| 135 | + } |
| 136 | + |
| 137 | + @Test |
| 138 | + fun runTestCreatedFactory() = runBlocking { |
| 139 | + val result = testCreatedFactory() |
| 140 | + assertTrue(result.success, "Created Factory test failed: ${result.message}") |
| 141 | + } |
| 142 | + |
| 143 | + @Test |
| 144 | + fun runTestAllValidationStatusCodes() = runBlocking { |
| 145 | + val result = testAllValidationStatusCodes() |
| 146 | + assertTrue(result.success, "All Validation Status Codes test failed: ${result.message}") |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + fun runTestAllDigitalSourceTypes() = runBlocking { |
| 151 | + val result = testAllDigitalSourceTypes() |
| 152 | + assertTrue(result.success, "All Digital Source Types test failed: ${result.message}") |
| 153 | + } |
| 154 | +} |
0 commit comments