1 #include <gtest/gtest.h>
2 #include <algorithm>
3 #include <vector>
4 #include <fstream>
5 #include "image.h"
6 #include "classifier.h"
7 #include "fingerprint_compressor.h"
8 #include "utils.h"
9 #include "test_utils.h"
10
11 using namespace chromaprint;
12
TEST(FingerprintCompressor,OneItemOneBit)13 TEST(FingerprintCompressor, OneItemOneBit)
14 {
15 FingerprintCompressor compressor;
16
17 uint32_t fingerprint[] = { 1 };
18 std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 1));
19
20 char expected[] = { 0, 0, 0, 1, 1 };
21 CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
22 }
23
TEST(FingerprintCompressor,OneItemThreeBits)24 TEST(FingerprintCompressor, OneItemThreeBits)
25 {
26 FingerprintCompressor compressor;
27
28 uint32_t fingerprint[] = { 7 };
29 std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 1));
30
31 char expected[] = { 0, 0, 0, 1, 73, 0 };
32 CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
33 }
34
TEST(FingerprintCompressor,OneItemOneBitExcept)35 TEST(FingerprintCompressor, OneItemOneBitExcept)
36 {
37 FingerprintCompressor compressor;
38
39 uint32_t fingerprint[] = { 1<<6 };
40 std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 1));
41
42 char expected[] = { 0, 0, 0, 1, 7, 0 };
43 CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
44 }
45
TEST(FingerprintCompressor,OneItemOneBitExcept2)46 TEST(FingerprintCompressor, OneItemOneBitExcept2)
47 {
48 FingerprintCompressor compressor;
49
50 uint32_t fingerprint[] = { 1<<8 };
51 std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 1));
52
53 char expected[] = { 0, 0, 0, 1, 7, 2 };
54 CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
55 }
56
TEST(FingerprintCompressor,TwoItems)57 TEST(FingerprintCompressor, TwoItems)
58 {
59 FingerprintCompressor compressor;
60
61 uint32_t fingerprint[] = { 1, 0 };
62 std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 2));
63
64 char expected[] = { 0, 0, 0, 2, 65, 0 };
65 CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
66 }
67
TEST(FingerprintCompressor,TwoItemsNoChange)68 TEST(FingerprintCompressor, TwoItemsNoChange)
69 {
70 FingerprintCompressor compressor;
71
72 uint32_t fingerprint[] = { 1, 1 };
73 std::string value = compressor.Compress(std::vector<uint32_t>(fingerprint, fingerprint + 2));
74
75 char expected[] = { 0, 0, 0, 2, 1, 0 };
76 CheckString(value, expected, sizeof(expected)/sizeof(expected[0]));
77 }
78