Skip to content

Commit

Permalink
Merge pull request #549 from java-native-access/fix-pictformat-struct
Browse files Browse the repository at this point in the history
Fix PictFormat assignment error in X11 libraries
  • Loading branch information
twall committed Dec 4, 2015
2 parents 7f3c757 + 539e731 commit 0519003
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Features

Bug Fixes
---------
* [#549](https://github.com/java-native-access/jna/pull/549): Fixed bug in types derived from XID - [@twall](https://github.com/twall).

Release 4.2.1
=============
Expand Down
17 changes: 17 additions & 0 deletions contrib/platform/src/com/sun/jna/platform/unix/X11.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,19 @@ public interface X11 extends Library {

class VisualID extends NativeLong {
private static final long serialVersionUID = 1L;
public static final VisualID None = null;
public VisualID() { this(0); }
public VisualID(long value) { super(value, true); }
protected boolean isNone(Object o) {
return o == null
|| (o instanceof Number
&& ((Number)o).longValue() == X11.None);
}
public Object fromNative(Object nativeValue, FromNativeContext context) {
if (isNone(nativeValue))
return None;
return new VisualID(((Number)nativeValue).longValue());
}
}

class XID extends NativeLong {
Expand Down Expand Up @@ -286,8 +297,14 @@ protected List getFieldOrder() {
}
class PictFormat extends XID {
private static final long serialVersionUID = 1L;
public static final PictFormat None = null;
public PictFormat(long value) { super(value); }
public PictFormat() { this(0); }
public Object fromNative(Object nativeValue, FromNativeContext context) {
if (isNone(nativeValue))
return None;
return new PictFormat(((Number)nativeValue).longValue());
}
}
class XRenderPictFormat extends Structure {
public PictFormat id;
Expand Down
36 changes: 36 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/unix/X11Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright (c) 2015 Timothy Wall, All Rights Reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* <p/>
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
package com.sun.jna.platform.unix;

import junit.framework.TestCase;

/**
* Exercise the {@link X11} class.
*
* @author twalljava@java.net
*/
// @SuppressWarnings("unused")
public class X11Test extends TestCase {

public void testXrender() {
X11.Xrender.XRenderPictFormat s = new X11.Xrender.XRenderPictFormat();
s.getPointer().setInt(0, 25);
s.read();
}

public static void main(java.lang.String[] argList) {
junit.textui.TestRunner.run(X11Test.class);
}
}


0 comments on commit 0519003

Please sign in to comment.