forked from getodk/sensors-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
71 changes: 62 additions & 9 deletions
71
sensorsframework_app/src/androidTest/java/org/opendatakit/sensors/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,66 @@ | ||
package org.opendatakit.sensors; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.IBinder; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.rule.ServiceTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import android.util.Log; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.opendatakit.sensors.service.ODKSensorService; | ||
|
||
import java.util.concurrent.TimeoutException; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class ApplicationTest { | ||
|
||
private final static String LOGTAG = ApplicationTest.class.getCanonicalName(); | ||
|
||
@Rule | ||
public final ServiceTestRule mServiceRule = new ServiceTestRule(); | ||
|
||
private ODKSensorService bindToService() { | ||
Context context = InstrumentationRegistry.getContext(); | ||
Intent bind_intent = new Intent(); | ||
bind_intent.setClassName(SensorsConsts.frameworkPackage, SensorsConsts.frameworkService); | ||
|
||
int count = 0; | ||
ODKSensorService sensorService; | ||
try { | ||
IBinder service = null; | ||
while ( service == null ) { | ||
try { | ||
service = mServiceRule.bindService(bind_intent); | ||
} catch (TimeoutException e) { | ||
service = null; | ||
} | ||
if ( service == null ) { | ||
++count; | ||
if ( count % 20 == 0 ) { | ||
Log.i(LOGTAG, "bindToDbService failed for " + count); | ||
} | ||
try { | ||
Thread.sleep(10); | ||
} catch (InterruptedException e) { | ||
} | ||
} | ||
} | ||
sensorService = ODKSensorService.Stub.asInterface(service); | ||
} catch (IllegalArgumentException e) { | ||
sensorService = null; | ||
} | ||
return sensorService; | ||
} | ||
|
||
@Test | ||
public void testBinding() { | ||
ODKSensorService serviceInterface = bindToService(); | ||
assertNotNull( "bind did not succeed", serviceInterface); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
sensorsframework_app/src/test/java/org/opendatakit/sensors/ExampleUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters