1bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam/* 2bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * Copyright (C) 2015 The Android Open Source Project 3bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * 4bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * Licensed under the Apache License, Version 2.0 (the "License"); 5bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * you may not use this file except in compliance with the License. 6bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * You may obtain a copy of the License at 7bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * 8bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * http://www.apache.org/licenses/LICENSE-2.0 9bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * 10bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * Unless required by applicable law or agreed to in writing, software 11bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * distributed under the License is distributed on an "AS IS" BASIS, 12bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * See the License for the specific language governing permissions and 14bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam * limitations under the License. 15bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam */ 16bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 17bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lampackage com.android.setupwizardlib.test; 18bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 19bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lamimport android.content.Context; 20bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lamimport android.test.InstrumentationTestCase; 21bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lamimport android.test.suitebuilder.annotation.SmallTest; 22bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lamimport android.view.LayoutInflater; 23bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lamimport android.view.View; 24bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lamimport android.widget.TextView; 25bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 26bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lamimport com.android.setupwizardlib.TemplateLayout; 27bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 28bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lampublic class TemplateLayoutTest extends InstrumentationTestCase { 29bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 30bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam private Context mContext; 31bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 32bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam @Override 33bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam protected void setUp() throws Exception { 34bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam super.setUp(); 35bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam mContext = getInstrumentation().getContext(); 36bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam } 37bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 38bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam @SmallTest 39bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam public void testAddView() { 40bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam TemplateLayout layout = new TemplateLayout(mContext, R.layout.test_template, 41bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam R.id.suw_layout_content); 42bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam TextView tv = new TextView(mContext); 43bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam tv.setId(R.id.test_view_id); 44bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam layout.addView(tv); 45bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam View view = layout.findViewById(R.id.test_view_id); 46bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam assertSame("The view added should be the same text view", tv, view); 47bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam } 48bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 49bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam @SmallTest 50bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam public void testInflateFromXml() { 51bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam LayoutInflater inflater = LayoutInflater.from(mContext); 52bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam TemplateLayout layout = 53bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam (TemplateLayout) inflater.inflate(R.layout.test_template_layout, null); 54bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam View content = layout.findViewById(R.id.test_content); 55bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam assertTrue("@id/test_content should be a TextView", content instanceof TextView); 56bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam } 57bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 58bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam @SmallTest 59bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam public void testTemplate() { 60bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam TemplateLayout layout = new TemplateLayout(mContext, R.layout.test_template, 61bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam R.id.suw_layout_content); 62bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam View templateView = layout.findViewById(R.id.test_template_view); 63bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam assertNotNull("@id/test_template_view should exist in template", templateView); 64bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 65bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam TextView tv = new TextView(mContext); 66bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam tv.setId(R.id.test_view_id); 67bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam layout.addView(tv); 68bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 69bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam templateView = layout.findViewById(R.id.test_template_view); 70bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam assertNotNull("@id/test_template_view should exist in template", templateView); 71bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam View contentView = layout.findViewById(R.id.test_view_id); 72bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam assertSame("The view added should be the same text view", tv, contentView); 73bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam } 74bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam 75bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam @SmallTest 76bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam public void testNoTemplate() { 77bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam try { 78bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam new TemplateLayout(mContext, 0, 0); 79bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam fail("Inflating TemplateLayout without template should throw exception"); 80bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam } catch (IllegalArgumentException e) { 81bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam // Expected IllegalArgumentException 82bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam } 83bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam } 84bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam} 85