aboutsummaryrefslogtreecommitdiff
path: root/jgvariant-ostree/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'jgvariant-ostree/src/test')
-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);
}