Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers unity_output_Spy.c Source File

unity_output_Spy.c

00001 //- Copyright (c) 2010 James Grenning and Contributed to Unity Project
00002 /* ==========================================
00003     Unity Project - A Test Framework for C
00004     Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
00005     [Released under MIT License. Please refer to license.txt for details]
00006 ========================================== */
00007 
00008 
00009 #include "unity_output_Spy.h"
00010 #include "unity_fixture.h"
00011 
00012 #include <stdio.h>
00013 #include <string.h>
00014 
00015 static int size;
00016 static int count;
00017 static char* buffer;
00018 static int spy_enable;
00019 
00020 void UnityOutputCharSpy_Create(int s)
00021 {
00022     size = (s > 0) ? s : 0;
00023     count = 0;
00024     spy_enable = 0;
00025     buffer = malloc((size_t)size);
00026     TEST_ASSERT_NOT_NULL_MESSAGE(buffer, "Internal malloc failed in Spy Create():" __FILE__);
00027     memset(buffer, 0, (size_t)size);
00028 }
00029 
00030 void UnityOutputCharSpy_Destroy(void)
00031 {
00032     size = 0;
00033     free(buffer);
00034 }
00035 
00036 void UnityOutputCharSpy_OutputChar(int c)
00037 {
00038     if (spy_enable)
00039     {
00040         if (count < (size-1))
00041             buffer[count++] = (char)c;
00042     }
00043     else
00044     {
00045         putchar(c);
00046     }
00047 }
00048 
00049 const char * UnityOutputCharSpy_Get(void)
00050 {
00051     return buffer;
00052 }
00053 
00054 void UnityOutputCharSpy_Enable(int enable)
00055 {
00056     spy_enable = enable;
00057 }