From b4b7ef926e9bfda72f01bd3957b1dc85da6b0941 Mon Sep 17 00:00:00 2001 From: amarjeetkapoor1 Date: Fri, 22 Jul 2016 21:11:31 +0530 Subject: [PATCH] test cases for set of parameter added, plus some corrections --- src/Parameter/ParameterWidget.cc | 2 +- src/Parameter/parameterset.cpp | 4 +- testdata/scad/customizer/setofparameter.json | 39 +++++++++++++++ testdata/scad/customizer/setofparameter.scad | 45 ++++++++++++++++++ tests/CMakeLists.txt | 4 ++ .../setofparameter-expected.ast | 47 +++++++++++++++++++ .../setofparameter-expected.ast | 47 +++++++++++++++++++ .../setofparameter-expected.ast | 47 +++++++++++++++++++ .../setofparameter-expected.ast | 47 +++++++++++++++++++ .../customizertest_final/sign-expected.ast | 6 +-- .../sign-expected.ast | 6 +-- 11 files changed, 285 insertions(+), 9 deletions(-) create mode 100644 testdata/scad/customizer/setofparameter.json create mode 100644 testdata/scad/customizer/setofparameter.scad create mode 100644 tests/regression/customizertest-first/setofparameter-expected.ast create mode 100644 tests/regression/customizertest-imgset/setofparameter-expected.ast create mode 100644 tests/regression/customizertest-incomplete/setofparameter-expected.ast create mode 100644 tests/regression/customizertest-wrong/setofparameter-expected.ast diff --git a/src/Parameter/ParameterWidget.cc b/src/Parameter/ParameterWidget.cc index 88714d66..fb5f0ddb 100644 --- a/src/Parameter/ParameterWidget.cc +++ b/src/Parameter/ParameterWidget.cc @@ -279,7 +279,7 @@ void ParameterWidget::applyParameterSet(string setName){ AssignmentList *assignmentList; assignmentList=parser(v.second.data().c_str()); if(assignmentList==NULL){ - return ; + continue ; } ModuleContext ctx; diff --git a/src/Parameter/parameterset.cpp b/src/Parameter/parameterset.cpp index 746b5c67..3f44a459 100644 --- a/src/Parameter/parameterset.cpp +++ b/src/Parameter/parameterset.cpp @@ -68,12 +68,12 @@ void ParameterSet::applyParameterSet(FileModule *fileModule,string setName) AssignmentList *assignmentList; assignmentList=parser(v.second.data().c_str()); if(assignmentList==NULL){ - return ; + continue ; } ModuleContext ctx; for(int i=0; isize(); i++) { if(defaultValue->type()== assignmentList[i].data()->expr.get()->evaluate(&ctx)->type()){ - assignment=assignmentList[i].data(); + assignment->expr=assignmentList[i].data()->expr; } } } diff --git a/testdata/scad/customizer/setofparameter.json b/testdata/scad/customizer/setofparameter.json new file mode 100644 index 00000000..cf8acef9 --- /dev/null +++ b/testdata/scad/customizer/setofparameter.json @@ -0,0 +1,39 @@ +{ + "SET": + { + "firstSet": + { + "Labeled_value": " \/*New *\/ ", + "Labeled_values": "100", + "Numbers": "1", + "Spinbox": "35", + "String": "hello", + "Strings": "foo", + "Variable": "false", + "Vector": "[2, 34, 45, 12, 3, 56]", + "Vector2": "[12,4, 45, 23]", + "slider": "38", + "stepSlider": "12" + }, + "wrongSetValues": + { + "Labeled_value": "S new", + "Labeled_values": "wrong type", + "Numbers": "2", + "Spinbox": "5", + "String": "1234", + "Strings": "fo", + "Variable": "true", + "Vector": "12, 34, 44, 43, 2, 23", + "Vector2": "[12, 34, 45, 23]", + "slider": "34", + "stepSlider": "2" + }, + "thirdSet": + { + "Labeled_value":"S new", + "non existing":"value", + "nonparameter" : "second" + } + } +} diff --git a/testdata/scad/customizer/setofparameter.scad b/testdata/scad/customizer/setofparameter.scad new file mode 100644 index 00000000..32e9daee --- /dev/null +++ b/testdata/scad/customizer/setofparameter.scad @@ -0,0 +1,45 @@ +/* [Drop down box:] */ +// combo box for nunber +Numbers=2; // [0, 1, 2, 3] + +// combo box for string +Strings="foo"; + +//labeled combo box for numbers +Labeled_values=10; // [10:L, 20:M, 30:L] + +//labeled combo box for string +Labeled_value="S"; // [S:Small, M:Medium, L:Large] + +/*[ Slider ]*/ +// slider widget for number +slider =34; // [10:100] + +//step slider for number +stepSlider=2; //[0:5:100] + +/* [Checkbox] */ + +//description +Variable = true; //comment + +/*[Spinbox] */ + +// spinbox with step size 23 +Spinbox = 5; //23 + +/* [Textbox] */ + +//Text box for vector with more than 4 elements +Vector=[12,34,44,43,23,23];//comment + +// Text box for string +String="hello"; //comment + +/* [Special vector] */ +//Text box for vector with less than or equal to 4 elements +Vector2=[12,34,45,23]; //any thing + +nonparameter="new"; + +echo(String); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c4a5a6b8..2364df82 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1590,6 +1590,10 @@ add_cmdline_test(customizertest EXE ${OPENSCAD_BINPATH} ARGS -o SUFFIX ast FILES add_cmdline_test(customizertest_secondset EXE ${OPENSCAD_BINPATH} ARGS -p ${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/sign.json -P secondset -o SUFFIX ast FILES ${CMAKE_SOURCE_DIR}/../examples/Parametric/sign.scad) add_cmdline_test(customizertest_final EXE ${OPENSCAD_BINPATH} ARGS -p ${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/sign.json -P final -o SUFFIX ast FILES ${CMAKE_SOURCE_DIR}/../examples/Parametric/sign.scad) +add_cmdline_test(customizertest-first EXE ${OPENSCAD_BINPATH} ARGS -p ${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/setofparameter.json -P firstSet -o SUFFIX ast FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/setofparameter.scad) +add_cmdline_test(customizertest-wrong EXE ${OPENSCAD_BINPATH} ARGS -p ${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/setofparameter.json -P wrongSetValues -o SUFFIX ast FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/setofparameter.scad) +add_cmdline_test(customizertest-incomplete EXE ${OPENSCAD_BINPATH} ARGS -p ${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/setofparameter.json -P thirdSet -o SUFFIX ast FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/setofparameter.scad) +add_cmdline_test(customizertest-imgset EXE ${OPENSCAD_BINPATH} ARGS -p ${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/setofparameter.json -P imagine -o SUFFIX ast FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/customizer/setofparameter.scad) # # Add experimental tests diff --git a/tests/regression/customizertest-first/setofparameter-expected.ast b/tests/regression/customizertest-first/setofparameter-expected.ast new file mode 100644 index 00000000..04e15be4 --- /dev/null +++ b/tests/regression/customizertest-first/setofparameter-expected.ast @@ -0,0 +1,47 @@ +@Group("Drop down box:") +@Description("combo box for nunber") +@Parameter([0, 1, 2, 3]) +Numbers = 1; +@Group("Drop down box:") +@Description("combo box for string") +Strings = "foo"; +@Group("Drop down box:") +@Description("labeled combo box for numbers") +@Parameter([[10, "L"], [20, "M"], [30, "L"]]) +Labeled_values = 100; +@Group("Drop down box:") +@Description("labeled combo box for string") +@Parameter([["S", "Small"], ["M", "Medium"], ["L", "Large"]]) +Labeled_value = " /*New */ "; +@Group(" Slider ") +@Description("slider widget for number") +@Parameter([10 : 100]) +slider = 38; +@Group(" Slider ") +@Description("step slider for number") +@Parameter([0 : 5 : 100]) +stepSlider = 12; +@Group("Checkbox") +@Description("description") +@Parameter("comment") +Variable = true; +@Group("Spinbox") +@Description("spinbox with step size 23") +@Parameter(23) +Spinbox = 35; +@Group("Textbox") +@Description("Text box for vector with more than 4 elements") +@Parameter("comment") +Vector = [2, 34, 45, 12, 3, 56]; +@Group("Textbox") +@Description("Text box for string") +@Parameter("comment") +String = "hello"; +@Group("Special vector") +@Description("Text box for vector with less than or equal to 4 elements") +@Parameter("any thing") +Vector2 = [12, 4, 45, 23]; +@Group("Special vector") +nonparameter = "new"; +echo(String); + diff --git a/tests/regression/customizertest-imgset/setofparameter-expected.ast b/tests/regression/customizertest-imgset/setofparameter-expected.ast new file mode 100644 index 00000000..473e26aa --- /dev/null +++ b/tests/regression/customizertest-imgset/setofparameter-expected.ast @@ -0,0 +1,47 @@ +@Group("Drop down box:") +@Description("combo box for nunber") +@Parameter([0, 1, 2, 3]) +Numbers = 2; +@Group("Drop down box:") +@Description("combo box for string") +Strings = "foo"; +@Group("Drop down box:") +@Description("labeled combo box for numbers") +@Parameter([[10, "L"], [20, "M"], [30, "L"]]) +Labeled_values = 10; +@Group("Drop down box:") +@Description("labeled combo box for string") +@Parameter([["S", "Small"], ["M", "Medium"], ["L", "Large"]]) +Labeled_value = "S"; +@Group(" Slider ") +@Description("slider widget for number") +@Parameter([10 : 100]) +slider = 34; +@Group(" Slider ") +@Description("step slider for number") +@Parameter([0 : 5 : 100]) +stepSlider = 2; +@Group("Checkbox") +@Description("description") +@Parameter("comment") +Variable = true; +@Group("Spinbox") +@Description("spinbox with step size 23") +@Parameter(23) +Spinbox = 5; +@Group("Textbox") +@Description("Text box for vector with more than 4 elements") +@Parameter("comment") +Vector = [12, 34, 44, 43, 23, 23]; +@Group("Textbox") +@Description("Text box for string") +@Parameter("comment") +String = "hello"; +@Group("Special vector") +@Description("Text box for vector with less than or equal to 4 elements") +@Parameter("any thing") +Vector2 = [12, 34, 45, 23]; +@Group("Special vector") +nonparameter = "new"; +echo(String); + diff --git a/tests/regression/customizertest-incomplete/setofparameter-expected.ast b/tests/regression/customizertest-incomplete/setofparameter-expected.ast new file mode 100644 index 00000000..3e4d048a --- /dev/null +++ b/tests/regression/customizertest-incomplete/setofparameter-expected.ast @@ -0,0 +1,47 @@ +@Group("Drop down box:") +@Description("combo box for nunber") +@Parameter([0, 1, 2, 3]) +Numbers = 2; +@Group("Drop down box:") +@Description("combo box for string") +Strings = "foo"; +@Group("Drop down box:") +@Description("labeled combo box for numbers") +@Parameter([[10, "L"], [20, "M"], [30, "L"]]) +Labeled_values = 10; +@Group("Drop down box:") +@Description("labeled combo box for string") +@Parameter([["S", "Small"], ["M", "Medium"], ["L", "Large"]]) +Labeled_value = "S new"; +@Group(" Slider ") +@Description("slider widget for number") +@Parameter([10 : 100]) +slider = 34; +@Group(" Slider ") +@Description("step slider for number") +@Parameter([0 : 5 : 100]) +stepSlider = 2; +@Group("Checkbox") +@Description("description") +@Parameter("comment") +Variable = true; +@Group("Spinbox") +@Description("spinbox with step size 23") +@Parameter(23) +Spinbox = 5; +@Group("Textbox") +@Description("Text box for vector with more than 4 elements") +@Parameter("comment") +Vector = [12, 34, 44, 43, 23, 23]; +@Group("Textbox") +@Description("Text box for string") +@Parameter("comment") +String = "hello"; +@Group("Special vector") +@Description("Text box for vector with less than or equal to 4 elements") +@Parameter("any thing") +Vector2 = [12, 34, 45, 23]; +@Group("Special vector") +nonparameter = "second"; +echo(String); + diff --git a/tests/regression/customizertest-wrong/setofparameter-expected.ast b/tests/regression/customizertest-wrong/setofparameter-expected.ast new file mode 100644 index 00000000..e93b0a4d --- /dev/null +++ b/tests/regression/customizertest-wrong/setofparameter-expected.ast @@ -0,0 +1,47 @@ +@Group("Drop down box:") +@Description("combo box for nunber") +@Parameter([0, 1, 2, 3]) +Numbers = 2; +@Group("Drop down box:") +@Description("combo box for string") +Strings = "fo"; +@Group("Drop down box:") +@Description("labeled combo box for numbers") +@Parameter([[10, "L"], [20, "M"], [30, "L"]]) +Labeled_values = 10; +@Group("Drop down box:") +@Description("labeled combo box for string") +@Parameter([["S", "Small"], ["M", "Medium"], ["L", "Large"]]) +Labeled_value = "S new"; +@Group(" Slider ") +@Description("slider widget for number") +@Parameter([10 : 100]) +slider = 34; +@Group(" Slider ") +@Description("step slider for number") +@Parameter([0 : 5 : 100]) +stepSlider = 2; +@Group("Checkbox") +@Description("description") +@Parameter("comment") +Variable = true; +@Group("Spinbox") +@Description("spinbox with step size 23") +@Parameter(23) +Spinbox = 5; +@Group("Textbox") +@Description("Text box for vector with more than 4 elements") +@Parameter("comment") +Vector = [12, 34, 44, 43, 23, 23]; +@Group("Textbox") +@Description("Text box for string") +@Parameter("comment") +String = "1234"; +@Group("Special vector") +@Description("Text box for vector with less than or equal to 4 elements") +@Parameter("any thing") +Vector2 = [12, 34, 45, 23]; +@Group("Special vector") +nonparameter = "new"; +echo(String); + diff --git a/tests/regression/customizertest_final/sign-expected.ast b/tests/regression/customizertest_final/sign-expected.ast index e3a3d327..d8edbb98 100644 --- a/tests/regression/customizertest_final/sign-expected.ast +++ b/tests/regression/customizertest_final/sign-expected.ast @@ -1,12 +1,12 @@ @Description("The resolution of the curves. Higher values give smoother curves but may increase the model render time.") @Parameter([10, 20, 30, 50, 100]) -resolution = 30; +resolution = 100; @Description("The horizontal radius of the outer ellipse of the sign.") @Parameter([60 : 200]) -radius = 80; +radius = 74; @Description("Total height of the sign") @Parameter([1 : 10]) -height = 2; +height = 9; @Parameter(["Welcome to...", "Happy Birthday!", "Happy Anniversary", "Congratulations", "Thank You"]) selection = "Thank You"; @Parameter() diff --git a/tests/regression/customizertest_secondset/sign-expected.ast b/tests/regression/customizertest_secondset/sign-expected.ast index 733c5d31..6a7345b3 100644 --- a/tests/regression/customizertest_secondset/sign-expected.ast +++ b/tests/regression/customizertest_secondset/sign-expected.ast @@ -1,12 +1,12 @@ @Description("The resolution of the curves. Higher values give smoother curves but may increase the model render time.") @Parameter([10, 20, 30, 50, 100]) -resolution = 30; +resolution = 50; @Description("The horizontal radius of the outer ellipse of the sign.") @Parameter([60 : 200]) -radius = 80; +radius = 110; @Description("Total height of the sign") @Parameter([1 : 10]) -height = 2; +height = 6; @Parameter(["Welcome to...", "Happy Birthday!", "Happy Anniversary", "Congratulations", "Thank You"]) selection = "Happy Anniversary"; @Parameter()