Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
7bdd74a7
Commit
7bdd74a7
authored
7 years ago
by
Anton Tarasov
Browse files
Options
Download
Email Patches
Plain Diff
Improve IconScaleTest
(cherry picked from commit
bb6f5f0c
)
parent
c783b798
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
platform/platform-tests/testSrc/com/intellij/util/ui/IconScaleTest.java
+37
-30
...orm-tests/testSrc/com/intellij/util/ui/IconScaleTest.java
with
37 additions
and
30 deletions
+37
-30
platform/platform-tests/testSrc/com/intellij/util/ui/IconScaleTest.java
+
37
-
30
View file @
7bdd74a7
...
...
@@ -12,7 +12,6 @@ import com.intellij.util.ui.paint.AbstractPainter2DTest;
import
com.intellij.util.ui.paint.PaintUtilTest
;
import
junit.framework.TestCase
;
import
org.junit.After
;
import
org.junit.Assume
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -21,6 +20,7 @@ import java.io.File;
import
java.net.MalformedURLException
;
import
static
com
.
intellij
.
util
.
ui
.
JBUI
.
ScaleType
.
SYS_SCALE
;
import
static
com
.
intellij
.
util
.
ui
.
JBUI
.
ScaleType
.
USR_SCALE
;
/**
* Tests that {@link CachedImageIcon#scale(float)} doesn't break the contract and scales correctly.
...
...
@@ -49,44 +49,51 @@ public class IconScaleTest {
@Test
public
void
test
()
throws
MalformedURLException
{
Assume
.
assumeFalse
(
"Linux doesn't support JRE-HiDPI yet"
,
SystemInfo
.
isLinux
);
test
(
1.0
);
test
(
2.0
);
test
(
2.5
);
}
final
double
[]
SCALES
=
{
1
,
2
,
2.5
};
public
void
test
(
double
sysScale
)
throws
MalformedURLException
{
final
int
BASE_SIZE
=
16
;
final
float
ICON_SCALE
=
1.75f
;
//
// 1) JRE-HiDPI
//
PaintUtilTest
.
overrideJreHiDPIEnabled
(
true
);
if
(!
SystemInfo
.
isLinux
)
{
// Linux doesn't support JRE-HiDPI yet
for
(
double
s
:
SCALES
)
test
(
1
,
s
);
}
//
// 2) IDE-HiDPI
//
PaintUtilTest
.
overrideJreHiDPIEnabled
(
false
);
for
(
double
s
:
SCALES
)
test
(
s
,
1
);
}
public
void
test
(
double
usrScale
,
double
sysScale
)
throws
MalformedURLException
{
JBUI
.
setUserScaleFactor
((
float
)
usrScale
);
ScaleContext
ctx
=
ScaleContext
.
create
(
SYS_SCALE
.
of
(
sysScale
),
USR_SCALE
.
of
(
usrScale
));
final
int
ICON_BASE_SIZE
=
16
;
final
int
ICON_USER_SIZE
=
(
int
)
Math
.
round
(
ICON_BASE_SIZE
*
ctx
.
getScale
(
USR_SCALE
));
final
int
ICON_REAL_SIZE
=
(
int
)
Math
.
round
(
ICON_USER_SIZE
*
ctx
.
getScale
(
SYS_SCALE
));
PaintUtilTest
.
overrideJreHiDPIEnabled
(
true
);
JBUI
.
setUserScaleFactor
(
1
);
final
float
ICON_SCALE
=
1.75f
;
final
int
ICON_SCALED_USER_SIZE
=
Math
.
round
(
ICON_USER_SIZE
*
ICON_SCALE
);
final
int
ICON_SCALED_REAL_SIZE
=
Math
.
round
(
ICON_REAL_SIZE
*
ICON_SCALE
);
CachedImageIcon
icon
=
new
CachedImageIcon
(
new
File
(
getIconPath
()).
toURI
().
toURL
());
icon
.
updateScale
(
SYS_SCALE
.
of
(
sysScale
));
ScaleContext
originalCtx
=
icon
.
getScaleContext
().
copy
();
icon
.
updateScaleContext
(
ctx
);
TestCase
.
assertEquals
(
"unexpected icon user width"
,
BASE_SIZE
,
icon
.
getIconWidth
());
TestCase
.
assertEquals
(
"unexpected icon user height"
,
BASE_SIZE
,
icon
.
getIconHeight
());
TestCase
.
assertEquals
(
"unexpected icon real width"
,
0
,
Double
.
compare
(
BASE_SIZE
*
sysScale
,
ImageUtil
.
getRealWidth
(
IconUtil
.
toImage
(
icon
))));
TestCase
.
assertEquals
(
"unexpected icon real height"
,
0
,
Double
.
compare
(
BASE_SIZE
*
sysScale
,
ImageUtil
.
getRealHeight
(
IconUtil
.
toImage
(
icon
))));
TestCase
.
assertEquals
(
"unexpected icon user width"
,
ICON_USER_SIZE
,
icon
.
getIconWidth
());
TestCase
.
assertEquals
(
"unexpected icon user height"
,
ICON_USER_SIZE
,
icon
.
getIconHeight
());
TestCase
.
assertEquals
(
"unexpected icon real width"
,
ICON_REAL_SIZE
,
ImageUtil
.
getRealWidth
(
IconUtil
.
toImage
(
icon
)));
TestCase
.
assertEquals
(
"unexpected icon real height"
,
ICON_REAL_SIZE
,
ImageUtil
.
getRealHeight
(
IconUtil
.
toImage
(
icon
)));
Icon
scaledIcon
=
icon
.
scale
(
ICON_SCALE
);
TestCase
.
assertFalse
(
"new instance of the icon is expected"
,
icon
==
scaledIcon
);
TestCase
.
assertEquals
(
"ScaleContext of the original icon changed"
,
originalCtx
,
icon
.
getScaleContext
());
TestCase
.
assertEquals
(
"unexpected icon user width"
,
0
,
Double
.
compare
(
BASE_SIZE
*
ICON_SCALE
,
scaledIcon
.
getIconWidth
()));
TestCase
.
assertEquals
(
"unexpected icon user height"
,
0
,
Double
.
compare
(
BASE_SIZE
*
ICON_SCALE
,
scaledIcon
.
getIconHeight
()));
TestCase
.
assertEquals
(
"unexpected icon real width"
,
0
,
Double
.
compare
(
BASE_SIZE
*
ICON_SCALE
*
sysScale
,
ImageUtil
.
getRealWidth
(
IconUtil
.
toImage
(
scaledIcon
))));
TestCase
.
assertEquals
(
"unexpected icon real height"
,
0
,
Double
.
compare
(
BASE_SIZE
*
ICON_SCALE
*
sysScale
,
ImageUtil
.
getRealHeight
(
IconUtil
.
toImage
(
scaledIcon
))));
TestCase
.
assertNotSame
(
"new instance of the icon is expected"
,
icon
,
scaledIcon
);
TestCase
.
assertEquals
(
"ScaleContext of the original icon changed"
,
ctx
,
icon
.
getScaleContext
());
TestCase
.
assertEquals
(
"unexpected scaled icon user width"
,
ICON_SCALED_USER_SIZE
,
scaledIcon
.
getIconWidth
());
TestCase
.
assertEquals
(
"unexpected scaled icon user height"
,
ICON_SCALED_USER_SIZE
,
scaledIcon
.
getIconHeight
());
TestCase
.
assertEquals
(
"unexpected scaled icon real width"
,
ICON_SCALED_REAL_SIZE
,
ImageUtil
.
getRealWidth
(
IconUtil
.
toImage
(
scaledIcon
)));
TestCase
.
assertEquals
(
"unexpected scaled icon real height"
,
ICON_SCALED_REAL_SIZE
,
ImageUtil
.
getRealHeight
(
IconUtil
.
toImage
(
scaledIcon
)));
}
private
String
getIconPath
()
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment