File: StringArrayTest.java

package info (click to toggle)
jaffl 0.5.9-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,424 kB
  • ctags: 3,737
  • sloc: java: 10,718; xml: 1,011; ansic: 273; makefile: 14; sh: 6
file content (78 lines) | stat: -rw-r--r-- 2,233 bytes parent folder | download
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.kenai.jaffl;

import com.kenai.jaffl.annotations.In;
import com.kenai.jaffl.annotations.Out;
import java.nio.charset.Charset;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author wayne
 */
public class StringArrayTest {

    public StringArrayTest() {
    }

    public static interface TestLib {
        String ptr_return_array_element(@In String[] array, int index);
        void ptr_set_array_element(@Out String[] array, int index, Pointer value);
    }
    
    static TestLib testlib;
    static Runtime runtime;
    @BeforeClass
    public static void setUpClass() throws Exception {
        testlib = TstUtil.loadTestLib(TestLib.class);
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    // TODO add test methods here.
    // The methods must be annotated with annotation @Test. For example:
    //
    // @Test
    // public void hello() {}
    @Test public void lastElementOfStringArrayShouldBeNull() {
        String[] strings = { "test" };
        String result = testlib.ptr_return_array_element(strings, 1);
        assertNull("last element of string array was not null", result);
    }

    @Test public void firstElementOfStringArrayShouldNotBeNull() {
        final String MAGIC = "test";
        String[] strings = { MAGIC };
        assertNotNull(testlib.ptr_return_array_element(strings, 0));
    }

    @Test public void firstElementOfStringArrayShouldEqualOriginalValue() {
        final String MAGIC = "test";
        String[] strings = { MAGIC };
        assertEquals(MAGIC, testlib.ptr_return_array_element(strings, 0));
    }

    @Test public void elementsSetByNativeCodeShouldBeReloaded() {
        final String MAGIC = "test";
        String[] strings = new String[1];
        Pointer ptr = FFIProvider.getProvider().getMemoryManager().allocateDirect(1024);
        ptr.putString(0, MAGIC, 1024, Charset.defaultCharset());
        testlib.ptr_set_array_element(strings, 0, ptr);
        assertEquals(MAGIC, strings[0]);
    }
}