コード例 #1
0
ファイル: Sfree.c プロジェクト: doniexun/MemoryChecker
void *_safeFree(char *dataAddress, int lineNumber, char *fileName){
  MemoryDescription *freePtr;
  ErrorObject *err; 
  
  int iHeader=-1,iFooter=-1;
  Try{
    freePtr=moveBetweenList(dataAddress, fileName, lineNumber);
    // no error, will do below designation
    freePtr->freeLine      =lineNumber;
    freePtr->freeFile      =fileName;
    patternRepeat(freePtr->dataSize, "#", freePtr->memoryAddress);
    iHeader = patternCheck(freePtr->headerAddress, HEADER_SIZE, CODE_PATTERN);
    iFooter = patternCheck(freePtr->footerAddress, FOOTER_SIZE, CODE_PATTERN);
  
    if(iHeader != PASS_TICKET){
      printf("File:%p:%d: note: Memory's header integrity violated when freed@column:%d",fileName,lineNumber,iHeader);   
    }
  
    if(iFooter != PASS_TICKET){
      printf("File:%p:%d: note: Memory's footer integrity violated when freed@column:%d",fileName,lineNumber,iFooter);   
    }
  
  }Catch(err){
    printf("Error: %s\n", err->errorMsg);
    freeError(err);
  }
  
  
  

}
コード例 #2
0
ファイル: Model.c プロジェクト: bort-four/Logic
void freeModel(_md)
{
	size_t predNum, funcNum, axNum, taskNum,
		   factNum, restrNum, typeNum, srcNum, errNum;

	freeServData(modelPtr);

	/* Predicates */
	forVect(predNum, preds_m)
		freeFunc(getPredPtr(predNum));
	
	/* Functions */
	forVect(funcNum, funcs_m)
		freeFunc(getFuncPtr(funcNum));
		
	/* Axioms */
	forVect(axNum, axioms_m)
		freeAxiom(getAxPtr(axNum));

	/* Tasks */
	forVect(taskNum, taskPtrs_m)
		freeTask(getTaskPtr(taskNum));

	/* Temp Facts */
	forVect(factNum, tmpFacts_m)
		freeFact(ptr(Fact, tmpFacts_m) + factNum);

	/* Restrictions */
	forVect(restrNum, restrs_m)
		freeRestriction(getRestrPtr(restrNum));

	/* DataTypes */
	forVect(typeNum, types_m)
		freeDataType(getTypePtr(typeNum));

	/* Sources */
	forVect(srcNum, modelPtr->sources)
		freeSource(ptr(Source, modelPtr->sources) + srcNum);
	
	/* Errors */
	forVect(errNum, modelPtr->errors)
		freeError(ptr(Error, modelPtr->errors) + errNum);

	/* Vectors */
	freeVect(preds_m);
	freeVect(funcs_m);
	freeVect(axioms_m);
	freeVect(taskPtrs_m);
	freeVect(tmpFacts_m)
	freeVect(restrs_m); 
	freeVect(types_m);
	freeVect(modelPtr->errors);
	freeVect(modelPtr->sources);
}
コード例 #3
0
void test_decrypStr_given_NULL_in_Str_expected_thorw_err_STR_CANNOT_BE_NULL(void) {
    printf("No21.0 - decrypStr\n");
    CEXCEPTION_T err;
    Try{
        uint8_t* cipherKey = encrypStr("1234","9988772211334455",AES_256);
        uint8_t* invCipherKey = decrypStr(NULL,"9988772211334455",AES_256);
    } Catch(err) {
        printf("%s",err->errorMsg);
        TEST_ASSERT_EQUAL(ERR_STR_CANNOT_BE_NULL,err->errorCode);
        TEST_ASSERT_EQUAL_STRING("Error: Input plainText cannot be NULL!",err->errorMsg);
        freeError(err);
    }
}
コード例 #4
0
void test_decrypStr_given_NULL_in_decrykey_expected_thorw_err_KEY_CANNOT_BE_NULL_(void) {
    printf("No20.0 - decrypStr\n");
    CEXCEPTION_T err;
    Try{
        uint8_t* cipherKey = encrypStr("Hello,HwaNeng!!! I m LengZai","9988772211334455",AES_256);
        uint8_t* invCipherKey = decrypStr(cipherKey,NULL,AES_256);
    } Catch(err) {
        printf("%s",err->errorMsg);
        TEST_ASSERT_EQUAL(ERR_KEY_CANNOT_BE_NULL,err->errorCode);
        TEST_ASSERT_EQUAL_STRING("Error: Decrypt Key cannot be NULL!",err->errorMsg);
        freeError(err);
    }
}
コード例 #5
0
void test_decrypStr_given_a_unknown_mode_expected_thorw_err_AES_MODE_CANNOT_BE_NULL_(void) {
    printf("No19.0 - decrypStr\n");
    CEXCEPTION_T err;
    Try{
        uint8_t* cipherKey = encrypStr("Hello,HwaNeng!!! I m LengZai","9988772211334455",AES_256);
        uint8_t* invCipherKey = decrypStr(cipherKey,"9988772211334455",0);
    } Catch(err) {
        printf("%s",err->errorMsg);
        TEST_ASSERT_EQUAL(ERR_AES_MODE_CANNOT_BE_NULL,err->errorCode);
        TEST_ASSERT_EQUAL_STRING("Erorr: Please key in correct AES mode!",err->errorMsg);
        freeError(err);
    }

}
コード例 #6
0
void test_specialAdd_given_minus_7_and_88_should_throw_ERR_NUMBER_TOO_LARGE(void)
{
  //printf("HELLO\n");
  ErrorObject *err;
  //int result;
  
  Try
  {
    specialAdd(-7, 88);
  } Catch(err)
  {
    TEST_ASSERT_EQUAL_STRING("Hey! The second number must no more that 50.",  \
                               err->errorMsg);
    TEST_ASSERT_EQUAL(ERR_NUMBER_TOO_LARGE, err->errorCode);
    
    freeError(err);
  }
}
コード例 #7
0
void test_specialAdd_given_minus_7_and_minus_8_should_throw_ERR_NUMBER_NOT_POSITIVE(void)
{
  //printf("HELLO\n");
  ErrorObject *err;
  //int result;
  
  Try
  {
    specialAdd(-7, -8);
  } Catch(err)
  {
    TEST_ASSERT_EQUAL_STRING("Hey! The second number must be positive.",  \
                               err->errorMsg);
    TEST_ASSERT_EQUAL(ERR_NUMBER_NOT_POSITIVE, err->errorCode);
    
    freeError(err);
  }
}
コード例 #8
0
void test_specialAdd_given_7_and_18_should_throw_ERR_NUMBER_NOT_NEGATIVE(void)
{
  //printf("HELLO\n");
  ErrorObject *err;
  //int result;
  
  Try
  {
    specialAdd(7, 18);
  } Catch(err)
  {
    TEST_ASSERT_EQUAL_STRING("Hey! The first number must be negative.",  \
                               err->errorMsg);
    TEST_ASSERT_EQUAL(ERR_NUMBER_NOT_NEGATIVE, err->errorCode);
    
    freeError(err);
  }
}
コード例 #9
0
void test_doThings(void)
{
  ErrorObject *err;
  
 Try
 {
    doThings();
    TEST_FAIL_MESSAGE("Expect ERR_DUNNO_WHAT_HAPPEN to be thrown."  \
                      "But none throw.");
  } Catch(err)
  {
    TEST_ASSERT_EQUAL_STRING("Hey! Something is really wrong here.",   \
                               err->errorMsg);
    TEST_ASSERT_EQUAL(ERR_DUNNO_WHAT_HAPPEN, err->errorCode);
    
    freeError(err);
  }
}
コード例 #10
0
/* Given                            should catch the error.
 *            OperatorToken *
 *            --------------
 * type:      TOKEN_OPERATOR_TYPE
 * symbol:       "~="
 * arity:         0
 * assoc:         0
 * precedence:    0
 *
 */
