TEST_F(CreateFigureFixture, shouldGetGeneratedNumberWhenCreateFigure) { // Given CCreateFigure createFigure(&strictRandom, size); // Expected EXPECT_CALL(strictRandom, generate()).WillOnce(Return(1)); // When createFigure.create(); }
TEST_F(CreateFigureFixture, shouldCreateFigure4WhenCreate) { // Given ON_CALL(niceRandom, generate()).WillByDefault(Return(3)); CCreateFigure createFigure(&niceRandom, size); // When CFigurePtr spFigure = createFigure.create(); // Then ASSERT_EQ(4, spFigure->elem.size()); EXPECT_EQ(QPoint(size/2 - 1, 0), spFigure->elem[0].pos()); EXPECT_EQ(QPoint(size/2, 0), spFigure->elem[1].pos()); EXPECT_EQ(QPoint(size/2, 1), spFigure->elem[2].pos()); EXPECT_EQ(QPoint(size/2, 2), spFigure->elem[3].pos()); }
void CurveEditPart::setModel(shared_ptr<ModelElementBase> value) { curve_ = dynamic_pointer_cast< CurveLine >(value); curve_start_point_changed_disconnect = auto_ptr< SignalDisconnect >( new SignalDisconnect( curve_->signalStartPointChanged().connect ( sigc::mem_fun(this, &CurveEditPart::onCurveStartPointChanged)) ) ); curve_end_point_changed_disconnect = auto_ptr< SignalDisconnect >( new SignalDisconnect( curve_->signalEndPointChanged().connect ( sigc::mem_fun(this, &CurveEditPart::onCurveEndPointChanged)) ) ); curve_start_control_point_changed_disconnect = auto_ptr< SignalDisconnect >( new SignalDisconnect( curve_->signalStartControlPointChanged().connect ( sigc::mem_fun(this, &CurveEditPart::onCurveStartControlPointChanged)) ) ); curve_end_control_point_changed_disconnect = auto_ptr< SignalDisconnect >( new SignalDisconnect( curve_->signalEndControlPointChanged().connect ( sigc::mem_fun(this, &CurveEditPart::onCurveEndControlPointChanged)) ) ); curve_color_changed_disconnect = auto_ptr< SignalDisconnect >( new SignalDisconnect( curve_->signalLineColorChanged().connect ( sigc::mem_fun(this, &CurveEditPart::onCurveLineColorChanged)) ) ); curve_line_width_changed_disconnect = auto_ptr< SignalDisconnect >( new SignalDisconnect( curve_->signalLineWidthChanged().connect ( sigc::mem_fun(this, &CurveEditPart::onCurveLineWidthChanged)) ) ); curve_line_dash_style_changed_disconnect = auto_ptr< SignalDisconnect >( new SignalDisconnect( curve_->signalLineDashStyleChanged().connect ( sigc::mem_fun(this, &CurveEditPart::onCurveLineDashStyleChanged)) ) ); curve_line_dash_style_offset_changed_disconnect = auto_ptr< SignalDisconnect >( new SignalDisconnect( curve_->signalLineDashStyleOffsetChanged().connect ( sigc::mem_fun(this, &CurveEditPart::onCurveLineDashStyleOffsetChanged)) ) ); setFigure (createFigure()); updateMoveDragTrackerFigure(); }
/*--------------------------------------------------------------------------*/ int sci_figure(char * fname, void* pvApiCtx) { SciErr sciErr; int* piAddr = NULL; int iFig = 0; int iRhs = nbInputArgument(pvApiCtx); int iId = 0; int iPos = 0; int i = 0; int iAxes = 0; int iPropertyOffset = 0; BOOL bDoCreation = TRUE; BOOL bVisible = TRUE; // Create a visible figure by default BOOL bDockable = TRUE; // Create a dockable figure by default BOOL bDefaultAxes = TRUE; // Create an Axes by default double* figureSize = NULL; double* axesSize = NULL; double* position = NULL; double val[4]; BOOL bMenuBar = TRUE; BOOL bToolBar = TRUE; BOOL bInfoBar = TRUE; BOOL bResize = TRUE; int iMenubarType = 1; // Create a 'figure' menubar by default int iToolbarType = 1; // Create a 'figure' toolbar by default double dblId = 0; BOOL status = FALSE; //figure(num) -> scf(num) //figure() -> scf() //figure(x, "...", ...) // figure() if (iRhs == 0) // Auto ID { iId = getValidDefaultFigureId(); iFig = createNewFigureWithAxes(); setGraphicObjectProperty(iFig, __GO_ID__, &iId, jni_int, 1); iAxes = setDefaultProperties(iFig, TRUE); initBar(iFig, bMenuBar, bToolBar, bInfoBar); createScalarHandle(pvApiCtx, iRhs + 1, getHandle(iFig)); AssignOutputVariable(pvApiCtx, 1) = iRhs + 1; ReturnArguments(pvApiCtx); return 0; } if (iRhs == 1) { //figure(x); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isVarMatrixType(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: An integer value expected.\n"), fname, 1); return 0; } if (getScalarDouble(pvApiCtx, piAddr, &dblId)) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } iId = (int)(dblId + 0.5); //avoid 1.999 -> 1 //get current fig from id iFig = getFigureFromIndex(iId); if (iFig == 0) // Figure does not exists, create a new one { iFig = createNewFigureWithAxes(); setGraphicObjectProperty(iFig, __GO_ID__, &iId, jni_int, 1); iAxes = setDefaultProperties(iFig, TRUE); } initBar(iFig, bMenuBar, bToolBar, bInfoBar); createScalarHandle(pvApiCtx, iRhs + 1, getHandle(iFig)); AssignOutputVariable(pvApiCtx, 1) = iRhs + 1; ReturnArguments(pvApiCtx); return 0; } // Prepare property analysis if (iRhs % 2 == 0) { //get highest value of winsid to create the new windows @ + 1 iId = getValidDefaultFigureId(); iPos = 0; } else { iPos = 1; //figure(x, ...); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); return 0; } if (isVarMatrixType(pvApiCtx, piAddr) == 0) { Scierror(999, _("%s: Wrong type for input argument #%d: An integer value expected.\n"), fname, 1); return 0; } if (getScalarDouble(pvApiCtx, piAddr, &dblId)) { Scierror(999, _("%s: No more memory.\n"), fname); return 0; } iId = (int)(dblId + 0.5); //avoid 1.999 -> 1 //get current fig from id iFig = getFigureFromIndex(iId); if (iFig != 0) // Figure already exists { bDoCreation = FALSE; } } if (bDoCreation) { int* piAddrProp = NULL; char* pstProName = NULL; int* piAddrData = NULL; for (i = iPos + 1 ; i <= iRhs ; i += 2) { //get property name sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddrProp); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrProp, &pstProName)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i); return 1; } if (stricmp(pstProName, "dockable") != 0 && stricmp(pstProName, "toolbar") != 0 && stricmp(pstProName, "menubar") != 0 && stricmp(pstProName, "default_axes") != 0 && stricmp(pstProName, "visible") != 0 && stricmp(pstProName, "figure_size") != 0 && stricmp(pstProName, "axes_size") != 0 && stricmp(pstProName, "position") != 0 && stricmp(pstProName, "menubar_visible") != 0 && stricmp(pstProName, "toolbar_visible") != 0 && stricmp(pstProName, "resize") != 0 && stricmp(pstProName, "infobar_visible") != 0) { freeAllocatedSingleString(pstProName); continue; } //get address of value on stack sciErr = getVarAddressFromPosition(pvApiCtx, i + 1, &piAddrData); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } //check property value to compatibility if (stricmp(pstProName, "dockable") == 0) { bDockable = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bDockable == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "dockable", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "toolbar") == 0) { char* pstVal = NULL; if (isStringType(pvApiCtx, piAddrData) == FALSE || isScalar(pvApiCtx, piAddrData) == FALSE) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i); freeAllocatedSingleString(pstProName); } if (getAllocatedSingleString(pvApiCtx, piAddrData, &pstVal)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } if (stricmp(pstVal, "none") == 0) { iToolbarType = 0; } else if (stricmp(pstVal, "figure") == 0) { iToolbarType = 1; } else { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "toolbar", "none", "figure"); freeAllocatedSingleString(pstProName); freeAllocatedSingleString(pstVal); return 1; } freeAllocatedSingleString(pstVal); } else if (stricmp(pstProName, "menubar") == 0) { char* pstVal = NULL; if (isStringType(pvApiCtx, piAddrData) == FALSE || isScalar(pvApiCtx, piAddrData) == FALSE) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrData, &pstVal)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } if (stricmp(pstVal, "none") == 0) { iMenubarType = 0; } else if (stricmp(pstVal, "figure") == 0) { iMenubarType = 1; } else { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "menubar", "none", "figure"); freeAllocatedSingleString(pstProName); freeAllocatedSingleString(pstVal); return 1; } freeAllocatedSingleString(pstVal); } else if (stricmp(pstProName, "default_axes") == 0) { bDefaultAxes = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bDefaultAxes == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "default_axes", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "visible") == 0) { bVisible = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bVisible == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "visible", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "figure_size") == 0) { int iRows = 0; int iCols = 0; if (isDoubleType(pvApiCtx, piAddrData) == FALSE) { Scierror(999, _("%s: Wrong type for input argument #%d: A double vector expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } getMatrixOfDouble(pvApiCtx, piAddrData, &iRows, &iCols, &figureSize); if (iRows * iCols != 2) { Scierror(999, _("Wrong size for '%s' property: %d elements expected.\n"), "figure_size", 2); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "axes_size") == 0) { int iRows = 0; int iCols = 0; if (isDoubleType(pvApiCtx, piAddrData) == FALSE) { Scierror(999, _("%s: Wrong type for input argument #%d: A double vector expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } getMatrixOfDouble(pvApiCtx, piAddrData, &iRows, &iCols, &axesSize); if (iRows * iCols != 2) { Scierror(999, _("Wrong size for '%s' property: %d elements expected.\n"), "axes_size", 2); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "position") == 0) { int iRows = 0; int iCols = 0; double* pdbl = NULL; if (isDoubleType(pvApiCtx, piAddrData)) { getMatrixOfDouble(pvApiCtx, piAddrData, &iRows, &iCols, &pdbl); if (iRows * iCols != 4) { Scierror(999, _("Wrong size for '%s' property: %d elements expected.\n"), "position", 4); freeAllocatedSingleString(pstProName); return 1; } position = pdbl; axesSize = (pdbl + 2); } else if (isStringType(pvApiCtx, piAddrData) && isScalar(pvApiCtx, piAddrData)) { char* pstVal = NULL; int iVal = 0; if (getAllocatedSingleString(pvApiCtx, piAddrData, &pstVal)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } iVal = sscanf(pstVal, "%lf|%lf|%lf|%lf", &val[0], &val[1], &val[2], &val[3]); freeAllocatedSingleString(pstVal); if (iVal != 4) { Scierror(999, _("Wrong value for '%s' property: string or 1 x %d real row vector expected.\n"), "position", 4); freeAllocatedSingleString(pstProName); return 1; } position = val; axesSize = (val + 2); } else { Scierror(999, _("Wrong value for '%s' property: string or 1 x %d real row vector expected.\n"), "position", 4); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "resize") == 0) { bResize = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bResize == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "resize", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "menubar_visible") == 0) { bMenuBar = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bMenuBar == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "menubar_visible", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "toolbar_visible") == 0) { bToolBar = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bToolBar == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "toolbar_visible", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } else if (stricmp(pstProName, "infobar_visible") == 0) { bInfoBar = getStackArgumentAsBoolean(pvApiCtx, piAddrData); if (bInfoBar == -1) { Scierror(999, _("Wrong value for '%s' property: '%s' or '%s' expected."), "infobar_visible", "on", "off"); freeAllocatedSingleString(pstProName); return 1; } } freeAllocatedSingleString(pstProName); } iFig = createFigure(bDockable, iMenubarType, iToolbarType, bDefaultAxes, bVisible); setGraphicObjectProperty(iFig, __GO_ID__, &iId, jni_int, 1); iAxes = setDefaultProperties(iFig, bDefaultAxes); } //set(iFig, iPos, iPos + 1) for (i = iPos + 1 ; i <= iRhs ; i += 2) { int isMatrixOfString = 0; int* piAddrProp = NULL; char* pstProName = NULL; int* piAddrData = NULL; int iRows = 0; int iCols = 0; void* _pvData = NULL; int iType = 0; //get property name sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddrProp); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i); return 1; } if (getAllocatedSingleString(pvApiCtx, piAddrProp, &pstProName)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, i); return 1; } if (bDoCreation && ( stricmp(pstProName, "dockable") == 0 || stricmp(pstProName, "toolbar") == 0 || stricmp(pstProName, "menubar") == 0 || stricmp(pstProName, "default_axes") == 0 || stricmp(pstProName, "visible") == 0 || stricmp(pstProName, "figure_size") == 0 || stricmp(pstProName, "axes_size") == 0 || stricmp(pstProName, "position") == 0 || stricmp(pstProName, "resize") == 0 || stricmp(pstProName, "menubar_visible") == 0 || stricmp(pstProName, "toolbar_visible") == 0 || stricmp(pstProName, "infobar_visible") == 0)) { // Already set creating new figure // but let the set_ function fail if figure already exists freeAllocatedSingleString(pstProName); continue; } //get address of value on stack sciErr = getVarAddressFromPosition(pvApiCtx, i + 1, &piAddrData); if (sciErr.iErr) { Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, i + 1); freeAllocatedSingleString(pstProName); return 1; } getVarType(pvApiCtx, piAddrData, &iType); if ((strcmp(pstProName, "user_data") == 0) || (stricmp(pstProName, "userdata") == 0)) { /* in this case set_user_data_property * directly uses the third position in the stack * to get the variable which is to be set in * the user_data property (any data type is allowed) S. Steer */ _pvData = (void*)piAddrData; /*position in the stack */ iRows = -1; /*unused */ iCols = -1; /*unused */ iType = -1; } else { switch (iType) { case sci_matrix : getMatrixOfDouble(pvApiCtx, piAddrData, &iRows, &iCols, (double**)&_pvData); break; case sci_boolean : getMatrixOfBoolean(pvApiCtx, piAddrData, &iRows, &iCols, (int**)&_pvData); break; case sci_handles : getMatrixOfHandle(pvApiCtx, piAddrData, &iRows, &iCols, (long long**)&_pvData); break; case sci_strings : if ( strcmp(pstProName, "tics_labels") != 0 && strcmp(pstProName, "auto_ticks") != 0 && strcmp(pstProName, "axes_visible") != 0 && strcmp(pstProName, "axes_reverse") != 0 && strcmp(pstProName, "text") != 0 && stricmp(pstProName, "string") != 0 && stricmp(pstProName, "tooltipstring") != 0) /* Added for uicontrols */ { if (getAllocatedSingleString(pvApiCtx, piAddrData, (char**)&_pvData)) { Scierror(999, _("%s: Wrong size for input argument #%d: A single string expected.\n"), fname, 3); freeAllocatedSingleString(pstProName); return 1; } iRows = (int)strlen((char*)_pvData); iCols = 1; } else { isMatrixOfString = 1; if (getAllocatedMatrixOfString(pvApiCtx, piAddrData, &iRows, &iCols, (char***)&_pvData)) { Scierror(999, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3); freeAllocatedSingleString(pstProName); return 1; } } break; case sci_list : iCols = 1; getListItemNumber(pvApiCtx, piAddrData, &iRows); _pvData = (void*)piAddrData; /* In this case l3 is the list position in stack */ break; default : _pvData = (void*)piAddrData; /* In this case l3 is the list position in stack */ break; } } callSetProperty(pvApiCtx, iFig, _pvData, iType, iRows, iCols, pstProName); // If backgroundcolor is set : // * add it to colormap => performed by callSetProperty // * set background to index => performed by callSetProperty // * copy value into axes background property if (stricmp(pstProName, "backgroundcolor") == 0 && iAxes > 0) { int iBackground = 0; int *piBackground = &iBackground; getGraphicObjectProperty(iFig, __GO_BACKGROUND__, jni_int, (void **)&piBackground); setGraphicObjectProperty(iAxes, __GO_BACKGROUND__, piBackground, jni_int, 1); } freeAllocatedSingleString(pstProName); if (iType == sci_strings) { //free allacted data if (isMatrixOfString == 1) { freeAllocatedMatrixOfString(iRows, iCols, (char**)_pvData); } else { freeAllocatedSingleString((char*)_pvData); } } } if (position) { int pos[2]; pos[0] = (int)position[0]; pos[1] = (int)position[1]; setGraphicObjectProperty(iFig, __GO_POSITION__, pos, jni_int_vector, 2); } //axes_size if (axesSize) { int axes[2]; axes[0] = (int)axesSize[0]; axes[1] = (int)axesSize[1]; setGraphicObjectProperty(iFig, __GO_AXES_SIZE__, axes, jni_int_vector, 2); } else //no size, use default axes_size { int* piAxesSize = NULL; getGraphicObjectProperty(getFigureModel(), __GO_AXES_SIZE__, jni_int_vector, (void **)&piAxesSize); setGraphicObjectProperty(iFig, __GO_AXES_SIZE__, piAxesSize, jni_int_vector, 2); releaseGraphicObjectProperty(__GO_AXES_SIZE__, piAxesSize, jni_int_vector, 2); } initBar(iFig, bMenuBar, bToolBar, bInfoBar); if (axesSize == NULL && figureSize) //figure_size { int figure[2]; figure[0] = (int)figureSize[0]; figure[1] = (int)figureSize[1]; setGraphicObjectProperty(iFig, __GO_SIZE__, figure, jni_int_vector, 2); } setGraphicObjectProperty(iFig, __GO_RESIZE__, (void*)&bResize, jni_bool, 1); //return new created fig createScalarHandle(pvApiCtx, iRhs + 1, getHandle(iFig)); AssignOutputVariable(pvApiCtx, 1) = iRhs + 1; ReturnArguments(pvApiCtx); return 0; }
TEST_F(CreateFigureFixture, shouldCreate) { CCreateFigure createFigure(nullptr, size); }