Skip to content

Commit

Permalink
Add test for @stringdef null assignment
Browse files Browse the repository at this point in the history
Summary: A test for the null assignment fix in D51512837.

Reviewed By: itang00

Differential Revision: D51734422

fbshipit-source-id: b7e9264a5b164c4a9f0f9f78c96106c1cd11aac5
  • Loading branch information
Wei Zhang (Devinfra) authored and facebook-github-bot committed Dec 4, 2023
1 parent f65752d commit 032fb59
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 26 additions & 1 deletion test/integ/TypedefAnnoCheckerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,6 @@ TEST_F(TypedefAnnoCheckerTest, testSynthAccessor) {
EXPECT_TRUE(accessor != nullptr);
IRCode* code = accessor->get_code();
code->build_cfg();
// auto& cfg = code->cfg();

StrDefConstants strdef_constants;
IntDefConstants intdef_constants;
Expand Down Expand Up @@ -887,3 +886,29 @@ TEST_F(TypedefAnnoCheckerTest, testSynthAccessor) {
Error invoking Lcom/facebook/redextest/TypedefAnnoCheckerKtTest;.access$takesStrConst:(Lcom/facebook/redextest/TypedefAnnoCheckerKtTest;Ljava/lang/String;)Ljava/lang/String;\n\
Incorrect parameter's index: 1\n\n");
}

TEST_F(TypedefAnnoCheckerTest, testAssignNullToString) {
auto scope = build_class_scope(stores);
auto method =
DexMethod::get_method(
"Lcom/facebook/redextest/"
"TypedefAnnoCheckerTest;.testAssignNullToString:()Ljava/lang/String;")
->as_def();

IRCode* code = method->get_code();
code->build_cfg();

StrDefConstants strdef_constants;
IntDefConstants intdef_constants;
TypedefAnnoCheckerPass pass = TypedefAnnoCheckerPass(get_config());
for (auto cls : scope) {
gather_typedef_values(pass, cls, strdef_constants, intdef_constants);
}

TypedefAnnoChecker checker =
TypedefAnnoChecker(strdef_constants, intdef_constants, get_config());
checker.run(method);
code->clear_cfg();

EXPECT_TRUE(checker.complete());
}
4 changes: 4 additions & 0 deletions test/integ/TypedefAnnoCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,8 @@ void testStringField(@TestStringDef String val) {
int res = flag ? TestIntDef.ZERO : TestIntDef.ONE;
return res;
}

static @TestStringDef String testAssignNullToString() {
return null;
}
}

0 comments on commit 032fb59

Please sign in to comment.