10194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta/* 20194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * Copyright (C) 2015 The Android Open Source Project 30194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * 40194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * Licensed under the Apache License, Version 2.0 (the "License"); 50194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * you may not use this file except in compliance with the License. 60194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * You may obtain a copy of the License at 70194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * 80194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * http://www.apache.org/licenses/LICENSE-2.0 90194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * 100194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * Unless required by applicable law or agreed to in writing, software 110194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * distributed under the License is distributed on an "AS IS" BASIS, 120194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * See the License for the specific language governing permissions and 140194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta * limitations under the License. 150194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta */ 160194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta 170194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Guptapackage android.support.v7.widget.test; 180194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta 190194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Guptaimport android.app.Activity; 200194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Guptaimport android.support.v7.recyclerview.test.CustomLayoutManager; 210194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Guptaimport android.support.v7.recyclerview.test.R; 220194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Guptaimport android.support.v7.widget.GridLayoutManager; 230194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Guptaimport android.support.v7.widget.RecyclerView; 240194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Guptaimport android.test.ActivityInstrumentationTestCase2; 250194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Guptaimport android.widget.LinearLayout; 260194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta 270194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Guptapublic class RecyclerViewTest extends ActivityInstrumentationTestCase2<RecyclerViewTestActivity> { 280194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta 290194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta public RecyclerViewTest() { 300194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta super("android.support.v7.widget.test", RecyclerViewTestActivity.class); 310194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta } 320194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta 330194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta private void setContentView(final int layoutId) throws Throwable { 340194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta final Activity activity = getActivity(); 350194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta runTestOnUiThread(new Runnable() { 360194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta @Override 370194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta public void run() { 380194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta activity.setContentView(layoutId); 390194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta } 400194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta }); 410194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta } 420194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta 430194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta public void testInflation() throws Throwable { 440194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta setContentView(R.layout.inflation_test); 450194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta getInstrumentation().waitForIdleSync(); 460194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta RecyclerView view = (RecyclerView) getActivity().findViewById(R.id.recyclerView); 470194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta RecyclerView.LayoutManager layoutManager = view.getLayoutManager(); 480194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertNotNull("LayoutManager not created.", layoutManager); 490194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertEquals("Incorrect LayoutManager created", 500194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta layoutManager.getClass().getName(), GridLayoutManager.class.getName()); 510194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta GridLayoutManager gridLayoutManager = ((GridLayoutManager) layoutManager); 520194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertEquals("Incorrect span count.", 3, gridLayoutManager.getSpanCount()); 530194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertEquals("Expected horizontal orientation.", 540194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta LinearLayout.HORIZONTAL, gridLayoutManager.getOrientation()); 550194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertTrue("Expected reversed layout", gridLayoutManager.getReverseLayout()); 560194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta 570194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta view = (RecyclerView) getActivity().findViewById(R.id.recyclerView2); 580194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta layoutManager = view.getLayoutManager(); 590194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertNotNull("LayoutManager not created.", layoutManager); 600194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertEquals("Incorrect LayoutManager created", 610194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta layoutManager.getClass().getName(), 620194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta CustomLayoutManager.class.getName()); 630194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta CustomLayoutManager customLayoutManager = 640194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta (CustomLayoutManager) layoutManager; 650194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertEquals("Expected vertical orientation.", 660194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta LinearLayout.VERTICAL, customLayoutManager.getOrientation()); 670194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertTrue("Expected items to be stacked from end", customLayoutManager.getStackFromEnd()); 680194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta 690194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta view = (RecyclerView) getActivity().findViewById(R.id.recyclerView3); 700194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta layoutManager = view.getLayoutManager(); 710194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertNotNull("LayoutManager not created.", layoutManager); 720194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta assertEquals("Incorrect LayoutManager created", 730194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta layoutManager.getClass().getName(), 740194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta CustomLayoutManager.LayoutManager.class.getName()); 750194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta 76ec494eb6490aae36981351d80c778031efcf2ebeYigit Boyar view = (RecyclerView) getActivity().findViewById(R.id.recyclerView4); 77ec494eb6490aae36981351d80c778031efcf2ebeYigit Boyar layoutManager = view.getLayoutManager(); 78ec494eb6490aae36981351d80c778031efcf2ebeYigit Boyar assertNotNull("LayoutManager not created.", layoutManager); 79ec494eb6490aae36981351d80c778031efcf2ebeYigit Boyar assertEquals("Incorrect LayoutManager created", 80ec494eb6490aae36981351d80c778031efcf2ebeYigit Boyar "android.support.v7.recyclerview.test.PrivateLayoutManager", 81ec494eb6490aae36981351d80c778031efcf2ebeYigit Boyar layoutManager.getClass().getName()); 82ec494eb6490aae36981351d80c778031efcf2ebeYigit Boyar 830194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta } 840194ed84ad6f1d3d489db52b9431fa93a7697b50Deepanshu Gupta} 85