Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
eb141ad1
Commit
eb141ad1
authored
Mar 26, 2019
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add tests for #474
parent
b446bf27
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
86 additions
and
24 deletions
+86
-24
IntegrationTest.java
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
+8
-0
SmaliTest.java
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
+12
-9
TestCaseSensitiveChecks.java
...jadx/tests/integration/names/TestCaseSensitiveChecks.java
+60
-0
TestClassNameWithInvalidChar.java
...tests/integration/names/TestClassNameWithInvalidChar.java
+2
-15
1.smali
...core/src/test/smali/names/TestCaseSensitiveChecks/1.smali
+2
-0
2.smali
...core/src/test/smali/names/TestCaseSensitiveChecks/2.smali
+2
-0
No files found.
jadx-core/src/test/java/jadx/tests/api/IntegrationTest.java
View file @
eb141ad1
...
...
@@ -81,6 +81,14 @@ public abstract class IntegrationTest extends TestUtils {
args
.
setFsCaseSensitive
(
false
);
// use same value on all systems
}
public
String
getTestName
()
{
return
this
.
getClass
().
getSimpleName
();
}
public
String
getTestPkg
()
{
return
this
.
getClass
().
getPackage
().
getName
().
replace
(
"jadx.tests.integration."
,
""
);
}
public
ClassNode
getClassNode
(
Class
<?>
clazz
)
{
try
{
File
jar
=
getJarForClass
(
clazz
);
...
...
jadx-core/src/test/java/jadx/tests/api/SmaliTest.java
View file @
eb141ad1
...
...
@@ -11,7 +11,9 @@ import org.jf.smali.Smali;
import
org.jf.smali.SmaliOptions
;
import
jadx.api.JadxDecompiler
;
import
jadx.api.JadxInternalAccess
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.RootNode
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
...
...
@@ -47,16 +49,17 @@ public abstract class SmaliTest extends IntegrationTest {
return
getClassNodeFromFile
(
outDex
,
pkg
+
'.'
+
clsName
);
}
protected
JadxDecompiler
loadSmaliFile
(
String
pkg
,
String
smaliFileName
)
{
protected
List
<
ClassNode
>
loadFromSmaliFiles
(
)
{
File
outDex
=
createTempFile
(
".dex"
);
compileSmali
(
outDex
,
Collections
.
singletonList
(
getSmaliFile
(
pkg
+
File
.
separatorChar
+
smaliFileName
)));
return
loadFiles
(
Collections
.
singletonList
(
outDex
));
}
compileSmali
(
outDex
,
collectSmaliFiles
(
getTestPkg
(),
getTestName
()));
protected
JadxDecompiler
loadSmaliFiles
(
String
pkg
,
String
testNameDir
)
{
File
outDex
=
createTempFile
(
".dex"
);
compileSmali
(
outDex
,
collectSmaliFiles
(
pkg
,
testNameDir
));
return
loadFiles
(
Collections
.
singletonList
(
outDex
));
JadxDecompiler
d
=
loadFiles
(
Collections
.
singletonList
(
outDex
));
RootNode
root
=
JadxInternalAccess
.
getRoot
(
d
);
List
<
ClassNode
>
classes
=
root
.
getClasses
(
false
);
for
(
ClassNode
cls
:
classes
)
{
decompileAndCheckCls
(
d
,
cls
);
}
return
classes
;
}
private
List
<
File
>
collectSmaliFiles
(
String
pkg
,
@Nullable
String
testDir
)
{
...
...
@@ -68,7 +71,7 @@ public abstract class SmaliTest extends IntegrationTest {
}
File
smaliDir
=
new
File
(
SMALI_TESTS_DIR
,
smaliFilesDir
);
String
[]
smaliFileNames
=
smaliDir
.
list
((
dir
,
name
)
->
name
.
endsWith
(
".smali"
));
assertThat
(
"Smali files not found
"
,
smaliFileNames
,
notNullValue
());
assertThat
(
"Smali files not found
in "
+
smaliDir
,
smaliFileNames
,
notNullValue
());
return
Arrays
.
stream
(
smaliFileNames
)
.
map
(
file
->
new
File
(
smaliDir
,
file
))
.
collect
(
Collectors
.
toList
());
...
...
jadx-core/src/test/java/jadx/tests/integration/names/TestCaseSensitiveChecks.java
0 → 100644
View file @
eb141ad1
package
jadx
.
tests
.
integration
.
names
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
org.hamcrest.Matchers
;
import
org.junit.jupiter.api.Test
;
import
jadx.core.Consts
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.tests.api.SmaliTest
;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
hamcrest
.
Matchers
.
emptyString
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
not
;
public
class
TestCaseSensitiveChecks
extends
SmaliTest
{
/*
public class A {}
public class a {}
*/
@Test
public
void
test
()
{
args
.
setFsCaseSensitive
(
false
);
List
<
ClassNode
>
classes
=
loadFromSmaliFiles
();
for
(
ClassNode
cls
:
classes
)
{
assertThat
(
cls
.
getPackage
(),
is
(
Consts
.
DEFAULT_PACKAGE_NAME
));
}
long
namesCount
=
classes
.
stream
().
map
(
cls
->
cls
.
getShortName
().
toLowerCase
()).
distinct
().
count
();
assertThat
(
namesCount
,
is
(
2L
));
}
@Test
public
void
testCaseSensitiveFS
()
{
args
.
setFsCaseSensitive
(
true
);
List
<
ClassNode
>
classes
=
loadFromSmaliFiles
();
for
(
ClassNode
cls
:
classes
)
{
assertThat
(
cls
.
getPackage
(),
is
(
Consts
.
DEFAULT_PACKAGE_NAME
));
}
List
<
String
>
names
=
classes
.
stream
().
map
(
ClassNode:
:
getShortName
).
collect
(
Collectors
.
toList
());
assertThat
(
names
,
Matchers
.
containsInAnyOrder
(
"A"
,
"a"
));
}
@Test
public
void
testWithDeobfuscation
()
{
enableDeobfuscation
();
List
<
ClassNode
>
classes
=
loadFromSmaliFiles
();
for
(
ClassNode
cls
:
classes
)
{
assertThat
(
cls
.
getPackage
(),
not
(
emptyString
()));
assertThat
(
cls
.
getPackage
(),
not
(
Consts
.
DEFAULT_PACKAGE_NAME
));
}
long
namesCount
=
classes
.
stream
().
map
(
cls
->
cls
.
getShortName
().
toLowerCase
()).
distinct
().
count
();
assertThat
(
namesCount
,
is
(
2L
));
}
}
jadx-core/src/test/java/jadx/tests/integration/names/TestClassNameWithInvalidChar.java
View file @
eb141ad1
...
...
@@ -2,10 +2,6 @@ package jadx.tests.integration.names;
import
org.junit.jupiter.api.Test
;
import
jadx.api.JadxDecompiler
;
import
jadx.api.JadxInternalAccess
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.RootNode
;
import
jadx.tests.api.SmaliTest
;
public
class
TestClassNameWithInvalidChar
extends
SmaliTest
{
...
...
@@ -16,21 +12,12 @@ public class TestClassNameWithInvalidChar extends SmaliTest {
@Test
public
void
test
()
{
JadxDecompiler
d
=
loadSmaliFiles
(
"names"
,
"TestClassNameWithInvalidChar"
);
RootNode
root
=
JadxInternalAccess
.
getRoot
(
d
);
for
(
ClassNode
cls
:
root
.
getClasses
(
false
))
{
decompileAndCheckCls
(
d
,
cls
);
}
loadFromSmaliFiles
();
}
@Test
public
void
testWithDeobfuscation
()
{
enableDeobfuscation
();
JadxDecompiler
d
=
loadSmaliFiles
(
"names"
,
"TestClassNameWithInvalidChar"
);
RootNode
root
=
JadxInternalAccess
.
getRoot
(
d
);
for
(
ClassNode
cls
:
root
.
getClasses
(
false
))
{
decompileAndCheckCls
(
d
,
cls
);
}
loadFromSmaliFiles
();
}
}
jadx-core/src/test/smali/names/TestCaseSensitiveChecks/1.smali
0 → 100644
View file @
eb141ad1
.class public LA;
.super Ljava/lang/Object;
jadx-core/src/test/smali/names/TestCaseSensitiveChecks/2.smali
0 → 100644
View file @
eb141ad1
.class public La;
.super Ljava/lang/Object;
Write
Preview
Markdown
is supported
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