Skip to content

Commit

Permalink
Add hint for Graphviz that generated document is UTF-8
Browse files Browse the repository at this point in the history
  • Loading branch information
atextor committed Jan 22, 2024
1 parent 6366c2a commit 6d720bb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public Try<Void> generate( final OWLOntology ontology, final OutputStream output
LOG.trace( "Generated Graphviz document: {}", graphvizGraph );

final ThrowingConsumer<OutputStream, IOException> contentProvider = outputStream -> {
outputStream.write( graphvizGraph.getBytes() );
outputStream.write( graphvizGraph.getBytes( StandardCharsets.UTF_8 ) );
outputStream.flush();
if ( outputStream != System.out ) {
outputStream.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class GraphvizDocument implements Function<Configuration, String> {
private static final StringTemplate GRAPHVIZ_TEMPLATE = new StringTemplate( """
digraph G {
rankdir = ${rankdir}
charset = "utf-8"
bgcolor = "${bgcolor}"
color = "${fgcolor}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@
import net.jqwik.api.ForAll;
import net.jqwik.api.Property;
import net.jqwik.api.Provide;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.semanticweb.owlapi.model.IRI;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -207,19 +206,15 @@ Arbitrary<Set<GraphElement>> anyGraph() {
/**
* Tests that any Graphviz diagram that can be generated is actually syntactically valid, i.e., can be processed
* by Graphviz without errors.
* This property-based test is disabled on Windows. Since Graphviz documents are create that happen to contain specific
* symbols (e.g., the disjoint union symbol, ⚭) which are only representable in UTF-8 but not Windows-1252 or US-ASCII,
* Graphviz will refuse to render this document (because of "unknown tokens").
*
* @param graph the input graph
* @return true if it could successfully be rendered
*/
@Property
@DisabledOnOs( OS.WINDOWS )
public boolean everyGeneratedDiagramIsSyntacticallyValid( @ForAll( "anyGraph" ) final Set<GraphElement> graph ) {
final String graphvizDocument = graphvizGenerator.apply( graph.stream() ).apply( configuration );
final ThrowingConsumer<OutputStream, IOException> contentProvider = outputStream -> {
outputStream.write( graphvizDocument.getBytes() );
outputStream.write( graphvizDocument.getBytes( StandardCharsets.UTF_8 ) );
outputStream.flush();
outputStream.close();
};
Expand Down

0 comments on commit 6d720bb

Please sign in to comment.