Repository navigation
Expand file tree
/
Copy pathSysfsTest.java
More file actions
147 lines (99 loc) · 4.65 KB
/
Copy pathSysfsTest.java
File metadata and controls
147 lines (99 loc) · 4.65 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package ev3dev.utils;
import ev3dev.hardware.EV3DevPlatform;
import ev3dev.sensors.Battery;
import fake_ev3dev.ev3dev.sensors.FakeBattery;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@Slf4j
public class SysfsTest {
@Before
public void resetTest() throws IOException {
FakeBattery.deleteEV3DevFakeSystemPath();
FakeBattery.createEV3DevFakeSystemPath();
}
//OK
@Test
public void existPathSuccessTest() throws IOException {
final FakeBattery fakeBattery = new FakeBattery(EV3DevPlatform.EV3BRICK);
final boolean result = Sysfs.existPath(fakeBattery.EV3DEV_FAKE_SYSTEM_PATH);
assertThat(result, is(true));
}
@Test
public void readString() throws Exception {
final FakeBattery fakeBattery = new FakeBattery(EV3DevPlatform.EV3BRICK);
String pathToAssert = FakeBattery.EV3DEV_FAKE_SYSTEM_PATH + "/"+ Battery.BATTERY + "/" + Battery.BATTERY_EV3 + "/" + Battery.VOLTAGE;
String result = Sysfs.readString(pathToAssert);
assertThat(result, is(fakeBattery.BATTERY_FIELD_VOLTAGE_VALUE));
}
@Test
public void readInteger() throws Exception {
final FakeBattery fakeBattery = new FakeBattery(EV3DevPlatform.EV3BRICK);
String pathToAssert = FakeBattery.EV3DEV_FAKE_SYSTEM_PATH + "/"+ Battery.BATTERY + "/" + Battery.BATTERY_EV3 + "/" + Battery.VOLTAGE;
int result = Sysfs.readInteger(pathToAssert);
assertThat(result, is(Integer.parseInt(FakeBattery.BATTERY_FIELD_VOLTAGE_VALUE)));
}
@Test
public void readFloat() throws Exception {
final FakeBattery fakeBattery = new FakeBattery(EV3DevPlatform.EV3BRICK);
String pathToAssert = FakeBattery.EV3DEV_FAKE_SYSTEM_PATH + "/"+ Battery.BATTERY + "/" + Battery.BATTERY_EV3 + "/" + Battery.VOLTAGE;
float result = Sysfs.readFloat(pathToAssert);
assertThat(result, is(Float.parseFloat(FakeBattery.BATTERY_FIELD_VOLTAGE_VALUE)));
}
@Test
public void getElements() throws Exception {
final FakeBattery fakeBattery = new FakeBattery(EV3DevPlatform.EV3BRICK);
String pathToAssert = FakeBattery.EV3DEV_FAKE_SYSTEM_PATH + "/"+ Battery.BATTERY;
final List<File> fileList = new ArrayList<>();
fileList.add(new File(pathToAssert + "/" + Battery.BATTERY_EV3));
assertThat(Sysfs.getElements(pathToAssert), is(fileList));
}
@Test
public void existFile() throws Exception {
final FakeBattery fakeBattery = new FakeBattery(EV3DevPlatform.EV3BRICK);
String pathToAssert = FakeBattery.EV3DEV_FAKE_SYSTEM_PATH + "/"+ Battery.BATTERY + "/"+ Battery.BATTERY_EV3 + "/" + Battery.VOLTAGE;
final Path path = Paths.get(pathToAssert);
boolean result = Sysfs.existFile(path);
assertThat(result, is(true));
}
@Test
public void notExistFile() throws Exception {
final FakeBattery fakeBattery = new FakeBattery(EV3DevPlatform.EV3BRICK);
String pathToAssert = FakeBattery.EV3DEV_FAKE_SYSTEM_PATH + "/"+ Battery.BATTERY + "/"+ Battery.BATTERY_EV3 + "/" + Battery.CURRENT;
final Path path = Paths.get(pathToAssert);
assertThat(Sysfs.existFile(path), is(false));
}
@Test
public void writeString() throws Exception {
final FakeBattery fakeBattery = new FakeBattery(EV3DevPlatform.EV3BRICK);
String pathToAssert = FakeBattery.EV3DEV_FAKE_SYSTEM_PATH + "/"+ Battery.BATTERY + "/"+ Battery.BATTERY_EV3 + "/" + Battery.VOLTAGE;
final Path path = Paths.get(pathToAssert);
Sysfs.writeString(pathToAssert, "10");
assertThat(Sysfs.readString(pathToAssert), is("10"));
}
@Test
public void writeInteger() throws Exception {
final FakeBattery fakeBattery = new FakeBattery(EV3DevPlatform.EV3BRICK);
String pathToAssert = FakeBattery.EV3DEV_FAKE_SYSTEM_PATH + "/"+ Battery.BATTERY + "/"+ Battery.BATTERY_EV3 + "/" + Battery.VOLTAGE;
final Path path = Paths.get(pathToAssert);
Sysfs.writeInteger(pathToAssert, 10);
assertThat(Sysfs.readInteger(pathToAssert), is(10));
}
@Ignore("Review error in detail for Travis CI")
@Test(expected = RuntimeException.class)
public void writeBytesTest() {
int BUFFER_SIZE = 0;
byte[] buf = new byte[BUFFER_SIZE];
final String FB_PATH = "/dev/MY_PERSONAL_PATH";
Sysfs.writeBytes(FB_PATH, buf);
}
}