Skip to content

Commit

Permalink
Restructures test instances for composition; Added parsing method by …
Browse files Browse the repository at this point in the history
…simply giving a path
  • Loading branch information
SundermannC committed Apr 17, 2024
1 parent decf6c1 commit 3a70b75
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 53 deletions.
18 changes: 16 additions & 2 deletions src/main/java/de/vill/main/UVLModelFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.vill.main;

import de.vill.util.Util;
import uvl.UVLJavaLexer;
import uvl.UVLJavaParser;

Expand Down Expand Up @@ -93,7 +94,20 @@ public FeatureModel parse(String text, Map<String, String> fileLoader) throws Pa
}

/**
* This method parses the givel text and returns a {@link FeatureModel} if everything is fine or throws a {@link ParseError} if something went wrong.
* This method parses an UVL model given a path to the UVL model. For imported submodels (if applicable) the directory of the UVL model is used
* @param uvlModelPath path to uvl model
* @return
* @throws ParseError
*/
public FeatureModel parse(Path uvlModelPath) throws ParseError {
String content = Util.readFileContent(uvlModelPath);
String projectRootForImports = uvlModelPath.getParent().toString();

return parse(content, projectRootForImports);
}

/**
* This method parses the given text and returns a {@link FeatureModel} if everything is fine or throws a {@link ParseError} if something went wrong.
*
* @param text A String that describes a feature model in UVL notation.
* @param path Path to the directory where all submodels are stored.
Expand All @@ -107,7 +121,7 @@ public FeatureModel parse(String text, String path) throws ParseError {
}

/**
* This method parses the givel text and returns a {@link FeatureModel} if everything is fine or throws a {@link ParseError} if something went wrong.
* This method parses the given text and returns a {@link FeatureModel} if everything is fine or throws a {@link ParseError} if something went wrong.
* It assumes that all the necessary submodels are in the current working directory.
*
* @param text A String that describes a feature model in UVL notation.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/vill/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Constants {
public static final String TRUE = "true";
public static final String UNDEF = "undef";

// Default attribtues
// Default attributes
public static final String TYPE_LEVEL_VALUE = "type_level_value";
public static final String TYPE_LEVEL_LENGTH = "type_level_value_length";

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/vill/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import de.vill.config.Configuration;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class Util {
public static String indentEachLine(String text) {
StringBuilder result = new StringBuilder();
Expand Down Expand Up @@ -32,4 +36,12 @@ public static String addNecessaryQuotes(String reference) {
}
return result.toString();
}

public static String readFileContent(Path file) {
try {
return new String(Files.readAllBytes(file));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
22 changes: 20 additions & 2 deletions src/test/java/de/vill/parsing/ParsingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class ParsingTests {
+ File.separator;
private static final String COMPLEX_MODEL_PREFIX = TEST_MODEL_PREFIX + File.separator + "complex" + File.separator;

private static final String COMPOSITION_MODEL_PREFIX = TEST_MODEL_PREFIX + "composition" + File.separator;

private static final String NESTED_MODEL_PREFIX = COMPOSITION_MODEL_PREFIX + "nested" + File.separator;

// Boolean level models
private static final String SIMPLE_BOOLEAN = CONCEPTS_MODEL_PREFIX + "boolean.uvl";
private static final String NAMESPACE = CONCEPTS_MODEL_PREFIX + "namespace.uvl";
Expand Down Expand Up @@ -53,6 +57,14 @@ public class ParsingTests {
private static final String MISSING_REFRENCE = FAULTY_MODEL_PREFIX + "missingreference.uvl";
private static final String WRONG_INDENT = FAULTY_MODEL_PREFIX + "wrongindent.uvl";

// Composition uvl models

private static final String COMPOSITION_ROOT = COMPOSITION_MODEL_PREFIX + "composition_root.uvl";

private static final String NESTED_COMPOSITION_ROOT = COMPOSITION_MODEL_PREFIX + "nested_main.uvl";

private static final String NESTED_SUB_COMPOSITION_ROOT = NESTED_MODEL_PREFIX + "nested_sub.uvl";

@Test
void testBooleanModel() throws Exception {
testModelParsing(SIMPLE_BOOLEAN);
Expand Down Expand Up @@ -120,6 +132,13 @@ void checkFaultyModels() throws Exception {

}

@Test
void checkCompositionModels() throws Exception {
testModelParsing(COMPOSITION_ROOT);
testModelParsing(NESTED_COMPOSITION_ROOT);
testModelParsing(NESTED_SUB_COMPOSITION_ROOT);
}

private void testModelParsing(String path) {
testModelParsing(path, true);
}
Expand All @@ -130,8 +149,7 @@ public static FeatureModel testModelParsing(String path, boolean expectSuccess)
FeatureModel result = null;
boolean error = false;
try {
content = new String(Files.readAllBytes(Paths.get(path)));
result = uvlModelFactory.parse(content);
result = uvlModelFactory.parse(Paths.get(path));
} catch (Exception e) {
error = true;
}
Expand Down
31 changes: 0 additions & 31 deletions src/test/resources/composition/composition_root.uvl

This file was deleted.

24 changes: 24 additions & 0 deletions src/test/resources/parsing/composition/composition_root.uvl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
imports
composition_sub1

features
Computer
optional
"RAM-module"
mandatory
"SATA-Devices"
[0..3]
HDD
SSD
"DVD-drive"
"Card-reader"
"Blu-ray-drive"
composition_sub1.CPU
PSU {abstract true}
alternative
strong_PSU
weak_PSU

constraints
SSD => strong_PSU
"DVD-drive" <=> composition_sub1.brand & composition_sub1.fmIntel.feature1 & composition_sub1.composition_sub1_sub2.feature2
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
include
SAT-level
SMT-level

namespace composition_sub1

imports
composition_sub1_sub1 as fmIntel
composition_sub1_sub2
Expand All @@ -21,7 +15,6 @@ features
Bit32 {bit 32}

constraints
Bit64 => fmIntel.Intel
fmIntel.feature1 & fmIntel.feature2 <=> (Bit64) | !composition_sub1_sub2.feature2
Bit64.bit + Bit32.bit > 32
fmIntel.feature1.power - fmIntel.feature2.power == 25
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
include
SAT-level

namespace composition_sub1_sub1

features
Intel
mandatory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
include
SAT-level

namespace composition_sub1_sub2

features
AMD
mandatory
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
features
Nested
optional
N1
N2
9 changes: 9 additions & 0 deletions src/test/resources/parsing/composition/nested/nested_sub.uvl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
imports
nested_referenced_sub as nrs

features
Root
optional
F1
F2
nrs.Nested
7 changes: 7 additions & 0 deletions src/test/resources/parsing/composition/nested_main.uvl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ímports
nested.nested_sub as nesu

features
Root
optional
nesu.Root

0 comments on commit 3a70b75

Please sign in to comment.