Skip to content

Commit

Permalink
#54 correctif des tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aekathens03 committed Apr 10, 2019
1 parent 5fc9924 commit 6fdf083
Show file tree
Hide file tree
Showing 26 changed files with 300 additions and 90 deletions.
26 changes: 20 additions & 6 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
//noinspection GradleDependency
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "projet.license"
minSdkVersion 21
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
sourceSets {
// ajout de la partie commune
main.java.srcDirs += '../../../javastd/commun/src/main/java'
main.java.srcDirs += '../../javastd/commun/src/main/java'
// et quand il y aura des tests...
// test.java.srcDirs += '../../../javastd/commun/src/test/java'
test.java.srcDirs += '../../javastd/commun/src/test/java'
}
buildTypes {
release {
Expand All @@ -32,13 +33,26 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'junit:junit:4.12'

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'

implementation('io.socket:socket.io-client:1.0.0') {
exclude group: 'org.json', module: 'json'
// car cela est dans le java android
}
testImplementation 'androidx.test:core:1.1.0'

androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
//noinspection GradleDynamicVersion
androidTestImplementation 'com.android.support:support-annotations:28+'

}
56 changes: 56 additions & 0 deletions android/app/src/androidTest/java/projet/license/MyViewAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package projet.license;

import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;

import org.hamcrest.Matcher;

import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.matcher.ViewMatchers;

public class MyViewAction {
public static ViewAction singleTouchAt(final int x, final int y, final int action) {
return new ViewAction() {
@Override
public void perform(UiController uiController, View view) {
long date = SystemClock.uptimeMillis();
MotionEvent me = MotionEvent.obtain(date, date, action, x, y, 0);
view.onTouchEvent(me);
}

@Override
public String getDescription() {
return "touch ";
}

@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isAssignableFrom(View.class);
}
};
}


public static ViewAction pamatreziedSingleTouchAt(final float x, final float y, final int action, final long d1, final long d2, final int meta) {
return new ViewAction() {
@Override
public void perform(UiController uiController, View view) {
MotionEvent me = MotionEvent.obtain(d1, d2, action, x, y, meta);
view.onTouchEvent(me);
}

@Override
public String getDescription() {
return "touch ";
}

@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isAssignableFrom(View.class);
}
};
}

}
84 changes: 84 additions & 0 deletions android/app/src/androidTest/java/projet/license/RiddleGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package projet.license;


import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import androidx.test.espresso.ViewInteraction;
import androidx.test.rule.ActivityTestRule;
import androidx.test.runner.AndroidJUnit4;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.core.AllOf.allOf;


@RunWith(AndroidJUnit4.class)
public class RiddleGame {

@Rule
public ActivityTestRule<LoginActivity> mActivityTestRule = new ActivityTestRule<>(LoginActivity.class);

@Test
public void riddleGame() {
ViewInteraction button = onView(
allOf(withId(R.id.loginConfim), withText("confirm"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
3),
isDisplayed()));
button.perform(click());

ViewInteraction button2 = onView(
allOf(withId(R.id.Riddle), withText("RIDDLES"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
3),
isDisplayed()));
button2.perform(click());

ViewInteraction button3 = onView(
allOf(withId(R.id.start), withText("START"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
2),
isDisplayed()));
button3.perform(click());
}

private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {

return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}

@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
}
3 changes: 2 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
xmlns:tools="http://schemas.android.com/tools"
package="projet.license">
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/java/commun/Affichage.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package commun;

import java.util.List;

public interface Affichage {

void majScor(boolean ok);
Expand All @@ -14,4 +12,6 @@ public interface Affichage {

void riddleGame(boolean rep);


// void majGraphic(String message, Bundle parameters);
}
45 changes: 40 additions & 5 deletions android/app/src/main/java/commun/Controleur.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package commun;


import java.util.List;


import android.os.Bundle;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

public class Controleur {
Connexion connexion;
Expand Down Expand Up @@ -35,7 +37,16 @@ public void majScor(boolean verif) {
}

public void timeGameScor(Integer scor,Integer tentative) {
getAffichage().timeGameScor(scor,tentative); }
getAffichage().timeGameScor(scor,tentative);

/*
Bundle bundle = new Bundle();
bundle.putInt("scor", scor);
bundle.putInt("tentative", tentative);
getAffichage().majGraphic("timeGameScor", bundle);
*/

}

public void listTimeGame(String listFormeDem,String listFormeRec) {
getAffichage().listTimeGame(listFormeDem,listFormeRec);
Expand All @@ -59,9 +70,33 @@ public Affichage getAffichage() {
public void timeDetectorValider(String image) {connexion.timeImage(image);}


public void endTimeGame() {connexion.endTimeGame(); }
public void endTimeGame() {connexion.endTimeGame();

}
public void listTimeGame2(){connexion.listResTimeGame();}

public void rtoValider(String image) {connexion.rtoImage(image);}
public void riddleValider(String image) {connexion.riddleImage(image);}



//pour recuperer l'adressIp
public String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf
.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
}
return "";
}

}
20 changes: 0 additions & 20 deletions android/app/src/main/java/commun/Identification.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public class DrawDetectorActivity extends Activity implements View.OnClickListe
private String formeDemande = "Press start";
public PaintView myCanvas;
final String[] formes = {"Point", "Segment", "Triangle", "Carre", "Rond"};
private RelativeLayout mRelativeLayout;
private Context mContext;
private int textCol;
private boolean debut = true;



Expand All @@ -48,9 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {


ctrl = new Controleur(this);
//tilefono
//Connexion connexion = new Connexion("http://192.168.0.101:10101",ctrl);
Connexion connexion = new Connexion("http://172.20.10.2:10101", ctrl);
Connexion connexion = new Connexion("http://192.168.0.100:10101", ctrl);
connexion.seConnecter();


Expand Down Expand Up @@ -78,7 +72,6 @@ private void init() {



mContext = getApplicationContext();
myCanvas = findViewById(R.id.myCanvas);

effacer.setOnClickListener(this);
Expand Down
1 change: 0 additions & 1 deletion android/app/src/main/java/projet/license/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected void onCreate(Bundle savedInstanceState){
valider.setOnClickListener(this);

ctrl = new Controleur(this);
Connexion connexion = new Connexion("http://172.20.10.2:10101", ctrl);
Connexion connexion = new Connexion("http://192.168.0.100:10101", ctrl);
connexion.seConnecter();

}
Expand Down
4 changes: 1 addition & 3 deletions android/app/src/main/java/projet/license/RiddleActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {


ctrl = new Controleur(this);
//tilefono
//Connexion connexion = new Connexion("http://192.168.0.101:10101",ctrl);
Connexion connexion = new Connexion("http://172.20.10.2:10101", ctrl);
Connexion connexion = new Connexion("http://192.168.0.100:10101", ctrl);
connexion.seConnecter();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ protected void onCreate(Bundle savedInstanceState) {


ctrl = new Controleur((Affichage) this);
//fac
//Connexion connexion = new Connexion("http://10.1.124.22:10101",ctrl);
//spiti
//Connexion connexion = new Connexion("http://192.168.0.18:10101", ctrl);
//tilefono
Connexion connexion = new Connexion("http://172.20.10.2:10101",ctrl);
Connexion connexion = new Connexion("http://192.168.0.100:10101", ctrl);
connexion.seConnecter();


Expand Down
Loading

0 comments on commit 6fdf083

Please sign in to comment.