Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0f516a0
minor detail change: Question and Ans don't get out of screen/box whe…
Apr 8, 2021
a854ee5
Merge branch 'main' of https://github.com/CMPUT301W21T31/Quantify int…
Apr 9, 2021
4513982
Test Cases for Experiment
Apr 9, 2021
1c8e126
making result card xml separate
mimjahratul Apr 9, 2021
ea2afc4
Trial statistics now available
arghoroy98 Apr 9, 2021
aea583f
Merge pull request #55 from CMPUT301W21T31/nahin-p4-exp
NahinChowdhury Apr 9, 2021
13d5df8
Merge remote-tracking branch 'origin/main' into mim2
mimjahratul Apr 9, 2021
cfb2352
removing extra icons
mimjahratul Apr 9, 2021
51b38cf
Merge pull request #57 from CMPUT301W21T31/mim2
mimjahratul Apr 9, 2021
8d137ef
Add files via upload
mimjahratul Apr 9, 2021
c99b3fb
Generate QR code done for every trial
Halo103109 Apr 10, 2021
4558721
Merge pull request #56 from CMPUT301W21T31/adit-p4
NahinChowdhury Apr 10, 2021
d0bb363
scan early version
Halo103109 Apr 10, 2021
f5dcdbc
ignoring now works for binimial trials
NahinChowdhury Apr 10, 2021
76724fd
QR scanning final version
Halo103109 Apr 10, 2021
15a5e7e
Merge branch 'main' of https://github.com/CMPUT301W21T31/Quantify int…
NahinChowdhury Apr 10, 2021
426ed0d
performed some error checking for searching
NahinChowdhury Apr 10, 2021
67ffd4a
Merge branch 'yiheng' into main_backup
yikkr Apr 12, 2021
3dd9def
barcode
yikkr Apr 12, 2021
82a625a
fixed barcode crashing issue
Halo103109 Apr 13, 2021
15aa61b
demo version 1.0
Halo103109 Apr 13, 2021
d9e49e4
barcode fix
yikkr Apr 14, 2021
f9c8e77
minor fix barcode
yikkr Apr 14, 2021
3dc3ca3
minor fix
yikkr Apr 14, 2021
14d7b22
Final version
Halo103109 Apr 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions app/src/androidTest/java/com/example/quantify/ExperimentTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package com.example.quantify;

import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;
import com.robotium.solo.Solo;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
* VERY IMPORTANT NOTE
* MANY OF THE TEST CASES ARE BUILT ON SPECIFIC DATA SAVED ON DATABASE AT THE TIME OF TESTING
* SO THEY MIGHT NOT WORK/GIVE ERROR LATER ON. ALSO MANY OF THE TEST CASES ARE BUILT ON
* ROBOTIUM SCREEN COORDINATES THAT HELPED TO REAL PLACE WHICH WAS BEING TESTED SO RUNNING THEM
* LATER WILL GIVE THE SAME ERROR. TO USE THESE SPECIFIC TEST CASES, KNOW WHAT YOU ARE DOING.
*/

