-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathViewSpanTest.java
More file actions
66 lines (55 loc) · 2.37 KB
/
ViewSpanTest.java
File metadata and controls
66 lines (55 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.tokenautocomplete;
import android.content.Context;
import android.graphics.Paint;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
/**
* Instrumentation test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ViewSpanTest {
@Rule
public ActivityTestRule<TokenActivity> activityRule = new ActivityTestRule<>(
TokenActivity.class);
@Test
public void correctLineHeightWithBaseline() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
TextView textView = new TextView(appContext);
textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
textView.setText("A person's name");
ViewSpan span = new ViewSpan(textView, 100);
Paint paint = new Paint();
Paint.FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
int width = span.getSize(paint, "", 0, 0, fontMetricsInt);
assertEquals(width, textView.getRight());
assertEquals(textView.getHeight() - textView.getBaseline(), fontMetricsInt.bottom);
assertEquals(-textView.getBaseline(), fontMetricsInt.top);
}
@Test
public void correctLineHeightWithoutBaseline() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
View view = new View(appContext);
view.setMinimumHeight(1000);
view.setMinimumWidth(1000);
ViewSpan span = new ViewSpan(view, 100);
Paint paint = new Paint();
Paint.FontMetricsInt fontMetricsInt = paint.getFontMetricsInt();
int width = span.getSize(paint, "", 0, 0, fontMetricsInt);
assertEquals(width, 100);
assertEquals(0, fontMetricsInt.bottom);
assertEquals(-view.getHeight(), fontMetricsInt.top);
}
}