Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C#/Java: Add model generator test examples.
Browse files Browse the repository at this point in the history
michaelnebel committed Sep 19, 2024
1 parent e0db908 commit 78e0937
Showing 2 changed files with 148 additions and 0 deletions.
80 changes: 80 additions & 0 deletions csharp/ql/test/utils/modelgenerator/dataflow/Summaries.cs
Original file line number Diff line number Diff line change
@@ -838,3 +838,83 @@ public void SetProp2(string v)
Prop2 = v;
}
}

public class Fanout
{

public abstract class Base1
{
public abstract string GetValue();
}

public abstract class Base2 : Base1 { }

public class Impl1 : Base1
{
public string Prop { get; set; }

// summary=Models;Fanout+Base1;true;GetValue;();;Argument[this];ReturnValue;taint;df-generated
// contentbased-summary=Models;Fanout+Impl1;true;GetValue;();;Argument[this].Property[Models.Fanout+Impl1.Prop];ReturnValue;value;df-generated
public override string GetValue()
{
return Prop;
}
}

public class Impl2 : Base2
{
public string Prop { get; set; }

// summary=Models;Fanout+Base1;true;GetValue;();;Argument[this];ReturnValue;taint;df-generated
// contentbased-summary=Models;Fanout+Impl2;true;GetValue;();;Argument[this].Property[Models.Fanout+Impl2.Prop];ReturnValue;value;df-generated
public override string GetValue()
{
return Prop;
}
}

public class Impl3 : Base2
{
public string Prop { get; set; }

// summary=Models;Fanout+Base1;true;GetValue;();;Argument[this];ReturnValue;taint;df-generated
// contentbased-summary=Models;Fanout+Impl3;true;GetValue;();;Argument[this].Property[Models.Fanout+Impl3.Prop];ReturnValue;value;df-generated
public override string GetValue()
{
return Prop;
}
}

public class Impl4 : Base2
{
public string Prop { get; set; }

// summary=Models;Fanout+Base1;true;GetValue;();;Argument[this];ReturnValue;taint;df-generated
// contentbased-summary=Models;Fanout+Impl4;true;GetValue;();;Argument[this].Property[Models.Fanout+Impl4.Prop];ReturnValue;value;df-generated
public override string GetValue()
{
return Prop;
}
}

// summary=Models;Fanout;false;ConcatValueOnBase1;(System.String,Models.Fanout+Base1);;Argument[0];ReturnValue;taint;df-generated
// summary=Models;Fanout;false;ConcatValueOnBase1;(System.String,Models.Fanout+Base1);;Argument[1];ReturnValue;taint;df-generated
// No content based summaries are expected for this method on parameter `b1`
// as the fanout (number of content flows) exceeds the limit of 3.
// contentbased-summary=Models;Fanout;false;ConcatValueOnBase1;(System.String,Models.Fanout+Base1);;Argument[0];ReturnValue;taint;df-generated
public string ConcatValueOnBase1(string other, Base1 b1)
{
return other + b1.GetValue();
}

// summary=Models;Fanout;false;ConcatValueOnBase2;(System.String,Models.Fanout+Base2);;Argument[0];ReturnValue;taint;df-generated
// summary=Models;Fanout;false;ConcatValueOnBase2;(System.String,Models.Fanout+Base2);;Argument[1];ReturnValue;taint;df-generated
// contentbased-summary=Models;Fanout;false;ConcatValueOnBase2;(System.String,Models.Fanout+Base2);;Argument[0];ReturnValue;taint;df-generated
// contentbased-summary=Models;Fanout;false;ConcatValueOnBase2;(System.String,Models.Fanout+Base2);;Argument[1].Property[Models.Fanout+Impl2.Prop];ReturnValue;taint;df-generated
// contentbased-summary=Models;Fanout;false;ConcatValueOnBase2;(System.String,Models.Fanout+Base2);;Argument[1].Property[Models.Fanout+Impl3.Prop];ReturnValue;taint;df-generated
// contentbased-summary=Models;Fanout;false;ConcatValueOnBase2;(System.String,Models.Fanout+Base2);;Argument[1].Property[Models.Fanout+Impl4.Prop];ReturnValue;taint;df-generated
public string ConcatValueOnBase2(string other, Base2 b2)
{
return other + b2.GetValue();
}
}
68 changes: 68 additions & 0 deletions java/ql/test/utils/modelgenerator/dataflow/p/Fanout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package p;

