11package eu .neverblink .jelly .core .sparql
22
3- import com .google .protobuf .{ByteString , InvalidProtocolBufferException }
3+ import com .google .protobuf .{ByteString , InvalidProtocolBufferException , TextFormat }
44import eu .neverblink .jelly .core .proto .v1 .*
55import eu .neverblink .jelly .core .proto .v1 .sparql .*
6+ import eu .neverblink .jelly .core .proto .google .v1 .sparql as google
67import eu .neverblink .protoc .java .runtime .ProtoMessage
78import org .scalatest .matchers .should .Matchers
89import org .scalatest .wordspec .AnyWordSpec
@@ -12,6 +13,9 @@ import java.io.{ByteArrayInputStream, ByteArrayOutputStream, InputStream}
1213/** Tests for the generated Protobuf messages of Jelly-SPARQL: the serialization round-trips and the
1314 * auxiliary methods (clone, copyFrom, mergeFrom, clear, equals) that the encoder and decoder do
1415 * not exercise by themselves.
16+ *
17+ * This also tests the classes generated by Google's protoc-java, from the
18+ * core-sparql-protos-google module.
1519 */
1620class SparqlProtoSpec extends AnyWordSpec , Matchers :
1721
@@ -500,3 +504,51 @@ class SparqlProtoSpec extends AnyWordSpec, Matchers:
500504 a.mergeFrom(b) shouldBe merged
501505 }
502506 }
507+
508+ // Tests for the core-sparql-protos-google module. These also check that the two code generators
509+ // agree on the wire format.
510+ " proto.google.v1.sparql.SparqlResultsFrame" should {
511+ val cases = Seq (
512+ " frame with every field set" -> fullFrame,
513+ " frame with a datatype-monomorphic literal column" -> SparqlResultsFrame
514+ .newInstance()
515+ .setOptions(JellySparqlOptions .SMALL )
516+ .setRowCount(3 )
517+ .addVariables(SparqlVariable .newInstance().setName(" x" ).setColumnIndex(0 ))
518+ .addLiteralColumns(lexLiteralColumn),
519+ )
520+
521+ " round-trip in non-delimited binary form" when {
522+ for (name, frame) <- cases do
523+ s " a $name" in {
524+ val gFrame = google.SparqlResultsFrame .parseFrom(frame.toByteArray)
525+ SparqlResultsFrame .parseFrom(gFrame.toByteArray) shouldBe frame
526+ }
527+ }
528+
529+ " round-trip in delimited binary form" when {
530+ for (name, frame) <- cases do
531+ s " a $name" in {
532+ val out = ByteArrayOutputStream ()
533+ frame.writeDelimitedTo(out)
534+ val gFrame =
535+ google.SparqlResultsFrame .parseDelimitedFrom(ByteArrayInputStream (out.toByteArray))
536+ val gOut = ByteArrayOutputStream ()
537+ gFrame.writeDelimitedTo(gOut)
538+ SparqlResultsFrame .parseDelimitedFrom(
539+ ByteArrayInputStream (gOut.toByteArray),
540+ ) shouldBe frame
541+ }
542+ }
543+
544+ " round-trip the message in Text Format" when {
545+ for (name, frame) <- cases do
546+ s " a $name" in {
547+ val gFrame = google.SparqlResultsFrame .parseFrom(frame.toByteArray)
548+ val text = gFrame.toString
549+ val gFrame2 = TextFormat .parse(text, classOf [google.SparqlResultsFrame ])
550+ gFrame2 shouldBe gFrame
551+ SparqlResultsFrame .parseFrom(gFrame2.toByteArray) shouldBe frame
552+ }
553+ }
554+ }
0 commit comments