コード例 #1
0
void test_circularBufferRemoveInt_until_overflow_should_wrap_over_to_beginning_of_buffer() {
	CircularBuffer *cb = circularBufferNew(4, sizeof(int));	
	int arrayInts[] = {0xdead, 0xbeef, 0xbad, 0xc0ffee, 0xfee1bad};
	int data;
	
	circularBufferAddInt(cb, &arrayInts[0]);
	circularBufferAddInt(cb, &arrayInts[1]);
	circularBufferAddInt(cb, &arrayInts[2]);
	circularBufferAddInt(cb, &arrayInts[3]);
	circularBufferRemoveInt(cb, &data);
	TEST_ASSERT_EQUAL(0xdead, data);
	circularBufferAddInt(cb, &arrayInts[4]);			// should wrap over
	circularBufferRemoveInt(cb, &data);
	TEST_ASSERT_EQUAL(0xbeef, data);
	circularBufferRemoveInt(cb, &data);
	TEST_ASSERT_EQUAL(0xbad, data);
	circularBufferRemoveInt(cb, &data);
	TEST_ASSERT_EQUAL(0xc0ffee, data);
	circularBufferRemoveInt(cb, &data);
	TEST_ASSERT_EQUAL(0xfee1bad, data);
	TEST_ASSERT_EQUAL(0, cb->size);		
	TEST_ASSERT_EQUAL((int *)cb->head, &((int *)cb->buffer)[1]);
	TEST_ASSERT_EQUAL((int *)cb->tail, &((int *)cb->buffer)[1]);
	circularBufferDel(cb);
}
コード例 #2
0
void test_circularBufferRemove_given_13_should_return_13(void)

{

 unsigned int err;

 CircularBuffer *cb = circularBufferNew(5);

 int value_been_removed ;



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

 {

  CircularBufferAdd(cb,13);

  value_been_removed = circularBufferRemove(cb);

  UnityAssertEqualNumber((_U_SINT)((13)), (_U_SINT)((value_been_removed)), (((void *)0)), (_U_UINT)180, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((0)), (_U_SINT)((cb->size)), (((void *)0)), (_U_UINT)181, UNITY_DISPLAY_STYLE_INT);

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

  UnityAssertEqualNumber((_U_SINT)((ERR_BUFFER_IS_EMPTY)), (_U_SINT)((err)), (((void *)0)), (_U_UINT)183, UNITY_DISPLAY_STYLE_INT);

  printf("Caught a ERR_BUFFER_IS_EMPTY exception! Error code is: %i" , err);

 }

 circularBufferDel(cb);

}
コード例 #3
0
void test_CircularBufferAdd_given_value_6_7_8_9_should_get_9_8_7_6(void)

