summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/btr/proxy/search/desktop/win/DLLManagerTest.java
blob: 0711a8ce6fd5f80a2371fc04bdccfc6d57420fa8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.btr.proxy.search.desktop.win;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;

import com.btr.proxy.TestUtil;

/*****************************************************************************
 * Unit tests for DLL loading code.  
 * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
 ****************************************************************************/

@Ignore
public class DLLManagerTest {

	/*************************************************************************
	 * Reset system property at the end.
	 ************************************************************************/
	@AfterClass
	public static void teardown() {
		System.setProperty(DLLManager.LIB_DIR_OVERRIDE, "");
	}
	
	/*************************************************************************
	 * Test method 
	 * @throws IOException on error 
	 ************************************************************************/
	@Test
	public void testFindLibFileOverride() throws IOException {
		String path = TestUtil.class.getResource("/").getFile() + File.separator+"data"+File.separator+"win";
		System.setProperty(DLLManager.LIB_DIR_OVERRIDE, path);
		File actual = DLLManager.findLibFile();
		assertTrue(actual.getAbsolutePath().contains(path));
	}
	
	/*************************************************************************
	 * Test method 
	 * @throws IOException on error 
	 ************************************************************************/
	@Test
	public void testFindLibFileDefault() throws IOException {
		System.setProperty(DLLManager.LIB_DIR_OVERRIDE, "");
		File actual = DLLManager.findLibFile();
		assertTrue(actual.getAbsolutePath().contains("lib"+File.separator));
	}

	/*************************************************************************
	 * Test method 
	 * @throws IOException on error 
	 ************************************************************************/
	@Test
	public void testCleanupTempFiles() throws IOException {
		File f1 = File.createTempFile(DLLManager.TEMP_FILE_PREFIX+"_ABC", DLLManager.DLL_EXTENSION);
		assertTrue(f1.exists());
		DLLManager.cleanupTempFiles();
		assertFalse(f1.exists());
	}
	
	/*************************************************************************
	 * Test method 
	 * @throws IOException on error 
	 ************************************************************************/
//	@Test
//	public void testFileCopy() throws IOException {
//	    URL originalFile = DLLManagerTest.class.getResource("/lib/proxy_util_w32.dll");
//		File tempFile = File.createTempFile(DLLManager.TEMP_FILE_PREFIX, DLLManager.TEMP_FILE_PREFIX);
//		DLLManager.copy(originalFile.openStream(), new FileOutputStream(tempFile));
//		assertTrue(tempFile.exists() && tempFile.length() == originalFile.length());
//		tempFile.delete();
//	}

}