From 9b56a29be59058993f89466b3fccb78c018f1944 Mon Sep 17 00:00:00 2001
From: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Date: Thu, 23 Jan 2014 15:20:15 -0500
Subject: [PATCH] * #39226: add basic tests on HomeActivity

---
 .../org/sflphone/client/HomeActivityTest.java |  27 ++++-
 .../org/sflphone/client/ManagerImplTest.java  | 109 ------------------
 src/org/sflphone/client/HomeActivity.java     |   2 +-
 .../sflphone/fragments/DialingFragment.java   |   2 +-
 src/org/sflphone/fragments/HomeFragment.java  |   9 +-
 5 files changed, 34 insertions(+), 115 deletions(-)
 delete mode 100644 Tests/src/org/sflphone/client/ManagerImplTest.java

diff --git a/Tests/src/org/sflphone/client/HomeActivityTest.java b/Tests/src/org/sflphone/client/HomeActivityTest.java
index ecde418a1..a9759d756 100644
--- a/Tests/src/org/sflphone/client/HomeActivityTest.java
+++ b/Tests/src/org/sflphone/client/HomeActivityTest.java
@@ -2,6 +2,11 @@ package org.sflphone.client;
 
 import android.test.ActivityInstrumentationTestCase2;
 import junit.framework.Assert;
+import org.sflphone.R;
+import org.sflphone.fragments.AboutFragment;
+import org.sflphone.fragments.AccountsManagementFragment;
+import org.sflphone.fragments.HomeFragment;
+import org.sflphone.model.Account;
 
 /**
  * This is a simple framework for a test of an Application.  See
@@ -15,14 +20,30 @@ import junit.framework.Assert;
  */
 public class HomeActivityTest extends ActivityInstrumentationTestCase2<HomeActivity> {
 
+    HomeActivity mActivity;
+
     public HomeActivityTest() {
         super(HomeActivity.class);
     }
 
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        mActivity = getActivity();
+    }
+
+    public void testService() throws Exception {
+        Assert.assertTrue(mActivity.getService() != null);
+        Assert.assertTrue(mActivity.getService().getRecordPath() != null);
+    }
 
-    public void testStringForDisplay() throws Exception {
-        HomeActivity act_ = getActivity();
-        Assert.assertTrue(act_.getService() != null);
+    public void testSections() throws Exception {
+        mActivity.onSectionSelected(0);
+        Assert.assertTrue(mActivity.fContent instanceof HomeFragment);
+        mActivity.onSectionSelected(1);
+        Assert.assertTrue(mActivity.fContent instanceof AccountsManagementFragment);
+        mActivity.onSectionSelected(2);
+        Assert.assertTrue(mActivity.fContent instanceof AboutFragment);
     }
 
 }
