File: test_utils.h

package info (click to toggle)
chromaprint 1.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,336 kB
  • sloc: cpp: 58,922; python: 4,402; ansic: 3,461; sh: 440; makefile: 366
file content (47 lines) | stat: -rw-r--r-- 1,239 bytes parent folder | download | duplicates (5)
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
#ifndef CHROMAPRINT_TESTS_UTILS_H_
#define CHROMAPRINT_TESTS_UTILS_H_

#include <stdint.h>
#include <vector>
#include <fstream>
#include <string>
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#define NELEMS(x) (sizeof(x)/sizeof(x[0]))

inline void CheckString(std::string actual, char *expected, int expected_size)
{
	ASSERT_EQ(expected_size, actual.size());
	for (int i = 0; i < expected_size; i++) {
		EXPECT_EQ(expected[i], actual[i]) << "Different at index " << i;
	}
}

inline void CheckFingerprints(std::vector<uint32_t> actual, uint32_t *expected, int expected_size)
{
	ASSERT_EQ(expected_size, actual.size());
	for (int i = 0; i < expected_size; i++) {
		EXPECT_EQ(expected[i], actual[i]) << "Different at index " << i;
	}
}

inline std::vector<short> LoadAudioFile(const std::string &file_name)
{
	std::string path = TESTS_DIR + file_name;
	std::ifstream file(path.c_str(), std::ifstream::in | std::ifstream::binary);
	uint8_t buf[4096];
	std::vector<int16_t> data;
	while (!file.eof()) {
		file.read((char *) buf, 4096);
		size_t nread = file.gcount();
		for (size_t i = 0; i < nread - 1; i += 2) {
			data.push_back((int16_t) (((uint16_t) buf[i+1] << 8) | ((uint16_t) buf[i])));
		}
	}
	file.close();
	return data;
}

#endif