Skip to content

Commit 2a0a594

Browse files
committed
Add more transformation regression tests.
1 parent f89f2f4 commit 2a0a594

File tree

105 files changed

+314
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+314
-3
lines changed

instrumentation/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ dependencies {
1010
// loading classes functions. It's not clear why androidTestCompile isn't sufficient, but for
1111
// whatever reason, compile is the only dependency that seems to work.
1212
compile "com.android.support:appcompat-v7:${ANDROID_SUPPORT_VERSION}"
13-
androidTestCompile project(":annotation:compiler")
13+
annotationProcessor project(":annotation:compiler")
14+
compile project(":library")
15+
1416
androidTestCompile project(':library')
1517
androidTestCompile "org.mockito:mockito-android:${MOCKITO_ANDROID_VERSION}"
1618
androidTestCompile "com.android.support:support-fragment:${ANDROID_SUPPORT_VERSION}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.bumptech.glide;
2+
3+
import static com.google.common.truth.Truth.assertThat;
4+
5+
import android.content.Context;
6+
import android.graphics.Bitmap;
7+
import android.support.test.InstrumentationRegistry;
8+
import android.support.test.runner.AndroidJUnit4;
9+
import com.bumptech.glide.test.BitmapRegressionTester;
10+
import com.bumptech.glide.test.CanonicalBitmap;
11+
import com.bumptech.glide.test.GlideApp;
12+
import com.bumptech.glide.test.RegressionTest;
13+
import com.bumptech.glide.test.SplitByCpu;
14+
import com.bumptech.glide.test.SplitBySdk;
15+
import com.bumptech.glide.test.TearDownGlide;
16+
import java.util.concurrent.ExecutionException;
17+
import org.junit.Before;
18+
import org.junit.Rule;
19+
import org.junit.Test;
20+
import org.junit.rules.TestName;
21+
import org.junit.runner.RunWith;
22+
23+
@RunWith(AndroidJUnit4.class)
24+
@RegressionTest
25+
@SplitByCpu
26+
@SplitBySdk({24, 21, 16})
27+
public class CenterCropRegressionTest {
28+
@Rule public TestName testName = new TestName();
29+
@Rule public TearDownGlide tearDownGlide = new TearDownGlide();
30+
private BitmapRegressionTester bitmapRegressionTester;
31+
private Context context;
32+
private CanonicalBitmap canonical;
33+
34+
@Before
35+
public void setUp() {
36+
context = InstrumentationRegistry.getTargetContext();
37+
bitmapRegressionTester = new BitmapRegressionTester(getClass(), testName);
38+
canonical = new CanonicalBitmap();
39+
}
40+
41+
@Test
42+
public void centerCrop_withSquareSmallerThanImage_returnsSquareImage()
43+
throws ExecutionException, InterruptedException {
44+
Bitmap result =
45+
bitmapRegressionTester.test(
46+
GlideApp.with(context)
47+
.asBitmap()
48+
.load(canonical.getBitmap())
49+
.centerCrop()
50+
.override(50));
51+
assertThat(result.getWidth()).isEqualTo(50);
52+
assertThat(result.getHeight()).isEqualTo(50);
53+
}
54+
55+
@Test
56+
public void centerCrop_withRectangleSmallerThanImage_returnsRectangularImage()
57+
throws ExecutionException, InterruptedException {
58+
Bitmap result =
59+
bitmapRegressionTester.test(
60+
GlideApp.with(context)
61+
.asBitmap()
62+
.load(canonical.getBitmap())
63+
.centerCrop()
64+
.override(60, 70));
65+
assertThat(result.getWidth()).isEqualTo(60);
66+
assertThat(result.getHeight()).isEqualTo(70);
67+
}
68+
69+
@Test
70+
public void centerCrop_withSquareLargerThanImage_returnsUpscaledRectangularImage()
71+
throws ExecutionException, InterruptedException {
72+
Bitmap result =
73+
bitmapRegressionTester.test(
74+
GlideApp.with(context)
75+
.asBitmap()
76+
.load(canonical.getBitmap())
77+
.centerCrop()
78+
.override(canonical.getWidth() * 2));
79+
assertThat(result.getWidth()).isEqualTo(canonical.getWidth() * 2);
80+
assertThat(result.getHeight()).isEqualTo(canonical.getWidth() * 2);
81+
}
82+
83+
@Test
84+
public void centerCrop_withRectangleLargerThanImage_returnsUpscaledRectangularImage()
85+
throws ExecutionException, InterruptedException {
86+
Bitmap result =
87+
bitmapRegressionTester.test(
88+
GlideApp.with(context)
89+
.asBitmap()
90+
.load(canonical.getBitmap())
91+
.centerCrop()
92+
.override(canonical.getWidth() * 2, canonical.getHeight() * 2));
93+
assertThat(result.getWidth()).isEqualTo(canonical.getWidth() * 2);
94+
assertThat(result.getHeight()).isEqualTo(canonical.getHeight() * 2);
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.bumptech.glide;
2+
3+
import static com.google.common.truth.Truth.assertThat;
4+
5+
import android.content.Context;
6+
import android.graphics.Bitmap;
7+
import android.support.test.InstrumentationRegistry;
8+
import android.support.test.runner.AndroidJUnit4;
9+
import com.bumptech.glide.test.BitmapRegressionTester;
10+
import com.bumptech.glide.test.CanonicalBitmap;
11+
import com.bumptech.glide.test.GlideApp;
12+
import com.bumptech.glide.test.RegressionTest;
13+
import com.bumptech.glide.test.SplitByCpu;
14+
import com.bumptech.glide.test.SplitBySdk;
15+
import com.bumptech.glide.test.TearDownGlide;
16+
import java.util.concurrent.ExecutionException;
17+
import org.junit.Before;
18+
import org.junit.Rule;
19+
import org.junit.Test;
20+
import org.junit.rules.ExpectedException;
21+
import org.junit.rules.TestName;
22+
import org.junit.runner.RunWith;
23+
24+
@RunWith(AndroidJUnit4.class)
25+
@SplitByCpu
26+
@SplitBySdk({24, 21, 16})
27+
@RegressionTest
28+
public class CenterInsideRegressionTest {
29+
@Rule public TestName testName = new TestName();
30+
@Rule public ExpectedException expectedException = ExpectedException.none();
31+
@Rule public TearDownGlide tearDownGlide = new TearDownGlide();
32+
private BitmapRegressionTester bitmapRegressionTester;
33+
private Context context;
34+
private CanonicalBitmap canonical;
35+
36+
@Before
37+
public void setUp() {
38+
context = InstrumentationRegistry.getTargetContext();
39+
bitmapRegressionTester = new BitmapRegressionTester(getClass(), testName);
40+
canonical = new CanonicalBitmap();
41+
}
42+
43+
@Test
44+
public void centerInside_withSquareSmallerThanImage_returnsImageFitWithinSquare()
45+
throws ExecutionException, InterruptedException {
46+
47+
Bitmap result =
48+
bitmapRegressionTester.test(
49+
GlideApp.with(context)
50+
.asBitmap()
51+
.load(canonical.getBitmap())
52+
.centerInside()
53+
.override(50));
54+
55+
assertThat(result.getWidth()).isEqualTo(50);
56+
assertThat(result.getHeight()).isEqualTo(37);
57+
}
58+
59+
@Test
60+
public void centerInside_withSquareLargerThanImage_returnsOriginalImage()
61+
throws ExecutionException, InterruptedException {
62+
float multiplier = 1.1f;
63+
int multipliedWidth = (int) (canonical.getWidth() * multiplier);
64+
Bitmap result =
65+
bitmapRegressionTester.test(
66+
GlideApp.with(context)
67+
.asBitmap()
68+
.load(canonical.getBitmap())
69+
.centerInside()
70+
.override(multipliedWidth));
71+
72+
assertThat(result.getWidth()).isEqualTo(canonical.getWidth());
73+
assertThat(result.getHeight()).isEqualTo(canonical.getHeight());
74+
}
75+
76+
@Test
77+
public void centerInside_withNarrowRectangle_fitsWithinMaintainingAspectRatio()
78+
throws ExecutionException, InterruptedException {
79+
Bitmap result =
80+
bitmapRegressionTester.test(
81+
GlideApp.with(context)
82+
.asBitmap()
83+
.load(canonical.getBitmap())
84+
.centerInside()
85+
.override(canonical.getWidth() / 10, canonical.getHeight()));
86+
87+
assertThat(result.getWidth()).isEqualTo(canonical.getWidth() / 10);
88+
assertThat(result.getHeight()).isEqualTo(canonical.getHeight() / 10);
89+
}
90+
91+
@Test
92+
public void centerInside_withShortRectangle_fitsWithinMaintainingAspectRatio()
93+
throws ExecutionException, InterruptedException {
94+
Bitmap result =
95+
bitmapRegressionTester.test(
96+
GlideApp.with(context)
97+
.asBitmap()
98+
.load(canonical.getBitmap())
99+
.centerInside()
100+
.override(canonical.getWidth(), canonical.getHeight() / 2));
101+
102+
assertThat(result.getWidth()).isEqualTo(canonical.getWidth() / 2);
103+
assertThat(result.getHeight()).isEqualTo(canonical.getHeight() / 2);
104+
}
105+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.bumptech.glide;
2+
3+
import static com.google.common.truth.Truth.assertThat;
4+
5+
import android.content.Context;
6+
import android.graphics.Bitmap;
7+
import android.support.test.InstrumentationRegistry;
8+
import android.support.test.runner.AndroidJUnit4;
9+
import com.bumptech.glide.test.BitmapRegressionTester;
10+
import com.bumptech.glide.test.CanonicalBitmap;
11+
import com.bumptech.glide.test.GlideApp;
12+
import com.bumptech.glide.test.RegressionTest;
13+
import com.bumptech.glide.test.SplitByCpu;
14+
import com.bumptech.glide.test.SplitBySdk;
15+
import com.bumptech.glide.test.TearDownGlide;
16+
import java.util.concurrent.ExecutionException;
17+
import org.junit.Before;
18+
import org.junit.Rule;
19+
import org.junit.Test;
20+
import org.junit.rules.ExpectedException;
21+
import org.junit.rules.TestName;
22+
import org.junit.runner.RunWith;
23+
24+
@RunWith(AndroidJUnit4.class)
25+
@SplitByCpu
26+
@SplitBySdk({26, 24, 23, 21, 18, 16})
27+
@RegressionTest
28+
public class CircleCropRegressionTest {
29+
@Rule public TestName testName = new TestName();
30+
@Rule public ExpectedException expectedException = ExpectedException.none();
31+
@Rule public TearDownGlide tearDownGlide = new TearDownGlide();
32+
private BitmapRegressionTester bitmapRegressionTester;
33+
private Context context;
34+
private CanonicalBitmap canonical;
35+
36+
@Before
37+
public void setUp() {
38+
context = InstrumentationRegistry.getTargetContext();
39+
bitmapRegressionTester = new BitmapRegressionTester(getClass(), testName);
40+
canonical = new CanonicalBitmap();
41+
}
42+
43+
@Test
44+
public void circleCrop_withSquareSmallerThanImage_returnsSquaredImage()
45+
throws ExecutionException, InterruptedException {
46+
Bitmap result =
47+
bitmapRegressionTester.test(
48+
GlideApp.with(context)
49+
.asBitmap()
50+
.load(canonical.getBitmap())
51+
.circleCrop()
52+
.override(50));
53+
54+
assertThat(result.getWidth()).isEqualTo(50);
55+
assertThat(result.getHeight()).isEqualTo(50);
56+
}
57+
58+
@Test
59+
public void circleCrop_withSquareLargerThanImage_returnsUpscaledFitImage()
60+
throws ExecutionException, InterruptedException {
61+
float multiplier = 1.1f;
62+
int multipliedWidth = (int) (canonical.getWidth() * multiplier);
63+
int multipliedHeight = (int) (canonical.getHeight() * multiplier);
64+
Bitmap result =
65+
bitmapRegressionTester.test(
66+
GlideApp.with(context)
67+
.asBitmap()
68+
.load(canonical.getBitmap())
69+
.circleCrop()
70+
.override(multipliedWidth));
71+
72+
assertThat(result.getWidth()).isEqualTo(multipliedWidth);
73+
assertThat(result.getHeight()).isEqualTo(multipliedWidth);
74+
}
75+
76+
@Test
77+
public void circleCrop_withNarrowRectangle_cropsWithin()
78+
throws ExecutionException, InterruptedException {
79+
Bitmap result =
80+
bitmapRegressionTester.test(
81+
GlideApp.with(context)
82+
.asBitmap()
83+
.load(canonical.getBitmap())
84+
.circleCrop()
85+
.override(canonical.getWidth() / 10, canonical.getHeight()));
86+
87+
assertThat(result.getWidth()).isEqualTo(canonical.getWidth() / 10);
88+
assertThat(result.getHeight()).isEqualTo(canonical.getWidth() / 10);
89+
}
90+
91+
@Test
92+
public void circleCrop_withShortRectangle_fitsWithinMaintainingAspectRatio()
93+
throws ExecutionException, InterruptedException {
94+
Bitmap result =
95+
bitmapRegressionTester.test(
96+
GlideApp.with(context)
97+
.asBitmap()
98+
.load(canonical.getBitmap())
99+
.circleCrop()
100+
.override(canonical.getWidth(), canonical.getHeight() / 2));
101+
102+
assertThat(result.getWidth()).isEqualTo(canonical.getHeight() / 2);
103+
assertThat(result.getHeight()).isEqualTo(canonical.getHeight() / 2);
104+
}
105+
}

instrumentation/src/androidTest/java/com/bumptech/glide/FitCenterRegressionTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.bumptech.glide.test.RegressionTest;
1313
import com.bumptech.glide.test.SplitByCpu;
1414
import com.bumptech.glide.test.SplitBySdk;
15+
import com.bumptech.glide.test.TearDownGlide;
1516
import java.util.concurrent.ExecutionException;
1617
import org.junit.Before;
1718
import org.junit.Rule;
@@ -27,6 +28,7 @@
2728
public class FitCenterRegressionTest {
2829
@Rule public TestName testName = new TestName();
2930
@Rule public ExpectedException expectedException = ExpectedException.none();
31+
@Rule public TearDownGlide tearDownGlide = new TearDownGlide();
3032
private BitmapRegressionTester bitmapRegressionTester;
3133
private Context context;
3234
private CanonicalBitmap canonical;
@@ -39,7 +41,7 @@ public void setUp() {
3941
}
4042

4143
@Test
42-
public void fitCenter_withSquareSmallerThanImage_returnsSquareImage()
44+
public void fitCenter_withSquareSmallerThanImage_returnsImageFitWithinSquare()
4345
throws ExecutionException, InterruptedException {
4446

4547
Bitmap result =
@@ -105,10 +107,10 @@ public void fitCenter_withShortRectangle_fitsWithinMaintainingAspectRatio()
105107
@Test
106108
public void fitCenter_withHugeRectangle_throwsOOM()
107109
throws ExecutionException, InterruptedException {
108-
expectedException.expect(ExecutionException.class);
109110
float multiplier = Integer.MAX_VALUE / (canonical.getWidth() * canonical.getHeight() * 2);
110111
int overrideWidth = (int) multiplier * canonical.getWidth();
111112
int overrideHeight = (int) multiplier * canonical.getHeight();
113+
expectedException.expect(ExecutionException.class);
112114
GlideApp
113115
.with(context)
114116
.asBitmap()

scripts/split_by_sdk.sh

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ do
161161
done
162162
adb -s emulator-5554 emu kill
163163
sleep 1
164+
kill -9 $pid
164165
pkill emulator64-crash-service
165166
pkill emulator-crash-service
166167
echo "Finished API ${api}" 1>&3 2>&4

0 commit comments

Comments
 (0)