-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
165e062
commit ba8dae7
Showing
15 changed files
with
278 additions
and
151 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 @@ | ||
/build |
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,33 @@ | ||
plugins { | ||
id("com.android.library") | ||
} | ||
|
||
android { | ||
namespace = "org.divviup.commontest" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
minSdk = 21 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation("com.squareup.okhttp3:mockwebserver:4.12.0") | ||
} |
Empty file.
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
39 changes: 39 additions & 0 deletions
39
divviup/commontest/src/main/java/org/divviup/commontest/MockAggregator.java
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,39 @@ | ||
package org.divviup.commontest; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Objects; | ||
|
||
import okhttp3.mockwebserver.MockResponse; | ||
import okhttp3.mockwebserver.MockWebServer; | ||
import okio.Buffer; | ||
|
||
public class MockAggregator { | ||
private static Buffer loadHpkeConfigList() throws IOException { | ||
Buffer hpkeConfigListBuffer; | ||
ClassLoader classLoader = Objects.requireNonNull(MockAggregator.class.getClassLoader()); | ||
try (InputStream is = classLoader.getResourceAsStream("hpke_config_list.bin")) { | ||
hpkeConfigListBuffer = new Buffer(); | ||
hpkeConfigListBuffer.readFrom(is); | ||
} | ||
return hpkeConfigListBuffer; | ||
} | ||
|
||
public static MockWebServer setupMockServer() throws IOException { | ||
Buffer hpkeConfigListBuffer = loadHpkeConfigList(); | ||
MockWebServer server = new MockWebServer(); | ||
server.enqueue( | ||
new MockResponse() | ||
.setHeader("Content-Type", "application/dap-hpke-config-list") | ||
.setBody(hpkeConfigListBuffer) | ||
); | ||
server.enqueue( | ||
new MockResponse() | ||
.setHeader("Content-Type", "application/dap-hpke-config-list") | ||
.setBody(hpkeConfigListBuffer) | ||
); | ||
server.enqueue(new MockResponse()); | ||
server.start(); | ||
return server; | ||
} | ||
} |
File renamed without changes.
128 changes: 0 additions & 128 deletions
128
divviup/src/androidTest/java/org/divviup/android/ExampleInstrumentedTest.java
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
divviup/src/androidTest/java/org/divviup/android/InstrumentedSmokeTest.java
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,80 @@ | ||
package org.divviup.android; | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.divviup.commontest.MockAggregator; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
|
||
import okhttp3.mockwebserver.MockWebServer; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class InstrumentedSmokeTest { | ||
private static final TaskId ZERO_TASK_ID = TaskId.parse("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); | ||
|
||
@Test | ||
public void smokeTestPrio3Count() throws IOException, InterruptedException { | ||
try (MockWebServer server = MockAggregator.setupMockServer()) { | ||
URI uri = server.url("/").uri(); | ||
Client<Boolean> client = Client.createPrio3Count(uri, uri, ZERO_TASK_ID, 300); | ||
client.sendMeasurement(true); | ||
|
||
basicUploadChecks(server); | ||
} | ||
} | ||
|
||
@Test | ||
public void smokeTestPrio3Sum() throws IOException, InterruptedException { | ||
try (MockWebServer server = MockAggregator.setupMockServer()) { | ||
URI uri = server.url("/").uri(); | ||
Client<Long> client = Client.createPrio3Sum(uri, uri, ZERO_TASK_ID, 300, 32); | ||
client.sendMeasurement(1000000L); | ||
|
||
basicUploadChecks(server); | ||
} | ||
} | ||
|
||
@Test | ||
public void smokeTestPrio3SumVec() throws IOException, InterruptedException { | ||
try (MockWebServer server = MockAggregator.setupMockServer()) { | ||
URI uri = server.url("/").uri(); | ||
Client<long[]> client = Client.createPrio3SumVec(uri, uri, ZERO_TASK_ID, 300, 10, 8, 12); | ||
client.sendMeasurement(new long[] {252L, 7L, 80L, 194L, 190L, 217L, 141L, 85L, 222L, 243L}); | ||
|
||
basicUploadChecks(server); | ||
} | ||
} | ||
|
||
@Test | ||
public void smokeTestPrio3Histogram() throws IOException, InterruptedException { | ||
try (MockWebServer server = MockAggregator.setupMockServer()) { | ||
URI uri = server.url("/").uri(); | ||
Client<Long> client = Client.createPrio3Histogram(uri, uri, ZERO_TASK_ID, 300, 5, 2); | ||
client.sendMeasurement(2L); | ||
|
||
basicUploadChecks(server); | ||
} | ||
} | ||
|
||
private static void basicUploadChecks(MockWebServer server) throws InterruptedException { | ||
RecordedRequest r1 = server.takeRequest(); | ||
assertEquals(r1.getMethod(), "GET"); | ||
assertEquals(r1.getPath(), "/hpke_config?task_id=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); | ||
|
||
RecordedRequest r2 = server.takeRequest(); | ||
assertEquals(r2.getMethod(), "GET"); | ||
assertEquals(r2.getPath(), "/hpke_config?task_id=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); | ||
|
||
RecordedRequest r3 = server.takeRequest(); | ||
assertEquals(r3.getMethod(), "PUT"); | ||
assertEquals(r3.getPath(), "/tasks/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/reports"); | ||
assertEquals(r3.getHeader("Content-Type"), "application/dap-report"); | ||
assertTrue(r3.getBody().size() > 0); | ||
} | ||
} |
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,18 @@ | ||
package android.util; | ||
|
||
public class Base64 { | ||
public static final int NO_PADDING = 1, NO_WRAP = 2, URL_SAFE = 8; | ||
private static final int DAP_BASE64_FLAGS = NO_PADDING | NO_WRAP | URL_SAFE; | ||
|
||
public static String encodeToString(byte[] input, int flags) { | ||
assert flags == DAP_BASE64_FLAGS; | ||
java.util.Base64.Encoder encoder = java.util.Base64.getUrlEncoder().withoutPadding(); | ||
return encoder.encodeToString(input); | ||
} | ||
|
||
public static byte[] decode(String str, int flags) { | ||
assert flags == DAP_BASE64_FLAGS; | ||
java.util.Base64.Decoder decoder = java.util.Base64.getUrlDecoder(); | ||
return decoder.decode(str); | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
divviup/src/test/java/org/divviup/android/ExampleUnitTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.