Skip to content

Commit 6b58441

Browse files
Added Testcases for Log
1 parent d7bbcfd commit 6b58441

File tree

5 files changed

+158
-1
lines changed

5 files changed

+158
-1
lines changed

FFmpegAndroid/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ dependencies {
6262
exclude module: 'wagon-http-lightweight'
6363
exclude module: 'wagon-provider-api'
6464
}
65+
66+
androidTestCompile 'com.squareup.assertj:assertj-android:1.0.0'
6567
}
6668

6769
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.github.hiteshsondhi88.libffmpeg;
2+
3+
import static junit.framework.Assert.assertTrue;
4+
5+
public class AssertionHelper {
6+
7+
public static void assertError(String message) {
8+
assertTrue(message, false);
9+
}
10+
11+
public static void assertError() {
12+
assertError("");
13+
}
14+
15+
public static void assertOK(String message) {
16+
assertTrue(message, true);
17+
}
18+
19+
public static void assertOK() {
20+
assertOK("");
21+
}
22+
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.hiteshsondhi88.libffmpeg;
2+
3+
import junit.framework.TestCase;
4+
5+
public class CommonTestCase extends TestCase {
6+
7+
public void setUp() throws Exception {
8+
super.setUp();
9+
Log.setDEBUG(true);
10+
}
11+
12+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package com.github.hiteshsondhi88.libffmpeg;
2+
3+
import org.junit.runner.RunWith;
4+
import org.robolectric.RobolectricTestRunner;
5+
6+
/**
7+
* Trying Logging everything I can Log.java class should never throw any error
8+
*/
9+
@RunWith(RobolectricTestRunner.class)
10+
public class LogTest extends CommonTestCase {
11+
12+
private Object[] OBJECTS_TO_TEST = {null, "", "test string", 1, 1.00123, 2.45225747946181e-072};
13+
private Throwable[] EXCEPTIONS_TO_TEST = {new Exception(), new Exception("Test exception"), new Exception("")};
14+
15+
public void testD() throws Exception {
16+
printLog(new PrintLogInterface() {
17+
@Override
18+
public void print(Object obj) throws Exception {
19+
Log.d(obj);
20+
}
21+
22+
@Override
23+
public void print(Throwable throwable) throws Exception {
24+
Log.d(throwable);
25+
}
26+
});
27+
}
28+
29+
public void testW() throws Exception {
30+
printLog(new PrintLogInterface() {
31+
@Override
32+
public void print(Object obj) throws Exception {
33+
Log.w(obj);
34+
}
35+
36+
@Override
37+
public void print(Throwable throwable) throws Exception {
38+
Log.w(throwable);
39+
}
40+
});
41+
}
42+
43+
public void testI() throws Exception {
44+
printLog(new PrintLogInterface() {
45+
@Override
46+
public void print(Object obj) throws Exception {
47+
Log.i(obj);
48+
}
49+
50+
@Override
51+
public void print(Throwable throwable) throws Exception {
52+
Log.i(throwable);
53+
}
54+
});
55+
}
56+
57+
public void testV() throws Exception {
58+
printLog(new PrintLogInterface() {
59+
@Override
60+
public void print(Object obj) throws Exception {
61+
Log.v(obj);
62+
}
63+
64+
@Override
65+
public void print(Throwable throwable) throws Exception {
66+
Log.v(throwable);
67+
}
68+
});
69+
}
70+
71+
public void testE() throws Exception {
72+
printLog(new PrintLogInterface() {
73+
@Override
74+
public void print(Object obj) throws Exception {
75+
Log.e(obj);
76+
}
77+
78+
@Override
79+
public void print(Throwable throwable) throws Exception {
80+
Log.e(throwable);
81+
}
82+
});
83+
84+
for (Object obj : OBJECTS_TO_TEST) {
85+
for (Throwable throwable : EXCEPTIONS_TO_TEST) {
86+
try {
87+
Log.e(obj, throwable);
88+
} catch (Exception e) {
89+
AssertionHelper.assertError("Logging failed for object "+obj+" and throwable "+throwable);
90+
}
91+
}
92+
}
93+
}
94+
95+
private void printLog(PrintLogInterface printLogInterface) {
96+
for (Object obj : OBJECTS_TO_TEST) {
97+
try {
98+
printLogInterface.print(obj);
99+
} catch (Exception e) {
100+
AssertionHelper.assertError("Logging failed for object "+obj);
101+
}
102+
}
103+
for (Throwable throwable : EXCEPTIONS_TO_TEST) {
104+
try {
105+
printLogInterface.print(throwable);
106+
} catch (Exception e) {
107+
AssertionHelper.assertError("Logging failed for throwable "+throwable);
108+
}
109+
}
110+
}
111+
112+
private interface PrintLogInterface {
113+
void print(Object obj) throws Exception;
114+
void print(Throwable throwable) throws Exception;
115+
}
116+
}

FFmpegAndroid/src/main/java/com/github/hiteshsondhi88/libffmpeg/Log.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
@SuppressWarnings("unused")
44
class Log {
55

6-
private static final String TAG = FFmpeg.class.getSimpleName();
6+
private static String TAG = FFmpeg.class.getSimpleName();
77
private static boolean DEBUG = false;
88

99
static void setDEBUG(boolean DEBUG) {
1010
Log.DEBUG = DEBUG;
1111
}
1212

13+
static void setTAG(String tag) {
14+
Log.TAG = tag;
15+
}
16+
1317
static void d(Object obj) {
1418
if (DEBUG) {
1519
android.util.Log.d(TAG, obj != null ? obj.toString() : null+"");

0 commit comments

Comments
 (0)