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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tests.SQLite;
import SQLite.Blob;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import junit.framework.TestCase;
import java.io.InputStream;
import java.io.OutputStream;
@TestTargetClass(Blob.class)
public class BlobTest extends TestCase {
private static Blob testBlob = null;
private byte[] blobInput= null;
private static InputStream file = null;
public BlobTest(String name) {
super(name);
}
protected void setUp() throws java.lang.Exception {
super.setUp();
testBlob = new Blob();
// can not fill Blob with data at this point...
/*
File resources = Support_Resources.createTempFolder();
BufferedReader r = null;
try {
Class c = Class.forName(this.getClass().getName());
assertNotNull(c);
file = Class.forName(this.getClass().getName())
.getResourceAsStream("/blob.c");
r = new BufferedReader(new InputStreamReader(file));
} catch (NullPointerException e) {
fail("Should not throw NullPointerException reading file"
+ e.getMessage());
}
OutputStream out = testBlob.getOutputStream();
String s = null;
while ((s = r.readLine()) != null) {
out.write(r.readLine().getBytes());
}
out.flush();
out.close();
testBlob.close();
*/
}
protected void tearDown() throws java.lang.Exception {
super.tearDown();
testBlob.close();
}
/**
* @tests Blob#Blob()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "constructor test",
method = "Blob",
args = {}
)
public void _testBlob() {
Blob b = new Blob();
assertNotNull(b);
//assertEquals(0, b.size);
}
/**
* @tests Blob#finalize()
*/
@TestTargetNew(
level = TestLevel.NOT_FEASIBLE,
notes = "method test",
method = "finalize",
args = {}
)
public void _testFinalize() {
fail("Not yet implemented");
}
/**
* @tests Blob.getInputStream()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "method test",
method = "getInputStream",
args = {}
)
public void testGetInputStream() {
InputStream in = testBlob.getInputStream();
assertNotNull(in);
try {
in.read();
fail("Read operation unsupported");
} catch (Throwable e) {
//ok
}
/*
byte[] defaultByteArray = null;
BufferedReader actual = new BufferedReader(new InputStreamReader(
testBlob.getInputStream()));
byte[] b1;
byte[] b2;
try {
BufferedReader shouldBe = new BufferedReader(new InputStreamReader(
this.file));
while (((b1 = actual.readLine().getBytes()) != null)
&& ((b2 = shouldBe.readLine().getBytes()) != null)) {
assertEquals(b2, b1);
}
assertEquals("both finished", shouldBe.readLine(), actual
.readLine());
} catch (IOException e) {
fail("Error in test setup: " + e.toString());
e.printStackTrace();
}
*/
}
/**
* @tests Blob#getOutputStream()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "method test",
method = "getOutputStream",
args = {}
)
public void testGetOutputStream() {
OutputStream out = testBlob.getOutputStream();
assertNotNull(out);
try {
out.write(null);
fail("Write operation unsupported");
} catch (Throwable e) {
assertEquals("Write operation unsupported", e.getMessage());
}
}
/**
* @tests Blob#close()
*/
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "method test",
method = "close",
args = {}
)
public void _testClose() {
try {
testBlob.close();
testBlob.close();
testBlob.getInputStream();
//assertEquals(0, testBlob.size);
} catch (Throwable e) {
fail("Tests failed");
}
}
// these tests show that read and write are unsupported -> blob is unsupported
// /**
// * @tests Blob#write(byte[], int, int, int)
// */
// @TestTargetNew(
// level = TestLevel.COMPLETE,
// notes = "method test",
// method = "write",
// args = {byte[].class, int.class, int.class, int.class}
// )
// public void testWrite() {
// try {
// testBlob.write(null, 0, 0, 0);
// fail("Write operation unsupported");
// } catch (Throwable e) {
// //ok
// }
// }
//
// /**
// * @tests Blob#read()
// */
// @TestTargetNew(
// level = TestLevel.COMPLETE,
// notes = "method test",
// method = "read",
// args = {}
// )
// public void testRead() {
// Blob b = new Blob();
// try {
// testBlob.read(null, 0, 0, 0);
// fail("Read operation unsupported");
// } catch (Throwable e) {
// //ok
// }
// }
}
|