summaryrefslogtreecommitdiffstats
path: root/src/junit/com/jogamp/common/net/AssetURLConnectionBase.java
blob: 80f9bd41a5211d6e454cc76e884283c0838579b5 (plain)
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
package com.jogamp.common.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.JarURLConnection;
import java.net.URLConnection;

import org.junit.Assert;

import com.jogamp.common.os.AndroidVersion;
import com.jogamp.common.util.IOUtil;
import com.jogamp.junit.util.JunitTracer;

public abstract class AssetURLConnectionBase extends JunitTracer {

    /** In gluegen-rt.jar */
    protected static final String test_asset_rt_url      = "asset:gluegen/info.txt";
    protected static final String test_asset_rt_entry    = "gluegen/info.txt";
    
    protected static final String test_asset_rt2_url     = "asset:/gluegen/info.txt";
    
    /** In gluegen.test.jar */
    protected static final String test_asset_test1_url   = "asset:gluegen-test/info.txt";
    protected static final String test_asset_test1_entry = "gluegen-test/info.txt";
    protected static final String test_asset_test2_rel   = "data/AssetURLConnectionTest.txt";
    protected static final String test_asset_test2a_url  = "asset:com/jogamp/common/net/data/AssetURLConnectionTest.txt";
    protected static final String test_asset_test2b_url  = "asset:/com/jogamp/common/net/data/AssetURLConnectionTest.txt";
    protected static final String test_asset_test2_entry = "com/jogamp/common/net/data/AssetURLConnectionTest.txt";
    protected static final String test_asset_test3_rel   = "RelativeData.txt";
    protected static final String test_asset_test3a_url  = "asset:com/jogamp/common/net/data/RelativeData.txt";
    protected static final String test_asset_test3b_url  = "asset:/com/jogamp/common/net/data/RelativeData.txt";
    protected static final String test_asset_test3_entry = "com/jogamp/common/net/data/RelativeData.txt";

    protected static void testAssetConnection(URLConnection c, String entry_name) throws IOException {
        Assert.assertNotNull(c);
        if(c instanceof AssetURLConnection) {
            final AssetURLConnection ac = (AssetURLConnection) c;
            Assert.assertEquals(entry_name, ac.getEntryName());
        } else if(c instanceof JarURLConnection) {
            final JarURLConnection jc = (JarURLConnection) c;
            if(AndroidVersion.isAvailable) {
                Assert.assertEquals("assets/"+entry_name, jc.getEntryName());
            } else {
                Assert.assertEquals(entry_name, jc.getEntryName());
            }
        }
        
        final BufferedReader reader = new BufferedReader(new InputStreamReader(c.getInputStream()));
        try {
            String line = null;
            int l = 0;
            while ((line = reader.readLine()) != null) {
                System.err.println(c.getURL()+":"+l+"> "+line);
                l++;
            }
        } finally {
            IOUtil.close(reader, false);
        }
    }   
}