~ubuntu-branches/ubuntu/wily/libjna-java/wily-proposed

« back to all changes in this revision

Viewing changes to test/com/sun/jna/LibraryLoadTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-11-02 14:14:51 UTC
  • mfrom: (4.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20091102141451-j5hdwzzq5zwxrp4n
* New upstream release.
* Fixed debian/repack-source.sh to correctly use mktemp.
* Make libjna-java Depends on *-headless packages.
* Moved package under pkg-java control.
* Added debian/README.source to describe quilt.
* Added myself as Uploader.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
 
1
/* Copyright (c) 2007-2009 Timothy Wall, All Rights Reserved
2
2
 * 
3
3
 * This library is free software; you can redistribute it and/or
4
4
 * modify it under the terms of the GNU Lesser General Public
13
13
package com.sun.jna;
14
14
 
15
15
import java.awt.Frame;
 
16
import java.awt.GraphicsEnvironment;
16
17
import java.awt.Toolkit;
17
 
import java.awt.GraphicsEnvironment;
18
18
import java.io.File;
19
19
import java.io.FileInputStream;
20
20
import java.io.FileOutputStream;
26
26
    
27
27
    private static final String BUILDDIR =
28
28
        System.getProperty("jna.builddir", "build"
29
 
                           + (Native.POINTER_SIZE == 8 ? "-d64" : ""));
 
29
                           + (Platform.is64Bit() ? "-d64" : ""));
30
30
 
31
31
    public void testLoadJNALibrary() {
32
32
        assertTrue("Point size should never be zero", Pointer.SIZE > 0);
51
51
        int wcslen(WString wstr);
52
52
        int strlen(String str);
53
53
        int atol(String str);
 
54
 
 
55
        Pointer getpwuid(int uid);
 
56
        int geteuid();
54
57
    }
55
58
 
56
59
    public void testLoadAWTAfterJNA() {
 
60
        if (GraphicsEnvironment.isHeadless()) return;
 
61
 
57
62
        if (Pointer.SIZE > 0) {
58
63
            Toolkit.getDefaultToolkit();
59
64
        }
89
94
        String tmp = System.getProperty("java.io.tmpdir");
90
95
        String libName = System.mapLibraryName("jnidispatch");
91
96
        File src = new File(BUILDDIR + "/native", libName);
 
97
        assertTrue("Expected JNA native library at " + src + " is missing", src.exists());
 
98
 
92
99
        String newLibName = UNICODE;
93
100
        if (libName.startsWith("lib"))
94
101
            newLibName = "lib" + newLibName;
105
112
        dst.deleteOnExit();
106
113
        copy(src, dst);
107
114
        NativeLibrary.addSearchPath(UNICODE, tmp);
108
 
        NativeLibrary.getInstance(UNICODE);
 
115
        NativeLibrary nl = NativeLibrary.getInstance(UNICODE);
 
116
        nl.dispose();
109
117
    }
110
118
    
111
119
    public void testHandleObjectMethods() {
139
147
        }
140
148
    }
141
149
 
 
150
    // Ubuntu bug when arch-specific libc is active
 
151
    // Only fails on *some* functions
 
152
    public void testLoadProperCLibraryVersion() {
 
153
        if (Platform.isWindows()) return;
 
154
 
 
155
        CLibrary lib = (CLibrary)Native.loadLibrary("c", CLibrary.class);
 
156
        assertNotNull("Couldn't get current user",
 
157
                      lib.getpwuid(lib.geteuid()));
 
158
    }
 
159
    
142
160
    public static void main(String[] args) {
143
161
        junit.textui.TestRunner.run(LibraryLoadTest.class);
144
162
    }