diff --git a/Tests/src/org/sflphone/client/ManagerImplTest.java b/Tests/src/org/sflphone/client/ManagerImplTest.java
deleted file mode 100644
index 6f4f5d4b8..000000000
--- a/Tests/src/org/sflphone/client/ManagerImplTest.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.sflphone.client;
-/**
- * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
- *
- * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * Additional permission under GNU GPL version 3 section 7:
- *
- * If you modify this program, or any covered work, by linking or
- * combining it with the OpenSSL project's OpenSSL library (or a
- * modified version of that library), containing parts covered by the
- * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
- * grants you additional permission to convey the resulting work.
- * Corresponding Source for a non-source form of such a combination
- * shall include the source code for the parts of OpenSSL used as well
- * as that of the covered work.
- */
-
-
-        import java.lang.Thread;
-        import android.test.AndroidTestCase;
-        import org.sflphone.service.*;
-
-
-public class ManagerImplTest extends AndroidTestCase {
-    public static final String ACCOUNT_ID = "IP2IP";
-    public static final String CALLING_VALID_IP = "127.0.0.1";
-    public static final String CALLING_BAD_IP = "123.234.123.234";
-    public static final String CALL_ID = "1234567";
-    public static final int CALL_SLEEP_TIME = 1000; // in ms
-
-    static {
-        System.loadLibrary("gnustl_shared");
-        System.loadLibrary("crypto");
-        System.loadLibrary("ssl");
-        System.loadLibrary("sflphone");
-    }
-
-    ManagerImpl managerImpl;
-    private CallManager callManagerJNI;
-    private ConfigurationManager configurationManagerJNI;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        managerImpl = SFLPhoneservice.instance();
-        /* set static AppPath before calling manager.init */
-        // managerImpl.setPath(getApplication().getFilesDir().getAbsolutePath());
-        callManagerJNI = new CallManager();
-        configurationManagerJNI = new ConfigurationManager();
-        /*managerImpl.init("");*/
-
-        assertTrue(managerImpl != null);
-        assertTrue(callManagerJNI != null);
-        assertTrue(configurationManagerJNI != null);
-    }
-
-/*    @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-    }*/
-
-
-/*    public void testPlaceCallSuccessful() {
-        try {
-            callManagerJNI.placeCall(ACCOUNT_ID, CALL_ID, CALLING_VALID_IP);
-            assertTrue(true);
-
-            // FIXME: We should have a method returning the call state
-            //        and wait for the call to be in state CURRENT.
-            Thread.sleep(CALL_SLEEP_TIME);
-
-            callManagerJNI.hangUp(CALL_ID);
-            assertTrue(true);
-
-        } catch (InterruptedException e) {
-            assertTrue(false);
-        }
-    }*/
-
-    /*public void testPlaceCallBad() {
-        try {
-            callManagerJNI.placeCall(ACCOUNT_ID, CALL_ID, CALLING_BAD_IP);
-            assertTrue(true);
-
-            Thread.sleep(CALL_SLEEP_TIME);
-
-            callManagerJNI.hangUp(CALL_ID);
-            assertTrue(true);
-
-        } catch (InterruptedException e) {
-            assertTrue(false);
-        }
-    }*/
-}
diff --git a/src/org/sflphone/client/HomeActivity.java b/src/org/sflphone/client/HomeActivity.java
index d36540355..fbba34018 100644
--- a/src/org/sflphone/client/HomeActivity.java
+++ b/src/org/sflphone/client/HomeActivity.java
@@ -108,7 +108,7 @@ public class HomeActivity extends FragmentActivity implements DialingFragment.Ca
     private boolean isClosing = false;
     private Timer t = new Timer();
 
-    private Fragment fContent;
+    protected Fragment fContent;
 
     /* called before activity is killed, e.g. rotation */
     @Override
diff --git a/src/org/sflphone/fragments/DialingFragment.java b/src/org/sflphone/fragments/DialingFragment.java
index 3ab822e10..dd1a07b89 100644
--- a/src/org/sflphone/fragments/DialingFragment.java
+++ b/src/org/sflphone/fragments/DialingFragment.java
@@ -120,7 +120,7 @@ public class DialingFragment extends Fragment implements OnTouchListener {
         View inflatedView = inflater.inflate(R.layout.frag_dialing, parent, false);
 
         textField = (ClearableEditText) inflatedView.findViewById(R.id.textField);
-        ((ImageButton) inflatedView.findViewById(R.id.buttonCall)).setOnClickListener(new OnClickListener() {
+        inflatedView.findViewById(R.id.buttonCall).setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
 
diff --git a/src/org/sflphone/fragments/HomeFragment.java b/src/org/sflphone/fragments/HomeFragment.java
index fff0dc8a0..3bd52a664 100644
--- a/src/org/sflphone/fragments/HomeFragment.java
+++ b/src/org/sflphone/fragments/HomeFragment.java
@@ -50,7 +50,7 @@ public class HomeFragment extends Fragment {
      * The {@link ViewPager} that will host the section contents.
      */
     ViewPager mViewPager;
-    SectionsPagerAdapter mSectionsPagerAdapter = null;
+    SectionsPagerAdapter mSectionsPagerAdapter;
 
     @Override
     public void onResume() {
@@ -112,4 +112,11 @@ public class HomeFragment extends Fragment {
         }
     }
 
+    public SectionsPagerAdapter getSectionsPagerAdapter() {
+        return mSectionsPagerAdapter;
+    }
+
+    public ViewPager getViewPager() {
+        return mViewPager;
+    }
 }
\ No newline at end of file
-- 
GitLab