1
2
3
4 package net.sf.ovanttasks.ovnative.win32;
5
6 import static org.junit.Assert.*;
7
8 import java.io.File;
9
10 import org.junit.After;
11 import org.junit.Before;
12 import org.junit.BeforeClass;
13 import org.junit.Test;
14
15 public class LnkFileTest {
16
17 LnkFile lnkFile = null;
18 File file = null;
19
20 @BeforeClass
21 public static void setUpClass() throws Exception {
22
23 OvNativeLibLoader.loadLibWithoutVersion();
24 }
25
26 @Before
27 public void setUp() throws Exception {
28
29 file = File.createTempFile("test", ".lnk");
30 file.deleteOnExit();
31 lnkFile = new LnkFile(file, false);
32 }
33
34 @After
35 public void tearDown() throws Exception {
36
37 if (file.exists()) {
38 file.delete();
39 }
40 file = null;
41 if (lnkFile.getSrcFile().exists()) {
42 lnkFile.getSrcFile().delete();
43 }
44 lnkFile = null;
45 }
46
47
48
49
50 @Test
51 public void testArguments() throws Exception {
52 System.out.println("testArguments");
53 lnkFile.setArguments("-h test1 -d test2");
54 lnkFile.save();
55
56 assertEquals(lnkFile.getArguments(), loadTestFile().getArguments());
57 }
58
59 LnkFile loadTestFile() {
60 System.out.println("getTestFile");
61 LnkFile result = new LnkFile(lnkFile.getSrcFile(), true);
62 return result;
63 }
64
65
66
67
68
69 @Test
70 public void testGetLnkFile() throws Exception {
71 System.out.println("testGetFolder");
72 lnkFile.save();
73 assertEquals(lnkFile.getSrcFile().getAbsolutePath(), loadTestFile().getSrcFile().getAbsolutePath());
74 }
75
76
77
78
79
80 @Test
81 public void testSetDescription() throws Exception {
82 System.out.println("testSetDescription");
83 lnkFile.setToolTipText("desc");
84 lnkFile.save();
85 }
86
87
88
89
90
91 @Test
92 public void testSetPath() throws Exception {
93 System.out.println("testSetPath");
94 lnkFile.setTargetFile("C:\\test.exe");
95 lnkFile.save();
96
97 assertEquals(lnkFile.getTargetFile(), loadTestFile().getTargetFile());
98 }
99
100
101
102
103
104 @Test
105 public void testSetWorkingDirectory() throws Exception {
106 System.out.println("testSetWorkingDirectory");
107 lnkFile.setWorkingDirectory(Win32.getWindowsDirectory());
108 lnkFile.save();
109
110 assertEquals(lnkFile.getWorkingDirectory(), loadTestFile().getWorkingDirectory());
111 }
112
113
114
115
116
117 @Test
118 public void testSetIcon() throws Exception {
119 System.out.println("testSetIconLocation");
120 lnkFile.setIcon("desc", 0);
121 lnkFile.save();
122 assertEquals(lnkFile.getIconLocation(), loadTestFile().getIconLocation());
123 assertEquals(lnkFile.getIconIndex(), loadTestFile().getIconIndex());
124 }
125
126 @Test
127 public void testUTF8File() throws Exception {
128 System.out.println("testUTF8File");
129 File utf8File = File.createTempFile("ÄÖÜäöü", ".txt");
130 utf8File.deleteOnExit();
131
132
133 String strFileName = utf8File.getName();
134 String strFilePath = utf8File.getParentFile().getAbsolutePath();
135 String strTargetPath = utf8File.getAbsolutePath();
136
137 LnkFile shortCut = new LnkFile(strFilePath, strFileName, false);
138 shortCut.setTargetFile(strTargetPath);
139 shortCut.save();
140
141 assertTrue("link file does not exists: " + shortCut.getSrcFile().getAbsolutePath(),
142 shortCut.getSrcFile().exists());
143 }
144
145 @Test
146 public void testUTF16File() throws Exception {
147 System.out.println("testUTF16File");
148
149 File utf16File = File.createTempFile("48_\uFEBA_511", ".txt");
150 utf16File.deleteOnExit();
151 String strFileName = utf16File.getName();
152 String strFilePath = utf16File.getParentFile().getAbsolutePath();
153 String strTargetPath = utf16File.getAbsolutePath();
154
155 LnkFile shortCut = new LnkFile(strFilePath, strFileName, false);
156 shortCut.setTargetFile(strTargetPath);
157 shortCut.save();
158
159 assertTrue("link file does not exists: " + shortCut.getSrcFile().getAbsolutePath(),
160 shortCut.getSrcFile().exists());
161 }
162
163 @Test
164 public void testResolve() throws Exception {
165 System.out.println("testResolve");
166 File resolveFile = File.createTempFile("Roxes_LnkFileTest_testResolve",
167 ".txt");
168 resolveFile.deleteOnExit();
169 String strFileName = resolveFile.getName();
170 String strFilePath = resolveFile.getParentFile().getAbsolutePath();
171 String strTargetPath = resolveFile.getAbsolutePath();
172
173 LnkFile shortCut = new LnkFile(strFilePath, strFileName, false);
174 shortCut.setTargetFile(strTargetPath);
175 shortCut.save();
176 shortCut.resolve
177
178
179 ();
180 }
181 }