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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package constantine.platform;
import com.kenai.constantine.platform.Errno;
import com.kenai.constantine.ConstantSet;
import java.util.EnumSet;
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 ErrnoTest {
private ConstantSet constants;
public ErrnoTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
}
@AfterClass
public static void tearDownClass() throws Exception {
}
@Before
public void setUp() {
constants = ConstantSet.getConstantSet("Errno");
}
@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 intValue() {
for (Errno errno : EnumSet.allOf(Errno.class)) {
if (errno == Errno.__UNKNOWN_CONSTANT__) {
continue;
}
int val = constants.getValue(errno.name());
assertEquals("Incorrect integer value for " + errno.name() + ",", val, errno.value());
}
}
@Test public void valueOf() {
for (Errno errno : EnumSet.allOf(Errno.class)) {
if (errno == Errno.__UNKNOWN_CONSTANT__) {
continue;
}
Errno e = Errno.valueOf(errno.value());
assertEquals("Incorrect integer value for " + errno.name() + ",", errno.value(), e.value());
}
}
@Test public void description() {
for (Errno errno : Errno.values()) {
if (errno == Errno.__UNKNOWN_CONSTANT__) {
continue;
}
assertNotSame("Lack of description for " + errno.name(), errno.name(), errno.toString());
}
}
@Test public void expected() {
for (Errno e : new Errno[] {Errno.ENOENT, Errno.EINVAL, Errno.EISDIR}) {
assertNotSame(e.name() + " is unknown", Errno.__UNKNOWN_CONSTANT__, e);
}
}
@Test public void unknownConstant() {
Errno none = Errno.valueOf(~0);
assertEquals("Incorrect errno for unknown value", Errno.__UNKNOWN_CONSTANT__, none);
}
@Test public void reverseLookupCache() {
for (Errno errno : EnumSet.allOf(Errno.class)) {
if (errno == Errno.__UNKNOWN_CONSTANT__) {
continue;
}
Errno e1 = Errno.valueOf(errno.value());
Errno e2 = Errno.valueOf(errno.value());
assertEquals("Cached Enum values differ for " + errno.name() + ",", e1, e2);
}
}
}
|