libvirt/tests/virrandommock.c
John Ferlan 6a3f4121a5 tests: Add mock for virRandomBytes
Create a mock for virRandomBytes to generate a not so random value.
This should be usable by other tests that need a not so random number
to be generated by including the virrandommock at preload.

The "random number" generated is based upon the size of the expected
stream of bytes being returned where each byte in the result gets
the index of the array - hence a 4 byte array returns 0x00010203.
2016-05-20 09:36:28 -04:00

40 lines
1.0 KiB
C

/*
* Copyright (C) 2016 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Author: John Ferlan <jferlan@redhat.com>
*/
#include <config.h>
#include "internal.h"
#include "virrandom.h"
#include "virmock.h"
#define VIR_FROM_THIS VIR_FROM_NONE
int
virRandomBytes(unsigned char *buf,
size_t buflen)
{
size_t i;
for (i = 0; i < buflen; i++)
buf[i] = i;
return 0;
}