• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2010 James Grenning and Contributed to Unity Project
2  * ==========================================
3  *  Unity Project - A Test Framework for C
4  *  Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
5  *  [Released under MIT License. Please refer to license.txt for details]
6  * ========================================== */
7 
8 
9 #include "unity_output_Spy.h"
10 #include "unity_fixture.h"
11 
12 #include <stdio.h>
13 #include <string.h>
14 
15 static int size;
16 static int count;
17 static char* buffer;
18 static int spy_enable;
19 
UnityOutputCharSpy_Create(int s)20 void UnityOutputCharSpy_Create(int s)
21 {
22     size = (s > 0) ? s : 0;
23     count = 0;
24     spy_enable = 0;
25     buffer = malloc((size_t)size);
26     TEST_ASSERT_NOT_NULL_MESSAGE(buffer, "Internal malloc failed in Spy Create():" __FILE__);
27     memset(buffer, 0, (size_t)size);
28 }
29 
UnityOutputCharSpy_Destroy(void)30 void UnityOutputCharSpy_Destroy(void)
31 {
32     size = 0;
33     free(buffer);
34 }
35 
UnityOutputCharSpy_OutputChar(int c)36 void UnityOutputCharSpy_OutputChar(int c)
37 {
38     if (spy_enable)
39     {
40         if (count < (size-1))
41             buffer[count++] = (char)c;
42     }
43     else
44     {
45         putchar(c);
46     }
47 }
48 
UnityOutputCharSpy_Get(void)49 const char * UnityOutputCharSpy_Get(void)
50 {
51     return buffer;
52 }
53 
UnityOutputCharSpy_Enable(int enable)54 void UnityOutputCharSpy_Enable(int enable)
55 {
56     spy_enable = enable;
57 }
58