Skip to content

Commit

Permalink
Merge pull request #40 from bailuk/dev/properties
Browse files Browse the repository at this point in the history
Add gui tests
  • Loading branch information
bailuk authored Feb 15, 2024
2 parents e4cd7d7 + 707db00 commit cddc7a9
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-on-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

env:
JAVA_TOOL_OPTIONS: '-Dfile.encoding=UTF8'
JAVA_TOOL_OPTIONS: '-Dfile.encoding=UTF8 -Djava-gtk.headless=true'

jobs:
build:
Expand Down
25 changes: 25 additions & 0 deletions ci/ubuntu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# A Ubuntu based build image
#
# This should be as identical as possible with the official GitHub Actions Ubuntu image
# https://github.com/actions/runner-images
#
# Based on https://hub.docker.com/_/ubuntu/

# podman build -f Dockerfile -t build-on-ubuntu
# podman run -it --name build-on-ubuntu build-on-ubuntu:latest
# => ./clone-and-build.sh

FROM docker.io/ubuntu:latest
LABEL version="0.1.0"

ENV JAVA_TOOL_OPTIONS "-Dfile.encoding=UTF8"

COPY clone-and-build.sh clone-and-build.sh
RUN chmod +x clone-and-build.sh

RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get -y install git
RUN apt-get -y install openjdk-11-jdk-headless
RUN apt-get -y install libgtk-4-1
RUN apt-get -y clean
9 changes: 9 additions & 0 deletions ci/ubuntu/clone-and-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

test -d java-gtk || git clone "https://github.com/bailuk/java-gtk.git" || exit 1

cd java-gtk || exit 1
git pull || exit 1

./gradlew generate || exit 1
./gradlew build
2 changes: 0 additions & 2 deletions java-gtk/src/main/java/ch/bailu/gtk/type/PropertyHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public Str getStrProperty(String name) {
return value.getString();
}



public Pointer getObjectProperty(String name) {
var value = initValue(Object.getTypeID());
getProperty(name, value);
Expand Down
68 changes: 67 additions & 1 deletion java-gtk/src/test/java/ch/bailu/gtk/TestPropertyAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,34 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;

import ch.bailu.gtk.gdk.Display;
import ch.bailu.gtk.gio.ListStore;
import ch.bailu.gtk.glib.Glib;
import ch.bailu.gtk.gtk.Box;
import ch.bailu.gtk.gtk.Button;
import ch.bailu.gtk.gtk.Gtk;
import ch.bailu.gtk.gtk.Orientation;
import ch.bailu.gtk.gtk.TextTag;
import ch.bailu.gtk.type.Str;

public class TestPropertyAccess {
public static boolean gtkInit() {
if ("true".equals(System.getProperty("java-gtk.headless"))) {
return false;
} else {
return Gtk.initCheck() && Display.getDefault().isNotNull(); // Does not work inside Windows container
}
}

public static boolean checkVersion() {
return Glib.checkVersion(2, 74, 0).isNull();
}

@Test
public void testPropertyAccess() {
@EnabledIf("checkVersion")
public void testPropertyAccessListStore() {
var listStore = new ListStore(TextTag.getTypeID());
var textTag = new TextTag("test");

Expand All @@ -22,10 +43,55 @@ public void testPropertyAccess() {
var textTagGet = new TextTag(listStore.asListModel().getItem(0).cast());
assertEquals("test", textTagGet.getStringProperty("name"));
assertEquals("test", textTag.getStringProperty("name"));
}

@Test
public void testPropertyAccessTextTag() {
var textTag = new TextTag("test");
assertEquals("test", textTag.getStringProperty("name"));

textTag.setBooleanProperty("accumulative-margin", false);
assertFalse(textTag.getBooleanProperty("accumulative-margin"));
textTag.setBooleanProperty("accumulative-margin", true);
assertTrue(textTag.getBooleanProperty("accumulative-margin"));
}

@Test
@EnabledIf("gtkInit")
public void testPropertyAccessButton() {
var button = new Button();
var label = new Str("test2");

button.setStringProperty("label", "test");
assertEquals("test", button.getLabel().toString());
assertEquals("test", button.getStringProperty("label"));

button.setStrProperty("label", label);
assertEquals("test2", button.getLabel().toString());

assertTrue(button.getChild().isNotNull());
assertTrue(button.getObjectProperty("child").isNotNull());

assertEquals(button.getChild(), button.getObjectProperty("child"));
}

@Test
@EnabledIf("gtkInit")
public void testPropertyAccessBox() {
var box = new Box(Orientation.HORIZONTAL, 5);

int spacing = box.getIntProperty("spacing");
assertEquals(5, spacing);

box.setIntProperty("spacing", 10);
assertEquals(10, box.getSpacing());

box.setHomogeneous(false);
assertEquals(box.getHomogeneous(), box.getBooleanProperty("homogeneous"));
assertFalse(box.getHomogeneous());

box.setBooleanProperty("homogeneous", true);
assertEquals(box.getCanFocus(), box.getBooleanProperty("homogeneous"));
assertTrue(box.getHomogeneous());
}
}

0 comments on commit cddc7a9

Please sign in to comment.