imported first development of Manfred
git-svn-id: https://projects.brucker.ch/su4sml/svn/infsec-import/trunk/src/su4sml@5824 3260e6d1-4efc-4170-b0a7-36055960796d
This commit is contained in:
parent
9a217f2ad9
commit
4c1bcc95ab
|
@ -57,6 +57,7 @@ use "componentuml_cartridge.sml";
|
|||
|
||||
|
||||
use "java_cartridge.sml";
|
||||
use "junit.sml";
|
||||
|
||||
|
||||
(* Statemachines *)
|
||||
|
|
|
@ -90,6 +90,13 @@ fun initEnv model = { model = model,
|
|||
curAttribute = NONE,
|
||||
curArgument = NONE } : environment
|
||||
|
||||
fun curClassifierPackageToString env p2sfun = (case (#curClassifier env) of
|
||||
NONE => p2sfun
|
||||
(Rep.package_of
|
||||
(hd (#model env)))
|
||||
| SOME c => p2sfun
|
||||
(Rep.package_of
|
||||
(curClassifier' env)))
|
||||
|
||||
(* FIX: check for NONEs in arguments environment *)
|
||||
(**
|
||||
|
@ -101,13 +108,8 @@ fun initEnv model = { model = model,
|
|||
* operation_visibility, operation_scope, argument_name, argument_type
|
||||
*)
|
||||
fun lookup env "classifier_name" = Rep_Core.short_name_of (curClassifier' env)
|
||||
| lookup env "classifier_package" = (case (#curClassifier env) of
|
||||
NONE => Rep_OclType.string_of_path
|
||||
(Rep.package_of
|
||||
(hd (#model env)))
|
||||
| SOME c => Rep_OclType.string_of_path
|
||||
(Rep.package_of
|
||||
(curClassifier' env)))
|
||||
| lookup env "classifier_package" = curClassifierPackageToString env Rep_OclType.string_of_path
|
||||
| lookup env "classifier_package_path" = curClassifierPackageToString env Rep_OclType.pathstring_of_path
|
||||
| lookup env "classifier_parent" = Rep_Core.short_parent_name_of
|
||||
(curClassifier' env)
|
||||
| lookup env "attribute_name" = #name (curAttribute' env)
|
||||
|
@ -157,6 +159,7 @@ fun test env "isClass" = (case (#curClassifier env) of
|
|||
in
|
||||
(parentName <> "oclLib.OclAny")
|
||||
end
|
||||
| test env "hasOperations" = (length (Rep_Core.operations_of (curClassifier' env))) > 0
|
||||
| test env "first_classifier" = (curClassifier' env = hd (#model env))
|
||||
| test env "first_attribute" = (curAttribute' env
|
||||
= hd (Rep_Core.attributes_of (curClassifier' env)))
|
||||
|
|
|
@ -46,9 +46,9 @@ structure SecureUML_Base_Gcg
|
|||
structure CSharpSM_Gcg = GCG_Core (CSSM_Cartridge(CSharp_Cartridge(Base_Cartridge)))
|
||||
|
||||
structure Java_Gcg = GCG_Core (Java_Cartridge(Base_Cartridge))
|
||||
(*
|
||||
|
||||
structure Junit_Gcg = GCG_Core (Junit_Cartridge(Java_Cartridge(Base_Cartridge)))
|
||||
*)
|
||||
|
||||
(*
|
||||
structure JavaSecure_Gcg = GCG_Core (Java_Cartridge(SecureUML_Cartridge(Base_Cartridge)));
|
||||
*)
|
||||
|
@ -67,9 +67,8 @@ fun generate xmi_file "base" =
|
|||
CSharpSM_Gcg.generate (RepParser.readFile xmi_file) "templates/C#_SM.tpl"
|
||||
| generate xmi_file "java" =
|
||||
Java_Gcg.generate (RepParser.readFile xmi_file) "templates/java.tpl"
|
||||
(* | generate xmi_file "junit" =
|
||||
| generate xmi_file "junit" =
|
||||
Junit_Gcg.generate (RepParser.readFile xmi_file) "templates/junit.tpl"
|
||||
*)
|
||||
(*
|
||||
| generate "java_secure" = JavaSecure_Gcg.generate model "templates/java_SecureUML.tpl"
|
||||
*)
|
||||
|
|
|
@ -54,7 +54,14 @@ fun openFile file = (closeFile ();
|
|||
out := (TextIO.openOut file);
|
||||
curFile := file
|
||||
)
|
||||
|
||||
|
||||
fun openFileIfNotExists file = (closeFile ();
|
||||
(if ((OS.FileSys.fileSize file) > 0) then
|
||||
openFile "/dev/null"
|
||||
else
|
||||
openFile file
|
||||
) handle SysErr => ( openFile file ))
|
||||
|
||||
fun initOut () = (out := TextIO.stdOut;
|
||||
curFile := "")
|
||||
|
||||
|
@ -79,6 +86,7 @@ fun substituteVars e s = let val tkl = (Gcg_Helper.joinEscapeSplitted "$") (Gcg_
|
|||
(** traverses a templateParseTree and executes the given instructions *)
|
||||
fun write env (Tpl_Parser.RootNode(l)) = List.app (write env) l
|
||||
| write env (Tpl_Parser.OpenFileLeaf(file)) = openFile (substituteVars env file)
|
||||
| write env (Tpl_Parser.OpenFileIfNotExistsLeaf(file)) = openFileIfNotExists (substituteVars env file)
|
||||
| write env (Tpl_Parser.EvalLeaf(l)) = let fun collectEval [] = ""
|
||||
| collectEval ((Tpl_Parser.TextLeaf(expr))::t) = expr^"\n"^(collectEval t)
|
||||
| collectEval _ =
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* su4sml - a SecureUML repository for SML
|
||||
*
|
||||
* junit_cartridge.sml - a junit cartridge for gcg
|
||||
* Copyright (C) 2006
|
||||
* Copyright (C) 2006 Manfred Stock
|
||||
*
|
||||
* This file is part of su4sml.
|
||||
*
|
||||
|
@ -51,7 +51,10 @@ fun curAttribute env = SuperCart.curAttribute (unpack env)
|
|||
fun lookup (env : environment) s = SuperCart.lookup (unpack env) s
|
||||
|
||||
(* any special predicates?*)
|
||||
fun test (env : environment) s = SuperCart.test (unpack env) s
|
||||
fun test (env : environment ) "operation_isNotPrivate" = not (test env "operation_isPrivate")
|
||||
| test (env : environment ) "not_last_argument" = not (test env "last_argument")
|
||||
| test (env : environment) "isTestable" = (test env "hasOperations") andalso (not (test env "isInterface"))
|
||||
| test (env : environment) s = SuperCart.test (unpack env) s
|
||||
|
||||
(* any special lists? *)
|
||||
fun foreach listType (env : environment)
|
||||
|
|
|
@ -1 +1,97 @@
|
|||
@// Template for Junit TestCases
|
||||
|
||||
@foreach classifier_list
|
||||
@if isTestable
|
||||
@//---------------------------------------------------
|
||||
@// Generate main test class which inherits from the abstract class
|
||||
@//---------------------------------------------------
|
||||
@openfile generated/src/test/java/$classifier_package_path$/$classifier_name$Test.java
|
||||
package $classifier_package$;
|
||||
@nl@nl
|
||||
@nl import java.io.FileNotFoundException;
|
||||
@nl import org.junit.BeforeClass;
|
||||
@nl import org.junit.Test;
|
||||
@nl import ch.ethz.infsec.jtestdataaccessor.TestDataAccessor;
|
||||
@nl import ch.ethz.infsec.jtestdataaccessor.TestDataParseException;
|
||||
@nl import ch.ethz.infsec.jtestdataaccessor.TestDataUser;
|
||||
@nl import ch.ethz.infsec.jtestdataaccessor.TestHelper;
|
||||
@nl import antlr.RecognitionException;
|
||||
@nl import antlr.TokenStreamException;
|
||||
@nl
|
||||
@nl public class $classifier_name$Test extends Abstract$classifier_name$Test implements TestDataUser {
|
||||
|
||||
@nl@tab public static String classUnderTest = "$classifier_package$.$classifier_name$";
|
||||
|
||||
@nl@nl@tab private static TestDataAccessor tda;
|
||||
|
||||
@nl@nl@tab private static TestHelper th;
|
||||
|
||||
@nl@nl@tab public String getClassUnderTest() {
|
||||
@nl@tab@tab return classUnderTest;
|
||||
@nl@tab}
|
||||
|
||||
@nl@nl@tabpublic Object getTestObject() {
|
||||
@nl@tab@tab return testObject;
|
||||
@nl@tab}
|
||||
|
||||
@nl@nl@tab \@BeforeClass
|
||||
@nl@tab public static void basicEnvSetup() throws FileNotFoundException, RecognitionException, TokenStreamException, TestDataParseException {
|
||||
@nl@tab@tab tda = new TestDataAccessor("src/test/resources/$classifier_package_path$/Testdata$classifier_name$");
|
||||
@nl@tab@tab th = new TestHelper(classUnderTest,tda);
|
||||
@nl@tab }
|
||||
|
||||
@foreach operation_list
|
||||
@if operation_isNotPrivate
|
||||
@nl@nl@tab\@Test
|
||||
@nl@tab public void $operation_name$Test() throws Throwable {
|
||||
@nl@tab@tab String methodname = "$operation_name$";
|
||||
@nl@tab@tab th.doTest(methodname, this);
|
||||
@nl@tab }
|
||||
@end
|
||||
@end
|
||||
@nl}
|
||||
|
||||
|
||||
@//--------------------------
|
||||
@// Generate stub for abstract class
|
||||
@//--------------------------
|
||||
@openfileifnotexists generated/src/test/java/$classifier_package_path$/Abstract$classifier_name$Test.java
|
||||
package $classifier_package$;
|
||||
@nl import $classifier_package$.$classifier_name$;
|
||||
@nl@nl public abstract class Abstract$classifier_name$Test {
|
||||
|
||||
@nl@nl@tab static Value testObject;
|
||||
|
||||
@nl@nl }
|
||||
|
||||
|
||||
@//----------------------
|
||||
@// Generate stub for testdata
|
||||
@//----------------------
|
||||
@openfileifnotexists generated/src/test/resources/$classifier_package_path$/Testdata$classifier_name$
|
||||
|
||||
@foreach operation_list
|
||||
@if operation_isNotPrivate
|
||||
[$operation_name$]
|
||||
@nl resulttype = $operation_result_type$;
|
||||
@nl inputtypes =
|
||||
@foreach argument_list
|
||||
$argument_type$
|
||||
@if not_last_argument
|
||||
,
|
||||
@end
|
||||
@end
|
||||
;
|
||||
@nl #setup = ;
|
||||
@nl #teardown = ;
|
||||
@nl #{
|
||||
@nl #@tab input = ;
|
||||
@nl #@tab result = ;
|
||||
@nl #@tab checker = ;
|
||||
@nl #@tab comment = ;
|
||||
@nl #}
|
||||
@nl@nl
|
||||
@end
|
||||
@end
|
||||
@end
|
||||
@end
|
||||
|
|
|
@ -30,6 +30,7 @@ datatype TemplateTree
|
|||
| ForEachNode of string * TemplateTree list
|
||||
| IfNode of string * TemplateTree list
|
||||
| OpenFileLeaf of string
|
||||
| OpenFileIfNotExistsLeaf of string
|
||||
| RootNode of TemplateTree list
|
||||
| TextLeaf of string
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ datatype TemplateTree
|
|||
| ForEachNode of string * TemplateTree list
|
||||
| IfNode of string * TemplateTree list
|
||||
| OpenFileLeaf of string
|
||||
| OpenFileIfNotExistsLeaf of string
|
||||
| RootNode of TemplateTree list
|
||||
| TextLeaf of string
|
||||
|
||||
|
@ -57,6 +58,7 @@ fun readNextLine () = TextIO.inputLine (!tplStream)
|
|||
|
||||
datatype TemplateTree = RootNode of TemplateTree list
|
||||
| OpenFileLeaf of string
|
||||
| OpenFileIfNotExistsLeaf of string
|
||||
| EvalLeaf of TemplateTree list
|
||||
| TextLeaf of string
|
||||
| IfNode of string * TemplateTree list
|
||||
|
@ -100,6 +102,7 @@ fun cleanLine s = let fun removeWspace s =
|
|||
*)
|
||||
fun printTplTree prefix (RootNode(l)) = (print (prefix^"root"^"\n"); List.app (printTplTree (prefix))l)
|
||||
| printTplTree prefix (OpenFileLeaf(s))= print (prefix^"openfile:"^s^"\n")
|
||||
| printTplTree prefix (OpenFileIfNotExistsLeaf(s))= print (prefix^"openfileifnotexists:"^s^"\n")
|
||||
| printTplTree prefix (EvalLeaf(l)) = (print (prefix^"eval:\n"); List.app (printTplTree (prefix^"\t"))l)
|
||||
| printTplTree prefix (TextLeaf(s)) = print (prefix^"text:"^s^"\n")
|
||||
| printTplTree prefix (IfNode(s,l)) = (print (prefix^"if:"^s^"\n");List.app (printTplTree (prefix^"\t")) l)
|
||||
|
@ -168,6 +171,7 @@ fun buildTree (SOME line) = let fun getNode ("text",c) = (TextLeaf(c))::(buil
|
|||
| getNode ("else",_) = [ElseNode(buildTree (readNextLine()))]
|
||||
| getNode ("elsif",c) = [ElseNode([IfNode(c,buildTree (readNextLine()))])]
|
||||
| getNode ("openfile",c)= (OpenFileLeaf(c))::(buildTree (readNextLine()))
|
||||
| getNode ("openfileifnotexists",c)= (OpenFileIfNotExistsLeaf(c))::(buildTree (readNextLine()))
|
||||
| getNode ("eval","") =
|
||||
(EvalLeaf(buildTree(readNextLine())))::(buildTree (readNextLine()))
|
||||
| getNode ("eval",expr) = (EvalLeaf([TextLeaf(expr)]))::(buildTree (readNextLine()))
|
||||
|
|
|
@ -35,6 +35,7 @@ sig
|
|||
| Classifier of Path | OclVoid | DummyT | TemplateParameter of string
|
||||
val string_of_OclType : OclType -> string
|
||||
val string_of_path : Path -> string
|
||||
val pathstring_of_path: Path -> string
|
||||
val is_Classifier : OclType -> bool
|
||||
val is_Collection : OclType -> bool
|
||||
end
|
||||
|
@ -99,10 +100,16 @@ datatype OclType = Integer | Real | String | Boolean | OclAny
|
|||
| Classifier of Path
|
||||
| TemplateParameter of string
|
||||
|
||||
fun string_of_path (path:Path) = case path of
|
||||
(** Convert Path to a string using given separator *)
|
||||
fun path_to_string (path:Path) separator = case path of
|
||||
[] => ""
|
||||
| p => foldr1 (fn (a,b) => a^"."^b) p
|
||||
| p => foldr1 (fn (a,b) => a^separator^b) p
|
||||
|
||||
(** Convert Path to a string using ., creating a Java package name like string *)
|
||||
fun string_of_path (path:Path) = path_to_string path "."
|
||||
|
||||
(** Convert Path to a string using /, creating a Unix directory like string *)
|
||||
fun pathstring_of_path (path:Path) = path_to_string path "/"
|
||||
|
||||
fun string_of_OclType Integer = "Integer"
|
||||
| string_of_OclType Real = "Real"
|
||||
|
|
Loading…
Reference in New Issue