File: tests_volca_sample.c

package info (click to toggle)
elektroid 3.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,236 kB
  • sloc: ansic: 33,475; sh: 582; makefile: 394; xml: 78
file content (194 lines) | stat: -rw-r--r-- 4,972 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <CUnit/CUnit.h>
#include <CUnit/Basic.h>
#include <sndfile.h>
#include "../src/sample.h"
#include "../src/utils.h"
#include "../src/connectors/common.h"
#include "../src/connectors/volca_sample.h"
#include "../src/connectors/volca_sample_sdk/korg_syro_volcasample.h"

gint volca_sample_get_delete (guint id, struct idata *delete_audio);

gint volca_sample_get_upload (guint id, struct idata *input,
			      struct idata *syro_op, guint32 quality,
			      struct task_control *control);

static void
test_volca_sample_compare_to (struct idata *actual, const gchar *path)
{
  gint err, cmp;
  struct idata expected;
  struct sample_info *actual_si, sample_info_src;
  struct sample_load_opts sample_info_opts;

  sample_load_opts_init_direct (&sample_info_opts, FALSE);

  err = sample_load_from_file (path, &expected, NULL, &sample_info_opts,
			       &sample_info_src);
  CU_ASSERT_EQUAL (err, 0);
  if (err)
    {
      return;
    }

  CU_ASSERT_EQUAL (actual->content->len, expected.content->len);
  cmp = memcmp (actual->content->data, expected.content->data,
		actual->content->len);
  CU_ASSERT_EQUAL (cmp, 0);

  actual_si = actual->info;

  CU_ASSERT_EQUAL (actual_si->frames, sample_info_src.frames);
  CU_ASSERT_EQUAL (actual_si->channels, sample_info_src.channels);
  CU_ASSERT_EQUAL (actual_si->rate, sample_info_src.rate);
  CU_ASSERT_EQUAL (actual_si->format,
		   sample_info_src.format & SF_FORMAT_SUBMASK);

  idata_clear (&expected);
  idata_clear (actual);
}

static void
test_volca_sample_get_delete ()
{
  gint err;
  struct idata actual;

  printf ("\n");

  err = volca_sample_get_delete (17, &actual);
  CU_ASSERT_EQUAL (err, 0);
  if (err)
    {
      return;
    }

  // This file has been generated with the official project and the command below.
  // syro_volcasample_example volca_sample_delete_17.wav e17:
  test_volca_sample_compare_to (&actual, TEST_DATA_DIR
				"/connectors/volca_sample_delete_17.wav");
}

static void
test_volca_sample_get_update_params (const gchar *path, guint id,
				     guint32 quality)
{
  gint err;
  struct idata sample;
  struct idata actual;
  struct task_control control;

  printf ("\n");

  controllable_init (&control.controllable);
  controllable_set_active (&control.controllable, TRUE);
  control.callback = NULL;
  task_control_reset (&control, 1);

  //Same audio file as in the
  err = common_sample_load (TEST_DATA_DIR "/connectors/square.wav",
			    &sample, NULL, 1, 31250, SF_FORMAT_PCM_16, FALSE);
  CU_ASSERT_EQUAL (err, 0);
  if (err)
    {
      goto err;
    }

  err = volca_sample_get_upload (id, &sample, &actual, quality, &control);
  CU_ASSERT_EQUAL (err, 0);
  if (err)
    {
      goto err;
    }

  test_volca_sample_compare_to (&actual, path);

  idata_clear (&sample);

err:
  controllable_clear (&control.controllable);
}

static void
test_volca_sample_get_update ()
{
  // This file has been generated with the official project and the command below.
  // Previously, square.wav was resampled to 31250 Hz.
  // syro_volcasample_example volca_sample_upload_59.wav s59:square.wav
  test_volca_sample_get_update_params (TEST_DATA_DIR
				       "/connectors/volca_sample_upload_59.wav",
				       59, 0);
}

static void
test_volca_sample_get_update_16b ()
{
  // This file has been generated with the official project and the command below.
  // Previously, square.wav was resampled to 31250 Hz.
  // syro_volcasample_example volca_sample_upload_93_16b.wav s93c16:square.wav
  test_volca_sample_get_update_params (TEST_DATA_DIR
				       "/connectors/volca_sample_upload_93_16b.wav",
				       93, 16);
}

static void
test_volca_sample_get_update_8b ()
{
  // This file has been generated with the official project and the command below.
  // Previously, square.wav was resampled to 31250 Hz.
  // syro_volcasample_example volca_sample_upload_71_8b.wav s71c8:square.wav
  test_volca_sample_get_update_params (TEST_DATA_DIR
				       "/connectors/volca_sample_upload_71_8b.wav",
				       71, 8);
}

gint
main (gint argc, gchar *argv[])
{
  gint err = 0;

  debug_level = 5;

  if (CU_initialize_registry () != CUE_SUCCESS)
    {
      goto cleanup;
    }
  CU_pSuite suite = CU_add_suite ("Elektroid Volca Sample tests", 0, 0);
  if (!suite)
    {
      goto cleanup;
    }

  if (!CU_add_test (suite, "volca_sample_get_delete",
		    test_volca_sample_get_delete))
    {
      goto cleanup;
    }

  if (!CU_add_test (suite, "volca_sample_get_update",
		    test_volca_sample_get_update))
    {
      goto cleanup;
    }

  if (!CU_add_test (suite, "volca_sample_get_update_16b",
		    test_volca_sample_get_update_16b))
    {
      goto cleanup;
    }

  if (!CU_add_test (suite, "volca_sample_get_update_8b",
		    test_volca_sample_get_update_8b))
    {
      goto cleanup;
    }

  CU_basic_set_mode (CU_BRM_VERBOSE);

  CU_basic_run_tests ();
  err = CU_get_number_of_tests_failed ();

cleanup:
  CU_cleanup_registry ();
  return err || CU_get_error ();
}