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
|
#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, Header)
{
std::string data = Base64Decode("AQAAEwkjrUmSJQpUHflR9mjSJMdZpcO_Imdw9dCO9Clu4_wQPvhCB01w6xAtXNcAp5RASgDBhDSCGGIAcwA");
size_t size = 0;
int algorithm = 0;
ASSERT_EQ(true, DecompressFingerprintHeader(data, size, algorithm));
ASSERT_EQ(19, size);
ASSERT_EQ(1, algorithm);
}
TEST(FingerprintDecompressor, OneItemOneBit)
{
uint32_t expected[] = { 1 };
char data[] = { 0, 0, 0, 1, 1 };
int algorithm = 1;
std::vector<uint32_t> value;
ASSERT_EQ(true, DecompressFingerprint(std::string(data, NELEMS(data)), value, 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;
ASSERT_EQ(true, DecompressFingerprint(std::string(data, NELEMS(data)), value, 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;
ASSERT_EQ(true, DecompressFingerprint(std::string(data, NELEMS(data)), value, 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;
ASSERT_EQ(true, DecompressFingerprint(std::string(data, NELEMS(data)), value, 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;
ASSERT_EQ(true, DecompressFingerprint(std::string(data, NELEMS(data)), value, 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;
ASSERT_EQ(true, DecompressFingerprint(std::string(data, NELEMS(data)), value, 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;
ASSERT_EQ(false, DecompressFingerprint(std::string(data, NELEMS(data)), value, algorithm));
CheckFingerprints(value, expected, 0);
ASSERT_EQ(1, 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;
ASSERT_EQ(true, DecompressFingerprint(data, value, algorithm));
CheckFingerprints(value, (uint32_t *) expected, NELEMS(expected));
ASSERT_EQ(1, algorithm);
}
|