|
| 1 | +/* Copyright (c) 2007-2014 Timothy Wall, All Rights Reserved |
| 2 | + * |
| 3 | + * This library is free software; you can redistribute it and/or |
| 4 | + * modify it under the terms of the GNU Lesser General Public |
| 5 | + * License as published by the Free Software Foundation; either |
| 6 | + * version 2.1 of the License, or (at your option) any later version. |
| 7 | + * |
| 8 | + * This library is distributed in the hope that it will be useful, |
| 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | + * Lesser General Public License for more details. |
| 12 | + */ |
| 13 | +package com.sun.jna.platform.win32; |
| 14 | + |
| 15 | +import com.sun.jna.Memory; |
| 16 | +import com.sun.jna.Native; |
| 17 | +import com.sun.jna.Pointer; |
| 18 | +import junit.framework.TestCase; |
| 19 | + |
| 20 | +public class WTypesTest extends TestCase { |
| 21 | + |
| 22 | + private static final String TEST_STRING = "input"; |
| 23 | + |
| 24 | + private static final Pointer TEST_POINTER = new Memory((TEST_STRING.length() + 1L) * Native.WCHAR_SIZE); |
| 25 | + |
| 26 | + static { |
| 27 | + TEST_POINTER.setWideString(0, TEST_STRING); |
| 28 | + } |
| 29 | + |
| 30 | + public void testLPOLESTRConstruction() { |
| 31 | + WTypes.LPOLESTR fromString = new WTypes.LPOLESTR(TEST_STRING); |
| 32 | + assertEquals(fromString.getValue(), TEST_STRING); |
| 33 | + WTypes.LPOLESTR empty = new WTypes.LPOLESTR(); |
| 34 | + assertNull(empty.getValue()); |
| 35 | + WTypes.LPOLESTR fromPointer = new WTypes.LPOLESTR(TEST_POINTER); |
| 36 | + assertEquals(fromPointer.getValue(), TEST_STRING); |
| 37 | + } |
| 38 | + |
| 39 | + public void testLPSTRConstruction() { |
| 40 | + WTypes.LPSTR instance = new WTypes.LPSTR(TEST_STRING); |
| 41 | + assertEquals(instance.getValue(), TEST_STRING); |
| 42 | + WTypes.LPSTR empty = new WTypes.LPSTR(); |
| 43 | + assertNull(empty.getValue()); |
| 44 | + WTypes.LPSTR fromPointer = new WTypes.LPSTR(TEST_POINTER); |
| 45 | + assertEquals(fromPointer.getValue(), TEST_STRING); |
| 46 | + } |
| 47 | + |
| 48 | + public void testLPWSTRConstruction() { |
| 49 | + WTypes.LPWSTR instance = new WTypes.LPWSTR(TEST_STRING); |
| 50 | + assertEquals(instance.getValue(), TEST_STRING); |
| 51 | + WTypes.LPWSTR empty = new WTypes.LPWSTR(); |
| 52 | + assertNull(empty.getValue()); |
| 53 | + WTypes.LPWSTR fromPointer = new WTypes.LPWSTR(TEST_POINTER); |
| 54 | + assertEquals(fromPointer.getValue(), TEST_STRING); |
| 55 | + } |
| 56 | + |
| 57 | + public static void main(String[] args) { |
| 58 | + junit.textui.TestRunner.run(WTypesTest.class); |
| 59 | + } |
| 60 | +} |
0 commit comments