TEST_F(PointerCoordsTest, Parcel) { Parcel parcel; PointerCoords inCoords; inCoords.clear(); PointerCoords outCoords; // Round trip with empty coords. inCoords.writeToParcel(&parcel); parcel.setDataPosition(0); outCoords.readFromParcel(&parcel); ASSERT_EQ(0ULL, outCoords.bits); // Round trip with some values. parcel.freeData(); inCoords.setAxisValue(2, 5); inCoords.setAxisValue(5, 8); inCoords.writeToParcel(&parcel); parcel.setDataPosition(0); outCoords.readFromParcel(&parcel); ASSERT_EQ(outCoords.bits, inCoords.bits); ASSERT_EQ(outCoords.values[0], inCoords.values[0]); ASSERT_EQ(outCoords.values[1], inCoords.values[1]); }
static inline void scaleAxisValue(PointerCoords& c, int axis, float scaleFactor) { float value = c.getAxisValue(axis); if (value != 0) { c.setAxisValue(axis, value * scaleFactor); } }
TEST_F(PointerCoordsTest, AxisValues) { float* valuePtr; PointerCoords coords; coords.clear(); // Check invariants when no axes are present. ASSERT_EQ(0, coords.getAxisValue(0)) << "getAxisValue should return zero because axis is not present"; ASSERT_EQ(0, coords.getAxisValue(1)) << "getAxisValue should return zero because axis is not present"; // Set first axis. ASSERT_EQ(OK, coords.setAxisValue(1, 5)); ASSERT_EQ(5, coords.values[0]); ASSERT_EQ(0x4000000000000000ULL, coords.bits); ASSERT_EQ(0, coords.getAxisValue(0)) << "getAxisValue should return zero because axis is not present"; ASSERT_EQ(5, coords.getAxisValue(1)) << "getAxisValue should return value of axis"; // Set an axis with a higher id than all others. (appending value at the end) ASSERT_EQ(OK, coords.setAxisValue(3, 2)); ASSERT_EQ(0x5000000000000000ULL, coords.bits); ASSERT_EQ(5, coords.values[0]); ASSERT_EQ(2, coords.values[1]); ASSERT_EQ(0, coords.getAxisValue(0)) << "getAxisValue should return zero because axis is not present"; ASSERT_EQ(5, coords.getAxisValue(1)) << "getAxisValue should return value of axis"; ASSERT_EQ(0, coords.getAxisValue(2)) << "getAxisValue should return zero because axis is not present"; ASSERT_EQ(2, coords.getAxisValue(3)) << "getAxisValue should return value of axis"; // Set an axis with an id lower than all others. (prepending value at beginning) ASSERT_EQ(OK, coords.setAxisValue(0, 4)); ASSERT_EQ(0xd000000000000000ULL, coords.bits); ASSERT_EQ(4, coords.values[0]); ASSERT_EQ(5, coords.values[1]); ASSERT_EQ(2, coords.values[2]); ASSERT_EQ(4, coords.getAxisValue(0)) << "getAxisValue should return value of axis"; ASSERT_EQ(5, coords.getAxisValue(1)) << "getAxisValue should return value of axis"; ASSERT_EQ(0, coords.getAxisValue(2)) << "getAxisValue should return zero because axis is not present"; ASSERT_EQ(2, coords.getAxisValue(3)) << "getAxisValue should return value of axis"; // Set an axis with an id between the others. (inserting value in the middle) ASSERT_EQ(OK, coords.setAxisValue(2, 1)); ASSERT_EQ(0xf000000000000000ULL, coords.bits); ASSERT_EQ(4, coords.values[0]); ASSERT_EQ(5, coords.values[1]); ASSERT_EQ(1, coords.values[2]); ASSERT_EQ(2, coords.values[3]); ASSERT_EQ(4, coords.getAxisValue(0)) << "getAxisValue should return value of axis"; ASSERT_EQ(5, coords.getAxisValue(1)) << "getAxisValue should return value of axis"; ASSERT_EQ(1, coords.getAxisValue(2)) << "getAxisValue should return value of axis"; ASSERT_EQ(2, coords.getAxisValue(3)) << "getAxisValue should return value of axis"; // Set an existing axis value in place. ASSERT_EQ(OK, coords.setAxisValue(1, 6)); ASSERT_EQ(0xf000000000000000ULL, coords.bits); ASSERT_EQ(4, coords.values[0]); ASSERT_EQ(6, coords.values[1]); ASSERT_EQ(1, coords.values[2]); ASSERT_EQ(2, coords.values[3]); ASSERT_EQ(4, coords.getAxisValue(0)) << "getAxisValue should return value of axis"; ASSERT_EQ(6, coords.getAxisValue(1)) << "getAxisValue should return value of axis"; ASSERT_EQ(1, coords.getAxisValue(2)) << "getAxisValue should return value of axis"; ASSERT_EQ(2, coords.getAxisValue(3)) << "getAxisValue should return value of axis"; // Set maximum number of axes. for (size_t axis = 4; axis < PointerCoords::MAX_AXES; axis++) { ASSERT_EQ(OK, coords.setAxisValue(axis, axis)); } ASSERT_EQ(PointerCoords::MAX_AXES, __builtin_popcountll(coords.bits)); // Try to set one more axis beyond maximum number. // Ensure bits are unchanged. ASSERT_EQ(NO_MEMORY, coords.setAxisValue(PointerCoords::MAX_AXES, 100)); ASSERT_EQ(PointerCoords::MAX_AXES, __builtin_popcountll(coords.bits)); }
TEST_F(PointerCoordsTest, ClearSetsBitsToZero) { PointerCoords coords; coords.clear(); ASSERT_EQ(0ULL, coords.bits); }