void test_extendSingleCharacterOperator_given_illegal_symbol_should_catch_the_error(void)
{
  OperatorToken *op = (OperatorToken*)createOperatorToken("~=");
  Attributes *attr = &operatorAttributesTable[(int)*(op->symbol)];

  ErrorObject *err;
  Try
  {
    op = (OperatorToken *)attr->extend((Token *)op, attr);
    TEST_FAIL_MESSAGE("Expected to catch Error here, but didn't.\n");
  }
  Catch(err)
  {
    TEST_ASSERT_EQUAL_STRING(("%s is an undefined operator.", ((OperatorToken *)op)->symbol), \
                               err->errorMsg);
    TEST_ASSERT_EQUAL(UNDEFINED_OPERATOR, err->errorCode);
    freeError(err);
  }
}
コード例 #11
0
/* Given                            should catch the error.
 *            OperatorToken *
 *            --------------
 * type:      TOKEN_OPERATOR_TYPE
 * symbol:       '+++'
 * arity:         0
 * assoc:         0
 * precedence:    0
 *
 */
void test_tryConvertToPrefix_given_plus_plus_plus_should_fail_to_convert_to_prefix(void)
{
  OperatorToken *op = (OperatorToken*)createOperatorToken("+++");
  Attributes *attr = &operatorAttributesTable[(int)*(op->symbol)];
  OperatorToken **opP = malloc(sizeof(OperatorToken));
  opP = &op;
  ErrorObject *err;
  Try
  {
    tryConvertToPrefix((Token ***)&opP);
    TEST_FAIL_MESSAGE("Expected to catch Error here, but didn't.\n");
  }
  Catch(err)
  {
    TEST_ASSERT_EQUAL_STRING("Hey! This symbol is not belong to prefix type.", \
                               err->errorMsg);
    TEST_ASSERT_EQUAL(FAIL_TO_CONVERT_TO_PREFIX, err->errorCode);

    freeError(err);
  }
}
コード例 #12
0
void test_decrypStr_given_a_unknown_mode_expected_thorw_err_AES_MODE_CANNOT_BE_NULL_(void) {

    printf("No19.0 - decrypStr\n");

    ErrorObject* err;

    {   jmp_buf *PrevFrame, NewFrame;
        unsigned int MY_ID = (0);
        PrevFrame = CExceptionFrames[(0)].pFrame;
        CExceptionFrames[MY_ID].pFrame = (jmp_buf*)(&NewFrame);
        CExceptionFrames[MY_ID].Exception = ((void *)0);
        if (_setjmp(NewFrame) == 0) {
            if (1) {

                uint8_t* cipherKey = encrypStr("Hello,HwaNeng!!! I m LengZai","9988772211334455",3);

                uint8_t* invCipherKey = decrypStr(cipherKey,"9988772211334455",0);

            } else { } CExceptionFrames[MY_ID].Exception = ((void *)0);
        } else {
            err = CExceptionFrames[MY_ID].Exception;
            err=err;
        }
        CExceptionFrames[MY_ID].pFrame = PrevFrame;
    }
    if (CExceptionFrames[(0)].Exception != ((void *)0)) {

        printf("%s",err->errorMsg);

        UnityAssertEqualNumber((_U_SINT)((ERR_AES_MODE_CANNOT_BE_NULL)), (_U_SINT)((err->errorCode)), (((void *)0)), (_U_UINT)376, UNITY_DISPLAY_STYLE_INT);

        UnityAssertEqualString((const char*)("Erorr: Please key in correct AES mode!"), (const char*)(err->errorMsg), (((void *)0)), (_U_UINT)377);

        freeError(err);

    }



}
コード例 #13
0
void test_decrypStr_given_NULL_in_Str_expected_thorw_err_STR_CANNOT_BE_NULL(void) {

    printf("No21.0 - decrypStr\n");

    ErrorObject* err;

    {   jmp_buf *PrevFrame, NewFrame;
        unsigned int MY_ID = (0);
        PrevFrame = CExceptionFrames[(0)].pFrame;
        CExceptionFrames[MY_ID].pFrame = (jmp_buf*)(&NewFrame);
        CExceptionFrames[MY_ID].Exception = ((void *)0);
        if (_setjmp(NewFrame) == 0) {
            if (1) {

                uint8_t* cipherKey = encrypStr("1234","9988772211334455",3);

                uint8_t* invCipherKey = decrypStr(((void *)0),"9988772211334455",3);

            } else { } CExceptionFrames[MY_ID].Exception = ((void *)0);
        } else {
            err = CExceptionFrames[MY_ID].Exception;
            err=err;
        }
        CExceptionFrames[MY_ID].pFrame = PrevFrame;
    }
    if (CExceptionFrames[(0)].Exception != ((void *)0)) {

        printf("%s",err->errorMsg);

        UnityAssertEqualNumber((_U_SINT)((ERR_STR_CANNOT_BE_NULL)), (_U_SINT)((err->errorCode)), (((void *)0)), (_U_UINT)405, UNITY_DISPLAY_STYLE_INT);

        UnityAssertEqualString((const char*)("Error: Input plainText cannot be NULL!"), (const char*)(err->errorMsg), (((void *)0)), (_U_UINT)406);

        freeError(err);

    }

}