{

 unsigned int err;

 CircularBuffer *cb = circularBufferNew(5);

 int *temp = cb->buffer;



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

 {

  CircularBufferAdd(cb,6);

  CircularBufferAdd(cb,7);

  CircularBufferAdd(cb,8);

  CircularBufferAdd(cb,9);

  if ((((cb)) != ((void *)0))) {} else {UnityFail( (" Expected Non-NULL"), (_U_UINT)(_U_UINT)(_U_UINT)114);;};

  if ((((cb->buffer)) != ((void *)0))) {} else {UnityFail( (" Expected Non-NULL"), (_U_UINT)(_U_UINT)(_U_UINT)115);;};

  UnityAssertEqualNumber((_U_SINT)((5)), (_U_SINT)((cb->length)), (((void *)0)), (_U_UINT)116, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((4)), (_U_SINT)((cb->size)), (((void *)0)), (_U_UINT)117, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((6)), (_U_SINT)((*(temp))), (((void *)0)), (_U_UINT)118, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((7)), (_U_SINT)((*(temp+1))), (((void *)0)), (_U_UINT)119, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((8)), (_U_SINT)((*(temp+2))), (((void *)0)), (_U_UINT)120, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((9)), (_U_SINT)((*(temp+3))), (((void *)0)), (_U_UINT)121, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)(_UP)((9)), (_U_SINT)(_UP)((*(cb->head))), (((void *)0)), (_U_UINT)122, UNITY_DISPLAY_STYLE_HEX32);

  UnityAssertEqualNumber((_U_SINT)(_UP)((6)), (_U_SINT)(_UP)((*(cb->tail))), (((void *)0)), (_U_UINT)123, UNITY_DISPLAY_STYLE_HEX32);

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



  UnityAssertEqualNumber((_U_SINT)((ERR_BUFFER_IS_FULL)), (_U_SINT)((err)), (((void *)0)), (_U_UINT)126, UNITY_DISPLAY_STYLE_INT);

  UnityFail( ("Do not expect exception to be generated"), (_U_UINT)127);;

 }

 circularBufferDel(cb);

}
コード例 #4
0
void test_circularBufferAddInt_should_add_1_integer(void)
{
	CircularBuffer *cb = circularBufferNew(10, sizeof(int));
	
	TEST_ASSERT_EQUAL(1,cb->size);
	TEST_ASSERT_EQUAL(10,cb->length);
	TEST_ASSERT_EQUAL((int*)cb->head, &((int *)cb->buffer)[1]);
	TEST_ASSERT_EQUAL((int*)cb->tail, &((int *)cb->buffer)[1]);
	circularBufferDel(cb);
}
コード例 #5
0
void test_circularBufferNew_should_create_new_CircularBuffer_object_of_integer_type() {
	CircularBuffer *cb = circularBufferNew(7, sizeof(int));
	TEST_ASSERT_NOT_NULL(cb);
	TEST_ASSERT_NOT_NULL(cb->buffer);
	TEST_ASSERT_EQUAL_PTR(cb->buffer, cb->head);
	TEST_ASSERT_EQUAL_PTR(cb->buffer, cb->tail);
	TEST_ASSERT_EQUAL(0, cb->size);
	TEST_ASSERT_EQUAL(7, cb->length);
	TEST_ASSERT_EQUAL(sizeof(int), cb->sizeOfType);
	circularBufferDel(cb);
}
コード例 #6
0
void test_circularBufferAddInt_1_integer_should_add_0xbeef() {
	CircularBuffer *cb = circularBufferNew(4, sizeof(int));	
	int integer = 0xbeef;
	
	circularBufferAddInt(cb, &integer);
	TEST_ASSERT_EQUAL(1, cb->size);
	TEST_ASSERT_EQUAL(4, cb->length);
	TEST_ASSERT_EQUAL((int *)cb->head, &((int *)cb->buffer)[1]);
	TEST_ASSERT_EQUAL((int *)cb->tail, &((int *)cb->buffer)[0]);
	TEST_ASSERT_EQUAL(0xbeef, ((int *)cb->buffer)[0]);
	circularBufferDel(cb);
}
コード例 #7
0
void test_circularBufferNew_should_create_new_CircularBuffer_object_of_double_type(void)
{
	CircularBuffer *cb = circularBufferNew(13, sizeof(double));
	
	TEST_ASSERT_NOT_NULL(cb);
	TEST_ASSERT_NOT_NULL(cb->buffer);
	TEST_ASSERT_EQUAL_PTR(cb->buffer,cb->head);
	TEST_ASSERT_EQUAL_PTR(cb->buffer,cb->tail);
	TEST_ASSERT_EQUAL(0,cb->size);
	TEST_ASSERT_EQUAL(13,cb->length);
	TEST_ASSERT_EQUAL(sizeof(double), cb->sizeOfType);
	circularBufferDel(cb);
	
}
コード例 #8
0
void test_circularBufferAddInt_2_integers_should_add_the_2_integers() {
	CircularBuffer *cb = circularBufferNew(4, sizeof(int));	
	int arrayInts[] = {0xdead, 0xbeef};
	
	circularBufferAddInt(cb, &arrayInts[0]);
	circularBufferAddInt(cb, &arrayInts[1]);
	TEST_ASSERT_EQUAL(2, cb->size);
	TEST_ASSERT_EQUAL(4, cb->length);
	TEST_ASSERT_EQUAL((int *)cb->head, &((int *)cb->buffer)[2]);
	TEST_ASSERT_EQUAL((int *)cb->tail, &((int *)cb->buffer)[0]);
	TEST_ASSERT_EQUAL(0xdead, ((int *)cb->buffer)[0]);
	TEST_ASSERT_EQUAL(0xbeef, ((int *)cb->buffer)[1]);
	circularBufferDel(cb);
}
コード例 #9
0
void test_circularBufferRemoveInt_an_integer_should_remain_1_integer_in_buffer() {
	CircularBuffer *cb = circularBufferNew(4, sizeof(int));	
	int arrayInts[] = {0xdead, 0xbeef};
	int data;
	
	circularBufferAddInt(cb, &arrayInts[0]);
	circularBufferAddInt(cb, &arrayInts[1]);
	circularBufferRemoveInt(cb, &data);
	TEST_ASSERT_EQUAL(2, cb->size);
	TEST_ASSERT_EQUAL(0xdead, data);	
	TEST_ASSERT_EQUAL((int *)cb->head, &((int *)cb->buffer)[2]);
	TEST_ASSERT_EQUAL((int *)cb->tail, &((int *)cb->buffer)[1]);
	TEST_ASSERT_EQUAL(0xbeef, ((int *)cb->buffer)[1]);
	circularBufferDel(cb);
}
コード例 #10
0
void test_circularBufferNew_given_6_should_allocate_CircularBuffer_object_with_a_buffer_of_6(void)

