Skip to content

Commit

Permalink
Merge pull request #66 from sverbach/dev
Browse files Browse the repository at this point in the history
Dev to master Sprint 2
  • Loading branch information
sverbach authored Apr 7, 2021
2 parents 53c4a18 + e0670fd commit 5708aa6
Show file tree
Hide file tree
Showing 115 changed files with 4,069 additions and 964 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ dependencies {
implementation 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
implementation 'com.google.apis:google-api-services-drive:v3-rev110-1.23.0'
implementation 'com.google.zxing:core:3.2.1'
implementation 'com.google.android.gms:play-services-nearby:16.0.0'
implementation project(path: ':opencv_final')
testImplementation 'junit:junit:4.12'
testImplementation "org.mockito:mockito-core:1.+"
Expand Down
54 changes: 50 additions & 4 deletions app/src/androidTest/java/ch/m3ts/MainActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import static junit.framework.Assert.assertEquals;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.not;

@RunWith(AndroidJUnit4.class)
@LargeTest
Expand Down Expand Up @@ -59,6 +60,13 @@ public void testGoToMatchAndInitActivity() {
onView(withId(R.id.mainUseAsDisplayBtn))
.perform(click());

// check for alertDialog
pressBack();
onView(withText(R.string.quitMatchMessage)).check(matches(isDisplayed()));
onView(withText(R.string.quitMatchProceed)).perform(click());
onView(withId(R.id.mainUseAsDisplayBtn))
.perform(click());

// check if we are at the MatchActivity
onView(withId(R.id.match_type_bo1))
.check(matches(isDisplayed()));
Expand Down Expand Up @@ -107,14 +115,43 @@ public void checkAppSettings() {
onView(withText(R.string.prefDisplayDebug)).perform(click());
onView(withText(R.string.prefRecord)).perform(click());

// check rest of the settings...
// Video Capture
onView(withText(R.string.prefHeaderCapture)).check(matches(isDisplayed()));
onView(withText(R.string.prefHeaderCapture)).perform(click());
onView(withText(R.string.prefResolution)).check(matches(isDisplayed()));
onView(withText(R.string.prefCameraFacing)).check(matches(isDisplayed()));
onView(withText(R.string.prefRecordMode)).check(matches(isDisplayed()));
onView(withText(R.string.prefSlowPreview)).check(matches(isDisplayed()));

// Detection
onView(withText(R.string.prefHeaderDetection)).check(matches(isDisplayed()));
onView(withText(R.string.prefHeaderDetection)).perform(click());
onView(withText(R.string.prefColorSpace)).check(matches(isDisplayed()));
onView(withText(R.string.prefProcRes)).check(matches(isDisplayed()));

// Velocity estimation
onView(withText(R.string.prefHeaderVelocity)).check(matches(isDisplayed()));
onView(withText(R.string.prefHeaderVelocity)).perform(click());
onView(withText(R.string.prefVelocityEstimationMode)).check(matches(isDisplayed()));
onView(withText(R.string.prefObjectDiameterCustom)).check(matches(isDisplayed()));
onView(withText(R.string.prefObjectDiameterPicker)).check(matches(isDisplayed()));
onView(withText(R.string.prefFrameRate)).check(matches(isDisplayed()));

// Advanced
onView(withText(R.string.prefHeaderAdvanced)).check(matches(isDisplayed()));
onView(withText(R.string.prefHeaderAdvanced)).perform(click());
onView(withText(R.string.runVideoPlayer)).check(matches(isDisplayed()));
onView(withText(R.string.prefDisableDetection)).check(matches(isDisplayed()));
onView(withText(R.string.prefPubnub)).check(matches(isDisplayed()));

// now check the edited settings in main activity
pressBack();
config = new Config(activity);
assertEquals(!isUseDebug, config.isUseDebug());
assertEquals(!recordMatches, config.doRecordMatches());
assertEquals(newPlayer1Name, config.getPlayer1Name());
assertEquals(newPlayer2Name, config.getPlayer2Name());

}

private void checkMatchSettingsAndQRCode() {
Expand All @@ -134,9 +171,18 @@ private void checkMatchSettingsAndQRCode() {
onView(withId(R.id.init_sideAndMatchTypeDoneBtn))
.perform(click());

Activity activity = pmsMainActivityRule.getActivity();
Config config = new Config(activity);

// now we should be greeted by a QR code
onView(withId(R.id.qr_code))
.check(matches(isDisplayed()));
if (config.isUsingPubnub()) {
// now we should be greeted by a QR code
onView(withId(R.id.qr_code))
.check(matches(isDisplayed()));
} else {
onView(withId(R.id.qr_code))
.check(matches(not(isDisplayed())));
onView(withText(R.string.connectDisplaySearching))
.check(matches(isDisplayed()));
}
}
}
104 changes: 104 additions & 0 deletions app/src/androidTest/java/ch/m3ts/TutorialActivityTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package ch.m3ts;

import android.Manifest;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.filters.LargeTest;
import androidx.test.rule.ActivityTestRule;
import androidx.test.rule.GrantPermissionRule;
import androidx.test.runner.AndroidJUnit4;
import cz.fmo.R;
import helper.GrantPermission;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.pressBack;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class TutorialActivityTest {
private static final int STEPS_TRACKER_TUTORIAL = 3;
private static final int STEPS_DISPLAY_TUTORIAL = 5;
private static final int STEPS_SERVE_TUTORIAL = 1;

@Rule
public GrantPermissionRule grantPermissionRuleCamera = GrantPermissionRule.grant(Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE);

@Rule
public ActivityTestRule<MainActivity> pmsMainActivityRule = new ActivityTestRule<>(MainActivity.class);

@Before
public void grantAllPermissions() {
GrantPermission.grantAllPermissions();
}

@Test
public void checkTutorialActivity() {
int[] tutorials = {
R.string.tutorialTrackerBtnLabel,
R.string.tutorialDisplayBtnLabel,
R.string.tutorialPlayBtnLabel
};
onView(withId(R.id.mainHowToPlay)).perform(click());
for (int tutorialButtonLabel : tutorials) {
onView(withText(tutorialButtonLabel)).check(matches(isDisplayed()));
}
onView(withText(tutorials[0])).perform(click());

// should be in fragment now, confirm with display matches
onView(withId(R.id.tutorialImg)).check(matches(isDisplayed()));
onView(withId(R.id.tutorialDescriptionTxt)).check(matches(isDisplayed()));
onView(withId(R.id.tutorialTitleTxt)).check(matches(isDisplayed()));

// click revert Button a couple of times, nothing should happen
for (int i = 0; i < 10; i++) {
onView(withId(R.id.tutorialGoBackBtn)).perform(click());
}

onView(withId(R.id.tutorialContinueBtn)).perform(click());
onView(withId(R.id.tutorialGoBackBtn)).perform(click());

// do all tutorials...
testTrackerTutorial();
onView(withText(tutorials[1])).perform(click());
testDisplayTutorial();
onView(withText(tutorials[2])).perform(click());
testServeTutorial();

// now we should be in mainActivity again
pressBack();
onView(withId(R.id.mainHowToPlay)).check(matches(isDisplayed()));
}

private void testTrackerTutorial() {
// press continue until we finished tutorial
for (int i = 0; i < STEPS_TRACKER_TUTORIAL; i++) {
onView(withId(R.id.tutorialContinueBtn)).perform(click());
}
onView(withId(R.id.mainHowToPlay)).perform(click());
}

private void testDisplayTutorial() {
// press continue until we finished tutorial
for (int i = 0; i < STEPS_DISPLAY_TUTORIAL; i++) {
onView(withId(R.id.tutorialContinueBtn)).perform(click());
}
onView(withId(R.id.mainHowToPlay)).perform(click());
}

private void testServeTutorial() {
// press continue until we finished tutorial
for (int i = 0; i < STEPS_SERVE_TUTORIAL; i++) {
onView(withId(R.id.tutorialContinueBtn)).perform(click());
}
onView(withId(R.id.mainHowToPlay)).perform(click());
}
}
13 changes: 9 additions & 4 deletions app/src/androidTest/java/ch/m3ts/display/MatchActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.os.Bundle;
import android.test.InstrumentationTestCase;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

Expand All @@ -30,6 +29,7 @@
import androidx.test.runner.AndroidJUnit4;
import ch.m3ts.tabletennis.helper.Side;
import cz.fmo.R;
import cz.fmo.util.Config;
import helper.GrantPermission;

import static androidx.test.espresso.Espresso.onView;
Expand Down Expand Up @@ -272,14 +272,19 @@ public void testMatchInitFragment() throws Exception {
matchInitFragment.setArguments(bundle);
matchActivity.replaceFragment(matchInitFragment, "MATCH_INIT");
Thread.sleep(1000);
assertNotNull(((ImageView)matchActivity.findViewById(R.id.qr_code)).getDrawable());
Config config = new Config(matchActivity);
if (config.isUsingPubnub()) {
onView(withId(R.id.qr_code)).check(matches(isDisplayed()));
} else {
onView(withText(R.string.connectDisplaySearching)).check(matches(isDisplayed()));
}

// invoke onImageTransmissionStarted and check if LoadingBar is initialized
ProgressBar bar = matchActivity.findViewById(R.id.loading_bar);
final int parts = 50;
assertEquals(100, bar.getMax());
getInstrumentation().runOnMainSync(new Runnable(){
public void run(){
getInstrumentation().runOnMainSync(new Runnable() {
public void run() {
matchInitFragment.onImageTransmissionStarted(parts);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import androidx.test.runner.AndroidJUnit4;
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
import androidx.test.runner.lifecycle.Stage;
import ch.m3ts.connection.NearbyTrackerConnection;
import ch.m3ts.tabletennis.helper.Side;
import ch.m3ts.tabletennis.match.MatchType;
import ch.m3ts.tracker.visualization.CameraPreviewActivity;
import ch.m3ts.tracker.visualization.live.LiveActivity;
import cz.fmo.R;
import cz.fmo.util.Config;
import helper.GrantPermission;

import static androidx.test.espresso.Espresso.onView;
Expand All @@ -46,8 +48,8 @@
@LargeTest
public class InitTrackerActivityTest extends InstrumentationTestCase {
private InitTrackerActivity activity;
private Config config;
private String QR_CODE_PATH = "yuvimg.yuv";
private String SCAN_OVERLAY_TEXT = "Scan the QR code from the display";

@Rule
public ActivityTestRule<InitTrackerActivity> initActivityRule = new ActivityTestRule<InitTrackerActivity>(InitTrackerActivity.class) {
Expand All @@ -61,6 +63,11 @@ protected Intent getActivityIntent() {
public void setUp() {
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
activity = initActivityRule.getActivity();
config = new Config(activity);
if (!config.isUsingPubnub()) {
NearbyTrackerConnection trackerConnection = NearbyTrackerConnection.getInstance();
trackerConnection.init(activity);
}
GrantPermission.grantAllPermissions();
}

Expand All @@ -78,8 +85,11 @@ public void scanOverlayDisplayed() {
// need to perform a wait until the sensor data of the emulator has been received
onView(isRoot()).perform(waitFor(3000));
onView(withId(R.id.adjust_device_overlay)).check(matches(not(isDisplayed())));
onView(withId(R.id.scan_overlay)).check(matches(isDisplayed()));
onView(withText(SCAN_OVERLAY_TEXT)).check(matches(isDisplayed()));
if (config.isUsingPubnub()) {
onView(withId(R.id.scan_overlay)).check(matches(isDisplayed()));
} else {
onView(withText(R.string.connectTrackerSearching)).check(matches(isDisplayed()));
}
}

@Test
Expand All @@ -92,11 +102,11 @@ public void waitForPictureLayoutDisplayed() throws IllegalAccessException, NoSuc
cameraCallback.onCaptureFrame();
onView(withId(R.id.tracker_loading)).check(matches(isDisplayed()));
onView(withId(R.id.tracker_info)).check(matches(isDisplayed()));
onView(withId(R.id.loading_bar)).check(matches(isDisplayed()));
onView(withText(R.string.tiLoadingText)).check(matches(isDisplayed()));
}

@Test
public void switchToLiveActivity() throws Throwable{
public void switchToLiveActivity() throws Throwable {
String matchID = "some_id";
int selectedMatchType = 0;
int selectedServingSide = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ public void tearDown() {

@Test
public void testFindAllViews() {
onView(withId(R.id.debugScoreLayoutWrapper))
.check(matches(isDisplayed()));
onView(withId(R.id.playMovie_surfaceTracks))
.check(matches(isDisplayed()));
onView(withId(R.id.playMovie_surfaceTable))
Expand Down
17 changes: 13 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@
<activity
android:name="ch.m3ts.display.MatchWonActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">
</activity>
android:screenOrientation="landscape"></activity>
<activity
android:name="ch.m3ts.tutorial.TutorialActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"></activity>
<activity
android:name="ch.m3ts.tracker.init.InitTrackerActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@style/Recording">
</activity>
android:theme="@style/Recording"></activity>
<activity
android:name="ch.m3ts.tracker.visualization.live.LiveActivity"
android:configChanges=""
Expand Down Expand Up @@ -89,4 +91,11 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
</manifest>
11 changes: 11 additions & 0 deletions app/src/main/assets/gesture_indoor_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE properties SYSTEM
"http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>table location (2 corners)</comment>
<entry key="c1_x">26</entry>
<entry key="c1_y">496</entry>
<entry key="c2_x">1257</entry>
<entry key="c2_y">474</entry>
<entry key="n1_x">624</entry>
<entry key="n1_y">485</entry>
</properties>
11 changes: 11 additions & 0 deletions app/src/main/assets/gesture_outdoor_1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE properties SYSTEM
"http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>table location (2 corners)</comment>
<entry key="c1_x">6</entry>
<entry key="c1_y">387</entry>
<entry key="c2_x">1271</entry>
<entry key="c2_y">389</entry>
<entry key="n1_x">640</entry>
<entry key="n1_y">383</entry>
</properties>
Loading

0 comments on commit 5708aa6

Please sign in to comment.