Unit tests for SmartRest

Dependencies:   C027 SmartRest mbed

mock/BufferedDataSource.cpp

Committer:
vwochnik
Date:
2014-03-24
Revision:
0:789029e49ea1

File content as of revision 0:789029e49ea1:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "BufferedDataSource.h"

BufferedDataSource::BufferedDataSource()
{
    clear();
}

void BufferedDataSource::set(char *buf, size_t length)
{
    _data = _ptr = buf;
    _length = length;
}

void BufferedDataSource::set(const char *str)
{
    _data = _ptr = (char *)str;
    _length = strlen(str);
}

void BufferedDataSource::clear()
{
    _data = _ptr = NULL;
    _length = 0;
}

bool BufferedDataSource::exhausted()
{
    return (_ptr - _data) == _length;
}

char BufferedDataSource::read()
{
    if (exhausted())
        return 0;
    return *_ptr++;
}

uint8_t BufferedDataSource::status()
{
    if (exhausted())
        return DS_STATUS_CLOSED;
    return DS_STATUS_OK;
}