blob: 1d4d679daf190d1e2b1d91d09145d26d6d4de432 [file] [log] [blame]
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.view.cts;
import java.io.IOException;
import org.xmlpull.v1.XmlPullParserException;
import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.test.AndroidTestCase;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import com.android.cts.stub.R;
import com.android.internal.util.XmlUtils;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.ToBeFixed;
@TestTargetClass(ViewGroup.LayoutParams.class)
public class ViewGroup_LayoutParamsTest extends AndroidTestCase {
private ViewGroup.LayoutParams mLayoutParams;
@TestTargets({
@TestTargetNew(
level = TestLevel.TODO,
notes = "Test constructors",
method = "ViewGroup.LayoutParams",
args = {int.class, int.class}
),
@TestTargetNew(
level = TestLevel.TODO,
notes = "Test constructors",
method = "ViewGroup.LayoutParams",
args = {android.content.Context.class, android.util.AttributeSet.class}
),
@TestTargetNew(
level = TestLevel.TODO,
notes = "Test constructors",
method = "ViewGroup.LayoutParams",
args = {android.view.ViewGroup.LayoutParams.class}
)
})
public void testConstructor() throws XmlPullParserException, IOException {
// new the MarginLayoutParams instance
XmlResourceParser parser = mContext.getResources().getLayout(
R.layout.viewgroup_margin_layout);
XmlUtils.beginDocument(parser, "LinearLayout");
new ViewGroup.LayoutParams(mContext, parser);
LayoutParams temp = new ViewGroup.LayoutParams(320, 480);
new ViewGroup.LayoutParams(temp);
}
@TestTargetNew(
level = TestLevel.TODO,
notes = "Test setBaseAttributes(TypedArray, int, int)",
method = "setBaseAttributes",
args = {android.content.res.TypedArray.class, int.class, int.class}
)
public void testSetBaseAttributes() throws XmlPullParserException, IOException {
MockLayoutParams mockLayoutParams = new MockLayoutParams(240, 320);
XmlResourceParser parser = mContext.getResources().getLayout(
R.layout.viewgroup_margin_layout);
XmlUtils.beginDocument(parser, "LinearLayout");
TypedArray array = mContext.obtainStyledAttributes(parser,
com.android.internal.R.styleable.ViewGroup_Layout);
mockLayoutParams.setBaseAttributes(array,
com.android.internal.R.styleable.ViewGroup_Layout_layout_width,
com.android.internal.R.styleable.ViewGroup_Layout_layout_height);
array.recycle();
assertEquals(213, mockLayoutParams.width);
assertEquals(319, mockLayoutParams.height);
try {
mockLayoutParams.setBaseAttributes(null,
com.android.internal.R.styleable.ViewGroup_Layout_layout_width,
com.android.internal.R.styleable.ViewGroup_Layout_layout_height);
fail("should throw NullPointerException");
} catch (NullPointerException e) {
}
}
private class MockLayoutParams extends LayoutParams {
public MockLayoutParams(Context c, AttributeSet attrs) {
super(c, attrs);
}
public MockLayoutParams(int width, int height) {
super(width, height);
}
public MockLayoutParams(LayoutParams source) {
super(source);
}
protected void setBaseAttributes(TypedArray a, int widthAttr, int heightAttr) {
super.setBaseAttributes(a, widthAttr, heightAttr);
}
}
}