2015-07-05 10:19:22 -04:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** sngrep - SIP Messages flow viewer
|
|
|
|
**
|
2016-02-02 05:21:54 -05:00
|
|
|
** Copyright (C) 2013-2016 Ivan Alonso (Kaian)
|
|
|
|
** Copyright (C) 2013-2016 Irontec SL. All rights reserved.
|
2015-07-05 10:19:22 -04:00
|
|
|
**
|
|
|
|
** This program is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 3 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This program 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 General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
/**
|
|
|
|
* @file test_vector.c
|
|
|
|
* @author Ivan Alonso [aka Kaian] <kaian@irontec.com>
|
|
|
|
*
|
|
|
|
* Basic testing of vector structures
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "vector.h"
|
2015-08-19 09:36:27 -04:00
|
|
|
#include "util.h"
|
2015-07-05 10:19:22 -04:00
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
vector_t *vector;
|
|
|
|
|
|
|
|
// Basic Vector append/remove test
|
|
|
|
vector = vector_create(10, 10);
|
|
|
|
assert(vector);
|
|
|
|
assert(vector_count(vector) == 0);
|
|
|
|
vector_append(vector, 0);
|
|
|
|
assert(vector_count(vector) == 0);
|
2015-08-19 09:36:27 -04:00
|
|
|
vector_append(vector, sng_malloc(1024));
|
2015-07-05 10:19:22 -04:00
|
|
|
assert(vector_count(vector) == 1);
|
|
|
|
assert(vector_first(vector) == vector_item(vector, 0));
|
|
|
|
vector_remove(vector, vector_first(vector));
|
|
|
|
assert(vector_count(vector) == 0);
|
|
|
|
assert(vector_first(vector) == vector_item(vector, 0));
|
|
|
|
|
|
|
|
// Vector overflow test
|
2015-08-19 09:36:27 -04:00
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
2015-07-05 10:19:22 -04:00
|
|
|
// Next append requires memory reallocation
|
2015-08-19 09:36:27 -04:00
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
|
|
|
vector_append(vector, sng_malloc(32));
|
2015-07-05 10:19:22 -04:00
|
|
|
// Expected vector size
|
|
|
|
assert(vector_count(vector) == 16);
|
|
|
|
// Expected empty position
|
|
|
|
assert(vector_item(vector, vector_count(vector)) == 0);
|
|
|
|
// Remove position (use generic destroyer)
|
|
|
|
vector_set_destroyer(vector, vector_generic_destroyer);
|
|
|
|
vector_remove(vector, vector_item(vector, 12));
|
|
|
|
assert(vector_count(vector) == 15);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|