summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/envelope-test.c3
-rw-r--r--src/tests/get-binary-name-test.c25
-rw-r--r--src/tests/interpol-test.c81
-rw-r--r--src/tests/mix-test.c81
-rw-r--r--src/tests/remix-test.c3
-rw-r--r--src/tests/resampler-test.c3
-rw-r--r--src/tests/stripnul.c2
-rw-r--r--src/tests/usergroup-test.c161
-rw-r--r--src/tests/voltest.c70
9 files changed, 353 insertions, 76 deletions
diff --git a/src/tests/envelope-test.c b/src/tests/envelope-test.c
index 3af3044e..9382040b 100644
--- a/src/tests/envelope-test.c
+++ b/src/tests/envelope-test.c
@@ -34,8 +34,6 @@
#include <pulsecore/memblock.h>
#include <pulsecore/sample-util.h>
-#include <liboil/liboil.h>
-
const pa_envelope_def ramp_down = {
.n_points = 2,
.points_x = { 100*PA_USEC_PER_MSEC, 300*PA_USEC_PER_MSEC },
@@ -202,7 +200,6 @@ int main(int argc, char *argv[]) {
.values = { PA_VOLUME_NORM, PA_VOLUME_NORM/2 }
};
- oil_init();
pa_log_set_level(PA_LOG_DEBUG);
pa_assert_se(pool = pa_mempool_new(FALSE, 0));
diff --git a/src/tests/get-binary-name-test.c b/src/tests/get-binary-name-test.c
index a34e38fd..e49f2eff 100644
--- a/src/tests/get-binary-name-test.c
+++ b/src/tests/get-binary-name-test.c
@@ -23,12 +23,33 @@
#include <limits.h>
#include <stdio.h>
+#include <string.h>
#include <pulse/util.h>
+#include <pulse/xmalloc.h>
int main(int argc, char *argv[]) {
- char exename[PATH_MAX];
+ char *exename;
+ size_t allocated = 128;
+
+ for (;;) {
+ exename = pa_xmalloc(allocated);
+
+ if (!pa_get_binary_name(exename, allocated)) {
+ printf("failed to read binary name\n");
+ pa_xfree(exename);
+ break;
+ }
+
+ if (strlen(exename) < allocated - 1) {
+ printf("%s\n", exename);
+ pa_xfree(exename);
+ break;
+ }
+
+ pa_xfree(exename);
+ allocated *= 2;
+ }
- printf("%s\n", pa_get_binary_name(exename, sizeof(exename)));
return 0;
}
diff --git a/src/tests/interpol-test.c b/src/tests/interpol-test.c
index 0c906d3e..007555c3 100644
--- a/src/tests/interpol-test.c
+++ b/src/tests/interpol-test.c
@@ -43,20 +43,37 @@ static pa_context *context = NULL;
static pa_stream *stream = NULL;
static pa_mainloop_api *mainloop_api = NULL;
static pa_bool_t playback = TRUE;
+static pa_usec_t latency = 0;
static void stream_write_cb(pa_stream *p, size_t nbytes, void *userdata) {
/* Just some silence */
- pa_assert_se(pa_stream_write(p, pa_xmalloc0(nbytes), nbytes, pa_xfree, 0, PA_SEEK_RELATIVE) == 0);
+
+ for (;;) {
+ void *data;
+
+ pa_assert_se((nbytes = pa_stream_writable_size(p)) != (size_t) -1);
+
+ if (nbytes <= 0)
+ break;
+
+ pa_assert_se(pa_stream_begin_write(p, &data, &nbytes) == 0);
+ pa_memzero(data, nbytes);
+ pa_assert_se(pa_stream_write(p, data, nbytes, NULL, 0, PA_SEEK_RELATIVE) == 0);
+ }
}
static void stream_read_cb(pa_stream *p, size_t nbytes, void *userdata) {
- /* We don't care, just drop the data */
+ /* We don't care about the data, just drop it */
- while (pa_stream_readable_size(p) > 0) {
- const void *d;
- size_t b;
+ for (;;) {
+ const void *data;
- pa_assert_se(pa_stream_peek(p, &d, &b) == 0);
+ pa_assert_se((nbytes = pa_stream_readable_size(p)) != (size_t) -1);
+
+ if (nbytes <= 0)
+ break;
+
+ pa_assert_se(pa_stream_peek(p, &data, &nbytes) == 0);
pa_assert_se(pa_stream_drop(p) == 0);
}
}
@@ -82,27 +99,36 @@ static void context_state_callback(pa_context *c, void *userdata) {
case PA_CONTEXT_READY: {
pa_stream_flags_t flags = PA_STREAM_AUTO_TIMING_UPDATE;
-
+ pa_buffer_attr attr;
static const pa_sample_spec ss = {
.format = PA_SAMPLE_S16LE,
.rate = 44100,
.channels = 2
};
+ pa_zero(attr);
+ attr.maxlength = (uint32_t) -1;
+ attr.tlength = latency > 0 ? (uint32_t) pa_usec_to_bytes(latency, &ss) : (uint32_t) -1;
+ attr.prebuf = (uint32_t) -1;
+ attr.minreq = (uint32_t) -1;
+ attr.fragsize = (uint32_t) -1;
+
#ifdef INTERPOLATE
flags |= PA_STREAM_INTERPOLATE_TIMING;
#endif
+ if (latency > 0)
+ flags |= PA_STREAM_ADJUST_LATENCY;
+
fprintf(stderr, "Connection established.\n");
- stream = pa_stream_new(c, "interpol-test", &ss, NULL);
- assert(stream);
+ pa_assert_se(stream = pa_stream_new(c, "interpol-test", &ss, NULL));
if (playback) {
- pa_assert_se(pa_stream_connect_playback(stream, NULL, NULL, flags, NULL, NULL) == 0);
+ pa_assert_se(pa_stream_connect_playback(stream, NULL, &attr, flags, NULL, NULL) == 0);
pa_stream_set_write_callback(stream, stream_write_cb, NULL);
} else {
- pa_assert_se(pa_stream_connect_record(stream, NULL, NULL, flags) == 0);
+ pa_assert_se(pa_stream_connect_record(stream, NULL, &attr, flags) == 0);
pa_stream_set_read_callback(stream, stream_read_cb, NULL);
}
@@ -123,7 +149,7 @@ static void context_state_callback(pa_context *c, void *userdata) {
int main(int argc, char *argv[]) {
pa_threaded_mainloop* m = NULL;
- int k, r;
+ int k;
struct timeval start, last_info = { 0, 0 };
pa_usec_t old_t = 0, old_rtc = 0;
#ifdef CORK
@@ -134,24 +160,22 @@ int main(int argc, char *argv[]) {
playback = argc <= 1 || !pa_streq(argv[1], "-r");
- /* Set up a new main loop */
- m = pa_threaded_mainloop_new();
- assert(m);
-
- mainloop_api = pa_threaded_mainloop_get_api(m);
+ latency =
+ (argc >= 2 && !pa_streq(argv[1], "-r")) ? atoi(argv[1]) :
+ (argc >= 3 ? atoi(argv[2]) : 0);
- context = pa_context_new(mainloop_api, argv[0]);
- assert(context);
+ /* Set up a new main loop */
+ pa_assert_se(m = pa_threaded_mainloop_new());
+ pa_assert_se(mainloop_api = pa_threaded_mainloop_get_api(m));
+ pa_assert_se(context = pa_context_new(mainloop_api, argv[0]));
pa_context_set_state_callback(context, context_state_callback, NULL);
- r = pa_context_connect(context, NULL, 0, NULL);
- assert(r >= 0);
+ pa_assert_se(pa_context_connect(context, NULL, 0, NULL) >= 0);
pa_gettimeofday(&start);
- r = pa_threaded_mainloop_start(m);
- assert(r >= 0);
+ pa_assert_se(pa_threaded_mainloop_start(m) >= 0);
/* #ifdef CORK */
for (k = 0; k < 20000; k++)
@@ -160,7 +184,7 @@ int main(int argc, char *argv[]) {
/* #endif */
{
pa_bool_t success = FALSE, changed = FALSE;
- pa_usec_t t, rtc;
+ pa_usec_t t, rtc, d;
struct timeval now, tv;
pa_bool_t playing = FALSE;
@@ -169,7 +193,8 @@ int main(int argc, char *argv[]) {
if (stream) {
const pa_timing_info *info;
- if (pa_stream_get_time(stream, &t) >= 0)
+ if (pa_stream_get_time(stream, &t) >= 0 &&
+ pa_stream_get_latency(stream, &d, NULL) >= 0)
success = TRUE;
if ((info = pa_stream_get_timing_info(stream))) {
@@ -191,14 +216,16 @@ int main(int argc, char *argv[]) {
pa_bool_t cork_now;
#endif
rtc = pa_timeval_diff(&now, &start);
- printf("%i\t%llu\t%llu\t%llu\t%llu\t%lli\t%u\t%u\n", k,
+ printf("%i\t%llu\t%llu\t%llu\t%llu\t%lli\t%u\t%u\t%llu\t%llu\n", k,
(unsigned long long) rtc,
(unsigned long long) t,
(unsigned long long) (rtc-old_rtc),
(unsigned long long) (t-old_t),
(signed long long) rtc - (signed long long) t,
changed,
- playing);
+ playing,
+ (unsigned long long) latency,
+ (unsigned long long) d);
fflush(stdout);
old_t = t;
diff --git a/src/tests/mix-test.c b/src/tests/mix-test.c
index c7a30d67..457c4acd 100644
--- a/src/tests/mix-test.c
+++ b/src/tests/mix-test.c
@@ -32,8 +32,6 @@
#include <pulsecore/memblock.h>
#include <pulsecore/sample-util.h>
-#include <liboil/liboil.h>
-
static float swap_float(float a) {
uint32_t *b = (uint32_t*) &a;
*b = PA_UINT32_SWAP(*b);
@@ -69,6 +67,8 @@ static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) {
break;
}
+ case PA_SAMPLE_S24_32NE:
+ case PA_SAMPLE_S24_32RE:
case PA_SAMPLE_S32NE:
case PA_SAMPLE_S32RE: {
uint32_t *u = d;
@@ -83,8 +83,10 @@ static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) {
case PA_SAMPLE_S24RE: {
uint8_t *u = d;
- for (i = 0; i < chunk->length / pa_frame_size(ss); i++)
- printf("0x%02x%02x%02xx ", *(u++), *(u++), *(u++));
+ for (i = 0; i < chunk->length / pa_frame_size(ss); i++) {
+ printf("0x%02x%02x%02xx ", *u, *(u+1), *(u+2));
+ u += 3;
+ }
break;
}
@@ -123,66 +125,72 @@ static pa_memblock* generate_block(pa_mempool *pool, const pa_sample_spec *ss) {
case PA_SAMPLE_U8:
case PA_SAMPLE_ULAW:
case PA_SAMPLE_ALAW: {
- static const uint8_t u8_samples[] =
- { 0x00, 0xFF, 0x7F, 0x80, 0x9f,
- 0x3f, 0x01, 0xF0, 0x20, 0x21 };
+ static const uint8_t u8_samples[] = {
+ 0x00, 0xFF, 0x7F, 0x80, 0x9f,
+ 0x3f, 0x01, 0xF0, 0x20, 0x21
+ };
- memcpy(d, &u8_samples[0], sizeof(u8_samples));
+ memcpy(d, u8_samples, sizeof(u8_samples));
break;
}
case PA_SAMPLE_S16NE:
case PA_SAMPLE_S16RE: {
- static const uint16_t u16_samples[] =
- { 0x0000, 0xFFFF, 0x7FFF, 0x8000, 0x9fff,
- 0x3fff, 0x0001, 0xF000, 0x0020, 0x0021 };
+ static const uint16_t u16_samples[] = {
+ 0x0000, 0xFFFF, 0x7FFF, 0x8000, 0x9fff,
+ 0x3fff, 0x0001, 0xF000, 0x0020, 0x0021
+ };
- memcpy(d, &u16_samples[0], sizeof(u16_samples));
+ memcpy(d, u16_samples, sizeof(u16_samples));
break;
}
+ case PA_SAMPLE_S24_32NE:
+ case PA_SAMPLE_S24_32RE:
case PA_SAMPLE_S32NE:
case PA_SAMPLE_S32RE: {
- static const uint32_t u32_samples[] =
- { 0x00000001, 0xFFFF0002, 0x7FFF0003, 0x80000004, 0x9fff0005,
- 0x3fff0006, 0x00010007, 0xF0000008, 0x00200009, 0x0021000A };
+ static const uint32_t u32_samples[] = {
+ 0x00000001, 0xFFFF0002, 0x7FFF0003, 0x80000004, 0x9fff0005,
+ 0x3fff0006, 0x00010007, 0xF0000008, 0x00200009, 0x0021000A
+ };
- memcpy(d, &u32_samples[0], sizeof(u32_samples));
+ memcpy(d, u32_samples, sizeof(u32_samples));
break;
}
case PA_SAMPLE_S24NE:
case PA_SAMPLE_S24RE: {
- /* Need to be on a byte array because they are not aligned */
- static const uint8_t u24_samples[] =
- { 0x00, 0x00, 0x01,
- 0xFF, 0xFF, 0x02,
- 0x7F, 0xFF, 0x03,
- 0x80, 0x00, 0x04,
- 0x9f, 0xff, 0x05,
- 0x3f, 0xff, 0x06,
- 0x01, 0x00, 0x07,
- 0xF0, 0x00, 0x08,
- 0x20, 0x00, 0x09,
- 0x21, 0x00, 0x0A };
-
- memcpy(d, &u24_samples[0], sizeof(u24_samples));
+ /* Need to be on a byte array because they are not aligned */
+ static const uint8_t u24_samples[] = {
+ 0x00, 0x00, 0x01,
+ 0xFF, 0xFF, 0x02,
+ 0x7F, 0xFF, 0x03,
+ 0x80, 0x00, 0x04,
+ 0x9f, 0xff, 0x05,
+ 0x3f, 0xff, 0x06,
+ 0x01, 0x00, 0x07,
+ 0xF0, 0x00, 0x08,
+ 0x20, 0x00, 0x09,
+ 0x21, 0x00, 0x0A
+ };
+
+ memcpy(d, u24_samples, sizeof(u24_samples));
break;
}
case PA_SAMPLE_FLOAT32NE:
case PA_SAMPLE_FLOAT32RE: {
float *u = d;
- static const float float_samples[] =
- { 0.0f, -1.0f, 1.0f, 4711.0f, 0.222f,
- 0.33f, -.3f, 99.0f, -0.555f, -.123f };
+ static const float float_samples[] = {
+ 0.0f, -1.0f, 1.0f, 4711.0f, 0.222f,
+ 0.33f, -.3f, 99.0f, -0.555f, -.123f
+ };
if (ss->format == PA_SAMPLE_FLOAT32RE) {
for (i = 0; i < 10; i++)
u[i] = swap_float(float_samples[i]);
- } else {
- memcpy(d, &float_samples[0], sizeof(float_samples));
- }
+ } else
+ memcpy(d, float_samples, sizeof(float_samples));
break;
}
@@ -201,7 +209,6 @@ int main(int argc, char *argv[]) {
pa_sample_spec a;
pa_cvolume v;
- oil_init();
pa_log_set_level(PA_LOG_DEBUG);
pa_assert_se(pool = pa_mempool_new(FALSE, 0));
diff --git a/src/tests/remix-test.c b/src/tests/remix-test.c
index 9d110d6b..4990bf93 100644
--- a/src/tests/remix-test.c
+++ b/src/tests/remix-test.c
@@ -32,8 +32,6 @@
#include <pulsecore/memblock.h>
#include <pulsecore/sample-util.h>
-#include <liboil/liboil.h>
-
int main(int argc, char *argv[]) {
static const pa_channel_map maps[] = {
@@ -55,7 +53,6 @@ int main(int argc, char *argv[]) {
unsigned i, j;
pa_mempool *pool;
- oil_init();
pa_log_set_level(PA_LOG_DEBUG);
pa_assert_se(pool = pa_mempool_new(FALSE, 0));
diff --git a/src/tests/resampler-test.c b/src/tests/resampler-test.c
index 7236265a..82198b5e 100644
--- a/src/tests/resampler-test.c
+++ b/src/tests/resampler-test.c
@@ -32,8 +32,6 @@
#include <pulsecore/memblock.h>
#include <pulsecore/sample-util.h>
-#include <liboil/liboil.h>
-
static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) {
void *d;
unsigned i;
@@ -248,7 +246,6 @@ int main(int argc, char *argv[]) {
pa_sample_spec a, b;
pa_cvolume v;
- oil_init();
pa_log_set_level(PA_LOG_DEBUG);
pa_assert_se(pool = pa_mempool_new(FALSE, 0));
diff --git a/src/tests/stripnul.c b/src/tests/stripnul.c
index 1d8c4938..d677ad20 100644
--- a/src/tests/stripnul.c
+++ b/src/tests/stripnul.c
@@ -31,7 +31,7 @@
int main(int argc, char *argv[]) {
FILE *i, *o;
size_t granularity;
- pa_bool_t found;
+ pa_bool_t found = FALSE;
uint8_t *zero;
pa_assert_se(argc >= 2);
diff --git a/src/tests/usergroup-test.c b/src/tests/usergroup-test.c
new file mode 100644
index 00000000..a48b016d
--- /dev/null
+++ b/src/tests/usergroup-test.c
@@ -0,0 +1,161 @@
+/***
+ This file is part of PulseAudio.
+
+ Copyright 2009 Ted Percival
+
+ PulseAudio 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.
+
+ PulseAudio 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 PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+#include <errno.h>
+
+#include <pulsecore/usergroup.h>
+
+static int load_reference_structs(struct group **gr, struct passwd **pw) {
+ setpwent();
+ *pw = getpwent();
+ endpwent();
+
+ setgrent();
+ *gr = getgrent();
+ endgrent();
+
+ return (*gr && *pw) ? 0 : 1;
+}
+
+static int compare_group(const struct group *a, const struct group *b) {
+ char **amem, **bmem;
+
+ if (strcmp(a->gr_name, b->gr_name)) {
+ fprintf(stderr, "Group name mismatch: [%s] [%s]\n",
+ a->gr_name, b->gr_name);
+ return 1;
+ }
+
+ if (strcmp(a->gr_passwd, b->gr_passwd)) {
+ fprintf(stderr, "Group password mismatch: [%s] [%s]\n",
+ a->gr_passwd, b->gr_passwd);
+ return 1;
+ }
+
+ if (a->gr_gid != b->gr_gid) {
+ fprintf(stderr, "Gid mismatch: [%lu] [%lu]\n",
+ (unsigned long) a->gr_gid, (unsigned long) b->gr_gid);
+ return 1;
+ }
+
+ /* XXX: Assuming the group ordering is identical. */
+ for (amem = a->gr_mem, bmem = b->gr_mem; *amem && *bmem; ++amem, ++bmem) {
+ if (strcmp(*amem, *bmem)) {
+ fprintf(stderr, "Group member mismatch: [%s] [%s]\n",
+ *amem, *bmem);
+ return 1;
+ }
+ }
+
+ if (*amem || *bmem) {
+ fprintf(stderr, "Mismatched group count\n");
+ return 1;
+ }
+
+ return 0;
+}
+
+static int compare_passwd(const struct passwd *a, const struct passwd *b) {
+ if (strcmp(a->pw_name, b->pw_name)) {
+ fprintf(stderr, "pw_name mismatch: [%s] [%s]\n", a->pw_name, b->pw_name);
+ return 1;
+ }
+
+ if (strcmp(a->pw_passwd, b->pw_passwd)) {
+ fprintf(stderr, "pw_passwd mismatch: [%s] [%s]\n", a->pw_passwd, b->pw_passwd);
+ return 1;
+ }
+
+ if (a->pw_uid != b->pw_uid) {
+ fprintf(stderr, "pw_uid mismatch: [%lu] [%lu]\n",
+ (unsigned long) a->pw_uid, (unsigned long) b->pw_uid);
+ return 1;
+ }
+
+ if (a->pw_gid != b->pw_gid) {
+ fprintf(stderr, "pw_gid mismatch: [%lu] [%lu]\n",
+ (unsigned long) a->pw_gid, (unsigned long) b->pw_gid);
+ return 1;
+ }
+
+ if (strcmp(a->pw_gecos, b->pw_gecos)) {
+ fprintf(stderr, "pw_gecos mismatch: [%s] [%s]\n", a->pw_gecos, b->pw_gecos);
+ return 1;
+ }
+
+ if (strcmp(a->pw_dir, b->pw_dir)) {
+ fprintf(stderr, "pw_dir mismatch: [%s] [%s]\n", a->pw_dir, b->pw_dir);
+ return 1;
+ }
+
+ if (strcmp(a->pw_shell, b->pw_shell)) {
+ fprintf(stderr, "pw_shell mismatch: [%s] [%s]\n", a->pw_shell, b->pw_shell);
+ return 1;
+ }
+
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ struct group *gr;
+ struct passwd *pw;
+ int err;
+ struct group *reference_group = NULL;
+ struct passwd *reference_passwd = NULL;
+
+ err = load_reference_structs(&reference_group, &reference_passwd);
+ if (err)
+ return 77;
+
+ errno = 0;
+ gr = pa_getgrgid_malloc(reference_group->gr_gid);
+ if (compare_group(reference_group, gr))
+ return 1;
+ pa_getgrgid_free(gr);
+
+ errno = 0;
+ gr = pa_getgrnam_malloc(reference_group->gr_name);
+ if (compare_group(reference_group, gr))
+ return 1;
+ pa_getgrnam_free(gr);
+
+ errno = 0;
+ pw = pa_getpwuid_malloc(reference_passwd->pw_uid);
+ if (compare_passwd(reference_passwd, pw))
+ return 1;
+ pa_getpwuid_free(pw);
+
+ errno = 0;
+ pw = pa_getpwnam_malloc(reference_passwd->pw_name);
+ if (compare_passwd(reference_passwd, pw))
+ return 1;
+ pa_getpwnam_free(pw);
+
+ return 0;
+}
diff --git a/src/tests/voltest.c b/src/tests/voltest.c
index 2dcfa53c..551f7ecd 100644
--- a/src/tests/voltest.c
+++ b/src/tests/voltest.c
@@ -1,13 +1,40 @@
+/***
+ This file is part of PulseAudio.
+
+ PulseAudio 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.
+
+ PulseAudio 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 Lesser General Public License
+ along with PulseAudio; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <stdio.h>
#include <pulse/volume.h>
#include <pulse/gccmacro.h>
+#include <pulsecore/macro.h>
+
int main(int argc, char *argv[]) {
pa_volume_t v;
pa_cvolume cv;
float b;
pa_channel_map map;
+ pa_volume_t md = 0;
+ unsigned mdn = 0;
printf("Attenuation of sample 1 against 32767: %g dB\n", 20.0*log10(1.0/32767.0));
printf("Smallest possible attenutation > 0 applied to 32767: %li\n", lrint(32767.0*pa_sw_volume_to_linear(1)));
@@ -60,5 +87,48 @@ int main(int argc, char *argv[]) {
printf("After: volume: [%s]; balance: %2.1f (intended: %2.1f) %s\n", pa_cvolume_snprint(s, sizeof(s), &r), k, b, k < b-.05 || k > b+.5 ? "MISMATCH" : "");
}
+ for (v = PA_VOLUME_MUTED; v <= PA_VOLUME_NORM*2; v += 51) {
+
+ double l = pa_sw_volume_to_linear(v);
+ pa_volume_t k = pa_sw_volume_from_linear(l);
+ double db = pa_sw_volume_to_dB(v);
+ pa_volume_t r = pa_sw_volume_from_dB(db);
+ pa_volume_t w;
+
+ pa_assert(k == v);
+ pa_assert(r == v);
+
+ for (w = PA_VOLUME_MUTED; w < PA_VOLUME_NORM*2; w += 37) {
+
+ double t = pa_sw_volume_to_linear(w);
+ double db2 = pa_sw_volume_to_dB(w);
+ pa_volume_t p, p1, p2;
+ double q, qq;
+
+ p = pa_sw_volume_multiply(v, w);
+ qq = db + db2;
+ p2 = pa_sw_volume_from_dB(qq);
+ q = l*t;
+ p1 = pa_sw_volume_from_linear(q);
+
+ if (p2 > p && p2 - p > md)
+ md = p2 - p;
+ if (p2 < p && p - p2 > md)
+ md = p - p2;
+ if (p1 > p && p1 - p > md)
+ md = p1 - p;
+ if (p1 < p && p - p1 > md)
+ md = p - p1;
+
+ if (p1 != p || p2 != p)
+ mdn++;
+ }
+ }
+
+ printf("max deviation: %lu n=%lu\n", (unsigned long) md, (unsigned long) mdn);
+
+ pa_assert(md <= 1);
+ pa_assert(mdn <= 251);
+
return 0;
}