mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-28 03:40:35 +08:00
Strict warnings in the unit tests. This commit needs to be carefully reviewed.
This commit is contained in:
@@ -37,7 +37,12 @@ struct CustomType
|
||||
, c()
|
||||
{ }
|
||||
|
||||
bool operator==(const CustomType& rhs) const { return a == rhs.a && b == rhs.b && c == rhs.c; }
|
||||
bool operator==(const CustomType& rhs) const
|
||||
{
|
||||
return a == rhs.a &&
|
||||
uavcan::areFloatsExactlyEqual(b, rhs.b) &&
|
||||
c == rhs.c;
|
||||
}
|
||||
|
||||
static int encode(const CustomType& obj, uavcan::ScalarCodec& codec,
|
||||
uavcan::TailArrayOptimizationMode tao_mode = uavcan::TailArrayOptEnabled)
|
||||
@@ -127,19 +132,19 @@ TEST(Array, Basic)
|
||||
/*
|
||||
* Modification with known values; array lengths are hard coded.
|
||||
*/
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
a1.at(i) = i;
|
||||
a1.at(i) = int8_t(i);
|
||||
}
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
{
|
||||
a2.at(i) = i;
|
||||
}
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
{
|
||||
a3[i].a = i;
|
||||
a3[i].a = int8_t(i);
|
||||
a3[i].b = i;
|
||||
for (int i2 = 0; i2 < 5; i2++)
|
||||
for (uint8_t i2 = 0; i2 < 5; i2++)
|
||||
{
|
||||
a3[i].c.push_back(i2 & 1);
|
||||
}
|
||||
@@ -187,15 +192,15 @@ TEST(Array, Basic)
|
||||
ASSERT_EQ(a2_, a2);
|
||||
ASSERT_EQ(a3_, a3);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (uint8_t i = 0; i < 4; i++)
|
||||
{
|
||||
ASSERT_EQ(a1[i], a1_[i]);
|
||||
}
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
{
|
||||
ASSERT_EQ(a2[i], a2_[i]);
|
||||
}
|
||||
for (int i = 0; i < 2; i++)
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
{
|
||||
ASSERT_EQ(a3[i].a, a3_[i].a);
|
||||
ASSERT_EQ(a3[i].b, a3_[i].b);
|
||||
@@ -355,11 +360,11 @@ TEST(Array, Dynamic)
|
||||
ASSERT_EQ(5, a.size());
|
||||
ASSERT_EQ(255, b.size());
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
for (uint8_t i = 0; i < 5; i++)
|
||||
{
|
||||
ASSERT_TRUE(a[i]);
|
||||
}
|
||||
for (int i = 0; i < 255; i++)
|
||||
for (uint8_t i = 0; i < 255; i++)
|
||||
{
|
||||
ASSERT_EQ(72, b[i]);
|
||||
}
|
||||
@@ -382,7 +387,11 @@ struct CustomType2
|
||||
, b()
|
||||
{ }
|
||||
|
||||
bool operator==(const CustomType2& rhs) const { return a == rhs.a && b == rhs.b; }
|
||||
bool operator==(const CustomType2& rhs) const
|
||||
{
|
||||
return uavcan::areFloatsExactlyEqual(a, rhs.a) &&
|
||||
b == rhs.b;
|
||||
}
|
||||
|
||||
static int encode(const CustomType2& obj, uavcan::ScalarCodec& codec,
|
||||
uavcan::TailArrayOptimizationMode tao_mode = uavcan::TailArrayOptEnabled)
|
||||
@@ -699,7 +708,7 @@ TEST(Array, Appending)
|
||||
ASSERT_EQ(2, a[1]);
|
||||
|
||||
b += a;
|
||||
ASSERT_TRUE(a == b);
|
||||
ASSERT_TRUE(b == a);
|
||||
b += a;
|
||||
ASSERT_EQ(4, b.size());
|
||||
ASSERT_EQ(1, b[0]);
|
||||
@@ -793,8 +802,8 @@ TEST(Array, FlatStreaming)
|
||||
std::cout << std::endl;
|
||||
|
||||
AF16D af16d1;
|
||||
af16d1.push_back(1.23);
|
||||
af16d1.push_back(4.56);
|
||||
af16d1.push_back(1.23F);
|
||||
af16d1.push_back(4.56F);
|
||||
uavcan::YamlStreamer<AF16D>::stream(std::cout, af16d1, 0);
|
||||
std::cout << std::endl;
|
||||
|
||||
@@ -816,15 +825,15 @@ TEST(Array, MultidimensionalStreaming)
|
||||
|
||||
ThreeDimensional threedee;
|
||||
threedee.resize(3);
|
||||
for (int x = 0; x < threedee.size(); x++)
|
||||
for (uint8_t x = 0; x < threedee.size(); x++)
|
||||
{
|
||||
threedee[x].resize(3);
|
||||
for (int y = 0; y < threedee[x].size(); y++)
|
||||
for (uint8_t y = 0; y < threedee[x].size(); y++)
|
||||
{
|
||||
threedee[x][y].resize(3);
|
||||
for (int z = 0; z < threedee[x][y].size(); z++)
|
||||
for (uint8_t z = 0; z < threedee[x][y].size(); z++)
|
||||
{
|
||||
threedee[x][y][z] = 1.0 / (x + y + z + 1.0);
|
||||
threedee[x][y][z] = 1.0F / (float(x + y + z) + 1.0F);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -854,9 +863,9 @@ TEST(Array, SquareMatrixPacking)
|
||||
// Empty array will be decoded as zero matrix
|
||||
double nans3x3_out[9];
|
||||
m3x3s.unpackSquareMatrix(nans3x3_out);
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
ASSERT_FLOAT_EQ(0, nans3x3_out[i]);
|
||||
ASSERT_DOUBLE_EQ(0, nans3x3_out[i]);
|
||||
}
|
||||
}
|
||||
{
|
||||
@@ -866,25 +875,25 @@ TEST(Array, SquareMatrixPacking)
|
||||
|
||||
empty.resize(9);
|
||||
m3x3s.unpackSquareMatrix(empty);
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
ASSERT_FLOAT_EQ(0, empty.at(i));
|
||||
ASSERT_DOUBLE_EQ(0, empty.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Scalar matrix will be reduced to a single value
|
||||
{
|
||||
std::vector<float> scalar2x2(4);
|
||||
scalar2x2[0] = scalar2x2[3] = 3.14;
|
||||
scalar2x2[0] = scalar2x2[3] = 3.14F;
|
||||
m2x2f.packSquareMatrix(scalar2x2);
|
||||
ASSERT_EQ(1, m2x2f.size());
|
||||
ASSERT_FLOAT_EQ(3.14, m2x2f[0]);
|
||||
ASSERT_FLOAT_EQ(3.14F, m2x2f[0]);
|
||||
|
||||
m2x2f.unpackSquareMatrix(scalar2x2);
|
||||
const float reference[] =
|
||||
{
|
||||
3.14, 0,
|
||||
0, 3.14
|
||||
3.14F, 0.0F,
|
||||
0.0F, 3.14F
|
||||
};
|
||||
ASSERT_TRUE(std::equal(scalar2x2.begin(), scalar2x2.end(), reference));
|
||||
}
|
||||
@@ -900,7 +909,7 @@ TEST(Array, SquareMatrixPacking)
|
||||
};
|
||||
m6x6d.packSquareMatrix(scalar6x6);
|
||||
ASSERT_EQ(1, m6x6d.size());
|
||||
ASSERT_FLOAT_EQ(-18, m6x6d[0]);
|
||||
ASSERT_DOUBLE_EQ(-18, m6x6d[0]);
|
||||
|
||||
std::vector<long double> output(36);
|
||||
m6x6d.unpackSquareMatrix(output);
|
||||
@@ -920,12 +929,12 @@ TEST(Array, SquareMatrixPacking)
|
||||
};
|
||||
m6x6d.packSquareMatrix(diagonal6x6);
|
||||
ASSERT_EQ(6, m6x6d.size());
|
||||
ASSERT_FLOAT_EQ(1, m6x6d[0]);
|
||||
ASSERT_FLOAT_EQ(-2, m6x6d[1]);
|
||||
ASSERT_FLOAT_EQ(3, m6x6d[2]);
|
||||
ASSERT_FLOAT_EQ(-4, m6x6d[3]);
|
||||
ASSERT_FLOAT_EQ(5, m6x6d[4]);
|
||||
ASSERT_FLOAT_EQ(-6, m6x6d[5]);
|
||||
ASSERT_DOUBLE_EQ(1, m6x6d[0]);
|
||||
ASSERT_DOUBLE_EQ(-2, m6x6d[1]);
|
||||
ASSERT_DOUBLE_EQ(3, m6x6d[2]);
|
||||
ASSERT_DOUBLE_EQ(-4, m6x6d[3]);
|
||||
ASSERT_DOUBLE_EQ(5, m6x6d[4]);
|
||||
ASSERT_DOUBLE_EQ(-6, m6x6d[5]);
|
||||
|
||||
std::vector<long double> output(36);
|
||||
m6x6d.unpackSquareMatrix(output);
|
||||
@@ -935,15 +944,15 @@ TEST(Array, SquareMatrixPacking)
|
||||
// A matrix filled with random values will not be compressed
|
||||
{
|
||||
std::vector<float> full3x3(9);
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
full3x3[i] = i;
|
||||
full3x3[i] = float(i);
|
||||
}
|
||||
m3x3s.packSquareMatrix(full3x3);
|
||||
ASSERT_EQ(9, m3x3s.size());
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
ASSERT_FLOAT_EQ(i, m3x3s[i]);
|
||||
ASSERT_FLOAT_EQ(float(i), m3x3s[i]);
|
||||
}
|
||||
|
||||
long output[9];
|
||||
@@ -961,21 +970,21 @@ TEST(Array, SquareMatrixPacking)
|
||||
};
|
||||
m3x3s.packSquareMatrix(scalarnan3x3);
|
||||
ASSERT_EQ(3, m3x3s.size());
|
||||
ASSERT_FALSE(m3x3s[0] == m3x3s[0]); // NAN
|
||||
ASSERT_FALSE(m3x3s[1] == m3x3s[1]); // NAN
|
||||
ASSERT_FALSE(m3x3s[2] == m3x3s[2]); // NAN
|
||||
ASSERT_FALSE(m3x3s[0] <= m3x3s[0]); // NAN
|
||||
ASSERT_FALSE(m3x3s[1] <= m3x3s[1]); // NAN
|
||||
ASSERT_FALSE(m3x3s[2] <= m3x3s[2]); // NAN
|
||||
|
||||
float output[9];
|
||||
m3x3s.unpackSquareMatrix(output);
|
||||
ASSERT_FALSE(output[0] == output[0]); // NAN
|
||||
ASSERT_FALSE(output[0] <= output[0]); // NAN
|
||||
ASSERT_EQ(0, output[1]);
|
||||
ASSERT_EQ(0, output[2]);
|
||||
ASSERT_EQ(0, output[3]);
|
||||
ASSERT_FALSE(output[4] == output[4]); // NAN
|
||||
ASSERT_FALSE(output[4] <= output[4]); // NAN
|
||||
ASSERT_EQ(0, output[5]);
|
||||
ASSERT_EQ(0, output[6]);
|
||||
ASSERT_EQ(0, output[7]);
|
||||
ASSERT_FALSE(output[8] == output[8]); // NAN
|
||||
ASSERT_FALSE(output[8] <= output[8]); // NAN
|
||||
}
|
||||
|
||||
// This is a full matrix too (notice the NAN)
|
||||
@@ -988,14 +997,14 @@ TEST(Array, SquareMatrixPacking)
|
||||
m2x2f.packSquareMatrix(full2x2);
|
||||
ASSERT_EQ(4, m2x2f.size());
|
||||
ASSERT_FLOAT_EQ(1, m2x2f[0]);
|
||||
ASSERT_FALSE(m2x2f[1] == m2x2f[1]); // NAN
|
||||
ASSERT_FALSE(m2x2f[1] <= m2x2f[1]); // NAN
|
||||
ASSERT_FLOAT_EQ(0, m2x2f[2]);
|
||||
ASSERT_FLOAT_EQ(-2, m2x2f[3]);
|
||||
|
||||
float output[4];
|
||||
m2x2f.unpackSquareMatrix(output);
|
||||
ASSERT_EQ(1, output[0]);
|
||||
ASSERT_FALSE(output[1] == output[1]); // NAN
|
||||
ASSERT_FALSE(output[1] <= output[1]); // NAN
|
||||
ASSERT_EQ(0, output[2]);
|
||||
ASSERT_EQ(-2, output[3]);
|
||||
}
|
||||
@@ -1037,12 +1046,12 @@ TEST(Array, FuzzySquareMatrixPacking)
|
||||
|
||||
m6x6d.packSquareMatrix(diagonal6x6);
|
||||
ASSERT_EQ(6, m6x6d.size());
|
||||
ASSERT_FLOAT_EQ(1, m6x6d[0]);
|
||||
ASSERT_FLOAT_EQ(-2, m6x6d[1]);
|
||||
ASSERT_FLOAT_EQ(3, m6x6d[2]);
|
||||
ASSERT_FLOAT_EQ(-4, m6x6d[3]);
|
||||
ASSERT_FLOAT_EQ(5, m6x6d[4]);
|
||||
ASSERT_FLOAT_EQ(-6, m6x6d[5]);
|
||||
ASSERT_DOUBLE_EQ(1, m6x6d[0]);
|
||||
ASSERT_DOUBLE_EQ(-2, m6x6d[1]);
|
||||
ASSERT_DOUBLE_EQ(3, m6x6d[2]);
|
||||
ASSERT_DOUBLE_EQ(-4, m6x6d[3]);
|
||||
ASSERT_DOUBLE_EQ(5, m6x6d[4]);
|
||||
ASSERT_DOUBLE_EQ(-6, m6x6d[5]);
|
||||
|
||||
std::vector<long double> output(36);
|
||||
m6x6d.unpackSquareMatrix(output);
|
||||
@@ -1087,13 +1096,13 @@ TEST(Array, SquareMatrixPackingIntegers)
|
||||
}
|
||||
{
|
||||
std::vector<long double> full(9);
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
full[i] = i;
|
||||
}
|
||||
m3x3int.packSquareMatrix(full);
|
||||
ASSERT_EQ(9, m3x3int.size());
|
||||
for (int i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
ASSERT_EQ(i, m3x3int[i]);
|
||||
}
|
||||
@@ -1123,7 +1132,7 @@ TEST(Array, SquareMatrixPackingInPlace)
|
||||
// Will fill with zeros - matrix is empty
|
||||
m3x3s.unpackSquareMatrix();
|
||||
ASSERT_EQ(9, m3x3s.size());
|
||||
for (unsigned i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
ASSERT_EQ(0, m3x3s[i]);
|
||||
}
|
||||
@@ -1177,7 +1186,7 @@ TEST(Array, SquareMatrixPackingInPlace)
|
||||
m3x3s.unpackSquareMatrix();
|
||||
ASSERT_EQ(9, m3x3s.size());
|
||||
|
||||
for (unsigned i = 0; i < 9; i++)
|
||||
for (uint8_t i = 0; i < 9; i++)
|
||||
{
|
||||
const bool diagonal = (i == 0) || (i == 4) || (i == 8);
|
||||
ASSERT_EQ((diagonal ? 123 : 0), m3x3s[i]);
|
||||
|
||||
Reference in New Issue
Block a user