public class ExperimentTest {

private Solo solo;

@Rule
public ActivityTestRule<MainActivity> rule =
new ActivityTestRule<>(MainActivity.class, true, true);

/**
* Runs before all tests and creates solo instance.
* @throws Exception
*/
@Before
public void setUp() throws Exception{
solo = new Solo(InstrumentationRegistry.getInstrumentation(),rule.getActivity());
}

/**
* Gets the Activity
* @throws Exception
*/
@Test
public void start() throws Exception{
Activity activity = rule.getActivity();
}

/**
* This test checks if has anything on the screen at start (should be nothing as new user),
* then creates an experiment. Then checks again if he has the experiment now or not.
*/
@Test
public void publish() {
solo.assertCurrentActivity("Wrong Activity", MainActivity.class);

Activity activity = (Activity)solo.getCurrentActivity();
ListView listview = (ListView)solo.getView(R.id.exp_list);
int countPersonalExp = listview.getAdapter().getCount();

// The list should be empty
assertEquals(0, countPersonalExp);

// Now that we are good upto this point, next, create an experiment.
solo.clickOnView(solo.getView(R.id.floatingActionButton));
solo.enterText((EditText) solo.getView(R.id.exp_desc_fragment), "UI Testing");
solo.clearEditText((EditText) solo.getView(R.id.exp_desc_fragment)); //Clear the EditText
solo.enterText((EditText) solo.getView(R.id.exp_min_trials), "5");
solo.clearEditText((EditText) solo.getView(R.id.exp_min_trials)); //Clear the EditText

// Selecting which experiment type is it
solo.clickOnView(solo.getView(R.id.exp_type_fragment, 0));
solo.scrollToTop();
solo.clickOnView(solo.getView(TextView.class, 0)); // We choose you Binomial!

//solo.clickOnButton("OK");
solo.clickOnScreen(866, 1661);
// Do we return back to main activity?
solo.assertCurrentActivity("Wrong Activity, need Main activity", MainActivity.class);
// Check if our experiment is created
countPersonalExp = listview.getAdapter().getCount();
assertTrue(solo.waitForText("UI Testing", 1, 2000));
}

@Test
public void unpublish() {
solo.clickOnScreen(755, 780);
ListView listview = (ListView)solo.getView(R.id.exp_list);
int countPersonalExp = listview.getAdapter().getCount();
// The experiment should be gone
assertEquals(0, countPersonalExp);

}

@Test
public void end() {
solo.clickOnScreen(289, 766);
solo.clickOnText("UI Testing");
solo.clickOnScreen(366, 1343);
// the result is already 3 and it should not change
assertTrue(solo.waitForText("3", 1, 2000));
}

@Test
public void subscribe() {
solo.clickOnScreen(808, 285);
ListView listview = (ListView)solo.getView(R.id.exp_list);

// this subscribes the second row of all experiments
//String listValue = listview.getItemAtPosition(1).toString();
solo.clickLongOnScreen(459, 872);

// lets see if we can find the subscribed experiment
solo.clickOnScreen(607, 2005);
assertTrue(solo.waitForText("HaloPhoneTest", 1, 2000));

}

@Test
public void addTrials() {
solo.clickOnScreen(808, 285); // all experiment tab
solo.clickOnScreen(521, 1560); // experiment from list
solo.clickOnScreen(848, 1355); // proceed

solo.clickOnScreen(541, 1688); // start
solo.clickOnScreen(366, 1349); // success
solo.clickOnScreen(550, 1563); // save

// previous ans was 4, there is one place it should be 5
assertTrue(solo.searchText("1"));

}



/**
* Closes the activity after each test
* @throws Exception
*/
@After
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class MainActivityTest_2 {
public class MainActivityTest_2 {
private Solo solo;
@Rule
public ActivityTestRule<MainActivity> rule =
Expand Down Expand Up @@ -56,8 +56,8 @@ public void checkList(){
//solo.clickOnButton("Add New"); //select Add New
//Get view for EditText and enter the info
solo.enterText((EditText) solo.getView(R.id.exp_desc_fragment), "FunctionTest1");
solo.enterText((EditText) solo.getView(R.id.exp_user_fragment), "Halo_test_robot");
solo.enterText((EditText) solo.getView(R.id.exp_status_fragment), "RUNNING");
//solo.enterText((EditText) solo.getView(R.id.exp_user_fragment), "Halo_test_robot");
//solo.enterText((EditText) solo.getView(R.id.exp_status_fragment), "RUNNING");
solo.enterText((EditText) solo.getView(R.id.exp_type_fragment), "Binomial");
//can't find the OK button in AlertDialog
solo.clickOnText("Ok");
Expand Down
29 changes: 29 additions & 0 deletions app/src/androidTest/java/com/example/quantify/SubscribedTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.quantify;


import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;

import com.robotium.solo.Solo;

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

public class SubscribedTest {
private Solo solo;

@Rule
public ActivityTestRule<SubscribedActivity> rule =
new ActivityTestRule<>(SubscribedActivity.class, true, true);

@Before
public void setUp() {
solo = new Solo(InstrumentationRegistry.getInstrumentation(), rule.getActivity());
}

@Test
public void start() {
SubscribedActivity activity = rule.getActivity();
}
}
29 changes: 29 additions & 0 deletions app/src/androidTest/java/com/example/quantify/TrialTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.quantify;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;

import com.robotium.solo.Solo;

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

public class TrialTest {
private Solo solo;

@Rule
public ActivityTestRule<Trial> rule =
new ActivityTestRule<>(Trial.class, true, true);

@Before
public void setUp() {
solo = new Solo(InstrumentationRegistry.getInstrumentation(), rule.getActivity());
}

@Test
public void start() {
Trial activity = rule.getActivity();
}
}

42 changes: 42 additions & 0 deletions app/src/androidTest/java/com/example/quantify/UserProfileTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.quantify;

import android.app.Activity;
import android.widget.EditText;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;

import com.robotium.solo.Solo;

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

public class UserProfileTest {
private Solo solo;

@Rule
public ActivityTestRule<com.example.quantify.ShowUserProfile> rule =
new ActivityTestRule<>(com.example.quantify.ShowUserProfile.class, true, true);

@Before
public void setUp() {
solo = new Solo(InstrumentationRegistry.getInstrumentation(), rule.getActivity());
}

@Test
public void start() {
com.example.quantify.ShowUserProfile activity = rule.getActivity();
}

/*@Test
public void checkList() {
solo.assertCurrentActivity("Wrong activity", ShowUserProfile.class);
solo.clickOnButton("Phone");
solo.enterText((EditText) solo.getView(R.id.edit_text), "+1-202-555-0157");
solo.clickOnButton("OK");
}*/
}



54 changes: 40 additions & 14 deletions app/src/main/java/com/example/quantify/BinomialTrialActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.Settings;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.firestore.CollectionReference;
Expand All @@ -32,7 +24,6 @@
import com.google.zxing.WriterException;
import com.journeyapps.barcodescanner.BarcodeEncoder;

import java.lang.reflect.Array;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
Expand All @@ -41,7 +32,6 @@
import java.util.UUID;

import androidmads.library.qrgenearator.QRGContents;
import androidmads.library.qrgenearator.QRGEncoder;
import androidmads.library.qrgenearator.QRGSaver;

public class BinomialTrialActivity extends AppCompatActivity {
Expand All @@ -63,7 +53,7 @@ public class BinomialTrialActivity extends AppCompatActivity {

Button save;
Button generateQR;
ImageView imageView;
ImageView binomialQRImage;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -94,15 +84,51 @@ protected void onCreate(Bundle savedInstanceState) {
String savePath = Environment.getExternalStorageDirectory().getPath() + "/QRCode/";
String TAG = "GenerateQRCode";
UUID thisExperimentID = exp.getExperimentID();
imageView = findViewById(R.id.imageView);
binomialQRImage = findViewById(R.id.binomialQRImage);
generateQR.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String inputValue = thisExperimentID.toString() + ";" + result.getText().toString();
if (result.getText().toString().equals("_____")) {
Toast.makeText(getApplicationContext(), "The Trial result is empty, please enter result.", Toast.LENGTH_LONG).show();
return;
}

String inputValue = thisExperimentID.toString() + ";" + exp.getDescription() + ";" + result.getText().toString();
try{
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bitmap = barcodeEncoder.encodeBitmap(inputValue, BarcodeFormat.QR_CODE,400,400);
imageView.setImageBitmap(bitmap);
binomialQRImage.setImageBitmap(bitmap);

Log.d("expdesc", exp.getDescription());

FirebaseFirestore db;
db = FirebaseFirestore.getInstance();
final CollectionReference collectionReference = db.collection("Barcodes");

HashMap<String, String> data = new HashMap<>();
data.put("Associate Exp", thisExperimentID.toString());
data.put("Experiment desc", exp.getDescription());
data.put("Result", result.getText().toString());
data.put("Type", "Binomial Trials");

collectionReference
.document(inputValue)
.set(data)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// These are a method which gets executed when the task is succeeded
Log.d("TAG", "Data has been added successfully!");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// These are a method which gets executed if there’s any problem
Log.d("TAG", "Data could not be added!" + e.toString());
}
});

boolean save;
String result;
try {
Expand Down
Loading