aboutsummaryrefslogtreecommitdiff
path: root/jgvariant-ostree/src
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2023-12-10 20:29:35 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2023-12-10 20:32:21 +0100
commitdf853ef46a9c12d319bf824ac106a411f5eddabd (patch)
treef7e0112d7ff160c12186ba7d7ec4671a6487aeeb /jgvariant-ostree/src
parent3ad12086acde4cfa9d346938e876947bde6305dc (diff)
Add property-based tests and fix the bugs discovered.
Change-Id: I8deb1a7d75078c037714541d8f6f656052c2476c
Diffstat (limited to 'jgvariant-ostree/src')
-rw-r--r--jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderPropertyTest.java66
-rw-r--r--jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java14
2 files changed, 71 insertions, 9 deletions
diff --git a/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderPropertyTest.java b/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderPropertyTest.java
new file mode 100644
index 0000000..acd11c4
--- /dev/null
+++ b/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderPropertyTest.java
@@ -0,0 +1,66 @@
+package eu.mulk.jgvariant.ostree;
+
+import eu.mulk.jgvariant.core.Decoder;
+import java.util.Map;
+import net.jqwik.api.*;
+
+@SuppressWarnings("java:S2187")
+class OstreeDecoderPropertyTest {
+
+ @Group
+ class SummaryRoundtripLaw implements RoundtripLaw<Summary> {
+
+ @Override
+ public Decoder<Summary> decoder() {
+ return Summary.decoder();
+ }
+
+ @Override
+ public Arbitrary<Summary> anyT() {
+ return anySummary();
+ }
+ }
+
+ interface RoundtripLaw<T> {
+
+ @Property
+ default boolean roundtripsWell(@ForAll(value = "anyT") T entityLeft) {
+ var decoder = decoder();
+ var bytes = decoder.encode(entityLeft);
+ var entityRight = decoder.decode(bytes);
+ return entityLeft.equals(entityRight);
+ }
+
+ Decoder<T> decoder();
+
+ @Provide
+ Arbitrary<T> anyT();
+ }
+
+ @Provide
+ Arbitrary<Summary> anySummary() {
+ return Combinators.combine(anySummaryEntry().list(), anyMetadata()).as(Summary::new);
+ }
+
+ @Provide
+ Arbitrary<Metadata> anyMetadata() {
+ return Arbitraries.of(new Metadata(Map.of()));
+ }
+
+ @Provide
+ Arbitrary<Summary.Entry> anySummaryEntry() {
+ return Combinators.combine(Arbitraries.strings(), anySummaryEntryValue())
+ .as(Summary.Entry::new);
+ }
+
+ @Provide
+ Arbitrary<Summary.Entry.Value> anySummaryEntryValue() {
+ return Combinators.combine(Arbitraries.integers(), anyChecksum(), anyMetadata())
+ .as(Summary.Entry.Value::new);
+ }
+
+ @Provide
+ Arbitrary<Checksum> anyChecksum() {
+ return Arbitraries.of(new Checksum(new ByteString(new byte[32])));
+ }
+}
diff --git a/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java b/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java
index 4465d02..793c5a5 100644
--- a/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java
+++ b/jgvariant-ostree/src/test/java/eu/mulk/jgvariant/ostree/OstreeDecoderTest.java
@@ -110,10 +110,9 @@ class OstreeDecoderTest {
summary.metadata().fields()));
var encoded = decoder.encode(summary);
+
input.rewind();
assertEquals(input, encoded);
-
- System.out.println(summary);
}
@Test
@@ -123,10 +122,9 @@ class OstreeDecoderTest {
var commit = decoder.decode(input);
var encoded = decoder.encode(commit);
+
input.rewind();
assertEquals(input, encoded);
-
- System.out.println(commit);
}
@Test
@@ -136,10 +134,9 @@ class OstreeDecoderTest {
var dirTree = decoder.decode(input);
var encoded = decoder.encode(dirTree);
+
input.rewind();
assertEquals(input, encoded);
-
- System.out.println(dirTree);
}
@Test
@@ -149,10 +146,9 @@ class OstreeDecoderTest {
var dirMeta = decoder.decode(ByteBuffer.wrap(dirMetaBytes));
var encoded = decoder.encode(dirMeta);
+
input.rewind();
assertEquals(input, encoded);
-
- System.out.println(dirMeta);
}
@Test
@@ -160,9 +156,9 @@ class OstreeDecoderTest {
var decoder = DeltaSuperblock.decoder();
var input = ByteBuffer.wrap(deltaSuperblockBytes);
var deltaSuperblock = decoder.decode(input);
- System.out.println(deltaSuperblock);
var encoded = decoder.encode(deltaSuperblock);
+
input.rewind();
assertEquals(input, encoded);
}