END_TEST START_TEST(test_parseModel_repressilator) { doc = parseModel(EXAMPLES_FILENAME("repressilator.xml"), 0, 1); ck_assert(doc != NULL); model = SBMLDocument_getModel(doc); ck_assert(model != NULL); ck_assert(Model_getNumFunctionDefinitions(model) == 0); ck_assert(Model_getNumUnitDefinitions(model) == 0); ck_assert(Model_getNumCompartmentTypes(model) == 0); ck_assert(Model_getNumSpeciesTypes(model) == 0); ck_assert(Model_getNumCompartments(model) == 1); ck_assert(Model_getNumSpecies(model) == 6); ck_assert(Model_getNumSpeciesWithBoundaryCondition(model) == 0); ck_assert(Model_getNumParameters(model) == 3); ck_assert(Model_getNumInitialAssignments(model) == 0); ck_assert(Model_getNumRules(model) == 6); ck_assert(Model_getNumConstraints(model) == 0); ck_assert(Model_getNumReactions(model) == 0); ck_assert(Model_getNumEvents(model) == 0); CHECK_PARAMETER(model, 0, "alpha"); CHECK_PARAMETER(model, 1, "beta"); CHECK_PARAMETER(model, 2, "rho"); CHECK_RULE(model, 0, "beta * (y1 - x1)"); CHECK_RULE(model, 1, "beta * (y2 - x2)"); CHECK_RULE(model, 2, "beta * (y3 - x3)"); CHECK_RULE(model, 3, "alpha * x1 / (1 + x1 + rho * x3) - y1"); CHECK_RULE(model, 4, "alpha * x2 / (1 + x2 + rho * x1) - y2"); CHECK_RULE(model, 5, "alpha * x3 / (1 + x3 + rho * x2) - y3"); }
donnee_t* creerDonnee(const char* type, const char* texte) { CHECK_PARAMETER(type, "Erreur : l'assertion n'a pas de type défini (type == NULL)."); CHECK_PARAMETER(texte, "Erreur : l'assertion n'a pas de commentaire défini (texte == NULL)."); donnee_t* d = ALLOC(1, donnee_t); d->texte = ALLOC(strlen(texte) + 1, char); d->type = ALLOC(strlen(type) + 1, char); strcpy(d->texte, texte); strcpy(d->type, type); return d; }
NTSTATUS NTAPI VTUTF8ChannelProcessAttributes(IN PSAC_CHANNEL Channel, IN UCHAR Attribute) { NTSTATUS Status; CHECK_PARAMETER(Channel); /* Set bold if needed */ Status = VTUTF8ChannelAnsiDispatch(Channel, Attribute & SAC_CELL_FLAG_BOLD ? SacAnsiSetBoldAttribute : SacAnsiClearBoldAttribute, NULL, 0); if (!NT_SUCCESS(Status)) return Status; /* Set blink if needed */ Status = VTUTF8ChannelAnsiDispatch(Channel, Attribute & SAC_CELL_FLAG_BLINK ? SacAnsiSetBlinkAttribute : SacAnsiClearBlinkAttribute, NULL, 0); if (!NT_SUCCESS(Status)) return Status; /* Set inverse if needed */ return VTUTF8ChannelAnsiDispatch(Channel, Attribute & SAC_CELL_FLAG_INVERTED ? SacAnsiSetInverseAttribute : SacAnsiClearInverseAttribute, NULL, 0); }
END_TEST START_TEST(test_parseModel_basic) { doc = parseModel(EXAMPLES_FILENAME("basic.xml"), 0, 1); ck_assert(doc != NULL); model = SBMLDocument_getModel(doc); ck_assert(model != NULL); ck_assert(Model_getNumFunctionDefinitions(model) == 0); ck_assert(Model_getNumUnitDefinitions(model) == 0); ck_assert(Model_getNumCompartmentTypes(model) == 0); ck_assert(Model_getNumSpeciesTypes(model) == 0); ck_assert(Model_getNumCompartments(model) == 1); ck_assert(Model_getNumSpecies(model) == 2); ck_assert(Model_getNumSpeciesWithBoundaryCondition(model) == 0); ck_assert(Model_getNumParameters(model) == 1); ck_assert(Model_getNumInitialAssignments(model) == 0); ck_assert(Model_getNumRules(model) == 0); ck_assert(Model_getNumConstraints(model) == 0); ck_assert(Model_getNumReactions(model) == 2); ck_assert(Model_getNumEvents(model) == 0); CHECK_PARAMETER(model, 0, "k_1"); CHECK_REACTION(model, 0, "R1", "k_1 * S1"); CHECK_REACTION(model, 1, "R2", "k_2 * S2"); }
NTSTATUS NTAPI VTUTF8ChannelOInit(IN PSAC_CHANNEL Channel) { PSAC_VTUTF8_SCREEN Screen; ULONG R, C; CHECK_PARAMETER(Channel); /* Set the current channel cell parameters */ Channel->CellFlags = 0; Channel->CellBackColor = SetBackColorBlack; Channel->CellForeColor = SetColorWhite; /* Set the cell buffer position */ Screen = (PSAC_VTUTF8_SCREEN)Channel->OBuffer; /* Loop the output buffer height by width */ for (R = 0; R < SAC_VTUTF8_ROW_HEIGHT; R++) { for (C = 0; C < SAC_VTUTF8_COL_WIDTH; C++) { /* For every character, set the defaults */ Screen->Cell[R][C].Char = L' '; Screen->Cell[R][C].CellBackColor = SetBackColorBlack; Screen->Cell[R][C].CellForeColor = SetColorWhite; } } /* All done */ return STATUS_SUCCESS; }
void detruireDonnee(donnee_t* d) { CHECK_PARAMETER(d, "Destruction de donnée impossible : donnée nulle."); free(d->texte); free(d->type); free(d); }
NTSTATUS NTAPI ChannelDestroy(IN PSAC_CHANNEL Channel) { CHECK_PARAMETER(Channel); /* Same thing as dereferencing all the handles */ return ChannelDereferenceHandles(Channel); }
void ControlMode::onInit() { NODELET_INFO("ControlMode onInit() called"); nh = getMTNodeHandle(); nh_priv = getMTPrivateNodeHandle(); // Diagnostics diag_updater.add(getName() + " status", this, &ControlMode::diagnostics); diag_updater.setHardwareID("none"); diag_updater.force_update(); // Parameters nh_priv.param("status_report_rate", status_report_rate, status_report_rate); nh_priv.param("control_output_rate", control_output_rate, control_output_rate); CHECK_PARAMETER((status_report_rate > 0), "parameter value out of range"); CHECK_PARAMETER((control_output_rate > 0), "parameter value out of range"); // Publishers control_mode_status_pub = nh_priv.advertise<control_mode_status> ("status", 1, true); }
NTSTATUS NTAPI VTUTF8ChannelDestroy(IN PSAC_CHANNEL Channel) { CHECK_PARAMETER(Channel); /* Free the buffer and then destroy the channel */ if (Channel->OBuffer) SacFreePool(Channel->OBuffer); if (Channel->IBuffer) SacFreePool(Channel->IBuffer); return ChannelDestroy(Channel); }
void detruireResultat(result_t* r) { CHECK_PARAMETER(r, "Tentative de destruction d'un resultat nulle."); int i; for (i = 0; i < r->size; i++) { detruireAssertion(r->asserts[i]); } free(r->asserts); free(r); }
void detruireAssertion(assert_t* a) { CHECK_PARAMETER(a, "Tentative de destruction d'une assertion nulle."); int i; for (i = 0; i < a->size; i++) { detruireDonnee(a->donnees[i]); } free(a->donnees); free(a->nom); free(a); }
assert_t* creerAssertion(int condition, const char* nom) { CHECK_PARAMETER(nom, "Erreur : l'assertion n'a pas de nom défini (nom == NULL)."); assert_t* a = ALLOC(1, assert_t); a->nom = ALLOC(strlen(nom) + 1, char); strcpy(a->nom, nom); a->result = condition; a->donnees = ALLOC(DATA_LIST_MAX_SIZE, donnee_t*); a->size = 0; return a; }
NTSTATUS NTAPI ChannelClose(IN PSAC_CHANNEL Channel) { NTSTATUS Status; CHECK_PARAMETER(Channel); /* Set the channel inactive */ ChannelSetStatus(Channel, Inactive); /* Set the close event */ if (Channel->Flags & SAC_CHANNEL_FLAG_CLOSE_EVENT) { ChannelSetEvent(Channel, CloseEvent); } /* Close all the handles */ Status = ChannelDereferenceHandles(Channel); return Status; }
NTSTATUS NTAPI ChannelDereferenceHandles(IN PSAC_CHANNEL Channel) { CHECK_PARAMETER(Channel); /* Clear the data event */ if (Channel->HasNewDataEvent) { ChannelUninitializeEvent(Channel, HasNewDataEvent, SAC_CHANNEL_FLAG_HAS_NEW_DATA_EVENT); } /* Clear the close event */ if (Channel->CloseEvent) { ChannelUninitializeEvent(Channel, CloseEvent, SAC_CHANNEL_FLAG_CLOSE_EVENT); } /* Clear the lock event */ if (Channel->LockEvent) { ChannelUninitializeEvent(Channel, LockEvent, SAC_CHANNEL_FLAG_LOCK_EVENT); } /* Clear the redraw event */ if (Channel->RedrawEvent) { ChannelUninitializeEvent(Channel, RedrawEvent, SAC_CHANNEL_FLAG_REDRAW_EVENT); } /* All done */ return STATUS_SUCCESS; }
NTSTATUS NTAPI RawChannelCreate(IN PSAC_CHANNEL Channel) { CHECK_PARAMETER(Channel); /* Allocate the output buffer */ Channel->OBuffer = SacAllocatePool(SAC_RAW_OBUFFER_SIZE, GLOBAL_BLOCK_TAG); CHECK_ALLOCATION(Channel->OBuffer); /* Allocate the input buffer */ Channel->IBuffer = SacAllocatePool(SAC_RAW_IBUFFER_SIZE, GLOBAL_BLOCK_TAG); CHECK_ALLOCATION(Channel->IBuffer); /* Reset all flags and return success */ Channel->OBufferIndex = 0; Channel->OBufferFirstGoodIndex = 0; Channel->ChannelHasNewIBufferData = FALSE; Channel->ChannelHasNewOBufferData = FALSE; return STATUS_SUCCESS; }
NTSTATUS NTAPI VTUTF8ChannelCreate(IN PSAC_CHANNEL Channel) { NTSTATUS Status; CHECK_PARAMETER(Channel); /* Allocate the output buffer */ Channel->OBuffer = SacAllocatePool(SAC_VTUTF8_OBUFFER_SIZE, GLOBAL_BLOCK_TAG); CHECK_ALLOCATION(Channel->OBuffer); /* Allocate the input buffer */ Channel->IBuffer = SacAllocatePool(SAC_VTUTF8_IBUFFER_SIZE, GLOBAL_BLOCK_TAG); CHECK_ALLOCATION(Channel->IBuffer); /* Initialize the output stream */ Status = VTUTF8ChannelOInit(Channel); if (NT_SUCCESS(Status)) return Status; /* Reset all flags and return success */ _InterlockedExchange(&Channel->ChannelHasNewOBufferData, 0); _InterlockedExchange(&Channel->ChannelHasNewIBufferData, 0); return STATUS_SUCCESS; }
NTSTATUS NTAPI VTUTF8ChannelOFlush(IN PSAC_CHANNEL Channel) { NTSTATUS Status; PSAC_VTUTF8_SCREEN Screen; INT Color[2], Position[2]; ULONG Utf8ProcessedCount, Utf8Count, R, C, ForeColor, BackColor, Attribute; PWCHAR TmpBuffer; BOOLEAN Overflow = FALSE; CHECK_PARAMETER(Channel); /* Set the cell buffer position */ Screen = (PSAC_VTUTF8_SCREEN)Channel->OBuffer; /* Allocate a temporary buffer */ TmpBuffer = SacAllocatePool(40, GLOBAL_BLOCK_TAG); if (!TmpBuffer) { Status = STATUS_NO_MEMORY; goto Quickie; } /* First, clear the screen */ Status = VTUTF8ChannelAnsiDispatch(Channel, SacAnsiClearScreen, NULL, 0); if (!NT_SUCCESS(Status)) goto Quickie; /* Next, reset the cursor position */ Position[1] = 0; Position[0] = 0; Status = VTUTF8ChannelAnsiDispatch(Channel, SacAnsiSetPosition, Position, sizeof(Position)); if (!NT_SUCCESS(Status)) goto Quickie; /* Finally, reset the attributes */ Status = VTUTF8ChannelAnsiDispatch(Channel, SacAnsiClearAttributes, NULL, 0); if (!NT_SUCCESS(Status)) goto Quickie; /* Now set the current cell attributes */ Attribute = Channel->CellFlags; Status = VTUTF8ChannelProcessAttributes(Channel, Attribute); if (!NT_SUCCESS(Status)) goto Quickie; /* And set the current cell colors */ ForeColor = Channel->CellForeColor; BackColor = Channel->CellBackColor; Color[1] = BackColor; Color[0] = ForeColor; Status = VTUTF8ChannelAnsiDispatch(Channel, SacAnsiSetColors, Color, sizeof(Color)); if (!NT_SUCCESS(Status)) goto Quickie; /* Now loop all the characters in the cell buffer */ for (R = 0; R < SAC_VTUTF8_ROW_HEIGHT; R++) { /* Across every row */ for (C = 0; C < SAC_VTUTF8_COL_WIDTH; C++) { /* Check if there's been a change in colors */ if ((Screen->Cell[R][C].CellBackColor != BackColor) || (Screen->Cell[R][C].CellForeColor != ForeColor)) { /* New colors are being drawn -- are we also on a new row now? */ if (Overflow) { /* Reposition the cursor correctly */ Position[1] = R; Position[0] = C; Status = VTUTF8ChannelAnsiDispatch(Channel, SacAnsiSetPosition, Position, sizeof(Position)); if (!NT_SUCCESS(Status)) goto Quickie; Overflow = FALSE; } /* Cache the new colors */ ForeColor = Screen->Cell[R][C].CellForeColor; BackColor = Screen->Cell[R][C].CellBackColor; /* Set them on the screen */ Color[1] = BackColor; Color[0] = ForeColor; Status = VTUTF8ChannelAnsiDispatch(Channel, SacAnsiSetColors, Color, sizeof(Color)); if (!NT_SUCCESS(Status)) goto Quickie; } /* Check if there's been a change in attributes */ if (Screen->Cell[R][C].CellFlags != Attribute) { /* Yep! Are we also on a new row now? */ if (Overflow) { /* Reposition the cursor correctly */ Position[1] = R; Position[0] = C; Status = VTUTF8ChannelAnsiDispatch(Channel, SacAnsiSetPosition, Position, sizeof(Position)); if (!NT_SUCCESS(Status)) goto Quickie; Overflow = FALSE; } /* Set the new attributes on screen */ Attribute = Screen->Cell[R][C].CellFlags; Status = VTUTF8ChannelProcessAttributes(Channel, Attribute); if (!NT_SUCCESS(Status)) goto Quickie; } /* Time to write the character -- are we on a new row now? */ if (Overflow) { /* Reposition the cursor correctly */ Position[1] = R; Position[0] = C; Status = VTUTF8ChannelAnsiDispatch(Channel, SacAnsiSetPosition, Position, sizeof(Position)); if (!NT_SUCCESS(Status)) goto Quickie; Overflow = FALSE; } /* Write the character into our temporary buffer */ *TmpBuffer = Screen->Cell[R][C].Char; TmpBuffer[1] = UNICODE_NULL; /* Convert it to UTF-8 */ if (!SacTranslateUnicodeToUtf8(TmpBuffer, 1, Utf8ConversionBuffer, Utf8ConversionBufferSize, &Utf8Count, &Utf8ProcessedCount)) { /* Bail out if this failed */ Status = STATUS_UNSUCCESSFUL; goto Quickie; } /* Make sure we have a remaining valid character */ if (Utf8Count) { /* Write it out on the wire */ Status = ConMgrWriteData(Channel, Utf8ConversionBuffer, Utf8Count); if (!NT_SUCCESS(Status)) goto Quickie; } } /* All the characters on the row are done, indicate we need a reset */ Overflow = TRUE; } /* Everything is done, set the positition one last time */ Position[1] = Channel->CursorRow; Position[0] = Channel->CursorCol; Status = VTUTF8ChannelAnsiDispatch(Channel, SacAnsiSetPosition, Position, sizeof(Position)); if (!NT_SUCCESS(Status)) goto Quickie; /* Set the current attribute one last time */ Status = VTUTF8ChannelProcessAttributes(Channel, Channel->CellFlags); if (!NT_SUCCESS(Status)) goto Quickie; /* Set the current colors one last time */ Color[1] = Channel->CellBackColor; Color[0] = Channel->CellForeColor; Status = VTUTF8ChannelAnsiDispatch(Channel, SacAnsiSetColors, Color, sizeof(Color)); if (!NT_SUCCESS(Status)) goto Quickie; /* Flush all the data out on the wire */ Status = ConMgrFlushData(Channel); Quickie: /* We're done, free the temporary buffer */ if (TmpBuffer) SacFreePool(TmpBuffer); /* Indicate that all new data has been flushed now */ if (NT_SUCCESS(Status)) { _InterlockedExchange(&Channel->ChannelHasNewOBufferData, 0); } /* Return the result */ return Status; }
NTSTATUS NTAPI ChannelCreate(IN PSAC_CHANNEL Channel, IN PSAC_CHANNEL_ATTRIBUTES Attributes, IN SAC_CHANNEL_ID ChannelId) { NTSTATUS Status; CHECK_PARAMETER1(Channel); CHECK_PARAMETER2(Attributes); /* If a close event is being passed in, it must exist, and vice-versa */ if (Attributes->Flag & SAC_CHANNEL_FLAG_CLOSE_EVENT) { CHECK_PARAMETER(Attributes->CloseEvent != NULL); } else { CHECK_PARAMETER(Attributes->CloseEvent == NULL); } /* If a new data event is being passed in, it must exist, and vice-versa */ if (Attributes->Flag & SAC_CHANNEL_FLAG_HAS_NEW_DATA_EVENT) { CHECK_PARAMETER(Attributes->HasNewDataEvent != NULL); } else { CHECK_PARAMETER(Attributes->HasNewDataEvent == NULL); } /* If a lock event is being passed in, it must exist, and vice-versa */ if (Attributes->Flag & SAC_CHANNEL_FLAG_LOCK_EVENT) { CHECK_PARAMETER(Attributes->LockEvent != NULL); } else { CHECK_PARAMETER(Attributes->LockEvent == NULL); } /* If a redraw event is being passed in, it must exist, and vice-versa */ if (Attributes->Flag & SAC_CHANNEL_FLAG_REDRAW_EVENT) { CHECK_PARAMETER(Attributes->RedrawEvent != NULL); } else { CHECK_PARAMETER(Attributes->RedrawEvent == NULL); } /* Initialize the channel structure */ RtlZeroMemory(Channel, sizeof(SAC_CHANNEL)); Channel->ChannelId = ChannelId; Channel->ChannelType = Attributes->ChannelType; Channel->Flags = Attributes->Flag; if (Attributes->Flag & SAC_CHANNEL_FLAG_APPLICATION) { Channel->ApplicationType = Attributes->ChannelId; } /* Initialize all the locks and events */ SacInitializeLock(&Channel->ChannelAttributeLock); SacInitializeLock(&Channel->ChannelOBufferLock); SacInitializeLock(&Channel->ChannelIBufferLock); ChannelInitializeEvent(Channel, Attributes, CloseEvent); ChannelInitializeEvent(Channel, Attributes, HasNewDataEvent); ChannelInitializeEvent(Channel, Attributes, LockEvent); ChannelInitializeEvent(Channel, Attributes, RedrawEvent); /* Set the name and description */ ChannelSetName(Channel, Attributes->NameBuffer); ChannelSetDescription(Channel, Attributes->DescriptionBuffer); /* Initialize the function table for the type of channel this is */ Status = ChannelInitializeVTable(Channel); if (!NT_SUCCESS(Status)) { /* This is critical */ SAC_DBG(SAC_DBG_INIT, "SAC Create Channel :: Failed to initialize vtable\n"); goto FailChannel; } /* Now call the channel specific type constructor */ Status = Channel->ChannelCreate(Channel); if (!NT_SUCCESS(Status)) { /* This is critical */ SAC_DBG(SAC_DBG_INIT, "SAC Create Channel :: Failed channel specific initialization\n"); goto FailChannel; } /* Finally, mark the channel as active */ ChannelSetStatus(Channel, Active); return STATUS_SUCCESS; FailChannel: /* Destroy the channel and return the failure code */ Channel->ChannelDestroy(Channel); return Status; }
H_U32 _StorageUpdata(device_storage_gather_t *device_info) { H_U32 retcode; WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"in __storage_device_updata"); CHECK_PARAMETER(device_info, H_NULL, H_FAULTER); //H_U8 * buffer = H_NULL; //buffer = (H_U8 *)wy_malloc(STORAGE_BLOCK_LEN); //if( buffer == H_NULL) //{ // WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"malloc fail"); // return H_FAULTER; //} static H_U8 storage_buffer[STORAGE_BLOCK_LEN] = {0}; H_U32 offset = 0; H_U32 magic_data = 0; wy_memset(storage_buffer,0xFF,STORAGE_BLOCK_LEN); //WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"reading entire block..."); if(_StorageRead(device_info->handler, STORAGE_BLOCK_LEN,0,storage_buffer,device_info->user_block_size) != H_SUCCESS) { WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"read fail"); //wy_free(buffer); //buffer = H_NULL; return H_FAULTER; } //WYPrintf_array(storage_buffer, STORAGE_BLOCK_LEN); wy_tools_op()->_delay_ms(10); offset = device_info->id * device_info->user_block_size ; WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"offset will be:%d",offset); magic_data = decode32(storage_buffer, offset); if(magic_data == device_info->magic_data || magic_data == 0) // check whether this block has been written before and is written by correct module { //workaround WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"magic1"); if(device_info->magic_clear)//delete a record { WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"magic2"); wy_memset(&(storage_buffer[offset]), 0xff, device_info->hand_len); } wy_memcpy(&(storage_buffer[offset + device_info->hand_len]), device_info->data, device_info->data_len); } else //this block has not been written before { if(!device_info->magic_clear)//add a record { encode32(device_info->magic_data, storage_buffer, offset); wy_memcpy(&(storage_buffer[offset + device_info->hand_len]), device_info->data, device_info->data_len); WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"magic3:%x ",device_info->magic_data); } } retcode = _StorageErase(device_info->handler,STORAGE_BLOCK_LEN); WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"erasing module:%d block :%d",device_info->handler->module_id,device_info->handler->block_id); WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"ret of erase:%d",retcode); if(retcode != H_SUCCESS) { WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"erase fail"); //wy_free(buffer); //buffer = H_NULL; return H_FAULTER; } //wy_tools_op()->_delay_ms(100); //WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"before write1 for module:%d",device_info->handler->module_id); retcode = _StorageWrite(device_info->handler,storage_buffer,STORAGE_BLOCK_LEN, 0,device_info->user_block_size); WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"ret of write:%d block size:%d",retcode,device_info->user_block_size); if(retcode != H_SUCCESS) { WYPrintf(MODULE_DEBUG_STORAGE,LEVEL_DEBUG,"rewrite fail"); //wy_free(buffer); //buffer = H_NULL; return H_FAULTER; } wy_tools_op()->_delay_ms(100); //wy_free(buffer); //buffer = H_NULL; return H_SUCCESS; }