{

 CircularBuffer *cb = circularBufferNew(5);

 if ((((cb)) != ((void *)0))) {} else {UnityFail( (" Expected Non-NULL"), (_U_UINT)(_U_UINT)(_U_UINT)18);;};

 if ((((cb->buffer)) != ((void *)0))) {} else {UnityFail( (" Expected Non-NULL"), (_U_UINT)(_U_UINT)(_U_UINT)19);;};

 UnityAssertEqualNumber((_U_SINT)((5)), (_U_SINT)((cb->length)), (((void *)0)), (_U_UINT)20, UNITY_DISPLAY_STYLE_INT);

 UnityAssertEqualNumber((_U_SINT)((0)), (_U_SINT)((cb->size)), (((void *)0)), (_U_UINT)21, UNITY_DISPLAY_STYLE_INT);

 UnityAssertEqualNumber((_U_SINT)(_UP)((cb->buffer)), (_U_SINT)(_UP)((cb->head)), (((void *)0)), (_U_UINT)22, UNITY_DISPLAY_STYLE_HEX32);

 UnityAssertEqualNumber((_U_SINT)(_UP)((cb->buffer)), (_U_SINT)(_UP)((cb->tail)), (((void *)0)), (_U_UINT)23, UNITY_DISPLAY_STYLE_HEX32);

 circularBufferDel(cb);

}
コード例 #11
0
void test_CircularBufferAdd_given_value_6_should_add_into_the_first_buffer(void)

{

 unsigned int err;

 CircularBuffer *cb = circularBufferNew(5);

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

 {

  CircularBufferAdd(cb,6);

  if ((((cb)) != ((void *)0))) {} else {UnityFail( (" Expected Non-NULL"), (_U_UINT)(_U_UINT)(_U_UINT)34);;};

  if ((((cb->buffer)) != ((void *)0))) {} else {UnityFail( (" Expected Non-NULL"), (_U_UINT)(_U_UINT)(_U_UINT)35);;};

  UnityAssertEqualNumber((_U_SINT)((5)), (_U_SINT)((cb->length)), (((void *)0)), (_U_UINT)36, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((1)), (_U_SINT)((cb->size)), (((void *)0)), (_U_UINT)37, UNITY_DISPLAY_STYLE_INT);

  UnityAssertEqualNumber((_U_SINT)((6)), (_U_SINT)((*(cb->head))), (((void *)0)), (_U_UINT)38, UNITY_DISPLAY_STYLE_INT);

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



  UnityAssertEqualNumber((_U_SINT)((ERR_BUFFER_IS_FULL)), (_U_SINT)((err)), (((void *)0)), (_U_UINT)41, UNITY_DISPLAY_STYLE_INT);

  UnityFail( ("Do not expect exception to be generated"), (_U_UINT)42);;

 }



    circularBufferDel(cb);

}
コード例 #12
0
void test_CircularBufferAdd_given_buffer_is_full_but_trying_to_add_should_throw_ERR_BUFFER_IS_FULL(void)

{

 unsigned int err;

 CircularBuffer *cb = circularBufferNew(5);



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

 {

  CircularBufferAdd(cb,6);

  CircularBufferAdd(cb,7);

  CircularBufferAdd(cb,8);

  CircularBufferAdd(cb,9);

  CircularBufferAdd(cb,10);

  CircularBufferAdd(cb,11);

  UnityFail( ("Expect ERR_BUFFER_IS_FULL exception to be generated"), (_U_UINT)145);;

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

  UnityAssertEqualNumber((_U_SINT)((ERR_BUFFER_IS_FULL)), (_U_SINT)((err)), (((void *)0)), (_U_UINT)147, UNITY_DISPLAY_STYLE_INT);

  printf("Caught a ERR_BUFFER_IS_FULL exception! Error code is: %i" , err);

 }

 circularBufferDel(cb);

}