1 #include "../hrtf/mysofa.h"
2 #include "../hrtf/tools.h"
3 #include "tests.h"
4 #include <assert.h>
5 #include <float.h>
6 #include <math.h>
7 #include <stdio.h>
8 #include <string.h>
9
test_cache()10 void test_cache() {
11 char *filename1 = "build/sofacoustics.org/data/sofa_api_mo_test/Pulse.sofa";
12 char *filename2 = "tests/tester.sofa";
13 float sr1 = 48000;
14 float sr2 = 8000;
15
16 struct MYSOFA_EASY *easy1 = malloc(sizeof(struct MYSOFA_EASY));
17 struct MYSOFA_EASY *easy2 = malloc(sizeof(struct MYSOFA_EASY));
18 bzero(easy1, sizeof(struct MYSOFA_EASY));
19 bzero(easy2, sizeof(struct MYSOFA_EASY));
20
21 mysofa_close(easy2); /* must pass without segfail */
22
23 CU_ASSERT(!mysofa_cache_lookup(filename1, sr1)); /* no entry so far */
24 CU_ASSERT(mysofa_cache_store(easy1, filename1, sr1) == easy1); /* add */
25 CU_ASSERT(mysofa_cache_lookup(filename1, sr1) ==
26 easy1); /* check whether easy1 has been cached. */
27
28 mysofa_cache_release_all(); /* remove all */
29 CU_ASSERT(!mysofa_cache_lookup(filename1, sr1)); /* cache must be empty now */
30
31 /*
32 mysofa_cache_release(easy1);
33 free(easy1)
34
35 must segfail
36 */
37
38 easy1 = malloc(sizeof(struct MYSOFA_EASY));
39 bzero(easy1, sizeof(struct MYSOFA_EASY));
40
41 CU_ASSERT(mysofa_cache_store(easy1, filename1, sr1) == easy1); /* add again */
42
43 easy2 = malloc(
44 sizeof(struct MYSOFA_EASY)); /* easy2 has been freed automatically */
45 bzero(easy2, sizeof(struct MYSOFA_EASY));
46
47 CU_ASSERT(mysofa_cache_store(easy2, filename1, sr1) ==
48 easy1); /* second add must be possible too, return cached */
49
50 easy2 = malloc(
51 sizeof(struct MYSOFA_EASY)); /* easy2 has been freed automatically */
52 bzero(easy2, sizeof(struct MYSOFA_EASY));
53
54 CU_ASSERT(mysofa_cache_store(easy2, filename1, sr2) ==
55 easy2); /* now third add with different sample rate */
56
57 CU_ASSERT(mysofa_cache_lookup(filename1, sr2) == easy2);
58 mysofa_cache_release(easy2);
59 mysofa_cache_release(easy2);
60 CU_ASSERT(!mysofa_cache_lookup(filename1, sr2));
61
62 easy2 = malloc(sizeof(struct MYSOFA_EASY));
63 bzero(easy2, sizeof(struct MYSOFA_EASY));
64
65 CU_ASSERT(mysofa_cache_store(easy2, filename2, sr2) ==
66 easy2); /* now third add with different file name */
67 CU_ASSERT(mysofa_cache_lookup(filename2, sr2) == easy2);
68 mysofa_cache_release(easy2);
69 mysofa_cache_release(easy2);
70 CU_ASSERT(!mysofa_cache_lookup(filename1, sr2));
71 mysofa_cache_release_all(); /* remove all */
72 }
73