Search in sources :

Example 11 with Region

use of de.fraunhofer.aisec.cpg.sarif.Region in project cpg by Fraunhofer-AISEC.

the class LocationConverterTest method toEntityAttributeWithStrings.

@Test
void toEntityAttributeWithStrings() {
    // arrange
    final CompositeAttributeConverter<PhysicalLocation> sut = getSut();
    final Map<String, Object> value = new HashMap<>();
    final String startLineValue = "1";
    value.put(LocationConverter.START_LINE, startLineValue);
    final String endLineValue = "2";
    value.put(LocationConverter.END_LINE, endLineValue);
    final String startColumnValue = "3";
    value.put(LocationConverter.START_COLUMN, startColumnValue);
    final String endColumnValue = "4";
    value.put(LocationConverter.END_COLUMN, endColumnValue);
    value.put(LocationConverter.ARTIFACT, URI_STRING);
    final Region region = new Region(Integer.parseInt(startLineValue), Integer.parseInt(startColumnValue), Integer.parseInt(endLineValue), Integer.parseInt(endColumnValue));
    final PhysicalLocation want = new PhysicalLocation(URI_TO_TEST, region);
    // act
    final PhysicalLocation have = sut.toEntityAttribute(value);
    // assert
    Assertions.assertEquals(want, have);
}
Also used : HashMap(java.util.HashMap) Region(de.fraunhofer.aisec.cpg.sarif.Region) PhysicalLocation(de.fraunhofer.aisec.cpg.sarif.PhysicalLocation) Test(org.junit.jupiter.api.Test)

Example 12 with Region

use of de.fraunhofer.aisec.cpg.sarif.Region in project cpg by Fraunhofer-AISEC.

the class LocationConverterTest method toEntityAttributeWithIntegerAndLong.

@Test
void toEntityAttributeWithIntegerAndLong() {
    // arrange
    final CompositeAttributeConverter<PhysicalLocation> sut = getSut();
    final Map<String, Object> value = new HashMap<>();
    final int startLineValue = 1;
    // autoboxing to Integer
    value.put(LocationConverter.START_LINE, startLineValue);
    final int endLineValue = 2;
    value.put(LocationConverter.END_LINE, endLineValue);
    final long startColumnValue = 3;
    // autoboxing to Long
    value.put(LocationConverter.START_COLUMN, startColumnValue);
    final long endColumnValue = 4;
    value.put(LocationConverter.END_COLUMN, endColumnValue);
    value.put(LocationConverter.ARTIFACT, URI_STRING);
    final Region region = new Region(startLineValue, (int) startColumnValue, endLineValue, (int) endColumnValue);
    final PhysicalLocation want = new PhysicalLocation(URI_TO_TEST, region);
    // act
    final PhysicalLocation have = sut.toEntityAttribute(value);
    // assert
    Assertions.assertEquals(want, have);
}
Also used : HashMap(java.util.HashMap) Region(de.fraunhofer.aisec.cpg.sarif.Region) PhysicalLocation(de.fraunhofer.aisec.cpg.sarif.PhysicalLocation) Test(org.junit.jupiter.api.Test)

Aggregations

Region (de.fraunhofer.aisec.cpg.sarif.Region)12 PhysicalLocation (de.fraunhofer.aisec.cpg.sarif.PhysicalLocation)10 Test (org.junit.jupiter.api.Test)9 HashMap (java.util.HashMap)6 BaseTest (de.fraunhofer.aisec.cpg.BaseTest)3 File (java.io.File)3 FunctionDeclaration (de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration)2 TranslationUnitDeclaration (de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration)2 Range (com.github.javaparser.Range)1 TokenRange (com.github.javaparser.TokenRange)1 Node (de.fraunhofer.aisec.cpg.graph.Node)1 CompoundStatement (de.fraunhofer.aisec.cpg.graph.statements.CompoundStatement)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1