~ubuntu-branches/ubuntu/raring/scilab/raring-proposed

« back to all changes in this revision

Viewing changes to modules/hdf5/tests/java/org/scilab/tests/modules/hdf5/testScilabList.java

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-08-30 14:42:38 UTC
  • mfrom: (1.4.7)
  • Revision ID: package-import@ubuntu.com-20120830144238-c1y2og7dbm7m9nig
Tags: 5.4.0-beta-3-1~exp1
* New upstream release
* Update the scirenderer dep
* Get ride of libjhdf5-java dependency

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.scilab.tests.modules.hdf5;
2
 
/*
3
 
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4
 
 * Copyright (C) 2009 - DIGITEO - Bruno JOFRET
5
 
 *
6
 
 * This file must be used under the terms of the CeCILL.
7
 
 * This source file is licensed as described in the file COPYING, which
8
 
 * you should have received as part of this distribution.  The terms
9
 
 * are also available at
10
 
 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11
 
 *
12
 
 */
13
 
import ncsa.hdf.hdf5lib.exceptions.HDF5Exception;
14
 
import ncsa.hdf.hdf5lib.exceptions.HDF5LibraryException;
15
 
 
16
 
import org.scilab.modules.hdf5.H5ScilabConstant;
17
 
import org.scilab.modules.hdf5.read.H5Read;
18
 
import org.scilab.modules.hdf5.write.H5Write;
19
 
import org.scilab.modules.types.ScilabDouble;
20
 
import org.scilab.modules.types.ScilabList;
21
 
import org.scilab.modules.types.ScilabString;
22
 
import org.junit.*;
23
 
import org.junit.*;
24
 
 
25
 
import java.io.File;
26
 
 
27
 
public class testScilabList {
28
 
    private final static String tempDir = System.getProperty("java.io.tmpdir");
29
 
 
30
 
    @Test
31
 
    public void testEmptyList() throws NullPointerException, HDF5LibraryException, HDF5Exception {
32
 
        ScilabList data = new ScilabList();
33
 
        String fileName = tempDir + "/emptyListFromJava.sod";
34
 
 
35
 
        int fileId = H5Write.createFile(fileName);
36
 
        H5Write.writeInDataSet(fileId, "EmptyList", data);
37
 
        H5Write.closeFile(fileId);
38
 
 
39
 
        data = new ScilabList();
40
 
        fileId = H5Read.openFile(fileName);
41
 
        Assert.assertEquals(H5Read.getRootType(fileId), H5ScilabConstant.SCILAB_CLASS_LIST);
42
 
        H5Read.readDataFromFile(fileId, data);
43
 
        Assert.assertEquals(data.isEmpty(), true);
44
 
        new File(fileName).delete();
45
 
    }
46
 
 
47
 
    @Test
48
 
    public void testStringList() throws NullPointerException, HDF5LibraryException, HDF5Exception {
49
 
        ScilabList dataList = new ScilabList();
50
 
        dataList.add(new ScilabString("hello"));
51
 
        String[][] stringData = {{"i", "am", "a"}, {"string", "matrix", "!!!"}};
52
 
        String fileName = tempDir + "/stringListFromJava.sod";
53
 
 
54
 
        dataList.add(new ScilabString(stringData));
55
 
 
56
 
        int fileId = H5Write.createFile(fileName);
57
 
        H5Write.writeInDataSet(fileId, "StringList", dataList);
58
 
        H5Write.closeFile(fileId);
59
 
 
60
 
        ScilabList data = new ScilabList();
61
 
        fileId = H5Read.openFile(fileName);
62
 
        Assert.assertEquals(H5Read.getRootType(fileId), H5ScilabConstant.SCILAB_CLASS_LIST);
63
 
        H5Read.readDataFromFile(fileId, data);
64
 
 
65
 
        Assert.assertEquals(data.getHeight(), dataList.getHeight());
66
 
        Assert.assertEquals(data.getWidth(), dataList.getWidth());
67
 
 
68
 
        Assert.assertEquals(data, dataList); // deep equals
69
 
        new File(fileName).delete();
70
 
    }
71
 
 
72
 
    @Test
73
 
    public void testDoubleList() throws NullPointerException, HDF5LibraryException, HDF5Exception {
74
 
        ScilabList dataList = new ScilabList();
75
 
        String fileName = tempDir + "/doubleListFromJava.sod";
76
 
        dataList.add(new ScilabDouble(2));
77
 
        dataList.add(new ScilabDouble(51));
78
 
 
79
 
        int fileId = H5Write.createFile(fileName);
80
 
        H5Write.writeInDataSet(fileId, "DoubleList", dataList);
81
 
        H5Write.closeFile(fileId);
82
 
 
83
 
        ScilabList data = new ScilabList();
84
 
        fileId = H5Read.openFile(fileName);
85
 
        Assert.assertEquals(H5Read.getRootType(fileId), H5ScilabConstant.SCILAB_CLASS_LIST);
86
 
        H5Read.readDataFromFile(fileId, data);
87
 
 
88
 
        Assert.assertEquals(data.getHeight(), dataList.getHeight());
89
 
        Assert.assertEquals(data.getWidth(), dataList.getWidth());
90
 
 
91
 
        Assert.assertEquals(data, dataList); // deep equals
92
 
        new File(fileName).delete();
93
 
    }
94
 
 
95
 
    @Test
96
 
    public void testMixedList() throws HDF5Exception {
97
 
        String fileName = tempDir + "/mixedListFromJava.sod";
98
 
        ScilabList dataList = new ScilabList();
99
 
        dataList.add(new ScilabDouble(2));
100
 
        dataList.add(new ScilabDouble(51));
101
 
        String[][] stringData = {{"i", "am", "a"}, {"string", "matrix", "!!!"}};
102
 
        dataList.add(new ScilabString(stringData));
103
 
 
104
 
        int fileId = H5Write.createFile(fileName);
105
 
        H5Write.writeInDataSet(fileId, "MixedList", dataList);
106
 
        H5Write.closeFile(fileId);
107
 
 
108
 
        ScilabList data = new ScilabList();
109
 
        fileId = H5Read.openFile(fileName);
110
 
        Assert.assertEquals(H5Read.getRootType(fileId), H5ScilabConstant.SCILAB_CLASS_LIST);
111
 
        H5Read.readDataFromFile(fileId, data);
112
 
 
113
 
        Assert.assertEquals(data.getHeight(), dataList.getHeight());
114
 
        Assert.assertEquals(data.getWidth(), dataList.getWidth());
115
 
 
116
 
        Assert.assertEquals(data, dataList); // deep equals
117
 
        new File(fileName).delete();
118
 
    }
119
 
 
120
 
    /**
121
 
     * Call all public methods through introspection
122
 
     * @param args not used
123
 
     * @throws Exception on error
124
 
     */
125
 
    public static void main(String[] args) throws Exception {
126
 
        final Class < ? > myClass = Class.forName(new Throwable().getStackTrace()[0].getClassName());
127
 
 
128
 
        Object obj = myClass.newInstance();
129
 
        java.lang.reflect.Method[] tests = myClass.getDeclaredMethods();
130
 
        for (java.lang.reflect.Method method : tests) {
131
 
            if (method.getAnnotation(Test.class) != null) {
132
 
                method.invoke(obj, (Object[]) null);
133
 
            }
134
 
        }
135
 
    }
136
 
}