LMMS
Loading...
Searching...
No Matches
atom-test-utils.c
Go to the documentation of this file.
1/*
2 Copyright 2012-2018 David Robillard <d@drobilla.net>
3
4 Permission to use, copy, modify, and/or distribute this software for any
5 purpose with or without fee is hereby granted, provided that the above
6 copyright notice and this permission notice appear in all copies.
7
8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17#include "lv2/atom/atom.h"
18#include "lv2/atom/forge.h"
19#include "lv2/atom/util.h"
20#include "lv2/log/log.h"
21#include "lv2/urid/urid.h"
22
23#include <stdarg.h>
24#include <stdio.h>
25#include <stdlib.h>
26
27static char** uris = NULL;
28static uint32_t n_uris = 0;
29
30static char*
31copy_string(const char* str)
32{
33 const size_t len = strlen(str);
34 char* dup = (char*)malloc(len + 1);
35 memcpy(dup, str, len + 1);
36 return dup;
37}
38
39static LV2_URID
40urid_map(LV2_URID_Map_Handle handle, const char* uri)
41{
42 for (uint32_t i = 0; i < n_uris; ++i) {
43 if (!strcmp(uris[i], uri)) {
44 return i + 1;
45 }
46 }
47
48 uris = (char**)realloc(uris, ++n_uris * sizeof(char*));
49 uris[n_uris - 1] = copy_string(uri);
50 return n_uris;
51}
52
53static void
55{
56 for (uint32_t i = 0; i < n_uris; ++i) {
57 free(uris[i]);
58 }
59
60 free(uris);
61}
62
63LV2_LOG_FUNC(1, 2)
64static int
65test_fail(const char* fmt, ...)
66{
67 va_list args;
68 va_start(args, fmt);
69 fprintf(stderr, "error: ");
70 vfprintf(stderr, fmt, args);
71 va_end(args);
72 return 1;
73}
#define NULL
Definition CarlaBridgeFormat.cpp:30
static int test_fail(const char *fmt,...)
Definition atom-test-utils.c:65
static char * copy_string(const char *str)
Definition atom-test-utils.c:31
static char ** uris
Definition atom-test-utils.c:27
static void free_urid_map(void)
Definition atom-test-utils.c:54
static uint32_t n_uris
Definition atom-test-utils.c:28
register unsigned i
Definition inflate.c:1575
void * LV2_URID_Map_Handle
Definition urid.h:48
uint32_t LV2_URID
Definition urid.h:58
static SordNode * uri(SordWorld *world, int num)
Definition sord_test.c:47
static LilvNode * urid_map
Definition lv2bench.c:37
unsigned int uint32_t
Definition mid.cpp:100
memcpy(hh, h, RAND_HEAD_LEN)
fmt[0]
Definition fileio.c:2503
char * malloc()
#define const
Definition zconf.h:137