package lejos.test;
import org.apache.log4j.Logger;
import junit.framework.TestCase;
import lejos.nxt.LightSensor;
import lejos.nxt.SensorPort;
import lejos.stub.ISensorPort;
import lejos.stub.SensorPortStub;
public class TestLight extends TestCase {
LightSensor light;
protected void setUp() throws Exception {
}
protected void tearDown() throws Exception {
}
public void testLightSetOn() {
SensorPortStub.setISensorPort(0, new ISensorPort() {
public int i2cBusy() {
fail();
return 0;
}
public void i2cDisable() {
fail();
}
public void i2cEnable() {
fail();
}
public int i2cStart(int address, int internalAddress,
int numInternalBytes, byte[] buffer, int numBytes,
int transferType) {
fail();
return 0;
}
public int readSensorValue() {
fail();
return 0;
}
public void setADType(int type) {
assertEquals(1, type);
}
public void setPowerType(int portType) {
assertEquals(0, portType);
}
});
light = new LightSensor(SensorPort.S1, true);
}
public void testSetOff() {
SensorPortStub.setISensorPort(0, new ISensorPort() {
public int i2cBusy() {
fail();
return 0;
}
public void i2cDisable() {
fail();
}
public void i2cEnable() {
fail();
}
public int i2cStart(int address, int internalAddress,
int numInternalBytes, byte[] buffer, int numBytes,
int transferType) {
fail();
return 0;
}
public int readSensorValue() {
fail();
return 0;
}
public void setADType(int type) {
assertEquals(0, type);
}
public void setPowerType(int portType) {
assertEquals(0, portType);
}
});
light = new LightSensor(SensorPort.S1, false);
}
public void testRead() {
SensorPortStub.setISensorPort(0, new ISensorPort() {
public int i2cBusy() {
fail();
return 0;
}
public void i2cDisable() {
fail();
}
public void i2cEnable() {
fail();
}
public int i2cStart(int address, int internalAddress,
int numInternalBytes, byte[] buffer, int numBytes,
int transferType) {
fail();
return 0;
}
public int readSensorValue() {
return 12;
}
public void setADType(int type) {
assertEquals(0, type);
}
public void setPowerType(int portType) {
assertEquals(0, portType);
}
});
light = new LightSensor(SensorPort.S1, false);
light.readValue();
}
}