1 | /* |
2 | * Win32VerifierTest.java |
3 | * |
4 | * Created on 16.09.2004 |
5 | * |
6 | * eaio: NativeCall - calling operating system methods from Java |
7 | * Copyright (c) 2004-2006 Johann Burkard (<mailto:jb@eaio.com>) |
8 | * <http://eaio.com> |
9 | * |
10 | * Permission is hereby granted, free of charge, to any person obtaining a |
11 | * copy of this software and associated documentation files (the "Software"), |
12 | * to deal in the Software without restriction, including without limitation |
13 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
14 | * and/or sell copies of the Software, and to permit persons to whom the |
15 | * Software is furnished to do so, subject to the following conditions: |
16 | * |
17 | * The above copyright notice and this permission notice shall be included |
18 | * in all copies or substantial portions of the Software. |
19 | * |
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
21 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
23 | * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
24 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
25 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
26 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
27 | * |
28 | */ |
29 | package com.eaio.nativecall; |
30 | import junit.framework.TestCase; |
31 | |
32 | import com.eaio.nativecall.Win32Verifier; |
33 | |
34 | /** |
35 | * Test case for the {@link com.eaio.nativecall.Win32Verifier} class. |
36 | * |
37 | * @author <a href="mailto:jb@eaio.com">Johann Burkard</a> |
38 | * @version $Id: Win32VerifierTest.java,v 1.2 2006/01/05 19:57:07 grnull Exp $ |
39 | */ |
40 | public class Win32VerifierTest extends TestCase { |
41 | |
42 | /** |
43 | * Constructor for Win32VerifierTest. |
44 | * @param arg0 |
45 | */ |
46 | public Win32VerifierTest(String arg0) { |
47 | super(arg0); |
48 | } |
49 | |
50 | public static void main(String[] args) { |
51 | junit.awtui.TestRunner.run(Win32VerifierTest.class); |
52 | } |
53 | |
54 | public void testVerifyModuleName() { |
55 | Win32Verifier ver = new Win32Verifier(); |
56 | |
57 | assertEquals("kernel32", ver.verifyModuleName(null)); |
58 | assertEquals("kernel32", ver.verifyModuleName("")); |
59 | |
60 | String module = "blabla.dll"; |
61 | assertTrue(module == ver.verifyModuleName(module)); |
62 | |
63 | module = "bla\\blorb.dll"; |
64 | assertTrue(module == ver.verifyModuleName(module)); |
65 | |
66 | module = "c:/bla/blorb/blub\\bla.dll"; |
67 | assertEquals( |
68 | "c:\\bla\\blorb\\blub\\bla.dll", |
69 | ver.verifyModuleName(module)); |
70 | } |
71 | |
72 | public void testVerifyFunctionName() { |
73 | Win32Verifier ver = new Win32Verifier(); |
74 | |
75 | try { |
76 | ver.verifyFunctionName(null); |
77 | fail("Did not throw NPE."); |
78 | } |
79 | catch (NullPointerException ex) {} |
80 | |
81 | try { |
82 | ver.verifyFunctionName(""); |
83 | fail("Did not throw NPE."); |
84 | } |
85 | catch (NullPointerException ex) {} |
86 | |
87 | String function = "GetProcessId"; |
88 | assertTrue(function == ver.verifyFunctionName(function)); |
89 | } |
90 | |
91 | public void testGetDefaultModule() { |
92 | Win32Verifier ver = new Win32Verifier(); |
93 | assertEquals("kernel32", ver.getDefaultModule()); |
94 | } |
95 | |
96 | public void testHandleString() { |
97 | Win32Verifier ver = new Win32Verifier(); |
98 | |
99 | String bla = "blorb"; |
100 | |
101 | assertTrue(ver.handleString(bla, "kernel32", "Blub") instanceof byte[]); |
102 | assertEquals( |
103 | 6, |
104 | ((byte[]) ver.handleString(bla, "kernel32", "Blub")).length); |
105 | assertTrue( |
106 | ver.handleString(bla, "kernel32", "BlubA") instanceof byte[]); |
107 | assertEquals( |
108 | 6, |
109 | ((byte[]) ver.handleString(bla, "kernel32", "BlubA")).length); |
110 | |
111 | assertTrue( |
112 | ver.handleString(bla, "kernel32", "BlubW") instanceof char[]); |
113 | assertEquals( |
114 | 6, |
115 | ((char[]) ver.handleString(bla, "kernel32", "BlubW")).length); |
116 | } |
117 | |
118 | } |