File: test_fingerprint_decompressor.cpp

package info (click to toggle)
chromaprint 1.4.3-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,676 kB
  • sloc: cpp: 5,976; ansic: 2,521; python: 657; makefile: 167; sh: 93
file content (98 lines) | stat: -rw-r--r-- 3,036 bytes parent folder | download | duplicates (2)
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
#include <gtest/gtest.h>
#include <algorithm>
#include <vector>
#include "fingerprint_decompressor.h"
#include "utils/base64.h"
#include "utils.h"
#include "test_utils.h"

using namespace chromaprint;

TEST(FingerprintDecompressor, OneItemOneBit)
{
	uint32_t expected[] = { 1 };
	char data[] = { 0, 0, 0, 1, 1 };

	int algorithm = 1;
	std::vector<uint32_t> value = DecompressFingerprint(std::string(data, NELEMS(data)), &algorithm);
	CheckFingerprints(value, expected, NELEMS(expected));
	ASSERT_EQ(0, algorithm);
}


TEST(FingerprintDecompressor, OneItemThreeBits)
{
	uint32_t expected[] = { 7 };
	char data[] = { 0, 0, 0, 1, 73, 0 };

	int algorithm = 1;
	std::vector<uint32_t> value = DecompressFingerprint(std::string(data, NELEMS(data)), &algorithm);
	CheckFingerprints(value, expected, NELEMS(expected));
	ASSERT_EQ(0, algorithm);
}

TEST(FingerprintDecompressor, OneItemOneBitExcept)
{
	uint32_t expected[] = { 1<<6 };
	char data[] = { 0, 0, 0, 1, 7, 0 };

	int algorithm = 1;
	std::vector<uint32_t> value = DecompressFingerprint(std::string(data, NELEMS(data)), &algorithm);
	CheckFingerprints(value, expected, NELEMS(expected));
	ASSERT_EQ(0, algorithm);
}

TEST(FingerprintDecompressor, OneItemOneBitExcept2)
{
	uint32_t expected[] = { 1<<8 };
	char data[] = { 0, 0, 0, 1, 7, 2 };

	int algorithm = 1;
	std::vector<uint32_t> value = DecompressFingerprint(std::string(data, NELEMS(data)), &algorithm);
	CheckFingerprints(value, expected, NELEMS(expected));
	ASSERT_EQ(0, algorithm);
}

TEST(FingerprintDecompressor, TwoItems)
{
	uint32_t expected[] = { 1, 0 };
	char data[] = { 0, 0, 0, 2, 65, 0 };

	int algorithm = 1;
	std::vector<uint32_t> value = DecompressFingerprint(std::string(data, NELEMS(data)), &algorithm);
	CheckFingerprints(value, expected, NELEMS(expected));
	ASSERT_EQ(0, algorithm);
}

TEST(FingerprintDecompressor, TwoItemsNoChange)
{
	uint32_t expected[] = { 1, 1 };
	char data[] = { 0, 0, 0, 2, 1, 0 };

	int algorithm = 1;
	std::vector<uint32_t> value = DecompressFingerprint(std::string(data, NELEMS(data)), &algorithm);
	CheckFingerprints(value, expected, NELEMS(expected));
	ASSERT_EQ(0, algorithm);
}

TEST(FingerprintDecompressor, Invalid1)
{
	uint32_t expected[] = { 0 };
	char data[] = { 0, char(255), char(255), char(255) };

	int algorithm = 1;
	std::vector<uint32_t> value = DecompressFingerprint(std::string(data, NELEMS(data)), &algorithm);
	CheckFingerprints(value, expected, 0);
	ASSERT_EQ(0, algorithm);
}

TEST(FingerprintDecompressor, Long)
{
	int32_t expected[] = { -587455133,-591649759,-574868448,-576973520,-543396544,1330439488,1326360000,1326355649,1191625921,1192674515,1194804466,1195336818,1165981042,1165956451,1157441379,1157441299,1291679571,1291673457,1170079601 };
	std::string data = Base64Decode("AQAAEwkjrUmSJQpUHflR9mjSJMdZpcO_Imdw9dCO9Clu4_wQPvhCB01w6xAtXNcAp5RASgDBhDSCGGIAcwA");

	int algorithm = 2;
	std::vector<uint32_t> value = DecompressFingerprint(data, &algorithm);
	CheckFingerprints(value, (uint32_t *) expected, NELEMS(expected));
	ASSERT_EQ(1, algorithm);
}