Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PictFormat assignment error in X11 libraries #549

Merged
merged 1 commit into from
Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,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);
}
}