public class Fanout {
public interface I1 {
String getValue();
}

public interface I2 extends I1 {}

public class Impl1 implements I1 {
public String v;

// summary=p;Fanout$I1;true;getValue;();;Argument[this];ReturnValue;taint;df-generated
// contentbased-summary=p;Fanout$Impl1;true;getValue;();;Argument[this].Field[p.Fanout$Impl1.v];ReturnValue;value;df-generated
public String getValue() {
return v;
}
}

public class Impl2 implements I2 {
public String v;

// summary=p;Fanout$I1;true;getValue;();;Argument[this];ReturnValue;taint;df-generated
// contentbased-summary=p;Fanout$Impl2;true;getValue;();;Argument[this].Field[p.Fanout$Impl2.v];ReturnValue;value;df-generated
public String getValue() {
return v;
}
}

public class Impl3 implements I2 {
public String v;

// summary=p;Fanout$I1;true;getValue;();;Argument[this];ReturnValue;taint;df-generated
// contentbased-summary=p;Fanout$Impl3;true;getValue;();;Argument[this].Field[p.Fanout$Impl3.v];ReturnValue;value;df-generated
public String getValue() {
return v;
}
}

public class Impl4 implements I2 {
public String v;

// summary=p;Fanout$I1;true;getValue;();;Argument[this];ReturnValue;taint;df-generated
// contentbased-summary=p;Fanout$Impl4;true;getValue;();;Argument[this].Field[p.Fanout$Impl4.v];ReturnValue;value;df-generated
public String getValue() {
return v;
}
}

// summary=p;Fanout;true;concatGetValueOnI1;(String,Fanout$I1);;Argument[0];ReturnValue;taint;df-generated
// summary=p;Fanout;true;concatGetValueOnI1;(String,Fanout$I1);;Argument[1];ReturnValue;taint;df-generated
// No content based summaries are expected for this method on parameter `i`
// as the fanout (number of content flows) exceeds the limit of 3.
// contentbased-summary=p;Fanout;true;concatGetValueOnI1;(String,Fanout$I1);;Argument[0];ReturnValue;taint;df-generated
public String concatGetValueOnI1(String other, I1 i) {
return other + i.getValue();
}

// summary=p;Fanout;true;concatGetValueOnI2;(String,Fanout$I2);;Argument[0];ReturnValue;taint;df-generated
// summary=p;Fanout;true;concatGetValueOnI2;(String,Fanout$I2);;Argument[1];ReturnValue;taint;df-generated
// contentbased-summary=p;Fanout;true;concatGetValueOnI2;(String,Fanout$I2);;Argument[0];ReturnValue;taint;df-generated
// contentbased-summary=p;Fanout;true;concatGetValueOnI2;(String,Fanout$I2);;Argument[1].Field[p.Fanout$Impl2.v];ReturnValue;taint;df-generated
// contentbased-summary=p;Fanout;true;concatGetValueOnI2;(String,Fanout$I2);;Argument[1].Field[p.Fanout$Impl3.v];ReturnValue;taint;df-generated
// contentbased-summary=p;Fanout;true;concatGetValueOnI2;(String,Fanout$I2);;Argument[1].Field[p.Fanout$Impl4.v];ReturnValue;taint;df-generated
public String concatGetValueOnI2(String other, I2 i) {
return other + i.getValue();
}
}

0 comments on commit 78e0937

Please sign in to comment.